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" |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTStructuralEquivalence.h" |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclObjC.h" |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclVisitor.h" |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 21 | #include "clang/AST/StmtVisitor.h" |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 22 | #include "clang/AST/TypeVisitor.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 23 | #include "clang/Basic/FileManager.h" |
| 24 | #include "clang/Basic/SourceManager.h" |
| 25 | #include "llvm/Support/MemoryBuffer.h" |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 26 | #include <deque> |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 27 | |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 28 | namespace clang { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 29 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, QualType>, |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 30 | public DeclVisitor<ASTNodeImporter, Decl *>, |
| 31 | public StmtVisitor<ASTNodeImporter, Stmt *> { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 32 | ASTImporter &Importer; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 33 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 34 | public: |
| 35 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) { } |
| 36 | |
| 37 | using TypeVisitor<ASTNodeImporter, QualType>::Visit; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 38 | using DeclVisitor<ASTNodeImporter, Decl *>::Visit; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 39 | using StmtVisitor<ASTNodeImporter, Stmt *>::Visit; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 40 | |
| 41 | // Importing types |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 42 | QualType VisitType(const Type *T); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 43 | QualType VisitAtomicType(const AtomicType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 44 | QualType VisitBuiltinType(const BuiltinType *T); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 45 | QualType VisitDecayedType(const DecayedType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 46 | QualType VisitComplexType(const ComplexType *T); |
| 47 | QualType VisitPointerType(const PointerType *T); |
| 48 | QualType VisitBlockPointerType(const BlockPointerType *T); |
| 49 | QualType VisitLValueReferenceType(const LValueReferenceType *T); |
| 50 | QualType VisitRValueReferenceType(const RValueReferenceType *T); |
| 51 | QualType VisitMemberPointerType(const MemberPointerType *T); |
| 52 | QualType VisitConstantArrayType(const ConstantArrayType *T); |
| 53 | QualType VisitIncompleteArrayType(const IncompleteArrayType *T); |
| 54 | QualType VisitVariableArrayType(const VariableArrayType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 55 | // FIXME: DependentSizedArrayType |
| 56 | // FIXME: DependentSizedExtVectorType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 57 | QualType VisitVectorType(const VectorType *T); |
| 58 | QualType VisitExtVectorType(const ExtVectorType *T); |
| 59 | QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T); |
| 60 | QualType VisitFunctionProtoType(const FunctionProtoType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 61 | // FIXME: UnresolvedUsingType |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 62 | QualType VisitParenType(const ParenType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 63 | QualType VisitTypedefType(const TypedefType *T); |
| 64 | QualType VisitTypeOfExprType(const TypeOfExprType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 65 | // FIXME: DependentTypeOfExprType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 66 | QualType VisitTypeOfType(const TypeOfType *T); |
| 67 | QualType VisitDecltypeType(const DecltypeType *T); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 68 | QualType VisitUnaryTransformType(const UnaryTransformType *T); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 69 | QualType VisitAutoType(const AutoType *T); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 70 | QualType VisitInjectedClassNameType(const InjectedClassNameType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 71 | // FIXME: DependentDecltypeType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 72 | QualType VisitRecordType(const RecordType *T); |
| 73 | QualType VisitEnumType(const EnumType *T); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 74 | QualType VisitAttributedType(const AttributedType *T); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 75 | QualType VisitTemplateTypeParmType(const TemplateTypeParmType *T); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 76 | QualType VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 77 | QualType VisitTemplateSpecializationType(const TemplateSpecializationType *T); |
| 78 | QualType VisitElaboratedType(const ElaboratedType *T); |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 79 | // FIXME: DependentNameType |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 80 | // FIXME: DependentTemplateSpecializationType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 81 | QualType VisitObjCInterfaceType(const ObjCInterfaceType *T); |
| 82 | QualType VisitObjCObjectType(const ObjCObjectType *T); |
| 83 | QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 84 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 85 | // Importing declarations |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 86 | bool ImportDeclParts(NamedDecl *D, DeclContext *&DC, |
| 87 | DeclContext *&LexicalDC, DeclarationName &Name, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 88 | NamedDecl *&ToD, SourceLocation &Loc); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 89 | void ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 90 | void ImportDeclarationNameLoc(const DeclarationNameInfo &From, |
| 91 | DeclarationNameInfo& To); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 92 | void ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 93 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 94 | bool ImportCastPath(CastExpr *E, CXXCastPath &Path); |
| 95 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 96 | typedef DesignatedInitExpr::Designator Designator; |
| 97 | Designator ImportDesignator(const Designator &D); |
| 98 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 99 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 100 | /// \brief What we should import from the definition. |
| 101 | enum ImportDefinitionKind { |
| 102 | /// \brief Import the default subset of the definition, which might be |
| 103 | /// nothing (if minimal import is set) or might be everything (if minimal |
| 104 | /// import is not set). |
| 105 | IDK_Default, |
| 106 | /// \brief Import everything. |
| 107 | IDK_Everything, |
| 108 | /// \brief Import only the bare bones needed to establish a valid |
| 109 | /// DeclContext. |
| 110 | IDK_Basic |
| 111 | }; |
| 112 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 113 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { |
| 114 | return IDK == IDK_Everything || |
| 115 | (IDK == IDK_Default && !Importer.isMinimalImport()); |
| 116 | } |
| 117 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 118 | bool ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 119 | ImportDefinitionKind Kind = IDK_Default); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 120 | bool ImportDefinition(VarDecl *From, VarDecl *To, |
| 121 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 122 | bool ImportDefinition(EnumDecl *From, EnumDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 123 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 124 | bool ImportDefinition(ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 125 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 126 | bool ImportDefinition(ObjCProtocolDecl *From, ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 127 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 128 | TemplateParameterList *ImportTemplateParameterList( |
| 129 | TemplateParameterList *Params); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 130 | TemplateArgument ImportTemplateArgument(const TemplateArgument &From); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 131 | TemplateArgumentLoc ImportTemplateArgumentLoc( |
| 132 | const TemplateArgumentLoc &TALoc, bool &Error); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 133 | bool ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 134 | unsigned NumFromArgs, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 135 | SmallVectorImpl<TemplateArgument> &ToArgs); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 136 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, |
| 137 | bool Complain = true); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 138 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 139 | bool Complain = true); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 140 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 141 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 142 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 143 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 144 | Decl *VisitDecl(Decl *D); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 145 | Decl *VisitAccessSpecDecl(AccessSpecDecl *D); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 146 | Decl *VisitStaticAssertDecl(StaticAssertDecl *D); |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 147 | Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 148 | Decl *VisitNamespaceDecl(NamespaceDecl *D); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 149 | Decl *VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 150 | Decl *VisitTypedefDecl(TypedefDecl *D); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 151 | Decl *VisitTypeAliasDecl(TypeAliasDecl *D); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 152 | Decl *VisitLabelDecl(LabelDecl *D); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 153 | Decl *VisitEnumDecl(EnumDecl *D); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 154 | Decl *VisitRecordDecl(RecordDecl *D); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 155 | Decl *VisitEnumConstantDecl(EnumConstantDecl *D); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 156 | Decl *VisitFunctionDecl(FunctionDecl *D); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 157 | Decl *VisitCXXMethodDecl(CXXMethodDecl *D); |
| 158 | Decl *VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 159 | Decl *VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 160 | Decl *VisitCXXConversionDecl(CXXConversionDecl *D); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 161 | Decl *VisitFieldDecl(FieldDecl *D); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 162 | Decl *VisitIndirectFieldDecl(IndirectFieldDecl *D); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 163 | Decl *VisitFriendDecl(FriendDecl *D); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 164 | Decl *VisitObjCIvarDecl(ObjCIvarDecl *D); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 165 | Decl *VisitVarDecl(VarDecl *D); |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 166 | Decl *VisitImplicitParamDecl(ImplicitParamDecl *D); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 167 | Decl *VisitParmVarDecl(ParmVarDecl *D); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 168 | Decl *VisitObjCMethodDecl(ObjCMethodDecl *D); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 169 | Decl *VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 170 | Decl *VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 171 | Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 172 | Decl *VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 173 | |
| 174 | ObjCTypeParamList *ImportObjCTypeParamList(ObjCTypeParamList *list); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 175 | Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 176 | Decl *VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 177 | Decl *VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 178 | Decl *VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 179 | Decl *VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 180 | Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 181 | Decl *VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 182 | Decl *VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 183 | Decl *VisitClassTemplateDecl(ClassTemplateDecl *D); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 184 | Decl *VisitClassTemplateSpecializationDecl( |
| 185 | ClassTemplateSpecializationDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 186 | Decl *VisitVarTemplateDecl(VarTemplateDecl *D); |
| 187 | Decl *VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
| 188 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 189 | // Importing statements |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 190 | DeclGroupRef ImportDeclGroup(DeclGroupRef DG); |
| 191 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 192 | Stmt *VisitStmt(Stmt *S); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 193 | Stmt *VisitGCCAsmStmt(GCCAsmStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 194 | Stmt *VisitDeclStmt(DeclStmt *S); |
| 195 | Stmt *VisitNullStmt(NullStmt *S); |
| 196 | Stmt *VisitCompoundStmt(CompoundStmt *S); |
| 197 | Stmt *VisitCaseStmt(CaseStmt *S); |
| 198 | Stmt *VisitDefaultStmt(DefaultStmt *S); |
| 199 | Stmt *VisitLabelStmt(LabelStmt *S); |
| 200 | Stmt *VisitAttributedStmt(AttributedStmt *S); |
| 201 | Stmt *VisitIfStmt(IfStmt *S); |
| 202 | Stmt *VisitSwitchStmt(SwitchStmt *S); |
| 203 | Stmt *VisitWhileStmt(WhileStmt *S); |
| 204 | Stmt *VisitDoStmt(DoStmt *S); |
| 205 | Stmt *VisitForStmt(ForStmt *S); |
| 206 | Stmt *VisitGotoStmt(GotoStmt *S); |
| 207 | Stmt *VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 208 | Stmt *VisitContinueStmt(ContinueStmt *S); |
| 209 | Stmt *VisitBreakStmt(BreakStmt *S); |
| 210 | Stmt *VisitReturnStmt(ReturnStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 211 | // FIXME: MSAsmStmt |
| 212 | // FIXME: SEHExceptStmt |
| 213 | // FIXME: SEHFinallyStmt |
| 214 | // FIXME: SEHTryStmt |
| 215 | // FIXME: SEHLeaveStmt |
| 216 | // FIXME: CapturedStmt |
| 217 | Stmt *VisitCXXCatchStmt(CXXCatchStmt *S); |
| 218 | Stmt *VisitCXXTryStmt(CXXTryStmt *S); |
| 219 | Stmt *VisitCXXForRangeStmt(CXXForRangeStmt *S); |
| 220 | // FIXME: MSDependentExistsStmt |
| 221 | Stmt *VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); |
| 222 | Stmt *VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); |
| 223 | Stmt *VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); |
| 224 | Stmt *VisitObjCAtTryStmt(ObjCAtTryStmt *S); |
| 225 | Stmt *VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); |
| 226 | Stmt *VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); |
| 227 | Stmt *VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 228 | |
| 229 | // Importing expressions |
| 230 | Expr *VisitExpr(Expr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 231 | Expr *VisitVAArgExpr(VAArgExpr *E); |
| 232 | Expr *VisitGNUNullExpr(GNUNullExpr *E); |
| 233 | Expr *VisitPredefinedExpr(PredefinedExpr *E); |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 234 | Expr *VisitDeclRefExpr(DeclRefExpr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 235 | Expr *VisitImplicitValueInitExpr(ImplicitValueInitExpr *ILE); |
| 236 | Expr *VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 237 | Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 238 | Expr *VisitIntegerLiteral(IntegerLiteral *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 239 | Expr *VisitFloatingLiteral(FloatingLiteral *E); |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 240 | Expr *VisitCharacterLiteral(CharacterLiteral *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 241 | Expr *VisitStringLiteral(StringLiteral *E); |
| 242 | Expr *VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 243 | Expr *VisitAtomicExpr(AtomicExpr *E); |
| 244 | Expr *VisitAddrLabelExpr(AddrLabelExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 245 | Expr *VisitParenExpr(ParenExpr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 246 | Expr *VisitParenListExpr(ParenListExpr *E); |
| 247 | Expr *VisitStmtExpr(StmtExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 248 | Expr *VisitUnaryOperator(UnaryOperator *E); |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 249 | Expr *VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 250 | Expr *VisitBinaryOperator(BinaryOperator *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 251 | Expr *VisitConditionalOperator(ConditionalOperator *E); |
| 252 | Expr *VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 253 | Expr *VisitOpaqueValueExpr(OpaqueValueExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 254 | Expr *VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 255 | Expr *VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 256 | Expr *VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 257 | Expr *VisitCompoundAssignOperator(CompoundAssignOperator *E); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 258 | Expr *VisitImplicitCastExpr(ImplicitCastExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 259 | Expr *VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 260 | Expr *VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 261 | Expr *VisitCXXThrowExpr(CXXThrowExpr *E); |
| 262 | Expr *VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 263 | Expr *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 264 | Expr *VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 265 | Expr *VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 266 | Expr *VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE); |
| 267 | Expr *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
| 268 | Expr *VisitCXXNewExpr(CXXNewExpr *CE); |
| 269 | Expr *VisitCXXDeleteExpr(CXXDeleteExpr *E); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 270 | Expr *VisitCXXConstructExpr(CXXConstructExpr *E); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 271 | Expr *VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 272 | Expr *VisitExprWithCleanups(ExprWithCleanups *EWC); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 273 | Expr *VisitCXXThisExpr(CXXThisExpr *E); |
| 274 | Expr *VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 275 | Expr *VisitMemberExpr(MemberExpr *E); |
| 276 | Expr *VisitCallExpr(CallExpr *E); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 277 | Expr *VisitInitListExpr(InitListExpr *E); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 278 | Expr *VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 279 | Expr *VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 280 | Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 281 | Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 282 | Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
| 283 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 284 | |
| 285 | template<typename IIter, typename OIter> |
| 286 | void ImportArray(IIter Ibegin, IIter Iend, OIter Obegin) { |
| 287 | typedef typename std::remove_reference<decltype(*Obegin)>::type ItemT; |
| 288 | ASTImporter &ImporterRef = Importer; |
| 289 | std::transform(Ibegin, Iend, Obegin, |
| 290 | [&ImporterRef](ItemT From) -> ItemT { |
| 291 | return ImporterRef.Import(From); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 292 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | template<typename IIter, typename OIter> |
| 296 | bool ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
| 297 | typedef typename std::remove_reference<decltype(**Obegin)>::type ItemT; |
| 298 | ASTImporter &ImporterRef = Importer; |
| 299 | bool Failed = false; |
| 300 | std::transform(Ibegin, Iend, Obegin, |
| 301 | [&ImporterRef, &Failed](ItemT *From) -> ItemT * { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 302 | ItemT *To = cast_or_null<ItemT>( |
| 303 | ImporterRef.Import(From)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 304 | if (!To && From) |
| 305 | Failed = true; |
| 306 | return To; |
| 307 | }); |
| 308 | return Failed; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 309 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 310 | |
| 311 | template<typename InContainerTy, typename OutContainerTy> |
| 312 | bool ImportContainerChecked(const InContainerTy &InContainer, |
| 313 | OutContainerTy &OutContainer) { |
| 314 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), |
| 315 | OutContainer.begin()); |
| 316 | } |
| 317 | |
| 318 | template<typename InContainerTy, typename OIter> |
| 319 | bool ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
| 320 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 321 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 322 | |
| 323 | // Importing overrides. |
| 324 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 325 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 326 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 327 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 328 | //---------------------------------------------------------------------------- |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 329 | // Import Types |
| 330 | //---------------------------------------------------------------------------- |
| 331 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 332 | using namespace clang; |
| 333 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 334 | QualType ASTNodeImporter::VisitType(const Type *T) { |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 335 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 336 | << T->getTypeClassName(); |
| 337 | return QualType(); |
| 338 | } |
| 339 | |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 340 | QualType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 341 | QualType UnderlyingType = Importer.Import(T->getValueType()); |
| 342 | if(UnderlyingType.isNull()) |
| 343 | return QualType(); |
| 344 | |
| 345 | return Importer.getToContext().getAtomicType(UnderlyingType); |
| 346 | } |
| 347 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 348 | QualType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 349 | switch (T->getKind()) { |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 350 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 351 | case BuiltinType::Id: \ |
| 352 | return Importer.getToContext().SingletonId; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 353 | #include "clang/Basic/OpenCLImageTypes.def" |
John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 354 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 355 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 356 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 357 | #include "clang/AST/BuiltinTypes.def" |
| 358 | |
| 359 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 360 | // context supports C++. |
| 361 | |
| 362 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 363 | // context supports ObjC. |
| 364 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 365 | case BuiltinType::Char_U: |
| 366 | // The context we're importing from has an unsigned 'char'. If we're |
| 367 | // importing into a context with a signed 'char', translate to |
| 368 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 369 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 370 | return Importer.getToContext().UnsignedCharTy; |
| 371 | |
| 372 | return Importer.getToContext().CharTy; |
| 373 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 374 | case BuiltinType::Char_S: |
| 375 | // The context we're importing from has an unsigned 'char'. If we're |
| 376 | // importing into a context with a signed 'char', translate to |
| 377 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 378 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 379 | return Importer.getToContext().SignedCharTy; |
| 380 | |
| 381 | return Importer.getToContext().CharTy; |
| 382 | |
Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 383 | case BuiltinType::WChar_S: |
| 384 | case BuiltinType::WChar_U: |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 385 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 386 | // wchar_t? |
| 387 | return Importer.getToContext().WCharTy; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 388 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 389 | |
| 390 | llvm_unreachable("Invalid BuiltinType Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 393 | QualType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 394 | QualType OrigT = Importer.Import(T->getOriginalType()); |
| 395 | if (OrigT.isNull()) |
| 396 | return QualType(); |
| 397 | |
| 398 | return Importer.getToContext().getDecayedType(OrigT); |
| 399 | } |
| 400 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 401 | QualType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 402 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 403 | if (ToElementType.isNull()) |
| 404 | return QualType(); |
| 405 | |
| 406 | return Importer.getToContext().getComplexType(ToElementType); |
| 407 | } |
| 408 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 409 | QualType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 410 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 411 | if (ToPointeeType.isNull()) |
| 412 | return QualType(); |
| 413 | |
| 414 | return Importer.getToContext().getPointerType(ToPointeeType); |
| 415 | } |
| 416 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 417 | QualType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 418 | // FIXME: Check for blocks support in "to" context. |
| 419 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 420 | if (ToPointeeType.isNull()) |
| 421 | return QualType(); |
| 422 | |
| 423 | return Importer.getToContext().getBlockPointerType(ToPointeeType); |
| 424 | } |
| 425 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 426 | QualType |
| 427 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 428 | // FIXME: Check for C++ support in "to" context. |
| 429 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 430 | if (ToPointeeType.isNull()) |
| 431 | return QualType(); |
| 432 | |
| 433 | return Importer.getToContext().getLValueReferenceType(ToPointeeType); |
| 434 | } |
| 435 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 436 | QualType |
| 437 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 438 | // FIXME: Check for C++0x support in "to" context. |
| 439 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 440 | if (ToPointeeType.isNull()) |
| 441 | return QualType(); |
| 442 | |
| 443 | return Importer.getToContext().getRValueReferenceType(ToPointeeType); |
| 444 | } |
| 445 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 446 | QualType ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 447 | // FIXME: Check for C++ support in "to" context. |
| 448 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 449 | if (ToPointeeType.isNull()) |
| 450 | return QualType(); |
| 451 | |
| 452 | QualType ClassType = Importer.Import(QualType(T->getClass(), 0)); |
| 453 | return Importer.getToContext().getMemberPointerType(ToPointeeType, |
| 454 | ClassType.getTypePtr()); |
| 455 | } |
| 456 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 457 | QualType ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 458 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 459 | if (ToElementType.isNull()) |
| 460 | return QualType(); |
| 461 | |
| 462 | return Importer.getToContext().getConstantArrayType(ToElementType, |
| 463 | T->getSize(), |
| 464 | T->getSizeModifier(), |
| 465 | T->getIndexTypeCVRQualifiers()); |
| 466 | } |
| 467 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 468 | QualType |
| 469 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 470 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 471 | if (ToElementType.isNull()) |
| 472 | return QualType(); |
| 473 | |
| 474 | return Importer.getToContext().getIncompleteArrayType(ToElementType, |
| 475 | T->getSizeModifier(), |
| 476 | T->getIndexTypeCVRQualifiers()); |
| 477 | } |
| 478 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 479 | QualType ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 480 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 481 | if (ToElementType.isNull()) |
| 482 | return QualType(); |
| 483 | |
| 484 | Expr *Size = Importer.Import(T->getSizeExpr()); |
| 485 | if (!Size) |
| 486 | return QualType(); |
| 487 | |
| 488 | SourceRange Brackets = Importer.Import(T->getBracketsRange()); |
| 489 | return Importer.getToContext().getVariableArrayType(ToElementType, Size, |
| 490 | T->getSizeModifier(), |
| 491 | T->getIndexTypeCVRQualifiers(), |
| 492 | Brackets); |
| 493 | } |
| 494 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 495 | QualType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 496 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 497 | if (ToElementType.isNull()) |
| 498 | return QualType(); |
| 499 | |
| 500 | return Importer.getToContext().getVectorType(ToElementType, |
| 501 | T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 502 | T->getVectorKind()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 503 | } |
| 504 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 505 | QualType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 506 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 507 | if (ToElementType.isNull()) |
| 508 | return QualType(); |
| 509 | |
| 510 | return Importer.getToContext().getExtVectorType(ToElementType, |
| 511 | T->getNumElements()); |
| 512 | } |
| 513 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 514 | QualType |
| 515 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 516 | // FIXME: What happens if we're importing a function without a prototype |
| 517 | // into C++? Should we make it variadic? |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 518 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 519 | if (ToResultType.isNull()) |
| 520 | return QualType(); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 521 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 522 | return Importer.getToContext().getFunctionNoProtoType(ToResultType, |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 523 | T->getExtInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 524 | } |
| 525 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 526 | QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 527 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 528 | if (ToResultType.isNull()) |
| 529 | return QualType(); |
| 530 | |
| 531 | // Import argument types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 532 | SmallVector<QualType, 4> ArgTypes; |
Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 533 | for (const auto &A : T->param_types()) { |
| 534 | QualType ArgType = Importer.Import(A); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 535 | if (ArgType.isNull()) |
| 536 | return QualType(); |
| 537 | ArgTypes.push_back(ArgType); |
| 538 | } |
| 539 | |
| 540 | // Import exception types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 541 | SmallVector<QualType, 4> ExceptionTypes; |
Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 542 | for (const auto &E : T->exceptions()) { |
| 543 | QualType ExceptionType = Importer.Import(E); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 544 | if (ExceptionType.isNull()) |
| 545 | return QualType(); |
| 546 | ExceptionTypes.push_back(ExceptionType); |
| 547 | } |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 548 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 549 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 550 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 551 | |
| 552 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 553 | ToEPI.Variadic = FromEPI.Variadic; |
| 554 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 555 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 556 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 557 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 558 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
| 559 | ToEPI.ExceptionSpec.NoexceptExpr = |
| 560 | Importer.Import(FromEPI.ExceptionSpec.NoexceptExpr); |
| 561 | ToEPI.ExceptionSpec.SourceDecl = cast_or_null<FunctionDecl>( |
| 562 | Importer.Import(FromEPI.ExceptionSpec.SourceDecl)); |
| 563 | ToEPI.ExceptionSpec.SourceTemplate = cast_or_null<FunctionDecl>( |
| 564 | Importer.Import(FromEPI.ExceptionSpec.SourceTemplate)); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 565 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 566 | return Importer.getToContext().getFunctionType(ToResultType, ArgTypes, ToEPI); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 569 | QualType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 570 | QualType ToInnerType = Importer.Import(T->getInnerType()); |
| 571 | if (ToInnerType.isNull()) |
| 572 | return QualType(); |
| 573 | |
| 574 | return Importer.getToContext().getParenType(ToInnerType); |
| 575 | } |
| 576 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 577 | QualType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 578 | TypedefNameDecl *ToDecl |
| 579 | = dyn_cast_or_null<TypedefNameDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 580 | if (!ToDecl) |
| 581 | return QualType(); |
| 582 | |
| 583 | return Importer.getToContext().getTypeDeclType(ToDecl); |
| 584 | } |
| 585 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 586 | QualType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 587 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 588 | if (!ToExpr) |
| 589 | return QualType(); |
| 590 | |
| 591 | return Importer.getToContext().getTypeOfExprType(ToExpr); |
| 592 | } |
| 593 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 594 | QualType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 595 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 596 | if (ToUnderlyingType.isNull()) |
| 597 | return QualType(); |
| 598 | |
| 599 | return Importer.getToContext().getTypeOfType(ToUnderlyingType); |
| 600 | } |
| 601 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 602 | QualType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 603 | // FIXME: Make sure that the "to" context supports C++0x! |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 604 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 605 | if (!ToExpr) |
| 606 | return QualType(); |
| 607 | |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 608 | QualType UnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 609 | if (UnderlyingType.isNull()) |
| 610 | return QualType(); |
| 611 | |
| 612 | return Importer.getToContext().getDecltypeType(ToExpr, UnderlyingType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 613 | } |
| 614 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 615 | QualType ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 616 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 617 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 618 | if (ToBaseType.isNull() || ToUnderlyingType.isNull()) |
| 619 | return QualType(); |
| 620 | |
| 621 | return Importer.getToContext().getUnaryTransformType(ToBaseType, |
| 622 | ToUnderlyingType, |
| 623 | T->getUTTKind()); |
| 624 | } |
| 625 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 626 | QualType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 627 | // FIXME: Make sure that the "to" context supports C++11! |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 628 | QualType FromDeduced = T->getDeducedType(); |
| 629 | QualType ToDeduced; |
| 630 | if (!FromDeduced.isNull()) { |
| 631 | ToDeduced = Importer.Import(FromDeduced); |
| 632 | if (ToDeduced.isNull()) |
| 633 | return QualType(); |
| 634 | } |
| 635 | |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 636 | return Importer.getToContext().getAutoType(ToDeduced, T->getKeyword(), |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 637 | /*IsDependent*/false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 638 | } |
| 639 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 640 | QualType ASTNodeImporter::VisitInjectedClassNameType( |
| 641 | const InjectedClassNameType *T) { |
| 642 | CXXRecordDecl *D = cast_or_null<CXXRecordDecl>(Importer.Import(T->getDecl())); |
| 643 | if (!D) |
| 644 | return QualType(); |
| 645 | |
| 646 | QualType InjType = Importer.Import(T->getInjectedSpecializationType()); |
| 647 | if (InjType.isNull()) |
| 648 | return QualType(); |
| 649 | |
| 650 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 651 | // See comments in InjectedClassNameType definition for details |
| 652 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 653 | enum { |
| 654 | TypeAlignmentInBits = 4, |
| 655 | TypeAlignment = 1 << TypeAlignmentInBits |
| 656 | }; |
| 657 | |
| 658 | return QualType(new (Importer.getToContext(), TypeAlignment) |
| 659 | InjectedClassNameType(D, InjType), 0); |
| 660 | } |
| 661 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 662 | QualType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 663 | RecordDecl *ToDecl |
| 664 | = dyn_cast_or_null<RecordDecl>(Importer.Import(T->getDecl())); |
| 665 | if (!ToDecl) |
| 666 | return QualType(); |
| 667 | |
| 668 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 669 | } |
| 670 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 671 | QualType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 672 | EnumDecl *ToDecl |
| 673 | = dyn_cast_or_null<EnumDecl>(Importer.Import(T->getDecl())); |
| 674 | if (!ToDecl) |
| 675 | return QualType(); |
| 676 | |
| 677 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 678 | } |
| 679 | |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 680 | QualType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 681 | QualType FromModifiedType = T->getModifiedType(); |
| 682 | QualType FromEquivalentType = T->getEquivalentType(); |
| 683 | QualType ToModifiedType; |
| 684 | QualType ToEquivalentType; |
| 685 | |
| 686 | if (!FromModifiedType.isNull()) { |
| 687 | ToModifiedType = Importer.Import(FromModifiedType); |
| 688 | if (ToModifiedType.isNull()) |
| 689 | return QualType(); |
| 690 | } |
| 691 | if (!FromEquivalentType.isNull()) { |
| 692 | ToEquivalentType = Importer.Import(FromEquivalentType); |
| 693 | if (ToEquivalentType.isNull()) |
| 694 | return QualType(); |
| 695 | } |
| 696 | |
| 697 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
| 698 | ToModifiedType, ToEquivalentType); |
| 699 | } |
| 700 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 701 | |
| 702 | QualType ASTNodeImporter::VisitTemplateTypeParmType( |
| 703 | const TemplateTypeParmType *T) { |
| 704 | TemplateTypeParmDecl *ParmDecl = |
| 705 | cast_or_null<TemplateTypeParmDecl>(Importer.Import(T->getDecl())); |
| 706 | if (!ParmDecl && T->getDecl()) |
| 707 | return QualType(); |
| 708 | |
| 709 | return Importer.getToContext().getTemplateTypeParmType( |
| 710 | T->getDepth(), T->getIndex(), T->isParameterPack(), ParmDecl); |
| 711 | } |
| 712 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 713 | QualType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
| 714 | const SubstTemplateTypeParmType *T) { |
| 715 | const TemplateTypeParmType *Replaced = |
| 716 | cast_or_null<TemplateTypeParmType>(Importer.Import( |
| 717 | QualType(T->getReplacedParameter(), 0)).getTypePtr()); |
| 718 | if (!Replaced) |
| 719 | return QualType(); |
| 720 | |
| 721 | QualType Replacement = Importer.Import(T->getReplacementType()); |
| 722 | if (Replacement.isNull()) |
| 723 | return QualType(); |
| 724 | Replacement = Replacement.getCanonicalType(); |
| 725 | |
| 726 | return Importer.getToContext().getSubstTemplateTypeParmType( |
| 727 | Replaced, Replacement); |
| 728 | } |
| 729 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 730 | QualType ASTNodeImporter::VisitTemplateSpecializationType( |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 731 | const TemplateSpecializationType *T) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 732 | TemplateName ToTemplate = Importer.Import(T->getTemplateName()); |
| 733 | if (ToTemplate.isNull()) |
| 734 | return QualType(); |
| 735 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 736 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 737 | if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
| 738 | return QualType(); |
| 739 | |
| 740 | QualType ToCanonType; |
| 741 | if (!QualType(T, 0).isCanonical()) { |
| 742 | QualType FromCanonType |
| 743 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
| 744 | ToCanonType =Importer.Import(FromCanonType); |
| 745 | if (ToCanonType.isNull()) |
| 746 | return QualType(); |
| 747 | } |
| 748 | return Importer.getToContext().getTemplateSpecializationType(ToTemplate, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 749 | ToTemplateArgs, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 750 | ToCanonType); |
| 751 | } |
| 752 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 753 | QualType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 754 | NestedNameSpecifier *ToQualifier = nullptr; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 755 | // Note: the qualifier in an ElaboratedType is optional. |
| 756 | if (T->getQualifier()) { |
| 757 | ToQualifier = Importer.Import(T->getQualifier()); |
| 758 | if (!ToQualifier) |
| 759 | return QualType(); |
| 760 | } |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 761 | |
| 762 | QualType ToNamedType = Importer.Import(T->getNamedType()); |
| 763 | if (ToNamedType.isNull()) |
| 764 | return QualType(); |
| 765 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 766 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
| 767 | ToQualifier, ToNamedType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 768 | } |
| 769 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 770 | QualType ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 771 | ObjCInterfaceDecl *Class |
| 772 | = dyn_cast_or_null<ObjCInterfaceDecl>(Importer.Import(T->getDecl())); |
| 773 | if (!Class) |
| 774 | return QualType(); |
| 775 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 776 | return Importer.getToContext().getObjCInterfaceType(Class); |
| 777 | } |
| 778 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 779 | QualType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 780 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 781 | if (ToBaseType.isNull()) |
| 782 | return QualType(); |
| 783 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 784 | SmallVector<QualType, 4> TypeArgs; |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 785 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 786 | QualType ImportedTypeArg = Importer.Import(TypeArg); |
| 787 | if (ImportedTypeArg.isNull()) |
| 788 | return QualType(); |
| 789 | |
| 790 | TypeArgs.push_back(ImportedTypeArg); |
| 791 | } |
| 792 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 793 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 794 | for (auto *P : T->quals()) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 795 | ObjCProtocolDecl *Protocol |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 796 | = dyn_cast_or_null<ObjCProtocolDecl>(Importer.Import(P)); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 797 | if (!Protocol) |
| 798 | return QualType(); |
| 799 | Protocols.push_back(Protocol); |
| 800 | } |
| 801 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 802 | return Importer.getToContext().getObjCObjectType(ToBaseType, TypeArgs, |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 803 | Protocols, |
| 804 | T->isKindOfTypeAsWritten()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 805 | } |
| 806 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 807 | QualType |
| 808 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 809 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 810 | if (ToPointeeType.isNull()) |
| 811 | return QualType(); |
| 812 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 813 | return Importer.getToContext().getObjCObjectPointerType(ToPointeeType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 814 | } |
| 815 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 816 | //---------------------------------------------------------------------------- |
| 817 | // Import Declarations |
| 818 | //---------------------------------------------------------------------------- |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 819 | bool ASTNodeImporter::ImportDeclParts(NamedDecl *D, DeclContext *&DC, |
| 820 | DeclContext *&LexicalDC, |
| 821 | DeclarationName &Name, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 822 | NamedDecl *&ToD, |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 823 | SourceLocation &Loc) { |
| 824 | // Import the context of this declaration. |
| 825 | DC = Importer.ImportContext(D->getDeclContext()); |
| 826 | if (!DC) |
| 827 | return true; |
| 828 | |
| 829 | LexicalDC = DC; |
| 830 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 831 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 832 | if (!LexicalDC) |
| 833 | return true; |
| 834 | } |
| 835 | |
| 836 | // Import the name of this declaration. |
| 837 | Name = Importer.Import(D->getDeclName()); |
| 838 | if (D->getDeclName() && !Name) |
| 839 | return true; |
| 840 | |
| 841 | // Import the location of this declaration. |
| 842 | Loc = Importer.Import(D->getLocation()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 843 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 844 | return false; |
| 845 | } |
| 846 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 847 | void ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
| 848 | if (!FromD) |
| 849 | return; |
| 850 | |
| 851 | if (!ToD) { |
| 852 | ToD = Importer.Import(FromD); |
| 853 | if (!ToD) |
| 854 | return; |
| 855 | } |
| 856 | |
| 857 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 858 | if (RecordDecl *ToRecord = cast_or_null<RecordDecl>(ToD)) { |
Sean Callanan | 19dfc93 | 2013-01-11 23:17:47 +0000 | [diff] [blame] | 859 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && !ToRecord->getDefinition()) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 860 | ImportDefinition(FromRecord, ToRecord); |
| 861 | } |
| 862 | } |
| 863 | return; |
| 864 | } |
| 865 | |
| 866 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 867 | if (EnumDecl *ToEnum = cast_or_null<EnumDecl>(ToD)) { |
| 868 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
| 869 | ImportDefinition(FromEnum, ToEnum); |
| 870 | } |
| 871 | } |
| 872 | return; |
| 873 | } |
| 874 | } |
| 875 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 876 | void |
| 877 | ASTNodeImporter::ImportDeclarationNameLoc(const DeclarationNameInfo &From, |
| 878 | DeclarationNameInfo& To) { |
| 879 | // NOTE: To.Name and To.Loc are already imported. |
| 880 | // We only have to import To.LocInfo. |
| 881 | switch (To.getName().getNameKind()) { |
| 882 | case DeclarationName::Identifier: |
| 883 | case DeclarationName::ObjCZeroArgSelector: |
| 884 | case DeclarationName::ObjCOneArgSelector: |
| 885 | case DeclarationName::ObjCMultiArgSelector: |
| 886 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 887 | case DeclarationName::CXXDeductionGuideName: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 888 | return; |
| 889 | |
| 890 | case DeclarationName::CXXOperatorName: { |
| 891 | SourceRange Range = From.getCXXOperatorNameRange(); |
| 892 | To.setCXXOperatorNameRange(Importer.Import(Range)); |
| 893 | return; |
| 894 | } |
| 895 | case DeclarationName::CXXLiteralOperatorName: { |
| 896 | SourceLocation Loc = From.getCXXLiteralOperatorNameLoc(); |
| 897 | To.setCXXLiteralOperatorNameLoc(Importer.Import(Loc)); |
| 898 | return; |
| 899 | } |
| 900 | case DeclarationName::CXXConstructorName: |
| 901 | case DeclarationName::CXXDestructorName: |
| 902 | case DeclarationName::CXXConversionFunctionName: { |
| 903 | TypeSourceInfo *FromTInfo = From.getNamedTypeInfo(); |
| 904 | To.setNamedTypeInfo(Importer.Import(FromTInfo)); |
| 905 | return; |
| 906 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 907 | } |
Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 908 | llvm_unreachable("Unknown name kind."); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 909 | } |
| 910 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 911 | void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 912 | if (Importer.isMinimalImport() && !ForceImport) { |
Sean Callanan | 81d577c | 2011-07-22 23:46:03 +0000 | [diff] [blame] | 913 | Importer.ImportContext(FromDC); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 914 | return; |
| 915 | } |
| 916 | |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 917 | for (auto *From : FromDC->decls()) |
| 918 | Importer.Import(From); |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 919 | } |
| 920 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 921 | bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 922 | ImportDefinitionKind Kind) { |
| 923 | if (To->getDefinition() || To->isBeingDefined()) { |
| 924 | if (Kind == IDK_Everything) |
| 925 | ImportDeclContext(From, /*ForceImport=*/true); |
| 926 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 927 | return false; |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 928 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 929 | |
| 930 | To->startDefinition(); |
| 931 | |
| 932 | // Add base classes. |
| 933 | if (CXXRecordDecl *ToCXX = dyn_cast<CXXRecordDecl>(To)) { |
| 934 | CXXRecordDecl *FromCXX = cast<CXXRecordDecl>(From); |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 935 | |
| 936 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 937 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 938 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 939 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 940 | ToData.Aggregate = FromData.Aggregate; |
| 941 | ToData.PlainOldData = FromData.PlainOldData; |
| 942 | ToData.Empty = FromData.Empty; |
| 943 | ToData.Polymorphic = FromData.Polymorphic; |
| 944 | ToData.Abstract = FromData.Abstract; |
| 945 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
| 946 | ToData.HasNoNonEmptyBases = FromData.HasNoNonEmptyBases; |
| 947 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 948 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 949 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 950 | ToData.HasMutableFields = FromData.HasMutableFields; |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 951 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 952 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 953 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 954 | ToData.HasUninitializedReferenceMember |
| 955 | = FromData.HasUninitializedReferenceMember; |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 956 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 957 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 958 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 959 | ToData.NeedOverloadResolutionForCopyConstructor |
| 960 | = FromData.NeedOverloadResolutionForCopyConstructor; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 961 | ToData.NeedOverloadResolutionForMoveConstructor |
| 962 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 963 | ToData.NeedOverloadResolutionForMoveAssignment |
| 964 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 965 | ToData.NeedOverloadResolutionForDestructor |
| 966 | = FromData.NeedOverloadResolutionForDestructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 967 | ToData.DefaultedCopyConstructorIsDeleted |
| 968 | = FromData.DefaultedCopyConstructorIsDeleted; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 969 | ToData.DefaultedMoveConstructorIsDeleted |
| 970 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 971 | ToData.DefaultedMoveAssignmentIsDeleted |
| 972 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 973 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 974 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 975 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 976 | ToData.HasConstexprNonCopyMoveConstructor |
| 977 | = FromData.HasConstexprNonCopyMoveConstructor; |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 978 | ToData.HasDefaultedDefaultConstructor |
| 979 | = FromData.HasDefaultedDefaultConstructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 980 | ToData.CanPassInRegisters = FromData.CanPassInRegisters; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 981 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 982 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 983 | ToData.HasConstexprDefaultConstructor |
| 984 | = FromData.HasConstexprDefaultConstructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 985 | ToData.HasNonLiteralTypeFieldsOrBases |
| 986 | = FromData.HasNonLiteralTypeFieldsOrBases; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 987 | // ComputedVisibleConversions not imported. |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 988 | ToData.UserProvidedDefaultConstructor |
| 989 | = FromData.UserProvidedDefaultConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 990 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 991 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 992 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 993 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 994 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 995 | ToData.ImplicitCopyAssignmentHasConstParam |
| 996 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 997 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 998 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 999 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 1000 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1001 | ToData.IsLambda = FromData.IsLambda; |
| 1002 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1003 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1004 | for (const auto &Base1 : FromCXX->bases()) { |
| 1005 | QualType T = Importer.Import(Base1.getType()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1006 | if (T.isNull()) |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1007 | return true; |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1008 | |
| 1009 | SourceLocation EllipsisLoc; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1010 | if (Base1.isPackExpansion()) |
| 1011 | EllipsisLoc = Importer.Import(Base1.getEllipsisLoc()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1012 | |
| 1013 | // Ensure that we have a definition for the base. |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1014 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1015 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1016 | Bases.push_back( |
| 1017 | new (Importer.getToContext()) |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1018 | CXXBaseSpecifier(Importer.Import(Base1.getSourceRange()), |
| 1019 | Base1.isVirtual(), |
| 1020 | Base1.isBaseOfClass(), |
| 1021 | Base1.getAccessSpecifierAsWritten(), |
| 1022 | Importer.Import(Base1.getTypeSourceInfo()), |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1023 | EllipsisLoc)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1024 | } |
| 1025 | if (!Bases.empty()) |
Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1026 | ToCXX->setBases(Bases.data(), Bases.size()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1029 | if (shouldForceImportDeclContext(Kind)) |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1030 | ImportDeclContext(From, /*ForceImport=*/true); |
| 1031 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1032 | To->completeDefinition(); |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1033 | return false; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1036 | bool ASTNodeImporter::ImportDefinition(VarDecl *From, VarDecl *To, |
| 1037 | ImportDefinitionKind Kind) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1038 | if (To->getAnyInitializer()) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1039 | return false; |
| 1040 | |
| 1041 | // FIXME: Can we really import any initializer? Alternatively, we could force |
| 1042 | // ourselves to import every declaration of a variable and then only use |
| 1043 | // getInit() here. |
| 1044 | To->setInit(Importer.Import(const_cast<Expr *>(From->getAnyInitializer()))); |
| 1045 | |
| 1046 | // FIXME: Other bits to merge? |
| 1047 | |
| 1048 | return false; |
| 1049 | } |
| 1050 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1051 | bool ASTNodeImporter::ImportDefinition(EnumDecl *From, EnumDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1052 | ImportDefinitionKind Kind) { |
| 1053 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1054 | if (Kind == IDK_Everything) |
| 1055 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1056 | return false; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1057 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1058 | |
| 1059 | To->startDefinition(); |
| 1060 | |
| 1061 | QualType T = Importer.Import(Importer.getFromContext().getTypeDeclType(From)); |
| 1062 | if (T.isNull()) |
| 1063 | return true; |
| 1064 | |
| 1065 | QualType ToPromotionType = Importer.Import(From->getPromotionType()); |
| 1066 | if (ToPromotionType.isNull()) |
| 1067 | return true; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1068 | |
| 1069 | if (shouldForceImportDeclContext(Kind)) |
| 1070 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1071 | |
| 1072 | // FIXME: we might need to merge the number of positive or negative bits |
| 1073 | // if the enumerator lists don't match. |
| 1074 | To->completeDefinition(T, ToPromotionType, |
| 1075 | From->getNumPositiveBits(), |
| 1076 | From->getNumNegativeBits()); |
| 1077 | return false; |
| 1078 | } |
| 1079 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1080 | TemplateParameterList *ASTNodeImporter::ImportTemplateParameterList( |
| 1081 | TemplateParameterList *Params) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1082 | SmallVector<NamedDecl *, 4> ToParams(Params->size()); |
| 1083 | if (ImportContainerChecked(*Params, ToParams)) |
| 1084 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1085 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1086 | Expr *ToRequiresClause; |
| 1087 | if (Expr *const R = Params->getRequiresClause()) { |
| 1088 | ToRequiresClause = Importer.Import(R); |
| 1089 | if (!ToRequiresClause) |
| 1090 | return nullptr; |
| 1091 | } else { |
| 1092 | ToRequiresClause = nullptr; |
| 1093 | } |
| 1094 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1095 | return TemplateParameterList::Create(Importer.getToContext(), |
| 1096 | Importer.Import(Params->getTemplateLoc()), |
| 1097 | Importer.Import(Params->getLAngleLoc()), |
David Majnemer | 902f8c6 | 2015-12-27 07:16:27 +0000 | [diff] [blame] | 1098 | ToParams, |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1099 | Importer.Import(Params->getRAngleLoc()), |
| 1100 | ToRequiresClause); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1101 | } |
| 1102 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1103 | TemplateArgument |
| 1104 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1105 | switch (From.getKind()) { |
| 1106 | case TemplateArgument::Null: |
| 1107 | return TemplateArgument(); |
| 1108 | |
| 1109 | case TemplateArgument::Type: { |
| 1110 | QualType ToType = Importer.Import(From.getAsType()); |
| 1111 | if (ToType.isNull()) |
| 1112 | return TemplateArgument(); |
| 1113 | return TemplateArgument(ToType); |
| 1114 | } |
| 1115 | |
| 1116 | case TemplateArgument::Integral: { |
| 1117 | QualType ToType = Importer.Import(From.getIntegralType()); |
| 1118 | if (ToType.isNull()) |
| 1119 | return TemplateArgument(); |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 1120 | return TemplateArgument(From, ToType); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1123 | case TemplateArgument::Declaration: { |
David Blaikie | 3c7dd6b | 2014-10-22 19:54:16 +0000 | [diff] [blame] | 1124 | ValueDecl *To = cast_or_null<ValueDecl>(Importer.Import(From.getAsDecl())); |
| 1125 | QualType ToType = Importer.Import(From.getParamTypeForDecl()); |
| 1126 | if (!To || ToType.isNull()) |
| 1127 | return TemplateArgument(); |
| 1128 | return TemplateArgument(To, ToType); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | case TemplateArgument::NullPtr: { |
| 1132 | QualType ToType = Importer.Import(From.getNullPtrType()); |
| 1133 | if (ToType.isNull()) |
| 1134 | return TemplateArgument(); |
| 1135 | return TemplateArgument(ToType, /*isNullPtr*/true); |
| 1136 | } |
| 1137 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1138 | case TemplateArgument::Template: { |
| 1139 | TemplateName ToTemplate = Importer.Import(From.getAsTemplate()); |
| 1140 | if (ToTemplate.isNull()) |
| 1141 | return TemplateArgument(); |
| 1142 | |
| 1143 | return TemplateArgument(ToTemplate); |
| 1144 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1145 | |
| 1146 | case TemplateArgument::TemplateExpansion: { |
| 1147 | TemplateName ToTemplate |
| 1148 | = Importer.Import(From.getAsTemplateOrTemplatePattern()); |
| 1149 | if (ToTemplate.isNull()) |
| 1150 | return TemplateArgument(); |
| 1151 | |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 1152 | return TemplateArgument(ToTemplate, From.getNumTemplateExpansions()); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1153 | } |
| 1154 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1155 | case TemplateArgument::Expression: |
| 1156 | if (Expr *ToExpr = Importer.Import(From.getAsExpr())) |
| 1157 | return TemplateArgument(ToExpr); |
| 1158 | return TemplateArgument(); |
| 1159 | |
| 1160 | case TemplateArgument::Pack: { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1161 | SmallVector<TemplateArgument, 2> ToPack; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1162 | ToPack.reserve(From.pack_size()); |
| 1163 | if (ImportTemplateArguments(From.pack_begin(), From.pack_size(), ToPack)) |
| 1164 | return TemplateArgument(); |
Benjamin Kramer | cce6347 | 2015-08-05 09:40:22 +0000 | [diff] [blame] | 1165 | |
| 1166 | return TemplateArgument( |
| 1167 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | llvm_unreachable("Invalid template argument kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1174 | TemplateArgumentLoc ASTNodeImporter::ImportTemplateArgumentLoc( |
| 1175 | const TemplateArgumentLoc &TALoc, bool &Error) { |
| 1176 | Error = false; |
| 1177 | TemplateArgument Arg = ImportTemplateArgument(TALoc.getArgument()); |
| 1178 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 1179 | TemplateArgumentLocInfo ToInfo; |
| 1180 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 1181 | Expr *E = Importer.Import(FromInfo.getAsExpr()); |
| 1182 | ToInfo = TemplateArgumentLocInfo(E); |
| 1183 | if (!E) |
| 1184 | Error = true; |
| 1185 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 1186 | if (TypeSourceInfo *TSI = Importer.Import(FromInfo.getAsTypeSourceInfo())) |
| 1187 | ToInfo = TemplateArgumentLocInfo(TSI); |
| 1188 | else |
| 1189 | Error = true; |
| 1190 | } else { |
| 1191 | ToInfo = TemplateArgumentLocInfo( |
| 1192 | Importer.Import(FromInfo.getTemplateQualifierLoc()), |
| 1193 | Importer.Import(FromInfo.getTemplateNameLoc()), |
| 1194 | Importer.Import(FromInfo.getTemplateEllipsisLoc())); |
| 1195 | } |
| 1196 | return TemplateArgumentLoc(Arg, ToInfo); |
| 1197 | } |
| 1198 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1199 | bool ASTNodeImporter::ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 1200 | unsigned NumFromArgs, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1201 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1202 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
| 1203 | TemplateArgument To = ImportTemplateArgument(FromArgs[I]); |
| 1204 | if (To.isNull() && !FromArgs[I].isNull()) |
| 1205 | return true; |
| 1206 | |
| 1207 | ToArgs.push_back(To); |
| 1208 | } |
| 1209 | |
| 1210 | return false; |
| 1211 | } |
| 1212 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1213 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1214 | RecordDecl *ToRecord, bool Complain) { |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1215 | // Eliminate a potential failure point where we attempt to re-import |
| 1216 | // something we're trying to import while completing ToRecord. |
| 1217 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 1218 | if (ToOrigin) { |
| 1219 | RecordDecl *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
| 1220 | if (ToOriginRecord) |
| 1221 | ToRecord = ToOriginRecord; |
| 1222 | } |
| 1223 | |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1224 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1225 | ToRecord->getASTContext(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1226 | Importer.getNonEquivalentDecls(), |
| 1227 | false, Complain); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1228 | return Ctx.IsStructurallyEquivalent(FromRecord, ToRecord); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1231 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 1232 | bool Complain) { |
| 1233 | StructuralEquivalenceContext Ctx( |
| 1234 | Importer.getFromContext(), Importer.getToContext(), |
| 1235 | Importer.getNonEquivalentDecls(), false, Complain); |
| 1236 | return Ctx.IsStructurallyEquivalent(FromVar, ToVar); |
| 1237 | } |
| 1238 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1239 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1240 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1241 | Importer.getToContext(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1242 | Importer.getNonEquivalentDecls()); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1243 | return Ctx.IsStructurallyEquivalent(FromEnum, ToEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1246 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
| 1247 | EnumConstantDecl *ToEC) |
| 1248 | { |
| 1249 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 1250 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 1251 | |
| 1252 | return FromVal.isSigned() == ToVal.isSigned() && |
| 1253 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 1254 | FromVal == ToVal; |
| 1255 | } |
| 1256 | |
| 1257 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1258 | ClassTemplateDecl *To) { |
| 1259 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1260 | Importer.getToContext(), |
| 1261 | Importer.getNonEquivalentDecls()); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1262 | return Ctx.IsStructurallyEquivalent(From, To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1263 | } |
| 1264 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1265 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 1266 | VarTemplateDecl *To) { |
| 1267 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1268 | Importer.getToContext(), |
| 1269 | Importer.getNonEquivalentDecls()); |
| 1270 | return Ctx.IsStructurallyEquivalent(From, To); |
| 1271 | } |
| 1272 | |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1273 | Decl *ASTNodeImporter::VisitDecl(Decl *D) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 1274 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1275 | << D->getDeclKindName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1276 | return nullptr; |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1277 | } |
| 1278 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 1279 | Decl *ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 1280 | TranslationUnitDecl *ToD = |
| 1281 | Importer.getToContext().getTranslationUnitDecl(); |
| 1282 | |
| 1283 | Importer.Imported(D, ToD); |
| 1284 | |
| 1285 | return ToD; |
| 1286 | } |
| 1287 | |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1288 | Decl *ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 1289 | |
| 1290 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1291 | SourceLocation ColonLoc = Importer.Import(D->getColonLoc()); |
| 1292 | |
| 1293 | // Import the context of this declaration. |
| 1294 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1295 | if (!DC) |
| 1296 | return nullptr; |
| 1297 | |
| 1298 | AccessSpecDecl *accessSpecDecl |
| 1299 | = AccessSpecDecl::Create(Importer.getToContext(), D->getAccess(), |
| 1300 | DC, Loc, ColonLoc); |
| 1301 | |
| 1302 | if (!accessSpecDecl) |
| 1303 | return nullptr; |
| 1304 | |
| 1305 | // Lexical DeclContext and Semantic DeclContext |
| 1306 | // is always the same for the accessSpec. |
| 1307 | accessSpecDecl->setLexicalDeclContext(DC); |
| 1308 | DC->addDeclInternal(accessSpecDecl); |
| 1309 | |
| 1310 | return accessSpecDecl; |
| 1311 | } |
| 1312 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1313 | Decl *ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 1314 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1315 | if (!DC) |
| 1316 | return nullptr; |
| 1317 | |
| 1318 | DeclContext *LexicalDC = DC; |
| 1319 | |
| 1320 | // Import the location of this declaration. |
| 1321 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1322 | |
| 1323 | Expr *AssertExpr = Importer.Import(D->getAssertExpr()); |
| 1324 | if (!AssertExpr) |
| 1325 | return nullptr; |
| 1326 | |
| 1327 | StringLiteral *FromMsg = D->getMessage(); |
| 1328 | StringLiteral *ToMsg = cast_or_null<StringLiteral>(Importer.Import(FromMsg)); |
| 1329 | if (!ToMsg && FromMsg) |
| 1330 | return nullptr; |
| 1331 | |
| 1332 | StaticAssertDecl *ToD = StaticAssertDecl::Create( |
| 1333 | Importer.getToContext(), DC, Loc, AssertExpr, ToMsg, |
| 1334 | Importer.Import(D->getRParenLoc()), D->isFailed()); |
| 1335 | |
| 1336 | ToD->setLexicalDeclContext(LexicalDC); |
| 1337 | LexicalDC->addDeclInternal(ToD); |
| 1338 | Importer.Imported(D, ToD); |
| 1339 | return ToD; |
| 1340 | } |
| 1341 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1342 | Decl *ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
| 1343 | // Import the major distinguishing characteristics of this namespace. |
| 1344 | DeclContext *DC, *LexicalDC; |
| 1345 | DeclarationName Name; |
| 1346 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1347 | NamedDecl *ToD; |
| 1348 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1349 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1350 | if (ToD) |
| 1351 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1352 | |
| 1353 | NamespaceDecl *MergeWithNamespace = nullptr; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1354 | if (!Name) { |
| 1355 | // This is an anonymous namespace. Adopt an existing anonymous |
| 1356 | // namespace if we can. |
| 1357 | // FIXME: Not testable. |
| 1358 | if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| 1359 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 1360 | else |
| 1361 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 1362 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1363 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1364 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1365 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1366 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1367 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1368 | continue; |
| 1369 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1370 | if (NamespaceDecl *FoundNS = dyn_cast<NamespaceDecl>(FoundDecls[I])) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1371 | MergeWithNamespace = FoundNS; |
| 1372 | ConflictingDecls.clear(); |
| 1373 | break; |
| 1374 | } |
| 1375 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1376 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1377 | } |
| 1378 | |
| 1379 | if (!ConflictingDecls.empty()) { |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 1380 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1381 | ConflictingDecls.data(), |
| 1382 | ConflictingDecls.size()); |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | // Create the "to" namespace, if needed. |
| 1387 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 1388 | if (!ToNamespace) { |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 1389 | ToNamespace = NamespaceDecl::Create(Importer.getToContext(), DC, |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1390 | D->isInline(), |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 1391 | Importer.Import(D->getLocStart()), |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1392 | Loc, Name.getAsIdentifierInfo(), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1393 | /*PrevDecl=*/nullptr); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1394 | ToNamespace->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1395 | LexicalDC->addDeclInternal(ToNamespace); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1396 | |
| 1397 | // If this is an anonymous namespace, register it as the anonymous |
| 1398 | // namespace within its context. |
| 1399 | if (!Name) { |
| 1400 | if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| 1401 | TU->setAnonymousNamespace(ToNamespace); |
| 1402 | else |
| 1403 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 1404 | } |
| 1405 | } |
| 1406 | Importer.Imported(D, ToNamespace); |
| 1407 | |
| 1408 | ImportDeclContext(D); |
| 1409 | |
| 1410 | return ToNamespace; |
| 1411 | } |
| 1412 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1413 | Decl *ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1414 | // Import the major distinguishing characteristics of this typedef. |
| 1415 | DeclContext *DC, *LexicalDC; |
| 1416 | DeclarationName Name; |
| 1417 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1418 | NamedDecl *ToD; |
| 1419 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1420 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1421 | if (ToD) |
| 1422 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1423 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1424 | // If this typedef is not in block scope, determine whether we've |
| 1425 | // seen a typedef with the same name (that we can merge with) or any |
| 1426 | // other entity by that name (which name lookup could conflict with). |
| 1427 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1428 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1429 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1430 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1431 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1432 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1433 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1434 | continue; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1435 | if (TypedefNameDecl *FoundTypedef = |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1436 | dyn_cast<TypedefNameDecl>(FoundDecls[I])) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1437 | if (Importer.IsStructurallyEquivalent(D->getUnderlyingType(), |
| 1438 | FoundTypedef->getUnderlyingType())) |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1439 | return Importer.Imported(D, FoundTypedef); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1440 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1441 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1442 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1443 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1444 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1445 | if (!ConflictingDecls.empty()) { |
| 1446 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1447 | ConflictingDecls.data(), |
| 1448 | ConflictingDecls.size()); |
| 1449 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1450 | return nullptr; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1451 | } |
| 1452 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1453 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1454 | // Import the underlying type of this typedef; |
| 1455 | QualType T = Importer.Import(D->getUnderlyingType()); |
| 1456 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1457 | return nullptr; |
| 1458 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1459 | // Create the new typedef node. |
| 1460 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 1461 | SourceLocation StartL = Importer.Import(D->getLocStart()); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1462 | TypedefNameDecl *ToTypedef; |
| 1463 | if (IsAlias) |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 1464 | ToTypedef = TypeAliasDecl::Create(Importer.getToContext(), DC, |
| 1465 | StartL, Loc, |
| 1466 | Name.getAsIdentifierInfo(), |
| 1467 | TInfo); |
| 1468 | else |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1469 | ToTypedef = TypedefDecl::Create(Importer.getToContext(), DC, |
| 1470 | StartL, Loc, |
| 1471 | Name.getAsIdentifierInfo(), |
| 1472 | TInfo); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1473 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1474 | ToTypedef->setAccess(D->getAccess()); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1475 | ToTypedef->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1476 | Importer.Imported(D, ToTypedef); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1477 | LexicalDC->addDeclInternal(ToTypedef); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1478 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1479 | return ToTypedef; |
| 1480 | } |
| 1481 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1482 | Decl *ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
| 1483 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 1484 | } |
| 1485 | |
| 1486 | Decl *ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| 1487 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 1488 | } |
| 1489 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1490 | Decl *ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
| 1491 | // Import the major distinguishing characteristics of this label. |
| 1492 | DeclContext *DC, *LexicalDC; |
| 1493 | DeclarationName Name; |
| 1494 | SourceLocation Loc; |
| 1495 | NamedDecl *ToD; |
| 1496 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 1497 | return nullptr; |
| 1498 | if (ToD) |
| 1499 | return ToD; |
| 1500 | |
| 1501 | assert(LexicalDC->isFunctionOrMethod()); |
| 1502 | |
| 1503 | LabelDecl *ToLabel = D->isGnuLocal() |
| 1504 | ? LabelDecl::Create(Importer.getToContext(), |
| 1505 | DC, Importer.Import(D->getLocation()), |
| 1506 | Name.getAsIdentifierInfo(), |
| 1507 | Importer.Import(D->getLocStart())) |
| 1508 | : LabelDecl::Create(Importer.getToContext(), |
| 1509 | DC, Importer.Import(D->getLocation()), |
| 1510 | Name.getAsIdentifierInfo()); |
| 1511 | Importer.Imported(D, ToLabel); |
| 1512 | |
| 1513 | LabelStmt *Label = cast_or_null<LabelStmt>(Importer.Import(D->getStmt())); |
| 1514 | if (!Label) |
| 1515 | return nullptr; |
| 1516 | |
| 1517 | ToLabel->setStmt(Label); |
| 1518 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 1519 | LexicalDC->addDeclInternal(ToLabel); |
| 1520 | return ToLabel; |
| 1521 | } |
| 1522 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1523 | Decl *ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
| 1524 | // Import the major distinguishing characteristics of this enum. |
| 1525 | DeclContext *DC, *LexicalDC; |
| 1526 | DeclarationName Name; |
| 1527 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1528 | NamedDecl *ToD; |
| 1529 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1530 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1531 | if (ToD) |
| 1532 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1533 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1534 | // Figure out what enum name we're looking for. |
| 1535 | unsigned IDNS = Decl::IDNS_Tag; |
| 1536 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1537 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 1538 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1539 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1540 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1541 | IDNS |= Decl::IDNS_Ordinary; |
| 1542 | |
| 1543 | // We may already have an enum of the same name; try to find and match it. |
| 1544 | if (!DC->isFunctionOrMethod() && SearchName) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1545 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1546 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 1547 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1548 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1549 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1550 | continue; |
| 1551 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1552 | Decl *Found = FoundDecls[I]; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1553 | if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1554 | if (const TagType *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| 1555 | Found = Tag->getDecl(); |
| 1556 | } |
| 1557 | |
| 1558 | if (EnumDecl *FoundEnum = dyn_cast<EnumDecl>(Found)) { |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1559 | if (IsStructuralMatch(D, FoundEnum)) |
| 1560 | return Importer.Imported(D, FoundEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1561 | } |
| 1562 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1563 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | if (!ConflictingDecls.empty()) { |
| 1567 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1568 | ConflictingDecls.data(), |
| 1569 | ConflictingDecls.size()); |
| 1570 | } |
| 1571 | } |
| 1572 | |
| 1573 | // Create the enum declaration. |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 1574 | EnumDecl *D2 = EnumDecl::Create(Importer.getToContext(), DC, |
| 1575 | Importer.Import(D->getLocStart()), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1576 | Loc, Name.getAsIdentifierInfo(), nullptr, |
Abramo Bagnara | 0e05e24 | 2010-12-03 18:54:17 +0000 | [diff] [blame] | 1577 | D->isScoped(), D->isScopedUsingClassTag(), |
| 1578 | D->isFixed()); |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 1579 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 1580 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1581 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1582 | D2->setLexicalDeclContext(LexicalDC); |
| 1583 | Importer.Imported(D, D2); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1584 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1585 | |
| 1586 | // Import the integer type. |
| 1587 | QualType ToIntegerType = Importer.Import(D->getIntegerType()); |
| 1588 | if (ToIntegerType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1589 | return nullptr; |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1590 | D2->setIntegerType(ToIntegerType); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1591 | |
| 1592 | // Import the definition |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 1593 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1594 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1595 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1596 | return D2; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1597 | } |
| 1598 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1599 | Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
| 1600 | // If this record has a definition in the translation unit we're coming from, |
| 1601 | // but this particular declaration is not that definition, import the |
| 1602 | // definition and map to that. |
Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 1603 | TagDecl *Definition = D->getDefinition(); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1604 | if (Definition && Definition != D) { |
| 1605 | Decl *ImportedDef = Importer.Import(Definition); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1606 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1607 | return nullptr; |
| 1608 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1609 | return Importer.Imported(D, ImportedDef); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1610 | } |
| 1611 | |
| 1612 | // Import the major distinguishing characteristics of this record. |
| 1613 | DeclContext *DC, *LexicalDC; |
| 1614 | DeclarationName Name; |
| 1615 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1616 | NamedDecl *ToD; |
| 1617 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1618 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1619 | if (ToD) |
| 1620 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1621 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1622 | // Figure out what structure name we're looking for. |
| 1623 | unsigned IDNS = Decl::IDNS_Tag; |
| 1624 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1625 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 1626 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1627 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1628 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1629 | IDNS |= Decl::IDNS_Ordinary; |
| 1630 | |
| 1631 | // We may already have a record of the same name; try to find and match it. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1632 | RecordDecl *AdoptDecl = nullptr; |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 1633 | RecordDecl *PrevDecl = nullptr; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1634 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1635 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1636 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 1637 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 1638 | |
| 1639 | if (!FoundDecls.empty()) { |
| 1640 | // We're going to have to compare D against potentially conflicting Decls, so complete it. |
| 1641 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 1642 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 1643 | } |
| 1644 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1645 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1646 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1647 | continue; |
| 1648 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1649 | Decl *Found = FoundDecls[I]; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1650 | if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1651 | if (const TagType *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| 1652 | Found = Tag->getDecl(); |
| 1653 | } |
| 1654 | |
| 1655 | if (RecordDecl *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
Gabor Horvath | 3b392bb | 2017-04-03 21:06:45 +0000 | [diff] [blame] | 1656 | if (D->isAnonymousStructOrUnion() && |
| 1657 | FoundRecord->isAnonymousStructOrUnion()) { |
| 1658 | // If both anonymous structs/unions are in a record context, make sure |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 1659 | // they occur in the same location in the context records. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1660 | if (Optional<unsigned> Index1 = |
| 1661 | StructuralEquivalenceContext::findUntaggedStructOrUnionIndex( |
| 1662 | D)) { |
| 1663 | if (Optional<unsigned> Index2 = StructuralEquivalenceContext:: |
Sean Callanan | 488f861 | 2016-07-14 19:53:44 +0000 | [diff] [blame] | 1664 | findUntaggedStructOrUnionIndex(FoundRecord)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 1665 | if (*Index1 != *Index2) |
| 1666 | continue; |
| 1667 | } |
| 1668 | } |
| 1669 | } |
| 1670 | |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 1671 | PrevDecl = FoundRecord; |
| 1672 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1673 | if (RecordDecl *FoundDef = FoundRecord->getDefinition()) { |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1674 | if ((SearchName && !D->isCompleteDefinition()) |
| 1675 | || (D->isCompleteDefinition() && |
| 1676 | D->isAnonymousStructOrUnion() |
| 1677 | == FoundDef->isAnonymousStructOrUnion() && |
| 1678 | IsStructuralMatch(D, FoundDef))) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1679 | // The record types structurally match, or the "from" translation |
| 1680 | // unit only had a forward declaration anyway; call it the same |
| 1681 | // function. |
| 1682 | // FIXME: For C++, we should also merge methods here. |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1683 | return Importer.Imported(D, FoundDef); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1684 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1685 | } else if (!D->isCompleteDefinition()) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1686 | // We have a forward declaration of this type, so adopt that forward |
| 1687 | // declaration rather than building a new one. |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 1688 | |
| 1689 | // If one or both can be completed from external storage then try one |
| 1690 | // last time to complete and compare them before doing this. |
| 1691 | |
| 1692 | if (FoundRecord->hasExternalLexicalStorage() && |
| 1693 | !FoundRecord->isCompleteDefinition()) |
| 1694 | FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord); |
| 1695 | if (D->hasExternalLexicalStorage()) |
| 1696 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 1697 | |
| 1698 | if (FoundRecord->isCompleteDefinition() && |
| 1699 | D->isCompleteDefinition() && |
| 1700 | !IsStructuralMatch(D, FoundRecord)) |
| 1701 | continue; |
| 1702 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1703 | AdoptDecl = FoundRecord; |
| 1704 | continue; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1705 | } else if (!SearchName) { |
| 1706 | continue; |
| 1707 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1708 | } |
| 1709 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1710 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1711 | } |
| 1712 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1713 | if (!ConflictingDecls.empty() && SearchName) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1714 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1715 | ConflictingDecls.data(), |
| 1716 | ConflictingDecls.size()); |
| 1717 | } |
| 1718 | } |
| 1719 | |
| 1720 | // Create the record declaration. |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1721 | RecordDecl *D2 = AdoptDecl; |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 1722 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1723 | if (!D2) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 1724 | CXXRecordDecl *D2CXX = nullptr; |
| 1725 | if (CXXRecordDecl *DCXX = llvm::dyn_cast<CXXRecordDecl>(D)) { |
| 1726 | if (DCXX->isLambda()) { |
| 1727 | TypeSourceInfo *TInfo = Importer.Import(DCXX->getLambdaTypeInfo()); |
| 1728 | D2CXX = CXXRecordDecl::CreateLambda(Importer.getToContext(), |
| 1729 | DC, TInfo, Loc, |
| 1730 | DCXX->isDependentLambda(), |
| 1731 | DCXX->isGenericLambda(), |
| 1732 | DCXX->getLambdaCaptureDefault()); |
| 1733 | Decl *CDecl = Importer.Import(DCXX->getLambdaContextDecl()); |
| 1734 | if (DCXX->getLambdaContextDecl() && !CDecl) |
| 1735 | return nullptr; |
Sean Callanan | 041cceb | 2016-05-14 05:43:57 +0000 | [diff] [blame] | 1736 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), CDecl); |
| 1737 | } else if (DCXX->isInjectedClassName()) { |
| 1738 | // We have to be careful to do a similar dance to the one in |
| 1739 | // Sema::ActOnStartCXXMemberDeclarations |
| 1740 | CXXRecordDecl *const PrevDecl = nullptr; |
| 1741 | const bool DelayTypeCreation = true; |
| 1742 | D2CXX = CXXRecordDecl::Create( |
| 1743 | Importer.getToContext(), D->getTagKind(), DC, StartLoc, Loc, |
| 1744 | Name.getAsIdentifierInfo(), PrevDecl, DelayTypeCreation); |
| 1745 | Importer.getToContext().getTypeDeclType( |
| 1746 | D2CXX, llvm::dyn_cast<CXXRecordDecl>(DC)); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 1747 | } else { |
| 1748 | D2CXX = CXXRecordDecl::Create(Importer.getToContext(), |
| 1749 | D->getTagKind(), |
| 1750 | DC, StartLoc, Loc, |
| 1751 | Name.getAsIdentifierInfo()); |
| 1752 | } |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1753 | D2 = D2CXX; |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1754 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1755 | } else { |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1756 | D2 = RecordDecl::Create(Importer.getToContext(), D->getTagKind(), |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 1757 | DC, StartLoc, Loc, Name.getAsIdentifierInfo()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1758 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 1759 | |
| 1760 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1761 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1762 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1763 | if (D->isAnonymousStructOrUnion()) |
| 1764 | D2->setAnonymousStructOrUnion(true); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 1765 | if (PrevDecl) { |
| 1766 | // FIXME: do this for all Redeclarables, not just RecordDecls. |
| 1767 | D2->setPreviousDecl(PrevDecl); |
| 1768 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1769 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1770 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1771 | Importer.Imported(D, D2); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1772 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1773 | if (D->isCompleteDefinition() && ImportDefinition(D, D2, IDK_Default)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1774 | return nullptr; |
| 1775 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1776 | return D2; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1777 | } |
| 1778 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1779 | Decl *ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| 1780 | // Import the major distinguishing characteristics of this enumerator. |
| 1781 | DeclContext *DC, *LexicalDC; |
| 1782 | DeclarationName Name; |
| 1783 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1784 | NamedDecl *ToD; |
| 1785 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1786 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1787 | if (ToD) |
| 1788 | return ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1789 | |
| 1790 | QualType T = Importer.Import(D->getType()); |
| 1791 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1792 | return nullptr; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1793 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1794 | // Determine whether there are any other declarations with the same name and |
| 1795 | // in the same context. |
| 1796 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1797 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1798 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1799 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1800 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1801 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1802 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1803 | continue; |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1804 | |
| 1805 | if (EnumConstantDecl *FoundEnumConstant |
| 1806 | = dyn_cast<EnumConstantDecl>(FoundDecls[I])) { |
| 1807 | if (IsStructuralMatch(D, FoundEnumConstant)) |
| 1808 | return Importer.Imported(D, FoundEnumConstant); |
| 1809 | } |
| 1810 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1811 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | if (!ConflictingDecls.empty()) { |
| 1815 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1816 | ConflictingDecls.data(), |
| 1817 | ConflictingDecls.size()); |
| 1818 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1819 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1820 | } |
| 1821 | } |
| 1822 | |
| 1823 | Expr *Init = Importer.Import(D->getInitExpr()); |
| 1824 | if (D->getInitExpr() && !Init) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1825 | return nullptr; |
| 1826 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1827 | EnumConstantDecl *ToEnumerator |
| 1828 | = EnumConstantDecl::Create(Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
| 1829 | Name.getAsIdentifierInfo(), T, |
| 1830 | Init, D->getInitVal()); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1831 | ToEnumerator->setAccess(D->getAccess()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1832 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1833 | Importer.Imported(D, ToEnumerator); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1834 | LexicalDC->addDeclInternal(ToEnumerator); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1835 | return ToEnumerator; |
| 1836 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1837 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1838 | Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
| 1839 | // Import the major distinguishing characteristics of this function. |
| 1840 | DeclContext *DC, *LexicalDC; |
| 1841 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1842 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1843 | NamedDecl *ToD; |
| 1844 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1845 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1846 | if (ToD) |
| 1847 | return ToD; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1848 | |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 1849 | const FunctionDecl *FoundWithoutBody = nullptr; |
| 1850 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1851 | // Try to find a function in our own ("to") context with the same name, same |
| 1852 | // type, and in the same context as the function we're importing. |
| 1853 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1854 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1855 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1856 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1857 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1858 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1859 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1860 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1861 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1862 | if (FunctionDecl *FoundFunction = dyn_cast<FunctionDecl>(FoundDecls[I])) { |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 1863 | if (FoundFunction->hasExternalFormalLinkage() && |
| 1864 | D->hasExternalFormalLinkage()) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1865 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| 1866 | FoundFunction->getType())) { |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1867 | // FIXME: Actually try to merge the body and other attributes. |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 1868 | const FunctionDecl *FromBodyDecl = nullptr; |
| 1869 | D->hasBody(FromBodyDecl); |
| 1870 | if (D == FromBodyDecl && !FoundFunction->hasBody()) { |
| 1871 | // This function is needed to merge completely. |
| 1872 | FoundWithoutBody = FoundFunction; |
| 1873 | break; |
| 1874 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1875 | return Importer.Imported(D, FoundFunction); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1876 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1877 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1878 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 1879 | // Sema::IsOverload out to the AST library. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1880 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1881 | // Function overloading is okay in C++. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1882 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1883 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1884 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1885 | // Complain about inconsistent function types. |
| 1886 | Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1887 | << Name << D->getType() << FoundFunction->getType(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1888 | Importer.ToDiag(FoundFunction->getLocation(), |
| 1889 | diag::note_odr_value_here) |
| 1890 | << FoundFunction->getType(); |
| 1891 | } |
| 1892 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1893 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1894 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1895 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1896 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1897 | if (!ConflictingDecls.empty()) { |
| 1898 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1899 | ConflictingDecls.data(), |
| 1900 | ConflictingDecls.size()); |
| 1901 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1902 | return nullptr; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1903 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 1904 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1905 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1906 | DeclarationNameInfo NameInfo(Name, Loc); |
| 1907 | // Import additional name location/type info. |
| 1908 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 1909 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 1910 | QualType FromTy = D->getType(); |
| 1911 | bool usedDifferentExceptionSpec = false; |
| 1912 | |
| 1913 | if (const FunctionProtoType * |
| 1914 | FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
| 1915 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 1916 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 1917 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 1918 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 1919 | // with a simplified function type and update it afterwards. |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 1920 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 1921 | FromEPI.ExceptionSpec.SourceTemplate || |
| 1922 | FromEPI.ExceptionSpec.NoexceptExpr) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 1923 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 1924 | FromTy = Importer.getFromContext().getFunctionType( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 1925 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 1926 | usedDifferentExceptionSpec = true; |
| 1927 | } |
| 1928 | } |
| 1929 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1930 | // Import the type. |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 1931 | QualType T = Importer.Import(FromTy); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1932 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1933 | return nullptr; |
| 1934 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1935 | // Import the function parameters. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1936 | SmallVector<ParmVarDecl *, 8> Parameters; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 1937 | for (auto P : D->parameters()) { |
Aaron Ballman | f6bf62e | 2014-03-07 15:12:56 +0000 | [diff] [blame] | 1938 | ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(P)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1939 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1940 | return nullptr; |
| 1941 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1942 | Parameters.push_back(ToP); |
| 1943 | } |
| 1944 | |
| 1945 | // Create the imported function. |
| 1946 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1947 | FunctionDecl *ToFunction = nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1948 | SourceLocation InnerLocStart = Importer.Import(D->getInnerLocStart()); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 1949 | if (CXXConstructorDecl *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| 1950 | ToFunction = CXXConstructorDecl::Create(Importer.getToContext(), |
| 1951 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1952 | InnerLocStart, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1953 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 1954 | FromConstructor->isExplicit(), |
| 1955 | D->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1956 | D->isImplicit(), |
| 1957 | D->isConstexpr()); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 1958 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 1959 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers; |
| 1960 | for (CXXCtorInitializer *I : FromConstructor->inits()) { |
| 1961 | CXXCtorInitializer *ToI = |
| 1962 | cast_or_null<CXXCtorInitializer>(Importer.Import(I)); |
| 1963 | if (!ToI && I) |
| 1964 | return nullptr; |
| 1965 | CtorInitializers.push_back(ToI); |
| 1966 | } |
| 1967 | CXXCtorInitializer **Memory = |
| 1968 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 1969 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
| 1970 | CXXConstructorDecl *ToCtor = llvm::cast<CXXConstructorDecl>(ToFunction); |
| 1971 | ToCtor->setCtorInitializers(Memory); |
| 1972 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 1973 | } |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 1974 | } else if (isa<CXXDestructorDecl>(D)) { |
| 1975 | ToFunction = CXXDestructorDecl::Create(Importer.getToContext(), |
| 1976 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1977 | InnerLocStart, |
Craig Silverstein | af8808d | 2010-10-21 00:44:50 +0000 | [diff] [blame] | 1978 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 1979 | D->isInlineSpecified(), |
| 1980 | D->isImplicit()); |
| 1981 | } else if (CXXConversionDecl *FromConversion |
| 1982 | = dyn_cast<CXXConversionDecl>(D)) { |
| 1983 | ToFunction = CXXConversionDecl::Create(Importer.getToContext(), |
| 1984 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1985 | InnerLocStart, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1986 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 1987 | D->isInlineSpecified(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 1988 | FromConversion->isExplicit(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1989 | D->isConstexpr(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 1990 | Importer.Import(D->getLocEnd())); |
Douglas Gregor | a50ad13 | 2010-11-29 16:04:58 +0000 | [diff] [blame] | 1991 | } else if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { |
| 1992 | ToFunction = CXXMethodDecl::Create(Importer.getToContext(), |
| 1993 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1994 | InnerLocStart, |
Douglas Gregor | a50ad13 | 2010-11-29 16:04:58 +0000 | [diff] [blame] | 1995 | NameInfo, T, TInfo, |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 1996 | Method->getStorageClass(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 1997 | Method->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1998 | D->isConstexpr(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 1999 | Importer.Import(D->getLocEnd())); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2000 | } else { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2001 | ToFunction = FunctionDecl::Create(Importer.getToContext(), DC, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2002 | InnerLocStart, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2003 | NameInfo, T, TInfo, D->getStorageClass(), |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2004 | D->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2005 | D->hasWrittenPrototype(), |
| 2006 | D->isConstexpr()); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2007 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 2008 | |
| 2009 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2010 | ToFunction->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2011 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2012 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 2013 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 2014 | ToFunction->setTrivial(D->isTrivial()); |
| 2015 | ToFunction->setPure(D->isPure()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2016 | Importer.Imported(D, ToFunction); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2017 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2018 | // Set the parameters. |
| 2019 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2020 | Parameters[I]->setOwningFunction(ToFunction); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2021 | ToFunction->addDeclInternal(Parameters[I]); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2022 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 2023 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2024 | |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2025 | if (FoundWithoutBody) { |
| 2026 | auto *Recent = const_cast<FunctionDecl *>( |
| 2027 | FoundWithoutBody->getMostRecentDecl()); |
| 2028 | ToFunction->setPreviousDecl(Recent); |
| 2029 | } |
| 2030 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2031 | if (usedDifferentExceptionSpec) { |
| 2032 | // Update FunctionProtoType::ExtProtoInfo. |
| 2033 | QualType T = Importer.Import(D->getType()); |
| 2034 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2035 | return nullptr; |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2036 | ToFunction->setType(T); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 2037 | } |
| 2038 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2039 | // Import the body, if any. |
| 2040 | if (Stmt *FromBody = D->getBody()) { |
| 2041 | if (Stmt *ToBody = Importer.Import(FromBody)) { |
| 2042 | ToFunction->setBody(ToBody); |
| 2043 | } |
| 2044 | } |
| 2045 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2046 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2047 | |
| 2048 | // Add this function to the lexical context. |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2049 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2050 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 2051 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 2052 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 2053 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2054 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2055 | } |
| 2056 | |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2057 | Decl *ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| 2058 | return VisitFunctionDecl(D); |
| 2059 | } |
| 2060 | |
| 2061 | Decl *ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| 2062 | return VisitCXXMethodDecl(D); |
| 2063 | } |
| 2064 | |
| 2065 | Decl *ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| 2066 | return VisitCXXMethodDecl(D); |
| 2067 | } |
| 2068 | |
| 2069 | Decl *ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| 2070 | return VisitCXXMethodDecl(D); |
| 2071 | } |
| 2072 | |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2073 | static unsigned getFieldIndex(Decl *F) { |
| 2074 | RecordDecl *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
| 2075 | if (!Owner) |
| 2076 | return 0; |
| 2077 | |
| 2078 | unsigned Index = 1; |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2079 | for (const auto *D : Owner->noload_decls()) { |
| 2080 | if (D == F) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2081 | return Index; |
| 2082 | |
| 2083 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 2084 | ++Index; |
| 2085 | } |
| 2086 | |
| 2087 | return Index; |
| 2088 | } |
| 2089 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2090 | Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
| 2091 | // Import the major distinguishing characteristics of a variable. |
| 2092 | DeclContext *DC, *LexicalDC; |
| 2093 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2094 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2095 | NamedDecl *ToD; |
| 2096 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2097 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2098 | if (ToD) |
| 2099 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2100 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2101 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2102 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2103 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2104 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2105 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2106 | // For anonymous fields, match up by index. |
| 2107 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2108 | continue; |
| 2109 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2110 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2111 | FoundField->getType())) { |
| 2112 | Importer.Imported(D, FoundField); |
| 2113 | return FoundField; |
| 2114 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2115 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2116 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2117 | << Name << D->getType() << FoundField->getType(); |
| 2118 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2119 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2120 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2121 | } |
| 2122 | } |
| 2123 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2124 | // Import the type. |
| 2125 | QualType T = Importer.Import(D->getType()); |
| 2126 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2127 | return nullptr; |
| 2128 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2129 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2130 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 2131 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2132 | return nullptr; |
| 2133 | |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2134 | FieldDecl *ToField = FieldDecl::Create(Importer.getToContext(), DC, |
| 2135 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2136 | Loc, Name.getAsIdentifierInfo(), |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2137 | T, TInfo, BitWidth, D->isMutable(), |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2138 | D->getInClassInitStyle()); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2139 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2140 | ToField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 3a83ea7 | 2016-03-03 02:22:05 +0000 | [diff] [blame] | 2141 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
Sean Callanan | bb33f58 | 2016-03-03 01:21:28 +0000 | [diff] [blame] | 2142 | Expr *ToInitializer = Importer.Import(FromInitializer); |
| 2143 | if (ToInitializer) |
| 2144 | ToField->setInClassInitializer(ToInitializer); |
| 2145 | else |
| 2146 | return nullptr; |
| 2147 | } |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2148 | ToField->setImplicit(D->isImplicit()); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2149 | Importer.Imported(D, ToField); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2150 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2151 | return ToField; |
| 2152 | } |
| 2153 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2154 | Decl *ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| 2155 | // Import the major distinguishing characteristics of a variable. |
| 2156 | DeclContext *DC, *LexicalDC; |
| 2157 | DeclarationName Name; |
| 2158 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2159 | NamedDecl *ToD; |
| 2160 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2161 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2162 | if (ToD) |
| 2163 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2164 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2165 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2166 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2167 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2168 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2169 | if (IndirectFieldDecl *FoundField |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2170 | = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2171 | // For anonymous indirect fields, match up by index. |
| 2172 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2173 | continue; |
| 2174 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2175 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2176 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 2177 | !Name.isEmpty())) { |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2178 | Importer.Imported(D, FoundField); |
| 2179 | return FoundField; |
| 2180 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2181 | |
| 2182 | // If there are more anonymous fields to check, continue. |
| 2183 | if (!Name && I < N-1) |
| 2184 | continue; |
| 2185 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2186 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2187 | << Name << D->getType() << FoundField->getType(); |
| 2188 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2189 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2190 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2191 | } |
| 2192 | } |
| 2193 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2194 | // Import the type. |
| 2195 | QualType T = Importer.Import(D->getType()); |
| 2196 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2197 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2198 | |
| 2199 | NamedDecl **NamedChain = |
| 2200 | new (Importer.getToContext())NamedDecl*[D->getChainingSize()]; |
| 2201 | |
| 2202 | unsigned i = 0; |
Aaron Ballman | 29c9460 | 2014-03-07 18:36:15 +0000 | [diff] [blame] | 2203 | for (auto *PI : D->chain()) { |
Aaron Ballman | 1391608 | 2014-03-07 18:11:58 +0000 | [diff] [blame] | 2204 | Decl *D = Importer.Import(PI); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2205 | if (!D) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2206 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2207 | NamedChain[i++] = cast<NamedDecl>(D); |
| 2208 | } |
| 2209 | |
| 2210 | IndirectFieldDecl *ToIndirectField = IndirectFieldDecl::Create( |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2211 | Importer.getToContext(), DC, Loc, Name.getAsIdentifierInfo(), T, |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2212 | {NamedChain, D->getChainingSize()}); |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2213 | |
| 2214 | for (const auto *Attr : D->attrs()) |
| 2215 | ToIndirectField->addAttr(Attr->clone(Importer.getToContext())); |
| 2216 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2217 | ToIndirectField->setAccess(D->getAccess()); |
| 2218 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
| 2219 | Importer.Imported(D, ToIndirectField); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2220 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2221 | return ToIndirectField; |
| 2222 | } |
| 2223 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2224 | Decl *ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
| 2225 | // Import the major distinguishing characteristics of a declaration. |
| 2226 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 2227 | DeclContext *LexicalDC = D->getDeclContext() == D->getLexicalDeclContext() |
| 2228 | ? DC : Importer.ImportContext(D->getLexicalDeclContext()); |
| 2229 | if (!DC || !LexicalDC) |
| 2230 | return nullptr; |
| 2231 | |
| 2232 | // Determine whether we've already imported this decl. |
| 2233 | // FriendDecl is not a NamedDecl so we cannot use localUncachedLookup. |
| 2234 | auto *RD = cast<CXXRecordDecl>(DC); |
| 2235 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
| 2236 | StructuralEquivalenceContext Context( |
| 2237 | Importer.getFromContext(), Importer.getToContext(), |
| 2238 | Importer.getNonEquivalentDecls(), false, false); |
| 2239 | |
| 2240 | while (ImportedFriend) { |
| 2241 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
| 2242 | if (Context.IsStructurallyEquivalent(D->getFriendDecl(), |
| 2243 | ImportedFriend->getFriendDecl())) |
| 2244 | return Importer.Imported(D, ImportedFriend); |
| 2245 | |
| 2246 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 2247 | if (Importer.IsStructurallyEquivalent( |
| 2248 | D->getFriendType()->getType(), |
| 2249 | ImportedFriend->getFriendType()->getType(), true)) |
| 2250 | return Importer.Imported(D, ImportedFriend); |
| 2251 | } |
| 2252 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 2253 | } |
| 2254 | |
| 2255 | // Not found. Create it. |
| 2256 | FriendDecl::FriendUnion ToFU; |
| 2257 | if (NamedDecl *FriendD = D->getFriendDecl()) |
| 2258 | ToFU = cast_or_null<NamedDecl>(Importer.Import(FriendD)); |
| 2259 | else |
| 2260 | ToFU = Importer.Import(D->getFriendType()); |
| 2261 | if (!ToFU) |
| 2262 | return nullptr; |
| 2263 | |
| 2264 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
| 2265 | TemplateParameterList **FromTPLists = |
| 2266 | D->getTrailingObjects<TemplateParameterList *>(); |
| 2267 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
| 2268 | TemplateParameterList *List = ImportTemplateParameterList(FromTPLists[I]); |
| 2269 | if (!List) |
| 2270 | return nullptr; |
| 2271 | ToTPLists[I] = List; |
| 2272 | } |
| 2273 | |
| 2274 | FriendDecl *FrD = FriendDecl::Create(Importer.getToContext(), DC, |
| 2275 | Importer.Import(D->getLocation()), |
| 2276 | ToFU, Importer.Import(D->getFriendLoc()), |
| 2277 | ToTPLists); |
| 2278 | |
| 2279 | Importer.Imported(D, FrD); |
| 2280 | RD->pushFriendDecl(FrD); |
| 2281 | |
| 2282 | FrD->setAccess(D->getAccess()); |
| 2283 | FrD->setLexicalDeclContext(LexicalDC); |
| 2284 | LexicalDC->addDeclInternal(FrD); |
| 2285 | return FrD; |
| 2286 | } |
| 2287 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2288 | Decl *ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| 2289 | // Import the major distinguishing characteristics of an ivar. |
| 2290 | DeclContext *DC, *LexicalDC; |
| 2291 | DeclarationName Name; |
| 2292 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2293 | NamedDecl *ToD; |
| 2294 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2295 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2296 | if (ToD) |
| 2297 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2298 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2299 | // Determine whether we've already imported this ivar |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2300 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2301 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2302 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2303 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecls[I])) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2304 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2305 | FoundIvar->getType())) { |
| 2306 | Importer.Imported(D, FoundIvar); |
| 2307 | return FoundIvar; |
| 2308 | } |
| 2309 | |
| 2310 | Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent) |
| 2311 | << Name << D->getType() << FoundIvar->getType(); |
| 2312 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 2313 | << FoundIvar->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2314 | return nullptr; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2315 | } |
| 2316 | } |
| 2317 | |
| 2318 | // Import the type. |
| 2319 | QualType T = Importer.Import(D->getType()); |
| 2320 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2321 | return nullptr; |
| 2322 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2323 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2324 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 2325 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2326 | return nullptr; |
| 2327 | |
Daniel Dunbar | fe3ead7 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 2328 | ObjCIvarDecl *ToIvar = ObjCIvarDecl::Create(Importer.getToContext(), |
| 2329 | cast<ObjCContainerDecl>(DC), |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2330 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2331 | Loc, Name.getAsIdentifierInfo(), |
| 2332 | T, TInfo, D->getAccessControl(), |
Argyrios Kyrtzidis | 2080d90 | 2014-01-03 18:32:18 +0000 | [diff] [blame] | 2333 | BitWidth, D->getSynthesize()); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2334 | ToIvar->setLexicalDeclContext(LexicalDC); |
| 2335 | Importer.Imported(D, ToIvar); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2336 | LexicalDC->addDeclInternal(ToIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2337 | return ToIvar; |
| 2338 | |
| 2339 | } |
| 2340 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2341 | Decl *ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
| 2342 | // Import the major distinguishing characteristics of a variable. |
| 2343 | DeclContext *DC, *LexicalDC; |
| 2344 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2345 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2346 | NamedDecl *ToD; |
| 2347 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2348 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2349 | if (ToD) |
| 2350 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2351 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2352 | // Try to find a variable in our own ("to") context with the same name and |
| 2353 | // in the same context as the variable we're importing. |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2354 | if (D->isFileVarDecl()) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2355 | VarDecl *MergeWithVar = nullptr; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2356 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2357 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2358 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2359 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2360 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2361 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2362 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2363 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2364 | if (VarDecl *FoundVar = dyn_cast<VarDecl>(FoundDecls[I])) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2365 | // 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] | 2366 | if (FoundVar->hasExternalFormalLinkage() && |
| 2367 | D->hasExternalFormalLinkage()) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2368 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2369 | FoundVar->getType())) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2370 | MergeWithVar = FoundVar; |
| 2371 | break; |
| 2372 | } |
| 2373 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2374 | const ArrayType *FoundArray |
| 2375 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 2376 | const ArrayType *TArray |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2377 | = Importer.getToContext().getAsArrayType(D->getType()); |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2378 | if (FoundArray && TArray) { |
| 2379 | if (isa<IncompleteArrayType>(FoundArray) && |
| 2380 | isa<ConstantArrayType>(TArray)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2381 | // Import the type. |
| 2382 | QualType T = Importer.Import(D->getType()); |
| 2383 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2384 | return nullptr; |
| 2385 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2386 | FoundVar->setType(T); |
| 2387 | MergeWithVar = FoundVar; |
| 2388 | break; |
| 2389 | } else if (isa<IncompleteArrayType>(TArray) && |
| 2390 | isa<ConstantArrayType>(FoundArray)) { |
| 2391 | MergeWithVar = FoundVar; |
| 2392 | break; |
Douglas Gregor | 2fbe558 | 2010-02-10 17:16:49 +0000 | [diff] [blame] | 2393 | } |
| 2394 | } |
| 2395 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2396 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2397 | << Name << D->getType() << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2398 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 2399 | << FoundVar->getType(); |
| 2400 | } |
| 2401 | } |
| 2402 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2403 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2404 | } |
| 2405 | |
| 2406 | if (MergeWithVar) { |
| 2407 | // An equivalent variable with external linkage has been found. Link |
| 2408 | // the two declarations, then merge them. |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2409 | Importer.Imported(D, MergeWithVar); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2410 | |
| 2411 | if (VarDecl *DDef = D->getDefinition()) { |
| 2412 | if (VarDecl *ExistingDef = MergeWithVar->getDefinition()) { |
| 2413 | Importer.ToDiag(ExistingDef->getLocation(), |
| 2414 | diag::err_odr_variable_multiple_def) |
| 2415 | << Name; |
| 2416 | Importer.FromDiag(DDef->getLocation(), diag::note_odr_defined_here); |
| 2417 | } else { |
| 2418 | Expr *Init = Importer.Import(DDef->getInit()); |
Douglas Gregor | d505812 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 2419 | MergeWithVar->setInit(Init); |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 2420 | if (DDef->isInitKnownICE()) { |
| 2421 | EvaluatedStmt *Eval = MergeWithVar->ensureEvaluatedStmt(); |
| 2422 | Eval->CheckedICE = true; |
| 2423 | Eval->IsICE = DDef->isInitICE(); |
| 2424 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2425 | } |
| 2426 | } |
| 2427 | |
| 2428 | return MergeWithVar; |
| 2429 | } |
| 2430 | |
| 2431 | if (!ConflictingDecls.empty()) { |
| 2432 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2433 | ConflictingDecls.data(), |
| 2434 | ConflictingDecls.size()); |
| 2435 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2436 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2437 | } |
| 2438 | } |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2439 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2440 | // Import the type. |
| 2441 | QualType T = Importer.Import(D->getType()); |
| 2442 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2443 | return nullptr; |
| 2444 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2445 | // Create the imported variable. |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2446 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2447 | VarDecl *ToVar = VarDecl::Create(Importer.getToContext(), DC, |
| 2448 | Importer.Import(D->getInnerLocStart()), |
| 2449 | Loc, Name.getAsIdentifierInfo(), |
| 2450 | T, TInfo, |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 2451 | D->getStorageClass()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2452 | ToVar->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2453 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2454 | ToVar->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2455 | Importer.Imported(D, ToVar); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2456 | LexicalDC->addDeclInternal(ToVar); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2457 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2458 | if (!D->isFileVarDecl() && |
| 2459 | D->isUsed()) |
| 2460 | ToVar->setIsUsed(); |
| 2461 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2462 | // Merge the initializer. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2463 | if (ImportDefinition(D, ToVar)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2464 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2465 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 2466 | if (D->isConstexpr()) |
| 2467 | ToVar->setConstexpr(true); |
| 2468 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2469 | return ToVar; |
| 2470 | } |
| 2471 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2472 | Decl *ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| 2473 | // Parameters are created in the translation unit's context, then moved |
| 2474 | // into the function declaration's context afterward. |
| 2475 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| 2476 | |
| 2477 | // Import the name of this declaration. |
| 2478 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 2479 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2480 | return nullptr; |
| 2481 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2482 | // Import the location of this declaration. |
| 2483 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 2484 | |
| 2485 | // Import the parameter's type. |
| 2486 | QualType T = Importer.Import(D->getType()); |
| 2487 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2488 | return nullptr; |
| 2489 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2490 | // Create the imported parameter. |
Alexey Bataev | 5622323 | 2017-06-09 13:40:18 +0000 | [diff] [blame] | 2491 | auto *ToParm = ImplicitParamDecl::Create(Importer.getToContext(), DC, Loc, |
| 2492 | Name.getAsIdentifierInfo(), T, |
| 2493 | D->getParameterKind()); |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2494 | return Importer.Imported(D, ToParm); |
| 2495 | } |
| 2496 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2497 | Decl *ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
| 2498 | // Parameters are created in the translation unit's context, then moved |
| 2499 | // into the function declaration's context afterward. |
| 2500 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| 2501 | |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2502 | // Import the name of this declaration. |
| 2503 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 2504 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2505 | return nullptr; |
| 2506 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2507 | // Import the location of this declaration. |
| 2508 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 2509 | |
| 2510 | // Import the parameter's type. |
| 2511 | QualType T = Importer.Import(D->getType()); |
| 2512 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2513 | return nullptr; |
| 2514 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2515 | // Create the imported parameter. |
| 2516 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2517 | ParmVarDecl *ToParm = ParmVarDecl::Create(Importer.getToContext(), DC, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2518 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2519 | Loc, Name.getAsIdentifierInfo(), |
| 2520 | T, TInfo, D->getStorageClass(), |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 2521 | /*DefaultArg*/ nullptr); |
| 2522 | |
| 2523 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 2524 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 2525 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 2526 | |
| 2527 | Expr *ToDefArg = nullptr; |
| 2528 | Expr *FromDefArg = nullptr; |
| 2529 | if (D->hasUninstantiatedDefaultArg()) { |
| 2530 | FromDefArg = D->getUninstantiatedDefaultArg(); |
| 2531 | ToDefArg = Importer.Import(FromDefArg); |
| 2532 | ToParm->setUninstantiatedDefaultArg(ToDefArg); |
| 2533 | } else if (D->hasUnparsedDefaultArg()) { |
| 2534 | ToParm->setUnparsedDefaultArg(); |
| 2535 | } else if (D->hasDefaultArg()) { |
| 2536 | FromDefArg = D->getDefaultArg(); |
| 2537 | ToDefArg = Importer.Import(FromDefArg); |
| 2538 | ToParm->setDefaultArg(ToDefArg); |
| 2539 | } |
| 2540 | if (FromDefArg && !ToDefArg) |
| 2541 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2542 | |
| 2543 | if (D->isUsed()) |
| 2544 | ToParm->setIsUsed(); |
| 2545 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2546 | return Importer.Imported(D, ToParm); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2547 | } |
| 2548 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2549 | Decl *ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| 2550 | // Import the major distinguishing characteristics of a method. |
| 2551 | DeclContext *DC, *LexicalDC; |
| 2552 | DeclarationName Name; |
| 2553 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2554 | NamedDecl *ToD; |
| 2555 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2556 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2557 | if (ToD) |
| 2558 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2559 | |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2560 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2561 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2562 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2563 | if (ObjCMethodDecl *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecls[I])) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2564 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 2565 | continue; |
| 2566 | |
| 2567 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2568 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 2569 | FoundMethod->getReturnType())) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2570 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2571 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 2572 | << FoundMethod->getReturnType(); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2573 | Importer.ToDiag(FoundMethod->getLocation(), |
| 2574 | diag::note_odr_objc_method_here) |
| 2575 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2576 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2577 | } |
| 2578 | |
| 2579 | // Check the number of parameters. |
| 2580 | if (D->param_size() != FoundMethod->param_size()) { |
| 2581 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) |
| 2582 | << D->isInstanceMethod() << Name |
| 2583 | << D->param_size() << FoundMethod->param_size(); |
| 2584 | Importer.ToDiag(FoundMethod->getLocation(), |
| 2585 | diag::note_odr_objc_method_here) |
| 2586 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2587 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2588 | } |
| 2589 | |
| 2590 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2591 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2592 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 2593 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2594 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2595 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2596 | Importer.FromDiag((*P)->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2597 | diag::err_odr_objc_method_param_type_inconsistent) |
| 2598 | << D->isInstanceMethod() << Name |
| 2599 | << (*P)->getType() << (*FoundP)->getType(); |
| 2600 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 2601 | << (*FoundP)->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2602 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2603 | } |
| 2604 | } |
| 2605 | |
| 2606 | // Check variadic/non-variadic. |
| 2607 | // Check the number of parameters. |
| 2608 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| 2609 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) |
| 2610 | << D->isInstanceMethod() << Name; |
| 2611 | Importer.ToDiag(FoundMethod->getLocation(), |
| 2612 | diag::note_odr_objc_method_here) |
| 2613 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2614 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2615 | } |
| 2616 | |
| 2617 | // FIXME: Any other bits we need to merge? |
| 2618 | return Importer.Imported(D, FoundMethod); |
| 2619 | } |
| 2620 | } |
| 2621 | |
| 2622 | // Import the result type. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2623 | QualType ResultTy = Importer.Import(D->getReturnType()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2624 | if (ResultTy.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2625 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2626 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2627 | TypeSourceInfo *ReturnTInfo = Importer.Import(D->getReturnTypeSourceInfo()); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 2628 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2629 | ObjCMethodDecl *ToMethod = ObjCMethodDecl::Create( |
| 2630 | Importer.getToContext(), Loc, Importer.Import(D->getLocEnd()), |
| 2631 | Name.getObjCSelector(), ResultTy, ReturnTInfo, DC, D->isInstanceMethod(), |
| 2632 | D->isVariadic(), D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 2633 | D->getImplementationControl(), D->hasRelatedResultType()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2634 | |
| 2635 | // FIXME: When we decide to merge method definitions, we'll need to |
| 2636 | // deal with implicit parameters. |
| 2637 | |
| 2638 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2639 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2640 | for (auto *FromP : D->parameters()) { |
Aaron Ballman | 43b68be | 2014-03-07 17:50:17 +0000 | [diff] [blame] | 2641 | ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(FromP)); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2642 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2643 | return nullptr; |
| 2644 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2645 | ToParams.push_back(ToP); |
| 2646 | } |
| 2647 | |
| 2648 | // Set the parameters. |
| 2649 | for (unsigned I = 0, N = ToParams.size(); I != N; ++I) { |
| 2650 | ToParams[I]->setOwningFunction(ToMethod); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2651 | ToMethod->addDeclInternal(ToParams[I]); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2652 | } |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 2653 | SmallVector<SourceLocation, 12> SelLocs; |
| 2654 | D->getSelectorLocs(SelLocs); |
| 2655 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, SelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2656 | |
| 2657 | ToMethod->setLexicalDeclContext(LexicalDC); |
| 2658 | Importer.Imported(D, ToMethod); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2659 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2660 | return ToMethod; |
| 2661 | } |
| 2662 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 2663 | Decl *ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| 2664 | // Import the major distinguishing characteristics of a category. |
| 2665 | DeclContext *DC, *LexicalDC; |
| 2666 | DeclarationName Name; |
| 2667 | SourceLocation Loc; |
| 2668 | NamedDecl *ToD; |
| 2669 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2670 | return nullptr; |
| 2671 | if (ToD) |
| 2672 | return ToD; |
| 2673 | |
| 2674 | TypeSourceInfo *BoundInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2675 | if (!BoundInfo) |
| 2676 | return nullptr; |
| 2677 | |
| 2678 | ObjCTypeParamDecl *Result = ObjCTypeParamDecl::Create( |
| 2679 | Importer.getToContext(), DC, |
Douglas Gregor | 1ac1b63 | 2015-07-07 03:58:54 +0000 | [diff] [blame] | 2680 | D->getVariance(), |
| 2681 | Importer.Import(D->getVarianceLoc()), |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 2682 | D->getIndex(), |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 2683 | Importer.Import(D->getLocation()), |
| 2684 | Name.getAsIdentifierInfo(), |
| 2685 | Importer.Import(D->getColonLoc()), |
| 2686 | BoundInfo); |
| 2687 | Importer.Imported(D, Result); |
| 2688 | Result->setLexicalDeclContext(LexicalDC); |
| 2689 | return Result; |
| 2690 | } |
| 2691 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2692 | Decl *ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| 2693 | // Import the major distinguishing characteristics of a category. |
| 2694 | DeclContext *DC, *LexicalDC; |
| 2695 | DeclarationName Name; |
| 2696 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2697 | NamedDecl *ToD; |
| 2698 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2699 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2700 | if (ToD) |
| 2701 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2702 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2703 | ObjCInterfaceDecl *ToInterface |
| 2704 | = cast_or_null<ObjCInterfaceDecl>(Importer.Import(D->getClassInterface())); |
| 2705 | if (!ToInterface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2706 | return nullptr; |
| 2707 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2708 | // Determine if we've already encountered this category. |
| 2709 | ObjCCategoryDecl *MergeWithCategory |
| 2710 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 2711 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 2712 | if (!ToCategory) { |
| 2713 | ToCategory = ObjCCategoryDecl::Create(Importer.getToContext(), DC, |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 2714 | Importer.Import(D->getAtStartLoc()), |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2715 | Loc, |
| 2716 | Importer.Import(D->getCategoryNameLoc()), |
Argyrios Kyrtzidis | 3a5094b | 2011-08-30 19:43:26 +0000 | [diff] [blame] | 2717 | Name.getAsIdentifierInfo(), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 2718 | ToInterface, |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 2719 | /*TypeParamList=*/nullptr, |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 2720 | Importer.Import(D->getIvarLBraceLoc()), |
| 2721 | Importer.Import(D->getIvarRBraceLoc())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2722 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2723 | LexicalDC->addDeclInternal(ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2724 | Importer.Imported(D, ToCategory); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 2725 | // Import the type parameter list after calling Imported, to avoid |
| 2726 | // loops when bringing in their DeclContext. |
| 2727 | ToCategory->setTypeParamList(ImportObjCTypeParamList( |
| 2728 | D->getTypeParamList())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2729 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2730 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2731 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 2732 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2733 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 2734 | = D->protocol_loc_begin(); |
| 2735 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 2736 | FromProtoEnd = D->protocol_end(); |
| 2737 | FromProto != FromProtoEnd; |
| 2738 | ++FromProto, ++FromProtoLoc) { |
| 2739 | ObjCProtocolDecl *ToProto |
| 2740 | = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
| 2741 | if (!ToProto) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2742 | return nullptr; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2743 | Protocols.push_back(ToProto); |
| 2744 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 2745 | } |
| 2746 | |
| 2747 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 2748 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 2749 | ProtocolLocs.data(), Importer.getToContext()); |
| 2750 | |
| 2751 | } else { |
| 2752 | Importer.Imported(D, ToCategory); |
| 2753 | } |
| 2754 | |
| 2755 | // Import all of the members of this category. |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 2756 | ImportDeclContext(D); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2757 | |
| 2758 | // If we have an implementation, import it as well. |
| 2759 | if (D->getImplementation()) { |
| 2760 | ObjCCategoryImplDecl *Impl |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 2761 | = cast_or_null<ObjCCategoryImplDecl>( |
| 2762 | Importer.Import(D->getImplementation())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2763 | if (!Impl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2764 | return nullptr; |
| 2765 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2766 | ToCategory->setImplementation(Impl); |
| 2767 | } |
| 2768 | |
| 2769 | return ToCategory; |
| 2770 | } |
| 2771 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2772 | bool ASTNodeImporter::ImportDefinition(ObjCProtocolDecl *From, |
| 2773 | ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2774 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2775 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2776 | if (shouldForceImportDeclContext(Kind)) |
| 2777 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2778 | return false; |
| 2779 | } |
| 2780 | |
| 2781 | // Start the protocol definition |
| 2782 | To->startDefinition(); |
| 2783 | |
| 2784 | // Import protocols |
| 2785 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 2786 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| 2787 | ObjCProtocolDecl::protocol_loc_iterator |
| 2788 | FromProtoLoc = From->protocol_loc_begin(); |
| 2789 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 2790 | FromProtoEnd = From->protocol_end(); |
| 2791 | FromProto != FromProtoEnd; |
| 2792 | ++FromProto, ++FromProtoLoc) { |
| 2793 | ObjCProtocolDecl *ToProto |
| 2794 | = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
| 2795 | if (!ToProto) |
| 2796 | return true; |
| 2797 | Protocols.push_back(ToProto); |
| 2798 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 2799 | } |
| 2800 | |
| 2801 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 2802 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 2803 | ProtocolLocs.data(), Importer.getToContext()); |
| 2804 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2805 | if (shouldForceImportDeclContext(Kind)) { |
| 2806 | // Import all of the members of this protocol. |
| 2807 | ImportDeclContext(From, /*ForceImport=*/true); |
| 2808 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2809 | return false; |
| 2810 | } |
| 2811 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 2812 | Decl *ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2813 | // If this protocol has a definition in the translation unit we're coming |
| 2814 | // from, but this particular declaration is not that definition, import the |
| 2815 | // definition and map to that. |
| 2816 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 2817 | if (Definition && Definition != D) { |
| 2818 | Decl *ImportedDef = Importer.Import(Definition); |
| 2819 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2820 | return nullptr; |
| 2821 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2822 | return Importer.Imported(D, ImportedDef); |
| 2823 | } |
| 2824 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2825 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 2826 | DeclContext *DC, *LexicalDC; |
| 2827 | DeclarationName Name; |
| 2828 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2829 | NamedDecl *ToD; |
| 2830 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2831 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2832 | if (ToD) |
| 2833 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 2834 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2835 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2836 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2837 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2838 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2839 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 2840 | continue; |
| 2841 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2842 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecls[I]))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 2843 | break; |
| 2844 | } |
| 2845 | |
| 2846 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2847 | if (!ToProto) { |
| 2848 | ToProto = ObjCProtocolDecl::Create(Importer.getToContext(), DC, |
| 2849 | Name.getAsIdentifierInfo(), Loc, |
| 2850 | Importer.Import(D->getAtStartLoc()), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2851 | /*PrevDecl=*/nullptr); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2852 | ToProto->setLexicalDeclContext(LexicalDC); |
| 2853 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 2854 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2855 | |
| 2856 | Importer.Imported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 2857 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2858 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToProto)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2859 | return nullptr; |
| 2860 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 2861 | return ToProto; |
| 2862 | } |
| 2863 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 2864 | Decl *ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 2865 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 2866 | DeclContext *LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 2867 | |
| 2868 | SourceLocation ExternLoc = Importer.Import(D->getExternLoc()); |
| 2869 | SourceLocation LangLoc = Importer.Import(D->getLocation()); |
| 2870 | |
| 2871 | bool HasBraces = D->hasBraces(); |
| 2872 | |
Sean Callanan | b12a855 | 2014-12-10 21:22:20 +0000 | [diff] [blame] | 2873 | LinkageSpecDecl *ToLinkageSpec = |
| 2874 | LinkageSpecDecl::Create(Importer.getToContext(), |
| 2875 | DC, |
| 2876 | ExternLoc, |
| 2877 | LangLoc, |
| 2878 | D->getLanguage(), |
| 2879 | HasBraces); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 2880 | |
| 2881 | if (HasBraces) { |
| 2882 | SourceLocation RBraceLoc = Importer.Import(D->getRBraceLoc()); |
| 2883 | ToLinkageSpec->setRBraceLoc(RBraceLoc); |
| 2884 | } |
| 2885 | |
| 2886 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 2887 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 2888 | |
| 2889 | Importer.Imported(D, ToLinkageSpec); |
| 2890 | |
| 2891 | return ToLinkageSpec; |
| 2892 | } |
| 2893 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2894 | bool ASTNodeImporter::ImportDefinition(ObjCInterfaceDecl *From, |
| 2895 | ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2896 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2897 | if (To->getDefinition()) { |
| 2898 | // Check consistency of superclass. |
| 2899 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 2900 | if (FromSuper) { |
| 2901 | FromSuper = cast_or_null<ObjCInterfaceDecl>(Importer.Import(FromSuper)); |
| 2902 | if (!FromSuper) |
| 2903 | return true; |
| 2904 | } |
| 2905 | |
| 2906 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
| 2907 | if ((bool)FromSuper != (bool)ToSuper || |
| 2908 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
| 2909 | Importer.ToDiag(To->getLocation(), |
| 2910 | diag::err_odr_objc_superclass_inconsistent) |
| 2911 | << To->getDeclName(); |
| 2912 | if (ToSuper) |
| 2913 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 2914 | << To->getSuperClass()->getDeclName(); |
| 2915 | else |
| 2916 | Importer.ToDiag(To->getLocation(), |
| 2917 | diag::note_odr_objc_missing_superclass); |
| 2918 | if (From->getSuperClass()) |
| 2919 | Importer.FromDiag(From->getSuperClassLoc(), |
| 2920 | diag::note_odr_objc_superclass) |
| 2921 | << From->getSuperClass()->getDeclName(); |
| 2922 | else |
| 2923 | Importer.FromDiag(From->getLocation(), |
| 2924 | diag::note_odr_objc_missing_superclass); |
| 2925 | } |
| 2926 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2927 | if (shouldForceImportDeclContext(Kind)) |
| 2928 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2929 | return false; |
| 2930 | } |
| 2931 | |
| 2932 | // Start the definition. |
| 2933 | To->startDefinition(); |
| 2934 | |
| 2935 | // If this class has a superclass, import it. |
| 2936 | if (From->getSuperClass()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 2937 | TypeSourceInfo *SuperTInfo = Importer.Import(From->getSuperClassTInfo()); |
| 2938 | if (!SuperTInfo) |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2939 | return true; |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 2940 | |
| 2941 | To->setSuperClass(SuperTInfo); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2942 | } |
| 2943 | |
| 2944 | // Import protocols |
| 2945 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 2946 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| 2947 | ObjCInterfaceDecl::protocol_loc_iterator |
| 2948 | FromProtoLoc = From->protocol_loc_begin(); |
| 2949 | |
| 2950 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 2951 | FromProtoEnd = From->protocol_end(); |
| 2952 | FromProto != FromProtoEnd; |
| 2953 | ++FromProto, ++FromProtoLoc) { |
| 2954 | ObjCProtocolDecl *ToProto |
| 2955 | = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
| 2956 | if (!ToProto) |
| 2957 | return true; |
| 2958 | Protocols.push_back(ToProto); |
| 2959 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 2960 | } |
| 2961 | |
| 2962 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 2963 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 2964 | ProtocolLocs.data(), Importer.getToContext()); |
| 2965 | |
| 2966 | // Import categories. When the categories themselves are imported, they'll |
| 2967 | // hook themselves into this interface. |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 2968 | for (auto *Cat : From->known_categories()) |
| 2969 | Importer.Import(Cat); |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 2970 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2971 | // If we have an @implementation, import it as well. |
| 2972 | if (From->getImplementation()) { |
| 2973 | ObjCImplementationDecl *Impl = cast_or_null<ObjCImplementationDecl>( |
| 2974 | Importer.Import(From->getImplementation())); |
| 2975 | if (!Impl) |
| 2976 | return true; |
| 2977 | |
| 2978 | To->setImplementation(Impl); |
| 2979 | } |
| 2980 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2981 | if (shouldForceImportDeclContext(Kind)) { |
| 2982 | // Import all of the members of this class. |
| 2983 | ImportDeclContext(From, /*ForceImport=*/true); |
| 2984 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2985 | return false; |
| 2986 | } |
| 2987 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 2988 | ObjCTypeParamList * |
| 2989 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 2990 | if (!list) |
| 2991 | return nullptr; |
| 2992 | |
| 2993 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
| 2994 | for (auto fromTypeParam : *list) { |
| 2995 | auto toTypeParam = cast_or_null<ObjCTypeParamDecl>( |
| 2996 | Importer.Import(fromTypeParam)); |
| 2997 | if (!toTypeParam) |
| 2998 | return nullptr; |
| 2999 | |
| 3000 | toTypeParams.push_back(toTypeParam); |
| 3001 | } |
| 3002 | |
| 3003 | return ObjCTypeParamList::create(Importer.getToContext(), |
| 3004 | Importer.Import(list->getLAngleLoc()), |
| 3005 | toTypeParams, |
| 3006 | Importer.Import(list->getRAngleLoc())); |
| 3007 | } |
| 3008 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3009 | Decl *ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3010 | // If this class has a definition in the translation unit we're coming from, |
| 3011 | // but this particular declaration is not that definition, import the |
| 3012 | // definition and map to that. |
| 3013 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 3014 | if (Definition && Definition != D) { |
| 3015 | Decl *ImportedDef = Importer.Import(Definition); |
| 3016 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3017 | return nullptr; |
| 3018 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3019 | return Importer.Imported(D, ImportedDef); |
| 3020 | } |
| 3021 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3022 | // Import the major distinguishing characteristics of an @interface. |
| 3023 | DeclContext *DC, *LexicalDC; |
| 3024 | DeclarationName Name; |
| 3025 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3026 | NamedDecl *ToD; |
| 3027 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3028 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3029 | if (ToD) |
| 3030 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3031 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3032 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3033 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3034 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3035 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3036 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 3037 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3038 | continue; |
| 3039 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3040 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecls[I]))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3041 | break; |
| 3042 | } |
| 3043 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3044 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3045 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3046 | if (!ToIface) { |
| 3047 | ToIface = ObjCInterfaceDecl::Create(Importer.getToContext(), DC, |
| 3048 | Importer.Import(D->getAtStartLoc()), |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3049 | Name.getAsIdentifierInfo(), |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3050 | /*TypeParamList=*/nullptr, |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3051 | /*PrevDecl=*/nullptr, Loc, |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3052 | D->isImplicitInterfaceDecl()); |
| 3053 | ToIface->setLexicalDeclContext(LexicalDC); |
| 3054 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3055 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3056 | Importer.Imported(D, ToIface); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3057 | // Import the type parameter list after calling Imported, to avoid |
| 3058 | // loops when bringing in their DeclContext. |
| 3059 | ToIface->setTypeParamList(ImportObjCTypeParamList( |
| 3060 | D->getTypeParamListAsWritten())); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3061 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3062 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToIface)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3063 | return nullptr; |
| 3064 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3065 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3066 | } |
| 3067 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3068 | Decl *ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 3069 | ObjCCategoryDecl *Category = cast_or_null<ObjCCategoryDecl>( |
| 3070 | Importer.Import(D->getCategoryDecl())); |
| 3071 | if (!Category) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3072 | return nullptr; |
| 3073 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3074 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 3075 | if (!ToImpl) { |
| 3076 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3077 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3078 | return nullptr; |
| 3079 | |
Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 3080 | SourceLocation CategoryNameLoc = Importer.Import(D->getCategoryNameLoc()); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3081 | ToImpl = ObjCCategoryImplDecl::Create(Importer.getToContext(), DC, |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3082 | Importer.Import(D->getIdentifier()), |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3083 | Category->getClassInterface(), |
| 3084 | Importer.Import(D->getLocation()), |
Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 3085 | Importer.Import(D->getAtStartLoc()), |
| 3086 | CategoryNameLoc); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3087 | |
| 3088 | DeclContext *LexicalDC = DC; |
| 3089 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3090 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3091 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3092 | return nullptr; |
| 3093 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3094 | ToImpl->setLexicalDeclContext(LexicalDC); |
| 3095 | } |
| 3096 | |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3097 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3098 | Category->setImplementation(ToImpl); |
| 3099 | } |
| 3100 | |
| 3101 | Importer.Imported(D, ToImpl); |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 3102 | ImportDeclContext(D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3103 | return ToImpl; |
| 3104 | } |
| 3105 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3106 | Decl *ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 3107 | // Find the corresponding interface. |
| 3108 | ObjCInterfaceDecl *Iface = cast_or_null<ObjCInterfaceDecl>( |
| 3109 | Importer.Import(D->getClassInterface())); |
| 3110 | if (!Iface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3111 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3112 | |
| 3113 | // Import the superclass, if any. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3114 | ObjCInterfaceDecl *Super = nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3115 | if (D->getSuperClass()) { |
| 3116 | Super = cast_or_null<ObjCInterfaceDecl>( |
| 3117 | Importer.Import(D->getSuperClass())); |
| 3118 | if (!Super) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3119 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3120 | } |
| 3121 | |
| 3122 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 3123 | if (!Impl) { |
| 3124 | // We haven't imported an implementation yet. Create a new @implementation |
| 3125 | // now. |
| 3126 | Impl = ObjCImplementationDecl::Create(Importer.getToContext(), |
| 3127 | Importer.ImportContext(D->getDeclContext()), |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3128 | Iface, Super, |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3129 | Importer.Import(D->getLocation()), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3130 | Importer.Import(D->getAtStartLoc()), |
Argyrios Kyrtzidis | 5d2ce84 | 2013-05-03 22:31:26 +0000 | [diff] [blame] | 3131 | Importer.Import(D->getSuperClassLoc()), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3132 | Importer.Import(D->getIvarLBraceLoc()), |
| 3133 | Importer.Import(D->getIvarRBraceLoc())); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3134 | |
| 3135 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3136 | DeclContext *LexicalDC |
| 3137 | = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3138 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3139 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3140 | Impl->setLexicalDeclContext(LexicalDC); |
| 3141 | } |
| 3142 | |
| 3143 | // Associate the implementation with the class it implements. |
| 3144 | Iface->setImplementation(Impl); |
| 3145 | Importer.Imported(D, Iface->getImplementation()); |
| 3146 | } else { |
| 3147 | Importer.Imported(D, Iface->getImplementation()); |
| 3148 | |
| 3149 | // Verify that the existing @implementation has the same superclass. |
| 3150 | if ((Super && !Impl->getSuperClass()) || |
| 3151 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 3152 | (Super && Impl->getSuperClass() && |
| 3153 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 3154 | Impl->getSuperClass()))) { |
| 3155 | Importer.ToDiag(Impl->getLocation(), |
| 3156 | diag::err_odr_objc_superclass_inconsistent) |
| 3157 | << Iface->getDeclName(); |
| 3158 | // FIXME: It would be nice to have the location of the superclass |
| 3159 | // below. |
| 3160 | if (Impl->getSuperClass()) |
| 3161 | Importer.ToDiag(Impl->getLocation(), |
| 3162 | diag::note_odr_objc_superclass) |
| 3163 | << Impl->getSuperClass()->getDeclName(); |
| 3164 | else |
| 3165 | Importer.ToDiag(Impl->getLocation(), |
| 3166 | diag::note_odr_objc_missing_superclass); |
| 3167 | if (D->getSuperClass()) |
| 3168 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3169 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 3170 | << D->getSuperClass()->getDeclName(); |
| 3171 | else |
| 3172 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3173 | diag::note_odr_objc_missing_superclass); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3174 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3175 | } |
| 3176 | } |
| 3177 | |
| 3178 | // Import all of the members of this @implementation. |
| 3179 | ImportDeclContext(D); |
| 3180 | |
| 3181 | return Impl; |
| 3182 | } |
| 3183 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3184 | Decl *ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| 3185 | // Import the major distinguishing characteristics of an @property. |
| 3186 | DeclContext *DC, *LexicalDC; |
| 3187 | DeclarationName Name; |
| 3188 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3189 | NamedDecl *ToD; |
| 3190 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3191 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3192 | if (ToD) |
| 3193 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3194 | |
| 3195 | // Check whether we have already imported this property. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3196 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3197 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3198 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3199 | if (ObjCPropertyDecl *FoundProp |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3200 | = dyn_cast<ObjCPropertyDecl>(FoundDecls[I])) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3201 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3202 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3203 | FoundProp->getType())) { |
| 3204 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) |
| 3205 | << Name << D->getType() << FoundProp->getType(); |
| 3206 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 3207 | << FoundProp->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3208 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3209 | } |
| 3210 | |
| 3211 | // FIXME: Check property attributes, getters, setters, etc.? |
| 3212 | |
| 3213 | // Consider these properties to be equivalent. |
| 3214 | Importer.Imported(D, FoundProp); |
| 3215 | return FoundProp; |
| 3216 | } |
| 3217 | } |
| 3218 | |
| 3219 | // Import the type. |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 3220 | TypeSourceInfo *TSI = Importer.Import(D->getTypeSourceInfo()); |
| 3221 | if (!TSI) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3222 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3223 | |
| 3224 | // Create the new property. |
| 3225 | ObjCPropertyDecl *ToProperty |
| 3226 | = ObjCPropertyDecl::Create(Importer.getToContext(), DC, Loc, |
| 3227 | Name.getAsIdentifierInfo(), |
| 3228 | Importer.Import(D->getAtLoc()), |
Fariborz Jahanian | 86c2f5c | 2012-02-29 22:18:55 +0000 | [diff] [blame] | 3229 | Importer.Import(D->getLParenLoc()), |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 3230 | Importer.Import(D->getType()), |
| 3231 | TSI, |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3232 | D->getPropertyImplementation()); |
| 3233 | Importer.Imported(D, ToProperty); |
| 3234 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3235 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3236 | |
| 3237 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 3238 | ToProperty->setPropertyAttributesAsWritten( |
| 3239 | D->getPropertyAttributesAsWritten()); |
Argyrios Kyrtzidis | 194b28e | 2017-03-16 18:25:40 +0000 | [diff] [blame] | 3240 | ToProperty->setGetterName(Importer.Import(D->getGetterName()), |
| 3241 | Importer.Import(D->getGetterNameLoc())); |
| 3242 | ToProperty->setSetterName(Importer.Import(D->getSetterName()), |
| 3243 | Importer.Import(D->getSetterNameLoc())); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3244 | ToProperty->setGetterMethodDecl( |
| 3245 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getGetterMethodDecl()))); |
| 3246 | ToProperty->setSetterMethodDecl( |
| 3247 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getSetterMethodDecl()))); |
| 3248 | ToProperty->setPropertyIvarDecl( |
| 3249 | cast_or_null<ObjCIvarDecl>(Importer.Import(D->getPropertyIvarDecl()))); |
| 3250 | return ToProperty; |
| 3251 | } |
| 3252 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3253 | Decl *ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 3254 | ObjCPropertyDecl *Property = cast_or_null<ObjCPropertyDecl>( |
| 3255 | Importer.Import(D->getPropertyDecl())); |
| 3256 | if (!Property) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3257 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3258 | |
| 3259 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3260 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3261 | return nullptr; |
| 3262 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3263 | // Import the lexical declaration context. |
| 3264 | DeclContext *LexicalDC = DC; |
| 3265 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3266 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3267 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3268 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3269 | } |
| 3270 | |
| 3271 | ObjCImplDecl *InImpl = dyn_cast<ObjCImplDecl>(LexicalDC); |
| 3272 | if (!InImpl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3273 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3274 | |
| 3275 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3276 | ObjCIvarDecl *Ivar = nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3277 | if (D->getPropertyIvarDecl()) { |
| 3278 | Ivar = cast_or_null<ObjCIvarDecl>( |
| 3279 | Importer.Import(D->getPropertyIvarDecl())); |
| 3280 | if (!Ivar) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3281 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 3285 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 3286 | Property->getQueryKind()); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3287 | if (!ToImpl) { |
| 3288 | ToImpl = ObjCPropertyImplDecl::Create(Importer.getToContext(), DC, |
| 3289 | Importer.Import(D->getLocStart()), |
| 3290 | Importer.Import(D->getLocation()), |
| 3291 | Property, |
| 3292 | D->getPropertyImplementation(), |
| 3293 | Ivar, |
| 3294 | Importer.Import(D->getPropertyIvarDeclLoc())); |
| 3295 | ToImpl->setLexicalDeclContext(LexicalDC); |
| 3296 | Importer.Imported(D, ToImpl); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3297 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3298 | } else { |
| 3299 | // Check that we have the same kind of property implementation (@synthesize |
| 3300 | // vs. @dynamic). |
| 3301 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
| 3302 | Importer.ToDiag(ToImpl->getLocation(), |
| 3303 | diag::err_odr_objc_property_impl_kind_inconsistent) |
| 3304 | << Property->getDeclName() |
| 3305 | << (ToImpl->getPropertyImplementation() |
| 3306 | == ObjCPropertyImplDecl::Dynamic); |
| 3307 | Importer.FromDiag(D->getLocation(), |
| 3308 | diag::note_odr_objc_property_impl_kind) |
| 3309 | << D->getPropertyDecl()->getDeclName() |
| 3310 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3311 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3312 | } |
| 3313 | |
| 3314 | // For @synthesize, check that we have the same |
| 3315 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 3316 | Ivar != ToImpl->getPropertyIvarDecl()) { |
| 3317 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
| 3318 | diag::err_odr_objc_synthesize_ivar_inconsistent) |
| 3319 | << Property->getDeclName() |
| 3320 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 3321 | << Ivar->getDeclName(); |
| 3322 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
| 3323 | diag::note_odr_objc_synthesize_ivar_here) |
| 3324 | << D->getPropertyIvarDecl()->getDeclName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3325 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3326 | } |
| 3327 | |
| 3328 | // Merge the existing implementation with the new implementation. |
| 3329 | Importer.Imported(D, ToImpl); |
| 3330 | } |
| 3331 | |
| 3332 | return ToImpl; |
| 3333 | } |
| 3334 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3335 | Decl *ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| 3336 | // For template arguments, we adopt the translation unit as our declaration |
| 3337 | // context. This context will be fixed when the actual template declaration |
| 3338 | // is created. |
| 3339 | |
| 3340 | // FIXME: Import default argument. |
| 3341 | return TemplateTypeParmDecl::Create(Importer.getToContext(), |
| 3342 | Importer.getToContext().getTranslationUnitDecl(), |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 3343 | Importer.Import(D->getLocStart()), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3344 | Importer.Import(D->getLocation()), |
| 3345 | D->getDepth(), |
| 3346 | D->getIndex(), |
| 3347 | Importer.Import(D->getIdentifier()), |
| 3348 | D->wasDeclaredWithTypename(), |
| 3349 | D->isParameterPack()); |
| 3350 | } |
| 3351 | |
| 3352 | Decl * |
| 3353 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| 3354 | // Import the name of this declaration. |
| 3355 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 3356 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3357 | return nullptr; |
| 3358 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3359 | // Import the location of this declaration. |
| 3360 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 3361 | |
| 3362 | // Import the type of this declaration. |
| 3363 | QualType T = Importer.Import(D->getType()); |
| 3364 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3365 | return nullptr; |
| 3366 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3367 | // Import type-source information. |
| 3368 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3369 | if (D->getTypeSourceInfo() && !TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3370 | return nullptr; |
| 3371 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3372 | // FIXME: Import default argument. |
| 3373 | |
| 3374 | return NonTypeTemplateParmDecl::Create(Importer.getToContext(), |
| 3375 | Importer.getToContext().getTranslationUnitDecl(), |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 3376 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3377 | Loc, D->getDepth(), D->getPosition(), |
| 3378 | Name.getAsIdentifierInfo(), |
Douglas Gregor | da3cc0d | 2010-12-23 23:51:58 +0000 | [diff] [blame] | 3379 | T, D->isParameterPack(), TInfo); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3380 | } |
| 3381 | |
| 3382 | Decl * |
| 3383 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 3384 | // Import the name of this declaration. |
| 3385 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 3386 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3387 | return nullptr; |
| 3388 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3389 | // Import the location of this declaration. |
| 3390 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 3391 | |
| 3392 | // Import template parameters. |
| 3393 | TemplateParameterList *TemplateParams |
| 3394 | = ImportTemplateParameterList(D->getTemplateParameters()); |
| 3395 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3396 | return nullptr; |
| 3397 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3398 | // FIXME: Import default argument. |
| 3399 | |
| 3400 | return TemplateTemplateParmDecl::Create(Importer.getToContext(), |
| 3401 | Importer.getToContext().getTranslationUnitDecl(), |
| 3402 | Loc, D->getDepth(), D->getPosition(), |
Douglas Gregor | f550077 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 3403 | D->isParameterPack(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3404 | Name.getAsIdentifierInfo(), |
| 3405 | TemplateParams); |
| 3406 | } |
| 3407 | |
| 3408 | Decl *ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 3409 | // If this record has a definition in the translation unit we're coming from, |
| 3410 | // but this particular declaration is not that definition, import the |
| 3411 | // definition and map to that. |
| 3412 | CXXRecordDecl *Definition |
| 3413 | = cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition()); |
| 3414 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 3415 | Decl *ImportedDef |
| 3416 | = Importer.Import(Definition->getDescribedClassTemplate()); |
| 3417 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3418 | return nullptr; |
| 3419 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3420 | return Importer.Imported(D, ImportedDef); |
| 3421 | } |
| 3422 | |
| 3423 | // Import the major distinguishing characteristics of this class template. |
| 3424 | DeclContext *DC, *LexicalDC; |
| 3425 | DeclarationName Name; |
| 3426 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3427 | NamedDecl *ToD; |
| 3428 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3429 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3430 | if (ToD) |
| 3431 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3432 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3433 | // We may already have a template of the same name; try to find and match it. |
| 3434 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3435 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3436 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3437 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3438 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 3439 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3440 | continue; |
| 3441 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3442 | Decl *Found = FoundDecls[I]; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3443 | if (ClassTemplateDecl *FoundTemplate |
| 3444 | = dyn_cast<ClassTemplateDecl>(Found)) { |
| 3445 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 3446 | // The class templates structurally match; call it the same template. |
| 3447 | // FIXME: We may be filling in a forward declaration here. Handle |
| 3448 | // this case! |
| 3449 | Importer.Imported(D->getTemplatedDecl(), |
| 3450 | FoundTemplate->getTemplatedDecl()); |
| 3451 | return Importer.Imported(D, FoundTemplate); |
| 3452 | } |
| 3453 | } |
| 3454 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3455 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3456 | } |
| 3457 | |
| 3458 | if (!ConflictingDecls.empty()) { |
| 3459 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 3460 | ConflictingDecls.data(), |
| 3461 | ConflictingDecls.size()); |
| 3462 | } |
| 3463 | |
| 3464 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3465 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3466 | } |
| 3467 | |
| 3468 | CXXRecordDecl *DTemplated = D->getTemplatedDecl(); |
| 3469 | |
| 3470 | // Create the declaration that is being templated. |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 3471 | // Create the declaration that is being templated. |
| 3472 | CXXRecordDecl *D2Templated = cast_or_null<CXXRecordDecl>( |
| 3473 | Importer.Import(DTemplated)); |
| 3474 | if (!D2Templated) |
| 3475 | return nullptr; |
| 3476 | |
| 3477 | // Resolve possible cyclic import. |
| 3478 | if (Decl *AlreadyImported = Importer.GetAlreadyImportedOrNull(D)) |
| 3479 | return AlreadyImported; |
| 3480 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3481 | // Create the class template declaration itself. |
| 3482 | TemplateParameterList *TemplateParams |
| 3483 | = ImportTemplateParameterList(D->getTemplateParameters()); |
| 3484 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3485 | return nullptr; |
| 3486 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3487 | ClassTemplateDecl *D2 = ClassTemplateDecl::Create(Importer.getToContext(), DC, |
| 3488 | Loc, Name, TemplateParams, |
Vassil Vassilev | 352e441 | 2017-01-12 09:16:26 +0000 | [diff] [blame] | 3489 | D2Templated); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3490 | D2Templated->setDescribedClassTemplate(D2); |
| 3491 | |
| 3492 | D2->setAccess(D->getAccess()); |
| 3493 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3494 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3495 | |
| 3496 | // Note the relationship between the class templates. |
| 3497 | Importer.Imported(D, D2); |
| 3498 | Importer.Imported(DTemplated, D2Templated); |
| 3499 | |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 3500 | if (DTemplated->isCompleteDefinition() && |
| 3501 | !D2Templated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3502 | // FIXME: Import definition! |
| 3503 | } |
| 3504 | |
| 3505 | return D2; |
| 3506 | } |
| 3507 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3508 | Decl *ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
| 3509 | ClassTemplateSpecializationDecl *D) { |
| 3510 | // If this record has a definition in the translation unit we're coming from, |
| 3511 | // but this particular declaration is not that definition, import the |
| 3512 | // definition and map to that. |
| 3513 | TagDecl *Definition = D->getDefinition(); |
| 3514 | if (Definition && Definition != D) { |
| 3515 | Decl *ImportedDef = Importer.Import(Definition); |
| 3516 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3517 | return nullptr; |
| 3518 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3519 | return Importer.Imported(D, ImportedDef); |
| 3520 | } |
| 3521 | |
| 3522 | ClassTemplateDecl *ClassTemplate |
| 3523 | = cast_or_null<ClassTemplateDecl>(Importer.Import( |
| 3524 | D->getSpecializedTemplate())); |
| 3525 | if (!ClassTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3526 | return nullptr; |
| 3527 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3528 | // Import the context of this declaration. |
| 3529 | DeclContext *DC = ClassTemplate->getDeclContext(); |
| 3530 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3531 | return nullptr; |
| 3532 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3533 | DeclContext *LexicalDC = DC; |
| 3534 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3535 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3536 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3537 | return nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3538 | } |
| 3539 | |
| 3540 | // Import the location of this declaration. |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 3541 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 3542 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3543 | |
| 3544 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3545 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3546 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 3547 | D->getTemplateArgs().size(), |
| 3548 | TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3549 | return nullptr; |
| 3550 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3551 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3552 | void *InsertPos = nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3553 | ClassTemplateSpecializationDecl *D2 |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 3554 | = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3555 | if (D2) { |
| 3556 | // We already have a class template specialization with these template |
| 3557 | // arguments. |
| 3558 | |
| 3559 | // FIXME: Check for specialization vs. instantiation errors. |
| 3560 | |
| 3561 | if (RecordDecl *FoundDef = D2->getDefinition()) { |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 3562 | if (!D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3563 | // The record types structurally match, or the "from" translation |
| 3564 | // unit only had a forward declaration anyway; call it the same |
| 3565 | // function. |
| 3566 | return Importer.Imported(D, FoundDef); |
| 3567 | } |
| 3568 | } |
| 3569 | } else { |
| 3570 | // Create a new specialization. |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3571 | if (ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 3572 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { |
| 3573 | |
| 3574 | // Import TemplateArgumentListInfo |
| 3575 | TemplateArgumentListInfo ToTAInfo; |
| 3576 | auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 3577 | for (unsigned I = 0, E = ASTTemplateArgs.NumTemplateArgs; I < E; ++I) { |
| 3578 | bool Error = false; |
| 3579 | auto ToLoc = ImportTemplateArgumentLoc(ASTTemplateArgs[I], Error); |
| 3580 | if (Error) |
| 3581 | return nullptr; |
| 3582 | ToTAInfo.addArgument(ToLoc); |
| 3583 | } |
| 3584 | |
| 3585 | QualType CanonInjType = Importer.Import( |
| 3586 | PartialSpec->getInjectedSpecializationType()); |
| 3587 | if (CanonInjType.isNull()) |
| 3588 | return nullptr; |
| 3589 | CanonInjType = CanonInjType.getCanonicalType(); |
| 3590 | |
| 3591 | TemplateParameterList *ToTPList = ImportTemplateParameterList( |
| 3592 | PartialSpec->getTemplateParameters()); |
| 3593 | if (!ToTPList && PartialSpec->getTemplateParameters()) |
| 3594 | return nullptr; |
| 3595 | |
| 3596 | D2 = ClassTemplatePartialSpecializationDecl::Create( |
| 3597 | Importer.getToContext(), D->getTagKind(), DC, StartLoc, IdLoc, |
| 3598 | ToTPList, ClassTemplate, |
| 3599 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
| 3600 | ToTAInfo, CanonInjType, nullptr); |
| 3601 | |
| 3602 | } else { |
| 3603 | D2 = ClassTemplateSpecializationDecl::Create(Importer.getToContext(), |
| 3604 | D->getTagKind(), DC, |
| 3605 | StartLoc, IdLoc, |
| 3606 | ClassTemplate, |
| 3607 | TemplateArgs, |
| 3608 | /*PrevDecl=*/nullptr); |
| 3609 | } |
| 3610 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3611 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 3612 | |
| 3613 | // Add this specialization to the class template. |
| 3614 | ClassTemplate->AddSpecialization(D2, InsertPos); |
| 3615 | |
| 3616 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3617 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3618 | |
| 3619 | Importer.Imported(D, D2); |
| 3620 | |
| 3621 | if (auto *TSI = D->getTypeAsWritten()) { |
| 3622 | TypeSourceInfo *TInfo = Importer.Import(TSI); |
| 3623 | if (!TInfo) |
| 3624 | return nullptr; |
| 3625 | D2->setTypeAsWritten(TInfo); |
| 3626 | D2->setTemplateKeywordLoc(Importer.Import(D->getTemplateKeywordLoc())); |
| 3627 | D2->setExternLoc(Importer.Import(D->getExternLoc())); |
| 3628 | } |
| 3629 | |
| 3630 | SourceLocation POI = Importer.Import(D->getPointOfInstantiation()); |
| 3631 | if (POI.isValid()) |
| 3632 | D2->setPointOfInstantiation(POI); |
| 3633 | else if (D->getPointOfInstantiation().isValid()) |
| 3634 | return nullptr; |
| 3635 | |
| 3636 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 3637 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3638 | // Add the specialization to this context. |
| 3639 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3640 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3641 | } |
| 3642 | Importer.Imported(D, D2); |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 3643 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3644 | return nullptr; |
| 3645 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3646 | return D2; |
| 3647 | } |
| 3648 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3649 | Decl *ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| 3650 | // If this variable has a definition in the translation unit we're coming |
| 3651 | // from, |
| 3652 | // but this particular declaration is not that definition, import the |
| 3653 | // definition and map to that. |
| 3654 | VarDecl *Definition = |
| 3655 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 3656 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 3657 | Decl *ImportedDef = Importer.Import(Definition->getDescribedVarTemplate()); |
| 3658 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3659 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3660 | |
| 3661 | return Importer.Imported(D, ImportedDef); |
| 3662 | } |
| 3663 | |
| 3664 | // Import the major distinguishing characteristics of this variable template. |
| 3665 | DeclContext *DC, *LexicalDC; |
| 3666 | DeclarationName Name; |
| 3667 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3668 | NamedDecl *ToD; |
| 3669 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3670 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3671 | if (ToD) |
| 3672 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3673 | |
| 3674 | // We may already have a template of the same name; try to find and match it. |
| 3675 | assert(!DC->isFunctionOrMethod() && |
| 3676 | "Variable templates cannot be declared at function scope"); |
| 3677 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 3678 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3679 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3680 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 3681 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
| 3682 | continue; |
| 3683 | |
| 3684 | Decl *Found = FoundDecls[I]; |
| 3685 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
| 3686 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 3687 | // The variable templates structurally match; call it the same template. |
| 3688 | Importer.Imported(D->getTemplatedDecl(), |
| 3689 | FoundTemplate->getTemplatedDecl()); |
| 3690 | return Importer.Imported(D, FoundTemplate); |
| 3691 | } |
| 3692 | } |
| 3693 | |
| 3694 | ConflictingDecls.push_back(FoundDecls[I]); |
| 3695 | } |
| 3696 | |
| 3697 | if (!ConflictingDecls.empty()) { |
| 3698 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 3699 | ConflictingDecls.data(), |
| 3700 | ConflictingDecls.size()); |
| 3701 | } |
| 3702 | |
| 3703 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3704 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3705 | |
| 3706 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 3707 | |
| 3708 | // Import the type. |
| 3709 | QualType T = Importer.Import(DTemplated->getType()); |
| 3710 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3711 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3712 | |
| 3713 | // Create the declaration that is being templated. |
| 3714 | SourceLocation StartLoc = Importer.Import(DTemplated->getLocStart()); |
| 3715 | SourceLocation IdLoc = Importer.Import(DTemplated->getLocation()); |
| 3716 | TypeSourceInfo *TInfo = Importer.Import(DTemplated->getTypeSourceInfo()); |
| 3717 | VarDecl *D2Templated = VarDecl::Create(Importer.getToContext(), DC, StartLoc, |
| 3718 | IdLoc, Name.getAsIdentifierInfo(), T, |
| 3719 | TInfo, DTemplated->getStorageClass()); |
| 3720 | D2Templated->setAccess(DTemplated->getAccess()); |
| 3721 | D2Templated->setQualifierInfo(Importer.Import(DTemplated->getQualifierLoc())); |
| 3722 | D2Templated->setLexicalDeclContext(LexicalDC); |
| 3723 | |
| 3724 | // Importer.Imported(DTemplated, D2Templated); |
| 3725 | // LexicalDC->addDeclInternal(D2Templated); |
| 3726 | |
| 3727 | // Merge the initializer. |
| 3728 | if (ImportDefinition(DTemplated, D2Templated)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3729 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3730 | |
| 3731 | // Create the variable template declaration itself. |
| 3732 | TemplateParameterList *TemplateParams = |
| 3733 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 3734 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3735 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3736 | |
| 3737 | VarTemplateDecl *D2 = VarTemplateDecl::Create( |
Richard Smith | beef345 | 2014-01-16 23:39:20 +0000 | [diff] [blame] | 3738 | Importer.getToContext(), DC, Loc, Name, TemplateParams, D2Templated); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3739 | D2Templated->setDescribedVarTemplate(D2); |
| 3740 | |
| 3741 | D2->setAccess(D->getAccess()); |
| 3742 | D2->setLexicalDeclContext(LexicalDC); |
| 3743 | LexicalDC->addDeclInternal(D2); |
| 3744 | |
| 3745 | // Note the relationship between the variable templates. |
| 3746 | Importer.Imported(D, D2); |
| 3747 | Importer.Imported(DTemplated, D2Templated); |
| 3748 | |
| 3749 | if (DTemplated->isThisDeclarationADefinition() && |
| 3750 | !D2Templated->isThisDeclarationADefinition()) { |
| 3751 | // FIXME: Import definition! |
| 3752 | } |
| 3753 | |
| 3754 | return D2; |
| 3755 | } |
| 3756 | |
| 3757 | Decl *ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
| 3758 | VarTemplateSpecializationDecl *D) { |
| 3759 | // If this record has a definition in the translation unit we're coming from, |
| 3760 | // but this particular declaration is not that definition, import the |
| 3761 | // definition and map to that. |
| 3762 | VarDecl *Definition = D->getDefinition(); |
| 3763 | if (Definition && Definition != D) { |
| 3764 | Decl *ImportedDef = Importer.Import(Definition); |
| 3765 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3766 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3767 | |
| 3768 | return Importer.Imported(D, ImportedDef); |
| 3769 | } |
| 3770 | |
| 3771 | VarTemplateDecl *VarTemplate = cast_or_null<VarTemplateDecl>( |
| 3772 | Importer.Import(D->getSpecializedTemplate())); |
| 3773 | if (!VarTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3774 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3775 | |
| 3776 | // Import the context of this declaration. |
| 3777 | DeclContext *DC = VarTemplate->getDeclContext(); |
| 3778 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3779 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3780 | |
| 3781 | DeclContext *LexicalDC = DC; |
| 3782 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3783 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3784 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3785 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3786 | } |
| 3787 | |
| 3788 | // Import the location of this declaration. |
| 3789 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 3790 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
| 3791 | |
| 3792 | // Import template arguments. |
| 3793 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| 3794 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 3795 | D->getTemplateArgs().size(), TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3796 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3797 | |
| 3798 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3799 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3800 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 3801 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3802 | if (D2) { |
| 3803 | // We already have a variable template specialization with these template |
| 3804 | // arguments. |
| 3805 | |
| 3806 | // FIXME: Check for specialization vs. instantiation errors. |
| 3807 | |
| 3808 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 3809 | if (!D->isThisDeclarationADefinition() || |
| 3810 | IsStructuralMatch(D, FoundDef)) { |
| 3811 | // The record types structurally match, or the "from" translation |
| 3812 | // unit only had a forward declaration anyway; call it the same |
| 3813 | // variable. |
| 3814 | return Importer.Imported(D, FoundDef); |
| 3815 | } |
| 3816 | } |
| 3817 | } else { |
| 3818 | |
| 3819 | // Import the type. |
| 3820 | QualType T = Importer.Import(D->getType()); |
| 3821 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3822 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3823 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3824 | |
| 3825 | // Create a new specialization. |
| 3826 | D2 = VarTemplateSpecializationDecl::Create( |
| 3827 | Importer.getToContext(), DC, StartLoc, IdLoc, VarTemplate, T, TInfo, |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 3828 | D->getStorageClass(), TemplateArgs); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3829 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 3830 | D2->setTemplateArgsInfo(D->getTemplateArgsInfo()); |
| 3831 | |
| 3832 | // Add this specialization to the class template. |
| 3833 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 3834 | |
| 3835 | // Import the qualifier, if any. |
| 3836 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
| 3837 | |
| 3838 | // Add the specialization to this context. |
| 3839 | D2->setLexicalDeclContext(LexicalDC); |
| 3840 | LexicalDC->addDeclInternal(D2); |
| 3841 | } |
| 3842 | Importer.Imported(D, D2); |
| 3843 | |
| 3844 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3845 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3846 | |
| 3847 | return D2; |
| 3848 | } |
| 3849 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 3850 | //---------------------------------------------------------------------------- |
| 3851 | // Import Statements |
| 3852 | //---------------------------------------------------------------------------- |
| 3853 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3854 | DeclGroupRef ASTNodeImporter::ImportDeclGroup(DeclGroupRef DG) { |
| 3855 | if (DG.isNull()) |
| 3856 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 3857 | size_t NumDecls = DG.end() - DG.begin(); |
| 3858 | SmallVector<Decl *, 1> ToDecls(NumDecls); |
| 3859 | auto &_Importer = this->Importer; |
| 3860 | std::transform(DG.begin(), DG.end(), ToDecls.begin(), |
| 3861 | [&_Importer](Decl *D) -> Decl * { |
| 3862 | return _Importer.Import(D); |
| 3863 | }); |
| 3864 | return DeclGroupRef::Create(Importer.getToContext(), |
| 3865 | ToDecls.begin(), |
| 3866 | NumDecls); |
| 3867 | } |
| 3868 | |
| 3869 | Stmt *ASTNodeImporter::VisitStmt(Stmt *S) { |
| 3870 | Importer.FromDiag(S->getLocStart(), diag::err_unsupported_ast_node) |
| 3871 | << S->getStmtClassName(); |
| 3872 | return nullptr; |
| 3873 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 3874 | |
| 3875 | |
| 3876 | Stmt *ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
| 3877 | SmallVector<IdentifierInfo *, 4> Names; |
| 3878 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 3879 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 3880 | // ToII is nullptr when no symbolic name is given for output operand |
| 3881 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 3882 | if (!ToII && S->getOutputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 3883 | return nullptr; |
| 3884 | Names.push_back(ToII); |
| 3885 | } |
| 3886 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 3887 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 3888 | // ToII is nullptr when no symbolic name is given for input operand |
| 3889 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 3890 | if (!ToII && S->getInputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 3891 | return nullptr; |
| 3892 | Names.push_back(ToII); |
| 3893 | } |
| 3894 | |
| 3895 | SmallVector<StringLiteral *, 4> Clobbers; |
| 3896 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
| 3897 | StringLiteral *Clobber = cast_or_null<StringLiteral>( |
| 3898 | Importer.Import(S->getClobberStringLiteral(I))); |
| 3899 | if (!Clobber) |
| 3900 | return nullptr; |
| 3901 | Clobbers.push_back(Clobber); |
| 3902 | } |
| 3903 | |
| 3904 | SmallVector<StringLiteral *, 4> Constraints; |
| 3905 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 3906 | StringLiteral *Output = cast_or_null<StringLiteral>( |
| 3907 | Importer.Import(S->getOutputConstraintLiteral(I))); |
| 3908 | if (!Output) |
| 3909 | return nullptr; |
| 3910 | Constraints.push_back(Output); |
| 3911 | } |
| 3912 | |
| 3913 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 3914 | StringLiteral *Input = cast_or_null<StringLiteral>( |
| 3915 | Importer.Import(S->getInputConstraintLiteral(I))); |
| 3916 | if (!Input) |
| 3917 | return nullptr; |
| 3918 | Constraints.push_back(Input); |
| 3919 | } |
| 3920 | |
| 3921 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3922 | if (ImportContainerChecked(S->outputs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 3923 | return nullptr; |
| 3924 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3925 | if (ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 3926 | return nullptr; |
| 3927 | |
| 3928 | StringLiteral *AsmStr = cast_or_null<StringLiteral>( |
| 3929 | Importer.Import(S->getAsmString())); |
| 3930 | if (!AsmStr) |
| 3931 | return nullptr; |
| 3932 | |
| 3933 | return new (Importer.getToContext()) GCCAsmStmt( |
| 3934 | Importer.getToContext(), |
| 3935 | Importer.Import(S->getAsmLoc()), |
| 3936 | S->isSimple(), |
| 3937 | S->isVolatile(), |
| 3938 | S->getNumOutputs(), |
| 3939 | S->getNumInputs(), |
| 3940 | Names.data(), |
| 3941 | Constraints.data(), |
| 3942 | Exprs.data(), |
| 3943 | AsmStr, |
| 3944 | S->getNumClobbers(), |
| 3945 | Clobbers.data(), |
| 3946 | Importer.Import(S->getRParenLoc())); |
| 3947 | } |
| 3948 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3949 | Stmt *ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 3950 | DeclGroupRef ToDG = ImportDeclGroup(S->getDeclGroup()); |
| 3951 | for (Decl *ToD : ToDG) { |
| 3952 | if (!ToD) |
| 3953 | return nullptr; |
| 3954 | } |
| 3955 | SourceLocation ToStartLoc = Importer.Import(S->getStartLoc()); |
| 3956 | SourceLocation ToEndLoc = Importer.Import(S->getEndLoc()); |
| 3957 | return new (Importer.getToContext()) DeclStmt(ToDG, ToStartLoc, ToEndLoc); |
| 3958 | } |
| 3959 | |
| 3960 | Stmt *ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 3961 | SourceLocation ToSemiLoc = Importer.Import(S->getSemiLoc()); |
| 3962 | return new (Importer.getToContext()) NullStmt(ToSemiLoc, |
| 3963 | S->hasLeadingEmptyMacro()); |
| 3964 | } |
| 3965 | |
| 3966 | Stmt *ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 3967 | llvm::SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3968 | |
| 3969 | if (ImportContainerChecked(S->body(), ToStmts)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 3970 | return nullptr; |
| 3971 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3972 | SourceLocation ToLBraceLoc = Importer.Import(S->getLBracLoc()); |
| 3973 | SourceLocation ToRBraceLoc = Importer.Import(S->getRBracLoc()); |
| 3974 | return new (Importer.getToContext()) CompoundStmt(Importer.getToContext(), |
| 3975 | ToStmts, |
| 3976 | ToLBraceLoc, ToRBraceLoc); |
| 3977 | } |
| 3978 | |
| 3979 | Stmt *ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 3980 | Expr *ToLHS = Importer.Import(S->getLHS()); |
| 3981 | if (!ToLHS) |
| 3982 | return nullptr; |
| 3983 | Expr *ToRHS = Importer.Import(S->getRHS()); |
| 3984 | if (!ToRHS && S->getRHS()) |
| 3985 | return nullptr; |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame^] | 3986 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 3987 | if (!ToSubStmt && S->getSubStmt()) |
| 3988 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3989 | SourceLocation ToCaseLoc = Importer.Import(S->getCaseLoc()); |
| 3990 | SourceLocation ToEllipsisLoc = Importer.Import(S->getEllipsisLoc()); |
| 3991 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame^] | 3992 | CaseStmt *ToStmt = new (Importer.getToContext()) |
| 3993 | CaseStmt(ToLHS, ToRHS, ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
| 3994 | ToStmt->setSubStmt(ToSubStmt); |
| 3995 | return ToStmt; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3996 | } |
| 3997 | |
| 3998 | Stmt *ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 3999 | SourceLocation ToDefaultLoc = Importer.Import(S->getDefaultLoc()); |
| 4000 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 4001 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4002 | if (!ToSubStmt && S->getSubStmt()) |
| 4003 | return nullptr; |
| 4004 | return new (Importer.getToContext()) DefaultStmt(ToDefaultLoc, ToColonLoc, |
| 4005 | ToSubStmt); |
| 4006 | } |
| 4007 | |
| 4008 | Stmt *ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 4009 | SourceLocation ToIdentLoc = Importer.Import(S->getIdentLoc()); |
| 4010 | LabelDecl *ToLabelDecl = |
| 4011 | cast_or_null<LabelDecl>(Importer.Import(S->getDecl())); |
| 4012 | if (!ToLabelDecl && S->getDecl()) |
| 4013 | return nullptr; |
| 4014 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4015 | if (!ToSubStmt && S->getSubStmt()) |
| 4016 | return nullptr; |
| 4017 | return new (Importer.getToContext()) LabelStmt(ToIdentLoc, ToLabelDecl, |
| 4018 | ToSubStmt); |
| 4019 | } |
| 4020 | |
| 4021 | Stmt *ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 4022 | SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc()); |
| 4023 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 4024 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
| 4025 | ASTContext &_ToContext = Importer.getToContext(); |
| 4026 | std::transform(FromAttrs.begin(), FromAttrs.end(), ToAttrs.begin(), |
| 4027 | [&_ToContext](const Attr *A) -> const Attr * { |
| 4028 | return A->clone(_ToContext); |
| 4029 | }); |
| 4030 | for (const Attr *ToA : ToAttrs) { |
| 4031 | if (!ToA) |
| 4032 | return nullptr; |
| 4033 | } |
| 4034 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4035 | if (!ToSubStmt && S->getSubStmt()) |
| 4036 | return nullptr; |
| 4037 | return AttributedStmt::Create(Importer.getToContext(), ToAttrLoc, |
| 4038 | ToAttrs, ToSubStmt); |
| 4039 | } |
| 4040 | |
| 4041 | Stmt *ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 4042 | SourceLocation ToIfLoc = Importer.Import(S->getIfLoc()); |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4043 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4044 | if (!ToInit && S->getInit()) |
| 4045 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4046 | VarDecl *ToConditionVariable = nullptr; |
| 4047 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4048 | ToConditionVariable = |
| 4049 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4050 | if (!ToConditionVariable) |
| 4051 | return nullptr; |
| 4052 | } |
| 4053 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4054 | if (!ToCondition && S->getCond()) |
| 4055 | return nullptr; |
| 4056 | Stmt *ToThenStmt = Importer.Import(S->getThen()); |
| 4057 | if (!ToThenStmt && S->getThen()) |
| 4058 | return nullptr; |
| 4059 | SourceLocation ToElseLoc = Importer.Import(S->getElseLoc()); |
| 4060 | Stmt *ToElseStmt = Importer.Import(S->getElse()); |
| 4061 | if (!ToElseStmt && S->getElse()) |
| 4062 | return nullptr; |
| 4063 | return new (Importer.getToContext()) IfStmt(Importer.getToContext(), |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 4064 | ToIfLoc, S->isConstexpr(), |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4065 | ToInit, |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 4066 | ToConditionVariable, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4067 | ToCondition, ToThenStmt, |
| 4068 | ToElseLoc, ToElseStmt); |
| 4069 | } |
| 4070 | |
| 4071 | Stmt *ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4072 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4073 | if (!ToInit && S->getInit()) |
| 4074 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4075 | VarDecl *ToConditionVariable = nullptr; |
| 4076 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4077 | ToConditionVariable = |
| 4078 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4079 | if (!ToConditionVariable) |
| 4080 | return nullptr; |
| 4081 | } |
| 4082 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4083 | if (!ToCondition && S->getCond()) |
| 4084 | return nullptr; |
| 4085 | SwitchStmt *ToStmt = new (Importer.getToContext()) SwitchStmt( |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4086 | Importer.getToContext(), ToInit, |
| 4087 | ToConditionVariable, ToCondition); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4088 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4089 | if (!ToBody && S->getBody()) |
| 4090 | return nullptr; |
| 4091 | ToStmt->setBody(ToBody); |
| 4092 | ToStmt->setSwitchLoc(Importer.Import(S->getSwitchLoc())); |
| 4093 | // Now we have to re-chain the cases. |
| 4094 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 4095 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 4096 | SC = SC->getNextSwitchCase()) { |
| 4097 | SwitchCase *ToSC = dyn_cast_or_null<SwitchCase>(Importer.Import(SC)); |
| 4098 | if (!ToSC) |
| 4099 | return nullptr; |
| 4100 | if (LastChainedSwitchCase) |
| 4101 | LastChainedSwitchCase->setNextSwitchCase(ToSC); |
| 4102 | else |
| 4103 | ToStmt->setSwitchCaseList(ToSC); |
| 4104 | LastChainedSwitchCase = ToSC; |
| 4105 | } |
| 4106 | return ToStmt; |
| 4107 | } |
| 4108 | |
| 4109 | Stmt *ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 4110 | VarDecl *ToConditionVariable = nullptr; |
| 4111 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4112 | ToConditionVariable = |
| 4113 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4114 | if (!ToConditionVariable) |
| 4115 | return nullptr; |
| 4116 | } |
| 4117 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4118 | if (!ToCondition && S->getCond()) |
| 4119 | return nullptr; |
| 4120 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4121 | if (!ToBody && S->getBody()) |
| 4122 | return nullptr; |
| 4123 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 4124 | return new (Importer.getToContext()) WhileStmt(Importer.getToContext(), |
| 4125 | ToConditionVariable, |
| 4126 | ToCondition, ToBody, |
| 4127 | ToWhileLoc); |
| 4128 | } |
| 4129 | |
| 4130 | Stmt *ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 4131 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4132 | if (!ToBody && S->getBody()) |
| 4133 | return nullptr; |
| 4134 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4135 | if (!ToCondition && S->getCond()) |
| 4136 | return nullptr; |
| 4137 | SourceLocation ToDoLoc = Importer.Import(S->getDoLoc()); |
| 4138 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 4139 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4140 | return new (Importer.getToContext()) DoStmt(ToBody, ToCondition, |
| 4141 | ToDoLoc, ToWhileLoc, |
| 4142 | ToRParenLoc); |
| 4143 | } |
| 4144 | |
| 4145 | Stmt *ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 4146 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4147 | if (!ToInit && S->getInit()) |
| 4148 | return nullptr; |
| 4149 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4150 | if (!ToCondition && S->getCond()) |
| 4151 | return nullptr; |
| 4152 | VarDecl *ToConditionVariable = nullptr; |
| 4153 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4154 | ToConditionVariable = |
| 4155 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4156 | if (!ToConditionVariable) |
| 4157 | return nullptr; |
| 4158 | } |
| 4159 | Expr *ToInc = Importer.Import(S->getInc()); |
| 4160 | if (!ToInc && S->getInc()) |
| 4161 | return nullptr; |
| 4162 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4163 | if (!ToBody && S->getBody()) |
| 4164 | return nullptr; |
| 4165 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 4166 | SourceLocation ToLParenLoc = Importer.Import(S->getLParenLoc()); |
| 4167 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4168 | return new (Importer.getToContext()) ForStmt(Importer.getToContext(), |
| 4169 | ToInit, ToCondition, |
| 4170 | ToConditionVariable, |
| 4171 | ToInc, ToBody, |
| 4172 | ToForLoc, ToLParenLoc, |
| 4173 | ToRParenLoc); |
| 4174 | } |
| 4175 | |
| 4176 | Stmt *ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 4177 | LabelDecl *ToLabel = nullptr; |
| 4178 | if (LabelDecl *FromLabel = S->getLabel()) { |
| 4179 | ToLabel = dyn_cast_or_null<LabelDecl>(Importer.Import(FromLabel)); |
| 4180 | if (!ToLabel) |
| 4181 | return nullptr; |
| 4182 | } |
| 4183 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 4184 | SourceLocation ToLabelLoc = Importer.Import(S->getLabelLoc()); |
| 4185 | return new (Importer.getToContext()) GotoStmt(ToLabel, |
| 4186 | ToGotoLoc, ToLabelLoc); |
| 4187 | } |
| 4188 | |
| 4189 | Stmt *ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 4190 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 4191 | SourceLocation ToStarLoc = Importer.Import(S->getStarLoc()); |
| 4192 | Expr *ToTarget = Importer.Import(S->getTarget()); |
| 4193 | if (!ToTarget && S->getTarget()) |
| 4194 | return nullptr; |
| 4195 | return new (Importer.getToContext()) IndirectGotoStmt(ToGotoLoc, ToStarLoc, |
| 4196 | ToTarget); |
| 4197 | } |
| 4198 | |
| 4199 | Stmt *ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 4200 | SourceLocation ToContinueLoc = Importer.Import(S->getContinueLoc()); |
| 4201 | return new (Importer.getToContext()) ContinueStmt(ToContinueLoc); |
| 4202 | } |
| 4203 | |
| 4204 | Stmt *ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 4205 | SourceLocation ToBreakLoc = Importer.Import(S->getBreakLoc()); |
| 4206 | return new (Importer.getToContext()) BreakStmt(ToBreakLoc); |
| 4207 | } |
| 4208 | |
| 4209 | Stmt *ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 4210 | SourceLocation ToRetLoc = Importer.Import(S->getReturnLoc()); |
| 4211 | Expr *ToRetExpr = Importer.Import(S->getRetValue()); |
| 4212 | if (!ToRetExpr && S->getRetValue()) |
| 4213 | return nullptr; |
| 4214 | VarDecl *NRVOCandidate = const_cast<VarDecl*>(S->getNRVOCandidate()); |
| 4215 | VarDecl *ToNRVOCandidate = cast_or_null<VarDecl>(Importer.Import(NRVOCandidate)); |
| 4216 | if (!ToNRVOCandidate && NRVOCandidate) |
| 4217 | return nullptr; |
| 4218 | return new (Importer.getToContext()) ReturnStmt(ToRetLoc, ToRetExpr, |
| 4219 | ToNRVOCandidate); |
| 4220 | } |
| 4221 | |
| 4222 | Stmt *ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 4223 | SourceLocation ToCatchLoc = Importer.Import(S->getCatchLoc()); |
| 4224 | VarDecl *ToExceptionDecl = nullptr; |
| 4225 | if (VarDecl *FromExceptionDecl = S->getExceptionDecl()) { |
| 4226 | ToExceptionDecl = |
| 4227 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 4228 | if (!ToExceptionDecl) |
| 4229 | return nullptr; |
| 4230 | } |
| 4231 | Stmt *ToHandlerBlock = Importer.Import(S->getHandlerBlock()); |
| 4232 | if (!ToHandlerBlock && S->getHandlerBlock()) |
| 4233 | return nullptr; |
| 4234 | return new (Importer.getToContext()) CXXCatchStmt(ToCatchLoc, |
| 4235 | ToExceptionDecl, |
| 4236 | ToHandlerBlock); |
| 4237 | } |
| 4238 | |
| 4239 | Stmt *ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 4240 | SourceLocation ToTryLoc = Importer.Import(S->getTryLoc()); |
| 4241 | Stmt *ToTryBlock = Importer.Import(S->getTryBlock()); |
| 4242 | if (!ToTryBlock && S->getTryBlock()) |
| 4243 | return nullptr; |
| 4244 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 4245 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 4246 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
| 4247 | if (Stmt *ToHandler = Importer.Import(FromHandler)) |
| 4248 | ToHandlers[HI] = ToHandler; |
| 4249 | else |
| 4250 | return nullptr; |
| 4251 | } |
| 4252 | return CXXTryStmt::Create(Importer.getToContext(), ToTryLoc, ToTryBlock, |
| 4253 | ToHandlers); |
| 4254 | } |
| 4255 | |
| 4256 | Stmt *ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
| 4257 | DeclStmt *ToRange = |
| 4258 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getRangeStmt())); |
| 4259 | if (!ToRange && S->getRangeStmt()) |
| 4260 | return nullptr; |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 4261 | DeclStmt *ToBegin = |
| 4262 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getBeginStmt())); |
| 4263 | if (!ToBegin && S->getBeginStmt()) |
| 4264 | return nullptr; |
| 4265 | DeclStmt *ToEnd = |
| 4266 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getEndStmt())); |
| 4267 | if (!ToEnd && S->getEndStmt()) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4268 | return nullptr; |
| 4269 | Expr *ToCond = Importer.Import(S->getCond()); |
| 4270 | if (!ToCond && S->getCond()) |
| 4271 | return nullptr; |
| 4272 | Expr *ToInc = Importer.Import(S->getInc()); |
| 4273 | if (!ToInc && S->getInc()) |
| 4274 | return nullptr; |
| 4275 | DeclStmt *ToLoopVar = |
| 4276 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getLoopVarStmt())); |
| 4277 | if (!ToLoopVar && S->getLoopVarStmt()) |
| 4278 | return nullptr; |
| 4279 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4280 | if (!ToBody && S->getBody()) |
| 4281 | return nullptr; |
| 4282 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 4283 | SourceLocation ToCoawaitLoc = Importer.Import(S->getCoawaitLoc()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4284 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 4285 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 4286 | return new (Importer.getToContext()) CXXForRangeStmt(ToRange, ToBegin, ToEnd, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4287 | ToCond, ToInc, |
| 4288 | ToLoopVar, ToBody, |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 4289 | ToForLoc, ToCoawaitLoc, |
| 4290 | ToColonLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4291 | } |
| 4292 | |
| 4293 | Stmt *ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 4294 | Stmt *ToElem = Importer.Import(S->getElement()); |
| 4295 | if (!ToElem && S->getElement()) |
| 4296 | return nullptr; |
| 4297 | Expr *ToCollect = Importer.Import(S->getCollection()); |
| 4298 | if (!ToCollect && S->getCollection()) |
| 4299 | return nullptr; |
| 4300 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4301 | if (!ToBody && S->getBody()) |
| 4302 | return nullptr; |
| 4303 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 4304 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4305 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElem, |
| 4306 | ToCollect, |
| 4307 | ToBody, ToForLoc, |
| 4308 | ToRParenLoc); |
| 4309 | } |
| 4310 | |
| 4311 | Stmt *ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 4312 | SourceLocation ToAtCatchLoc = Importer.Import(S->getAtCatchLoc()); |
| 4313 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4314 | VarDecl *ToExceptionDecl = nullptr; |
| 4315 | if (VarDecl *FromExceptionDecl = S->getCatchParamDecl()) { |
| 4316 | ToExceptionDecl = |
| 4317 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 4318 | if (!ToExceptionDecl) |
| 4319 | return nullptr; |
| 4320 | } |
| 4321 | Stmt *ToBody = Importer.Import(S->getCatchBody()); |
| 4322 | if (!ToBody && S->getCatchBody()) |
| 4323 | return nullptr; |
| 4324 | return new (Importer.getToContext()) ObjCAtCatchStmt(ToAtCatchLoc, |
| 4325 | ToRParenLoc, |
| 4326 | ToExceptionDecl, |
| 4327 | ToBody); |
| 4328 | } |
| 4329 | |
| 4330 | Stmt *ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 4331 | SourceLocation ToAtFinallyLoc = Importer.Import(S->getAtFinallyLoc()); |
| 4332 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyBody()); |
| 4333 | if (!ToAtFinallyStmt && S->getFinallyBody()) |
| 4334 | return nullptr; |
| 4335 | return new (Importer.getToContext()) ObjCAtFinallyStmt(ToAtFinallyLoc, |
| 4336 | ToAtFinallyStmt); |
| 4337 | } |
| 4338 | |
| 4339 | Stmt *ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 4340 | SourceLocation ToAtTryLoc = Importer.Import(S->getAtTryLoc()); |
| 4341 | Stmt *ToAtTryStmt = Importer.Import(S->getTryBody()); |
| 4342 | if (!ToAtTryStmt && S->getTryBody()) |
| 4343 | return nullptr; |
| 4344 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 4345 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 4346 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
| 4347 | if (Stmt *ToCatchStmt = Importer.Import(FromCatchStmt)) |
| 4348 | ToCatchStmts[CI] = ToCatchStmt; |
| 4349 | else |
| 4350 | return nullptr; |
| 4351 | } |
| 4352 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyStmt()); |
| 4353 | if (!ToAtFinallyStmt && S->getFinallyStmt()) |
| 4354 | return nullptr; |
| 4355 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
| 4356 | ToAtTryLoc, ToAtTryStmt, |
| 4357 | ToCatchStmts.begin(), ToCatchStmts.size(), |
| 4358 | ToAtFinallyStmt); |
| 4359 | } |
| 4360 | |
| 4361 | Stmt *ASTNodeImporter::VisitObjCAtSynchronizedStmt |
| 4362 | (ObjCAtSynchronizedStmt *S) { |
| 4363 | SourceLocation ToAtSynchronizedLoc = |
| 4364 | Importer.Import(S->getAtSynchronizedLoc()); |
| 4365 | Expr *ToSynchExpr = Importer.Import(S->getSynchExpr()); |
| 4366 | if (!ToSynchExpr && S->getSynchExpr()) |
| 4367 | return nullptr; |
| 4368 | Stmt *ToSynchBody = Importer.Import(S->getSynchBody()); |
| 4369 | if (!ToSynchBody && S->getSynchBody()) |
| 4370 | return nullptr; |
| 4371 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 4372 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 4373 | } |
| 4374 | |
| 4375 | Stmt *ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 4376 | SourceLocation ToAtThrowLoc = Importer.Import(S->getThrowLoc()); |
| 4377 | Expr *ToThrow = Importer.Import(S->getThrowExpr()); |
| 4378 | if (!ToThrow && S->getThrowExpr()) |
| 4379 | return nullptr; |
| 4380 | return new (Importer.getToContext()) ObjCAtThrowStmt(ToAtThrowLoc, ToThrow); |
| 4381 | } |
| 4382 | |
| 4383 | Stmt *ASTNodeImporter::VisitObjCAutoreleasePoolStmt |
| 4384 | (ObjCAutoreleasePoolStmt *S) { |
| 4385 | SourceLocation ToAtLoc = Importer.Import(S->getAtLoc()); |
| 4386 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4387 | if (!ToSubStmt && S->getSubStmt()) |
| 4388 | return nullptr; |
| 4389 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(ToAtLoc, |
| 4390 | ToSubStmt); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4391 | } |
| 4392 | |
| 4393 | //---------------------------------------------------------------------------- |
| 4394 | // Import Expressions |
| 4395 | //---------------------------------------------------------------------------- |
| 4396 | Expr *ASTNodeImporter::VisitExpr(Expr *E) { |
| 4397 | Importer.FromDiag(E->getLocStart(), diag::err_unsupported_ast_node) |
| 4398 | << E->getStmtClassName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4399 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4400 | } |
| 4401 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4402 | Expr *ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 4403 | QualType T = Importer.Import(E->getType()); |
| 4404 | if (T.isNull()) |
| 4405 | return nullptr; |
| 4406 | |
| 4407 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 4408 | if (!SubExpr && E->getSubExpr()) |
| 4409 | return nullptr; |
| 4410 | |
| 4411 | TypeSourceInfo *TInfo = Importer.Import(E->getWrittenTypeInfo()); |
| 4412 | if (!TInfo) |
| 4413 | return nullptr; |
| 4414 | |
| 4415 | return new (Importer.getToContext()) VAArgExpr( |
| 4416 | Importer.Import(E->getBuiltinLoc()), SubExpr, TInfo, |
| 4417 | Importer.Import(E->getRParenLoc()), T, E->isMicrosoftABI()); |
| 4418 | } |
| 4419 | |
| 4420 | |
| 4421 | Expr *ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 4422 | QualType T = Importer.Import(E->getType()); |
| 4423 | if (T.isNull()) |
| 4424 | return nullptr; |
| 4425 | |
| 4426 | return new (Importer.getToContext()) GNUNullExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4427 | T, Importer.Import(E->getLocStart())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4428 | } |
| 4429 | |
| 4430 | Expr *ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 4431 | QualType T = Importer.Import(E->getType()); |
| 4432 | if (T.isNull()) |
| 4433 | return nullptr; |
| 4434 | |
| 4435 | StringLiteral *SL = cast_or_null<StringLiteral>( |
| 4436 | Importer.Import(E->getFunctionName())); |
| 4437 | if (!SL && E->getFunctionName()) |
| 4438 | return nullptr; |
| 4439 | |
| 4440 | return new (Importer.getToContext()) PredefinedExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4441 | Importer.Import(E->getLocStart()), T, E->getIdentType(), SL); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4442 | } |
| 4443 | |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 4444 | Expr *ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 4445 | ValueDecl *ToD = cast_or_null<ValueDecl>(Importer.Import(E->getDecl())); |
| 4446 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4447 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 4448 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4449 | NamedDecl *FoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 4450 | if (E->getDecl() != E->getFoundDecl()) { |
| 4451 | FoundD = cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl())); |
| 4452 | if (!FoundD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4453 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 4454 | } |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 4455 | |
| 4456 | QualType T = Importer.Import(E->getType()); |
| 4457 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4458 | return nullptr; |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 4459 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4460 | |
| 4461 | TemplateArgumentListInfo ToTAInfo; |
| 4462 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 4463 | if (E->hasExplicitTemplateArgs()) { |
| 4464 | for (const auto &FromLoc : E->template_arguments()) { |
| 4465 | bool Error = false; |
| 4466 | TemplateArgumentLoc ToTALoc = ImportTemplateArgumentLoc(FromLoc, Error); |
| 4467 | if (Error) |
| 4468 | return nullptr; |
| 4469 | ToTAInfo.addArgument(ToTALoc); |
| 4470 | } |
| 4471 | ResInfo = &ToTAInfo; |
| 4472 | } |
| 4473 | |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 4474 | DeclRefExpr *DRE = DeclRefExpr::Create(Importer.getToContext(), |
| 4475 | Importer.Import(E->getQualifierLoc()), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 4476 | Importer.Import(E->getTemplateKeywordLoc()), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 4477 | ToD, |
Alexey Bataev | 19acc3d | 2015-01-12 10:17:46 +0000 | [diff] [blame] | 4478 | E->refersToEnclosingVariableOrCapture(), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 4479 | Importer.Import(E->getLocation()), |
| 4480 | T, E->getValueKind(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4481 | FoundD, ResInfo); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 4482 | if (E->hadMultipleCandidates()) |
| 4483 | DRE->setHadMultipleCandidates(true); |
| 4484 | return DRE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 4485 | } |
| 4486 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4487 | Expr *ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 4488 | QualType T = Importer.Import(E->getType()); |
| 4489 | if (T.isNull()) |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4490 | return nullptr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4491 | |
| 4492 | return new (Importer.getToContext()) ImplicitValueInitExpr(T); |
| 4493 | } |
| 4494 | |
| 4495 | ASTNodeImporter::Designator |
| 4496 | ASTNodeImporter::ImportDesignator(const Designator &D) { |
| 4497 | if (D.isFieldDesignator()) { |
| 4498 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 4499 | // Caller checks for import error |
| 4500 | return Designator(ToFieldName, Importer.Import(D.getDotLoc()), |
| 4501 | Importer.Import(D.getFieldLoc())); |
| 4502 | } |
| 4503 | if (D.isArrayDesignator()) |
| 4504 | return Designator(D.getFirstExprIndex(), |
| 4505 | Importer.Import(D.getLBracketLoc()), |
| 4506 | Importer.Import(D.getRBracketLoc())); |
| 4507 | |
| 4508 | assert(D.isArrayRangeDesignator()); |
| 4509 | return Designator(D.getFirstExprIndex(), |
| 4510 | Importer.Import(D.getLBracketLoc()), |
| 4511 | Importer.Import(D.getEllipsisLoc()), |
| 4512 | Importer.Import(D.getRBracketLoc())); |
| 4513 | } |
| 4514 | |
| 4515 | |
| 4516 | Expr *ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *DIE) { |
| 4517 | Expr *Init = cast_or_null<Expr>(Importer.Import(DIE->getInit())); |
| 4518 | if (!Init) |
| 4519 | return nullptr; |
| 4520 | |
| 4521 | SmallVector<Expr *, 4> IndexExprs(DIE->getNumSubExprs() - 1); |
| 4522 | // List elements from the second, the first is Init itself |
| 4523 | for (unsigned I = 1, E = DIE->getNumSubExprs(); I < E; I++) { |
| 4524 | if (Expr *Arg = cast_or_null<Expr>(Importer.Import(DIE->getSubExpr(I)))) |
| 4525 | IndexExprs[I - 1] = Arg; |
| 4526 | else |
| 4527 | return nullptr; |
| 4528 | } |
| 4529 | |
| 4530 | SmallVector<Designator, 4> Designators(DIE->size()); |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 4531 | llvm::transform(DIE->designators(), Designators.begin(), |
| 4532 | [this](const Designator &D) -> Designator { |
| 4533 | return ImportDesignator(D); |
| 4534 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4535 | |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 4536 | for (const Designator &D : DIE->designators()) |
| 4537 | if (D.isFieldDesignator() && !D.getFieldName()) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4538 | return nullptr; |
| 4539 | |
| 4540 | return DesignatedInitExpr::Create( |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 4541 | Importer.getToContext(), Designators, |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4542 | IndexExprs, Importer.Import(DIE->getEqualOrColonLoc()), |
| 4543 | DIE->usesGNUSyntax(), Init); |
| 4544 | } |
| 4545 | |
| 4546 | Expr *ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 4547 | QualType T = Importer.Import(E->getType()); |
| 4548 | if (T.isNull()) |
| 4549 | return nullptr; |
| 4550 | |
| 4551 | return new (Importer.getToContext()) |
| 4552 | CXXNullPtrLiteralExpr(T, Importer.Import(E->getLocation())); |
| 4553 | } |
| 4554 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4555 | Expr *ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 4556 | QualType T = Importer.Import(E->getType()); |
| 4557 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4558 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4559 | |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 4560 | return IntegerLiteral::Create(Importer.getToContext(), |
| 4561 | E->getValue(), T, |
| 4562 | Importer.Import(E->getLocation())); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4563 | } |
| 4564 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4565 | Expr *ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 4566 | QualType T = Importer.Import(E->getType()); |
| 4567 | if (T.isNull()) |
| 4568 | return nullptr; |
| 4569 | |
| 4570 | return FloatingLiteral::Create(Importer.getToContext(), |
| 4571 | E->getValue(), E->isExact(), T, |
| 4572 | Importer.Import(E->getLocation())); |
| 4573 | } |
| 4574 | |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 4575 | Expr *ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 4576 | QualType T = Importer.Import(E->getType()); |
| 4577 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4578 | return nullptr; |
| 4579 | |
Douglas Gregor | fb65e59 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 4580 | return new (Importer.getToContext()) CharacterLiteral(E->getValue(), |
| 4581 | E->getKind(), T, |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 4582 | Importer.Import(E->getLocation())); |
| 4583 | } |
| 4584 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4585 | Expr *ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 4586 | QualType T = Importer.Import(E->getType()); |
| 4587 | if (T.isNull()) |
| 4588 | return nullptr; |
| 4589 | |
| 4590 | SmallVector<SourceLocation, 4> Locations(E->getNumConcatenated()); |
| 4591 | ImportArray(E->tokloc_begin(), E->tokloc_end(), Locations.begin()); |
| 4592 | |
| 4593 | return StringLiteral::Create(Importer.getToContext(), E->getBytes(), |
| 4594 | E->getKind(), E->isPascal(), T, |
| 4595 | Locations.data(), Locations.size()); |
| 4596 | } |
| 4597 | |
| 4598 | Expr *ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 4599 | QualType T = Importer.Import(E->getType()); |
| 4600 | if (T.isNull()) |
| 4601 | return nullptr; |
| 4602 | |
| 4603 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeSourceInfo()); |
| 4604 | if (!TInfo) |
| 4605 | return nullptr; |
| 4606 | |
| 4607 | Expr *Init = Importer.Import(E->getInitializer()); |
| 4608 | if (!Init) |
| 4609 | return nullptr; |
| 4610 | |
| 4611 | return new (Importer.getToContext()) CompoundLiteralExpr( |
| 4612 | Importer.Import(E->getLParenLoc()), TInfo, T, E->getValueKind(), |
| 4613 | Init, E->isFileScope()); |
| 4614 | } |
| 4615 | |
| 4616 | Expr *ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 4617 | QualType T = Importer.Import(E->getType()); |
| 4618 | if (T.isNull()) |
| 4619 | return nullptr; |
| 4620 | |
| 4621 | SmallVector<Expr *, 6> Exprs(E->getNumSubExprs()); |
| 4622 | if (ImportArrayChecked( |
| 4623 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 4624 | Exprs.begin())) |
| 4625 | return nullptr; |
| 4626 | |
| 4627 | return new (Importer.getToContext()) AtomicExpr( |
| 4628 | Importer.Import(E->getBuiltinLoc()), Exprs, T, E->getOp(), |
| 4629 | Importer.Import(E->getRParenLoc())); |
| 4630 | } |
| 4631 | |
| 4632 | Expr *ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 4633 | QualType T = Importer.Import(E->getType()); |
| 4634 | if (T.isNull()) |
| 4635 | return nullptr; |
| 4636 | |
| 4637 | LabelDecl *ToLabel = cast_or_null<LabelDecl>(Importer.Import(E->getLabel())); |
| 4638 | if (!ToLabel) |
| 4639 | return nullptr; |
| 4640 | |
| 4641 | return new (Importer.getToContext()) AddrLabelExpr( |
| 4642 | Importer.Import(E->getAmpAmpLoc()), Importer.Import(E->getLabelLoc()), |
| 4643 | ToLabel, T); |
| 4644 | } |
| 4645 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4646 | Expr *ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 4647 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 4648 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4649 | return nullptr; |
| 4650 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4651 | return new (Importer.getToContext()) |
| 4652 | ParenExpr(Importer.Import(E->getLParen()), |
| 4653 | Importer.Import(E->getRParen()), |
| 4654 | SubExpr); |
| 4655 | } |
| 4656 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4657 | Expr *ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 4658 | SmallVector<Expr *, 4> Exprs(E->getNumExprs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4659 | if (ImportContainerChecked(E->exprs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4660 | return nullptr; |
| 4661 | |
| 4662 | return new (Importer.getToContext()) ParenListExpr( |
| 4663 | Importer.getToContext(), Importer.Import(E->getLParenLoc()), |
| 4664 | Exprs, Importer.Import(E->getLParenLoc())); |
| 4665 | } |
| 4666 | |
| 4667 | Expr *ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 4668 | QualType T = Importer.Import(E->getType()); |
| 4669 | if (T.isNull()) |
| 4670 | return nullptr; |
| 4671 | |
| 4672 | CompoundStmt *ToSubStmt = cast_or_null<CompoundStmt>( |
| 4673 | Importer.Import(E->getSubStmt())); |
| 4674 | if (!ToSubStmt && E->getSubStmt()) |
| 4675 | return nullptr; |
| 4676 | |
| 4677 | return new (Importer.getToContext()) StmtExpr(ToSubStmt, T, |
| 4678 | Importer.Import(E->getLParenLoc()), Importer.Import(E->getRParenLoc())); |
| 4679 | } |
| 4680 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4681 | Expr *ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 4682 | QualType T = Importer.Import(E->getType()); |
| 4683 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4684 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4685 | |
| 4686 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 4687 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4688 | return nullptr; |
| 4689 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4690 | return new (Importer.getToContext()) UnaryOperator(SubExpr, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 4691 | T, E->getValueKind(), |
| 4692 | E->getObjectKind(), |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4693 | Importer.Import(E->getOperatorLoc())); |
| 4694 | } |
| 4695 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 4696 | Expr *ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr( |
| 4697 | UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 4698 | QualType ResultType = Importer.Import(E->getType()); |
| 4699 | |
| 4700 | if (E->isArgumentType()) { |
| 4701 | TypeSourceInfo *TInfo = Importer.Import(E->getArgumentTypeInfo()); |
| 4702 | if (!TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4703 | return nullptr; |
| 4704 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 4705 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 4706 | TInfo, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 4707 | Importer.Import(E->getOperatorLoc()), |
| 4708 | Importer.Import(E->getRParenLoc())); |
| 4709 | } |
| 4710 | |
| 4711 | Expr *SubExpr = Importer.Import(E->getArgumentExpr()); |
| 4712 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4713 | return nullptr; |
| 4714 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 4715 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 4716 | SubExpr, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 4717 | Importer.Import(E->getOperatorLoc()), |
| 4718 | Importer.Import(E->getRParenLoc())); |
| 4719 | } |
| 4720 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4721 | Expr *ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 4722 | QualType T = Importer.Import(E->getType()); |
| 4723 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4724 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4725 | |
| 4726 | Expr *LHS = Importer.Import(E->getLHS()); |
| 4727 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4728 | return nullptr; |
| 4729 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4730 | Expr *RHS = Importer.Import(E->getRHS()); |
| 4731 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4732 | return nullptr; |
| 4733 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4734 | return new (Importer.getToContext()) BinaryOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 4735 | T, E->getValueKind(), |
| 4736 | E->getObjectKind(), |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 4737 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 4738 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4739 | } |
| 4740 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4741 | Expr *ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 4742 | QualType T = Importer.Import(E->getType()); |
| 4743 | if (T.isNull()) |
| 4744 | return nullptr; |
| 4745 | |
| 4746 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 4747 | if (!ToLHS) |
| 4748 | return nullptr; |
| 4749 | |
| 4750 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 4751 | if (!ToRHS) |
| 4752 | return nullptr; |
| 4753 | |
| 4754 | Expr *ToCond = Importer.Import(E->getCond()); |
| 4755 | if (!ToCond) |
| 4756 | return nullptr; |
| 4757 | |
| 4758 | return new (Importer.getToContext()) ConditionalOperator( |
| 4759 | ToCond, Importer.Import(E->getQuestionLoc()), |
| 4760 | ToLHS, Importer.Import(E->getColonLoc()), |
| 4761 | ToRHS, T, E->getValueKind(), E->getObjectKind()); |
| 4762 | } |
| 4763 | |
| 4764 | Expr *ASTNodeImporter::VisitBinaryConditionalOperator( |
| 4765 | BinaryConditionalOperator *E) { |
| 4766 | QualType T = Importer.Import(E->getType()); |
| 4767 | if (T.isNull()) |
| 4768 | return nullptr; |
| 4769 | |
| 4770 | Expr *Common = Importer.Import(E->getCommon()); |
| 4771 | if (!Common) |
| 4772 | return nullptr; |
| 4773 | |
| 4774 | Expr *Cond = Importer.Import(E->getCond()); |
| 4775 | if (!Cond) |
| 4776 | return nullptr; |
| 4777 | |
| 4778 | OpaqueValueExpr *OpaqueValue = cast_or_null<OpaqueValueExpr>( |
| 4779 | Importer.Import(E->getOpaqueValue())); |
| 4780 | if (!OpaqueValue) |
| 4781 | return nullptr; |
| 4782 | |
| 4783 | Expr *TrueExpr = Importer.Import(E->getTrueExpr()); |
| 4784 | if (!TrueExpr) |
| 4785 | return nullptr; |
| 4786 | |
| 4787 | Expr *FalseExpr = Importer.Import(E->getFalseExpr()); |
| 4788 | if (!FalseExpr) |
| 4789 | return nullptr; |
| 4790 | |
| 4791 | return new (Importer.getToContext()) BinaryConditionalOperator( |
| 4792 | Common, OpaqueValue, Cond, TrueExpr, FalseExpr, |
| 4793 | Importer.Import(E->getQuestionLoc()), Importer.Import(E->getColonLoc()), |
| 4794 | T, E->getValueKind(), E->getObjectKind()); |
| 4795 | } |
| 4796 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4797 | Expr *ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 4798 | QualType T = Importer.Import(E->getType()); |
| 4799 | if (T.isNull()) |
| 4800 | return nullptr; |
| 4801 | |
| 4802 | TypeSourceInfo *ToQueried = Importer.Import(E->getQueriedTypeSourceInfo()); |
| 4803 | if (!ToQueried) |
| 4804 | return nullptr; |
| 4805 | |
| 4806 | Expr *Dim = Importer.Import(E->getDimensionExpression()); |
| 4807 | if (!Dim && E->getDimensionExpression()) |
| 4808 | return nullptr; |
| 4809 | |
| 4810 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
| 4811 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 4812 | E->getValue(), Dim, Importer.Import(E->getLocEnd()), T); |
| 4813 | } |
| 4814 | |
| 4815 | Expr *ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 4816 | QualType T = Importer.Import(E->getType()); |
| 4817 | if (T.isNull()) |
| 4818 | return nullptr; |
| 4819 | |
| 4820 | Expr *ToQueried = Importer.Import(E->getQueriedExpression()); |
| 4821 | if (!ToQueried) |
| 4822 | return nullptr; |
| 4823 | |
| 4824 | return new (Importer.getToContext()) ExpressionTraitExpr( |
| 4825 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 4826 | E->getValue(), Importer.Import(E->getLocEnd()), T); |
| 4827 | } |
| 4828 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4829 | Expr *ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 4830 | QualType T = Importer.Import(E->getType()); |
| 4831 | if (T.isNull()) |
| 4832 | return nullptr; |
| 4833 | |
| 4834 | Expr *SourceExpr = Importer.Import(E->getSourceExpr()); |
| 4835 | if (!SourceExpr && E->getSourceExpr()) |
| 4836 | return nullptr; |
| 4837 | |
| 4838 | return new (Importer.getToContext()) OpaqueValueExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4839 | Importer.Import(E->getLocation()), T, E->getValueKind(), |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4840 | E->getObjectKind(), SourceExpr); |
| 4841 | } |
| 4842 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4843 | Expr *ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 4844 | QualType T = Importer.Import(E->getType()); |
| 4845 | if (T.isNull()) |
| 4846 | return nullptr; |
| 4847 | |
| 4848 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 4849 | if (!ToLHS) |
| 4850 | return nullptr; |
| 4851 | |
| 4852 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 4853 | if (!ToRHS) |
| 4854 | return nullptr; |
| 4855 | |
| 4856 | return new (Importer.getToContext()) ArraySubscriptExpr( |
| 4857 | ToLHS, ToRHS, T, E->getValueKind(), E->getObjectKind(), |
| 4858 | Importer.Import(E->getRBracketLoc())); |
| 4859 | } |
| 4860 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4861 | Expr *ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 4862 | QualType T = Importer.Import(E->getType()); |
| 4863 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4864 | return nullptr; |
| 4865 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4866 | QualType CompLHSType = Importer.Import(E->getComputationLHSType()); |
| 4867 | if (CompLHSType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4868 | return nullptr; |
| 4869 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4870 | QualType CompResultType = Importer.Import(E->getComputationResultType()); |
| 4871 | if (CompResultType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4872 | return nullptr; |
| 4873 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4874 | Expr *LHS = Importer.Import(E->getLHS()); |
| 4875 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4876 | return nullptr; |
| 4877 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4878 | Expr *RHS = Importer.Import(E->getRHS()); |
| 4879 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4880 | return nullptr; |
| 4881 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4882 | return new (Importer.getToContext()) |
| 4883 | CompoundAssignOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 4884 | T, E->getValueKind(), |
| 4885 | E->getObjectKind(), |
| 4886 | CompLHSType, CompResultType, |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 4887 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 4888 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4889 | } |
| 4890 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4891 | bool ASTNodeImporter::ImportCastPath(CastExpr *CE, CXXCastPath &Path) { |
| 4892 | for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) { |
| 4893 | if (CXXBaseSpecifier *Spec = Importer.Import(*I)) |
| 4894 | Path.push_back(Spec); |
| 4895 | else |
| 4896 | return true; |
| 4897 | } |
| 4898 | return false; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 4899 | } |
| 4900 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 4901 | Expr *ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 4902 | QualType T = Importer.Import(E->getType()); |
| 4903 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4904 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 4905 | |
| 4906 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 4907 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4908 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 4909 | |
| 4910 | CXXCastPath BasePath; |
| 4911 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4912 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 4913 | |
| 4914 | return ImplicitCastExpr::Create(Importer.getToContext(), T, E->getCastKind(), |
John McCall | 2536c6d | 2010-08-25 10:28:54 +0000 | [diff] [blame] | 4915 | SubExpr, &BasePath, E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 4916 | } |
| 4917 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4918 | Expr *ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 4919 | QualType T = Importer.Import(E->getType()); |
| 4920 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4921 | return nullptr; |
| 4922 | |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 4923 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 4924 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4925 | return nullptr; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 4926 | |
| 4927 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeInfoAsWritten()); |
| 4928 | if (!TInfo && E->getTypeInfoAsWritten()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4929 | return nullptr; |
| 4930 | |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 4931 | CXXCastPath BasePath; |
| 4932 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4933 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 4934 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4935 | switch (E->getStmtClass()) { |
| 4936 | case Stmt::CStyleCastExprClass: { |
| 4937 | CStyleCastExpr *CCE = cast<CStyleCastExpr>(E); |
| 4938 | return CStyleCastExpr::Create(Importer.getToContext(), T, |
| 4939 | E->getValueKind(), E->getCastKind(), |
| 4940 | SubExpr, &BasePath, TInfo, |
| 4941 | Importer.Import(CCE->getLParenLoc()), |
| 4942 | Importer.Import(CCE->getRParenLoc())); |
| 4943 | } |
| 4944 | |
| 4945 | case Stmt::CXXFunctionalCastExprClass: { |
| 4946 | CXXFunctionalCastExpr *FCE = cast<CXXFunctionalCastExpr>(E); |
| 4947 | return CXXFunctionalCastExpr::Create(Importer.getToContext(), T, |
| 4948 | E->getValueKind(), TInfo, |
| 4949 | E->getCastKind(), SubExpr, &BasePath, |
| 4950 | Importer.Import(FCE->getLParenLoc()), |
| 4951 | Importer.Import(FCE->getRParenLoc())); |
| 4952 | } |
| 4953 | |
| 4954 | case Stmt::ObjCBridgedCastExprClass: { |
| 4955 | ObjCBridgedCastExpr *OCE = cast<ObjCBridgedCastExpr>(E); |
| 4956 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 4957 | Importer.Import(OCE->getLParenLoc()), OCE->getBridgeKind(), |
| 4958 | E->getCastKind(), Importer.Import(OCE->getBridgeKeywordLoc()), |
| 4959 | TInfo, SubExpr); |
| 4960 | } |
| 4961 | default: |
| 4962 | break; // just fall through |
| 4963 | } |
| 4964 | |
| 4965 | CXXNamedCastExpr *Named = cast<CXXNamedCastExpr>(E); |
| 4966 | SourceLocation ExprLoc = Importer.Import(Named->getOperatorLoc()), |
| 4967 | RParenLoc = Importer.Import(Named->getRParenLoc()); |
| 4968 | SourceRange Brackets = Importer.Import(Named->getAngleBrackets()); |
| 4969 | |
| 4970 | switch (E->getStmtClass()) { |
| 4971 | case Stmt::CXXStaticCastExprClass: |
| 4972 | return CXXStaticCastExpr::Create(Importer.getToContext(), T, |
| 4973 | E->getValueKind(), E->getCastKind(), |
| 4974 | SubExpr, &BasePath, TInfo, |
| 4975 | ExprLoc, RParenLoc, Brackets); |
| 4976 | |
| 4977 | case Stmt::CXXDynamicCastExprClass: |
| 4978 | return CXXDynamicCastExpr::Create(Importer.getToContext(), T, |
| 4979 | E->getValueKind(), E->getCastKind(), |
| 4980 | SubExpr, &BasePath, TInfo, |
| 4981 | ExprLoc, RParenLoc, Brackets); |
| 4982 | |
| 4983 | case Stmt::CXXReinterpretCastExprClass: |
| 4984 | return CXXReinterpretCastExpr::Create(Importer.getToContext(), T, |
| 4985 | E->getValueKind(), E->getCastKind(), |
| 4986 | SubExpr, &BasePath, TInfo, |
| 4987 | ExprLoc, RParenLoc, Brackets); |
| 4988 | |
| 4989 | case Stmt::CXXConstCastExprClass: |
| 4990 | return CXXConstCastExpr::Create(Importer.getToContext(), T, |
| 4991 | E->getValueKind(), SubExpr, TInfo, ExprLoc, |
| 4992 | RParenLoc, Brackets); |
| 4993 | default: |
| 4994 | llvm_unreachable("Cast expression of unsupported type!"); |
| 4995 | return nullptr; |
| 4996 | } |
| 4997 | } |
| 4998 | |
| 4999 | Expr *ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *OE) { |
| 5000 | QualType T = Importer.Import(OE->getType()); |
| 5001 | if (T.isNull()) |
| 5002 | return nullptr; |
| 5003 | |
| 5004 | SmallVector<OffsetOfNode, 4> Nodes; |
| 5005 | for (int I = 0, E = OE->getNumComponents(); I < E; ++I) { |
| 5006 | const OffsetOfNode &Node = OE->getComponent(I); |
| 5007 | |
| 5008 | switch (Node.getKind()) { |
| 5009 | case OffsetOfNode::Array: |
| 5010 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), |
| 5011 | Node.getArrayExprIndex(), |
| 5012 | Importer.Import(Node.getLocEnd()))); |
| 5013 | break; |
| 5014 | |
| 5015 | case OffsetOfNode::Base: { |
| 5016 | CXXBaseSpecifier *BS = Importer.Import(Node.getBase()); |
| 5017 | if (!BS && Node.getBase()) |
| 5018 | return nullptr; |
| 5019 | Nodes.push_back(OffsetOfNode(BS)); |
| 5020 | break; |
| 5021 | } |
| 5022 | case OffsetOfNode::Field: { |
| 5023 | FieldDecl *FD = cast_or_null<FieldDecl>(Importer.Import(Node.getField())); |
| 5024 | if (!FD) |
| 5025 | return nullptr; |
| 5026 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), FD, |
| 5027 | Importer.Import(Node.getLocEnd()))); |
| 5028 | break; |
| 5029 | } |
| 5030 | case OffsetOfNode::Identifier: { |
| 5031 | IdentifierInfo *ToII = Importer.Import(Node.getFieldName()); |
| 5032 | if (!ToII) |
| 5033 | return nullptr; |
| 5034 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), ToII, |
| 5035 | Importer.Import(Node.getLocEnd()))); |
| 5036 | break; |
| 5037 | } |
| 5038 | } |
| 5039 | } |
| 5040 | |
| 5041 | SmallVector<Expr *, 4> Exprs(OE->getNumExpressions()); |
| 5042 | for (int I = 0, E = OE->getNumExpressions(); I < E; ++I) { |
| 5043 | Expr *ToIndexExpr = Importer.Import(OE->getIndexExpr(I)); |
| 5044 | if (!ToIndexExpr) |
| 5045 | return nullptr; |
| 5046 | Exprs[I] = ToIndexExpr; |
| 5047 | } |
| 5048 | |
| 5049 | TypeSourceInfo *TInfo = Importer.Import(OE->getTypeSourceInfo()); |
| 5050 | if (!TInfo && OE->getTypeSourceInfo()) |
| 5051 | return nullptr; |
| 5052 | |
| 5053 | return OffsetOfExpr::Create(Importer.getToContext(), T, |
| 5054 | Importer.Import(OE->getOperatorLoc()), |
| 5055 | TInfo, Nodes, Exprs, |
| 5056 | Importer.Import(OE->getRParenLoc())); |
| 5057 | } |
| 5058 | |
| 5059 | Expr *ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 5060 | QualType T = Importer.Import(E->getType()); |
| 5061 | if (T.isNull()) |
| 5062 | return nullptr; |
| 5063 | |
| 5064 | Expr *Operand = Importer.Import(E->getOperand()); |
| 5065 | if (!Operand) |
| 5066 | return nullptr; |
| 5067 | |
| 5068 | CanThrowResult CanThrow; |
| 5069 | if (E->isValueDependent()) |
| 5070 | CanThrow = CT_Dependent; |
| 5071 | else |
| 5072 | CanThrow = E->getValue() ? CT_Can : CT_Cannot; |
| 5073 | |
| 5074 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 5075 | T, Operand, CanThrow, |
| 5076 | Importer.Import(E->getLocStart()), Importer.Import(E->getLocEnd())); |
| 5077 | } |
| 5078 | |
| 5079 | Expr *ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 5080 | QualType T = Importer.Import(E->getType()); |
| 5081 | if (T.isNull()) |
| 5082 | return nullptr; |
| 5083 | |
| 5084 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5085 | if (!SubExpr && E->getSubExpr()) |
| 5086 | return nullptr; |
| 5087 | |
| 5088 | return new (Importer.getToContext()) CXXThrowExpr( |
| 5089 | SubExpr, T, Importer.Import(E->getThrowLoc()), |
| 5090 | E->isThrownVariableInScope()); |
| 5091 | } |
| 5092 | |
| 5093 | Expr *ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 5094 | ParmVarDecl *Param = cast_or_null<ParmVarDecl>( |
| 5095 | Importer.Import(E->getParam())); |
| 5096 | if (!Param) |
| 5097 | return nullptr; |
| 5098 | |
| 5099 | return CXXDefaultArgExpr::Create( |
| 5100 | Importer.getToContext(), Importer.Import(E->getUsedLocation()), Param); |
| 5101 | } |
| 5102 | |
| 5103 | Expr *ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 5104 | QualType T = Importer.Import(E->getType()); |
| 5105 | if (T.isNull()) |
| 5106 | return nullptr; |
| 5107 | |
| 5108 | TypeSourceInfo *TypeInfo = Importer.Import(E->getTypeSourceInfo()); |
| 5109 | if (!TypeInfo) |
| 5110 | return nullptr; |
| 5111 | |
| 5112 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
| 5113 | T, TypeInfo, Importer.Import(E->getRParenLoc())); |
| 5114 | } |
| 5115 | |
| 5116 | Expr *ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 5117 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5118 | if (!SubExpr) |
| 5119 | return nullptr; |
| 5120 | |
| 5121 | auto *Dtor = cast_or_null<CXXDestructorDecl>( |
| 5122 | Importer.Import(const_cast<CXXDestructorDecl *>( |
| 5123 | E->getTemporary()->getDestructor()))); |
| 5124 | if (!Dtor) |
| 5125 | return nullptr; |
| 5126 | |
| 5127 | ASTContext &ToCtx = Importer.getToContext(); |
| 5128 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, Dtor); |
| 5129 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, SubExpr); |
| 5130 | } |
| 5131 | |
| 5132 | Expr *ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE) { |
| 5133 | QualType T = Importer.Import(CE->getType()); |
| 5134 | if (T.isNull()) |
| 5135 | return nullptr; |
| 5136 | |
| 5137 | SmallVector<Expr *, 8> Args(CE->getNumArgs()); |
| 5138 | if (ImportContainerChecked(CE->arguments(), Args)) |
| 5139 | return nullptr; |
| 5140 | |
| 5141 | auto *Ctor = cast_or_null<CXXConstructorDecl>( |
| 5142 | Importer.Import(CE->getConstructor())); |
| 5143 | if (!Ctor) |
| 5144 | return nullptr; |
| 5145 | |
| 5146 | return CXXTemporaryObjectExpr::Create( |
| 5147 | Importer.getToContext(), T, |
| 5148 | Importer.Import(CE->getLocStart()), |
| 5149 | Ctor, |
| 5150 | CE->isElidable(), |
| 5151 | Args, |
| 5152 | CE->hadMultipleCandidates(), |
| 5153 | CE->isListInitialization(), |
| 5154 | CE->isStdInitListInitialization(), |
| 5155 | CE->requiresZeroInitialization(), |
| 5156 | CE->getConstructionKind(), |
| 5157 | Importer.Import(CE->getParenOrBraceRange())); |
| 5158 | } |
| 5159 | |
| 5160 | Expr * |
| 5161 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
| 5162 | QualType T = Importer.Import(E->getType()); |
| 5163 | if (T.isNull()) |
| 5164 | return nullptr; |
| 5165 | |
| 5166 | Expr *TempE = Importer.Import(E->GetTemporaryExpr()); |
| 5167 | if (!TempE) |
| 5168 | return nullptr; |
| 5169 | |
| 5170 | ValueDecl *ExtendedBy = cast_or_null<ValueDecl>( |
| 5171 | Importer.Import(const_cast<ValueDecl *>(E->getExtendingDecl()))); |
| 5172 | if (!ExtendedBy && E->getExtendingDecl()) |
| 5173 | return nullptr; |
| 5174 | |
| 5175 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
| 5176 | T, TempE, E->isBoundToLvalueReference()); |
| 5177 | |
| 5178 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
| 5179 | ToMTE->setExtendingDecl(ExtendedBy, E->getManglingNumber()); |
| 5180 | return ToMTE; |
| 5181 | } |
| 5182 | |
| 5183 | Expr *ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *CE) { |
| 5184 | QualType T = Importer.Import(CE->getType()); |
| 5185 | if (T.isNull()) |
| 5186 | return nullptr; |
| 5187 | |
| 5188 | SmallVector<Expr *, 4> PlacementArgs(CE->getNumPlacementArgs()); |
| 5189 | if (ImportContainerChecked(CE->placement_arguments(), PlacementArgs)) |
| 5190 | return nullptr; |
| 5191 | |
| 5192 | FunctionDecl *OperatorNewDecl = cast_or_null<FunctionDecl>( |
| 5193 | Importer.Import(CE->getOperatorNew())); |
| 5194 | if (!OperatorNewDecl && CE->getOperatorNew()) |
| 5195 | return nullptr; |
| 5196 | |
| 5197 | FunctionDecl *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
| 5198 | Importer.Import(CE->getOperatorDelete())); |
| 5199 | if (!OperatorDeleteDecl && CE->getOperatorDelete()) |
| 5200 | return nullptr; |
| 5201 | |
| 5202 | Expr *ToInit = Importer.Import(CE->getInitializer()); |
| 5203 | if (!ToInit && CE->getInitializer()) |
| 5204 | return nullptr; |
| 5205 | |
| 5206 | TypeSourceInfo *TInfo = Importer.Import(CE->getAllocatedTypeSourceInfo()); |
| 5207 | if (!TInfo) |
| 5208 | return nullptr; |
| 5209 | |
| 5210 | Expr *ToArrSize = Importer.Import(CE->getArraySize()); |
| 5211 | if (!ToArrSize && CE->getArraySize()) |
| 5212 | return nullptr; |
| 5213 | |
| 5214 | return new (Importer.getToContext()) CXXNewExpr( |
| 5215 | Importer.getToContext(), |
| 5216 | CE->isGlobalNew(), |
| 5217 | OperatorNewDecl, OperatorDeleteDecl, |
Richard Smith | b2f0f05 | 2016-10-10 18:54:32 +0000 | [diff] [blame] | 5218 | CE->passAlignment(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5219 | CE->doesUsualArrayDeleteWantSize(), |
| 5220 | PlacementArgs, |
| 5221 | Importer.Import(CE->getTypeIdParens()), |
| 5222 | ToArrSize, CE->getInitializationStyle(), ToInit, T, TInfo, |
| 5223 | Importer.Import(CE->getSourceRange()), |
| 5224 | Importer.Import(CE->getDirectInitRange())); |
| 5225 | } |
| 5226 | |
| 5227 | Expr *ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 5228 | QualType T = Importer.Import(E->getType()); |
| 5229 | if (T.isNull()) |
| 5230 | return nullptr; |
| 5231 | |
| 5232 | FunctionDecl *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
| 5233 | Importer.Import(E->getOperatorDelete())); |
| 5234 | if (!OperatorDeleteDecl && E->getOperatorDelete()) |
| 5235 | return nullptr; |
| 5236 | |
| 5237 | Expr *ToArg = Importer.Import(E->getArgument()); |
| 5238 | if (!ToArg && E->getArgument()) |
| 5239 | return nullptr; |
| 5240 | |
| 5241 | return new (Importer.getToContext()) CXXDeleteExpr( |
| 5242 | T, E->isGlobalDelete(), |
| 5243 | E->isArrayForm(), |
| 5244 | E->isArrayFormAsWritten(), |
| 5245 | E->doesUsualArrayDeleteWantSize(), |
| 5246 | OperatorDeleteDecl, |
| 5247 | ToArg, |
| 5248 | Importer.Import(E->getLocStart())); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5249 | } |
| 5250 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5251 | Expr *ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 5252 | QualType T = Importer.Import(E->getType()); |
| 5253 | if (T.isNull()) |
| 5254 | return nullptr; |
| 5255 | |
| 5256 | CXXConstructorDecl *ToCCD = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 5257 | dyn_cast_or_null<CXXConstructorDecl>(Importer.Import(E->getConstructor())); |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 5258 | if (!ToCCD) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5259 | return nullptr; |
| 5260 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5261 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5262 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5263 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5264 | |
| 5265 | return CXXConstructExpr::Create(Importer.getToContext(), T, |
| 5266 | Importer.Import(E->getLocation()), |
Richard Smith | c83bf82 | 2016-06-10 00:58:19 +0000 | [diff] [blame] | 5267 | ToCCD, E->isElidable(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5268 | ToArgs, E->hadMultipleCandidates(), |
| 5269 | E->isListInitialization(), |
| 5270 | E->isStdInitListInitialization(), |
| 5271 | E->requiresZeroInitialization(), |
| 5272 | E->getConstructionKind(), |
| 5273 | Importer.Import(E->getParenOrBraceRange())); |
| 5274 | } |
| 5275 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5276 | Expr *ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *EWC) { |
| 5277 | Expr *SubExpr = Importer.Import(EWC->getSubExpr()); |
| 5278 | if (!SubExpr && EWC->getSubExpr()) |
| 5279 | return nullptr; |
| 5280 | |
| 5281 | SmallVector<ExprWithCleanups::CleanupObject, 8> Objs(EWC->getNumObjects()); |
| 5282 | for (unsigned I = 0, E = EWC->getNumObjects(); I < E; I++) |
| 5283 | if (ExprWithCleanups::CleanupObject Obj = |
| 5284 | cast_or_null<BlockDecl>(Importer.Import(EWC->getObject(I)))) |
| 5285 | Objs[I] = Obj; |
| 5286 | else |
| 5287 | return nullptr; |
| 5288 | |
| 5289 | return ExprWithCleanups::Create(Importer.getToContext(), |
| 5290 | SubExpr, EWC->cleanupsHaveSideEffects(), |
| 5291 | Objs); |
| 5292 | } |
| 5293 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5294 | Expr *ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 5295 | QualType T = Importer.Import(E->getType()); |
| 5296 | if (T.isNull()) |
| 5297 | return nullptr; |
| 5298 | |
| 5299 | Expr *ToFn = Importer.Import(E->getCallee()); |
| 5300 | if (!ToFn) |
| 5301 | return nullptr; |
| 5302 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5303 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5304 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5305 | return nullptr; |
| 5306 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5307 | return new (Importer.getToContext()) CXXMemberCallExpr( |
| 5308 | Importer.getToContext(), ToFn, ToArgs, T, E->getValueKind(), |
| 5309 | Importer.Import(E->getRParenLoc())); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5310 | } |
| 5311 | |
| 5312 | Expr *ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 5313 | QualType T = Importer.Import(E->getType()); |
| 5314 | if (T.isNull()) |
| 5315 | return nullptr; |
| 5316 | |
| 5317 | return new (Importer.getToContext()) |
| 5318 | CXXThisExpr(Importer.Import(E->getLocation()), T, E->isImplicit()); |
| 5319 | } |
| 5320 | |
| 5321 | Expr *ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 5322 | QualType T = Importer.Import(E->getType()); |
| 5323 | if (T.isNull()) |
| 5324 | return nullptr; |
| 5325 | |
| 5326 | return new (Importer.getToContext()) |
| 5327 | CXXBoolLiteralExpr(E->getValue(), T, Importer.Import(E->getLocation())); |
| 5328 | } |
| 5329 | |
| 5330 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5331 | Expr *ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 5332 | QualType T = Importer.Import(E->getType()); |
| 5333 | if (T.isNull()) |
| 5334 | return nullptr; |
| 5335 | |
| 5336 | Expr *ToBase = Importer.Import(E->getBase()); |
| 5337 | if (!ToBase && E->getBase()) |
| 5338 | return nullptr; |
| 5339 | |
| 5340 | ValueDecl *ToMember = dyn_cast<ValueDecl>(Importer.Import(E->getMemberDecl())); |
| 5341 | if (!ToMember && E->getMemberDecl()) |
| 5342 | return nullptr; |
| 5343 | |
| 5344 | DeclAccessPair ToFoundDecl = DeclAccessPair::make( |
| 5345 | dyn_cast<NamedDecl>(Importer.Import(E->getFoundDecl().getDecl())), |
| 5346 | E->getFoundDecl().getAccess()); |
| 5347 | |
| 5348 | DeclarationNameInfo ToMemberNameInfo( |
| 5349 | Importer.Import(E->getMemberNameInfo().getName()), |
| 5350 | Importer.Import(E->getMemberNameInfo().getLoc())); |
| 5351 | |
| 5352 | if (E->hasExplicitTemplateArgs()) { |
| 5353 | return nullptr; // FIXME: handle template arguments |
| 5354 | } |
| 5355 | |
| 5356 | return MemberExpr::Create(Importer.getToContext(), ToBase, |
| 5357 | E->isArrow(), |
| 5358 | Importer.Import(E->getOperatorLoc()), |
| 5359 | Importer.Import(E->getQualifierLoc()), |
| 5360 | Importer.Import(E->getTemplateKeywordLoc()), |
| 5361 | ToMember, ToFoundDecl, ToMemberNameInfo, |
| 5362 | nullptr, T, E->getValueKind(), |
| 5363 | E->getObjectKind()); |
| 5364 | } |
| 5365 | |
| 5366 | Expr *ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 5367 | QualType T = Importer.Import(E->getType()); |
| 5368 | if (T.isNull()) |
| 5369 | return nullptr; |
| 5370 | |
| 5371 | Expr *ToCallee = Importer.Import(E->getCallee()); |
| 5372 | if (!ToCallee && E->getCallee()) |
| 5373 | return nullptr; |
| 5374 | |
| 5375 | unsigned NumArgs = E->getNumArgs(); |
| 5376 | |
| 5377 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); |
| 5378 | |
| 5379 | for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) { |
| 5380 | Expr *FromArg = E->getArg(ai); |
| 5381 | Expr *ToArg = Importer.Import(FromArg); |
| 5382 | if (!ToArg) |
| 5383 | return nullptr; |
| 5384 | ToArgs[ai] = ToArg; |
| 5385 | } |
| 5386 | |
| 5387 | Expr **ToArgs_Copied = new (Importer.getToContext()) |
| 5388 | Expr*[NumArgs]; |
| 5389 | |
| 5390 | for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) |
| 5391 | ToArgs_Copied[ai] = ToArgs[ai]; |
| 5392 | |
| 5393 | return new (Importer.getToContext()) |
| 5394 | CallExpr(Importer.getToContext(), ToCallee, |
Craig Topper | c005cc0 | 2015-09-27 03:44:08 +0000 | [diff] [blame] | 5395 | llvm::makeArrayRef(ToArgs_Copied, NumArgs), T, E->getValueKind(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5396 | Importer.Import(E->getRParenLoc())); |
| 5397 | } |
| 5398 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5399 | Expr *ASTNodeImporter::VisitInitListExpr(InitListExpr *ILE) { |
| 5400 | QualType T = Importer.Import(ILE->getType()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5401 | if (T.isNull()) |
| 5402 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5403 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5404 | llvm::SmallVector<Expr *, 4> Exprs(ILE->getNumInits()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5405 | if (ImportContainerChecked(ILE->inits(), Exprs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5406 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5407 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5408 | ASTContext &ToCtx = Importer.getToContext(); |
| 5409 | InitListExpr *To = new (ToCtx) InitListExpr( |
| 5410 | ToCtx, Importer.Import(ILE->getLBraceLoc()), |
| 5411 | Exprs, Importer.Import(ILE->getLBraceLoc())); |
| 5412 | To->setType(T); |
| 5413 | |
| 5414 | if (ILE->hasArrayFiller()) { |
| 5415 | Expr *Filler = Importer.Import(ILE->getArrayFiller()); |
| 5416 | if (!Filler) |
| 5417 | return nullptr; |
| 5418 | To->setArrayFiller(Filler); |
| 5419 | } |
| 5420 | |
| 5421 | if (FieldDecl *FromFD = ILE->getInitializedFieldInUnion()) { |
| 5422 | FieldDecl *ToFD = cast_or_null<FieldDecl>(Importer.Import(FromFD)); |
| 5423 | if (!ToFD) |
| 5424 | return nullptr; |
| 5425 | To->setInitializedFieldInUnion(ToFD); |
| 5426 | } |
| 5427 | |
| 5428 | if (InitListExpr *SyntForm = ILE->getSyntacticForm()) { |
| 5429 | InitListExpr *ToSyntForm = cast_or_null<InitListExpr>( |
| 5430 | Importer.Import(SyntForm)); |
| 5431 | if (!ToSyntForm) |
| 5432 | return nullptr; |
| 5433 | To->setSyntacticForm(ToSyntForm); |
| 5434 | } |
| 5435 | |
| 5436 | To->sawArrayRangeDesignator(ILE->hadArrayRangeDesignator()); |
| 5437 | To->setValueDependent(ILE->isValueDependent()); |
| 5438 | To->setInstantiationDependent(ILE->isInstantiationDependent()); |
| 5439 | |
| 5440 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5441 | } |
| 5442 | |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 5443 | Expr *ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 5444 | QualType ToType = Importer.Import(E->getType()); |
| 5445 | if (ToType.isNull()) |
| 5446 | return nullptr; |
| 5447 | |
| 5448 | Expr *ToCommon = Importer.Import(E->getCommonExpr()); |
| 5449 | if (!ToCommon && E->getCommonExpr()) |
| 5450 | return nullptr; |
| 5451 | |
| 5452 | Expr *ToSubExpr = Importer.Import(E->getSubExpr()); |
| 5453 | if (!ToSubExpr && E->getSubExpr()) |
| 5454 | return nullptr; |
| 5455 | |
| 5456 | return new (Importer.getToContext()) |
| 5457 | ArrayInitLoopExpr(ToType, ToCommon, ToSubExpr); |
| 5458 | } |
| 5459 | |
| 5460 | Expr *ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 5461 | QualType ToType = Importer.Import(E->getType()); |
| 5462 | if (ToType.isNull()) |
| 5463 | return nullptr; |
| 5464 | return new (Importer.getToContext()) ArrayInitIndexExpr(ToType); |
| 5465 | } |
| 5466 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 5467 | Expr *ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) { |
| 5468 | FieldDecl *ToField = llvm::dyn_cast_or_null<FieldDecl>( |
| 5469 | Importer.Import(DIE->getField())); |
| 5470 | if (!ToField && DIE->getField()) |
| 5471 | return nullptr; |
| 5472 | |
| 5473 | return CXXDefaultInitExpr::Create( |
| 5474 | Importer.getToContext(), Importer.Import(DIE->getLocStart()), ToField); |
| 5475 | } |
| 5476 | |
| 5477 | Expr *ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 5478 | QualType ToType = Importer.Import(E->getType()); |
| 5479 | if (ToType.isNull() && !E->getType().isNull()) |
| 5480 | return nullptr; |
| 5481 | ExprValueKind VK = E->getValueKind(); |
| 5482 | CastKind CK = E->getCastKind(); |
| 5483 | Expr *ToOp = Importer.Import(E->getSubExpr()); |
| 5484 | if (!ToOp && E->getSubExpr()) |
| 5485 | return nullptr; |
| 5486 | CXXCastPath BasePath; |
| 5487 | if (ImportCastPath(E, BasePath)) |
| 5488 | return nullptr; |
| 5489 | TypeSourceInfo *ToWritten = Importer.Import(E->getTypeInfoAsWritten()); |
| 5490 | SourceLocation ToOperatorLoc = Importer.Import(E->getOperatorLoc()); |
| 5491 | SourceLocation ToRParenLoc = Importer.Import(E->getRParenLoc()); |
| 5492 | SourceRange ToAngleBrackets = Importer.Import(E->getAngleBrackets()); |
| 5493 | |
| 5494 | if (isa<CXXStaticCastExpr>(E)) { |
| 5495 | return CXXStaticCastExpr::Create( |
| 5496 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 5497 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 5498 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 5499 | return CXXDynamicCastExpr::Create( |
| 5500 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 5501 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 5502 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 5503 | return CXXReinterpretCastExpr::Create( |
| 5504 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 5505 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 5506 | } else { |
| 5507 | return nullptr; |
| 5508 | } |
| 5509 | } |
| 5510 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5511 | |
| 5512 | Expr *ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
| 5513 | SubstNonTypeTemplateParmExpr *E) { |
| 5514 | QualType T = Importer.Import(E->getType()); |
| 5515 | if (T.isNull()) |
| 5516 | return nullptr; |
| 5517 | |
| 5518 | NonTypeTemplateParmDecl *Param = cast_or_null<NonTypeTemplateParmDecl>( |
| 5519 | Importer.Import(E->getParameter())); |
| 5520 | if (!Param) |
| 5521 | return nullptr; |
| 5522 | |
| 5523 | Expr *Replacement = Importer.Import(E->getReplacement()); |
| 5524 | if (!Replacement) |
| 5525 | return nullptr; |
| 5526 | |
| 5527 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
| 5528 | T, E->getValueKind(), Importer.Import(E->getExprLoc()), Param, |
| 5529 | Replacement); |
| 5530 | } |
| 5531 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 5532 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 5533 | CXXMethodDecl *FromMethod) { |
| 5534 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) |
| 5535 | ToMethod->addOverriddenMethod( |
| 5536 | cast<CXXMethodDecl>(Importer.Import(const_cast<CXXMethodDecl*>( |
| 5537 | FromOverriddenMethod)))); |
| 5538 | } |
| 5539 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 5540 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 5541 | ASTContext &FromContext, FileManager &FromFileManager, |
| 5542 | bool MinimalImport) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 5543 | : ToContext(ToContext), FromContext(FromContext), |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 5544 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 5545 | Minimal(MinimalImport), LastDiagFromFrom(false) |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 5546 | { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5547 | ImportedDecls[FromContext.getTranslationUnitDecl()] |
| 5548 | = ToContext.getTranslationUnitDecl(); |
| 5549 | } |
| 5550 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 5551 | ASTImporter::~ASTImporter() { } |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 5552 | |
| 5553 | QualType ASTImporter::Import(QualType FromT) { |
| 5554 | if (FromT.isNull()) |
| 5555 | return QualType(); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5556 | |
| 5557 | const Type *fromTy = FromT.getTypePtr(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 5558 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 5559 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5560 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
| 5561 | = ImportedTypes.find(fromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 5562 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5563 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 5564 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 5565 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 5566 | ASTNodeImporter Importer(*this); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5567 | QualType ToT = Importer.Visit(fromTy); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 5568 | if (ToT.isNull()) |
| 5569 | return ToT; |
| 5570 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 5571 | // Record the imported type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5572 | ImportedTypes[fromTy] = ToT.getTypePtr(); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 5573 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5574 | return ToContext.getQualifiedType(ToT, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 5575 | } |
| 5576 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5577 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 5578 | if (!FromTSI) |
| 5579 | return FromTSI; |
| 5580 | |
| 5581 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 5582 | // 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] | 5583 | QualType T = Import(FromTSI->getType()); |
| 5584 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5585 | return nullptr; |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 5586 | |
| 5587 | return ToContext.getTrivialTypeSourceInfo(T, |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 5588 | Import(FromTSI->getTypeLoc().getLocStart())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5589 | } |
| 5590 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5591 | Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) { |
| 5592 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
| 5593 | if (Pos != ImportedDecls.end()) { |
| 5594 | Decl *ToD = Pos->second; |
| 5595 | ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD); |
| 5596 | return ToD; |
| 5597 | } else { |
| 5598 | return nullptr; |
| 5599 | } |
| 5600 | } |
| 5601 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5602 | Decl *ASTImporter::Import(Decl *FromD) { |
| 5603 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5604 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5605 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 5606 | ASTNodeImporter Importer(*this); |
| 5607 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5608 | // Check whether we've already imported this declaration. |
| 5609 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 5610 | if (Pos != ImportedDecls.end()) { |
| 5611 | Decl *ToD = Pos->second; |
| 5612 | Importer.ImportDefinitionIfNeeded(FromD, ToD); |
| 5613 | return ToD; |
| 5614 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5615 | |
| 5616 | // Import the type |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5617 | Decl *ToD = Importer.Visit(FromD); |
| 5618 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5619 | return nullptr; |
| 5620 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5621 | // Record the imported declaration. |
| 5622 | ImportedDecls[FromD] = ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 5623 | |
| 5624 | if (TagDecl *FromTag = dyn_cast<TagDecl>(FromD)) { |
| 5625 | // Keep track of anonymous tags that have an associated typedef. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 5626 | if (FromTag->getTypedefNameForAnonDecl()) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 5627 | AnonTagsWithPendingTypedefs.push_back(FromTag); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 5628 | } else if (TypedefNameDecl *FromTypedef = dyn_cast<TypedefNameDecl>(FromD)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 5629 | // When we've finished transforming a typedef, see whether it was the |
| 5630 | // typedef for an anonymous tag. |
Craig Topper | 2341c0d | 2013-07-04 03:08:24 +0000 | [diff] [blame] | 5631 | for (SmallVectorImpl<TagDecl *>::iterator |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 5632 | FromTag = AnonTagsWithPendingTypedefs.begin(), |
| 5633 | FromTagEnd = AnonTagsWithPendingTypedefs.end(); |
| 5634 | FromTag != FromTagEnd; ++FromTag) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 5635 | if ((*FromTag)->getTypedefNameForAnonDecl() == FromTypedef) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 5636 | if (TagDecl *ToTag = cast_or_null<TagDecl>(Import(*FromTag))) { |
| 5637 | // We found the typedef for an anonymous tag; link them. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 5638 | ToTag->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(ToD)); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 5639 | AnonTagsWithPendingTypedefs.erase(FromTag); |
| 5640 | break; |
| 5641 | } |
| 5642 | } |
| 5643 | } |
| 5644 | } |
| 5645 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5646 | return ToD; |
| 5647 | } |
| 5648 | |
| 5649 | DeclContext *ASTImporter::ImportContext(DeclContext *FromDC) { |
| 5650 | if (!FromDC) |
| 5651 | return FromDC; |
| 5652 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 5653 | DeclContext *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 5654 | if (!ToDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5655 | return nullptr; |
| 5656 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 5657 | // When we're using a record/enum/Objective-C class/protocol as a context, we |
| 5658 | // need it to have a definition. |
| 5659 | if (RecordDecl *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
Douglas Gregor | 63db971 | 2012-01-25 01:13:20 +0000 | [diff] [blame] | 5660 | RecordDecl *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 5661 | if (ToRecord->isCompleteDefinition()) { |
| 5662 | // Do nothing. |
| 5663 | } else if (FromRecord->isCompleteDefinition()) { |
| 5664 | ASTNodeImporter(*this).ImportDefinition(FromRecord, ToRecord, |
| 5665 | ASTNodeImporter::IDK_Basic); |
| 5666 | } else { |
| 5667 | CompleteDecl(ToRecord); |
| 5668 | } |
| 5669 | } else if (EnumDecl *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 5670 | EnumDecl *FromEnum = cast<EnumDecl>(FromDC); |
| 5671 | if (ToEnum->isCompleteDefinition()) { |
| 5672 | // Do nothing. |
| 5673 | } else if (FromEnum->isCompleteDefinition()) { |
| 5674 | ASTNodeImporter(*this).ImportDefinition(FromEnum, ToEnum, |
| 5675 | ASTNodeImporter::IDK_Basic); |
| 5676 | } else { |
| 5677 | CompleteDecl(ToEnum); |
| 5678 | } |
| 5679 | } else if (ObjCInterfaceDecl *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 5680 | ObjCInterfaceDecl *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
| 5681 | if (ToClass->getDefinition()) { |
| 5682 | // Do nothing. |
| 5683 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
| 5684 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToClass, |
| 5685 | ASTNodeImporter::IDK_Basic); |
| 5686 | } else { |
| 5687 | CompleteDecl(ToClass); |
| 5688 | } |
| 5689 | } else if (ObjCProtocolDecl *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 5690 | ObjCProtocolDecl *FromProto = cast<ObjCProtocolDecl>(FromDC); |
| 5691 | if (ToProto->getDefinition()) { |
| 5692 | // Do nothing. |
| 5693 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
| 5694 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToProto, |
| 5695 | ASTNodeImporter::IDK_Basic); |
| 5696 | } else { |
| 5697 | CompleteDecl(ToProto); |
| 5698 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 5699 | } |
| 5700 | |
| 5701 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5702 | } |
| 5703 | |
| 5704 | Expr *ASTImporter::Import(Expr *FromE) { |
| 5705 | if (!FromE) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5706 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5707 | |
| 5708 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); |
| 5709 | } |
| 5710 | |
| 5711 | Stmt *ASTImporter::Import(Stmt *FromS) { |
| 5712 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5713 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5714 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5715 | // Check whether we've already imported this declaration. |
| 5716 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 5717 | if (Pos != ImportedStmts.end()) |
| 5718 | return Pos->second; |
| 5719 | |
| 5720 | // Import the type |
| 5721 | ASTNodeImporter Importer(*this); |
| 5722 | Stmt *ToS = Importer.Visit(FromS); |
| 5723 | if (!ToS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5724 | return nullptr; |
| 5725 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5726 | // Record the imported declaration. |
| 5727 | ImportedStmts[FromS] = ToS; |
| 5728 | return ToS; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5729 | } |
| 5730 | |
| 5731 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| 5732 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5733 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5734 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 5735 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); |
| 5736 | |
| 5737 | switch (FromNNS->getKind()) { |
| 5738 | case NestedNameSpecifier::Identifier: |
| 5739 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { |
| 5740 | return NestedNameSpecifier::Create(ToContext, prefix, II); |
| 5741 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5742 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 5743 | |
| 5744 | case NestedNameSpecifier::Namespace: |
| 5745 | if (NamespaceDecl *NS = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5746 | cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 5747 | return NestedNameSpecifier::Create(ToContext, prefix, NS); |
| 5748 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5749 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 5750 | |
| 5751 | case NestedNameSpecifier::NamespaceAlias: |
| 5752 | if (NamespaceAliasDecl *NSAD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5753 | cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 5754 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); |
| 5755 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5756 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 5757 | |
| 5758 | case NestedNameSpecifier::Global: |
| 5759 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 5760 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5761 | case NestedNameSpecifier::Super: |
| 5762 | if (CXXRecordDecl *RD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5763 | cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) { |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5764 | return NestedNameSpecifier::SuperSpecifier(ToContext, RD); |
| 5765 | } |
| 5766 | return nullptr; |
| 5767 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 5768 | case NestedNameSpecifier::TypeSpec: |
| 5769 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 5770 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); |
| 5771 | if (!T.isNull()) { |
| 5772 | bool bTemplate = FromNNS->getKind() == |
| 5773 | NestedNameSpecifier::TypeSpecWithTemplate; |
| 5774 | return NestedNameSpecifier::Create(ToContext, prefix, |
| 5775 | bTemplate, T.getTypePtr()); |
| 5776 | } |
| 5777 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5778 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 5779 | } |
| 5780 | |
| 5781 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5782 | } |
| 5783 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 5784 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5785 | // Copied from NestedNameSpecifier mostly. |
| 5786 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 5787 | NestedNameSpecifierLoc NNS = FromNNS; |
| 5788 | |
| 5789 | // Push each of the nested-name-specifiers's onto a stack for |
| 5790 | // serialization in reverse order. |
| 5791 | while (NNS) { |
| 5792 | NestedNames.push_back(NNS); |
| 5793 | NNS = NNS.getPrefix(); |
| 5794 | } |
| 5795 | |
| 5796 | NestedNameSpecifierLocBuilder Builder; |
| 5797 | |
| 5798 | while (!NestedNames.empty()) { |
| 5799 | NNS = NestedNames.pop_back_val(); |
| 5800 | NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier()); |
| 5801 | if (!Spec) |
| 5802 | return NestedNameSpecifierLoc(); |
| 5803 | |
| 5804 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| 5805 | switch (Kind) { |
| 5806 | case NestedNameSpecifier::Identifier: |
| 5807 | Builder.Extend(getToContext(), |
| 5808 | Spec->getAsIdentifier(), |
| 5809 | Import(NNS.getLocalBeginLoc()), |
| 5810 | Import(NNS.getLocalEndLoc())); |
| 5811 | break; |
| 5812 | |
| 5813 | case NestedNameSpecifier::Namespace: |
| 5814 | Builder.Extend(getToContext(), |
| 5815 | Spec->getAsNamespace(), |
| 5816 | Import(NNS.getLocalBeginLoc()), |
| 5817 | Import(NNS.getLocalEndLoc())); |
| 5818 | break; |
| 5819 | |
| 5820 | case NestedNameSpecifier::NamespaceAlias: |
| 5821 | Builder.Extend(getToContext(), |
| 5822 | Spec->getAsNamespaceAlias(), |
| 5823 | Import(NNS.getLocalBeginLoc()), |
| 5824 | Import(NNS.getLocalEndLoc())); |
| 5825 | break; |
| 5826 | |
| 5827 | case NestedNameSpecifier::TypeSpec: |
| 5828 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 5829 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| 5830 | QualType(Spec->getAsType(), 0)); |
| 5831 | Builder.Extend(getToContext(), |
| 5832 | Import(NNS.getLocalBeginLoc()), |
| 5833 | TSI->getTypeLoc(), |
| 5834 | Import(NNS.getLocalEndLoc())); |
| 5835 | break; |
| 5836 | } |
| 5837 | |
| 5838 | case NestedNameSpecifier::Global: |
| 5839 | Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc())); |
| 5840 | break; |
| 5841 | |
| 5842 | case NestedNameSpecifier::Super: { |
| 5843 | SourceRange ToRange = Import(NNS.getSourceRange()); |
| 5844 | Builder.MakeSuper(getToContext(), |
| 5845 | Spec->getAsRecordDecl(), |
| 5846 | ToRange.getBegin(), |
| 5847 | ToRange.getEnd()); |
| 5848 | } |
| 5849 | } |
| 5850 | } |
| 5851 | |
| 5852 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 5853 | } |
| 5854 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5855 | TemplateName ASTImporter::Import(TemplateName From) { |
| 5856 | switch (From.getKind()) { |
| 5857 | case TemplateName::Template: |
| 5858 | if (TemplateDecl *ToTemplate |
| 5859 | = cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
| 5860 | return TemplateName(ToTemplate); |
| 5861 | |
| 5862 | return TemplateName(); |
| 5863 | |
| 5864 | case TemplateName::OverloadedTemplate: { |
| 5865 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 5866 | UnresolvedSet<2> ToTemplates; |
| 5867 | for (OverloadedTemplateStorage::iterator I = FromStorage->begin(), |
| 5868 | E = FromStorage->end(); |
| 5869 | I != E; ++I) { |
| 5870 | if (NamedDecl *To = cast_or_null<NamedDecl>(Import(*I))) |
| 5871 | ToTemplates.addDecl(To); |
| 5872 | else |
| 5873 | return TemplateName(); |
| 5874 | } |
| 5875 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
| 5876 | ToTemplates.end()); |
| 5877 | } |
| 5878 | |
| 5879 | case TemplateName::QualifiedTemplate: { |
| 5880 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| 5881 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); |
| 5882 | if (!Qualifier) |
| 5883 | return TemplateName(); |
| 5884 | |
| 5885 | if (TemplateDecl *ToTemplate |
| 5886 | = cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
| 5887 | return ToContext.getQualifiedTemplateName(Qualifier, |
| 5888 | QTN->hasTemplateKeyword(), |
| 5889 | ToTemplate); |
| 5890 | |
| 5891 | return TemplateName(); |
| 5892 | } |
| 5893 | |
| 5894 | case TemplateName::DependentTemplate: { |
| 5895 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| 5896 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); |
| 5897 | if (!Qualifier) |
| 5898 | return TemplateName(); |
| 5899 | |
| 5900 | if (DTN->isIdentifier()) { |
| 5901 | return ToContext.getDependentTemplateName(Qualifier, |
| 5902 | Import(DTN->getIdentifier())); |
| 5903 | } |
| 5904 | |
| 5905 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); |
| 5906 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5907 | |
| 5908 | case TemplateName::SubstTemplateTemplateParm: { |
| 5909 | SubstTemplateTemplateParmStorage *subst |
| 5910 | = From.getAsSubstTemplateTemplateParm(); |
| 5911 | TemplateTemplateParmDecl *param |
| 5912 | = cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); |
| 5913 | if (!param) |
| 5914 | return TemplateName(); |
| 5915 | |
| 5916 | TemplateName replacement = Import(subst->getReplacement()); |
| 5917 | if (replacement.isNull()) return TemplateName(); |
| 5918 | |
| 5919 | return ToContext.getSubstTemplateTemplateParm(param, replacement); |
| 5920 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5921 | |
| 5922 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5923 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 5924 | = From.getAsSubstTemplateTemplateParmPack(); |
| 5925 | TemplateTemplateParmDecl *Param |
| 5926 | = cast_or_null<TemplateTemplateParmDecl>( |
| 5927 | Import(SubstPack->getParameterPack())); |
| 5928 | if (!Param) |
| 5929 | return TemplateName(); |
| 5930 | |
| 5931 | ASTNodeImporter Importer(*this); |
| 5932 | TemplateArgument ArgPack |
| 5933 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 5934 | if (ArgPack.isNull()) |
| 5935 | return TemplateName(); |
| 5936 | |
| 5937 | return ToContext.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 5938 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5939 | } |
| 5940 | |
| 5941 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5942 | } |
| 5943 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5944 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { |
| 5945 | if (FromLoc.isInvalid()) |
| 5946 | return SourceLocation(); |
| 5947 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 5948 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 5949 | |
Sean Callanan | 24c5fe6 | 2016-11-07 20:42:25 +0000 | [diff] [blame] | 5950 | // For now, map everything down to its file location, so that we |
Chandler Carruth | 2536641 | 2011-07-15 00:04:35 +0000 | [diff] [blame] | 5951 | // don't have to import macro expansions. |
| 5952 | // FIXME: Import macro expansions! |
Sean Callanan | 24c5fe6 | 2016-11-07 20:42:25 +0000 | [diff] [blame] | 5953 | FromLoc = FromSM.getFileLoc(FromLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 5954 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
| 5955 | SourceManager &ToSM = ToContext.getSourceManager(); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 5956 | FileID ToFileID = Import(Decomposed.first); |
| 5957 | if (ToFileID.isInvalid()) |
| 5958 | return SourceLocation(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5959 | SourceLocation ret = ToSM.getLocForStartOfFile(ToFileID) |
| 5960 | .getLocWithOffset(Decomposed.second); |
| 5961 | return ret; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5962 | } |
| 5963 | |
| 5964 | SourceRange ASTImporter::Import(SourceRange FromRange) { |
| 5965 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); |
| 5966 | } |
| 5967 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 5968 | FileID ASTImporter::Import(FileID FromID) { |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 5969 | llvm::DenseMap<FileID, FileID>::iterator Pos |
| 5970 | = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 5971 | if (Pos != ImportedFileIDs.end()) |
| 5972 | return Pos->second; |
| 5973 | |
| 5974 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 5975 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 5976 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Chandler Carruth | 2536641 | 2011-07-15 00:04:35 +0000 | [diff] [blame] | 5977 | assert(FromSLoc.isFile() && "Cannot handle macro expansions yet"); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 5978 | |
| 5979 | // Include location of this file. |
| 5980 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| 5981 | |
| 5982 | // Map the FileID for to the "to" source manager. |
| 5983 | FileID ToID; |
| 5984 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
Sean Callanan | 25d34af | 2015-04-30 00:44:21 +0000 | [diff] [blame] | 5985 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 5986 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 5987 | // disk again |
| 5988 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 5989 | // than mmap the files several times. |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 5990 | const FileEntry *Entry = ToFileManager.getFile(Cache->OrigEntry->getName()); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 5991 | if (!Entry) |
| 5992 | return FileID(); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 5993 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, |
| 5994 | FromSLoc.getFile().getFileCharacteristic()); |
| 5995 | } else { |
| 5996 | // FIXME: We want to re-use the existing MemoryBuffer! |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 5997 | const llvm::MemoryBuffer * |
| 5998 | FromBuf = Cache->getBuffer(FromContext.getDiagnostics(), FromSM); |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 5999 | std::unique_ptr<llvm::MemoryBuffer> ToBuf |
Chris Lattner | 58c7934 | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 6000 | = llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6001 | FromBuf->getBufferIdentifier()); |
David Blaikie | 50a5f97 | 2014-08-29 07:59:55 +0000 | [diff] [blame] | 6002 | ToID = ToSM.createFileID(std::move(ToBuf), |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 6003 | FromSLoc.getFile().getFileCharacteristic()); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6004 | } |
| 6005 | |
| 6006 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 6007 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6008 | return ToID; |
| 6009 | } |
| 6010 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6011 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { |
| 6012 | Expr *ToExpr = Import(From->getInit()); |
| 6013 | if (!ToExpr && From->getInit()) |
| 6014 | return nullptr; |
| 6015 | |
| 6016 | if (From->isBaseInitializer()) { |
| 6017 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 6018 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 6019 | return nullptr; |
| 6020 | |
| 6021 | return new (ToContext) CXXCtorInitializer( |
| 6022 | ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()), |
| 6023 | ToExpr, Import(From->getRParenLoc()), |
| 6024 | From->isPackExpansion() ? Import(From->getEllipsisLoc()) |
| 6025 | : SourceLocation()); |
| 6026 | } else if (From->isMemberInitializer()) { |
| 6027 | FieldDecl *ToField = |
| 6028 | llvm::cast_or_null<FieldDecl>(Import(From->getMember())); |
| 6029 | if (!ToField && From->getMember()) |
| 6030 | return nullptr; |
| 6031 | |
| 6032 | return new (ToContext) CXXCtorInitializer( |
| 6033 | ToContext, ToField, Import(From->getMemberLocation()), |
| 6034 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 6035 | } else if (From->isIndirectMemberInitializer()) { |
| 6036 | IndirectFieldDecl *ToIField = llvm::cast_or_null<IndirectFieldDecl>( |
| 6037 | Import(From->getIndirectMember())); |
| 6038 | if (!ToIField && From->getIndirectMember()) |
| 6039 | return nullptr; |
| 6040 | |
| 6041 | return new (ToContext) CXXCtorInitializer( |
| 6042 | ToContext, ToIField, Import(From->getMemberLocation()), |
| 6043 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 6044 | } else if (From->isDelegatingInitializer()) { |
| 6045 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 6046 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 6047 | return nullptr; |
| 6048 | |
| 6049 | return new (ToContext) |
| 6050 | CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()), |
| 6051 | ToExpr, Import(From->getRParenLoc())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6052 | } else { |
| 6053 | return nullptr; |
| 6054 | } |
| 6055 | } |
| 6056 | |
| 6057 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6058 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| 6059 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 6060 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 6061 | return Pos->second; |
| 6062 | |
| 6063 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| 6064 | Import(BaseSpec->getSourceRange()), |
| 6065 | BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 6066 | BaseSpec->getAccessSpecifierAsWritten(), |
| 6067 | Import(BaseSpec->getTypeSourceInfo()), |
| 6068 | Import(BaseSpec->getEllipsisLoc())); |
| 6069 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 6070 | return Imported; |
| 6071 | } |
| 6072 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 6073 | void ASTImporter::ImportDefinition(Decl *From) { |
| 6074 | Decl *To = Import(From); |
| 6075 | if (!To) |
| 6076 | return; |
| 6077 | |
| 6078 | if (DeclContext *FromDC = cast<DeclContext>(From)) { |
| 6079 | ASTNodeImporter Importer(*this); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 6080 | |
| 6081 | if (RecordDecl *ToRecord = dyn_cast<RecordDecl>(To)) { |
| 6082 | if (!ToRecord->getDefinition()) { |
| 6083 | Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 6084 | ASTNodeImporter::IDK_Everything); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 6085 | return; |
| 6086 | } |
| 6087 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6088 | |
| 6089 | if (EnumDecl *ToEnum = dyn_cast<EnumDecl>(To)) { |
| 6090 | if (!ToEnum->getDefinition()) { |
| 6091 | Importer.ImportDefinition(cast<EnumDecl>(FromDC), ToEnum, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6092 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6093 | return; |
| 6094 | } |
| 6095 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 6096 | |
| 6097 | if (ObjCInterfaceDecl *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
| 6098 | if (!ToIFace->getDefinition()) { |
| 6099 | Importer.ImportDefinition(cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6100 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 6101 | return; |
| 6102 | } |
| 6103 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6104 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 6105 | if (ObjCProtocolDecl *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
| 6106 | if (!ToProto->getDefinition()) { |
| 6107 | Importer.ImportDefinition(cast<ObjCProtocolDecl>(FromDC), ToProto, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6108 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 6109 | return; |
| 6110 | } |
| 6111 | } |
| 6112 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 6113 | Importer.ImportDeclContext(FromDC, true); |
| 6114 | } |
| 6115 | } |
| 6116 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6117 | DeclarationName ASTImporter::Import(DeclarationName FromName) { |
| 6118 | if (!FromName) |
| 6119 | return DeclarationName(); |
| 6120 | |
| 6121 | switch (FromName.getNameKind()) { |
| 6122 | case DeclarationName::Identifier: |
| 6123 | return Import(FromName.getAsIdentifierInfo()); |
| 6124 | |
| 6125 | case DeclarationName::ObjCZeroArgSelector: |
| 6126 | case DeclarationName::ObjCOneArgSelector: |
| 6127 | case DeclarationName::ObjCMultiArgSelector: |
| 6128 | return Import(FromName.getObjCSelector()); |
| 6129 | |
| 6130 | case DeclarationName::CXXConstructorName: { |
| 6131 | QualType T = Import(FromName.getCXXNameType()); |
| 6132 | if (T.isNull()) |
| 6133 | return DeclarationName(); |
| 6134 | |
| 6135 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 6136 | ToContext.getCanonicalType(T)); |
| 6137 | } |
| 6138 | |
| 6139 | case DeclarationName::CXXDestructorName: { |
| 6140 | QualType T = Import(FromName.getCXXNameType()); |
| 6141 | if (T.isNull()) |
| 6142 | return DeclarationName(); |
| 6143 | |
| 6144 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 6145 | ToContext.getCanonicalType(T)); |
| 6146 | } |
| 6147 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 6148 | case DeclarationName::CXXDeductionGuideName: { |
| 6149 | TemplateDecl *Template = cast_or_null<TemplateDecl>( |
| 6150 | Import(FromName.getCXXDeductionGuideTemplate())); |
| 6151 | if (!Template) |
| 6152 | return DeclarationName(); |
| 6153 | return ToContext.DeclarationNames.getCXXDeductionGuideName(Template); |
| 6154 | } |
| 6155 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6156 | case DeclarationName::CXXConversionFunctionName: { |
| 6157 | QualType T = Import(FromName.getCXXNameType()); |
| 6158 | if (T.isNull()) |
| 6159 | return DeclarationName(); |
| 6160 | |
| 6161 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 6162 | ToContext.getCanonicalType(T)); |
| 6163 | } |
| 6164 | |
| 6165 | case DeclarationName::CXXOperatorName: |
| 6166 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 6167 | FromName.getCXXOverloadedOperator()); |
| 6168 | |
| 6169 | case DeclarationName::CXXLiteralOperatorName: |
| 6170 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| 6171 | Import(FromName.getCXXLiteralIdentifier())); |
| 6172 | |
| 6173 | case DeclarationName::CXXUsingDirective: |
| 6174 | // FIXME: STATICS! |
| 6175 | return DeclarationName::getUsingDirectiveName(); |
| 6176 | } |
| 6177 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 6178 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6179 | } |
| 6180 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6181 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6182 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6183 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6184 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 6185 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 6186 | |
| 6187 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 6188 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 6189 | |
| 6190 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6191 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 6192 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 6193 | Selector ASTImporter::Import(Selector FromSel) { |
| 6194 | if (FromSel.isNull()) |
| 6195 | return Selector(); |
| 6196 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6197 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 6198 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 6199 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 6200 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 6201 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 6202 | } |
| 6203 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 6204 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 6205 | DeclContext *DC, |
| 6206 | unsigned IDNS, |
| 6207 | NamedDecl **Decls, |
| 6208 | unsigned NumDecls) { |
| 6209 | return Name; |
| 6210 | } |
| 6211 | |
| 6212 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 6213 | if (LastDiagFromFrom) |
| 6214 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 6215 | FromContext.getDiagnostics()); |
| 6216 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6217 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 6218 | } |
| 6219 | |
| 6220 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 6221 | if (!LastDiagFromFrom) |
| 6222 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 6223 | ToContext.getDiagnostics()); |
| 6224 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6225 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 6226 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 6227 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6228 | void ASTImporter::CompleteDecl (Decl *D) { |
| 6229 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
| 6230 | if (!ID->getDefinition()) |
| 6231 | ID->startDefinition(); |
| 6232 | } |
| 6233 | else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
| 6234 | if (!PD->getDefinition()) |
| 6235 | PD->startDefinition(); |
| 6236 | } |
| 6237 | else if (TagDecl *TD = dyn_cast<TagDecl>(D)) { |
| 6238 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 6239 | TD->startDefinition(); |
| 6240 | TD->setCompleteDefinition(true); |
| 6241 | } |
| 6242 | } |
| 6243 | else { |
| 6244 | assert (0 && "CompleteDecl called on a Decl that can't be completed"); |
| 6245 | } |
| 6246 | } |
| 6247 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 6248 | Decl *ASTImporter::Imported(Decl *From, Decl *To) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6249 | if (From->hasAttrs()) { |
| 6250 | for (Attr *FromAttr : From->getAttrs()) |
| 6251 | To->addAttr(FromAttr->clone(To->getASTContext())); |
| 6252 | } |
| 6253 | if (From->isUsed()) { |
| 6254 | To->setIsUsed(); |
| 6255 | } |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6256 | if (From->isImplicit()) { |
| 6257 | To->setImplicit(); |
| 6258 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 6259 | ImportedDecls[From] = To; |
| 6260 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 6261 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6262 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 6263 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 6264 | bool Complain) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6265 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6266 | = ImportedTypes.find(From.getTypePtr()); |
| 6267 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) |
| 6268 | return true; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 6269 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 6270 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
| 6271 | false, Complain); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 6272 | return Ctx.IsStructurallyEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6273 | } |