clang  3.7.0
ASTImporter.cpp
Go to the documentation of this file.
1 //===--- ASTImporter.cpp - Importing ASTs from other Contexts ---*- C++ -*-===//
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 #include "clang/AST/ASTImporter.h"
15 #include "clang/AST/ASTContext.h"
17 #include "clang/AST/DeclCXX.h"
18 #include "clang/AST/DeclObjC.h"
19 #include "clang/AST/DeclVisitor.h"
20 #include "clang/AST/StmtVisitor.h"
21 #include "clang/AST/TypeVisitor.h"
24 #include "llvm/Support/MemoryBuffer.h"
25 #include <deque>
26 
27 namespace clang {
28  class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, QualType>,
29  public DeclVisitor<ASTNodeImporter, Decl *>,
30  public StmtVisitor<ASTNodeImporter, Stmt *> {
31  ASTImporter &Importer;
32 
33  public:
34  explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) { }
35 
39 
40  // Importing types
41  QualType VisitType(const Type *T);
52  // FIXME: DependentSizedArrayType
53  // FIXME: DependentSizedExtVectorType
58  // FIXME: UnresolvedUsingType
62  // FIXME: DependentTypeOfExprType
67  // FIXME: DependentDecltypeType
71  // FIXME: TemplateTypeParmType
72  // FIXME: SubstTemplateTypeParmType
75  // FIXME: DependentNameType
76  // FIXME: DependentTemplateSpecializationType
80 
81  // Importing declarations
82  bool ImportDeclParts(NamedDecl *D, DeclContext *&DC,
83  DeclContext *&LexicalDC, DeclarationName &Name,
84  NamedDecl *&ToD, SourceLocation &Loc);
85  void ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
88  void ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
89 
90  /// \brief What we should import from the definition.
92  /// \brief Import the default subset of the definition, which might be
93  /// nothing (if minimal import is set) or might be everything (if minimal
94  /// import is not set).
96  /// \brief Import everything.
98  /// \brief Import only the bare bones needed to establish a valid
99  /// DeclContext.
101  };
102 
104  return IDK == IDK_Everything ||
105  (IDK == IDK_Default && !Importer.isMinimalImport());
106  }
107 
108  bool ImportDefinition(RecordDecl *From, RecordDecl *To,
110  bool ImportDefinition(VarDecl *From, VarDecl *To,
112  bool ImportDefinition(EnumDecl *From, EnumDecl *To,
119  TemplateParameterList *Params);
121  bool ImportTemplateArguments(const TemplateArgument *FromArgs,
122  unsigned NumFromArgs,
124  bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord,
125  bool Complain = true);
126  bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar,
127  bool Complain = true);
128  bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord);
132  Decl *VisitDecl(Decl *D);
135  Decl *VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias);
157 
172 
173  // Importing statements
175 
176  Stmt *VisitStmt(Stmt *S);
194  // FIXME: GCCAsmStmt
195  // FIXME: MSAsmStmt
196  // FIXME: SEHExceptStmt
197  // FIXME: SEHFinallyStmt
198  // FIXME: SEHTryStmt
199  // FIXME: SEHLeaveStmt
200  // FIXME: CapturedStmt
204  // FIXME: MSDependentExistsStmt
212 
213  // Importing expressions
214  Expr *VisitExpr(Expr *E);
228  };
229 }
230 using namespace clang;
231 
232 //----------------------------------------------------------------------------
233 // Structural Equivalence
234 //----------------------------------------------------------------------------
235 
236 namespace {
237  struct StructuralEquivalenceContext {
238  /// \brief AST contexts for which we are checking structural equivalence.
239  ASTContext &C1, &C2;
240 
241  /// \brief The set of "tentative" equivalences between two canonical
242  /// declarations, mapping from a declaration in the first context to the
243  /// declaration in the second context that we believe to be equivalent.
244  llvm::DenseMap<Decl *, Decl *> TentativeEquivalences;
245 
246  /// \brief Queue of declarations in the first context whose equivalence
247  /// with a declaration in the second context still needs to be verified.
248  std::deque<Decl *> DeclsToCheck;
249 
250  /// \brief Declaration (from, to) pairs that are known not to be equivalent
251  /// (which we have already complained about).
252  llvm::DenseSet<std::pair<Decl *, Decl *> > &NonEquivalentDecls;
253 
254  /// \brief Whether we're being strict about the spelling of types when
255  /// unifying two types.
256  bool StrictTypeSpelling;
257 
258  /// \brief Whether to complain about failures.
259  bool Complain;
260 
261  /// \brief \c true if the last diagnostic came from C2.
262  bool LastDiagFromC2;
263 
264  StructuralEquivalenceContext(ASTContext &C1, ASTContext &C2,
265  llvm::DenseSet<std::pair<Decl *, Decl *> > &NonEquivalentDecls,
266  bool StrictTypeSpelling = false,
267  bool Complain = true)
268  : C1(C1), C2(C2), NonEquivalentDecls(NonEquivalentDecls),
269  StrictTypeSpelling(StrictTypeSpelling), Complain(Complain),
270  LastDiagFromC2(false) {}
271 
272  /// \brief Determine whether the two declarations are structurally
273  /// equivalent.
274  bool IsStructurallyEquivalent(Decl *D1, Decl *D2);
275 
276  /// \brief Determine whether the two types are structurally equivalent.
278 
279  private:
280  /// \brief Finish checking all of the structural equivalences.
281  ///
282  /// \returns true if an error occurred, false otherwise.
283  bool Finish();
284 
285  public:
286  DiagnosticBuilder Diag1(SourceLocation Loc, unsigned DiagID) {
287  assert(Complain && "Not allowed to complain");
288  if (LastDiagFromC2)
289  C1.getDiagnostics().notePriorDiagnosticFrom(C2.getDiagnostics());
290  LastDiagFromC2 = false;
291  return C1.getDiagnostics().Report(Loc, DiagID);
292  }
293 
294  DiagnosticBuilder Diag2(SourceLocation Loc, unsigned DiagID) {
295  assert(Complain && "Not allowed to complain");
296  if (!LastDiagFromC2)
297  C2.getDiagnostics().notePriorDiagnosticFrom(C1.getDiagnostics());
298  LastDiagFromC2 = true;
299  return C2.getDiagnostics().Report(Loc, DiagID);
300  }
301  };
302 }
303 
304 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
305  QualType T1, QualType T2);
306 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
307  Decl *D1, Decl *D2);
308 
309 /// \brief Determine structural equivalence of two expressions.
310 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
311  Expr *E1, Expr *E2) {
312  if (!E1 || !E2)
313  return E1 == E2;
314 
315  // FIXME: Actually perform a structural comparison!
316  return true;
317 }
318 
319 /// \brief Determine whether two identifiers are equivalent.
320 static bool IsStructurallyEquivalent(const IdentifierInfo *Name1,
321  const IdentifierInfo *Name2) {
322  if (!Name1 || !Name2)
323  return Name1 == Name2;
324 
325  return Name1->getName() == Name2->getName();
326 }
327 
328 /// \brief Determine whether two nested-name-specifiers are equivalent.
329 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
330  NestedNameSpecifier *NNS1,
331  NestedNameSpecifier *NNS2) {
332  // FIXME: Implement!
333  return true;
334 }
335 
336 /// \brief Determine whether two template arguments are equivalent.
337 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
338  const TemplateArgument &Arg1,
339  const TemplateArgument &Arg2) {
340  if (Arg1.getKind() != Arg2.getKind())
341  return false;
342 
343  switch (Arg1.getKind()) {
345  return true;
346 
348  return Context.IsStructurallyEquivalent(Arg1.getAsType(), Arg2.getAsType());
349 
351  if (!Context.IsStructurallyEquivalent(Arg1.getIntegralType(),
352  Arg2.getIntegralType()))
353  return false;
354 
355  return llvm::APSInt::isSameValue(Arg1.getAsIntegral(), Arg2.getAsIntegral());
356 
358  return Context.IsStructurallyEquivalent(Arg1.getAsDecl(), Arg2.getAsDecl());
359 
361  return true; // FIXME: Is this correct?
362 
364  return IsStructurallyEquivalent(Context,
365  Arg1.getAsTemplate(),
366  Arg2.getAsTemplate());
367 
369  return IsStructurallyEquivalent(Context,
372 
374  return IsStructurallyEquivalent(Context,
375  Arg1.getAsExpr(), Arg2.getAsExpr());
376 
378  if (Arg1.pack_size() != Arg2.pack_size())
379  return false;
380 
381  for (unsigned I = 0, N = Arg1.pack_size(); I != N; ++I)
382  if (!IsStructurallyEquivalent(Context,
383  Arg1.pack_begin()[I],
384  Arg2.pack_begin()[I]))
385  return false;
386 
387  return true;
388  }
389 
390  llvm_unreachable("Invalid template argument kind");
391 }
392 
393 /// \brief Determine structural equivalence for the common part of array
394 /// types.
395 static bool IsArrayStructurallyEquivalent(StructuralEquivalenceContext &Context,
396  const ArrayType *Array1,
397  const ArrayType *Array2) {
398  if (!IsStructurallyEquivalent(Context,
399  Array1->getElementType(),
400  Array2->getElementType()))
401  return false;
402  if (Array1->getSizeModifier() != Array2->getSizeModifier())
403  return false;
404  if (Array1->getIndexTypeQualifiers() != Array2->getIndexTypeQualifiers())
405  return false;
406 
407  return true;
408 }
409 
410 /// \brief Determine structural equivalence of two types.
411 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
412  QualType T1, QualType T2) {
413  if (T1.isNull() || T2.isNull())
414  return T1.isNull() && T2.isNull();
415 
416  if (!Context.StrictTypeSpelling) {
417  // We aren't being strict about token-to-token equivalence of types,
418  // so map down to the canonical type.
419  T1 = Context.C1.getCanonicalType(T1);
420  T2 = Context.C2.getCanonicalType(T2);
421  }
422 
423  if (T1.getQualifiers() != T2.getQualifiers())
424  return false;
425 
426  Type::TypeClass TC = T1->getTypeClass();
427 
428  if (T1->getTypeClass() != T2->getTypeClass()) {
429  // Compare function types with prototypes vs. without prototypes as if
430  // both did not have prototypes.
431  if (T1->getTypeClass() == Type::FunctionProto &&
432  T2->getTypeClass() == Type::FunctionNoProto)
433  TC = Type::FunctionNoProto;
434  else if (T1->getTypeClass() == Type::FunctionNoProto &&
435  T2->getTypeClass() == Type::FunctionProto)
436  TC = Type::FunctionNoProto;
437  else
438  return false;
439  }
440 
441  switch (TC) {
442  case Type::Builtin:
443  // FIXME: Deal with Char_S/Char_U.
444  if (cast<BuiltinType>(T1)->getKind() != cast<BuiltinType>(T2)->getKind())
445  return false;
446  break;
447 
448  case Type::Complex:
449  if (!IsStructurallyEquivalent(Context,
450  cast<ComplexType>(T1)->getElementType(),
451  cast<ComplexType>(T2)->getElementType()))
452  return false;
453  break;
454 
455  case Type::Adjusted:
456  case Type::Decayed:
457  if (!IsStructurallyEquivalent(Context,
458  cast<AdjustedType>(T1)->getOriginalType(),
459  cast<AdjustedType>(T2)->getOriginalType()))
460  return false;
461  break;
462 
463  case Type::Pointer:
464  if (!IsStructurallyEquivalent(Context,
465  cast<PointerType>(T1)->getPointeeType(),
466  cast<PointerType>(T2)->getPointeeType()))
467  return false;
468  break;
469 
470  case Type::BlockPointer:
471  if (!IsStructurallyEquivalent(Context,
472  cast<BlockPointerType>(T1)->getPointeeType(),
473  cast<BlockPointerType>(T2)->getPointeeType()))
474  return false;
475  break;
476 
477  case Type::LValueReference:
478  case Type::RValueReference: {
479  const ReferenceType *Ref1 = cast<ReferenceType>(T1);
480  const ReferenceType *Ref2 = cast<ReferenceType>(T2);
481  if (Ref1->isSpelledAsLValue() != Ref2->isSpelledAsLValue())
482  return false;
483  if (Ref1->isInnerRef() != Ref2->isInnerRef())
484  return false;
485  if (!IsStructurallyEquivalent(Context,
486  Ref1->getPointeeTypeAsWritten(),
487  Ref2->getPointeeTypeAsWritten()))
488  return false;
489  break;
490  }
491 
492  case Type::MemberPointer: {
493  const MemberPointerType *MemPtr1 = cast<MemberPointerType>(T1);
494  const MemberPointerType *MemPtr2 = cast<MemberPointerType>(T2);
495  if (!IsStructurallyEquivalent(Context,
496  MemPtr1->getPointeeType(),
497  MemPtr2->getPointeeType()))
498  return false;
499  if (!IsStructurallyEquivalent(Context,
500  QualType(MemPtr1->getClass(), 0),
501  QualType(MemPtr2->getClass(), 0)))
502  return false;
503  break;
504  }
505 
506  case Type::ConstantArray: {
507  const ConstantArrayType *Array1 = cast<ConstantArrayType>(T1);
508  const ConstantArrayType *Array2 = cast<ConstantArrayType>(T2);
509  if (!llvm::APInt::isSameValue(Array1->getSize(), Array2->getSize()))
510  return false;
511 
512  if (!IsArrayStructurallyEquivalent(Context, Array1, Array2))
513  return false;
514  break;
515  }
516 
517  case Type::IncompleteArray:
518  if (!IsArrayStructurallyEquivalent(Context,
519  cast<ArrayType>(T1),
520  cast<ArrayType>(T2)))
521  return false;
522  break;
523 
524  case Type::VariableArray: {
525  const VariableArrayType *Array1 = cast<VariableArrayType>(T1);
526  const VariableArrayType *Array2 = cast<VariableArrayType>(T2);
527  if (!IsStructurallyEquivalent(Context,
528  Array1->getSizeExpr(), Array2->getSizeExpr()))
529  return false;
530 
531  if (!IsArrayStructurallyEquivalent(Context, Array1, Array2))
532  return false;
533 
534  break;
535  }
536 
537  case Type::DependentSizedArray: {
538  const DependentSizedArrayType *Array1 = cast<DependentSizedArrayType>(T1);
539  const DependentSizedArrayType *Array2 = cast<DependentSizedArrayType>(T2);
540  if (!IsStructurallyEquivalent(Context,
541  Array1->getSizeExpr(), Array2->getSizeExpr()))
542  return false;
543 
544  if (!IsArrayStructurallyEquivalent(Context, Array1, Array2))
545  return false;
546 
547  break;
548  }
549 
550  case Type::DependentSizedExtVector: {
551  const DependentSizedExtVectorType *Vec1
552  = cast<DependentSizedExtVectorType>(T1);
553  const DependentSizedExtVectorType *Vec2
554  = cast<DependentSizedExtVectorType>(T2);
555  if (!IsStructurallyEquivalent(Context,
556  Vec1->getSizeExpr(), Vec2->getSizeExpr()))
557  return false;
558  if (!IsStructurallyEquivalent(Context,
559  Vec1->getElementType(),
560  Vec2->getElementType()))
561  return false;
562  break;
563  }
564 
565  case Type::Vector:
566  case Type::ExtVector: {
567  const VectorType *Vec1 = cast<VectorType>(T1);
568  const VectorType *Vec2 = cast<VectorType>(T2);
569  if (!IsStructurallyEquivalent(Context,
570  Vec1->getElementType(),
571  Vec2->getElementType()))
572  return false;
573  if (Vec1->getNumElements() != Vec2->getNumElements())
574  return false;
575  if (Vec1->getVectorKind() != Vec2->getVectorKind())
576  return false;
577  break;
578  }
579 
580  case Type::FunctionProto: {
581  const FunctionProtoType *Proto1 = cast<FunctionProtoType>(T1);
582  const FunctionProtoType *Proto2 = cast<FunctionProtoType>(T2);
583  if (Proto1->getNumParams() != Proto2->getNumParams())
584  return false;
585  for (unsigned I = 0, N = Proto1->getNumParams(); I != N; ++I) {
586  if (!IsStructurallyEquivalent(Context, Proto1->getParamType(I),
587  Proto2->getParamType(I)))
588  return false;
589  }
590  if (Proto1->isVariadic() != Proto2->isVariadic())
591  return false;
592  if (Proto1->getExceptionSpecType() != Proto2->getExceptionSpecType())
593  return false;
594  if (Proto1->getExceptionSpecType() == EST_Dynamic) {
595  if (Proto1->getNumExceptions() != Proto2->getNumExceptions())
596  return false;
597  for (unsigned I = 0, N = Proto1->getNumExceptions(); I != N; ++I) {
598  if (!IsStructurallyEquivalent(Context,
599  Proto1->getExceptionType(I),
600  Proto2->getExceptionType(I)))
601  return false;
602  }
603  } else if (Proto1->getExceptionSpecType() == EST_ComputedNoexcept) {
604  if (!IsStructurallyEquivalent(Context,
605  Proto1->getNoexceptExpr(),
606  Proto2->getNoexceptExpr()))
607  return false;
608  }
609  if (Proto1->getTypeQuals() != Proto2->getTypeQuals())
610  return false;
611 
612  // Fall through to check the bits common with FunctionNoProtoType.
613  }
614 
615  case Type::FunctionNoProto: {
616  const FunctionType *Function1 = cast<FunctionType>(T1);
617  const FunctionType *Function2 = cast<FunctionType>(T2);
618  if (!IsStructurallyEquivalent(Context, Function1->getReturnType(),
619  Function2->getReturnType()))
620  return false;
621  if (Function1->getExtInfo() != Function2->getExtInfo())
622  return false;
623  break;
624  }
625 
626  case Type::UnresolvedUsing:
627  if (!IsStructurallyEquivalent(Context,
628  cast<UnresolvedUsingType>(T1)->getDecl(),
629  cast<UnresolvedUsingType>(T2)->getDecl()))
630  return false;
631 
632  break;
633 
634  case Type::Attributed:
635  if (!IsStructurallyEquivalent(Context,
636  cast<AttributedType>(T1)->getModifiedType(),
637  cast<AttributedType>(T2)->getModifiedType()))
638  return false;
639  if (!IsStructurallyEquivalent(Context,
640  cast<AttributedType>(T1)->getEquivalentType(),
641  cast<AttributedType>(T2)->getEquivalentType()))
642  return false;
643  break;
644 
645  case Type::Paren:
646  if (!IsStructurallyEquivalent(Context,
647  cast<ParenType>(T1)->getInnerType(),
648  cast<ParenType>(T2)->getInnerType()))
649  return false;
650  break;
651 
652  case Type::Typedef:
653  if (!IsStructurallyEquivalent(Context,
654  cast<TypedefType>(T1)->getDecl(),
655  cast<TypedefType>(T2)->getDecl()))
656  return false;
657  break;
658 
659  case Type::TypeOfExpr:
660  if (!IsStructurallyEquivalent(Context,
661  cast<TypeOfExprType>(T1)->getUnderlyingExpr(),
662  cast<TypeOfExprType>(T2)->getUnderlyingExpr()))
663  return false;
664  break;
665 
666  case Type::TypeOf:
667  if (!IsStructurallyEquivalent(Context,
668  cast<TypeOfType>(T1)->getUnderlyingType(),
669  cast<TypeOfType>(T2)->getUnderlyingType()))
670  return false;
671  break;
672 
673  case Type::UnaryTransform:
674  if (!IsStructurallyEquivalent(Context,
675  cast<UnaryTransformType>(T1)->getUnderlyingType(),
676  cast<UnaryTransformType>(T1)->getUnderlyingType()))
677  return false;
678  break;
679 
680  case Type::Decltype:
681  if (!IsStructurallyEquivalent(Context,
682  cast<DecltypeType>(T1)->getUnderlyingExpr(),
683  cast<DecltypeType>(T2)->getUnderlyingExpr()))
684  return false;
685  break;
686 
687  case Type::Auto:
688  if (!IsStructurallyEquivalent(Context,
689  cast<AutoType>(T1)->getDeducedType(),
690  cast<AutoType>(T2)->getDeducedType()))
691  return false;
692  break;
693 
694  case Type::Record:
695  case Type::Enum:
696  if (!IsStructurallyEquivalent(Context,
697  cast<TagType>(T1)->getDecl(),
698  cast<TagType>(T2)->getDecl()))
699  return false;
700  break;
701 
702  case Type::TemplateTypeParm: {
703  const TemplateTypeParmType *Parm1 = cast<TemplateTypeParmType>(T1);
704  const TemplateTypeParmType *Parm2 = cast<TemplateTypeParmType>(T2);
705  if (Parm1->getDepth() != Parm2->getDepth())
706  return false;
707  if (Parm1->getIndex() != Parm2->getIndex())
708  return false;
709  if (Parm1->isParameterPack() != Parm2->isParameterPack())
710  return false;
711 
712  // Names of template type parameters are never significant.
713  break;
714  }
715 
716  case Type::SubstTemplateTypeParm: {
717  const SubstTemplateTypeParmType *Subst1
718  = cast<SubstTemplateTypeParmType>(T1);
719  const SubstTemplateTypeParmType *Subst2
720  = cast<SubstTemplateTypeParmType>(T2);
721  if (!IsStructurallyEquivalent(Context,
722  QualType(Subst1->getReplacedParameter(), 0),
723  QualType(Subst2->getReplacedParameter(), 0)))
724  return false;
725  if (!IsStructurallyEquivalent(Context,
726  Subst1->getReplacementType(),
727  Subst2->getReplacementType()))
728  return false;
729  break;
730  }
731 
732  case Type::SubstTemplateTypeParmPack: {
733  const SubstTemplateTypeParmPackType *Subst1
734  = cast<SubstTemplateTypeParmPackType>(T1);
735  const SubstTemplateTypeParmPackType *Subst2
736  = cast<SubstTemplateTypeParmPackType>(T2);
737  if (!IsStructurallyEquivalent(Context,
738  QualType(Subst1->getReplacedParameter(), 0),
739  QualType(Subst2->getReplacedParameter(), 0)))
740  return false;
741  if (!IsStructurallyEquivalent(Context,
742  Subst1->getArgumentPack(),
743  Subst2->getArgumentPack()))
744  return false;
745  break;
746  }
747  case Type::TemplateSpecialization: {
748  const TemplateSpecializationType *Spec1
749  = cast<TemplateSpecializationType>(T1);
750  const TemplateSpecializationType *Spec2
751  = cast<TemplateSpecializationType>(T2);
752  if (!IsStructurallyEquivalent(Context,
753  Spec1->getTemplateName(),
754  Spec2->getTemplateName()))
755  return false;
756  if (Spec1->getNumArgs() != Spec2->getNumArgs())
757  return false;
758  for (unsigned I = 0, N = Spec1->getNumArgs(); I != N; ++I) {
759  if (!IsStructurallyEquivalent(Context,
760  Spec1->getArg(I), Spec2->getArg(I)))
761  return false;
762  }
763  break;
764  }
765 
766  case Type::Elaborated: {
767  const ElaboratedType *Elab1 = cast<ElaboratedType>(T1);
768  const ElaboratedType *Elab2 = cast<ElaboratedType>(T2);
769  // CHECKME: what if a keyword is ETK_None or ETK_typename ?
770  if (Elab1->getKeyword() != Elab2->getKeyword())
771  return false;
772  if (!IsStructurallyEquivalent(Context,
773  Elab1->getQualifier(),
774  Elab2->getQualifier()))
775  return false;
776  if (!IsStructurallyEquivalent(Context,
777  Elab1->getNamedType(),
778  Elab2->getNamedType()))
779  return false;
780  break;
781  }
782 
783  case Type::InjectedClassName: {
784  const InjectedClassNameType *Inj1 = cast<InjectedClassNameType>(T1);
785  const InjectedClassNameType *Inj2 = cast<InjectedClassNameType>(T2);
786  if (!IsStructurallyEquivalent(Context,
788  Inj2->getInjectedSpecializationType()))
789  return false;
790  break;
791  }
792 
793  case Type::DependentName: {
794  const DependentNameType *Typename1 = cast<DependentNameType>(T1);
795  const DependentNameType *Typename2 = cast<DependentNameType>(T2);
796  if (!IsStructurallyEquivalent(Context,
797  Typename1->getQualifier(),
798  Typename2->getQualifier()))
799  return false;
800  if (!IsStructurallyEquivalent(Typename1->getIdentifier(),
801  Typename2->getIdentifier()))
802  return false;
803 
804  break;
805  }
806 
807  case Type::DependentTemplateSpecialization: {
809  cast<DependentTemplateSpecializationType>(T1);
811  cast<DependentTemplateSpecializationType>(T2);
812  if (!IsStructurallyEquivalent(Context,
813  Spec1->getQualifier(),
814  Spec2->getQualifier()))
815  return false;
817  Spec2->getIdentifier()))
818  return false;
819  if (Spec1->getNumArgs() != Spec2->getNumArgs())
820  return false;
821  for (unsigned I = 0, N = Spec1->getNumArgs(); I != N; ++I) {
822  if (!IsStructurallyEquivalent(Context,
823  Spec1->getArg(I), Spec2->getArg(I)))
824  return false;
825  }
826  break;
827  }
828 
829  case Type::PackExpansion:
830  if (!IsStructurallyEquivalent(Context,
831  cast<PackExpansionType>(T1)->getPattern(),
832  cast<PackExpansionType>(T2)->getPattern()))
833  return false;
834  break;
835 
836  case Type::ObjCInterface: {
837  const ObjCInterfaceType *Iface1 = cast<ObjCInterfaceType>(T1);
838  const ObjCInterfaceType *Iface2 = cast<ObjCInterfaceType>(T2);
839  if (!IsStructurallyEquivalent(Context,
840  Iface1->getDecl(), Iface2->getDecl()))
841  return false;
842  break;
843  }
844 
845  case Type::ObjCObject: {
846  const ObjCObjectType *Obj1 = cast<ObjCObjectType>(T1);
847  const ObjCObjectType *Obj2 = cast<ObjCObjectType>(T2);
848  if (!IsStructurallyEquivalent(Context,
849  Obj1->getBaseType(),
850  Obj2->getBaseType()))
851  return false;
852  if (Obj1->getNumProtocols() != Obj2->getNumProtocols())
853  return false;
854  for (unsigned I = 0, N = Obj1->getNumProtocols(); I != N; ++I) {
855  if (!IsStructurallyEquivalent(Context,
856  Obj1->getProtocol(I),
857  Obj2->getProtocol(I)))
858  return false;
859  }
860  break;
861  }
862 
863  case Type::ObjCObjectPointer: {
864  const ObjCObjectPointerType *Ptr1 = cast<ObjCObjectPointerType>(T1);
865  const ObjCObjectPointerType *Ptr2 = cast<ObjCObjectPointerType>(T2);
866  if (!IsStructurallyEquivalent(Context,
867  Ptr1->getPointeeType(),
868  Ptr2->getPointeeType()))
869  return false;
870  break;
871  }
872 
873  case Type::Atomic: {
874  if (!IsStructurallyEquivalent(Context,
875  cast<AtomicType>(T1)->getValueType(),
876  cast<AtomicType>(T2)->getValueType()))
877  return false;
878  break;
879  }
880 
881  } // end switch
882 
883  return true;
884 }
885 
886 /// \brief Determine structural equivalence of two fields.
887 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
888  FieldDecl *Field1, FieldDecl *Field2) {
889  RecordDecl *Owner2 = cast<RecordDecl>(Field2->getDeclContext());
890 
891  // For anonymous structs/unions, match up the anonymous struct/union type
892  // declarations directly, so that we don't go off searching for anonymous
893  // types
894  if (Field1->isAnonymousStructOrUnion() &&
895  Field2->isAnonymousStructOrUnion()) {
896  RecordDecl *D1 = Field1->getType()->castAs<RecordType>()->getDecl();
897  RecordDecl *D2 = Field2->getType()->castAs<RecordType>()->getDecl();
898  return IsStructurallyEquivalent(Context, D1, D2);
899  }
900 
901  // Check for equivalent field names.
902  IdentifierInfo *Name1 = Field1->getIdentifier();
903  IdentifierInfo *Name2 = Field2->getIdentifier();
904  if (!::IsStructurallyEquivalent(Name1, Name2))
905  return false;
906 
907  if (!IsStructurallyEquivalent(Context,
908  Field1->getType(), Field2->getType())) {
909  if (Context.Complain) {
910  Context.Diag2(Owner2->getLocation(), diag::warn_odr_tag_type_inconsistent)
911  << Context.C2.getTypeDeclType(Owner2);
912  Context.Diag2(Field2->getLocation(), diag::note_odr_field)
913  << Field2->getDeclName() << Field2->getType();
914  Context.Diag1(Field1->getLocation(), diag::note_odr_field)
915  << Field1->getDeclName() << Field1->getType();
916  }
917  return false;
918  }
919 
920  if (Field1->isBitField() != Field2->isBitField()) {
921  if (Context.Complain) {
922  Context.Diag2(Owner2->getLocation(), diag::warn_odr_tag_type_inconsistent)
923  << Context.C2.getTypeDeclType(Owner2);
924  if (Field1->isBitField()) {
925  Context.Diag1(Field1->getLocation(), diag::note_odr_bit_field)
926  << Field1->getDeclName() << Field1->getType()
927  << Field1->getBitWidthValue(Context.C1);
928  Context.Diag2(Field2->getLocation(), diag::note_odr_not_bit_field)
929  << Field2->getDeclName();
930  } else {
931  Context.Diag2(Field2->getLocation(), diag::note_odr_bit_field)
932  << Field2->getDeclName() << Field2->getType()
933  << Field2->getBitWidthValue(Context.C2);
934  Context.Diag1(Field1->getLocation(), diag::note_odr_not_bit_field)
935  << Field1->getDeclName();
936  }
937  }
938  return false;
939  }
940 
941  if (Field1->isBitField()) {
942  // Make sure that the bit-fields are the same length.
943  unsigned Bits1 = Field1->getBitWidthValue(Context.C1);
944  unsigned Bits2 = Field2->getBitWidthValue(Context.C2);
945 
946  if (Bits1 != Bits2) {
947  if (Context.Complain) {
948  Context.Diag2(Owner2->getLocation(), diag::warn_odr_tag_type_inconsistent)
949  << Context.C2.getTypeDeclType(Owner2);
950  Context.Diag2(Field2->getLocation(), diag::note_odr_bit_field)
951  << Field2->getDeclName() << Field2->getType() << Bits2;
952  Context.Diag1(Field1->getLocation(), diag::note_odr_bit_field)
953  << Field1->getDeclName() << Field1->getType() << Bits1;
954  }
955  return false;
956  }
957  }
958 
959  return true;
960 }
961 
962 /// \brief Find the index of the given anonymous struct/union within its
963 /// context.
964 ///
965 /// \returns Returns the index of this anonymous struct/union in its context,
966 /// including the next assigned index (if none of them match). Returns an
967 /// empty option if the context is not a record, i.e.. if the anonymous
968 /// struct/union is at namespace or block scope.
970  ASTContext &Context = Anon->getASTContext();
971  QualType AnonTy = Context.getRecordType(Anon);
972 
973  RecordDecl *Owner = dyn_cast<RecordDecl>(Anon->getDeclContext());
974  if (!Owner)
975  return None;
976 
977  unsigned Index = 0;
978  for (const auto *D : Owner->noload_decls()) {
979  const auto *F = dyn_cast<FieldDecl>(D);
980  if (!F || !F->isAnonymousStructOrUnion())
981  continue;
982 
983  if (Context.hasSameType(F->getType(), AnonTy))
984  break;
985 
986  ++Index;
987  }
988 
989  return Index;
990 }
991 
992 /// \brief Determine structural equivalence of two records.
993 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
994  RecordDecl *D1, RecordDecl *D2) {
995  if (D1->isUnion() != D2->isUnion()) {
996  if (Context.Complain) {
997  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
998  << Context.C2.getTypeDeclType(D2);
999  Context.Diag1(D1->getLocation(), diag::note_odr_tag_kind_here)
1000  << D1->getDeclName() << (unsigned)D1->getTagKind();
1001  }
1002  return false;
1003  }
1004 
1006  // If both anonymous structs/unions are in a record context, make sure
1007  // they occur in the same location in the context records.
1010  if (*Index1 != *Index2)
1011  return false;
1012  }
1013  }
1014  }
1015 
1016  // If both declarations are class template specializations, we know
1017  // the ODR applies, so check the template and template arguments.
1019  = dyn_cast<ClassTemplateSpecializationDecl>(D1);
1021  = dyn_cast<ClassTemplateSpecializationDecl>(D2);
1022  if (Spec1 && Spec2) {
1023  // Check that the specialized templates are the same.
1024  if (!IsStructurallyEquivalent(Context, Spec1->getSpecializedTemplate(),
1025  Spec2->getSpecializedTemplate()))
1026  return false;
1027 
1028  // Check that the template arguments are the same.
1029  if (Spec1->getTemplateArgs().size() != Spec2->getTemplateArgs().size())
1030  return false;
1031 
1032  for (unsigned I = 0, N = Spec1->getTemplateArgs().size(); I != N; ++I)
1033  if (!IsStructurallyEquivalent(Context,
1034  Spec1->getTemplateArgs().get(I),
1035  Spec2->getTemplateArgs().get(I)))
1036  return false;
1037  }
1038  // If one is a class template specialization and the other is not, these
1039  // structures are different.
1040  else if (Spec1 || Spec2)
1041  return false;
1042 
1043  // Compare the definitions of these two records. If either or both are
1044  // incomplete, we assume that they are equivalent.
1045  D1 = D1->getDefinition();
1046  D2 = D2->getDefinition();
1047  if (!D1 || !D2)
1048  return true;
1049 
1050  if (CXXRecordDecl *D1CXX = dyn_cast<CXXRecordDecl>(D1)) {
1051  if (CXXRecordDecl *D2CXX = dyn_cast<CXXRecordDecl>(D2)) {
1052  if (D1CXX->getNumBases() != D2CXX->getNumBases()) {
1053  if (Context.Complain) {
1054  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1055  << Context.C2.getTypeDeclType(D2);
1056  Context.Diag2(D2->getLocation(), diag::note_odr_number_of_bases)
1057  << D2CXX->getNumBases();
1058  Context.Diag1(D1->getLocation(), diag::note_odr_number_of_bases)
1059  << D1CXX->getNumBases();
1060  }
1061  return false;
1062  }
1063 
1064  // Check the base classes.
1065  for (CXXRecordDecl::base_class_iterator Base1 = D1CXX->bases_begin(),
1066  BaseEnd1 = D1CXX->bases_end(),
1067  Base2 = D2CXX->bases_begin();
1068  Base1 != BaseEnd1;
1069  ++Base1, ++Base2) {
1070  if (!IsStructurallyEquivalent(Context,
1071  Base1->getType(), Base2->getType())) {
1072  if (Context.Complain) {
1073  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1074  << Context.C2.getTypeDeclType(D2);
1075  Context.Diag2(Base2->getLocStart(), diag::note_odr_base)
1076  << Base2->getType()
1077  << Base2->getSourceRange();
1078  Context.Diag1(Base1->getLocStart(), diag::note_odr_base)
1079  << Base1->getType()
1080  << Base1->getSourceRange();
1081  }
1082  return false;
1083  }
1084 
1085  // Check virtual vs. non-virtual inheritance mismatch.
1086  if (Base1->isVirtual() != Base2->isVirtual()) {
1087  if (Context.Complain) {
1088  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1089  << Context.C2.getTypeDeclType(D2);
1090  Context.Diag2(Base2->getLocStart(),
1091  diag::note_odr_virtual_base)
1092  << Base2->isVirtual() << Base2->getSourceRange();
1093  Context.Diag1(Base1->getLocStart(), diag::note_odr_base)
1094  << Base1->isVirtual()
1095  << Base1->getSourceRange();
1096  }
1097  return false;
1098  }
1099  }
1100  } else if (D1CXX->getNumBases() > 0) {
1101  if (Context.Complain) {
1102  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1103  << Context.C2.getTypeDeclType(D2);
1104  const CXXBaseSpecifier *Base1 = D1CXX->bases_begin();
1105  Context.Diag1(Base1->getLocStart(), diag::note_odr_base)
1106  << Base1->getType()
1107  << Base1->getSourceRange();
1108  Context.Diag2(D2->getLocation(), diag::note_odr_missing_base);
1109  }
1110  return false;
1111  }
1112  }
1113 
1114  // Check the fields for consistency.
1115  RecordDecl::field_iterator Field2 = D2->field_begin(),
1116  Field2End = D2->field_end();
1117  for (RecordDecl::field_iterator Field1 = D1->field_begin(),
1118  Field1End = D1->field_end();
1119  Field1 != Field1End;
1120  ++Field1, ++Field2) {
1121  if (Field2 == Field2End) {
1122  if (Context.Complain) {
1123  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1124  << Context.C2.getTypeDeclType(D2);
1125  Context.Diag1(Field1->getLocation(), diag::note_odr_field)
1126  << Field1->getDeclName() << Field1->getType();
1127  Context.Diag2(D2->getLocation(), diag::note_odr_missing_field);
1128  }
1129  return false;
1130  }
1131 
1132  if (!IsStructurallyEquivalent(Context, *Field1, *Field2))
1133  return false;
1134  }
1135 
1136  if (Field2 != Field2End) {
1137  if (Context.Complain) {
1138  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1139  << Context.C2.getTypeDeclType(D2);
1140  Context.Diag2(Field2->getLocation(), diag::note_odr_field)
1141  << Field2->getDeclName() << Field2->getType();
1142  Context.Diag1(D1->getLocation(), diag::note_odr_missing_field);
1143  }
1144  return false;
1145  }
1146 
1147  return true;
1148 }
1149 
1150 /// \brief Determine structural equivalence of two enums.
1151 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1152  EnumDecl *D1, EnumDecl *D2) {
1154  EC2End = D2->enumerator_end();
1156  EC1End = D1->enumerator_end();
1157  EC1 != EC1End; ++EC1, ++EC2) {
1158  if (EC2 == EC2End) {
1159  if (Context.Complain) {
1160  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1161  << Context.C2.getTypeDeclType(D2);
1162  Context.Diag1(EC1->getLocation(), diag::note_odr_enumerator)
1163  << EC1->getDeclName()
1164  << EC1->getInitVal().toString(10);
1165  Context.Diag2(D2->getLocation(), diag::note_odr_missing_enumerator);
1166  }
1167  return false;
1168  }
1169 
1170  llvm::APSInt Val1 = EC1->getInitVal();
1171  llvm::APSInt Val2 = EC2->getInitVal();
1172  if (!llvm::APSInt::isSameValue(Val1, Val2) ||
1173  !IsStructurallyEquivalent(EC1->getIdentifier(), EC2->getIdentifier())) {
1174  if (Context.Complain) {
1175  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1176  << Context.C2.getTypeDeclType(D2);
1177  Context.Diag2(EC2->getLocation(), diag::note_odr_enumerator)
1178  << EC2->getDeclName()
1179  << EC2->getInitVal().toString(10);
1180  Context.Diag1(EC1->getLocation(), diag::note_odr_enumerator)
1181  << EC1->getDeclName()
1182  << EC1->getInitVal().toString(10);
1183  }
1184  return false;
1185  }
1186  }
1187 
1188  if (EC2 != EC2End) {
1189  if (Context.Complain) {
1190  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1191  << Context.C2.getTypeDeclType(D2);
1192  Context.Diag2(EC2->getLocation(), diag::note_odr_enumerator)
1193  << EC2->getDeclName()
1194  << EC2->getInitVal().toString(10);
1195  Context.Diag1(D1->getLocation(), diag::note_odr_missing_enumerator);
1196  }
1197  return false;
1198  }
1199 
1200  return true;
1201 }
1202 
1203 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1204  TemplateParameterList *Params1,
1205  TemplateParameterList *Params2) {
1206  if (Params1->size() != Params2->size()) {
1207  if (Context.Complain) {
1208  Context.Diag2(Params2->getTemplateLoc(),
1209  diag::err_odr_different_num_template_parameters)
1210  << Params1->size() << Params2->size();
1211  Context.Diag1(Params1->getTemplateLoc(),
1212  diag::note_odr_template_parameter_list);
1213  }
1214  return false;
1215  }
1216 
1217  for (unsigned I = 0, N = Params1->size(); I != N; ++I) {
1218  if (Params1->getParam(I)->getKind() != Params2->getParam(I)->getKind()) {
1219  if (Context.Complain) {
1220  Context.Diag2(Params2->getParam(I)->getLocation(),
1221  diag::err_odr_different_template_parameter_kind);
1222  Context.Diag1(Params1->getParam(I)->getLocation(),
1223  diag::note_odr_template_parameter_here);
1224  }
1225  return false;
1226  }
1227 
1228  if (!Context.IsStructurallyEquivalent(Params1->getParam(I),
1229  Params2->getParam(I))) {
1230 
1231  return false;
1232  }
1233  }
1234 
1235  return true;
1236 }
1237 
1238 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1240  TemplateTypeParmDecl *D2) {
1241  if (D1->isParameterPack() != D2->isParameterPack()) {
1242  if (Context.Complain) {
1243  Context.Diag2(D2->getLocation(), diag::err_odr_parameter_pack_non_pack)
1244  << D2->isParameterPack();
1245  Context.Diag1(D1->getLocation(), diag::note_odr_parameter_pack_non_pack)
1246  << D1->isParameterPack();
1247  }
1248  return false;
1249  }
1250 
1251  return true;
1252 }
1253 
1254 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1257  if (D1->isParameterPack() != D2->isParameterPack()) {
1258  if (Context.Complain) {
1259  Context.Diag2(D2->getLocation(), diag::err_odr_parameter_pack_non_pack)
1260  << D2->isParameterPack();
1261  Context.Diag1(D1->getLocation(), diag::note_odr_parameter_pack_non_pack)
1262  << D1->isParameterPack();
1263  }
1264  return false;
1265  }
1266 
1267  // Check types.
1268  if (!Context.IsStructurallyEquivalent(D1->getType(), D2->getType())) {
1269  if (Context.Complain) {
1270  Context.Diag2(D2->getLocation(),
1271  diag::err_odr_non_type_parameter_type_inconsistent)
1272  << D2->getType() << D1->getType();
1273  Context.Diag1(D1->getLocation(), diag::note_odr_value_here)
1274  << D1->getType();
1275  }
1276  return false;
1277  }
1278 
1279  return true;
1280 }
1281 
1282 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1285  if (D1->isParameterPack() != D2->isParameterPack()) {
1286  if (Context.Complain) {
1287  Context.Diag2(D2->getLocation(), diag::err_odr_parameter_pack_non_pack)
1288  << D2->isParameterPack();
1289  Context.Diag1(D1->getLocation(), diag::note_odr_parameter_pack_non_pack)
1290  << D1->isParameterPack();
1291  }
1292  return false;
1293  }
1294 
1295  // Check template parameter lists.
1296  return IsStructurallyEquivalent(Context, D1->getTemplateParameters(),
1297  D2->getTemplateParameters());
1298 }
1299 
1300 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1301  ClassTemplateDecl *D1,
1302  ClassTemplateDecl *D2) {
1303  // Check template parameters.
1304  if (!IsStructurallyEquivalent(Context,
1305  D1->getTemplateParameters(),
1306  D2->getTemplateParameters()))
1307  return false;
1308 
1309  // Check the templated declaration.
1310  return Context.IsStructurallyEquivalent(D1->getTemplatedDecl(),
1311  D2->getTemplatedDecl());
1312 }
1313 
1314 /// \brief Determine structural equivalence of two declarations.
1315 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1316  Decl *D1, Decl *D2) {
1317  // FIXME: Check for known structural equivalences via a callback of some sort.
1318 
1319  // Check whether we already know that these two declarations are not
1320  // structurally equivalent.
1321  if (Context.NonEquivalentDecls.count(std::make_pair(D1->getCanonicalDecl(),
1322  D2->getCanonicalDecl())))
1323  return false;
1324 
1325  // Determine whether we've already produced a tentative equivalence for D1.
1326  Decl *&EquivToD1 = Context.TentativeEquivalences[D1->getCanonicalDecl()];
1327  if (EquivToD1)
1328  return EquivToD1 == D2->getCanonicalDecl();
1329 
1330  // Produce a tentative equivalence D1 <-> D2, which will be checked later.
1331  EquivToD1 = D2->getCanonicalDecl();
1332  Context.DeclsToCheck.push_back(D1->getCanonicalDecl());
1333  return true;
1334 }
1335 
1337  Decl *D2) {
1338  if (!::IsStructurallyEquivalent(*this, D1, D2))
1339  return false;
1340 
1341  return !Finish();
1342 }
1343 
1345  QualType T2) {
1346  if (!::IsStructurallyEquivalent(*this, T1, T2))
1347  return false;
1348 
1349  return !Finish();
1350 }
1351 
1352 bool StructuralEquivalenceContext::Finish() {
1353  while (!DeclsToCheck.empty()) {
1354  // Check the next declaration.
1355  Decl *D1 = DeclsToCheck.front();
1356  DeclsToCheck.pop_front();
1357 
1358  Decl *D2 = TentativeEquivalences[D1];
1359  assert(D2 && "Unrecorded tentative equivalence?");
1360 
1361  bool Equivalent = true;
1362 
1363  // FIXME: Switch on all declaration kinds. For now, we're just going to
1364  // check the obvious ones.
1365  if (RecordDecl *Record1 = dyn_cast<RecordDecl>(D1)) {
1366  if (RecordDecl *Record2 = dyn_cast<RecordDecl>(D2)) {
1367  // Check for equivalent structure names.
1368  IdentifierInfo *Name1 = Record1->getIdentifier();
1369  if (!Name1 && Record1->getTypedefNameForAnonDecl())
1370  Name1 = Record1->getTypedefNameForAnonDecl()->getIdentifier();
1371  IdentifierInfo *Name2 = Record2->getIdentifier();
1372  if (!Name2 && Record2->getTypedefNameForAnonDecl())
1373  Name2 = Record2->getTypedefNameForAnonDecl()->getIdentifier();
1374  if (!::IsStructurallyEquivalent(Name1, Name2) ||
1375  !::IsStructurallyEquivalent(*this, Record1, Record2))
1376  Equivalent = false;
1377  } else {
1378  // Record/non-record mismatch.
1379  Equivalent = false;
1380  }
1381  } else if (EnumDecl *Enum1 = dyn_cast<EnumDecl>(D1)) {
1382  if (EnumDecl *Enum2 = dyn_cast<EnumDecl>(D2)) {
1383  // Check for equivalent enum names.
1384  IdentifierInfo *Name1 = Enum1->getIdentifier();
1385  if (!Name1 && Enum1->getTypedefNameForAnonDecl())
1386  Name1 = Enum1->getTypedefNameForAnonDecl()->getIdentifier();
1387  IdentifierInfo *Name2 = Enum2->getIdentifier();
1388  if (!Name2 && Enum2->getTypedefNameForAnonDecl())
1389  Name2 = Enum2->getTypedefNameForAnonDecl()->getIdentifier();
1390  if (!::IsStructurallyEquivalent(Name1, Name2) ||
1391  !::IsStructurallyEquivalent(*this, Enum1, Enum2))
1392  Equivalent = false;
1393  } else {
1394  // Enum/non-enum mismatch
1395  Equivalent = false;
1396  }
1397  } else if (TypedefNameDecl *Typedef1 = dyn_cast<TypedefNameDecl>(D1)) {
1398  if (TypedefNameDecl *Typedef2 = dyn_cast<TypedefNameDecl>(D2)) {
1399  if (!::IsStructurallyEquivalent(Typedef1->getIdentifier(),
1400  Typedef2->getIdentifier()) ||
1401  !::IsStructurallyEquivalent(*this,
1402  Typedef1->getUnderlyingType(),
1403  Typedef2->getUnderlyingType()))
1404  Equivalent = false;
1405  } else {
1406  // Typedef/non-typedef mismatch.
1407  Equivalent = false;
1408  }
1409  } else if (ClassTemplateDecl *ClassTemplate1
1410  = dyn_cast<ClassTemplateDecl>(D1)) {
1411  if (ClassTemplateDecl *ClassTemplate2 = dyn_cast<ClassTemplateDecl>(D2)) {
1412  if (!::IsStructurallyEquivalent(ClassTemplate1->getIdentifier(),
1413  ClassTemplate2->getIdentifier()) ||
1414  !::IsStructurallyEquivalent(*this, ClassTemplate1, ClassTemplate2))
1415  Equivalent = false;
1416  } else {
1417  // Class template/non-class-template mismatch.
1418  Equivalent = false;
1419  }
1420  } else if (TemplateTypeParmDecl *TTP1= dyn_cast<TemplateTypeParmDecl>(D1)) {
1421  if (TemplateTypeParmDecl *TTP2 = dyn_cast<TemplateTypeParmDecl>(D2)) {
1422  if (!::IsStructurallyEquivalent(*this, TTP1, TTP2))
1423  Equivalent = false;
1424  } else {
1425  // Kind mismatch.
1426  Equivalent = false;
1427  }
1428  } else if (NonTypeTemplateParmDecl *NTTP1
1429  = dyn_cast<NonTypeTemplateParmDecl>(D1)) {
1430  if (NonTypeTemplateParmDecl *NTTP2
1431  = dyn_cast<NonTypeTemplateParmDecl>(D2)) {
1432  if (!::IsStructurallyEquivalent(*this, NTTP1, NTTP2))
1433  Equivalent = false;
1434  } else {
1435  // Kind mismatch.
1436  Equivalent = false;
1437  }
1438  } else if (TemplateTemplateParmDecl *TTP1
1439  = dyn_cast<TemplateTemplateParmDecl>(D1)) {
1440  if (TemplateTemplateParmDecl *TTP2
1441  = dyn_cast<TemplateTemplateParmDecl>(D2)) {
1442  if (!::IsStructurallyEquivalent(*this, TTP1, TTP2))
1443  Equivalent = false;
1444  } else {
1445  // Kind mismatch.
1446  Equivalent = false;
1447  }
1448  }
1449 
1450  if (!Equivalent) {
1451  // Note that these two declarations are not equivalent (and we already
1452  // know about it).
1453  NonEquivalentDecls.insert(std::make_pair(D1->getCanonicalDecl(),
1454  D2->getCanonicalDecl()));
1455  return true;
1456  }
1457  // FIXME: Check other declaration kinds!
1458  }
1459 
1460  return false;
1461 }
1462 
1463 //----------------------------------------------------------------------------
1464 // Import Types
1465 //----------------------------------------------------------------------------
1466 
1468  Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
1469  << T->getTypeClassName();
1470  return QualType();
1471 }
1472 
1474  switch (T->getKind()) {
1475 #define SHARED_SINGLETON_TYPE(Expansion)
1476 #define BUILTIN_TYPE(Id, SingletonId) \
1477  case BuiltinType::Id: return Importer.getToContext().SingletonId;
1478 #include "clang/AST/BuiltinTypes.def"
1479 
1480  // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
1481  // context supports C++.
1482 
1483  // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
1484  // context supports ObjC.
1485 
1486  case BuiltinType::Char_U:
1487  // The context we're importing from has an unsigned 'char'. If we're
1488  // importing into a context with a signed 'char', translate to
1489  // 'unsigned char' instead.
1490  if (Importer.getToContext().getLangOpts().CharIsSigned)
1491  return Importer.getToContext().UnsignedCharTy;
1492 
1493  return Importer.getToContext().CharTy;
1494 
1495  case BuiltinType::Char_S:
1496  // The context we're importing from has an unsigned 'char'. If we're
1497  // importing into a context with a signed 'char', translate to
1498  // 'unsigned char' instead.
1499  if (!Importer.getToContext().getLangOpts().CharIsSigned)
1500  return Importer.getToContext().SignedCharTy;
1501 
1502  return Importer.getToContext().CharTy;
1503 
1504  case BuiltinType::WChar_S:
1505  case BuiltinType::WChar_U:
1506  // FIXME: If not in C++, shall we translate to the C equivalent of
1507  // wchar_t?
1508  return Importer.getToContext().WCharTy;
1509  }
1510 
1511  llvm_unreachable("Invalid BuiltinType Kind!");
1512 }
1513 
1515  QualType ToElementType = Importer.Import(T->getElementType());
1516  if (ToElementType.isNull())
1517  return QualType();
1518 
1519  return Importer.getToContext().getComplexType(ToElementType);
1520 }
1521 
1523  QualType ToPointeeType = Importer.Import(T->getPointeeType());
1524  if (ToPointeeType.isNull())
1525  return QualType();
1526 
1527  return Importer.getToContext().getPointerType(ToPointeeType);
1528 }
1529 
1531  // FIXME: Check for blocks support in "to" context.
1532  QualType ToPointeeType = Importer.Import(T->getPointeeType());
1533  if (ToPointeeType.isNull())
1534  return QualType();
1535 
1536  return Importer.getToContext().getBlockPointerType(ToPointeeType);
1537 }
1538 
1539 QualType
1541  // FIXME: Check for C++ support in "to" context.
1542  QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten());
1543  if (ToPointeeType.isNull())
1544  return QualType();
1545 
1546  return Importer.getToContext().getLValueReferenceType(ToPointeeType);
1547 }
1548 
1549 QualType
1551  // FIXME: Check for C++0x support in "to" context.
1552  QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten());
1553  if (ToPointeeType.isNull())
1554  return QualType();
1555 
1556  return Importer.getToContext().getRValueReferenceType(ToPointeeType);
1557 }
1558 
1560  // FIXME: Check for C++ support in "to" context.
1561  QualType ToPointeeType = Importer.Import(T->getPointeeType());
1562  if (ToPointeeType.isNull())
1563  return QualType();
1564 
1565  QualType ClassType = Importer.Import(QualType(T->getClass(), 0));
1566  return Importer.getToContext().getMemberPointerType(ToPointeeType,
1567  ClassType.getTypePtr());
1568 }
1569 
1571  QualType ToElementType = Importer.Import(T->getElementType());
1572  if (ToElementType.isNull())
1573  return QualType();
1574 
1575  return Importer.getToContext().getConstantArrayType(ToElementType,
1576  T->getSize(),
1577  T->getSizeModifier(),
1579 }
1580 
1581 QualType
1583  QualType ToElementType = Importer.Import(T->getElementType());
1584  if (ToElementType.isNull())
1585  return QualType();
1586 
1587  return Importer.getToContext().getIncompleteArrayType(ToElementType,
1588  T->getSizeModifier(),
1590 }
1591 
1593  QualType ToElementType = Importer.Import(T->getElementType());
1594  if (ToElementType.isNull())
1595  return QualType();
1596 
1597  Expr *Size = Importer.Import(T->getSizeExpr());
1598  if (!Size)
1599  return QualType();
1600 
1601  SourceRange Brackets = Importer.Import(T->getBracketsRange());
1602  return Importer.getToContext().getVariableArrayType(ToElementType, Size,
1603  T->getSizeModifier(),
1605  Brackets);
1606 }
1607 
1609  QualType ToElementType = Importer.Import(T->getElementType());
1610  if (ToElementType.isNull())
1611  return QualType();
1612 
1613  return Importer.getToContext().getVectorType(ToElementType,
1614  T->getNumElements(),
1615  T->getVectorKind());
1616 }
1617 
1619  QualType ToElementType = Importer.Import(T->getElementType());
1620  if (ToElementType.isNull())
1621  return QualType();
1622 
1623  return Importer.getToContext().getExtVectorType(ToElementType,
1624  T->getNumElements());
1625 }
1626 
1627 QualType
1629  // FIXME: What happens if we're importing a function without a prototype
1630  // into C++? Should we make it variadic?
1631  QualType ToResultType = Importer.Import(T->getReturnType());
1632  if (ToResultType.isNull())
1633  return QualType();
1634 
1635  return Importer.getToContext().getFunctionNoProtoType(ToResultType,
1636  T->getExtInfo());
1637 }
1638 
1640  QualType ToResultType = Importer.Import(T->getReturnType());
1641  if (ToResultType.isNull())
1642  return QualType();
1643 
1644  // Import argument types
1645  SmallVector<QualType, 4> ArgTypes;
1646  for (const auto &A : T->param_types()) {
1647  QualType ArgType = Importer.Import(A);
1648  if (ArgType.isNull())
1649  return QualType();
1650  ArgTypes.push_back(ArgType);
1651  }
1652 
1653  // Import exception types
1654  SmallVector<QualType, 4> ExceptionTypes;
1655  for (const auto &E : T->exceptions()) {
1656  QualType ExceptionType = Importer.Import(E);
1657  if (ExceptionType.isNull())
1658  return QualType();
1659  ExceptionTypes.push_back(ExceptionType);
1660  }
1661 
1664 
1665  ToEPI.ExtInfo = FromEPI.ExtInfo;
1666  ToEPI.Variadic = FromEPI.Variadic;
1667  ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
1668  ToEPI.TypeQuals = FromEPI.TypeQuals;
1669  ToEPI.RefQualifier = FromEPI.RefQualifier;
1670  ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
1671  ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
1672  ToEPI.ExceptionSpec.NoexceptExpr =
1673  Importer.Import(FromEPI.ExceptionSpec.NoexceptExpr);
1674  ToEPI.ExceptionSpec.SourceDecl = cast_or_null<FunctionDecl>(
1675  Importer.Import(FromEPI.ExceptionSpec.SourceDecl));
1676  ToEPI.ExceptionSpec.SourceTemplate = cast_or_null<FunctionDecl>(
1677  Importer.Import(FromEPI.ExceptionSpec.SourceTemplate));
1678 
1679  return Importer.getToContext().getFunctionType(ToResultType, ArgTypes, ToEPI);
1680 }
1681 
1683  QualType ToInnerType = Importer.Import(T->getInnerType());
1684  if (ToInnerType.isNull())
1685  return QualType();
1686 
1687  return Importer.getToContext().getParenType(ToInnerType);
1688 }
1689 
1691  TypedefNameDecl *ToDecl
1692  = dyn_cast_or_null<TypedefNameDecl>(Importer.Import(T->getDecl()));
1693  if (!ToDecl)
1694  return QualType();
1695 
1696  return Importer.getToContext().getTypeDeclType(ToDecl);
1697 }
1698 
1700  Expr *ToExpr = Importer.Import(T->getUnderlyingExpr());
1701  if (!ToExpr)
1702  return QualType();
1703 
1704  return Importer.getToContext().getTypeOfExprType(ToExpr);
1705 }
1706 
1708  QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType());
1709  if (ToUnderlyingType.isNull())
1710  return QualType();
1711 
1712  return Importer.getToContext().getTypeOfType(ToUnderlyingType);
1713 }
1714 
1716  // FIXME: Make sure that the "to" context supports C++0x!
1717  Expr *ToExpr = Importer.Import(T->getUnderlyingExpr());
1718  if (!ToExpr)
1719  return QualType();
1720 
1721  QualType UnderlyingType = Importer.Import(T->getUnderlyingType());
1722  if (UnderlyingType.isNull())
1723  return QualType();
1724 
1725  return Importer.getToContext().getDecltypeType(ToExpr, UnderlyingType);
1726 }
1727 
1729  QualType ToBaseType = Importer.Import(T->getBaseType());
1730  QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType());
1731  if (ToBaseType.isNull() || ToUnderlyingType.isNull())
1732  return QualType();
1733 
1734  return Importer.getToContext().getUnaryTransformType(ToBaseType,
1735  ToUnderlyingType,
1736  T->getUTTKind());
1737 }
1738 
1740  // FIXME: Make sure that the "to" context supports C++11!
1741  QualType FromDeduced = T->getDeducedType();
1742  QualType ToDeduced;
1743  if (!FromDeduced.isNull()) {
1744  ToDeduced = Importer.Import(FromDeduced);
1745  if (ToDeduced.isNull())
1746  return QualType();
1747  }
1748 
1749  return Importer.getToContext().getAutoType(ToDeduced, T->isDecltypeAuto(),
1750  /*IsDependent*/false);
1751 }
1752 
1754  RecordDecl *ToDecl
1755  = dyn_cast_or_null<RecordDecl>(Importer.Import(T->getDecl()));
1756  if (!ToDecl)
1757  return QualType();
1758 
1759  return Importer.getToContext().getTagDeclType(ToDecl);
1760 }
1761 
1763  EnumDecl *ToDecl
1764  = dyn_cast_or_null<EnumDecl>(Importer.Import(T->getDecl()));
1765  if (!ToDecl)
1766  return QualType();
1767 
1768  return Importer.getToContext().getTagDeclType(ToDecl);
1769 }
1770 
1772  QualType FromModifiedType = T->getModifiedType();
1773  QualType FromEquivalentType = T->getEquivalentType();
1774  QualType ToModifiedType;
1775  QualType ToEquivalentType;
1776 
1777  if (!FromModifiedType.isNull()) {
1778  ToModifiedType = Importer.Import(FromModifiedType);
1779  if (ToModifiedType.isNull())
1780  return QualType();
1781  }
1782  if (!FromEquivalentType.isNull()) {
1783  ToEquivalentType = Importer.Import(FromEquivalentType);
1784  if (ToEquivalentType.isNull())
1785  return QualType();
1786  }
1787 
1788  return Importer.getToContext().getAttributedType(T->getAttrKind(),
1789  ToModifiedType, ToEquivalentType);
1790 }
1791 
1793  const TemplateSpecializationType *T) {
1794  TemplateName ToTemplate = Importer.Import(T->getTemplateName());
1795  if (ToTemplate.isNull())
1796  return QualType();
1797 
1798  SmallVector<TemplateArgument, 2> ToTemplateArgs;
1799  if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToTemplateArgs))
1800  return QualType();
1801 
1802  QualType ToCanonType;
1803  if (!QualType(T, 0).isCanonical()) {
1804  QualType FromCanonType
1805  = Importer.getFromContext().getCanonicalType(QualType(T, 0));
1806  ToCanonType =Importer.Import(FromCanonType);
1807  if (ToCanonType.isNull())
1808  return QualType();
1809  }
1810  return Importer.getToContext().getTemplateSpecializationType(ToTemplate,
1811  ToTemplateArgs.data(),
1812  ToTemplateArgs.size(),
1813  ToCanonType);
1814 }
1815 
1817  NestedNameSpecifier *ToQualifier = nullptr;
1818  // Note: the qualifier in an ElaboratedType is optional.
1819  if (T->getQualifier()) {
1820  ToQualifier = Importer.Import(T->getQualifier());
1821  if (!ToQualifier)
1822  return QualType();
1823  }
1824 
1825  QualType ToNamedType = Importer.Import(T->getNamedType());
1826  if (ToNamedType.isNull())
1827  return QualType();
1828 
1829  return Importer.getToContext().getElaboratedType(T->getKeyword(),
1830  ToQualifier, ToNamedType);
1831 }
1832 
1834  ObjCInterfaceDecl *Class
1835  = dyn_cast_or_null<ObjCInterfaceDecl>(Importer.Import(T->getDecl()));
1836  if (!Class)
1837  return QualType();
1838 
1839  return Importer.getToContext().getObjCInterfaceType(Class);
1840 }
1841 
1843  QualType ToBaseType = Importer.Import(T->getBaseType());
1844  if (ToBaseType.isNull())
1845  return QualType();
1846 
1847  SmallVector<QualType, 4> TypeArgs;
1848  for (auto TypeArg : T->getTypeArgsAsWritten()) {
1849  QualType ImportedTypeArg = Importer.Import(TypeArg);
1850  if (ImportedTypeArg.isNull())
1851  return QualType();
1852 
1853  TypeArgs.push_back(ImportedTypeArg);
1854  }
1855 
1857  for (auto *P : T->quals()) {
1858  ObjCProtocolDecl *Protocol
1859  = dyn_cast_or_null<ObjCProtocolDecl>(Importer.Import(P));
1860  if (!Protocol)
1861  return QualType();
1862  Protocols.push_back(Protocol);
1863  }
1864 
1865  return Importer.getToContext().getObjCObjectType(ToBaseType, TypeArgs,
1866  Protocols,
1867  T->isKindOfTypeAsWritten());
1868 }
1869 
1870 QualType
1872  QualType ToPointeeType = Importer.Import(T->getPointeeType());
1873  if (ToPointeeType.isNull())
1874  return QualType();
1875 
1876  return Importer.getToContext().getObjCObjectPointerType(ToPointeeType);
1877 }
1878 
1879 //----------------------------------------------------------------------------
1880 // Import Declarations
1881 //----------------------------------------------------------------------------
1883  DeclContext *&LexicalDC,
1884  DeclarationName &Name,
1885  NamedDecl *&ToD,
1886  SourceLocation &Loc) {
1887  // Import the context of this declaration.
1888  DC = Importer.ImportContext(D->getDeclContext());
1889  if (!DC)
1890  return true;
1891 
1892  LexicalDC = DC;
1893  if (D->getDeclContext() != D->getLexicalDeclContext()) {
1894  LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
1895  if (!LexicalDC)
1896  return true;
1897  }
1898 
1899  // Import the name of this declaration.
1900  Name = Importer.Import(D->getDeclName());
1901  if (D->getDeclName() && !Name)
1902  return true;
1903 
1904  // Import the location of this declaration.
1905  Loc = Importer.Import(D->getLocation());
1906  ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
1907  return false;
1908 }
1909 
1911  if (!FromD)
1912  return;
1913 
1914  if (!ToD) {
1915  ToD = Importer.Import(FromD);
1916  if (!ToD)
1917  return;
1918  }
1919 
1920  if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
1921  if (RecordDecl *ToRecord = cast_or_null<RecordDecl>(ToD)) {
1922  if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && !ToRecord->getDefinition()) {
1923  ImportDefinition(FromRecord, ToRecord);
1924  }
1925  }
1926  return;
1927  }
1928 
1929  if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
1930  if (EnumDecl *ToEnum = cast_or_null<EnumDecl>(ToD)) {
1931  if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
1932  ImportDefinition(FromEnum, ToEnum);
1933  }
1934  }
1935  return;
1936  }
1937 }
1938 
1939 void
1941  DeclarationNameInfo& To) {
1942  // NOTE: To.Name and To.Loc are already imported.
1943  // We only have to import To.LocInfo.
1944  switch (To.getName().getNameKind()) {
1950  return;
1951 
1953  SourceRange Range = From.getCXXOperatorNameRange();
1954  To.setCXXOperatorNameRange(Importer.Import(Range));
1955  return;
1956  }
1959  To.setCXXLiteralOperatorNameLoc(Importer.Import(Loc));
1960  return;
1961  }
1965  TypeSourceInfo *FromTInfo = From.getNamedTypeInfo();
1966  To.setNamedTypeInfo(Importer.Import(FromTInfo));
1967  return;
1968  }
1969  }
1970  llvm_unreachable("Unknown name kind.");
1971 }
1972 
1973 void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) {
1974  if (Importer.isMinimalImport() && !ForceImport) {
1975  Importer.ImportContext(FromDC);
1976  return;
1977  }
1978 
1979  for (auto *From : FromDC->decls())
1980  Importer.Import(From);
1981 }
1982 
1985  if (To->getDefinition() || To->isBeingDefined()) {
1986  if (Kind == IDK_Everything)
1987  ImportDeclContext(From, /*ForceImport=*/true);
1988 
1989  return false;
1990  }
1991 
1992  To->startDefinition();
1993 
1994  // Add base classes.
1995  if (CXXRecordDecl *ToCXX = dyn_cast<CXXRecordDecl>(To)) {
1996  CXXRecordDecl *FromCXX = cast<CXXRecordDecl>(From);
1997 
1998  struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
1999  struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2000  ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor;
2001  ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers;
2002  ToData.Aggregate = FromData.Aggregate;
2003  ToData.PlainOldData = FromData.PlainOldData;
2004  ToData.Empty = FromData.Empty;
2005  ToData.Polymorphic = FromData.Polymorphic;
2006  ToData.Abstract = FromData.Abstract;
2007  ToData.IsStandardLayout = FromData.IsStandardLayout;
2008  ToData.HasNoNonEmptyBases = FromData.HasNoNonEmptyBases;
2009  ToData.HasPrivateFields = FromData.HasPrivateFields;
2010  ToData.HasProtectedFields = FromData.HasProtectedFields;
2011  ToData.HasPublicFields = FromData.HasPublicFields;
2012  ToData.HasMutableFields = FromData.HasMutableFields;
2013  ToData.HasVariantMembers = FromData.HasVariantMembers;
2014  ToData.HasOnlyCMembers = FromData.HasOnlyCMembers;
2015  ToData.HasInClassInitializer = FromData.HasInClassInitializer;
2016  ToData.HasUninitializedReferenceMember
2017  = FromData.HasUninitializedReferenceMember;
2018  ToData.NeedOverloadResolutionForMoveConstructor
2019  = FromData.NeedOverloadResolutionForMoveConstructor;
2020  ToData.NeedOverloadResolutionForMoveAssignment
2021  = FromData.NeedOverloadResolutionForMoveAssignment;
2022  ToData.NeedOverloadResolutionForDestructor
2023  = FromData.NeedOverloadResolutionForDestructor;
2024  ToData.DefaultedMoveConstructorIsDeleted
2025  = FromData.DefaultedMoveConstructorIsDeleted;
2026  ToData.DefaultedMoveAssignmentIsDeleted
2027  = FromData.DefaultedMoveAssignmentIsDeleted;
2028  ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted;
2029  ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers;
2030  ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor;
2031  ToData.HasConstexprNonCopyMoveConstructor
2032  = FromData.HasConstexprNonCopyMoveConstructor;
2033  ToData.DefaultedDefaultConstructorIsConstexpr
2034  = FromData.DefaultedDefaultConstructorIsConstexpr;
2035  ToData.HasConstexprDefaultConstructor
2036  = FromData.HasConstexprDefaultConstructor;
2037  ToData.HasNonLiteralTypeFieldsOrBases
2038  = FromData.HasNonLiteralTypeFieldsOrBases;
2039  // ComputedVisibleConversions not imported.
2040  ToData.UserProvidedDefaultConstructor
2041  = FromData.UserProvidedDefaultConstructor;
2042  ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers;
2043  ToData.ImplicitCopyConstructorHasConstParam
2044  = FromData.ImplicitCopyConstructorHasConstParam;
2045  ToData.ImplicitCopyAssignmentHasConstParam
2046  = FromData.ImplicitCopyAssignmentHasConstParam;
2047  ToData.HasDeclaredCopyConstructorWithConstParam
2048  = FromData.HasDeclaredCopyConstructorWithConstParam;
2049  ToData.HasDeclaredCopyAssignmentWithConstParam
2050  = FromData.HasDeclaredCopyAssignmentWithConstParam;
2051  ToData.IsLambda = FromData.IsLambda;
2052 
2054  for (const auto &Base1 : FromCXX->bases()) {
2055  QualType T = Importer.Import(Base1.getType());
2056  if (T.isNull())
2057  return true;
2058 
2059  SourceLocation EllipsisLoc;
2060  if (Base1.isPackExpansion())
2061  EllipsisLoc = Importer.Import(Base1.getEllipsisLoc());
2062 
2063  // Ensure that we have a definition for the base.
2064  ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl());
2065 
2066  Bases.push_back(
2067  new (Importer.getToContext())
2068  CXXBaseSpecifier(Importer.Import(Base1.getSourceRange()),
2069  Base1.isVirtual(),
2070  Base1.isBaseOfClass(),
2071  Base1.getAccessSpecifierAsWritten(),
2072  Importer.Import(Base1.getTypeSourceInfo()),
2073  EllipsisLoc));
2074  }
2075  if (!Bases.empty())
2076  ToCXX->setBases(Bases.data(), Bases.size());
2077  }
2078 
2079  if (shouldForceImportDeclContext(Kind))
2080  ImportDeclContext(From, /*ForceImport=*/true);
2081 
2082  To->completeDefinition();
2083  return false;
2084 }
2085 
2088  if (To->getAnyInitializer())
2089  return false;
2090 
2091  // FIXME: Can we really import any initializer? Alternatively, we could force
2092  // ourselves to import every declaration of a variable and then only use
2093  // getInit() here.
2094  To->setInit(Importer.Import(const_cast<Expr *>(From->getAnyInitializer())));
2095 
2096  // FIXME: Other bits to merge?
2097 
2098  return false;
2099 }
2100 
2103  if (To->getDefinition() || To->isBeingDefined()) {
2104  if (Kind == IDK_Everything)
2105  ImportDeclContext(From, /*ForceImport=*/true);
2106  return false;
2107  }
2108 
2109  To->startDefinition();
2110 
2111  QualType T = Importer.Import(Importer.getFromContext().getTypeDeclType(From));
2112  if (T.isNull())
2113  return true;
2114 
2115  QualType ToPromotionType = Importer.Import(From->getPromotionType());
2116  if (ToPromotionType.isNull())
2117  return true;
2118 
2119  if (shouldForceImportDeclContext(Kind))
2120  ImportDeclContext(From, /*ForceImport=*/true);
2121 
2122  // FIXME: we might need to merge the number of positive or negative bits
2123  // if the enumerator lists don't match.
2124  To->completeDefinition(T, ToPromotionType,
2125  From->getNumPositiveBits(),
2126  From->getNumNegativeBits());
2127  return false;
2128 }
2129 
2131  TemplateParameterList *Params) {
2132  SmallVector<NamedDecl *, 4> ToParams;
2133  ToParams.reserve(Params->size());
2134  for (TemplateParameterList::iterator P = Params->begin(),
2135  PEnd = Params->end();
2136  P != PEnd; ++P) {
2137  Decl *To = Importer.Import(*P);
2138  if (!To)
2139  return nullptr;
2140 
2141  ToParams.push_back(cast<NamedDecl>(To));
2142  }
2143 
2144  return TemplateParameterList::Create(Importer.getToContext(),
2145  Importer.Import(Params->getTemplateLoc()),
2146  Importer.Import(Params->getLAngleLoc()),
2147  ToParams.data(), ToParams.size(),
2148  Importer.Import(Params->getRAngleLoc()));
2149 }
2150 
2153  switch (From.getKind()) {
2155  return TemplateArgument();
2156 
2157  case TemplateArgument::Type: {
2158  QualType ToType = Importer.Import(From.getAsType());
2159  if (ToType.isNull())
2160  return TemplateArgument();
2161  return TemplateArgument(ToType);
2162  }
2163 
2165  QualType ToType = Importer.Import(From.getIntegralType());
2166  if (ToType.isNull())
2167  return TemplateArgument();
2168  return TemplateArgument(From, ToType);
2169  }
2170 
2172  ValueDecl *To = cast_or_null<ValueDecl>(Importer.Import(From.getAsDecl()));
2173  QualType ToType = Importer.Import(From.getParamTypeForDecl());
2174  if (!To || ToType.isNull())
2175  return TemplateArgument();
2176  return TemplateArgument(To, ToType);
2177  }
2178 
2180  QualType ToType = Importer.Import(From.getNullPtrType());
2181  if (ToType.isNull())
2182  return TemplateArgument();
2183  return TemplateArgument(ToType, /*isNullPtr*/true);
2184  }
2185 
2187  TemplateName ToTemplate = Importer.Import(From.getAsTemplate());
2188  if (ToTemplate.isNull())
2189  return TemplateArgument();
2190 
2191  return TemplateArgument(ToTemplate);
2192  }
2193 
2195  TemplateName ToTemplate
2196  = Importer.Import(From.getAsTemplateOrTemplatePattern());
2197  if (ToTemplate.isNull())
2198  return TemplateArgument();
2199 
2200  return TemplateArgument(ToTemplate, From.getNumTemplateExpansions());
2201  }
2202 
2204  if (Expr *ToExpr = Importer.Import(From.getAsExpr()))
2205  return TemplateArgument(ToExpr);
2206  return TemplateArgument();
2207 
2208  case TemplateArgument::Pack: {
2210  ToPack.reserve(From.pack_size());
2211  if (ImportTemplateArguments(From.pack_begin(), From.pack_size(), ToPack))
2212  return TemplateArgument();
2213 
2214  TemplateArgument *ToArgs
2215  = new (Importer.getToContext()) TemplateArgument[ToPack.size()];
2216  std::copy(ToPack.begin(), ToPack.end(), ToArgs);
2217  return TemplateArgument(ToArgs, ToPack.size());
2218  }
2219  }
2220 
2221  llvm_unreachable("Invalid template argument kind");
2222 }
2223 
2225  unsigned NumFromArgs,
2227  for (unsigned I = 0; I != NumFromArgs; ++I) {
2228  TemplateArgument To = ImportTemplateArgument(FromArgs[I]);
2229  if (To.isNull() && !FromArgs[I].isNull())
2230  return true;
2231 
2232  ToArgs.push_back(To);
2233  }
2234 
2235  return false;
2236 }
2237 
2239  RecordDecl *ToRecord, bool Complain) {
2240  // Eliminate a potential failure point where we attempt to re-import
2241  // something we're trying to import while completing ToRecord.
2242  Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord);
2243  if (ToOrigin) {
2244  RecordDecl *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin);
2245  if (ToOriginRecord)
2246  ToRecord = ToOriginRecord;
2247  }
2248 
2249  StructuralEquivalenceContext Ctx(Importer.getFromContext(),
2250  ToRecord->getASTContext(),
2251  Importer.getNonEquivalentDecls(),
2252  false, Complain);
2253  return Ctx.IsStructurallyEquivalent(FromRecord, ToRecord);
2254 }
2255 
2257  bool Complain) {
2258  StructuralEquivalenceContext Ctx(
2259  Importer.getFromContext(), Importer.getToContext(),
2260  Importer.getNonEquivalentDecls(), false, Complain);
2261  return Ctx.IsStructurallyEquivalent(FromVar, ToVar);
2262 }
2263 
2265  StructuralEquivalenceContext Ctx(Importer.getFromContext(),
2266  Importer.getToContext(),
2267  Importer.getNonEquivalentDecls());
2268  return Ctx.IsStructurallyEquivalent(FromEnum, ToEnum);
2269 }
2270 
2272  EnumConstantDecl *ToEC)
2273 {
2274  const llvm::APSInt &FromVal = FromEC->getInitVal();
2275  const llvm::APSInt &ToVal = ToEC->getInitVal();
2276 
2277  return FromVal.isSigned() == ToVal.isSigned() &&
2278  FromVal.getBitWidth() == ToVal.getBitWidth() &&
2279  FromVal == ToVal;
2280 }
2281 
2283  ClassTemplateDecl *To) {
2284  StructuralEquivalenceContext Ctx(Importer.getFromContext(),
2285  Importer.getToContext(),
2286  Importer.getNonEquivalentDecls());
2287  return Ctx.IsStructurallyEquivalent(From, To);
2288 }
2289 
2291  VarTemplateDecl *To) {
2292  StructuralEquivalenceContext Ctx(Importer.getFromContext(),
2293  Importer.getToContext(),
2294  Importer.getNonEquivalentDecls());
2295  return Ctx.IsStructurallyEquivalent(From, To);
2296 }
2297 
2299  Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2300  << D->getDeclKindName();
2301  return nullptr;
2302 }
2303 
2305  TranslationUnitDecl *ToD =
2306  Importer.getToContext().getTranslationUnitDecl();
2307 
2308  Importer.Imported(D, ToD);
2309 
2310  return ToD;
2311 }
2312 
2314  // Import the major distinguishing characteristics of this namespace.
2315  DeclContext *DC, *LexicalDC;
2316  DeclarationName Name;
2317  SourceLocation Loc;
2318  NamedDecl *ToD;
2319  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2320  return nullptr;
2321  if (ToD)
2322  return ToD;
2323 
2324  NamespaceDecl *MergeWithNamespace = nullptr;
2325  if (!Name) {
2326  // This is an anonymous namespace. Adopt an existing anonymous
2327  // namespace if we can.
2328  // FIXME: Not testable.
2329  if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(DC))
2330  MergeWithNamespace = TU->getAnonymousNamespace();
2331  else
2332  MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace();
2333  } else {
2334  SmallVector<NamedDecl *, 4> ConflictingDecls;
2335  SmallVector<NamedDecl *, 2> FoundDecls;
2336  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
2337  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
2338  if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Namespace))
2339  continue;
2340 
2341  if (NamespaceDecl *FoundNS = dyn_cast<NamespaceDecl>(FoundDecls[I])) {
2342  MergeWithNamespace = FoundNS;
2343  ConflictingDecls.clear();
2344  break;
2345  }
2346 
2347  ConflictingDecls.push_back(FoundDecls[I]);
2348  }
2349 
2350  if (!ConflictingDecls.empty()) {
2351  Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace,
2352  ConflictingDecls.data(),
2353  ConflictingDecls.size());
2354  }
2355  }
2356 
2357  // Create the "to" namespace, if needed.
2358  NamespaceDecl *ToNamespace = MergeWithNamespace;
2359  if (!ToNamespace) {
2360  ToNamespace = NamespaceDecl::Create(Importer.getToContext(), DC,
2361  D->isInline(),
2362  Importer.Import(D->getLocStart()),
2363  Loc, Name.getAsIdentifierInfo(),
2364  /*PrevDecl=*/nullptr);
2365  ToNamespace->setLexicalDeclContext(LexicalDC);
2366  LexicalDC->addDeclInternal(ToNamespace);
2367 
2368  // If this is an anonymous namespace, register it as the anonymous
2369  // namespace within its context.
2370  if (!Name) {
2371  if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(DC))
2372  TU->setAnonymousNamespace(ToNamespace);
2373  else
2374  cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
2375  }
2376  }
2377  Importer.Imported(D, ToNamespace);
2378 
2379  ImportDeclContext(D);
2380 
2381  return ToNamespace;
2382 }
2383 
2385  // Import the major distinguishing characteristics of this typedef.
2386  DeclContext *DC, *LexicalDC;
2387  DeclarationName Name;
2388  SourceLocation Loc;
2389  NamedDecl *ToD;
2390  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2391  return nullptr;
2392  if (ToD)
2393  return ToD;
2394 
2395  // If this typedef is not in block scope, determine whether we've
2396  // seen a typedef with the same name (that we can merge with) or any
2397  // other entity by that name (which name lookup could conflict with).
2398  if (!DC->isFunctionOrMethod()) {
2399  SmallVector<NamedDecl *, 4> ConflictingDecls;
2400  unsigned IDNS = Decl::IDNS_Ordinary;
2401  SmallVector<NamedDecl *, 2> FoundDecls;
2402  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
2403  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
2404  if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
2405  continue;
2406  if (TypedefNameDecl *FoundTypedef =
2407  dyn_cast<TypedefNameDecl>(FoundDecls[I])) {
2408  if (Importer.IsStructurallyEquivalent(D->getUnderlyingType(),
2409  FoundTypedef->getUnderlyingType()))
2410  return Importer.Imported(D, FoundTypedef);
2411  }
2412 
2413  ConflictingDecls.push_back(FoundDecls[I]);
2414  }
2415 
2416  if (!ConflictingDecls.empty()) {
2417  Name = Importer.HandleNameConflict(Name, DC, IDNS,
2418  ConflictingDecls.data(),
2419  ConflictingDecls.size());
2420  if (!Name)
2421  return nullptr;
2422  }
2423  }
2424 
2425  // Import the underlying type of this typedef;
2426  QualType T = Importer.Import(D->getUnderlyingType());
2427  if (T.isNull())
2428  return nullptr;
2429 
2430  // Create the new typedef node.
2431  TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
2432  SourceLocation StartL = Importer.Import(D->getLocStart());
2433  TypedefNameDecl *ToTypedef;
2434  if (IsAlias)
2435  ToTypedef = TypeAliasDecl::Create(Importer.getToContext(), DC,
2436  StartL, Loc,
2437  Name.getAsIdentifierInfo(),
2438  TInfo);
2439  else
2440  ToTypedef = TypedefDecl::Create(Importer.getToContext(), DC,
2441  StartL, Loc,
2442  Name.getAsIdentifierInfo(),
2443  TInfo);
2444 
2445  ToTypedef->setAccess(D->getAccess());
2446  ToTypedef->setLexicalDeclContext(LexicalDC);
2447  Importer.Imported(D, ToTypedef);
2448  LexicalDC->addDeclInternal(ToTypedef);
2449 
2450  return ToTypedef;
2451 }
2452 
2454  return VisitTypedefNameDecl(D, /*IsAlias=*/false);
2455 }
2456 
2458  return VisitTypedefNameDecl(D, /*IsAlias=*/true);
2459 }
2460 
2462  // Import the major distinguishing characteristics of this enum.
2463  DeclContext *DC, *LexicalDC;
2464  DeclarationName Name;
2465  SourceLocation Loc;
2466  NamedDecl *ToD;
2467  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2468  return nullptr;
2469  if (ToD)
2470  return ToD;
2471 
2472  // Figure out what enum name we're looking for.
2473  unsigned IDNS = Decl::IDNS_Tag;
2474  DeclarationName SearchName = Name;
2475  if (!SearchName && D->getTypedefNameForAnonDecl()) {
2476  SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName());
2477  IDNS = Decl::IDNS_Ordinary;
2478  } else if (Importer.getToContext().getLangOpts().CPlusPlus)
2479  IDNS |= Decl::IDNS_Ordinary;
2480 
2481  // We may already have an enum of the same name; try to find and match it.
2482  if (!DC->isFunctionOrMethod() && SearchName) {
2483  SmallVector<NamedDecl *, 4> ConflictingDecls;
2484  SmallVector<NamedDecl *, 2> FoundDecls;
2485  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
2486  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
2487  if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
2488  continue;
2489 
2490  Decl *Found = FoundDecls[I];
2491  if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
2492  if (const TagType *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
2493  Found = Tag->getDecl();
2494  }
2495 
2496  if (EnumDecl *FoundEnum = dyn_cast<EnumDecl>(Found)) {
2497  if (IsStructuralMatch(D, FoundEnum))
2498  return Importer.Imported(D, FoundEnum);
2499  }
2500 
2501  ConflictingDecls.push_back(FoundDecls[I]);
2502  }
2503 
2504  if (!ConflictingDecls.empty()) {
2505  Name = Importer.HandleNameConflict(Name, DC, IDNS,
2506  ConflictingDecls.data(),
2507  ConflictingDecls.size());
2508  }
2509  }
2510 
2511  // Create the enum declaration.
2512  EnumDecl *D2 = EnumDecl::Create(Importer.getToContext(), DC,
2513  Importer.Import(D->getLocStart()),
2514  Loc, Name.getAsIdentifierInfo(), nullptr,
2515  D->isScoped(), D->isScopedUsingClassTag(),
2516  D->isFixed());
2517  // Import the qualifier, if any.
2518  D2->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
2519  D2->setAccess(D->getAccess());
2520  D2->setLexicalDeclContext(LexicalDC);
2521  Importer.Imported(D, D2);
2522  LexicalDC->addDeclInternal(D2);
2523 
2524  // Import the integer type.
2525  QualType ToIntegerType = Importer.Import(D->getIntegerType());
2526  if (ToIntegerType.isNull())
2527  return nullptr;
2528  D2->setIntegerType(ToIntegerType);
2529 
2530  // Import the definition
2531  if (D->isCompleteDefinition() && ImportDefinition(D, D2))
2532  return nullptr;
2533 
2534  return D2;
2535 }
2536 
2538  // If this record has a definition in the translation unit we're coming from,
2539  // but this particular declaration is not that definition, import the
2540  // definition and map to that.
2541  TagDecl *Definition = D->getDefinition();
2542  if (Definition && Definition != D) {
2543  Decl *ImportedDef = Importer.Import(Definition);
2544  if (!ImportedDef)
2545  return nullptr;
2546 
2547  return Importer.Imported(D, ImportedDef);
2548  }
2549 
2550  // Import the major distinguishing characteristics of this record.
2551  DeclContext *DC, *LexicalDC;
2552  DeclarationName Name;
2553  SourceLocation Loc;
2554  NamedDecl *ToD;
2555  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2556  return nullptr;
2557  if (ToD)
2558  return ToD;
2559 
2560  // Figure out what structure name we're looking for.
2561  unsigned IDNS = Decl::IDNS_Tag;
2562  DeclarationName SearchName = Name;
2563  if (!SearchName && D->getTypedefNameForAnonDecl()) {
2564  SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName());
2565  IDNS = Decl::IDNS_Ordinary;
2566  } else if (Importer.getToContext().getLangOpts().CPlusPlus)
2567  IDNS |= Decl::IDNS_Ordinary;
2568 
2569  // We may already have a record of the same name; try to find and match it.
2570  RecordDecl *AdoptDecl = nullptr;
2571  if (!DC->isFunctionOrMethod()) {
2572  SmallVector<NamedDecl *, 4> ConflictingDecls;
2573  SmallVector<NamedDecl *, 2> FoundDecls;
2574  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
2575  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
2576  if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
2577  continue;
2578 
2579  Decl *Found = FoundDecls[I];
2580  if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
2581  if (const TagType *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
2582  Found = Tag->getDecl();
2583  }
2584 
2585  if (RecordDecl *FoundRecord = dyn_cast<RecordDecl>(Found)) {
2586  if (D->isAnonymousStructOrUnion() &&
2587  FoundRecord->isAnonymousStructOrUnion()) {
2588  // If both anonymous structs/unions are in a record context, make sure
2589  // they occur in the same location in the context records.
2590  if (Optional<unsigned> Index1
2592  if (Optional<unsigned> Index2 =
2593  findAnonymousStructOrUnionIndex(FoundRecord)) {
2594  if (*Index1 != *Index2)
2595  continue;
2596  }
2597  }
2598  }
2599 
2600  if (RecordDecl *FoundDef = FoundRecord->getDefinition()) {
2601  if ((SearchName && !D->isCompleteDefinition())
2602  || (D->isCompleteDefinition() &&
2604  == FoundDef->isAnonymousStructOrUnion() &&
2605  IsStructuralMatch(D, FoundDef))) {
2606  // The record types structurally match, or the "from" translation
2607  // unit only had a forward declaration anyway; call it the same
2608  // function.
2609  // FIXME: For C++, we should also merge methods here.
2610  return Importer.Imported(D, FoundDef);
2611  }
2612  } else if (!D->isCompleteDefinition()) {
2613  // We have a forward declaration of this type, so adopt that forward
2614  // declaration rather than building a new one.
2615 
2616  // If one or both can be completed from external storage then try one
2617  // last time to complete and compare them before doing this.
2618 
2619  if (FoundRecord->hasExternalLexicalStorage() &&
2620  !FoundRecord->isCompleteDefinition())
2621  FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord);
2622  if (D->hasExternalLexicalStorage())
2624 
2625  if (FoundRecord->isCompleteDefinition() &&
2626  D->isCompleteDefinition() &&
2627  !IsStructuralMatch(D, FoundRecord))
2628  continue;
2629 
2630  AdoptDecl = FoundRecord;
2631  continue;
2632  } else if (!SearchName) {
2633  continue;
2634  }
2635  }
2636 
2637  ConflictingDecls.push_back(FoundDecls[I]);
2638  }
2639 
2640  if (!ConflictingDecls.empty() && SearchName) {
2641  Name = Importer.HandleNameConflict(Name, DC, IDNS,
2642  ConflictingDecls.data(),
2643  ConflictingDecls.size());
2644  }
2645  }
2646 
2647  // Create the record declaration.
2648  RecordDecl *D2 = AdoptDecl;
2649  SourceLocation StartLoc = Importer.Import(D->getLocStart());
2650  if (!D2) {
2651  if (isa<CXXRecordDecl>(D)) {
2652  CXXRecordDecl *D2CXX = CXXRecordDecl::Create(Importer.getToContext(),
2653  D->getTagKind(),
2654  DC, StartLoc, Loc,
2655  Name.getAsIdentifierInfo());
2656  D2 = D2CXX;
2657  D2->setAccess(D->getAccess());
2658  } else {
2659  D2 = RecordDecl::Create(Importer.getToContext(), D->getTagKind(),
2660  DC, StartLoc, Loc, Name.getAsIdentifierInfo());
2661  }
2662 
2663  D2->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
2664  D2->setLexicalDeclContext(LexicalDC);
2665  LexicalDC->addDeclInternal(D2);
2666  if (D->isAnonymousStructOrUnion())
2667  D2->setAnonymousStructOrUnion(true);
2668  }
2669 
2670  Importer.Imported(D, D2);
2671 
2673  return nullptr;
2674 
2675  return D2;
2676 }
2677 
2679  // Import the major distinguishing characteristics of this enumerator.
2680  DeclContext *DC, *LexicalDC;
2681  DeclarationName Name;
2682  SourceLocation Loc;
2683  NamedDecl *ToD;
2684  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2685  return nullptr;
2686  if (ToD)
2687  return ToD;
2688 
2689  QualType T = Importer.Import(D->getType());
2690  if (T.isNull())
2691  return nullptr;
2692 
2693  // Determine whether there are any other declarations with the same name and
2694  // in the same context.
2695  if (!LexicalDC->isFunctionOrMethod()) {
2696  SmallVector<NamedDecl *, 4> ConflictingDecls;
2697  unsigned IDNS = Decl::IDNS_Ordinary;
2698  SmallVector<NamedDecl *, 2> FoundDecls;
2699  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
2700  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
2701  if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
2702  continue;
2703 
2704  if (EnumConstantDecl *FoundEnumConstant
2705  = dyn_cast<EnumConstantDecl>(FoundDecls[I])) {
2706  if (IsStructuralMatch(D, FoundEnumConstant))
2707  return Importer.Imported(D, FoundEnumConstant);
2708  }
2709 
2710  ConflictingDecls.push_back(FoundDecls[I]);
2711  }
2712 
2713  if (!ConflictingDecls.empty()) {
2714  Name = Importer.HandleNameConflict(Name, DC, IDNS,
2715  ConflictingDecls.data(),
2716  ConflictingDecls.size());
2717  if (!Name)
2718  return nullptr;
2719  }
2720  }
2721 
2722  Expr *Init = Importer.Import(D->getInitExpr());
2723  if (D->getInitExpr() && !Init)
2724  return nullptr;
2725 
2726  EnumConstantDecl *ToEnumerator
2727  = EnumConstantDecl::Create(Importer.getToContext(), cast<EnumDecl>(DC), Loc,
2728  Name.getAsIdentifierInfo(), T,
2729  Init, D->getInitVal());
2730  ToEnumerator->setAccess(D->getAccess());
2731  ToEnumerator->setLexicalDeclContext(LexicalDC);
2732  Importer.Imported(D, ToEnumerator);
2733  LexicalDC->addDeclInternal(ToEnumerator);
2734  return ToEnumerator;
2735 }
2736 
2738  // Import the major distinguishing characteristics of this function.
2739  DeclContext *DC, *LexicalDC;
2740  DeclarationName Name;
2741  SourceLocation Loc;
2742  NamedDecl *ToD;
2743  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2744  return nullptr;
2745  if (ToD)
2746  return ToD;
2747 
2748  // Try to find a function in our own ("to") context with the same name, same
2749  // type, and in the same context as the function we're importing.
2750  if (!LexicalDC->isFunctionOrMethod()) {
2751  SmallVector<NamedDecl *, 4> ConflictingDecls;
2752  unsigned IDNS = Decl::IDNS_Ordinary;
2753  SmallVector<NamedDecl *, 2> FoundDecls;
2754  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
2755  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
2756  if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
2757  continue;
2758 
2759  if (FunctionDecl *FoundFunction = dyn_cast<FunctionDecl>(FoundDecls[I])) {
2760  if (FoundFunction->hasExternalFormalLinkage() &&
2761  D->hasExternalFormalLinkage()) {
2762  if (Importer.IsStructurallyEquivalent(D->getType(),
2763  FoundFunction->getType())) {
2764  // FIXME: Actually try to merge the body and other attributes.
2765  return Importer.Imported(D, FoundFunction);
2766  }
2767 
2768  // FIXME: Check for overloading more carefully, e.g., by boosting
2769  // Sema::IsOverload out to the AST library.
2770 
2771  // Function overloading is okay in C++.
2772  if (Importer.getToContext().getLangOpts().CPlusPlus)
2773  continue;
2774 
2775  // Complain about inconsistent function types.
2776  Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent)
2777  << Name << D->getType() << FoundFunction->getType();
2778  Importer.ToDiag(FoundFunction->getLocation(),
2779  diag::note_odr_value_here)
2780  << FoundFunction->getType();
2781  }
2782  }
2783 
2784  ConflictingDecls.push_back(FoundDecls[I]);
2785  }
2786 
2787  if (!ConflictingDecls.empty()) {
2788  Name = Importer.HandleNameConflict(Name, DC, IDNS,
2789  ConflictingDecls.data(),
2790  ConflictingDecls.size());
2791  if (!Name)
2792  return nullptr;
2793  }
2794  }
2795 
2796  DeclarationNameInfo NameInfo(Name, Loc);
2797  // Import additional name location/type info.
2798  ImportDeclarationNameLoc(D->getNameInfo(), NameInfo);
2799 
2800  QualType FromTy = D->getType();
2801  bool usedDifferentExceptionSpec = false;
2802 
2803  if (const FunctionProtoType *
2804  FromFPT = D->getType()->getAs<FunctionProtoType>()) {
2805  FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
2806  // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
2807  // FunctionDecl that we are importing the FunctionProtoType for.
2808  // To avoid an infinite recursion when importing, create the FunctionDecl
2809  // with a simplified function type and update it afterwards.
2810  if (FromEPI.ExceptionSpec.SourceDecl ||
2811  FromEPI.ExceptionSpec.SourceTemplate ||
2812  FromEPI.ExceptionSpec.NoexceptExpr) {
2814  FromTy = Importer.getFromContext().getFunctionType(
2815  FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI);
2816  usedDifferentExceptionSpec = true;
2817  }
2818  }
2819 
2820  // Import the type.
2821  QualType T = Importer.Import(FromTy);
2822  if (T.isNull())
2823  return nullptr;
2824 
2825  // Import the function parameters.
2826  SmallVector<ParmVarDecl *, 8> Parameters;
2827  for (auto P : D->params()) {
2828  ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(P));
2829  if (!ToP)
2830  return nullptr;
2831 
2832  Parameters.push_back(ToP);
2833  }
2834 
2835  // Create the imported function.
2836  TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
2837  FunctionDecl *ToFunction = nullptr;
2838  SourceLocation InnerLocStart = Importer.Import(D->getInnerLocStart());
2839  if (CXXConstructorDecl *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
2840  ToFunction = CXXConstructorDecl::Create(Importer.getToContext(),
2841  cast<CXXRecordDecl>(DC),
2842  InnerLocStart,
2843  NameInfo, T, TInfo,
2844  FromConstructor->isExplicit(),
2845  D->isInlineSpecified(),
2846  D->isImplicit(),
2847  D->isConstexpr());
2848  } else if (isa<CXXDestructorDecl>(D)) {
2849  ToFunction = CXXDestructorDecl::Create(Importer.getToContext(),
2850  cast<CXXRecordDecl>(DC),
2851  InnerLocStart,
2852  NameInfo, T, TInfo,
2853  D->isInlineSpecified(),
2854  D->isImplicit());
2855  } else if (CXXConversionDecl *FromConversion
2856  = dyn_cast<CXXConversionDecl>(D)) {
2857  ToFunction = CXXConversionDecl::Create(Importer.getToContext(),
2858  cast<CXXRecordDecl>(DC),
2859  InnerLocStart,
2860  NameInfo, T, TInfo,
2861  D->isInlineSpecified(),
2862  FromConversion->isExplicit(),
2863  D->isConstexpr(),
2864  Importer.Import(D->getLocEnd()));
2865  } else if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) {
2866  ToFunction = CXXMethodDecl::Create(Importer.getToContext(),
2867  cast<CXXRecordDecl>(DC),
2868  InnerLocStart,
2869  NameInfo, T, TInfo,
2870  Method->getStorageClass(),
2871  Method->isInlineSpecified(),
2872  D->isConstexpr(),
2873  Importer.Import(D->getLocEnd()));
2874  } else {
2875  ToFunction = FunctionDecl::Create(Importer.getToContext(), DC,
2876  InnerLocStart,
2877  NameInfo, T, TInfo, D->getStorageClass(),
2878  D->isInlineSpecified(),
2879  D->hasWrittenPrototype(),
2880  D->isConstexpr());
2881  }
2882 
2883  // Import the qualifier, if any.
2884  ToFunction->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
2885  ToFunction->setAccess(D->getAccess());
2886  ToFunction->setLexicalDeclContext(LexicalDC);
2887  ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
2888  ToFunction->setTrivial(D->isTrivial());
2889  ToFunction->setPure(D->isPure());
2890  Importer.Imported(D, ToFunction);
2891 
2892  // Set the parameters.
2893  for (unsigned I = 0, N = Parameters.size(); I != N; ++I) {
2894  Parameters[I]->setOwningFunction(ToFunction);
2895  ToFunction->addDeclInternal(Parameters[I]);
2896  }
2897  ToFunction->setParams(Parameters);
2898 
2899  if (usedDifferentExceptionSpec) {
2900  // Update FunctionProtoType::ExtProtoInfo.
2901  QualType T = Importer.Import(D->getType());
2902  if (T.isNull())
2903  return nullptr;
2904  ToFunction->setType(T);
2905  }
2906 
2907  // Import the body, if any.
2908  if (Stmt *FromBody = D->getBody()) {
2909  if (Stmt *ToBody = Importer.Import(FromBody)) {
2910  ToFunction->setBody(ToBody);
2911  }
2912  }
2913 
2914  // FIXME: Other bits to merge?
2915 
2916  // Add this function to the lexical context.
2917  LexicalDC->addDeclInternal(ToFunction);
2918 
2919  return ToFunction;
2920 }
2921 
2923  return VisitFunctionDecl(D);
2924 }
2925 
2927  return VisitCXXMethodDecl(D);
2928 }
2929 
2931  return VisitCXXMethodDecl(D);
2932 }
2933 
2935  return VisitCXXMethodDecl(D);
2936 }
2937 
2938 static unsigned getFieldIndex(Decl *F) {
2939  RecordDecl *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
2940  if (!Owner)
2941  return 0;
2942 
2943  unsigned Index = 1;
2944  for (const auto *D : Owner->noload_decls()) {
2945  if (D == F)
2946  return Index;
2947 
2948  if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D))
2949  ++Index;
2950  }
2951 
2952  return Index;
2953 }
2954 
2956  // Import the major distinguishing characteristics of a variable.
2957  DeclContext *DC, *LexicalDC;
2958  DeclarationName Name;
2959  SourceLocation Loc;
2960  NamedDecl *ToD;
2961  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2962  return nullptr;
2963  if (ToD)
2964  return ToD;
2965 
2966  // Determine whether we've already imported this field.
2967  SmallVector<NamedDecl *, 2> FoundDecls;
2968  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
2969  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
2970  if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecls[I])) {
2971  // For anonymous fields, match up by index.
2972  if (!Name && getFieldIndex(D) != getFieldIndex(FoundField))
2973  continue;
2974 
2975  if (Importer.IsStructurallyEquivalent(D->getType(),
2976  FoundField->getType())) {
2977  Importer.Imported(D, FoundField);
2978  return FoundField;
2979  }
2980 
2981  Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent)
2982  << Name << D->getType() << FoundField->getType();
2983  Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
2984  << FoundField->getType();
2985  return nullptr;
2986  }
2987  }
2988 
2989  // Import the type.
2990  QualType T = Importer.Import(D->getType());
2991  if (T.isNull())
2992  return nullptr;
2993 
2994  TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
2995  Expr *BitWidth = Importer.Import(D->getBitWidth());
2996  if (!BitWidth && D->getBitWidth())
2997  return nullptr;
2998 
2999  FieldDecl *ToField = FieldDecl::Create(Importer.getToContext(), DC,
3000  Importer.Import(D->getInnerLocStart()),
3001  Loc, Name.getAsIdentifierInfo(),
3002  T, TInfo, BitWidth, D->isMutable(),
3003  D->getInClassInitStyle());
3004  ToField->setAccess(D->getAccess());
3005  ToField->setLexicalDeclContext(LexicalDC);
3006  if (ToField->hasInClassInitializer())
3008  ToField->setImplicit(D->isImplicit());
3009  Importer.Imported(D, ToField);
3010  LexicalDC->addDeclInternal(ToField);
3011  return ToField;
3012 }
3013 
3015  // Import the major distinguishing characteristics of a variable.
3016  DeclContext *DC, *LexicalDC;
3017  DeclarationName Name;
3018  SourceLocation Loc;
3019  NamedDecl *ToD;
3020  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3021  return nullptr;
3022  if (ToD)
3023  return ToD;
3024 
3025  // Determine whether we've already imported this field.
3026  SmallVector<NamedDecl *, 2> FoundDecls;
3027  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
3028  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
3029  if (IndirectFieldDecl *FoundField
3030  = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
3031  // For anonymous indirect fields, match up by index.
3032  if (!Name && getFieldIndex(D) != getFieldIndex(FoundField))
3033  continue;
3034 
3035  if (Importer.IsStructurallyEquivalent(D->getType(),
3036  FoundField->getType(),
3037  !Name.isEmpty())) {
3038  Importer.Imported(D, FoundField);
3039  return FoundField;
3040  }
3041 
3042  // If there are more anonymous fields to check, continue.
3043  if (!Name && I < N-1)
3044  continue;
3045 
3046  Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent)
3047  << Name << D->getType() << FoundField->getType();
3048  Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
3049  << FoundField->getType();
3050  return nullptr;
3051  }
3052  }
3053 
3054  // Import the type.
3055  QualType T = Importer.Import(D->getType());
3056  if (T.isNull())
3057  return nullptr;
3058 
3059  NamedDecl **NamedChain =
3060  new (Importer.getToContext())NamedDecl*[D->getChainingSize()];
3061 
3062  unsigned i = 0;
3063  for (auto *PI : D->chain()) {
3064  Decl *D = Importer.Import(PI);
3065  if (!D)
3066  return nullptr;
3067  NamedChain[i++] = cast<NamedDecl>(D);
3068  }
3069 
3070  IndirectFieldDecl *ToIndirectField = IndirectFieldDecl::Create(
3071  Importer.getToContext(), DC, Loc, Name.getAsIdentifierInfo(), T,
3072  NamedChain, D->getChainingSize());
3073 
3074  for (const auto *Attr : D->attrs())
3075  ToIndirectField->addAttr(Attr->clone(Importer.getToContext()));
3076 
3077  ToIndirectField->setAccess(D->getAccess());
3078  ToIndirectField->setLexicalDeclContext(LexicalDC);
3079  Importer.Imported(D, ToIndirectField);
3080  LexicalDC->addDeclInternal(ToIndirectField);
3081  return ToIndirectField;
3082 }
3083 
3085  // Import the major distinguishing characteristics of an ivar.
3086  DeclContext *DC, *LexicalDC;
3087  DeclarationName Name;
3088  SourceLocation Loc;
3089  NamedDecl *ToD;
3090  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3091  return nullptr;
3092  if (ToD)
3093  return ToD;
3094 
3095  // Determine whether we've already imported this ivar
3096  SmallVector<NamedDecl *, 2> FoundDecls;
3097  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
3098  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
3099  if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecls[I])) {
3100  if (Importer.IsStructurallyEquivalent(D->getType(),
3101  FoundIvar->getType())) {
3102  Importer.Imported(D, FoundIvar);
3103  return FoundIvar;
3104  }
3105 
3106  Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent)
3107  << Name << D->getType() << FoundIvar->getType();
3108  Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
3109  << FoundIvar->getType();
3110  return nullptr;
3111  }
3112  }
3113 
3114  // Import the type.
3115  QualType T = Importer.Import(D->getType());
3116  if (T.isNull())
3117  return nullptr;
3118 
3119  TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
3120  Expr *BitWidth = Importer.Import(D->getBitWidth());
3121  if (!BitWidth && D->getBitWidth())
3122  return nullptr;
3123 
3124  ObjCIvarDecl *ToIvar = ObjCIvarDecl::Create(Importer.getToContext(),
3125  cast<ObjCContainerDecl>(DC),
3126  Importer.Import(D->getInnerLocStart()),
3127  Loc, Name.getAsIdentifierInfo(),
3128  T, TInfo, D->getAccessControl(),
3129  BitWidth, D->getSynthesize());
3130  ToIvar->setLexicalDeclContext(LexicalDC);
3131  Importer.Imported(D, ToIvar);
3132  LexicalDC->addDeclInternal(ToIvar);
3133  return ToIvar;
3134 
3135 }
3136 
3138  // Import the major distinguishing characteristics of a variable.
3139  DeclContext *DC, *LexicalDC;
3140  DeclarationName Name;
3141  SourceLocation Loc;
3142  NamedDecl *ToD;
3143  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3144  return nullptr;
3145  if (ToD)
3146  return ToD;
3147 
3148  // Try to find a variable in our own ("to") context with the same name and
3149  // in the same context as the variable we're importing.
3150  if (D->isFileVarDecl()) {
3151  VarDecl *MergeWithVar = nullptr;
3152  SmallVector<NamedDecl *, 4> ConflictingDecls;
3153  unsigned IDNS = Decl::IDNS_Ordinary;
3154  SmallVector<NamedDecl *, 2> FoundDecls;
3155  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
3156  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
3157  if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
3158  continue;
3159 
3160  if (VarDecl *FoundVar = dyn_cast<VarDecl>(FoundDecls[I])) {
3161  // We have found a variable that we may need to merge with. Check it.
3162  if (FoundVar->hasExternalFormalLinkage() &&
3163  D->hasExternalFormalLinkage()) {
3164  if (Importer.IsStructurallyEquivalent(D->getType(),
3165  FoundVar->getType())) {
3166  MergeWithVar = FoundVar;
3167  break;
3168  }
3169 
3170  const ArrayType *FoundArray
3171  = Importer.getToContext().getAsArrayType(FoundVar->getType());
3172  const ArrayType *TArray
3173  = Importer.getToContext().getAsArrayType(D->getType());
3174  if (FoundArray && TArray) {
3175  if (isa<IncompleteArrayType>(FoundArray) &&
3176  isa<ConstantArrayType>(TArray)) {
3177  // Import the type.
3178  QualType T = Importer.Import(D->getType());
3179  if (T.isNull())
3180  return nullptr;
3181 
3182  FoundVar->setType(T);
3183  MergeWithVar = FoundVar;
3184  break;
3185  } else if (isa<IncompleteArrayType>(TArray) &&
3186  isa<ConstantArrayType>(FoundArray)) {
3187  MergeWithVar = FoundVar;
3188  break;
3189  }
3190  }
3191 
3192  Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent)
3193  << Name << D->getType() << FoundVar->getType();
3194  Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
3195  << FoundVar->getType();
3196  }
3197  }
3198 
3199  ConflictingDecls.push_back(FoundDecls[I]);
3200  }
3201 
3202  if (MergeWithVar) {
3203  // An equivalent variable with external linkage has been found. Link
3204  // the two declarations, then merge them.
3205  Importer.Imported(D, MergeWithVar);
3206 
3207  if (VarDecl *DDef = D->getDefinition()) {
3208  if (VarDecl *ExistingDef = MergeWithVar->getDefinition()) {
3209  Importer.ToDiag(ExistingDef->getLocation(),
3210  diag::err_odr_variable_multiple_def)
3211  << Name;
3212  Importer.FromDiag(DDef->getLocation(), diag::note_odr_defined_here);
3213  } else {
3214  Expr *Init = Importer.Import(DDef->getInit());
3215  MergeWithVar->setInit(Init);
3216  if (DDef->isInitKnownICE()) {
3217  EvaluatedStmt *Eval = MergeWithVar->ensureEvaluatedStmt();
3218  Eval->CheckedICE = true;
3219  Eval->IsICE = DDef->isInitICE();
3220  }
3221  }
3222  }
3223 
3224  return MergeWithVar;
3225  }
3226 
3227  if (!ConflictingDecls.empty()) {
3228  Name = Importer.HandleNameConflict(Name, DC, IDNS,
3229  ConflictingDecls.data(),
3230  ConflictingDecls.size());
3231  if (!Name)
3232  return nullptr;
3233  }
3234  }
3235 
3236  // Import the type.
3237  QualType T = Importer.Import(D->getType());
3238  if (T.isNull())
3239  return nullptr;
3240 
3241  // Create the imported variable.
3242  TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
3243  VarDecl *ToVar = VarDecl::Create(Importer.getToContext(), DC,
3244  Importer.Import(D->getInnerLocStart()),
3245  Loc, Name.getAsIdentifierInfo(),
3246  T, TInfo,
3247  D->getStorageClass());
3248  ToVar->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
3249  ToVar->setAccess(D->getAccess());
3250  ToVar->setLexicalDeclContext(LexicalDC);
3251  Importer.Imported(D, ToVar);
3252  LexicalDC->addDeclInternal(ToVar);
3253 
3254  if (!D->isFileVarDecl() &&
3255  D->isUsed())
3256  ToVar->setIsUsed();
3257 
3258  // Merge the initializer.
3259  if (ImportDefinition(D, ToVar))
3260  return nullptr;
3261 
3262  return ToVar;
3263 }
3264 
3266  // Parameters are created in the translation unit's context, then moved
3267  // into the function declaration's context afterward.
3268  DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
3269 
3270  // Import the name of this declaration.
3271  DeclarationName Name = Importer.Import(D->getDeclName());
3272  if (D->getDeclName() && !Name)
3273  return nullptr;
3274 
3275  // Import the location of this declaration.
3276  SourceLocation Loc = Importer.Import(D->getLocation());
3277 
3278  // Import the parameter's type.
3279  QualType T = Importer.Import(D->getType());
3280  if (T.isNull())
3281  return nullptr;
3282 
3283  // Create the imported parameter.
3284  ImplicitParamDecl *ToParm
3285  = ImplicitParamDecl::Create(Importer.getToContext(), DC,
3286  Loc, Name.getAsIdentifierInfo(),
3287  T);
3288  return Importer.Imported(D, ToParm);
3289 }
3290 
3292  // Parameters are created in the translation unit's context, then moved
3293  // into the function declaration's context afterward.
3294  DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
3295 
3296  // Import the name of this declaration.
3297  DeclarationName Name = Importer.Import(D->getDeclName());
3298  if (D->getDeclName() && !Name)
3299  return nullptr;
3300 
3301  // Import the location of this declaration.
3302  SourceLocation Loc = Importer.Import(D->getLocation());
3303 
3304  // Import the parameter's type.
3305  QualType T = Importer.Import(D->getType());
3306  if (T.isNull())
3307  return nullptr;
3308 
3309  // Create the imported parameter.
3310  TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
3311  ParmVarDecl *ToParm = ParmVarDecl::Create(Importer.getToContext(), DC,
3312  Importer.Import(D->getInnerLocStart()),
3313  Loc, Name.getAsIdentifierInfo(),
3314  T, TInfo, D->getStorageClass(),
3315  /*FIXME: Default argument*/nullptr);
3317 
3318  if (D->isUsed())
3319  ToParm->setIsUsed();
3320 
3321  return Importer.Imported(D, ToParm);
3322 }
3323 
3325  // Import the major distinguishing characteristics of a method.
3326  DeclContext *DC, *LexicalDC;
3327  DeclarationName Name;
3328  SourceLocation Loc;
3329  NamedDecl *ToD;
3330  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3331  return nullptr;
3332  if (ToD)
3333  return ToD;
3334 
3335  SmallVector<NamedDecl *, 2> FoundDecls;
3336  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
3337  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
3338  if (ObjCMethodDecl *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecls[I])) {
3339  if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
3340  continue;
3341 
3342  // Check return types.
3343  if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
3344  FoundMethod->getReturnType())) {
3345  Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent)
3346  << D->isInstanceMethod() << Name << D->getReturnType()
3347  << FoundMethod->getReturnType();
3348  Importer.ToDiag(FoundMethod->getLocation(),
3349  diag::note_odr_objc_method_here)
3350  << D->isInstanceMethod() << Name;
3351  return nullptr;
3352  }
3353 
3354  // Check the number of parameters.
3355  if (D->param_size() != FoundMethod->param_size()) {
3356  Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent)
3357  << D->isInstanceMethod() << Name
3358  << D->param_size() << FoundMethod->param_size();
3359  Importer.ToDiag(FoundMethod->getLocation(),
3360  diag::note_odr_objc_method_here)
3361  << D->isInstanceMethod() << Name;
3362  return nullptr;
3363  }
3364 
3365  // Check parameter types.
3367  PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
3368  P != PEnd; ++P, ++FoundP) {
3369  if (!Importer.IsStructurallyEquivalent((*P)->getType(),
3370  (*FoundP)->getType())) {
3371  Importer.FromDiag((*P)->getLocation(),
3372  diag::err_odr_objc_method_param_type_inconsistent)
3373  << D->isInstanceMethod() << Name
3374  << (*P)->getType() << (*FoundP)->getType();
3375  Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
3376  << (*FoundP)->getType();
3377  return nullptr;
3378  }
3379  }
3380 
3381  // Check variadic/non-variadic.
3382  // Check the number of parameters.
3383  if (D->isVariadic() != FoundMethod->isVariadic()) {
3384  Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent)
3385  << D->isInstanceMethod() << Name;
3386  Importer.ToDiag(FoundMethod->getLocation(),
3387  diag::note_odr_objc_method_here)
3388  << D->isInstanceMethod() << Name;
3389  return nullptr;
3390  }
3391 
3392  // FIXME: Any other bits we need to merge?
3393  return Importer.Imported(D, FoundMethod);
3394  }
3395  }
3396 
3397  // Import the result type.
3398  QualType ResultTy = Importer.Import(D->getReturnType());
3399  if (ResultTy.isNull())
3400  return nullptr;
3401 
3402  TypeSourceInfo *ReturnTInfo = Importer.Import(D->getReturnTypeSourceInfo());
3403 
3405  Importer.getToContext(), Loc, Importer.Import(D->getLocEnd()),
3406  Name.getObjCSelector(), ResultTy, ReturnTInfo, DC, D->isInstanceMethod(),
3407  D->isVariadic(), D->isPropertyAccessor(), D->isImplicit(), D->isDefined(),
3409 
3410  // FIXME: When we decide to merge method definitions, we'll need to
3411  // deal with implicit parameters.
3412 
3413  // Import the parameters
3415  for (auto *FromP : D->params()) {
3416  ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(FromP));
3417  if (!ToP)
3418  return nullptr;
3419 
3420  ToParams.push_back(ToP);
3421  }
3422 
3423  // Set the parameters.
3424  for (unsigned I = 0, N = ToParams.size(); I != N; ++I) {
3425  ToParams[I]->setOwningFunction(ToMethod);
3426  ToMethod->addDeclInternal(ToParams[I]);
3427  }
3429  D->getSelectorLocs(SelLocs);
3430  ToMethod->setMethodParams(Importer.getToContext(), ToParams, SelLocs);
3431 
3432  ToMethod->setLexicalDeclContext(LexicalDC);
3433  Importer.Imported(D, ToMethod);
3434  LexicalDC->addDeclInternal(ToMethod);
3435  return ToMethod;
3436 }
3437 
3439  // Import the major distinguishing characteristics of a category.
3440  DeclContext *DC, *LexicalDC;
3441  DeclarationName Name;
3442  SourceLocation Loc;
3443  NamedDecl *ToD;
3444  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3445  return nullptr;
3446  if (ToD)
3447  return ToD;
3448 
3449  TypeSourceInfo *BoundInfo = Importer.Import(D->getTypeSourceInfo());
3450  if (!BoundInfo)
3451  return nullptr;
3452 
3454  Importer.getToContext(), DC,
3455  D->getVariance(),
3456  Importer.Import(D->getVarianceLoc()),
3457  D->getIndex(),
3458  Importer.Import(D->getLocation()),
3459  Name.getAsIdentifierInfo(),
3460  Importer.Import(D->getColonLoc()),
3461  BoundInfo);
3462  Importer.Imported(D, Result);
3463  Result->setLexicalDeclContext(LexicalDC);
3464  return Result;
3465 }
3466 
3468  // Import the major distinguishing characteristics of a category.
3469  DeclContext *DC, *LexicalDC;
3470  DeclarationName Name;
3471  SourceLocation Loc;
3472  NamedDecl *ToD;
3473  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3474  return nullptr;
3475  if (ToD)
3476  return ToD;
3477 
3478  ObjCInterfaceDecl *ToInterface
3479  = cast_or_null<ObjCInterfaceDecl>(Importer.Import(D->getClassInterface()));
3480  if (!ToInterface)
3481  return nullptr;
3482 
3483  // Determine if we've already encountered this category.
3484  ObjCCategoryDecl *MergeWithCategory
3485  = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
3486  ObjCCategoryDecl *ToCategory = MergeWithCategory;
3487  if (!ToCategory) {
3488  ToCategory = ObjCCategoryDecl::Create(Importer.getToContext(), DC,
3489  Importer.Import(D->getAtStartLoc()),
3490  Loc,
3491  Importer.Import(D->getCategoryNameLoc()),
3492  Name.getAsIdentifierInfo(),
3493  ToInterface,
3494  /*TypeParamList=*/nullptr,
3495  Importer.Import(D->getIvarLBraceLoc()),
3496  Importer.Import(D->getIvarRBraceLoc()));
3497  ToCategory->setLexicalDeclContext(LexicalDC);
3498  LexicalDC->addDeclInternal(ToCategory);
3499  Importer.Imported(D, ToCategory);
3500  // Import the type parameter list after calling Imported, to avoid
3501  // loops when bringing in their DeclContext.
3503  D->getTypeParamList()));
3504 
3505  // Import protocols
3507  SmallVector<SourceLocation, 4> ProtocolLocs;
3509  = D->protocol_loc_begin();
3511  FromProtoEnd = D->protocol_end();
3512  FromProto != FromProtoEnd;
3513  ++FromProto, ++FromProtoLoc) {
3514  ObjCProtocolDecl *ToProto
3515  = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto));
3516  if (!ToProto)
3517  return nullptr;
3518  Protocols.push_back(ToProto);
3519  ProtocolLocs.push_back(Importer.Import(*FromProtoLoc));
3520  }
3521 
3522  // FIXME: If we're merging, make sure that the protocol list is the same.
3523  ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
3524  ProtocolLocs.data(), Importer.getToContext());
3525 
3526  } else {
3527  Importer.Imported(D, ToCategory);
3528  }
3529 
3530  // Import all of the members of this category.
3531  ImportDeclContext(D);
3532 
3533  // If we have an implementation, import it as well.
3534  if (D->getImplementation()) {
3535  ObjCCategoryImplDecl *Impl
3536  = cast_or_null<ObjCCategoryImplDecl>(
3537  Importer.Import(D->getImplementation()));
3538  if (!Impl)
3539  return nullptr;
3540 
3541  ToCategory->setImplementation(Impl);
3542  }
3543 
3544  return ToCategory;
3545 }
3546 
3548  ObjCProtocolDecl *To,
3550  if (To->getDefinition()) {
3551  if (shouldForceImportDeclContext(Kind))
3552  ImportDeclContext(From);
3553  return false;
3554  }
3555 
3556  // Start the protocol definition
3557  To->startDefinition();
3558 
3559  // Import protocols
3561  SmallVector<SourceLocation, 4> ProtocolLocs;
3563  FromProtoLoc = From->protocol_loc_begin();
3564  for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
3565  FromProtoEnd = From->protocol_end();
3566  FromProto != FromProtoEnd;
3567  ++FromProto, ++FromProtoLoc) {
3568  ObjCProtocolDecl *ToProto
3569  = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto));
3570  if (!ToProto)
3571  return true;
3572  Protocols.push_back(ToProto);
3573  ProtocolLocs.push_back(Importer.Import(*FromProtoLoc));
3574  }
3575 
3576  // FIXME: If we're merging, make sure that the protocol list is the same.
3577  To->setProtocolList(Protocols.data(), Protocols.size(),
3578  ProtocolLocs.data(), Importer.getToContext());
3579 
3580  if (shouldForceImportDeclContext(Kind)) {
3581  // Import all of the members of this protocol.
3582  ImportDeclContext(From, /*ForceImport=*/true);
3583  }
3584  return false;
3585 }
3586 
3588  // If this protocol has a definition in the translation unit we're coming
3589  // from, but this particular declaration is not that definition, import the
3590  // definition and map to that.
3591  ObjCProtocolDecl *Definition = D->getDefinition();
3592  if (Definition && Definition != D) {
3593  Decl *ImportedDef = Importer.Import(Definition);
3594  if (!ImportedDef)
3595  return nullptr;
3596 
3597  return Importer.Imported(D, ImportedDef);
3598  }
3599 
3600  // Import the major distinguishing characteristics of a protocol.
3601  DeclContext *DC, *LexicalDC;
3602  DeclarationName Name;
3603  SourceLocation Loc;
3604  NamedDecl *ToD;
3605  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3606  return nullptr;
3607  if (ToD)
3608  return ToD;
3609 
3610  ObjCProtocolDecl *MergeWithProtocol = nullptr;
3611  SmallVector<NamedDecl *, 2> FoundDecls;
3612  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
3613  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
3614  if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol))
3615  continue;
3616 
3617  if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecls[I])))
3618  break;
3619  }
3620 
3621  ObjCProtocolDecl *ToProto = MergeWithProtocol;
3622  if (!ToProto) {
3623  ToProto = ObjCProtocolDecl::Create(Importer.getToContext(), DC,
3624  Name.getAsIdentifierInfo(), Loc,
3625  Importer.Import(D->getAtStartLoc()),
3626  /*PrevDecl=*/nullptr);
3627  ToProto->setLexicalDeclContext(LexicalDC);
3628  LexicalDC->addDeclInternal(ToProto);
3629  }
3630 
3631  Importer.Imported(D, ToProto);
3632 
3633  if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToProto))
3634  return nullptr;
3635 
3636  return ToProto;
3637 }
3638 
3640  DeclContext *DC = Importer.ImportContext(D->getDeclContext());
3641  DeclContext *LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
3642 
3643  SourceLocation ExternLoc = Importer.Import(D->getExternLoc());
3644  SourceLocation LangLoc = Importer.Import(D->getLocation());
3645 
3646  bool HasBraces = D->hasBraces();
3647 
3648  LinkageSpecDecl *ToLinkageSpec =
3650  DC,
3651  ExternLoc,
3652  LangLoc,
3653  D->getLanguage(),
3654  HasBraces);
3655 
3656  if (HasBraces) {
3657  SourceLocation RBraceLoc = Importer.Import(D->getRBraceLoc());
3658  ToLinkageSpec->setRBraceLoc(RBraceLoc);
3659  }
3660 
3661  ToLinkageSpec->setLexicalDeclContext(LexicalDC);
3662  LexicalDC->addDeclInternal(ToLinkageSpec);
3663 
3664  Importer.Imported(D, ToLinkageSpec);
3665 
3666  return ToLinkageSpec;
3667 }
3668 
3670  ObjCInterfaceDecl *To,
3672  if (To->getDefinition()) {
3673  // Check consistency of superclass.
3674  ObjCInterfaceDecl *FromSuper = From->getSuperClass();
3675  if (FromSuper) {
3676  FromSuper = cast_or_null<ObjCInterfaceDecl>(Importer.Import(FromSuper));
3677  if (!FromSuper)
3678  return true;
3679  }
3680 
3681  ObjCInterfaceDecl *ToSuper = To->getSuperClass();
3682  if ((bool)FromSuper != (bool)ToSuper ||
3683  (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
3684  Importer.ToDiag(To->getLocation(),
3685  diag::err_odr_objc_superclass_inconsistent)
3686  << To->getDeclName();
3687  if (ToSuper)
3688  Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
3689  << To->getSuperClass()->getDeclName();
3690  else
3691  Importer.ToDiag(To->getLocation(),
3692  diag::note_odr_objc_missing_superclass);
3693  if (From->getSuperClass())
3694  Importer.FromDiag(From->getSuperClassLoc(),
3695  diag::note_odr_objc_superclass)
3696  << From->getSuperClass()->getDeclName();
3697  else
3698  Importer.FromDiag(From->getLocation(),
3699  diag::note_odr_objc_missing_superclass);
3700  }
3701 
3702  if (shouldForceImportDeclContext(Kind))
3703  ImportDeclContext(From);
3704  return false;
3705  }
3706 
3707  // Start the definition.
3708  To->startDefinition();
3709 
3710  // If this class has a superclass, import it.
3711  if (From->getSuperClass()) {
3712  TypeSourceInfo *SuperTInfo = Importer.Import(From->getSuperClassTInfo());
3713  if (!SuperTInfo)
3714  return true;
3715 
3716  To->setSuperClass(SuperTInfo);
3717  }
3718 
3719  // Import protocols
3721  SmallVector<SourceLocation, 4> ProtocolLocs;
3723  FromProtoLoc = From->protocol_loc_begin();
3724 
3725  for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(),
3726  FromProtoEnd = From->protocol_end();
3727  FromProto != FromProtoEnd;
3728  ++FromProto, ++FromProtoLoc) {
3729  ObjCProtocolDecl *ToProto
3730  = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto));
3731  if (!ToProto)
3732  return true;
3733  Protocols.push_back(ToProto);
3734  ProtocolLocs.push_back(Importer.Import(*FromProtoLoc));
3735  }
3736 
3737  // FIXME: If we're merging, make sure that the protocol list is the same.
3738  To->setProtocolList(Protocols.data(), Protocols.size(),
3739  ProtocolLocs.data(), Importer.getToContext());
3740 
3741  // Import categories. When the categories themselves are imported, they'll
3742  // hook themselves into this interface.
3743  for (auto *Cat : From->known_categories())
3744  Importer.Import(Cat);
3745 
3746  // If we have an @implementation, import it as well.
3747  if (From->getImplementation()) {
3748  ObjCImplementationDecl *Impl = cast_or_null<ObjCImplementationDecl>(
3749  Importer.Import(From->getImplementation()));
3750  if (!Impl)
3751  return true;
3752 
3753  To->setImplementation(Impl);
3754  }
3755 
3756  if (shouldForceImportDeclContext(Kind)) {
3757  // Import all of the members of this class.
3758  ImportDeclContext(From, /*ForceImport=*/true);
3759  }
3760  return false;
3761 }
3762 
3765  if (!list)
3766  return nullptr;
3767 
3769  for (auto fromTypeParam : *list) {
3770  auto toTypeParam = cast_or_null<ObjCTypeParamDecl>(
3771  Importer.Import(fromTypeParam));
3772  if (!toTypeParam)
3773  return nullptr;
3774 
3775  toTypeParams.push_back(toTypeParam);
3776  }
3777 
3778  return ObjCTypeParamList::create(Importer.getToContext(),
3779  Importer.Import(list->getLAngleLoc()),
3780  toTypeParams,
3781  Importer.Import(list->getRAngleLoc()));
3782 }
3783 
3785  // If this class has a definition in the translation unit we're coming from,
3786  // but this particular declaration is not that definition, import the
3787  // definition and map to that.
3788  ObjCInterfaceDecl *Definition = D->getDefinition();
3789  if (Definition && Definition != D) {
3790  Decl *ImportedDef = Importer.Import(Definition);
3791  if (!ImportedDef)
3792  return nullptr;
3793 
3794  return Importer.Imported(D, ImportedDef);
3795  }
3796 
3797  // Import the major distinguishing characteristics of an @interface.
3798  DeclContext *DC, *LexicalDC;
3799  DeclarationName Name;
3800  SourceLocation Loc;
3801  NamedDecl *ToD;
3802  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3803  return nullptr;
3804  if (ToD)
3805  return ToD;
3806 
3807  // Look for an existing interface with the same name.
3808  ObjCInterfaceDecl *MergeWithIface = nullptr;
3809  SmallVector<NamedDecl *, 2> FoundDecls;
3810  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
3811  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
3812  if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary))
3813  continue;
3814 
3815  if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecls[I])))
3816  break;
3817  }
3818 
3819  // Create an interface declaration, if one does not already exist.
3820  ObjCInterfaceDecl *ToIface = MergeWithIface;
3821  if (!ToIface) {
3822  ToIface = ObjCInterfaceDecl::Create(Importer.getToContext(), DC,
3823  Importer.Import(D->getAtStartLoc()),
3824  Name.getAsIdentifierInfo(),
3825  /*TypeParamList=*/nullptr,
3826  /*PrevDecl=*/nullptr, Loc,
3828  ToIface->setLexicalDeclContext(LexicalDC);
3829  LexicalDC->addDeclInternal(ToIface);
3830  }
3831  Importer.Imported(D, ToIface);
3832  // Import the type parameter list after calling Imported, to avoid
3833  // loops when bringing in their DeclContext.
3836 
3837  if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToIface))
3838  return nullptr;
3839 
3840  return ToIface;
3841 }
3842 
3844  ObjCCategoryDecl *Category = cast_or_null<ObjCCategoryDecl>(
3845  Importer.Import(D->getCategoryDecl()));
3846  if (!Category)
3847  return nullptr;
3848 
3849  ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
3850  if (!ToImpl) {
3851  DeclContext *DC = Importer.ImportContext(D->getDeclContext());
3852  if (!DC)
3853  return nullptr;
3854 
3855  SourceLocation CategoryNameLoc = Importer.Import(D->getCategoryNameLoc());
3856  ToImpl = ObjCCategoryImplDecl::Create(Importer.getToContext(), DC,
3857  Importer.Import(D->getIdentifier()),
3858  Category->getClassInterface(),
3859  Importer.Import(D->getLocation()),
3860  Importer.Import(D->getAtStartLoc()),
3861  CategoryNameLoc);
3862 
3863  DeclContext *LexicalDC = DC;
3864  if (D->getDeclContext() != D->getLexicalDeclContext()) {
3865  LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
3866  if (!LexicalDC)
3867  return nullptr;
3868 
3869  ToImpl->setLexicalDeclContext(LexicalDC);
3870  }
3871 
3872  LexicalDC->addDeclInternal(ToImpl);
3873  Category->setImplementation(ToImpl);
3874  }
3875 
3876  Importer.Imported(D, ToImpl);
3877  ImportDeclContext(D);
3878  return ToImpl;
3879 }
3880 
3882  // Find the corresponding interface.
3883  ObjCInterfaceDecl *Iface = cast_or_null<ObjCInterfaceDecl>(
3884  Importer.Import(D->getClassInterface()));
3885  if (!Iface)
3886  return nullptr;
3887 
3888  // Import the superclass, if any.
3889  ObjCInterfaceDecl *Super = nullptr;
3890  if (D->getSuperClass()) {
3891  Super = cast_or_null<ObjCInterfaceDecl>(
3892  Importer.Import(D->getSuperClass()));
3893  if (!Super)
3894  return nullptr;
3895  }
3896 
3897  ObjCImplementationDecl *Impl = Iface->getImplementation();
3898  if (!Impl) {
3899  // We haven't imported an implementation yet. Create a new @implementation
3900  // now.
3901  Impl = ObjCImplementationDecl::Create(Importer.getToContext(),
3902  Importer.ImportContext(D->getDeclContext()),
3903  Iface, Super,
3904  Importer.Import(D->getLocation()),
3905  Importer.Import(D->getAtStartLoc()),
3906  Importer.Import(D->getSuperClassLoc()),
3907  Importer.Import(D->getIvarLBraceLoc()),
3908  Importer.Import(D->getIvarRBraceLoc()));
3909 
3910  if (D->getDeclContext() != D->getLexicalDeclContext()) {
3911  DeclContext *LexicalDC
3912  = Importer.ImportContext(D->getLexicalDeclContext());
3913  if (!LexicalDC)
3914  return nullptr;
3915  Impl->setLexicalDeclContext(LexicalDC);
3916  }
3917 
3918  // Associate the implementation with the class it implements.
3919  Iface->setImplementation(Impl);
3920  Importer.Imported(D, Iface->getImplementation());
3921  } else {
3922  Importer.Imported(D, Iface->getImplementation());
3923 
3924  // Verify that the existing @implementation has the same superclass.
3925  if ((Super && !Impl->getSuperClass()) ||
3926  (!Super && Impl->getSuperClass()) ||
3927  (Super && Impl->getSuperClass() &&
3929  Impl->getSuperClass()))) {
3930  Importer.ToDiag(Impl->getLocation(),
3931  diag::err_odr_objc_superclass_inconsistent)
3932  << Iface->getDeclName();
3933  // FIXME: It would be nice to have the location of the superclass
3934  // below.
3935  if (Impl->getSuperClass())
3936  Importer.ToDiag(Impl->getLocation(),
3937  diag::note_odr_objc_superclass)
3938  << Impl->getSuperClass()->getDeclName();
3939  else
3940  Importer.ToDiag(Impl->getLocation(),
3941  diag::note_odr_objc_missing_superclass);
3942  if (D->getSuperClass())
3943  Importer.FromDiag(D->getLocation(),
3944  diag::note_odr_objc_superclass)
3945  << D->getSuperClass()->getDeclName();
3946  else
3947  Importer.FromDiag(D->getLocation(),
3948  diag::note_odr_objc_missing_superclass);
3949  return nullptr;
3950  }
3951  }
3952 
3953  // Import all of the members of this @implementation.
3954  ImportDeclContext(D);
3955 
3956  return Impl;
3957 }
3958 
3960  // Import the major distinguishing characteristics of an @property.
3961  DeclContext *DC, *LexicalDC;
3962  DeclarationName Name;
3963  SourceLocation Loc;
3964  NamedDecl *ToD;
3965  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3966  return nullptr;
3967  if (ToD)
3968  return ToD;
3969 
3970  // Check whether we have already imported this property.
3971  SmallVector<NamedDecl *, 2> FoundDecls;
3972  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
3973  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
3974  if (ObjCPropertyDecl *FoundProp
3975  = dyn_cast<ObjCPropertyDecl>(FoundDecls[I])) {
3976  // Check property types.
3977  if (!Importer.IsStructurallyEquivalent(D->getType(),
3978  FoundProp->getType())) {
3979  Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent)
3980  << Name << D->getType() << FoundProp->getType();
3981  Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
3982  << FoundProp->getType();
3983  return nullptr;
3984  }
3985 
3986  // FIXME: Check property attributes, getters, setters, etc.?
3987 
3988  // Consider these properties to be equivalent.
3989  Importer.Imported(D, FoundProp);
3990  return FoundProp;
3991  }
3992  }
3993 
3994  // Import the type.
3995  TypeSourceInfo *TSI = Importer.Import(D->getTypeSourceInfo());
3996  if (!TSI)
3997  return nullptr;
3998 
3999  // Create the new property.
4000  ObjCPropertyDecl *ToProperty
4001  = ObjCPropertyDecl::Create(Importer.getToContext(), DC, Loc,
4002  Name.getAsIdentifierInfo(),
4003  Importer.Import(D->getAtLoc()),
4004  Importer.Import(D->getLParenLoc()),
4005  Importer.Import(D->getType()),
4006  TSI,
4008  Importer.Imported(D, ToProperty);
4009  ToProperty->setLexicalDeclContext(LexicalDC);
4010  LexicalDC->addDeclInternal(ToProperty);
4011 
4012  ToProperty->setPropertyAttributes(D->getPropertyAttributes());
4013  ToProperty->setPropertyAttributesAsWritten(
4015  ToProperty->setGetterName(Importer.Import(D->getGetterName()));
4016  ToProperty->setSetterName(Importer.Import(D->getSetterName()));
4017  ToProperty->setGetterMethodDecl(
4018  cast_or_null<ObjCMethodDecl>(Importer.Import(D->getGetterMethodDecl())));
4019  ToProperty->setSetterMethodDecl(
4020  cast_or_null<ObjCMethodDecl>(Importer.Import(D->getSetterMethodDecl())));
4021  ToProperty->setPropertyIvarDecl(
4022  cast_or_null<ObjCIvarDecl>(Importer.Import(D->getPropertyIvarDecl())));
4023  return ToProperty;
4024 }
4025 
4027  ObjCPropertyDecl *Property = cast_or_null<ObjCPropertyDecl>(
4028  Importer.Import(D->getPropertyDecl()));
4029  if (!Property)
4030  return nullptr;
4031 
4032  DeclContext *DC = Importer.ImportContext(D->getDeclContext());
4033  if (!DC)
4034  return nullptr;
4035 
4036  // Import the lexical declaration context.
4037  DeclContext *LexicalDC = DC;
4038  if (D->getDeclContext() != D->getLexicalDeclContext()) {
4039  LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
4040  if (!LexicalDC)
4041  return nullptr;
4042  }
4043 
4044  ObjCImplDecl *InImpl = dyn_cast<ObjCImplDecl>(LexicalDC);
4045  if (!InImpl)
4046  return nullptr;
4047 
4048  // Import the ivar (for an @synthesize).
4049  ObjCIvarDecl *Ivar = nullptr;
4050  if (D->getPropertyIvarDecl()) {
4051  Ivar = cast_or_null<ObjCIvarDecl>(
4052  Importer.Import(D->getPropertyIvarDecl()));
4053  if (!Ivar)
4054  return nullptr;
4055  }
4056 
4057  ObjCPropertyImplDecl *ToImpl
4058  = InImpl->FindPropertyImplDecl(Property->getIdentifier());
4059  if (!ToImpl) {
4060  ToImpl = ObjCPropertyImplDecl::Create(Importer.getToContext(), DC,
4061  Importer.Import(D->getLocStart()),
4062  Importer.Import(D->getLocation()),
4063  Property,
4065  Ivar,
4066  Importer.Import(D->getPropertyIvarDeclLoc()));
4067  ToImpl->setLexicalDeclContext(LexicalDC);
4068  Importer.Imported(D, ToImpl);
4069  LexicalDC->addDeclInternal(ToImpl);
4070  } else {
4071  // Check that we have the same kind of property implementation (@synthesize
4072  // vs. @dynamic).
4073  if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) {
4074  Importer.ToDiag(ToImpl->getLocation(),
4075  diag::err_odr_objc_property_impl_kind_inconsistent)
4076  << Property->getDeclName()
4077  << (ToImpl->getPropertyImplementation()
4079  Importer.FromDiag(D->getLocation(),
4080  diag::note_odr_objc_property_impl_kind)
4081  << D->getPropertyDecl()->getDeclName()
4083  return nullptr;
4084  }
4085 
4086  // For @synthesize, check that we have the same
4088  Ivar != ToImpl->getPropertyIvarDecl()) {
4089  Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
4090  diag::err_odr_objc_synthesize_ivar_inconsistent)
4091  << Property->getDeclName()
4092  << ToImpl->getPropertyIvarDecl()->getDeclName()
4093  << Ivar->getDeclName();
4094  Importer.FromDiag(D->getPropertyIvarDeclLoc(),
4095  diag::note_odr_objc_synthesize_ivar_here)
4096  << D->getPropertyIvarDecl()->getDeclName();
4097  return nullptr;
4098  }
4099 
4100  // Merge the existing implementation with the new implementation.
4101  Importer.Imported(D, ToImpl);
4102  }
4103 
4104  return ToImpl;
4105 }
4106 
4108  // For template arguments, we adopt the translation unit as our declaration
4109  // context. This context will be fixed when the actual template declaration
4110  // is created.
4111 
4112  // FIXME: Import default argument.
4113  return TemplateTypeParmDecl::Create(Importer.getToContext(),
4114  Importer.getToContext().getTranslationUnitDecl(),
4115  Importer.Import(D->getLocStart()),
4116  Importer.Import(D->getLocation()),
4117  D->getDepth(),
4118  D->getIndex(),
4119  Importer.Import(D->getIdentifier()),
4121  D->isParameterPack());
4122 }
4123 
4124 Decl *
4126  // Import the name of this declaration.
4127  DeclarationName Name = Importer.Import(D->getDeclName());
4128  if (D->getDeclName() && !Name)
4129  return nullptr;
4130 
4131  // Import the location of this declaration.
4132  SourceLocation Loc = Importer.Import(D->getLocation());
4133 
4134  // Import the type of this declaration.
4135  QualType T = Importer.Import(D->getType());
4136  if (T.isNull())
4137  return nullptr;
4138 
4139  // Import type-source information.
4140  TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
4141  if (D->getTypeSourceInfo() && !TInfo)
4142  return nullptr;
4143 
4144  // FIXME: Import default argument.
4145 
4147  Importer.getToContext().getTranslationUnitDecl(),
4148  Importer.Import(D->getInnerLocStart()),
4149  Loc, D->getDepth(), D->getPosition(),
4150  Name.getAsIdentifierInfo(),
4151  T, D->isParameterPack(), TInfo);
4152 }
4153 
4154 Decl *
4156  // Import the name of this declaration.
4157  DeclarationName Name = Importer.Import(D->getDeclName());
4158  if (D->getDeclName() && !Name)
4159  return nullptr;
4160 
4161  // Import the location of this declaration.
4162  SourceLocation Loc = Importer.Import(D->getLocation());
4163 
4164  // Import template parameters.
4165  TemplateParameterList *TemplateParams
4167  if (!TemplateParams)
4168  return nullptr;
4169 
4170  // FIXME: Import default argument.
4171 
4173  Importer.getToContext().getTranslationUnitDecl(),
4174  Loc, D->getDepth(), D->getPosition(),
4175  D->isParameterPack(),
4176  Name.getAsIdentifierInfo(),
4177  TemplateParams);
4178 }
4179 
4181  // If this record has a definition in the translation unit we're coming from,
4182  // but this particular declaration is not that definition, import the
4183  // definition and map to that.
4184  CXXRecordDecl *Definition
4185  = cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition());
4186  if (Definition && Definition != D->getTemplatedDecl()) {
4187  Decl *ImportedDef
4188  = Importer.Import(Definition->getDescribedClassTemplate());
4189  if (!ImportedDef)
4190  return nullptr;
4191 
4192  return Importer.Imported(D, ImportedDef);
4193  }
4194 
4195  // Import the major distinguishing characteristics of this class template.
4196  DeclContext *DC, *LexicalDC;
4197  DeclarationName Name;
4198  SourceLocation Loc;
4199  NamedDecl *ToD;
4200  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4201  return nullptr;
4202  if (ToD)
4203  return ToD;
4204 
4205  // We may already have a template of the same name; try to find and match it.
4206  if (!DC->isFunctionOrMethod()) {
4207  SmallVector<NamedDecl *, 4> ConflictingDecls;
4208  SmallVector<NamedDecl *, 2> FoundDecls;
4209  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
4210  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4211  if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary))
4212  continue;
4213 
4214  Decl *Found = FoundDecls[I];
4215  if (ClassTemplateDecl *FoundTemplate
4216  = dyn_cast<ClassTemplateDecl>(Found)) {
4217  if (IsStructuralMatch(D, FoundTemplate)) {
4218  // The class templates structurally match; call it the same template.
4219  // FIXME: We may be filling in a forward declaration here. Handle
4220  // this case!
4221  Importer.Imported(D->getTemplatedDecl(),
4222  FoundTemplate->getTemplatedDecl());
4223  return Importer.Imported(D, FoundTemplate);
4224  }
4225  }
4226 
4227  ConflictingDecls.push_back(FoundDecls[I]);
4228  }
4229 
4230  if (!ConflictingDecls.empty()) {
4231  Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary,
4232  ConflictingDecls.data(),
4233  ConflictingDecls.size());
4234  }
4235 
4236  if (!Name)
4237  return nullptr;
4238  }
4239 
4240  CXXRecordDecl *DTemplated = D->getTemplatedDecl();
4241 
4242  // Create the declaration that is being templated.
4243  SourceLocation StartLoc = Importer.Import(DTemplated->getLocStart());
4244  SourceLocation IdLoc = Importer.Import(DTemplated->getLocation());
4245  CXXRecordDecl *D2Templated = CXXRecordDecl::Create(Importer.getToContext(),
4246  DTemplated->getTagKind(),
4247  DC, StartLoc, IdLoc,
4248  Name.getAsIdentifierInfo());
4249  D2Templated->setAccess(DTemplated->getAccess());
4250  D2Templated->setQualifierInfo(Importer.Import(DTemplated->getQualifierLoc()));
4251  D2Templated->setLexicalDeclContext(LexicalDC);
4252 
4253  // Create the class template declaration itself.
4254  TemplateParameterList *TemplateParams
4256  if (!TemplateParams)
4257  return nullptr;
4258 
4260  Loc, Name, TemplateParams,
4261  D2Templated,
4262  /*PrevDecl=*/nullptr);
4263  D2Templated->setDescribedClassTemplate(D2);
4264 
4265  D2->setAccess(D->getAccess());
4266  D2->setLexicalDeclContext(LexicalDC);
4267  LexicalDC->addDeclInternal(D2);
4268 
4269  // Note the relationship between the class templates.
4270  Importer.Imported(D, D2);
4271  Importer.Imported(DTemplated, D2Templated);
4272 
4273  if (DTemplated->isCompleteDefinition() &&
4274  !D2Templated->isCompleteDefinition()) {
4275  // FIXME: Import definition!
4276  }
4277 
4278  return D2;
4279 }
4280 
4283  // If this record has a definition in the translation unit we're coming from,
4284  // but this particular declaration is not that definition, import the
4285  // definition and map to that.
4286  TagDecl *Definition = D->getDefinition();
4287  if (Definition && Definition != D) {
4288  Decl *ImportedDef = Importer.Import(Definition);
4289  if (!ImportedDef)
4290  return nullptr;
4291 
4292  return Importer.Imported(D, ImportedDef);
4293  }
4294 
4295  ClassTemplateDecl *ClassTemplate
4296  = cast_or_null<ClassTemplateDecl>(Importer.Import(
4297  D->getSpecializedTemplate()));
4298  if (!ClassTemplate)
4299  return nullptr;
4300 
4301  // Import the context of this declaration.
4302  DeclContext *DC = ClassTemplate->getDeclContext();
4303  if (!DC)
4304  return nullptr;
4305 
4306  DeclContext *LexicalDC = DC;
4307  if (D->getDeclContext() != D->getLexicalDeclContext()) {
4308  LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
4309  if (!LexicalDC)
4310  return nullptr;
4311  }
4312 
4313  // Import the location of this declaration.
4314  SourceLocation StartLoc = Importer.Import(D->getLocStart());
4315  SourceLocation IdLoc = Importer.Import(D->getLocation());
4316 
4317  // Import template arguments.
4318  SmallVector<TemplateArgument, 2> TemplateArgs;
4320  D->getTemplateArgs().size(),
4321  TemplateArgs))
4322  return nullptr;
4323 
4324  // Try to find an existing specialization with these template arguments.
4325  void *InsertPos = nullptr;
4327  = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
4328  if (D2) {
4329  // We already have a class template specialization with these template
4330  // arguments.
4331 
4332  // FIXME: Check for specialization vs. instantiation errors.
4333 
4334  if (RecordDecl *FoundDef = D2->getDefinition()) {
4335  if (!D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) {
4336  // The record types structurally match, or the "from" translation
4337  // unit only had a forward declaration anyway; call it the same
4338  // function.
4339  return Importer.Imported(D, FoundDef);
4340  }
4341  }
4342  } else {
4343  // Create a new specialization.
4345  D->getTagKind(), DC,
4346  StartLoc, IdLoc,
4347  ClassTemplate,
4348  TemplateArgs.data(),
4349  TemplateArgs.size(),
4350  /*PrevDecl=*/nullptr);
4352 
4353  // Add this specialization to the class template.
4354  ClassTemplate->AddSpecialization(D2, InsertPos);
4355 
4356  // Import the qualifier, if any.
4357  D2->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
4358 
4359  // Add the specialization to this context.
4360  D2->setLexicalDeclContext(LexicalDC);
4361  LexicalDC->addDeclInternal(D2);
4362  }
4363  Importer.Imported(D, D2);
4364 
4365  if (D->isCompleteDefinition() && ImportDefinition(D, D2))
4366  return nullptr;
4367 
4368  return D2;
4369 }
4370 
4372  // If this variable has a definition in the translation unit we're coming
4373  // from,
4374  // but this particular declaration is not that definition, import the
4375  // definition and map to that.
4376  VarDecl *Definition =
4377  cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition());
4378  if (Definition && Definition != D->getTemplatedDecl()) {
4379  Decl *ImportedDef = Importer.Import(Definition->getDescribedVarTemplate());
4380  if (!ImportedDef)
4381  return nullptr;
4382 
4383  return Importer.Imported(D, ImportedDef);
4384  }
4385 
4386  // Import the major distinguishing characteristics of this variable template.
4387  DeclContext *DC, *LexicalDC;
4388  DeclarationName Name;
4389  SourceLocation Loc;
4390  NamedDecl *ToD;
4391  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4392  return nullptr;
4393  if (ToD)
4394  return ToD;
4395 
4396  // We may already have a template of the same name; try to find and match it.
4397  assert(!DC->isFunctionOrMethod() &&
4398  "Variable templates cannot be declared at function scope");
4399  SmallVector<NamedDecl *, 4> ConflictingDecls;
4400  SmallVector<NamedDecl *, 2> FoundDecls;
4401  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
4402  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4403  if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary))
4404  continue;
4405 
4406  Decl *Found = FoundDecls[I];
4407  if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) {
4408  if (IsStructuralMatch(D, FoundTemplate)) {
4409  // The variable templates structurally match; call it the same template.
4410  Importer.Imported(D->getTemplatedDecl(),
4411  FoundTemplate->getTemplatedDecl());
4412  return Importer.Imported(D, FoundTemplate);
4413  }
4414  }
4415 
4416  ConflictingDecls.push_back(FoundDecls[I]);
4417  }
4418 
4419  if (!ConflictingDecls.empty()) {
4420  Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary,
4421  ConflictingDecls.data(),
4422  ConflictingDecls.size());
4423  }
4424 
4425  if (!Name)
4426  return nullptr;
4427 
4428  VarDecl *DTemplated = D->getTemplatedDecl();
4429 
4430  // Import the type.
4431  QualType T = Importer.Import(DTemplated->getType());
4432  if (T.isNull())
4433  return nullptr;
4434 
4435  // Create the declaration that is being templated.
4436  SourceLocation StartLoc = Importer.Import(DTemplated->getLocStart());
4437  SourceLocation IdLoc = Importer.Import(DTemplated->getLocation());
4438  TypeSourceInfo *TInfo = Importer.Import(DTemplated->getTypeSourceInfo());
4439  VarDecl *D2Templated = VarDecl::Create(Importer.getToContext(), DC, StartLoc,
4440  IdLoc, Name.getAsIdentifierInfo(), T,
4441  TInfo, DTemplated->getStorageClass());
4442  D2Templated->setAccess(DTemplated->getAccess());
4443  D2Templated->setQualifierInfo(Importer.Import(DTemplated->getQualifierLoc()));
4444  D2Templated->setLexicalDeclContext(LexicalDC);
4445 
4446  // Importer.Imported(DTemplated, D2Templated);
4447  // LexicalDC->addDeclInternal(D2Templated);
4448 
4449  // Merge the initializer.
4450  if (ImportDefinition(DTemplated, D2Templated))
4451  return nullptr;
4452 
4453  // Create the variable template declaration itself.
4454  TemplateParameterList *TemplateParams =
4456  if (!TemplateParams)
4457  return nullptr;
4458 
4460  Importer.getToContext(), DC, Loc, Name, TemplateParams, D2Templated);
4461  D2Templated->setDescribedVarTemplate(D2);
4462 
4463  D2->setAccess(D->getAccess());
4464  D2->setLexicalDeclContext(LexicalDC);
4465  LexicalDC->addDeclInternal(D2);
4466 
4467  // Note the relationship between the variable templates.
4468  Importer.Imported(D, D2);
4469  Importer.Imported(DTemplated, D2Templated);
4470 
4471  if (DTemplated->isThisDeclarationADefinition() &&
4472  !D2Templated->isThisDeclarationADefinition()) {
4473  // FIXME: Import definition!
4474  }
4475 
4476  return D2;
4477 }
4478 
4481  // If this record has a definition in the translation unit we're coming from,
4482  // but this particular declaration is not that definition, import the
4483  // definition and map to that.
4484  VarDecl *Definition = D->getDefinition();
4485  if (Definition && Definition != D) {
4486  Decl *ImportedDef = Importer.Import(Definition);
4487  if (!ImportedDef)
4488  return nullptr;
4489 
4490  return Importer.Imported(D, ImportedDef);
4491  }
4492 
4493  VarTemplateDecl *VarTemplate = cast_or_null<VarTemplateDecl>(
4494  Importer.Import(D->getSpecializedTemplate()));
4495  if (!VarTemplate)
4496  return nullptr;
4497 
4498  // Import the context of this declaration.
4499  DeclContext *DC = VarTemplate->getDeclContext();
4500  if (!DC)
4501  return nullptr;
4502 
4503  DeclContext *LexicalDC = DC;
4504  if (D->getDeclContext() != D->getLexicalDeclContext()) {
4505  LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
4506  if (!LexicalDC)
4507  return nullptr;
4508  }
4509 
4510  // Import the location of this declaration.
4511  SourceLocation StartLoc = Importer.Import(D->getLocStart());
4512  SourceLocation IdLoc = Importer.Import(D->getLocation());
4513 
4514  // Import template arguments.
4515  SmallVector<TemplateArgument, 2> TemplateArgs;
4517  D->getTemplateArgs().size(), TemplateArgs))
4518  return nullptr;
4519 
4520  // Try to find an existing specialization with these template arguments.
4521  void *InsertPos = nullptr;
4523  TemplateArgs, InsertPos);
4524  if (D2) {
4525  // We already have a variable template specialization with these template
4526  // arguments.
4527 
4528  // FIXME: Check for specialization vs. instantiation errors.
4529 
4530  if (VarDecl *FoundDef = D2->getDefinition()) {
4531  if (!D->isThisDeclarationADefinition() ||
4532  IsStructuralMatch(D, FoundDef)) {
4533  // The record types structurally match, or the "from" translation
4534  // unit only had a forward declaration anyway; call it the same
4535  // variable.
4536  return Importer.Imported(D, FoundDef);
4537  }
4538  }
4539  } else {
4540 
4541  // Import the type.
4542  QualType T = Importer.Import(D->getType());
4543  if (T.isNull())
4544  return nullptr;
4545  TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
4546 
4547  // Create a new specialization.
4549  Importer.getToContext(), DC, StartLoc, IdLoc, VarTemplate, T, TInfo,
4550  D->getStorageClass(), TemplateArgs.data(), TemplateArgs.size());
4553 
4554  // Add this specialization to the class template.
4555  VarTemplate->AddSpecialization(D2, InsertPos);
4556 
4557  // Import the qualifier, if any.
4558  D2->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
4559 
4560  // Add the specialization to this context.
4561  D2->setLexicalDeclContext(LexicalDC);
4562  LexicalDC->addDeclInternal(D2);
4563  }
4564  Importer.Imported(D, D2);
4565 
4567  return nullptr;
4568 
4569  return D2;
4570 }
4571 
4572 //----------------------------------------------------------------------------
4573 // Import Statements
4574 //----------------------------------------------------------------------------
4575 
4577  if (DG.isNull())
4578  return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
4579  size_t NumDecls = DG.end() - DG.begin();
4580  SmallVector<Decl *, 1> ToDecls(NumDecls);
4581  auto &_Importer = this->Importer;
4582  std::transform(DG.begin(), DG.end(), ToDecls.begin(),
4583  [&_Importer](Decl *D) -> Decl * {
4584  return _Importer.Import(D);
4585  });
4586  return DeclGroupRef::Create(Importer.getToContext(),
4587  ToDecls.begin(),
4588  NumDecls);
4589 }
4590 
4592  Importer.FromDiag(S->getLocStart(), diag::err_unsupported_ast_node)
4593  << S->getStmtClassName();
4594  return nullptr;
4595  }
4596 
4599  for (Decl *ToD : ToDG) {
4600  if (!ToD)
4601  return nullptr;
4602  }
4603  SourceLocation ToStartLoc = Importer.Import(S->getStartLoc());
4604  SourceLocation ToEndLoc = Importer.Import(S->getEndLoc());
4605  return new (Importer.getToContext()) DeclStmt(ToDG, ToStartLoc, ToEndLoc);
4606 }
4607 
4609  SourceLocation ToSemiLoc = Importer.Import(S->getSemiLoc());
4610  return new (Importer.getToContext()) NullStmt(ToSemiLoc,
4611  S->hasLeadingEmptyMacro());
4612 }
4613 
4615  SmallVector<Stmt *, 4> ToStmts(S->size());
4616  auto &_Importer = this->Importer;
4617  std::transform(S->body_begin(), S->body_end(), ToStmts.begin(),
4618  [&_Importer](Stmt *CS) -> Stmt * {
4619  return _Importer.Import(CS);
4620  });
4621  for (Stmt *ToS : ToStmts) {
4622  if (!ToS)
4623  return nullptr;
4624  }
4625  SourceLocation ToLBraceLoc = Importer.Import(S->getLBracLoc());
4626  SourceLocation ToRBraceLoc = Importer.Import(S->getRBracLoc());
4627  return new (Importer.getToContext()) CompoundStmt(Importer.getToContext(),
4628  ToStmts,
4629  ToLBraceLoc, ToRBraceLoc);
4630 }
4631 
4633  Expr *ToLHS = Importer.Import(S->getLHS());
4634  if (!ToLHS)
4635  return nullptr;
4636  Expr *ToRHS = Importer.Import(S->getRHS());
4637  if (!ToRHS && S->getRHS())
4638  return nullptr;
4639  SourceLocation ToCaseLoc = Importer.Import(S->getCaseLoc());
4640  SourceLocation ToEllipsisLoc = Importer.Import(S->getEllipsisLoc());
4641  SourceLocation ToColonLoc = Importer.Import(S->getColonLoc());
4642  return new (Importer.getToContext()) CaseStmt(ToLHS, ToRHS,
4643  ToCaseLoc, ToEllipsisLoc,
4644  ToColonLoc);
4645 }
4646 
4648  SourceLocation ToDefaultLoc = Importer.Import(S->getDefaultLoc());
4649  SourceLocation ToColonLoc = Importer.Import(S->getColonLoc());
4650  Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
4651  if (!ToSubStmt && S->getSubStmt())
4652  return nullptr;
4653  return new (Importer.getToContext()) DefaultStmt(ToDefaultLoc, ToColonLoc,
4654  ToSubStmt);
4655 }
4656 
4658  SourceLocation ToIdentLoc = Importer.Import(S->getIdentLoc());
4659  LabelDecl *ToLabelDecl =
4660  cast_or_null<LabelDecl>(Importer.Import(S->getDecl()));
4661  if (!ToLabelDecl && S->getDecl())
4662  return nullptr;
4663  Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
4664  if (!ToSubStmt && S->getSubStmt())
4665  return nullptr;
4666  return new (Importer.getToContext()) LabelStmt(ToIdentLoc, ToLabelDecl,
4667  ToSubStmt);
4668 }
4669 
4671  SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc());
4672  ArrayRef<const Attr*> FromAttrs(S->getAttrs());
4673  SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
4674  ASTContext &_ToContext = Importer.getToContext();
4675  std::transform(FromAttrs.begin(), FromAttrs.end(), ToAttrs.begin(),
4676  [&_ToContext](const Attr *A) -> const Attr * {
4677  return A->clone(_ToContext);
4678  });
4679  for (const Attr *ToA : ToAttrs) {
4680  if (!ToA)
4681  return nullptr;
4682  }
4683  Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
4684  if (!ToSubStmt && S->getSubStmt())
4685  return nullptr;
4686  return AttributedStmt::Create(Importer.getToContext(), ToAttrLoc,
4687  ToAttrs, ToSubStmt);
4688 }
4689 
4691  SourceLocation ToIfLoc = Importer.Import(S->getIfLoc());
4692  VarDecl *ToConditionVariable = nullptr;
4693  if (VarDecl *FromConditionVariable = S->getConditionVariable()) {
4694  ToConditionVariable =
4695  dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable));
4696  if (!ToConditionVariable)
4697  return nullptr;
4698  }
4699  Expr *ToCondition = Importer.Import(S->getCond());
4700  if (!ToCondition && S->getCond())
4701  return nullptr;
4702  Stmt *ToThenStmt = Importer.Import(S->getThen());
4703  if (!ToThenStmt && S->getThen())
4704  return nullptr;
4705  SourceLocation ToElseLoc = Importer.Import(S->getElseLoc());
4706  Stmt *ToElseStmt = Importer.Import(S->getElse());
4707  if (!ToElseStmt && S->getElse())
4708  return nullptr;
4709  return new (Importer.getToContext()) IfStmt(Importer.getToContext(),
4710  ToIfLoc, ToConditionVariable,
4711  ToCondition, ToThenStmt,
4712  ToElseLoc, ToElseStmt);
4713 }
4714 
4716  VarDecl *ToConditionVariable = nullptr;
4717  if (VarDecl *FromConditionVariable = S->getConditionVariable()) {
4718  ToConditionVariable =
4719  dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable));
4720  if (!ToConditionVariable)
4721  return nullptr;
4722  }
4723  Expr *ToCondition = Importer.Import(S->getCond());
4724  if (!ToCondition && S->getCond())
4725  return nullptr;
4726  SwitchStmt *ToStmt = new (Importer.getToContext()) SwitchStmt(
4727  Importer.getToContext(), ToConditionVariable,
4728  ToCondition);
4729  Stmt *ToBody = Importer.Import(S->getBody());
4730  if (!ToBody && S->getBody())
4731  return nullptr;
4732  ToStmt->setBody(ToBody);
4733  ToStmt->setSwitchLoc(Importer.Import(S->getSwitchLoc()));
4734  // Now we have to re-chain the cases.
4735  SwitchCase *LastChainedSwitchCase = nullptr;
4736  for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
4737  SC = SC->getNextSwitchCase()) {
4738  SwitchCase *ToSC = dyn_cast_or_null<SwitchCase>(Importer.Import(SC));
4739  if (!ToSC)
4740  return nullptr;
4741  if (LastChainedSwitchCase)
4742  LastChainedSwitchCase->setNextSwitchCase(ToSC);
4743  else
4744  ToStmt->setSwitchCaseList(ToSC);
4745  LastChainedSwitchCase = ToSC;
4746  }
4747  return ToStmt;
4748 }
4749 
4751  VarDecl *ToConditionVariable = nullptr;
4752  if (VarDecl *FromConditionVariable = S->getConditionVariable()) {
4753  ToConditionVariable =
4754  dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable));
4755  if (!ToConditionVariable)
4756  return nullptr;
4757  }
4758  Expr *ToCondition = Importer.Import(S->getCond());
4759  if (!ToCondition && S->getCond())
4760  return nullptr;
4761  Stmt *ToBody = Importer.Import(S->getBody());
4762  if (!ToBody && S->getBody())
4763  return nullptr;
4764  SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc());
4765  return new (Importer.getToContext()) WhileStmt(Importer.getToContext(),
4766  ToConditionVariable,
4767  ToCondition, ToBody,
4768  ToWhileLoc);
4769 }
4770 
4772  Stmt *ToBody = Importer.Import(S->getBody());
4773  if (!ToBody && S->getBody())
4774  return nullptr;
4775  Expr *ToCondition = Importer.Import(S->getCond());
4776  if (!ToCondition && S->getCond())
4777  return nullptr;
4778  SourceLocation ToDoLoc = Importer.Import(S->getDoLoc());
4779  SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc());
4780  SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
4781  return new (Importer.getToContext()) DoStmt(ToBody, ToCondition,
4782  ToDoLoc, ToWhileLoc,
4783  ToRParenLoc);
4784 }
4785 
4787  Stmt *ToInit = Importer.Import(S->getInit());
4788  if (!ToInit && S->getInit())
4789  return nullptr;
4790  Expr *ToCondition = Importer.Import(S->getCond());
4791  if (!ToCondition && S->getCond())
4792  return nullptr;
4793  VarDecl *ToConditionVariable = nullptr;
4794  if (VarDecl *FromConditionVariable = S->getConditionVariable()) {
4795  ToConditionVariable =
4796  dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable));
4797  if (!ToConditionVariable)
4798  return nullptr;
4799  }
4800  Expr *ToInc = Importer.Import(S->getInc());
4801  if (!ToInc && S->getInc())
4802  return nullptr;
4803  Stmt *ToBody = Importer.Import(S->getBody());
4804  if (!ToBody && S->getBody())
4805  return nullptr;
4806  SourceLocation ToForLoc = Importer.Import(S->getForLoc());
4807  SourceLocation ToLParenLoc = Importer.Import(S->getLParenLoc());
4808  SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
4809  return new (Importer.getToContext()) ForStmt(Importer.getToContext(),
4810  ToInit, ToCondition,
4811  ToConditionVariable,
4812  ToInc, ToBody,
4813  ToForLoc, ToLParenLoc,
4814  ToRParenLoc);
4815 }
4816 
4818  LabelDecl *ToLabel = nullptr;
4819  if (LabelDecl *FromLabel = S->getLabel()) {
4820  ToLabel = dyn_cast_or_null<LabelDecl>(Importer.Import(FromLabel));
4821  if (!ToLabel)
4822  return nullptr;
4823  }
4824  SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc());
4825  SourceLocation ToLabelLoc = Importer.Import(S->getLabelLoc());
4826  return new (Importer.getToContext()) GotoStmt(ToLabel,
4827  ToGotoLoc, ToLabelLoc);
4828 }
4829 
4831  SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc());
4832  SourceLocation ToStarLoc = Importer.Import(S->getStarLoc());
4833  Expr *ToTarget = Importer.Import(S->getTarget());
4834  if (!ToTarget && S->getTarget())
4835  return nullptr;
4836  return new (Importer.getToContext()) IndirectGotoStmt(ToGotoLoc, ToStarLoc,
4837  ToTarget);
4838 }
4839 
4841  SourceLocation ToContinueLoc = Importer.Import(S->getContinueLoc());
4842  return new (Importer.getToContext()) ContinueStmt(ToContinueLoc);
4843 }
4844 
4846  SourceLocation ToBreakLoc = Importer.Import(S->getBreakLoc());
4847  return new (Importer.getToContext()) BreakStmt(ToBreakLoc);
4848 }
4849 
4851  SourceLocation ToRetLoc = Importer.Import(S->getReturnLoc());
4852  Expr *ToRetExpr = Importer.Import(S->getRetValue());
4853  if (!ToRetExpr && S->getRetValue())
4854  return nullptr;
4855  VarDecl *NRVOCandidate = const_cast<VarDecl*>(S->getNRVOCandidate());
4856  VarDecl *ToNRVOCandidate = cast_or_null<VarDecl>(Importer.Import(NRVOCandidate));
4857  if (!ToNRVOCandidate && NRVOCandidate)
4858  return nullptr;
4859  return new (Importer.getToContext()) ReturnStmt(ToRetLoc, ToRetExpr,
4860  ToNRVOCandidate);
4861 }
4862 
4864  SourceLocation ToCatchLoc = Importer.Import(S->getCatchLoc());
4865  VarDecl *ToExceptionDecl = nullptr;
4866  if (VarDecl *FromExceptionDecl = S->getExceptionDecl()) {
4867  ToExceptionDecl =
4868  dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl));
4869  if (!ToExceptionDecl)
4870  return nullptr;
4871  }
4872  Stmt *ToHandlerBlock = Importer.Import(S->getHandlerBlock());
4873  if (!ToHandlerBlock && S->getHandlerBlock())
4874  return nullptr;
4875  return new (Importer.getToContext()) CXXCatchStmt(ToCatchLoc,
4876  ToExceptionDecl,
4877  ToHandlerBlock);
4878 }
4879 
4881  SourceLocation ToTryLoc = Importer.Import(S->getTryLoc());
4882  Stmt *ToTryBlock = Importer.Import(S->getTryBlock());
4883  if (!ToTryBlock && S->getTryBlock())
4884  return nullptr;
4885  SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
4886  for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
4887  CXXCatchStmt *FromHandler = S->getHandler(HI);
4888  if (Stmt *ToHandler = Importer.Import(FromHandler))
4889  ToHandlers[HI] = ToHandler;
4890  else
4891  return nullptr;
4892  }
4893  return CXXTryStmt::Create(Importer.getToContext(), ToTryLoc, ToTryBlock,
4894  ToHandlers);
4895 }
4896 
4898  DeclStmt *ToRange =
4899  dyn_cast_or_null<DeclStmt>(Importer.Import(S->getRangeStmt()));
4900  if (!ToRange && S->getRangeStmt())
4901  return nullptr;
4902  DeclStmt *ToBeginEnd =
4903  dyn_cast_or_null<DeclStmt>(Importer.Import(S->getBeginEndStmt()));
4904  if (!ToBeginEnd && S->getBeginEndStmt())
4905  return nullptr;
4906  Expr *ToCond = Importer.Import(S->getCond());
4907  if (!ToCond && S->getCond())
4908  return nullptr;
4909  Expr *ToInc = Importer.Import(S->getInc());
4910  if (!ToInc && S->getInc())
4911  return nullptr;
4912  DeclStmt *ToLoopVar =
4913  dyn_cast_or_null<DeclStmt>(Importer.Import(S->getLoopVarStmt()));
4914  if (!ToLoopVar && S->getLoopVarStmt())
4915  return nullptr;
4916  Stmt *ToBody = Importer.Import(S->getBody());
4917  if (!ToBody && S->getBody())
4918  return nullptr;
4919  SourceLocation ToForLoc = Importer.Import(S->getForLoc());
4920  SourceLocation ToColonLoc = Importer.Import(S->getColonLoc());
4921  SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
4922  return new (Importer.getToContext()) CXXForRangeStmt(ToRange, ToBeginEnd,
4923  ToCond, ToInc,
4924  ToLoopVar, ToBody,
4925  ToForLoc, ToColonLoc,
4926  ToRParenLoc);
4927 }
4928 
4930  Stmt *ToElem = Importer.Import(S->getElement());
4931  if (!ToElem && S->getElement())
4932  return nullptr;
4933  Expr *ToCollect = Importer.Import(S->getCollection());
4934  if (!ToCollect && S->getCollection())
4935  return nullptr;
4936  Stmt *ToBody = Importer.Import(S->getBody());
4937  if (!ToBody && S->getBody())
4938  return nullptr;
4939  SourceLocation ToForLoc = Importer.Import(S->getForLoc());
4940  SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
4941  return new (Importer.getToContext()) ObjCForCollectionStmt(ToElem,
4942  ToCollect,
4943  ToBody, ToForLoc,
4944  ToRParenLoc);
4945 }
4946 
4948  SourceLocation ToAtCatchLoc = Importer.Import(S->getAtCatchLoc());
4949  SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
4950  VarDecl *ToExceptionDecl = nullptr;
4951  if (VarDecl *FromExceptionDecl = S->getCatchParamDecl()) {
4952  ToExceptionDecl =
4953  dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl));
4954  if (!ToExceptionDecl)
4955  return nullptr;
4956  }
4957  Stmt *ToBody = Importer.Import(S->getCatchBody());
4958  if (!ToBody && S->getCatchBody())
4959  return nullptr;
4960  return new (Importer.getToContext()) ObjCAtCatchStmt(ToAtCatchLoc,
4961  ToRParenLoc,
4962  ToExceptionDecl,
4963  ToBody);
4964 }
4965 
4967  SourceLocation ToAtFinallyLoc = Importer.Import(S->getAtFinallyLoc());
4968  Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyBody());
4969  if (!ToAtFinallyStmt && S->getFinallyBody())
4970  return nullptr;
4971  return new (Importer.getToContext()) ObjCAtFinallyStmt(ToAtFinallyLoc,
4972  ToAtFinallyStmt);
4973 }
4974 
4976  SourceLocation ToAtTryLoc = Importer.Import(S->getAtTryLoc());
4977  Stmt *ToAtTryStmt = Importer.Import(S->getTryBody());
4978  if (!ToAtTryStmt && S->getTryBody())
4979  return nullptr;
4980  SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
4981  for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
4982  ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
4983  if (Stmt *ToCatchStmt = Importer.Import(FromCatchStmt))
4984  ToCatchStmts[CI] = ToCatchStmt;
4985  else
4986  return nullptr;
4987  }
4988  Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyStmt());
4989  if (!ToAtFinallyStmt && S->getFinallyStmt())
4990  return nullptr;
4991  return ObjCAtTryStmt::Create(Importer.getToContext(),
4992  ToAtTryLoc, ToAtTryStmt,
4993  ToCatchStmts.begin(), ToCatchStmts.size(),
4994  ToAtFinallyStmt);
4995 }
4996 
4999  SourceLocation ToAtSynchronizedLoc =
5000  Importer.Import(S->getAtSynchronizedLoc());
5001  Expr *ToSynchExpr = Importer.Import(S->getSynchExpr());
5002  if (!ToSynchExpr && S->getSynchExpr())
5003  return nullptr;
5004  Stmt *ToSynchBody = Importer.Import(S->getSynchBody());
5005  if (!ToSynchBody && S->getSynchBody())
5006  return nullptr;
5007  return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
5008  ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
5009 }
5010 
5012  SourceLocation ToAtThrowLoc = Importer.Import(S->getThrowLoc());
5013  Expr *ToThrow = Importer.Import(S->getThrowExpr());
5014  if (!ToThrow && S->getThrowExpr())
5015  return nullptr;
5016  return new (Importer.getToContext()) ObjCAtThrowStmt(ToAtThrowLoc, ToThrow);
5017 }
5018 
5021  SourceLocation ToAtLoc = Importer.Import(S->getAtLoc());
5022  Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
5023  if (!ToSubStmt && S->getSubStmt())
5024  return nullptr;
5025  return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(ToAtLoc,
5026  ToSubStmt);
5027 }
5028 
5029 //----------------------------------------------------------------------------
5030 // Import Expressions
5031 //----------------------------------------------------------------------------
5033  Importer.FromDiag(E->getLocStart(), diag::err_unsupported_ast_node)
5034  << E->getStmtClassName();
5035  return nullptr;
5036 }
5037 
5039  ValueDecl *ToD = cast_or_null<ValueDecl>(Importer.Import(E->getDecl()));
5040  if (!ToD)
5041  return nullptr;
5042 
5043  NamedDecl *FoundD = nullptr;
5044  if (E->getDecl() != E->getFoundDecl()) {
5045  FoundD = cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl()));
5046  if (!FoundD)
5047  return nullptr;
5048  }
5049 
5050  QualType T = Importer.Import(E->getType());
5051  if (T.isNull())
5052  return nullptr;
5053 
5054  DeclRefExpr *DRE = DeclRefExpr::Create(Importer.getToContext(),
5055  Importer.Import(E->getQualifierLoc()),
5056  Importer.Import(E->getTemplateKeywordLoc()),
5057  ToD,
5059  Importer.Import(E->getLocation()),
5060  T, E->getValueKind(),
5061  FoundD,
5062  /*FIXME:TemplateArgs=*/nullptr);
5063  if (E->hadMultipleCandidates())
5064  DRE->setHadMultipleCandidates(true);
5065  return DRE;
5066 }
5067 
5069  QualType T = Importer.Import(E->getType());
5070  if (T.isNull())
5071  return nullptr;
5072 
5073  return IntegerLiteral::Create(Importer.getToContext(),
5074  E->getValue(), T,
5075  Importer.Import(E->getLocation()));
5076 }
5077 
5079  QualType T = Importer.Import(E->getType());
5080  if (T.isNull())
5081  return nullptr;
5082 
5083  return new (Importer.getToContext()) CharacterLiteral(E->getValue(),
5084  E->getKind(), T,
5085  Importer.Import(E->getLocation()));
5086 }
5087 
5089  Expr *SubExpr = Importer.Import(E->getSubExpr());
5090  if (!SubExpr)
5091  return nullptr;
5092 
5093  return new (Importer.getToContext())
5094  ParenExpr(Importer.Import(E->getLParen()),
5095  Importer.Import(E->getRParen()),
5096  SubExpr);
5097 }
5098 
5100  QualType T = Importer.Import(E->getType());
5101  if (T.isNull())
5102  return nullptr;
5103 
5104  Expr *SubExpr = Importer.Import(E->getSubExpr());
5105  if (!SubExpr)
5106  return nullptr;
5107 
5108  return new (Importer.getToContext()) UnaryOperator(SubExpr, E->getOpcode(),
5109  T, E->getValueKind(),
5110  E->getObjectKind(),
5111  Importer.Import(E->getOperatorLoc()));
5112 }
5113 
5116  QualType ResultType = Importer.Import(E->getType());
5117 
5118  if (E->isArgumentType()) {
5119  TypeSourceInfo *TInfo = Importer.Import(E->getArgumentTypeInfo());
5120  if (!TInfo)
5121  return nullptr;
5122 
5123  return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(),
5124  TInfo, ResultType,
5125  Importer.Import(E->getOperatorLoc()),
5126  Importer.Import(E->getRParenLoc()));
5127  }
5128 
5129  Expr *SubExpr = Importer.Import(E->getArgumentExpr());
5130  if (!SubExpr)
5131  return nullptr;
5132 
5133  return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(),
5134  SubExpr, ResultType,
5135  Importer.Import(E->getOperatorLoc()),
5136  Importer.Import(E->getRParenLoc()));
5137 }
5138 
5140  QualType T = Importer.Import(E->getType());
5141  if (T.isNull())
5142  return nullptr;
5143 
5144  Expr *LHS = Importer.Import(E->getLHS());
5145  if (!LHS)
5146  return nullptr;
5147 
5148  Expr *RHS = Importer.Import(E->getRHS());
5149  if (!RHS)
5150  return nullptr;
5151 
5152  return new (Importer.getToContext()) BinaryOperator(LHS, RHS, E->getOpcode(),
5153  T, E->getValueKind(),
5154  E->getObjectKind(),
5155  Importer.Import(E->getOperatorLoc()),
5156  E->isFPContractable());
5157 }
5158 
5160  QualType T = Importer.Import(E->getType());
5161  if (T.isNull())
5162  return nullptr;
5163 
5164  QualType CompLHSType = Importer.Import(E->getComputationLHSType());
5165  if (CompLHSType.isNull())
5166  return nullptr;
5167 
5168  QualType CompResultType = Importer.Import(E->getComputationResultType());
5169  if (CompResultType.isNull())
5170  return nullptr;
5171 
5172  Expr *LHS = Importer.Import(E->getLHS());
5173  if (!LHS)
5174  return nullptr;
5175 
5176  Expr *RHS = Importer.Import(E->getRHS());
5177  if (!RHS)
5178  return nullptr;
5179 
5180  return new (Importer.getToContext())
5181  CompoundAssignOperator(LHS, RHS, E->getOpcode(),
5182  T, E->getValueKind(),
5183  E->getObjectKind(),
5184  CompLHSType, CompResultType,
5185  Importer.Import(E->getOperatorLoc()),
5186  E->isFPContractable());
5187 }
5188 
5189 static bool ImportCastPath(CastExpr *E, CXXCastPath &Path) {
5190  if (E->path_empty()) return false;
5191 
5192  // TODO: import cast paths
5193  return true;
5194 }
5195 
5197  QualType T = Importer.Import(E->getType());
5198  if (T.isNull())
5199  return nullptr;
5200 
5201  Expr *SubExpr = Importer.Import(E->getSubExpr());
5202  if (!SubExpr)
5203  return nullptr;
5204 
5205  CXXCastPath BasePath;
5206  if (ImportCastPath(E, BasePath))
5207  return nullptr;
5208 
5209  return ImplicitCastExpr::Create(Importer.getToContext(), T, E->getCastKind(),
5210  SubExpr, &BasePath, E->getValueKind());
5211 }
5212 
5214  QualType T = Importer.Import(E->getType());
5215  if (T.isNull())
5216  return nullptr;
5217 
5218  Expr *SubExpr = Importer.Import(E->getSubExpr());
5219  if (!SubExpr)
5220  return nullptr;
5221 
5222  TypeSourceInfo *TInfo = Importer.Import(E->getTypeInfoAsWritten());
5223  if (!TInfo && E->getTypeInfoAsWritten())
5224  return nullptr;
5225 
5226  CXXCastPath BasePath;
5227  if (ImportCastPath(E, BasePath))
5228  return nullptr;
5229 
5230  return CStyleCastExpr::Create(Importer.getToContext(), T,
5231  E->getValueKind(), E->getCastKind(),
5232  SubExpr, &BasePath, TInfo,
5233  Importer.Import(E->getLParenLoc()),
5234  Importer.Import(E->getRParenLoc()));
5235 }
5236 
5238  QualType T = Importer.Import(E->getType());
5239  if (T.isNull())
5240  return nullptr;
5241 
5242  CXXConstructorDecl *ToCCD =
5243  dyn_cast<CXXConstructorDecl>(Importer.Import(E->getConstructor()));
5244  if (!ToCCD && E->getConstructor())
5245  return nullptr;
5246 
5247  size_t NumArgs = E->getNumArgs();
5248  SmallVector<Expr *, 1> ToArgs(NumArgs);
5249  ASTImporter &_Importer = Importer;
5250  std::transform(E->arg_begin(), E->arg_end(), ToArgs.begin(),
5251  [&_Importer](Expr *AE) -> Expr * {
5252  return _Importer.Import(AE);
5253  });
5254  for (Expr *ToA : ToArgs) {
5255  if (!ToA)
5256  return nullptr;
5257  }
5258 
5259  return CXXConstructExpr::Create(Importer.getToContext(), T,
5260  Importer.Import(E->getLocation()),
5261  ToCCD, E->isElidable(),
5262  ToArgs, E->hadMultipleCandidates(),
5263  E->isListInitialization(),
5266  E->getConstructionKind(),
5267  Importer.Import(E->getParenOrBraceRange()));
5268 }
5269 
5271  QualType T = Importer.Import(E->getType());
5272  if (T.isNull())
5273  return nullptr;
5274 
5275  Expr *ToBase = Importer.Import(E->getBase());
5276  if (!ToBase && E->getBase())
5277  return nullptr;
5278 
5279  ValueDecl *ToMember = dyn_cast<ValueDecl>(Importer.Import(E->getMemberDecl()));
5280  if (!ToMember && E->getMemberDecl())
5281  return nullptr;
5282 
5283  DeclAccessPair ToFoundDecl = DeclAccessPair::make(
5284  dyn_cast<NamedDecl>(Importer.Import(E->getFoundDecl().getDecl())),
5285  E->getFoundDecl().getAccess());
5286 
5287  DeclarationNameInfo ToMemberNameInfo(
5288  Importer.Import(E->getMemberNameInfo().getName()),
5289  Importer.Import(E->getMemberNameInfo().getLoc()));
5290 
5291  if (E->hasExplicitTemplateArgs()) {
5292  return nullptr; // FIXME: handle template arguments
5293  }
5294 
5295  return MemberExpr::Create(Importer.getToContext(), ToBase,
5296  E->isArrow(),
5297  Importer.Import(E->getOperatorLoc()),
5298  Importer.Import(E->getQualifierLoc()),
5299  Importer.Import(E->getTemplateKeywordLoc()),
5300  ToMember, ToFoundDecl, ToMemberNameInfo,
5301  nullptr, T, E->getValueKind(),
5302  E->getObjectKind());
5303 }
5304 
5306  QualType T = Importer.Import(E->getType());
5307  if (T.isNull())
5308  return nullptr;
5309 
5310  Expr *ToCallee = Importer.Import(E->getCallee());
5311  if (!ToCallee && E->getCallee())
5312  return nullptr;
5313 
5314  unsigned NumArgs = E->getNumArgs();
5315 
5316  llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
5317 
5318  for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) {
5319  Expr *FromArg = E->getArg(ai);
5320  Expr *ToArg = Importer.Import(FromArg);
5321  if (!ToArg)
5322  return nullptr;
5323  ToArgs[ai] = ToArg;
5324  }
5325 
5326  Expr **ToArgs_Copied = new (Importer.getToContext())
5327  Expr*[NumArgs];
5328 
5329  for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai)
5330  ToArgs_Copied[ai] = ToArgs[ai];
5331 
5332  return new (Importer.getToContext())
5333  CallExpr(Importer.getToContext(), ToCallee,
5334  ArrayRef<Expr*>(ToArgs_Copied, NumArgs), T, E->getValueKind(),
5335  Importer.Import(E->getRParenLoc()));
5336 }
5337 
5339  ASTContext &FromContext, FileManager &FromFileManager,
5340  bool MinimalImport)
5341  : ToContext(ToContext), FromContext(FromContext),
5342  ToFileManager(ToFileManager), FromFileManager(FromFileManager),
5343  Minimal(MinimalImport), LastDiagFromFrom(false)
5344 {
5345  ImportedDecls[FromContext.getTranslationUnitDecl()]
5346  = ToContext.getTranslationUnitDecl();
5347 }
5348 
5350 
5352  if (FromT.isNull())
5353  return QualType();
5354 
5355  const Type *fromTy = FromT.getTypePtr();
5356 
5357  // Check whether we've already imported this type.
5358  llvm::DenseMap<const Type *, const Type *>::iterator Pos
5359  = ImportedTypes.find(fromTy);
5360  if (Pos != ImportedTypes.end())
5361  return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers());
5362 
5363  // Import the type
5364  ASTNodeImporter Importer(*this);
5365  QualType ToT = Importer.Visit(fromTy);
5366  if (ToT.isNull())
5367  return ToT;
5368 
5369  // Record the imported type.
5370  ImportedTypes[fromTy] = ToT.getTypePtr();
5371 
5372  return ToContext.getQualifiedType(ToT, FromT.getLocalQualifiers());
5373 }
5374 
5376  if (!FromTSI)
5377  return FromTSI;
5378 
5379  // FIXME: For now we just create a "trivial" type source info based
5380  // on the type and a single location. Implement a real version of this.
5381  QualType T = Import(FromTSI->getType());
5382  if (T.isNull())
5383  return nullptr;
5384 
5385  return ToContext.getTrivialTypeSourceInfo(T,
5386  Import(FromTSI->getTypeLoc().getLocStart()));
5387 }
5388 
5390  llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD);
5391  if (Pos != ImportedDecls.end()) {
5392  Decl *ToD = Pos->second;
5393  ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD);
5394  return ToD;
5395  } else {
5396  return nullptr;
5397  }
5398 }
5399 
5401  if (!FromD)
5402  return nullptr;
5403 
5404  ASTNodeImporter Importer(*this);
5405 
5406  // Check whether we've already imported this declaration.
5407  llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD);
5408  if (Pos != ImportedDecls.end()) {
5409  Decl *ToD = Pos->second;
5410  Importer.ImportDefinitionIfNeeded(FromD, ToD);
5411  return ToD;
5412  }
5413 
5414  // Import the type
5415  Decl *ToD = Importer.Visit(FromD);
5416  if (!ToD)
5417  return nullptr;
5418 
5419  // Record the imported declaration.
5420  ImportedDecls[FromD] = ToD;
5421 
5422  if (TagDecl *FromTag = dyn_cast<TagDecl>(FromD)) {
5423  // Keep track of anonymous tags that have an associated typedef.
5424  if (FromTag->getTypedefNameForAnonDecl())
5425  AnonTagsWithPendingTypedefs.push_back(FromTag);
5426  } else if (TypedefNameDecl *FromTypedef = dyn_cast<TypedefNameDecl>(FromD)) {
5427  // When we've finished transforming a typedef, see whether it was the
5428  // typedef for an anonymous tag.
5430  FromTag = AnonTagsWithPendingTypedefs.begin(),
5431  FromTagEnd = AnonTagsWithPendingTypedefs.end();
5432  FromTag != FromTagEnd; ++FromTag) {
5433  if ((*FromTag)->getTypedefNameForAnonDecl() == FromTypedef) {
5434  if (TagDecl *ToTag = cast_or_null<TagDecl>(Import(*FromTag))) {
5435  // We found the typedef for an anonymous tag; link them.
5436  ToTag->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(ToD));
5437  AnonTagsWithPendingTypedefs.erase(FromTag);
5438  break;
5439  }
5440  }
5441  }
5442  }
5443 
5444  return ToD;
5445 }
5446 
5448  if (!FromDC)
5449  return FromDC;
5450 
5451  DeclContext *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC)));
5452  if (!ToDC)
5453  return nullptr;
5454 
5455  // When we're using a record/enum/Objective-C class/protocol as a context, we
5456  // need it to have a definition.
5457  if (RecordDecl *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
5458  RecordDecl *FromRecord = cast<RecordDecl>(FromDC);
5459  if (ToRecord->isCompleteDefinition()) {
5460  // Do nothing.
5461  } else if (FromRecord->isCompleteDefinition()) {
5462  ASTNodeImporter(*this).ImportDefinition(FromRecord, ToRecord,
5464  } else {
5465  CompleteDecl(ToRecord);
5466  }
5467  } else if (EnumDecl *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
5468  EnumDecl *FromEnum = cast<EnumDecl>(FromDC);
5469  if (ToEnum->isCompleteDefinition()) {
5470  // Do nothing.
5471  } else if (FromEnum->isCompleteDefinition()) {
5472  ASTNodeImporter(*this).ImportDefinition(FromEnum, ToEnum,
5474  } else {
5475  CompleteDecl(ToEnum);
5476  }
5477  } else if (ObjCInterfaceDecl *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
5478  ObjCInterfaceDecl *FromClass = cast<ObjCInterfaceDecl>(FromDC);
5479  if (ToClass->getDefinition()) {
5480  // Do nothing.
5481  } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
5482  ASTNodeImporter(*this).ImportDefinition(FromDef, ToClass,
5484  } else {
5485  CompleteDecl(ToClass);
5486  }
5487  } else if (ObjCProtocolDecl *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
5488  ObjCProtocolDecl *FromProto = cast<ObjCProtocolDecl>(FromDC);
5489  if (ToProto->getDefinition()) {
5490  // Do nothing.
5491  } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
5492  ASTNodeImporter(*this).ImportDefinition(FromDef, ToProto,
5494  } else {
5495  CompleteDecl(ToProto);
5496  }
5497  }
5498 
5499  return ToDC;
5500 }
5501 
5503  if (!FromE)
5504  return nullptr;
5505 
5506  return cast_or_null<Expr>(Import(cast<Stmt>(FromE)));
5507 }
5508 
5510  if (!FromS)
5511  return nullptr;
5512 
5513  // Check whether we've already imported this declaration.
5514  llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
5515  if (Pos != ImportedStmts.end())
5516  return Pos->second;
5517 
5518  // Import the type
5519  ASTNodeImporter Importer(*this);
5520  Stmt *ToS = Importer.Visit(FromS);
5521  if (!ToS)
5522  return nullptr;
5523 
5524  // Record the imported declaration.
5525  ImportedStmts[FromS] = ToS;
5526  return ToS;
5527 }
5528 
5530  if (!FromNNS)
5531  return nullptr;
5532 
5533  NestedNameSpecifier *prefix = Import(FromNNS->getPrefix());
5534 
5535  switch (FromNNS->getKind()) {
5537  if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) {
5538  return NestedNameSpecifier::Create(ToContext, prefix, II);
5539  }
5540  return nullptr;
5541 
5543  if (NamespaceDecl *NS =
5544  cast<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) {
5545  return NestedNameSpecifier::Create(ToContext, prefix, NS);
5546  }
5547  return nullptr;
5548 
5550  if (NamespaceAliasDecl *NSAD =
5551  cast<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) {
5552  return NestedNameSpecifier::Create(ToContext, prefix, NSAD);
5553  }
5554  return nullptr;
5555 
5557  return NestedNameSpecifier::GlobalSpecifier(ToContext);
5558 
5560  if (CXXRecordDecl *RD =
5561  cast<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) {
5562  return NestedNameSpecifier::SuperSpecifier(ToContext, RD);
5563  }
5564  return nullptr;
5565 
5568  QualType T = Import(QualType(FromNNS->getAsType(), 0u));
5569  if (!T.isNull()) {
5570  bool bTemplate = FromNNS->getKind() ==
5572  return NestedNameSpecifier::Create(ToContext, prefix,
5573  bTemplate, T.getTypePtr());
5574  }
5575  }
5576  return nullptr;
5577  }
5578 
5579  llvm_unreachable("Invalid nested name specifier kind");
5580 }
5581 
5583  // FIXME: Implement!
5584  return NestedNameSpecifierLoc();
5585 }
5586 
5588  switch (From.getKind()) {
5590  if (TemplateDecl *ToTemplate
5591  = cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl())))
5592  return TemplateName(ToTemplate);
5593 
5594  return TemplateName();
5595 
5597  OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate();
5598  UnresolvedSet<2> ToTemplates;
5599  for (OverloadedTemplateStorage::iterator I = FromStorage->begin(),
5600  E = FromStorage->end();
5601  I != E; ++I) {
5602  if (NamedDecl *To = cast_or_null<NamedDecl>(Import(*I)))
5603  ToTemplates.addDecl(To);
5604  else
5605  return TemplateName();
5606  }
5607  return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
5608  ToTemplates.end());
5609  }
5610 
5613  NestedNameSpecifier *Qualifier = Import(QTN->getQualifier());
5614  if (!Qualifier)
5615  return TemplateName();
5616 
5617  if (TemplateDecl *ToTemplate
5618  = cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl())))
5619  return ToContext.getQualifiedTemplateName(Qualifier,
5620  QTN->hasTemplateKeyword(),
5621  ToTemplate);
5622 
5623  return TemplateName();
5624  }
5625 
5628  NestedNameSpecifier *Qualifier = Import(DTN->getQualifier());
5629  if (!Qualifier)
5630  return TemplateName();
5631 
5632  if (DTN->isIdentifier()) {
5633  return ToContext.getDependentTemplateName(Qualifier,
5634  Import(DTN->getIdentifier()));
5635  }
5636 
5637  return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator());
5638  }
5639 
5644  = cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter()));
5645  if (!param)
5646  return TemplateName();
5647 
5648  TemplateName replacement = Import(subst->getReplacement());
5649  if (replacement.isNull()) return TemplateName();
5650 
5651  return ToContext.getSubstTemplateTemplateParm(param, replacement);
5652  }
5653 
5658  = cast_or_null<TemplateTemplateParmDecl>(
5659  Import(SubstPack->getParameterPack()));
5660  if (!Param)
5661  return TemplateName();
5662 
5663  ASTNodeImporter Importer(*this);
5664  TemplateArgument ArgPack
5665  = Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
5666  if (ArgPack.isNull())
5667  return TemplateName();
5668 
5669  return ToContext.getSubstTemplateTemplateParmPack(Param, ArgPack);
5670  }
5671  }
5672 
5673  llvm_unreachable("Invalid template name kind");
5674 }
5675 
5677  if (FromLoc.isInvalid())
5678  return SourceLocation();
5679 
5680  SourceManager &FromSM = FromContext.getSourceManager();
5681 
5682  // For now, map everything down to its spelling location, so that we
5683  // don't have to import macro expansions.
5684  // FIXME: Import macro expansions!
5685  FromLoc = FromSM.getSpellingLoc(FromLoc);
5686  std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc);
5687  SourceManager &ToSM = ToContext.getSourceManager();
5688  FileID ToFileID = Import(Decomposed.first);
5689  if (ToFileID.isInvalid())
5690  return SourceLocation();
5691  SourceLocation ret = ToSM.getLocForStartOfFile(ToFileID)
5692  .getLocWithOffset(Decomposed.second);
5693  return ret;
5694 }
5695 
5697  return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd()));
5698 }
5699 
5701  llvm::DenseMap<FileID, FileID>::iterator Pos
5702  = ImportedFileIDs.find(FromID);
5703  if (Pos != ImportedFileIDs.end())
5704  return Pos->second;
5705 
5706  SourceManager &FromSM = FromContext.getSourceManager();
5707  SourceManager &ToSM = ToContext.getSourceManager();
5708  const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
5709  assert(FromSLoc.isFile() && "Cannot handle macro expansions yet");
5710 
5711  // Include location of this file.
5712  SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
5713 
5714  // Map the FileID for to the "to" source manager.
5715  FileID ToID;
5716  const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache();
5717  if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
5718  // FIXME: We probably want to use getVirtualFile(), so we don't hit the
5719  // disk again
5720  // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
5721  // than mmap the files several times.
5722  const FileEntry *Entry = ToFileManager.getFile(Cache->OrigEntry->getName());
5723  if (!Entry)
5724  return FileID();
5725  ToID = ToSM.createFileID(Entry, ToIncludeLoc,
5726  FromSLoc.getFile().getFileCharacteristic());
5727  } else {
5728  // FIXME: We want to re-use the existing MemoryBuffer!
5729  const llvm::MemoryBuffer *
5730  FromBuf = Cache->getBuffer(FromContext.getDiagnostics(), FromSM);
5731  std::unique_ptr<llvm::MemoryBuffer> ToBuf
5732  = llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
5733  FromBuf->getBufferIdentifier());
5734  ToID = ToSM.createFileID(std::move(ToBuf),
5735  FromSLoc.getFile().getFileCharacteristic());
5736  }
5737 
5738 
5739  ImportedFileIDs[FromID] = ToID;
5740  return ToID;
5741 }
5742 
5744  Decl *To = Import(From);
5745  if (!To)
5746  return;
5747 
5748  if (DeclContext *FromDC = cast<DeclContext>(From)) {
5749  ASTNodeImporter Importer(*this);
5750 
5751  if (RecordDecl *ToRecord = dyn_cast<RecordDecl>(To)) {
5752  if (!ToRecord->getDefinition()) {
5753  Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord,
5755  return;
5756  }
5757  }
5758 
5759  if (EnumDecl *ToEnum = dyn_cast<EnumDecl>(To)) {
5760  if (!ToEnum->getDefinition()) {
5761  Importer.ImportDefinition(cast<EnumDecl>(FromDC), ToEnum,
5763  return;
5764  }
5765  }
5766 
5767  if (ObjCInterfaceDecl *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
5768  if (!ToIFace->getDefinition()) {
5769  Importer.ImportDefinition(cast<ObjCInterfaceDecl>(FromDC), ToIFace,
5771  return;
5772  }
5773  }
5774 
5775  if (ObjCProtocolDecl *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
5776  if (!ToProto->getDefinition()) {
5777  Importer.ImportDefinition(cast<ObjCProtocolDecl>(FromDC), ToProto,
5779  return;
5780  }
5781  }
5782 
5783  Importer.ImportDeclContext(FromDC, true);
5784  }
5785 }
5786 
5788  if (!FromName)
5789  return DeclarationName();
5790 
5791  switch (FromName.getNameKind()) {
5793  return Import(FromName.getAsIdentifierInfo());
5794 
5798  return Import(FromName.getObjCSelector());
5799 
5801  QualType T = Import(FromName.getCXXNameType());
5802  if (T.isNull())
5803  return DeclarationName();
5804 
5805  return ToContext.DeclarationNames.getCXXConstructorName(
5806  ToContext.getCanonicalType(T));
5807  }
5808 
5810  QualType T = Import(FromName.getCXXNameType());
5811  if (T.isNull())
5812  return DeclarationName();
5813 
5814  return ToContext.DeclarationNames.getCXXDestructorName(
5815  ToContext.getCanonicalType(T));
5816  }
5817 
5819  QualType T = Import(FromName.getCXXNameType());
5820  if (T.isNull())
5821  return DeclarationName();
5822 
5824  ToContext.getCanonicalType(T));
5825  }
5826 
5828  return ToContext.DeclarationNames.getCXXOperatorName(
5829  FromName.getCXXOverloadedOperator());
5830 
5833  Import(FromName.getCXXLiteralIdentifier()));
5834 
5836  // FIXME: STATICS!
5838  }
5839 
5840  llvm_unreachable("Invalid DeclarationName Kind!");
5841 }
5842 
5844  if (!FromId)
5845  return nullptr;
5846 
5847  return &ToContext.Idents.get(FromId->getName());
5848 }
5849 
5851  if (FromSel.isNull())
5852  return Selector();
5853 
5855  Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
5856  for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
5857  Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
5858  return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
5859 }
5860 
5862  DeclContext *DC,
5863  unsigned IDNS,
5864  NamedDecl **Decls,
5865  unsigned NumDecls) {
5866  return Name;
5867 }
5868 
5870  if (LastDiagFromFrom)
5872  FromContext.getDiagnostics());
5873  LastDiagFromFrom = false;
5874  return ToContext.getDiagnostics().Report(Loc, DiagID);
5875 }
5876 
5878  if (!LastDiagFromFrom)
5880  ToContext.getDiagnostics());
5881  LastDiagFromFrom = true;
5882  return FromContext.getDiagnostics().Report(Loc, DiagID);
5883 }
5884 
5886  if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
5887  if (!ID->getDefinition())
5888  ID->startDefinition();
5889  }
5890  else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) {
5891  if (!PD->getDefinition())
5892  PD->startDefinition();
5893  }
5894  else if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
5895  if (!TD->getDefinition() && !TD->isBeingDefined()) {
5896  TD->startDefinition();
5897  TD->setCompleteDefinition(true);
5898  }
5899  }
5900  else {
5901  assert (0 && "CompleteDecl called on a Decl that can't be completed");
5902  }
5903 }
5904 
5906  ImportedDecls[From] = To;
5907  return To;
5908 }
5909 
5911  bool Complain) {
5912  llvm::DenseMap<const Type *, const Type *>::iterator Pos
5913  = ImportedTypes.find(From.getTypePtr());
5914  if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To))
5915  return true;
5916 
5917  StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls,
5918  false, Complain);
5919  return Ctx.IsStructurallyEquivalent(From, To);
5920 }
Expr * getInc()
Definition: Stmt.h:1178
Kind getKind() const
Definition: Type.h:2006
unsigned getNumElements() const
Definition: Type.h:2724
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl)
Definition: DeclCXX.cpp:2013
param_const_iterator param_begin() const
Definition: DeclObjC.h:359
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition: Expr.h:2411
SourceRange getParenOrBraceRange() const
Definition: ExprCXX.h:1218
void setMethodParams(ASTContext &C, ArrayRef< ParmVarDecl * > Params, ArrayRef< SourceLocation > SelLocs=llvm::None)
Sets the method's parameters and selector source locations. If the method is implicit (not coming fro...
Definition: DeclObjC.cpp:763
QualType getElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType) const
Defines the clang::ASTContext interface.
QualType getExceptionType(unsigned i) const
Definition: Type.h:3194
Represents a type that was referred to using an elaborated type keyword, e.g., struct S...
Definition: Type.h:4219
SourceLocation getEnd() const
const SwitchCase * getNextSwitchCase() const
Definition: Stmt.h:667
void setOwningFunction(DeclContext *FD)
Definition: Decl.h:1486
Expr * getSizeExpr() const
Definition: Type.h:2674
QualType getUnderlyingType() const
Definition: Type.h:3431
TemplateParameterList * ImportTemplateParameterList(TemplateParameterList *Params)
Stmt * VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S)
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:5035
ObjCInterfaceDecl * getDecl() const
getDecl - Get the declaration of this interface.
Definition: Type.h:4736
CastKind getCastKind() const
Definition: Expr.h:2709
ExprObjectKind getObjectKind() const
Definition: Expr.h:411
static unsigned getFieldIndex(Decl *F)
void setImplicit(bool I=true)
Definition: DeclBase.h:504
Decl * VisitCXXMethodDecl(CXXMethodDecl *D)
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
Definition: Expr.h:1034
bool isVariadic() const
Definition: Type.h:3228
QualType VisitVectorType(const VectorType *T)
Decl * VisitEnumDecl(EnumDecl *D)
body_iterator body_end()
Definition: Stmt.h:587
unsigned getDepth() const
Definition: Type.h:3735
bool isMinimalImport() const
Whether the importer will perform a minimal import, creating to-be-completed forward declarations whe...
Definition: ASTImporter.h:101
Stmt * VisitDoStmt(DoStmt *S)
const DeclGroupRef getDeclGroup() const
Definition: Stmt.h:470
Smart pointer class that efficiently represents Objective-C method names.
This is a discriminated union of FileInfo and ExpansionInfo.
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
Definition: TemplateName.h:254
void setAnonymousStructOrUnion(bool Anon)
Definition: Decl.h:3295
const ObjCAtFinallyStmt * getFinallyStmt() const
Retrieve the @finally statement, if any.
Definition: StmtObjC.h:224
ImplementationControl getImplementationControl() const
Definition: DeclObjC.h:468
QualType VisitDecltypeType(const DecltypeType *T)
base_class_range bases()
Definition: DeclCXX.h:713
SourceRange getBracketsRange() const
Definition: Type.h:2573
bool isNull() const
Definition: DeclGroup.h:83
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
Definition: TemplateBase.h:284
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition: Expr.h:2216
Stmt * VisitCaseStmt(CaseStmt *S)
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.h:1982
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:115
void startDefinition()
Starts the definition of this Objective-C class, taking it from a forward declaration (@class) to a d...
Definition: DeclObjC.cpp:528
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:2330
bool hasLeadingEmptyMacro() const
Definition: Stmt.h:538
SourceLocation getLParenLoc() const
Definition: Stmt.h:1193
ObjCTypeParamList * ImportObjCTypeParamList(ObjCTypeParamList *list)
QualType getType() const
Retrieves the type of the base class.
Definition: DeclCXX.h:252
bool isElidable() const
Whether this construction is elidable.
Definition: ExprCXX.h:1144
Expr * getCond()
Definition: Stmt.h:1066
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition: Expr.h:2541
Defines the clang::FileManager interface and associated types.
protocol_iterator protocol_end() const
Definition: DeclObjC.h:1797
QualType getComplexType(QualType T) const
Return the uniqued reference to the type for a complex number with the specified element type...
Stmt * VisitObjCAtCatchStmt(ObjCAtCatchStmt *S)
IdentifierInfo * getIdentifier() const
Definition: Decl.h:163
DeclarationName getCXXConstructorName(CanQualType Ty)
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition: Expr.h:2466
QualType getBaseType() const
Definition: Type.h:3485
Decl * VisitDecl(Decl *D)
bool isKindOfTypeAsWritten() const
Whether this is a "__kindof" type as written.
Definition: Type.h:4645
PropertyControl getPropertyImplementation() const
Definition: DeclObjC.h:2591
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:1581
static CXXConstructExpr * Create(const ASTContext &C, QualType T, SourceLocation Loc, CXXConstructorDecl *D, bool Elidable, ArrayRef< Expr * > Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization, ConstructionKind ConstructKind, SourceRange ParenOrBraceRange)
Definition: ExprCXX.cpp:830
Stmt * VisitContinueStmt(ContinueStmt *S)
CharacterKind getKind() const
Definition: Expr.h:1342
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID. ...
SourceLocation getCXXLiteralOperatorNameLoc() const
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition: Decl.h:3177
decl_range decls() const
Definition: DeclBase.h:1413
bool isDefined() const
Definition: DeclObjC.h:429
bool isParameterPack() const
Returns whether this is a parameter pack.
CXXCatchStmt * getHandler(unsigned i)
Definition: StmtCXX.h:104
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
bool IsICE
Whether this statement is an integral constant expression, or in C++11, whether the statement is a co...
Definition: Decl.h:700
const Expr * getInitExpr() const
Definition: Decl.h:2467
bool isArgumentType() const
Definition: Expr.h:2013
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
Definition: DeclObjC.h:1195
ClassTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type...
unsigned getNumArgs() const
Retrieve the number of template arguments.
Definition: Type.h:4378
Expr * VisitImplicitCastExpr(ImplicitCastExpr *E)
IdentifierInfo * getCXXLiteralIdentifier() const
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
Definition: TemplateName.h:512
Expr * VisitCXXConstructExpr(CXXConstructExpr *E)
Defines the SourceManager interface.
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in...
Expr * VisitBinaryOperator(BinaryOperator *E)
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:4285
QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType, UnaryTransformType::UTTKind UKind) const
Unary type transforms.
SourceLocation getForLoc() const
Definition: StmtObjC.h:53
static TemplateTemplateParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation L, unsigned D, unsigned P, bool ParameterPack, IdentifierInfo *Id, TemplateParameterList *Params)
DeclarationName getCXXConversionFunctionName(CanQualType Ty)
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
QualType getUnderlyingType() const
Definition: Decl.h:2616
iterator end()
Definition: DeclGroup.h:109
AccessSpecifier getAccess() const
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, NamedDecl **Params, unsigned NumParams, SourceLocation RAngleLoc)
DeclGroupRef ImportDeclGroup(DeclGroupRef DG)
chain_range chain() const
Definition: Decl.h:2510
arg_iterator arg_begin()
Definition: ExprCXX.h:1189
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition: Decl.cpp:1987
Represents a C++11 auto or C++1y decltype(auto) type.
Definition: Type.h:3874
void setPure(bool P=true)
Definition: Decl.cpp:2421
Represents an attribute applied to a statement.
Definition: Stmt.h:833
static ObjCProtocolDecl * Create(ASTContext &C, DeclContext *DC, IdentifierInfo *Id, SourceLocation nameLoc, SourceLocation atStartLoc, ObjCProtocolDecl *PrevDecl)
Definition: DeclObjC.cpp:1697
static ObjCPropertyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, SourceLocation AtLocation, SourceLocation LParenLocation, QualType T, TypeSourceInfo *TSI, PropertyControl propControl=None)
Definition: DeclObjC.cpp:2051
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
Definition: TemplateBase.h:317
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type...
QualType getPointeeType() const
Definition: Type.h:2364
IdentifierInfo * getAsIdentifierInfo() const
static ClassTemplateSpecializationDecl * Create(ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, const TemplateArgument *Args, unsigned NumArgs, ClassTemplateSpecializationDecl *PrevDecl)
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
enumerator_iterator enumerator_end() const
Definition: Decl.h:3098
Represents Objective-C's @throw statement.
Definition: StmtObjC.h:313
QualType VisitTemplateSpecializationType(const TemplateSpecializationType *T)
QualType getRecordType(const RecordDecl *Decl) const
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1118
Declaration of a variable template.
SourceLocation getIfLoc() const
Definition: Stmt.h:925
TemplateTemplateParmDecl * getParameterPack() const
Retrieve the template template parameter pack being substituted.
Definition: TemplateName.h:132
NamespaceDecl - Represent a C++ namespace.
Definition: Decl.h:400
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:1068
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1075
RetTy Visit(const Type *T)
Performs the operation associated with this visitor object.
Definition: TypeVisitor.h:69
void setSpecializationKind(TemplateSpecializationKind TSK)
virtual void completeDefinition()
Definition: Decl.cpp:3638
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:96
bool isDecltypeAuto() const
Definition: Type.h:3890
Decl * VisitFieldDecl(FieldDecl *D)
A container of type source information.
Definition: Decl.h:60
void setSwitchCaseList(SwitchCase *SC)
Set the case list for this switch statement.
Definition: Stmt.h:996
const Stmt * getElse() const
Definition: Stmt.h:918
unsigned getIndex() const
Definition: Type.h:3736
Decl * VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D)
SourceLocation getOperatorLoc() const
Definition: Expr.h:2958
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:307
void setTemplateArgsInfo(const TemplateArgumentListInfo &ArgsInfo)
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:1785
enumerator_iterator enumerator_begin() const
Definition: Decl.h:3091
const TemplateArgument & get(unsigned Idx) const
Retrieve the template argument at a given index.
Definition: DeclTemplate.h:197
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
Definition: Stmt.cpp:925
SourceLocation getLocEnd() const LLVM_READONLY
Definition: DeclBase.h:368
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:1429
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2147
bool isSpelledAsLValue() const
Definition: Type.h:2282
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:202
Expr * getInClassInitializer() const
Definition: Decl.h:2385
InClassInitStyle getInClassInitStyle() const
Definition: Decl.h:2369
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition: Expr.h:2490
const llvm::APInt & getSize() const
Definition: Type.h:2472
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:1809
ObjCTypeParamVariance getVariance() const
Determine the variance of this type parameter.
Definition: DeclObjC.h:577
SourceLocation getIncludeLoc() const
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: Expr.h:1071
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
An identifier, stored as an IdentifierInfo*.
Stmt * getSubStmt()
Definition: Stmt.h:763
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
QualType VisitPointerType(const PointerType *T)
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
virtual Decl * GetOriginalDecl(Decl *To)
Called by StructuralEquivalenceContext. If a RecordDecl is being compared to another RecordDecl as pa...
Definition: ASTImporter.h:286
void setImplementation(ObjCCategoryImplDecl *ImplD)
Definition: DeclObjC.cpp:1869
SourceLocation getReturnLoc() const
Definition: Stmt.h:1370
static CXXConversionDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool isInline, bool isExplicit, bool isConstexpr, SourceLocation EndLocation)
Definition: DeclCXX.cpp:1935
bool isFileVarDecl() const
isFileVarDecl - Returns true for file scoped variable declaration.
Definition: Decl.h:1040
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
unsigned getIndex() const
Retrieve the index into its type parameter list.
Definition: DeclObjC.h:590
void setCXXLiteralOperatorNameLoc(SourceLocation Loc)
const Expr * getCallee() const
Definition: Expr.h:2188
Stmt * VisitLabelStmt(LabelStmt *S)
SourceLocation getIvarRBraceLoc() const
Definition: DeclObjC.h:2067
Expr * VisitIntegerLiteral(IntegerLiteral *E)
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:45
ExtProtoInfo - Extra information about a function prototype.
Definition: Type.h:3042
AccessSpecifier getAccess() const
Definition: DeclBase.h:416
TypeSourceInfo * getSuperClassTInfo() const
Definition: DeclObjC.h:1243
field_iterator field_begin() const
Definition: Decl.cpp:3629
unsigned size() const
Definition: Stmt.h:580
Represents a variable template specialization, which refers to a variable template with a given set o...
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition: Expr.h:1304
Decl * VisitVarDecl(VarDecl *D)
A namespace, stored as a NamespaceDecl*.
DiagnosticBuilder ToDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "to" context.
SourceLocation getDoLoc() const
Definition: Stmt.h:1118
UnaryExprOrTypeTrait getKind() const
Definition: Expr.h:2008
Expr * VisitUnaryOperator(UnaryOperator *E)
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:46
void getSelectorLocs(SmallVectorImpl< SourceLocation > &SelLocs) const
Definition: DeclObjC.cpp:757
static bool ImportCastPath(CastExpr *E, CXXCastPath &Path)
QualType Import(QualType FromT)
Import the given type from the "from" context into the "to" context.
Qualifiers getIndexTypeQualifiers() const
Definition: Type.h:2438
unsigned param_size() const
Definition: DeclObjC.h:348
unsigned getValue() const
Definition: Expr.h:1349
TemplateTemplateParmDecl * getParameter() const
Definition: TemplateName.h:352
ParmVarDecl - Represents a parameter to a function.
Definition: Decl.h:1334
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:3773
bool ImportTemplateArguments(const TemplateArgument *FromArgs, unsigned NumFromArgs, SmallVectorImpl< TemplateArgument > &ToArgs)
unsigned getNumArgs() const
Retrieve the number of template arguments.
Definition: Type.h:4038
SourceLocation getDefaultLoc() const
Definition: Stmt.h:767
SourceLocation getLocation() const
Definition: Expr.h:1002
QualType getUnderlyingType() const
Definition: Type.h:3484
SourceLocation getEllipsisLoc() const
Definition: Stmt.h:712
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition: Decl.h:647
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
IdentifierInfo * getIdentifier() const
Definition: DeclObjC.h:2179
QualType getType() const
Definition: DeclObjC.h:2505
TypeSourceInfo * getTypeSourceInfo() const
Definition: DeclObjC.h:2503
EvaluatedStmt * ensureEvaluatedStmt() const
Definition: Decl.cpp:2086
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:502
bool hasExternalFormalLinkage() const
True if this decl has external linkage.
Definition: Decl.h:275
unsigned getNumParams() const
Definition: Type.h:3133
Kind getPropertyImplementation() const
Definition: DeclObjC.h:2683
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:1035
ObjCTypeParamList * getTypeParamListAsWritten() const
Definition: DeclObjC.h:984
Decl * VisitObjCCategoryDecl(ObjCCategoryDecl *D)
QualType VisitBlockPointerType(const BlockPointerType *T)
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.
const IdentifierInfo * getIdentifier() const
Retrieve the type named by the typename specifier as an identifier.
Definition: Type.h:4313
QualType getElementType() const
Definition: Type.h:2675
DeclarationName getName() const
getName - Returns the embedded declaration name.
FunctionType::ExtInfo ExtInfo
Definition: Type.h:3057
Represents a class template specialization, which refers to a class template with a given set of temp...
Stmt * getBody()
Definition: Stmt.h:1114
void setIntegerType(QualType T)
Set the underlying integer type.
Definition: Decl.h:3124
unsigned getIndexTypeCVRQualifiers() const
Definition: Type.h:2441
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3171
Decl * VisitTypedefDecl(TypedefDecl *D)
DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "from" context.
Decl * VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D)
Expr * VisitCompoundAssignOperator(CompoundAssignOperator *E)
static RecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl *PrevDecl=nullptr)
Definition: Decl.cpp:3591
QualType getAutoType(QualType DeducedType, bool IsDecltypeAuto, bool IsDependent) const
C++11 deduced auto type.
Expr * getSizeExpr() const
Definition: Type.h:2568
IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:89
A C++ nested-name-specifier augmented with source location information.
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:440
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition: DeclBase.h:1716
bool CheckedICE
Whether we already checked whether this statement was an integral constant expression.
Definition: Decl.h:691
bool isIdentifier() const
Determine whether this template name refers to an identifier.
Definition: TemplateName.h:499
Decl * VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D)
QualType VisitMemberPointerType(const MemberPointerType *T)
SourceLocation getLocStart() const LLVM_READONLY
Definition: DeclCXX.h:202
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:2016
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size...
bool isCompleteDefinition() const
Definition: Decl.h:2838
void setTypeParamList(ObjCTypeParamList *TPL)
Definition: DeclObjC.cpp:262
QualType VisitParenType(const ParenType *T)
An operation on a type.
Definition: TypeVisitor.h:65
NameKind getKind() const
bool isPure() const
Definition: Decl.h:1789
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition: Expr.h:1650
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:3419
void setSuperClass(TypeSourceInfo *superClass)
Definition: DeclObjC.h:1258
SourceLocation getCaseLoc() const
Definition: Stmt.h:710
CXXRecordDecl * getDefinition() const
Definition: DeclCXX.h:675
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Definition: DeclTemplate.h:212
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:4305
TagKind getTagKind() const
Definition: Decl.h:2897
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:1871
Represents the result of substituting a set of types for a template type parameter pack...
Definition: Type.h:3828
param_range params()
Definition: DeclObjC.h:354
DeclarationName getCXXDestructorName(CanQualType Ty)
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:367
QualType getTypeOfType(QualType t) const
unsigned size() const
Definition: DeclTemplate.h:87
Expr * VisitExpr(Expr *E)
Decl * VisitObjCImplementationDecl(ObjCImplementationDecl *D)
SourceLocation getLBracLoc() const
Definition: Stmt.h:633
Expr * getSubExpr()
Definition: Expr.h:2713
void startDefinition()
Starts the definition of this Objective-C protocol.
Definition: DeclObjC.cpp:1757
bool isNull() const
Determine whether this is the empty selector.
qual_range quals() const
Definition: Type.h:4623
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1114
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
Definition: TemplateName.h:268
QualType VisitObjCInterfaceType(const ObjCInterfaceType *T)
SourceLocation getRParenLoc() const
Definition: Expr.h:2283
TypeSourceInfo * getNamedTypeInfo() const
IdentifierTable & Idents
Definition: ASTContext.h:439
QualType getUnderlyingType() const
Definition: Type.h:3410
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition: DeclCXX.h:2514
QualType VisitComplexType(const ComplexType *T)
SourceLocation getCategoryNameLoc() const
Definition: DeclObjC.h:2061
bool isFPContractable() const
Definition: Expr.h:3082
StorageClass getStorageClass() const
Returns the storage class as written in the source. For the computed linkage of symbol, see getLinkage.
Definition: Decl.h:871
Expr * getUnderlyingExpr() const
Definition: Type.h:3430
Expr * getLHS() const
Definition: Expr.h:2964
const VarDecl * getCatchParamDecl() const
Definition: StmtObjC.h:94
SourceLocation getColonLoc() const
Definition: DeclObjC.h:598
SourceLocation getWhileLoc() const
Definition: Stmt.h:1073
Represents Objective-C's @catch statement.
Definition: StmtObjC.h:74
const CompoundStmt * getSynchBody() const
Definition: StmtObjC.h:282
void setBody(Stmt *S)
Definition: Stmt.h:992
const VarDecl * getNRVOCandidate() const
Retrieve the variable that might be used for the named return value optimization. ...
Definition: Stmt.h:1378
bool isNull() const
Determine whether this template name is NULL.
Definition: TemplateName.h:220
QualType VisitVariableArrayType(const VariableArrayType *T)
Stmt * VisitBreakStmt(BreakStmt *S)
Decl * VisitCXXConstructorDecl(CXXConstructorDecl *D)
TemplateArgument getArgumentPack() const
Definition: Type.cpp:2932
param_type_range param_types() const
Definition: Type.h:3251
SourceLocation getLAngleLoc() const
Definition: DeclTemplate.h:127
QualType getParenType(QualType NamedType) const
const Stmt * getFinallyBody() const
Definition: StmtObjC.h:132
A qualified template name, where the qualification is kept to describe the source code as written...
Definition: TemplateName.h:196
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition: Decl.h:2956
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
static ObjCInterfaceDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, ObjCTypeParamList *typeParamList, ObjCInterfaceDecl *PrevDecl, SourceLocation ClassLoc=SourceLocation(), bool isInternal=false)
Definition: DeclObjC.cpp:1296
QualType VisitElaboratedType(const ElaboratedType *T)
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
const LangOptions & getLangOpts() const
Definition: ASTContext.h:533
Stmt * VisitAttributedStmt(AttributedStmt *S)
bool isImplicit() const
Definition: DeclBase.h:503
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition: Decl.h:455
ObjCTypeParamList * getTypeParamList() const
Definition: DeclObjC.h:1987
void setCXXOperatorNameRange(SourceRange R)
SourceLocation getIvarLBraceLoc() const
Definition: DeclObjC.h:2065
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
Definition: DeclObjC.cpp:291
static ObjCCategoryDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation AtLoc, SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc, IdentifierInfo *Id, ObjCInterfaceDecl *IDecl, ObjCTypeParamList *typeParamList, SourceLocation IvarLBraceLoc=SourceLocation(), SourceLocation IvarRBraceLoc=SourceLocation())
Definition: DeclObjC.cpp:1831
QualType getBaseType() const
Definition: Type.h:4569
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
Definition: Type.h:4030
SourceLocation getAtFinallyLoc() const
Definition: StmtObjC.h:141
static ObjCPropertyImplDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation atLoc, SourceLocation L, ObjCPropertyDecl *property, Kind PK, ObjCIvarDecl *ivarDecl, SourceLocation ivarLoc)
Definition: DeclObjC.cpp:2079
protocol_iterator protocol_end() const
Definition: DeclObjC.h:2019
QualType getReturnType() const
Definition: Type.h:2952
static EnumConstantDecl * Create(ASTContext &C, EnumDecl *DC, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E, const llvm::APSInt &V)
Definition: Decl.cpp:3904
SourceLocation getRParenLoc() const
Definition: Stmt.h:1123
OverloadedTemplateStorage * getAsOverloadedTemplate() const
Retrieve the underlying, overloaded function template.
Definition: TemplateName.h:241
Stmt * getHandlerBlock() const
Definition: StmtCXX.h:52
Stmt * getBody()
Definition: Stmt.h:1179
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition: Expr.h:1646
TemplateArgument getArgumentPack() const
Retrieve the template template argument pack with which this parameter was substituted.
TemplateName getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param, TemplateName replacement) const
const ArrayType * getAsArrayType(QualType T) const
Decl * VisitObjCPropertyDecl(ObjCPropertyDecl *D)
TypeOfExprType (GCC extension).
Definition: Type.h:3357
Expr * VisitCharacterLiteral(CharacterLiteral *E)
static TemplateTypeParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation KeyLoc, SourceLocation NameLoc, unsigned D, unsigned P, IdentifierInfo *Id, bool Typename, bool ParameterPack)
Expr * getNoexceptExpr() const
Definition: Type.h:3198
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:2918
static ObjCTypeParamList * create(ASTContext &ctx, SourceLocation lAngleLoc, ArrayRef< ObjCTypeParamDecl * > typeParams, SourceLocation rAngleLoc)
Create a new Objective-C type parameter list.
Definition: DeclObjC.cpp:1270
Stmt * getInit()
Definition: Stmt.h:1158
RecordDecl * getDecl() const
Definition: Type.h:3527
static CXXTryStmt * Create(const ASTContext &C, SourceLocation tryLoc, Stmt *tryBlock, ArrayRef< Stmt * > handlers)
Definition: Stmt.cpp:824
iterator begin()
Definition: DeclGroup.h:103
Decl * VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D)
Selector getSetterName() const
Definition: DeclObjC.h:2578
Stmt * VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S)
SourceLocation getThrowLoc()
Definition: StmtObjC.h:329
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Definition: DeclObjC.h:1866
void setSpecializationKind(TemplateSpecializationKind TSK)
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1006
const Stmt * getCatchBody() const
Definition: StmtObjC.h:90
Expr * getCond()
Definition: Stmt.h:1177
void setTrivial(bool IT)
Definition: Decl.h:1801
Decl * VisitObjCProtocolDecl(ObjCProtocolDecl *D)
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:4246
TypeClass getTypeClass() const
Definition: Type.h:1486
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:1731
const ObjCAtCatchStmt * getCatchStmt(unsigned I) const
Retrieve a @catch statement.
Definition: StmtObjC.h:206
bool IsStructurallyEquivalent(QualType From, QualType To, bool Complain=true)
Determine whether the given types are structurally equivalent.
DeclContext * getLexicalDeclContext()
Definition: DeclBase.h:697
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:496
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
Definition: Decl.cpp:1785
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition: Expr.cpp:726
Stmt * VisitNullStmt(NullStmt *S)
TypeSourceInfo * getTypeInfoAsWritten() const
Definition: Expr.h:2844
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
Definition: DeclObjC.h:1830
Stmt * VisitCXXCatchStmt(CXXCatchStmt *S)
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
Represents an ObjC class declaration.
Definition: DeclObjC.h:851
SourceLocation getLocEnd() const LLVM_READONLY
Definition: DeclObjC.cpp:850
Represents a linkage specification.
Definition: DeclCXX.h:2467
Expr * VisitCStyleCastExpr(CStyleCastExpr *E)
Stmt * VisitCXXTryStmt(CXXTryStmt *S)
PropertyAttributeKind getPropertyAttributes() const
Definition: DeclObjC.h:2516
bool ImportDefinition(RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind=IDK_Default)
ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, ASTContext &FromContext, FileManager &FromFileManager, bool MinimalImport)
Create a new AST importer.
known_categories_range known_categories() const
Definition: DeclObjC.h:1358
CanQualType UnsignedCharTy
Definition: ASTContext.h:826
QualType getType() const
Definition: Decl.h:538
bool isInvalid() const
static FunctionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation NLoc, DeclarationName N, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool isInlineSpecified=false, bool hasWrittenPrototype=true, bool isConstexprSpecified=false)
Definition: Decl.h:1683
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:733
SourceLocation getIvarLBraceLoc() const
Definition: DeclObjC.h:2361
Import the default subset of the definition, which might be nothing (if minimal import is set) or mig...
Definition: ASTImporter.cpp:95
SourceLocation getSwitchLoc() const
Definition: Stmt.h:998
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
Definition: DeclBase.cpp:1236
SourceLocation getAtStartLoc() const
Definition: DeclObjC.h:796
Stmt * VisitDeclStmt(DeclStmt *S)
ObjCProtocolDecl * getProtocol(unsigned I) const
Fetch a protocol by index.
Definition: Type.h:4634
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
Definition: Type.h:3849
bool hadMultipleCandidates() const
Whether the referred constructor was resolved from an overloaded set having size greater than 1...
Definition: ExprCXX.h:1149
DiagnosticsEngine & getDiagnostics() const
field_iterator field_end() const
Definition: Decl.h:3352
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
SourceLocation getAtLoc() const
Definition: DeclObjC.h:2497
EnumDecl * getDecl() const
Definition: Type.h:3550
QualType getTemplateSpecializationType(TemplateName T, const TemplateArgument *Args, unsigned NumArgs, QualType Canon=QualType()) const
AnnotatingParser & P
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
Definition: TemplateName.h:284
SourceLocation getOperatorLoc() const LLVM_READONLY
Definition: Expr.h:2546
bool isUnion() const
Definition: Decl.h:2906
Decl * VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias)
Optional< unsigned > getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce...
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)
Definition: Decl.cpp:3530
QualType getInjectedSpecializationType() const
Definition: Type.h:4112
Decl * VisitCXXDestructorDecl(CXXDestructorDecl *D)
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
Definition: DeclObjC.h:1877
SourceLocation getLocStart() const LLVM_READONLY
Definition: DeclObjC.h:2675
QualType VisitObjCObjectType(const ObjCObjectType *T)
ExtInfo getExtInfo() const
Definition: Type.h:2961
SourceLocation getTryLoc() const
Definition: StmtCXX.h:91
QualType getObjCObjectType(QualType Base, ObjCProtocolDecl *const *Protocols, unsigned NumProtocols) const
Legacy interface: cannot provide type arguments or __kindof.
llvm::APInt getValue() const
Definition: Expr.h:1262
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:866
QualType getParamType(unsigned i) const
Definition: Type.h:3134
Decl * VisitRecordDecl(RecordDecl *D)
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition: Type.h:3166
SourceLocation getLocStart() const LLVM_READONLY
Definition: Decl.h:2560
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
Decl * VisitCXXConversionDecl(CXXConversionDecl *D)
Objective C @protocol.
Definition: DeclBase.h:131
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat)
Definition: Expr.cpp:1737
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:442
A dependent template name that has not been resolved to a template (or set of templates).
Definition: TemplateName.h:199
unsigned getChainingSize() const
Definition: Decl.h:2516
decl_range noload_decls() const
Definition: DeclBase.h:1421
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:2027
NamedDecl * getDecl() const
Stmt * VisitObjCForCollectionStmt(ObjCForCollectionStmt *S)
ASTContext * Context
arg_iterator arg_end()
Definition: ExprCXX.h:1190
void setTypeParamList(ObjCTypeParamList *TPL)
Definition: DeclObjC.cpp:1873
ImportDefinitionKind
What we should import from the definition.
Definition: ASTImporter.cpp:91
SourceLocation getSuperClassLoc() const
Definition: DeclObjC.h:2356
ID
Defines the set of possible language-specific address spaces.
Definition: AddressSpaces.h:27
StorageClass getStorageClass() const
Returns the storage class as written in the source. For the computed linkage of symbol, see getLinkage.
Definition: Decl.h:2020
QualType getPointeeType() const
Definition: Type.cpp:414
void setInClassInitializer(Expr *Init)
Definition: Decl.h:2393
SourceLocation getColonLoc() const
Definition: Stmt.h:714
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
NameKind getNameKind() const
getNameKind - Determine what kind of name this is.
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called...
Definition: ExprCXX.h:1165
static NestedNameSpecifier * SuperSpecifier(const ASTContext &Context, CXXRecordDecl *RD)
Returns the nested name specifier representing the __super scope for the given CXXRecordDecl.
static CXXDestructorDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool isInline, bool isImplicitlyDeclared)
Definition: DeclCXX.cpp:1903
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
Expr * VisitParenExpr(ParenExpr *E)
LabelDecl * getDecl() const
Definition: Stmt.h:809
SourceLocation getVarianceLoc() const
Retrieve the location of the variance keyword.
Definition: DeclObjC.h:587
void setGetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:2582
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition: Decl.cpp:2224
QualType getPointeeType() const
Definition: Type.h:2246
Stmt * VisitGotoStmt(GotoStmt *S)
StringRef getName() const
Return the actual identifier string.
Decl * VisitEnumConstantDecl(EnumConstantDecl *D)
SourceLocation getRParenLoc() const
Definition: Expr.h:2047
static ObjCMethodDecl * Create(ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc, Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo, DeclContext *contextDecl, bool isInstance=true, bool isVariadic=false, bool isPropertyAccessor=false, bool isImplicitlyDeclared=false, bool isDefined=false, ImplementationControl impControl=None, bool HasRelatedResultType=false)
Definition: DeclObjC.cpp:697
Stmt * VisitCXXForRangeStmt(CXXForRangeStmt *S)
unsigned getNumArgs() const
bool isEmpty() const
Evaluates true when this declaration name is empty.
Declaration of a template type parameter.
void setSetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:2585
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition: ExprCXX.h:1153
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "while" statement, if any.
Definition: Stmt.cpp:985
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 wasDeclaredWithTypename() const
Whether this template type parameter was declared with the 'typename' keyword.
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:2687
Expr * VisitDeclRefExpr(DeclRefExpr *E)
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:1041
static ClassTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl, ClassTemplateDecl *PrevDecl)
Create a class template node.
TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, UnresolvedSetIterator End) const
Retrieve the template name that corresponds to a non-empty lookup.
Expr * getBitWidth() const
Definition: Decl.h:2344
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, QualType T1, QualType T2)
Determine structural equivalence of two types.
SourceLocation getRParenLoc() const
Definition: StmtObjC.h:55
bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, bool Complain=true)
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2358
void setInit(Expr *I)
Definition: Decl.cpp:2047
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:812
SourceLocation getGotoLoc() const
Definition: Stmt.h:1229
Expr * getUnderlyingExpr() const
Definition: Type.h:3364
void setRBraceLoc(SourceLocation L)
Definition: DeclCXX.h:2522
Stmt * VisitIfStmt(IfStmt *S)
Kind getKind() const
Definition: DeclBase.h:375
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:4249
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:218
SourceLocation getLocation() const
Definition: ExprCXX.h:1140
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:3142
Decl * VisitLinkageSpecDecl(LinkageSpecDecl *D)
Stmt * getBody()
Definition: Stmt.h:1069
static ObjCTypeParamDecl * Create(ASTContext &ctx, DeclContext *dc, ObjCTypeParamVariance variance, SourceLocation varianceLoc, unsigned index, SourceLocation nameLoc, IdentifierInfo *name, SourceLocation colonLoc, TypeSourceInfo *boundInfo)
Definition: DeclObjC.cpp:1223
DeclContext * getDeclContext()
Definition: DeclBase.h:381
A structure for storing the information associated with a substituted template template parameter...
Definition: TemplateName.h:339
Expr * getRHS()
Definition: Stmt.h:718
QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T)
ConstructionKind getConstructionKind() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition: ExprCXX.h:1172
ParmVarDecl *const * param_iterator
Definition: DeclObjC.h:350
Represents Objective-C's @synchronized statement.
Definition: StmtObjC.h:262
const char * getDeclKindName() const
Definition: DeclBase.cpp:87
void setGetterName(Selector Sel)
Definition: DeclObjC.h:2576
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:1791
Represents a C++ template name within the type system.
Definition: TemplateName.h:175
DecltypeType (C++0x)
Definition: Type.h:3422
QualType VisitConstantArrayType(const ConstantArrayType *T)
A namespace alias, stored as a NamespaceAliasDecl*.
void setImplementation(ObjCImplementationDecl *ImplD)
Definition: DeclObjC.cpp:1406
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
SourceLocation getEndLoc() const
Definition: Stmt.h:476
Kind getAttrKind() const
Definition: Type.h:3634
Stmt * VisitObjCAtTryStmt(ObjCAtTryStmt *S)
const SwitchCase * getSwitchCaseList() const
Definition: Stmt.h:987
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3166
Expr * getSubExpr() const
Definition: Expr.h:1699
SourceLocation getLabelLoc() const
Definition: Stmt.h:1231
bool hasRelatedResultType() const
Determine whether this method has a result type that is related to the message receiver's type...
Definition: DeclObjC.h:276
A unary type transform, which is a type constructed from another.
Definition: Type.h:3463
bool isInstanceMethod() const
Definition: DeclObjC.h:419
bool isFunctionOrMethod() const
Definition: DeclBase.h:1223
void ImportDeclarationNameLoc(const DeclarationNameInfo &From, DeclarationNameInfo &To)
QualType getCXXNameType() const
Decl * GetAlreadyImportedOrNull(Decl *FromD)
Return the copy of the given declaration in the "to" context if it has already been imported from the...
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:271
const TemplateArgument * data() const
Retrieve a pointer to the template argument list.
Definition: DeclTemplate.h:215
DeclarationName getDeclName() const
Definition: Decl.h:189
Stmt * VisitReturnStmt(ReturnStmt *S)
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: Stmt.cpp:311
ValueDecl * getDecl()
Definition: Expr.h:994
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
QualType getElementType() const
Definition: Type.h:2723
QualType getComputationLHSType() const
Definition: Expr.h:3133
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2405
The result type of a method or function.
RecordDecl * getDefinition() const
Definition: Decl.h:3339
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name, with source-location information.
Definition: Expr.h:1022
SourceLocation getSemiLoc() const
Definition: Stmt.h:535
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:611
QualType getReplacementType() const
Definition: Type.h:3794
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:2937
CanQualType SignedCharTy
Definition: ASTContext.h:825
const Expr * getAnyInitializer() const
Definition: Decl.h:1056
SourceLocation getAtLoc() const
Definition: StmtObjC.h:363
TypeSourceInfo * getReturnTypeSourceInfo() const
Definition: DeclObjC.h:344
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
Definition: Decl.h:1835
Decl * VisitObjCMethodDecl(ObjCMethodDecl *D)
TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, bool TemplateKeyword, TemplateDecl *Template) const
Retrieve the template name that represents a qualified template name such as std::vector.
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition: Decl.h:1784
static CXXRecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, CXXRecordDecl *PrevDecl=nullptr, bool DelayTypeCreation=false)
Definition: DeclCXX.cpp:95
ObjCCategoryDecl * getCategoryDecl() const
Definition: DeclObjC.cpp:1909
param_const_iterator param_end() const
Definition: DeclObjC.h:362
QualType getComputationResultType() const
Definition: Expr.h:3136
QualType VisitEnumType(const EnumType *T)
LabelDecl * getLabel() const
Definition: Stmt.h:1226
void addAttr(Attr *A)
Definition: DeclBase.h:437
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
Definition: Type.h:3788
Stmt * getBody(const FunctionDecl *&Definition) const
Definition: Decl.cpp:2405
SourceLocation getOperatorLoc() const
Definition: Expr.h:2044
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
const IdentifierInfo * getIdentifier() const
Definition: Type.h:4370
A template template parameter pack that has been substituted for a template template argument pack...
Definition: TemplateName.h:206
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
Definition: DeclCXX.h:1367
ASTContext & getFromContext() const
Retrieve the context that AST nodes are being imported from.
Definition: ASTImporter.h:250
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:208
ObjCPropertyImplDecl * FindPropertyImplDecl(IdentifierInfo *propertyId) const
Definition: DeclObjC.cpp:1960
SourceLocation getGotoLoc() const
Definition: Stmt.h:1262
SourceLocation getExternLoc() const
Definition: DeclCXX.h:2519
#define false
Definition: stdbool.h:33
SelectorTable & Selectors
Definition: ASTContext.h:440
Kind
Decl * VisitIndirectFieldDecl(IndirectFieldDecl *D)
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:3028
Decl * VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D)
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
bool isAnonymousStructOrUnion() const
Definition: Decl.cpp:3334
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Definition: ASTContext.h:864
const Type * getTypePtr() const
Definition: Type.h:5016
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:264
QualType VisitFunctionProtoType(const FunctionProtoType *T)
QualType getElementType() const
Definition: Type.h:2077
unsigned getBitWidthValue(const ASTContext &Ctx) const
Definition: Decl.cpp:3344
TypeOfType (GCC extension).
Definition: Type.h:3398
const TemplateArgumentListInfo & getTemplateArgsInfo() const
QualType VisitBuiltinType(const BuiltinType *T)
SourceLocation getLocStart() const LLVM_READONLY
Definition: Decl.h:507
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:118
static CXXConstructorDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool isExplicit, bool isInline, bool isImplicitlyDeclared, bool isConstexpr)
Definition: DeclCXX.cpp:1750
OverloadedOperatorKind getCXXOverloadedOperator() const
Expr * getLHS()
Definition: Stmt.h:717
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2694
TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, const IdentifierInfo *Name) const
Retrieve the template name that represents a dependent template name such as MetaFun::template apply...
attr_range attrs() const
Definition: DeclBase.h:447
static Optional< unsigned > findAnonymousStructOrUnionIndex(RecordDecl *Anon)
Find the index of the given anonymous struct/union within its context.
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:284
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.
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Definition: Expr.h:1158
static QualType getUnderlyingType(const SubRegion *R)
Decl * VisitTranslationUnitDecl(TranslationUnitDecl *D)
void setPropertyAttributesAsWritten(PropertyAttributeKind PRVal)
Definition: DeclObjC.h:2533
const Expr * getCond() const
Definition: Stmt.h:985
bool isVariadic() const
Definition: DeclObjC.h:421
VectorKind getVectorKind() const
Definition: Type.h:2732
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:53
SourceLocation getIdentLoc() const
Definition: Stmt.h:808
Decl * VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D)
Expr * VisitMemberExpr(MemberExpr *E)
bool getSynthesize() const
Definition: DeclObjC.h:1658
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1717
unsigned getDepth() const
Retrieve the depth of the template parameter.
bool shouldForceImportDeclContext(ImportDefinitionKind IDK)
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
Definition: DeclObjC.h:1157
QualType getIncompleteArrayType(QualType EltTy, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return a unique reference to the type for an incomplete array of the specified element type...
Decl * VisitFunctionDecl(FunctionDecl *D)
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:2093
bool isPropertyAccessor() const
Definition: DeclObjC.h:426
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:77
QualType VisitTypedefType(const TypedefType *T)
SourceLocation getContinueLoc() const
Definition: Stmt.h:1299
const FileInfo & getFile() const
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:2424
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "switch" statement, if any.
Definition: Stmt.cpp:951
TypedefNameDecl * getDecl() const
Definition: Type.h:3348
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
Definition: DeclObjC.h:2001
ASTNodeImporter(ASTImporter &Importer)
Definition: ASTImporter.cpp:34
Stmt * VisitForStmt(ForStmt *S)
unsigned getNumProtocols() const
Definition: Type.h:4631
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:67
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
SourceLocation getBegin() const
QualType getReturnType() const
Definition: DeclObjC.h:330
const T * castAs() const
Definition: Type.h:5586
QualType getAttributedType(AttributedType::Kind attrKind, QualType modifiedType, QualType equivalentType)
QualType VisitRecordType(const RecordType *T)
Decl * VisitVarTemplateDecl(VarTemplateDecl *D)
Stmt * VisitCompoundStmt(CompoundStmt *S)
Stmt * VisitIndirectGotoStmt(IndirectGotoStmt *S)
Decl * VisitImplicitParamDecl(ImplicitParamDecl *D)
SourceLocation getAtSynchronizedLoc() const
Definition: StmtObjC.h:279
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition: Decl.h:2024
Stmt * VisitWhileStmt(WhileStmt *S)
Attr * clone(ASTContext &C) const
UTTKind getUTTKind() const
Definition: Type.h:3487
Expr * VisitCallExpr(CallExpr *E)
SourceLocation getCategoryNameLoc() const
Definition: DeclObjC.h:2186
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
Definition: TemplateName.h:278
QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T)
void setHasInheritedDefaultArg(bool I=true)
Definition: Decl.h:1472
SourceLocation getForLoc() const
Definition: StmtCXX.h:185
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:68
SourceLocation getLParenLoc() const
Definition: DeclObjC.h:2500
Opcode getOpcode() const
Definition: Expr.h:1696
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:247
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:1379
The injected class name of a C++ class template or class template partial specialization. Used to record that a type was spelled with a bare identifier rather than as a template-id; the equivalent for non-templated classes is just RecordType.
Definition: Type.h:4082
QualType getPointeeType() const
Definition: Type.h:2139
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition: Expr.h:1703
void setVirtualAsWritten(bool V)
Definition: Decl.h:1785
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
static TypeAliasDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
Definition: Decl.cpp:3970
ArrayRef< QualType > getTypeArgsAsWritten() const
Definition: Type.h:4615
const char * getTypeClassName() const
Definition: Type.cpp:2464
Expr * getSizeExpr() const
Definition: Type.h:2624
param_range params()
Definition: Decl.h:1951
bool isArrow() const
Definition: Expr.h:2548
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2576
QualType getType() const
Definition: Expr.h:125
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool isAnonymousStructOrUnion() const
Definition: Decl.h:3294
CanQualType CharTy
Definition: ASTContext.h:819
Represents a template argument.
Definition: TemplateBase.h:39
SourceLocation getLocation() const
Definition: Expr.h:1341
QualType getMemberPointerType(QualType T, const Type *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
bool ImportDeclParts(NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc)
void setBody(Stmt *B)
Definition: Decl.cpp:2415
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:240
static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls)
Definition: DeclGroup.h:72
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "if" statement, if any.
Definition: Stmt.cpp:894
NonEquivalentDeclSet & getNonEquivalentDecls()
Return the set of declarations that we know are not equivalent.
Definition: ASTImporter.h:265
Represents a template name that was expressed as a qualified name.
Definition: TemplateName.h:383
Selector getObjCSelector() const
TemplateName getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param, const TemplateArgument &ArgPack) const
ObjCCategoryDecl * FindCategoryDeclaration(IdentifierInfo *CategoryId) const
Definition: DeclObjC.cpp:1505
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition: Decl.cpp:2276
static LinkageSpecDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation ExternLoc, SourceLocation LangLoc, LanguageIDs Lang, bool HasBraces)
Definition: DeclCXX.cpp:1956
virtual void CompleteDecl(Decl *D)
Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl. Mark the Decl as complete, filling it in as much as possible.
static const Type * getElementType(const Expr *BaseExpr)
SourceRange getCXXOperatorNameRange() const
SourceLocation getLParenLoc() const
Definition: Expr.h:2884
ObjCCategoryImplDecl * getImplementation() const
Definition: DeclObjC.cpp:1864
void ImportDeclContext(DeclContext *FromDC, bool ForceImport=false)
bool hasTemplateKeyword() const
Whether the template name was prefixed by the "template" keyword.
Definition: TemplateName.h:410
bool hadMultipleCandidates() const
Returns true if this expression refers to a function that was resolved from an overloaded set having ...
Definition: Expr.h:1146
static NonTypeTemplateParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id, QualType T, bool ParameterPack, TypeSourceInfo *TInfo)
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
SourceLocation getStarLoc() const
Definition: Stmt.h:1264
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:311
TemplateArgument ImportTemplateArgument(const TemplateArgument &From)
QualType VisitIncompleteArrayType(const IncompleteArrayType *T)
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
virtual Decl * Imported(Decl *From, Decl *To)
Note that we have imported the "from" declaration by mapping it to the (potentially-newly-created) "t...
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:2598
const Stmt * getBody() const
Definition: Stmt.h:986
SourceLocation getLocStart() const LLVM_READONLY
Definition: TypeLoc.h:130
QualType getPromotionType() const
Definition: Decl.h:3107
QualType VisitAttributedType(const AttributedType *T)
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name...
Definition: Expr.h:2440
static bool IsArrayStructurallyEquivalent(StructuralEquivalenceContext &Context, const ArrayType *Array1, const ArrayType *Array2)
Determine structural equivalence for the common part of array types.
QualType getEquivalentType() const
Definition: Type.h:3639
const llvm::APSInt & getInitVal() const
Definition: Decl.h:2469
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition: DeclObjC.h:1219
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
bool isParameterPack() const
Definition: Type.h:3737
LanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition: DeclCXX.h:2508
SourceLocation getPropertyIvarDeclLoc() const
Definition: DeclObjC.h:2690
bool hasWrittenPrototype() const
Definition: Decl.h:1827
const ContentCache * getContentCache() const
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
const Expr * getSynchExpr() const
Definition: StmtObjC.h:290
Expr * VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E)
unsigned getNumHandlers() const
Definition: StmtCXX.h:103
Selector getGetterName() const
Definition: DeclObjC.h:2575
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
DefinitionKind isThisDeclarationADefinition(ASTContext &) const
Check whether this declaration is a definition. If this could be a tentative definition (in C)...
Definition: Decl.cpp:1896
bool isUsed(bool CheckUsedAttr=true) const
Whether this declaration was used, meaning that a definition is required.
Definition: DeclBase.cpp:305
static ObjCImplementationDecl * Create(ASTContext &C, DeclContext *DC, ObjCInterfaceDecl *classInterface, ObjCInterfaceDecl *superDecl, SourceLocation nameLoc, SourceLocation atStartLoc, SourceLocation superLoc=SourceLocation(), SourceLocation IvarLBraceLoc=SourceLocation(), SourceLocation IvarRBraceLoc=SourceLocation())
Definition: DeclObjC.cpp:1980
Decl * VisitClassTemplateDecl(ClassTemplateDecl *D)
A set of unresolved declarations.
SourceLocation getWhileLoc() const
Definition: Stmt.h:1120
SourceLocation getLocStart() const LLVM_READONLY
Definition: Decl.h:633
bool isNull() const
Determine whether this template argument has no value.
Definition: TemplateBase.h:221
bool path_empty() const
Definition: Expr.h:2727
QualType getModifiedType() const
Definition: Type.h:3638
const Expr * getRetValue() const
Definition: Stmt.cpp:1013
unsigned getNumArgs() const
Definition: Expr.h:2205
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:1855
unsigned getNumArgs() const
Definition: ExprCXX.h:1198
A type that was preceded by the 'template' keyword, stored as a Type*.
static EnumDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl, bool IsScoped, bool IsScopedUsingClassTag, bool IsFixed)
Definition: Decl.cpp:3503
body_iterator body_begin()
Definition: Stmt.h:586
Decl * VisitObjCIvarDecl(ObjCIvarDecl *D)
VarTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
const TemplateArgument & getArg(unsigned Idx) const
Definition: TemplateBase.h:664
Decl * VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D)
unsigned getDepth() const
Get the nesting depth of the template parameter.
QualType getPointeeType() const
Definition: Type.h:4794
const Stmt * getThen() const
Definition: Stmt.h:916
QualType VisitLValueReferenceType(const LValueReferenceType *T)
SourceLocation getAtCatchLoc() const
Definition: StmtObjC.h:102
bool hasInheritedDefaultArg() const
Definition: Decl.h:1468
static ObjCIvarDecl * Create(ASTContext &C, ObjCContainerDecl *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW=nullptr, bool synthesized=false)
Definition: DeclObjC.cpp:1589
SourceLocation getRParenLoc() const
Definition: StmtObjC.h:104
ObjCMethodDecl * getGetterMethodDecl() const
Definition: DeclObjC.h:2581
const TemplateArgument * getArgs() const
Retrieve the template arguments.
Definition: Type.h:4033
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum. These widths include the rightmost leading 1; that is:
Definition: Decl.h:3158
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition: DeclBase.h:517
VarDecl * getTemplatedDecl() const
Get the underlying variable declarations of the template.
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:3465
static VarTemplateSpecializationDecl * Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args, unsigned NumArgs)
const T * getAs() const
Definition: Type.h:5555
Imports selected nodes from one AST context into another context, merging AST nodes where appropriate...
Definition: ASTImporter.h:38
DeclStmt * getBeginEndStmt()
Definition: StmtCXX.h:151
unsigned getTypeQuals() const
Definition: Type.h:3240
const Stmt * getSubStmt() const
Definition: StmtObjC.h:356
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T)
Definition: Decl.cpp:3850
Represents Objective-C's collection statement.
Definition: StmtObjC.h:24
bool isInvalid() const
ObjCMethodDecl * getSetterMethodDecl() const
Definition: DeclObjC.h:2584
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:1626
Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV)
Can create any sort of selector.
SourceLocation getAtTryLoc() const
Retrieve the location of the @ in the @try.
Definition: StmtObjC.h:193
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:1758
QualType getIntegralType() const
Retrieve the type of the integral value.
Definition: TemplateBase.h:296
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2010
CanQualType WCharTy
Definition: ASTContext.h:820
QualType getIntegerType() const
Definition: Decl.h:3115
void setSwitchLoc(SourceLocation L)
Definition: Stmt.h:999
QualType getInnerType() const
Definition: Type.h:2108
virtual void CompleteType(TagDecl *Tag)
Gives the external AST source an opportunity to complete an incomplete type.
void setSetterName(Selector Sel)
Definition: DeclObjC.h:2579
DeclContext * getRedeclContext()
Definition: DeclBase.cpp:1466
CXXConstructorDecl * getConstructor() const
Definition: ExprCXX.h:1137
SourceLocation getRBraceLoc() const
Definition: DeclCXX.h:2520
bool isTrivial() const
Definition: Decl.h:1800
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition: DeclObjC.h:1578
Represents Objective-C's @finally statement.
Definition: StmtObjC.h:120
static CXXMethodDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool isInline, bool isConstexpr, SourceLocation EndLocation)
Definition: DeclCXX.cpp:1467
The template argument is a type.
Definition: TemplateBase.h:47
ObjCImplementationDecl * getImplementation() const
Definition: DeclObjC.cpp:1393
NestedNameSpecifier * getQualifier() const
Definition: Type.h:4369
protocol_iterator protocol_end() const
Definition: DeclObjC.h:1051
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
const TemplateArgument & getArg(unsigned Idx) const
Retrieve a specific template argument as a type.
Definition: TemplateBase.h:658
Represents a base class of a C++ class.
Definition: DeclCXX.h:157
QualType VisitUnaryTransformType(const UnaryTransformType *T)
unsigned getNumCatchStmts() const
Retrieve the number of @catch statements in this try-catch-finally block.
Definition: StmtObjC.h:203
SourceLocation getRParenLoc() const
Definition: Expr.h:2887
void setNamedTypeInfo(TypeSourceInfo *TInfo)
Decl * VisitObjCTypeParamDecl(ObjCTypeParamDecl *D)
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:3030
SourceManager & getSourceManager()
Definition: ASTContext.h:494
SourceLocation getForLoc() const
Definition: Stmt.h:1191
DeclStmt * getRangeStmt()
Definition: StmtCXX.h:150
Stmt * VisitObjCAtThrowStmt(ObjCAtThrowStmt *S)
ArrayRef< const Attr * > getAttrs() const
Definition: Stmt.h:863
void ImportDefinition(Decl *From)
Import the definition of the given declaration, including all of the declarations it contains...
Expr * getTarget()
Definition: Stmt.h:1266
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:1152
Expr * getBase() const
Definition: Expr.h:2405
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
const Type * getClass() const
Definition: Type.h:2378
ObjCPropertyDecl * getPropertyDecl() const
Definition: DeclObjC.h:2678
SourceLocation getAttrLoc() const
Definition: Stmt.h:862
AccessControl getAccessControl() const
Definition: DeclObjC.h:1651
Decl * VisitTypeAliasDecl(TypeAliasDecl *D)
Expr * NoexceptExpr
Noexcept expression, if this is EST_ComputedNoexcept.
Definition: Type.h:3032
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
Definition: TemplateBase.h:258
QualType getTypeOfExprType(Expr *e) const
GCC extension.
DeclarationName getCXXLiteralOperatorName(IdentifierInfo *II)
Expr * getCond()
Definition: Stmt.h:1111
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:337
bool isImplicitInterfaceDecl() const
Definition: DeclObjC.h:1557
const Expr * getSubExpr() const
Definition: Expr.h:1638
QualType getVariableArrayType(QualType EltTy, Expr *NumElts, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals, SourceRange Brackets) const
Return a non-unique reference to the type for a variable array of the specified element type...
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum...
Definition: Decl.h:3141
Represents a C++ struct/union/class.
Definition: DeclCXX.h:285
SourceLocation getRParenLoc() const
Definition: Stmt.h:1195
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition: Decl.cpp:2229
Opcode getOpcode() const
Definition: Expr.h:2961
SourceLocation getBreakLoc() const
Definition: Stmt.h:1327
static TypedefDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
Definition: Decl.cpp:3942
ArraySizeModifier getSizeModifier() const
Definition: Type.h:2435
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:4177
A structure for storing the information associated with an overloaded template name.
Definition: TemplateName.h:92
SourceLocation getColonLoc() const
Definition: Stmt.h:769
const Expr * getCond() const
Definition: Stmt.h:914
SourceLocation getElseLoc() const
Definition: Stmt.h:927
static VarTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, VarDecl *Decl)
Create a variable template node.
Declaration of a class template.
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorType::VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
Stmt * VisitSwitchStmt(SwitchStmt *S)
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:335
CompoundStmt * getTryBlock()
Definition: StmtCXX.h:96
void setPropertyAttributes(PropertyAttributeKind PRVal)
Definition: DeclObjC.h:2519
Represents Objective-C's @try ... @catch ... @finally statement.
Definition: StmtObjC.h:154
unsigned getIndex() const
Retrieve the index of the template parameter.
const Expr * getThrowExpr() const
Definition: StmtObjC.h:325
QualType getParamTypeForDecl() const
Definition: TemplateBase.h:252
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:406
Expr * getRHS() const
Definition: Expr.h:2966
ASTContext & getToContext() const
Retrieve the context that AST nodes are being imported into.
Definition: ASTImporter.h:247
static IndirectFieldDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, NamedDecl **CH, unsigned CHS)
Definition: Decl.cpp:3920
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:271
PropertyAttributeKind getPropertyAttributesAsWritten() const
Definition: DeclObjC.h:2523
Stmt * VisitDefaultStmt(DefaultStmt *S)
QualType getPointeeTypeAsWritten() const
Definition: Type.h:2285
SourceLocation getRBracLoc() const
Definition: Stmt.h:634
Import only the bare bones needed to establish a valid DeclContext.
SourceLocation getColonLoc() const
Definition: StmtCXX.h:187
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:739
QualType VisitExtVectorType(const ExtVectorType *T)
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition: ExprCXX.h:1160
void setNextSwitchCase(SwitchCase *SC)
Definition: Stmt.h:671
SourceLocation getIvarRBraceLoc() const
Definition: DeclObjC.h:2363
const Stmt * getTryBody() const
Retrieve the @try body.
Definition: StmtObjC.h:197
TranslationUnitDecl - The top declaration context.
Definition: Decl.h:78
void ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD=nullptr)
QualType VisitTypeOfExprType(const TypeOfExprType *T)
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace nested inside this namespace, if any.
Definition: Decl.h:487
VarDecl * getExceptionDecl() const
Definition: StmtCXX.h:50
A reference to a declared variable, function, enum, etc. [C99 6.5.1p2].
Definition: Expr.h:899
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:404
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:3941
QualType getDecltypeType(Expr *e, QualType UnderlyingType) const
C++11 decltype.
SourceLocation getRAngleLoc() const
Definition: DeclTemplate.h:128
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type...
QualType getElementType() const
Definition: Type.h:2434
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
SourceLocation getInnerLocStart() const
Definition: Decl.h:625
Stmt * getSubStmt()
Definition: Stmt.h:812
DeclStmt * getLoopVarStmt()
Definition: StmtCXX.h:156
A set of overloaded template declarations.
Definition: TemplateName.h:193
SourceLocation getRParenLoc() const
Definition: StmtCXX.h:189
A trivial tuple used to represent a source range.
SourceLocation getLocation() const
Definition: DeclBase.h:372
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:230
DeclarationNameInfo getNameInfo() const
Definition: Decl.h:1709
static ObjCCategoryImplDecl * Create(ASTContext &C, DeclContext *DC, IdentifierInfo *Id, ObjCInterfaceDecl *classInterface, SourceLocation nameLoc, SourceLocation atStartLoc, SourceLocation CategoryNameLoc)
Definition: DeclObjC.cpp:1890
static DeclarationName getUsingDirectiveName()
getUsingDirectiveName - Return name for all using-directives.
void setAccess(AccessSpecifier AS)
Definition: DeclBase.h:411
EnumDecl * getDefinition() const
Definition: Decl.h:3060
Decl * VisitNamespaceDecl(NamespaceDecl *D)
Represents a C++ namespace alias.
Definition: DeclCXX.h:2662
Decl * VisitObjCInterfaceDecl(ObjCInterfaceDecl *D)
Stmt * VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S)
SourceLocation getStartLoc() const
Definition: Stmt.h:474
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
SourceRange getSourceRange() const LLVM_READONLY
Retrieves the source range that contains the entire base specifier.
Definition: DeclCXX.h:201
bool isNull() const
isNull - Return true if this QualType doesn't point to a type yet.
Definition: Type.h:633
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:2611
static FieldDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)
Definition: Decl.cpp:3319
The global specifier '::'. There is no stored value.
void setType(QualType newType)
Definition: Decl.h:539
Decl * VisitParmVarDecl(ParmVarDecl *D)
SourceLocation getCatchLoc() const
Definition: StmtCXX.h:49
QualType VisitRValueReferenceType(const RValueReferenceType *T)
Represents Objective-C's @autoreleasepool Statement.
Definition: StmtObjC.h:345
QualType VisitAutoType(const AutoType *T)
ArrayRef< QualType > exceptions() const
Definition: Type.h:3263
bool isBeingDefined() const
isBeingDefined - Return true if this decl is currently being defined.
Definition: Decl.h:2849
This class handles loading and caching of source files into memory.
Stmt * getSubStmt()
Definition: Stmt.h:866
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:3062
QualType VisitType(const Type *T)
DeclContext * ImportContext(DeclContext *FromDC)
Import the given declaration context from the "from" AST context into the "to" AST context...
void setPropertyIvarDecl(ObjCIvarDecl *Ivar)
Definition: DeclObjC.h:2595
static ObjCAtTryStmt * Create(const ASTContext &Context, SourceLocation atTryLoc, Stmt *atTryStmt, Stmt **CatchStmts, unsigned NumCatchStmts, Stmt *atFinallyStmt)
Definition: Stmt.cpp:794
Stmt * VisitStmt(Stmt *S)
Attr - This represents one attribute.
Definition: Attr.h:44
QualType VisitTypeOfType(const TypeOfType *T)
A single template declaration.
Definition: TemplateName.h:191
DeclAccessPair getFoundDecl() const
Retrieves the declaration found by lookup.
Definition: Expr.h:2415
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:5043
bool isMutable() const
isMutable - Determines whether this field is mutable (C++ only).
Definition: Decl.h:2327
bool hasInClassInitializer() const
Definition: Decl.h:2377
TypeSourceInfo * getArgumentTypeInfo() const
Definition: Expr.h:2017
bool isInnerRef() const
Definition: Type.h:2283
unsigned getNumExceptions() const
Definition: Type.h:3193
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
Structure used to store a statement, the constant value to which it was evaluated (if any)...
Definition: Decl.h:679
const ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.h:2354
SourceLocation getTemplateLoc() const
Definition: DeclTemplate.h:126
static NestedNameSpecifier * GlobalSpecifier(const ASTContext &Context)
Returns the nested name specifier representing the global scope.
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:625
QualType getDeducedType() const
Get the type deduced for this auto type, or null if it's either not been deduced or was deduced to a ...
Definition: Type.h:3897