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