clang  19.0.0git
ASTImporter.cpp
Go to the documentation of this file.
1 //===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the ASTImporter class which imports AST nodes from one
10 // context into another context.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/ASTImporter.h"
15 #include "clang/AST/ASTContext.h"
19 #include "clang/AST/Attr.h"
20 #include "clang/AST/Decl.h"
22 #include "clang/AST/DeclBase.h"
23 #include "clang/AST/DeclCXX.h"
24 #include "clang/AST/DeclFriend.h"
25 #include "clang/AST/DeclGroup.h"
26 #include "clang/AST/DeclObjC.h"
27 #include "clang/AST/DeclTemplate.h"
28 #include "clang/AST/DeclVisitor.h"
30 #include "clang/AST/Expr.h"
31 #include "clang/AST/ExprCXX.h"
32 #include "clang/AST/ExprObjC.h"
37 #include "clang/AST/Stmt.h"
38 #include "clang/AST/StmtCXX.h"
39 #include "clang/AST/StmtObjC.h"
40 #include "clang/AST/StmtVisitor.h"
41 #include "clang/AST/TemplateBase.h"
42 #include "clang/AST/TemplateName.h"
43 #include "clang/AST/Type.h"
44 #include "clang/AST/TypeLoc.h"
45 #include "clang/AST/TypeVisitor.h"
47 #include "clang/Basic/Builtins.h"
51 #include "clang/Basic/LLVM.h"
55 #include "clang/Basic/Specifiers.h"
56 #include "llvm/ADT/APSInt.h"
57 #include "llvm/ADT/ArrayRef.h"
58 #include "llvm/ADT/DenseMap.h"
59 #include "llvm/ADT/STLExtras.h"
60 #include "llvm/ADT/ScopeExit.h"
61 #include "llvm/ADT/SmallVector.h"
62 #include "llvm/Support/Casting.h"
63 #include "llvm/Support/ErrorHandling.h"
64 #include "llvm/Support/MemoryBuffer.h"
65 #include <algorithm>
66 #include <cassert>
67 #include <cstddef>
68 #include <memory>
69 #include <optional>
70 #include <type_traits>
71 #include <utility>
72 
73 namespace clang {
74 
75  using llvm::make_error;
76  using llvm::Error;
77  using llvm::Expected;
85 
86  std::string ASTImportError::toString() const {
87  // FIXME: Improve error texts.
88  switch (Error) {
89  case NameConflict:
90  return "NameConflict";
92  return "UnsupportedConstruct";
93  case Unknown:
94  return "Unknown error";
95  }
96  llvm_unreachable("Invalid error code.");
97  return "Invalid error code.";
98  }
99 
100  void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
101 
102  std::error_code ASTImportError::convertToErrorCode() const {
103  llvm_unreachable("Function not implemented.");
104  }
105 
106  char ASTImportError::ID;
107 
108  template <class T>
111  SmallVector<Decl *, 2> Redecls;
112  for (auto *R : D->getFirstDecl()->redecls()) {
113  if (R != D->getFirstDecl())
114  Redecls.push_back(R);
115  }
116  Redecls.push_back(D->getFirstDecl());
117  std::reverse(Redecls.begin(), Redecls.end());
118  return Redecls;
119  }
120 
122  if (auto *FD = dyn_cast<FunctionDecl>(D))
123  return getCanonicalForwardRedeclChain<FunctionDecl>(FD);
124  if (auto *VD = dyn_cast<VarDecl>(D))
125  return getCanonicalForwardRedeclChain<VarDecl>(VD);
126  if (auto *TD = dyn_cast<TagDecl>(D))
127  return getCanonicalForwardRedeclChain<TagDecl>(TD);
128  llvm_unreachable("Bad declaration kind");
129  }
130 
131  void updateFlags(const Decl *From, Decl *To) {
132  // Check if some flags or attrs are new in 'From' and copy into 'To'.
133  // FIXME: Other flags or attrs?
134  if (From->isUsed(false) && !To->isUsed(false))
135  To->setIsUsed();
136  }
137 
138  /// How to handle import errors that occur when import of a child declaration
139  /// of a DeclContext fails.
141  /// This context is imported (in the 'from' domain).
142  /// It is nullptr if a non-DeclContext is imported.
143  const DeclContext *const FromDC;
144  /// Ignore import errors of the children.
145  /// If true, the context can be imported successfully if a child
146  /// of it failed to import. Otherwise the import errors of the child nodes
147  /// are accumulated (joined) into the import error object of the parent.
148  /// (Import of a parent can fail in other ways.)
149  bool const IgnoreChildErrors;
150 
151  public:
153  : FromDC(FromDC), IgnoreChildErrors(!isa<TagDecl>(FromDC)) {}
155  : FromDC(dyn_cast<DeclContext>(FromD)),
156  IgnoreChildErrors(!isa<TagDecl>(FromD)) {}
157 
158  /// Process the import result of a child (of the current declaration).
159  /// \param ResultErr The import error that can be used as result of
160  /// importing the parent. This may be changed by the function.
161  /// \param ChildErr Result of importing a child. Can be success or error.
162  void handleChildImportResult(Error &ResultErr, Error &&ChildErr) {
163  if (ChildErr && !IgnoreChildErrors)
164  ResultErr = joinErrors(std::move(ResultErr), std::move(ChildErr));
165  else
166  consumeError(std::move(ChildErr));
167  }
168 
169  /// Determine if import failure of a child does not cause import failure of
170  /// its parent.
171  bool ignoreChildErrorOnParent(Decl *FromChildD) const {
172  if (!IgnoreChildErrors || !FromDC)
173  return false;
174  return FromDC->containsDecl(FromChildD);
175  }
176  };
177 
178  class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>,
179  public DeclVisitor<ASTNodeImporter, ExpectedDecl>,
180  public StmtVisitor<ASTNodeImporter, ExpectedStmt> {
181  ASTImporter &Importer;
182 
183  // Use this instead of Importer.importInto .
184  template <typename ImportT>
185  [[nodiscard]] Error importInto(ImportT &To, const ImportT &From) {
186  return Importer.importInto(To, From);
187  }
188 
189  // Use this to import pointers of specific type.
190  template <typename ImportT>
191  [[nodiscard]] Error importInto(ImportT *&To, ImportT *From) {
192  auto ToOrErr = Importer.Import(From);
193  if (ToOrErr)
194  To = cast_or_null<ImportT>(*ToOrErr);
195  return ToOrErr.takeError();
196  }
197 
198  // Call the import function of ASTImporter for a baseclass of type `T` and
199  // cast the return value to `T`.
200  template <typename T>
201  auto import(T *From)
202  -> std::conditional_t<std::is_base_of_v<Type, T>, Expected<const T *>,
203  Expected<T *>> {
204  auto ToOrErr = Importer.Import(From);
205  if (!ToOrErr)
206  return ToOrErr.takeError();
207  return cast_or_null<T>(*ToOrErr);
208  }
209 
210  template <typename T>
211  auto import(const T *From) {
212  return import(const_cast<T *>(From));
213  }
214 
215  // Call the import function of ASTImporter for type `T`.
216  template <typename T>
217  Expected<T> import(const T &From) {
218  return Importer.Import(From);
219  }
220 
221  // Import an std::optional<T> by importing the contained T, if any.
222  template <typename T>
223  Expected<std::optional<T>> import(std::optional<T> From) {
224  if (!From)
225  return std::nullopt;
226  return import(*From);
227  }
228 
229  ExplicitSpecifier importExplicitSpecifier(Error &Err,
230  ExplicitSpecifier ESpec);
231 
232  // Wrapper for an overload set.
233  template <typename ToDeclT> struct CallOverloadedCreateFun {
234  template <typename... Args> decltype(auto) operator()(Args &&... args) {
235  return ToDeclT::Create(std::forward<Args>(args)...);
236  }
237  };
238 
239  // Always use these functions to create a Decl during import. There are
240  // certain tasks which must be done after the Decl was created, e.g. we
241  // must immediately register that as an imported Decl. The parameter `ToD`
242  // will be set to the newly created Decl or if had been imported before
243  // then to the already imported Decl. Returns a bool value set to true if
244  // the `FromD` had been imported before.
245  template <typename ToDeclT, typename FromDeclT, typename... Args>
246  [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
247  Args &&...args) {
248  // There may be several overloads of ToDeclT::Create. We must make sure
249  // to call the one which would be chosen by the arguments, thus we use a
250  // wrapper for the overload set.
251  CallOverloadedCreateFun<ToDeclT> OC;
252  return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
253  std::forward<Args>(args)...);
254  }
255  // Use this overload if a special Type is needed to be created. E.g if we
256  // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl`
257  // then:
258  // TypedefNameDecl *ToTypedef;
259  // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...);
260  template <typename NewDeclT, typename ToDeclT, typename FromDeclT,
261  typename... Args>
262  [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
263  Args &&...args) {
264  CallOverloadedCreateFun<NewDeclT> OC;
265  return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
266  std::forward<Args>(args)...);
267  }
268  // Use this version if a special create function must be
269  // used, e.g. CXXRecordDecl::CreateLambda .
270  template <typename ToDeclT, typename CreateFunT, typename FromDeclT,
271  typename... Args>
272  [[nodiscard]] bool
273  GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun,
274  FromDeclT *FromD, Args &&...args) {
275  if (Importer.getImportDeclErrorIfAny(FromD)) {
276  ToD = nullptr;
277  return true; // Already imported but with error.
278  }
279  ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD));
280  if (ToD)
281  return true; // Already imported.
282  ToD = CreateFun(std::forward<Args>(args)...);
283  // Keep track of imported Decls.
284  Importer.RegisterImportedDecl(FromD, ToD);
285  Importer.SharedState->markAsNewDecl(ToD);
286  InitializeImportedDecl(FromD, ToD);
287  return false; // A new Decl is created.
288  }
289 
290  void InitializeImportedDecl(Decl *FromD, Decl *ToD) {
291  ToD->IdentifierNamespace = FromD->IdentifierNamespace;
292  if (FromD->isUsed())
293  ToD->setIsUsed();
294  if (FromD->isImplicit())
295  ToD->setImplicit();
296  }
297 
298  // Check if we have found an existing definition. Returns with that
299  // definition if yes, otherwise returns null.
300  Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) {
301  const FunctionDecl *Definition = nullptr;
302  if (D->doesThisDeclarationHaveABody() &&
303  FoundFunction->hasBody(Definition))
304  return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition));
305  return nullptr;
306  }
307 
308  void addDeclToContexts(Decl *FromD, Decl *ToD) {
309  if (Importer.isMinimalImport()) {
310  // In minimal import case the decl must be added even if it is not
311  // contained in original context, for LLDB compatibility.
312  // FIXME: Check if a better solution is possible.
313  if (!FromD->getDescribedTemplate() &&
314  FromD->getFriendObjectKind() == Decl::FOK_None)
316  return;
317  }
318 
319  DeclContext *FromDC = FromD->getDeclContext();
320  DeclContext *FromLexicalDC = FromD->getLexicalDeclContext();
321  DeclContext *ToDC = ToD->getDeclContext();
322  DeclContext *ToLexicalDC = ToD->getLexicalDeclContext();
323 
324  bool Visible = false;
325  if (FromDC->containsDeclAndLoad(FromD)) {
326  ToDC->addDeclInternal(ToD);
327  Visible = true;
328  }
329  if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) {
330  ToLexicalDC->addDeclInternal(ToD);
331  Visible = true;
332  }
333 
334  // If the Decl was added to any context, it was made already visible.
335  // Otherwise it is still possible that it should be visible.
336  if (!Visible) {
337  if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) {
338  auto *ToNamed = cast<NamedDecl>(ToD);
339  DeclContextLookupResult FromLookup =
340  FromDC->lookup(FromNamed->getDeclName());
341  if (llvm::is_contained(FromLookup, FromNamed))
342  ToDC->makeDeclVisibleInContext(ToNamed);
343  }
344  }
345  }
346 
347  void updateLookupTableForTemplateParameters(TemplateParameterList &Params,
348  DeclContext *OldDC) {
349  ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
350  if (!LT)
351  return;
352 
353  for (NamedDecl *TP : Params)
354  LT->update(TP, OldDC);
355  }
356 
357  void updateLookupTableForTemplateParameters(TemplateParameterList &Params) {
358  updateLookupTableForTemplateParameters(
359  Params, Importer.getToContext().getTranslationUnitDecl());
360  }
361 
362  public:
363  explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {}
364 
368 
369  // Importing types
370  ExpectedType VisitType(const Type *T);
371 #define TYPE(Class, Base) \
372  ExpectedType Visit##Class##Type(const Class##Type *T);
373 #include "clang/AST/TypeNodes.inc"
374 
375  // Importing declarations
376  Error ImportDeclParts(NamedDecl *D, DeclarationName &Name, NamedDecl *&ToD,
378  Error ImportDeclParts(
379  NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
381  Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
383  const DeclarationNameInfo &From, DeclarationNameInfo &To);
384  Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
385  Error ImportDeclContext(
386  Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
387  Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To);
388 
389  Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To);
391  Expected<APValue> ImportAPValue(const APValue &FromValue);
392 
394 
395  /// What we should import from the definition.
397  /// Import the default subset of the definition, which might be
398  /// nothing (if minimal import is set) or might be everything (if minimal
399  /// import is not set).
401  /// Import everything.
403  /// Import only the bare bones needed to establish a valid
404  /// DeclContext.
405  IDK_Basic
406  };
407 
409  return IDK == IDK_Everything ||
410  (IDK == IDK_Default && !Importer.isMinimalImport());
411  }
412 
413  Error ImportInitializer(VarDecl *From, VarDecl *To);
414  Error ImportDefinition(
415  RecordDecl *From, RecordDecl *To,
417  Error ImportDefinition(
418  EnumDecl *From, EnumDecl *To,
420  Error ImportDefinition(
423  Error ImportDefinition(
430 
431  template <typename InContainerTy>
433  const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo);
434 
435  template<typename InContainerTy>
437  SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
438  const InContainerTy &Container, TemplateArgumentListInfo &Result);
439 
442  std::tuple<FunctionTemplateDecl *, TemplateArgsTy>;
445  FunctionDecl *FromFD);
446 
447  template <typename DeclTy>
448  Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD);
449 
451 
452  Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD);
453 
454  Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam,
455  ParmVarDecl *ToParam);
456 
459 
460  template <typename T>
461  bool hasSameVisibilityContextAndLinkage(T *Found, T *From);
462 
463  bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
464  bool IgnoreTemplateParmDepth = false);
511 
514 
529 
530  // Importing statements
550  // FIXME: MSAsmStmt
551  // FIXME: SEHExceptStmt
552  // FIXME: SEHFinallyStmt
553  // FIXME: SEHTryStmt
554  // FIXME: SEHLeaveStmt
555  // FIXME: CapturedStmt
559  // FIXME: MSDependentExistsStmt
567 
568  // Importing expressions
645 
646  // Helper for chaining together multiple imports. If an error is detected,
647  // subsequent imports will return default constructed nodes, so that failure
648  // can be detected with a single conditional branch after a sequence of
649  // imports.
650  template <typename T> T importChecked(Error &Err, const T &From) {
651  // Don't attempt to import nodes if we hit an error earlier.
652  if (Err)
653  return T{};
654  Expected<T> MaybeVal = import(From);
655  if (!MaybeVal) {
656  Err = MaybeVal.takeError();
657  return T{};
658  }
659  return *MaybeVal;
660  }
661 
662  template<typename IIter, typename OIter>
663  Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
664  using ItemT = std::remove_reference_t<decltype(*Obegin)>;
665  for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
666  Expected<ItemT> ToOrErr = import(*Ibegin);
667  if (!ToOrErr)
668  return ToOrErr.takeError();
669  *Obegin = *ToOrErr;
670  }
671  return Error::success();
672  }
673 
674  // Import every item from a container structure into an output container.
675  // If error occurs, stops at first error and returns the error.
676  // The output container should have space for all needed elements (it is not
677  // expanded, new items are put into from the beginning).
678  template<typename InContainerTy, typename OutContainerTy>
680  const InContainerTy &InContainer, OutContainerTy &OutContainer) {
681  return ImportArrayChecked(
682  InContainer.begin(), InContainer.end(), OutContainer.begin());
683  }
684 
685  template<typename InContainerTy, typename OIter>
686  Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
687  return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
688  }
689 
690  Error ImportOverriddenMethods(CXXMethodDecl *ToMethod,
691  CXXMethodDecl *FromMethod);
692 
694  FunctionDecl *FromFD);
695 
696  // Returns true if the given function has a placeholder return type and
697  // that type is declared inside the body of the function.
698  // E.g. auto f() { struct X{}; return X(); }
700  };
701 
702 template <typename InContainerTy>
704  SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
705  const InContainerTy &Container, TemplateArgumentListInfo &Result) {
706  auto ToLAngleLocOrErr = import(FromLAngleLoc);
707  if (!ToLAngleLocOrErr)
708  return ToLAngleLocOrErr.takeError();
709  auto ToRAngleLocOrErr = import(FromRAngleLoc);
710  if (!ToRAngleLocOrErr)
711  return ToRAngleLocOrErr.takeError();
712 
713  TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr);
714  if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo))
715  return Err;
716  Result = ToTAInfo;
717  return Error::success();
718 }
719 
720 template <>
721 Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>(
722  const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) {
724  From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result);
725 }
726 
727 template <>
730  const ASTTemplateArgumentListInfo &From,
731  TemplateArgumentListInfo &Result) {
732  return ImportTemplateArgumentListInfo(
733  From.LAngleLoc, From.RAngleLoc, From.arguments(), Result);
734 }
735 
738  FunctionDecl *FromFD) {
739  assert(FromFD->getTemplatedKind() ==
741 
743 
744  auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
745  if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate()))
746  return std::move(Err);
747 
748  // Import template arguments.
749  if (Error Err = ImportTemplateArguments(FTSInfo->TemplateArguments->asArray(),
750  std::get<1>(Result)))
751  return std::move(Err);
752 
753  return Result;
754 }
755 
756 template <>
758 ASTNodeImporter::import(TemplateParameterList *From) {
759  SmallVector<NamedDecl *, 4> To(From->size());
760  if (Error Err = ImportContainerChecked(*From, To))
761  return std::move(Err);
762 
763  ExpectedExpr ToRequiresClause = import(From->getRequiresClause());
764  if (!ToRequiresClause)
765  return ToRequiresClause.takeError();
766 
767  auto ToTemplateLocOrErr = import(From->getTemplateLoc());
768  if (!ToTemplateLocOrErr)
769  return ToTemplateLocOrErr.takeError();
770  auto ToLAngleLocOrErr = import(From->getLAngleLoc());
771  if (!ToLAngleLocOrErr)
772  return ToLAngleLocOrErr.takeError();
773  auto ToRAngleLocOrErr = import(From->getRAngleLoc());
774  if (!ToRAngleLocOrErr)
775  return ToRAngleLocOrErr.takeError();
776 
778  Importer.getToContext(),
779  *ToTemplateLocOrErr,
780  *ToLAngleLocOrErr,
781  To,
782  *ToRAngleLocOrErr,
783  *ToRequiresClause);
784 }
785 
786 template <>
788 ASTNodeImporter::import(const TemplateArgument &From) {
789  switch (From.getKind()) {
791  return TemplateArgument();
792 
793  case TemplateArgument::Type: {
794  ExpectedType ToTypeOrErr = import(From.getAsType());
795  if (!ToTypeOrErr)
796  return ToTypeOrErr.takeError();
797  return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false,
798  From.getIsDefaulted());
799  }
800 
802  ExpectedType ToTypeOrErr = import(From.getIntegralType());
803  if (!ToTypeOrErr)
804  return ToTypeOrErr.takeError();
805  return TemplateArgument(From, *ToTypeOrErr);
806  }
807 
809  Expected<ValueDecl *> ToOrErr = import(From.getAsDecl());
810  if (!ToOrErr)
811  return ToOrErr.takeError();
812  ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
813  if (!ToTypeOrErr)
814  return ToTypeOrErr.takeError();
815  return TemplateArgument(dyn_cast<ValueDecl>((*ToOrErr)->getCanonicalDecl()),
816  *ToTypeOrErr, From.getIsDefaulted());
817  }
818 
820  ExpectedType ToTypeOrErr = import(From.getNullPtrType());
821  if (!ToTypeOrErr)
822  return ToTypeOrErr.takeError();
823  return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true,
824  From.getIsDefaulted());
825  }
826 
828  ExpectedType ToTypeOrErr = import(From.getStructuralValueType());
829  if (!ToTypeOrErr)
830  return ToTypeOrErr.takeError();
831  Expected<APValue> ToValueOrErr = import(From.getAsStructuralValue());
832  if (!ToValueOrErr)
833  return ToValueOrErr.takeError();
834  return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
835  *ToValueOrErr);
836  }
837 
839  Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
840  if (!ToTemplateOrErr)
841  return ToTemplateOrErr.takeError();
842 
843  return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
844  }
845 
847  Expected<TemplateName> ToTemplateOrErr =
848  import(From.getAsTemplateOrTemplatePattern());
849  if (!ToTemplateOrErr)
850  return ToTemplateOrErr.takeError();
851 
852  return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(),
853  From.getIsDefaulted());
854  }
855 
857  if (ExpectedExpr ToExpr = import(From.getAsExpr()))
858  return TemplateArgument(*ToExpr, From.getIsDefaulted());
859  else
860  return ToExpr.takeError();
861 
862  case TemplateArgument::Pack: {
864  ToPack.reserve(From.pack_size());
865  if (Error Err = ImportTemplateArguments(From.pack_elements(), ToPack))
866  return std::move(Err);
867 
868  return TemplateArgument(
869  llvm::ArrayRef(ToPack).copy(Importer.getToContext()));
870  }
871  }
872 
873  llvm_unreachable("Invalid template argument kind");
874 }
875 
876 template <>
878 ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) {
879  Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument());
880  if (!ArgOrErr)
881  return ArgOrErr.takeError();
882  TemplateArgument Arg = *ArgOrErr;
883 
884  TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
885 
887  if (Arg.getKind() == TemplateArgument::Expression) {
888  ExpectedExpr E = import(FromInfo.getAsExpr());
889  if (!E)
890  return E.takeError();
891  ToInfo = TemplateArgumentLocInfo(*E);
892  } else if (Arg.getKind() == TemplateArgument::Type) {
893  if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo()))
894  ToInfo = TemplateArgumentLocInfo(*TSIOrErr);
895  else
896  return TSIOrErr.takeError();
897  } else {
898  auto ToTemplateQualifierLocOrErr =
899  import(FromInfo.getTemplateQualifierLoc());
900  if (!ToTemplateQualifierLocOrErr)
901  return ToTemplateQualifierLocOrErr.takeError();
902  auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc());
903  if (!ToTemplateNameLocOrErr)
904  return ToTemplateNameLocOrErr.takeError();
905  auto ToTemplateEllipsisLocOrErr =
906  import(FromInfo.getTemplateEllipsisLoc());
907  if (!ToTemplateEllipsisLocOrErr)
908  return ToTemplateEllipsisLocOrErr.takeError();
909  ToInfo = TemplateArgumentLocInfo(
910  Importer.getToContext(), *ToTemplateQualifierLocOrErr,
911  *ToTemplateNameLocOrErr, *ToTemplateEllipsisLocOrErr);
912  }
913 
914  return TemplateArgumentLoc(Arg, ToInfo);
915 }
916 
917 template <>
918 Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) {
919  if (DG.isNull())
920  return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
921  size_t NumDecls = DG.end() - DG.begin();
922  SmallVector<Decl *, 1> ToDecls;
923  ToDecls.reserve(NumDecls);
924  for (Decl *FromD : DG) {
925  if (auto ToDOrErr = import(FromD))
926  ToDecls.push_back(*ToDOrErr);
927  else
928  return ToDOrErr.takeError();
929  }
930  return DeclGroupRef::Create(Importer.getToContext(),
931  ToDecls.begin(),
932  NumDecls);
933 }
934 
935 template <>
937 ASTNodeImporter::import(const Designator &D) {
938  if (D.isFieldDesignator()) {
939  IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
940 
941  ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc());
942  if (!ToDotLocOrErr)
943  return ToDotLocOrErr.takeError();
944 
945  ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc());
946  if (!ToFieldLocOrErr)
947  return ToFieldLocOrErr.takeError();
948 
950  ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr);
951  }
952 
953  ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc());
954  if (!ToLBracketLocOrErr)
955  return ToLBracketLocOrErr.takeError();
956 
957  ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc());
958  if (!ToRBracketLocOrErr)
959  return ToRBracketLocOrErr.takeError();
960 
961  if (D.isArrayDesignator())
963  *ToLBracketLocOrErr,
964  *ToRBracketLocOrErr);
965 
966  ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc());
967  if (!ToEllipsisLocOrErr)
968  return ToEllipsisLocOrErr.takeError();
969 
970  assert(D.isArrayRangeDesignator());
972  D.getArrayIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr,
973  *ToRBracketLocOrErr);
974 }
975 
976 template <>
977 Expected<ConceptReference *> ASTNodeImporter::import(ConceptReference *From) {
978  Error Err = Error::success();
979  auto ToNNS = importChecked(Err, From->getNestedNameSpecifierLoc());
980  auto ToTemplateKWLoc = importChecked(Err, From->getTemplateKWLoc());
981  auto ToConceptNameLoc =
982  importChecked(Err, From->getConceptNameInfo().getLoc());
983  auto ToConceptName = importChecked(Err, From->getConceptNameInfo().getName());
984  auto ToFoundDecl = importChecked(Err, From->getFoundDecl());
985  auto ToNamedConcept = importChecked(Err, From->getNamedConcept());
986  if (Err)
987  return std::move(Err);
988  TemplateArgumentListInfo ToTAInfo;
989  const auto *ASTTemplateArgs = From->getTemplateArgsAsWritten();
990  if (ASTTemplateArgs)
991  if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
992  return std::move(Err);
993  auto *ConceptRef = ConceptReference::Create(
994  Importer.getToContext(), ToNNS, ToTemplateKWLoc,
995  DeclarationNameInfo(ToConceptName, ToConceptNameLoc), ToFoundDecl,
996  ToNamedConcept,
997  ASTTemplateArgs ? ASTTemplateArgumentListInfo::Create(
998  Importer.getToContext(), ToTAInfo)
999  : nullptr);
1000  return ConceptRef;
1001 }
1002 
1003 template <>
1004 Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) {
1005  ValueDecl *Var = nullptr;
1006  if (From.capturesVariable()) {
1007  if (auto VarOrErr = import(From.getCapturedVar()))
1008  Var = *VarOrErr;
1009  else
1010  return VarOrErr.takeError();
1011  }
1012 
1013  auto LocationOrErr = import(From.getLocation());
1014  if (!LocationOrErr)
1015  return LocationOrErr.takeError();
1016 
1017  SourceLocation EllipsisLoc;
1018  if (From.isPackExpansion())
1019  if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc()))
1020  return std::move(Err);
1021 
1022  return LambdaCapture(
1023  *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var,
1024  EllipsisLoc);
1025 }
1026 
1027 template <typename T>
1029  if (Found->getLinkageInternal() != From->getLinkageInternal())
1030  return false;
1031 
1032  if (From->hasExternalFormalLinkage())
1033  return Found->hasExternalFormalLinkage();
1034  if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl())
1035  return false;
1036  if (From->isInAnonymousNamespace())
1037  return Found->isInAnonymousNamespace();
1038  else
1039  return !Found->isInAnonymousNamespace() &&
1040  !Found->hasExternalFormalLinkage();
1041 }
1042 
1043 template <>
1045  TypedefNameDecl *From) {
1046  if (Found->getLinkageInternal() != From->getLinkageInternal())
1047  return false;
1048 
1049  if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace())
1050  return Importer.GetFromTU(Found) == From->getTranslationUnitDecl();
1051  return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace();
1052 }
1053 
1054 } // namespace clang
1055 
1056 //----------------------------------------------------------------------------
1057 // Import Types
1058 //----------------------------------------------------------------------------
1059 
1060 using namespace clang;
1061 
1063  Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
1064  << T->getTypeClassName();
1065  return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1066 }
1067 
1068 ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
1069  ExpectedType UnderlyingTypeOrErr = import(T->getValueType());
1070  if (!UnderlyingTypeOrErr)
1071  return UnderlyingTypeOrErr.takeError();
1072 
1073  return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr);
1074 }
1075 
1076 ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
1077  switch (T->getKind()) {
1078 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1079  case BuiltinType::Id: \
1080  return Importer.getToContext().SingletonId;
1081 #include "clang/Basic/OpenCLImageTypes.def"
1082 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1083  case BuiltinType::Sampled##Id: \
1084  return Importer.getToContext().Sampled##SingletonId;
1085 #define IMAGE_WRITE_TYPE(Type, Id, Ext)
1086 #define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
1087 #include "clang/Basic/OpenCLImageTypes.def"
1088 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1089  case BuiltinType::Id: \
1090  return Importer.getToContext().Id##Ty;
1091 #include "clang/Basic/OpenCLExtensionTypes.def"
1092 #define SVE_TYPE(Name, Id, SingletonId) \
1093  case BuiltinType::Id: \
1094  return Importer.getToContext().SingletonId;
1095 #include "clang/Basic/AArch64SVEACLETypes.def"
1096 #define PPC_VECTOR_TYPE(Name, Id, Size) \
1097  case BuiltinType::Id: \
1098  return Importer.getToContext().Id##Ty;
1099 #include "clang/Basic/PPCTypes.def"
1100 #define RVV_TYPE(Name, Id, SingletonId) \
1101  case BuiltinType::Id: \
1102  return Importer.getToContext().SingletonId;
1103 #include "clang/Basic/RISCVVTypes.def"
1104 #define WASM_TYPE(Name, Id, SingletonId) \
1105  case BuiltinType::Id: \
1106  return Importer.getToContext().SingletonId;
1107 #include "clang/Basic/WebAssemblyReferenceTypes.def"
1108 #define SHARED_SINGLETON_TYPE(Expansion)
1109 #define BUILTIN_TYPE(Id, SingletonId) \
1110  case BuiltinType::Id: return Importer.getToContext().SingletonId;
1111 #include "clang/AST/BuiltinTypes.def"
1112 
1113  // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
1114  // context supports C++.
1115 
1116  // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
1117  // context supports ObjC.
1118 
1119  case BuiltinType::Char_U:
1120  // The context we're importing from has an unsigned 'char'. If we're
1121  // importing into a context with a signed 'char', translate to
1122  // 'unsigned char' instead.
1123  if (Importer.getToContext().getLangOpts().CharIsSigned)
1124  return Importer.getToContext().UnsignedCharTy;
1125 
1126  return Importer.getToContext().CharTy;
1127 
1128  case BuiltinType::Char_S:
1129  // The context we're importing from has an unsigned 'char'. If we're
1130  // importing into a context with a signed 'char', translate to
1131  // 'unsigned char' instead.
1132  if (!Importer.getToContext().getLangOpts().CharIsSigned)
1133  return Importer.getToContext().SignedCharTy;
1134 
1135  return Importer.getToContext().CharTy;
1136 
1137  case BuiltinType::WChar_S:
1138  case BuiltinType::WChar_U:
1139  // FIXME: If not in C++, shall we translate to the C equivalent of
1140  // wchar_t?
1141  return Importer.getToContext().WCharTy;
1142  }
1143 
1144  llvm_unreachable("Invalid BuiltinType Kind!");
1145 }
1146 
1147 ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) {
1148  ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType());
1149  if (!ToOriginalTypeOrErr)
1150  return ToOriginalTypeOrErr.takeError();
1151 
1152  return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr);
1153 }
1154 
1155 ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) {
1156  ExpectedType ToElementTypeOrErr = import(T->getElementType());
1157  if (!ToElementTypeOrErr)
1158  return ToElementTypeOrErr.takeError();
1159 
1160  return Importer.getToContext().getComplexType(*ToElementTypeOrErr);
1161 }
1162 
1163 ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) {
1164  ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1165  if (!ToPointeeTypeOrErr)
1166  return ToPointeeTypeOrErr.takeError();
1167 
1168  return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr);
1169 }
1170 
1171 ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) {
1172  // FIXME: Check for blocks support in "to" context.
1173  ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1174  if (!ToPointeeTypeOrErr)
1175  return ToPointeeTypeOrErr.takeError();
1176 
1177  return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr);
1178 }
1179 
1181 ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) {
1182  // FIXME: Check for C++ support in "to" context.
1183  ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1184  if (!ToPointeeTypeOrErr)
1185  return ToPointeeTypeOrErr.takeError();
1186 
1187  return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr);
1188 }
1189 
1191 ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) {
1192  // FIXME: Check for C++0x support in "to" context.
1193  ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1194  if (!ToPointeeTypeOrErr)
1195  return ToPointeeTypeOrErr.takeError();
1196 
1197  return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr);
1198 }
1199 
1201 ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) {
1202  // FIXME: Check for C++ support in "to" context.
1203  ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1204  if (!ToPointeeTypeOrErr)
1205  return ToPointeeTypeOrErr.takeError();
1206 
1207  ExpectedTypePtr ClassTypeOrErr = import(T->getClass());
1208  if (!ClassTypeOrErr)
1209  return ClassTypeOrErr.takeError();
1210 
1211  return Importer.getToContext().getMemberPointerType(*ToPointeeTypeOrErr,
1212  *ClassTypeOrErr);
1213 }
1214 
1216 ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) {
1217  Error Err = Error::success();
1218  auto ToElementType = importChecked(Err, T->getElementType());
1219  auto ToSizeExpr = importChecked(Err, T->getSizeExpr());
1220  if (Err)
1221  return std::move(Err);
1222 
1223  return Importer.getToContext().getConstantArrayType(
1224  ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(),
1225  T->getIndexTypeCVRQualifiers());
1226 }
1227 
1229 ASTNodeImporter::VisitArrayParameterType(const ArrayParameterType *T) {
1230  ExpectedType ToArrayTypeOrErr = VisitConstantArrayType(T);
1231  if (!ToArrayTypeOrErr)
1232  return ToArrayTypeOrErr.takeError();
1233 
1234  return Importer.getToContext().getArrayParameterType(*ToArrayTypeOrErr);
1235 }
1236 
1238 ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
1239  ExpectedType ToElementTypeOrErr = import(T->getElementType());
1240  if (!ToElementTypeOrErr)
1241  return ToElementTypeOrErr.takeError();
1242 
1243  return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr,
1244  T->getSizeModifier(),
1245  T->getIndexTypeCVRQualifiers());
1246 }
1247 
1249 ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
1250  Error Err = Error::success();
1251  QualType ToElementType = importChecked(Err, T->getElementType());
1252  Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1253  SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange());
1254  if (Err)
1255  return std::move(Err);
1256  return Importer.getToContext().getVariableArrayType(
1257  ToElementType, ToSizeExpr, T->getSizeModifier(),
1258  T->getIndexTypeCVRQualifiers(), ToBracketsRange);
1259 }
1260 
1261 ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
1262  const DependentSizedArrayType *T) {
1263  Error Err = Error::success();
1264  QualType ToElementType = importChecked(Err, T->getElementType());
1265  Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1266  SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange());
1267  if (Err)
1268  return std::move(Err);
1269  // SizeExpr may be null if size is not specified directly.
1270  // For example, 'int a[]'.
1271 
1272  return Importer.getToContext().getDependentSizedArrayType(
1273  ToElementType, ToSizeExpr, T->getSizeModifier(),
1274  T->getIndexTypeCVRQualifiers(), ToBracketsRange);
1275 }
1276 
1277 ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(
1278  const DependentSizedExtVectorType *T) {
1279  Error Err = Error::success();
1280  QualType ToElementType = importChecked(Err, T->getElementType());
1281  Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1282  SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1283  if (Err)
1284  return std::move(Err);
1285  return Importer.getToContext().getDependentSizedExtVectorType(
1286  ToElementType, ToSizeExpr, ToAttrLoc);
1287 }
1288 
1289 ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) {
1290  ExpectedType ToElementTypeOrErr = import(T->getElementType());
1291  if (!ToElementTypeOrErr)
1292  return ToElementTypeOrErr.takeError();
1293 
1294  return Importer.getToContext().getVectorType(*ToElementTypeOrErr,
1295  T->getNumElements(),
1296  T->getVectorKind());
1297 }
1298 
1299 ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) {
1300  ExpectedType ToElementTypeOrErr = import(T->getElementType());
1301  if (!ToElementTypeOrErr)
1302  return ToElementTypeOrErr.takeError();
1303 
1304  return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr,
1305  T->getNumElements());
1306 }
1307 
1309 ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1310  // FIXME: What happens if we're importing a function without a prototype
1311  // into C++? Should we make it variadic?
1312  ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1313  if (!ToReturnTypeOrErr)
1314  return ToReturnTypeOrErr.takeError();
1315 
1316  return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr,
1317  T->getExtInfo());
1318 }
1319 
1321 ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
1322  ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1323  if (!ToReturnTypeOrErr)
1324  return ToReturnTypeOrErr.takeError();
1325 
1326  // Import argument types
1327  SmallVector<QualType, 4> ArgTypes;
1328  for (const auto &A : T->param_types()) {
1329  ExpectedType TyOrErr = import(A);
1330  if (!TyOrErr)
1331  return TyOrErr.takeError();
1332  ArgTypes.push_back(*TyOrErr);
1333  }
1334 
1335  // Import exception types
1336  SmallVector<QualType, 4> ExceptionTypes;
1337  for (const auto &E : T->exceptions()) {
1338  ExpectedType TyOrErr = import(E);
1339  if (!TyOrErr)
1340  return TyOrErr.takeError();
1341  ExceptionTypes.push_back(*TyOrErr);
1342  }
1343 
1345  Error Err = Error::success();
1347  ToEPI.ExtInfo = FromEPI.ExtInfo;
1348  ToEPI.Variadic = FromEPI.Variadic;
1349  ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
1350  ToEPI.TypeQuals = FromEPI.TypeQuals;
1351  ToEPI.RefQualifier = FromEPI.RefQualifier;
1352  ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
1353  ToEPI.ExceptionSpec.NoexceptExpr =
1355  ToEPI.ExceptionSpec.SourceDecl =
1356  importChecked(Err, FromEPI.ExceptionSpec.SourceDecl);
1359  ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
1360 
1361  if (Err)
1362  return std::move(Err);
1363 
1364  return Importer.getToContext().getFunctionType(
1365  *ToReturnTypeOrErr, ArgTypes, ToEPI);
1366 }
1367 
1368 ExpectedType ASTNodeImporter::VisitUnresolvedUsingType(
1369  const UnresolvedUsingType *T) {
1370  Error Err = Error::success();
1371  auto ToD = importChecked(Err, T->getDecl());
1372  auto ToPrevD = importChecked(Err, T->getDecl()->getPreviousDecl());
1373  if (Err)
1374  return std::move(Err);
1375 
1376  return Importer.getToContext().getTypeDeclType(
1377  ToD, cast_or_null<TypeDecl>(ToPrevD));
1378 }
1379 
1380 ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) {
1381  ExpectedType ToInnerTypeOrErr = import(T->getInnerType());
1382  if (!ToInnerTypeOrErr)
1383  return ToInnerTypeOrErr.takeError();
1384 
1385  return Importer.getToContext().getParenType(*ToInnerTypeOrErr);
1386 }
1387 
1389 ASTNodeImporter::VisitPackIndexingType(clang::PackIndexingType const *T) {
1390 
1391  ExpectedType Pattern = import(T->getPattern());
1392  if (!Pattern)
1393  return Pattern.takeError();
1394  ExpectedExpr Index = import(T->getIndexExpr());
1395  if (!Index)
1396  return Index.takeError();
1397  return Importer.getToContext().getPackIndexingType(*Pattern, *Index);
1398 }
1399 
1400 ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) {
1401  Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl());
1402  if (!ToDeclOrErr)
1403  return ToDeclOrErr.takeError();
1404 
1405  TypedefNameDecl *ToDecl = *ToDeclOrErr;
1406  if (ToDecl->getTypeForDecl())
1407  return QualType(ToDecl->getTypeForDecl(), 0);
1408 
1409  ExpectedType ToUnderlyingTypeOrErr = import(T->desugar());
1410  if (!ToUnderlyingTypeOrErr)
1411  return ToUnderlyingTypeOrErr.takeError();
1412 
1413  return Importer.getToContext().getTypedefType(ToDecl, *ToUnderlyingTypeOrErr);
1414 }
1415 
1416 ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {
1417  ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1418  if (!ToExprOrErr)
1419  return ToExprOrErr.takeError();
1420  return Importer.getToContext().getTypeOfExprType(*ToExprOrErr, T->getKind());
1421 }
1422 
1423 ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
1424  ExpectedType ToUnderlyingTypeOrErr = import(T->getUnmodifiedType());
1425  if (!ToUnderlyingTypeOrErr)
1426  return ToUnderlyingTypeOrErr.takeError();
1427  return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr,
1428  T->getKind());
1429 }
1430 
1431 ExpectedType ASTNodeImporter::VisitUsingType(const UsingType *T) {
1432  Expected<UsingShadowDecl *> FoundOrErr = import(T->getFoundDecl());
1433  if (!FoundOrErr)
1434  return FoundOrErr.takeError();
1435  Expected<QualType> UnderlyingOrErr = import(T->getUnderlyingType());
1436  if (!UnderlyingOrErr)
1437  return UnderlyingOrErr.takeError();
1438 
1439  return Importer.getToContext().getUsingType(*FoundOrErr, *UnderlyingOrErr);
1440 }
1441 
1442 ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) {
1443  // FIXME: Make sure that the "to" context supports C++0x!
1444  ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1445  if (!ToExprOrErr)
1446  return ToExprOrErr.takeError();
1447 
1448  ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1449  if (!ToUnderlyingTypeOrErr)
1450  return ToUnderlyingTypeOrErr.takeError();
1451 
1452  return Importer.getToContext().getDecltypeType(
1453  *ToExprOrErr, *ToUnderlyingTypeOrErr);
1454 }
1455 
1457 ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) {
1458  ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1459  if (!ToBaseTypeOrErr)
1460  return ToBaseTypeOrErr.takeError();
1461 
1462  ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1463  if (!ToUnderlyingTypeOrErr)
1464  return ToUnderlyingTypeOrErr.takeError();
1465 
1466  return Importer.getToContext().getUnaryTransformType(
1467  *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind());
1468 }
1469 
1470 ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) {
1471  // FIXME: Make sure that the "to" context supports C++11!
1472  ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1473  if (!ToDeducedTypeOrErr)
1474  return ToDeducedTypeOrErr.takeError();
1475 
1476  ExpectedDecl ToTypeConstraintConcept = import(T->getTypeConstraintConcept());
1477  if (!ToTypeConstraintConcept)
1478  return ToTypeConstraintConcept.takeError();
1479 
1480  SmallVector<TemplateArgument, 2> ToTemplateArgs;
1481  if (Error Err = ImportTemplateArguments(T->getTypeConstraintArguments(),
1482  ToTemplateArgs))
1483  return std::move(Err);
1484 
1485  return Importer.getToContext().getAutoType(
1486  *ToDeducedTypeOrErr, T->getKeyword(), /*IsDependent*/false,
1487  /*IsPack=*/false, cast_or_null<ConceptDecl>(*ToTypeConstraintConcept),
1488  ToTemplateArgs);
1489 }
1490 
1491 ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType(
1493  // FIXME: Make sure that the "to" context supports C++17!
1494  Expected<TemplateName> ToTemplateNameOrErr = import(T->getTemplateName());
1495  if (!ToTemplateNameOrErr)
1496  return ToTemplateNameOrErr.takeError();
1497  ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1498  if (!ToDeducedTypeOrErr)
1499  return ToDeducedTypeOrErr.takeError();
1500 
1502  *ToTemplateNameOrErr, *ToDeducedTypeOrErr, T->isDependentType());
1503 }
1504 
1505 ExpectedType ASTNodeImporter::VisitInjectedClassNameType(
1506  const InjectedClassNameType *T) {
1507  Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl());
1508  if (!ToDeclOrErr)
1509  return ToDeclOrErr.takeError();
1510 
1511  // The InjectedClassNameType is created in VisitRecordDecl when the
1512  // T->getDecl() is imported. Here we can return the existing type.
1513  const Type *Ty = (*ToDeclOrErr)->getTypeForDecl();
1514  assert(Ty && isa<InjectedClassNameType>(Ty));
1515  return QualType(Ty, 0);
1516 }
1517 
1518 ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) {
1519  Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl());
1520  if (!ToDeclOrErr)
1521  return ToDeclOrErr.takeError();
1522 
1523  return Importer.getToContext().getTagDeclType(*ToDeclOrErr);
1524 }
1525 
1526 ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) {
1527  Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl());
1528  if (!ToDeclOrErr)
1529  return ToDeclOrErr.takeError();
1530 
1531  return Importer.getToContext().getTagDeclType(*ToDeclOrErr);
1532 }
1533 
1534 ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) {
1535  ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType());
1536  if (!ToModifiedTypeOrErr)
1537  return ToModifiedTypeOrErr.takeError();
1538  ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType());
1539  if (!ToEquivalentTypeOrErr)
1540  return ToEquivalentTypeOrErr.takeError();
1541 
1542  return Importer.getToContext().getAttributedType(T->getAttrKind(),
1543  *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr);
1544 }
1545 
1547 ASTNodeImporter::VisitCountAttributedType(const CountAttributedType *T) {
1548  ExpectedType ToWrappedTypeOrErr = import(T->desugar());
1549  if (!ToWrappedTypeOrErr)
1550  return ToWrappedTypeOrErr.takeError();
1551 
1552  Error Err = Error::success();
1553  Expr *CountExpr = importChecked(Err, T->getCountExpr());
1554 
1556  for (auto TI : T->dependent_decls()) {
1557  Expected<ValueDecl *> ToDeclOrErr = import(TI.getDecl());
1558  if (!ToDeclOrErr)
1559  return ToDeclOrErr.takeError();
1560  CoupledDecls.emplace_back(*ToDeclOrErr, TI.isDeref());
1561  }
1562 
1563  return Importer.getToContext().getCountAttributedType(
1564  *ToWrappedTypeOrErr, CountExpr, T->isCountInBytes(), T->isOrNull(),
1565  ArrayRef(CoupledDecls.data(), CoupledDecls.size()));
1566 }
1567 
1568 ExpectedType ASTNodeImporter::VisitTemplateTypeParmType(
1569  const TemplateTypeParmType *T) {
1570  Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl());
1571  if (!ToDeclOrErr)
1572  return ToDeclOrErr.takeError();
1573 
1574  return Importer.getToContext().getTemplateTypeParmType(
1575  T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr);
1576 }
1577 
1578 ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType(
1579  const SubstTemplateTypeParmType *T) {
1580  Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1581  if (!ReplacedOrErr)
1582  return ReplacedOrErr.takeError();
1583 
1584  ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType());
1585  if (!ToReplacementTypeOrErr)
1586  return ToReplacementTypeOrErr.takeError();
1587 
1588  return Importer.getToContext().getSubstTemplateTypeParmType(
1589  *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex(),
1590  T->getPackIndex());
1591 }
1592 
1593 ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
1595  Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1596  if (!ReplacedOrErr)
1597  return ReplacedOrErr.takeError();
1598 
1599  Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1600  if (!ToArgumentPack)
1601  return ToArgumentPack.takeError();
1602 
1604  *ReplacedOrErr, T->getIndex(), T->getFinal(), *ToArgumentPack);
1605 }
1606 
1607 ExpectedType ASTNodeImporter::VisitTemplateSpecializationType(
1608  const TemplateSpecializationType *T) {
1609  auto ToTemplateOrErr = import(T->getTemplateName());
1610  if (!ToTemplateOrErr)
1611  return ToTemplateOrErr.takeError();
1612 
1613  SmallVector<TemplateArgument, 2> ToTemplateArgs;
1614  if (Error Err =
1615  ImportTemplateArguments(T->template_arguments(), ToTemplateArgs))
1616  return std::move(Err);
1617 
1618  QualType ToCanonType;
1619  if (!T->isCanonicalUnqualified()) {
1620  QualType FromCanonType
1621  = Importer.getFromContext().getCanonicalType(QualType(T, 0));
1622  if (ExpectedType TyOrErr = import(FromCanonType))
1623  ToCanonType = *TyOrErr;
1624  else
1625  return TyOrErr.takeError();
1626  }
1627  return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr,
1628  ToTemplateArgs,
1629  ToCanonType);
1630 }
1631 
1632 ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) {
1633  // Note: the qualifier in an ElaboratedType is optional.
1634  auto ToQualifierOrErr = import(T->getQualifier());
1635  if (!ToQualifierOrErr)
1636  return ToQualifierOrErr.takeError();
1637 
1638  ExpectedType ToNamedTypeOrErr = import(T->getNamedType());
1639  if (!ToNamedTypeOrErr)
1640  return ToNamedTypeOrErr.takeError();
1641 
1642  Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl());
1643  if (!ToOwnedTagDeclOrErr)
1644  return ToOwnedTagDeclOrErr.takeError();
1645 
1646  return Importer.getToContext().getElaboratedType(T->getKeyword(),
1647  *ToQualifierOrErr,
1648  *ToNamedTypeOrErr,
1649  *ToOwnedTagDeclOrErr);
1650 }
1651 
1653 ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) {
1654  ExpectedType ToPatternOrErr = import(T->getPattern());
1655  if (!ToPatternOrErr)
1656  return ToPatternOrErr.takeError();
1657 
1658  return Importer.getToContext().getPackExpansionType(*ToPatternOrErr,
1659  T->getNumExpansions(),
1660  /*ExpactPack=*/false);
1661 }
1662 
1663 ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType(
1665  auto ToQualifierOrErr = import(T->getQualifier());
1666  if (!ToQualifierOrErr)
1667  return ToQualifierOrErr.takeError();
1668 
1669  IdentifierInfo *ToName = Importer.Import(T->getIdentifier());
1670 
1672  ToPack.reserve(T->template_arguments().size());
1673  if (Error Err = ImportTemplateArguments(T->template_arguments(), ToPack))
1674  return std::move(Err);
1675 
1677  T->getKeyword(), *ToQualifierOrErr, ToName, ToPack);
1678 }
1679 
1681 ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) {
1682  auto ToQualifierOrErr = import(T->getQualifier());
1683  if (!ToQualifierOrErr)
1684  return ToQualifierOrErr.takeError();
1685 
1686  IdentifierInfo *Name = Importer.Import(T->getIdentifier());
1687 
1688  QualType Canon;
1689  if (T != T->getCanonicalTypeInternal().getTypePtr()) {
1690  if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal()))
1691  Canon = (*TyOrErr).getCanonicalType();
1692  else
1693  return TyOrErr.takeError();
1694  }
1695 
1696  return Importer.getToContext().getDependentNameType(T->getKeyword(),
1697  *ToQualifierOrErr,
1698  Name, Canon);
1699 }
1700 
1702 ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1703  Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl());
1704  if (!ToDeclOrErr)
1705  return ToDeclOrErr.takeError();
1706 
1707  return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr);
1708 }
1709 
1710 ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) {
1711  ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1712  if (!ToBaseTypeOrErr)
1713  return ToBaseTypeOrErr.takeError();
1714 
1715  SmallVector<QualType, 4> TypeArgs;
1716  for (auto TypeArg : T->getTypeArgsAsWritten()) {
1717  if (ExpectedType TyOrErr = import(TypeArg))
1718  TypeArgs.push_back(*TyOrErr);
1719  else
1720  return TyOrErr.takeError();
1721  }
1722 
1724  for (auto *P : T->quals()) {
1725  if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P))
1726  Protocols.push_back(*ProtocolOrErr);
1727  else
1728  return ProtocolOrErr.takeError();
1729 
1730  }
1731 
1732  return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs,
1733  Protocols,
1734  T->isKindOfTypeAsWritten());
1735 }
1736 
1738 ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1739  ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1740  if (!ToPointeeTypeOrErr)
1741  return ToPointeeTypeOrErr.takeError();
1742 
1743  return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
1744 }
1745 
1747 ASTNodeImporter::VisitMacroQualifiedType(const MacroQualifiedType *T) {
1748  ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1749  if (!ToUnderlyingTypeOrErr)
1750  return ToUnderlyingTypeOrErr.takeError();
1751 
1752  IdentifierInfo *ToIdentifier = Importer.Import(T->getMacroIdentifier());
1753  return Importer.getToContext().getMacroQualifiedType(*ToUnderlyingTypeOrErr,
1754  ToIdentifier);
1755 }
1756 
1757 ExpectedType clang::ASTNodeImporter::VisitAdjustedType(const AdjustedType *T) {
1758  Error Err = Error::success();
1759  QualType ToOriginalType = importChecked(Err, T->getOriginalType());
1760  QualType ToAdjustedType = importChecked(Err, T->getAdjustedType());
1761  if (Err)
1762  return std::move(Err);
1763 
1764  return Importer.getToContext().getAdjustedType(ToOriginalType,
1765  ToAdjustedType);
1766 }
1767 
1768 ExpectedType clang::ASTNodeImporter::VisitBitIntType(const BitIntType *T) {
1769  return Importer.getToContext().getBitIntType(T->isUnsigned(),
1770  T->getNumBits());
1771 }
1772 
1773 ExpectedType clang::ASTNodeImporter::VisitBTFTagAttributedType(
1774  const clang::BTFTagAttributedType *T) {
1775  Error Err = Error::success();
1776  const BTFTypeTagAttr *ToBTFAttr = importChecked(Err, T->getAttr());
1777  QualType ToWrappedType = importChecked(Err, T->getWrappedType());
1778  if (Err)
1779  return std::move(Err);
1780 
1781  return Importer.getToContext().getBTFTagAttributedType(ToBTFAttr,
1782  ToWrappedType);
1783 }
1784 
1785 ExpectedType clang::ASTNodeImporter::VisitConstantMatrixType(
1786  const clang::ConstantMatrixType *T) {
1787  ExpectedType ToElementTypeOrErr = import(T->getElementType());
1788  if (!ToElementTypeOrErr)
1789  return ToElementTypeOrErr.takeError();
1790 
1791  return Importer.getToContext().getConstantMatrixType(
1792  *ToElementTypeOrErr, T->getNumRows(), T->getNumColumns());
1793 }
1794 
1795 ExpectedType clang::ASTNodeImporter::VisitDependentAddressSpaceType(
1797  Error Err = Error::success();
1798  QualType ToPointeeType = importChecked(Err, T->getPointeeType());
1799  Expr *ToAddrSpaceExpr = importChecked(Err, T->getAddrSpaceExpr());
1800  SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1801  if (Err)
1802  return std::move(Err);
1803 
1804  return Importer.getToContext().getDependentAddressSpaceType(
1805  ToPointeeType, ToAddrSpaceExpr, ToAttrLoc);
1806 }
1807 
1808 ExpectedType clang::ASTNodeImporter::VisitDependentBitIntType(
1809  const clang::DependentBitIntType *T) {
1810  ExpectedExpr ToNumBitsExprOrErr = import(T->getNumBitsExpr());
1811  if (!ToNumBitsExprOrErr)
1812  return ToNumBitsExprOrErr.takeError();
1813  return Importer.getToContext().getDependentBitIntType(T->isUnsigned(),
1814  *ToNumBitsExprOrErr);
1815 }
1816 
1817 ExpectedType clang::ASTNodeImporter::VisitDependentSizedMatrixType(
1819  Error Err = Error::success();
1820  QualType ToElementType = importChecked(Err, T->getElementType());
1821  Expr *ToRowExpr = importChecked(Err, T->getRowExpr());
1822  Expr *ToColumnExpr = importChecked(Err, T->getColumnExpr());
1823  SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1824  if (Err)
1825  return std::move(Err);
1826 
1827  return Importer.getToContext().getDependentSizedMatrixType(
1828  ToElementType, ToRowExpr, ToColumnExpr, ToAttrLoc);
1829 }
1830 
1831 ExpectedType clang::ASTNodeImporter::VisitDependentVectorType(
1832  const clang::DependentVectorType *T) {
1833  Error Err = Error::success();
1834  QualType ToElementType = importChecked(Err, T->getElementType());
1835  Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1836  SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1837  if (Err)
1838  return std::move(Err);
1839 
1840  return Importer.getToContext().getDependentVectorType(
1841  ToElementType, ToSizeExpr, ToAttrLoc, T->getVectorKind());
1842 }
1843 
1844 ExpectedType clang::ASTNodeImporter::VisitObjCTypeParamType(
1845  const clang::ObjCTypeParamType *T) {
1846  Expected<ObjCTypeParamDecl *> ToDeclOrErr = import(T->getDecl());
1847  if (!ToDeclOrErr)
1848  return ToDeclOrErr.takeError();
1849 
1851  for (ObjCProtocolDecl *FromProtocol : T->getProtocols()) {
1852  Expected<ObjCProtocolDecl *> ToProtocolOrErr = import(FromProtocol);
1853  if (!ToProtocolOrErr)
1854  return ToProtocolOrErr.takeError();
1855  ToProtocols.push_back(*ToProtocolOrErr);
1856  }
1857 
1858  return Importer.getToContext().getObjCTypeParamType(*ToDeclOrErr,
1859  ToProtocols);
1860 }
1861 
1862 ExpectedType clang::ASTNodeImporter::VisitPipeType(const clang::PipeType *T) {
1863  ExpectedType ToElementTypeOrErr = import(T->getElementType());
1864  if (!ToElementTypeOrErr)
1865  return ToElementTypeOrErr.takeError();
1866 
1867  ASTContext &ToCtx = Importer.getToContext();
1868  if (T->isReadOnly())
1869  return ToCtx.getReadPipeType(*ToElementTypeOrErr);
1870  else
1871  return ToCtx.getWritePipeType(*ToElementTypeOrErr);
1872 }
1873 
1874 //----------------------------------------------------------------------------
1875 // Import Declarations
1876 //----------------------------------------------------------------------------
1878  NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
1879  DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) {
1880  // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop.
1881  // example: int struct_in_proto(struct data_t{int a;int b;} *d);
1882  // FIXME: We could support these constructs by importing a different type of
1883  // this parameter and by importing the original type of the parameter only
1884  // after the FunctionDecl is created. See
1885  // VisitFunctionDecl::UsedDifferentProtoType.
1886  DeclContext *OrigDC = D->getDeclContext();
1887  FunctionDecl *FunDecl;
1888  if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) &&
1889  FunDecl->hasBody()) {
1890  auto getLeafPointeeType = [](const Type *T) {
1891  while (T->isPointerType() || T->isArrayType()) {
1893  }
1894  return T;
1895  };
1896  for (const ParmVarDecl *P : FunDecl->parameters()) {
1897  const Type *LeafT =
1898  getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
1899  auto *RT = dyn_cast<RecordType>(LeafT);
1900  if (RT && RT->getDecl() == D) {
1901  Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
1902  << D->getDeclKindName();
1903  return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1904  }
1905  }
1906  }
1907 
1908  // Import the context of this declaration.
1909  if (Error Err = ImportDeclContext(D, DC, LexicalDC))
1910  return Err;
1911 
1912  // Import the name of this declaration.
1913  if (Error Err = importInto(Name, D->getDeclName()))
1914  return Err;
1915 
1916  // Import the location of this declaration.
1917  if (Error Err = importInto(Loc, D->getLocation()))
1918  return Err;
1919 
1920  ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
1921  if (ToD)
1922  if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
1923  return Err;
1924 
1925  return Error::success();
1926 }
1927 
1929  NamedDecl *&ToD, SourceLocation &Loc) {
1930 
1931  // Import the name of this declaration.
1932  if (Error Err = importInto(Name, D->getDeclName()))
1933  return Err;
1934 
1935  // Import the location of this declaration.
1936  if (Error Err = importInto(Loc, D->getLocation()))
1937  return Err;
1938 
1939  ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
1940  if (ToD)
1941  if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
1942  return Err;
1943 
1944  return Error::success();
1945 }
1946 
1948  if (!FromD)
1949  return Error::success();
1950 
1951  if (!ToD)
1952  if (Error Err = importInto(ToD, FromD))
1953  return Err;
1954 
1955  if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
1956  if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) {
1957  if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() &&
1958  !ToRecord->getDefinition()) {
1959  if (Error Err = ImportDefinition(FromRecord, ToRecord))
1960  return Err;
1961  }
1962  }
1963  return Error::success();
1964  }
1965 
1966  if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
1967  if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) {
1968  if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
1969  if (Error Err = ImportDefinition(FromEnum, ToEnum))
1970  return Err;
1971  }
1972  }
1973  return Error::success();
1974  }
1975 
1976  return Error::success();
1977 }
1978 
1979 Error
1981  const DeclarationNameInfo &From, DeclarationNameInfo& To) {
1982  // NOTE: To.Name and To.Loc are already imported.
1983  // We only have to import To.LocInfo.
1984  switch (To.getName().getNameKind()) {
1991  return Error::success();
1992 
1994  if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange()))
1995  To.setCXXOperatorNameRange(*ToRangeOrErr);
1996  else
1997  return ToRangeOrErr.takeError();
1998  return Error::success();
1999  }
2001  if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc()))
2002  To.setCXXLiteralOperatorNameLoc(*LocOrErr);
2003  else
2004  return LocOrErr.takeError();
2005  return Error::success();
2006  }
2010  if (auto ToTInfoOrErr = import(From.getNamedTypeInfo()))
2011  To.setNamedTypeInfo(*ToTInfoOrErr);
2012  else
2013  return ToTInfoOrErr.takeError();
2014  return Error::success();
2015  }
2016  }
2017  llvm_unreachable("Unknown name kind.");
2018 }
2019 
2020 Error
2022  if (Importer.isMinimalImport() && !ForceImport) {
2023  auto ToDCOrErr = Importer.ImportContext(FromDC);
2024  return ToDCOrErr.takeError();
2025  }
2026 
2027  // We use strict error handling in case of records and enums, but not
2028  // with e.g. namespaces.
2029  //
2030  // FIXME Clients of the ASTImporter should be able to choose an
2031  // appropriate error handling strategy for their needs. For instance,
2032  // they may not want to mark an entire namespace as erroneous merely
2033  // because there is an ODR error with two typedefs. As another example,
2034  // the client may allow EnumConstantDecls with same names but with
2035  // different values in two distinct translation units.
2036  ChildErrorHandlingStrategy HandleChildErrors(FromDC);
2037 
2038  auto MightNeedReordering = [](const Decl *D) {
2039  return isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<FriendDecl>(D);
2040  };
2041 
2042  // Import everything that might need reordering first.
2043  Error ChildErrors = Error::success();
2044  for (auto *From : FromDC->decls()) {
2045  if (!MightNeedReordering(From))
2046  continue;
2047 
2048  ExpectedDecl ImportedOrErr = import(From);
2049 
2050  // If we are in the process of ImportDefinition(...) for a RecordDecl we
2051  // want to make sure that we are also completing each FieldDecl. There
2052  // are currently cases where this does not happen and this is correctness
2053  // fix since operations such as code generation will expect this to be so.
2054  if (!ImportedOrErr) {
2055  HandleChildErrors.handleChildImportResult(ChildErrors,
2056  ImportedOrErr.takeError());
2057  continue;
2058  }
2059  FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
2060  Decl *ImportedDecl = *ImportedOrErr;
2061  FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
2062  if (FieldFrom && FieldTo) {
2063  Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
2064  HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
2065  }
2066  }
2067 
2068  // We reorder declarations in RecordDecls because they may have another order
2069  // in the "to" context than they have in the "from" context. This may happen
2070  // e.g when we import a class like this:
2071  // struct declToImport {
2072  // int a = c + b;
2073  // int b = 1;
2074  // int c = 2;
2075  // };
2076  // During the import of `a` we import first the dependencies in sequence,
2077  // thus the order would be `c`, `b`, `a`. We will get the normal order by
2078  // first removing the already imported members and then adding them in the
2079  // order as they appear in the "from" context.
2080  //
2081  // Keeping field order is vital because it determines structure layout.
2082  //
2083  // Here and below, we cannot call field_begin() method and its callers on
2084  // ToDC if it has an external storage. Calling field_begin() will
2085  // automatically load all the fields by calling
2086  // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would
2087  // call ASTImporter::Import(). This is because the ExternalASTSource
2088  // interface in LLDB is implemented by the means of the ASTImporter. However,
2089  // calling an import at this point would result in an uncontrolled import, we
2090  // must avoid that.
2091 
2092  auto ToDCOrErr = Importer.ImportContext(FromDC);
2093  if (!ToDCOrErr) {
2094  consumeError(std::move(ChildErrors));
2095  return ToDCOrErr.takeError();
2096  }
2097 
2098  if (const auto *FromRD = dyn_cast<RecordDecl>(FromDC)) {
2099  DeclContext *ToDC = *ToDCOrErr;
2100  // Remove all declarations, which may be in wrong order in the
2101  // lexical DeclContext and then add them in the proper order.
2102  for (auto *D : FromRD->decls()) {
2103  if (!MightNeedReordering(D))
2104  continue;
2105 
2106  assert(D && "DC contains a null decl");
2107  if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
2108  // Remove only the decls which we successfully imported.
2109  assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
2110  // Remove the decl from its wrong place in the linked list.
2111  ToDC->removeDecl(ToD);
2112  // Add the decl to the end of the linked list.
2113  // This time it will be at the proper place because the enclosing for
2114  // loop iterates in the original (good) order of the decls.
2115  ToDC->addDeclInternal(ToD);
2116  }
2117  }
2118  }
2119 
2120  // Import everything else.
2121  for (auto *From : FromDC->decls()) {
2122  if (MightNeedReordering(From))
2123  continue;
2124 
2125  ExpectedDecl ImportedOrErr = import(From);
2126  if (!ImportedOrErr)
2127  HandleChildErrors.handleChildImportResult(ChildErrors,
2128  ImportedOrErr.takeError());
2129  }
2130 
2131  return ChildErrors;
2132 }
2133 
2135  const FieldDecl *To) {
2136  RecordDecl *FromRecordDecl = nullptr;
2137  RecordDecl *ToRecordDecl = nullptr;
2138  // If we have a field that is an ArrayType we need to check if the array
2139  // element is a RecordDecl and if so we need to import the definition.
2140  QualType FromType = From->getType();
2141  QualType ToType = To->getType();
2142  if (FromType->isArrayType()) {
2143  // getBaseElementTypeUnsafe(...) handles multi-dimensonal arrays for us.
2144  FromRecordDecl = FromType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2145  ToRecordDecl = ToType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2146  }
2147 
2148  if (!FromRecordDecl || !ToRecordDecl) {
2149  const RecordType *RecordFrom = FromType->getAs<RecordType>();
2150  const RecordType *RecordTo = ToType->getAs<RecordType>();
2151 
2152  if (RecordFrom && RecordTo) {
2153  FromRecordDecl = RecordFrom->getDecl();
2154  ToRecordDecl = RecordTo->getDecl();
2155  }
2156  }
2157 
2158  if (FromRecordDecl && ToRecordDecl) {
2159  if (FromRecordDecl->isCompleteDefinition() &&
2160  !ToRecordDecl->isCompleteDefinition())
2161  return ImportDefinition(FromRecordDecl, ToRecordDecl);
2162  }
2163 
2164  return Error::success();
2165 }
2166 
2168  Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) {
2169  auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext());
2170  if (!ToDCOrErr)
2171  return ToDCOrErr.takeError();
2172  ToDC = *ToDCOrErr;
2173 
2174  if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) {
2175  auto ToLexicalDCOrErr = Importer.ImportContext(
2176  FromD->getLexicalDeclContext());
2177  if (!ToLexicalDCOrErr)
2178  return ToLexicalDCOrErr.takeError();
2179  ToLexicalDC = *ToLexicalDCOrErr;
2180  } else
2181  ToLexicalDC = ToDC;
2182 
2183  return Error::success();
2184 }
2185 
2187  const CXXRecordDecl *From, CXXRecordDecl *To) {
2188  assert(From->isCompleteDefinition() && To->getDefinition() == To &&
2189  "Import implicit methods to or from non-definition");
2190 
2191  for (CXXMethodDecl *FromM : From->methods())
2192  if (FromM->isImplicit()) {
2193  Expected<CXXMethodDecl *> ToMOrErr = import(FromM);
2194  if (!ToMOrErr)
2195  return ToMOrErr.takeError();
2196  }
2197 
2198  return Error::success();
2199 }
2200 
2202  ASTImporter &Importer) {
2203  if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
2204  if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef))
2205  To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr));
2206  else
2207  return ToTypedefOrErr.takeError();
2208  }
2209  return Error::success();
2210 }
2211 
2214  auto DefinitionCompleter = [To]() {
2215  // There are cases in LLDB when we first import a class without its
2216  // members. The class will have DefinitionData, but no members. Then,
2217  // importDefinition is called from LLDB, which tries to get the members, so
2218  // when we get here, the class already has the DefinitionData set, so we
2219  // must unset the CompleteDefinition here to be able to complete again the
2220  // definition.
2221  To->setCompleteDefinition(false);
2222  To->completeDefinition();
2223  };
2224 
2225  if (To->getDefinition() || To->isBeingDefined()) {
2226  if (Kind == IDK_Everything ||
2227  // In case of lambdas, the class already has a definition ptr set, but
2228  // the contained decls are not imported yet. Also, isBeingDefined was
2229  // set in CXXRecordDecl::CreateLambda. We must import the contained
2230  // decls here and finish the definition.
2232  if (To->isLambda()) {
2233  auto *FromCXXRD = cast<CXXRecordDecl>(From);
2234  SmallVector<LambdaCapture, 8> ToCaptures;
2235  ToCaptures.reserve(FromCXXRD->capture_size());
2236  for (const auto &FromCapture : FromCXXRD->captures()) {
2237  if (auto ToCaptureOrErr = import(FromCapture))
2238  ToCaptures.push_back(*ToCaptureOrErr);
2239  else
2240  return ToCaptureOrErr.takeError();
2241  }
2242  cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(),
2243  ToCaptures);
2244  }
2245 
2246  Error Result = ImportDeclContext(From, /*ForceImport=*/true);
2247  // Finish the definition of the lambda, set isBeingDefined to false.
2248  if (To->isLambda())
2249  DefinitionCompleter();
2250  return Result;
2251  }
2252 
2253  return Error::success();
2254  }
2255 
2256  To->startDefinition();
2257  // Set the definition to complete even if it is really not complete during
2258  // import. Some AST constructs (expressions) require the record layout
2259  // to be calculated (see 'clang::computeDependence') at the time they are
2260  // constructed. Import of such AST node is possible during import of the
2261  // same record, there is no way to have a completely defined record (all
2262  // fields imported) at that time without multiple AST import passes.
2263  if (!Importer.isMinimalImport())
2264  To->setCompleteDefinition(true);
2265  // Complete the definition even if error is returned.
2266  // The RecordDecl may be already part of the AST so it is better to
2267  // have it in complete state even if something is wrong with it.
2268  auto DefinitionCompleterScopeExit =
2269  llvm::make_scope_exit(DefinitionCompleter);
2270 
2271  if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2272  return Err;
2273 
2274  // Add base classes.
2275  auto *ToCXX = dyn_cast<CXXRecordDecl>(To);
2276  auto *FromCXX = dyn_cast<CXXRecordDecl>(From);
2277  if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) {
2278 
2279  struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
2280  struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2281 
2282  #define FIELD(Name, Width, Merge) \
2283  ToData.Name = FromData.Name;
2284  #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2285 
2286  // Copy over the data stored in RecordDeclBits
2287  ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions());
2288 
2290  for (const auto &Base1 : FromCXX->bases()) {
2291  ExpectedType TyOrErr = import(Base1.getType());
2292  if (!TyOrErr)
2293  return TyOrErr.takeError();
2294 
2295  SourceLocation EllipsisLoc;
2296  if (Base1.isPackExpansion()) {
2297  if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc()))
2298  EllipsisLoc = *LocOrErr;
2299  else
2300  return LocOrErr.takeError();
2301  }
2302 
2303  // Ensure that we have a definition for the base.
2304  if (Error Err =
2305  ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
2306  return Err;
2307 
2308  auto RangeOrErr = import(Base1.getSourceRange());
2309  if (!RangeOrErr)
2310  return RangeOrErr.takeError();
2311 
2312  auto TSIOrErr = import(Base1.getTypeSourceInfo());
2313  if (!TSIOrErr)
2314  return TSIOrErr.takeError();
2315 
2316  Bases.push_back(
2317  new (Importer.getToContext()) CXXBaseSpecifier(
2318  *RangeOrErr,
2319  Base1.isVirtual(),
2320  Base1.isBaseOfClass(),
2321  Base1.getAccessSpecifierAsWritten(),
2322  *TSIOrErr,
2323  EllipsisLoc));
2324  }
2325  if (!Bases.empty())
2326  ToCXX->setBases(Bases.data(), Bases.size());
2327  }
2328 
2330  if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2331  return Err;
2332  }
2333 
2334  return Error::success();
2335 }
2336 
2338  if (To->getAnyInitializer())
2339  return Error::success();
2340 
2341  Expr *FromInit = From->getInit();
2342  if (!FromInit)
2343  return Error::success();
2344 
2345  ExpectedExpr ToInitOrErr = import(FromInit);
2346  if (!ToInitOrErr)
2347  return ToInitOrErr.takeError();
2348 
2349  To->setInit(*ToInitOrErr);
2350  if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) {
2351  EvaluatedStmt *ToEval = To->ensureEvaluatedStmt();
2352  ToEval->HasConstantInitialization = FromEval->HasConstantInitialization;
2353  ToEval->HasConstantDestruction = FromEval->HasConstantDestruction;
2354  // FIXME: Also import the initializer value.
2355  }
2356 
2357  // FIXME: Other bits to merge?
2358  return Error::success();
2359 }
2360 
2363  if (To->getDefinition() || To->isBeingDefined()) {
2364  if (Kind == IDK_Everything)
2365  return ImportDeclContext(From, /*ForceImport=*/true);
2366  return Error::success();
2367  }
2368 
2369  To->startDefinition();
2370 
2371  if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2372  return Err;
2373 
2374  ExpectedType ToTypeOrErr =
2375  import(Importer.getFromContext().getTypeDeclType(From));
2376  if (!ToTypeOrErr)
2377  return ToTypeOrErr.takeError();
2378 
2379  ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType());
2380  if (!ToPromotionTypeOrErr)
2381  return ToPromotionTypeOrErr.takeError();
2382 
2384  if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2385  return Err;
2386 
2387  // FIXME: we might need to merge the number of positive or negative bits
2388  // if the enumerator lists don't match.
2389  To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr,
2390  From->getNumPositiveBits(),
2391  From->getNumNegativeBits());
2392  return Error::success();
2393 }
2394 
2396  ArrayRef<TemplateArgument> FromArgs,
2398  for (const auto &Arg : FromArgs) {
2399  if (auto ToOrErr = import(Arg))
2400  ToArgs.push_back(*ToOrErr);
2401  else
2402  return ToOrErr.takeError();
2403  }
2404 
2405  return Error::success();
2406 }
2407 
2408 // FIXME: Do not forget to remove this and use only 'import'.
2411  return import(From);
2412 }
2413 
2414 template <typename InContainerTy>
2416  const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) {
2417  for (const auto &FromLoc : Container) {
2418  if (auto ToLocOrErr = import(FromLoc))
2419  ToTAInfo.addArgument(*ToLocOrErr);
2420  else
2421  return ToLocOrErr.takeError();
2422  }
2423  return Error::success();
2424 }
2425 
2430 }
2431 
2432 bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
2433  bool IgnoreTemplateParmDepth) {
2434  // Eliminate a potential failure point where we attempt to re-import
2435  // something we're trying to import while completing ToRecord.
2436  Decl *ToOrigin = Importer.GetOriginalDecl(To);
2437  if (ToOrigin) {
2438  To = ToOrigin;
2439  }
2440 
2442  Importer.getFromContext(), Importer.getToContext(),
2444  /*StrictTypeSpelling=*/false, Complain, /*ErrorOnTagTypeMismatch=*/false,
2445  IgnoreTemplateParmDepth);
2446  return Ctx.IsEquivalent(From, To);
2447 }
2448 
2450  Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2451  << D->getDeclKindName();
2452  return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2453 }
2454 
2456  Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2457  << D->getDeclKindName();
2458  return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2459 }
2460 
2462  // Import the context of this declaration.
2463  DeclContext *DC, *LexicalDC;
2464  if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2465  return std::move(Err);
2466 
2467  // Import the location of this declaration.
2468  ExpectedSLoc LocOrErr = import(D->getLocation());
2469  if (!LocOrErr)
2470  return LocOrErr.takeError();
2471 
2472  EmptyDecl *ToD;
2473  if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr))
2474  return ToD;
2475 
2476  ToD->setLexicalDeclContext(LexicalDC);
2477  LexicalDC->addDeclInternal(ToD);
2478  return ToD;
2479 }
2480 
2482  TranslationUnitDecl *ToD =
2483  Importer.getToContext().getTranslationUnitDecl();
2484 
2485  Importer.MapImported(D, ToD);
2486 
2487  return ToD;
2488 }
2489 
2491  DeclContext *DC, *LexicalDC;
2492  DeclarationName Name;
2494  NamedDecl *ToND;
2495  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
2496  return std::move(Err);
2497  if (ToND)
2498  return ToND;
2499 
2500  BindingDecl *ToD;
2501  if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
2502  Name.getAsIdentifierInfo()))
2503  return ToD;
2504 
2505  Error Err = Error::success();
2506  QualType ToType = importChecked(Err, D->getType());
2507  Expr *ToBinding = importChecked(Err, D->getBinding());
2508  ValueDecl *ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl());
2509  if (Err)
2510  return std::move(Err);
2511 
2512  ToD->setBinding(ToType, ToBinding);
2513  ToD->setDecomposedDecl(ToDecomposedDecl);
2514  addDeclToContexts(D, ToD);
2515 
2516  return ToD;
2517 }
2518 
2520  ExpectedSLoc LocOrErr = import(D->getLocation());
2521  if (!LocOrErr)
2522  return LocOrErr.takeError();
2523  auto ColonLocOrErr = import(D->getColonLoc());
2524  if (!ColonLocOrErr)
2525  return ColonLocOrErr.takeError();
2526 
2527  // Import the context of this declaration.
2528  auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2529  if (!DCOrErr)
2530  return DCOrErr.takeError();
2531  DeclContext *DC = *DCOrErr;
2532 
2533  AccessSpecDecl *ToD;
2534  if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(),
2535  DC, *LocOrErr, *ColonLocOrErr))
2536  return ToD;
2537 
2538  // Lexical DeclContext and Semantic DeclContext
2539  // is always the same for the accessSpec.
2540  ToD->setLexicalDeclContext(DC);
2541  DC->addDeclInternal(ToD);
2542 
2543  return ToD;
2544 }
2545 
2547  auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2548  if (!DCOrErr)
2549  return DCOrErr.takeError();
2550  DeclContext *DC = *DCOrErr;
2551  DeclContext *LexicalDC = DC;
2552 
2553  Error Err = Error::success();
2554  auto ToLocation = importChecked(Err, D->getLocation());
2555  auto ToRParenLoc = importChecked(Err, D->getRParenLoc());
2556  auto ToAssertExpr = importChecked(Err, D->getAssertExpr());
2557  auto ToMessage = importChecked(Err, D->getMessage());
2558  if (Err)
2559  return std::move(Err);
2560 
2561  StaticAssertDecl *ToD;
2562  if (GetImportedOrCreateDecl(
2563  ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
2564  ToRParenLoc, D->isFailed()))
2565  return ToD;
2566 
2567  ToD->setLexicalDeclContext(LexicalDC);
2568  LexicalDC->addDeclInternal(ToD);
2569  return ToD;
2570 }
2571 
2573  // Import the major distinguishing characteristics of this namespace.
2574  DeclContext *DC, *LexicalDC;
2575  DeclarationName Name;
2577  NamedDecl *ToD;
2578  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2579  return std::move(Err);
2580  if (ToD)
2581  return ToD;
2582 
2583  NamespaceDecl *MergeWithNamespace = nullptr;
2584  if (!Name) {
2585  // This is an anonymous namespace. Adopt an existing anonymous
2586  // namespace if we can.
2587  // FIXME: Not testable.
2588  if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2589  MergeWithNamespace = TU->getAnonymousNamespace();
2590  else
2591  MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace();
2592  } else {
2593  SmallVector<NamedDecl *, 4> ConflictingDecls;
2594  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2595  for (auto *FoundDecl : FoundDecls) {
2597  continue;
2598 
2599  if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) {
2600  MergeWithNamespace = FoundNS;
2601  ConflictingDecls.clear();
2602  break;
2603  }
2604 
2605  ConflictingDecls.push_back(FoundDecl);
2606  }
2607 
2608  if (!ConflictingDecls.empty()) {
2609  ExpectedName NameOrErr = Importer.HandleNameConflict(
2610  Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(),
2611  ConflictingDecls.size());
2612  if (NameOrErr)
2613  Name = NameOrErr.get();
2614  else
2615  return NameOrErr.takeError();
2616  }
2617  }
2618 
2619  ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2620  if (!BeginLocOrErr)
2621  return BeginLocOrErr.takeError();
2622  ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
2623  if (!RBraceLocOrErr)
2624  return RBraceLocOrErr.takeError();
2625 
2626  // Create the "to" namespace, if needed.
2627  NamespaceDecl *ToNamespace = MergeWithNamespace;
2628  if (!ToNamespace) {
2629  if (GetImportedOrCreateDecl(ToNamespace, D, Importer.getToContext(), DC,
2630  D->isInline(), *BeginLocOrErr, Loc,
2631  Name.getAsIdentifierInfo(),
2632  /*PrevDecl=*/nullptr, D->isNested()))
2633  return ToNamespace;
2634  ToNamespace->setRBraceLoc(*RBraceLocOrErr);
2635  ToNamespace->setLexicalDeclContext(LexicalDC);
2636  LexicalDC->addDeclInternal(ToNamespace);
2637 
2638  // If this is an anonymous namespace, register it as the anonymous
2639  // namespace within its context.
2640  if (!Name) {
2641  if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2642  TU->setAnonymousNamespace(ToNamespace);
2643  else
2644  cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
2645  }
2646  }
2647  Importer.MapImported(D, ToNamespace);
2648 
2649  if (Error Err = ImportDeclContext(D))
2650  return std::move(Err);
2651 
2652  return ToNamespace;
2653 }
2654 
2656  // Import the major distinguishing characteristics of this namespace.
2657  DeclContext *DC, *LexicalDC;
2658  DeclarationName Name;
2660  NamedDecl *LookupD;
2661  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc))
2662  return std::move(Err);
2663  if (LookupD)
2664  return LookupD;
2665 
2666  // NOTE: No conflict resolution is done for namespace aliases now.
2667 
2668  Error Err = Error::success();
2669  auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc());
2670  auto ToAliasLoc = importChecked(Err, D->getAliasLoc());
2671  auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
2672  auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc());
2673  auto ToNamespace = importChecked(Err, D->getNamespace());
2674  if (Err)
2675  return std::move(Err);
2676 
2677  IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
2678 
2679  NamespaceAliasDecl *ToD;
2680  if (GetImportedOrCreateDecl(
2681  ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
2682  ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
2683  return ToD;
2684 
2685  ToD->setLexicalDeclContext(LexicalDC);
2686  LexicalDC->addDeclInternal(ToD);
2687 
2688  return ToD;
2689 }
2690 
2693  // Import the major distinguishing characteristics of this typedef.
2694  DeclarationName Name;
2696  NamedDecl *ToD;
2697  // Do not import the DeclContext, we will import it once the TypedefNameDecl
2698  // is created.
2699  if (Error Err = ImportDeclParts(D, Name, ToD, Loc))
2700  return std::move(Err);
2701  if (ToD)
2702  return ToD;
2703 
2704  DeclContext *DC = cast_or_null<DeclContext>(
2705  Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext())));
2706  DeclContext *LexicalDC =
2707  cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull(
2708  cast<Decl>(D->getLexicalDeclContext())));
2709 
2710  // If this typedef is not in block scope, determine whether we've
2711  // seen a typedef with the same name (that we can merge with) or any
2712  // other entity by that name (which name lookup could conflict with).
2713  // Note: Repeated typedefs are not valid in C99:
2714  // 'typedef int T; typedef int T;' is invalid
2715  // We do not care about this now.
2716  if (DC && !DC->isFunctionOrMethod()) {
2717  SmallVector<NamedDecl *, 4> ConflictingDecls;
2718  unsigned IDNS = Decl::IDNS_Ordinary;
2719  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2720  for (auto *FoundDecl : FoundDecls) {
2721  if (!FoundDecl->isInIdentifierNamespace(IDNS))
2722  continue;
2723  if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
2724  if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D))
2725  continue;
2726 
2727  QualType FromUT = D->getUnderlyingType();
2728  QualType FoundUT = FoundTypedef->getUnderlyingType();
2729  if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) {
2730  // If the underlying declarations are unnamed records these can be
2731  // imported as different types. We should create a distinct typedef
2732  // node in this case.
2733  // If we found an existing underlying type with a record in a
2734  // different context (than the imported), this is already reason for
2735  // having distinct typedef nodes for these.
2736  // Again this can create situation like
2737  // 'typedef int T; typedef int T;' but this is hard to avoid without
2738  // a rename strategy at import.
2739  if (!FromUT.isNull() && !FoundUT.isNull()) {
2740  RecordDecl *FromR = FromUT->getAsRecordDecl();
2741  RecordDecl *FoundR = FoundUT->getAsRecordDecl();
2742  if (FromR && FoundR &&
2743  !hasSameVisibilityContextAndLinkage(FoundR, FromR))
2744  continue;
2745  }
2746  // If the "From" context has a complete underlying type but we
2747  // already have a complete underlying type then return with that.
2748  if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
2749  return Importer.MapImported(D, FoundTypedef);
2750  // FIXME Handle redecl chain. When you do that make consistent changes
2751  // in ASTImporterLookupTable too.
2752  } else {
2753  ConflictingDecls.push_back(FoundDecl);
2754  }
2755  }
2756  }
2757 
2758  if (!ConflictingDecls.empty()) {
2759  ExpectedName NameOrErr = Importer.HandleNameConflict(
2760  Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
2761  if (NameOrErr)
2762  Name = NameOrErr.get();
2763  else
2764  return NameOrErr.takeError();
2765  }
2766  }
2767 
2768  Error Err = Error::success();
2770  auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
2771  auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
2772  if (Err)
2773  return std::move(Err);
2774 
2775  // Create the new typedef node.
2776  // FIXME: ToUnderlyingType is not used.
2777  (void)ToUnderlyingType;
2778  TypedefNameDecl *ToTypedef;
2779  if (IsAlias) {
2780  if (GetImportedOrCreateDecl<TypeAliasDecl>(
2781  ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
2782  Name.getAsIdentifierInfo(), ToTypeSourceInfo))
2783  return ToTypedef;
2784  } else if (GetImportedOrCreateDecl<TypedefDecl>(
2785  ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
2786  Name.getAsIdentifierInfo(), ToTypeSourceInfo))
2787  return ToTypedef;
2788 
2789  // Import the DeclContext and set it to the Typedef.
2790  if ((Err = ImportDeclContext(D, DC, LexicalDC)))
2791  return std::move(Err);
2792  ToTypedef->setDeclContext(DC);
2793  ToTypedef->setLexicalDeclContext(LexicalDC);
2794  // Add to the lookupTable because we could not do that in MapImported.
2795  Importer.AddToLookupTable(ToTypedef);
2796 
2797  ToTypedef->setAccess(D->getAccess());
2798 
2799  // Templated declarations should not appear in DeclContext.
2800  TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr;
2801  if (!FromAlias || !FromAlias->getDescribedAliasTemplate())
2802  LexicalDC->addDeclInternal(ToTypedef);
2803 
2804  return ToTypedef;
2805 }
2806 
2808  return VisitTypedefNameDecl(D, /*IsAlias=*/false);
2809 }
2810 
2812  return VisitTypedefNameDecl(D, /*IsAlias=*/true);
2813 }
2814 
2817  // Import the major distinguishing characteristics of this typedef.
2818  DeclContext *DC, *LexicalDC;
2819  DeclarationName Name;
2821  NamedDecl *FoundD;
2822  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc))
2823  return std::move(Err);
2824  if (FoundD)
2825  return FoundD;
2826 
2827  // If this typedef is not in block scope, determine whether we've
2828  // seen a typedef with the same name (that we can merge with) or any
2829  // other entity by that name (which name lookup could conflict with).
2830  if (!DC->isFunctionOrMethod()) {
2831  SmallVector<NamedDecl *, 4> ConflictingDecls;
2832  unsigned IDNS = Decl::IDNS_Ordinary;
2833  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2834  for (auto *FoundDecl : FoundDecls) {
2835  if (!FoundDecl->isInIdentifierNamespace(IDNS))
2836  continue;
2837  if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) {
2838  if (IsStructuralMatch(D, FoundAlias))
2839  return Importer.MapImported(D, FoundAlias);
2840  ConflictingDecls.push_back(FoundDecl);
2841  }
2842  }
2843 
2844  if (!ConflictingDecls.empty()) {
2845  ExpectedName NameOrErr = Importer.HandleNameConflict(
2846  Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
2847  if (NameOrErr)
2848  Name = NameOrErr.get();
2849  else
2850  return NameOrErr.takeError();
2851  }
2852  }
2853 
2854  Error Err = Error::success();
2855  auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
2856  auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl());
2857  if (Err)
2858  return std::move(Err);
2859 
2860  TypeAliasTemplateDecl *ToAlias;
2861  if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc,
2862  Name, ToTemplateParameters, ToTemplatedDecl))
2863  return ToAlias;
2864 
2865  ToTemplatedDecl->setDescribedAliasTemplate(ToAlias);
2866 
2867  ToAlias->setAccess(D->getAccess());
2868  ToAlias->setLexicalDeclContext(LexicalDC);
2869  LexicalDC->addDeclInternal(ToAlias);
2870  if (DC != Importer.getToContext().getTranslationUnitDecl())
2871  updateLookupTableForTemplateParameters(*ToTemplateParameters);
2872  return ToAlias;
2873 }
2874 
2876  // Import the major distinguishing characteristics of this label.
2877  DeclContext *DC, *LexicalDC;
2878  DeclarationName Name;
2880  NamedDecl *ToD;
2881  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2882  return std::move(Err);
2883  if (ToD)
2884  return ToD;
2885 
2886  assert(LexicalDC->isFunctionOrMethod());
2887 
2888  LabelDecl *ToLabel;
2889  if (D->isGnuLocal()) {
2890  ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2891  if (!BeginLocOrErr)
2892  return BeginLocOrErr.takeError();
2893  if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
2894  Name.getAsIdentifierInfo(), *BeginLocOrErr))
2895  return ToLabel;
2896 
2897  } else {
2898  if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
2899  Name.getAsIdentifierInfo()))
2900  return ToLabel;
2901 
2902  }
2903 
2904  Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
2905  if (!ToStmtOrErr)
2906  return ToStmtOrErr.takeError();
2907 
2908  ToLabel->setStmt(*ToStmtOrErr);
2909  ToLabel->setLexicalDeclContext(LexicalDC);
2910  LexicalDC->addDeclInternal(ToLabel);
2911  return ToLabel;
2912 }
2913 
2915  // Import the major distinguishing characteristics of this enum.
2916  DeclContext *DC, *LexicalDC;
2917  DeclarationName Name;
2919  NamedDecl *ToD;
2920  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2921  return std::move(Err);
2922  if (ToD)
2923  return ToD;
2924 
2925  // Figure out what enum name we're looking for.
2926  unsigned IDNS = Decl::IDNS_Tag;
2927  DeclarationName SearchName = Name;
2928  if (!SearchName && D->getTypedefNameForAnonDecl()) {
2929  if (Error Err = importInto(
2930  SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
2931  return std::move(Err);
2932  IDNS = Decl::IDNS_Ordinary;
2933  } else if (Importer.getToContext().getLangOpts().CPlusPlus)
2934  IDNS |= Decl::IDNS_Ordinary;
2935 
2936  // We may already have an enum of the same name; try to find and match it.
2937  EnumDecl *PrevDecl = nullptr;
2938  if (!DC->isFunctionOrMethod() && SearchName) {
2939  SmallVector<NamedDecl *, 4> ConflictingDecls;
2940  auto FoundDecls =
2941  Importer.findDeclsInToCtx(DC, SearchName);
2942  for (auto *FoundDecl : FoundDecls) {
2943  if (!FoundDecl->isInIdentifierNamespace(IDNS))
2944  continue;
2945 
2946  if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
2947  if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
2948  FoundDecl = Tag->getDecl();
2949  }
2950 
2951  if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) {
2952  if (!hasSameVisibilityContextAndLinkage(FoundEnum, D))
2953  continue;
2954  if (IsStructuralMatch(D, FoundEnum)) {
2955  EnumDecl *FoundDef = FoundEnum->getDefinition();
2956  if (D->isThisDeclarationADefinition() && FoundDef)
2957  return Importer.MapImported(D, FoundDef);
2958  PrevDecl = FoundEnum->getMostRecentDecl();
2959  break;
2960  }
2961  ConflictingDecls.push_back(FoundDecl);
2962  }
2963  }
2964 
2965  if (!ConflictingDecls.empty()) {
2966  ExpectedName NameOrErr = Importer.HandleNameConflict(
2967  SearchName, DC, IDNS, ConflictingDecls.data(),
2968  ConflictingDecls.size());
2969  if (NameOrErr)
2970  Name = NameOrErr.get();
2971  else
2972  return NameOrErr.takeError();
2973  }
2974  }
2975 
2976  Error Err = Error::success();
2977  auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
2978  auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
2979  auto ToIntegerType = importChecked(Err, D->getIntegerType());
2980  auto ToBraceRange = importChecked(Err, D->getBraceRange());
2981  if (Err)
2982  return std::move(Err);
2983 
2984  // Create the enum declaration.
2985  EnumDecl *D2;
2986  if (GetImportedOrCreateDecl(
2987  D2, D, Importer.getToContext(), DC, ToBeginLoc,
2988  Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(),
2989  D->isScopedUsingClassTag(), D->isFixed()))
2990  return D2;
2991 
2992  D2->setQualifierInfo(ToQualifierLoc);
2993  D2->setIntegerType(ToIntegerType);
2994  D2->setBraceRange(ToBraceRange);
2995  D2->setAccess(D->getAccess());
2996  D2->setLexicalDeclContext(LexicalDC);
2997  addDeclToContexts(D, D2);
2998 
2999  if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
3000  TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
3001  EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
3002  if (Expected<EnumDecl *> ToInstOrErr = import(FromInst))
3003  D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
3004  else
3005  return ToInstOrErr.takeError();
3006  if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
3008  else
3009  return POIOrErr.takeError();
3010  }
3011 
3012  // Import the definition
3013  if (D->isCompleteDefinition())
3014  if (Error Err = ImportDefinition(D, D2))
3015  return std::move(Err);
3016 
3017  return D2;
3018 }
3019 
3021  bool IsFriendTemplate = false;
3022  if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3023  IsFriendTemplate =
3024  DCXX->getDescribedClassTemplate() &&
3025  DCXX->getDescribedClassTemplate()->getFriendObjectKind() !=
3027  }
3028 
3029  // Import the major distinguishing characteristics of this record.
3030  DeclContext *DC = nullptr, *LexicalDC = nullptr;
3031  DeclarationName Name;
3033  NamedDecl *ToD = nullptr;
3034  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3035  return std::move(Err);
3036  if (ToD)
3037  return ToD;
3038 
3039  // Figure out what structure name we're looking for.
3040  unsigned IDNS = Decl::IDNS_Tag;
3041  DeclarationName SearchName = Name;
3042  if (!SearchName && D->getTypedefNameForAnonDecl()) {
3043  if (Error Err = importInto(
3044  SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3045  return std::move(Err);
3046  IDNS = Decl::IDNS_Ordinary;
3047  } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3049 
3050  bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
3051  : DC->isDependentContext();
3052  bool DependentFriend = IsFriendTemplate && IsDependentContext;
3053 
3054  // We may already have a record of the same name; try to find and match it.
3055  RecordDecl *PrevDecl = nullptr;
3056  if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
3057  SmallVector<NamedDecl *, 4> ConflictingDecls;
3058  auto FoundDecls =
3059  Importer.findDeclsInToCtx(DC, SearchName);
3060  if (!FoundDecls.empty()) {
3061  // We're going to have to compare D against potentially conflicting Decls,
3062  // so complete it.
3065  }
3066 
3067  for (auto *FoundDecl : FoundDecls) {
3068  if (!FoundDecl->isInIdentifierNamespace(IDNS))
3069  continue;
3070 
3071  Decl *Found = FoundDecl;
3072  if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
3073  if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3074  Found = Tag->getDecl();
3075  }
3076 
3077  if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) {
3078  // Do not emit false positive diagnostic in case of unnamed
3079  // struct/union and in case of anonymous structs. Would be false
3080  // because there may be several anonymous/unnamed structs in a class.
3081  // E.g. these are both valid:
3082  // struct A { // unnamed structs
3083  // struct { struct A *next; } entry0;
3084  // struct { struct A *next; } entry1;
3085  // };
3086  // struct X { struct { int a; }; struct { int b; }; }; // anon structs
3087  if (!SearchName)
3088  if (!IsStructuralMatch(D, FoundRecord, false))
3089  continue;
3090 
3091  if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
3092  continue;
3093 
3094  if (IsStructuralMatch(D, FoundRecord)) {
3095  RecordDecl *FoundDef = FoundRecord->getDefinition();
3096  if (D->isThisDeclarationADefinition() && FoundDef) {
3097  // FIXME: Structural equivalence check should check for same
3098  // user-defined methods.
3099  Importer.MapImported(D, FoundDef);
3100  if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3101  auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef);
3102  assert(FoundCXX && "Record type mismatch");
3103 
3104  if (!Importer.isMinimalImport())
3105  // FoundDef may not have every implicit method that D has
3106  // because implicit methods are created only if they are used.
3107  if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
3108  return std::move(Err);
3109  }
3110  }
3111  PrevDecl = FoundRecord->getMostRecentDecl();
3112  break;
3113  }
3114  ConflictingDecls.push_back(FoundDecl);
3115  } // kind is RecordDecl
3116  } // for
3117 
3118  if (!ConflictingDecls.empty() && SearchName) {
3119  ExpectedName NameOrErr = Importer.HandleNameConflict(
3120  SearchName, DC, IDNS, ConflictingDecls.data(),
3121  ConflictingDecls.size());
3122  if (NameOrErr)
3123  Name = NameOrErr.get();
3124  else
3125  return NameOrErr.takeError();
3126  }
3127  }
3128 
3129  ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3130  if (!BeginLocOrErr)
3131  return BeginLocOrErr.takeError();
3132 
3133  // Create the record declaration.
3134  RecordDecl *D2 = nullptr;
3135  CXXRecordDecl *D2CXX = nullptr;
3136  if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3137  if (DCXX->isLambda()) {
3138  auto TInfoOrErr = import(DCXX->getLambdaTypeInfo());
3139  if (!TInfoOrErr)
3140  return TInfoOrErr.takeError();
3141  if (GetImportedOrCreateSpecialDecl(
3142  D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(),
3143  DC, *TInfoOrErr, Loc, DCXX->getLambdaDependencyKind(),
3144  DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault()))
3145  return D2CXX;
3146  CXXRecordDecl::LambdaNumbering Numbering = DCXX->getLambdaNumbering();
3147  ExpectedDecl CDeclOrErr = import(Numbering.ContextDecl);
3148  if (!CDeclOrErr)
3149  return CDeclOrErr.takeError();
3150  Numbering.ContextDecl = *CDeclOrErr;
3151  D2CXX->setLambdaNumbering(Numbering);
3152  } else if (DCXX->isInjectedClassName()) {
3153  // We have to be careful to do a similar dance to the one in
3154  // Sema::ActOnStartCXXMemberDeclarations
3155  const bool DelayTypeCreation = true;
3156  if (GetImportedOrCreateDecl(
3157  D2CXX, D, Importer.getToContext(), D->getTagKind(), DC,
3158  *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(),
3159  cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation))
3160  return D2CXX;
3161  Importer.getToContext().getTypeDeclType(
3162  D2CXX, dyn_cast<CXXRecordDecl>(DC));
3163  } else {
3164  if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
3165  D->getTagKind(), DC, *BeginLocOrErr, Loc,
3166  Name.getAsIdentifierInfo(),
3167  cast_or_null<CXXRecordDecl>(PrevDecl)))
3168  return D2CXX;
3169  }
3170 
3171  D2 = D2CXX;
3172  D2->setAccess(D->getAccess());
3173  D2->setLexicalDeclContext(LexicalDC);
3174  addDeclToContexts(D, D2);
3175 
3176  if (ClassTemplateDecl *FromDescribed =
3177  DCXX->getDescribedClassTemplate()) {
3178  ClassTemplateDecl *ToDescribed;
3179  if (Error Err = importInto(ToDescribed, FromDescribed))
3180  return std::move(Err);
3181  D2CXX->setDescribedClassTemplate(ToDescribed);
3182  if (!DCXX->isInjectedClassName() && !IsFriendTemplate) {
3183  // In a record describing a template the type should be an
3184  // InjectedClassNameType (see Sema::CheckClassTemplate). Update the
3185  // previously set type to the correct value here (ToDescribed is not
3186  // available at record create).
3187  CXXRecordDecl *Injected = nullptr;
3188  for (NamedDecl *Found : D2CXX->noload_lookup(Name)) {
3189  auto *Record = dyn_cast<CXXRecordDecl>(Found);
3190  if (Record && Record->isInjectedClassName()) {
3191  Injected = Record;
3192  break;
3193  }
3194  }
3195  // Create an injected type for the whole redecl chain.
3196  // The chain may contain an already existing injected type at the start,
3197  // if yes this should be reused. We must ensure that only one type
3198  // object exists for the injected type (including the injected record
3199  // declaration), ASTContext does not check it.
3200  SmallVector<Decl *, 2> Redecls =
3202  const Type *FrontTy =
3203  cast<CXXRecordDecl>(Redecls.front())->getTypeForDecl();
3204  QualType InjSpec;
3205  if (auto *InjTy = FrontTy->getAs<InjectedClassNameType>())
3206  InjSpec = InjTy->getInjectedSpecializationType();
3207  else
3208  InjSpec = ToDescribed->getInjectedClassNameSpecialization();
3209  for (auto *R : Redecls) {
3210  auto *RI = cast<CXXRecordDecl>(R);
3211  if (R != Redecls.front() ||
3212  !isa<InjectedClassNameType>(RI->getTypeForDecl()))
3213  RI->setTypeForDecl(nullptr);
3214  // This function tries to get the injected type from getTypeForDecl,
3215  // then from the previous declaration if possible. If not, it creates
3216  // a new type.
3217  Importer.getToContext().getInjectedClassNameType(RI, InjSpec);
3218  }
3219  // Set the new type for the injected decl too.
3220  if (Injected) {
3221  Injected->setTypeForDecl(nullptr);
3222  // This function will copy the injected type from D2CXX into Injected.
3223  // The injected decl does not have a previous decl to copy from.
3224  Importer.getToContext().getTypeDeclType(Injected, D2CXX);
3225  }
3226  }
3227  } else if (MemberSpecializationInfo *MemberInfo =
3228  DCXX->getMemberSpecializationInfo()) {
3230  MemberInfo->getTemplateSpecializationKind();
3231  CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass();
3232 
3233  if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
3234  D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
3235  else
3236  return ToInstOrErr.takeError();
3237 
3238  if (ExpectedSLoc POIOrErr =
3239  import(MemberInfo->getPointOfInstantiation()))
3241  *POIOrErr);
3242  else
3243  return POIOrErr.takeError();
3244  }
3245 
3246  } else {
3247  if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
3248  D->getTagKind(), DC, *BeginLocOrErr, Loc,
3249  Name.getAsIdentifierInfo(), PrevDecl))
3250  return D2;
3251  D2->setLexicalDeclContext(LexicalDC);
3252  addDeclToContexts(D, D2);
3253  }
3254 
3255  if (auto BraceRangeOrErr = import(D->getBraceRange()))
3256  D2->setBraceRange(*BraceRangeOrErr);
3257  else
3258  return BraceRangeOrErr.takeError();
3259  if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
3260  D2->setQualifierInfo(*QualifierLocOrErr);
3261  else
3262  return QualifierLocOrErr.takeError();
3263 
3264  if (D->isAnonymousStructOrUnion())
3265  D2->setAnonymousStructOrUnion(true);
3266 
3267  if (D->isCompleteDefinition())
3268  if (Error Err = ImportDefinition(D, D2, IDK_Default))
3269  return std::move(Err);
3270 
3271  return D2;
3272 }
3273 
3275  // Import the major distinguishing characteristics of this enumerator.
3276  DeclContext *DC, *LexicalDC;
3277  DeclarationName Name;
3279  NamedDecl *ToD;
3280  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3281  return std::move(Err);
3282  if (ToD)
3283  return ToD;
3284 
3285  // Determine whether there are any other declarations with the same name and
3286  // in the same context.
3287  if (!LexicalDC->isFunctionOrMethod()) {
3288  SmallVector<NamedDecl *, 4> ConflictingDecls;
3289  unsigned IDNS = Decl::IDNS_Ordinary;
3290  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3291  for (auto *FoundDecl : FoundDecls) {
3292  if (!FoundDecl->isInIdentifierNamespace(IDNS))
3293  continue;
3294 
3295  if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
3296  if (IsStructuralMatch(D, FoundEnumConstant))
3297  return Importer.MapImported(D, FoundEnumConstant);
3298  ConflictingDecls.push_back(FoundDecl);
3299  }
3300  }
3301 
3302  if (!ConflictingDecls.empty()) {
3303  ExpectedName NameOrErr = Importer.HandleNameConflict(
3304  Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3305  if (NameOrErr)
3306  Name = NameOrErr.get();
3307  else
3308  return NameOrErr.takeError();
3309  }
3310  }
3311 
3312  ExpectedType TypeOrErr = import(D->getType());
3313  if (!TypeOrErr)
3314  return TypeOrErr.takeError();
3315 
3316  ExpectedExpr InitOrErr = import(D->getInitExpr());
3317  if (!InitOrErr)
3318  return InitOrErr.takeError();
3319 
3320  EnumConstantDecl *ToEnumerator;
3321  if (GetImportedOrCreateDecl(
3322  ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
3323  Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
3324  return ToEnumerator;
3325 
3326  ToEnumerator->setAccess(D->getAccess());
3327  ToEnumerator->setLexicalDeclContext(LexicalDC);
3328  LexicalDC->addDeclInternal(ToEnumerator);
3329  return ToEnumerator;
3330 }
3331 
3332 template <typename DeclTy>
3334  DeclTy *ToD) {
3335  unsigned int Num = FromD->getNumTemplateParameterLists();
3336  if (Num == 0)
3337  return Error::success();
3339  for (unsigned int I = 0; I < Num; ++I)
3340  if (Expected<TemplateParameterList *> ToTPListOrErr =
3341  import(FromD->getTemplateParameterList(I)))
3342  ToTPLists[I] = *ToTPListOrErr;
3343  else
3344  return ToTPListOrErr.takeError();
3345  ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
3346  return Error::success();
3347 }
3348 
3350  FunctionDecl *FromFD, FunctionDecl *ToFD) {
3351  switch (FromFD->getTemplatedKind()) {
3354  return Error::success();
3355 
3357  if (Expected<FunctionDecl *> InstFDOrErr =
3358  import(FromFD->getInstantiatedFromDecl()))
3359  ToFD->setInstantiatedFromDecl(*InstFDOrErr);
3360  return Error::success();
3363 
3364  if (Expected<FunctionDecl *> InstFDOrErr =
3365  import(FromFD->getInstantiatedFromMemberFunction()))
3366  ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
3367  else
3368  return InstFDOrErr.takeError();
3369 
3370  if (ExpectedSLoc POIOrErr = import(
3373  else
3374  return POIOrErr.takeError();
3375 
3376  return Error::success();
3377  }
3378 
3380  auto FunctionAndArgsOrErr =
3382  if (!FunctionAndArgsOrErr)
3383  return FunctionAndArgsOrErr.takeError();
3384 
3386  Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
3387 
3388  auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
3389  TemplateArgumentListInfo ToTAInfo;
3390  const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
3391  if (FromTAArgsAsWritten)
3393  *FromTAArgsAsWritten, ToTAInfo))
3394  return Err;
3395 
3396  ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
3397  if (!POIOrErr)
3398  return POIOrErr.takeError();
3399 
3400  if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
3401  return Err;
3402 
3403  TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
3404  ToFD->setFunctionTemplateSpecialization(
3405  std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr,
3406  TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
3407  return Error::success();
3408  }
3409 
3411  auto *FromInfo = FromFD->getDependentSpecializationInfo();
3412  UnresolvedSet<8> Candidates;
3413  for (FunctionTemplateDecl *FTD : FromInfo->getCandidates()) {
3414  if (Expected<FunctionTemplateDecl *> ToFTDOrErr = import(FTD))
3415  Candidates.addDecl(*ToFTDOrErr);
3416  else
3417  return ToFTDOrErr.takeError();
3418  }
3419 
3420  // Import TemplateArgumentListInfo.
3421  TemplateArgumentListInfo ToTAInfo;
3422  const auto *FromTAArgsAsWritten = FromInfo->TemplateArgumentsAsWritten;
3423  if (FromTAArgsAsWritten)
3424  if (Error Err =
3425  ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
3426  return Err;
3427 
3429  Importer.getToContext(), Candidates,
3430  FromTAArgsAsWritten ? &ToTAInfo : nullptr);
3431  return Error::success();
3432  }
3433  }
3434  llvm_unreachable("All cases should be covered!");
3435 }
3436 
3439  auto FunctionAndArgsOrErr =
3441  if (!FunctionAndArgsOrErr)
3442  return FunctionAndArgsOrErr.takeError();
3443 
3444  FunctionTemplateDecl *Template;
3445  TemplateArgsTy ToTemplArgs;
3446  std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
3447  void *InsertPos = nullptr;
3448  auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos);
3449  return FoundSpec;
3450 }
3451 
3453  FunctionDecl *ToFD) {
3454  if (Stmt *FromBody = FromFD->getBody()) {
3455  if (ExpectedStmt ToBodyOrErr = import(FromBody))
3456  ToFD->setBody(*ToBodyOrErr);
3457  else
3458  return ToBodyOrErr.takeError();
3459  }
3460  return Error::success();
3461 }
3462 
3463 // Returns true if the given D has a DeclContext up to the TranslationUnitDecl
3464 // which is equal to the given DC, or D is equal to DC.
3465 static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) {
3466  const DeclContext *DCi = dyn_cast<DeclContext>(D);
3467  if (!DCi)
3468  DCi = D->getDeclContext();
3469  assert(DCi && "Declaration should have a context");
3470  while (DCi != D->getTranslationUnitDecl()) {
3471  if (DCi == DC)
3472  return true;
3473  DCi = DCi->getParent();
3474  }
3475  return false;
3476 }
3477 
3478 // Check if there is a declaration that has 'DC' as parent context and is
3479 // referenced from statement 'S' or one of its children. The search is done in
3480 // BFS order through children of 'S'.
3481 static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
3482  SmallVector<const Stmt *> ToProcess;
3483  ToProcess.push_back(S);
3484  while (!ToProcess.empty()) {
3485  const Stmt *CurrentS = ToProcess.pop_back_val();
3486  ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
3487  if (const auto *DeclRef = dyn_cast<DeclRefExpr>(CurrentS)) {
3488  if (const Decl *D = DeclRef->getDecl())
3489  if (isAncestorDeclContextOf(DC, D))
3490  return true;
3491  } else if (const auto *E =
3492  dyn_cast_or_null<SubstNonTypeTemplateParmExpr>(CurrentS)) {
3493  if (const Decl *D = E->getAssociatedDecl())
3494  if (isAncestorDeclContextOf(DC, D))
3495  return true;
3496  }
3497  }
3498  return false;
3499 }
3500 
3501 namespace {
3502 /// Check if a type has any reference to a declaration that is inside the body
3503 /// of a function.
3504 /// The \c CheckType(QualType) function should be used to determine
3505 /// this property.
3506 ///
3507 /// The type visitor visits one type object only (not recursive).
3508 /// To find all referenced declarations we must discover all type objects until
3509 /// the canonical type is reached (walk over typedef and similar objects). This
3510 /// is done by loop over all "sugar" type objects. For every such type we must
3511 /// check all declarations that are referenced from it. For this check the
3512 /// visitor is used. In the visit functions all referenced declarations except
3513 /// the one that follows in the sugar chain (if any) must be checked. For this
3514 /// check the same visitor is re-used (it has no state-dependent data).
3515 ///
3516 /// The visit functions have 3 possible return values:
3517 /// - True, found a declaration inside \c ParentDC.
3518 /// - False, found declarations only outside \c ParentDC and it is not possible
3519 /// to find more declarations (the "sugar" chain does not continue).
3520 /// - Empty optional value, found no declarations or only outside \c ParentDC,
3521 /// but it is possible to find more declarations in the type "sugar" chain.
3522 /// The loop over the "sugar" types can be implemented by using type visit
3523 /// functions only (call \c CheckType with the desugared type). With the current
3524 /// solution no visit function is needed if the type has only a desugared type
3525 /// as data.
3526 class IsTypeDeclaredInsideVisitor
3527  : public TypeVisitor<IsTypeDeclaredInsideVisitor, std::optional<bool>> {
3528 public:
3529  IsTypeDeclaredInsideVisitor(const FunctionDecl *ParentDC)
3530  : ParentDC(ParentDC) {}
3531 
3532  bool CheckType(QualType T) {
3533  // Check the chain of "sugar" types.
3534  // The "sugar" types are typedef or similar types that have the same
3535  // canonical type.
3536  if (std::optional<bool> Res = Visit(T.getTypePtr()))
3537  return *Res;
3538  QualType DsT =
3539  T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3540  while (DsT != T) {
3541  if (std::optional<bool> Res = Visit(DsT.getTypePtr()))
3542  return *Res;
3543  T = DsT;
3544  DsT = T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3545  }
3546  return false;
3547  }
3548 
3549  std::optional<bool> VisitTagType(const TagType *T) {
3550  if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(T->getDecl()))
3551  for (const auto &Arg : Spec->getTemplateArgs().asArray())
3552  if (checkTemplateArgument(Arg))
3553  return true;
3554  return isAncestorDeclContextOf(ParentDC, T->getDecl());
3555  }
3556 
3557  std::optional<bool> VisitPointerType(const PointerType *T) {
3558  return CheckType(T->getPointeeType());
3559  }
3560 
3561  std::optional<bool> VisitReferenceType(const ReferenceType *T) {
3562  return CheckType(T->getPointeeTypeAsWritten());
3563  }
3564 
3565  std::optional<bool> VisitTypedefType(const TypedefType *T) {
3566  const TypedefNameDecl *TD = T->getDecl();
3567  assert(TD);
3568  return isAncestorDeclContextOf(ParentDC, TD);
3569  }
3570 
3571  std::optional<bool> VisitUsingType(const UsingType *T) {
3572  if (T->getFoundDecl() &&
3573  isAncestorDeclContextOf(ParentDC, T->getFoundDecl()))
3574  return true;
3575 
3576  return {};
3577  }
3578 
3579  std::optional<bool>
3580  VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
3581  for (const auto &Arg : T->template_arguments())
3582  if (checkTemplateArgument(Arg))
3583  return true;
3584  // This type is a "sugar" to a record type, it can have a desugared type.
3585  return {};
3586  }
3587 
3588  std::optional<bool>
3589  VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
3590  // The "associated declaration" can be the same as ParentDC.
3591  if (isAncestorDeclContextOf(ParentDC, T->getAssociatedDecl()))
3592  return true;
3593  return {};
3594  }
3595 
3596  std::optional<bool> VisitConstantArrayType(const ConstantArrayType *T) {
3597  if (T->getSizeExpr() && isAncestorDeclContextOf(ParentDC, T->getSizeExpr()))
3598  return true;
3599 
3600  return CheckType(T->getElementType());
3601  }
3602 
3603  std::optional<bool> VisitVariableArrayType(const VariableArrayType *T) {
3604  llvm_unreachable(
3605  "Variable array should not occur in deduced return type of a function");
3606  }
3607 
3608  std::optional<bool> VisitIncompleteArrayType(const IncompleteArrayType *T) {
3609  llvm_unreachable("Incomplete array should not occur in deduced return type "
3610  "of a function");
3611  }
3612 
3613  std::optional<bool> VisitDependentArrayType(const IncompleteArrayType *T) {
3614  llvm_unreachable("Dependent array should not occur in deduced return type "
3615  "of a function");
3616  }
3617 
3618 private:
3619  const DeclContext *const ParentDC;
3620 
3621  bool checkTemplateArgument(const TemplateArgument &Arg) {
3622  switch (Arg.getKind()) {
3624  return false;
3626  return CheckType(Arg.getIntegralType());
3628  return CheckType(Arg.getAsType());
3630  return isAncestorDeclContextOf(ParentDC, Arg.getAsExpr());
3632  // FIXME: The declaration in this case is not allowed to be in a function?
3633  return isAncestorDeclContextOf(ParentDC, Arg.getAsDecl());
3635  // FIXME: The type is not allowed to be in the function?
3636  return CheckType(Arg.getNullPtrType());
3638  return CheckType(Arg.getStructuralValueType());
3640  for (const auto &PackArg : Arg.getPackAsArray())
3641  if (checkTemplateArgument(PackArg))
3642  return true;
3643  return false;
3645  // Templates can not be defined locally in functions.
3646  // A template passed as argument can be not in ParentDC.
3647  return false;
3649  // Templates can not be defined locally in functions.
3650  // A template passed as argument can be not in ParentDC.
3651  return false;
3652  }
3653  llvm_unreachable("Unknown TemplateArgument::ArgKind enum");
3654  };
3655 };
3656 } // namespace
3657 
3658 /// This function checks if the given function has a return type that contains
3659 /// a reference (in any way) to a declaration inside the same function.
3661  QualType FromTy = D->getType();
3662  const auto *FromFPT = FromTy->getAs<FunctionProtoType>();
3663  assert(FromFPT && "Must be called on FunctionProtoType");
3664 
3665  auto IsCXX11LambdaWithouTrailingReturn = [&]() {
3666  if (Importer.FromContext.getLangOpts().CPlusPlus14) // C++14 or later
3667  return false;
3668 
3669  if (FromFPT->hasTrailingReturn())
3670  return false;
3671 
3672  if (const auto *MD = dyn_cast<CXXMethodDecl>(D))
3673  return cast<CXXRecordDecl>(MD->getDeclContext())->isLambda();
3674 
3675  return false;
3676  };
3677 
3678  QualType RetT = FromFPT->getReturnType();
3679  if (isa<AutoType>(RetT.getTypePtr()) || IsCXX11LambdaWithouTrailingReturn()) {
3680  FunctionDecl *Def = D->getDefinition();
3681  IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D);
3682  return Visitor.CheckType(RetT);
3683  }
3684 
3685  return false;
3686 }
3687 
3689 ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3690  Expr *ExplicitExpr = ESpec.getExpr();
3691  if (ExplicitExpr)
3692  ExplicitExpr = importChecked(Err, ESpec.getExpr());
3693  return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3694 }
3695 
3697 
3699  auto RedeclIt = Redecls.begin();
3700  // Import the first part of the decl chain. I.e. import all previous
3701  // declarations starting from the canonical decl.
3702  for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3703  ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3704  if (!ToRedeclOrErr)
3705  return ToRedeclOrErr.takeError();
3706  }
3707  assert(*RedeclIt == D);
3708 
3709  // Import the major distinguishing characteristics of this function.
3710  DeclContext *DC, *LexicalDC;
3711  DeclarationName Name;
3713  NamedDecl *ToD;
3714  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3715  return std::move(Err);
3716  if (ToD)
3717  return ToD;
3718 
3719  FunctionDecl *FoundByLookup = nullptr;
3721 
3722  // If this is a function template specialization, then try to find the same
3723  // existing specialization in the "to" context. The lookup below will not
3724  // find any specialization, but would find the primary template; thus, we
3725  // have to skip normal lookup in case of specializations.
3726  // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3727  if (D->getTemplatedKind() ==
3729  auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
3730  if (!FoundFunctionOrErr)
3731  return FoundFunctionOrErr.takeError();
3732  if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
3733  if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3734  return Def;
3735  FoundByLookup = FoundFunction;
3736  }
3737  }
3738  // Try to find a function in our own ("to") context with the same name, same
3739  // type, and in the same context as the function we're importing.
3740  else if (!LexicalDC->isFunctionOrMethod()) {
3741  SmallVector<NamedDecl *, 4> ConflictingDecls;
3743  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3744  for (auto *FoundDecl : FoundDecls) {
3745  if (!FoundDecl->isInIdentifierNamespace(IDNS))
3746  continue;
3747 
3748  if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3749  if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
3750  continue;
3751 
3752  if (IsStructuralMatch(D, FoundFunction)) {
3753  if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3754  return Def;
3755  FoundByLookup = FoundFunction;
3756  break;
3757  }
3758  // FIXME: Check for overloading more carefully, e.g., by boosting
3759  // Sema::IsOverload out to the AST library.
3760 
3761  // Function overloading is okay in C++.
3762  if (Importer.getToContext().getLangOpts().CPlusPlus)
3763  continue;
3764 
3765  // Complain about inconsistent function types.
3766  Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
3767  << Name << D->getType() << FoundFunction->getType();
3768  Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
3769  << FoundFunction->getType();
3770  ConflictingDecls.push_back(FoundDecl);
3771  }
3772  }
3773 
3774  if (!ConflictingDecls.empty()) {
3775  ExpectedName NameOrErr = Importer.HandleNameConflict(
3776  Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3777  if (NameOrErr)
3778  Name = NameOrErr.get();
3779  else
3780  return NameOrErr.takeError();
3781  }
3782  }
3783 
3784  // We do not allow more than one in-class declaration of a function. This is
3785  // because AST clients like VTableBuilder asserts on this. VTableBuilder
3786  // assumes there is only one in-class declaration. Building a redecl
3787  // chain would result in more than one in-class declaration for
3788  // overrides (even if they are part of the same redecl chain inside the
3789  // derived class.)
3790  if (FoundByLookup) {
3791  if (isa<CXXMethodDecl>(FoundByLookup)) {
3792  if (D->getLexicalDeclContext() == D->getDeclContext()) {
3793  if (!D->doesThisDeclarationHaveABody()) {
3794  if (FunctionTemplateDecl *DescribedD =
3796  // Handle a "templated" function together with its described
3797  // template. This avoids need for a similar check at import of the
3798  // described template.
3799  assert(FoundByLookup->getDescribedFunctionTemplate() &&
3800  "Templated function mapped to non-templated?");
3801  Importer.MapImported(DescribedD,
3802  FoundByLookup->getDescribedFunctionTemplate());
3803  }
3804  return Importer.MapImported(D, FoundByLookup);
3805  } else {
3806  // Let's continue and build up the redecl chain in this case.
3807  // FIXME Merge the functions into one decl.
3808  }
3809  }
3810  }
3811  }
3812 
3813  DeclarationNameInfo NameInfo(Name, Loc);
3814  // Import additional name location/type info.
3815  if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
3816  return std::move(Err);
3817 
3818  QualType FromTy = D->getType();
3819  TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
3820  // Set to true if we do not import the type of the function as is. There are
3821  // cases when the original type would result in an infinite recursion during
3822  // the import. To avoid an infinite recursion when importing, we create the
3823  // FunctionDecl with a simplified function type and update it only after the
3824  // relevant AST nodes are already imported.
3825  // The type is related to TypeSourceInfo (it references the type), so we must
3826  // do the same with TypeSourceInfo.
3827  bool UsedDifferentProtoType = false;
3828  if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
3829  QualType FromReturnTy = FromFPT->getReturnType();
3830  // Functions with auto return type may define a struct inside their body
3831  // and the return type could refer to that struct.
3832  // E.g.: auto foo() { struct X{}; return X(); }
3833  // To avoid an infinite recursion when importing, create the FunctionDecl
3834  // with a simplified return type.
3835  if (hasReturnTypeDeclaredInside(D)) {
3836  FromReturnTy = Importer.getFromContext().VoidTy;
3837  UsedDifferentProtoType = true;
3838  }
3839  FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
3840  // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
3841  // FunctionDecl that we are importing the FunctionProtoType for.
3842  // To avoid an infinite recursion when importing, create the FunctionDecl
3843  // with a simplified function type.
3844  if (FromEPI.ExceptionSpec.SourceDecl ||
3845  FromEPI.ExceptionSpec.SourceTemplate ||
3846  FromEPI.ExceptionSpec.NoexceptExpr) {
3848  FromEPI = DefaultEPI;
3849  UsedDifferentProtoType = true;
3850  }
3851  FromTy = Importer.getFromContext().getFunctionType(
3852  FromReturnTy, FromFPT->getParamTypes(), FromEPI);
3853  FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
3854  FromTy, D->getBeginLoc());
3855  }
3856 
3857  Error Err = Error::success();
3858  auto T = importChecked(Err, FromTy);
3859  auto TInfo = importChecked(Err, FromTSI);
3860  auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
3861  auto ToEndLoc = importChecked(Err, D->getEndLoc());
3862  auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
3863  auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3864  auto TrailingRequiresClause =
3866  if (Err)
3867  return std::move(Err);
3868 
3869  // Import the function parameters.
3870  SmallVector<ParmVarDecl *, 8> Parameters;
3871  for (auto *P : D->parameters()) {
3872  if (Expected<ParmVarDecl *> ToPOrErr = import(P))
3873  Parameters.push_back(*ToPOrErr);
3874  else
3875  return ToPOrErr.takeError();
3876  }
3877 
3878  // Create the imported function.
3879  FunctionDecl *ToFunction = nullptr;
3880  if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
3881  ExplicitSpecifier ESpec =
3882  importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
3883  if (Err)
3884  return std::move(Err);
3885  auto ToInheritedConstructor = InheritedConstructor();
3886  if (FromConstructor->isInheritingConstructor()) {
3887  Expected<InheritedConstructor> ImportedInheritedCtor =
3888  import(FromConstructor->getInheritedConstructor());
3889  if (!ImportedInheritedCtor)
3890  return ImportedInheritedCtor.takeError();
3891  ToInheritedConstructor = *ImportedInheritedCtor;
3892  }
3893  if (GetImportedOrCreateDecl<CXXConstructorDecl>(
3894  ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3895  ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
3897  ToInheritedConstructor, TrailingRequiresClause))
3898  return ToFunction;
3899  } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
3900 
3901  Error Err = Error::success();
3902  auto ToOperatorDelete = importChecked(
3903  Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
3904  auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
3905  if (Err)
3906  return std::move(Err);
3907 
3908  if (GetImportedOrCreateDecl<CXXDestructorDecl>(
3909  ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3910  ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
3912  TrailingRequiresClause))
3913  return ToFunction;
3914 
3915  CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
3916 
3917  ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
3918  } else if (CXXConversionDecl *FromConversion =
3919  dyn_cast<CXXConversionDecl>(D)) {
3920  ExplicitSpecifier ESpec =
3921  importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
3922  if (Err)
3923  return std::move(Err);
3924  if (GetImportedOrCreateDecl<CXXConversionDecl>(
3925  ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3926  ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
3927  D->isInlineSpecified(), ESpec, D->getConstexprKind(),
3928  SourceLocation(), TrailingRequiresClause))
3929  return ToFunction;
3930  } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
3931  if (GetImportedOrCreateDecl<CXXMethodDecl>(
3932  ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3933  ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
3934  Method->UsesFPIntrin(), Method->isInlineSpecified(),
3935  D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
3936  return ToFunction;
3937  } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
3938  ExplicitSpecifier ESpec =
3939  importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
3940  CXXConstructorDecl *Ctor =
3941  importChecked(Err, Guide->getCorrespondingConstructor());
3942  if (Err)
3943  return std::move(Err);
3944  if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
3945  ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
3946  NameInfo, T, TInfo, ToEndLoc, Ctor))
3947  return ToFunction;
3948  cast<CXXDeductionGuideDecl>(ToFunction)
3949  ->setDeductionCandidateKind(Guide->getDeductionCandidateKind());
3950  } else {
3951  if (GetImportedOrCreateDecl(
3952  ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
3953  NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
3955  D->getConstexprKind(), TrailingRequiresClause))
3956  return ToFunction;
3957  }
3958 
3959  // Connect the redecl chain.
3960  if (FoundByLookup) {
3961  auto *Recent = const_cast<FunctionDecl *>(
3962  FoundByLookup->getMostRecentDecl());
3963  ToFunction->setPreviousDecl(Recent);
3964  // FIXME Probably we should merge exception specifications. E.g. In the
3965  // "To" context the existing function may have exception specification with
3966  // noexcept-unevaluated, while the newly imported function may have an
3967  // evaluated noexcept. A call to adjustExceptionSpec() on the imported
3968  // decl and its redeclarations may be required.
3969  }
3970 
3971  StringLiteral *Msg = D->getDeletedMessage();
3972  if (Msg) {
3973  auto Imported = import(Msg);
3974  if (!Imported)
3975  return Imported.takeError();
3976  Msg = *Imported;
3977  }
3978 
3979  ToFunction->setQualifierInfo(ToQualifierLoc);
3980  ToFunction->setAccess(D->getAccess());
3981  ToFunction->setLexicalDeclContext(LexicalDC);
3982  ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
3983  ToFunction->setTrivial(D->isTrivial());
3984  ToFunction->setIsPureVirtual(D->isPureVirtual());
3985  ToFunction->setDefaulted(D->isDefaulted());
3987  ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
3990  ToFunction->setRangeEnd(ToEndLoc);
3991  ToFunction->setDefaultLoc(ToDefaultLoc);
3992 
3993  if (Msg)
3994  ToFunction->setDefaultedOrDeletedInfo(
3996  Importer.getToContext(), {}, Msg));
3997 
3998  // Set the parameters.
3999  for (auto *Param : Parameters) {
4000  Param->setOwningFunction(ToFunction);
4001  ToFunction->addDeclInternal(Param);
4002  if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
4003  LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
4004  }
4005  ToFunction->setParams(Parameters);
4006 
4007  // We need to complete creation of FunctionProtoTypeLoc manually with setting
4008  // params it refers to.
4009  if (TInfo) {
4010  if (auto ProtoLoc =
4011  TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
4012  for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
4013  ProtoLoc.setParam(I, Parameters[I]);
4014  }
4015  }
4016 
4017  // Import the describing template function, if any.
4018  if (FromFT) {
4019  auto ToFTOrErr = import(FromFT);
4020  if (!ToFTOrErr)
4021  return ToFTOrErr.takeError();
4022  }
4023 
4024  // Import Ctor initializers.
4025  if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4026  if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
4027  SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
4028  // Import first, then allocate memory and copy if there was no error.
4029  if (Error Err = ImportContainerChecked(
4030  FromConstructor->inits(), CtorInitializers))
4031  return std::move(Err);
4032  auto **Memory =
4033  new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4034  std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
4035  auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
4036  ToCtor->setCtorInitializers(Memory);
4037  ToCtor->setNumCtorInitializers(NumInitializers);
4038  }
4039  }
4040 
4041  // If it is a template, import all related things.
4042  if (Error Err = ImportTemplateInformation(D, ToFunction))
4043  return std::move(Err);
4044 
4045  if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
4046  if (Error Err = ImportOverriddenMethods(cast<CXXMethodDecl>(ToFunction),
4047  FromCXXMethod))
4048  return std::move(Err);
4049 
4050  if (D->doesThisDeclarationHaveABody()) {
4051  Error Err = ImportFunctionDeclBody(D, ToFunction);
4052 
4053  if (Err)
4054  return std::move(Err);
4055  }
4056 
4057  // Import and set the original type in case we used another type.
4058  if (UsedDifferentProtoType) {
4059  if (ExpectedType TyOrErr = import(D->getType()))
4060  ToFunction->setType(*TyOrErr);
4061  else
4062  return TyOrErr.takeError();
4063  if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
4064  ToFunction->setTypeSourceInfo(*TSIOrErr);
4065  else
4066  return TSIOrErr.takeError();
4067  }
4068 
4069  // FIXME: Other bits to merge?
4070 
4071  addDeclToContexts(D, ToFunction);
4072 
4073  // Import the rest of the chain. I.e. import all subsequent declarations.
4074  for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4075  ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4076  if (!ToRedeclOrErr)
4077  return ToRedeclOrErr.takeError();
4078  }
4079 
4080  return ToFunction;
4081 }
4082 
4084  return VisitFunctionDecl(D);
4085 }
4086 
4088  return VisitCXXMethodDecl(D);
4089 }
4090 
4092  return VisitCXXMethodDecl(D);
4093 }
4094 
4096  return VisitCXXMethodDecl(D);
4097 }
4098 
4101  return VisitFunctionDecl(D);
4102 }
4103 
4105  // Import the major distinguishing characteristics of a variable.
4106  DeclContext *DC, *LexicalDC;
4107  DeclarationName Name;
4109  NamedDecl *ToD;
4110  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4111  return std::move(Err);
4112  if (ToD)
4113  return ToD;
4114 
4115  // Determine whether we've already imported this field.
4116  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4117  for (auto *FoundDecl : FoundDecls) {
4118  if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4119  // For anonymous fields, match up by index.
4120  if (!Name &&
4122  ASTImporter::getFieldIndex(FoundField))
4123  continue;
4124 
4125  if (Importer.IsStructurallyEquivalent(D->getType(),
4126  FoundField->getType())) {
4127  Importer.MapImported(D, FoundField);
4128  // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4129  // initializer of a FieldDecl might not had been instantiated in the
4130  // "To" context. However, the "From" context might instantiated that,
4131  // thus we have to merge that.
4132  // Note: `hasInClassInitializer()` is not the same as non-null
4133  // `getInClassInitializer()` value.
4134  if (Expr *FromInitializer = D->getInClassInitializer()) {
4135  if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4136  // Import of the FromInitializer may result in the setting of
4137  // InClassInitializer. If not, set it here.
4138  assert(FoundField->hasInClassInitializer() &&
4139  "Field should have an in-class initializer if it has an "
4140  "expression for it.");
4141  if (!FoundField->getInClassInitializer())
4142  FoundField->setInClassInitializer(*ToInitializerOrErr);
4143  } else {
4144  return ToInitializerOrErr.takeError();
4145  }
4146  }
4147  return FoundField;
4148  }
4149 
4150  // FIXME: Why is this case not handled with calling HandleNameConflict?
4151  Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4152  << Name << D->getType() << FoundField->getType();
4153  Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4154  << FoundField->getType();
4155 
4156  return make_error<ASTImportError>(ASTImportError::NameConflict);
4157  }
4158  }
4159 
4160  Error Err = Error::success();
4161  auto ToType = importChecked(Err, D->getType());
4162  auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4163  auto ToBitWidth = importChecked(Err, D->getBitWidth());
4164  auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4165  if (Err)
4166  return std::move(Err);
4167  const Type *ToCapturedVLAType = nullptr;
4168  if (Error Err = Importer.importInto(
4169  ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4170  return std::move(Err);
4171 
4172  FieldDecl *ToField;
4173  if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4174  ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4175  ToType, ToTInfo, ToBitWidth, D->isMutable(),
4176  D->getInClassInitStyle()))
4177  return ToField;
4178 
4179  // We need [[no_unqiue_address]] attributes to be added to FieldDecl, before
4180  // we add fields in CXXRecordDecl::addedMember, otherwise record will be
4181  // marked as having non-zero size.
4182  Err = Importer.ImportAttrs(ToField, D);
4183  if (Err)
4184  return std::move(Err);
4185  ToField->setAccess(D->getAccess());
4186  ToField->setLexicalDeclContext(LexicalDC);
4187  ToField->setImplicit(D->isImplicit());
4188  if (ToCapturedVLAType)
4189  ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4190  LexicalDC->addDeclInternal(ToField);
4191  // Import initializer only after the field was created, it may have recursive
4192  // reference to the field.
4193  auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4194  if (Err)
4195  return std::move(Err);
4196  if (ToInitializer) {
4197  auto *AlreadyImported = ToField->getInClassInitializer();
4198  if (AlreadyImported)
4199  assert(ToInitializer == AlreadyImported &&
4200  "Duplicate import of in-class initializer.");
4201  else
4202  ToField->setInClassInitializer(ToInitializer);
4203  }
4204 
4205  return ToField;
4206 }
4207 
4209  // Import the major distinguishing characteristics of a variable.
4210  DeclContext *DC, *LexicalDC;
4211  DeclarationName Name;
4213  NamedDecl *ToD;
4214  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4215  return std::move(Err);
4216  if (ToD)
4217  return ToD;
4218 
4219  // Determine whether we've already imported this field.
4220  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4221  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4222  if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4223  // For anonymous indirect fields, match up by index.
4224  if (!Name &&
4226  ASTImporter::getFieldIndex(FoundField))
4227  continue;
4228 
4229  if (Importer.IsStructurallyEquivalent(D->getType(),
4230  FoundField->getType(),
4231  !Name.isEmpty())) {
4232  Importer.MapImported(D, FoundField);
4233  return FoundField;
4234  }
4235 
4236  // If there are more anonymous fields to check, continue.
4237  if (!Name && I < N-1)
4238  continue;
4239 
4240  // FIXME: Why is this case not handled with calling HandleNameConflict?
4241  Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4242  << Name << D->getType() << FoundField->getType();
4243  Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4244  << FoundField->getType();
4245 
4246  return make_error<ASTImportError>(ASTImportError::NameConflict);
4247  }
4248  }
4249 
4250  // Import the type.
4251  auto TypeOrErr = import(D->getType());
4252  if (!TypeOrErr)
4253  return TypeOrErr.takeError();
4254 
4255  auto **NamedChain =
4256  new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4257 
4258  unsigned i = 0;
4259  for (auto *PI : D->chain())
4260  if (Expected<NamedDecl *> ToD = import(PI))
4261  NamedChain[i++] = *ToD;
4262  else
4263  return ToD.takeError();
4264 
4265  llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()};
4266  IndirectFieldDecl *ToIndirectField;
4267  if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4268  Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4269  // FIXME here we leak `NamedChain` which is allocated before
4270  return ToIndirectField;
4271 
4272  ToIndirectField->setAccess(D->getAccess());
4273  ToIndirectField->setLexicalDeclContext(LexicalDC);
4274  LexicalDC->addDeclInternal(ToIndirectField);
4275  return ToIndirectField;
4276 }
4277 
4278 /// Used as return type of getFriendCountAndPosition.
4280  /// Number of similar looking friends.
4281  unsigned int TotalCount;
4282  /// Index of the specific FriendDecl.
4283  unsigned int IndexOfDecl;
4284 };
4285 
4286 static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4287  FriendDecl *FD2) {
4288  if ((!FD1->getFriendType()) != (!FD2->getFriendType()))
4289  return false;
4290 
4291  if (const TypeSourceInfo *TSI = FD1->getFriendType())
4292  return Importer.IsStructurallyEquivalent(
4293  TSI->getType(), FD2->getFriendType()->getType(), /*Complain=*/false);
4294 
4295  ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4297  FD1->getASTContext(), FD2->getASTContext(), NonEquivalentDecls,
4299  /* StrictTypeSpelling = */ false, /* Complain = */ false);
4300  return Ctx.IsEquivalent(FD1, FD2);
4301 }
4302 
4304  FriendDecl *FD) {
4305  unsigned int FriendCount = 0;
4306  std::optional<unsigned int> FriendPosition;
4307  const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4308 
4309  for (FriendDecl *FoundFriend : RD->friends()) {
4310  if (FoundFriend == FD) {
4311  FriendPosition = FriendCount;
4312  ++FriendCount;
4313  } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4314  ++FriendCount;
4315  }
4316  }
4317 
4318  assert(FriendPosition && "Friend decl not found in own parent.");
4319 
4320  return {FriendCount, *FriendPosition};
4321 }
4322 
4324  // Import the major distinguishing characteristics of a declaration.
4325  DeclContext *DC, *LexicalDC;
4326  if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4327  return std::move(Err);
4328 
4329  // Determine whether we've already imported this decl.
4330  // FriendDecl is not a NamedDecl so we cannot use lookup.
4331  // We try to maintain order and count of redundant friend declarations.
4332  const auto *RD = cast<CXXRecordDecl>(DC);
4333  SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4334  for (FriendDecl *ImportedFriend : RD->friends())
4335  if (IsEquivalentFriend(Importer, D, ImportedFriend))
4336  ImportedEquivalentFriends.push_back(ImportedFriend);
4337 
4338  FriendCountAndPosition CountAndPosition =
4339  getFriendCountAndPosition(Importer, D);
4340 
4341  assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4342  "Class with non-matching friends is imported, ODR check wrong?");
4343  if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4344  return Importer.MapImported(
4345  D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4346 
4347  // Not found. Create it.
4348  // The declarations will be put into order later by ImportDeclContext.
4350  if (NamedDecl *FriendD = D->getFriendDecl()) {
4351  NamedDecl *ToFriendD;
4352  if (Error Err = importInto(ToFriendD, FriendD))
4353  return std::move(Err);
4354 
4355  if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4356  !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator)))
4357  ToFriendD->setObjectOfFriendDecl(false);
4358 
4359  ToFU = ToFriendD;
4360  } else { // The friend is a type, not a decl.
4361  if (auto TSIOrErr = import(D->getFriendType()))
4362  ToFU = *TSIOrErr;
4363  else
4364  return TSIOrErr.takeError();
4365  }
4366 
4367  SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
4368  auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>();
4369  for (unsigned I = 0; I < D->NumTPLists; I++) {
4370  if (auto ListOrErr = import(FromTPLists[I]))
4371  ToTPLists[I] = *ListOrErr;
4372  else
4373  return ListOrErr.takeError();
4374  }
4375 
4376  auto LocationOrErr = import(D->getLocation());
4377  if (!LocationOrErr)
4378  return LocationOrErr.takeError();
4379  auto FriendLocOrErr = import(D->getFriendLoc());
4380  if (!FriendLocOrErr)
4381  return FriendLocOrErr.takeError();
4382 
4383  FriendDecl *FrD;
4384  if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4385  *LocationOrErr, ToFU,
4386  *FriendLocOrErr, ToTPLists))
4387  return FrD;
4388 
4389  FrD->setAccess(D->getAccess());
4390  FrD->setLexicalDeclContext(LexicalDC);
4391  LexicalDC->addDeclInternal(FrD);
4392  return FrD;
4393 }
4394 
4396  // Import the major distinguishing characteristics of an ivar.
4397  DeclContext *DC, *LexicalDC;
4398  DeclarationName Name;
4400  NamedDecl *ToD;
4401  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4402  return std::move(Err);
4403  if (ToD)
4404  return ToD;
4405 
4406  // Determine whether we've already imported this ivar
4407  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4408  for (auto *FoundDecl : FoundDecls) {
4409  if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4410  if (Importer.IsStructurallyEquivalent(D->getType(),
4411  FoundIvar->getType())) {
4412  Importer.MapImported(D, FoundIvar);
4413  return FoundIvar;
4414  }
4415 
4416  Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4417  << Name << D->getType() << FoundIvar->getType();
4418  Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4419  << FoundIvar->getType();
4420 
4421  return make_error<ASTImportError>(ASTImportError::NameConflict);
4422  }
4423  }
4424 
4425  Error Err = Error::success();
4426  auto ToType = importChecked(Err, D->getType());
4427  auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4428  auto ToBitWidth = importChecked(Err, D->getBitWidth());
4429  auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4430  if (Err)
4431  return std::move(Err);
4432 
4433  ObjCIvarDecl *ToIvar;
4434  if (GetImportedOrCreateDecl(
4435  ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4436  ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4437  ToType, ToTypeSourceInfo,
4438  D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4439  return ToIvar;
4440 
4441  ToIvar->setLexicalDeclContext(LexicalDC);
4442  LexicalDC->addDeclInternal(ToIvar);
4443  return ToIvar;
4444 }
4445 
4447 
4449  auto RedeclIt = Redecls.begin();
4450  // Import the first part of the decl chain. I.e. import all previous
4451  // declarations starting from the canonical decl.
4452  for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4453  ExpectedDecl RedeclOrErr = import(*RedeclIt);
4454  if (!RedeclOrErr)
4455  return RedeclOrErr.takeError();
4456  }
4457  assert(*RedeclIt == D);
4458 
4459  // Import the major distinguishing characteristics of a variable.
4460  DeclContext *DC, *LexicalDC;
4461  DeclarationName Name;
4463  NamedDecl *ToD;
4464  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4465  return std::move(Err);
4466  if (ToD)
4467  return ToD;
4468 
4469  // Try to find a variable in our own ("to") context with the same name and
4470  // in the same context as the variable we're importing.
4471  VarDecl *FoundByLookup = nullptr;
4472  if (D->isFileVarDecl()) {
4473  SmallVector<NamedDecl *, 4> ConflictingDecls;
4474  unsigned IDNS = Decl::IDNS_Ordinary;
4475  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4476  for (auto *FoundDecl : FoundDecls) {
4477  if (!FoundDecl->isInIdentifierNamespace(IDNS))
4478  continue;
4479 
4480  if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4481  if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4482  continue;
4483  if (Importer.IsStructurallyEquivalent(D->getType(),
4484  FoundVar->getType())) {
4485 
4486  // The VarDecl in the "From" context has a definition, but in the
4487  // "To" context we already have a definition.
4488  VarDecl *FoundDef = FoundVar->getDefinition();
4489  if (D->isThisDeclarationADefinition() && FoundDef)
4490  // FIXME Check for ODR error if the two definitions have
4491  // different initializers?
4492  return Importer.MapImported(D, FoundDef);
4493 
4494  // The VarDecl in the "From" context has an initializer, but in the
4495  // "To" context we already have an initializer.
4496  const VarDecl *FoundDInit = nullptr;
4497  if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4498  // FIXME Diagnose ODR error if the two initializers are different?
4499  return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4500 
4501  FoundByLookup = FoundVar;
4502  break;
4503  }
4504 
4505  const ArrayType *FoundArray
4506  = Importer.getToContext().getAsArrayType(FoundVar->getType());
4507  const ArrayType *TArray
4508  = Importer.getToContext().getAsArrayType(D->getType());
4509  if (FoundArray && TArray) {
4510  if (isa<IncompleteArrayType>(FoundArray) &&
4511  isa<ConstantArrayType>(TArray)) {
4512  // Import the type.
4513  if (auto TyOrErr = import(D->getType()))
4514  FoundVar->setType(*TyOrErr);
4515  else
4516  return TyOrErr.takeError();
4517 
4518  FoundByLookup = FoundVar;
4519  break;
4520  } else if (isa<IncompleteArrayType>(TArray) &&
4521  isa<ConstantArrayType>(FoundArray)) {
4522  FoundByLookup = FoundVar;
4523  break;
4524  }
4525  }
4526 
4527  Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4528  << Name << D->getType() << FoundVar->getType();
4529  Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4530  << FoundVar->getType();
4531  ConflictingDecls.push_back(FoundDecl);
4532  }
4533  }
4534 
4535  if (!ConflictingDecls.empty()) {
4536  ExpectedName NameOrErr = Importer.HandleNameConflict(
4537  Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4538  if (NameOrErr)
4539  Name = NameOrErr.get();
4540  else
4541  return NameOrErr.takeError();
4542  }
4543  }
4544 
4545  Error Err = Error::success();
4546  auto ToType = importChecked(Err, D->getType());
4547  auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4548  auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4549  auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4550  if (Err)
4551  return std::move(Err);
4552 
4553  VarDecl *ToVar;
4554  if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4555  SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4556  if (Error Err =
4557  ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4558  return std::move(Err);
4559  DecompositionDecl *ToDecomp;
4560  if (GetImportedOrCreateDecl(
4561  ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4562  Loc, ToType, ToTypeSourceInfo, D->getStorageClass(), Bindings))
4563  return ToDecomp;
4564  ToVar = ToDecomp;
4565  } else {
4566  // Create the imported variable.
4567  if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4568  ToInnerLocStart, Loc,
4569  Name.getAsIdentifierInfo(), ToType,
4570  ToTypeSourceInfo, D->getStorageClass()))
4571  return ToVar;
4572  }
4573 
4574  ToVar->setTSCSpec(D->getTSCSpec());
4575  ToVar->setQualifierInfo(ToQualifierLoc);
4576  ToVar->setAccess(D->getAccess());
4577  ToVar->setLexicalDeclContext(LexicalDC);
4578  if (D->isInlineSpecified())
4579  ToVar->setInlineSpecified();
4580  if (D->isInline())
4581  ToVar->setImplicitlyInline();
4582 
4583  if (FoundByLookup) {
4584  auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4585  ToVar->setPreviousDecl(Recent);
4586  }
4587 
4588  // Import the described template, if any.
4589  if (D->getDescribedVarTemplate()) {
4590  auto ToVTOrErr = import(D->getDescribedVarTemplate());
4591  if (!ToVTOrErr)
4592  return ToVTOrErr.takeError();
4593  } else if (MemberSpecializationInfo *MSI = D->getMemberSpecializationInfo()) {
4594  TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4596  if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4597  ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4598  else
4599  return ToInstOrErr.takeError();
4600  if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4602  else
4603  return POIOrErr.takeError();
4604  }
4605 
4606  if (Error Err = ImportInitializer(D, ToVar))
4607  return std::move(Err);
4608 
4609  if (D->isConstexpr())
4610  ToVar->setConstexpr(true);
4611 
4612  addDeclToContexts(D, ToVar);
4613 
4614  // Import the rest of the chain. I.e. import all subsequent declarations.
4615  for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4616  ExpectedDecl RedeclOrErr = import(*RedeclIt);
4617  if (!RedeclOrErr)
4618  return RedeclOrErr.takeError();
4619  }
4620 
4621  return ToVar;
4622 }
4623 
4625  // Parameters are created in the translation unit's context, then moved
4626  // into the function declaration's context afterward.
4627  DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4628 
4629  Error Err = Error::success();
4630  auto ToDeclName = importChecked(Err, D->getDeclName());
4631  auto ToLocation = importChecked(Err, D->getLocation());
4632  auto ToType = importChecked(Err, D->getType());
4633  if (Err)
4634  return std::move(Err);
4635 
4636  // Create the imported parameter.
4637  ImplicitParamDecl *ToParm = nullptr;
4638  if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4639  ToLocation, ToDeclName.getAsIdentifierInfo(),
4640  ToType, D->getParameterKind()))
4641  return ToParm;
4642  return ToParm;
4643 }
4644 
4646  const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4647  ToParam->setHasInheritedDefaultArg(FromParam->hasInheritedDefaultArg());
4649  FromParam->getExplicitObjectParamThisLoc());
4650  ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4651 
4652  if (FromParam->hasUninstantiatedDefaultArg()) {
4653  if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4654  ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4655  else
4656  return ToDefArgOrErr.takeError();
4657  } else if (FromParam->hasUnparsedDefaultArg()) {
4658  ToParam->setUnparsedDefaultArg();
4659  } else if (FromParam->hasDefaultArg()) {
4660  if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4661  ToParam->setDefaultArg(*ToDefArgOrErr);
4662  else
4663  return ToDefArgOrErr.takeError();
4664  }
4665 
4666  return Error::success();
4667 }
4668 
4671  Error Err = Error::success();
4672  CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4673  ConstructorUsingShadowDecl *ToShadow =
4674  importChecked(Err, From.getShadowDecl());
4675  if (Err)
4676  return std::move(Err);
4677  return InheritedConstructor(ToShadow, ToBaseCtor);
4678 }
4679 
4681  // Parameters are created in the translation unit's context, then moved
4682  // into the function declaration's context afterward.
4683  DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4684 
4685  Error Err = Error::success();
4686  auto ToDeclName = importChecked(Err, D->getDeclName());
4687  auto ToLocation = importChecked(Err, D->getLocation());
4688  auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4689  auto ToType = importChecked(Err, D->getType());
4690  auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4691  if (Err)
4692  return std::move(Err);
4693 
4694  ParmVarDecl *ToParm;
4695  if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4696  ToInnerLocStart, ToLocation,
4697  ToDeclName.getAsIdentifierInfo(), ToType,
4698  ToTypeSourceInfo, D->getStorageClass(),
4699  /*DefaultArg*/ nullptr))
4700  return ToParm;
4701 
4702  // Set the default argument. It should be no problem if it was already done.
4703  // Do not import the default expression before GetImportedOrCreateDecl call
4704  // to avoid possible infinite import loop because circular dependency.
4705  if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4706  return std::move(Err);
4707 
4708  if (D->isObjCMethodParameter()) {
4711  } else {
4712  ToParm->setScopeInfo(D->getFunctionScopeDepth(),
4713  D->getFunctionScopeIndex());
4714  }
4715 
4716  return ToParm;
4717 }
4718 
4720  // Import the major distinguishing characteristics of a method.
4721  DeclContext *DC, *LexicalDC;
4722  DeclarationName Name;
4724  NamedDecl *ToD;
4725  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4726  return std::move(Err);
4727  if (ToD)
4728  return ToD;
4729 
4730  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4731  for (auto *FoundDecl : FoundDecls) {
4732  if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
4733  if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
4734  continue;
4735 
4736  // Check return types.
4737  if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
4738  FoundMethod->getReturnType())) {
4739  Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
4740  << D->isInstanceMethod() << Name << D->getReturnType()
4741  << FoundMethod->getReturnType();
4742  Importer.ToDiag(FoundMethod->getLocation(),
4743  diag::note_odr_objc_method_here)
4744  << D->isInstanceMethod() << Name;
4745 
4746  return make_error<ASTImportError>(ASTImportError::NameConflict);
4747  }
4748 
4749  // Check the number of parameters.
4750  if (D->param_size() != FoundMethod->param_size()) {
4751  Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
4752  << D->isInstanceMethod() << Name
4753  << D->param_size() << FoundMethod->param_size();
4754  Importer.ToDiag(FoundMethod->getLocation(),
4755  diag::note_odr_objc_method_here)
4756  << D->isInstanceMethod() << Name;
4757 
4758  return make_error<ASTImportError>(ASTImportError::NameConflict);
4759  }
4760 
4761  // Check parameter types.
4763  PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
4764  P != PEnd; ++P, ++FoundP) {
4765  if (!Importer.IsStructurallyEquivalent((*P)->getType(),
4766  (*FoundP)->getType())) {
4767  Importer.FromDiag((*P)->getLocation(),
4768  diag::warn_odr_objc_method_param_type_inconsistent)
4769  << D->isInstanceMethod() << Name
4770  << (*P)->getType() << (*FoundP)->getType();
4771  Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
4772  << (*FoundP)->getType();
4773 
4774  return make_error<ASTImportError>(ASTImportError::NameConflict);
4775  }
4776  }
4777 
4778  // Check variadic/non-variadic.
4779  // Check the number of parameters.
4780  if (D->isVariadic() != FoundMethod->isVariadic()) {
4781  Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
4782  << D->isInstanceMethod() << Name;
4783  Importer.ToDiag(FoundMethod->getLocation(),
4784  diag::note_odr_objc_method_here)
4785  << D->isInstanceMethod() << Name;
4786 
4787  return make_error<ASTImportError>(ASTImportError::NameConflict);
4788  }
4789 
4790  // FIXME: Any other bits we need to merge?
4791  return Importer.MapImported(D, FoundMethod);
4792  }
4793  }
4794 
4795  Error Err = Error::success();
4796  auto ToEndLoc = importChecked(Err, D->getEndLoc());
4797  auto ToReturnType = importChecked(Err, D->getReturnType());
4798  auto ToReturnTypeSourceInfo =
4800  if (Err)
4801  return std::move(Err);
4802 
4803  ObjCMethodDecl *ToMethod;
4804  if (GetImportedOrCreateDecl(
4805  ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
4806  Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
4810  return ToMethod;
4811 
4812  // FIXME: When we decide to merge method definitions, we'll need to
4813  // deal with implicit parameters.
4814 
4815  // Import the parameters
4817  for (auto *FromP : D->parameters()) {
4818  if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
4819  ToParams.push_back(*ToPOrErr);
4820  else
4821  return ToPOrErr.takeError();
4822  }
4823 
4824  // Set the parameters.
4825  for (auto *ToParam : ToParams) {
4826  ToParam->setOwningFunction(ToMethod);
4827  ToMethod->addDeclInternal(ToParam);
4828  }
4829 
4830  SmallVector<SourceLocation, 12> FromSelLocs;
4831  D->getSelectorLocs(FromSelLocs);
4832  SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
4833  if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
4834  return std::move(Err);
4835 
4836  ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
4837 
4838  ToMethod->setLexicalDeclContext(LexicalDC);
4839  LexicalDC->addDeclInternal(ToMethod);
4840 
4841  // Implicit params are declared when Sema encounters the definition but this
4842  // never happens when the method is imported. Manually declare the implicit
4843  // params now that the MethodDecl knows its class interface.
4844  if (D->getSelfDecl())
4845  ToMethod->createImplicitParams(Importer.getToContext(),
4846  ToMethod->getClassInterface());
4847 
4848  return ToMethod;
4849 }
4850 
4852  // Import the major distinguishing characteristics of a category.
4853  DeclContext *DC, *LexicalDC;
4854  DeclarationName Name;
4856  NamedDecl *ToD;
4857  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4858  return std::move(Err);
4859  if (ToD)
4860  return ToD;
4861 
4862  Error Err = Error::success();
4863  auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
4864  auto ToLocation = importChecked(Err, D->getLocation());
4865  auto ToColonLoc = importChecked(Err, D->getColonLoc());
4866  auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4867  if (Err)
4868  return std::move(Err);
4869 
4870  ObjCTypeParamDecl *Result;
4871  if (GetImportedOrCreateDecl(
4872  Result, D, Importer.getToContext(), DC, D->getVariance(),
4873  ToVarianceLoc, D->getIndex(),
4874  ToLocation, Name.getAsIdentifierInfo(),
4875  ToColonLoc, ToTypeSourceInfo))
4876  return Result;
4877 
4878  // Only import 'ObjCTypeParamType' after the decl is created.
4879  auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
4880  if (Err)
4881  return std::move(Err);
4882  Result->setTypeForDecl(ToTypeForDecl);
4883  Result->setLexicalDeclContext(LexicalDC);
4884  return Result;
4885 }
4886 
4888  // Import the major distinguishing characteristics of a category.
4889  DeclContext *DC, *LexicalDC;
4890  DeclarationName Name;
4892  NamedDecl *ToD;
4893  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4894  return std::move(Err);
4895  if (ToD)
4896  return ToD;
4897 
4898  ObjCInterfaceDecl *ToInterface;
4899  if (Error Err = importInto(ToInterface, D->getClassInterface()))
4900  return std::move(Err);
4901 
4902  // Determine if we've already encountered this category.
4903  ObjCCategoryDecl *MergeWithCategory
4904  = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
4905  ObjCCategoryDecl *ToCategory = MergeWithCategory;
4906  if (!ToCategory) {
4907 
4908  Error Err = Error::success();
4909  auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
4910  auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
4911  auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
4912  auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
4913  if (Err)
4914  return std::move(Err);
4915 
4916  if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
4917  ToAtStartLoc, Loc,
4918  ToCategoryNameLoc,
4919  Name.getAsIdentifierInfo(), ToInterface,
4920  /*TypeParamList=*/nullptr,
4921  ToIvarLBraceLoc,
4922  ToIvarRBraceLoc))
4923  return ToCategory;
4924 
4925  ToCategory->setLexicalDeclContext(LexicalDC);
4926  LexicalDC->addDeclInternal(ToCategory);
4927  // Import the type parameter list after MapImported, to avoid
4928  // loops when bringing in their DeclContext.
4929  if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
4930  ToCategory->setTypeParamList(*PListOrErr);
4931  else
4932  return PListOrErr.takeError();
4933 
4934  // Import protocols
4936  SmallVector<SourceLocation, 4> ProtocolLocs;
4938  = D->protocol_loc_begin();
4940  FromProtoEnd = D->protocol_end();
4941  FromProto != FromProtoEnd;
4942  ++FromProto, ++FromProtoLoc) {
4943  if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
4944  Protocols.push_back(*ToProtoOrErr);
4945  else
4946  return ToProtoOrErr.takeError();
4947 
4948  if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
4949  ProtocolLocs.push_back(*ToProtoLocOrErr);
4950  else
4951  return ToProtoLocOrErr.takeError();
4952  }
4953 
4954  // FIXME: If we're merging, make sure that the protocol list is the same.
4955  ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
4956  ProtocolLocs.data(), Importer.getToContext());
4957 
4958  } else {
4959  Importer.MapImported(D, ToCategory);
4960  }
4961 
4962  // Import all of the members of this category.
4963  if (Error Err = ImportDeclContext(D))
4964  return std::move(Err);
4965 
4966  // If we have an implementation, import it as well.
4967  if (D->getImplementation()) {
4968  if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
4969  import(D->getImplementation()))
4970  ToCategory->setImplementation(*ToImplOrErr);
4971  else
4972  return ToImplOrErr.takeError();
4973  }
4974 
4975  return ToCategory;
4976 }
4977 
4980  if (To->getDefinition()) {
4982  if (Error Err = ImportDeclContext(From))
4983  return Err;
4984  return Error::success();
4985  }
4986 
4987  // Start the protocol definition
4988  To->startDefinition();
4989 
4990  // Import protocols
4992  SmallVector<SourceLocation, 4> ProtocolLocs;
4994  From->protocol_loc_begin();
4995  for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
4996  FromProtoEnd = From->protocol_end();
4997  FromProto != FromProtoEnd;
4998  ++FromProto, ++FromProtoLoc) {
4999  if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5000  Protocols.push_back(*ToProtoOrErr);
5001  else
5002  return ToProtoOrErr.takeError();
5003 
5004  if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5005  ProtocolLocs.push_back(*ToProtoLocOrErr);
5006  else
5007  return ToProtoLocOrErr.takeError();
5008 
5009  }
5010 
5011  // FIXME: If we're merging, make sure that the protocol list is the same.
5012  To->setProtocolList(Protocols.data(), Protocols.size(),
5013  ProtocolLocs.data(), Importer.getToContext());
5014 
5016  // Import all of the members of this protocol.
5017  if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5018  return Err;
5019  }
5020  return Error::success();
5021 }
5022 
5024  // If this protocol has a definition in the translation unit we're coming
5025  // from, but this particular declaration is not that definition, import the
5026  // definition and map to that.
5027  ObjCProtocolDecl *Definition = D->getDefinition();
5028  if (Definition && Definition != D) {
5029  if (ExpectedDecl ImportedDefOrErr = import(Definition))
5030  return Importer.MapImported(D, *ImportedDefOrErr);
5031  else
5032  return ImportedDefOrErr.takeError();
5033  }
5034 
5035  // Import the major distinguishing characteristics of a protocol.
5036  DeclContext *DC, *LexicalDC;
5037  DeclarationName Name;
5039  NamedDecl *ToD;
5040  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5041  return std::move(Err);
5042  if (ToD)
5043  return ToD;
5044 
5045  ObjCProtocolDecl *MergeWithProtocol = nullptr;
5046  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5047  for (auto *FoundDecl : FoundDecls) {
5049  continue;
5050 
5051  if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
5052  break;
5053  }
5054 
5055  ObjCProtocolDecl *ToProto = MergeWithProtocol;
5056  if (!ToProto) {
5057  auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
5058  if (!ToAtBeginLocOrErr)
5059  return ToAtBeginLocOrErr.takeError();
5060 
5061  if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
5062  Name.getAsIdentifierInfo(), Loc,
5063  *ToAtBeginLocOrErr,
5064  /*PrevDecl=*/nullptr))
5065  return ToProto;
5066  ToProto->setLexicalDeclContext(LexicalDC);
5067  LexicalDC->addDeclInternal(ToProto);
5068  }
5069 
5070  Importer.MapImported(D, ToProto);
5071 
5073  if (Error Err = ImportDefinition(D, ToProto))
5074  return std::move(Err);
5075 
5076  return ToProto;
5077 }
5078 
5080  DeclContext *DC, *LexicalDC;
5081  if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5082  return std::move(Err);
5083 
5084  ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5085  if (!ExternLocOrErr)
5086  return ExternLocOrErr.takeError();
5087 
5088  ExpectedSLoc LangLocOrErr = import(D->getLocation());
5089  if (!LangLocOrErr)
5090  return LangLocOrErr.takeError();
5091 
5092  bool HasBraces = D->hasBraces();
5093 
5094  LinkageSpecDecl *ToLinkageSpec;
5095  if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5096  *ExternLocOrErr, *LangLocOrErr,
5097  D->getLanguage(), HasBraces))
5098  return ToLinkageSpec;
5099 
5100  if (HasBraces) {
5101  ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5102  if (!RBraceLocOrErr)
5103  return RBraceLocOrErr.takeError();
5104  ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5105  }
5106 
5107  ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5108  LexicalDC->addDeclInternal(ToLinkageSpec);
5109 
5110  return ToLinkageSpec;
5111 }
5112 
5114  BaseUsingDecl *ToSI) {
5115  for (UsingShadowDecl *FromShadow : D->shadows()) {
5116  if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5117  ToSI->addShadowDecl(*ToShadowOrErr);
5118  else
5119  // FIXME: We return error here but the definition is already created
5120  // and available with lookups. How to fix this?..
5121  return ToShadowOrErr.takeError();
5122  }
5123  return ToSI;
5124 }
5125 
5127  DeclContext *DC, *LexicalDC;
5128  DeclarationName Name;
5130  NamedDecl *ToD = nullptr;
5131  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5132  return std::move(Err);
5133  if (ToD)
5134  return ToD;
5135 
5136  Error Err = Error::success();
5137  auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5138  auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5139  auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5140  if (Err)
5141  return std::move(Err);
5142 
5143  DeclarationNameInfo NameInfo(Name, ToLoc);
5144  if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5145  return std::move(Err);
5146 
5147  UsingDecl *ToUsing;
5148  if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5149  ToUsingLoc, ToQualifierLoc, NameInfo,
5150  D->hasTypename()))
5151  return ToUsing;
5152 
5153  ToUsing->setLexicalDeclContext(LexicalDC);
5154  LexicalDC->addDeclInternal(ToUsing);
5155 
5156  if (NamedDecl *FromPattern =
5158  if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5160  ToUsing, *ToPatternOrErr);
5161  else
5162  return ToPatternOrErr.takeError();
5163  }
5164 
5165  return ImportUsingShadowDecls(D, ToUsing);
5166 }
5167 
5169  DeclContext *DC, *LexicalDC;
5170  DeclarationName Name;
5172  NamedDecl *ToD = nullptr;
5173  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5174  return std::move(Err);
5175  if (ToD)
5176  return ToD;
5177 
5178  Error Err = Error::success();
5179  auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5180  auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5181  auto ToNameLoc = importChecked(Err, D->getLocation());
5182  auto *ToEnumType = importChecked(Err, D->getEnumType());
5183  if (Err)
5184  return std::move(Err);
5185 
5186  UsingEnumDecl *ToUsingEnum;
5187  if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5188  ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5189  return ToUsingEnum;
5190 
5191  ToUsingEnum->setLexicalDeclContext(LexicalDC);
5192  LexicalDC->addDeclInternal(ToUsingEnum);
5193 
5194  if (UsingEnumDecl *FromPattern =
5196  if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5197  Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5198  *ToPatternOrErr);
5199  else
5200  return ToPatternOrErr.takeError();
5201  }
5202 
5203  return ImportUsingShadowDecls(D, ToUsingEnum);
5204 }
5205 
5207  DeclContext *DC, *LexicalDC;
5208  DeclarationName Name;
5210  NamedDecl *ToD = nullptr;
5211  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5212  return std::move(Err);
5213  if (ToD)
5214  return ToD;
5215 
5216  Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5217  if (!ToIntroducerOrErr)
5218  return ToIntroducerOrErr.takeError();
5219 
5220  Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5221  if (!ToTargetOrErr)
5222  return ToTargetOrErr.takeError();
5223 
5224  UsingShadowDecl *ToShadow;
5225  if (auto *FromConstructorUsingShadow =
5226  dyn_cast<ConstructorUsingShadowDecl>(D)) {
5227  Error Err = Error::success();
5229  Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5230  if (Err)
5231  return std::move(Err);
5232  // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5233  // is really the "NominatedBaseClassShadowDecl" value if it exists
5234  // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5235  // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5236  // get the correct values.
5237  if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5238  ToShadow, D, Importer.getToContext(), DC, Loc,
5239  cast<UsingDecl>(*ToIntroducerOrErr),
5240  Nominated ? Nominated : *ToTargetOrErr,
5241  FromConstructorUsingShadow->constructsVirtualBase()))
5242  return ToShadow;
5243  } else {
5244  if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5245  Name, *ToIntroducerOrErr, *ToTargetOrErr))
5246  return ToShadow;
5247  }
5248 
5249  ToShadow->setLexicalDeclContext(LexicalDC);
5250  ToShadow->setAccess(D->getAccess());
5251 
5252  if (UsingShadowDecl *FromPattern =
5254  if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5256  ToShadow, *ToPatternOrErr);
5257  else
5258  // FIXME: We return error here but the definition is already created
5259  // and available with lookups. How to fix this?..
5260  return ToPatternOrErr.takeError();
5261  }
5262 
5263  LexicalDC->addDeclInternal(ToShadow);
5264 
5265  return ToShadow;
5266 }
5267 
5269  DeclContext *DC, *LexicalDC;
5270  DeclarationName Name;
5272  NamedDecl *ToD = nullptr;
5273  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5274  return std::move(Err);
5275  if (ToD)
5276  return ToD;
5277 
5278  auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5279  if (!ToComAncestorOrErr)
5280  return ToComAncestorOrErr.takeError();
5281 
5282  Error Err = Error::success();
5283  auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5284  auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5285  auto ToNamespaceKeyLocation =
5287  auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5288  auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5289  if (Err)
5290  return std::move(Err);
5291 
5292  UsingDirectiveDecl *ToUsingDir;
5293  if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5294  ToUsingLoc,
5295  ToNamespaceKeyLocation,
5296  ToQualifierLoc,
5297  ToIdentLocation,
5298  ToNominatedNamespace, *ToComAncestorOrErr))
5299  return ToUsingDir;
5300 
5301  ToUsingDir->setLexicalDeclContext(LexicalDC);
5302  LexicalDC->addDeclInternal(ToUsingDir);
5303 
5304  return ToUsingDir;
5305 }
5306 
5308  DeclContext *DC, *LexicalDC;
5309  DeclarationName Name;
5311  NamedDecl *ToD = nullptr;
5312  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5313  return std::move(Err);
5314  if (ToD)
5315  return ToD;
5316 
5317  auto ToInstantiatedFromUsingOrErr =
5318  Importer.Import(D->getInstantiatedFromUsingDecl());
5319  if (!ToInstantiatedFromUsingOrErr)
5320  return ToInstantiatedFromUsingOrErr.takeError();
5321  SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5322  if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5323  return std::move(Err);
5324 
5325  UsingPackDecl *ToUsingPack;
5326  if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5327  cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5328  Expansions))
5329  return ToUsingPack;
5330 
5331  addDeclToContexts(D, ToUsingPack);
5332 
5333  return ToUsingPack;
5334 }
5335 
5338  DeclContext *DC, *LexicalDC;
5339  DeclarationName Name;
5341  NamedDecl *ToD = nullptr;
5342  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5343  return std::move(Err);
5344  if (ToD)
5345  return ToD;
5346 
5347  Error Err = Error::success();
5348  auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5349  auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5350  auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5351  auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5352  if (Err)
5353  return std::move(Err);
5354 
5355  DeclarationNameInfo NameInfo(Name, ToLoc);
5356  if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5357  return std::move(Err);
5358 
5359  UnresolvedUsingValueDecl *ToUsingValue;
5360  if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5361  ToUsingLoc, ToQualifierLoc, NameInfo,
5362  ToEllipsisLoc))
5363  return ToUsingValue;
5364 
5365  ToUsingValue->setAccess(D->getAccess());
5366  ToUsingValue->setLexicalDeclContext(LexicalDC);
5367  LexicalDC->addDeclInternal(ToUsingValue);
5368 
5369  return ToUsingValue;
5370 }
5371 
5374  DeclContext *DC, *LexicalDC;
5375  DeclarationName Name;
5377  NamedDecl *ToD = nullptr;
5378  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5379  return std::move(Err);
5380  if (ToD)
5381  return ToD;
5382 
5383  Error Err = Error::success();
5384  auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5385  auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5386  auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5387  auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5388  if (Err)
5389  return std::move(Err);
5390 
5391  UnresolvedUsingTypenameDecl *ToUsing;
5392  if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5393  ToUsingLoc, ToTypenameLoc,
5394  ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5395  return ToUsing;
5396 
5397  ToUsing->setAccess(D->getAccess());
5398  ToUsing->setLexicalDeclContext(LexicalDC);
5399  LexicalDC->addDeclInternal(ToUsing);
5400 
5401  return ToUsing;
5402 }
5403 
5405  Decl* ToD = nullptr;
5406  switch (D->getBuiltinTemplateKind()) {
5408  ToD = Importer.getToContext().getMakeIntegerSeqDecl();
5409  break;
5411  ToD = Importer.getToContext().getTypePackElementDecl();
5412  break;
5413  }
5414  assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5415  Importer.MapImported(D, ToD);
5416  return ToD;
5417 }
5418 
5421  if (To->getDefinition()) {
5422  // Check consistency of superclass.
5423  ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5424  if (FromSuper) {
5425  if (auto FromSuperOrErr = import(FromSuper))
5426  FromSuper = *FromSuperOrErr;
5427  else
5428  return FromSuperOrErr.takeError();
5429  }
5430 
5431  ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5432  if ((bool)FromSuper != (bool)ToSuper ||
5433  (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5434  Importer.ToDiag(To->getLocation(),
5435  diag::warn_odr_objc_superclass_inconsistent)
5436  << To->getDeclName();
5437  if (ToSuper)
5438  Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5439  << To->getSuperClass()->getDeclName();
5440  else
5441  Importer.ToDiag(To->getLocation(),
5442  diag::note_odr_objc_missing_superclass);
5443  if (From->getSuperClass())
5444  Importer.FromDiag(From->getSuperClassLoc(),
5445  diag::note_odr_objc_superclass)
5446  << From->getSuperClass()->getDeclName();
5447  else
5448  Importer.FromDiag(From->getLocation(),
5449  diag::note_odr_objc_missing_superclass);
5450  }
5451 
5453  if (Error Err = ImportDeclContext(From))
5454  return Err;
5455  return Error::success();
5456  }
5457 
5458  // Start the definition.
5459  To->startDefinition();
5460 
5461  // If this class has a superclass, import it.
5462  if (From->getSuperClass()) {
5463  if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5464  To->setSuperClass(*SuperTInfoOrErr);
5465  else
5466  return SuperTInfoOrErr.takeError();
5467  }
5468 
5469  // Import protocols
5471  SmallVector<SourceLocation, 4> ProtocolLocs;
5473  From->protocol_loc_begin();
5474 
5475  for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(),
5476  FromProtoEnd = From->protocol_end();
5477  FromProto != FromProtoEnd;
5478  ++FromProto, ++FromProtoLoc) {
5479  if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5480  Protocols.push_back(*ToProtoOrErr);
5481  else
5482  return ToProtoOrErr.takeError();
5483 
5484  if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5485  ProtocolLocs.push_back(*ToProtoLocOrErr);
5486  else
5487  return ToProtoLocOrErr.takeError();
5488 
5489  }
5490 
5491  // FIXME: If we're merging, make sure that the protocol list is the same.
5492  To->setProtocolList(Protocols.data(), Protocols.size(),
5493  ProtocolLocs.data(), Importer.getToContext());
5494 
5495  // Import categories. When the categories themselves are imported, they'll
5496  // hook themselves into this interface.
5497  for (auto *Cat : From->known_categories()) {
5498  auto ToCatOrErr = import(Cat);
5499  if (!ToCatOrErr)
5500  return ToCatOrErr.takeError();
5501  }
5502 
5503  // If we have an @implementation, import it as well.
5504  if (From->getImplementation()) {
5505  if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5506  import(From->getImplementation()))
5507  To->setImplementation(*ToImplOrErr);
5508  else
5509  return ToImplOrErr.takeError();
5510  }
5511 
5512  // Import all of the members of this class.
5513  if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5514  return Err;
5515 
5516  return Error::success();
5517 }
5518 
5521  if (!list)
5522  return nullptr;
5523 
5525  for (auto *fromTypeParam : *list) {
5526  if (auto toTypeParamOrErr = import(fromTypeParam))
5527  toTypeParams.push_back(*toTypeParamOrErr);
5528  else
5529  return toTypeParamOrErr.takeError();
5530  }
5531 
5532  auto LAngleLocOrErr = import(list->getLAngleLoc());
5533  if (!LAngleLocOrErr)
5534  return LAngleLocOrErr.takeError();
5535 
5536  auto RAngleLocOrErr = import(list->getRAngleLoc());
5537  if (!RAngleLocOrErr)
5538  return RAngleLocOrErr.takeError();
5539 
5540  return ObjCTypeParamList::create(Importer.getToContext(),
5541  *LAngleLocOrErr,
5542  toTypeParams,
5543  *RAngleLocOrErr);
5544 }
5545 
5547  // If this class has a definition in the translation unit we're coming from,
5548  // but this particular declaration is not that definition, import the
5549  // definition and map to that.
5550  ObjCInterfaceDecl *Definition = D->getDefinition();
5551  if (Definition && Definition != D) {
5552  if (ExpectedDecl ImportedDefOrErr = import(Definition))
5553  return Importer.MapImported(D, *ImportedDefOrErr);
5554  else
5555  return ImportedDefOrErr.takeError();
5556  }
5557 
5558  // Import the major distinguishing characteristics of an @interface.
5559  DeclContext *DC, *LexicalDC;
5560  DeclarationName Name;
5562  NamedDecl *ToD;
5563  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5564  return std::move(Err);
5565  if (ToD)
5566  return ToD;
5567 
5568  // Look for an existing interface with the same name.
5569  ObjCInterfaceDecl *MergeWithIface = nullptr;
5570  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5571  for (auto *FoundDecl : FoundDecls) {
5573  continue;
5574 
5575  if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5576  break;
5577  }
5578 
5579  // Create an interface declaration, if one does not already exist.
5580  ObjCInterfaceDecl *ToIface = MergeWithIface;
5581  if (!ToIface) {
5582  ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5583  if (!AtBeginLocOrErr)
5584  return AtBeginLocOrErr.takeError();
5585 
5586  if (GetImportedOrCreateDecl(
5587  ToIface, D, Importer.getToContext(), DC,
5588  *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5589  /*TypeParamList=*/nullptr,
5590  /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5591  return ToIface;
5592  ToIface->setLexicalDeclContext(LexicalDC);
5593  LexicalDC->addDeclInternal(ToIface);
5594  }
5595  Importer.MapImported(D, ToIface);
5596  // Import the type parameter list after MapImported, to avoid
5597  // loops when bringing in their DeclContext.
5598  if (auto ToPListOrErr =
5600  ToIface->setTypeParamList(*ToPListOrErr);
5601  else
5602  return ToPListOrErr.takeError();
5603 
5605  if (Error Err = ImportDefinition(D, ToIface))
5606  return std::move(Err);
5607 
5608  return ToIface;
5609 }
5610 
5614  if (Error Err = importInto(Category, D->getCategoryDecl()))
5615  return std::move(Err);
5616 
5617  ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5618  if (!ToImpl) {
5619  DeclContext *DC, *LexicalDC;
5620  if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5621  return std::move(Err);
5622 
5623  Error Err = Error::success();
5624  auto ToLocation = importChecked(Err, D->getLocation());
5625  auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5626  auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5627  if (Err)
5628  return std::move(Err);
5629 
5630  if (GetImportedOrCreateDecl(
5631  ToImpl, D, Importer.getToContext(), DC,
5632  Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5633  ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5634  return ToImpl;
5635 
5636  ToImpl->setLexicalDeclContext(LexicalDC);
5637  LexicalDC->addDeclInternal(ToImpl);
5638  Category->setImplementation(ToImpl);
5639  }
5640 
5641  Importer.MapImported(D, ToImpl);
5642  if (Error Err = ImportDeclContext(D))
5643  return std::move(Err);
5644 
5645  return ToImpl;
5646 }
5647 
5650  // Find the corresponding interface.
5651  ObjCInterfaceDecl *Iface;
5652  if (Error Err = importInto(Iface, D->getClassInterface()))
5653  return std::move(Err);
5654 
5655  // Import the superclass, if any.
5656  ObjCInterfaceDecl *Super;
5657  if (Error Err = importInto(Super, D->getSuperClass()))
5658  return std::move(Err);
5659 
5660  ObjCImplementationDecl *Impl = Iface->getImplementation();
5661  if (!Impl) {
5662  // We haven't imported an implementation yet. Create a new @implementation
5663  // now.
5664  DeclContext *DC, *LexicalDC;
5665  if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5666  return std::move(Err);
5667 
5668  Error Err = Error::success();
5669  auto ToLocation = importChecked(Err, D->getLocation());
5670  auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5671  auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5672  auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5673  auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5674  if (Err)
5675  return std::move(Err);
5676 
5677  if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5678  DC, Iface, Super,
5679  ToLocation,
5680  ToAtStartLoc,
5681  ToSuperClassLoc,
5682  ToIvarLBraceLoc,
5683  ToIvarRBraceLoc))
5684  return Impl;
5685 
5686  Impl->setLexicalDeclContext(LexicalDC);
5687 
5688  // Associate the implementation with the class it implements.
5689  Iface->setImplementation(Impl);
5690  Importer.MapImported(D, Iface->getImplementation());
5691  } else {
5692  Importer.MapImported(D, Iface->getImplementation());
5693 
5694  // Verify that the existing @implementation has the same superclass.
5695  if ((Super && !Impl->getSuperClass()) ||
5696  (!Super && Impl->getSuperClass()) ||
5697  (Super && Impl->getSuperClass() &&
5699  Impl->getSuperClass()))) {
5700  Importer.ToDiag(Impl->getLocation(),
5701  diag::warn_odr_objc_superclass_inconsistent)
5702  << Iface->getDeclName();
5703  // FIXME: It would be nice to have the location of the superclass
5704  // below.
5705  if (Impl->getSuperClass())
5706  Importer.ToDiag(Impl->getLocation(),
5707  diag::note_odr_objc_superclass)
5708  << Impl->getSuperClass()->getDeclName();
5709  else
5710  Importer.ToDiag(Impl->getLocation(),
5711  diag::note_odr_objc_missing_superclass);
5712  if (D->getSuperClass())
5713  Importer.FromDiag(D->getLocation(),
5714  diag::note_odr_objc_superclass)
5715  << D->getSuperClass()->getDeclName();
5716  else
5717  Importer.FromDiag(D->getLocation(),
5718  diag::note_odr_objc_missing_superclass);
5719 
5720  return make_error<ASTImportError>(ASTImportError::NameConflict);
5721  }
5722  }
5723 
5724  // Import all of the members of this @implementation.
5725  if (Error Err = ImportDeclContext(D))
5726  return std::move(Err);
5727 
5728  return Impl;
5729 }
5730 
5732  // Import the major distinguishing characteristics of an @property.
5733  DeclContext *DC, *LexicalDC;
5734  DeclarationName Name;
5736  NamedDecl *ToD;
5737  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5738  return std::move(Err);
5739  if (ToD)
5740  return ToD;
5741 
5742  // Check whether we have already imported this property.
5743  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5744  for (auto *FoundDecl : FoundDecls) {
5745  if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
5746  // Instance and class properties can share the same name but are different
5747  // declarations.
5748  if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
5749  continue;
5750 
5751  // Check property types.
5752  if (!Importer.IsStructurallyEquivalent(D->getType(),
5753  FoundProp->getType())) {
5754  Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
5755  << Name << D->getType() << FoundProp->getType();
5756  Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
5757  << FoundProp->getType();
5758 
5759  return make_error<ASTImportError>(ASTImportError::NameConflict);
5760  }
5761 
5762  // FIXME: Check property attributes, getters, setters, etc.?
5763 
5764  // Consider these properties to be equivalent.
5765  Importer.MapImported(D, FoundProp);
5766  return FoundProp;
5767  }
5768  }
5769 
5770  Error Err = Error::success();
5771  auto ToType = importChecked(Err, D->getType());
5772  auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5773  auto ToAtLoc = importChecked(Err, D->getAtLoc());
5774  auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
5775  if (Err)
5776  return std::move(Err);
5777 
5778  // Create the new property.
5779  ObjCPropertyDecl *ToProperty;
5780  if (GetImportedOrCreateDecl(
5781  ToProperty, D, Importer.getToContext(), DC, Loc,
5782  Name.getAsIdentifierInfo(), ToAtLoc,
5783  ToLParenLoc, ToType,
5784  ToTypeSourceInfo, D->getPropertyImplementation()))
5785  return ToProperty;
5786 
5787  auto ToGetterName = importChecked(Err, D->getGetterName());
5788  auto ToSetterName = importChecked(Err, D->getSetterName());
5789  auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
5790  auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
5791  auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
5792  auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
5793  auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
5794  if (Err)
5795  return std::move(Err);
5796 
5797  ToProperty->setLexicalDeclContext(LexicalDC);
5798  LexicalDC->addDeclInternal(ToProperty);
5799 
5800  ToProperty->setPropertyAttributes(D->getPropertyAttributes());
5801  ToProperty->setPropertyAttributesAsWritten(
5803  ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
5804  ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
5805  ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
5806  ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
5807  ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
5808  return ToProperty;
5809 }
5810 
5814  if (Error Err = importInto(Property, D->getPropertyDecl()))
5815  return std::move(Err);
5816 
5817  DeclContext *DC, *LexicalDC;
5818  if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5819  return std::move(Err);
5820 
5821  auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
5822 
5823  // Import the ivar (for an @synthesize).
5824  ObjCIvarDecl *Ivar = nullptr;
5825  if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
5826  return std::move(Err);
5827 
5828  ObjCPropertyImplDecl *ToImpl
5829  = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
5830  Property->getQueryKind());
5831  if (!ToImpl) {
5832 
5833  Error Err = Error::success();
5834  auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
5835  auto ToLocation = importChecked(Err, D->getLocation());
5836  auto ToPropertyIvarDeclLoc =
5838  if (Err)
5839  return std::move(Err);
5840 
5841  if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
5842  ToBeginLoc,
5843  ToLocation, Property,
5844  D->getPropertyImplementation(), Ivar,
5845  ToPropertyIvarDeclLoc))
5846  return ToImpl;
5847 
5848  ToImpl->setLexicalDeclContext(LexicalDC);
5849  LexicalDC->addDeclInternal(ToImpl);
5850  } else {
5851  // Check that we have the same kind of property implementation (@synthesize
5852  // vs. @dynamic).
5853  if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) {
5854  Importer.ToDiag(ToImpl->getLocation(),
5855  diag::warn_odr_objc_property_impl_kind_inconsistent)
5856  << Property->getDeclName()
5857  << (ToImpl->getPropertyImplementation()
5859  Importer.FromDiag(D->getLocation(),
5860  diag::note_odr_objc_property_impl_kind)
5861  << D->getPropertyDecl()->getDeclName()
5863 
5864  return make_error<ASTImportError>(ASTImportError::NameConflict);
5865  }
5866 
5867  // For @synthesize, check that we have the same
5869  Ivar != ToImpl->getPropertyIvarDecl()) {
5870  Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
5871  diag::warn_odr_objc_synthesize_ivar_inconsistent)
5872  << Property->getDeclName()
5873  << ToImpl->getPropertyIvarDecl()->getDeclName()
5874  << Ivar->getDeclName();
5875  Importer.FromDiag(D->getPropertyIvarDeclLoc(),
5876  diag::note_odr_objc_synthesize_ivar_here)
5877  << D->getPropertyIvarDecl()->getDeclName();
5878 
5879  return make_error<ASTImportError>(ASTImportError::NameConflict);
5880  }
5881 
5882  // Merge the existing implementation with the new implementation.
5883  Importer.MapImported(D, ToImpl);
5884  }
5885 
5886  return ToImpl;
5887 }
5888 
5891  // For template arguments, we adopt the translation unit as our declaration
5892  // context. This context will be fixed when the actual template declaration
5893  // is created.
5894 
5895  ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
5896  if (!BeginLocOrErr)
5897  return BeginLocOrErr.takeError();
5898 
5899  ExpectedSLoc LocationOrErr = import(D->getLocation());
5900  if (!LocationOrErr)
5901  return LocationOrErr.takeError();
5902 
5903  TemplateTypeParmDecl *ToD = nullptr;
5904  if (GetImportedOrCreateDecl(
5905  ToD, D, Importer.getToContext(),
5906  Importer.getToContext().getTranslationUnitDecl(),
5907  *BeginLocOrErr, *LocationOrErr,
5908  D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
5910  D->hasTypeConstraint()))
5911  return ToD;
5912 
5913  // Import the type-constraint
5914  if (const TypeConstraint *TC = D->getTypeConstraint()) {
5915 
5916  Error Err = Error::success();
5917  auto ToConceptRef = importChecked(Err, TC->getConceptReference());
5918  auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
5919  if (Err)
5920  return std::move(Err);
5921 
5922  ToD->setTypeConstraint(ToConceptRef, ToIDC);
5923  }
5924 
5925  if (D->hasDefaultArgument()) {
5926  Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
5927  import(D->getDefaultArgument());
5928  if (!ToDefaultArgOrErr)
5929  return ToDefaultArgOrErr.takeError();
5930  ToD->setDefaultArgument(ToD->getASTContext(), *ToDefaultArgOrErr);
5931  }
5932 
5933  return ToD;
5934 }
5935 
5938 
5939  Error Err = Error::success();
5940  auto ToDeclName = importChecked(Err, D->getDeclName());
5941  auto ToLocation = importChecked(Err, D->getLocation());
5942  auto ToType = importChecked(Err, D->getType());
5943  auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5944  auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
5945  if (Err)
5946  return std::move(Err);
5947 
5948  NonTypeTemplateParmDecl *ToD = nullptr;
5949  if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
5950  Importer.getToContext().getTranslationUnitDecl(),
5951  ToInnerLocStart, ToLocation, D->getDepth(),
5952  D->getPosition(),
5953  ToDeclName.getAsIdentifierInfo(), ToType,
5954  D->isParameterPack(), ToTypeSourceInfo))
5955  return ToD;
5956 
5957  if (D->hasDefaultArgument()) {
5958  Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
5959  import(D->getDefaultArgument());
5960  if (!ToDefaultArgOrErr)
5961  return ToDefaultArgOrErr.takeError();
5962  ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
5963  }
5964 
5965  return ToD;
5966 }
5967 
5970  // Import the name of this declaration.
5971  auto NameOrErr = import(D->getDeclName());
5972  if (!NameOrErr)
5973  return NameOrErr.takeError();
5974 
5975  // Import the location of this declaration.
5976  ExpectedSLoc LocationOrErr = import(D->getLocation());
5977  if (!LocationOrErr)
5978  return LocationOrErr.takeError();
5979 
5980  // Import template parameters.
5981  auto TemplateParamsOrErr = import(D->getTemplateParameters());
5982  if (!TemplateParamsOrErr)
5983  return TemplateParamsOrErr.takeError();
5984 
5985  TemplateTemplateParmDecl *ToD = nullptr;
5986  if (GetImportedOrCreateDecl(
5987  ToD, D, Importer.getToContext(),
5988  Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
5989  D->getDepth(), D->getPosition(), D->isParameterPack(),
5990  (*NameOrErr).getAsIdentifierInfo(), D->wasDeclaredWithTypename(),
5991  *TemplateParamsOrErr))
5992  return ToD;
5993 
5994  if (D->hasDefaultArgument()) {
5995  Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
5996  import(D->getDefaultArgument());
5997  if (!ToDefaultArgOrErr)
5998  return ToDefaultArgOrErr.takeError();
5999  ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
6000  }
6001 
6002  return ToD;
6003 }
6004 
6005 // Returns the definition for a (forward) declaration of a TemplateDecl, if
6006 // it has any definition in the redecl chain.
6007 template <typename T> static auto getTemplateDefinition(T *D) -> T * {
6008  assert(D->getTemplatedDecl() && "Should be called on templates only");
6009  auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
6010  if (!ToTemplatedDef)
6011  return nullptr;
6012  auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
6013  return cast_or_null<T>(TemplateWithDef);
6014 }
6015 
6017 
6018  // Import the major distinguishing characteristics of this class template.
6019  DeclContext *DC, *LexicalDC;
6020  DeclarationName Name;
6022  NamedDecl *ToD;
6023  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6024  return std::move(Err);
6025  if (ToD)
6026  return ToD;
6027 
6028  // Should check if a declaration is friend in a dependent context.
6029  // Such templates are not linked together in a declaration chain.
6030  // The ASTImporter strategy is to map existing forward declarations to
6031  // imported ones only if strictly necessary, otherwise import these as new
6032  // forward declarations. In case of the "dependent friend" declarations, new
6033  // declarations are created, but not linked in a declaration chain.
6034  auto IsDependentFriend = [](ClassTemplateDecl *TD) {
6035  return TD->getFriendObjectKind() != Decl::FOK_None &&
6037  };
6038  bool DependentFriend = IsDependentFriend(D);
6039 
6040  ClassTemplateDecl *FoundByLookup = nullptr;
6041 
6042  // We may already have a template of the same name; try to find and match it.
6043  if (!DC->isFunctionOrMethod()) {
6044  SmallVector<NamedDecl *, 4> ConflictingDecls;
6045  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6046  for (auto *FoundDecl : FoundDecls) {
6049  continue;
6050 
6051  Decl *Found = FoundDecl;
6052  auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found);
6053  if (FoundTemplate) {
6054  if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6055  continue;
6056 
6057  // FIXME: sufficient conditon for 'IgnoreTemplateParmDepth'?
6058  bool IgnoreTemplateParmDepth =
6059  (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
6061  if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
6062  IgnoreTemplateParmDepth)) {
6063  if (DependentFriend || IsDependentFriend(FoundTemplate))
6064  continue;
6065 
6066  ClassTemplateDecl *TemplateWithDef =
6067  getTemplateDefinition(FoundTemplate);
6068  if (D->isThisDeclarationADefinition() && TemplateWithDef)
6069  return Importer.MapImported(D, TemplateWithDef);
6070  if (!FoundByLookup)
6071  FoundByLookup = FoundTemplate;
6072  // Search in all matches because there may be multiple decl chains,
6073  // see ASTTests test ImportExistingFriendClassTemplateDef.
6074  continue;
6075  }
6076  ConflictingDecls.push_back(FoundDecl);
6077  }
6078  }
6079 
6080  if (!ConflictingDecls.empty()) {
6081  ExpectedName NameOrErr = Importer.HandleNameConflict(
6082  Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6083  ConflictingDecls.size());
6084  if (NameOrErr)
6085  Name = NameOrErr.get();
6086  else
6087  return NameOrErr.takeError();
6088  }
6089  }
6090 
6091  CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6092 
6093  auto TemplateParamsOrErr = import(D->getTemplateParameters());
6094  if (!TemplateParamsOrErr)
6095  return TemplateParamsOrErr.takeError();
6096 
6097  // Create the declaration that is being templated.
6098  CXXRecordDecl *ToTemplated;
6099  if (Error Err = importInto(ToTemplated, FromTemplated))
6100  return std::move(Err);
6101 
6102  // Create the class template declaration itself.
6103  ClassTemplateDecl *D2;
6104  if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6105  *TemplateParamsOrErr, ToTemplated))
6106  return D2;
6107 
6108  ToTemplated->setDescribedClassTemplate(D2);
6109 
6110  D2->setAccess(D->getAccess());
6111  D2->setLexicalDeclContext(LexicalDC);
6112 
6113  addDeclToContexts(D, D2);
6114  updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6115 
6116  if (FoundByLookup) {
6117  auto *Recent =
6118  const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6119 
6120  // It is possible that during the import of the class template definition
6121  // we start the import of a fwd friend decl of the very same class template
6122  // and we add the fwd friend decl to the lookup table. But the ToTemplated
6123  // had been created earlier and by that time the lookup could not find
6124  // anything existing, so it has no previous decl. Later, (still during the
6125  // import of the fwd friend decl) we start to import the definition again
6126  // and this time the lookup finds the previous fwd friend class template.
6127  // In this case we must set up the previous decl for the templated decl.
6128  if (!ToTemplated->getPreviousDecl()) {
6129  assert(FoundByLookup->getTemplatedDecl() &&
6130  "Found decl must have its templated decl set");
6131  CXXRecordDecl *PrevTemplated =
6132  FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6133  if (ToTemplated != PrevTemplated)
6134  ToTemplated->setPreviousDecl(PrevTemplated);
6135  }
6136 
6137  D2->setPreviousDecl(Recent);
6138  }
6139 
6140  return D2;
6141 }
6142 
6145  ClassTemplateDecl *ClassTemplate;
6146  if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6147  return std::move(Err);
6148 
6149  // Import the context of this declaration.
6150  DeclContext *DC, *LexicalDC;
6151  if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6152  return std::move(Err);
6153 
6154  // Import template arguments.
6155  SmallVector<TemplateArgument, 2> TemplateArgs;
6156  if (Error Err =
6157  ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6158  return std::move(Err);
6159  // Try to find an existing specialization with these template arguments and
6160  // template parameter list.
6161  void *InsertPos = nullptr;
6162  ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6164  dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6165 
6166  // Import template parameters.
6167  TemplateParameterList *ToTPList = nullptr;
6168 
6169  if (PartialSpec) {
6170  auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6171  if (!ToTPListOrErr)
6172  return ToTPListOrErr.takeError();
6173  ToTPList = *ToTPListOrErr;
6174  PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs,
6175  *ToTPListOrErr,
6176  InsertPos);
6177  } else
6178  PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
6179 
6180  if (PrevDecl) {
6181  if (IsStructuralMatch(D, PrevDecl)) {
6182  CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6183  if (D->isThisDeclarationADefinition() && PrevDefinition) {
6184  Importer.MapImported(D, PrevDefinition);
6185  // Import those default field initializers which have been
6186  // instantiated in the "From" context, but not in the "To" context.
6187  for (auto *FromField : D->fields()) {
6188  auto ToOrErr = import(FromField);
6189  if (!ToOrErr)
6190  return ToOrErr.takeError();
6191  }
6192 
6193  // Import those methods which have been instantiated in the
6194  // "From" context, but not in the "To" context.
6195  for (CXXMethodDecl *FromM : D->methods()) {
6196  auto ToOrErr = import(FromM);
6197  if (!ToOrErr)
6198  return ToOrErr.takeError();
6199  }
6200 
6201  // TODO Import instantiated default arguments.
6202  // TODO Import instantiated exception specifications.
6203  //
6204  // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6205  // what else could be fused during an AST merge.
6206  return PrevDefinition;
6207  }
6208  } else { // ODR violation.
6209  // FIXME HandleNameConflict
6210  return make_error<ASTImportError>(ASTImportError::NameConflict);
6211  }
6212  }
6213 
6214  // Import the location of this declaration.
6215  ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6216  if (!BeginLocOrErr)
6217  return BeginLocOrErr.takeError();
6218  ExpectedSLoc IdLocOrErr = import(D->getLocation());
6219  if (!IdLocOrErr)
6220  return IdLocOrErr.takeError();
6221 
6222  // Import TemplateArgumentListInfo.
6223  TemplateArgumentListInfo ToTAInfo;
6224  if (const auto *ASTTemplateArgs = D->getTemplateArgsAsWritten()) {
6225  if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
6226  return std::move(Err);
6227  }
6228 
6229  // Create the specialization.
6230  ClassTemplateSpecializationDecl *D2 = nullptr;
6231  if (PartialSpec) {
6232  QualType CanonInjType;
6233  if (Error Err = importInto(
6234  CanonInjType, PartialSpec->getInjectedSpecializationType()))
6235  return std::move(Err);
6236  CanonInjType = CanonInjType.getCanonicalType();
6237 
6238  if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6239  D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6240  *IdLocOrErr, ToTPList, ClassTemplate,
6241  llvm::ArrayRef(TemplateArgs.data(), TemplateArgs.size()),
6242  CanonInjType,
6243  cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6244  return D2;
6245 
6246  // Update InsertPos, because preceding import calls may have invalidated
6247  // it by adding new specializations.
6248  auto *PartSpec2 = cast<ClassTemplatePartialSpecializationDecl>(D2);
6249  if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6250  InsertPos))
6251  // Add this partial specialization to the class template.
6252  ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
6254  import(PartialSpec->getInstantiatedFromMember()))
6255  PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6256  else
6257  return ToInstOrErr.takeError();
6258 
6259  updateLookupTableForTemplateParameters(*ToTPList);
6260  } else { // Not a partial specialization.
6261  if (GetImportedOrCreateDecl(
6262  D2, D, Importer.getToContext(), D->getTagKind(), DC,
6263  *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs,
6264  PrevDecl))
6265  return D2;
6266 
6267  // Update InsertPos, because preceding import calls may have invalidated
6268  // it by adding new specializations.
6269  if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos))
6270  // Add this specialization to the class template.
6271  ClassTemplate->AddSpecialization(D2, InsertPos);
6272  }
6273 
6275 
6276  // Set the context of this specialization/instantiation.
6277  D2->setLexicalDeclContext(LexicalDC);
6278 
6279  // Add to the DC only if it was an explicit specialization/instantiation.
6281  LexicalDC->addDeclInternal(D2);
6282  }
6283 
6284  if (auto BraceRangeOrErr = import(D->getBraceRange()))
6285  D2->setBraceRange(*BraceRangeOrErr);
6286  else
6287  return BraceRangeOrErr.takeError();
6288 
6289  if (Error Err = ImportTemplateParameterLists(D, D2))
6290  return std::move(Err);
6291 
6292  // Import the qualifier, if any.
6293  if (auto LocOrErr = import(D->getQualifierLoc()))
6294  D2->setQualifierInfo(*LocOrErr);
6295  else
6296  return LocOrErr.takeError();
6297 
6298  if (D->getTemplateArgsAsWritten())
6299  D2->setTemplateArgsAsWritten(ToTAInfo);
6300 
6301  if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6302  D2->setTemplateKeywordLoc(*LocOrErr);
6303  else
6304  return LocOrErr.takeError();
6305 
6306  if (auto LocOrErr = import(D->getExternKeywordLoc()))
6307  D2->setExternKeywordLoc(*LocOrErr);
6308  else
6309  return LocOrErr.takeError();
6310 
6311  if (D->getPointOfInstantiation().isValid()) {
6312  if (auto POIOrErr = import(D->getPointOfInstantiation()))
6313  D2->setPointOfInstantiation(*POIOrErr);
6314  else
6315  return POIOrErr.takeError();
6316  }
6317 
6319 
6320  if (auto P = D->getInstantiatedFrom()) {
6321  if (auto *CTD = P.dyn_cast<ClassTemplateDecl *>()) {
6322  if (auto CTDorErr = import(CTD))
6323  D2->setInstantiationOf(*CTDorErr);
6324  } else {
6325  auto *CTPSD = cast<ClassTemplatePartialSpecializationDecl *>(P);
6326  auto CTPSDOrErr = import(CTPSD);
6327  if (!CTPSDOrErr)
6328  return CTPSDOrErr.takeError();
6330  SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6331  for (unsigned I = 0; I < DArgs.size(); ++I) {
6332  const TemplateArgument &DArg = DArgs[I];
6333  if (auto ArgOrErr = import(DArg))
6334  D2ArgsVec[I] = *ArgOrErr;
6335  else
6336  return ArgOrErr.takeError();
6337  }
6338  D2->setInstantiationOf(
6339  *CTPSDOrErr,
6340  TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6341  }
6342  }
6343 
6344  if (D->isCompleteDefinition())
6345  if (Error Err = ImportDefinition(D, D2))
6346  return std::move(Err);
6347 
6348  return D2;
6349 }
6350 
6352  // Import the major distinguishing characteristics of this variable template.
6353  DeclContext *DC, *LexicalDC;
6354  DeclarationName Name;
6356  NamedDecl *ToD;
6357  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6358  return std::move(Err);
6359  if (ToD)
6360  return ToD;
6361 
6362  // We may already have a template of the same name; try to find and match it.
6363  assert(!DC->isFunctionOrMethod() &&
6364  "Variable templates cannot be declared at function scope");
6365 
6366  SmallVector<NamedDecl *, 4> ConflictingDecls;
6367  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6368  VarTemplateDecl *FoundByLookup = nullptr;
6369  for (auto *FoundDecl : FoundDecls) {
6371  continue;
6372 
6373  if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6374  // Use the templated decl, some linkage flags are set only there.
6375  if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6376  D->getTemplatedDecl()))
6377  continue;
6378  if (IsStructuralMatch(D, FoundTemplate)) {
6379  // FIXME Check for ODR error if the two definitions have
6380  // different initializers?
6381  VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6382  if (D->getDeclContext()->isRecord()) {
6383  assert(FoundTemplate->getDeclContext()->isRecord() &&
6384  "Member variable template imported as non-member, "
6385  "inconsistent imported AST?");
6386  if (FoundDef)
6387  return Importer.MapImported(D, FoundDef);
6388  if (!D->isThisDeclarationADefinition())
6389  return Importer.MapImported(D, FoundTemplate);
6390  } else {
6391  if (FoundDef && D->isThisDeclarationADefinition())
6392  return Importer.MapImported(D, FoundDef);
6393  }
6394  FoundByLookup = FoundTemplate;
6395  break;
6396  }
6397  ConflictingDecls.push_back(FoundDecl);
6398  }
6399  }
6400 
6401  if (!ConflictingDecls.empty()) {
6402  ExpectedName NameOrErr = Importer.HandleNameConflict(
6403  Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6404  ConflictingDecls.size());
6405  if (NameOrErr)
6406  Name = NameOrErr.get();
6407  else
6408  return NameOrErr.takeError();
6409  }
6410 
6411  VarDecl *DTemplated = D->getTemplatedDecl();
6412 
6413  // Import the type.
6414  // FIXME: Value not used?
6415  ExpectedType TypeOrErr = import(DTemplated->getType());
6416  if (!TypeOrErr)
6417  return TypeOrErr.takeError();
6418 
6419  // Create the declaration that is being templated.
6420  VarDecl *ToTemplated;
6421  if (Error Err = importInto(ToTemplated, DTemplated))
6422  return std::move(Err);
6423 
6424  // Create the variable template declaration itself.
6425  auto TemplateParamsOrErr = import(D->getTemplateParameters());
6426  if (!TemplateParamsOrErr)
6427  return TemplateParamsOrErr.takeError();
6428 
6429  VarTemplateDecl *ToVarTD;
6430  if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6431  Name, *TemplateParamsOrErr, ToTemplated))
6432  return ToVarTD;
6433 
6434  ToTemplated->setDescribedVarTemplate(ToVarTD);
6435 
6436  ToVarTD->setAccess(D->getAccess());
6437  ToVarTD->setLexicalDeclContext(LexicalDC);
6438  LexicalDC->addDeclInternal(ToVarTD);
6439  if (DC != Importer.getToContext().getTranslationUnitDecl())
6440  updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6441 
6442  if (FoundByLookup) {
6443  auto *Recent =
6444  const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6445  if (!ToTemplated->getPreviousDecl()) {
6446  auto *PrevTemplated =
6447  FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6448  if (ToTemplated != PrevTemplated)
6449  ToTemplated->setPreviousDecl(PrevTemplated);
6450  }
6451  ToVarTD->setPreviousDecl(Recent);
6452  }
6453 
6454  return ToVarTD;
6455 }
6456 
6459  // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6460  // in an analog way (but specialized for this case).
6461 
6463  auto RedeclIt = Redecls.begin();
6464  // Import the first part of the decl chain. I.e. import all previous
6465  // declarations starting from the canonical decl.
6466  for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6467  ExpectedDecl RedeclOrErr = import(*RedeclIt);
6468  if (!RedeclOrErr)
6469  return RedeclOrErr.takeError();
6470  }
6471  assert(*RedeclIt == D);
6472 
6473  VarTemplateDecl *VarTemplate = nullptr;
6474  if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate()))
6475  return std::move(Err);
6476 
6477  // Import the context of this declaration.
6478  DeclContext *DC, *LexicalDC;
6479  if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6480  return std::move(Err);
6481 
6482  // Import the location of this declaration.
6483  ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6484  if (!BeginLocOrErr)
6485  return BeginLocOrErr.takeError();
6486 
6487  auto IdLocOrErr = import(D->getLocation());
6488  if (!IdLocOrErr)
6489  return IdLocOrErr.takeError();
6490 
6491  // Import template arguments.
6492  SmallVector<TemplateArgument, 2> TemplateArgs;
6493  if (Error Err =
6494  ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6495  return std::move(Err);
6496 
6497  // Try to find an existing specialization with these template arguments.
6498  void *InsertPos = nullptr;
6499  VarTemplateSpecializationDecl *FoundSpecialization =
6500  VarTemplate->findSpecialization(TemplateArgs, InsertPos);
6501  if (FoundSpecialization) {
6502  if (IsStructuralMatch(D, FoundSpecialization)) {
6503  VarDecl *FoundDef = FoundSpecialization->getDefinition();
6504  if (D->getDeclContext()->isRecord()) {
6505  // In a record, it is allowed only to have one optional declaration and
6506  // one definition of the (static or constexpr) variable template.
6507  assert(
6508  FoundSpecialization->getDeclContext()->isRecord() &&
6509  "Member variable template specialization imported as non-member, "
6510  "inconsistent imported AST?");
6511  if (FoundDef)
6512  return Importer.MapImported(D, FoundDef);
6513  if (!D->isThisDeclarationADefinition())
6514  return Importer.MapImported(D, FoundSpecialization);
6515  } else {
6516  // If definition is imported and there is already one, map to it.
6517  // Otherwise create a new variable and link it to the existing.
6518  if (FoundDef && D->isThisDeclarationADefinition())
6519  return Importer.MapImported(D, FoundDef);
6520  }
6521  } else {
6522  return make_error<ASTImportError>(ASTImportError::NameConflict);
6523  }
6524  }
6525 
6526  VarTemplateSpecializationDecl *D2 = nullptr;
6527 
6528  TemplateArgumentListInfo ToTAInfo;
6529  if (const auto *Args = D->getTemplateArgsAsWritten()) {
6530  if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6531  return std::move(Err);
6532  }
6533 
6534  using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6535  // Create a new specialization.
6536  if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6537  auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6538  if (!ToTPListOrErr)
6539  return ToTPListOrErr.takeError();
6540 
6541  PartVarSpecDecl *ToPartial;
6542  if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6543  *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6544  VarTemplate, QualType(), nullptr,
6545  D->getStorageClass(), TemplateArgs))
6546  return ToPartial;
6547 
6548  if (Expected<PartVarSpecDecl *> ToInstOrErr =
6549  import(FromPartial->getInstantiatedFromMember()))
6550  ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6551  else
6552  return ToInstOrErr.takeError();
6553 
6554  if (FromPartial->isMemberSpecialization())
6555  ToPartial->setMemberSpecialization();
6556 
6557  D2 = ToPartial;
6558 
6559  // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6560  // to adopt template parameters.
6561  // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6562  } else { // Full specialization
6563  if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6564  *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6565  QualType(), nullptr, D->getStorageClass(),
6566  TemplateArgs))
6567  return D2;
6568  }
6569 
6570  QualType T;
6571  if (Error Err = importInto(T, D->getType()))
6572  return std::move(Err);
6573  D2->setType(T);
6574 
6575  auto TInfoOrErr = import(D->getTypeSourceInfo());
6576  if (!TInfoOrErr)
6577  return TInfoOrErr.takeError();
6578  D2->setTypeSourceInfo(*TInfoOrErr);
6579 
6580  if (D->getPointOfInstantiation().isValid()) {
6581  if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6582  D2->setPointOfInstantiation(*POIOrErr);
6583  else
6584  return POIOrErr.takeError();
6585  }
6586 
6588 
6589  if (D->getTemplateArgsAsWritten())
6590  D2->setTemplateArgsAsWritten(ToTAInfo);
6591 
6592  if (auto LocOrErr = import(D->getQualifierLoc()))
6593  D2->setQualifierInfo(*LocOrErr);
6594  else
6595  return LocOrErr.takeError();
6596 
6597  if (D->isConstexpr())
6598  D2->setConstexpr(true);
6599 
6600  D2->setAccess(D->getAccess());
6601 
6602  if (Error Err = ImportInitializer(D, D2))
6603  return std::move(Err);
6604 
6605  if (FoundSpecialization)
6606  D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6607 
6608  VarTemplate->AddSpecialization(D2, InsertPos);
6609 
6610  addDeclToContexts(D, D2);
6611 
6612  // Import the rest of the chain. I.e. import all subsequent declarations.
6613  for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6614  ExpectedDecl RedeclOrErr = import(*RedeclIt);
6615  if (!RedeclOrErr)
6616  return RedeclOrErr.takeError();
6617  }
6618 
6619  return D2;
6620 }
6621 
6624  DeclContext *DC, *LexicalDC;
6625  DeclarationName Name;
6627  NamedDecl *ToD;
6628 
6629  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6630  return std::move(Err);
6631 
6632  if (ToD)
6633  return ToD;
6634 
6635  const FunctionTemplateDecl *FoundByLookup = nullptr;
6636 
6637  // Try to find a function in our own ("to") context with the same name, same
6638  // type, and in the same context as the function we're importing.
6639  // FIXME Split this into a separate function.
6640  if (!LexicalDC->isFunctionOrMethod()) {
6642  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6643  for (auto *FoundDecl : FoundDecls) {
6644  if (!FoundDecl->isInIdentifierNamespace(IDNS))
6645  continue;
6646 
6647  if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6648  if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6649  continue;
6650  if (IsStructuralMatch(D, FoundTemplate)) {
6651  FunctionTemplateDecl *TemplateWithDef =
6652  getTemplateDefinition(FoundTemplate);
6653  if (D->isThisDeclarationADefinition() && TemplateWithDef)
6654  return Importer.MapImported(D, TemplateWithDef);
6655 
6656  FoundByLookup = FoundTemplate;
6657  break;
6658  // TODO: handle conflicting names
6659  }
6660  }
6661  }
6662  }
6663 
6664  auto ParamsOrErr = import(D->getTemplateParameters());
6665  if (!ParamsOrErr)
6666  return ParamsOrErr.takeError();
6667  TemplateParameterList *Params = *ParamsOrErr;
6668 
6669  FunctionDecl *TemplatedFD;
6670  if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6671  return std::move(Err);
6672 
6673  // At creation of the template the template parameters are "adopted"
6674  // (DeclContext is changed). After this possible change the lookup table
6675  // must be updated.
6676  // At deduction guides the DeclContext of the template parameters may be
6677  // different from what we would expect, it may be the class template, or a
6678  // probably different CXXDeductionGuideDecl. This may come from the fact that
6679  // the template parameter objects may be shared between deduction guides or
6680  // the class template, and at creation of multiple FunctionTemplateDecl
6681  // objects (for deduction guides) the same parameters are re-used. The
6682  // "adoption" happens multiple times with different parent, even recursively
6683  // for TemplateTemplateParmDecl. The same happens at import when the
6684  // FunctionTemplateDecl objects are created, but in different order.
6685  // In this way the DeclContext of these template parameters is not necessarily
6686  // the same as in the "from" context.
6687  SmallVector<DeclContext *, 2> OldParamDC;
6688  OldParamDC.reserve(Params->size());
6689  llvm::transform(*Params, std::back_inserter(OldParamDC),
6690  [](NamedDecl *ND) { return ND->getDeclContext(); });
6691 
6692  FunctionTemplateDecl *ToFunc;
6693  if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6694  Params, TemplatedFD))
6695  return ToFunc;
6696 
6697  TemplatedFD->setDescribedFunctionTemplate(ToFunc);
6698 
6699  ToFunc->setAccess(D->getAccess());
6700  ToFunc->setLexicalDeclContext(LexicalDC);
6701  addDeclToContexts(D, ToFunc);
6702 
6703  ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
6704  if (LT && !OldParamDC.empty()) {
6705  for (unsigned int I = 0; I < OldParamDC.size(); ++I)
6706  LT->updateForced(Params->getParam(I), OldParamDC[I]);
6707  }
6708 
6709  if (FoundByLookup) {
6710  auto *Recent =
6711  const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6712  if (!TemplatedFD->getPreviousDecl()) {
6713  assert(FoundByLookup->getTemplatedDecl() &&
6714  "Found decl must have its templated decl set");
6715  auto *PrevTemplated =
6716  FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6717  if (TemplatedFD != PrevTemplated)
6718  TemplatedFD->setPreviousDecl(PrevTemplated);
6719  }
6720  ToFunc->setPreviousDecl(Recent);
6721  }
6722 
6723  return ToFunc;
6724 }
6725 
6726 //----------------------------------------------------------------------------
6727 // Import Statements
6728 //----------------------------------------------------------------------------
6729 
6731  Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
6732  << S->getStmtClassName();
6733  return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
6734 }
6735 
6736 
6738  if (Importer.returnWithErrorInTest())
6739  return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
6741  for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
6742  IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
6743  // ToII is nullptr when no symbolic name is given for output operand
6744  // see ParseStmtAsm::ParseAsmOperandsOpt
6745  Names.push_back(ToII);
6746  }
6747 
6748  for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
6749  IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
6750  // ToII is nullptr when no symbolic name is given for input operand
6751  // see ParseStmtAsm::ParseAsmOperandsOpt
6752  Names.push_back(ToII);
6753  }
6754 
6756  for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
6757  if (auto ClobberOrErr = import(S->getClobberStringLiteral(I)))
6758  Clobbers.push_back(*ClobberOrErr);
6759  else
6760  return ClobberOrErr.takeError();
6761 
6762  }
6763 
6764  SmallVector<StringLiteral *, 4> Constraints;
6765  for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
6766  if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I)))
6767  Constraints.push_back(*OutputOrErr);
6768  else
6769  return OutputOrErr.takeError();
6770  }
6771 
6772  for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
6773  if (auto InputOrErr = import(S->getInputConstraintLiteral(I)))
6774  Constraints.push_back(*InputOrErr);
6775  else
6776  return InputOrErr.takeError();
6777  }
6778 
6779  SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs() +
6780  S->getNumLabels());
6781  if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
6782  return std::move(Err);
6783 
6784  if (Error Err =
6785  ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
6786  return std::move(Err);
6787 
6788  if (Error Err = ImportArrayChecked(
6789  S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs()))
6790  return std::move(Err);
6791 
6792  ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
6793  if (!AsmLocOrErr)
6794  return AsmLocOrErr.takeError();
6795  auto AsmStrOrErr = import(S->getAsmString());
6796  if (!AsmStrOrErr)
6797  return AsmStrOrErr.takeError();
6798  ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
6799  if (!RParenLocOrErr)
6800  return RParenLocOrErr.takeError();
6801 
6802  return new (Importer.getToContext()) GCCAsmStmt(
6803  Importer.getToContext(),
6804  *AsmLocOrErr,
6805  S->isSimple(),
6806  S->isVolatile(),
6807  S->getNumOutputs(),
6808  S->getNumInputs(),
6809  Names.data(),
6810  Constraints.data(),
6811  Exprs.data(),
6812  *AsmStrOrErr,
6813  S->getNumClobbers(),
6814  Clobbers.data(),
6815  S->getNumLabels(),
6816  *RParenLocOrErr);
6817 }
6818 
6820 
6821  Error Err = Error::success();
6822  auto ToDG = importChecked(Err, S->getDeclGroup());
6823  auto ToBeginLoc = importChecked(Err, S->getBeginLoc());
6824  auto ToEndLoc = importChecked(Err, S->getEndLoc());
6825  if (Err)
6826  return std::move(Err);
6827  return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
6828 }
6829 
6831  ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
6832  if (!ToSemiLocOrErr)
6833  return ToSemiLocOrErr.takeError();
6834  return new (Importer.getToContext()) NullStmt(
6835  *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
6836 }
6837 
6839  SmallVector<Stmt *, 8> ToStmts(S->size());
6840 
6841  if (Error Err = ImportContainerChecked(S->body(), ToStmts))
6842  return std::move(Err);
6843 
6844  ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
6845  if (!ToLBracLocOrErr)
6846  return ToLBracLocOrErr.takeError();
6847 
6848  ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
6849  if (!ToRBracLocOrErr)
6850  return ToRBracLocOrErr.takeError();
6851 
6852  FPOptionsOverride FPO =
6853  S->hasStoredFPFeatures() ? S->getStoredFPFeatures() : FPOptionsOverride();
6854  return CompoundStmt::Create(Importer.getToContext(), ToStmts, FPO,
6855  *ToLBracLocOrErr, *ToRBracLocOrErr);
6856 }
6857 
6859 
6860  Error Err = Error::success();
6861  auto ToLHS = importChecked(Err, S->getLHS());
6862  auto ToRHS = importChecked(Err, S->getRHS());
6863  auto ToSubStmt = importChecked(Err, S->getSubStmt());
6864  auto ToCaseLoc = importChecked(Err, S->getCaseLoc());
6865  auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc());
6866  auto ToColonLoc = importChecked(Err, S->getColonLoc());
6867  if (Err)
6868  return std::move(Err);
6869 
6870  auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
6871  ToCaseLoc, ToEllipsisLoc, ToColonLoc);
6872  ToStmt->setSubStmt(ToSubStmt);
6873 
6874  return ToStmt;
6875 }
6876 
6878 
6879  Error Err = Error::success();
6880  auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc());
6881  auto ToColonLoc = importChecked(Err, S->getColonLoc());
6882  auto ToSubStmt = importChecked(Err, S->getSubStmt());
6883  if (Err)
6884  return std::move(Err);
6885 
6886  return new (Importer.getToContext()) DefaultStmt(
6887  ToDefaultLoc, ToColonLoc, ToSubStmt);
6888 }
6889 
6891 
6892  Error Err = Error::success();
6893  auto ToIdentLoc = importChecked(Err, S->getIdentLoc());
6894  auto ToLabelDecl = importChecked(Err, S->getDecl());
6895  auto ToSubStmt = importChecked(Err, S->getSubStmt());
6896  if (Err)
6897  return std::move(Err);
6898 
6899  return new (Importer.getToContext()) LabelStmt(
6900  ToIdentLoc, ToLabelDecl, ToSubStmt);
6901 }
6902 
6904  ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
6905  if (!ToAttrLocOrErr)
6906  return ToAttrLocOrErr.takeError();
6907  ArrayRef<const Attr*> FromAttrs(S->getAttrs());
6908  SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
6909  if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
6910  return std::move(Err);
6911  ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
6912  if (!ToSubStmtOrErr)
6913  return ToSubStmtOrErr.takeError();
6914 
6915  return AttributedStmt::Create(
6916  Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
6917 }
6918 
6920 
6921  Error Err = Error::success();
6922  auto ToIfLoc = importChecked(Err, S->getIfLoc());
6923  auto ToInit = importChecked(Err, S->getInit());
6924  auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
6925  auto ToCond = importChecked(Err, S->getCond());
6926  auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
6927  auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
6928  auto ToThen = importChecked(Err, S->getThen());
6929  auto ToElseLoc = importChecked(Err, S->getElseLoc());
6930  auto ToElse = importChecked(Err, S->getElse());
6931  if (Err)
6932  return std::move(Err);
6933 
6934  return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(),
6935  ToInit, ToConditionVariable, ToCond, ToLParenLoc,
6936  ToRParenLoc, ToThen, ToElseLoc, ToElse);
6937 }
6938 
6940 
6941  Error Err = Error::success();
6942  auto ToInit = importChecked(Err, S->getInit());
6943  auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
6944  auto ToCond = importChecked(Err, S->getCond());
6945  auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
6946  auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
6947  auto ToBody = importChecked(Err, S->getBody());
6948  auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
6949  if (Err)
6950  return std::move(Err);
6951 
6952  auto *ToStmt =
6953  SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
6954  ToCond, ToLParenLoc, ToRParenLoc);
6955  ToStmt->setBody(ToBody);
6956  ToStmt->setSwitchLoc(ToSwitchLoc);
6957 
6958  // Now we have to re-chain the cases.
6959  SwitchCase *LastChainedSwitchCase = nullptr;
6960  for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
6961  SC = SC->getNextSwitchCase()) {
6962  Expected<SwitchCase *> ToSCOrErr = import(SC);
6963  if (!ToSCOrErr)
6964  return ToSCOrErr.takeError();
6965  if (LastChainedSwitchCase)
6966  LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
6967  else
6968  ToStmt->setSwitchCaseList(*ToSCOrErr);
6969  LastChainedSwitchCase = *ToSCOrErr;
6970  }
6971 
6972  return ToStmt;
6973 }
6974 
6976 
6977  Error Err = Error::success();
6978  auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
6979  auto ToCond = importChecked(Err, S->getCond());
6980  auto ToBody = importChecked(Err, S->getBody());
6981  auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
6982  auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
6983  auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
6984  if (Err)
6985  return std::move(Err);
6986 
6987  return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
6988  ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc);
6989 }
6990 
6992 
6993  Error Err = Error::success();
6994  auto ToBody = importChecked(Err, S->getBody());
6995  auto ToCond = importChecked(Err, S->getCond());
6996  auto ToDoLoc = importChecked(Err, S->getDoLoc());
6997  auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
6998  auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
6999  if (Err)
7000  return std::move(Err);
7001 
7002  return new (Importer.getToContext()) DoStmt(
7003  ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
7004 }
7005 
7007 
7008  Error Err = Error::success();
7009  auto ToInit = importChecked(Err, S->getInit());
7010  auto ToCond = importChecked(Err, S->getCond());
7011  auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7012  auto ToInc = importChecked(Err, S->getInc());
7013  auto ToBody = importChecked(Err, S->getBody());
7014  auto ToForLoc = importChecked(Err, S->getForLoc());
7015  auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7016  auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7017  if (Err)
7018  return std::move(Err);
7019 
7020  return new (Importer.getToContext()) ForStmt(
7021  Importer.getToContext(),
7022  ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
7023  ToRParenLoc);
7024 }
7025 
7027 
7028  Error Err = Error::success();
7029  auto ToLabel = importChecked(Err, S->getLabel());
7030  auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7031  auto ToLabelLoc = importChecked(Err, S->getLabelLoc());
7032  if (Err)
7033  return std::move(Err);
7034 
7035  return new (Importer.getToContext()) GotoStmt(
7036  ToLabel, ToGotoLoc, ToLabelLoc);
7037 }
7038 
7040 
7041  Error Err = Error::success();
7042  auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7043  auto ToStarLoc = importChecked(Err, S->getStarLoc());
7044  auto ToTarget = importChecked(Err, S->getTarget());
7045  if (Err)
7046  return std::move(Err);
7047 
7048  return new (Importer.getToContext()) IndirectGotoStmt(
7049  ToGotoLoc, ToStarLoc, ToTarget);
7050 }
7051 
7053  ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc());
7054  if (!ToContinueLocOrErr)
7055  return ToContinueLocOrErr.takeError();
7056  return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr);
7057 }
7058 
7060  auto ToBreakLocOrErr = import(S->getBreakLoc());
7061  if (!ToBreakLocOrErr)
7062  return ToBreakLocOrErr.takeError();
7063  return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr);
7064 }
7065 
7067 
7068  Error Err = Error::success();
7069  auto ToReturnLoc = importChecked(Err, S->getReturnLoc());
7070  auto ToRetValue = importChecked(Err, S->getRetValue());
7071  auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate());
7072  if (Err)
7073  return std::move(Err);
7074 
7075  return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
7076  ToNRVOCandidate);
7077 }
7078 
7080 
7081  Error Err = Error::success();
7082  auto ToCatchLoc = importChecked(Err, S->getCatchLoc());
7083  auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl());
7084  auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock());
7085  if (Err)
7086  return std::move(Err);
7087 
7088  return new (Importer.getToContext()) CXXCatchStmt (
7089  ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
7090 }
7091 
7093  ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
7094  if (!ToTryLocOrErr)
7095  return ToTryLocOrErr.takeError();
7096 
7097  ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
7098  if (!ToTryBlockOrErr)
7099  return ToTryBlockOrErr.takeError();
7100 
7101  SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
7102  for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
7103  CXXCatchStmt *FromHandler = S->getHandler(HI);
7104  if (auto ToHandlerOrErr = import(FromHandler))
7105  ToHandlers[HI] = *ToHandlerOrErr;
7106  else
7107  return ToHandlerOrErr.takeError();
7108  }
7109 
7110  return CXXTryStmt::Create(Importer.getToContext(), *ToTryLocOrErr,
7111  cast<CompoundStmt>(*ToTryBlockOrErr), ToHandlers);
7112 }
7113 
7115 
7116  Error Err = Error::success();
7117  auto ToInit = importChecked(Err, S->getInit());
7118  auto ToRangeStmt = importChecked(Err, S->getRangeStmt());
7119  auto ToBeginStmt = importChecked(Err, S->getBeginStmt());
7120  auto ToEndStmt = importChecked(Err, S->getEndStmt());
7121  auto ToCond = importChecked(Err, S->getCond());
7122  auto ToInc = importChecked(Err, S->getInc());
7123  auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt());
7124  auto ToBody = importChecked(Err, S->getBody());
7125  auto ToForLoc = importChecked(Err, S->getForLoc());
7126  auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc());
7127  auto ToColonLoc = importChecked(Err, S->getColonLoc());
7128  auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7129  if (Err)
7130  return std::move(Err);
7131 
7132  return new (Importer.getToContext()) CXXForRangeStmt(
7133  ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
7134  ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
7135 }
7136 
7139  Error Err = Error::success();
7140  auto ToElement = importChecked(Err, S->getElement());
7141  auto ToCollection = importChecked(Err, S->getCollection());
7142  auto ToBody = importChecked(Err, S->getBody());
7143  auto ToForLoc = importChecked(Err, S->getForLoc());
7144  auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7145  if (Err)
7146  return std::move(Err);
7147 
7148  return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
7149  ToCollection,
7150  ToBody,
7151  ToForLoc,
7152  ToRParenLoc);
7153 }
7154 
7156 
7157  Error Err = Error::success();
7158  auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc());
7159  auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7160  auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl());
7161  auto ToCatchBody = importChecked(Err, S->getCatchBody());
7162  if (Err)
7163  return std::move(Err);
7164 
7165  return new (Importer.getToContext()) ObjCAtCatchStmt (
7166  ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
7167 }
7168 
7170  ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
7171  if (!ToAtFinallyLocOrErr)
7172  return ToAtFinallyLocOrErr.takeError();
7173  ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
7174  if (!ToAtFinallyStmtOrErr)
7175  return ToAtFinallyStmtOrErr.takeError();
7176  return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
7177  *ToAtFinallyStmtOrErr);
7178 }
7179 
7181 
7182  Error Err = Error::success();
7183  auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc());
7184  auto ToTryBody = importChecked(Err, S->getTryBody());
7185  auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt());
7186  if (Err)
7187  return std::move(Err);
7188 
7189  SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
7190  for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
7191  ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
7192  if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
7193  ToCatchStmts[CI] = *ToCatchStmtOrErr;
7194  else
7195  return ToCatchStmtOrErr.takeError();
7196  }
7197 
7198  return ObjCAtTryStmt::Create(Importer.getToContext(),
7199  ToAtTryLoc, ToTryBody,
7200  ToCatchStmts.begin(), ToCatchStmts.size(),
7201  ToFinallyStmt);
7202 }
7203 
7206 
7207  Error Err = Error::success();
7208  auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc());
7209  auto ToSynchExpr = importChecked(Err, S->getSynchExpr());
7210  auto ToSynchBody = importChecked(Err, S->getSynchBody());
7211  if (Err)
7212  return std::move(Err);
7213 
7214  return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
7215  ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
7216 }
7217 
7219  ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
7220  if (!ToThrowLocOrErr)
7221  return ToThrowLocOrErr.takeError();
7222  ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
7223  if (!ToThrowExprOrErr)
7224  return ToThrowExprOrErr.takeError();
7225  return new (Importer.getToContext()) ObjCAtThrowStmt(
7226  *ToThrowLocOrErr, *ToThrowExprOrErr);
7227 }
7228 
7231  ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
7232  if (!ToAtLocOrErr)
7233  return ToAtLocOrErr.takeError();
7234  ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7235  if (!ToSubStmtOrErr)
7236  return ToSubStmtOrErr.takeError();
7237  return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
7238  *ToSubStmtOrErr);
7239 }
7240 
7241 //----------------------------------------------------------------------------
7242 // Import Expressions
7243 //----------------------------------------------------------------------------
7245  Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
7246  << E->getStmtClassName();
7247  return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7248 }
7249 
7251  Error Err = Error::success();
7252  auto ToType = importChecked(Err, E->getType());
7253  auto BLoc = importChecked(Err, E->getBeginLoc());
7254  auto RParenLoc = importChecked(Err, E->getEndLoc());
7255  if (Err)
7256  return std::move(Err);
7257  auto ParentContextOrErr = Importer.ImportContext(E->getParentContext());
7258  if (!ParentContextOrErr)
7259  return ParentContextOrErr.takeError();
7260 
7261  return new (Importer.getToContext())
7262  SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc,
7263  RParenLoc, *ParentContextOrErr);
7264 }
7265 
7267 
7268  Error Err = Error::success();
7269  auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7270  auto ToSubExpr = importChecked(Err, E->getSubExpr());
7271  auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo());
7272  auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7273  auto ToType = importChecked(Err, E->getType());
7274  if (Err)
7275  return std::move(Err);
7276 
7277  return new (Importer.getToContext()) VAArgExpr(
7278  ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
7279  E->isMicrosoftABI());
7280 }
7281 
7283 
7284  Error Err = Error::success();
7285  auto ToCond = importChecked(Err, E->getCond());
7286  auto ToLHS = importChecked(Err, E->getLHS());
7287  auto ToRHS = importChecked(Err, E->getRHS());
7288  auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7289  auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7290  auto ToType = importChecked(Err, E->getType());
7291  if (Err)
7292  return std::move(Err);
7293 
7294  ExprValueKind VK = E->getValueKind();
7295  ExprObjectKind OK = E->getObjectKind();
7296 
7297  // The value of CondIsTrue only matters if the value is not
7298  // condition-dependent.
7299  bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
7300 
7301  return new (Importer.getToContext())
7302  ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
7303  ToRParenLoc, CondIsTrue);
7304 }
7305 
7307  Error Err = Error::success();
7308  auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
7309  auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7310  auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7311  auto ToType = importChecked(Err, E->getType());
7312  auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
7313  if (Err)
7314  return std::move(Err);
7315 
7316  return new (Importer.getToContext())
7317  ConvertVectorExpr(ToSrcExpr, ToTSI, ToType, E->getValueKind(),
7318  E->getObjectKind(), ToBuiltinLoc, ToRParenLoc);
7319 }
7320 
7322  Error Err = Error::success();
7323  auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7324  auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7325  auto ToType = importChecked(Err, E->getType());
7326  const unsigned NumSubExprs = E->getNumSubExprs();
7327 
7328  llvm::SmallVector<Expr *, 8> ToSubExprs;
7329  llvm::ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
7330  ToSubExprs.resize(NumSubExprs);
7331 
7332  if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
7333  return std::move(Err);
7334 
7335  return new (Importer.getToContext()) ShuffleVectorExpr(
7336  Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
7337 }
7338 
7340  ExpectedType TypeOrErr = import(E->getType());
7341  if (!TypeOrErr)
7342  return TypeOrErr.takeError();
7343 
7344  ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
7345  if (!BeginLocOrErr)
7346  return BeginLocOrErr.takeError();
7347 
7348  return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
7349 }
7350 
7353  Error Err = Error::success();
7354  auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
7355  Expr *ToControllingExpr = nullptr;
7356  TypeSourceInfo *ToControllingType = nullptr;
7357  if (E->isExprPredicate())
7358  ToControllingExpr = importChecked(Err, E->getControllingExpr());
7359  else
7360  ToControllingType = importChecked(Err, E->getControllingType());
7361  assert((ToControllingExpr || ToControllingType) &&
7362  "Either the controlling expr or type must be nonnull");
7363  auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
7364  auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7365  if (Err)
7366  return std::move(Err);
7367 
7369  SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
7370  if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
7371  return std::move(Err);
7372 
7373  ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
7374  SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
7375  if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
7376  return std::move(Err);
7377 
7378  const ASTContext &ToCtx = Importer.getToContext();
7379  if (E->isResultDependent()) {
7380  if (ToControllingExpr) {
7382  ToCtx, ToGenericLoc, ToControllingExpr, llvm::ArrayRef(ToAssocTypes),
7383  llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7385  }
7387  ToCtx, ToGenericLoc, ToControllingType, llvm::ArrayRef(ToAssocTypes),
7388  llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7390  }
7391 
7392  if (ToControllingExpr) {
7394  ToCtx, ToGenericLoc, ToControllingExpr, llvm::ArrayRef(ToAssocTypes),
7395  llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7397  }
7399  ToCtx, ToGenericLoc, ToControllingType, llvm::ArrayRef(ToAssocTypes),
7400  llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7402 }
7403 
7405 
7406  Error Err = Error::success();
7407  auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7408  auto ToType = importChecked(Err, E->getType());
7409  auto ToFunctionName = importChecked(Err, E->getFunctionName());
7410  if (Err)
7411  return std::move(Err);
7412 
7413  return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
7414  E->getIdentKind(), E->isTransparent(),
7415  ToFunctionName);
7416 }
7417 
7419 
7420  Error Err = Error::success();
7421  auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
7422  auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
7423  auto ToDecl = importChecked(Err, E->getDecl());
7424  auto ToLocation = importChecked(Err, E->getLocation());
7425  auto ToType = importChecked(Err, E->getType());
7426  if (Err)
7427  return std::move(Err);
7428 
7429  NamedDecl *ToFoundD = nullptr;
7430  if (E->getDecl() != E->getFoundDecl()) {
7431  auto FoundDOrErr = import(E->getFoundDecl());
7432  if (!FoundDOrErr)
7433  return FoundDOrErr.takeError();
7434  ToFoundD = *FoundDOrErr;
7435  }
7436 
7437  TemplateArgumentListInfo ToTAInfo;
7438  TemplateArgumentListInfo *ToResInfo = nullptr;
7439  if (E->hasExplicitTemplateArgs()) {
7440  if (Error Err =
7442  E->template_arguments(), ToTAInfo))
7443  return std::move(Err);
7444  ToResInfo = &ToTAInfo;
7445  }
7446 
7447  auto *ToE = DeclRefExpr::Create(
7448  Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
7449  E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
7450  E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse());
7451  if (E->hadMultipleCandidates())
7452  ToE->setHadMultipleCandidates(true);
7453  ToE->setIsImmediateEscalating(E->isImmediateEscalating());
7454  return ToE;
7455 }
7456 
7458  ExpectedType TypeOrErr = import(E->getType());
7459  if (!TypeOrErr)
7460  return TypeOrErr.takeError();
7461 
7462  return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
7463 }
7464 
7466  ExpectedExpr ToInitOrErr = import(E->getInit());
7467  if (!ToInitOrErr)
7468  return ToInitOrErr.takeError();
7469 
7470  ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
7471  if (!ToEqualOrColonLocOrErr)
7472  return ToEqualOrColonLocOrErr.takeError();
7473 
7474  SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
7475  // List elements from the second, the first is Init itself
7476  for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
7477  if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
7478  ToIndexExprs[I - 1] = *ToArgOrErr;
7479  else
7480  return ToArgOrErr.takeError();
7481  }
7482 
7483  SmallVector<Designator, 4> ToDesignators(E->size());
7484  if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
7485  return std::move(Err);
7486 
7488  Importer.getToContext(), ToDesignators,
7489  ToIndexExprs, *ToEqualOrColonLocOrErr,
7490  E->usesGNUSyntax(), *ToInitOrErr);
7491 }
7492 
7495  ExpectedType ToTypeOrErr = import(E->getType());
7496  if (!ToTypeOrErr)
7497  return ToTypeOrErr.takeError();
7498 
7499  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7500  if (!ToLocationOrErr)
7501  return ToLocationOrErr.takeError();
7502 
7503  return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
7504  *ToTypeOrErr, *ToLocationOrErr);
7505 }
7506 
7508  ExpectedType ToTypeOrErr = import(E->getType());
7509  if (!ToTypeOrErr)
7510  return ToTypeOrErr.takeError();
7511 
7512  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7513  if (!ToLocationOrErr)
7514  return ToLocationOrErr.takeError();
7515 
7516  return IntegerLiteral::Create(
7517  Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7518 }
7519 
7520 
7522  ExpectedType ToTypeOrErr = import(E->getType());
7523  if (!ToTypeOrErr)
7524  return ToTypeOrErr.takeError();
7525 
7526  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7527  if (!ToLocationOrErr)
7528  return ToLocationOrErr.takeError();
7529 
7530  return FloatingLiteral::Create(
7531  Importer.getToContext(), E->getValue(), E->isExact(),
7532  *ToTypeOrErr, *ToLocationOrErr);
7533 }
7534 
7536  auto ToTypeOrErr = import(E->getType());
7537  if (!ToTypeOrErr)
7538  return ToTypeOrErr.takeError();
7539 
7540  ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7541  if (!ToSubExprOrErr)
7542  return ToSubExprOrErr.takeError();
7543 
7544  return new (Importer.getToContext()) ImaginaryLiteral(
7545  *ToSubExprOrErr, *ToTypeOrErr);
7546 }
7547 
7549  auto ToTypeOrErr = import(E->getType());
7550  if (!ToTypeOrErr)
7551  return ToTypeOrErr.takeError();
7552 
7553  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7554  if (!ToLocationOrErr)
7555  return ToLocationOrErr.takeError();
7556 
7557  return new (Importer.getToContext()) FixedPointLiteral(
7558  Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
7559  Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
7560 }
7561 
7563  ExpectedType ToTypeOrErr = import(E->getType());
7564  if (!ToTypeOrErr)
7565  return ToTypeOrErr.takeError();
7566 
7567  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7568  if (!ToLocationOrErr)
7569  return ToLocationOrErr.takeError();
7570 
7571  return new (Importer.getToContext()) CharacterLiteral(
7572  E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
7573 }
7574 
7576  ExpectedType ToTypeOrErr = import(E->getType());
7577  if (!ToTypeOrErr)
7578  return ToTypeOrErr.takeError();
7579 
7581  if (Error Err = ImportArrayChecked(
7582  E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
7583  return std::move(Err);
7584 
7585  return StringLiteral::Create(
7586  Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(),
7587  *ToTypeOrErr, ToLocations.data(), ToLocations.size());
7588 }
7589 
7591 
7592  Error Err = Error::success();
7593  auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7594  auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7595  auto ToType = importChecked(Err, E->getType());
7596  auto ToInitializer = importChecked(Err, E->getInitializer());
7597  if (Err)
7598  return std::move(Err);
7599 
7600  return new (Importer.getToContext()) CompoundLiteralExpr(
7601  ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
7602  ToInitializer, E->isFileScope());
7603 }
7604 
7606 
7607  Error Err = Error::success();
7608  auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7609  auto ToType = importChecked(Err, E->getType());
7610  auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7611  if (Err)
7612  return std::move(Err);
7613 
7614  SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs());
7615  if (Error Err = ImportArrayChecked(
7616  E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
7617  ToExprs.begin()))
7618  return std::move(Err);
7619 
7620  return new (Importer.getToContext()) AtomicExpr(
7621 
7622  ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
7623 }
7624 
7626  Error Err = Error::success();
7627  auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc());
7628  auto ToLabelLoc = importChecked(Err, E->getLabelLoc());
7629  auto ToLabel = importChecked(Err, E->getLabel());
7630  auto ToType = importChecked(Err, E->getType());
7631  if (Err)
7632  return std::move(Err);
7633 
7634  return new (Importer.getToContext()) AddrLabelExpr(
7635  ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
7636 }
7638  Error Err = Error::success();
7639  auto ToSubExpr = importChecked(Err, E->getSubExpr());
7640  auto ToResult = importChecked(Err, E->getAPValueResult());
7641  if (Err)
7642  return std::move(Err);
7643 
7644  return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult);
7645 }
7647  Error Err = Error::success();
7648  auto ToLParen = importChecked(Err, E->getLParen());
7649  auto ToRParen = importChecked(Err, E->getRParen());
7650  auto ToSubExpr = importChecked(Err, E->getSubExpr());
7651  if (Err)
7652  return std::move(Err);
7653 
7654  return new (Importer.getToContext())
7655  ParenExpr(ToLParen, ToRParen, ToSubExpr);
7656 }
7657 
7659  SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
7660  if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
7661  return std::move(Err);
7662 
7663  ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
7664  if (!ToLParenLocOrErr)
7665  return ToLParenLocOrErr.takeError();
7666 
7667  ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
7668  if (!ToRParenLocOrErr)
7669  return ToRParenLocOrErr.takeError();
7670 
7671  return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
7672  ToExprs, *ToRParenLocOrErr);
7673 }
7674 
7676  Error Err = Error::success();
7677  auto ToSubStmt = importChecked(Err, E->getSubStmt());
7678  auto ToType = importChecked(Err, E->getType());
7679  auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7680  auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7681  if (Err)
7682  return std::move(Err);
7683 
7684  return new (Importer.getToContext())
7685  StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
7686  E->getTemplateDepth());
7687 }
7688 
7690  Error Err = Error::success();
7691  auto ToSubExpr = importChecked(Err, E->getSubExpr());
7692  auto ToType = importChecked(Err, E->getType());
7693  auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7694  if (Err)
7695  return std::move(Err);
7696 
7697  auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
7698  E->hasStoredFPFeatures());
7699  UO->setType(ToType);
7700  UO->setSubExpr(ToSubExpr);
7701  UO->setOpcode(E->getOpcode());
7702  UO->setOperatorLoc(ToOperatorLoc);
7703  UO->setCanOverflow(E->canOverflow());
7704  if (E->hasStoredFPFeatures())
7705  UO->setStoredFPFeatures(E->getStoredFPFeatures());
7706 
7707  return UO;
7708 }
7709 
7711 
7713  Error Err = Error::success();
7714  auto ToType = importChecked(Err, E->getType());
7715  auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7716  auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7717  if (Err)
7718  return std::move(Err);
7719 
7720  if (E->isArgumentType()) {
7721  Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
7722  import(E->getArgumentTypeInfo());
7723  if (!ToArgumentTypeInfoOrErr)
7724  return ToArgumentTypeInfoOrErr.takeError();
7725 
7726  return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
7727  E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
7728  ToRParenLoc);
7729  }
7730 
7731  ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
7732  if (!ToArgumentExprOrErr)
7733  return ToArgumentExprOrErr.takeError();
7734 
7735  return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
7736  E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
7737 }
7738 
7740  Error Err = Error::success();
7741  auto ToLHS = importChecked(Err, E->getLHS());
7742  auto ToRHS = importChecked(Err, E->getRHS());
7743  auto ToType = importChecked(Err, E->getType());
7744  auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7745  if (Err)
7746  return std::move(Err);
7747 
7748  return BinaryOperator::Create(
7749  Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
7750  E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
7751  E->getFPFeatures());
7752 }
7753 
7755  Error Err = Error::success();
7756  auto ToCond = importChecked(Err, E->getCond());
7757  auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
7758  auto ToLHS = importChecked(Err, E->getLHS());
7759  auto ToColonLoc = importChecked(Err, E->getColonLoc());
7760  auto ToRHS = importChecked(Err, E->getRHS());
7761  auto ToType = importChecked(Err, E->getType());
7762  if (Err)
7763  return std::move(Err);
7764 
7765  return new (Importer.getToContext()) ConditionalOperator(
7766  ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
7767  E->getValueKind(), E->getObjectKind());
7768 }
7769 
7772  Error Err = Error::success();
7773  auto ToCommon = importChecked(Err, E->getCommon());
7774  auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue());
7775  auto ToCond = importChecked(Err, E->getCond());
7776  auto ToTrueExpr = importChecked(Err, E->getTrueExpr());
7777  auto ToFalseExpr = importChecked(Err, E->getFalseExpr());
7778  auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
7779  auto ToColonLoc = importChecked(Err, E->getColonLoc());
7780  auto ToType = importChecked(Err, E->getType());
7781  if (Err)
7782  return std::move(Err);
7783 
7784  return new (Importer.getToContext()) BinaryConditionalOperator(
7785  ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
7786  ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
7787  E->getObjectKind());
7788 }
7789 
7792  Error Err = Error::success();
7793  auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
7794  if (Err)
7795  return std::move(Err);
7796 
7797  return new (Importer.getToContext())
7798  CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
7799 }
7800 
7802  Error Err = Error::success();
7803  auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7804  auto ToQueriedTypeSourceInfo =
7806  auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression());
7807  auto ToEndLoc = importChecked(Err, E->getEndLoc());
7808  auto ToType = importChecked(Err, E->getType());
7809  if (Err)
7810  return std::move(Err);
7811 
7812  return new (Importer.getToContext()) ArrayTypeTraitExpr(
7813  ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
7814  ToDimensionExpression, ToEndLoc, ToType);
7815 }
7816 
7818  Error Err = Error::success();
7819  auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7820  auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression());
7821  auto ToEndLoc = importChecked(Err, E->getEndLoc());
7822  auto ToType = importChecked(Err, E->getType());
7823  if (Err)
7824  return std::move(Err);
7825 
7826  return new (Importer.getToContext()) ExpressionTraitExpr(
7827  ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
7828  ToEndLoc, ToType);
7829 }
7830 
7832  Error Err = Error::success();
7833  auto ToLocation = importChecked(Err, E->getLocation());
7834  auto ToType = importChecked(Err, E->getType());
7835  auto ToSourceExpr = importChecked(Err, E->getSourceExpr());
7836  if (Err)
7837  return std::move(Err);
7838 
7839  return new (Importer.getToContext()) OpaqueValueExpr(
7840  ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
7841 }
7842 
7844  Error Err = Error::success();
7845  auto ToLHS = importChecked(Err, E->getLHS());
7846  auto ToRHS = importChecked(Err, E->getRHS());
7847  auto ToType = importChecked(Err, E->getType());
7848  auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc());
7849  if (Err)
7850  return std::move(Err);
7851 
7852  return new (Importer.getToContext()) ArraySubscriptExpr(
7853  ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
7854  ToRBracketLoc);
7855 }
7856 
7859  Error Err = Error::success();
7860  auto ToLHS = importChecked(Err, E->getLHS());
7861  auto ToRHS = importChecked(Err, E->getRHS());
7862  auto ToType = importChecked(Err, E->getType());
7863  auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType());
7864  auto ToComputationResultType =
7866  auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7867  if (Err)
7868  return std::move(Err);
7869 
7871  Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
7872  E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
7873  E->getFPFeatures(),
7874  ToComputationLHSType, ToComputationResultType);
7875 }
7876 
7879  CXXCastPath Path;
7880  for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
7881  if (auto SpecOrErr = import(*I))
7882  Path.push_back(*SpecOrErr);
7883  else
7884  return SpecOrErr.takeError();
7885  }
7886  return Path;
7887 }
7888 
7890  ExpectedType ToTypeOrErr = import(E->getType());
7891  if (!ToTypeOrErr)
7892  return ToTypeOrErr.takeError();
7893 
7894  ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7895  if (!ToSubExprOrErr)
7896  return ToSubExprOrErr.takeError();
7897 
7898  Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
7899  if (!ToBasePathOrErr)
7900  return ToBasePathOrErr.takeError();
7901 
7902  return ImplicitCastExpr::Create(
7903  Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
7904  &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures());
7905 }
7906 
7908  Error Err = Error::success();
7909  auto ToType = importChecked(Err, E->getType());
7910  auto ToSubExpr = importChecked(Err, E->getSubExpr());
7911  auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
7912  if (Err)
7913  return std::move(Err);
7914 
7915  Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
7916  if (!ToBasePathOrErr)
7917  return ToBasePathOrErr.takeError();
7918  CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
7919 
7920  switch (E->getStmtClass()) {
7921  case Stmt::CStyleCastExprClass: {
7922  auto *CCE = cast<CStyleCastExpr>(E);
7923  ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
7924  if (!ToLParenLocOrErr)
7925  return ToLParenLocOrErr.takeError();
7926  ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
7927  if (!ToRParenLocOrErr)
7928  return ToRParenLocOrErr.takeError();
7929  return CStyleCastExpr::Create(
7930  Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
7931  ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten,
7932  *ToLParenLocOrErr, *ToRParenLocOrErr);
7933  }
7934 
7935  case Stmt::CXXFunctionalCastExprClass: {
7936  auto *FCE = cast<CXXFunctionalCastExpr>(E);
7937  ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
7938  if (!ToLParenLocOrErr)
7939  return ToLParenLocOrErr.takeError();
7940  ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
7941  if (!ToRParenLocOrErr)
7942  return ToRParenLocOrErr.takeError();
7944  Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
7945  E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(),
7946  *ToLParenLocOrErr, *ToRParenLocOrErr);
7947  }
7948 
7949  case Stmt::ObjCBridgedCastExprClass: {
7950  auto *OCE = cast<ObjCBridgedCastExpr>(E);
7951  ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
7952  if (!ToLParenLocOrErr)
7953  return ToLParenLocOrErr.takeError();
7954  ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
7955  if (!ToBridgeKeywordLocOrErr)
7956  return ToBridgeKeywordLocOrErr.takeError();
7957  return new (Importer.getToContext()) ObjCBridgedCastExpr(
7958  *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
7959  *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
7960  }
7961  case Stmt::BuiltinBitCastExprClass: {
7962  auto *BBC = cast<BuiltinBitCastExpr>(E);
7963  ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
7964  if (!ToKWLocOrErr)
7965  return ToKWLocOrErr.takeError();
7966  ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
7967  if (!ToRParenLocOrErr)
7968  return ToRParenLocOrErr.takeError();
7969  return new (Importer.getToContext()) BuiltinBitCastExpr(
7970  ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
7971  ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
7972  }
7973  default:
7974  llvm_unreachable("Cast expression of unsupported type!");
7975  return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7976  }
7977 }
7978 
7981  for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
7982  const OffsetOfNode &FromNode = E->getComponent(I);
7983 
7984  SourceLocation ToBeginLoc, ToEndLoc;
7985 
7986  if (FromNode.getKind() != OffsetOfNode::Base) {
7987  Error Err = Error::success();
7988  ToBeginLoc = importChecked(Err, FromNode.getBeginLoc());
7989  ToEndLoc = importChecked(Err, FromNode.getEndLoc());
7990  if (Err)
7991  return std::move(Err);
7992  }
7993 
7994  switch (FromNode.getKind()) {
7995  case OffsetOfNode::Array:
7996  ToNodes.push_back(
7997  OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
7998  break;
7999  case OffsetOfNode::Base: {
8000  auto ToBSOrErr = import(FromNode.getBase());
8001  if (!ToBSOrErr)
8002  return ToBSOrErr.takeError();
8003  ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
8004  break;
8005  }
8006  case OffsetOfNode::Field: {
8007  auto ToFieldOrErr = import(FromNode.getField());
8008  if (!ToFieldOrErr)
8009  return ToFieldOrErr.takeError();
8010  ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
8011  break;
8012  }
8013  case OffsetOfNode::Identifier: {
8014  IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
8015  ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
8016  break;
8017  }
8018  }
8019  }
8020 
8022  for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
8023  ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
8024  if (!ToIndexExprOrErr)
8025  return ToIndexExprOrErr.takeError();
8026  ToExprs[I] = *ToIndexExprOrErr;
8027  }
8028 
8029  Error Err = Error::success();
8030  auto ToType = importChecked(Err, E->getType());
8031  auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8032  auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8033  auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8034  if (Err)
8035  return std::move(Err);
8036 
8037  return OffsetOfExpr::Create(
8038  Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
8039  ToExprs, ToRParenLoc);
8040 }
8041 
8043  Error Err = Error::success();
8044  auto ToType = importChecked(Err, E->getType());
8045  auto ToOperand = importChecked(Err, E->getOperand());
8046  auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8047  auto ToEndLoc = importChecked(Err, E->getEndLoc());
8048  if (Err)
8049  return std::move(Err);
8050 
8051  CanThrowResult ToCanThrow;
8052  if (E->isValueDependent())
8053  ToCanThrow = CT_Dependent;
8054  else
8055  ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
8056 
8057  return new (Importer.getToContext()) CXXNoexceptExpr(
8058  ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
8059 }
8060 
8062  Error Err = Error::success();
8063  auto ToSubExpr = importChecked(Err, E->getSubExpr());
8064  auto ToType = importChecked(Err, E->getType());
8065  auto ToThrowLoc = importChecked(Err, E->getThrowLoc());
8066  if (Err)
8067  return std::move(Err);
8068 
8069  return new (Importer.getToContext()) CXXThrowExpr(
8070  ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
8071 }
8072 
8074  ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
8075  if (!ToUsedLocOrErr)
8076  return ToUsedLocOrErr.takeError();
8077 
8078  auto ToParamOrErr = import(E->getParam());
8079  if (!ToParamOrErr)
8080  return ToParamOrErr.takeError();
8081 
8082  auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8083  if (!UsedContextOrErr)
8084  return UsedContextOrErr.takeError();
8085 
8086  // Import the default arg if it was not imported yet.
8087  // This is needed because it can happen that during the import of the
8088  // default expression (from VisitParmVarDecl) the same ParmVarDecl is
8089  // encountered here. The default argument for a ParmVarDecl is set in the
8090  // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here,
8091  // see VisitParmVarDecl).
8092  ParmVarDecl *ToParam = *ToParamOrErr;
8093  if (!ToParam->getDefaultArg()) {
8094  std::optional<ParmVarDecl *> FromParam =
8095  Importer.getImportedFromDecl(ToParam);
8096  assert(FromParam && "ParmVarDecl was not imported?");
8097 
8098  if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam))
8099  return std::move(Err);
8100  }
8101  Expr *RewrittenInit = nullptr;
8102  if (E->hasRewrittenInit()) {
8103  ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8104  if (!ExprOrErr)
8105  return ExprOrErr.takeError();
8106  RewrittenInit = ExprOrErr.get();
8107  }
8108  return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr,
8109  *ToParamOrErr, RewrittenInit,
8110  *UsedContextOrErr);
8111 }
8112 
8115  Error Err = Error::success();
8116  auto ToType = importChecked(Err, E->getType());
8117  auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8118  auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8119  if (Err)
8120  return std::move(Err);
8121 
8122  return new (Importer.getToContext()) CXXScalarValueInitExpr(
8123  ToType, ToTypeSourceInfo, ToRParenLoc);
8124 }
8125 
8128  ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8129  if (!ToSubExprOrErr)
8130  return ToSubExprOrErr.takeError();
8131 
8132  auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
8133  if (!ToDtorOrErr)
8134  return ToDtorOrErr.takeError();
8135 
8136  ASTContext &ToCtx = Importer.getToContext();
8137  CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
8138  return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
8139 }
8140 
8142 
8144  Error Err = Error::success();
8145  auto ToConstructor = importChecked(Err, E->getConstructor());
8146  auto ToType = importChecked(Err, E->getType());
8147  auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8148  auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8149  if (Err)
8150  return std::move(Err);
8151 
8152  SmallVector<Expr *, 8> ToArgs(E->getNumArgs());
8153  if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8154  return std::move(Err);
8155 
8157  Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
8158  ToParenOrBraceRange, E->hadMultipleCandidates(),
8161 }
8162 
8165  DeclContext *DC, *LexicalDC;
8166  if (Error Err = ImportDeclContext(D, DC, LexicalDC))
8167  return std::move(Err);
8168 
8169  Error Err = Error::success();
8170  auto Temporary = importChecked(Err, D->getTemporaryExpr());
8171  auto ExtendingDecl = importChecked(Err, D->getExtendingDecl());
8172  if (Err)
8173  return std::move(Err);
8174  // FIXME: Should ManglingNumber get numbers associated with 'to' context?
8175 
8177  if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl,
8178  D->getManglingNumber()))
8179  return To;
8180 
8181  To->setLexicalDeclContext(LexicalDC);
8182  LexicalDC->addDeclInternal(To);
8183  return To;
8184 }
8185 
8188  Error Err = Error::success();
8189  auto ToType = importChecked(Err, E->getType());
8190  Expr *ToTemporaryExpr = importChecked(
8191  Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr());
8192  auto ToMaterializedDecl =
8194  if (Err)
8195  return std::move(Err);
8196 
8197  if (!ToTemporaryExpr)
8198  ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
8199 
8200  auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
8201  ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
8202  ToMaterializedDecl);
8203 
8204  return ToMTE;
8205 }
8206 
8208  Error Err = Error::success();
8209  auto ToType = importChecked(Err, E->getType());
8210  auto ToPattern = importChecked(Err, E->getPattern());
8211  auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8212  if (Err)
8213  return std::move(Err);
8214 
8215  return new (Importer.getToContext()) PackExpansionExpr(
8216  ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions());
8217 }
8218 
8220  Error Err = Error::success();
8221  auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8222  auto ToPack = importChecked(Err, E->getPack());
8223  auto ToPackLoc = importChecked(Err, E->getPackLoc());
8224  auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8225  if (Err)
8226  return std::move(Err);
8227 
8228  std::optional<unsigned> Length;
8229  if (!E->isValueDependent())
8230  Length = E->getPackLength();
8231 
8232  SmallVector<TemplateArgument, 8> ToPartialArguments;
8233  if (E->isPartiallySubstituted()) {
8234  if (Error Err = ImportTemplateArguments(E->getPartialArguments(),
8235  ToPartialArguments))
8236  return std::move(Err);
8237  }
8238 
8239  return SizeOfPackExpr::Create(
8240  Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
8241  Length, ToPartialArguments);
8242 }
8243 
8244 
8246  Error Err = Error::success();
8247  auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
8248  auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8249  auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens());
8250  auto ToArraySize = importChecked(Err, E->getArraySize());
8251  auto ToInitializer = importChecked(Err, E->getInitializer());
8252  auto ToType = importChecked(Err, E->getType());
8253  auto ToAllocatedTypeSourceInfo =
8255  auto ToSourceRange = importChecked(Err, E->getSourceRange());
8256  auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange());
8257  if (Err)
8258  return std::move(Err);
8259 
8260  SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
8261  if (Error Err =
8262  ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
8263  return std::move(Err);
8264 
8265  return CXXNewExpr::Create(
8266  Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
8267  ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(),
8268  ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(),
8269  ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange,
8270  ToDirectInitRange);
8271 }
8272 
8274  Error Err = Error::success();
8275  auto ToType = importChecked(Err, E->getType());
8276  auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8277  auto ToArgument = importChecked(Err, E->getArgument());
8278  auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8279  if (Err)
8280  return std::move(Err);
8281 
8282  return new (Importer.getToContext()) CXXDeleteExpr(
8283  ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
8284  E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
8285  ToBeginLoc);
8286 }
8287 
8289  Error Err = Error::success();
8290  auto ToType = importChecked(Err, E->getType());
8291  auto ToLocation = importChecked(Err, E->getLocation());
8292  auto ToConstructor = importChecked(Err, E->getConstructor());
8293  auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8294  if (Err)
8295  return std::move(Err);
8296 
8297  SmallVector<Expr *, 6> ToArgs(E->getNumArgs());
8298  if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8299  return std::move(Err);
8300 
8302  Importer.getToContext(), ToType, ToLocation, ToConstructor,
8303  E->isElidable(), ToArgs, E->hadMultipleCandidates(),
8306  ToParenOrBraceRange);
8308  return ToE;
8309 }
8310 
8312  ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8313  if (!ToSubExprOrErr)
8314  return ToSubExprOrErr.takeError();
8315 
8317  if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
8318  return std::move(Err);
8319 
8320  return ExprWithCleanups::Create(
8321  Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
8322  ToObjects);
8323 }
8324 
8326  Error Err = Error::success();
8327  auto ToCallee = importChecked(Err, E->getCallee());
8328  auto ToType = importChecked(Err, E->getType());
8329  auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8330  if (Err)
8331  return std::move(Err);
8332 
8333  SmallVector<Expr *, 4> ToArgs(E->getNumArgs());
8334  if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8335  return std::move(Err);
8336 
8337  return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
8338  ToType, E->getValueKind(), ToRParenLoc,
8339  E->getFPFeatures());
8340 }
8341 
8343  ExpectedType ToTypeOrErr = import(E->getType());
8344  if (!ToTypeOrErr)
8345  return ToTypeOrErr.takeError();
8346 
8347  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8348  if (!ToLocationOrErr)
8349  return ToLocationOrErr.takeError();
8350 
8351  return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
8352  *ToTypeOrErr, E->isImplicit());
8353 }
8354 
8356  ExpectedType ToTypeOrErr = import(E->getType());
8357  if (!ToTypeOrErr)
8358  return ToTypeOrErr.takeError();
8359 
8360  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8361  if (!ToLocationOrErr)
8362  return ToLocationOrErr.takeError();
8363 
8364  return CXXBoolLiteralExpr::Create(Importer.getToContext(), E->getValue(),
8365  *ToTypeOrErr, *ToLocationOrErr);
8366 }
8367 
8369  Error Err = Error::success();
8370  auto ToBase = importChecked(Err, E->getBase());
8371  auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8372  auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8373  auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8374  auto ToMemberDecl = importChecked(Err, E->getMemberDecl());
8375  auto ToType = importChecked(Err, E->getType());
8376  auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl());
8377  auto ToName = importChecked(Err, E->getMemberNameInfo().getName());
8378  auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc());
8379  if (Err)
8380  return std::move(Err);
8381 
8382  DeclAccessPair ToFoundDecl =
8384 
8385  DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
8386 
8387  TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8388  if (E->hasExplicitTemplateArgs()) {
8389  if (Error Err =
8391  E->template_arguments(), ToTAInfo))
8392  return std::move(Err);
8393  ResInfo = &ToTAInfo;
8394  }
8395 
8396  return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(),
8397  ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8398  ToMemberDecl, ToFoundDecl, ToMemberNameInfo,
8399  ResInfo, ToType, E->getValueKind(),
8400  E->getObjectKind(), E->isNonOdrUse());
8401 }
8402 
8405  Error Err = Error::success();
8406  auto ToBase = importChecked(Err, E->getBase());
8407  auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8408  auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8409  auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo());
8410  auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc());
8411  auto ToTildeLoc = importChecked(Err, E->getTildeLoc());
8412  if (Err)
8413  return std::move(Err);
8414 
8416  if (const IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
8417  const IdentifierInfo *ToII = Importer.Import(FromII);
8418  ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
8419  if (!ToDestroyedTypeLocOrErr)
8420  return ToDestroyedTypeLocOrErr.takeError();
8421  Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
8422  } else {
8423  if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
8424  Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
8425  else
8426  return ToTIOrErr.takeError();
8427  }
8428 
8429  return new (Importer.getToContext()) CXXPseudoDestructorExpr(
8430  Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
8431  ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
8432 }
8433 
8436  Error Err = Error::success();
8437  auto ToType = importChecked(Err, E->getType());
8438  auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8439  auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8440  auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8441  auto ToFirstQualifierFoundInScope =
8443  if (Err)
8444  return std::move(Err);
8445 
8446  Expr *ToBase = nullptr;
8447  if (!E->isImplicitAccess()) {
8448  if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8449  ToBase = *ToBaseOrErr;
8450  else
8451  return ToBaseOrErr.takeError();
8452  }
8453 
8454  TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8455 
8456  if (E->hasExplicitTemplateArgs()) {
8457  if (Error Err =
8459  E->template_arguments(), ToTAInfo))
8460  return std::move(Err);
8461  ResInfo = &ToTAInfo;
8462  }
8463  auto ToMember = importChecked(Err, E->getMember());
8464  auto ToMemberLoc = importChecked(Err, E->getMemberLoc());
8465  if (Err)
8466  return std::move(Err);
8467  DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc);
8468 
8469  // Import additional name location/type info.
8470  if (Error Err =
8471  ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo))
8472  return std::move(Err);
8473 
8475  Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
8476  ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
8477  ToMemberNameInfo, ResInfo);
8478 }
8479 
8482  Error Err = Error::success();
8483  auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8484  auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8485  auto ToDeclName = importChecked(Err, E->getDeclName());
8486  auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc());
8487  auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc());
8488  auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc());
8489  if (Err)
8490  return std::move(Err);
8491 
8492  DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8493  if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8494  return std::move(Err);
8495 
8496  TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
8497  TemplateArgumentListInfo *ResInfo = nullptr;
8498  if (E->hasExplicitTemplateArgs()) {
8499  if (Error Err =
8501  return std::move(Err);
8502  ResInfo = &ToTAInfo;
8503  }
8504 
8506  Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
8507  ToNameInfo, ResInfo);
8508 }
8509 
8512  Error Err = Error::success();
8513  auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8514  auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8515  auto ToType = importChecked(Err, E->getType());
8516  auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8517  if (Err)
8518  return std::move(Err);
8519 
8520  SmallVector<Expr *, 8> ToArgs(E->getNumArgs());
8521  if (Error Err =
8522  ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
8523  return std::move(Err);
8524 
8526  Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc,
8527  llvm::ArrayRef(ToArgs), ToRParenLoc, E->isListInitialization());
8528 }
8529 
8532  Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
8533  if (!ToNamingClassOrErr)
8534  return ToNamingClassOrErr.takeError();
8535 
8536  auto ToQualifierLocOrErr = import(E->getQualifierLoc());
8537  if (!ToQualifierLocOrErr)
8538  return ToQualifierLocOrErr.takeError();
8539 
8540  Error Err = Error::success();
8541  auto ToName = importChecked(Err, E->getName());
8542  auto ToNameLoc = importChecked(Err, E->getNameLoc());
8543  if (Err)
8544  return std::move(Err);
8545  DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8546 
8547  // Import additional name location/type info.
8548  if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8549  return std::move(Err);
8550 
8551  UnresolvedSet<8> ToDecls;
8552  for (auto *D : E->decls())
8553  if (auto ToDOrErr = import(D))
8554  ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8555  else
8556  return ToDOrErr.takeError();
8557 
8558  if (E->hasExplicitTemplateArgs()) {
8559  TemplateArgumentListInfo ToTAInfo;
8560  if (Error Err = ImportTemplateArgumentListInfo(
8561  E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(),
8562  ToTAInfo))
8563  return std::move(Err);
8564 
8565  ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
8566  if (!ToTemplateKeywordLocOrErr)
8567  return ToTemplateKeywordLocOrErr.takeError();
8568 
8569  const bool KnownDependent =
8570  (E->getDependence() & ExprDependence::TypeValue) ==
8571  ExprDependence::TypeValue;
8573  Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8574  *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
8575  ToDecls.begin(), ToDecls.end(), KnownDependent);
8576  }
8577 
8579  Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8580  ToNameInfo, E->requiresADL(), ToDecls.begin(), ToDecls.end(),
8581  /*KnownDependent=*/E->isTypeDependent());
8582 }
8583 
8586  Error Err = Error::success();
8587  auto ToType = importChecked(Err, E->getType());
8588  auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8589  auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8590  auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8591  auto ToName = importChecked(Err, E->getName());
8592  auto ToNameLoc = importChecked(Err, E->getNameLoc());
8593  if (Err)
8594  return std::move(Err);
8595 
8596  DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8597  // Import additional name location/type info.
8598  if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8599  return std::move(Err);
8600 
8601  UnresolvedSet<8> ToDecls;
8602  for (Decl *D : E->decls())
8603  if (auto ToDOrErr = import(D))
8604  ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8605  else
8606  return ToDOrErr.takeError();
8607 
8608  TemplateArgumentListInfo ToTAInfo;
8609  TemplateArgumentListInfo *ResInfo = nullptr;
8610  if (E->hasExplicitTemplateArgs()) {
8611  TemplateArgumentListInfo FromTAInfo;
8612  E->copyTemplateArgumentsInto(FromTAInfo);
8613  if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo))
8614  return std::move(Err);
8615  ResInfo = &ToTAInfo;
8616  }
8617 
8618  Expr *ToBase = nullptr;
8619  if (!E->isImplicitAccess()) {
8620  if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8621  ToBase = *ToBaseOrErr;
8622  else
8623  return ToBaseOrErr.takeError();
8624  }
8625 
8627  Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
8628  E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8629  ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
8630 }
8631 
8633  Error Err = Error::success();
8634  auto ToCallee = importChecked(Err, E->getCallee());
8635  auto ToType = importChecked(Err, E->getType());
8636  auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8637  if (Err)
8638  return std::move(Err);
8639 
8640  unsigned NumArgs = E->getNumArgs();
8641  llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
8642  if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8643  return std::move(Err);
8644 
8645  if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
8647  Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
8648  OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
8649  OCE->getADLCallKind());
8650  }
8651 
8652  return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
8653  E->getValueKind(), ToRParenLoc, E->getFPFeatures(),
8654  /*MinNumArgs=*/0, E->getADLCallKind());
8655 }
8656 
8658  CXXRecordDecl *FromClass = E->getLambdaClass();
8659  auto ToClassOrErr = import(FromClass);
8660  if (!ToClassOrErr)
8661  return ToClassOrErr.takeError();
8662  CXXRecordDecl *ToClass = *ToClassOrErr;
8663 
8664  auto ToCallOpOrErr = import(E->getCallOperator());
8665  if (!ToCallOpOrErr)
8666  return ToCallOpOrErr.takeError();
8667 
8668  SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
8669  if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
8670  return std::move(Err);
8671 
8672  Error Err = Error::success();
8673  auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange());
8674  auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc());
8675  auto ToEndLoc = importChecked(Err, E->getEndLoc());
8676  if (Err)
8677  return std::move(Err);
8678 
8679  return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange,
8680  E->getCaptureDefault(), ToCaptureDefaultLoc,
8681  E->hasExplicitParameters(),
8682  E->hasExplicitResultType(), ToCaptureInits,
8683  ToEndLoc, E->containsUnexpandedParameterPack());
8684 }
8685 
8686 
8688  Error Err = Error::success();
8689  auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
8690  auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc());
8691  auto ToType = importChecked(Err, E->getType());
8692  if (Err)
8693  return std::move(Err);
8694 
8695  SmallVector<Expr *, 4> ToExprs(E->getNumInits());
8696  if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
8697  return std::move(Err);
8698 
8699  ASTContext &ToCtx = Importer.getToContext();
8700  InitListExpr *To = new (ToCtx) InitListExpr(
8701  ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc);
8702  To->setType(ToType);
8703 
8704  if (E->hasArrayFiller()) {
8705  if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
8706  To->setArrayFiller(*ToFillerOrErr);
8707  else
8708  return ToFillerOrErr.takeError();
8709  }
8710 
8711  if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
8712  if (auto ToFDOrErr = import(FromFD))
8713  To->setInitializedFieldInUnion(*ToFDOrErr);
8714  else
8715  return ToFDOrErr.takeError();
8716  }
8717 
8718  if (InitListExpr *SyntForm = E->getSyntacticForm()) {
8719  if (auto ToSyntFormOrErr = import(SyntForm))
8720  To->setSyntacticForm(*ToSyntFormOrErr);
8721  else
8722  return ToSyntFormOrErr.takeError();
8723  }
8724 
8725  // Copy InitListExprBitfields, which are not handled in the ctor of
8726  // InitListExpr.
8728 
8729  return To;
8730 }
8731 
8734  ExpectedType ToTypeOrErr = import(E->getType());
8735  if (!ToTypeOrErr)
8736  return ToTypeOrErr.takeError();
8737 
8738  ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8739  if (!ToSubExprOrErr)
8740  return ToSubExprOrErr.takeError();
8741 
8742  return new (Importer.getToContext()) CXXStdInitializerListExpr(
8743  *ToTypeOrErr, *ToSubExprOrErr);
8744 }
8745 
8748  Error Err = Error::success();
8749  auto ToLocation = importChecked(Err, E->getLocation());
8750  auto ToType = importChecked(Err, E->getType());
8751  auto ToConstructor = importChecked(Err, E->getConstructor());
8752  if (Err)
8753  return std::move(Err);
8754 
8755  return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
8756  ToLocation, ToType, ToConstructor, E->constructsVBase(),
8757  E->inheritedFromVBase());
8758 }
8759 
8761  Error Err = Error::success();
8762  auto ToType = importChecked(Err, E->getType());
8763  auto ToCommonExpr = importChecked(Err, E->getCommonExpr());
8764  auto ToSubExpr = importChecked(Err, E->getSubExpr());
8765  if (Err)
8766  return std::move(Err);
8767 
8768  return new (Importer.getToContext()) ArrayInitLoopExpr(
8769  ToType, ToCommonExpr, ToSubExpr);
8770 }
8771 
8773  ExpectedType ToTypeOrErr = import(E->getType());
8774  if (!ToTypeOrErr)
8775  return ToTypeOrErr.takeError();
8776  return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
8777 }
8778 
8780  ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
8781  if (!ToBeginLocOrErr)
8782  return ToBeginLocOrErr.takeError();
8783 
8784  auto ToFieldOrErr = import(E->getField());
8785  if (!ToFieldOrErr)
8786  return ToFieldOrErr.takeError();
8787 
8788  auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8789  if (!UsedContextOrErr)
8790  return UsedContextOrErr.takeError();
8791 
8792  FieldDecl *ToField = *ToFieldOrErr;
8793  assert(ToField->hasInClassInitializer() &&
8794  "Field should have in-class initializer if there is a default init "
8795  "expression that uses it.");
8796  if (!ToField->getInClassInitializer()) {
8797  // The in-class initializer may be not yet set in "To" AST even if the
8798  // field is already there. This must be set here to make construction of
8799  // CXXDefaultInitExpr work.
8800  auto ToInClassInitializerOrErr =
8801  import(E->getField()->getInClassInitializer());
8802  if (!ToInClassInitializerOrErr)
8803  return ToInClassInitializerOrErr.takeError();
8804  ToField->setInClassInitializer(*ToInClassInitializerOrErr);
8805  }
8806 
8807  Expr *RewrittenInit = nullptr;
8808  if (E->hasRewrittenInit()) {
8809  ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8810  if (!ExprOrErr)
8811  return ExprOrErr.takeError();
8812  RewrittenInit = ExprOrErr.get();
8813  }
8814 
8815  return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr,
8816  ToField, *UsedContextOrErr, RewrittenInit);
8817 }
8818 
8820  Error Err = Error::success();
8821  auto ToType = importChecked(Err, E->getType());
8822  auto ToSubExpr = importChecked(Err, E->getSubExpr());
8823  auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
8824  auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8825  auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8826  auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets());
8827  if (Err)
8828  return std::move(Err);
8829 
8830  ExprValueKind VK = E->getValueKind();
8831  CastKind CK = E->getCastKind();
8832  auto ToBasePathOrErr = ImportCastPath(E);
8833  if (!ToBasePathOrErr)
8834  return ToBasePathOrErr.takeError();
8835 
8836  if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) {
8838  Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
8839  ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc,
8840  ToAngleBrackets);
8841  } else if (isa<CXXDynamicCastExpr>(E)) {
8843  Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
8844  ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
8845  } else if (isa<CXXReinterpretCastExpr>(E)) {
8847  Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
8848  ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
8849  } else if (isa<CXXConstCastExpr>(E)) {
8850  return CXXConstCastExpr::Create(
8851  Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
8852  ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
8853  } else {
8854  llvm_unreachable("Unknown cast type");
8855  return make_error<ASTImportError>();
8856  }
8857 }
8858 
8861  Error Err = Error::success();
8862  auto ToType = importChecked(Err, E->getType());
8863  auto ToExprLoc = importChecked(Err, E->getExprLoc());
8864  auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
8865  auto ToReplacement = importChecked(Err, E->getReplacement());
8866  if (Err)
8867  return std::move(Err);
8868 
8869  return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
8870  ToType, E->getValueKind(), ToExprLoc, ToReplacement, ToAssociatedDecl,
8871  E->getIndex(), E->getPackIndex(), E->isReferenceParameter());
8872 }
8873 
8875  Error Err = Error::success();
8876  auto ToType = importChecked(Err, E->getType());
8877  auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8878  auto ToEndLoc = importChecked(Err, E->getEndLoc());
8879  if (Err)
8880  return std::move(Err);
8881 
8883  if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
8884  return std::move(Err);
8885 
8886  // According to Sema::BuildTypeTrait(), if E is value-dependent,
8887  // Value is always false.
8888  bool ToValue = (E->isValueDependent() ? false : E->getValue());
8889 
8890  return TypeTraitExpr::Create(
8891  Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs,
8892  ToEndLoc, ToValue);
8893 }
8894 
8896  ExpectedType ToTypeOrErr = import(E->getType());
8897  if (!ToTypeOrErr)
8898  return ToTypeOrErr.takeError();
8899 
8900  auto ToSourceRangeOrErr = import(E->getSourceRange());
8901  if (!ToSourceRangeOrErr)
8902  return ToSourceRangeOrErr.takeError();
8903 
8904  if (E->isTypeOperand()) {
8905  if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
8906  return new (Importer.getToContext()) CXXTypeidExpr(
8907  *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
8908  else
8909  return ToTSIOrErr.takeError();
8910  }
8911 
8912  ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
8913  if (!ToExprOperandOrErr)
8914  return ToExprOperandOrErr.takeError();
8915 
8916  return new (Importer.getToContext()) CXXTypeidExpr(
8917  *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
8918 }
8919 
8921  Error Err = Error::success();
8922 
8923  QualType ToType = importChecked(Err, E->getType());
8924  UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
8925  SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
8926  Expr *ToLHS = importChecked(Err, E->getLHS());
8927  SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8928  Expr *ToRHS = importChecked(Err, E->getRHS());
8929  SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
8930 
8931  if (Err)
8932  return std::move(Err);
8933 
8934  return new (Importer.getToContext())
8935  CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
8936  ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
8937 }
8938 
8940  CXXMethodDecl *FromMethod) {
8941  Error ImportErrors = Error::success();
8942  for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
8943  if (auto ImportedOrErr = import(FromOverriddenMethod))
8944  ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>(
8945  (*ImportedOrErr)->getCanonicalDecl()));
8946  else
8947  ImportErrors =
8948  joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
8949  }
8950  return ImportErrors;
8951 }
8952 
8954  ASTContext &FromContext, FileManager &FromFileManager,
8955  bool MinimalImport,
8956  std::shared_ptr<ASTImporterSharedState> SharedState)
8957  : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
8958  ToFileManager(ToFileManager), FromFileManager(FromFileManager),
8959  Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) {
8960 
8961  // Create a default state without the lookup table: LLDB case.
8962  if (!SharedState) {
8963  this->SharedState = std::make_shared<ASTImporterSharedState>();
8964  }
8965 
8966  ImportedDecls[FromContext.getTranslationUnitDecl()] =
8967  ToContext.getTranslationUnitDecl();
8968 }
8969 
8970 ASTImporter::~ASTImporter() = default;
8971 
8972 std::optional<unsigned> ASTImporter::getFieldIndex(Decl *F) {
8973  assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
8974  "Try to get field index for non-field.");
8975 
8976  auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
8977  if (!Owner)
8978  return std::nullopt;
8979 
8980  unsigned Index = 0;
8981  for (const auto *D : Owner->decls()) {
8982  if (D == F)
8983  return Index;
8984 
8985  if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D))
8986  ++Index;
8987  }
8988 
8989  llvm_unreachable("Field was not found in its parent context.");
8990 
8991  return std::nullopt;
8992 }
8993 
8995 ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
8996  // We search in the redecl context because of transparent contexts.
8997  // E.g. a simple C language enum is a transparent context:
8998  // enum E { A, B };
8999  // Now if we had a global variable in the TU
9000  // int A;
9001  // then the enum constant 'A' and the variable 'A' violates ODR.
9002  // We can diagnose this only if we search in the redecl context.
9003  DeclContext *ReDC = DC->getRedeclContext();
9004  if (SharedState->getLookupTable()) {
9006  SharedState->getLookupTable()->lookup(ReDC, Name);
9007  return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
9008  } else {
9009  DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
9010  FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
9011  // We must search by the slow case of localUncachedLookup because that is
9012  // working even if there is no LookupPtr for the DC. We could use
9013  // DC::buildLookup() to create the LookupPtr, but that would load external
9014  // decls again, we must avoid that case.
9015  // Also, even if we had the LookupPtr, we must find Decls which are not
9016  // in the LookupPtr, so we need the slow case.
9017  // These cases are handled in ASTImporterLookupTable, but we cannot use
9018  // that with LLDB since that traverses through the AST which initiates the
9019  // load of external decls again via DC::decls(). And again, we must avoid
9020  // loading external decls during the import.
9021  if (Result.empty())
9022  ReDC->localUncachedLookup(Name, Result);
9023  return Result;
9024  }
9025 }
9026 
9027 void ASTImporter::AddToLookupTable(Decl *ToD) {
9028  SharedState->addDeclToLookup(ToD);
9029 }
9030 
9032  // Import the decl using ASTNodeImporter.
9033  ASTNodeImporter Importer(*this);
9034  return Importer.Visit(FromD);
9035 }
9036 
9038  MapImported(FromD, ToD);
9039 }
9040 
9043  if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) {
9044  if (Expected<Expr *> R = Import(CLE))
9045  return ExprWithCleanups::CleanupObject(cast<CompoundLiteralExpr>(*R));
9046  }
9047 
9048  // FIXME: Handle BlockDecl when we implement importing BlockExpr in
9049  // ASTNodeImporter.
9050  return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
9051 }
9052 
9054  if (!FromT)
9055  return FromT;
9056 
9057  // Check whether we've already imported this type.
9058  llvm::DenseMap<const Type *, const Type *>::iterator Pos =
9059  ImportedTypes.find(FromT);
9060  if (Pos != ImportedTypes.end())
9061  return Pos->second;
9062 
9063  // Import the type.
9064  ASTNodeImporter Importer(*this);
9065  ExpectedType ToTOrErr = Importer.Visit(FromT);
9066  if (!ToTOrErr)
9067  return ToTOrErr.takeError();
9068 
9069  // Record the imported type.
9070  ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9071 
9072  return ToTOrErr->getTypePtr();
9073 }
9074 
9076  if (FromT.isNull())
9077  return QualType{};
9078 
9079  ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9080  if (!ToTyOrErr)
9081  return ToTyOrErr.takeError();
9082 
9083  return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9084 }
9085 
9087  if (!FromTSI)
9088  return FromTSI;
9089 
9090  // FIXME: For now we just create a "trivial" type source info based
9091  // on the type and a single location. Implement a real version of this.
9092  ExpectedType TOrErr = Import(FromTSI->getType());
9093  if (!TOrErr)
9094  return TOrErr.takeError();
9095  ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9096  if (!BeginLocOrErr)
9097  return BeginLocOrErr.takeError();
9098 
9099  return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9100 }
9101 
9102 namespace {
9103 // To use this object, it should be created before the new attribute is created,
9104 // and destructed after it is created. The construction already performs the
9105 // import of the data.
9106 template <typename T> struct AttrArgImporter {
9107  AttrArgImporter(const AttrArgImporter<T> &) = delete;
9108  AttrArgImporter(AttrArgImporter<T> &&) = default;
9109  AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9110  AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9111 
9112  AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9113  : To(I.importChecked(Err, From)) {}
9114 
9115  const T &value() { return To; }
9116 
9117 private:
9118  T To;
9119 };
9120 
9121 // To use this object, it should be created before the new attribute is created,
9122 // and destructed after it is created. The construction already performs the
9123 // import of the data. The array data is accessible in a pointer form, this form
9124 // is used by the attribute classes. This object should be created once for the
9125 // array data to be imported (the array size is not imported, just copied).
9126 template <typename T> struct AttrArgArrayImporter {
9127  AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9128  AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9129  AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9130  AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9131 
9132  AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9133  const llvm::iterator_range<T *> &From,
9134  unsigned ArraySize) {
9135  if (Err)
9136  return;
9137  To.reserve(ArraySize);
9138  Err = I.ImportContainerChecked(From, To);
9139  }
9140 
9141  T *value() { return To.data(); }
9142 
9143 private:
9145 };
9146 
9147 class AttrImporter {
9148  Error Err{Error::success()};
9149  Attr *ToAttr = nullptr;
9150  ASTImporter &Importer;
9151  ASTNodeImporter NImporter;
9152 
9153 public:
9154  AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9155 
9156  // Useful for accessing the imported attribute.
9157  template <typename T> T *castAttrAs() { return cast<T>(ToAttr); }
9158  template <typename T> const T *castAttrAs() const { return cast<T>(ToAttr); }
9159 
9160  // Create an "importer" for an attribute parameter.
9161  // Result of the 'value()' of that object is to be passed to the function
9162  // 'importAttr', in the order that is expected by the attribute class.
9163  template <class T> AttrArgImporter<T> importArg(const T &From) {
9164  return AttrArgImporter<T>(NImporter, Err, From);
9165  }
9166 
9167  // Create an "importer" for an attribute parameter that has array type.
9168  // Result of the 'value()' of that object is to be passed to the function
9169  // 'importAttr', then the size of the array as next argument.
9170  template <typename T>
9171  AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9172  unsigned ArraySize) {
9173  return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9174  }
9175 
9176  // Create an attribute object with the specified arguments.
9177  // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9178  // should be values that are passed to the 'Create' function of the attribute.
9179  // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9180  // used here.) As much data is copied or imported from the old attribute
9181  // as possible. The passed arguments should be already imported.
9182  // If an import error happens, the internal error is set to it, and any
9183  // further import attempt is ignored.
9184  template <typename T, typename... Arg>
9185  void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9186  static_assert(std::is_base_of<Attr, T>::value,
9187  "T should be subclass of Attr.");
9188  assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9189 
9190  const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9191  const IdentifierInfo *ToScopeName =
9192  Importer.Import(FromAttr->getScopeName());
9193  SourceRange ToAttrRange =
9194  NImporter.importChecked(Err, FromAttr->getRange());
9195  SourceLocation ToScopeLoc =
9196  NImporter.importChecked(Err, FromAttr->getScopeLoc());
9197 
9198  if (Err)
9199  return;
9200 
9201  AttributeCommonInfo ToI(ToAttrName, ToScopeName, ToAttrRange, ToScopeLoc,
9202  FromAttr->getParsedKind(), FromAttr->getForm());
9203  // The "SemanticSpelling" is not needed to be passed to the constructor.
9204  // That value is recalculated from the SpellingListIndex if needed.
9205  ToAttr = T::Create(Importer.getToContext(),
9206  std::forward<Arg>(ImportedArg)..., ToI);
9207 
9208  ToAttr->setImplicit(FromAttr->isImplicit());
9209  ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9210  if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9211  ToInheritableAttr->setInherited(FromAttr->isInherited());
9212  }
9213 
9214  // Create a clone of the 'FromAttr' and import its source range only.
9215  // This causes objects with invalid references to be created if the 'FromAttr'
9216  // contains other data that should be imported.
9217  void cloneAttr(const Attr *FromAttr) {
9218  assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9219 
9220  SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9221  if (Err)
9222  return;
9223 
9224  ToAttr = FromAttr->clone(Importer.getToContext());
9225  ToAttr->setRange(ToRange);
9226  ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9227  }
9228 
9229  // Get the result of the previous import attempt (can be used only once).
9230  llvm::Expected<Attr *> getResult() && {
9231  if (Err)
9232  return std::move(Err);
9233  assert(ToAttr && "Attribute should be created.");
9234  return ToAttr;
9235  }
9236 };
9237 } // namespace
9238 
9240  AttrImporter AI(*this);
9241 
9242  // FIXME: Is there some kind of AttrVisitor to use here?
9243  switch (FromAttr->getKind()) {
9244  case attr::Aligned: {
9245  auto *From = cast<AlignedAttr>(FromAttr);
9246  if (From->isAlignmentExpr())
9247  AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9248  else
9249  AI.importAttr(From, false,
9250  AI.importArg(From->getAlignmentType()).value());
9251  break;
9252  }
9253 
9254  case attr::AlignValue: {
9255  auto *From = cast<AlignValueAttr>(FromAttr);
9256  AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9257  break;
9258  }
9259 
9260  case attr::Format: {
9261  const auto *From = cast<FormatAttr>(FromAttr);
9262  AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9263  From->getFirstArg());
9264  break;
9265  }
9266 
9267  case attr::EnableIf: {
9268  const auto *From = cast<EnableIfAttr>(FromAttr);
9269  AI.importAttr(From, AI.importArg(From->getCond()).value(),
9270  From->getMessage());
9271  break;
9272  }
9273 
9274  case attr::AssertCapability: {
9275  const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9276  AI.importAttr(From,
9277  AI.importArrayArg(From->args(), From->args_size()).value(),
9278  From->args_size());
9279  break;
9280  }
9281  case attr::AcquireCapability: {
9282  const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9283  AI.importAttr(From,
9284  AI.importArrayArg(From->args(), From->args_size()).value(),
9285  From->args_size());
9286  break;
9287  }
9288  case attr::TryAcquireCapability: {
9289  const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9290  AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9291  AI.importArrayArg(From->args(), From->args_size()).value(),
9292  From->args_size());
9293  break;
9294  }
9295  case attr::ReleaseCapability: {
9296  const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9297  AI.importAttr(From,
9298  AI.importArrayArg(From->args(), From->args_size()).value(),
9299  From->args_size());
9300  break;
9301  }
9302  case attr::RequiresCapability: {
9303  const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9304  AI.importAttr(From,
9305  AI.importArrayArg(From->args(), From->args_size()).value(),
9306  From->args_size());
9307  break;
9308  }
9309  case attr::GuardedBy: {
9310  const auto *From = cast<GuardedByAttr>(FromAttr);
9311  AI.importAttr(From, AI.importArg(From->getArg()).value());
9312  break;
9313  }
9314  case attr::PtGuardedBy: {
9315  const auto *From = cast<PtGuardedByAttr>(FromAttr);
9316  AI.importAttr(From, AI.importArg(From->getArg()).value());
9317  break;
9318  }
9319  case attr::AcquiredAfter: {
9320  const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9321  AI.importAttr(From,
9322  AI.importArrayArg(From->args(), From->args_size()).value(),
9323  From->args_size());
9324  break;
9325  }
9326  case attr::AcquiredBefore: {
9327  const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9328  AI.importAttr(From,
9329  AI.importArrayArg(From->args(), From->args_size()).value(),
9330  From->args_size());
9331  break;
9332  }
9333  case attr::AssertExclusiveLock: {
9334  const auto *From = cast<AssertExclusiveLockAttr>(FromAttr);
9335  AI.importAttr(From,
9336  AI.importArrayArg(From->args(), From->args_size()).value(),
9337  From->args_size());
9338  break;
9339  }
9340  case attr::AssertSharedLock: {
9341  const auto *From = cast<AssertSharedLockAttr>(FromAttr);
9342  AI.importAttr(From,
9343  AI.importArrayArg(From->args(), From->args_size()).value(),
9344  From->args_size());
9345  break;
9346  }
9347  case attr::ExclusiveTrylockFunction: {
9348  const auto *From = cast<ExclusiveTrylockFunctionAttr>(FromAttr);
9349  AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9350  AI.importArrayArg(From->args(), From->args_size()).value(),
9351  From->args_size());
9352  break;
9353  }
9354  case attr::SharedTrylockFunction: {
9355  const auto *From = cast<SharedTrylockFunctionAttr>(FromAttr);
9356  AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9357  AI.importArrayArg(From->args(), From->args_size()).value(),
9358  From->args_size());
9359  break;
9360  }
9361  case attr::LockReturned: {
9362  const auto *From = cast<LockReturnedAttr>(FromAttr);
9363  AI.importAttr(From, AI.importArg(From->getArg()).value());
9364  break;
9365  }
9366  case attr::LocksExcluded: {
9367  const auto *From = cast<LocksExcludedAttr>(FromAttr);
9368  AI.importAttr(From,
9369  AI.importArrayArg(From->args(), From->args_size()).value(),
9370  From->args_size());
9371  break;
9372  }
9373  default: {
9374  // The default branch works for attributes that have no arguments to import.
9375  // FIXME: Handle every attribute type that has arguments of type to import
9376  // (most often Expr* or Decl* or type) in the switch above.
9377  AI.cloneAttr(FromAttr);
9378  break;
9379  }
9380  }
9381 
9382  return std::move(AI).getResult();
9383 }
9384 
9386  return ImportedDecls.lookup(FromD);
9387 }
9388 
9390  auto FromDPos = ImportedFromDecls.find(ToD);
9391  if (FromDPos == ImportedFromDecls.end())
9392  return nullptr;
9393  return FromDPos->second->getTranslationUnitDecl();
9394 }
9395 
9396 Error ASTImporter::ImportAttrs(Decl *ToD, Decl *FromD) {
9397  if (!FromD->hasAttrs() || ToD->hasAttrs())
9398  return Error::success();
9399  for (const Attr *FromAttr : FromD->getAttrs()) {
9400  auto ToAttrOrErr = Import(FromAttr);
9401  if (ToAttrOrErr)
9402  ToD->addAttr(*ToAttrOrErr);
9403  else
9404  return ToAttrOrErr.takeError();
9405  }
9406  return Error::success();
9407 }
9408 
9410  if (!FromD)
9411  return nullptr;
9412 
9413  // Push FromD to the stack, and remove that when we return.
9414  ImportPath.push(FromD);
9415  auto ImportPathBuilder =
9416  llvm::make_scope_exit([this]() { ImportPath.pop(); });
9417 
9418  // Check whether there was a previous failed import.
9419  // If yes return the existing error.
9420  if (auto Error = getImportDeclErrorIfAny(FromD))
9421  return make_error<ASTImportError>(*Error);
9422 
9423  // Check whether we've already imported this declaration.
9424  Decl *ToD = GetAlreadyImportedOrNull(FromD);
9425  if (ToD) {
9426  // Already imported (possibly from another TU) and with an error.
9427  if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9428  setImportDeclError(FromD, *Error);
9429  return make_error<ASTImportError>(*Error);
9430  }
9431 
9432  // If FromD has some updated flags after last import, apply it.
9433  updateFlags(FromD, ToD);
9434  // If we encounter a cycle during an import then we save the relevant part
9435  // of the import path associated to the Decl.
9436  if (ImportPath.hasCycleAtBack())
9437  SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9438  return ToD;
9439  }
9440 
9441  // Import the declaration.
9442  ExpectedDecl ToDOrErr = ImportImpl(FromD);
9443  if (!ToDOrErr) {
9444  // Failed to import.
9445 
9446  auto Pos = ImportedDecls.find(FromD);
9447  if (Pos != ImportedDecls.end()) {
9448  // Import failed after the object was created.
9449  // Remove all references to it.
9450  auto *ToD = Pos->second;
9451  ImportedDecls.erase(Pos);
9452 
9453  // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9454  // (e.g. with namespaces) that several decls from the 'from' context are
9455  // mapped to the same decl in the 'to' context. If we removed entries
9456  // from the LookupTable here then we may end up removing them multiple
9457  // times.
9458 
9459  // The Lookuptable contains decls only which are in the 'to' context.
9460  // Remove from the Lookuptable only if it is *imported* into the 'to'
9461  // context (and do not remove it if it was added during the initial
9462  // traverse of the 'to' context).
9463  auto PosF = ImportedFromDecls.find(ToD);
9464  if (PosF != ImportedFromDecls.end()) {
9465  // In the case of TypedefNameDecl we create the Decl first and only
9466  // then we import and set its DeclContext. So, the DC might not be set
9467  // when we reach here.
9468  if (ToD->getDeclContext())
9469  SharedState->removeDeclFromLookup(ToD);
9470  ImportedFromDecls.erase(PosF);
9471  }
9472 
9473  // FIXME: AST may contain remaining references to the failed object.
9474  // However, the ImportDeclErrors in the shared state contains all the
9475  // failed objects together with their error.
9476  }
9477 
9478  // Error encountered for the first time.
9479  // After takeError the error is not usable any more in ToDOrErr.
9480  // Get a copy of the error object (any more simple solution for this?).
9481  ASTImportError ErrOut;
9482  handleAllErrors(ToDOrErr.takeError(),
9483  [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9484  setImportDeclError(FromD, ErrOut);
9485  // Set the error for the mapped to Decl, which is in the "to" context.
9486  if (Pos != ImportedDecls.end())
9487  SharedState->setImportDeclError(Pos->second, ErrOut);
9488 
9489  // Set the error for all nodes which have been created before we
9490  // recognized the error.
9491  for (const auto &Path : SavedImportPaths[FromD]) {
9492  // The import path contains import-dependency nodes first.
9493  // Save the node that was imported as dependency of the current node.
9494  Decl *PrevFromDi = FromD;
9495  for (Decl *FromDi : Path) {
9496  // Begin and end of the path equals 'FromD', skip it.
9497  if (FromDi == FromD)
9498  continue;
9499  // We should not set import error on a node and all following nodes in
9500  // the path if child import errors are ignored.
9501  if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9502  PrevFromDi))
9503  break;
9504  PrevFromDi = FromDi;
9505  setImportDeclError(FromDi, ErrOut);
9506  //FIXME Should we remove these Decls from ImportedDecls?
9507  // Set the error for the mapped to Decl, which is in the "to" context.
9508  auto Ii = ImportedDecls.find(FromDi);
9509  if (Ii != ImportedDecls.end())
9510  SharedState->setImportDeclError(Ii->second, ErrOut);
9511  // FIXME Should we remove these Decls from the LookupTable,
9512  // and from ImportedFromDecls?
9513  }
9514  }
9515  SavedImportPaths.erase(FromD);
9516 
9517  // Do not return ToDOrErr, error was taken out of it.
9518  return make_error<ASTImportError>(ErrOut);
9519  }
9520 
9521  ToD = *ToDOrErr;
9522 
9523  // FIXME: Handle the "already imported with error" case. We can get here
9524  // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
9525  // previously failed create was requested).
9526  // Later GetImportedOrCreateDecl can be updated to return the error.
9527  if (!ToD) {
9528  auto Err = getImportDeclErrorIfAny(FromD);
9529  assert(Err);
9530  return make_error<ASTImportError>(*Err);
9531  }
9532 
9533  // We could import from the current TU without error. But previously we
9534  // already had imported a Decl as `ToD` from another TU (with another
9535  // ASTImporter object) and with an error.
9536  if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9537  setImportDeclError(FromD, *Error);
9538  return make_error<ASTImportError>(*Error);
9539  }
9540  // Make sure that ImportImpl registered the imported decl.
9541  assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
9542  if (auto Error = ImportAttrs(ToD, FromD))
9543  return std::move(Error);
9544 
9545  // Notify subclasses.
9546  Imported(FromD, ToD);
9547 
9548  updateFlags(FromD, ToD);
9549  SavedImportPaths.erase(FromD);
9550  return ToDOrErr;
9551 }
9552 
9555  return ASTNodeImporter(*this).ImportInheritedConstructor(From);
9556 }
9557 
9559  if (!FromDC)
9560  return FromDC;
9561 
9562  ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
9563  if (!ToDCOrErr)
9564  return ToDCOrErr.takeError();
9565  auto *ToDC = cast<DeclContext>(*ToDCOrErr);
9566 
9567  // When we're using a record/enum/Objective-C class/protocol as a context, we
9568  // need it to have a definition.
9569  if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
9570  auto *FromRecord = cast<RecordDecl>(FromDC);
9571  if (ToRecord->isCompleteDefinition())
9572  return ToDC;
9573 
9574  // If FromRecord is not defined we need to force it to be.
9575  // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
9576  // it will start the definition but we never finish it.
9577  // If there are base classes they won't be imported and we will
9578  // be missing anything that we inherit from those bases.
9579  if (FromRecord->getASTContext().getExternalSource() &&
9580  !FromRecord->isCompleteDefinition())
9581  FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
9582 
9583  if (FromRecord->isCompleteDefinition())
9584  if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9585  FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
9586  return std::move(Err);
9587  } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
9588  auto *FromEnum = cast<EnumDecl>(FromDC);
9589  if (ToEnum->isCompleteDefinition()) {
9590  // Do nothing.
9591  } else if (FromEnum->isCompleteDefinition()) {
9592  if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9593  FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
9594  return std::move(Err);
9595  } else {
9596  CompleteDecl(ToEnum);
9597  }
9598  } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
9599  auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
9600  if (ToClass->getDefinition()) {
9601  // Do nothing.
9602  } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
9603  if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9604  FromDef, ToClass, ASTNodeImporter::IDK_Basic))
9605  return std::move(Err);
9606  } else {
9607  CompleteDecl(ToClass);
9608  }
9609  } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
9610  auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
9611  if (ToProto->getDefinition()) {
9612  // Do nothing.
9613  } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
9614  if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9615  FromDef, ToProto, ASTNodeImporter::IDK_Basic))
9616  return std::move(Err);
9617  } else {
9618  CompleteDecl(ToProto);
9619  }
9620  }
9621 
9622  return ToDC;
9623 }
9624 
9626  if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
9627  return cast_or_null<Expr>(*ToSOrErr);
9628  else
9629  return ToSOrErr.takeError();
9630 }
9631 
9633  if (!FromS)
9634  return nullptr;
9635 
9636  // Check whether we've already imported this statement.
9637  llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
9638  if (Pos != ImportedStmts.end())
9639  return Pos->second;
9640 
9641  // Import the statement.
9642  ASTNodeImporter Importer(*this);
9643  ExpectedStmt ToSOrErr = Importer.Visit(FromS);
9644  if (!ToSOrErr)
9645  return ToSOrErr;
9646 
9647  if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
9648  auto *FromE = cast<Expr>(FromS);
9649  // Copy ExprBitfields, which may not be handled in Expr subclasses
9650  // constructors.
9651  ToE->setValueKind(FromE->getValueKind());
9652  ToE->setObjectKind(FromE->getObjectKind());
9653  ToE->setDependence(FromE->getDependence());
9654  }
9655 
9656  // Record the imported statement object.
9657  ImportedStmts[FromS] = *ToSOrErr;
9658  return ToSOrErr;
9659 }
9660 
9663  if (!FromNNS)
9664  return nullptr;
9665 
9666  NestedNameSpecifier *Prefix = nullptr;
9667  if (Error Err = importInto(Prefix, FromNNS->getPrefix()))
9668  return std::move(Err);
9669 
9670  switch (FromNNS->getKind()) {
9672  assert(FromNNS->getAsIdentifier() && "NNS should contain identifier.");
9673  return NestedNameSpecifier::Create(ToContext, Prefix,
9674  Import(FromNNS->getAsIdentifier()));
9675 
9677  if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) {
9678  return NestedNameSpecifier::Create(ToContext, Prefix,
9679  cast<NamespaceDecl>(*NSOrErr));
9680  } else
9681  return NSOrErr.takeError();
9682 
9684  if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias()))
9685  return NestedNameSpecifier::Create(ToContext, Prefix,
9686  cast<NamespaceAliasDecl>(*NSADOrErr));
9687  else
9688  return NSADOrErr.takeError();
9689 
9691  return NestedNameSpecifier::GlobalSpecifier(ToContext);
9692 
9694  if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl()))
9695  return NestedNameSpecifier::SuperSpecifier(ToContext,
9696  cast<CXXRecordDecl>(*RDOrErr));
9697  else
9698  return RDOrErr.takeError();
9699 
9702  if (ExpectedTypePtr TyOrErr = Import(FromNNS->getAsType())) {
9703  bool TSTemplate =
9705  return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate,
9706  *TyOrErr);
9707  } else {
9708  return TyOrErr.takeError();
9709  }
9710  }
9711 
9712  llvm_unreachable("Invalid nested name specifier kind");
9713 }
9714 
9717  // Copied from NestedNameSpecifier mostly.
9719  NestedNameSpecifierLoc NNS = FromNNS;
9720 
9721  // Push each of the nested-name-specifiers's onto a stack for
9722  // serialization in reverse order.
9723  while (NNS) {
9724  NestedNames.push_back(NNS);
9725  NNS = NNS.getPrefix();
9726  }
9727 
9729 
9730  while (!NestedNames.empty()) {
9731  NNS = NestedNames.pop_back_val();
9732  NestedNameSpecifier *Spec = nullptr;
9733  if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
9734  return std::move(Err);
9735 
9737 
9738  SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
9740  if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
9741  return std::move(Err);
9742 
9744  if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
9745  return std::move(Err);
9746  }
9747 
9748  switch (Kind) {
9750  Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc,
9751  ToLocalEndLoc);
9752  break;
9753 
9755  Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc,
9756  ToLocalEndLoc);
9757  break;
9758 
9760  Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(),
9761  ToLocalBeginLoc, ToLocalEndLoc);
9762  break;
9763 
9766  SourceLocation ToTLoc;
9767  if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc()))
9768  return std::move(Err);
9770  QualType(Spec->getAsType(), 0), ToTLoc);
9772  // ToLocalBeginLoc is here the location of the 'template' keyword.
9773  Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(),
9774  ToLocalEndLoc);
9775  else
9776  // No location for 'template' keyword here.
9777  Builder.Extend(getToContext(), SourceLocation{}, TSI->getTypeLoc(),
9778  ToLocalEndLoc);
9779  break;
9780  }
9781 
9783  Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
9784  break;
9785 
9787  auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
9788  if (!ToSourceRangeOrErr)
9789  return ToSourceRangeOrErr.takeError();
9790 
9791  Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(),
9792  ToSourceRangeOrErr->getBegin(),
9793  ToSourceRangeOrErr->getEnd());
9794  }
9795  }
9796  }
9797 
9798  return Builder.getWithLocInContext(getToContext());
9799 }
9800 
9802  switch (From.getKind()) {
9804  if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
9805  return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
9806  else
9807  return ToTemplateOrErr.takeError();
9808 
9810  OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate();
9811  UnresolvedSet<2> ToTemplates;
9812  for (auto *I : *FromStorage) {
9813  if (auto ToOrErr = Import(I))
9814  ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
9815  else
9816  return ToOrErr.takeError();
9817  }
9818  return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
9819  ToTemplates.end());
9820  }
9821 
9823  AssumedTemplateStorage *FromStorage = From.getAsAssumedTemplateName();
9824  auto DeclNameOrErr = Import(FromStorage->getDeclName());
9825  if (!DeclNameOrErr)
9826  return DeclNameOrErr.takeError();
9827  return ToContext.getAssumedTemplateName(*DeclNameOrErr);
9828  }
9829 
9832  auto QualifierOrErr = Import(QTN->getQualifier());
9833  if (!QualifierOrErr)
9834  return QualifierOrErr.takeError();
9835  auto TNOrErr = Import(QTN->getUnderlyingTemplate());
9836  if (!TNOrErr)
9837  return TNOrErr.takeError();
9838  return ToContext.getQualifiedTemplateName(
9839  *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
9840  }
9841 
9844  auto QualifierOrErr = Import(DTN->getQualifier());
9845  if (!QualifierOrErr)
9846  return QualifierOrErr.takeError();
9847 
9848  if (DTN->isIdentifier()) {
9849  return ToContext.getDependentTemplateName(*QualifierOrErr,
9850  Import(DTN->getIdentifier()));
9851  }
9852 
9853  return ToContext.getDependentTemplateName(*QualifierOrErr,
9854  DTN->getOperator());
9855  }
9856 
9860  auto ReplacementOrErr = Import(Subst->getReplacement());
9861  if (!ReplacementOrErr)
9862  return ReplacementOrErr.takeError();
9863 
9864  auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
9865  if (!AssociatedDeclOrErr)
9866  return AssociatedDeclOrErr.takeError();
9867 
9868  return ToContext.getSubstTemplateTemplateParm(
9869  *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
9870  Subst->getPackIndex());
9871  }
9872 
9876  ASTNodeImporter Importer(*this);
9877  auto ArgPackOrErr =
9878  Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
9879  if (!ArgPackOrErr)
9880  return ArgPackOrErr.takeError();
9881 
9882  auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
9883  if (!AssociatedDeclOrErr)
9884  return AssociatedDeclOrErr.takeError();
9885 
9886  return ToContext.getSubstTemplateTemplateParmPack(
9887  *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
9888  SubstPack->getFinal());
9889  }
9891  auto UsingOrError = Import(From.getAsUsingShadowDecl());
9892  if (!UsingOrError)
9893  return UsingOrError.takeError();
9894  return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
9895  }
9896  }
9897 
9898  llvm_unreachable("Invalid template name kind");
9899 }
9900 
9902  if (FromLoc.isInvalid())
9903  return SourceLocation{};
9904 
9905  SourceManager &FromSM = FromContext.getSourceManager();
9906  bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
9907 
9908  std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc);
9909  Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
9910  if (!ToFileIDOrErr)
9911  return ToFileIDOrErr.takeError();
9912  SourceManager &ToSM = ToContext.getSourceManager();
9913  return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
9914 }
9915 
9917  SourceLocation ToBegin, ToEnd;
9918  if (Error Err = importInto(ToBegin, FromRange.getBegin()))
9919  return std::move(Err);
9920  if (Error Err = importInto(ToEnd, FromRange.getEnd()))
9921  return std::move(Err);
9922 
9923  return SourceRange(ToBegin, ToEnd);
9924 }
9925 
9927  llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
9928  if (Pos != ImportedFileIDs.end())
9929  return Pos->second;
9930 
9931  SourceManager &FromSM = FromContext.getSourceManager();
9932  SourceManager &ToSM = ToContext.getSourceManager();
9933  const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
9934 
9935  // Map the FromID to the "to" source manager.
9936  FileID ToID;
9937  if (FromSLoc.isExpansion()) {
9938  const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
9939  ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
9940  if (!ToSpLoc)
9941  return ToSpLoc.takeError();
9942  ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
9943  if (!ToExLocS)
9944  return ToExLocS.takeError();
9945  unsigned ExLength = FromSM.getFileIDSize(FromID);
9946  SourceLocation MLoc;
9947  if (FromEx.isMacroArgExpansion()) {
9948  MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
9949  } else {
9950  if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
9951  MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
9952  FromEx.isExpansionTokenRange());
9953  else
9954  return ToExLocE.takeError();
9955  }
9956  ToID = ToSM.getFileID(MLoc);
9957  } else {
9958  const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
9959 
9960  if (!IsBuiltin && !Cache->BufferOverridden) {
9961  // Include location of this file.
9962  ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
9963  if (!ToIncludeLoc)
9964  return ToIncludeLoc.takeError();
9965 
9966  // Every FileID that is not the main FileID needs to have a valid include
9967  // location so that the include chain points to the main FileID. When
9968  // importing the main FileID (which has no include location), we need to
9969  // create a fake include location in the main file to keep this property
9970  // intact.
9971  SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
9972  if (FromID == FromSM.getMainFileID())
9973  ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
9974 
9975  if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
9976  // FIXME: We probably want to use getVirtualFile(), so we don't hit the
9977  // disk again
9978  // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
9979  // than mmap the files several times.
9980  auto Entry =
9981  ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
9982  // FIXME: The filename may be a virtual name that does probably not
9983  // point to a valid file and we get no Entry here. In this case try with
9984  // the memory buffer below.
9985  if (Entry)
9986  ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
9987  FromSLoc.getFile().getFileCharacteristic());
9988  }
9989  }
9990 
9991  if (ToID.isInvalid() || IsBuiltin) {
9992  // FIXME: We want to re-use the existing MemoryBuffer!
9993  std::optional<llvm::MemoryBufferRef> FromBuf =
9994  Cache->getBufferOrNone(FromContext.getDiagnostics(),
9995  FromSM.getFileManager(), SourceLocation{});
9996  if (!FromBuf)
9997  return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
9998 
9999  std::unique_ptr<llvm::MemoryBuffer> ToBuf =
10000  llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
10001  FromBuf->getBufferIdentifier());
10002  ToID = ToSM.createFileID(std::move(ToBuf),
10003  FromSLoc.getFile().getFileCharacteristic());
10004  }
10005  }
10006 
10007  assert(ToID.isValid() && "Unexpected invalid fileID was created.");
10008 
10009  ImportedFileIDs[FromID] = ToID;
10010  return ToID;
10011 }
10012 
10014  ExpectedExpr ToExprOrErr = Import(From->getInit());
10015  if (!ToExprOrErr)
10016  return ToExprOrErr.takeError();
10017 
10018  auto LParenLocOrErr = Import(From->getLParenLoc());
10019  if (!LParenLocOrErr)
10020  return LParenLocOrErr.takeError();
10021 
10022  auto RParenLocOrErr = Import(From->getRParenLoc());
10023  if (!RParenLocOrErr)
10024  return RParenLocOrErr.takeError();
10025 
10026  if (From->isBaseInitializer()) {
10027  auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10028  if (!ToTInfoOrErr)
10029  return ToTInfoOrErr.takeError();
10030 
10031  SourceLocation EllipsisLoc;
10032  if (From->isPackExpansion())
10033  if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
10034  return std::move(Err);
10035 
10036  return new (ToContext) CXXCtorInitializer(
10037  ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
10038  *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
10039  } else if (From->isMemberInitializer()) {
10040  ExpectedDecl ToFieldOrErr = Import(From->getMember());
10041  if (!ToFieldOrErr)
10042  return ToFieldOrErr.takeError();
10043 
10044  auto MemberLocOrErr = Import(From->getMemberLocation());
10045  if (!MemberLocOrErr)
10046  return MemberLocOrErr.takeError();
10047 
10048  return new (ToContext) CXXCtorInitializer(
10049  ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
10050  *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10051  } else if (From->isIndirectMemberInitializer()) {
10052  ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
10053  if (!ToIFieldOrErr)
10054  return ToIFieldOrErr.takeError();
10055 
10056  auto MemberLocOrErr = Import(From->getMemberLocation());
10057  if (!MemberLocOrErr)
10058  return MemberLocOrErr.takeError();
10059 
10060  return new (ToContext) CXXCtorInitializer(
10061  ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10062  *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10063  } else if (From->isDelegatingInitializer()) {
10064  auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10065  if (!ToTInfoOrErr)
10066  return ToTInfoOrErr.takeError();
10067 
10068  return new (ToContext)
10069  CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10070  *ToExprOrErr, *RParenLocOrErr);
10071  } else {
10072  // FIXME: assert?
10073  return make_error<ASTImportError>();
10074  }
10075 }
10076 
10079  auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10080  if (Pos != ImportedCXXBaseSpecifiers.end())
10081  return Pos->second;
10082 
10083  Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10084  if (!ToSourceRange)
10085  return ToSourceRange.takeError();
10087  if (!ToTSI)
10088  return ToTSI.takeError();
10089  ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10090  if (!ToEllipsisLoc)
10091  return ToEllipsisLoc.takeError();
10092  CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10093  *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10094  BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10095  ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10096  return Imported;
10097 }
10098 
10100  ASTNodeImporter Importer(*this);
10101  return Importer.ImportAPValue(FromValue);
10102 }
10103 
10105  ExpectedDecl ToOrErr = Import(From);
10106  if (!ToOrErr)
10107  return ToOrErr.takeError();
10108  Decl *To = *ToOrErr;
10109 
10110  auto *FromDC = cast<DeclContext>(From);
10111  ASTNodeImporter Importer(*this);
10112 
10113  if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10114  if (!ToRecord->getDefinition()) {
10115  return Importer.ImportDefinition(
10116  cast<RecordDecl>(FromDC), ToRecord,
10118  }
10119  }
10120 
10121  if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10122  if (!ToEnum->getDefinition()) {
10123  return Importer.ImportDefinition(
10124  cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything);
10125  }
10126  }
10127 
10128  if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10129  if (!ToIFace->getDefinition()) {
10130  return Importer.ImportDefinition(
10131  cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10133  }
10134  }
10135 
10136  if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10137  if (!ToProto->getDefinition()) {
10138  return Importer.ImportDefinition(
10139  cast<ObjCProtocolDecl>(FromDC), ToProto,
10141  }
10142  }
10143 
10144  return Importer.ImportDeclContext(FromDC, true);
10145 }
10146 
10148  if (!FromName)
10149  return DeclarationName{};
10150 
10151  switch (FromName.getNameKind()) {
10153  return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10154 
10158  if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10159  return DeclarationName(*ToSelOrErr);
10160  else
10161  return ToSelOrErr.takeError();
10162 
10164  if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10165  return ToContext.DeclarationNames.getCXXConstructorName(
10166  ToContext.getCanonicalType(*ToTyOrErr));
10167  else
10168  return ToTyOrErr.takeError();
10169  }
10170 
10172  if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10173  return ToContext.DeclarationNames.getCXXDestructorName(
10174  ToContext.getCanonicalType(*ToTyOrErr));
10175  else
10176  return ToTyOrErr.takeError();
10177  }
10178 
10180  if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10181  return ToContext.DeclarationNames.getCXXDeductionGuideName(
10182  cast<TemplateDecl>(*ToTemplateOrErr));
10183  else
10184  return ToTemplateOrErr.takeError();
10185  }
10186 
10188  if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10190  ToContext.getCanonicalType(*ToTyOrErr));
10191  else
10192  return ToTyOrErr.takeError();
10193  }
10194 
10196  return ToContext.DeclarationNames.getCXXOperatorName(
10197  FromName.getCXXOverloadedOperator());
10198 
10201  Import(FromName.getCXXLiteralIdentifier()));
10202 
10204  // FIXME: STATICS!
10206  }
10207 
10208  llvm_unreachable("Invalid DeclarationName Kind!");
10209 }
10210 
10212  if (!FromId)
10213  return nullptr;
10214 
10215  IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10216 
10217  if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10218  ToId->setBuiltinID(FromId->getBuiltinID());
10219 
10220  return ToId;
10221 }
10222 
10224  if (FromSel.isNull())
10225  return Selector{};
10226 
10228  Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10229  for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10230  Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10231  return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10232 }
10233 
10236  APValue Result;
10237  llvm::Error Err = llvm::Error::success();
10238  auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10239  for (unsigned Idx = 0; Idx < Size; Idx++) {
10240  APValue Tmp = importChecked(Err, From[Idx]);
10241  To[Idx] = Tmp;
10242  }
10243  };
10244  switch (FromValue.getKind()) {
10245  case APValue::None:
10247  case APValue::Int:
10248  case APValue::Float:
10249  case APValue::FixedPoint:
10250  case APValue::ComplexInt:
10251  case APValue::ComplexFloat:
10252  Result = FromValue;
10253  break;
10254  case APValue::Vector: {
10255  Result.MakeVector();
10257  Result.setVectorUninit(FromValue.getVectorLength());
10258  ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10259  Elts.data(), FromValue.getVectorLength());
10260  break;
10261  }
10262  case APValue::Array:
10263  Result.MakeArray(FromValue.getArrayInitializedElts(),
10264  FromValue.getArraySize());
10265  ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10266  ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10267  FromValue.getArrayInitializedElts());
10268  break;
10269  case APValue::Struct:
10270  Result.MakeStruct(FromValue.getStructNumBases(),
10271  FromValue.getStructNumFields());
10272  ImportLoop(
10273  ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10274  ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10275  FromValue.getStructNumBases() + FromValue.getStructNumFields());
10276  break;
10277  case APValue::Union: {
10278  Result.MakeUnion();
10279  const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10280  APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10281  if (Err)
10282  return std::move(Err);
10283  Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10284  break;
10285  }
10286  case APValue::AddrLabelDiff: {
10287  Result.MakeAddrLabelDiff();
10288  const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10289  const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10290  if (Err)
10291  return std::move(Err);
10292  Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10293  cast<AddrLabelExpr>(ImpRHS));
10294  break;
10295  }
10296  case APValue::MemberPointer: {
10297  const Decl *ImpMemPtrDecl =
10298  importChecked(Err, FromValue.getMemberPointerDecl());
10299  if (Err)
10300  return std::move(Err);
10302  Result.setMemberPointerUninit(
10303  cast<const ValueDecl>(ImpMemPtrDecl),
10304  FromValue.isMemberPointerToDerivedMember(),
10305  FromValue.getMemberPointerPath().size());
10307  Result.getMemberPointerPath();
10308  for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10309  Idx++) {
10310  const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10311  if (Err)
10312  return std::move(Err);
10313  ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10314  }
10315  break;
10316  }
10317  case APValue::LValue:
10319  QualType FromElemTy;
10320  if (FromValue.getLValueBase()) {
10321  assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10322  "in C++20 dynamic allocation are transient so they shouldn't "
10323  "appear in the AST");
10324  if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10325  if (const auto *E =
10326  FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10327  FromElemTy = E->getType();
10328  const Expr *ImpExpr = importChecked(Err, E);
10329  if (Err)
10330  return std::move(Err);
10331  Base = APValue::LValueBase(ImpExpr,
10332  FromValue.getLValueBase().getCallIndex(),
10333  FromValue.getLValueBase().getVersion());
10334  } else {
10335  FromElemTy =
10336  FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10337  const Decl *ImpDecl = importChecked(
10338  Err, FromValue.getLValueBase().get<const ValueDecl *>());
10339  if (Err)
10340  return std::move(Err);
10341  Base = APValue::LValueBase(cast<ValueDecl>(ImpDecl),
10342  FromValue.getLValueBase().getCallIndex(),
10343  FromValue.getLValueBase().getVersion());
10344  }
10345  } else {
10346  FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10347  const Type *ImpTypeInfo = importChecked(
10348  Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10349  QualType ImpType =
10350  importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10351  if (Err)
10352  return std::move(Err);
10354  ImpType);
10355  }
10356  }
10357  CharUnits Offset = FromValue.getLValueOffset();
10358  unsigned PathLength = FromValue.getLValuePath().size();
10359  Result.MakeLValue();
10360  if (FromValue.hasLValuePath()) {
10361  MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10362  Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10363  FromValue.isNullPointer());
10365  FromValue.getLValuePath();
10366  for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10367  if (FromElemTy->isRecordType()) {
10368  const Decl *FromDecl =
10369  FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10370  const Decl *ImpDecl = importChecked(Err, FromDecl);
10371  if (Err)
10372  return std::move(Err);
10373  if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10374  FromElemTy = Importer.FromContext.getRecordType(RD);
10375  else
10376  FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10378  ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10379  } else {
10380  FromElemTy =
10381  Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10382  ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10383  FromPath[LoopIdx].getAsArrayIndex());
10384  }
10385  }
10386  } else
10387  Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10388  FromValue.isNullPointer());
10389  }
10390  if (Err)
10391  return std::move(Err);
10392  return Result;
10393 }
10394 
10396  DeclContext *DC,
10397  unsigned IDNS,
10398  NamedDecl **Decls,
10399  unsigned NumDecls) {
10400  if (ODRHandling == ODRHandlingType::Conservative)
10401  // Report error at any name conflict.
10402  return make_error<ASTImportError>(ASTImportError::NameConflict);
10403  else
10404  // Allow to create the new Decl with the same name.
10405  return Name;
10406 }
10407 
10409  if (LastDiagFromFrom)
10411  FromContext.getDiagnostics());
10412  LastDiagFromFrom = false;
10413  return ToContext.getDiagnostics().Report(Loc, DiagID);
10414 }
10415 
10417  if (!LastDiagFromFrom)
10419  ToContext.getDiagnostics());
10420  LastDiagFromFrom = true;
10421  return FromContext.getDiagnostics().Report(Loc, DiagID);
10422 }
10423 
10425  if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10426  if (!ID->getDefinition())
10427  ID->startDefinition();
10428  }
10429  else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10430  if (!PD->getDefinition())
10431  PD->startDefinition();
10432  }
10433  else if (auto *TD = dyn_cast<TagDecl>(D)) {
10434  if (!TD->getDefinition() && !TD->isBeingDefined()) {
10435  TD->startDefinition();
10436  TD->setCompleteDefinition(true);
10437  }
10438  }
10439  else {
10440  assert(0 && "CompleteDecl called on a Decl that can't be completed");
10441  }
10442 }
10443 
10445  llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From);
10446  assert((Pos == ImportedDecls.end() || Pos->second == To) &&
10447  "Try to import an already imported Decl");
10448  if (Pos != ImportedDecls.end())
10449  return Pos->second;
10450  ImportedDecls[From] = To;
10451  // This mapping should be maintained only in this function. Therefore do not
10452  // check for additional consistency.
10453  ImportedFromDecls[To] = From;
10454  // In the case of TypedefNameDecl we create the Decl first and only then we
10455  // import and set its DeclContext. So, the DC is still not set when we reach
10456  // here from GetImportedOrCreateDecl.
10457  if (To->getDeclContext())
10458  AddToLookupTable(To);
10459  return To;
10460 }
10461 
10462 std::optional<ASTImportError>
10464  auto Pos = ImportDeclErrors.find(FromD);
10465  if (Pos != ImportDeclErrors.end())
10466  return Pos->second;
10467  else
10468  return std::nullopt;
10469 }
10470 
10472  auto InsertRes = ImportDeclErrors.insert({From, Error});
10473  (void)InsertRes;
10474  // Either we set the error for the first time, or we already had set one and
10475  // now we want to set the same error.
10476  assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10477 }
10478 
10480  bool Complain) {
10481  llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10482  ImportedTypes.find(From.getTypePtr());
10483  if (Pos != ImportedTypes.end()) {
10484  if (ExpectedType ToFromOrErr = Import(From)) {
10485  if (ToContext.hasSameType(*ToFromOrErr, To))
10486  return true;
10487  } else {
10488  llvm::consumeError(ToFromOrErr.takeError());
10489  }
10490  }
10491 
10492  StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls,
10493  getStructuralEquivalenceKind(*this), false,
10494  Complain);
10495  return Ctx.IsEquivalent(From, To);
10496 }
Defines the clang::ASTContext interface.
ASTImporterLookupTable & LT
static FriendCountAndPosition getFriendCountAndPosition(ASTImporter &Importer, FriendDecl *FD)
static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1, FriendDecl *FD2)
static auto getTemplateDefinition(T *D) -> T *
static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D)
static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, ASTImporter &Importer)
static StructuralEquivalenceKind getStructuralEquivalenceKind(const ASTImporter &Importer)
static char ID
Definition: Arena.cpp:183
Defines enum values for all the target-independent builtin functions.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines the ExceptionSpecificationType enumeration and various utility functions.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines the clang::FileManager interface and associated types.
unsigned Offset
Definition: Format.cpp:2978
int Category
Definition: Format.cpp:2979
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the LambdaCapture class.
Defines the clang::LangOptions interface.
llvm::MachO::Record Record
Definition: MachO.h:31
llvm::SmallVector< std::pair< const MemRegion *, SVal >, 4 > Bindings
SourceLocation Loc
Definition: SemaObjC.cpp:755
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Defines various enumerations that describe declaration and type specifiers.
Defines the Objective-C statement AST node classes.
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
const NamedDecl * FromDecl
llvm::APInt getValue() const
unsigned getVersion() const
Definition: APValue.cpp:113
QualType getTypeInfoType() const
Definition: APValue.cpp:117
static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo)
Definition: APValue.cpp:55
unsigned getCallIndex() const
Definition: APValue.cpp:108
A non-discriminated union of a base, field, or array index.
Definition: APValue.h:208
static LValuePathEntry ArrayIndex(uint64_t Index)
Definition: APValue.h:216
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
const LValueBase getLValueBase() const
Definition: APValue.cpp:974
ArrayRef< LValuePathEntry > getLValuePath() const
Definition: APValue.cpp:994
const AddrLabelExpr * getAddrLabelDiffLHS() const
Definition: APValue.h:579
APValue & getUnionValue()
Definition: APValue.h:567
unsigned getStructNumFields() const
Definition: APValue.h:542
llvm::PointerIntPair< const Decl *, 1, bool > BaseOrMemberType
A FieldDecl or CXXRecordDecl, along with a flag indicating whether we mean a virtual or non-virtual b...
Definition: APValue.h:205
ValueKind getKind() const
Definition: APValue.h:395
bool isLValueOnePastTheEnd() const
Definition: APValue.cpp:979
bool isMemberPointerToDerivedMember() const
Definition: APValue.cpp:1064
unsigned getArrayInitializedElts() const
Definition: APValue.h:529
unsigned getStructNumBases() const
Definition: APValue.h:538
bool hasLValuePath() const
Definition: APValue.cpp:989
const ValueDecl * getMemberPointerDecl() const
Definition: APValue.cpp:1057
CharUnits & getLValueOffset()
Definition: APValue.cpp:984
unsigned getVectorLength() const
Definition: APValue.h:505
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition: APValue.h:583
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition: APValue.cpp:1071
const FieldDecl * getUnionField() const
Definition: APValue.h:563
unsigned getArraySize() const
Definition: APValue.h:533
@ Indeterminate
This object has an indeterminate value (C++ [basic.indet]).
Definition: APValue.h:131
@ None
There is no such object (it's outside its lifetime).
Definition: APValue.h:129
bool isNullPointer() const
Definition: APValue.cpp:1010
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:185
QualType getUsingType(const UsingShadowDecl *Found, QualType Underlying) const
QualType getAtomicType(QualType T) const
Return the uniqued reference to the atomic type for the specified type.
QualType getParenType(QualType NamedType) const
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type.
SourceManager & getSourceManager()
Definition: ASTContext.h:708
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType) const
BuiltinTemplateDecl * getMakeIntegerSeqDecl() const
void setInstantiatedFromUsingDecl(NamedDecl *Inst, NamedDecl *Pattern)
Remember that the using decl Inst is an instantiation of the using decl Pattern of a class template.
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent, bool IsPack=false, ConceptDecl *TypeConstraintConcept=nullptr, ArrayRef< TemplateArgument > TypeConstraintArgs={}) const
C++11 deduced auto type.
QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, ArrayRef< TemplateArgumentLoc > Args) const
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl.
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl.
QualType getMemberPointerType(QualType T, const Type *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
NamedDecl * getInstantiatedFromUsingDecl(NamedDecl *Inst)
If the given using decl Inst is an instantiation of another (possibly unresolved) using decl,...
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:651
QualType getTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon=QualType()) const
QualType getRecordType(const RecordDecl *Decl) const
QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const
getInjectedClassNameType - Return the unique reference to the injected class name type for the specif...
QualType getVariableArrayType(QualType EltTy, Expr *NumElts, ArraySizeModifier ASM, unsigned IndexTypeQuals, SourceRange Brackets) const
Return a non-unique reference to the type for a variable array of the specified element type.
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
QualType getArrayParameterType(QualType Ty) const
Return the uniqued reference to a specified array parameter type from the original array type.
QualType getCountAttributedType(QualType T, Expr *CountExpr, bool CountInBytes, bool OrNull, ArrayRef< TypeCoupledDeclRefInfo > DependentDecls) const
QualType getPackExpansionType(QualType Pattern, std::optional< unsigned > NumExpansions, bool ExpectPackInType=true)
Form a pack expansion type with the given pattern.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2589
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2605
void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, UsingShadowDecl *Pattern)
TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, bool TemplateKeyword, TemplateName Template) const
Retrieve the template name that represents a qualified template name such as std::vector.
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
QualType getReadPipeType(QualType T) const
Return a read_only pipe type for the specified type.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1605
IdentifierTable & Idents
Definition: ASTContext.h:647
TemplateName getSubstTemplateTemplateParm(TemplateName replacement, Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex) const
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
SelectorTable & Selectors
Definition: ASTContext.h:648
QualType getMacroQualifiedType(QualType UnderlyingTy, const IdentifierInfo *MacroII) const
QualType getDecayedType(QualType T) const
Return the uniqued reference to the decayed version of the given type.
const LangOptions & getLangOpts() const
Definition: ASTContext.h:778
void setInstantiatedFromUsingEnumDecl(UsingEnumDecl *Inst, UsingEnumDecl *Pattern)
Remember that the using enum decl Inst is an instantiation of the using enum decl Pattern of a class ...
UsingEnumDecl * getInstantiatedFromUsingEnumDecl(UsingEnumDecl *Inst)
If the given using-enum decl Inst is an instantiation of another using-enum decl, return it.
QualType getDeducedTemplateSpecializationType(TemplateName Template, QualType DeducedType, bool IsDependent) const
C++17 deduced class template specialization type.
QualType getTemplateTypeParmType(unsigned Depth, unsigned Index, bool ParameterPack, TemplateTypeParmDecl *ParmDecl=nullptr) const
Retrieve the template type parameter type for a template parameter or parameter pack with the given d...
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
QualType getSubstTemplateTypeParmPackType(Decl *AssociatedDecl, unsigned Index, bool Final, const TemplateArgument &ArgPack)
Retrieve a.
CanQualType CharTy
Definition: ASTContext.h:1096
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:2171
QualType getElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType, TagDecl *OwnedTagDecl=nullptr) const
CanQualType SignedCharTy
Definition: ASTContext.h:1103
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
QualType getObjCObjectType(QualType Base, ObjCProtocolDecl *const *Protocols, unsigned NumProtocols) const
Legacy interface: cannot provide type arguments or __kindof.
QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts, ArraySizeModifier ASM, unsigned IndexTypeQuals, SourceRange Brackets) const
Return a non-unique reference to the type for a dependently-sized array of the specified element type...
UsingShadowDecl * getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst)
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
QualType getWritePipeType(QualType T) const
Return a write_only pipe type for the specified type.
CanQualType VoidTy
Definition: ASTContext.h:1094
CanQualType UnsignedCharTy
Definition: ASTContext.h:1104
TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, const IdentifierInfo *Name) const
Retrieve the template name that represents a dependent template name such as MetaFun::template apply.
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
Definition: ASTContext.h:1583
QualType getDependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, QualType Canon=QualType()) const
QualType getPackIndexingType(QualType Pattern, Expr *IndexExpr, bool FullySubstituted=false, ArrayRef< QualType > Expansions={}, int Index=-1) const
QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType, UnaryTransformType::UTTKind UKind) const
Unary type transforms.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Definition: ASTContext.h:1203
QualType getComplexType(QualType T) const
Return the uniqued reference to the type for a complex number with the specified element type.
DiagnosticsEngine & getDiagnostics() const
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size.
TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, UnresolvedSetIterator End) const
Retrieve the template name that corresponds to a non-empty lookup.
TemplateName getSubstTemplateTemplateParmPack(const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index, bool Final) const
BuiltinTemplateDecl * getTypePackElementDecl() const
QualType getTypeOfType(QualType QT, TypeOfKind Kind) const
getTypeOfType - Unlike many "get<Type>" functions, we don't unique TypeOfType nodes.
CanQualType WCharTy
Definition: ASTContext.h:1097
QualType getDecltypeType(Expr *e, QualType UnderlyingType) const
C++11 decltype.
QualType getTypedefType(const TypedefNameDecl *Decl, QualType Underlying=QualType()) const
Return the unique reference to the type for the specified typedef-name decl.
QualType getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex) const
Retrieve a substitution-result type.
unsigned char getFixedPointScale(QualType Ty) const
QualType getIncompleteArrayType(QualType EltTy, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return a unique reference to the type for an incomplete array of the specified element type.
QualType getDependentSizedExtVectorType(QualType VectorType, Expr *SizeExpr, SourceLocation AttrLoc) const
TemplateName getAssumedTemplateName(DeclarationName Name) const
Retrieve a template name representing an unqualified-id that has been assumed to name a template for ...
QualType getTypeOfExprType(Expr *E, TypeOfKind Kind) const
C23 feature and GCC extension.
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1076
std::error_code convertToErrorCode() const override
void log(llvm::raw_ostream &OS) const override
std::string toString() const
Definition: ASTImporter.cpp:86
@ Unknown
Not supported node or case.
@ UnsupportedConstruct
Naming ambiguity (likely ODR violation).
void update(NamedDecl *ND, DeclContext *OldDC)
void updateForced(NamedDecl *ND, DeclContext *OldDC)
bool hasCycleAtBack() const
Returns true if the last element can be found earlier in the path.
Definition: ASTImporter.h:164
VecTy copyCycleAtBack() const
Returns the copy of the cycle.
Definition: ASTImporter.h:178
Imports selected nodes from one AST context into another context, merging AST nodes where appropriate...
Definition: ASTImporter.h:62
std::optional< DeclT * > getImportedFromDecl(const DeclT *ToD) const
Return the declaration in the "from" context from which the declaration in the "to" context was impor...
Definition: ASTImporter.h:371
virtual Decl * GetOriginalDecl(Decl *To)
Called by StructuralEquivalenceContext.
Definition: ASTImporter.h:563
DiagnosticBuilder ToDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "to" context.
Decl * MapImported(Decl *From, Decl *To)
Store and assign the imported declaration to its counterpart.
TranslationUnitDecl * GetFromTU(Decl *ToD)
Return the translation unit from where the declaration was imported.
llvm::Expected< DeclContext * > ImportContext(DeclContext *FromDC)
Import the given declaration context from the "from" AST context into the "to" AST context.
llvm::Error ImportDefinition(Decl *From)
Import the definition of the given declaration, including all of the declarations it contains.
virtual Expected< DeclarationName > HandleNameConflict(DeclarationName Name, DeclContext *DC, unsigned IDNS, NamedDecl **Decls, unsigned NumDecls)
Cope with a name conflict when importing a declaration into the given context.
virtual bool returnWithErrorInTest()
Used only in unittests to verify the behaviour of the error handling.
Definition: ASTImporter.h:270
void RegisterImportedDecl(Decl *FromD, Decl *ToD)
std::optional< ASTImportError > getImportDeclErrorIfAny(Decl *FromD) const
Return if import of the given declaration has failed and if yes the kind of the problem.
friend class ASTNodeImporter
Definition: ASTImporter.h:63
static std::optional< unsigned > getFieldIndex(Decl *F)
Determine the index of a field in its parent record.
llvm::Error importInto(ImportT &To, const ImportT &From)
Import the given object, returns the result.
Definition: ASTImporter.h:308
virtual void Imported(Decl *From, Decl *To)
Subclasses can override this function to observe all of the From -> To declaration mappings as they a...
Definition: ASTImporter.h:548
DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "from" context.
virtual ~ASTImporter()
bool IsStructurallyEquivalent(QualType From, QualType To, bool Complain=true)
Determine whether the given types are structurally equivalent.
ASTContext & getFromContext() const
Retrieve the context that AST nodes are being imported from.
Definition: ASTImporter.h:523
virtual Expected< Decl * > ImportImpl(Decl *From)
Can be overwritten by subclasses to implement their own import logic.
bool isMinimalImport() const
Whether the importer will perform a minimal import, creating to-be-completed forward declarations whe...
Definition: ASTImporter.h:298
NonEquivalentDeclSet & getNonEquivalentDecls()
Return the set of declarations that we know are not equivalent.
Definition: ASTImporter.h:538
ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, ASTContext &FromContext, FileManager &FromFileManager, bool MinimalImport, std::shared_ptr< ASTImporterSharedState > SharedState=nullptr)
llvm::Expected< ExprWithCleanups::CleanupObject > Import(ExprWithCleanups::CleanupObject From)
Import cleanup objects owned by ExprWithCleanup.
ASTContext & getToContext() const
Retrieve the context that AST nodes are being imported into.
Definition: ASTImporter.h:520
virtual void CompleteDecl(Decl *D)
Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl.
Decl * GetAlreadyImportedOrNull(const Decl *FromD) const
Return the copy of the given declaration in the "to" context if it has already been imported from the...
void setImportDeclError(Decl *From, ASTImportError Error)
Mark (newly) imported declaration with error.
ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D)
ExpectedStmt VisitGenericSelectionExpr(GenericSelectionExpr *E)
ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E)
ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D)
ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D)
ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E)
ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D)
ExpectedDecl VisitFunctionDecl(FunctionDecl *D)
ExpectedDecl VisitParmVarDecl(ParmVarDecl *D)
ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E)
ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E)
ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D)
ExpectedDecl VisitUsingDecl(UsingDecl *D)
ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D)
ExpectedStmt VisitStmt(Stmt *S)
ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D)
ExpectedDecl VisitFieldDecl(FieldDecl *D)
Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To)
Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD=nullptr)
ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E)
ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E)
ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S)
ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D)
ExpectedStmt VisitShuffleVectorExpr(ShuffleVectorExpr *E)
ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D)
ExpectedDecl VisitRecordDecl(RecordDecl *D)
ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E)
ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D)
Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin)
ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S)
T importChecked(Error &Err, const T &From)
ExpectedStmt VisitVAArgExpr(VAArgExpr *E)
ExpectedStmt VisitDefaultStmt(DefaultStmt *S)
ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D)
ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E)
ExpectedDecl VisitLabelDecl(LabelDecl *D)
ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E)
ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S)
ExpectedStmt VisitUnaryOperator(UnaryOperator *E)
Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD)
Error ImportDeclContext(DeclContext *FromDC, bool ForceImport=false)
ExpectedStmt VisitContinueStmt(ContinueStmt *S)
ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E)
ExpectedDecl VisitVarDecl(VarDecl *D)
ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E)
ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D)
Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To)
ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E)
ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E)
ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D)
ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D)
ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E)
ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE)
ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E)
ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D)
ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E)
ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D)
Expected< InheritedConstructor > ImportInheritedConstructor(const InheritedConstructor &From)
ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E)
Error ImportDeclParts(NamedDecl *D, DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc)
Error ImportDefinition(RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind=IDK_Default)
ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S)
ExpectedStmt VisitConstantExpr(ConstantExpr *E)
ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E)
ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E)
ExpectedDecl VisitDecl(Decl *D)
bool hasSameVisibilityContextAndLinkage(T *Found, T *From)
ExpectedStmt VisitParenExpr(ParenExpr *E)
ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S)
ExpectedStmt VisitSourceLocExpr(SourceLocExpr *E)
ExpectedStmt VisitInitListExpr(InitListExpr *E)
Expected< FunctionTemplateAndArgsTy > ImportFunctionTemplateWithTemplateArgsFromSpecialization(FunctionDecl *FromFD)
ExpectedStmt VisitReturnStmt(ReturnStmt *S)
ExpectedStmt VisitAtomicExpr(AtomicExpr *E)
ExpectedStmt VisitConditionalOperator(ConditionalOperator *E)
ExpectedStmt VisitChooseExpr(ChooseExpr *E)
ExpectedStmt VisitCompoundStmt(CompoundStmt *S)
Expected< TemplateArgument > ImportTemplateArgument(const TemplateArgument &From)
ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E)
ExpectedStmt VisitCaseStmt(CaseStmt *S)
ExpectedStmt VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *E)
ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E)
ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D)
ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E)
ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E)
ExpectedStmt VisitLambdaExpr(LambdaExpr *LE)
ExpectedStmt VisitBinaryOperator(BinaryOperator *E)
ExpectedStmt VisitCallExpr(CallExpr *E)
ExpectedStmt VisitDeclStmt(DeclStmt *S)
ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E)
ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E)
Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin)
ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D)
ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D)
Expected< CXXCastPath > ImportCastPath(CastExpr *E)
Expected< APValue > ImportAPValue(const APValue &FromValue)
ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D)
ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E)
ExpectedDecl VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D)
ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E)
ExpectedDecl VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D)
ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias)
ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D)
ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D)
ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D)
Expected< ObjCTypeParamList * > ImportObjCTypeParamList(ObjCTypeParamList *list)
ExpectedDecl VisitUsingPackDecl(UsingPackDecl *D)
ExpectedStmt VisitWhileStmt(WhileStmt *S)
ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D)
ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E)
ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S)
ExpectedDecl VisitFriendDecl(FriendDecl *D)
Error ImportContainerChecked(const InContainerTy &InContainer, OutContainerTy &OutContainer)
ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E)
ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E)
bool IsStructuralMatch(Decl *From, Decl *To, bool Complain=true, bool IgnoreTemplateParmDepth=false)
ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E)
ExpectedStmt VisitForStmt(ForStmt *S)
ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E)
ExpectedDecl VisitEnumDecl(EnumDecl *D)
ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D)
ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E)
ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E)
ExpectedStmt VisitSwitchStmt(SwitchStmt *S)
ExpectedType VisitType(const Type *T)
ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D)
ExpectedDecl ImportUsingShadowDecls(BaseUsingDecl *D, BaseUsingDecl *ToSI)
ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E)
ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E)
ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D)
ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E)
ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D)
ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E)
ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E)
ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D)
Error ImportTemplateArguments(ArrayRef< TemplateArgument > FromArgs, SmallVectorImpl< TemplateArgument > &ToArgs)
ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D)
ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E)
ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D)
ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D)
ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E)
ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E)
Error ImportTemplateArgumentListInfo(const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo)
ExpectedStmt VisitDoStmt(DoStmt *S)
ExpectedStmt VisitNullStmt(NullStmt *S)
ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E)
ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D)
Error ImportOverriddenMethods(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod)
ExpectedStmt VisitStringLiteral(StringLiteral *E)
Error ImportDeclarationNameLoc(const DeclarationNameInfo &From, DeclarationNameInfo &To)
ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E)
bool hasReturnTypeDeclaredInside(FunctionDecl *D)
This function checks if the given function has a return type that contains a reference (in any way) t...
ASTNodeImporter(ASTImporter &Importer)
std::tuple< FunctionTemplateDecl *, TemplateArgsTy > FunctionTemplateAndArgsTy
ExpectedDecl VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D)
ExpectedStmt VisitMemberExpr(MemberExpr *E)
ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E)
Error ImportInitializer(VarDecl *From, VarDecl *To)
ImportDefinitionKind
What we should import from the definition.
@ IDK_Everything
Import everything.
@ IDK_Default
Import the default subset of the definition, which might be nothing (if minimal import is set) or mig...
@ IDK_Basic
Import only the bare bones needed to establish a valid DeclContext.
ExpectedDecl VisitTypedefDecl(TypedefDecl *D)
ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D)
ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E)
ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D)
ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E)
ExpectedStmt VisitIfStmt(IfStmt *S)
ExpectedStmt VisitLabelStmt(LabelStmt *S)
ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E)
ExpectedStmt VisitConvertVectorExpr(ConvertVectorExpr *E)
ExpectedDecl VisitUsingEnumDecl(UsingEnumDecl *D)
ExpectedStmt VisitGotoStmt(GotoStmt *S)
ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E)
ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S)
ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S)
ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D)
ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S)
ExpectedDecl VisitImportDecl(ImportDecl *D)
Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD)
ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E)
ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E)
ExpectedDecl VisitEmptyDecl(EmptyDecl *D)
ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E)
ExpectedStmt VisitExpr(Expr *E)
Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam, ParmVarDecl *ToParam)
ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E)
ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S)
ExpectedStmt VisitAttributedStmt(AttributedStmt *S)
ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S)
ExpectedStmt VisitParenListExpr(ParenListExpr *E)
Expected< FunctionDecl * > FindFunctionTemplateSpecialization(FunctionDecl *FromFD)
ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D)
ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S)
Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD)
ExpectedStmt VisitStmtExpr(StmtExpr *E)
ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E)
bool shouldForceImportDeclContext(ImportDefinitionKind IDK)
ExpectedDecl VisitBindingDecl(BindingDecl *D)
ExpectedStmt VisitBreakStmt(BreakStmt *S)
SourceLocation getColonLoc() const
Definition: Expr.h:4221
SourceLocation getQuestionLoc() const
Definition: Expr.h:4220
Represents an access specifier followed by colon ':'.
Definition: DeclCXX.h:86
SourceLocation getColonLoc() const
The location of the colon following the access specifier.
Definition: DeclCXX.h:108
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition: Expr.h:4390
SourceLocation getAmpAmpLoc() const
Definition: Expr.h:4405
LabelDecl * getLabel() const
Definition: Expr.h:4413
SourceLocation getLabelLoc() const
Definition: Expr.h:4407
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Definition: Type.h:3310
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition: Expr.h:5605
Represents a loop initializing the elements of an array.
Definition: Expr.h:5552
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition: Expr.h:5572
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition: Expr.h:5567
Represents a constant array type that does not decay to a pointer when used as a function parameter.
Definition: Type.h:3700
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2716
SourceLocation getRBracketLoc() const
Definition: Expr.h:2764
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Definition: Expr.h:2745
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition: ExprCXX.h:2848
uint64_t getValue() const
Definition: ExprCXX.h:2894
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition: ExprCXX.h:2892
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:2886
ArrayTypeTrait getTrait() const
Definition: ExprCXX.h:2888
Expr * getDimensionExpression() const
Definition: ExprCXX.h:2896
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.h:2885
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3530
QualType getElementType() const
Definition: Type.h:3542
A structure for storing the information associated with a name that has been assumed to be a template...
DeclarationName getDeclName() const
Get the name of the template.
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition: Expr.h:6478
SourceLocation getRParenLoc() const
Definition: Expr.h:6583
static unsigned getNumSubExprs(AtomicOp Op)
Determine the number of arguments the specified atomic builtin should have.
Definition: Expr.cpp:5015
AtomicOp getOp() const
Definition: Expr.h:6542
Expr ** getSubExprs()
Definition: Expr.h:6555
SourceLocation getBuiltinLoc() const
Definition: Expr.h:6582
Attr - This represents one attribute.
Definition: Attr.h:46
Attr * clone(ASTContext &C) const
attr::Kind getKind() const
Definition: Attr.h:92
void setPackExpansion(bool PE)
Definition: Attr.h:108
void setImplicit(bool I)
Definition: Attr.h:106
void setAttrName(const IdentifierInfo *AttrNameII)
const IdentifierInfo * getAttrName() const
Represents an attribute applied to a statement.
Definition: Stmt.h:2080
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: Stmt.cpp:425
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:5616
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:5993
Represents a C++ declaration that introduces decls from somewhere else.
Definition: DeclCXX.h:3417
void addShadowDecl(UsingShadowDecl *S)
Definition: DeclCXX.cpp:3142
shadow_range shadows() const
Definition: DeclCXX.h:3483
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition: Expr.h:4293
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Definition: Expr.h:4340
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condnition evaluates to false;...
Definition: Expr.h:4347
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition: Expr.h:4328
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition: Expr.h:4331
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
Definition: Expr.h:4335
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3892
SourceLocation getOperatorLoc() const
Definition: Expr.h:3933
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Definition: Expr.cpp:4843
Opcode getOpcode() const
Definition: Expr.h:3936
FPOptionsOverride getFPFeatures() const
Definition: Expr.h:4098
Expr * getRHS() const
Definition: Expr.h:3943
Expr * getLHS() const
Definition: Expr.h:3941
A binding in a decomposition declaration.
Definition: DeclCXX.h:4107
void setBinding(QualType DeclaredType, Expr *Binding)
Set the binding for this BindingDecl, along with its declared type (which should be a possibly-cv-qua...
Definition: DeclCXX.h:4144
void setDecomposedDecl(ValueDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition: DeclCXX.h:4150
ValueDecl * getDecomposedDecl() const
Get the decomposition declaration that this binding represents a decomposition of.
Definition: DeclCXX.h:4135
Expr * getBinding() const
Get the expression to which this declaration is bound.
Definition: DeclCXX.h:4131
A fixed int type of a specified bitwidth.
Definition: Type.h:7254
Pointer to a block type.
Definition: Type.h:3361
BreakStmt - This represents a break.
Definition: Stmt.h:2980
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition: ExprCXX.h:5293
Represents the builtin template declaration which is used to implement __make_integer_seq and other b...
BuiltinTemplateKind getBuiltinTemplateKind() const
This class is used for builtin types like 'int'.
Definition: Type.h:2989
static CStyleCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *BasePath, FPOptionsOverride FPO, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation R)
Definition: Expr.cpp:2160
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
TypeSourceInfo * getTypeSourceInfo() const
Retrieves the type and source location of the base class.
Definition: DeclCXX.h:254
AccessSpecifier getAccessSpecifierAsWritten() const
Retrieves the access specifier as written in the source code (which may mean that no access specifier...
Definition: DeclCXX.h:242
SourceLocation getEllipsisLoc() const
For a pack expansion, determine the location of the ellipsis.
Definition: DeclCXX.h:221
bool isVirtual() const
Determines whether the base class is a virtual base class (or not).
Definition: DeclCXX.h:203
bool isBaseOfClass() const
Determine whether this base class is a base of a class declared with the 'class' keyword (vs.
Definition: DeclCXX.h:207
SourceRange getSourceRange() const LLVM_READONLY
Retrieves the source range that contains the entire base specifier.
Definition: DeclCXX.h:193
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1487
const Expr * getSubExpr() const
Definition: ExprCXX.h:1509
static CXXBindTemporaryExpr * Create(const ASTContext &C, CXXTemporary *Temp, Expr *SubExpr)
Definition: ExprCXX.cpp:1048
CXXTemporary * getTemporary()
Definition: ExprCXX.h:1505
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition: ExprCXX.h:720
bool getValue() const
Definition: ExprCXX.h:737
static CXXBoolLiteralExpr * Create(const ASTContext &C, bool Val, QualType Ty, SourceLocation Loc)
Definition: ExprCXX.h:732
SourceLocation getLocation() const
Definition: ExprCXX.h:743
CXXCatchStmt - This represents a C++ catch block.
Definition: StmtCXX.h:28
static CXXConstCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, Expr *Op, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:826
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1542
SourceRange getParenOrBraceRange() const
Definition: ExprCXX.h:1710
void setIsImmediateEscalating(bool Set)
Definition: ExprCXX.h:1704
bool isElidable() const
Whether this construction is elidable.
Definition: ExprCXX.h:1611
bool hadMultipleCandidates() const
Whether the referred constructor was resolved from an overloaded set having size greater than 1.
Definition: ExprCXX.h:1616
static CXXConstructExpr * Create(const ASTContext &Ctx, QualType Ty, SourceLocation Loc, CXXConstructorDecl *Ctor, bool Elidable, ArrayRef< Expr * > Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization, CXXConstructionKind ConstructKind, SourceRange ParenOrBraceRange)
Create a C++ construction expression.
Definition: ExprCXX.cpp:1110
arg_range arguments()
Definition: ExprCXX.h:1666
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition: ExprCXX.h:1635
bool isImmediateEscalating() const
Definition: ExprCXX.h:1700
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
Definition: ExprCXX.h:1644
SourceLocation getLocation() const
Definition: ExprCXX.h:1607
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition: ExprCXX.h:1624
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition: ExprCXX.h:1682
CXXConstructionKind getConstructionKind() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition: ExprCXX.h:1653
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition: ExprCXX.h:1605
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2535
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2862
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2300
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition: DeclCXX.h:2400
IndirectFieldDecl * getIndirectMember() const
Definition: DeclCXX.h:2454
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition: DeclCXX.h:2440
SourceLocation getRParenLoc() const
Definition: DeclCXX.h:2499
SourceLocation getEllipsisLoc() const
Definition: DeclCXX.h:2410
SourceLocation getLParenLoc() const
Definition: DeclCXX.h:2498
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition: DeclCXX.h:2405
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition: DeclCXX.h:2378
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition: DeclCXX.h:2372
Expr * getInit() const
Get the initializer.
Definition: DeclCXX.h:2502
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition: DeclCXX.h:2434
bool isIndirectMemberInitializer() const
Definition: DeclCXX.h:2384
SourceLocation getMemberLocation() const
Definition: DeclCXX.h:2460
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition: DeclCXX.h:2426
Represents a C++ deduction guide declaration.
Definition: DeclCXX.h:1952
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1264
const ParmVarDecl * getParam() const
Definition: ExprCXX.h:1306
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
Definition: ExprCXX.h:1338
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition: ExprCXX.cpp:969
const DeclContext * getUsedContext() const
Definition: ExprCXX.h:1334
bool hasRewrittenInit() const
Definition: ExprCXX.h:1309
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1371
static CXXDefaultInitExpr * Create(const ASTContext &Ctx, SourceLocation Loc, FieldDecl *Field, DeclContext *UsedContext, Expr *RewrittenInitExpr)
Field is the non-static data member whose default initializer is used by this expression.
Definition: ExprCXX.cpp:1023
bool hasRewrittenInit() const
Definition: ExprCXX.h:1400
SourceLocation getBeginLoc() const
Definition: ExprCXX.h:1435
const Expr * getRewrittenExpr() const
Retrieve the initializing expression with evaluated immediate calls, if any.
Definition: ExprCXX.h:1416
const DeclContext * getUsedContext() const
Definition: ExprCXX.h:1428
FieldDecl * getField()
Get the field whose initializer will be used.
Definition: ExprCXX.h:1405
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition: ExprCXX.h:2493
Expr * getArgument()
Definition: ExprCXX.h:2534
bool isArrayForm() const
Definition: ExprCXX.h:2519
SourceLocation getBeginLoc() const
Definition: ExprCXX.h:2543
FunctionDecl * getOperatorDelete() const
Definition: ExprCXX.h:2532
bool isGlobalDelete() const
Definition: ExprCXX.h:2518
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition: ExprCXX.h:2528
bool isArrayFormAsWritten() const
Definition: ExprCXX.h:2520
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition: ExprCXX.h:3676
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition: ExprCXX.h:3779
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition: ExprCXX.h:3782
static CXXDependentScopeMemberExpr * Create(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:1484
const DeclarationNameInfo & getMemberNameInfo() const
Retrieve the name of the member that this expression refers to.
Definition: ExprCXX.h:3813
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:3834
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition: ExprCXX.h:3826
Expr * getBase() const
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition: ExprCXX.h:3770
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: ExprCXX.h:3881
bool hasExplicitTemplateArgs() const
Determines whether this member expression actually had a C++ template argument list explicitly specif...
Definition: ExprCXX.h:3853
SourceLocation getMemberLoc() const
Definition: ExprCXX.h:3822
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:3842
DeclarationName getMember() const
Retrieve the name of the member that this expression refers to.
Definition: ExprCXX.h:3818
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the member name, with source location information.
Definition: ExprCXX.h:3793
bool isImplicitAccess() const
True if this is an implicit access, i.e.
Definition: ExprCXX.h:3762
NamedDecl * getFirstQualifierFoundInScope() const
Retrieve the first part of the nested-name-specifier that was found in the scope of the member access...
Definition: ExprCXX.h:3806
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2799
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg)
Definition: DeclCXX.cpp:2870
static CXXDynamicCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:738
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:4833
UnresolvedLookupExpr * getCallee() const
Definition: ExprCXX.h:4864
Expr * getRHS() const
Definition: ExprCXX.h:4868
Expr * getLHS() const
Definition: ExprCXX.h:4867
SourceLocation getLParenLoc() const
Definition: ExprCXX.h:4884
SourceLocation getEllipsisLoc() const
Definition: ExprCXX.h:4886
std::optional< unsigned > getNumExpansions() const
Definition: ExprCXX.h:4889
SourceLocation getRParenLoc() const
Definition: ExprCXX.h:4885
BinaryOperatorKind getOperator() const
Definition: ExprCXX.h:4887
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition: StmtCXX.h:135
static CXXFunctionalCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, TypeSourceInfo *Written, CastKind Kind, Expr *Op, const CXXCastPath *Path, FPOptionsOverride FPO, SourceLocation LPLoc, SourceLocation RPLoc)
Definition: ExprCXX.cpp:852
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1733
bool constructsVBase() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition: ExprCXX.h:1774
SourceLocation getLocation() const LLVM_READONLY
Definition: ExprCXX.h:1786
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Definition: ExprCXX.h:1770
bool inheritedFromVBase() const
Determine whether the inherited constructor is inherited from a virtual base of the object we constru...
Definition: ExprCXX.h:1784
Represents a call to a member function that may be written either with member call syntax (e....
Definition: ExprCXX.h:176
static CXXMemberCallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RP, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0)
Definition: ExprCXX.cpp:626
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2060
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition: DeclCXX.cpp:2509
overridden_method_range overridden_methods() const
Definition: DeclCXX.cpp:2534
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:2156
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition: ExprCXX.h:372
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition: ExprCXX.h:403
SourceRange getAngleBrackets() const LLVM_READONLY
Definition: ExprCXX.h:410
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition: ExprCXX.h:406
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition: ExprCXX.h:2236
SourceRange getDirectInitRange() const
Definition: ExprCXX.h:2476
CXXNewInitializationStyle getInitializationStyle() const
The kind of initializer this new-expression has.
Definition: ExprCXX.h:2403
bool passAlignment() const
Indicates whether the required alignment should be implicitly passed to the allocation function.
Definition: ExprCXX.h:2427
unsigned getNumPlacementArgs() const
Definition: ExprCXX.h:2374
Expr * getInitializer()
The initializer of this new-expression.
Definition: ExprCXX.h:2409
TypeSourceInfo * getAllocatedTypeSourceInfo() const
Definition: ExprCXX.h:2318
SourceRange getSourceRange() const
Definition: ExprCXX.h:2477
SourceRange getTypeIdParens() const
Definition: ExprCXX.h:2392
llvm::iterator_range< arg_iterator > placement_arguments()
Definition: ExprCXX.h:2439
FunctionDecl * getOperatorDelete() const
Definition: ExprCXX.h:2341
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition: ExprCXX.h:2432
bool isGlobalNew() const
Definition: ExprCXX.h:2397
FunctionDecl * getOperatorNew() const
Definition: ExprCXX.h:2339
std::optional< Expr * > getArraySize()
This might return std::nullopt even if isArray() returns true, since there might not be an array size...
Definition: ExprCXX.h:2349
static CXXNewExpr * Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef< Expr * > PlacementArgs, SourceRange TypeIdParens, std::optional< Expr * > ArraySize, CXXNewInitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange)
Create a c++ new expression.
Definition: ExprCXX.cpp:245
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition: ExprCXX.h:4119
bool getValue() const
Definition: ExprCXX.h:4142
Expr * getOperand() const
Definition: ExprCXX.h:4136
SourceLocation getEndLoc() const
Definition: ExprCXX.h:4139
SourceLocation getBeginLoc() const
Definition: ExprCXX.h:4138
The null pointer literal (C++11 [lex.nullptr])
Definition: ExprCXX.h:765
SourceLocation getLocation() const
Definition: ExprCXX.h:779
static CXXOperatorCallExpr * Create(const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation OperatorLoc, FPOptionsOverride FPFeatures, ADLCallKind UsesADL=NotADL)
Definition: ExprCXX.cpp:562
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition: ExprCXX.h:2612
bool isArrow() const
Determine whether this pseudo-destructor expression was written using an '->' (otherwise,...
Definition: ExprCXX.h:2676
SourceLocation getTildeLoc() const
Retrieve the location of the '~'.
Definition: ExprCXX.h:2697
TypeSourceInfo * getScopeTypeInfo() const
Retrieve the scope type in a qualified pseudo-destructor expression.
Definition: ExprCXX.h:2690
NestedNameSpecifierLoc getQualifierLoc() const
Retrieves the nested-name-specifier that qualifies the type name, with source-location information.
Definition: ExprCXX.h:2665
SourceLocation getDestroyedTypeLoc() const
Retrieve the starting location of the type being destroyed.
Definition: ExprCXX.h:2721
const IdentifierInfo * getDestroyedTypeIdentifier() const
In a dependent pseudo-destructor expression for which we do not have full type information on the des...
Definition: ExprCXX.h:2713
SourceLocation getColonColonLoc() const
Retrieve the location of the '::' in a qualified pseudo-destructor expression.
Definition: ExprCXX.h:2694
SourceLocation getOperatorLoc() const
Retrieve the location of the '.' or '->' operator.
Definition: ExprCXX.h:2679
TypeSourceInfo * getDestroyedTypeInfo() const
Retrieve the source location information for the type being destroyed.
Definition: ExprCXX.h:2706
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
CXXRecordDecl * getMostRecentDecl()
Definition: DeclCXX.h:540
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
Definition: DeclCXX.cpp:1876
method_range methods() const
Definition: DeclCXX.h:661
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, unsigned DependencyKind, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
Definition: DeclCXX.cpp:148
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
Definition: DeclCXX.cpp:1905
void setInstantiationOfMemberClass(CXXRecordDecl *RD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member class RD.
Definition: DeclCXX.cpp:1888
CXXRecordDecl * getPreviousDecl()
Definition: DeclCXX.h:531
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition: DeclCXX.cpp:1901
void setLambdaNumbering(LambdaNumbering Numbering)
Set the mangling numbers and context declaration for a lambda class.
Definition: DeclCXX.cpp:1691
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
Definition: DeclCXX.cpp:1883
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition: DeclCXX.cpp:1916
CXXRecordDecl * getDefinition() const
Definition: DeclCXX.h:564
static CXXReinterpretCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:803
A rewritten comparison expression that was originally written using operator syntax.
Definition: ExprCXX.h:283
bool isReversed() const
Determine whether this expression was rewritten in reverse form.
Definition: ExprCXX.h:319
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
Definition: ExprCXX.h:301
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type.
Definition: ExprCXX.h:2177
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:2196
SourceLocation getRParenLoc() const
Definition: ExprCXX.h:2200
static CXXStaticCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, FPOptionsOverride FPO, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:712
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition: ExprCXX.h:797
Represents a C++ functional cast expression that builds a temporary object.
Definition: ExprCXX.h:1881
static CXXTemporaryObjectExpr * Create(const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty, TypeSourceInfo *TSI, ArrayRef< Expr * > Args, SourceRange ParenOrBraceRange, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization)
Definition: ExprCXX.cpp:1076
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:1910
Represents a C++ temporary.
Definition: ExprCXX.h:1453
const CXXDestructorDecl * getDestructor() const
Definition: ExprCXX.h:1464
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition: ExprCXX.cpp:1043
Represents the this expression in C++.
Definition: ExprCXX.h:1148
bool isImplicit() const
Definition: ExprCXX.h:1171
static CXXThisExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType Ty, bool IsImplicit)
Definition: ExprCXX.cpp:1519
SourceLocation getLocation() const
Definition: ExprCXX.h:1165
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:1202
const Expr * getSubExpr() const
Definition: ExprCXX.h:1222
SourceLocation getThrowLoc() const
Definition: ExprCXX.h:1225
bool isThrownVariableInScope() const
Determines whether the variable thrown by this expression (if any!) is within the innermost try block...
Definition: ExprCXX.h:1232
CXXTryStmt - A C++ try block, including all handlers.
Definition: StmtCXX.h:69
static CXXTryStmt * Create(const ASTContext &C, SourceLocation tryLoc, CompoundStmt *tryBlock, ArrayRef< Stmt * > handlers)
Definition: StmtCXX.cpp:25
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition: ExprCXX.h:845
TypeSourceInfo * getTypeOperandSourceInfo() const
Retrieve source information for the type operand.
Definition: ExprCXX.h:888
bool isTypeOperand() const
Definition: ExprCXX.h:881
SourceRange getSourceRange() const LLVM_READONLY
Definition: ExprCXX.h:899
Expr * getExprOperand() const
Definition: ExprCXX.h:892
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition: ExprCXX.h:3550
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses ('(') that precedes the argument list.
Definition: ExprCXX.h:3594
bool isListInitialization() const
Determine whether this expression models list-initialization.
Definition: ExprCXX.h:3605
static CXXUnresolvedConstructExpr * Create(const ASTContext &Context, QualType T, TypeSourceInfo *TSI, SourceLocation LParenLoc, ArrayRef< Expr * > Args, SourceLocation RParenLoc, bool IsListInit)
Definition: ExprCXX.cpp:1422
TypeSourceInfo * getTypeSourceInfo() const
Retrieve the type source information for the type being constructed.
Definition: ExprCXX.h:3588
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (')') that follows the argument list.
Definition: ExprCXX.h:3599
unsigned getNumArgs() const
Retrieve the number of arguments.
Definition: ExprCXX.h:3608
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2872
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
Definition: Expr.cpp:1549
ADLCallKind getADLCallKind() const
Definition: Expr.h:3026
FPOptionsOverride getFPFeatures() const
Definition: Expr.h:3154
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition: Expr.h:3050
arg_range arguments()
Definition: Expr.h:3111
SourceLocation getRParenLoc() const
Definition: Expr.h:3182
Expr * getCallee()
Definition: Expr.h:3022
CaseStmt - Represent a case statement.
Definition: Stmt.h:1801
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Definition: Stmt.cpp:1220
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3535
path_iterator path_begin()
Definition: Expr.h:3605
CastKind getCastKind() const
Definition: Expr.h:3579
Expr * getSubExpr()
Definition: Expr.h:3585
path_iterator path_end()
Definition: Expr.h:3606
FPOptionsOverride getFPFeatures() const
Definition: Expr.h:3650
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
SourceLocation getLocation() const
Definition: Expr.h:1602
unsigned getValue() const
Definition: Expr.h:1610
CharacterLiteralKind getKind() const
Definition: Expr.h:1603
How to handle import errors that occur when import of a child declaration of a DeclContext fails.
bool ignoreChildErrorOnParent(Decl *FromChildD) const
Determine if import failure of a child does not cause import failure of its parent.
ChildErrorHandlingStrategy(const Decl *FromD)
void handleChildImportResult(Error &ResultErr, Error &&ChildErr)
Process the import result of a child (of the current declaration).
ChildErrorHandlingStrategy(const DeclContext *FromDC)
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition: Expr.h:4610
Expr * getCond() const
Definition: Expr.h:4650
SourceLocation getBuiltinLoc() const
Definition: Expr.h:4657
bool isConditionDependent() const
Definition: Expr.h:4640
bool isConditionTrue() const
isConditionTrue - Return whether the condition is true (i.e.
Definition: Expr.h:4633
SourceLocation getRParenLoc() const
Definition: Expr.h:4660
Expr * getLHS() const
Definition: Expr.h:4652
Expr * getRHS() const
Definition: Expr.h:4654
Declaration of a class template.
void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, void *InsertPos)
Insert the specified partial specialization knowing that it is not already in.
ClassTemplateDecl * getMostRecentDecl()
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
ClassTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, TemplateParameterList *TPL, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary class pattern.
void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
QualType getInjectedClassNameSpecialization()
Retrieve the template specialization type of the injected-class-name for this class template.
ClassTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
QualType getInjectedSpecializationType() const
Retrieves the injected specialization type for this partial specialization.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a class template specialization, which refers to a class template with a given set of temp...
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getInstantiatedFrom() const
If this class template specialization is an instantiation of a template (rather than an explicit spec...
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
void setPointOfInstantiation(SourceLocation Loc)
const TemplateArgumentList & getTemplateInstantiationArgs() const
Retrieve the set of template arguments that should be used to instantiate members of the class templa...
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
void setExternKeywordLoc(SourceLocation Loc)
Sets the location of the extern keyword.
void setSpecializationKind(TemplateSpecializationKind TSK)
SourceLocation getExternKeywordLoc() const
Gets the location of the extern keyword, if present.
SourceLocation getTemplateKeywordLoc() const
Gets the location of the template keyword, if present.
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this class template specialization is actually an instantiation of the given class template...
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
Complex values, per C99 6.2.5p11.
Definition: Type.h:3098
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4140
QualType getComputationLHSType() const
Definition: Expr.h:4174
static CompoundAssignOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures, QualType CompLHSType=QualType(), QualType CompResultType=QualType())
Definition: Expr.cpp:4865
QualType getComputationResultType() const
Definition: Expr.h:4177
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3465
SourceLocation getLParenLoc() const
Definition: Expr.h:3495
TypeSourceInfo * getTypeSourceInfo() const
Definition: Expr.h:3498
bool isFileScope() const
Definition: Expr.h:3492
const Expr * getInitializer() const
Definition: Expr.h:3488
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1606
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Definition: Stmt.cpp:383
A reference to a concept and its template args, as it appears in the code.
Definition: ASTConcept.h:128
const DeclarationNameInfo & getConceptNameInfo() const
Definition: ASTConcept.h:171
NamedDecl * getFoundDecl() const
Definition: ASTConcept.h:199
ConceptDecl * getNamedConcept() const
Definition: ASTConcept.h:203
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition: ASTConcept.h:207
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
Definition: ASTConcept.h:167
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
Definition: ASTConcept.cpp:94
SourceLocation getTemplateKWLoc() const
Definition: ASTConcept.h:177
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:4231
Expr * getLHS() const
Definition: Expr.h:4265
Expr * getCond() const
getCond - Return the expression representing the condition for the ?: operator.
Definition: Expr.h:4254
Expr * getRHS() const
Definition: Expr.h:4266
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3568
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition: Expr.h:1072
APValue getAPValueResult() const
Definition: Expr.cpp:413
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition: Expr.cpp:350
Represents a concrete matrix type with constant number of rows and columns.
Definition: Type.h:4179
Represents a shadow constructor declaration introduced into a class by a C++11 using-declaration that...
Definition: DeclCXX.h:3598
ContinueStmt - This represents a continue.
Definition: Stmt.h:2950
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition: Expr.h:4551
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition: Expr.h:4585
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition: Expr.h:4571
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_convertvector token.
Definition: Expr.h:4582
TypeSourceInfo * getTypeSourceInfo() const
getTypeSourceInfo - Return the destination type.
Definition: Expr.h:4574
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
Definition: Type.h:3259
Represents a pointer type decayed from an array or function type.
Definition: Type.h:3344
A POD class for pairing a NamedDecl* with an access specifier.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
NamedDecl * getDecl() const
AccessSpecifier getAccess() const
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1369
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1436
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
Definition: DeclBase.cpp:1993
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1282
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2066
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1802
bool isRecord() const
Definition: DeclBase.h:2146
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1938
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
Definition: DeclBase.cpp:1724
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1590
void removeDecl(Decl *D)
Removes a declaration from this context.
Definition: DeclBase.cpp:1635
lookup_result noload_lookup(DeclarationName Name)
Find the declarations with the given name that are visible within this context; don't attempt to retr...
Definition: DeclBase.cpp:1867
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1585
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition: DeclBase.h:2637
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:2322
bool isFunctionOrMethod() const
Definition: DeclBase.h:2118
void localUncachedLookup(DeclarationName Name, SmallVectorImpl< NamedDecl * > &Results)
A simplistic name lookup mechanism that performs name lookup into this declaration context without co...
Definition: DeclBase.cpp:1899
static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls)
Definition: DeclGroup.h:68
iterator begin()
Definition: DeclGroup.h:99
iterator end()
Definition: DeclGroup.h:105
bool isNull() const
Definition: DeclGroup.h:79
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1260
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list.
Definition: Expr.h:1409
ValueDecl * getDecl()
Definition: Expr.h:1328
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Definition: Expr.h:1458
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: Expr.h:1381
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
Definition: Expr.cpp:488
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: Expr.h:1389
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: Expr.h:1435
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
Definition: Expr.h:1347
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
Definition: Expr.h:1365
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition: Expr.h:1452
bool hadMultipleCandidates() const
Returns true if this expression refers to a function that was resolved from an overloaded set having ...
Definition: Expr.h:1441
SourceLocation getLocation() const
Definition: Expr.h:1336
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: Expr.h:1397
bool isImmediateEscalating() const
Definition: Expr.h:1462
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1497
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:67
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:441
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition: DeclBase.h:1216
bool hasAttrs() const
Definition: DeclBase.h:524
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:501
void addAttr(Attr *A)
Definition: DeclBase.cpp:991
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:599
bool isInIdentifierNamespace(unsigned NS) const
Definition: DeclBase.h:883
AttrVec & getAttrs()
Definition: DeclBase.h:530
@ FOK_None
Not a friend object.
Definition: DeclBase.h:1207
void setObjectOfFriendDecl(bool PerformFriendInjection=false)
Changes the namespace of this declaration to reflect that it's the object of a friend declaration.
Definition: DeclBase.h:1170
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:968
void setAccess(AccessSpecifier AS)
Definition: DeclBase.h:508
SourceLocation getLocation() const
Definition: DeclBase.h:445
const char * getDeclKindName() const
Definition: DeclBase.cpp:123
IdentifierNamespace
IdentifierNamespace - The different namespaces in which declarations may appear.
Definition: DeclBase.h:115
@ IDNS_NonMemberOperator
This declaration is a C++ operator declared in a non-class context.
Definition: DeclBase.h:168
@ IDNS_TagFriend
This declaration is a friend class.
Definition: DeclBase.h:157
@ IDNS_Ordinary
Ordinary names.
Definition: DeclBase.h:144
@ IDNS_ObjCProtocol
Objective C @protocol.
Definition: DeclBase.h:147
@ IDNS_Namespace
Namespaces, declared with 'namespace foo {}'.
Definition: DeclBase.h:140
@ IDNS_OrdinaryFriend
This declaration is a friend function.
Definition: DeclBase.h:152
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
Definition: DeclBase.h:125
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:908
void setImplicit(bool I=true)
Definition: DeclBase.h:600
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition: DeclBase.h:614
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition: DeclBase.cpp:530
AccessSpecifier getAccess() const
Definition: DeclBase.h:513
bool isInAnonymousNamespace() const
Definition: DeclBase.cpp:393
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:437
TranslationUnitDecl * getTranslationUnitDecl()
Definition: DeclBase.cpp:486
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition: DeclBase.cpp:336
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:340
DeclContext * getDeclContext()
Definition: DeclBase.h:454
DeclarationName getCXXConversionFunctionName(CanQualType Ty)
Returns the name of a C++ conversion function for the given Type.
DeclarationName getCXXDestructorName(CanQualType Ty)
Returns the name of a C++ destructor for the given Type.
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
Get the name of the overloadable C++ operator corresponding to Op.
DeclarationName getCXXDeductionGuideName(TemplateDecl *TD)
Returns the name of a C++ deduction guide for the given template.
DeclarationName getCXXConstructorName(CanQualType Ty)
Returns the name of a C++ constructor for the given Type.
DeclarationName getCXXLiteralOperatorName(const IdentifierInfo *II)
Get the name of the literal operator function with II as the identifier.
The name of a declaration.
const IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it.
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
static DeclarationName getUsingDirectiveName()
Returns the name for all C++ using-directives.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
NameKind getNameKind() const
Determine what kind of name this is.
Expr * getTrailingRequiresClause()
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Definition: Decl.h:847
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition: Decl.h:814
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:823
void setTypeSourceInfo(TypeSourceInfo *TI)
Definition: Decl.h:806
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:2001
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:800
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition: Decl.h:837
Represents the type decltype(expr) (C++11).
Definition: Type.h:5370
A decomposition declaration.
Definition: DeclCXX.h:4166
Represents a C++17 deduced template specialization type.
Definition: Type.h:6041
Represents an extended address space qualifier where the input address space value is dependent.
Definition: Type.h:3871
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:6464
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3316
static DependentScopeDeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:482
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition: ExprCXX.h:3352
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:3390
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition: ExprCXX.h:3364
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:3382
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition: ExprCXX.h:3400
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: ExprCXX.h:3374
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition: ExprCXX.h:3355
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: ExprCXX.h:3424
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:3813
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:3911
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition: Type.h:4238
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:488
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
Definition: TemplateName.h:560
bool isIdentifier() const
Determine whether this template name refers to an identifier.
Definition: TemplateName.h:547
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:550
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:544
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: Type.h:6516
Represents a vector type where either the type or size is dependent.
Definition: Type.h:4033
Represents a single C99 designator.
Definition: Expr.h:5176
unsigned getArrayIndex() const
Definition: Expr.h:5314
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition: Expr.h:5303
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition: Expr.h:5257
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition: Expr.h:5293
SourceLocation getFieldLoc() const
Definition: Expr.h:5284
SourceLocation getRBracketLoc() const
Definition: Expr.h:5332
const IdentifierInfo * getFieldName() const
Definition: Expr.cpp:4602
SourceLocation getEllipsisLoc() const
Definition: Expr.h:5326
SourceLocation getDotLoc() const
Definition: Expr.h:5279
SourceLocation getLBracketLoc() const
Definition: Expr.h:5320
Represents a C99 designated initializer expression.
Definition: Expr.h:5133
Expr * getInit() const
Retrieve the initializer value.
Definition: Expr.h:5401
llvm::MutableArrayRef< Designator > designators()
Definition: Expr.h:5366
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
Definition: Expr.h:5397
static DesignatedInitExpr * Create(const ASTContext &C, llvm::ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition: Expr.cpp:4644
Expr * getSubExpr(unsigned Idx) const
Definition: Expr.h:5415
unsigned size() const
Returns the number of designators in this initializer.
Definition: Expr.h:5363
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
Definition: Expr.h:5388
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression,...
Definition: Expr.h:5413
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1277
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1553
void notePriorDiagnosticFrom(const DiagnosticsEngine &Other)
Note that the prior diagnostic was emitted by some other DiagnosticsEngine, and we may be attaching a...
Definition: Diagnostic.h:902
DoStmt - This represents a 'do/while' stmt.
Definition: Stmt.h:2725
Symbolic representation of a dynamic allocation.
Definition: APValue.h:65
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:6383
Represents an empty-declaration.
Definition: Decl.h:4928
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3300
const Expr * getInitExpr() const
Definition: Decl.h:3318
llvm::APSInt getInitVal() const
Definition: Decl.h:3320
Represents an enum.
Definition: Decl.h:3870
EnumDecl * getMostRecentDecl()
Definition: Decl.h:3966
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:4075
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition: Decl.h:4067
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:4078
void setIntegerType(QualType T)
Set the underlying integer type.
Definition: Decl.h:4039
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition: Decl.h:4129
EnumDecl * getDefinition() const
Definition: Decl.h:3973
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition: Decl.h:4084
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition: Decl.cpp:4882
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:4030
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition: Decl.cpp:4942
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition: Decl.h:4056
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition: Decl.h:4022
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:5587
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:3782
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition: Expr.h:3804
Store information needed for an explicit specifier.
Definition: DeclCXX.h:1897
const Expr * getExpr() const
Definition: DeclCXX.h:1906
ExplicitSpecKind getKind() const
Definition: DeclCXX.h:1905
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3467
bool cleanupsHaveSideEffects() const
Definition: ExprCXX.h:3502
unsigned getNumObjects() const
Definition: ExprCXX.h:3495
ArrayRef< CleanupObject > getObjects() const
Definition: ExprCXX.h:3491
llvm::PointerUnion< BlockDecl *, CompoundLiteralExpr * > CleanupObject
The type of objects that are kept in the cleanup.
Definition: ExprCXX.h:3473
static ExprWithCleanups * Create(const ASTContext &C, EmptyShell empty, unsigned numObjects)
Definition: ExprCXX.cpp:1397
This represents one expression.
Definition: Expr.h:110
void setType(QualType t)
Definition: Expr.h:143
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition: Expr.h:175
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:437
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:192
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
Definition: Expr.h:239
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:444
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:277
QualType getType() const
Definition: Expr.h:142
ExprDependence getDependence() const
Definition: Expr.h:162
An expression trait intrinsic.
Definition: ExprCXX.h:2919
Expr * getQueriedExpression() const
Definition: ExprCXX.h:2958
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.h:2953
ExpressionTrait getTrait() const
Definition: ExprCXX.h:2956
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:2954
ExtVectorType - Extended vector type.
Definition: Type.h:4073
virtual void CompleteType(TagDecl *Tag)
Gives the external AST source an opportunity to complete an incomplete type.
Represents difference between two FPOptions values.
Definition: LangOptions.h:956
Represents a member of a struct/union/class.
Definition: Decl.h:3060
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition: Decl.h:3148
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition: Decl.cpp:4574
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition: Decl.h:3221
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition: Decl.h:3215
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition: Decl.h:3261
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition: Decl.cpp:4584
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition: Decl.h:3164
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition: Decl.cpp:4679
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool isValid() const
bool isInvalid() const
Implements support for file system lookup, file system caching, and directory search management.
Definition: FileManager.h:53
OptionalFileEntryRef getOptionalFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Get a FileEntryRef if it exists, without doing anything on error.
Definition: FileManager.h:240
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition: Expr.h:1562
SourceLocation getLocation() const
Definition: Expr.h:1688
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition: Expr.cpp:1133
llvm::APFloat getValue() const
Definition: Expr.h:1647
bool isExact() const
Definition: Expr.h:1680
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition: Stmt.h:2781
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
Definition: DeclFriend.h:54
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
Definition: DeclFriend.h:137
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
Definition: DeclFriend.h:58
SourceLocation getFriendLoc() const
Retrieves the location of the 'friend' keyword.
Definition: DeclFriend.h:142
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition: DeclFriend.h:122
const Expr * getSubExpr() const
Definition: Expr.h:1052
static DefaultedOrDeletedFunctionInfo * Create(ASTContext &Context, ArrayRef< DeclAccessPair > Lookups, StringLiteral *DeletedMessage=nullptr)
Definition: Decl.cpp:3100
Represents a function declaration or definition.
Definition: Decl.h:1972
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:3240
ConstexprSpecKind getConstexprKind() const
Definition: Decl.h:2441
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition: Decl.cpp:4051
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:4046
void setIsPureVirtual(bool P=true)
Definition: Decl.cpp:3259
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition: Decl.cpp:3121
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition: Decl.h:2614
bool UsesFPIntrin() const
Determine whether the function was declared in source context that requires constrained FP intrinsics...
Definition: Decl.h:2821
SourceLocation getDefaultLoc() const
Definition: Decl.h:2363
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
Definition: Decl.h:2354
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition: Decl.h:2342
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition: Decl.h:2413
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition: Decl.cpp:4025
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition: Decl.cpp:4176
void setDefaultLoc(SourceLocation NewLoc)
Definition: Decl.h:2367
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition: Decl.h:2298
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition: Decl.cpp:4241
@ TK_MemberSpecialization
Definition: Decl.h:1984
@ TK_DependentNonTemplate
Definition: Decl.h:1993
@ TK_FunctionTemplateSpecialization
Definition: Decl.h:1988
@ TK_DependentFunctionTemplateSpecialization
Definition: Decl.h:1991
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:2800
void setTrivial(bool IT)
Definition: Decl.h:2343
bool FriendConstraintRefersToEnclosingTemplate() const
Definition: Decl.h:2620
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition: Decl.cpp:3997
StringLiteral * getDeletedMessage() const
Get the message that indicates why this function was deleted.
Definition: Decl.h:2670
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition: Decl.cpp:4064
bool isDeletedAsWritten() const
Definition: Decl.h:2509
void setDependentTemplateSpecialization(ASTContext &Context, const UnresolvedSetImpl &Templates, const TemplateArgumentListInfo *TemplateArgs)
Specifies that this function declaration is actually a dependent function template specialization.
Definition: Decl.cpp:4230
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Definition: Decl.h:2325
void setVirtualAsWritten(bool V)
State that this function is marked as virtual explicitly.
Definition: Decl.h:2321
void setRangeEnd(SourceLocation E)
Definition: Decl.h:2190
bool isDefaulted() const
Whether this function is defaulted.
Definition: Decl.h:2350
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2686
FunctionDecl * getInstantiatedFromDecl() const
Definition: Decl.cpp:4070
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition: Decl.cpp:4270
void setDefaulted(bool D=true)
Definition: Decl.h:2351
void setBody(Stmt *B)
Definition: Decl.cpp:3252
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition: Decl.h:2316
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition: Decl.cpp:3130
void setExplicitlyDefaulted(bool ED=true)
State that this function is explicitly defaulted.
Definition: Decl.h:2359
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition: Decl.cpp:4018
DeclarationNameInfo getNameInfo() const
Definition: Decl.h:2183
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition: Decl.cpp:3160
FunctionDecl * getDefinition()
Get the definition for this declaration.
Definition: Decl.h:2254
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition: Decl.h:2811
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4623
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4668
QualType desugar() const
Definition: Type.h:5135
ArrayRef< QualType > param_types() const
Definition: Type.h:5056
ArrayRef< QualType > exceptions() const
Definition: Type.h:5070
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:4912
Declaration of a template function.
Definition: DeclTemplate.h:957
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary pattern.
FunctionTemplateDecl * getMostRecentDecl()
ExtInfo getExtInfo() const
Definition: Type.h:4597
QualType getReturnType() const
Definition: Type.h:4585
This represents a GCC inline-assembly statement extension.
Definition: Stmt.h:3259
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition: Expr.h:4685
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:4702
Represents a C11 generic selection.
Definition: Expr.h:5766
ArrayRef< Expr * > getAssocExprs() const
Definition: Expr.h:6061
bool isExprPredicate() const
Whether this generic selection uses an expression as its controlling argument.
Definition: Expr.h:6022
Expr * getControllingExpr()
Return the controlling expression of this generic selection expression.
Definition: Expr.h:6029
SourceLocation getGenericLoc() const
Definition: Expr.h:6119
SourceLocation getRParenLoc() const
Definition: Expr.h:6123
unsigned getResultIndex() const
The zero-based index of the result expression's generic association in the generic selection's associ...
Definition: Expr.h:6011
SourceLocation getDefaultLoc() const
Definition: Expr.h:6122
TypeSourceInfo * getControllingType()
Return the controlling type of this generic selection expression.
Definition: Expr.h:6041
static GenericSelectionExpr * Create(const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, ArrayRef< TypeSourceInfo * > AssocTypes, ArrayRef< Expr * > AssocExprs, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack, unsigned ResultIndex)
Create a non-result-dependent generic selection expression accepting an expression predicate.
Definition: Expr.cpp:4532
bool isResultDependent() const
Whether this generic selection is result-dependent.
Definition: Expr.h:6018
ArrayRef< TypeSourceInfo * > getAssocTypeSourceInfos() const
Definition: Expr.h:6066
GotoStmt - This represents a direct goto.
Definition: Stmt.h:2862
One of these records is kept for each identifier that is lexed.
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
void setBuiltinID(unsigned ID)
StringRef getName() const
Return the actual identifier string.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
IfStmt - This represents an if/then/else.
Definition: Stmt.h:2138
static IfStmt * Create(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LPL, SourceLocation RPL, Stmt *Then, SourceLocation EL=SourceLocation(), Stmt *Else=nullptr)
Create an IfStmt.
Definition: Stmt.cpp:958
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition: Expr.h:1712
const Expr * getSubExpr() const
Definition: Expr.h:1724
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3707
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition: Expr.cpp:2129
ImplicitParamKind getParameterKind() const
Returns the implicit parameter kind.
Definition: Decl.h:1752
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5641
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4802
Represents a C array with an unspecified size.
Definition: Type.h:3715
Represents a field injected from an anonymous union/struct into the parent scope.
Definition: Decl.h:3344
ArrayRef< NamedDecl * > chain() const
Definition: Decl.h:3366
unsigned getChainingSize() const
Definition: Decl.h:3372
IndirectGotoStmt - This represents an indirect goto.
Definition: Stmt.h:2901
Description of a constructor that was inherited from a base class.
Definition: DeclCXX.h:2506
ConstructorUsingShadowDecl * getShadowDecl() const
Definition: DeclCXX.h:2518
CXXConstructorDecl * getConstructor() const
Definition: DeclCXX.h:2519
Describes an C or C++ initializer list.
Definition: Expr.h:4888
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition: Expr.h:5007
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition: Expr.h:4992
void setSyntacticForm(InitListExpr *Init)
Definition: Expr.h:5058
unsigned getNumInits() const
Definition: Expr.h:4918
SourceLocation getLBraceLoc() const
Definition: Expr.h:5042
ArrayRef< Expr * > inits()
Definition: Expr.h:4928
void setArrayFiller(Expr *filler)
Definition: Expr.cpp:2460
bool hadArrayRangeDesignator() const
Definition: Expr.h:5065
SourceLocation getRBraceLoc() const
Definition: Expr.h:5044
void setInitializedFieldInUnion(FieldDecl *FD)
Definition: Expr.h:5013
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition: Expr.h:4982
void sawArrayRangeDesignator(bool ARD=true)
Definition: Expr.h:5068
InitListExpr * getSyntacticForm() const
Definition: Expr.h:5054
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:6233
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition: Expr.cpp:1032
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition: Expr.h:1520
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3436
Represents the declaration of a label.
Definition: Decl.h:500
bool isGnuLocal() const
Definition: Decl.h:527
LabelStmt * getStmt() const
Definition: Decl.h:524
void setStmt(LabelStmt *T)
Definition: Decl.h:525
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:2031
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:25
bool capturesVariable() const
Determine whether this capture handles a variable.
Definition: LambdaCapture.h:88
bool isPackExpansion() const
Determine whether this capture is a pack expansion, which captures a function parameter pack.
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis for a capture that is a pack expansion.
LambdaCaptureKind getCaptureKind() const
Determine the kind of capture.
Definition: ExprCXX.cpp:1196
bool isImplicit() const
Determine whether this was an implicit capture (not written between the square brackets introducing t...
SourceLocation getLocation() const
Retrieve the source location of the capture.
ValueDecl * getCapturedVar() const
Retrieve the declaration of the local variable being captured.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1950
static LambdaExpr * Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, bool ExplicitParams, bool ExplicitResultType, ArrayRef< Expr * > CaptureInits, SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack)
Construct a new lambda expression.
Definition: ExprCXX.cpp:1244
llvm::iterator_range< capture_init_iterator > capture_inits()
Retrieve the initialization expressions for this lambda's captures.
Definition: ExprCXX.h:2065
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:2168
bool hasExplicitParameters() const
Determine whether this lambda has an explicit parameter list vs.
Definition: ExprCXX.h:2153
SourceRange getIntroducerRange() const
Retrieve the source range covering the lambda introducer, which contains the explicit capture list su...
Definition: ExprCXX.h:2101
unsigned capture_size() const
Determine the number of captures in this lambda.
Definition: ExprCXX.h:2031
CXXMethodDecl * getCallOperator() const
Retrieve the function call operator associated with this lambda expression.
Definition: ExprCXX.cpp:1336
bool hasExplicitResultType() const
Whether this lambda had its result type explicitly specified.
Definition: ExprCXX.h:2156
SourceLocation getCaptureDefaultLoc() const
Retrieve the location of this lambda's capture-default, if any.
Definition: ExprCXX.h:2008
LambdaCaptureDefault getCaptureDefault() const
Determine the default capture kind for this lambda.
Definition: ExprCXX.h:2003
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition: ExprCXX.cpp:1332
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
Definition: DeclCXX.h:3229
unsigned getManglingNumber() const
Definition: DeclCXX.h:3278
Expr * getTemporaryExpr()
Retrieve the expression to which the temporary materialization conversion was applied.
Definition: DeclCXX.h:3275
Represents a linkage specification.
Definition: DeclCXX.h:2934
void setRBraceLoc(SourceLocation L)
Definition: DeclCXX.h:2976
LinkageSpecLanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition: DeclCXX.h:2957
SourceLocation getExternLoc() const
Definition: DeclCXX.h:2973
SourceLocation getRBraceLoc() const
Definition: DeclCXX.h:2974
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition: DeclCXX.h:2968
Represents the results of name lookup.
Definition: Lookup.h:46
iterator end() const
Definition: Lookup.h:359
iterator begin() const
Definition: Lookup.h:358
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation.
Definition: Type.h:5254
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4721
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
Definition: ExprCXX.h:4761
bool isBoundToLvalueReference() const
Determine whether this materialized temporary is bound to an lvalue reference; otherwise,...
Definition: ExprCXX.h:4790
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
Definition: ExprCXX.h:4738
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3224
SourceLocation getOperatorLoc() const
Definition: Expr.h:3406
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: Expr.h:3396
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition: Expr.h:3341
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name,...
Definition: Expr.h:3326
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition: Expr.h:3368
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why? This is only meaningful if the named memb...
Definition: Expr.h:3448
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition: Expr.h:3307
static MemberExpr * Create(const ASTContext &C, Expr *Base, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *MemberDecl, DeclAccessPair FoundDecl, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, QualType T, ExprValueKind VK, ExprObjectKind OK, NonOdrUseReason NOUR)
Definition: Expr.cpp:1809
Expr * getBase() const
Definition: Expr.h:3301
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: Expr.h:3357
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: Expr.h:3349
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition: Expr.h:3401
bool isArrow() const
Definition: Expr.h:3408
DeclAccessPair getFoundDecl() const
Retrieves the declaration found by lookup.
Definition: Expr.h:3311
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3472
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:615
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
Definition: DeclTemplate.h:655
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Definition: DeclTemplate.h:660
This represents a decl that may have a name.
Definition: Decl.h:249
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition: Decl.cpp:1169
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:315
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
Represents a C++ namespace alias.
Definition: DeclCXX.h:3120
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition: DeclCXX.h:3183
SourceLocation getAliasLoc() const
Returns the location of the alias name, i.e.
Definition: DeclCXX.h:3205
SourceLocation getNamespaceLoc() const
Returns the location of the namespace keyword.
Definition: DeclCXX.h:3208
SourceLocation getTargetNameLoc() const
Returns the location of the identifier in the named namespace.
Definition: DeclCXX.h:3211
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition: DeclCXX.h:3192
Represent a C++ namespace.
Definition: Decl.h:548
SourceLocation getRBraceLoc() const
Definition: Decl.h:687
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:686
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace nested inside this namespace, if any.
Definition: Decl.h:666
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition: Decl.h:611
bool isNested() const
Returns true if this is a nested namespace declaration.
Definition: Decl.h:628
void setRBraceLoc(SourceLocation L)
Definition: Decl.h:689
Class that aids in the construction of nested-name-specifiers along with source-location information ...
A C++ nested-name-specifier augmented with source location information.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
TypeLoc getTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
NestedNameSpecifierLoc getPrefix() const
Return the prefix of this nested-name-specifier.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, const IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
static NestedNameSpecifier * GlobalSpecifier(const ASTContext &Context)
Returns the nested name specifier representing the global scope.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
SpecifierKind
The kind of specifier that completes this nested name specifier.
@ NamespaceAlias
A namespace alias, stored as a NamespaceAliasDecl*.
@ TypeSpec
A type, stored as a Type*.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Identifier
An identifier, stored as an IdentifierInfo*.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace, stored as a NamespaceDecl*.
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
static NestedNameSpecifier * SuperSpecifier(const ASTContext &Context, CXXRecordDecl *RD)
Returns the nested name specifier representing the __super scope for the given CXXRecordDecl.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
unsigned getDepth() const
Get the nesting depth of the template parameter.
void setDefaultArgument(const ASTContext &C, const TemplateArgumentLoc &DefArg)
Set the default argument for this template parameter, and whether that default argument was inherited...
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition: Stmt.h:1569
Represents Objective-C's @catch statement.
Definition: StmtObjC.h:77
Represents Objective-C's @finally statement.
Definition: StmtObjC.h:127
Represents Objective-C's @synchronized statement.
Definition: StmtObjC.h:303
Represents Objective-C's @throw statement.
Definition: StmtObjC.h:358
Represents Objective-C's @try ... @catch ... @finally statement.
Definition: StmtObjC.h:167
static ObjCAtTryStmt * Create(const ASTContext &Context, SourceLocation atTryLoc, Stmt *atTryStmt, Stmt **CatchStmts, unsigned NumCatchStmts, Stmt *atFinallyStmt)
Definition: StmtObjC.cpp:45
Represents Objective-C's @autoreleasepool Statement.
Definition: StmtObjC.h:394
An Objective-C "bridged" cast expression, which casts between Objective-C pointers and C pointers,...
Definition: ExprObjC.h:1636
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2326
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this category.
Definition: DeclObjC.cpp:2167
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition: DeclObjC.h:2388
ObjCCategoryImplDecl * getImplementation() const
Definition: DeclObjC.cpp:2158
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
Definition: DeclObjC.h:2374
protocol_iterator protocol_end() const
Definition: DeclObjC.h:2408
SourceLocation getIvarLBraceLoc() const
Definition: DeclObjC.h:2461
SourceLocation getIvarRBraceLoc() const
Definition: DeclObjC.h:2463
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:2418
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:2404
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.h:2369
void setImplementation(ObjCCategoryImplDecl *ImplD)
Definition: DeclObjC.cpp:2163
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2397
SourceLocation getCategoryNameLoc() const
Definition: DeclObjC.h:2457
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition: DeclObjC.h:2542
SourceLocation getCategoryNameLoc() const
Definition: DeclObjC.h:2569
ObjCCategoryDecl * getCategoryDecl() const
Definition: DeclObjC.cpp:2199
SourceLocation getAtStartLoc() const
Definition: DeclObjC.h:1095
Represents Objective-C's collection statement.
Definition: StmtObjC.h:23
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:2483
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2594
SourceLocation getIvarRBraceLoc() const
Definition: DeclObjC.h:2741
const ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.h:2732
SourceLocation getSuperClassLoc() const
Definition: DeclObjC.h:2734
SourceLocation getIvarLBraceLoc() const
Definition: DeclObjC.h:2739
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition: DeclObjC.h:1484
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition: DeclObjC.h:1541
bool isImplicitInterfaceDecl() const
isImplicitInterfaceDecl - check that this is an implicitly declared ObjCInterfaceDecl node.
Definition: DeclObjC.h:1891
ObjCCategoryDecl * FindCategoryDeclaration(const IdentifierInfo *CategoryId) const
FindCategoryDeclaration - Finds category declaration in the list of categories for this class and ret...
Definition: DeclObjC.cpp:1748
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:1391
void setImplementation(ObjCImplementationDecl *ImplD)
Definition: DeclObjC.cpp:1642
known_categories_range known_categories() const
Definition: DeclObjC.h:1686
void setSuperClass(TypeSourceInfo *superClass)
Definition: DeclObjC.h:1587
protocol_iterator protocol_end() const
Definition: DeclObjC.h:1373
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
Definition: DeclObjC.cpp:372
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
Definition: DeclObjC.h:1522
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this class.
Definition: DeclObjC.cpp:343
TypeSourceInfo * getSuperClassTInfo() const
Definition: DeclObjC.h:1572
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:1355
ObjCImplementationDecl * getImplementation() const
Definition: DeclObjC.cpp:1629
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class.
Definition: DeclObjC.h:1302
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:1362
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition: DeclObjC.h:1913
void startDefinition()
Starts the definition of this Objective-C class, taking it from a forward declaration (@class) to a d...
Definition: DeclObjC.cpp:616
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:352
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:6964
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1950
AccessControl getAccessControl() const
Definition: DeclObjC.h:1998
bool getSynthesize() const
Definition: DeclObjC.h:2005
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
unsigned param_size() const
Definition: DeclObjC.h:347
bool isPropertyAccessor() const
Definition: DeclObjC.h:436
param_const_iterator param_end() const
Definition: DeclObjC.h:358
param_const_iterator param_begin() const
Definition: DeclObjC.h:354
bool isVariadic() const
Definition: DeclObjC.h:431
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclObjC.cpp:1047
bool isSynthesizedAccessorStub() const
Definition: DeclObjC.h:444
bool hasRelatedResultType() const
Determine whether this method has a result type that is related to the message receiver's type.
Definition: DeclObjC.h:256
ImplicitParamDecl * getSelfDecl() const
Definition: DeclObjC.h:418
void setMethodParams(ASTContext &C, ArrayRef< ParmVarDecl * > Params, ArrayRef< SourceLocation > SelLocs=std::nullopt)
Sets the method's parameters and selector source locations.
Definition: DeclObjC.cpp:944
bool isInstanceMethod() const
Definition: DeclObjC.h:426
bool isDefined() const
Definition: DeclObjC.h:452
void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID)
createImplicitParams - Used to lazily create the self and cmd implicit parameters.
Definition: DeclObjC.cpp:1190
QualType getReturnType() const
Definition: DeclObjC.h:329
ParmVarDecl *const * param_iterator
Definition: DeclObjC.h:350
ObjCImplementationControl getImplementationControl() const
Definition: DeclObjC.h:500
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.cpp:1211
ArrayRef< ParmVarDecl * > parameters() const
Definition: DeclObjC.h:373
TypeSourceInfo * getReturnTypeSourceInfo() const
Definition: DeclObjC.h:343
void getSelectorLocs(SmallVectorImpl< SourceLocation > &SelLocs) const
Definition: DeclObjC.cpp:938
Represents a pointer to an Objective C object.
Definition: Type.h:7020
Represents a class type in Objective C.
Definition: Type.h:6766
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:730
void setSetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:895
SourceLocation getGetterNameLoc() const
Definition: DeclObjC.h:885
bool isInstanceProperty() const
Definition: DeclObjC.h:853
SourceLocation getSetterNameLoc() const
Definition: DeclObjC.h:893
SourceLocation getAtLoc() const
Definition: DeclObjC.h:795
void setPropertyAttributes(ObjCPropertyAttribute::Kind PRVal)
Definition: DeclObjC.h:818
ObjCMethodDecl * getGetterMethodDecl() const
Definition: DeclObjC.h:900
Selector getSetterName() const
Definition: DeclObjC.h:892
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:923
QualType getType() const
Definition: DeclObjC.h:803
void setPropertyAttributesAsWritten(ObjCPropertyAttribute::Kind PRVal)
Definition: DeclObjC.h:830
Selector getGetterName() const
Definition: DeclObjC.h:884
void setPropertyIvarDecl(ObjCIvarDecl *Ivar)
Definition: DeclObjC.h:919
SourceLocation getLParenLoc() const
Definition: DeclObjC.h:798
void setSetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:904
ObjCPropertyAttribute::Kind getPropertyAttributesAsWritten() const
Definition: DeclObjC.h:826
ObjCPropertyAttribute::Kind getPropertyAttributes() const
Definition: DeclObjC.h:814
TypeSourceInfo * getTypeSourceInfo() const
Definition: DeclObjC.h:801
void setGetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:887
PropertyControl getPropertyImplementation() const
Definition: DeclObjC.h:911
void setGetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:901
ObjCMethodDecl * getSetterMethodDecl() const
Definition: DeclObjC.h:903
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition: DeclObjC.h:2802
SourceLocation getPropertyIvarDeclLoc() const
Definition: DeclObjC.h:2879
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:2876
ObjCPropertyDecl * getPropertyDecl() const
Definition: DeclObjC.h:2867
Kind getPropertyImplementation() const
Definition: DeclObjC.h:2872
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclObjC.h:2864
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2082
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
Definition: DeclObjC.h:2258
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition: DeclObjC.h:2206
void startDefinition()
Starts the definition of this Objective-C protocol.
Definition: DeclObjC.cpp:2023
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2155
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:2162
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Definition: DeclObjC.h:2247
protocol_iterator protocol_end() const
Definition: DeclObjC.h:2169
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:2183
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:578
unsigned getIndex() const
Retrieve the index into its type parameter list.
Definition: DeclObjC.h:636
SourceLocation getColonLoc() const
Retrieve the location of the ':' separating the type parameter name from the explicitly-specified bou...
Definition: DeclObjC.h:644
ObjCTypeParamVariance getVariance() const
Determine the variance of this type parameter.
Definition: DeclObjC.h:623
SourceLocation getVarianceLoc() const
Retrieve the location of the variance keyword.
Definition: DeclObjC.h:633
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition: DeclObjC.h:659
SourceLocation getRAngleLoc() const
Definition: DeclObjC.h:710
static ObjCTypeParamList * create(ASTContext &ctx, SourceLocation lAngleLoc, ArrayRef< ObjCTypeParamDecl * > typeParams, SourceLocation rAngleLoc)
Create a new Objective-C type parameter list.
Definition: DeclObjC.cpp:1520
SourceLocation getLAngleLoc() const
Definition: DeclObjC.h:709
Represents a type parameter type in Objective C.
Definition: Type.h:6692
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition: Expr.h:2517
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition: Expr.h:2550
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
Definition: Expr.cpp:1712
TypeSourceInfo * getTypeSourceInfo() const
Definition: Expr.h:2557
const OffsetOfNode & getComponent(unsigned Idx) const
Definition: Expr.h:2564
unsigned getNumExpressions() const
Definition: Expr.h:2593
SourceLocation getRParenLoc() const
Return the location of the right parentheses.
Definition: Expr.h:2554
Expr * getIndexExpr(unsigned Idx)
Definition: Expr.h:2578
unsigned getNumComponents() const
Definition: Expr.h:2574
Helper class for OffsetOfExpr.
Definition: Expr.h:2411
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition: Expr.h:2469
IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition: Expr.cpp:1747
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition: Expr.h:2475
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition: Expr.h:2485
@ Array
An index into an array.
Definition: Expr.h:2416
@ Identifier
A field in a dependent type, known only by its name.
Definition: Expr.h:2420
@ Field
A field.
Definition: Expr.h:2418
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition: Expr.h:2423
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:2497
Kind getKind() const
Determine what kind of offsetof node this is.
Definition: Expr.h:2465
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:2498
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1168
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition: Expr.h:1218
SourceLocation getLocation() const
Retrieve the location of this expression.
Definition: Expr.h:1190
llvm::iterator_range< decls_iterator > decls() const
Definition: ExprCXX.h:3076
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition: ExprCXX.h:3129
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:3111
SourceLocation getNameLoc() const
Gets the location of the name.
Definition: ExprCXX.h:3090
const DeclarationNameInfo & getNameInfo() const
Gets the full name info.
Definition: ExprCXX.h:3084
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: ExprCXX.h:3103
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition: ExprCXX.h:3099
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments into the given structure.
Definition: ExprCXX.h:3149
DeclarationName getName() const
Gets the name looked up.
Definition: ExprCXX.h:3087
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:3119
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: ExprCXX.h:3144
A structure for storing the information associated with an overloaded template name.
Definition: TemplateName.h:108
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:4173
std::optional< unsigned > getNumExpansions() const
Determine the number of expansions that will be produced when this pack expansion is instantiated,...
Definition: ExprCXX.h:4213
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis that describes this pack expansion.
Definition: ExprCXX.h:4209
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition: ExprCXX.h:4202
Represents a pack expansion of types.
Definition: Type.h:6581
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:2182
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition: Expr.h:2205
const Expr * getSubExpr() const
Definition: Expr.h:2197
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition: Expr.h:2209
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition: Expr.cpp:4785
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition: Expr.h:5694
SourceLocation getLParenLoc() const
Definition: Expr.h:5711
SourceLocation getRParenLoc() const
Definition: Expr.h:5712
ArrayRef< Expr * > exprs()
Definition: Expr.h:5709
Sugar for parentheses used when specifying types.
Definition: Type.h:3125
Represents a parameter to a function.
Definition: Decl.h:1762
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion:
Definition: Decl.h:1843
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition: Decl.h:1822
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition: Decl.h:1830
void setDefaultArg(Expr *defarg)
Definition: Decl.cpp:2984
SourceLocation getExplicitObjectParamThisLoc() const
Definition: Decl.h:1858
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition: Decl.h:1903
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition: Decl.h:1891
void setUninstantiatedDefaultArg(Expr *arg)
Definition: Decl.cpp:3009
bool isObjCMethodParameter() const
Definition: Decl.h:1805
ObjCDeclQualifier getObjCDeclQualifier() const
Definition: Decl.h:1826
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1795
bool hasUninstantiatedDefaultArg() const
Definition: Decl.h:1895
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition: Decl.h:1790
bool hasInheritedDefaultArg() const
Definition: Decl.h:1907
void setKNRPromoted(bool promoted)
Definition: Decl.h:1846
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition: Decl.h:1854
Expr * getDefaultArg()
Definition: Decl.cpp:2972
Expr * getUninstantiatedDefaultArg()
Definition: Decl.cpp:3014
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition: Decl.cpp:3020
unsigned getFunctionScopeDepth() const
Definition: Decl.h:1812
void setHasInheritedDefaultArg(bool I=true)
Definition: Decl.h:1911
PipeType - OpenCL20.
Definition: Type.h:7220
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:3151
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1986
SourceLocation getBeginLoc() const
Definition: Expr.h:2051
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
Definition: Expr.cpp:693
bool isTransparent() const
Definition: Expr.h:2025
PredefinedIdentKind getIdentKind() const
Definition: Expr.h:2021
StringLiteral * getFunctionName()
Definition: Expr.h:2030
Stores the type being destroyed by a pseudo-destructor expression.
Definition: ExprCXX.h:2561
A (possibly-)qualified type.
Definition: Type.h:940
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:1007
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:7371
QualType getCanonicalType() const
Definition: Type.h:7423
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:7403
Represents a template name that was expressed as a qualified name.
Definition: TemplateName.h:431
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:459
TemplateName getUnderlyingTemplate() const
Return the underlying template name.
Definition: TemplateName.h:466
bool hasTemplateKeyword() const
Whether the template name was prefixed by the "template" keyword.
Definition: TemplateName.h:463
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3454
Represents a struct/union/class.
Definition: Decl.h:4171
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition: Decl.cpp:5044
void setAnonymousStructOrUnion(bool Anon)
Definition: Decl.h:4227
field_range fields() const
Definition: Decl.h:4377
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:4362
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition: Decl.cpp:5085
RecordDecl * getMostRecentDecl()
Definition: Decl.h:4197
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition: Decl.h:4223
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5561
RecordDecl * getDecl() const
Definition: Type.h:5571
Provides common interface for the Decls that can be redeclared.
Definition: Redeclarable.h:84
decl_type * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
Definition: Redeclarable.h:226
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Definition: Redeclarable.h:216
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
Definition: Decl.h:4997
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Definition: Redeclarable.h:204
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3392
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition: Stmt.h:3019
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition: Stmt.cpp:1204
Selector getSelector(unsigned NumArgs, const IdentifierInfo **IIV)
Can create any sort of selector.
Smart pointer class that efficiently represents Objective-C method names.
const IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
bool isNull() const
Determine whether this is the empty selector.
unsigned getNumArgs() const
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition: Expr.h:4483
Expr ** getSubExprs()
Retrieve the array of expressions.
Definition: Expr.h:4520
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Definition: Expr.h:4517
SourceLocation getRParenLoc() const
Definition: Expr.h:4504
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:4507
Represents an expression that computes the length of a parameter pack.
Definition: ExprCXX.h:4251
SourceLocation getPackLoc() const
Determine the location of the parameter pack.
Definition: ExprCXX.h:4314
ArrayRef< TemplateArgument > getPartialArguments() const
Get.
Definition: ExprCXX.h:4342
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof...
Definition: ExprCXX.h:4337
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition: ExprCXX.h:4320
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, std::optional< unsigned > Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs=std::nullopt)
Definition: ExprCXX.cpp:1644
SourceLocation getOperatorLoc() const
Determine the location of the 'sizeof' keyword.
Definition: ExprCXX.h:4311
SourceLocation getRParenLoc() const
Determine the location of the right parenthesis.
Definition: ExprCXX.h:4317
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Definition: ExprCXX.h:4326
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition: Expr.h:4779
const DeclContext * getParentContext() const
If the SourceLocExpr has been resolved return the subexpression representing the resolved value.
Definition: Expr.h:4820
SourceLocation getBeginLoc() const
Definition: Expr.h:4824
SourceLocation getEndLoc() const
Definition: Expr.h:4825
SourceLocIdentKind getIdentKind() const
Definition: Expr.h:4799
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
bool isWrittenInBuiltinFile(SourceLocation Loc) const
Returns whether Loc is located in a <built-in> file.
FileID createFileID(FileEntryRef SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
FileManager & getFileManager() const
SourceLocation getComposedLoc(FileID FID, unsigned Offset) const
Form a SourceLocation from a FileID and Offset pair.
FileID getMainFileID() const
Returns the FileID of the main source file.
unsigned getFileIDSize(FileID FID) const
The size of the SLocEntry that FID represents.
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file.
SourceLocation createExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned Length, bool ExpansionIsTokenRange=true, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Creates an expansion SLocEntry for a macro use.
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
SourceLocation createMacroArgExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLoc, unsigned Length)
Creates an expansion SLocEntry for the substitution of an argument into a function-like macro's body.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
One instance of this struct is kept for every file loaded or used.
Each ExpansionInfo encodes the expansion location - where the token was ultimately expanded,...
SourceLocation getExpansionLocStart() const
SourceLocation getSpellingLoc() const
SourceLocation getExpansionLocEnd() const
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
SourceLocation getIncludeLoc() const
const ContentCache & getContentCache() const
This is a discriminated union of FileInfo and ExpansionInfo.
const ExpansionInfo & getExpansion() const
const FileInfo & getFile() const
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:4058
bool isFailed() const
Definition: DeclCXX.h:4087
SourceLocation getRParenLoc() const
Definition: DeclCXX.h:4089
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:4435
CompoundStmt * getSubStmt()
Definition: Expr.h:4452
unsigned getTemplateDepth() const
Definition: Expr.h:4464
SourceLocation getRParenLoc() const
Definition: Expr.h:4461
SourceLocation getLParenLoc() const
Definition: Expr.h:4459
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:185
Stmt - This represents one statement.
Definition: Stmt.h:84
child_iterator child_begin()
Definition: Stmt.h:1457
StmtClass getStmtClass() const
Definition: Stmt.h:1358
child_iterator child_end()
Definition: Stmt.h:1458
const char * getStmtClassName() const
Definition: Stmt.cpp:79
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:338
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1773
bool isPascal() const
Definition: Expr.h:1903
tokloc_iterator tokloc_begin() const
Definition: Expr.h:1946
tokloc_iterator tokloc_end() const
Definition: Expr.h:1950
StringLiteralKind getKind() const
Definition: Expr.h:1893
StringRef getBytes() const
Allow access to clients that need the byte representation, such as ASTWriterStmt::VisitStringLiteral(...
Definition: Expr.h:1858
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, const SourceLocation *Loc, unsigned NumConcatenated)
This is the "fully general" constructor that allows representation of strings formed from multiple co...
Definition: Expr.cpp:1246
unsigned getNumConcatenated() const
getNumConcatenated - Get the number of string literal tokens that were concatenated in translation ph...
Definition: Expr.h:1921
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4477
std::optional< unsigned > getPackIndex() const
Definition: ExprCXX.h:4525
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: ExprCXX.h:4523
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: ExprCXX.h:4519
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:141
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
TemplateArgument getArgumentPack() const
Retrieve the template template argument pack with which this parameter was substituted.
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: TemplateName.h:156
A structure for storing the information associated with a substituted template template parameter.
Definition: TemplateName.h:373
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: TemplateName.h:391
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: TemplateName.h:395
std::optional< unsigned > getPackIndex() const
Definition: TemplateName.h:397
Represents the result of substituting a set of types for a template type parameter pack.
Definition: Type.h:5901
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:5831
void setNextSwitchCase(SwitchCase *SC)
Definition: Stmt.h:1776
SwitchStmt - This represents a 'switch' stmt.
Definition: Stmt.h:2388
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a switch statement.
Definition: Stmt.cpp:1081
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3587
SourceRange getBraceRange() const
Definition: Decl.h:3666
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3710
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition: Decl.h:3685
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3690
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition: Decl.h:3832
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:4741
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition: Decl.cpp:4732
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:4787
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3815
TagKind getTagKind() const
Definition: Decl.h:3782
void setBraceRange(SourceRange R)
Definition: Decl.h:3667
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition: Decl.h:3693
A convenient class for passing around template argument information.
Definition: TemplateBase.h:632
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:648
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:667
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:659
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:647
A template argument list.
Definition: DeclTemplate.h:244
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Definition: DeclTemplate.h:280
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Definition: DeclTemplate.h:274
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:524
TemplateArgumentLocInfo getLocInfo() const
Definition: TemplateBase.h:576
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:574
Represents a template argument.
Definition: TemplateBase.h:61
QualType getStructuralValueType() const
Get the type of a StructuralValue.
Definition: TemplateBase.h:399
QualType getParamTypeForDecl() const
Definition: TemplateBase.h:331
std::optional< unsigned > getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce,...
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:319
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
Definition: TemplateBase.h:444
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
Definition: TemplateBase.h:337
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
Definition: TemplateBase.h:396
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:343
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:438
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:326
QualType getIntegralType() const
Retrieve the type of the integral value.
Definition: TemplateBase.h:377
bool getIsDefaulted() const
If returns 'true', this TemplateArgument corresponds to a default template parameter.
Definition: TemplateBase.h:393
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
Definition: TemplateBase.h:74
@ Template
The template argument is a template name that was provided for a template template parameter.
Definition: TemplateBase.h:93
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
Definition: TemplateBase.h:89
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:107
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:97
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:78
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:67
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:82
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Definition: TemplateBase.h:103
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:295
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:408
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:432
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
Definition: TemplateBase.h:350
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:413
Represents a C++ template name within the type system.
Definition: TemplateName.h:202
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
OverloadedTemplateStorage * getAsOverloadedTemplate() const
Retrieve the underlying, overloaded function template declarations that this template name refers to,...
AssumedTemplateStorage * getAsAssumedTemplateName() const
Retrieve information on a name that has been assumed to be a template-name in order to permit a call ...
NameKind getKind() const
@ UsingTemplate
A template name that refers to a template declaration found through a specific using shadow declarati...
Definition: TemplateName.h:247
@ OverloadedTemplate
A set of overloaded template declarations.
Definition: TemplateName.h:222
@ Template
A single template declaration.
Definition: TemplateName.h:219
@ DependentTemplate
A dependent template name that has not been resolved to a template (or set of templates).
Definition: TemplateName.h:234
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:238
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
Definition: TemplateName.h:243
@ QualifiedTemplate
A qualified template name, where the qualification is kept to describe the source code as written.
Definition: TemplateName.h:230
@ AssumedTemplate
An unqualified-id that has been assumed to name a function template that will be found by ADL.
Definition: TemplateName.h:226
UsingShadowDecl * getAsUsingShadowDecl() const
Retrieve the using shadow declaration through which the underlying template declaration is introduced...
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
SourceLocation getRAngleLoc() const
Definition: DeclTemplate.h:201
SourceLocation getLAngleLoc() const
Definition: DeclTemplate.h:200
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:144
Expr * getRequiresClause()
The constraint-expression of the associated requires-clause.
Definition: DeclTemplate.h:180
SourceLocation getTemplateLoc() const
Definition: DeclTemplate.h:199
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:6101
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
bool wasDeclaredWithTypename() const
Whether this template template parameter was declared with the 'typename' keyword.
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
void setDefaultArgument(const ASTContext &C, const TemplateArgumentLoc &DefArg)
Set the default argument for this template parameter, and whether that default argument was inherited...
unsigned getDepth() const
Get the nesting depth of the template parameter.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
Declaration of a template type parameter.
bool wasDeclaredWithTypename() const
Whether this template type parameter was declared with the 'typename' keyword.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
unsigned getIndex() const
Retrieve the index of the template parameter.
bool hasTypeConstraint() const
Determine whether this template parameter has a type-constraint.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
bool isParameterPack() const
Returns whether this is a parameter pack.
unsigned getDepth() const
Retrieve the depth of the template parameter.
void setTypeConstraint(ConceptReference *CR, Expr *ImmediatelyDeclaredConstraint)
void setDefaultArgument(const ASTContext &C, const TemplateArgumentLoc &DefArg)
Set the default argument for this template parameter.
const TypeConstraint * getTypeConstraint() const
Returns the type constraint associated with this template parameter (if any).
The top declaration context.
Definition: Decl.h:84
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3558
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition: Decl.h:3576
Declaration of an alias template.
TypeAliasDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
Definition: ASTConcept.h:231
void setTypeForDecl(const Type *TD)
Definition: Decl.h:3418
const Type * getTypeForDecl() const
Definition: Decl.h:3417
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:3420
Symbolic representation of typeid(T) for some type T.
Definition: APValue.h:44
const Type * getType() const
Definition: APValue.h:51
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:192
Represents a typeof (or typeof) expression (a C23 feature and GCC extension) or a typeof_unqual expre...
Definition: Type.h:5286
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Definition: Type.h:5334
The type-property cache.
Definition: Type.cpp:4392
A container of type source information.
Definition: Type.h:7342
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:256
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:7353
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2763
static TypeTraitExpr * Create(const ASTContext &C, QualType T, SourceLocation Loc, TypeTrait Kind, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc, bool Value)
Create a new type trait expression.
Definition: ExprCXX.cpp:1827
ArrayRef< TypeSourceInfo * > getArgs() const
Retrieve the argument types.
Definition: ExprCXX.h:2819
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:2824
unsigned getNumArgs() const
Determine the number of arguments to this type trait.
Definition: ExprCXX.h:2810
bool getValue() const
Definition: ExprCXX.h:2804
TypeTrait getTrait() const
Determine which type trait this expression uses.
Definition: ExprCXX.h:2800
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.h:2823
An operation on a type.
Definition: TypeVisitor.h:64
RetTy Visit(const Type *T)
Performs the operation associated with this visitor object.
Definition: TypeVisitor.h:68
The base class of the type hierarchy.
Definition: Type.h:1813
const Type * getPointeeOrArrayElementType() const
If this is a pointer type, return the pointee type.
Definition: Type.h:8117
bool isArrayType() const
Definition: Type.h:7690
bool isPointerType() const
Definition: Type.h:7624
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:705
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2661
QualType getCanonicalTypeInternal() const
Definition: Type.h:2944
const char * getTypeClassName() const
Definition: Type.cpp:3292
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition: Type.h:8110
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition: Type.cpp:2361
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition: Type.h:2326
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8160
bool isRecordType() const
Definition: Type.h:7718
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition: Type.cpp:1885
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3537
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3435
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:3485
QualType getUnderlyingType() const
Definition: Decl.h:3490
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition: Expr.h:2620
SourceLocation getRParenLoc() const
Definition: Expr.h:2696
SourceLocation getOperatorLoc() const
Definition: Expr.h:2693
TypeSourceInfo * getArgumentTypeInfo() const
Definition: Expr.h:2666
bool isArgumentType() const
Definition: Expr.h:2662
UnaryExprOrTypeTrait getKind() const
Definition: Expr.h:2652
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2235
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition: Expr.h:2284
Opcode getOpcode() const
Definition: Expr.h:2275
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
Definition: Expr.h:2376
Expr * getSubExpr() const
Definition: Expr.h:2280
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition: Expr.h:2379
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition: Expr.cpp:4879
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Definition: Expr.h:2293
A unary type transform, which is a type constructed from another.
Definition: Type.h:5478
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:3197
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, UnresolvedSetIterator Begin, UnresolvedSetIterator End, bool KnownDependent)
Definition: ExprCXX.cpp:372
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition: ExprCXX.h:3265
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition: ExprCXX.h:3270
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition: ExprCXX.h:3936
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition: ExprCXX.h:4028
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition: ExprCXX.h:4031
bool hasUnresolvedUsing() const
Determine whether the lookup results contain an unresolved using declaration.
Definition: ExprCXX.h:4022
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition: ExprCXX.h:4009
static UnresolvedMemberExpr * Create(const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
Definition: ExprCXX.cpp:1586
bool isImplicitAccess() const
True if this is an implicit access, i.e., one in which the member being accessed was not written in t...
Definition: ExprCXX.cpp:1579
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:91
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition: Type.h:5156
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3959
SourceLocation getTypenameLoc() const
Returns the source location of the 'typename' keyword.
Definition: DeclCXX.h:3989
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition: DeclCXX.h:3993
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition: DeclCXX.h:3986
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition: DeclCXX.h:4010
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3862
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition: DeclCXX.h:3893
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition: DeclCXX.h:3903
DeclarationNameInfo getNameInfo() const
Definition: DeclCXX.h:3910
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition: DeclCXX.h:3920
Represents a C++ using-declaration.
Definition: DeclCXX.h:3512
bool hasTypename() const
Return true if the using declaration has 'typename'.
Definition: DeclCXX.h:3561
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition: DeclCXX.h:3546
DeclarationNameInfo getNameInfo() const
Definition: DeclCXX.h:3553
SourceLocation getUsingLoc() const
Return the source location of the 'using' keyword.
Definition: DeclCXX.h:3539
Represents C++ using-directive.
Definition: DeclCXX.h:3015
SourceLocation getUsingLoc() const
Return the location of the using keyword.
Definition: DeclCXX.h:3086
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Definition: DeclCXX.cpp:2958
SourceLocation getNamespaceKeyLocation() const
Returns the location of the namespace keyword.
Definition: DeclCXX.h:3090
DeclContext * getCommonAncestor()
Returns the common ancestor context of this using-directive and its nominated namespace.
Definition: DeclCXX.h:3082
SourceLocation getIdentLocation() const
Returns the location of this using declaration's identifier.
Definition: DeclCXX.h:3093
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition: DeclCXX.h:3060
Represents a C++ using-enum-declaration.
Definition: DeclCXX.h:3713
SourceLocation getEnumLoc() const
The source location of the 'enum' keyword.
Definition: DeclCXX.h:3737
TypeSourceInfo * getEnumType() const
Definition: DeclCXX.h:3751
SourceLocation getUsingLoc() const
The source location of the 'using' keyword.
Definition: DeclCXX.h:3733
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition: DeclCXX.h:3794
ArrayRef< NamedDecl * > expansions() const
Get the set of using declarations that this pack expanded into.
Definition: DeclCXX.h:3828
NamedDecl * getInstantiatedFromUsingDecl() const
Get the using declaration from which this was instantiated.
Definition: DeclCXX.h:3824
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3320
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition: DeclCXX.h:3384
BaseUsingDecl * getIntroducer() const
Gets the (written or instantiated) using declaration that introduced this declaration.
Definition: DeclCXX.cpp:3113
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:4719
SourceLocation getBuiltinLoc() const
Definition: Expr.h:4746
SourceLocation getRParenLoc() const
Definition: Expr.h:4749
bool isMicrosoftABI() const
Returns whether this is really a Win64 ABI va_arg expression.
Definition: Expr.h:4740
TypeSourceInfo * getWrittenTypeInfo() const
Definition: Expr.h:4743
const Expr * getSubExpr() const
Definition: Expr.h:4735
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:707
void setType(QualType newType)
Definition: Decl.h:719
QualType getType() const
Definition: Decl.h:718
Represents a variable declaration or definition.
Definition: Decl.h:919
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition: Decl.cpp:2791
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1550
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition: Decl.cpp:2908
DefinitionKind isThisDeclarationADefinition(ASTContext &) const
Check whether this declaration is a definition.
Definition: Decl.cpp:2261
bool isInlineSpecified() const
Definition: Decl.h:1535
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition: Decl.cpp:2367
EvaluatedStmt * getEvaluatedStmt() const
Definition: Decl.cpp:2551
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition: Decl.cpp:2537
void setInlineSpecified()
Definition: Decl.h:1539
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Definition: Decl.h:1346
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
Definition: Decl.cpp:2753
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
Definition: Decl.h:1330
const Expr * getInit() const
Definition: Decl.h:1356
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition: Decl.h:1161
bool isInline() const
Whether this variable is (C++1z) inline.
Definition: Decl.h:1532
ThreadStorageClassSpecifier getTSCSpec() const
Definition: Decl.h:1165
void setConstexpr(bool IC)
Definition: Decl.h:1553
void setInit(Expr *I)
Definition: Decl.cpp:2458
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition: Decl.cpp:2796
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1156
void setImplicitlyInline()
Definition: Decl.h:1544
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition: Decl.cpp:2871
Declaration of a variable template.
VarDecl * getTemplatedDecl() const
Get the underlying variable declarations of the template.
void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
VarTemplateDecl * getMostRecentDecl()
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary variable pattern.
VarTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
void setInstantiatedFromMember(VarTemplatePartialSpecializationDecl *PartialSpec)
Represents a variable template specialization, which refers to a variable template with a given set o...
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
VarTemplateSpecializationDecl * getMostRecentDecl()
void setSpecializationKind(TemplateSpecializationKind TSK)
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
void setPointOfInstantiation(SourceLocation Loc)
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:3759
Represents a GCC generic vector type.
Definition: Type.h:3981
WhileStmt - This represents a 'while' stmt.
Definition: Stmt.h:2584
static WhileStmt * Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body, SourceLocation WL, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a while statement.
Definition: Stmt.cpp:1143
unsigned llvm::PointerUnion< const Decl *, const Expr * > DeclTy
Definition: Descriptor.h:27
bool LE(InterpState &S, CodePtr OpPC)
Definition: Interp.h:883
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition: Address.h:294
StructuralEquivalenceKind
Whether to perform a normal or minimal equivalence check.
CanThrowResult
Possible results from evaluation of a noexcept expression.
void updateFlags(const Decl *From, Decl *To)
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition: Specifiers.h:146
@ Property
The type of a property.
@ BTK__type_pack_element
This names the __type_pack_element BuiltinTemplateDecl.
Definition: Builtins.h:307
@ BTK__make_integer_seq
This names the __make_integer_seq BuiltinTemplateDecl.
Definition: Builtins.h:304
CastKind
CastKind - The kind of operation required for a conversion.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:129
const FunctionProtoType * T
llvm::SmallVector< Decl *, 2 > getCanonicalForwardRedeclChain(Decl *D)
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1275
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:185
#define false
Definition: stdbool.h:26
Used as return type of getFriendCountAndPosition.
unsigned int IndexOfDecl
Index of the specific FriendDecl.
unsigned int TotalCount
Number of similar looking friends.
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:676
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
Information about how a lambda is numbered within its context.
Definition: DeclCXX.h:1798
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
void setCXXLiteralOperatorNameLoc(SourceLocation Loc)
setCXXLiteralOperatorNameLoc - Sets the location of the literal operator name (not the operator keywo...
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
void setCXXOperatorNameRange(SourceRange R)
setCXXOperatorNameRange - Sets the range of the operator name (without the operator keyword).
SourceRange getCXXOperatorNameRange() const
getCXXOperatorNameRange - Gets the range of the operator name (without the operator keyword).
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
SourceLocation getCXXLiteralOperatorNameLoc() const
getCXXLiteralOperatorNameLoc - Returns the location of the literal operator name (not the operator ke...
Structure used to store a statement, the constant value to which it was evaluated (if any),...
Definition: Decl.h:884
bool HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition: Decl.h:902
bool HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition: Decl.h:895
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition: Type.h:4731
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:4735
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:4721
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:4724
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition: Type.h:4727
Extra information about a function prototype.
Definition: Type.h:4747
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:4754
FunctionType::ExtInfo ExtInfo
Definition: Type.h:4748
bool IsEquivalent(Decl *D1, Decl *D2)
Determine whether the two declarations are structurally equivalent.
Location information for a TemplateArgument.
Definition: TemplateBase.h:472
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:517
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:507
TypeSourceInfo * getAsTypeSourceInfo() const
Definition: TemplateBase.h:501
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:513