clang  8.0.0
ASTImporter.cpp
Go to the documentation of this file.
1 //===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the ASTImporter class which imports AST nodes from one
11 // context into another context.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "clang/AST/ASTImporter.h"
17 #include "clang/AST/ASTContext.h"
20 #include "clang/AST/Attr.h"
21 #include "clang/AST/Decl.h"
23 #include "clang/AST/DeclBase.h"
24 #include "clang/AST/DeclCXX.h"
25 #include "clang/AST/DeclFriend.h"
26 #include "clang/AST/DeclGroup.h"
27 #include "clang/AST/DeclObjC.h"
28 #include "clang/AST/DeclTemplate.h"
29 #include "clang/AST/DeclVisitor.h"
31 #include "clang/AST/Expr.h"
32 #include "clang/AST/ExprCXX.h"
33 #include "clang/AST/ExprObjC.h"
38 #include "clang/AST/Stmt.h"
39 #include "clang/AST/StmtCXX.h"
40 #include "clang/AST/StmtObjC.h"
41 #include "clang/AST/StmtVisitor.h"
42 #include "clang/AST/TemplateBase.h"
43 #include "clang/AST/TemplateName.h"
44 #include "clang/AST/Type.h"
45 #include "clang/AST/TypeLoc.h"
46 #include "clang/AST/TypeVisitor.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/None.h"
60 #include "llvm/ADT/Optional.h"
61 #include "llvm/ADT/STLExtras.h"
62 #include "llvm/ADT/SmallVector.h"
63 #include "llvm/Support/Casting.h"
64 #include "llvm/Support/ErrorHandling.h"
65 #include "llvm/Support/MemoryBuffer.h"
66 #include <algorithm>
67 #include <cassert>
68 #include <cstddef>
69 #include <memory>
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;
83 
84  std::string ImportError::toString() const {
85  // FIXME: Improve error texts.
86  switch (Error) {
87  case NameConflict:
88  return "NameConflict";
90  return "UnsupportedConstruct";
91  case Unknown:
92  return "Unknown error";
93  }
94  llvm_unreachable("Invalid error code.");
95  return "Invalid error code.";
96  }
97 
98  void ImportError::log(raw_ostream &OS) const {
99  OS << toString();
100  }
101 
102  std::error_code ImportError::convertToErrorCode() const {
103  llvm_unreachable("Function not implemented.");
104  }
105 
106  char ImportError::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  // FIXME: Temporary until every import returns Expected.
139  template <>
140  LLVM_NODISCARD Error
142  To = Import(From);
143  if (From.isValid() && To.isInvalid())
144  return llvm::make_error<ImportError>();
145  return Error::success();
146  }
147  // FIXME: Temporary until every import returns Expected.
148  template <>
149  LLVM_NODISCARD Error
151  To = Import(From);
152  if (!From.isNull() && To.isNull())
153  return llvm::make_error<ImportError>();
154  return Error::success();
155  }
156 
157  class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>,
158  public DeclVisitor<ASTNodeImporter, ExpectedDecl>,
159  public StmtVisitor<ASTNodeImporter, ExpectedStmt> {
160  ASTImporter &Importer;
161 
162  // Use this instead of Importer.importInto .
163  template <typename ImportT>
164  LLVM_NODISCARD Error importInto(ImportT &To, const ImportT &From) {
165  return Importer.importInto(To, From);
166  }
167 
168  // Use this to import pointers of specific type.
169  template <typename ImportT>
170  LLVM_NODISCARD Error importInto(ImportT *&To, ImportT *From) {
171  auto ToI = Importer.Import(From);
172  if (!ToI && From)
173  return make_error<ImportError>();
174  To = cast_or_null<ImportT>(ToI);
175  return Error::success();
176  // FIXME: This should be the final code.
177  //auto ToOrErr = Importer.Import(From);
178  //if (ToOrErr) {
179  // To = cast_or_null<ImportT>(*ToOrErr);
180  //}
181  //return ToOrErr.takeError();
182  }
183 
184  // Call the import function of ASTImporter for a baseclass of type `T` and
185  // cast the return value to `T`.
186  template <typename T>
187  Expected<T *> import(T *From) {
188  auto *To = Importer.Import(From);
189  if (!To && From)
190  return make_error<ImportError>();
191  return cast_or_null<T>(To);
192  // FIXME: This should be the final code.
193  //auto ToOrErr = Importer.Import(From);
194  //if (!ToOrErr)
195  // return ToOrErr.takeError();
196  //return cast_or_null<T>(*ToOrErr);
197  }
198 
199  template <typename T>
200  Expected<T *> import(const T *From) {
201  return import(const_cast<T *>(From));
202  }
203 
204  // Call the import function of ASTImporter for type `T`.
205  template <typename T>
206  Expected<T> import(const T &From) {
207  T To = Importer.Import(From);
208  T DefaultT;
209  if (To == DefaultT && !(From == DefaultT))
210  return make_error<ImportError>();
211  return To;
212  // FIXME: This should be the final code.
213  //return Importer.Import(From);
214  }
215 
216  template <class T>
218  importSeq(const T &From) {
219  Expected<T> ToOrErr = import(From);
220  if (!ToOrErr)
221  return ToOrErr.takeError();
222  return std::make_tuple<T>(std::move(*ToOrErr));
223  }
224 
225  // Import multiple objects with a single function call.
226  // This should work for every type for which a variant of `import` exists.
227  // The arguments are processed from left to right and import is stopped on
228  // first error.
229  template <class THead, class... TTail>
230  Expected<std::tuple<THead, TTail...>>
231  importSeq(const THead &FromHead, const TTail &...FromTail) {
232  Expected<std::tuple<THead>> ToHeadOrErr = importSeq(FromHead);
233  if (!ToHeadOrErr)
234  return ToHeadOrErr.takeError();
235  Expected<std::tuple<TTail...>> ToTailOrErr = importSeq(FromTail...);
236  if (!ToTailOrErr)
237  return ToTailOrErr.takeError();
238  return std::tuple_cat(*ToHeadOrErr, *ToTailOrErr);
239  }
240 
241 // Wrapper for an overload set.
242  template <typename ToDeclT> struct CallOverloadedCreateFun {
243  template <typename... Args>
244  auto operator()(Args &&... args)
245  -> decltype(ToDeclT::Create(std::forward<Args>(args)...)) {
246  return ToDeclT::Create(std::forward<Args>(args)...);
247  }
248  };
249 
250  // Always use these functions to create a Decl during import. There are
251  // certain tasks which must be done after the Decl was created, e.g. we
252  // must immediately register that as an imported Decl. The parameter `ToD`
253  // will be set to the newly created Decl or if had been imported before
254  // then to the already imported Decl. Returns a bool value set to true if
255  // the `FromD` had been imported before.
256  template <typename ToDeclT, typename FromDeclT, typename... Args>
257  LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
258  Args &&... args) {
259  // There may be several overloads of ToDeclT::Create. We must make sure
260  // to call the one which would be chosen by the arguments, thus we use a
261  // wrapper for the overload set.
262  CallOverloadedCreateFun<ToDeclT> OC;
263  return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
264  std::forward<Args>(args)...);
265  }
266  // Use this overload if a special Type is needed to be created. E.g if we
267  // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl`
268  // then:
269  // TypedefNameDecl *ToTypedef;
270  // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...);
271  template <typename NewDeclT, typename ToDeclT, typename FromDeclT,
272  typename... Args>
273  LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
274  Args &&... args) {
275  CallOverloadedCreateFun<NewDeclT> OC;
276  return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
277  std::forward<Args>(args)...);
278  }
279  // Use this version if a special create function must be
280  // used, e.g. CXXRecordDecl::CreateLambda .
281  template <typename ToDeclT, typename CreateFunT, typename FromDeclT,
282  typename... Args>
283  LLVM_NODISCARD bool
284  GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun,
285  FromDeclT *FromD, Args &&... args) {
286  // FIXME: This code is needed later.
287  //if (Importer.getImportDeclErrorIfAny(FromD)) {
288  // ToD = nullptr;
289  // return true; // Already imported but with error.
290  //}
291  ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD));
292  if (ToD)
293  return true; // Already imported.
294  ToD = CreateFun(std::forward<Args>(args)...);
295  // Keep track of imported Decls.
296  Importer.MapImported(FromD, ToD);
297  Importer.AddToLookupTable(ToD);
298  InitializeImportedDecl(FromD, ToD);
299  return false; // A new Decl is created.
300  }
301 
302  void InitializeImportedDecl(Decl *FromD, Decl *ToD) {
304  if (FromD->hasAttrs())
305  for (const Attr *FromAttr : FromD->getAttrs())
306  ToD->addAttr(Importer.Import(FromAttr));
307  if (FromD->isUsed())
308  ToD->setIsUsed();
309  if (FromD->isImplicit())
310  ToD->setImplicit();
311  }
312 
313  public:
314  explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {}
315 
319 
320  // Importing types
321  ExpectedType VisitType(const Type *T);
322  ExpectedType VisitAtomicType(const AtomicType *T);
323  ExpectedType VisitBuiltinType(const BuiltinType *T);
324  ExpectedType VisitDecayedType(const DecayedType *T);
325  ExpectedType VisitComplexType(const ComplexType *T);
326  ExpectedType VisitPointerType(const PointerType *T);
327  ExpectedType VisitBlockPointerType(const BlockPointerType *T);
328  ExpectedType VisitLValueReferenceType(const LValueReferenceType *T);
329  ExpectedType VisitRValueReferenceType(const RValueReferenceType *T);
330  ExpectedType VisitMemberPointerType(const MemberPointerType *T);
331  ExpectedType VisitConstantArrayType(const ConstantArrayType *T);
332  ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T);
333  ExpectedType VisitVariableArrayType(const VariableArrayType *T);
334  ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T);
335  // FIXME: DependentSizedExtVectorType
336  ExpectedType VisitVectorType(const VectorType *T);
337  ExpectedType VisitExtVectorType(const ExtVectorType *T);
338  ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T);
339  ExpectedType VisitFunctionProtoType(const FunctionProtoType *T);
340  ExpectedType VisitUnresolvedUsingType(const UnresolvedUsingType *T);
341  ExpectedType VisitParenType(const ParenType *T);
342  ExpectedType VisitTypedefType(const TypedefType *T);
343  ExpectedType VisitTypeOfExprType(const TypeOfExprType *T);
344  // FIXME: DependentTypeOfExprType
345  ExpectedType VisitTypeOfType(const TypeOfType *T);
346  ExpectedType VisitDecltypeType(const DecltypeType *T);
347  ExpectedType VisitUnaryTransformType(const UnaryTransformType *T);
348  ExpectedType VisitAutoType(const AutoType *T);
349  ExpectedType VisitInjectedClassNameType(const InjectedClassNameType *T);
350  // FIXME: DependentDecltypeType
351  ExpectedType VisitRecordType(const RecordType *T);
352  ExpectedType VisitEnumType(const EnumType *T);
353  ExpectedType VisitAttributedType(const AttributedType *T);
354  ExpectedType VisitTemplateTypeParmType(const TemplateTypeParmType *T);
355  ExpectedType VisitSubstTemplateTypeParmType(
356  const SubstTemplateTypeParmType *T);
357  ExpectedType VisitTemplateSpecializationType(
358  const TemplateSpecializationType *T);
359  ExpectedType VisitElaboratedType(const ElaboratedType *T);
360  ExpectedType VisitDependentNameType(const DependentNameType *T);
361  ExpectedType VisitPackExpansionType(const PackExpansionType *T);
362  ExpectedType VisitDependentTemplateSpecializationType(
364  ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T);
365  ExpectedType VisitObjCObjectType(const ObjCObjectType *T);
366  ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T);
367 
368  // Importing declarations
369  Error ImportDeclParts(
370  NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
371  DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc);
372  Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
373  Error ImportDeclarationNameLoc(
374  const DeclarationNameInfo &From, DeclarationNameInfo &To);
375  Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
376  Error ImportDeclContext(
377  Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
378  Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To);
379 
380  Expected<CXXCastPath> ImportCastPath(CastExpr *E);
381 
383 
384  /// What we should import from the definition.
386  /// Import the default subset of the definition, which might be
387  /// nothing (if minimal import is set) or might be everything (if minimal
388  /// import is not set).
390  /// Import everything.
392  /// Import only the bare bones needed to establish a valid
393  /// DeclContext.
394  IDK_Basic
395  };
396 
398  return IDK == IDK_Everything ||
399  (IDK == IDK_Default && !Importer.isMinimalImport());
400  }
401 
402  Error ImportInitializer(VarDecl *From, VarDecl *To);
403  Error ImportDefinition(
404  RecordDecl *From, RecordDecl *To,
405  ImportDefinitionKind Kind = IDK_Default);
406  Error ImportDefinition(
407  EnumDecl *From, EnumDecl *To,
408  ImportDefinitionKind Kind = IDK_Default);
409  Error ImportDefinition(
411  ImportDefinitionKind Kind = IDK_Default);
412  Error ImportDefinition(
414  ImportDefinitionKind Kind = IDK_Default);
415  Expected<TemplateParameterList *> ImportTemplateParameterList(
416  TemplateParameterList *Params);
417  Error ImportTemplateArguments(
418  const TemplateArgument *FromArgs, unsigned NumFromArgs,
421  ImportTemplateArgument(const TemplateArgument &From);
422 
423  template <typename InContainerTy>
424  Error ImportTemplateArgumentListInfo(
425  const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo);
426 
427  template<typename InContainerTy>
428  Error ImportTemplateArgumentListInfo(
429  SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
430  const InContainerTy &Container, TemplateArgumentListInfo &Result);
431 
434  std::tuple<FunctionTemplateDecl *, TemplateArgsTy>;
436  ImportFunctionTemplateWithTemplateArgsFromSpecialization(
437  FunctionDecl *FromFD);
438 
439  Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD);
440 
441  bool IsStructuralMatch(Decl *From, Decl *To, bool Complain);
442  bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord,
443  bool Complain = true);
444  bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar,
445  bool Complain = true);
446  bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord);
447  bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC);
448  bool IsStructuralMatch(FunctionTemplateDecl *From,
450  bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To);
451  bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To);
452  bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To);
453  ExpectedDecl VisitDecl(Decl *D);
454  ExpectedDecl VisitImportDecl(ImportDecl *D);
455  ExpectedDecl VisitEmptyDecl(EmptyDecl *D);
456  ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D);
457  ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D);
458  ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D);
459  ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D);
460  ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
461  ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias);
462  ExpectedDecl VisitTypedefDecl(TypedefDecl *D);
463  ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D);
464  ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
465  ExpectedDecl VisitLabelDecl(LabelDecl *D);
466  ExpectedDecl VisitEnumDecl(EnumDecl *D);
467  ExpectedDecl VisitRecordDecl(RecordDecl *D);
468  ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D);
469  ExpectedDecl VisitFunctionDecl(FunctionDecl *D);
470  ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D);
471  ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D);
472  ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D);
473  ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D);
474  ExpectedDecl VisitFieldDecl(FieldDecl *D);
475  ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D);
476  ExpectedDecl VisitFriendDecl(FriendDecl *D);
477  ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D);
478  ExpectedDecl VisitVarDecl(VarDecl *D);
479  ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D);
480  ExpectedDecl VisitParmVarDecl(ParmVarDecl *D);
481  ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D);
482  ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
483  ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D);
484  ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D);
485  ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D);
486  ExpectedDecl VisitUsingDecl(UsingDecl *D);
487  ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D);
488  ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
489  ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
490  ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
491 
493  ImportObjCTypeParamList(ObjCTypeParamList *list);
494 
495  ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
496  ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
497  ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D);
498  ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D);
499  ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
500  ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
501  ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
502  ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
503  ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D);
504  ExpectedDecl VisitClassTemplateSpecializationDecl(
506  ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D);
507  ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D);
508  ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
509 
510  // Importing statements
511  ExpectedStmt VisitStmt(Stmt *S);
512  ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S);
513  ExpectedStmt VisitDeclStmt(DeclStmt *S);
514  ExpectedStmt VisitNullStmt(NullStmt *S);
515  ExpectedStmt VisitCompoundStmt(CompoundStmt *S);
516  ExpectedStmt VisitCaseStmt(CaseStmt *S);
517  ExpectedStmt VisitDefaultStmt(DefaultStmt *S);
518  ExpectedStmt VisitLabelStmt(LabelStmt *S);
519  ExpectedStmt VisitAttributedStmt(AttributedStmt *S);
520  ExpectedStmt VisitIfStmt(IfStmt *S);
521  ExpectedStmt VisitSwitchStmt(SwitchStmt *S);
522  ExpectedStmt VisitWhileStmt(WhileStmt *S);
523  ExpectedStmt VisitDoStmt(DoStmt *S);
524  ExpectedStmt VisitForStmt(ForStmt *S);
525  ExpectedStmt VisitGotoStmt(GotoStmt *S);
526  ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S);
527  ExpectedStmt VisitContinueStmt(ContinueStmt *S);
528  ExpectedStmt VisitBreakStmt(BreakStmt *S);
529  ExpectedStmt VisitReturnStmt(ReturnStmt *S);
530  // FIXME: MSAsmStmt
531  // FIXME: SEHExceptStmt
532  // FIXME: SEHFinallyStmt
533  // FIXME: SEHTryStmt
534  // FIXME: SEHLeaveStmt
535  // FIXME: CapturedStmt
536  ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S);
537  ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S);
538  ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S);
539  // FIXME: MSDependentExistsStmt
540  ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S);
541  ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S);
542  ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S);
543  ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S);
544  ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S);
545  ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S);
546  ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S);
547 
548  // Importing expressions
549  ExpectedStmt VisitExpr(Expr *E);
550  ExpectedStmt VisitVAArgExpr(VAArgExpr *E);
551  ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E);
552  ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E);
553  ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E);
554  ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E);
555  ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E);
556  ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
557  ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E);
558  ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E);
559  ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E);
560  ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E);
561  ExpectedStmt VisitStringLiteral(StringLiteral *E);
562  ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
563  ExpectedStmt VisitAtomicExpr(AtomicExpr *E);
564  ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E);
565  ExpectedStmt VisitConstantExpr(ConstantExpr *E);
566  ExpectedStmt VisitParenExpr(ParenExpr *E);
567  ExpectedStmt VisitParenListExpr(ParenListExpr *E);
568  ExpectedStmt VisitStmtExpr(StmtExpr *E);
569  ExpectedStmt VisitUnaryOperator(UnaryOperator *E);
570  ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E);
571  ExpectedStmt VisitBinaryOperator(BinaryOperator *E);
572  ExpectedStmt VisitConditionalOperator(ConditionalOperator *E);
573  ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E);
574  ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E);
575  ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E);
576  ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E);
577  ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E);
578  ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E);
579  ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E);
580  ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E);
581  ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE);
582  ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E);
583  ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E);
584  ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
585  ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E);
586  ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
587  ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E);
588  ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E);
589  ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E);
590  ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E);
591  ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E);
592  ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E);
593  ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E);
594  ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E);
595  ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E);
596  ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E);
597  ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E);
598  ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E);
599  ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E);
600  ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E);
601  ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E);
602  ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
603  ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E);
604  ExpectedStmt VisitMemberExpr(MemberExpr *E);
605  ExpectedStmt VisitCallExpr(CallExpr *E);
606  ExpectedStmt VisitLambdaExpr(LambdaExpr *LE);
607  ExpectedStmt VisitInitListExpr(InitListExpr *E);
608  ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E);
609  ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E);
610  ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E);
611  ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E);
612  ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
613  ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
614  ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
615  ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E);
616  ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E);
617 
618  template<typename IIter, typename OIter>
619  Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
620  using ItemT = typename std::remove_reference<decltype(*Obegin)>::type;
621  for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
622  Expected<ItemT> ToOrErr = import(*Ibegin);
623  if (!ToOrErr)
624  return ToOrErr.takeError();
625  *Obegin = *ToOrErr;
626  }
627  return Error::success();
628  }
629 
630  // Import every item from a container structure into an output container.
631  // If error occurs, stops at first error and returns the error.
632  // The output container should have space for all needed elements (it is not
633  // expanded, new items are put into from the beginning).
634  template<typename InContainerTy, typename OutContainerTy>
636  const InContainerTy &InContainer, OutContainerTy &OutContainer) {
637  return ImportArrayChecked(
638  InContainer.begin(), InContainer.end(), OutContainer.begin());
639  }
640 
641  template<typename InContainerTy, typename OIter>
642  Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
643  return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
644  }
645 
646  void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod);
647 
648  Expected<FunctionDecl *> FindFunctionTemplateSpecialization(
649  FunctionDecl *FromFD);
650  };
651 
652 // FIXME: Temporary until every import returns Expected.
653 template <>
654 Expected<TemplateName> ASTNodeImporter::import(const TemplateName &From) {
655  TemplateName To = Importer.Import(From);
656  if (To.isNull() && !From.isNull())
657  return make_error<ImportError>();
658  return To;
659 }
660 
661 template <typename InContainerTy>
663  SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
664  const InContainerTy &Container, TemplateArgumentListInfo &Result) {
665  auto ToLAngleLocOrErr = import(FromLAngleLoc);
666  if (!ToLAngleLocOrErr)
667  return ToLAngleLocOrErr.takeError();
668  auto ToRAngleLocOrErr = import(FromRAngleLoc);
669  if (!ToRAngleLocOrErr)
670  return ToRAngleLocOrErr.takeError();
671 
672  TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr);
673  if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo))
674  return Err;
675  Result = ToTAInfo;
676  return Error::success();
677 }
678 
679 template <>
680 Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>(
682  return ImportTemplateArgumentListInfo(
683  From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result);
684 }
685 
686 template <>
689  const ASTTemplateArgumentListInfo &From,
691  return ImportTemplateArgumentListInfo(
692  From.LAngleLoc, From.RAngleLoc, From.arguments(), Result);
693 }
694 
697  FunctionDecl *FromFD) {
698  assert(FromFD->getTemplatedKind() ==
700 
702 
703  auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
704  if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate()))
705  return std::move(Err);
706 
707  // Import template arguments.
708  auto TemplArgs = FTSInfo->TemplateArguments->asArray();
709  if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(),
710  std::get<1>(Result)))
711  return std::move(Err);
712 
713  return Result;
714 }
715 
716 template <>
718 ASTNodeImporter::import(TemplateParameterList *From) {
719  SmallVector<NamedDecl *, 4> To(From->size());
720  if (Error Err = ImportContainerChecked(*From, To))
721  return std::move(Err);
722 
723  ExpectedExpr ToRequiresClause = import(From->getRequiresClause());
724  if (!ToRequiresClause)
725  return ToRequiresClause.takeError();
726 
727  auto ToTemplateLocOrErr = import(From->getTemplateLoc());
728  if (!ToTemplateLocOrErr)
729  return ToTemplateLocOrErr.takeError();
730  auto ToLAngleLocOrErr = import(From->getLAngleLoc());
731  if (!ToLAngleLocOrErr)
732  return ToLAngleLocOrErr.takeError();
733  auto ToRAngleLocOrErr = import(From->getRAngleLoc());
734  if (!ToRAngleLocOrErr)
735  return ToRAngleLocOrErr.takeError();
736 
738  Importer.getToContext(),
739  *ToTemplateLocOrErr,
740  *ToLAngleLocOrErr,
741  To,
742  *ToRAngleLocOrErr,
743  *ToRequiresClause);
744 }
745 
746 template <>
748 ASTNodeImporter::import(const TemplateArgument &From) {
749  switch (From.getKind()) {
751  return TemplateArgument();
752 
753  case TemplateArgument::Type: {
754  ExpectedType ToTypeOrErr = import(From.getAsType());
755  if (!ToTypeOrErr)
756  return ToTypeOrErr.takeError();
757  return TemplateArgument(*ToTypeOrErr);
758  }
759 
761  ExpectedType ToTypeOrErr = import(From.getIntegralType());
762  if (!ToTypeOrErr)
763  return ToTypeOrErr.takeError();
764  return TemplateArgument(From, *ToTypeOrErr);
765  }
766 
768  Expected<ValueDecl *> ToOrErr = import(From.getAsDecl());
769  if (!ToOrErr)
770  return ToOrErr.takeError();
771  ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
772  if (!ToTypeOrErr)
773  return ToTypeOrErr.takeError();
774  return TemplateArgument(*ToOrErr, *ToTypeOrErr);
775  }
776 
778  ExpectedType ToTypeOrErr = import(From.getNullPtrType());
779  if (!ToTypeOrErr)
780  return ToTypeOrErr.takeError();
781  return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true);
782  }
783 
785  Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
786  if (!ToTemplateOrErr)
787  return ToTemplateOrErr.takeError();
788 
789  return TemplateArgument(*ToTemplateOrErr);
790  }
791 
793  Expected<TemplateName> ToTemplateOrErr =
794  import(From.getAsTemplateOrTemplatePattern());
795  if (!ToTemplateOrErr)
796  return ToTemplateOrErr.takeError();
797 
798  return TemplateArgument(
799  *ToTemplateOrErr, From.getNumTemplateExpansions());
800  }
801 
803  if (ExpectedExpr ToExpr = import(From.getAsExpr()))
804  return TemplateArgument(*ToExpr);
805  else
806  return ToExpr.takeError();
807 
808  case TemplateArgument::Pack: {
810  ToPack.reserve(From.pack_size());
811  if (Error Err = ImportTemplateArguments(
812  From.pack_begin(), From.pack_size(), ToPack))
813  return std::move(Err);
814 
815  return TemplateArgument(
816  llvm::makeArrayRef(ToPack).copy(Importer.getToContext()));
817  }
818  }
819 
820  llvm_unreachable("Invalid template argument kind");
821 }
822 
823 template <>
825 ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) {
826  Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument());
827  if (!ArgOrErr)
828  return ArgOrErr.takeError();
829  TemplateArgument Arg = *ArgOrErr;
830 
831  TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
832 
834  if (Arg.getKind() == TemplateArgument::Expression) {
835  ExpectedExpr E = import(FromInfo.getAsExpr());
836  if (!E)
837  return E.takeError();
838  ToInfo = TemplateArgumentLocInfo(*E);
839  } else if (Arg.getKind() == TemplateArgument::Type) {
840  if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo()))
841  ToInfo = TemplateArgumentLocInfo(*TSIOrErr);
842  else
843  return TSIOrErr.takeError();
844  } else {
845  auto ToTemplateQualifierLocOrErr =
846  import(FromInfo.getTemplateQualifierLoc());
847  if (!ToTemplateQualifierLocOrErr)
848  return ToTemplateQualifierLocOrErr.takeError();
849  auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc());
850  if (!ToTemplateNameLocOrErr)
851  return ToTemplateNameLocOrErr.takeError();
852  auto ToTemplateEllipsisLocOrErr =
853  import(FromInfo.getTemplateEllipsisLoc());
854  if (!ToTemplateEllipsisLocOrErr)
855  return ToTemplateEllipsisLocOrErr.takeError();
856 
857  ToInfo = TemplateArgumentLocInfo(
858  *ToTemplateQualifierLocOrErr,
859  *ToTemplateNameLocOrErr,
860  *ToTemplateEllipsisLocOrErr);
861  }
862 
863  return TemplateArgumentLoc(Arg, ToInfo);
864 }
865 
866 template <>
867 Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) {
868  if (DG.isNull())
869  return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
870  size_t NumDecls = DG.end() - DG.begin();
871  SmallVector<Decl *, 1> ToDecls;
872  ToDecls.reserve(NumDecls);
873  for (Decl *FromD : DG) {
874  if (auto ToDOrErr = import(FromD))
875  ToDecls.push_back(*ToDOrErr);
876  else
877  return ToDOrErr.takeError();
878  }
879  return DeclGroupRef::Create(Importer.getToContext(),
880  ToDecls.begin(),
881  NumDecls);
882 }
883 
884 template <>
886 ASTNodeImporter::import(const Designator &D) {
887  if (D.isFieldDesignator()) {
888  IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
889 
890  ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc());
891  if (!ToDotLocOrErr)
892  return ToDotLocOrErr.takeError();
893 
894  ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc());
895  if (!ToFieldLocOrErr)
896  return ToFieldLocOrErr.takeError();
897 
898  return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr);
899  }
900 
901  ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc());
902  if (!ToLBracketLocOrErr)
903  return ToLBracketLocOrErr.takeError();
904 
905  ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc());
906  if (!ToRBracketLocOrErr)
907  return ToRBracketLocOrErr.takeError();
908 
909  if (D.isArrayDesignator())
910  return Designator(D.getFirstExprIndex(),
911  *ToLBracketLocOrErr, *ToRBracketLocOrErr);
912 
913  ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc());
914  if (!ToEllipsisLocOrErr)
915  return ToEllipsisLocOrErr.takeError();
916 
917  assert(D.isArrayRangeDesignator());
918  return Designator(
919  D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr,
920  *ToRBracketLocOrErr);
921 }
922 
923 template <>
924 Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) {
925  VarDecl *Var = nullptr;
926  if (From.capturesVariable()) {
927  if (auto VarOrErr = import(From.getCapturedVar()))
928  Var = *VarOrErr;
929  else
930  return VarOrErr.takeError();
931  }
932 
933  auto LocationOrErr = import(From.getLocation());
934  if (!LocationOrErr)
935  return LocationOrErr.takeError();
936 
937  SourceLocation EllipsisLoc;
938  if (From.isPackExpansion())
939  if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc()))
940  return std::move(Err);
941 
942  return LambdaCapture(
943  *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var,
944  EllipsisLoc);
945 }
946 
947 } // namespace clang
948 
949 //----------------------------------------------------------------------------
950 // Import Types
951 //----------------------------------------------------------------------------
952 
953 using namespace clang;
954 
956  Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
957  << T->getTypeClassName();
958  return make_error<ImportError>(ImportError::UnsupportedConstruct);
959 }
960 
962  ExpectedType UnderlyingTypeOrErr = import(T->getValueType());
963  if (!UnderlyingTypeOrErr)
964  return UnderlyingTypeOrErr.takeError();
965 
966  return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr);
967 }
968 
970  switch (T->getKind()) {
971 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
972  case BuiltinType::Id: \
973  return Importer.getToContext().SingletonId;
974 #include "clang/Basic/OpenCLImageTypes.def"
975 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
976  case BuiltinType::Id: \
977  return Importer.getToContext().Id##Ty;
978 #include "clang/Basic/OpenCLExtensionTypes.def"
979 #define SHARED_SINGLETON_TYPE(Expansion)
980 #define BUILTIN_TYPE(Id, SingletonId) \
981  case BuiltinType::Id: return Importer.getToContext().SingletonId;
982 #include "clang/AST/BuiltinTypes.def"
983 
984  // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
985  // context supports C++.
986 
987  // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
988  // context supports ObjC.
989 
990  case BuiltinType::Char_U:
991  // The context we're importing from has an unsigned 'char'. If we're
992  // importing into a context with a signed 'char', translate to
993  // 'unsigned char' instead.
994  if (Importer.getToContext().getLangOpts().CharIsSigned)
995  return Importer.getToContext().UnsignedCharTy;
996 
997  return Importer.getToContext().CharTy;
998 
999  case BuiltinType::Char_S:
1000  // The context we're importing from has an unsigned 'char'. If we're
1001  // importing into a context with a signed 'char', translate to
1002  // 'unsigned char' instead.
1003  if (!Importer.getToContext().getLangOpts().CharIsSigned)
1004  return Importer.getToContext().SignedCharTy;
1005 
1006  return Importer.getToContext().CharTy;
1007 
1008  case BuiltinType::WChar_S:
1009  case BuiltinType::WChar_U:
1010  // FIXME: If not in C++, shall we translate to the C equivalent of
1011  // wchar_t?
1012  return Importer.getToContext().WCharTy;
1013  }
1014 
1015  llvm_unreachable("Invalid BuiltinType Kind!");
1016 }
1017 
1019  ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType());
1020  if (!ToOriginalTypeOrErr)
1021  return ToOriginalTypeOrErr.takeError();
1022 
1023  return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr);
1024 }
1025 
1027  ExpectedType ToElementTypeOrErr = import(T->getElementType());
1028  if (!ToElementTypeOrErr)
1029  return ToElementTypeOrErr.takeError();
1030 
1031  return Importer.getToContext().getComplexType(*ToElementTypeOrErr);
1032 }
1033 
1035  ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1036  if (!ToPointeeTypeOrErr)
1037  return ToPointeeTypeOrErr.takeError();
1038 
1039  return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr);
1040 }
1041 
1043  // FIXME: Check for blocks support in "to" context.
1044  ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1045  if (!ToPointeeTypeOrErr)
1046  return ToPointeeTypeOrErr.takeError();
1047 
1048  return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr);
1049 }
1050 
1053  // FIXME: Check for C++ support in "to" context.
1054  ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1055  if (!ToPointeeTypeOrErr)
1056  return ToPointeeTypeOrErr.takeError();
1057 
1058  return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr);
1059 }
1060 
1063  // FIXME: Check for C++0x support in "to" context.
1064  ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1065  if (!ToPointeeTypeOrErr)
1066  return ToPointeeTypeOrErr.takeError();
1067 
1068  return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr);
1069 }
1070 
1073  // FIXME: Check for C++ support in "to" context.
1074  ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1075  if (!ToPointeeTypeOrErr)
1076  return ToPointeeTypeOrErr.takeError();
1077 
1078  ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0));
1079  if (!ClassTypeOrErr)
1080  return ClassTypeOrErr.takeError();
1081 
1082  return Importer.getToContext().getMemberPointerType(
1083  *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr());
1084 }
1085 
1088  ExpectedType ToElementTypeOrErr = import(T->getElementType());
1089  if (!ToElementTypeOrErr)
1090  return ToElementTypeOrErr.takeError();
1091 
1092  return Importer.getToContext().getConstantArrayType(*ToElementTypeOrErr,
1093  T->getSize(),
1094  T->getSizeModifier(),
1096 }
1097 
1100  ExpectedType ToElementTypeOrErr = import(T->getElementType());
1101  if (!ToElementTypeOrErr)
1102  return ToElementTypeOrErr.takeError();
1103 
1104  return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr,
1105  T->getSizeModifier(),
1107 }
1108 
1111  QualType ToElementType;
1112  Expr *ToSizeExpr;
1113  SourceRange ToBracketsRange;
1114  if (auto Imp = importSeq(
1115  T->getElementType(), T->getSizeExpr(), T->getBracketsRange()))
1116  std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp;
1117  else
1118  return Imp.takeError();
1119 
1120  return Importer.getToContext().getVariableArrayType(
1121  ToElementType, ToSizeExpr, T->getSizeModifier(),
1122  T->getIndexTypeCVRQualifiers(), ToBracketsRange);
1123 }
1124 
1126  const DependentSizedArrayType *T) {
1127  QualType ToElementType;
1128  Expr *ToSizeExpr;
1129  SourceRange ToBracketsRange;
1130  if (auto Imp = importSeq(
1131  T->getElementType(), T->getSizeExpr(), T->getBracketsRange()))
1132  std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp;
1133  else
1134  return Imp.takeError();
1135  // SizeExpr may be null if size is not specified directly.
1136  // For example, 'int a[]'.
1137 
1138  return Importer.getToContext().getDependentSizedArrayType(
1139  ToElementType, ToSizeExpr, T->getSizeModifier(),
1140  T->getIndexTypeCVRQualifiers(), ToBracketsRange);
1141 }
1142 
1144  ExpectedType ToElementTypeOrErr = import(T->getElementType());
1145  if (!ToElementTypeOrErr)
1146  return ToElementTypeOrErr.takeError();
1147 
1148  return Importer.getToContext().getVectorType(*ToElementTypeOrErr,
1149  T->getNumElements(),
1150  T->getVectorKind());
1151 }
1152 
1154  ExpectedType ToElementTypeOrErr = import(T->getElementType());
1155  if (!ToElementTypeOrErr)
1156  return ToElementTypeOrErr.takeError();
1157 
1158  return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr,
1159  T->getNumElements());
1160 }
1161 
1164  // FIXME: What happens if we're importing a function without a prototype
1165  // into C++? Should we make it variadic?
1166  ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1167  if (!ToReturnTypeOrErr)
1168  return ToReturnTypeOrErr.takeError();
1169 
1170  return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr,
1171  T->getExtInfo());
1172 }
1173 
1176  ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1177  if (!ToReturnTypeOrErr)
1178  return ToReturnTypeOrErr.takeError();
1179 
1180  // Import argument types
1181  SmallVector<QualType, 4> ArgTypes;
1182  for (const auto &A : T->param_types()) {
1183  ExpectedType TyOrErr = import(A);
1184  if (!TyOrErr)
1185  return TyOrErr.takeError();
1186  ArgTypes.push_back(*TyOrErr);
1187  }
1188 
1189  // Import exception types
1190  SmallVector<QualType, 4> ExceptionTypes;
1191  for (const auto &E : T->exceptions()) {
1192  ExpectedType TyOrErr = import(E);
1193  if (!TyOrErr)
1194  return TyOrErr.takeError();
1195  ExceptionTypes.push_back(*TyOrErr);
1196  }
1197 
1200 
1201  auto Imp = importSeq(
1202  FromEPI.ExceptionSpec.NoexceptExpr,
1203  FromEPI.ExceptionSpec.SourceDecl,
1204  FromEPI.ExceptionSpec.SourceTemplate);
1205  if (!Imp)
1206  return Imp.takeError();
1207 
1208  ToEPI.ExtInfo = FromEPI.ExtInfo;
1209  ToEPI.Variadic = FromEPI.Variadic;
1210  ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
1211  ToEPI.TypeQuals = FromEPI.TypeQuals;
1212  ToEPI.RefQualifier = FromEPI.RefQualifier;
1213  ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
1214  ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
1215  std::tie(
1217  ToEPI.ExceptionSpec.SourceDecl,
1218  ToEPI.ExceptionSpec.SourceTemplate) = *Imp;
1219 
1220  return Importer.getToContext().getFunctionType(
1221  *ToReturnTypeOrErr, ArgTypes, ToEPI);
1222 }
1223 
1225  const UnresolvedUsingType *T) {
1227  Decl *ToPrevD;
1228  if (auto Imp = importSeq(T->getDecl(), T->getDecl()->getPreviousDecl()))
1229  std::tie(ToD, ToPrevD) = *Imp;
1230  else
1231  return Imp.takeError();
1232 
1233  return Importer.getToContext().getTypeDeclType(
1234  ToD, cast_or_null<TypeDecl>(ToPrevD));
1235 }
1236 
1238  ExpectedType ToInnerTypeOrErr = import(T->getInnerType());
1239  if (!ToInnerTypeOrErr)
1240  return ToInnerTypeOrErr.takeError();
1241 
1242  return Importer.getToContext().getParenType(*ToInnerTypeOrErr);
1243 }
1244 
1246  Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl());
1247  if (!ToDeclOrErr)
1248  return ToDeclOrErr.takeError();
1249 
1250  return Importer.getToContext().getTypeDeclType(*ToDeclOrErr);
1251 }
1252 
1254  ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1255  if (!ToExprOrErr)
1256  return ToExprOrErr.takeError();
1257 
1258  return Importer.getToContext().getTypeOfExprType(*ToExprOrErr);
1259 }
1260 
1262  ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1263  if (!ToUnderlyingTypeOrErr)
1264  return ToUnderlyingTypeOrErr.takeError();
1265 
1266  return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr);
1267 }
1268 
1270  // FIXME: Make sure that the "to" context supports C++0x!
1271  ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1272  if (!ToExprOrErr)
1273  return ToExprOrErr.takeError();
1274 
1275  ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1276  if (!ToUnderlyingTypeOrErr)
1277  return ToUnderlyingTypeOrErr.takeError();
1278 
1279  return Importer.getToContext().getDecltypeType(
1280  *ToExprOrErr, *ToUnderlyingTypeOrErr);
1281 }
1282 
1285  ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1286  if (!ToBaseTypeOrErr)
1287  return ToBaseTypeOrErr.takeError();
1288 
1289  ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1290  if (!ToUnderlyingTypeOrErr)
1291  return ToUnderlyingTypeOrErr.takeError();
1292 
1293  return Importer.getToContext().getUnaryTransformType(
1294  *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind());
1295 }
1296 
1298  // FIXME: Make sure that the "to" context supports C++11!
1299  ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1300  if (!ToDeducedTypeOrErr)
1301  return ToDeducedTypeOrErr.takeError();
1302 
1303  return Importer.getToContext().getAutoType(*ToDeducedTypeOrErr,
1304  T->getKeyword(),
1305  /*IsDependent*/false);
1306 }
1307 
1309  const InjectedClassNameType *T) {
1310  Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl());
1311  if (!ToDeclOrErr)
1312  return ToDeclOrErr.takeError();
1313 
1314  ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType());
1315  if (!ToInjTypeOrErr)
1316  return ToInjTypeOrErr.takeError();
1317 
1318  // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading
1319  // See comments in InjectedClassNameType definition for details
1320  // return Importer.getToContext().getInjectedClassNameType(D, InjType);
1321  enum {
1322  TypeAlignmentInBits = 4,
1324  };
1325 
1326  return QualType(new (Importer.getToContext(), TypeAlignment)
1327  InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0);
1328 }
1329 
1331  Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl());
1332  if (!ToDeclOrErr)
1333  return ToDeclOrErr.takeError();
1334 
1335  return Importer.getToContext().getTagDeclType(*ToDeclOrErr);
1336 }
1337 
1339  Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl());
1340  if (!ToDeclOrErr)
1341  return ToDeclOrErr.takeError();
1342 
1343  return Importer.getToContext().getTagDeclType(*ToDeclOrErr);
1344 }
1345 
1347  ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType());
1348  if (!ToModifiedTypeOrErr)
1349  return ToModifiedTypeOrErr.takeError();
1350  ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType());
1351  if (!ToEquivalentTypeOrErr)
1352  return ToEquivalentTypeOrErr.takeError();
1353 
1354  return Importer.getToContext().getAttributedType(T->getAttrKind(),
1355  *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr);
1356 }
1357 
1359  const TemplateTypeParmType *T) {
1360  Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl());
1361  if (!ToDeclOrErr)
1362  return ToDeclOrErr.takeError();
1363 
1364  return Importer.getToContext().getTemplateTypeParmType(
1365  T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr);
1366 }
1367 
1369  const SubstTemplateTypeParmType *T) {
1370  ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0));
1371  if (!ReplacedOrErr)
1372  return ReplacedOrErr.takeError();
1373  const TemplateTypeParmType *Replaced =
1374  cast<TemplateTypeParmType>((*ReplacedOrErr).getTypePtr());
1375 
1376  ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType());
1377  if (!ToReplacementTypeOrErr)
1378  return ToReplacementTypeOrErr.takeError();
1379 
1380  return Importer.getToContext().getSubstTemplateTypeParmType(
1381  Replaced, (*ToReplacementTypeOrErr).getCanonicalType());
1382 }
1383 
1385  const TemplateSpecializationType *T) {
1386  auto ToTemplateOrErr = import(T->getTemplateName());
1387  if (!ToTemplateOrErr)
1388  return ToTemplateOrErr.takeError();
1389 
1390  SmallVector<TemplateArgument, 2> ToTemplateArgs;
1391  if (Error Err = ImportTemplateArguments(
1392  T->getArgs(), T->getNumArgs(), ToTemplateArgs))
1393  return std::move(Err);
1394 
1395  QualType ToCanonType;
1396  if (!QualType(T, 0).isCanonical()) {
1397  QualType FromCanonType
1398  = Importer.getFromContext().getCanonicalType(QualType(T, 0));
1399  if (ExpectedType TyOrErr = import(FromCanonType))
1400  ToCanonType = *TyOrErr;
1401  else
1402  return TyOrErr.takeError();
1403  }
1404  return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr,
1405  ToTemplateArgs,
1406  ToCanonType);
1407 }
1408 
1410  // Note: the qualifier in an ElaboratedType is optional.
1411  auto ToQualifierOrErr = import(T->getQualifier());
1412  if (!ToQualifierOrErr)
1413  return ToQualifierOrErr.takeError();
1414 
1415  ExpectedType ToNamedTypeOrErr = import(T->getNamedType());
1416  if (!ToNamedTypeOrErr)
1417  return ToNamedTypeOrErr.takeError();
1418 
1419  Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl());
1420  if (!ToOwnedTagDeclOrErr)
1421  return ToOwnedTagDeclOrErr.takeError();
1422 
1423  return Importer.getToContext().getElaboratedType(T->getKeyword(),
1424  *ToQualifierOrErr,
1425  *ToNamedTypeOrErr,
1426  *ToOwnedTagDeclOrErr);
1427 }
1428 
1431  ExpectedType ToPatternOrErr = import(T->getPattern());
1432  if (!ToPatternOrErr)
1433  return ToPatternOrErr.takeError();
1434 
1435  return Importer.getToContext().getPackExpansionType(*ToPatternOrErr,
1436  T->getNumExpansions());
1437 }
1438 
1441  auto ToQualifierOrErr = import(T->getQualifier());
1442  if (!ToQualifierOrErr)
1443  return ToQualifierOrErr.takeError();
1444 
1445  IdentifierInfo *ToName = Importer.Import(T->getIdentifier());
1446 
1448  ToPack.reserve(T->getNumArgs());
1449  if (Error Err = ImportTemplateArguments(
1450  T->getArgs(), T->getNumArgs(), ToPack))
1451  return std::move(Err);
1452 
1453  return Importer.getToContext().getDependentTemplateSpecializationType(
1454  T->getKeyword(), *ToQualifierOrErr, ToName, ToPack);
1455 }
1456 
1459  auto ToQualifierOrErr = import(T->getQualifier());
1460  if (!ToQualifierOrErr)
1461  return ToQualifierOrErr.takeError();
1462 
1463  IdentifierInfo *Name = Importer.Import(T->getIdentifier());
1464 
1465  QualType Canon;
1466  if (T != T->getCanonicalTypeInternal().getTypePtr()) {
1467  if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal()))
1468  Canon = (*TyOrErr).getCanonicalType();
1469  else
1470  return TyOrErr.takeError();
1471  }
1472 
1473  return Importer.getToContext().getDependentNameType(T->getKeyword(),
1474  *ToQualifierOrErr,
1475  Name, Canon);
1476 }
1477 
1480  Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl());
1481  if (!ToDeclOrErr)
1482  return ToDeclOrErr.takeError();
1483 
1484  return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr);
1485 }
1486 
1488  ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1489  if (!ToBaseTypeOrErr)
1490  return ToBaseTypeOrErr.takeError();
1491 
1492  SmallVector<QualType, 4> TypeArgs;
1493  for (auto TypeArg : T->getTypeArgsAsWritten()) {
1494  if (ExpectedType TyOrErr = import(TypeArg))
1495  TypeArgs.push_back(*TyOrErr);
1496  else
1497  return TyOrErr.takeError();
1498  }
1499 
1501  for (auto *P : T->quals()) {
1502  if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P))
1503  Protocols.push_back(*ProtocolOrErr);
1504  else
1505  return ProtocolOrErr.takeError();
1506 
1507  }
1508 
1509  return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs,
1510  Protocols,
1511  T->isKindOfTypeAsWritten());
1512 }
1513 
1516  ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1517  if (!ToPointeeTypeOrErr)
1518  return ToPointeeTypeOrErr.takeError();
1519 
1520  return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
1521 }
1522 
1523 //----------------------------------------------------------------------------
1524 // Import Declarations
1525 //----------------------------------------------------------------------------
1527  NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
1528  DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) {
1529  // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop.
1530  // example: int struct_in_proto(struct data_t{int a;int b;} *d);
1531  DeclContext *OrigDC = D->getDeclContext();
1532  FunctionDecl *FunDecl;
1533  if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) &&
1534  FunDecl->hasBody()) {
1535  auto getLeafPointeeType = [](const Type *T) {
1536  while (T->isPointerType() || T->isArrayType()) {
1537  T = T->getPointeeOrArrayElementType();
1538  }
1539  return T;
1540  };
1541  for (const ParmVarDecl *P : FunDecl->parameters()) {
1542  const Type *LeafT =
1543  getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
1544  auto *RT = dyn_cast<RecordType>(LeafT);
1545  if (RT && RT->getDecl() == D) {
1546  Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
1547  << D->getDeclKindName();
1548  return make_error<ImportError>(ImportError::UnsupportedConstruct);
1549  }
1550  }
1551  }
1552 
1553  // Import the context of this declaration.
1554  if (Error Err = ImportDeclContext(D, DC, LexicalDC))
1555  return Err;
1556 
1557  // Import the name of this declaration.
1558  if (Error Err = importInto(Name, D->getDeclName()))
1559  return Err;
1560 
1561  // Import the location of this declaration.
1562  if (Error Err = importInto(Loc, D->getLocation()))
1563  return Err;
1564 
1565  ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
1566  if (ToD)
1567  if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
1568  return Err;
1569 
1570  return Error::success();
1571 }
1572 
1574  if (!FromD)
1575  return Error::success();
1576 
1577  if (!ToD)
1578  if (Error Err = importInto(ToD, FromD))
1579  return Err;
1580 
1581  if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
1582  if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) {
1583  if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() &&
1584  !ToRecord->getDefinition()) {
1585  if (Error Err = ImportDefinition(FromRecord, ToRecord))
1586  return Err;
1587  }
1588  }
1589  return Error::success();
1590  }
1591 
1592  if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
1593  if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) {
1594  if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
1595  if (Error Err = ImportDefinition(FromEnum, ToEnum))
1596  return Err;
1597  }
1598  }
1599  return Error::success();
1600  }
1601 
1602  return Error::success();
1603 }
1604 
1605 Error
1607  const DeclarationNameInfo &From, DeclarationNameInfo& To) {
1608  // NOTE: To.Name and To.Loc are already imported.
1609  // We only have to import To.LocInfo.
1610  switch (To.getName().getNameKind()) {
1617  return Error::success();
1618 
1620  if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange()))
1621  To.setCXXOperatorNameRange(*ToRangeOrErr);
1622  else
1623  return ToRangeOrErr.takeError();
1624  return Error::success();
1625  }
1627  if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc()))
1628  To.setCXXLiteralOperatorNameLoc(*LocOrErr);
1629  else
1630  return LocOrErr.takeError();
1631  return Error::success();
1632  }
1636  if (auto ToTInfoOrErr = import(From.getNamedTypeInfo()))
1637  To.setNamedTypeInfo(*ToTInfoOrErr);
1638  else
1639  return ToTInfoOrErr.takeError();
1640  return Error::success();
1641  }
1642  }
1643  llvm_unreachable("Unknown name kind.");
1644 }
1645 
1646 Error
1648  if (Importer.isMinimalImport() && !ForceImport) {
1649  auto ToDCOrErr = Importer.ImportContext(FromDC);
1650  return ToDCOrErr.takeError();
1651  }
1652  llvm::SmallVector<Decl *, 8> ImportedDecls;
1653  for (auto *From : FromDC->decls()) {
1654  ExpectedDecl ImportedOrErr = import(From);
1655  if (!ImportedOrErr)
1656  // Ignore the error, continue with next Decl.
1657  // FIXME: Handle this case somehow better.
1658  consumeError(ImportedOrErr.takeError());
1659  }
1660 
1661  return Error::success();
1662 }
1663 
1665  Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) {
1666  auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext());
1667  if (!ToDCOrErr)
1668  return ToDCOrErr.takeError();
1669  ToDC = *ToDCOrErr;
1670 
1671  if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) {
1672  auto ToLexicalDCOrErr = Importer.ImportContext(
1673  FromD->getLexicalDeclContext());
1674  if (!ToLexicalDCOrErr)
1675  return ToLexicalDCOrErr.takeError();
1676  ToLexicalDC = *ToLexicalDCOrErr;
1677  } else
1678  ToLexicalDC = ToDC;
1679 
1680  return Error::success();
1681 }
1682 
1684  const CXXRecordDecl *From, CXXRecordDecl *To) {
1685  assert(From->isCompleteDefinition() && To->getDefinition() == To &&
1686  "Import implicit methods to or from non-definition");
1687 
1688  for (CXXMethodDecl *FromM : From->methods())
1689  if (FromM->isImplicit()) {
1690  Expected<CXXMethodDecl *> ToMOrErr = import(FromM);
1691  if (!ToMOrErr)
1692  return ToMOrErr.takeError();
1693  }
1694 
1695  return Error::success();
1696 }
1697 
1699  ASTImporter &Importer) {
1700  if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
1701  Decl *ToTypedef = Importer.Import(FromTypedef);
1702  if (!ToTypedef)
1703  return make_error<ImportError>();
1704  To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(ToTypedef));
1705  // FIXME: This should be the final code.
1706  //if (Expected<Decl *> ToTypedefOrErr = Importer.Import(FromTypedef))
1707  // To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr));
1708  //else
1709  // return ToTypedefOrErr.takeError();
1710  }
1711  return Error::success();
1712 }
1713 
1716  if (To->getDefinition() || To->isBeingDefined()) {
1717  if (Kind == IDK_Everything)
1718  return ImportDeclContext(From, /*ForceImport=*/true);
1719 
1720  return Error::success();
1721  }
1722 
1723  To->startDefinition();
1724 
1725  if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
1726  return Err;
1727 
1728  // Add base classes.
1729  auto *ToCXX = dyn_cast<CXXRecordDecl>(To);
1730  auto *FromCXX = dyn_cast<CXXRecordDecl>(From);
1731  if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) {
1732 
1733  struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
1734  struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
1735  ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor;
1736  ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers;
1737  ToData.Aggregate = FromData.Aggregate;
1738  ToData.PlainOldData = FromData.PlainOldData;
1739  ToData.Empty = FromData.Empty;
1740  ToData.Polymorphic = FromData.Polymorphic;
1741  ToData.Abstract = FromData.Abstract;
1742  ToData.IsStandardLayout = FromData.IsStandardLayout;
1743  ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout;
1744  ToData.HasBasesWithFields = FromData.HasBasesWithFields;
1745  ToData.HasBasesWithNonStaticDataMembers =
1746  FromData.HasBasesWithNonStaticDataMembers;
1747  ToData.HasPrivateFields = FromData.HasPrivateFields;
1748  ToData.HasProtectedFields = FromData.HasProtectedFields;
1749  ToData.HasPublicFields = FromData.HasPublicFields;
1750  ToData.HasMutableFields = FromData.HasMutableFields;
1751  ToData.HasVariantMembers = FromData.HasVariantMembers;
1752  ToData.HasOnlyCMembers = FromData.HasOnlyCMembers;
1753  ToData.HasInClassInitializer = FromData.HasInClassInitializer;
1754  ToData.HasUninitializedReferenceMember
1755  = FromData.HasUninitializedReferenceMember;
1756  ToData.HasUninitializedFields = FromData.HasUninitializedFields;
1757  ToData.HasInheritedConstructor = FromData.HasInheritedConstructor;
1758  ToData.HasInheritedAssignment = FromData.HasInheritedAssignment;
1759  ToData.NeedOverloadResolutionForCopyConstructor
1760  = FromData.NeedOverloadResolutionForCopyConstructor;
1761  ToData.NeedOverloadResolutionForMoveConstructor
1762  = FromData.NeedOverloadResolutionForMoveConstructor;
1763  ToData.NeedOverloadResolutionForMoveAssignment
1764  = FromData.NeedOverloadResolutionForMoveAssignment;
1765  ToData.NeedOverloadResolutionForDestructor
1766  = FromData.NeedOverloadResolutionForDestructor;
1767  ToData.DefaultedCopyConstructorIsDeleted
1768  = FromData.DefaultedCopyConstructorIsDeleted;
1769  ToData.DefaultedMoveConstructorIsDeleted
1770  = FromData.DefaultedMoveConstructorIsDeleted;
1771  ToData.DefaultedMoveAssignmentIsDeleted
1772  = FromData.DefaultedMoveAssignmentIsDeleted;
1773  ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted;
1774  ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers;
1775  ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor;
1776  ToData.HasConstexprNonCopyMoveConstructor
1777  = FromData.HasConstexprNonCopyMoveConstructor;
1778  ToData.HasDefaultedDefaultConstructor
1779  = FromData.HasDefaultedDefaultConstructor;
1780  ToData.DefaultedDefaultConstructorIsConstexpr
1781  = FromData.DefaultedDefaultConstructorIsConstexpr;
1782  ToData.HasConstexprDefaultConstructor
1783  = FromData.HasConstexprDefaultConstructor;
1784  ToData.HasNonLiteralTypeFieldsOrBases
1785  = FromData.HasNonLiteralTypeFieldsOrBases;
1786  // ComputedVisibleConversions not imported.
1787  ToData.UserProvidedDefaultConstructor
1788  = FromData.UserProvidedDefaultConstructor;
1789  ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers;
1790  ToData.ImplicitCopyConstructorCanHaveConstParamForVBase
1791  = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase;
1792  ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase
1793  = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase;
1794  ToData.ImplicitCopyAssignmentHasConstParam
1795  = FromData.ImplicitCopyAssignmentHasConstParam;
1796  ToData.HasDeclaredCopyConstructorWithConstParam
1797  = FromData.HasDeclaredCopyConstructorWithConstParam;
1798  ToData.HasDeclaredCopyAssignmentWithConstParam
1799  = FromData.HasDeclaredCopyAssignmentWithConstParam;
1800 
1802  for (const auto &Base1 : FromCXX->bases()) {
1803  ExpectedType TyOrErr = import(Base1.getType());
1804  if (!TyOrErr)
1805  return TyOrErr.takeError();
1806 
1807  SourceLocation EllipsisLoc;
1808  if (Base1.isPackExpansion()) {
1809  if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc()))
1810  EllipsisLoc = *LocOrErr;
1811  else
1812  return LocOrErr.takeError();
1813  }
1814 
1815  // Ensure that we have a definition for the base.
1816  if (Error Err =
1817  ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
1818  return Err;
1819 
1820  auto RangeOrErr = import(Base1.getSourceRange());
1821  if (!RangeOrErr)
1822  return RangeOrErr.takeError();
1823 
1824  auto TSIOrErr = import(Base1.getTypeSourceInfo());
1825  if (!TSIOrErr)
1826  return TSIOrErr.takeError();
1827 
1828  Bases.push_back(
1829  new (Importer.getToContext()) CXXBaseSpecifier(
1830  *RangeOrErr,
1831  Base1.isVirtual(),
1832  Base1.isBaseOfClass(),
1833  Base1.getAccessSpecifierAsWritten(),
1834  *TSIOrErr,
1835  EllipsisLoc));
1836  }
1837  if (!Bases.empty())
1838  ToCXX->setBases(Bases.data(), Bases.size());
1839  }
1840 
1841  if (shouldForceImportDeclContext(Kind))
1842  if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
1843  return Err;
1844 
1845  To->completeDefinition();
1846  return Error::success();
1847 }
1848 
1850  if (To->getAnyInitializer())
1851  return Error::success();
1852 
1853  Expr *FromInit = From->getInit();
1854  if (!FromInit)
1855  return Error::success();
1856 
1857  ExpectedExpr ToInitOrErr = import(FromInit);
1858  if (!ToInitOrErr)
1859  return ToInitOrErr.takeError();
1860 
1861  To->setInit(*ToInitOrErr);
1862  if (From->isInitKnownICE()) {
1863  EvaluatedStmt *Eval = To->ensureEvaluatedStmt();
1864  Eval->CheckedICE = true;
1865  Eval->IsICE = From->isInitICE();
1866  }
1867 
1868  // FIXME: Other bits to merge?
1869  return Error::success();
1870 }
1871 
1874  if (To->getDefinition() || To->isBeingDefined()) {
1875  if (Kind == IDK_Everything)
1876  return ImportDeclContext(From, /*ForceImport=*/true);
1877  return Error::success();
1878  }
1879 
1880  To->startDefinition();
1881 
1882  if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
1883  return Err;
1884 
1885  ExpectedType ToTypeOrErr =
1886  import(Importer.getFromContext().getTypeDeclType(From));
1887  if (!ToTypeOrErr)
1888  return ToTypeOrErr.takeError();
1889 
1890  ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType());
1891  if (!ToPromotionTypeOrErr)
1892  return ToPromotionTypeOrErr.takeError();
1893 
1894  if (shouldForceImportDeclContext(Kind))
1895  if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
1896  return Err;
1897 
1898  // FIXME: we might need to merge the number of positive or negative bits
1899  // if the enumerator lists don't match.
1900  To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr,
1901  From->getNumPositiveBits(),
1902  From->getNumNegativeBits());
1903  return Error::success();
1904 }
1905 
1906 // FIXME: Remove this, use `import` instead.
1908  TemplateParameterList *Params) {
1909  SmallVector<NamedDecl *, 4> ToParams(Params->size());
1910  if (Error Err = ImportContainerChecked(*Params, ToParams))
1911  return std::move(Err);
1912 
1913  Expr *ToRequiresClause;
1914  if (Expr *const R = Params->getRequiresClause()) {
1915  if (Error Err = importInto(ToRequiresClause, R))
1916  return std::move(Err);
1917  } else {
1918  ToRequiresClause = nullptr;
1919  }
1920 
1921  auto ToTemplateLocOrErr = import(Params->getTemplateLoc());
1922  if (!ToTemplateLocOrErr)
1923  return ToTemplateLocOrErr.takeError();
1924  auto ToLAngleLocOrErr = import(Params->getLAngleLoc());
1925  if (!ToLAngleLocOrErr)
1926  return ToLAngleLocOrErr.takeError();
1927  auto ToRAngleLocOrErr = import(Params->getRAngleLoc());
1928  if (!ToRAngleLocOrErr)
1929  return ToRAngleLocOrErr.takeError();
1930 
1932  Importer.getToContext(),
1933  *ToTemplateLocOrErr,
1934  *ToLAngleLocOrErr,
1935  ToParams,
1936  *ToRAngleLocOrErr,
1937  ToRequiresClause);
1938 }
1939 
1941  const TemplateArgument *FromArgs, unsigned NumFromArgs,
1943  for (unsigned I = 0; I != NumFromArgs; ++I) {
1944  if (auto ToOrErr = import(FromArgs[I]))
1945  ToArgs.push_back(*ToOrErr);
1946  else
1947  return ToOrErr.takeError();
1948  }
1949 
1950  return Error::success();
1951 }
1952 
1953 // FIXME: Do not forget to remove this and use only 'import'.
1956  return import(From);
1957 }
1958 
1959 template <typename InContainerTy>
1961  const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) {
1962  for (const auto &FromLoc : Container) {
1963  if (auto ToLocOrErr = import(FromLoc))
1964  ToTAInfo.addArgument(*ToLocOrErr);
1965  else
1966  return ToLocOrErr.takeError();
1967  }
1968  return Error::success();
1969 }
1970 
1975 }
1976 
1977 bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) {
1979  Importer.getFromContext(), Importer.getToContext(),
1980  Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer),
1981  false, Complain);
1982  return Ctx.IsEquivalent(From, To);
1983 }
1984 
1986  RecordDecl *ToRecord, bool Complain) {
1987  // Eliminate a potential failure point where we attempt to re-import
1988  // something we're trying to import while completing ToRecord.
1989  Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord);
1990  if (ToOrigin) {
1991  auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin);
1992  if (ToOriginRecord)
1993  ToRecord = ToOriginRecord;
1994  }
1995 
1996  StructuralEquivalenceContext Ctx(Importer.getFromContext(),
1997  ToRecord->getASTContext(),
1998  Importer.getNonEquivalentDecls(),
1999  getStructuralEquivalenceKind(Importer),
2000  false, Complain);
2001  return Ctx.IsEquivalent(FromRecord, ToRecord);
2002 }
2003 
2005  bool Complain) {
2007  Importer.getFromContext(), Importer.getToContext(),
2008  Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer),
2009  false, Complain);
2010  return Ctx.IsEquivalent(FromVar, ToVar);
2011 }
2012 
2015  Importer.getFromContext(), Importer.getToContext(),
2016  Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer));
2017  return Ctx.IsEquivalent(FromEnum, ToEnum);
2018 }
2019 
2021  FunctionTemplateDecl *To) {
2023  Importer.getFromContext(), Importer.getToContext(),
2024  Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer),
2025  false, false);
2026  return Ctx.IsEquivalent(From, To);
2027 }
2028 
2031  Importer.getFromContext(), Importer.getToContext(),
2032  Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer),
2033  false, false);
2034  return Ctx.IsEquivalent(From, To);
2035 }
2036 
2038  EnumConstantDecl *ToEC) {
2039  const llvm::APSInt &FromVal = FromEC->getInitVal();
2040  const llvm::APSInt &ToVal = ToEC->getInitVal();
2041 
2042  return FromVal.isSigned() == ToVal.isSigned() &&
2043  FromVal.getBitWidth() == ToVal.getBitWidth() &&
2044  FromVal == ToVal;
2045 }
2046 
2048  ClassTemplateDecl *To) {
2049  StructuralEquivalenceContext Ctx(Importer.getFromContext(),
2050  Importer.getToContext(),
2051  Importer.getNonEquivalentDecls(),
2052  getStructuralEquivalenceKind(Importer));
2053  return Ctx.IsEquivalent(From, To);
2054 }
2055 
2057  VarTemplateDecl *To) {
2058  StructuralEquivalenceContext Ctx(Importer.getFromContext(),
2059  Importer.getToContext(),
2060  Importer.getNonEquivalentDecls(),
2061  getStructuralEquivalenceKind(Importer));
2062  return Ctx.IsEquivalent(From, To);
2063 }
2064 
2066  Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2067  << D->getDeclKindName();
2068  return make_error<ImportError>(ImportError::UnsupportedConstruct);
2069 }
2070 
2072  Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2073  << D->getDeclKindName();
2074  return make_error<ImportError>(ImportError::UnsupportedConstruct);
2075 }
2076 
2078  // Import the context of this declaration.
2079  DeclContext *DC, *LexicalDC;
2080  if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2081  return std::move(Err);
2082 
2083  // Import the location of this declaration.
2084  ExpectedSLoc LocOrErr = import(D->getLocation());
2085  if (!LocOrErr)
2086  return LocOrErr.takeError();
2087 
2088  EmptyDecl *ToD;
2089  if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr))
2090  return ToD;
2091 
2092  ToD->setLexicalDeclContext(LexicalDC);
2093  LexicalDC->addDeclInternal(ToD);
2094  return ToD;
2095 }
2096 
2098  TranslationUnitDecl *ToD =
2099  Importer.getToContext().getTranslationUnitDecl();
2100 
2101  Importer.MapImported(D, ToD);
2102 
2103  return ToD;
2104 }
2105 
2107  ExpectedSLoc LocOrErr = import(D->getLocation());
2108  if (!LocOrErr)
2109  return LocOrErr.takeError();
2110  auto ColonLocOrErr = import(D->getColonLoc());
2111  if (!ColonLocOrErr)
2112  return ColonLocOrErr.takeError();
2113 
2114  // Import the context of this declaration.
2115  auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2116  if (!DCOrErr)
2117  return DCOrErr.takeError();
2118  DeclContext *DC = *DCOrErr;
2119 
2120  AccessSpecDecl *ToD;
2121  if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(),
2122  DC, *LocOrErr, *ColonLocOrErr))
2123  return ToD;
2124 
2125  // Lexical DeclContext and Semantic DeclContext
2126  // is always the same for the accessSpec.
2127  ToD->setLexicalDeclContext(DC);
2128  DC->addDeclInternal(ToD);
2129 
2130  return ToD;
2131 }
2132 
2134  auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2135  if (!DCOrErr)
2136  return DCOrErr.takeError();
2137  DeclContext *DC = *DCOrErr;
2138  DeclContext *LexicalDC = DC;
2139 
2140  SourceLocation ToLocation, ToRParenLoc;
2141  Expr *ToAssertExpr;
2142  StringLiteral *ToMessage;
2143  if (auto Imp = importSeq(
2144  D->getLocation(), D->getAssertExpr(), D->getMessage(), D->getRParenLoc()))
2145  std::tie(ToLocation, ToAssertExpr, ToMessage, ToRParenLoc) = *Imp;
2146  else
2147  return Imp.takeError();
2148 
2149  StaticAssertDecl *ToD;
2150  if (GetImportedOrCreateDecl(
2151  ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
2152  ToRParenLoc, D->isFailed()))
2153  return ToD;
2154 
2155  ToD->setLexicalDeclContext(LexicalDC);
2156  LexicalDC->addDeclInternal(ToD);
2157  return ToD;
2158 }
2159 
2161  // Import the major distinguishing characteristics of this namespace.
2162  DeclContext *DC, *LexicalDC;
2163  DeclarationName Name;
2164  SourceLocation Loc;
2165  NamedDecl *ToD;
2166  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2167  return std::move(Err);
2168  if (ToD)
2169  return ToD;
2170 
2171  NamespaceDecl *MergeWithNamespace = nullptr;
2172  if (!Name) {
2173  // This is an anonymous namespace. Adopt an existing anonymous
2174  // namespace if we can.
2175  // FIXME: Not testable.
2176  if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2177  MergeWithNamespace = TU->getAnonymousNamespace();
2178  else
2179  MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace();
2180  } else {
2181  SmallVector<NamedDecl *, 4> ConflictingDecls;
2182  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2183  for (auto *FoundDecl : FoundDecls) {
2185  continue;
2186 
2187  if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) {
2188  MergeWithNamespace = FoundNS;
2189  ConflictingDecls.clear();
2190  break;
2191  }
2192 
2193  ConflictingDecls.push_back(FoundDecl);
2194  }
2195 
2196  if (!ConflictingDecls.empty()) {
2197  Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace,
2198  ConflictingDecls.data(),
2199  ConflictingDecls.size());
2200  if (!Name)
2201  return make_error<ImportError>(ImportError::NameConflict);
2202  }
2203  }
2204 
2205  ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2206  if (!BeginLocOrErr)
2207  return BeginLocOrErr.takeError();
2208 
2209  // Create the "to" namespace, if needed.
2210  NamespaceDecl *ToNamespace = MergeWithNamespace;
2211  if (!ToNamespace) {
2212  if (GetImportedOrCreateDecl(
2213  ToNamespace, D, Importer.getToContext(), DC, D->isInline(),
2214  *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(),
2215  /*PrevDecl=*/nullptr))
2216  return ToNamespace;
2217  ToNamespace->setLexicalDeclContext(LexicalDC);
2218  LexicalDC->addDeclInternal(ToNamespace);
2219 
2220  // If this is an anonymous namespace, register it as the anonymous
2221  // namespace within its context.
2222  if (!Name) {
2223  if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2224  TU->setAnonymousNamespace(ToNamespace);
2225  else
2226  cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
2227  }
2228  }
2229  Importer.MapImported(D, ToNamespace);
2230 
2231  if (Error Err = ImportDeclContext(D))
2232  return std::move(Err);
2233 
2234  return ToNamespace;
2235 }
2236 
2238  // Import the major distinguishing characteristics of this namespace.
2239  DeclContext *DC, *LexicalDC;
2240  DeclarationName Name;
2241  SourceLocation Loc;
2242  NamedDecl *LookupD;
2243  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc))
2244  return std::move(Err);
2245  if (LookupD)
2246  return LookupD;
2247 
2248  // NOTE: No conflict resolution is done for namespace aliases now.
2249 
2250  SourceLocation ToNamespaceLoc, ToAliasLoc, ToTargetNameLoc;
2251  NestedNameSpecifierLoc ToQualifierLoc;
2252  NamespaceDecl *ToNamespace;
2253  if (auto Imp = importSeq(
2254  D->getNamespaceLoc(), D->getAliasLoc(), D->getQualifierLoc(),
2255  D->getTargetNameLoc(), D->getNamespace()))
2256  std::tie(
2257  ToNamespaceLoc, ToAliasLoc, ToQualifierLoc, ToTargetNameLoc,
2258  ToNamespace) = *Imp;
2259  else
2260  return Imp.takeError();
2261  IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
2262 
2263  NamespaceAliasDecl *ToD;
2264  if (GetImportedOrCreateDecl(
2265  ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
2266  ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
2267  return ToD;
2268 
2269  ToD->setLexicalDeclContext(LexicalDC);
2270  LexicalDC->addDeclInternal(ToD);
2271 
2272  return ToD;
2273 }
2274 
2277  // Import the major distinguishing characteristics of this typedef.
2278  DeclContext *DC, *LexicalDC;
2279  DeclarationName Name;
2280  SourceLocation Loc;
2281  NamedDecl *ToD;
2282  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2283  return std::move(Err);
2284  if (ToD)
2285  return ToD;
2286 
2287  // If this typedef is not in block scope, determine whether we've
2288  // seen a typedef with the same name (that we can merge with) or any
2289  // other entity by that name (which name lookup could conflict with).
2290  if (!DC->isFunctionOrMethod()) {
2291  SmallVector<NamedDecl *, 4> ConflictingDecls;
2292  unsigned IDNS = Decl::IDNS_Ordinary;
2293  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2294  for (auto *FoundDecl : FoundDecls) {
2295  if (!FoundDecl->isInIdentifierNamespace(IDNS))
2296  continue;
2297  if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
2298  QualType FromUT = D->getUnderlyingType();
2299  QualType FoundUT = FoundTypedef->getUnderlyingType();
2300  if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) {
2301  // If the "From" context has a complete underlying type but we
2302  // already have a complete underlying type then return with that.
2303  if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
2304  return Importer.MapImported(D, FoundTypedef);
2305  }
2306  // FIXME Handle redecl chain.
2307  break;
2308  }
2309 
2310  ConflictingDecls.push_back(FoundDecl);
2311  }
2312 
2313  if (!ConflictingDecls.empty()) {
2314  Name = Importer.HandleNameConflict(Name, DC, IDNS,
2315  ConflictingDecls.data(),
2316  ConflictingDecls.size());
2317  if (!Name)
2318  return make_error<ImportError>(ImportError::NameConflict);
2319  }
2320  }
2321 
2322  QualType ToUnderlyingType;
2323  TypeSourceInfo *ToTypeSourceInfo;
2324  SourceLocation ToBeginLoc;
2325  if (auto Imp = importSeq(
2327  std::tie(ToUnderlyingType, ToTypeSourceInfo, ToBeginLoc) = *Imp;
2328  else
2329  return Imp.takeError();
2330 
2331  // Create the new typedef node.
2332  // FIXME: ToUnderlyingType is not used.
2333  TypedefNameDecl *ToTypedef;
2334  if (IsAlias) {
2335  if (GetImportedOrCreateDecl<TypeAliasDecl>(
2336  ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
2337  Name.getAsIdentifierInfo(), ToTypeSourceInfo))
2338  return ToTypedef;
2339  } else if (GetImportedOrCreateDecl<TypedefDecl>(
2340  ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
2341  Name.getAsIdentifierInfo(), ToTypeSourceInfo))
2342  return ToTypedef;
2343 
2344  ToTypedef->setAccess(D->getAccess());
2345  ToTypedef->setLexicalDeclContext(LexicalDC);
2346 
2347  // Templated declarations should not appear in DeclContext.
2348  TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr;
2349  if (!FromAlias || !FromAlias->getDescribedAliasTemplate())
2350  LexicalDC->addDeclInternal(ToTypedef);
2351 
2352  return ToTypedef;
2353 }
2354 
2356  return VisitTypedefNameDecl(D, /*IsAlias=*/false);
2357 }
2358 
2360  return VisitTypedefNameDecl(D, /*IsAlias=*/true);
2361 }
2362 
2365  // Import the major distinguishing characteristics of this typedef.
2366  DeclContext *DC, *LexicalDC;
2367  DeclarationName Name;
2368  SourceLocation Loc;
2369  NamedDecl *FoundD;
2370  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc))
2371  return std::move(Err);
2372  if (FoundD)
2373  return FoundD;
2374 
2375  // If this typedef is not in block scope, determine whether we've
2376  // seen a typedef with the same name (that we can merge with) or any
2377  // other entity by that name (which name lookup could conflict with).
2378  if (!DC->isFunctionOrMethod()) {
2379  SmallVector<NamedDecl *, 4> ConflictingDecls;
2380  unsigned IDNS = Decl::IDNS_Ordinary;
2381  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2382  for (auto *FoundDecl : FoundDecls) {
2383  if (!FoundDecl->isInIdentifierNamespace(IDNS))
2384  continue;
2385  if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl))
2386  return Importer.MapImported(D, FoundAlias);
2387  ConflictingDecls.push_back(FoundDecl);
2388  }
2389 
2390  if (!ConflictingDecls.empty()) {
2391  Name = Importer.HandleNameConflict(Name, DC, IDNS,
2392  ConflictingDecls.data(),
2393  ConflictingDecls.size());
2394  if (!Name)
2395  return make_error<ImportError>(ImportError::NameConflict);
2396  }
2397  }
2398 
2399  TemplateParameterList *ToTemplateParameters;
2400  TypeAliasDecl *ToTemplatedDecl;
2401  if (auto Imp = importSeq(D->getTemplateParameters(), D->getTemplatedDecl()))
2402  std::tie(ToTemplateParameters, ToTemplatedDecl) = *Imp;
2403  else
2404  return Imp.takeError();
2405 
2406  TypeAliasTemplateDecl *ToAlias;
2407  if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc,
2408  Name, ToTemplateParameters, ToTemplatedDecl))
2409  return ToAlias;
2410 
2411  ToTemplatedDecl->setDescribedAliasTemplate(ToAlias);
2412 
2413  ToAlias->setAccess(D->getAccess());
2414  ToAlias->setLexicalDeclContext(LexicalDC);
2415  LexicalDC->addDeclInternal(ToAlias);
2416  return ToAlias;
2417 }
2418 
2420  // Import the major distinguishing characteristics of this label.
2421  DeclContext *DC, *LexicalDC;
2422  DeclarationName Name;
2423  SourceLocation Loc;
2424  NamedDecl *ToD;
2425  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2426  return std::move(Err);
2427  if (ToD)
2428  return ToD;
2429 
2430  assert(LexicalDC->isFunctionOrMethod());
2431 
2432  LabelDecl *ToLabel;
2433  if (D->isGnuLocal()) {
2434  ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2435  if (!BeginLocOrErr)
2436  return BeginLocOrErr.takeError();
2437  if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
2438  Name.getAsIdentifierInfo(), *BeginLocOrErr))
2439  return ToLabel;
2440 
2441  } else {
2442  if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
2443  Name.getAsIdentifierInfo()))
2444  return ToLabel;
2445 
2446  }
2447 
2448  Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
2449  if (!ToStmtOrErr)
2450  return ToStmtOrErr.takeError();
2451 
2452  ToLabel->setStmt(*ToStmtOrErr);
2453  ToLabel->setLexicalDeclContext(LexicalDC);
2454  LexicalDC->addDeclInternal(ToLabel);
2455  return ToLabel;
2456 }
2457 
2459  // Import the major distinguishing characteristics of this enum.
2460  DeclContext *DC, *LexicalDC;
2461  DeclarationName Name;
2462  SourceLocation Loc;
2463  NamedDecl *ToD;
2464  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2465  return std::move(Err);
2466  if (ToD)
2467  return ToD;
2468 
2469  // Figure out what enum name we're looking for.
2470  unsigned IDNS = Decl::IDNS_Tag;
2471  DeclarationName SearchName = Name;
2472  if (!SearchName && D->getTypedefNameForAnonDecl()) {
2473  if (Error Err = importInto(
2474  SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
2475  return std::move(Err);
2476  IDNS = Decl::IDNS_Ordinary;
2477  } else if (Importer.getToContext().getLangOpts().CPlusPlus)
2478  IDNS |= Decl::IDNS_Ordinary;
2479 
2480  // We may already have an enum of the same name; try to find and match it.
2481  if (!DC->isFunctionOrMethod() && SearchName) {
2482  SmallVector<NamedDecl *, 4> ConflictingDecls;
2483  auto FoundDecls =
2484  Importer.findDeclsInToCtx(DC, SearchName);
2485  for (auto *FoundDecl : FoundDecls) {
2486  if (!FoundDecl->isInIdentifierNamespace(IDNS))
2487  continue;
2488 
2489  if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
2490  if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
2491  FoundDecl = Tag->getDecl();
2492  }
2493 
2494  if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) {
2495  if (IsStructuralMatch(D, FoundEnum))
2496  return Importer.MapImported(D, FoundEnum);
2497  }
2498 
2499  ConflictingDecls.push_back(FoundDecl);
2500  }
2501 
2502  if (!ConflictingDecls.empty()) {
2503  Name = Importer.HandleNameConflict(Name, DC, IDNS,
2504  ConflictingDecls.data(),
2505  ConflictingDecls.size());
2506  if (!Name)
2507  return make_error<ImportError>(ImportError::NameConflict);
2508  }
2509  }
2510 
2511  SourceLocation ToBeginLoc;
2512  NestedNameSpecifierLoc ToQualifierLoc;
2513  QualType ToIntegerType;
2514  if (auto Imp = importSeq(
2515  D->getBeginLoc(), D->getQualifierLoc(), D->getIntegerType()))
2516  std::tie(ToBeginLoc, ToQualifierLoc, ToIntegerType) = *Imp;
2517  else
2518  return Imp.takeError();
2519 
2520  // Create the enum declaration.
2521  EnumDecl *D2;
2522  if (GetImportedOrCreateDecl(
2523  D2, D, Importer.getToContext(), DC, ToBeginLoc,
2524  Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(),
2525  D->isScopedUsingClassTag(), D->isFixed()))
2526  return D2;
2527 
2528  D2->setQualifierInfo(ToQualifierLoc);
2529  D2->setIntegerType(ToIntegerType);
2530  D2->setAccess(D->getAccess());
2531  D2->setLexicalDeclContext(LexicalDC);
2532  LexicalDC->addDeclInternal(D2);
2533 
2534  // Import the definition
2535  if (D->isCompleteDefinition())
2536  if (Error Err = ImportDefinition(D, D2))
2537  return std::move(Err);
2538 
2539  return D2;
2540 }
2541 
2543  bool IsFriendTemplate = false;
2544  if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
2545  IsFriendTemplate =
2546  DCXX->getDescribedClassTemplate() &&
2547  DCXX->getDescribedClassTemplate()->getFriendObjectKind() !=
2549  }
2550 
2551  // If this record has a definition in the translation unit we're coming from,
2552  // but this particular declaration is not that definition, import the
2553  // definition and map to that.
2554  TagDecl *Definition = D->getDefinition();
2555  if (Definition && Definition != D &&
2556  // Friend template declaration must be imported on its own.
2557  !IsFriendTemplate &&
2558  // In contrast to a normal CXXRecordDecl, the implicit
2559  // CXXRecordDecl of ClassTemplateSpecializationDecl is its redeclaration.
2560  // The definition of the implicit CXXRecordDecl in this case is the
2561  // ClassTemplateSpecializationDecl itself. Thus, we start with an extra
2562  // condition in order to be able to import the implict Decl.
2563  !D->isImplicit()) {
2564  ExpectedDecl ImportedDefOrErr = import(Definition);
2565  if (!ImportedDefOrErr)
2566  return ImportedDefOrErr.takeError();
2567 
2568  return Importer.MapImported(D, *ImportedDefOrErr);
2569  }
2570 
2571  // Import the major distinguishing characteristics of this record.
2572  DeclContext *DC, *LexicalDC;
2573  DeclarationName Name;
2574  SourceLocation Loc;
2575  NamedDecl *ToD;
2576  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2577  return std::move(Err);
2578  if (ToD)
2579  return ToD;
2580 
2581  // Figure out what structure name we're looking for.
2582  unsigned IDNS = Decl::IDNS_Tag;
2583  DeclarationName SearchName = Name;
2584  if (!SearchName && D->getTypedefNameForAnonDecl()) {
2585  if (Error Err = importInto(
2586  SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
2587  return std::move(Err);
2588  IDNS = Decl::IDNS_Ordinary;
2589  } else if (Importer.getToContext().getLangOpts().CPlusPlus)
2591 
2592  // We may already have a record of the same name; try to find and match it.
2593  RecordDecl *PrevDecl = nullptr;
2594  if (!DC->isFunctionOrMethod()) {
2595  SmallVector<NamedDecl *, 4> ConflictingDecls;
2596  auto FoundDecls =
2597  Importer.findDeclsInToCtx(DC, SearchName);
2598  if (!FoundDecls.empty()) {
2599  // We're going to have to compare D against potentially conflicting Decls, so complete it.
2602  }
2603 
2604  for (auto *FoundDecl : FoundDecls) {
2605  if (!FoundDecl->isInIdentifierNamespace(IDNS))
2606  continue;
2607 
2608  Decl *Found = FoundDecl;
2609  if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
2610  if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
2611  Found = Tag->getDecl();
2612  }
2613 
2614  if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) {
2615  // Do not emit false positive diagnostic in case of unnamed
2616  // struct/union and in case of anonymous structs. Would be false
2617  // because there may be several anonymous/unnamed structs in a class.
2618  // E.g. these are both valid:
2619  // struct A { // unnamed structs
2620  // struct { struct A *next; } entry0;
2621  // struct { struct A *next; } entry1;
2622  // };
2623  // struct X { struct { int a; }; struct { int b; }; }; // anon structs
2624  if (!SearchName)
2625  if (!IsStructuralMatch(D, FoundRecord, false))
2626  continue;
2627 
2628  if (IsStructuralMatch(D, FoundRecord)) {
2629  RecordDecl *FoundDef = FoundRecord->getDefinition();
2630  if (D->isThisDeclarationADefinition() && FoundDef) {
2631  // FIXME: Structural equivalence check should check for same
2632  // user-defined methods.
2633  Importer.MapImported(D, FoundDef);
2634  if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
2635  auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef);
2636  assert(FoundCXX && "Record type mismatch");
2637 
2638  if (!Importer.isMinimalImport())
2639  // FoundDef may not have every implicit method that D has
2640  // because implicit methods are created only if they are used.
2641  if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
2642  return std::move(Err);
2643  }
2644  }
2645  PrevDecl = FoundRecord->getMostRecentDecl();
2646  break;
2647  }
2648  }
2649 
2650  ConflictingDecls.push_back(FoundDecl);
2651  } // for
2652 
2653  if (!ConflictingDecls.empty() && SearchName) {
2654  Name = Importer.HandleNameConflict(Name, DC, IDNS,
2655  ConflictingDecls.data(),
2656  ConflictingDecls.size());
2657  if (!Name)
2658  return make_error<ImportError>(ImportError::NameConflict);
2659  }
2660  }
2661 
2662  ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2663  if (!BeginLocOrErr)
2664  return BeginLocOrErr.takeError();
2665 
2666  // Create the record declaration.
2667  RecordDecl *D2 = nullptr;
2668  CXXRecordDecl *D2CXX = nullptr;
2669  if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
2670  if (DCXX->isLambda()) {
2671  auto TInfoOrErr = import(DCXX->getLambdaTypeInfo());
2672  if (!TInfoOrErr)
2673  return TInfoOrErr.takeError();
2674  if (GetImportedOrCreateSpecialDecl(
2675  D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(),
2676  DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(),
2677  DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault()))
2678  return D2CXX;
2679  ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl());
2680  if (!CDeclOrErr)
2681  return CDeclOrErr.takeError();
2682  D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr);
2683  } else if (DCXX->isInjectedClassName()) {
2684  // We have to be careful to do a similar dance to the one in
2685  // Sema::ActOnStartCXXMemberDeclarations
2686  const bool DelayTypeCreation = true;
2687  if (GetImportedOrCreateDecl(
2688  D2CXX, D, Importer.getToContext(), D->getTagKind(), DC,
2689  *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(),
2690  cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation))
2691  return D2CXX;
2692  Importer.getToContext().getTypeDeclType(
2693  D2CXX, dyn_cast<CXXRecordDecl>(DC));
2694  } else {
2695  if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
2696  D->getTagKind(), DC, *BeginLocOrErr, Loc,
2697  Name.getAsIdentifierInfo(),
2698  cast_or_null<CXXRecordDecl>(PrevDecl)))
2699  return D2CXX;
2700  }
2701 
2702  D2 = D2CXX;
2703  D2->setAccess(D->getAccess());
2704  D2->setLexicalDeclContext(LexicalDC);
2705  if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit())
2706  LexicalDC->addDeclInternal(D2);
2707 
2708  if (LexicalDC != DC && D->isInIdentifierNamespace(Decl::IDNS_TagFriend))
2709  DC->makeDeclVisibleInContext(D2);
2710 
2711  if (ClassTemplateDecl *FromDescribed =
2712  DCXX->getDescribedClassTemplate()) {
2713  ClassTemplateDecl *ToDescribed;
2714  if (Error Err = importInto(ToDescribed, FromDescribed))
2715  return std::move(Err);
2716  D2CXX->setDescribedClassTemplate(ToDescribed);
2717  if (!DCXX->isInjectedClassName() && !IsFriendTemplate) {
2718  // In a record describing a template the type should be an
2719  // InjectedClassNameType (see Sema::CheckClassTemplate). Update the
2720  // previously set type to the correct value here (ToDescribed is not
2721  // available at record create).
2722  // FIXME: The previous type is cleared but not removed from
2723  // ASTContext's internal storage.
2724  CXXRecordDecl *Injected = nullptr;
2725  for (NamedDecl *Found : D2CXX->noload_lookup(Name)) {
2726  auto *Record = dyn_cast<CXXRecordDecl>(Found);
2727  if (Record && Record->isInjectedClassName()) {
2728  Injected = Record;
2729  break;
2730  }
2731  }
2732  // Create an injected type for the whole redecl chain.
2733  SmallVector<Decl *, 2> Redecls =
2735  for (auto *R : Redecls) {
2736  auto *RI = cast<CXXRecordDecl>(R);
2737  RI->setTypeForDecl(nullptr);
2738  // Below we create a new injected type and assign that to the
2739  // canonical decl, subsequent declarations in the chain will reuse
2740  // that type.
2741  Importer.getToContext().getInjectedClassNameType(
2742  RI, ToDescribed->getInjectedClassNameSpecialization());
2743  }
2744  // Set the new type for the previous injected decl too.
2745  if (Injected) {
2746  Injected->setTypeForDecl(nullptr);
2747  Importer.getToContext().getTypeDeclType(Injected, D2CXX);
2748  }
2749  }
2750  } else if (MemberSpecializationInfo *MemberInfo =
2751  DCXX->getMemberSpecializationInfo()) {
2753  MemberInfo->getTemplateSpecializationKind();
2754  CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass();
2755 
2756  if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
2757  D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
2758  else
2759  return ToInstOrErr.takeError();
2760 
2761  if (ExpectedSLoc POIOrErr =
2762  import(MemberInfo->getPointOfInstantiation()))
2764  *POIOrErr);
2765  else
2766  return POIOrErr.takeError();
2767  }
2768 
2769  } else {
2770  if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
2771  D->getTagKind(), DC, *BeginLocOrErr, Loc,
2772  Name.getAsIdentifierInfo(), PrevDecl))
2773  return D2;
2774  D2->setLexicalDeclContext(LexicalDC);
2775  LexicalDC->addDeclInternal(D2);
2776  }
2777 
2778  if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
2779  D2->setQualifierInfo(*QualifierLocOrErr);
2780  else
2781  return QualifierLocOrErr.takeError();
2782 
2783  if (D->isAnonymousStructOrUnion())
2784  D2->setAnonymousStructOrUnion(true);
2785 
2786  if (D->isCompleteDefinition())
2787  if (Error Err = ImportDefinition(D, D2, IDK_Default))
2788  return std::move(Err);
2789 
2790  return D2;
2791 }
2792 
2794  // Import the major distinguishing characteristics of this enumerator.
2795  DeclContext *DC, *LexicalDC;
2796  DeclarationName Name;
2797  SourceLocation Loc;
2798  NamedDecl *ToD;
2799  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2800  return std::move(Err);
2801  if (ToD)
2802  return ToD;
2803 
2804  // Determine whether there are any other declarations with the same name and
2805  // in the same context.
2806  if (!LexicalDC->isFunctionOrMethod()) {
2807  SmallVector<NamedDecl *, 4> ConflictingDecls;
2808  unsigned IDNS = Decl::IDNS_Ordinary;
2809  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2810  for (auto *FoundDecl : FoundDecls) {
2811  if (!FoundDecl->isInIdentifierNamespace(IDNS))
2812  continue;
2813 
2814  if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
2815  if (IsStructuralMatch(D, FoundEnumConstant))
2816  return Importer.MapImported(D, FoundEnumConstant);
2817  }
2818 
2819  ConflictingDecls.push_back(FoundDecl);
2820  }
2821 
2822  if (!ConflictingDecls.empty()) {
2823  Name = Importer.HandleNameConflict(Name, DC, IDNS,
2824  ConflictingDecls.data(),
2825  ConflictingDecls.size());
2826  if (!Name)
2827  return make_error<ImportError>(ImportError::NameConflict);
2828  }
2829  }
2830 
2831  ExpectedType TypeOrErr = import(D->getType());
2832  if (!TypeOrErr)
2833  return TypeOrErr.takeError();
2834 
2835  ExpectedExpr InitOrErr = import(D->getInitExpr());
2836  if (!InitOrErr)
2837  return InitOrErr.takeError();
2838 
2839  EnumConstantDecl *ToEnumerator;
2840  if (GetImportedOrCreateDecl(
2841  ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
2842  Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
2843  return ToEnumerator;
2844 
2845  ToEnumerator->setAccess(D->getAccess());
2846  ToEnumerator->setLexicalDeclContext(LexicalDC);
2847  LexicalDC->addDeclInternal(ToEnumerator);
2848  return ToEnumerator;
2849 }
2850 
2852  FunctionDecl *FromFD, FunctionDecl *ToFD) {
2853  switch (FromFD->getTemplatedKind()) {
2856  return Error::success();
2857 
2860 
2861  if (Expected<FunctionDecl *> InstFDOrErr =
2862  import(FromFD->getInstantiatedFromMemberFunction()))
2863  ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
2864  else
2865  return InstFDOrErr.takeError();
2866 
2867  if (ExpectedSLoc POIOrErr = import(
2870  else
2871  return POIOrErr.takeError();
2872 
2873  return Error::success();
2874  }
2875 
2877  auto FunctionAndArgsOrErr =
2878  ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD);
2879  if (!FunctionAndArgsOrErr)
2880  return FunctionAndArgsOrErr.takeError();
2881 
2883  Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
2884 
2885  auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
2886  TemplateArgumentListInfo ToTAInfo;
2887  const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
2888  if (FromTAArgsAsWritten)
2889  if (Error Err = ImportTemplateArgumentListInfo(
2890  *FromTAArgsAsWritten, ToTAInfo))
2891  return Err;
2892 
2893  ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
2894  if (!POIOrErr)
2895  return POIOrErr.takeError();
2896 
2897  TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
2898  ToFD->setFunctionTemplateSpecialization(
2899  std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr,
2900  TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
2901  return Error::success();
2902  }
2903 
2905  auto *FromInfo = FromFD->getDependentSpecializationInfo();
2906  UnresolvedSet<8> TemplDecls;
2907  unsigned NumTemplates = FromInfo->getNumTemplates();
2908  for (unsigned I = 0; I < NumTemplates; I++) {
2909  if (Expected<FunctionTemplateDecl *> ToFTDOrErr =
2910  import(FromInfo->getTemplate(I)))
2911  TemplDecls.addDecl(*ToFTDOrErr);
2912  else
2913  return ToFTDOrErr.takeError();
2914  }
2915 
2916  // Import TemplateArgumentListInfo.
2917  TemplateArgumentListInfo ToTAInfo;
2918  if (Error Err = ImportTemplateArgumentListInfo(
2919  FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(),
2920  llvm::makeArrayRef(
2921  FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()),
2922  ToTAInfo))
2923  return Err;
2924 
2925  ToFD->setDependentTemplateSpecialization(Importer.getToContext(),
2926  TemplDecls, ToTAInfo);
2927  return Error::success();
2928  }
2929  }
2930  llvm_unreachable("All cases should be covered!");
2931 }
2932 
2935  auto FunctionAndArgsOrErr =
2936  ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD);
2937  if (!FunctionAndArgsOrErr)
2938  return FunctionAndArgsOrErr.takeError();
2939 
2940  FunctionTemplateDecl *Template;
2941  TemplateArgsTy ToTemplArgs;
2942  std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
2943  void *InsertPos = nullptr;
2944  auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos);
2945  return FoundSpec;
2946 }
2947 
2949 
2951  auto RedeclIt = Redecls.begin();
2952  // Import the first part of the decl chain. I.e. import all previous
2953  // declarations starting from the canonical decl.
2954  for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
2955  ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
2956  if (!ToRedeclOrErr)
2957  return ToRedeclOrErr.takeError();
2958  }
2959  assert(*RedeclIt == D);
2960 
2961  // Import the major distinguishing characteristics of this function.
2962  DeclContext *DC, *LexicalDC;
2963  DeclarationName Name;
2964  SourceLocation Loc;
2965  NamedDecl *ToD;
2966  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2967  return std::move(Err);
2968  if (ToD)
2969  return ToD;
2970 
2971  const FunctionDecl *FoundByLookup = nullptr;
2973 
2974  // If this is a function template specialization, then try to find the same
2975  // existing specialization in the "to" context. The lookup below will not
2976  // find any specialization, but would find the primary template; thus, we
2977  // have to skip normal lookup in case of specializations.
2978  // FIXME handle member function templates (TK_MemberSpecialization) similarly?
2979  if (D->getTemplatedKind() ==
2981  auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
2982  if (!FoundFunctionOrErr)
2983  return FoundFunctionOrErr.takeError();
2984  if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
2985  if (D->doesThisDeclarationHaveABody() && FoundFunction->hasBody())
2986  return Importer.MapImported(D, FoundFunction);
2987  FoundByLookup = FoundFunction;
2988  }
2989  }
2990  // Try to find a function in our own ("to") context with the same name, same
2991  // type, and in the same context as the function we're importing.
2992  else if (!LexicalDC->isFunctionOrMethod()) {
2993  SmallVector<NamedDecl *, 4> ConflictingDecls;
2995  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2996  for (auto *FoundDecl : FoundDecls) {
2997  if (!FoundDecl->isInIdentifierNamespace(IDNS))
2998  continue;
2999 
3000  if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3001  if (FoundFunction->hasExternalFormalLinkage() &&
3002  D->hasExternalFormalLinkage()) {
3003  if (IsStructuralMatch(D, FoundFunction)) {
3004  const FunctionDecl *Definition = nullptr;
3005  if (D->doesThisDeclarationHaveABody() &&
3006  FoundFunction->hasBody(Definition)) {
3007  return Importer.MapImported(
3008  D, const_cast<FunctionDecl *>(Definition));
3009  }
3010  FoundByLookup = FoundFunction;
3011  break;
3012  }
3013 
3014  // FIXME: Check for overloading more carefully, e.g., by boosting
3015  // Sema::IsOverload out to the AST library.
3016 
3017  // Function overloading is okay in C++.
3018  if (Importer.getToContext().getLangOpts().CPlusPlus)
3019  continue;
3020 
3021  // Complain about inconsistent function types.
3022  Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent)
3023  << Name << D->getType() << FoundFunction->getType();
3024  Importer.ToDiag(FoundFunction->getLocation(),
3025  diag::note_odr_value_here)
3026  << FoundFunction->getType();
3027  }
3028  }
3029 
3030  ConflictingDecls.push_back(FoundDecl);
3031  }
3032 
3033  if (!ConflictingDecls.empty()) {
3034  Name = Importer.HandleNameConflict(Name, DC, IDNS,
3035  ConflictingDecls.data(),
3036  ConflictingDecls.size());
3037  if (!Name)
3038  return make_error<ImportError>(ImportError::NameConflict);
3039  }
3040  }
3041 
3042  DeclarationNameInfo NameInfo(Name, Loc);
3043  // Import additional name location/type info.
3044  if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
3045  return std::move(Err);
3046 
3047  QualType FromTy = D->getType();
3048  bool usedDifferentExceptionSpec = false;
3049 
3050  if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) {
3051  FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
3052  // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
3053  // FunctionDecl that we are importing the FunctionProtoType for.
3054  // To avoid an infinite recursion when importing, create the FunctionDecl
3055  // with a simplified function type and update it afterwards.
3056  if (FromEPI.ExceptionSpec.SourceDecl ||
3057  FromEPI.ExceptionSpec.SourceTemplate ||
3058  FromEPI.ExceptionSpec.NoexceptExpr) {
3060  FromTy = Importer.getFromContext().getFunctionType(
3061  FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI);
3062  usedDifferentExceptionSpec = true;
3063  }
3064  }
3065 
3066  QualType T;
3067  TypeSourceInfo *TInfo;
3068  SourceLocation ToInnerLocStart, ToEndLoc;
3069  NestedNameSpecifierLoc ToQualifierLoc;
3070  if (auto Imp = importSeq(
3071  FromTy, D->getTypeSourceInfo(), D->getInnerLocStart(),
3072  D->getQualifierLoc(), D->getEndLoc()))
3073  std::tie(T, TInfo, ToInnerLocStart, ToQualifierLoc, ToEndLoc) = *Imp;
3074  else
3075  return Imp.takeError();
3076 
3077  // Import the function parameters.
3078  SmallVector<ParmVarDecl *, 8> Parameters;
3079  for (auto P : D->parameters()) {
3080  if (Expected<ParmVarDecl *> ToPOrErr = import(P))
3081  Parameters.push_back(*ToPOrErr);
3082  else
3083  return ToPOrErr.takeError();
3084  }
3085 
3086  // Create the imported function.
3087  FunctionDecl *ToFunction = nullptr;
3088  if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
3089  if (GetImportedOrCreateDecl<CXXConstructorDecl>(
3090  ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3091  ToInnerLocStart, NameInfo, T, TInfo,
3092  FromConstructor->isExplicit(),
3093  D->isInlineSpecified(), D->isImplicit(), D->isConstexpr()))
3094  return ToFunction;
3095  } else if (isa<CXXDestructorDecl>(D)) {
3096  if (GetImportedOrCreateDecl<CXXDestructorDecl>(
3097  ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3098  ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(),
3099  D->isImplicit()))
3100  return ToFunction;
3101  } else if (CXXConversionDecl *FromConversion =
3102  dyn_cast<CXXConversionDecl>(D)) {
3103  if (GetImportedOrCreateDecl<CXXConversionDecl>(
3104  ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3105  ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(),
3106  FromConversion->isExplicit(), D->isConstexpr(), SourceLocation()))
3107  return ToFunction;
3108  } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
3109  if (GetImportedOrCreateDecl<CXXMethodDecl>(
3110  ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3111  ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
3112  Method->isInlineSpecified(), D->isConstexpr(), SourceLocation()))
3113  return ToFunction;
3114  } else {
3115  if (GetImportedOrCreateDecl(ToFunction, D, Importer.getToContext(), DC,
3116  ToInnerLocStart, NameInfo, T, TInfo,
3118  D->hasWrittenPrototype(), D->isConstexpr()))
3119  return ToFunction;
3120  }
3121 
3122  // Connect the redecl chain.
3123  if (FoundByLookup) {
3124  auto *Recent = const_cast<FunctionDecl *>(
3125  FoundByLookup->getMostRecentDecl());
3126  ToFunction->setPreviousDecl(Recent);
3127  }
3128 
3129  // Import Ctor initializers.
3130  if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
3131  if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
3132  SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
3133  // Import first, then allocate memory and copy if there was no error.
3134  if (Error Err = ImportContainerChecked(
3135  FromConstructor->inits(), CtorInitializers))
3136  return std::move(Err);
3137  auto **Memory =
3138  new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
3139  std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
3140  auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
3141  ToCtor->setCtorInitializers(Memory);
3142  ToCtor->setNumCtorInitializers(NumInitializers);
3143  }
3144  }
3145 
3146  ToFunction->setQualifierInfo(ToQualifierLoc);
3147  ToFunction->setAccess(D->getAccess());
3148  ToFunction->setLexicalDeclContext(LexicalDC);
3149  ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
3150  ToFunction->setTrivial(D->isTrivial());
3151  ToFunction->setPure(D->isPure());
3152  ToFunction->setRangeEnd(ToEndLoc);
3153 
3154  // Set the parameters.
3155  for (auto *Param : Parameters) {
3156  Param->setOwningFunction(ToFunction);
3157  ToFunction->addDeclInternal(Param);
3158  }
3159  ToFunction->setParams(Parameters);
3160 
3161  // We need to complete creation of FunctionProtoTypeLoc manually with setting
3162  // params it refers to.
3163  if (TInfo) {
3164  if (auto ProtoLoc =
3166  for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
3167  ProtoLoc.setParam(I, Parameters[I]);
3168  }
3169  }
3170 
3171  if (usedDifferentExceptionSpec) {
3172  // Update FunctionProtoType::ExtProtoInfo.
3173  if (ExpectedType TyOrErr = import(D->getType()))
3174  ToFunction->setType(*TyOrErr);
3175  else
3176  return TyOrErr.takeError();
3177  }
3178 
3179  // Import the describing template function, if any.
3180  if (FromFT) {
3181  auto ToFTOrErr = import(FromFT);
3182  if (!ToFTOrErr)
3183  return ToFTOrErr.takeError();
3184  }
3185 
3186  if (D->doesThisDeclarationHaveABody()) {
3187  if (Stmt *FromBody = D->getBody()) {
3188  if (ExpectedStmt ToBodyOrErr = import(FromBody))
3189  ToFunction->setBody(*ToBodyOrErr);
3190  else
3191  return ToBodyOrErr.takeError();
3192  }
3193  }
3194 
3195  // FIXME: Other bits to merge?
3196 
3197  // If it is a template, import all related things.
3198  if (Error Err = ImportTemplateInformation(D, ToFunction))
3199  return std::move(Err);
3200 
3202 
3203  // TODO Can we generalize this approach to other AST nodes as well?
3204  if (D->getDeclContext()->containsDeclAndLoad(D))
3205  DC->addDeclInternal(ToFunction);
3206  if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D))
3207  LexicalDC->addDeclInternal(ToFunction);
3208 
3209  // Friend declaration's lexical context is the befriending class, but the
3210  // semantic context is the enclosing scope of the befriending class.
3211  // We want the friend functions to be found in the semantic context by lookup.
3212  // FIXME should we handle this generically in VisitFriendDecl?
3213  // In Other cases when LexicalDC != DC we don't want it to be added,
3214  // e.g out-of-class definitions like void B::f() {} .
3215  if (LexicalDC != DC && IsFriend) {
3216  DC->makeDeclVisibleInContext(ToFunction);
3217  }
3218 
3219  if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
3220  ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod);
3221 
3222  // Import the rest of the chain. I.e. import all subsequent declarations.
3223  for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
3224  ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3225  if (!ToRedeclOrErr)
3226  return ToRedeclOrErr.takeError();
3227  }
3228 
3229  return ToFunction;
3230 }
3231 
3233  return VisitFunctionDecl(D);
3234 }
3235 
3237  return VisitCXXMethodDecl(D);
3238 }
3239 
3241  return VisitCXXMethodDecl(D);
3242 }
3243 
3245  return VisitCXXMethodDecl(D);
3246 }
3247 
3249  // Import the major distinguishing characteristics of a variable.
3250  DeclContext *DC, *LexicalDC;
3251  DeclarationName Name;
3252  SourceLocation Loc;
3253  NamedDecl *ToD;
3254  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3255  return std::move(Err);
3256  if (ToD)
3257  return ToD;
3258 
3259  // Determine whether we've already imported this field.
3260  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3261  for (auto *FoundDecl : FoundDecls) {
3262  if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
3263  // For anonymous fields, match up by index.
3264  if (!Name &&
3266  ASTImporter::getFieldIndex(FoundField))
3267  continue;
3268 
3269  if (Importer.IsStructurallyEquivalent(D->getType(),
3270  FoundField->getType())) {
3271  Importer.MapImported(D, FoundField);
3272  // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
3273  // initializer of a FieldDecl might not had been instantiated in the
3274  // "To" context. However, the "From" context might instantiated that,
3275  // thus we have to merge that.
3276  if (Expr *FromInitializer = D->getInClassInitializer()) {
3277  // We don't have yet the initializer set.
3278  if (FoundField->hasInClassInitializer() &&
3279  !FoundField->getInClassInitializer()) {
3280  if (ExpectedExpr ToInitializerOrErr = import(FromInitializer))
3281  FoundField->setInClassInitializer(*ToInitializerOrErr);
3282  else {
3283  // We can't return error here,
3284  // since we already mapped D as imported.
3285  // FIXME: warning message?
3286  consumeError(ToInitializerOrErr.takeError());
3287  return FoundField;
3288  }
3289  }
3290  }
3291  return FoundField;
3292  }
3293 
3294  // FIXME: Why is this case not handled with calling HandleNameConflict?
3295  Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent)
3296  << Name << D->getType() << FoundField->getType();
3297  Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
3298  << FoundField->getType();
3299 
3300  return make_error<ImportError>(ImportError::NameConflict);
3301  }
3302  }
3303 
3304  QualType ToType;
3305  TypeSourceInfo *ToTInfo;
3306  Expr *ToBitWidth;
3307  SourceLocation ToInnerLocStart;
3308  Expr *ToInitializer;
3309  if (auto Imp = importSeq(
3310  D->getType(), D->getTypeSourceInfo(), D->getBitWidth(),
3312  std::tie(
3313  ToType, ToTInfo, ToBitWidth, ToInnerLocStart, ToInitializer) = *Imp;
3314  else
3315  return Imp.takeError();
3316 
3317  FieldDecl *ToField;
3318  if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
3319  ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
3320  ToType, ToTInfo, ToBitWidth, D->isMutable(),
3321  D->getInClassInitStyle()))
3322  return ToField;
3323 
3324  ToField->setAccess(D->getAccess());
3325  ToField->setLexicalDeclContext(LexicalDC);
3326  if (ToInitializer)
3327  ToField->setInClassInitializer(ToInitializer);
3328  ToField->setImplicit(D->isImplicit());
3329  LexicalDC->addDeclInternal(ToField);
3330  return ToField;
3331 }
3332 
3334  // Import the major distinguishing characteristics of a variable.
3335  DeclContext *DC, *LexicalDC;
3336  DeclarationName Name;
3337  SourceLocation Loc;
3338  NamedDecl *ToD;
3339  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3340  return std::move(Err);
3341  if (ToD)
3342  return ToD;
3343 
3344  // Determine whether we've already imported this field.
3345  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3346  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
3347  if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
3348  // For anonymous indirect fields, match up by index.
3349  if (!Name &&
3351  ASTImporter::getFieldIndex(FoundField))
3352  continue;
3353 
3354  if (Importer.IsStructurallyEquivalent(D->getType(),
3355  FoundField->getType(),
3356  !Name.isEmpty())) {
3357  Importer.MapImported(D, FoundField);
3358  return FoundField;
3359  }
3360 
3361  // If there are more anonymous fields to check, continue.
3362  if (!Name && I < N-1)
3363  continue;
3364 
3365  // FIXME: Why is this case not handled with calling HandleNameConflict?
3366  Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent)
3367  << Name << D->getType() << FoundField->getType();
3368  Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
3369  << FoundField->getType();
3370 
3371  return make_error<ImportError>(ImportError::NameConflict);
3372  }
3373  }
3374 
3375  // Import the type.
3376  auto TypeOrErr = import(D->getType());
3377  if (!TypeOrErr)
3378  return TypeOrErr.takeError();
3379 
3380  auto **NamedChain =
3381  new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
3382 
3383  unsigned i = 0;
3384  for (auto *PI : D->chain())
3385  if (Expected<NamedDecl *> ToD = import(PI))
3386  NamedChain[i++] = *ToD;
3387  else
3388  return ToD.takeError();
3389 
3390  llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()};
3391  IndirectFieldDecl *ToIndirectField;
3392  if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
3393  Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
3394  // FIXME here we leak `NamedChain` which is allocated before
3395  return ToIndirectField;
3396 
3397  for (const auto *Attr : D->attrs())
3398  ToIndirectField->addAttr(Importer.Import(Attr));
3399 
3400  ToIndirectField->setAccess(D->getAccess());
3401  ToIndirectField->setLexicalDeclContext(LexicalDC);
3402  LexicalDC->addDeclInternal(ToIndirectField);
3403  return ToIndirectField;
3404 }
3405 
3407  // Import the major distinguishing characteristics of a declaration.
3408  DeclContext *DC, *LexicalDC;
3409  if (Error Err = ImportDeclContext(D, DC, LexicalDC))
3410  return std::move(Err);
3411 
3412  // Determine whether we've already imported this decl.
3413  // FriendDecl is not a NamedDecl so we cannot use lookup.
3414  auto *RD = cast<CXXRecordDecl>(DC);
3415  FriendDecl *ImportedFriend = RD->getFirstFriend();
3416 
3417  while (ImportedFriend) {
3418  if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) {
3419  if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(),
3420  /*Complain=*/false))
3421  return Importer.MapImported(D, ImportedFriend);
3422 
3423  } else if (D->getFriendType() && ImportedFriend->getFriendType()) {
3424  if (Importer.IsStructurallyEquivalent(
3425  D->getFriendType()->getType(),
3426  ImportedFriend->getFriendType()->getType(), true))
3427  return Importer.MapImported(D, ImportedFriend);
3428  }
3429  ImportedFriend = ImportedFriend->getNextFriend();
3430  }
3431 
3432  // Not found. Create it.
3434  if (NamedDecl *FriendD = D->getFriendDecl()) {
3435  NamedDecl *ToFriendD;
3436  if (Error Err = importInto(ToFriendD, FriendD))
3437  return std::move(Err);
3438 
3439  if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
3440  !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator)))
3441  ToFriendD->setObjectOfFriendDecl(false);
3442 
3443  ToFU = ToFriendD;
3444  } else { // The friend is a type, not a decl.
3445  if (auto TSIOrErr = import(D->getFriendType()))
3446  ToFU = *TSIOrErr;
3447  else
3448  return TSIOrErr.takeError();
3449  }
3450 
3451  SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
3452  auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>();
3453  for (unsigned I = 0; I < D->NumTPLists; I++) {
3454  if (auto ListOrErr = ImportTemplateParameterList(FromTPLists[I]))
3455  ToTPLists[I] = *ListOrErr;
3456  else
3457  return ListOrErr.takeError();
3458  }
3459 
3460  auto LocationOrErr = import(D->getLocation());
3461  if (!LocationOrErr)
3462  return LocationOrErr.takeError();
3463  auto FriendLocOrErr = import(D->getFriendLoc());
3464  if (!FriendLocOrErr)
3465  return FriendLocOrErr.takeError();
3466 
3467  FriendDecl *FrD;
3468  if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
3469  *LocationOrErr, ToFU,
3470  *FriendLocOrErr, ToTPLists))
3471  return FrD;
3472 
3473  FrD->setAccess(D->getAccess());
3474  FrD->setLexicalDeclContext(LexicalDC);
3475  LexicalDC->addDeclInternal(FrD);
3476  return FrD;
3477 }
3478 
3480  // Import the major distinguishing characteristics of an ivar.
3481  DeclContext *DC, *LexicalDC;
3482  DeclarationName Name;
3483  SourceLocation Loc;
3484  NamedDecl *ToD;
3485  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3486  return std::move(Err);
3487  if (ToD)
3488  return ToD;
3489 
3490  // Determine whether we've already imported this ivar
3491  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3492  for (auto *FoundDecl : FoundDecls) {
3493  if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
3494  if (Importer.IsStructurallyEquivalent(D->getType(),
3495  FoundIvar->getType())) {
3496  Importer.MapImported(D, FoundIvar);
3497  return FoundIvar;
3498  }
3499 
3500  Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent)
3501  << Name << D->getType() << FoundIvar->getType();
3502  Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
3503  << FoundIvar->getType();
3504 
3505  return make_error<ImportError>(ImportError::NameConflict);
3506  }
3507  }
3508 
3509  QualType ToType;
3510  TypeSourceInfo *ToTypeSourceInfo;
3511  Expr *ToBitWidth;
3512  SourceLocation ToInnerLocStart;
3513  if (auto Imp = importSeq(
3514  D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), D->getInnerLocStart()))
3515  std::tie(ToType, ToTypeSourceInfo, ToBitWidth, ToInnerLocStart) = *Imp;
3516  else
3517  return Imp.takeError();
3518 
3519  ObjCIvarDecl *ToIvar;
3520  if (GetImportedOrCreateDecl(
3521  ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
3522  ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
3523  ToType, ToTypeSourceInfo,
3524  D->getAccessControl(),ToBitWidth, D->getSynthesize()))
3525  return ToIvar;
3526 
3527  ToIvar->setLexicalDeclContext(LexicalDC);
3528  LexicalDC->addDeclInternal(ToIvar);
3529  return ToIvar;
3530 }
3531 
3533 
3535  auto RedeclIt = Redecls.begin();
3536  // Import the first part of the decl chain. I.e. import all previous
3537  // declarations starting from the canonical decl.
3538  for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3539  ExpectedDecl RedeclOrErr = import(*RedeclIt);
3540  if (!RedeclOrErr)
3541  return RedeclOrErr.takeError();
3542  }
3543  assert(*RedeclIt == D);
3544 
3545  // Import the major distinguishing characteristics of a variable.
3546  DeclContext *DC, *LexicalDC;
3547  DeclarationName Name;
3548  SourceLocation Loc;
3549  NamedDecl *ToD;
3550  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3551  return std::move(Err);
3552  if (ToD)
3553  return ToD;
3554 
3555  // Try to find a variable in our own ("to") context with the same name and
3556  // in the same context as the variable we're importing.
3557  VarDecl *FoundByLookup = nullptr;
3558  if (D->isFileVarDecl()) {
3559  SmallVector<NamedDecl *, 4> ConflictingDecls;
3560  unsigned IDNS = Decl::IDNS_Ordinary;
3561  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3562  for (auto *FoundDecl : FoundDecls) {
3563  if (!FoundDecl->isInIdentifierNamespace(IDNS))
3564  continue;
3565 
3566  if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
3567  // We have found a variable that we may need to merge with. Check it.
3568  if (FoundVar->hasExternalFormalLinkage() &&
3569  D->hasExternalFormalLinkage()) {
3570  if (Importer.IsStructurallyEquivalent(D->getType(),
3571  FoundVar->getType())) {
3572 
3573  // The VarDecl in the "From" context has a definition, but in the
3574  // "To" context we already have a definition.
3575  VarDecl *FoundDef = FoundVar->getDefinition();
3576  if (D->isThisDeclarationADefinition() && FoundDef)
3577  // FIXME Check for ODR error if the two definitions have
3578  // different initializers?
3579  return Importer.MapImported(D, FoundDef);
3580 
3581  // The VarDecl in the "From" context has an initializer, but in the
3582  // "To" context we already have an initializer.
3583  const VarDecl *FoundDInit = nullptr;
3584  if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
3585  // FIXME Diagnose ODR error if the two initializers are different?
3586  return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
3587 
3588  FoundByLookup = FoundVar;
3589  break;
3590  }
3591 
3592  const ArrayType *FoundArray
3593  = Importer.getToContext().getAsArrayType(FoundVar->getType());
3594  const ArrayType *TArray
3595  = Importer.getToContext().getAsArrayType(D->getType());
3596  if (FoundArray && TArray) {
3597  if (isa<IncompleteArrayType>(FoundArray) &&
3598  isa<ConstantArrayType>(TArray)) {
3599  // Import the type.
3600  if (auto TyOrErr = import(D->getType()))
3601  FoundVar->setType(*TyOrErr);
3602  else
3603  return TyOrErr.takeError();
3604 
3605  FoundByLookup = FoundVar;
3606  break;
3607  } else if (isa<IncompleteArrayType>(TArray) &&
3608  isa<ConstantArrayType>(FoundArray)) {
3609  FoundByLookup = FoundVar;
3610  break;
3611  }
3612  }
3613 
3614  Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent)
3615  << Name << D->getType() << FoundVar->getType();
3616  Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
3617  << FoundVar->getType();
3618  }
3619  }
3620 
3621  ConflictingDecls.push_back(FoundDecl);
3622  }
3623 
3624  if (!ConflictingDecls.empty()) {
3625  Name = Importer.HandleNameConflict(Name, DC, IDNS,
3626  ConflictingDecls.data(),
3627  ConflictingDecls.size());
3628  if (!Name)
3629  return make_error<ImportError>(ImportError::NameConflict);
3630  }
3631  }
3632 
3633  QualType ToType;
3634  TypeSourceInfo *ToTypeSourceInfo;
3635  SourceLocation ToInnerLocStart;
3636  NestedNameSpecifierLoc ToQualifierLoc;
3637  if (auto Imp = importSeq(
3638  D->getType(), D->getTypeSourceInfo(), D->getInnerLocStart(),
3639  D->getQualifierLoc()))
3640  std::tie(ToType, ToTypeSourceInfo, ToInnerLocStart, ToQualifierLoc) = *Imp;
3641  else
3642  return Imp.takeError();
3643 
3644  // Create the imported variable.
3645  VarDecl *ToVar;
3646  if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
3647  ToInnerLocStart, Loc,
3648  Name.getAsIdentifierInfo(),
3649  ToType, ToTypeSourceInfo,
3650  D->getStorageClass()))
3651  return ToVar;
3652 
3653  ToVar->setQualifierInfo(ToQualifierLoc);
3654  ToVar->setAccess(D->getAccess());
3655  ToVar->setLexicalDeclContext(LexicalDC);
3656 
3657  if (FoundByLookup) {
3658  auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
3659  ToVar->setPreviousDecl(Recent);
3660  }
3661 
3662  if (Error Err = ImportInitializer(D, ToVar))
3663  return std::move(Err);
3664 
3665  if (D->isConstexpr())
3666  ToVar->setConstexpr(true);
3667 
3668  if (D->getDeclContext()->containsDeclAndLoad(D))
3669  DC->addDeclInternal(ToVar);
3670  if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D))
3671  LexicalDC->addDeclInternal(ToVar);
3672 
3673  // Import the rest of the chain. I.e. import all subsequent declarations.
3674  for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
3675  ExpectedDecl RedeclOrErr = import(*RedeclIt);
3676  if (!RedeclOrErr)
3677  return RedeclOrErr.takeError();
3678  }
3679 
3680  return ToVar;
3681 }
3682 
3684  // Parameters are created in the translation unit's context, then moved
3685  // into the function declaration's context afterward.
3686  DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
3687 
3688  DeclarationName ToDeclName;
3689  SourceLocation ToLocation;
3690  QualType ToType;
3691  if (auto Imp = importSeq(D->getDeclName(), D->getLocation(), D->getType()))
3692  std::tie(ToDeclName, ToLocation, ToType) = *Imp;
3693  else
3694  return Imp.takeError();
3695 
3696  // Create the imported parameter.
3697  ImplicitParamDecl *ToParm = nullptr;
3698  if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
3699  ToLocation, ToDeclName.getAsIdentifierInfo(),
3700  ToType, D->getParameterKind()))
3701  return ToParm;
3702  return ToParm;
3703 }
3704 
3706  // Parameters are created in the translation unit's context, then moved
3707  // into the function declaration's context afterward.
3708  DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
3709 
3710  DeclarationName ToDeclName;
3711  SourceLocation ToLocation, ToInnerLocStart;
3712  QualType ToType;
3713  TypeSourceInfo *ToTypeSourceInfo;
3714  if (auto Imp = importSeq(
3715  D->getDeclName(), D->getLocation(), D->getType(), D->getInnerLocStart(),
3716  D->getTypeSourceInfo()))
3717  std::tie(
3718  ToDeclName, ToLocation, ToType, ToInnerLocStart,
3719  ToTypeSourceInfo) = *Imp;
3720  else
3721  return Imp.takeError();
3722 
3723  ParmVarDecl *ToParm;
3724  if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
3725  ToInnerLocStart, ToLocation,
3726  ToDeclName.getAsIdentifierInfo(), ToType,
3727  ToTypeSourceInfo, D->getStorageClass(),
3728  /*DefaultArg*/ nullptr))
3729  return ToParm;
3730 
3731  // Set the default argument.
3733  ToParm->setKNRPromoted(D->isKNRPromoted());
3734 
3735  if (D->hasUninstantiatedDefaultArg()) {
3736  if (auto ToDefArgOrErr = import(D->getUninstantiatedDefaultArg()))
3737  ToParm->setUninstantiatedDefaultArg(*ToDefArgOrErr);
3738  else
3739  return ToDefArgOrErr.takeError();
3740  } else if (D->hasUnparsedDefaultArg()) {
3741  ToParm->setUnparsedDefaultArg();
3742  } else if (D->hasDefaultArg()) {
3743  if (auto ToDefArgOrErr = import(D->getDefaultArg()))
3744  ToParm->setDefaultArg(*ToDefArgOrErr);
3745  else
3746  return ToDefArgOrErr.takeError();
3747  }
3748 
3749  if (D->isObjCMethodParameter()) {
3752  } else {
3753  ToParm->setScopeInfo(D->getFunctionScopeDepth(),
3754  D->getFunctionScopeIndex());
3755  }
3756 
3757  return ToParm;
3758 }
3759 
3761  // Import the major distinguishing characteristics of a method.
3762  DeclContext *DC, *LexicalDC;
3763  DeclarationName Name;
3764  SourceLocation Loc;
3765  NamedDecl *ToD;
3766  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3767  return std::move(Err);
3768  if (ToD)
3769  return ToD;
3770 
3771  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3772  for (auto *FoundDecl : FoundDecls) {
3773  if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
3774  if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
3775  continue;
3776 
3777  // Check return types.
3778  if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
3779  FoundMethod->getReturnType())) {
3780  Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent)
3781  << D->isInstanceMethod() << Name << D->getReturnType()
3782  << FoundMethod->getReturnType();
3783  Importer.ToDiag(FoundMethod->getLocation(),
3784  diag::note_odr_objc_method_here)
3785  << D->isInstanceMethod() << Name;
3786 
3787  return make_error<ImportError>(ImportError::NameConflict);
3788  }
3789 
3790  // Check the number of parameters.
3791  if (D->param_size() != FoundMethod->param_size()) {
3792  Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent)
3793  << D->isInstanceMethod() << Name
3794  << D->param_size() << FoundMethod->param_size();
3795  Importer.ToDiag(FoundMethod->getLocation(),
3796  diag::note_odr_objc_method_here)
3797  << D->isInstanceMethod() << Name;
3798 
3799  return make_error<ImportError>(ImportError::NameConflict);
3800  }
3801 
3802  // Check parameter types.
3804  PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
3805  P != PEnd; ++P, ++FoundP) {
3806  if (!Importer.IsStructurallyEquivalent((*P)->getType(),
3807  (*FoundP)->getType())) {
3808  Importer.FromDiag((*P)->getLocation(),
3809  diag::err_odr_objc_method_param_type_inconsistent)
3810  << D->isInstanceMethod() << Name
3811  << (*P)->getType() << (*FoundP)->getType();
3812  Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
3813  << (*FoundP)->getType();
3814 
3815  return make_error<ImportError>(ImportError::NameConflict);
3816  }
3817  }
3818 
3819  // Check variadic/non-variadic.
3820  // Check the number of parameters.
3821  if (D->isVariadic() != FoundMethod->isVariadic()) {
3822  Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent)
3823  << D->isInstanceMethod() << Name;
3824  Importer.ToDiag(FoundMethod->getLocation(),
3825  diag::note_odr_objc_method_here)
3826  << D->isInstanceMethod() << Name;
3827 
3828  return make_error<ImportError>(ImportError::NameConflict);
3829  }
3830 
3831  // FIXME: Any other bits we need to merge?
3832  return Importer.MapImported(D, FoundMethod);
3833  }
3834  }
3835 
3836  SourceLocation ToEndLoc;
3837  QualType ToReturnType;
3838  TypeSourceInfo *ToReturnTypeSourceInfo;
3839  if (auto Imp = importSeq(
3841  std::tie(ToEndLoc, ToReturnType, ToReturnTypeSourceInfo) = *Imp;
3842  else
3843  return Imp.takeError();
3844 
3845  ObjCMethodDecl *ToMethod;
3846  if (GetImportedOrCreateDecl(
3847  ToMethod, D, Importer.getToContext(), Loc,
3848  ToEndLoc, Name.getObjCSelector(), ToReturnType,
3849  ToReturnTypeSourceInfo, DC, D->isInstanceMethod(), D->isVariadic(),
3850  D->isPropertyAccessor(), D->isImplicit(), D->isDefined(),
3852  return ToMethod;
3853 
3854  // FIXME: When we decide to merge method definitions, we'll need to
3855  // deal with implicit parameters.
3856 
3857  // Import the parameters
3859  for (auto *FromP : D->parameters()) {
3860  if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
3861  ToParams.push_back(*ToPOrErr);
3862  else
3863  return ToPOrErr.takeError();
3864  }
3865 
3866  // Set the parameters.
3867  for (auto *ToParam : ToParams) {
3868  ToParam->setOwningFunction(ToMethod);
3869  ToMethod->addDeclInternal(ToParam);
3870  }
3871 
3872  SmallVector<SourceLocation, 12> FromSelLocs;
3873  D->getSelectorLocs(FromSelLocs);
3874  SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
3875  if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
3876  return std::move(Err);
3877 
3878  ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
3879 
3880  ToMethod->setLexicalDeclContext(LexicalDC);
3881  LexicalDC->addDeclInternal(ToMethod);
3882  return ToMethod;
3883 }
3884 
3886  // Import the major distinguishing characteristics of a category.
3887  DeclContext *DC, *LexicalDC;
3888  DeclarationName Name;
3889  SourceLocation Loc;
3890  NamedDecl *ToD;
3891  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3892  return std::move(Err);
3893  if (ToD)
3894  return ToD;
3895 
3896  SourceLocation ToVarianceLoc, ToLocation, ToColonLoc;
3897  TypeSourceInfo *ToTypeSourceInfo;
3898  if (auto Imp = importSeq(
3899  D->getVarianceLoc(), D->getLocation(), D->getColonLoc(),
3900  D->getTypeSourceInfo()))
3901  std::tie(ToVarianceLoc, ToLocation, ToColonLoc, ToTypeSourceInfo) = *Imp;
3902  else
3903  return Imp.takeError();
3904 
3906  if (GetImportedOrCreateDecl(
3907  Result, D, Importer.getToContext(), DC, D->getVariance(),
3908  ToVarianceLoc, D->getIndex(),
3909  ToLocation, Name.getAsIdentifierInfo(),
3910  ToColonLoc, ToTypeSourceInfo))
3911  return Result;
3912 
3913  Result->setLexicalDeclContext(LexicalDC);
3914  return Result;
3915 }
3916 
3918  // Import the major distinguishing characteristics of a category.
3919  DeclContext *DC, *LexicalDC;
3920  DeclarationName Name;
3921  SourceLocation Loc;
3922  NamedDecl *ToD;
3923  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3924  return std::move(Err);
3925  if (ToD)
3926  return ToD;
3927 
3928  ObjCInterfaceDecl *ToInterface;
3929  if (Error Err = importInto(ToInterface, D->getClassInterface()))
3930  return std::move(Err);
3931 
3932  // Determine if we've already encountered this category.
3933  ObjCCategoryDecl *MergeWithCategory
3934  = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
3935  ObjCCategoryDecl *ToCategory = MergeWithCategory;
3936  if (!ToCategory) {
3937  SourceLocation ToAtStartLoc, ToCategoryNameLoc;
3938  SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc;
3939  if (auto Imp = importSeq(
3940  D->getAtStartLoc(), D->getCategoryNameLoc(),
3941  D->getIvarLBraceLoc(), D->getIvarRBraceLoc()))
3942  std::tie(
3943  ToAtStartLoc, ToCategoryNameLoc,
3944  ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp;
3945  else
3946  return Imp.takeError();
3947 
3948  if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
3949  ToAtStartLoc, Loc,
3950  ToCategoryNameLoc,
3951  Name.getAsIdentifierInfo(), ToInterface,
3952  /*TypeParamList=*/nullptr,
3953  ToIvarLBraceLoc,
3954  ToIvarRBraceLoc))
3955  return ToCategory;
3956 
3957  ToCategory->setLexicalDeclContext(LexicalDC);
3958  LexicalDC->addDeclInternal(ToCategory);
3959  // Import the type parameter list after MapImported, to avoid
3960  // loops when bringing in their DeclContext.
3961  if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
3962  ToCategory->setTypeParamList(*PListOrErr);
3963  else
3964  return PListOrErr.takeError();
3965 
3966  // Import protocols
3968  SmallVector<SourceLocation, 4> ProtocolLocs;
3970  = D->protocol_loc_begin();
3972  FromProtoEnd = D->protocol_end();
3973  FromProto != FromProtoEnd;
3974  ++FromProto, ++FromProtoLoc) {
3975  if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
3976  Protocols.push_back(*ToProtoOrErr);
3977  else
3978  return ToProtoOrErr.takeError();
3979 
3980  if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
3981  ProtocolLocs.push_back(*ToProtoLocOrErr);
3982  else
3983  return ToProtoLocOrErr.takeError();
3984  }
3985 
3986  // FIXME: If we're merging, make sure that the protocol list is the same.
3987  ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
3988  ProtocolLocs.data(), Importer.getToContext());
3989 
3990  } else {
3991  Importer.MapImported(D, ToCategory);
3992  }
3993 
3994  // Import all of the members of this category.
3995  if (Error Err = ImportDeclContext(D))
3996  return std::move(Err);
3997 
3998  // If we have an implementation, import it as well.
3999  if (D->getImplementation()) {
4000  if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
4001  import(D->getImplementation()))
4002  ToCategory->setImplementation(*ToImplOrErr);
4003  else
4004  return ToImplOrErr.takeError();
4005  }
4006 
4007  return ToCategory;
4008 }
4009 
4012  if (To->getDefinition()) {
4013  if (shouldForceImportDeclContext(Kind))
4014  if (Error Err = ImportDeclContext(From))
4015  return Err;
4016  return Error::success();
4017  }
4018 
4019  // Start the protocol definition
4020  To->startDefinition();
4021 
4022  // Import protocols
4024  SmallVector<SourceLocation, 4> ProtocolLocs;
4026  From->protocol_loc_begin();
4027  for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
4028  FromProtoEnd = From->protocol_end();
4029  FromProto != FromProtoEnd;
4030  ++FromProto, ++FromProtoLoc) {
4031  if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
4032  Protocols.push_back(*ToProtoOrErr);
4033  else
4034  return ToProtoOrErr.takeError();
4035 
4036  if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
4037  ProtocolLocs.push_back(*ToProtoLocOrErr);
4038  else
4039  return ToProtoLocOrErr.takeError();
4040 
4041  }
4042 
4043  // FIXME: If we're merging, make sure that the protocol list is the same.
4044  To->setProtocolList(Protocols.data(), Protocols.size(),
4045  ProtocolLocs.data(), Importer.getToContext());
4046 
4047  if (shouldForceImportDeclContext(Kind)) {
4048  // Import all of the members of this protocol.
4049  if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
4050  return Err;
4051  }
4052  return Error::success();
4053 }
4054 
4056  // If this protocol has a definition in the translation unit we're coming
4057  // from, but this particular declaration is not that definition, import the
4058  // definition and map to that.
4059  ObjCProtocolDecl *Definition = D->getDefinition();
4060  if (Definition && Definition != D) {
4061  if (ExpectedDecl ImportedDefOrErr = import(Definition))
4062  return Importer.MapImported(D, *ImportedDefOrErr);
4063  else
4064  return ImportedDefOrErr.takeError();
4065  }
4066 
4067  // Import the major distinguishing characteristics of a protocol.
4068  DeclContext *DC, *LexicalDC;
4069  DeclarationName Name;
4070  SourceLocation Loc;
4071  NamedDecl *ToD;
4072  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4073  return std::move(Err);
4074  if (ToD)
4075  return ToD;
4076 
4077  ObjCProtocolDecl *MergeWithProtocol = nullptr;
4078  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4079  for (auto *FoundDecl : FoundDecls) {
4081  continue;
4082 
4083  if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
4084  break;
4085  }
4086 
4087  ObjCProtocolDecl *ToProto = MergeWithProtocol;
4088  if (!ToProto) {
4089  auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
4090  if (!ToAtBeginLocOrErr)
4091  return ToAtBeginLocOrErr.takeError();
4092 
4093  if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
4094  Name.getAsIdentifierInfo(), Loc,
4095  *ToAtBeginLocOrErr,
4096  /*PrevDecl=*/nullptr))
4097  return ToProto;
4098  ToProto->setLexicalDeclContext(LexicalDC);
4099  LexicalDC->addDeclInternal(ToProto);
4100  }
4101 
4102  Importer.MapImported(D, ToProto);
4103 
4105  if (Error Err = ImportDefinition(D, ToProto))
4106  return std::move(Err);
4107 
4108  return ToProto;
4109 }
4110 
4112  DeclContext *DC, *LexicalDC;
4113  if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4114  return std::move(Err);
4115 
4116  ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
4117  if (!ExternLocOrErr)
4118  return ExternLocOrErr.takeError();
4119 
4120  ExpectedSLoc LangLocOrErr = import(D->getLocation());
4121  if (!LangLocOrErr)
4122  return LangLocOrErr.takeError();
4123 
4124  bool HasBraces = D->hasBraces();
4125 
4126  LinkageSpecDecl *ToLinkageSpec;
4127  if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
4128  *ExternLocOrErr, *LangLocOrErr,
4129  D->getLanguage(), HasBraces))
4130  return ToLinkageSpec;
4131 
4132  if (HasBraces) {
4133  ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
4134  if (!RBraceLocOrErr)
4135  return RBraceLocOrErr.takeError();
4136  ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
4137  }
4138 
4139  ToLinkageSpec->setLexicalDeclContext(LexicalDC);
4140  LexicalDC->addDeclInternal(ToLinkageSpec);
4141 
4142  return ToLinkageSpec;
4143 }
4144 
4146  DeclContext *DC, *LexicalDC;
4147  DeclarationName Name;
4148  SourceLocation Loc;
4149  NamedDecl *ToD = nullptr;
4150  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4151  return std::move(Err);
4152  if (ToD)
4153  return ToD;
4154 
4155  SourceLocation ToLoc, ToUsingLoc;
4156  NestedNameSpecifierLoc ToQualifierLoc;
4157  if (auto Imp = importSeq(
4158  D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc()))
4159  std::tie(ToLoc, ToUsingLoc, ToQualifierLoc) = *Imp;
4160  else
4161  return Imp.takeError();
4162 
4163  DeclarationNameInfo NameInfo(Name, ToLoc);
4164  if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
4165  return std::move(Err);
4166 
4167  UsingDecl *ToUsing;
4168  if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
4169  ToUsingLoc, ToQualifierLoc, NameInfo,
4170  D->hasTypename()))
4171  return ToUsing;
4172 
4173  ToUsing->setLexicalDeclContext(LexicalDC);
4174  LexicalDC->addDeclInternal(ToUsing);
4175 
4176  if (NamedDecl *FromPattern =
4177  Importer.getFromContext().getInstantiatedFromUsingDecl(D)) {
4178  if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
4179  Importer.getToContext().setInstantiatedFromUsingDecl(
4180  ToUsing, *ToPatternOrErr);
4181  else
4182  return ToPatternOrErr.takeError();
4183  }
4184 
4185  for (UsingShadowDecl *FromShadow : D->shadows()) {
4186  if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
4187  ToUsing->addShadowDecl(*ToShadowOrErr);
4188  else
4189  // FIXME: We return error here but the definition is already created
4190  // and available with lookups. How to fix this?..
4191  return ToShadowOrErr.takeError();
4192  }
4193  return ToUsing;
4194 }
4195 
4197  DeclContext *DC, *LexicalDC;
4198  DeclarationName Name;
4199  SourceLocation Loc;
4200  NamedDecl *ToD = nullptr;
4201  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4202  return std::move(Err);
4203  if (ToD)
4204  return ToD;
4205 
4206  Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl());
4207  if (!ToUsingOrErr)
4208  return ToUsingOrErr.takeError();
4209 
4210  Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
4211  if (!ToTargetOrErr)
4212  return ToTargetOrErr.takeError();
4213 
4214  UsingShadowDecl *ToShadow;
4215  if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
4216  *ToUsingOrErr, *ToTargetOrErr))
4217  return ToShadow;
4218 
4219  ToShadow->setLexicalDeclContext(LexicalDC);
4220  ToShadow->setAccess(D->getAccess());
4221 
4222  if (UsingShadowDecl *FromPattern =
4223  Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) {
4224  if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
4225  Importer.getToContext().setInstantiatedFromUsingShadowDecl(
4226  ToShadow, *ToPatternOrErr);
4227  else
4228  // FIXME: We return error here but the definition is already created
4229  // and available with lookups. How to fix this?..
4230  return ToPatternOrErr.takeError();
4231  }
4232 
4233  LexicalDC->addDeclInternal(ToShadow);
4234 
4235  return ToShadow;
4236 }
4237 
4239  DeclContext *DC, *LexicalDC;
4240  DeclarationName Name;
4241  SourceLocation Loc;
4242  NamedDecl *ToD = nullptr;
4243  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4244  return std::move(Err);
4245  if (ToD)
4246  return ToD;
4247 
4248  auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
4249  if (!ToComAncestorOrErr)
4250  return ToComAncestorOrErr.takeError();
4251 
4252  NamespaceDecl *ToNominatedNamespace;
4253  SourceLocation ToUsingLoc, ToNamespaceKeyLocation, ToIdentLocation;
4254  NestedNameSpecifierLoc ToQualifierLoc;
4255  if (auto Imp = importSeq(
4258  D->getIdentLocation()))
4259  std::tie(
4260  ToNominatedNamespace, ToUsingLoc, ToNamespaceKeyLocation,
4261  ToQualifierLoc, ToIdentLocation) = *Imp;
4262  else
4263  return Imp.takeError();
4264 
4265  UsingDirectiveDecl *ToUsingDir;
4266  if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
4267  ToUsingLoc,
4268  ToNamespaceKeyLocation,
4269  ToQualifierLoc,
4270  ToIdentLocation,
4271  ToNominatedNamespace, *ToComAncestorOrErr))
4272  return ToUsingDir;
4273 
4274  ToUsingDir->setLexicalDeclContext(LexicalDC);
4275  LexicalDC->addDeclInternal(ToUsingDir);
4276 
4277  return ToUsingDir;
4278 }
4279 
4282  DeclContext *DC, *LexicalDC;
4283  DeclarationName Name;
4284  SourceLocation Loc;
4285  NamedDecl *ToD = nullptr;
4286  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4287  return std::move(Err);
4288  if (ToD)
4289  return ToD;
4290 
4291  SourceLocation ToLoc, ToUsingLoc, ToEllipsisLoc;
4292  NestedNameSpecifierLoc ToQualifierLoc;
4293  if (auto Imp = importSeq(
4294  D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc(),
4295  D->getEllipsisLoc()))
4296  std::tie(ToLoc, ToUsingLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp;
4297  else
4298  return Imp.takeError();
4299 
4300  DeclarationNameInfo NameInfo(Name, ToLoc);
4301  if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
4302  return std::move(Err);
4303 
4304  UnresolvedUsingValueDecl *ToUsingValue;
4305  if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
4306  ToUsingLoc, ToQualifierLoc, NameInfo,
4307  ToEllipsisLoc))
4308  return ToUsingValue;
4309 
4310  ToUsingValue->setAccess(D->getAccess());
4311  ToUsingValue->setLexicalDeclContext(LexicalDC);
4312  LexicalDC->addDeclInternal(ToUsingValue);
4313 
4314  return ToUsingValue;
4315 }
4316 
4319  DeclContext *DC, *LexicalDC;
4320  DeclarationName Name;
4321  SourceLocation Loc;
4322  NamedDecl *ToD = nullptr;
4323  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4324  return std::move(Err);
4325  if (ToD)
4326  return ToD;
4327 
4328  SourceLocation ToUsingLoc, ToTypenameLoc, ToEllipsisLoc;
4329  NestedNameSpecifierLoc ToQualifierLoc;
4330  if (auto Imp = importSeq(
4331  D->getUsingLoc(), D->getTypenameLoc(), D->getQualifierLoc(),
4332  D->getEllipsisLoc()))
4333  std::tie(ToUsingLoc, ToTypenameLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp;
4334  else
4335  return Imp.takeError();
4336 
4337  UnresolvedUsingTypenameDecl *ToUsing;
4338  if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
4339  ToUsingLoc, ToTypenameLoc,
4340  ToQualifierLoc, Loc, Name, ToEllipsisLoc))
4341  return ToUsing;
4342 
4343  ToUsing->setAccess(D->getAccess());
4344  ToUsing->setLexicalDeclContext(LexicalDC);
4345  LexicalDC->addDeclInternal(ToUsing);
4346 
4347  return ToUsing;
4348 }
4349 
4350 
4353  if (To->getDefinition()) {
4354  // Check consistency of superclass.
4355  ObjCInterfaceDecl *FromSuper = From->getSuperClass();
4356  if (FromSuper) {
4357  if (auto FromSuperOrErr = import(FromSuper))
4358  FromSuper = *FromSuperOrErr;
4359  else
4360  return FromSuperOrErr.takeError();
4361  }
4362 
4363  ObjCInterfaceDecl *ToSuper = To->getSuperClass();
4364  if ((bool)FromSuper != (bool)ToSuper ||
4365  (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
4366  Importer.ToDiag(To->getLocation(),
4367  diag::err_odr_objc_superclass_inconsistent)
4368  << To->getDeclName();
4369  if (ToSuper)
4370  Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
4371  << To->getSuperClass()->getDeclName();
4372  else
4373  Importer.ToDiag(To->getLocation(),
4374  diag::note_odr_objc_missing_superclass);
4375  if (From->getSuperClass())
4376  Importer.FromDiag(From->getSuperClassLoc(),
4377  diag::note_odr_objc_superclass)
4378  << From->getSuperClass()->getDeclName();
4379  else
4380  Importer.FromDiag(From->getLocation(),
4381  diag::note_odr_objc_missing_superclass);
4382  }
4383 
4384  if (shouldForceImportDeclContext(Kind))
4385  if (Error Err = ImportDeclContext(From))
4386  return Err;
4387  return Error::success();
4388  }
4389 
4390  // Start the definition.
4391  To->startDefinition();
4392 
4393  // If this class has a superclass, import it.
4394  if (From->getSuperClass()) {
4395  if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
4396  To->setSuperClass(*SuperTInfoOrErr);
4397  else
4398  return SuperTInfoOrErr.takeError();
4399  }
4400 
4401  // Import protocols
4403  SmallVector<SourceLocation, 4> ProtocolLocs;
4405  From->protocol_loc_begin();
4406 
4407  for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(),
4408  FromProtoEnd = From->protocol_end();
4409  FromProto != FromProtoEnd;
4410  ++FromProto, ++FromProtoLoc) {
4411  if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
4412  Protocols.push_back(*ToProtoOrErr);
4413  else
4414  return ToProtoOrErr.takeError();
4415 
4416  if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
4417  ProtocolLocs.push_back(*ToProtoLocOrErr);
4418  else
4419  return ToProtoLocOrErr.takeError();
4420 
4421  }
4422 
4423  // FIXME: If we're merging, make sure that the protocol list is the same.
4424  To->setProtocolList(Protocols.data(), Protocols.size(),
4425  ProtocolLocs.data(), Importer.getToContext());
4426 
4427  // Import categories. When the categories themselves are imported, they'll
4428  // hook themselves into this interface.
4429  for (auto *Cat : From->known_categories()) {
4430  auto ToCatOrErr = import(Cat);
4431  if (!ToCatOrErr)
4432  return ToCatOrErr.takeError();
4433  }
4434 
4435  // If we have an @implementation, import it as well.
4436  if (From->getImplementation()) {
4437  if (Expected<ObjCImplementationDecl *> ToImplOrErr =
4438  import(From->getImplementation()))
4439  To->setImplementation(*ToImplOrErr);
4440  else
4441  return ToImplOrErr.takeError();
4442  }
4443 
4444  if (shouldForceImportDeclContext(Kind)) {
4445  // Import all of the members of this class.
4446  if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
4447  return Err;
4448  }
4449  return Error::success();
4450 }
4451 
4454  if (!list)
4455  return nullptr;
4456 
4458  for (auto *fromTypeParam : *list) {
4459  if (auto toTypeParamOrErr = import(fromTypeParam))
4460  toTypeParams.push_back(*toTypeParamOrErr);
4461  else
4462  return toTypeParamOrErr.takeError();
4463  }
4464 
4465  auto LAngleLocOrErr = import(list->getLAngleLoc());
4466  if (!LAngleLocOrErr)
4467  return LAngleLocOrErr.takeError();
4468 
4469  auto RAngleLocOrErr = import(list->getRAngleLoc());
4470  if (!RAngleLocOrErr)
4471  return RAngleLocOrErr.takeError();
4472 
4473  return ObjCTypeParamList::create(Importer.getToContext(),
4474  *LAngleLocOrErr,
4475  toTypeParams,
4476  *RAngleLocOrErr);
4477 }
4478 
4480  // If this class has a definition in the translation unit we're coming from,
4481  // but this particular declaration is not that definition, import the
4482  // definition and map to that.
4483  ObjCInterfaceDecl *Definition = D->getDefinition();
4484  if (Definition && Definition != D) {
4485  if (ExpectedDecl ImportedDefOrErr = import(Definition))
4486  return Importer.MapImported(D, *ImportedDefOrErr);
4487  else
4488  return ImportedDefOrErr.takeError();
4489  }
4490 
4491  // Import the major distinguishing characteristics of an @interface.
4492  DeclContext *DC, *LexicalDC;
4493  DeclarationName Name;
4494  SourceLocation Loc;
4495  NamedDecl *ToD;
4496  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4497  return std::move(Err);
4498  if (ToD)
4499  return ToD;
4500 
4501  // Look for an existing interface with the same name.
4502  ObjCInterfaceDecl *MergeWithIface = nullptr;
4503  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4504  for (auto *FoundDecl : FoundDecls) {
4506  continue;
4507 
4508  if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
4509  break;
4510  }
4511 
4512  // Create an interface declaration, if one does not already exist.
4513  ObjCInterfaceDecl *ToIface = MergeWithIface;
4514  if (!ToIface) {
4515  ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
4516  if (!AtBeginLocOrErr)
4517  return AtBeginLocOrErr.takeError();
4518 
4519  if (GetImportedOrCreateDecl(
4520  ToIface, D, Importer.getToContext(), DC,
4521  *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
4522  /*TypeParamList=*/nullptr,
4523  /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
4524  return ToIface;
4525  ToIface->setLexicalDeclContext(LexicalDC);
4526  LexicalDC->addDeclInternal(ToIface);
4527  }
4528  Importer.MapImported(D, ToIface);
4529  // Import the type parameter list after MapImported, to avoid
4530  // loops when bringing in their DeclContext.
4531  if (auto ToPListOrErr =
4532  ImportObjCTypeParamList(D->getTypeParamListAsWritten()))
4533  ToIface->setTypeParamList(*ToPListOrErr);
4534  else
4535  return ToPListOrErr.takeError();
4536 
4538  if (Error Err = ImportDefinition(D, ToIface))
4539  return std::move(Err);
4540 
4541  return ToIface;
4542 }
4543 
4547  if (Error Err = importInto(Category, D->getCategoryDecl()))
4548  return std::move(Err);
4549 
4550  ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
4551  if (!ToImpl) {
4552  DeclContext *DC, *LexicalDC;
4553  if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4554  return std::move(Err);
4555 
4556  SourceLocation ToLocation, ToAtStartLoc, ToCategoryNameLoc;
4557  if (auto Imp = importSeq(
4558  D->getLocation(), D->getAtStartLoc(), D->getCategoryNameLoc()))
4559  std::tie(ToLocation, ToAtStartLoc, ToCategoryNameLoc) = *Imp;
4560  else
4561  return Imp.takeError();
4562 
4563  if (GetImportedOrCreateDecl(
4564  ToImpl, D, Importer.getToContext(), DC,
4565  Importer.Import(D->getIdentifier()), Category->getClassInterface(),
4566  ToLocation, ToAtStartLoc, ToCategoryNameLoc))
4567  return ToImpl;
4568 
4569  ToImpl->setLexicalDeclContext(LexicalDC);
4570  LexicalDC->addDeclInternal(ToImpl);
4571  Category->setImplementation(ToImpl);
4572  }
4573 
4574  Importer.MapImported(D, ToImpl);
4575  if (Error Err = ImportDeclContext(D))
4576  return std::move(Err);
4577 
4578  return ToImpl;
4579 }
4580 
4583  // Find the corresponding interface.
4584  ObjCInterfaceDecl *Iface;
4585  if (Error Err = importInto(Iface, D->getClassInterface()))
4586  return std::move(Err);
4587 
4588  // Import the superclass, if any.
4589  ObjCInterfaceDecl *Super;
4590  if (Error Err = importInto(Super, D->getSuperClass()))
4591  return std::move(Err);
4592 
4593  ObjCImplementationDecl *Impl = Iface->getImplementation();
4594  if (!Impl) {
4595  // We haven't imported an implementation yet. Create a new @implementation
4596  // now.
4597  DeclContext *DC, *LexicalDC;
4598  if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4599  return std::move(Err);
4600 
4601  SourceLocation ToLocation, ToAtStartLoc, ToSuperClassLoc;
4602  SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc;
4603  if (auto Imp = importSeq(
4604  D->getLocation(), D->getAtStartLoc(), D->getSuperClassLoc(),
4605  D->getIvarLBraceLoc(), D->getIvarRBraceLoc()))
4606  std::tie(
4607  ToLocation, ToAtStartLoc, ToSuperClassLoc,
4608  ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp;
4609  else
4610  return Imp.takeError();
4611 
4612  if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
4613  DC, Iface, Super,
4614  ToLocation,
4615  ToAtStartLoc,
4616  ToSuperClassLoc,
4617  ToIvarLBraceLoc,
4618  ToIvarRBraceLoc))
4619  return Impl;
4620 
4621  Impl->setLexicalDeclContext(LexicalDC);
4622 
4623  // Associate the implementation with the class it implements.
4624  Iface->setImplementation(Impl);
4625  Importer.MapImported(D, Iface->getImplementation());
4626  } else {
4627  Importer.MapImported(D, Iface->getImplementation());
4628 
4629  // Verify that the existing @implementation has the same superclass.
4630  if ((Super && !Impl->getSuperClass()) ||
4631  (!Super && Impl->getSuperClass()) ||
4632  (Super && Impl->getSuperClass() &&
4634  Impl->getSuperClass()))) {
4635  Importer.ToDiag(Impl->getLocation(),
4636  diag::err_odr_objc_superclass_inconsistent)
4637  << Iface->getDeclName();
4638  // FIXME: It would be nice to have the location of the superclass
4639  // below.
4640  if (Impl->getSuperClass())
4641  Importer.ToDiag(Impl->getLocation(),
4642  diag::note_odr_objc_superclass)
4643  << Impl->getSuperClass()->getDeclName();
4644  else
4645  Importer.ToDiag(Impl->getLocation(),
4646  diag::note_odr_objc_missing_superclass);
4647  if (D->getSuperClass())
4648  Importer.FromDiag(D->getLocation(),
4649  diag::note_odr_objc_superclass)
4650  << D->getSuperClass()->getDeclName();
4651  else
4652  Importer.FromDiag(D->getLocation(),
4653  diag::note_odr_objc_missing_superclass);
4654 
4655  return make_error<ImportError>(ImportError::NameConflict);
4656  }
4657  }
4658 
4659  // Import all of the members of this @implementation.
4660  if (Error Err = ImportDeclContext(D))
4661  return std::move(Err);
4662 
4663  return Impl;
4664 }
4665 
4667  // Import the major distinguishing characteristics of an @property.
4668  DeclContext *DC, *LexicalDC;
4669  DeclarationName Name;
4670  SourceLocation Loc;
4671  NamedDecl *ToD;
4672  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4673  return std::move(Err);
4674  if (ToD)
4675  return ToD;
4676 
4677  // Check whether we have already imported this property.
4678  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4679  for (auto *FoundDecl : FoundDecls) {
4680  if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
4681  // Check property types.
4682  if (!Importer.IsStructurallyEquivalent(D->getType(),
4683  FoundProp->getType())) {
4684  Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent)
4685  << Name << D->getType() << FoundProp->getType();
4686  Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
4687  << FoundProp->getType();
4688 
4689  return make_error<ImportError>(ImportError::NameConflict);
4690  }
4691 
4692  // FIXME: Check property attributes, getters, setters, etc.?
4693 
4694  // Consider these properties to be equivalent.
4695  Importer.MapImported(D, FoundProp);
4696  return FoundProp;
4697  }
4698  }
4699 
4700  QualType ToType;
4701  TypeSourceInfo *ToTypeSourceInfo;
4702  SourceLocation ToAtLoc, ToLParenLoc;
4703  if (auto Imp = importSeq(
4704  D->getType(), D->getTypeSourceInfo(), D->getAtLoc(), D->getLParenLoc()))
4705  std::tie(ToType, ToTypeSourceInfo, ToAtLoc, ToLParenLoc) = *Imp;
4706  else
4707  return Imp.takeError();
4708 
4709  // Create the new property.
4710  ObjCPropertyDecl *ToProperty;
4711  if (GetImportedOrCreateDecl(
4712  ToProperty, D, Importer.getToContext(), DC, Loc,
4713  Name.getAsIdentifierInfo(), ToAtLoc,
4714  ToLParenLoc, ToType,
4715  ToTypeSourceInfo, D->getPropertyImplementation()))
4716  return ToProperty;
4717 
4718  Selector ToGetterName, ToSetterName;
4719  SourceLocation ToGetterNameLoc, ToSetterNameLoc;
4720  ObjCMethodDecl *ToGetterMethodDecl, *ToSetterMethodDecl;
4721  ObjCIvarDecl *ToPropertyIvarDecl;
4722  if (auto Imp = importSeq(
4723  D->getGetterName(), D->getSetterName(),
4726  D->getPropertyIvarDecl()))
4727  std::tie(
4728  ToGetterName, ToSetterName,
4729  ToGetterNameLoc, ToSetterNameLoc,
4730  ToGetterMethodDecl, ToSetterMethodDecl,
4731  ToPropertyIvarDecl) = *Imp;
4732  else
4733  return Imp.takeError();
4734 
4735  ToProperty->setLexicalDeclContext(LexicalDC);
4736  LexicalDC->addDeclInternal(ToProperty);
4737 
4738  ToProperty->setPropertyAttributes(D->getPropertyAttributes());
4739  ToProperty->setPropertyAttributesAsWritten(
4741  ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
4742  ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
4743  ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
4744  ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
4745  ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
4746  return ToProperty;
4747 }
4748 
4752  if (Error Err = importInto(Property, D->getPropertyDecl()))
4753  return std::move(Err);
4754 
4755  DeclContext *DC, *LexicalDC;
4756  if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4757  return std::move(Err);
4758 
4759  auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
4760 
4761  // Import the ivar (for an @synthesize).
4762  ObjCIvarDecl *Ivar = nullptr;
4763  if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
4764  return std::move(Err);
4765 
4766  ObjCPropertyImplDecl *ToImpl
4767  = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
4768  Property->getQueryKind());
4769  if (!ToImpl) {
4770  SourceLocation ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc;
4771  if (auto Imp = importSeq(
4773  std::tie(ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc) = *Imp;
4774  else
4775  return Imp.takeError();
4776 
4777  if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
4778  ToBeginLoc,
4779  ToLocation, Property,
4780  D->getPropertyImplementation(), Ivar,
4781  ToPropertyIvarDeclLoc))
4782  return ToImpl;
4783 
4784  ToImpl->setLexicalDeclContext(LexicalDC);
4785  LexicalDC->addDeclInternal(ToImpl);
4786  } else {
4787  // Check that we have the same kind of property implementation (@synthesize
4788  // vs. @dynamic).
4789  if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) {
4790  Importer.ToDiag(ToImpl->getLocation(),
4791  diag::err_odr_objc_property_impl_kind_inconsistent)
4792  << Property->getDeclName()
4793  << (ToImpl->getPropertyImplementation()
4795  Importer.FromDiag(D->getLocation(),
4796  diag::note_odr_objc_property_impl_kind)
4797  << D->getPropertyDecl()->getDeclName()
4799 
4800  return make_error<ImportError>(ImportError::NameConflict);
4801  }
4802 
4803  // For @synthesize, check that we have the same
4805  Ivar != ToImpl->getPropertyIvarDecl()) {
4806  Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
4807  diag::err_odr_objc_synthesize_ivar_inconsistent)
4808  << Property->getDeclName()
4809  << ToImpl->getPropertyIvarDecl()->getDeclName()
4810  << Ivar->getDeclName();
4811  Importer.FromDiag(D->getPropertyIvarDeclLoc(),
4812  diag::note_odr_objc_synthesize_ivar_here)
4813  << D->getPropertyIvarDecl()->getDeclName();
4814 
4815  return make_error<ImportError>(ImportError::NameConflict);
4816  }
4817 
4818  // Merge the existing implementation with the new implementation.
4819  Importer.MapImported(D, ToImpl);
4820  }
4821 
4822  return ToImpl;
4823 }
4824 
4827  // For template arguments, we adopt the translation unit as our declaration
4828  // context. This context will be fixed when the actual template declaration
4829  // is created.
4830 
4831  // FIXME: Import default argument.
4832 
4833  ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
4834  if (!BeginLocOrErr)
4835  return BeginLocOrErr.takeError();
4836 
4837  ExpectedSLoc LocationOrErr = import(D->getLocation());
4838  if (!LocationOrErr)
4839  return LocationOrErr.takeError();
4840 
4841  TemplateTypeParmDecl *ToD = nullptr;
4842  (void)GetImportedOrCreateDecl(
4843  ToD, D, Importer.getToContext(),
4844  Importer.getToContext().getTranslationUnitDecl(),
4845  *BeginLocOrErr, *LocationOrErr,
4846  D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
4848  return ToD;
4849 }
4850 
4853  DeclarationName ToDeclName;
4854  SourceLocation ToLocation, ToInnerLocStart;
4855  QualType ToType;
4856  TypeSourceInfo *ToTypeSourceInfo;
4857  if (auto Imp = importSeq(
4858  D->getDeclName(), D->getLocation(), D->getType(), D->getTypeSourceInfo(),
4859  D->getInnerLocStart()))
4860  std::tie(
4861  ToDeclName, ToLocation, ToType, ToTypeSourceInfo,
4862  ToInnerLocStart) = *Imp;
4863  else
4864  return Imp.takeError();
4865 
4866  // FIXME: Import default argument.
4867 
4868  NonTypeTemplateParmDecl *ToD = nullptr;
4869  (void)GetImportedOrCreateDecl(
4870  ToD, D, Importer.getToContext(),
4871  Importer.getToContext().getTranslationUnitDecl(),
4872  ToInnerLocStart, ToLocation, D->getDepth(),
4873  D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType,
4874  D->isParameterPack(), ToTypeSourceInfo);
4875  return ToD;
4876 }
4877 
4880  // Import the name of this declaration.
4881  auto NameOrErr = import(D->getDeclName());
4882  if (!NameOrErr)
4883  return NameOrErr.takeError();
4884 
4885  // Import the location of this declaration.
4886  ExpectedSLoc LocationOrErr = import(D->getLocation());
4887  if (!LocationOrErr)
4888  return LocationOrErr.takeError();
4889 
4890  // Import template parameters.
4891  auto TemplateParamsOrErr = ImportTemplateParameterList(
4892  D->getTemplateParameters());
4893  if (!TemplateParamsOrErr)
4894  return TemplateParamsOrErr.takeError();
4895 
4896  // FIXME: Import default argument.
4897 
4898  TemplateTemplateParmDecl *ToD = nullptr;
4899  (void)GetImportedOrCreateDecl(
4900  ToD, D, Importer.getToContext(),
4901  Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
4902  D->getDepth(), D->getPosition(), D->isParameterPack(),
4903  (*NameOrErr).getAsIdentifierInfo(),
4904  *TemplateParamsOrErr);
4905  return ToD;
4906 }
4907 
4908 // Returns the definition for a (forward) declaration of a ClassTemplateDecl, if
4909 // it has any definition in the redecl chain.
4911  CXXRecordDecl *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
4912  if (!ToTemplatedDef)
4913  return nullptr;
4914  ClassTemplateDecl *TemplateWithDef =
4915  ToTemplatedDef->getDescribedClassTemplate();
4916  return TemplateWithDef;
4917 }
4918 
4920  bool IsFriend = D->getFriendObjectKind() != Decl::FOK_None;
4921 
4922  // If this template has a definition in the translation unit we're coming
4923  // from, but this particular declaration is not that definition, import the
4924  // definition and map to that.
4925  ClassTemplateDecl *Definition = getDefinition(D);
4926  if (Definition && Definition != D && !IsFriend) {
4927  if (ExpectedDecl ImportedDefOrErr = import(Definition))
4928  return Importer.MapImported(D, *ImportedDefOrErr);
4929  else
4930  return ImportedDefOrErr.takeError();
4931  }
4932 
4933  // Import the major distinguishing characteristics of this class template.
4934  DeclContext *DC, *LexicalDC;
4935  DeclarationName Name;
4936  SourceLocation Loc;
4937  NamedDecl *ToD;
4938  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4939  return std::move(Err);
4940  if (ToD)
4941  return ToD;
4942 
4943  ClassTemplateDecl *FoundByLookup = nullptr;
4944 
4945  // We may already have a template of the same name; try to find and match it.
4946  if (!DC->isFunctionOrMethod()) {
4947  SmallVector<NamedDecl *, 4> ConflictingDecls;
4948  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4949  for (auto *FoundDecl : FoundDecls) {
4952  continue;
4953 
4954  Decl *Found = FoundDecl;
4955  auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found);
4956  if (FoundTemplate) {
4957 
4958  if (IsStructuralMatch(D, FoundTemplate)) {
4959  ClassTemplateDecl *TemplateWithDef = getDefinition(FoundTemplate);
4960  if (D->isThisDeclarationADefinition() && TemplateWithDef) {
4961  return Importer.MapImported(D, TemplateWithDef);
4962  }
4963  FoundByLookup = FoundTemplate;
4964  break;
4965  }
4966  }
4967 
4968  ConflictingDecls.push_back(FoundDecl);
4969  }
4970 
4971  if (!ConflictingDecls.empty()) {
4972  Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary,
4973  ConflictingDecls.data(),
4974  ConflictingDecls.size());
4975  }
4976 
4977  if (!Name)
4978  return make_error<ImportError>(ImportError::NameConflict);
4979  }
4980 
4981  CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
4982 
4983  // Create the declaration that is being templated.
4984  CXXRecordDecl *ToTemplated;
4985  if (Error Err = importInto(ToTemplated, FromTemplated))
4986  return std::move(Err);
4987 
4988  // Create the class template declaration itself.
4989  auto TemplateParamsOrErr = ImportTemplateParameterList(
4990  D->getTemplateParameters());
4991  if (!TemplateParamsOrErr)
4992  return TemplateParamsOrErr.takeError();
4993 
4994  ClassTemplateDecl *D2;
4995  if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
4996  *TemplateParamsOrErr, ToTemplated))
4997  return D2;
4998 
4999  ToTemplated->setDescribedClassTemplate(D2);
5000 
5001  D2->setAccess(D->getAccess());
5002  D2->setLexicalDeclContext(LexicalDC);
5003 
5004  if (D->getDeclContext()->containsDeclAndLoad(D))
5005  DC->addDeclInternal(D2);
5006  if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D))
5007  LexicalDC->addDeclInternal(D2);
5008 
5009  if (FoundByLookup) {
5010  auto *Recent =
5011  const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
5012 
5013  // It is possible that during the import of the class template definition
5014  // we start the import of a fwd friend decl of the very same class template
5015  // and we add the fwd friend decl to the lookup table. But the ToTemplated
5016  // had been created earlier and by that time the lookup could not find
5017  // anything existing, so it has no previous decl. Later, (still during the
5018  // import of the fwd friend decl) we start to import the definition again
5019  // and this time the lookup finds the previous fwd friend class template.
5020  // In this case we must set up the previous decl for the templated decl.
5021  if (!ToTemplated->getPreviousDecl()) {
5022  CXXRecordDecl *PrevTemplated =
5023  FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
5024  if (ToTemplated != PrevTemplated)
5025  ToTemplated->setPreviousDecl(PrevTemplated);
5026  }
5027 
5028  D2->setPreviousDecl(Recent);
5029  }
5030 
5031  if (LexicalDC != DC && IsFriend)
5032  DC->makeDeclVisibleInContext(D2);
5033 
5034  if (FromTemplated->isCompleteDefinition() &&
5035  !ToTemplated->isCompleteDefinition()) {
5036  // FIXME: Import definition!
5037  }
5038 
5039  return D2;
5040 }
5041 
5044  // If this record has a definition in the translation unit we're coming from,
5045  // but this particular declaration is not that definition, import the
5046  // definition and map to that.
5047  TagDecl *Definition = D->getDefinition();
5048  if (Definition && Definition != D) {
5049  if (ExpectedDecl ImportedDefOrErr = import(Definition))
5050  return Importer.MapImported(D, *ImportedDefOrErr);
5051  else
5052  return ImportedDefOrErr.takeError();
5053  }
5054 
5055  ClassTemplateDecl *ClassTemplate;
5056  if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
5057  return std::move(Err);
5058 
5059  // Import the context of this declaration.
5060  DeclContext *DC, *LexicalDC;
5061  if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5062  return std::move(Err);
5063 
5064  // Import template arguments.
5065  SmallVector<TemplateArgument, 2> TemplateArgs;
5066  if (Error Err = ImportTemplateArguments(
5067  D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs))
5068  return std::move(Err);
5069 
5070  // Try to find an existing specialization with these template arguments.
5071  void *InsertPos = nullptr;
5072  ClassTemplateSpecializationDecl *D2 = nullptr;
5075  if (PartialSpec)
5076  D2 = ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos);
5077  else
5078  D2 = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
5079  ClassTemplateSpecializationDecl * const PrevDecl = D2;
5080  RecordDecl *FoundDef = D2 ? D2->getDefinition() : nullptr;
5081  if (FoundDef) {
5082  if (!D->isCompleteDefinition()) {
5083  // The "From" translation unit only had a forward declaration; call it
5084  // the same declaration.
5085  // TODO Handle the redecl chain properly!
5086  return Importer.MapImported(D, FoundDef);
5087  }
5088 
5089  if (IsStructuralMatch(D, FoundDef)) {
5090 
5091  Importer.MapImported(D, FoundDef);
5092 
5093  // Import those those default field initializers which have been
5094  // instantiated in the "From" context, but not in the "To" context.
5095  for (auto *FromField : D->fields()) {
5096  auto ToOrErr = import(FromField);
5097  if (!ToOrErr)
5098  // FIXME: return the error?
5099  consumeError(ToOrErr.takeError());
5100  }
5101 
5102  // Import those methods which have been instantiated in the
5103  // "From" context, but not in the "To" context.
5104  for (CXXMethodDecl *FromM : D->methods()) {
5105  auto ToOrErr = import(FromM);
5106  if (!ToOrErr)
5107  // FIXME: return the error?
5108  consumeError(ToOrErr.takeError());
5109  }
5110 
5111  // TODO Import instantiated default arguments.
5112  // TODO Import instantiated exception specifications.
5113  //
5114  // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint what
5115  // else could be fused during an AST merge.
5116 
5117  return FoundDef;
5118  }
5119  } else { // We either couldn't find any previous specialization in the "To"
5120  // context, or we found one but without definition. Let's create a
5121  // new specialization and register that at the class template.
5122 
5123  // Import the location of this declaration.
5124  ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
5125  if (!BeginLocOrErr)
5126  return BeginLocOrErr.takeError();
5127  ExpectedSLoc IdLocOrErr = import(D->getLocation());
5128  if (!IdLocOrErr)
5129  return IdLocOrErr.takeError();
5130 
5131  if (PartialSpec) {
5132  // Import TemplateArgumentListInfo.
5133  TemplateArgumentListInfo ToTAInfo;
5134  const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten();
5135  if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo))
5136  return std::move(Err);
5137 
5138  QualType CanonInjType;
5139  if (Error Err = importInto(
5140  CanonInjType, PartialSpec->getInjectedSpecializationType()))
5141  return std::move(Err);
5142  CanonInjType = CanonInjType.getCanonicalType();
5143 
5144  auto ToTPListOrErr = ImportTemplateParameterList(
5145  PartialSpec->getTemplateParameters());
5146  if (!ToTPListOrErr)
5147  return ToTPListOrErr.takeError();
5148 
5149  if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
5150  D2, D, Importer.getToContext(), D->getTagKind(), DC,
5151  *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, ClassTemplate,
5152  llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()),
5153  ToTAInfo, CanonInjType,
5154  cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
5155  return D2;
5156 
5157  // Update InsertPos, because preceding import calls may have invalidated
5158  // it by adding new specializations.
5159  if (!ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos))
5160  // Add this partial specialization to the class template.
5161  ClassTemplate->AddPartialSpecialization(
5162  cast<ClassTemplatePartialSpecializationDecl>(D2), InsertPos);
5163 
5164  } else { // Not a partial specialization.
5165  if (GetImportedOrCreateDecl(
5166  D2, D, Importer.getToContext(), D->getTagKind(), DC,
5167  *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs,
5168  PrevDecl))
5169  return D2;
5170 
5171  // Update InsertPos, because preceding import calls may have invalidated
5172  // it by adding new specializations.
5173  if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos))
5174  // Add this specialization to the class template.
5175  ClassTemplate->AddSpecialization(D2, InsertPos);
5176  }
5177 
5179 
5180  // Import the qualifier, if any.
5181  if (auto LocOrErr = import(D->getQualifierLoc()))
5182  D2->setQualifierInfo(*LocOrErr);
5183  else
5184  return LocOrErr.takeError();
5185 
5186  if (auto *TSI = D->getTypeAsWritten()) {
5187  if (auto TInfoOrErr = import(TSI))
5188  D2->setTypeAsWritten(*TInfoOrErr);
5189  else
5190  return TInfoOrErr.takeError();
5191 
5192  if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
5193  D2->setTemplateKeywordLoc(*LocOrErr);
5194  else
5195  return LocOrErr.takeError();
5196 
5197  if (auto LocOrErr = import(D->getExternLoc()))
5198  D2->setExternLoc(*LocOrErr);
5199  else
5200  return LocOrErr.takeError();
5201  }
5202 
5203  if (D->getPointOfInstantiation().isValid()) {
5204  if (auto POIOrErr = import(D->getPointOfInstantiation()))
5205  D2->setPointOfInstantiation(*POIOrErr);
5206  else
5207  return POIOrErr.takeError();
5208  }
5209 
5211 
5212  // Set the context of this specialization/instantiation.
5213  D2->setLexicalDeclContext(LexicalDC);
5214 
5215  // Add to the DC only if it was an explicit specialization/instantiation.
5217  LexicalDC->addDeclInternal(D2);
5218  }
5219  }
5220  if (D->isCompleteDefinition())
5221  if (Error Err = ImportDefinition(D, D2))
5222  return std::move(Err);
5223 
5224  return D2;
5225 }
5226 
5228  // If this variable has a definition in the translation unit we're coming
5229  // from,
5230  // but this particular declaration is not that definition, import the
5231  // definition and map to that.
5232  auto *Definition =
5233  cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition());
5234  if (Definition && Definition != D->getTemplatedDecl()) {
5235  if (ExpectedDecl ImportedDefOrErr = import(
5236  Definition->getDescribedVarTemplate()))
5237  return Importer.MapImported(D, *ImportedDefOrErr);
5238  else
5239  return ImportedDefOrErr.takeError();
5240  }
5241 
5242  // Import the major distinguishing characteristics of this variable template.
5243  DeclContext *DC, *LexicalDC;
5244  DeclarationName Name;
5245  SourceLocation Loc;
5246  NamedDecl *ToD;
5247  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5248  return std::move(Err);
5249  if (ToD)
5250  return ToD;
5251 
5252  // We may already have a template of the same name; try to find and match it.
5253  assert(!DC->isFunctionOrMethod() &&
5254  "Variable templates cannot be declared at function scope");
5255  SmallVector<NamedDecl *, 4> ConflictingDecls;
5256  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5257  for (auto *FoundDecl : FoundDecls) {
5259  continue;
5260 
5261  Decl *Found = FoundDecl;
5262  if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) {
5263  if (IsStructuralMatch(D, FoundTemplate)) {
5264  // The variable templates structurally match; call it the same template.
5265  Importer.MapImported(D->getTemplatedDecl(),
5266  FoundTemplate->getTemplatedDecl());
5267  return Importer.MapImported(D, FoundTemplate);
5268  }
5269  }
5270 
5271  ConflictingDecls.push_back(FoundDecl);
5272  }
5273 
5274  if (!ConflictingDecls.empty()) {
5275  Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary,
5276  ConflictingDecls.data(),
5277  ConflictingDecls.size());
5278  }
5279 
5280  if (!Name)
5281  // FIXME: Is it possible to get other error than name conflict?
5282  // (Put this `if` into the previous `if`?)
5283  return make_error<ImportError>(ImportError::NameConflict);
5284 
5285  VarDecl *DTemplated = D->getTemplatedDecl();
5286 
5287  // Import the type.
5288  // FIXME: Value not used?
5289  ExpectedType TypeOrErr = import(DTemplated->getType());
5290  if (!TypeOrErr)
5291  return TypeOrErr.takeError();
5292 
5293  // Create the declaration that is being templated.
5294  VarDecl *ToTemplated;
5295  if (Error Err = importInto(ToTemplated, DTemplated))
5296  return std::move(Err);
5297 
5298  // Create the variable template declaration itself.
5299  auto TemplateParamsOrErr = ImportTemplateParameterList(
5300  D->getTemplateParameters());
5301  if (!TemplateParamsOrErr)
5302  return TemplateParamsOrErr.takeError();
5303 
5304  VarTemplateDecl *ToVarTD;
5305  if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
5306  Name, *TemplateParamsOrErr, ToTemplated))
5307  return ToVarTD;
5308 
5309  ToTemplated->setDescribedVarTemplate(ToVarTD);
5310 
5311  ToVarTD->setAccess(D->getAccess());
5312  ToVarTD->setLexicalDeclContext(LexicalDC);
5313  LexicalDC->addDeclInternal(ToVarTD);
5314 
5315  if (DTemplated->isThisDeclarationADefinition() &&
5316  !ToTemplated->isThisDeclarationADefinition()) {
5317  // FIXME: Import definition!
5318  }
5319 
5320  return ToVarTD;
5321 }
5322 
5325  // If this record has a definition in the translation unit we're coming from,
5326  // but this particular declaration is not that definition, import the
5327  // definition and map to that.
5328  VarDecl *Definition = D->getDefinition();
5329  if (Definition && Definition != D) {
5330  if (ExpectedDecl ImportedDefOrErr = import(Definition))
5331  return Importer.MapImported(D, *ImportedDefOrErr);
5332  else
5333  return ImportedDefOrErr.takeError();
5334  }
5335 
5336  VarTemplateDecl *VarTemplate;
5337  if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate()))
5338  return std::move(Err);
5339 
5340  // Import the context of this declaration.
5341  DeclContext *DC, *LexicalDC;
5342  if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5343  return std::move(Err);
5344 
5345  // Import the location of this declaration.
5346  ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
5347  if (!BeginLocOrErr)
5348  return BeginLocOrErr.takeError();
5349 
5350  auto IdLocOrErr = import(D->getLocation());
5351  if (!IdLocOrErr)
5352  return IdLocOrErr.takeError();
5353 
5354  // Import template arguments.
5355  SmallVector<TemplateArgument, 2> TemplateArgs;
5356  if (Error Err = ImportTemplateArguments(
5357  D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs))
5358  return std::move(Err);
5359 
5360  // Try to find an existing specialization with these template arguments.
5361  void *InsertPos = nullptr;
5363  TemplateArgs, InsertPos);
5364  if (D2) {
5365  // We already have a variable template specialization with these template
5366  // arguments.
5367 
5368  // FIXME: Check for specialization vs. instantiation errors.
5369 
5370  if (VarDecl *FoundDef = D2->getDefinition()) {
5371  if (!D->isThisDeclarationADefinition() ||
5372  IsStructuralMatch(D, FoundDef)) {
5373  // The record types structurally match, or the "from" translation
5374  // unit only had a forward declaration anyway; call it the same
5375  // variable.
5376  return Importer.MapImported(D, FoundDef);
5377  }
5378  }
5379  } else {
5380  // Import the type.
5381  QualType T;
5382  if (Error Err = importInto(T, D->getType()))
5383  return std::move(Err);
5384 
5385  auto TInfoOrErr = import(D->getTypeSourceInfo());
5386  if (!TInfoOrErr)
5387  return TInfoOrErr.takeError();
5388 
5389  TemplateArgumentListInfo ToTAInfo;
5390  if (Error Err = ImportTemplateArgumentListInfo(
5391  D->getTemplateArgsInfo(), ToTAInfo))
5392  return std::move(Err);
5393 
5394  using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
5395  // Create a new specialization.
5396  if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
5397  // Import TemplateArgumentListInfo
5398  TemplateArgumentListInfo ArgInfos;
5399  const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten();
5400  // NOTE: FromTAArgsAsWritten and template parameter list are non-null.
5401  if (Error Err = ImportTemplateArgumentListInfo(
5402  *FromTAArgsAsWritten, ArgInfos))
5403  return std::move(Err);
5404 
5405  auto ToTPListOrErr = ImportTemplateParameterList(
5406  FromPartial->getTemplateParameters());
5407  if (!ToTPListOrErr)
5408  return ToTPListOrErr.takeError();
5409 
5410  PartVarSpecDecl *ToPartial;
5411  if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
5412  *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
5413  VarTemplate, T, *TInfoOrErr,
5414  D->getStorageClass(), TemplateArgs, ArgInfos))
5415  return ToPartial;
5416 
5417  if (Expected<PartVarSpecDecl *> ToInstOrErr = import(
5418  FromPartial->getInstantiatedFromMember()))
5419  ToPartial->setInstantiatedFromMember(*ToInstOrErr);
5420  else
5421  return ToInstOrErr.takeError();
5422 
5423  if (FromPartial->isMemberSpecialization())
5424  ToPartial->setMemberSpecialization();
5425 
5426  D2 = ToPartial;
5427 
5428  } else { // Full specialization
5429  if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
5430  *BeginLocOrErr, *IdLocOrErr, VarTemplate,
5431  T, *TInfoOrErr,
5432  D->getStorageClass(), TemplateArgs))
5433  return D2;
5434  }
5435 
5436  if (D->getPointOfInstantiation().isValid()) {
5437  if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
5438  D2->setPointOfInstantiation(*POIOrErr);
5439  else
5440  return POIOrErr.takeError();
5441  }
5442 
5444  D2->setTemplateArgsInfo(ToTAInfo);
5445 
5446  // Add this specialization to the class template.
5447  VarTemplate->AddSpecialization(D2, InsertPos);
5448 
5449  // Import the qualifier, if any.
5450  if (auto LocOrErr = import(D->getQualifierLoc()))
5451  D2->setQualifierInfo(*LocOrErr);
5452  else
5453  return LocOrErr.takeError();
5454 
5455  if (D->isConstexpr())
5456  D2->setConstexpr(true);
5457 
5458  // Add the specialization to this context.
5459  D2->setLexicalDeclContext(LexicalDC);
5460  LexicalDC->addDeclInternal(D2);
5461 
5462  D2->setAccess(D->getAccess());
5463  }
5464 
5465  if (Error Err = ImportInitializer(D, D2))
5466  return std::move(Err);
5467 
5468  return D2;
5469 }
5470 
5473  DeclContext *DC, *LexicalDC;
5474  DeclarationName Name;
5475  SourceLocation Loc;
5476  NamedDecl *ToD;
5477 
5478  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5479  return std::move(Err);
5480 
5481  if (ToD)
5482  return ToD;
5483 
5484  // Try to find a function in our own ("to") context with the same name, same
5485  // type, and in the same context as the function we're importing.
5486  if (!LexicalDC->isFunctionOrMethod()) {
5487  unsigned IDNS = Decl::IDNS_Ordinary;
5488  auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5489  for (auto *FoundDecl : FoundDecls) {
5490  if (!FoundDecl->isInIdentifierNamespace(IDNS))
5491  continue;
5492 
5493  if (auto *FoundFunction =
5494  dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
5495  if (FoundFunction->hasExternalFormalLinkage() &&
5496  D->hasExternalFormalLinkage()) {
5497  if (IsStructuralMatch(D, FoundFunction)) {
5498  Importer.MapImported(D, FoundFunction);
5499  // FIXME: Actually try to merge the body and other attributes.
5500  return FoundFunction;
5501  }
5502  }
5503  }
5504  // TODO: handle conflicting names
5505  }
5506  }
5507 
5508  auto ParamsOrErr = ImportTemplateParameterList(
5509  D->getTemplateParameters());
5510  if (!ParamsOrErr)
5511  return ParamsOrErr.takeError();
5512 
5513  FunctionDecl *TemplatedFD;
5514  if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
5515  return std::move(Err);
5516 
5517  FunctionTemplateDecl *ToFunc;
5518  if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
5519  *ParamsOrErr, TemplatedFD))
5520  return ToFunc;
5521 
5522  TemplatedFD->setDescribedFunctionTemplate(ToFunc);
5523  ToFunc->setAccess(D->getAccess());
5524  ToFunc->setLexicalDeclContext(LexicalDC);
5525 
5526  LexicalDC->addDeclInternal(ToFunc);
5527  return ToFunc;
5528 }
5529 
5530 //----------------------------------------------------------------------------
5531 // Import Statements
5532 //----------------------------------------------------------------------------
5533 
5535  Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
5536  << S->getStmtClassName();
5537  return make_error<ImportError>(ImportError::UnsupportedConstruct);
5538 }
5539 
5540 
5543  for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
5544  IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
5545  // ToII is nullptr when no symbolic name is given for output operand
5546  // see ParseStmtAsm::ParseAsmOperandsOpt
5547  Names.push_back(ToII);
5548  }
5549 
5550  for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
5551  IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
5552  // ToII is nullptr when no symbolic name is given for input operand
5553  // see ParseStmtAsm::ParseAsmOperandsOpt
5554  Names.push_back(ToII);
5555  }
5556 
5558  for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
5559  if (auto ClobberOrErr = import(S->getClobberStringLiteral(I)))
5560  Clobbers.push_back(*ClobberOrErr);
5561  else
5562  return ClobberOrErr.takeError();
5563 
5564  }
5565 
5566  SmallVector<StringLiteral *, 4> Constraints;
5567  for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
5568  if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I)))
5569  Constraints.push_back(*OutputOrErr);
5570  else
5571  return OutputOrErr.takeError();
5572  }
5573 
5574  for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
5575  if (auto InputOrErr = import(S->getInputConstraintLiteral(I)))
5576  Constraints.push_back(*InputOrErr);
5577  else
5578  return InputOrErr.takeError();
5579  }
5580 
5582  if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
5583  return std::move(Err);
5584 
5585  if (Error Err = ImportArrayChecked(
5586  S->inputs(), Exprs.begin() + S->getNumOutputs()))
5587  return std::move(Err);
5588 
5589  ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
5590  if (!AsmLocOrErr)
5591  return AsmLocOrErr.takeError();
5592  auto AsmStrOrErr = import(S->getAsmString());
5593  if (!AsmStrOrErr)
5594  return AsmStrOrErr.takeError();
5595  ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
5596  if (!RParenLocOrErr)
5597  return RParenLocOrErr.takeError();
5598 
5599  return new (Importer.getToContext()) GCCAsmStmt(
5600  Importer.getToContext(),
5601  *AsmLocOrErr,
5602  S->isSimple(),
5603  S->isVolatile(),
5604  S->getNumOutputs(),
5605  S->getNumInputs(),
5606  Names.data(),
5607  Constraints.data(),
5608  Exprs.data(),
5609  *AsmStrOrErr,
5610  S->getNumClobbers(),
5611  Clobbers.data(),
5612  *RParenLocOrErr);
5613 }
5614 
5616  auto Imp = importSeq(S->getDeclGroup(), S->getBeginLoc(), S->getEndLoc());
5617  if (!Imp)
5618  return Imp.takeError();
5619 
5620  DeclGroupRef ToDG;
5621  SourceLocation ToBeginLoc, ToEndLoc;
5622  std::tie(ToDG, ToBeginLoc, ToEndLoc) = *Imp;
5623 
5624  return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
5625 }
5626 
5628  ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
5629  if (!ToSemiLocOrErr)
5630  return ToSemiLocOrErr.takeError();
5631  return new (Importer.getToContext()) NullStmt(
5632  *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
5633 }
5634 
5636  SmallVector<Stmt *, 8> ToStmts(S->size());
5637 
5638  if (Error Err = ImportContainerChecked(S->body(), ToStmts))
5639  return std::move(Err);
5640 
5641  ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
5642  if (!ToLBracLocOrErr)
5643  return ToLBracLocOrErr.takeError();
5644 
5645  ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
5646  if (!ToRBracLocOrErr)
5647  return ToRBracLocOrErr.takeError();
5648 
5649  return CompoundStmt::Create(
5650  Importer.getToContext(), ToStmts,
5651  *ToLBracLocOrErr, *ToRBracLocOrErr);
5652 }
5653 
5655  auto Imp = importSeq(
5656  S->getLHS(), S->getRHS(), S->getSubStmt(), S->getCaseLoc(),
5657  S->getEllipsisLoc(), S->getColonLoc());
5658  if (!Imp)
5659  return Imp.takeError();
5660 
5661  Expr *ToLHS, *ToRHS;
5662  Stmt *ToSubStmt;
5663  SourceLocation ToCaseLoc, ToEllipsisLoc, ToColonLoc;
5664  std::tie(ToLHS, ToRHS, ToSubStmt, ToCaseLoc, ToEllipsisLoc, ToColonLoc) =
5665  *Imp;
5666 
5667  auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
5668  ToCaseLoc, ToEllipsisLoc, ToColonLoc);
5669  ToStmt->setSubStmt(ToSubStmt);
5670 
5671  return ToStmt;
5672 }
5673 
5675  auto Imp = importSeq(S->getDefaultLoc(), S->getColonLoc(), S->getSubStmt());
5676  if (!Imp)
5677  return Imp.takeError();
5678 
5679  SourceLocation ToDefaultLoc, ToColonLoc;
5680  Stmt *ToSubStmt;
5681  std::tie(ToDefaultLoc, ToColonLoc, ToSubStmt) = *Imp;
5682 
5683  return new (Importer.getToContext()) DefaultStmt(
5684  ToDefaultLoc, ToColonLoc, ToSubStmt);
5685 }
5686 
5688  auto Imp = importSeq(S->getIdentLoc(), S->getDecl(), S->getSubStmt());
5689  if (!Imp)
5690  return Imp.takeError();
5691 
5692  SourceLocation ToIdentLoc;
5693  LabelDecl *ToLabelDecl;
5694  Stmt *ToSubStmt;
5695  std::tie(ToIdentLoc, ToLabelDecl, ToSubStmt) = *Imp;
5696 
5697  return new (Importer.getToContext()) LabelStmt(
5698  ToIdentLoc, ToLabelDecl, ToSubStmt);
5699 }
5700 
5702  ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
5703  if (!ToAttrLocOrErr)
5704  return ToAttrLocOrErr.takeError();
5705  ArrayRef<const Attr*> FromAttrs(S->getAttrs());
5706  SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
5707  if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
5708  return std::move(Err);
5709  ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
5710  if (!ToSubStmtOrErr)
5711  return ToSubStmtOrErr.takeError();
5712 
5713  return AttributedStmt::Create(
5714  Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
5715 }
5716 
5718  auto Imp = importSeq(
5719  S->getIfLoc(), S->getInit(), S->getConditionVariable(), S->getCond(),
5720  S->getThen(), S->getElseLoc(), S->getElse());
5721  if (!Imp)
5722  return Imp.takeError();
5723 
5724  SourceLocation ToIfLoc, ToElseLoc;
5725  Stmt *ToInit, *ToThen, *ToElse;
5726  VarDecl *ToConditionVariable;
5727  Expr *ToCond;
5728  std::tie(
5729  ToIfLoc, ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, ToElse) =
5730  *Imp;
5731 
5732  return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(),
5733  ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc,
5734  ToElse);
5735 }
5736 
5738  auto Imp = importSeq(
5739  S->getInit(), S->getConditionVariable(), S->getCond(),
5740  S->getBody(), S->getSwitchLoc());
5741  if (!Imp)
5742  return Imp.takeError();
5743 
5744  Stmt *ToInit, *ToBody;
5745  VarDecl *ToConditionVariable;
5746  Expr *ToCond;
5747  SourceLocation ToSwitchLoc;
5748  std::tie(ToInit, ToConditionVariable, ToCond, ToBody, ToSwitchLoc) = *Imp;
5749 
5750  auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit,
5751  ToConditionVariable, ToCond);
5752  ToStmt->setBody(ToBody);
5753  ToStmt->setSwitchLoc(ToSwitchLoc);
5754 
5755  // Now we have to re-chain the cases.
5756  SwitchCase *LastChainedSwitchCase = nullptr;
5757  for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
5758  SC = SC->getNextSwitchCase()) {
5759  Expected<SwitchCase *> ToSCOrErr = import(SC);
5760  if (!ToSCOrErr)
5761  return ToSCOrErr.takeError();
5762  if (LastChainedSwitchCase)
5763  LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
5764  else
5765  ToStmt->setSwitchCaseList(*ToSCOrErr);
5766  LastChainedSwitchCase = *ToSCOrErr;
5767  }
5768 
5769  return ToStmt;
5770 }
5771 
5773  auto Imp = importSeq(
5774  S->getConditionVariable(), S->getCond(), S->getBody(), S->getWhileLoc());
5775  if (!Imp)
5776  return Imp.takeError();
5777 
5778  VarDecl *ToConditionVariable;
5779  Expr *ToCond;
5780  Stmt *ToBody;
5781  SourceLocation ToWhileLoc;
5782  std::tie(ToConditionVariable, ToCond, ToBody, ToWhileLoc) = *Imp;
5783 
5784  return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
5785  ToBody, ToWhileLoc);
5786 }
5787 
5789  auto Imp = importSeq(
5790  S->getBody(), S->getCond(), S->getDoLoc(), S->getWhileLoc(),
5791  S->getRParenLoc());
5792  if (!Imp)
5793  return Imp.takeError();
5794 
5795  Stmt *ToBody;
5796  Expr *ToCond;
5797  SourceLocation ToDoLoc, ToWhileLoc, ToRParenLoc;
5798  std::tie(ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc) = *Imp;
5799 
5800  return new (Importer.getToContext()) DoStmt(
5801  ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
5802 }
5803 
5805  auto Imp = importSeq(
5806  S->getInit(), S->getCond(), S->getConditionVariable(), S->getInc(),
5807  S->getBody(), S->getForLoc(), S->getLParenLoc(), S->getRParenLoc());
5808  if (!Imp)
5809  return Imp.takeError();
5810 
5811  Stmt *ToInit;
5812  Expr *ToCond, *ToInc;
5813  VarDecl *ToConditionVariable;
5814  Stmt *ToBody;
5815  SourceLocation ToForLoc, ToLParenLoc, ToRParenLoc;
5816  std::tie(
5817  ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc,
5818  ToLParenLoc, ToRParenLoc) = *Imp;
5819 
5820  return new (Importer.getToContext()) ForStmt(
5821  Importer.getToContext(),
5822  ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
5823  ToRParenLoc);
5824 }
5825 
5827  auto Imp = importSeq(S->getLabel(), S->getGotoLoc(), S->getLabelLoc());
5828  if (!Imp)
5829  return Imp.takeError();
5830 
5831  LabelDecl *ToLabel;
5832  SourceLocation ToGotoLoc, ToLabelLoc;
5833  std::tie(ToLabel, ToGotoLoc, ToLabelLoc) = *Imp;
5834 
5835  return new (Importer.getToContext()) GotoStmt(
5836  ToLabel, ToGotoLoc, ToLabelLoc);
5837 }
5838 
5840  auto Imp = importSeq(S->getGotoLoc(), S->getStarLoc(), S->getTarget());
5841  if (!Imp)
5842  return Imp.takeError();
5843 
5844  SourceLocation ToGotoLoc, ToStarLoc;
5845  Expr *ToTarget;
5846  std::tie(ToGotoLoc, ToStarLoc, ToTarget) = *Imp;
5847 
5848  return new (Importer.getToContext()) IndirectGotoStmt(
5849  ToGotoLoc, ToStarLoc, ToTarget);
5850 }
5851 
5853  ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc());
5854  if (!ToContinueLocOrErr)
5855  return ToContinueLocOrErr.takeError();
5856  return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr);
5857 }
5858 
5860  auto ToBreakLocOrErr = import(S->getBreakLoc());
5861  if (!ToBreakLocOrErr)
5862  return ToBreakLocOrErr.takeError();
5863  return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr);
5864 }
5865 
5867  auto Imp = importSeq(
5868  S->getReturnLoc(), S->getRetValue(), S->getNRVOCandidate());
5869  if (!Imp)
5870  return Imp.takeError();
5871 
5872  SourceLocation ToReturnLoc;
5873  Expr *ToRetValue;
5874  const VarDecl *ToNRVOCandidate;
5875  std::tie(ToReturnLoc, ToRetValue, ToNRVOCandidate) = *Imp;
5876 
5877  return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
5878  ToNRVOCandidate);
5879 }
5880 
5882  auto Imp = importSeq(
5883  S->getCatchLoc(), S->getExceptionDecl(), S->getHandlerBlock());
5884  if (!Imp)
5885  return Imp.takeError();
5886 
5887  SourceLocation ToCatchLoc;
5888  VarDecl *ToExceptionDecl;
5889  Stmt *ToHandlerBlock;
5890  std::tie(ToCatchLoc, ToExceptionDecl, ToHandlerBlock) = *Imp;
5891 
5892  return new (Importer.getToContext()) CXXCatchStmt (
5893  ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
5894 }
5895 
5897  ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
5898  if (!ToTryLocOrErr)
5899  return ToTryLocOrErr.takeError();
5900 
5901  ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
5902  if (!ToTryBlockOrErr)
5903  return ToTryBlockOrErr.takeError();
5904 
5905  SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
5906  for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
5907  CXXCatchStmt *FromHandler = S->getHandler(HI);
5908  if (auto ToHandlerOrErr = import(FromHandler))
5909  ToHandlers[HI] = *ToHandlerOrErr;
5910  else
5911  return ToHandlerOrErr.takeError();
5912  }
5913 
5914  return CXXTryStmt::Create(
5915  Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers);
5916 }
5917 
5919  auto Imp1 = importSeq(
5920  S->getInit(), S->getRangeStmt(), S->getBeginStmt(), S->getEndStmt(),
5921  S->getCond(), S->getInc(), S->getLoopVarStmt(), S->getBody());
5922  if (!Imp1)
5923  return Imp1.takeError();
5924  auto Imp2 = importSeq(
5925  S->getForLoc(), S->getCoawaitLoc(), S->getColonLoc(), S->getRParenLoc());
5926  if (!Imp2)
5927  return Imp2.takeError();
5928 
5929  DeclStmt *ToRangeStmt, *ToBeginStmt, *ToEndStmt, *ToLoopVarStmt;
5930  Expr *ToCond, *ToInc;
5931  Stmt *ToInit, *ToBody;
5932  std::tie(
5933  ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
5934  ToBody) = *Imp1;
5935  SourceLocation ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc;
5936  std::tie(ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc) = *Imp2;
5937 
5938  return new (Importer.getToContext()) CXXForRangeStmt(
5939  ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
5940  ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
5941 }
5942 
5945  auto Imp = importSeq(
5946  S->getElement(), S->getCollection(), S->getBody(),
5947  S->getForLoc(), S->getRParenLoc());
5948  if (!Imp)
5949  return Imp.takeError();
5950 
5951  Stmt *ToElement, *ToBody;
5952  Expr *ToCollection;
5953  SourceLocation ToForLoc, ToRParenLoc;
5954  std::tie(ToElement, ToCollection, ToBody, ToForLoc, ToRParenLoc) = *Imp;
5955 
5956  return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
5957  ToCollection,
5958  ToBody,
5959  ToForLoc,
5960  ToRParenLoc);
5961 }
5962 
5964  auto Imp = importSeq(
5965  S->getAtCatchLoc(), S->getRParenLoc(), S->getCatchParamDecl(),
5966  S->getCatchBody());
5967  if (!Imp)
5968  return Imp.takeError();
5969 
5970  SourceLocation ToAtCatchLoc, ToRParenLoc;
5971  VarDecl *ToCatchParamDecl;
5972  Stmt *ToCatchBody;
5973  std::tie(ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody) = *Imp;
5974 
5975  return new (Importer.getToContext()) ObjCAtCatchStmt (
5976  ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
5977 }
5978 
5980  ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
5981  if (!ToAtFinallyLocOrErr)
5982  return ToAtFinallyLocOrErr.takeError();
5983  ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
5984  if (!ToAtFinallyStmtOrErr)
5985  return ToAtFinallyStmtOrErr.takeError();
5986  return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
5987  *ToAtFinallyStmtOrErr);
5988 }
5989 
5991  auto Imp = importSeq(
5992  S->getAtTryLoc(), S->getTryBody(), S->getFinallyStmt());
5993  if (!Imp)
5994  return Imp.takeError();
5995 
5996  SourceLocation ToAtTryLoc;
5997  Stmt *ToTryBody, *ToFinallyStmt;
5998  std::tie(ToAtTryLoc, ToTryBody, ToFinallyStmt) = *Imp;
5999 
6000  SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
6001  for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
6002  ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
6003  if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
6004  ToCatchStmts[CI] = *ToCatchStmtOrErr;
6005  else
6006  return ToCatchStmtOrErr.takeError();
6007  }
6008 
6009  return ObjCAtTryStmt::Create(Importer.getToContext(),
6010  ToAtTryLoc, ToTryBody,
6011  ToCatchStmts.begin(), ToCatchStmts.size(),
6012  ToFinallyStmt);
6013 }
6014 
6017  auto Imp = importSeq(
6019  if (!Imp)
6020  return Imp.takeError();
6021 
6022  SourceLocation ToAtSynchronizedLoc;
6023  Expr *ToSynchExpr;
6024  Stmt *ToSynchBody;
6025  std::tie(ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody) = *Imp;
6026 
6027  return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
6028  ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
6029 }
6030 
6032  ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
6033  if (!ToThrowLocOrErr)
6034  return ToThrowLocOrErr.takeError();
6035  ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
6036  if (!ToThrowExprOrErr)
6037  return ToThrowExprOrErr.takeError();
6038  return new (Importer.getToContext()) ObjCAtThrowStmt(
6039  *ToThrowLocOrErr, *ToThrowExprOrErr);
6040 }
6041 
6044  ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
6045  if (!ToAtLocOrErr)
6046  return ToAtLocOrErr.takeError();
6047  ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
6048  if (!ToSubStmtOrErr)
6049  return ToSubStmtOrErr.takeError();
6050  return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
6051  *ToSubStmtOrErr);
6052 }
6053 
6054 //----------------------------------------------------------------------------
6055 // Import Expressions
6056 //----------------------------------------------------------------------------
6058  Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
6059  << E->getStmtClassName();
6060  return make_error<ImportError>(ImportError::UnsupportedConstruct);
6061 }
6062 
6064  auto Imp = importSeq(
6065  E->getBuiltinLoc(), E->getSubExpr(), E->getWrittenTypeInfo(),
6066  E->getRParenLoc(), E->getType());
6067  if (!Imp)
6068  return Imp.takeError();
6069 
6070  SourceLocation ToBuiltinLoc, ToRParenLoc;
6071  Expr *ToSubExpr;
6072  TypeSourceInfo *ToWrittenTypeInfo;
6073  QualType ToType;
6074  std::tie(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType) =
6075  *Imp;
6076 
6077  return new (Importer.getToContext()) VAArgExpr(
6078  ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
6079  E->isMicrosoftABI());
6080 }
6081 
6082 
6084  ExpectedType TypeOrErr = import(E->getType());
6085  if (!TypeOrErr)
6086  return TypeOrErr.takeError();
6087 
6088  ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
6089  if (!BeginLocOrErr)
6090  return BeginLocOrErr.takeError();
6091 
6092  return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
6093 }
6094 
6096  auto Imp = importSeq(
6097  E->getBeginLoc(), E->getType(), E->getFunctionName());
6098  if (!Imp)
6099  return Imp.takeError();
6100 
6101  SourceLocation ToBeginLoc;
6102  QualType ToType;
6103  StringLiteral *ToFunctionName;
6104  std::tie(ToBeginLoc, ToType, ToFunctionName) = *Imp;
6105 
6106  return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
6107  E->getIdentKind(), ToFunctionName);
6108 }
6109 
6111  auto Imp = importSeq(
6113  E->getLocation(), E->getType());
6114  if (!Imp)
6115  return Imp.takeError();
6116 
6117  NestedNameSpecifierLoc ToQualifierLoc;
6118  SourceLocation ToTemplateKeywordLoc, ToLocation;
6119  ValueDecl *ToDecl;
6120  QualType ToType;
6121  std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, ToLocation, ToType) =
6122  *Imp;
6123 
6124  NamedDecl *ToFoundD = nullptr;
6125  if (E->getDecl() != E->getFoundDecl()) {
6126  auto FoundDOrErr = import(E->getFoundDecl());
6127  if (!FoundDOrErr)
6128  return FoundDOrErr.takeError();
6129  ToFoundD = *FoundDOrErr;
6130  }
6131 
6132  TemplateArgumentListInfo ToTAInfo;
6133  TemplateArgumentListInfo *ToResInfo = nullptr;
6134  if (E->hasExplicitTemplateArgs()) {
6135  if (Error Err =
6136  ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo))
6137  return std::move(Err);
6138  ToResInfo = &ToTAInfo;
6139  }
6140 
6141  auto *ToE = DeclRefExpr::Create(
6142  Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
6143  E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
6144  E->getValueKind(), ToFoundD, ToResInfo);
6145  if (E->hadMultipleCandidates())
6146  ToE->setHadMultipleCandidates(true);
6147  return ToE;
6148 }
6149 
6151  ExpectedType TypeOrErr = import(E->getType());
6152  if (!TypeOrErr)
6153  return TypeOrErr.takeError();
6154 
6155  return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
6156 }
6157 
6159  ExpectedExpr ToInitOrErr = import(E->getInit());
6160  if (!ToInitOrErr)
6161  return ToInitOrErr.takeError();
6162 
6163  ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
6164  if (!ToEqualOrColonLocOrErr)
6165  return ToEqualOrColonLocOrErr.takeError();
6166 
6167  SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
6168  // List elements from the second, the first is Init itself
6169  for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
6170  if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
6171  ToIndexExprs[I - 1] = *ToArgOrErr;
6172  else
6173  return ToArgOrErr.takeError();
6174  }
6175 
6176  SmallVector<Designator, 4> ToDesignators(E->size());
6177  if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
6178  return std::move(Err);
6179 
6181  Importer.getToContext(), ToDesignators,
6182  ToIndexExprs, *ToEqualOrColonLocOrErr,
6183  E->usesGNUSyntax(), *ToInitOrErr);
6184 }
6185 
6188  ExpectedType ToTypeOrErr = import(E->getType());
6189  if (!ToTypeOrErr)
6190  return ToTypeOrErr.takeError();
6191 
6192  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
6193  if (!ToLocationOrErr)
6194  return ToLocationOrErr.takeError();
6195 
6196  return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
6197  *ToTypeOrErr, *ToLocationOrErr);
6198 }
6199 
6201  ExpectedType ToTypeOrErr = import(E->getType());
6202  if (!ToTypeOrErr)
6203  return ToTypeOrErr.takeError();
6204 
6205  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
6206  if (!ToLocationOrErr)
6207  return ToLocationOrErr.takeError();
6208 
6209  return IntegerLiteral::Create(
6210  Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
6211 }
6212 
6213 
6215  ExpectedType ToTypeOrErr = import(E->getType());
6216  if (!ToTypeOrErr)
6217  return ToTypeOrErr.takeError();
6218 
6219  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
6220  if (!ToLocationOrErr)
6221  return ToLocationOrErr.takeError();
6222 
6223  return FloatingLiteral::Create(
6224  Importer.getToContext(), E->getValue(), E->isExact(),
6225  *ToTypeOrErr, *ToLocationOrErr);
6226 }
6227 
6229  auto ToTypeOrErr = import(E->getType());
6230  if (!ToTypeOrErr)
6231  return ToTypeOrErr.takeError();
6232 
6233  ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
6234  if (!ToSubExprOrErr)
6235  return ToSubExprOrErr.takeError();
6236 
6237  return new (Importer.getToContext()) ImaginaryLiteral(
6238  *ToSubExprOrErr, *ToTypeOrErr);
6239 }
6240 
6242  ExpectedType ToTypeOrErr = import(E->getType());
6243  if (!ToTypeOrErr)
6244  return ToTypeOrErr.takeError();
6245 
6246  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
6247  if (!ToLocationOrErr)
6248  return ToLocationOrErr.takeError();
6249 
6250  return new (Importer.getToContext()) CharacterLiteral(
6251  E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
6252 }
6253 
6255  ExpectedType ToTypeOrErr = import(E->getType());
6256  if (!ToTypeOrErr)
6257  return ToTypeOrErr.takeError();
6258 
6260  if (Error Err = ImportArrayChecked(
6261  E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
6262  return std::move(Err);
6263 
6264  return StringLiteral::Create(
6265  Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(),
6266  *ToTypeOrErr, ToLocations.data(), ToLocations.size());
6267 }
6268 
6270  auto Imp = importSeq(
6271  E->getLParenLoc(), E->getTypeSourceInfo(), E->getType(),
6272  E->getInitializer());
6273  if (!Imp)
6274  return Imp.takeError();
6275 
6276  SourceLocation ToLParenLoc;
6277  TypeSourceInfo *ToTypeSourceInfo;
6278  QualType ToType;
6279  Expr *ToInitializer;
6280  std::tie(ToLParenLoc, ToTypeSourceInfo, ToType, ToInitializer) = *Imp;
6281 
6282  return new (Importer.getToContext()) CompoundLiteralExpr(
6283  ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
6284  ToInitializer, E->isFileScope());
6285 }
6286 
6288  auto Imp = importSeq(
6289  E->getBuiltinLoc(), E->getType(), E->getRParenLoc());
6290  if (!Imp)
6291  return Imp.takeError();
6292 
6293  SourceLocation ToBuiltinLoc, ToRParenLoc;
6294  QualType ToType;
6295  std::tie(ToBuiltinLoc, ToType, ToRParenLoc) = *Imp;
6296 
6297  SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs());
6298  if (Error Err = ImportArrayChecked(
6299  E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
6300  ToExprs.begin()))
6301  return std::move(Err);
6302 
6303  return new (Importer.getToContext()) AtomicExpr(
6304  ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
6305 }
6306 
6308  auto Imp = importSeq(
6309  E->getAmpAmpLoc(), E->getLabelLoc(), E->getLabel(), E->getType());
6310  if (!Imp)
6311  return Imp.takeError();
6312 
6313  SourceLocation ToAmpAmpLoc, ToLabelLoc;
6314  LabelDecl *ToLabel;
6315  QualType ToType;
6316  std::tie(ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType) = *Imp;
6317 
6318  return new (Importer.getToContext()) AddrLabelExpr(
6319  ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
6320 }
6321 
6323  auto Imp = importSeq(E->getSubExpr());
6324  if (!Imp)
6325  return Imp.takeError();
6326 
6327  Expr *ToSubExpr;
6328  std::tie(ToSubExpr) = *Imp;
6329 
6330  return ConstantExpr::Create(Importer.getToContext(), ToSubExpr);
6331 }
6332 
6334  auto Imp = importSeq(E->getLParen(), E->getRParen(), E->getSubExpr());
6335  if (!Imp)
6336  return Imp.takeError();
6337 
6338  SourceLocation ToLParen, ToRParen;
6339  Expr *ToSubExpr;
6340  std::tie(ToLParen, ToRParen, ToSubExpr) = *Imp;
6341 
6342  return new (Importer.getToContext())
6343  ParenExpr(ToLParen, ToRParen, ToSubExpr);
6344 }
6345 
6347  SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
6348  if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
6349  return std::move(Err);
6350 
6351  ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
6352  if (!ToLParenLocOrErr)
6353  return ToLParenLocOrErr.takeError();
6354 
6355  ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
6356  if (!ToRParenLocOrErr)
6357  return ToRParenLocOrErr.takeError();
6358 
6359  return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
6360  ToExprs, *ToRParenLocOrErr);
6361 }
6362 
6364  auto Imp = importSeq(
6365  E->getSubStmt(), E->getType(), E->getLParenLoc(), E->getRParenLoc());
6366  if (!Imp)
6367  return Imp.takeError();
6368 
6369  CompoundStmt *ToSubStmt;
6370  QualType ToType;
6371  SourceLocation ToLParenLoc, ToRParenLoc;
6372  std::tie(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc) = *Imp;
6373 
6374  return new (Importer.getToContext()) StmtExpr(
6375  ToSubStmt, ToType, ToLParenLoc, ToRParenLoc);
6376 }
6377 
6379  auto Imp = importSeq(
6380  E->getSubExpr(), E->getType(), E->getOperatorLoc());
6381  if (!Imp)
6382  return Imp.takeError();
6383 
6384  Expr *ToSubExpr;
6385  QualType ToType;
6386  SourceLocation ToOperatorLoc;
6387  std::tie(ToSubExpr, ToType, ToOperatorLoc) = *Imp;
6388 
6389  return new (Importer.getToContext()) UnaryOperator(
6390  ToSubExpr, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(),
6391  ToOperatorLoc, E->canOverflow());
6392 }
6393 
6396  auto Imp = importSeq(E->getType(), E->getOperatorLoc(), E->getRParenLoc());
6397  if (!Imp)
6398  return Imp.takeError();
6399 
6400  QualType ToType;
6401  SourceLocation ToOperatorLoc, ToRParenLoc;
6402  std::tie(ToType, ToOperatorLoc, ToRParenLoc) = *Imp;
6403 
6404  if (E->isArgumentType()) {
6405  Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
6406  import(E->getArgumentTypeInfo());
6407  if (!ToArgumentTypeInfoOrErr)
6408  return ToArgumentTypeInfoOrErr.takeError();
6409 
6410  return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
6411  E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
6412  ToRParenLoc);
6413  }
6414 
6415  ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
6416  if (!ToArgumentExprOrErr)
6417  return ToArgumentExprOrErr.takeError();
6418 
6419  return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
6420  E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
6421 }
6422 
6424  auto Imp = importSeq(
6425  E->getLHS(), E->getRHS(), E->getType(), E->getOperatorLoc());
6426  if (!Imp)
6427  return Imp.takeError();
6428 
6429  Expr *ToLHS, *ToRHS;
6430  QualType ToType;
6431  SourceLocation ToOperatorLoc;
6432  std::tie(ToLHS, ToRHS, ToType, ToOperatorLoc) = *Imp;
6433 
6434  return new (Importer.getToContext()) BinaryOperator(
6435  ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(),
6436  E->getObjectKind(), ToOperatorLoc, E->getFPFeatures());
6437 }
6438 
6440  auto Imp = importSeq(
6441  E->getCond(), E->getQuestionLoc(), E->getLHS(), E->getColonLoc(),
6442  E->getRHS(), E->getType());
6443  if (!Imp)
6444  return Imp.takeError();
6445 
6446  Expr *ToCond, *ToLHS, *ToRHS;
6447  SourceLocation ToQuestionLoc, ToColonLoc;
6448  QualType ToType;
6449  std::tie(ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType) = *Imp;
6450 
6451  return new (Importer.getToContext()) ConditionalOperator(
6452  ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
6453  E->getValueKind(), E->getObjectKind());
6454 }
6455 
6458  auto Imp = importSeq(
6459  E->getCommon(), E->getOpaqueValue(), E->getCond(), E->getTrueExpr(),
6460  E->getFalseExpr(), E->getQuestionLoc(), E->getColonLoc(), E->getType());
6461  if (!Imp)
6462  return Imp.takeError();
6463 
6464  Expr *ToCommon, *ToCond, *ToTrueExpr, *ToFalseExpr;
6465  OpaqueValueExpr *ToOpaqueValue;
6466  SourceLocation ToQuestionLoc, ToColonLoc;
6467  QualType ToType;
6468  std::tie(
6469  ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, ToQuestionLoc,
6470  ToColonLoc, ToType) = *Imp;
6471 
6472  return new (Importer.getToContext()) BinaryConditionalOperator(
6473  ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
6474  ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
6475  E->getObjectKind());
6476 }
6477 
6479  auto Imp = importSeq(
6481  E->getDimensionExpression(), E->getEndLoc(), E->getType());
6482  if (!Imp)
6483  return Imp.takeError();
6484 
6485  SourceLocation ToBeginLoc, ToEndLoc;
6486  TypeSourceInfo *ToQueriedTypeSourceInfo;
6487  Expr *ToDimensionExpression;
6488  QualType ToType;
6489  std::tie(
6490  ToBeginLoc, ToQueriedTypeSourceInfo, ToDimensionExpression, ToEndLoc,
6491  ToType) = *Imp;
6492 
6493  return new (Importer.getToContext()) ArrayTypeTraitExpr(
6494  ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
6495  ToDimensionExpression, ToEndLoc, ToType);
6496 }
6497 
6499  auto Imp = importSeq(
6500  E->getBeginLoc(), E->getQueriedExpression(), E->getEndLoc(), E->getType());
6501  if (!Imp)
6502  return Imp.takeError();
6503 
6504  SourceLocation ToBeginLoc, ToEndLoc;
6505  Expr *ToQueriedExpression;
6506  QualType ToType;
6507  std::tie(ToBeginLoc, ToQueriedExpression, ToEndLoc, ToType) = *Imp;
6508 
6509  return new (Importer.getToContext()) ExpressionTraitExpr(
6510  ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
6511  ToEndLoc, ToType);
6512 }
6513 
6515  auto Imp = importSeq(
6516  E->getLocation(), E->getType(), E->getSourceExpr());
6517  if (!Imp)
6518  return Imp.takeError();
6519 
6520  SourceLocation ToLocation;
6521  QualType ToType;
6522  Expr *ToSourceExpr;
6523  std::tie(ToLocation, ToType, ToSourceExpr) = *Imp;
6524 
6525  return new (Importer.getToContext()) OpaqueValueExpr(
6526  ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
6527 }
6528 
6530  auto Imp = importSeq(
6531  E->getLHS(), E->getRHS(), E->getType(), E->getRBracketLoc());
6532  if (!Imp)
6533  return Imp.takeError();
6534 
6535  Expr *ToLHS, *ToRHS;
6536  SourceLocation ToRBracketLoc;
6537  QualType ToType;
6538  std::tie(ToLHS, ToRHS, ToType, ToRBracketLoc) = *Imp;
6539 
6540  return new (Importer.getToContext()) ArraySubscriptExpr(
6541  ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
6542  ToRBracketLoc);
6543 }
6544 
6547  auto Imp = importSeq(
6548  E->getLHS(), E->getRHS(), E->getType(), E->getComputationLHSType(),
6550  if (!Imp)
6551  return Imp.takeError();
6552 
6553  Expr *ToLHS, *ToRHS;
6554  QualType ToType, ToComputationLHSType, ToComputationResultType;
6555  SourceLocation ToOperatorLoc;
6556  std::tie(ToLHS, ToRHS, ToType, ToComputationLHSType, ToComputationResultType,
6557  ToOperatorLoc) = *Imp;
6558 
6559  return new (Importer.getToContext()) CompoundAssignOperator(
6560  ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(),
6561  E->getObjectKind(), ToComputationLHSType, ToComputationResultType,
6562  ToOperatorLoc, E->getFPFeatures());
6563 }
6564 
6567  CXXCastPath Path;
6568  for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
6569  if (auto SpecOrErr = import(*I))
6570  Path.push_back(*SpecOrErr);
6571  else
6572  return SpecOrErr.takeError();
6573  }
6574  return Path;
6575 }
6576 
6578  ExpectedType ToTypeOrErr = import(E->getType());
6579  if (!ToTypeOrErr)
6580  return ToTypeOrErr.takeError();
6581 
6582  ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
6583  if (!ToSubExprOrErr)
6584  return ToSubExprOrErr.takeError();
6585 
6586  Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
6587  if (!ToBasePathOrErr)
6588  return ToBasePathOrErr.takeError();
6589 
6590  return ImplicitCastExpr::Create(
6591  Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
6592  &(*ToBasePathOrErr), E->getValueKind());
6593 }
6594 
6596  auto Imp1 = importSeq(
6597  E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten());
6598  if (!Imp1)
6599  return Imp1.takeError();
6600 
6601  QualType ToType;
6602  Expr *ToSubExpr;
6603  TypeSourceInfo *ToTypeInfoAsWritten;
6604  std::tie(ToType, ToSubExpr, ToTypeInfoAsWritten) = *Imp1;
6605 
6606  Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
6607  if (!ToBasePathOrErr)
6608  return ToBasePathOrErr.takeError();
6609  CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
6610 
6611  switch (E->getStmtClass()) {
6612  case Stmt::CStyleCastExprClass: {
6613  auto *CCE = cast<CStyleCastExpr>(E);
6614  ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
6615  if (!ToLParenLocOrErr)
6616  return ToLParenLocOrErr.takeError();
6617  ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
6618  if (!ToRParenLocOrErr)
6619  return ToRParenLocOrErr.takeError();
6620  return CStyleCastExpr::Create(
6621  Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
6622  ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr,
6623  *ToRParenLocOrErr);
6624  }
6625 
6626  case Stmt::CXXFunctionalCastExprClass: {
6627  auto *FCE = cast<CXXFunctionalCastExpr>(E);
6628  ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
6629  if (!ToLParenLocOrErr)
6630  return ToLParenLocOrErr.takeError();
6631  ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
6632  if (!ToRParenLocOrErr)
6633  return ToRParenLocOrErr.takeError();
6635  Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
6636  E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr,
6637  *ToRParenLocOrErr);
6638  }
6639 
6640  case Stmt::ObjCBridgedCastExprClass: {
6641  auto *OCE = cast<ObjCBridgedCastExpr>(E);
6642  ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
6643  if (!ToLParenLocOrErr)
6644  return ToLParenLocOrErr.takeError();
6645  ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
6646  if (!ToBridgeKeywordLocOrErr)
6647  return ToBridgeKeywordLocOrErr.takeError();
6648  return new (Importer.getToContext()) ObjCBridgedCastExpr(
6649  *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
6650  *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
6651  }
6652  default:
6653  llvm_unreachable("Cast expression of unsupported type!");
6654  return make_error<ImportError>(ImportError::UnsupportedConstruct);
6655  }
6656 }
6657 
6660  for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
6661  const OffsetOfNode &FromNode = E->getComponent(I);
6662 
6663  SourceLocation ToBeginLoc, ToEndLoc;
6664  if (FromNode.getKind() != OffsetOfNode::Base) {
6665  auto Imp = importSeq(FromNode.getBeginLoc(), FromNode.getEndLoc());
6666  if (!Imp)
6667  return Imp.takeError();
6668  std::tie(ToBeginLoc, ToEndLoc) = *Imp;
6669  }
6670 
6671  switch (FromNode.getKind()) {
6672  case OffsetOfNode::Array:
6673  ToNodes.push_back(
6674  OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
6675  break;
6676  case OffsetOfNode::Base: {
6677  auto ToBSOrErr = import(FromNode.getBase());
6678  if (!ToBSOrErr)
6679  return ToBSOrErr.takeError();
6680  ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
6681  break;
6682  }
6683  case OffsetOfNode::Field: {
6684  auto ToFieldOrErr = import(FromNode.getField());
6685  if (!ToFieldOrErr)
6686  return ToFieldOrErr.takeError();
6687  ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
6688  break;
6689  }
6690  case OffsetOfNode::Identifier: {
6691  IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
6692  ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
6693  break;
6694  }
6695  }
6696  }
6697 
6699  for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
6700  ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
6701  if (!ToIndexExprOrErr)
6702  return ToIndexExprOrErr.takeError();
6703  ToExprs[I] = *ToIndexExprOrErr;
6704  }
6705 
6706  auto Imp = importSeq(
6707  E->getType(), E->getTypeSourceInfo(), E->getOperatorLoc(),
6708  E->getRParenLoc());
6709  if (!Imp)
6710  return Imp.takeError();
6711 
6712  QualType ToType;
6713  TypeSourceInfo *ToTypeSourceInfo;
6714  SourceLocation ToOperatorLoc, ToRParenLoc;
6715  std::tie(ToType, ToTypeSourceInfo, ToOperatorLoc, ToRParenLoc) = *Imp;
6716 
6717  return OffsetOfExpr::Create(
6718  Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
6719  ToExprs, ToRParenLoc);
6720 }
6721 
6723  auto Imp = importSeq(
6724  E->getType(), E->getOperand(), E->getBeginLoc(), E->getEndLoc());
6725  if (!Imp)
6726  return Imp.takeError();
6727 
6728  QualType ToType;
6729  Expr *ToOperand;
6730  SourceLocation ToBeginLoc, ToEndLoc;
6731  std::tie(ToType, ToOperand, ToBeginLoc, ToEndLoc) = *Imp;
6732 
6733  CanThrowResult ToCanThrow;
6734  if (E->isValueDependent())
6735  ToCanThrow = CT_Dependent;
6736  else
6737  ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
6738 
6739  return new (Importer.getToContext()) CXXNoexceptExpr(
6740  ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
6741 }
6742 
6744  auto Imp = importSeq(E->getSubExpr(), E->getType(), E->getThrowLoc());
6745  if (!Imp)
6746  return Imp.takeError();
6747 
6748  Expr *ToSubExpr;
6749  QualType ToType;
6750  SourceLocation ToThrowLoc;
6751  std::tie(ToSubExpr, ToType, ToThrowLoc) = *Imp;
6752 
6753  return new (Importer.getToContext()) CXXThrowExpr(
6754  ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
6755 }
6756 
6758  ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
6759  if (!ToUsedLocOrErr)
6760  return ToUsedLocOrErr.takeError();
6761 
6762  auto ToParamOrErr = import(E->getParam());
6763  if (!ToParamOrErr)
6764  return ToParamOrErr.takeError();
6765 
6767  Importer.getToContext(), *ToUsedLocOrErr, *ToParamOrErr);
6768 }
6769 
6772  auto Imp = importSeq(
6773  E->getType(), E->getTypeSourceInfo(), E->getRParenLoc());
6774  if (!Imp)
6775  return Imp.takeError();
6776 
6777  QualType ToType;
6778  TypeSourceInfo *ToTypeSourceInfo;
6779  SourceLocation ToRParenLoc;
6780  std::tie(ToType, ToTypeSourceInfo, ToRParenLoc) = *Imp;
6781 
6782  return new (Importer.getToContext()) CXXScalarValueInitExpr(
6783  ToType, ToTypeSourceInfo, ToRParenLoc);
6784 }
6785 
6788  ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
6789  if (!ToSubExprOrErr)
6790  return ToSubExprOrErr.takeError();
6791 
6792  auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
6793  if (!ToDtorOrErr)
6794  return ToDtorOrErr.takeError();
6795 
6796  ASTContext &ToCtx = Importer.getToContext();
6797  CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
6798  return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
6799 }
6800 
6803  auto Imp = importSeq(
6804  E->getConstructor(), E->getType(), E->getTypeSourceInfo(),
6805  E->getParenOrBraceRange());
6806  if (!Imp)
6807  return Imp.takeError();
6808 
6809  CXXConstructorDecl *ToConstructor;
6810  QualType ToType;
6811  TypeSourceInfo *ToTypeSourceInfo;
6812  SourceRange ToParenOrBraceRange;
6813  std::tie(ToConstructor, ToType, ToTypeSourceInfo, ToParenOrBraceRange) = *Imp;
6814 
6815  SmallVector<Expr *, 8> ToArgs(E->getNumArgs());
6816  if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
6817  return std::move(Err);
6818 
6820  Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
6821  ToParenOrBraceRange, E->hadMultipleCandidates(),
6824 }
6825 
6828  auto Imp = importSeq(
6829  E->getType(), E->GetTemporaryExpr(), E->getExtendingDecl());
6830  if (!Imp)
6831  return Imp.takeError();
6832 
6833  QualType ToType;
6834  Expr *ToTemporaryExpr;
6835  const ValueDecl *ToExtendingDecl;
6836  std::tie(ToType, ToTemporaryExpr, ToExtendingDecl) = *Imp;
6837 
6838  auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
6839  ToType, ToTemporaryExpr, E->isBoundToLvalueReference());
6840 
6841  // FIXME: Should ManglingNumber get numbers associated with 'to' context?
6842  ToMTE->setExtendingDecl(ToExtendingDecl, E->getManglingNumber());
6843  return ToMTE;
6844 }
6845 
6847  auto Imp = importSeq(
6848  E->getType(), E->getPattern(), E->getEllipsisLoc());
6849  if (!Imp)
6850  return Imp.takeError();
6851 
6852  QualType ToType;
6853  Expr *ToPattern;
6854  SourceLocation ToEllipsisLoc;
6855  std::tie(ToType, ToPattern, ToEllipsisLoc) = *Imp;
6856 
6857  return new (Importer.getToContext()) PackExpansionExpr(
6858  ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions());
6859 }
6860 
6862  auto Imp = importSeq(
6863  E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc());
6864  if (!Imp)
6865  return Imp.takeError();
6866 
6867  SourceLocation ToOperatorLoc, ToPackLoc, ToRParenLoc;
6868  NamedDecl *ToPack;
6869  std::tie(ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc) = *Imp;
6870 
6871  Optional<unsigned> Length;
6872  if (!E->isValueDependent())
6873  Length = E->getPackLength();
6874 
6875  SmallVector<TemplateArgument, 8> ToPartialArguments;
6876  if (E->isPartiallySubstituted()) {
6877  if (Error Err = ImportTemplateArguments(
6878  E->getPartialArguments().data(),
6879  E->getPartialArguments().size(),
6880  ToPartialArguments))
6881  return std::move(Err);
6882  }
6883 
6884  return SizeOfPackExpr::Create(
6885  Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
6886  Length, ToPartialArguments);
6887 }
6888 
6889 
6891  auto Imp = importSeq(
6893  E->getArraySize(), E->getInitializer(), E->getType(),
6895  E->getDirectInitRange());
6896  if (!Imp)
6897  return Imp.takeError();
6898 
6899  FunctionDecl *ToOperatorNew, *ToOperatorDelete;
6900  SourceRange ToTypeIdParens, ToSourceRange, ToDirectInitRange;
6901  Expr *ToArraySize, *ToInitializer;
6902  QualType ToType;
6903  TypeSourceInfo *ToAllocatedTypeSourceInfo;
6904  std::tie(
6905  ToOperatorNew, ToOperatorDelete, ToTypeIdParens, ToArraySize, ToInitializer,
6906  ToType, ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange) = *Imp;
6907 
6908  SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
6909  if (Error Err =
6910  ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
6911  return std::move(Err);
6912 
6913  return CXXNewExpr::Create(
6914  Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
6915  ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(),
6916  ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(),
6917  ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange,
6918  ToDirectInitRange);
6919 }
6920 
6922  auto Imp = importSeq(
6923  E->getType(), E->getOperatorDelete(), E->getArgument(), E->getBeginLoc());
6924  if (!Imp)
6925  return Imp.takeError();
6926 
6927  QualType ToType;
6928  FunctionDecl *ToOperatorDelete;
6929  Expr *ToArgument;
6930  SourceLocation ToBeginLoc;
6931  std::tie(ToType, ToOperatorDelete, ToArgument, ToBeginLoc) = *Imp;
6932 
6933  return new (Importer.getToContext()) CXXDeleteExpr(
6934  ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
6935  E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
6936  ToBeginLoc);
6937 }
6938 
6940  auto Imp = importSeq(
6941  E->getType(), E->getLocation(), E->getConstructor(),
6942  E->getParenOrBraceRange());
6943  if (!Imp)
6944  return Imp.takeError();
6945 
6946  QualType ToType;
6947  SourceLocation ToLocation;
6948  CXXConstructorDecl *ToConstructor;
6949  SourceRange ToParenOrBraceRange;
6950  std::tie(ToType, ToLocation, ToConstructor, ToParenOrBraceRange) = *Imp;
6951 
6952  SmallVector<Expr *, 6> ToArgs(E->getNumArgs());
6953  if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
6954  return std::move(Err);
6955 
6956  return CXXConstructExpr::Create(
6957  Importer.getToContext(), ToType, ToLocation, ToConstructor,
6958  E->isElidable(), ToArgs, E->hadMultipleCandidates(),
6961  ToParenOrBraceRange);
6962 }
6963 
6965  ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
6966  if (!ToSubExprOrErr)
6967  return ToSubExprOrErr.takeError();
6968 
6970  if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
6971  return std::move(Err);
6972 
6973  return ExprWithCleanups::Create(
6974  Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
6975  ToObjects);
6976 }
6977 
6979  auto Imp = importSeq(
6980  E->getCallee(), E->getType(), E->getRParenLoc());
6981  if (!Imp)
6982  return Imp.takeError();
6983 
6984  Expr *ToCallee;
6985  QualType ToType;
6986  SourceLocation ToRParenLoc;
6987  std::tie(ToCallee, ToType, ToRParenLoc) = *Imp;
6988 
6989  SmallVector<Expr *, 4> ToArgs(E->getNumArgs());
6990  if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
6991  return std::move(Err);
6992 
6993  return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
6994  ToType, E->getValueKind(), ToRParenLoc);
6995 }
6996 
6998  ExpectedType ToTypeOrErr = import(E->getType());
6999  if (!ToTypeOrErr)
7000  return ToTypeOrErr.takeError();
7001 
7002  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7003  if (!ToLocationOrErr)
7004  return ToLocationOrErr.takeError();
7005 
7006  return new (Importer.getToContext()) CXXThisExpr(
7007  *ToLocationOrErr, *ToTypeOrErr, E->isImplicit());
7008 }
7009 
7011  ExpectedType ToTypeOrErr = import(E->getType());
7012  if (!ToTypeOrErr)
7013  return ToTypeOrErr.takeError();
7014 
7015  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7016  if (!ToLocationOrErr)
7017  return ToLocationOrErr.takeError();
7018 
7019  return new (Importer.getToContext()) CXXBoolLiteralExpr(
7020  E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7021 }
7022 
7024  auto Imp1 = importSeq(
7025  E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(),
7026  E->getTemplateKeywordLoc(), E->getMemberDecl(), E->getType());
7027  if (!Imp1)
7028  return Imp1.takeError();
7029 
7030  Expr *ToBase;
7031  SourceLocation ToOperatorLoc, ToTemplateKeywordLoc;
7032  NestedNameSpecifierLoc ToQualifierLoc;
7033  ValueDecl *ToMemberDecl;
7034  QualType ToType;
7035  std::tie(
7036  ToBase, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl,
7037  ToType) = *Imp1;
7038 
7039  auto Imp2 = importSeq(
7041  E->getMemberNameInfo().getLoc(), E->getLAngleLoc(), E->getRAngleLoc());
7042  if (!Imp2)
7043  return Imp2.takeError();
7044  NamedDecl *ToDecl;
7045  DeclarationName ToName;
7046  SourceLocation ToLoc, ToLAngleLoc, ToRAngleLoc;
7047  std::tie(ToDecl, ToName, ToLoc, ToLAngleLoc, ToRAngleLoc) = *Imp2;
7048 
7049  DeclAccessPair ToFoundDecl =
7051 
7052  DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
7053 
7054  if (E->hasExplicitTemplateArgs()) {
7055  // FIXME: handle template arguments
7056  return make_error<ImportError>(ImportError::UnsupportedConstruct);
7057  }
7058 
7059  return MemberExpr::Create(
7060  Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
7061  ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, ToFoundDecl,
7062  ToMemberNameInfo, nullptr, ToType, E->getValueKind(), E->getObjectKind());
7063 }
7064 
7067  auto Imp = importSeq(
7068  E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(),
7069  E->getScopeTypeInfo(), E->getColonColonLoc(), E->getTildeLoc());
7070  if (!Imp)
7071  return Imp.takeError();
7072 
7073  Expr *ToBase;
7074  SourceLocation ToOperatorLoc, ToColonColonLoc, ToTildeLoc;
7075  NestedNameSpecifierLoc ToQualifierLoc;
7076  TypeSourceInfo *ToScopeTypeInfo;
7077  std::tie(
7078  ToBase, ToOperatorLoc, ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc,
7079  ToTildeLoc) = *Imp;
7080 
7082  if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
7083  IdentifierInfo *ToII = Importer.Import(FromII);
7084  ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
7085  if (!ToDestroyedTypeLocOrErr)
7086  return ToDestroyedTypeLocOrErr.takeError();
7087  Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
7088  } else {
7089  if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
7090  Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
7091  else
7092  return ToTIOrErr.takeError();
7093  }
7094 
7095  return new (Importer.getToContext()) CXXPseudoDestructorExpr(
7096  Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
7097  ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
7098 }
7099 
7102  auto Imp = importSeq(
7103  E->getType(), E->getOperatorLoc(), E->getQualifierLoc(),
7105  if (!Imp)
7106  return Imp.takeError();
7107 
7108  QualType ToType;
7109  SourceLocation ToOperatorLoc, ToTemplateKeywordLoc;
7110  NestedNameSpecifierLoc ToQualifierLoc;
7111  NamedDecl *ToFirstQualifierFoundInScope;
7112  std::tie(
7113  ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
7114  ToFirstQualifierFoundInScope) = *Imp;
7115 
7116  Expr *ToBase = nullptr;
7117  if (!E->isImplicitAccess()) {
7118  if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
7119  ToBase = *ToBaseOrErr;
7120  else
7121  return ToBaseOrErr.takeError();
7122  }
7123 
7124  TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
7125  if (E->hasExplicitTemplateArgs()) {
7126  if (Error Err = ImportTemplateArgumentListInfo(
7127  E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(),
7128  ToTAInfo))
7129  return std::move(Err);
7130  ResInfo = &ToTAInfo;
7131  }
7132 
7133  auto ToMemberNameInfoOrErr = importSeq(E->getMember(), E->getMemberLoc());
7134  if (!ToMemberNameInfoOrErr)
7135  return ToMemberNameInfoOrErr.takeError();
7136  DeclarationNameInfo ToMemberNameInfo(
7137  std::get<0>(*ToMemberNameInfoOrErr), std::get<1>(*ToMemberNameInfoOrErr));
7138  // Import additional name location/type info.
7139  if (Error Err = ImportDeclarationNameLoc(
7140  E->getMemberNameInfo(), ToMemberNameInfo))
7141  return std::move(Err);
7142 
7144  Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
7145  ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
7146  ToMemberNameInfo, ResInfo);
7147 }
7148 
7151  auto Imp = importSeq(
7153  E->getExprLoc(), E->getLAngleLoc(), E->getRAngleLoc());
7154  if (!Imp)
7155  return Imp.takeError();
7156 
7157  NestedNameSpecifierLoc ToQualifierLoc;
7158  SourceLocation ToTemplateKeywordLoc, ToExprLoc, ToLAngleLoc, ToRAngleLoc;
7159  DeclarationName ToDeclName;
7160  std::tie(
7161  ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToExprLoc,
7162  ToLAngleLoc, ToRAngleLoc) = *Imp;
7163 
7164  DeclarationNameInfo ToNameInfo(ToDeclName, ToExprLoc);
7165  if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
7166  return std::move(Err);
7167 
7168  TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
7169  TemplateArgumentListInfo *ResInfo = nullptr;
7170  if (E->hasExplicitTemplateArgs()) {
7171  if (Error Err =
7172  ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo))
7173  return std::move(Err);
7174  ResInfo = &ToTAInfo;
7175  }
7176 
7178  Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
7179  ToNameInfo, ResInfo);
7180 }
7181 
7184  auto Imp = importSeq(
7185  E->getLParenLoc(), E->getRParenLoc(), E->getTypeSourceInfo());
7186  if (!Imp)
7187  return Imp.takeError();
7188 
7189  SourceLocation ToLParenLoc, ToRParenLoc;
7190  TypeSourceInfo *ToTypeSourceInfo;
7191  std::tie(ToLParenLoc, ToRParenLoc, ToTypeSourceInfo) = *Imp;
7192 
7193  SmallVector<Expr *, 8> ToArgs(E->arg_size());
7194  if (Error Err =
7195  ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
7196  return std::move(Err);
7197 
7199  Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc,
7200  llvm::makeArrayRef(ToArgs), ToRParenLoc);
7201 }
7202 
7205  Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
7206  if (!ToNamingClassOrErr)
7207  return ToNamingClassOrErr.takeError();
7208 
7209  auto ToQualifierLocOrErr = import(E->getQualifierLoc());
7210  if (!ToQualifierLocOrErr)
7211  return ToQualifierLocOrErr.takeError();
7212 
7213  auto ToNameInfoOrErr = importSeq(E->getName(), E->getNameLoc());
7214  if (!ToNameInfoOrErr)
7215  return ToNameInfoOrErr.takeError();
7216  DeclarationNameInfo ToNameInfo(
7217  std::get<0>(*ToNameInfoOrErr), std::get<1>(*ToNameInfoOrErr));
7218  // Import additional name location/type info.
7219  if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
7220  return std::move(Err);
7221 
7222  UnresolvedSet<8> ToDecls;
7223  for (auto *D : E->decls())
7224  if (auto ToDOrErr = import(D))
7225  ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
7226  else
7227  return ToDOrErr.takeError();
7228 
7230  TemplateArgumentListInfo ToTAInfo;
7231  if (Error Err = ImportTemplateArgumentListInfo(
7232  E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(),
7233  ToTAInfo))
7234  return std::move(Err);
7235 
7236  ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
7237  if (!ToTemplateKeywordLocOrErr)
7238  return ToTemplateKeywordLocOrErr.takeError();
7239 
7241  Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
7242  *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
7243  ToDecls.begin(), ToDecls.end());
7244  }
7245 
7247  Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
7248  ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(),
7249  ToDecls.end());
7250 }
7251 
7254  auto Imp1 = importSeq(
7255  E->getType(), E->getOperatorLoc(), E->getQualifierLoc(),
7256  E->getTemplateKeywordLoc());
7257  if (!Imp1)
7258  return Imp1.takeError();
7259 
7260  QualType ToType;
7261  SourceLocation ToOperatorLoc, ToTemplateKeywordLoc;
7262  NestedNameSpecifierLoc ToQualifierLoc;
7263  std::tie(ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc) = *Imp1;
7264 
7265  auto Imp2 = importSeq(E->getName(), E->getNameLoc());
7266  if (!Imp2)
7267  return Imp2.takeError();
7268  DeclarationNameInfo ToNameInfo(std::get<0>(*Imp2), std::get<1>(*Imp2));
7269  // Import additional name location/type info.
7270  if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
7271  return std::move(Err);
7272 
7273  UnresolvedSet<8> ToDecls;
7274  for (Decl *D : E->decls())
7275  if (auto ToDOrErr = import(D))
7276  ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
7277  else
7278  return ToDOrErr.takeError();
7279 
7280  TemplateArgumentListInfo ToTAInfo;
7281  TemplateArgumentListInfo *ResInfo = nullptr;
7282  if (E->hasExplicitTemplateArgs()) {
7283  if (Error Err =
7284  ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo))
7285  return std::move(Err);
7286  ResInfo = &ToTAInfo;
7287  }
7288 
7289  Expr *ToBase = nullptr;
7290  if (!E->isImplicitAccess()) {
7291  if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
7292  ToBase = *ToBaseOrErr;
7293  else
7294  return ToBaseOrErr.takeError();
7295  }
7296 
7298  Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
7299  E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
7300  ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
7301 }
7302 
7304  auto Imp = importSeq(E->getCallee(), E->getType(), E->getRParenLoc());
7305  if (!Imp)
7306  return Imp.takeError();
7307 
7308  Expr *ToCallee;
7309  QualType ToType;
7310  SourceLocation ToRParenLoc;
7311  std::tie(ToCallee, ToType, ToRParenLoc) = *Imp;
7312 
7313  unsigned NumArgs = E->getNumArgs();
7314  llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
7315  if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
7316  return std::move(Err);
7317 
7318  if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
7320  Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
7321  OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
7322  OCE->getADLCallKind());
7323  }
7324 
7325  return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
7326  E->getValueKind(), ToRParenLoc, /*MinNumArgs=*/0,
7327  E->getADLCallKind());
7328 }
7329 
7331  CXXRecordDecl *FromClass = E->getLambdaClass();
7332  auto ToClassOrErr = import(FromClass);
7333  if (!ToClassOrErr)
7334  return ToClassOrErr.takeError();
7335  CXXRecordDecl *ToClass = *ToClassOrErr;
7336 
7337  // NOTE: lambda classes are created with BeingDefined flag set up.
7338  // It means that ImportDefinition doesn't work for them and we should fill it
7339  // manually.
7340  if (ToClass->isBeingDefined()) {
7341  for (auto FromField : FromClass->fields()) {
7342  auto ToFieldOrErr = import(FromField);
7343  if (!ToFieldOrErr)
7344  return ToFieldOrErr.takeError();
7345  }
7346  }
7347 
7348  auto ToCallOpOrErr = import(E->getCallOperator());
7349  if (!ToCallOpOrErr)
7350  return ToCallOpOrErr.takeError();
7351 
7352  ToClass->completeDefinition();
7353 
7354  SmallVector<LambdaCapture, 8> ToCaptures;
7355  ToCaptures.reserve(E->capture_size());
7356  for (const auto &FromCapture : E->captures()) {
7357  if (auto ToCaptureOrErr = import(FromCapture))
7358  ToCaptures.push_back(*ToCaptureOrErr);
7359  else
7360  return ToCaptureOrErr.takeError();
7361  }
7362 
7363  SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
7364  if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
7365  return std::move(Err);
7366 
7367  auto Imp = importSeq(
7369  if (!Imp)
7370  return Imp.takeError();
7371 
7372  SourceRange ToIntroducerRange;
7373  SourceLocation ToCaptureDefaultLoc, ToEndLoc;
7374  std::tie(ToIntroducerRange, ToCaptureDefaultLoc, ToEndLoc) = *Imp;
7375 
7376  return LambdaExpr::Create(
7377  Importer.getToContext(), ToClass, ToIntroducerRange,
7378  E->getCaptureDefault(), ToCaptureDefaultLoc, ToCaptures,
7379  E->hasExplicitParameters(), E->hasExplicitResultType(), ToCaptureInits,
7380  ToEndLoc, E->containsUnexpandedParameterPack());
7381 }
7382 
7383 
7385  auto Imp = importSeq(E->getLBraceLoc(), E->getRBraceLoc(), E->getType());
7386  if (!Imp)
7387  return Imp.takeError();
7388 
7389  SourceLocation ToLBraceLoc, ToRBraceLoc;
7390  QualType ToType;
7391  std::tie(ToLBraceLoc, ToRBraceLoc, ToType) = *Imp;
7392 
7393  SmallVector<Expr *, 4> ToExprs(E->getNumInits());
7394  if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
7395  return std::move(Err);
7396 
7397  ASTContext &ToCtx = Importer.getToContext();
7398  InitListExpr *To = new (ToCtx) InitListExpr(
7399  ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc);
7400  To->setType(ToType);
7401 
7402  if (E->hasArrayFiller()) {
7403  if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
7404  To->setArrayFiller(*ToFillerOrErr);
7405  else
7406  return ToFillerOrErr.takeError();
7407  }
7408 
7409  if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
7410  if (auto ToFDOrErr = import(FromFD))
7411  To->setInitializedFieldInUnion(*ToFDOrErr);
7412  else
7413  return ToFDOrErr.takeError();
7414  }
7415 
7416  if (InitListExpr *SyntForm = E->getSyntacticForm()) {
7417  if (auto ToSyntFormOrErr = import(SyntForm))
7418  To->setSyntacticForm(*ToSyntFormOrErr);
7419  else
7420  return ToSyntFormOrErr.takeError();
7421  }
7422 
7423  // Copy InitListExprBitfields, which are not handled in the ctor of
7424  // InitListExpr.
7426 
7427  return To;
7428 }
7429 
7432  ExpectedType ToTypeOrErr = import(E->getType());
7433  if (!ToTypeOrErr)
7434  return ToTypeOrErr.takeError();
7435 
7436  ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7437  if (!ToSubExprOrErr)
7438  return ToSubExprOrErr.takeError();
7439 
7440  return new (Importer.getToContext()) CXXStdInitializerListExpr(
7441  *ToTypeOrErr, *ToSubExprOrErr);
7442 }
7443 
7446  auto Imp = importSeq(E->getLocation(), E->getType(), E->getConstructor());
7447  if (!Imp)
7448  return Imp.takeError();
7449 
7450  SourceLocation ToLocation;
7451  QualType ToType;
7452  CXXConstructorDecl *ToConstructor;
7453  std::tie(ToLocation, ToType, ToConstructor) = *Imp;
7454 
7455  return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
7456  ToLocation, ToType, ToConstructor, E->constructsVBase(),
7457  E->inheritedFromVBase());
7458 }
7459 
7461  auto Imp = importSeq(E->getType(), E->getCommonExpr(), E->getSubExpr());
7462  if (!Imp)
7463  return Imp.takeError();
7464 
7465  QualType ToType;
7466  Expr *ToCommonExpr, *ToSubExpr;
7467  std::tie(ToType, ToCommonExpr, ToSubExpr) = *Imp;
7468 
7469  return new (Importer.getToContext()) ArrayInitLoopExpr(
7470  ToType, ToCommonExpr, ToSubExpr);
7471 }
7472 
7474  ExpectedType ToTypeOrErr = import(E->getType());
7475  if (!ToTypeOrErr)
7476  return ToTypeOrErr.takeError();
7477  return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
7478 }
7479 
7481  ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
7482  if (!ToBeginLocOrErr)
7483  return ToBeginLocOrErr.takeError();
7484 
7485  auto ToFieldOrErr = import(E->getField());
7486  if (!ToFieldOrErr)
7487  return ToFieldOrErr.takeError();
7488 
7490  Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr);
7491 }
7492 
7494  auto Imp = importSeq(
7495  E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten(),
7496  E->getOperatorLoc(), E->getRParenLoc(), E->getAngleBrackets());
7497  if (!Imp)
7498  return Imp.takeError();
7499 
7500  QualType ToType;
7501  Expr *ToSubExpr;
7502  TypeSourceInfo *ToTypeInfoAsWritten;
7503  SourceLocation ToOperatorLoc, ToRParenLoc;
7504  SourceRange ToAngleBrackets;
7505  std::tie(
7506  ToType, ToSubExpr, ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc,
7507  ToAngleBrackets) = *Imp;
7508 
7509  ExprValueKind VK = E->getValueKind();
7510  CastKind CK = E->getCastKind();
7511  auto ToBasePathOrErr = ImportCastPath(E);
7512  if (!ToBasePathOrErr)
7513  return ToBasePathOrErr.takeError();
7514 
7515  if (isa<CXXStaticCastExpr>(E)) {
7517  Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
7518  ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
7519  } else if (isa<CXXDynamicCastExpr>(E)) {
7521  Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
7522  ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
7523  } else if (isa<CXXReinterpretCastExpr>(E)) {
7525  Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
7526  ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
7527  } else if (isa<CXXConstCastExpr>(E)) {
7528  return CXXConstCastExpr::Create(
7529  Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
7530  ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
7531  } else {
7532  llvm_unreachable("Unknown cast type");
7533  return make_error<ImportError>();
7534  }
7535 }
7536 
7539  auto Imp = importSeq(
7540  E->getType(), E->getExprLoc(), E->getParameter(), E->getReplacement());
7541  if (!Imp)
7542  return Imp.takeError();
7543 
7544  QualType ToType;
7545  SourceLocation ToExprLoc;
7546  NonTypeTemplateParmDecl *ToParameter;
7547  Expr *ToReplacement;
7548  std::tie(ToType, ToExprLoc, ToParameter, ToReplacement) = *Imp;
7549 
7550  return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
7551  ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement);
7552 }
7553 
7555  auto Imp = importSeq(
7556  E->getType(), E->getBeginLoc(), E->getEndLoc());
7557  if (!Imp)
7558  return Imp.takeError();
7559 
7560  QualType ToType;
7561  SourceLocation ToBeginLoc, ToEndLoc;
7562  std::tie(ToType, ToBeginLoc, ToEndLoc) = *Imp;
7563 
7565  if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
7566  return std::move(Err);
7567 
7568  // According to Sema::BuildTypeTrait(), if E is value-dependent,
7569  // Value is always false.
7570  bool ToValue = (E->isValueDependent() ? false : E->getValue());
7571 
7572  return TypeTraitExpr::Create(
7573  Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs,
7574  ToEndLoc, ToValue);
7575 }
7576 
7578  ExpectedType ToTypeOrErr = import(E->getType());
7579  if (!ToTypeOrErr)
7580  return ToTypeOrErr.takeError();
7581 
7582  auto ToSourceRangeOrErr = import(E->getSourceRange());
7583  if (!ToSourceRangeOrErr)
7584  return ToSourceRangeOrErr.takeError();
7585 
7586  if (E->isTypeOperand()) {
7587  if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
7588  return new (Importer.getToContext()) CXXTypeidExpr(
7589  *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
7590  else
7591  return ToTSIOrErr.takeError();
7592  }
7593 
7594  ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
7595  if (!ToExprOperandOrErr)
7596  return ToExprOperandOrErr.takeError();
7597 
7598  return new (Importer.getToContext()) CXXTypeidExpr(
7599  *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
7600 }
7601 
7603  CXXMethodDecl *FromMethod) {
7604  for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
7605  if (auto ImportedOrErr = import(FromOverriddenMethod))
7606  ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>(
7607  (*ImportedOrErr)->getCanonicalDecl()));
7608  else
7609  consumeError(ImportedOrErr.takeError());
7610  }
7611 }
7612 
7614  ASTContext &FromContext, FileManager &FromFileManager,
7615  bool MinimalImport,
7616  ASTImporterLookupTable *LookupTable)
7617  : LookupTable(LookupTable), ToContext(ToContext), FromContext(FromContext),
7618  ToFileManager(ToFileManager), FromFileManager(FromFileManager),
7619  Minimal(MinimalImport) {
7620 
7621  ImportedDecls[FromContext.getTranslationUnitDecl()] =
7622  ToContext.getTranslationUnitDecl();
7623 }
7624 
7625 ASTImporter::~ASTImporter() = default;
7626 
7628  QualType ToT = Import(FromT);
7629  if (ToT.isNull() && !FromT.isNull())
7630  return make_error<ImportError>();
7631  return ToT;
7632 }
7633 
7635  assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
7636  "Try to get field index for non-field.");
7637 
7638  auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
7639  if (!Owner)
7640  return None;
7641 
7642  unsigned Index = 0;
7643  for (const auto *D : Owner->decls()) {
7644  if (D == F)
7645  return Index;
7646 
7647  if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D))
7648  ++Index;
7649  }
7650 
7651  llvm_unreachable("Field was not found in its parent context.");
7652 
7653  return None;
7654 }
7655 
7657 ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
7658  // We search in the redecl context because of transparent contexts.
7659  // E.g. a simple C language enum is a transparent context:
7660  // enum E { A, B };
7661  // Now if we had a global variable in the TU
7662  // int A;
7663  // then the enum constant 'A' and the variable 'A' violates ODR.
7664  // We can diagnose this only if we search in the redecl context.
7665  DeclContext *ReDC = DC->getRedeclContext();
7666  if (LookupTable) {
7668  LookupTable->lookup(ReDC, Name);
7669  return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
7670  } else {
7671  // FIXME Can we remove this kind of lookup?
7672  // Or lldb really needs this C/C++ lookup?
7674  ReDC->localUncachedLookup(Name, Result);
7675  return Result;
7676  }
7677 }
7678 
7679 void ASTImporter::AddToLookupTable(Decl *ToD) {
7680  if (LookupTable)
7681  if (auto *ToND = dyn_cast<NamedDecl>(ToD))
7682  LookupTable->add(ToND);
7683 }
7684 
7686  if (FromT.isNull())
7687  return {};
7688 
7689  const Type *FromTy = FromT.getTypePtr();
7690 
7691  // Check whether we've already imported this type.
7692  llvm::DenseMap<const Type *, const Type *>::iterator Pos
7693  = ImportedTypes.find(FromTy);
7694  if (Pos != ImportedTypes.end())
7695  return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers());
7696 
7697  // Import the type
7698  ASTNodeImporter Importer(*this);
7699  ExpectedType ToTOrErr = Importer.Visit(FromTy);
7700  if (!ToTOrErr) {
7701  llvm::consumeError(ToTOrErr.takeError());
7702  return {};
7703  }
7704 
7705  // Record the imported type.
7706  ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr();
7707 
7708  return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers());
7709 }
7710 
7712  TypeSourceInfo *ToTSI = Import(FromTSI);
7713  if (!ToTSI && FromTSI)
7714  return llvm::make_error<ImportError>();
7715  return ToTSI;
7716 }
7718  if (!FromTSI)
7719  return FromTSI;
7720 
7721  // FIXME: For now we just create a "trivial" type source info based
7722  // on the type and a single location. Implement a real version of this.
7723  QualType T = Import(FromTSI->getType());
7724  if (T.isNull())
7725  return nullptr;
7726 
7727  return ToContext.getTrivialTypeSourceInfo(
7728  T, Import(FromTSI->getTypeLoc().getBeginLoc()));
7729 }
7730 
7732  return Import(FromAttr);
7733 }
7734 Attr *ASTImporter::Import(const Attr *FromAttr) {
7735  Attr *ToAttr = FromAttr->clone(ToContext);
7736  // NOTE: Import of SourceRange may fail.
7737  ToAttr->setRange(Import(FromAttr->getRange()));
7738  return ToAttr;
7739 }
7740 
7742  auto Pos = ImportedDecls.find(FromD);
7743  if (Pos != ImportedDecls.end())
7744  return Pos->second;
7745  else
7746  return nullptr;
7747 }
7748 
7750  Decl *ToD = Import(FromD);
7751  if (!ToD && FromD)
7752  return llvm::make_error<ImportError>();
7753  return ToD;
7754 }
7756  if (!FromD)
7757  return nullptr;
7758 
7759  ASTNodeImporter Importer(*this);
7760 
7761  // Check whether we've already imported this declaration.
7762  Decl *ToD = GetAlreadyImportedOrNull(FromD);
7763  if (ToD) {
7764  // If FromD has some updated flags after last import, apply it
7765  updateFlags(FromD, ToD);
7766  return ToD;
7767  }
7768 
7769  // Import the type.
7770  ExpectedDecl ToDOrErr = Importer.Visit(FromD);
7771  if (!ToDOrErr) {
7772  llvm::consumeError(ToDOrErr.takeError());
7773  return nullptr;
7774  }
7775  ToD = *ToDOrErr;
7776 
7777  // Once the decl is connected to the existing declarations, i.e. when the
7778  // redecl chain is properly set then we populate the lookup again.
7779  // This way the primary context will be able to find all decls.
7780  AddToLookupTable(ToD);
7781 
7782  // Notify subclasses.
7783  Imported(FromD, ToD);
7784 
7785  updateFlags(FromD, ToD);
7786  return ToD;
7787 }
7788 
7790  if (!FromDC)
7791  return FromDC;
7792 
7793  auto *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC)));
7794  if (!ToDC)
7795  return nullptr;
7796 
7797  // When we're using a record/enum/Objective-C class/protocol as a context, we
7798  // need it to have a definition.
7799  if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
7800  auto *FromRecord = cast<RecordDecl>(FromDC);
7801  if (ToRecord->isCompleteDefinition()) {
7802  // Do nothing.
7803  } else if (FromRecord->isCompleteDefinition()) {
7804  if (Error Err = ASTNodeImporter(*this).ImportDefinition(
7805  FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
7806  return std::move(Err);
7807  } else {
7808  CompleteDecl(ToRecord);
7809  }
7810  } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
7811  auto *FromEnum = cast<EnumDecl>(FromDC);
7812  if (ToEnum->isCompleteDefinition()) {
7813  // Do nothing.
7814  } else if (FromEnum->isCompleteDefinition()) {
7815  if (Error Err = ASTNodeImporter(*this).ImportDefinition(
7816  FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
7817  return std::move(Err);
7818  } else {
7819  CompleteDecl(ToEnum);
7820  }
7821  } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
7822  auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
7823  if (ToClass->getDefinition()) {
7824  // Do nothing.
7825  } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
7826  if (Error Err = ASTNodeImporter(*this).ImportDefinition(
7827  FromDef, ToClass, ASTNodeImporter::IDK_Basic))
7828  return std::move(Err);
7829  } else {
7830  CompleteDecl(ToClass);
7831  }
7832  } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
7833  auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
7834  if (ToProto->getDefinition()) {
7835  // Do nothing.
7836  } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
7837  if (Error Err = ASTNodeImporter(*this).ImportDefinition(
7838  FromDef, ToProto, ASTNodeImporter::IDK_Basic))
7839  return std::move(Err);
7840  } else {
7841  CompleteDecl(ToProto);
7842  }
7843  }
7844 
7845  return ToDC;
7846 }
7847 
7849  Expr *ToE = Import(FromE);
7850  if (!ToE && FromE)
7851  return llvm::make_error<ImportError>();
7852  return ToE;
7853 }
7855  if (!FromE)
7856  return nullptr;
7857 
7858  return cast_or_null<Expr>(Import(cast<Stmt>(FromE)));
7859 }
7860 
7862  Stmt *ToS = Import(FromS);
7863  if (!ToS && FromS)
7864  return llvm::make_error<ImportError>();
7865  return ToS;
7866 }
7868  if (!FromS)
7869  return nullptr;
7870 
7871  // Check whether we've already imported this declaration.
7872  llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
7873  if (Pos != ImportedStmts.end())
7874  return Pos->second;
7875 
7876  // Import the statement.
7877  ASTNodeImporter Importer(*this);
7878  ExpectedStmt ToSOrErr = Importer.Visit(FromS);
7879  if (!ToSOrErr) {
7880  llvm::consumeError(ToSOrErr.takeError());
7881  return nullptr;
7882  }
7883 
7884  if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
7885  auto *FromE = cast<Expr>(FromS);
7886  // Copy ExprBitfields, which may not be handled in Expr subclasses
7887  // constructors.
7888  ToE->setValueKind(FromE->getValueKind());
7889  ToE->setObjectKind(FromE->getObjectKind());
7890  ToE->setTypeDependent(FromE->isTypeDependent());
7891  ToE->setValueDependent(FromE->isValueDependent());
7892  ToE->setInstantiationDependent(FromE->isInstantiationDependent());
7893  ToE->setContainsUnexpandedParameterPack(
7894  FromE->containsUnexpandedParameterPack());
7895  }
7896 
7897  // Record the imported declaration.
7898  ImportedStmts[FromS] = *ToSOrErr;
7899  return *ToSOrErr;
7900 }
7901 
7904  NestedNameSpecifier *ToNNS = Import(FromNNS);
7905  if (!ToNNS && FromNNS)
7906  return llvm::make_error<ImportError>();
7907  return ToNNS;
7908 }
7910  if (!FromNNS)
7911  return nullptr;
7912 
7913  NestedNameSpecifier *prefix = Import(FromNNS->getPrefix());
7914 
7915  switch (FromNNS->getKind()) {
7917  if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) {
7918  return NestedNameSpecifier::Create(ToContext, prefix, II);
7919  }
7920  return nullptr;
7921 
7923  if (auto *NS =
7924  cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) {
7925  return NestedNameSpecifier::Create(ToContext, prefix, NS);
7926  }
7927  return nullptr;
7928 
7930  if (auto *NSAD =
7931  cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) {
7932  return NestedNameSpecifier::Create(ToContext, prefix, NSAD);
7933  }
7934  return nullptr;
7935 
7937  return NestedNameSpecifier::GlobalSpecifier(ToContext);
7938 
7940  if (auto *RD =
7941  cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) {
7942  return NestedNameSpecifier::SuperSpecifier(ToContext, RD);
7943  }
7944  return nullptr;
7945 
7948  QualType T = Import(QualType(FromNNS->getAsType(), 0u));
7949  if (!T.isNull()) {
7950  bool bTemplate = FromNNS->getKind() ==
7952  return NestedNameSpecifier::Create(ToContext, prefix,
7953  bTemplate, T.getTypePtr());
7954  }
7955  }
7956  return nullptr;
7957  }
7958 
7959  llvm_unreachable("Invalid nested name specifier kind");
7960 }
7961 
7964  NestedNameSpecifierLoc ToNNS = Import(FromNNS);
7965  return ToNNS;
7966 }
7968  // Copied from NestedNameSpecifier mostly.
7970  NestedNameSpecifierLoc NNS = FromNNS;
7971 
7972  // Push each of the nested-name-specifiers's onto a stack for
7973  // serialization in reverse order.
7974  while (NNS) {
7975  NestedNames.push_back(NNS);
7976  NNS = NNS.getPrefix();
7977  }
7978 
7980 
7981  while (!NestedNames.empty()) {
7982  NNS = NestedNames.pop_back_val();
7984  if (!Spec)
7985  return NestedNameSpecifierLoc();
7986 
7988  switch (Kind) {
7990  Builder.Extend(getToContext(),
7991  Spec->getAsIdentifier(),
7992  Import(NNS.getLocalBeginLoc()),
7993  Import(NNS.getLocalEndLoc()));
7994  break;
7995 
7997  Builder.Extend(getToContext(),
7998  Spec->getAsNamespace(),
7999  Import(NNS.getLocalBeginLoc()),
8000  Import(NNS.getLocalEndLoc()));
8001  break;
8002 
8004  Builder.Extend(getToContext(),
8005  Spec->getAsNamespaceAlias(),
8006  Import(NNS.getLocalBeginLoc()),
8007  Import(NNS.getLocalEndLoc()));
8008  break;
8009 
8013  QualType(Spec->getAsType(), 0));
8014  Builder.Extend(getToContext(),
8015  Import(NNS.getLocalBeginLoc()),
8016  TSI->getTypeLoc(),
8017  Import(NNS.getLocalEndLoc()));
8018  break;
8019  }
8020 
8022  Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc()));
8023  break;
8024 
8026  SourceRange ToRange = Import(NNS.getSourceRange());
8027  Builder.MakeSuper(getToContext(),
8028  Spec->getAsRecordDecl(),
8029  ToRange.getBegin(),
8030  ToRange.getEnd());
8031  }
8032  }
8033  }
8034 
8035  return Builder.getWithLocInContext(getToContext());
8036 }
8037 
8039  TemplateName To = Import(From);
8040  if (To.isNull() && !From.isNull())
8041  return llvm::make_error<ImportError>();
8042  return To;
8043 }
8045  switch (From.getKind()) {
8047  if (auto *ToTemplate =
8048  cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl())))
8049  return TemplateName(ToTemplate);
8050 
8051  return {};
8052 
8054  OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate();
8055  UnresolvedSet<2> ToTemplates;
8056  for (auto *I : *FromStorage) {
8057  if (auto *To = cast_or_null<NamedDecl>(Import(I)))
8058  ToTemplates.addDecl(To);
8059  else
8060  return {};
8061  }
8062  return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
8063  ToTemplates.end());
8064  }
8065 
8068  NestedNameSpecifier *Qualifier = Import(QTN->getQualifier());
8069  if (!Qualifier)
8070  return {};
8071 
8072  if (auto *ToTemplate =
8073  cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl())))
8074  return ToContext.getQualifiedTemplateName(Qualifier,
8075  QTN->hasTemplateKeyword(),
8076  ToTemplate);
8077 
8078  return {};
8079  }
8080 
8083  NestedNameSpecifier *Qualifier = Import(DTN->getQualifier());
8084  if (!Qualifier)
8085  return {};
8086 
8087  if (DTN->isIdentifier()) {
8088  return ToContext.getDependentTemplateName(Qualifier,
8089  Import(DTN->getIdentifier()));
8090  }
8091 
8092  return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator());
8093  }
8094 
8098  auto *param =
8099  cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter()));
8100  if (!param)
8101  return {};
8102 
8103  TemplateName replacement = Import(subst->getReplacement());
8104  if (replacement.isNull())
8105  return {};
8106 
8107  return ToContext.getSubstTemplateTemplateParm(param, replacement);
8108  }
8109 
8113  auto *Param =
8114  cast_or_null<TemplateTemplateParmDecl>(
8115  Import(SubstPack->getParameterPack()));
8116  if (!Param)
8117  return {};
8118 
8119  ASTNodeImporter Importer(*this);
8121  = Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
8122  if (!ArgPack) {
8123  llvm::consumeError(ArgPack.takeError());
8124  return {};
8125  }
8126 
8127  return ToContext.getSubstTemplateTemplateParmPack(Param, *ArgPack);
8128  }
8129  }
8130 
8131  llvm_unreachable("Invalid template name kind");
8132 }
8133 
8135  SourceLocation ToLoc = Import(FromLoc);
8136  if (ToLoc.isInvalid() && !FromLoc.isInvalid())
8137  return llvm::make_error<ImportError>();
8138  return ToLoc;
8139 }
8141  if (FromLoc.isInvalid())
8142  return {};
8143 
8144  SourceManager &FromSM = FromContext.getSourceManager();
8145 
8146  std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc);
8147  FileID ToFileID = Import(Decomposed.first);
8148  if (ToFileID.isInvalid())
8149  return {};
8150  SourceManager &ToSM = ToContext.getSourceManager();
8151  return ToSM.getComposedLoc(ToFileID, Decomposed.second);
8152 }
8153 
8155  SourceRange ToRange = Import(FromRange);
8156  return ToRange;
8157 }
8159  return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd()));
8160 }
8161 
8163  FileID ToID = Import(FromID);
8164  if (ToID.isInvalid() && FromID.isValid())
8165  return llvm::make_error<ImportError>();
8166  return ToID;
8167 }
8169  llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
8170  if (Pos != ImportedFileIDs.end())
8171  return Pos->second;
8172 
8173  SourceManager &FromSM = FromContext.getSourceManager();
8174  SourceManager &ToSM = ToContext.getSourceManager();
8175  const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
8176 
8177  // Map the FromID to the "to" source manager.
8178  FileID ToID;
8179  if (FromSLoc.isExpansion()) {
8180  const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
8181  SourceLocation ToSpLoc = Import(FromEx.getSpellingLoc());
8182  SourceLocation ToExLocS = Import(FromEx.getExpansionLocStart());
8183  unsigned TokenLen = FromSM.getFileIDSize(FromID);
8184  SourceLocation MLoc;
8185  if (FromEx.isMacroArgExpansion()) {
8186  MLoc = ToSM.createMacroArgExpansionLoc(ToSpLoc, ToExLocS, TokenLen);
8187  } else {
8188  SourceLocation ToExLocE = Import(FromEx.getExpansionLocEnd());
8189  MLoc = ToSM.createExpansionLoc(ToSpLoc, ToExLocS, ToExLocE, TokenLen,
8190  FromEx.isExpansionTokenRange());
8191  }
8192  ToID = ToSM.getFileID(MLoc);
8193  } else {
8194  // Include location of this file.
8195  SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
8196 
8197  const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache();
8198  if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
8199  // FIXME: We probably want to use getVirtualFile(), so we don't hit the
8200  // disk again
8201  // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
8202  // than mmap the files several times.
8203  const FileEntry *Entry =
8204  ToFileManager.getFile(Cache->OrigEntry->getName());
8205  if (!Entry)
8206  return {};
8207  ToID = ToSM.createFileID(Entry, ToIncludeLoc,
8208  FromSLoc.getFile().getFileCharacteristic());
8209  } else {
8210  // FIXME: We want to re-use the existing MemoryBuffer!
8211  const llvm::MemoryBuffer *FromBuf =
8212  Cache->getBuffer(FromContext.getDiagnostics(), FromSM);
8213  std::unique_ptr<llvm::MemoryBuffer> ToBuf =
8214  llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
8215  FromBuf->getBufferIdentifier());
8216  ToID = ToSM.createFileID(std::move(ToBuf),
8217  FromSLoc.getFile().getFileCharacteristic());
8218  }
8219  }
8220 
8221  ImportedFileIDs[FromID] = ToID;
8222  return ToID;
8223 }
8224 
8227  CXXCtorInitializer *To = Import(From);
8228  if (!To && From)
8229  return llvm::make_error<ImportError>();
8230  return To;
8231 }
8233  Expr *ToExpr = Import(From->getInit());
8234  if (!ToExpr && From->getInit())
8235  return nullptr;
8236 
8237  if (From->isBaseInitializer()) {
8238  TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo());
8239  if (!ToTInfo && From->getTypeSourceInfo())
8240  return nullptr;
8241 
8242  return new (ToContext) CXXCtorInitializer(
8243  ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()),
8244  ToExpr, Import(From->getRParenLoc()),
8245  From->isPackExpansion() ? Import(From->getEllipsisLoc())
8246  : SourceLocation());
8247  } else if (From->isMemberInitializer()) {
8248  auto *ToField = cast_or_null<FieldDecl>(Import(From->getMember()));
8249  if (!ToField && From->getMember())
8250  return nullptr;
8251 
8252  return new (ToContext) CXXCtorInitializer(
8253  ToContext, ToField, Import(From->getMemberLocation()),
8254  Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc()));
8255  } else if (From->isIndirectMemberInitializer()) {
8256  auto *ToIField = cast_or_null<IndirectFieldDecl>(
8257  Import(From->getIndirectMember()));
8258  if (!ToIField && From->getIndirectMember())
8259  return nullptr;
8260 
8261  return new (ToContext) CXXCtorInitializer(
8262  ToContext, ToIField, Import(From->getMemberLocation()),
8263  Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc()));
8264  } else if (From->isDelegatingInitializer()) {
8265  TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo());
8266  if (!ToTInfo && From->getTypeSourceInfo())
8267  return nullptr;
8268 
8269  return new (ToContext)
8270  CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()),
8271  ToExpr, Import(From->getRParenLoc()));
8272  } else {
8273  return nullptr;
8274  }
8275 }
8276 
8279  CXXBaseSpecifier *To = Import(From);
8280  if (!To && From)
8281  return llvm::make_error<ImportError>();
8282  return To;
8283 }
8285  auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
8286  if (Pos != ImportedCXXBaseSpecifiers.end())
8287  return Pos->second;
8288 
8289  CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
8290  Import(BaseSpec->getSourceRange()),
8291  BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
8292  BaseSpec->getAccessSpecifierAsWritten(),
8293  Import(BaseSpec->getTypeSourceInfo()),
8294  Import(BaseSpec->getEllipsisLoc()));
8295  ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
8296  return Imported;
8297 }
8298 
8300  Decl *To = Import(From);
8301  if (!To)
8302  return llvm::make_error<ImportError>();
8303 
8304  if (auto *FromDC = cast<DeclContext>(From)) {
8305  ASTNodeImporter Importer(*this);
8306 
8307  if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
8308  if (!ToRecord->getDefinition()) {
8309  return Importer.ImportDefinition(
8310  cast<RecordDecl>(FromDC), ToRecord,
8312  }
8313  }
8314 
8315  if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
8316  if (!ToEnum->getDefinition()) {
8317  return Importer.ImportDefinition(
8318  cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything);
8319  }
8320  }
8321 
8322  if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
8323  if (!ToIFace->getDefinition()) {
8324  return Importer.ImportDefinition(
8325  cast<ObjCInterfaceDecl>(FromDC), ToIFace,
8327  }
8328  }
8329 
8330  if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
8331  if (!ToProto->getDefinition()) {
8332  return Importer.ImportDefinition(
8333  cast<ObjCProtocolDecl>(FromDC), ToProto,
8335  }
8336  }
8337 
8338  return Importer.ImportDeclContext(FromDC, true);
8339  }
8340 
8341  return Error::success();
8342 }
8343 
8345  Error Err = ImportDefinition_New(From);
8346  llvm::consumeError(std::move(Err));
8347 }
8348 
8350  DeclarationName ToName = Import(FromName);
8351  if (!ToName && FromName)
8352  return llvm::make_error<ImportError>();
8353  return ToName;
8354 }
8356  if (!FromName)
8357  return {};
8358 
8359  switch (FromName.getNameKind()) {
8361  return Import(FromName.getAsIdentifierInfo());
8362 
8366  return Import(FromName.getObjCSelector());
8367 
8369  QualType T = Import(FromName.getCXXNameType());
8370  if (T.isNull())
8371  return {};
8372 
8373  return ToContext.DeclarationNames.getCXXConstructorName(
8374  ToContext.getCanonicalType(T));
8375  }
8376 
8378  QualType T = Import(FromName.getCXXNameType());
8379  if (T.isNull())
8380  return {};
8381 
8382  return ToContext.DeclarationNames.getCXXDestructorName(
8383  ToContext.getCanonicalType(T));
8384  }
8385 
8387  auto *Template = cast_or_null<TemplateDecl>(
8388  Import(FromName.getCXXDeductionGuideTemplate()));
8389  if (!Template)
8390  return {};
8391  return ToContext.DeclarationNames.getCXXDeductionGuideName(Template);
8392  }
8393 
8395  QualType T = Import(FromName.getCXXNameType());
8396  if (T.isNull())
8397  return {};
8398 
8400  ToContext.getCanonicalType(T));
8401  }
8402 
8404  return ToContext.DeclarationNames.getCXXOperatorName(
8405  FromName.getCXXOverloadedOperator());
8406 
8409  Import(FromName.getCXXLiteralIdentifier()));
8410 
8412  // FIXME: STATICS!
8414  }
8415 
8416  llvm_unreachable("Invalid DeclarationName Kind!");
8417 }
8418 
8420  if (!FromId)
8421  return nullptr;
8422 
8423  IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
8424 
8425  if (!ToId->getBuiltinID() && FromId->getBuiltinID())
8426  ToId->setBuiltinID(FromId->getBuiltinID());
8427 
8428  return ToId;
8429 }
8430 
8432  Selector ToSel = Import(FromSel);
8433  if (ToSel.isNull() && !FromSel.isNull())
8434  return llvm::make_error<ImportError>();
8435  return ToSel;
8436 }
8438  if (FromSel.isNull())
8439  return {};
8440 
8442  Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
8443  for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
8444  Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
8445  return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
8446 }
8447 
8449  DeclContext *DC,
8450  unsigned IDNS,
8451  NamedDecl **Decls,
8452  unsigned NumDecls) {
8453  return Name;
8454 }
8455 
8457  if (LastDiagFromFrom)
8459  FromContext.getDiagnostics());
8460  LastDiagFromFrom = false;
8461  return ToContext.getDiagnostics().Report(Loc, DiagID);
8462 }
8463 
8465  if (!LastDiagFromFrom)
8467  ToContext.getDiagnostics());
8468  LastDiagFromFrom = true;
8469  return FromContext.getDiagnostics().Report(Loc, DiagID);
8470 }
8471 
8473  if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
8474  if (!ID->getDefinition())
8475  ID->startDefinition();
8476  }
8477  else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
8478  if (!PD->getDefinition())
8479  PD->startDefinition();
8480  }
8481  else if (auto *TD = dyn_cast<TagDecl>(D)) {
8482  if (!TD->getDefinition() && !TD->isBeingDefined()) {
8483  TD->startDefinition();
8484  TD->setCompleteDefinition(true);
8485  }
8486  }
8487  else {
8488  assert(0 && "CompleteDecl called on a Decl that can't be completed");
8489  }
8490 }
8491 
8493  llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From);
8494  assert((Pos == ImportedDecls.end() || Pos->second == To) &&
8495  "Try to import an already imported Decl");
8496  if (Pos != ImportedDecls.end())
8497  return Pos->second;
8498  ImportedDecls[From] = To;
8499  return To;
8500 }
8501 
8503  bool Complain) {
8504  llvm::DenseMap<const Type *, const Type *>::iterator Pos
8505  = ImportedTypes.find(From.getTypePtr());
8506  if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To))
8507  return true;
8508 
8509  StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls,
8510  getStructuralEquivalenceKind(*this), false,
8511  Complain);
8512  return Ctx.IsEquivalent(From, To);
8513 }
SourceLocation getRParenLoc() const
Definition: Stmt.h:2218
LLVM_NODISCARD llvm::Error ImportDefinition_New(Decl *From)
Import the definition of the given declaration, including all of the declarations it contains...
Expr * getInc()
Definition: Stmt.h:2270
ExpectedStmt VisitNullStmt(NullStmt *S)
const Expr * getSubExpr() const
Definition: Expr.h:890
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition: DeclCXX.h:2325
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition: Expr.h:4289
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
Represents a single C99 designator.
Definition: Expr.h:4494
SourceLocation getGetterNameLoc() const
Definition: DeclObjC.h:907
TemplateTemplateParmDecl * getParameterPack() const
Retrieve the template template parameter pack being substituted.
Definition: TemplateName.h:136
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
Definition: Type.h:5376
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
SourceLocation getRBracLoc() const
Definition: Stmt.h:1334
Defines the clang::ASTContext interface.
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it&#39;s either not been deduced or was deduce...
Definition: Type.h:4735
static CXXDefaultInitExpr * Create(const ASTContext &Ctx, SourceLocation Loc, FieldDecl *Field)
Field is the non-static data member whose default initializer is used by this expression.
Definition: ExprCXX.h:1152
IdentifierInfo * getInputIdentifier(unsigned i) const
Definition: Stmt.h:2789
Represents a type that was referred to using an elaborated type keyword, e.g., struct S...
Definition: Type.h:5129
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1583
ObjCPropertyQueryKind getQueryKind() const
Definition: DeclObjC.h:881
SourceLocation getRParenLoc() const
Definition: Stmt.h:2696
VarDecl * getCapturedVar() const
Retrieve the declaration of the local variable being captured.
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition: DeclCXX.h:3201
The null pointer literal (C++11 [lex.nullptr])
Definition: ExprCXX.h:596
const CXXDestructorDecl * getDestructor() const
Definition: ExprCXX.h:1196
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:2768
This represents a GCC inline-assembly statement extension.
Definition: Stmt.h:2675
void setImplicit(bool I=true)
Definition: DeclBase.h:548
Represents a function declaration or definition.
Definition: Decl.h:1738
SourceLocation getForLoc() const
Definition: StmtCXX.h:194
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
Definition: Expr.h:1151
ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D)
bool getValue() const
Definition: ExprCXX.h:2473
bool isImplicit() const
Determine whether this was an implicit capture (not written between the square brackets introducing t...
static char ID
Definition: ASTImporter.h:60
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:1692
Expr * getLHS() const
Definition: Expr.h:3627
ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E)
Expr * getInit() const
Get the initializer.
Definition: DeclCXX.h:2454
bool isKindOfTypeAsWritten() const
Whether this is a "__kindof" type as written.
Definition: Type.h:5655
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition: ExprCXX.h:2786
unsigned getNumInputs() const
Definition: Stmt.h:2591
ExpectedStmt VisitExpr(Expr *E)
SourceLocation getRParenLoc() const
Definition: Expr.h:2635
void setArrayFiller(Expr *filler)
Definition: Expr.cpp:2035
Smart pointer class that efficiently represents Objective-C method names.
This is a discriminated union of FileInfo and ExpansionInfo.
SourceLocation getForLoc() const
Definition: Stmt.h:2283
void setAnonymousStructOrUnion(bool Anon)
Definition: Decl.h:3670
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2537
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments of this object type as they were written.
Definition: Type.h:5649
QualType getPointeeType() const
Definition: Type.h:2550
llvm::iterator_range< arg_iterator > placement_arguments()
Definition: ExprCXX.h:2120
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
Definition: ExprCXX.h:1110
Represents the dependent type named by a dependently-scoped typename using declaration, e.g.
Definition: Type.h:4121
bool hasTemplateKeyword() const
Whether the template name was prefixed by the "template" keyword.
Definition: TemplateName.h:393
Stores the type being destroyed by a pseudo-destructor expression.
Definition: ExprCXX.h:2235
A (possibly-)qualified type.
Definition: Type.h:638
uint64_t getValue() const
Definition: ExprCXX.h:2559
SourceLocation getBeginLoc() const
Definition: ExprCXX.h:1171
Expected< ObjCTypeParamList * > ImportObjCTypeParamList(ObjCTypeParamList *list)
ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D)
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: ExprCXX.h:3054
const char * getDeclKindName() const
Definition: DeclBase.cpp:123
StringKind getKind() const
Definition: Expr.h:1681
ExpectedType VisitElaboratedType(const ElaboratedType *T)
ExpectedDecl VisitUsingDecl(UsingDecl *D)
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
Definition: TemplateName.h:495
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary class pattern.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition: Expr.h:2773
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
unsigned param_size() const
Definition: DeclObjC.h:341
Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin)
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.h:2325
QualType getInjectedSpecializationType() const
Definition: Type.h:5010
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:479
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:122
SourceRange getCXXOperatorNameRange() const
getCXXOperatorNameRange - Gets the range of the operator name (without the operator keyword)...
void startDefinition()
Starts the definition of this Objective-C class, taking it from a forward declaration (@class) to a d...
Definition: DeclObjC.cpp:611
SourceLocation getSpellingLoc() const
SourceLocation getEllipsisLoc() const
Get the location of the ... in a case statement of the form LHS ... RHS.
Definition: Stmt.h:1469
SourceLocation getLParen() const
Get the location of the left parentheses &#39;(&#39;.
Definition: Expr.h:1868
const Expr * getSubExpr() const
Definition: ExprCXX.h:1037
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition: DeclCXX.h:3630
static ClassTemplateDecl * getDefinition(ClassTemplateDecl *D)
SourceLocation getLParenLoc() const
Definition: DeclCXX.h:2450
Expr * getCond()
Definition: Stmt.h:2112
inputs_range inputs()
Definition: Stmt.h:2624
ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D)
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
Definition: DeclObjC.h:1530
Defines the clang::FileManager interface and associated types.
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:2827
bool isObjCMethodParameter() const
Definition: Decl.h:1593
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2430
CompoundStmt * getSubStmt()
Definition: Expr.h:3817
DeclarationName getCXXConstructorName(CanQualType Ty)
Returns the name of a C++ constructor for the given Type.
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition: Decl.h:2707
Expr * getUnderlyingExpr() const
Definition: Type.h:4256
SourceLocation getRParenLoc() const
Definition: StmtObjC.h:104
bool hasExplicitResultType() const
Whether this lambda had its result type explicitly specified.
Definition: ExprCXX.h:1851
bool isThrownVariableInScope() const
Determines whether the variable thrown by this expression (if any!) is within the innermost try block...
Definition: ExprCXX.h:1047
Stmt - This represents one statement.
Definition: Stmt.h:66
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition: Expr.h:2540
Expr * getDimensionExpression() const
Definition: ExprCXX.h:2561
const ObjCAtFinallyStmt * getFinallyStmt() const
Retrieve the @finally statement, if any.
Definition: StmtObjC.h:224
Expr * getBitWidth() const
Definition: Decl.h:2668
Kind getKind() const
Definition: Type.h:2418
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
Definition: Decl.h:4289
CXXCatchStmt * getHandler(unsigned i)
Definition: StmtCXX.h:104
bool IsICE
Whether this statement is an integral constant expression, or in C++11, whether the statement is a co...
Definition: Decl.h:802
bool isArrayFormAsWritten() const
Definition: ExprCXX.h:2198
ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D)
IfStmt - This represents an if/then/else.
Definition: Stmt.h:1687
ClassTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
VarDecl * getTemplatedDecl() const
Get the underlying variable declarations of the template.
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:3012
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition: Expr.h:2152
SourceLocation getLocation() const
Definition: Expr.h:1493
ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D)
ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S)
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:2786
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:713
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
Definition: DeclObjC.cpp:358
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1020
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:1442
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition: Decl.cpp:3868
Represents the declaration of a typedef-name via the &#39;typedef&#39; type specifier.
Definition: Decl.h:3018
C Language Family Type Representation.
unsigned getNumOutputs() const
Definition: Stmt.h:2569
Defines the SourceManager interface.
Microsoft&#39;s &#39;__super&#39; specifier, stored as a CXXRecordDecl* of the class it appeared in...
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
Definition: Decl.h:2094
ExpectedDecl VisitParmVarDecl(ParmVarDecl *D)
ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E)
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:5212
SourceLocation getRBracketLoc() const
Definition: Expr.h:4577
The template argument is an expression, and we&#39;ve not resolved it to one of the other forms yet...
Definition: TemplateBase.h:87
ArrayRef< CleanupObject > getObjects() const
Definition: ExprCXX.h:3115
Expr * getBase() const
Definition: Expr.h:2767
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Definition: DeclTemplate.h:270
const StringLiteral * getAsmString() const
Definition: Stmt.h:2701
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:5231
DeclarationName getCXXConversionFunctionName(CanQualType Ty)
Returns the name of a C++ conversion function for the given Type.
TypeSourceInfo * getTypeSourceInfo() const
Definition: Expr.h:2961
bool isInitICE() const
Determines whether the initializer is an integral constant expression, or in C++11, whether the initializer is a constant expression.
Definition: Decl.cpp:2324
ExpectedStmt VisitDoStmt(DoStmt *S)
ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E)
iterator end()
Definition: DeclGroup.h:106
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:1933
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
void setRangeEnd(SourceLocation E)
Definition: Decl.h:1908
bool hasLeadingEmptyMacro() const
Definition: Stmt.h:1224
Stmt * getHandlerBlock() const
Definition: StmtCXX.h:52
ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E)
ExpectedDecl VisitRecordDecl(RecordDecl *D)
llvm::APFloat getValue() const
Definition: Expr.h:1459
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:410
ExpectedStmt VisitBreakStmt(BreakStmt *S)
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition: Expr.h:4858
FunctionDecl * getOperatorNew() const
Definition: ExprCXX.h:2033
ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S)
ExpectedStmt VisitVAArgExpr(VAArgExpr *E)
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition: Decl.cpp:2132
bool isVirtual() const
Determines whether the base class is a virtual base class (or not).
Definition: DeclCXX.h:245
void setType(QualType t)
Definition: Expr.h:129
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:2828
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
const Expr * getSubExpr() const
Definition: Expr.h:4109
Defines the C++ template declaration subclasses.
Opcode getOpcode() const
Definition: Expr.h:3322
StringRef P
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E)
Represents a C++11 auto or C++14 decltype(auto) type.
Definition: Type.h:4749
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression, including the actual initialized value and any expressions that occur within array and array-range designators.
Definition: Expr.h:4665
SourceLocation getIdentLoc() const
Definition: Stmt.h:1607
void setPure(bool P=true)
Definition: Decl.cpp:2747
ExpectedStmt VisitLabelStmt(LabelStmt *S)
Represents an attribute applied to a statement.
Definition: Stmt.h:1633
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition: Decl.h:2072
Not a friend object.
Definition: DeclBase.h:1095
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:1844
known_categories_range known_categories() const
Definition: DeclObjC.h:1687
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration, or NULL if there is no previous declaration.
Definition: DeclBase.h:953
NamedDecl * getDecl() const
ExpectedStmt VisitParenListExpr(ParenListExpr *E)
Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD)
SourceLocation getColonLoc() const
The location of the colon following the access specifier.
Definition: DeclCXX.h:154
The base class of the type hierarchy.
Definition: Type.h:1407
Represents an empty-declaration.
Definition: Decl.h:4259
ExpectedStmt VisitStmt(Stmt *S)
Represents Objective-C&#39;s @throw statement.
Definition: StmtObjC.h:313
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called...
Definition: ExprCXX.h:1373
ExpectedStmt VisitDefaultStmt(DefaultStmt *S)
Each ExpansionInfo encodes the expansion location - where the token was ultimately expanded...
DiagnosticsEngine & getDiagnostics() const
ExpectedType VisitUnresolvedUsingType(const UnresolvedUsingType *T)
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1295
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list...
Definition: Expr.h:1195
SourceLocation getLocation() const
Definition: ExprCXX.h:610
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2812
Declaration of a variable template.
SourceLocation getRParenLoc() const
Definition: Expr.h:2292
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Definition: TemplateBase.h:64
Represent a C++ namespace.
Definition: Decl.h:515
ExpectedStmt VisitAttributedStmt(AttributedStmt *S)
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1262
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.h:1169
Expected< TemplateParameterList * > ImportTemplateParameterList(TemplateParameterList *Params)
RetTy Visit(const Type *T)
Performs the operation associated with this visitor object.
Definition: TypeVisitor.h:69
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to...
Definition: Expr.h:3208
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:1370
FPOptions getFPFeatures() const
Definition: Expr.h:3461
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent...
Definition: ExprCXX.h:2514
void setSpecializationKind(TemplateSpecializationKind TSK)
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition: Decl.cpp:4154
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:414
ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D)
A container of type source information.
Definition: Decl.h:87
ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E)
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
Definition: Type.h:5983
bool isEmpty() const
Evaluates true when this declaration name is empty.
ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E)
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr *> Attrs, Stmt *SubStmt)
Definition: Stmt.cpp:352
IdentKind getIdentKind() const
Definition: Expr.h:1806
ExpectedType VisitDependentTemplateSpecializationType(const DependentTemplateSpecializationType *T)
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.h:2493
SourceLocation getGotoLoc() const
Definition: Stmt.h:2355
void setTemplateArgsInfo(const TemplateArgumentListInfo &ArgsInfo)
ExpectedDecl VisitFieldDecl(FieldDecl *D)
static CXXFunctionalCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, TypeSourceInfo *Written, CastKind Kind, Expr *Op, const CXXCastPath *Path, SourceLocation LPLoc, SourceLocation RPLoc)
Definition: ExprCXX.cpp:809
SourceLocation getOperatorLoc() const
Determine the location of the &#39;sizeof&#39; keyword.
Definition: ExprCXX.h:3906
SourceLocation getRParenLoc() const
Definition: ExprCXX.h:1895
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to...
Definition: Decl.h:1210
SourceLocation getColonLoc() const
Retrieve the location of the &#39;:&#39; separating the type parameter name from the explicitly-specified bou...
Definition: DeclObjC.h:623
bool isPackExpansion() const
Determine whether this capture is a pack expansion, which captures a function parameter pack...
Not supported node or case.
Definition: ASTImporter.h:55
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:26
param_const_iterator param_end() const
Definition: DeclObjC.h:352
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:4569
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2484
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
Definition: ExprCXX.h:4156
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:207
ExpectedType VisitComplexType(const ComplexType *T)
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition: Decl.h:2000
ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D)
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition: DeclCXX.h:2358
SourceLocation getTargetNameLoc() const
Returns the location of the identifier in the named namespace.
Definition: DeclCXX.h:3112
QualType getElementType() const
Definition: Type.h:2847
DeclarationName getCXXDeductionGuideName(TemplateDecl *TD)
Returns the name of a C++ deduction guide for the given template.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3169
const Expr * getSubExpr() const
Definition: Expr.h:1529
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
static CXXOperatorCallExpr * Create(const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn, ArrayRef< Expr *> Args, QualType Ty, ExprValueKind VK, SourceLocation OperatorLoc, FPOptions FPFeatures, ADLCallKind UsesADL=NotADL)
Definition: ExprCXX.cpp:557
ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E)
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:485
SourceLocation getCoawaitLoc() const
Definition: StmtCXX.h:195
std::tuple< FunctionTemplateDecl *, TemplateArgsTy > FunctionTemplateAndArgsTy
Expr * getIndexExpr(unsigned Idx)
Definition: Expr.h:2180
bool isIndirectMemberInitializer() const
Definition: DeclCXX.h:2337
An identifier, stored as an IdentifierInfo*.
Stmt * getSubStmt()
Definition: Stmt.h:1555
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.h:2550
unsigned getDepth() const
Get the nesting depth of the template parameter.
FriendDecl - Represents the declaration of a friend entity, which can be a function, a type, or a templated function or type.
Definition: DeclFriend.h:54
Expected< CXXCastPath > ImportCastPath(CastExpr *E)
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, ConstructionKind ConstructKind, SourceRange ParenOrBraceRange)
Create a C++ construction expression.
Definition: ExprCXX.cpp:984
Represents a variable declaration or definition.
Definition: Decl.h:813
ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T)
void setImplementation(ObjCCategoryImplDecl *ImplD)
Definition: DeclObjC.cpp:2025
const VarDecl * getNRVOCandidate() const
Retrieve the variable that might be used for the named return value optimization. ...
Definition: Stmt.h:2485
SourceLocation getLParenLoc() const
Definition: Stmt.h:2285
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
ExpectedType VisitTypeOfType(const TypeOfType *T)
ExpectedDecl VisitLabelDecl(LabelDecl *D)
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:2925
ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D)
void setCXXLiteralOperatorNameLoc(SourceLocation Loc)
setCXXLiteralOperatorNameLoc - Sets the location of the literal operator name (not the operator keywo...
SourceRange getSourceRange() const LLVM_READONLY
Definition: ExprCXX.h:738
SourceLocation getOperatorLoc() const
Retrieve the location of the &#39;.&#39; or &#39;->&#39; operator.
Definition: ExprCXX.h:2352
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition: Decl.h:3529
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition: Expr.h:4820
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6748
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition: Decl.cpp:2621
ObjCCategoryImplDecl * getImplementation() const
Definition: DeclObjC.cpp:2020
ExpectedType VisitAtomicType(const AtomicType *T)
unsigned getNumArgs() const
Determine the number of arguments to this type trait.
Definition: ExprCXX.h:2479
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:57
SourceLocation getExternLoc() const
Gets the location of the extern keyword, if present.
Extra information about a function prototype.
Definition: Type.h:3767
SourceRange getSourceRange() const
Definition: ExprCXX.h:2158
bool hasInheritedDefaultArg() const
Definition: Decl.h:1676
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:1997
ExpectedType VisitRValueReferenceType(const RValueReferenceType *T)
SourceLocation getColonLoc() const
Definition: Expr.h:3572
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
Represents a variable template specialization, which refers to a variable template with a given set o...
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
SourceLocation getLAngleLoc() const
Definition: DeclTemplate.h:173
ExpectedType VisitObjCObjectType(const ObjCObjectType *T)
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:604
A namespace, stored as a NamespaceDecl*.
DeclarationName getName() const
Gets the name looked up.
Definition: ExprCXX.h:2744
DiagnosticBuilder ToDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "to" context.
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition: ExprCXX.h:624
Stmt * getThen()
Definition: Stmt.h:1774
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
Definition: DeclFriend.h:60
SourceLocation getIfLoc() const
Definition: Stmt.h:1846
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:68
unsigned getNumPlacementArgs() const
Definition: ExprCXX.h:2051
TypeSourceInfo * getArgumentTypeInfo() const
Definition: Expr.h:2262
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition: DeclCXX.h:2331
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition: ExprCXX.h:2896
TemplateName getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param, TemplateName replacement) const
Defines the Objective-C statement AST node classes.
SourceLocation getEllipsisLoc() const
Definition: DeclCXX.h:2363
unsigned getNumExpressions() const
Definition: Expr.h:2195
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition: Expr.h:1334
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Definition: ExprCXX.h:1483
QualType Import(QualType FromT)
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:1015
Expr * getExprOperand() const
Definition: ExprCXX.h:726
Represents an expression – generally a full-expression – that introduces cleanups to be run at the ...
Definition: ExprCXX.h:3089
Represents a parameter to a function.
Definition: Decl.h:1550
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:4603
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:950
DeclarationNameInfo getNameInfo() const
Definition: DeclCXX.h:3620
Defines the clang::Expr interface and subclasses for C++ expressions.
SourceLocation getRParenLoc() const
Definition: DeclCXX.h:2451
QualType getIntegralType() const
Retrieve the type of the integral value.
Definition: TemplateBase.h:315
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition: ExprCXX.cpp:1196
const ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.h:2689
ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D)
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
const Stmt * getSubStmt() const
Definition: StmtObjC.h:356
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition: DeclCXX.cpp:1638
const char * getStmtClassName() const
Definition: Stmt.cpp:75
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition: ExprCXX.h:303
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:1593
ExpectedStmt VisitForStmt(ForStmt *S)
static CXXUnresolvedConstructExpr * Create(const ASTContext &Context, TypeSourceInfo *Type, SourceLocation LParenLoc, ArrayRef< Expr *> Args, SourceLocation RParenLoc)
Definition: ExprCXX.cpp:1283
ExpectedStmt VisitCompoundStmt(CompoundStmt *S)
SourceLocation getDotLoc() const
Definition: Expr.h:4561
Represents a struct/union/class.
Definition: Decl.h:3593
Represents a C99 designated initializer expression.
Definition: Expr.h:4419
LanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition: DeclCXX.h:2860
ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D)
SourceLocation getVarianceLoc() const
Retrieve the location of the variance keyword.
Definition: DeclObjC.h:612
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
virtual 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.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:298
Provides common interface for the Decls that can be redeclared.
Definition: Redeclarable.h:85
QualType getOriginalType() const
Definition: Type.h:2601
TypeSourceInfo * getScopeTypeInfo() const
Retrieve the scope type in a qualified pseudo-destructor expression.
Definition: ExprCXX.h:2363
FunctionType::ExtInfo ExtInfo
Definition: Type.h:3768
One of these records is kept for each identifier that is lexed.
Represents a class template specialization, which refers to a class template with a given set of temp...
Stmt * getBody()
Definition: Stmt.h:2210
void setIntegerType(QualType T)
Set the underlying integer type.
Definition: Decl.h:3489
Expr * GetTemporaryExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
Definition: ExprCXX.h:4197
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition: DeclFriend.h:124
unsigned getDepth() const
Retrieve the depth of the template parameter.
SourceLocation getTildeLoc() const
Retrieve the location of the &#39;~&#39;.
Definition: ExprCXX.h:2370
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition: Expr.h:2077
DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "from" context.
SourceLocation getRParenLoc() const
Definition: Expr.h:5524
ExpectedDecl VisitDecl(Decl *D)
StringLiteral * getMessage()
Definition: DeclCXX.h:3772
bool cleanupsHaveSideEffects() const
Definition: ExprCXX.h:3127
QualType getComputationResultType() const
Definition: Expr.h:3530
SourceLocation getIvarLBraceLoc() const
Definition: DeclObjC.h:2696
Represents a class type in Objective C.
Definition: Type.h:5538
SourceLocation getRParen() const
Get the location of the right parentheses &#39;)&#39;.
Definition: Expr.h:1872
QualType getPointeeType() const
Definition: Type.h:2654
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:330
void setUninstantiatedDefaultArg(Expr *arg)
Definition: Decl.cpp:2610
CXXRecordDecl * getPreviousDecl()
Definition: DeclCXX.h:736
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:155
A C++ nested-name-specifier augmented with source location information.
Expr * getInit() const
Retrieve the initializer value.
Definition: Expr.h:4653
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition: Decl.h:576
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:423
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
bool CheckedICE
Whether we already checked whether this statement was an integral constant expression.
Definition: Decl.h:793
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition: DeclCXX.h:3093
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:72
bool isFileScope() const
Definition: Expr.h:2955
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:3774
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:618
field_range fields() const
Definition: Decl.h:3784
SourceLocation getAmpAmpLoc() const
Definition: Expr.h:3771
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:288
ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E)
NameKind getNameKind() const
Determine what kind of name this is.
SourceLocation getEndLoc() const
Definition: Stmt.h:1166
Represents a member of a struct/union/class.
Definition: Decl.h:2579
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
Definition: Type.h:4904
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this class.
Definition: DeclObjC.cpp:329
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition: DeclCXX.h:2386
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:2133
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition: ExprCXX.h:3615
const llvm::APSInt & getInitVal() const
Definition: Decl.h:2807
Defines the ExceptionSpecificationType enumeration and various utility functions. ...
ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E)
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:4074
This declaration is a friend function.
Definition: DeclBase.h:153
NonTypeTemplateParmDecl * getParameter() const
Definition: ExprCXX.h:3992
const DeclarationNameInfo & getNameInfo() const
Gets the full name info.
Definition: ExprCXX.h:2741
static DesignatedInitExpr * Create(const ASTContext &C, llvm::ArrayRef< Designator > Designators, ArrayRef< Expr *> IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition: Expr.cpp:3907
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition: Decl.h:1603
An operation on a type.
Definition: TypeVisitor.h:65
One instance of this struct is kept for every file loaded or used.
Definition: SourceManager.h:95
bool isDefined() const
Definition: DeclObjC.h:440
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition: Expr.h:2071
SourceLocation getLabelLoc() const
Definition: Expr.h:3773
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:3877
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition: Expr.h:2834
ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D)
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
void setSuperClass(TypeSourceInfo *superClass)
Definition: DeclObjC.h:1588
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:2127
SourceLocation getRBraceLoc() const
Definition: Expr.h:4332
SourceLocation getOperatorLoc() const
Definition: Expr.h:2289
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition: Expr.h:4057
Optional< unsigned > getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce...
ObjCMethodDecl * getSetterMethodDecl() const
Definition: DeclObjC.h:925
NamedDecl * getFriendDecl() const
If this friend declaration doesn&#39;t name a type, return the inner declaration.
Definition: DeclFriend.h:139
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class. ...
Definition: DeclObjC.h:1311
TagDecl * getOwnedTagDecl() const
Return the (re)declaration of this type owned by this occurrence of this type, or nullptr if there is...
Definition: Type.h:5179
bool isInIdentifierNamespace(unsigned NS) const
Definition: DeclBase.h:796
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
DeclarationName getCXXDestructorName(CanQualType Ty)
Returns the name of a C++ destructor for the given Type.
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)
Definition: Expr.cpp:406
ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E)
int Category
Definition: Format.cpp:1632
TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, UnresolvedSetIterator End) const
Retrieve the template name that corresponds to a non-empty lookup.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition: Expr.h:1003
ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E)
Represents a C++ member access expression for which lookup produced a set of overloaded functions...
Definition: ExprCXX.h:3538
protocol_iterator protocol_end() const
Definition: DeclObjC.h:1381
ExpectedStmt VisitWhileStmt(WhileStmt *S)
ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E)
ExpectedType VisitDecayedType(const DecayedType *T)
const DeclGroupRef getDeclGroup() const
Definition: Stmt.h:1161
Expr * getSubExpr()
Definition: Expr.h:3050
Represents an access specifier followed by colon &#39;:&#39;.
Definition: DeclCXX.h:132
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:739
void startDefinition()
Starts the definition of this Objective-C protocol.
Definition: DeclObjC.cpp:1916
ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D)
SourceLocation getQuestionLoc() const
Definition: Expr.h:3571
void addShadowDecl(UsingShadowDecl *S)
Definition: DeclCXX.cpp:2711
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, bool DependentLambda, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
Definition: DeclCXX.cpp:140
bool isGnuLocal() const
Definition: Decl.h:496
SourceLocation getTemplateLoc() const
Definition: DeclTemplate.h:172
ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E)
void setSubStmt(Stmt *S)
Definition: Stmt.h:1518
ExpectedStmt VisitUnaryOperator(UnaryOperator *E)
LambdaCaptureDefault getCaptureDefault() const
Determine the default capture kind for this lambda.
Definition: ExprCXX.h:1720
unsigned getIndex() const
Retrieve the index into its type parameter list.
Definition: DeclObjC.h:615
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: ExprCXX.h:2801
QualType getParamTypeForDecl() const
Definition: TemplateBase.h:269
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition: ExprCXX.h:3030
IdentifierTable & Idents
Definition: ASTContext.h:566
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:6091
bool hadArrayRangeDesignator() const
Definition: Expr.h:4353
SourceLocation getCatchLoc() const
Definition: StmtCXX.h:49
ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E)
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2262
ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E)
Represents Objective-C&#39;s @catch statement.
Definition: StmtObjC.h:74
SourceLocation getComposedLoc(FileID FID, unsigned Offset) const
Form a SourceLocation from a FileID and Offset pair.
ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E)
SourceLocation getBeginLoc() const
Definition: ExprCXX.h:3741
TypeAliasDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
IndirectGotoStmt - This represents an indirect goto.
Definition: Stmt.h:2339
SourceLocation getMemberLoc() const
Definition: ExprCXX.h:3434
ExpectedDecl VisitVarDecl(VarDecl *D)
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr *> Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition: Expr.cpp:4051
Describes an C or C++ initializer list.
Definition: Expr.h:4185
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition: ExprCXX.h:669
Represents a C++ using-declaration.
Definition: DeclCXX.h:3352
bool isInvalid() const
SourceLocation getIvarRBraceLoc() const
Definition: DeclObjC.h:2698
Expr * getArraySize()
Definition: ExprCXX.h:2040
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2738
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
UnresolvedUsingTypenameDecl * getDecl() const
Definition: Type.h:4132
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
SourceLocation getEndLoc() const
Definition: ExprCXX.h:3742
ExpectedDecl VisitTypedefDecl(TypedefDecl *D)
void completeDefinition() override
Indicates that the definition of this class is now complete.
Definition: DeclCXX.cpp:1793
ForStmt - This represents a &#39;for (init;cond;inc)&#39; stmt.
Definition: Stmt.h:2237
Represents the results of name lookup.
Definition: Lookup.h:47
A qualified template name, where the qualification is kept to describe the source code as written...
Definition: TemplateName.h:199
unsigned getFirstExprIndex() const
Definition: Expr.h:4589
static IfStmt * Create(const ASTContext &Ctx, SourceLocation IL, bool IsConstexpr, Stmt *Init, VarDecl *Var, Expr *Cond, Stmt *Then, SourceLocation EL=SourceLocation(), Stmt *Else=nullptr)
Create an IfStmt.
Definition: Stmt.cpp:841
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:2731
FunctionDecl * getOperatorDelete() const
Definition: ExprCXX.h:2210
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
bool isElidable() const
Whether this construction is elidable.
Definition: ExprCXX.h:1340
Expr * getOperand() const
Definition: ExprCXX.h:3739
const Expr * getThrowExpr() const
Definition: StmtObjC.h:325
Error ImportDefinition(RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind=IDK_Default)
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition: DeclCXX.h:2378
ExpectedStmt VisitInitListExpr(InitListExpr *E)
TagKind getTagKind() const
Definition: Decl.h:3243
Namespaces, declared with &#39;namespace foo {}&#39;.
Definition: DeclBase.h:141
bool isGlobalNew() const
Definition: ExprCXX.h:2074
void setCXXOperatorNameRange(SourceRange R)
setCXXOperatorNameRange - Sets the range of the operator name (without the operator keyword)...
A convenient class for passing around template argument information.
Definition: TemplateBase.h:555
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion: ...
Definition: Decl.h:1624
ExpectedType VisitPointerType(const PointerType *T)
const FileInfo & getFile() const
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
void setRange(SourceRange R)
Definition: Attr.h:96
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition: ExprCXX.h:2206
LabelDecl * getDecl() const
Definition: Stmt.h:1610
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
SourceLocation getLBracLoc() const
Definition: Stmt.h:1333
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:3354
ArrayRef< NamedDecl * > chain() const
Definition: Decl.h:2847
SourceLocation getRParenLoc() const
Definition: StmtCXX.h:197
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
Definition: TemplateBase.h:275
Expr * getInitializer()
The initializer of this new-expression.
Definition: ExprCXX.h:2090
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:405
path_iterator path_begin()
Definition: Expr.h:3070
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Definition: Stmt.cpp:1080
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: ExprCXX.h:2760
Stmt * getBody()
Definition: Stmt.h:2271
ExpectedDecl VisitEnumDecl(EnumDecl *D)
PropertyAttributeKind getPropertyAttributes() const
Definition: DeclObjC.h:840
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D)
ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E)
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:2901
Error ImportDeclContext(DeclContext *FromDC, bool ForceImport=false)
Represents a typeof (or typeof) expression (a GCC extension).
Definition: Type.h:4176
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3287
Expected< FunctionDecl * > FindFunctionTemplateSpecialization(FunctionDecl *FromFD)
ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S)
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition: Decl.h:753
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum...
Definition: Decl.h:3506
bool constructsVBase() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition: ExprCXX.h:1487
ExpectedType VisitUnaryTransformType(const UnaryTransformType *T)
void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl)
Set the mangling number and context declaration for a lambda class.
Definition: DeclCXX.h:1922
tokloc_iterator tokloc_end() const
Definition: Expr.h:1737
Stmt * getInit()
Definition: Stmt.h:2250
ExpectedStmt VisitSwitchStmt(SwitchStmt *S)
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt *> Stmts, SourceLocation LB, SourceLocation RB)
Definition: Stmt.cpp:332
iterator begin()
Definition: DeclGroup.h:100
ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E)
ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E)
SourceLocation getThrowLoc() const
Definition: ExprCXX.h:1040
const StringLiteral * getInputConstraintLiteral(unsigned i) const
Definition: Stmt.h:2802
const Type * getClass() const
Definition: Type.h:2790
CXXForRangeStmt - This represents C++0x [stmt.ranged]&#39;s ranged for statement, represented as &#39;for (ra...
Definition: StmtCXX.h:127
ExpectedType VisitFunctionProtoType(const FunctionProtoType *T)
Error ImportInitializer(VarDecl *From, VarDecl *To)
CXXRecordDecl * getDecl() const
Definition: Type.cpp:3255
bool isArrow() const
Definition: Expr.h:2874
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1382
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition: Decl.cpp:3469
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Definition: DeclObjC.h:2210
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the &#39;=&#39; that precedes the initializer value itself, if present.
Definition: Expr.h:4644
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:3454
void setSpecializationKind(TemplateSpecializationKind TSK)
Expr * getSizeExpr() const
Definition: Type.h:2991
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6072
ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE)
const TemplateArgument * getArgs() const
Retrieve the template arguments.
Definition: Type.h:4907
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E)
bool isNull() const
Definition: DeclGroup.h:80
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1158
CaseStmt - Represent a case statement.
Definition: Stmt.h:1394
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition: Decl.h:1660
Expr * getCond()
Definition: Stmt.h:2269
void setTrivial(bool IT)
Definition: Decl.h:2027
SourceLocation getContinueLoc() const
Definition: Stmt.h:2393
const Expr * getInitExpr() const
Definition: Decl.h:2805
SourceLocation getPropertyIvarDeclLoc() const
Definition: DeclObjC.h:2830
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:2998
FieldDecl * getField()
Get the field whose initializer will be used.
Definition: ExprCXX.h:1158
Helper class for OffsetOfExpr.
Definition: Expr.h:2013
SourceLocation getExternLoc() const
Definition: DeclCXX.h:2874
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2064
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1217
bool IsStructurallyEquivalent(QualType From, QualType To, bool Complain=true)
Determine whether the given types are structurally equivalent.
ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E)
StringLiteral * getClobberStringLiteral(unsigned i)
Definition: Stmt.h:2836
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
Definition: DeclBase.h:821
TemplateTemplateParmDecl * getParameter() const
Definition: TemplateName.h:339
SourceLocation getBuiltinLoc() const
Definition: Expr.h:4120
CXXTemporary * getTemporary()
Definition: ExprCXX.h:1236
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1649
CXXRecordDecl * getNamingClass()
Gets the &#39;naming class&#39; (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition: ExprCXX.h:2904
ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S)
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value &#39;V&#39; and type &#39;type&#39;.
Definition: Expr.cpp:792
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name, with source-location information.
Definition: Expr.h:1133
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:2177
ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E)
PropertyControl getPropertyImplementation() const
Definition: DeclObjC.h:933
const TemplateArgument * data() const
Retrieve a pointer to the template argument list.
Definition: DeclTemplate.h:273
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition: ExprCXX.h:2985
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization, retrieves the function from which it was instantiated.
Definition: Decl.cpp:3332
void log(raw_ostream &OS) const override
Definition: ASTImporter.cpp:98
ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D)
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition: ExprCXX.h:3284
ExpectedStmt VisitReturnStmt(ReturnStmt *S)
Represents an ObjC class declaration.
Definition: DeclObjC.h:1172
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
Definition: Stmt.cpp:902
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition: DeclCXX.h:2392
ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E)
Represents a linkage specification.
Definition: DeclCXX.h:2826
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition: Expr.h:1930
QualType getReturnType() const
Definition: DeclObjC.h:323
SourceLocation getIncludeLoc() const
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
Definition: ExprCXX.cpp:325
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition: Type.h:3753
ExpectedStmt VisitLambdaExpr(LambdaExpr *LE)
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization, retrieves the member specialization information.
Definition: Decl.cpp:3339
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:1891
ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T)
Stmt * getBody()
Definition: Stmt.h:1958
Ordinary names.
Definition: DeclBase.h:145
Expr * getSizeExpr() const
Definition: Type.h:3048
Stmt * getInit()
Definition: Stmt.h:1830
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1073
void setMethodParams(ASTContext &C, ArrayRef< ParmVarDecl *> Params, ArrayRef< SourceLocation > SelLocs=llvm::None)
Sets the method&#39;s parameters and selector source locations.
Definition: DeclObjC.cpp:887
bool isExact() const
Definition: Expr.h:1485
QualType getPointeeTypeAsWritten() const
Definition: Type.h:2692
SourceLocation getAtStartLoc() const
Definition: DeclObjC.h:1115
ExpectedStmt VisitParenExpr(ParenExpr *E)
Import the default subset of the definition, which might be nothing (if minimal import is set) or mig...
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
Definition: DeclBase.cpp:1515
ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D)
ASTContext & getToContext() const
Retrieve the context that AST nodes are being imported into.
Definition: ASTImporter.h:397
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition: Decl.h:3666
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:3418
Represents the this expression in C++.
Definition: ExprCXX.h:976
ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, ASTContext &FromContext, FileManager &FromFileManager, bool MinimalImport, ASTImporterLookupTable *LookupTable=nullptr)
ExpectedStmt VisitIfStmt(IfStmt *S)
ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D)
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (&#39;)&#39;) that follows the argument list.
Definition: ExprCXX.h:3217
TypeSourceInfo * getAllocatedTypeSourceInfo() const
Definition: ExprCXX.h:2012
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name...
Definition: Expr.h:2792
Class that aids in the construction of nested-name-specifiers along with source-location information ...
SourceLocation getRParenLoc() const
Definition: DeclCXX.h:3777
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition: ExprCXX.h:2557
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:443
void getSelectorLocs(SmallVectorImpl< SourceLocation > &SelLocs) const
Definition: DeclObjC.cpp:881
bool isArrayForm() const
Definition: ExprCXX.h:2197
const ObjCAtCatchStmt * getCatchStmt(unsigned I) const
Retrieve a @catch statement.
Definition: StmtObjC.h:206
Represents a K&R-style &#39;int foo()&#39; function, which has no information available about its arguments...
Definition: Type.h:3650
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition: DeclObjC.h:2759
SourceLocation getEllipsisLoc() const
Definition: Expr.h:4583
Decl * MapImported(Decl *From, Decl *To)
Store and assign the imported declaration to its counterpart.
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition: DeclCXX.h:2869
ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E)
const FileEntry * getFile(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition: Decl.cpp:4001
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:3582
QualType getBaseType() const
Gets the base type of this object type.
Definition: Type.h:5601
const ValueDecl * getExtendingDecl() const
Get the declaration which triggered the lifetime-extension of this temporary, if any.
Definition: ExprCXX.h:4219
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:1610
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition: ExprCXX.h:1364
RecordDecl * getMostRecentDecl()
Definition: Decl.h:3640
CXXRecordDecl * getMostRecentDecl()
Definition: DeclCXX.h:745
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition: ExprCXX.h:2286
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3038
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1043
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1241
ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E)
void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3687
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
Definition: Decl.h:1194
bool isMicrosoftABI() const
Returns whether this is really a Win64 ABI va_arg expression.
Definition: Expr.h:4114
ExpectedDecl VisitImportDecl(ImportDecl *D)
ExpectedType VisitTypeOfExprType(const TypeOfExprType *T)
Expr ** getSubExprs()
Definition: Expr.h:5500
friend class ASTNodeImporter
Definition: ASTImporter.h:84
This declaration is a C++ operator declared in a non-class context.
Definition: DeclBase.h:169
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition: ExprCXX.h:1334
Objective C @protocol.
Definition: DeclBase.h:148
QualType getComputationLHSType() const
Definition: Expr.h:3527
SourceLocation getTypenameLoc() const
Returns the source location of the &#39;typename&#39; keyword.
Definition: DeclCXX.h:3699
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
Definition: DeclCXX.cpp:1627
CastKind
CastKind - The kind of operation required for a conversion.
qual_range quals() const
Definition: Type.h:5438
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition: Decl.h:3472
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition: DeclCXX.h:2353
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat)
Definition: Expr.cpp:1844
ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E)
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:569
A dependent template name that has not been resolved to a template (or set of templates).
Definition: TemplateName.h:203
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:2099
ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E)
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand...
Definition: Expr.h:2222
bool isValid() const
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
SourceLocation getTryLoc() const
Definition: StmtCXX.h:91
bool isConstexpr() const
Definition: Stmt.h:1860
SourceLocation getLocation() const
Definition: ExprCXX.h:1336
SourceLocation getLocation() const
Definition: Expr.h:1122
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this category.
Definition: DeclObjC.cpp:2029
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclObjC.cpp:980
ArrayRef< TypeSourceInfo * > getArgs() const
Retrieve the argument types.
Definition: ExprCXX.h:2488
ConstantExpr - An expression that occurs in a constant context.
Definition: Expr.h:904
ImportDefinitionKind
What we should import from the definition.
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param)
Definition: ExprCXX.h:1096
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:4091
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:264
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:2966
ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S)
SourceLocation getLabelLoc() const
Definition: Stmt.h:2322
void setInClassInitializer(Expr *Init)
Set the C++11 in-class initializer for this member.
Definition: Decl.h:2731
This declaration is a friend class.
Definition: DeclBase.h:158
bool isImplicitAccess() const
True if this is an implicit access, i.e.
Definition: ExprCXX.h:3374
SourceLocation getThrowLoc() const LLVM_READONLY
Definition: StmtObjC.h:329
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
static unsigned getNumSubExprs(AtomicOp Op)
Determine the number of arguments the specified atomic builtin should have.
Definition: Expr.cpp:4189
unsigned getValue() const
Definition: Expr.h:1426
static NestedNameSpecifier * SuperSpecifier(const ASTContext &Context, CXXRecordDecl *RD)
Returns the nested name specifier representing the __super scope for the given CXXRecordDecl.
ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E)
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:3026
SourceLocation getDestroyedTypeLoc() const
Retrieve the starting location of the type being destroyed.
Definition: ExprCXX.h:2394
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:190
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:432
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringKind 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:983
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type...
Definition: ExprCXX.h:1871
ADLCallKind getADLCallKind() const
Definition: Expr.h:2518
SourceLocation getOperatorLoc() const
Retrieve the location of the &#39;->&#39; or &#39;.&#39; operator.
Definition: ExprCXX.h:3637
Expr * getCond() const
Definition: Expr.h:3616
QualType getInjectedSpecializationType() const
Retrieves the injected specialization type for this partial specialization.
QualType getElementType() const
Definition: Type.h:2490
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr *> Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
Definition: Expr.cpp:1283
Error ImportTemplateArgumentListInfo(const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo)
void setGetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:923
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition: Decl.h:2342
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function)...
ExpectedType VisitInjectedClassNameType(const InjectedClassNameType *T)
unsigned getNumArgs() const
Retrieve the number of template arguments.
Definition: Type.h:5299
unsigned getFunctionScopeDepth() const
Definition: Decl.h:1597
llvm::MutableArrayRef< Designator > designators()
Definition: Expr.h:4622
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
DeclAccessPair getFoundDecl() const
Retrieves the declaration found by lookup.
Definition: Expr.h:2777
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:637
This represents one expression.
Definition: Expr.h:106
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition: DeclCXX.h:3392
Defines the clang::LangOptions interface.
SourceLocation getElseLoc() const
Definition: Stmt.h:1849
DeclStmt * getEndStmt()
Definition: StmtCXX.h:158
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:1611
unsigned getChainingSize() const
Definition: Decl.h:2853
SourceLocation getAliasLoc() const
Returns the location of the alias name, i.e.
Definition: DeclCXX.h:3106
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:107
Selector getSetterName() const
Definition: DeclObjC.h:914
SourceLocation getCaptureDefaultLoc() const
Retrieve the location of this lambda&#39;s capture-default, if any.
Definition: ExprCXX.h:1725
IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition: Expr.cpp:1493
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition: Expr.h:2087
bool isArrow() const
Determine whether this member expression used the &#39;->&#39; operator; otherwise, it used the &#39;...
Definition: ExprCXX.h:3634
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3523
TypeSourceInfo * getSuperClassTInfo() const
Definition: DeclObjC.h:1573
Declaration of a template type parameter.
void setSetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:926
SourceLocation getDefaultLoc() const
Definition: Stmt.h:1559
unsigned getIndex() const
Definition: Type.h:4566
FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, unsigned LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
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:1435
SourceLocation getWhileLoc() const
Definition: Stmt.h:2164
TypeSourceInfo * getTypeSourceInfo() const
Definition: DeclObjC.h:827
DeclarationNameInfo getNameInfo() const
Definition: DeclCXX.h:3399
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Definition: ExprCXX.h:3921
void setSyntacticForm(InitListExpr *Init)
Definition: Expr.h:4346
ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D)
Represents a C++ functional cast expression that builds a temporary object.
Definition: ExprCXX.h:1581
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:68
ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T)
SourceLocation getLocation() const
Definition: ExprCXX.h:991
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:87
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2706
bool hasRelatedResultType() const
Determine whether this method has a result type that is related to the message receiver&#39;s type...
Definition: DeclObjC.h:257
void setInit(Expr *I)
Definition: Decl.cpp:2205
SourceLocation createMacroArgExpansionLoc(SourceLocation Loc, SourceLocation ExpansionLoc, unsigned TokLength)
Return a new SourceLocation that encodes the fact that a token from SpellingLoc should actually be re...
VarDecl * getExceptionDecl() const
Definition: StmtCXX.h:50
IdentifierInfo * getDestroyedTypeIdentifier() const
In a dependent pseudo-destructor expression for which we do not have full type information on the des...
Definition: ExprCXX.h:2386
Expr * getCallee()
Definition: Expr.h:2514
unsigned getNumInits() const
Definition: Expr.h:4215
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
Definition: DeclObjC.h:2221
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:547
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition: Expr.h:4825
SourceLocation getBeginLoc() const
Definition: Expr.h:1828
void setRBraceLoc(SourceLocation L)
Definition: DeclCXX.h:2877
const char * getTypeClassName() const
Definition: Type.cpp:2646
LookupResult lookup(DeclContext *DC, DeclarationName Name) const
static CXXStaticCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:688
ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D)
bool isArrow() const
Determine whether this pseudo-destructor expression was written using an &#39;->&#39; (otherwise, it used a &#39;.
Definition: ExprCXX.h:2349
Stmt * getBody()
Definition: Stmt.h:2124
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
overridden_method_range overridden_methods() const
Definition: DeclCXX.cpp:2170
ExpectedStmt VisitGotoStmt(GotoStmt *S)
arg_range arguments()
Definition: ExprCXX.h:1394
const CompoundStmt * getSynchBody() const
Definition: StmtObjC.h:282
DeclContext * getDeclContext()
Definition: DeclBase.h:427
SourceLocation getLParenLoc() const
Definition: Expr.h:4964
A structure for storing the information associated with a substituted template template parameter...
Definition: TemplateName.h:326
Expr * getRHS()
Definition: Stmt.h:1495
CXXRecordDecl * getDefinition() const
Definition: DeclCXX.h:769
QualType getBaseType() const
Definition: Type.h:4315
ExpectedType VisitTypedefType(const TypedefType *T)
lookup_result noload_lookup(DeclarationName Name)
Find the declarations with the given name that are visible within this context; don&#39;t attempt to retr...
Definition: DeclBase.cpp:1660
void setBody(Stmt *Body)
Definition: Stmt.h:1963
const IdentifierInfo * getIdentifier() const
Retrieve the type named by the typename specifier as an identifier.
Definition: Type.h:5238
Represents Objective-C&#39;s @synchronized statement.
Definition: StmtObjC.h:262
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:338
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:1350
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
TypeSourceInfo * getTypeSourceInfo() const
Definition: Expr.h:2159
NestedNameSpecifierLoc getPrefix() const
Return the prefix of this nested-name-specifier.
static ObjCTypeParamList * create(ASTContext &ctx, SourceLocation lAngleLoc, ArrayRef< ObjCTypeParamDecl *> typeParams, SourceLocation rAngleLoc)
Create a new Objective-C type parameter list.
Definition: DeclObjC.cpp:1434
unsigned size() const
Returns the number of designators in this initializer.
Definition: Expr.h:4619
Represents an expression that computes the length of a parameter pack.
Definition: ExprCXX.h:3844
ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E)
CXXTryStmt - A C++ try block, including all handlers.
Definition: StmtCXX.h:65
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:2331
SourceLocation getAtTryLoc() const
Retrieve the location of the @ in the @try.
Definition: StmtObjC.h:193
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Definition: Expr.h:1239
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition: Expr.cpp:848
Represents a C++ template name within the type system.
Definition: TemplateName.h:179
Represents the type decltype(expr) (C++11).
Definition: Type.h:4246
ArrayTypeTrait getTrait() const
Definition: ExprCXX.h:2553
EnumDecl * getDefinition() const
Definition: Decl.h:3427
Defines the clang::TypeLoc interface and its subclasses.
bool isIdentifier() const
Determine whether this template name refers to an identifier.
Definition: TemplateName.h:482
A namespace alias, stored as a NamespaceAliasDecl*.
ParmVarDecl *const * param_iterator
Definition: DeclObjC.h:344
llvm::Expected< QualType > Import_New(QualType FromT)
Import the given type from the "from" context into the "to" context.
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:1399
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1389
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition: Decl.cpp:3527
unsigned size() const
Definition: Stmt.h:1269
llvm::SmallVector< Decl *, 2 > getCanonicalForwardRedeclChain(Decl *D)
ArrayRef< Expr * > inits()
Definition: Expr.h:4225
ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E)
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn&#39;t...
void setImplementation(ObjCImplementationDecl *ImplD)
Definition: DeclObjC.cpp:1562
void setConstexpr(bool IC)
Definition: Decl.h:1385
SourceRange getAngleBrackets() const LLVM_READONLY
Definition: ExprCXX.h:307
ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E)
ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D)
Kind getKind() const
Determine what kind of offsetof node this is.
Definition: Expr.h:2067
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: Expr.h:2815
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition: Decl.cpp:2695
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
QualType getType() const
Definition: Expr.h:128
bool isFunctionOrMethod() const
Definition: DeclBase.h:1800
A unary type transform, which is a type constructed from another.
Definition: Type.h:4289
std::error_code convertToErrorCode() const override
ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D)
ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E)
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
Get the name of the overloadable C++ operator corresponding to Op.
static LambdaExpr * Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, ArrayRef< LambdaCapture > Captures, bool ExplicitParams, bool ExplicitResultType, ArrayRef< Expr *> CaptureInits, SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack)
Construct a new lambda expression.
Definition: ExprCXX.cpp:1128
SourceLocation getSwitchLoc() const
Definition: Stmt.h:2019
Declaration of an alias template.
LabelDecl * getLabel() const
Definition: Stmt.h:2317
const Stmt * getTryBody() const
Retrieve the @try body.
Definition: StmtObjC.h:197
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, IdentKind IK, StringLiteral *SL)
Create a PredefinedExpr.
Definition: Expr.cpp:497
ReturnStmt - This represents a return, optionally of an expression: return; return 4;...
Definition: Stmt.h:2443
void setPointOfInstantiation(SourceLocation Loc)
SourceLocation getDoLoc() const
Definition: Stmt.h:2214
SwitchCase * getSwitchCaseList()
Definition: Stmt.h:2015
SourceLocation getAtLoc() const
Definition: StmtObjC.h:365
SourceLocation getLBracketLoc() const
Definition: Expr.h:4571
SourceLocation getRBracketLoc() const
Definition: Expr.h:2366
SourceLocation getEnd() const
UnaryOperator - This represents the unary-expression&#39;s (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
Definition: Expr.h:1896
bool isInstanceMethod() const
Definition: DeclObjC.h:422
Represents a GCC generic vector type.
Definition: Type.h:3168
ArraySizeModifier getSizeModifier() const
Definition: Type.h:2849
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
Definition: Expr.h:4649
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:2615
ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S)
AtomicOp getOp() const
Definition: Expr.h:5497
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization, retrieves the member specialization information.
Definition: DeclCXX.cpp:1605
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2720
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
static WhileStmt * Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body, SourceLocation WL)
Create a while statement.
Definition: Stmt.cpp:1005
UTTKind getUTTKind() const
Definition: Type.h:4317
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:3958
bool isBaseOfClass() const
Determine whether this base class is a base of a class declared with the &#39;class&#39; keyword (vs...
Definition: DeclCXX.h:249
const OffsetOfNode & getComponent(unsigned Idx) const
Definition: Expr.h:2166
unsigned getNumArgs() const
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Definition: Expr.h:3707
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: Expr.h:1167
Expr * getCond()
Definition: Stmt.h:1762
ValueDecl * getDecl()
Definition: Expr.h:1114
ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E)
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition: DeclCXX.cpp:1623
SourceLocation getRParenLoc() const
Definition: Expr.h:4123
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2768
ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E)
The result type of a method or function.
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition: Decl.h:2026
SourceLocation getForLoc() const
Definition: StmtObjC.h:53
const Expr * getSubExpr() const
Definition: Expr.h:1860
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclObjC.h:2815
const Expr * getSubExpr() const
Definition: ExprCXX.h:1240
SourceLocation getPackLoc() const
Determine the location of the parameter pack.
Definition: ExprCXX.h:3909
CXXMethodDecl * getCallOperator() const
Retrieve the function call operator associated with this lambda expression.
Definition: ExprCXX.cpp:1200
ExpectedStmt VisitStringLiteral(StringLiteral *E)
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:703
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Definition: Expr.h:2347
QualType getType() const
Definition: DeclObjC.h:829
bool getValue() const
Definition: ExprCXX.h:574
bool hadMultipleCandidates() const
Returns true if this expression refers to a function that was resolved from an overloaded set having ...
Definition: Expr.h:1227
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:1861
ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E)
virtual ~ASTImporter()
const ExpansionInfo & getExpansion() const
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1...
Definition: Expr.h:1517
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl *> Params, SourceLocation RAngleLoc, Expr *RequiresClause)
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so...
Definition: DeclBase.h:1104
Expr * getUnderlyingExpr() const
Definition: Type.h:4185
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Definition: Redeclarable.h:216
ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S)
ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E)
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:1363
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:412
DoStmt - This represents a &#39;do/while&#39; stmt.
Definition: Stmt.h:2185
SourceLocation getOperatorLoc() const
Retrieve the location of the &#39;->&#39; or &#39;.&#39; operator.
Definition: ExprCXX.h:3394
AttrVec & getAttrs()
Definition: DeclBase.h:479
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
bool hasAttrs() const
Definition: DeclBase.h:473
TypeSourceInfo * getAsTypeSourceInfo() const
Definition: TemplateBase.h:426
ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E)
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses (&#39;(&#39;) that precedes the argument list.
Definition: ExprCXX.h:3212
TypeSourceInfo * getReturnTypeSourceInfo() const
Definition: DeclObjC.h:337
RecordDecl * getDecl() const
Definition: Type.h:4380
bool capturesVariable() const
Determine whether this capture handles a variable.
Definition: LambdaCapture.h:89
SpecifierKind
The kind of specifier that completes this nested name specifier.
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition: ExprCXX.h:2982
Expr * getArgument()
Definition: ExprCXX.h:2212
ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E)
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:434
ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E)
SourceLocation getExpansionLocEnd() const
SourceLocation getUsingLoc() const
Return the location of the using keyword.
Definition: DeclCXX.h:2987
void setTypeForDecl(const Type *TD)
Definition: Decl.h:2899
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:389
A template template parameter pack that has been substituted for a template template argument pack...
Definition: TemplateName.h:212
CanThrowResult
Possible results from evaluation of a noexcept expression.
SourceLocation getUsingLoc() const
Returns the source location of the &#39;using&#39; keyword.
Definition: DeclCXX.h:3603
Error ImportContainerChecked(const InContainerTy &InContainer, OutContainerTy &OutContainer)
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond)
Create a switch statement.
Definition: Stmt.cpp:947
bool getValue() const
Definition: ExprCXX.h:3745
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
Definition: Expr.h:945
OverloadedTemplateStorage * getAsOverloadedTemplate() const
Retrieve the underlying, overloaded function template.
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
Definition: DeclBase.cpp:1785
#define false
Definition: stdbool.h:33
TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, const IdentifierInfo *Name) const
Retrieve the template name that represents a dependent template name such as MetaFun::template apply...
SourceLocation getLParenLoc() const
Definition: Expr.h:2958
SelectorTable & Selectors
Definition: ASTContext.h:567
ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D)
static CXXConstCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, Expr *Op, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:795
Kind
static CXXBindTemporaryExpr * Create(const ASTContext &C, CXXTemporary *Temp, Expr *SubExpr)
Definition: ExprCXX.cpp:924
A field in a dependent type, known only by its name.
Definition: Expr.h:2022
ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E)
QualType getCanonicalType() const
Definition: Type.h:6111
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1448
ExpectedDecl VisitEmptyDecl(EmptyDecl *D)
ExpressionTrait getTrait() const
Definition: ExprCXX.h:2617
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:3743
TypeLoc IgnoreParens() const
Definition: TypeLoc.h:1127
param_type_range param_types() const
Definition: Type.h:4030
IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:5090
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:3899
const ContentCache * getContentCache() const
static CXXNewExpr * Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef< Expr *> PlacementArgs, SourceRange TypeIdParens, Expr *ArraySize, InitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange)
Create a c++ new expression.
Definition: ExprCXX.cpp:179
void setKNRPromoted(bool promoted)
Definition: Decl.h:1627
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis for a capture that is a pack expansion.
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:2100
SourceLocation getNameLoc() const
Gets the location of the name.
Definition: ExprCXX.h:2747
bool inheritedFromVBase() const
Determine whether the inherited constructor is inherited from a virtual base of the object we constru...
Definition: ExprCXX.h:1497
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: Expr.h:2823
StringLiteral * getFunctionName()
Definition: Expr.h:1813
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition: Expr.h:4945
ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E)
ExpectedType VisitRecordType(const RecordType *T)
void MakeSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into &#39;__super&#39; nested-name-specifier.
bool isParameterPack() const
Returns whether this is a parameter pack.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Encodes a location in the source.
bool getSynthesize() const
Definition: DeclObjC.h:1991
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
Definition: Type.h:5751
body_range body()
Definition: Stmt.h:1274
Sugar for parentheses used when specifying types.
Definition: Type.h:2507
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:2551
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
QualType getReturnType() const
Definition: Type.h:3613
bool isPure() const
Whether this virtual function is pure, i.e.
Definition: Decl.h:2009
Expr * getRetValue()
Definition: Stmt.h:2476
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Definition: Type.h:4396
SourceLocation getOperatorLoc() const
Definition: Expr.h:3319
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2353
const Stmt * getCatchBody() const
Definition: StmtObjC.h:90
static DependentScopeDeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:477
unsigned getNumHandlers() const
Definition: StmtCXX.h:103
SourceLocation createExpansionLoc(SourceLocation Loc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned TokLength, bool ExpansionIsTokenRange=true, int LoadedID=0, unsigned LoadedOffset=0)
Return a new SourceLocation that encodes the fact that a token from SpellingLoc should actually be re...
Expr * getSubExpr() const
Definition: Expr.h:1926
SourceLocation getSuperClassLoc() const
Definition: DeclObjC.h:2691
Represents a C++ temporary.
Definition: ExprCXX.h:1185
bool hasExplicitTemplateArgs() const
Determines whether this member expression actually had a C++ template argument list explicitly specif...
Definition: ExprCXX.h:3465
Represents typeof(type), a GCC extension.
Definition: Type.h:4219
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:5738
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:3020
Attr * clone(ASTContext &C) const
NestedNameSpecifierLoc getQualifierLoc() const
Retrieves the nested-name-specifier that qualifies the type name, with source-location information...
Definition: ExprCXX.h:2338
SourceLocation getNamespaceKeyLocation() const
Returns the location of the namespace keyword.
Definition: DeclCXX.h:2991
ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D)
bool hasUnresolvedUsing() const
Determine whether the lookup results contain an unresolved using declaration.
Definition: ExprCXX.h:3628
CastKind getCastKind() const
Definition: Expr.h:3044
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
Definition: DeclObjC.h:2330
Expr * getSubExpr(unsigned Idx) const
Definition: Expr.h:4667
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:122
ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S)
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition: ExprCXX.h:300
ExpectedStmt VisitDeclStmt(DeclStmt *S)
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)"...
Definition: ExprCXX.h:1914
void setExternLoc(SourceLocation Loc)
Sets the location of the extern keyword.
Expr * getLHS()
Definition: Stmt.h:1483
ExpectedType VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T)
bool wasDeclaredWithTypename() const
Whether this template type parameter was declared with the &#39;typename&#39; keyword.
DeclarationName getName() const
getName - Returns the embedded declaration name.
static ConstantExpr * Create(const ASTContext &Context, Expr *E)
Definition: Expr.h:909
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3064
SourceLocation getUsingLoc() const
Return the source location of the &#39;using&#39; keyword.
Definition: DeclCXX.h:3385
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis that describes this pack expansion.
Definition: ExprCXX.h:3808
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, Optional< unsigned > Length=None, ArrayRef< TemplateArgument > PartialArgs=None)
Definition: ExprCXX.cpp:1504
SourceLocation getCategoryNameLoc() const
Definition: DeclObjC.h:2527
Represents a call to a member function that may be written either with member call syntax (e...
Definition: ExprCXX.h:171
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition: Decl.h:3055
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:376
llvm::iterator_range< capture_init_iterator > capture_inits()
Retrieve the initialization expressions for this lambda&#39;s captures.
Definition: ExprCXX.h:1783
static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, ASTImporter &Importer)
Stmt * getElse()
Definition: Stmt.h:1783
ObjCCategoryDecl * getCategoryDecl() const
Definition: DeclObjC.cpp:2064
QualType getElementType() const
Definition: Type.h:3203
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
Definition: Stmt.h:1143
ExpectedType VisitAutoType(const AutoType *T)
Represents the declaration of a label.
Definition: Decl.h:469
void setPropertyAttributesAsWritten(PropertyAttributeKind PRVal)
Definition: DeclObjC.h:856
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:2494
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3571
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:60
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition: DeclCXX.h:3613
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set...
Definition: Decl.h:2721
ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D)
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr *> exprs, SourceLocation RParenLoc)
Definition: Expr.cpp:1447
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2041
static ExprWithCleanups * Create(const ASTContext &C, EmptyShell empty, unsigned numObjects)
Definition: ExprCXX.cpp:1250
SourceLocation getFriendLoc() const
Retrieves the location of the &#39;friend&#39; keyword.
Definition: DeclFriend.h:144
bool shouldForceImportDeclContext(ImportDefinitionKind IDK)
Expr * getCond()
Definition: Stmt.h:1946
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:183
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Definition: Expr.h:1939
SourceLocation getRParenLoc() const
Definition: Expr.h:3826
Expr * getRequiresClause()
The constraint-expression of the associated requires-clause.
Definition: DeclTemplate.h:163
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition: DeclCXX.cpp:2145
SourceLocation getIdentLocation() const
Returns the location of this using declaration&#39;s identifier.
Definition: DeclCXX.h:2994
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:1492
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier &#39;::&#39;.
bool isBoundToLvalueReference() const
Determine whether this materialized temporary is bound to an lvalue reference; otherwise, it&#39;s bound to an rvalue reference.
Definition: ExprCXX.h:4232
bool isParameterPack() const
Definition: Type.h:4567
bool isPascal() const
Definition: Expr.h:1690
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition: DeclCXX.h:2961
ExpectedType VisitTemplateSpecializationType(const TemplateSpecializationType *T)
ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D)
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2280
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:360
QualType getInjectedClassNameSpecialization()
Retrieve the template specialization type of the injected-class-name for this class template...
QualType getEquivalentType() const
Definition: Type.h:4451
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the similarly-named C++11 instructions, and __c11 variants for <stdatomic.h>, and corresponding __opencl_atomic_* for OpenCL 2.0.
Definition: Expr.h:5433
unsigned capture_size() const
Determine the number of captures in this lambda.
Definition: ExprCXX.h:1750
UnaryExprOrTypeTrait getKind() const
Definition: Expr.h:2253
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition: DeclBase.h:2312
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3520
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:89
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
Definition: Expr.h:149
const TemplateArgumentListInfo & getTemplateArgsInfo() const
QualType getInnerType() const
Definition: Type.h:2520
SourceLocation getLParenLoc() const
Definition: Expr.h:3824
arg_range arguments()
Definition: Expr.h:2585
SourceLocation getGotoLoc() const
Definition: Stmt.h:2320
SourceLocation getAtFinallyLoc() const
Definition: StmtObjC.h:141
AccessSpecifier getAccess() const
ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E)
void setPointOfInstantiation(SourceLocation Loc)
StructuralEquivalenceKind
Whether to perform a normal or minimal equivalence check.
bool isMinimalImport() const
Whether the importer will perform a minimal import, creating to-be-completed forward declarations whe...
Definition: ASTImporter.h:167
ClassTemplateDecl * getMostRecentDecl()
const StringLiteral * getOutputConstraintLiteral(unsigned i) const
Definition: Stmt.h:2774
ExpectedStmt VisitContinueStmt(ContinueStmt *S)
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:729
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:2344
ASTNodeImporter(ASTImporter &Importer)
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3115
ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D)
ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D)
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:5166
SourceLocation getAtCatchLoc() const
Definition: StmtObjC.h:102
ExpectedType VisitParenType(const ParenType *T)
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:67
CharacterKind getKind() const
Definition: Expr.h:1419
bool hasUninstantiatedDefaultArg() const
Definition: Decl.h:1664
ExpectedDecl VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D)
AutoTypeKeyword getKeyword() const
Definition: Type.h:4764
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required...
Definition: DeclBase.cpp:397
virtual Decl * 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:425
TypeSourceInfo * getTypeAsWritten() const
Gets the type of this specialization as it was written by the user, if it was so written.
An expression trait intrinsic.
Definition: ExprCXX.h:2580
SourceLocation getRAngleLoc() const
Definition: DeclTemplate.h:174
SourceLocation getMemberLocation() const
Definition: DeclCXX.h:2412
bool isImplicitInterfaceDecl() const
isImplicitInterfaceDecl - check that this is an implicitly declared ObjCInterfaceDecl node...
Definition: DeclObjC.h:1893
EnumDecl * getDecl() const
Definition: Type.h:4403
ArrayRef< Expr * > exprs()
Definition: Expr.h:4960
DeclarationNameInfo getNameInfo() const
Definition: Decl.h:1901
ExpectedType VisitExtVectorType(const ExtVectorType *T)
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:3746
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
Definition: Stmt.cpp:965
Naming ambiguity (likely ODR violation).
Definition: ASTImporter.h:54
SourceLocation getExpansionLocStart() const
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:3801
SourceRange getBracketsRange() const
Definition: Type.h:3054
bool isArgumentType() const
Definition: Expr.h:2258
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: ExprCXX.h:3493
ObjCImplementationDecl * getImplementation() const
Definition: DeclObjC.cpp:1549
SourceLocation getRBraceLoc() const
Definition: DeclCXX.h:2875
Optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:5380
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition: Expr.h:4279
TypeSourceInfo * getTypeSourceInfo() const
Retrieves the type and source location of the base class.
Definition: DeclCXX.h:296
SourceLocation getStarLoc() const
Definition: Stmt.h:2357
void setHasInheritedDefaultArg(bool I=true)
Definition: Decl.h:1680
bool passAlignment() const
Indicates whether the required alignment should be implicitly passed to the allocation function...
Definition: ExprCXX.h:2108
void sawArrayRangeDesignator(bool ARD=true)
Definition: Expr.h:4356
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:595
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:772
FunctionDecl * getOperatorDelete() const
Definition: ExprCXX.h:2035
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.h:2614
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: ExprCXX.h:3004
SourceLocation getIvarLBraceLoc() const
Definition: DeclObjC.h:2417
static MemberExpr * Create(const ASTContext &C, Expr *base, bool isarrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *memberdecl, DeclAccessPair founddecl, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *targs, QualType ty, ExprValueKind VK, ExprObjectKind OK)
Definition: Expr.cpp:1539
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4149
Represents a pointer type decayed from an array or function type.
Definition: Type.h:2622
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:215
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:4978
ExpectedType VisitBuiltinType(const BuiltinType *T)
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:2942
void setVirtualAsWritten(bool V)
State that this function is marked as virtual explicitly.
Definition: Decl.h:2005
ExpectedType VisitEnumType(const EnumType *T)
const Expr * getInitializer() const
Definition: Expr.h:2951
ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E)
Represents a pack expansion of types.
Definition: Type.h:5355
InitializationStyle getInitializationStyle() const
The kind of initializer this new-expression has.
Definition: ExprCXX.h:2082
Expr * getLHS() const
Definition: Expr.h:3327
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:3504
SourceLocation getLocation() const LLVM_READONLY
Definition: ExprCXX.h:1499
Defines various enumerations that describe declaration and type specifiers.
A POD class for pairing a NamedDecl* with an access specifier.
ObjCDeclQualifier getObjCDeclQualifier() const
Definition: Decl.h:1607
ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E)
StringRef getName() const
Return the actual identifier string.
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition: Decl.h:3291
ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E)
ArrayRef< TemplateArgument > getPartialArguments() const
Get.
Definition: ExprCXX.h:3937
Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin)
void updateFlags(const Decl *From, Decl *To)
SourceRange getRange() const
Definition: Attr.h:95
ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S)
Error ImportTemplateArguments(const TemplateArgument *FromArgs, unsigned NumFromArgs, SmallVectorImpl< TemplateArgument > &ToArgs)
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition: Expr.h:3757
An Objective-C "bridged" cast expression, which casts between Objective-C pointers and C pointers...
Definition: ExprObjC.h:1575
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2916
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Represents a template argument.
Definition: TemplateBase.h:51
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition: Expr.h:3698
LabelStmt * getStmt() const
Definition: Decl.h:493
unsigned getManglingNumber() const
Definition: ExprCXX.h:4226
TypeSourceInfo * getDestroyedTypeInfo() const
Retrieve the source location information for the type being destroyed.
Definition: ExprCXX.h:2379
void setBody(Stmt *B)
Definition: Decl.cpp:2741
Expected< FunctionTemplateAndArgsTy > ImportFunctionTemplateWithTemplateArgsFromSpecialization(FunctionDecl *FromFD)
llvm::Expected< DeclContext * > ImportContext(DeclContext *FromDC)
Import the given declaration context from the "from" AST context into the "to" AST context...
static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls)
Definition: DeclGroup.h:69
SourceLocation getTemplateKeywordLoc() const
Gets the location of the template keyword, if present.
Represents a template name that was expressed as a qualified name.
Definition: TemplateName.h:367
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condnition evaluates to false;...
Definition: Expr.h:3714
protocol_iterator protocol_end() const
Definition: DeclObjC.h:2140
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition: Stmt.h:1210
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:2440
bool isTypeOperand() const
Definition: ExprCXX.h:709
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Definition: DeclCXX.cpp:2566
virtual void CompleteDecl(Decl *D)
Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl.
SourceLocation getLocation() const
Definition: ExprCXX.h:580
bool isNull() const
Determine whether this template name is NULL.
Dataflow Directional Tag Classes.
void setDescribedAliasTemplate(TypeAliasTemplateDecl *TAT)
Definition: Decl.h:3056
void setExtendingDecl(const ValueDecl *ExtendedBy, unsigned ManglingNumber)
Definition: ExprCXX.cpp:1564
TemplateName getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param, const TemplateArgument &ArgPack) const
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
bool isValid() const
Return true if this is a valid SourceLocation object.
bool isVolatile() const
Definition: Stmt.h:2556
ExpectedType VisitVectorType(const VectorType *T)
tokloc_iterator tokloc_begin() const
Definition: Expr.h:1733
ExpectedStmt VisitCallExpr(CallExpr *E)
ExtInfo getExtInfo() const
Definition: Type.h:3624
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
Definition: Stmt.cpp:1021
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:499
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1758
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition: Expr.h:2867
void setGetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:909
NestedNameSpecifier * getQualifier() const
Definition: Type.h:5290
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1262
ExpectedStmt VisitAtomicExpr(AtomicExpr *E)
Represents a delete expression for memory deallocation and destructor calls, e.g. ...
Definition: ExprCXX.h:2170
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:439
IdentifierInfo * getOutputIdentifier(unsigned i) const
Definition: Stmt.h:2763
PropertyAttributeKind getPropertyAttributesAsWritten() const
Definition: DeclObjC.h:852
bool isSimple() const
Definition: Stmt.h:2553
Kind getPropertyImplementation() const
Definition: DeclObjC.h:2823
ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D)
bool isInitKnownICE() const
Determines whether it is already known whether the initializer is an integral constant expression or ...
Definition: Decl.cpp:2317
const Stmt * getFinallyBody() const
Definition: StmtObjC.h:132
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:80
SourceLocation getAtLoc() const
Definition: DeclObjC.h:821
ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E)
const TemplateArgument * getArgs() const
Retrieve the template arguments.
Definition: Type.h:5294
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition: Decl.cpp:3558
ArrayRef< const Attr * > getAttrs() const
Definition: Stmt.h:1669
bool isImplicit() const
Definition: ExprCXX.h:997
attr_range attrs() const
Definition: DeclBase.h:490
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition: Stmt.cpp:1064
Represents a field injected from an anonymous union/struct into the parent scope. ...
Definition: Decl.h:2825
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...
QualType getUnderlyingType() const
Definition: Decl.h:2971
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition: DeclCXX.h:3084
ExpectedStmt VisitBinaryOperator(BinaryOperator *E)
DeclContext * getCommonAncestor()
Returns the common ancestor context of this using-directive and its nominated namespace.
Definition: DeclCXX.h:2983
TypeSourceInfo * getTypeSourceInfo() const
Retrieve the type source information for the type being constructed.
Definition: ExprCXX.h:3208
AccessSpecifier getAccess() const
Definition: DeclBase.h:462
const Expr * getInit() const
Definition: Decl.h:1220
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition: DeclObjC.h:1549
QualType getUnderlyingType() const
Definition: Type.h:4257
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration, or explicit instantiation definition.
LambdaCaptureKind getCaptureKind() const
Determine the kind of capture.
Definition: ExprCXX.cpp:1076
IdentifierNamespace
IdentifierNamespace - The different namespaces in which declarations may appear.
Definition: DeclBase.h:116
ExpectedType VisitType(const Type *T)
unsigned getIndex() const
Retrieve the index of the template parameter.
LLVM_NODISCARD llvm::Error importInto(ImportT &To, const ImportT &From)
Import the given object, returns the result.
Definition: ASTImporter.h:175
DeclarationName getMember() const
Retrieve the name of the member that this expression refers to.
Definition: ExprCXX.h:3430
SourceLocation getLBraceLoc() const
Definition: Expr.h:4330
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3667
SourceLocation getSemiLoc() const
Definition: Stmt.h:1221
The name of a declaration.
StmtClass getStmtClass() const
Definition: Stmt.h:1029
VectorKind getVectorKind() const
Definition: Type.h:3213
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:559
ArrayRef< QualType > exceptions() const
Definition: Type.h:4044
Expr * getDefaultArg()
Definition: Decl.cpp:2573
SourceRange getIntroducerRange() const
Retrieve the source range covering the lambda introducer, which contains the explicit capture list su...
Definition: ExprCXX.h:1819
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition: DeclCXX.h:3703
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:3516
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:3772
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition: ExprCXX.h:1353
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:1598
ExpectedType VisitConstantArrayType(const ConstantArrayType *T)
Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To)
Represents an enum.
Definition: Decl.h:3326
const Expr * getSynchExpr() const
Definition: StmtObjC.h:290
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:2756
ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D)
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:146
ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E)
ExpectedStmt VisitConstantExpr(ConstantExpr *E)
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:3190
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Tags, declared with &#39;struct foo;&#39; and referenced with &#39;struct foo&#39;.
Definition: DeclBase.h:126
void setInitializedFieldInUnion(FieldDecl *FD)
Definition: Expr.h:4303
A type that was preceded by the &#39;template&#39; keyword, stored as a Type*.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Definition: ASTContext.h:1083
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
Definition: TemplateBase.h:340
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
Definition: Type.h:4618
SourceLocation getSetterNameLoc() const
Definition: DeclObjC.h:915
ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D)
VarTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E)
void setObjectOfFriendDecl(bool PerformFriendInjection=false)
Changes the namespace of this declaration to reflect that it&#39;s the object of a friend declaration...
Definition: DeclBase.h:1064
TypeSourceInfo * getTypeOperandSourceInfo() const
Retrieve source information for the type operand.
Definition: ExprCXX.h:716
llvm::APInt getValue() const
Definition: Expr.h:1292
QualType getUnderlyingType() const
Definition: Type.h:4314
QualType getModifiedType() const
Definition: Type.h:4450
LabelDecl * getLabel() const
Definition: Expr.h:3779
path_iterator path_end()
Definition: Expr.h:3071
Represents a pointer to an Objective C object.
Definition: Type.h:5794
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition: ExprCXX.h:3719
SwitchStmt - This represents a &#39;switch&#39; stmt.
Definition: Stmt.h:1886
Pointer to a block type.
Definition: Type.h:2639
UsingDecl * getUsingDecl() const
Gets the using declaration to which this declaration is tied.
Definition: DeclCXX.cpp:2682
bool IsEquivalent(Decl *D1, Decl *D2)
Determine whether the two declarations are structurally equivalent.
SourceLocation getColonColonLoc() const
Retrieve the location of the &#39;::&#39; in a qualified pseudo-destructor expression.
Definition: ExprCXX.h:2367
SourceLocation getFieldLoc() const
Definition: Expr.h:4566
void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod)
SourceLocation getBeginLoc() const
Definition: ExprCXX.h:2221
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2552
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition: ExprCXX.h:2994
SourceLocation getRParenLoc() const
Definition: StmtObjC.h:55
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:3757
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4370
Complex values, per C99 6.2.5p11.
Definition: Type.h:2477
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:450
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition: DeclBase.h:562
unsigned getIndexTypeCVRQualifiers() const
Definition: Type.h:2857
unsigned getNumArgs() const
Retrieve the number of template arguments.
Definition: Type.h:4912
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition: Decl.h:1672
Expr * getUninstantiatedDefaultArg()
Definition: Decl.cpp:2615
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:3923
Imports selected nodes from one AST context into another context, merging AST nodes where appropriate...
Definition: ASTImporter.h:83
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2312
QualType getCanonicalTypeInternal() const
Definition: Type.h:2355
Represents Objective-C&#39;s collection statement.
Definition: StmtObjC.h:24
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2256
unsigned getNumObjects() const
Definition: ExprCXX.h:3120
IndirectFieldDecl * getIndirectMember() const
Definition: DeclCXX.h:2406
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:1771
SourceLocation getLocation() const
Retrieve the location of this expression.
Definition: Expr.h:975
SourceLocation getRParenLoc() const
Determine the location of the right parenthesis.
Definition: ExprCXX.h:3912
Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV)
Can create any sort of selector.
bool IsStructuralMatch(Decl *From, Decl *To, bool Complain)
static CStyleCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *BasePath, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation R)
Definition: Expr.cpp:1865
ExpectedType VisitAttributedType(const AttributedType *T)
An implicit indirection through a C++ base class, when the field found is in a base class...
Definition: Expr.h:2025
const llvm::APInt & getSize() const
Definition: Type.h:2890
Kind getAttrKind() const
Definition: Type.h:4446
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value...
Definition: Expr.h:3702
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:2360
void setBuiltinID(unsigned ID)
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:716
Stmt * getInit()
Definition: Stmt.h:1967
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition: ExprCXX.h:2113
ExtVectorType - Extended vector type.
Definition: Type.h:3287
ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D)
SourceRange getDirectInitRange() const
Definition: ExprCXX.h:2157
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the member name, with source location information...
Definition: ExprCXX.h:3405
Opcode getOpcode() const
Definition: Expr.h:1921
virtual void CompleteType(TagDecl *Tag)
Gives the external AST source an opportunity to complete an incomplete type.
param_const_iterator param_begin() const
Definition: DeclObjC.h:348
SourceRange getBracketsRange() const
Definition: Type.h:2997
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1730
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2269
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition: DeclObjC.h:1915
StringRef getBytes() const
Allow access to clients that need the byte representation, such as ASTWriterStmt::VisitStringLiteral(...
Definition: Expr.h:1657
Represents Objective-C&#39;s @finally statement.
Definition: StmtObjC.h:120
The template argument is a type.
Definition: TemplateBase.h:60
QualType getUnderlyingType() const
Definition: Type.h:4234
ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D)
void setInstantiationOfMemberClass(CXXRecordDecl *RD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member class RD.
Definition: DeclCXX.cpp:1610
void setSetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:917
The template argument is actually a parameter pack.
Definition: TemplateBase.h:91
bool isArrow() const
Determine whether this member expression used the &#39;->&#39; operator; otherwise, it used the &#39;...
Definition: ExprCXX.h:3391
SourceLocation getColonLoc() const
Definition: Stmt.h:1375
Represents a base class of a C++ class.
Definition: DeclCXX.h:192
bool hasTypename() const
Return true if the using declaration has &#39;typename&#39;.
Definition: DeclCXX.h:3407
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
unsigned getNumClobbers() const
Definition: Stmt.h:2601
SourceLocation getRParenLoc() const
Definition: Stmt.h:2287
static llvm::Optional< unsigned > getFieldIndex(Decl *F)
Determine the index of a field in its parent record.
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:3746
SourceManager & getSourceManager()
Definition: ASTContext.h:662
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition: Decl.h:1578
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
Definition: Type.cpp:2031
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof...
Definition: ExprCXX.h:3932
The type-property cache.
Definition: Type.cpp:3448
ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E)
DeclStmt * getRangeStmt()
Definition: StmtCXX.h:154
unsigned arg_size() const
Retrieve the number of arguments.
Definition: ExprCXX.h:3226
ImplementationControl getImplementationControl() const
Definition: DeclObjC.h:482
Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD=nullptr)
llvm::iterator_range< decls_iterator > decls() const
Definition: ExprCXX.h:2733
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition: ExprCXX.h:3169
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2253
SourceLocation getAsmLoc() const
Definition: Stmt.h:2550
outputs_range outputs()
Definition: Stmt.h:2653
GotoStmt - This represents a direct goto.
Definition: Stmt.h:2304
void ImportDefinition(Decl *From)
ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D)
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1137
Expr * getTarget()
Definition: Stmt.h:2359
void setHadMultipleCandidates(bool V=true)
Sets the flag telling whether this expression refers to a function that was resolved from an overload...
Definition: Expr.h:1233
A template argument list.
Definition: DeclTemplate.h:210
ExpectedType VisitLValueReferenceType(const LValueReferenceType *T)
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:238
ExpectedStmt VisitConditionalOperator(ConditionalOperator *E)
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:3446
SourceLocation getCXXLiteralOperatorNameLoc() const
getCXXLiteralOperatorNameLoc - Returns the location of the literal operator name (not the operator ke...
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
Definition: DeclCXX.cpp:1619
TypedefNameDecl * getDecl() const
Definition: Type.h:4167
const SwitchCase * getNextSwitchCase() const
Definition: Stmt.h:1369
ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D)
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition: Type.h:3749
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: Expr.h:1221
ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T)
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:235
shadow_range shadows() const
Definition: DeclCXX.h:3452
unsigned getDepth() const
Definition: Type.h:4565
DeclarationName getCXXLiteralOperatorName(IdentifierInfo *II)
Get the name of the literal operator function with II as the identifier.
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:4425
Expr * getCond()
Definition: Stmt.h:2203
static CXXMemberCallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr *> Args, QualType Ty, ExprValueKind VK, SourceLocation RP, unsigned MinNumArgs=0)
Definition: ExprCXX.cpp:615
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S)
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
Definition: Stmt.cpp:864
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1009
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:2682
SourceLocation getWhileLoc() const
Definition: Stmt.h:2216
Defines the clang::SourceLocation class and associated facilities.
SourceLocation getCategoryNameLoc() const
Definition: DeclObjC.h:2413
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3274
void setDefaultArg(Expr *defarg)
Definition: Decl.cpp:2585
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition: Decl.h:2654
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition: Decl.h:3164
Represents a C++ struct/union/class.
Definition: DeclCXX.h:300
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:5264
ContinueStmt - This represents a continue.
Definition: Stmt.h:2384
ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T)
Represents a loop initializing the elements of an array.
Definition: Expr.h:4803
The template argument is a template name that was provided for a template template parameter...
Definition: TemplateBase.h:76
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition: Decl.cpp:2459
ExpectedType VisitVariableArrayType(const VariableArrayType *T)
static CXXTryStmt * Create(const ASTContext &C, SourceLocation tryLoc, Stmt *tryBlock, ArrayRef< Stmt *> handlers)
Definition: StmtCXX.cpp:26
SourceLocation getColonLoc() const
Definition: StmtCXX.h:196
Represents a C array with an unspecified size.
Definition: Type.h:2926
TemplateArgumentLocInfo getLocInfo() const
Definition: TemplateBase.h:503
SourceLocation getEllipsisLoc() const
For a pack expansion, determine the location of the ellipsis.
Definition: DeclCXX.h:263
SourceLocation getAttrLoc() const
Definition: Stmt.h:1668
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition: ExprCXX.cpp:919
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition: Expr.h:3655
CXXCatchStmt - This represents a C++ catch block.
Definition: StmtCXX.h:29
An index into an array.
Definition: Expr.h:2018
SourceLocation getRParenLoc() const
Definition: Expr.h:4965
ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E)
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition: Decl.h:3517
Expr * getRHS() const
Definition: Expr.h:3628
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1945
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:945
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:608
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:5169
WhileStmt - This represents a &#39;while&#39; stmt.
Definition: Stmt.h:2063
A structure for storing the information associated with an overloaded template name.
Definition: TemplateName.h:96
static StructuralEquivalenceKind getStructuralEquivalenceKind(const ASTImporter &Importer)
SourceRange getParenOrBraceRange() const
Definition: ExprCXX.h:1430
ClassTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
ExpectedType VisitPackExpansionType(const PackExpansionType *T)
ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E)
unsigned getNumConcatenated() const
getNumConcatenated - Get the number of string literal tokens that were concatenated in translation ph...
Definition: Expr.h:1708
bool isNull() const
Determine whether this is the empty selector.
QualType getReplacementType() const
Gets the type that was substituted for the template parameter.
Definition: Type.h:4624
Location information for a TemplateArgument.
Definition: TemplateBase.h:393
bool isFailed() const
Definition: DeclCXX.h:3775
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates)...
Definition: Expr.h:214
Declaration of a class template.
SourceLocation getAtSynchronizedLoc() const
Definition: StmtObjC.h:279
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition: DeclObjC.h:637
This class is used for builtin types like &#39;int&#39;.
Definition: Type.h:2391
Optional< unsigned > getNumExpansions() const
Determine the number of expansions that will be produced when this pack expansion is instantiated...
Definition: ExprCXX.h:3812
bool isVariadic() const
Definition: DeclObjC.h:427
void addAttr(Attr *A)
Definition: DeclBase.cpp:840
CompoundStmt * getTryBlock()
Definition: StmtCXX.h:96
SourceLocation getBreakLoc() const
Definition: Stmt.h:2419
ExpectedDecl VisitFunctionDecl(FunctionDecl *D)
SourceLocation getCaseLoc() const
Definition: Stmt.h:1465
capture_range captures() const
Retrieve this lambda&#39;s captures.
Definition: ExprCXX.cpp:1166
void setPropertyAttributes(PropertyAttributeKind PRVal)
Definition: DeclObjC.h:844
Represents Objective-C&#39;s @try ... @catch ... @finally statement.
Definition: StmtObjC.h:154
protocol_iterator protocol_end() const
Definition: DeclObjC.h:2364
bool isGlobalDelete() const
Definition: ExprCXX.h:2196
SourceLocation getLocation() const
Retrieve the source location of the capture.
unsigned getNumCatchStmts() const
Retrieve the number of @catch statements in this try-catch-finally block.
Definition: StmtObjC.h:203
Expr * getBase() const
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition: ExprCXX.h:3382
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1566
bool hasExplicitParameters() const
Determine whether this lambda has an explicit parameter list vs.
Definition: ExprCXX.h:1848
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2396
Expected< TemplateArgument > ImportTemplateArgument(const TemplateArgument &From)
ExpectedStmt VisitStmtExpr(StmtExpr *E)
ExpectedDecl VisitFriendDecl(FriendDecl *D)
SourceRange getTypeIdParens() const
Definition: ExprCXX.h:2069
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:3480
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition: ExprCXX.h:3801
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition: Decl.h:1989
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition: Decl.cpp:3358
ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D)
Import only the bare bones needed to establish a valid DeclContext.
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition: DeclCXX.h:3720
NameKind getKind() const
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition: ExprCXX.h:270
unsigned getNumElements() const
Definition: Type.h:3204
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:2776
ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D)
void setNextSwitchCase(SwitchCase *SC)
Definition: Stmt.h:1371
decl_type * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
Definition: Redeclarable.h:226
The top declaration context.
Definition: Decl.h:108
unsigned getNumComponents() const
Definition: Expr.h:2176
const ParmVarDecl * getParam() const
Definition: ExprCXX.h:1102
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:257
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1041
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:4841
Expr * getRHS() const
Definition: Expr.h:3329
ObjCPropertyDecl * getPropertyDecl() const
Definition: DeclObjC.h:2818
ObjCTypeParamVariance getVariance() const
Determine the variance of this type parameter.
Definition: DeclObjC.h:602
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition: ExprCXX.h:2756
BreakStmt - This represents a break.
Definition: Stmt.h:2410
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition: Decl.cpp:3316
void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form &#39;type...
std::string toString() const
Definition: ASTImporter.cpp:84
ExpectedStmt VisitCaseStmt(CaseStmt *S)
SourceLocation getUsingLoc() const
Returns the source location of the &#39;using&#39; keyword.
Definition: DeclCXX.h:3696
const VarDecl * getCatchParamDecl() const
Definition: StmtObjC.h:94
ExpectedType VisitMemberPointerType(const MemberPointerType *T)
ExpectedType VisitTemplateTypeParmType(const TemplateTypeParmType *T)
SourceLocation getLocation() const
Definition: Expr.h:1418
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition: Decl.h:1611
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition: Expr.h:4297
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition: ExprCXX.h:3438
DefinitionKind isThisDeclarationADefinition(ASTContext &) const
Check whether this declaration is a definition.
Definition: Decl.cpp:2029
Stmt * getSubStmt()
Definition: Stmt.h:1614
bool hadMultipleCandidates() const
Whether the referred constructor was resolved from an overloaded set having size greater than 1...
Definition: ExprCXX.h:1345
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace nested inside this namespace, if any.
Definition: Decl.h:598
SourceLocation getNamespaceLoc() const
Returns the location of the namespace keyword.
Definition: DeclCXX.h:3109
static DeclarationName getUsingDirectiveName()
Returns the name for all C++ using-directives.
DeclStmt * getLoopVarStmt()
Definition: StmtCXX.h:161
IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it...
QualType getType() const
Definition: Decl.h:648
AccessSpecifier getAccessSpecifierAsWritten() const
Retrieves the access specifier as written in the source code (which may mean that no access specifier...
Definition: DeclCXX.h:284
TemplateArgument getArgumentPack() const
Retrieve the template template argument pack with which this parameter was substituted.
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition: ExprCXX.h:1410
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:2154
Error ImportDeclParts(NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc)
A set of overloaded template declarations.
Definition: TemplateName.h:195
Error ImportDeclarationNameLoc(const DeclarationNameInfo &From, DeclarationNameInfo &To)
A trivial tuple used to represent a source range.
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:299
ObjCMethodDecl * getGetterMethodDecl() const
Definition: DeclObjC.h:922
This represents a decl that may have a name.
Definition: Decl.h:249
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition: Expr.h:2807
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition: ExprCXX.h:562
ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S)
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type, member-designator).
Definition: Expr.h:2117
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:2374
void setAccess(AccessSpecifier AS)
Definition: DeclBase.h:457
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:2971
Expr * getQueriedExpression() const
Definition: ExprCXX.h:2619
Represents a C++ namespace alias.
Definition: DeclCXX.h:3020
SourceLocation getBuiltinLoc() const
Definition: Expr.h:5523
SourceRange getSourceRange() const LLVM_READONLY
Retrieves the source range that contains the entire base specifier.
Definition: DeclCXX.h:235
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:281
AccessControl getAccessControl() const
Definition: DeclObjC.h:1984
SourceLocation getIvarRBraceLoc() const
Definition: DeclObjC.h:2419
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition: Expr.h:3695
bool isPropertyAccessor() const
Definition: DeclObjC.h:432
TypeSourceInfo * getWrittenTypeInfo() const
Definition: Expr.h:4117
Selector getGetterName() const
Definition: DeclObjC.h:906
ImplicitParamKind getParameterKind() const
Returns the implicit parameter kind.
Definition: Decl.h:1540
Represents C++ using-directive.
Definition: DeclCXX.h:2916
DeclStmt * getBeginStmt()
Definition: StmtCXX.h:155
SourceLocation getLParenLoc() const
Definition: DeclObjC.h:824
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
Definition: DeclTemplate.h:648
ExpectedType VisitDependentNameType(const DependentNameType *T)
void setTypeAsWritten(TypeSourceInfo *T)
Sets the type of this specialization as it was written by the user.
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Definition: DeclTemplate.h:653
The global specifier &#39;::&#39;. There is no stored value.
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2126
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion, return the pattern as a template name.
Definition: TemplateBase.h:288
ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S)
void setType(QualType newType)
Definition: Decl.h:649
SourceLocation getBegin() const
TranslationUnitDecl * getTranslationUnitDecl()
Definition: DeclBase.cpp:361
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Get the template arguments as written.
SourceLocation getRParenLoc() const
Return the location of the right parentheses.
Definition: Expr.h:2156
ExpectedStmt VisitMemberExpr(MemberExpr *E)
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition: Decl.h:730
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition: ExprCXX.h:3915
Represents Objective-C&#39;s @autoreleasepool Statement.
Definition: StmtObjC.h:345
ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias)
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
Definition: DeclObjC.h:2499
IdentifierInfo * getFieldName() const
Definition: Expr.cpp:3833
This class handles loading and caching of source files into memory.
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:2872
Stmt * getSubStmt()
Definition: Stmt.h:1673
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:3773
InitListExpr * getSyntacticForm() const
Definition: Expr.h:4342
Declaration of a template function.
Definition: DeclTemplate.h:969
void setPropertyIvarDecl(ObjCIvarDecl *Ivar)
Definition: DeclObjC.h:941
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:4893
static ObjCAtTryStmt * Create(const ASTContext &Context, SourceLocation atTryLoc, Stmt *atTryStmt, Stmt **CatchStmts, unsigned NumCatchStmts, Stmt *atFinallyStmt)
Definition: StmtObjC.cpp:46
SourceLocation getReturnLoc() const
Definition: Stmt.h:2499
TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, bool TemplateKeyword, TemplateDecl *Template) const
Retrieve the template name that represents a qualified template name such as std::vector.
Attr - This represents one attribute.
Definition: Attr.h:44
SourceLocation getLocation() const
Definition: DeclBase.h:418
QualType getPointeeType() const
Definition: Type.h:2776
Represents a shadow declaration introduced into a scope by a (resolved) using declaration.
Definition: DeclCXX.h:3139
ExpectedType VisitDecltypeType(const DecltypeType *T)
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:98
TypeTrait getTrait() const
Determine which type trait this expression uses.
Definition: ExprCXX.h:2469
A single template declaration.
Definition: TemplateName.h:192
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3189
SourceLocation getOperatorLoc() const
Definition: Expr.h:2872
ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D)
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
Defines the LambdaCapture class.
const DeclarationNameInfo & getMemberNameInfo() const
Retrieve the name of the member that this expression refers to.
Definition: ExprCXX.h:3425
ArrayRef< ParmVarDecl * > parameters() const
Definition: DeclObjC.h:367
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form, which contains extra information on the evaluated value of the initializer.
Definition: Decl.cpp:2244
const IdentifierInfo * getIdentifier() const
Definition: Type.h:5291
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> PL, ArrayRef< Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.
bool hasExternalFormalLinkage() const
True if this decl has external linkage.
Definition: Decl.h:376
ConstructionKind getConstructionKind() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition: ExprCXX.h:1382
ObjCCategoryDecl * FindCategoryDeclaration(IdentifierInfo *CategoryId) const
FindCategoryDeclaration - Finds category declaration in the list of categories for this class and ret...
Definition: DeclObjC.cpp:1664
ExpectedType VisitBlockPointerType(const BlockPointerType *T)
Structure used to store a statement, the constant value to which it was evaluated (if any)...
Definition: Decl.h:784
Stmt * getSubStmt()
Definition: Stmt.h:1513
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:5810
method_range methods() const
Definition: DeclCXX.h:865
static NestedNameSpecifier * GlobalSpecifier(const ASTContext &Context)
Returns the nested name specifier representing the global scope.
bool isOverloaded() const
True if this lookup is overloaded.
Definition: ExprCXX.h:2899
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:799