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); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 61 | QualType VisitUnresolvedUsingType(const UnresolvedUsingType *T); |
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 |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 80 | QualType VisitPackExpansionType(const PackExpansionType *T); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 81 | // FIXME: DependentTemplateSpecializationType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 82 | QualType VisitObjCInterfaceType(const ObjCInterfaceType *T); |
| 83 | QualType VisitObjCObjectType(const ObjCObjectType *T); |
| 84 | QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 85 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 86 | // Importing declarations |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 87 | bool ImportDeclParts(NamedDecl *D, DeclContext *&DC, |
| 88 | DeclContext *&LexicalDC, DeclarationName &Name, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 89 | NamedDecl *&ToD, SourceLocation &Loc); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 90 | void ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 91 | void ImportDeclarationNameLoc(const DeclarationNameInfo &From, |
| 92 | DeclarationNameInfo& To); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 93 | void ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 94 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 95 | bool ImportCastPath(CastExpr *E, CXXCastPath &Path); |
| 96 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 97 | typedef DesignatedInitExpr::Designator Designator; |
| 98 | Designator ImportDesignator(const Designator &D); |
| 99 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 100 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 101 | /// \brief What we should import from the definition. |
| 102 | enum ImportDefinitionKind { |
| 103 | /// \brief Import the default subset of the definition, which might be |
| 104 | /// nothing (if minimal import is set) or might be everything (if minimal |
| 105 | /// import is not set). |
| 106 | IDK_Default, |
| 107 | /// \brief Import everything. |
| 108 | IDK_Everything, |
| 109 | /// \brief Import only the bare bones needed to establish a valid |
| 110 | /// DeclContext. |
| 111 | IDK_Basic |
| 112 | }; |
| 113 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 114 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { |
| 115 | return IDK == IDK_Everything || |
| 116 | (IDK == IDK_Default && !Importer.isMinimalImport()); |
| 117 | } |
| 118 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 119 | bool ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 120 | ImportDefinitionKind Kind = IDK_Default); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 121 | bool ImportDefinition(VarDecl *From, VarDecl *To, |
| 122 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 123 | bool ImportDefinition(EnumDecl *From, EnumDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 124 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 125 | bool ImportDefinition(ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 126 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 127 | bool ImportDefinition(ObjCProtocolDecl *From, ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 128 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 129 | TemplateParameterList *ImportTemplateParameterList( |
| 130 | TemplateParameterList *Params); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 131 | TemplateArgument ImportTemplateArgument(const TemplateArgument &From); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 132 | Optional<TemplateArgumentLoc> ImportTemplateArgumentLoc( |
| 133 | const TemplateArgumentLoc &TALoc); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 134 | bool ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 135 | unsigned NumFromArgs, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 136 | SmallVectorImpl<TemplateArgument> &ToArgs); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 137 | template <typename InContainerTy> |
| 138 | bool ImportTemplateArgumentListInfo(const InContainerTy &Container, |
| 139 | TemplateArgumentListInfo &ToTAInfo); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 140 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, |
| 141 | bool Complain = true); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 142 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 143 | bool Complain = true); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 144 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 145 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 146 | bool IsStructuralMatch(FunctionTemplateDecl *From, |
| 147 | FunctionTemplateDecl *To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 148 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 149 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 150 | Decl *VisitDecl(Decl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 151 | Decl *VisitEmptyDecl(EmptyDecl *D); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 152 | Decl *VisitAccessSpecDecl(AccessSpecDecl *D); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 153 | Decl *VisitStaticAssertDecl(StaticAssertDecl *D); |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 154 | Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 155 | Decl *VisitNamespaceDecl(NamespaceDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 156 | Decl *VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 157 | Decl *VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 158 | Decl *VisitTypedefDecl(TypedefDecl *D); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 159 | Decl *VisitTypeAliasDecl(TypeAliasDecl *D); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 160 | Decl *VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 161 | Decl *VisitLabelDecl(LabelDecl *D); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 162 | Decl *VisitEnumDecl(EnumDecl *D); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 163 | Decl *VisitRecordDecl(RecordDecl *D); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 164 | Decl *VisitEnumConstantDecl(EnumConstantDecl *D); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 165 | Decl *VisitFunctionDecl(FunctionDecl *D); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 166 | Decl *VisitCXXMethodDecl(CXXMethodDecl *D); |
| 167 | Decl *VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 168 | Decl *VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 169 | Decl *VisitCXXConversionDecl(CXXConversionDecl *D); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 170 | Decl *VisitFieldDecl(FieldDecl *D); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 171 | Decl *VisitIndirectFieldDecl(IndirectFieldDecl *D); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 172 | Decl *VisitFriendDecl(FriendDecl *D); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 173 | Decl *VisitObjCIvarDecl(ObjCIvarDecl *D); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 174 | Decl *VisitVarDecl(VarDecl *D); |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 175 | Decl *VisitImplicitParamDecl(ImplicitParamDecl *D); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 176 | Decl *VisitParmVarDecl(ParmVarDecl *D); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 177 | Decl *VisitObjCMethodDecl(ObjCMethodDecl *D); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 178 | Decl *VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 179 | Decl *VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 180 | Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 181 | Decl *VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 182 | Decl *VisitUsingDecl(UsingDecl *D); |
| 183 | Decl *VisitUsingShadowDecl(UsingShadowDecl *D); |
| 184 | Decl *VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 185 | Decl *VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| 186 | Decl *VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
| 187 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 188 | |
| 189 | ObjCTypeParamList *ImportObjCTypeParamList(ObjCTypeParamList *list); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 190 | Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 191 | Decl *VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 192 | Decl *VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 193 | Decl *VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 194 | Decl *VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 195 | Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 196 | Decl *VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 197 | Decl *VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 198 | Decl *VisitClassTemplateDecl(ClassTemplateDecl *D); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 199 | Decl *VisitClassTemplateSpecializationDecl( |
| 200 | ClassTemplateSpecializationDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 201 | Decl *VisitVarTemplateDecl(VarTemplateDecl *D); |
| 202 | Decl *VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 203 | Decl *VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 204 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 205 | // Importing statements |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 206 | DeclGroupRef ImportDeclGroup(DeclGroupRef DG); |
| 207 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 208 | Stmt *VisitStmt(Stmt *S); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 209 | Stmt *VisitGCCAsmStmt(GCCAsmStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 210 | Stmt *VisitDeclStmt(DeclStmt *S); |
| 211 | Stmt *VisitNullStmt(NullStmt *S); |
| 212 | Stmt *VisitCompoundStmt(CompoundStmt *S); |
| 213 | Stmt *VisitCaseStmt(CaseStmt *S); |
| 214 | Stmt *VisitDefaultStmt(DefaultStmt *S); |
| 215 | Stmt *VisitLabelStmt(LabelStmt *S); |
| 216 | Stmt *VisitAttributedStmt(AttributedStmt *S); |
| 217 | Stmt *VisitIfStmt(IfStmt *S); |
| 218 | Stmt *VisitSwitchStmt(SwitchStmt *S); |
| 219 | Stmt *VisitWhileStmt(WhileStmt *S); |
| 220 | Stmt *VisitDoStmt(DoStmt *S); |
| 221 | Stmt *VisitForStmt(ForStmt *S); |
| 222 | Stmt *VisitGotoStmt(GotoStmt *S); |
| 223 | Stmt *VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 224 | Stmt *VisitContinueStmt(ContinueStmt *S); |
| 225 | Stmt *VisitBreakStmt(BreakStmt *S); |
| 226 | Stmt *VisitReturnStmt(ReturnStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 227 | // FIXME: MSAsmStmt |
| 228 | // FIXME: SEHExceptStmt |
| 229 | // FIXME: SEHFinallyStmt |
| 230 | // FIXME: SEHTryStmt |
| 231 | // FIXME: SEHLeaveStmt |
| 232 | // FIXME: CapturedStmt |
| 233 | Stmt *VisitCXXCatchStmt(CXXCatchStmt *S); |
| 234 | Stmt *VisitCXXTryStmt(CXXTryStmt *S); |
| 235 | Stmt *VisitCXXForRangeStmt(CXXForRangeStmt *S); |
| 236 | // FIXME: MSDependentExistsStmt |
| 237 | Stmt *VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); |
| 238 | Stmt *VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); |
| 239 | Stmt *VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); |
| 240 | Stmt *VisitObjCAtTryStmt(ObjCAtTryStmt *S); |
| 241 | Stmt *VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); |
| 242 | Stmt *VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); |
| 243 | Stmt *VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 244 | |
| 245 | // Importing expressions |
| 246 | Expr *VisitExpr(Expr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 247 | Expr *VisitVAArgExpr(VAArgExpr *E); |
| 248 | Expr *VisitGNUNullExpr(GNUNullExpr *E); |
| 249 | Expr *VisitPredefinedExpr(PredefinedExpr *E); |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 250 | Expr *VisitDeclRefExpr(DeclRefExpr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 251 | Expr *VisitImplicitValueInitExpr(ImplicitValueInitExpr *ILE); |
| 252 | Expr *VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 253 | Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 254 | Expr *VisitIntegerLiteral(IntegerLiteral *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 255 | Expr *VisitFloatingLiteral(FloatingLiteral *E); |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 256 | Expr *VisitCharacterLiteral(CharacterLiteral *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 257 | Expr *VisitStringLiteral(StringLiteral *E); |
| 258 | Expr *VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 259 | Expr *VisitAtomicExpr(AtomicExpr *E); |
| 260 | Expr *VisitAddrLabelExpr(AddrLabelExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 261 | Expr *VisitParenExpr(ParenExpr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 262 | Expr *VisitParenListExpr(ParenListExpr *E); |
| 263 | Expr *VisitStmtExpr(StmtExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 264 | Expr *VisitUnaryOperator(UnaryOperator *E); |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 265 | Expr *VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 266 | Expr *VisitBinaryOperator(BinaryOperator *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 267 | Expr *VisitConditionalOperator(ConditionalOperator *E); |
| 268 | Expr *VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 269 | Expr *VisitOpaqueValueExpr(OpaqueValueExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 270 | Expr *VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 271 | Expr *VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 272 | Expr *VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 273 | Expr *VisitCompoundAssignOperator(CompoundAssignOperator *E); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 274 | Expr *VisitImplicitCastExpr(ImplicitCastExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 275 | Expr *VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 276 | Expr *VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 277 | Expr *VisitCXXThrowExpr(CXXThrowExpr *E); |
| 278 | Expr *VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 279 | Expr *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 280 | Expr *VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 281 | Expr *VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 282 | Expr *VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE); |
| 283 | Expr *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 284 | Expr *VisitPackExpansionExpr(PackExpansionExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 285 | Expr *VisitCXXNewExpr(CXXNewExpr *CE); |
| 286 | Expr *VisitCXXDeleteExpr(CXXDeleteExpr *E); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 287 | Expr *VisitCXXConstructExpr(CXXConstructExpr *E); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 288 | Expr *VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 289 | Expr *VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 290 | Expr *VisitExprWithCleanups(ExprWithCleanups *EWC); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 291 | Expr *VisitCXXThisExpr(CXXThisExpr *E); |
| 292 | Expr *VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 293 | Expr *VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 294 | Expr *VisitMemberExpr(MemberExpr *E); |
| 295 | Expr *VisitCallExpr(CallExpr *E); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 296 | Expr *VisitInitListExpr(InitListExpr *E); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 297 | Expr *VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 298 | Expr *VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 299 | Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 300 | Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 301 | Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 302 | Expr *VisitTypeTraitExpr(TypeTraitExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 303 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 304 | |
| 305 | template<typename IIter, typename OIter> |
| 306 | void ImportArray(IIter Ibegin, IIter Iend, OIter Obegin) { |
| 307 | typedef typename std::remove_reference<decltype(*Obegin)>::type ItemT; |
| 308 | ASTImporter &ImporterRef = Importer; |
| 309 | std::transform(Ibegin, Iend, Obegin, |
| 310 | [&ImporterRef](ItemT From) -> ItemT { |
| 311 | return ImporterRef.Import(From); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 312 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | template<typename IIter, typename OIter> |
| 316 | bool ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
| 317 | typedef typename std::remove_reference<decltype(**Obegin)>::type ItemT; |
| 318 | ASTImporter &ImporterRef = Importer; |
| 319 | bool Failed = false; |
| 320 | std::transform(Ibegin, Iend, Obegin, |
| 321 | [&ImporterRef, &Failed](ItemT *From) -> ItemT * { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 322 | ItemT *To = cast_or_null<ItemT>( |
| 323 | ImporterRef.Import(From)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 324 | if (!To && From) |
| 325 | Failed = true; |
| 326 | return To; |
| 327 | }); |
| 328 | return Failed; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 329 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 330 | |
| 331 | template<typename InContainerTy, typename OutContainerTy> |
| 332 | bool ImportContainerChecked(const InContainerTy &InContainer, |
| 333 | OutContainerTy &OutContainer) { |
| 334 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), |
| 335 | OutContainer.begin()); |
| 336 | } |
| 337 | |
| 338 | template<typename InContainerTy, typename OIter> |
| 339 | bool ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
| 340 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 341 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 342 | |
| 343 | // Importing overrides. |
| 344 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 345 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 346 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 347 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 348 | //---------------------------------------------------------------------------- |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 349 | // Import Types |
| 350 | //---------------------------------------------------------------------------- |
| 351 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 352 | using namespace clang; |
| 353 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 354 | QualType ASTNodeImporter::VisitType(const Type *T) { |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 355 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 356 | << T->getTypeClassName(); |
| 357 | return QualType(); |
| 358 | } |
| 359 | |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 360 | QualType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 361 | QualType UnderlyingType = Importer.Import(T->getValueType()); |
| 362 | if(UnderlyingType.isNull()) |
| 363 | return QualType(); |
| 364 | |
| 365 | return Importer.getToContext().getAtomicType(UnderlyingType); |
| 366 | } |
| 367 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 368 | QualType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 369 | switch (T->getKind()) { |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 370 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 371 | case BuiltinType::Id: \ |
| 372 | return Importer.getToContext().SingletonId; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 373 | #include "clang/Basic/OpenCLImageTypes.def" |
John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 374 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 375 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 376 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 377 | #include "clang/AST/BuiltinTypes.def" |
| 378 | |
| 379 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 380 | // context supports C++. |
| 381 | |
| 382 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 383 | // context supports ObjC. |
| 384 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 385 | case BuiltinType::Char_U: |
| 386 | // The context we're importing from has an unsigned 'char'. If we're |
| 387 | // importing into a context with a signed 'char', translate to |
| 388 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 389 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 390 | return Importer.getToContext().UnsignedCharTy; |
| 391 | |
| 392 | return Importer.getToContext().CharTy; |
| 393 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 394 | case BuiltinType::Char_S: |
| 395 | // The context we're importing from has an unsigned 'char'. If we're |
| 396 | // importing into a context with a signed 'char', translate to |
| 397 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 398 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 399 | return Importer.getToContext().SignedCharTy; |
| 400 | |
| 401 | return Importer.getToContext().CharTy; |
| 402 | |
Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 403 | case BuiltinType::WChar_S: |
| 404 | case BuiltinType::WChar_U: |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 405 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 406 | // wchar_t? |
| 407 | return Importer.getToContext().WCharTy; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 408 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 409 | |
| 410 | llvm_unreachable("Invalid BuiltinType Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 413 | QualType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 414 | QualType OrigT = Importer.Import(T->getOriginalType()); |
| 415 | if (OrigT.isNull()) |
| 416 | return QualType(); |
| 417 | |
| 418 | return Importer.getToContext().getDecayedType(OrigT); |
| 419 | } |
| 420 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 421 | QualType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 422 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 423 | if (ToElementType.isNull()) |
| 424 | return QualType(); |
| 425 | |
| 426 | return Importer.getToContext().getComplexType(ToElementType); |
| 427 | } |
| 428 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 429 | QualType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 430 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 431 | if (ToPointeeType.isNull()) |
| 432 | return QualType(); |
| 433 | |
| 434 | return Importer.getToContext().getPointerType(ToPointeeType); |
| 435 | } |
| 436 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 437 | QualType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 438 | // FIXME: Check for blocks support in "to" context. |
| 439 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 440 | if (ToPointeeType.isNull()) |
| 441 | return QualType(); |
| 442 | |
| 443 | return Importer.getToContext().getBlockPointerType(ToPointeeType); |
| 444 | } |
| 445 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 446 | QualType |
| 447 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 448 | // FIXME: Check for C++ support in "to" context. |
| 449 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 450 | if (ToPointeeType.isNull()) |
| 451 | return QualType(); |
| 452 | |
| 453 | return Importer.getToContext().getLValueReferenceType(ToPointeeType); |
| 454 | } |
| 455 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 456 | QualType |
| 457 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 458 | // FIXME: Check for C++0x support in "to" context. |
| 459 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 460 | if (ToPointeeType.isNull()) |
| 461 | return QualType(); |
| 462 | |
| 463 | return Importer.getToContext().getRValueReferenceType(ToPointeeType); |
| 464 | } |
| 465 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 466 | QualType ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 467 | // FIXME: Check for C++ support in "to" context. |
| 468 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 469 | if (ToPointeeType.isNull()) |
| 470 | return QualType(); |
| 471 | |
| 472 | QualType ClassType = Importer.Import(QualType(T->getClass(), 0)); |
| 473 | return Importer.getToContext().getMemberPointerType(ToPointeeType, |
| 474 | ClassType.getTypePtr()); |
| 475 | } |
| 476 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 477 | QualType ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 478 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 479 | if (ToElementType.isNull()) |
| 480 | return QualType(); |
| 481 | |
| 482 | return Importer.getToContext().getConstantArrayType(ToElementType, |
| 483 | T->getSize(), |
| 484 | T->getSizeModifier(), |
| 485 | T->getIndexTypeCVRQualifiers()); |
| 486 | } |
| 487 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 488 | QualType |
| 489 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 490 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 491 | if (ToElementType.isNull()) |
| 492 | return QualType(); |
| 493 | |
| 494 | return Importer.getToContext().getIncompleteArrayType(ToElementType, |
| 495 | T->getSizeModifier(), |
| 496 | T->getIndexTypeCVRQualifiers()); |
| 497 | } |
| 498 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 499 | QualType ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 500 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 501 | if (ToElementType.isNull()) |
| 502 | return QualType(); |
| 503 | |
| 504 | Expr *Size = Importer.Import(T->getSizeExpr()); |
| 505 | if (!Size) |
| 506 | return QualType(); |
| 507 | |
| 508 | SourceRange Brackets = Importer.Import(T->getBracketsRange()); |
| 509 | return Importer.getToContext().getVariableArrayType(ToElementType, Size, |
| 510 | T->getSizeModifier(), |
| 511 | T->getIndexTypeCVRQualifiers(), |
| 512 | Brackets); |
| 513 | } |
| 514 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 515 | QualType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 516 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 517 | if (ToElementType.isNull()) |
| 518 | return QualType(); |
| 519 | |
| 520 | return Importer.getToContext().getVectorType(ToElementType, |
| 521 | T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 522 | T->getVectorKind()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 523 | } |
| 524 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 525 | QualType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 526 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 527 | if (ToElementType.isNull()) |
| 528 | return QualType(); |
| 529 | |
| 530 | return Importer.getToContext().getExtVectorType(ToElementType, |
| 531 | T->getNumElements()); |
| 532 | } |
| 533 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 534 | QualType |
| 535 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 536 | // FIXME: What happens if we're importing a function without a prototype |
| 537 | // into C++? Should we make it variadic? |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 538 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 539 | if (ToResultType.isNull()) |
| 540 | return QualType(); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 541 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 542 | return Importer.getToContext().getFunctionNoProtoType(ToResultType, |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 543 | T->getExtInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 544 | } |
| 545 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 546 | QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 547 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 548 | if (ToResultType.isNull()) |
| 549 | return QualType(); |
| 550 | |
| 551 | // Import argument types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 552 | SmallVector<QualType, 4> ArgTypes; |
Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 553 | for (const auto &A : T->param_types()) { |
| 554 | QualType ArgType = Importer.Import(A); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 555 | if (ArgType.isNull()) |
| 556 | return QualType(); |
| 557 | ArgTypes.push_back(ArgType); |
| 558 | } |
| 559 | |
| 560 | // Import exception types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 561 | SmallVector<QualType, 4> ExceptionTypes; |
Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 562 | for (const auto &E : T->exceptions()) { |
| 563 | QualType ExceptionType = Importer.Import(E); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 564 | if (ExceptionType.isNull()) |
| 565 | return QualType(); |
| 566 | ExceptionTypes.push_back(ExceptionType); |
| 567 | } |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 568 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 569 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 570 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 571 | |
| 572 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 573 | ToEPI.Variadic = FromEPI.Variadic; |
| 574 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 575 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 576 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 577 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 578 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
| 579 | ToEPI.ExceptionSpec.NoexceptExpr = |
| 580 | Importer.Import(FromEPI.ExceptionSpec.NoexceptExpr); |
| 581 | ToEPI.ExceptionSpec.SourceDecl = cast_or_null<FunctionDecl>( |
| 582 | Importer.Import(FromEPI.ExceptionSpec.SourceDecl)); |
| 583 | ToEPI.ExceptionSpec.SourceTemplate = cast_or_null<FunctionDecl>( |
| 584 | Importer.Import(FromEPI.ExceptionSpec.SourceTemplate)); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 585 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 586 | return Importer.getToContext().getFunctionType(ToResultType, ArgTypes, ToEPI); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 587 | } |
| 588 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 589 | QualType ASTNodeImporter::VisitUnresolvedUsingType( |
| 590 | const UnresolvedUsingType *T) { |
| 591 | UnresolvedUsingTypenameDecl *ToD = cast_or_null<UnresolvedUsingTypenameDecl>( |
| 592 | Importer.Import(T->getDecl())); |
| 593 | if (!ToD) |
| 594 | return QualType(); |
| 595 | |
| 596 | UnresolvedUsingTypenameDecl *ToPrevD = |
| 597 | cast_or_null<UnresolvedUsingTypenameDecl>( |
| 598 | Importer.Import(T->getDecl()->getPreviousDecl())); |
| 599 | if (!ToPrevD && T->getDecl()->getPreviousDecl()) |
| 600 | return QualType(); |
| 601 | |
| 602 | return Importer.getToContext().getTypeDeclType(ToD, ToPrevD); |
| 603 | } |
| 604 | |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 605 | QualType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 606 | QualType ToInnerType = Importer.Import(T->getInnerType()); |
| 607 | if (ToInnerType.isNull()) |
| 608 | return QualType(); |
| 609 | |
| 610 | return Importer.getToContext().getParenType(ToInnerType); |
| 611 | } |
| 612 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 613 | QualType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 614 | TypedefNameDecl *ToDecl |
| 615 | = dyn_cast_or_null<TypedefNameDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 616 | if (!ToDecl) |
| 617 | return QualType(); |
| 618 | |
| 619 | return Importer.getToContext().getTypeDeclType(ToDecl); |
| 620 | } |
| 621 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 622 | QualType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 623 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 624 | if (!ToExpr) |
| 625 | return QualType(); |
| 626 | |
| 627 | return Importer.getToContext().getTypeOfExprType(ToExpr); |
| 628 | } |
| 629 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 630 | QualType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 631 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 632 | if (ToUnderlyingType.isNull()) |
| 633 | return QualType(); |
| 634 | |
| 635 | return Importer.getToContext().getTypeOfType(ToUnderlyingType); |
| 636 | } |
| 637 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 638 | QualType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 639 | // FIXME: Make sure that the "to" context supports C++0x! |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 640 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 641 | if (!ToExpr) |
| 642 | return QualType(); |
| 643 | |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 644 | QualType UnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 645 | if (UnderlyingType.isNull()) |
| 646 | return QualType(); |
| 647 | |
| 648 | return Importer.getToContext().getDecltypeType(ToExpr, UnderlyingType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 649 | } |
| 650 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 651 | QualType ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 652 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 653 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 654 | if (ToBaseType.isNull() || ToUnderlyingType.isNull()) |
| 655 | return QualType(); |
| 656 | |
| 657 | return Importer.getToContext().getUnaryTransformType(ToBaseType, |
| 658 | ToUnderlyingType, |
| 659 | T->getUTTKind()); |
| 660 | } |
| 661 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 662 | QualType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 663 | // FIXME: Make sure that the "to" context supports C++11! |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 664 | QualType FromDeduced = T->getDeducedType(); |
| 665 | QualType ToDeduced; |
| 666 | if (!FromDeduced.isNull()) { |
| 667 | ToDeduced = Importer.Import(FromDeduced); |
| 668 | if (ToDeduced.isNull()) |
| 669 | return QualType(); |
| 670 | } |
| 671 | |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 672 | return Importer.getToContext().getAutoType(ToDeduced, T->getKeyword(), |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 673 | /*IsDependent*/false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 674 | } |
| 675 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 676 | QualType ASTNodeImporter::VisitInjectedClassNameType( |
| 677 | const InjectedClassNameType *T) { |
| 678 | CXXRecordDecl *D = cast_or_null<CXXRecordDecl>(Importer.Import(T->getDecl())); |
| 679 | if (!D) |
| 680 | return QualType(); |
| 681 | |
| 682 | QualType InjType = Importer.Import(T->getInjectedSpecializationType()); |
| 683 | if (InjType.isNull()) |
| 684 | return QualType(); |
| 685 | |
| 686 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 687 | // See comments in InjectedClassNameType definition for details |
| 688 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 689 | enum { |
| 690 | TypeAlignmentInBits = 4, |
| 691 | TypeAlignment = 1 << TypeAlignmentInBits |
| 692 | }; |
| 693 | |
| 694 | return QualType(new (Importer.getToContext(), TypeAlignment) |
| 695 | InjectedClassNameType(D, InjType), 0); |
| 696 | } |
| 697 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 698 | QualType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 699 | RecordDecl *ToDecl |
| 700 | = dyn_cast_or_null<RecordDecl>(Importer.Import(T->getDecl())); |
| 701 | if (!ToDecl) |
| 702 | return QualType(); |
| 703 | |
| 704 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 705 | } |
| 706 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 707 | QualType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 708 | EnumDecl *ToDecl |
| 709 | = dyn_cast_or_null<EnumDecl>(Importer.Import(T->getDecl())); |
| 710 | if (!ToDecl) |
| 711 | return QualType(); |
| 712 | |
| 713 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 714 | } |
| 715 | |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 716 | QualType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 717 | QualType FromModifiedType = T->getModifiedType(); |
| 718 | QualType FromEquivalentType = T->getEquivalentType(); |
| 719 | QualType ToModifiedType; |
| 720 | QualType ToEquivalentType; |
| 721 | |
| 722 | if (!FromModifiedType.isNull()) { |
| 723 | ToModifiedType = Importer.Import(FromModifiedType); |
| 724 | if (ToModifiedType.isNull()) |
| 725 | return QualType(); |
| 726 | } |
| 727 | if (!FromEquivalentType.isNull()) { |
| 728 | ToEquivalentType = Importer.Import(FromEquivalentType); |
| 729 | if (ToEquivalentType.isNull()) |
| 730 | return QualType(); |
| 731 | } |
| 732 | |
| 733 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
| 734 | ToModifiedType, ToEquivalentType); |
| 735 | } |
| 736 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 737 | |
| 738 | QualType ASTNodeImporter::VisitTemplateTypeParmType( |
| 739 | const TemplateTypeParmType *T) { |
| 740 | TemplateTypeParmDecl *ParmDecl = |
| 741 | cast_or_null<TemplateTypeParmDecl>(Importer.Import(T->getDecl())); |
| 742 | if (!ParmDecl && T->getDecl()) |
| 743 | return QualType(); |
| 744 | |
| 745 | return Importer.getToContext().getTemplateTypeParmType( |
| 746 | T->getDepth(), T->getIndex(), T->isParameterPack(), ParmDecl); |
| 747 | } |
| 748 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 749 | QualType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
| 750 | const SubstTemplateTypeParmType *T) { |
| 751 | const TemplateTypeParmType *Replaced = |
| 752 | cast_or_null<TemplateTypeParmType>(Importer.Import( |
| 753 | QualType(T->getReplacedParameter(), 0)).getTypePtr()); |
| 754 | if (!Replaced) |
| 755 | return QualType(); |
| 756 | |
| 757 | QualType Replacement = Importer.Import(T->getReplacementType()); |
| 758 | if (Replacement.isNull()) |
| 759 | return QualType(); |
| 760 | Replacement = Replacement.getCanonicalType(); |
| 761 | |
| 762 | return Importer.getToContext().getSubstTemplateTypeParmType( |
| 763 | Replaced, Replacement); |
| 764 | } |
| 765 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 766 | QualType ASTNodeImporter::VisitTemplateSpecializationType( |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 767 | const TemplateSpecializationType *T) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 768 | TemplateName ToTemplate = Importer.Import(T->getTemplateName()); |
| 769 | if (ToTemplate.isNull()) |
| 770 | return QualType(); |
| 771 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 772 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 773 | if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
| 774 | return QualType(); |
| 775 | |
| 776 | QualType ToCanonType; |
| 777 | if (!QualType(T, 0).isCanonical()) { |
| 778 | QualType FromCanonType |
| 779 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
| 780 | ToCanonType =Importer.Import(FromCanonType); |
| 781 | if (ToCanonType.isNull()) |
| 782 | return QualType(); |
| 783 | } |
| 784 | return Importer.getToContext().getTemplateSpecializationType(ToTemplate, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 785 | ToTemplateArgs, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 786 | ToCanonType); |
| 787 | } |
| 788 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 789 | QualType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 790 | NestedNameSpecifier *ToQualifier = nullptr; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 791 | // Note: the qualifier in an ElaboratedType is optional. |
| 792 | if (T->getQualifier()) { |
| 793 | ToQualifier = Importer.Import(T->getQualifier()); |
| 794 | if (!ToQualifier) |
| 795 | return QualType(); |
| 796 | } |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 797 | |
| 798 | QualType ToNamedType = Importer.Import(T->getNamedType()); |
| 799 | if (ToNamedType.isNull()) |
| 800 | return QualType(); |
| 801 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 802 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
| 803 | ToQualifier, ToNamedType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 804 | } |
| 805 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 806 | QualType ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 807 | QualType Pattern = Importer.Import(T->getPattern()); |
| 808 | if (Pattern.isNull()) |
| 809 | return QualType(); |
| 810 | |
| 811 | return Importer.getToContext().getPackExpansionType(Pattern, |
| 812 | T->getNumExpansions()); |
| 813 | } |
| 814 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 815 | QualType ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 816 | ObjCInterfaceDecl *Class |
| 817 | = dyn_cast_or_null<ObjCInterfaceDecl>(Importer.Import(T->getDecl())); |
| 818 | if (!Class) |
| 819 | return QualType(); |
| 820 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 821 | return Importer.getToContext().getObjCInterfaceType(Class); |
| 822 | } |
| 823 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 824 | QualType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 825 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 826 | if (ToBaseType.isNull()) |
| 827 | return QualType(); |
| 828 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 829 | SmallVector<QualType, 4> TypeArgs; |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 830 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 831 | QualType ImportedTypeArg = Importer.Import(TypeArg); |
| 832 | if (ImportedTypeArg.isNull()) |
| 833 | return QualType(); |
| 834 | |
| 835 | TypeArgs.push_back(ImportedTypeArg); |
| 836 | } |
| 837 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 838 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 839 | for (auto *P : T->quals()) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 840 | ObjCProtocolDecl *Protocol |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 841 | = dyn_cast_or_null<ObjCProtocolDecl>(Importer.Import(P)); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 842 | if (!Protocol) |
| 843 | return QualType(); |
| 844 | Protocols.push_back(Protocol); |
| 845 | } |
| 846 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 847 | return Importer.getToContext().getObjCObjectType(ToBaseType, TypeArgs, |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 848 | Protocols, |
| 849 | T->isKindOfTypeAsWritten()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 850 | } |
| 851 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 852 | QualType |
| 853 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 854 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 855 | if (ToPointeeType.isNull()) |
| 856 | return QualType(); |
| 857 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 858 | return Importer.getToContext().getObjCObjectPointerType(ToPointeeType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 859 | } |
| 860 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 861 | //---------------------------------------------------------------------------- |
| 862 | // Import Declarations |
| 863 | //---------------------------------------------------------------------------- |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 864 | bool ASTNodeImporter::ImportDeclParts(NamedDecl *D, DeclContext *&DC, |
| 865 | DeclContext *&LexicalDC, |
| 866 | DeclarationName &Name, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 867 | NamedDecl *&ToD, |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 868 | SourceLocation &Loc) { |
| 869 | // Import the context of this declaration. |
| 870 | DC = Importer.ImportContext(D->getDeclContext()); |
| 871 | if (!DC) |
| 872 | return true; |
| 873 | |
| 874 | LexicalDC = DC; |
| 875 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 876 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 877 | if (!LexicalDC) |
| 878 | return true; |
| 879 | } |
| 880 | |
| 881 | // Import the name of this declaration. |
| 882 | Name = Importer.Import(D->getDeclName()); |
| 883 | if (D->getDeclName() && !Name) |
| 884 | return true; |
| 885 | |
| 886 | // Import the location of this declaration. |
| 887 | Loc = Importer.Import(D->getLocation()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 888 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 889 | return false; |
| 890 | } |
| 891 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 892 | void ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
| 893 | if (!FromD) |
| 894 | return; |
| 895 | |
| 896 | if (!ToD) { |
| 897 | ToD = Importer.Import(FromD); |
| 898 | if (!ToD) |
| 899 | return; |
| 900 | } |
| 901 | |
| 902 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 903 | if (RecordDecl *ToRecord = cast_or_null<RecordDecl>(ToD)) { |
Sean Callanan | 19dfc93 | 2013-01-11 23:17:47 +0000 | [diff] [blame] | 904 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && !ToRecord->getDefinition()) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 905 | ImportDefinition(FromRecord, ToRecord); |
| 906 | } |
| 907 | } |
| 908 | return; |
| 909 | } |
| 910 | |
| 911 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 912 | if (EnumDecl *ToEnum = cast_or_null<EnumDecl>(ToD)) { |
| 913 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
| 914 | ImportDefinition(FromEnum, ToEnum); |
| 915 | } |
| 916 | } |
| 917 | return; |
| 918 | } |
| 919 | } |
| 920 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 921 | void |
| 922 | ASTNodeImporter::ImportDeclarationNameLoc(const DeclarationNameInfo &From, |
| 923 | DeclarationNameInfo& To) { |
| 924 | // NOTE: To.Name and To.Loc are already imported. |
| 925 | // We only have to import To.LocInfo. |
| 926 | switch (To.getName().getNameKind()) { |
| 927 | case DeclarationName::Identifier: |
| 928 | case DeclarationName::ObjCZeroArgSelector: |
| 929 | case DeclarationName::ObjCOneArgSelector: |
| 930 | case DeclarationName::ObjCMultiArgSelector: |
| 931 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 932 | case DeclarationName::CXXDeductionGuideName: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 933 | return; |
| 934 | |
| 935 | case DeclarationName::CXXOperatorName: { |
| 936 | SourceRange Range = From.getCXXOperatorNameRange(); |
| 937 | To.setCXXOperatorNameRange(Importer.Import(Range)); |
| 938 | return; |
| 939 | } |
| 940 | case DeclarationName::CXXLiteralOperatorName: { |
| 941 | SourceLocation Loc = From.getCXXLiteralOperatorNameLoc(); |
| 942 | To.setCXXLiteralOperatorNameLoc(Importer.Import(Loc)); |
| 943 | return; |
| 944 | } |
| 945 | case DeclarationName::CXXConstructorName: |
| 946 | case DeclarationName::CXXDestructorName: |
| 947 | case DeclarationName::CXXConversionFunctionName: { |
| 948 | TypeSourceInfo *FromTInfo = From.getNamedTypeInfo(); |
| 949 | To.setNamedTypeInfo(Importer.Import(FromTInfo)); |
| 950 | return; |
| 951 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 952 | } |
Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 953 | llvm_unreachable("Unknown name kind."); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 954 | } |
| 955 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 956 | void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 957 | if (Importer.isMinimalImport() && !ForceImport) { |
Sean Callanan | 81d577c | 2011-07-22 23:46:03 +0000 | [diff] [blame] | 958 | Importer.ImportContext(FromDC); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 959 | return; |
| 960 | } |
| 961 | |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 962 | for (auto *From : FromDC->decls()) |
| 963 | Importer.Import(From); |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 964 | } |
| 965 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 966 | bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 967 | ImportDefinitionKind Kind) { |
| 968 | if (To->getDefinition() || To->isBeingDefined()) { |
| 969 | if (Kind == IDK_Everything) |
| 970 | ImportDeclContext(From, /*ForceImport=*/true); |
| 971 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 972 | return false; |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 973 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 974 | |
| 975 | To->startDefinition(); |
| 976 | |
| 977 | // Add base classes. |
| 978 | if (CXXRecordDecl *ToCXX = dyn_cast<CXXRecordDecl>(To)) { |
| 979 | CXXRecordDecl *FromCXX = cast<CXXRecordDecl>(From); |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 980 | |
| 981 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 982 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 983 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 984 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 985 | ToData.Aggregate = FromData.Aggregate; |
| 986 | ToData.PlainOldData = FromData.PlainOldData; |
| 987 | ToData.Empty = FromData.Empty; |
| 988 | ToData.Polymorphic = FromData.Polymorphic; |
| 989 | ToData.Abstract = FromData.Abstract; |
| 990 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
| 991 | ToData.HasNoNonEmptyBases = FromData.HasNoNonEmptyBases; |
| 992 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 993 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 994 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 995 | ToData.HasMutableFields = FromData.HasMutableFields; |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 996 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 997 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 998 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 999 | ToData.HasUninitializedReferenceMember |
| 1000 | = FromData.HasUninitializedReferenceMember; |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1001 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1002 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 1003 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1004 | ToData.NeedOverloadResolutionForCopyConstructor |
| 1005 | = FromData.NeedOverloadResolutionForCopyConstructor; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1006 | ToData.NeedOverloadResolutionForMoveConstructor |
| 1007 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 1008 | ToData.NeedOverloadResolutionForMoveAssignment |
| 1009 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 1010 | ToData.NeedOverloadResolutionForDestructor |
| 1011 | = FromData.NeedOverloadResolutionForDestructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1012 | ToData.DefaultedCopyConstructorIsDeleted |
| 1013 | = FromData.DefaultedCopyConstructorIsDeleted; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1014 | ToData.DefaultedMoveConstructorIsDeleted |
| 1015 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 1016 | ToData.DefaultedMoveAssignmentIsDeleted |
| 1017 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 1018 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1019 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 1020 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1021 | ToData.HasConstexprNonCopyMoveConstructor |
| 1022 | = FromData.HasConstexprNonCopyMoveConstructor; |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1023 | ToData.HasDefaultedDefaultConstructor |
| 1024 | = FromData.HasDefaultedDefaultConstructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1025 | ToData.CanPassInRegisters = FromData.CanPassInRegisters; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1026 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 1027 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1028 | ToData.HasConstexprDefaultConstructor |
| 1029 | = FromData.HasConstexprDefaultConstructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1030 | ToData.HasNonLiteralTypeFieldsOrBases |
| 1031 | = FromData.HasNonLiteralTypeFieldsOrBases; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1032 | // ComputedVisibleConversions not imported. |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1033 | ToData.UserProvidedDefaultConstructor |
| 1034 | = FromData.UserProvidedDefaultConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1035 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1036 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 1037 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 1038 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 1039 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 1040 | ToData.ImplicitCopyAssignmentHasConstParam |
| 1041 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 1042 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 1043 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 1044 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 1045 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1046 | ToData.IsLambda = FromData.IsLambda; |
| 1047 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1048 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1049 | for (const auto &Base1 : FromCXX->bases()) { |
| 1050 | QualType T = Importer.Import(Base1.getType()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1051 | if (T.isNull()) |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1052 | return true; |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1053 | |
| 1054 | SourceLocation EllipsisLoc; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1055 | if (Base1.isPackExpansion()) |
| 1056 | EllipsisLoc = Importer.Import(Base1.getEllipsisLoc()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1057 | |
| 1058 | // Ensure that we have a definition for the base. |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1059 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1060 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1061 | Bases.push_back( |
| 1062 | new (Importer.getToContext()) |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1063 | CXXBaseSpecifier(Importer.Import(Base1.getSourceRange()), |
| 1064 | Base1.isVirtual(), |
| 1065 | Base1.isBaseOfClass(), |
| 1066 | Base1.getAccessSpecifierAsWritten(), |
| 1067 | Importer.Import(Base1.getTypeSourceInfo()), |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1068 | EllipsisLoc)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1069 | } |
| 1070 | if (!Bases.empty()) |
Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1071 | ToCXX->setBases(Bases.data(), Bases.size()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1074 | if (shouldForceImportDeclContext(Kind)) |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1075 | ImportDeclContext(From, /*ForceImport=*/true); |
| 1076 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1077 | To->completeDefinition(); |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1078 | return false; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1081 | bool ASTNodeImporter::ImportDefinition(VarDecl *From, VarDecl *To, |
| 1082 | ImportDefinitionKind Kind) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1083 | if (To->getAnyInitializer()) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1084 | return false; |
| 1085 | |
| 1086 | // FIXME: Can we really import any initializer? Alternatively, we could force |
| 1087 | // ourselves to import every declaration of a variable and then only use |
| 1088 | // getInit() here. |
| 1089 | To->setInit(Importer.Import(const_cast<Expr *>(From->getAnyInitializer()))); |
| 1090 | |
| 1091 | // FIXME: Other bits to merge? |
| 1092 | |
| 1093 | return false; |
| 1094 | } |
| 1095 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1096 | bool ASTNodeImporter::ImportDefinition(EnumDecl *From, EnumDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1097 | ImportDefinitionKind Kind) { |
| 1098 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1099 | if (Kind == IDK_Everything) |
| 1100 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1101 | return false; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1102 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1103 | |
| 1104 | To->startDefinition(); |
| 1105 | |
| 1106 | QualType T = Importer.Import(Importer.getFromContext().getTypeDeclType(From)); |
| 1107 | if (T.isNull()) |
| 1108 | return true; |
| 1109 | |
| 1110 | QualType ToPromotionType = Importer.Import(From->getPromotionType()); |
| 1111 | if (ToPromotionType.isNull()) |
| 1112 | return true; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1113 | |
| 1114 | if (shouldForceImportDeclContext(Kind)) |
| 1115 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1116 | |
| 1117 | // FIXME: we might need to merge the number of positive or negative bits |
| 1118 | // if the enumerator lists don't match. |
| 1119 | To->completeDefinition(T, ToPromotionType, |
| 1120 | From->getNumPositiveBits(), |
| 1121 | From->getNumNegativeBits()); |
| 1122 | return false; |
| 1123 | } |
| 1124 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1125 | TemplateParameterList *ASTNodeImporter::ImportTemplateParameterList( |
| 1126 | TemplateParameterList *Params) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1127 | SmallVector<NamedDecl *, 4> ToParams(Params->size()); |
| 1128 | if (ImportContainerChecked(*Params, ToParams)) |
| 1129 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1130 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1131 | Expr *ToRequiresClause; |
| 1132 | if (Expr *const R = Params->getRequiresClause()) { |
| 1133 | ToRequiresClause = Importer.Import(R); |
| 1134 | if (!ToRequiresClause) |
| 1135 | return nullptr; |
| 1136 | } else { |
| 1137 | ToRequiresClause = nullptr; |
| 1138 | } |
| 1139 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1140 | return TemplateParameterList::Create(Importer.getToContext(), |
| 1141 | Importer.Import(Params->getTemplateLoc()), |
| 1142 | Importer.Import(Params->getLAngleLoc()), |
David Majnemer | 902f8c6 | 2015-12-27 07:16:27 +0000 | [diff] [blame] | 1143 | ToParams, |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1144 | Importer.Import(Params->getRAngleLoc()), |
| 1145 | ToRequiresClause); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1146 | } |
| 1147 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1148 | TemplateArgument |
| 1149 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1150 | switch (From.getKind()) { |
| 1151 | case TemplateArgument::Null: |
| 1152 | return TemplateArgument(); |
| 1153 | |
| 1154 | case TemplateArgument::Type: { |
| 1155 | QualType ToType = Importer.Import(From.getAsType()); |
| 1156 | if (ToType.isNull()) |
| 1157 | return TemplateArgument(); |
| 1158 | return TemplateArgument(ToType); |
| 1159 | } |
| 1160 | |
| 1161 | case TemplateArgument::Integral: { |
| 1162 | QualType ToType = Importer.Import(From.getIntegralType()); |
| 1163 | if (ToType.isNull()) |
| 1164 | return TemplateArgument(); |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 1165 | return TemplateArgument(From, ToType); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1168 | case TemplateArgument::Declaration: { |
David Blaikie | 3c7dd6b | 2014-10-22 19:54:16 +0000 | [diff] [blame] | 1169 | ValueDecl *To = cast_or_null<ValueDecl>(Importer.Import(From.getAsDecl())); |
| 1170 | QualType ToType = Importer.Import(From.getParamTypeForDecl()); |
| 1171 | if (!To || ToType.isNull()) |
| 1172 | return TemplateArgument(); |
| 1173 | return TemplateArgument(To, ToType); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | case TemplateArgument::NullPtr: { |
| 1177 | QualType ToType = Importer.Import(From.getNullPtrType()); |
| 1178 | if (ToType.isNull()) |
| 1179 | return TemplateArgument(); |
| 1180 | return TemplateArgument(ToType, /*isNullPtr*/true); |
| 1181 | } |
| 1182 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1183 | case TemplateArgument::Template: { |
| 1184 | TemplateName ToTemplate = Importer.Import(From.getAsTemplate()); |
| 1185 | if (ToTemplate.isNull()) |
| 1186 | return TemplateArgument(); |
| 1187 | |
| 1188 | return TemplateArgument(ToTemplate); |
| 1189 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1190 | |
| 1191 | case TemplateArgument::TemplateExpansion: { |
| 1192 | TemplateName ToTemplate |
| 1193 | = Importer.Import(From.getAsTemplateOrTemplatePattern()); |
| 1194 | if (ToTemplate.isNull()) |
| 1195 | return TemplateArgument(); |
| 1196 | |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 1197 | return TemplateArgument(ToTemplate, From.getNumTemplateExpansions()); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1200 | case TemplateArgument::Expression: |
| 1201 | if (Expr *ToExpr = Importer.Import(From.getAsExpr())) |
| 1202 | return TemplateArgument(ToExpr); |
| 1203 | return TemplateArgument(); |
| 1204 | |
| 1205 | case TemplateArgument::Pack: { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1206 | SmallVector<TemplateArgument, 2> ToPack; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1207 | ToPack.reserve(From.pack_size()); |
| 1208 | if (ImportTemplateArguments(From.pack_begin(), From.pack_size(), ToPack)) |
| 1209 | return TemplateArgument(); |
Benjamin Kramer | cce6347 | 2015-08-05 09:40:22 +0000 | [diff] [blame] | 1210 | |
| 1211 | return TemplateArgument( |
| 1212 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | llvm_unreachable("Invalid template argument kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1219 | Optional<TemplateArgumentLoc> |
| 1220 | ASTNodeImporter::ImportTemplateArgumentLoc(const TemplateArgumentLoc &TALoc) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1221 | TemplateArgument Arg = ImportTemplateArgument(TALoc.getArgument()); |
| 1222 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 1223 | TemplateArgumentLocInfo ToInfo; |
| 1224 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 1225 | Expr *E = Importer.Import(FromInfo.getAsExpr()); |
| 1226 | ToInfo = TemplateArgumentLocInfo(E); |
| 1227 | if (!E) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1228 | return None; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1229 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 1230 | if (TypeSourceInfo *TSI = Importer.Import(FromInfo.getAsTypeSourceInfo())) |
| 1231 | ToInfo = TemplateArgumentLocInfo(TSI); |
| 1232 | else |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1233 | return None; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1234 | } else { |
| 1235 | ToInfo = TemplateArgumentLocInfo( |
| 1236 | Importer.Import(FromInfo.getTemplateQualifierLoc()), |
| 1237 | Importer.Import(FromInfo.getTemplateNameLoc()), |
| 1238 | Importer.Import(FromInfo.getTemplateEllipsisLoc())); |
| 1239 | } |
| 1240 | return TemplateArgumentLoc(Arg, ToInfo); |
| 1241 | } |
| 1242 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1243 | bool ASTNodeImporter::ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 1244 | unsigned NumFromArgs, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1245 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1246 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
| 1247 | TemplateArgument To = ImportTemplateArgument(FromArgs[I]); |
| 1248 | if (To.isNull() && !FromArgs[I].isNull()) |
| 1249 | return true; |
| 1250 | |
| 1251 | ToArgs.push_back(To); |
| 1252 | } |
| 1253 | |
| 1254 | return false; |
| 1255 | } |
| 1256 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1257 | template <typename InContainerTy> |
| 1258 | bool ASTNodeImporter::ImportTemplateArgumentListInfo( |
| 1259 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 1260 | for (const auto &FromLoc : Container) { |
| 1261 | if (auto ToLoc = ImportTemplateArgumentLoc(FromLoc)) |
| 1262 | ToTAInfo.addArgument(*ToLoc); |
| 1263 | else |
| 1264 | return true; |
| 1265 | } |
| 1266 | return false; |
| 1267 | } |
| 1268 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1269 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1270 | RecordDecl *ToRecord, bool Complain) { |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1271 | // Eliminate a potential failure point where we attempt to re-import |
| 1272 | // something we're trying to import while completing ToRecord. |
| 1273 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 1274 | if (ToOrigin) { |
| 1275 | RecordDecl *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
| 1276 | if (ToOriginRecord) |
| 1277 | ToRecord = ToOriginRecord; |
| 1278 | } |
| 1279 | |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1280 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1281 | ToRecord->getASTContext(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1282 | Importer.getNonEquivalentDecls(), |
| 1283 | false, Complain); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1284 | return Ctx.IsStructurallyEquivalent(FromRecord, ToRecord); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1285 | } |
| 1286 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1287 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 1288 | bool Complain) { |
| 1289 | StructuralEquivalenceContext Ctx( |
| 1290 | Importer.getFromContext(), Importer.getToContext(), |
| 1291 | Importer.getNonEquivalentDecls(), false, Complain); |
| 1292 | return Ctx.IsStructurallyEquivalent(FromVar, ToVar); |
| 1293 | } |
| 1294 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1295 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1296 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1297 | Importer.getToContext(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1298 | Importer.getNonEquivalentDecls()); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1299 | return Ctx.IsStructurallyEquivalent(FromEnum, ToEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1300 | } |
| 1301 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1302 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 1303 | FunctionTemplateDecl *To) { |
| 1304 | StructuralEquivalenceContext Ctx( |
| 1305 | Importer.getFromContext(), Importer.getToContext(), |
| 1306 | Importer.getNonEquivalentDecls(), false, false); |
| 1307 | return Ctx.IsStructurallyEquivalent(From, To); |
| 1308 | } |
| 1309 | |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1310 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
| 1311 | EnumConstantDecl *ToEC) |
| 1312 | { |
| 1313 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 1314 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 1315 | |
| 1316 | return FromVal.isSigned() == ToVal.isSigned() && |
| 1317 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 1318 | FromVal == ToVal; |
| 1319 | } |
| 1320 | |
| 1321 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1322 | ClassTemplateDecl *To) { |
| 1323 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1324 | Importer.getToContext(), |
| 1325 | Importer.getNonEquivalentDecls()); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1326 | return Ctx.IsStructurallyEquivalent(From, To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1327 | } |
| 1328 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1329 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 1330 | VarTemplateDecl *To) { |
| 1331 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1332 | Importer.getToContext(), |
| 1333 | Importer.getNonEquivalentDecls()); |
| 1334 | return Ctx.IsStructurallyEquivalent(From, To); |
| 1335 | } |
| 1336 | |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1337 | Decl *ASTNodeImporter::VisitDecl(Decl *D) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 1338 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1339 | << D->getDeclKindName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1340 | return nullptr; |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1341 | } |
| 1342 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1343 | Decl *ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 1344 | // Import the context of this declaration. |
| 1345 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1346 | if (!DC) |
| 1347 | return nullptr; |
| 1348 | |
| 1349 | DeclContext *LexicalDC = DC; |
| 1350 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 1351 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 1352 | if (!LexicalDC) |
| 1353 | return nullptr; |
| 1354 | } |
| 1355 | |
| 1356 | // Import the location of this declaration. |
| 1357 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1358 | |
| 1359 | EmptyDecl *ToD = EmptyDecl::Create(Importer.getToContext(), DC, Loc); |
| 1360 | ToD->setLexicalDeclContext(LexicalDC); |
| 1361 | Importer.Imported(D, ToD); |
| 1362 | LexicalDC->addDeclInternal(ToD); |
| 1363 | return ToD; |
| 1364 | } |
| 1365 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 1366 | Decl *ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 1367 | TranslationUnitDecl *ToD = |
| 1368 | Importer.getToContext().getTranslationUnitDecl(); |
| 1369 | |
| 1370 | Importer.Imported(D, ToD); |
| 1371 | |
| 1372 | return ToD; |
| 1373 | } |
| 1374 | |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1375 | Decl *ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 1376 | |
| 1377 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1378 | SourceLocation ColonLoc = Importer.Import(D->getColonLoc()); |
| 1379 | |
| 1380 | // Import the context of this declaration. |
| 1381 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1382 | if (!DC) |
| 1383 | return nullptr; |
| 1384 | |
| 1385 | AccessSpecDecl *accessSpecDecl |
| 1386 | = AccessSpecDecl::Create(Importer.getToContext(), D->getAccess(), |
| 1387 | DC, Loc, ColonLoc); |
| 1388 | |
| 1389 | if (!accessSpecDecl) |
| 1390 | return nullptr; |
| 1391 | |
| 1392 | // Lexical DeclContext and Semantic DeclContext |
| 1393 | // is always the same for the accessSpec. |
| 1394 | accessSpecDecl->setLexicalDeclContext(DC); |
| 1395 | DC->addDeclInternal(accessSpecDecl); |
| 1396 | |
| 1397 | return accessSpecDecl; |
| 1398 | } |
| 1399 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1400 | Decl *ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 1401 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1402 | if (!DC) |
| 1403 | return nullptr; |
| 1404 | |
| 1405 | DeclContext *LexicalDC = DC; |
| 1406 | |
| 1407 | // Import the location of this declaration. |
| 1408 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1409 | |
| 1410 | Expr *AssertExpr = Importer.Import(D->getAssertExpr()); |
| 1411 | if (!AssertExpr) |
| 1412 | return nullptr; |
| 1413 | |
| 1414 | StringLiteral *FromMsg = D->getMessage(); |
| 1415 | StringLiteral *ToMsg = cast_or_null<StringLiteral>(Importer.Import(FromMsg)); |
| 1416 | if (!ToMsg && FromMsg) |
| 1417 | return nullptr; |
| 1418 | |
| 1419 | StaticAssertDecl *ToD = StaticAssertDecl::Create( |
| 1420 | Importer.getToContext(), DC, Loc, AssertExpr, ToMsg, |
| 1421 | Importer.Import(D->getRParenLoc()), D->isFailed()); |
| 1422 | |
| 1423 | ToD->setLexicalDeclContext(LexicalDC); |
| 1424 | LexicalDC->addDeclInternal(ToD); |
| 1425 | Importer.Imported(D, ToD); |
| 1426 | return ToD; |
| 1427 | } |
| 1428 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1429 | Decl *ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
| 1430 | // Import the major distinguishing characteristics of this namespace. |
| 1431 | DeclContext *DC, *LexicalDC; |
| 1432 | DeclarationName Name; |
| 1433 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1434 | NamedDecl *ToD; |
| 1435 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1436 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1437 | if (ToD) |
| 1438 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1439 | |
| 1440 | NamespaceDecl *MergeWithNamespace = nullptr; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1441 | if (!Name) { |
| 1442 | // This is an anonymous namespace. Adopt an existing anonymous |
| 1443 | // namespace if we can. |
| 1444 | // FIXME: Not testable. |
| 1445 | if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| 1446 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 1447 | else |
| 1448 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 1449 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1450 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1451 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1452 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1453 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1454 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1455 | continue; |
| 1456 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1457 | if (NamespaceDecl *FoundNS = dyn_cast<NamespaceDecl>(FoundDecls[I])) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1458 | MergeWithNamespace = FoundNS; |
| 1459 | ConflictingDecls.clear(); |
| 1460 | break; |
| 1461 | } |
| 1462 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1463 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | if (!ConflictingDecls.empty()) { |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 1467 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1468 | ConflictingDecls.data(), |
| 1469 | ConflictingDecls.size()); |
| 1470 | } |
| 1471 | } |
| 1472 | |
| 1473 | // Create the "to" namespace, if needed. |
| 1474 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 1475 | if (!ToNamespace) { |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 1476 | ToNamespace = NamespaceDecl::Create(Importer.getToContext(), DC, |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1477 | D->isInline(), |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 1478 | Importer.Import(D->getLocStart()), |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1479 | Loc, Name.getAsIdentifierInfo(), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1480 | /*PrevDecl=*/nullptr); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1481 | ToNamespace->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1482 | LexicalDC->addDeclInternal(ToNamespace); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1483 | |
| 1484 | // If this is an anonymous namespace, register it as the anonymous |
| 1485 | // namespace within its context. |
| 1486 | if (!Name) { |
| 1487 | if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| 1488 | TU->setAnonymousNamespace(ToNamespace); |
| 1489 | else |
| 1490 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 1491 | } |
| 1492 | } |
| 1493 | Importer.Imported(D, ToNamespace); |
| 1494 | |
| 1495 | ImportDeclContext(D); |
| 1496 | |
| 1497 | return ToNamespace; |
| 1498 | } |
| 1499 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1500 | Decl *ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| 1501 | // Import the major distinguishing characteristics of this namespace. |
| 1502 | DeclContext *DC, *LexicalDC; |
| 1503 | DeclarationName Name; |
| 1504 | SourceLocation Loc; |
| 1505 | NamedDecl *LookupD; |
| 1506 | if (ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 1507 | return nullptr; |
| 1508 | if (LookupD) |
| 1509 | return LookupD; |
| 1510 | |
| 1511 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 1512 | |
| 1513 | NamespaceDecl *TargetDecl = cast_or_null<NamespaceDecl>( |
| 1514 | Importer.Import(D->getNamespace())); |
| 1515 | if (!TargetDecl) |
| 1516 | return nullptr; |
| 1517 | |
| 1518 | IdentifierInfo *ToII = Importer.Import(D->getIdentifier()); |
| 1519 | if (!ToII) |
| 1520 | return nullptr; |
| 1521 | |
| 1522 | NestedNameSpecifierLoc ToQLoc = Importer.Import(D->getQualifierLoc()); |
| 1523 | if (D->getQualifierLoc() && !ToQLoc) |
| 1524 | return nullptr; |
| 1525 | |
| 1526 | NamespaceAliasDecl *ToD = NamespaceAliasDecl::Create( |
| 1527 | Importer.getToContext(), DC, Importer.Import(D->getNamespaceLoc()), |
| 1528 | Importer.Import(D->getAliasLoc()), ToII, ToQLoc, |
| 1529 | Importer.Import(D->getTargetNameLoc()), TargetDecl); |
| 1530 | |
| 1531 | ToD->setLexicalDeclContext(LexicalDC); |
| 1532 | Importer.Imported(D, ToD); |
| 1533 | LexicalDC->addDeclInternal(ToD); |
| 1534 | |
| 1535 | return ToD; |
| 1536 | } |
| 1537 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1538 | Decl *ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1539 | // Import the major distinguishing characteristics of this typedef. |
| 1540 | DeclContext *DC, *LexicalDC; |
| 1541 | DeclarationName Name; |
| 1542 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1543 | NamedDecl *ToD; |
| 1544 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1545 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1546 | if (ToD) |
| 1547 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1548 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1549 | // If this typedef is not in block scope, determine whether we've |
| 1550 | // seen a typedef with the same name (that we can merge with) or any |
| 1551 | // other entity by that name (which name lookup could conflict with). |
| 1552 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1553 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1554 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1555 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1556 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1557 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1558 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1559 | continue; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1560 | if (TypedefNameDecl *FoundTypedef = |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1561 | dyn_cast<TypedefNameDecl>(FoundDecls[I])) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1562 | if (Importer.IsStructurallyEquivalent(D->getUnderlyingType(), |
| 1563 | FoundTypedef->getUnderlyingType())) |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1564 | return Importer.Imported(D, FoundTypedef); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1565 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1566 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1567 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1568 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1569 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1570 | if (!ConflictingDecls.empty()) { |
| 1571 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1572 | ConflictingDecls.data(), |
| 1573 | ConflictingDecls.size()); |
| 1574 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1575 | return nullptr; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1576 | } |
| 1577 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1578 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1579 | // Import the underlying type of this typedef; |
| 1580 | QualType T = Importer.Import(D->getUnderlyingType()); |
| 1581 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1582 | return nullptr; |
| 1583 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1584 | // Create the new typedef node. |
| 1585 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 1586 | SourceLocation StartL = Importer.Import(D->getLocStart()); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1587 | TypedefNameDecl *ToTypedef; |
| 1588 | if (IsAlias) |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 1589 | ToTypedef = TypeAliasDecl::Create(Importer.getToContext(), DC, |
| 1590 | StartL, Loc, |
| 1591 | Name.getAsIdentifierInfo(), |
| 1592 | TInfo); |
| 1593 | else |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1594 | ToTypedef = TypedefDecl::Create(Importer.getToContext(), DC, |
| 1595 | StartL, Loc, |
| 1596 | Name.getAsIdentifierInfo(), |
| 1597 | TInfo); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1598 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1599 | ToTypedef->setAccess(D->getAccess()); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1600 | ToTypedef->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1601 | Importer.Imported(D, ToTypedef); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1602 | LexicalDC->addDeclInternal(ToTypedef); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1603 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1604 | return ToTypedef; |
| 1605 | } |
| 1606 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1607 | Decl *ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
| 1608 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 1609 | } |
| 1610 | |
| 1611 | Decl *ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| 1612 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 1613 | } |
| 1614 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1615 | Decl *ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| 1616 | // Import the major distinguishing characteristics of this typedef. |
| 1617 | DeclContext *DC, *LexicalDC; |
| 1618 | DeclarationName Name; |
| 1619 | SourceLocation Loc; |
| 1620 | NamedDecl *ToD; |
| 1621 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 1622 | return nullptr; |
| 1623 | if (ToD) |
| 1624 | return ToD; |
| 1625 | |
| 1626 | // If this typedef is not in block scope, determine whether we've |
| 1627 | // seen a typedef with the same name (that we can merge with) or any |
| 1628 | // other entity by that name (which name lookup could conflict with). |
| 1629 | if (!DC->isFunctionOrMethod()) { |
| 1630 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 1631 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 1632 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 1633 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
| 1634 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1635 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
| 1636 | continue; |
| 1637 | if (auto *FoundAlias = |
| 1638 | dyn_cast<TypeAliasTemplateDecl>(FoundDecls[I])) |
| 1639 | return Importer.Imported(D, FoundAlias); |
| 1640 | ConflictingDecls.push_back(FoundDecls[I]); |
| 1641 | } |
| 1642 | |
| 1643 | if (!ConflictingDecls.empty()) { |
| 1644 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1645 | ConflictingDecls.data(), |
| 1646 | ConflictingDecls.size()); |
| 1647 | if (!Name) |
| 1648 | return nullptr; |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | TemplateParameterList *Params = ImportTemplateParameterList( |
| 1653 | D->getTemplateParameters()); |
| 1654 | if (!Params) |
| 1655 | return nullptr; |
| 1656 | |
| 1657 | NamedDecl *TemplDecl = cast_or_null<NamedDecl>( |
| 1658 | Importer.Import(D->getTemplatedDecl())); |
| 1659 | if (!TemplDecl) |
| 1660 | return nullptr; |
| 1661 | |
| 1662 | TypeAliasTemplateDecl *ToAlias = TypeAliasTemplateDecl::Create( |
| 1663 | Importer.getToContext(), DC, Loc, Name, Params, TemplDecl); |
| 1664 | |
| 1665 | ToAlias->setAccess(D->getAccess()); |
| 1666 | ToAlias->setLexicalDeclContext(LexicalDC); |
| 1667 | Importer.Imported(D, ToAlias); |
| 1668 | LexicalDC->addDeclInternal(ToAlias); |
| 1669 | return ToD; |
| 1670 | } |
| 1671 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1672 | Decl *ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
| 1673 | // Import the major distinguishing characteristics of this label. |
| 1674 | DeclContext *DC, *LexicalDC; |
| 1675 | DeclarationName Name; |
| 1676 | SourceLocation Loc; |
| 1677 | NamedDecl *ToD; |
| 1678 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 1679 | return nullptr; |
| 1680 | if (ToD) |
| 1681 | return ToD; |
| 1682 | |
| 1683 | assert(LexicalDC->isFunctionOrMethod()); |
| 1684 | |
| 1685 | LabelDecl *ToLabel = D->isGnuLocal() |
| 1686 | ? LabelDecl::Create(Importer.getToContext(), |
| 1687 | DC, Importer.Import(D->getLocation()), |
| 1688 | Name.getAsIdentifierInfo(), |
| 1689 | Importer.Import(D->getLocStart())) |
| 1690 | : LabelDecl::Create(Importer.getToContext(), |
| 1691 | DC, Importer.Import(D->getLocation()), |
| 1692 | Name.getAsIdentifierInfo()); |
| 1693 | Importer.Imported(D, ToLabel); |
| 1694 | |
| 1695 | LabelStmt *Label = cast_or_null<LabelStmt>(Importer.Import(D->getStmt())); |
| 1696 | if (!Label) |
| 1697 | return nullptr; |
| 1698 | |
| 1699 | ToLabel->setStmt(Label); |
| 1700 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 1701 | LexicalDC->addDeclInternal(ToLabel); |
| 1702 | return ToLabel; |
| 1703 | } |
| 1704 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1705 | Decl *ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
| 1706 | // Import the major distinguishing characteristics of this enum. |
| 1707 | DeclContext *DC, *LexicalDC; |
| 1708 | DeclarationName Name; |
| 1709 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1710 | NamedDecl *ToD; |
| 1711 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1712 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1713 | if (ToD) |
| 1714 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1715 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1716 | // Figure out what enum name we're looking for. |
| 1717 | unsigned IDNS = Decl::IDNS_Tag; |
| 1718 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1719 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 1720 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1721 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1722 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1723 | IDNS |= Decl::IDNS_Ordinary; |
| 1724 | |
| 1725 | // We may already have an enum of the same name; try to find and match it. |
| 1726 | if (!DC->isFunctionOrMethod() && SearchName) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1727 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1728 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 1729 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1730 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1731 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1732 | continue; |
| 1733 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1734 | Decl *Found = FoundDecls[I]; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1735 | if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1736 | if (const TagType *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| 1737 | Found = Tag->getDecl(); |
| 1738 | } |
| 1739 | |
| 1740 | if (EnumDecl *FoundEnum = dyn_cast<EnumDecl>(Found)) { |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1741 | if (IsStructuralMatch(D, FoundEnum)) |
| 1742 | return Importer.Imported(D, FoundEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1743 | } |
| 1744 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1745 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | if (!ConflictingDecls.empty()) { |
| 1749 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1750 | ConflictingDecls.data(), |
| 1751 | ConflictingDecls.size()); |
| 1752 | } |
| 1753 | } |
| 1754 | |
| 1755 | // Create the enum declaration. |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 1756 | EnumDecl *D2 = EnumDecl::Create(Importer.getToContext(), DC, |
| 1757 | Importer.Import(D->getLocStart()), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1758 | Loc, Name.getAsIdentifierInfo(), nullptr, |
Abramo Bagnara | 0e05e24 | 2010-12-03 18:54:17 +0000 | [diff] [blame] | 1759 | D->isScoped(), D->isScopedUsingClassTag(), |
| 1760 | D->isFixed()); |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 1761 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 1762 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1763 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1764 | D2->setLexicalDeclContext(LexicalDC); |
| 1765 | Importer.Imported(D, D2); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1766 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1767 | |
| 1768 | // Import the integer type. |
| 1769 | QualType ToIntegerType = Importer.Import(D->getIntegerType()); |
| 1770 | if (ToIntegerType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1771 | return nullptr; |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1772 | D2->setIntegerType(ToIntegerType); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1773 | |
| 1774 | // Import the definition |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 1775 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1776 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1777 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1778 | return D2; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1779 | } |
| 1780 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1781 | Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
| 1782 | // If this record has a definition in the translation unit we're coming from, |
| 1783 | // but this particular declaration is not that definition, import the |
| 1784 | // definition and map to that. |
Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 1785 | TagDecl *Definition = D->getDefinition(); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1786 | if (Definition && Definition != D) { |
| 1787 | Decl *ImportedDef = Importer.Import(Definition); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1788 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1789 | return nullptr; |
| 1790 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1791 | return Importer.Imported(D, ImportedDef); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | // Import the major distinguishing characteristics of this record. |
| 1795 | DeclContext *DC, *LexicalDC; |
| 1796 | DeclarationName Name; |
| 1797 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1798 | NamedDecl *ToD; |
| 1799 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1800 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1801 | if (ToD) |
| 1802 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1803 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1804 | // Figure out what structure name we're looking for. |
| 1805 | unsigned IDNS = Decl::IDNS_Tag; |
| 1806 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1807 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 1808 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1809 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1810 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1811 | IDNS |= Decl::IDNS_Ordinary; |
| 1812 | |
| 1813 | // 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] | 1814 | RecordDecl *AdoptDecl = nullptr; |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 1815 | RecordDecl *PrevDecl = nullptr; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1816 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1817 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1818 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 1819 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 1820 | |
| 1821 | if (!FoundDecls.empty()) { |
| 1822 | // We're going to have to compare D against potentially conflicting Decls, so complete it. |
| 1823 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 1824 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 1825 | } |
| 1826 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1827 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1828 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1829 | continue; |
| 1830 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1831 | Decl *Found = FoundDecls[I]; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1832 | if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1833 | if (const TagType *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| 1834 | Found = Tag->getDecl(); |
| 1835 | } |
| 1836 | |
| 1837 | if (RecordDecl *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
Gabor Horvath | 3b392bb | 2017-04-03 21:06:45 +0000 | [diff] [blame] | 1838 | if (D->isAnonymousStructOrUnion() && |
| 1839 | FoundRecord->isAnonymousStructOrUnion()) { |
| 1840 | // If both anonymous structs/unions are in a record context, make sure |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 1841 | // they occur in the same location in the context records. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1842 | if (Optional<unsigned> Index1 = |
| 1843 | StructuralEquivalenceContext::findUntaggedStructOrUnionIndex( |
| 1844 | D)) { |
| 1845 | if (Optional<unsigned> Index2 = StructuralEquivalenceContext:: |
Sean Callanan | 488f861 | 2016-07-14 19:53:44 +0000 | [diff] [blame] | 1846 | findUntaggedStructOrUnionIndex(FoundRecord)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 1847 | if (*Index1 != *Index2) |
| 1848 | continue; |
| 1849 | } |
| 1850 | } |
| 1851 | } |
| 1852 | |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 1853 | PrevDecl = FoundRecord; |
| 1854 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1855 | if (RecordDecl *FoundDef = FoundRecord->getDefinition()) { |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1856 | if ((SearchName && !D->isCompleteDefinition()) |
| 1857 | || (D->isCompleteDefinition() && |
| 1858 | D->isAnonymousStructOrUnion() |
| 1859 | == FoundDef->isAnonymousStructOrUnion() && |
| 1860 | IsStructuralMatch(D, FoundDef))) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1861 | // The record types structurally match, or the "from" translation |
| 1862 | // unit only had a forward declaration anyway; call it the same |
| 1863 | // function. |
| 1864 | // FIXME: For C++, we should also merge methods here. |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1865 | return Importer.Imported(D, FoundDef); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1866 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1867 | } else if (!D->isCompleteDefinition()) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1868 | // We have a forward declaration of this type, so adopt that forward |
| 1869 | // declaration rather than building a new one. |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 1870 | |
| 1871 | // If one or both can be completed from external storage then try one |
| 1872 | // last time to complete and compare them before doing this. |
| 1873 | |
| 1874 | if (FoundRecord->hasExternalLexicalStorage() && |
| 1875 | !FoundRecord->isCompleteDefinition()) |
| 1876 | FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord); |
| 1877 | if (D->hasExternalLexicalStorage()) |
| 1878 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 1879 | |
| 1880 | if (FoundRecord->isCompleteDefinition() && |
| 1881 | D->isCompleteDefinition() && |
| 1882 | !IsStructuralMatch(D, FoundRecord)) |
| 1883 | continue; |
| 1884 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1885 | AdoptDecl = FoundRecord; |
| 1886 | continue; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1887 | } else if (!SearchName) { |
| 1888 | continue; |
| 1889 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1890 | } |
| 1891 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1892 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1893 | } |
| 1894 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1895 | if (!ConflictingDecls.empty() && SearchName) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1896 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1897 | ConflictingDecls.data(), |
| 1898 | ConflictingDecls.size()); |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | // Create the record declaration. |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1903 | RecordDecl *D2 = AdoptDecl; |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 1904 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1905 | if (!D2) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 1906 | CXXRecordDecl *D2CXX = nullptr; |
| 1907 | if (CXXRecordDecl *DCXX = llvm::dyn_cast<CXXRecordDecl>(D)) { |
| 1908 | if (DCXX->isLambda()) { |
| 1909 | TypeSourceInfo *TInfo = Importer.Import(DCXX->getLambdaTypeInfo()); |
| 1910 | D2CXX = CXXRecordDecl::CreateLambda(Importer.getToContext(), |
| 1911 | DC, TInfo, Loc, |
| 1912 | DCXX->isDependentLambda(), |
| 1913 | DCXX->isGenericLambda(), |
| 1914 | DCXX->getLambdaCaptureDefault()); |
| 1915 | Decl *CDecl = Importer.Import(DCXX->getLambdaContextDecl()); |
| 1916 | if (DCXX->getLambdaContextDecl() && !CDecl) |
| 1917 | return nullptr; |
Sean Callanan | 041cceb | 2016-05-14 05:43:57 +0000 | [diff] [blame] | 1918 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), CDecl); |
| 1919 | } else if (DCXX->isInjectedClassName()) { |
| 1920 | // We have to be careful to do a similar dance to the one in |
| 1921 | // Sema::ActOnStartCXXMemberDeclarations |
| 1922 | CXXRecordDecl *const PrevDecl = nullptr; |
| 1923 | const bool DelayTypeCreation = true; |
| 1924 | D2CXX = CXXRecordDecl::Create( |
| 1925 | Importer.getToContext(), D->getTagKind(), DC, StartLoc, Loc, |
| 1926 | Name.getAsIdentifierInfo(), PrevDecl, DelayTypeCreation); |
| 1927 | Importer.getToContext().getTypeDeclType( |
| 1928 | D2CXX, llvm::dyn_cast<CXXRecordDecl>(DC)); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 1929 | } else { |
| 1930 | D2CXX = CXXRecordDecl::Create(Importer.getToContext(), |
| 1931 | D->getTagKind(), |
| 1932 | DC, StartLoc, Loc, |
| 1933 | Name.getAsIdentifierInfo()); |
| 1934 | } |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1935 | D2 = D2CXX; |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1936 | D2->setAccess(D->getAccess()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1937 | |
| 1938 | Importer.Imported(D, D2); |
| 1939 | |
| 1940 | if (ClassTemplateDecl *FromDescribed = |
| 1941 | DCXX->getDescribedClassTemplate()) { |
| 1942 | ClassTemplateDecl *ToDescribed = cast_or_null<ClassTemplateDecl>( |
| 1943 | Importer.Import(FromDescribed)); |
| 1944 | if (!ToDescribed) |
| 1945 | return nullptr; |
| 1946 | D2CXX->setDescribedClassTemplate(ToDescribed); |
| 1947 | |
| 1948 | } else if (MemberSpecializationInfo *MemberInfo = |
| 1949 | DCXX->getMemberSpecializationInfo()) { |
| 1950 | TemplateSpecializationKind SK = |
| 1951 | MemberInfo->getTemplateSpecializationKind(); |
| 1952 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
| 1953 | CXXRecordDecl *ToInst = |
| 1954 | cast_or_null<CXXRecordDecl>(Importer.Import(FromInst)); |
| 1955 | if (FromInst && !ToInst) |
| 1956 | return nullptr; |
| 1957 | D2CXX->setInstantiationOfMemberClass(ToInst, SK); |
| 1958 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 1959 | Importer.Import(MemberInfo->getPointOfInstantiation())); |
| 1960 | } |
| 1961 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1962 | } else { |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1963 | D2 = RecordDecl::Create(Importer.getToContext(), D->getTagKind(), |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 1964 | DC, StartLoc, Loc, Name.getAsIdentifierInfo()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1965 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 1966 | |
| 1967 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1968 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1969 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1970 | if (D->isAnonymousStructOrUnion()) |
| 1971 | D2->setAnonymousStructOrUnion(true); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 1972 | if (PrevDecl) { |
| 1973 | // FIXME: do this for all Redeclarables, not just RecordDecls. |
| 1974 | D2->setPreviousDecl(PrevDecl); |
| 1975 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1976 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1977 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1978 | Importer.Imported(D, D2); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1979 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1980 | if (D->isCompleteDefinition() && ImportDefinition(D, D2, IDK_Default)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1981 | return nullptr; |
| 1982 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1983 | return D2; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1984 | } |
| 1985 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1986 | Decl *ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| 1987 | // Import the major distinguishing characteristics of this enumerator. |
| 1988 | DeclContext *DC, *LexicalDC; |
| 1989 | DeclarationName Name; |
| 1990 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1991 | NamedDecl *ToD; |
| 1992 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1993 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1994 | if (ToD) |
| 1995 | return ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1996 | |
| 1997 | QualType T = Importer.Import(D->getType()); |
| 1998 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1999 | return nullptr; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2000 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2001 | // Determine whether there are any other declarations with the same name and |
| 2002 | // in the same context. |
| 2003 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2004 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2005 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2006 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2007 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2008 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2009 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2010 | continue; |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2011 | |
| 2012 | if (EnumConstantDecl *FoundEnumConstant |
| 2013 | = dyn_cast<EnumConstantDecl>(FoundDecls[I])) { |
| 2014 | if (IsStructuralMatch(D, FoundEnumConstant)) |
| 2015 | return Importer.Imported(D, FoundEnumConstant); |
| 2016 | } |
| 2017 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2018 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | if (!ConflictingDecls.empty()) { |
| 2022 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2023 | ConflictingDecls.data(), |
| 2024 | ConflictingDecls.size()); |
| 2025 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2026 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2027 | } |
| 2028 | } |
| 2029 | |
| 2030 | Expr *Init = Importer.Import(D->getInitExpr()); |
| 2031 | if (D->getInitExpr() && !Init) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2032 | return nullptr; |
| 2033 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2034 | EnumConstantDecl *ToEnumerator |
| 2035 | = EnumConstantDecl::Create(Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
| 2036 | Name.getAsIdentifierInfo(), T, |
| 2037 | Init, D->getInitVal()); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2038 | ToEnumerator->setAccess(D->getAccess()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2039 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2040 | Importer.Imported(D, ToEnumerator); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2041 | LexicalDC->addDeclInternal(ToEnumerator); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2042 | return ToEnumerator; |
| 2043 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2044 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2045 | Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
| 2046 | // Import the major distinguishing characteristics of this function. |
| 2047 | DeclContext *DC, *LexicalDC; |
| 2048 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2049 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2050 | NamedDecl *ToD; |
| 2051 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2052 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2053 | if (ToD) |
| 2054 | return ToD; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2055 | |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2056 | const FunctionDecl *FoundWithoutBody = nullptr; |
| 2057 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2058 | // Try to find a function in our own ("to") context with the same name, same |
| 2059 | // type, and in the same context as the function we're importing. |
| 2060 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2061 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2062 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2063 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2064 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2065 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2066 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2067 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2068 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2069 | if (FunctionDecl *FoundFunction = dyn_cast<FunctionDecl>(FoundDecls[I])) { |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 2070 | if (FoundFunction->hasExternalFormalLinkage() && |
| 2071 | D->hasExternalFormalLinkage()) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2072 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| 2073 | FoundFunction->getType())) { |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2074 | // FIXME: Actually try to merge the body and other attributes. |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2075 | const FunctionDecl *FromBodyDecl = nullptr; |
| 2076 | D->hasBody(FromBodyDecl); |
| 2077 | if (D == FromBodyDecl && !FoundFunction->hasBody()) { |
| 2078 | // This function is needed to merge completely. |
| 2079 | FoundWithoutBody = FoundFunction; |
| 2080 | break; |
| 2081 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2082 | return Importer.Imported(D, FoundFunction); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2083 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2084 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2085 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 2086 | // Sema::IsOverload out to the AST library. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2087 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2088 | // Function overloading is okay in C++. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2089 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2090 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2091 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2092 | // Complain about inconsistent function types. |
| 2093 | Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2094 | << Name << D->getType() << FoundFunction->getType(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2095 | Importer.ToDiag(FoundFunction->getLocation(), |
| 2096 | diag::note_odr_value_here) |
| 2097 | << FoundFunction->getType(); |
| 2098 | } |
| 2099 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2100 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2101 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2102 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2103 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2104 | if (!ConflictingDecls.empty()) { |
| 2105 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2106 | ConflictingDecls.data(), |
| 2107 | ConflictingDecls.size()); |
| 2108 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2109 | return nullptr; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2110 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2111 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2112 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2113 | DeclarationNameInfo NameInfo(Name, Loc); |
| 2114 | // Import additional name location/type info. |
| 2115 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 2116 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2117 | QualType FromTy = D->getType(); |
| 2118 | bool usedDifferentExceptionSpec = false; |
| 2119 | |
| 2120 | if (const FunctionProtoType * |
| 2121 | FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
| 2122 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 2123 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 2124 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 2125 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 2126 | // with a simplified function type and update it afterwards. |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 2127 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 2128 | FromEPI.ExceptionSpec.SourceTemplate || |
| 2129 | FromEPI.ExceptionSpec.NoexceptExpr) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2130 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 2131 | FromTy = Importer.getFromContext().getFunctionType( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2132 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2133 | usedDifferentExceptionSpec = true; |
| 2134 | } |
| 2135 | } |
| 2136 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2137 | // Import the type. |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2138 | QualType T = Importer.Import(FromTy); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2139 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2140 | return nullptr; |
| 2141 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2142 | // Import the function parameters. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2143 | SmallVector<ParmVarDecl *, 8> Parameters; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2144 | for (auto P : D->parameters()) { |
Aaron Ballman | f6bf62e | 2014-03-07 15:12:56 +0000 | [diff] [blame] | 2145 | ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(P)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2146 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2147 | return nullptr; |
| 2148 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2149 | Parameters.push_back(ToP); |
| 2150 | } |
| 2151 | |
| 2152 | // Create the imported function. |
| 2153 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2154 | FunctionDecl *ToFunction = nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2155 | SourceLocation InnerLocStart = Importer.Import(D->getInnerLocStart()); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2156 | if (CXXConstructorDecl *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| 2157 | ToFunction = CXXConstructorDecl::Create(Importer.getToContext(), |
| 2158 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2159 | InnerLocStart, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2160 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2161 | FromConstructor->isExplicit(), |
| 2162 | D->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2163 | D->isImplicit(), |
| 2164 | D->isConstexpr()); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2165 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 2166 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers; |
| 2167 | for (CXXCtorInitializer *I : FromConstructor->inits()) { |
| 2168 | CXXCtorInitializer *ToI = |
| 2169 | cast_or_null<CXXCtorInitializer>(Importer.Import(I)); |
| 2170 | if (!ToI && I) |
| 2171 | return nullptr; |
| 2172 | CtorInitializers.push_back(ToI); |
| 2173 | } |
| 2174 | CXXCtorInitializer **Memory = |
| 2175 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 2176 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
| 2177 | CXXConstructorDecl *ToCtor = llvm::cast<CXXConstructorDecl>(ToFunction); |
| 2178 | ToCtor->setCtorInitializers(Memory); |
| 2179 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 2180 | } |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2181 | } else if (isa<CXXDestructorDecl>(D)) { |
| 2182 | ToFunction = CXXDestructorDecl::Create(Importer.getToContext(), |
| 2183 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2184 | InnerLocStart, |
Craig Silverstein | af8808d | 2010-10-21 00:44:50 +0000 | [diff] [blame] | 2185 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2186 | D->isInlineSpecified(), |
| 2187 | D->isImplicit()); |
| 2188 | } else if (CXXConversionDecl *FromConversion |
| 2189 | = dyn_cast<CXXConversionDecl>(D)) { |
| 2190 | ToFunction = CXXConversionDecl::Create(Importer.getToContext(), |
| 2191 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2192 | InnerLocStart, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2193 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2194 | D->isInlineSpecified(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2195 | FromConversion->isExplicit(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2196 | D->isConstexpr(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2197 | Importer.Import(D->getLocEnd())); |
Douglas Gregor | a50ad13 | 2010-11-29 16:04:58 +0000 | [diff] [blame] | 2198 | } else if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { |
| 2199 | ToFunction = CXXMethodDecl::Create(Importer.getToContext(), |
| 2200 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2201 | InnerLocStart, |
Douglas Gregor | a50ad13 | 2010-11-29 16:04:58 +0000 | [diff] [blame] | 2202 | NameInfo, T, TInfo, |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 2203 | Method->getStorageClass(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2204 | Method->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2205 | D->isConstexpr(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2206 | Importer.Import(D->getLocEnd())); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2207 | } else { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2208 | ToFunction = FunctionDecl::Create(Importer.getToContext(), DC, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2209 | InnerLocStart, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2210 | NameInfo, T, TInfo, D->getStorageClass(), |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2211 | D->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2212 | D->hasWrittenPrototype(), |
| 2213 | D->isConstexpr()); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2214 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 2215 | |
| 2216 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2217 | ToFunction->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2218 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2219 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 2220 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 2221 | ToFunction->setTrivial(D->isTrivial()); |
| 2222 | ToFunction->setPure(D->isPure()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2223 | Importer.Imported(D, ToFunction); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2224 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2225 | // Set the parameters. |
| 2226 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2227 | Parameters[I]->setOwningFunction(ToFunction); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2228 | ToFunction->addDeclInternal(Parameters[I]); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2229 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 2230 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2231 | |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2232 | if (FoundWithoutBody) { |
| 2233 | auto *Recent = const_cast<FunctionDecl *>( |
| 2234 | FoundWithoutBody->getMostRecentDecl()); |
| 2235 | ToFunction->setPreviousDecl(Recent); |
| 2236 | } |
| 2237 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2238 | if (usedDifferentExceptionSpec) { |
| 2239 | // Update FunctionProtoType::ExtProtoInfo. |
| 2240 | QualType T = Importer.Import(D->getType()); |
| 2241 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2242 | return nullptr; |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2243 | ToFunction->setType(T); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 2244 | } |
| 2245 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2246 | // Import the body, if any. |
| 2247 | if (Stmt *FromBody = D->getBody()) { |
| 2248 | if (Stmt *ToBody = Importer.Import(FromBody)) { |
| 2249 | ToFunction->setBody(ToBody); |
| 2250 | } |
| 2251 | } |
| 2252 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2253 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2254 | |
| 2255 | // Add this function to the lexical context. |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2256 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2257 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 2258 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 2259 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 2260 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2261 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2262 | } |
| 2263 | |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2264 | Decl *ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| 2265 | return VisitFunctionDecl(D); |
| 2266 | } |
| 2267 | |
| 2268 | Decl *ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| 2269 | return VisitCXXMethodDecl(D); |
| 2270 | } |
| 2271 | |
| 2272 | Decl *ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| 2273 | return VisitCXXMethodDecl(D); |
| 2274 | } |
| 2275 | |
| 2276 | Decl *ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| 2277 | return VisitCXXMethodDecl(D); |
| 2278 | } |
| 2279 | |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2280 | static unsigned getFieldIndex(Decl *F) { |
| 2281 | RecordDecl *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
| 2282 | if (!Owner) |
| 2283 | return 0; |
| 2284 | |
| 2285 | unsigned Index = 1; |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2286 | for (const auto *D : Owner->noload_decls()) { |
| 2287 | if (D == F) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2288 | return Index; |
| 2289 | |
| 2290 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 2291 | ++Index; |
| 2292 | } |
| 2293 | |
| 2294 | return Index; |
| 2295 | } |
| 2296 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2297 | Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
| 2298 | // Import the major distinguishing characteristics of a variable. |
| 2299 | DeclContext *DC, *LexicalDC; |
| 2300 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2301 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2302 | NamedDecl *ToD; |
| 2303 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2304 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2305 | if (ToD) |
| 2306 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2307 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2308 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2309 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2310 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2311 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2312 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2313 | // For anonymous fields, match up by index. |
| 2314 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2315 | continue; |
| 2316 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2317 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2318 | FoundField->getType())) { |
| 2319 | Importer.Imported(D, FoundField); |
| 2320 | return FoundField; |
| 2321 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2322 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2323 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2324 | << Name << D->getType() << FoundField->getType(); |
| 2325 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2326 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2327 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2328 | } |
| 2329 | } |
| 2330 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2331 | // Import the type. |
| 2332 | QualType T = Importer.Import(D->getType()); |
| 2333 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2334 | return nullptr; |
| 2335 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2336 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2337 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 2338 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2339 | return nullptr; |
| 2340 | |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2341 | FieldDecl *ToField = FieldDecl::Create(Importer.getToContext(), DC, |
| 2342 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2343 | Loc, Name.getAsIdentifierInfo(), |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2344 | T, TInfo, BitWidth, D->isMutable(), |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2345 | D->getInClassInitStyle()); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2346 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2347 | ToField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 3a83ea7 | 2016-03-03 02:22:05 +0000 | [diff] [blame] | 2348 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
Sean Callanan | bb33f58 | 2016-03-03 01:21:28 +0000 | [diff] [blame] | 2349 | Expr *ToInitializer = Importer.Import(FromInitializer); |
| 2350 | if (ToInitializer) |
| 2351 | ToField->setInClassInitializer(ToInitializer); |
| 2352 | else |
| 2353 | return nullptr; |
| 2354 | } |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2355 | ToField->setImplicit(D->isImplicit()); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2356 | Importer.Imported(D, ToField); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2357 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2358 | return ToField; |
| 2359 | } |
| 2360 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2361 | Decl *ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| 2362 | // Import the major distinguishing characteristics of a variable. |
| 2363 | DeclContext *DC, *LexicalDC; |
| 2364 | DeclarationName Name; |
| 2365 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2366 | NamedDecl *ToD; |
| 2367 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2368 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2369 | if (ToD) |
| 2370 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2371 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2372 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2373 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2374 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2375 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2376 | if (IndirectFieldDecl *FoundField |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2377 | = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2378 | // For anonymous indirect fields, match up by index. |
| 2379 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2380 | continue; |
| 2381 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2382 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2383 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 2384 | !Name.isEmpty())) { |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2385 | Importer.Imported(D, FoundField); |
| 2386 | return FoundField; |
| 2387 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2388 | |
| 2389 | // If there are more anonymous fields to check, continue. |
| 2390 | if (!Name && I < N-1) |
| 2391 | continue; |
| 2392 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2393 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2394 | << Name << D->getType() << FoundField->getType(); |
| 2395 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2396 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2397 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2398 | } |
| 2399 | } |
| 2400 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2401 | // Import the type. |
| 2402 | QualType T = Importer.Import(D->getType()); |
| 2403 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2404 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2405 | |
| 2406 | NamedDecl **NamedChain = |
| 2407 | new (Importer.getToContext())NamedDecl*[D->getChainingSize()]; |
| 2408 | |
| 2409 | unsigned i = 0; |
Aaron Ballman | 29c9460 | 2014-03-07 18:36:15 +0000 | [diff] [blame] | 2410 | for (auto *PI : D->chain()) { |
Aaron Ballman | 1391608 | 2014-03-07 18:11:58 +0000 | [diff] [blame] | 2411 | Decl *D = Importer.Import(PI); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2412 | if (!D) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2413 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2414 | NamedChain[i++] = cast<NamedDecl>(D); |
| 2415 | } |
| 2416 | |
| 2417 | IndirectFieldDecl *ToIndirectField = IndirectFieldDecl::Create( |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2418 | Importer.getToContext(), DC, Loc, Name.getAsIdentifierInfo(), T, |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2419 | {NamedChain, D->getChainingSize()}); |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2420 | |
| 2421 | for (const auto *Attr : D->attrs()) |
| 2422 | ToIndirectField->addAttr(Attr->clone(Importer.getToContext())); |
| 2423 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2424 | ToIndirectField->setAccess(D->getAccess()); |
| 2425 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
| 2426 | Importer.Imported(D, ToIndirectField); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2427 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2428 | return ToIndirectField; |
| 2429 | } |
| 2430 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2431 | Decl *ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
| 2432 | // Import the major distinguishing characteristics of a declaration. |
| 2433 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 2434 | DeclContext *LexicalDC = D->getDeclContext() == D->getLexicalDeclContext() |
| 2435 | ? DC : Importer.ImportContext(D->getLexicalDeclContext()); |
| 2436 | if (!DC || !LexicalDC) |
| 2437 | return nullptr; |
| 2438 | |
| 2439 | // Determine whether we've already imported this decl. |
| 2440 | // FriendDecl is not a NamedDecl so we cannot use localUncachedLookup. |
| 2441 | auto *RD = cast<CXXRecordDecl>(DC); |
| 2442 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
| 2443 | StructuralEquivalenceContext Context( |
| 2444 | Importer.getFromContext(), Importer.getToContext(), |
| 2445 | Importer.getNonEquivalentDecls(), false, false); |
| 2446 | |
| 2447 | while (ImportedFriend) { |
| 2448 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
| 2449 | if (Context.IsStructurallyEquivalent(D->getFriendDecl(), |
| 2450 | ImportedFriend->getFriendDecl())) |
| 2451 | return Importer.Imported(D, ImportedFriend); |
| 2452 | |
| 2453 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 2454 | if (Importer.IsStructurallyEquivalent( |
| 2455 | D->getFriendType()->getType(), |
| 2456 | ImportedFriend->getFriendType()->getType(), true)) |
| 2457 | return Importer.Imported(D, ImportedFriend); |
| 2458 | } |
| 2459 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 2460 | } |
| 2461 | |
| 2462 | // Not found. Create it. |
| 2463 | FriendDecl::FriendUnion ToFU; |
| 2464 | if (NamedDecl *FriendD = D->getFriendDecl()) |
| 2465 | ToFU = cast_or_null<NamedDecl>(Importer.Import(FriendD)); |
| 2466 | else |
| 2467 | ToFU = Importer.Import(D->getFriendType()); |
| 2468 | if (!ToFU) |
| 2469 | return nullptr; |
| 2470 | |
| 2471 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
| 2472 | TemplateParameterList **FromTPLists = |
| 2473 | D->getTrailingObjects<TemplateParameterList *>(); |
| 2474 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
| 2475 | TemplateParameterList *List = ImportTemplateParameterList(FromTPLists[I]); |
| 2476 | if (!List) |
| 2477 | return nullptr; |
| 2478 | ToTPLists[I] = List; |
| 2479 | } |
| 2480 | |
| 2481 | FriendDecl *FrD = FriendDecl::Create(Importer.getToContext(), DC, |
| 2482 | Importer.Import(D->getLocation()), |
| 2483 | ToFU, Importer.Import(D->getFriendLoc()), |
| 2484 | ToTPLists); |
| 2485 | |
| 2486 | Importer.Imported(D, FrD); |
| 2487 | RD->pushFriendDecl(FrD); |
| 2488 | |
| 2489 | FrD->setAccess(D->getAccess()); |
| 2490 | FrD->setLexicalDeclContext(LexicalDC); |
| 2491 | LexicalDC->addDeclInternal(FrD); |
| 2492 | return FrD; |
| 2493 | } |
| 2494 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2495 | Decl *ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| 2496 | // Import the major distinguishing characteristics of an ivar. |
| 2497 | DeclContext *DC, *LexicalDC; |
| 2498 | DeclarationName Name; |
| 2499 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2500 | NamedDecl *ToD; |
| 2501 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2502 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2503 | if (ToD) |
| 2504 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2505 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2506 | // Determine whether we've already imported this ivar |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2507 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2508 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2509 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2510 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecls[I])) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2511 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2512 | FoundIvar->getType())) { |
| 2513 | Importer.Imported(D, FoundIvar); |
| 2514 | return FoundIvar; |
| 2515 | } |
| 2516 | |
| 2517 | Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent) |
| 2518 | << Name << D->getType() << FoundIvar->getType(); |
| 2519 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 2520 | << FoundIvar->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2521 | return nullptr; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2522 | } |
| 2523 | } |
| 2524 | |
| 2525 | // Import the type. |
| 2526 | QualType T = Importer.Import(D->getType()); |
| 2527 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2528 | return nullptr; |
| 2529 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2530 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2531 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 2532 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2533 | return nullptr; |
| 2534 | |
Daniel Dunbar | fe3ead7 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 2535 | ObjCIvarDecl *ToIvar = ObjCIvarDecl::Create(Importer.getToContext(), |
| 2536 | cast<ObjCContainerDecl>(DC), |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2537 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2538 | Loc, Name.getAsIdentifierInfo(), |
| 2539 | T, TInfo, D->getAccessControl(), |
Argyrios Kyrtzidis | 2080d90 | 2014-01-03 18:32:18 +0000 | [diff] [blame] | 2540 | BitWidth, D->getSynthesize()); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2541 | ToIvar->setLexicalDeclContext(LexicalDC); |
| 2542 | Importer.Imported(D, ToIvar); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2543 | LexicalDC->addDeclInternal(ToIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2544 | return ToIvar; |
| 2545 | |
| 2546 | } |
| 2547 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2548 | Decl *ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
| 2549 | // Import the major distinguishing characteristics of a variable. |
| 2550 | DeclContext *DC, *LexicalDC; |
| 2551 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2552 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2553 | NamedDecl *ToD; |
| 2554 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2555 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2556 | if (ToD) |
| 2557 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2558 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2559 | // Try to find a variable in our own ("to") context with the same name and |
| 2560 | // in the same context as the variable we're importing. |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2561 | if (D->isFileVarDecl()) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2562 | VarDecl *MergeWithVar = nullptr; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2563 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2564 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2565 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2566 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2567 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2568 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2569 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2570 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2571 | if (VarDecl *FoundVar = dyn_cast<VarDecl>(FoundDecls[I])) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2572 | // 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] | 2573 | if (FoundVar->hasExternalFormalLinkage() && |
| 2574 | D->hasExternalFormalLinkage()) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2575 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2576 | FoundVar->getType())) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2577 | MergeWithVar = FoundVar; |
| 2578 | break; |
| 2579 | } |
| 2580 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2581 | const ArrayType *FoundArray |
| 2582 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 2583 | const ArrayType *TArray |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2584 | = Importer.getToContext().getAsArrayType(D->getType()); |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2585 | if (FoundArray && TArray) { |
| 2586 | if (isa<IncompleteArrayType>(FoundArray) && |
| 2587 | isa<ConstantArrayType>(TArray)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2588 | // Import the type. |
| 2589 | QualType T = Importer.Import(D->getType()); |
| 2590 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2591 | return nullptr; |
| 2592 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2593 | FoundVar->setType(T); |
| 2594 | MergeWithVar = FoundVar; |
| 2595 | break; |
| 2596 | } else if (isa<IncompleteArrayType>(TArray) && |
| 2597 | isa<ConstantArrayType>(FoundArray)) { |
| 2598 | MergeWithVar = FoundVar; |
| 2599 | break; |
Douglas Gregor | 2fbe558 | 2010-02-10 17:16:49 +0000 | [diff] [blame] | 2600 | } |
| 2601 | } |
| 2602 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2603 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2604 | << Name << D->getType() << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2605 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 2606 | << FoundVar->getType(); |
| 2607 | } |
| 2608 | } |
| 2609 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2610 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2611 | } |
| 2612 | |
| 2613 | if (MergeWithVar) { |
| 2614 | // An equivalent variable with external linkage has been found. Link |
| 2615 | // the two declarations, then merge them. |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2616 | Importer.Imported(D, MergeWithVar); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2617 | |
| 2618 | if (VarDecl *DDef = D->getDefinition()) { |
| 2619 | if (VarDecl *ExistingDef = MergeWithVar->getDefinition()) { |
| 2620 | Importer.ToDiag(ExistingDef->getLocation(), |
| 2621 | diag::err_odr_variable_multiple_def) |
| 2622 | << Name; |
| 2623 | Importer.FromDiag(DDef->getLocation(), diag::note_odr_defined_here); |
| 2624 | } else { |
| 2625 | Expr *Init = Importer.Import(DDef->getInit()); |
Douglas Gregor | d505812 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 2626 | MergeWithVar->setInit(Init); |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 2627 | if (DDef->isInitKnownICE()) { |
| 2628 | EvaluatedStmt *Eval = MergeWithVar->ensureEvaluatedStmt(); |
| 2629 | Eval->CheckedICE = true; |
| 2630 | Eval->IsICE = DDef->isInitICE(); |
| 2631 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2632 | } |
| 2633 | } |
| 2634 | |
| 2635 | return MergeWithVar; |
| 2636 | } |
| 2637 | |
| 2638 | if (!ConflictingDecls.empty()) { |
| 2639 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2640 | ConflictingDecls.data(), |
| 2641 | ConflictingDecls.size()); |
| 2642 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2643 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2644 | } |
| 2645 | } |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2646 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2647 | // Import the type. |
| 2648 | QualType T = Importer.Import(D->getType()); |
| 2649 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2650 | return nullptr; |
| 2651 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2652 | // Create the imported variable. |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2653 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2654 | VarDecl *ToVar = VarDecl::Create(Importer.getToContext(), DC, |
| 2655 | Importer.Import(D->getInnerLocStart()), |
| 2656 | Loc, Name.getAsIdentifierInfo(), |
| 2657 | T, TInfo, |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 2658 | D->getStorageClass()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2659 | ToVar->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2660 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2661 | ToVar->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2662 | Importer.Imported(D, ToVar); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2663 | LexicalDC->addDeclInternal(ToVar); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2664 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2665 | if (!D->isFileVarDecl() && |
| 2666 | D->isUsed()) |
| 2667 | ToVar->setIsUsed(); |
| 2668 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2669 | // Merge the initializer. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2670 | if (ImportDefinition(D, ToVar)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2671 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2672 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 2673 | if (D->isConstexpr()) |
| 2674 | ToVar->setConstexpr(true); |
| 2675 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2676 | return ToVar; |
| 2677 | } |
| 2678 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2679 | Decl *ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| 2680 | // Parameters are created in the translation unit's context, then moved |
| 2681 | // into the function declaration's context afterward. |
| 2682 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| 2683 | |
| 2684 | // Import the name of this declaration. |
| 2685 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 2686 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2687 | return nullptr; |
| 2688 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2689 | // Import the location of this declaration. |
| 2690 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 2691 | |
| 2692 | // Import the parameter's type. |
| 2693 | QualType T = Importer.Import(D->getType()); |
| 2694 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2695 | return nullptr; |
| 2696 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2697 | // Create the imported parameter. |
Alexey Bataev | 5622323 | 2017-06-09 13:40:18 +0000 | [diff] [blame] | 2698 | auto *ToParm = ImplicitParamDecl::Create(Importer.getToContext(), DC, Loc, |
| 2699 | Name.getAsIdentifierInfo(), T, |
| 2700 | D->getParameterKind()); |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2701 | return Importer.Imported(D, ToParm); |
| 2702 | } |
| 2703 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2704 | Decl *ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
| 2705 | // Parameters are created in the translation unit's context, then moved |
| 2706 | // into the function declaration's context afterward. |
| 2707 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| 2708 | |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2709 | // Import the name of this declaration. |
| 2710 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 2711 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2712 | return nullptr; |
| 2713 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2714 | // Import the location of this declaration. |
| 2715 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 2716 | |
| 2717 | // Import the parameter's type. |
| 2718 | QualType T = Importer.Import(D->getType()); |
| 2719 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2720 | return nullptr; |
| 2721 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2722 | // Create the imported parameter. |
| 2723 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2724 | ParmVarDecl *ToParm = ParmVarDecl::Create(Importer.getToContext(), DC, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2725 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2726 | Loc, Name.getAsIdentifierInfo(), |
| 2727 | T, TInfo, D->getStorageClass(), |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 2728 | /*DefaultArg*/ nullptr); |
| 2729 | |
| 2730 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 2731 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 2732 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 2733 | |
| 2734 | Expr *ToDefArg = nullptr; |
| 2735 | Expr *FromDefArg = nullptr; |
| 2736 | if (D->hasUninstantiatedDefaultArg()) { |
| 2737 | FromDefArg = D->getUninstantiatedDefaultArg(); |
| 2738 | ToDefArg = Importer.Import(FromDefArg); |
| 2739 | ToParm->setUninstantiatedDefaultArg(ToDefArg); |
| 2740 | } else if (D->hasUnparsedDefaultArg()) { |
| 2741 | ToParm->setUnparsedDefaultArg(); |
| 2742 | } else if (D->hasDefaultArg()) { |
| 2743 | FromDefArg = D->getDefaultArg(); |
| 2744 | ToDefArg = Importer.Import(FromDefArg); |
| 2745 | ToParm->setDefaultArg(ToDefArg); |
| 2746 | } |
| 2747 | if (FromDefArg && !ToDefArg) |
| 2748 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2749 | |
| 2750 | if (D->isUsed()) |
| 2751 | ToParm->setIsUsed(); |
| 2752 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2753 | return Importer.Imported(D, ToParm); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2754 | } |
| 2755 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2756 | Decl *ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| 2757 | // Import the major distinguishing characteristics of a method. |
| 2758 | DeclContext *DC, *LexicalDC; |
| 2759 | DeclarationName Name; |
| 2760 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2761 | NamedDecl *ToD; |
| 2762 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2763 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2764 | if (ToD) |
| 2765 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2766 | |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2767 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2768 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2769 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2770 | if (ObjCMethodDecl *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecls[I])) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2771 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 2772 | continue; |
| 2773 | |
| 2774 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2775 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 2776 | FoundMethod->getReturnType())) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2777 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2778 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 2779 | << FoundMethod->getReturnType(); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2780 | Importer.ToDiag(FoundMethod->getLocation(), |
| 2781 | diag::note_odr_objc_method_here) |
| 2782 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2783 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2784 | } |
| 2785 | |
| 2786 | // Check the number of parameters. |
| 2787 | if (D->param_size() != FoundMethod->param_size()) { |
| 2788 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) |
| 2789 | << D->isInstanceMethod() << Name |
| 2790 | << D->param_size() << FoundMethod->param_size(); |
| 2791 | Importer.ToDiag(FoundMethod->getLocation(), |
| 2792 | diag::note_odr_objc_method_here) |
| 2793 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2794 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2795 | } |
| 2796 | |
| 2797 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2798 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2799 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 2800 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2801 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2802 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2803 | Importer.FromDiag((*P)->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2804 | diag::err_odr_objc_method_param_type_inconsistent) |
| 2805 | << D->isInstanceMethod() << Name |
| 2806 | << (*P)->getType() << (*FoundP)->getType(); |
| 2807 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 2808 | << (*FoundP)->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2809 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2810 | } |
| 2811 | } |
| 2812 | |
| 2813 | // Check variadic/non-variadic. |
| 2814 | // Check the number of parameters. |
| 2815 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| 2816 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) |
| 2817 | << D->isInstanceMethod() << Name; |
| 2818 | Importer.ToDiag(FoundMethod->getLocation(), |
| 2819 | diag::note_odr_objc_method_here) |
| 2820 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2821 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2822 | } |
| 2823 | |
| 2824 | // FIXME: Any other bits we need to merge? |
| 2825 | return Importer.Imported(D, FoundMethod); |
| 2826 | } |
| 2827 | } |
| 2828 | |
| 2829 | // Import the result type. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2830 | QualType ResultTy = Importer.Import(D->getReturnType()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2831 | if (ResultTy.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2832 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2833 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2834 | TypeSourceInfo *ReturnTInfo = Importer.Import(D->getReturnTypeSourceInfo()); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 2835 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2836 | ObjCMethodDecl *ToMethod = ObjCMethodDecl::Create( |
| 2837 | Importer.getToContext(), Loc, Importer.Import(D->getLocEnd()), |
| 2838 | Name.getObjCSelector(), ResultTy, ReturnTInfo, DC, D->isInstanceMethod(), |
| 2839 | D->isVariadic(), D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 2840 | D->getImplementationControl(), D->hasRelatedResultType()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2841 | |
| 2842 | // FIXME: When we decide to merge method definitions, we'll need to |
| 2843 | // deal with implicit parameters. |
| 2844 | |
| 2845 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2846 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2847 | for (auto *FromP : D->parameters()) { |
Aaron Ballman | 43b68be | 2014-03-07 17:50:17 +0000 | [diff] [blame] | 2848 | ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(FromP)); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2849 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2850 | return nullptr; |
| 2851 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2852 | ToParams.push_back(ToP); |
| 2853 | } |
| 2854 | |
| 2855 | // Set the parameters. |
| 2856 | for (unsigned I = 0, N = ToParams.size(); I != N; ++I) { |
| 2857 | ToParams[I]->setOwningFunction(ToMethod); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2858 | ToMethod->addDeclInternal(ToParams[I]); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2859 | } |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 2860 | |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 2861 | SmallVector<SourceLocation, 12> SelLocs; |
| 2862 | D->getSelectorLocs(SelLocs); |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 2863 | for (SourceLocation &Loc : SelLocs) |
| 2864 | Loc = Importer.Import(Loc); |
| 2865 | |
| 2866 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, SelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2867 | |
| 2868 | ToMethod->setLexicalDeclContext(LexicalDC); |
| 2869 | Importer.Imported(D, ToMethod); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2870 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2871 | return ToMethod; |
| 2872 | } |
| 2873 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 2874 | Decl *ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| 2875 | // Import the major distinguishing characteristics of a category. |
| 2876 | DeclContext *DC, *LexicalDC; |
| 2877 | DeclarationName Name; |
| 2878 | SourceLocation Loc; |
| 2879 | NamedDecl *ToD; |
| 2880 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2881 | return nullptr; |
| 2882 | if (ToD) |
| 2883 | return ToD; |
| 2884 | |
| 2885 | TypeSourceInfo *BoundInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2886 | if (!BoundInfo) |
| 2887 | return nullptr; |
| 2888 | |
| 2889 | ObjCTypeParamDecl *Result = ObjCTypeParamDecl::Create( |
| 2890 | Importer.getToContext(), DC, |
Douglas Gregor | 1ac1b63 | 2015-07-07 03:58:54 +0000 | [diff] [blame] | 2891 | D->getVariance(), |
| 2892 | Importer.Import(D->getVarianceLoc()), |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 2893 | D->getIndex(), |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 2894 | Importer.Import(D->getLocation()), |
| 2895 | Name.getAsIdentifierInfo(), |
| 2896 | Importer.Import(D->getColonLoc()), |
| 2897 | BoundInfo); |
| 2898 | Importer.Imported(D, Result); |
| 2899 | Result->setLexicalDeclContext(LexicalDC); |
| 2900 | return Result; |
| 2901 | } |
| 2902 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2903 | Decl *ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| 2904 | // Import the major distinguishing characteristics of a category. |
| 2905 | DeclContext *DC, *LexicalDC; |
| 2906 | DeclarationName Name; |
| 2907 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2908 | NamedDecl *ToD; |
| 2909 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2910 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2911 | if (ToD) |
| 2912 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2913 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2914 | ObjCInterfaceDecl *ToInterface |
| 2915 | = cast_or_null<ObjCInterfaceDecl>(Importer.Import(D->getClassInterface())); |
| 2916 | if (!ToInterface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2917 | return nullptr; |
| 2918 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2919 | // Determine if we've already encountered this category. |
| 2920 | ObjCCategoryDecl *MergeWithCategory |
| 2921 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 2922 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 2923 | if (!ToCategory) { |
| 2924 | ToCategory = ObjCCategoryDecl::Create(Importer.getToContext(), DC, |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 2925 | Importer.Import(D->getAtStartLoc()), |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2926 | Loc, |
| 2927 | Importer.Import(D->getCategoryNameLoc()), |
Argyrios Kyrtzidis | 3a5094b | 2011-08-30 19:43:26 +0000 | [diff] [blame] | 2928 | Name.getAsIdentifierInfo(), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 2929 | ToInterface, |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 2930 | /*TypeParamList=*/nullptr, |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 2931 | Importer.Import(D->getIvarLBraceLoc()), |
| 2932 | Importer.Import(D->getIvarRBraceLoc())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2933 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2934 | LexicalDC->addDeclInternal(ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2935 | Importer.Imported(D, ToCategory); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 2936 | // Import the type parameter list after calling Imported, to avoid |
| 2937 | // loops when bringing in their DeclContext. |
| 2938 | ToCategory->setTypeParamList(ImportObjCTypeParamList( |
| 2939 | D->getTypeParamList())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2940 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2941 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2942 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 2943 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2944 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 2945 | = D->protocol_loc_begin(); |
| 2946 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 2947 | FromProtoEnd = D->protocol_end(); |
| 2948 | FromProto != FromProtoEnd; |
| 2949 | ++FromProto, ++FromProtoLoc) { |
| 2950 | ObjCProtocolDecl *ToProto |
| 2951 | = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
| 2952 | if (!ToProto) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2953 | return nullptr; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2954 | Protocols.push_back(ToProto); |
| 2955 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 2956 | } |
| 2957 | |
| 2958 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 2959 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 2960 | ProtocolLocs.data(), Importer.getToContext()); |
| 2961 | |
| 2962 | } else { |
| 2963 | Importer.Imported(D, ToCategory); |
| 2964 | } |
| 2965 | |
| 2966 | // Import all of the members of this category. |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 2967 | ImportDeclContext(D); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2968 | |
| 2969 | // If we have an implementation, import it as well. |
| 2970 | if (D->getImplementation()) { |
| 2971 | ObjCCategoryImplDecl *Impl |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 2972 | = cast_or_null<ObjCCategoryImplDecl>( |
| 2973 | Importer.Import(D->getImplementation())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2974 | if (!Impl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2975 | return nullptr; |
| 2976 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2977 | ToCategory->setImplementation(Impl); |
| 2978 | } |
| 2979 | |
| 2980 | return ToCategory; |
| 2981 | } |
| 2982 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2983 | bool ASTNodeImporter::ImportDefinition(ObjCProtocolDecl *From, |
| 2984 | ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2985 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2986 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2987 | if (shouldForceImportDeclContext(Kind)) |
| 2988 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2989 | return false; |
| 2990 | } |
| 2991 | |
| 2992 | // Start the protocol definition |
| 2993 | To->startDefinition(); |
| 2994 | |
| 2995 | // Import protocols |
| 2996 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 2997 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| 2998 | ObjCProtocolDecl::protocol_loc_iterator |
| 2999 | FromProtoLoc = From->protocol_loc_begin(); |
| 3000 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3001 | FromProtoEnd = From->protocol_end(); |
| 3002 | FromProto != FromProtoEnd; |
| 3003 | ++FromProto, ++FromProtoLoc) { |
| 3004 | ObjCProtocolDecl *ToProto |
| 3005 | = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
| 3006 | if (!ToProto) |
| 3007 | return true; |
| 3008 | Protocols.push_back(ToProto); |
| 3009 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3010 | } |
| 3011 | |
| 3012 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3013 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 3014 | ProtocolLocs.data(), Importer.getToContext()); |
| 3015 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3016 | if (shouldForceImportDeclContext(Kind)) { |
| 3017 | // Import all of the members of this protocol. |
| 3018 | ImportDeclContext(From, /*ForceImport=*/true); |
| 3019 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3020 | return false; |
| 3021 | } |
| 3022 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3023 | Decl *ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3024 | // If this protocol has a definition in the translation unit we're coming |
| 3025 | // from, but this particular declaration is not that definition, import the |
| 3026 | // definition and map to that. |
| 3027 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 3028 | if (Definition && Definition != D) { |
| 3029 | Decl *ImportedDef = Importer.Import(Definition); |
| 3030 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3031 | return nullptr; |
| 3032 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3033 | return Importer.Imported(D, ImportedDef); |
| 3034 | } |
| 3035 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3036 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3037 | DeclContext *DC, *LexicalDC; |
| 3038 | DeclarationName Name; |
| 3039 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3040 | NamedDecl *ToD; |
| 3041 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3042 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3043 | if (ToD) |
| 3044 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3045 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3046 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3047 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3048 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3049 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 3050 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3051 | continue; |
| 3052 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3053 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecls[I]))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3054 | break; |
| 3055 | } |
| 3056 | |
| 3057 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3058 | if (!ToProto) { |
| 3059 | ToProto = ObjCProtocolDecl::Create(Importer.getToContext(), DC, |
| 3060 | Name.getAsIdentifierInfo(), Loc, |
| 3061 | Importer.Import(D->getAtStartLoc()), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3062 | /*PrevDecl=*/nullptr); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3063 | ToProto->setLexicalDeclContext(LexicalDC); |
| 3064 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3065 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3066 | |
| 3067 | Importer.Imported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3068 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3069 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToProto)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3070 | return nullptr; |
| 3071 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3072 | return ToProto; |
| 3073 | } |
| 3074 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3075 | Decl *ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 3076 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3077 | DeclContext *LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3078 | |
| 3079 | SourceLocation ExternLoc = Importer.Import(D->getExternLoc()); |
| 3080 | SourceLocation LangLoc = Importer.Import(D->getLocation()); |
| 3081 | |
| 3082 | bool HasBraces = D->hasBraces(); |
| 3083 | |
Sean Callanan | b12a855 | 2014-12-10 21:22:20 +0000 | [diff] [blame] | 3084 | LinkageSpecDecl *ToLinkageSpec = |
| 3085 | LinkageSpecDecl::Create(Importer.getToContext(), |
| 3086 | DC, |
| 3087 | ExternLoc, |
| 3088 | LangLoc, |
| 3089 | D->getLanguage(), |
| 3090 | HasBraces); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3091 | |
| 3092 | if (HasBraces) { |
| 3093 | SourceLocation RBraceLoc = Importer.Import(D->getRBraceLoc()); |
| 3094 | ToLinkageSpec->setRBraceLoc(RBraceLoc); |
| 3095 | } |
| 3096 | |
| 3097 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 3098 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 3099 | |
| 3100 | Importer.Imported(D, ToLinkageSpec); |
| 3101 | |
| 3102 | return ToLinkageSpec; |
| 3103 | } |
| 3104 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3105 | Decl *ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
| 3106 | DeclContext *DC, *LexicalDC; |
| 3107 | DeclarationName Name; |
| 3108 | SourceLocation Loc; |
| 3109 | NamedDecl *ToD = nullptr; |
| 3110 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3111 | return nullptr; |
| 3112 | if (ToD) |
| 3113 | return ToD; |
| 3114 | |
| 3115 | DeclarationNameInfo NameInfo(Name, |
| 3116 | Importer.Import(D->getNameInfo().getLoc())); |
| 3117 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 3118 | |
| 3119 | UsingDecl *ToUsing = UsingDecl::Create(Importer.getToContext(), DC, |
| 3120 | Importer.Import(D->getUsingLoc()), |
| 3121 | Importer.Import(D->getQualifierLoc()), |
| 3122 | NameInfo, D->hasTypename()); |
| 3123 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 3124 | LexicalDC->addDeclInternal(ToUsing); |
| 3125 | Importer.Imported(D, ToUsing); |
| 3126 | |
| 3127 | if (NamedDecl *FromPattern = |
| 3128 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
| 3129 | if (NamedDecl *ToPattern = |
| 3130 | dyn_cast_or_null<NamedDecl>(Importer.Import(FromPattern))) |
| 3131 | Importer.getToContext().setInstantiatedFromUsingDecl(ToUsing, ToPattern); |
| 3132 | else |
| 3133 | return nullptr; |
| 3134 | } |
| 3135 | |
| 3136 | for (UsingShadowDecl *FromShadow : D->shadows()) { |
| 3137 | if (UsingShadowDecl *ToShadow = |
| 3138 | dyn_cast_or_null<UsingShadowDecl>(Importer.Import(FromShadow))) |
| 3139 | ToUsing->addShadowDecl(ToShadow); |
| 3140 | else |
| 3141 | // FIXME: We return a nullptr here but the definition is already created |
| 3142 | // and available with lookups. How to fix this?.. |
| 3143 | return nullptr; |
| 3144 | } |
| 3145 | return ToUsing; |
| 3146 | } |
| 3147 | |
| 3148 | Decl *ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| 3149 | DeclContext *DC, *LexicalDC; |
| 3150 | DeclarationName Name; |
| 3151 | SourceLocation Loc; |
| 3152 | NamedDecl *ToD = nullptr; |
| 3153 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3154 | return nullptr; |
| 3155 | if (ToD) |
| 3156 | return ToD; |
| 3157 | |
| 3158 | UsingDecl *ToUsing = dyn_cast_or_null<UsingDecl>( |
| 3159 | Importer.Import(D->getUsingDecl())); |
| 3160 | if (!ToUsing) |
| 3161 | return nullptr; |
| 3162 | |
| 3163 | NamedDecl *ToTarget = dyn_cast_or_null<NamedDecl>( |
| 3164 | Importer.Import(D->getTargetDecl())); |
| 3165 | if (!ToTarget) |
| 3166 | return nullptr; |
| 3167 | |
| 3168 | UsingShadowDecl *ToShadow = UsingShadowDecl::Create( |
| 3169 | Importer.getToContext(), DC, Loc, ToUsing, ToTarget); |
| 3170 | |
| 3171 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 3172 | ToShadow->setAccess(D->getAccess()); |
| 3173 | Importer.Imported(D, ToShadow); |
| 3174 | |
| 3175 | if (UsingShadowDecl *FromPattern = |
| 3176 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
| 3177 | if (UsingShadowDecl *ToPattern = |
| 3178 | dyn_cast_or_null<UsingShadowDecl>(Importer.Import(FromPattern))) |
| 3179 | Importer.getToContext().setInstantiatedFromUsingShadowDecl(ToShadow, |
| 3180 | ToPattern); |
| 3181 | else |
| 3182 | // FIXME: We return a nullptr here but the definition is already created |
| 3183 | // and available with lookups. How to fix this?.. |
| 3184 | return nullptr; |
| 3185 | } |
| 3186 | |
| 3187 | LexicalDC->addDeclInternal(ToShadow); |
| 3188 | |
| 3189 | return ToShadow; |
| 3190 | } |
| 3191 | |
| 3192 | |
| 3193 | Decl *ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 3194 | DeclContext *DC, *LexicalDC; |
| 3195 | DeclarationName Name; |
| 3196 | SourceLocation Loc; |
| 3197 | NamedDecl *ToD = nullptr; |
| 3198 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3199 | return nullptr; |
| 3200 | if (ToD) |
| 3201 | return ToD; |
| 3202 | |
| 3203 | DeclContext *ToComAncestor = Importer.ImportContext(D->getCommonAncestor()); |
| 3204 | if (!ToComAncestor) |
| 3205 | return nullptr; |
| 3206 | |
| 3207 | NamespaceDecl *ToNominated = cast_or_null<NamespaceDecl>( |
| 3208 | Importer.Import(D->getNominatedNamespace())); |
| 3209 | if (!ToNominated) |
| 3210 | return nullptr; |
| 3211 | |
| 3212 | UsingDirectiveDecl *ToUsingDir = UsingDirectiveDecl::Create( |
| 3213 | Importer.getToContext(), DC, Importer.Import(D->getUsingLoc()), |
| 3214 | Importer.Import(D->getNamespaceKeyLocation()), |
| 3215 | Importer.Import(D->getQualifierLoc()), |
| 3216 | Importer.Import(D->getIdentLocation()), ToNominated, ToComAncestor); |
| 3217 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 3218 | LexicalDC->addDeclInternal(ToUsingDir); |
| 3219 | Importer.Imported(D, ToUsingDir); |
| 3220 | |
| 3221 | return ToUsingDir; |
| 3222 | } |
| 3223 | |
| 3224 | Decl *ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
| 3225 | UnresolvedUsingValueDecl *D) { |
| 3226 | DeclContext *DC, *LexicalDC; |
| 3227 | DeclarationName Name; |
| 3228 | SourceLocation Loc; |
| 3229 | NamedDecl *ToD = nullptr; |
| 3230 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3231 | return nullptr; |
| 3232 | if (ToD) |
| 3233 | return ToD; |
| 3234 | |
| 3235 | DeclarationNameInfo NameInfo(Name, Importer.Import(D->getNameInfo().getLoc())); |
| 3236 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 3237 | |
| 3238 | UnresolvedUsingValueDecl *ToUsingValue = UnresolvedUsingValueDecl::Create( |
| 3239 | Importer.getToContext(), DC, Importer.Import(D->getUsingLoc()), |
| 3240 | Importer.Import(D->getQualifierLoc()), NameInfo, |
| 3241 | Importer.Import(D->getEllipsisLoc())); |
| 3242 | |
| 3243 | Importer.Imported(D, ToUsingValue); |
| 3244 | ToUsingValue->setAccess(D->getAccess()); |
| 3245 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 3246 | LexicalDC->addDeclInternal(ToUsingValue); |
| 3247 | |
| 3248 | return ToUsingValue; |
| 3249 | } |
| 3250 | |
| 3251 | Decl *ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
| 3252 | UnresolvedUsingTypenameDecl *D) { |
| 3253 | DeclContext *DC, *LexicalDC; |
| 3254 | DeclarationName Name; |
| 3255 | SourceLocation Loc; |
| 3256 | NamedDecl *ToD = nullptr; |
| 3257 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3258 | return nullptr; |
| 3259 | if (ToD) |
| 3260 | return ToD; |
| 3261 | |
| 3262 | UnresolvedUsingTypenameDecl *ToUsing = UnresolvedUsingTypenameDecl::Create( |
| 3263 | Importer.getToContext(), DC, Importer.Import(D->getUsingLoc()), |
| 3264 | Importer.Import(D->getTypenameLoc()), |
| 3265 | Importer.Import(D->getQualifierLoc()), Loc, Name, |
| 3266 | Importer.Import(D->getEllipsisLoc())); |
| 3267 | |
| 3268 | Importer.Imported(D, ToUsing); |
| 3269 | ToUsing->setAccess(D->getAccess()); |
| 3270 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 3271 | LexicalDC->addDeclInternal(ToUsing); |
| 3272 | |
| 3273 | return ToUsing; |
| 3274 | } |
| 3275 | |
| 3276 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3277 | bool ASTNodeImporter::ImportDefinition(ObjCInterfaceDecl *From, |
| 3278 | ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3279 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3280 | if (To->getDefinition()) { |
| 3281 | // Check consistency of superclass. |
| 3282 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 3283 | if (FromSuper) { |
| 3284 | FromSuper = cast_or_null<ObjCInterfaceDecl>(Importer.Import(FromSuper)); |
| 3285 | if (!FromSuper) |
| 3286 | return true; |
| 3287 | } |
| 3288 | |
| 3289 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
| 3290 | if ((bool)FromSuper != (bool)ToSuper || |
| 3291 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
| 3292 | Importer.ToDiag(To->getLocation(), |
| 3293 | diag::err_odr_objc_superclass_inconsistent) |
| 3294 | << To->getDeclName(); |
| 3295 | if (ToSuper) |
| 3296 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 3297 | << To->getSuperClass()->getDeclName(); |
| 3298 | else |
| 3299 | Importer.ToDiag(To->getLocation(), |
| 3300 | diag::note_odr_objc_missing_superclass); |
| 3301 | if (From->getSuperClass()) |
| 3302 | Importer.FromDiag(From->getSuperClassLoc(), |
| 3303 | diag::note_odr_objc_superclass) |
| 3304 | << From->getSuperClass()->getDeclName(); |
| 3305 | else |
| 3306 | Importer.FromDiag(From->getLocation(), |
| 3307 | diag::note_odr_objc_missing_superclass); |
| 3308 | } |
| 3309 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3310 | if (shouldForceImportDeclContext(Kind)) |
| 3311 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3312 | return false; |
| 3313 | } |
| 3314 | |
| 3315 | // Start the definition. |
| 3316 | To->startDefinition(); |
| 3317 | |
| 3318 | // If this class has a superclass, import it. |
| 3319 | if (From->getSuperClass()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 3320 | TypeSourceInfo *SuperTInfo = Importer.Import(From->getSuperClassTInfo()); |
| 3321 | if (!SuperTInfo) |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3322 | return true; |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 3323 | |
| 3324 | To->setSuperClass(SuperTInfo); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | // Import protocols |
| 3328 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3329 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| 3330 | ObjCInterfaceDecl::protocol_loc_iterator |
| 3331 | FromProtoLoc = From->protocol_loc_begin(); |
| 3332 | |
| 3333 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3334 | FromProtoEnd = From->protocol_end(); |
| 3335 | FromProto != FromProtoEnd; |
| 3336 | ++FromProto, ++FromProtoLoc) { |
| 3337 | ObjCProtocolDecl *ToProto |
| 3338 | = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
| 3339 | if (!ToProto) |
| 3340 | return true; |
| 3341 | Protocols.push_back(ToProto); |
| 3342 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3343 | } |
| 3344 | |
| 3345 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3346 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 3347 | ProtocolLocs.data(), Importer.getToContext()); |
| 3348 | |
| 3349 | // Import categories. When the categories themselves are imported, they'll |
| 3350 | // hook themselves into this interface. |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 3351 | for (auto *Cat : From->known_categories()) |
| 3352 | Importer.Import(Cat); |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 3353 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3354 | // If we have an @implementation, import it as well. |
| 3355 | if (From->getImplementation()) { |
| 3356 | ObjCImplementationDecl *Impl = cast_or_null<ObjCImplementationDecl>( |
| 3357 | Importer.Import(From->getImplementation())); |
| 3358 | if (!Impl) |
| 3359 | return true; |
| 3360 | |
| 3361 | To->setImplementation(Impl); |
| 3362 | } |
| 3363 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3364 | if (shouldForceImportDeclContext(Kind)) { |
| 3365 | // Import all of the members of this class. |
| 3366 | ImportDeclContext(From, /*ForceImport=*/true); |
| 3367 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3368 | return false; |
| 3369 | } |
| 3370 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3371 | ObjCTypeParamList * |
| 3372 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 3373 | if (!list) |
| 3374 | return nullptr; |
| 3375 | |
| 3376 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
| 3377 | for (auto fromTypeParam : *list) { |
| 3378 | auto toTypeParam = cast_or_null<ObjCTypeParamDecl>( |
| 3379 | Importer.Import(fromTypeParam)); |
| 3380 | if (!toTypeParam) |
| 3381 | return nullptr; |
| 3382 | |
| 3383 | toTypeParams.push_back(toTypeParam); |
| 3384 | } |
| 3385 | |
| 3386 | return ObjCTypeParamList::create(Importer.getToContext(), |
| 3387 | Importer.Import(list->getLAngleLoc()), |
| 3388 | toTypeParams, |
| 3389 | Importer.Import(list->getRAngleLoc())); |
| 3390 | } |
| 3391 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3392 | Decl *ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3393 | // If this class has a definition in the translation unit we're coming from, |
| 3394 | // but this particular declaration is not that definition, import the |
| 3395 | // definition and map to that. |
| 3396 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 3397 | if (Definition && Definition != D) { |
| 3398 | Decl *ImportedDef = Importer.Import(Definition); |
| 3399 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3400 | return nullptr; |
| 3401 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3402 | return Importer.Imported(D, ImportedDef); |
| 3403 | } |
| 3404 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3405 | // Import the major distinguishing characteristics of an @interface. |
| 3406 | DeclContext *DC, *LexicalDC; |
| 3407 | DeclarationName Name; |
| 3408 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3409 | NamedDecl *ToD; |
| 3410 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3411 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3412 | if (ToD) |
| 3413 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3414 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3415 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3416 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3417 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3418 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3419 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 3420 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3421 | continue; |
| 3422 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3423 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecls[I]))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3424 | break; |
| 3425 | } |
| 3426 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3427 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3428 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3429 | if (!ToIface) { |
| 3430 | ToIface = ObjCInterfaceDecl::Create(Importer.getToContext(), DC, |
| 3431 | Importer.Import(D->getAtStartLoc()), |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3432 | Name.getAsIdentifierInfo(), |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3433 | /*TypeParamList=*/nullptr, |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3434 | /*PrevDecl=*/nullptr, Loc, |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3435 | D->isImplicitInterfaceDecl()); |
| 3436 | ToIface->setLexicalDeclContext(LexicalDC); |
| 3437 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3438 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3439 | Importer.Imported(D, ToIface); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3440 | // Import the type parameter list after calling Imported, to avoid |
| 3441 | // loops when bringing in their DeclContext. |
| 3442 | ToIface->setTypeParamList(ImportObjCTypeParamList( |
| 3443 | D->getTypeParamListAsWritten())); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3444 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3445 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToIface)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3446 | return nullptr; |
| 3447 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3448 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3449 | } |
| 3450 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3451 | Decl *ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 3452 | ObjCCategoryDecl *Category = cast_or_null<ObjCCategoryDecl>( |
| 3453 | Importer.Import(D->getCategoryDecl())); |
| 3454 | if (!Category) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3455 | return nullptr; |
| 3456 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3457 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 3458 | if (!ToImpl) { |
| 3459 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3460 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3461 | return nullptr; |
| 3462 | |
Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 3463 | SourceLocation CategoryNameLoc = Importer.Import(D->getCategoryNameLoc()); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3464 | ToImpl = ObjCCategoryImplDecl::Create(Importer.getToContext(), DC, |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3465 | Importer.Import(D->getIdentifier()), |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3466 | Category->getClassInterface(), |
| 3467 | Importer.Import(D->getLocation()), |
Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 3468 | Importer.Import(D->getAtStartLoc()), |
| 3469 | CategoryNameLoc); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3470 | |
| 3471 | DeclContext *LexicalDC = DC; |
| 3472 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3473 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3474 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3475 | return nullptr; |
| 3476 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3477 | ToImpl->setLexicalDeclContext(LexicalDC); |
| 3478 | } |
| 3479 | |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3480 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3481 | Category->setImplementation(ToImpl); |
| 3482 | } |
| 3483 | |
| 3484 | Importer.Imported(D, ToImpl); |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 3485 | ImportDeclContext(D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3486 | return ToImpl; |
| 3487 | } |
| 3488 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3489 | Decl *ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 3490 | // Find the corresponding interface. |
| 3491 | ObjCInterfaceDecl *Iface = cast_or_null<ObjCInterfaceDecl>( |
| 3492 | Importer.Import(D->getClassInterface())); |
| 3493 | if (!Iface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3494 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3495 | |
| 3496 | // Import the superclass, if any. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3497 | ObjCInterfaceDecl *Super = nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3498 | if (D->getSuperClass()) { |
| 3499 | Super = cast_or_null<ObjCInterfaceDecl>( |
| 3500 | Importer.Import(D->getSuperClass())); |
| 3501 | if (!Super) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3502 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 3506 | if (!Impl) { |
| 3507 | // We haven't imported an implementation yet. Create a new @implementation |
| 3508 | // now. |
| 3509 | Impl = ObjCImplementationDecl::Create(Importer.getToContext(), |
| 3510 | Importer.ImportContext(D->getDeclContext()), |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3511 | Iface, Super, |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3512 | Importer.Import(D->getLocation()), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3513 | Importer.Import(D->getAtStartLoc()), |
Argyrios Kyrtzidis | 5d2ce84 | 2013-05-03 22:31:26 +0000 | [diff] [blame] | 3514 | Importer.Import(D->getSuperClassLoc()), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3515 | Importer.Import(D->getIvarLBraceLoc()), |
| 3516 | Importer.Import(D->getIvarRBraceLoc())); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3517 | |
| 3518 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3519 | DeclContext *LexicalDC |
| 3520 | = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3521 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3522 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3523 | Impl->setLexicalDeclContext(LexicalDC); |
| 3524 | } |
| 3525 | |
| 3526 | // Associate the implementation with the class it implements. |
| 3527 | Iface->setImplementation(Impl); |
| 3528 | Importer.Imported(D, Iface->getImplementation()); |
| 3529 | } else { |
| 3530 | Importer.Imported(D, Iface->getImplementation()); |
| 3531 | |
| 3532 | // Verify that the existing @implementation has the same superclass. |
| 3533 | if ((Super && !Impl->getSuperClass()) || |
| 3534 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 3535 | (Super && Impl->getSuperClass() && |
| 3536 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 3537 | Impl->getSuperClass()))) { |
| 3538 | Importer.ToDiag(Impl->getLocation(), |
| 3539 | diag::err_odr_objc_superclass_inconsistent) |
| 3540 | << Iface->getDeclName(); |
| 3541 | // FIXME: It would be nice to have the location of the superclass |
| 3542 | // below. |
| 3543 | if (Impl->getSuperClass()) |
| 3544 | Importer.ToDiag(Impl->getLocation(), |
| 3545 | diag::note_odr_objc_superclass) |
| 3546 | << Impl->getSuperClass()->getDeclName(); |
| 3547 | else |
| 3548 | Importer.ToDiag(Impl->getLocation(), |
| 3549 | diag::note_odr_objc_missing_superclass); |
| 3550 | if (D->getSuperClass()) |
| 3551 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3552 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 3553 | << D->getSuperClass()->getDeclName(); |
| 3554 | else |
| 3555 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3556 | diag::note_odr_objc_missing_superclass); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3557 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3558 | } |
| 3559 | } |
| 3560 | |
| 3561 | // Import all of the members of this @implementation. |
| 3562 | ImportDeclContext(D); |
| 3563 | |
| 3564 | return Impl; |
| 3565 | } |
| 3566 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3567 | Decl *ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| 3568 | // Import the major distinguishing characteristics of an @property. |
| 3569 | DeclContext *DC, *LexicalDC; |
| 3570 | DeclarationName Name; |
| 3571 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3572 | NamedDecl *ToD; |
| 3573 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3574 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3575 | if (ToD) |
| 3576 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3577 | |
| 3578 | // Check whether we have already imported this property. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3579 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3580 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3581 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3582 | if (ObjCPropertyDecl *FoundProp |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3583 | = dyn_cast<ObjCPropertyDecl>(FoundDecls[I])) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3584 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3585 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3586 | FoundProp->getType())) { |
| 3587 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) |
| 3588 | << Name << D->getType() << FoundProp->getType(); |
| 3589 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 3590 | << FoundProp->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3591 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3592 | } |
| 3593 | |
| 3594 | // FIXME: Check property attributes, getters, setters, etc.? |
| 3595 | |
| 3596 | // Consider these properties to be equivalent. |
| 3597 | Importer.Imported(D, FoundProp); |
| 3598 | return FoundProp; |
| 3599 | } |
| 3600 | } |
| 3601 | |
| 3602 | // Import the type. |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 3603 | TypeSourceInfo *TSI = Importer.Import(D->getTypeSourceInfo()); |
| 3604 | if (!TSI) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3605 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3606 | |
| 3607 | // Create the new property. |
| 3608 | ObjCPropertyDecl *ToProperty |
| 3609 | = ObjCPropertyDecl::Create(Importer.getToContext(), DC, Loc, |
| 3610 | Name.getAsIdentifierInfo(), |
| 3611 | Importer.Import(D->getAtLoc()), |
Fariborz Jahanian | 86c2f5c | 2012-02-29 22:18:55 +0000 | [diff] [blame] | 3612 | Importer.Import(D->getLParenLoc()), |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 3613 | Importer.Import(D->getType()), |
| 3614 | TSI, |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3615 | D->getPropertyImplementation()); |
| 3616 | Importer.Imported(D, ToProperty); |
| 3617 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3618 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3619 | |
| 3620 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 3621 | ToProperty->setPropertyAttributesAsWritten( |
| 3622 | D->getPropertyAttributesAsWritten()); |
Argyrios Kyrtzidis | 194b28e | 2017-03-16 18:25:40 +0000 | [diff] [blame] | 3623 | ToProperty->setGetterName(Importer.Import(D->getGetterName()), |
| 3624 | Importer.Import(D->getGetterNameLoc())); |
| 3625 | ToProperty->setSetterName(Importer.Import(D->getSetterName()), |
| 3626 | Importer.Import(D->getSetterNameLoc())); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3627 | ToProperty->setGetterMethodDecl( |
| 3628 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getGetterMethodDecl()))); |
| 3629 | ToProperty->setSetterMethodDecl( |
| 3630 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getSetterMethodDecl()))); |
| 3631 | ToProperty->setPropertyIvarDecl( |
| 3632 | cast_or_null<ObjCIvarDecl>(Importer.Import(D->getPropertyIvarDecl()))); |
| 3633 | return ToProperty; |
| 3634 | } |
| 3635 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3636 | Decl *ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 3637 | ObjCPropertyDecl *Property = cast_or_null<ObjCPropertyDecl>( |
| 3638 | Importer.Import(D->getPropertyDecl())); |
| 3639 | if (!Property) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3640 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3641 | |
| 3642 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3643 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3644 | return nullptr; |
| 3645 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3646 | // Import the lexical declaration context. |
| 3647 | DeclContext *LexicalDC = DC; |
| 3648 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3649 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3650 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3651 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3652 | } |
| 3653 | |
| 3654 | ObjCImplDecl *InImpl = dyn_cast<ObjCImplDecl>(LexicalDC); |
| 3655 | if (!InImpl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3656 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3657 | |
| 3658 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3659 | ObjCIvarDecl *Ivar = nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3660 | if (D->getPropertyIvarDecl()) { |
| 3661 | Ivar = cast_or_null<ObjCIvarDecl>( |
| 3662 | Importer.Import(D->getPropertyIvarDecl())); |
| 3663 | if (!Ivar) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3664 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 3668 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 3669 | Property->getQueryKind()); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3670 | if (!ToImpl) { |
| 3671 | ToImpl = ObjCPropertyImplDecl::Create(Importer.getToContext(), DC, |
| 3672 | Importer.Import(D->getLocStart()), |
| 3673 | Importer.Import(D->getLocation()), |
| 3674 | Property, |
| 3675 | D->getPropertyImplementation(), |
| 3676 | Ivar, |
| 3677 | Importer.Import(D->getPropertyIvarDeclLoc())); |
| 3678 | ToImpl->setLexicalDeclContext(LexicalDC); |
| 3679 | Importer.Imported(D, ToImpl); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3680 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3681 | } else { |
| 3682 | // Check that we have the same kind of property implementation (@synthesize |
| 3683 | // vs. @dynamic). |
| 3684 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
| 3685 | Importer.ToDiag(ToImpl->getLocation(), |
| 3686 | diag::err_odr_objc_property_impl_kind_inconsistent) |
| 3687 | << Property->getDeclName() |
| 3688 | << (ToImpl->getPropertyImplementation() |
| 3689 | == ObjCPropertyImplDecl::Dynamic); |
| 3690 | Importer.FromDiag(D->getLocation(), |
| 3691 | diag::note_odr_objc_property_impl_kind) |
| 3692 | << D->getPropertyDecl()->getDeclName() |
| 3693 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3694 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3695 | } |
| 3696 | |
| 3697 | // For @synthesize, check that we have the same |
| 3698 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 3699 | Ivar != ToImpl->getPropertyIvarDecl()) { |
| 3700 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
| 3701 | diag::err_odr_objc_synthesize_ivar_inconsistent) |
| 3702 | << Property->getDeclName() |
| 3703 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 3704 | << Ivar->getDeclName(); |
| 3705 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
| 3706 | diag::note_odr_objc_synthesize_ivar_here) |
| 3707 | << D->getPropertyIvarDecl()->getDeclName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3708 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3709 | } |
| 3710 | |
| 3711 | // Merge the existing implementation with the new implementation. |
| 3712 | Importer.Imported(D, ToImpl); |
| 3713 | } |
| 3714 | |
| 3715 | return ToImpl; |
| 3716 | } |
| 3717 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3718 | Decl *ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| 3719 | // For template arguments, we adopt the translation unit as our declaration |
| 3720 | // context. This context will be fixed when the actual template declaration |
| 3721 | // is created. |
| 3722 | |
| 3723 | // FIXME: Import default argument. |
| 3724 | return TemplateTypeParmDecl::Create(Importer.getToContext(), |
| 3725 | Importer.getToContext().getTranslationUnitDecl(), |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 3726 | Importer.Import(D->getLocStart()), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3727 | Importer.Import(D->getLocation()), |
| 3728 | D->getDepth(), |
| 3729 | D->getIndex(), |
| 3730 | Importer.Import(D->getIdentifier()), |
| 3731 | D->wasDeclaredWithTypename(), |
| 3732 | D->isParameterPack()); |
| 3733 | } |
| 3734 | |
| 3735 | Decl * |
| 3736 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| 3737 | // Import the name of this declaration. |
| 3738 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 3739 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3740 | return nullptr; |
| 3741 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3742 | // Import the location of this declaration. |
| 3743 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 3744 | |
| 3745 | // Import the type of this declaration. |
| 3746 | QualType T = Importer.Import(D->getType()); |
| 3747 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3748 | return nullptr; |
| 3749 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3750 | // Import type-source information. |
| 3751 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3752 | if (D->getTypeSourceInfo() && !TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3753 | return nullptr; |
| 3754 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3755 | // FIXME: Import default argument. |
| 3756 | |
| 3757 | return NonTypeTemplateParmDecl::Create(Importer.getToContext(), |
| 3758 | Importer.getToContext().getTranslationUnitDecl(), |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 3759 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3760 | Loc, D->getDepth(), D->getPosition(), |
| 3761 | Name.getAsIdentifierInfo(), |
Douglas Gregor | da3cc0d | 2010-12-23 23:51:58 +0000 | [diff] [blame] | 3762 | T, D->isParameterPack(), TInfo); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3763 | } |
| 3764 | |
| 3765 | Decl * |
| 3766 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 3767 | // Import the name of this declaration. |
| 3768 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 3769 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3770 | return nullptr; |
| 3771 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3772 | // Import the location of this declaration. |
| 3773 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 3774 | |
| 3775 | // Import template parameters. |
| 3776 | TemplateParameterList *TemplateParams |
| 3777 | = ImportTemplateParameterList(D->getTemplateParameters()); |
| 3778 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3779 | return nullptr; |
| 3780 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3781 | // FIXME: Import default argument. |
| 3782 | |
| 3783 | return TemplateTemplateParmDecl::Create(Importer.getToContext(), |
| 3784 | Importer.getToContext().getTranslationUnitDecl(), |
| 3785 | Loc, D->getDepth(), D->getPosition(), |
Douglas Gregor | f550077 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 3786 | D->isParameterPack(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3787 | Name.getAsIdentifierInfo(), |
| 3788 | TemplateParams); |
| 3789 | } |
| 3790 | |
| 3791 | Decl *ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 3792 | // If this record has a definition in the translation unit we're coming from, |
| 3793 | // but this particular declaration is not that definition, import the |
| 3794 | // definition and map to that. |
| 3795 | CXXRecordDecl *Definition |
| 3796 | = cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition()); |
| 3797 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 3798 | Decl *ImportedDef |
| 3799 | = Importer.Import(Definition->getDescribedClassTemplate()); |
| 3800 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3801 | return nullptr; |
| 3802 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3803 | return Importer.Imported(D, ImportedDef); |
| 3804 | } |
| 3805 | |
| 3806 | // Import the major distinguishing characteristics of this class template. |
| 3807 | DeclContext *DC, *LexicalDC; |
| 3808 | DeclarationName Name; |
| 3809 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3810 | NamedDecl *ToD; |
| 3811 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3812 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3813 | if (ToD) |
| 3814 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3815 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3816 | // We may already have a template of the same name; try to find and match it. |
| 3817 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3818 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3819 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3820 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3821 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 3822 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3823 | continue; |
| 3824 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3825 | Decl *Found = FoundDecls[I]; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3826 | if (ClassTemplateDecl *FoundTemplate |
| 3827 | = dyn_cast<ClassTemplateDecl>(Found)) { |
| 3828 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 3829 | // The class templates structurally match; call it the same template. |
| 3830 | // FIXME: We may be filling in a forward declaration here. Handle |
| 3831 | // this case! |
| 3832 | Importer.Imported(D->getTemplatedDecl(), |
| 3833 | FoundTemplate->getTemplatedDecl()); |
| 3834 | return Importer.Imported(D, FoundTemplate); |
| 3835 | } |
| 3836 | } |
| 3837 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3838 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3839 | } |
| 3840 | |
| 3841 | if (!ConflictingDecls.empty()) { |
| 3842 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 3843 | ConflictingDecls.data(), |
| 3844 | ConflictingDecls.size()); |
| 3845 | } |
| 3846 | |
| 3847 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3848 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3849 | } |
| 3850 | |
| 3851 | CXXRecordDecl *DTemplated = D->getTemplatedDecl(); |
| 3852 | |
| 3853 | // Create the declaration that is being templated. |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 3854 | CXXRecordDecl *D2Templated = cast_or_null<CXXRecordDecl>( |
| 3855 | Importer.Import(DTemplated)); |
| 3856 | if (!D2Templated) |
| 3857 | return nullptr; |
| 3858 | |
| 3859 | // Resolve possible cyclic import. |
| 3860 | if (Decl *AlreadyImported = Importer.GetAlreadyImportedOrNull(D)) |
| 3861 | return AlreadyImported; |
| 3862 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3863 | // Create the class template declaration itself. |
| 3864 | TemplateParameterList *TemplateParams |
| 3865 | = ImportTemplateParameterList(D->getTemplateParameters()); |
| 3866 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3867 | return nullptr; |
| 3868 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3869 | ClassTemplateDecl *D2 = ClassTemplateDecl::Create(Importer.getToContext(), DC, |
| 3870 | Loc, Name, TemplateParams, |
Vassil Vassilev | 352e441 | 2017-01-12 09:16:26 +0000 | [diff] [blame] | 3871 | D2Templated); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3872 | D2Templated->setDescribedClassTemplate(D2); |
| 3873 | |
| 3874 | D2->setAccess(D->getAccess()); |
| 3875 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3876 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3877 | |
| 3878 | // Note the relationship between the class templates. |
| 3879 | Importer.Imported(D, D2); |
| 3880 | Importer.Imported(DTemplated, D2Templated); |
| 3881 | |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 3882 | if (DTemplated->isCompleteDefinition() && |
| 3883 | !D2Templated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3884 | // FIXME: Import definition! |
| 3885 | } |
| 3886 | |
| 3887 | return D2; |
| 3888 | } |
| 3889 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3890 | Decl *ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
| 3891 | ClassTemplateSpecializationDecl *D) { |
| 3892 | // If this record has a definition in the translation unit we're coming from, |
| 3893 | // but this particular declaration is not that definition, import the |
| 3894 | // definition and map to that. |
| 3895 | TagDecl *Definition = D->getDefinition(); |
| 3896 | if (Definition && Definition != D) { |
| 3897 | Decl *ImportedDef = Importer.Import(Definition); |
| 3898 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3899 | return nullptr; |
| 3900 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3901 | return Importer.Imported(D, ImportedDef); |
| 3902 | } |
| 3903 | |
| 3904 | ClassTemplateDecl *ClassTemplate |
| 3905 | = cast_or_null<ClassTemplateDecl>(Importer.Import( |
| 3906 | D->getSpecializedTemplate())); |
| 3907 | if (!ClassTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3908 | return nullptr; |
| 3909 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3910 | // Import the context of this declaration. |
| 3911 | DeclContext *DC = ClassTemplate->getDeclContext(); |
| 3912 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3913 | return nullptr; |
| 3914 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3915 | DeclContext *LexicalDC = DC; |
| 3916 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3917 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3918 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3919 | return nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3920 | } |
| 3921 | |
| 3922 | // Import the location of this declaration. |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 3923 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 3924 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3925 | |
| 3926 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3927 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3928 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 3929 | D->getTemplateArgs().size(), |
| 3930 | TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3931 | return nullptr; |
| 3932 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3933 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3934 | void *InsertPos = nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3935 | ClassTemplateSpecializationDecl *D2 |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 3936 | = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3937 | if (D2) { |
| 3938 | // We already have a class template specialization with these template |
| 3939 | // arguments. |
| 3940 | |
| 3941 | // FIXME: Check for specialization vs. instantiation errors. |
| 3942 | |
| 3943 | if (RecordDecl *FoundDef = D2->getDefinition()) { |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 3944 | if (!D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3945 | // The record types structurally match, or the "from" translation |
| 3946 | // unit only had a forward declaration anyway; call it the same |
| 3947 | // function. |
| 3948 | return Importer.Imported(D, FoundDef); |
| 3949 | } |
| 3950 | } |
| 3951 | } else { |
| 3952 | // Create a new specialization. |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3953 | if (ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 3954 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { |
| 3955 | |
| 3956 | // Import TemplateArgumentListInfo |
| 3957 | TemplateArgumentListInfo ToTAInfo; |
| 3958 | auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 3959 | for (unsigned I = 0, E = ASTTemplateArgs.NumTemplateArgs; I < E; ++I) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3960 | if (auto ToLoc = ImportTemplateArgumentLoc(ASTTemplateArgs[I])) |
| 3961 | ToTAInfo.addArgument(*ToLoc); |
| 3962 | else |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3963 | return nullptr; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3964 | } |
| 3965 | |
| 3966 | QualType CanonInjType = Importer.Import( |
| 3967 | PartialSpec->getInjectedSpecializationType()); |
| 3968 | if (CanonInjType.isNull()) |
| 3969 | return nullptr; |
| 3970 | CanonInjType = CanonInjType.getCanonicalType(); |
| 3971 | |
| 3972 | TemplateParameterList *ToTPList = ImportTemplateParameterList( |
| 3973 | PartialSpec->getTemplateParameters()); |
| 3974 | if (!ToTPList && PartialSpec->getTemplateParameters()) |
| 3975 | return nullptr; |
| 3976 | |
| 3977 | D2 = ClassTemplatePartialSpecializationDecl::Create( |
| 3978 | Importer.getToContext(), D->getTagKind(), DC, StartLoc, IdLoc, |
| 3979 | ToTPList, ClassTemplate, |
| 3980 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
| 3981 | ToTAInfo, CanonInjType, nullptr); |
| 3982 | |
| 3983 | } else { |
| 3984 | D2 = ClassTemplateSpecializationDecl::Create(Importer.getToContext(), |
| 3985 | D->getTagKind(), DC, |
| 3986 | StartLoc, IdLoc, |
| 3987 | ClassTemplate, |
| 3988 | TemplateArgs, |
| 3989 | /*PrevDecl=*/nullptr); |
| 3990 | } |
| 3991 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3992 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 3993 | |
| 3994 | // Add this specialization to the class template. |
| 3995 | ClassTemplate->AddSpecialization(D2, InsertPos); |
| 3996 | |
| 3997 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3998 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3999 | |
| 4000 | Importer.Imported(D, D2); |
| 4001 | |
| 4002 | if (auto *TSI = D->getTypeAsWritten()) { |
| 4003 | TypeSourceInfo *TInfo = Importer.Import(TSI); |
| 4004 | if (!TInfo) |
| 4005 | return nullptr; |
| 4006 | D2->setTypeAsWritten(TInfo); |
| 4007 | D2->setTemplateKeywordLoc(Importer.Import(D->getTemplateKeywordLoc())); |
| 4008 | D2->setExternLoc(Importer.Import(D->getExternLoc())); |
| 4009 | } |
| 4010 | |
| 4011 | SourceLocation POI = Importer.Import(D->getPointOfInstantiation()); |
| 4012 | if (POI.isValid()) |
| 4013 | D2->setPointOfInstantiation(POI); |
| 4014 | else if (D->getPointOfInstantiation().isValid()) |
| 4015 | return nullptr; |
| 4016 | |
| 4017 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 4018 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4019 | // Add the specialization to this context. |
| 4020 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4021 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4022 | } |
| 4023 | Importer.Imported(D, D2); |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4024 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4025 | return nullptr; |
| 4026 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4027 | return D2; |
| 4028 | } |
| 4029 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4030 | Decl *ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| 4031 | // If this variable has a definition in the translation unit we're coming |
| 4032 | // from, |
| 4033 | // but this particular declaration is not that definition, import the |
| 4034 | // definition and map to that. |
| 4035 | VarDecl *Definition = |
| 4036 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 4037 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 4038 | Decl *ImportedDef = Importer.Import(Definition->getDescribedVarTemplate()); |
| 4039 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4040 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4041 | |
| 4042 | return Importer.Imported(D, ImportedDef); |
| 4043 | } |
| 4044 | |
| 4045 | // Import the major distinguishing characteristics of this variable template. |
| 4046 | DeclContext *DC, *LexicalDC; |
| 4047 | DeclarationName Name; |
| 4048 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4049 | NamedDecl *ToD; |
| 4050 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4051 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4052 | if (ToD) |
| 4053 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4054 | |
| 4055 | // We may already have a template of the same name; try to find and match it. |
| 4056 | assert(!DC->isFunctionOrMethod() && |
| 4057 | "Variable templates cannot be declared at function scope"); |
| 4058 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 4059 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4060 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4061 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 4062 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
| 4063 | continue; |
| 4064 | |
| 4065 | Decl *Found = FoundDecls[I]; |
| 4066 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
| 4067 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 4068 | // The variable templates structurally match; call it the same template. |
| 4069 | Importer.Imported(D->getTemplatedDecl(), |
| 4070 | FoundTemplate->getTemplatedDecl()); |
| 4071 | return Importer.Imported(D, FoundTemplate); |
| 4072 | } |
| 4073 | } |
| 4074 | |
| 4075 | ConflictingDecls.push_back(FoundDecls[I]); |
| 4076 | } |
| 4077 | |
| 4078 | if (!ConflictingDecls.empty()) { |
| 4079 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 4080 | ConflictingDecls.data(), |
| 4081 | ConflictingDecls.size()); |
| 4082 | } |
| 4083 | |
| 4084 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4085 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4086 | |
| 4087 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 4088 | |
| 4089 | // Import the type. |
| 4090 | QualType T = Importer.Import(DTemplated->getType()); |
| 4091 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4092 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4093 | |
| 4094 | // Create the declaration that is being templated. |
| 4095 | SourceLocation StartLoc = Importer.Import(DTemplated->getLocStart()); |
| 4096 | SourceLocation IdLoc = Importer.Import(DTemplated->getLocation()); |
| 4097 | TypeSourceInfo *TInfo = Importer.Import(DTemplated->getTypeSourceInfo()); |
| 4098 | VarDecl *D2Templated = VarDecl::Create(Importer.getToContext(), DC, StartLoc, |
| 4099 | IdLoc, Name.getAsIdentifierInfo(), T, |
| 4100 | TInfo, DTemplated->getStorageClass()); |
| 4101 | D2Templated->setAccess(DTemplated->getAccess()); |
| 4102 | D2Templated->setQualifierInfo(Importer.Import(DTemplated->getQualifierLoc())); |
| 4103 | D2Templated->setLexicalDeclContext(LexicalDC); |
| 4104 | |
| 4105 | // Importer.Imported(DTemplated, D2Templated); |
| 4106 | // LexicalDC->addDeclInternal(D2Templated); |
| 4107 | |
| 4108 | // Merge the initializer. |
| 4109 | if (ImportDefinition(DTemplated, D2Templated)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4110 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4111 | |
| 4112 | // Create the variable template declaration itself. |
| 4113 | TemplateParameterList *TemplateParams = |
| 4114 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 4115 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4116 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4117 | |
| 4118 | VarTemplateDecl *D2 = VarTemplateDecl::Create( |
Richard Smith | beef345 | 2014-01-16 23:39:20 +0000 | [diff] [blame] | 4119 | Importer.getToContext(), DC, Loc, Name, TemplateParams, D2Templated); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4120 | D2Templated->setDescribedVarTemplate(D2); |
| 4121 | |
| 4122 | D2->setAccess(D->getAccess()); |
| 4123 | D2->setLexicalDeclContext(LexicalDC); |
| 4124 | LexicalDC->addDeclInternal(D2); |
| 4125 | |
| 4126 | // Note the relationship between the variable templates. |
| 4127 | Importer.Imported(D, D2); |
| 4128 | Importer.Imported(DTemplated, D2Templated); |
| 4129 | |
| 4130 | if (DTemplated->isThisDeclarationADefinition() && |
| 4131 | !D2Templated->isThisDeclarationADefinition()) { |
| 4132 | // FIXME: Import definition! |
| 4133 | } |
| 4134 | |
| 4135 | return D2; |
| 4136 | } |
| 4137 | |
| 4138 | Decl *ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
| 4139 | VarTemplateSpecializationDecl *D) { |
| 4140 | // If this record has a definition in the translation unit we're coming from, |
| 4141 | // but this particular declaration is not that definition, import the |
| 4142 | // definition and map to that. |
| 4143 | VarDecl *Definition = D->getDefinition(); |
| 4144 | if (Definition && Definition != D) { |
| 4145 | Decl *ImportedDef = Importer.Import(Definition); |
| 4146 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4147 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4148 | |
| 4149 | return Importer.Imported(D, ImportedDef); |
| 4150 | } |
| 4151 | |
| 4152 | VarTemplateDecl *VarTemplate = cast_or_null<VarTemplateDecl>( |
| 4153 | Importer.Import(D->getSpecializedTemplate())); |
| 4154 | if (!VarTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4155 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4156 | |
| 4157 | // Import the context of this declaration. |
| 4158 | DeclContext *DC = VarTemplate->getDeclContext(); |
| 4159 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4160 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4161 | |
| 4162 | DeclContext *LexicalDC = DC; |
| 4163 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4164 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4165 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4166 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4167 | } |
| 4168 | |
| 4169 | // Import the location of this declaration. |
| 4170 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 4171 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
| 4172 | |
| 4173 | // Import template arguments. |
| 4174 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| 4175 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 4176 | D->getTemplateArgs().size(), TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4177 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4178 | |
| 4179 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4180 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4181 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 4182 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4183 | if (D2) { |
| 4184 | // We already have a variable template specialization with these template |
| 4185 | // arguments. |
| 4186 | |
| 4187 | // FIXME: Check for specialization vs. instantiation errors. |
| 4188 | |
| 4189 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 4190 | if (!D->isThisDeclarationADefinition() || |
| 4191 | IsStructuralMatch(D, FoundDef)) { |
| 4192 | // The record types structurally match, or the "from" translation |
| 4193 | // unit only had a forward declaration anyway; call it the same |
| 4194 | // variable. |
| 4195 | return Importer.Imported(D, FoundDef); |
| 4196 | } |
| 4197 | } |
| 4198 | } else { |
| 4199 | |
| 4200 | // Import the type. |
| 4201 | QualType T = Importer.Import(D->getType()); |
| 4202 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4203 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4204 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 4205 | |
| 4206 | // Create a new specialization. |
| 4207 | D2 = VarTemplateSpecializationDecl::Create( |
| 4208 | Importer.getToContext(), DC, StartLoc, IdLoc, VarTemplate, T, TInfo, |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 4209 | D->getStorageClass(), TemplateArgs); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4210 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 4211 | D2->setTemplateArgsInfo(D->getTemplateArgsInfo()); |
| 4212 | |
| 4213 | // Add this specialization to the class template. |
| 4214 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 4215 | |
| 4216 | // Import the qualifier, if any. |
| 4217 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
| 4218 | |
| 4219 | // Add the specialization to this context. |
| 4220 | D2->setLexicalDeclContext(LexicalDC); |
| 4221 | LexicalDC->addDeclInternal(D2); |
| 4222 | } |
| 4223 | Importer.Imported(D, D2); |
| 4224 | |
| 4225 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4226 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4227 | |
| 4228 | return D2; |
| 4229 | } |
| 4230 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4231 | Decl *ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 4232 | DeclContext *DC, *LexicalDC; |
| 4233 | DeclarationName Name; |
| 4234 | SourceLocation Loc; |
| 4235 | NamedDecl *ToD; |
| 4236 | |
| 4237 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4238 | return nullptr; |
| 4239 | |
| 4240 | if (ToD) |
| 4241 | return ToD; |
| 4242 | |
| 4243 | // Try to find a function in our own ("to") context with the same name, same |
| 4244 | // type, and in the same context as the function we're importing. |
| 4245 | if (!LexicalDC->isFunctionOrMethod()) { |
| 4246 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 4247 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 4248 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
| 4249 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 4250 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
| 4251 | continue; |
| 4252 | |
| 4253 | if (FunctionTemplateDecl *FoundFunction = |
| 4254 | dyn_cast<FunctionTemplateDecl>(FoundDecls[I])) { |
| 4255 | if (FoundFunction->hasExternalFormalLinkage() && |
| 4256 | D->hasExternalFormalLinkage()) { |
| 4257 | if (IsStructuralMatch(D, FoundFunction)) { |
| 4258 | Importer.Imported(D, FoundFunction); |
| 4259 | // FIXME: Actually try to merge the body and other attributes. |
| 4260 | return FoundFunction; |
| 4261 | } |
| 4262 | } |
| 4263 | } |
| 4264 | } |
| 4265 | } |
| 4266 | |
| 4267 | TemplateParameterList *Params = |
| 4268 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 4269 | if (!Params) |
| 4270 | return nullptr; |
| 4271 | |
| 4272 | FunctionDecl *TemplatedFD = |
| 4273 | cast_or_null<FunctionDecl>(Importer.Import(D->getTemplatedDecl())); |
| 4274 | if (!TemplatedFD) |
| 4275 | return nullptr; |
| 4276 | |
| 4277 | FunctionTemplateDecl *ToFunc = FunctionTemplateDecl::Create( |
| 4278 | Importer.getToContext(), DC, Loc, Name, Params, TemplatedFD); |
| 4279 | |
| 4280 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| 4281 | ToFunc->setAccess(D->getAccess()); |
| 4282 | ToFunc->setLexicalDeclContext(LexicalDC); |
| 4283 | Importer.Imported(D, ToFunc); |
| 4284 | |
| 4285 | LexicalDC->addDeclInternal(ToFunc); |
| 4286 | return ToFunc; |
| 4287 | } |
| 4288 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4289 | //---------------------------------------------------------------------------- |
| 4290 | // Import Statements |
| 4291 | //---------------------------------------------------------------------------- |
| 4292 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4293 | DeclGroupRef ASTNodeImporter::ImportDeclGroup(DeclGroupRef DG) { |
| 4294 | if (DG.isNull()) |
| 4295 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 4296 | size_t NumDecls = DG.end() - DG.begin(); |
| 4297 | SmallVector<Decl *, 1> ToDecls(NumDecls); |
| 4298 | auto &_Importer = this->Importer; |
| 4299 | std::transform(DG.begin(), DG.end(), ToDecls.begin(), |
| 4300 | [&_Importer](Decl *D) -> Decl * { |
| 4301 | return _Importer.Import(D); |
| 4302 | }); |
| 4303 | return DeclGroupRef::Create(Importer.getToContext(), |
| 4304 | ToDecls.begin(), |
| 4305 | NumDecls); |
| 4306 | } |
| 4307 | |
| 4308 | Stmt *ASTNodeImporter::VisitStmt(Stmt *S) { |
| 4309 | Importer.FromDiag(S->getLocStart(), diag::err_unsupported_ast_node) |
| 4310 | << S->getStmtClassName(); |
| 4311 | return nullptr; |
| 4312 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4313 | |
| 4314 | |
| 4315 | Stmt *ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
| 4316 | SmallVector<IdentifierInfo *, 4> Names; |
| 4317 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 4318 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 4319 | // ToII is nullptr when no symbolic name is given for output operand |
| 4320 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 4321 | if (!ToII && S->getOutputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4322 | return nullptr; |
| 4323 | Names.push_back(ToII); |
| 4324 | } |
| 4325 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 4326 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 4327 | // ToII is nullptr when no symbolic name is given for input operand |
| 4328 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 4329 | if (!ToII && S->getInputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4330 | return nullptr; |
| 4331 | Names.push_back(ToII); |
| 4332 | } |
| 4333 | |
| 4334 | SmallVector<StringLiteral *, 4> Clobbers; |
| 4335 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
| 4336 | StringLiteral *Clobber = cast_or_null<StringLiteral>( |
| 4337 | Importer.Import(S->getClobberStringLiteral(I))); |
| 4338 | if (!Clobber) |
| 4339 | return nullptr; |
| 4340 | Clobbers.push_back(Clobber); |
| 4341 | } |
| 4342 | |
| 4343 | SmallVector<StringLiteral *, 4> Constraints; |
| 4344 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 4345 | StringLiteral *Output = cast_or_null<StringLiteral>( |
| 4346 | Importer.Import(S->getOutputConstraintLiteral(I))); |
| 4347 | if (!Output) |
| 4348 | return nullptr; |
| 4349 | Constraints.push_back(Output); |
| 4350 | } |
| 4351 | |
| 4352 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 4353 | StringLiteral *Input = cast_or_null<StringLiteral>( |
| 4354 | Importer.Import(S->getInputConstraintLiteral(I))); |
| 4355 | if (!Input) |
| 4356 | return nullptr; |
| 4357 | Constraints.push_back(Input); |
| 4358 | } |
| 4359 | |
| 4360 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4361 | if (ImportContainerChecked(S->outputs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4362 | return nullptr; |
| 4363 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4364 | if (ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4365 | return nullptr; |
| 4366 | |
| 4367 | StringLiteral *AsmStr = cast_or_null<StringLiteral>( |
| 4368 | Importer.Import(S->getAsmString())); |
| 4369 | if (!AsmStr) |
| 4370 | return nullptr; |
| 4371 | |
| 4372 | return new (Importer.getToContext()) GCCAsmStmt( |
| 4373 | Importer.getToContext(), |
| 4374 | Importer.Import(S->getAsmLoc()), |
| 4375 | S->isSimple(), |
| 4376 | S->isVolatile(), |
| 4377 | S->getNumOutputs(), |
| 4378 | S->getNumInputs(), |
| 4379 | Names.data(), |
| 4380 | Constraints.data(), |
| 4381 | Exprs.data(), |
| 4382 | AsmStr, |
| 4383 | S->getNumClobbers(), |
| 4384 | Clobbers.data(), |
| 4385 | Importer.Import(S->getRParenLoc())); |
| 4386 | } |
| 4387 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4388 | Stmt *ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 4389 | DeclGroupRef ToDG = ImportDeclGroup(S->getDeclGroup()); |
| 4390 | for (Decl *ToD : ToDG) { |
| 4391 | if (!ToD) |
| 4392 | return nullptr; |
| 4393 | } |
| 4394 | SourceLocation ToStartLoc = Importer.Import(S->getStartLoc()); |
| 4395 | SourceLocation ToEndLoc = Importer.Import(S->getEndLoc()); |
| 4396 | return new (Importer.getToContext()) DeclStmt(ToDG, ToStartLoc, ToEndLoc); |
| 4397 | } |
| 4398 | |
| 4399 | Stmt *ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 4400 | SourceLocation ToSemiLoc = Importer.Import(S->getSemiLoc()); |
| 4401 | return new (Importer.getToContext()) NullStmt(ToSemiLoc, |
| 4402 | S->hasLeadingEmptyMacro()); |
| 4403 | } |
| 4404 | |
| 4405 | Stmt *ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4406 | llvm::SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4407 | |
| 4408 | if (ImportContainerChecked(S->body(), ToStmts)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 4409 | return nullptr; |
| 4410 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4411 | SourceLocation ToLBraceLoc = Importer.Import(S->getLBracLoc()); |
| 4412 | SourceLocation ToRBraceLoc = Importer.Import(S->getRBracLoc()); |
Benjamin Kramer | 0742090 | 2017-12-24 16:24:20 +0000 | [diff] [blame] | 4413 | return CompoundStmt::Create(Importer.getToContext(), ToStmts, ToLBraceLoc, |
| 4414 | ToRBraceLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4415 | } |
| 4416 | |
| 4417 | Stmt *ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 4418 | Expr *ToLHS = Importer.Import(S->getLHS()); |
| 4419 | if (!ToLHS) |
| 4420 | return nullptr; |
| 4421 | Expr *ToRHS = Importer.Import(S->getRHS()); |
| 4422 | if (!ToRHS && S->getRHS()) |
| 4423 | return nullptr; |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 4424 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4425 | if (!ToSubStmt && S->getSubStmt()) |
| 4426 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4427 | SourceLocation ToCaseLoc = Importer.Import(S->getCaseLoc()); |
| 4428 | SourceLocation ToEllipsisLoc = Importer.Import(S->getEllipsisLoc()); |
| 4429 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 4430 | CaseStmt *ToStmt = new (Importer.getToContext()) |
| 4431 | CaseStmt(ToLHS, ToRHS, ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
| 4432 | ToStmt->setSubStmt(ToSubStmt); |
| 4433 | return ToStmt; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4434 | } |
| 4435 | |
| 4436 | Stmt *ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 4437 | SourceLocation ToDefaultLoc = Importer.Import(S->getDefaultLoc()); |
| 4438 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 4439 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4440 | if (!ToSubStmt && S->getSubStmt()) |
| 4441 | return nullptr; |
| 4442 | return new (Importer.getToContext()) DefaultStmt(ToDefaultLoc, ToColonLoc, |
| 4443 | ToSubStmt); |
| 4444 | } |
| 4445 | |
| 4446 | Stmt *ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 4447 | SourceLocation ToIdentLoc = Importer.Import(S->getIdentLoc()); |
| 4448 | LabelDecl *ToLabelDecl = |
| 4449 | cast_or_null<LabelDecl>(Importer.Import(S->getDecl())); |
| 4450 | if (!ToLabelDecl && S->getDecl()) |
| 4451 | return nullptr; |
| 4452 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4453 | if (!ToSubStmt && S->getSubStmt()) |
| 4454 | return nullptr; |
| 4455 | return new (Importer.getToContext()) LabelStmt(ToIdentLoc, ToLabelDecl, |
| 4456 | ToSubStmt); |
| 4457 | } |
| 4458 | |
| 4459 | Stmt *ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 4460 | SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc()); |
| 4461 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 4462 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
| 4463 | ASTContext &_ToContext = Importer.getToContext(); |
| 4464 | std::transform(FromAttrs.begin(), FromAttrs.end(), ToAttrs.begin(), |
| 4465 | [&_ToContext](const Attr *A) -> const Attr * { |
| 4466 | return A->clone(_ToContext); |
| 4467 | }); |
| 4468 | for (const Attr *ToA : ToAttrs) { |
| 4469 | if (!ToA) |
| 4470 | return nullptr; |
| 4471 | } |
| 4472 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4473 | if (!ToSubStmt && S->getSubStmt()) |
| 4474 | return nullptr; |
| 4475 | return AttributedStmt::Create(Importer.getToContext(), ToAttrLoc, |
| 4476 | ToAttrs, ToSubStmt); |
| 4477 | } |
| 4478 | |
| 4479 | Stmt *ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 4480 | SourceLocation ToIfLoc = Importer.Import(S->getIfLoc()); |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4481 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4482 | if (!ToInit && S->getInit()) |
| 4483 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4484 | VarDecl *ToConditionVariable = nullptr; |
| 4485 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4486 | ToConditionVariable = |
| 4487 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4488 | if (!ToConditionVariable) |
| 4489 | return nullptr; |
| 4490 | } |
| 4491 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4492 | if (!ToCondition && S->getCond()) |
| 4493 | return nullptr; |
| 4494 | Stmt *ToThenStmt = Importer.Import(S->getThen()); |
| 4495 | if (!ToThenStmt && S->getThen()) |
| 4496 | return nullptr; |
| 4497 | SourceLocation ToElseLoc = Importer.Import(S->getElseLoc()); |
| 4498 | Stmt *ToElseStmt = Importer.Import(S->getElse()); |
| 4499 | if (!ToElseStmt && S->getElse()) |
| 4500 | return nullptr; |
| 4501 | return new (Importer.getToContext()) IfStmt(Importer.getToContext(), |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 4502 | ToIfLoc, S->isConstexpr(), |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4503 | ToInit, |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 4504 | ToConditionVariable, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4505 | ToCondition, ToThenStmt, |
| 4506 | ToElseLoc, ToElseStmt); |
| 4507 | } |
| 4508 | |
| 4509 | Stmt *ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4510 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4511 | if (!ToInit && S->getInit()) |
| 4512 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4513 | VarDecl *ToConditionVariable = nullptr; |
| 4514 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4515 | ToConditionVariable = |
| 4516 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4517 | if (!ToConditionVariable) |
| 4518 | return nullptr; |
| 4519 | } |
| 4520 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4521 | if (!ToCondition && S->getCond()) |
| 4522 | return nullptr; |
| 4523 | SwitchStmt *ToStmt = new (Importer.getToContext()) SwitchStmt( |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4524 | Importer.getToContext(), ToInit, |
| 4525 | ToConditionVariable, ToCondition); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4526 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4527 | if (!ToBody && S->getBody()) |
| 4528 | return nullptr; |
| 4529 | ToStmt->setBody(ToBody); |
| 4530 | ToStmt->setSwitchLoc(Importer.Import(S->getSwitchLoc())); |
| 4531 | // Now we have to re-chain the cases. |
| 4532 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 4533 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 4534 | SC = SC->getNextSwitchCase()) { |
| 4535 | SwitchCase *ToSC = dyn_cast_or_null<SwitchCase>(Importer.Import(SC)); |
| 4536 | if (!ToSC) |
| 4537 | return nullptr; |
| 4538 | if (LastChainedSwitchCase) |
| 4539 | LastChainedSwitchCase->setNextSwitchCase(ToSC); |
| 4540 | else |
| 4541 | ToStmt->setSwitchCaseList(ToSC); |
| 4542 | LastChainedSwitchCase = ToSC; |
| 4543 | } |
| 4544 | return ToStmt; |
| 4545 | } |
| 4546 | |
| 4547 | Stmt *ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 4548 | VarDecl *ToConditionVariable = nullptr; |
| 4549 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4550 | ToConditionVariable = |
| 4551 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4552 | if (!ToConditionVariable) |
| 4553 | return nullptr; |
| 4554 | } |
| 4555 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4556 | if (!ToCondition && S->getCond()) |
| 4557 | return nullptr; |
| 4558 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4559 | if (!ToBody && S->getBody()) |
| 4560 | return nullptr; |
| 4561 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 4562 | return new (Importer.getToContext()) WhileStmt(Importer.getToContext(), |
| 4563 | ToConditionVariable, |
| 4564 | ToCondition, ToBody, |
| 4565 | ToWhileLoc); |
| 4566 | } |
| 4567 | |
| 4568 | Stmt *ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 4569 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4570 | if (!ToBody && S->getBody()) |
| 4571 | return nullptr; |
| 4572 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4573 | if (!ToCondition && S->getCond()) |
| 4574 | return nullptr; |
| 4575 | SourceLocation ToDoLoc = Importer.Import(S->getDoLoc()); |
| 4576 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 4577 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4578 | return new (Importer.getToContext()) DoStmt(ToBody, ToCondition, |
| 4579 | ToDoLoc, ToWhileLoc, |
| 4580 | ToRParenLoc); |
| 4581 | } |
| 4582 | |
| 4583 | Stmt *ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 4584 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4585 | if (!ToInit && S->getInit()) |
| 4586 | return nullptr; |
| 4587 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4588 | if (!ToCondition && S->getCond()) |
| 4589 | return nullptr; |
| 4590 | VarDecl *ToConditionVariable = nullptr; |
| 4591 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4592 | ToConditionVariable = |
| 4593 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4594 | if (!ToConditionVariable) |
| 4595 | return nullptr; |
| 4596 | } |
| 4597 | Expr *ToInc = Importer.Import(S->getInc()); |
| 4598 | if (!ToInc && S->getInc()) |
| 4599 | return nullptr; |
| 4600 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4601 | if (!ToBody && S->getBody()) |
| 4602 | return nullptr; |
| 4603 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 4604 | SourceLocation ToLParenLoc = Importer.Import(S->getLParenLoc()); |
| 4605 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4606 | return new (Importer.getToContext()) ForStmt(Importer.getToContext(), |
| 4607 | ToInit, ToCondition, |
| 4608 | ToConditionVariable, |
| 4609 | ToInc, ToBody, |
| 4610 | ToForLoc, ToLParenLoc, |
| 4611 | ToRParenLoc); |
| 4612 | } |
| 4613 | |
| 4614 | Stmt *ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 4615 | LabelDecl *ToLabel = nullptr; |
| 4616 | if (LabelDecl *FromLabel = S->getLabel()) { |
| 4617 | ToLabel = dyn_cast_or_null<LabelDecl>(Importer.Import(FromLabel)); |
| 4618 | if (!ToLabel) |
| 4619 | return nullptr; |
| 4620 | } |
| 4621 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 4622 | SourceLocation ToLabelLoc = Importer.Import(S->getLabelLoc()); |
| 4623 | return new (Importer.getToContext()) GotoStmt(ToLabel, |
| 4624 | ToGotoLoc, ToLabelLoc); |
| 4625 | } |
| 4626 | |
| 4627 | Stmt *ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 4628 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 4629 | SourceLocation ToStarLoc = Importer.Import(S->getStarLoc()); |
| 4630 | Expr *ToTarget = Importer.Import(S->getTarget()); |
| 4631 | if (!ToTarget && S->getTarget()) |
| 4632 | return nullptr; |
| 4633 | return new (Importer.getToContext()) IndirectGotoStmt(ToGotoLoc, ToStarLoc, |
| 4634 | ToTarget); |
| 4635 | } |
| 4636 | |
| 4637 | Stmt *ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 4638 | SourceLocation ToContinueLoc = Importer.Import(S->getContinueLoc()); |
| 4639 | return new (Importer.getToContext()) ContinueStmt(ToContinueLoc); |
| 4640 | } |
| 4641 | |
| 4642 | Stmt *ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 4643 | SourceLocation ToBreakLoc = Importer.Import(S->getBreakLoc()); |
| 4644 | return new (Importer.getToContext()) BreakStmt(ToBreakLoc); |
| 4645 | } |
| 4646 | |
| 4647 | Stmt *ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 4648 | SourceLocation ToRetLoc = Importer.Import(S->getReturnLoc()); |
| 4649 | Expr *ToRetExpr = Importer.Import(S->getRetValue()); |
| 4650 | if (!ToRetExpr && S->getRetValue()) |
| 4651 | return nullptr; |
| 4652 | VarDecl *NRVOCandidate = const_cast<VarDecl*>(S->getNRVOCandidate()); |
| 4653 | VarDecl *ToNRVOCandidate = cast_or_null<VarDecl>(Importer.Import(NRVOCandidate)); |
| 4654 | if (!ToNRVOCandidate && NRVOCandidate) |
| 4655 | return nullptr; |
| 4656 | return new (Importer.getToContext()) ReturnStmt(ToRetLoc, ToRetExpr, |
| 4657 | ToNRVOCandidate); |
| 4658 | } |
| 4659 | |
| 4660 | Stmt *ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 4661 | SourceLocation ToCatchLoc = Importer.Import(S->getCatchLoc()); |
| 4662 | VarDecl *ToExceptionDecl = nullptr; |
| 4663 | if (VarDecl *FromExceptionDecl = S->getExceptionDecl()) { |
| 4664 | ToExceptionDecl = |
| 4665 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 4666 | if (!ToExceptionDecl) |
| 4667 | return nullptr; |
| 4668 | } |
| 4669 | Stmt *ToHandlerBlock = Importer.Import(S->getHandlerBlock()); |
| 4670 | if (!ToHandlerBlock && S->getHandlerBlock()) |
| 4671 | return nullptr; |
| 4672 | return new (Importer.getToContext()) CXXCatchStmt(ToCatchLoc, |
| 4673 | ToExceptionDecl, |
| 4674 | ToHandlerBlock); |
| 4675 | } |
| 4676 | |
| 4677 | Stmt *ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 4678 | SourceLocation ToTryLoc = Importer.Import(S->getTryLoc()); |
| 4679 | Stmt *ToTryBlock = Importer.Import(S->getTryBlock()); |
| 4680 | if (!ToTryBlock && S->getTryBlock()) |
| 4681 | return nullptr; |
| 4682 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 4683 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 4684 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
| 4685 | if (Stmt *ToHandler = Importer.Import(FromHandler)) |
| 4686 | ToHandlers[HI] = ToHandler; |
| 4687 | else |
| 4688 | return nullptr; |
| 4689 | } |
| 4690 | return CXXTryStmt::Create(Importer.getToContext(), ToTryLoc, ToTryBlock, |
| 4691 | ToHandlers); |
| 4692 | } |
| 4693 | |
| 4694 | Stmt *ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
| 4695 | DeclStmt *ToRange = |
| 4696 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getRangeStmt())); |
| 4697 | if (!ToRange && S->getRangeStmt()) |
| 4698 | return nullptr; |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 4699 | DeclStmt *ToBegin = |
| 4700 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getBeginStmt())); |
| 4701 | if (!ToBegin && S->getBeginStmt()) |
| 4702 | return nullptr; |
| 4703 | DeclStmt *ToEnd = |
| 4704 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getEndStmt())); |
| 4705 | if (!ToEnd && S->getEndStmt()) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4706 | return nullptr; |
| 4707 | Expr *ToCond = Importer.Import(S->getCond()); |
| 4708 | if (!ToCond && S->getCond()) |
| 4709 | return nullptr; |
| 4710 | Expr *ToInc = Importer.Import(S->getInc()); |
| 4711 | if (!ToInc && S->getInc()) |
| 4712 | return nullptr; |
| 4713 | DeclStmt *ToLoopVar = |
| 4714 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getLoopVarStmt())); |
| 4715 | if (!ToLoopVar && S->getLoopVarStmt()) |
| 4716 | return nullptr; |
| 4717 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4718 | if (!ToBody && S->getBody()) |
| 4719 | return nullptr; |
| 4720 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 4721 | SourceLocation ToCoawaitLoc = Importer.Import(S->getCoawaitLoc()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4722 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 4723 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 4724 | return new (Importer.getToContext()) CXXForRangeStmt(ToRange, ToBegin, ToEnd, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4725 | ToCond, ToInc, |
| 4726 | ToLoopVar, ToBody, |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 4727 | ToForLoc, ToCoawaitLoc, |
| 4728 | ToColonLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4729 | } |
| 4730 | |
| 4731 | Stmt *ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 4732 | Stmt *ToElem = Importer.Import(S->getElement()); |
| 4733 | if (!ToElem && S->getElement()) |
| 4734 | return nullptr; |
| 4735 | Expr *ToCollect = Importer.Import(S->getCollection()); |
| 4736 | if (!ToCollect && S->getCollection()) |
| 4737 | return nullptr; |
| 4738 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4739 | if (!ToBody && S->getBody()) |
| 4740 | return nullptr; |
| 4741 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 4742 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4743 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElem, |
| 4744 | ToCollect, |
| 4745 | ToBody, ToForLoc, |
| 4746 | ToRParenLoc); |
| 4747 | } |
| 4748 | |
| 4749 | Stmt *ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 4750 | SourceLocation ToAtCatchLoc = Importer.Import(S->getAtCatchLoc()); |
| 4751 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4752 | VarDecl *ToExceptionDecl = nullptr; |
| 4753 | if (VarDecl *FromExceptionDecl = S->getCatchParamDecl()) { |
| 4754 | ToExceptionDecl = |
| 4755 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 4756 | if (!ToExceptionDecl) |
| 4757 | return nullptr; |
| 4758 | } |
| 4759 | Stmt *ToBody = Importer.Import(S->getCatchBody()); |
| 4760 | if (!ToBody && S->getCatchBody()) |
| 4761 | return nullptr; |
| 4762 | return new (Importer.getToContext()) ObjCAtCatchStmt(ToAtCatchLoc, |
| 4763 | ToRParenLoc, |
| 4764 | ToExceptionDecl, |
| 4765 | ToBody); |
| 4766 | } |
| 4767 | |
| 4768 | Stmt *ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 4769 | SourceLocation ToAtFinallyLoc = Importer.Import(S->getAtFinallyLoc()); |
| 4770 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyBody()); |
| 4771 | if (!ToAtFinallyStmt && S->getFinallyBody()) |
| 4772 | return nullptr; |
| 4773 | return new (Importer.getToContext()) ObjCAtFinallyStmt(ToAtFinallyLoc, |
| 4774 | ToAtFinallyStmt); |
| 4775 | } |
| 4776 | |
| 4777 | Stmt *ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 4778 | SourceLocation ToAtTryLoc = Importer.Import(S->getAtTryLoc()); |
| 4779 | Stmt *ToAtTryStmt = Importer.Import(S->getTryBody()); |
| 4780 | if (!ToAtTryStmt && S->getTryBody()) |
| 4781 | return nullptr; |
| 4782 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 4783 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 4784 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
| 4785 | if (Stmt *ToCatchStmt = Importer.Import(FromCatchStmt)) |
| 4786 | ToCatchStmts[CI] = ToCatchStmt; |
| 4787 | else |
| 4788 | return nullptr; |
| 4789 | } |
| 4790 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyStmt()); |
| 4791 | if (!ToAtFinallyStmt && S->getFinallyStmt()) |
| 4792 | return nullptr; |
| 4793 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
| 4794 | ToAtTryLoc, ToAtTryStmt, |
| 4795 | ToCatchStmts.begin(), ToCatchStmts.size(), |
| 4796 | ToAtFinallyStmt); |
| 4797 | } |
| 4798 | |
| 4799 | Stmt *ASTNodeImporter::VisitObjCAtSynchronizedStmt |
| 4800 | (ObjCAtSynchronizedStmt *S) { |
| 4801 | SourceLocation ToAtSynchronizedLoc = |
| 4802 | Importer.Import(S->getAtSynchronizedLoc()); |
| 4803 | Expr *ToSynchExpr = Importer.Import(S->getSynchExpr()); |
| 4804 | if (!ToSynchExpr && S->getSynchExpr()) |
| 4805 | return nullptr; |
| 4806 | Stmt *ToSynchBody = Importer.Import(S->getSynchBody()); |
| 4807 | if (!ToSynchBody && S->getSynchBody()) |
| 4808 | return nullptr; |
| 4809 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 4810 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 4811 | } |
| 4812 | |
| 4813 | Stmt *ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 4814 | SourceLocation ToAtThrowLoc = Importer.Import(S->getThrowLoc()); |
| 4815 | Expr *ToThrow = Importer.Import(S->getThrowExpr()); |
| 4816 | if (!ToThrow && S->getThrowExpr()) |
| 4817 | return nullptr; |
| 4818 | return new (Importer.getToContext()) ObjCAtThrowStmt(ToAtThrowLoc, ToThrow); |
| 4819 | } |
| 4820 | |
| 4821 | Stmt *ASTNodeImporter::VisitObjCAutoreleasePoolStmt |
| 4822 | (ObjCAutoreleasePoolStmt *S) { |
| 4823 | SourceLocation ToAtLoc = Importer.Import(S->getAtLoc()); |
| 4824 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4825 | if (!ToSubStmt && S->getSubStmt()) |
| 4826 | return nullptr; |
| 4827 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(ToAtLoc, |
| 4828 | ToSubStmt); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4829 | } |
| 4830 | |
| 4831 | //---------------------------------------------------------------------------- |
| 4832 | // Import Expressions |
| 4833 | //---------------------------------------------------------------------------- |
| 4834 | Expr *ASTNodeImporter::VisitExpr(Expr *E) { |
| 4835 | Importer.FromDiag(E->getLocStart(), diag::err_unsupported_ast_node) |
| 4836 | << E->getStmtClassName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4837 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4838 | } |
| 4839 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4840 | Expr *ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 4841 | QualType T = Importer.Import(E->getType()); |
| 4842 | if (T.isNull()) |
| 4843 | return nullptr; |
| 4844 | |
| 4845 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 4846 | if (!SubExpr && E->getSubExpr()) |
| 4847 | return nullptr; |
| 4848 | |
| 4849 | TypeSourceInfo *TInfo = Importer.Import(E->getWrittenTypeInfo()); |
| 4850 | if (!TInfo) |
| 4851 | return nullptr; |
| 4852 | |
| 4853 | return new (Importer.getToContext()) VAArgExpr( |
| 4854 | Importer.Import(E->getBuiltinLoc()), SubExpr, TInfo, |
| 4855 | Importer.Import(E->getRParenLoc()), T, E->isMicrosoftABI()); |
| 4856 | } |
| 4857 | |
| 4858 | |
| 4859 | Expr *ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 4860 | QualType T = Importer.Import(E->getType()); |
| 4861 | if (T.isNull()) |
| 4862 | return nullptr; |
| 4863 | |
| 4864 | return new (Importer.getToContext()) GNUNullExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4865 | T, Importer.Import(E->getLocStart())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4866 | } |
| 4867 | |
| 4868 | Expr *ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 4869 | QualType T = Importer.Import(E->getType()); |
| 4870 | if (T.isNull()) |
| 4871 | return nullptr; |
| 4872 | |
| 4873 | StringLiteral *SL = cast_or_null<StringLiteral>( |
| 4874 | Importer.Import(E->getFunctionName())); |
| 4875 | if (!SL && E->getFunctionName()) |
| 4876 | return nullptr; |
| 4877 | |
| 4878 | return new (Importer.getToContext()) PredefinedExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4879 | Importer.Import(E->getLocStart()), T, E->getIdentType(), SL); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4880 | } |
| 4881 | |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 4882 | Expr *ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 4883 | ValueDecl *ToD = cast_or_null<ValueDecl>(Importer.Import(E->getDecl())); |
| 4884 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4885 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 4886 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4887 | NamedDecl *FoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 4888 | if (E->getDecl() != E->getFoundDecl()) { |
| 4889 | FoundD = cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl())); |
| 4890 | if (!FoundD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4891 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 4892 | } |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 4893 | |
| 4894 | QualType T = Importer.Import(E->getType()); |
| 4895 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4896 | return nullptr; |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 4897 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4898 | |
| 4899 | TemplateArgumentListInfo ToTAInfo; |
| 4900 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 4901 | if (E->hasExplicitTemplateArgs()) { |
| 4902 | for (const auto &FromLoc : E->template_arguments()) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4903 | if (auto ToTALoc = ImportTemplateArgumentLoc(FromLoc)) |
| 4904 | ToTAInfo.addArgument(*ToTALoc); |
| 4905 | else |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4906 | return nullptr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4907 | } |
| 4908 | ResInfo = &ToTAInfo; |
| 4909 | } |
| 4910 | |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 4911 | DeclRefExpr *DRE = DeclRefExpr::Create(Importer.getToContext(), |
| 4912 | Importer.Import(E->getQualifierLoc()), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 4913 | Importer.Import(E->getTemplateKeywordLoc()), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 4914 | ToD, |
Alexey Bataev | 19acc3d | 2015-01-12 10:17:46 +0000 | [diff] [blame] | 4915 | E->refersToEnclosingVariableOrCapture(), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 4916 | Importer.Import(E->getLocation()), |
| 4917 | T, E->getValueKind(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4918 | FoundD, ResInfo); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 4919 | if (E->hadMultipleCandidates()) |
| 4920 | DRE->setHadMultipleCandidates(true); |
| 4921 | return DRE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 4922 | } |
| 4923 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4924 | Expr *ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 4925 | QualType T = Importer.Import(E->getType()); |
| 4926 | if (T.isNull()) |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4927 | return nullptr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4928 | |
| 4929 | return new (Importer.getToContext()) ImplicitValueInitExpr(T); |
| 4930 | } |
| 4931 | |
| 4932 | ASTNodeImporter::Designator |
| 4933 | ASTNodeImporter::ImportDesignator(const Designator &D) { |
| 4934 | if (D.isFieldDesignator()) { |
| 4935 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 4936 | // Caller checks for import error |
| 4937 | return Designator(ToFieldName, Importer.Import(D.getDotLoc()), |
| 4938 | Importer.Import(D.getFieldLoc())); |
| 4939 | } |
| 4940 | if (D.isArrayDesignator()) |
| 4941 | return Designator(D.getFirstExprIndex(), |
| 4942 | Importer.Import(D.getLBracketLoc()), |
| 4943 | Importer.Import(D.getRBracketLoc())); |
| 4944 | |
| 4945 | assert(D.isArrayRangeDesignator()); |
| 4946 | return Designator(D.getFirstExprIndex(), |
| 4947 | Importer.Import(D.getLBracketLoc()), |
| 4948 | Importer.Import(D.getEllipsisLoc()), |
| 4949 | Importer.Import(D.getRBracketLoc())); |
| 4950 | } |
| 4951 | |
| 4952 | |
| 4953 | Expr *ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *DIE) { |
| 4954 | Expr *Init = cast_or_null<Expr>(Importer.Import(DIE->getInit())); |
| 4955 | if (!Init) |
| 4956 | return nullptr; |
| 4957 | |
| 4958 | SmallVector<Expr *, 4> IndexExprs(DIE->getNumSubExprs() - 1); |
| 4959 | // List elements from the second, the first is Init itself |
| 4960 | for (unsigned I = 1, E = DIE->getNumSubExprs(); I < E; I++) { |
| 4961 | if (Expr *Arg = cast_or_null<Expr>(Importer.Import(DIE->getSubExpr(I)))) |
| 4962 | IndexExprs[I - 1] = Arg; |
| 4963 | else |
| 4964 | return nullptr; |
| 4965 | } |
| 4966 | |
| 4967 | SmallVector<Designator, 4> Designators(DIE->size()); |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 4968 | llvm::transform(DIE->designators(), Designators.begin(), |
| 4969 | [this](const Designator &D) -> Designator { |
| 4970 | return ImportDesignator(D); |
| 4971 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4972 | |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 4973 | for (const Designator &D : DIE->designators()) |
| 4974 | if (D.isFieldDesignator() && !D.getFieldName()) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4975 | return nullptr; |
| 4976 | |
| 4977 | return DesignatedInitExpr::Create( |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 4978 | Importer.getToContext(), Designators, |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4979 | IndexExprs, Importer.Import(DIE->getEqualOrColonLoc()), |
| 4980 | DIE->usesGNUSyntax(), Init); |
| 4981 | } |
| 4982 | |
| 4983 | Expr *ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 4984 | QualType T = Importer.Import(E->getType()); |
| 4985 | if (T.isNull()) |
| 4986 | return nullptr; |
| 4987 | |
| 4988 | return new (Importer.getToContext()) |
| 4989 | CXXNullPtrLiteralExpr(T, Importer.Import(E->getLocation())); |
| 4990 | } |
| 4991 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4992 | Expr *ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 4993 | QualType T = Importer.Import(E->getType()); |
| 4994 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4995 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4996 | |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 4997 | return IntegerLiteral::Create(Importer.getToContext(), |
| 4998 | E->getValue(), T, |
| 4999 | Importer.Import(E->getLocation())); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5000 | } |
| 5001 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5002 | Expr *ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 5003 | QualType T = Importer.Import(E->getType()); |
| 5004 | if (T.isNull()) |
| 5005 | return nullptr; |
| 5006 | |
| 5007 | return FloatingLiteral::Create(Importer.getToContext(), |
| 5008 | E->getValue(), E->isExact(), T, |
| 5009 | Importer.Import(E->getLocation())); |
| 5010 | } |
| 5011 | |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 5012 | Expr *ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 5013 | QualType T = Importer.Import(E->getType()); |
| 5014 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5015 | return nullptr; |
| 5016 | |
Douglas Gregor | fb65e59 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 5017 | return new (Importer.getToContext()) CharacterLiteral(E->getValue(), |
| 5018 | E->getKind(), T, |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 5019 | Importer.Import(E->getLocation())); |
| 5020 | } |
| 5021 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5022 | Expr *ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 5023 | QualType T = Importer.Import(E->getType()); |
| 5024 | if (T.isNull()) |
| 5025 | return nullptr; |
| 5026 | |
| 5027 | SmallVector<SourceLocation, 4> Locations(E->getNumConcatenated()); |
| 5028 | ImportArray(E->tokloc_begin(), E->tokloc_end(), Locations.begin()); |
| 5029 | |
| 5030 | return StringLiteral::Create(Importer.getToContext(), E->getBytes(), |
| 5031 | E->getKind(), E->isPascal(), T, |
| 5032 | Locations.data(), Locations.size()); |
| 5033 | } |
| 5034 | |
| 5035 | Expr *ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 5036 | QualType T = Importer.Import(E->getType()); |
| 5037 | if (T.isNull()) |
| 5038 | return nullptr; |
| 5039 | |
| 5040 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeSourceInfo()); |
| 5041 | if (!TInfo) |
| 5042 | return nullptr; |
| 5043 | |
| 5044 | Expr *Init = Importer.Import(E->getInitializer()); |
| 5045 | if (!Init) |
| 5046 | return nullptr; |
| 5047 | |
| 5048 | return new (Importer.getToContext()) CompoundLiteralExpr( |
| 5049 | Importer.Import(E->getLParenLoc()), TInfo, T, E->getValueKind(), |
| 5050 | Init, E->isFileScope()); |
| 5051 | } |
| 5052 | |
| 5053 | Expr *ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 5054 | QualType T = Importer.Import(E->getType()); |
| 5055 | if (T.isNull()) |
| 5056 | return nullptr; |
| 5057 | |
| 5058 | SmallVector<Expr *, 6> Exprs(E->getNumSubExprs()); |
| 5059 | if (ImportArrayChecked( |
| 5060 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 5061 | Exprs.begin())) |
| 5062 | return nullptr; |
| 5063 | |
| 5064 | return new (Importer.getToContext()) AtomicExpr( |
| 5065 | Importer.Import(E->getBuiltinLoc()), Exprs, T, E->getOp(), |
| 5066 | Importer.Import(E->getRParenLoc())); |
| 5067 | } |
| 5068 | |
| 5069 | Expr *ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 5070 | QualType T = Importer.Import(E->getType()); |
| 5071 | if (T.isNull()) |
| 5072 | return nullptr; |
| 5073 | |
| 5074 | LabelDecl *ToLabel = cast_or_null<LabelDecl>(Importer.Import(E->getLabel())); |
| 5075 | if (!ToLabel) |
| 5076 | return nullptr; |
| 5077 | |
| 5078 | return new (Importer.getToContext()) AddrLabelExpr( |
| 5079 | Importer.Import(E->getAmpAmpLoc()), Importer.Import(E->getLabelLoc()), |
| 5080 | ToLabel, T); |
| 5081 | } |
| 5082 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5083 | Expr *ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 5084 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5085 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5086 | return nullptr; |
| 5087 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5088 | return new (Importer.getToContext()) |
| 5089 | ParenExpr(Importer.Import(E->getLParen()), |
| 5090 | Importer.Import(E->getRParen()), |
| 5091 | SubExpr); |
| 5092 | } |
| 5093 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5094 | Expr *ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 5095 | SmallVector<Expr *, 4> Exprs(E->getNumExprs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5096 | if (ImportContainerChecked(E->exprs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5097 | return nullptr; |
| 5098 | |
| 5099 | return new (Importer.getToContext()) ParenListExpr( |
| 5100 | Importer.getToContext(), Importer.Import(E->getLParenLoc()), |
| 5101 | Exprs, Importer.Import(E->getLParenLoc())); |
| 5102 | } |
| 5103 | |
| 5104 | Expr *ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 5105 | QualType T = Importer.Import(E->getType()); |
| 5106 | if (T.isNull()) |
| 5107 | return nullptr; |
| 5108 | |
| 5109 | CompoundStmt *ToSubStmt = cast_or_null<CompoundStmt>( |
| 5110 | Importer.Import(E->getSubStmt())); |
| 5111 | if (!ToSubStmt && E->getSubStmt()) |
| 5112 | return nullptr; |
| 5113 | |
| 5114 | return new (Importer.getToContext()) StmtExpr(ToSubStmt, T, |
| 5115 | Importer.Import(E->getLParenLoc()), Importer.Import(E->getRParenLoc())); |
| 5116 | } |
| 5117 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5118 | Expr *ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 5119 | QualType T = Importer.Import(E->getType()); |
| 5120 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5121 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5122 | |
| 5123 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5124 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5125 | return nullptr; |
| 5126 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 5127 | return new (Importer.getToContext()) UnaryOperator( |
| 5128 | SubExpr, E->getOpcode(), T, E->getValueKind(), E->getObjectKind(), |
| 5129 | Importer.Import(E->getOperatorLoc()), E->canOverflow()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5130 | } |
| 5131 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 5132 | Expr * |
| 5133 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5134 | QualType ResultType = Importer.Import(E->getType()); |
| 5135 | |
| 5136 | if (E->isArgumentType()) { |
| 5137 | TypeSourceInfo *TInfo = Importer.Import(E->getArgumentTypeInfo()); |
| 5138 | if (!TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5139 | return nullptr; |
| 5140 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5141 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 5142 | TInfo, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5143 | Importer.Import(E->getOperatorLoc()), |
| 5144 | Importer.Import(E->getRParenLoc())); |
| 5145 | } |
| 5146 | |
| 5147 | Expr *SubExpr = Importer.Import(E->getArgumentExpr()); |
| 5148 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5149 | return nullptr; |
| 5150 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5151 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 5152 | SubExpr, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5153 | Importer.Import(E->getOperatorLoc()), |
| 5154 | Importer.Import(E->getRParenLoc())); |
| 5155 | } |
| 5156 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5157 | Expr *ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 5158 | QualType T = Importer.Import(E->getType()); |
| 5159 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5160 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5161 | |
| 5162 | Expr *LHS = Importer.Import(E->getLHS()); |
| 5163 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5164 | return nullptr; |
| 5165 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5166 | Expr *RHS = Importer.Import(E->getRHS()); |
| 5167 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5168 | return nullptr; |
| 5169 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5170 | return new (Importer.getToContext()) BinaryOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 5171 | T, E->getValueKind(), |
| 5172 | E->getObjectKind(), |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 5173 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 5174 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5175 | } |
| 5176 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5177 | Expr *ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 5178 | QualType T = Importer.Import(E->getType()); |
| 5179 | if (T.isNull()) |
| 5180 | return nullptr; |
| 5181 | |
| 5182 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 5183 | if (!ToLHS) |
| 5184 | return nullptr; |
| 5185 | |
| 5186 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 5187 | if (!ToRHS) |
| 5188 | return nullptr; |
| 5189 | |
| 5190 | Expr *ToCond = Importer.Import(E->getCond()); |
| 5191 | if (!ToCond) |
| 5192 | return nullptr; |
| 5193 | |
| 5194 | return new (Importer.getToContext()) ConditionalOperator( |
| 5195 | ToCond, Importer.Import(E->getQuestionLoc()), |
| 5196 | ToLHS, Importer.Import(E->getColonLoc()), |
| 5197 | ToRHS, T, E->getValueKind(), E->getObjectKind()); |
| 5198 | } |
| 5199 | |
| 5200 | Expr *ASTNodeImporter::VisitBinaryConditionalOperator( |
| 5201 | BinaryConditionalOperator *E) { |
| 5202 | QualType T = Importer.Import(E->getType()); |
| 5203 | if (T.isNull()) |
| 5204 | return nullptr; |
| 5205 | |
| 5206 | Expr *Common = Importer.Import(E->getCommon()); |
| 5207 | if (!Common) |
| 5208 | return nullptr; |
| 5209 | |
| 5210 | Expr *Cond = Importer.Import(E->getCond()); |
| 5211 | if (!Cond) |
| 5212 | return nullptr; |
| 5213 | |
| 5214 | OpaqueValueExpr *OpaqueValue = cast_or_null<OpaqueValueExpr>( |
| 5215 | Importer.Import(E->getOpaqueValue())); |
| 5216 | if (!OpaqueValue) |
| 5217 | return nullptr; |
| 5218 | |
| 5219 | Expr *TrueExpr = Importer.Import(E->getTrueExpr()); |
| 5220 | if (!TrueExpr) |
| 5221 | return nullptr; |
| 5222 | |
| 5223 | Expr *FalseExpr = Importer.Import(E->getFalseExpr()); |
| 5224 | if (!FalseExpr) |
| 5225 | return nullptr; |
| 5226 | |
| 5227 | return new (Importer.getToContext()) BinaryConditionalOperator( |
| 5228 | Common, OpaqueValue, Cond, TrueExpr, FalseExpr, |
| 5229 | Importer.Import(E->getQuestionLoc()), Importer.Import(E->getColonLoc()), |
| 5230 | T, E->getValueKind(), E->getObjectKind()); |
| 5231 | } |
| 5232 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5233 | Expr *ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 5234 | QualType T = Importer.Import(E->getType()); |
| 5235 | if (T.isNull()) |
| 5236 | return nullptr; |
| 5237 | |
| 5238 | TypeSourceInfo *ToQueried = Importer.Import(E->getQueriedTypeSourceInfo()); |
| 5239 | if (!ToQueried) |
| 5240 | return nullptr; |
| 5241 | |
| 5242 | Expr *Dim = Importer.Import(E->getDimensionExpression()); |
| 5243 | if (!Dim && E->getDimensionExpression()) |
| 5244 | return nullptr; |
| 5245 | |
| 5246 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
| 5247 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 5248 | E->getValue(), Dim, Importer.Import(E->getLocEnd()), T); |
| 5249 | } |
| 5250 | |
| 5251 | Expr *ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 5252 | QualType T = Importer.Import(E->getType()); |
| 5253 | if (T.isNull()) |
| 5254 | return nullptr; |
| 5255 | |
| 5256 | Expr *ToQueried = Importer.Import(E->getQueriedExpression()); |
| 5257 | if (!ToQueried) |
| 5258 | return nullptr; |
| 5259 | |
| 5260 | return new (Importer.getToContext()) ExpressionTraitExpr( |
| 5261 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 5262 | E->getValue(), Importer.Import(E->getLocEnd()), T); |
| 5263 | } |
| 5264 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5265 | Expr *ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 5266 | QualType T = Importer.Import(E->getType()); |
| 5267 | if (T.isNull()) |
| 5268 | return nullptr; |
| 5269 | |
| 5270 | Expr *SourceExpr = Importer.Import(E->getSourceExpr()); |
| 5271 | if (!SourceExpr && E->getSourceExpr()) |
| 5272 | return nullptr; |
| 5273 | |
| 5274 | return new (Importer.getToContext()) OpaqueValueExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5275 | Importer.Import(E->getLocation()), T, E->getValueKind(), |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5276 | E->getObjectKind(), SourceExpr); |
| 5277 | } |
| 5278 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5279 | Expr *ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 5280 | QualType T = Importer.Import(E->getType()); |
| 5281 | if (T.isNull()) |
| 5282 | return nullptr; |
| 5283 | |
| 5284 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 5285 | if (!ToLHS) |
| 5286 | return nullptr; |
| 5287 | |
| 5288 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 5289 | if (!ToRHS) |
| 5290 | return nullptr; |
| 5291 | |
| 5292 | return new (Importer.getToContext()) ArraySubscriptExpr( |
| 5293 | ToLHS, ToRHS, T, E->getValueKind(), E->getObjectKind(), |
| 5294 | Importer.Import(E->getRBracketLoc())); |
| 5295 | } |
| 5296 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5297 | Expr *ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 5298 | QualType T = Importer.Import(E->getType()); |
| 5299 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5300 | return nullptr; |
| 5301 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5302 | QualType CompLHSType = Importer.Import(E->getComputationLHSType()); |
| 5303 | if (CompLHSType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5304 | return nullptr; |
| 5305 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5306 | QualType CompResultType = Importer.Import(E->getComputationResultType()); |
| 5307 | if (CompResultType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5308 | return nullptr; |
| 5309 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5310 | Expr *LHS = Importer.Import(E->getLHS()); |
| 5311 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5312 | return nullptr; |
| 5313 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5314 | Expr *RHS = Importer.Import(E->getRHS()); |
| 5315 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5316 | return nullptr; |
| 5317 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5318 | return new (Importer.getToContext()) |
| 5319 | CompoundAssignOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 5320 | T, E->getValueKind(), |
| 5321 | E->getObjectKind(), |
| 5322 | CompLHSType, CompResultType, |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 5323 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 5324 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5325 | } |
| 5326 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5327 | bool ASTNodeImporter::ImportCastPath(CastExpr *CE, CXXCastPath &Path) { |
| 5328 | for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) { |
| 5329 | if (CXXBaseSpecifier *Spec = Importer.Import(*I)) |
| 5330 | Path.push_back(Spec); |
| 5331 | else |
| 5332 | return true; |
| 5333 | } |
| 5334 | return false; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5335 | } |
| 5336 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5337 | Expr *ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 5338 | QualType T = Importer.Import(E->getType()); |
| 5339 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5340 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5341 | |
| 5342 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5343 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5344 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5345 | |
| 5346 | CXXCastPath BasePath; |
| 5347 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5348 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5349 | |
| 5350 | return ImplicitCastExpr::Create(Importer.getToContext(), T, E->getCastKind(), |
John McCall | 2536c6d | 2010-08-25 10:28:54 +0000 | [diff] [blame] | 5351 | SubExpr, &BasePath, E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5352 | } |
| 5353 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5354 | Expr *ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5355 | QualType T = Importer.Import(E->getType()); |
| 5356 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5357 | return nullptr; |
| 5358 | |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5359 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5360 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5361 | return nullptr; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5362 | |
| 5363 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeInfoAsWritten()); |
| 5364 | if (!TInfo && E->getTypeInfoAsWritten()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5365 | return nullptr; |
| 5366 | |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5367 | CXXCastPath BasePath; |
| 5368 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5369 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5370 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5371 | switch (E->getStmtClass()) { |
| 5372 | case Stmt::CStyleCastExprClass: { |
| 5373 | CStyleCastExpr *CCE = cast<CStyleCastExpr>(E); |
| 5374 | return CStyleCastExpr::Create(Importer.getToContext(), T, |
| 5375 | E->getValueKind(), E->getCastKind(), |
| 5376 | SubExpr, &BasePath, TInfo, |
| 5377 | Importer.Import(CCE->getLParenLoc()), |
| 5378 | Importer.Import(CCE->getRParenLoc())); |
| 5379 | } |
| 5380 | |
| 5381 | case Stmt::CXXFunctionalCastExprClass: { |
| 5382 | CXXFunctionalCastExpr *FCE = cast<CXXFunctionalCastExpr>(E); |
| 5383 | return CXXFunctionalCastExpr::Create(Importer.getToContext(), T, |
| 5384 | E->getValueKind(), TInfo, |
| 5385 | E->getCastKind(), SubExpr, &BasePath, |
| 5386 | Importer.Import(FCE->getLParenLoc()), |
| 5387 | Importer.Import(FCE->getRParenLoc())); |
| 5388 | } |
| 5389 | |
| 5390 | case Stmt::ObjCBridgedCastExprClass: { |
| 5391 | ObjCBridgedCastExpr *OCE = cast<ObjCBridgedCastExpr>(E); |
| 5392 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 5393 | Importer.Import(OCE->getLParenLoc()), OCE->getBridgeKind(), |
| 5394 | E->getCastKind(), Importer.Import(OCE->getBridgeKeywordLoc()), |
| 5395 | TInfo, SubExpr); |
| 5396 | } |
| 5397 | default: |
| 5398 | break; // just fall through |
| 5399 | } |
| 5400 | |
| 5401 | CXXNamedCastExpr *Named = cast<CXXNamedCastExpr>(E); |
| 5402 | SourceLocation ExprLoc = Importer.Import(Named->getOperatorLoc()), |
| 5403 | RParenLoc = Importer.Import(Named->getRParenLoc()); |
| 5404 | SourceRange Brackets = Importer.Import(Named->getAngleBrackets()); |
| 5405 | |
| 5406 | switch (E->getStmtClass()) { |
| 5407 | case Stmt::CXXStaticCastExprClass: |
| 5408 | return CXXStaticCastExpr::Create(Importer.getToContext(), T, |
| 5409 | E->getValueKind(), E->getCastKind(), |
| 5410 | SubExpr, &BasePath, TInfo, |
| 5411 | ExprLoc, RParenLoc, Brackets); |
| 5412 | |
| 5413 | case Stmt::CXXDynamicCastExprClass: |
| 5414 | return CXXDynamicCastExpr::Create(Importer.getToContext(), T, |
| 5415 | E->getValueKind(), E->getCastKind(), |
| 5416 | SubExpr, &BasePath, TInfo, |
| 5417 | ExprLoc, RParenLoc, Brackets); |
| 5418 | |
| 5419 | case Stmt::CXXReinterpretCastExprClass: |
| 5420 | return CXXReinterpretCastExpr::Create(Importer.getToContext(), T, |
| 5421 | E->getValueKind(), E->getCastKind(), |
| 5422 | SubExpr, &BasePath, TInfo, |
| 5423 | ExprLoc, RParenLoc, Brackets); |
| 5424 | |
| 5425 | case Stmt::CXXConstCastExprClass: |
| 5426 | return CXXConstCastExpr::Create(Importer.getToContext(), T, |
| 5427 | E->getValueKind(), SubExpr, TInfo, ExprLoc, |
| 5428 | RParenLoc, Brackets); |
| 5429 | default: |
| 5430 | llvm_unreachable("Cast expression of unsupported type!"); |
| 5431 | return nullptr; |
| 5432 | } |
| 5433 | } |
| 5434 | |
| 5435 | Expr *ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *OE) { |
| 5436 | QualType T = Importer.Import(OE->getType()); |
| 5437 | if (T.isNull()) |
| 5438 | return nullptr; |
| 5439 | |
| 5440 | SmallVector<OffsetOfNode, 4> Nodes; |
| 5441 | for (int I = 0, E = OE->getNumComponents(); I < E; ++I) { |
| 5442 | const OffsetOfNode &Node = OE->getComponent(I); |
| 5443 | |
| 5444 | switch (Node.getKind()) { |
| 5445 | case OffsetOfNode::Array: |
| 5446 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), |
| 5447 | Node.getArrayExprIndex(), |
| 5448 | Importer.Import(Node.getLocEnd()))); |
| 5449 | break; |
| 5450 | |
| 5451 | case OffsetOfNode::Base: { |
| 5452 | CXXBaseSpecifier *BS = Importer.Import(Node.getBase()); |
| 5453 | if (!BS && Node.getBase()) |
| 5454 | return nullptr; |
| 5455 | Nodes.push_back(OffsetOfNode(BS)); |
| 5456 | break; |
| 5457 | } |
| 5458 | case OffsetOfNode::Field: { |
| 5459 | FieldDecl *FD = cast_or_null<FieldDecl>(Importer.Import(Node.getField())); |
| 5460 | if (!FD) |
| 5461 | return nullptr; |
| 5462 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), FD, |
| 5463 | Importer.Import(Node.getLocEnd()))); |
| 5464 | break; |
| 5465 | } |
| 5466 | case OffsetOfNode::Identifier: { |
| 5467 | IdentifierInfo *ToII = Importer.Import(Node.getFieldName()); |
| 5468 | if (!ToII) |
| 5469 | return nullptr; |
| 5470 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), ToII, |
| 5471 | Importer.Import(Node.getLocEnd()))); |
| 5472 | break; |
| 5473 | } |
| 5474 | } |
| 5475 | } |
| 5476 | |
| 5477 | SmallVector<Expr *, 4> Exprs(OE->getNumExpressions()); |
| 5478 | for (int I = 0, E = OE->getNumExpressions(); I < E; ++I) { |
| 5479 | Expr *ToIndexExpr = Importer.Import(OE->getIndexExpr(I)); |
| 5480 | if (!ToIndexExpr) |
| 5481 | return nullptr; |
| 5482 | Exprs[I] = ToIndexExpr; |
| 5483 | } |
| 5484 | |
| 5485 | TypeSourceInfo *TInfo = Importer.Import(OE->getTypeSourceInfo()); |
| 5486 | if (!TInfo && OE->getTypeSourceInfo()) |
| 5487 | return nullptr; |
| 5488 | |
| 5489 | return OffsetOfExpr::Create(Importer.getToContext(), T, |
| 5490 | Importer.Import(OE->getOperatorLoc()), |
| 5491 | TInfo, Nodes, Exprs, |
| 5492 | Importer.Import(OE->getRParenLoc())); |
| 5493 | } |
| 5494 | |
| 5495 | Expr *ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 5496 | QualType T = Importer.Import(E->getType()); |
| 5497 | if (T.isNull()) |
| 5498 | return nullptr; |
| 5499 | |
| 5500 | Expr *Operand = Importer.Import(E->getOperand()); |
| 5501 | if (!Operand) |
| 5502 | return nullptr; |
| 5503 | |
| 5504 | CanThrowResult CanThrow; |
| 5505 | if (E->isValueDependent()) |
| 5506 | CanThrow = CT_Dependent; |
| 5507 | else |
| 5508 | CanThrow = E->getValue() ? CT_Can : CT_Cannot; |
| 5509 | |
| 5510 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 5511 | T, Operand, CanThrow, |
| 5512 | Importer.Import(E->getLocStart()), Importer.Import(E->getLocEnd())); |
| 5513 | } |
| 5514 | |
| 5515 | Expr *ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 5516 | QualType T = Importer.Import(E->getType()); |
| 5517 | if (T.isNull()) |
| 5518 | return nullptr; |
| 5519 | |
| 5520 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5521 | if (!SubExpr && E->getSubExpr()) |
| 5522 | return nullptr; |
| 5523 | |
| 5524 | return new (Importer.getToContext()) CXXThrowExpr( |
| 5525 | SubExpr, T, Importer.Import(E->getThrowLoc()), |
| 5526 | E->isThrownVariableInScope()); |
| 5527 | } |
| 5528 | |
| 5529 | Expr *ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 5530 | ParmVarDecl *Param = cast_or_null<ParmVarDecl>( |
| 5531 | Importer.Import(E->getParam())); |
| 5532 | if (!Param) |
| 5533 | return nullptr; |
| 5534 | |
| 5535 | return CXXDefaultArgExpr::Create( |
| 5536 | Importer.getToContext(), Importer.Import(E->getUsedLocation()), Param); |
| 5537 | } |
| 5538 | |
| 5539 | Expr *ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 5540 | QualType T = Importer.Import(E->getType()); |
| 5541 | if (T.isNull()) |
| 5542 | return nullptr; |
| 5543 | |
| 5544 | TypeSourceInfo *TypeInfo = Importer.Import(E->getTypeSourceInfo()); |
| 5545 | if (!TypeInfo) |
| 5546 | return nullptr; |
| 5547 | |
| 5548 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
| 5549 | T, TypeInfo, Importer.Import(E->getRParenLoc())); |
| 5550 | } |
| 5551 | |
| 5552 | Expr *ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 5553 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5554 | if (!SubExpr) |
| 5555 | return nullptr; |
| 5556 | |
| 5557 | auto *Dtor = cast_or_null<CXXDestructorDecl>( |
| 5558 | Importer.Import(const_cast<CXXDestructorDecl *>( |
| 5559 | E->getTemporary()->getDestructor()))); |
| 5560 | if (!Dtor) |
| 5561 | return nullptr; |
| 5562 | |
| 5563 | ASTContext &ToCtx = Importer.getToContext(); |
| 5564 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, Dtor); |
| 5565 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, SubExpr); |
| 5566 | } |
| 5567 | |
| 5568 | Expr *ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE) { |
| 5569 | QualType T = Importer.Import(CE->getType()); |
| 5570 | if (T.isNull()) |
| 5571 | return nullptr; |
| 5572 | |
| 5573 | SmallVector<Expr *, 8> Args(CE->getNumArgs()); |
| 5574 | if (ImportContainerChecked(CE->arguments(), Args)) |
| 5575 | return nullptr; |
| 5576 | |
| 5577 | auto *Ctor = cast_or_null<CXXConstructorDecl>( |
| 5578 | Importer.Import(CE->getConstructor())); |
| 5579 | if (!Ctor) |
| 5580 | return nullptr; |
| 5581 | |
| 5582 | return CXXTemporaryObjectExpr::Create( |
| 5583 | Importer.getToContext(), T, |
| 5584 | Importer.Import(CE->getLocStart()), |
| 5585 | Ctor, |
| 5586 | CE->isElidable(), |
| 5587 | Args, |
| 5588 | CE->hadMultipleCandidates(), |
| 5589 | CE->isListInitialization(), |
| 5590 | CE->isStdInitListInitialization(), |
| 5591 | CE->requiresZeroInitialization(), |
| 5592 | CE->getConstructionKind(), |
| 5593 | Importer.Import(CE->getParenOrBraceRange())); |
| 5594 | } |
| 5595 | |
| 5596 | Expr * |
| 5597 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
| 5598 | QualType T = Importer.Import(E->getType()); |
| 5599 | if (T.isNull()) |
| 5600 | return nullptr; |
| 5601 | |
| 5602 | Expr *TempE = Importer.Import(E->GetTemporaryExpr()); |
| 5603 | if (!TempE) |
| 5604 | return nullptr; |
| 5605 | |
| 5606 | ValueDecl *ExtendedBy = cast_or_null<ValueDecl>( |
| 5607 | Importer.Import(const_cast<ValueDecl *>(E->getExtendingDecl()))); |
| 5608 | if (!ExtendedBy && E->getExtendingDecl()) |
| 5609 | return nullptr; |
| 5610 | |
| 5611 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
| 5612 | T, TempE, E->isBoundToLvalueReference()); |
| 5613 | |
| 5614 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
| 5615 | ToMTE->setExtendingDecl(ExtendedBy, E->getManglingNumber()); |
| 5616 | return ToMTE; |
| 5617 | } |
| 5618 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 5619 | Expr *ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 5620 | QualType T = Importer.Import(E->getType()); |
| 5621 | if (T.isNull()) |
| 5622 | return nullptr; |
| 5623 | |
| 5624 | Expr *Pattern = Importer.Import(E->getPattern()); |
| 5625 | if (!Pattern) |
| 5626 | return nullptr; |
| 5627 | |
| 5628 | return new (Importer.getToContext()) PackExpansionExpr( |
| 5629 | T, Pattern, Importer.Import(E->getEllipsisLoc()), |
| 5630 | E->getNumExpansions()); |
| 5631 | } |
| 5632 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5633 | Expr *ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *CE) { |
| 5634 | QualType T = Importer.Import(CE->getType()); |
| 5635 | if (T.isNull()) |
| 5636 | return nullptr; |
| 5637 | |
| 5638 | SmallVector<Expr *, 4> PlacementArgs(CE->getNumPlacementArgs()); |
| 5639 | if (ImportContainerChecked(CE->placement_arguments(), PlacementArgs)) |
| 5640 | return nullptr; |
| 5641 | |
| 5642 | FunctionDecl *OperatorNewDecl = cast_or_null<FunctionDecl>( |
| 5643 | Importer.Import(CE->getOperatorNew())); |
| 5644 | if (!OperatorNewDecl && CE->getOperatorNew()) |
| 5645 | return nullptr; |
| 5646 | |
| 5647 | FunctionDecl *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
| 5648 | Importer.Import(CE->getOperatorDelete())); |
| 5649 | if (!OperatorDeleteDecl && CE->getOperatorDelete()) |
| 5650 | return nullptr; |
| 5651 | |
| 5652 | Expr *ToInit = Importer.Import(CE->getInitializer()); |
| 5653 | if (!ToInit && CE->getInitializer()) |
| 5654 | return nullptr; |
| 5655 | |
| 5656 | TypeSourceInfo *TInfo = Importer.Import(CE->getAllocatedTypeSourceInfo()); |
| 5657 | if (!TInfo) |
| 5658 | return nullptr; |
| 5659 | |
| 5660 | Expr *ToArrSize = Importer.Import(CE->getArraySize()); |
| 5661 | if (!ToArrSize && CE->getArraySize()) |
| 5662 | return nullptr; |
| 5663 | |
| 5664 | return new (Importer.getToContext()) CXXNewExpr( |
| 5665 | Importer.getToContext(), |
| 5666 | CE->isGlobalNew(), |
| 5667 | OperatorNewDecl, OperatorDeleteDecl, |
Richard Smith | b2f0f05 | 2016-10-10 18:54:32 +0000 | [diff] [blame] | 5668 | CE->passAlignment(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5669 | CE->doesUsualArrayDeleteWantSize(), |
| 5670 | PlacementArgs, |
| 5671 | Importer.Import(CE->getTypeIdParens()), |
| 5672 | ToArrSize, CE->getInitializationStyle(), ToInit, T, TInfo, |
| 5673 | Importer.Import(CE->getSourceRange()), |
| 5674 | Importer.Import(CE->getDirectInitRange())); |
| 5675 | } |
| 5676 | |
| 5677 | Expr *ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 5678 | QualType T = Importer.Import(E->getType()); |
| 5679 | if (T.isNull()) |
| 5680 | return nullptr; |
| 5681 | |
| 5682 | FunctionDecl *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
| 5683 | Importer.Import(E->getOperatorDelete())); |
| 5684 | if (!OperatorDeleteDecl && E->getOperatorDelete()) |
| 5685 | return nullptr; |
| 5686 | |
| 5687 | Expr *ToArg = Importer.Import(E->getArgument()); |
| 5688 | if (!ToArg && E->getArgument()) |
| 5689 | return nullptr; |
| 5690 | |
| 5691 | return new (Importer.getToContext()) CXXDeleteExpr( |
| 5692 | T, E->isGlobalDelete(), |
| 5693 | E->isArrayForm(), |
| 5694 | E->isArrayFormAsWritten(), |
| 5695 | E->doesUsualArrayDeleteWantSize(), |
| 5696 | OperatorDeleteDecl, |
| 5697 | ToArg, |
| 5698 | Importer.Import(E->getLocStart())); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5699 | } |
| 5700 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5701 | Expr *ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 5702 | QualType T = Importer.Import(E->getType()); |
| 5703 | if (T.isNull()) |
| 5704 | return nullptr; |
| 5705 | |
| 5706 | CXXConstructorDecl *ToCCD = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 5707 | dyn_cast_or_null<CXXConstructorDecl>(Importer.Import(E->getConstructor())); |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 5708 | if (!ToCCD) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5709 | return nullptr; |
| 5710 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5711 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5712 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5713 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5714 | |
| 5715 | return CXXConstructExpr::Create(Importer.getToContext(), T, |
| 5716 | Importer.Import(E->getLocation()), |
Richard Smith | c83bf82 | 2016-06-10 00:58:19 +0000 | [diff] [blame] | 5717 | ToCCD, E->isElidable(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5718 | ToArgs, E->hadMultipleCandidates(), |
| 5719 | E->isListInitialization(), |
| 5720 | E->isStdInitListInitialization(), |
| 5721 | E->requiresZeroInitialization(), |
| 5722 | E->getConstructionKind(), |
| 5723 | Importer.Import(E->getParenOrBraceRange())); |
| 5724 | } |
| 5725 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5726 | Expr *ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *EWC) { |
| 5727 | Expr *SubExpr = Importer.Import(EWC->getSubExpr()); |
| 5728 | if (!SubExpr && EWC->getSubExpr()) |
| 5729 | return nullptr; |
| 5730 | |
| 5731 | SmallVector<ExprWithCleanups::CleanupObject, 8> Objs(EWC->getNumObjects()); |
| 5732 | for (unsigned I = 0, E = EWC->getNumObjects(); I < E; I++) |
| 5733 | if (ExprWithCleanups::CleanupObject Obj = |
| 5734 | cast_or_null<BlockDecl>(Importer.Import(EWC->getObject(I)))) |
| 5735 | Objs[I] = Obj; |
| 5736 | else |
| 5737 | return nullptr; |
| 5738 | |
| 5739 | return ExprWithCleanups::Create(Importer.getToContext(), |
| 5740 | SubExpr, EWC->cleanupsHaveSideEffects(), |
| 5741 | Objs); |
| 5742 | } |
| 5743 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5744 | Expr *ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 5745 | QualType T = Importer.Import(E->getType()); |
| 5746 | if (T.isNull()) |
| 5747 | return nullptr; |
| 5748 | |
| 5749 | Expr *ToFn = Importer.Import(E->getCallee()); |
| 5750 | if (!ToFn) |
| 5751 | return nullptr; |
| 5752 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5753 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5754 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5755 | return nullptr; |
| 5756 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5757 | return new (Importer.getToContext()) CXXMemberCallExpr( |
| 5758 | Importer.getToContext(), ToFn, ToArgs, T, E->getValueKind(), |
| 5759 | Importer.Import(E->getRParenLoc())); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5760 | } |
| 5761 | |
| 5762 | Expr *ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 5763 | QualType T = Importer.Import(E->getType()); |
| 5764 | if (T.isNull()) |
| 5765 | return nullptr; |
| 5766 | |
| 5767 | return new (Importer.getToContext()) |
| 5768 | CXXThisExpr(Importer.Import(E->getLocation()), T, E->isImplicit()); |
| 5769 | } |
| 5770 | |
| 5771 | Expr *ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 5772 | QualType T = Importer.Import(E->getType()); |
| 5773 | if (T.isNull()) |
| 5774 | return nullptr; |
| 5775 | |
| 5776 | return new (Importer.getToContext()) |
| 5777 | CXXBoolLiteralExpr(E->getValue(), T, Importer.Import(E->getLocation())); |
| 5778 | } |
| 5779 | |
| 5780 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5781 | Expr *ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 5782 | QualType T = Importer.Import(E->getType()); |
| 5783 | if (T.isNull()) |
| 5784 | return nullptr; |
| 5785 | |
| 5786 | Expr *ToBase = Importer.Import(E->getBase()); |
| 5787 | if (!ToBase && E->getBase()) |
| 5788 | return nullptr; |
| 5789 | |
| 5790 | ValueDecl *ToMember = dyn_cast<ValueDecl>(Importer.Import(E->getMemberDecl())); |
| 5791 | if (!ToMember && E->getMemberDecl()) |
| 5792 | return nullptr; |
| 5793 | |
| 5794 | DeclAccessPair ToFoundDecl = DeclAccessPair::make( |
| 5795 | dyn_cast<NamedDecl>(Importer.Import(E->getFoundDecl().getDecl())), |
| 5796 | E->getFoundDecl().getAccess()); |
| 5797 | |
| 5798 | DeclarationNameInfo ToMemberNameInfo( |
| 5799 | Importer.Import(E->getMemberNameInfo().getName()), |
| 5800 | Importer.Import(E->getMemberNameInfo().getLoc())); |
| 5801 | |
| 5802 | if (E->hasExplicitTemplateArgs()) { |
| 5803 | return nullptr; // FIXME: handle template arguments |
| 5804 | } |
| 5805 | |
| 5806 | return MemberExpr::Create(Importer.getToContext(), ToBase, |
| 5807 | E->isArrow(), |
| 5808 | Importer.Import(E->getOperatorLoc()), |
| 5809 | Importer.Import(E->getQualifierLoc()), |
| 5810 | Importer.Import(E->getTemplateKeywordLoc()), |
| 5811 | ToMember, ToFoundDecl, ToMemberNameInfo, |
| 5812 | nullptr, T, E->getValueKind(), |
| 5813 | E->getObjectKind()); |
| 5814 | } |
| 5815 | |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 5816 | Expr *ASTNodeImporter::VisitCXXPseudoDestructorExpr( |
| 5817 | CXXPseudoDestructorExpr *E) { |
| 5818 | |
| 5819 | Expr *BaseE = Importer.Import(E->getBase()); |
| 5820 | if (!BaseE) |
| 5821 | return nullptr; |
| 5822 | |
| 5823 | TypeSourceInfo *ScopeInfo = Importer.Import(E->getScopeTypeInfo()); |
| 5824 | if (!ScopeInfo && E->getScopeTypeInfo()) |
| 5825 | return nullptr; |
| 5826 | |
| 5827 | PseudoDestructorTypeStorage Storage; |
| 5828 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 5829 | IdentifierInfo *ToII = Importer.Import(FromII); |
| 5830 | if (!ToII) |
| 5831 | return nullptr; |
| 5832 | Storage = PseudoDestructorTypeStorage( |
| 5833 | ToII, Importer.Import(E->getDestroyedTypeLoc())); |
| 5834 | } else { |
| 5835 | TypeSourceInfo *TI = Importer.Import(E->getDestroyedTypeInfo()); |
| 5836 | if (!TI) |
| 5837 | return nullptr; |
| 5838 | Storage = PseudoDestructorTypeStorage(TI); |
| 5839 | } |
| 5840 | |
| 5841 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
| 5842 | Importer.getToContext(), BaseE, E->isArrow(), |
| 5843 | Importer.Import(E->getOperatorLoc()), |
| 5844 | Importer.Import(E->getQualifierLoc()), |
| 5845 | ScopeInfo, Importer.Import(E->getColonColonLoc()), |
| 5846 | Importer.Import(E->getTildeLoc()), Storage); |
| 5847 | } |
| 5848 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5849 | Expr *ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
| 5850 | CXXDependentScopeMemberExpr *E) { |
| 5851 | Expr *Base = nullptr; |
| 5852 | if (!E->isImplicitAccess()) { |
| 5853 | Base = Importer.Import(E->getBase()); |
| 5854 | if (!Base) |
| 5855 | return nullptr; |
| 5856 | } |
| 5857 | |
| 5858 | QualType BaseType = Importer.Import(E->getBaseType()); |
| 5859 | if (BaseType.isNull()) |
| 5860 | return nullptr; |
| 5861 | |
| 5862 | TemplateArgumentListInfo ToTAInfo(Importer.Import(E->getLAngleLoc()), |
| 5863 | Importer.Import(E->getRAngleLoc())); |
| 5864 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 5865 | if (E->hasExplicitTemplateArgs()) { |
| 5866 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 5867 | return nullptr; |
| 5868 | ResInfo = &ToTAInfo; |
| 5869 | } |
| 5870 | |
| 5871 | DeclarationName Name = Importer.Import(E->getMember()); |
| 5872 | if (!E->getMember().isEmpty() && Name.isEmpty()) |
| 5873 | return nullptr; |
| 5874 | |
| 5875 | DeclarationNameInfo MemberNameInfo(Name, Importer.Import(E->getMemberLoc())); |
| 5876 | // Import additional name location/type info. |
| 5877 | ImportDeclarationNameLoc(E->getMemberNameInfo(), MemberNameInfo); |
| 5878 | auto ToFQ = Importer.Import(E->getFirstQualifierFoundInScope()); |
| 5879 | if (!ToFQ && E->getFirstQualifierFoundInScope()) |
| 5880 | return nullptr; |
| 5881 | |
| 5882 | return CXXDependentScopeMemberExpr::Create( |
| 5883 | Importer.getToContext(), Base, BaseType, E->isArrow(), |
| 5884 | Importer.Import(E->getOperatorLoc()), |
| 5885 | Importer.Import(E->getQualifierLoc()), |
| 5886 | Importer.Import(E->getTemplateKeywordLoc()), |
| 5887 | cast_or_null<NamedDecl>(ToFQ), MemberNameInfo, ResInfo); |
| 5888 | } |
| 5889 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5890 | Expr *ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 5891 | QualType T = Importer.Import(E->getType()); |
| 5892 | if (T.isNull()) |
| 5893 | return nullptr; |
| 5894 | |
| 5895 | Expr *ToCallee = Importer.Import(E->getCallee()); |
| 5896 | if (!ToCallee && E->getCallee()) |
| 5897 | return nullptr; |
| 5898 | |
| 5899 | unsigned NumArgs = E->getNumArgs(); |
| 5900 | |
| 5901 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); |
| 5902 | |
| 5903 | for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) { |
| 5904 | Expr *FromArg = E->getArg(ai); |
| 5905 | Expr *ToArg = Importer.Import(FromArg); |
| 5906 | if (!ToArg) |
| 5907 | return nullptr; |
| 5908 | ToArgs[ai] = ToArg; |
| 5909 | } |
| 5910 | |
| 5911 | Expr **ToArgs_Copied = new (Importer.getToContext()) |
| 5912 | Expr*[NumArgs]; |
| 5913 | |
| 5914 | for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) |
| 5915 | ToArgs_Copied[ai] = ToArgs[ai]; |
| 5916 | |
| 5917 | return new (Importer.getToContext()) |
| 5918 | CallExpr(Importer.getToContext(), ToCallee, |
Craig Topper | c005cc0 | 2015-09-27 03:44:08 +0000 | [diff] [blame] | 5919 | llvm::makeArrayRef(ToArgs_Copied, NumArgs), T, E->getValueKind(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5920 | Importer.Import(E->getRParenLoc())); |
| 5921 | } |
| 5922 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5923 | Expr *ASTNodeImporter::VisitInitListExpr(InitListExpr *ILE) { |
| 5924 | QualType T = Importer.Import(ILE->getType()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5925 | if (T.isNull()) |
| 5926 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5927 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5928 | llvm::SmallVector<Expr *, 4> Exprs(ILE->getNumInits()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5929 | if (ImportContainerChecked(ILE->inits(), Exprs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5930 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5931 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5932 | ASTContext &ToCtx = Importer.getToContext(); |
| 5933 | InitListExpr *To = new (ToCtx) InitListExpr( |
| 5934 | ToCtx, Importer.Import(ILE->getLBraceLoc()), |
| 5935 | Exprs, Importer.Import(ILE->getLBraceLoc())); |
| 5936 | To->setType(T); |
| 5937 | |
| 5938 | if (ILE->hasArrayFiller()) { |
| 5939 | Expr *Filler = Importer.Import(ILE->getArrayFiller()); |
| 5940 | if (!Filler) |
| 5941 | return nullptr; |
| 5942 | To->setArrayFiller(Filler); |
| 5943 | } |
| 5944 | |
| 5945 | if (FieldDecl *FromFD = ILE->getInitializedFieldInUnion()) { |
| 5946 | FieldDecl *ToFD = cast_or_null<FieldDecl>(Importer.Import(FromFD)); |
| 5947 | if (!ToFD) |
| 5948 | return nullptr; |
| 5949 | To->setInitializedFieldInUnion(ToFD); |
| 5950 | } |
| 5951 | |
| 5952 | if (InitListExpr *SyntForm = ILE->getSyntacticForm()) { |
| 5953 | InitListExpr *ToSyntForm = cast_or_null<InitListExpr>( |
| 5954 | Importer.Import(SyntForm)); |
| 5955 | if (!ToSyntForm) |
| 5956 | return nullptr; |
| 5957 | To->setSyntacticForm(ToSyntForm); |
| 5958 | } |
| 5959 | |
| 5960 | To->sawArrayRangeDesignator(ILE->hadArrayRangeDesignator()); |
| 5961 | To->setValueDependent(ILE->isValueDependent()); |
| 5962 | To->setInstantiationDependent(ILE->isInstantiationDependent()); |
| 5963 | |
| 5964 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5965 | } |
| 5966 | |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 5967 | Expr *ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 5968 | QualType ToType = Importer.Import(E->getType()); |
| 5969 | if (ToType.isNull()) |
| 5970 | return nullptr; |
| 5971 | |
| 5972 | Expr *ToCommon = Importer.Import(E->getCommonExpr()); |
| 5973 | if (!ToCommon && E->getCommonExpr()) |
| 5974 | return nullptr; |
| 5975 | |
| 5976 | Expr *ToSubExpr = Importer.Import(E->getSubExpr()); |
| 5977 | if (!ToSubExpr && E->getSubExpr()) |
| 5978 | return nullptr; |
| 5979 | |
| 5980 | return new (Importer.getToContext()) |
| 5981 | ArrayInitLoopExpr(ToType, ToCommon, ToSubExpr); |
| 5982 | } |
| 5983 | |
| 5984 | Expr *ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 5985 | QualType ToType = Importer.Import(E->getType()); |
| 5986 | if (ToType.isNull()) |
| 5987 | return nullptr; |
| 5988 | return new (Importer.getToContext()) ArrayInitIndexExpr(ToType); |
| 5989 | } |
| 5990 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 5991 | Expr *ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) { |
| 5992 | FieldDecl *ToField = llvm::dyn_cast_or_null<FieldDecl>( |
| 5993 | Importer.Import(DIE->getField())); |
| 5994 | if (!ToField && DIE->getField()) |
| 5995 | return nullptr; |
| 5996 | |
| 5997 | return CXXDefaultInitExpr::Create( |
| 5998 | Importer.getToContext(), Importer.Import(DIE->getLocStart()), ToField); |
| 5999 | } |
| 6000 | |
| 6001 | Expr *ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 6002 | QualType ToType = Importer.Import(E->getType()); |
| 6003 | if (ToType.isNull() && !E->getType().isNull()) |
| 6004 | return nullptr; |
| 6005 | ExprValueKind VK = E->getValueKind(); |
| 6006 | CastKind CK = E->getCastKind(); |
| 6007 | Expr *ToOp = Importer.Import(E->getSubExpr()); |
| 6008 | if (!ToOp && E->getSubExpr()) |
| 6009 | return nullptr; |
| 6010 | CXXCastPath BasePath; |
| 6011 | if (ImportCastPath(E, BasePath)) |
| 6012 | return nullptr; |
| 6013 | TypeSourceInfo *ToWritten = Importer.Import(E->getTypeInfoAsWritten()); |
| 6014 | SourceLocation ToOperatorLoc = Importer.Import(E->getOperatorLoc()); |
| 6015 | SourceLocation ToRParenLoc = Importer.Import(E->getRParenLoc()); |
| 6016 | SourceRange ToAngleBrackets = Importer.Import(E->getAngleBrackets()); |
| 6017 | |
| 6018 | if (isa<CXXStaticCastExpr>(E)) { |
| 6019 | return CXXStaticCastExpr::Create( |
| 6020 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6021 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6022 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 6023 | return CXXDynamicCastExpr::Create( |
| 6024 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6025 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6026 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 6027 | return CXXReinterpretCastExpr::Create( |
| 6028 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6029 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6030 | } else { |
| 6031 | return nullptr; |
| 6032 | } |
| 6033 | } |
| 6034 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6035 | |
| 6036 | Expr *ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
| 6037 | SubstNonTypeTemplateParmExpr *E) { |
| 6038 | QualType T = Importer.Import(E->getType()); |
| 6039 | if (T.isNull()) |
| 6040 | return nullptr; |
| 6041 | |
| 6042 | NonTypeTemplateParmDecl *Param = cast_or_null<NonTypeTemplateParmDecl>( |
| 6043 | Importer.Import(E->getParameter())); |
| 6044 | if (!Param) |
| 6045 | return nullptr; |
| 6046 | |
| 6047 | Expr *Replacement = Importer.Import(E->getReplacement()); |
| 6048 | if (!Replacement) |
| 6049 | return nullptr; |
| 6050 | |
| 6051 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
| 6052 | T, E->getValueKind(), Importer.Import(E->getExprLoc()), Param, |
| 6053 | Replacement); |
| 6054 | } |
| 6055 | |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 6056 | Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 6057 | QualType ToType = Importer.Import(E->getType()); |
| 6058 | if (ToType.isNull()) |
| 6059 | return nullptr; |
| 6060 | |
| 6061 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
| 6062 | if (ImportContainerChecked(E->getArgs(), ToArgs)) |
| 6063 | return nullptr; |
| 6064 | |
| 6065 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 6066 | // Value is always false. |
| 6067 | bool ToValue = false; |
| 6068 | if (!E->isValueDependent()) |
| 6069 | ToValue = E->getValue(); |
| 6070 | |
| 6071 | return TypeTraitExpr::Create( |
| 6072 | Importer.getToContext(), ToType, Importer.Import(E->getLocStart()), |
| 6073 | E->getTrait(), ToArgs, Importer.Import(E->getLocEnd()), ToValue); |
| 6074 | } |
| 6075 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 6076 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 6077 | CXXMethodDecl *FromMethod) { |
| 6078 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) |
| 6079 | ToMethod->addOverriddenMethod( |
| 6080 | cast<CXXMethodDecl>(Importer.Import(const_cast<CXXMethodDecl*>( |
| 6081 | FromOverriddenMethod)))); |
| 6082 | } |
| 6083 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6084 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 6085 | ASTContext &FromContext, FileManager &FromFileManager, |
| 6086 | bool MinimalImport) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6087 | : ToContext(ToContext), FromContext(FromContext), |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 6088 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 6089 | Minimal(MinimalImport), LastDiagFromFrom(false) |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 6090 | { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6091 | ImportedDecls[FromContext.getTranslationUnitDecl()] |
| 6092 | = ToContext.getTranslationUnitDecl(); |
| 6093 | } |
| 6094 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 6095 | ASTImporter::~ASTImporter() { } |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6096 | |
| 6097 | QualType ASTImporter::Import(QualType FromT) { |
| 6098 | if (FromT.isNull()) |
| 6099 | return QualType(); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6100 | |
| 6101 | const Type *fromTy = FromT.getTypePtr(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6102 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6103 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6104 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
| 6105 | = ImportedTypes.find(fromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6106 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6107 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6108 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6109 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6110 | ASTNodeImporter Importer(*this); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6111 | QualType ToT = Importer.Visit(fromTy); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6112 | if (ToT.isNull()) |
| 6113 | return ToT; |
| 6114 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6115 | // Record the imported type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6116 | ImportedTypes[fromTy] = ToT.getTypePtr(); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6117 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6118 | return ToContext.getQualifiedType(ToT, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6119 | } |
| 6120 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6121 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 6122 | if (!FromTSI) |
| 6123 | return FromTSI; |
| 6124 | |
| 6125 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 6126 | // 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] | 6127 | QualType T = Import(FromTSI->getType()); |
| 6128 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6129 | return nullptr; |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 6130 | |
| 6131 | return ToContext.getTrivialTypeSourceInfo(T, |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 6132 | Import(FromTSI->getTypeLoc().getLocStart())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6133 | } |
| 6134 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6135 | Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) { |
| 6136 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
| 6137 | if (Pos != ImportedDecls.end()) { |
| 6138 | Decl *ToD = Pos->second; |
| 6139 | ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD); |
| 6140 | return ToD; |
| 6141 | } else { |
| 6142 | return nullptr; |
| 6143 | } |
| 6144 | } |
| 6145 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6146 | Decl *ASTImporter::Import(Decl *FromD) { |
| 6147 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6148 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6149 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6150 | ASTNodeImporter Importer(*this); |
| 6151 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6152 | // Check whether we've already imported this declaration. |
| 6153 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6154 | if (Pos != ImportedDecls.end()) { |
| 6155 | Decl *ToD = Pos->second; |
| 6156 | Importer.ImportDefinitionIfNeeded(FromD, ToD); |
| 6157 | return ToD; |
| 6158 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6159 | |
| 6160 | // Import the type |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6161 | Decl *ToD = Importer.Visit(FromD); |
| 6162 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6163 | return nullptr; |
| 6164 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6165 | // Record the imported declaration. |
| 6166 | ImportedDecls[FromD] = ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6167 | |
| 6168 | if (TagDecl *FromTag = dyn_cast<TagDecl>(FromD)) { |
| 6169 | // Keep track of anonymous tags that have an associated typedef. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 6170 | if (FromTag->getTypedefNameForAnonDecl()) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6171 | AnonTagsWithPendingTypedefs.push_back(FromTag); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 6172 | } else if (TypedefNameDecl *FromTypedef = dyn_cast<TypedefNameDecl>(FromD)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6173 | // When we've finished transforming a typedef, see whether it was the |
| 6174 | // typedef for an anonymous tag. |
Craig Topper | 2341c0d | 2013-07-04 03:08:24 +0000 | [diff] [blame] | 6175 | for (SmallVectorImpl<TagDecl *>::iterator |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6176 | FromTag = AnonTagsWithPendingTypedefs.begin(), |
| 6177 | FromTagEnd = AnonTagsWithPendingTypedefs.end(); |
| 6178 | FromTag != FromTagEnd; ++FromTag) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 6179 | if ((*FromTag)->getTypedefNameForAnonDecl() == FromTypedef) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6180 | if (TagDecl *ToTag = cast_or_null<TagDecl>(Import(*FromTag))) { |
| 6181 | // We found the typedef for an anonymous tag; link them. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 6182 | ToTag->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(ToD)); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6183 | AnonTagsWithPendingTypedefs.erase(FromTag); |
| 6184 | break; |
| 6185 | } |
| 6186 | } |
| 6187 | } |
| 6188 | } |
| 6189 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6190 | return ToD; |
| 6191 | } |
| 6192 | |
| 6193 | DeclContext *ASTImporter::ImportContext(DeclContext *FromDC) { |
| 6194 | if (!FromDC) |
| 6195 | return FromDC; |
| 6196 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 6197 | DeclContext *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6198 | if (!ToDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6199 | return nullptr; |
| 6200 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6201 | // When we're using a record/enum/Objective-C class/protocol as a context, we |
| 6202 | // need it to have a definition. |
| 6203 | if (RecordDecl *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
Douglas Gregor | 63db971 | 2012-01-25 01:13:20 +0000 | [diff] [blame] | 6204 | RecordDecl *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6205 | if (ToRecord->isCompleteDefinition()) { |
| 6206 | // Do nothing. |
| 6207 | } else if (FromRecord->isCompleteDefinition()) { |
| 6208 | ASTNodeImporter(*this).ImportDefinition(FromRecord, ToRecord, |
| 6209 | ASTNodeImporter::IDK_Basic); |
| 6210 | } else { |
| 6211 | CompleteDecl(ToRecord); |
| 6212 | } |
| 6213 | } else if (EnumDecl *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 6214 | EnumDecl *FromEnum = cast<EnumDecl>(FromDC); |
| 6215 | if (ToEnum->isCompleteDefinition()) { |
| 6216 | // Do nothing. |
| 6217 | } else if (FromEnum->isCompleteDefinition()) { |
| 6218 | ASTNodeImporter(*this).ImportDefinition(FromEnum, ToEnum, |
| 6219 | ASTNodeImporter::IDK_Basic); |
| 6220 | } else { |
| 6221 | CompleteDecl(ToEnum); |
| 6222 | } |
| 6223 | } else if (ObjCInterfaceDecl *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 6224 | ObjCInterfaceDecl *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
| 6225 | if (ToClass->getDefinition()) { |
| 6226 | // Do nothing. |
| 6227 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
| 6228 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToClass, |
| 6229 | ASTNodeImporter::IDK_Basic); |
| 6230 | } else { |
| 6231 | CompleteDecl(ToClass); |
| 6232 | } |
| 6233 | } else if (ObjCProtocolDecl *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 6234 | ObjCProtocolDecl *FromProto = cast<ObjCProtocolDecl>(FromDC); |
| 6235 | if (ToProto->getDefinition()) { |
| 6236 | // Do nothing. |
| 6237 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
| 6238 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToProto, |
| 6239 | ASTNodeImporter::IDK_Basic); |
| 6240 | } else { |
| 6241 | CompleteDecl(ToProto); |
| 6242 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 6243 | } |
| 6244 | |
| 6245 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6246 | } |
| 6247 | |
| 6248 | Expr *ASTImporter::Import(Expr *FromE) { |
| 6249 | if (!FromE) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6250 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6251 | |
| 6252 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); |
| 6253 | } |
| 6254 | |
| 6255 | Stmt *ASTImporter::Import(Stmt *FromS) { |
| 6256 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6257 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6258 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6259 | // Check whether we've already imported this declaration. |
| 6260 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 6261 | if (Pos != ImportedStmts.end()) |
| 6262 | return Pos->second; |
| 6263 | |
| 6264 | // Import the type |
| 6265 | ASTNodeImporter Importer(*this); |
| 6266 | Stmt *ToS = Importer.Visit(FromS); |
| 6267 | if (!ToS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6268 | return nullptr; |
| 6269 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6270 | // Record the imported declaration. |
| 6271 | ImportedStmts[FromS] = ToS; |
| 6272 | return ToS; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6273 | } |
| 6274 | |
| 6275 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| 6276 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6277 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6278 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6279 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); |
| 6280 | |
| 6281 | switch (FromNNS->getKind()) { |
| 6282 | case NestedNameSpecifier::Identifier: |
| 6283 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { |
| 6284 | return NestedNameSpecifier::Create(ToContext, prefix, II); |
| 6285 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6286 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6287 | |
| 6288 | case NestedNameSpecifier::Namespace: |
| 6289 | if (NamespaceDecl *NS = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6290 | cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6291 | return NestedNameSpecifier::Create(ToContext, prefix, NS); |
| 6292 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6293 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6294 | |
| 6295 | case NestedNameSpecifier::NamespaceAlias: |
| 6296 | if (NamespaceAliasDecl *NSAD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6297 | cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6298 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); |
| 6299 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6300 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6301 | |
| 6302 | case NestedNameSpecifier::Global: |
| 6303 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 6304 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 6305 | case NestedNameSpecifier::Super: |
| 6306 | if (CXXRecordDecl *RD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6307 | cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) { |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 6308 | return NestedNameSpecifier::SuperSpecifier(ToContext, RD); |
| 6309 | } |
| 6310 | return nullptr; |
| 6311 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6312 | case NestedNameSpecifier::TypeSpec: |
| 6313 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 6314 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); |
| 6315 | if (!T.isNull()) { |
| 6316 | bool bTemplate = FromNNS->getKind() == |
| 6317 | NestedNameSpecifier::TypeSpecWithTemplate; |
| 6318 | return NestedNameSpecifier::Create(ToContext, prefix, |
| 6319 | bTemplate, T.getTypePtr()); |
| 6320 | } |
| 6321 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6322 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6323 | } |
| 6324 | |
| 6325 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6326 | } |
| 6327 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 6328 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6329 | // Copied from NestedNameSpecifier mostly. |
| 6330 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 6331 | NestedNameSpecifierLoc NNS = FromNNS; |
| 6332 | |
| 6333 | // Push each of the nested-name-specifiers's onto a stack for |
| 6334 | // serialization in reverse order. |
| 6335 | while (NNS) { |
| 6336 | NestedNames.push_back(NNS); |
| 6337 | NNS = NNS.getPrefix(); |
| 6338 | } |
| 6339 | |
| 6340 | NestedNameSpecifierLocBuilder Builder; |
| 6341 | |
| 6342 | while (!NestedNames.empty()) { |
| 6343 | NNS = NestedNames.pop_back_val(); |
| 6344 | NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier()); |
| 6345 | if (!Spec) |
| 6346 | return NestedNameSpecifierLoc(); |
| 6347 | |
| 6348 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| 6349 | switch (Kind) { |
| 6350 | case NestedNameSpecifier::Identifier: |
| 6351 | Builder.Extend(getToContext(), |
| 6352 | Spec->getAsIdentifier(), |
| 6353 | Import(NNS.getLocalBeginLoc()), |
| 6354 | Import(NNS.getLocalEndLoc())); |
| 6355 | break; |
| 6356 | |
| 6357 | case NestedNameSpecifier::Namespace: |
| 6358 | Builder.Extend(getToContext(), |
| 6359 | Spec->getAsNamespace(), |
| 6360 | Import(NNS.getLocalBeginLoc()), |
| 6361 | Import(NNS.getLocalEndLoc())); |
| 6362 | break; |
| 6363 | |
| 6364 | case NestedNameSpecifier::NamespaceAlias: |
| 6365 | Builder.Extend(getToContext(), |
| 6366 | Spec->getAsNamespaceAlias(), |
| 6367 | Import(NNS.getLocalBeginLoc()), |
| 6368 | Import(NNS.getLocalEndLoc())); |
| 6369 | break; |
| 6370 | |
| 6371 | case NestedNameSpecifier::TypeSpec: |
| 6372 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 6373 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| 6374 | QualType(Spec->getAsType(), 0)); |
| 6375 | Builder.Extend(getToContext(), |
| 6376 | Import(NNS.getLocalBeginLoc()), |
| 6377 | TSI->getTypeLoc(), |
| 6378 | Import(NNS.getLocalEndLoc())); |
| 6379 | break; |
| 6380 | } |
| 6381 | |
| 6382 | case NestedNameSpecifier::Global: |
| 6383 | Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc())); |
| 6384 | break; |
| 6385 | |
| 6386 | case NestedNameSpecifier::Super: { |
| 6387 | SourceRange ToRange = Import(NNS.getSourceRange()); |
| 6388 | Builder.MakeSuper(getToContext(), |
| 6389 | Spec->getAsRecordDecl(), |
| 6390 | ToRange.getBegin(), |
| 6391 | ToRange.getEnd()); |
| 6392 | } |
| 6393 | } |
| 6394 | } |
| 6395 | |
| 6396 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 6397 | } |
| 6398 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6399 | TemplateName ASTImporter::Import(TemplateName From) { |
| 6400 | switch (From.getKind()) { |
| 6401 | case TemplateName::Template: |
| 6402 | if (TemplateDecl *ToTemplate |
| 6403 | = cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
| 6404 | return TemplateName(ToTemplate); |
| 6405 | |
| 6406 | return TemplateName(); |
| 6407 | |
| 6408 | case TemplateName::OverloadedTemplate: { |
| 6409 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 6410 | UnresolvedSet<2> ToTemplates; |
| 6411 | for (OverloadedTemplateStorage::iterator I = FromStorage->begin(), |
| 6412 | E = FromStorage->end(); |
| 6413 | I != E; ++I) { |
| 6414 | if (NamedDecl *To = cast_or_null<NamedDecl>(Import(*I))) |
| 6415 | ToTemplates.addDecl(To); |
| 6416 | else |
| 6417 | return TemplateName(); |
| 6418 | } |
| 6419 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
| 6420 | ToTemplates.end()); |
| 6421 | } |
| 6422 | |
| 6423 | case TemplateName::QualifiedTemplate: { |
| 6424 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| 6425 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); |
| 6426 | if (!Qualifier) |
| 6427 | return TemplateName(); |
| 6428 | |
| 6429 | if (TemplateDecl *ToTemplate |
| 6430 | = cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
| 6431 | return ToContext.getQualifiedTemplateName(Qualifier, |
| 6432 | QTN->hasTemplateKeyword(), |
| 6433 | ToTemplate); |
| 6434 | |
| 6435 | return TemplateName(); |
| 6436 | } |
| 6437 | |
| 6438 | case TemplateName::DependentTemplate: { |
| 6439 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| 6440 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); |
| 6441 | if (!Qualifier) |
| 6442 | return TemplateName(); |
| 6443 | |
| 6444 | if (DTN->isIdentifier()) { |
| 6445 | return ToContext.getDependentTemplateName(Qualifier, |
| 6446 | Import(DTN->getIdentifier())); |
| 6447 | } |
| 6448 | |
| 6449 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); |
| 6450 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6451 | |
| 6452 | case TemplateName::SubstTemplateTemplateParm: { |
| 6453 | SubstTemplateTemplateParmStorage *subst |
| 6454 | = From.getAsSubstTemplateTemplateParm(); |
| 6455 | TemplateTemplateParmDecl *param |
| 6456 | = cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); |
| 6457 | if (!param) |
| 6458 | return TemplateName(); |
| 6459 | |
| 6460 | TemplateName replacement = Import(subst->getReplacement()); |
| 6461 | if (replacement.isNull()) return TemplateName(); |
| 6462 | |
| 6463 | return ToContext.getSubstTemplateTemplateParm(param, replacement); |
| 6464 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6465 | |
| 6466 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 6467 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 6468 | = From.getAsSubstTemplateTemplateParmPack(); |
| 6469 | TemplateTemplateParmDecl *Param |
| 6470 | = cast_or_null<TemplateTemplateParmDecl>( |
| 6471 | Import(SubstPack->getParameterPack())); |
| 6472 | if (!Param) |
| 6473 | return TemplateName(); |
| 6474 | |
| 6475 | ASTNodeImporter Importer(*this); |
| 6476 | TemplateArgument ArgPack |
| 6477 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 6478 | if (ArgPack.isNull()) |
| 6479 | return TemplateName(); |
| 6480 | |
| 6481 | return ToContext.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 6482 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6483 | } |
| 6484 | |
| 6485 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6486 | } |
| 6487 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6488 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { |
| 6489 | if (FromLoc.isInvalid()) |
| 6490 | return SourceLocation(); |
| 6491 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6492 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 6493 | |
Sean Callanan | 24c5fe6 | 2016-11-07 20:42:25 +0000 | [diff] [blame] | 6494 | // For now, map everything down to its file location, so that we |
Chandler Carruth | 2536641 | 2011-07-15 00:04:35 +0000 | [diff] [blame] | 6495 | // don't have to import macro expansions. |
| 6496 | // FIXME: Import macro expansions! |
Sean Callanan | 24c5fe6 | 2016-11-07 20:42:25 +0000 | [diff] [blame] | 6497 | FromLoc = FromSM.getFileLoc(FromLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6498 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
| 6499 | SourceManager &ToSM = ToContext.getSourceManager(); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 6500 | FileID ToFileID = Import(Decomposed.first); |
| 6501 | if (ToFileID.isInvalid()) |
| 6502 | return SourceLocation(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6503 | SourceLocation ret = ToSM.getLocForStartOfFile(ToFileID) |
| 6504 | .getLocWithOffset(Decomposed.second); |
| 6505 | return ret; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6506 | } |
| 6507 | |
| 6508 | SourceRange ASTImporter::Import(SourceRange FromRange) { |
| 6509 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); |
| 6510 | } |
| 6511 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6512 | FileID ASTImporter::Import(FileID FromID) { |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 6513 | llvm::DenseMap<FileID, FileID>::iterator Pos |
| 6514 | = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6515 | if (Pos != ImportedFileIDs.end()) |
| 6516 | return Pos->second; |
| 6517 | |
| 6518 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 6519 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 6520 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Chandler Carruth | 2536641 | 2011-07-15 00:04:35 +0000 | [diff] [blame] | 6521 | assert(FromSLoc.isFile() && "Cannot handle macro expansions yet"); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6522 | |
| 6523 | // Include location of this file. |
| 6524 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| 6525 | |
| 6526 | // Map the FileID for to the "to" source manager. |
| 6527 | FileID ToID; |
| 6528 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
Sean Callanan | 25d34af | 2015-04-30 00:44:21 +0000 | [diff] [blame] | 6529 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6530 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 6531 | // disk again |
| 6532 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 6533 | // than mmap the files several times. |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 6534 | const FileEntry *Entry = ToFileManager.getFile(Cache->OrigEntry->getName()); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 6535 | if (!Entry) |
| 6536 | return FileID(); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6537 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, |
| 6538 | FromSLoc.getFile().getFileCharacteristic()); |
| 6539 | } else { |
| 6540 | // FIXME: We want to re-use the existing MemoryBuffer! |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6541 | const llvm::MemoryBuffer * |
| 6542 | FromBuf = Cache->getBuffer(FromContext.getDiagnostics(), FromSM); |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 6543 | std::unique_ptr<llvm::MemoryBuffer> ToBuf |
Chris Lattner | 58c7934 | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 6544 | = llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6545 | FromBuf->getBufferIdentifier()); |
David Blaikie | 50a5f97 | 2014-08-29 07:59:55 +0000 | [diff] [blame] | 6546 | ToID = ToSM.createFileID(std::move(ToBuf), |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 6547 | FromSLoc.getFile().getFileCharacteristic()); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6548 | } |
| 6549 | |
| 6550 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 6551 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6552 | return ToID; |
| 6553 | } |
| 6554 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6555 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { |
| 6556 | Expr *ToExpr = Import(From->getInit()); |
| 6557 | if (!ToExpr && From->getInit()) |
| 6558 | return nullptr; |
| 6559 | |
| 6560 | if (From->isBaseInitializer()) { |
| 6561 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 6562 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 6563 | return nullptr; |
| 6564 | |
| 6565 | return new (ToContext) CXXCtorInitializer( |
| 6566 | ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()), |
| 6567 | ToExpr, Import(From->getRParenLoc()), |
| 6568 | From->isPackExpansion() ? Import(From->getEllipsisLoc()) |
| 6569 | : SourceLocation()); |
| 6570 | } else if (From->isMemberInitializer()) { |
| 6571 | FieldDecl *ToField = |
| 6572 | llvm::cast_or_null<FieldDecl>(Import(From->getMember())); |
| 6573 | if (!ToField && From->getMember()) |
| 6574 | return nullptr; |
| 6575 | |
| 6576 | return new (ToContext) CXXCtorInitializer( |
| 6577 | ToContext, ToField, Import(From->getMemberLocation()), |
| 6578 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 6579 | } else if (From->isIndirectMemberInitializer()) { |
| 6580 | IndirectFieldDecl *ToIField = llvm::cast_or_null<IndirectFieldDecl>( |
| 6581 | Import(From->getIndirectMember())); |
| 6582 | if (!ToIField && From->getIndirectMember()) |
| 6583 | return nullptr; |
| 6584 | |
| 6585 | return new (ToContext) CXXCtorInitializer( |
| 6586 | ToContext, ToIField, Import(From->getMemberLocation()), |
| 6587 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 6588 | } else if (From->isDelegatingInitializer()) { |
| 6589 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 6590 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 6591 | return nullptr; |
| 6592 | |
| 6593 | return new (ToContext) |
| 6594 | CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()), |
| 6595 | ToExpr, Import(From->getRParenLoc())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6596 | } else { |
| 6597 | return nullptr; |
| 6598 | } |
| 6599 | } |
| 6600 | |
| 6601 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6602 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| 6603 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 6604 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 6605 | return Pos->second; |
| 6606 | |
| 6607 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| 6608 | Import(BaseSpec->getSourceRange()), |
| 6609 | BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 6610 | BaseSpec->getAccessSpecifierAsWritten(), |
| 6611 | Import(BaseSpec->getTypeSourceInfo()), |
| 6612 | Import(BaseSpec->getEllipsisLoc())); |
| 6613 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 6614 | return Imported; |
| 6615 | } |
| 6616 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 6617 | void ASTImporter::ImportDefinition(Decl *From) { |
| 6618 | Decl *To = Import(From); |
| 6619 | if (!To) |
| 6620 | return; |
| 6621 | |
| 6622 | if (DeclContext *FromDC = cast<DeclContext>(From)) { |
| 6623 | ASTNodeImporter Importer(*this); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 6624 | |
| 6625 | if (RecordDecl *ToRecord = dyn_cast<RecordDecl>(To)) { |
| 6626 | if (!ToRecord->getDefinition()) { |
| 6627 | Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 6628 | ASTNodeImporter::IDK_Everything); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 6629 | return; |
| 6630 | } |
| 6631 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6632 | |
| 6633 | if (EnumDecl *ToEnum = dyn_cast<EnumDecl>(To)) { |
| 6634 | if (!ToEnum->getDefinition()) { |
| 6635 | Importer.ImportDefinition(cast<EnumDecl>(FromDC), ToEnum, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6636 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6637 | return; |
| 6638 | } |
| 6639 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 6640 | |
| 6641 | if (ObjCInterfaceDecl *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
| 6642 | if (!ToIFace->getDefinition()) { |
| 6643 | Importer.ImportDefinition(cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6644 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 6645 | return; |
| 6646 | } |
| 6647 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6648 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 6649 | if (ObjCProtocolDecl *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
| 6650 | if (!ToProto->getDefinition()) { |
| 6651 | Importer.ImportDefinition(cast<ObjCProtocolDecl>(FromDC), ToProto, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6652 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 6653 | return; |
| 6654 | } |
| 6655 | } |
| 6656 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 6657 | Importer.ImportDeclContext(FromDC, true); |
| 6658 | } |
| 6659 | } |
| 6660 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6661 | DeclarationName ASTImporter::Import(DeclarationName FromName) { |
| 6662 | if (!FromName) |
| 6663 | return DeclarationName(); |
| 6664 | |
| 6665 | switch (FromName.getNameKind()) { |
| 6666 | case DeclarationName::Identifier: |
| 6667 | return Import(FromName.getAsIdentifierInfo()); |
| 6668 | |
| 6669 | case DeclarationName::ObjCZeroArgSelector: |
| 6670 | case DeclarationName::ObjCOneArgSelector: |
| 6671 | case DeclarationName::ObjCMultiArgSelector: |
| 6672 | return Import(FromName.getObjCSelector()); |
| 6673 | |
| 6674 | case DeclarationName::CXXConstructorName: { |
| 6675 | QualType T = Import(FromName.getCXXNameType()); |
| 6676 | if (T.isNull()) |
| 6677 | return DeclarationName(); |
| 6678 | |
| 6679 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 6680 | ToContext.getCanonicalType(T)); |
| 6681 | } |
| 6682 | |
| 6683 | case DeclarationName::CXXDestructorName: { |
| 6684 | QualType T = Import(FromName.getCXXNameType()); |
| 6685 | if (T.isNull()) |
| 6686 | return DeclarationName(); |
| 6687 | |
| 6688 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 6689 | ToContext.getCanonicalType(T)); |
| 6690 | } |
| 6691 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 6692 | case DeclarationName::CXXDeductionGuideName: { |
| 6693 | TemplateDecl *Template = cast_or_null<TemplateDecl>( |
| 6694 | Import(FromName.getCXXDeductionGuideTemplate())); |
| 6695 | if (!Template) |
| 6696 | return DeclarationName(); |
| 6697 | return ToContext.DeclarationNames.getCXXDeductionGuideName(Template); |
| 6698 | } |
| 6699 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6700 | case DeclarationName::CXXConversionFunctionName: { |
| 6701 | QualType T = Import(FromName.getCXXNameType()); |
| 6702 | if (T.isNull()) |
| 6703 | return DeclarationName(); |
| 6704 | |
| 6705 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 6706 | ToContext.getCanonicalType(T)); |
| 6707 | } |
| 6708 | |
| 6709 | case DeclarationName::CXXOperatorName: |
| 6710 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 6711 | FromName.getCXXOverloadedOperator()); |
| 6712 | |
| 6713 | case DeclarationName::CXXLiteralOperatorName: |
| 6714 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| 6715 | Import(FromName.getCXXLiteralIdentifier())); |
| 6716 | |
| 6717 | case DeclarationName::CXXUsingDirective: |
| 6718 | // FIXME: STATICS! |
| 6719 | return DeclarationName::getUsingDirectiveName(); |
| 6720 | } |
| 6721 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 6722 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6723 | } |
| 6724 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6725 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6726 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6727 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6728 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 6729 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 6730 | |
| 6731 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 6732 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 6733 | |
| 6734 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6735 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 6736 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 6737 | Selector ASTImporter::Import(Selector FromSel) { |
| 6738 | if (FromSel.isNull()) |
| 6739 | return Selector(); |
| 6740 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6741 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 6742 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 6743 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 6744 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 6745 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 6746 | } |
| 6747 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 6748 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 6749 | DeclContext *DC, |
| 6750 | unsigned IDNS, |
| 6751 | NamedDecl **Decls, |
| 6752 | unsigned NumDecls) { |
| 6753 | return Name; |
| 6754 | } |
| 6755 | |
| 6756 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 6757 | if (LastDiagFromFrom) |
| 6758 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 6759 | FromContext.getDiagnostics()); |
| 6760 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6761 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 6762 | } |
| 6763 | |
| 6764 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 6765 | if (!LastDiagFromFrom) |
| 6766 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 6767 | ToContext.getDiagnostics()); |
| 6768 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6769 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 6770 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 6771 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6772 | void ASTImporter::CompleteDecl (Decl *D) { |
| 6773 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
| 6774 | if (!ID->getDefinition()) |
| 6775 | ID->startDefinition(); |
| 6776 | } |
| 6777 | else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
| 6778 | if (!PD->getDefinition()) |
| 6779 | PD->startDefinition(); |
| 6780 | } |
| 6781 | else if (TagDecl *TD = dyn_cast<TagDecl>(D)) { |
| 6782 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 6783 | TD->startDefinition(); |
| 6784 | TD->setCompleteDefinition(true); |
| 6785 | } |
| 6786 | } |
| 6787 | else { |
| 6788 | assert (0 && "CompleteDecl called on a Decl that can't be completed"); |
| 6789 | } |
| 6790 | } |
| 6791 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 6792 | Decl *ASTImporter::Imported(Decl *From, Decl *To) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6793 | if (From->hasAttrs()) { |
| 6794 | for (Attr *FromAttr : From->getAttrs()) |
| 6795 | To->addAttr(FromAttr->clone(To->getASTContext())); |
| 6796 | } |
| 6797 | if (From->isUsed()) { |
| 6798 | To->setIsUsed(); |
| 6799 | } |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6800 | if (From->isImplicit()) { |
| 6801 | To->setImplicit(); |
| 6802 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 6803 | ImportedDecls[From] = To; |
| 6804 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 6805 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6806 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 6807 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 6808 | bool Complain) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6809 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6810 | = ImportedTypes.find(From.getTypePtr()); |
| 6811 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) |
| 6812 | return true; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 6813 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 6814 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
| 6815 | false, Complain); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 6816 | return Ctx.IsStructurallyEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6817 | } |