clang  3.9.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
68  // FIXME: DependentDecltypeType
73  // FIXME: SubstTemplateTypeParmType
76  // FIXME: DependentNameType
77  // FIXME: DependentTemplateSpecializationType
81 
82  // Importing declarations
83  bool ImportDeclParts(NamedDecl *D, DeclContext *&DC,
84  DeclContext *&LexicalDC, DeclarationName &Name,
85  NamedDecl *&ToD, SourceLocation &Loc);
86  void ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
89  void ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
90 
93 
94 
95  /// \brief What we should import from the definition.
97  /// \brief Import the default subset of the definition, which might be
98  /// nothing (if minimal import is set) or might be everything (if minimal
99  /// import is not set).
101  /// \brief Import everything.
103  /// \brief Import only the bare bones needed to establish a valid
104  /// DeclContext.
106  };
107 
109  return IDK == IDK_Everything ||
110  (IDK == IDK_Default && !Importer.isMinimalImport());
111  }
112 
113  bool ImportDefinition(RecordDecl *From, RecordDecl *To,
115  bool ImportDefinition(VarDecl *From, VarDecl *To,
117  bool ImportDefinition(EnumDecl *From, EnumDecl *To,
124  TemplateParameterList *Params);
126  bool ImportTemplateArguments(const TemplateArgument *FromArgs,
127  unsigned NumFromArgs,
129  bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord,
130  bool Complain = true);
131  bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar,
132  bool Complain = true);
133  bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord);
137  Decl *VisitDecl(Decl *D);
141  Decl *VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias);
164 
179 
180  // Importing statements
182 
183  Stmt *VisitStmt(Stmt *S);
202  // FIXME: MSAsmStmt
203  // FIXME: SEHExceptStmt
204  // FIXME: SEHFinallyStmt
205  // FIXME: SEHTryStmt
206  // FIXME: SEHLeaveStmt
207  // FIXME: CapturedStmt
211  // FIXME: MSDependentExistsStmt
219 
220  // Importing expressions
221  Expr *VisitExpr(Expr *E);
257 
258  template<typename IIter, typename OIter>
259  void ImportArray(IIter Ibegin, IIter Iend, OIter Obegin) {
260  typedef typename std::remove_reference<decltype(*Obegin)>::type ItemT;
261  ASTImporter &ImporterRef = Importer;
262  std::transform(Ibegin, Iend, Obegin,
263  [&ImporterRef](ItemT From) -> ItemT {
264  return ImporterRef.Import(From);
265  });
266  }
267 
268  template<typename IIter, typename OIter>
269  bool ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
271  ASTImporter &ImporterRef = Importer;
272  bool Failed = false;
273  std::transform(Ibegin, Iend, Obegin,
274  [&ImporterRef, &Failed](ItemT *From) -> ItemT * {
275  ItemT *To = ImporterRef.Import(From);
276  if (!To && From)
277  Failed = true;
278  return To;
279  });
280  return Failed;
281  }
282  };
283 }
284 
285 using namespace clang;
286 
287 //----------------------------------------------------------------------------
288 // Structural Equivalence
289 //----------------------------------------------------------------------------
290 
291 namespace {
292  struct StructuralEquivalenceContext {
293  /// \brief AST contexts for which we are checking structural equivalence.
294  ASTContext &C1, &C2;
295 
296  /// \brief The set of "tentative" equivalences between two canonical
297  /// declarations, mapping from a declaration in the first context to the
298  /// declaration in the second context that we believe to be equivalent.
299  llvm::DenseMap<Decl *, Decl *> TentativeEquivalences;
300 
301  /// \brief Queue of declarations in the first context whose equivalence
302  /// with a declaration in the second context still needs to be verified.
303  std::deque<Decl *> DeclsToCheck;
304 
305  /// \brief Declaration (from, to) pairs that are known not to be equivalent
306  /// (which we have already complained about).
307  llvm::DenseSet<std::pair<Decl *, Decl *> > &NonEquivalentDecls;
308 
309  /// \brief Whether we're being strict about the spelling of types when
310  /// unifying two types.
311  bool StrictTypeSpelling;
312 
313  /// \brief Whether to complain about failures.
314  bool Complain;
315 
316  /// \brief \c true if the last diagnostic came from C2.
317  bool LastDiagFromC2;
318 
319  StructuralEquivalenceContext(ASTContext &C1, ASTContext &C2,
320  llvm::DenseSet<std::pair<Decl *, Decl *> > &NonEquivalentDecls,
321  bool StrictTypeSpelling = false,
322  bool Complain = true)
323  : C1(C1), C2(C2), NonEquivalentDecls(NonEquivalentDecls),
324  StrictTypeSpelling(StrictTypeSpelling), Complain(Complain),
325  LastDiagFromC2(false) {}
326 
327  /// \brief Determine whether the two declarations are structurally
328  /// equivalent.
329  bool IsStructurallyEquivalent(Decl *D1, Decl *D2);
330 
331  /// \brief Determine whether the two types are structurally equivalent.
333 
334  private:
335  /// \brief Finish checking all of the structural equivalences.
336  ///
337  /// \returns true if an error occurred, false otherwise.
338  bool Finish();
339 
340  public:
341  DiagnosticBuilder Diag1(SourceLocation Loc, unsigned DiagID) {
342  assert(Complain && "Not allowed to complain");
343  if (LastDiagFromC2)
344  C1.getDiagnostics().notePriorDiagnosticFrom(C2.getDiagnostics());
345  LastDiagFromC2 = false;
346  return C1.getDiagnostics().Report(Loc, DiagID);
347  }
348 
349  DiagnosticBuilder Diag2(SourceLocation Loc, unsigned DiagID) {
350  assert(Complain && "Not allowed to complain");
351  if (!LastDiagFromC2)
352  C2.getDiagnostics().notePriorDiagnosticFrom(C1.getDiagnostics());
353  LastDiagFromC2 = true;
354  return C2.getDiagnostics().Report(Loc, DiagID);
355  }
356  };
357 }
358 
359 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
360  QualType T1, QualType T2);
361 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
362  Decl *D1, Decl *D2);
363 
364 /// \brief Determine structural equivalence of two expressions.
365 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
366  Expr *E1, Expr *E2) {
367  if (!E1 || !E2)
368  return E1 == E2;
369 
370  // FIXME: Actually perform a structural comparison!
371  return true;
372 }
373 
374 /// \brief Determine whether two identifiers are equivalent.
375 static bool IsStructurallyEquivalent(const IdentifierInfo *Name1,
376  const IdentifierInfo *Name2) {
377  if (!Name1 || !Name2)
378  return Name1 == Name2;
379 
380  return Name1->getName() == Name2->getName();
381 }
382 
383 /// \brief Determine whether two nested-name-specifiers are equivalent.
384 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
385  NestedNameSpecifier *NNS1,
386  NestedNameSpecifier *NNS2) {
387  // FIXME: Implement!
388  return true;
389 }
390 
391 /// \brief Determine whether two template arguments are equivalent.
392 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
393  const TemplateArgument &Arg1,
394  const TemplateArgument &Arg2) {
395  if (Arg1.getKind() != Arg2.getKind())
396  return false;
397 
398  switch (Arg1.getKind()) {
400  return true;
401 
403  return Context.IsStructurallyEquivalent(Arg1.getAsType(), Arg2.getAsType());
404 
406  if (!Context.IsStructurallyEquivalent(Arg1.getIntegralType(),
407  Arg2.getIntegralType()))
408  return false;
409 
410  return llvm::APSInt::isSameValue(Arg1.getAsIntegral(), Arg2.getAsIntegral());
411 
413  return Context.IsStructurallyEquivalent(Arg1.getAsDecl(), Arg2.getAsDecl());
414 
416  return true; // FIXME: Is this correct?
417 
419  return IsStructurallyEquivalent(Context,
420  Arg1.getAsTemplate(),
421  Arg2.getAsTemplate());
422 
424  return IsStructurallyEquivalent(Context,
427 
429  return IsStructurallyEquivalent(Context,
430  Arg1.getAsExpr(), Arg2.getAsExpr());
431 
433  if (Arg1.pack_size() != Arg2.pack_size())
434  return false;
435 
436  for (unsigned I = 0, N = Arg1.pack_size(); I != N; ++I)
437  if (!IsStructurallyEquivalent(Context,
438  Arg1.pack_begin()[I],
439  Arg2.pack_begin()[I]))
440  return false;
441 
442  return true;
443  }
444 
445  llvm_unreachable("Invalid template argument kind");
446 }
447 
448 /// \brief Determine structural equivalence for the common part of array
449 /// types.
450 static bool IsArrayStructurallyEquivalent(StructuralEquivalenceContext &Context,
451  const ArrayType *Array1,
452  const ArrayType *Array2) {
453  if (!IsStructurallyEquivalent(Context,
454  Array1->getElementType(),
455  Array2->getElementType()))
456  return false;
457  if (Array1->getSizeModifier() != Array2->getSizeModifier())
458  return false;
459  if (Array1->getIndexTypeQualifiers() != Array2->getIndexTypeQualifiers())
460  return false;
461 
462  return true;
463 }
464 
465 /// \brief Determine structural equivalence of two types.
466 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
467  QualType T1, QualType T2) {
468  if (T1.isNull() || T2.isNull())
469  return T1.isNull() && T2.isNull();
470 
471  if (!Context.StrictTypeSpelling) {
472  // We aren't being strict about token-to-token equivalence of types,
473  // so map down to the canonical type.
474  T1 = Context.C1.getCanonicalType(T1);
475  T2 = Context.C2.getCanonicalType(T2);
476  }
477 
478  if (T1.getQualifiers() != T2.getQualifiers())
479  return false;
480 
481  Type::TypeClass TC = T1->getTypeClass();
482 
483  if (T1->getTypeClass() != T2->getTypeClass()) {
484  // Compare function types with prototypes vs. without prototypes as if
485  // both did not have prototypes.
486  if (T1->getTypeClass() == Type::FunctionProto &&
487  T2->getTypeClass() == Type::FunctionNoProto)
488  TC = Type::FunctionNoProto;
489  else if (T1->getTypeClass() == Type::FunctionNoProto &&
490  T2->getTypeClass() == Type::FunctionProto)
491  TC = Type::FunctionNoProto;
492  else
493  return false;
494  }
495 
496  switch (TC) {
497  case Type::Builtin:
498  // FIXME: Deal with Char_S/Char_U.
499  if (cast<BuiltinType>(T1)->getKind() != cast<BuiltinType>(T2)->getKind())
500  return false;
501  break;
502 
503  case Type::Complex:
504  if (!IsStructurallyEquivalent(Context,
505  cast<ComplexType>(T1)->getElementType(),
506  cast<ComplexType>(T2)->getElementType()))
507  return false;
508  break;
509 
510  case Type::Adjusted:
511  case Type::Decayed:
512  if (!IsStructurallyEquivalent(Context,
513  cast<AdjustedType>(T1)->getOriginalType(),
514  cast<AdjustedType>(T2)->getOriginalType()))
515  return false;
516  break;
517 
518  case Type::Pointer:
519  if (!IsStructurallyEquivalent(Context,
520  cast<PointerType>(T1)->getPointeeType(),
521  cast<PointerType>(T2)->getPointeeType()))
522  return false;
523  break;
524 
525  case Type::BlockPointer:
526  if (!IsStructurallyEquivalent(Context,
527  cast<BlockPointerType>(T1)->getPointeeType(),
528  cast<BlockPointerType>(T2)->getPointeeType()))
529  return false;
530  break;
531 
532  case Type::LValueReference:
533  case Type::RValueReference: {
534  const ReferenceType *Ref1 = cast<ReferenceType>(T1);
535  const ReferenceType *Ref2 = cast<ReferenceType>(T2);
536  if (Ref1->isSpelledAsLValue() != Ref2->isSpelledAsLValue())
537  return false;
538  if (Ref1->isInnerRef() != Ref2->isInnerRef())
539  return false;
540  if (!IsStructurallyEquivalent(Context,
541  Ref1->getPointeeTypeAsWritten(),
542  Ref2->getPointeeTypeAsWritten()))
543  return false;
544  break;
545  }
546 
547  case Type::MemberPointer: {
548  const MemberPointerType *MemPtr1 = cast<MemberPointerType>(T1);
549  const MemberPointerType *MemPtr2 = cast<MemberPointerType>(T2);
550  if (!IsStructurallyEquivalent(Context,
551  MemPtr1->getPointeeType(),
552  MemPtr2->getPointeeType()))
553  return false;
554  if (!IsStructurallyEquivalent(Context,
555  QualType(MemPtr1->getClass(), 0),
556  QualType(MemPtr2->getClass(), 0)))
557  return false;
558  break;
559  }
560 
561  case Type::ConstantArray: {
562  const ConstantArrayType *Array1 = cast<ConstantArrayType>(T1);
563  const ConstantArrayType *Array2 = cast<ConstantArrayType>(T2);
564  if (!llvm::APInt::isSameValue(Array1->getSize(), Array2->getSize()))
565  return false;
566 
567  if (!IsArrayStructurallyEquivalent(Context, Array1, Array2))
568  return false;
569  break;
570  }
571 
572  case Type::IncompleteArray:
573  if (!IsArrayStructurallyEquivalent(Context,
574  cast<ArrayType>(T1),
575  cast<ArrayType>(T2)))
576  return false;
577  break;
578 
579  case Type::VariableArray: {
580  const VariableArrayType *Array1 = cast<VariableArrayType>(T1);
581  const VariableArrayType *Array2 = cast<VariableArrayType>(T2);
582  if (!IsStructurallyEquivalent(Context,
583  Array1->getSizeExpr(), Array2->getSizeExpr()))
584  return false;
585 
586  if (!IsArrayStructurallyEquivalent(Context, Array1, Array2))
587  return false;
588 
589  break;
590  }
591 
592  case Type::DependentSizedArray: {
593  const DependentSizedArrayType *Array1 = cast<DependentSizedArrayType>(T1);
594  const DependentSizedArrayType *Array2 = cast<DependentSizedArrayType>(T2);
595  if (!IsStructurallyEquivalent(Context,
596  Array1->getSizeExpr(), Array2->getSizeExpr()))
597  return false;
598 
599  if (!IsArrayStructurallyEquivalent(Context, Array1, Array2))
600  return false;
601 
602  break;
603  }
604 
605  case Type::DependentSizedExtVector: {
606  const DependentSizedExtVectorType *Vec1
607  = cast<DependentSizedExtVectorType>(T1);
608  const DependentSizedExtVectorType *Vec2
609  = cast<DependentSizedExtVectorType>(T2);
610  if (!IsStructurallyEquivalent(Context,
611  Vec1->getSizeExpr(), Vec2->getSizeExpr()))
612  return false;
613  if (!IsStructurallyEquivalent(Context,
614  Vec1->getElementType(),
615  Vec2->getElementType()))
616  return false;
617  break;
618  }
619 
620  case Type::Vector:
621  case Type::ExtVector: {
622  const VectorType *Vec1 = cast<VectorType>(T1);
623  const VectorType *Vec2 = cast<VectorType>(T2);
624  if (!IsStructurallyEquivalent(Context,
625  Vec1->getElementType(),
626  Vec2->getElementType()))
627  return false;
628  if (Vec1->getNumElements() != Vec2->getNumElements())
629  return false;
630  if (Vec1->getVectorKind() != Vec2->getVectorKind())
631  return false;
632  break;
633  }
634 
635  case Type::FunctionProto: {
636  const FunctionProtoType *Proto1 = cast<FunctionProtoType>(T1);
637  const FunctionProtoType *Proto2 = cast<FunctionProtoType>(T2);
638  if (Proto1->getNumParams() != Proto2->getNumParams())
639  return false;
640  for (unsigned I = 0, N = Proto1->getNumParams(); I != N; ++I) {
641  if (!IsStructurallyEquivalent(Context, Proto1->getParamType(I),
642  Proto2->getParamType(I)))
643  return false;
644  }
645  if (Proto1->isVariadic() != Proto2->isVariadic())
646  return false;
647  if (Proto1->getExceptionSpecType() != Proto2->getExceptionSpecType())
648  return false;
649  if (Proto1->getExceptionSpecType() == EST_Dynamic) {
650  if (Proto1->getNumExceptions() != Proto2->getNumExceptions())
651  return false;
652  for (unsigned I = 0, N = Proto1->getNumExceptions(); I != N; ++I) {
653  if (!IsStructurallyEquivalent(Context,
654  Proto1->getExceptionType(I),
655  Proto2->getExceptionType(I)))
656  return false;
657  }
658  } else if (Proto1->getExceptionSpecType() == EST_ComputedNoexcept) {
659  if (!IsStructurallyEquivalent(Context,
660  Proto1->getNoexceptExpr(),
661  Proto2->getNoexceptExpr()))
662  return false;
663  }
664  if (Proto1->getTypeQuals() != Proto2->getTypeQuals())
665  return false;
666 
667  // Fall through to check the bits common with FunctionNoProtoType.
668  }
669 
670  case Type::FunctionNoProto: {
671  const FunctionType *Function1 = cast<FunctionType>(T1);
672  const FunctionType *Function2 = cast<FunctionType>(T2);
673  if (!IsStructurallyEquivalent(Context, Function1->getReturnType(),
674  Function2->getReturnType()))
675  return false;
676  if (Function1->getExtInfo() != Function2->getExtInfo())
677  return false;
678  break;
679  }
680 
681  case Type::UnresolvedUsing:
682  if (!IsStructurallyEquivalent(Context,
683  cast<UnresolvedUsingType>(T1)->getDecl(),
684  cast<UnresolvedUsingType>(T2)->getDecl()))
685  return false;
686 
687  break;
688 
689  case Type::Attributed:
690  if (!IsStructurallyEquivalent(Context,
691  cast<AttributedType>(T1)->getModifiedType(),
692  cast<AttributedType>(T2)->getModifiedType()))
693  return false;
694  if (!IsStructurallyEquivalent(Context,
695  cast<AttributedType>(T1)->getEquivalentType(),
696  cast<AttributedType>(T2)->getEquivalentType()))
697  return false;
698  break;
699 
700  case Type::Paren:
701  if (!IsStructurallyEquivalent(Context,
702  cast<ParenType>(T1)->getInnerType(),
703  cast<ParenType>(T2)->getInnerType()))
704  return false;
705  break;
706 
707  case Type::Typedef:
708  if (!IsStructurallyEquivalent(Context,
709  cast<TypedefType>(T1)->getDecl(),
710  cast<TypedefType>(T2)->getDecl()))
711  return false;
712  break;
713 
714  case Type::TypeOfExpr:
715  if (!IsStructurallyEquivalent(Context,
716  cast<TypeOfExprType>(T1)->getUnderlyingExpr(),
717  cast<TypeOfExprType>(T2)->getUnderlyingExpr()))
718  return false;
719  break;
720 
721  case Type::TypeOf:
722  if (!IsStructurallyEquivalent(Context,
723  cast<TypeOfType>(T1)->getUnderlyingType(),
724  cast<TypeOfType>(T2)->getUnderlyingType()))
725  return false;
726  break;
727 
728  case Type::UnaryTransform:
729  if (!IsStructurallyEquivalent(Context,
730  cast<UnaryTransformType>(T1)->getUnderlyingType(),
731  cast<UnaryTransformType>(T1)->getUnderlyingType()))
732  return false;
733  break;
734 
735  case Type::Decltype:
736  if (!IsStructurallyEquivalent(Context,
737  cast<DecltypeType>(T1)->getUnderlyingExpr(),
738  cast<DecltypeType>(T2)->getUnderlyingExpr()))
739  return false;
740  break;
741 
742  case Type::Auto:
743  if (!IsStructurallyEquivalent(Context,
744  cast<AutoType>(T1)->getDeducedType(),
745  cast<AutoType>(T2)->getDeducedType()))
746  return false;
747  break;
748 
749  case Type::Record:
750  case Type::Enum:
751  if (!IsStructurallyEquivalent(Context,
752  cast<TagType>(T1)->getDecl(),
753  cast<TagType>(T2)->getDecl()))
754  return false;
755  break;
756 
757  case Type::TemplateTypeParm: {
758  const TemplateTypeParmType *Parm1 = cast<TemplateTypeParmType>(T1);
759  const TemplateTypeParmType *Parm2 = cast<TemplateTypeParmType>(T2);
760  if (Parm1->getDepth() != Parm2->getDepth())
761  return false;
762  if (Parm1->getIndex() != Parm2->getIndex())
763  return false;
764  if (Parm1->isParameterPack() != Parm2->isParameterPack())
765  return false;
766 
767  // Names of template type parameters are never significant.
768  break;
769  }
770 
771  case Type::SubstTemplateTypeParm: {
772  const SubstTemplateTypeParmType *Subst1
773  = cast<SubstTemplateTypeParmType>(T1);
774  const SubstTemplateTypeParmType *Subst2
775  = cast<SubstTemplateTypeParmType>(T2);
776  if (!IsStructurallyEquivalent(Context,
777  QualType(Subst1->getReplacedParameter(), 0),
778  QualType(Subst2->getReplacedParameter(), 0)))
779  return false;
780  if (!IsStructurallyEquivalent(Context,
781  Subst1->getReplacementType(),
782  Subst2->getReplacementType()))
783  return false;
784  break;
785  }
786 
787  case Type::SubstTemplateTypeParmPack: {
788  const SubstTemplateTypeParmPackType *Subst1
789  = cast<SubstTemplateTypeParmPackType>(T1);
790  const SubstTemplateTypeParmPackType *Subst2
791  = cast<SubstTemplateTypeParmPackType>(T2);
792  if (!IsStructurallyEquivalent(Context,
793  QualType(Subst1->getReplacedParameter(), 0),
794  QualType(Subst2->getReplacedParameter(), 0)))
795  return false;
796  if (!IsStructurallyEquivalent(Context,
797  Subst1->getArgumentPack(),
798  Subst2->getArgumentPack()))
799  return false;
800  break;
801  }
802  case Type::TemplateSpecialization: {
803  const TemplateSpecializationType *Spec1
804  = cast<TemplateSpecializationType>(T1);
805  const TemplateSpecializationType *Spec2
806  = cast<TemplateSpecializationType>(T2);
807  if (!IsStructurallyEquivalent(Context,
808  Spec1->getTemplateName(),
809  Spec2->getTemplateName()))
810  return false;
811  if (Spec1->getNumArgs() != Spec2->getNumArgs())
812  return false;
813  for (unsigned I = 0, N = Spec1->getNumArgs(); I != N; ++I) {
814  if (!IsStructurallyEquivalent(Context,
815  Spec1->getArg(I), Spec2->getArg(I)))
816  return false;
817  }
818  break;
819  }
820 
821  case Type::Elaborated: {
822  const ElaboratedType *Elab1 = cast<ElaboratedType>(T1);
823  const ElaboratedType *Elab2 = cast<ElaboratedType>(T2);
824  // CHECKME: what if a keyword is ETK_None or ETK_typename ?
825  if (Elab1->getKeyword() != Elab2->getKeyword())
826  return false;
827  if (!IsStructurallyEquivalent(Context,
828  Elab1->getQualifier(),
829  Elab2->getQualifier()))
830  return false;
831  if (!IsStructurallyEquivalent(Context,
832  Elab1->getNamedType(),
833  Elab2->getNamedType()))
834  return false;
835  break;
836  }
837 
838  case Type::InjectedClassName: {
839  const InjectedClassNameType *Inj1 = cast<InjectedClassNameType>(T1);
840  const InjectedClassNameType *Inj2 = cast<InjectedClassNameType>(T2);
841  if (!IsStructurallyEquivalent(Context,
843  Inj2->getInjectedSpecializationType()))
844  return false;
845  break;
846  }
847 
848  case Type::DependentName: {
849  const DependentNameType *Typename1 = cast<DependentNameType>(T1);
850  const DependentNameType *Typename2 = cast<DependentNameType>(T2);
851  if (!IsStructurallyEquivalent(Context,
852  Typename1->getQualifier(),
853  Typename2->getQualifier()))
854  return false;
855  if (!IsStructurallyEquivalent(Typename1->getIdentifier(),
856  Typename2->getIdentifier()))
857  return false;
858 
859  break;
860  }
861 
862  case Type::DependentTemplateSpecialization: {
864  cast<DependentTemplateSpecializationType>(T1);
866  cast<DependentTemplateSpecializationType>(T2);
867  if (!IsStructurallyEquivalent(Context,
868  Spec1->getQualifier(),
869  Spec2->getQualifier()))
870  return false;
871  if (!IsStructurallyEquivalent(Spec1->getIdentifier(),
872  Spec2->getIdentifier()))
873  return false;
874  if (Spec1->getNumArgs() != Spec2->getNumArgs())
875  return false;
876  for (unsigned I = 0, N = Spec1->getNumArgs(); I != N; ++I) {
877  if (!IsStructurallyEquivalent(Context,
878  Spec1->getArg(I), Spec2->getArg(I)))
879  return false;
880  }
881  break;
882  }
883 
884  case Type::PackExpansion:
885  if (!IsStructurallyEquivalent(Context,
886  cast<PackExpansionType>(T1)->getPattern(),
887  cast<PackExpansionType>(T2)->getPattern()))
888  return false;
889  break;
890 
891  case Type::ObjCInterface: {
892  const ObjCInterfaceType *Iface1 = cast<ObjCInterfaceType>(T1);
893  const ObjCInterfaceType *Iface2 = cast<ObjCInterfaceType>(T2);
894  if (!IsStructurallyEquivalent(Context,
895  Iface1->getDecl(), Iface2->getDecl()))
896  return false;
897  break;
898  }
899 
900  case Type::ObjCObject: {
901  const ObjCObjectType *Obj1 = cast<ObjCObjectType>(T1);
902  const ObjCObjectType *Obj2 = cast<ObjCObjectType>(T2);
903  if (!IsStructurallyEquivalent(Context,
904  Obj1->getBaseType(),
905  Obj2->getBaseType()))
906  return false;
907  if (Obj1->getNumProtocols() != Obj2->getNumProtocols())
908  return false;
909  for (unsigned I = 0, N = Obj1->getNumProtocols(); I != N; ++I) {
910  if (!IsStructurallyEquivalent(Context,
911  Obj1->getProtocol(I),
912  Obj2->getProtocol(I)))
913  return false;
914  }
915  break;
916  }
917 
918  case Type::ObjCObjectPointer: {
919  const ObjCObjectPointerType *Ptr1 = cast<ObjCObjectPointerType>(T1);
920  const ObjCObjectPointerType *Ptr2 = cast<ObjCObjectPointerType>(T2);
921  if (!IsStructurallyEquivalent(Context,
922  Ptr1->getPointeeType(),
923  Ptr2->getPointeeType()))
924  return false;
925  break;
926  }
927 
928  case Type::Atomic: {
929  if (!IsStructurallyEquivalent(Context,
930  cast<AtomicType>(T1)->getValueType(),
931  cast<AtomicType>(T2)->getValueType()))
932  return false;
933  break;
934  }
935 
936  case Type::Pipe: {
937  if (!IsStructurallyEquivalent(Context,
938  cast<PipeType>(T1)->getElementType(),
939  cast<PipeType>(T2)->getElementType()))
940  return false;
941  break;
942  }
943 
944  } // end switch
945 
946  return true;
947 }
948 
949 /// \brief Determine structural equivalence of two fields.
950 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
951  FieldDecl *Field1, FieldDecl *Field2) {
952  RecordDecl *Owner2 = cast<RecordDecl>(Field2->getDeclContext());
953 
954  // For anonymous structs/unions, match up the anonymous struct/union type
955  // declarations directly, so that we don't go off searching for anonymous
956  // types
957  if (Field1->isAnonymousStructOrUnion() &&
958  Field2->isAnonymousStructOrUnion()) {
959  RecordDecl *D1 = Field1->getType()->castAs<RecordType>()->getDecl();
960  RecordDecl *D2 = Field2->getType()->castAs<RecordType>()->getDecl();
961  return IsStructurallyEquivalent(Context, D1, D2);
962  }
963 
964  // Check for equivalent field names.
965  IdentifierInfo *Name1 = Field1->getIdentifier();
966  IdentifierInfo *Name2 = Field2->getIdentifier();
967  if (!::IsStructurallyEquivalent(Name1, Name2))
968  return false;
969 
970  if (!IsStructurallyEquivalent(Context,
971  Field1->getType(), Field2->getType())) {
972  if (Context.Complain) {
973  Context.Diag2(Owner2->getLocation(), diag::warn_odr_tag_type_inconsistent)
974  << Context.C2.getTypeDeclType(Owner2);
975  Context.Diag2(Field2->getLocation(), diag::note_odr_field)
976  << Field2->getDeclName() << Field2->getType();
977  Context.Diag1(Field1->getLocation(), diag::note_odr_field)
978  << Field1->getDeclName() << Field1->getType();
979  }
980  return false;
981  }
982 
983  if (Field1->isBitField() != Field2->isBitField()) {
984  if (Context.Complain) {
985  Context.Diag2(Owner2->getLocation(), diag::warn_odr_tag_type_inconsistent)
986  << Context.C2.getTypeDeclType(Owner2);
987  if (Field1->isBitField()) {
988  Context.Diag1(Field1->getLocation(), diag::note_odr_bit_field)
989  << Field1->getDeclName() << Field1->getType()
990  << Field1->getBitWidthValue(Context.C1);
991  Context.Diag2(Field2->getLocation(), diag::note_odr_not_bit_field)
992  << Field2->getDeclName();
993  } else {
994  Context.Diag2(Field2->getLocation(), diag::note_odr_bit_field)
995  << Field2->getDeclName() << Field2->getType()
996  << Field2->getBitWidthValue(Context.C2);
997  Context.Diag1(Field1->getLocation(), diag::note_odr_not_bit_field)
998  << Field1->getDeclName();
999  }
1000  }
1001  return false;
1002  }
1003 
1004  if (Field1->isBitField()) {
1005  // Make sure that the bit-fields are the same length.
1006  unsigned Bits1 = Field1->getBitWidthValue(Context.C1);
1007  unsigned Bits2 = Field2->getBitWidthValue(Context.C2);
1008 
1009  if (Bits1 != Bits2) {
1010  if (Context.Complain) {
1011  Context.Diag2(Owner2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1012  << Context.C2.getTypeDeclType(Owner2);
1013  Context.Diag2(Field2->getLocation(), diag::note_odr_bit_field)
1014  << Field2->getDeclName() << Field2->getType() << Bits2;
1015  Context.Diag1(Field1->getLocation(), diag::note_odr_bit_field)
1016  << Field1->getDeclName() << Field1->getType() << Bits1;
1017  }
1018  return false;
1019  }
1020  }
1021 
1022  return true;
1023 }
1024 
1025 /// \brief Find the index of the given anonymous struct/union within its
1026 /// context.
1027 ///
1028 /// \returns Returns the index of this anonymous struct/union in its context,
1029 /// including the next assigned index (if none of them match). Returns an
1030 /// empty option if the context is not a record, i.e.. if the anonymous
1031 /// struct/union is at namespace or block scope.
1033  ASTContext &Context = Anon->getASTContext();
1034  QualType AnonTy = Context.getRecordType(Anon);
1035 
1036  RecordDecl *Owner = dyn_cast<RecordDecl>(Anon->getDeclContext());
1037  if (!Owner)
1038  return None;
1039 
1040  unsigned Index = 0;
1041  for (const auto *D : Owner->noload_decls()) {
1042  const auto *F = dyn_cast<FieldDecl>(D);
1043  if (!F)
1044  continue;
1045 
1046  if (F->isAnonymousStructOrUnion()) {
1047  if (Context.hasSameType(F->getType(), AnonTy))
1048  break;
1049  ++Index;
1050  continue;
1051  }
1052 
1053  // If the field looks like this:
1054  // struct { ... } A;
1055  QualType FieldType = F->getType();
1056  if (const auto *RecType = dyn_cast<RecordType>(FieldType)) {
1057  const RecordDecl *RecDecl = RecType->getDecl();
1058  if (RecDecl->getDeclContext() == Owner &&
1059  !RecDecl->getIdentifier()) {
1060  if (Context.hasSameType(FieldType, AnonTy))
1061  break;
1062  ++Index;
1063  continue;
1064  }
1065  }
1066  }
1067 
1068  return Index;
1069 }
1070 
1071 /// \brief Determine structural equivalence of two records.
1072 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1073  RecordDecl *D1, RecordDecl *D2) {
1074  if (D1->isUnion() != D2->isUnion()) {
1075  if (Context.Complain) {
1076  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1077  << Context.C2.getTypeDeclType(D2);
1078  Context.Diag1(D1->getLocation(), diag::note_odr_tag_kind_here)
1079  << D1->getDeclName() << (unsigned)D1->getTagKind();
1080  }
1081  return false;
1082  }
1083 
1085  // If both anonymous structs/unions are in a record context, make sure
1086  // they occur in the same location in the context records.
1089  if (*Index1 != *Index2)
1090  return false;
1091  }
1092  }
1093  }
1094 
1095  // If both declarations are class template specializations, we know
1096  // the ODR applies, so check the template and template arguments.
1098  = dyn_cast<ClassTemplateSpecializationDecl>(D1);
1100  = dyn_cast<ClassTemplateSpecializationDecl>(D2);
1101  if (Spec1 && Spec2) {
1102  // Check that the specialized templates are the same.
1103  if (!IsStructurallyEquivalent(Context, Spec1->getSpecializedTemplate(),
1104  Spec2->getSpecializedTemplate()))
1105  return false;
1106 
1107  // Check that the template arguments are the same.
1108  if (Spec1->getTemplateArgs().size() != Spec2->getTemplateArgs().size())
1109  return false;
1110 
1111  for (unsigned I = 0, N = Spec1->getTemplateArgs().size(); I != N; ++I)
1112  if (!IsStructurallyEquivalent(Context,
1113  Spec1->getTemplateArgs().get(I),
1114  Spec2->getTemplateArgs().get(I)))
1115  return false;
1116  }
1117  // If one is a class template specialization and the other is not, these
1118  // structures are different.
1119  else if (Spec1 || Spec2)
1120  return false;
1121 
1122  // Compare the definitions of these two records. If either or both are
1123  // incomplete, we assume that they are equivalent.
1124  D1 = D1->getDefinition();
1125  D2 = D2->getDefinition();
1126  if (!D1 || !D2)
1127  return true;
1128 
1129  if (CXXRecordDecl *D1CXX = dyn_cast<CXXRecordDecl>(D1)) {
1130  if (CXXRecordDecl *D2CXX = dyn_cast<CXXRecordDecl>(D2)) {
1131  if (D1CXX->getNumBases() != D2CXX->getNumBases()) {
1132  if (Context.Complain) {
1133  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1134  << Context.C2.getTypeDeclType(D2);
1135  Context.Diag2(D2->getLocation(), diag::note_odr_number_of_bases)
1136  << D2CXX->getNumBases();
1137  Context.Diag1(D1->getLocation(), diag::note_odr_number_of_bases)
1138  << D1CXX->getNumBases();
1139  }
1140  return false;
1141  }
1142 
1143  // Check the base classes.
1144  for (CXXRecordDecl::base_class_iterator Base1 = D1CXX->bases_begin(),
1145  BaseEnd1 = D1CXX->bases_end(),
1146  Base2 = D2CXX->bases_begin();
1147  Base1 != BaseEnd1;
1148  ++Base1, ++Base2) {
1149  if (!IsStructurallyEquivalent(Context,
1150  Base1->getType(), Base2->getType())) {
1151  if (Context.Complain) {
1152  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1153  << Context.C2.getTypeDeclType(D2);
1154  Context.Diag2(Base2->getLocStart(), diag::note_odr_base)
1155  << Base2->getType()
1156  << Base2->getSourceRange();
1157  Context.Diag1(Base1->getLocStart(), diag::note_odr_base)
1158  << Base1->getType()
1159  << Base1->getSourceRange();
1160  }
1161  return false;
1162  }
1163 
1164  // Check virtual vs. non-virtual inheritance mismatch.
1165  if (Base1->isVirtual() != Base2->isVirtual()) {
1166  if (Context.Complain) {
1167  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1168  << Context.C2.getTypeDeclType(D2);
1169  Context.Diag2(Base2->getLocStart(),
1170  diag::note_odr_virtual_base)
1171  << Base2->isVirtual() << Base2->getSourceRange();
1172  Context.Diag1(Base1->getLocStart(), diag::note_odr_base)
1173  << Base1->isVirtual()
1174  << Base1->getSourceRange();
1175  }
1176  return false;
1177  }
1178  }
1179  } else if (D1CXX->getNumBases() > 0) {
1180  if (Context.Complain) {
1181  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1182  << Context.C2.getTypeDeclType(D2);
1183  const CXXBaseSpecifier *Base1 = D1CXX->bases_begin();
1184  Context.Diag1(Base1->getLocStart(), diag::note_odr_base)
1185  << Base1->getType()
1186  << Base1->getSourceRange();
1187  Context.Diag2(D2->getLocation(), diag::note_odr_missing_base);
1188  }
1189  return false;
1190  }
1191  }
1192 
1193  // Check the fields for consistency.
1194  RecordDecl::field_iterator Field2 = D2->field_begin(),
1195  Field2End = D2->field_end();
1196  for (RecordDecl::field_iterator Field1 = D1->field_begin(),
1197  Field1End = D1->field_end();
1198  Field1 != Field1End;
1199  ++Field1, ++Field2) {
1200  if (Field2 == Field2End) {
1201  if (Context.Complain) {
1202  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1203  << Context.C2.getTypeDeclType(D2);
1204  Context.Diag1(Field1->getLocation(), diag::note_odr_field)
1205  << Field1->getDeclName() << Field1->getType();
1206  Context.Diag2(D2->getLocation(), diag::note_odr_missing_field);
1207  }
1208  return false;
1209  }
1210 
1211  if (!IsStructurallyEquivalent(Context, *Field1, *Field2))
1212  return false;
1213  }
1214 
1215  if (Field2 != Field2End) {
1216  if (Context.Complain) {
1217  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1218  << Context.C2.getTypeDeclType(D2);
1219  Context.Diag2(Field2->getLocation(), diag::note_odr_field)
1220  << Field2->getDeclName() << Field2->getType();
1221  Context.Diag1(D1->getLocation(), diag::note_odr_missing_field);
1222  }
1223  return false;
1224  }
1225 
1226  return true;
1227 }
1228 
1229 /// \brief Determine structural equivalence of two enums.
1230 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1231  EnumDecl *D1, EnumDecl *D2) {
1233  EC2End = D2->enumerator_end();
1235  EC1End = D1->enumerator_end();
1236  EC1 != EC1End; ++EC1, ++EC2) {
1237  if (EC2 == EC2End) {
1238  if (Context.Complain) {
1239  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1240  << Context.C2.getTypeDeclType(D2);
1241  Context.Diag1(EC1->getLocation(), diag::note_odr_enumerator)
1242  << EC1->getDeclName()
1243  << EC1->getInitVal().toString(10);
1244  Context.Diag2(D2->getLocation(), diag::note_odr_missing_enumerator);
1245  }
1246  return false;
1247  }
1248 
1249  llvm::APSInt Val1 = EC1->getInitVal();
1250  llvm::APSInt Val2 = EC2->getInitVal();
1251  if (!llvm::APSInt::isSameValue(Val1, Val2) ||
1252  !IsStructurallyEquivalent(EC1->getIdentifier(), EC2->getIdentifier())) {
1253  if (Context.Complain) {
1254  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1255  << Context.C2.getTypeDeclType(D2);
1256  Context.Diag2(EC2->getLocation(), diag::note_odr_enumerator)
1257  << EC2->getDeclName()
1258  << EC2->getInitVal().toString(10);
1259  Context.Diag1(EC1->getLocation(), diag::note_odr_enumerator)
1260  << EC1->getDeclName()
1261  << EC1->getInitVal().toString(10);
1262  }
1263  return false;
1264  }
1265  }
1266 
1267  if (EC2 != EC2End) {
1268  if (Context.Complain) {
1269  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1270  << Context.C2.getTypeDeclType(D2);
1271  Context.Diag2(EC2->getLocation(), diag::note_odr_enumerator)
1272  << EC2->getDeclName()
1273  << EC2->getInitVal().toString(10);
1274  Context.Diag1(D1->getLocation(), diag::note_odr_missing_enumerator);
1275  }
1276  return false;
1277  }
1278 
1279  return true;
1280 }
1281 
1282 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1283  TemplateParameterList *Params1,
1284  TemplateParameterList *Params2) {
1285  if (Params1->size() != Params2->size()) {
1286  if (Context.Complain) {
1287  Context.Diag2(Params2->getTemplateLoc(),
1288  diag::err_odr_different_num_template_parameters)
1289  << Params1->size() << Params2->size();
1290  Context.Diag1(Params1->getTemplateLoc(),
1291  diag::note_odr_template_parameter_list);
1292  }
1293  return false;
1294  }
1295 
1296  for (unsigned I = 0, N = Params1->size(); I != N; ++I) {
1297  if (Params1->getParam(I)->getKind() != Params2->getParam(I)->getKind()) {
1298  if (Context.Complain) {
1299  Context.Diag2(Params2->getParam(I)->getLocation(),
1300  diag::err_odr_different_template_parameter_kind);
1301  Context.Diag1(Params1->getParam(I)->getLocation(),
1302  diag::note_odr_template_parameter_here);
1303  }
1304  return false;
1305  }
1306 
1307  if (!Context.IsStructurallyEquivalent(Params1->getParam(I),
1308  Params2->getParam(I))) {
1309 
1310  return false;
1311  }
1312  }
1313 
1314  return true;
1315 }
1316 
1317 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1319  TemplateTypeParmDecl *D2) {
1320  if (D1->isParameterPack() != D2->isParameterPack()) {
1321  if (Context.Complain) {
1322  Context.Diag2(D2->getLocation(), diag::err_odr_parameter_pack_non_pack)
1323  << D2->isParameterPack();
1324  Context.Diag1(D1->getLocation(), diag::note_odr_parameter_pack_non_pack)
1325  << D1->isParameterPack();
1326  }
1327  return false;
1328  }
1329 
1330  return true;
1331 }
1332 
1333 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1336  if (D1->isParameterPack() != D2->isParameterPack()) {
1337  if (Context.Complain) {
1338  Context.Diag2(D2->getLocation(), diag::err_odr_parameter_pack_non_pack)
1339  << D2->isParameterPack();
1340  Context.Diag1(D1->getLocation(), diag::note_odr_parameter_pack_non_pack)
1341  << D1->isParameterPack();
1342  }
1343  return false;
1344  }
1345 
1346  // Check types.
1347  if (!Context.IsStructurallyEquivalent(D1->getType(), D2->getType())) {
1348  if (Context.Complain) {
1349  Context.Diag2(D2->getLocation(),
1350  diag::err_odr_non_type_parameter_type_inconsistent)
1351  << D2->getType() << D1->getType();
1352  Context.Diag1(D1->getLocation(), diag::note_odr_value_here)
1353  << D1->getType();
1354  }
1355  return false;
1356  }
1357 
1358  return true;
1359 }
1360 
1361 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1364  if (D1->isParameterPack() != D2->isParameterPack()) {
1365  if (Context.Complain) {
1366  Context.Diag2(D2->getLocation(), diag::err_odr_parameter_pack_non_pack)
1367  << D2->isParameterPack();
1368  Context.Diag1(D1->getLocation(), diag::note_odr_parameter_pack_non_pack)
1369  << D1->isParameterPack();
1370  }
1371  return false;
1372  }
1373 
1374  // Check template parameter lists.
1375  return IsStructurallyEquivalent(Context, D1->getTemplateParameters(),
1376  D2->getTemplateParameters());
1377 }
1378 
1379 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1380  ClassTemplateDecl *D1,
1381  ClassTemplateDecl *D2) {
1382  // Check template parameters.
1383  if (!IsStructurallyEquivalent(Context,
1384  D1->getTemplateParameters(),
1385  D2->getTemplateParameters()))
1386  return false;
1387 
1388  // Check the templated declaration.
1389  return Context.IsStructurallyEquivalent(D1->getTemplatedDecl(),
1390  D2->getTemplatedDecl());
1391 }
1392 
1393 /// \brief Determine structural equivalence of two declarations.
1394 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1395  Decl *D1, Decl *D2) {
1396  // FIXME: Check for known structural equivalences via a callback of some sort.
1397 
1398  // Check whether we already know that these two declarations are not
1399  // structurally equivalent.
1400  if (Context.NonEquivalentDecls.count(std::make_pair(D1->getCanonicalDecl(),
1401  D2->getCanonicalDecl())))
1402  return false;
1403 
1404  // Determine whether we've already produced a tentative equivalence for D1.
1405  Decl *&EquivToD1 = Context.TentativeEquivalences[D1->getCanonicalDecl()];
1406  if (EquivToD1)
1407  return EquivToD1 == D2->getCanonicalDecl();
1408 
1409  // Produce a tentative equivalence D1 <-> D2, which will be checked later.
1410  EquivToD1 = D2->getCanonicalDecl();
1411  Context.DeclsToCheck.push_back(D1->getCanonicalDecl());
1412  return true;
1413 }
1414 
1416  Decl *D2) {
1417  if (!::IsStructurallyEquivalent(*this, D1, D2))
1418  return false;
1419 
1420  return !Finish();
1421 }
1422 
1424  QualType T2) {
1425  if (!::IsStructurallyEquivalent(*this, T1, T2))
1426  return false;
1427 
1428  return !Finish();
1429 }
1430 
1431 bool StructuralEquivalenceContext::Finish() {
1432  while (!DeclsToCheck.empty()) {
1433  // Check the next declaration.
1434  Decl *D1 = DeclsToCheck.front();
1435  DeclsToCheck.pop_front();
1436 
1437  Decl *D2 = TentativeEquivalences[D1];
1438  assert(D2 && "Unrecorded tentative equivalence?");
1439 
1440  bool Equivalent = true;
1441 
1442  // FIXME: Switch on all declaration kinds. For now, we're just going to
1443  // check the obvious ones.
1444  if (RecordDecl *Record1 = dyn_cast<RecordDecl>(D1)) {
1445  if (RecordDecl *Record2 = dyn_cast<RecordDecl>(D2)) {
1446  // Check for equivalent structure names.
1447  IdentifierInfo *Name1 = Record1->getIdentifier();
1448  if (!Name1 && Record1->getTypedefNameForAnonDecl())
1449  Name1 = Record1->getTypedefNameForAnonDecl()->getIdentifier();
1450  IdentifierInfo *Name2 = Record2->getIdentifier();
1451  if (!Name2 && Record2->getTypedefNameForAnonDecl())
1452  Name2 = Record2->getTypedefNameForAnonDecl()->getIdentifier();
1453  if (!::IsStructurallyEquivalent(Name1, Name2) ||
1454  !::IsStructurallyEquivalent(*this, Record1, Record2))
1455  Equivalent = false;
1456  } else {
1457  // Record/non-record mismatch.
1458  Equivalent = false;
1459  }
1460  } else if (EnumDecl *Enum1 = dyn_cast<EnumDecl>(D1)) {
1461  if (EnumDecl *Enum2 = dyn_cast<EnumDecl>(D2)) {
1462  // Check for equivalent enum names.
1463  IdentifierInfo *Name1 = Enum1->getIdentifier();
1464  if (!Name1 && Enum1->getTypedefNameForAnonDecl())
1465  Name1 = Enum1->getTypedefNameForAnonDecl()->getIdentifier();
1466  IdentifierInfo *Name2 = Enum2->getIdentifier();
1467  if (!Name2 && Enum2->getTypedefNameForAnonDecl())
1468  Name2 = Enum2->getTypedefNameForAnonDecl()->getIdentifier();
1469  if (!::IsStructurallyEquivalent(Name1, Name2) ||
1470  !::IsStructurallyEquivalent(*this, Enum1, Enum2))
1471  Equivalent = false;
1472  } else {
1473  // Enum/non-enum mismatch
1474  Equivalent = false;
1475  }
1476  } else if (TypedefNameDecl *Typedef1 = dyn_cast<TypedefNameDecl>(D1)) {
1477  if (TypedefNameDecl *Typedef2 = dyn_cast<TypedefNameDecl>(D2)) {
1478  if (!::IsStructurallyEquivalent(Typedef1->getIdentifier(),
1479  Typedef2->getIdentifier()) ||
1480  !::IsStructurallyEquivalent(*this,
1481  Typedef1->getUnderlyingType(),
1482  Typedef2->getUnderlyingType()))
1483  Equivalent = false;
1484  } else {
1485  // Typedef/non-typedef mismatch.
1486  Equivalent = false;
1487  }
1488  } else if (ClassTemplateDecl *ClassTemplate1
1489  = dyn_cast<ClassTemplateDecl>(D1)) {
1490  if (ClassTemplateDecl *ClassTemplate2 = dyn_cast<ClassTemplateDecl>(D2)) {
1491  if (!::IsStructurallyEquivalent(ClassTemplate1->getIdentifier(),
1492  ClassTemplate2->getIdentifier()) ||
1493  !::IsStructurallyEquivalent(*this, ClassTemplate1, ClassTemplate2))
1494  Equivalent = false;
1495  } else {
1496  // Class template/non-class-template mismatch.
1497  Equivalent = false;
1498  }
1499  } else if (TemplateTypeParmDecl *TTP1= dyn_cast<TemplateTypeParmDecl>(D1)) {
1500  if (TemplateTypeParmDecl *TTP2 = dyn_cast<TemplateTypeParmDecl>(D2)) {
1501  if (!::IsStructurallyEquivalent(*this, TTP1, TTP2))
1502  Equivalent = false;
1503  } else {
1504  // Kind mismatch.
1505  Equivalent = false;
1506  }
1507  } else if (NonTypeTemplateParmDecl *NTTP1
1508  = dyn_cast<NonTypeTemplateParmDecl>(D1)) {
1509  if (NonTypeTemplateParmDecl *NTTP2
1510  = dyn_cast<NonTypeTemplateParmDecl>(D2)) {
1511  if (!::IsStructurallyEquivalent(*this, NTTP1, NTTP2))
1512  Equivalent = false;
1513  } else {
1514  // Kind mismatch.
1515  Equivalent = false;
1516  }
1517  } else if (TemplateTemplateParmDecl *TTP1
1518  = dyn_cast<TemplateTemplateParmDecl>(D1)) {
1519  if (TemplateTemplateParmDecl *TTP2
1520  = dyn_cast<TemplateTemplateParmDecl>(D2)) {
1521  if (!::IsStructurallyEquivalent(*this, TTP1, TTP2))
1522  Equivalent = false;
1523  } else {
1524  // Kind mismatch.
1525  Equivalent = false;
1526  }
1527  }
1528 
1529  if (!Equivalent) {
1530  // Note that these two declarations are not equivalent (and we already
1531  // know about it).
1532  NonEquivalentDecls.insert(std::make_pair(D1->getCanonicalDecl(),
1533  D2->getCanonicalDecl()));
1534  return true;
1535  }
1536  // FIXME: Check other declaration kinds!
1537  }
1538 
1539  return false;
1540 }
1541 
1542 //----------------------------------------------------------------------------
1543 // Import Types
1544 //----------------------------------------------------------------------------
1545 
1547  Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
1548  << T->getTypeClassName();
1549  return QualType();
1550 }
1551 
1553  switch (T->getKind()) {
1554 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1555  case BuiltinType::Id: \
1556  return Importer.getToContext().SingletonId;
1557 #include "clang/Basic/OpenCLImageTypes.def"
1558 #define SHARED_SINGLETON_TYPE(Expansion)
1559 #define BUILTIN_TYPE(Id, SingletonId) \
1560  case BuiltinType::Id: return Importer.getToContext().SingletonId;
1561 #include "clang/AST/BuiltinTypes.def"
1562 
1563  // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
1564  // context supports C++.
1565 
1566  // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
1567  // context supports ObjC.
1568 
1569  case BuiltinType::Char_U:
1570  // The context we're importing from has an unsigned 'char'. If we're
1571  // importing into a context with a signed 'char', translate to
1572  // 'unsigned char' instead.
1573  if (Importer.getToContext().getLangOpts().CharIsSigned)
1574  return Importer.getToContext().UnsignedCharTy;
1575 
1576  return Importer.getToContext().CharTy;
1577 
1578  case BuiltinType::Char_S:
1579  // The context we're importing from has an unsigned 'char'. If we're
1580  // importing into a context with a signed 'char', translate to
1581  // 'unsigned char' instead.
1582  if (!Importer.getToContext().getLangOpts().CharIsSigned)
1583  return Importer.getToContext().SignedCharTy;
1584 
1585  return Importer.getToContext().CharTy;
1586 
1587  case BuiltinType::WChar_S:
1588  case BuiltinType::WChar_U:
1589  // FIXME: If not in C++, shall we translate to the C equivalent of
1590  // wchar_t?
1591  return Importer.getToContext().WCharTy;
1592  }
1593 
1594  llvm_unreachable("Invalid BuiltinType Kind!");
1595 }
1596 
1598  QualType ToElementType = Importer.Import(T->getElementType());
1599  if (ToElementType.isNull())
1600  return QualType();
1601 
1602  return Importer.getToContext().getComplexType(ToElementType);
1603 }
1604 
1606  QualType ToPointeeType = Importer.Import(T->getPointeeType());
1607  if (ToPointeeType.isNull())
1608  return QualType();
1609 
1610  return Importer.getToContext().getPointerType(ToPointeeType);
1611 }
1612 
1614  // FIXME: Check for blocks support in "to" context.
1615  QualType ToPointeeType = Importer.Import(T->getPointeeType());
1616  if (ToPointeeType.isNull())
1617  return QualType();
1618 
1619  return Importer.getToContext().getBlockPointerType(ToPointeeType);
1620 }
1621 
1622 QualType
1624  // FIXME: Check for C++ support in "to" context.
1625  QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten());
1626  if (ToPointeeType.isNull())
1627  return QualType();
1628 
1629  return Importer.getToContext().getLValueReferenceType(ToPointeeType);
1630 }
1631 
1632 QualType
1634  // FIXME: Check for C++0x support in "to" context.
1635  QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten());
1636  if (ToPointeeType.isNull())
1637  return QualType();
1638 
1639  return Importer.getToContext().getRValueReferenceType(ToPointeeType);
1640 }
1641 
1643  // FIXME: Check for C++ support in "to" context.
1644  QualType ToPointeeType = Importer.Import(T->getPointeeType());
1645  if (ToPointeeType.isNull())
1646  return QualType();
1647 
1648  QualType ClassType = Importer.Import(QualType(T->getClass(), 0));
1649  return Importer.getToContext().getMemberPointerType(ToPointeeType,
1650  ClassType.getTypePtr());
1651 }
1652 
1654  QualType ToElementType = Importer.Import(T->getElementType());
1655  if (ToElementType.isNull())
1656  return QualType();
1657 
1658  return Importer.getToContext().getConstantArrayType(ToElementType,
1659  T->getSize(),
1660  T->getSizeModifier(),
1662 }
1663 
1664 QualType
1666  QualType ToElementType = Importer.Import(T->getElementType());
1667  if (ToElementType.isNull())
1668  return QualType();
1669 
1670  return Importer.getToContext().getIncompleteArrayType(ToElementType,
1671  T->getSizeModifier(),
1673 }
1674 
1676  QualType ToElementType = Importer.Import(T->getElementType());
1677  if (ToElementType.isNull())
1678  return QualType();
1679 
1680  Expr *Size = Importer.Import(T->getSizeExpr());
1681  if (!Size)
1682  return QualType();
1683 
1684  SourceRange Brackets = Importer.Import(T->getBracketsRange());
1685  return Importer.getToContext().getVariableArrayType(ToElementType, Size,
1686  T->getSizeModifier(),
1688  Brackets);
1689 }
1690 
1692  QualType ToElementType = Importer.Import(T->getElementType());
1693  if (ToElementType.isNull())
1694  return QualType();
1695 
1696  return Importer.getToContext().getVectorType(ToElementType,
1697  T->getNumElements(),
1698  T->getVectorKind());
1699 }
1700 
1702  QualType ToElementType = Importer.Import(T->getElementType());
1703  if (ToElementType.isNull())
1704  return QualType();
1705 
1706  return Importer.getToContext().getExtVectorType(ToElementType,
1707  T->getNumElements());
1708 }
1709 
1710 QualType
1712  // FIXME: What happens if we're importing a function without a prototype
1713  // into C++? Should we make it variadic?
1714  QualType ToResultType = Importer.Import(T->getReturnType());
1715  if (ToResultType.isNull())
1716  return QualType();
1717 
1718  return Importer.getToContext().getFunctionNoProtoType(ToResultType,
1719  T->getExtInfo());
1720 }
1721 
1723  QualType ToResultType = Importer.Import(T->getReturnType());
1724  if (ToResultType.isNull())
1725  return QualType();
1726 
1727  // Import argument types
1728  SmallVector<QualType, 4> ArgTypes;
1729  for (const auto &A : T->param_types()) {
1730  QualType ArgType = Importer.Import(A);
1731  if (ArgType.isNull())
1732  return QualType();
1733  ArgTypes.push_back(ArgType);
1734  }
1735 
1736  // Import exception types
1737  SmallVector<QualType, 4> ExceptionTypes;
1738  for (const auto &E : T->exceptions()) {
1739  QualType ExceptionType = Importer.Import(E);
1740  if (ExceptionType.isNull())
1741  return QualType();
1742  ExceptionTypes.push_back(ExceptionType);
1743  }
1744 
1747 
1748  ToEPI.ExtInfo = FromEPI.ExtInfo;
1749  ToEPI.Variadic = FromEPI.Variadic;
1750  ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
1751  ToEPI.TypeQuals = FromEPI.TypeQuals;
1752  ToEPI.RefQualifier = FromEPI.RefQualifier;
1753  ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
1754  ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
1755  ToEPI.ExceptionSpec.NoexceptExpr =
1756  Importer.Import(FromEPI.ExceptionSpec.NoexceptExpr);
1757  ToEPI.ExceptionSpec.SourceDecl = cast_or_null<FunctionDecl>(
1758  Importer.Import(FromEPI.ExceptionSpec.SourceDecl));
1759  ToEPI.ExceptionSpec.SourceTemplate = cast_or_null<FunctionDecl>(
1760  Importer.Import(FromEPI.ExceptionSpec.SourceTemplate));
1761 
1762  return Importer.getToContext().getFunctionType(ToResultType, ArgTypes, ToEPI);
1763 }
1764 
1766  QualType ToInnerType = Importer.Import(T->getInnerType());
1767  if (ToInnerType.isNull())
1768  return QualType();
1769 
1770  return Importer.getToContext().getParenType(ToInnerType);
1771 }
1772 
1774  TypedefNameDecl *ToDecl
1775  = dyn_cast_or_null<TypedefNameDecl>(Importer.Import(T->getDecl()));
1776  if (!ToDecl)
1777  return QualType();
1778 
1779  return Importer.getToContext().getTypeDeclType(ToDecl);
1780 }
1781 
1783  Expr *ToExpr = Importer.Import(T->getUnderlyingExpr());
1784  if (!ToExpr)
1785  return QualType();
1786 
1787  return Importer.getToContext().getTypeOfExprType(ToExpr);
1788 }
1789 
1791  QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType());
1792  if (ToUnderlyingType.isNull())
1793  return QualType();
1794 
1795  return Importer.getToContext().getTypeOfType(ToUnderlyingType);
1796 }
1797 
1799  // FIXME: Make sure that the "to" context supports C++0x!
1800  Expr *ToExpr = Importer.Import(T->getUnderlyingExpr());
1801  if (!ToExpr)
1802  return QualType();
1803 
1804  QualType UnderlyingType = Importer.Import(T->getUnderlyingType());
1805  if (UnderlyingType.isNull())
1806  return QualType();
1807 
1808  return Importer.getToContext().getDecltypeType(ToExpr, UnderlyingType);
1809 }
1810 
1812  QualType ToBaseType = Importer.Import(T->getBaseType());
1813  QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType());
1814  if (ToBaseType.isNull() || ToUnderlyingType.isNull())
1815  return QualType();
1816 
1817  return Importer.getToContext().getUnaryTransformType(ToBaseType,
1818  ToUnderlyingType,
1819  T->getUTTKind());
1820 }
1821 
1823  // FIXME: Make sure that the "to" context supports C++11!
1824  QualType FromDeduced = T->getDeducedType();
1825  QualType ToDeduced;
1826  if (!FromDeduced.isNull()) {
1827  ToDeduced = Importer.Import(FromDeduced);
1828  if (ToDeduced.isNull())
1829  return QualType();
1830  }
1831 
1832  return Importer.getToContext().getAutoType(ToDeduced, T->getKeyword(),
1833  /*IsDependent*/false);
1834 }
1835 
1837  const InjectedClassNameType *T) {
1838  CXXRecordDecl *D = cast_or_null<CXXRecordDecl>(Importer.Import(T->getDecl()));
1839  if (!D)
1840  return QualType();
1841 
1842  QualType InjType = Importer.Import(T->getInjectedSpecializationType());
1843  if (InjType.isNull())
1844  return QualType();
1845 
1846  // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading
1847  // See comments in InjectedClassNameType definition for details
1848  // return Importer.getToContext().getInjectedClassNameType(D, InjType);
1849  enum {
1850  TypeAlignmentInBits = 4,
1852  };
1853 
1854  return QualType(new (Importer.getToContext(), TypeAlignment)
1855  InjectedClassNameType(D, InjType), 0);
1856 }
1857 
1859  RecordDecl *ToDecl
1860  = dyn_cast_or_null<RecordDecl>(Importer.Import(T->getDecl()));
1861  if (!ToDecl)
1862  return QualType();
1863 
1864  return Importer.getToContext().getTagDeclType(ToDecl);
1865 }
1866 
1868  EnumDecl *ToDecl
1869  = dyn_cast_or_null<EnumDecl>(Importer.Import(T->getDecl()));
1870  if (!ToDecl)
1871  return QualType();
1872 
1873  return Importer.getToContext().getTagDeclType(ToDecl);
1874 }
1875 
1877  QualType FromModifiedType = T->getModifiedType();
1878  QualType FromEquivalentType = T->getEquivalentType();
1879  QualType ToModifiedType;
1880  QualType ToEquivalentType;
1881 
1882  if (!FromModifiedType.isNull()) {
1883  ToModifiedType = Importer.Import(FromModifiedType);
1884  if (ToModifiedType.isNull())
1885  return QualType();
1886  }
1887  if (!FromEquivalentType.isNull()) {
1888  ToEquivalentType = Importer.Import(FromEquivalentType);
1889  if (ToEquivalentType.isNull())
1890  return QualType();
1891  }
1892 
1893  return Importer.getToContext().getAttributedType(T->getAttrKind(),
1894  ToModifiedType, ToEquivalentType);
1895 }
1896 
1897 
1899  const TemplateTypeParmType *T) {
1900  TemplateTypeParmDecl *ParmDecl =
1901  cast_or_null<TemplateTypeParmDecl>(Importer.Import(T->getDecl()));
1902  if (!ParmDecl && T->getDecl())
1903  return QualType();
1904 
1905  return Importer.getToContext().getTemplateTypeParmType(
1906  T->getDepth(), T->getIndex(), T->isParameterPack(), ParmDecl);
1907 }
1908 
1910  const TemplateSpecializationType *T) {
1911  TemplateName ToTemplate = Importer.Import(T->getTemplateName());
1912  if (ToTemplate.isNull())
1913  return QualType();
1914 
1915  SmallVector<TemplateArgument, 2> ToTemplateArgs;
1916  if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToTemplateArgs))
1917  return QualType();
1918 
1919  QualType ToCanonType;
1920  if (!QualType(T, 0).isCanonical()) {
1921  QualType FromCanonType
1922  = Importer.getFromContext().getCanonicalType(QualType(T, 0));
1923  ToCanonType =Importer.Import(FromCanonType);
1924  if (ToCanonType.isNull())
1925  return QualType();
1926  }
1927  return Importer.getToContext().getTemplateSpecializationType(ToTemplate,
1928  ToTemplateArgs,
1929  ToCanonType);
1930 }
1931 
1933  NestedNameSpecifier *ToQualifier = nullptr;
1934  // Note: the qualifier in an ElaboratedType is optional.
1935  if (T->getQualifier()) {
1936  ToQualifier = Importer.Import(T->getQualifier());
1937  if (!ToQualifier)
1938  return QualType();
1939  }
1940 
1941  QualType ToNamedType = Importer.Import(T->getNamedType());
1942  if (ToNamedType.isNull())
1943  return QualType();
1944 
1945  return Importer.getToContext().getElaboratedType(T->getKeyword(),
1946  ToQualifier, ToNamedType);
1947 }
1948 
1950  ObjCInterfaceDecl *Class
1951  = dyn_cast_or_null<ObjCInterfaceDecl>(Importer.Import(T->getDecl()));
1952  if (!Class)
1953  return QualType();
1954 
1955  return Importer.getToContext().getObjCInterfaceType(Class);
1956 }
1957 
1959  QualType ToBaseType = Importer.Import(T->getBaseType());
1960  if (ToBaseType.isNull())
1961  return QualType();
1962 
1963  SmallVector<QualType, 4> TypeArgs;
1964  for (auto TypeArg : T->getTypeArgsAsWritten()) {
1965  QualType ImportedTypeArg = Importer.Import(TypeArg);
1966  if (ImportedTypeArg.isNull())
1967  return QualType();
1968 
1969  TypeArgs.push_back(ImportedTypeArg);
1970  }
1971 
1973  for (auto *P : T->quals()) {
1974  ObjCProtocolDecl *Protocol
1975  = dyn_cast_or_null<ObjCProtocolDecl>(Importer.Import(P));
1976  if (!Protocol)
1977  return QualType();
1978  Protocols.push_back(Protocol);
1979  }
1980 
1981  return Importer.getToContext().getObjCObjectType(ToBaseType, TypeArgs,
1982  Protocols,
1983  T->isKindOfTypeAsWritten());
1984 }
1985 
1986 QualType
1988  QualType ToPointeeType = Importer.Import(T->getPointeeType());
1989  if (ToPointeeType.isNull())
1990  return QualType();
1991 
1992  return Importer.getToContext().getObjCObjectPointerType(ToPointeeType);
1993 }
1994 
1995 //----------------------------------------------------------------------------
1996 // Import Declarations
1997 //----------------------------------------------------------------------------
1999  DeclContext *&LexicalDC,
2001  NamedDecl *&ToD,
2002  SourceLocation &Loc) {
2003  // Import the context of this declaration.
2004  DC = Importer.ImportContext(D->getDeclContext());
2005  if (!DC)
2006  return true;
2007 
2008  LexicalDC = DC;
2009  if (D->getDeclContext() != D->getLexicalDeclContext()) {
2010  LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
2011  if (!LexicalDC)
2012  return true;
2013  }
2014 
2015  // Import the name of this declaration.
2016  Name = Importer.Import(D->getDeclName());
2017  if (D->getDeclName() && !Name)
2018  return true;
2019 
2020  // Import the location of this declaration.
2021  Loc = Importer.Import(D->getLocation());
2022  ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2023  return false;
2024 }
2025 
2027  if (!FromD)
2028  return;
2029 
2030  if (!ToD) {
2031  ToD = Importer.Import(FromD);
2032  if (!ToD)
2033  return;
2034  }
2035 
2036  if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
2037  if (RecordDecl *ToRecord = cast_or_null<RecordDecl>(ToD)) {
2038  if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && !ToRecord->getDefinition()) {
2039  ImportDefinition(FromRecord, ToRecord);
2040  }
2041  }
2042  return;
2043  }
2044 
2045  if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
2046  if (EnumDecl *ToEnum = cast_or_null<EnumDecl>(ToD)) {
2047  if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
2048  ImportDefinition(FromEnum, ToEnum);
2049  }
2050  }
2051  return;
2052  }
2053 }
2054 
2055 void
2057  DeclarationNameInfo& To) {
2058  // NOTE: To.Name and To.Loc are already imported.
2059  // We only have to import To.LocInfo.
2060  switch (To.getName().getNameKind()) {
2066  return;
2067 
2069  SourceRange Range = From.getCXXOperatorNameRange();
2070  To.setCXXOperatorNameRange(Importer.Import(Range));
2071  return;
2072  }
2075  To.setCXXLiteralOperatorNameLoc(Importer.Import(Loc));
2076  return;
2077  }
2081  TypeSourceInfo *FromTInfo = From.getNamedTypeInfo();
2082  To.setNamedTypeInfo(Importer.Import(FromTInfo));
2083  return;
2084  }
2085  }
2086  llvm_unreachable("Unknown name kind.");
2087 }
2088 
2089 void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) {
2090  if (Importer.isMinimalImport() && !ForceImport) {
2091  Importer.ImportContext(FromDC);
2092  return;
2093  }
2094 
2095  for (auto *From : FromDC->decls())
2096  Importer.Import(From);
2097 }
2098 
2101  if (To->getDefinition() || To->isBeingDefined()) {
2102  if (Kind == IDK_Everything)
2103  ImportDeclContext(From, /*ForceImport=*/true);
2104 
2105  return false;
2106  }
2107 
2108  To->startDefinition();
2109 
2110  // Add base classes.
2111  if (CXXRecordDecl *ToCXX = dyn_cast<CXXRecordDecl>(To)) {
2112  CXXRecordDecl *FromCXX = cast<CXXRecordDecl>(From);
2113 
2114  struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
2115  struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2116  ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor;
2117  ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers;
2118  ToData.Aggregate = FromData.Aggregate;
2119  ToData.PlainOldData = FromData.PlainOldData;
2120  ToData.Empty = FromData.Empty;
2121  ToData.Polymorphic = FromData.Polymorphic;
2122  ToData.Abstract = FromData.Abstract;
2123  ToData.IsStandardLayout = FromData.IsStandardLayout;
2124  ToData.HasNoNonEmptyBases = FromData.HasNoNonEmptyBases;
2125  ToData.HasPrivateFields = FromData.HasPrivateFields;
2126  ToData.HasProtectedFields = FromData.HasProtectedFields;
2127  ToData.HasPublicFields = FromData.HasPublicFields;
2128  ToData.HasMutableFields = FromData.HasMutableFields;
2129  ToData.HasVariantMembers = FromData.HasVariantMembers;
2130  ToData.HasOnlyCMembers = FromData.HasOnlyCMembers;
2131  ToData.HasInClassInitializer = FromData.HasInClassInitializer;
2132  ToData.HasUninitializedReferenceMember
2133  = FromData.HasUninitializedReferenceMember;
2134  ToData.HasUninitializedFields = FromData.HasUninitializedFields;
2135  ToData.HasInheritedConstructor = FromData.HasInheritedConstructor;
2136  ToData.HasInheritedAssignment = FromData.HasInheritedAssignment;
2137  ToData.NeedOverloadResolutionForMoveConstructor
2138  = FromData.NeedOverloadResolutionForMoveConstructor;
2139  ToData.NeedOverloadResolutionForMoveAssignment
2140  = FromData.NeedOverloadResolutionForMoveAssignment;
2141  ToData.NeedOverloadResolutionForDestructor
2142  = FromData.NeedOverloadResolutionForDestructor;
2143  ToData.DefaultedMoveConstructorIsDeleted
2144  = FromData.DefaultedMoveConstructorIsDeleted;
2145  ToData.DefaultedMoveAssignmentIsDeleted
2146  = FromData.DefaultedMoveAssignmentIsDeleted;
2147  ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted;
2148  ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers;
2149  ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor;
2150  ToData.HasConstexprNonCopyMoveConstructor
2151  = FromData.HasConstexprNonCopyMoveConstructor;
2152  ToData.HasDefaultedDefaultConstructor
2153  = FromData.HasDefaultedDefaultConstructor;
2154  ToData.DefaultedDefaultConstructorIsConstexpr
2155  = FromData.DefaultedDefaultConstructorIsConstexpr;
2156  ToData.HasConstexprDefaultConstructor
2157  = FromData.HasConstexprDefaultConstructor;
2158  ToData.HasNonLiteralTypeFieldsOrBases
2159  = FromData.HasNonLiteralTypeFieldsOrBases;
2160  // ComputedVisibleConversions not imported.
2161  ToData.UserProvidedDefaultConstructor
2162  = FromData.UserProvidedDefaultConstructor;
2163  ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers;
2164  ToData.ImplicitCopyConstructorHasConstParam
2165  = FromData.ImplicitCopyConstructorHasConstParam;
2166  ToData.ImplicitCopyAssignmentHasConstParam
2167  = FromData.ImplicitCopyAssignmentHasConstParam;
2168  ToData.HasDeclaredCopyConstructorWithConstParam
2169  = FromData.HasDeclaredCopyConstructorWithConstParam;
2170  ToData.HasDeclaredCopyAssignmentWithConstParam
2171  = FromData.HasDeclaredCopyAssignmentWithConstParam;
2172  ToData.IsLambda = FromData.IsLambda;
2173 
2175  for (const auto &Base1 : FromCXX->bases()) {
2176  QualType T = Importer.Import(Base1.getType());
2177  if (T.isNull())
2178  return true;
2179 
2180  SourceLocation EllipsisLoc;
2181  if (Base1.isPackExpansion())
2182  EllipsisLoc = Importer.Import(Base1.getEllipsisLoc());
2183 
2184  // Ensure that we have a definition for the base.
2185  ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl());
2186 
2187  Bases.push_back(
2188  new (Importer.getToContext())
2189  CXXBaseSpecifier(Importer.Import(Base1.getSourceRange()),
2190  Base1.isVirtual(),
2191  Base1.isBaseOfClass(),
2192  Base1.getAccessSpecifierAsWritten(),
2193  Importer.Import(Base1.getTypeSourceInfo()),
2194  EllipsisLoc));
2195  }
2196  if (!Bases.empty())
2197  ToCXX->setBases(Bases.data(), Bases.size());
2198  }
2199 
2200  if (shouldForceImportDeclContext(Kind))
2201  ImportDeclContext(From, /*ForceImport=*/true);
2202 
2203  To->completeDefinition();
2204  return false;
2205 }
2206 
2209  if (To->getAnyInitializer())
2210  return false;
2211 
2212  // FIXME: Can we really import any initializer? Alternatively, we could force
2213  // ourselves to import every declaration of a variable and then only use
2214  // getInit() here.
2215  To->setInit(Importer.Import(const_cast<Expr *>(From->getAnyInitializer())));
2216 
2217  // FIXME: Other bits to merge?
2218 
2219  return false;
2220 }
2221 
2224  if (To->getDefinition() || To->isBeingDefined()) {
2225  if (Kind == IDK_Everything)
2226  ImportDeclContext(From, /*ForceImport=*/true);
2227  return false;
2228  }
2229 
2230  To->startDefinition();
2231 
2232  QualType T = Importer.Import(Importer.getFromContext().getTypeDeclType(From));
2233  if (T.isNull())
2234  return true;
2235 
2236  QualType ToPromotionType = Importer.Import(From->getPromotionType());
2237  if (ToPromotionType.isNull())
2238  return true;
2239 
2240  if (shouldForceImportDeclContext(Kind))
2241  ImportDeclContext(From, /*ForceImport=*/true);
2242 
2243  // FIXME: we might need to merge the number of positive or negative bits
2244  // if the enumerator lists don't match.
2245  To->completeDefinition(T, ToPromotionType,
2246  From->getNumPositiveBits(),
2247  From->getNumNegativeBits());
2248  return false;
2249 }
2250 
2252  TemplateParameterList *Params) {
2253  SmallVector<NamedDecl *, 4> ToParams;
2254  ToParams.reserve(Params->size());
2255  for (TemplateParameterList::iterator P = Params->begin(),
2256  PEnd = Params->end();
2257  P != PEnd; ++P) {
2258  Decl *To = Importer.Import(*P);
2259  if (!To)
2260  return nullptr;
2261 
2262  ToParams.push_back(cast<NamedDecl>(To));
2263  }
2264 
2265  return TemplateParameterList::Create(Importer.getToContext(),
2266  Importer.Import(Params->getTemplateLoc()),
2267  Importer.Import(Params->getLAngleLoc()),
2268  ToParams,
2269  Importer.Import(Params->getRAngleLoc()));
2270 }
2271 
2274  switch (From.getKind()) {
2276  return TemplateArgument();
2277 
2278  case TemplateArgument::Type: {
2279  QualType ToType = Importer.Import(From.getAsType());
2280  if (ToType.isNull())
2281  return TemplateArgument();
2282  return TemplateArgument(ToType);
2283  }
2284 
2286  QualType ToType = Importer.Import(From.getIntegralType());
2287  if (ToType.isNull())
2288  return TemplateArgument();
2289  return TemplateArgument(From, ToType);
2290  }
2291 
2293  ValueDecl *To = cast_or_null<ValueDecl>(Importer.Import(From.getAsDecl()));
2294  QualType ToType = Importer.Import(From.getParamTypeForDecl());
2295  if (!To || ToType.isNull())
2296  return TemplateArgument();
2297  return TemplateArgument(To, ToType);
2298  }
2299 
2301  QualType ToType = Importer.Import(From.getNullPtrType());
2302  if (ToType.isNull())
2303  return TemplateArgument();
2304  return TemplateArgument(ToType, /*isNullPtr*/true);
2305  }
2306 
2308  TemplateName ToTemplate = Importer.Import(From.getAsTemplate());
2309  if (ToTemplate.isNull())
2310  return TemplateArgument();
2311 
2312  return TemplateArgument(ToTemplate);
2313  }
2314 
2316  TemplateName ToTemplate
2317  = Importer.Import(From.getAsTemplateOrTemplatePattern());
2318  if (ToTemplate.isNull())
2319  return TemplateArgument();
2320 
2321  return TemplateArgument(ToTemplate, From.getNumTemplateExpansions());
2322  }
2323 
2325  if (Expr *ToExpr = Importer.Import(From.getAsExpr()))
2326  return TemplateArgument(ToExpr);
2327  return TemplateArgument();
2328 
2329  case TemplateArgument::Pack: {
2331  ToPack.reserve(From.pack_size());
2332  if (ImportTemplateArguments(From.pack_begin(), From.pack_size(), ToPack))
2333  return TemplateArgument();
2334 
2335  return TemplateArgument(
2336  llvm::makeArrayRef(ToPack).copy(Importer.getToContext()));
2337  }
2338  }
2339 
2340  llvm_unreachable("Invalid template argument kind");
2341 }
2342 
2344  unsigned NumFromArgs,
2346  for (unsigned I = 0; I != NumFromArgs; ++I) {
2347  TemplateArgument To = ImportTemplateArgument(FromArgs[I]);
2348  if (To.isNull() && !FromArgs[I].isNull())
2349  return true;
2350 
2351  ToArgs.push_back(To);
2352  }
2353 
2354  return false;
2355 }
2356 
2358  RecordDecl *ToRecord, bool Complain) {
2359  // Eliminate a potential failure point where we attempt to re-import
2360  // something we're trying to import while completing ToRecord.
2361  Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord);
2362  if (ToOrigin) {
2363  RecordDecl *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin);
2364  if (ToOriginRecord)
2365  ToRecord = ToOriginRecord;
2366  }
2367 
2368  StructuralEquivalenceContext Ctx(Importer.getFromContext(),
2369  ToRecord->getASTContext(),
2370  Importer.getNonEquivalentDecls(),
2371  false, Complain);
2372  return Ctx.IsStructurallyEquivalent(FromRecord, ToRecord);
2373 }
2374 
2376  bool Complain) {
2377  StructuralEquivalenceContext Ctx(
2378  Importer.getFromContext(), Importer.getToContext(),
2379  Importer.getNonEquivalentDecls(), false, Complain);
2380  return Ctx.IsStructurallyEquivalent(FromVar, ToVar);
2381 }
2382 
2384  StructuralEquivalenceContext Ctx(Importer.getFromContext(),
2385  Importer.getToContext(),
2386  Importer.getNonEquivalentDecls());
2387  return Ctx.IsStructurallyEquivalent(FromEnum, ToEnum);
2388 }
2389 
2391  EnumConstantDecl *ToEC)
2392 {
2393  const llvm::APSInt &FromVal = FromEC->getInitVal();
2394  const llvm::APSInt &ToVal = ToEC->getInitVal();
2395 
2396  return FromVal.isSigned() == ToVal.isSigned() &&
2397  FromVal.getBitWidth() == ToVal.getBitWidth() &&
2398  FromVal == ToVal;
2399 }
2400 
2402  ClassTemplateDecl *To) {
2403  StructuralEquivalenceContext Ctx(Importer.getFromContext(),
2404  Importer.getToContext(),
2405  Importer.getNonEquivalentDecls());
2406  return Ctx.IsStructurallyEquivalent(From, To);
2407 }
2408 
2410  VarTemplateDecl *To) {
2411  StructuralEquivalenceContext Ctx(Importer.getFromContext(),
2412  Importer.getToContext(),
2413  Importer.getNonEquivalentDecls());
2414  return Ctx.IsStructurallyEquivalent(From, To);
2415 }
2416 
2418  Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2419  << D->getDeclKindName();
2420  return nullptr;
2421 }
2422 
2424  TranslationUnitDecl *ToD =
2425  Importer.getToContext().getTranslationUnitDecl();
2426 
2427  Importer.Imported(D, ToD);
2428 
2429  return ToD;
2430 }
2431 
2433 
2434  SourceLocation Loc = Importer.Import(D->getLocation());
2435  SourceLocation ColonLoc = Importer.Import(D->getColonLoc());
2436 
2437  // Import the context of this declaration.
2438  DeclContext *DC = Importer.ImportContext(D->getDeclContext());
2439  if (!DC)
2440  return nullptr;
2441 
2443  = AccessSpecDecl::Create(Importer.getToContext(), D->getAccess(),
2444  DC, Loc, ColonLoc);
2445 
2446  if (!accessSpecDecl)
2447  return nullptr;
2448 
2449  // Lexical DeclContext and Semantic DeclContext
2450  // is always the same for the accessSpec.
2451  accessSpecDecl->setLexicalDeclContext(DC);
2452  DC->addDeclInternal(accessSpecDecl);
2453 
2454  return accessSpecDecl;
2455 }
2456 
2458  // Import the major distinguishing characteristics of this namespace.
2459  DeclContext *DC, *LexicalDC;
2461  SourceLocation Loc;
2462  NamedDecl *ToD;
2463  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2464  return nullptr;
2465  if (ToD)
2466  return ToD;
2467 
2468  NamespaceDecl *MergeWithNamespace = nullptr;
2469  if (!Name) {
2470  // This is an anonymous namespace. Adopt an existing anonymous
2471  // namespace if we can.
2472  // FIXME: Not testable.
2473  if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(DC))
2474  MergeWithNamespace = TU->getAnonymousNamespace();
2475  else
2476  MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace();
2477  } else {
2478  SmallVector<NamedDecl *, 4> ConflictingDecls;
2479  SmallVector<NamedDecl *, 2> FoundDecls;
2480  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
2481  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
2482  if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Namespace))
2483  continue;
2484 
2485  if (NamespaceDecl *FoundNS = dyn_cast<NamespaceDecl>(FoundDecls[I])) {
2486  MergeWithNamespace = FoundNS;
2487  ConflictingDecls.clear();
2488  break;
2489  }
2490 
2491  ConflictingDecls.push_back(FoundDecls[I]);
2492  }
2493 
2494  if (!ConflictingDecls.empty()) {
2495  Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace,
2496  ConflictingDecls.data(),
2497  ConflictingDecls.size());
2498  }
2499  }
2500 
2501  // Create the "to" namespace, if needed.
2502  NamespaceDecl *ToNamespace = MergeWithNamespace;
2503  if (!ToNamespace) {
2504  ToNamespace = NamespaceDecl::Create(Importer.getToContext(), DC,
2505  D->isInline(),
2506  Importer.Import(D->getLocStart()),
2507  Loc, Name.getAsIdentifierInfo(),
2508  /*PrevDecl=*/nullptr);
2509  ToNamespace->setLexicalDeclContext(LexicalDC);
2510  LexicalDC->addDeclInternal(ToNamespace);
2511 
2512  // If this is an anonymous namespace, register it as the anonymous
2513  // namespace within its context.
2514  if (!Name) {
2515  if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(DC))
2516  TU->setAnonymousNamespace(ToNamespace);
2517  else
2518  cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
2519  }
2520  }
2521  Importer.Imported(D, ToNamespace);
2522 
2523  ImportDeclContext(D);
2524 
2525  return ToNamespace;
2526 }
2527 
2529  // Import the major distinguishing characteristics of this typedef.
2530  DeclContext *DC, *LexicalDC;
2532  SourceLocation Loc;
2533  NamedDecl *ToD;
2534  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2535  return nullptr;
2536  if (ToD)
2537  return ToD;
2538 
2539  // If this typedef is not in block scope, determine whether we've
2540  // seen a typedef with the same name (that we can merge with) or any
2541  // other entity by that name (which name lookup could conflict with).
2542  if (!DC->isFunctionOrMethod()) {
2543  SmallVector<NamedDecl *, 4> ConflictingDecls;
2544  unsigned IDNS = Decl::IDNS_Ordinary;
2545  SmallVector<NamedDecl *, 2> FoundDecls;
2546  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
2547  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
2548  if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
2549  continue;
2550  if (TypedefNameDecl *FoundTypedef =
2551  dyn_cast<TypedefNameDecl>(FoundDecls[I])) {
2552  if (Importer.IsStructurallyEquivalent(D->getUnderlyingType(),
2553  FoundTypedef->getUnderlyingType()))
2554  return Importer.Imported(D, FoundTypedef);
2555  }
2556 
2557  ConflictingDecls.push_back(FoundDecls[I]);
2558  }
2559 
2560  if (!ConflictingDecls.empty()) {
2561  Name = Importer.HandleNameConflict(Name, DC, IDNS,
2562  ConflictingDecls.data(),
2563  ConflictingDecls.size());
2564  if (!Name)
2565  return nullptr;
2566  }
2567  }
2568 
2569  // Import the underlying type of this typedef;
2570  QualType T = Importer.Import(D->getUnderlyingType());
2571  if (T.isNull())
2572  return nullptr;
2573 
2574  // Create the new typedef node.
2575  TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
2576  SourceLocation StartL = Importer.Import(D->getLocStart());
2577  TypedefNameDecl *ToTypedef;
2578  if (IsAlias)
2579  ToTypedef = TypeAliasDecl::Create(Importer.getToContext(), DC,
2580  StartL, Loc,
2581  Name.getAsIdentifierInfo(),
2582  TInfo);
2583  else
2584  ToTypedef = TypedefDecl::Create(Importer.getToContext(), DC,
2585  StartL, Loc,
2586  Name.getAsIdentifierInfo(),
2587  TInfo);
2588 
2589  ToTypedef->setAccess(D->getAccess());
2590  ToTypedef->setLexicalDeclContext(LexicalDC);
2591  Importer.Imported(D, ToTypedef);
2592  LexicalDC->addDeclInternal(ToTypedef);
2593 
2594  return ToTypedef;
2595 }
2596 
2598  return VisitTypedefNameDecl(D, /*IsAlias=*/false);
2599 }
2600 
2602  return VisitTypedefNameDecl(D, /*IsAlias=*/true);
2603 }
2604 
2606  // Import the major distinguishing characteristics of this label.
2607  DeclContext *DC, *LexicalDC;
2609  SourceLocation Loc;
2610  NamedDecl *ToD;
2611  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2612  return nullptr;
2613  if (ToD)
2614  return ToD;
2615 
2616  assert(LexicalDC->isFunctionOrMethod());
2617 
2618  LabelDecl *ToLabel = D->isGnuLocal()
2619  ? LabelDecl::Create(Importer.getToContext(),
2620  DC, Importer.Import(D->getLocation()),
2621  Name.getAsIdentifierInfo(),
2622  Importer.Import(D->getLocStart()))
2623  : LabelDecl::Create(Importer.getToContext(),
2624  DC, Importer.Import(D->getLocation()),
2625  Name.getAsIdentifierInfo());
2626  Importer.Imported(D, ToLabel);
2627 
2628  LabelStmt *Label = cast_or_null<LabelStmt>(Importer.Import(D->getStmt()));
2629  if (!Label)
2630  return nullptr;
2631 
2632  ToLabel->setStmt(Label);
2633  ToLabel->setLexicalDeclContext(LexicalDC);
2634  LexicalDC->addDeclInternal(ToLabel);
2635  return ToLabel;
2636 }
2637 
2639  // Import the major distinguishing characteristics of this enum.
2640  DeclContext *DC, *LexicalDC;
2642  SourceLocation Loc;
2643  NamedDecl *ToD;
2644  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2645  return nullptr;
2646  if (ToD)
2647  return ToD;
2648 
2649  // Figure out what enum name we're looking for.
2650  unsigned IDNS = Decl::IDNS_Tag;
2651  DeclarationName SearchName = Name;
2652  if (!SearchName && D->getTypedefNameForAnonDecl()) {
2653  SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName());
2654  IDNS = Decl::IDNS_Ordinary;
2655  } else if (Importer.getToContext().getLangOpts().CPlusPlus)
2656  IDNS |= Decl::IDNS_Ordinary;
2657 
2658  // We may already have an enum of the same name; try to find and match it.
2659  if (!DC->isFunctionOrMethod() && SearchName) {
2660  SmallVector<NamedDecl *, 4> ConflictingDecls;
2661  SmallVector<NamedDecl *, 2> FoundDecls;
2662  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
2663  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
2664  if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
2665  continue;
2666 
2667  Decl *Found = FoundDecls[I];
2668  if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
2669  if (const TagType *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
2670  Found = Tag->getDecl();
2671  }
2672 
2673  if (EnumDecl *FoundEnum = dyn_cast<EnumDecl>(Found)) {
2674  if (IsStructuralMatch(D, FoundEnum))
2675  return Importer.Imported(D, FoundEnum);
2676  }
2677 
2678  ConflictingDecls.push_back(FoundDecls[I]);
2679  }
2680 
2681  if (!ConflictingDecls.empty()) {
2682  Name = Importer.HandleNameConflict(Name, DC, IDNS,
2683  ConflictingDecls.data(),
2684  ConflictingDecls.size());
2685  }
2686  }
2687 
2688  // Create the enum declaration.
2689  EnumDecl *D2 = EnumDecl::Create(Importer.getToContext(), DC,
2690  Importer.Import(D->getLocStart()),
2691  Loc, Name.getAsIdentifierInfo(), nullptr,
2692  D->isScoped(), D->isScopedUsingClassTag(),
2693  D->isFixed());
2694  // Import the qualifier, if any.
2695  D2->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
2696  D2->setAccess(D->getAccess());
2697  D2->setLexicalDeclContext(LexicalDC);
2698  Importer.Imported(D, D2);
2699  LexicalDC->addDeclInternal(D2);
2700 
2701  // Import the integer type.
2702  QualType ToIntegerType = Importer.Import(D->getIntegerType());
2703  if (ToIntegerType.isNull())
2704  return nullptr;
2705  D2->setIntegerType(ToIntegerType);
2706 
2707  // Import the definition
2708  if (D->isCompleteDefinition() && ImportDefinition(D, D2))
2709  return nullptr;
2710 
2711  return D2;
2712 }
2713 
2715  // If this record has a definition in the translation unit we're coming from,
2716  // but this particular declaration is not that definition, import the
2717  // definition and map to that.
2718  TagDecl *Definition = D->getDefinition();
2719  if (Definition && Definition != D) {
2720  Decl *ImportedDef = Importer.Import(Definition);
2721  if (!ImportedDef)
2722  return nullptr;
2723 
2724  return Importer.Imported(D, ImportedDef);
2725  }
2726 
2727  // Import the major distinguishing characteristics of this record.
2728  DeclContext *DC, *LexicalDC;
2730  SourceLocation Loc;
2731  NamedDecl *ToD;
2732  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2733  return nullptr;
2734  if (ToD)
2735  return ToD;
2736 
2737  // Figure out what structure name we're looking for.
2738  unsigned IDNS = Decl::IDNS_Tag;
2739  DeclarationName SearchName = Name;
2740  if (!SearchName && D->getTypedefNameForAnonDecl()) {
2741  SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName());
2742  IDNS = Decl::IDNS_Ordinary;
2743  } else if (Importer.getToContext().getLangOpts().CPlusPlus)
2744  IDNS |= Decl::IDNS_Ordinary;
2745 
2746  // We may already have a record of the same name; try to find and match it.
2747  RecordDecl *AdoptDecl = nullptr;
2748  if (!DC->isFunctionOrMethod()) {
2749  SmallVector<NamedDecl *, 4> ConflictingDecls;
2750  SmallVector<NamedDecl *, 2> FoundDecls;
2751  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
2752  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
2753  if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
2754  continue;
2755 
2756  Decl *Found = FoundDecls[I];
2757  if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
2758  if (const TagType *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
2759  Found = Tag->getDecl();
2760  }
2761 
2762  if (RecordDecl *FoundRecord = dyn_cast<RecordDecl>(Found)) {
2763  if (D->isAnonymousStructOrUnion() &&
2764  FoundRecord->isAnonymousStructOrUnion()) {
2765  // If both anonymous structs/unions are in a record context, make sure
2766  // they occur in the same location in the context records.
2767  if (Optional<unsigned> Index1
2769  if (Optional<unsigned> Index2 =
2770  findUntaggedStructOrUnionIndex(FoundRecord)) {
2771  if (*Index1 != *Index2)
2772  continue;
2773  }
2774  }
2775  }
2776 
2777  if (RecordDecl *FoundDef = FoundRecord->getDefinition()) {
2778  if ((SearchName && !D->isCompleteDefinition())
2779  || (D->isCompleteDefinition() &&
2781  == FoundDef->isAnonymousStructOrUnion() &&
2782  IsStructuralMatch(D, FoundDef))) {
2783  // The record types structurally match, or the "from" translation
2784  // unit only had a forward declaration anyway; call it the same
2785  // function.
2786  // FIXME: For C++, we should also merge methods here.
2787  return Importer.Imported(D, FoundDef);
2788  }
2789  } else if (!D->isCompleteDefinition()) {
2790  // We have a forward declaration of this type, so adopt that forward
2791  // declaration rather than building a new one.
2792 
2793  // If one or both can be completed from external storage then try one
2794  // last time to complete and compare them before doing this.
2795 
2796  if (FoundRecord->hasExternalLexicalStorage() &&
2797  !FoundRecord->isCompleteDefinition())
2798  FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord);
2799  if (D->hasExternalLexicalStorage())
2800  D->getASTContext().getExternalSource()->CompleteType(D);
2801 
2802  if (FoundRecord->isCompleteDefinition() &&
2803  D->isCompleteDefinition() &&
2804  !IsStructuralMatch(D, FoundRecord))
2805  continue;
2806 
2807  AdoptDecl = FoundRecord;
2808  continue;
2809  } else if (!SearchName) {
2810  continue;
2811  }
2812  }
2813 
2814  ConflictingDecls.push_back(FoundDecls[I]);
2815  }
2816 
2817  if (!ConflictingDecls.empty() && SearchName) {
2818  Name = Importer.HandleNameConflict(Name, DC, IDNS,
2819  ConflictingDecls.data(),
2820  ConflictingDecls.size());
2821  }
2822  }
2823 
2824  // Create the record declaration.
2825  RecordDecl *D2 = AdoptDecl;
2826  SourceLocation StartLoc = Importer.Import(D->getLocStart());
2827  if (!D2) {
2828  CXXRecordDecl *D2CXX = nullptr;
2829  if (CXXRecordDecl *DCXX = llvm::dyn_cast<CXXRecordDecl>(D)) {
2830  if (DCXX->isLambda()) {
2831  TypeSourceInfo *TInfo = Importer.Import(DCXX->getLambdaTypeInfo());
2832  D2CXX = CXXRecordDecl::CreateLambda(Importer.getToContext(),
2833  DC, TInfo, Loc,
2834  DCXX->isDependentLambda(),
2835  DCXX->isGenericLambda(),
2836  DCXX->getLambdaCaptureDefault());
2837  Decl *CDecl = Importer.Import(DCXX->getLambdaContextDecl());
2838  if (DCXX->getLambdaContextDecl() && !CDecl)
2839  return nullptr;
2840  D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), CDecl);
2841  } else if (DCXX->isInjectedClassName()) {
2842  // We have to be careful to do a similar dance to the one in
2843  // Sema::ActOnStartCXXMemberDeclarations
2844  CXXRecordDecl *const PrevDecl = nullptr;
2845  const bool DelayTypeCreation = true;
2846  D2CXX = CXXRecordDecl::Create(
2847  Importer.getToContext(), D->getTagKind(), DC, StartLoc, Loc,
2848  Name.getAsIdentifierInfo(), PrevDecl, DelayTypeCreation);
2849  Importer.getToContext().getTypeDeclType(
2850  D2CXX, llvm::dyn_cast<CXXRecordDecl>(DC));
2851  } else {
2852  D2CXX = CXXRecordDecl::Create(Importer.getToContext(),
2853  D->getTagKind(),
2854  DC, StartLoc, Loc,
2855  Name.getAsIdentifierInfo());
2856  }
2857  D2 = D2CXX;
2858  D2->setAccess(D->getAccess());
2859  } else {
2860  D2 = RecordDecl::Create(Importer.getToContext(), D->getTagKind(),
2861  DC, StartLoc, Loc, Name.getAsIdentifierInfo());
2862  }
2863 
2864  D2->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
2865  D2->setLexicalDeclContext(LexicalDC);
2866  LexicalDC->addDeclInternal(D2);
2867  if (D->isAnonymousStructOrUnion())
2868  D2->setAnonymousStructOrUnion(true);
2869  }
2870 
2871  Importer.Imported(D, D2);
2872 
2874  return nullptr;
2875 
2876  return D2;
2877 }
2878 
2880  // Import the major distinguishing characteristics of this enumerator.
2881  DeclContext *DC, *LexicalDC;
2883  SourceLocation Loc;
2884  NamedDecl *ToD;
2885  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2886  return nullptr;
2887  if (ToD)
2888  return ToD;
2889 
2890  QualType T = Importer.Import(D->getType());
2891  if (T.isNull())
2892  return nullptr;
2893 
2894  // Determine whether there are any other declarations with the same name and
2895  // in the same context.
2896  if (!LexicalDC->isFunctionOrMethod()) {
2897  SmallVector<NamedDecl *, 4> ConflictingDecls;
2898  unsigned IDNS = Decl::IDNS_Ordinary;
2899  SmallVector<NamedDecl *, 2> FoundDecls;
2900  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
2901  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
2902  if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
2903  continue;
2904 
2905  if (EnumConstantDecl *FoundEnumConstant
2906  = dyn_cast<EnumConstantDecl>(FoundDecls[I])) {
2907  if (IsStructuralMatch(D, FoundEnumConstant))
2908  return Importer.Imported(D, FoundEnumConstant);
2909  }
2910 
2911  ConflictingDecls.push_back(FoundDecls[I]);
2912  }
2913 
2914  if (!ConflictingDecls.empty()) {
2915  Name = Importer.HandleNameConflict(Name, DC, IDNS,
2916  ConflictingDecls.data(),
2917  ConflictingDecls.size());
2918  if (!Name)
2919  return nullptr;
2920  }
2921  }
2922 
2923  Expr *Init = Importer.Import(D->getInitExpr());
2924  if (D->getInitExpr() && !Init)
2925  return nullptr;
2926 
2927  EnumConstantDecl *ToEnumerator
2928  = EnumConstantDecl::Create(Importer.getToContext(), cast<EnumDecl>(DC), Loc,
2929  Name.getAsIdentifierInfo(), T,
2930  Init, D->getInitVal());
2931  ToEnumerator->setAccess(D->getAccess());
2932  ToEnumerator->setLexicalDeclContext(LexicalDC);
2933  Importer.Imported(D, ToEnumerator);
2934  LexicalDC->addDeclInternal(ToEnumerator);
2935  return ToEnumerator;
2936 }
2937 
2939  // Import the major distinguishing characteristics of this function.
2940  DeclContext *DC, *LexicalDC;
2942  SourceLocation Loc;
2943  NamedDecl *ToD;
2944  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2945  return nullptr;
2946  if (ToD)
2947  return ToD;
2948 
2949  // Try to find a function in our own ("to") context with the same name, same
2950  // type, and in the same context as the function we're importing.
2951  if (!LexicalDC->isFunctionOrMethod()) {
2952  SmallVector<NamedDecl *, 4> ConflictingDecls;
2953  unsigned IDNS = Decl::IDNS_Ordinary;
2954  SmallVector<NamedDecl *, 2> FoundDecls;
2955  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
2956  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
2957  if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
2958  continue;
2959 
2960  if (FunctionDecl *FoundFunction = dyn_cast<FunctionDecl>(FoundDecls[I])) {
2961  if (FoundFunction->hasExternalFormalLinkage() &&
2962  D->hasExternalFormalLinkage()) {
2963  if (Importer.IsStructurallyEquivalent(D->getType(),
2964  FoundFunction->getType())) {
2965  // FIXME: Actually try to merge the body and other attributes.
2966  return Importer.Imported(D, FoundFunction);
2967  }
2968 
2969  // FIXME: Check for overloading more carefully, e.g., by boosting
2970  // Sema::IsOverload out to the AST library.
2971 
2972  // Function overloading is okay in C++.
2973  if (Importer.getToContext().getLangOpts().CPlusPlus)
2974  continue;
2975 
2976  // Complain about inconsistent function types.
2977  Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent)
2978  << Name << D->getType() << FoundFunction->getType();
2979  Importer.ToDiag(FoundFunction->getLocation(),
2980  diag::note_odr_value_here)
2981  << FoundFunction->getType();
2982  }
2983  }
2984 
2985  ConflictingDecls.push_back(FoundDecls[I]);
2986  }
2987 
2988  if (!ConflictingDecls.empty()) {
2989  Name = Importer.HandleNameConflict(Name, DC, IDNS,
2990  ConflictingDecls.data(),
2991  ConflictingDecls.size());
2992  if (!Name)
2993  return nullptr;
2994  }
2995  }
2996 
2997  DeclarationNameInfo NameInfo(Name, Loc);
2998  // Import additional name location/type info.
2999  ImportDeclarationNameLoc(D->getNameInfo(), NameInfo);
3000 
3001  QualType FromTy = D->getType();
3002  bool usedDifferentExceptionSpec = false;
3003 
3004  if (const FunctionProtoType *
3005  FromFPT = D->getType()->getAs<FunctionProtoType>()) {
3006  FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
3007  // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
3008  // FunctionDecl that we are importing the FunctionProtoType for.
3009  // To avoid an infinite recursion when importing, create the FunctionDecl
3010  // with a simplified function type and update it afterwards.
3011  if (FromEPI.ExceptionSpec.SourceDecl ||
3012  FromEPI.ExceptionSpec.SourceTemplate ||
3013  FromEPI.ExceptionSpec.NoexceptExpr) {
3015  FromTy = Importer.getFromContext().getFunctionType(
3016  FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI);
3017  usedDifferentExceptionSpec = true;
3018  }
3019  }
3020 
3021  // Import the type.
3022  QualType T = Importer.Import(FromTy);
3023  if (T.isNull())
3024  return nullptr;
3025 
3026  // Import the function parameters.
3027  SmallVector<ParmVarDecl *, 8> Parameters;
3028  for (auto P : D->parameters()) {
3029  ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(P));
3030  if (!ToP)
3031  return nullptr;
3032 
3033  Parameters.push_back(ToP);
3034  }
3035 
3036  // Create the imported function.
3037  TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
3038  FunctionDecl *ToFunction = nullptr;
3039  SourceLocation InnerLocStart = Importer.Import(D->getInnerLocStart());
3040  if (CXXConstructorDecl *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
3041  ToFunction = CXXConstructorDecl::Create(Importer.getToContext(),
3042  cast<CXXRecordDecl>(DC),
3043  InnerLocStart,
3044  NameInfo, T, TInfo,
3045  FromConstructor->isExplicit(),
3046  D->isInlineSpecified(),
3047  D->isImplicit(),
3048  D->isConstexpr());
3049  if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
3050  SmallVector<CXXCtorInitializer *, 4> CtorInitializers;
3051  for (CXXCtorInitializer *I : FromConstructor->inits()) {
3052  CXXCtorInitializer *ToI =
3053  cast_or_null<CXXCtorInitializer>(Importer.Import(I));
3054  if (!ToI && I)
3055  return nullptr;
3056  CtorInitializers.push_back(ToI);
3057  }
3058  CXXCtorInitializer **Memory =
3059  new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
3060  std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
3061  CXXConstructorDecl *ToCtor = llvm::cast<CXXConstructorDecl>(ToFunction);
3062  ToCtor->setCtorInitializers(Memory);
3063  ToCtor->setNumCtorInitializers(NumInitializers);
3064  }
3065  } else if (isa<CXXDestructorDecl>(D)) {
3066  ToFunction = CXXDestructorDecl::Create(Importer.getToContext(),
3067  cast<CXXRecordDecl>(DC),
3068  InnerLocStart,
3069  NameInfo, T, TInfo,
3070  D->isInlineSpecified(),
3071  D->isImplicit());
3072  } else if (CXXConversionDecl *FromConversion
3073  = dyn_cast<CXXConversionDecl>(D)) {
3074  ToFunction = CXXConversionDecl::Create(Importer.getToContext(),
3075  cast<CXXRecordDecl>(DC),
3076  InnerLocStart,
3077  NameInfo, T, TInfo,
3078  D->isInlineSpecified(),
3079  FromConversion->isExplicit(),
3080  D->isConstexpr(),
3081  Importer.Import(D->getLocEnd()));
3082  } else if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) {
3083  ToFunction = CXXMethodDecl::Create(Importer.getToContext(),
3084  cast<CXXRecordDecl>(DC),
3085  InnerLocStart,
3086  NameInfo, T, TInfo,
3087  Method->getStorageClass(),
3088  Method->isInlineSpecified(),
3089  D->isConstexpr(),
3090  Importer.Import(D->getLocEnd()));
3091  } else {
3092  ToFunction = FunctionDecl::Create(Importer.getToContext(), DC,
3093  InnerLocStart,
3094  NameInfo, T, TInfo, D->getStorageClass(),
3095  D->isInlineSpecified(),
3096  D->hasWrittenPrototype(),
3097  D->isConstexpr());
3098  }
3099 
3100  // Import the qualifier, if any.
3101  ToFunction->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
3102  ToFunction->setAccess(D->getAccess());
3103  ToFunction->setLexicalDeclContext(LexicalDC);
3104  ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
3105  ToFunction->setTrivial(D->isTrivial());
3106  ToFunction->setPure(D->isPure());
3107  Importer.Imported(D, ToFunction);
3108 
3109  // Set the parameters.
3110  for (unsigned I = 0, N = Parameters.size(); I != N; ++I) {
3111  Parameters[I]->setOwningFunction(ToFunction);
3112  ToFunction->addDeclInternal(Parameters[I]);
3113  }
3114  ToFunction->setParams(Parameters);
3115 
3116  if (usedDifferentExceptionSpec) {
3117  // Update FunctionProtoType::ExtProtoInfo.
3118  QualType T = Importer.Import(D->getType());
3119  if (T.isNull())
3120  return nullptr;
3121  ToFunction->setType(T);
3122  }
3123 
3124  // Import the body, if any.
3125  if (Stmt *FromBody = D->getBody()) {
3126  if (Stmt *ToBody = Importer.Import(FromBody)) {
3127  ToFunction->setBody(ToBody);
3128  }
3129  }
3130 
3131  // FIXME: Other bits to merge?
3132 
3133  // Add this function to the lexical context.
3134  LexicalDC->addDeclInternal(ToFunction);
3135 
3136  return ToFunction;
3137 }
3138 
3140  return VisitFunctionDecl(D);
3141 }
3142 
3144  return VisitCXXMethodDecl(D);
3145 }
3146 
3148  return VisitCXXMethodDecl(D);
3149 }
3150 
3152  return VisitCXXMethodDecl(D);
3153 }
3154 
3155 static unsigned getFieldIndex(Decl *F) {
3156  RecordDecl *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
3157  if (!Owner)
3158  return 0;
3159 
3160  unsigned Index = 1;
3161  for (const auto *D : Owner->noload_decls()) {
3162  if (D == F)
3163  return Index;
3164 
3165  if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D))
3166  ++Index;
3167  }
3168 
3169  return Index;
3170 }
3171 
3173  // Import the major distinguishing characteristics of a variable.
3174  DeclContext *DC, *LexicalDC;
3176  SourceLocation Loc;
3177  NamedDecl *ToD;
3178  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3179  return nullptr;
3180  if (ToD)
3181  return ToD;
3182 
3183  // Determine whether we've already imported this field.
3184  SmallVector<NamedDecl *, 2> FoundDecls;
3185  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
3186  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
3187  if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecls[I])) {
3188  // For anonymous fields, match up by index.
3189  if (!Name && getFieldIndex(D) != getFieldIndex(FoundField))
3190  continue;
3191 
3192  if (Importer.IsStructurallyEquivalent(D->getType(),
3193  FoundField->getType())) {
3194  Importer.Imported(D, FoundField);
3195  return FoundField;
3196  }
3197 
3198  Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent)
3199  << Name << D->getType() << FoundField->getType();
3200  Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
3201  << FoundField->getType();
3202  return nullptr;
3203  }
3204  }
3205 
3206  // Import the type.
3207  QualType T = Importer.Import(D->getType());
3208  if (T.isNull())
3209  return nullptr;
3210 
3211  TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
3212  Expr *BitWidth = Importer.Import(D->getBitWidth());
3213  if (!BitWidth && D->getBitWidth())
3214  return nullptr;
3215 
3216  FieldDecl *ToField = FieldDecl::Create(Importer.getToContext(), DC,
3217  Importer.Import(D->getInnerLocStart()),
3218  Loc, Name.getAsIdentifierInfo(),
3219  T, TInfo, BitWidth, D->isMutable(),
3220  D->getInClassInitStyle());
3221  ToField->setAccess(D->getAccess());
3222  ToField->setLexicalDeclContext(LexicalDC);
3223  if (Expr *FromInitializer = D->getInClassInitializer()) {
3224  Expr *ToInitializer = Importer.Import(FromInitializer);
3225  if (ToInitializer)
3226  ToField->setInClassInitializer(ToInitializer);
3227  else
3228  return nullptr;
3229  }
3230  ToField->setImplicit(D->isImplicit());
3231  Importer.Imported(D, ToField);
3232  LexicalDC->addDeclInternal(ToField);
3233  return ToField;
3234 }
3235 
3237  // Import the major distinguishing characteristics of a variable.
3238  DeclContext *DC, *LexicalDC;
3240  SourceLocation Loc;
3241  NamedDecl *ToD;
3242  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3243  return nullptr;
3244  if (ToD)
3245  return ToD;
3246 
3247  // Determine whether we've already imported this field.
3248  SmallVector<NamedDecl *, 2> FoundDecls;
3249  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
3250  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
3251  if (IndirectFieldDecl *FoundField
3252  = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
3253  // For anonymous indirect fields, match up by index.
3254  if (!Name && getFieldIndex(D) != getFieldIndex(FoundField))
3255  continue;
3256 
3257  if (Importer.IsStructurallyEquivalent(D->getType(),
3258  FoundField->getType(),
3259  !Name.isEmpty())) {
3260  Importer.Imported(D, FoundField);
3261  return FoundField;
3262  }
3263 
3264  // If there are more anonymous fields to check, continue.
3265  if (!Name && I < N-1)
3266  continue;
3267 
3268  Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent)
3269  << Name << D->getType() << FoundField->getType();
3270  Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
3271  << FoundField->getType();
3272  return nullptr;
3273  }
3274  }
3275 
3276  // Import the type.
3277  QualType T = Importer.Import(D->getType());
3278  if (T.isNull())
3279  return nullptr;
3280 
3281  NamedDecl **NamedChain =
3282  new (Importer.getToContext())NamedDecl*[D->getChainingSize()];
3283 
3284  unsigned i = 0;
3285  for (auto *PI : D->chain()) {
3286  Decl *D = Importer.Import(PI);
3287  if (!D)
3288  return nullptr;
3289  NamedChain[i++] = cast<NamedDecl>(D);
3290  }
3291 
3292  IndirectFieldDecl *ToIndirectField = IndirectFieldDecl::Create(
3293  Importer.getToContext(), DC, Loc, Name.getAsIdentifierInfo(), T,
3294  {NamedChain, D->getChainingSize()});
3295 
3296  for (const auto *Attr : D->attrs())
3297  ToIndirectField->addAttr(Attr->clone(Importer.getToContext()));
3298 
3299  ToIndirectField->setAccess(D->getAccess());
3300  ToIndirectField->setLexicalDeclContext(LexicalDC);
3301  Importer.Imported(D, ToIndirectField);
3302  LexicalDC->addDeclInternal(ToIndirectField);
3303  return ToIndirectField;
3304 }
3305 
3307  // Import the major distinguishing characteristics of an ivar.
3308  DeclContext *DC, *LexicalDC;
3310  SourceLocation Loc;
3311  NamedDecl *ToD;
3312  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3313  return nullptr;
3314  if (ToD)
3315  return ToD;
3316 
3317  // Determine whether we've already imported this ivar
3318  SmallVector<NamedDecl *, 2> FoundDecls;
3319  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
3320  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
3321  if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecls[I])) {
3322  if (Importer.IsStructurallyEquivalent(D->getType(),
3323  FoundIvar->getType())) {
3324  Importer.Imported(D, FoundIvar);
3325  return FoundIvar;
3326  }
3327 
3328  Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent)
3329  << Name << D->getType() << FoundIvar->getType();
3330  Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
3331  << FoundIvar->getType();
3332  return nullptr;
3333  }
3334  }
3335 
3336  // Import the type.
3337  QualType T = Importer.Import(D->getType());
3338  if (T.isNull())
3339  return nullptr;
3340 
3341  TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
3342  Expr *BitWidth = Importer.Import(D->getBitWidth());
3343  if (!BitWidth && D->getBitWidth())
3344  return nullptr;
3345 
3346  ObjCIvarDecl *ToIvar = ObjCIvarDecl::Create(Importer.getToContext(),
3347  cast<ObjCContainerDecl>(DC),
3348  Importer.Import(D->getInnerLocStart()),
3349  Loc, Name.getAsIdentifierInfo(),
3350  T, TInfo, D->getAccessControl(),
3351  BitWidth, D->getSynthesize());
3352  ToIvar->setLexicalDeclContext(LexicalDC);
3353  Importer.Imported(D, ToIvar);
3354  LexicalDC->addDeclInternal(ToIvar);
3355  return ToIvar;
3356 
3357 }
3358 
3360  // Import the major distinguishing characteristics of a variable.
3361  DeclContext *DC, *LexicalDC;
3363  SourceLocation Loc;
3364  NamedDecl *ToD;
3365  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3366  return nullptr;
3367  if (ToD)
3368  return ToD;
3369 
3370  // Try to find a variable in our own ("to") context with the same name and
3371  // in the same context as the variable we're importing.
3372  if (D->isFileVarDecl()) {
3373  VarDecl *MergeWithVar = nullptr;
3374  SmallVector<NamedDecl *, 4> ConflictingDecls;
3375  unsigned IDNS = Decl::IDNS_Ordinary;
3376  SmallVector<NamedDecl *, 2> FoundDecls;
3377  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
3378  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
3379  if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
3380  continue;
3381 
3382  if (VarDecl *FoundVar = dyn_cast<VarDecl>(FoundDecls[I])) {
3383  // We have found a variable that we may need to merge with. Check it.
3384  if (FoundVar->hasExternalFormalLinkage() &&
3385  D->hasExternalFormalLinkage()) {
3386  if (Importer.IsStructurallyEquivalent(D->getType(),
3387  FoundVar->getType())) {
3388  MergeWithVar = FoundVar;
3389  break;
3390  }
3391 
3392  const ArrayType *FoundArray
3393  = Importer.getToContext().getAsArrayType(FoundVar->getType());
3394  const ArrayType *TArray
3395  = Importer.getToContext().getAsArrayType(D->getType());
3396  if (FoundArray && TArray) {
3397  if (isa<IncompleteArrayType>(FoundArray) &&
3398  isa<ConstantArrayType>(TArray)) {
3399  // Import the type.
3400  QualType T = Importer.Import(D->getType());
3401  if (T.isNull())
3402  return nullptr;
3403 
3404  FoundVar->setType(T);
3405  MergeWithVar = FoundVar;
3406  break;
3407  } else if (isa<IncompleteArrayType>(TArray) &&
3408  isa<ConstantArrayType>(FoundArray)) {
3409  MergeWithVar = FoundVar;
3410  break;
3411  }
3412  }
3413 
3414  Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent)
3415  << Name << D->getType() << FoundVar->getType();
3416  Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
3417  << FoundVar->getType();
3418  }
3419  }
3420 
3421  ConflictingDecls.push_back(FoundDecls[I]);
3422  }
3423 
3424  if (MergeWithVar) {
3425  // An equivalent variable with external linkage has been found. Link
3426  // the two declarations, then merge them.
3427  Importer.Imported(D, MergeWithVar);
3428 
3429  if (VarDecl *DDef = D->getDefinition()) {
3430  if (VarDecl *ExistingDef = MergeWithVar->getDefinition()) {
3431  Importer.ToDiag(ExistingDef->getLocation(),
3432  diag::err_odr_variable_multiple_def)
3433  << Name;
3434  Importer.FromDiag(DDef->getLocation(), diag::note_odr_defined_here);
3435  } else {
3436  Expr *Init = Importer.Import(DDef->getInit());
3437  MergeWithVar->setInit(Init);
3438  if (DDef->isInitKnownICE()) {
3439  EvaluatedStmt *Eval = MergeWithVar->ensureEvaluatedStmt();
3440  Eval->CheckedICE = true;
3441  Eval->IsICE = DDef->isInitICE();
3442  }
3443  }
3444  }
3445 
3446  return MergeWithVar;
3447  }
3448 
3449  if (!ConflictingDecls.empty()) {
3450  Name = Importer.HandleNameConflict(Name, DC, IDNS,
3451  ConflictingDecls.data(),
3452  ConflictingDecls.size());
3453  if (!Name)
3454  return nullptr;
3455  }
3456  }
3457 
3458  // Import the type.
3459  QualType T = Importer.Import(D->getType());
3460  if (T.isNull())
3461  return nullptr;
3462 
3463  // Create the imported variable.
3464  TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
3465  VarDecl *ToVar = VarDecl::Create(Importer.getToContext(), DC,
3466  Importer.Import(D->getInnerLocStart()),
3467  Loc, Name.getAsIdentifierInfo(),
3468  T, TInfo,
3469  D->getStorageClass());
3470  ToVar->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
3471  ToVar->setAccess(D->getAccess());
3472  ToVar->setLexicalDeclContext(LexicalDC);
3473  Importer.Imported(D, ToVar);
3474  LexicalDC->addDeclInternal(ToVar);
3475 
3476  if (!D->isFileVarDecl() &&
3477  D->isUsed())
3478  ToVar->setIsUsed();
3479 
3480  // Merge the initializer.
3481  if (ImportDefinition(D, ToVar))
3482  return nullptr;
3483 
3484  return ToVar;
3485 }
3486 
3488  // Parameters are created in the translation unit's context, then moved
3489  // into the function declaration's context afterward.
3490  DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
3491 
3492  // Import the name of this declaration.
3493  DeclarationName Name = Importer.Import(D->getDeclName());
3494  if (D->getDeclName() && !Name)
3495  return nullptr;
3496 
3497  // Import the location of this declaration.
3498  SourceLocation Loc = Importer.Import(D->getLocation());
3499 
3500  // Import the parameter's type.
3501  QualType T = Importer.Import(D->getType());
3502  if (T.isNull())
3503  return nullptr;
3504 
3505  // Create the imported parameter.
3506  ImplicitParamDecl *ToParm
3507  = ImplicitParamDecl::Create(Importer.getToContext(), DC,
3508  Loc, Name.getAsIdentifierInfo(),
3509  T);
3510  return Importer.Imported(D, ToParm);
3511 }
3512 
3514  // Parameters are created in the translation unit's context, then moved
3515  // into the function declaration's context afterward.
3516  DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
3517 
3518  // Import the name of this declaration.
3519  DeclarationName Name = Importer.Import(D->getDeclName());
3520  if (D->getDeclName() && !Name)
3521  return nullptr;
3522 
3523  // Import the location of this declaration.
3524  SourceLocation Loc = Importer.Import(D->getLocation());
3525 
3526  // Import the parameter's type.
3527  QualType T = Importer.Import(D->getType());
3528  if (T.isNull())
3529  return nullptr;
3530 
3531  // Create the imported parameter.
3532  TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
3533  ParmVarDecl *ToParm = ParmVarDecl::Create(Importer.getToContext(), DC,
3534  Importer.Import(D->getInnerLocStart()),
3535  Loc, Name.getAsIdentifierInfo(),
3536  T, TInfo, D->getStorageClass(),
3537  /*FIXME: Default argument*/nullptr);
3539 
3540  if (D->isUsed())
3541  ToParm->setIsUsed();
3542 
3543  return Importer.Imported(D, ToParm);
3544 }
3545 
3547  // Import the major distinguishing characteristics of a method.
3548  DeclContext *DC, *LexicalDC;
3550  SourceLocation Loc;
3551  NamedDecl *ToD;
3552  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3553  return nullptr;
3554  if (ToD)
3555  return ToD;
3556 
3557  SmallVector<NamedDecl *, 2> FoundDecls;
3558  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
3559  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
3560  if (ObjCMethodDecl *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecls[I])) {
3561  if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
3562  continue;
3563 
3564  // Check return types.
3565  if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
3566  FoundMethod->getReturnType())) {
3567  Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent)
3568  << D->isInstanceMethod() << Name << D->getReturnType()
3569  << FoundMethod->getReturnType();
3570  Importer.ToDiag(FoundMethod->getLocation(),
3571  diag::note_odr_objc_method_here)
3572  << D->isInstanceMethod() << Name;
3573  return nullptr;
3574  }
3575 
3576  // Check the number of parameters.
3577  if (D->param_size() != FoundMethod->param_size()) {
3578  Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent)
3579  << D->isInstanceMethod() << Name
3580  << D->param_size() << FoundMethod->param_size();
3581  Importer.ToDiag(FoundMethod->getLocation(),
3582  diag::note_odr_objc_method_here)
3583  << D->isInstanceMethod() << Name;
3584  return nullptr;
3585  }
3586 
3587  // Check parameter types.
3589  PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
3590  P != PEnd; ++P, ++FoundP) {
3591  if (!Importer.IsStructurallyEquivalent((*P)->getType(),
3592  (*FoundP)->getType())) {
3593  Importer.FromDiag((*P)->getLocation(),
3594  diag::err_odr_objc_method_param_type_inconsistent)
3595  << D->isInstanceMethod() << Name
3596  << (*P)->getType() << (*FoundP)->getType();
3597  Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
3598  << (*FoundP)->getType();
3599  return nullptr;
3600  }
3601  }
3602 
3603  // Check variadic/non-variadic.
3604  // Check the number of parameters.
3605  if (D->isVariadic() != FoundMethod->isVariadic()) {
3606  Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent)
3607  << D->isInstanceMethod() << Name;
3608  Importer.ToDiag(FoundMethod->getLocation(),
3609  diag::note_odr_objc_method_here)
3610  << D->isInstanceMethod() << Name;
3611  return nullptr;
3612  }
3613 
3614  // FIXME: Any other bits we need to merge?
3615  return Importer.Imported(D, FoundMethod);
3616  }
3617  }
3618 
3619  // Import the result type.
3620  QualType ResultTy = Importer.Import(D->getReturnType());
3621  if (ResultTy.isNull())
3622  return nullptr;
3623 
3624  TypeSourceInfo *ReturnTInfo = Importer.Import(D->getReturnTypeSourceInfo());
3625 
3627  Importer.getToContext(), Loc, Importer.Import(D->getLocEnd()),
3628  Name.getObjCSelector(), ResultTy, ReturnTInfo, DC, D->isInstanceMethod(),
3629  D->isVariadic(), D->isPropertyAccessor(), D->isImplicit(), D->isDefined(),
3631 
3632  // FIXME: When we decide to merge method definitions, we'll need to
3633  // deal with implicit parameters.
3634 
3635  // Import the parameters
3637  for (auto *FromP : D->parameters()) {
3638  ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(FromP));
3639  if (!ToP)
3640  return nullptr;
3641 
3642  ToParams.push_back(ToP);
3643  }
3644 
3645  // Set the parameters.
3646  for (unsigned I = 0, N = ToParams.size(); I != N; ++I) {
3647  ToParams[I]->setOwningFunction(ToMethod);
3648  ToMethod->addDeclInternal(ToParams[I]);
3649  }
3651  D->getSelectorLocs(SelLocs);
3652  ToMethod->setMethodParams(Importer.getToContext(), ToParams, SelLocs);
3653 
3654  ToMethod->setLexicalDeclContext(LexicalDC);
3655  Importer.Imported(D, ToMethod);
3656  LexicalDC->addDeclInternal(ToMethod);
3657  return ToMethod;
3658 }
3659 
3661  // Import the major distinguishing characteristics of a category.
3662  DeclContext *DC, *LexicalDC;
3664  SourceLocation Loc;
3665  NamedDecl *ToD;
3666  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3667  return nullptr;
3668  if (ToD)
3669  return ToD;
3670 
3671  TypeSourceInfo *BoundInfo = Importer.Import(D->getTypeSourceInfo());
3672  if (!BoundInfo)
3673  return nullptr;
3674 
3676  Importer.getToContext(), DC,
3677  D->getVariance(),
3678  Importer.Import(D->getVarianceLoc()),
3679  D->getIndex(),
3680  Importer.Import(D->getLocation()),
3681  Name.getAsIdentifierInfo(),
3682  Importer.Import(D->getColonLoc()),
3683  BoundInfo);
3684  Importer.Imported(D, Result);
3685  Result->setLexicalDeclContext(LexicalDC);
3686  return Result;
3687 }
3688 
3690  // Import the major distinguishing characteristics of a category.
3691  DeclContext *DC, *LexicalDC;
3693  SourceLocation Loc;
3694  NamedDecl *ToD;
3695  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3696  return nullptr;
3697  if (ToD)
3698  return ToD;
3699 
3700  ObjCInterfaceDecl *ToInterface
3701  = cast_or_null<ObjCInterfaceDecl>(Importer.Import(D->getClassInterface()));
3702  if (!ToInterface)
3703  return nullptr;
3704 
3705  // Determine if we've already encountered this category.
3706  ObjCCategoryDecl *MergeWithCategory
3707  = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
3708  ObjCCategoryDecl *ToCategory = MergeWithCategory;
3709  if (!ToCategory) {
3710  ToCategory = ObjCCategoryDecl::Create(Importer.getToContext(), DC,
3711  Importer.Import(D->getAtStartLoc()),
3712  Loc,
3713  Importer.Import(D->getCategoryNameLoc()),
3714  Name.getAsIdentifierInfo(),
3715  ToInterface,
3716  /*TypeParamList=*/nullptr,
3717  Importer.Import(D->getIvarLBraceLoc()),
3718  Importer.Import(D->getIvarRBraceLoc()));
3719  ToCategory->setLexicalDeclContext(LexicalDC);
3720  LexicalDC->addDeclInternal(ToCategory);
3721  Importer.Imported(D, ToCategory);
3722  // Import the type parameter list after calling Imported, to avoid
3723  // loops when bringing in their DeclContext.
3725  D->getTypeParamList()));
3726 
3727  // Import protocols
3729  SmallVector<SourceLocation, 4> ProtocolLocs;
3731  = D->protocol_loc_begin();
3733  FromProtoEnd = D->protocol_end();
3734  FromProto != FromProtoEnd;
3735  ++FromProto, ++FromProtoLoc) {
3736  ObjCProtocolDecl *ToProto
3737  = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto));
3738  if (!ToProto)
3739  return nullptr;
3740  Protocols.push_back(ToProto);
3741  ProtocolLocs.push_back(Importer.Import(*FromProtoLoc));
3742  }
3743 
3744  // FIXME: If we're merging, make sure that the protocol list is the same.
3745  ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
3746  ProtocolLocs.data(), Importer.getToContext());
3747 
3748  } else {
3749  Importer.Imported(D, ToCategory);
3750  }
3751 
3752  // Import all of the members of this category.
3753  ImportDeclContext(D);
3754 
3755  // If we have an implementation, import it as well.
3756  if (D->getImplementation()) {
3757  ObjCCategoryImplDecl *Impl
3758  = cast_or_null<ObjCCategoryImplDecl>(
3759  Importer.Import(D->getImplementation()));
3760  if (!Impl)
3761  return nullptr;
3762 
3763  ToCategory->setImplementation(Impl);
3764  }
3765 
3766  return ToCategory;
3767 }
3768 
3770  ObjCProtocolDecl *To,
3772  if (To->getDefinition()) {
3773  if (shouldForceImportDeclContext(Kind))
3774  ImportDeclContext(From);
3775  return false;
3776  }
3777 
3778  // Start the protocol definition
3779  To->startDefinition();
3780 
3781  // Import protocols
3783  SmallVector<SourceLocation, 4> ProtocolLocs;
3785  FromProtoLoc = From->protocol_loc_begin();
3786  for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
3787  FromProtoEnd = From->protocol_end();
3788  FromProto != FromProtoEnd;
3789  ++FromProto, ++FromProtoLoc) {
3790  ObjCProtocolDecl *ToProto
3791  = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto));
3792  if (!ToProto)
3793  return true;
3794  Protocols.push_back(ToProto);
3795  ProtocolLocs.push_back(Importer.Import(*FromProtoLoc));
3796  }
3797 
3798  // FIXME: If we're merging, make sure that the protocol list is the same.
3799  To->setProtocolList(Protocols.data(), Protocols.size(),
3800  ProtocolLocs.data(), Importer.getToContext());
3801 
3802  if (shouldForceImportDeclContext(Kind)) {
3803  // Import all of the members of this protocol.
3804  ImportDeclContext(From, /*ForceImport=*/true);
3805  }
3806  return false;
3807 }
3808 
3810  // If this protocol has a definition in the translation unit we're coming
3811  // from, but this particular declaration is not that definition, import the
3812  // definition and map to that.
3813  ObjCProtocolDecl *Definition = D->getDefinition();
3814  if (Definition && Definition != D) {
3815  Decl *ImportedDef = Importer.Import(Definition);
3816  if (!ImportedDef)
3817  return nullptr;
3818 
3819  return Importer.Imported(D, ImportedDef);
3820  }
3821 
3822  // Import the major distinguishing characteristics of a protocol.
3823  DeclContext *DC, *LexicalDC;
3825  SourceLocation Loc;
3826  NamedDecl *ToD;
3827  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3828  return nullptr;
3829  if (ToD)
3830  return ToD;
3831 
3832  ObjCProtocolDecl *MergeWithProtocol = nullptr;
3833  SmallVector<NamedDecl *, 2> FoundDecls;
3834  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
3835  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
3836  if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol))
3837  continue;
3838 
3839  if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecls[I])))
3840  break;
3841  }
3842 
3843  ObjCProtocolDecl *ToProto = MergeWithProtocol;
3844  if (!ToProto) {
3845  ToProto = ObjCProtocolDecl::Create(Importer.getToContext(), DC,
3846  Name.getAsIdentifierInfo(), Loc,
3847  Importer.Import(D->getAtStartLoc()),
3848  /*PrevDecl=*/nullptr);
3849  ToProto->setLexicalDeclContext(LexicalDC);
3850  LexicalDC->addDeclInternal(ToProto);
3851  }
3852 
3853  Importer.Imported(D, ToProto);
3854 
3855  if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToProto))
3856  return nullptr;
3857 
3858  return ToProto;
3859 }
3860 
3862  DeclContext *DC = Importer.ImportContext(D->getDeclContext());
3863  DeclContext *LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
3864 
3865  SourceLocation ExternLoc = Importer.Import(D->getExternLoc());
3866  SourceLocation LangLoc = Importer.Import(D->getLocation());
3867 
3868  bool HasBraces = D->hasBraces();
3869 
3870  LinkageSpecDecl *ToLinkageSpec =
3872  DC,
3873  ExternLoc,
3874  LangLoc,
3875  D->getLanguage(),
3876  HasBraces);
3877 
3878  if (HasBraces) {
3879  SourceLocation RBraceLoc = Importer.Import(D->getRBraceLoc());
3880  ToLinkageSpec->setRBraceLoc(RBraceLoc);
3881  }
3882 
3883  ToLinkageSpec->setLexicalDeclContext(LexicalDC);
3884  LexicalDC->addDeclInternal(ToLinkageSpec);
3885 
3886  Importer.Imported(D, ToLinkageSpec);
3887 
3888  return ToLinkageSpec;
3889 }
3890 
3892  ObjCInterfaceDecl *To,
3894  if (To->getDefinition()) {
3895  // Check consistency of superclass.
3896  ObjCInterfaceDecl *FromSuper = From->getSuperClass();
3897  if (FromSuper) {
3898  FromSuper = cast_or_null<ObjCInterfaceDecl>(Importer.Import(FromSuper));
3899  if (!FromSuper)
3900  return true;
3901  }
3902 
3903  ObjCInterfaceDecl *ToSuper = To->getSuperClass();
3904  if ((bool)FromSuper != (bool)ToSuper ||
3905  (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
3906  Importer.ToDiag(To->getLocation(),
3907  diag::err_odr_objc_superclass_inconsistent)
3908  << To->getDeclName();
3909  if (ToSuper)
3910  Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
3911  << To->getSuperClass()->getDeclName();
3912  else
3913  Importer.ToDiag(To->getLocation(),
3914  diag::note_odr_objc_missing_superclass);
3915  if (From->getSuperClass())
3916  Importer.FromDiag(From->getSuperClassLoc(),
3917  diag::note_odr_objc_superclass)
3918  << From->getSuperClass()->getDeclName();
3919  else
3920  Importer.FromDiag(From->getLocation(),
3921  diag::note_odr_objc_missing_superclass);
3922  }
3923 
3924  if (shouldForceImportDeclContext(Kind))
3925  ImportDeclContext(From);
3926  return false;
3927  }
3928 
3929  // Start the definition.
3930  To->startDefinition();
3931 
3932  // If this class has a superclass, import it.
3933  if (From->getSuperClass()) {
3934  TypeSourceInfo *SuperTInfo = Importer.Import(From->getSuperClassTInfo());
3935  if (!SuperTInfo)
3936  return true;
3937 
3938  To->setSuperClass(SuperTInfo);
3939  }
3940 
3941  // Import protocols
3943  SmallVector<SourceLocation, 4> ProtocolLocs;
3945  FromProtoLoc = From->protocol_loc_begin();
3946 
3947  for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(),
3948  FromProtoEnd = From->protocol_end();
3949  FromProto != FromProtoEnd;
3950  ++FromProto, ++FromProtoLoc) {
3951  ObjCProtocolDecl *ToProto
3952  = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto));
3953  if (!ToProto)
3954  return true;
3955  Protocols.push_back(ToProto);
3956  ProtocolLocs.push_back(Importer.Import(*FromProtoLoc));
3957  }
3958 
3959  // FIXME: If we're merging, make sure that the protocol list is the same.
3960  To->setProtocolList(Protocols.data(), Protocols.size(),
3961  ProtocolLocs.data(), Importer.getToContext());
3962 
3963  // Import categories. When the categories themselves are imported, they'll
3964  // hook themselves into this interface.
3965  for (auto *Cat : From->known_categories())
3966  Importer.Import(Cat);
3967 
3968  // If we have an @implementation, import it as well.
3969  if (From->getImplementation()) {
3970  ObjCImplementationDecl *Impl = cast_or_null<ObjCImplementationDecl>(
3971  Importer.Import(From->getImplementation()));
3972  if (!Impl)
3973  return true;
3974 
3975  To->setImplementation(Impl);
3976  }
3977 
3978  if (shouldForceImportDeclContext(Kind)) {
3979  // Import all of the members of this class.
3980  ImportDeclContext(From, /*ForceImport=*/true);
3981  }
3982  return false;
3983 }
3984 
3987  if (!list)
3988  return nullptr;
3989 
3991  for (auto fromTypeParam : *list) {
3992  auto toTypeParam = cast_or_null<ObjCTypeParamDecl>(
3993  Importer.Import(fromTypeParam));
3994  if (!toTypeParam)
3995  return nullptr;
3996 
3997  toTypeParams.push_back(toTypeParam);
3998  }
3999 
4000  return ObjCTypeParamList::create(Importer.getToContext(),
4001  Importer.Import(list->getLAngleLoc()),
4002  toTypeParams,
4003  Importer.Import(list->getRAngleLoc()));
4004 }
4005 
4007  // If this class has a definition in the translation unit we're coming from,
4008  // but this particular declaration is not that definition, import the
4009  // definition and map to that.
4010  ObjCInterfaceDecl *Definition = D->getDefinition();
4011  if (Definition && Definition != D) {
4012  Decl *ImportedDef = Importer.Import(Definition);
4013  if (!ImportedDef)
4014  return nullptr;
4015 
4016  return Importer.Imported(D, ImportedDef);
4017  }
4018 
4019  // Import the major distinguishing characteristics of an @interface.
4020  DeclContext *DC, *LexicalDC;
4022  SourceLocation Loc;
4023  NamedDecl *ToD;
4024  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4025  return nullptr;
4026  if (ToD)
4027  return ToD;
4028 
4029  // Look for an existing interface with the same name.
4030  ObjCInterfaceDecl *MergeWithIface = nullptr;
4031  SmallVector<NamedDecl *, 2> FoundDecls;
4032  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
4033  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4034  if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary))
4035  continue;
4036 
4037  if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecls[I])))
4038  break;
4039  }
4040 
4041  // Create an interface declaration, if one does not already exist.
4042  ObjCInterfaceDecl *ToIface = MergeWithIface;
4043  if (!ToIface) {
4044  ToIface = ObjCInterfaceDecl::Create(Importer.getToContext(), DC,
4045  Importer.Import(D->getAtStartLoc()),
4046  Name.getAsIdentifierInfo(),
4047  /*TypeParamList=*/nullptr,
4048  /*PrevDecl=*/nullptr, Loc,
4050  ToIface->setLexicalDeclContext(LexicalDC);
4051  LexicalDC->addDeclInternal(ToIface);
4052  }
4053  Importer.Imported(D, ToIface);
4054  // Import the type parameter list after calling Imported, to avoid
4055  // loops when bringing in their DeclContext.
4058 
4059  if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToIface))
4060  return nullptr;
4061 
4062  return ToIface;
4063 }
4064 
4066  ObjCCategoryDecl *Category = cast_or_null<ObjCCategoryDecl>(
4067  Importer.Import(D->getCategoryDecl()));
4068  if (!Category)
4069  return nullptr;
4070 
4071  ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
4072  if (!ToImpl) {
4073  DeclContext *DC = Importer.ImportContext(D->getDeclContext());
4074  if (!DC)
4075  return nullptr;
4076 
4077  SourceLocation CategoryNameLoc = Importer.Import(D->getCategoryNameLoc());
4078  ToImpl = ObjCCategoryImplDecl::Create(Importer.getToContext(), DC,
4079  Importer.Import(D->getIdentifier()),
4080  Category->getClassInterface(),
4081  Importer.Import(D->getLocation()),
4082  Importer.Import(D->getAtStartLoc()),
4083  CategoryNameLoc);
4084 
4085  DeclContext *LexicalDC = DC;
4086  if (D->getDeclContext() != D->getLexicalDeclContext()) {
4087  LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
4088  if (!LexicalDC)
4089  return nullptr;
4090 
4091  ToImpl->setLexicalDeclContext(LexicalDC);
4092  }
4093 
4094  LexicalDC->addDeclInternal(ToImpl);
4095  Category->setImplementation(ToImpl);
4096  }
4097 
4098  Importer.Imported(D, ToImpl);
4099  ImportDeclContext(D);
4100  return ToImpl;
4101 }
4102 
4104  // Find the corresponding interface.
4105  ObjCInterfaceDecl *Iface = cast_or_null<ObjCInterfaceDecl>(
4106  Importer.Import(D->getClassInterface()));
4107  if (!Iface)
4108  return nullptr;
4109 
4110  // Import the superclass, if any.
4111  ObjCInterfaceDecl *Super = nullptr;
4112  if (D->getSuperClass()) {
4113  Super = cast_or_null<ObjCInterfaceDecl>(
4114  Importer.Import(D->getSuperClass()));
4115  if (!Super)
4116  return nullptr;
4117  }
4118 
4119  ObjCImplementationDecl *Impl = Iface->getImplementation();
4120  if (!Impl) {
4121  // We haven't imported an implementation yet. Create a new @implementation
4122  // now.
4123  Impl = ObjCImplementationDecl::Create(Importer.getToContext(),
4124  Importer.ImportContext(D->getDeclContext()),
4125  Iface, Super,
4126  Importer.Import(D->getLocation()),
4127  Importer.Import(D->getAtStartLoc()),
4128  Importer.Import(D->getSuperClassLoc()),
4129  Importer.Import(D->getIvarLBraceLoc()),
4130  Importer.Import(D->getIvarRBraceLoc()));
4131 
4132  if (D->getDeclContext() != D->getLexicalDeclContext()) {
4133  DeclContext *LexicalDC
4134  = Importer.ImportContext(D->getLexicalDeclContext());
4135  if (!LexicalDC)
4136  return nullptr;
4137  Impl->setLexicalDeclContext(LexicalDC);
4138  }
4139 
4140  // Associate the implementation with the class it implements.
4141  Iface->setImplementation(Impl);
4142  Importer.Imported(D, Iface->getImplementation());
4143  } else {
4144  Importer.Imported(D, Iface->getImplementation());
4145 
4146  // Verify that the existing @implementation has the same superclass.
4147  if ((Super && !Impl->getSuperClass()) ||
4148  (!Super && Impl->getSuperClass()) ||
4149  (Super && Impl->getSuperClass() &&
4151  Impl->getSuperClass()))) {
4152  Importer.ToDiag(Impl->getLocation(),
4153  diag::err_odr_objc_superclass_inconsistent)
4154  << Iface->getDeclName();
4155  // FIXME: It would be nice to have the location of the superclass
4156  // below.
4157  if (Impl->getSuperClass())
4158  Importer.ToDiag(Impl->getLocation(),
4159  diag::note_odr_objc_superclass)
4160  << Impl->getSuperClass()->getDeclName();
4161  else
4162  Importer.ToDiag(Impl->getLocation(),
4163  diag::note_odr_objc_missing_superclass);
4164  if (D->getSuperClass())
4165  Importer.FromDiag(D->getLocation(),
4166  diag::note_odr_objc_superclass)
4167  << D->getSuperClass()->getDeclName();
4168  else
4169  Importer.FromDiag(D->getLocation(),
4170  diag::note_odr_objc_missing_superclass);
4171  return nullptr;
4172  }
4173  }
4174 
4175  // Import all of the members of this @implementation.
4176  ImportDeclContext(D);
4177 
4178  return Impl;
4179 }
4180 
4182  // Import the major distinguishing characteristics of an @property.
4183  DeclContext *DC, *LexicalDC;
4185  SourceLocation Loc;
4186  NamedDecl *ToD;
4187  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4188  return nullptr;
4189  if (ToD)
4190  return ToD;
4191 
4192  // Check whether we have already imported this property.
4193  SmallVector<NamedDecl *, 2> FoundDecls;
4194  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
4195  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4196  if (ObjCPropertyDecl *FoundProp
4197  = dyn_cast<ObjCPropertyDecl>(FoundDecls[I])) {
4198  // Check property types.
4199  if (!Importer.IsStructurallyEquivalent(D->getType(),
4200  FoundProp->getType())) {
4201  Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent)
4202  << Name << D->getType() << FoundProp->getType();
4203  Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
4204  << FoundProp->getType();
4205  return nullptr;
4206  }
4207 
4208  // FIXME: Check property attributes, getters, setters, etc.?
4209 
4210  // Consider these properties to be equivalent.
4211  Importer.Imported(D, FoundProp);
4212  return FoundProp;
4213  }
4214  }
4215 
4216  // Import the type.
4217  TypeSourceInfo *TSI = Importer.Import(D->getTypeSourceInfo());
4218  if (!TSI)
4219  return nullptr;
4220 
4221  // Create the new property.
4222  ObjCPropertyDecl *ToProperty
4223  = ObjCPropertyDecl::Create(Importer.getToContext(), DC, Loc,
4224  Name.getAsIdentifierInfo(),
4225  Importer.Import(D->getAtLoc()),
4226  Importer.Import(D->getLParenLoc()),
4227  Importer.Import(D->getType()),
4228  TSI,
4230  Importer.Imported(D, ToProperty);
4231  ToProperty->setLexicalDeclContext(LexicalDC);
4232  LexicalDC->addDeclInternal(ToProperty);
4233 
4234  ToProperty->setPropertyAttributes(D->getPropertyAttributes());
4235  ToProperty->setPropertyAttributesAsWritten(
4237  ToProperty->setGetterName(Importer.Import(D->getGetterName()));
4238  ToProperty->setSetterName(Importer.Import(D->getSetterName()));
4239  ToProperty->setGetterMethodDecl(
4240  cast_or_null<ObjCMethodDecl>(Importer.Import(D->getGetterMethodDecl())));
4241  ToProperty->setSetterMethodDecl(
4242  cast_or_null<ObjCMethodDecl>(Importer.Import(D->getSetterMethodDecl())));
4243  ToProperty->setPropertyIvarDecl(
4244  cast_or_null<ObjCIvarDecl>(Importer.Import(D->getPropertyIvarDecl())));
4245  return ToProperty;
4246 }
4247 
4249  ObjCPropertyDecl *Property = cast_or_null<ObjCPropertyDecl>(
4250  Importer.Import(D->getPropertyDecl()));
4251  if (!Property)
4252  return nullptr;
4253 
4254  DeclContext *DC = Importer.ImportContext(D->getDeclContext());
4255  if (!DC)
4256  return nullptr;
4257 
4258  // Import the lexical declaration context.
4259  DeclContext *LexicalDC = DC;
4260  if (D->getDeclContext() != D->getLexicalDeclContext()) {
4261  LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
4262  if (!LexicalDC)
4263  return nullptr;
4264  }
4265 
4266  ObjCImplDecl *InImpl = dyn_cast<ObjCImplDecl>(LexicalDC);
4267  if (!InImpl)
4268  return nullptr;
4269 
4270  // Import the ivar (for an @synthesize).
4271  ObjCIvarDecl *Ivar = nullptr;
4272  if (D->getPropertyIvarDecl()) {
4273  Ivar = cast_or_null<ObjCIvarDecl>(
4274  Importer.Import(D->getPropertyIvarDecl()));
4275  if (!Ivar)
4276  return nullptr;
4277  }
4278 
4279  ObjCPropertyImplDecl *ToImpl
4280  = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
4281  Property->getQueryKind());
4282  if (!ToImpl) {
4283  ToImpl = ObjCPropertyImplDecl::Create(Importer.getToContext(), DC,
4284  Importer.Import(D->getLocStart()),
4285  Importer.Import(D->getLocation()),
4286  Property,
4288  Ivar,
4289  Importer.Import(D->getPropertyIvarDeclLoc()));
4290  ToImpl->setLexicalDeclContext(LexicalDC);
4291  Importer.Imported(D, ToImpl);
4292  LexicalDC->addDeclInternal(ToImpl);
4293  } else {
4294  // Check that we have the same kind of property implementation (@synthesize
4295  // vs. @dynamic).
4296  if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) {
4297  Importer.ToDiag(ToImpl->getLocation(),
4298  diag::err_odr_objc_property_impl_kind_inconsistent)
4299  << Property->getDeclName()
4300  << (ToImpl->getPropertyImplementation()
4302  Importer.FromDiag(D->getLocation(),
4303  diag::note_odr_objc_property_impl_kind)
4304  << D->getPropertyDecl()->getDeclName()
4306  return nullptr;
4307  }
4308 
4309  // For @synthesize, check that we have the same
4311  Ivar != ToImpl->getPropertyIvarDecl()) {
4312  Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
4313  diag::err_odr_objc_synthesize_ivar_inconsistent)
4314  << Property->getDeclName()
4315  << ToImpl->getPropertyIvarDecl()->getDeclName()
4316  << Ivar->getDeclName();
4317  Importer.FromDiag(D->getPropertyIvarDeclLoc(),
4318  diag::note_odr_objc_synthesize_ivar_here)
4319  << D->getPropertyIvarDecl()->getDeclName();
4320  return nullptr;
4321  }
4322 
4323  // Merge the existing implementation with the new implementation.
4324  Importer.Imported(D, ToImpl);
4325  }
4326 
4327  return ToImpl;
4328 }
4329 
4331  // For template arguments, we adopt the translation unit as our declaration
4332  // context. This context will be fixed when the actual template declaration
4333  // is created.
4334 
4335  // FIXME: Import default argument.
4336  return TemplateTypeParmDecl::Create(Importer.getToContext(),
4337  Importer.getToContext().getTranslationUnitDecl(),
4338  Importer.Import(D->getLocStart()),
4339  Importer.Import(D->getLocation()),
4340  D->getDepth(),
4341  D->getIndex(),
4342  Importer.Import(D->getIdentifier()),
4344  D->isParameterPack());
4345 }
4346 
4347 Decl *
4349  // Import the name of this declaration.
4350  DeclarationName Name = Importer.Import(D->getDeclName());
4351  if (D->getDeclName() && !Name)
4352  return nullptr;
4353 
4354  // Import the location of this declaration.
4355  SourceLocation Loc = Importer.Import(D->getLocation());
4356 
4357  // Import the type of this declaration.
4358  QualType T = Importer.Import(D->getType());
4359  if (T.isNull())
4360  return nullptr;
4361 
4362  // Import type-source information.
4363  TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
4364  if (D->getTypeSourceInfo() && !TInfo)
4365  return nullptr;
4366 
4367  // FIXME: Import default argument.
4368 
4370  Importer.getToContext().getTranslationUnitDecl(),
4371  Importer.Import(D->getInnerLocStart()),
4372  Loc, D->getDepth(), D->getPosition(),
4373  Name.getAsIdentifierInfo(),
4374  T, D->isParameterPack(), TInfo);
4375 }
4376 
4377 Decl *
4379  // Import the name of this declaration.
4380  DeclarationName Name = Importer.Import(D->getDeclName());
4381  if (D->getDeclName() && !Name)
4382  return nullptr;
4383 
4384  // Import the location of this declaration.
4385  SourceLocation Loc = Importer.Import(D->getLocation());
4386 
4387  // Import template parameters.
4388  TemplateParameterList *TemplateParams
4390  if (!TemplateParams)
4391  return nullptr;
4392 
4393  // FIXME: Import default argument.
4394 
4396  Importer.getToContext().getTranslationUnitDecl(),
4397  Loc, D->getDepth(), D->getPosition(),
4398  D->isParameterPack(),
4399  Name.getAsIdentifierInfo(),
4400  TemplateParams);
4401 }
4402 
4404  // If this record has a definition in the translation unit we're coming from,
4405  // but this particular declaration is not that definition, import the
4406  // definition and map to that.
4407  CXXRecordDecl *Definition
4408  = cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition());
4409  if (Definition && Definition != D->getTemplatedDecl()) {
4410  Decl *ImportedDef
4411  = Importer.Import(Definition->getDescribedClassTemplate());
4412  if (!ImportedDef)
4413  return nullptr;
4414 
4415  return Importer.Imported(D, ImportedDef);
4416  }
4417 
4418  // Import the major distinguishing characteristics of this class template.
4419  DeclContext *DC, *LexicalDC;
4421  SourceLocation Loc;
4422  NamedDecl *ToD;
4423  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4424  return nullptr;
4425  if (ToD)
4426  return ToD;
4427 
4428  // We may already have a template of the same name; try to find and match it.
4429  if (!DC->isFunctionOrMethod()) {
4430  SmallVector<NamedDecl *, 4> ConflictingDecls;
4431  SmallVector<NamedDecl *, 2> FoundDecls;
4432  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
4433  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4434  if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary))
4435  continue;
4436 
4437  Decl *Found = FoundDecls[I];
4438  if (ClassTemplateDecl *FoundTemplate
4439  = dyn_cast<ClassTemplateDecl>(Found)) {
4440  if (IsStructuralMatch(D, FoundTemplate)) {
4441  // The class templates structurally match; call it the same template.
4442  // FIXME: We may be filling in a forward declaration here. Handle
4443  // this case!
4444  Importer.Imported(D->getTemplatedDecl(),
4445  FoundTemplate->getTemplatedDecl());
4446  return Importer.Imported(D, FoundTemplate);
4447  }
4448  }
4449 
4450  ConflictingDecls.push_back(FoundDecls[I]);
4451  }
4452 
4453  if (!ConflictingDecls.empty()) {
4454  Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary,
4455  ConflictingDecls.data(),
4456  ConflictingDecls.size());
4457  }
4458 
4459  if (!Name)
4460  return nullptr;
4461  }
4462 
4463  CXXRecordDecl *DTemplated = D->getTemplatedDecl();
4464 
4465  // Create the declaration that is being templated.
4466  // Create the declaration that is being templated.
4467  CXXRecordDecl *D2Templated = cast_or_null<CXXRecordDecl>(
4468  Importer.Import(DTemplated));
4469  if (!D2Templated)
4470  return nullptr;
4471 
4472  // Resolve possible cyclic import.
4473  if (Decl *AlreadyImported = Importer.GetAlreadyImportedOrNull(D))
4474  return AlreadyImported;
4475 
4476  // Create the class template declaration itself.
4477  TemplateParameterList *TemplateParams
4479  if (!TemplateParams)
4480  return nullptr;
4481 
4483  Loc, Name, TemplateParams,
4484  D2Templated,
4485  /*PrevDecl=*/nullptr);
4486  D2Templated->setDescribedClassTemplate(D2);
4487 
4488  D2->setAccess(D->getAccess());
4489  D2->setLexicalDeclContext(LexicalDC);
4490  LexicalDC->addDeclInternal(D2);
4491 
4492  // Note the relationship between the class templates.
4493  Importer.Imported(D, D2);
4494  Importer.Imported(DTemplated, D2Templated);
4495 
4496  if (DTemplated->isCompleteDefinition() &&
4497  !D2Templated->isCompleteDefinition()) {
4498  // FIXME: Import definition!
4499  }
4500 
4501  return D2;
4502 }
4503 
4506  // If this record has a definition in the translation unit we're coming from,
4507  // but this particular declaration is not that definition, import the
4508  // definition and map to that.
4509  TagDecl *Definition = D->getDefinition();
4510  if (Definition && Definition != D) {
4511  Decl *ImportedDef = Importer.Import(Definition);
4512  if (!ImportedDef)
4513  return nullptr;
4514 
4515  return Importer.Imported(D, ImportedDef);
4516  }
4517 
4518  ClassTemplateDecl *ClassTemplate
4519  = cast_or_null<ClassTemplateDecl>(Importer.Import(
4520  D->getSpecializedTemplate()));
4521  if (!ClassTemplate)
4522  return nullptr;
4523 
4524  // Import the context of this declaration.
4525  DeclContext *DC = ClassTemplate->getDeclContext();
4526  if (!DC)
4527  return nullptr;
4528 
4529  DeclContext *LexicalDC = DC;
4530  if (D->getDeclContext() != D->getLexicalDeclContext()) {
4531  LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
4532  if (!LexicalDC)
4533  return nullptr;
4534  }
4535 
4536  // Import the location of this declaration.
4537  SourceLocation StartLoc = Importer.Import(D->getLocStart());
4538  SourceLocation IdLoc = Importer.Import(D->getLocation());
4539 
4540  // Import template arguments.
4541  SmallVector<TemplateArgument, 2> TemplateArgs;
4543  D->getTemplateArgs().size(),
4544  TemplateArgs))
4545  return nullptr;
4546 
4547  // Try to find an existing specialization with these template arguments.
4548  void *InsertPos = nullptr;
4550  = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
4551  if (D2) {
4552  // We already have a class template specialization with these template
4553  // arguments.
4554 
4555  // FIXME: Check for specialization vs. instantiation errors.
4556 
4557  if (RecordDecl *FoundDef = D2->getDefinition()) {
4558  if (!D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) {
4559  // The record types structurally match, or the "from" translation
4560  // unit only had a forward declaration anyway; call it the same
4561  // function.
4562  return Importer.Imported(D, FoundDef);
4563  }
4564  }
4565  } else {
4566  // Create a new specialization.
4568  D->getTagKind(), DC,
4569  StartLoc, IdLoc,
4570  ClassTemplate,
4571  TemplateArgs,
4572  /*PrevDecl=*/nullptr);
4574 
4575  // Add this specialization to the class template.
4576  ClassTemplate->AddSpecialization(D2, InsertPos);
4577 
4578  // Import the qualifier, if any.
4579  D2->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
4580 
4581  // Add the specialization to this context.
4582  D2->setLexicalDeclContext(LexicalDC);
4583  LexicalDC->addDeclInternal(D2);
4584  }
4585  Importer.Imported(D, D2);
4586 
4587  if (D->isCompleteDefinition() && ImportDefinition(D, D2))
4588  return nullptr;
4589 
4590  return D2;
4591 }
4592 
4594  // If this variable has a definition in the translation unit we're coming
4595  // from,
4596  // but this particular declaration is not that definition, import the
4597  // definition and map to that.
4598  VarDecl *Definition =
4599  cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition());
4600  if (Definition && Definition != D->getTemplatedDecl()) {
4601  Decl *ImportedDef = Importer.Import(Definition->getDescribedVarTemplate());
4602  if (!ImportedDef)
4603  return nullptr;
4604 
4605  return Importer.Imported(D, ImportedDef);
4606  }
4607 
4608  // Import the major distinguishing characteristics of this variable template.
4609  DeclContext *DC, *LexicalDC;
4611  SourceLocation Loc;
4612  NamedDecl *ToD;
4613  if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4614  return nullptr;
4615  if (ToD)
4616  return ToD;
4617 
4618  // We may already have a template of the same name; try to find and match it.
4619  assert(!DC->isFunctionOrMethod() &&
4620  "Variable templates cannot be declared at function scope");
4621  SmallVector<NamedDecl *, 4> ConflictingDecls;
4622  SmallVector<NamedDecl *, 2> FoundDecls;
4623  DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
4624  for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4625  if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary))
4626  continue;
4627 
4628  Decl *Found = FoundDecls[I];
4629  if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) {
4630  if (IsStructuralMatch(D, FoundTemplate)) {
4631  // The variable templates structurally match; call it the same template.
4632  Importer.Imported(D->getTemplatedDecl(),
4633  FoundTemplate->getTemplatedDecl());
4634  return Importer.Imported(D, FoundTemplate);
4635  }
4636  }
4637 
4638  ConflictingDecls.push_back(FoundDecls[I]);
4639  }
4640 
4641  if (!ConflictingDecls.empty()) {
4642  Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary,
4643  ConflictingDecls.data(),
4644  ConflictingDecls.size());
4645  }
4646 
4647  if (!Name)
4648  return nullptr;
4649 
4650  VarDecl *DTemplated = D->getTemplatedDecl();
4651 
4652  // Import the type.
4653  QualType T = Importer.Import(DTemplated->getType());
4654  if (T.isNull())
4655  return nullptr;
4656 
4657  // Create the declaration that is being templated.
4658  SourceLocation StartLoc = Importer.Import(DTemplated->getLocStart());
4659  SourceLocation IdLoc = Importer.Import(DTemplated->getLocation());
4660  TypeSourceInfo *TInfo = Importer.Import(DTemplated->getTypeSourceInfo());
4661  VarDecl *D2Templated = VarDecl::Create(Importer.getToContext(), DC, StartLoc,
4662  IdLoc, Name.getAsIdentifierInfo(), T,
4663  TInfo, DTemplated->getStorageClass());
4664  D2Templated->setAccess(DTemplated->getAccess());
4665  D2Templated->setQualifierInfo(Importer.Import(DTemplated->getQualifierLoc()));
4666  D2Templated->setLexicalDeclContext(LexicalDC);
4667 
4668  // Importer.Imported(DTemplated, D2Templated);
4669  // LexicalDC->addDeclInternal(D2Templated);
4670 
4671  // Merge the initializer.
4672  if (ImportDefinition(DTemplated, D2Templated))
4673  return nullptr;
4674 
4675  // Create the variable template declaration itself.
4676  TemplateParameterList *TemplateParams =
4678  if (!TemplateParams)
4679  return nullptr;
4680 
4682  Importer.getToContext(), DC, Loc, Name, TemplateParams, D2Templated);
4683  D2Templated->setDescribedVarTemplate(D2);
4684 
4685  D2->setAccess(D->getAccess());
4686  D2->setLexicalDeclContext(LexicalDC);
4687  LexicalDC->addDeclInternal(D2);
4688 
4689  // Note the relationship between the variable templates.
4690  Importer.Imported(D, D2);
4691  Importer.Imported(DTemplated, D2Templated);
4692 
4693  if (DTemplated->isThisDeclarationADefinition() &&
4694  !D2Templated->isThisDeclarationADefinition()) {
4695  // FIXME: Import definition!
4696  }
4697 
4698  return D2;
4699 }
4700 
4703  // If this record has a definition in the translation unit we're coming from,
4704  // but this particular declaration is not that definition, import the
4705  // definition and map to that.
4706  VarDecl *Definition = D->getDefinition();
4707  if (Definition && Definition != D) {
4708  Decl *ImportedDef = Importer.Import(Definition);
4709  if (!ImportedDef)
4710  return nullptr;
4711 
4712  return Importer.Imported(D, ImportedDef);
4713  }
4714 
4715  VarTemplateDecl *VarTemplate = cast_or_null<VarTemplateDecl>(
4716  Importer.Import(D->getSpecializedTemplate()));
4717  if (!VarTemplate)
4718  return nullptr;
4719 
4720  // Import the context of this declaration.
4721  DeclContext *DC = VarTemplate->getDeclContext();
4722  if (!DC)
4723  return nullptr;
4724 
4725  DeclContext *LexicalDC = DC;
4726  if (D->getDeclContext() != D->getLexicalDeclContext()) {
4727  LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
4728  if (!LexicalDC)
4729  return nullptr;
4730  }
4731 
4732  // Import the location of this declaration.
4733  SourceLocation StartLoc = Importer.Import(D->getLocStart());
4734  SourceLocation IdLoc = Importer.Import(D->getLocation());
4735 
4736  // Import template arguments.
4737  SmallVector<TemplateArgument, 2> TemplateArgs;
4739  D->getTemplateArgs().size(), TemplateArgs))
4740  return nullptr;
4741 
4742  // Try to find an existing specialization with these template arguments.
4743  void *InsertPos = nullptr;
4745  TemplateArgs, InsertPos);
4746  if (D2) {
4747  // We already have a variable template specialization with these template
4748  // arguments.
4749 
4750  // FIXME: Check for specialization vs. instantiation errors.
4751 
4752  if (VarDecl *FoundDef = D2->getDefinition()) {
4753  if (!D->isThisDeclarationADefinition() ||
4754  IsStructuralMatch(D, FoundDef)) {
4755  // The record types structurally match, or the "from" translation
4756  // unit only had a forward declaration anyway; call it the same
4757  // variable.
4758  return Importer.Imported(D, FoundDef);
4759  }
4760  }
4761  } else {
4762 
4763  // Import the type.
4764  QualType T = Importer.Import(D->getType());
4765  if (T.isNull())
4766  return nullptr;
4767  TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
4768 
4769  // Create a new specialization.
4771  Importer.getToContext(), DC, StartLoc, IdLoc, VarTemplate, T, TInfo,
4772  D->getStorageClass(), TemplateArgs);
4775 
4776  // Add this specialization to the class template.
4777  VarTemplate->AddSpecialization(D2, InsertPos);
4778 
4779  // Import the qualifier, if any.
4780  D2->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
4781 
4782  // Add the specialization to this context.
4783  D2->setLexicalDeclContext(LexicalDC);
4784  LexicalDC->addDeclInternal(D2);
4785  }
4786  Importer.Imported(D, D2);
4787 
4789  return nullptr;
4790 
4791  return D2;
4792 }
4793 
4794 //----------------------------------------------------------------------------
4795 // Import Statements
4796 //----------------------------------------------------------------------------
4797 
4799  if (DG.isNull())
4800  return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
4801  size_t NumDecls = DG.end() - DG.begin();
4802  SmallVector<Decl *, 1> ToDecls(NumDecls);
4803  auto &_Importer = this->Importer;
4804  std::transform(DG.begin(), DG.end(), ToDecls.begin(),
4805  [&_Importer](Decl *D) -> Decl * {
4806  return _Importer.Import(D);
4807  });
4808  return DeclGroupRef::Create(Importer.getToContext(),
4809  ToDecls.begin(),
4810  NumDecls);
4811 }
4812 
4814  Importer.FromDiag(S->getLocStart(), diag::err_unsupported_ast_node)
4815  << S->getStmtClassName();
4816  return nullptr;
4817  }
4818 
4819 
4822  for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
4823  IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
4824  if (!ToII)
4825  return nullptr;
4826  Names.push_back(ToII);
4827  }
4828  for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
4829  IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
4830  if (!ToII)
4831  return nullptr;
4832  Names.push_back(ToII);
4833  }
4834 
4836  for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
4837  StringLiteral *Clobber = cast_or_null<StringLiteral>(
4838  Importer.Import(S->getClobberStringLiteral(I)));
4839  if (!Clobber)
4840  return nullptr;
4841  Clobbers.push_back(Clobber);
4842  }
4843 
4844  SmallVector<StringLiteral *, 4> Constraints;
4845  for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
4846  StringLiteral *Output = cast_or_null<StringLiteral>(
4847  Importer.Import(S->getOutputConstraintLiteral(I)));
4848  if (!Output)
4849  return nullptr;
4850  Constraints.push_back(Output);
4851  }
4852 
4853  for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
4854  StringLiteral *Input = cast_or_null<StringLiteral>(
4855  Importer.Import(S->getInputConstraintLiteral(I)));
4856  if (!Input)
4857  return nullptr;
4858  Constraints.push_back(Input);
4859  }
4860 
4862  if (ImportArrayChecked(S->begin_outputs(), S->end_outputs(), Exprs.begin()))
4863  return nullptr;
4864 
4866  Exprs.begin() + S->getNumOutputs()))
4867  return nullptr;
4868 
4869  StringLiteral *AsmStr = cast_or_null<StringLiteral>(
4870  Importer.Import(S->getAsmString()));
4871  if (!AsmStr)
4872  return nullptr;
4873 
4874  return new (Importer.getToContext()) GCCAsmStmt(
4875  Importer.getToContext(),
4876  Importer.Import(S->getAsmLoc()),
4877  S->isSimple(),
4878  S->isVolatile(),
4879  S->getNumOutputs(),
4880  S->getNumInputs(),
4881  Names.data(),
4882  Constraints.data(),
4883  Exprs.data(),
4884  AsmStr,
4885  S->getNumClobbers(),
4886  Clobbers.data(),
4887  Importer.Import(S->getRParenLoc()));
4888 }
4889 
4892  for (Decl *ToD : ToDG) {
4893  if (!ToD)
4894  return nullptr;
4895  }
4896  SourceLocation ToStartLoc = Importer.Import(S->getStartLoc());
4897  SourceLocation ToEndLoc = Importer.Import(S->getEndLoc());
4898  return new (Importer.getToContext()) DeclStmt(ToDG, ToStartLoc, ToEndLoc);
4899 }
4900 
4902  SourceLocation ToSemiLoc = Importer.Import(S->getSemiLoc());
4903  return new (Importer.getToContext()) NullStmt(ToSemiLoc,
4904  S->hasLeadingEmptyMacro());
4905 }
4906 
4908  llvm::SmallVector<Stmt *, 8> ToStmts(S->size());
4909 
4910  if (ImportArrayChecked(S->body_begin(), S->body_end(), ToStmts.begin()))
4911  return nullptr;
4912 
4913  SourceLocation ToLBraceLoc = Importer.Import(S->getLBracLoc());
4914  SourceLocation ToRBraceLoc = Importer.Import(S->getRBracLoc());
4915  return new (Importer.getToContext()) CompoundStmt(Importer.getToContext(),
4916  ToStmts,
4917  ToLBraceLoc, ToRBraceLoc);
4918 }
4919 
4921  Expr *ToLHS = Importer.Import(S->getLHS());
4922  if (!ToLHS)
4923  return nullptr;
4924  Expr *ToRHS = Importer.Import(S->getRHS());
4925  if (!ToRHS && S->getRHS())
4926  return nullptr;
4927  SourceLocation ToCaseLoc = Importer.Import(S->getCaseLoc());
4928  SourceLocation ToEllipsisLoc = Importer.Import(S->getEllipsisLoc());
4929  SourceLocation ToColonLoc = Importer.Import(S->getColonLoc());
4930  return new (Importer.getToContext()) CaseStmt(ToLHS, ToRHS,
4931  ToCaseLoc, ToEllipsisLoc,
4932  ToColonLoc);
4933 }
4934 
4936  SourceLocation ToDefaultLoc = Importer.Import(S->getDefaultLoc());
4937  SourceLocation ToColonLoc = Importer.Import(S->getColonLoc());
4938  Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
4939  if (!ToSubStmt && S->getSubStmt())
4940  return nullptr;
4941  return new (Importer.getToContext()) DefaultStmt(ToDefaultLoc, ToColonLoc,
4942  ToSubStmt);
4943 }
4944 
4946  SourceLocation ToIdentLoc = Importer.Import(S->getIdentLoc());
4947  LabelDecl *ToLabelDecl =
4948  cast_or_null<LabelDecl>(Importer.Import(S->getDecl()));
4949  if (!ToLabelDecl && S->getDecl())
4950  return nullptr;
4951  Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
4952  if (!ToSubStmt && S->getSubStmt())
4953  return nullptr;
4954  return new (Importer.getToContext()) LabelStmt(ToIdentLoc, ToLabelDecl,
4955  ToSubStmt);
4956 }
4957 
4959  SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc());
4960  ArrayRef<const Attr*> FromAttrs(S->getAttrs());
4961  SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
4962  ASTContext &_ToContext = Importer.getToContext();
4963  std::transform(FromAttrs.begin(), FromAttrs.end(), ToAttrs.begin(),
4964  [&_ToContext](const Attr *A) -> const Attr * {
4965  return A->clone(_ToContext);
4966  });
4967  for (const Attr *ToA : ToAttrs) {
4968  if (!ToA)
4969  return nullptr;
4970  }
4971  Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
4972  if (!ToSubStmt && S->getSubStmt())
4973  return nullptr;
4974  return AttributedStmt::Create(Importer.getToContext(), ToAttrLoc,
4975  ToAttrs, ToSubStmt);
4976 }
4977 
4979  SourceLocation ToIfLoc = Importer.Import(S->getIfLoc());
4980  Stmt *ToInit = Importer.Import(S->getInit());
4981  if (!ToInit && S->getInit())
4982  return nullptr;
4983  VarDecl *ToConditionVariable = nullptr;
4984  if (VarDecl *FromConditionVariable = S->getConditionVariable()) {
4985  ToConditionVariable =
4986  dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable));
4987  if (!ToConditionVariable)
4988  return nullptr;
4989  }
4990  Expr *ToCondition = Importer.Import(S->getCond());
4991  if (!ToCondition && S->getCond())
4992  return nullptr;
4993  Stmt *ToThenStmt = Importer.Import(S->getThen());
4994  if (!ToThenStmt && S->getThen())
4995  return nullptr;
4996  SourceLocation ToElseLoc = Importer.Import(S->getElseLoc());
4997  Stmt *ToElseStmt = Importer.Import(S->getElse());
4998  if (!ToElseStmt && S->getElse())
4999  return nullptr;
5000  return new (Importer.getToContext()) IfStmt(Importer.getToContext(),
5001  ToIfLoc, S->isConstexpr(),
5002  ToInit,
5003  ToConditionVariable,
5004  ToCondition, ToThenStmt,
5005  ToElseLoc, ToElseStmt);
5006 }
5007 
5009  Stmt *ToInit = Importer.Import(S->getInit());
5010  if (!ToInit && S->getInit())
5011  return nullptr;
5012  VarDecl *ToConditionVariable = nullptr;
5013  if (VarDecl *FromConditionVariable = S->getConditionVariable()) {
5014  ToConditionVariable =
5015  dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable));
5016  if (!ToConditionVariable)
5017  return nullptr;
5018  }
5019  Expr *ToCondition = Importer.Import(S->getCond());
5020  if (!ToCondition && S->getCond())
5021  return nullptr;
5022  SwitchStmt *ToStmt = new (Importer.getToContext()) SwitchStmt(
5023  Importer.getToContext(), ToInit,
5024  ToConditionVariable, ToCondition);
5025  Stmt *ToBody = Importer.Import(S->getBody());
5026  if (!ToBody && S->getBody())
5027  return nullptr;
5028  ToStmt->setBody(ToBody);
5029  ToStmt->setSwitchLoc(Importer.Import(S->getSwitchLoc()));
5030  // Now we have to re-chain the cases.
5031  SwitchCase *LastChainedSwitchCase = nullptr;
5032  for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
5033  SC = SC->getNextSwitchCase()) {
5034  SwitchCase *ToSC = dyn_cast_or_null<SwitchCase>(Importer.Import(SC));
5035  if (!ToSC)
5036  return nullptr;
5037  if (LastChainedSwitchCase)
5038  LastChainedSwitchCase->setNextSwitchCase(ToSC);
5039  else
5040  ToStmt->setSwitchCaseList(ToSC);
5041  LastChainedSwitchCase = ToSC;
5042  }
5043  return ToStmt;
5044 }
5045 
5047  VarDecl *ToConditionVariable = nullptr;
5048  if (VarDecl *FromConditionVariable = S->getConditionVariable()) {
5049  ToConditionVariable =
5050  dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable));
5051  if (!ToConditionVariable)
5052  return nullptr;
5053  }
5054  Expr *ToCondition = Importer.Import(S->getCond());
5055  if (!ToCondition && S->getCond())
5056  return nullptr;
5057  Stmt *ToBody = Importer.Import(S->getBody());
5058  if (!ToBody && S->getBody())
5059  return nullptr;
5060  SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc());
5061  return new (Importer.getToContext()) WhileStmt(Importer.getToContext(),
5062  ToConditionVariable,
5063  ToCondition, ToBody,
5064  ToWhileLoc);
5065 }
5066 
5068  Stmt *ToBody = Importer.Import(S->getBody());
5069  if (!ToBody && S->getBody())
5070  return nullptr;
5071  Expr *ToCondition = Importer.Import(S->getCond());
5072  if (!ToCondition && S->getCond())
5073  return nullptr;
5074  SourceLocation ToDoLoc = Importer.Import(S->getDoLoc());
5075  SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc());
5076  SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
5077  return new (Importer.getToContext()) DoStmt(ToBody, ToCondition,
5078  ToDoLoc, ToWhileLoc,
5079  ToRParenLoc);
5080 }
5081 
5083  Stmt *ToInit = Importer.Import(S->getInit());
5084  if (!ToInit && S->getInit())
5085  return nullptr;
5086  Expr *ToCondition = Importer.Import(S->getCond());
5087  if (!ToCondition && S->getCond())
5088  return nullptr;
5089  VarDecl *ToConditionVariable = nullptr;
5090  if (VarDecl *FromConditionVariable = S->getConditionVariable()) {
5091  ToConditionVariable =
5092  dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable));
5093  if (!ToConditionVariable)
5094  return nullptr;
5095  }
5096  Expr *ToInc = Importer.Import(S->getInc());
5097  if (!ToInc && S->getInc())
5098  return nullptr;
5099  Stmt *ToBody = Importer.Import(S->getBody());
5100  if (!ToBody && S->getBody())
5101  return nullptr;
5102  SourceLocation ToForLoc = Importer.Import(S->getForLoc());
5103  SourceLocation ToLParenLoc = Importer.Import(S->getLParenLoc());
5104  SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
5105  return new (Importer.getToContext()) ForStmt(Importer.getToContext(),
5106  ToInit, ToCondition,
5107  ToConditionVariable,
5108  ToInc, ToBody,
5109  ToForLoc, ToLParenLoc,
5110  ToRParenLoc);
5111 }
5112 
5114  LabelDecl *ToLabel = nullptr;
5115  if (LabelDecl *FromLabel = S->getLabel()) {
5116  ToLabel = dyn_cast_or_null<LabelDecl>(Importer.Import(FromLabel));
5117  if (!ToLabel)
5118  return nullptr;
5119  }
5120  SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc());
5121  SourceLocation ToLabelLoc = Importer.Import(S->getLabelLoc());
5122  return new (Importer.getToContext()) GotoStmt(ToLabel,
5123  ToGotoLoc, ToLabelLoc);
5124 }
5125 
5127  SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc());
5128  SourceLocation ToStarLoc = Importer.Import(S->getStarLoc());
5129  Expr *ToTarget = Importer.Import(S->getTarget());
5130  if (!ToTarget && S->getTarget())
5131  return nullptr;
5132  return new (Importer.getToContext()) IndirectGotoStmt(ToGotoLoc, ToStarLoc,
5133  ToTarget);
5134 }
5135 
5137  SourceLocation ToContinueLoc = Importer.Import(S->getContinueLoc());
5138  return new (Importer.getToContext()) ContinueStmt(ToContinueLoc);
5139 }
5140 
5142  SourceLocation ToBreakLoc = Importer.Import(S->getBreakLoc());
5143  return new (Importer.getToContext()) BreakStmt(ToBreakLoc);
5144 }
5145 
5147  SourceLocation ToRetLoc = Importer.Import(S->getReturnLoc());
5148  Expr *ToRetExpr = Importer.Import(S->getRetValue());
5149  if (!ToRetExpr && S->getRetValue())
5150  return nullptr;
5151  VarDecl *NRVOCandidate = const_cast<VarDecl*>(S->getNRVOCandidate());
5152  VarDecl *ToNRVOCandidate = cast_or_null<VarDecl>(Importer.Import(NRVOCandidate));
5153  if (!ToNRVOCandidate && NRVOCandidate)
5154  return nullptr;
5155  return new (Importer.getToContext()) ReturnStmt(ToRetLoc, ToRetExpr,
5156  ToNRVOCandidate);
5157 }
5158 
5160  SourceLocation ToCatchLoc = Importer.Import(S->getCatchLoc());
5161  VarDecl *ToExceptionDecl = nullptr;
5162  if (VarDecl *FromExceptionDecl = S->getExceptionDecl()) {
5163  ToExceptionDecl =
5164  dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl));
5165  if (!ToExceptionDecl)
5166  return nullptr;
5167  }
5168  Stmt *ToHandlerBlock = Importer.Import(S->getHandlerBlock());
5169  if (!ToHandlerBlock && S->getHandlerBlock())
5170  return nullptr;
5171  return new (Importer.getToContext()) CXXCatchStmt(ToCatchLoc,
5172  ToExceptionDecl,
5173  ToHandlerBlock);
5174 }
5175 
5177  SourceLocation ToTryLoc = Importer.Import(S->getTryLoc());
5178  Stmt *ToTryBlock = Importer.Import(S->getTryBlock());
5179  if (!ToTryBlock && S->getTryBlock())
5180  return nullptr;
5181  SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
5182  for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
5183  CXXCatchStmt *FromHandler = S->getHandler(HI);
5184  if (Stmt *ToHandler = Importer.Import(FromHandler))
5185  ToHandlers[HI] = ToHandler;
5186  else
5187  return nullptr;
5188  }
5189  return CXXTryStmt::Create(Importer.getToContext(), ToTryLoc, ToTryBlock,
5190  ToHandlers);
5191 }
5192 
5194  DeclStmt *ToRange =
5195  dyn_cast_or_null<DeclStmt>(Importer.Import(S->getRangeStmt()));
5196  if (!ToRange && S->getRangeStmt())
5197  return nullptr;
5198  DeclStmt *ToBegin =
5199  dyn_cast_or_null<DeclStmt>(Importer.Import(S->getBeginStmt()));
5200  if (!ToBegin && S->getBeginStmt())
5201  return nullptr;
5202  DeclStmt *ToEnd =
5203  dyn_cast_or_null<DeclStmt>(Importer.Import(S->getEndStmt()));
5204  if (!ToEnd && S->getEndStmt())
5205  return nullptr;
5206  Expr *ToCond = Importer.Import(S->getCond());
5207  if (!ToCond && S->getCond())
5208  return nullptr;
5209  Expr *ToInc = Importer.Import(S->getInc());
5210  if (!ToInc && S->getInc())
5211  return nullptr;
5212  DeclStmt *ToLoopVar =
5213  dyn_cast_or_null<DeclStmt>(Importer.Import(S->getLoopVarStmt()));
5214  if (!ToLoopVar && S->getLoopVarStmt())
5215  return nullptr;
5216  Stmt *ToBody = Importer.Import(S->getBody());
5217  if (!ToBody && S->getBody())
5218  return nullptr;
5219  SourceLocation ToForLoc = Importer.Import(S->getForLoc());
5220  SourceLocation ToCoawaitLoc = Importer.Import(S->getCoawaitLoc());
5221  SourceLocation ToColonLoc = Importer.Import(S->getColonLoc());
5222  SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
5223  return new (Importer.getToContext()) CXXForRangeStmt(ToRange, ToBegin, ToEnd,
5224  ToCond, ToInc,
5225  ToLoopVar, ToBody,
5226  ToForLoc, ToCoawaitLoc,
5227  ToColonLoc, ToRParenLoc);
5228 }
5229 
5231  Stmt *ToElem = Importer.Import(S->getElement());
5232  if (!ToElem && S->getElement())
5233  return nullptr;
5234  Expr *ToCollect = Importer.Import(S->getCollection());
5235  if (!ToCollect && S->getCollection())
5236  return nullptr;
5237  Stmt *ToBody = Importer.Import(S->getBody());
5238  if (!ToBody && S->getBody())
5239  return nullptr;
5240  SourceLocation ToForLoc = Importer.Import(S->getForLoc());
5241  SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
5242  return new (Importer.getToContext()) ObjCForCollectionStmt(ToElem,
5243  ToCollect,
5244  ToBody, ToForLoc,
5245  ToRParenLoc);
5246 }
5247 
5249  SourceLocation ToAtCatchLoc = Importer.Import(S->getAtCatchLoc());
5250  SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
5251  VarDecl *ToExceptionDecl = nullptr;
5252  if (VarDecl *FromExceptionDecl = S->getCatchParamDecl()) {
5253  ToExceptionDecl =
5254  dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl));
5255  if (!ToExceptionDecl)
5256  return nullptr;
5257  }
5258  Stmt *ToBody = Importer.Import(S->getCatchBody());
5259  if (!ToBody && S->getCatchBody())
5260  return nullptr;
5261  return new (Importer.getToContext()) ObjCAtCatchStmt(ToAtCatchLoc,
5262  ToRParenLoc,
5263  ToExceptionDecl,
5264  ToBody);
5265 }
5266 
5268  SourceLocation ToAtFinallyLoc = Importer.Import(S->getAtFinallyLoc());
5269  Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyBody());
5270  if (!ToAtFinallyStmt && S->getFinallyBody())
5271  return nullptr;
5272  return new (Importer.getToContext()) ObjCAtFinallyStmt(ToAtFinallyLoc,
5273  ToAtFinallyStmt);
5274 }
5275 
5277  SourceLocation ToAtTryLoc = Importer.Import(S->getAtTryLoc());
5278  Stmt *ToAtTryStmt = Importer.Import(S->getTryBody());
5279  if (!ToAtTryStmt && S->getTryBody())
5280  return nullptr;
5281  SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
5282  for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
5283  ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
5284  if (Stmt *ToCatchStmt = Importer.Import(FromCatchStmt))
5285  ToCatchStmts[CI] = ToCatchStmt;
5286  else
5287  return nullptr;
5288  }
5289  Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyStmt());
5290  if (!ToAtFinallyStmt && S->getFinallyStmt())
5291  return nullptr;
5292  return ObjCAtTryStmt::Create(Importer.getToContext(),
5293  ToAtTryLoc, ToAtTryStmt,
5294  ToCatchStmts.begin(), ToCatchStmts.size(),
5295  ToAtFinallyStmt);
5296 }
5297 
5300  SourceLocation ToAtSynchronizedLoc =
5301  Importer.Import(S->getAtSynchronizedLoc());
5302  Expr *ToSynchExpr = Importer.Import(S->getSynchExpr());
5303  if (!ToSynchExpr && S->getSynchExpr())
5304  return nullptr;
5305  Stmt *ToSynchBody = Importer.Import(S->getSynchBody());
5306  if (!ToSynchBody && S->getSynchBody())
5307  return nullptr;
5308  return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
5309  ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
5310 }
5311 
5313  SourceLocation ToAtThrowLoc = Importer.Import(S->getThrowLoc());
5314  Expr *ToThrow = Importer.Import(S->getThrowExpr());
5315  if (!ToThrow && S->getThrowExpr())
5316  return nullptr;
5317  return new (Importer.getToContext()) ObjCAtThrowStmt(ToAtThrowLoc, ToThrow);
5318 }
5319 
5322  SourceLocation ToAtLoc = Importer.Import(S->getAtLoc());
5323  Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
5324  if (!ToSubStmt && S->getSubStmt())
5325  return nullptr;
5326  return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(ToAtLoc,
5327  ToSubStmt);
5328 }
5329 
5330 //----------------------------------------------------------------------------
5331 // Import Expressions
5332 //----------------------------------------------------------------------------
5334  Importer.FromDiag(E->getLocStart(), diag::err_unsupported_ast_node)
5335  << E->getStmtClassName();
5336  return nullptr;
5337 }
5338 
5340  QualType T = Importer.Import(E->getType());
5341  if (T.isNull())
5342  return nullptr;
5343 
5344  Expr *SubExpr = Importer.Import(E->getSubExpr());
5345  if (!SubExpr && E->getSubExpr())
5346  return nullptr;
5347 
5348  TypeSourceInfo *TInfo = Importer.Import(E->getWrittenTypeInfo());
5349  if (!TInfo)
5350  return nullptr;
5351 
5352  return new (Importer.getToContext()) VAArgExpr(
5353  Importer.Import(E->getBuiltinLoc()), SubExpr, TInfo,
5354  Importer.Import(E->getRParenLoc()), T, E->isMicrosoftABI());
5355 }
5356 
5357 
5359  QualType T = Importer.Import(E->getType());
5360  if (T.isNull())
5361  return nullptr;
5362 
5363  return new (Importer.getToContext()) GNUNullExpr(
5364  T, Importer.Import(E->getExprLoc()));
5365 }
5366 
5368  QualType T = Importer.Import(E->getType());
5369  if (T.isNull())
5370  return nullptr;
5371 
5372  StringLiteral *SL = cast_or_null<StringLiteral>(
5373  Importer.Import(E->getFunctionName()));
5374  if (!SL && E->getFunctionName())
5375  return nullptr;
5376 
5377  return new (Importer.getToContext()) PredefinedExpr(
5378  Importer.Import(E->getExprLoc()), T, E->getIdentType(), SL);
5379 }
5380 
5382  ValueDecl *ToD = cast_or_null<ValueDecl>(Importer.Import(E->getDecl()));
5383  if (!ToD)
5384  return nullptr;
5385 
5386  NamedDecl *FoundD = nullptr;
5387  if (E->getDecl() != E->getFoundDecl()) {
5388  FoundD = cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl()));
5389  if (!FoundD)
5390  return nullptr;
5391  }
5392 
5393  QualType T = Importer.Import(E->getType());
5394  if (T.isNull())
5395  return nullptr;
5396 
5397  DeclRefExpr *DRE = DeclRefExpr::Create(Importer.getToContext(),
5398  Importer.Import(E->getQualifierLoc()),
5399  Importer.Import(E->getTemplateKeywordLoc()),
5400  ToD,
5402  Importer.Import(E->getLocation()),
5403  T, E->getValueKind(),
5404  FoundD,
5405  /*FIXME:TemplateArgs=*/nullptr);
5406  if (E->hadMultipleCandidates())
5407  DRE->setHadMultipleCandidates(true);
5408  return DRE;
5409 }
5410 
5412  QualType T = Importer.Import(E->getType());
5413  if (T.isNull())
5414  return NULL;
5415 
5416  return new (Importer.getToContext()) ImplicitValueInitExpr(T);
5417 }
5418 
5421  if (D.isFieldDesignator()) {
5422  IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
5423  // Caller checks for import error
5424  return Designator(ToFieldName, Importer.Import(D.getDotLoc()),
5425  Importer.Import(D.getFieldLoc()));
5426  }
5427  if (D.isArrayDesignator())
5428  return Designator(D.getFirstExprIndex(),
5429  Importer.Import(D.getLBracketLoc()),
5430  Importer.Import(D.getRBracketLoc()));
5431 
5432  assert(D.isArrayRangeDesignator());
5433  return Designator(D.getFirstExprIndex(),
5434  Importer.Import(D.getLBracketLoc()),
5435  Importer.Import(D.getEllipsisLoc()),
5436  Importer.Import(D.getRBracketLoc()));
5437 }
5438 
5439 
5441  Expr *Init = cast_or_null<Expr>(Importer.Import(DIE->getInit()));
5442  if (!Init)
5443  return nullptr;
5444 
5445  SmallVector<Expr *, 4> IndexExprs(DIE->getNumSubExprs() - 1);
5446  // List elements from the second, the first is Init itself
5447  for (unsigned I = 1, E = DIE->getNumSubExprs(); I < E; I++) {
5448  if (Expr *Arg = cast_or_null<Expr>(Importer.Import(DIE->getSubExpr(I))))
5449  IndexExprs[I - 1] = Arg;
5450  else
5451  return nullptr;
5452  }
5453 
5454  SmallVector<Designator, 4> Designators(DIE->size());
5455  llvm::transform(DIE->designators(), Designators.begin(),
5456  [this](const Designator &D) -> Designator {
5457  return ImportDesignator(D);
5458  });
5459 
5460  for (const Designator &D : DIE->designators())
5461  if (D.isFieldDesignator() && !D.getFieldName())
5462  return nullptr;
5463 
5465  Importer.getToContext(), Designators,
5466  IndexExprs, Importer.Import(DIE->getEqualOrColonLoc()),
5467  DIE->usesGNUSyntax(), Init);
5468 }
5469 
5471  QualType T = Importer.Import(E->getType());
5472  if (T.isNull())
5473  return nullptr;
5474 
5475  return new (Importer.getToContext())
5476  CXXNullPtrLiteralExpr(T, Importer.Import(E->getLocation()));
5477 }
5478 
5480  QualType T = Importer.Import(E->getType());
5481  if (T.isNull())
5482  return nullptr;
5483 
5484  return IntegerLiteral::Create(Importer.getToContext(),
5485  E->getValue(), T,
5486  Importer.Import(E->getLocation()));
5487 }
5488 
5490  QualType T = Importer.Import(E->getType());
5491  if (T.isNull())
5492  return nullptr;
5493 
5494  return FloatingLiteral::Create(Importer.getToContext(),
5495  E->getValue(), E->isExact(), T,
5496  Importer.Import(E->getLocation()));
5497 }
5498 
5500  QualType T = Importer.Import(E->getType());
5501  if (T.isNull())
5502  return nullptr;
5503 
5504  return new (Importer.getToContext()) CharacterLiteral(E->getValue(),
5505  E->getKind(), T,
5506  Importer.Import(E->getLocation()));
5507 }
5508 
5510  QualType T = Importer.Import(E->getType());
5511  if (T.isNull())
5512  return nullptr;
5513 
5515  ImportArray(E->tokloc_begin(), E->tokloc_end(), Locations.begin());
5516 
5517  return StringLiteral::Create(Importer.getToContext(), E->getBytes(),
5518  E->getKind(), E->isPascal(), T,
5519  Locations.data(), Locations.size());
5520 }
5521 
5523  QualType T = Importer.Import(E->getType());
5524  if (T.isNull())
5525  return nullptr;
5526 
5527  TypeSourceInfo *TInfo = Importer.Import(E->getTypeSourceInfo());
5528  if (!TInfo)
5529  return nullptr;
5530 
5531  Expr *Init = Importer.Import(E->getInitializer());
5532  if (!Init)
5533  return nullptr;
5534 
5535  return new (Importer.getToContext()) CompoundLiteralExpr(
5536  Importer.Import(E->getLParenLoc()), TInfo, T, E->getValueKind(),
5537  Init, E->isFileScope());
5538 }
5539 
5541  QualType T = Importer.Import(E->getType());
5542  if (T.isNull())
5543  return nullptr;
5544 
5546  if (ImportArrayChecked(
5547  E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
5548  Exprs.begin()))
5549  return nullptr;
5550 
5551  return new (Importer.getToContext()) AtomicExpr(
5552  Importer.Import(E->getBuiltinLoc()), Exprs, T, E->getOp(),
5553  Importer.Import(E->getRParenLoc()));
5554 }
5555 
5557  QualType T = Importer.Import(E->getType());
5558  if (T.isNull())
5559  return nullptr;
5560 
5561  LabelDecl *ToLabel = cast_or_null<LabelDecl>(Importer.Import(E->getLabel()));
5562  if (!ToLabel)
5563  return nullptr;
5564 
5565  return new (Importer.getToContext()) AddrLabelExpr(
5566  Importer.Import(E->getAmpAmpLoc()), Importer.Import(E->getLabelLoc()),
5567  ToLabel, T);
5568 }
5569 
5571  Expr *SubExpr = Importer.Import(E->getSubExpr());
5572  if (!SubExpr)
5573  return nullptr;
5574 
5575  return new (Importer.getToContext())
5576  ParenExpr(Importer.Import(E->getLParen()),
5577  Importer.Import(E->getRParen()),
5578  SubExpr);
5579 }
5580 
5582  SmallVector<Expr *, 4> Exprs(E->getNumExprs());
5583  if (ImportArrayChecked(
5584  E->getExprs(), E->getExprs() + E->getNumExprs(), Exprs.begin()))
5585  return nullptr;
5586 
5587  return new (Importer.getToContext()) ParenListExpr(
5588  Importer.getToContext(), Importer.Import(E->getLParenLoc()),
5589  Exprs, Importer.Import(E->getLParenLoc()));
5590 }
5591 
5593  QualType T = Importer.Import(E->getType());
5594  if (T.isNull())
5595  return nullptr;
5596 
5597  CompoundStmt *ToSubStmt = cast_or_null<CompoundStmt>(
5598  Importer.Import(E->getSubStmt()));
5599  if (!ToSubStmt && E->getSubStmt())
5600  return nullptr;
5601 
5602  return new (Importer.getToContext()) StmtExpr(ToSubStmt, T,
5603  Importer.Import(E->getLParenLoc()), Importer.Import(E->getRParenLoc()));
5604 }
5605 
5607  QualType T = Importer.Import(E->getType());
5608  if (T.isNull())
5609  return nullptr;
5610 
5611  Expr *SubExpr = Importer.Import(E->getSubExpr());
5612  if (!SubExpr)
5613  return nullptr;
5614 
5615  return new (Importer.getToContext()) UnaryOperator(SubExpr, E->getOpcode(),
5616  T, E->getValueKind(),
5617  E->getObjectKind(),
5618  Importer.Import(E->getOperatorLoc()));
5619 }
5620 
5623  QualType ResultType = Importer.Import(E->getType());
5624 
5625  if (E->isArgumentType()) {
5626  TypeSourceInfo *TInfo = Importer.Import(E->getArgumentTypeInfo());
5627  if (!TInfo)
5628  return nullptr;
5629 
5630  return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(),
5631  TInfo, ResultType,
5632  Importer.Import(E->getOperatorLoc()),
5633  Importer.Import(E->getRParenLoc()));
5634  }
5635 
5636  Expr *SubExpr = Importer.Import(E->getArgumentExpr());
5637  if (!SubExpr)
5638  return nullptr;
5639 
5640  return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(),
5641  SubExpr, ResultType,
5642  Importer.Import(E->getOperatorLoc()),
5643  Importer.Import(E->getRParenLoc()));
5644 }
5645 
5647  QualType T = Importer.Import(E->getType());
5648  if (T.isNull())
5649  return nullptr;
5650 
5651  Expr *LHS = Importer.Import(E->getLHS());
5652  if (!LHS)
5653  return nullptr;
5654 
5655  Expr *RHS = Importer.Import(E->getRHS());
5656  if (!RHS)
5657  return nullptr;
5658 
5659  return new (Importer.getToContext()) BinaryOperator(LHS, RHS, E->getOpcode(),
5660  T, E->getValueKind(),
5661  E->getObjectKind(),
5662  Importer.Import(E->getOperatorLoc()),
5663  E->isFPContractable());
5664 }
5665 
5667  QualType T = Importer.Import(E->getType());
5668  if (T.isNull())
5669  return nullptr;
5670 
5671  Expr *ToLHS = Importer.Import(E->getLHS());
5672  if (!ToLHS)
5673  return nullptr;
5674 
5675  Expr *ToRHS = Importer.Import(E->getRHS());
5676  if (!ToRHS)
5677  return nullptr;
5678 
5679  Expr *ToCond = Importer.Import(E->getCond());
5680  if (!ToCond)
5681  return nullptr;
5682 
5683  return new (Importer.getToContext()) ConditionalOperator(
5684  ToCond, Importer.Import(E->getQuestionLoc()),
5685  ToLHS, Importer.Import(E->getColonLoc()),
5686  ToRHS, T, E->getValueKind(), E->getObjectKind());
5687 }
5688 
5691  QualType T = Importer.Import(E->getType());
5692  if (T.isNull())
5693  return nullptr;
5694 
5695  Expr *Common = Importer.Import(E->getCommon());
5696  if (!Common)
5697  return nullptr;
5698 
5699  Expr *Cond = Importer.Import(E->getCond());
5700  if (!Cond)
5701  return nullptr;
5702 
5703  OpaqueValueExpr *OpaqueValue = cast_or_null<OpaqueValueExpr>(
5704  Importer.Import(E->getOpaqueValue()));
5705  if (!OpaqueValue)
5706  return nullptr;
5707 
5708  Expr *TrueExpr = Importer.Import(E->getTrueExpr());
5709  if (!TrueExpr)
5710  return nullptr;
5711 
5712  Expr *FalseExpr = Importer.Import(E->getFalseExpr());
5713  if (!FalseExpr)
5714  return nullptr;
5715 
5716  return new (Importer.getToContext()) BinaryConditionalOperator(
5717  Common, OpaqueValue, Cond, TrueExpr, FalseExpr,
5718  Importer.Import(E->getQuestionLoc()), Importer.Import(E->getColonLoc()),
5719  T, E->getValueKind(), E->getObjectKind());
5720 }
5721 
5723  QualType T = Importer.Import(E->getType());
5724  if (T.isNull())
5725  return nullptr;
5726 
5727  Expr *SourceExpr = Importer.Import(E->getSourceExpr());
5728  if (!SourceExpr && E->getSourceExpr())
5729  return nullptr;
5730 
5731  return new (Importer.getToContext()) OpaqueValueExpr(
5732  Importer.Import(E->getExprLoc()), T, E->getValueKind(),
5733  E->getObjectKind(), SourceExpr);
5734 }
5735 
5737  QualType T = Importer.Import(E->getType());
5738  if (T.isNull())
5739  return nullptr;
5740 
5741  QualType CompLHSType = Importer.Import(E->getComputationLHSType());
5742  if (CompLHSType.isNull())
5743  return nullptr;
5744 
5745  QualType CompResultType = Importer.Import(E->getComputationResultType());
5746  if (CompResultType.isNull())
5747  return nullptr;
5748 
5749  Expr *LHS = Importer.Import(E->getLHS());
5750  if (!LHS)
5751  return nullptr;
5752 
5753  Expr *RHS = Importer.Import(E->getRHS());
5754  if (!RHS)
5755  return nullptr;
5756 
5757  return new (Importer.getToContext())
5758  CompoundAssignOperator(LHS, RHS, E->getOpcode(),
5759  T, E->getValueKind(),
5760  E->getObjectKind(),
5761  CompLHSType, CompResultType,
5762  Importer.Import(E->getOperatorLoc()),
5763  E->isFPContractable());
5764 }
5765 
5766 static bool ImportCastPath(CastExpr *E, CXXCastPath &Path) {
5767  if (E->path_empty()) return false;
5768 
5769  // TODO: import cast paths
5770  return true;
5771 }
5772 
5774  QualType T = Importer.Import(E->getType());
5775  if (T.isNull())
5776  return nullptr;
5777 
5778  Expr *SubExpr = Importer.Import(E->getSubExpr());
5779  if (!SubExpr)
5780  return nullptr;
5781 
5782  CXXCastPath BasePath;
5783  if (ImportCastPath(E, BasePath))
5784  return nullptr;
5785 
5786  return ImplicitCastExpr::Create(Importer.getToContext(), T, E->getCastKind(),
5787  SubExpr, &BasePath, E->getValueKind());
5788 }
5789 
5791  QualType T = Importer.Import(E->getType());
5792  if (T.isNull())
5793  return nullptr;
5794 
5795  Expr *SubExpr = Importer.Import(E->getSubExpr());
5796  if (!SubExpr)
5797  return nullptr;
5798 
5799  TypeSourceInfo *TInfo = Importer.Import(E->getTypeInfoAsWritten());
5800  if (!TInfo && E->getTypeInfoAsWritten())
5801  return nullptr;
5802 
5803  CXXCastPath BasePath;
5804  if (ImportCastPath(E, BasePath))
5805  return nullptr;
5806 
5807  return CStyleCastExpr::Create(Importer.getToContext(), T,
5808  E->getValueKind(), E->getCastKind(),
5809  SubExpr, &BasePath, TInfo,
5810  Importer.Import(E->getLParenLoc()),
5811  Importer.Import(E->getRParenLoc()));
5812 }
5813 
5815  QualType T = Importer.Import(E->getType());
5816  if (T.isNull())
5817  return nullptr;
5818 
5819  CXXConstructorDecl *ToCCD =
5820  dyn_cast_or_null<CXXConstructorDecl>(Importer.Import(E->getConstructor()));
5821  if (!ToCCD)
5822  return nullptr;
5823 
5824  SmallVector<Expr *, 6> ToArgs(E->getNumArgs());
5825  if (ImportArrayChecked(E->getArgs(), E->getArgs() + E->getNumArgs(),
5826  ToArgs.begin()))
5827  return nullptr;
5828 
5829  return CXXConstructExpr::Create(Importer.getToContext(), T,
5830  Importer.Import(E->getLocation()),
5831  ToCCD, E->isElidable(),
5832  ToArgs, E->hadMultipleCandidates(),
5833  E->isListInitialization(),
5836  E->getConstructionKind(),
5837  Importer.Import(E->getParenOrBraceRange()));
5838 }
5839 
5841  QualType T = Importer.Import(E->getType());
5842  if (T.isNull())
5843  return nullptr;
5844 
5845  Expr *ToFn = Importer.Import(E->getCallee());
5846  if (!ToFn)
5847  return nullptr;
5848 
5849  SmallVector<Expr *, 4> ToArgs(E->getNumArgs());
5850 
5851  if (ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
5852  return nullptr;
5853 
5854  return new (Importer.getToContext()) CXXMemberCallExpr(
5855  Importer.getToContext(), ToFn, ToArgs, T, E->getValueKind(),
5856  Importer.Import(E->getRParenLoc()));
5857 }
5858 
5860  QualType T = Importer.Import(E->getType());
5861  if (T.isNull())
5862  return nullptr;
5863 
5864  return new (Importer.getToContext())
5865  CXXThisExpr(Importer.Import(E->getLocation()), T, E->isImplicit());
5866 }
5867 
5869  QualType T = Importer.Import(E->getType());
5870  if (T.isNull())
5871  return nullptr;
5872 
5873  return new (Importer.getToContext())
5874  CXXBoolLiteralExpr(E->getValue(), T, Importer.Import(E->getLocation()));
5875 }
5876 
5877 
5879  QualType T = Importer.Import(E->getType());
5880  if (T.isNull())
5881  return nullptr;
5882 
5883  Expr *ToBase = Importer.Import(E->getBase());
5884  if (!ToBase && E->getBase())
5885  return nullptr;
5886 
5887  ValueDecl *ToMember = dyn_cast<ValueDecl>(Importer.Import(E->getMemberDecl()));
5888  if (!ToMember && E->getMemberDecl())
5889  return nullptr;
5890 
5891  DeclAccessPair ToFoundDecl = DeclAccessPair::make(
5892  dyn_cast<NamedDecl>(Importer.Import(E->getFoundDecl().getDecl())),
5893  E->getFoundDecl().getAccess());
5894 
5895  DeclarationNameInfo ToMemberNameInfo(
5896  Importer.Import(E->getMemberNameInfo().getName()),
5897  Importer.Import(E->getMemberNameInfo().getLoc()));
5898 
5899  if (E->hasExplicitTemplateArgs()) {
5900  return nullptr; // FIXME: handle template arguments
5901  }
5902 
5903  return MemberExpr::Create(Importer.getToContext(), ToBase,
5904  E->isArrow(),
5905  Importer.Import(E->getOperatorLoc()),
5906  Importer.Import(E->getQualifierLoc()),
5907  Importer.Import(E->getTemplateKeywordLoc()),
5908  ToMember, ToFoundDecl, ToMemberNameInfo,
5909  nullptr, T, E->getValueKind(),
5910  E->getObjectKind());
5911 }
5912 
5914  QualType T = Importer.Import(E->getType());
5915  if (T.isNull())
5916  return nullptr;
5917 
5918  Expr *ToCallee = Importer.Import(E->getCallee());
5919  if (!ToCallee && E->getCallee())
5920  return nullptr;
5921 
5922  unsigned NumArgs = E->getNumArgs();
5923 
5924  llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
5925 
5926  for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) {
5927  Expr *FromArg = E->getArg(ai);
5928  Expr *ToArg = Importer.Import(FromArg);
5929  if (!ToArg)
5930  return nullptr;
5931  ToArgs[ai] = ToArg;
5932  }
5933 
5934  Expr **ToArgs_Copied = new (Importer.getToContext())
5935  Expr*[NumArgs];
5936 
5937  for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai)
5938  ToArgs_Copied[ai] = ToArgs[ai];
5939 
5940  return new (Importer.getToContext())
5941  CallExpr(Importer.getToContext(), ToCallee,
5942  llvm::makeArrayRef(ToArgs_Copied, NumArgs), T, E->getValueKind(),
5943  Importer.Import(E->getRParenLoc()));
5944 }
5945 
5947  QualType T = Importer.Import(ILE->getType());
5948  if (T.isNull())
5949  return nullptr;
5950 
5952  if (ImportArrayChecked(
5953  ILE->getInits(), ILE->getInits() + ILE->getNumInits(), Exprs.begin()))
5954  return nullptr;
5955 
5956  ASTContext &ToCtx = Importer.getToContext();
5957  InitListExpr *To = new (ToCtx) InitListExpr(
5958  ToCtx, Importer.Import(ILE->getLBraceLoc()),
5959  Exprs, Importer.Import(ILE->getLBraceLoc()));
5960  To->setType(T);
5961 
5962  if (ILE->hasArrayFiller()) {
5963  Expr *Filler = Importer.Import(ILE->getArrayFiller());
5964  if (!Filler)
5965  return nullptr;
5966  To->setArrayFiller(Filler);
5967  }
5968 
5969  if (FieldDecl *FromFD = ILE->getInitializedFieldInUnion()) {
5970  FieldDecl *ToFD = cast_or_null<FieldDecl>(Importer.Import(FromFD));
5971  if (!ToFD)
5972  return nullptr;
5973  To->setInitializedFieldInUnion(ToFD);
5974  }
5975 
5976  if (InitListExpr *SyntForm = ILE->getSyntacticForm()) {
5977  InitListExpr *ToSyntForm = cast_or_null<InitListExpr>(
5978  Importer.Import(SyntForm));
5979  if (!ToSyntForm)
5980  return nullptr;
5981  To->setSyntacticForm(ToSyntForm);
5982  }
5983 
5985  To->setValueDependent(ILE->isValueDependent());
5987 
5988  return To;
5989 }
5990 
5992  FieldDecl *ToField = llvm::dyn_cast_or_null<FieldDecl>(
5993  Importer.Import(DIE->getField()));
5994  if (!ToField && DIE->getField())
5995  return nullptr;
5996 
5998  Importer.getToContext(), Importer.Import(DIE->getLocStart()), ToField);
5999 }
6000 
6002  QualType ToType = Importer.Import(E->getType());
6003  if (ToType.isNull() && !E->getType().isNull())
6004  return nullptr;
6005  ExprValueKind VK = E->getValueKind();
6006  CastKind CK = E->getCastKind();
6007  Expr *ToOp = Importer.Import(E->getSubExpr());
6008  if (!ToOp && E->getSubExpr())
6009  return nullptr;
6010  CXXCastPath BasePath;
6011  if (ImportCastPath(E, BasePath))
6012  return nullptr;
6013  TypeSourceInfo *ToWritten = Importer.Import(E->getTypeInfoAsWritten());
6014  SourceLocation ToOperatorLoc = Importer.Import(E->getOperatorLoc());
6015  SourceLocation ToRParenLoc = Importer.Import(E->getRParenLoc());
6016  SourceRange ToAngleBrackets = Importer.Import(E->getAngleBrackets());
6017 
6018  if (isa<CXXStaticCastExpr>(E)) {
6020  Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath,
6021  ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
6022  } else if (isa<CXXDynamicCastExpr>(E)) {
6024  Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath,
6025  ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
6026  } else if (isa<CXXReinterpretCastExpr>(E)) {
6028  Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath,
6029  ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
6030  } else {
6031  return nullptr;
6032  }
6033 }
6034 
6036  ASTContext &FromContext, FileManager &FromFileManager,
6037  bool MinimalImport)
6038  : ToContext(ToContext), FromContext(FromContext),
6039  ToFileManager(ToFileManager), FromFileManager(FromFileManager),
6040  Minimal(MinimalImport), LastDiagFromFrom(false)
6041 {
6042  ImportedDecls[FromContext.getTranslationUnitDecl()]
6043  = ToContext.getTranslationUnitDecl();
6044 }
6045 
6047 
6049  if (FromT.isNull())
6050  return QualType();
6051 
6052  const Type *fromTy = FromT.getTypePtr();
6053 
6054  // Check whether we've already imported this type.
6056  = ImportedTypes.find(fromTy);
6057  if (Pos != ImportedTypes.end())
6058  return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers());
6059 
6060  // Import the type
6061  ASTNodeImporter Importer(*this);
6062  QualType ToT = Importer.Visit(fromTy);
6063  if (ToT.isNull())
6064  return ToT;
6065 
6066  // Record the imported type.
6067  ImportedTypes[fromTy] = ToT.getTypePtr();
6068 
6069  return ToContext.getQualifiedType(ToT, FromT.getLocalQualifiers());
6070 }
6071 
6073  if (!FromTSI)
6074  return FromTSI;
6075 
6076  // FIXME: For now we just create a "trivial" type source info based
6077  // on the type and a single location. Implement a real version of this.
6078  QualType T = Import(FromTSI->getType());
6079  if (T.isNull())
6080  return nullptr;
6081 
6082  return ToContext.getTrivialTypeSourceInfo(T,
6083  Import(FromTSI->getTypeLoc().getLocStart()));
6084 }
6085 
6087  llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD);
6088  if (Pos != ImportedDecls.end()) {
6089  Decl *ToD = Pos->second;
6090  ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD);
6091  return ToD;
6092  } else {
6093  return nullptr;
6094  }
6095 }
6096 
6098  if (!FromD)
6099  return nullptr;
6100 
6101  ASTNodeImporter Importer(*this);
6102 
6103  // Check whether we've already imported this declaration.
6104  llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD);
6105  if (Pos != ImportedDecls.end()) {
6106  Decl *ToD = Pos->second;
6107  Importer.ImportDefinitionIfNeeded(FromD, ToD);
6108  return ToD;
6109  }
6110 
6111  // Import the type
6112  Decl *ToD = Importer.Visit(FromD);
6113  if (!ToD)
6114  return nullptr;
6115 
6116  // Record the imported declaration.
6117  ImportedDecls[FromD] = ToD;
6118 
6119  if (TagDecl *FromTag = dyn_cast<TagDecl>(FromD)) {
6120  // Keep track of anonymous tags that have an associated typedef.
6121  if (FromTag->getTypedefNameForAnonDecl())
6122  AnonTagsWithPendingTypedefs.push_back(FromTag);
6123  } else if (TypedefNameDecl *FromTypedef = dyn_cast<TypedefNameDecl>(FromD)) {
6124  // When we've finished transforming a typedef, see whether it was the
6125  // typedef for an anonymous tag.
6127  FromTag = AnonTagsWithPendingTypedefs.begin(),
6128  FromTagEnd = AnonTagsWithPendingTypedefs.end();
6129  FromTag != FromTagEnd; ++FromTag) {
6130  if ((*FromTag)->getTypedefNameForAnonDecl() == FromTypedef) {
6131  if (TagDecl *ToTag = cast_or_null<TagDecl>(Import(*FromTag))) {
6132  // We found the typedef for an anonymous tag; link them.
6133  ToTag->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(ToD));
6134  AnonTagsWithPendingTypedefs.erase(FromTag);
6135  break;
6136  }
6137  }
6138  }
6139  }
6140 
6141  return ToD;
6142 }
6143 
6145  if (!FromDC)
6146  return FromDC;
6147 
6148  DeclContext *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC)));
6149  if (!ToDC)
6150  return nullptr;
6151 
6152  // When we're using a record/enum/Objective-C class/protocol as a context, we
6153  // need it to have a definition.
6154  if (RecordDecl *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
6155  RecordDecl *FromRecord = cast<RecordDecl>(FromDC);
6156  if (ToRecord->isCompleteDefinition()) {
6157  // Do nothing.
6158  } else if (FromRecord->isCompleteDefinition()) {
6159  ASTNodeImporter(*this).ImportDefinition(FromRecord, ToRecord,
6161  } else {
6162  CompleteDecl(ToRecord);
6163  }
6164  } else if (EnumDecl *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
6165  EnumDecl *FromEnum = cast<EnumDecl>(FromDC);
6166  if (ToEnum->isCompleteDefinition()) {
6167  // Do nothing.
6168  } else if (FromEnum->isCompleteDefinition()) {
6169  ASTNodeImporter(*this).ImportDefinition(FromEnum, ToEnum,
6171  } else {
6172  CompleteDecl(ToEnum);
6173  }
6174  } else if (ObjCInterfaceDecl *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
6175  ObjCInterfaceDecl *FromClass = cast<ObjCInterfaceDecl>(FromDC);
6176  if (ToClass->getDefinition()) {
6177  // Do nothing.
6178  } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
6179  ASTNodeImporter(*this).ImportDefinition(FromDef, ToClass,
6181  } else {
6182  CompleteDecl(ToClass);
6183  }
6184  } else if (ObjCProtocolDecl *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
6185  ObjCProtocolDecl *FromProto = cast<ObjCProtocolDecl>(FromDC);
6186  if (ToProto->getDefinition()) {
6187  // Do nothing.
6188  } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
6189  ASTNodeImporter(*this).ImportDefinition(FromDef, ToProto,
6191  } else {
6192  CompleteDecl(ToProto);
6193  }
6194  }
6195 
6196  return ToDC;
6197 }
6198 
6200  if (!FromE)
6201  return nullptr;
6202 
6203  return cast_or_null<Expr>(Import(cast<Stmt>(FromE)));
6204 }
6205 
6207  if (!FromS)
6208  return nullptr;
6209 
6210  // Check whether we've already imported this declaration.
6211  llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
6212  if (Pos != ImportedStmts.end())
6213  return Pos->second;
6214 
6215  // Import the type
6216  ASTNodeImporter Importer(*this);
6217  Stmt *ToS = Importer.Visit(FromS);
6218  if (!ToS)
6219  return nullptr;
6220 
6221  // Record the imported declaration.
6222  ImportedStmts[FromS] = ToS;
6223  return ToS;
6224 }
6225 
6227  if (!FromNNS)
6228  return nullptr;
6229 
6230  NestedNameSpecifier *prefix = Import(FromNNS->getPrefix());
6231 
6232  switch (FromNNS->getKind()) {
6234  if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) {
6235  return NestedNameSpecifier::Create(ToContext, prefix, II);
6236  }
6237  return nullptr;
6238 
6240  if (NamespaceDecl *NS =
6241  cast<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) {
6242  return NestedNameSpecifier::Create(ToContext, prefix, NS);
6243  }
6244  return nullptr;
6245 
6247  if (NamespaceAliasDecl *NSAD =
6248  cast<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) {
6249  return NestedNameSpecifier::Create(ToContext, prefix, NSAD);
6250  }
6251  return nullptr;
6252 
6254  return NestedNameSpecifier::GlobalSpecifier(ToContext);
6255 
6257  if (CXXRecordDecl *RD =
6258  cast<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) {
6259  return NestedNameSpecifier::SuperSpecifier(ToContext, RD);
6260  }
6261  return nullptr;
6262 
6265  QualType T = Import(QualType(FromNNS->getAsType(), 0u));
6266  if (!T.isNull()) {
6267  bool bTemplate = FromNNS->getKind() ==
6269  return NestedNameSpecifier::Create(ToContext, prefix,
6270  bTemplate, T.getTypePtr());
6271  }
6272  }
6273  return nullptr;
6274  }
6275 
6276  llvm_unreachable("Invalid nested name specifier kind");
6277 }
6278 
6280  // FIXME: Implement!
6281  return NestedNameSpecifierLoc();
6282 }
6283 
6285  switch (From.getKind()) {
6287  if (TemplateDecl *ToTemplate
6288  = cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl())))
6289  return TemplateName(ToTemplate);
6290 
6291  return TemplateName();
6292 
6294  OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate();
6295  UnresolvedSet<2> ToTemplates;
6296  for (OverloadedTemplateStorage::iterator I = FromStorage->begin(),
6297  E = FromStorage->end();
6298  I != E; ++I) {
6299  if (NamedDecl *To = cast_or_null<NamedDecl>(Import(*I)))
6300  ToTemplates.addDecl(To);
6301  else
6302  return TemplateName();
6303  }
6304  return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
6305  ToTemplates.end());
6306  }
6307 
6310  NestedNameSpecifier *Qualifier = Import(QTN->getQualifier());
6311  if (!Qualifier)
6312  return TemplateName();
6313 
6314  if (TemplateDecl *ToTemplate
6315  = cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl())))
6316  return ToContext.getQualifiedTemplateName(Qualifier,
6317  QTN->hasTemplateKeyword(),
6318  ToTemplate);
6319 
6320  return TemplateName();
6321  }
6322 
6325  NestedNameSpecifier *Qualifier = Import(DTN->getQualifier());
6326  if (!Qualifier)
6327  return TemplateName();
6328 
6329  if (DTN->isIdentifier()) {
6330  return ToContext.getDependentTemplateName(Qualifier,
6331  Import(DTN->getIdentifier()));
6332  }
6333 
6334  return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator());
6335  }
6336 
6341  = cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter()));
6342  if (!param)
6343  return TemplateName();
6344 
6345  TemplateName replacement = Import(subst->getReplacement());
6346  if (replacement.isNull()) return TemplateName();
6347 
6348  return ToContext.getSubstTemplateTemplateParm(param, replacement);
6349  }
6350 
6355  = cast_or_null<TemplateTemplateParmDecl>(
6356  Import(SubstPack->getParameterPack()));
6357  if (!Param)
6358  return TemplateName();
6359 
6360  ASTNodeImporter Importer(*this);
6361  TemplateArgument ArgPack
6362  = Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
6363  if (ArgPack.isNull())
6364  return TemplateName();
6365 
6366  return ToContext.getSubstTemplateTemplateParmPack(Param, ArgPack);
6367  }
6368  }
6369 
6370  llvm_unreachable("Invalid template name kind");
6371 }
6372 
6374  if (FromLoc.isInvalid())
6375  return SourceLocation();
6376 
6377  SourceManager &FromSM = FromContext.getSourceManager();
6378 
6379  // For now, map everything down to its spelling location, so that we
6380  // don't have to import macro expansions.
6381  // FIXME: Import macro expansions!
6382  FromLoc = FromSM.getSpellingLoc(FromLoc);
6383  std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc);
6384  SourceManager &ToSM = ToContext.getSourceManager();
6385  FileID ToFileID = Import(Decomposed.first);
6386  if (ToFileID.isInvalid())
6387  return SourceLocation();
6388  SourceLocation ret = ToSM.getLocForStartOfFile(ToFileID)
6389  .getLocWithOffset(Decomposed.second);
6390  return ret;
6391 }
6392 
6394  return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd()));
6395 }
6396 
6399  = ImportedFileIDs.find(FromID);
6400  if (Pos != ImportedFileIDs.end())
6401  return Pos->second;
6402 
6403  SourceManager &FromSM = FromContext.getSourceManager();
6404  SourceManager &ToSM = ToContext.getSourceManager();
6405  const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
6406  assert(FromSLoc.isFile() && "Cannot handle macro expansions yet");
6407 
6408  // Include location of this file.
6409  SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
6410 
6411  // Map the FileID for to the "to" source manager.
6412  FileID ToID;
6413  const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache();
6414  if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
6415  // FIXME: We probably want to use getVirtualFile(), so we don't hit the
6416  // disk again
6417  // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
6418  // than mmap the files several times.
6419  const FileEntry *Entry = ToFileManager.getFile(Cache->OrigEntry->getName());
6420  if (!Entry)
6421  return FileID();
6422  ToID = ToSM.createFileID(Entry, ToIncludeLoc,
6423  FromSLoc.getFile().getFileCharacteristic());
6424  } else {
6425  // FIXME: We want to re-use the existing MemoryBuffer!
6426  const llvm::MemoryBuffer *
6427  FromBuf = Cache->getBuffer(FromContext.getDiagnostics(), FromSM);
6428  std::unique_ptr<llvm::MemoryBuffer> ToBuf
6429  = llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
6430  FromBuf->getBufferIdentifier());
6431  ToID = ToSM.createFileID(std::move(ToBuf),
6432  FromSLoc.getFile().getFileCharacteristic());
6433  }
6434 
6435 
6436  ImportedFileIDs[FromID] = ToID;
6437  return ToID;
6438 }
6439 
6441  Expr *ToExpr = Import(From->getInit());
6442  if (!ToExpr && From->getInit())
6443  return nullptr;
6444 
6445  if (From->isBaseInitializer()) {
6446  TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo());
6447  if (!ToTInfo && From->getTypeSourceInfo())
6448  return nullptr;
6449 
6450  return new (ToContext) CXXCtorInitializer(
6451  ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()),
6452  ToExpr, Import(From->getRParenLoc()),
6453  From->isPackExpansion() ? Import(From->getEllipsisLoc())
6454  : SourceLocation());
6455  } else if (From->isMemberInitializer()) {
6456  FieldDecl *ToField =
6457  llvm::cast_or_null<FieldDecl>(Import(From->getMember()));
6458  if (!ToField && From->getMember())
6459  return nullptr;
6460 
6461  return new (ToContext) CXXCtorInitializer(
6462  ToContext, ToField, Import(From->getMemberLocation()),
6463  Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc()));
6464  } else if (From->isIndirectMemberInitializer()) {
6465  IndirectFieldDecl *ToIField = llvm::cast_or_null<IndirectFieldDecl>(
6466  Import(From->getIndirectMember()));
6467  if (!ToIField && From->getIndirectMember())
6468  return nullptr;
6469 
6470  return new (ToContext) CXXCtorInitializer(
6471  ToContext, ToIField, Import(From->getMemberLocation()),
6472  Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc()));
6473  } else if (From->isDelegatingInitializer()) {
6474  TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo());
6475  if (!ToTInfo && From->getTypeSourceInfo())
6476  return nullptr;
6477 
6478  return new (ToContext)
6479  CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()),
6480  ToExpr, Import(From->getRParenLoc()));
6481  } else if (unsigned NumArrayIndices = From->getNumArrayIndices()) {
6482  FieldDecl *ToField =
6483  llvm::cast_or_null<FieldDecl>(Import(From->getMember()));
6484  if (!ToField && From->getMember())
6485  return nullptr;
6486 
6487  SmallVector<VarDecl *, 4> ToAIs(NumArrayIndices);
6488 
6489  for (unsigned AII = 0; AII < NumArrayIndices; ++AII) {
6490  VarDecl *ToArrayIndex =
6491  dyn_cast_or_null<VarDecl>(Import(From->getArrayIndex(AII)));
6492  if (!ToArrayIndex && From->getArrayIndex(AII))
6493  return nullptr;
6494  }
6495 
6497  ToContext, ToField, Import(From->getMemberLocation()),
6498  Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc()),
6499  ToAIs.data(), NumArrayIndices);
6500  } else {
6501  return nullptr;
6502  }
6503 }
6504 
6505 
6507  Decl *To = Import(From);
6508  if (!To)
6509  return;
6510 
6511  if (DeclContext *FromDC = cast<DeclContext>(From)) {
6512  ASTNodeImporter Importer(*this);
6513 
6514  if (RecordDecl *ToRecord = dyn_cast<RecordDecl>(To)) {
6515  if (!ToRecord->getDefinition()) {
6516  Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord,
6518  return;
6519  }
6520  }
6521 
6522  if (EnumDecl *ToEnum = dyn_cast<EnumDecl>(To)) {
6523  if (!ToEnum->getDefinition()) {
6524  Importer.ImportDefinition(cast<EnumDecl>(FromDC), ToEnum,
6526  return;
6527  }
6528  }
6529 
6530  if (ObjCInterfaceDecl *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
6531  if (!ToIFace->getDefinition()) {
6532  Importer.ImportDefinition(cast<ObjCInterfaceDecl>(FromDC), ToIFace,
6534  return;
6535  }
6536  }
6537 
6538  if (ObjCProtocolDecl *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
6539  if (!ToProto->getDefinition()) {
6540  Importer.ImportDefinition(cast<ObjCProtocolDecl>(FromDC), ToProto,
6542  return;
6543  }
6544  }
6545 
6546  Importer.ImportDeclContext(FromDC, true);
6547  }
6548 }
6549 
6551  if (!FromName)
6552  return DeclarationName();
6553 
6554  switch (FromName.getNameKind()) {
6556  return Import(FromName.getAsIdentifierInfo());
6557 
6561  return Import(FromName.getObjCSelector());
6562 
6564  QualType T = Import(FromName.getCXXNameType());
6565  if (T.isNull())
6566  return DeclarationName();
6567 
6568  return ToContext.DeclarationNames.getCXXConstructorName(
6569  ToContext.getCanonicalType(T));
6570  }
6571 
6573  QualType T = Import(FromName.getCXXNameType());
6574  if (T.isNull())
6575  return DeclarationName();
6576 
6577  return ToContext.DeclarationNames.getCXXDestructorName(
6578  ToContext.getCanonicalType(T));
6579  }
6580 
6582  QualType T = Import(FromName.getCXXNameType());
6583  if (T.isNull())
6584  return DeclarationName();
6585 
6587  ToContext.getCanonicalType(T));
6588  }
6589 
6591  return ToContext.DeclarationNames.getCXXOperatorName(
6592  FromName.getCXXOverloadedOperator());
6593 
6596  Import(FromName.getCXXLiteralIdentifier()));
6597 
6599  // FIXME: STATICS!
6601  }
6602 
6603  llvm_unreachable("Invalid DeclarationName Kind!");
6604 }
6605 
6607  if (!FromId)
6608  return nullptr;
6609 
6610  IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
6611 
6612  if (!ToId->getBuiltinID() && FromId->getBuiltinID())
6613  ToId->setBuiltinID(FromId->getBuiltinID());
6614 
6615  return ToId;
6616 }
6617 
6619  if (FromSel.isNull())
6620  return Selector();
6621 
6623  Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
6624  for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
6625  Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
6626  return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
6627 }
6628 
6630  DeclContext *DC,
6631  unsigned IDNS,
6632  NamedDecl **Decls,
6633  unsigned NumDecls) {
6634  return Name;
6635 }
6636 
6638  if (LastDiagFromFrom)
6640  FromContext.getDiagnostics());
6641  LastDiagFromFrom = false;
6642  return ToContext.getDiagnostics().Report(Loc, DiagID);
6643 }
6644 
6646  if (!LastDiagFromFrom)
6648  ToContext.getDiagnostics());
6649  LastDiagFromFrom = true;
6650  return FromContext.getDiagnostics().Report(Loc, DiagID);
6651 }
6652 
6654  if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
6655  if (!ID->getDefinition())
6656  ID->startDefinition();
6657  }
6658  else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) {
6659  if (!PD->getDefinition())
6660  PD->startDefinition();
6661  }
6662  else if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
6663  if (!TD->getDefinition() && !TD->isBeingDefined()) {
6664  TD->startDefinition();
6665  TD->setCompleteDefinition(true);
6666  }
6667  }
6668  else {
6669  assert (0 && "CompleteDecl called on a Decl that can't be completed");
6670  }
6671 }
6672 
6674  if (From->hasAttrs()) {
6675  for (Attr *FromAttr : From->getAttrs())
6676  To->addAttr(FromAttr->clone(To->getASTContext()));
6677  }
6678  if (From->isUsed()) {
6679  To->setIsUsed();
6680  }
6681  if (From->isImplicit()) {
6682  To->setImplicit();
6683  }
6684  ImportedDecls[From] = To;
6685  return To;
6686 }
6687 
6689  bool Complain) {
6691  = ImportedTypes.find(From.getTypePtr());
6692  if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To))
6693  return true;
6694 
6695  StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls,
6696  false, Complain);
6697  return Ctx.IsStructurallyEquivalent(From, To);
6698 }
SourceLocation getRParenLoc() const
Definition: Expr.h:3405
Expr * getInc()
Definition: Stmt.h:1187
Kind getKind() const
Definition: Type.h:2060
unsigned getNumElements() const
Definition: Type.h:2781
Represents a single C99 designator.
Definition: Expr.h:4028
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl)
Definition: DeclCXX.cpp:2082
param_const_iterator param_begin() const
Definition: DeclObjC.h:354
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition: Expr.h:2411
SourceRange getParenOrBraceRange() const
Definition: ExprCXX.h:1305
void setMethodParams(ASTContext &C, ArrayRef< ParmVarDecl * > Params, ArrayRef< SourceLocation > SelLocs=llvm::None)
Sets the method's parameters and selector source locations.
Definition: DeclObjC.cpp:820
void setValueDependent(bool VD)
Set whether this expression is value-dependent or not.
Definition: Expr.h:150
QualType getElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType) const
tokloc_iterator tokloc_begin() const
Definition: Expr.h:1599
Defines the clang::ASTContext interface.
unsigned getNumArrayIndices() const
Determine the number of implicit array indices used while described an array member initialization...
Definition: DeclCXX.h:2131
unsigned getNumInits() const
Definition: Expr.h:3776
QualType getExceptionType(unsigned i) const
Definition: Type.h:3332
Represents a type that was referred to using an elaborated type keyword, e.g., struct S...
Definition: Type.h:4430
SourceLocation getEnd() const
const SwitchCase * getNextSwitchCase() const
Definition: Stmt.h:664
void setOwningFunction(DeclContext *FD)
setOwningFunction - Sets the function declaration that owns this ParmVarDecl.
Definition: Decl.h:1523
Expr * getSizeExpr() const
Definition: Type.h:2731
QualType getUnderlyingType() const
Definition: Type.h:3599
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:5278
Expr * VisitCXXMemberCallExpr(CXXMemberCallExpr *E)
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
Definition: Type.h:4948
CastKind getCastKind() const
Definition: Expr.h:2680
The null pointer literal (C++11 [lex.nullptr])
Definition: ExprCXX.h:505
Expr * VisitConditionalOperator(ConditionalOperator *E)
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:408
static unsigned getFieldIndex(Decl *F)
This represents a GCC inline-assembly statement extension.
Definition: Stmt.h:1565
Decl * VisitCXXMethodDecl(CXXMethodDecl *D)
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1561
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
Definition: Expr.h:1054
bool isVariadic() const
Definition: Type.h:3366
QualType VisitVectorType(const VectorType *T)
unsigned getNumOutputs() const
Definition: Stmt.h:1462
TypeSourceInfo * getTypeSourceInfo() const
Definition: Expr.h:2598
Decl * VisitEnumDecl(EnumDecl *D)
body_iterator body_end()
Definition: Stmt.h:583
unsigned getDepth() const
Definition: Type.h:3945
bool isMinimalImport() const
Whether the importer will perform a minimal import, creating to-be-completed forward declarations whe...
Definition: ASTImporter.h:102
void setArrayFiller(Expr *filler)
Definition: Expr.cpp:1809
Stmt * VisitDoStmt(DoStmt *S)
const DeclGroupRef getDeclGroup() const
Definition: Stmt.h:464
Smart pointer class that efficiently represents Objective-C method names.
This is a discriminated union of FileInfo and ExpansionInfo.
bool isFileScope() const
Definition: Expr.h:2592
void setAnonymousStructOrUnion(bool Anon)
Definition: Decl.h:3321
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2179
const ObjCAtFinallyStmt * getFinallyStmt() const
Retrieve the @finally statement, if any.
Definition: StmtObjC.h:224
A (possibly-)qualified type.
Definition: Type.h:598
ImplementationControl getImplementationControl() const
Definition: DeclObjC.h:463
QualType VisitDecltypeType(const DecltypeType *T)
base_class_range bases()
Definition: DeclCXX.h:718
SourceRange getBracketsRange() const
Definition: Type.h:2628
bool isNull() const
Definition: DeclGroup.h:82
bool getValue() const
Definition: ExprCXX.h:483
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
Definition: TemplateBase.h:282
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition: Expr.h:2217
Stmt * VisitCaseStmt(CaseStmt *S)
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.h:2214
bool isPascal() const
Definition: Expr.h:1562
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:117
void startDefinition()
Starts the definition of this Objective-C class, taking it from a forward declaration (@class) to a d...
Definition: DeclObjC.cpp:581
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:2361
bool hasLeadingEmptyMacro() const
Definition: Stmt.h:532
SourceLocation getLParenLoc() const
Definition: Stmt.h:1202
ObjCTypeParamList * ImportObjCTypeParamList(ObjCTypeParamList *list)
QualType getType() const
Retrieves the type of the base class.
Definition: DeclCXX.h:254
bool isElidable() const
Whether this construction is elidable.
Definition: ExprCXX.h:1231
Expr * getCond()
Definition: Stmt.h:1075
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition: Expr.h:2503
Defines the clang::FileManager interface and associated types.
protocol_iterator protocol_end() const
Definition: DeclObjC.h:2034
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)
CompoundStmt * getSubStmt()
Definition: Expr.h:3396
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
Definition: Decl.h:232
DeclarationName getCXXConstructorName(CanQualType Ty)
getCXXConstructorName - Returns the name of a C++ constructor for the given Type. ...
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition: Expr.h:2446
QualType getBaseType() const
Definition: Type.h:3653
Decl * VisitDecl(Decl *D)
bool isKindOfTypeAsWritten() const
Whether this is a "__kindof" type as written.
Definition: Type.h:4858
PropertyControl getPropertyImplementation() const
Definition: DeclObjC.h:870
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:1693
outputs_iterator end_outputs()
Definition: Stmt.h:1541
Stmt * VisitContinueStmt(ContinueStmt *S)
CharacterKind getKind() const
Definition: Expr.h:1331
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID. ...
SourceLocation getCXXLiteralOperatorNameLoc() const
getCXXLiteralOperatorNameLoc - Returns the location of the literal operator name (not the operator ke...
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition: Decl.h:3199
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:1453
bool isDefined() const
Definition: DeclObjC.h:424
bool isParameterPack() const
Returns whether this is a parameter pack.
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:2879
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:760
const Expr * getInitExpr() const
Definition: Decl.h:2498
bool isArgumentType() const
Definition: Expr.h:2010
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
Definition: DeclObjC.h:1435
IfStmt - This represents an if/then/else.
Definition: Stmt.h:881
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...
Expr * VisitImplicitCastExpr(ImplicitCastExpr *E)
Expr * getInit() const
Retrieve the initializer value.
Definition: Expr.h:4184
IdentifierInfo * getCXXLiteralIdentifier() const
getCXXLiteralIdentifier - If this name is the name of a literal operator, retrieve the identifier ass...
EnumConstantDecl - An instance of this object exists for each enum constant that is defined...
Definition: Decl.h:2481
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
Definition: TemplateName.h:484
static CXXDynamicCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:535
Expr * VisitCXXConstructExpr(CXXConstructExpr *E)
TypedefDecl - Represents the declaration of a typedef-name via the 'typedef' type specifier...
Definition: Decl.h:2681
Defines the SourceManager interface.
tokloc_iterator tokloc_end() const
Definition: Expr.h:1600
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:4496
The template argument is an expression, and we've not resolved it to one of the other forms yet...
Definition: TemplateBase.h:69
QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType, UnaryTransformType::UTTKind UKind) const
Unary type transforms.
SourceLocation getForLoc() const
Definition: StmtObjC.h:53
CXXRecordDecl * getDecl() const
Definition: Type.cpp:3065
static TemplateTemplateParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation L, unsigned D, unsigned P, bool ParameterPack, IdentifierInfo *Id, TemplateParameterList *Params)
DeclarationName getCXXConversionFunctionName(CanQualType Ty)
getCXXConversionFunctionName - Returns the name of a C++ conversion function for the given Type...
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
QualType getUnderlyingType() const
Definition: Decl.h:2649
iterator end()
Definition: DeclGroup.h:108
SourceLocation getLParenLoc() const
Definition: Expr.h:3403
SourceLocation getLocStart() const LLVM_READONLY
Definition: ExprCXX.h:1071
unsigned size() const
Returns the number of designators in this initializer.
Definition: Expr.h:4153
AccessSpecifier getAccess() const
DeclGroupRef ImportDeclGroup(DeclGroupRef DG)
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition: Decl.cpp:2008
void setType(QualType t)
Definition: Expr.h:127
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
StringRef P
Represents a C++11 auto or C++14 decltype(auto) type.
Definition: Type.h:4084
void setPure(bool P=true)
Definition: Decl.cpp:2507
Represents an attribute applied to a statement.
Definition: Stmt.h:830
static ObjCProtocolDecl * Create(ASTContext &C, DeclContext *DC, IdentifierInfo *Id, SourceLocation nameLoc, SourceLocation atStartLoc, ObjCProtocolDecl *PrevDecl)
Definition: DeclObjC.cpp:1785
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:1619
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:2160
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
Definition: TemplateBase.h:315
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:2420
IdentifierInfo * getAsIdentifierInfo() const
getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in this declaration name, or NULL if this declaration name isn't a simple identifier.
The base class of the type hierarchy.
Definition: Type.h:1281
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
enumerator_iterator enumerator_end() const
Definition: Decl.h:3120
Represents Objective-C's @throw statement.
Definition: StmtObjC.h:313
SourceLocation getRBracketLoc() const
Definition: Expr.h:4111
QualType VisitTemplateSpecializationType(const TemplateSpecializationType *T)
SourceLocation getLabelLoc() const
Definition: Expr.h:3355
QualType getRecordType(const RecordDecl *Decl) const
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1124
InitListExpr * getSyntacticForm() const
Definition: Expr.h:3882
DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, ArrayRef< TemplateArgument > Args, QualType Canon)
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2456
Declaration of a variable template.
SourceLocation getIfLoc() const
Definition: Stmt.h:928
SourceLocation getRParenLoc() const
Definition: DeclCXX.h:2127
TemplateTemplateParmDecl * getParameterPack() const
Retrieve the template template parameter pack being substituted.
Definition: TemplateName.h:133
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Definition: TemplateBase.h:51
NamespaceDecl - Represent a C++ namespace.
Definition: Decl.h:471
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:1308
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1162
SourceLocation getCoawaitLoc() const
Definition: StmtCXX.h:194
RetTy Visit(const Type *T)
Performs the operation associated with this visitor object.
Definition: TypeVisitor.h:69
void setSpecializationKind(TemplateSpecializationKind TSK)
virtual void completeDefinition()
completeDefinition - Notes that the definition of this type is now complete.
Definition: Decl.cpp:3776
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:101
Decl * VisitFieldDecl(FieldDecl *D)
A container of type source information.
Definition: Decl.h:62
void setSwitchCaseList(SwitchCase *SC)
Set the case list for this switch statement.
Definition: Stmt.h:1005
const Stmt * getElse() const
Definition: Stmt.h:921
unsigned getIndex() const
Definition: Type.h:3946
Decl * VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D)
SourceLocation getOperatorLoc() const
Definition: Expr.h:2937
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:305
static StringLiteral * Create(const ASTContext &C, StringRef Str, StringKind Kind, bool Pascal, QualType Ty, const SourceLocation *Loc, unsigned NumStrs)
This is the "fully general" constructor that allows representation of strings formed from multiple co...
Definition: Expr.cpp:826
QualType VisitInjectedClassNameType(const InjectedClassNameType *T)
void setTemplateArgsInfo(const TemplateArgumentListInfo &ArgsInfo)
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2022
enumerator_iterator enumerator_begin() const
Definition: Decl.h:3113
const TemplateArgument & get(unsigned Idx) const
Retrieve the template argument at a given index.
Definition: DeclTemplate.h:216
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
Definition: Stmt.cpp:809
SourceLocation getEllipsisLoc() const
Definition: Expr.h:4117
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:1497
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2187
bool isSpelledAsLValue() const
Definition: Type.h:2336
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:201
Expr * getInClassInitializer() const
getInClassInitializer - Get the C++11 in-class initializer for this member, or null if one has not be...
Definition: Decl.h:2416
InClassInitStyle getInClassInitStyle() const
getInClassInitStyle - Get the kind of (C++11) in-class initializer which this field has...
Definition: Decl.h:2400
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition: Expr.h:2470
IdentType getIdentType() const
Definition: Expr.h:1187
const llvm::APInt & getSize() const
Definition: Type.h:2527
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:2046
ObjCTypeParamVariance getVariance() const
Determine the variance of this type parameter.
Definition: DeclObjC.h:572
SourceLocation getIncludeLoc() const
bool hadArrayRangeDesignator() const
Definition: Expr.h:3893
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: Expr.h:1070
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
static CXXConstructExpr * Create(const ASTContext &C, QualType T, SourceLocation Loc, CXXConstructorDecl *Ctor, bool Elidable, ArrayRef< Expr * > Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization, ConstructionKind ConstructKind, SourceRange ParenOrBraceRange)
Definition: ExprCXX.cpp:751
An identifier, stored as an IdentifierInfo*.
Stmt * getSubStmt()
Definition: Stmt.h:760
Expr * VisitStringLiteral(StringLiteral *E)
bool isImplicit() const
Definition: ExprCXX.h:895
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.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:768
virtual Decl * GetOriginalDecl(Decl *To)
Called by StructuralEquivalenceContext.
Definition: ASTImporter.h:295
void setImplementation(ObjCCategoryImplDecl *ImplD)
Definition: DeclObjC.cpp:1959
SourceLocation getReturnLoc() const
Definition: Stmt.h:1385
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:2004
bool isFileVarDecl() const
isFileVarDecl - Returns true for file scoped variable declaration.
Definition: Decl.h:1113
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
Expr * getInit() const
Get the initializer.
Definition: DeclCXX.h:2155
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:2562
unsigned getIndex() const
Retrieve the index into its type parameter list.
Definition: DeclObjC.h:585
void setCXXLiteralOperatorNameLoc(SourceLocation Loc)
setCXXLiteralOperatorNameLoc - Sets the location of the literal operator name (not the operator keywo...
const Expr * getCallee() const
Definition: Expr.h:2188
Stmt * VisitLabelStmt(LabelStmt *S)
SourceLocation getIvarRBraceLoc() const
Definition: DeclObjC.h:2299
Expr * VisitIntegerLiteral(IntegerLiteral *E)
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:46
Extra information about a function prototype.
Definition: Type.h:3167
AutoTypeKeyword getKeyword() const
Definition: Type.h:4102
TypeSourceInfo * getSuperClassTInfo() const
Definition: DeclObjC.h:1478
field_iterator field_begin() const
Definition: Decl.cpp:3767
unsigned size() const
Definition: Stmt.h:576
Represents a variable template specialization, which refers to a variable template with a given set o...
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:113
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition: Expr.h:1290
Decl * VisitVarDecl(VarDecl *D)
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:3949
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:1127
SourceLocation getRParenLoc() const
Definition: Stmt.h:1587
UnaryExprOrTypeTrait getKind() const
Definition: Expr.h:2005
Expr * VisitUnaryOperator(UnaryOperator *E)
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:49
Expr * VisitAtomicExpr(AtomicExpr *E)
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value...
Definition: Expr.h:3287
void getSelectorLocs(SmallVectorImpl< SourceLocation > &SelLocs) const
Definition: DeclObjC.cpp:814
static bool ImportCastPath(CastExpr *E, CXXCastPath &Path)
Qualifiers getIndexTypeQualifiers() const
Definition: Type.h:2494
QualType Import(QualType FromT)
Import the given type from the "from" context into the "to" context.
unsigned param_size() const
Definition: DeclObjC.h:348
unsigned getValue() const
Definition: Expr.h:1338
TemplateTemplateParmDecl * getParameter() const
Definition: TemplateName.h:327
static AccessSpecDecl * Create(ASTContext &C, AccessSpecifier AS, DeclContext *DC, SourceLocation ASLoc, SourceLocation ColonLoc)
Definition: DeclCXX.h:130
ParmVarDecl - Represents a parameter to a function.
Definition: Decl.h:1377
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:3983
bool ImportTemplateArguments(const TemplateArgument *FromArgs, unsigned NumFromArgs, SmallVectorImpl< TemplateArgument > &ToArgs)
SourceLocation getDefaultLoc() const
Definition: Stmt.h:764
SourceLocation getLocation() const
Definition: Expr.h:1025
QualType getUnderlyingType() const
Definition: Type.h:3652
SourceLocation getEllipsisLoc() const
Definition: Stmt.h:709
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition: Decl.h:707
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition: DeclCXX.h:2002
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names the category interface associated with this implementat...
Definition: DeclObjC.h:2412
QualType getType() const
Definition: DeclObjC.h:781
TypeSourceInfo * getTypeSourceInfo() const
Definition: DeclObjC.h:779
SourceLocation getEllipsisLoc() const
Definition: DeclCXX.h:2040
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form, which contains extra information on the evaluated value of the initializer.
Definition: Decl.cpp:2120
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:474
bool hasExternalFormalLinkage() const
True if this decl has external linkage.
Definition: Decl.h:344
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:789
unsigned getNumParams() const
Definition: Type.h:3271
Kind getPropertyImplementation() const
Definition: DeclObjC.h:2717
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3253
Represents a C99 designated initializer expression.
Definition: Expr.h:3953
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:1275
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class. ...
Definition: DeclObjC.h:1224
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:4523
QualType getElementType() const
Definition: Type.h:2732
DeclarationName getName() const
getName - Returns the embedded declaration name.
inputs_iterator begin_inputs()
Definition: Stmt.h:1509
FunctionType::ExtInfo ExtInfo
Definition: Type.h:3182
One of these records is kept for each identifier that is lexed.
Represents a class template specialization, which refers to a class template with a given set of temp...
Stmt * getBody()
Definition: Stmt.h:1123
void setIntegerType(QualType T)
Set the underlying integer type.
Definition: Decl.h:3146
unsigned getIndexTypeCVRQualifiers() const
Definition: Type.h:2497
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3193
Decl * VisitTypedefDecl(TypedefDecl *D)
DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "from" context.
Expr * getSubExpr(unsigned Idx) const
Definition: Expr.h:4198
OverloadedTemplateStorage * getAsOverloadedTemplate() const
Retrieve the underlying, overloaded function template.
unsigned getNumInputs() const
Definition: Stmt.h:1484
Designator ImportDesignator(const Designator &D)
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4549
Decl * VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D)
Expr * VisitCompoundAssignOperator(CompoundAssignOperator *E)
Represents a class type in Objective C.
Definition: Type.h:4727
static RecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl *PrevDecl=nullptr)
Definition: Decl.cpp:3729
Expr * getSizeExpr() const
Definition: Type.h:2623
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:92
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:412
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition: DeclBase.h:1756
bool CheckedICE
Whether we already checked whether this statement was an integral constant expression.
Definition: Decl.h:751
bool isIdentifier() const
Determine whether this template name refers to an identifier.
Definition: TemplateName.h:471
bool ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin)
Decl * VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D)
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:57
QualType VisitMemberPointerType(const MemberPointerType *T)
SourceLocation getLocStart() const LLVM_READONLY
Definition: DeclCXX.h:204
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:2248
SourceLocation getAmpAmpLoc() const
Definition: Expr.h:3353
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size...
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
Definition: Decl.h:2293
bool isCompleteDefinition() const
isCompleteDefinition - Return true if this decl has its body fully specified.
Definition: Decl.h:2871
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this class.
Definition: DeclObjC.cpp:305
QualType VisitParenType(const ParenType *T)
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition: DeclCXX.h:2008
An operation on a type.
Definition: TypeVisitor.h:65
NameKind getKind() const
bool isPure() const
Whether this virtual function is pure, i.e.
Definition: Decl.h:1837
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition: Expr.h:1647
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:3544
void setSuperClass(TypeSourceInfo *superClass)
Definition: DeclObjC.h:1493
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition: Expr.h:3624
SourceLocation getCaseLoc() const
Definition: Stmt.h:707
CXXRecordDecl * getDefinition() const
Definition: DeclCXX.h:678
static CXXCtorInitializer * Create(ASTContext &Context, FieldDecl *Member, SourceLocation MemberLoc, SourceLocation L, Expr *Init, SourceLocation R, VarDecl **Indices, unsigned NumIndices)
Creates a new member initializer that optionally contains array indices used to describe an elementwi...
Definition: DeclCXX.cpp:1768
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Definition: DeclTemplate.h:231
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:4516
TagKind getTagKind() const
Definition: Decl.h:2930
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:1982
Represents the result of substituting a set of types for a template type parameter pack...
Definition: Type.h:4038
DeclarationName getCXXDestructorName(CanQualType Ty)
getCXXDestructorName - Returns the name of a C++ destructor for the given Type.
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr)
Definition: Expr.cpp:368
int Category
Definition: Format.cpp:1197
QualType getTypeOfType(QualType t) const
getTypeOfType - Unlike many "get<Type>" functions, we don't unique TypeOfType nodes...
unsigned size() const
Definition: DeclTemplate.h:92
Expr * VisitExpr(Expr *E)
Decl * VisitObjCImplementationDecl(ObjCImplementationDecl *D)
SourceLocation getLBracLoc() const
Definition: Stmt.h:629
Expr * getSubExpr()
Definition: Expr.h:2684
Represents an access specifier followed by colon ':'.
Definition: DeclCXX.h:103
void startDefinition()
Starts the definition of this Objective-C protocol.
Definition: DeclObjC.cpp:1845
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, bool DependentLambda, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
Definition: DeclCXX.cpp:110
bool isNull() const
Determine whether this is the empty selector.
qual_range quals() const
Definition: Type.h:4836
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:1199
QualType VisitObjCInterfaceType(const ObjCInterfaceType *T)
SourceLocation getRParenLoc() const
Definition: Expr.h:2284
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
IdentifierTable & Idents
Definition: ASTContext.h:459
QualType getUnderlyingType() const
Definition: Type.h:3578
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition: DeclCXX.h:2570
QualType VisitComplexType(const ComplexType *T)
SourceLocation getCategoryNameLoc() const
Definition: DeclObjC.h:2293
bool isFPContractable() const
Definition: Expr.h:3064
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:947
Expr * getUnderlyingExpr() const
Definition: Type.h:3598
Expr * getLHS() const
Definition: Expr.h:2943
const VarDecl * getCatchParamDecl() const
Definition: StmtObjC.h:94
SourceLocation getColonLoc() const
Retrieve the location of the ':' separating the type parameter name from the explicitly-specified bou...
Definition: DeclObjC.h:593
SourceLocation getWhileLoc() const
Definition: Stmt.h:1082
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:1001
const VarDecl * getNRVOCandidate() const
Retrieve the variable that might be used for the named return value optimization. ...
Definition: Stmt.h:1393
IndirectGotoStmt - This represents an indirect goto.
Definition: Stmt.h:1258
Describes an C or C++ initializer list.
Definition: Expr.h:3746
QualType VisitVariableArrayType(const VariableArrayType *T)
Stmt * VisitBreakStmt(BreakStmt *S)
Decl * VisitCXXConstructorDecl(CXXConstructorDecl *D)
TemplateArgument getArgumentPack() const
Definition: Type.cpp:3083
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2383
param_type_range param_types() const
Definition: Type.h:3389
SourceLocation getLAngleLoc() const
Definition: DeclTemplate.h:132
IdentifierInfo * getOutputIdentifier(unsigned i) const
Definition: Stmt.h:1655
QualType getParenType(QualType NamedType) const
const Stmt * getFinallyBody() const
Definition: StmtObjC.h:132
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition: Stmt.h:1153
A qualified template name, where the qualification is kept to describe the source code as written...
Definition: TemplateName.h:195
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition: Decl.h:2978
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.
outputs_iterator begin_outputs()
Definition: Stmt.h:1538
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:1384
QualType VisitElaboratedType(const ElaboratedType *T)
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
const LangOptions & getLangOpts() const
Definition: ASTContext.h:604
Stmt * VisitAttributedStmt(AttributedStmt *S)
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition: Decl.h:526
IndirectFieldDecl * getIndirectMember() const
Definition: DeclCXX.h:2082
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
Definition: DeclObjC.h:2219
void setCXXOperatorNameRange(SourceRange R)
setCXXOperatorNameRange - Sets the range of the operator name (without the operator keyword)...
SourceLocation getIvarLBraceLoc() const
Definition: DeclObjC.h:2297
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
Definition: DeclObjC.cpp:334
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:1921
QualType getBaseType() const
Gets the base type of this object type.
Definition: Type.h:4782
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:2188
protocol_iterator protocol_end() const
Definition: DeclObjC.h:2251
QualType getReturnType() const
Definition: Type.h:3009
static EnumConstantDecl * Create(ASTContext &C, EnumDecl *DC, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E, const llvm::APSInt &V)
Definition: Decl.cpp:4080
SourceLocation getRParenLoc() const
Definition: Stmt.h:1132
Stmt * getHandlerBlock() const
Definition: StmtCXX.h:52
Stmt * getBody()
Definition: Stmt.h:1188
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition: Expr.h:1643
TemplateArgument getArgumentPack() const
Retrieve the template template argument pack with which this parameter was substituted.
QualType VisitTemplateTypeParmType(const TemplateTypeParmType *T)
TemplateName getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param, TemplateName replacement) const
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
Decl * VisitObjCPropertyDecl(ObjCPropertyDecl *D)
Represents a typeof (or typeof) expression (a GCC extension).
Definition: Type.h:3525
Expr * VisitCharacterLiteral(CharacterLiteral *E)
const Expr * getSubExpr() const
Definition: Expr.h:3673
static TemplateTypeParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation KeyLoc, SourceLocation NameLoc, unsigned D, unsigned P, IdentifierInfo *Id, bool Typename, bool ParameterPack)
SourceLocation getRParenLoc() const
Definition: Expr.h:3687
Expr * getNoexceptExpr() const
Definition: Type.h:3336
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:2897
SourceLocation getLocation() const
Definition: ExprCXX.h:489
static ObjCTypeParamList * create(ASTContext &ctx, SourceLocation lAngleLoc, ArrayRef< ObjCTypeParamDecl * > typeParams, SourceLocation rAngleLoc)
Create a new Objective-C type parameter list.
Definition: DeclObjC.cpp:1362
void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl)
Set the mangling number and context declaration for a lambda class.
Definition: DeclCXX.h:1675
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
Definition: Expr.h:147
Stmt * getInit()
Definition: Stmt.h:1167
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
RecordDecl * getDecl() const
Definition: Type.h:3716
static CXXTryStmt * Create(const ASTContext &C, SourceLocation tryLoc, Stmt *tryBlock, ArrayRef< Stmt * > handlers)
Definition: StmtCXX.cpp:26
iterator begin()
Definition: DeclGroup.h:102
Decl * VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D)
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition: StmtCXX.h:128
Selector getSetterName() const
Definition: DeclObjC.h:857
Stmt * VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S)
LabelStmt * getStmt() const
Definition: Decl.h:449
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Definition: DeclObjC.h:2098
void setSpecializationKind(TemplateSpecializationKind TSK)
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1039
const Stmt * getCatchBody() const
Definition: StmtObjC.h:90
Expr * getCond()
Definition: Stmt.h:1186
void setTrivial(bool IT)
Definition: Decl.h:1849
#define NULL
Definition: opencl-c.h:143
Decl * VisitObjCProtocolDecl(ObjCProtocolDecl *D)
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition: DeclCXX.h:2030
Expr * getLHS() const
Definition: Expr.h:3215
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:4457
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:2632
TypeClass getTypeClass() const
Definition: Type.h:1533
FieldDecl * getField()
Get the field whose initializer will be used.
Definition: ExprCXX.h:1058
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:1968
const ObjCAtCatchStmt * getCatchStmt(unsigned I) const
Retrieve a @catch statement.
Definition: StmtObjC.h:206
StringLiteral * getClobberStringLiteral(unsigned i)
Definition: Stmt.h:1729
bool IsStructurallyEquivalent(QualType From, QualType To, bool Complain=true)
Determine whether the given types are structurally equivalent.
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:468
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
Definition: Decl.cpp:1800
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:720
Stmt * VisitNullStmt(NullStmt *S)
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to...
Definition: Expr.h:2818
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition: DeclObjC.h:2067
Stmt * VisitCXXCatchStmt(CXXCatchStmt *S)
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
Represents an ObjC class declaration.
Definition: DeclObjC.h:1091
SourceLocation getLocEnd() const LLVM_READONLY
Definition: DeclObjC.cpp:907
Represents a linkage specification.
Definition: DeclCXX.h:2523
Expr * VisitCStyleCastExpr(CStyleCastExpr *E)
Stmt * VisitCXXTryStmt(CXXTryStmt *S)
detail::InMemoryDirectory::const_iterator I
PropertyAttributeKind getPropertyAttributes() const
Definition: DeclObjC.h:792
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition: Type.h:3160
bool ImportDefinition(RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind=IDK_Default)
SourceLocation getLParenLoc() const
Definition: Expr.h:4368
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:1593
CanQualType UnsignedCharTy
Definition: ASTContext.h:902
Stmt * getInit()
Definition: Stmt.h:914
QualType getType() const
Definition: Decl.h:599
Expr * VisitGNUNullExpr(GNUNullExpr *E)
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:1720
SourceLocation getIvarLBraceLoc() const
Definition: DeclObjC.h:2594
Import the default subset of the definition, which might be nothing (if minimal import is set) or mig...
SourceLocation getSwitchLoc() const
Definition: Stmt.h:1007
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
Definition: DeclBase.cpp:1304
SourceLocation getAtStartLoc() const
Definition: DeclObjC.h:1036
Stmt * VisitDeclStmt(DeclStmt *S)
ObjCProtocolDecl * getProtocol(unsigned I) const
Fetch a protocol by index.
Definition: Type.h:4847
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:2718
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
Definition: Type.h:4059
Represents the this expression in C++.
Definition: ExprCXX.h:873
bool hadMultipleCandidates() const
Whether the referred constructor was resolved from an overloaded set having size greater than 1...
Definition: ExprCXX.h:1236
DiagnosticsEngine & getDiagnostics() const
arg_iterator arg_end()
Definition: Expr.h:2248
field_iterator field_end() const
Definition: Decl.h:3385
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
SourceLocation getAtLoc() const
Definition: DeclObjC.h:773
SourceLocation getBuiltinLoc() const
Definition: Expr.h:3684
EnumDecl * getDecl() const
Definition: Type.h:3739
Expr * getRHS() const
Definition: Expr.h:3216
Represents a K&R-style 'int foo()' function, which has no information available about its arguments...
Definition: Type.h:3039
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition: DeclObjC.h:2655
SourceLocation getOperatorLoc() const LLVM_READONLY
Definition: Expr.h:2508
bool isUnion() const
Definition: Decl.h:2939
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)
completeDefinition - When created, the EnumDecl corresponds to a forward-declared enum...
Definition: Decl.cpp:3653
QualType getInjectedSpecializationType() const
Definition: Type.h:4326
Decl * VisitCXXDestructorDecl(CXXDestructorDecl *D)
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
Definition: DeclObjC.h:2109
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:3170
SourceLocation getLocStart() const LLVM_READONLY
Definition: DeclObjC.h:2709
QualType VisitObjCObjectType(const ObjCObjectType *T)
ExtInfo getExtInfo() const
Definition: Type.h:3018
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:1248
TypeAliasDecl - Represents the declaration of a typedef-name via a C++0x alias-declaration.
Definition: Decl.h:2701
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:873
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:551
SourceLocation getAsmLoc() const
Definition: Stmt.h:1443
QualType getParamType(unsigned i) const
Definition: Type.h:3272
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3073
IdentifierInfo * getFieldName() const
Definition: Expr.cpp:3512
Decl * VisitRecordDecl(RecordDecl *D)
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition: Type.h:3304
SourceLocation getLocStart() const LLVM_READONLY
Definition: Decl.h:2593
Expr ** getSubExprs()
Definition: Expr.h:4864
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
Decl * VisitCXXConversionDecl(CXXConversionDecl *D)
ObjCPropertyImplDecl * FindPropertyImplDecl(IdentifierInfo *propertyId, ObjCPropertyQueryKind queryKind) const
FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl added to the list of thos...
Definition: DeclObjC.cpp:2050
CastKind
CastKind - The kind of operation required for a conversion.
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat)
Definition: Expr.cpp:1652
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:462
A dependent template name that has not been resolved to a template (or set of templates).
Definition: TemplateName.h:198
unsigned getChainingSize() const
Definition: Decl.h:2546
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand...
Definition: Expr.h:1974
decl_range noload_decls() const
noload_decls_begin/end - Iterate over the declarations stored in this context that are currently load...
Definition: DeclBase.h:1461
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:2259
NamedDecl * getDecl() const
Stmt * VisitObjCForCollectionStmt(ObjCForCollectionStmt *S)
ASTContext * Context
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this category.
Definition: DeclObjC.cpp:1963
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on a template...
Definition: Expr.h:189
ImportDefinitionKind
What we should import from the definition.
Definition: ASTImporter.cpp:96
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:3655
Expr * getCond() const
Definition: Expr.h:3204
SourceLocation getSuperClassLoc() const
Definition: DeclObjC.h:2589
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:2063
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:415
void setInClassInitializer(Expr *Init)
setInClassInitializer - Set the C++11 in-class initializer for this member.
Definition: Decl.h:2424
SourceLocation getColonLoc() const
Definition: Stmt.h:711
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl...
NameKind getNameKind() const
getNameKind - Determine what kind of name this is.
SourceLocation getThrowLoc() const LLVM_READONLY
Definition: StmtObjC.h:329
static unsigned getNumSubExprs(AtomicOp Op)
Determine the number of arguments the specified atomic builtin should have.
Definition: Expr.cpp:3841
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called...
Definition: ExprCXX.h:1252
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:1972
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:2659
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
Expr * VisitParenExpr(ParenExpr *E)
LabelDecl * getDecl() const
Definition: Stmt.h:806
unsigned getNumExprs() const
Definition: Expr.h:4350
SourceLocation getVarianceLoc() const
Retrieve the location of the variance keyword.
Definition: DeclObjC.h:582
void setGetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:861
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition: Decl.cpp:2276
IdentifierInfo * getInputIdentifier(unsigned i) const
Definition: Stmt.h:1683
llvm::MutableArrayRef< Designator > designators()
Definition: Expr.h:4156
QualType getPointeeType() const
Definition: Type.h:2300
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Definition: Decl.h:590
Expr - This represents one expression.
Definition: Expr.h:105
Stmt * VisitGotoStmt(GotoStmt *S)
StringRef getName() const
Return the actual identifier string.
Decl * VisitEnumConstantDecl(EnumConstantDecl *D)
DeclStmt * getEndStmt()
Definition: StmtCXX.h:158
SourceLocation getRParenLoc() const
Definition: Expr.h:2044
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:750
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:102
SourceLocation getLParenLoc() const
Definition: DeclCXX.h:2126
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:864
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition: ExprCXX.h:1240
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "while" statement, if any.
Definition: Stmt.cpp:871
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:2721
Expr * VisitDeclRefExpr(DeclRefExpr *E)
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:1281
void setSyntacticForm(InitListExpr *Init)
Definition: Expr.h:3886
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:54
static ClassTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl, ClassTemplateDecl *PrevDecl)
Create a class template node.
SourceLocation getLBraceLoc() const
Definition: Expr.h:3873
TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, UnresolvedSetIterator End) const
Retrieve the template name that corresponds to a non-empty lookup.
Expr * getBitWidth() const
Definition: Decl.h:2375
ArrayRef< NamedDecl * > chain() const
Definition: Decl.h:2540
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:2414
void setInit(Expr *I)
Definition: Decl.cpp:2081
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:886
SourceLocation getGotoLoc() const
Definition: Stmt.h:1238
Expr * getUnderlyingExpr() const
Definition: Type.h:3532
void setRBraceLoc(SourceLocation L)
Definition: DeclCXX.h:2578
Stmt * VisitIfStmt(IfStmt *S)
bool isGnuLocal() const
Definition: Decl.h:452
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:4460
static CXXStaticCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:510
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:216
SourceLocation getLocation() const
Definition: ExprCXX.h:1227
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:3280
static Optional< unsigned > findUntaggedStructOrUnionIndex(RecordDecl *Anon)
Find the index of the given anonymous struct/union within its context.
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
Definition: Expr.h:4175
Decl * VisitLinkageSpecDecl(LinkageSpecDecl *D)
Stmt * getBody()
Definition: Stmt.h:1078
static ObjCTypeParamDecl * Create(ASTContext &ctx, DeclContext *dc, ObjCTypeParamVariance variance, SourceLocation varianceLoc, unsigned index, SourceLocation nameLoc, IdentifierInfo *name, SourceLocation colonLoc, TypeSourceInfo *boundInfo)
Definition: DeclObjC.cpp:1315
Expr * VisitAddrLabelExpr(AddrLabelExpr *E)
Decl * VisitAccessSpecDecl(AccessSpecDecl *D)
A structure for storing the information associated with a substituted template template parameter...
Definition: TemplateName.h:314
Expr * getRHS()
Definition: Stmt.h:715
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:1259
ParmVarDecl *const * param_iterator
Definition: DeclObjC.h:350
Represents Objective-C's @synchronized statement.
Definition: StmtObjC.h:262
void setGetterName(Selector Sel)
Definition: DeclObjC.h:855
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
CXXTryStmt - A C++ try block, including all handlers.
Definition: StmtCXX.h:65
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:2028
Expr * VisitPredefinedExpr(PredefinedExpr *E)
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition: Expr.cpp:746
Represents a C++ template name within the type system.
Definition: TemplateName.h:176
Represents the type decltype(expr) (C++11).
Definition: Type.h:3590
QualType VisitConstantArrayType(const ConstantArrayType *T)
A namespace alias, stored as a NamespaceAliasDecl*.
void setImplementation(ObjCImplementationDecl *ImplD)
Definition: DeclObjC.cpp:1494
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
SourceRange getAngleBrackets() const LLVM_READONLY
Definition: ExprCXX.h:235
SourceLocation getMemberLocation() const
Definition: DeclCXX.h:2088
SourceLocation getEndLoc() const
Definition: Stmt.h:470
Kind getAttrKind() const
Definition: Type.h:3827
Stmt * VisitObjCAtTryStmt(ObjCAtTryStmt *S)
const SwitchCase * getSwitchCaseList() const
Definition: Stmt.h:996
SourceLocation getQuestionLoc() const
Definition: Expr.h:3159
Expr * VisitCXXThisExpr(CXXThisExpr *E)
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3188
Expr * getSubExpr() const
Definition: Expr.h:1695
bool isIndirectMemberInitializer() const
Definition: DeclCXX.h:2014
SourceLocation getLabelLoc() const
Definition: Stmt.h:1240
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:3631
bool isInstanceMethod() const
Definition: DeclObjC.h:414
bool isFunctionOrMethod() const
Definition: DeclBase.h:1263
void ImportDeclarationNameLoc(const DeclarationNameInfo &From, DeclarationNameInfo &To)
QualType getCXXNameType() const
getCXXNameType - If this name is one of the C++ names (of a constructor, destructor, or conversion function), return the type associated with that name.
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:269
ReturnStmt - This represents a return, optionally of an expression: return; return 4;...
Definition: Stmt.h:1366
const TemplateArgument * data() const
Retrieve a pointer to the template argument list.
Definition: DeclTemplate.h:234
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
Definition: Expr.h:1668
Represents a GCC generic vector type.
Definition: Type.h:2756
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2366
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
Definition: Decl.h:258
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Stmt * VisitReturnStmt(ReturnStmt *S)
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
class LLVM_ALIGNAS(8) TemplateSpecializationType unsigned NumArgs
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:4154
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: Stmt.cpp:313
ValueDecl * getDecl()
Definition: Expr.h:1017
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
QualType getElementType() const
Definition: Type.h:2780
QualType getComputationLHSType() const
Definition: Expr.h:3115
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2461
The result type of a method or function.
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr.cast]), which uses the syntax (Type)expr.
Definition: Expr.h:2834
RecordDecl * getDefinition() const
getDefinition - Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:3372
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name, with source-location information.
Definition: Expr.h:1036
AtomicOp getOp() const
Definition: Expr.h:4861
SourceLocation getLParenLoc() const
Definition: Expr.h:2595
SourceLocation getSemiLoc() const
Definition: Stmt.h:529
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:671
QualType getReplacementType() const
Gets the type that was substituted for the template parameter.
Definition: Type.h:4004
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:2961
CanQualType SignedCharTy
Definition: ASTContext.h:901
const Expr * getAnyInitializer() const
getAnyInitializer - Get the initializer for this variable, no matter which declaration it is attached...
Definition: Decl.h:1129
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:1883
Decl * VisitObjCMethodDecl(ObjCMethodDecl *D)
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression, including the actual initialized value and any expressions that occur within array and array-range designators.
Definition: Expr.h:4196
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:1832
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:94
DoStmt - This represents a 'do/while' stmt.
Definition: Stmt.h:1102
ObjCCategoryDecl * getCategoryDecl() const
Definition: DeclObjC.cpp:1999
param_const_iterator param_end() const
Definition: DeclObjC.h:357
bool isArrayRangeDesignator() const
Definition: Expr.h:4078
QualType getComputationResultType() const
Definition: Expr.h:3118
QualType VisitEnumType(const EnumType *T)
LabelDecl * getLabel() const
Definition: Stmt.h:1235
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc)
ArrayRef< ParmVarDecl * > parameters() const
Definition: DeclObjC.h:371
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
Definition: Type.h:3998
Stmt * getBody(const FunctionDecl *&Definition) const
getBody - Retrieve the body (definition) of the function.
Definition: Decl.cpp:2491
SourceLocation getOperatorLoc() const
Definition: Expr.h:2041
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
Expr * VisitParenListExpr(ParenListExpr *E)
A template template parameter pack that has been substituted for a template template argument pack...
Definition: TemplateName.h:205
SourceLocation getDotLoc() const
Definition: Expr.h:4095
ASTContext & getFromContext() const
Retrieve the context that AST nodes are being imported from.
Definition: ASTImporter.h:259
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:215
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
Definition: Expr.h:848
SourceLocation getGotoLoc() const
Definition: Stmt.h:1273
SourceLocation getExternLoc() const
Definition: DeclCXX.h:2575
const StringLiteral * getAsmString() const
Definition: Stmt.h:1592
#define false
Definition: stdbool.h:33
SelectorTable & Selectors
Definition: ASTContext.h:460
Kind
Decl * VisitIndirectFieldDecl(IndirectFieldDecl *D)
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:3153
static ClassTemplateSpecializationDecl * Create(ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, ArrayRef< TemplateArgument > Args, ClassTemplateSpecializationDecl *PrevDecl)
Decl * VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D)
Encodes a location in the source.
bool isConstexpr() const
Definition: Stmt.h:933
bool isAnonymousStructOrUnion() const
isAnonymousStructOrUnion - Determines whether this field is a representative for an anonymous struct ...
Definition: Decl.cpp:3458
Sugar for parentheses used when specifying types.
Definition: Type.h:2148
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:5259
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Definition: Type.h:3733
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:262
QualType VisitFunctionProtoType(const FunctionProtoType *T)
const TemplateArgument * iterator
Definition: Type.h:4233
QualType getElementType() const
Definition: Type.h:2131
unsigned getBitWidthValue(const ASTContext &Ctx) const
Definition: Decl.cpp:3468
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition: Expr.h:902
Represents typeof(type), a GCC extension.
Definition: Type.h:3566
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:4936
const TemplateArgumentListInfo & getTemplateArgsInfo() const
QualType VisitBuiltinType(const BuiltinType *T)
SourceLocation getLocStart() const LLVM_READONLY
Definition: Decl.h:568
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:119
OverloadedOperatorKind getCXXOverloadedOperator() const
getCXXOverloadedOperator - If this name is the name of an overloadable operator in C++ (e...
Expr * getLHS()
Definition: Stmt.h:714
const std::string ID
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2727
TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, const IdentifierInfo *Name) const
Retrieve the template name that represents a dependent template name such as MetaFun::template apply...
Represents a call to a member function that may be written either with member call syntax (e...
Definition: ExprCXX.h:121
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:1141
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
Definition: Stmt.h:443
static QualType getUnderlyingType(const SubRegion *R)
Decl * VisitTranslationUnitDecl(TranslationUnitDecl *D)
LabelDecl - Represents the declaration of a label.
Definition: Decl.h:424
void setPropertyAttributesAsWritten(PropertyAttributeKind PRVal)
Definition: DeclObjC.h:806
const Expr * getCond() const
Definition: Stmt.h:994
bool isVariadic() const
Definition: DeclObjC.h:416
VectorKind getVectorKind() const
Definition: Type.h:2789
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:53
SourceLocation getIdentLoc() const
Definition: Stmt.h:805
Decl * VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D)
Expr * VisitMemberExpr(MemberExpr *E)
void setCtorInitializers(CXXCtorInitializer **Initializers)
Definition: DeclCXX.h:2301
QualType getTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon=QualType()) const
bool getSynthesize() const
Definition: DeclObjC.h:1895
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1736
unsigned getDepth() const
Retrieve the depth of the template parameter.
bool shouldForceImportDeclContext(ImportDefinitionKind IDK)
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:178
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:1989
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition: DeclCXX.h:2055
SourceLocation getLBracketLoc() const
Definition: Expr.h:4105
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition: DeclObjC.h:1397
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)
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2171
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:2325
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the similarly-named C++11 instructions, and __c11 variants for <stdatomic.h>.
Definition: Expr.h:4804
bool isPropertyAccessor() const
Definition: DeclObjC.h:421
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:82
QualType VisitTypedefType(const TypedefType *T)
SourceLocation getContinueLoc() const
Definition: Stmt.h:1310
const FileInfo & getFile() const
StringLiteral * getFunctionName()
Definition: Expr.cpp:446
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition: ExprCXX.h:228
const internal::VariadicDynCastAllOfMatcher< Decl, AccessSpecDecl > accessSpecDecl
Matches C++ access specifier declarations.
Definition: ASTMatchers.h:426
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition: DeclCXX.h:2035
static CXXDefaultInitExpr * Create(const ASTContext &C, SourceLocation Loc, FieldDecl *Field)
Field is the non-static data member whose default initializer is used by this expression.
Definition: ExprCXX.h:1052
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:699
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "switch" statement, if any.
Definition: Stmt.cpp:837
TypedefNameDecl * getDecl() const
Definition: Type.h:3516
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition: DeclObjC.h:2233
ASTNodeImporter(ASTImporter &Importer)
Definition: ASTImporter.cpp:34
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:2734
Stmt * VisitForStmt(ForStmt *S)
unsigned getNumProtocols() const
Return the number of qualifying protocols in this interface type, or 0 if there are none...
Definition: Type.h:4844
Expr ** getInits()
Retrieve the set of initializers.
Definition: Expr.h:3779
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
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
Member-template castAs<specific type>.
Definition: Type.h:5849
static DesignatedInitExpr * Create(const ASTContext &C, llvm::ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition: Expr.cpp:3586
QualType getAttributedType(AttributedType::Kind attrKind, QualType modifiedType, QualType equivalentType)
QualType VisitRecordType(const RecordType *T)
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent) const
C++11 deduced auto type.
Decl * VisitVarTemplateDecl(VarTemplateDecl *D)
Stmt * VisitCompoundStmt(CompoundStmt *S)
Stmt * VisitIndirectGotoStmt(IndirectGotoStmt *S)
Decl * VisitImplicitParamDecl(ImplicitParamDecl *D)
Expr * VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E)
Expr ** getExprs()
Definition: Expr.h:4362
SourceLocation getAtSynchronizedLoc() const
Definition: StmtObjC.h:279
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition: Decl.h:2067
Stmt * VisitWhileStmt(WhileStmt *S)
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:3380
Attr * clone(ASTContext &C) const
UTTKind getUTTKind() const
Definition: Type.h:3655
Expr * VisitCallExpr(CallExpr *E)
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition: Expr.h:3831
SourceLocation getCategoryNameLoc() const
Definition: DeclObjC.h:2419
Decl * VisitLabelDecl(LabelDecl *D)
QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T)
void setHasInheritedDefaultArg(bool I=true)
Definition: Decl.h:1509
SourceLocation getForLoc() const
Definition: StmtCXX.h:193
void sawArrayRangeDesignator(bool ARD=true)
Definition: Expr.h:3896
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:70
static CXXReinterpretCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:594
SourceLocation getLParenLoc() const
Definition: DeclObjC.h:776
Opcode getOpcode() const
Definition: Expr.h:1692
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:245
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:1402
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:193
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:4294
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
Definition: DeclCXX.cpp:1302
QualType getPointeeType() const
Definition: Type.h:2193
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition: Expr.h:1699
void setVirtualAsWritten(bool V)
Definition: Decl.h:1833
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:4157
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:3092
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments of this object type as they were written.
Definition: Type.h:4828
A POD class for pairing a NamedDecl* with an access specifier.
const char * getTypeClassName() const
Definition: Type.cpp:2509
Expr * getSizeExpr() const
Definition: Type.h:2679
bool isArrow() const
Definition: Expr.h:2510
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition: Expr.h:3339
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2609
QualType getType() const
Definition: Expr.h:126
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool isAnonymousStructOrUnion() const
isAnonymousStructOrUnion - Whether this is an anonymous struct or union.
Definition: Decl.h:3320
CanQualType CharTy
Definition: ASTContext.h:895
Represents a template argument.
Definition: TemplateBase.h:40
SourceLocation getLocation() const
Definition: Expr.h:1330
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:2501
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:238
static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls)
Definition: DeclGroup.h:71
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "if" statement, if any.
Definition: Stmt.cpp:778
NonEquivalentDeclSet & getNonEquivalentDecls()
Return the set of declarations that we know are not equivalent.
Definition: ASTImporter.h:274
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition: Expr.h:3280
Represents a template name that was expressed as a qualified name.
Definition: TemplateName.h:355
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition: DeclCXX.h:2063
SourceLocation getExprLoc() const LLVM_READONLY
Definition: Expr.h:885
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition: Stmt.h:511
Selector getObjCSelector() const
getObjCSelector - Get the Objective-C selector stored in this declaration name.
SourceLocation getColonLoc() const
The location of the colon following the access specifier.
Definition: DeclCXX.h:122
TemplateName getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param, const TemplateArgument &ArgPack) const
ObjCCategoryDecl * FindCategoryDeclaration(IdentifierInfo *CategoryId) const
FindCategoryDeclaration - Finds category declaration in the list of categories for this class and ret...
Definition: DeclObjC.cpp:1593
Expr * VisitCXXNamedCastExpr(CXXNamedCastExpr *E)
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition: Decl.cpp:2328
static LinkageSpecDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation ExternLoc, SourceLocation LangLoc, LanguageIDs Lang, bool HasBraces)
Definition: DeclCXX.cpp:2025
virtual void CompleteDecl(Decl *D)
Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl.
SourceRange getCXXOperatorNameRange() const
getCXXOperatorNameRange - Gets the range of the operator name (without the operator keyword)...
SourceLocation getLParenLoc() const
Definition: Expr.h:2860
ObjCCategoryImplDecl * getImplementation() const
Definition: DeclObjC.cpp:1954
void ImportDeclContext(DeclContext *FromDC, bool ForceImport=false)
bool hasTemplateKeyword() const
Whether the template name was prefixed by the "template" keyword.
Definition: TemplateName.h:382
bool hadMultipleCandidates() const
Returns true if this expression refers to a function that was resolved from an overloaded set having ...
Definition: Expr.h:1129
static NonTypeTemplateParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id, QualType T, bool ParameterPack, TypeSourceInfo *TInfo)
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1160
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1135
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
SourceLocation getStarLoc() const
Definition: Stmt.h:1275
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:330
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...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchers.h:1983
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:877
const Stmt * getBody() const
Definition: Stmt.h:995
SourceLocation getLocStart() const LLVM_READONLY
Definition: TypeLoc.h:130
QualType getPromotionType() const
getPromotionType - Return the integer type that enumerators should promote to.
Definition: Decl.h:3129
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:63
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:2430
static bool IsArrayStructurallyEquivalent(StructuralEquivalenceContext &Context, const ArrayType *Array1, const ArrayType *Array2)
Determine structural equivalence for the common part of array types.
IndirectFieldDecl - An instance of this class is created to represent a field injected from an anonym...
Definition: Decl.h:2521
QualType getEquivalentType() const
Definition: Type.h:3832
const llvm::APSInt & getInitVal() const
Definition: Decl.h:2500
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition: DeclObjC.h:1454
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
bool isParameterPack() const
Definition: Type.h:3947
LanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition: DeclCXX.h:2564
SourceLocation getPropertyIvarDeclLoc() const
Definition: DeclObjC.h:2724
bool hasWrittenPrototype() const
Definition: Decl.h:1875
const ContentCache * getContentCache() const
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
DeclarationName - The name of a declaration.
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:532
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:854
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
const StringLiteral * getOutputConstraintLiteral(unsigned i) const
Definition: Stmt.h:1668
DefinitionKind isThisDeclarationADefinition(ASTContext &) const
Check whether this declaration is a definition.
Definition: Decl.cpp:1911
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:2089
Decl * VisitClassTemplateDecl(ClassTemplateDecl *D)
QualType getTemplateTypeParmType(unsigned Depth, unsigned Index, bool ParameterPack, TemplateTypeParmDecl *ParmDecl=nullptr) const
Retrieve the template type parameter type for a template parameter or parameter pack with the given d...
A set of unresolved declarations.
StringRef getBytes() const
Allow access to clients that need the byte representation, such as ASTWriterStmt::VisitStringLiteral(...
Definition: Expr.h:1522
SourceLocation getWhileLoc() const
Definition: Stmt.h:1129
void setInstantiationDependent(bool ID)
Set whether this expression is instantiation-dependent or not.
Definition: Expr.h:194
SourceLocation getLocStart() const LLVM_READONLY
Definition: Decl.h:693
bool isNull() const
Determine whether this template argument has no value.
Definition: TemplateBase.h:219
StringKind getKind() const
Definition: Expr.h:1554
EnumDecl - Represents an enum.
Definition: Decl.h:3013
bool path_empty() const
Definition: Expr.h:2698
void ImportArray(IIter Ibegin, IIter Iend, OIter Obegin)
detail::InMemoryDirectory::const_iterator E
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:2401
QualType getModifiedType() const
Definition: Type.h:3831
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
Definition: Expr.h:4180
const Expr * getRetValue() const
Definition: Stmt.cpp:899
Expr * VisitImplicitValueInitExpr(ImplicitValueInitExpr *ILE)
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition: Expr.h:2205
SourceLocation getLocation() const
Definition: ExprCXX.h:889
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:1966
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition: DeclCXX.h:2069
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
unsigned getNumArgs() const
Definition: ExprCXX.h:1285
unsigned getNumConcatenated() const
getNumConcatenated - Get the number of string literal tokens that were concatenated in translation ph...
Definition: Expr.h:1574
void setInitializedFieldInUnion(FieldDecl *FD)
Definition: Expr.h:3855
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:3627
body_iterator body_begin()
Definition: Stmt.h:582
Decl * VisitObjCIvarDecl(ObjCIvarDecl *D)
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
Definition: DeclBase.h:1473
VarTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
static LabelDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II)
Definition: Decl.cpp:3980
llvm::APFloat getValue() const
Definition: Expr.h:1368
Decl * VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D)
unsigned getDepth() const
Get the nesting depth of the template parameter.
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:5006
const Stmt * getThen() const
Definition: Stmt.h:919
QualType VisitLValueReferenceType(const LValueReferenceType *T)
Represents a pointer to an Objective C object.
Definition: Type.h:4991
SwitchStmt - This represents a 'switch' stmt.
Definition: Stmt.h:957
SourceLocation getAtCatchLoc() const
Definition: StmtObjC.h:102
Pointer to a block type.
Definition: Type.h:2286
bool hasInheritedDefaultArg() const
Definition: Decl.h:1505
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:1677
Expr * VisitFloatingLiteral(FloatingLiteral *E)
SourceLocation getRParenLoc() const
Definition: StmtObjC.h:104
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2461
ObjCMethodDecl * getGetterMethodDecl() const
Definition: DeclObjC.h:860
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:3163
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:3707
Complex values, per C99 6.2.5p11.
Definition: Type.h:2119
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition: Decl.h:3180
VarDecl * getTemplatedDecl() const
Get the underlying variable declarations of the template.
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:3590
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:5818
Imports selected nodes from one AST context into another context, merging AST nodes where appropriate...
Definition: ASTImporter.h:39
unsigned getTypeQuals() const
Definition: Type.h:3378
const Stmt * getSubStmt() const
Definition: StmtObjC.h:356
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T)
Definition: Decl.cpp:4016
Represents Objective-C's collection statement.
Definition: StmtObjC.h:24
Represents a C++ base or member initializer.
Definition: DeclCXX.h:1922
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition: Expr.h:3283
Expr * VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E)
bool isInvalid() const
arg_iterator arg_begin()
Definition: Expr.h:2247
ObjCMethodDecl * getSetterMethodDecl() const
Definition: DeclObjC.h:863
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:1649
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:1673
QualType getIntegralType() const
Retrieve the type of the integral value.
Definition: TemplateBase.h:294
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2242
CanQualType WCharTy
Definition: ASTContext.h:896
bool isNull() const
Determine whether this template name is NULL.
QualType getIntegerType() const
getIntegerType - Return the integer type this enum decl corresponds to.
Definition: Decl.h:3137
void setBuiltinID(unsigned ID)
TypeSourceInfo * getWrittenTypeInfo() const
Definition: Expr.h:3681
void setSwitchLoc(SourceLocation L)
Definition: Stmt.h:1008
Stmt * getInit()
Definition: Stmt.h:991
ExtVectorType - Extended vector type.
Definition: Type.h:2816
QualType getInnerType() const
Definition: Type.h:2162
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2319
void setSetterName(Selector Sel)
Definition: DeclObjC.h:858
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1534
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition: ExprCXX.h:1225
SourceLocation getRBraceLoc() const
Definition: DeclCXX.h:2576
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition: Decl.h:1848
bool isVolatile() const
Definition: Stmt.h:1449
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition: DeclObjC.h:1815
Represents Objective-C's @finally statement.
Definition: StmtObjC.h:120
DesignatedInitExpr::Designator Designator
Definition: ASTImporter.cpp:91
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:1540
The template argument is a type.
Definition: TemplateBase.h:48
ObjCImplementationDecl * getImplementation() const
Definition: DeclObjC.cpp:1481
The template argument is actually a parameter pack.
Definition: TemplateBase.h:72
LabelDecl * getLabel() const
Definition: Expr.h:3361
protocol_iterator protocol_end() const
Definition: DeclObjC.h:1291
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
Represents a base class of a C++ class.
Definition: DeclCXX.h:159
QualType VisitUnaryTransformType(const UnaryTransformType *T)
unsigned getNumCatchStmts() const
Retrieve the number of @catch statements in this try-catch-finally block.
Definition: StmtObjC.h:203
const Expr * getInitializer() const
Definition: Expr.h:2588
SourceLocation getRParenLoc() const
Definition: Expr.h:2863
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
Decl * VisitObjCTypeParamDecl(ObjCTypeParamDecl *D)
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:3155
SourceManager & getSourceManager()
Definition: ASTContext.h:561
SourceLocation getForLoc() const
Definition: Stmt.h:1200
SourceLocation getLocation() const
Definition: ExprCXX.h:519
The type-property cache.
Definition: Type.cpp:3242
DeclStmt * getRangeStmt()
Definition: StmtCXX.h:154
Stmt * VisitObjCAtThrowStmt(ObjCAtThrowStmt *S)
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condnition evaluates to false;...
Definition: Expr.h:3299
GotoStmt - This represents a direct goto.
Definition: Stmt.h:1224
ArrayRef< const Attr * > getAttrs() const
Definition: Stmt.h:862
void ImportDefinition(Decl *From)
Import the definition of the given declaration, including all of the declarations it contains...
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1037
Expr * getTarget()
Definition: Stmt.h:1277
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:1135
Expr * getBase() const
Definition: Expr.h:2405
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
const Type * getClass() const
Definition: Type.h:2434
ObjCPropertyDecl * getPropertyDecl() const
Definition: DeclObjC.h:2712
SourceLocation getAttrLoc() const
Definition: Stmt.h:861
AccessControl getAccessControl() const
Definition: DeclObjC.h:1888
Decl * VisitTypeAliasDecl(TypeAliasDecl *D)
Expr * NoexceptExpr
Noexcept expression, if this is EST_ComputedNoexcept.
Definition: Type.h:3157
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
Definition: TemplateBase.h:256
Expr * VisitInitListExpr(InitListExpr *E)
QualType getTypeOfExprType(Expr *e) const
GCC extension.
DeclarationName getCXXLiteralOperatorName(IdentifierInfo *II)
getCXXLiteralOperatorName - Get the name of the literal operator function with II as the identifier...
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:3761
Expr * getCond()
Definition: Stmt.h:1120
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
const StringLiteral * getInputConstraintLiteral(unsigned i) const
Definition: Stmt.h:1696
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:2315
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:335
bool isImplicitInterfaceDecl() const
isImplicitInterfaceDecl - check that this is an implicitly declared ObjCInterfaceDecl node...
Definition: DeclObjC.h:1794
const Expr * getSubExpr() const
Definition: Expr.h:1635
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...
SourceLocation getBuiltinLoc() const
Definition: Expr.h:4880
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition: Expr.h:3841
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition: ExprCXX.h:231
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum...
Definition: Decl.h:3163
Represents a C++ struct/union/class.
Definition: DeclCXX.h:263
static IndirectFieldDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, llvm::MutableArrayRef< NamedDecl * > CH)
Definition: Decl.cpp:4108
ContinueStmt - This represents a continue.
Definition: Stmt.h:1302
Expr * VisitDesignatedInitExpr(DesignatedInitExpr *E)
SourceLocation getRParenLoc() const
Definition: Stmt.h:1204
The template argument is a template name that was provided for a template template parameter...
Definition: TemplateBase.h:60
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition: Decl.cpp:2281
Represents a C array with an unspecified size.
Definition: Type.h:2562
Opcode getOpcode() const
Definition: Expr.h:2940
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition: Expr.h:3240
SourceLocation getBreakLoc() const
Definition: Stmt.h:1340
CXXCatchStmt - This represents a C++ catch block.
Definition: StmtCXX.h:29
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1849
static TypedefDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
Definition: Decl.cpp:4129
ArraySizeModifier getSizeModifier() const
Definition: Type.h:2491
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:4391
WhileStmt - This represents a 'while' stmt.
Definition: Stmt.h:1047
A structure for storing the information associated with an overloaded template name.
Definition: TemplateName.h:93
SourceLocation getColonLoc() const
Definition: Stmt.h:766
const Expr * getCond() const
Definition: Stmt.h:917
ObjCPropertyQueryKind getQueryKind() const
Definition: DeclObjC.h:830
SourceLocation getElseLoc() const
Definition: Stmt.h:930
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.
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition: DeclObjC.h:610
Stmt * VisitSwitchStmt(SwitchStmt *S)
This class is used for builtin types like 'int'.
Definition: Type.h:2039
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:353
CompoundStmt * getTryBlock()
Definition: StmtCXX.h:96
void setPropertyAttributes(PropertyAttributeKind PRVal)
Definition: DeclObjC.h:795
Represents Objective-C's @try ... @catch ... @finally statement.
Definition: StmtObjC.h:154
bool isSimple() const
Definition: Stmt.h:1446
unsigned getIndex() const
Retrieve the index of the template parameter.
Expr * VisitVAArgExpr(VAArgExpr *E)
const Expr * getThrowExpr() const
Definition: StmtObjC.h:325
const StringRef Input
QualType getParamTypeForDecl() const
Definition: TemplateBase.h:250
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:378
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1466
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2148
Expr * getRHS() const
Definition: Expr.h:2945
ASTContext & getToContext() const
Retrieve the context that AST nodes are being imported into.
Definition: ASTImporter.h:256
bool isExact() const
Definition: Expr.h:1394
Expr * VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E)
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:314
Expr * VisitOpaqueValueExpr(OpaqueValueExpr *E)
PropertyAttributeKind getPropertyAttributesAsWritten() const
Definition: DeclObjC.h:802
Stmt * VisitDefaultStmt(DefaultStmt *S)
QualType getPointeeTypeAsWritten() const
Definition: Type.h:2339
SourceLocation getRBracLoc() const
Definition: Stmt.h:630
Import only the bare bones needed to establish a valid DeclContext.
SourceLocation getColonLoc() const
Definition: StmtCXX.h:195
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:810
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition: ExprCXX.h:203
bool isMicrosoftABI() const
Returns whether this is really a Win64 ABI va_arg expression.
Definition: Expr.h:3678
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:1247
void setNextSwitchCase(SwitchCase *SC)
Definition: Stmt.h:668
SourceLocation getIvarRBraceLoc() const
Definition: DeclObjC.h:2596
const Stmt * getTryBody() const
Retrieve the @try body.
Definition: StmtObjC.h:197
TranslationUnitDecl - The top declaration context.
Definition: Decl.h:80
void ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD=nullptr)
VarDecl * getArrayIndex(unsigned I)
Retrieve a particular array index variable used to describe an array member initialization.
Definition: DeclCXX.h:2137
QualType VisitTypeOfExprType(const TypeOfExprType *T)
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace nested inside this namespace, if any.
Definition: Decl.h:548
VarDecl * getExceptionDecl() const
Definition: StmtCXX.h:50
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:932
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:401
Expr * VisitBinaryConditionalOperator(BinaryConditionalOperator *E)
QualType getDecltypeType(Expr *e, QualType UnderlyingType) const
C++11 decltype.
SourceLocation getRAngleLoc() const
Definition: DeclTemplate.h:133
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:2490
BreakStmt - This represents a break.
Definition: Stmt.h:1328
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
SourceLocation getInnerLocStart() const
getInnerLocStart - Return SourceLocation representing start of source range ignoring outer template d...
Definition: Decl.h:685
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition: Expr.h:3849
Expr * VisitCompoundLiteralExpr(CompoundLiteralExpr *E)
Stmt * getSubStmt()
Definition: Stmt.h:809
DeclStmt * getLoopVarStmt()
Definition: StmtCXX.h:161
unsigned getNumClobbers() const
Definition: Stmt.h:1494
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Definition: Expr.h:3292
A set of overloaded template declarations.
Definition: TemplateName.h:192
SourceLocation getRParenLoc() const
Definition: StmtCXX.h:196
unsigned getFirstExprIndex() const
Definition: Expr.h:4123
A trivial tuple used to represent a source range.
static VarTemplateSpecializationDecl * Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, StorageClass S, ArrayRef< TemplateArgument > Args)
NamedDecl - This represents a decl with a name.
Definition: Decl.h:213
DeclarationNameInfo getNameInfo() const
Definition: Decl.h:1746
SourceLocation getRParenLoc() const
Definition: Expr.h:4881
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition: ExprCXX.h:471
static ObjCCategoryImplDecl * Create(ASTContext &C, DeclContext *DC, IdentifierInfo *Id, ObjCInterfaceDecl *classInterface, SourceLocation nameLoc, SourceLocation atStartLoc, SourceLocation CategoryNameLoc)
Definition: DeclObjC.cpp:1980
static DeclarationName getUsingDirectiveName()
getUsingDirectiveName - Return name for all using-directives.
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:2607
EnumDecl * getDefinition() const
Definition: Decl.h:3082
Decl * VisitNamespaceDecl(NamespaceDecl *D)
Represents a C++ namespace alias.
Definition: DeclCXX.h:2718
Decl * VisitObjCInterfaceDecl(ObjCInterfaceDecl *D)
Stmt * VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S)
SourceLocation getStartLoc() const
Definition: Stmt.h:468
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:203
SourceLocation getLocation() const
Definition: Expr.h:1402
DeclStmt * getBeginStmt()
Definition: StmtCXX.h:155
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:665
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:2644
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:3443
The global specifier '::'. There is no stored value.
void setType(QualType newType)
Definition: Decl.h:600
static CXXConstructorDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool isExplicit, bool isInline, bool isImplicitlyDeclared, bool isConstexpr, InheritedConstructor Inherited=InheritedConstructor())
Definition: DeclCXX.cpp:1833
SourceLocation ColonLoc
Location of ':'.
Definition: OpenMPClause.h:266
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
Stmt * VisitGCCAsmStmt(GCCAsmStmt *S)
QualType VisitAutoType(const AutoType *T)
TemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon, QualType Aliased)
SourceLocation getFieldLoc() const
Definition: Expr.h:4100
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
Definition: DeclObjC.h:2380
ArrayRef< QualType > exceptions() const
Definition: Type.h:3401
bool isBeingDefined() const
isBeingDefined - Return true if this decl is currently being defined.
Definition: Decl.h:2882
This class handles loading and caching of source files into memory.
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:2512
Stmt * getSubStmt()
Definition: Stmt.h:865
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:3187
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:874
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:4315
static ObjCAtTryStmt * Create(const ASTContext &Context, SourceLocation atTryLoc, Stmt *atTryStmt, Stmt **CatchStmts, unsigned NumCatchStmts, Stmt *atFinallyStmt)
Definition: StmtObjC.cpp:46
Stmt * VisitStmt(Stmt *S)
Attr - This represents one attribute.
Definition: Attr.h:45
QualType VisitTypeOfType(const TypeOfType *T)
A single template declaration.
Definition: TemplateName.h:190
SourceLocation getColonLoc() const
Definition: Expr.h:3160
Expr * VisitStmtExpr(StmtExpr *E)
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:5286
bool isMutable() const
isMutable - Determines whether this field is mutable (C++ only).
Definition: Decl.h:2358
TypeSourceInfo * getArgumentTypeInfo() const
Definition: Expr.h:2014
bool isInnerRef() const
Definition: Type.h:2337
unsigned getNumExceptions() const
Definition: Type.h:3331
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
getCXXOperatorName - Get the name of the overloadable C++ operator corresponding to Op...
Structure used to store a statement, the constant value to which it was evaluated (if any)...
Definition: Decl.h:739
const ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.h:2587
SourceLocation getTemplateLoc() const
Definition: DeclTemplate.h:131
inputs_iterator end_inputs()
Definition: Stmt.h:1513
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:632
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:4111