| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 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 |  | 
|  | 16 | #include "clang/AST/ASTContext.h" | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTDiagnostic.h" | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclCXX.h" | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclObjC.h" | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclVisitor.h" | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 21 | #include "clang/AST/StmtVisitor.h" | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 22 | #include "clang/AST/TypeVisitor.h" | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 23 | #include "clang/Basic/FileManager.h" | 
|  | 24 | #include "clang/Basic/SourceManager.h" | 
|  | 25 | #include "llvm/Support/MemoryBuffer.h" | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 26 | #include <deque> | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 27 |  | 
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 28 | namespace clang { | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 29 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, QualType>, | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 30 | public DeclVisitor<ASTNodeImporter, Decl *>, | 
|  | 31 | public StmtVisitor<ASTNodeImporter, Stmt *> { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 32 | ASTImporter &Importer; | 
|  | 33 |  | 
|  | 34 | public: | 
|  | 35 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) { } | 
|  | 36 |  | 
|  | 37 | using TypeVisitor<ASTNodeImporter, QualType>::Visit; | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 38 | using DeclVisitor<ASTNodeImporter, Decl *>::Visit; | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 39 | using StmtVisitor<ASTNodeImporter, Stmt *>::Visit; | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 40 |  | 
|  | 41 | // Importing types | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 42 | QualType VisitType(const Type *T); | 
|  | 43 | QualType VisitBuiltinType(const BuiltinType *T); | 
|  | 44 | QualType VisitComplexType(const ComplexType *T); | 
|  | 45 | QualType VisitPointerType(const PointerType *T); | 
|  | 46 | QualType VisitBlockPointerType(const BlockPointerType *T); | 
|  | 47 | QualType VisitLValueReferenceType(const LValueReferenceType *T); | 
|  | 48 | QualType VisitRValueReferenceType(const RValueReferenceType *T); | 
|  | 49 | QualType VisitMemberPointerType(const MemberPointerType *T); | 
|  | 50 | QualType VisitConstantArrayType(const ConstantArrayType *T); | 
|  | 51 | QualType VisitIncompleteArrayType(const IncompleteArrayType *T); | 
|  | 52 | QualType VisitVariableArrayType(const VariableArrayType *T); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 53 | // FIXME: DependentSizedArrayType | 
|  | 54 | // FIXME: DependentSizedExtVectorType | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 55 | QualType VisitVectorType(const VectorType *T); | 
|  | 56 | QualType VisitExtVectorType(const ExtVectorType *T); | 
|  | 57 | QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T); | 
|  | 58 | QualType VisitFunctionProtoType(const FunctionProtoType *T); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 59 | // FIXME: UnresolvedUsingType | 
| Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 60 | QualType VisitParenType(const ParenType *T); | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 61 | QualType VisitTypedefType(const TypedefType *T); | 
|  | 62 | QualType VisitTypeOfExprType(const TypeOfExprType *T); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 63 | // FIXME: DependentTypeOfExprType | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 64 | QualType VisitTypeOfType(const TypeOfType *T); | 
|  | 65 | QualType VisitDecltypeType(const DecltypeType *T); | 
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 66 | QualType VisitUnaryTransformType(const UnaryTransformType *T); | 
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 67 | QualType VisitAutoType(const AutoType *T); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 68 | // FIXME: DependentDecltypeType | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 69 | QualType VisitRecordType(const RecordType *T); | 
|  | 70 | QualType VisitEnumType(const EnumType *T); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 71 | // FIXME: TemplateTypeParmType | 
|  | 72 | // FIXME: SubstTemplateTypeParmType | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 73 | QualType VisitTemplateSpecializationType(const TemplateSpecializationType *T); | 
|  | 74 | QualType VisitElaboratedType(const ElaboratedType *T); | 
| Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 75 | // FIXME: DependentNameType | 
| John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 76 | // FIXME: DependentTemplateSpecializationType | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 77 | QualType VisitObjCInterfaceType(const ObjCInterfaceType *T); | 
|  | 78 | QualType VisitObjCObjectType(const ObjCObjectType *T); | 
|  | 79 | QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 80 |  | 
|  | 81 | // Importing declarations | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 82 | bool ImportDeclParts(NamedDecl *D, DeclContext *&DC, | 
|  | 83 | DeclContext *&LexicalDC, DeclarationName &Name, | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 84 | SourceLocation &Loc); | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 85 | void ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = 0); | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 86 | void ImportDeclarationNameLoc(const DeclarationNameInfo &From, | 
|  | 87 | DeclarationNameInfo& To); | 
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 88 | void ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 89 | bool ImportDefinition(RecordDecl *From, RecordDecl *To, | 
|  | 90 | bool ForceImport = false); | 
|  | 91 | bool ImportDefinition(EnumDecl *From, EnumDecl *To, | 
|  | 92 | bool ForceImport = false); | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 93 | TemplateParameterList *ImportTemplateParameterList( | 
|  | 94 | TemplateParameterList *Params); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 95 | TemplateArgument ImportTemplateArgument(const TemplateArgument &From); | 
|  | 96 | bool ImportTemplateArguments(const TemplateArgument *FromArgs, | 
|  | 97 | unsigned NumFromArgs, | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 98 | SmallVectorImpl<TemplateArgument> &ToArgs); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 99 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 100 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 101 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); | 
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 102 | Decl *VisitDecl(Decl *D); | 
| Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 103 | Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D); | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 104 | Decl *VisitNamespaceDecl(NamespaceDecl *D); | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 105 | Decl *VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 106 | Decl *VisitTypedefDecl(TypedefDecl *D); | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 107 | Decl *VisitTypeAliasDecl(TypeAliasDecl *D); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 108 | Decl *VisitEnumDecl(EnumDecl *D); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 109 | Decl *VisitRecordDecl(RecordDecl *D); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 110 | Decl *VisitEnumConstantDecl(EnumConstantDecl *D); | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 111 | Decl *VisitFunctionDecl(FunctionDecl *D); | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 112 | Decl *VisitCXXMethodDecl(CXXMethodDecl *D); | 
|  | 113 | Decl *VisitCXXConstructorDecl(CXXConstructorDecl *D); | 
|  | 114 | Decl *VisitCXXDestructorDecl(CXXDestructorDecl *D); | 
|  | 115 | Decl *VisitCXXConversionDecl(CXXConversionDecl *D); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 116 | Decl *VisitFieldDecl(FieldDecl *D); | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 117 | Decl *VisitIndirectFieldDecl(IndirectFieldDecl *D); | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 118 | Decl *VisitObjCIvarDecl(ObjCIvarDecl *D); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 119 | Decl *VisitVarDecl(VarDecl *D); | 
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 120 | Decl *VisitImplicitParamDecl(ImplicitParamDecl *D); | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 121 | Decl *VisitParmVarDecl(ParmVarDecl *D); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 122 | Decl *VisitObjCMethodDecl(ObjCMethodDecl *D); | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 123 | Decl *VisitObjCCategoryDecl(ObjCCategoryDecl *D); | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 124 | Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D); | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 125 | Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); | 
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 126 | Decl *VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 127 | Decl *VisitObjCImplementationDecl(ObjCImplementationDecl *D); | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 128 | Decl *VisitObjCPropertyDecl(ObjCPropertyDecl *D); | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 129 | Decl *VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); | 
| Douglas Gregor | 8661a72 | 2010-02-18 02:12:22 +0000 | [diff] [blame] | 130 | Decl *VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D); | 
| Douglas Gregor | 06537af | 2010-02-18 02:04:09 +0000 | [diff] [blame] | 131 | Decl *VisitObjCClassDecl(ObjCClassDecl *D); | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 132 | Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); | 
|  | 133 | Decl *VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); | 
|  | 134 | Decl *VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); | 
|  | 135 | Decl *VisitClassTemplateDecl(ClassTemplateDecl *D); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 136 | Decl *VisitClassTemplateSpecializationDecl( | 
|  | 137 | ClassTemplateSpecializationDecl *D); | 
| Douglas Gregor | 06537af | 2010-02-18 02:04:09 +0000 | [diff] [blame] | 138 |  | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 139 | // Importing statements | 
|  | 140 | Stmt *VisitStmt(Stmt *S); | 
|  | 141 |  | 
|  | 142 | // Importing expressions | 
|  | 143 | Expr *VisitExpr(Expr *E); | 
| Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 144 | Expr *VisitDeclRefExpr(DeclRefExpr *E); | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 145 | Expr *VisitIntegerLiteral(IntegerLiteral *E); | 
| Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 146 | Expr *VisitCharacterLiteral(CharacterLiteral *E); | 
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 147 | Expr *VisitParenExpr(ParenExpr *E); | 
|  | 148 | Expr *VisitUnaryOperator(UnaryOperator *E); | 
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 149 | Expr *VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); | 
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 150 | Expr *VisitBinaryOperator(BinaryOperator *E); | 
|  | 151 | Expr *VisitCompoundAssignOperator(CompoundAssignOperator *E); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 152 | Expr *VisitImplicitCastExpr(ImplicitCastExpr *E); | 
| Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 153 | Expr *VisitCStyleCastExpr(CStyleCastExpr *E); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 154 | }; | 
|  | 155 | } | 
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 156 | using namespace clang; | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 157 |  | 
|  | 158 | //---------------------------------------------------------------------------- | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 159 | // Structural Equivalence | 
|  | 160 | //---------------------------------------------------------------------------- | 
|  | 161 |  | 
|  | 162 | namespace { | 
|  | 163 | struct StructuralEquivalenceContext { | 
|  | 164 | /// \brief AST contexts for which we are checking structural equivalence. | 
|  | 165 | ASTContext &C1, &C2; | 
|  | 166 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 167 | /// \brief The set of "tentative" equivalences between two canonical | 
|  | 168 | /// declarations, mapping from a declaration in the first context to the | 
|  | 169 | /// declaration in the second context that we believe to be equivalent. | 
|  | 170 | llvm::DenseMap<Decl *, Decl *> TentativeEquivalences; | 
|  | 171 |  | 
|  | 172 | /// \brief Queue of declarations in the first context whose equivalence | 
|  | 173 | /// with a declaration in the second context still needs to be verified. | 
|  | 174 | std::deque<Decl *> DeclsToCheck; | 
|  | 175 |  | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 176 | /// \brief Declaration (from, to) pairs that are known not to be equivalent | 
|  | 177 | /// (which we have already complained about). | 
|  | 178 | llvm::DenseSet<std::pair<Decl *, Decl *> > &NonEquivalentDecls; | 
|  | 179 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 180 | /// \brief Whether we're being strict about the spelling of types when | 
|  | 181 | /// unifying two types. | 
|  | 182 | bool StrictTypeSpelling; | 
|  | 183 |  | 
|  | 184 | StructuralEquivalenceContext(ASTContext &C1, ASTContext &C2, | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 185 | llvm::DenseSet<std::pair<Decl *, Decl *> > &NonEquivalentDecls, | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 186 | bool StrictTypeSpelling = false) | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 187 | : C1(C1), C2(C2), NonEquivalentDecls(NonEquivalentDecls), | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 188 | StrictTypeSpelling(StrictTypeSpelling) { } | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 189 |  | 
|  | 190 | /// \brief Determine whether the two declarations are structurally | 
|  | 191 | /// equivalent. | 
|  | 192 | bool IsStructurallyEquivalent(Decl *D1, Decl *D2); | 
|  | 193 |  | 
|  | 194 | /// \brief Determine whether the two types are structurally equivalent. | 
|  | 195 | bool IsStructurallyEquivalent(QualType T1, QualType T2); | 
|  | 196 |  | 
|  | 197 | private: | 
|  | 198 | /// \brief Finish checking all of the structural equivalences. | 
|  | 199 | /// | 
|  | 200 | /// \returns true if an error occurred, false otherwise. | 
|  | 201 | bool Finish(); | 
|  | 202 |  | 
|  | 203 | public: | 
|  | 204 | DiagnosticBuilder Diag1(SourceLocation Loc, unsigned DiagID) { | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 205 | return C1.getDiagnostics().Report(Loc, DiagID); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 206 | } | 
|  | 207 |  | 
|  | 208 | DiagnosticBuilder Diag2(SourceLocation Loc, unsigned DiagID) { | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 209 | return C2.getDiagnostics().Report(Loc, DiagID); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 210 | } | 
|  | 211 | }; | 
|  | 212 | } | 
|  | 213 |  | 
|  | 214 | static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, | 
|  | 215 | QualType T1, QualType T2); | 
|  | 216 | static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, | 
|  | 217 | Decl *D1, Decl *D2); | 
|  | 218 |  | 
|  | 219 | /// \brief Determine if two APInts have the same value, after zero-extending | 
|  | 220 | /// one of them (if needed!) to ensure that the bit-widths match. | 
|  | 221 | static bool IsSameValue(const llvm::APInt &I1, const llvm::APInt &I2) { | 
|  | 222 | if (I1.getBitWidth() == I2.getBitWidth()) | 
|  | 223 | return I1 == I2; | 
|  | 224 |  | 
|  | 225 | if (I1.getBitWidth() > I2.getBitWidth()) | 
| Jay Foad | 6d4db0c | 2010-12-07 08:25:34 +0000 | [diff] [blame] | 226 | return I1 == I2.zext(I1.getBitWidth()); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 227 |  | 
| Jay Foad | 6d4db0c | 2010-12-07 08:25:34 +0000 | [diff] [blame] | 228 | return I1.zext(I2.getBitWidth()) == I2; | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 229 | } | 
|  | 230 |  | 
|  | 231 | /// \brief Determine if two APSInts have the same value, zero- or sign-extending | 
|  | 232 | /// as needed. | 
|  | 233 | static bool IsSameValue(const llvm::APSInt &I1, const llvm::APSInt &I2) { | 
|  | 234 | if (I1.getBitWidth() == I2.getBitWidth() && I1.isSigned() == I2.isSigned()) | 
|  | 235 | return I1 == I2; | 
|  | 236 |  | 
|  | 237 | // Check for a bit-width mismatch. | 
|  | 238 | if (I1.getBitWidth() > I2.getBitWidth()) | 
| Jay Foad | 6d4db0c | 2010-12-07 08:25:34 +0000 | [diff] [blame] | 239 | return IsSameValue(I1, I2.extend(I1.getBitWidth())); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 240 | else if (I2.getBitWidth() > I1.getBitWidth()) | 
| Jay Foad | 6d4db0c | 2010-12-07 08:25:34 +0000 | [diff] [blame] | 241 | return IsSameValue(I1.extend(I2.getBitWidth()), I2); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 242 |  | 
|  | 243 | // We have a signedness mismatch. Turn the signed value into an unsigned | 
|  | 244 | // value. | 
|  | 245 | if (I1.isSigned()) { | 
|  | 246 | if (I1.isNegative()) | 
|  | 247 | return false; | 
|  | 248 |  | 
|  | 249 | return llvm::APSInt(I1, true) == I2; | 
|  | 250 | } | 
|  | 251 |  | 
|  | 252 | if (I2.isNegative()) | 
|  | 253 | return false; | 
|  | 254 |  | 
|  | 255 | return I1 == llvm::APSInt(I2, true); | 
|  | 256 | } | 
|  | 257 |  | 
|  | 258 | /// \brief Determine structural equivalence of two expressions. | 
|  | 259 | static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, | 
|  | 260 | Expr *E1, Expr *E2) { | 
|  | 261 | if (!E1 || !E2) | 
|  | 262 | return E1 == E2; | 
|  | 263 |  | 
|  | 264 | // FIXME: Actually perform a structural comparison! | 
|  | 265 | return true; | 
|  | 266 | } | 
|  | 267 |  | 
|  | 268 | /// \brief Determine whether two identifiers are equivalent. | 
|  | 269 | static bool IsStructurallyEquivalent(const IdentifierInfo *Name1, | 
|  | 270 | const IdentifierInfo *Name2) { | 
|  | 271 | if (!Name1 || !Name2) | 
|  | 272 | return Name1 == Name2; | 
|  | 273 |  | 
|  | 274 | return Name1->getName() == Name2->getName(); | 
|  | 275 | } | 
|  | 276 |  | 
|  | 277 | /// \brief Determine whether two nested-name-specifiers are equivalent. | 
|  | 278 | static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, | 
|  | 279 | NestedNameSpecifier *NNS1, | 
|  | 280 | NestedNameSpecifier *NNS2) { | 
|  | 281 | // FIXME: Implement! | 
|  | 282 | return true; | 
|  | 283 | } | 
|  | 284 |  | 
|  | 285 | /// \brief Determine whether two template arguments are equivalent. | 
|  | 286 | static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, | 
|  | 287 | const TemplateArgument &Arg1, | 
|  | 288 | const TemplateArgument &Arg2) { | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 289 | if (Arg1.getKind() != Arg2.getKind()) | 
|  | 290 | return false; | 
|  | 291 |  | 
|  | 292 | switch (Arg1.getKind()) { | 
|  | 293 | case TemplateArgument::Null: | 
|  | 294 | return true; | 
|  | 295 |  | 
|  | 296 | case TemplateArgument::Type: | 
|  | 297 | return Context.IsStructurallyEquivalent(Arg1.getAsType(), Arg2.getAsType()); | 
|  | 298 |  | 
|  | 299 | case TemplateArgument::Integral: | 
|  | 300 | if (!Context.IsStructurallyEquivalent(Arg1.getIntegralType(), | 
|  | 301 | Arg2.getIntegralType())) | 
|  | 302 | return false; | 
|  | 303 |  | 
|  | 304 | return IsSameValue(*Arg1.getAsIntegral(), *Arg2.getAsIntegral()); | 
|  | 305 |  | 
|  | 306 | case TemplateArgument::Declaration: | 
|  | 307 | return Context.IsStructurallyEquivalent(Arg1.getAsDecl(), Arg2.getAsDecl()); | 
|  | 308 |  | 
|  | 309 | case TemplateArgument::Template: | 
|  | 310 | return IsStructurallyEquivalent(Context, | 
|  | 311 | Arg1.getAsTemplate(), | 
|  | 312 | Arg2.getAsTemplate()); | 
| Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 313 |  | 
|  | 314 | case TemplateArgument::TemplateExpansion: | 
|  | 315 | return IsStructurallyEquivalent(Context, | 
|  | 316 | Arg1.getAsTemplateOrTemplatePattern(), | 
|  | 317 | Arg2.getAsTemplateOrTemplatePattern()); | 
|  | 318 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 319 | case TemplateArgument::Expression: | 
|  | 320 | return IsStructurallyEquivalent(Context, | 
|  | 321 | Arg1.getAsExpr(), Arg2.getAsExpr()); | 
|  | 322 |  | 
|  | 323 | case TemplateArgument::Pack: | 
|  | 324 | if (Arg1.pack_size() != Arg2.pack_size()) | 
|  | 325 | return false; | 
|  | 326 |  | 
|  | 327 | for (unsigned I = 0, N = Arg1.pack_size(); I != N; ++I) | 
|  | 328 | if (!IsStructurallyEquivalent(Context, | 
|  | 329 | Arg1.pack_begin()[I], | 
|  | 330 | Arg2.pack_begin()[I])) | 
|  | 331 | return false; | 
|  | 332 |  | 
|  | 333 | return true; | 
|  | 334 | } | 
|  | 335 |  | 
|  | 336 | llvm_unreachable("Invalid template argument kind"); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 337 | return true; | 
|  | 338 | } | 
|  | 339 |  | 
|  | 340 | /// \brief Determine structural equivalence for the common part of array | 
|  | 341 | /// types. | 
|  | 342 | static bool IsArrayStructurallyEquivalent(StructuralEquivalenceContext &Context, | 
|  | 343 | const ArrayType *Array1, | 
|  | 344 | const ArrayType *Array2) { | 
|  | 345 | if (!IsStructurallyEquivalent(Context, | 
|  | 346 | Array1->getElementType(), | 
|  | 347 | Array2->getElementType())) | 
|  | 348 | return false; | 
|  | 349 | if (Array1->getSizeModifier() != Array2->getSizeModifier()) | 
|  | 350 | return false; | 
|  | 351 | if (Array1->getIndexTypeQualifiers() != Array2->getIndexTypeQualifiers()) | 
|  | 352 | return false; | 
|  | 353 |  | 
|  | 354 | return true; | 
|  | 355 | } | 
|  | 356 |  | 
|  | 357 | /// \brief Determine structural equivalence of two types. | 
|  | 358 | static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, | 
|  | 359 | QualType T1, QualType T2) { | 
|  | 360 | if (T1.isNull() || T2.isNull()) | 
|  | 361 | return T1.isNull() && T2.isNull(); | 
|  | 362 |  | 
|  | 363 | if (!Context.StrictTypeSpelling) { | 
|  | 364 | // We aren't being strict about token-to-token equivalence of types, | 
|  | 365 | // so map down to the canonical type. | 
|  | 366 | T1 = Context.C1.getCanonicalType(T1); | 
|  | 367 | T2 = Context.C2.getCanonicalType(T2); | 
|  | 368 | } | 
|  | 369 |  | 
|  | 370 | if (T1.getQualifiers() != T2.getQualifiers()) | 
|  | 371 | return false; | 
|  | 372 |  | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 373 | Type::TypeClass TC = T1->getTypeClass(); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 374 |  | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 375 | if (T1->getTypeClass() != T2->getTypeClass()) { | 
|  | 376 | // Compare function types with prototypes vs. without prototypes as if | 
|  | 377 | // both did not have prototypes. | 
|  | 378 | if (T1->getTypeClass() == Type::FunctionProto && | 
|  | 379 | T2->getTypeClass() == Type::FunctionNoProto) | 
|  | 380 | TC = Type::FunctionNoProto; | 
|  | 381 | else if (T1->getTypeClass() == Type::FunctionNoProto && | 
|  | 382 | T2->getTypeClass() == Type::FunctionProto) | 
|  | 383 | TC = Type::FunctionNoProto; | 
|  | 384 | else | 
|  | 385 | return false; | 
|  | 386 | } | 
|  | 387 |  | 
|  | 388 | switch (TC) { | 
|  | 389 | case Type::Builtin: | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 390 | // FIXME: Deal with Char_S/Char_U. | 
|  | 391 | if (cast<BuiltinType>(T1)->getKind() != cast<BuiltinType>(T2)->getKind()) | 
|  | 392 | return false; | 
|  | 393 | break; | 
|  | 394 |  | 
|  | 395 | case Type::Complex: | 
|  | 396 | if (!IsStructurallyEquivalent(Context, | 
|  | 397 | cast<ComplexType>(T1)->getElementType(), | 
|  | 398 | cast<ComplexType>(T2)->getElementType())) | 
|  | 399 | return false; | 
|  | 400 | break; | 
|  | 401 |  | 
|  | 402 | case Type::Pointer: | 
|  | 403 | if (!IsStructurallyEquivalent(Context, | 
|  | 404 | cast<PointerType>(T1)->getPointeeType(), | 
|  | 405 | cast<PointerType>(T2)->getPointeeType())) | 
|  | 406 | return false; | 
|  | 407 | break; | 
|  | 408 |  | 
|  | 409 | case Type::BlockPointer: | 
|  | 410 | if (!IsStructurallyEquivalent(Context, | 
|  | 411 | cast<BlockPointerType>(T1)->getPointeeType(), | 
|  | 412 | cast<BlockPointerType>(T2)->getPointeeType())) | 
|  | 413 | return false; | 
|  | 414 | break; | 
|  | 415 |  | 
|  | 416 | case Type::LValueReference: | 
|  | 417 | case Type::RValueReference: { | 
|  | 418 | const ReferenceType *Ref1 = cast<ReferenceType>(T1); | 
|  | 419 | const ReferenceType *Ref2 = cast<ReferenceType>(T2); | 
|  | 420 | if (Ref1->isSpelledAsLValue() != Ref2->isSpelledAsLValue()) | 
|  | 421 | return false; | 
|  | 422 | if (Ref1->isInnerRef() != Ref2->isInnerRef()) | 
|  | 423 | return false; | 
|  | 424 | if (!IsStructurallyEquivalent(Context, | 
|  | 425 | Ref1->getPointeeTypeAsWritten(), | 
|  | 426 | Ref2->getPointeeTypeAsWritten())) | 
|  | 427 | return false; | 
|  | 428 | break; | 
|  | 429 | } | 
|  | 430 |  | 
|  | 431 | case Type::MemberPointer: { | 
|  | 432 | const MemberPointerType *MemPtr1 = cast<MemberPointerType>(T1); | 
|  | 433 | const MemberPointerType *MemPtr2 = cast<MemberPointerType>(T2); | 
|  | 434 | if (!IsStructurallyEquivalent(Context, | 
|  | 435 | MemPtr1->getPointeeType(), | 
|  | 436 | MemPtr2->getPointeeType())) | 
|  | 437 | return false; | 
|  | 438 | if (!IsStructurallyEquivalent(Context, | 
|  | 439 | QualType(MemPtr1->getClass(), 0), | 
|  | 440 | QualType(MemPtr2->getClass(), 0))) | 
|  | 441 | return false; | 
|  | 442 | break; | 
|  | 443 | } | 
|  | 444 |  | 
|  | 445 | case Type::ConstantArray: { | 
|  | 446 | const ConstantArrayType *Array1 = cast<ConstantArrayType>(T1); | 
|  | 447 | const ConstantArrayType *Array2 = cast<ConstantArrayType>(T2); | 
|  | 448 | if (!IsSameValue(Array1->getSize(), Array2->getSize())) | 
|  | 449 | return false; | 
|  | 450 |  | 
|  | 451 | if (!IsArrayStructurallyEquivalent(Context, Array1, Array2)) | 
|  | 452 | return false; | 
|  | 453 | break; | 
|  | 454 | } | 
|  | 455 |  | 
|  | 456 | case Type::IncompleteArray: | 
|  | 457 | if (!IsArrayStructurallyEquivalent(Context, | 
|  | 458 | cast<ArrayType>(T1), | 
|  | 459 | cast<ArrayType>(T2))) | 
|  | 460 | return false; | 
|  | 461 | break; | 
|  | 462 |  | 
|  | 463 | case Type::VariableArray: { | 
|  | 464 | const VariableArrayType *Array1 = cast<VariableArrayType>(T1); | 
|  | 465 | const VariableArrayType *Array2 = cast<VariableArrayType>(T2); | 
|  | 466 | if (!IsStructurallyEquivalent(Context, | 
|  | 467 | Array1->getSizeExpr(), Array2->getSizeExpr())) | 
|  | 468 | return false; | 
|  | 469 |  | 
|  | 470 | if (!IsArrayStructurallyEquivalent(Context, Array1, Array2)) | 
|  | 471 | return false; | 
|  | 472 |  | 
|  | 473 | break; | 
|  | 474 | } | 
|  | 475 |  | 
|  | 476 | case Type::DependentSizedArray: { | 
|  | 477 | const DependentSizedArrayType *Array1 = cast<DependentSizedArrayType>(T1); | 
|  | 478 | const DependentSizedArrayType *Array2 = cast<DependentSizedArrayType>(T2); | 
|  | 479 | if (!IsStructurallyEquivalent(Context, | 
|  | 480 | Array1->getSizeExpr(), Array2->getSizeExpr())) | 
|  | 481 | return false; | 
|  | 482 |  | 
|  | 483 | if (!IsArrayStructurallyEquivalent(Context, Array1, Array2)) | 
|  | 484 | return false; | 
|  | 485 |  | 
|  | 486 | break; | 
|  | 487 | } | 
|  | 488 |  | 
|  | 489 | case Type::DependentSizedExtVector: { | 
|  | 490 | const DependentSizedExtVectorType *Vec1 | 
|  | 491 | = cast<DependentSizedExtVectorType>(T1); | 
|  | 492 | const DependentSizedExtVectorType *Vec2 | 
|  | 493 | = cast<DependentSizedExtVectorType>(T2); | 
|  | 494 | if (!IsStructurallyEquivalent(Context, | 
|  | 495 | Vec1->getSizeExpr(), Vec2->getSizeExpr())) | 
|  | 496 | return false; | 
|  | 497 | if (!IsStructurallyEquivalent(Context, | 
|  | 498 | Vec1->getElementType(), | 
|  | 499 | Vec2->getElementType())) | 
|  | 500 | return false; | 
|  | 501 | break; | 
|  | 502 | } | 
|  | 503 |  | 
|  | 504 | case Type::Vector: | 
|  | 505 | case Type::ExtVector: { | 
|  | 506 | const VectorType *Vec1 = cast<VectorType>(T1); | 
|  | 507 | const VectorType *Vec2 = cast<VectorType>(T2); | 
|  | 508 | if (!IsStructurallyEquivalent(Context, | 
|  | 509 | Vec1->getElementType(), | 
|  | 510 | Vec2->getElementType())) | 
|  | 511 | return false; | 
|  | 512 | if (Vec1->getNumElements() != Vec2->getNumElements()) | 
|  | 513 | return false; | 
| Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 514 | if (Vec1->getVectorKind() != Vec2->getVectorKind()) | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 515 | return false; | 
| Douglas Gregor | 01cc437 | 2010-02-19 01:36:36 +0000 | [diff] [blame] | 516 | break; | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 517 | } | 
|  | 518 |  | 
|  | 519 | case Type::FunctionProto: { | 
|  | 520 | const FunctionProtoType *Proto1 = cast<FunctionProtoType>(T1); | 
|  | 521 | const FunctionProtoType *Proto2 = cast<FunctionProtoType>(T2); | 
|  | 522 | if (Proto1->getNumArgs() != Proto2->getNumArgs()) | 
|  | 523 | return false; | 
|  | 524 | for (unsigned I = 0, N = Proto1->getNumArgs(); I != N; ++I) { | 
|  | 525 | if (!IsStructurallyEquivalent(Context, | 
|  | 526 | Proto1->getArgType(I), | 
|  | 527 | Proto2->getArgType(I))) | 
|  | 528 | return false; | 
|  | 529 | } | 
|  | 530 | if (Proto1->isVariadic() != Proto2->isVariadic()) | 
|  | 531 | return false; | 
| Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 532 | if (Proto1->getExceptionSpecType() != Proto2->getExceptionSpecType()) | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 533 | return false; | 
| Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 534 | if (Proto1->getExceptionSpecType() == EST_Dynamic) { | 
|  | 535 | if (Proto1->getNumExceptions() != Proto2->getNumExceptions()) | 
|  | 536 | return false; | 
|  | 537 | for (unsigned I = 0, N = Proto1->getNumExceptions(); I != N; ++I) { | 
|  | 538 | if (!IsStructurallyEquivalent(Context, | 
|  | 539 | Proto1->getExceptionType(I), | 
|  | 540 | Proto2->getExceptionType(I))) | 
|  | 541 | return false; | 
|  | 542 | } | 
|  | 543 | } else if (Proto1->getExceptionSpecType() == EST_ComputedNoexcept) { | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 544 | if (!IsStructurallyEquivalent(Context, | 
| Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 545 | Proto1->getNoexceptExpr(), | 
|  | 546 | Proto2->getNoexceptExpr())) | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 547 | return false; | 
|  | 548 | } | 
|  | 549 | if (Proto1->getTypeQuals() != Proto2->getTypeQuals()) | 
|  | 550 | return false; | 
|  | 551 |  | 
|  | 552 | // Fall through to check the bits common with FunctionNoProtoType. | 
|  | 553 | } | 
|  | 554 |  | 
|  | 555 | case Type::FunctionNoProto: { | 
|  | 556 | const FunctionType *Function1 = cast<FunctionType>(T1); | 
|  | 557 | const FunctionType *Function2 = cast<FunctionType>(T2); | 
|  | 558 | if (!IsStructurallyEquivalent(Context, | 
|  | 559 | Function1->getResultType(), | 
|  | 560 | Function2->getResultType())) | 
|  | 561 | return false; | 
| Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 562 | if (Function1->getExtInfo() != Function2->getExtInfo()) | 
|  | 563 | return false; | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 564 | break; | 
|  | 565 | } | 
|  | 566 |  | 
|  | 567 | case Type::UnresolvedUsing: | 
|  | 568 | if (!IsStructurallyEquivalent(Context, | 
|  | 569 | cast<UnresolvedUsingType>(T1)->getDecl(), | 
|  | 570 | cast<UnresolvedUsingType>(T2)->getDecl())) | 
|  | 571 | return false; | 
|  | 572 |  | 
|  | 573 | break; | 
| John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 574 |  | 
|  | 575 | case Type::Attributed: | 
|  | 576 | if (!IsStructurallyEquivalent(Context, | 
|  | 577 | cast<AttributedType>(T1)->getModifiedType(), | 
|  | 578 | cast<AttributedType>(T2)->getModifiedType())) | 
|  | 579 | return false; | 
|  | 580 | if (!IsStructurallyEquivalent(Context, | 
|  | 581 | cast<AttributedType>(T1)->getEquivalentType(), | 
|  | 582 | cast<AttributedType>(T2)->getEquivalentType())) | 
|  | 583 | return false; | 
|  | 584 | break; | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 585 |  | 
| Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 586 | case Type::Paren: | 
|  | 587 | if (!IsStructurallyEquivalent(Context, | 
|  | 588 | cast<ParenType>(T1)->getInnerType(), | 
|  | 589 | cast<ParenType>(T2)->getInnerType())) | 
|  | 590 | return false; | 
|  | 591 | break; | 
|  | 592 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 593 | case Type::Typedef: | 
|  | 594 | if (!IsStructurallyEquivalent(Context, | 
|  | 595 | cast<TypedefType>(T1)->getDecl(), | 
|  | 596 | cast<TypedefType>(T2)->getDecl())) | 
|  | 597 | return false; | 
|  | 598 | break; | 
|  | 599 |  | 
|  | 600 | case Type::TypeOfExpr: | 
|  | 601 | if (!IsStructurallyEquivalent(Context, | 
|  | 602 | cast<TypeOfExprType>(T1)->getUnderlyingExpr(), | 
|  | 603 | cast<TypeOfExprType>(T2)->getUnderlyingExpr())) | 
|  | 604 | return false; | 
|  | 605 | break; | 
|  | 606 |  | 
|  | 607 | case Type::TypeOf: | 
|  | 608 | if (!IsStructurallyEquivalent(Context, | 
|  | 609 | cast<TypeOfType>(T1)->getUnderlyingType(), | 
|  | 610 | cast<TypeOfType>(T2)->getUnderlyingType())) | 
|  | 611 | return false; | 
|  | 612 | break; | 
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 613 |  | 
|  | 614 | case Type::UnaryTransform: | 
|  | 615 | if (!IsStructurallyEquivalent(Context, | 
|  | 616 | cast<UnaryTransformType>(T1)->getUnderlyingType(), | 
|  | 617 | cast<UnaryTransformType>(T1)->getUnderlyingType())) | 
|  | 618 | return false; | 
|  | 619 | break; | 
|  | 620 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 621 | case Type::Decltype: | 
|  | 622 | if (!IsStructurallyEquivalent(Context, | 
|  | 623 | cast<DecltypeType>(T1)->getUnderlyingExpr(), | 
|  | 624 | cast<DecltypeType>(T2)->getUnderlyingExpr())) | 
|  | 625 | return false; | 
|  | 626 | break; | 
|  | 627 |  | 
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 628 | case Type::Auto: | 
|  | 629 | if (!IsStructurallyEquivalent(Context, | 
|  | 630 | cast<AutoType>(T1)->getDeducedType(), | 
|  | 631 | cast<AutoType>(T2)->getDeducedType())) | 
|  | 632 | return false; | 
|  | 633 | break; | 
|  | 634 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 635 | case Type::Record: | 
|  | 636 | case Type::Enum: | 
|  | 637 | if (!IsStructurallyEquivalent(Context, | 
|  | 638 | cast<TagType>(T1)->getDecl(), | 
|  | 639 | cast<TagType>(T2)->getDecl())) | 
|  | 640 | return false; | 
|  | 641 | break; | 
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 642 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 643 | case Type::TemplateTypeParm: { | 
|  | 644 | const TemplateTypeParmType *Parm1 = cast<TemplateTypeParmType>(T1); | 
|  | 645 | const TemplateTypeParmType *Parm2 = cast<TemplateTypeParmType>(T2); | 
|  | 646 | if (Parm1->getDepth() != Parm2->getDepth()) | 
|  | 647 | return false; | 
|  | 648 | if (Parm1->getIndex() != Parm2->getIndex()) | 
|  | 649 | return false; | 
|  | 650 | if (Parm1->isParameterPack() != Parm2->isParameterPack()) | 
|  | 651 | return false; | 
|  | 652 |  | 
|  | 653 | // Names of template type parameters are never significant. | 
|  | 654 | break; | 
|  | 655 | } | 
|  | 656 |  | 
|  | 657 | case Type::SubstTemplateTypeParm: { | 
|  | 658 | const SubstTemplateTypeParmType *Subst1 | 
|  | 659 | = cast<SubstTemplateTypeParmType>(T1); | 
|  | 660 | const SubstTemplateTypeParmType *Subst2 | 
|  | 661 | = cast<SubstTemplateTypeParmType>(T2); | 
|  | 662 | if (!IsStructurallyEquivalent(Context, | 
|  | 663 | QualType(Subst1->getReplacedParameter(), 0), | 
|  | 664 | QualType(Subst2->getReplacedParameter(), 0))) | 
|  | 665 | return false; | 
|  | 666 | if (!IsStructurallyEquivalent(Context, | 
|  | 667 | Subst1->getReplacementType(), | 
|  | 668 | Subst2->getReplacementType())) | 
|  | 669 | return false; | 
|  | 670 | break; | 
|  | 671 | } | 
|  | 672 |  | 
| Douglas Gregor | fb322d8 | 2011-01-14 05:11:40 +0000 | [diff] [blame] | 673 | case Type::SubstTemplateTypeParmPack: { | 
|  | 674 | const SubstTemplateTypeParmPackType *Subst1 | 
|  | 675 | = cast<SubstTemplateTypeParmPackType>(T1); | 
|  | 676 | const SubstTemplateTypeParmPackType *Subst2 | 
|  | 677 | = cast<SubstTemplateTypeParmPackType>(T2); | 
|  | 678 | if (!IsStructurallyEquivalent(Context, | 
|  | 679 | QualType(Subst1->getReplacedParameter(), 0), | 
|  | 680 | QualType(Subst2->getReplacedParameter(), 0))) | 
|  | 681 | return false; | 
|  | 682 | if (!IsStructurallyEquivalent(Context, | 
|  | 683 | Subst1->getArgumentPack(), | 
|  | 684 | Subst2->getArgumentPack())) | 
|  | 685 | return false; | 
|  | 686 | break; | 
|  | 687 | } | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 688 | case Type::TemplateSpecialization: { | 
|  | 689 | const TemplateSpecializationType *Spec1 | 
|  | 690 | = cast<TemplateSpecializationType>(T1); | 
|  | 691 | const TemplateSpecializationType *Spec2 | 
|  | 692 | = cast<TemplateSpecializationType>(T2); | 
|  | 693 | if (!IsStructurallyEquivalent(Context, | 
|  | 694 | Spec1->getTemplateName(), | 
|  | 695 | Spec2->getTemplateName())) | 
|  | 696 | return false; | 
|  | 697 | if (Spec1->getNumArgs() != Spec2->getNumArgs()) | 
|  | 698 | return false; | 
|  | 699 | for (unsigned I = 0, N = Spec1->getNumArgs(); I != N; ++I) { | 
|  | 700 | if (!IsStructurallyEquivalent(Context, | 
|  | 701 | Spec1->getArg(I), Spec2->getArg(I))) | 
|  | 702 | return false; | 
|  | 703 | } | 
|  | 704 | break; | 
|  | 705 | } | 
|  | 706 |  | 
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 707 | case Type::Elaborated: { | 
|  | 708 | const ElaboratedType *Elab1 = cast<ElaboratedType>(T1); | 
|  | 709 | const ElaboratedType *Elab2 = cast<ElaboratedType>(T2); | 
|  | 710 | // CHECKME: what if a keyword is ETK_None or ETK_typename ? | 
|  | 711 | if (Elab1->getKeyword() != Elab2->getKeyword()) | 
|  | 712 | return false; | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 713 | if (!IsStructurallyEquivalent(Context, | 
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 714 | Elab1->getQualifier(), | 
|  | 715 | Elab2->getQualifier())) | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 716 | return false; | 
|  | 717 | if (!IsStructurallyEquivalent(Context, | 
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 718 | Elab1->getNamedType(), | 
|  | 719 | Elab2->getNamedType())) | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 720 | return false; | 
|  | 721 | break; | 
|  | 722 | } | 
|  | 723 |  | 
| John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 724 | case Type::InjectedClassName: { | 
|  | 725 | const InjectedClassNameType *Inj1 = cast<InjectedClassNameType>(T1); | 
|  | 726 | const InjectedClassNameType *Inj2 = cast<InjectedClassNameType>(T2); | 
|  | 727 | if (!IsStructurallyEquivalent(Context, | 
| John McCall | 2408e32 | 2010-04-27 00:57:59 +0000 | [diff] [blame] | 728 | Inj1->getInjectedSpecializationType(), | 
|  | 729 | Inj2->getInjectedSpecializationType())) | 
| John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 730 | return false; | 
|  | 731 | break; | 
|  | 732 | } | 
|  | 733 |  | 
| Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 734 | case Type::DependentName: { | 
|  | 735 | const DependentNameType *Typename1 = cast<DependentNameType>(T1); | 
|  | 736 | const DependentNameType *Typename2 = cast<DependentNameType>(T2); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 737 | if (!IsStructurallyEquivalent(Context, | 
|  | 738 | Typename1->getQualifier(), | 
|  | 739 | Typename2->getQualifier())) | 
|  | 740 | return false; | 
|  | 741 | if (!IsStructurallyEquivalent(Typename1->getIdentifier(), | 
|  | 742 | Typename2->getIdentifier())) | 
|  | 743 | return false; | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 744 |  | 
|  | 745 | break; | 
|  | 746 | } | 
|  | 747 |  | 
| John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 748 | case Type::DependentTemplateSpecialization: { | 
|  | 749 | const DependentTemplateSpecializationType *Spec1 = | 
|  | 750 | cast<DependentTemplateSpecializationType>(T1); | 
|  | 751 | const DependentTemplateSpecializationType *Spec2 = | 
|  | 752 | cast<DependentTemplateSpecializationType>(T2); | 
|  | 753 | if (!IsStructurallyEquivalent(Context, | 
|  | 754 | Spec1->getQualifier(), | 
|  | 755 | Spec2->getQualifier())) | 
|  | 756 | return false; | 
|  | 757 | if (!IsStructurallyEquivalent(Spec1->getIdentifier(), | 
|  | 758 | Spec2->getIdentifier())) | 
|  | 759 | return false; | 
|  | 760 | if (Spec1->getNumArgs() != Spec2->getNumArgs()) | 
|  | 761 | return false; | 
|  | 762 | for (unsigned I = 0, N = Spec1->getNumArgs(); I != N; ++I) { | 
|  | 763 | if (!IsStructurallyEquivalent(Context, | 
|  | 764 | Spec1->getArg(I), Spec2->getArg(I))) | 
|  | 765 | return false; | 
|  | 766 | } | 
|  | 767 | break; | 
|  | 768 | } | 
| Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 769 |  | 
|  | 770 | case Type::PackExpansion: | 
|  | 771 | if (!IsStructurallyEquivalent(Context, | 
|  | 772 | cast<PackExpansionType>(T1)->getPattern(), | 
|  | 773 | cast<PackExpansionType>(T2)->getPattern())) | 
|  | 774 | return false; | 
|  | 775 | break; | 
|  | 776 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 777 | case Type::ObjCInterface: { | 
|  | 778 | const ObjCInterfaceType *Iface1 = cast<ObjCInterfaceType>(T1); | 
|  | 779 | const ObjCInterfaceType *Iface2 = cast<ObjCInterfaceType>(T2); | 
|  | 780 | if (!IsStructurallyEquivalent(Context, | 
|  | 781 | Iface1->getDecl(), Iface2->getDecl())) | 
|  | 782 | return false; | 
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 783 | break; | 
|  | 784 | } | 
|  | 785 |  | 
|  | 786 | case Type::ObjCObject: { | 
|  | 787 | const ObjCObjectType *Obj1 = cast<ObjCObjectType>(T1); | 
|  | 788 | const ObjCObjectType *Obj2 = cast<ObjCObjectType>(T2); | 
|  | 789 | if (!IsStructurallyEquivalent(Context, | 
|  | 790 | Obj1->getBaseType(), | 
|  | 791 | Obj2->getBaseType())) | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 792 | return false; | 
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 793 | if (Obj1->getNumProtocols() != Obj2->getNumProtocols()) | 
|  | 794 | return false; | 
|  | 795 | for (unsigned I = 0, N = Obj1->getNumProtocols(); I != N; ++I) { | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 796 | if (!IsStructurallyEquivalent(Context, | 
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 797 | Obj1->getProtocol(I), | 
|  | 798 | Obj2->getProtocol(I))) | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 799 | return false; | 
|  | 800 | } | 
|  | 801 | break; | 
|  | 802 | } | 
|  | 803 |  | 
|  | 804 | case Type::ObjCObjectPointer: { | 
|  | 805 | const ObjCObjectPointerType *Ptr1 = cast<ObjCObjectPointerType>(T1); | 
|  | 806 | const ObjCObjectPointerType *Ptr2 = cast<ObjCObjectPointerType>(T2); | 
|  | 807 | if (!IsStructurallyEquivalent(Context, | 
|  | 808 | Ptr1->getPointeeType(), | 
|  | 809 | Ptr2->getPointeeType())) | 
|  | 810 | return false; | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 811 | break; | 
|  | 812 | } | 
| Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 813 |  | 
|  | 814 | case Type::Atomic: { | 
|  | 815 | if (!IsStructurallyEquivalent(Context, | 
|  | 816 | cast<AtomicType>(T1)->getValueType(), | 
|  | 817 | cast<AtomicType>(T2)->getValueType())) | 
|  | 818 | return false; | 
|  | 819 | break; | 
|  | 820 | } | 
|  | 821 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 822 | } // end switch | 
|  | 823 |  | 
|  | 824 | return true; | 
|  | 825 | } | 
|  | 826 |  | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 827 | /// \brief Determine structural equivalence of two fields. | 
|  | 828 | static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, | 
|  | 829 | FieldDecl *Field1, FieldDecl *Field2) { | 
|  | 830 | RecordDecl *Owner2 = cast<RecordDecl>(Field2->getDeclContext()); | 
|  | 831 |  | 
|  | 832 | if (!IsStructurallyEquivalent(Context, | 
|  | 833 | Field1->getType(), Field2->getType())) { | 
|  | 834 | Context.Diag2(Owner2->getLocation(), diag::warn_odr_tag_type_inconsistent) | 
|  | 835 | << Context.C2.getTypeDeclType(Owner2); | 
|  | 836 | Context.Diag2(Field2->getLocation(), diag::note_odr_field) | 
|  | 837 | << Field2->getDeclName() << Field2->getType(); | 
|  | 838 | Context.Diag1(Field1->getLocation(), diag::note_odr_field) | 
|  | 839 | << Field1->getDeclName() << Field1->getType(); | 
|  | 840 | return false; | 
|  | 841 | } | 
|  | 842 |  | 
|  | 843 | if (Field1->isBitField() != Field2->isBitField()) { | 
|  | 844 | Context.Diag2(Owner2->getLocation(), diag::warn_odr_tag_type_inconsistent) | 
|  | 845 | << Context.C2.getTypeDeclType(Owner2); | 
|  | 846 | if (Field1->isBitField()) { | 
|  | 847 | Context.Diag1(Field1->getLocation(), diag::note_odr_bit_field) | 
|  | 848 | << Field1->getDeclName() << Field1->getType() | 
|  | 849 | << Field1->getBitWidthValue(Context.C1); | 
|  | 850 | Context.Diag2(Field2->getLocation(), diag::note_odr_not_bit_field) | 
|  | 851 | << Field2->getDeclName(); | 
|  | 852 | } else { | 
|  | 853 | Context.Diag2(Field2->getLocation(), diag::note_odr_bit_field) | 
|  | 854 | << Field2->getDeclName() << Field2->getType() | 
|  | 855 | << Field2->getBitWidthValue(Context.C2); | 
|  | 856 | Context.Diag1(Field1->getLocation(), diag::note_odr_not_bit_field) | 
|  | 857 | << Field1->getDeclName(); | 
|  | 858 | } | 
|  | 859 | return false; | 
|  | 860 | } | 
|  | 861 |  | 
|  | 862 | if (Field1->isBitField()) { | 
|  | 863 | // Make sure that the bit-fields are the same length. | 
|  | 864 | unsigned Bits1 = Field1->getBitWidthValue(Context.C1); | 
|  | 865 | unsigned Bits2 = Field2->getBitWidthValue(Context.C2); | 
|  | 866 |  | 
|  | 867 | if (Bits1 != Bits2) { | 
|  | 868 | Context.Diag2(Owner2->getLocation(), diag::warn_odr_tag_type_inconsistent) | 
|  | 869 | << Context.C2.getTypeDeclType(Owner2); | 
|  | 870 | Context.Diag2(Field2->getLocation(), diag::note_odr_bit_field) | 
|  | 871 | << Field2->getDeclName() << Field2->getType() << Bits2; | 
|  | 872 | Context.Diag1(Field1->getLocation(), diag::note_odr_bit_field) | 
|  | 873 | << Field1->getDeclName() << Field1->getType() << Bits1; | 
|  | 874 | return false; | 
|  | 875 | } | 
|  | 876 | } | 
|  | 877 |  | 
|  | 878 | return true; | 
|  | 879 | } | 
|  | 880 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 881 | /// \brief Determine structural equivalence of two records. | 
|  | 882 | static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, | 
|  | 883 | RecordDecl *D1, RecordDecl *D2) { | 
|  | 884 | if (D1->isUnion() != D2->isUnion()) { | 
|  | 885 | Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent) | 
|  | 886 | << Context.C2.getTypeDeclType(D2); | 
|  | 887 | Context.Diag1(D1->getLocation(), diag::note_odr_tag_kind_here) | 
|  | 888 | << D1->getDeclName() << (unsigned)D1->getTagKind(); | 
|  | 889 | return false; | 
|  | 890 | } | 
|  | 891 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 892 | // If both declarations are class template specializations, we know | 
|  | 893 | // the ODR applies, so check the template and template arguments. | 
|  | 894 | ClassTemplateSpecializationDecl *Spec1 | 
|  | 895 | = dyn_cast<ClassTemplateSpecializationDecl>(D1); | 
|  | 896 | ClassTemplateSpecializationDecl *Spec2 | 
|  | 897 | = dyn_cast<ClassTemplateSpecializationDecl>(D2); | 
|  | 898 | if (Spec1 && Spec2) { | 
|  | 899 | // Check that the specialized templates are the same. | 
|  | 900 | if (!IsStructurallyEquivalent(Context, Spec1->getSpecializedTemplate(), | 
|  | 901 | Spec2->getSpecializedTemplate())) | 
|  | 902 | return false; | 
|  | 903 |  | 
|  | 904 | // Check that the template arguments are the same. | 
|  | 905 | if (Spec1->getTemplateArgs().size() != Spec2->getTemplateArgs().size()) | 
|  | 906 | return false; | 
|  | 907 |  | 
|  | 908 | for (unsigned I = 0, N = Spec1->getTemplateArgs().size(); I != N; ++I) | 
|  | 909 | if (!IsStructurallyEquivalent(Context, | 
|  | 910 | Spec1->getTemplateArgs().get(I), | 
|  | 911 | Spec2->getTemplateArgs().get(I))) | 
|  | 912 | return false; | 
|  | 913 | } | 
|  | 914 | // If one is a class template specialization and the other is not, these | 
| Chris Lattner | 57540c5 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 915 | // structures are different. | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 916 | else if (Spec1 || Spec2) | 
|  | 917 | return false; | 
|  | 918 |  | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 919 | // Compare the definitions of these two records. If either or both are | 
|  | 920 | // incomplete, we assume that they are equivalent. | 
|  | 921 | D1 = D1->getDefinition(); | 
|  | 922 | D2 = D2->getDefinition(); | 
|  | 923 | if (!D1 || !D2) | 
|  | 924 | return true; | 
|  | 925 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 926 | if (CXXRecordDecl *D1CXX = dyn_cast<CXXRecordDecl>(D1)) { | 
|  | 927 | if (CXXRecordDecl *D2CXX = dyn_cast<CXXRecordDecl>(D2)) { | 
|  | 928 | if (D1CXX->getNumBases() != D2CXX->getNumBases()) { | 
|  | 929 | Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent) | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 930 | << Context.C2.getTypeDeclType(D2); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 931 | Context.Diag2(D2->getLocation(), diag::note_odr_number_of_bases) | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 932 | << D2CXX->getNumBases(); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 933 | Context.Diag1(D1->getLocation(), diag::note_odr_number_of_bases) | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 934 | << D1CXX->getNumBases(); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 935 | return false; | 
|  | 936 | } | 
|  | 937 |  | 
|  | 938 | // Check the base classes. | 
|  | 939 | for (CXXRecordDecl::base_class_iterator Base1 = D1CXX->bases_begin(), | 
|  | 940 | BaseEnd1 = D1CXX->bases_end(), | 
|  | 941 | Base2 = D2CXX->bases_begin(); | 
|  | 942 | Base1 != BaseEnd1; | 
|  | 943 | ++Base1, ++Base2) { | 
|  | 944 | if (!IsStructurallyEquivalent(Context, | 
|  | 945 | Base1->getType(), Base2->getType())) { | 
|  | 946 | Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent) | 
|  | 947 | << Context.C2.getTypeDeclType(D2); | 
|  | 948 | Context.Diag2(Base2->getSourceRange().getBegin(), diag::note_odr_base) | 
|  | 949 | << Base2->getType() | 
|  | 950 | << Base2->getSourceRange(); | 
|  | 951 | Context.Diag1(Base1->getSourceRange().getBegin(), diag::note_odr_base) | 
|  | 952 | << Base1->getType() | 
|  | 953 | << Base1->getSourceRange(); | 
|  | 954 | return false; | 
|  | 955 | } | 
|  | 956 |  | 
|  | 957 | // Check virtual vs. non-virtual inheritance mismatch. | 
|  | 958 | if (Base1->isVirtual() != Base2->isVirtual()) { | 
|  | 959 | Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent) | 
|  | 960 | << Context.C2.getTypeDeclType(D2); | 
|  | 961 | Context.Diag2(Base2->getSourceRange().getBegin(), | 
|  | 962 | diag::note_odr_virtual_base) | 
|  | 963 | << Base2->isVirtual() << Base2->getSourceRange(); | 
|  | 964 | Context.Diag1(Base1->getSourceRange().getBegin(), diag::note_odr_base) | 
|  | 965 | << Base1->isVirtual() | 
|  | 966 | << Base1->getSourceRange(); | 
|  | 967 | return false; | 
|  | 968 | } | 
|  | 969 | } | 
|  | 970 | } else if (D1CXX->getNumBases() > 0) { | 
|  | 971 | Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent) | 
|  | 972 | << Context.C2.getTypeDeclType(D2); | 
|  | 973 | const CXXBaseSpecifier *Base1 = D1CXX->bases_begin(); | 
|  | 974 | Context.Diag1(Base1->getSourceRange().getBegin(), diag::note_odr_base) | 
|  | 975 | << Base1->getType() | 
|  | 976 | << Base1->getSourceRange(); | 
|  | 977 | Context.Diag2(D2->getLocation(), diag::note_odr_missing_base); | 
|  | 978 | return false; | 
|  | 979 | } | 
|  | 980 | } | 
|  | 981 |  | 
|  | 982 | // Check the fields for consistency. | 
|  | 983 | CXXRecordDecl::field_iterator Field2 = D2->field_begin(), | 
|  | 984 | Field2End = D2->field_end(); | 
|  | 985 | for (CXXRecordDecl::field_iterator Field1 = D1->field_begin(), | 
|  | 986 | Field1End = D1->field_end(); | 
|  | 987 | Field1 != Field1End; | 
|  | 988 | ++Field1, ++Field2) { | 
|  | 989 | if (Field2 == Field2End) { | 
|  | 990 | Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent) | 
|  | 991 | << Context.C2.getTypeDeclType(D2); | 
|  | 992 | Context.Diag1(Field1->getLocation(), diag::note_odr_field) | 
|  | 993 | << Field1->getDeclName() << Field1->getType(); | 
|  | 994 | Context.Diag2(D2->getLocation(), diag::note_odr_missing_field); | 
|  | 995 | return false; | 
|  | 996 | } | 
|  | 997 |  | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 998 | if (!IsStructurallyEquivalent(Context, *Field1, *Field2)) | 
|  | 999 | return false; | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1000 | } | 
|  | 1001 |  | 
|  | 1002 | if (Field2 != Field2End) { | 
|  | 1003 | Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent) | 
|  | 1004 | << Context.C2.getTypeDeclType(D2); | 
|  | 1005 | Context.Diag2(Field2->getLocation(), diag::note_odr_field) | 
|  | 1006 | << Field2->getDeclName() << Field2->getType(); | 
|  | 1007 | Context.Diag1(D1->getLocation(), diag::note_odr_missing_field); | 
|  | 1008 | return false; | 
|  | 1009 | } | 
|  | 1010 |  | 
|  | 1011 | return true; | 
|  | 1012 | } | 
|  | 1013 |  | 
|  | 1014 | /// \brief Determine structural equivalence of two enums. | 
|  | 1015 | static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, | 
|  | 1016 | EnumDecl *D1, EnumDecl *D2) { | 
|  | 1017 | EnumDecl::enumerator_iterator EC2 = D2->enumerator_begin(), | 
|  | 1018 | EC2End = D2->enumerator_end(); | 
|  | 1019 | for (EnumDecl::enumerator_iterator EC1 = D1->enumerator_begin(), | 
|  | 1020 | EC1End = D1->enumerator_end(); | 
|  | 1021 | EC1 != EC1End; ++EC1, ++EC2) { | 
|  | 1022 | if (EC2 == EC2End) { | 
|  | 1023 | Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent) | 
|  | 1024 | << Context.C2.getTypeDeclType(D2); | 
|  | 1025 | Context.Diag1(EC1->getLocation(), diag::note_odr_enumerator) | 
|  | 1026 | << EC1->getDeclName() | 
|  | 1027 | << EC1->getInitVal().toString(10); | 
|  | 1028 | Context.Diag2(D2->getLocation(), diag::note_odr_missing_enumerator); | 
|  | 1029 | return false; | 
|  | 1030 | } | 
|  | 1031 |  | 
|  | 1032 | llvm::APSInt Val1 = EC1->getInitVal(); | 
|  | 1033 | llvm::APSInt Val2 = EC2->getInitVal(); | 
|  | 1034 | if (!IsSameValue(Val1, Val2) || | 
|  | 1035 | !IsStructurallyEquivalent(EC1->getIdentifier(), EC2->getIdentifier())) { | 
|  | 1036 | Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent) | 
|  | 1037 | << Context.C2.getTypeDeclType(D2); | 
|  | 1038 | Context.Diag2(EC2->getLocation(), diag::note_odr_enumerator) | 
|  | 1039 | << EC2->getDeclName() | 
|  | 1040 | << EC2->getInitVal().toString(10); | 
|  | 1041 | Context.Diag1(EC1->getLocation(), diag::note_odr_enumerator) | 
|  | 1042 | << EC1->getDeclName() | 
|  | 1043 | << EC1->getInitVal().toString(10); | 
|  | 1044 | return false; | 
|  | 1045 | } | 
|  | 1046 | } | 
|  | 1047 |  | 
|  | 1048 | if (EC2 != EC2End) { | 
|  | 1049 | Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent) | 
|  | 1050 | << Context.C2.getTypeDeclType(D2); | 
|  | 1051 | Context.Diag2(EC2->getLocation(), diag::note_odr_enumerator) | 
|  | 1052 | << EC2->getDeclName() | 
|  | 1053 | << EC2->getInitVal().toString(10); | 
|  | 1054 | Context.Diag1(D1->getLocation(), diag::note_odr_missing_enumerator); | 
|  | 1055 | return false; | 
|  | 1056 | } | 
|  | 1057 |  | 
|  | 1058 | return true; | 
|  | 1059 | } | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1060 |  | 
|  | 1061 | static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, | 
|  | 1062 | TemplateParameterList *Params1, | 
|  | 1063 | TemplateParameterList *Params2) { | 
|  | 1064 | if (Params1->size() != Params2->size()) { | 
|  | 1065 | Context.Diag2(Params2->getTemplateLoc(), | 
|  | 1066 | diag::err_odr_different_num_template_parameters) | 
|  | 1067 | << Params1->size() << Params2->size(); | 
|  | 1068 | Context.Diag1(Params1->getTemplateLoc(), | 
|  | 1069 | diag::note_odr_template_parameter_list); | 
|  | 1070 | return false; | 
|  | 1071 | } | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1072 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1073 | for (unsigned I = 0, N = Params1->size(); I != N; ++I) { | 
|  | 1074 | if (Params1->getParam(I)->getKind() != Params2->getParam(I)->getKind()) { | 
|  | 1075 | Context.Diag2(Params2->getParam(I)->getLocation(), | 
|  | 1076 | diag::err_odr_different_template_parameter_kind); | 
|  | 1077 | Context.Diag1(Params1->getParam(I)->getLocation(), | 
|  | 1078 | diag::note_odr_template_parameter_here); | 
|  | 1079 | return false; | 
|  | 1080 | } | 
|  | 1081 |  | 
|  | 1082 | if (!Context.IsStructurallyEquivalent(Params1->getParam(I), | 
|  | 1083 | Params2->getParam(I))) { | 
|  | 1084 |  | 
|  | 1085 | return false; | 
|  | 1086 | } | 
|  | 1087 | } | 
|  | 1088 |  | 
|  | 1089 | return true; | 
|  | 1090 | } | 
|  | 1091 |  | 
|  | 1092 | static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, | 
|  | 1093 | TemplateTypeParmDecl *D1, | 
|  | 1094 | TemplateTypeParmDecl *D2) { | 
|  | 1095 | if (D1->isParameterPack() != D2->isParameterPack()) { | 
|  | 1096 | Context.Diag2(D2->getLocation(), diag::err_odr_parameter_pack_non_pack) | 
|  | 1097 | << D2->isParameterPack(); | 
|  | 1098 | Context.Diag1(D1->getLocation(), diag::note_odr_parameter_pack_non_pack) | 
|  | 1099 | << D1->isParameterPack(); | 
|  | 1100 | return false; | 
|  | 1101 | } | 
|  | 1102 |  | 
|  | 1103 | return true; | 
|  | 1104 | } | 
|  | 1105 |  | 
|  | 1106 | static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, | 
|  | 1107 | NonTypeTemplateParmDecl *D1, | 
|  | 1108 | NonTypeTemplateParmDecl *D2) { | 
|  | 1109 | // FIXME: Enable once we have variadic templates. | 
|  | 1110 | #if 0 | 
|  | 1111 | if (D1->isParameterPack() != D2->isParameterPack()) { | 
|  | 1112 | Context.Diag2(D2->getLocation(), diag::err_odr_parameter_pack_non_pack) | 
|  | 1113 | << D2->isParameterPack(); | 
|  | 1114 | Context.Diag1(D1->getLocation(), diag::note_odr_parameter_pack_non_pack) | 
|  | 1115 | << D1->isParameterPack(); | 
|  | 1116 | return false; | 
|  | 1117 | } | 
|  | 1118 | #endif | 
|  | 1119 |  | 
|  | 1120 | // Check types. | 
|  | 1121 | if (!Context.IsStructurallyEquivalent(D1->getType(), D2->getType())) { | 
|  | 1122 | Context.Diag2(D2->getLocation(), | 
|  | 1123 | diag::err_odr_non_type_parameter_type_inconsistent) | 
|  | 1124 | << D2->getType() << D1->getType(); | 
|  | 1125 | Context.Diag1(D1->getLocation(), diag::note_odr_value_here) | 
|  | 1126 | << D1->getType(); | 
|  | 1127 | return false; | 
|  | 1128 | } | 
|  | 1129 |  | 
|  | 1130 | return true; | 
|  | 1131 | } | 
|  | 1132 |  | 
|  | 1133 | static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, | 
|  | 1134 | TemplateTemplateParmDecl *D1, | 
|  | 1135 | TemplateTemplateParmDecl *D2) { | 
|  | 1136 | // FIXME: Enable once we have variadic templates. | 
|  | 1137 | #if 0 | 
|  | 1138 | if (D1->isParameterPack() != D2->isParameterPack()) { | 
|  | 1139 | Context.Diag2(D2->getLocation(), diag::err_odr_parameter_pack_non_pack) | 
|  | 1140 | << D2->isParameterPack(); | 
|  | 1141 | Context.Diag1(D1->getLocation(), diag::note_odr_parameter_pack_non_pack) | 
|  | 1142 | << D1->isParameterPack(); | 
|  | 1143 | return false; | 
|  | 1144 | } | 
|  | 1145 | #endif | 
|  | 1146 |  | 
|  | 1147 | // Check template parameter lists. | 
|  | 1148 | return IsStructurallyEquivalent(Context, D1->getTemplateParameters(), | 
|  | 1149 | D2->getTemplateParameters()); | 
|  | 1150 | } | 
|  | 1151 |  | 
|  | 1152 | static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, | 
|  | 1153 | ClassTemplateDecl *D1, | 
|  | 1154 | ClassTemplateDecl *D2) { | 
|  | 1155 | // Check template parameters. | 
|  | 1156 | if (!IsStructurallyEquivalent(Context, | 
|  | 1157 | D1->getTemplateParameters(), | 
|  | 1158 | D2->getTemplateParameters())) | 
|  | 1159 | return false; | 
|  | 1160 |  | 
|  | 1161 | // Check the templated declaration. | 
|  | 1162 | return Context.IsStructurallyEquivalent(D1->getTemplatedDecl(), | 
|  | 1163 | D2->getTemplatedDecl()); | 
|  | 1164 | } | 
|  | 1165 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1166 | /// \brief Determine structural equivalence of two declarations. | 
|  | 1167 | static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, | 
|  | 1168 | Decl *D1, Decl *D2) { | 
|  | 1169 | // FIXME: Check for known structural equivalences via a callback of some sort. | 
|  | 1170 |  | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1171 | // Check whether we already know that these two declarations are not | 
|  | 1172 | // structurally equivalent. | 
|  | 1173 | if (Context.NonEquivalentDecls.count(std::make_pair(D1->getCanonicalDecl(), | 
|  | 1174 | D2->getCanonicalDecl()))) | 
|  | 1175 | return false; | 
|  | 1176 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1177 | // Determine whether we've already produced a tentative equivalence for D1. | 
|  | 1178 | Decl *&EquivToD1 = Context.TentativeEquivalences[D1->getCanonicalDecl()]; | 
|  | 1179 | if (EquivToD1) | 
|  | 1180 | return EquivToD1 == D2->getCanonicalDecl(); | 
|  | 1181 |  | 
|  | 1182 | // Produce a tentative equivalence D1 <-> D2, which will be checked later. | 
|  | 1183 | EquivToD1 = D2->getCanonicalDecl(); | 
|  | 1184 | Context.DeclsToCheck.push_back(D1->getCanonicalDecl()); | 
|  | 1185 | return true; | 
|  | 1186 | } | 
|  | 1187 |  | 
|  | 1188 | bool StructuralEquivalenceContext::IsStructurallyEquivalent(Decl *D1, | 
|  | 1189 | Decl *D2) { | 
|  | 1190 | if (!::IsStructurallyEquivalent(*this, D1, D2)) | 
|  | 1191 | return false; | 
|  | 1192 |  | 
|  | 1193 | return !Finish(); | 
|  | 1194 | } | 
|  | 1195 |  | 
|  | 1196 | bool StructuralEquivalenceContext::IsStructurallyEquivalent(QualType T1, | 
|  | 1197 | QualType T2) { | 
|  | 1198 | if (!::IsStructurallyEquivalent(*this, T1, T2)) | 
|  | 1199 | return false; | 
|  | 1200 |  | 
|  | 1201 | return !Finish(); | 
|  | 1202 | } | 
|  | 1203 |  | 
|  | 1204 | bool StructuralEquivalenceContext::Finish() { | 
|  | 1205 | while (!DeclsToCheck.empty()) { | 
|  | 1206 | // Check the next declaration. | 
|  | 1207 | Decl *D1 = DeclsToCheck.front(); | 
|  | 1208 | DeclsToCheck.pop_front(); | 
|  | 1209 |  | 
|  | 1210 | Decl *D2 = TentativeEquivalences[D1]; | 
|  | 1211 | assert(D2 && "Unrecorded tentative equivalence?"); | 
|  | 1212 |  | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1213 | bool Equivalent = true; | 
|  | 1214 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1215 | // FIXME: Switch on all declaration kinds. For now, we're just going to | 
|  | 1216 | // check the obvious ones. | 
|  | 1217 | if (RecordDecl *Record1 = dyn_cast<RecordDecl>(D1)) { | 
|  | 1218 | if (RecordDecl *Record2 = dyn_cast<RecordDecl>(D2)) { | 
|  | 1219 | // Check for equivalent structure names. | 
|  | 1220 | IdentifierInfo *Name1 = Record1->getIdentifier(); | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1221 | if (!Name1 && Record1->getTypedefNameForAnonDecl()) | 
|  | 1222 | Name1 = Record1->getTypedefNameForAnonDecl()->getIdentifier(); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1223 | IdentifierInfo *Name2 = Record2->getIdentifier(); | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1224 | if (!Name2 && Record2->getTypedefNameForAnonDecl()) | 
|  | 1225 | Name2 = Record2->getTypedefNameForAnonDecl()->getIdentifier(); | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1226 | if (!::IsStructurallyEquivalent(Name1, Name2) || | 
|  | 1227 | !::IsStructurallyEquivalent(*this, Record1, Record2)) | 
|  | 1228 | Equivalent = false; | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1229 | } else { | 
|  | 1230 | // Record/non-record mismatch. | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1231 | Equivalent = false; | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1232 | } | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1233 | } else if (EnumDecl *Enum1 = dyn_cast<EnumDecl>(D1)) { | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1234 | if (EnumDecl *Enum2 = dyn_cast<EnumDecl>(D2)) { | 
|  | 1235 | // Check for equivalent enum names. | 
|  | 1236 | IdentifierInfo *Name1 = Enum1->getIdentifier(); | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1237 | if (!Name1 && Enum1->getTypedefNameForAnonDecl()) | 
|  | 1238 | Name1 = Enum1->getTypedefNameForAnonDecl()->getIdentifier(); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1239 | IdentifierInfo *Name2 = Enum2->getIdentifier(); | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1240 | if (!Name2 && Enum2->getTypedefNameForAnonDecl()) | 
|  | 1241 | Name2 = Enum2->getTypedefNameForAnonDecl()->getIdentifier(); | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1242 | if (!::IsStructurallyEquivalent(Name1, Name2) || | 
|  | 1243 | !::IsStructurallyEquivalent(*this, Enum1, Enum2)) | 
|  | 1244 | Equivalent = false; | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1245 | } else { | 
|  | 1246 | // Enum/non-enum mismatch | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1247 | Equivalent = false; | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1248 | } | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1249 | } else if (TypedefNameDecl *Typedef1 = dyn_cast<TypedefNameDecl>(D1)) { | 
|  | 1250 | if (TypedefNameDecl *Typedef2 = dyn_cast<TypedefNameDecl>(D2)) { | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1251 | if (!::IsStructurallyEquivalent(Typedef1->getIdentifier(), | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1252 | Typedef2->getIdentifier()) || | 
|  | 1253 | !::IsStructurallyEquivalent(*this, | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1254 | Typedef1->getUnderlyingType(), | 
|  | 1255 | Typedef2->getUnderlyingType())) | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1256 | Equivalent = false; | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1257 | } else { | 
|  | 1258 | // Typedef/non-typedef mismatch. | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1259 | Equivalent = false; | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1260 | } | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1261 | } else if (ClassTemplateDecl *ClassTemplate1 | 
|  | 1262 | = dyn_cast<ClassTemplateDecl>(D1)) { | 
|  | 1263 | if (ClassTemplateDecl *ClassTemplate2 = dyn_cast<ClassTemplateDecl>(D2)) { | 
|  | 1264 | if (!::IsStructurallyEquivalent(ClassTemplate1->getIdentifier(), | 
|  | 1265 | ClassTemplate2->getIdentifier()) || | 
|  | 1266 | !::IsStructurallyEquivalent(*this, ClassTemplate1, ClassTemplate2)) | 
|  | 1267 | Equivalent = false; | 
|  | 1268 | } else { | 
|  | 1269 | // Class template/non-class-template mismatch. | 
|  | 1270 | Equivalent = false; | 
|  | 1271 | } | 
|  | 1272 | } else if (TemplateTypeParmDecl *TTP1= dyn_cast<TemplateTypeParmDecl>(D1)) { | 
|  | 1273 | if (TemplateTypeParmDecl *TTP2 = dyn_cast<TemplateTypeParmDecl>(D2)) { | 
|  | 1274 | if (!::IsStructurallyEquivalent(*this, TTP1, TTP2)) | 
|  | 1275 | Equivalent = false; | 
|  | 1276 | } else { | 
|  | 1277 | // Kind mismatch. | 
|  | 1278 | Equivalent = false; | 
|  | 1279 | } | 
|  | 1280 | } else if (NonTypeTemplateParmDecl *NTTP1 | 
|  | 1281 | = dyn_cast<NonTypeTemplateParmDecl>(D1)) { | 
|  | 1282 | if (NonTypeTemplateParmDecl *NTTP2 | 
|  | 1283 | = dyn_cast<NonTypeTemplateParmDecl>(D2)) { | 
|  | 1284 | if (!::IsStructurallyEquivalent(*this, NTTP1, NTTP2)) | 
|  | 1285 | Equivalent = false; | 
|  | 1286 | } else { | 
|  | 1287 | // Kind mismatch. | 
|  | 1288 | Equivalent = false; | 
|  | 1289 | } | 
|  | 1290 | } else if (TemplateTemplateParmDecl *TTP1 | 
|  | 1291 | = dyn_cast<TemplateTemplateParmDecl>(D1)) { | 
|  | 1292 | if (TemplateTemplateParmDecl *TTP2 | 
|  | 1293 | = dyn_cast<TemplateTemplateParmDecl>(D2)) { | 
|  | 1294 | if (!::IsStructurallyEquivalent(*this, TTP1, TTP2)) | 
|  | 1295 | Equivalent = false; | 
|  | 1296 | } else { | 
|  | 1297 | // Kind mismatch. | 
|  | 1298 | Equivalent = false; | 
|  | 1299 | } | 
|  | 1300 | } | 
|  | 1301 |  | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1302 | if (!Equivalent) { | 
|  | 1303 | // Note that these two declarations are not equivalent (and we already | 
|  | 1304 | // know about it). | 
|  | 1305 | NonEquivalentDecls.insert(std::make_pair(D1->getCanonicalDecl(), | 
|  | 1306 | D2->getCanonicalDecl())); | 
|  | 1307 | return true; | 
|  | 1308 | } | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1309 | // FIXME: Check other declaration kinds! | 
|  | 1310 | } | 
|  | 1311 |  | 
|  | 1312 | return false; | 
|  | 1313 | } | 
|  | 1314 |  | 
|  | 1315 | //---------------------------------------------------------------------------- | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1316 | // Import Types | 
|  | 1317 | //---------------------------------------------------------------------------- | 
|  | 1318 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1319 | QualType ASTNodeImporter::VisitType(const Type *T) { | 
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1320 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) | 
|  | 1321 | << T->getTypeClassName(); | 
|  | 1322 | return QualType(); | 
|  | 1323 | } | 
|  | 1324 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1325 | QualType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1326 | switch (T->getKind()) { | 
| John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 1327 | #define SHARED_SINGLETON_TYPE(Expansion) | 
|  | 1328 | #define BUILTIN_TYPE(Id, SingletonId) \ | 
|  | 1329 | case BuiltinType::Id: return Importer.getToContext().SingletonId; | 
|  | 1330 | #include "clang/AST/BuiltinTypes.def" | 
|  | 1331 |  | 
|  | 1332 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" | 
|  | 1333 | // context supports C++. | 
|  | 1334 |  | 
|  | 1335 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" | 
|  | 1336 | // context supports ObjC. | 
|  | 1337 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1338 | case BuiltinType::Char_U: | 
|  | 1339 | // The context we're importing from has an unsigned 'char'. If we're | 
|  | 1340 | // importing into a context with a signed 'char', translate to | 
|  | 1341 | // 'unsigned char' instead. | 
|  | 1342 | if (Importer.getToContext().getLangOptions().CharIsSigned) | 
|  | 1343 | return Importer.getToContext().UnsignedCharTy; | 
|  | 1344 |  | 
|  | 1345 | return Importer.getToContext().CharTy; | 
|  | 1346 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1347 | case BuiltinType::Char_S: | 
|  | 1348 | // The context we're importing from has an unsigned 'char'. If we're | 
|  | 1349 | // importing into a context with a signed 'char', translate to | 
|  | 1350 | // 'unsigned char' instead. | 
|  | 1351 | if (!Importer.getToContext().getLangOptions().CharIsSigned) | 
|  | 1352 | return Importer.getToContext().SignedCharTy; | 
|  | 1353 |  | 
|  | 1354 | return Importer.getToContext().CharTy; | 
|  | 1355 |  | 
| Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 1356 | case BuiltinType::WChar_S: | 
|  | 1357 | case BuiltinType::WChar_U: | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1358 | // FIXME: If not in C++, shall we translate to the C equivalent of | 
|  | 1359 | // wchar_t? | 
|  | 1360 | return Importer.getToContext().WCharTy; | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1361 | } | 
|  | 1362 |  | 
|  | 1363 | return QualType(); | 
|  | 1364 | } | 
|  | 1365 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1366 | QualType ASTNodeImporter::VisitComplexType(const ComplexType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1367 | QualType ToElementType = Importer.Import(T->getElementType()); | 
|  | 1368 | if (ToElementType.isNull()) | 
|  | 1369 | return QualType(); | 
|  | 1370 |  | 
|  | 1371 | return Importer.getToContext().getComplexType(ToElementType); | 
|  | 1372 | } | 
|  | 1373 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1374 | QualType ASTNodeImporter::VisitPointerType(const PointerType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1375 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); | 
|  | 1376 | if (ToPointeeType.isNull()) | 
|  | 1377 | return QualType(); | 
|  | 1378 |  | 
|  | 1379 | return Importer.getToContext().getPointerType(ToPointeeType); | 
|  | 1380 | } | 
|  | 1381 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1382 | QualType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1383 | // FIXME: Check for blocks support in "to" context. | 
|  | 1384 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); | 
|  | 1385 | if (ToPointeeType.isNull()) | 
|  | 1386 | return QualType(); | 
|  | 1387 |  | 
|  | 1388 | return Importer.getToContext().getBlockPointerType(ToPointeeType); | 
|  | 1389 | } | 
|  | 1390 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1391 | QualType | 
|  | 1392 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1393 | // FIXME: Check for C++ support in "to" context. | 
|  | 1394 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); | 
|  | 1395 | if (ToPointeeType.isNull()) | 
|  | 1396 | return QualType(); | 
|  | 1397 |  | 
|  | 1398 | return Importer.getToContext().getLValueReferenceType(ToPointeeType); | 
|  | 1399 | } | 
|  | 1400 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1401 | QualType | 
|  | 1402 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1403 | // FIXME: Check for C++0x support in "to" context. | 
|  | 1404 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); | 
|  | 1405 | if (ToPointeeType.isNull()) | 
|  | 1406 | return QualType(); | 
|  | 1407 |  | 
|  | 1408 | return Importer.getToContext().getRValueReferenceType(ToPointeeType); | 
|  | 1409 | } | 
|  | 1410 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1411 | QualType ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1412 | // FIXME: Check for C++ support in "to" context. | 
|  | 1413 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); | 
|  | 1414 | if (ToPointeeType.isNull()) | 
|  | 1415 | return QualType(); | 
|  | 1416 |  | 
|  | 1417 | QualType ClassType = Importer.Import(QualType(T->getClass(), 0)); | 
|  | 1418 | return Importer.getToContext().getMemberPointerType(ToPointeeType, | 
|  | 1419 | ClassType.getTypePtr()); | 
|  | 1420 | } | 
|  | 1421 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1422 | QualType ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1423 | QualType ToElementType = Importer.Import(T->getElementType()); | 
|  | 1424 | if (ToElementType.isNull()) | 
|  | 1425 | return QualType(); | 
|  | 1426 |  | 
|  | 1427 | return Importer.getToContext().getConstantArrayType(ToElementType, | 
|  | 1428 | T->getSize(), | 
|  | 1429 | T->getSizeModifier(), | 
|  | 1430 | T->getIndexTypeCVRQualifiers()); | 
|  | 1431 | } | 
|  | 1432 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1433 | QualType | 
|  | 1434 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1435 | QualType ToElementType = Importer.Import(T->getElementType()); | 
|  | 1436 | if (ToElementType.isNull()) | 
|  | 1437 | return QualType(); | 
|  | 1438 |  | 
|  | 1439 | return Importer.getToContext().getIncompleteArrayType(ToElementType, | 
|  | 1440 | T->getSizeModifier(), | 
|  | 1441 | T->getIndexTypeCVRQualifiers()); | 
|  | 1442 | } | 
|  | 1443 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1444 | QualType ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1445 | QualType ToElementType = Importer.Import(T->getElementType()); | 
|  | 1446 | if (ToElementType.isNull()) | 
|  | 1447 | return QualType(); | 
|  | 1448 |  | 
|  | 1449 | Expr *Size = Importer.Import(T->getSizeExpr()); | 
|  | 1450 | if (!Size) | 
|  | 1451 | return QualType(); | 
|  | 1452 |  | 
|  | 1453 | SourceRange Brackets = Importer.Import(T->getBracketsRange()); | 
|  | 1454 | return Importer.getToContext().getVariableArrayType(ToElementType, Size, | 
|  | 1455 | T->getSizeModifier(), | 
|  | 1456 | T->getIndexTypeCVRQualifiers(), | 
|  | 1457 | Brackets); | 
|  | 1458 | } | 
|  | 1459 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1460 | QualType ASTNodeImporter::VisitVectorType(const VectorType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1461 | QualType ToElementType = Importer.Import(T->getElementType()); | 
|  | 1462 | if (ToElementType.isNull()) | 
|  | 1463 | return QualType(); | 
|  | 1464 |  | 
|  | 1465 | return Importer.getToContext().getVectorType(ToElementType, | 
|  | 1466 | T->getNumElements(), | 
| Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 1467 | T->getVectorKind()); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1468 | } | 
|  | 1469 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1470 | QualType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1471 | QualType ToElementType = Importer.Import(T->getElementType()); | 
|  | 1472 | if (ToElementType.isNull()) | 
|  | 1473 | return QualType(); | 
|  | 1474 |  | 
|  | 1475 | return Importer.getToContext().getExtVectorType(ToElementType, | 
|  | 1476 | T->getNumElements()); | 
|  | 1477 | } | 
|  | 1478 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1479 | QualType | 
|  | 1480 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1481 | // FIXME: What happens if we're importing a function without a prototype | 
|  | 1482 | // into C++? Should we make it variadic? | 
|  | 1483 | QualType ToResultType = Importer.Import(T->getResultType()); | 
|  | 1484 | if (ToResultType.isNull()) | 
|  | 1485 | return QualType(); | 
| Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1486 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1487 | return Importer.getToContext().getFunctionNoProtoType(ToResultType, | 
| Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1488 | T->getExtInfo()); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1489 | } | 
|  | 1490 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1491 | QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1492 | QualType ToResultType = Importer.Import(T->getResultType()); | 
|  | 1493 | if (ToResultType.isNull()) | 
|  | 1494 | return QualType(); | 
|  | 1495 |  | 
|  | 1496 | // Import argument types | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1497 | SmallVector<QualType, 4> ArgTypes; | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1498 | for (FunctionProtoType::arg_type_iterator A = T->arg_type_begin(), | 
|  | 1499 | AEnd = T->arg_type_end(); | 
|  | 1500 | A != AEnd; ++A) { | 
|  | 1501 | QualType ArgType = Importer.Import(*A); | 
|  | 1502 | if (ArgType.isNull()) | 
|  | 1503 | return QualType(); | 
|  | 1504 | ArgTypes.push_back(ArgType); | 
|  | 1505 | } | 
|  | 1506 |  | 
|  | 1507 | // Import exception types | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1508 | SmallVector<QualType, 4> ExceptionTypes; | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1509 | for (FunctionProtoType::exception_iterator E = T->exception_begin(), | 
|  | 1510 | EEnd = T->exception_end(); | 
|  | 1511 | E != EEnd; ++E) { | 
|  | 1512 | QualType ExceptionType = Importer.Import(*E); | 
|  | 1513 | if (ExceptionType.isNull()) | 
|  | 1514 | return QualType(); | 
|  | 1515 | ExceptionTypes.push_back(ExceptionType); | 
|  | 1516 | } | 
| John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 1517 |  | 
|  | 1518 | FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo(); | 
|  | 1519 | EPI.Exceptions = ExceptionTypes.data(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1520 |  | 
|  | 1521 | return Importer.getToContext().getFunctionType(ToResultType, ArgTypes.data(), | 
| John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 1522 | ArgTypes.size(), EPI); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1523 | } | 
|  | 1524 |  | 
| Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 1525 | QualType ASTNodeImporter::VisitParenType(const ParenType *T) { | 
|  | 1526 | QualType ToInnerType = Importer.Import(T->getInnerType()); | 
|  | 1527 | if (ToInnerType.isNull()) | 
|  | 1528 | return QualType(); | 
|  | 1529 |  | 
|  | 1530 | return Importer.getToContext().getParenType(ToInnerType); | 
|  | 1531 | } | 
|  | 1532 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1533 | QualType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1534 | TypedefNameDecl *ToDecl | 
|  | 1535 | = dyn_cast_or_null<TypedefNameDecl>(Importer.Import(T->getDecl())); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1536 | if (!ToDecl) | 
|  | 1537 | return QualType(); | 
|  | 1538 |  | 
|  | 1539 | return Importer.getToContext().getTypeDeclType(ToDecl); | 
|  | 1540 | } | 
|  | 1541 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1542 | QualType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1543 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); | 
|  | 1544 | if (!ToExpr) | 
|  | 1545 | return QualType(); | 
|  | 1546 |  | 
|  | 1547 | return Importer.getToContext().getTypeOfExprType(ToExpr); | 
|  | 1548 | } | 
|  | 1549 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1550 | QualType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1551 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); | 
|  | 1552 | if (ToUnderlyingType.isNull()) | 
|  | 1553 | return QualType(); | 
|  | 1554 |  | 
|  | 1555 | return Importer.getToContext().getTypeOfType(ToUnderlyingType); | 
|  | 1556 | } | 
|  | 1557 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1558 | QualType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { | 
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1559 | // FIXME: Make sure that the "to" context supports C++0x! | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1560 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); | 
|  | 1561 | if (!ToExpr) | 
|  | 1562 | return QualType(); | 
|  | 1563 |  | 
|  | 1564 | return Importer.getToContext().getDecltypeType(ToExpr); | 
|  | 1565 | } | 
|  | 1566 |  | 
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1567 | QualType ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { | 
|  | 1568 | QualType ToBaseType = Importer.Import(T->getBaseType()); | 
|  | 1569 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); | 
|  | 1570 | if (ToBaseType.isNull() || ToUnderlyingType.isNull()) | 
|  | 1571 | return QualType(); | 
|  | 1572 |  | 
|  | 1573 | return Importer.getToContext().getUnaryTransformType(ToBaseType, | 
|  | 1574 | ToUnderlyingType, | 
|  | 1575 | T->getUTTKind()); | 
|  | 1576 | } | 
|  | 1577 |  | 
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1578 | QualType ASTNodeImporter::VisitAutoType(const AutoType *T) { | 
|  | 1579 | // FIXME: Make sure that the "to" context supports C++0x! | 
|  | 1580 | QualType FromDeduced = T->getDeducedType(); | 
|  | 1581 | QualType ToDeduced; | 
|  | 1582 | if (!FromDeduced.isNull()) { | 
|  | 1583 | ToDeduced = Importer.Import(FromDeduced); | 
|  | 1584 | if (ToDeduced.isNull()) | 
|  | 1585 | return QualType(); | 
|  | 1586 | } | 
|  | 1587 |  | 
|  | 1588 | return Importer.getToContext().getAutoType(ToDeduced); | 
|  | 1589 | } | 
|  | 1590 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1591 | QualType ASTNodeImporter::VisitRecordType(const RecordType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1592 | RecordDecl *ToDecl | 
|  | 1593 | = dyn_cast_or_null<RecordDecl>(Importer.Import(T->getDecl())); | 
|  | 1594 | if (!ToDecl) | 
|  | 1595 | return QualType(); | 
|  | 1596 |  | 
|  | 1597 | return Importer.getToContext().getTagDeclType(ToDecl); | 
|  | 1598 | } | 
|  | 1599 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1600 | QualType ASTNodeImporter::VisitEnumType(const EnumType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1601 | EnumDecl *ToDecl | 
|  | 1602 | = dyn_cast_or_null<EnumDecl>(Importer.Import(T->getDecl())); | 
|  | 1603 | if (!ToDecl) | 
|  | 1604 | return QualType(); | 
|  | 1605 |  | 
|  | 1606 | return Importer.getToContext().getTagDeclType(ToDecl); | 
|  | 1607 | } | 
|  | 1608 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1609 | QualType ASTNodeImporter::VisitTemplateSpecializationType( | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1610 | const TemplateSpecializationType *T) { | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1611 | TemplateName ToTemplate = Importer.Import(T->getTemplateName()); | 
|  | 1612 | if (ToTemplate.isNull()) | 
|  | 1613 | return QualType(); | 
|  | 1614 |  | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1615 | SmallVector<TemplateArgument, 2> ToTemplateArgs; | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1616 | if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToTemplateArgs)) | 
|  | 1617 | return QualType(); | 
|  | 1618 |  | 
|  | 1619 | QualType ToCanonType; | 
|  | 1620 | if (!QualType(T, 0).isCanonical()) { | 
|  | 1621 | QualType FromCanonType | 
|  | 1622 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); | 
|  | 1623 | ToCanonType =Importer.Import(FromCanonType); | 
|  | 1624 | if (ToCanonType.isNull()) | 
|  | 1625 | return QualType(); | 
|  | 1626 | } | 
|  | 1627 | return Importer.getToContext().getTemplateSpecializationType(ToTemplate, | 
|  | 1628 | ToTemplateArgs.data(), | 
|  | 1629 | ToTemplateArgs.size(), | 
|  | 1630 | ToCanonType); | 
|  | 1631 | } | 
|  | 1632 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1633 | QualType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { | 
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1634 | NestedNameSpecifier *ToQualifier = 0; | 
|  | 1635 | // Note: the qualifier in an ElaboratedType is optional. | 
|  | 1636 | if (T->getQualifier()) { | 
|  | 1637 | ToQualifier = Importer.Import(T->getQualifier()); | 
|  | 1638 | if (!ToQualifier) | 
|  | 1639 | return QualType(); | 
|  | 1640 | } | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1641 |  | 
|  | 1642 | QualType ToNamedType = Importer.Import(T->getNamedType()); | 
|  | 1643 | if (ToNamedType.isNull()) | 
|  | 1644 | return QualType(); | 
|  | 1645 |  | 
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1646 | return Importer.getToContext().getElaboratedType(T->getKeyword(), | 
|  | 1647 | ToQualifier, ToNamedType); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1648 | } | 
|  | 1649 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1650 | QualType ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1651 | ObjCInterfaceDecl *Class | 
|  | 1652 | = dyn_cast_or_null<ObjCInterfaceDecl>(Importer.Import(T->getDecl())); | 
|  | 1653 | if (!Class) | 
|  | 1654 | return QualType(); | 
|  | 1655 |  | 
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1656 | return Importer.getToContext().getObjCInterfaceType(Class); | 
|  | 1657 | } | 
|  | 1658 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1659 | QualType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { | 
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1660 | QualType ToBaseType = Importer.Import(T->getBaseType()); | 
|  | 1661 | if (ToBaseType.isNull()) | 
|  | 1662 | return QualType(); | 
|  | 1663 |  | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1664 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | 
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1665 | for (ObjCObjectType::qual_iterator P = T->qual_begin(), | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1666 | PEnd = T->qual_end(); | 
|  | 1667 | P != PEnd; ++P) { | 
|  | 1668 | ObjCProtocolDecl *Protocol | 
|  | 1669 | = dyn_cast_or_null<ObjCProtocolDecl>(Importer.Import(*P)); | 
|  | 1670 | if (!Protocol) | 
|  | 1671 | return QualType(); | 
|  | 1672 | Protocols.push_back(Protocol); | 
|  | 1673 | } | 
|  | 1674 |  | 
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1675 | return Importer.getToContext().getObjCObjectType(ToBaseType, | 
|  | 1676 | Protocols.data(), | 
|  | 1677 | Protocols.size()); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1678 | } | 
|  | 1679 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1680 | QualType | 
|  | 1681 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1682 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); | 
|  | 1683 | if (ToPointeeType.isNull()) | 
|  | 1684 | return QualType(); | 
|  | 1685 |  | 
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1686 | return Importer.getToContext().getObjCObjectPointerType(ToPointeeType); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1687 | } | 
|  | 1688 |  | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1689 | //---------------------------------------------------------------------------- | 
|  | 1690 | // Import Declarations | 
|  | 1691 | //---------------------------------------------------------------------------- | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1692 | bool ASTNodeImporter::ImportDeclParts(NamedDecl *D, DeclContext *&DC, | 
|  | 1693 | DeclContext *&LexicalDC, | 
|  | 1694 | DeclarationName &Name, | 
|  | 1695 | SourceLocation &Loc) { | 
|  | 1696 | // Import the context of this declaration. | 
|  | 1697 | DC = Importer.ImportContext(D->getDeclContext()); | 
|  | 1698 | if (!DC) | 
|  | 1699 | return true; | 
|  | 1700 |  | 
|  | 1701 | LexicalDC = DC; | 
|  | 1702 | if (D->getDeclContext() != D->getLexicalDeclContext()) { | 
|  | 1703 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); | 
|  | 1704 | if (!LexicalDC) | 
|  | 1705 | return true; | 
|  | 1706 | } | 
|  | 1707 |  | 
|  | 1708 | // Import the name of this declaration. | 
|  | 1709 | Name = Importer.Import(D->getDeclName()); | 
|  | 1710 | if (D->getDeclName() && !Name) | 
|  | 1711 | return true; | 
|  | 1712 |  | 
|  | 1713 | // Import the location of this declaration. | 
|  | 1714 | Loc = Importer.Import(D->getLocation()); | 
|  | 1715 | return false; | 
|  | 1716 | } | 
|  | 1717 |  | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1718 | void ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { | 
|  | 1719 | if (!FromD) | 
|  | 1720 | return; | 
|  | 1721 |  | 
|  | 1722 | if (!ToD) { | 
|  | 1723 | ToD = Importer.Import(FromD); | 
|  | 1724 | if (!ToD) | 
|  | 1725 | return; | 
|  | 1726 | } | 
|  | 1727 |  | 
|  | 1728 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { | 
|  | 1729 | if (RecordDecl *ToRecord = cast_or_null<RecordDecl>(ToD)) { | 
|  | 1730 | if (FromRecord->getDefinition() && !ToRecord->getDefinition()) { | 
|  | 1731 | ImportDefinition(FromRecord, ToRecord); | 
|  | 1732 | } | 
|  | 1733 | } | 
|  | 1734 | return; | 
|  | 1735 | } | 
|  | 1736 |  | 
|  | 1737 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { | 
|  | 1738 | if (EnumDecl *ToEnum = cast_or_null<EnumDecl>(ToD)) { | 
|  | 1739 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { | 
|  | 1740 | ImportDefinition(FromEnum, ToEnum); | 
|  | 1741 | } | 
|  | 1742 | } | 
|  | 1743 | return; | 
|  | 1744 | } | 
|  | 1745 | } | 
|  | 1746 |  | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1747 | void | 
|  | 1748 | ASTNodeImporter::ImportDeclarationNameLoc(const DeclarationNameInfo &From, | 
|  | 1749 | DeclarationNameInfo& To) { | 
|  | 1750 | // NOTE: To.Name and To.Loc are already imported. | 
|  | 1751 | // We only have to import To.LocInfo. | 
|  | 1752 | switch (To.getName().getNameKind()) { | 
|  | 1753 | case DeclarationName::Identifier: | 
|  | 1754 | case DeclarationName::ObjCZeroArgSelector: | 
|  | 1755 | case DeclarationName::ObjCOneArgSelector: | 
|  | 1756 | case DeclarationName::ObjCMultiArgSelector: | 
|  | 1757 | case DeclarationName::CXXUsingDirective: | 
|  | 1758 | return; | 
|  | 1759 |  | 
|  | 1760 | case DeclarationName::CXXOperatorName: { | 
|  | 1761 | SourceRange Range = From.getCXXOperatorNameRange(); | 
|  | 1762 | To.setCXXOperatorNameRange(Importer.Import(Range)); | 
|  | 1763 | return; | 
|  | 1764 | } | 
|  | 1765 | case DeclarationName::CXXLiteralOperatorName: { | 
|  | 1766 | SourceLocation Loc = From.getCXXLiteralOperatorNameLoc(); | 
|  | 1767 | To.setCXXLiteralOperatorNameLoc(Importer.Import(Loc)); | 
|  | 1768 | return; | 
|  | 1769 | } | 
|  | 1770 | case DeclarationName::CXXConstructorName: | 
|  | 1771 | case DeclarationName::CXXDestructorName: | 
|  | 1772 | case DeclarationName::CXXConversionFunctionName: { | 
|  | 1773 | TypeSourceInfo *FromTInfo = From.getNamedTypeInfo(); | 
|  | 1774 | To.setNamedTypeInfo(Importer.Import(FromTInfo)); | 
|  | 1775 | return; | 
|  | 1776 | } | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1777 | } | 
| Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1778 | llvm_unreachable("Unknown name kind."); | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1779 | } | 
|  | 1780 |  | 
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1781 | void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { | 
|  | 1782 | if (Importer.isMinimalImport() && !ForceImport) { | 
| Sean Callanan | 81d577c | 2011-07-22 23:46:03 +0000 | [diff] [blame] | 1783 | Importer.ImportContext(FromDC); | 
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1784 | return; | 
|  | 1785 | } | 
|  | 1786 |  | 
| Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1787 | for (DeclContext::decl_iterator From = FromDC->decls_begin(), | 
|  | 1788 | FromEnd = FromDC->decls_end(); | 
|  | 1789 | From != FromEnd; | 
|  | 1790 | ++From) | 
|  | 1791 | Importer.Import(*From); | 
|  | 1792 | } | 
|  | 1793 |  | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1794 | bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To, | 
|  | 1795 | bool ForceImport) { | 
|  | 1796 | if (To->getDefinition() || To->isBeingDefined()) | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1797 | return false; | 
|  | 1798 |  | 
|  | 1799 | To->startDefinition(); | 
|  | 1800 |  | 
|  | 1801 | // Add base classes. | 
|  | 1802 | if (CXXRecordDecl *ToCXX = dyn_cast<CXXRecordDecl>(To)) { | 
|  | 1803 | CXXRecordDecl *FromCXX = cast<CXXRecordDecl>(From); | 
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1804 |  | 
|  | 1805 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); | 
|  | 1806 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); | 
|  | 1807 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; | 
|  | 1808 | ToData.UserDeclaredCopyConstructor = FromData.UserDeclaredCopyConstructor; | 
|  | 1809 | ToData.UserDeclaredMoveConstructor = FromData.UserDeclaredMoveConstructor; | 
|  | 1810 | ToData.UserDeclaredCopyAssignment = FromData.UserDeclaredCopyAssignment; | 
|  | 1811 | ToData.UserDeclaredMoveAssignment = FromData.UserDeclaredMoveAssignment; | 
|  | 1812 | ToData.UserDeclaredDestructor = FromData.UserDeclaredDestructor; | 
|  | 1813 | ToData.Aggregate = FromData.Aggregate; | 
|  | 1814 | ToData.PlainOldData = FromData.PlainOldData; | 
|  | 1815 | ToData.Empty = FromData.Empty; | 
|  | 1816 | ToData.Polymorphic = FromData.Polymorphic; | 
|  | 1817 | ToData.Abstract = FromData.Abstract; | 
|  | 1818 | ToData.IsStandardLayout = FromData.IsStandardLayout; | 
|  | 1819 | ToData.HasNoNonEmptyBases = FromData.HasNoNonEmptyBases; | 
|  | 1820 | ToData.HasPrivateFields = FromData.HasPrivateFields; | 
|  | 1821 | ToData.HasProtectedFields = FromData.HasProtectedFields; | 
|  | 1822 | ToData.HasPublicFields = FromData.HasPublicFields; | 
|  | 1823 | ToData.HasMutableFields = FromData.HasMutableFields; | 
|  | 1824 | ToData.HasTrivialDefaultConstructor = FromData.HasTrivialDefaultConstructor; | 
|  | 1825 | ToData.HasConstexprNonCopyMoveConstructor | 
|  | 1826 | = FromData.HasConstexprNonCopyMoveConstructor; | 
|  | 1827 | ToData.HasTrivialCopyConstructor = FromData.HasTrivialCopyConstructor; | 
|  | 1828 | ToData.HasTrivialMoveConstructor = FromData.HasTrivialMoveConstructor; | 
|  | 1829 | ToData.HasTrivialCopyAssignment = FromData.HasTrivialCopyAssignment; | 
|  | 1830 | ToData.HasTrivialMoveAssignment = FromData.HasTrivialMoveAssignment; | 
|  | 1831 | ToData.HasTrivialDestructor = FromData.HasTrivialDestructor; | 
|  | 1832 | ToData.HasNonLiteralTypeFieldsOrBases | 
|  | 1833 | = FromData.HasNonLiteralTypeFieldsOrBases; | 
|  | 1834 | ToData.UserProvidedDefaultConstructor | 
|  | 1835 | = FromData.UserProvidedDefaultConstructor; | 
|  | 1836 | ToData.DeclaredDefaultConstructor = FromData.DeclaredDefaultConstructor; | 
|  | 1837 | ToData.DeclaredCopyConstructor = FromData.DeclaredCopyConstructor; | 
|  | 1838 | ToData.DeclaredMoveConstructor = FromData.DeclaredMoveConstructor; | 
|  | 1839 | ToData.DeclaredCopyAssignment = FromData.DeclaredCopyAssignment; | 
|  | 1840 | ToData.DeclaredMoveAssignment = FromData.DeclaredMoveAssignment; | 
|  | 1841 | ToData.DeclaredDestructor = FromData.DeclaredDestructor; | 
|  | 1842 | ToData.FailedImplicitMoveConstructor | 
|  | 1843 | = FromData.FailedImplicitMoveConstructor; | 
|  | 1844 | ToData.FailedImplicitMoveAssignment = FromData.FailedImplicitMoveAssignment; | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1845 |  | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1846 | SmallVector<CXXBaseSpecifier *, 4> Bases; | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1847 | for (CXXRecordDecl::base_class_iterator | 
|  | 1848 | Base1 = FromCXX->bases_begin(), | 
|  | 1849 | FromBaseEnd = FromCXX->bases_end(); | 
|  | 1850 | Base1 != FromBaseEnd; | 
|  | 1851 | ++Base1) { | 
|  | 1852 | QualType T = Importer.Import(Base1->getType()); | 
|  | 1853 | if (T.isNull()) | 
| Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1854 | return true; | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1855 |  | 
|  | 1856 | SourceLocation EllipsisLoc; | 
|  | 1857 | if (Base1->isPackExpansion()) | 
|  | 1858 | EllipsisLoc = Importer.Import(Base1->getEllipsisLoc()); | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1859 |  | 
|  | 1860 | // Ensure that we have a definition for the base. | 
|  | 1861 | ImportDefinitionIfNeeded(Base1->getType()->getAsCXXRecordDecl()); | 
|  | 1862 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1863 | Bases.push_back( | 
|  | 1864 | new (Importer.getToContext()) | 
|  | 1865 | CXXBaseSpecifier(Importer.Import(Base1->getSourceRange()), | 
|  | 1866 | Base1->isVirtual(), | 
|  | 1867 | Base1->isBaseOfClass(), | 
|  | 1868 | Base1->getAccessSpecifierAsWritten(), | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1869 | Importer.Import(Base1->getTypeSourceInfo()), | 
|  | 1870 | EllipsisLoc)); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1871 | } | 
|  | 1872 | if (!Bases.empty()) | 
|  | 1873 | ToCXX->setBases(Bases.data(), Bases.size()); | 
|  | 1874 | } | 
|  | 1875 |  | 
| Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 1876 | ImportDeclContext(From, ForceImport); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1877 | To->completeDefinition(); | 
| Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1878 | return false; | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1879 | } | 
|  | 1880 |  | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1881 | bool ASTNodeImporter::ImportDefinition(EnumDecl *From, EnumDecl *To, | 
|  | 1882 | bool ForceImport) { | 
|  | 1883 | if (To->getDefinition() || To->isBeingDefined()) | 
|  | 1884 | return false; | 
|  | 1885 |  | 
|  | 1886 | To->startDefinition(); | 
|  | 1887 |  | 
|  | 1888 | QualType T = Importer.Import(Importer.getFromContext().getTypeDeclType(From)); | 
|  | 1889 | if (T.isNull()) | 
|  | 1890 | return true; | 
|  | 1891 |  | 
|  | 1892 | QualType ToPromotionType = Importer.Import(From->getPromotionType()); | 
|  | 1893 | if (ToPromotionType.isNull()) | 
|  | 1894 | return true; | 
|  | 1895 |  | 
|  | 1896 | ImportDeclContext(From, ForceImport); | 
|  | 1897 |  | 
|  | 1898 | // FIXME: we might need to merge the number of positive or negative bits | 
|  | 1899 | // if the enumerator lists don't match. | 
|  | 1900 | To->completeDefinition(T, ToPromotionType, | 
|  | 1901 | From->getNumPositiveBits(), | 
|  | 1902 | From->getNumNegativeBits()); | 
|  | 1903 | return false; | 
|  | 1904 | } | 
|  | 1905 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1906 | TemplateParameterList *ASTNodeImporter::ImportTemplateParameterList( | 
|  | 1907 | TemplateParameterList *Params) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1908 | SmallVector<NamedDecl *, 4> ToParams; | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1909 | ToParams.reserve(Params->size()); | 
|  | 1910 | for (TemplateParameterList::iterator P = Params->begin(), | 
|  | 1911 | PEnd = Params->end(); | 
|  | 1912 | P != PEnd; ++P) { | 
|  | 1913 | Decl *To = Importer.Import(*P); | 
|  | 1914 | if (!To) | 
|  | 1915 | return 0; | 
|  | 1916 |  | 
|  | 1917 | ToParams.push_back(cast<NamedDecl>(To)); | 
|  | 1918 | } | 
|  | 1919 |  | 
|  | 1920 | return TemplateParameterList::Create(Importer.getToContext(), | 
|  | 1921 | Importer.Import(Params->getTemplateLoc()), | 
|  | 1922 | Importer.Import(Params->getLAngleLoc()), | 
|  | 1923 | ToParams.data(), ToParams.size(), | 
|  | 1924 | Importer.Import(Params->getRAngleLoc())); | 
|  | 1925 | } | 
|  | 1926 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1927 | TemplateArgument | 
|  | 1928 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { | 
|  | 1929 | switch (From.getKind()) { | 
|  | 1930 | case TemplateArgument::Null: | 
|  | 1931 | return TemplateArgument(); | 
|  | 1932 |  | 
|  | 1933 | case TemplateArgument::Type: { | 
|  | 1934 | QualType ToType = Importer.Import(From.getAsType()); | 
|  | 1935 | if (ToType.isNull()) | 
|  | 1936 | return TemplateArgument(); | 
|  | 1937 | return TemplateArgument(ToType); | 
|  | 1938 | } | 
|  | 1939 |  | 
|  | 1940 | case TemplateArgument::Integral: { | 
|  | 1941 | QualType ToType = Importer.Import(From.getIntegralType()); | 
|  | 1942 | if (ToType.isNull()) | 
|  | 1943 | return TemplateArgument(); | 
|  | 1944 | return TemplateArgument(*From.getAsIntegral(), ToType); | 
|  | 1945 | } | 
|  | 1946 |  | 
|  | 1947 | case TemplateArgument::Declaration: | 
|  | 1948 | if (Decl *To = Importer.Import(From.getAsDecl())) | 
|  | 1949 | return TemplateArgument(To); | 
|  | 1950 | return TemplateArgument(); | 
|  | 1951 |  | 
|  | 1952 | case TemplateArgument::Template: { | 
|  | 1953 | TemplateName ToTemplate = Importer.Import(From.getAsTemplate()); | 
|  | 1954 | if (ToTemplate.isNull()) | 
|  | 1955 | return TemplateArgument(); | 
|  | 1956 |  | 
|  | 1957 | return TemplateArgument(ToTemplate); | 
|  | 1958 | } | 
| Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1959 |  | 
|  | 1960 | case TemplateArgument::TemplateExpansion: { | 
|  | 1961 | TemplateName ToTemplate | 
|  | 1962 | = Importer.Import(From.getAsTemplateOrTemplatePattern()); | 
|  | 1963 | if (ToTemplate.isNull()) | 
|  | 1964 | return TemplateArgument(); | 
|  | 1965 |  | 
| Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 1966 | return TemplateArgument(ToTemplate, From.getNumTemplateExpansions()); | 
| Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1967 | } | 
|  | 1968 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1969 | case TemplateArgument::Expression: | 
|  | 1970 | if (Expr *ToExpr = Importer.Import(From.getAsExpr())) | 
|  | 1971 | return TemplateArgument(ToExpr); | 
|  | 1972 | return TemplateArgument(); | 
|  | 1973 |  | 
|  | 1974 | case TemplateArgument::Pack: { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1975 | SmallVector<TemplateArgument, 2> ToPack; | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1976 | ToPack.reserve(From.pack_size()); | 
|  | 1977 | if (ImportTemplateArguments(From.pack_begin(), From.pack_size(), ToPack)) | 
|  | 1978 | return TemplateArgument(); | 
|  | 1979 |  | 
|  | 1980 | TemplateArgument *ToArgs | 
|  | 1981 | = new (Importer.getToContext()) TemplateArgument[ToPack.size()]; | 
|  | 1982 | std::copy(ToPack.begin(), ToPack.end(), ToArgs); | 
|  | 1983 | return TemplateArgument(ToArgs, ToPack.size()); | 
|  | 1984 | } | 
|  | 1985 | } | 
|  | 1986 |  | 
|  | 1987 | llvm_unreachable("Invalid template argument kind"); | 
|  | 1988 | return TemplateArgument(); | 
|  | 1989 | } | 
|  | 1990 |  | 
|  | 1991 | bool ASTNodeImporter::ImportTemplateArguments(const TemplateArgument *FromArgs, | 
|  | 1992 | unsigned NumFromArgs, | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1993 | SmallVectorImpl<TemplateArgument> &ToArgs) { | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1994 | for (unsigned I = 0; I != NumFromArgs; ++I) { | 
|  | 1995 | TemplateArgument To = ImportTemplateArgument(FromArgs[I]); | 
|  | 1996 | if (To.isNull() && !FromArgs[I].isNull()) | 
|  | 1997 | return true; | 
|  | 1998 |  | 
|  | 1999 | ToArgs.push_back(To); | 
|  | 2000 | } | 
|  | 2001 |  | 
|  | 2002 | return false; | 
|  | 2003 | } | 
|  | 2004 |  | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2005 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2006 | RecordDecl *ToRecord) { | 
| Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 2007 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2008 | Importer.getToContext(), | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2009 | Importer.getNonEquivalentDecls()); | 
| Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 2010 | return Ctx.IsStructurallyEquivalent(FromRecord, ToRecord); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2011 | } | 
|  | 2012 |  | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2013 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { | 
| Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 2014 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2015 | Importer.getToContext(), | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2016 | Importer.getNonEquivalentDecls()); | 
| Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 2017 | return Ctx.IsStructurallyEquivalent(FromEnum, ToEnum); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2018 | } | 
|  | 2019 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2020 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, | 
|  | 2021 | ClassTemplateDecl *To) { | 
|  | 2022 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | 
|  | 2023 | Importer.getToContext(), | 
|  | 2024 | Importer.getNonEquivalentDecls()); | 
|  | 2025 | return Ctx.IsStructurallyEquivalent(From, To); | 
|  | 2026 | } | 
|  | 2027 |  | 
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2028 | Decl *ASTNodeImporter::VisitDecl(Decl *D) { | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 2029 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | 
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2030 | << D->getDeclKindName(); | 
|  | 2031 | return 0; | 
|  | 2032 | } | 
|  | 2033 |  | 
| Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2034 | Decl *ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { | 
|  | 2035 | TranslationUnitDecl *ToD = | 
|  | 2036 | Importer.getToContext().getTranslationUnitDecl(); | 
|  | 2037 |  | 
|  | 2038 | Importer.Imported(D, ToD); | 
|  | 2039 |  | 
|  | 2040 | return ToD; | 
|  | 2041 | } | 
|  | 2042 |  | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2043 | Decl *ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { | 
|  | 2044 | // Import the major distinguishing characteristics of this namespace. | 
|  | 2045 | DeclContext *DC, *LexicalDC; | 
|  | 2046 | DeclarationName Name; | 
|  | 2047 | SourceLocation Loc; | 
|  | 2048 | if (ImportDeclParts(D, DC, LexicalDC, Name, Loc)) | 
|  | 2049 | return 0; | 
|  | 2050 |  | 
|  | 2051 | NamespaceDecl *MergeWithNamespace = 0; | 
|  | 2052 | if (!Name) { | 
|  | 2053 | // This is an anonymous namespace. Adopt an existing anonymous | 
|  | 2054 | // namespace if we can. | 
|  | 2055 | // FIXME: Not testable. | 
|  | 2056 | if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(DC)) | 
|  | 2057 | MergeWithNamespace = TU->getAnonymousNamespace(); | 
|  | 2058 | else | 
|  | 2059 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); | 
|  | 2060 | } else { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2061 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2062 | llvm::SmallVector<NamedDecl *, 2> FoundDecls; | 
|  | 2063 | DC->localUncachedLookup(Name, FoundDecls); | 
|  | 2064 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | 
|  | 2065 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Namespace)) | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2066 | continue; | 
|  | 2067 |  | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2068 | if (NamespaceDecl *FoundNS = dyn_cast<NamespaceDecl>(FoundDecls[I])) { | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2069 | MergeWithNamespace = FoundNS; | 
|  | 2070 | ConflictingDecls.clear(); | 
|  | 2071 | break; | 
|  | 2072 | } | 
|  | 2073 |  | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2074 | ConflictingDecls.push_back(FoundDecls[I]); | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2075 | } | 
|  | 2076 |  | 
|  | 2077 | if (!ConflictingDecls.empty()) { | 
| John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 2078 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2079 | ConflictingDecls.data(), | 
|  | 2080 | ConflictingDecls.size()); | 
|  | 2081 | } | 
|  | 2082 | } | 
|  | 2083 |  | 
|  | 2084 | // Create the "to" namespace, if needed. | 
|  | 2085 | NamespaceDecl *ToNamespace = MergeWithNamespace; | 
|  | 2086 | if (!ToNamespace) { | 
| Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 2087 | ToNamespace = NamespaceDecl::Create(Importer.getToContext(), DC, | 
|  | 2088 | Importer.Import(D->getLocStart()), | 
|  | 2089 | Loc, Name.getAsIdentifierInfo()); | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2090 | ToNamespace->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2091 | LexicalDC->addDeclInternal(ToNamespace); | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2092 |  | 
|  | 2093 | // If this is an anonymous namespace, register it as the anonymous | 
|  | 2094 | // namespace within its context. | 
|  | 2095 | if (!Name) { | 
|  | 2096 | if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(DC)) | 
|  | 2097 | TU->setAnonymousNamespace(ToNamespace); | 
|  | 2098 | else | 
|  | 2099 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); | 
|  | 2100 | } | 
|  | 2101 | } | 
|  | 2102 | Importer.Imported(D, ToNamespace); | 
|  | 2103 |  | 
|  | 2104 | ImportDeclContext(D); | 
|  | 2105 |  | 
|  | 2106 | return ToNamespace; | 
|  | 2107 | } | 
|  | 2108 |  | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2109 | Decl *ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2110 | // Import the major distinguishing characteristics of this typedef. | 
|  | 2111 | DeclContext *DC, *LexicalDC; | 
|  | 2112 | DeclarationName Name; | 
|  | 2113 | SourceLocation Loc; | 
|  | 2114 | if (ImportDeclParts(D, DC, LexicalDC, Name, Loc)) | 
|  | 2115 | return 0; | 
|  | 2116 |  | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2117 | // If this typedef is not in block scope, determine whether we've | 
|  | 2118 | // seen a typedef with the same name (that we can merge with) or any | 
|  | 2119 | // other entity by that name (which name lookup could conflict with). | 
|  | 2120 | if (!DC->isFunctionOrMethod()) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2121 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2122 | unsigned IDNS = Decl::IDNS_Ordinary; | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2123 | llvm::SmallVector<NamedDecl *, 2> FoundDecls; | 
|  | 2124 | DC->localUncachedLookup(Name, FoundDecls); | 
|  | 2125 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | 
|  | 2126 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2127 | continue; | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2128 | if (TypedefNameDecl *FoundTypedef = | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2129 | dyn_cast<TypedefNameDecl>(FoundDecls[I])) { | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2130 | if (Importer.IsStructurallyEquivalent(D->getUnderlyingType(), | 
|  | 2131 | FoundTypedef->getUnderlyingType())) | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2132 | return Importer.Imported(D, FoundTypedef); | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2133 | } | 
|  | 2134 |  | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2135 | ConflictingDecls.push_back(FoundDecls[I]); | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2136 | } | 
|  | 2137 |  | 
|  | 2138 | if (!ConflictingDecls.empty()) { | 
|  | 2139 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | 
|  | 2140 | ConflictingDecls.data(), | 
|  | 2141 | ConflictingDecls.size()); | 
|  | 2142 | if (!Name) | 
|  | 2143 | return 0; | 
|  | 2144 | } | 
|  | 2145 | } | 
|  | 2146 |  | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2147 | // Import the underlying type of this typedef; | 
|  | 2148 | QualType T = Importer.Import(D->getUnderlyingType()); | 
|  | 2149 | if (T.isNull()) | 
|  | 2150 | return 0; | 
|  | 2151 |  | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2152 | // Create the new typedef node. | 
|  | 2153 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); | 
| Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 2154 | SourceLocation StartL = Importer.Import(D->getLocStart()); | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2155 | TypedefNameDecl *ToTypedef; | 
|  | 2156 | if (IsAlias) | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2157 | ToTypedef = TypeAliasDecl::Create(Importer.getToContext(), DC, | 
|  | 2158 | StartL, Loc, | 
|  | 2159 | Name.getAsIdentifierInfo(), | 
|  | 2160 | TInfo); | 
|  | 2161 | else | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2162 | ToTypedef = TypedefDecl::Create(Importer.getToContext(), DC, | 
|  | 2163 | StartL, Loc, | 
|  | 2164 | Name.getAsIdentifierInfo(), | 
|  | 2165 | TInfo); | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2166 |  | 
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2167 | ToTypedef->setAccess(D->getAccess()); | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2168 | ToTypedef->setLexicalDeclContext(LexicalDC); | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2169 | Importer.Imported(D, ToTypedef); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2170 | LexicalDC->addDeclInternal(ToTypedef); | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2171 |  | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2172 | return ToTypedef; | 
|  | 2173 | } | 
|  | 2174 |  | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2175 | Decl *ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { | 
|  | 2176 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); | 
|  | 2177 | } | 
|  | 2178 |  | 
|  | 2179 | Decl *ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { | 
|  | 2180 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); | 
|  | 2181 | } | 
|  | 2182 |  | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2183 | Decl *ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { | 
|  | 2184 | // Import the major distinguishing characteristics of this enum. | 
|  | 2185 | DeclContext *DC, *LexicalDC; | 
|  | 2186 | DeclarationName Name; | 
|  | 2187 | SourceLocation Loc; | 
|  | 2188 | if (ImportDeclParts(D, DC, LexicalDC, Name, Loc)) | 
|  | 2189 | return 0; | 
|  | 2190 |  | 
|  | 2191 | // Figure out what enum name we're looking for. | 
|  | 2192 | unsigned IDNS = Decl::IDNS_Tag; | 
|  | 2193 | DeclarationName SearchName = Name; | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2194 | if (!SearchName && D->getTypedefNameForAnonDecl()) { | 
|  | 2195 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2196 | IDNS = Decl::IDNS_Ordinary; | 
|  | 2197 | } else if (Importer.getToContext().getLangOptions().CPlusPlus) | 
|  | 2198 | IDNS |= Decl::IDNS_Ordinary; | 
|  | 2199 |  | 
|  | 2200 | // We may already have an enum of the same name; try to find and match it. | 
|  | 2201 | if (!DC->isFunctionOrMethod() && SearchName) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2202 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2203 | llvm::SmallVector<NamedDecl *, 2> FoundDecls; | 
|  | 2204 | DC->localUncachedLookup(SearchName, FoundDecls); | 
|  | 2205 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | 
|  | 2206 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2207 | continue; | 
|  | 2208 |  | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2209 | Decl *Found = FoundDecls[I]; | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2210 | if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Found)) { | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2211 | if (const TagType *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) | 
|  | 2212 | Found = Tag->getDecl(); | 
|  | 2213 | } | 
|  | 2214 |  | 
|  | 2215 | if (EnumDecl *FoundEnum = dyn_cast<EnumDecl>(Found)) { | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2216 | if (IsStructuralMatch(D, FoundEnum)) | 
|  | 2217 | return Importer.Imported(D, FoundEnum); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2218 | } | 
|  | 2219 |  | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2220 | ConflictingDecls.push_back(FoundDecls[I]); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2221 | } | 
|  | 2222 |  | 
|  | 2223 | if (!ConflictingDecls.empty()) { | 
|  | 2224 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | 
|  | 2225 | ConflictingDecls.data(), | 
|  | 2226 | ConflictingDecls.size()); | 
|  | 2227 | } | 
|  | 2228 | } | 
|  | 2229 |  | 
|  | 2230 | // Create the enum declaration. | 
| Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 2231 | EnumDecl *D2 = EnumDecl::Create(Importer.getToContext(), DC, | 
|  | 2232 | Importer.Import(D->getLocStart()), | 
|  | 2233 | Loc, Name.getAsIdentifierInfo(), 0, | 
| Abramo Bagnara | 0e05e24 | 2010-12-03 18:54:17 +0000 | [diff] [blame] | 2234 | D->isScoped(), D->isScopedUsingClassTag(), | 
|  | 2235 | D->isFixed()); | 
| John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 2236 | // Import the qualifier, if any. | 
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2237 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); | 
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2238 | D2->setAccess(D->getAccess()); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2239 | D2->setLexicalDeclContext(LexicalDC); | 
|  | 2240 | Importer.Imported(D, D2); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2241 | LexicalDC->addDeclInternal(D2); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2242 |  | 
|  | 2243 | // Import the integer type. | 
|  | 2244 | QualType ToIntegerType = Importer.Import(D->getIntegerType()); | 
|  | 2245 | if (ToIntegerType.isNull()) | 
|  | 2246 | return 0; | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2247 | D2->setIntegerType(ToIntegerType); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2248 |  | 
|  | 2249 | // Import the definition | 
| John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 2250 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 2251 | return 0; | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2252 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2253 | return D2; | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2254 | } | 
|  | 2255 |  | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2256 | Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { | 
|  | 2257 | // If this record has a definition in the translation unit we're coming from, | 
|  | 2258 | // but this particular declaration is not that definition, import the | 
|  | 2259 | // definition and map to that. | 
| Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 2260 | TagDecl *Definition = D->getDefinition(); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2261 | if (Definition && Definition != D) { | 
|  | 2262 | Decl *ImportedDef = Importer.Import(Definition); | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2263 | if (!ImportedDef) | 
|  | 2264 | return 0; | 
|  | 2265 |  | 
|  | 2266 | return Importer.Imported(D, ImportedDef); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2267 | } | 
|  | 2268 |  | 
|  | 2269 | // Import the major distinguishing characteristics of this record. | 
|  | 2270 | DeclContext *DC, *LexicalDC; | 
|  | 2271 | DeclarationName Name; | 
|  | 2272 | SourceLocation Loc; | 
|  | 2273 | if (ImportDeclParts(D, DC, LexicalDC, Name, Loc)) | 
|  | 2274 | return 0; | 
|  | 2275 |  | 
|  | 2276 | // Figure out what structure name we're looking for. | 
|  | 2277 | unsigned IDNS = Decl::IDNS_Tag; | 
|  | 2278 | DeclarationName SearchName = Name; | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2279 | if (!SearchName && D->getTypedefNameForAnonDecl()) { | 
|  | 2280 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2281 | IDNS = Decl::IDNS_Ordinary; | 
|  | 2282 | } else if (Importer.getToContext().getLangOptions().CPlusPlus) | 
|  | 2283 | IDNS |= Decl::IDNS_Ordinary; | 
|  | 2284 |  | 
|  | 2285 | // We may already have a record of the same name; try to find and match it. | 
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2286 | RecordDecl *AdoptDecl = 0; | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2287 | if (!DC->isFunctionOrMethod() && SearchName) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2288 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2289 | llvm::SmallVector<NamedDecl *, 2> FoundDecls; | 
|  | 2290 | DC->localUncachedLookup(SearchName, FoundDecls); | 
|  | 2291 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | 
|  | 2292 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2293 | continue; | 
|  | 2294 |  | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2295 | Decl *Found = FoundDecls[I]; | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2296 | if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Found)) { | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2297 | if (const TagType *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) | 
|  | 2298 | Found = Tag->getDecl(); | 
|  | 2299 | } | 
|  | 2300 |  | 
|  | 2301 | if (RecordDecl *FoundRecord = dyn_cast<RecordDecl>(Found)) { | 
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2302 | if (RecordDecl *FoundDef = FoundRecord->getDefinition()) { | 
| John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 2303 | if (!D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) { | 
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2304 | // The record types structurally match, or the "from" translation | 
|  | 2305 | // unit only had a forward declaration anyway; call it the same | 
|  | 2306 | // function. | 
|  | 2307 | // FIXME: For C++, we should also merge methods here. | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2308 | return Importer.Imported(D, FoundDef); | 
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2309 | } | 
|  | 2310 | } else { | 
|  | 2311 | // We have a forward declaration of this type, so adopt that forward | 
|  | 2312 | // declaration rather than building a new one. | 
|  | 2313 | AdoptDecl = FoundRecord; | 
|  | 2314 | continue; | 
|  | 2315 | } | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2316 | } | 
|  | 2317 |  | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2318 | ConflictingDecls.push_back(FoundDecls[I]); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2319 | } | 
|  | 2320 |  | 
|  | 2321 | if (!ConflictingDecls.empty()) { | 
|  | 2322 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | 
|  | 2323 | ConflictingDecls.data(), | 
|  | 2324 | ConflictingDecls.size()); | 
|  | 2325 | } | 
|  | 2326 | } | 
|  | 2327 |  | 
|  | 2328 | // Create the record declaration. | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2329 | RecordDecl *D2 = AdoptDecl; | 
| Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 2330 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2331 | if (!D2) { | 
| John McCall | 1c70e99 | 2010-06-03 19:28:45 +0000 | [diff] [blame] | 2332 | if (isa<CXXRecordDecl>(D)) { | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2333 | CXXRecordDecl *D2CXX = CXXRecordDecl::Create(Importer.getToContext(), | 
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2334 | D->getTagKind(), | 
| Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 2335 | DC, StartLoc, Loc, | 
|  | 2336 | Name.getAsIdentifierInfo()); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2337 | D2 = D2CXX; | 
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2338 | D2->setAccess(D->getAccess()); | 
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2339 | } else { | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2340 | D2 = RecordDecl::Create(Importer.getToContext(), D->getTagKind(), | 
| Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 2341 | DC, StartLoc, Loc, Name.getAsIdentifierInfo()); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2342 | } | 
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2343 |  | 
|  | 2344 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2345 | D2->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2346 | LexicalDC->addDeclInternal(D2); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2347 | } | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2348 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2349 | Importer.Imported(D, D2); | 
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2350 |  | 
| John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 2351 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 2352 | return 0; | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2353 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2354 | return D2; | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2355 | } | 
|  | 2356 |  | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2357 | Decl *ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { | 
|  | 2358 | // Import the major distinguishing characteristics of this enumerator. | 
|  | 2359 | DeclContext *DC, *LexicalDC; | 
|  | 2360 | DeclarationName Name; | 
|  | 2361 | SourceLocation Loc; | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2362 | if (ImportDeclParts(D, DC, LexicalDC, Name, Loc)) | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2363 | return 0; | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2364 |  | 
|  | 2365 | QualType T = Importer.Import(D->getType()); | 
|  | 2366 | if (T.isNull()) | 
|  | 2367 | return 0; | 
|  | 2368 |  | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2369 | // Determine whether there are any other declarations with the same name and | 
|  | 2370 | // in the same context. | 
|  | 2371 | if (!LexicalDC->isFunctionOrMethod()) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2372 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2373 | unsigned IDNS = Decl::IDNS_Ordinary; | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2374 | llvm::SmallVector<NamedDecl *, 2> FoundDecls; | 
|  | 2375 | DC->localUncachedLookup(Name, FoundDecls); | 
|  | 2376 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | 
|  | 2377 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2378 | continue; | 
|  | 2379 |  | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2380 | ConflictingDecls.push_back(FoundDecls[I]); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2381 | } | 
|  | 2382 |  | 
|  | 2383 | if (!ConflictingDecls.empty()) { | 
|  | 2384 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | 
|  | 2385 | ConflictingDecls.data(), | 
|  | 2386 | ConflictingDecls.size()); | 
|  | 2387 | if (!Name) | 
|  | 2388 | return 0; | 
|  | 2389 | } | 
|  | 2390 | } | 
|  | 2391 |  | 
|  | 2392 | Expr *Init = Importer.Import(D->getInitExpr()); | 
|  | 2393 | if (D->getInitExpr() && !Init) | 
|  | 2394 | return 0; | 
|  | 2395 |  | 
|  | 2396 | EnumConstantDecl *ToEnumerator | 
|  | 2397 | = EnumConstantDecl::Create(Importer.getToContext(), cast<EnumDecl>(DC), Loc, | 
|  | 2398 | Name.getAsIdentifierInfo(), T, | 
|  | 2399 | Init, D->getInitVal()); | 
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2400 | ToEnumerator->setAccess(D->getAccess()); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2401 | ToEnumerator->setLexicalDeclContext(LexicalDC); | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2402 | Importer.Imported(D, ToEnumerator); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2403 | LexicalDC->addDeclInternal(ToEnumerator); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2404 | return ToEnumerator; | 
|  | 2405 | } | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2406 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2407 | Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { | 
|  | 2408 | // Import the major distinguishing characteristics of this function. | 
|  | 2409 | DeclContext *DC, *LexicalDC; | 
|  | 2410 | DeclarationName Name; | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2411 | SourceLocation Loc; | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2412 | if (ImportDeclParts(D, DC, LexicalDC, Name, Loc)) | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2413 | return 0; | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2414 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2415 | // Try to find a function in our own ("to") context with the same name, same | 
|  | 2416 | // type, and in the same context as the function we're importing. | 
|  | 2417 | if (!LexicalDC->isFunctionOrMethod()) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2418 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2419 | unsigned IDNS = Decl::IDNS_Ordinary; | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2420 | llvm::SmallVector<NamedDecl *, 2> FoundDecls; | 
|  | 2421 | DC->localUncachedLookup(Name, FoundDecls); | 
|  | 2422 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | 
|  | 2423 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2424 | continue; | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2425 |  | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2426 | if (FunctionDecl *FoundFunction = dyn_cast<FunctionDecl>(FoundDecls[I])) { | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2427 | if (isExternalLinkage(FoundFunction->getLinkage()) && | 
|  | 2428 | isExternalLinkage(D->getLinkage())) { | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2429 | if (Importer.IsStructurallyEquivalent(D->getType(), | 
|  | 2430 | FoundFunction->getType())) { | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2431 | // FIXME: Actually try to merge the body and other attributes. | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2432 | return Importer.Imported(D, FoundFunction); | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2433 | } | 
|  | 2434 |  | 
|  | 2435 | // FIXME: Check for overloading more carefully, e.g., by boosting | 
|  | 2436 | // Sema::IsOverload out to the AST library. | 
|  | 2437 |  | 
|  | 2438 | // Function overloading is okay in C++. | 
|  | 2439 | if (Importer.getToContext().getLangOptions().CPlusPlus) | 
|  | 2440 | continue; | 
|  | 2441 |  | 
|  | 2442 | // Complain about inconsistent function types. | 
|  | 2443 | Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent) | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2444 | << Name << D->getType() << FoundFunction->getType(); | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2445 | Importer.ToDiag(FoundFunction->getLocation(), | 
|  | 2446 | diag::note_odr_value_here) | 
|  | 2447 | << FoundFunction->getType(); | 
|  | 2448 | } | 
|  | 2449 | } | 
|  | 2450 |  | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2451 | ConflictingDecls.push_back(FoundDecls[I]); | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2452 | } | 
|  | 2453 |  | 
|  | 2454 | if (!ConflictingDecls.empty()) { | 
|  | 2455 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | 
|  | 2456 | ConflictingDecls.data(), | 
|  | 2457 | ConflictingDecls.size()); | 
|  | 2458 | if (!Name) | 
|  | 2459 | return 0; | 
|  | 2460 | } | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2461 | } | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2462 |  | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2463 | DeclarationNameInfo NameInfo(Name, Loc); | 
|  | 2464 | // Import additional name location/type info. | 
|  | 2465 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); | 
|  | 2466 |  | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2467 | // Import the type. | 
|  | 2468 | QualType T = Importer.Import(D->getType()); | 
|  | 2469 | if (T.isNull()) | 
|  | 2470 | return 0; | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2471 |  | 
|  | 2472 | // Import the function parameters. | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2473 | SmallVector<ParmVarDecl *, 8> Parameters; | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2474 | for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end(); | 
|  | 2475 | P != PEnd; ++P) { | 
|  | 2476 | ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(*P)); | 
|  | 2477 | if (!ToP) | 
|  | 2478 | return 0; | 
|  | 2479 |  | 
|  | 2480 | Parameters.push_back(ToP); | 
|  | 2481 | } | 
|  | 2482 |  | 
|  | 2483 | // Create the imported function. | 
|  | 2484 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2485 | FunctionDecl *ToFunction = 0; | 
|  | 2486 | if (CXXConstructorDecl *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { | 
|  | 2487 | ToFunction = CXXConstructorDecl::Create(Importer.getToContext(), | 
|  | 2488 | cast<CXXRecordDecl>(DC), | 
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2489 | D->getInnerLocStart(), | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2490 | NameInfo, T, TInfo, | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2491 | FromConstructor->isExplicit(), | 
|  | 2492 | D->isInlineSpecified(), | 
| Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2493 | D->isImplicit(), | 
|  | 2494 | D->isConstexpr()); | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2495 | } else if (isa<CXXDestructorDecl>(D)) { | 
|  | 2496 | ToFunction = CXXDestructorDecl::Create(Importer.getToContext(), | 
|  | 2497 | cast<CXXRecordDecl>(DC), | 
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2498 | D->getInnerLocStart(), | 
| Craig Silverstein | af8808d | 2010-10-21 00:44:50 +0000 | [diff] [blame] | 2499 | NameInfo, T, TInfo, | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2500 | D->isInlineSpecified(), | 
|  | 2501 | D->isImplicit()); | 
|  | 2502 | } else if (CXXConversionDecl *FromConversion | 
|  | 2503 | = dyn_cast<CXXConversionDecl>(D)) { | 
|  | 2504 | ToFunction = CXXConversionDecl::Create(Importer.getToContext(), | 
|  | 2505 | cast<CXXRecordDecl>(DC), | 
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2506 | D->getInnerLocStart(), | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2507 | NameInfo, T, TInfo, | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2508 | D->isInlineSpecified(), | 
| Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2509 | FromConversion->isExplicit(), | 
| Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2510 | D->isConstexpr(), | 
| Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2511 | Importer.Import(D->getLocEnd())); | 
| Douglas Gregor | a50ad13 | 2010-11-29 16:04:58 +0000 | [diff] [blame] | 2512 | } else if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { | 
|  | 2513 | ToFunction = CXXMethodDecl::Create(Importer.getToContext(), | 
|  | 2514 | cast<CXXRecordDecl>(DC), | 
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2515 | D->getInnerLocStart(), | 
| Douglas Gregor | a50ad13 | 2010-11-29 16:04:58 +0000 | [diff] [blame] | 2516 | NameInfo, T, TInfo, | 
|  | 2517 | Method->isStatic(), | 
|  | 2518 | Method->getStorageClassAsWritten(), | 
| Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2519 | Method->isInlineSpecified(), | 
| Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2520 | D->isConstexpr(), | 
| Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2521 | Importer.Import(D->getLocEnd())); | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2522 | } else { | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2523 | ToFunction = FunctionDecl::Create(Importer.getToContext(), DC, | 
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2524 | D->getInnerLocStart(), | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2525 | NameInfo, T, TInfo, D->getStorageClass(), | 
| Douglas Gregor | c4df407 | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 2526 | D->getStorageClassAsWritten(), | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2527 | D->isInlineSpecified(), | 
| Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2528 | D->hasWrittenPrototype(), | 
|  | 2529 | D->isConstexpr()); | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2530 | } | 
| John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 2531 |  | 
|  | 2532 | // Import the qualifier, if any. | 
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2533 | ToFunction->setQualifierInfo(Importer.Import(D->getQualifierLoc())); | 
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2534 | ToFunction->setAccess(D->getAccess()); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2535 | ToFunction->setLexicalDeclContext(LexicalDC); | 
| John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 2536 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); | 
|  | 2537 | ToFunction->setTrivial(D->isTrivial()); | 
|  | 2538 | ToFunction->setPure(D->isPure()); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2539 | Importer.Imported(D, ToFunction); | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2540 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2541 | // Set the parameters. | 
|  | 2542 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) { | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2543 | Parameters[I]->setOwningFunction(ToFunction); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2544 | ToFunction->addDeclInternal(Parameters[I]); | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2545 | } | 
| David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 2546 | ToFunction->setParams(Parameters); | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2547 |  | 
|  | 2548 | // FIXME: Other bits to merge? | 
| Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2549 |  | 
|  | 2550 | // Add this function to the lexical context. | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2551 | LexicalDC->addDeclInternal(ToFunction); | 
| Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2552 |  | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2553 | return ToFunction; | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2554 | } | 
|  | 2555 |  | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2556 | Decl *ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { | 
|  | 2557 | return VisitFunctionDecl(D); | 
|  | 2558 | } | 
|  | 2559 |  | 
|  | 2560 | Decl *ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { | 
|  | 2561 | return VisitCXXMethodDecl(D); | 
|  | 2562 | } | 
|  | 2563 |  | 
|  | 2564 | Decl *ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { | 
|  | 2565 | return VisitCXXMethodDecl(D); | 
|  | 2566 | } | 
|  | 2567 |  | 
|  | 2568 | Decl *ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { | 
|  | 2569 | return VisitCXXMethodDecl(D); | 
|  | 2570 | } | 
|  | 2571 |  | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2572 | Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { | 
|  | 2573 | // Import the major distinguishing characteristics of a variable. | 
|  | 2574 | DeclContext *DC, *LexicalDC; | 
|  | 2575 | DeclarationName Name; | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2576 | SourceLocation Loc; | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2577 | if (ImportDeclParts(D, DC, LexicalDC, Name, Loc)) | 
|  | 2578 | return 0; | 
|  | 2579 |  | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2580 | // Determine whether we've already imported this field. | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2581 | llvm::SmallVector<NamedDecl *, 2> FoundDecls; | 
|  | 2582 | DC->localUncachedLookup(Name, FoundDecls); | 
|  | 2583 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | 
|  | 2584 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecls[I])) { | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2585 | if (Importer.IsStructurallyEquivalent(D->getType(), | 
|  | 2586 | FoundField->getType())) { | 
|  | 2587 | Importer.Imported(D, FoundField); | 
|  | 2588 | return FoundField; | 
|  | 2589 | } | 
|  | 2590 |  | 
|  | 2591 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) | 
|  | 2592 | << Name << D->getType() << FoundField->getType(); | 
|  | 2593 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) | 
|  | 2594 | << FoundField->getType(); | 
|  | 2595 | return 0; | 
|  | 2596 | } | 
|  | 2597 | } | 
|  | 2598 |  | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2599 | // Import the type. | 
|  | 2600 | QualType T = Importer.Import(D->getType()); | 
|  | 2601 | if (T.isNull()) | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2602 | return 0; | 
|  | 2603 |  | 
|  | 2604 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); | 
|  | 2605 | Expr *BitWidth = Importer.Import(D->getBitWidth()); | 
|  | 2606 | if (!BitWidth && D->getBitWidth()) | 
|  | 2607 | return 0; | 
|  | 2608 |  | 
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2609 | FieldDecl *ToField = FieldDecl::Create(Importer.getToContext(), DC, | 
|  | 2610 | Importer.Import(D->getInnerLocStart()), | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2611 | Loc, Name.getAsIdentifierInfo(), | 
| Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2612 | T, TInfo, BitWidth, D->isMutable(), | 
|  | 2613 | D->hasInClassInitializer()); | 
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2614 | ToField->setAccess(D->getAccess()); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2615 | ToField->setLexicalDeclContext(LexicalDC); | 
| Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2616 | if (ToField->hasInClassInitializer()) | 
|  | 2617 | ToField->setInClassInitializer(D->getInClassInitializer()); | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2618 | Importer.Imported(D, ToField); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2619 | LexicalDC->addDeclInternal(ToField); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2620 | return ToField; | 
|  | 2621 | } | 
|  | 2622 |  | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2623 | Decl *ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { | 
|  | 2624 | // Import the major distinguishing characteristics of a variable. | 
|  | 2625 | DeclContext *DC, *LexicalDC; | 
|  | 2626 | DeclarationName Name; | 
|  | 2627 | SourceLocation Loc; | 
|  | 2628 | if (ImportDeclParts(D, DC, LexicalDC, Name, Loc)) | 
|  | 2629 | return 0; | 
|  | 2630 |  | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2631 | // Determine whether we've already imported this field. | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2632 | llvm::SmallVector<NamedDecl *, 2> FoundDecls; | 
|  | 2633 | DC->localUncachedLookup(Name, FoundDecls); | 
|  | 2634 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2635 | if (IndirectFieldDecl *FoundField | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2636 | = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2637 | if (Importer.IsStructurallyEquivalent(D->getType(), | 
|  | 2638 | FoundField->getType())) { | 
|  | 2639 | Importer.Imported(D, FoundField); | 
|  | 2640 | return FoundField; | 
|  | 2641 | } | 
|  | 2642 |  | 
|  | 2643 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) | 
|  | 2644 | << Name << D->getType() << FoundField->getType(); | 
|  | 2645 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) | 
|  | 2646 | << FoundField->getType(); | 
|  | 2647 | return 0; | 
|  | 2648 | } | 
|  | 2649 | } | 
|  | 2650 |  | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2651 | // Import the type. | 
|  | 2652 | QualType T = Importer.Import(D->getType()); | 
|  | 2653 | if (T.isNull()) | 
|  | 2654 | return 0; | 
|  | 2655 |  | 
|  | 2656 | NamedDecl **NamedChain = | 
|  | 2657 | new (Importer.getToContext())NamedDecl*[D->getChainingSize()]; | 
|  | 2658 |  | 
|  | 2659 | unsigned i = 0; | 
|  | 2660 | for (IndirectFieldDecl::chain_iterator PI = D->chain_begin(), | 
|  | 2661 | PE = D->chain_end(); PI != PE; ++PI) { | 
|  | 2662 | Decl* D = Importer.Import(*PI); | 
|  | 2663 | if (!D) | 
|  | 2664 | return 0; | 
|  | 2665 | NamedChain[i++] = cast<NamedDecl>(D); | 
|  | 2666 | } | 
|  | 2667 |  | 
|  | 2668 | IndirectFieldDecl *ToIndirectField = IndirectFieldDecl::Create( | 
|  | 2669 | Importer.getToContext(), DC, | 
|  | 2670 | Loc, Name.getAsIdentifierInfo(), T, | 
|  | 2671 | NamedChain, D->getChainingSize()); | 
|  | 2672 | ToIndirectField->setAccess(D->getAccess()); | 
|  | 2673 | ToIndirectField->setLexicalDeclContext(LexicalDC); | 
|  | 2674 | Importer.Imported(D, ToIndirectField); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2675 | LexicalDC->addDeclInternal(ToIndirectField); | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2676 | return ToIndirectField; | 
|  | 2677 | } | 
|  | 2678 |  | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2679 | Decl *ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { | 
|  | 2680 | // Import the major distinguishing characteristics of an ivar. | 
|  | 2681 | DeclContext *DC, *LexicalDC; | 
|  | 2682 | DeclarationName Name; | 
|  | 2683 | SourceLocation Loc; | 
|  | 2684 | if (ImportDeclParts(D, DC, LexicalDC, Name, Loc)) | 
|  | 2685 | return 0; | 
|  | 2686 |  | 
|  | 2687 | // Determine whether we've already imported this ivar | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2688 | llvm::SmallVector<NamedDecl *, 2> FoundDecls; | 
|  | 2689 | DC->localUncachedLookup(Name, FoundDecls); | 
|  | 2690 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | 
|  | 2691 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecls[I])) { | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2692 | if (Importer.IsStructurallyEquivalent(D->getType(), | 
|  | 2693 | FoundIvar->getType())) { | 
|  | 2694 | Importer.Imported(D, FoundIvar); | 
|  | 2695 | return FoundIvar; | 
|  | 2696 | } | 
|  | 2697 |  | 
|  | 2698 | Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent) | 
|  | 2699 | << Name << D->getType() << FoundIvar->getType(); | 
|  | 2700 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) | 
|  | 2701 | << FoundIvar->getType(); | 
|  | 2702 | return 0; | 
|  | 2703 | } | 
|  | 2704 | } | 
|  | 2705 |  | 
|  | 2706 | // Import the type. | 
|  | 2707 | QualType T = Importer.Import(D->getType()); | 
|  | 2708 | if (T.isNull()) | 
|  | 2709 | return 0; | 
|  | 2710 |  | 
|  | 2711 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); | 
|  | 2712 | Expr *BitWidth = Importer.Import(D->getBitWidth()); | 
|  | 2713 | if (!BitWidth && D->getBitWidth()) | 
|  | 2714 | return 0; | 
|  | 2715 |  | 
| Daniel Dunbar | fe3ead7 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 2716 | ObjCIvarDecl *ToIvar = ObjCIvarDecl::Create(Importer.getToContext(), | 
|  | 2717 | cast<ObjCContainerDecl>(DC), | 
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2718 | Importer.Import(D->getInnerLocStart()), | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2719 | Loc, Name.getAsIdentifierInfo(), | 
|  | 2720 | T, TInfo, D->getAccessControl(), | 
| Fariborz Jahanian | aea8e1e | 2010-07-17 18:35:47 +0000 | [diff] [blame] | 2721 | BitWidth, D->getSynthesize()); | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2722 | ToIvar->setLexicalDeclContext(LexicalDC); | 
|  | 2723 | Importer.Imported(D, ToIvar); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2724 | LexicalDC->addDeclInternal(ToIvar); | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2725 | return ToIvar; | 
|  | 2726 |  | 
|  | 2727 | } | 
|  | 2728 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2729 | Decl *ASTNodeImporter::VisitVarDecl(VarDecl *D) { | 
|  | 2730 | // Import the major distinguishing characteristics of a variable. | 
|  | 2731 | DeclContext *DC, *LexicalDC; | 
|  | 2732 | DeclarationName Name; | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2733 | SourceLocation Loc; | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2734 | if (ImportDeclParts(D, DC, LexicalDC, Name, Loc)) | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2735 | return 0; | 
|  | 2736 |  | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2737 | // Try to find a variable in our own ("to") context with the same name and | 
|  | 2738 | // in the same context as the variable we're importing. | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2739 | if (D->isFileVarDecl()) { | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2740 | VarDecl *MergeWithVar = 0; | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2741 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2742 | unsigned IDNS = Decl::IDNS_Ordinary; | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2743 | llvm::SmallVector<NamedDecl *, 2> FoundDecls; | 
|  | 2744 | DC->localUncachedLookup(Name, FoundDecls); | 
|  | 2745 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | 
|  | 2746 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2747 | continue; | 
|  | 2748 |  | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2749 | if (VarDecl *FoundVar = dyn_cast<VarDecl>(FoundDecls[I])) { | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2750 | // We have found a variable that we may need to merge with. Check it. | 
|  | 2751 | if (isExternalLinkage(FoundVar->getLinkage()) && | 
|  | 2752 | isExternalLinkage(D->getLinkage())) { | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2753 | if (Importer.IsStructurallyEquivalent(D->getType(), | 
|  | 2754 | FoundVar->getType())) { | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2755 | MergeWithVar = FoundVar; | 
|  | 2756 | break; | 
|  | 2757 | } | 
|  | 2758 |  | 
| Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2759 | const ArrayType *FoundArray | 
|  | 2760 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); | 
|  | 2761 | const ArrayType *TArray | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2762 | = Importer.getToContext().getAsArrayType(D->getType()); | 
| Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2763 | if (FoundArray && TArray) { | 
|  | 2764 | if (isa<IncompleteArrayType>(FoundArray) && | 
|  | 2765 | isa<ConstantArrayType>(TArray)) { | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2766 | // Import the type. | 
|  | 2767 | QualType T = Importer.Import(D->getType()); | 
|  | 2768 | if (T.isNull()) | 
|  | 2769 | return 0; | 
|  | 2770 |  | 
| Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2771 | FoundVar->setType(T); | 
|  | 2772 | MergeWithVar = FoundVar; | 
|  | 2773 | break; | 
|  | 2774 | } else if (isa<IncompleteArrayType>(TArray) && | 
|  | 2775 | isa<ConstantArrayType>(FoundArray)) { | 
|  | 2776 | MergeWithVar = FoundVar; | 
|  | 2777 | break; | 
| Douglas Gregor | 2fbe558 | 2010-02-10 17:16:49 +0000 | [diff] [blame] | 2778 | } | 
|  | 2779 | } | 
|  | 2780 |  | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2781 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2782 | << Name << D->getType() << FoundVar->getType(); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2783 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) | 
|  | 2784 | << FoundVar->getType(); | 
|  | 2785 | } | 
|  | 2786 | } | 
|  | 2787 |  | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2788 | ConflictingDecls.push_back(FoundDecls[I]); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2789 | } | 
|  | 2790 |  | 
|  | 2791 | if (MergeWithVar) { | 
|  | 2792 | // An equivalent variable with external linkage has been found. Link | 
|  | 2793 | // the two declarations, then merge them. | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2794 | Importer.Imported(D, MergeWithVar); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2795 |  | 
|  | 2796 | if (VarDecl *DDef = D->getDefinition()) { | 
|  | 2797 | if (VarDecl *ExistingDef = MergeWithVar->getDefinition()) { | 
|  | 2798 | Importer.ToDiag(ExistingDef->getLocation(), | 
|  | 2799 | diag::err_odr_variable_multiple_def) | 
|  | 2800 | << Name; | 
|  | 2801 | Importer.FromDiag(DDef->getLocation(), diag::note_odr_defined_here); | 
|  | 2802 | } else { | 
|  | 2803 | Expr *Init = Importer.Import(DDef->getInit()); | 
| Douglas Gregor | d505812 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 2804 | MergeWithVar->setInit(Init); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2805 | } | 
|  | 2806 | } | 
|  | 2807 |  | 
|  | 2808 | return MergeWithVar; | 
|  | 2809 | } | 
|  | 2810 |  | 
|  | 2811 | if (!ConflictingDecls.empty()) { | 
|  | 2812 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | 
|  | 2813 | ConflictingDecls.data(), | 
|  | 2814 | ConflictingDecls.size()); | 
|  | 2815 | if (!Name) | 
|  | 2816 | return 0; | 
|  | 2817 | } | 
|  | 2818 | } | 
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2819 |  | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2820 | // Import the type. | 
|  | 2821 | QualType T = Importer.Import(D->getType()); | 
|  | 2822 | if (T.isNull()) | 
|  | 2823 | return 0; | 
|  | 2824 |  | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2825 | // Create the imported variable. | 
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2826 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); | 
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2827 | VarDecl *ToVar = VarDecl::Create(Importer.getToContext(), DC, | 
|  | 2828 | Importer.Import(D->getInnerLocStart()), | 
|  | 2829 | Loc, Name.getAsIdentifierInfo(), | 
|  | 2830 | T, TInfo, | 
| Douglas Gregor | c4df407 | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 2831 | D->getStorageClass(), | 
|  | 2832 | D->getStorageClassAsWritten()); | 
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2833 | ToVar->setQualifierInfo(Importer.Import(D->getQualifierLoc())); | 
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2834 | ToVar->setAccess(D->getAccess()); | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2835 | ToVar->setLexicalDeclContext(LexicalDC); | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2836 | Importer.Imported(D, ToVar); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2837 | LexicalDC->addDeclInternal(ToVar); | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2838 |  | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2839 | // Merge the initializer. | 
|  | 2840 | // FIXME: Can we really import any initializer? Alternatively, we could force | 
|  | 2841 | // ourselves to import every declaration of a variable and then only use | 
|  | 2842 | // getInit() here. | 
| Douglas Gregor | d505812 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 2843 | ToVar->setInit(Importer.Import(const_cast<Expr *>(D->getAnyInitializer()))); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2844 |  | 
|  | 2845 | // FIXME: Other bits to merge? | 
|  | 2846 |  | 
|  | 2847 | return ToVar; | 
|  | 2848 | } | 
|  | 2849 |  | 
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2850 | Decl *ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { | 
|  | 2851 | // Parameters are created in the translation unit's context, then moved | 
|  | 2852 | // into the function declaration's context afterward. | 
|  | 2853 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); | 
|  | 2854 |  | 
|  | 2855 | // Import the name of this declaration. | 
|  | 2856 | DeclarationName Name = Importer.Import(D->getDeclName()); | 
|  | 2857 | if (D->getDeclName() && !Name) | 
|  | 2858 | return 0; | 
|  | 2859 |  | 
|  | 2860 | // Import the location of this declaration. | 
|  | 2861 | SourceLocation Loc = Importer.Import(D->getLocation()); | 
|  | 2862 |  | 
|  | 2863 | // Import the parameter's type. | 
|  | 2864 | QualType T = Importer.Import(D->getType()); | 
|  | 2865 | if (T.isNull()) | 
|  | 2866 | return 0; | 
|  | 2867 |  | 
|  | 2868 | // Create the imported parameter. | 
|  | 2869 | ImplicitParamDecl *ToParm | 
|  | 2870 | = ImplicitParamDecl::Create(Importer.getToContext(), DC, | 
|  | 2871 | Loc, Name.getAsIdentifierInfo(), | 
|  | 2872 | T); | 
|  | 2873 | return Importer.Imported(D, ToParm); | 
|  | 2874 | } | 
|  | 2875 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2876 | Decl *ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { | 
|  | 2877 | // Parameters are created in the translation unit's context, then moved | 
|  | 2878 | // into the function declaration's context afterward. | 
|  | 2879 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); | 
|  | 2880 |  | 
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2881 | // Import the name of this declaration. | 
|  | 2882 | DeclarationName Name = Importer.Import(D->getDeclName()); | 
|  | 2883 | if (D->getDeclName() && !Name) | 
|  | 2884 | return 0; | 
|  | 2885 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2886 | // Import the location of this declaration. | 
|  | 2887 | SourceLocation Loc = Importer.Import(D->getLocation()); | 
|  | 2888 |  | 
|  | 2889 | // Import the parameter's type. | 
|  | 2890 | QualType T = Importer.Import(D->getType()); | 
|  | 2891 | if (T.isNull()) | 
|  | 2892 | return 0; | 
|  | 2893 |  | 
|  | 2894 | // Create the imported parameter. | 
|  | 2895 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); | 
|  | 2896 | ParmVarDecl *ToParm = ParmVarDecl::Create(Importer.getToContext(), DC, | 
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2897 | Importer.Import(D->getInnerLocStart()), | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2898 | Loc, Name.getAsIdentifierInfo(), | 
|  | 2899 | T, TInfo, D->getStorageClass(), | 
| Douglas Gregor | c4df407 | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 2900 | D->getStorageClassAsWritten(), | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2901 | /*FIXME: Default argument*/ 0); | 
| John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 2902 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2903 | return Importer.Imported(D, ToParm); | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2904 | } | 
|  | 2905 |  | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2906 | Decl *ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { | 
|  | 2907 | // Import the major distinguishing characteristics of a method. | 
|  | 2908 | DeclContext *DC, *LexicalDC; | 
|  | 2909 | DeclarationName Name; | 
|  | 2910 | SourceLocation Loc; | 
|  | 2911 | if (ImportDeclParts(D, DC, LexicalDC, Name, Loc)) | 
|  | 2912 | return 0; | 
|  | 2913 |  | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2914 | llvm::SmallVector<NamedDecl *, 2> FoundDecls; | 
|  | 2915 | DC->localUncachedLookup(Name, FoundDecls); | 
|  | 2916 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | 
|  | 2917 | if (ObjCMethodDecl *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecls[I])) { | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2918 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) | 
|  | 2919 | continue; | 
|  | 2920 |  | 
|  | 2921 | // Check return types. | 
|  | 2922 | if (!Importer.IsStructurallyEquivalent(D->getResultType(), | 
|  | 2923 | FoundMethod->getResultType())) { | 
|  | 2924 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) | 
|  | 2925 | << D->isInstanceMethod() << Name | 
|  | 2926 | << D->getResultType() << FoundMethod->getResultType(); | 
|  | 2927 | Importer.ToDiag(FoundMethod->getLocation(), | 
|  | 2928 | diag::note_odr_objc_method_here) | 
|  | 2929 | << D->isInstanceMethod() << Name; | 
|  | 2930 | return 0; | 
|  | 2931 | } | 
|  | 2932 |  | 
|  | 2933 | // Check the number of parameters. | 
|  | 2934 | if (D->param_size() != FoundMethod->param_size()) { | 
|  | 2935 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) | 
|  | 2936 | << D->isInstanceMethod() << Name | 
|  | 2937 | << D->param_size() << FoundMethod->param_size(); | 
|  | 2938 | Importer.ToDiag(FoundMethod->getLocation(), | 
|  | 2939 | diag::note_odr_objc_method_here) | 
|  | 2940 | << D->isInstanceMethod() << Name; | 
|  | 2941 | return 0; | 
|  | 2942 | } | 
|  | 2943 |  | 
|  | 2944 | // Check parameter types. | 
|  | 2945 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), | 
|  | 2946 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); | 
|  | 2947 | P != PEnd; ++P, ++FoundP) { | 
|  | 2948 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), | 
|  | 2949 | (*FoundP)->getType())) { | 
|  | 2950 | Importer.FromDiag((*P)->getLocation(), | 
|  | 2951 | diag::err_odr_objc_method_param_type_inconsistent) | 
|  | 2952 | << D->isInstanceMethod() << Name | 
|  | 2953 | << (*P)->getType() << (*FoundP)->getType(); | 
|  | 2954 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) | 
|  | 2955 | << (*FoundP)->getType(); | 
|  | 2956 | return 0; | 
|  | 2957 | } | 
|  | 2958 | } | 
|  | 2959 |  | 
|  | 2960 | // Check variadic/non-variadic. | 
|  | 2961 | // Check the number of parameters. | 
|  | 2962 | if (D->isVariadic() != FoundMethod->isVariadic()) { | 
|  | 2963 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) | 
|  | 2964 | << D->isInstanceMethod() << Name; | 
|  | 2965 | Importer.ToDiag(FoundMethod->getLocation(), | 
|  | 2966 | diag::note_odr_objc_method_here) | 
|  | 2967 | << D->isInstanceMethod() << Name; | 
|  | 2968 | return 0; | 
|  | 2969 | } | 
|  | 2970 |  | 
|  | 2971 | // FIXME: Any other bits we need to merge? | 
|  | 2972 | return Importer.Imported(D, FoundMethod); | 
|  | 2973 | } | 
|  | 2974 | } | 
|  | 2975 |  | 
|  | 2976 | // Import the result type. | 
|  | 2977 | QualType ResultTy = Importer.Import(D->getResultType()); | 
|  | 2978 | if (ResultTy.isNull()) | 
|  | 2979 | return 0; | 
|  | 2980 |  | 
| Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 2981 | TypeSourceInfo *ResultTInfo = Importer.Import(D->getResultTypeSourceInfo()); | 
|  | 2982 |  | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2983 | ObjCMethodDecl *ToMethod | 
|  | 2984 | = ObjCMethodDecl::Create(Importer.getToContext(), | 
|  | 2985 | Loc, | 
|  | 2986 | Importer.Import(D->getLocEnd()), | 
|  | 2987 | Name.getObjCSelector(), | 
| Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 2988 | ResultTy, ResultTInfo, DC, | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2989 | D->isInstanceMethod(), | 
|  | 2990 | D->isVariadic(), | 
|  | 2991 | D->isSynthesized(), | 
| Argyrios Kyrtzidis | 004df6e | 2011-08-17 19:25:08 +0000 | [diff] [blame] | 2992 | D->isImplicit(), | 
| Fariborz Jahanian | 6e7e8cc | 2010-07-22 18:24:20 +0000 | [diff] [blame] | 2993 | D->isDefined(), | 
| Douglas Gregor | 3382372 | 2011-06-11 01:09:30 +0000 | [diff] [blame] | 2994 | D->getImplementationControl(), | 
|  | 2995 | D->hasRelatedResultType()); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2996 |  | 
|  | 2997 | // FIXME: When we decide to merge method definitions, we'll need to | 
|  | 2998 | // deal with implicit parameters. | 
|  | 2999 |  | 
|  | 3000 | // Import the parameters | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3001 | SmallVector<ParmVarDecl *, 5> ToParams; | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3002 | for (ObjCMethodDecl::param_iterator FromP = D->param_begin(), | 
|  | 3003 | FromPEnd = D->param_end(); | 
|  | 3004 | FromP != FromPEnd; | 
|  | 3005 | ++FromP) { | 
|  | 3006 | ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(*FromP)); | 
|  | 3007 | if (!ToP) | 
|  | 3008 | return 0; | 
|  | 3009 |  | 
|  | 3010 | ToParams.push_back(ToP); | 
|  | 3011 | } | 
|  | 3012 |  | 
|  | 3013 | // Set the parameters. | 
|  | 3014 | for (unsigned I = 0, N = ToParams.size(); I != N; ++I) { | 
|  | 3015 | ToParams[I]->setOwningFunction(ToMethod); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3016 | ToMethod->addDeclInternal(ToParams[I]); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3017 | } | 
| Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 3018 | SmallVector<SourceLocation, 12> SelLocs; | 
|  | 3019 | D->getSelectorLocs(SelLocs); | 
|  | 3020 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, SelLocs); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3021 |  | 
|  | 3022 | ToMethod->setLexicalDeclContext(LexicalDC); | 
|  | 3023 | Importer.Imported(D, ToMethod); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3024 | LexicalDC->addDeclInternal(ToMethod); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3025 | return ToMethod; | 
|  | 3026 | } | 
|  | 3027 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3028 | Decl *ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { | 
|  | 3029 | // Import the major distinguishing characteristics of a category. | 
|  | 3030 | DeclContext *DC, *LexicalDC; | 
|  | 3031 | DeclarationName Name; | 
|  | 3032 | SourceLocation Loc; | 
|  | 3033 | if (ImportDeclParts(D, DC, LexicalDC, Name, Loc)) | 
|  | 3034 | return 0; | 
|  | 3035 |  | 
|  | 3036 | ObjCInterfaceDecl *ToInterface | 
|  | 3037 | = cast_or_null<ObjCInterfaceDecl>(Importer.Import(D->getClassInterface())); | 
|  | 3038 | if (!ToInterface) | 
|  | 3039 | return 0; | 
|  | 3040 |  | 
|  | 3041 | // Determine if we've already encountered this category. | 
|  | 3042 | ObjCCategoryDecl *MergeWithCategory | 
|  | 3043 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); | 
|  | 3044 | ObjCCategoryDecl *ToCategory = MergeWithCategory; | 
|  | 3045 | if (!ToCategory) { | 
|  | 3046 | ToCategory = ObjCCategoryDecl::Create(Importer.getToContext(), DC, | 
| Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3047 | Importer.Import(D->getAtStartLoc()), | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3048 | Loc, | 
|  | 3049 | Importer.Import(D->getCategoryNameLoc()), | 
| Argyrios Kyrtzidis | 3a5094b | 2011-08-30 19:43:26 +0000 | [diff] [blame] | 3050 | Name.getAsIdentifierInfo(), | 
|  | 3051 | ToInterface); | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3052 | ToCategory->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3053 | LexicalDC->addDeclInternal(ToCategory); | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3054 | Importer.Imported(D, ToCategory); | 
|  | 3055 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3056 | // Import protocols | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3057 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | 
|  | 3058 | SmallVector<SourceLocation, 4> ProtocolLocs; | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3059 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc | 
|  | 3060 | = D->protocol_loc_begin(); | 
|  | 3061 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), | 
|  | 3062 | FromProtoEnd = D->protocol_end(); | 
|  | 3063 | FromProto != FromProtoEnd; | 
|  | 3064 | ++FromProto, ++FromProtoLoc) { | 
|  | 3065 | ObjCProtocolDecl *ToProto | 
|  | 3066 | = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); | 
|  | 3067 | if (!ToProto) | 
|  | 3068 | return 0; | 
|  | 3069 | Protocols.push_back(ToProto); | 
|  | 3070 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); | 
|  | 3071 | } | 
|  | 3072 |  | 
|  | 3073 | // FIXME: If we're merging, make sure that the protocol list is the same. | 
|  | 3074 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), | 
|  | 3075 | ProtocolLocs.data(), Importer.getToContext()); | 
|  | 3076 |  | 
|  | 3077 | } else { | 
|  | 3078 | Importer.Imported(D, ToCategory); | 
|  | 3079 | } | 
|  | 3080 |  | 
|  | 3081 | // Import all of the members of this category. | 
| Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 3082 | ImportDeclContext(D); | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3083 |  | 
|  | 3084 | // If we have an implementation, import it as well. | 
|  | 3085 | if (D->getImplementation()) { | 
|  | 3086 | ObjCCategoryImplDecl *Impl | 
| Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 3087 | = cast_or_null<ObjCCategoryImplDecl>( | 
|  | 3088 | Importer.Import(D->getImplementation())); | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3089 | if (!Impl) | 
|  | 3090 | return 0; | 
|  | 3091 |  | 
|  | 3092 | ToCategory->setImplementation(Impl); | 
|  | 3093 | } | 
|  | 3094 |  | 
|  | 3095 | return ToCategory; | 
|  | 3096 | } | 
|  | 3097 |  | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3098 | Decl *ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3099 | // Import the major distinguishing characteristics of a protocol. | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3100 | DeclContext *DC, *LexicalDC; | 
|  | 3101 | DeclarationName Name; | 
|  | 3102 | SourceLocation Loc; | 
|  | 3103 | if (ImportDeclParts(D, DC, LexicalDC, Name, Loc)) | 
|  | 3104 | return 0; | 
|  | 3105 |  | 
|  | 3106 | ObjCProtocolDecl *MergeWithProtocol = 0; | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3107 | llvm::SmallVector<NamedDecl *, 2> FoundDecls; | 
|  | 3108 | DC->localUncachedLookup(Name, FoundDecls); | 
|  | 3109 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | 
|  | 3110 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3111 | continue; | 
|  | 3112 |  | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3113 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecls[I]))) | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3114 | break; | 
|  | 3115 | } | 
|  | 3116 |  | 
|  | 3117 | ObjCProtocolDecl *ToProto = MergeWithProtocol; | 
|  | 3118 | if (!ToProto || ToProto->isForwardDecl()) { | 
|  | 3119 | if (!ToProto) { | 
| Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3120 | ToProto = ObjCProtocolDecl::Create(Importer.getToContext(), DC, | 
|  | 3121 | Name.getAsIdentifierInfo(), Loc, | 
| Argyrios Kyrtzidis | 1f4bee5 | 2011-10-17 19:48:06 +0000 | [diff] [blame] | 3122 | Importer.Import(D->getAtStartLoc()), | 
|  | 3123 | D->isInitiallyForwardDecl()); | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3124 | ToProto->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3125 | LexicalDC->addDeclInternal(ToProto); | 
| Argyrios Kyrtzidis | b97a402 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 3126 | if (D->isInitiallyForwardDecl() && !D->isForwardDecl()) | 
|  | 3127 | ToProto->completedForwardDecl(); | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3128 | } | 
|  | 3129 | Importer.Imported(D, ToProto); | 
|  | 3130 |  | 
|  | 3131 | // Import protocols | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3132 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | 
|  | 3133 | SmallVector<SourceLocation, 4> ProtocolLocs; | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3134 | ObjCProtocolDecl::protocol_loc_iterator | 
|  | 3135 | FromProtoLoc = D->protocol_loc_begin(); | 
|  | 3136 | for (ObjCProtocolDecl::protocol_iterator FromProto = D->protocol_begin(), | 
|  | 3137 | FromProtoEnd = D->protocol_end(); | 
|  | 3138 | FromProto != FromProtoEnd; | 
|  | 3139 | ++FromProto, ++FromProtoLoc) { | 
|  | 3140 | ObjCProtocolDecl *ToProto | 
|  | 3141 | = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); | 
|  | 3142 | if (!ToProto) | 
|  | 3143 | return 0; | 
|  | 3144 | Protocols.push_back(ToProto); | 
|  | 3145 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); | 
|  | 3146 | } | 
|  | 3147 |  | 
|  | 3148 | // FIXME: If we're merging, make sure that the protocol list is the same. | 
|  | 3149 | ToProto->setProtocolList(Protocols.data(), Protocols.size(), | 
|  | 3150 | ProtocolLocs.data(), Importer.getToContext()); | 
|  | 3151 | } else { | 
|  | 3152 | Importer.Imported(D, ToProto); | 
|  | 3153 | } | 
|  | 3154 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3155 | // Import all of the members of this protocol. | 
| Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 3156 | ImportDeclContext(D); | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3157 |  | 
|  | 3158 | return ToProto; | 
|  | 3159 | } | 
|  | 3160 |  | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3161 | Decl *ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { | 
|  | 3162 | // Import the major distinguishing characteristics of an @interface. | 
|  | 3163 | DeclContext *DC, *LexicalDC; | 
|  | 3164 | DeclarationName Name; | 
|  | 3165 | SourceLocation Loc; | 
|  | 3166 | if (ImportDeclParts(D, DC, LexicalDC, Name, Loc)) | 
|  | 3167 | return 0; | 
|  | 3168 |  | 
|  | 3169 | ObjCInterfaceDecl *MergeWithIface = 0; | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3170 | llvm::SmallVector<NamedDecl *, 2> FoundDecls; | 
|  | 3171 | DC->localUncachedLookup(Name, FoundDecls); | 
|  | 3172 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | 
|  | 3173 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary)) | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3174 | continue; | 
|  | 3175 |  | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3176 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecls[I]))) | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3177 | break; | 
|  | 3178 | } | 
|  | 3179 |  | 
|  | 3180 | ObjCInterfaceDecl *ToIface = MergeWithIface; | 
| Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 3181 | if (!ToIface || !ToIface->hasDefinition()) { | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3182 | if (!ToIface) { | 
| Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3183 | ToIface = ObjCInterfaceDecl::Create(Importer.getToContext(), DC, | 
|  | 3184 | Importer.Import(D->getAtStartLoc()), | 
|  | 3185 | Name.getAsIdentifierInfo(), Loc, | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3186 | D->isImplicitInterfaceDecl()); | 
|  | 3187 | ToIface->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3188 | LexicalDC->addDeclInternal(ToIface); | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3189 | } | 
|  | 3190 | Importer.Imported(D, ToIface); | 
|  | 3191 |  | 
| Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 3192 | if (D->hasDefinition()) { | 
|  | 3193 | if (!ToIface->hasDefinition()) | 
|  | 3194 | ToIface->startDefinition(); | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3195 |  | 
| Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 3196 | if (D->getSuperClass()) { | 
|  | 3197 | ObjCInterfaceDecl *Super | 
|  | 3198 | = cast_or_null<ObjCInterfaceDecl>( | 
|  | 3199 | Importer.Import(D->getSuperClass())); | 
|  | 3200 | if (!Super) | 
|  | 3201 | return 0; | 
|  | 3202 |  | 
|  | 3203 | ToIface->setSuperClass(Super); | 
|  | 3204 | ToIface->setSuperClassLoc(Importer.Import(D->getSuperClassLoc())); | 
|  | 3205 | } | 
|  | 3206 |  | 
|  | 3207 | // Import protocols | 
|  | 3208 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | 
|  | 3209 | SmallVector<SourceLocation, 4> ProtocolLocs; | 
|  | 3210 | ObjCInterfaceDecl::protocol_loc_iterator | 
|  | 3211 | FromProtoLoc = D->protocol_loc_begin(); | 
|  | 3212 |  | 
|  | 3213 | for (ObjCInterfaceDecl::protocol_iterator FromProto = D->protocol_begin(), | 
|  | 3214 | FromProtoEnd = D->protocol_end(); | 
|  | 3215 | FromProto != FromProtoEnd; | 
|  | 3216 | ++FromProto, ++FromProtoLoc) { | 
|  | 3217 | ObjCProtocolDecl *ToProto | 
|  | 3218 | = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); | 
|  | 3219 | if (!ToProto) | 
|  | 3220 | return 0; | 
|  | 3221 | Protocols.push_back(ToProto); | 
|  | 3222 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); | 
|  | 3223 | } | 
|  | 3224 |  | 
|  | 3225 | // FIXME: If we're merging, make sure that the protocol list is the same. | 
|  | 3226 | ToIface->setProtocolList(Protocols.data(), Protocols.size(), | 
|  | 3227 | ProtocolLocs.data(), Importer.getToContext()); | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3228 | } | 
|  | 3229 |  | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3230 | // Import @end range | 
|  | 3231 | ToIface->setAtEndRange(Importer.Import(D->getAtEndRange())); | 
|  | 3232 | } else { | 
|  | 3233 | Importer.Imported(D, ToIface); | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3234 |  | 
| Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 3235 | if (D->hasDefinition()) { | 
|  | 3236 | // Check for consistency of superclasses. | 
|  | 3237 | DeclarationName FromSuperName, ToSuperName; | 
|  | 3238 |  | 
|  | 3239 | // If the superclass hasn't been imported yet, do so before checking. | 
|  | 3240 | ObjCInterfaceDecl *DSuperClass = D->getSuperClass(); | 
|  | 3241 | ObjCInterfaceDecl *ToIfaceSuperClass = ToIface->getSuperClass(); | 
|  | 3242 |  | 
|  | 3243 | if (DSuperClass && !ToIfaceSuperClass) { | 
|  | 3244 | Decl *ImportedSuperClass = Importer.Import(DSuperClass); | 
|  | 3245 | ObjCInterfaceDecl *ImportedSuperIface | 
|  | 3246 | = cast<ObjCInterfaceDecl>(ImportedSuperClass); | 
|  | 3247 |  | 
|  | 3248 | ToIface->setSuperClass(ImportedSuperIface); | 
|  | 3249 | } | 
| Sean Callanan | 45e1328 | 2011-11-11 17:39:52 +0000 | [diff] [blame] | 3250 |  | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3251 | if (D->getSuperClass()) | 
| Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 3252 | FromSuperName = Importer.Import(D->getSuperClass()->getDeclName()); | 
|  | 3253 | if (ToIface->getSuperClass()) | 
|  | 3254 | ToSuperName = ToIface->getSuperClass()->getDeclName(); | 
|  | 3255 | if (FromSuperName != ToSuperName) { | 
|  | 3256 | Importer.ToDiag(ToIface->getLocation(), | 
|  | 3257 | diag::err_odr_objc_superclass_inconsistent) | 
|  | 3258 | << ToIface->getDeclName(); | 
|  | 3259 | if (ToIface->getSuperClass()) | 
|  | 3260 | Importer.ToDiag(ToIface->getSuperClassLoc(), | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3261 | diag::note_odr_objc_superclass) | 
| Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 3262 | << ToIface->getSuperClass()->getDeclName(); | 
|  | 3263 | else | 
|  | 3264 | Importer.ToDiag(ToIface->getLocation(), | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3265 | diag::note_odr_objc_missing_superclass); | 
| Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 3266 | if (D->getSuperClass()) | 
|  | 3267 | Importer.FromDiag(D->getSuperClassLoc(), | 
|  | 3268 | diag::note_odr_objc_superclass) | 
|  | 3269 | << D->getSuperClass()->getDeclName(); | 
|  | 3270 | else | 
|  | 3271 | Importer.FromDiag(D->getLocation(), | 
|  | 3272 | diag::note_odr_objc_missing_superclass); | 
|  | 3273 | return 0; | 
|  | 3274 | } | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3275 | } | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3276 | } | 
|  | 3277 |  | 
| Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 3278 | if (!D->hasDefinition()) | 
|  | 3279 | return ToIface; | 
|  | 3280 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3281 | // Import categories. When the categories themselves are imported, they'll | 
|  | 3282 | // hook themselves into this interface. | 
|  | 3283 | for (ObjCCategoryDecl *FromCat = D->getCategoryList(); FromCat; | 
|  | 3284 | FromCat = FromCat->getNextClassCategory()) | 
|  | 3285 | Importer.Import(FromCat); | 
|  | 3286 |  | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3287 | // Import all of the members of this class. | 
| Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 3288 | ImportDeclContext(D); | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3289 |  | 
|  | 3290 | // If we have an @implementation, import it as well. | 
| Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 3291 | if ( D->getImplementation()) { | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3292 | ObjCImplementationDecl *Impl = cast_or_null<ObjCImplementationDecl>( | 
|  | 3293 | Importer.Import(D->getImplementation())); | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3294 | if (!Impl) | 
|  | 3295 | return 0; | 
|  | 3296 |  | 
|  | 3297 | ToIface->setImplementation(Impl); | 
|  | 3298 | } | 
|  | 3299 |  | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3300 | return ToIface; | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3301 | } | 
|  | 3302 |  | 
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3303 | Decl *ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { | 
|  | 3304 | ObjCCategoryDecl *Category = cast_or_null<ObjCCategoryDecl>( | 
|  | 3305 | Importer.Import(D->getCategoryDecl())); | 
|  | 3306 | if (!Category) | 
|  | 3307 | return 0; | 
|  | 3308 |  | 
|  | 3309 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); | 
|  | 3310 | if (!ToImpl) { | 
|  | 3311 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); | 
|  | 3312 | if (!DC) | 
|  | 3313 | return 0; | 
|  | 3314 |  | 
| Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 3315 | SourceLocation CategoryNameLoc = Importer.Import(D->getCategoryNameLoc()); | 
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3316 | ToImpl = ObjCCategoryImplDecl::Create(Importer.getToContext(), DC, | 
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3317 | Importer.Import(D->getIdentifier()), | 
| Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3318 | Category->getClassInterface(), | 
|  | 3319 | Importer.Import(D->getLocation()), | 
| Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 3320 | Importer.Import(D->getAtStartLoc()), | 
|  | 3321 | CategoryNameLoc); | 
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3322 |  | 
|  | 3323 | DeclContext *LexicalDC = DC; | 
|  | 3324 | if (D->getDeclContext() != D->getLexicalDeclContext()) { | 
|  | 3325 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); | 
|  | 3326 | if (!LexicalDC) | 
|  | 3327 | return 0; | 
|  | 3328 |  | 
|  | 3329 | ToImpl->setLexicalDeclContext(LexicalDC); | 
|  | 3330 | } | 
|  | 3331 |  | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3332 | LexicalDC->addDeclInternal(ToImpl); | 
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3333 | Category->setImplementation(ToImpl); | 
|  | 3334 | } | 
|  | 3335 |  | 
|  | 3336 | Importer.Imported(D, ToImpl); | 
| Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 3337 | ImportDeclContext(D); | 
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3338 | return ToImpl; | 
|  | 3339 | } | 
|  | 3340 |  | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3341 | Decl *ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { | 
|  | 3342 | // Find the corresponding interface. | 
|  | 3343 | ObjCInterfaceDecl *Iface = cast_or_null<ObjCInterfaceDecl>( | 
|  | 3344 | Importer.Import(D->getClassInterface())); | 
|  | 3345 | if (!Iface) | 
|  | 3346 | return 0; | 
|  | 3347 |  | 
|  | 3348 | // Import the superclass, if any. | 
|  | 3349 | ObjCInterfaceDecl *Super = 0; | 
|  | 3350 | if (D->getSuperClass()) { | 
|  | 3351 | Super = cast_or_null<ObjCInterfaceDecl>( | 
|  | 3352 | Importer.Import(D->getSuperClass())); | 
|  | 3353 | if (!Super) | 
|  | 3354 | return 0; | 
|  | 3355 | } | 
|  | 3356 |  | 
|  | 3357 | ObjCImplementationDecl *Impl = Iface->getImplementation(); | 
|  | 3358 | if (!Impl) { | 
|  | 3359 | // We haven't imported an implementation yet. Create a new @implementation | 
|  | 3360 | // now. | 
|  | 3361 | Impl = ObjCImplementationDecl::Create(Importer.getToContext(), | 
|  | 3362 | Importer.ImportContext(D->getDeclContext()), | 
| Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3363 | Iface, Super, | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3364 | Importer.Import(D->getLocation()), | 
| Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3365 | Importer.Import(D->getAtStartLoc())); | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3366 |  | 
|  | 3367 | if (D->getDeclContext() != D->getLexicalDeclContext()) { | 
|  | 3368 | DeclContext *LexicalDC | 
|  | 3369 | = Importer.ImportContext(D->getLexicalDeclContext()); | 
|  | 3370 | if (!LexicalDC) | 
|  | 3371 | return 0; | 
|  | 3372 | Impl->setLexicalDeclContext(LexicalDC); | 
|  | 3373 | } | 
|  | 3374 |  | 
|  | 3375 | // Associate the implementation with the class it implements. | 
|  | 3376 | Iface->setImplementation(Impl); | 
|  | 3377 | Importer.Imported(D, Iface->getImplementation()); | 
|  | 3378 | } else { | 
|  | 3379 | Importer.Imported(D, Iface->getImplementation()); | 
|  | 3380 |  | 
|  | 3381 | // Verify that the existing @implementation has the same superclass. | 
|  | 3382 | if ((Super && !Impl->getSuperClass()) || | 
|  | 3383 | (!Super && Impl->getSuperClass()) || | 
|  | 3384 | (Super && Impl->getSuperClass() && | 
| Douglas Gregor | 0b144e1 | 2011-12-15 00:29:59 +0000 | [diff] [blame] | 3385 | !declaresSameEntity(Super->getCanonicalDecl(), Impl->getSuperClass()))) { | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3386 | Importer.ToDiag(Impl->getLocation(), | 
|  | 3387 | diag::err_odr_objc_superclass_inconsistent) | 
|  | 3388 | << Iface->getDeclName(); | 
|  | 3389 | // FIXME: It would be nice to have the location of the superclass | 
|  | 3390 | // below. | 
|  | 3391 | if (Impl->getSuperClass()) | 
|  | 3392 | Importer.ToDiag(Impl->getLocation(), | 
|  | 3393 | diag::note_odr_objc_superclass) | 
|  | 3394 | << Impl->getSuperClass()->getDeclName(); | 
|  | 3395 | else | 
|  | 3396 | Importer.ToDiag(Impl->getLocation(), | 
|  | 3397 | diag::note_odr_objc_missing_superclass); | 
|  | 3398 | if (D->getSuperClass()) | 
|  | 3399 | Importer.FromDiag(D->getLocation(), | 
|  | 3400 | diag::note_odr_objc_superclass) | 
|  | 3401 | << D->getSuperClass()->getDeclName(); | 
|  | 3402 | else | 
|  | 3403 | Importer.FromDiag(D->getLocation(), | 
|  | 3404 | diag::note_odr_objc_missing_superclass); | 
|  | 3405 | return 0; | 
|  | 3406 | } | 
|  | 3407 | } | 
|  | 3408 |  | 
|  | 3409 | // Import all of the members of this @implementation. | 
|  | 3410 | ImportDeclContext(D); | 
|  | 3411 |  | 
|  | 3412 | return Impl; | 
|  | 3413 | } | 
|  | 3414 |  | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3415 | Decl *ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { | 
|  | 3416 | // Import the major distinguishing characteristics of an @property. | 
|  | 3417 | DeclContext *DC, *LexicalDC; | 
|  | 3418 | DeclarationName Name; | 
|  | 3419 | SourceLocation Loc; | 
|  | 3420 | if (ImportDeclParts(D, DC, LexicalDC, Name, Loc)) | 
|  | 3421 | return 0; | 
|  | 3422 |  | 
|  | 3423 | // Check whether we have already imported this property. | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3424 | llvm::SmallVector<NamedDecl *, 2> FoundDecls; | 
|  | 3425 | DC->localUncachedLookup(Name, FoundDecls); | 
|  | 3426 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3427 | if (ObjCPropertyDecl *FoundProp | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3428 | = dyn_cast<ObjCPropertyDecl>(FoundDecls[I])) { | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3429 | // Check property types. | 
|  | 3430 | if (!Importer.IsStructurallyEquivalent(D->getType(), | 
|  | 3431 | FoundProp->getType())) { | 
|  | 3432 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) | 
|  | 3433 | << Name << D->getType() << FoundProp->getType(); | 
|  | 3434 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) | 
|  | 3435 | << FoundProp->getType(); | 
|  | 3436 | return 0; | 
|  | 3437 | } | 
|  | 3438 |  | 
|  | 3439 | // FIXME: Check property attributes, getters, setters, etc.? | 
|  | 3440 |  | 
|  | 3441 | // Consider these properties to be equivalent. | 
|  | 3442 | Importer.Imported(D, FoundProp); | 
|  | 3443 | return FoundProp; | 
|  | 3444 | } | 
|  | 3445 | } | 
|  | 3446 |  | 
|  | 3447 | // Import the type. | 
| John McCall | 339bb66 | 2010-06-04 20:50:08 +0000 | [diff] [blame] | 3448 | TypeSourceInfo *T = Importer.Import(D->getTypeSourceInfo()); | 
|  | 3449 | if (!T) | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3450 | return 0; | 
|  | 3451 |  | 
|  | 3452 | // Create the new property. | 
|  | 3453 | ObjCPropertyDecl *ToProperty | 
|  | 3454 | = ObjCPropertyDecl::Create(Importer.getToContext(), DC, Loc, | 
|  | 3455 | Name.getAsIdentifierInfo(), | 
|  | 3456 | Importer.Import(D->getAtLoc()), | 
|  | 3457 | T, | 
|  | 3458 | D->getPropertyImplementation()); | 
|  | 3459 | Importer.Imported(D, ToProperty); | 
|  | 3460 | ToProperty->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3461 | LexicalDC->addDeclInternal(ToProperty); | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3462 |  | 
|  | 3463 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); | 
| Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 3464 | ToProperty->setPropertyAttributesAsWritten( | 
|  | 3465 | D->getPropertyAttributesAsWritten()); | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3466 | ToProperty->setGetterName(Importer.Import(D->getGetterName())); | 
|  | 3467 | ToProperty->setSetterName(Importer.Import(D->getSetterName())); | 
|  | 3468 | ToProperty->setGetterMethodDecl( | 
|  | 3469 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getGetterMethodDecl()))); | 
|  | 3470 | ToProperty->setSetterMethodDecl( | 
|  | 3471 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getSetterMethodDecl()))); | 
|  | 3472 | ToProperty->setPropertyIvarDecl( | 
|  | 3473 | cast_or_null<ObjCIvarDecl>(Importer.Import(D->getPropertyIvarDecl()))); | 
|  | 3474 | return ToProperty; | 
|  | 3475 | } | 
|  | 3476 |  | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3477 | Decl *ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { | 
|  | 3478 | ObjCPropertyDecl *Property = cast_or_null<ObjCPropertyDecl>( | 
|  | 3479 | Importer.Import(D->getPropertyDecl())); | 
|  | 3480 | if (!Property) | 
|  | 3481 | return 0; | 
|  | 3482 |  | 
|  | 3483 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); | 
|  | 3484 | if (!DC) | 
|  | 3485 | return 0; | 
|  | 3486 |  | 
|  | 3487 | // Import the lexical declaration context. | 
|  | 3488 | DeclContext *LexicalDC = DC; | 
|  | 3489 | if (D->getDeclContext() != D->getLexicalDeclContext()) { | 
|  | 3490 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); | 
|  | 3491 | if (!LexicalDC) | 
|  | 3492 | return 0; | 
|  | 3493 | } | 
|  | 3494 |  | 
|  | 3495 | ObjCImplDecl *InImpl = dyn_cast<ObjCImplDecl>(LexicalDC); | 
|  | 3496 | if (!InImpl) | 
|  | 3497 | return 0; | 
|  | 3498 |  | 
|  | 3499 | // Import the ivar (for an @synthesize). | 
|  | 3500 | ObjCIvarDecl *Ivar = 0; | 
|  | 3501 | if (D->getPropertyIvarDecl()) { | 
|  | 3502 | Ivar = cast_or_null<ObjCIvarDecl>( | 
|  | 3503 | Importer.Import(D->getPropertyIvarDecl())); | 
|  | 3504 | if (!Ivar) | 
|  | 3505 | return 0; | 
|  | 3506 | } | 
|  | 3507 |  | 
|  | 3508 | ObjCPropertyImplDecl *ToImpl | 
|  | 3509 | = InImpl->FindPropertyImplDecl(Property->getIdentifier()); | 
|  | 3510 | if (!ToImpl) { | 
|  | 3511 | ToImpl = ObjCPropertyImplDecl::Create(Importer.getToContext(), DC, | 
|  | 3512 | Importer.Import(D->getLocStart()), | 
|  | 3513 | Importer.Import(D->getLocation()), | 
|  | 3514 | Property, | 
|  | 3515 | D->getPropertyImplementation(), | 
|  | 3516 | Ivar, | 
|  | 3517 | Importer.Import(D->getPropertyIvarDeclLoc())); | 
|  | 3518 | ToImpl->setLexicalDeclContext(LexicalDC); | 
|  | 3519 | Importer.Imported(D, ToImpl); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3520 | LexicalDC->addDeclInternal(ToImpl); | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3521 | } else { | 
|  | 3522 | // Check that we have the same kind of property implementation (@synthesize | 
|  | 3523 | // vs. @dynamic). | 
|  | 3524 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { | 
|  | 3525 | Importer.ToDiag(ToImpl->getLocation(), | 
|  | 3526 | diag::err_odr_objc_property_impl_kind_inconsistent) | 
|  | 3527 | << Property->getDeclName() | 
|  | 3528 | << (ToImpl->getPropertyImplementation() | 
|  | 3529 | == ObjCPropertyImplDecl::Dynamic); | 
|  | 3530 | Importer.FromDiag(D->getLocation(), | 
|  | 3531 | diag::note_odr_objc_property_impl_kind) | 
|  | 3532 | << D->getPropertyDecl()->getDeclName() | 
|  | 3533 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); | 
|  | 3534 | return 0; | 
|  | 3535 | } | 
|  | 3536 |  | 
|  | 3537 | // For @synthesize, check that we have the same | 
|  | 3538 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && | 
|  | 3539 | Ivar != ToImpl->getPropertyIvarDecl()) { | 
|  | 3540 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), | 
|  | 3541 | diag::err_odr_objc_synthesize_ivar_inconsistent) | 
|  | 3542 | << Property->getDeclName() | 
|  | 3543 | << ToImpl->getPropertyIvarDecl()->getDeclName() | 
|  | 3544 | << Ivar->getDeclName(); | 
|  | 3545 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), | 
|  | 3546 | diag::note_odr_objc_synthesize_ivar_here) | 
|  | 3547 | << D->getPropertyIvarDecl()->getDeclName(); | 
|  | 3548 | return 0; | 
|  | 3549 | } | 
|  | 3550 |  | 
|  | 3551 | // Merge the existing implementation with the new implementation. | 
|  | 3552 | Importer.Imported(D, ToImpl); | 
|  | 3553 | } | 
|  | 3554 |  | 
|  | 3555 | return ToImpl; | 
|  | 3556 | } | 
|  | 3557 |  | 
| Douglas Gregor | 8661a72 | 2010-02-18 02:12:22 +0000 | [diff] [blame] | 3558 | Decl * | 
|  | 3559 | ASTNodeImporter::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) { | 
|  | 3560 | // Import the context of this declaration. | 
|  | 3561 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); | 
|  | 3562 | if (!DC) | 
|  | 3563 | return 0; | 
|  | 3564 |  | 
|  | 3565 | DeclContext *LexicalDC = DC; | 
|  | 3566 | if (D->getDeclContext() != D->getLexicalDeclContext()) { | 
|  | 3567 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); | 
|  | 3568 | if (!LexicalDC) | 
|  | 3569 | return 0; | 
|  | 3570 | } | 
|  | 3571 |  | 
|  | 3572 | // Import the location of this declaration. | 
|  | 3573 | SourceLocation Loc = Importer.Import(D->getLocation()); | 
|  | 3574 |  | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3575 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | 
|  | 3576 | SmallVector<SourceLocation, 4> Locations; | 
| Douglas Gregor | 8661a72 | 2010-02-18 02:12:22 +0000 | [diff] [blame] | 3577 | ObjCForwardProtocolDecl::protocol_loc_iterator FromProtoLoc | 
|  | 3578 | = D->protocol_loc_begin(); | 
|  | 3579 | for (ObjCForwardProtocolDecl::protocol_iterator FromProto | 
|  | 3580 | = D->protocol_begin(), FromProtoEnd = D->protocol_end(); | 
|  | 3581 | FromProto != FromProtoEnd; | 
|  | 3582 | ++FromProto, ++FromProtoLoc) { | 
|  | 3583 | ObjCProtocolDecl *ToProto | 
|  | 3584 | = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); | 
|  | 3585 | if (!ToProto) | 
|  | 3586 | continue; | 
|  | 3587 |  | 
|  | 3588 | Protocols.push_back(ToProto); | 
|  | 3589 | Locations.push_back(Importer.Import(*FromProtoLoc)); | 
|  | 3590 | } | 
|  | 3591 |  | 
|  | 3592 | ObjCForwardProtocolDecl *ToForward | 
|  | 3593 | = ObjCForwardProtocolDecl::Create(Importer.getToContext(), DC, Loc, | 
|  | 3594 | Protocols.data(), Protocols.size(), | 
|  | 3595 | Locations.data()); | 
|  | 3596 | ToForward->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3597 | LexicalDC->addDeclInternal(ToForward); | 
| Douglas Gregor | 8661a72 | 2010-02-18 02:12:22 +0000 | [diff] [blame] | 3598 | Importer.Imported(D, ToForward); | 
|  | 3599 | return ToForward; | 
|  | 3600 | } | 
|  | 3601 |  | 
| Douglas Gregor | 06537af | 2010-02-18 02:04:09 +0000 | [diff] [blame] | 3602 | Decl *ASTNodeImporter::VisitObjCClassDecl(ObjCClassDecl *D) { | 
|  | 3603 | // Import the context of this declaration. | 
|  | 3604 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); | 
|  | 3605 | if (!DC) | 
|  | 3606 | return 0; | 
|  | 3607 |  | 
|  | 3608 | DeclContext *LexicalDC = DC; | 
|  | 3609 | if (D->getDeclContext() != D->getLexicalDeclContext()) { | 
|  | 3610 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); | 
|  | 3611 | if (!LexicalDC) | 
|  | 3612 | return 0; | 
|  | 3613 | } | 
|  | 3614 |  | 
|  | 3615 | // Import the location of this declaration. | 
|  | 3616 | SourceLocation Loc = Importer.Import(D->getLocation()); | 
| Fariborz Jahanian | 3a039e3 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 3617 | ObjCInterfaceDecl *ToIface | 
| Douglas Gregor | 40d009f | 2011-12-14 17:12:03 +0000 | [diff] [blame] | 3618 | = cast_or_null<ObjCInterfaceDecl>( | 
|  | 3619 | Importer.Import(D->getForwardInterfaceDecl())); | 
| Douglas Gregor | 06537af | 2010-02-18 02:04:09 +0000 | [diff] [blame] | 3620 | ObjCClassDecl *ToClass = ObjCClassDecl::Create(Importer.getToContext(), DC, | 
| Douglas Gregor | 40d009f | 2011-12-14 17:12:03 +0000 | [diff] [blame] | 3621 | Loc, | 
|  | 3622 | ToIface, | 
|  | 3623 | Importer.Import(D->getNameLoc())); | 
| Fariborz Jahanian | 3a039e3 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 3624 |  | 
| Douglas Gregor | 06537af | 2010-02-18 02:04:09 +0000 | [diff] [blame] | 3625 | ToClass->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3626 | LexicalDC->addDeclInternal(ToClass); | 
| Douglas Gregor | 06537af | 2010-02-18 02:04:09 +0000 | [diff] [blame] | 3627 | Importer.Imported(D, ToClass); | 
|  | 3628 | return ToClass; | 
|  | 3629 | } | 
|  | 3630 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3631 | Decl *ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { | 
|  | 3632 | // For template arguments, we adopt the translation unit as our declaration | 
|  | 3633 | // context. This context will be fixed when the actual template declaration | 
|  | 3634 | // is created. | 
|  | 3635 |  | 
|  | 3636 | // FIXME: Import default argument. | 
|  | 3637 | return TemplateTypeParmDecl::Create(Importer.getToContext(), | 
|  | 3638 | Importer.getToContext().getTranslationUnitDecl(), | 
| Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 3639 | Importer.Import(D->getLocStart()), | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3640 | Importer.Import(D->getLocation()), | 
|  | 3641 | D->getDepth(), | 
|  | 3642 | D->getIndex(), | 
|  | 3643 | Importer.Import(D->getIdentifier()), | 
|  | 3644 | D->wasDeclaredWithTypename(), | 
|  | 3645 | D->isParameterPack()); | 
|  | 3646 | } | 
|  | 3647 |  | 
|  | 3648 | Decl * | 
|  | 3649 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { | 
|  | 3650 | // Import the name of this declaration. | 
|  | 3651 | DeclarationName Name = Importer.Import(D->getDeclName()); | 
|  | 3652 | if (D->getDeclName() && !Name) | 
|  | 3653 | return 0; | 
|  | 3654 |  | 
|  | 3655 | // Import the location of this declaration. | 
|  | 3656 | SourceLocation Loc = Importer.Import(D->getLocation()); | 
|  | 3657 |  | 
|  | 3658 | // Import the type of this declaration. | 
|  | 3659 | QualType T = Importer.Import(D->getType()); | 
|  | 3660 | if (T.isNull()) | 
|  | 3661 | return 0; | 
|  | 3662 |  | 
|  | 3663 | // Import type-source information. | 
|  | 3664 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); | 
|  | 3665 | if (D->getTypeSourceInfo() && !TInfo) | 
|  | 3666 | return 0; | 
|  | 3667 |  | 
|  | 3668 | // FIXME: Import default argument. | 
|  | 3669 |  | 
|  | 3670 | return NonTypeTemplateParmDecl::Create(Importer.getToContext(), | 
|  | 3671 | Importer.getToContext().getTranslationUnitDecl(), | 
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 3672 | Importer.Import(D->getInnerLocStart()), | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3673 | Loc, D->getDepth(), D->getPosition(), | 
|  | 3674 | Name.getAsIdentifierInfo(), | 
| Douglas Gregor | da3cc0d | 2010-12-23 23:51:58 +0000 | [diff] [blame] | 3675 | T, D->isParameterPack(), TInfo); | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3676 | } | 
|  | 3677 |  | 
|  | 3678 | Decl * | 
|  | 3679 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { | 
|  | 3680 | // Import the name of this declaration. | 
|  | 3681 | DeclarationName Name = Importer.Import(D->getDeclName()); | 
|  | 3682 | if (D->getDeclName() && !Name) | 
|  | 3683 | return 0; | 
|  | 3684 |  | 
|  | 3685 | // Import the location of this declaration. | 
|  | 3686 | SourceLocation Loc = Importer.Import(D->getLocation()); | 
|  | 3687 |  | 
|  | 3688 | // Import template parameters. | 
|  | 3689 | TemplateParameterList *TemplateParams | 
|  | 3690 | = ImportTemplateParameterList(D->getTemplateParameters()); | 
|  | 3691 | if (!TemplateParams) | 
|  | 3692 | return 0; | 
|  | 3693 |  | 
|  | 3694 | // FIXME: Import default argument. | 
|  | 3695 |  | 
|  | 3696 | return TemplateTemplateParmDecl::Create(Importer.getToContext(), | 
|  | 3697 | Importer.getToContext().getTranslationUnitDecl(), | 
|  | 3698 | Loc, D->getDepth(), D->getPosition(), | 
| Douglas Gregor | f550077 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 3699 | D->isParameterPack(), | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3700 | Name.getAsIdentifierInfo(), | 
|  | 3701 | TemplateParams); | 
|  | 3702 | } | 
|  | 3703 |  | 
|  | 3704 | Decl *ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { | 
|  | 3705 | // If this record has a definition in the translation unit we're coming from, | 
|  | 3706 | // but this particular declaration is not that definition, import the | 
|  | 3707 | // definition and map to that. | 
|  | 3708 | CXXRecordDecl *Definition | 
|  | 3709 | = cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition()); | 
|  | 3710 | if (Definition && Definition != D->getTemplatedDecl()) { | 
|  | 3711 | Decl *ImportedDef | 
|  | 3712 | = Importer.Import(Definition->getDescribedClassTemplate()); | 
|  | 3713 | if (!ImportedDef) | 
|  | 3714 | return 0; | 
|  | 3715 |  | 
|  | 3716 | return Importer.Imported(D, ImportedDef); | 
|  | 3717 | } | 
|  | 3718 |  | 
|  | 3719 | // Import the major distinguishing characteristics of this class template. | 
|  | 3720 | DeclContext *DC, *LexicalDC; | 
|  | 3721 | DeclarationName Name; | 
|  | 3722 | SourceLocation Loc; | 
|  | 3723 | if (ImportDeclParts(D, DC, LexicalDC, Name, Loc)) | 
|  | 3724 | return 0; | 
|  | 3725 |  | 
|  | 3726 | // We may already have a template of the same name; try to find and match it. | 
|  | 3727 | if (!DC->isFunctionOrMethod()) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3728 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3729 | llvm::SmallVector<NamedDecl *, 2> FoundDecls; | 
|  | 3730 | DC->localUncachedLookup(Name, FoundDecls); | 
|  | 3731 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | 
|  | 3732 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary)) | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3733 | continue; | 
|  | 3734 |  | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3735 | Decl *Found = FoundDecls[I]; | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3736 | if (ClassTemplateDecl *FoundTemplate | 
|  | 3737 | = dyn_cast<ClassTemplateDecl>(Found)) { | 
|  | 3738 | if (IsStructuralMatch(D, FoundTemplate)) { | 
|  | 3739 | // The class templates structurally match; call it the same template. | 
|  | 3740 | // FIXME: We may be filling in a forward declaration here. Handle | 
|  | 3741 | // this case! | 
|  | 3742 | Importer.Imported(D->getTemplatedDecl(), | 
|  | 3743 | FoundTemplate->getTemplatedDecl()); | 
|  | 3744 | return Importer.Imported(D, FoundTemplate); | 
|  | 3745 | } | 
|  | 3746 | } | 
|  | 3747 |  | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3748 | ConflictingDecls.push_back(FoundDecls[I]); | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3749 | } | 
|  | 3750 |  | 
|  | 3751 | if (!ConflictingDecls.empty()) { | 
|  | 3752 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, | 
|  | 3753 | ConflictingDecls.data(), | 
|  | 3754 | ConflictingDecls.size()); | 
|  | 3755 | } | 
|  | 3756 |  | 
|  | 3757 | if (!Name) | 
|  | 3758 | return 0; | 
|  | 3759 | } | 
|  | 3760 |  | 
|  | 3761 | CXXRecordDecl *DTemplated = D->getTemplatedDecl(); | 
|  | 3762 |  | 
|  | 3763 | // Create the declaration that is being templated. | 
| Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 3764 | SourceLocation StartLoc = Importer.Import(DTemplated->getLocStart()); | 
|  | 3765 | SourceLocation IdLoc = Importer.Import(DTemplated->getLocation()); | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3766 | CXXRecordDecl *D2Templated = CXXRecordDecl::Create(Importer.getToContext(), | 
|  | 3767 | DTemplated->getTagKind(), | 
| Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 3768 | DC, StartLoc, IdLoc, | 
|  | 3769 | Name.getAsIdentifierInfo()); | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3770 | D2Templated->setAccess(DTemplated->getAccess()); | 
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3771 | D2Templated->setQualifierInfo(Importer.Import(DTemplated->getQualifierLoc())); | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3772 | D2Templated->setLexicalDeclContext(LexicalDC); | 
|  | 3773 |  | 
|  | 3774 | // Create the class template declaration itself. | 
|  | 3775 | TemplateParameterList *TemplateParams | 
|  | 3776 | = ImportTemplateParameterList(D->getTemplateParameters()); | 
|  | 3777 | if (!TemplateParams) | 
|  | 3778 | return 0; | 
|  | 3779 |  | 
|  | 3780 | ClassTemplateDecl *D2 = ClassTemplateDecl::Create(Importer.getToContext(), DC, | 
|  | 3781 | Loc, Name, TemplateParams, | 
|  | 3782 | D2Templated, | 
|  | 3783 | /*PrevDecl=*/0); | 
|  | 3784 | D2Templated->setDescribedClassTemplate(D2); | 
|  | 3785 |  | 
|  | 3786 | D2->setAccess(D->getAccess()); | 
|  | 3787 | D2->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3788 | LexicalDC->addDeclInternal(D2); | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3789 |  | 
|  | 3790 | // Note the relationship between the class templates. | 
|  | 3791 | Importer.Imported(D, D2); | 
|  | 3792 | Importer.Imported(DTemplated, D2Templated); | 
|  | 3793 |  | 
| John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 3794 | if (DTemplated->isCompleteDefinition() && | 
|  | 3795 | !D2Templated->isCompleteDefinition()) { | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3796 | // FIXME: Import definition! | 
|  | 3797 | } | 
|  | 3798 |  | 
|  | 3799 | return D2; | 
|  | 3800 | } | 
|  | 3801 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3802 | Decl *ASTNodeImporter::VisitClassTemplateSpecializationDecl( | 
|  | 3803 | ClassTemplateSpecializationDecl *D) { | 
|  | 3804 | // If this record has a definition in the translation unit we're coming from, | 
|  | 3805 | // but this particular declaration is not that definition, import the | 
|  | 3806 | // definition and map to that. | 
|  | 3807 | TagDecl *Definition = D->getDefinition(); | 
|  | 3808 | if (Definition && Definition != D) { | 
|  | 3809 | Decl *ImportedDef = Importer.Import(Definition); | 
|  | 3810 | if (!ImportedDef) | 
|  | 3811 | return 0; | 
|  | 3812 |  | 
|  | 3813 | return Importer.Imported(D, ImportedDef); | 
|  | 3814 | } | 
|  | 3815 |  | 
|  | 3816 | ClassTemplateDecl *ClassTemplate | 
|  | 3817 | = cast_or_null<ClassTemplateDecl>(Importer.Import( | 
|  | 3818 | D->getSpecializedTemplate())); | 
|  | 3819 | if (!ClassTemplate) | 
|  | 3820 | return 0; | 
|  | 3821 |  | 
|  | 3822 | // Import the context of this declaration. | 
|  | 3823 | DeclContext *DC = ClassTemplate->getDeclContext(); | 
|  | 3824 | if (!DC) | 
|  | 3825 | return 0; | 
|  | 3826 |  | 
|  | 3827 | DeclContext *LexicalDC = DC; | 
|  | 3828 | if (D->getDeclContext() != D->getLexicalDeclContext()) { | 
|  | 3829 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); | 
|  | 3830 | if (!LexicalDC) | 
|  | 3831 | return 0; | 
|  | 3832 | } | 
|  | 3833 |  | 
|  | 3834 | // Import the location of this declaration. | 
| Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 3835 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); | 
|  | 3836 | SourceLocation IdLoc = Importer.Import(D->getLocation()); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3837 |  | 
|  | 3838 | // Import template arguments. | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3839 | SmallVector<TemplateArgument, 2> TemplateArgs; | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3840 | if (ImportTemplateArguments(D->getTemplateArgs().data(), | 
|  | 3841 | D->getTemplateArgs().size(), | 
|  | 3842 | TemplateArgs)) | 
|  | 3843 | return 0; | 
|  | 3844 |  | 
|  | 3845 | // Try to find an existing specialization with these template arguments. | 
|  | 3846 | void *InsertPos = 0; | 
|  | 3847 | ClassTemplateSpecializationDecl *D2 | 
|  | 3848 | = ClassTemplate->findSpecialization(TemplateArgs.data(), | 
|  | 3849 | TemplateArgs.size(), InsertPos); | 
|  | 3850 | if (D2) { | 
|  | 3851 | // We already have a class template specialization with these template | 
|  | 3852 | // arguments. | 
|  | 3853 |  | 
|  | 3854 | // FIXME: Check for specialization vs. instantiation errors. | 
|  | 3855 |  | 
|  | 3856 | if (RecordDecl *FoundDef = D2->getDefinition()) { | 
| John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 3857 | if (!D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) { | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3858 | // The record types structurally match, or the "from" translation | 
|  | 3859 | // unit only had a forward declaration anyway; call it the same | 
|  | 3860 | // function. | 
|  | 3861 | return Importer.Imported(D, FoundDef); | 
|  | 3862 | } | 
|  | 3863 | } | 
|  | 3864 | } else { | 
|  | 3865 | // Create a new specialization. | 
|  | 3866 | D2 = ClassTemplateSpecializationDecl::Create(Importer.getToContext(), | 
|  | 3867 | D->getTagKind(), DC, | 
| Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 3868 | StartLoc, IdLoc, | 
|  | 3869 | ClassTemplate, | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3870 | TemplateArgs.data(), | 
|  | 3871 | TemplateArgs.size(), | 
|  | 3872 | /*PrevDecl=*/0); | 
|  | 3873 | D2->setSpecializationKind(D->getSpecializationKind()); | 
|  | 3874 |  | 
|  | 3875 | // Add this specialization to the class template. | 
|  | 3876 | ClassTemplate->AddSpecialization(D2, InsertPos); | 
|  | 3877 |  | 
|  | 3878 | // Import the qualifier, if any. | 
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3879 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3880 |  | 
|  | 3881 | // Add the specialization to this context. | 
|  | 3882 | D2->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3883 | LexicalDC->addDeclInternal(D2); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3884 | } | 
|  | 3885 | Importer.Imported(D, D2); | 
|  | 3886 |  | 
| John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 3887 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3888 | return 0; | 
|  | 3889 |  | 
|  | 3890 | return D2; | 
|  | 3891 | } | 
|  | 3892 |  | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 3893 | //---------------------------------------------------------------------------- | 
|  | 3894 | // Import Statements | 
|  | 3895 | //---------------------------------------------------------------------------- | 
|  | 3896 |  | 
|  | 3897 | Stmt *ASTNodeImporter::VisitStmt(Stmt *S) { | 
|  | 3898 | Importer.FromDiag(S->getLocStart(), diag::err_unsupported_ast_node) | 
|  | 3899 | << S->getStmtClassName(); | 
|  | 3900 | return 0; | 
|  | 3901 | } | 
|  | 3902 |  | 
|  | 3903 | //---------------------------------------------------------------------------- | 
|  | 3904 | // Import Expressions | 
|  | 3905 | //---------------------------------------------------------------------------- | 
|  | 3906 | Expr *ASTNodeImporter::VisitExpr(Expr *E) { | 
|  | 3907 | Importer.FromDiag(E->getLocStart(), diag::err_unsupported_ast_node) | 
|  | 3908 | << E->getStmtClassName(); | 
|  | 3909 | return 0; | 
|  | 3910 | } | 
|  | 3911 |  | 
| Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 3912 | Expr *ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { | 
| Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 3913 | ValueDecl *ToD = cast_or_null<ValueDecl>(Importer.Import(E->getDecl())); | 
|  | 3914 | if (!ToD) | 
|  | 3915 | return 0; | 
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 3916 |  | 
|  | 3917 | NamedDecl *FoundD = 0; | 
|  | 3918 | if (E->getDecl() != E->getFoundDecl()) { | 
|  | 3919 | FoundD = cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl())); | 
|  | 3920 | if (!FoundD) | 
|  | 3921 | return 0; | 
|  | 3922 | } | 
| Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 3923 |  | 
|  | 3924 | QualType T = Importer.Import(E->getType()); | 
|  | 3925 | if (T.isNull()) | 
|  | 3926 | return 0; | 
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 3927 |  | 
|  | 3928 | DeclRefExpr *DRE = DeclRefExpr::Create(Importer.getToContext(), | 
|  | 3929 | Importer.Import(E->getQualifierLoc()), | 
|  | 3930 | ToD, | 
|  | 3931 | Importer.Import(E->getLocation()), | 
|  | 3932 | T, E->getValueKind(), | 
|  | 3933 | FoundD, | 
|  | 3934 | /*FIXME:TemplateArgs=*/0); | 
|  | 3935 | if (E->hadMultipleCandidates()) | 
|  | 3936 | DRE->setHadMultipleCandidates(true); | 
|  | 3937 | return DRE; | 
| Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 3938 | } | 
|  | 3939 |  | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 3940 | Expr *ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { | 
|  | 3941 | QualType T = Importer.Import(E->getType()); | 
|  | 3942 | if (T.isNull()) | 
|  | 3943 | return 0; | 
|  | 3944 |  | 
| Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 3945 | return IntegerLiteral::Create(Importer.getToContext(), | 
|  | 3946 | E->getValue(), T, | 
|  | 3947 | Importer.Import(E->getLocation())); | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 3948 | } | 
|  | 3949 |  | 
| Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 3950 | Expr *ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { | 
|  | 3951 | QualType T = Importer.Import(E->getType()); | 
|  | 3952 | if (T.isNull()) | 
|  | 3953 | return 0; | 
|  | 3954 |  | 
| Douglas Gregor | fb65e59 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 3955 | return new (Importer.getToContext()) CharacterLiteral(E->getValue(), | 
|  | 3956 | E->getKind(), T, | 
| Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 3957 | Importer.Import(E->getLocation())); | 
|  | 3958 | } | 
|  | 3959 |  | 
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 3960 | Expr *ASTNodeImporter::VisitParenExpr(ParenExpr *E) { | 
|  | 3961 | Expr *SubExpr = Importer.Import(E->getSubExpr()); | 
|  | 3962 | if (!SubExpr) | 
|  | 3963 | return 0; | 
|  | 3964 |  | 
|  | 3965 | return new (Importer.getToContext()) | 
|  | 3966 | ParenExpr(Importer.Import(E->getLParen()), | 
|  | 3967 | Importer.Import(E->getRParen()), | 
|  | 3968 | SubExpr); | 
|  | 3969 | } | 
|  | 3970 |  | 
|  | 3971 | Expr *ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { | 
|  | 3972 | QualType T = Importer.Import(E->getType()); | 
|  | 3973 | if (T.isNull()) | 
|  | 3974 | return 0; | 
|  | 3975 |  | 
|  | 3976 | Expr *SubExpr = Importer.Import(E->getSubExpr()); | 
|  | 3977 | if (!SubExpr) | 
|  | 3978 | return 0; | 
|  | 3979 |  | 
|  | 3980 | return new (Importer.getToContext()) UnaryOperator(SubExpr, E->getOpcode(), | 
| John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 3981 | T, E->getValueKind(), | 
|  | 3982 | E->getObjectKind(), | 
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 3983 | Importer.Import(E->getOperatorLoc())); | 
|  | 3984 | } | 
|  | 3985 |  | 
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 3986 | Expr *ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr( | 
|  | 3987 | UnaryExprOrTypeTraitExpr *E) { | 
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 3988 | QualType ResultType = Importer.Import(E->getType()); | 
|  | 3989 |  | 
|  | 3990 | if (E->isArgumentType()) { | 
|  | 3991 | TypeSourceInfo *TInfo = Importer.Import(E->getArgumentTypeInfo()); | 
|  | 3992 | if (!TInfo) | 
|  | 3993 | return 0; | 
|  | 3994 |  | 
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 3995 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), | 
|  | 3996 | TInfo, ResultType, | 
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 3997 | Importer.Import(E->getOperatorLoc()), | 
|  | 3998 | Importer.Import(E->getRParenLoc())); | 
|  | 3999 | } | 
|  | 4000 |  | 
|  | 4001 | Expr *SubExpr = Importer.Import(E->getArgumentExpr()); | 
|  | 4002 | if (!SubExpr) | 
|  | 4003 | return 0; | 
|  | 4004 |  | 
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 4005 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), | 
|  | 4006 | SubExpr, ResultType, | 
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 4007 | Importer.Import(E->getOperatorLoc()), | 
|  | 4008 | Importer.Import(E->getRParenLoc())); | 
|  | 4009 | } | 
|  | 4010 |  | 
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4011 | Expr *ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { | 
|  | 4012 | QualType T = Importer.Import(E->getType()); | 
|  | 4013 | if (T.isNull()) | 
|  | 4014 | return 0; | 
|  | 4015 |  | 
|  | 4016 | Expr *LHS = Importer.Import(E->getLHS()); | 
|  | 4017 | if (!LHS) | 
|  | 4018 | return 0; | 
|  | 4019 |  | 
|  | 4020 | Expr *RHS = Importer.Import(E->getRHS()); | 
|  | 4021 | if (!RHS) | 
|  | 4022 | return 0; | 
|  | 4023 |  | 
|  | 4024 | return new (Importer.getToContext()) BinaryOperator(LHS, RHS, E->getOpcode(), | 
| John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 4025 | T, E->getValueKind(), | 
|  | 4026 | E->getObjectKind(), | 
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4027 | Importer.Import(E->getOperatorLoc())); | 
|  | 4028 | } | 
|  | 4029 |  | 
|  | 4030 | Expr *ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { | 
|  | 4031 | QualType T = Importer.Import(E->getType()); | 
|  | 4032 | if (T.isNull()) | 
|  | 4033 | return 0; | 
|  | 4034 |  | 
|  | 4035 | QualType CompLHSType = Importer.Import(E->getComputationLHSType()); | 
|  | 4036 | if (CompLHSType.isNull()) | 
|  | 4037 | return 0; | 
|  | 4038 |  | 
|  | 4039 | QualType CompResultType = Importer.Import(E->getComputationResultType()); | 
|  | 4040 | if (CompResultType.isNull()) | 
|  | 4041 | return 0; | 
|  | 4042 |  | 
|  | 4043 | Expr *LHS = Importer.Import(E->getLHS()); | 
|  | 4044 | if (!LHS) | 
|  | 4045 | return 0; | 
|  | 4046 |  | 
|  | 4047 | Expr *RHS = Importer.Import(E->getRHS()); | 
|  | 4048 | if (!RHS) | 
|  | 4049 | return 0; | 
|  | 4050 |  | 
|  | 4051 | return new (Importer.getToContext()) | 
|  | 4052 | CompoundAssignOperator(LHS, RHS, E->getOpcode(), | 
| John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 4053 | T, E->getValueKind(), | 
|  | 4054 | E->getObjectKind(), | 
|  | 4055 | CompLHSType, CompResultType, | 
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4056 | Importer.Import(E->getOperatorLoc())); | 
|  | 4057 | } | 
|  | 4058 |  | 
| Benjamin Kramer | 8aef596 | 2011-03-26 12:38:21 +0000 | [diff] [blame] | 4059 | static bool ImportCastPath(CastExpr *E, CXXCastPath &Path) { | 
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 4060 | if (E->path_empty()) return false; | 
|  | 4061 |  | 
|  | 4062 | // TODO: import cast paths | 
|  | 4063 | return true; | 
|  | 4064 | } | 
|  | 4065 |  | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 4066 | Expr *ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { | 
|  | 4067 | QualType T = Importer.Import(E->getType()); | 
|  | 4068 | if (T.isNull()) | 
|  | 4069 | return 0; | 
|  | 4070 |  | 
|  | 4071 | Expr *SubExpr = Importer.Import(E->getSubExpr()); | 
|  | 4072 | if (!SubExpr) | 
|  | 4073 | return 0; | 
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 4074 |  | 
|  | 4075 | CXXCastPath BasePath; | 
|  | 4076 | if (ImportCastPath(E, BasePath)) | 
|  | 4077 | return 0; | 
|  | 4078 |  | 
|  | 4079 | return ImplicitCastExpr::Create(Importer.getToContext(), T, E->getCastKind(), | 
| John McCall | 2536c6d | 2010-08-25 10:28:54 +0000 | [diff] [blame] | 4080 | SubExpr, &BasePath, E->getValueKind()); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 4081 | } | 
|  | 4082 |  | 
| Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 4083 | Expr *ASTNodeImporter::VisitCStyleCastExpr(CStyleCastExpr *E) { | 
|  | 4084 | QualType T = Importer.Import(E->getType()); | 
|  | 4085 | if (T.isNull()) | 
|  | 4086 | return 0; | 
|  | 4087 |  | 
|  | 4088 | Expr *SubExpr = Importer.Import(E->getSubExpr()); | 
|  | 4089 | if (!SubExpr) | 
|  | 4090 | return 0; | 
|  | 4091 |  | 
|  | 4092 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeInfoAsWritten()); | 
|  | 4093 | if (!TInfo && E->getTypeInfoAsWritten()) | 
|  | 4094 | return 0; | 
|  | 4095 |  | 
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 4096 | CXXCastPath BasePath; | 
|  | 4097 | if (ImportCastPath(E, BasePath)) | 
|  | 4098 | return 0; | 
|  | 4099 |  | 
| John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 4100 | return CStyleCastExpr::Create(Importer.getToContext(), T, | 
|  | 4101 | E->getValueKind(), E->getCastKind(), | 
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 4102 | SubExpr, &BasePath, TInfo, | 
|  | 4103 | Importer.Import(E->getLParenLoc()), | 
|  | 4104 | Importer.Import(E->getRParenLoc())); | 
| Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 4105 | } | 
|  | 4106 |  | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 4107 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, | 
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 4108 | ASTContext &FromContext, FileManager &FromFileManager, | 
|  | 4109 | bool MinimalImport) | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 4110 | : ToContext(ToContext), FromContext(FromContext), | 
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 4111 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), | 
|  | 4112 | Minimal(MinimalImport) | 
|  | 4113 | { | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 4114 | ImportedDecls[FromContext.getTranslationUnitDecl()] | 
|  | 4115 | = ToContext.getTranslationUnitDecl(); | 
|  | 4116 | } | 
|  | 4117 |  | 
|  | 4118 | ASTImporter::~ASTImporter() { } | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 4119 |  | 
|  | 4120 | QualType ASTImporter::Import(QualType FromT) { | 
|  | 4121 | if (FromT.isNull()) | 
|  | 4122 | return QualType(); | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4123 |  | 
|  | 4124 | const Type *fromTy = FromT.getTypePtr(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 4125 |  | 
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 4126 | // Check whether we've already imported this type. | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4127 | llvm::DenseMap<const Type *, const Type *>::iterator Pos | 
|  | 4128 | = ImportedTypes.find(fromTy); | 
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 4129 | if (Pos != ImportedTypes.end()) | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4130 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 4131 |  | 
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 4132 | // Import the type | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 4133 | ASTNodeImporter Importer(*this); | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4134 | QualType ToT = Importer.Visit(fromTy); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 4135 | if (ToT.isNull()) | 
|  | 4136 | return ToT; | 
|  | 4137 |  | 
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 4138 | // Record the imported type. | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4139 | ImportedTypes[fromTy] = ToT.getTypePtr(); | 
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 4140 |  | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4141 | return ToContext.getQualifiedType(ToT, FromT.getLocalQualifiers()); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 4142 | } | 
|  | 4143 |  | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 4144 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { | 
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 4145 | if (!FromTSI) | 
|  | 4146 | return FromTSI; | 
|  | 4147 |  | 
|  | 4148 | // FIXME: For now we just create a "trivial" type source info based | 
| Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4149 | // on the type and a single location. Implement a real version of this. | 
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 4150 | QualType T = Import(FromTSI->getType()); | 
|  | 4151 | if (T.isNull()) | 
|  | 4152 | return 0; | 
|  | 4153 |  | 
|  | 4154 | return ToContext.getTrivialTypeSourceInfo(T, | 
| Abramo Bagnara | 1108e7b | 2010-05-20 10:00:11 +0000 | [diff] [blame] | 4155 | FromTSI->getTypeLoc().getSourceRange().getBegin()); | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 4156 | } | 
|  | 4157 |  | 
|  | 4158 | Decl *ASTImporter::Import(Decl *FromD) { | 
|  | 4159 | if (!FromD) | 
|  | 4160 | return 0; | 
|  | 4161 |  | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 4162 | ASTNodeImporter Importer(*this); | 
|  | 4163 |  | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 4164 | // Check whether we've already imported this declaration. | 
|  | 4165 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 4166 | if (Pos != ImportedDecls.end()) { | 
|  | 4167 | Decl *ToD = Pos->second; | 
|  | 4168 | Importer.ImportDefinitionIfNeeded(FromD, ToD); | 
|  | 4169 | return ToD; | 
|  | 4170 | } | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 4171 |  | 
|  | 4172 | // Import the type | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 4173 | Decl *ToD = Importer.Visit(FromD); | 
|  | 4174 | if (!ToD) | 
|  | 4175 | return 0; | 
|  | 4176 |  | 
|  | 4177 | // Record the imported declaration. | 
|  | 4178 | ImportedDecls[FromD] = ToD; | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 4179 |  | 
|  | 4180 | if (TagDecl *FromTag = dyn_cast<TagDecl>(FromD)) { | 
|  | 4181 | // Keep track of anonymous tags that have an associated typedef. | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4182 | if (FromTag->getTypedefNameForAnonDecl()) | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 4183 | AnonTagsWithPendingTypedefs.push_back(FromTag); | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4184 | } else if (TypedefNameDecl *FromTypedef = dyn_cast<TypedefNameDecl>(FromD)) { | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 4185 | // When we've finished transforming a typedef, see whether it was the | 
|  | 4186 | // typedef for an anonymous tag. | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4187 | for (SmallVector<TagDecl *, 4>::iterator | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 4188 | FromTag = AnonTagsWithPendingTypedefs.begin(), | 
|  | 4189 | FromTagEnd = AnonTagsWithPendingTypedefs.end(); | 
|  | 4190 | FromTag != FromTagEnd; ++FromTag) { | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4191 | if ((*FromTag)->getTypedefNameForAnonDecl() == FromTypedef) { | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 4192 | if (TagDecl *ToTag = cast_or_null<TagDecl>(Import(*FromTag))) { | 
|  | 4193 | // We found the typedef for an anonymous tag; link them. | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4194 | ToTag->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(ToD)); | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 4195 | AnonTagsWithPendingTypedefs.erase(FromTag); | 
|  | 4196 | break; | 
|  | 4197 | } | 
|  | 4198 | } | 
|  | 4199 | } | 
|  | 4200 | } | 
|  | 4201 |  | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 4202 | return ToD; | 
|  | 4203 | } | 
|  | 4204 |  | 
|  | 4205 | DeclContext *ASTImporter::ImportContext(DeclContext *FromDC) { | 
|  | 4206 | if (!FromDC) | 
|  | 4207 | return FromDC; | 
|  | 4208 |  | 
|  | 4209 | return cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); | 
|  | 4210 | } | 
|  | 4211 |  | 
|  | 4212 | Expr *ASTImporter::Import(Expr *FromE) { | 
|  | 4213 | if (!FromE) | 
|  | 4214 | return 0; | 
|  | 4215 |  | 
|  | 4216 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); | 
|  | 4217 | } | 
|  | 4218 |  | 
|  | 4219 | Stmt *ASTImporter::Import(Stmt *FromS) { | 
|  | 4220 | if (!FromS) | 
|  | 4221 | return 0; | 
|  | 4222 |  | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4223 | // Check whether we've already imported this declaration. | 
|  | 4224 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); | 
|  | 4225 | if (Pos != ImportedStmts.end()) | 
|  | 4226 | return Pos->second; | 
|  | 4227 |  | 
|  | 4228 | // Import the type | 
|  | 4229 | ASTNodeImporter Importer(*this); | 
|  | 4230 | Stmt *ToS = Importer.Visit(FromS); | 
|  | 4231 | if (!ToS) | 
|  | 4232 | return 0; | 
|  | 4233 |  | 
|  | 4234 | // Record the imported declaration. | 
|  | 4235 | ImportedStmts[FromS] = ToS; | 
|  | 4236 | return ToS; | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 4237 | } | 
|  | 4238 |  | 
|  | 4239 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { | 
|  | 4240 | if (!FromNNS) | 
|  | 4241 | return 0; | 
|  | 4242 |  | 
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 4243 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); | 
|  | 4244 |  | 
|  | 4245 | switch (FromNNS->getKind()) { | 
|  | 4246 | case NestedNameSpecifier::Identifier: | 
|  | 4247 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { | 
|  | 4248 | return NestedNameSpecifier::Create(ToContext, prefix, II); | 
|  | 4249 | } | 
|  | 4250 | return 0; | 
|  | 4251 |  | 
|  | 4252 | case NestedNameSpecifier::Namespace: | 
|  | 4253 | if (NamespaceDecl *NS = | 
|  | 4254 | cast<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { | 
|  | 4255 | return NestedNameSpecifier::Create(ToContext, prefix, NS); | 
|  | 4256 | } | 
|  | 4257 | return 0; | 
|  | 4258 |  | 
|  | 4259 | case NestedNameSpecifier::NamespaceAlias: | 
|  | 4260 | if (NamespaceAliasDecl *NSAD = | 
|  | 4261 | cast<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { | 
|  | 4262 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); | 
|  | 4263 | } | 
|  | 4264 | return 0; | 
|  | 4265 |  | 
|  | 4266 | case NestedNameSpecifier::Global: | 
|  | 4267 | return NestedNameSpecifier::GlobalSpecifier(ToContext); | 
|  | 4268 |  | 
|  | 4269 | case NestedNameSpecifier::TypeSpec: | 
|  | 4270 | case NestedNameSpecifier::TypeSpecWithTemplate: { | 
|  | 4271 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); | 
|  | 4272 | if (!T.isNull()) { | 
|  | 4273 | bool bTemplate = FromNNS->getKind() == | 
|  | 4274 | NestedNameSpecifier::TypeSpecWithTemplate; | 
|  | 4275 | return NestedNameSpecifier::Create(ToContext, prefix, | 
|  | 4276 | bTemplate, T.getTypePtr()); | 
|  | 4277 | } | 
|  | 4278 | } | 
|  | 4279 | return 0; | 
|  | 4280 | } | 
|  | 4281 |  | 
|  | 4282 | llvm_unreachable("Invalid nested name specifier kind"); | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 4283 | return 0; | 
|  | 4284 | } | 
|  | 4285 |  | 
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4286 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { | 
|  | 4287 | // FIXME: Implement! | 
|  | 4288 | return NestedNameSpecifierLoc(); | 
|  | 4289 | } | 
|  | 4290 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4291 | TemplateName ASTImporter::Import(TemplateName From) { | 
|  | 4292 | switch (From.getKind()) { | 
|  | 4293 | case TemplateName::Template: | 
|  | 4294 | if (TemplateDecl *ToTemplate | 
|  | 4295 | = cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) | 
|  | 4296 | return TemplateName(ToTemplate); | 
|  | 4297 |  | 
|  | 4298 | return TemplateName(); | 
|  | 4299 |  | 
|  | 4300 | case TemplateName::OverloadedTemplate: { | 
|  | 4301 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); | 
|  | 4302 | UnresolvedSet<2> ToTemplates; | 
|  | 4303 | for (OverloadedTemplateStorage::iterator I = FromStorage->begin(), | 
|  | 4304 | E = FromStorage->end(); | 
|  | 4305 | I != E; ++I) { | 
|  | 4306 | if (NamedDecl *To = cast_or_null<NamedDecl>(Import(*I))) | 
|  | 4307 | ToTemplates.addDecl(To); | 
|  | 4308 | else | 
|  | 4309 | return TemplateName(); | 
|  | 4310 | } | 
|  | 4311 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), | 
|  | 4312 | ToTemplates.end()); | 
|  | 4313 | } | 
|  | 4314 |  | 
|  | 4315 | case TemplateName::QualifiedTemplate: { | 
|  | 4316 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); | 
|  | 4317 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); | 
|  | 4318 | if (!Qualifier) | 
|  | 4319 | return TemplateName(); | 
|  | 4320 |  | 
|  | 4321 | if (TemplateDecl *ToTemplate | 
|  | 4322 | = cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) | 
|  | 4323 | return ToContext.getQualifiedTemplateName(Qualifier, | 
|  | 4324 | QTN->hasTemplateKeyword(), | 
|  | 4325 | ToTemplate); | 
|  | 4326 |  | 
|  | 4327 | return TemplateName(); | 
|  | 4328 | } | 
|  | 4329 |  | 
|  | 4330 | case TemplateName::DependentTemplate: { | 
|  | 4331 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); | 
|  | 4332 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); | 
|  | 4333 | if (!Qualifier) | 
|  | 4334 | return TemplateName(); | 
|  | 4335 |  | 
|  | 4336 | if (DTN->isIdentifier()) { | 
|  | 4337 | return ToContext.getDependentTemplateName(Qualifier, | 
|  | 4338 | Import(DTN->getIdentifier())); | 
|  | 4339 | } | 
|  | 4340 |  | 
|  | 4341 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); | 
|  | 4342 | } | 
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 4343 |  | 
|  | 4344 | case TemplateName::SubstTemplateTemplateParm: { | 
|  | 4345 | SubstTemplateTemplateParmStorage *subst | 
|  | 4346 | = From.getAsSubstTemplateTemplateParm(); | 
|  | 4347 | TemplateTemplateParmDecl *param | 
|  | 4348 | = cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); | 
|  | 4349 | if (!param) | 
|  | 4350 | return TemplateName(); | 
|  | 4351 |  | 
|  | 4352 | TemplateName replacement = Import(subst->getReplacement()); | 
|  | 4353 | if (replacement.isNull()) return TemplateName(); | 
|  | 4354 |  | 
|  | 4355 | return ToContext.getSubstTemplateTemplateParm(param, replacement); | 
|  | 4356 | } | 
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4357 |  | 
|  | 4358 | case TemplateName::SubstTemplateTemplateParmPack: { | 
|  | 4359 | SubstTemplateTemplateParmPackStorage *SubstPack | 
|  | 4360 | = From.getAsSubstTemplateTemplateParmPack(); | 
|  | 4361 | TemplateTemplateParmDecl *Param | 
|  | 4362 | = cast_or_null<TemplateTemplateParmDecl>( | 
|  | 4363 | Import(SubstPack->getParameterPack())); | 
|  | 4364 | if (!Param) | 
|  | 4365 | return TemplateName(); | 
|  | 4366 |  | 
|  | 4367 | ASTNodeImporter Importer(*this); | 
|  | 4368 | TemplateArgument ArgPack | 
|  | 4369 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); | 
|  | 4370 | if (ArgPack.isNull()) | 
|  | 4371 | return TemplateName(); | 
|  | 4372 |  | 
|  | 4373 | return ToContext.getSubstTemplateTemplateParmPack(Param, ArgPack); | 
|  | 4374 | } | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4375 | } | 
|  | 4376 |  | 
|  | 4377 | llvm_unreachable("Invalid template name kind"); | 
|  | 4378 | return TemplateName(); | 
|  | 4379 | } | 
|  | 4380 |  | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 4381 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { | 
|  | 4382 | if (FromLoc.isInvalid()) | 
|  | 4383 | return SourceLocation(); | 
|  | 4384 |  | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 4385 | SourceManager &FromSM = FromContext.getSourceManager(); | 
|  | 4386 |  | 
|  | 4387 | // For now, map everything down to its spelling location, so that we | 
| Chandler Carruth | 2536641 | 2011-07-15 00:04:35 +0000 | [diff] [blame] | 4388 | // don't have to import macro expansions. | 
|  | 4389 | // FIXME: Import macro expansions! | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 4390 | FromLoc = FromSM.getSpellingLoc(FromLoc); | 
|  | 4391 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); | 
|  | 4392 | SourceManager &ToSM = ToContext.getSourceManager(); | 
|  | 4393 | return ToSM.getLocForStartOfFile(Import(Decomposed.first)) | 
| Argyrios Kyrtzidis | e6e67de | 2011-09-19 20:40:19 +0000 | [diff] [blame] | 4394 | .getLocWithOffset(Decomposed.second); | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 4395 | } | 
|  | 4396 |  | 
|  | 4397 | SourceRange ASTImporter::Import(SourceRange FromRange) { | 
|  | 4398 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); | 
|  | 4399 | } | 
|  | 4400 |  | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 4401 | FileID ASTImporter::Import(FileID FromID) { | 
| Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 4402 | llvm::DenseMap<FileID, FileID>::iterator Pos | 
|  | 4403 | = ImportedFileIDs.find(FromID); | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 4404 | if (Pos != ImportedFileIDs.end()) | 
|  | 4405 | return Pos->second; | 
|  | 4406 |  | 
|  | 4407 | SourceManager &FromSM = FromContext.getSourceManager(); | 
|  | 4408 | SourceManager &ToSM = ToContext.getSourceManager(); | 
|  | 4409 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); | 
| Chandler Carruth | 2536641 | 2011-07-15 00:04:35 +0000 | [diff] [blame] | 4410 | assert(FromSLoc.isFile() && "Cannot handle macro expansions yet"); | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 4411 |  | 
|  | 4412 | // Include location of this file. | 
|  | 4413 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); | 
|  | 4414 |  | 
|  | 4415 | // Map the FileID for to the "to" source manager. | 
|  | 4416 | FileID ToID; | 
|  | 4417 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); | 
| Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 4418 | if (Cache->OrigEntry) { | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 4419 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the | 
|  | 4420 | // disk again | 
|  | 4421 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather | 
|  | 4422 | // than mmap the files several times. | 
| Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 4423 | const FileEntry *Entry = ToFileManager.getFile(Cache->OrigEntry->getName()); | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 4424 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, | 
|  | 4425 | FromSLoc.getFile().getFileCharacteristic()); | 
|  | 4426 | } else { | 
|  | 4427 | // FIXME: We want to re-use the existing MemoryBuffer! | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 4428 | const llvm::MemoryBuffer * | 
|  | 4429 | FromBuf = Cache->getBuffer(FromContext.getDiagnostics(), FromSM); | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 4430 | llvm::MemoryBuffer *ToBuf | 
| Chris Lattner | 58c7934 | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 4431 | = llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 4432 | FromBuf->getBufferIdentifier()); | 
|  | 4433 | ToID = ToSM.createFileIDForMemBuffer(ToBuf); | 
|  | 4434 | } | 
|  | 4435 |  | 
|  | 4436 |  | 
| Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 4437 | ImportedFileIDs[FromID] = ToID; | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 4438 | return ToID; | 
|  | 4439 | } | 
|  | 4440 |  | 
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 4441 | void ASTImporter::ImportDefinition(Decl *From) { | 
|  | 4442 | Decl *To = Import(From); | 
|  | 4443 | if (!To) | 
|  | 4444 | return; | 
|  | 4445 |  | 
|  | 4446 | if (DeclContext *FromDC = cast<DeclContext>(From)) { | 
|  | 4447 | ASTNodeImporter Importer(*this); | 
| Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 4448 |  | 
|  | 4449 | if (RecordDecl *ToRecord = dyn_cast<RecordDecl>(To)) { | 
|  | 4450 | if (!ToRecord->getDefinition()) { | 
|  | 4451 | Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord, | 
|  | 4452 | /*ForceImport=*/true); | 
|  | 4453 | return; | 
|  | 4454 | } | 
|  | 4455 | } | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 4456 |  | 
|  | 4457 | if (EnumDecl *ToEnum = dyn_cast<EnumDecl>(To)) { | 
|  | 4458 | if (!ToEnum->getDefinition()) { | 
|  | 4459 | Importer.ImportDefinition(cast<EnumDecl>(FromDC), ToEnum, | 
|  | 4460 | /*ForceImport=*/true); | 
|  | 4461 | return; | 
|  | 4462 | } | 
|  | 4463 | } | 
|  | 4464 |  | 
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 4465 | Importer.ImportDeclContext(FromDC, true); | 
|  | 4466 | } | 
|  | 4467 | } | 
|  | 4468 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 4469 | DeclarationName ASTImporter::Import(DeclarationName FromName) { | 
|  | 4470 | if (!FromName) | 
|  | 4471 | return DeclarationName(); | 
|  | 4472 |  | 
|  | 4473 | switch (FromName.getNameKind()) { | 
|  | 4474 | case DeclarationName::Identifier: | 
|  | 4475 | return Import(FromName.getAsIdentifierInfo()); | 
|  | 4476 |  | 
|  | 4477 | case DeclarationName::ObjCZeroArgSelector: | 
|  | 4478 | case DeclarationName::ObjCOneArgSelector: | 
|  | 4479 | case DeclarationName::ObjCMultiArgSelector: | 
|  | 4480 | return Import(FromName.getObjCSelector()); | 
|  | 4481 |  | 
|  | 4482 | case DeclarationName::CXXConstructorName: { | 
|  | 4483 | QualType T = Import(FromName.getCXXNameType()); | 
|  | 4484 | if (T.isNull()) | 
|  | 4485 | return DeclarationName(); | 
|  | 4486 |  | 
|  | 4487 | return ToContext.DeclarationNames.getCXXConstructorName( | 
|  | 4488 | ToContext.getCanonicalType(T)); | 
|  | 4489 | } | 
|  | 4490 |  | 
|  | 4491 | case DeclarationName::CXXDestructorName: { | 
|  | 4492 | QualType T = Import(FromName.getCXXNameType()); | 
|  | 4493 | if (T.isNull()) | 
|  | 4494 | return DeclarationName(); | 
|  | 4495 |  | 
|  | 4496 | return ToContext.DeclarationNames.getCXXDestructorName( | 
|  | 4497 | ToContext.getCanonicalType(T)); | 
|  | 4498 | } | 
|  | 4499 |  | 
|  | 4500 | case DeclarationName::CXXConversionFunctionName: { | 
|  | 4501 | QualType T = Import(FromName.getCXXNameType()); | 
|  | 4502 | if (T.isNull()) | 
|  | 4503 | return DeclarationName(); | 
|  | 4504 |  | 
|  | 4505 | return ToContext.DeclarationNames.getCXXConversionFunctionName( | 
|  | 4506 | ToContext.getCanonicalType(T)); | 
|  | 4507 | } | 
|  | 4508 |  | 
|  | 4509 | case DeclarationName::CXXOperatorName: | 
|  | 4510 | return ToContext.DeclarationNames.getCXXOperatorName( | 
|  | 4511 | FromName.getCXXOverloadedOperator()); | 
|  | 4512 |  | 
|  | 4513 | case DeclarationName::CXXLiteralOperatorName: | 
|  | 4514 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( | 
|  | 4515 | Import(FromName.getCXXLiteralIdentifier())); | 
|  | 4516 |  | 
|  | 4517 | case DeclarationName::CXXUsingDirective: | 
|  | 4518 | // FIXME: STATICS! | 
|  | 4519 | return DeclarationName::getUsingDirectiveName(); | 
|  | 4520 | } | 
|  | 4521 |  | 
|  | 4522 | // Silence bogus GCC warning | 
|  | 4523 | return DeclarationName(); | 
|  | 4524 | } | 
|  | 4525 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4526 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 4527 | if (!FromId) | 
|  | 4528 | return 0; | 
|  | 4529 |  | 
|  | 4530 | return &ToContext.Idents.get(FromId->getName()); | 
|  | 4531 | } | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 4532 |  | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4533 | Selector ASTImporter::Import(Selector FromSel) { | 
|  | 4534 | if (FromSel.isNull()) | 
|  | 4535 | return Selector(); | 
|  | 4536 |  | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4537 | SmallVector<IdentifierInfo *, 4> Idents; | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4538 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); | 
|  | 4539 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) | 
|  | 4540 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); | 
|  | 4541 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); | 
|  | 4542 | } | 
|  | 4543 |  | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 4544 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, | 
|  | 4545 | DeclContext *DC, | 
|  | 4546 | unsigned IDNS, | 
|  | 4547 | NamedDecl **Decls, | 
|  | 4548 | unsigned NumDecls) { | 
|  | 4549 | return Name; | 
|  | 4550 | } | 
|  | 4551 |  | 
|  | 4552 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 4553 | return ToContext.getDiagnostics().Report(Loc, DiagID); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 4554 | } | 
|  | 4555 |  | 
|  | 4556 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 4557 | return FromContext.getDiagnostics().Report(Loc, DiagID); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 4558 | } | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 4559 |  | 
|  | 4560 | Decl *ASTImporter::Imported(Decl *From, Decl *To) { | 
|  | 4561 | ImportedDecls[From] = To; | 
|  | 4562 | return To; | 
| Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 4563 | } | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 4564 |  | 
|  | 4565 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To) { | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4566 | llvm::DenseMap<const Type *, const Type *>::iterator Pos | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 4567 | = ImportedTypes.find(From.getTypePtr()); | 
|  | 4568 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) | 
|  | 4569 | return true; | 
|  | 4570 |  | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 4571 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls); | 
| Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 4572 | return Ctx.IsStructurallyEquivalent(From, To); | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 4573 | } |