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 | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 26 | |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 27 | namespace clang { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 28 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, QualType>, |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 29 | public DeclVisitor<ASTNodeImporter, Decl *>, |
| 30 | public StmtVisitor<ASTNodeImporter, Stmt *> { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 31 | ASTImporter &Importer; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 32 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 33 | public: |
| 34 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) { } |
| 35 | |
| 36 | using TypeVisitor<ASTNodeImporter, QualType>::Visit; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 37 | using DeclVisitor<ASTNodeImporter, Decl *>::Visit; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 38 | using StmtVisitor<ASTNodeImporter, Stmt *>::Visit; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 39 | |
| 40 | // Importing types |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 41 | QualType VisitType(const Type *T); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 42 | QualType VisitAtomicType(const AtomicType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 43 | QualType VisitBuiltinType(const BuiltinType *T); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 44 | QualType VisitDecayedType(const DecayedType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 45 | QualType VisitComplexType(const ComplexType *T); |
| 46 | QualType VisitPointerType(const PointerType *T); |
| 47 | QualType VisitBlockPointerType(const BlockPointerType *T); |
| 48 | QualType VisitLValueReferenceType(const LValueReferenceType *T); |
| 49 | QualType VisitRValueReferenceType(const RValueReferenceType *T); |
| 50 | QualType VisitMemberPointerType(const MemberPointerType *T); |
| 51 | QualType VisitConstantArrayType(const ConstantArrayType *T); |
| 52 | QualType VisitIncompleteArrayType(const IncompleteArrayType *T); |
| 53 | QualType VisitVariableArrayType(const VariableArrayType *T); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 54 | QualType VisitDependentSizedArrayType(const DependentSizedArrayType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 55 | // FIXME: DependentSizedExtVectorType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 56 | QualType VisitVectorType(const VectorType *T); |
| 57 | QualType VisitExtVectorType(const ExtVectorType *T); |
| 58 | QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T); |
| 59 | QualType VisitFunctionProtoType(const FunctionProtoType *T); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 60 | QualType VisitUnresolvedUsingType(const UnresolvedUsingType *T); |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 61 | QualType VisitParenType(const ParenType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 62 | QualType VisitTypedefType(const TypedefType *T); |
| 63 | QualType VisitTypeOfExprType(const TypeOfExprType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 64 | // FIXME: DependentTypeOfExprType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 65 | QualType VisitTypeOfType(const TypeOfType *T); |
| 66 | QualType VisitDecltypeType(const DecltypeType *T); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 67 | QualType VisitUnaryTransformType(const UnaryTransformType *T); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 68 | QualType VisitAutoType(const AutoType *T); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 69 | QualType VisitInjectedClassNameType(const InjectedClassNameType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 70 | // FIXME: DependentDecltypeType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 71 | QualType VisitRecordType(const RecordType *T); |
| 72 | QualType VisitEnumType(const EnumType *T); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 73 | QualType VisitAttributedType(const AttributedType *T); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 74 | QualType VisitTemplateTypeParmType(const TemplateTypeParmType *T); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 75 | QualType VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 76 | QualType VisitTemplateSpecializationType(const TemplateSpecializationType *T); |
| 77 | QualType VisitElaboratedType(const ElaboratedType *T); |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 78 | // FIXME: DependentNameType |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 79 | QualType VisitPackExpansionType(const PackExpansionType *T); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 80 | QualType VisitDependentTemplateSpecializationType( |
| 81 | const DependentTemplateSpecializationType *T); |
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 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 100 | Optional<LambdaCapture> ImportLambdaCapture(const LambdaCapture &From); |
| 101 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 102 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 103 | /// \brief What we should import from the definition. |
| 104 | enum ImportDefinitionKind { |
| 105 | /// \brief Import the default subset of the definition, which might be |
| 106 | /// nothing (if minimal import is set) or might be everything (if minimal |
| 107 | /// import is not set). |
| 108 | IDK_Default, |
| 109 | /// \brief Import everything. |
| 110 | IDK_Everything, |
| 111 | /// \brief Import only the bare bones needed to establish a valid |
| 112 | /// DeclContext. |
| 113 | IDK_Basic |
| 114 | }; |
| 115 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 116 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { |
| 117 | return IDK == IDK_Everything || |
| 118 | (IDK == IDK_Default && !Importer.isMinimalImport()); |
| 119 | } |
| 120 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 121 | bool ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 122 | ImportDefinitionKind Kind = IDK_Default); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 123 | bool ImportDefinition(VarDecl *From, VarDecl *To, |
| 124 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 125 | bool ImportDefinition(EnumDecl *From, EnumDecl *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(ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 128 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 129 | bool ImportDefinition(ObjCProtocolDecl *From, ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 130 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 131 | TemplateParameterList *ImportTemplateParameterList( |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 132 | TemplateParameterList *Params); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 133 | TemplateArgument ImportTemplateArgument(const TemplateArgument &From); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 134 | Optional<TemplateArgumentLoc> ImportTemplateArgumentLoc( |
| 135 | const TemplateArgumentLoc &TALoc); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 136 | bool ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 137 | unsigned NumFromArgs, |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 138 | SmallVectorImpl<TemplateArgument> &ToArgs); |
| 139 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 140 | template <typename InContainerTy> |
| 141 | bool ImportTemplateArgumentListInfo(const InContainerTy &Container, |
| 142 | TemplateArgumentListInfo &ToTAInfo); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 143 | |
| 144 | template<typename InContainerTy> |
| 145 | bool ImportTemplateArgumentListInfo(SourceLocation FromLAngleLoc, |
| 146 | SourceLocation FromRAngleLoc, |
| 147 | const InContainerTy &Container, |
| 148 | TemplateArgumentListInfo &Result); |
| 149 | |
| 150 | bool ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); |
| 151 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 152 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, |
| 153 | bool Complain = true); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 154 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 155 | bool Complain = true); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 156 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 157 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 158 | bool IsStructuralMatch(FunctionTemplateDecl *From, |
| 159 | FunctionTemplateDecl *To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 160 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 161 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 162 | Decl *VisitDecl(Decl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 163 | Decl *VisitEmptyDecl(EmptyDecl *D); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 164 | Decl *VisitAccessSpecDecl(AccessSpecDecl *D); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 165 | Decl *VisitStaticAssertDecl(StaticAssertDecl *D); |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 166 | Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 167 | Decl *VisitNamespaceDecl(NamespaceDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 168 | Decl *VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 169 | Decl *VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 170 | Decl *VisitTypedefDecl(TypedefDecl *D); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 171 | Decl *VisitTypeAliasDecl(TypeAliasDecl *D); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 172 | Decl *VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 173 | Decl *VisitLabelDecl(LabelDecl *D); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 174 | Decl *VisitEnumDecl(EnumDecl *D); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 175 | Decl *VisitRecordDecl(RecordDecl *D); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 176 | Decl *VisitEnumConstantDecl(EnumConstantDecl *D); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 177 | Decl *VisitFunctionDecl(FunctionDecl *D); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 178 | Decl *VisitCXXMethodDecl(CXXMethodDecl *D); |
| 179 | Decl *VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 180 | Decl *VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 181 | Decl *VisitCXXConversionDecl(CXXConversionDecl *D); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 182 | Decl *VisitFieldDecl(FieldDecl *D); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 183 | Decl *VisitIndirectFieldDecl(IndirectFieldDecl *D); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 184 | Decl *VisitFriendDecl(FriendDecl *D); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 185 | Decl *VisitObjCIvarDecl(ObjCIvarDecl *D); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 186 | Decl *VisitVarDecl(VarDecl *D); |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 187 | Decl *VisitImplicitParamDecl(ImplicitParamDecl *D); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 188 | Decl *VisitParmVarDecl(ParmVarDecl *D); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 189 | Decl *VisitObjCMethodDecl(ObjCMethodDecl *D); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 190 | Decl *VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 191 | Decl *VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 192 | Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 193 | Decl *VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 194 | Decl *VisitUsingDecl(UsingDecl *D); |
| 195 | Decl *VisitUsingShadowDecl(UsingShadowDecl *D); |
| 196 | Decl *VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 197 | Decl *VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| 198 | Decl *VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
| 199 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 200 | |
| 201 | ObjCTypeParamList *ImportObjCTypeParamList(ObjCTypeParamList *list); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 202 | Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 203 | Decl *VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 204 | Decl *VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 205 | Decl *VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 206 | Decl *VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 207 | Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 208 | Decl *VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 209 | Decl *VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 210 | Decl *VisitClassTemplateDecl(ClassTemplateDecl *D); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 211 | Decl *VisitClassTemplateSpecializationDecl( |
| 212 | ClassTemplateSpecializationDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 213 | Decl *VisitVarTemplateDecl(VarTemplateDecl *D); |
| 214 | Decl *VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 215 | Decl *VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 216 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 217 | // Importing statements |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 218 | DeclGroupRef ImportDeclGroup(DeclGroupRef DG); |
| 219 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 220 | Stmt *VisitStmt(Stmt *S); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 221 | Stmt *VisitGCCAsmStmt(GCCAsmStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 222 | Stmt *VisitDeclStmt(DeclStmt *S); |
| 223 | Stmt *VisitNullStmt(NullStmt *S); |
| 224 | Stmt *VisitCompoundStmt(CompoundStmt *S); |
| 225 | Stmt *VisitCaseStmt(CaseStmt *S); |
| 226 | Stmt *VisitDefaultStmt(DefaultStmt *S); |
| 227 | Stmt *VisitLabelStmt(LabelStmt *S); |
| 228 | Stmt *VisitAttributedStmt(AttributedStmt *S); |
| 229 | Stmt *VisitIfStmt(IfStmt *S); |
| 230 | Stmt *VisitSwitchStmt(SwitchStmt *S); |
| 231 | Stmt *VisitWhileStmt(WhileStmt *S); |
| 232 | Stmt *VisitDoStmt(DoStmt *S); |
| 233 | Stmt *VisitForStmt(ForStmt *S); |
| 234 | Stmt *VisitGotoStmt(GotoStmt *S); |
| 235 | Stmt *VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 236 | Stmt *VisitContinueStmt(ContinueStmt *S); |
| 237 | Stmt *VisitBreakStmt(BreakStmt *S); |
| 238 | Stmt *VisitReturnStmt(ReturnStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 239 | // FIXME: MSAsmStmt |
| 240 | // FIXME: SEHExceptStmt |
| 241 | // FIXME: SEHFinallyStmt |
| 242 | // FIXME: SEHTryStmt |
| 243 | // FIXME: SEHLeaveStmt |
| 244 | // FIXME: CapturedStmt |
| 245 | Stmt *VisitCXXCatchStmt(CXXCatchStmt *S); |
| 246 | Stmt *VisitCXXTryStmt(CXXTryStmt *S); |
| 247 | Stmt *VisitCXXForRangeStmt(CXXForRangeStmt *S); |
| 248 | // FIXME: MSDependentExistsStmt |
| 249 | Stmt *VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); |
| 250 | Stmt *VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); |
| 251 | Stmt *VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); |
| 252 | Stmt *VisitObjCAtTryStmt(ObjCAtTryStmt *S); |
| 253 | Stmt *VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); |
| 254 | Stmt *VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); |
| 255 | Stmt *VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 256 | |
| 257 | // Importing expressions |
| 258 | Expr *VisitExpr(Expr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 259 | Expr *VisitVAArgExpr(VAArgExpr *E); |
| 260 | Expr *VisitGNUNullExpr(GNUNullExpr *E); |
| 261 | Expr *VisitPredefinedExpr(PredefinedExpr *E); |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 262 | Expr *VisitDeclRefExpr(DeclRefExpr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 263 | Expr *VisitImplicitValueInitExpr(ImplicitValueInitExpr *ILE); |
| 264 | Expr *VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 265 | Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 266 | Expr *VisitIntegerLiteral(IntegerLiteral *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 267 | Expr *VisitFloatingLiteral(FloatingLiteral *E); |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 268 | Expr *VisitCharacterLiteral(CharacterLiteral *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 269 | Expr *VisitStringLiteral(StringLiteral *E); |
| 270 | Expr *VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 271 | Expr *VisitAtomicExpr(AtomicExpr *E); |
| 272 | Expr *VisitAddrLabelExpr(AddrLabelExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 273 | Expr *VisitParenExpr(ParenExpr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 274 | Expr *VisitParenListExpr(ParenListExpr *E); |
| 275 | Expr *VisitStmtExpr(StmtExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 276 | Expr *VisitUnaryOperator(UnaryOperator *E); |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 277 | Expr *VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 278 | Expr *VisitBinaryOperator(BinaryOperator *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 279 | Expr *VisitConditionalOperator(ConditionalOperator *E); |
| 280 | Expr *VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 281 | Expr *VisitOpaqueValueExpr(OpaqueValueExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 282 | Expr *VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 283 | Expr *VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 284 | Expr *VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 285 | Expr *VisitCompoundAssignOperator(CompoundAssignOperator *E); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 286 | Expr *VisitImplicitCastExpr(ImplicitCastExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 287 | Expr *VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 288 | Expr *VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 289 | Expr *VisitCXXThrowExpr(CXXThrowExpr *E); |
| 290 | Expr *VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 291 | Expr *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 292 | Expr *VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 293 | Expr *VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 294 | Expr *VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE); |
| 295 | Expr *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 296 | Expr *VisitPackExpansionExpr(PackExpansionExpr *E); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 297 | Expr *VisitSizeOfPackExpr(SizeOfPackExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 298 | Expr *VisitCXXNewExpr(CXXNewExpr *CE); |
| 299 | Expr *VisitCXXDeleteExpr(CXXDeleteExpr *E); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 300 | Expr *VisitCXXConstructExpr(CXXConstructExpr *E); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 301 | Expr *VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 302 | Expr *VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 303 | Expr *VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *CE); |
| 304 | Expr *VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 305 | Expr *VisitExprWithCleanups(ExprWithCleanups *EWC); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 306 | Expr *VisitCXXThisExpr(CXXThisExpr *E); |
| 307 | Expr *VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 308 | Expr *VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 309 | Expr *VisitMemberExpr(MemberExpr *E); |
| 310 | Expr *VisitCallExpr(CallExpr *E); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 311 | Expr *VisitLambdaExpr(LambdaExpr *LE); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 312 | Expr *VisitInitListExpr(InitListExpr *E); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 313 | Expr *VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 314 | Expr *VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 315 | Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 316 | Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 317 | Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 318 | Expr *VisitTypeTraitExpr(TypeTraitExpr *E); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 319 | Expr *VisitCXXTypeidExpr(CXXTypeidExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 320 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 321 | |
| 322 | template<typename IIter, typename OIter> |
| 323 | void ImportArray(IIter Ibegin, IIter Iend, OIter Obegin) { |
| 324 | typedef typename std::remove_reference<decltype(*Obegin)>::type ItemT; |
| 325 | ASTImporter &ImporterRef = Importer; |
| 326 | std::transform(Ibegin, Iend, Obegin, |
| 327 | [&ImporterRef](ItemT From) -> ItemT { |
| 328 | return ImporterRef.Import(From); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 329 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | template<typename IIter, typename OIter> |
| 333 | bool ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
| 334 | typedef typename std::remove_reference<decltype(**Obegin)>::type ItemT; |
| 335 | ASTImporter &ImporterRef = Importer; |
| 336 | bool Failed = false; |
| 337 | std::transform(Ibegin, Iend, Obegin, |
| 338 | [&ImporterRef, &Failed](ItemT *From) -> ItemT * { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 339 | ItemT *To = cast_or_null<ItemT>( |
| 340 | ImporterRef.Import(From)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 341 | if (!To && From) |
| 342 | Failed = true; |
| 343 | return To; |
| 344 | }); |
| 345 | return Failed; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 346 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 347 | |
| 348 | template<typename InContainerTy, typename OutContainerTy> |
| 349 | bool ImportContainerChecked(const InContainerTy &InContainer, |
| 350 | OutContainerTy &OutContainer) { |
| 351 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), |
| 352 | OutContainer.begin()); |
| 353 | } |
| 354 | |
| 355 | template<typename InContainerTy, typename OIter> |
| 356 | bool ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
| 357 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 358 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 359 | |
| 360 | // Importing overrides. |
| 361 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 362 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 363 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 364 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 365 | //---------------------------------------------------------------------------- |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 366 | // Import Types |
| 367 | //---------------------------------------------------------------------------- |
| 368 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 369 | using namespace clang; |
| 370 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 371 | QualType ASTNodeImporter::VisitType(const Type *T) { |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 372 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 373 | << T->getTypeClassName(); |
| 374 | return QualType(); |
| 375 | } |
| 376 | |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 377 | QualType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 378 | QualType UnderlyingType = Importer.Import(T->getValueType()); |
| 379 | if(UnderlyingType.isNull()) |
| 380 | return QualType(); |
| 381 | |
| 382 | return Importer.getToContext().getAtomicType(UnderlyingType); |
| 383 | } |
| 384 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 385 | QualType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 386 | switch (T->getKind()) { |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 387 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 388 | case BuiltinType::Id: \ |
| 389 | return Importer.getToContext().SingletonId; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 390 | #include "clang/Basic/OpenCLImageTypes.def" |
John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 391 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 392 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 393 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 394 | #include "clang/AST/BuiltinTypes.def" |
| 395 | |
| 396 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 397 | // context supports C++. |
| 398 | |
| 399 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 400 | // context supports ObjC. |
| 401 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 402 | case BuiltinType::Char_U: |
| 403 | // The context we're importing from has an unsigned 'char'. If we're |
| 404 | // importing into a context with a signed 'char', translate to |
| 405 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 406 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 407 | return Importer.getToContext().UnsignedCharTy; |
| 408 | |
| 409 | return Importer.getToContext().CharTy; |
| 410 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 411 | case BuiltinType::Char_S: |
| 412 | // The context we're importing from has an unsigned 'char'. If we're |
| 413 | // importing into a context with a signed 'char', translate to |
| 414 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 415 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 416 | return Importer.getToContext().SignedCharTy; |
| 417 | |
| 418 | return Importer.getToContext().CharTy; |
| 419 | |
Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 420 | case BuiltinType::WChar_S: |
| 421 | case BuiltinType::WChar_U: |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 422 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 423 | // wchar_t? |
| 424 | return Importer.getToContext().WCharTy; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 425 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 426 | |
| 427 | llvm_unreachable("Invalid BuiltinType Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 430 | QualType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 431 | QualType OrigT = Importer.Import(T->getOriginalType()); |
| 432 | if (OrigT.isNull()) |
| 433 | return QualType(); |
| 434 | |
| 435 | return Importer.getToContext().getDecayedType(OrigT); |
| 436 | } |
| 437 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 438 | QualType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 439 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 440 | if (ToElementType.isNull()) |
| 441 | return QualType(); |
| 442 | |
| 443 | return Importer.getToContext().getComplexType(ToElementType); |
| 444 | } |
| 445 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 446 | QualType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 447 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 448 | if (ToPointeeType.isNull()) |
| 449 | return QualType(); |
| 450 | |
| 451 | return Importer.getToContext().getPointerType(ToPointeeType); |
| 452 | } |
| 453 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 454 | QualType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 455 | // FIXME: Check for blocks support in "to" context. |
| 456 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 457 | if (ToPointeeType.isNull()) |
| 458 | return QualType(); |
| 459 | |
| 460 | return Importer.getToContext().getBlockPointerType(ToPointeeType); |
| 461 | } |
| 462 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 463 | QualType |
| 464 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 465 | // FIXME: Check for C++ support in "to" context. |
| 466 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 467 | if (ToPointeeType.isNull()) |
| 468 | return QualType(); |
| 469 | |
| 470 | return Importer.getToContext().getLValueReferenceType(ToPointeeType); |
| 471 | } |
| 472 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 473 | QualType |
| 474 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 475 | // FIXME: Check for C++0x support in "to" context. |
| 476 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 477 | if (ToPointeeType.isNull()) |
| 478 | return QualType(); |
| 479 | |
| 480 | return Importer.getToContext().getRValueReferenceType(ToPointeeType); |
| 481 | } |
| 482 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 483 | QualType ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 484 | // FIXME: Check for C++ support in "to" context. |
| 485 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 486 | if (ToPointeeType.isNull()) |
| 487 | return QualType(); |
| 488 | |
| 489 | QualType ClassType = Importer.Import(QualType(T->getClass(), 0)); |
| 490 | return Importer.getToContext().getMemberPointerType(ToPointeeType, |
| 491 | ClassType.getTypePtr()); |
| 492 | } |
| 493 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 494 | QualType ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 495 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 496 | if (ToElementType.isNull()) |
| 497 | return QualType(); |
| 498 | |
| 499 | return Importer.getToContext().getConstantArrayType(ToElementType, |
| 500 | T->getSize(), |
| 501 | T->getSizeModifier(), |
| 502 | T->getIndexTypeCVRQualifiers()); |
| 503 | } |
| 504 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 505 | QualType |
| 506 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 507 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 508 | if (ToElementType.isNull()) |
| 509 | return QualType(); |
| 510 | |
| 511 | return Importer.getToContext().getIncompleteArrayType(ToElementType, |
| 512 | T->getSizeModifier(), |
| 513 | T->getIndexTypeCVRQualifiers()); |
| 514 | } |
| 515 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 516 | QualType ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 517 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 518 | if (ToElementType.isNull()) |
| 519 | return QualType(); |
| 520 | |
| 521 | Expr *Size = Importer.Import(T->getSizeExpr()); |
| 522 | if (!Size) |
| 523 | return QualType(); |
| 524 | |
| 525 | SourceRange Brackets = Importer.Import(T->getBracketsRange()); |
| 526 | return Importer.getToContext().getVariableArrayType(ToElementType, Size, |
| 527 | T->getSizeModifier(), |
| 528 | T->getIndexTypeCVRQualifiers(), |
| 529 | Brackets); |
| 530 | } |
| 531 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 532 | QualType ASTNodeImporter::VisitDependentSizedArrayType( |
| 533 | const DependentSizedArrayType *T) { |
| 534 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 535 | if (ToElementType.isNull()) |
| 536 | return QualType(); |
| 537 | |
| 538 | // SizeExpr may be null if size is not specified directly. |
| 539 | // For example, 'int a[]'. |
| 540 | Expr *Size = Importer.Import(T->getSizeExpr()); |
| 541 | if (!Size && T->getSizeExpr()) |
| 542 | return QualType(); |
| 543 | |
| 544 | SourceRange Brackets = Importer.Import(T->getBracketsRange()); |
| 545 | return Importer.getToContext().getDependentSizedArrayType( |
| 546 | ToElementType, Size, T->getSizeModifier(), T->getIndexTypeCVRQualifiers(), |
| 547 | Brackets); |
| 548 | } |
| 549 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 550 | QualType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 551 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 552 | if (ToElementType.isNull()) |
| 553 | return QualType(); |
| 554 | |
| 555 | return Importer.getToContext().getVectorType(ToElementType, |
| 556 | T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 557 | T->getVectorKind()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 558 | } |
| 559 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 560 | QualType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 561 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 562 | if (ToElementType.isNull()) |
| 563 | return QualType(); |
| 564 | |
| 565 | return Importer.getToContext().getExtVectorType(ToElementType, |
| 566 | T->getNumElements()); |
| 567 | } |
| 568 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 569 | QualType |
| 570 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 571 | // FIXME: What happens if we're importing a function without a prototype |
| 572 | // into C++? Should we make it variadic? |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 573 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 574 | if (ToResultType.isNull()) |
| 575 | return QualType(); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 576 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 577 | return Importer.getToContext().getFunctionNoProtoType(ToResultType, |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 578 | T->getExtInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 581 | QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 582 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 583 | if (ToResultType.isNull()) |
| 584 | return QualType(); |
| 585 | |
| 586 | // Import argument types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 587 | SmallVector<QualType, 4> ArgTypes; |
Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 588 | for (const auto &A : T->param_types()) { |
| 589 | QualType ArgType = Importer.Import(A); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 590 | if (ArgType.isNull()) |
| 591 | return QualType(); |
| 592 | ArgTypes.push_back(ArgType); |
| 593 | } |
| 594 | |
| 595 | // Import exception types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 596 | SmallVector<QualType, 4> ExceptionTypes; |
Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 597 | for (const auto &E : T->exceptions()) { |
| 598 | QualType ExceptionType = Importer.Import(E); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 599 | if (ExceptionType.isNull()) |
| 600 | return QualType(); |
| 601 | ExceptionTypes.push_back(ExceptionType); |
| 602 | } |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 603 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 604 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 605 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 606 | |
| 607 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 608 | ToEPI.Variadic = FromEPI.Variadic; |
| 609 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 610 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 611 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 612 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 613 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
| 614 | ToEPI.ExceptionSpec.NoexceptExpr = |
| 615 | Importer.Import(FromEPI.ExceptionSpec.NoexceptExpr); |
| 616 | ToEPI.ExceptionSpec.SourceDecl = cast_or_null<FunctionDecl>( |
| 617 | Importer.Import(FromEPI.ExceptionSpec.SourceDecl)); |
| 618 | ToEPI.ExceptionSpec.SourceTemplate = cast_or_null<FunctionDecl>( |
| 619 | Importer.Import(FromEPI.ExceptionSpec.SourceTemplate)); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 620 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 621 | return Importer.getToContext().getFunctionType(ToResultType, ArgTypes, ToEPI); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 622 | } |
| 623 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 624 | QualType ASTNodeImporter::VisitUnresolvedUsingType( |
| 625 | const UnresolvedUsingType *T) { |
| 626 | UnresolvedUsingTypenameDecl *ToD = cast_or_null<UnresolvedUsingTypenameDecl>( |
| 627 | Importer.Import(T->getDecl())); |
| 628 | if (!ToD) |
| 629 | return QualType(); |
| 630 | |
| 631 | UnresolvedUsingTypenameDecl *ToPrevD = |
| 632 | cast_or_null<UnresolvedUsingTypenameDecl>( |
| 633 | Importer.Import(T->getDecl()->getPreviousDecl())); |
| 634 | if (!ToPrevD && T->getDecl()->getPreviousDecl()) |
| 635 | return QualType(); |
| 636 | |
| 637 | return Importer.getToContext().getTypeDeclType(ToD, ToPrevD); |
| 638 | } |
| 639 | |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 640 | QualType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 641 | QualType ToInnerType = Importer.Import(T->getInnerType()); |
| 642 | if (ToInnerType.isNull()) |
| 643 | return QualType(); |
| 644 | |
| 645 | return Importer.getToContext().getParenType(ToInnerType); |
| 646 | } |
| 647 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 648 | QualType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 649 | TypedefNameDecl *ToDecl |
| 650 | = dyn_cast_or_null<TypedefNameDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 651 | if (!ToDecl) |
| 652 | return QualType(); |
| 653 | |
| 654 | return Importer.getToContext().getTypeDeclType(ToDecl); |
| 655 | } |
| 656 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 657 | QualType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 658 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 659 | if (!ToExpr) |
| 660 | return QualType(); |
| 661 | |
| 662 | return Importer.getToContext().getTypeOfExprType(ToExpr); |
| 663 | } |
| 664 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 665 | QualType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 666 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 667 | if (ToUnderlyingType.isNull()) |
| 668 | return QualType(); |
| 669 | |
| 670 | return Importer.getToContext().getTypeOfType(ToUnderlyingType); |
| 671 | } |
| 672 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 673 | QualType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 674 | // FIXME: Make sure that the "to" context supports C++0x! |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 675 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 676 | if (!ToExpr) |
| 677 | return QualType(); |
| 678 | |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 679 | QualType UnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 680 | if (UnderlyingType.isNull()) |
| 681 | return QualType(); |
| 682 | |
| 683 | return Importer.getToContext().getDecltypeType(ToExpr, UnderlyingType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 684 | } |
| 685 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 686 | QualType ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 687 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 688 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 689 | if (ToBaseType.isNull() || ToUnderlyingType.isNull()) |
| 690 | return QualType(); |
| 691 | |
| 692 | return Importer.getToContext().getUnaryTransformType(ToBaseType, |
| 693 | ToUnderlyingType, |
| 694 | T->getUTTKind()); |
| 695 | } |
| 696 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 697 | QualType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 698 | // FIXME: Make sure that the "to" context supports C++11! |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 699 | QualType FromDeduced = T->getDeducedType(); |
| 700 | QualType ToDeduced; |
| 701 | if (!FromDeduced.isNull()) { |
| 702 | ToDeduced = Importer.Import(FromDeduced); |
| 703 | if (ToDeduced.isNull()) |
| 704 | return QualType(); |
| 705 | } |
| 706 | |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 707 | return Importer.getToContext().getAutoType(ToDeduced, T->getKeyword(), |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 708 | /*IsDependent*/false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 709 | } |
| 710 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 711 | QualType ASTNodeImporter::VisitInjectedClassNameType( |
| 712 | const InjectedClassNameType *T) { |
| 713 | CXXRecordDecl *D = cast_or_null<CXXRecordDecl>(Importer.Import(T->getDecl())); |
| 714 | if (!D) |
| 715 | return QualType(); |
| 716 | |
| 717 | QualType InjType = Importer.Import(T->getInjectedSpecializationType()); |
| 718 | if (InjType.isNull()) |
| 719 | return QualType(); |
| 720 | |
| 721 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 722 | // See comments in InjectedClassNameType definition for details |
| 723 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 724 | enum { |
| 725 | TypeAlignmentInBits = 4, |
| 726 | TypeAlignment = 1 << TypeAlignmentInBits |
| 727 | }; |
| 728 | |
| 729 | return QualType(new (Importer.getToContext(), TypeAlignment) |
| 730 | InjectedClassNameType(D, InjType), 0); |
| 731 | } |
| 732 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 733 | QualType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 734 | RecordDecl *ToDecl |
| 735 | = dyn_cast_or_null<RecordDecl>(Importer.Import(T->getDecl())); |
| 736 | if (!ToDecl) |
| 737 | return QualType(); |
| 738 | |
| 739 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 740 | } |
| 741 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 742 | QualType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 743 | EnumDecl *ToDecl |
| 744 | = dyn_cast_or_null<EnumDecl>(Importer.Import(T->getDecl())); |
| 745 | if (!ToDecl) |
| 746 | return QualType(); |
| 747 | |
| 748 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 749 | } |
| 750 | |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 751 | QualType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 752 | QualType FromModifiedType = T->getModifiedType(); |
| 753 | QualType FromEquivalentType = T->getEquivalentType(); |
| 754 | QualType ToModifiedType; |
| 755 | QualType ToEquivalentType; |
| 756 | |
| 757 | if (!FromModifiedType.isNull()) { |
| 758 | ToModifiedType = Importer.Import(FromModifiedType); |
| 759 | if (ToModifiedType.isNull()) |
| 760 | return QualType(); |
| 761 | } |
| 762 | if (!FromEquivalentType.isNull()) { |
| 763 | ToEquivalentType = Importer.Import(FromEquivalentType); |
| 764 | if (ToEquivalentType.isNull()) |
| 765 | return QualType(); |
| 766 | } |
| 767 | |
| 768 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
| 769 | ToModifiedType, ToEquivalentType); |
| 770 | } |
| 771 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 772 | |
| 773 | QualType ASTNodeImporter::VisitTemplateTypeParmType( |
| 774 | const TemplateTypeParmType *T) { |
| 775 | TemplateTypeParmDecl *ParmDecl = |
| 776 | cast_or_null<TemplateTypeParmDecl>(Importer.Import(T->getDecl())); |
| 777 | if (!ParmDecl && T->getDecl()) |
| 778 | return QualType(); |
| 779 | |
| 780 | return Importer.getToContext().getTemplateTypeParmType( |
| 781 | T->getDepth(), T->getIndex(), T->isParameterPack(), ParmDecl); |
| 782 | } |
| 783 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 784 | QualType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
| 785 | const SubstTemplateTypeParmType *T) { |
| 786 | const TemplateTypeParmType *Replaced = |
| 787 | cast_or_null<TemplateTypeParmType>(Importer.Import( |
| 788 | QualType(T->getReplacedParameter(), 0)).getTypePtr()); |
| 789 | if (!Replaced) |
| 790 | return QualType(); |
| 791 | |
| 792 | QualType Replacement = Importer.Import(T->getReplacementType()); |
| 793 | if (Replacement.isNull()) |
| 794 | return QualType(); |
| 795 | Replacement = Replacement.getCanonicalType(); |
| 796 | |
| 797 | return Importer.getToContext().getSubstTemplateTypeParmType( |
| 798 | Replaced, Replacement); |
| 799 | } |
| 800 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 801 | QualType ASTNodeImporter::VisitTemplateSpecializationType( |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 802 | const TemplateSpecializationType *T) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 803 | TemplateName ToTemplate = Importer.Import(T->getTemplateName()); |
| 804 | if (ToTemplate.isNull()) |
| 805 | return QualType(); |
| 806 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 807 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 808 | if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
| 809 | return QualType(); |
| 810 | |
| 811 | QualType ToCanonType; |
| 812 | if (!QualType(T, 0).isCanonical()) { |
| 813 | QualType FromCanonType |
| 814 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
| 815 | ToCanonType =Importer.Import(FromCanonType); |
| 816 | if (ToCanonType.isNull()) |
| 817 | return QualType(); |
| 818 | } |
| 819 | return Importer.getToContext().getTemplateSpecializationType(ToTemplate, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 820 | ToTemplateArgs, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 821 | ToCanonType); |
| 822 | } |
| 823 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 824 | QualType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 825 | NestedNameSpecifier *ToQualifier = nullptr; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 826 | // Note: the qualifier in an ElaboratedType is optional. |
| 827 | if (T->getQualifier()) { |
| 828 | ToQualifier = Importer.Import(T->getQualifier()); |
| 829 | if (!ToQualifier) |
| 830 | return QualType(); |
| 831 | } |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 832 | |
| 833 | QualType ToNamedType = Importer.Import(T->getNamedType()); |
| 834 | if (ToNamedType.isNull()) |
| 835 | return QualType(); |
| 836 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 837 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
| 838 | ToQualifier, ToNamedType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 839 | } |
| 840 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 841 | QualType ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 842 | QualType Pattern = Importer.Import(T->getPattern()); |
| 843 | if (Pattern.isNull()) |
| 844 | return QualType(); |
| 845 | |
| 846 | return Importer.getToContext().getPackExpansionType(Pattern, |
| 847 | T->getNumExpansions()); |
| 848 | } |
| 849 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 850 | QualType ASTNodeImporter::VisitDependentTemplateSpecializationType( |
| 851 | const DependentTemplateSpecializationType *T) { |
| 852 | NestedNameSpecifier *Qualifier = Importer.Import(T->getQualifier()); |
| 853 | if (!Qualifier && T->getQualifier()) |
| 854 | return QualType(); |
| 855 | |
| 856 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
| 857 | if (!Name && T->getIdentifier()) |
| 858 | return QualType(); |
| 859 | |
| 860 | SmallVector<TemplateArgument, 2> ToPack; |
| 861 | ToPack.reserve(T->getNumArgs()); |
| 862 | if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToPack)) |
| 863 | return QualType(); |
| 864 | |
| 865 | return Importer.getToContext().getDependentTemplateSpecializationType( |
| 866 | T->getKeyword(), Qualifier, Name, ToPack); |
| 867 | } |
| 868 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 869 | QualType ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 870 | ObjCInterfaceDecl *Class |
| 871 | = dyn_cast_or_null<ObjCInterfaceDecl>(Importer.Import(T->getDecl())); |
| 872 | if (!Class) |
| 873 | return QualType(); |
| 874 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 875 | return Importer.getToContext().getObjCInterfaceType(Class); |
| 876 | } |
| 877 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 878 | QualType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 879 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 880 | if (ToBaseType.isNull()) |
| 881 | return QualType(); |
| 882 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 883 | SmallVector<QualType, 4> TypeArgs; |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 884 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 885 | QualType ImportedTypeArg = Importer.Import(TypeArg); |
| 886 | if (ImportedTypeArg.isNull()) |
| 887 | return QualType(); |
| 888 | |
| 889 | TypeArgs.push_back(ImportedTypeArg); |
| 890 | } |
| 891 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 892 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 893 | for (auto *P : T->quals()) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 894 | ObjCProtocolDecl *Protocol |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 895 | = dyn_cast_or_null<ObjCProtocolDecl>(Importer.Import(P)); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 896 | if (!Protocol) |
| 897 | return QualType(); |
| 898 | Protocols.push_back(Protocol); |
| 899 | } |
| 900 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 901 | return Importer.getToContext().getObjCObjectType(ToBaseType, TypeArgs, |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 902 | Protocols, |
| 903 | T->isKindOfTypeAsWritten()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 904 | } |
| 905 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 906 | QualType |
| 907 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 908 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 909 | if (ToPointeeType.isNull()) |
| 910 | return QualType(); |
| 911 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 912 | return Importer.getToContext().getObjCObjectPointerType(ToPointeeType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 913 | } |
| 914 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 915 | //---------------------------------------------------------------------------- |
| 916 | // Import Declarations |
| 917 | //---------------------------------------------------------------------------- |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 918 | bool ASTNodeImporter::ImportDeclParts(NamedDecl *D, DeclContext *&DC, |
| 919 | DeclContext *&LexicalDC, |
| 920 | DeclarationName &Name, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 921 | NamedDecl *&ToD, |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 922 | SourceLocation &Loc) { |
| 923 | // Import the context of this declaration. |
| 924 | DC = Importer.ImportContext(D->getDeclContext()); |
| 925 | if (!DC) |
| 926 | return true; |
| 927 | |
| 928 | LexicalDC = DC; |
| 929 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 930 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 931 | if (!LexicalDC) |
| 932 | return true; |
| 933 | } |
| 934 | |
| 935 | // Import the name of this declaration. |
| 936 | Name = Importer.Import(D->getDeclName()); |
| 937 | if (D->getDeclName() && !Name) |
| 938 | return true; |
| 939 | |
| 940 | // Import the location of this declaration. |
| 941 | Loc = Importer.Import(D->getLocation()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 942 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 943 | return false; |
| 944 | } |
| 945 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 946 | void ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
| 947 | if (!FromD) |
| 948 | return; |
| 949 | |
| 950 | if (!ToD) { |
| 951 | ToD = Importer.Import(FromD); |
| 952 | if (!ToD) |
| 953 | return; |
| 954 | } |
| 955 | |
| 956 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 957 | if (RecordDecl *ToRecord = cast_or_null<RecordDecl>(ToD)) { |
Sean Callanan | 19dfc93 | 2013-01-11 23:17:47 +0000 | [diff] [blame] | 958 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && !ToRecord->getDefinition()) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 959 | ImportDefinition(FromRecord, ToRecord); |
| 960 | } |
| 961 | } |
| 962 | return; |
| 963 | } |
| 964 | |
| 965 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 966 | if (EnumDecl *ToEnum = cast_or_null<EnumDecl>(ToD)) { |
| 967 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
| 968 | ImportDefinition(FromEnum, ToEnum); |
| 969 | } |
| 970 | } |
| 971 | return; |
| 972 | } |
| 973 | } |
| 974 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 975 | void |
| 976 | ASTNodeImporter::ImportDeclarationNameLoc(const DeclarationNameInfo &From, |
| 977 | DeclarationNameInfo& To) { |
| 978 | // NOTE: To.Name and To.Loc are already imported. |
| 979 | // We only have to import To.LocInfo. |
| 980 | switch (To.getName().getNameKind()) { |
| 981 | case DeclarationName::Identifier: |
| 982 | case DeclarationName::ObjCZeroArgSelector: |
| 983 | case DeclarationName::ObjCOneArgSelector: |
| 984 | case DeclarationName::ObjCMultiArgSelector: |
| 985 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 986 | case DeclarationName::CXXDeductionGuideName: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 987 | return; |
| 988 | |
| 989 | case DeclarationName::CXXOperatorName: { |
| 990 | SourceRange Range = From.getCXXOperatorNameRange(); |
| 991 | To.setCXXOperatorNameRange(Importer.Import(Range)); |
| 992 | return; |
| 993 | } |
| 994 | case DeclarationName::CXXLiteralOperatorName: { |
| 995 | SourceLocation Loc = From.getCXXLiteralOperatorNameLoc(); |
| 996 | To.setCXXLiteralOperatorNameLoc(Importer.Import(Loc)); |
| 997 | return; |
| 998 | } |
| 999 | case DeclarationName::CXXConstructorName: |
| 1000 | case DeclarationName::CXXDestructorName: |
| 1001 | case DeclarationName::CXXConversionFunctionName: { |
| 1002 | TypeSourceInfo *FromTInfo = From.getNamedTypeInfo(); |
| 1003 | To.setNamedTypeInfo(Importer.Import(FromTInfo)); |
| 1004 | return; |
| 1005 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1006 | } |
Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1007 | llvm_unreachable("Unknown name kind."); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1010 | void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1011 | if (Importer.isMinimalImport() && !ForceImport) { |
Sean Callanan | 81d577c | 2011-07-22 23:46:03 +0000 | [diff] [blame] | 1012 | Importer.ImportContext(FromDC); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1013 | return; |
| 1014 | } |
| 1015 | |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 1016 | for (auto *From : FromDC->decls()) |
| 1017 | Importer.Import(From); |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1020 | bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1021 | ImportDefinitionKind Kind) { |
| 1022 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1023 | if (Kind == IDK_Everything) |
| 1024 | ImportDeclContext(From, /*ForceImport=*/true); |
| 1025 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1026 | return false; |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1027 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1028 | |
| 1029 | To->startDefinition(); |
| 1030 | |
| 1031 | // Add base classes. |
| 1032 | if (CXXRecordDecl *ToCXX = dyn_cast<CXXRecordDecl>(To)) { |
| 1033 | CXXRecordDecl *FromCXX = cast<CXXRecordDecl>(From); |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1034 | |
| 1035 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1036 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 1037 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1038 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1039 | ToData.Aggregate = FromData.Aggregate; |
| 1040 | ToData.PlainOldData = FromData.PlainOldData; |
| 1041 | ToData.Empty = FromData.Empty; |
| 1042 | ToData.Polymorphic = FromData.Polymorphic; |
| 1043 | ToData.Abstract = FromData.Abstract; |
| 1044 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
| 1045 | ToData.HasNoNonEmptyBases = FromData.HasNoNonEmptyBases; |
| 1046 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 1047 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 1048 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 1049 | ToData.HasMutableFields = FromData.HasMutableFields; |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 1050 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1051 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 1052 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 1053 | ToData.HasUninitializedReferenceMember |
| 1054 | = FromData.HasUninitializedReferenceMember; |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1055 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1056 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 1057 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1058 | ToData.NeedOverloadResolutionForCopyConstructor |
| 1059 | = FromData.NeedOverloadResolutionForCopyConstructor; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1060 | ToData.NeedOverloadResolutionForMoveConstructor |
| 1061 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 1062 | ToData.NeedOverloadResolutionForMoveAssignment |
| 1063 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 1064 | ToData.NeedOverloadResolutionForDestructor |
| 1065 | = FromData.NeedOverloadResolutionForDestructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1066 | ToData.DefaultedCopyConstructorIsDeleted |
| 1067 | = FromData.DefaultedCopyConstructorIsDeleted; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1068 | ToData.DefaultedMoveConstructorIsDeleted |
| 1069 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 1070 | ToData.DefaultedMoveAssignmentIsDeleted |
| 1071 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 1072 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1073 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 1074 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1075 | ToData.HasConstexprNonCopyMoveConstructor |
| 1076 | = FromData.HasConstexprNonCopyMoveConstructor; |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1077 | ToData.HasDefaultedDefaultConstructor |
| 1078 | = FromData.HasDefaultedDefaultConstructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1079 | ToData.CanPassInRegisters = FromData.CanPassInRegisters; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1080 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 1081 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1082 | ToData.HasConstexprDefaultConstructor |
| 1083 | = FromData.HasConstexprDefaultConstructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1084 | ToData.HasNonLiteralTypeFieldsOrBases |
| 1085 | = FromData.HasNonLiteralTypeFieldsOrBases; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1086 | // ComputedVisibleConversions not imported. |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1087 | ToData.UserProvidedDefaultConstructor |
| 1088 | = FromData.UserProvidedDefaultConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1089 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1090 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 1091 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 1092 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 1093 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 1094 | ToData.ImplicitCopyAssignmentHasConstParam |
| 1095 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 1096 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 1097 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 1098 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 1099 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1100 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1101 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1102 | for (const auto &Base1 : FromCXX->bases()) { |
| 1103 | QualType T = Importer.Import(Base1.getType()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1104 | if (T.isNull()) |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1105 | return true; |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1106 | |
| 1107 | SourceLocation EllipsisLoc; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1108 | if (Base1.isPackExpansion()) |
| 1109 | EllipsisLoc = Importer.Import(Base1.getEllipsisLoc()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1110 | |
| 1111 | // Ensure that we have a definition for the base. |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1112 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1113 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1114 | Bases.push_back( |
| 1115 | new (Importer.getToContext()) |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1116 | CXXBaseSpecifier(Importer.Import(Base1.getSourceRange()), |
| 1117 | Base1.isVirtual(), |
| 1118 | Base1.isBaseOfClass(), |
| 1119 | Base1.getAccessSpecifierAsWritten(), |
| 1120 | Importer.Import(Base1.getTypeSourceInfo()), |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1121 | EllipsisLoc)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1122 | } |
| 1123 | if (!Bases.empty()) |
Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1124 | ToCXX->setBases(Bases.data(), Bases.size()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1127 | if (shouldForceImportDeclContext(Kind)) |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1128 | ImportDeclContext(From, /*ForceImport=*/true); |
| 1129 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1130 | To->completeDefinition(); |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1131 | return false; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1134 | bool ASTNodeImporter::ImportDefinition(VarDecl *From, VarDecl *To, |
| 1135 | ImportDefinitionKind Kind) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1136 | if (To->getAnyInitializer()) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1137 | return false; |
| 1138 | |
| 1139 | // FIXME: Can we really import any initializer? Alternatively, we could force |
| 1140 | // ourselves to import every declaration of a variable and then only use |
| 1141 | // getInit() here. |
| 1142 | To->setInit(Importer.Import(const_cast<Expr *>(From->getAnyInitializer()))); |
| 1143 | |
| 1144 | // FIXME: Other bits to merge? |
| 1145 | |
| 1146 | return false; |
| 1147 | } |
| 1148 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1149 | bool ASTNodeImporter::ImportDefinition(EnumDecl *From, EnumDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1150 | ImportDefinitionKind Kind) { |
| 1151 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1152 | if (Kind == IDK_Everything) |
| 1153 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1154 | return false; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1155 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1156 | |
| 1157 | To->startDefinition(); |
| 1158 | |
| 1159 | QualType T = Importer.Import(Importer.getFromContext().getTypeDeclType(From)); |
| 1160 | if (T.isNull()) |
| 1161 | return true; |
| 1162 | |
| 1163 | QualType ToPromotionType = Importer.Import(From->getPromotionType()); |
| 1164 | if (ToPromotionType.isNull()) |
| 1165 | return true; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1166 | |
| 1167 | if (shouldForceImportDeclContext(Kind)) |
| 1168 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1169 | |
| 1170 | // FIXME: we might need to merge the number of positive or negative bits |
| 1171 | // if the enumerator lists don't match. |
| 1172 | To->completeDefinition(T, ToPromotionType, |
| 1173 | From->getNumPositiveBits(), |
| 1174 | From->getNumNegativeBits()); |
| 1175 | return false; |
| 1176 | } |
| 1177 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1178 | TemplateParameterList *ASTNodeImporter::ImportTemplateParameterList( |
| 1179 | TemplateParameterList *Params) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1180 | SmallVector<NamedDecl *, 4> ToParams(Params->size()); |
| 1181 | if (ImportContainerChecked(*Params, ToParams)) |
| 1182 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1183 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1184 | Expr *ToRequiresClause; |
| 1185 | if (Expr *const R = Params->getRequiresClause()) { |
| 1186 | ToRequiresClause = Importer.Import(R); |
| 1187 | if (!ToRequiresClause) |
| 1188 | return nullptr; |
| 1189 | } else { |
| 1190 | ToRequiresClause = nullptr; |
| 1191 | } |
| 1192 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1193 | return TemplateParameterList::Create(Importer.getToContext(), |
| 1194 | Importer.Import(Params->getTemplateLoc()), |
| 1195 | Importer.Import(Params->getLAngleLoc()), |
David Majnemer | 902f8c6 | 2015-12-27 07:16:27 +0000 | [diff] [blame] | 1196 | ToParams, |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1197 | Importer.Import(Params->getRAngleLoc()), |
| 1198 | ToRequiresClause); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1201 | TemplateArgument |
| 1202 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1203 | switch (From.getKind()) { |
| 1204 | case TemplateArgument::Null: |
| 1205 | return TemplateArgument(); |
| 1206 | |
| 1207 | case TemplateArgument::Type: { |
| 1208 | QualType ToType = Importer.Import(From.getAsType()); |
| 1209 | if (ToType.isNull()) |
| 1210 | return TemplateArgument(); |
| 1211 | return TemplateArgument(ToType); |
| 1212 | } |
| 1213 | |
| 1214 | case TemplateArgument::Integral: { |
| 1215 | QualType ToType = Importer.Import(From.getIntegralType()); |
| 1216 | if (ToType.isNull()) |
| 1217 | return TemplateArgument(); |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 1218 | return TemplateArgument(From, ToType); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1221 | case TemplateArgument::Declaration: { |
David Blaikie | 3c7dd6b | 2014-10-22 19:54:16 +0000 | [diff] [blame] | 1222 | ValueDecl *To = cast_or_null<ValueDecl>(Importer.Import(From.getAsDecl())); |
| 1223 | QualType ToType = Importer.Import(From.getParamTypeForDecl()); |
| 1224 | if (!To || ToType.isNull()) |
| 1225 | return TemplateArgument(); |
| 1226 | return TemplateArgument(To, ToType); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | case TemplateArgument::NullPtr: { |
| 1230 | QualType ToType = Importer.Import(From.getNullPtrType()); |
| 1231 | if (ToType.isNull()) |
| 1232 | return TemplateArgument(); |
| 1233 | return TemplateArgument(ToType, /*isNullPtr*/true); |
| 1234 | } |
| 1235 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1236 | case TemplateArgument::Template: { |
| 1237 | TemplateName ToTemplate = Importer.Import(From.getAsTemplate()); |
| 1238 | if (ToTemplate.isNull()) |
| 1239 | return TemplateArgument(); |
| 1240 | |
| 1241 | return TemplateArgument(ToTemplate); |
| 1242 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1243 | |
| 1244 | case TemplateArgument::TemplateExpansion: { |
| 1245 | TemplateName ToTemplate |
| 1246 | = Importer.Import(From.getAsTemplateOrTemplatePattern()); |
| 1247 | if (ToTemplate.isNull()) |
| 1248 | return TemplateArgument(); |
| 1249 | |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 1250 | return TemplateArgument(ToTemplate, From.getNumTemplateExpansions()); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1253 | case TemplateArgument::Expression: |
| 1254 | if (Expr *ToExpr = Importer.Import(From.getAsExpr())) |
| 1255 | return TemplateArgument(ToExpr); |
| 1256 | return TemplateArgument(); |
| 1257 | |
| 1258 | case TemplateArgument::Pack: { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1259 | SmallVector<TemplateArgument, 2> ToPack; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1260 | ToPack.reserve(From.pack_size()); |
| 1261 | if (ImportTemplateArguments(From.pack_begin(), From.pack_size(), ToPack)) |
| 1262 | return TemplateArgument(); |
Benjamin Kramer | cce6347 | 2015-08-05 09:40:22 +0000 | [diff] [blame] | 1263 | |
| 1264 | return TemplateArgument( |
| 1265 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | llvm_unreachable("Invalid template argument kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1272 | Optional<TemplateArgumentLoc> |
| 1273 | ASTNodeImporter::ImportTemplateArgumentLoc(const TemplateArgumentLoc &TALoc) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1274 | TemplateArgument Arg = ImportTemplateArgument(TALoc.getArgument()); |
| 1275 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 1276 | TemplateArgumentLocInfo ToInfo; |
| 1277 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 1278 | Expr *E = Importer.Import(FromInfo.getAsExpr()); |
| 1279 | ToInfo = TemplateArgumentLocInfo(E); |
| 1280 | if (!E) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1281 | return None; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1282 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 1283 | if (TypeSourceInfo *TSI = Importer.Import(FromInfo.getAsTypeSourceInfo())) |
| 1284 | ToInfo = TemplateArgumentLocInfo(TSI); |
| 1285 | else |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1286 | return None; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1287 | } else { |
| 1288 | ToInfo = TemplateArgumentLocInfo( |
| 1289 | Importer.Import(FromInfo.getTemplateQualifierLoc()), |
| 1290 | Importer.Import(FromInfo.getTemplateNameLoc()), |
| 1291 | Importer.Import(FromInfo.getTemplateEllipsisLoc())); |
| 1292 | } |
| 1293 | return TemplateArgumentLoc(Arg, ToInfo); |
| 1294 | } |
| 1295 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1296 | bool ASTNodeImporter::ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 1297 | unsigned NumFromArgs, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1298 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1299 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
| 1300 | TemplateArgument To = ImportTemplateArgument(FromArgs[I]); |
| 1301 | if (To.isNull() && !FromArgs[I].isNull()) |
| 1302 | return true; |
| 1303 | |
| 1304 | ToArgs.push_back(To); |
| 1305 | } |
| 1306 | |
| 1307 | return false; |
| 1308 | } |
| 1309 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 1310 | // We cannot use Optional<> pattern here and below because |
| 1311 | // TemplateArgumentListInfo's operator new is declared as deleted so it cannot |
| 1312 | // be stored in Optional. |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1313 | template <typename InContainerTy> |
| 1314 | bool ASTNodeImporter::ImportTemplateArgumentListInfo( |
| 1315 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 1316 | for (const auto &FromLoc : Container) { |
| 1317 | if (auto ToLoc = ImportTemplateArgumentLoc(FromLoc)) |
| 1318 | ToTAInfo.addArgument(*ToLoc); |
| 1319 | else |
| 1320 | return true; |
| 1321 | } |
| 1322 | return false; |
| 1323 | } |
| 1324 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 1325 | template <typename InContainerTy> |
| 1326 | bool ASTNodeImporter::ImportTemplateArgumentListInfo( |
| 1327 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 1328 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { |
| 1329 | TemplateArgumentListInfo ToTAInfo(Importer.Import(FromLAngleLoc), |
| 1330 | Importer.Import(FromRAngleLoc)); |
| 1331 | if (ImportTemplateArgumentListInfo(Container, ToTAInfo)) |
| 1332 | return true; |
| 1333 | Result = ToTAInfo; |
| 1334 | return false; |
| 1335 | } |
| 1336 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1337 | template <> |
| 1338 | bool ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( |
| 1339 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { |
| 1340 | return ImportTemplateArgumentListInfo( |
| 1341 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); |
| 1342 | } |
| 1343 | |
| 1344 | template <> |
| 1345 | bool ASTNodeImporter::ImportTemplateArgumentListInfo< |
| 1346 | ASTTemplateArgumentListInfo>(const ASTTemplateArgumentListInfo &From, |
| 1347 | TemplateArgumentListInfo &Result) { |
| 1348 | return ImportTemplateArgumentListInfo(From.LAngleLoc, From.RAngleLoc, |
| 1349 | From.arguments(), Result); |
| 1350 | } |
| 1351 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1352 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1353 | RecordDecl *ToRecord, bool Complain) { |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1354 | // Eliminate a potential failure point where we attempt to re-import |
| 1355 | // something we're trying to import while completing ToRecord. |
| 1356 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 1357 | if (ToOrigin) { |
| 1358 | RecordDecl *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
| 1359 | if (ToOriginRecord) |
| 1360 | ToRecord = ToOriginRecord; |
| 1361 | } |
| 1362 | |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1363 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1364 | ToRecord->getASTContext(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1365 | Importer.getNonEquivalentDecls(), |
| 1366 | false, Complain); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1367 | return Ctx.IsStructurallyEquivalent(FromRecord, ToRecord); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1368 | } |
| 1369 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1370 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 1371 | bool Complain) { |
| 1372 | StructuralEquivalenceContext Ctx( |
| 1373 | Importer.getFromContext(), Importer.getToContext(), |
| 1374 | Importer.getNonEquivalentDecls(), false, Complain); |
| 1375 | return Ctx.IsStructurallyEquivalent(FromVar, ToVar); |
| 1376 | } |
| 1377 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1378 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1379 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1380 | Importer.getToContext(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1381 | Importer.getNonEquivalentDecls()); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1382 | return Ctx.IsStructurallyEquivalent(FromEnum, ToEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1385 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 1386 | FunctionTemplateDecl *To) { |
| 1387 | StructuralEquivalenceContext Ctx( |
| 1388 | Importer.getFromContext(), Importer.getToContext(), |
| 1389 | Importer.getNonEquivalentDecls(), false, false); |
| 1390 | return Ctx.IsStructurallyEquivalent(From, To); |
| 1391 | } |
| 1392 | |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1393 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
| 1394 | EnumConstantDecl *ToEC) |
| 1395 | { |
| 1396 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 1397 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 1398 | |
| 1399 | return FromVal.isSigned() == ToVal.isSigned() && |
| 1400 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 1401 | FromVal == ToVal; |
| 1402 | } |
| 1403 | |
| 1404 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1405 | ClassTemplateDecl *To) { |
| 1406 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1407 | Importer.getToContext(), |
| 1408 | Importer.getNonEquivalentDecls()); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1409 | return Ctx.IsStructurallyEquivalent(From, To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1410 | } |
| 1411 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1412 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 1413 | VarTemplateDecl *To) { |
| 1414 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1415 | Importer.getToContext(), |
| 1416 | Importer.getNonEquivalentDecls()); |
| 1417 | return Ctx.IsStructurallyEquivalent(From, To); |
| 1418 | } |
| 1419 | |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1420 | Decl *ASTNodeImporter::VisitDecl(Decl *D) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 1421 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1422 | << D->getDeclKindName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1423 | return nullptr; |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1426 | Decl *ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 1427 | // Import the context of this declaration. |
| 1428 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1429 | if (!DC) |
| 1430 | return nullptr; |
| 1431 | |
| 1432 | DeclContext *LexicalDC = DC; |
| 1433 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 1434 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 1435 | if (!LexicalDC) |
| 1436 | return nullptr; |
| 1437 | } |
| 1438 | |
| 1439 | // Import the location of this declaration. |
| 1440 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1441 | |
| 1442 | EmptyDecl *ToD = EmptyDecl::Create(Importer.getToContext(), DC, Loc); |
| 1443 | ToD->setLexicalDeclContext(LexicalDC); |
| 1444 | Importer.Imported(D, ToD); |
| 1445 | LexicalDC->addDeclInternal(ToD); |
| 1446 | return ToD; |
| 1447 | } |
| 1448 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 1449 | Decl *ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 1450 | TranslationUnitDecl *ToD = |
| 1451 | Importer.getToContext().getTranslationUnitDecl(); |
| 1452 | |
| 1453 | Importer.Imported(D, ToD); |
| 1454 | |
| 1455 | return ToD; |
| 1456 | } |
| 1457 | |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1458 | Decl *ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 1459 | |
| 1460 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1461 | SourceLocation ColonLoc = Importer.Import(D->getColonLoc()); |
| 1462 | |
| 1463 | // Import the context of this declaration. |
| 1464 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1465 | if (!DC) |
| 1466 | return nullptr; |
| 1467 | |
| 1468 | AccessSpecDecl *accessSpecDecl |
| 1469 | = AccessSpecDecl::Create(Importer.getToContext(), D->getAccess(), |
| 1470 | DC, Loc, ColonLoc); |
| 1471 | |
| 1472 | if (!accessSpecDecl) |
| 1473 | return nullptr; |
| 1474 | |
| 1475 | // Lexical DeclContext and Semantic DeclContext |
| 1476 | // is always the same for the accessSpec. |
| 1477 | accessSpecDecl->setLexicalDeclContext(DC); |
| 1478 | DC->addDeclInternal(accessSpecDecl); |
| 1479 | |
| 1480 | return accessSpecDecl; |
| 1481 | } |
| 1482 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1483 | Decl *ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 1484 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1485 | if (!DC) |
| 1486 | return nullptr; |
| 1487 | |
| 1488 | DeclContext *LexicalDC = DC; |
| 1489 | |
| 1490 | // Import the location of this declaration. |
| 1491 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1492 | |
| 1493 | Expr *AssertExpr = Importer.Import(D->getAssertExpr()); |
| 1494 | if (!AssertExpr) |
| 1495 | return nullptr; |
| 1496 | |
| 1497 | StringLiteral *FromMsg = D->getMessage(); |
| 1498 | StringLiteral *ToMsg = cast_or_null<StringLiteral>(Importer.Import(FromMsg)); |
| 1499 | if (!ToMsg && FromMsg) |
| 1500 | return nullptr; |
| 1501 | |
| 1502 | StaticAssertDecl *ToD = StaticAssertDecl::Create( |
| 1503 | Importer.getToContext(), DC, Loc, AssertExpr, ToMsg, |
| 1504 | Importer.Import(D->getRParenLoc()), D->isFailed()); |
| 1505 | |
| 1506 | ToD->setLexicalDeclContext(LexicalDC); |
| 1507 | LexicalDC->addDeclInternal(ToD); |
| 1508 | Importer.Imported(D, ToD); |
| 1509 | return ToD; |
| 1510 | } |
| 1511 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1512 | Decl *ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
| 1513 | // Import the major distinguishing characteristics of this namespace. |
| 1514 | DeclContext *DC, *LexicalDC; |
| 1515 | DeclarationName Name; |
| 1516 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1517 | NamedDecl *ToD; |
| 1518 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1519 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1520 | if (ToD) |
| 1521 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1522 | |
| 1523 | NamespaceDecl *MergeWithNamespace = nullptr; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1524 | if (!Name) { |
| 1525 | // This is an anonymous namespace. Adopt an existing anonymous |
| 1526 | // namespace if we can. |
| 1527 | // FIXME: Not testable. |
| 1528 | if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| 1529 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 1530 | else |
| 1531 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 1532 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1533 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1534 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1535 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1536 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1537 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1538 | continue; |
| 1539 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1540 | if (NamespaceDecl *FoundNS = dyn_cast<NamespaceDecl>(FoundDecls[I])) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1541 | MergeWithNamespace = FoundNS; |
| 1542 | ConflictingDecls.clear(); |
| 1543 | break; |
| 1544 | } |
| 1545 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1546 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | if (!ConflictingDecls.empty()) { |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 1550 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1551 | ConflictingDecls.data(), |
| 1552 | ConflictingDecls.size()); |
| 1553 | } |
| 1554 | } |
| 1555 | |
| 1556 | // Create the "to" namespace, if needed. |
| 1557 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 1558 | if (!ToNamespace) { |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 1559 | ToNamespace = NamespaceDecl::Create(Importer.getToContext(), DC, |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1560 | D->isInline(), |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 1561 | Importer.Import(D->getLocStart()), |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1562 | Loc, Name.getAsIdentifierInfo(), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1563 | /*PrevDecl=*/nullptr); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1564 | ToNamespace->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1565 | LexicalDC->addDeclInternal(ToNamespace); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1566 | |
| 1567 | // If this is an anonymous namespace, register it as the anonymous |
| 1568 | // namespace within its context. |
| 1569 | if (!Name) { |
| 1570 | if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| 1571 | TU->setAnonymousNamespace(ToNamespace); |
| 1572 | else |
| 1573 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 1574 | } |
| 1575 | } |
| 1576 | Importer.Imported(D, ToNamespace); |
| 1577 | |
| 1578 | ImportDeclContext(D); |
| 1579 | |
| 1580 | return ToNamespace; |
| 1581 | } |
| 1582 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1583 | Decl *ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| 1584 | // Import the major distinguishing characteristics of this namespace. |
| 1585 | DeclContext *DC, *LexicalDC; |
| 1586 | DeclarationName Name; |
| 1587 | SourceLocation Loc; |
| 1588 | NamedDecl *LookupD; |
| 1589 | if (ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 1590 | return nullptr; |
| 1591 | if (LookupD) |
| 1592 | return LookupD; |
| 1593 | |
| 1594 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 1595 | |
| 1596 | NamespaceDecl *TargetDecl = cast_or_null<NamespaceDecl>( |
| 1597 | Importer.Import(D->getNamespace())); |
| 1598 | if (!TargetDecl) |
| 1599 | return nullptr; |
| 1600 | |
| 1601 | IdentifierInfo *ToII = Importer.Import(D->getIdentifier()); |
| 1602 | if (!ToII) |
| 1603 | return nullptr; |
| 1604 | |
| 1605 | NestedNameSpecifierLoc ToQLoc = Importer.Import(D->getQualifierLoc()); |
| 1606 | if (D->getQualifierLoc() && !ToQLoc) |
| 1607 | return nullptr; |
| 1608 | |
| 1609 | NamespaceAliasDecl *ToD = NamespaceAliasDecl::Create( |
| 1610 | Importer.getToContext(), DC, Importer.Import(D->getNamespaceLoc()), |
| 1611 | Importer.Import(D->getAliasLoc()), ToII, ToQLoc, |
| 1612 | Importer.Import(D->getTargetNameLoc()), TargetDecl); |
| 1613 | |
| 1614 | ToD->setLexicalDeclContext(LexicalDC); |
| 1615 | Importer.Imported(D, ToD); |
| 1616 | LexicalDC->addDeclInternal(ToD); |
| 1617 | |
| 1618 | return ToD; |
| 1619 | } |
| 1620 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1621 | Decl *ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1622 | // Import the major distinguishing characteristics of this typedef. |
| 1623 | DeclContext *DC, *LexicalDC; |
| 1624 | DeclarationName Name; |
| 1625 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1626 | NamedDecl *ToD; |
| 1627 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1628 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1629 | if (ToD) |
| 1630 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1631 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1632 | // If this typedef is not in block scope, determine whether we've |
| 1633 | // seen a typedef with the same name (that we can merge with) or any |
| 1634 | // other entity by that name (which name lookup could conflict with). |
| 1635 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1636 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1637 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1638 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1639 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1640 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1641 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1642 | continue; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1643 | if (TypedefNameDecl *FoundTypedef = |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1644 | dyn_cast<TypedefNameDecl>(FoundDecls[I])) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1645 | if (Importer.IsStructurallyEquivalent(D->getUnderlyingType(), |
| 1646 | FoundTypedef->getUnderlyingType())) |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1647 | return Importer.Imported(D, FoundTypedef); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1648 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1649 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1650 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1651 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1652 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1653 | if (!ConflictingDecls.empty()) { |
| 1654 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1655 | ConflictingDecls.data(), |
| 1656 | ConflictingDecls.size()); |
| 1657 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1658 | return nullptr; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1659 | } |
| 1660 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1661 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1662 | // Import the underlying type of this typedef; |
| 1663 | QualType T = Importer.Import(D->getUnderlyingType()); |
| 1664 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1665 | return nullptr; |
| 1666 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1667 | // Create the new typedef node. |
| 1668 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 1669 | SourceLocation StartL = Importer.Import(D->getLocStart()); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1670 | TypedefNameDecl *ToTypedef; |
| 1671 | if (IsAlias) |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1672 | ToTypedef = TypeAliasDecl::Create(Importer.getToContext(), DC, StartL, Loc, |
| 1673 | Name.getAsIdentifierInfo(), TInfo); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 1674 | else |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1675 | ToTypedef = TypedefDecl::Create(Importer.getToContext(), DC, |
| 1676 | StartL, Loc, |
| 1677 | Name.getAsIdentifierInfo(), |
| 1678 | TInfo); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1679 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1680 | ToTypedef->setAccess(D->getAccess()); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1681 | ToTypedef->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1682 | Importer.Imported(D, ToTypedef); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1683 | |
| 1684 | // Templated declarations should not appear in DeclContext. |
| 1685 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 1686 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 1687 | LexicalDC->addDeclInternal(ToTypedef); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1688 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1689 | return ToTypedef; |
| 1690 | } |
| 1691 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1692 | Decl *ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
| 1693 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 1694 | } |
| 1695 | |
| 1696 | Decl *ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| 1697 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 1698 | } |
| 1699 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1700 | Decl *ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| 1701 | // Import the major distinguishing characteristics of this typedef. |
| 1702 | DeclContext *DC, *LexicalDC; |
| 1703 | DeclarationName Name; |
| 1704 | SourceLocation Loc; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1705 | NamedDecl *FoundD; |
| 1706 | if (ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1707 | return nullptr; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1708 | if (FoundD) |
| 1709 | return FoundD; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1710 | |
| 1711 | // If this typedef is not in block scope, determine whether we've |
| 1712 | // seen a typedef with the same name (that we can merge with) or any |
| 1713 | // other entity by that name (which name lookup could conflict with). |
| 1714 | if (!DC->isFunctionOrMethod()) { |
| 1715 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 1716 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 1717 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 1718 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
| 1719 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1720 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
| 1721 | continue; |
| 1722 | if (auto *FoundAlias = |
| 1723 | dyn_cast<TypeAliasTemplateDecl>(FoundDecls[I])) |
| 1724 | return Importer.Imported(D, FoundAlias); |
| 1725 | ConflictingDecls.push_back(FoundDecls[I]); |
| 1726 | } |
| 1727 | |
| 1728 | if (!ConflictingDecls.empty()) { |
| 1729 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1730 | ConflictingDecls.data(), |
| 1731 | ConflictingDecls.size()); |
| 1732 | if (!Name) |
| 1733 | return nullptr; |
| 1734 | } |
| 1735 | } |
| 1736 | |
| 1737 | TemplateParameterList *Params = ImportTemplateParameterList( |
| 1738 | D->getTemplateParameters()); |
| 1739 | if (!Params) |
| 1740 | return nullptr; |
| 1741 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1742 | auto *TemplDecl = cast_or_null<TypeAliasDecl>( |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1743 | Importer.Import(D->getTemplatedDecl())); |
| 1744 | if (!TemplDecl) |
| 1745 | return nullptr; |
| 1746 | |
| 1747 | TypeAliasTemplateDecl *ToAlias = TypeAliasTemplateDecl::Create( |
| 1748 | Importer.getToContext(), DC, Loc, Name, Params, TemplDecl); |
| 1749 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1750 | TemplDecl->setDescribedAliasTemplate(ToAlias); |
| 1751 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1752 | ToAlias->setAccess(D->getAccess()); |
| 1753 | ToAlias->setLexicalDeclContext(LexicalDC); |
| 1754 | Importer.Imported(D, ToAlias); |
| 1755 | LexicalDC->addDeclInternal(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1756 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1757 | } |
| 1758 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1759 | Decl *ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
| 1760 | // Import the major distinguishing characteristics of this label. |
| 1761 | DeclContext *DC, *LexicalDC; |
| 1762 | DeclarationName Name; |
| 1763 | SourceLocation Loc; |
| 1764 | NamedDecl *ToD; |
| 1765 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 1766 | return nullptr; |
| 1767 | if (ToD) |
| 1768 | return ToD; |
| 1769 | |
| 1770 | assert(LexicalDC->isFunctionOrMethod()); |
| 1771 | |
| 1772 | LabelDecl *ToLabel = D->isGnuLocal() |
| 1773 | ? LabelDecl::Create(Importer.getToContext(), |
| 1774 | DC, Importer.Import(D->getLocation()), |
| 1775 | Name.getAsIdentifierInfo(), |
| 1776 | Importer.Import(D->getLocStart())) |
| 1777 | : LabelDecl::Create(Importer.getToContext(), |
| 1778 | DC, Importer.Import(D->getLocation()), |
| 1779 | Name.getAsIdentifierInfo()); |
| 1780 | Importer.Imported(D, ToLabel); |
| 1781 | |
| 1782 | LabelStmt *Label = cast_or_null<LabelStmt>(Importer.Import(D->getStmt())); |
| 1783 | if (!Label) |
| 1784 | return nullptr; |
| 1785 | |
| 1786 | ToLabel->setStmt(Label); |
| 1787 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 1788 | LexicalDC->addDeclInternal(ToLabel); |
| 1789 | return ToLabel; |
| 1790 | } |
| 1791 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1792 | Decl *ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
| 1793 | // Import the major distinguishing characteristics of this enum. |
| 1794 | DeclContext *DC, *LexicalDC; |
| 1795 | DeclarationName Name; |
| 1796 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1797 | NamedDecl *ToD; |
| 1798 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1799 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1800 | if (ToD) |
| 1801 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1802 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1803 | // Figure out what enum name we're looking for. |
| 1804 | unsigned IDNS = Decl::IDNS_Tag; |
| 1805 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1806 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 1807 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1808 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1809 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1810 | IDNS |= Decl::IDNS_Ordinary; |
| 1811 | |
| 1812 | // We may already have an enum of the same name; try to find and match it. |
| 1813 | if (!DC->isFunctionOrMethod() && SearchName) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1814 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1815 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 1816 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1817 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1818 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1819 | continue; |
| 1820 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1821 | Decl *Found = FoundDecls[I]; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1822 | if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1823 | if (const TagType *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| 1824 | Found = Tag->getDecl(); |
| 1825 | } |
| 1826 | |
| 1827 | if (EnumDecl *FoundEnum = dyn_cast<EnumDecl>(Found)) { |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1828 | if (IsStructuralMatch(D, FoundEnum)) |
| 1829 | return Importer.Imported(D, FoundEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1830 | } |
| 1831 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1832 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | if (!ConflictingDecls.empty()) { |
| 1836 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1837 | ConflictingDecls.data(), |
| 1838 | ConflictingDecls.size()); |
| 1839 | } |
| 1840 | } |
| 1841 | |
| 1842 | // Create the enum declaration. |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 1843 | EnumDecl *D2 = EnumDecl::Create(Importer.getToContext(), DC, |
| 1844 | Importer.Import(D->getLocStart()), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1845 | Loc, Name.getAsIdentifierInfo(), nullptr, |
Abramo Bagnara | 0e05e24 | 2010-12-03 18:54:17 +0000 | [diff] [blame] | 1846 | D->isScoped(), D->isScopedUsingClassTag(), |
| 1847 | D->isFixed()); |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 1848 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 1849 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1850 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1851 | D2->setLexicalDeclContext(LexicalDC); |
| 1852 | Importer.Imported(D, D2); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1853 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1854 | |
| 1855 | // Import the integer type. |
| 1856 | QualType ToIntegerType = Importer.Import(D->getIntegerType()); |
| 1857 | if (ToIntegerType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1858 | return nullptr; |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1859 | D2->setIntegerType(ToIntegerType); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1860 | |
| 1861 | // Import the definition |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 1862 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1863 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1864 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1865 | return D2; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1866 | } |
| 1867 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1868 | Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
| 1869 | // If this record has a definition in the translation unit we're coming from, |
| 1870 | // but this particular declaration is not that definition, import the |
| 1871 | // definition and map to that. |
Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 1872 | TagDecl *Definition = D->getDefinition(); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1873 | if (Definition && Definition != D) { |
| 1874 | Decl *ImportedDef = Importer.Import(Definition); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1875 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1876 | return nullptr; |
| 1877 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1878 | return Importer.Imported(D, ImportedDef); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | // Import the major distinguishing characteristics of this record. |
| 1882 | DeclContext *DC, *LexicalDC; |
| 1883 | DeclarationName Name; |
| 1884 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1885 | NamedDecl *ToD; |
| 1886 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1887 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1888 | if (ToD) |
| 1889 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1890 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1891 | // Figure out what structure name we're looking for. |
| 1892 | unsigned IDNS = Decl::IDNS_Tag; |
| 1893 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1894 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 1895 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1896 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1897 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1898 | IDNS |= Decl::IDNS_Ordinary; |
| 1899 | |
| 1900 | // 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] | 1901 | RecordDecl *AdoptDecl = nullptr; |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 1902 | RecordDecl *PrevDecl = nullptr; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1903 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1904 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1905 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 1906 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 1907 | |
| 1908 | if (!FoundDecls.empty()) { |
| 1909 | // We're going to have to compare D against potentially conflicting Decls, so complete it. |
| 1910 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 1911 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 1912 | } |
| 1913 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1914 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1915 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1916 | continue; |
| 1917 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1918 | Decl *Found = FoundDecls[I]; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1919 | if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1920 | if (const TagType *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| 1921 | Found = Tag->getDecl(); |
| 1922 | } |
| 1923 | |
| 1924 | if (RecordDecl *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
Gabor Horvath | 3b392bb | 2017-04-03 21:06:45 +0000 | [diff] [blame] | 1925 | if (D->isAnonymousStructOrUnion() && |
| 1926 | FoundRecord->isAnonymousStructOrUnion()) { |
| 1927 | // If both anonymous structs/unions are in a record context, make sure |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 1928 | // they occur in the same location in the context records. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1929 | if (Optional<unsigned> Index1 = |
| 1930 | StructuralEquivalenceContext::findUntaggedStructOrUnionIndex( |
| 1931 | D)) { |
| 1932 | if (Optional<unsigned> Index2 = StructuralEquivalenceContext:: |
Sean Callanan | 488f861 | 2016-07-14 19:53:44 +0000 | [diff] [blame] | 1933 | findUntaggedStructOrUnionIndex(FoundRecord)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 1934 | if (*Index1 != *Index2) |
| 1935 | continue; |
| 1936 | } |
| 1937 | } |
| 1938 | } |
| 1939 | |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 1940 | PrevDecl = FoundRecord; |
| 1941 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1942 | if (RecordDecl *FoundDef = FoundRecord->getDefinition()) { |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1943 | if ((SearchName && !D->isCompleteDefinition()) |
| 1944 | || (D->isCompleteDefinition() && |
| 1945 | D->isAnonymousStructOrUnion() |
| 1946 | == FoundDef->isAnonymousStructOrUnion() && |
| 1947 | IsStructuralMatch(D, FoundDef))) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1948 | // The record types structurally match, or the "from" translation |
| 1949 | // unit only had a forward declaration anyway; call it the same |
| 1950 | // function. |
| 1951 | // FIXME: For C++, we should also merge methods here. |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1952 | return Importer.Imported(D, FoundDef); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1953 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1954 | } else if (!D->isCompleteDefinition()) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1955 | // We have a forward declaration of this type, so adopt that forward |
| 1956 | // declaration rather than building a new one. |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 1957 | |
| 1958 | // If one or both can be completed from external storage then try one |
| 1959 | // last time to complete and compare them before doing this. |
| 1960 | |
| 1961 | if (FoundRecord->hasExternalLexicalStorage() && |
| 1962 | !FoundRecord->isCompleteDefinition()) |
| 1963 | FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord); |
| 1964 | if (D->hasExternalLexicalStorage()) |
| 1965 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 1966 | |
| 1967 | if (FoundRecord->isCompleteDefinition() && |
| 1968 | D->isCompleteDefinition() && |
| 1969 | !IsStructuralMatch(D, FoundRecord)) |
| 1970 | continue; |
| 1971 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1972 | AdoptDecl = FoundRecord; |
| 1973 | continue; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1974 | } else if (!SearchName) { |
| 1975 | continue; |
| 1976 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1977 | } |
| 1978 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1979 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1980 | } |
| 1981 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1982 | if (!ConflictingDecls.empty() && SearchName) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1983 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1984 | ConflictingDecls.data(), |
| 1985 | ConflictingDecls.size()); |
| 1986 | } |
| 1987 | } |
| 1988 | |
| 1989 | // Create the record declaration. |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1990 | RecordDecl *D2 = AdoptDecl; |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 1991 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1992 | if (!D2) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 1993 | CXXRecordDecl *D2CXX = nullptr; |
| 1994 | if (CXXRecordDecl *DCXX = llvm::dyn_cast<CXXRecordDecl>(D)) { |
| 1995 | if (DCXX->isLambda()) { |
| 1996 | TypeSourceInfo *TInfo = Importer.Import(DCXX->getLambdaTypeInfo()); |
| 1997 | D2CXX = CXXRecordDecl::CreateLambda(Importer.getToContext(), |
| 1998 | DC, TInfo, Loc, |
| 1999 | DCXX->isDependentLambda(), |
| 2000 | DCXX->isGenericLambda(), |
| 2001 | DCXX->getLambdaCaptureDefault()); |
| 2002 | Decl *CDecl = Importer.Import(DCXX->getLambdaContextDecl()); |
| 2003 | if (DCXX->getLambdaContextDecl() && !CDecl) |
| 2004 | return nullptr; |
Sean Callanan | 041cceb | 2016-05-14 05:43:57 +0000 | [diff] [blame] | 2005 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), CDecl); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2006 | } else if (DCXX->isInjectedClassName()) { |
| 2007 | // We have to be careful to do a similar dance to the one in |
| 2008 | // Sema::ActOnStartCXXMemberDeclarations |
| 2009 | CXXRecordDecl *const PrevDecl = nullptr; |
| 2010 | const bool DelayTypeCreation = true; |
| 2011 | D2CXX = CXXRecordDecl::Create( |
| 2012 | Importer.getToContext(), D->getTagKind(), DC, StartLoc, Loc, |
| 2013 | Name.getAsIdentifierInfo(), PrevDecl, DelayTypeCreation); |
| 2014 | Importer.getToContext().getTypeDeclType( |
| 2015 | D2CXX, llvm::dyn_cast<CXXRecordDecl>(DC)); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2016 | } else { |
| 2017 | D2CXX = CXXRecordDecl::Create(Importer.getToContext(), |
| 2018 | D->getTagKind(), |
| 2019 | DC, StartLoc, Loc, |
| 2020 | Name.getAsIdentifierInfo()); |
| 2021 | } |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2022 | D2 = D2CXX; |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2023 | D2->setAccess(D->getAccess()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2024 | D2->setLexicalDeclContext(LexicalDC); |
| 2025 | if (!DCXX->getDescribedClassTemplate()) |
| 2026 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2027 | |
| 2028 | Importer.Imported(D, D2); |
| 2029 | |
| 2030 | if (ClassTemplateDecl *FromDescribed = |
| 2031 | DCXX->getDescribedClassTemplate()) { |
| 2032 | ClassTemplateDecl *ToDescribed = cast_or_null<ClassTemplateDecl>( |
| 2033 | Importer.Import(FromDescribed)); |
| 2034 | if (!ToDescribed) |
| 2035 | return nullptr; |
| 2036 | D2CXX->setDescribedClassTemplate(ToDescribed); |
| 2037 | |
| 2038 | } else if (MemberSpecializationInfo *MemberInfo = |
| 2039 | DCXX->getMemberSpecializationInfo()) { |
| 2040 | TemplateSpecializationKind SK = |
| 2041 | MemberInfo->getTemplateSpecializationKind(); |
| 2042 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
| 2043 | CXXRecordDecl *ToInst = |
| 2044 | cast_or_null<CXXRecordDecl>(Importer.Import(FromInst)); |
| 2045 | if (FromInst && !ToInst) |
| 2046 | return nullptr; |
| 2047 | D2CXX->setInstantiationOfMemberClass(ToInst, SK); |
| 2048 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2049 | Importer.Import(MemberInfo->getPointOfInstantiation())); |
| 2050 | } |
| 2051 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2052 | } else { |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2053 | D2 = RecordDecl::Create(Importer.getToContext(), D->getTagKind(), |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 2054 | DC, StartLoc, Loc, Name.getAsIdentifierInfo()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2055 | D2->setLexicalDeclContext(LexicalDC); |
| 2056 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2057 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2058 | |
| 2059 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2060 | if (D->isAnonymousStructOrUnion()) |
| 2061 | D2->setAnonymousStructOrUnion(true); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2062 | if (PrevDecl) { |
| 2063 | // FIXME: do this for all Redeclarables, not just RecordDecls. |
| 2064 | D2->setPreviousDecl(PrevDecl); |
| 2065 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2066 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2067 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2068 | Importer.Imported(D, D2); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2069 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 2070 | if (D->isCompleteDefinition() && ImportDefinition(D, D2, IDK_Default)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2071 | return nullptr; |
| 2072 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2073 | return D2; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2074 | } |
| 2075 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2076 | Decl *ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| 2077 | // Import the major distinguishing characteristics of this enumerator. |
| 2078 | DeclContext *DC, *LexicalDC; |
| 2079 | DeclarationName Name; |
| 2080 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2081 | NamedDecl *ToD; |
| 2082 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2083 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2084 | if (ToD) |
| 2085 | return ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2086 | |
| 2087 | QualType T = Importer.Import(D->getType()); |
| 2088 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2089 | return nullptr; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2090 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2091 | // Determine whether there are any other declarations with the same name and |
| 2092 | // in the same context. |
| 2093 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2094 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2095 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2096 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2097 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2098 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2099 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2100 | continue; |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2101 | |
| 2102 | if (EnumConstantDecl *FoundEnumConstant |
| 2103 | = dyn_cast<EnumConstantDecl>(FoundDecls[I])) { |
| 2104 | if (IsStructuralMatch(D, FoundEnumConstant)) |
| 2105 | return Importer.Imported(D, FoundEnumConstant); |
| 2106 | } |
| 2107 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2108 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | if (!ConflictingDecls.empty()) { |
| 2112 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2113 | ConflictingDecls.data(), |
| 2114 | ConflictingDecls.size()); |
| 2115 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2116 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2117 | } |
| 2118 | } |
| 2119 | |
| 2120 | Expr *Init = Importer.Import(D->getInitExpr()); |
| 2121 | if (D->getInitExpr() && !Init) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2122 | return nullptr; |
| 2123 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2124 | EnumConstantDecl *ToEnumerator |
| 2125 | = EnumConstantDecl::Create(Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
| 2126 | Name.getAsIdentifierInfo(), T, |
| 2127 | Init, D->getInitVal()); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2128 | ToEnumerator->setAccess(D->getAccess()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2129 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2130 | Importer.Imported(D, ToEnumerator); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2131 | LexicalDC->addDeclInternal(ToEnumerator); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2132 | return ToEnumerator; |
| 2133 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2134 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2135 | bool ASTNodeImporter::ImportTemplateInformation(FunctionDecl *FromFD, |
| 2136 | FunctionDecl *ToFD) { |
| 2137 | switch (FromFD->getTemplatedKind()) { |
| 2138 | case FunctionDecl::TK_NonTemplate: |
| 2139 | case FunctionDecl::TK_FunctionTemplate: |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2140 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2141 | |
| 2142 | case FunctionDecl::TK_MemberSpecialization: { |
| 2143 | auto *InstFD = cast_or_null<FunctionDecl>( |
| 2144 | Importer.Import(FromFD->getInstantiatedFromMemberFunction())); |
| 2145 | if (!InstFD) |
| 2146 | return true; |
| 2147 | |
| 2148 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
| 2149 | SourceLocation POI = Importer.Import( |
| 2150 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation()); |
| 2151 | ToFD->setInstantiationOfMemberFunction(InstFD, TSK); |
| 2152 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2153 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
| 2157 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
| 2158 | auto *Template = cast_or_null<FunctionTemplateDecl>( |
| 2159 | Importer.Import(FTSInfo->getTemplate())); |
| 2160 | if (!Template) |
| 2161 | return true; |
| 2162 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
| 2163 | |
| 2164 | // Import template arguments. |
| 2165 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); |
| 2166 | SmallVector<TemplateArgument, 8> ToTemplArgs; |
| 2167 | if (ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), |
| 2168 | ToTemplArgs)) |
| 2169 | return true; |
| 2170 | |
| 2171 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
| 2172 | Importer.getToContext(), ToTemplArgs); |
| 2173 | |
| 2174 | TemplateArgumentListInfo ToTAInfo; |
| 2175 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2176 | if (FromTAArgsAsWritten) |
| 2177 | if (ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2178 | return true; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2179 | |
| 2180 | SourceLocation POI = Importer.Import(FTSInfo->getPointOfInstantiation()); |
| 2181 | |
| 2182 | ToFD->setFunctionTemplateSpecialization( |
| 2183 | Template, ToTAList, /* InsertPos= */ nullptr, |
| 2184 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, POI); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2185 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2186 | } |
| 2187 | |
| 2188 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 2189 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 2190 | UnresolvedSet<8> TemplDecls; |
| 2191 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 2192 | for (unsigned I = 0; I < NumTemplates; I++) { |
| 2193 | if (auto *ToFTD = cast_or_null<FunctionTemplateDecl>( |
| 2194 | Importer.Import(FromInfo->getTemplate(I)))) |
| 2195 | TemplDecls.addDecl(ToFTD); |
| 2196 | else |
| 2197 | return true; |
| 2198 | } |
| 2199 | |
| 2200 | // Import TemplateArgumentListInfo. |
| 2201 | TemplateArgumentListInfo ToTAInfo; |
| 2202 | if (ImportTemplateArgumentListInfo( |
| 2203 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 2204 | llvm::makeArrayRef(FromInfo->getTemplateArgs(), |
| 2205 | FromInfo->getNumTemplateArgs()), |
| 2206 | ToTAInfo)) |
| 2207 | return true; |
| 2208 | |
| 2209 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 2210 | TemplDecls, ToTAInfo); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2211 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2212 | } |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2213 | } |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2214 | llvm_unreachable("All cases should be covered!"); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2215 | } |
| 2216 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2217 | Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
| 2218 | // Import the major distinguishing characteristics of this function. |
| 2219 | DeclContext *DC, *LexicalDC; |
| 2220 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2221 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2222 | NamedDecl *ToD; |
| 2223 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2224 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2225 | if (ToD) |
| 2226 | return ToD; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2227 | |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2228 | const FunctionDecl *FoundWithoutBody = nullptr; |
| 2229 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2230 | // Try to find a function in our own ("to") context with the same name, same |
| 2231 | // type, and in the same context as the function we're importing. |
| 2232 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2233 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2234 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2235 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2236 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2237 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2238 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2239 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2240 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2241 | if (FunctionDecl *FoundFunction = dyn_cast<FunctionDecl>(FoundDecls[I])) { |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 2242 | if (FoundFunction->hasExternalFormalLinkage() && |
| 2243 | D->hasExternalFormalLinkage()) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2244 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| 2245 | FoundFunction->getType())) { |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2246 | // FIXME: Actually try to merge the body and other attributes. |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2247 | const FunctionDecl *FromBodyDecl = nullptr; |
| 2248 | D->hasBody(FromBodyDecl); |
| 2249 | if (D == FromBodyDecl && !FoundFunction->hasBody()) { |
| 2250 | // This function is needed to merge completely. |
| 2251 | FoundWithoutBody = FoundFunction; |
| 2252 | break; |
| 2253 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2254 | return Importer.Imported(D, FoundFunction); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2255 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2256 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2257 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 2258 | // Sema::IsOverload out to the AST library. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2259 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2260 | // Function overloading is okay in C++. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2261 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2262 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2263 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2264 | // Complain about inconsistent function types. |
| 2265 | Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2266 | << Name << D->getType() << FoundFunction->getType(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2267 | Importer.ToDiag(FoundFunction->getLocation(), |
| 2268 | diag::note_odr_value_here) |
| 2269 | << FoundFunction->getType(); |
| 2270 | } |
| 2271 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2272 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2273 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2274 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2275 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2276 | if (!ConflictingDecls.empty()) { |
| 2277 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2278 | ConflictingDecls.data(), |
| 2279 | ConflictingDecls.size()); |
| 2280 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2281 | return nullptr; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2282 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2283 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2284 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2285 | DeclarationNameInfo NameInfo(Name, Loc); |
| 2286 | // Import additional name location/type info. |
| 2287 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 2288 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2289 | QualType FromTy = D->getType(); |
| 2290 | bool usedDifferentExceptionSpec = false; |
| 2291 | |
| 2292 | if (const FunctionProtoType * |
| 2293 | FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
| 2294 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 2295 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 2296 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 2297 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 2298 | // with a simplified function type and update it afterwards. |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 2299 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 2300 | FromEPI.ExceptionSpec.SourceTemplate || |
| 2301 | FromEPI.ExceptionSpec.NoexceptExpr) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2302 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 2303 | FromTy = Importer.getFromContext().getFunctionType( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2304 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2305 | usedDifferentExceptionSpec = true; |
| 2306 | } |
| 2307 | } |
| 2308 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2309 | // Import the type. |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2310 | QualType T = Importer.Import(FromTy); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2311 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2312 | return nullptr; |
| 2313 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2314 | // Import the function parameters. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2315 | SmallVector<ParmVarDecl *, 8> Parameters; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2316 | for (auto P : D->parameters()) { |
Aaron Ballman | f6bf62e | 2014-03-07 15:12:56 +0000 | [diff] [blame] | 2317 | ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(P)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2318 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2319 | return nullptr; |
| 2320 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2321 | Parameters.push_back(ToP); |
| 2322 | } |
| 2323 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2324 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2325 | if (D->getTypeSourceInfo() && !TInfo) |
| 2326 | return nullptr; |
| 2327 | |
| 2328 | // Create the imported function. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2329 | FunctionDecl *ToFunction = nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2330 | SourceLocation InnerLocStart = Importer.Import(D->getInnerLocStart()); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2331 | if (CXXConstructorDecl *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| 2332 | ToFunction = CXXConstructorDecl::Create(Importer.getToContext(), |
| 2333 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2334 | InnerLocStart, |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2335 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2336 | FromConstructor->isExplicit(), |
| 2337 | D->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2338 | D->isImplicit(), |
| 2339 | D->isConstexpr()); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2340 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 2341 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers; |
| 2342 | for (CXXCtorInitializer *I : FromConstructor->inits()) { |
| 2343 | CXXCtorInitializer *ToI = |
| 2344 | cast_or_null<CXXCtorInitializer>(Importer.Import(I)); |
| 2345 | if (!ToI && I) |
| 2346 | return nullptr; |
| 2347 | CtorInitializers.push_back(ToI); |
| 2348 | } |
| 2349 | CXXCtorInitializer **Memory = |
| 2350 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 2351 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
| 2352 | CXXConstructorDecl *ToCtor = llvm::cast<CXXConstructorDecl>(ToFunction); |
| 2353 | ToCtor->setCtorInitializers(Memory); |
| 2354 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 2355 | } |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2356 | } else if (isa<CXXDestructorDecl>(D)) { |
| 2357 | ToFunction = CXXDestructorDecl::Create(Importer.getToContext(), |
| 2358 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2359 | InnerLocStart, |
Craig Silverstein | af8808d | 2010-10-21 00:44:50 +0000 | [diff] [blame] | 2360 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2361 | D->isInlineSpecified(), |
| 2362 | D->isImplicit()); |
| 2363 | } else if (CXXConversionDecl *FromConversion |
| 2364 | = dyn_cast<CXXConversionDecl>(D)) { |
| 2365 | ToFunction = CXXConversionDecl::Create(Importer.getToContext(), |
| 2366 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2367 | InnerLocStart, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2368 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2369 | D->isInlineSpecified(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2370 | FromConversion->isExplicit(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2371 | D->isConstexpr(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2372 | Importer.Import(D->getLocEnd())); |
Douglas Gregor | a50ad13 | 2010-11-29 16:04:58 +0000 | [diff] [blame] | 2373 | } else if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { |
| 2374 | ToFunction = CXXMethodDecl::Create(Importer.getToContext(), |
| 2375 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2376 | InnerLocStart, |
Douglas Gregor | a50ad13 | 2010-11-29 16:04:58 +0000 | [diff] [blame] | 2377 | NameInfo, T, TInfo, |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 2378 | Method->getStorageClass(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2379 | Method->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2380 | D->isConstexpr(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2381 | Importer.Import(D->getLocEnd())); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2382 | } else { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2383 | ToFunction = FunctionDecl::Create(Importer.getToContext(), DC, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2384 | InnerLocStart, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2385 | NameInfo, T, TInfo, D->getStorageClass(), |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2386 | D->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2387 | D->hasWrittenPrototype(), |
| 2388 | D->isConstexpr()); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2389 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 2390 | |
| 2391 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2392 | ToFunction->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2393 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2394 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 2395 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 2396 | ToFunction->setTrivial(D->isTrivial()); |
| 2397 | ToFunction->setPure(D->isPure()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2398 | Importer.Imported(D, ToFunction); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2399 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2400 | // Set the parameters. |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2401 | for (ParmVarDecl *Param : Parameters) { |
| 2402 | Param->setOwningFunction(ToFunction); |
| 2403 | ToFunction->addDeclInternal(Param); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2404 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 2405 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2406 | |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2407 | if (FoundWithoutBody) { |
| 2408 | auto *Recent = const_cast<FunctionDecl *>( |
| 2409 | FoundWithoutBody->getMostRecentDecl()); |
| 2410 | ToFunction->setPreviousDecl(Recent); |
| 2411 | } |
| 2412 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2413 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 2414 | // params it refers to. |
| 2415 | if (TInfo) { |
| 2416 | if (auto ProtoLoc = |
| 2417 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 2418 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 2419 | ProtoLoc.setParam(I, Parameters[I]); |
| 2420 | } |
| 2421 | } |
| 2422 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2423 | if (usedDifferentExceptionSpec) { |
| 2424 | // Update FunctionProtoType::ExtProtoInfo. |
| 2425 | QualType T = Importer.Import(D->getType()); |
| 2426 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2427 | return nullptr; |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2428 | ToFunction->setType(T); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 2429 | } |
| 2430 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2431 | // Import the body, if any. |
| 2432 | if (Stmt *FromBody = D->getBody()) { |
| 2433 | if (Stmt *ToBody = Importer.Import(FromBody)) { |
| 2434 | ToFunction->setBody(ToBody); |
| 2435 | } |
| 2436 | } |
| 2437 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2438 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2439 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2440 | // If it is a template, import all related things. |
| 2441 | if (ImportTemplateInformation(D, ToFunction)) |
| 2442 | return nullptr; |
| 2443 | |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2444 | // Add this function to the lexical context. |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2445 | // NOTE: If the function is templated declaration, it should be not added into |
| 2446 | // LexicalDC. But described template is imported during import of |
| 2447 | // FunctionTemplateDecl (it happens later). So, we use source declaration |
| 2448 | // to determine if we should add the result function. |
| 2449 | if (!D->getDescribedFunctionTemplate()) |
| 2450 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2451 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 2452 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 2453 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 2454 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2455 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2456 | } |
| 2457 | |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2458 | Decl *ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| 2459 | return VisitFunctionDecl(D); |
| 2460 | } |
| 2461 | |
| 2462 | Decl *ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| 2463 | return VisitCXXMethodDecl(D); |
| 2464 | } |
| 2465 | |
| 2466 | Decl *ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| 2467 | return VisitCXXMethodDecl(D); |
| 2468 | } |
| 2469 | |
| 2470 | Decl *ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| 2471 | return VisitCXXMethodDecl(D); |
| 2472 | } |
| 2473 | |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2474 | static unsigned getFieldIndex(Decl *F) { |
| 2475 | RecordDecl *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
| 2476 | if (!Owner) |
| 2477 | return 0; |
| 2478 | |
| 2479 | unsigned Index = 1; |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2480 | for (const auto *D : Owner->noload_decls()) { |
| 2481 | if (D == F) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2482 | return Index; |
| 2483 | |
| 2484 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 2485 | ++Index; |
| 2486 | } |
| 2487 | |
| 2488 | return Index; |
| 2489 | } |
| 2490 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2491 | Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
| 2492 | // Import the major distinguishing characteristics of a variable. |
| 2493 | DeclContext *DC, *LexicalDC; |
| 2494 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2495 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2496 | NamedDecl *ToD; |
| 2497 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2498 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2499 | if (ToD) |
| 2500 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2501 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2502 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2503 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2504 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2505 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2506 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2507 | // For anonymous fields, match up by index. |
| 2508 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2509 | continue; |
| 2510 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2511 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2512 | FoundField->getType())) { |
| 2513 | Importer.Imported(D, FoundField); |
| 2514 | return FoundField; |
| 2515 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2516 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2517 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2518 | << Name << D->getType() << FoundField->getType(); |
| 2519 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2520 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2521 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2522 | } |
| 2523 | } |
| 2524 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 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 | 5c73e91 | 2010-02-11 00:48:18 +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 | |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2535 | FieldDecl *ToField = FieldDecl::Create(Importer.getToContext(), DC, |
| 2536 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2537 | Loc, Name.getAsIdentifierInfo(), |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2538 | T, TInfo, BitWidth, D->isMutable(), |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2539 | D->getInClassInitStyle()); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2540 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2541 | ToField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 3a83ea7 | 2016-03-03 02:22:05 +0000 | [diff] [blame] | 2542 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
Sean Callanan | bb33f58 | 2016-03-03 01:21:28 +0000 | [diff] [blame] | 2543 | Expr *ToInitializer = Importer.Import(FromInitializer); |
| 2544 | if (ToInitializer) |
| 2545 | ToField->setInClassInitializer(ToInitializer); |
| 2546 | else |
| 2547 | return nullptr; |
| 2548 | } |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2549 | ToField->setImplicit(D->isImplicit()); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2550 | Importer.Imported(D, ToField); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2551 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2552 | return ToField; |
| 2553 | } |
| 2554 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2555 | Decl *ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| 2556 | // Import the major distinguishing characteristics of a variable. |
| 2557 | DeclContext *DC, *LexicalDC; |
| 2558 | DeclarationName Name; |
| 2559 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2560 | NamedDecl *ToD; |
| 2561 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2562 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2563 | if (ToD) |
| 2564 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2565 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2566 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2567 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2568 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2569 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2570 | if (IndirectFieldDecl *FoundField |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2571 | = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2572 | // For anonymous indirect fields, match up by index. |
| 2573 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2574 | continue; |
| 2575 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2576 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2577 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 2578 | !Name.isEmpty())) { |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2579 | Importer.Imported(D, FoundField); |
| 2580 | return FoundField; |
| 2581 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2582 | |
| 2583 | // If there are more anonymous fields to check, continue. |
| 2584 | if (!Name && I < N-1) |
| 2585 | continue; |
| 2586 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2587 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2588 | << Name << D->getType() << FoundField->getType(); |
| 2589 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2590 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2591 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2592 | } |
| 2593 | } |
| 2594 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2595 | // Import the type. |
| 2596 | QualType T = Importer.Import(D->getType()); |
| 2597 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2598 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2599 | |
| 2600 | NamedDecl **NamedChain = |
| 2601 | new (Importer.getToContext())NamedDecl*[D->getChainingSize()]; |
| 2602 | |
| 2603 | unsigned i = 0; |
Aaron Ballman | 29c9460 | 2014-03-07 18:36:15 +0000 | [diff] [blame] | 2604 | for (auto *PI : D->chain()) { |
Aaron Ballman | 1391608 | 2014-03-07 18:11:58 +0000 | [diff] [blame] | 2605 | Decl *D = Importer.Import(PI); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2606 | if (!D) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2607 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2608 | NamedChain[i++] = cast<NamedDecl>(D); |
| 2609 | } |
| 2610 | |
| 2611 | IndirectFieldDecl *ToIndirectField = IndirectFieldDecl::Create( |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2612 | Importer.getToContext(), DC, Loc, Name.getAsIdentifierInfo(), T, |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2613 | {NamedChain, D->getChainingSize()}); |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2614 | |
| 2615 | for (const auto *Attr : D->attrs()) |
| 2616 | ToIndirectField->addAttr(Attr->clone(Importer.getToContext())); |
| 2617 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2618 | ToIndirectField->setAccess(D->getAccess()); |
| 2619 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
| 2620 | Importer.Imported(D, ToIndirectField); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2621 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2622 | return ToIndirectField; |
| 2623 | } |
| 2624 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2625 | Decl *ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
| 2626 | // Import the major distinguishing characteristics of a declaration. |
| 2627 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 2628 | DeclContext *LexicalDC = D->getDeclContext() == D->getLexicalDeclContext() |
| 2629 | ? DC : Importer.ImportContext(D->getLexicalDeclContext()); |
| 2630 | if (!DC || !LexicalDC) |
| 2631 | return nullptr; |
| 2632 | |
| 2633 | // Determine whether we've already imported this decl. |
| 2634 | // FriendDecl is not a NamedDecl so we cannot use localUncachedLookup. |
| 2635 | auto *RD = cast<CXXRecordDecl>(DC); |
| 2636 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
| 2637 | StructuralEquivalenceContext Context( |
| 2638 | Importer.getFromContext(), Importer.getToContext(), |
| 2639 | Importer.getNonEquivalentDecls(), false, false); |
| 2640 | |
| 2641 | while (ImportedFriend) { |
| 2642 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
| 2643 | if (Context.IsStructurallyEquivalent(D->getFriendDecl(), |
| 2644 | ImportedFriend->getFriendDecl())) |
| 2645 | return Importer.Imported(D, ImportedFriend); |
| 2646 | |
| 2647 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 2648 | if (Importer.IsStructurallyEquivalent( |
| 2649 | D->getFriendType()->getType(), |
| 2650 | ImportedFriend->getFriendType()->getType(), true)) |
| 2651 | return Importer.Imported(D, ImportedFriend); |
| 2652 | } |
| 2653 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 2654 | } |
| 2655 | |
| 2656 | // Not found. Create it. |
| 2657 | FriendDecl::FriendUnion ToFU; |
| 2658 | if (NamedDecl *FriendD = D->getFriendDecl()) |
| 2659 | ToFU = cast_or_null<NamedDecl>(Importer.Import(FriendD)); |
| 2660 | else |
| 2661 | ToFU = Importer.Import(D->getFriendType()); |
| 2662 | if (!ToFU) |
| 2663 | return nullptr; |
| 2664 | |
| 2665 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
| 2666 | TemplateParameterList **FromTPLists = |
| 2667 | D->getTrailingObjects<TemplateParameterList *>(); |
| 2668 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
| 2669 | TemplateParameterList *List = ImportTemplateParameterList(FromTPLists[I]); |
| 2670 | if (!List) |
| 2671 | return nullptr; |
| 2672 | ToTPLists[I] = List; |
| 2673 | } |
| 2674 | |
| 2675 | FriendDecl *FrD = FriendDecl::Create(Importer.getToContext(), DC, |
| 2676 | Importer.Import(D->getLocation()), |
| 2677 | ToFU, Importer.Import(D->getFriendLoc()), |
| 2678 | ToTPLists); |
| 2679 | |
| 2680 | Importer.Imported(D, FrD); |
| 2681 | RD->pushFriendDecl(FrD); |
| 2682 | |
| 2683 | FrD->setAccess(D->getAccess()); |
| 2684 | FrD->setLexicalDeclContext(LexicalDC); |
| 2685 | LexicalDC->addDeclInternal(FrD); |
| 2686 | return FrD; |
| 2687 | } |
| 2688 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2689 | Decl *ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| 2690 | // Import the major distinguishing characteristics of an ivar. |
| 2691 | DeclContext *DC, *LexicalDC; |
| 2692 | DeclarationName Name; |
| 2693 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2694 | NamedDecl *ToD; |
| 2695 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2696 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2697 | if (ToD) |
| 2698 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2699 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2700 | // Determine whether we've already imported this ivar |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2701 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2702 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2703 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2704 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecls[I])) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2705 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2706 | FoundIvar->getType())) { |
| 2707 | Importer.Imported(D, FoundIvar); |
| 2708 | return FoundIvar; |
| 2709 | } |
| 2710 | |
| 2711 | Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent) |
| 2712 | << Name << D->getType() << FoundIvar->getType(); |
| 2713 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 2714 | << FoundIvar->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2715 | return nullptr; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2716 | } |
| 2717 | } |
| 2718 | |
| 2719 | // Import the type. |
| 2720 | QualType T = Importer.Import(D->getType()); |
| 2721 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2722 | return nullptr; |
| 2723 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2724 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2725 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 2726 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2727 | return nullptr; |
| 2728 | |
Daniel Dunbar | fe3ead7 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 2729 | ObjCIvarDecl *ToIvar = ObjCIvarDecl::Create(Importer.getToContext(), |
| 2730 | cast<ObjCContainerDecl>(DC), |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2731 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2732 | Loc, Name.getAsIdentifierInfo(), |
| 2733 | T, TInfo, D->getAccessControl(), |
Argyrios Kyrtzidis | 2080d90 | 2014-01-03 18:32:18 +0000 | [diff] [blame] | 2734 | BitWidth, D->getSynthesize()); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2735 | ToIvar->setLexicalDeclContext(LexicalDC); |
| 2736 | Importer.Imported(D, ToIvar); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2737 | LexicalDC->addDeclInternal(ToIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2738 | return ToIvar; |
| 2739 | |
| 2740 | } |
| 2741 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2742 | Decl *ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
| 2743 | // Import the major distinguishing characteristics of a variable. |
| 2744 | DeclContext *DC, *LexicalDC; |
| 2745 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2746 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2747 | NamedDecl *ToD; |
| 2748 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2749 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2750 | if (ToD) |
| 2751 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2752 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2753 | // Try to find a variable in our own ("to") context with the same name and |
| 2754 | // in the same context as the variable we're importing. |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2755 | if (D->isFileVarDecl()) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2756 | VarDecl *MergeWithVar = nullptr; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2757 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2758 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2759 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2760 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2761 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2762 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2763 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2764 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2765 | if (VarDecl *FoundVar = dyn_cast<VarDecl>(FoundDecls[I])) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2766 | // 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] | 2767 | if (FoundVar->hasExternalFormalLinkage() && |
| 2768 | D->hasExternalFormalLinkage()) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2769 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2770 | FoundVar->getType())) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2771 | MergeWithVar = FoundVar; |
| 2772 | break; |
| 2773 | } |
| 2774 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2775 | const ArrayType *FoundArray |
| 2776 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 2777 | const ArrayType *TArray |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2778 | = Importer.getToContext().getAsArrayType(D->getType()); |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2779 | if (FoundArray && TArray) { |
| 2780 | if (isa<IncompleteArrayType>(FoundArray) && |
| 2781 | isa<ConstantArrayType>(TArray)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2782 | // Import the type. |
| 2783 | QualType T = Importer.Import(D->getType()); |
| 2784 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2785 | return nullptr; |
| 2786 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2787 | FoundVar->setType(T); |
| 2788 | MergeWithVar = FoundVar; |
| 2789 | break; |
| 2790 | } else if (isa<IncompleteArrayType>(TArray) && |
| 2791 | isa<ConstantArrayType>(FoundArray)) { |
| 2792 | MergeWithVar = FoundVar; |
| 2793 | break; |
Douglas Gregor | 2fbe558 | 2010-02-10 17:16:49 +0000 | [diff] [blame] | 2794 | } |
| 2795 | } |
| 2796 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2797 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2798 | << Name << D->getType() << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2799 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 2800 | << FoundVar->getType(); |
| 2801 | } |
| 2802 | } |
| 2803 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2804 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2805 | } |
| 2806 | |
| 2807 | if (MergeWithVar) { |
| 2808 | // An equivalent variable with external linkage has been found. Link |
| 2809 | // the two declarations, then merge them. |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2810 | Importer.Imported(D, MergeWithVar); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2811 | |
| 2812 | if (VarDecl *DDef = D->getDefinition()) { |
| 2813 | if (VarDecl *ExistingDef = MergeWithVar->getDefinition()) { |
| 2814 | Importer.ToDiag(ExistingDef->getLocation(), |
| 2815 | diag::err_odr_variable_multiple_def) |
| 2816 | << Name; |
| 2817 | Importer.FromDiag(DDef->getLocation(), diag::note_odr_defined_here); |
| 2818 | } else { |
| 2819 | Expr *Init = Importer.Import(DDef->getInit()); |
Douglas Gregor | d505812 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 2820 | MergeWithVar->setInit(Init); |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 2821 | if (DDef->isInitKnownICE()) { |
| 2822 | EvaluatedStmt *Eval = MergeWithVar->ensureEvaluatedStmt(); |
| 2823 | Eval->CheckedICE = true; |
| 2824 | Eval->IsICE = DDef->isInitICE(); |
| 2825 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2826 | } |
| 2827 | } |
| 2828 | |
| 2829 | return MergeWithVar; |
| 2830 | } |
| 2831 | |
| 2832 | if (!ConflictingDecls.empty()) { |
| 2833 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2834 | ConflictingDecls.data(), |
| 2835 | ConflictingDecls.size()); |
| 2836 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2837 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2838 | } |
| 2839 | } |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2840 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2841 | // Import the type. |
| 2842 | QualType T = Importer.Import(D->getType()); |
| 2843 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2844 | return nullptr; |
| 2845 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2846 | // Create the imported variable. |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2847 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2848 | VarDecl *ToVar = VarDecl::Create(Importer.getToContext(), DC, |
| 2849 | Importer.Import(D->getInnerLocStart()), |
| 2850 | Loc, Name.getAsIdentifierInfo(), |
| 2851 | T, TInfo, |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 2852 | D->getStorageClass()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2853 | ToVar->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2854 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2855 | ToVar->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2856 | Importer.Imported(D, ToVar); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2857 | |
| 2858 | // Templated declarations should never appear in the enclosing DeclContext. |
| 2859 | if (!D->getDescribedVarTemplate()) |
| 2860 | LexicalDC->addDeclInternal(ToVar); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2861 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2862 | if (!D->isFileVarDecl() && |
| 2863 | D->isUsed()) |
| 2864 | ToVar->setIsUsed(); |
| 2865 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2866 | // Merge the initializer. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2867 | if (ImportDefinition(D, ToVar)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2868 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2869 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 2870 | if (D->isConstexpr()) |
| 2871 | ToVar->setConstexpr(true); |
| 2872 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2873 | return ToVar; |
| 2874 | } |
| 2875 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2876 | Decl *ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| 2877 | // Parameters are created in the translation unit's context, then moved |
| 2878 | // into the function declaration's context afterward. |
| 2879 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| 2880 | |
| 2881 | // Import the name of this declaration. |
| 2882 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 2883 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2884 | return nullptr; |
| 2885 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2886 | // Import the location of this declaration. |
| 2887 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 2888 | |
| 2889 | // Import the parameter's type. |
| 2890 | QualType T = Importer.Import(D->getType()); |
| 2891 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2892 | return nullptr; |
| 2893 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2894 | // Create the imported parameter. |
Alexey Bataev | 5622323 | 2017-06-09 13:40:18 +0000 | [diff] [blame] | 2895 | auto *ToParm = ImplicitParamDecl::Create(Importer.getToContext(), DC, Loc, |
| 2896 | Name.getAsIdentifierInfo(), T, |
| 2897 | D->getParameterKind()); |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2898 | return Importer.Imported(D, ToParm); |
| 2899 | } |
| 2900 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2901 | Decl *ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
| 2902 | // Parameters are created in the translation unit's context, then moved |
| 2903 | // into the function declaration's context afterward. |
| 2904 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| 2905 | |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2906 | // Import the name of this declaration. |
| 2907 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 2908 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2909 | return nullptr; |
| 2910 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2911 | // Import the location of this declaration. |
| 2912 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 2913 | |
| 2914 | // Import the parameter's type. |
| 2915 | QualType T = Importer.Import(D->getType()); |
| 2916 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2917 | return nullptr; |
| 2918 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2919 | // Create the imported parameter. |
| 2920 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2921 | ParmVarDecl *ToParm = ParmVarDecl::Create(Importer.getToContext(), DC, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2922 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2923 | Loc, Name.getAsIdentifierInfo(), |
| 2924 | T, TInfo, D->getStorageClass(), |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 2925 | /*DefaultArg*/ nullptr); |
| 2926 | |
| 2927 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 2928 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 2929 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 2930 | |
| 2931 | Expr *ToDefArg = nullptr; |
| 2932 | Expr *FromDefArg = nullptr; |
| 2933 | if (D->hasUninstantiatedDefaultArg()) { |
| 2934 | FromDefArg = D->getUninstantiatedDefaultArg(); |
| 2935 | ToDefArg = Importer.Import(FromDefArg); |
| 2936 | ToParm->setUninstantiatedDefaultArg(ToDefArg); |
| 2937 | } else if (D->hasUnparsedDefaultArg()) { |
| 2938 | ToParm->setUnparsedDefaultArg(); |
| 2939 | } else if (D->hasDefaultArg()) { |
| 2940 | FromDefArg = D->getDefaultArg(); |
| 2941 | ToDefArg = Importer.Import(FromDefArg); |
| 2942 | ToParm->setDefaultArg(ToDefArg); |
| 2943 | } |
| 2944 | if (FromDefArg && !ToDefArg) |
| 2945 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2946 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2947 | if (D->isObjCMethodParameter()) { |
| 2948 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 2949 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 2950 | } else { |
| 2951 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 2952 | D->getFunctionScopeIndex()); |
| 2953 | } |
| 2954 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2955 | if (D->isUsed()) |
| 2956 | ToParm->setIsUsed(); |
| 2957 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2958 | return Importer.Imported(D, ToParm); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2959 | } |
| 2960 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2961 | Decl *ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| 2962 | // Import the major distinguishing characteristics of a method. |
| 2963 | DeclContext *DC, *LexicalDC; |
| 2964 | DeclarationName Name; |
| 2965 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2966 | NamedDecl *ToD; |
| 2967 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2968 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2969 | if (ToD) |
| 2970 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2971 | |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2972 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2973 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2974 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2975 | if (ObjCMethodDecl *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecls[I])) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2976 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 2977 | continue; |
| 2978 | |
| 2979 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2980 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 2981 | FoundMethod->getReturnType())) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2982 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2983 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 2984 | << FoundMethod->getReturnType(); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2985 | Importer.ToDiag(FoundMethod->getLocation(), |
| 2986 | diag::note_odr_objc_method_here) |
| 2987 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2988 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2989 | } |
| 2990 | |
| 2991 | // Check the number of parameters. |
| 2992 | if (D->param_size() != FoundMethod->param_size()) { |
| 2993 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) |
| 2994 | << D->isInstanceMethod() << Name |
| 2995 | << D->param_size() << FoundMethod->param_size(); |
| 2996 | Importer.ToDiag(FoundMethod->getLocation(), |
| 2997 | diag::note_odr_objc_method_here) |
| 2998 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2999 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3000 | } |
| 3001 | |
| 3002 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3003 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3004 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 3005 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3006 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3007 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3008 | Importer.FromDiag((*P)->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3009 | diag::err_odr_objc_method_param_type_inconsistent) |
| 3010 | << D->isInstanceMethod() << Name |
| 3011 | << (*P)->getType() << (*FoundP)->getType(); |
| 3012 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 3013 | << (*FoundP)->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3014 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3015 | } |
| 3016 | } |
| 3017 | |
| 3018 | // Check variadic/non-variadic. |
| 3019 | // Check the number of parameters. |
| 3020 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| 3021 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) |
| 3022 | << D->isInstanceMethod() << Name; |
| 3023 | Importer.ToDiag(FoundMethod->getLocation(), |
| 3024 | diag::note_odr_objc_method_here) |
| 3025 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3026 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3027 | } |
| 3028 | |
| 3029 | // FIXME: Any other bits we need to merge? |
| 3030 | return Importer.Imported(D, FoundMethod); |
| 3031 | } |
| 3032 | } |
| 3033 | |
| 3034 | // Import the result type. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3035 | QualType ResultTy = Importer.Import(D->getReturnType()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3036 | if (ResultTy.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3037 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3038 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3039 | TypeSourceInfo *ReturnTInfo = Importer.Import(D->getReturnTypeSourceInfo()); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3040 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3041 | ObjCMethodDecl *ToMethod = ObjCMethodDecl::Create( |
| 3042 | Importer.getToContext(), Loc, Importer.Import(D->getLocEnd()), |
| 3043 | Name.getObjCSelector(), ResultTy, ReturnTInfo, DC, D->isInstanceMethod(), |
| 3044 | D->isVariadic(), D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 3045 | D->getImplementationControl(), D->hasRelatedResultType()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3046 | |
| 3047 | // FIXME: When we decide to merge method definitions, we'll need to |
| 3048 | // deal with implicit parameters. |
| 3049 | |
| 3050 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3051 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3052 | for (auto *FromP : D->parameters()) { |
Aaron Ballman | 43b68be | 2014-03-07 17:50:17 +0000 | [diff] [blame] | 3053 | ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(FromP)); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3054 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3055 | return nullptr; |
| 3056 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3057 | ToParams.push_back(ToP); |
| 3058 | } |
| 3059 | |
| 3060 | // Set the parameters. |
| 3061 | for (unsigned I = 0, N = ToParams.size(); I != N; ++I) { |
| 3062 | ToParams[I]->setOwningFunction(ToMethod); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3063 | ToMethod->addDeclInternal(ToParams[I]); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3064 | } |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3065 | |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 3066 | SmallVector<SourceLocation, 12> SelLocs; |
| 3067 | D->getSelectorLocs(SelLocs); |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3068 | for (SourceLocation &Loc : SelLocs) |
| 3069 | Loc = Importer.Import(Loc); |
| 3070 | |
| 3071 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, SelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3072 | |
| 3073 | ToMethod->setLexicalDeclContext(LexicalDC); |
| 3074 | Importer.Imported(D, ToMethod); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3075 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3076 | return ToMethod; |
| 3077 | } |
| 3078 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3079 | Decl *ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| 3080 | // Import the major distinguishing characteristics of a category. |
| 3081 | DeclContext *DC, *LexicalDC; |
| 3082 | DeclarationName Name; |
| 3083 | SourceLocation Loc; |
| 3084 | NamedDecl *ToD; |
| 3085 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3086 | return nullptr; |
| 3087 | if (ToD) |
| 3088 | return ToD; |
| 3089 | |
| 3090 | TypeSourceInfo *BoundInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3091 | if (!BoundInfo) |
| 3092 | return nullptr; |
| 3093 | |
| 3094 | ObjCTypeParamDecl *Result = ObjCTypeParamDecl::Create( |
| 3095 | Importer.getToContext(), DC, |
Douglas Gregor | 1ac1b63 | 2015-07-07 03:58:54 +0000 | [diff] [blame] | 3096 | D->getVariance(), |
| 3097 | Importer.Import(D->getVarianceLoc()), |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 3098 | D->getIndex(), |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3099 | Importer.Import(D->getLocation()), |
| 3100 | Name.getAsIdentifierInfo(), |
| 3101 | Importer.Import(D->getColonLoc()), |
| 3102 | BoundInfo); |
| 3103 | Importer.Imported(D, Result); |
| 3104 | Result->setLexicalDeclContext(LexicalDC); |
| 3105 | return Result; |
| 3106 | } |
| 3107 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3108 | Decl *ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| 3109 | // Import the major distinguishing characteristics of a category. |
| 3110 | DeclContext *DC, *LexicalDC; |
| 3111 | DeclarationName Name; |
| 3112 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3113 | NamedDecl *ToD; |
| 3114 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3115 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3116 | if (ToD) |
| 3117 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3118 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3119 | ObjCInterfaceDecl *ToInterface |
| 3120 | = cast_or_null<ObjCInterfaceDecl>(Importer.Import(D->getClassInterface())); |
| 3121 | if (!ToInterface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3122 | return nullptr; |
| 3123 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3124 | // Determine if we've already encountered this category. |
| 3125 | ObjCCategoryDecl *MergeWithCategory |
| 3126 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 3127 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 3128 | if (!ToCategory) { |
| 3129 | ToCategory = ObjCCategoryDecl::Create(Importer.getToContext(), DC, |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3130 | Importer.Import(D->getAtStartLoc()), |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3131 | Loc, |
| 3132 | Importer.Import(D->getCategoryNameLoc()), |
Argyrios Kyrtzidis | 3a5094b | 2011-08-30 19:43:26 +0000 | [diff] [blame] | 3133 | Name.getAsIdentifierInfo(), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3134 | ToInterface, |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3135 | /*TypeParamList=*/nullptr, |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3136 | Importer.Import(D->getIvarLBraceLoc()), |
| 3137 | Importer.Import(D->getIvarRBraceLoc())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3138 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3139 | LexicalDC->addDeclInternal(ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3140 | Importer.Imported(D, ToCategory); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3141 | // Import the type parameter list after calling Imported, to avoid |
| 3142 | // loops when bringing in their DeclContext. |
| 3143 | ToCategory->setTypeParamList(ImportObjCTypeParamList( |
| 3144 | D->getTypeParamList())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3145 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3146 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3147 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3148 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3149 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 3150 | = D->protocol_loc_begin(); |
| 3151 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 3152 | FromProtoEnd = D->protocol_end(); |
| 3153 | FromProto != FromProtoEnd; |
| 3154 | ++FromProto, ++FromProtoLoc) { |
| 3155 | ObjCProtocolDecl *ToProto |
| 3156 | = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
| 3157 | if (!ToProto) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3158 | return nullptr; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3159 | Protocols.push_back(ToProto); |
| 3160 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3161 | } |
| 3162 | |
| 3163 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3164 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 3165 | ProtocolLocs.data(), Importer.getToContext()); |
| 3166 | |
| 3167 | } else { |
| 3168 | Importer.Imported(D, ToCategory); |
| 3169 | } |
| 3170 | |
| 3171 | // Import all of the members of this category. |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 3172 | ImportDeclContext(D); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3173 | |
| 3174 | // If we have an implementation, import it as well. |
| 3175 | if (D->getImplementation()) { |
| 3176 | ObjCCategoryImplDecl *Impl |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 3177 | = cast_or_null<ObjCCategoryImplDecl>( |
| 3178 | Importer.Import(D->getImplementation())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3179 | if (!Impl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3180 | return nullptr; |
| 3181 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3182 | ToCategory->setImplementation(Impl); |
| 3183 | } |
| 3184 | |
| 3185 | return ToCategory; |
| 3186 | } |
| 3187 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3188 | bool ASTNodeImporter::ImportDefinition(ObjCProtocolDecl *From, |
| 3189 | ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3190 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3191 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3192 | if (shouldForceImportDeclContext(Kind)) |
| 3193 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3194 | return false; |
| 3195 | } |
| 3196 | |
| 3197 | // Start the protocol definition |
| 3198 | To->startDefinition(); |
| 3199 | |
| 3200 | // Import protocols |
| 3201 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3202 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| 3203 | ObjCProtocolDecl::protocol_loc_iterator |
| 3204 | FromProtoLoc = From->protocol_loc_begin(); |
| 3205 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3206 | FromProtoEnd = From->protocol_end(); |
| 3207 | FromProto != FromProtoEnd; |
| 3208 | ++FromProto, ++FromProtoLoc) { |
| 3209 | ObjCProtocolDecl *ToProto |
| 3210 | = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
| 3211 | if (!ToProto) |
| 3212 | return true; |
| 3213 | Protocols.push_back(ToProto); |
| 3214 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3215 | } |
| 3216 | |
| 3217 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3218 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 3219 | ProtocolLocs.data(), Importer.getToContext()); |
| 3220 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3221 | if (shouldForceImportDeclContext(Kind)) { |
| 3222 | // Import all of the members of this protocol. |
| 3223 | ImportDeclContext(From, /*ForceImport=*/true); |
| 3224 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3225 | return false; |
| 3226 | } |
| 3227 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3228 | Decl *ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3229 | // If this protocol has a definition in the translation unit we're coming |
| 3230 | // from, but this particular declaration is not that definition, import the |
| 3231 | // definition and map to that. |
| 3232 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 3233 | if (Definition && Definition != D) { |
| 3234 | Decl *ImportedDef = Importer.Import(Definition); |
| 3235 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3236 | return nullptr; |
| 3237 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3238 | return Importer.Imported(D, ImportedDef); |
| 3239 | } |
| 3240 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3241 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3242 | DeclContext *DC, *LexicalDC; |
| 3243 | DeclarationName Name; |
| 3244 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3245 | NamedDecl *ToD; |
| 3246 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3247 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3248 | if (ToD) |
| 3249 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3250 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3251 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3252 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3253 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3254 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 3255 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3256 | continue; |
| 3257 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3258 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecls[I]))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3259 | break; |
| 3260 | } |
| 3261 | |
| 3262 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3263 | if (!ToProto) { |
| 3264 | ToProto = ObjCProtocolDecl::Create(Importer.getToContext(), DC, |
| 3265 | Name.getAsIdentifierInfo(), Loc, |
| 3266 | Importer.Import(D->getAtStartLoc()), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3267 | /*PrevDecl=*/nullptr); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3268 | ToProto->setLexicalDeclContext(LexicalDC); |
| 3269 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3270 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3271 | |
| 3272 | Importer.Imported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3273 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3274 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToProto)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3275 | return nullptr; |
| 3276 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3277 | return ToProto; |
| 3278 | } |
| 3279 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3280 | Decl *ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 3281 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3282 | DeclContext *LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3283 | |
| 3284 | SourceLocation ExternLoc = Importer.Import(D->getExternLoc()); |
| 3285 | SourceLocation LangLoc = Importer.Import(D->getLocation()); |
| 3286 | |
| 3287 | bool HasBraces = D->hasBraces(); |
| 3288 | |
Sean Callanan | b12a855 | 2014-12-10 21:22:20 +0000 | [diff] [blame] | 3289 | LinkageSpecDecl *ToLinkageSpec = |
| 3290 | LinkageSpecDecl::Create(Importer.getToContext(), |
| 3291 | DC, |
| 3292 | ExternLoc, |
| 3293 | LangLoc, |
| 3294 | D->getLanguage(), |
| 3295 | HasBraces); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3296 | |
| 3297 | if (HasBraces) { |
| 3298 | SourceLocation RBraceLoc = Importer.Import(D->getRBraceLoc()); |
| 3299 | ToLinkageSpec->setRBraceLoc(RBraceLoc); |
| 3300 | } |
| 3301 | |
| 3302 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 3303 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 3304 | |
| 3305 | Importer.Imported(D, ToLinkageSpec); |
| 3306 | |
| 3307 | return ToLinkageSpec; |
| 3308 | } |
| 3309 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3310 | Decl *ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
| 3311 | DeclContext *DC, *LexicalDC; |
| 3312 | DeclarationName Name; |
| 3313 | SourceLocation Loc; |
| 3314 | NamedDecl *ToD = nullptr; |
| 3315 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3316 | return nullptr; |
| 3317 | if (ToD) |
| 3318 | return ToD; |
| 3319 | |
| 3320 | DeclarationNameInfo NameInfo(Name, |
| 3321 | Importer.Import(D->getNameInfo().getLoc())); |
| 3322 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 3323 | |
| 3324 | UsingDecl *ToUsing = UsingDecl::Create(Importer.getToContext(), DC, |
| 3325 | Importer.Import(D->getUsingLoc()), |
| 3326 | Importer.Import(D->getQualifierLoc()), |
| 3327 | NameInfo, D->hasTypename()); |
| 3328 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 3329 | LexicalDC->addDeclInternal(ToUsing); |
| 3330 | Importer.Imported(D, ToUsing); |
| 3331 | |
| 3332 | if (NamedDecl *FromPattern = |
| 3333 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
| 3334 | if (NamedDecl *ToPattern = |
| 3335 | dyn_cast_or_null<NamedDecl>(Importer.Import(FromPattern))) |
| 3336 | Importer.getToContext().setInstantiatedFromUsingDecl(ToUsing, ToPattern); |
| 3337 | else |
| 3338 | return nullptr; |
| 3339 | } |
| 3340 | |
| 3341 | for (UsingShadowDecl *FromShadow : D->shadows()) { |
| 3342 | if (UsingShadowDecl *ToShadow = |
| 3343 | dyn_cast_or_null<UsingShadowDecl>(Importer.Import(FromShadow))) |
| 3344 | ToUsing->addShadowDecl(ToShadow); |
| 3345 | else |
| 3346 | // FIXME: We return a nullptr here but the definition is already created |
| 3347 | // and available with lookups. How to fix this?.. |
| 3348 | return nullptr; |
| 3349 | } |
| 3350 | return ToUsing; |
| 3351 | } |
| 3352 | |
| 3353 | Decl *ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| 3354 | DeclContext *DC, *LexicalDC; |
| 3355 | DeclarationName Name; |
| 3356 | SourceLocation Loc; |
| 3357 | NamedDecl *ToD = nullptr; |
| 3358 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3359 | return nullptr; |
| 3360 | if (ToD) |
| 3361 | return ToD; |
| 3362 | |
| 3363 | UsingDecl *ToUsing = dyn_cast_or_null<UsingDecl>( |
| 3364 | Importer.Import(D->getUsingDecl())); |
| 3365 | if (!ToUsing) |
| 3366 | return nullptr; |
| 3367 | |
| 3368 | NamedDecl *ToTarget = dyn_cast_or_null<NamedDecl>( |
| 3369 | Importer.Import(D->getTargetDecl())); |
| 3370 | if (!ToTarget) |
| 3371 | return nullptr; |
| 3372 | |
| 3373 | UsingShadowDecl *ToShadow = UsingShadowDecl::Create( |
| 3374 | Importer.getToContext(), DC, Loc, ToUsing, ToTarget); |
| 3375 | |
| 3376 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 3377 | ToShadow->setAccess(D->getAccess()); |
| 3378 | Importer.Imported(D, ToShadow); |
| 3379 | |
| 3380 | if (UsingShadowDecl *FromPattern = |
| 3381 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
| 3382 | if (UsingShadowDecl *ToPattern = |
| 3383 | dyn_cast_or_null<UsingShadowDecl>(Importer.Import(FromPattern))) |
| 3384 | Importer.getToContext().setInstantiatedFromUsingShadowDecl(ToShadow, |
| 3385 | ToPattern); |
| 3386 | else |
| 3387 | // FIXME: We return a nullptr here but the definition is already created |
| 3388 | // and available with lookups. How to fix this?.. |
| 3389 | return nullptr; |
| 3390 | } |
| 3391 | |
| 3392 | LexicalDC->addDeclInternal(ToShadow); |
| 3393 | |
| 3394 | return ToShadow; |
| 3395 | } |
| 3396 | |
| 3397 | |
| 3398 | Decl *ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 3399 | DeclContext *DC, *LexicalDC; |
| 3400 | DeclarationName Name; |
| 3401 | SourceLocation Loc; |
| 3402 | NamedDecl *ToD = nullptr; |
| 3403 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3404 | return nullptr; |
| 3405 | if (ToD) |
| 3406 | return ToD; |
| 3407 | |
| 3408 | DeclContext *ToComAncestor = Importer.ImportContext(D->getCommonAncestor()); |
| 3409 | if (!ToComAncestor) |
| 3410 | return nullptr; |
| 3411 | |
| 3412 | NamespaceDecl *ToNominated = cast_or_null<NamespaceDecl>( |
| 3413 | Importer.Import(D->getNominatedNamespace())); |
| 3414 | if (!ToNominated) |
| 3415 | return nullptr; |
| 3416 | |
| 3417 | UsingDirectiveDecl *ToUsingDir = UsingDirectiveDecl::Create( |
| 3418 | Importer.getToContext(), DC, Importer.Import(D->getUsingLoc()), |
| 3419 | Importer.Import(D->getNamespaceKeyLocation()), |
| 3420 | Importer.Import(D->getQualifierLoc()), |
| 3421 | Importer.Import(D->getIdentLocation()), ToNominated, ToComAncestor); |
| 3422 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 3423 | LexicalDC->addDeclInternal(ToUsingDir); |
| 3424 | Importer.Imported(D, ToUsingDir); |
| 3425 | |
| 3426 | return ToUsingDir; |
| 3427 | } |
| 3428 | |
| 3429 | Decl *ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
| 3430 | UnresolvedUsingValueDecl *D) { |
| 3431 | DeclContext *DC, *LexicalDC; |
| 3432 | DeclarationName Name; |
| 3433 | SourceLocation Loc; |
| 3434 | NamedDecl *ToD = nullptr; |
| 3435 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3436 | return nullptr; |
| 3437 | if (ToD) |
| 3438 | return ToD; |
| 3439 | |
| 3440 | DeclarationNameInfo NameInfo(Name, Importer.Import(D->getNameInfo().getLoc())); |
| 3441 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 3442 | |
| 3443 | UnresolvedUsingValueDecl *ToUsingValue = UnresolvedUsingValueDecl::Create( |
| 3444 | Importer.getToContext(), DC, Importer.Import(D->getUsingLoc()), |
| 3445 | Importer.Import(D->getQualifierLoc()), NameInfo, |
| 3446 | Importer.Import(D->getEllipsisLoc())); |
| 3447 | |
| 3448 | Importer.Imported(D, ToUsingValue); |
| 3449 | ToUsingValue->setAccess(D->getAccess()); |
| 3450 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 3451 | LexicalDC->addDeclInternal(ToUsingValue); |
| 3452 | |
| 3453 | return ToUsingValue; |
| 3454 | } |
| 3455 | |
| 3456 | Decl *ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
| 3457 | UnresolvedUsingTypenameDecl *D) { |
| 3458 | DeclContext *DC, *LexicalDC; |
| 3459 | DeclarationName Name; |
| 3460 | SourceLocation Loc; |
| 3461 | NamedDecl *ToD = nullptr; |
| 3462 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3463 | return nullptr; |
| 3464 | if (ToD) |
| 3465 | return ToD; |
| 3466 | |
| 3467 | UnresolvedUsingTypenameDecl *ToUsing = UnresolvedUsingTypenameDecl::Create( |
| 3468 | Importer.getToContext(), DC, Importer.Import(D->getUsingLoc()), |
| 3469 | Importer.Import(D->getTypenameLoc()), |
| 3470 | Importer.Import(D->getQualifierLoc()), Loc, Name, |
| 3471 | Importer.Import(D->getEllipsisLoc())); |
| 3472 | |
| 3473 | Importer.Imported(D, ToUsing); |
| 3474 | ToUsing->setAccess(D->getAccess()); |
| 3475 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 3476 | LexicalDC->addDeclInternal(ToUsing); |
| 3477 | |
| 3478 | return ToUsing; |
| 3479 | } |
| 3480 | |
| 3481 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3482 | bool ASTNodeImporter::ImportDefinition(ObjCInterfaceDecl *From, |
| 3483 | ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3484 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3485 | if (To->getDefinition()) { |
| 3486 | // Check consistency of superclass. |
| 3487 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 3488 | if (FromSuper) { |
| 3489 | FromSuper = cast_or_null<ObjCInterfaceDecl>(Importer.Import(FromSuper)); |
| 3490 | if (!FromSuper) |
| 3491 | return true; |
| 3492 | } |
| 3493 | |
| 3494 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
| 3495 | if ((bool)FromSuper != (bool)ToSuper || |
| 3496 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
| 3497 | Importer.ToDiag(To->getLocation(), |
| 3498 | diag::err_odr_objc_superclass_inconsistent) |
| 3499 | << To->getDeclName(); |
| 3500 | if (ToSuper) |
| 3501 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 3502 | << To->getSuperClass()->getDeclName(); |
| 3503 | else |
| 3504 | Importer.ToDiag(To->getLocation(), |
| 3505 | diag::note_odr_objc_missing_superclass); |
| 3506 | if (From->getSuperClass()) |
| 3507 | Importer.FromDiag(From->getSuperClassLoc(), |
| 3508 | diag::note_odr_objc_superclass) |
| 3509 | << From->getSuperClass()->getDeclName(); |
| 3510 | else |
| 3511 | Importer.FromDiag(From->getLocation(), |
| 3512 | diag::note_odr_objc_missing_superclass); |
| 3513 | } |
| 3514 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3515 | if (shouldForceImportDeclContext(Kind)) |
| 3516 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3517 | return false; |
| 3518 | } |
| 3519 | |
| 3520 | // Start the definition. |
| 3521 | To->startDefinition(); |
| 3522 | |
| 3523 | // If this class has a superclass, import it. |
| 3524 | if (From->getSuperClass()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 3525 | TypeSourceInfo *SuperTInfo = Importer.Import(From->getSuperClassTInfo()); |
| 3526 | if (!SuperTInfo) |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3527 | return true; |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 3528 | |
| 3529 | To->setSuperClass(SuperTInfo); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3530 | } |
| 3531 | |
| 3532 | // Import protocols |
| 3533 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3534 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| 3535 | ObjCInterfaceDecl::protocol_loc_iterator |
| 3536 | FromProtoLoc = From->protocol_loc_begin(); |
| 3537 | |
| 3538 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3539 | FromProtoEnd = From->protocol_end(); |
| 3540 | FromProto != FromProtoEnd; |
| 3541 | ++FromProto, ++FromProtoLoc) { |
| 3542 | ObjCProtocolDecl *ToProto |
| 3543 | = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
| 3544 | if (!ToProto) |
| 3545 | return true; |
| 3546 | Protocols.push_back(ToProto); |
| 3547 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3548 | } |
| 3549 | |
| 3550 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3551 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 3552 | ProtocolLocs.data(), Importer.getToContext()); |
| 3553 | |
| 3554 | // Import categories. When the categories themselves are imported, they'll |
| 3555 | // hook themselves into this interface. |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 3556 | for (auto *Cat : From->known_categories()) |
| 3557 | Importer.Import(Cat); |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 3558 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3559 | // If we have an @implementation, import it as well. |
| 3560 | if (From->getImplementation()) { |
| 3561 | ObjCImplementationDecl *Impl = cast_or_null<ObjCImplementationDecl>( |
| 3562 | Importer.Import(From->getImplementation())); |
| 3563 | if (!Impl) |
| 3564 | return true; |
| 3565 | |
| 3566 | To->setImplementation(Impl); |
| 3567 | } |
| 3568 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3569 | if (shouldForceImportDeclContext(Kind)) { |
| 3570 | // Import all of the members of this class. |
| 3571 | ImportDeclContext(From, /*ForceImport=*/true); |
| 3572 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3573 | return false; |
| 3574 | } |
| 3575 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3576 | ObjCTypeParamList * |
| 3577 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 3578 | if (!list) |
| 3579 | return nullptr; |
| 3580 | |
| 3581 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
| 3582 | for (auto fromTypeParam : *list) { |
| 3583 | auto toTypeParam = cast_or_null<ObjCTypeParamDecl>( |
| 3584 | Importer.Import(fromTypeParam)); |
| 3585 | if (!toTypeParam) |
| 3586 | return nullptr; |
| 3587 | |
| 3588 | toTypeParams.push_back(toTypeParam); |
| 3589 | } |
| 3590 | |
| 3591 | return ObjCTypeParamList::create(Importer.getToContext(), |
| 3592 | Importer.Import(list->getLAngleLoc()), |
| 3593 | toTypeParams, |
| 3594 | Importer.Import(list->getRAngleLoc())); |
| 3595 | } |
| 3596 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3597 | Decl *ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3598 | // If this class has a definition in the translation unit we're coming from, |
| 3599 | // but this particular declaration is not that definition, import the |
| 3600 | // definition and map to that. |
| 3601 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 3602 | if (Definition && Definition != D) { |
| 3603 | Decl *ImportedDef = Importer.Import(Definition); |
| 3604 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3605 | return nullptr; |
| 3606 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3607 | return Importer.Imported(D, ImportedDef); |
| 3608 | } |
| 3609 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3610 | // Import the major distinguishing characteristics of an @interface. |
| 3611 | DeclContext *DC, *LexicalDC; |
| 3612 | DeclarationName Name; |
| 3613 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3614 | NamedDecl *ToD; |
| 3615 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3616 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3617 | if (ToD) |
| 3618 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3619 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3620 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3621 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3622 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3623 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3624 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 3625 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3626 | continue; |
| 3627 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3628 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecls[I]))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3629 | break; |
| 3630 | } |
| 3631 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3632 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3633 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3634 | if (!ToIface) { |
| 3635 | ToIface = ObjCInterfaceDecl::Create(Importer.getToContext(), DC, |
| 3636 | Importer.Import(D->getAtStartLoc()), |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3637 | Name.getAsIdentifierInfo(), |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3638 | /*TypeParamList=*/nullptr, |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3639 | /*PrevDecl=*/nullptr, Loc, |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3640 | D->isImplicitInterfaceDecl()); |
| 3641 | ToIface->setLexicalDeclContext(LexicalDC); |
| 3642 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3643 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3644 | Importer.Imported(D, ToIface); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3645 | // Import the type parameter list after calling Imported, to avoid |
| 3646 | // loops when bringing in their DeclContext. |
| 3647 | ToIface->setTypeParamList(ImportObjCTypeParamList( |
| 3648 | D->getTypeParamListAsWritten())); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3649 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3650 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToIface)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3651 | return nullptr; |
| 3652 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3653 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3654 | } |
| 3655 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3656 | Decl *ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 3657 | ObjCCategoryDecl *Category = cast_or_null<ObjCCategoryDecl>( |
| 3658 | Importer.Import(D->getCategoryDecl())); |
| 3659 | if (!Category) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3660 | return nullptr; |
| 3661 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3662 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 3663 | if (!ToImpl) { |
| 3664 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3665 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3666 | return nullptr; |
| 3667 | |
Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 3668 | SourceLocation CategoryNameLoc = Importer.Import(D->getCategoryNameLoc()); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3669 | ToImpl = ObjCCategoryImplDecl::Create(Importer.getToContext(), DC, |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3670 | Importer.Import(D->getIdentifier()), |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3671 | Category->getClassInterface(), |
| 3672 | Importer.Import(D->getLocation()), |
Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 3673 | Importer.Import(D->getAtStartLoc()), |
| 3674 | CategoryNameLoc); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3675 | |
| 3676 | DeclContext *LexicalDC = DC; |
| 3677 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3678 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3679 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3680 | return nullptr; |
| 3681 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3682 | ToImpl->setLexicalDeclContext(LexicalDC); |
| 3683 | } |
| 3684 | |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3685 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3686 | Category->setImplementation(ToImpl); |
| 3687 | } |
| 3688 | |
| 3689 | Importer.Imported(D, ToImpl); |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 3690 | ImportDeclContext(D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3691 | return ToImpl; |
| 3692 | } |
| 3693 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3694 | Decl *ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 3695 | // Find the corresponding interface. |
| 3696 | ObjCInterfaceDecl *Iface = cast_or_null<ObjCInterfaceDecl>( |
| 3697 | Importer.Import(D->getClassInterface())); |
| 3698 | if (!Iface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3699 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3700 | |
| 3701 | // Import the superclass, if any. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3702 | ObjCInterfaceDecl *Super = nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3703 | if (D->getSuperClass()) { |
| 3704 | Super = cast_or_null<ObjCInterfaceDecl>( |
| 3705 | Importer.Import(D->getSuperClass())); |
| 3706 | if (!Super) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3707 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3708 | } |
| 3709 | |
| 3710 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 3711 | if (!Impl) { |
| 3712 | // We haven't imported an implementation yet. Create a new @implementation |
| 3713 | // now. |
| 3714 | Impl = ObjCImplementationDecl::Create(Importer.getToContext(), |
| 3715 | Importer.ImportContext(D->getDeclContext()), |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3716 | Iface, Super, |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3717 | Importer.Import(D->getLocation()), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3718 | Importer.Import(D->getAtStartLoc()), |
Argyrios Kyrtzidis | 5d2ce84 | 2013-05-03 22:31:26 +0000 | [diff] [blame] | 3719 | Importer.Import(D->getSuperClassLoc()), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3720 | Importer.Import(D->getIvarLBraceLoc()), |
| 3721 | Importer.Import(D->getIvarRBraceLoc())); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3722 | |
| 3723 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3724 | DeclContext *LexicalDC |
| 3725 | = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3726 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3727 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3728 | Impl->setLexicalDeclContext(LexicalDC); |
| 3729 | } |
| 3730 | |
| 3731 | // Associate the implementation with the class it implements. |
| 3732 | Iface->setImplementation(Impl); |
| 3733 | Importer.Imported(D, Iface->getImplementation()); |
| 3734 | } else { |
| 3735 | Importer.Imported(D, Iface->getImplementation()); |
| 3736 | |
| 3737 | // Verify that the existing @implementation has the same superclass. |
| 3738 | if ((Super && !Impl->getSuperClass()) || |
| 3739 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 3740 | (Super && Impl->getSuperClass() && |
| 3741 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 3742 | Impl->getSuperClass()))) { |
| 3743 | Importer.ToDiag(Impl->getLocation(), |
| 3744 | diag::err_odr_objc_superclass_inconsistent) |
| 3745 | << Iface->getDeclName(); |
| 3746 | // FIXME: It would be nice to have the location of the superclass |
| 3747 | // below. |
| 3748 | if (Impl->getSuperClass()) |
| 3749 | Importer.ToDiag(Impl->getLocation(), |
| 3750 | diag::note_odr_objc_superclass) |
| 3751 | << Impl->getSuperClass()->getDeclName(); |
| 3752 | else |
| 3753 | Importer.ToDiag(Impl->getLocation(), |
| 3754 | diag::note_odr_objc_missing_superclass); |
| 3755 | if (D->getSuperClass()) |
| 3756 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3757 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 3758 | << D->getSuperClass()->getDeclName(); |
| 3759 | else |
| 3760 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3761 | diag::note_odr_objc_missing_superclass); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3762 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3763 | } |
| 3764 | } |
| 3765 | |
| 3766 | // Import all of the members of this @implementation. |
| 3767 | ImportDeclContext(D); |
| 3768 | |
| 3769 | return Impl; |
| 3770 | } |
| 3771 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3772 | Decl *ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| 3773 | // Import the major distinguishing characteristics of an @property. |
| 3774 | DeclContext *DC, *LexicalDC; |
| 3775 | DeclarationName Name; |
| 3776 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3777 | NamedDecl *ToD; |
| 3778 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3779 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3780 | if (ToD) |
| 3781 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3782 | |
| 3783 | // Check whether we have already imported this property. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3784 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3785 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3786 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3787 | if (ObjCPropertyDecl *FoundProp |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3788 | = dyn_cast<ObjCPropertyDecl>(FoundDecls[I])) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3789 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3790 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3791 | FoundProp->getType())) { |
| 3792 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) |
| 3793 | << Name << D->getType() << FoundProp->getType(); |
| 3794 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 3795 | << FoundProp->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3796 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3797 | } |
| 3798 | |
| 3799 | // FIXME: Check property attributes, getters, setters, etc.? |
| 3800 | |
| 3801 | // Consider these properties to be equivalent. |
| 3802 | Importer.Imported(D, FoundProp); |
| 3803 | return FoundProp; |
| 3804 | } |
| 3805 | } |
| 3806 | |
| 3807 | // Import the type. |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 3808 | TypeSourceInfo *TSI = Importer.Import(D->getTypeSourceInfo()); |
| 3809 | if (!TSI) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3810 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3811 | |
| 3812 | // Create the new property. |
| 3813 | ObjCPropertyDecl *ToProperty |
| 3814 | = ObjCPropertyDecl::Create(Importer.getToContext(), DC, Loc, |
| 3815 | Name.getAsIdentifierInfo(), |
| 3816 | Importer.Import(D->getAtLoc()), |
Fariborz Jahanian | 86c2f5c | 2012-02-29 22:18:55 +0000 | [diff] [blame] | 3817 | Importer.Import(D->getLParenLoc()), |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 3818 | Importer.Import(D->getType()), |
| 3819 | TSI, |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3820 | D->getPropertyImplementation()); |
| 3821 | Importer.Imported(D, ToProperty); |
| 3822 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3823 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3824 | |
| 3825 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 3826 | ToProperty->setPropertyAttributesAsWritten( |
| 3827 | D->getPropertyAttributesAsWritten()); |
Argyrios Kyrtzidis | 194b28e | 2017-03-16 18:25:40 +0000 | [diff] [blame] | 3828 | ToProperty->setGetterName(Importer.Import(D->getGetterName()), |
| 3829 | Importer.Import(D->getGetterNameLoc())); |
| 3830 | ToProperty->setSetterName(Importer.Import(D->getSetterName()), |
| 3831 | Importer.Import(D->getSetterNameLoc())); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3832 | ToProperty->setGetterMethodDecl( |
| 3833 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getGetterMethodDecl()))); |
| 3834 | ToProperty->setSetterMethodDecl( |
| 3835 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getSetterMethodDecl()))); |
| 3836 | ToProperty->setPropertyIvarDecl( |
| 3837 | cast_or_null<ObjCIvarDecl>(Importer.Import(D->getPropertyIvarDecl()))); |
| 3838 | return ToProperty; |
| 3839 | } |
| 3840 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3841 | Decl *ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 3842 | ObjCPropertyDecl *Property = cast_or_null<ObjCPropertyDecl>( |
| 3843 | Importer.Import(D->getPropertyDecl())); |
| 3844 | if (!Property) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3845 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3846 | |
| 3847 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3848 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3849 | return nullptr; |
| 3850 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3851 | // Import the lexical declaration context. |
| 3852 | DeclContext *LexicalDC = DC; |
| 3853 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3854 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3855 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3856 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3857 | } |
| 3858 | |
| 3859 | ObjCImplDecl *InImpl = dyn_cast<ObjCImplDecl>(LexicalDC); |
| 3860 | if (!InImpl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3861 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3862 | |
| 3863 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3864 | ObjCIvarDecl *Ivar = nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3865 | if (D->getPropertyIvarDecl()) { |
| 3866 | Ivar = cast_or_null<ObjCIvarDecl>( |
| 3867 | Importer.Import(D->getPropertyIvarDecl())); |
| 3868 | if (!Ivar) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3869 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3870 | } |
| 3871 | |
| 3872 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 3873 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 3874 | Property->getQueryKind()); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3875 | if (!ToImpl) { |
| 3876 | ToImpl = ObjCPropertyImplDecl::Create(Importer.getToContext(), DC, |
| 3877 | Importer.Import(D->getLocStart()), |
| 3878 | Importer.Import(D->getLocation()), |
| 3879 | Property, |
| 3880 | D->getPropertyImplementation(), |
| 3881 | Ivar, |
| 3882 | Importer.Import(D->getPropertyIvarDeclLoc())); |
| 3883 | ToImpl->setLexicalDeclContext(LexicalDC); |
| 3884 | Importer.Imported(D, ToImpl); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3885 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3886 | } else { |
| 3887 | // Check that we have the same kind of property implementation (@synthesize |
| 3888 | // vs. @dynamic). |
| 3889 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
| 3890 | Importer.ToDiag(ToImpl->getLocation(), |
| 3891 | diag::err_odr_objc_property_impl_kind_inconsistent) |
| 3892 | << Property->getDeclName() |
| 3893 | << (ToImpl->getPropertyImplementation() |
| 3894 | == ObjCPropertyImplDecl::Dynamic); |
| 3895 | Importer.FromDiag(D->getLocation(), |
| 3896 | diag::note_odr_objc_property_impl_kind) |
| 3897 | << D->getPropertyDecl()->getDeclName() |
| 3898 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3899 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3900 | } |
| 3901 | |
| 3902 | // For @synthesize, check that we have the same |
| 3903 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 3904 | Ivar != ToImpl->getPropertyIvarDecl()) { |
| 3905 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
| 3906 | diag::err_odr_objc_synthesize_ivar_inconsistent) |
| 3907 | << Property->getDeclName() |
| 3908 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 3909 | << Ivar->getDeclName(); |
| 3910 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
| 3911 | diag::note_odr_objc_synthesize_ivar_here) |
| 3912 | << D->getPropertyIvarDecl()->getDeclName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3913 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3914 | } |
| 3915 | |
| 3916 | // Merge the existing implementation with the new implementation. |
| 3917 | Importer.Imported(D, ToImpl); |
| 3918 | } |
| 3919 | |
| 3920 | return ToImpl; |
| 3921 | } |
| 3922 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3923 | Decl *ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| 3924 | // For template arguments, we adopt the translation unit as our declaration |
| 3925 | // context. This context will be fixed when the actual template declaration |
| 3926 | // is created. |
| 3927 | |
| 3928 | // FIXME: Import default argument. |
| 3929 | return TemplateTypeParmDecl::Create(Importer.getToContext(), |
| 3930 | Importer.getToContext().getTranslationUnitDecl(), |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 3931 | Importer.Import(D->getLocStart()), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3932 | Importer.Import(D->getLocation()), |
| 3933 | D->getDepth(), |
| 3934 | D->getIndex(), |
| 3935 | Importer.Import(D->getIdentifier()), |
| 3936 | D->wasDeclaredWithTypename(), |
| 3937 | D->isParameterPack()); |
| 3938 | } |
| 3939 | |
| 3940 | Decl * |
| 3941 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| 3942 | // Import the name of this declaration. |
| 3943 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 3944 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3945 | return nullptr; |
| 3946 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3947 | // Import the location of this declaration. |
| 3948 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 3949 | |
| 3950 | // Import the type of this declaration. |
| 3951 | QualType T = Importer.Import(D->getType()); |
| 3952 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3953 | return nullptr; |
| 3954 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3955 | // Import type-source information. |
| 3956 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3957 | if (D->getTypeSourceInfo() && !TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3958 | return nullptr; |
| 3959 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3960 | // FIXME: Import default argument. |
| 3961 | |
| 3962 | return NonTypeTemplateParmDecl::Create(Importer.getToContext(), |
| 3963 | Importer.getToContext().getTranslationUnitDecl(), |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 3964 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3965 | Loc, D->getDepth(), D->getPosition(), |
| 3966 | Name.getAsIdentifierInfo(), |
Douglas Gregor | da3cc0d | 2010-12-23 23:51:58 +0000 | [diff] [blame] | 3967 | T, D->isParameterPack(), TInfo); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3968 | } |
| 3969 | |
| 3970 | Decl * |
| 3971 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 3972 | // Import the name of this declaration. |
| 3973 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 3974 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3975 | return nullptr; |
| 3976 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3977 | // Import the location of this declaration. |
| 3978 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 3979 | |
| 3980 | // Import template parameters. |
| 3981 | TemplateParameterList *TemplateParams |
| 3982 | = ImportTemplateParameterList(D->getTemplateParameters()); |
| 3983 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3984 | return nullptr; |
| 3985 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3986 | // FIXME: Import default argument. |
| 3987 | |
| 3988 | return TemplateTemplateParmDecl::Create(Importer.getToContext(), |
| 3989 | Importer.getToContext().getTranslationUnitDecl(), |
| 3990 | Loc, D->getDepth(), D->getPosition(), |
Douglas Gregor | f550077 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 3991 | D->isParameterPack(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3992 | Name.getAsIdentifierInfo(), |
| 3993 | TemplateParams); |
| 3994 | } |
| 3995 | |
| 3996 | Decl *ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 3997 | // If this record has a definition in the translation unit we're coming from, |
| 3998 | // but this particular declaration is not that definition, import the |
| 3999 | // definition and map to that. |
| 4000 | CXXRecordDecl *Definition |
| 4001 | = cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition()); |
| 4002 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 4003 | Decl *ImportedDef |
| 4004 | = Importer.Import(Definition->getDescribedClassTemplate()); |
| 4005 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4006 | return nullptr; |
| 4007 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4008 | return Importer.Imported(D, ImportedDef); |
| 4009 | } |
| 4010 | |
| 4011 | // Import the major distinguishing characteristics of this class template. |
| 4012 | DeclContext *DC, *LexicalDC; |
| 4013 | DeclarationName Name; |
| 4014 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4015 | NamedDecl *ToD; |
| 4016 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4017 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4018 | if (ToD) |
| 4019 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4020 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4021 | // We may already have a template of the same name; try to find and match it. |
| 4022 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4023 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4024 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4025 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 4026 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 4027 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4028 | continue; |
| 4029 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 4030 | Decl *Found = FoundDecls[I]; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4031 | if (ClassTemplateDecl *FoundTemplate |
| 4032 | = dyn_cast<ClassTemplateDecl>(Found)) { |
| 4033 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 4034 | // The class templates structurally match; call it the same template. |
| 4035 | // FIXME: We may be filling in a forward declaration here. Handle |
| 4036 | // this case! |
| 4037 | Importer.Imported(D->getTemplatedDecl(), |
| 4038 | FoundTemplate->getTemplatedDecl()); |
| 4039 | return Importer.Imported(D, FoundTemplate); |
| 4040 | } |
| 4041 | } |
| 4042 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 4043 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4044 | } |
| 4045 | |
| 4046 | if (!ConflictingDecls.empty()) { |
| 4047 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 4048 | ConflictingDecls.data(), |
| 4049 | ConflictingDecls.size()); |
| 4050 | } |
| 4051 | |
| 4052 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4053 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4054 | } |
| 4055 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4056 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 4057 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4058 | // Create the declaration that is being templated. |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4059 | CXXRecordDecl *ToTemplated = cast_or_null<CXXRecordDecl>( |
| 4060 | Importer.Import(FromTemplated)); |
| 4061 | if (!ToTemplated) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4062 | return nullptr; |
| 4063 | |
| 4064 | // Resolve possible cyclic import. |
| 4065 | if (Decl *AlreadyImported = Importer.GetAlreadyImportedOrNull(D)) |
| 4066 | return AlreadyImported; |
| 4067 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4068 | // Create the class template declaration itself. |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4069 | TemplateParameterList *TemplateParams = |
| 4070 | ImportTemplateParameterList(D->getTemplateParameters()); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4071 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4072 | return nullptr; |
| 4073 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4074 | ClassTemplateDecl *D2 = ClassTemplateDecl::Create(Importer.getToContext(), DC, |
| 4075 | Loc, Name, TemplateParams, |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4076 | ToTemplated); |
| 4077 | ToTemplated->setDescribedClassTemplate(D2); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4078 | |
| 4079 | D2->setAccess(D->getAccess()); |
| 4080 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4081 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4082 | |
| 4083 | // Note the relationship between the class templates. |
| 4084 | Importer.Imported(D, D2); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4085 | Importer.Imported(FromTemplated, ToTemplated); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4086 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4087 | if (FromTemplated->isCompleteDefinition() && |
| 4088 | !ToTemplated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4089 | // FIXME: Import definition! |
| 4090 | } |
| 4091 | |
| 4092 | return D2; |
| 4093 | } |
| 4094 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4095 | Decl *ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
| 4096 | ClassTemplateSpecializationDecl *D) { |
| 4097 | // If this record has a definition in the translation unit we're coming from, |
| 4098 | // but this particular declaration is not that definition, import the |
| 4099 | // definition and map to that. |
| 4100 | TagDecl *Definition = D->getDefinition(); |
| 4101 | if (Definition && Definition != D) { |
| 4102 | Decl *ImportedDef = Importer.Import(Definition); |
| 4103 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4104 | return nullptr; |
| 4105 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4106 | return Importer.Imported(D, ImportedDef); |
| 4107 | } |
| 4108 | |
| 4109 | ClassTemplateDecl *ClassTemplate |
| 4110 | = cast_or_null<ClassTemplateDecl>(Importer.Import( |
| 4111 | D->getSpecializedTemplate())); |
| 4112 | if (!ClassTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4113 | return nullptr; |
| 4114 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4115 | // Import the context of this declaration. |
| 4116 | DeclContext *DC = ClassTemplate->getDeclContext(); |
| 4117 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4118 | return nullptr; |
| 4119 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4120 | DeclContext *LexicalDC = DC; |
| 4121 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4122 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4123 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4124 | return nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4125 | } |
| 4126 | |
| 4127 | // Import the location of this declaration. |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 4128 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 4129 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4130 | |
| 4131 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4132 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4133 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 4134 | D->getTemplateArgs().size(), |
| 4135 | TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4136 | return nullptr; |
| 4137 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4138 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4139 | void *InsertPos = nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4140 | ClassTemplateSpecializationDecl *D2 |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 4141 | = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4142 | if (D2) { |
| 4143 | // We already have a class template specialization with these template |
| 4144 | // arguments. |
| 4145 | |
| 4146 | // FIXME: Check for specialization vs. instantiation errors. |
| 4147 | |
| 4148 | if (RecordDecl *FoundDef = D2->getDefinition()) { |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4149 | if (!D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4150 | // The record types structurally match, or the "from" translation |
| 4151 | // unit only had a forward declaration anyway; call it the same |
| 4152 | // function. |
| 4153 | return Importer.Imported(D, FoundDef); |
| 4154 | } |
| 4155 | } |
| 4156 | } else { |
| 4157 | // Create a new specialization. |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4158 | if (ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 4159 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { |
| 4160 | |
| 4161 | // Import TemplateArgumentListInfo |
| 4162 | TemplateArgumentListInfo ToTAInfo; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4163 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 4164 | if (ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4165 | return nullptr; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4166 | |
| 4167 | QualType CanonInjType = Importer.Import( |
| 4168 | PartialSpec->getInjectedSpecializationType()); |
| 4169 | if (CanonInjType.isNull()) |
| 4170 | return nullptr; |
| 4171 | CanonInjType = CanonInjType.getCanonicalType(); |
| 4172 | |
| 4173 | TemplateParameterList *ToTPList = ImportTemplateParameterList( |
| 4174 | PartialSpec->getTemplateParameters()); |
| 4175 | if (!ToTPList && PartialSpec->getTemplateParameters()) |
| 4176 | return nullptr; |
| 4177 | |
| 4178 | D2 = ClassTemplatePartialSpecializationDecl::Create( |
| 4179 | Importer.getToContext(), D->getTagKind(), DC, StartLoc, IdLoc, |
| 4180 | ToTPList, ClassTemplate, |
| 4181 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
| 4182 | ToTAInfo, CanonInjType, nullptr); |
| 4183 | |
| 4184 | } else { |
| 4185 | D2 = ClassTemplateSpecializationDecl::Create(Importer.getToContext(), |
| 4186 | D->getTagKind(), DC, |
| 4187 | StartLoc, IdLoc, |
| 4188 | ClassTemplate, |
| 4189 | TemplateArgs, |
| 4190 | /*PrevDecl=*/nullptr); |
| 4191 | } |
| 4192 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4193 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 4194 | |
| 4195 | // Add this specialization to the class template. |
| 4196 | ClassTemplate->AddSpecialization(D2, InsertPos); |
| 4197 | |
| 4198 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4199 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4200 | |
| 4201 | Importer.Imported(D, D2); |
| 4202 | |
| 4203 | if (auto *TSI = D->getTypeAsWritten()) { |
| 4204 | TypeSourceInfo *TInfo = Importer.Import(TSI); |
| 4205 | if (!TInfo) |
| 4206 | return nullptr; |
| 4207 | D2->setTypeAsWritten(TInfo); |
| 4208 | D2->setTemplateKeywordLoc(Importer.Import(D->getTemplateKeywordLoc())); |
| 4209 | D2->setExternLoc(Importer.Import(D->getExternLoc())); |
| 4210 | } |
| 4211 | |
| 4212 | SourceLocation POI = Importer.Import(D->getPointOfInstantiation()); |
| 4213 | if (POI.isValid()) |
| 4214 | D2->setPointOfInstantiation(POI); |
| 4215 | else if (D->getPointOfInstantiation().isValid()) |
| 4216 | return nullptr; |
| 4217 | |
| 4218 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 4219 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4220 | // Add the specialization to this context. |
| 4221 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4222 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4223 | } |
| 4224 | Importer.Imported(D, D2); |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4225 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4226 | return nullptr; |
| 4227 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4228 | return D2; |
| 4229 | } |
| 4230 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4231 | Decl *ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| 4232 | // If this variable has a definition in the translation unit we're coming |
| 4233 | // from, |
| 4234 | // but this particular declaration is not that definition, import the |
| 4235 | // definition and map to that. |
| 4236 | VarDecl *Definition = |
| 4237 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 4238 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 4239 | Decl *ImportedDef = Importer.Import(Definition->getDescribedVarTemplate()); |
| 4240 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4241 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4242 | |
| 4243 | return Importer.Imported(D, ImportedDef); |
| 4244 | } |
| 4245 | |
| 4246 | // Import the major distinguishing characteristics of this variable template. |
| 4247 | DeclContext *DC, *LexicalDC; |
| 4248 | DeclarationName Name; |
| 4249 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4250 | NamedDecl *ToD; |
| 4251 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4252 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4253 | if (ToD) |
| 4254 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4255 | |
| 4256 | // We may already have a template of the same name; try to find and match it. |
| 4257 | assert(!DC->isFunctionOrMethod() && |
| 4258 | "Variable templates cannot be declared at function scope"); |
| 4259 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 4260 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4261 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4262 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 4263 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
| 4264 | continue; |
| 4265 | |
| 4266 | Decl *Found = FoundDecls[I]; |
| 4267 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
| 4268 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 4269 | // The variable templates structurally match; call it the same template. |
| 4270 | Importer.Imported(D->getTemplatedDecl(), |
| 4271 | FoundTemplate->getTemplatedDecl()); |
| 4272 | return Importer.Imported(D, FoundTemplate); |
| 4273 | } |
| 4274 | } |
| 4275 | |
| 4276 | ConflictingDecls.push_back(FoundDecls[I]); |
| 4277 | } |
| 4278 | |
| 4279 | if (!ConflictingDecls.empty()) { |
| 4280 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 4281 | ConflictingDecls.data(), |
| 4282 | ConflictingDecls.size()); |
| 4283 | } |
| 4284 | |
| 4285 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4286 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4287 | |
| 4288 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 4289 | |
| 4290 | // Import the type. |
| 4291 | QualType T = Importer.Import(DTemplated->getType()); |
| 4292 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4293 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4294 | |
| 4295 | // Create the declaration that is being templated. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4296 | auto *ToTemplated = dyn_cast_or_null<VarDecl>(Importer.Import(DTemplated)); |
| 4297 | if (!ToTemplated) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4298 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4299 | |
| 4300 | // Create the variable template declaration itself. |
| 4301 | TemplateParameterList *TemplateParams = |
| 4302 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 4303 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4304 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4305 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4306 | VarTemplateDecl *ToVarTD = VarTemplateDecl::Create( |
| 4307 | Importer.getToContext(), DC, Loc, Name, TemplateParams, ToTemplated); |
| 4308 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4309 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4310 | ToVarTD->setAccess(D->getAccess()); |
| 4311 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 4312 | LexicalDC->addDeclInternal(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4313 | |
| 4314 | // Note the relationship between the variable templates. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4315 | Importer.Imported(D, ToVarTD); |
| 4316 | Importer.Imported(DTemplated, ToTemplated); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4317 | |
| 4318 | if (DTemplated->isThisDeclarationADefinition() && |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4319 | !ToTemplated->isThisDeclarationADefinition()) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4320 | // FIXME: Import definition! |
| 4321 | } |
| 4322 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4323 | return ToVarTD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4324 | } |
| 4325 | |
| 4326 | Decl *ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
| 4327 | VarTemplateSpecializationDecl *D) { |
| 4328 | // If this record has a definition in the translation unit we're coming from, |
| 4329 | // but this particular declaration is not that definition, import the |
| 4330 | // definition and map to that. |
| 4331 | VarDecl *Definition = D->getDefinition(); |
| 4332 | if (Definition && Definition != D) { |
| 4333 | Decl *ImportedDef = Importer.Import(Definition); |
| 4334 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4335 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4336 | |
| 4337 | return Importer.Imported(D, ImportedDef); |
| 4338 | } |
| 4339 | |
| 4340 | VarTemplateDecl *VarTemplate = cast_or_null<VarTemplateDecl>( |
| 4341 | Importer.Import(D->getSpecializedTemplate())); |
| 4342 | if (!VarTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4343 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4344 | |
| 4345 | // Import the context of this declaration. |
| 4346 | DeclContext *DC = VarTemplate->getDeclContext(); |
| 4347 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4348 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4349 | |
| 4350 | DeclContext *LexicalDC = DC; |
| 4351 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4352 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4353 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4354 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4355 | } |
| 4356 | |
| 4357 | // Import the location of this declaration. |
| 4358 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 4359 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
| 4360 | |
| 4361 | // Import template arguments. |
| 4362 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| 4363 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 4364 | D->getTemplateArgs().size(), TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4365 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4366 | |
| 4367 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4368 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4369 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 4370 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4371 | if (D2) { |
| 4372 | // We already have a variable template specialization with these template |
| 4373 | // arguments. |
| 4374 | |
| 4375 | // FIXME: Check for specialization vs. instantiation errors. |
| 4376 | |
| 4377 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 4378 | if (!D->isThisDeclarationADefinition() || |
| 4379 | IsStructuralMatch(D, FoundDef)) { |
| 4380 | // The record types structurally match, or the "from" translation |
| 4381 | // unit only had a forward declaration anyway; call it the same |
| 4382 | // variable. |
| 4383 | return Importer.Imported(D, FoundDef); |
| 4384 | } |
| 4385 | } |
| 4386 | } else { |
| 4387 | |
| 4388 | // Import the type. |
| 4389 | QualType T = Importer.Import(D->getType()); |
| 4390 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4391 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4392 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4393 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 4394 | if (D->getTypeSourceInfo() && !TInfo) |
| 4395 | return nullptr; |
| 4396 | |
| 4397 | TemplateArgumentListInfo ToTAInfo; |
| 4398 | if (ImportTemplateArgumentListInfo(D->getTemplateArgsInfo(), ToTAInfo)) |
| 4399 | return nullptr; |
| 4400 | |
| 4401 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4402 | // Create a new specialization. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4403 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 4404 | // Import TemplateArgumentListInfo |
| 4405 | TemplateArgumentListInfo ArgInfos; |
| 4406 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 4407 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
| 4408 | if (ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ArgInfos)) |
| 4409 | return nullptr; |
| 4410 | |
| 4411 | TemplateParameterList *ToTPList = ImportTemplateParameterList( |
| 4412 | FromPartial->getTemplateParameters()); |
| 4413 | if (!ToTPList) |
| 4414 | return nullptr; |
| 4415 | |
| 4416 | auto *ToPartial = PartVarSpecDecl::Create( |
| 4417 | Importer.getToContext(), DC, StartLoc, IdLoc, ToTPList, VarTemplate, |
| 4418 | T, TInfo, D->getStorageClass(), TemplateArgs, ArgInfos); |
| 4419 | |
| 4420 | auto *FromInst = FromPartial->getInstantiatedFromMember(); |
| 4421 | auto *ToInst = cast_or_null<PartVarSpecDecl>(Importer.Import(FromInst)); |
| 4422 | if (FromInst && !ToInst) |
| 4423 | return nullptr; |
| 4424 | |
| 4425 | ToPartial->setInstantiatedFromMember(ToInst); |
| 4426 | if (FromPartial->isMemberSpecialization()) |
| 4427 | ToPartial->setMemberSpecialization(); |
| 4428 | |
| 4429 | D2 = ToPartial; |
| 4430 | |
| 4431 | } else { // Full specialization |
| 4432 | D2 = VarTemplateSpecializationDecl::Create( |
| 4433 | Importer.getToContext(), DC, StartLoc, IdLoc, VarTemplate, T, TInfo, |
| 4434 | D->getStorageClass(), TemplateArgs); |
| 4435 | } |
| 4436 | |
| 4437 | SourceLocation POI = D->getPointOfInstantiation(); |
| 4438 | if (POI.isValid()) |
| 4439 | D2->setPointOfInstantiation(Importer.Import(POI)); |
| 4440 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4441 | D2->setSpecializationKind(D->getSpecializationKind()); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4442 | D2->setTemplateArgsInfo(ToTAInfo); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4443 | |
| 4444 | // Add this specialization to the class template. |
| 4445 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 4446 | |
| 4447 | // Import the qualifier, if any. |
| 4448 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
| 4449 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4450 | if (D->isConstexpr()) |
| 4451 | D2->setConstexpr(true); |
| 4452 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4453 | // Add the specialization to this context. |
| 4454 | D2->setLexicalDeclContext(LexicalDC); |
| 4455 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4456 | |
| 4457 | D2->setAccess(D->getAccess()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4458 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4459 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4460 | Importer.Imported(D, D2); |
| 4461 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4462 | // NOTE: isThisDeclarationADefinition() can return DeclarationOnly even if |
| 4463 | // declaration has initializer. Should this be fixed in the AST?.. Anyway, |
| 4464 | // we have to check the declaration for initializer - otherwise, it won't be |
| 4465 | // imported. |
| 4466 | if ((D->isThisDeclarationADefinition() || D->hasInit()) && |
| 4467 | ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4468 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4469 | |
| 4470 | return D2; |
| 4471 | } |
| 4472 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4473 | Decl *ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 4474 | DeclContext *DC, *LexicalDC; |
| 4475 | DeclarationName Name; |
| 4476 | SourceLocation Loc; |
| 4477 | NamedDecl *ToD; |
| 4478 | |
| 4479 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4480 | return nullptr; |
| 4481 | |
| 4482 | if (ToD) |
| 4483 | return ToD; |
| 4484 | |
| 4485 | // Try to find a function in our own ("to") context with the same name, same |
| 4486 | // type, and in the same context as the function we're importing. |
| 4487 | if (!LexicalDC->isFunctionOrMethod()) { |
| 4488 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 4489 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 4490 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
| 4491 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 4492 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
| 4493 | continue; |
| 4494 | |
| 4495 | if (FunctionTemplateDecl *FoundFunction = |
| 4496 | dyn_cast<FunctionTemplateDecl>(FoundDecls[I])) { |
| 4497 | if (FoundFunction->hasExternalFormalLinkage() && |
| 4498 | D->hasExternalFormalLinkage()) { |
| 4499 | if (IsStructuralMatch(D, FoundFunction)) { |
| 4500 | Importer.Imported(D, FoundFunction); |
| 4501 | // FIXME: Actually try to merge the body and other attributes. |
| 4502 | return FoundFunction; |
| 4503 | } |
| 4504 | } |
| 4505 | } |
| 4506 | } |
| 4507 | } |
| 4508 | |
| 4509 | TemplateParameterList *Params = |
| 4510 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 4511 | if (!Params) |
| 4512 | return nullptr; |
| 4513 | |
| 4514 | FunctionDecl *TemplatedFD = |
| 4515 | cast_or_null<FunctionDecl>(Importer.Import(D->getTemplatedDecl())); |
| 4516 | if (!TemplatedFD) |
| 4517 | return nullptr; |
| 4518 | |
| 4519 | FunctionTemplateDecl *ToFunc = FunctionTemplateDecl::Create( |
| 4520 | Importer.getToContext(), DC, Loc, Name, Params, TemplatedFD); |
| 4521 | |
| 4522 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| 4523 | ToFunc->setAccess(D->getAccess()); |
| 4524 | ToFunc->setLexicalDeclContext(LexicalDC); |
| 4525 | Importer.Imported(D, ToFunc); |
| 4526 | |
| 4527 | LexicalDC->addDeclInternal(ToFunc); |
| 4528 | return ToFunc; |
| 4529 | } |
| 4530 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4531 | //---------------------------------------------------------------------------- |
| 4532 | // Import Statements |
| 4533 | //---------------------------------------------------------------------------- |
| 4534 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4535 | DeclGroupRef ASTNodeImporter::ImportDeclGroup(DeclGroupRef DG) { |
| 4536 | if (DG.isNull()) |
| 4537 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 4538 | size_t NumDecls = DG.end() - DG.begin(); |
| 4539 | SmallVector<Decl *, 1> ToDecls(NumDecls); |
| 4540 | auto &_Importer = this->Importer; |
| 4541 | std::transform(DG.begin(), DG.end(), ToDecls.begin(), |
| 4542 | [&_Importer](Decl *D) -> Decl * { |
| 4543 | return _Importer.Import(D); |
| 4544 | }); |
| 4545 | return DeclGroupRef::Create(Importer.getToContext(), |
| 4546 | ToDecls.begin(), |
| 4547 | NumDecls); |
| 4548 | } |
| 4549 | |
| 4550 | Stmt *ASTNodeImporter::VisitStmt(Stmt *S) { |
| 4551 | Importer.FromDiag(S->getLocStart(), diag::err_unsupported_ast_node) |
| 4552 | << S->getStmtClassName(); |
| 4553 | return nullptr; |
| 4554 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4555 | |
| 4556 | |
| 4557 | Stmt *ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
| 4558 | SmallVector<IdentifierInfo *, 4> Names; |
| 4559 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 4560 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 4561 | // ToII is nullptr when no symbolic name is given for output operand |
| 4562 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 4563 | if (!ToII && S->getOutputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4564 | return nullptr; |
| 4565 | Names.push_back(ToII); |
| 4566 | } |
| 4567 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 4568 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 4569 | // ToII is nullptr when no symbolic name is given for input operand |
| 4570 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 4571 | if (!ToII && S->getInputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4572 | return nullptr; |
| 4573 | Names.push_back(ToII); |
| 4574 | } |
| 4575 | |
| 4576 | SmallVector<StringLiteral *, 4> Clobbers; |
| 4577 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
| 4578 | StringLiteral *Clobber = cast_or_null<StringLiteral>( |
| 4579 | Importer.Import(S->getClobberStringLiteral(I))); |
| 4580 | if (!Clobber) |
| 4581 | return nullptr; |
| 4582 | Clobbers.push_back(Clobber); |
| 4583 | } |
| 4584 | |
| 4585 | SmallVector<StringLiteral *, 4> Constraints; |
| 4586 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 4587 | StringLiteral *Output = cast_or_null<StringLiteral>( |
| 4588 | Importer.Import(S->getOutputConstraintLiteral(I))); |
| 4589 | if (!Output) |
| 4590 | return nullptr; |
| 4591 | Constraints.push_back(Output); |
| 4592 | } |
| 4593 | |
| 4594 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 4595 | StringLiteral *Input = cast_or_null<StringLiteral>( |
| 4596 | Importer.Import(S->getInputConstraintLiteral(I))); |
| 4597 | if (!Input) |
| 4598 | return nullptr; |
| 4599 | Constraints.push_back(Input); |
| 4600 | } |
| 4601 | |
| 4602 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4603 | if (ImportContainerChecked(S->outputs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4604 | return nullptr; |
| 4605 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4606 | if (ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4607 | return nullptr; |
| 4608 | |
| 4609 | StringLiteral *AsmStr = cast_or_null<StringLiteral>( |
| 4610 | Importer.Import(S->getAsmString())); |
| 4611 | if (!AsmStr) |
| 4612 | return nullptr; |
| 4613 | |
| 4614 | return new (Importer.getToContext()) GCCAsmStmt( |
| 4615 | Importer.getToContext(), |
| 4616 | Importer.Import(S->getAsmLoc()), |
| 4617 | S->isSimple(), |
| 4618 | S->isVolatile(), |
| 4619 | S->getNumOutputs(), |
| 4620 | S->getNumInputs(), |
| 4621 | Names.data(), |
| 4622 | Constraints.data(), |
| 4623 | Exprs.data(), |
| 4624 | AsmStr, |
| 4625 | S->getNumClobbers(), |
| 4626 | Clobbers.data(), |
| 4627 | Importer.Import(S->getRParenLoc())); |
| 4628 | } |
| 4629 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4630 | Stmt *ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 4631 | DeclGroupRef ToDG = ImportDeclGroup(S->getDeclGroup()); |
| 4632 | for (Decl *ToD : ToDG) { |
| 4633 | if (!ToD) |
| 4634 | return nullptr; |
| 4635 | } |
| 4636 | SourceLocation ToStartLoc = Importer.Import(S->getStartLoc()); |
| 4637 | SourceLocation ToEndLoc = Importer.Import(S->getEndLoc()); |
| 4638 | return new (Importer.getToContext()) DeclStmt(ToDG, ToStartLoc, ToEndLoc); |
| 4639 | } |
| 4640 | |
| 4641 | Stmt *ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 4642 | SourceLocation ToSemiLoc = Importer.Import(S->getSemiLoc()); |
| 4643 | return new (Importer.getToContext()) NullStmt(ToSemiLoc, |
| 4644 | S->hasLeadingEmptyMacro()); |
| 4645 | } |
| 4646 | |
| 4647 | Stmt *ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4648 | llvm::SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4649 | |
| 4650 | if (ImportContainerChecked(S->body(), ToStmts)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 4651 | return nullptr; |
| 4652 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4653 | SourceLocation ToLBraceLoc = Importer.Import(S->getLBracLoc()); |
| 4654 | SourceLocation ToRBraceLoc = Importer.Import(S->getRBracLoc()); |
Benjamin Kramer | 0742090 | 2017-12-24 16:24:20 +0000 | [diff] [blame] | 4655 | return CompoundStmt::Create(Importer.getToContext(), ToStmts, ToLBraceLoc, |
| 4656 | ToRBraceLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4657 | } |
| 4658 | |
| 4659 | Stmt *ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 4660 | Expr *ToLHS = Importer.Import(S->getLHS()); |
| 4661 | if (!ToLHS) |
| 4662 | return nullptr; |
| 4663 | Expr *ToRHS = Importer.Import(S->getRHS()); |
| 4664 | if (!ToRHS && S->getRHS()) |
| 4665 | return nullptr; |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 4666 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4667 | if (!ToSubStmt && S->getSubStmt()) |
| 4668 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4669 | SourceLocation ToCaseLoc = Importer.Import(S->getCaseLoc()); |
| 4670 | SourceLocation ToEllipsisLoc = Importer.Import(S->getEllipsisLoc()); |
| 4671 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 4672 | CaseStmt *ToStmt = new (Importer.getToContext()) |
| 4673 | CaseStmt(ToLHS, ToRHS, ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
| 4674 | ToStmt->setSubStmt(ToSubStmt); |
| 4675 | return ToStmt; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4676 | } |
| 4677 | |
| 4678 | Stmt *ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 4679 | SourceLocation ToDefaultLoc = Importer.Import(S->getDefaultLoc()); |
| 4680 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 4681 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4682 | if (!ToSubStmt && S->getSubStmt()) |
| 4683 | return nullptr; |
| 4684 | return new (Importer.getToContext()) DefaultStmt(ToDefaultLoc, ToColonLoc, |
| 4685 | ToSubStmt); |
| 4686 | } |
| 4687 | |
| 4688 | Stmt *ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 4689 | SourceLocation ToIdentLoc = Importer.Import(S->getIdentLoc()); |
| 4690 | LabelDecl *ToLabelDecl = |
| 4691 | cast_or_null<LabelDecl>(Importer.Import(S->getDecl())); |
| 4692 | if (!ToLabelDecl && S->getDecl()) |
| 4693 | return nullptr; |
| 4694 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4695 | if (!ToSubStmt && S->getSubStmt()) |
| 4696 | return nullptr; |
| 4697 | return new (Importer.getToContext()) LabelStmt(ToIdentLoc, ToLabelDecl, |
| 4698 | ToSubStmt); |
| 4699 | } |
| 4700 | |
| 4701 | Stmt *ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 4702 | SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc()); |
| 4703 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 4704 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
| 4705 | ASTContext &_ToContext = Importer.getToContext(); |
| 4706 | std::transform(FromAttrs.begin(), FromAttrs.end(), ToAttrs.begin(), |
| 4707 | [&_ToContext](const Attr *A) -> const Attr * { |
| 4708 | return A->clone(_ToContext); |
| 4709 | }); |
| 4710 | for (const Attr *ToA : ToAttrs) { |
| 4711 | if (!ToA) |
| 4712 | return nullptr; |
| 4713 | } |
| 4714 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4715 | if (!ToSubStmt && S->getSubStmt()) |
| 4716 | return nullptr; |
| 4717 | return AttributedStmt::Create(Importer.getToContext(), ToAttrLoc, |
| 4718 | ToAttrs, ToSubStmt); |
| 4719 | } |
| 4720 | |
| 4721 | Stmt *ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 4722 | SourceLocation ToIfLoc = Importer.Import(S->getIfLoc()); |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4723 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4724 | if (!ToInit && S->getInit()) |
| 4725 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4726 | VarDecl *ToConditionVariable = nullptr; |
| 4727 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4728 | ToConditionVariable = |
| 4729 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4730 | if (!ToConditionVariable) |
| 4731 | return nullptr; |
| 4732 | } |
| 4733 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4734 | if (!ToCondition && S->getCond()) |
| 4735 | return nullptr; |
| 4736 | Stmt *ToThenStmt = Importer.Import(S->getThen()); |
| 4737 | if (!ToThenStmt && S->getThen()) |
| 4738 | return nullptr; |
| 4739 | SourceLocation ToElseLoc = Importer.Import(S->getElseLoc()); |
| 4740 | Stmt *ToElseStmt = Importer.Import(S->getElse()); |
| 4741 | if (!ToElseStmt && S->getElse()) |
| 4742 | return nullptr; |
| 4743 | return new (Importer.getToContext()) IfStmt(Importer.getToContext(), |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 4744 | ToIfLoc, S->isConstexpr(), |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4745 | ToInit, |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 4746 | ToConditionVariable, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4747 | ToCondition, ToThenStmt, |
| 4748 | ToElseLoc, ToElseStmt); |
| 4749 | } |
| 4750 | |
| 4751 | Stmt *ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4752 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4753 | if (!ToInit && S->getInit()) |
| 4754 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4755 | VarDecl *ToConditionVariable = nullptr; |
| 4756 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4757 | ToConditionVariable = |
| 4758 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4759 | if (!ToConditionVariable) |
| 4760 | return nullptr; |
| 4761 | } |
| 4762 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4763 | if (!ToCondition && S->getCond()) |
| 4764 | return nullptr; |
| 4765 | SwitchStmt *ToStmt = new (Importer.getToContext()) SwitchStmt( |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4766 | Importer.getToContext(), ToInit, |
| 4767 | ToConditionVariable, ToCondition); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4768 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4769 | if (!ToBody && S->getBody()) |
| 4770 | return nullptr; |
| 4771 | ToStmt->setBody(ToBody); |
| 4772 | ToStmt->setSwitchLoc(Importer.Import(S->getSwitchLoc())); |
| 4773 | // Now we have to re-chain the cases. |
| 4774 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 4775 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 4776 | SC = SC->getNextSwitchCase()) { |
| 4777 | SwitchCase *ToSC = dyn_cast_or_null<SwitchCase>(Importer.Import(SC)); |
| 4778 | if (!ToSC) |
| 4779 | return nullptr; |
| 4780 | if (LastChainedSwitchCase) |
| 4781 | LastChainedSwitchCase->setNextSwitchCase(ToSC); |
| 4782 | else |
| 4783 | ToStmt->setSwitchCaseList(ToSC); |
| 4784 | LastChainedSwitchCase = ToSC; |
| 4785 | } |
| 4786 | return ToStmt; |
| 4787 | } |
| 4788 | |
| 4789 | Stmt *ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 4790 | VarDecl *ToConditionVariable = nullptr; |
| 4791 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4792 | ToConditionVariable = |
| 4793 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4794 | if (!ToConditionVariable) |
| 4795 | return nullptr; |
| 4796 | } |
| 4797 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4798 | if (!ToCondition && S->getCond()) |
| 4799 | return nullptr; |
| 4800 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4801 | if (!ToBody && S->getBody()) |
| 4802 | return nullptr; |
| 4803 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 4804 | return new (Importer.getToContext()) WhileStmt(Importer.getToContext(), |
| 4805 | ToConditionVariable, |
| 4806 | ToCondition, ToBody, |
| 4807 | ToWhileLoc); |
| 4808 | } |
| 4809 | |
| 4810 | Stmt *ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 4811 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4812 | if (!ToBody && S->getBody()) |
| 4813 | return nullptr; |
| 4814 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4815 | if (!ToCondition && S->getCond()) |
| 4816 | return nullptr; |
| 4817 | SourceLocation ToDoLoc = Importer.Import(S->getDoLoc()); |
| 4818 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 4819 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4820 | return new (Importer.getToContext()) DoStmt(ToBody, ToCondition, |
| 4821 | ToDoLoc, ToWhileLoc, |
| 4822 | ToRParenLoc); |
| 4823 | } |
| 4824 | |
| 4825 | Stmt *ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 4826 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4827 | if (!ToInit && S->getInit()) |
| 4828 | return nullptr; |
| 4829 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4830 | if (!ToCondition && S->getCond()) |
| 4831 | return nullptr; |
| 4832 | VarDecl *ToConditionVariable = nullptr; |
| 4833 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4834 | ToConditionVariable = |
| 4835 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4836 | if (!ToConditionVariable) |
| 4837 | return nullptr; |
| 4838 | } |
| 4839 | Expr *ToInc = Importer.Import(S->getInc()); |
| 4840 | if (!ToInc && S->getInc()) |
| 4841 | return nullptr; |
| 4842 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4843 | if (!ToBody && S->getBody()) |
| 4844 | return nullptr; |
| 4845 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 4846 | SourceLocation ToLParenLoc = Importer.Import(S->getLParenLoc()); |
| 4847 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4848 | return new (Importer.getToContext()) ForStmt(Importer.getToContext(), |
| 4849 | ToInit, ToCondition, |
| 4850 | ToConditionVariable, |
| 4851 | ToInc, ToBody, |
| 4852 | ToForLoc, ToLParenLoc, |
| 4853 | ToRParenLoc); |
| 4854 | } |
| 4855 | |
| 4856 | Stmt *ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 4857 | LabelDecl *ToLabel = nullptr; |
| 4858 | if (LabelDecl *FromLabel = S->getLabel()) { |
| 4859 | ToLabel = dyn_cast_or_null<LabelDecl>(Importer.Import(FromLabel)); |
| 4860 | if (!ToLabel) |
| 4861 | return nullptr; |
| 4862 | } |
| 4863 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 4864 | SourceLocation ToLabelLoc = Importer.Import(S->getLabelLoc()); |
| 4865 | return new (Importer.getToContext()) GotoStmt(ToLabel, |
| 4866 | ToGotoLoc, ToLabelLoc); |
| 4867 | } |
| 4868 | |
| 4869 | Stmt *ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 4870 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 4871 | SourceLocation ToStarLoc = Importer.Import(S->getStarLoc()); |
| 4872 | Expr *ToTarget = Importer.Import(S->getTarget()); |
| 4873 | if (!ToTarget && S->getTarget()) |
| 4874 | return nullptr; |
| 4875 | return new (Importer.getToContext()) IndirectGotoStmt(ToGotoLoc, ToStarLoc, |
| 4876 | ToTarget); |
| 4877 | } |
| 4878 | |
| 4879 | Stmt *ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 4880 | SourceLocation ToContinueLoc = Importer.Import(S->getContinueLoc()); |
| 4881 | return new (Importer.getToContext()) ContinueStmt(ToContinueLoc); |
| 4882 | } |
| 4883 | |
| 4884 | Stmt *ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 4885 | SourceLocation ToBreakLoc = Importer.Import(S->getBreakLoc()); |
| 4886 | return new (Importer.getToContext()) BreakStmt(ToBreakLoc); |
| 4887 | } |
| 4888 | |
| 4889 | Stmt *ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 4890 | SourceLocation ToRetLoc = Importer.Import(S->getReturnLoc()); |
| 4891 | Expr *ToRetExpr = Importer.Import(S->getRetValue()); |
| 4892 | if (!ToRetExpr && S->getRetValue()) |
| 4893 | return nullptr; |
| 4894 | VarDecl *NRVOCandidate = const_cast<VarDecl*>(S->getNRVOCandidate()); |
| 4895 | VarDecl *ToNRVOCandidate = cast_or_null<VarDecl>(Importer.Import(NRVOCandidate)); |
| 4896 | if (!ToNRVOCandidate && NRVOCandidate) |
| 4897 | return nullptr; |
| 4898 | return new (Importer.getToContext()) ReturnStmt(ToRetLoc, ToRetExpr, |
| 4899 | ToNRVOCandidate); |
| 4900 | } |
| 4901 | |
| 4902 | Stmt *ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 4903 | SourceLocation ToCatchLoc = Importer.Import(S->getCatchLoc()); |
| 4904 | VarDecl *ToExceptionDecl = nullptr; |
| 4905 | if (VarDecl *FromExceptionDecl = S->getExceptionDecl()) { |
| 4906 | ToExceptionDecl = |
| 4907 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 4908 | if (!ToExceptionDecl) |
| 4909 | return nullptr; |
| 4910 | } |
| 4911 | Stmt *ToHandlerBlock = Importer.Import(S->getHandlerBlock()); |
| 4912 | if (!ToHandlerBlock && S->getHandlerBlock()) |
| 4913 | return nullptr; |
| 4914 | return new (Importer.getToContext()) CXXCatchStmt(ToCatchLoc, |
| 4915 | ToExceptionDecl, |
| 4916 | ToHandlerBlock); |
| 4917 | } |
| 4918 | |
| 4919 | Stmt *ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 4920 | SourceLocation ToTryLoc = Importer.Import(S->getTryLoc()); |
| 4921 | Stmt *ToTryBlock = Importer.Import(S->getTryBlock()); |
| 4922 | if (!ToTryBlock && S->getTryBlock()) |
| 4923 | return nullptr; |
| 4924 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 4925 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 4926 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
| 4927 | if (Stmt *ToHandler = Importer.Import(FromHandler)) |
| 4928 | ToHandlers[HI] = ToHandler; |
| 4929 | else |
| 4930 | return nullptr; |
| 4931 | } |
| 4932 | return CXXTryStmt::Create(Importer.getToContext(), ToTryLoc, ToTryBlock, |
| 4933 | ToHandlers); |
| 4934 | } |
| 4935 | |
| 4936 | Stmt *ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
| 4937 | DeclStmt *ToRange = |
| 4938 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getRangeStmt())); |
| 4939 | if (!ToRange && S->getRangeStmt()) |
| 4940 | return nullptr; |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 4941 | DeclStmt *ToBegin = |
| 4942 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getBeginStmt())); |
| 4943 | if (!ToBegin && S->getBeginStmt()) |
| 4944 | return nullptr; |
| 4945 | DeclStmt *ToEnd = |
| 4946 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getEndStmt())); |
| 4947 | if (!ToEnd && S->getEndStmt()) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4948 | return nullptr; |
| 4949 | Expr *ToCond = Importer.Import(S->getCond()); |
| 4950 | if (!ToCond && S->getCond()) |
| 4951 | return nullptr; |
| 4952 | Expr *ToInc = Importer.Import(S->getInc()); |
| 4953 | if (!ToInc && S->getInc()) |
| 4954 | return nullptr; |
| 4955 | DeclStmt *ToLoopVar = |
| 4956 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getLoopVarStmt())); |
| 4957 | if (!ToLoopVar && S->getLoopVarStmt()) |
| 4958 | return nullptr; |
| 4959 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4960 | if (!ToBody && S->getBody()) |
| 4961 | return nullptr; |
| 4962 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 4963 | SourceLocation ToCoawaitLoc = Importer.Import(S->getCoawaitLoc()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4964 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 4965 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 4966 | return new (Importer.getToContext()) CXXForRangeStmt(ToRange, ToBegin, ToEnd, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4967 | ToCond, ToInc, |
| 4968 | ToLoopVar, ToBody, |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 4969 | ToForLoc, ToCoawaitLoc, |
| 4970 | ToColonLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4971 | } |
| 4972 | |
| 4973 | Stmt *ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 4974 | Stmt *ToElem = Importer.Import(S->getElement()); |
| 4975 | if (!ToElem && S->getElement()) |
| 4976 | return nullptr; |
| 4977 | Expr *ToCollect = Importer.Import(S->getCollection()); |
| 4978 | if (!ToCollect && S->getCollection()) |
| 4979 | return nullptr; |
| 4980 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4981 | if (!ToBody && S->getBody()) |
| 4982 | return nullptr; |
| 4983 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 4984 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4985 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElem, |
| 4986 | ToCollect, |
| 4987 | ToBody, ToForLoc, |
| 4988 | ToRParenLoc); |
| 4989 | } |
| 4990 | |
| 4991 | Stmt *ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 4992 | SourceLocation ToAtCatchLoc = Importer.Import(S->getAtCatchLoc()); |
| 4993 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4994 | VarDecl *ToExceptionDecl = nullptr; |
| 4995 | if (VarDecl *FromExceptionDecl = S->getCatchParamDecl()) { |
| 4996 | ToExceptionDecl = |
| 4997 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 4998 | if (!ToExceptionDecl) |
| 4999 | return nullptr; |
| 5000 | } |
| 5001 | Stmt *ToBody = Importer.Import(S->getCatchBody()); |
| 5002 | if (!ToBody && S->getCatchBody()) |
| 5003 | return nullptr; |
| 5004 | return new (Importer.getToContext()) ObjCAtCatchStmt(ToAtCatchLoc, |
| 5005 | ToRParenLoc, |
| 5006 | ToExceptionDecl, |
| 5007 | ToBody); |
| 5008 | } |
| 5009 | |
| 5010 | Stmt *ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 5011 | SourceLocation ToAtFinallyLoc = Importer.Import(S->getAtFinallyLoc()); |
| 5012 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyBody()); |
| 5013 | if (!ToAtFinallyStmt && S->getFinallyBody()) |
| 5014 | return nullptr; |
| 5015 | return new (Importer.getToContext()) ObjCAtFinallyStmt(ToAtFinallyLoc, |
| 5016 | ToAtFinallyStmt); |
| 5017 | } |
| 5018 | |
| 5019 | Stmt *ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 5020 | SourceLocation ToAtTryLoc = Importer.Import(S->getAtTryLoc()); |
| 5021 | Stmt *ToAtTryStmt = Importer.Import(S->getTryBody()); |
| 5022 | if (!ToAtTryStmt && S->getTryBody()) |
| 5023 | return nullptr; |
| 5024 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 5025 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 5026 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
| 5027 | if (Stmt *ToCatchStmt = Importer.Import(FromCatchStmt)) |
| 5028 | ToCatchStmts[CI] = ToCatchStmt; |
| 5029 | else |
| 5030 | return nullptr; |
| 5031 | } |
| 5032 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyStmt()); |
| 5033 | if (!ToAtFinallyStmt && S->getFinallyStmt()) |
| 5034 | return nullptr; |
| 5035 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
| 5036 | ToAtTryLoc, ToAtTryStmt, |
| 5037 | ToCatchStmts.begin(), ToCatchStmts.size(), |
| 5038 | ToAtFinallyStmt); |
| 5039 | } |
| 5040 | |
| 5041 | Stmt *ASTNodeImporter::VisitObjCAtSynchronizedStmt |
| 5042 | (ObjCAtSynchronizedStmt *S) { |
| 5043 | SourceLocation ToAtSynchronizedLoc = |
| 5044 | Importer.Import(S->getAtSynchronizedLoc()); |
| 5045 | Expr *ToSynchExpr = Importer.Import(S->getSynchExpr()); |
| 5046 | if (!ToSynchExpr && S->getSynchExpr()) |
| 5047 | return nullptr; |
| 5048 | Stmt *ToSynchBody = Importer.Import(S->getSynchBody()); |
| 5049 | if (!ToSynchBody && S->getSynchBody()) |
| 5050 | return nullptr; |
| 5051 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 5052 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 5053 | } |
| 5054 | |
| 5055 | Stmt *ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 5056 | SourceLocation ToAtThrowLoc = Importer.Import(S->getThrowLoc()); |
| 5057 | Expr *ToThrow = Importer.Import(S->getThrowExpr()); |
| 5058 | if (!ToThrow && S->getThrowExpr()) |
| 5059 | return nullptr; |
| 5060 | return new (Importer.getToContext()) ObjCAtThrowStmt(ToAtThrowLoc, ToThrow); |
| 5061 | } |
| 5062 | |
| 5063 | Stmt *ASTNodeImporter::VisitObjCAutoreleasePoolStmt |
| 5064 | (ObjCAutoreleasePoolStmt *S) { |
| 5065 | SourceLocation ToAtLoc = Importer.Import(S->getAtLoc()); |
| 5066 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5067 | if (!ToSubStmt && S->getSubStmt()) |
| 5068 | return nullptr; |
| 5069 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(ToAtLoc, |
| 5070 | ToSubStmt); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5071 | } |
| 5072 | |
| 5073 | //---------------------------------------------------------------------------- |
| 5074 | // Import Expressions |
| 5075 | //---------------------------------------------------------------------------- |
| 5076 | Expr *ASTNodeImporter::VisitExpr(Expr *E) { |
| 5077 | Importer.FromDiag(E->getLocStart(), diag::err_unsupported_ast_node) |
| 5078 | << E->getStmtClassName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5079 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5080 | } |
| 5081 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5082 | Expr *ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 5083 | QualType T = Importer.Import(E->getType()); |
| 5084 | if (T.isNull()) |
| 5085 | return nullptr; |
| 5086 | |
| 5087 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5088 | if (!SubExpr && E->getSubExpr()) |
| 5089 | return nullptr; |
| 5090 | |
| 5091 | TypeSourceInfo *TInfo = Importer.Import(E->getWrittenTypeInfo()); |
| 5092 | if (!TInfo) |
| 5093 | return nullptr; |
| 5094 | |
| 5095 | return new (Importer.getToContext()) VAArgExpr( |
| 5096 | Importer.Import(E->getBuiltinLoc()), SubExpr, TInfo, |
| 5097 | Importer.Import(E->getRParenLoc()), T, E->isMicrosoftABI()); |
| 5098 | } |
| 5099 | |
| 5100 | |
| 5101 | Expr *ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 5102 | QualType T = Importer.Import(E->getType()); |
| 5103 | if (T.isNull()) |
| 5104 | return nullptr; |
| 5105 | |
| 5106 | return new (Importer.getToContext()) GNUNullExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5107 | T, Importer.Import(E->getLocStart())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5108 | } |
| 5109 | |
| 5110 | Expr *ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 5111 | QualType T = Importer.Import(E->getType()); |
| 5112 | if (T.isNull()) |
| 5113 | return nullptr; |
| 5114 | |
| 5115 | StringLiteral *SL = cast_or_null<StringLiteral>( |
| 5116 | Importer.Import(E->getFunctionName())); |
| 5117 | if (!SL && E->getFunctionName()) |
| 5118 | return nullptr; |
| 5119 | |
| 5120 | return new (Importer.getToContext()) PredefinedExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5121 | Importer.Import(E->getLocStart()), T, E->getIdentType(), SL); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5122 | } |
| 5123 | |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5124 | Expr *ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5125 | ValueDecl *ToD = cast_or_null<ValueDecl>(Importer.Import(E->getDecl())); |
| 5126 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5127 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5128 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5129 | NamedDecl *FoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5130 | if (E->getDecl() != E->getFoundDecl()) { |
| 5131 | FoundD = cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl())); |
| 5132 | if (!FoundD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5133 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5134 | } |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5135 | |
| 5136 | QualType T = Importer.Import(E->getType()); |
| 5137 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5138 | return nullptr; |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5139 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5140 | |
| 5141 | TemplateArgumentListInfo ToTAInfo; |
| 5142 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 5143 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5144 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 5145 | return nullptr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5146 | ResInfo = &ToTAInfo; |
| 5147 | } |
| 5148 | |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5149 | DeclRefExpr *DRE = DeclRefExpr::Create(Importer.getToContext(), |
| 5150 | Importer.Import(E->getQualifierLoc()), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 5151 | Importer.Import(E->getTemplateKeywordLoc()), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5152 | ToD, |
Alexey Bataev | 19acc3d | 2015-01-12 10:17:46 +0000 | [diff] [blame] | 5153 | E->refersToEnclosingVariableOrCapture(), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5154 | Importer.Import(E->getLocation()), |
| 5155 | T, E->getValueKind(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5156 | FoundD, ResInfo); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5157 | if (E->hadMultipleCandidates()) |
| 5158 | DRE->setHadMultipleCandidates(true); |
| 5159 | return DRE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5160 | } |
| 5161 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5162 | Expr *ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 5163 | QualType T = Importer.Import(E->getType()); |
| 5164 | if (T.isNull()) |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5165 | return nullptr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5166 | |
| 5167 | return new (Importer.getToContext()) ImplicitValueInitExpr(T); |
| 5168 | } |
| 5169 | |
| 5170 | ASTNodeImporter::Designator |
| 5171 | ASTNodeImporter::ImportDesignator(const Designator &D) { |
| 5172 | if (D.isFieldDesignator()) { |
| 5173 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 5174 | // Caller checks for import error |
| 5175 | return Designator(ToFieldName, Importer.Import(D.getDotLoc()), |
| 5176 | Importer.Import(D.getFieldLoc())); |
| 5177 | } |
| 5178 | if (D.isArrayDesignator()) |
| 5179 | return Designator(D.getFirstExprIndex(), |
| 5180 | Importer.Import(D.getLBracketLoc()), |
| 5181 | Importer.Import(D.getRBracketLoc())); |
| 5182 | |
| 5183 | assert(D.isArrayRangeDesignator()); |
| 5184 | return Designator(D.getFirstExprIndex(), |
| 5185 | Importer.Import(D.getLBracketLoc()), |
| 5186 | Importer.Import(D.getEllipsisLoc()), |
| 5187 | Importer.Import(D.getRBracketLoc())); |
| 5188 | } |
| 5189 | |
| 5190 | |
| 5191 | Expr *ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *DIE) { |
| 5192 | Expr *Init = cast_or_null<Expr>(Importer.Import(DIE->getInit())); |
| 5193 | if (!Init) |
| 5194 | return nullptr; |
| 5195 | |
| 5196 | SmallVector<Expr *, 4> IndexExprs(DIE->getNumSubExprs() - 1); |
| 5197 | // List elements from the second, the first is Init itself |
| 5198 | for (unsigned I = 1, E = DIE->getNumSubExprs(); I < E; I++) { |
| 5199 | if (Expr *Arg = cast_or_null<Expr>(Importer.Import(DIE->getSubExpr(I)))) |
| 5200 | IndexExprs[I - 1] = Arg; |
| 5201 | else |
| 5202 | return nullptr; |
| 5203 | } |
| 5204 | |
| 5205 | SmallVector<Designator, 4> Designators(DIE->size()); |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5206 | llvm::transform(DIE->designators(), Designators.begin(), |
| 5207 | [this](const Designator &D) -> Designator { |
| 5208 | return ImportDesignator(D); |
| 5209 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5210 | |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5211 | for (const Designator &D : DIE->designators()) |
| 5212 | if (D.isFieldDesignator() && !D.getFieldName()) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5213 | return nullptr; |
| 5214 | |
| 5215 | return DesignatedInitExpr::Create( |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5216 | Importer.getToContext(), Designators, |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5217 | IndexExprs, Importer.Import(DIE->getEqualOrColonLoc()), |
| 5218 | DIE->usesGNUSyntax(), Init); |
| 5219 | } |
| 5220 | |
| 5221 | Expr *ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 5222 | QualType T = Importer.Import(E->getType()); |
| 5223 | if (T.isNull()) |
| 5224 | return nullptr; |
| 5225 | |
| 5226 | return new (Importer.getToContext()) |
| 5227 | CXXNullPtrLiteralExpr(T, Importer.Import(E->getLocation())); |
| 5228 | } |
| 5229 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5230 | Expr *ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 5231 | QualType T = Importer.Import(E->getType()); |
| 5232 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5233 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5234 | |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 5235 | return IntegerLiteral::Create(Importer.getToContext(), |
| 5236 | E->getValue(), T, |
| 5237 | Importer.Import(E->getLocation())); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5238 | } |
| 5239 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5240 | Expr *ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 5241 | QualType T = Importer.Import(E->getType()); |
| 5242 | if (T.isNull()) |
| 5243 | return nullptr; |
| 5244 | |
| 5245 | return FloatingLiteral::Create(Importer.getToContext(), |
| 5246 | E->getValue(), E->isExact(), T, |
| 5247 | Importer.Import(E->getLocation())); |
| 5248 | } |
| 5249 | |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 5250 | Expr *ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 5251 | QualType T = Importer.Import(E->getType()); |
| 5252 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5253 | return nullptr; |
| 5254 | |
Douglas Gregor | fb65e59 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 5255 | return new (Importer.getToContext()) CharacterLiteral(E->getValue(), |
| 5256 | E->getKind(), T, |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 5257 | Importer.Import(E->getLocation())); |
| 5258 | } |
| 5259 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5260 | Expr *ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 5261 | QualType T = Importer.Import(E->getType()); |
| 5262 | if (T.isNull()) |
| 5263 | return nullptr; |
| 5264 | |
| 5265 | SmallVector<SourceLocation, 4> Locations(E->getNumConcatenated()); |
| 5266 | ImportArray(E->tokloc_begin(), E->tokloc_end(), Locations.begin()); |
| 5267 | |
| 5268 | return StringLiteral::Create(Importer.getToContext(), E->getBytes(), |
| 5269 | E->getKind(), E->isPascal(), T, |
| 5270 | Locations.data(), Locations.size()); |
| 5271 | } |
| 5272 | |
| 5273 | Expr *ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 5274 | QualType T = Importer.Import(E->getType()); |
| 5275 | if (T.isNull()) |
| 5276 | return nullptr; |
| 5277 | |
| 5278 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeSourceInfo()); |
| 5279 | if (!TInfo) |
| 5280 | return nullptr; |
| 5281 | |
| 5282 | Expr *Init = Importer.Import(E->getInitializer()); |
| 5283 | if (!Init) |
| 5284 | return nullptr; |
| 5285 | |
| 5286 | return new (Importer.getToContext()) CompoundLiteralExpr( |
| 5287 | Importer.Import(E->getLParenLoc()), TInfo, T, E->getValueKind(), |
| 5288 | Init, E->isFileScope()); |
| 5289 | } |
| 5290 | |
| 5291 | Expr *ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 5292 | QualType T = Importer.Import(E->getType()); |
| 5293 | if (T.isNull()) |
| 5294 | return nullptr; |
| 5295 | |
| 5296 | SmallVector<Expr *, 6> Exprs(E->getNumSubExprs()); |
| 5297 | if (ImportArrayChecked( |
| 5298 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 5299 | Exprs.begin())) |
| 5300 | return nullptr; |
| 5301 | |
| 5302 | return new (Importer.getToContext()) AtomicExpr( |
| 5303 | Importer.Import(E->getBuiltinLoc()), Exprs, T, E->getOp(), |
| 5304 | Importer.Import(E->getRParenLoc())); |
| 5305 | } |
| 5306 | |
| 5307 | Expr *ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 5308 | QualType T = Importer.Import(E->getType()); |
| 5309 | if (T.isNull()) |
| 5310 | return nullptr; |
| 5311 | |
| 5312 | LabelDecl *ToLabel = cast_or_null<LabelDecl>(Importer.Import(E->getLabel())); |
| 5313 | if (!ToLabel) |
| 5314 | return nullptr; |
| 5315 | |
| 5316 | return new (Importer.getToContext()) AddrLabelExpr( |
| 5317 | Importer.Import(E->getAmpAmpLoc()), Importer.Import(E->getLabelLoc()), |
| 5318 | ToLabel, T); |
| 5319 | } |
| 5320 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5321 | Expr *ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 5322 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5323 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5324 | return nullptr; |
| 5325 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5326 | return new (Importer.getToContext()) |
| 5327 | ParenExpr(Importer.Import(E->getLParen()), |
| 5328 | Importer.Import(E->getRParen()), |
| 5329 | SubExpr); |
| 5330 | } |
| 5331 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5332 | Expr *ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 5333 | SmallVector<Expr *, 4> Exprs(E->getNumExprs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5334 | if (ImportContainerChecked(E->exprs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5335 | return nullptr; |
| 5336 | |
| 5337 | return new (Importer.getToContext()) ParenListExpr( |
| 5338 | Importer.getToContext(), Importer.Import(E->getLParenLoc()), |
| 5339 | Exprs, Importer.Import(E->getLParenLoc())); |
| 5340 | } |
| 5341 | |
| 5342 | Expr *ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 5343 | QualType T = Importer.Import(E->getType()); |
| 5344 | if (T.isNull()) |
| 5345 | return nullptr; |
| 5346 | |
| 5347 | CompoundStmt *ToSubStmt = cast_or_null<CompoundStmt>( |
| 5348 | Importer.Import(E->getSubStmt())); |
| 5349 | if (!ToSubStmt && E->getSubStmt()) |
| 5350 | return nullptr; |
| 5351 | |
| 5352 | return new (Importer.getToContext()) StmtExpr(ToSubStmt, T, |
| 5353 | Importer.Import(E->getLParenLoc()), Importer.Import(E->getRParenLoc())); |
| 5354 | } |
| 5355 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5356 | Expr *ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 5357 | QualType T = Importer.Import(E->getType()); |
| 5358 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5359 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5360 | |
| 5361 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5362 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5363 | return nullptr; |
| 5364 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 5365 | return new (Importer.getToContext()) UnaryOperator( |
| 5366 | SubExpr, E->getOpcode(), T, E->getValueKind(), E->getObjectKind(), |
| 5367 | Importer.Import(E->getOperatorLoc()), E->canOverflow()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5368 | } |
| 5369 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 5370 | Expr * |
| 5371 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5372 | QualType ResultType = Importer.Import(E->getType()); |
| 5373 | |
| 5374 | if (E->isArgumentType()) { |
| 5375 | TypeSourceInfo *TInfo = Importer.Import(E->getArgumentTypeInfo()); |
| 5376 | if (!TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5377 | return nullptr; |
| 5378 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5379 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 5380 | TInfo, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5381 | Importer.Import(E->getOperatorLoc()), |
| 5382 | Importer.Import(E->getRParenLoc())); |
| 5383 | } |
| 5384 | |
| 5385 | Expr *SubExpr = Importer.Import(E->getArgumentExpr()); |
| 5386 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5387 | return nullptr; |
| 5388 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5389 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 5390 | SubExpr, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5391 | Importer.Import(E->getOperatorLoc()), |
| 5392 | Importer.Import(E->getRParenLoc())); |
| 5393 | } |
| 5394 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5395 | Expr *ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 5396 | QualType T = Importer.Import(E->getType()); |
| 5397 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5398 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5399 | |
| 5400 | Expr *LHS = Importer.Import(E->getLHS()); |
| 5401 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5402 | return nullptr; |
| 5403 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5404 | Expr *RHS = Importer.Import(E->getRHS()); |
| 5405 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5406 | return nullptr; |
| 5407 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5408 | return new (Importer.getToContext()) BinaryOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 5409 | T, E->getValueKind(), |
| 5410 | E->getObjectKind(), |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 5411 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 5412 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5413 | } |
| 5414 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5415 | Expr *ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 5416 | QualType T = Importer.Import(E->getType()); |
| 5417 | if (T.isNull()) |
| 5418 | return nullptr; |
| 5419 | |
| 5420 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 5421 | if (!ToLHS) |
| 5422 | return nullptr; |
| 5423 | |
| 5424 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 5425 | if (!ToRHS) |
| 5426 | return nullptr; |
| 5427 | |
| 5428 | Expr *ToCond = Importer.Import(E->getCond()); |
| 5429 | if (!ToCond) |
| 5430 | return nullptr; |
| 5431 | |
| 5432 | return new (Importer.getToContext()) ConditionalOperator( |
| 5433 | ToCond, Importer.Import(E->getQuestionLoc()), |
| 5434 | ToLHS, Importer.Import(E->getColonLoc()), |
| 5435 | ToRHS, T, E->getValueKind(), E->getObjectKind()); |
| 5436 | } |
| 5437 | |
| 5438 | Expr *ASTNodeImporter::VisitBinaryConditionalOperator( |
| 5439 | BinaryConditionalOperator *E) { |
| 5440 | QualType T = Importer.Import(E->getType()); |
| 5441 | if (T.isNull()) |
| 5442 | return nullptr; |
| 5443 | |
| 5444 | Expr *Common = Importer.Import(E->getCommon()); |
| 5445 | if (!Common) |
| 5446 | return nullptr; |
| 5447 | |
| 5448 | Expr *Cond = Importer.Import(E->getCond()); |
| 5449 | if (!Cond) |
| 5450 | return nullptr; |
| 5451 | |
| 5452 | OpaqueValueExpr *OpaqueValue = cast_or_null<OpaqueValueExpr>( |
| 5453 | Importer.Import(E->getOpaqueValue())); |
| 5454 | if (!OpaqueValue) |
| 5455 | return nullptr; |
| 5456 | |
| 5457 | Expr *TrueExpr = Importer.Import(E->getTrueExpr()); |
| 5458 | if (!TrueExpr) |
| 5459 | return nullptr; |
| 5460 | |
| 5461 | Expr *FalseExpr = Importer.Import(E->getFalseExpr()); |
| 5462 | if (!FalseExpr) |
| 5463 | return nullptr; |
| 5464 | |
| 5465 | return new (Importer.getToContext()) BinaryConditionalOperator( |
| 5466 | Common, OpaqueValue, Cond, TrueExpr, FalseExpr, |
| 5467 | Importer.Import(E->getQuestionLoc()), Importer.Import(E->getColonLoc()), |
| 5468 | T, E->getValueKind(), E->getObjectKind()); |
| 5469 | } |
| 5470 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5471 | Expr *ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 5472 | QualType T = Importer.Import(E->getType()); |
| 5473 | if (T.isNull()) |
| 5474 | return nullptr; |
| 5475 | |
| 5476 | TypeSourceInfo *ToQueried = Importer.Import(E->getQueriedTypeSourceInfo()); |
| 5477 | if (!ToQueried) |
| 5478 | return nullptr; |
| 5479 | |
| 5480 | Expr *Dim = Importer.Import(E->getDimensionExpression()); |
| 5481 | if (!Dim && E->getDimensionExpression()) |
| 5482 | return nullptr; |
| 5483 | |
| 5484 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
| 5485 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 5486 | E->getValue(), Dim, Importer.Import(E->getLocEnd()), T); |
| 5487 | } |
| 5488 | |
| 5489 | Expr *ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 5490 | QualType T = Importer.Import(E->getType()); |
| 5491 | if (T.isNull()) |
| 5492 | return nullptr; |
| 5493 | |
| 5494 | Expr *ToQueried = Importer.Import(E->getQueriedExpression()); |
| 5495 | if (!ToQueried) |
| 5496 | return nullptr; |
| 5497 | |
| 5498 | return new (Importer.getToContext()) ExpressionTraitExpr( |
| 5499 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 5500 | E->getValue(), Importer.Import(E->getLocEnd()), T); |
| 5501 | } |
| 5502 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5503 | Expr *ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 5504 | QualType T = Importer.Import(E->getType()); |
| 5505 | if (T.isNull()) |
| 5506 | return nullptr; |
| 5507 | |
| 5508 | Expr *SourceExpr = Importer.Import(E->getSourceExpr()); |
| 5509 | if (!SourceExpr && E->getSourceExpr()) |
| 5510 | return nullptr; |
| 5511 | |
| 5512 | return new (Importer.getToContext()) OpaqueValueExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5513 | Importer.Import(E->getLocation()), T, E->getValueKind(), |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5514 | E->getObjectKind(), SourceExpr); |
| 5515 | } |
| 5516 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5517 | Expr *ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 5518 | QualType T = Importer.Import(E->getType()); |
| 5519 | if (T.isNull()) |
| 5520 | return nullptr; |
| 5521 | |
| 5522 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 5523 | if (!ToLHS) |
| 5524 | return nullptr; |
| 5525 | |
| 5526 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 5527 | if (!ToRHS) |
| 5528 | return nullptr; |
| 5529 | |
| 5530 | return new (Importer.getToContext()) ArraySubscriptExpr( |
| 5531 | ToLHS, ToRHS, T, E->getValueKind(), E->getObjectKind(), |
| 5532 | Importer.Import(E->getRBracketLoc())); |
| 5533 | } |
| 5534 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5535 | Expr *ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 5536 | QualType T = Importer.Import(E->getType()); |
| 5537 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5538 | return nullptr; |
| 5539 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5540 | QualType CompLHSType = Importer.Import(E->getComputationLHSType()); |
| 5541 | if (CompLHSType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5542 | return nullptr; |
| 5543 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5544 | QualType CompResultType = Importer.Import(E->getComputationResultType()); |
| 5545 | if (CompResultType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5546 | return nullptr; |
| 5547 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5548 | Expr *LHS = Importer.Import(E->getLHS()); |
| 5549 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5550 | return nullptr; |
| 5551 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5552 | Expr *RHS = Importer.Import(E->getRHS()); |
| 5553 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5554 | return nullptr; |
| 5555 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5556 | return new (Importer.getToContext()) |
| 5557 | CompoundAssignOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 5558 | T, E->getValueKind(), |
| 5559 | E->getObjectKind(), |
| 5560 | CompLHSType, CompResultType, |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 5561 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 5562 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5563 | } |
| 5564 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5565 | bool ASTNodeImporter::ImportCastPath(CastExpr *CE, CXXCastPath &Path) { |
| 5566 | for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) { |
| 5567 | if (CXXBaseSpecifier *Spec = Importer.Import(*I)) |
| 5568 | Path.push_back(Spec); |
| 5569 | else |
| 5570 | return true; |
| 5571 | } |
| 5572 | return false; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5573 | } |
| 5574 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5575 | Expr *ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 5576 | QualType T = Importer.Import(E->getType()); |
| 5577 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5578 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5579 | |
| 5580 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5581 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5582 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5583 | |
| 5584 | CXXCastPath BasePath; |
| 5585 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5586 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5587 | |
| 5588 | return ImplicitCastExpr::Create(Importer.getToContext(), T, E->getCastKind(), |
John McCall | 2536c6d | 2010-08-25 10:28:54 +0000 | [diff] [blame] | 5589 | SubExpr, &BasePath, E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5590 | } |
| 5591 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5592 | Expr *ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5593 | QualType T = Importer.Import(E->getType()); |
| 5594 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5595 | return nullptr; |
| 5596 | |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5597 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5598 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5599 | return nullptr; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5600 | |
| 5601 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeInfoAsWritten()); |
| 5602 | if (!TInfo && E->getTypeInfoAsWritten()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5603 | return nullptr; |
| 5604 | |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5605 | CXXCastPath BasePath; |
| 5606 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5607 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5608 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5609 | switch (E->getStmtClass()) { |
| 5610 | case Stmt::CStyleCastExprClass: { |
| 5611 | CStyleCastExpr *CCE = cast<CStyleCastExpr>(E); |
| 5612 | return CStyleCastExpr::Create(Importer.getToContext(), T, |
| 5613 | E->getValueKind(), E->getCastKind(), |
| 5614 | SubExpr, &BasePath, TInfo, |
| 5615 | Importer.Import(CCE->getLParenLoc()), |
| 5616 | Importer.Import(CCE->getRParenLoc())); |
| 5617 | } |
| 5618 | |
| 5619 | case Stmt::CXXFunctionalCastExprClass: { |
| 5620 | CXXFunctionalCastExpr *FCE = cast<CXXFunctionalCastExpr>(E); |
| 5621 | return CXXFunctionalCastExpr::Create(Importer.getToContext(), T, |
| 5622 | E->getValueKind(), TInfo, |
| 5623 | E->getCastKind(), SubExpr, &BasePath, |
| 5624 | Importer.Import(FCE->getLParenLoc()), |
| 5625 | Importer.Import(FCE->getRParenLoc())); |
| 5626 | } |
| 5627 | |
| 5628 | case Stmt::ObjCBridgedCastExprClass: { |
| 5629 | ObjCBridgedCastExpr *OCE = cast<ObjCBridgedCastExpr>(E); |
| 5630 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 5631 | Importer.Import(OCE->getLParenLoc()), OCE->getBridgeKind(), |
| 5632 | E->getCastKind(), Importer.Import(OCE->getBridgeKeywordLoc()), |
| 5633 | TInfo, SubExpr); |
| 5634 | } |
| 5635 | default: |
| 5636 | break; // just fall through |
| 5637 | } |
| 5638 | |
| 5639 | CXXNamedCastExpr *Named = cast<CXXNamedCastExpr>(E); |
| 5640 | SourceLocation ExprLoc = Importer.Import(Named->getOperatorLoc()), |
| 5641 | RParenLoc = Importer.Import(Named->getRParenLoc()); |
| 5642 | SourceRange Brackets = Importer.Import(Named->getAngleBrackets()); |
| 5643 | |
| 5644 | switch (E->getStmtClass()) { |
| 5645 | case Stmt::CXXStaticCastExprClass: |
| 5646 | return CXXStaticCastExpr::Create(Importer.getToContext(), T, |
| 5647 | E->getValueKind(), E->getCastKind(), |
| 5648 | SubExpr, &BasePath, TInfo, |
| 5649 | ExprLoc, RParenLoc, Brackets); |
| 5650 | |
| 5651 | case Stmt::CXXDynamicCastExprClass: |
| 5652 | return CXXDynamicCastExpr::Create(Importer.getToContext(), T, |
| 5653 | E->getValueKind(), E->getCastKind(), |
| 5654 | SubExpr, &BasePath, TInfo, |
| 5655 | ExprLoc, RParenLoc, Brackets); |
| 5656 | |
| 5657 | case Stmt::CXXReinterpretCastExprClass: |
| 5658 | return CXXReinterpretCastExpr::Create(Importer.getToContext(), T, |
| 5659 | E->getValueKind(), E->getCastKind(), |
| 5660 | SubExpr, &BasePath, TInfo, |
| 5661 | ExprLoc, RParenLoc, Brackets); |
| 5662 | |
| 5663 | case Stmt::CXXConstCastExprClass: |
| 5664 | return CXXConstCastExpr::Create(Importer.getToContext(), T, |
| 5665 | E->getValueKind(), SubExpr, TInfo, ExprLoc, |
| 5666 | RParenLoc, Brackets); |
| 5667 | default: |
| 5668 | llvm_unreachable("Cast expression of unsupported type!"); |
| 5669 | return nullptr; |
| 5670 | } |
| 5671 | } |
| 5672 | |
| 5673 | Expr *ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *OE) { |
| 5674 | QualType T = Importer.Import(OE->getType()); |
| 5675 | if (T.isNull()) |
| 5676 | return nullptr; |
| 5677 | |
| 5678 | SmallVector<OffsetOfNode, 4> Nodes; |
| 5679 | for (int I = 0, E = OE->getNumComponents(); I < E; ++I) { |
| 5680 | const OffsetOfNode &Node = OE->getComponent(I); |
| 5681 | |
| 5682 | switch (Node.getKind()) { |
| 5683 | case OffsetOfNode::Array: |
| 5684 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), |
| 5685 | Node.getArrayExprIndex(), |
| 5686 | Importer.Import(Node.getLocEnd()))); |
| 5687 | break; |
| 5688 | |
| 5689 | case OffsetOfNode::Base: { |
| 5690 | CXXBaseSpecifier *BS = Importer.Import(Node.getBase()); |
| 5691 | if (!BS && Node.getBase()) |
| 5692 | return nullptr; |
| 5693 | Nodes.push_back(OffsetOfNode(BS)); |
| 5694 | break; |
| 5695 | } |
| 5696 | case OffsetOfNode::Field: { |
| 5697 | FieldDecl *FD = cast_or_null<FieldDecl>(Importer.Import(Node.getField())); |
| 5698 | if (!FD) |
| 5699 | return nullptr; |
| 5700 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), FD, |
| 5701 | Importer.Import(Node.getLocEnd()))); |
| 5702 | break; |
| 5703 | } |
| 5704 | case OffsetOfNode::Identifier: { |
| 5705 | IdentifierInfo *ToII = Importer.Import(Node.getFieldName()); |
| 5706 | if (!ToII) |
| 5707 | return nullptr; |
| 5708 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), ToII, |
| 5709 | Importer.Import(Node.getLocEnd()))); |
| 5710 | break; |
| 5711 | } |
| 5712 | } |
| 5713 | } |
| 5714 | |
| 5715 | SmallVector<Expr *, 4> Exprs(OE->getNumExpressions()); |
| 5716 | for (int I = 0, E = OE->getNumExpressions(); I < E; ++I) { |
| 5717 | Expr *ToIndexExpr = Importer.Import(OE->getIndexExpr(I)); |
| 5718 | if (!ToIndexExpr) |
| 5719 | return nullptr; |
| 5720 | Exprs[I] = ToIndexExpr; |
| 5721 | } |
| 5722 | |
| 5723 | TypeSourceInfo *TInfo = Importer.Import(OE->getTypeSourceInfo()); |
| 5724 | if (!TInfo && OE->getTypeSourceInfo()) |
| 5725 | return nullptr; |
| 5726 | |
| 5727 | return OffsetOfExpr::Create(Importer.getToContext(), T, |
| 5728 | Importer.Import(OE->getOperatorLoc()), |
| 5729 | TInfo, Nodes, Exprs, |
| 5730 | Importer.Import(OE->getRParenLoc())); |
| 5731 | } |
| 5732 | |
| 5733 | Expr *ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 5734 | QualType T = Importer.Import(E->getType()); |
| 5735 | if (T.isNull()) |
| 5736 | return nullptr; |
| 5737 | |
| 5738 | Expr *Operand = Importer.Import(E->getOperand()); |
| 5739 | if (!Operand) |
| 5740 | return nullptr; |
| 5741 | |
| 5742 | CanThrowResult CanThrow; |
| 5743 | if (E->isValueDependent()) |
| 5744 | CanThrow = CT_Dependent; |
| 5745 | else |
| 5746 | CanThrow = E->getValue() ? CT_Can : CT_Cannot; |
| 5747 | |
| 5748 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 5749 | T, Operand, CanThrow, |
| 5750 | Importer.Import(E->getLocStart()), Importer.Import(E->getLocEnd())); |
| 5751 | } |
| 5752 | |
| 5753 | Expr *ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 5754 | QualType T = Importer.Import(E->getType()); |
| 5755 | if (T.isNull()) |
| 5756 | return nullptr; |
| 5757 | |
| 5758 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5759 | if (!SubExpr && E->getSubExpr()) |
| 5760 | return nullptr; |
| 5761 | |
| 5762 | return new (Importer.getToContext()) CXXThrowExpr( |
| 5763 | SubExpr, T, Importer.Import(E->getThrowLoc()), |
| 5764 | E->isThrownVariableInScope()); |
| 5765 | } |
| 5766 | |
| 5767 | Expr *ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 5768 | ParmVarDecl *Param = cast_or_null<ParmVarDecl>( |
| 5769 | Importer.Import(E->getParam())); |
| 5770 | if (!Param) |
| 5771 | return nullptr; |
| 5772 | |
| 5773 | return CXXDefaultArgExpr::Create( |
| 5774 | Importer.getToContext(), Importer.Import(E->getUsedLocation()), Param); |
| 5775 | } |
| 5776 | |
| 5777 | Expr *ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 5778 | QualType T = Importer.Import(E->getType()); |
| 5779 | if (T.isNull()) |
| 5780 | return nullptr; |
| 5781 | |
| 5782 | TypeSourceInfo *TypeInfo = Importer.Import(E->getTypeSourceInfo()); |
| 5783 | if (!TypeInfo) |
| 5784 | return nullptr; |
| 5785 | |
| 5786 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
| 5787 | T, TypeInfo, Importer.Import(E->getRParenLoc())); |
| 5788 | } |
| 5789 | |
| 5790 | Expr *ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 5791 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5792 | if (!SubExpr) |
| 5793 | return nullptr; |
| 5794 | |
| 5795 | auto *Dtor = cast_or_null<CXXDestructorDecl>( |
| 5796 | Importer.Import(const_cast<CXXDestructorDecl *>( |
| 5797 | E->getTemporary()->getDestructor()))); |
| 5798 | if (!Dtor) |
| 5799 | return nullptr; |
| 5800 | |
| 5801 | ASTContext &ToCtx = Importer.getToContext(); |
| 5802 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, Dtor); |
| 5803 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, SubExpr); |
| 5804 | } |
| 5805 | |
| 5806 | Expr *ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE) { |
| 5807 | QualType T = Importer.Import(CE->getType()); |
| 5808 | if (T.isNull()) |
| 5809 | return nullptr; |
| 5810 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 5811 | |
| 5812 | TypeSourceInfo *TInfo = Importer.Import(CE->getTypeSourceInfo()); |
| 5813 | if (!TInfo) |
| 5814 | return nullptr; |
| 5815 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5816 | SmallVector<Expr *, 8> Args(CE->getNumArgs()); |
| 5817 | if (ImportContainerChecked(CE->arguments(), Args)) |
| 5818 | return nullptr; |
| 5819 | |
| 5820 | auto *Ctor = cast_or_null<CXXConstructorDecl>( |
| 5821 | Importer.Import(CE->getConstructor())); |
| 5822 | if (!Ctor) |
| 5823 | return nullptr; |
| 5824 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 5825 | return new (Importer.getToContext()) CXXTemporaryObjectExpr( |
| 5826 | Importer.getToContext(), Ctor, T, TInfo, Args, |
| 5827 | Importer.Import(CE->getParenOrBraceRange()), CE->hadMultipleCandidates(), |
| 5828 | CE->isListInitialization(), CE->isStdInitListInitialization(), |
| 5829 | CE->requiresZeroInitialization()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5830 | } |
| 5831 | |
| 5832 | Expr * |
| 5833 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
| 5834 | QualType T = Importer.Import(E->getType()); |
| 5835 | if (T.isNull()) |
| 5836 | return nullptr; |
| 5837 | |
| 5838 | Expr *TempE = Importer.Import(E->GetTemporaryExpr()); |
| 5839 | if (!TempE) |
| 5840 | return nullptr; |
| 5841 | |
| 5842 | ValueDecl *ExtendedBy = cast_or_null<ValueDecl>( |
| 5843 | Importer.Import(const_cast<ValueDecl *>(E->getExtendingDecl()))); |
| 5844 | if (!ExtendedBy && E->getExtendingDecl()) |
| 5845 | return nullptr; |
| 5846 | |
| 5847 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
| 5848 | T, TempE, E->isBoundToLvalueReference()); |
| 5849 | |
| 5850 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
| 5851 | ToMTE->setExtendingDecl(ExtendedBy, E->getManglingNumber()); |
| 5852 | return ToMTE; |
| 5853 | } |
| 5854 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 5855 | Expr *ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 5856 | QualType T = Importer.Import(E->getType()); |
| 5857 | if (T.isNull()) |
| 5858 | return nullptr; |
| 5859 | |
| 5860 | Expr *Pattern = Importer.Import(E->getPattern()); |
| 5861 | if (!Pattern) |
| 5862 | return nullptr; |
| 5863 | |
| 5864 | return new (Importer.getToContext()) PackExpansionExpr( |
| 5865 | T, Pattern, Importer.Import(E->getEllipsisLoc()), |
| 5866 | E->getNumExpansions()); |
| 5867 | } |
| 5868 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 5869 | Expr *ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 5870 | auto *Pack = cast_or_null<NamedDecl>(Importer.Import(E->getPack())); |
| 5871 | if (!Pack) |
| 5872 | return nullptr; |
| 5873 | |
| 5874 | Optional<unsigned> Length; |
| 5875 | |
| 5876 | if (!E->isValueDependent()) |
| 5877 | Length = E->getPackLength(); |
| 5878 | |
| 5879 | SmallVector<TemplateArgument, 8> PartialArguments; |
| 5880 | if (E->isPartiallySubstituted()) { |
| 5881 | if (ImportTemplateArguments(E->getPartialArguments().data(), |
| 5882 | E->getPartialArguments().size(), |
| 5883 | PartialArguments)) |
| 5884 | return nullptr; |
| 5885 | } |
| 5886 | |
| 5887 | return SizeOfPackExpr::Create( |
| 5888 | Importer.getToContext(), Importer.Import(E->getOperatorLoc()), Pack, |
| 5889 | Importer.Import(E->getPackLoc()), Importer.Import(E->getRParenLoc()), |
| 5890 | Length, PartialArguments); |
| 5891 | } |
| 5892 | |
| 5893 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5894 | Expr *ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *CE) { |
| 5895 | QualType T = Importer.Import(CE->getType()); |
| 5896 | if (T.isNull()) |
| 5897 | return nullptr; |
| 5898 | |
| 5899 | SmallVector<Expr *, 4> PlacementArgs(CE->getNumPlacementArgs()); |
| 5900 | if (ImportContainerChecked(CE->placement_arguments(), PlacementArgs)) |
| 5901 | return nullptr; |
| 5902 | |
| 5903 | FunctionDecl *OperatorNewDecl = cast_or_null<FunctionDecl>( |
| 5904 | Importer.Import(CE->getOperatorNew())); |
| 5905 | if (!OperatorNewDecl && CE->getOperatorNew()) |
| 5906 | return nullptr; |
| 5907 | |
| 5908 | FunctionDecl *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
| 5909 | Importer.Import(CE->getOperatorDelete())); |
| 5910 | if (!OperatorDeleteDecl && CE->getOperatorDelete()) |
| 5911 | return nullptr; |
| 5912 | |
| 5913 | Expr *ToInit = Importer.Import(CE->getInitializer()); |
| 5914 | if (!ToInit && CE->getInitializer()) |
| 5915 | return nullptr; |
| 5916 | |
| 5917 | TypeSourceInfo *TInfo = Importer.Import(CE->getAllocatedTypeSourceInfo()); |
| 5918 | if (!TInfo) |
| 5919 | return nullptr; |
| 5920 | |
| 5921 | Expr *ToArrSize = Importer.Import(CE->getArraySize()); |
| 5922 | if (!ToArrSize && CE->getArraySize()) |
| 5923 | return nullptr; |
| 5924 | |
| 5925 | return new (Importer.getToContext()) CXXNewExpr( |
| 5926 | Importer.getToContext(), |
| 5927 | CE->isGlobalNew(), |
| 5928 | OperatorNewDecl, OperatorDeleteDecl, |
Richard Smith | b2f0f05 | 2016-10-10 18:54:32 +0000 | [diff] [blame] | 5929 | CE->passAlignment(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5930 | CE->doesUsualArrayDeleteWantSize(), |
| 5931 | PlacementArgs, |
| 5932 | Importer.Import(CE->getTypeIdParens()), |
| 5933 | ToArrSize, CE->getInitializationStyle(), ToInit, T, TInfo, |
| 5934 | Importer.Import(CE->getSourceRange()), |
| 5935 | Importer.Import(CE->getDirectInitRange())); |
| 5936 | } |
| 5937 | |
| 5938 | Expr *ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 5939 | QualType T = Importer.Import(E->getType()); |
| 5940 | if (T.isNull()) |
| 5941 | return nullptr; |
| 5942 | |
| 5943 | FunctionDecl *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
| 5944 | Importer.Import(E->getOperatorDelete())); |
| 5945 | if (!OperatorDeleteDecl && E->getOperatorDelete()) |
| 5946 | return nullptr; |
| 5947 | |
| 5948 | Expr *ToArg = Importer.Import(E->getArgument()); |
| 5949 | if (!ToArg && E->getArgument()) |
| 5950 | return nullptr; |
| 5951 | |
| 5952 | return new (Importer.getToContext()) CXXDeleteExpr( |
| 5953 | T, E->isGlobalDelete(), |
| 5954 | E->isArrayForm(), |
| 5955 | E->isArrayFormAsWritten(), |
| 5956 | E->doesUsualArrayDeleteWantSize(), |
| 5957 | OperatorDeleteDecl, |
| 5958 | ToArg, |
| 5959 | Importer.Import(E->getLocStart())); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5960 | } |
| 5961 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5962 | Expr *ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 5963 | QualType T = Importer.Import(E->getType()); |
| 5964 | if (T.isNull()) |
| 5965 | return nullptr; |
| 5966 | |
| 5967 | CXXConstructorDecl *ToCCD = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 5968 | dyn_cast_or_null<CXXConstructorDecl>(Importer.Import(E->getConstructor())); |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 5969 | if (!ToCCD) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5970 | return nullptr; |
| 5971 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5972 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5973 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5974 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5975 | |
| 5976 | return CXXConstructExpr::Create(Importer.getToContext(), T, |
| 5977 | Importer.Import(E->getLocation()), |
Richard Smith | c83bf82 | 2016-06-10 00:58:19 +0000 | [diff] [blame] | 5978 | ToCCD, E->isElidable(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5979 | ToArgs, E->hadMultipleCandidates(), |
| 5980 | E->isListInitialization(), |
| 5981 | E->isStdInitListInitialization(), |
| 5982 | E->requiresZeroInitialization(), |
| 5983 | E->getConstructionKind(), |
| 5984 | Importer.Import(E->getParenOrBraceRange())); |
| 5985 | } |
| 5986 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5987 | Expr *ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *EWC) { |
| 5988 | Expr *SubExpr = Importer.Import(EWC->getSubExpr()); |
| 5989 | if (!SubExpr && EWC->getSubExpr()) |
| 5990 | return nullptr; |
| 5991 | |
| 5992 | SmallVector<ExprWithCleanups::CleanupObject, 8> Objs(EWC->getNumObjects()); |
| 5993 | for (unsigned I = 0, E = EWC->getNumObjects(); I < E; I++) |
| 5994 | if (ExprWithCleanups::CleanupObject Obj = |
| 5995 | cast_or_null<BlockDecl>(Importer.Import(EWC->getObject(I)))) |
| 5996 | Objs[I] = Obj; |
| 5997 | else |
| 5998 | return nullptr; |
| 5999 | |
| 6000 | return ExprWithCleanups::Create(Importer.getToContext(), |
| 6001 | SubExpr, EWC->cleanupsHaveSideEffects(), |
| 6002 | Objs); |
| 6003 | } |
| 6004 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6005 | Expr *ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 6006 | QualType T = Importer.Import(E->getType()); |
| 6007 | if (T.isNull()) |
| 6008 | return nullptr; |
| 6009 | |
| 6010 | Expr *ToFn = Importer.Import(E->getCallee()); |
| 6011 | if (!ToFn) |
| 6012 | return nullptr; |
| 6013 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6014 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6015 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6016 | return nullptr; |
| 6017 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6018 | return new (Importer.getToContext()) CXXMemberCallExpr( |
| 6019 | Importer.getToContext(), ToFn, ToArgs, T, E->getValueKind(), |
| 6020 | Importer.Import(E->getRParenLoc())); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6021 | } |
| 6022 | |
| 6023 | Expr *ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 6024 | QualType T = Importer.Import(E->getType()); |
| 6025 | if (T.isNull()) |
| 6026 | return nullptr; |
| 6027 | |
| 6028 | return new (Importer.getToContext()) |
| 6029 | CXXThisExpr(Importer.Import(E->getLocation()), T, E->isImplicit()); |
| 6030 | } |
| 6031 | |
| 6032 | Expr *ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 6033 | QualType T = Importer.Import(E->getType()); |
| 6034 | if (T.isNull()) |
| 6035 | return nullptr; |
| 6036 | |
| 6037 | return new (Importer.getToContext()) |
| 6038 | CXXBoolLiteralExpr(E->getValue(), T, Importer.Import(E->getLocation())); |
| 6039 | } |
| 6040 | |
| 6041 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6042 | Expr *ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 6043 | QualType T = Importer.Import(E->getType()); |
| 6044 | if (T.isNull()) |
| 6045 | return nullptr; |
| 6046 | |
| 6047 | Expr *ToBase = Importer.Import(E->getBase()); |
| 6048 | if (!ToBase && E->getBase()) |
| 6049 | return nullptr; |
| 6050 | |
| 6051 | ValueDecl *ToMember = dyn_cast<ValueDecl>(Importer.Import(E->getMemberDecl())); |
| 6052 | if (!ToMember && E->getMemberDecl()) |
| 6053 | return nullptr; |
| 6054 | |
| 6055 | DeclAccessPair ToFoundDecl = DeclAccessPair::make( |
| 6056 | dyn_cast<NamedDecl>(Importer.Import(E->getFoundDecl().getDecl())), |
| 6057 | E->getFoundDecl().getAccess()); |
| 6058 | |
| 6059 | DeclarationNameInfo ToMemberNameInfo( |
| 6060 | Importer.Import(E->getMemberNameInfo().getName()), |
| 6061 | Importer.Import(E->getMemberNameInfo().getLoc())); |
| 6062 | |
| 6063 | if (E->hasExplicitTemplateArgs()) { |
| 6064 | return nullptr; // FIXME: handle template arguments |
| 6065 | } |
| 6066 | |
| 6067 | return MemberExpr::Create(Importer.getToContext(), ToBase, |
| 6068 | E->isArrow(), |
| 6069 | Importer.Import(E->getOperatorLoc()), |
| 6070 | Importer.Import(E->getQualifierLoc()), |
| 6071 | Importer.Import(E->getTemplateKeywordLoc()), |
| 6072 | ToMember, ToFoundDecl, ToMemberNameInfo, |
| 6073 | nullptr, T, E->getValueKind(), |
| 6074 | E->getObjectKind()); |
| 6075 | } |
| 6076 | |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 6077 | Expr *ASTNodeImporter::VisitCXXPseudoDestructorExpr( |
| 6078 | CXXPseudoDestructorExpr *E) { |
| 6079 | |
| 6080 | Expr *BaseE = Importer.Import(E->getBase()); |
| 6081 | if (!BaseE) |
| 6082 | return nullptr; |
| 6083 | |
| 6084 | TypeSourceInfo *ScopeInfo = Importer.Import(E->getScopeTypeInfo()); |
| 6085 | if (!ScopeInfo && E->getScopeTypeInfo()) |
| 6086 | return nullptr; |
| 6087 | |
| 6088 | PseudoDestructorTypeStorage Storage; |
| 6089 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 6090 | IdentifierInfo *ToII = Importer.Import(FromII); |
| 6091 | if (!ToII) |
| 6092 | return nullptr; |
| 6093 | Storage = PseudoDestructorTypeStorage( |
| 6094 | ToII, Importer.Import(E->getDestroyedTypeLoc())); |
| 6095 | } else { |
| 6096 | TypeSourceInfo *TI = Importer.Import(E->getDestroyedTypeInfo()); |
| 6097 | if (!TI) |
| 6098 | return nullptr; |
| 6099 | Storage = PseudoDestructorTypeStorage(TI); |
| 6100 | } |
| 6101 | |
| 6102 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
| 6103 | Importer.getToContext(), BaseE, E->isArrow(), |
| 6104 | Importer.Import(E->getOperatorLoc()), |
| 6105 | Importer.Import(E->getQualifierLoc()), |
| 6106 | ScopeInfo, Importer.Import(E->getColonColonLoc()), |
| 6107 | Importer.Import(E->getTildeLoc()), Storage); |
| 6108 | } |
| 6109 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6110 | Expr *ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
| 6111 | CXXDependentScopeMemberExpr *E) { |
| 6112 | Expr *Base = nullptr; |
| 6113 | if (!E->isImplicitAccess()) { |
| 6114 | Base = Importer.Import(E->getBase()); |
| 6115 | if (!Base) |
| 6116 | return nullptr; |
| 6117 | } |
| 6118 | |
| 6119 | QualType BaseType = Importer.Import(E->getBaseType()); |
| 6120 | if (BaseType.isNull()) |
| 6121 | return nullptr; |
| 6122 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6123 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6124 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6125 | if (ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6126 | E->template_arguments(), ToTAInfo)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6127 | return nullptr; |
| 6128 | ResInfo = &ToTAInfo; |
| 6129 | } |
| 6130 | |
| 6131 | DeclarationName Name = Importer.Import(E->getMember()); |
| 6132 | if (!E->getMember().isEmpty() && Name.isEmpty()) |
| 6133 | return nullptr; |
| 6134 | |
| 6135 | DeclarationNameInfo MemberNameInfo(Name, Importer.Import(E->getMemberLoc())); |
| 6136 | // Import additional name location/type info. |
| 6137 | ImportDeclarationNameLoc(E->getMemberNameInfo(), MemberNameInfo); |
| 6138 | auto ToFQ = Importer.Import(E->getFirstQualifierFoundInScope()); |
| 6139 | if (!ToFQ && E->getFirstQualifierFoundInScope()) |
| 6140 | return nullptr; |
| 6141 | |
| 6142 | return CXXDependentScopeMemberExpr::Create( |
| 6143 | Importer.getToContext(), Base, BaseType, E->isArrow(), |
| 6144 | Importer.Import(E->getOperatorLoc()), |
| 6145 | Importer.Import(E->getQualifierLoc()), |
| 6146 | Importer.Import(E->getTemplateKeywordLoc()), |
| 6147 | cast_or_null<NamedDecl>(ToFQ), MemberNameInfo, ResInfo); |
| 6148 | } |
| 6149 | |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6150 | Expr *ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 6151 | CXXUnresolvedConstructExpr *CE) { |
| 6152 | |
| 6153 | unsigned NumArgs = CE->arg_size(); |
| 6154 | |
| 6155 | llvm::SmallVector<Expr *, 8> ToArgs(NumArgs); |
| 6156 | if (ImportArrayChecked(CE->arg_begin(), CE->arg_end(), ToArgs.begin())) |
| 6157 | return nullptr; |
| 6158 | |
| 6159 | return CXXUnresolvedConstructExpr::Create( |
| 6160 | Importer.getToContext(), Importer.Import(CE->getTypeSourceInfo()), |
| 6161 | Importer.Import(CE->getLParenLoc()), llvm::makeArrayRef(ToArgs), |
| 6162 | Importer.Import(CE->getRParenLoc())); |
| 6163 | } |
| 6164 | |
| 6165 | Expr *ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
| 6166 | CXXRecordDecl *NamingClass = |
| 6167 | cast_or_null<CXXRecordDecl>(Importer.Import(E->getNamingClass())); |
| 6168 | if (E->getNamingClass() && !NamingClass) |
| 6169 | return nullptr; |
| 6170 | |
| 6171 | DeclarationName Name = Importer.Import(E->getName()); |
| 6172 | if (E->getName() && !Name) |
| 6173 | return nullptr; |
| 6174 | |
| 6175 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getNameLoc())); |
| 6176 | // Import additional name location/type info. |
| 6177 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6178 | |
| 6179 | UnresolvedSet<8> ToDecls; |
| 6180 | for (Decl *D : E->decls()) { |
| 6181 | if (NamedDecl *To = cast_or_null<NamedDecl>(Importer.Import(D))) |
| 6182 | ToDecls.addDecl(To); |
| 6183 | else |
| 6184 | return nullptr; |
| 6185 | } |
| 6186 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6187 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6188 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6189 | if (ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6190 | E->template_arguments(), ToTAInfo)) |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6191 | return nullptr; |
| 6192 | ResInfo = &ToTAInfo; |
| 6193 | } |
| 6194 | |
| 6195 | if (ResInfo || E->getTemplateKeywordLoc().isValid()) |
| 6196 | return UnresolvedLookupExpr::Create( |
| 6197 | Importer.getToContext(), NamingClass, |
| 6198 | Importer.Import(E->getQualifierLoc()), |
| 6199 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, E->requiresADL(), |
| 6200 | ResInfo, ToDecls.begin(), ToDecls.end()); |
| 6201 | |
| 6202 | return UnresolvedLookupExpr::Create( |
| 6203 | Importer.getToContext(), NamingClass, |
| 6204 | Importer.Import(E->getQualifierLoc()), NameInfo, E->requiresADL(), |
| 6205 | E->isOverloaded(), ToDecls.begin(), ToDecls.end()); |
| 6206 | } |
| 6207 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6208 | Expr *ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 6209 | QualType T = Importer.Import(E->getType()); |
| 6210 | if (T.isNull()) |
| 6211 | return nullptr; |
| 6212 | |
| 6213 | Expr *ToCallee = Importer.Import(E->getCallee()); |
| 6214 | if (!ToCallee && E->getCallee()) |
| 6215 | return nullptr; |
| 6216 | |
| 6217 | unsigned NumArgs = E->getNumArgs(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6218 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6219 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
| 6220 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6221 | |
| 6222 | Expr **ToArgs_Copied = new (Importer.getToContext()) |
| 6223 | Expr*[NumArgs]; |
| 6224 | |
| 6225 | for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) |
| 6226 | ToArgs_Copied[ai] = ToArgs[ai]; |
| 6227 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6228 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
| 6229 | return new (Importer.getToContext()) CXXOperatorCallExpr( |
| 6230 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, T, |
| 6231 | OCE->getValueKind(), Importer.Import(OCE->getRParenLoc()), |
| 6232 | OCE->getFPFeatures()); |
| 6233 | } |
| 6234 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6235 | return new (Importer.getToContext()) |
| 6236 | CallExpr(Importer.getToContext(), ToCallee, |
Craig Topper | c005cc0 | 2015-09-27 03:44:08 +0000 | [diff] [blame] | 6237 | llvm::makeArrayRef(ToArgs_Copied, NumArgs), T, E->getValueKind(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6238 | Importer.Import(E->getRParenLoc())); |
| 6239 | } |
| 6240 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6241 | Optional<LambdaCapture> |
| 6242 | ASTNodeImporter::ImportLambdaCapture(const LambdaCapture &From) { |
| 6243 | VarDecl *Var = nullptr; |
| 6244 | if (From.capturesVariable()) { |
| 6245 | Var = cast_or_null<VarDecl>(Importer.Import(From.getCapturedVar())); |
| 6246 | if (!Var) |
| 6247 | return None; |
| 6248 | } |
| 6249 | |
| 6250 | return LambdaCapture(Importer.Import(From.getLocation()), From.isImplicit(), |
| 6251 | From.getCaptureKind(), Var, |
| 6252 | From.isPackExpansion() |
| 6253 | ? Importer.Import(From.getEllipsisLoc()) |
| 6254 | : SourceLocation()); |
| 6255 | } |
| 6256 | |
| 6257 | Expr *ASTNodeImporter::VisitLambdaExpr(LambdaExpr *LE) { |
| 6258 | CXXRecordDecl *FromClass = LE->getLambdaClass(); |
| 6259 | auto *ToClass = dyn_cast_or_null<CXXRecordDecl>(Importer.Import(FromClass)); |
| 6260 | if (!ToClass) |
| 6261 | return nullptr; |
| 6262 | |
| 6263 | // NOTE: lambda classes are created with BeingDefined flag set up. |
| 6264 | // It means that ImportDefinition doesn't work for them and we should fill it |
| 6265 | // manually. |
| 6266 | if (ToClass->isBeingDefined()) { |
| 6267 | for (auto FromField : FromClass->fields()) { |
| 6268 | auto *ToField = cast_or_null<FieldDecl>(Importer.Import(FromField)); |
| 6269 | if (!ToField) |
| 6270 | return nullptr; |
| 6271 | } |
| 6272 | } |
| 6273 | |
| 6274 | auto *ToCallOp = dyn_cast_or_null<CXXMethodDecl>( |
| 6275 | Importer.Import(LE->getCallOperator())); |
| 6276 | if (!ToCallOp) |
| 6277 | return nullptr; |
| 6278 | |
| 6279 | ToClass->completeDefinition(); |
| 6280 | |
| 6281 | unsigned NumCaptures = LE->capture_size(); |
| 6282 | SmallVector<LambdaCapture, 8> Captures; |
| 6283 | Captures.reserve(NumCaptures); |
| 6284 | for (const auto &FromCapture : LE->captures()) { |
| 6285 | if (auto ToCapture = ImportLambdaCapture(FromCapture)) |
| 6286 | Captures.push_back(*ToCapture); |
| 6287 | else |
| 6288 | return nullptr; |
| 6289 | } |
| 6290 | |
| 6291 | SmallVector<Expr *, 8> InitCaptures(NumCaptures); |
| 6292 | if (ImportContainerChecked(LE->capture_inits(), InitCaptures)) |
| 6293 | return nullptr; |
| 6294 | |
| 6295 | return LambdaExpr::Create(Importer.getToContext(), ToClass, |
| 6296 | Importer.Import(LE->getIntroducerRange()), |
| 6297 | LE->getCaptureDefault(), |
| 6298 | Importer.Import(LE->getCaptureDefaultLoc()), |
| 6299 | Captures, |
| 6300 | LE->hasExplicitParameters(), |
| 6301 | LE->hasExplicitResultType(), |
| 6302 | InitCaptures, |
| 6303 | Importer.Import(LE->getLocEnd()), |
| 6304 | LE->containsUnexpandedParameterPack()); |
| 6305 | } |
| 6306 | |
| 6307 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6308 | Expr *ASTNodeImporter::VisitInitListExpr(InitListExpr *ILE) { |
| 6309 | QualType T = Importer.Import(ILE->getType()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6310 | if (T.isNull()) |
| 6311 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6312 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6313 | llvm::SmallVector<Expr *, 4> Exprs(ILE->getNumInits()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6314 | if (ImportContainerChecked(ILE->inits(), Exprs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6315 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6316 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6317 | ASTContext &ToCtx = Importer.getToContext(); |
| 6318 | InitListExpr *To = new (ToCtx) InitListExpr( |
| 6319 | ToCtx, Importer.Import(ILE->getLBraceLoc()), |
| 6320 | Exprs, Importer.Import(ILE->getLBraceLoc())); |
| 6321 | To->setType(T); |
| 6322 | |
| 6323 | if (ILE->hasArrayFiller()) { |
| 6324 | Expr *Filler = Importer.Import(ILE->getArrayFiller()); |
| 6325 | if (!Filler) |
| 6326 | return nullptr; |
| 6327 | To->setArrayFiller(Filler); |
| 6328 | } |
| 6329 | |
| 6330 | if (FieldDecl *FromFD = ILE->getInitializedFieldInUnion()) { |
| 6331 | FieldDecl *ToFD = cast_or_null<FieldDecl>(Importer.Import(FromFD)); |
| 6332 | if (!ToFD) |
| 6333 | return nullptr; |
| 6334 | To->setInitializedFieldInUnion(ToFD); |
| 6335 | } |
| 6336 | |
| 6337 | if (InitListExpr *SyntForm = ILE->getSyntacticForm()) { |
| 6338 | InitListExpr *ToSyntForm = cast_or_null<InitListExpr>( |
| 6339 | Importer.Import(SyntForm)); |
| 6340 | if (!ToSyntForm) |
| 6341 | return nullptr; |
| 6342 | To->setSyntacticForm(ToSyntForm); |
| 6343 | } |
| 6344 | |
| 6345 | To->sawArrayRangeDesignator(ILE->hadArrayRangeDesignator()); |
| 6346 | To->setValueDependent(ILE->isValueDependent()); |
| 6347 | To->setInstantiationDependent(ILE->isInstantiationDependent()); |
| 6348 | |
| 6349 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6350 | } |
| 6351 | |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 6352 | Expr *ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 6353 | QualType ToType = Importer.Import(E->getType()); |
| 6354 | if (ToType.isNull()) |
| 6355 | return nullptr; |
| 6356 | |
| 6357 | Expr *ToCommon = Importer.Import(E->getCommonExpr()); |
| 6358 | if (!ToCommon && E->getCommonExpr()) |
| 6359 | return nullptr; |
| 6360 | |
| 6361 | Expr *ToSubExpr = Importer.Import(E->getSubExpr()); |
| 6362 | if (!ToSubExpr && E->getSubExpr()) |
| 6363 | return nullptr; |
| 6364 | |
| 6365 | return new (Importer.getToContext()) |
| 6366 | ArrayInitLoopExpr(ToType, ToCommon, ToSubExpr); |
| 6367 | } |
| 6368 | |
| 6369 | Expr *ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 6370 | QualType ToType = Importer.Import(E->getType()); |
| 6371 | if (ToType.isNull()) |
| 6372 | return nullptr; |
| 6373 | return new (Importer.getToContext()) ArrayInitIndexExpr(ToType); |
| 6374 | } |
| 6375 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6376 | Expr *ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) { |
| 6377 | FieldDecl *ToField = llvm::dyn_cast_or_null<FieldDecl>( |
| 6378 | Importer.Import(DIE->getField())); |
| 6379 | if (!ToField && DIE->getField()) |
| 6380 | return nullptr; |
| 6381 | |
| 6382 | return CXXDefaultInitExpr::Create( |
| 6383 | Importer.getToContext(), Importer.Import(DIE->getLocStart()), ToField); |
| 6384 | } |
| 6385 | |
| 6386 | Expr *ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 6387 | QualType ToType = Importer.Import(E->getType()); |
| 6388 | if (ToType.isNull() && !E->getType().isNull()) |
| 6389 | return nullptr; |
| 6390 | ExprValueKind VK = E->getValueKind(); |
| 6391 | CastKind CK = E->getCastKind(); |
| 6392 | Expr *ToOp = Importer.Import(E->getSubExpr()); |
| 6393 | if (!ToOp && E->getSubExpr()) |
| 6394 | return nullptr; |
| 6395 | CXXCastPath BasePath; |
| 6396 | if (ImportCastPath(E, BasePath)) |
| 6397 | return nullptr; |
| 6398 | TypeSourceInfo *ToWritten = Importer.Import(E->getTypeInfoAsWritten()); |
| 6399 | SourceLocation ToOperatorLoc = Importer.Import(E->getOperatorLoc()); |
| 6400 | SourceLocation ToRParenLoc = Importer.Import(E->getRParenLoc()); |
| 6401 | SourceRange ToAngleBrackets = Importer.Import(E->getAngleBrackets()); |
| 6402 | |
| 6403 | if (isa<CXXStaticCastExpr>(E)) { |
| 6404 | return CXXStaticCastExpr::Create( |
| 6405 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6406 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6407 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 6408 | return CXXDynamicCastExpr::Create( |
| 6409 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6410 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6411 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 6412 | return CXXReinterpretCastExpr::Create( |
| 6413 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6414 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6415 | } else { |
| 6416 | return nullptr; |
| 6417 | } |
| 6418 | } |
| 6419 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6420 | |
| 6421 | Expr *ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
| 6422 | SubstNonTypeTemplateParmExpr *E) { |
| 6423 | QualType T = Importer.Import(E->getType()); |
| 6424 | if (T.isNull()) |
| 6425 | return nullptr; |
| 6426 | |
| 6427 | NonTypeTemplateParmDecl *Param = cast_or_null<NonTypeTemplateParmDecl>( |
| 6428 | Importer.Import(E->getParameter())); |
| 6429 | if (!Param) |
| 6430 | return nullptr; |
| 6431 | |
| 6432 | Expr *Replacement = Importer.Import(E->getReplacement()); |
| 6433 | if (!Replacement) |
| 6434 | return nullptr; |
| 6435 | |
| 6436 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
| 6437 | T, E->getValueKind(), Importer.Import(E->getExprLoc()), Param, |
| 6438 | Replacement); |
| 6439 | } |
| 6440 | |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 6441 | Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 6442 | QualType ToType = Importer.Import(E->getType()); |
| 6443 | if (ToType.isNull()) |
| 6444 | return nullptr; |
| 6445 | |
| 6446 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
| 6447 | if (ImportContainerChecked(E->getArgs(), ToArgs)) |
| 6448 | return nullptr; |
| 6449 | |
| 6450 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 6451 | // Value is always false. |
| 6452 | bool ToValue = false; |
| 6453 | if (!E->isValueDependent()) |
| 6454 | ToValue = E->getValue(); |
| 6455 | |
| 6456 | return TypeTraitExpr::Create( |
| 6457 | Importer.getToContext(), ToType, Importer.Import(E->getLocStart()), |
| 6458 | E->getTrait(), ToArgs, Importer.Import(E->getLocEnd()), ToValue); |
| 6459 | } |
| 6460 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6461 | Expr *ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 6462 | QualType ToType = Importer.Import(E->getType()); |
| 6463 | if (ToType.isNull()) |
| 6464 | return nullptr; |
| 6465 | |
| 6466 | if (E->isTypeOperand()) { |
| 6467 | TypeSourceInfo *TSI = Importer.Import(E->getTypeOperandSourceInfo()); |
| 6468 | if (!TSI) |
| 6469 | return nullptr; |
| 6470 | |
| 6471 | return new (Importer.getToContext()) |
| 6472 | CXXTypeidExpr(ToType, TSI, Importer.Import(E->getSourceRange())); |
| 6473 | } |
| 6474 | |
| 6475 | Expr *Op = Importer.Import(E->getExprOperand()); |
| 6476 | if (!Op) |
| 6477 | return nullptr; |
| 6478 | |
| 6479 | return new (Importer.getToContext()) |
| 6480 | CXXTypeidExpr(ToType, Op, Importer.Import(E->getSourceRange())); |
| 6481 | } |
| 6482 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 6483 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 6484 | CXXMethodDecl *FromMethod) { |
| 6485 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) |
| 6486 | ToMethod->addOverriddenMethod( |
| 6487 | cast<CXXMethodDecl>(Importer.Import(const_cast<CXXMethodDecl*>( |
| 6488 | FromOverriddenMethod)))); |
| 6489 | } |
| 6490 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6491 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 6492 | ASTContext &FromContext, FileManager &FromFileManager, |
| 6493 | bool MinimalImport) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6494 | : ToContext(ToContext), FromContext(FromContext), |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 6495 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 6496 | Minimal(MinimalImport), LastDiagFromFrom(false) |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 6497 | { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6498 | ImportedDecls[FromContext.getTranslationUnitDecl()] |
| 6499 | = ToContext.getTranslationUnitDecl(); |
| 6500 | } |
| 6501 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 6502 | ASTImporter::~ASTImporter() { } |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6503 | |
| 6504 | QualType ASTImporter::Import(QualType FromT) { |
| 6505 | if (FromT.isNull()) |
| 6506 | return QualType(); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6507 | |
| 6508 | const Type *fromTy = FromT.getTypePtr(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6509 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6510 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6511 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
| 6512 | = ImportedTypes.find(fromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6513 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6514 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6515 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6516 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6517 | ASTNodeImporter Importer(*this); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6518 | QualType ToT = Importer.Visit(fromTy); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6519 | if (ToT.isNull()) |
| 6520 | return ToT; |
| 6521 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6522 | // Record the imported type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6523 | ImportedTypes[fromTy] = ToT.getTypePtr(); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6524 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6525 | return ToContext.getQualifiedType(ToT, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6526 | } |
| 6527 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6528 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 6529 | if (!FromTSI) |
| 6530 | return FromTSI; |
| 6531 | |
| 6532 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 6533 | // 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] | 6534 | QualType T = Import(FromTSI->getType()); |
| 6535 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6536 | return nullptr; |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 6537 | |
| 6538 | return ToContext.getTrivialTypeSourceInfo(T, |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 6539 | Import(FromTSI->getTypeLoc().getLocStart())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6540 | } |
| 6541 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6542 | Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) { |
| 6543 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
| 6544 | if (Pos != ImportedDecls.end()) { |
| 6545 | Decl *ToD = Pos->second; |
| 6546 | ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD); |
| 6547 | return ToD; |
| 6548 | } else { |
| 6549 | return nullptr; |
| 6550 | } |
| 6551 | } |
| 6552 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6553 | Decl *ASTImporter::Import(Decl *FromD) { |
| 6554 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6555 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6556 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6557 | ASTNodeImporter Importer(*this); |
| 6558 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6559 | // Check whether we've already imported this declaration. |
| 6560 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6561 | if (Pos != ImportedDecls.end()) { |
| 6562 | Decl *ToD = Pos->second; |
| 6563 | Importer.ImportDefinitionIfNeeded(FromD, ToD); |
| 6564 | return ToD; |
| 6565 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6566 | |
| 6567 | // Import the type |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6568 | Decl *ToD = Importer.Visit(FromD); |
| 6569 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6570 | return nullptr; |
| 6571 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6572 | // Record the imported declaration. |
| 6573 | ImportedDecls[FromD] = ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6574 | |
| 6575 | if (TagDecl *FromTag = dyn_cast<TagDecl>(FromD)) { |
| 6576 | // Keep track of anonymous tags that have an associated typedef. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 6577 | if (FromTag->getTypedefNameForAnonDecl()) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6578 | AnonTagsWithPendingTypedefs.push_back(FromTag); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 6579 | } else if (TypedefNameDecl *FromTypedef = dyn_cast<TypedefNameDecl>(FromD)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6580 | // When we've finished transforming a typedef, see whether it was the |
| 6581 | // typedef for an anonymous tag. |
Craig Topper | 2341c0d | 2013-07-04 03:08:24 +0000 | [diff] [blame] | 6582 | for (SmallVectorImpl<TagDecl *>::iterator |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6583 | FromTag = AnonTagsWithPendingTypedefs.begin(), |
| 6584 | FromTagEnd = AnonTagsWithPendingTypedefs.end(); |
| 6585 | FromTag != FromTagEnd; ++FromTag) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 6586 | if ((*FromTag)->getTypedefNameForAnonDecl() == FromTypedef) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6587 | if (TagDecl *ToTag = cast_or_null<TagDecl>(Import(*FromTag))) { |
| 6588 | // We found the typedef for an anonymous tag; link them. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 6589 | ToTag->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(ToD)); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6590 | AnonTagsWithPendingTypedefs.erase(FromTag); |
| 6591 | break; |
| 6592 | } |
| 6593 | } |
| 6594 | } |
| 6595 | } |
| 6596 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6597 | return ToD; |
| 6598 | } |
| 6599 | |
| 6600 | DeclContext *ASTImporter::ImportContext(DeclContext *FromDC) { |
| 6601 | if (!FromDC) |
| 6602 | return FromDC; |
| 6603 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 6604 | DeclContext *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6605 | if (!ToDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6606 | return nullptr; |
| 6607 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6608 | // When we're using a record/enum/Objective-C class/protocol as a context, we |
| 6609 | // need it to have a definition. |
| 6610 | if (RecordDecl *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
Douglas Gregor | 63db971 | 2012-01-25 01:13:20 +0000 | [diff] [blame] | 6611 | RecordDecl *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6612 | if (ToRecord->isCompleteDefinition()) { |
| 6613 | // Do nothing. |
| 6614 | } else if (FromRecord->isCompleteDefinition()) { |
| 6615 | ASTNodeImporter(*this).ImportDefinition(FromRecord, ToRecord, |
| 6616 | ASTNodeImporter::IDK_Basic); |
| 6617 | } else { |
| 6618 | CompleteDecl(ToRecord); |
| 6619 | } |
| 6620 | } else if (EnumDecl *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 6621 | EnumDecl *FromEnum = cast<EnumDecl>(FromDC); |
| 6622 | if (ToEnum->isCompleteDefinition()) { |
| 6623 | // Do nothing. |
| 6624 | } else if (FromEnum->isCompleteDefinition()) { |
| 6625 | ASTNodeImporter(*this).ImportDefinition(FromEnum, ToEnum, |
| 6626 | ASTNodeImporter::IDK_Basic); |
| 6627 | } else { |
| 6628 | CompleteDecl(ToEnum); |
| 6629 | } |
| 6630 | } else if (ObjCInterfaceDecl *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 6631 | ObjCInterfaceDecl *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
| 6632 | if (ToClass->getDefinition()) { |
| 6633 | // Do nothing. |
| 6634 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
| 6635 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToClass, |
| 6636 | ASTNodeImporter::IDK_Basic); |
| 6637 | } else { |
| 6638 | CompleteDecl(ToClass); |
| 6639 | } |
| 6640 | } else if (ObjCProtocolDecl *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 6641 | ObjCProtocolDecl *FromProto = cast<ObjCProtocolDecl>(FromDC); |
| 6642 | if (ToProto->getDefinition()) { |
| 6643 | // Do nothing. |
| 6644 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
| 6645 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToProto, |
| 6646 | ASTNodeImporter::IDK_Basic); |
| 6647 | } else { |
| 6648 | CompleteDecl(ToProto); |
| 6649 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 6650 | } |
| 6651 | |
| 6652 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6653 | } |
| 6654 | |
| 6655 | Expr *ASTImporter::Import(Expr *FromE) { |
| 6656 | if (!FromE) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6657 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6658 | |
| 6659 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); |
| 6660 | } |
| 6661 | |
| 6662 | Stmt *ASTImporter::Import(Stmt *FromS) { |
| 6663 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6664 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6665 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6666 | // Check whether we've already imported this declaration. |
| 6667 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 6668 | if (Pos != ImportedStmts.end()) |
| 6669 | return Pos->second; |
| 6670 | |
| 6671 | // Import the type |
| 6672 | ASTNodeImporter Importer(*this); |
| 6673 | Stmt *ToS = Importer.Visit(FromS); |
| 6674 | if (!ToS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6675 | return nullptr; |
| 6676 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6677 | // Record the imported declaration. |
| 6678 | ImportedStmts[FromS] = ToS; |
| 6679 | return ToS; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6680 | } |
| 6681 | |
| 6682 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| 6683 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6684 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6685 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6686 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); |
| 6687 | |
| 6688 | switch (FromNNS->getKind()) { |
| 6689 | case NestedNameSpecifier::Identifier: |
| 6690 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { |
| 6691 | return NestedNameSpecifier::Create(ToContext, prefix, II); |
| 6692 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6693 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6694 | |
| 6695 | case NestedNameSpecifier::Namespace: |
| 6696 | if (NamespaceDecl *NS = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6697 | cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6698 | return NestedNameSpecifier::Create(ToContext, prefix, NS); |
| 6699 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6700 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6701 | |
| 6702 | case NestedNameSpecifier::NamespaceAlias: |
| 6703 | if (NamespaceAliasDecl *NSAD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6704 | cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6705 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); |
| 6706 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6707 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6708 | |
| 6709 | case NestedNameSpecifier::Global: |
| 6710 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 6711 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 6712 | case NestedNameSpecifier::Super: |
| 6713 | if (CXXRecordDecl *RD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6714 | cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) { |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 6715 | return NestedNameSpecifier::SuperSpecifier(ToContext, RD); |
| 6716 | } |
| 6717 | return nullptr; |
| 6718 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6719 | case NestedNameSpecifier::TypeSpec: |
| 6720 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 6721 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); |
| 6722 | if (!T.isNull()) { |
| 6723 | bool bTemplate = FromNNS->getKind() == |
| 6724 | NestedNameSpecifier::TypeSpecWithTemplate; |
| 6725 | return NestedNameSpecifier::Create(ToContext, prefix, |
| 6726 | bTemplate, T.getTypePtr()); |
| 6727 | } |
| 6728 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6729 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6730 | } |
| 6731 | |
| 6732 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6733 | } |
| 6734 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 6735 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6736 | // Copied from NestedNameSpecifier mostly. |
| 6737 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 6738 | NestedNameSpecifierLoc NNS = FromNNS; |
| 6739 | |
| 6740 | // Push each of the nested-name-specifiers's onto a stack for |
| 6741 | // serialization in reverse order. |
| 6742 | while (NNS) { |
| 6743 | NestedNames.push_back(NNS); |
| 6744 | NNS = NNS.getPrefix(); |
| 6745 | } |
| 6746 | |
| 6747 | NestedNameSpecifierLocBuilder Builder; |
| 6748 | |
| 6749 | while (!NestedNames.empty()) { |
| 6750 | NNS = NestedNames.pop_back_val(); |
| 6751 | NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier()); |
| 6752 | if (!Spec) |
| 6753 | return NestedNameSpecifierLoc(); |
| 6754 | |
| 6755 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| 6756 | switch (Kind) { |
| 6757 | case NestedNameSpecifier::Identifier: |
| 6758 | Builder.Extend(getToContext(), |
| 6759 | Spec->getAsIdentifier(), |
| 6760 | Import(NNS.getLocalBeginLoc()), |
| 6761 | Import(NNS.getLocalEndLoc())); |
| 6762 | break; |
| 6763 | |
| 6764 | case NestedNameSpecifier::Namespace: |
| 6765 | Builder.Extend(getToContext(), |
| 6766 | Spec->getAsNamespace(), |
| 6767 | Import(NNS.getLocalBeginLoc()), |
| 6768 | Import(NNS.getLocalEndLoc())); |
| 6769 | break; |
| 6770 | |
| 6771 | case NestedNameSpecifier::NamespaceAlias: |
| 6772 | Builder.Extend(getToContext(), |
| 6773 | Spec->getAsNamespaceAlias(), |
| 6774 | Import(NNS.getLocalBeginLoc()), |
| 6775 | Import(NNS.getLocalEndLoc())); |
| 6776 | break; |
| 6777 | |
| 6778 | case NestedNameSpecifier::TypeSpec: |
| 6779 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 6780 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| 6781 | QualType(Spec->getAsType(), 0)); |
| 6782 | Builder.Extend(getToContext(), |
| 6783 | Import(NNS.getLocalBeginLoc()), |
| 6784 | TSI->getTypeLoc(), |
| 6785 | Import(NNS.getLocalEndLoc())); |
| 6786 | break; |
| 6787 | } |
| 6788 | |
| 6789 | case NestedNameSpecifier::Global: |
| 6790 | Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc())); |
| 6791 | break; |
| 6792 | |
| 6793 | case NestedNameSpecifier::Super: { |
| 6794 | SourceRange ToRange = Import(NNS.getSourceRange()); |
| 6795 | Builder.MakeSuper(getToContext(), |
| 6796 | Spec->getAsRecordDecl(), |
| 6797 | ToRange.getBegin(), |
| 6798 | ToRange.getEnd()); |
| 6799 | } |
| 6800 | } |
| 6801 | } |
| 6802 | |
| 6803 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 6804 | } |
| 6805 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6806 | TemplateName ASTImporter::Import(TemplateName From) { |
| 6807 | switch (From.getKind()) { |
| 6808 | case TemplateName::Template: |
| 6809 | if (TemplateDecl *ToTemplate |
| 6810 | = cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
| 6811 | return TemplateName(ToTemplate); |
| 6812 | |
| 6813 | return TemplateName(); |
| 6814 | |
| 6815 | case TemplateName::OverloadedTemplate: { |
| 6816 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 6817 | UnresolvedSet<2> ToTemplates; |
| 6818 | for (OverloadedTemplateStorage::iterator I = FromStorage->begin(), |
| 6819 | E = FromStorage->end(); |
| 6820 | I != E; ++I) { |
| 6821 | if (NamedDecl *To = cast_or_null<NamedDecl>(Import(*I))) |
| 6822 | ToTemplates.addDecl(To); |
| 6823 | else |
| 6824 | return TemplateName(); |
| 6825 | } |
| 6826 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
| 6827 | ToTemplates.end()); |
| 6828 | } |
| 6829 | |
| 6830 | case TemplateName::QualifiedTemplate: { |
| 6831 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| 6832 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); |
| 6833 | if (!Qualifier) |
| 6834 | return TemplateName(); |
| 6835 | |
| 6836 | if (TemplateDecl *ToTemplate |
| 6837 | = cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
| 6838 | return ToContext.getQualifiedTemplateName(Qualifier, |
| 6839 | QTN->hasTemplateKeyword(), |
| 6840 | ToTemplate); |
| 6841 | |
| 6842 | return TemplateName(); |
| 6843 | } |
| 6844 | |
| 6845 | case TemplateName::DependentTemplate: { |
| 6846 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| 6847 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); |
| 6848 | if (!Qualifier) |
| 6849 | return TemplateName(); |
| 6850 | |
| 6851 | if (DTN->isIdentifier()) { |
| 6852 | return ToContext.getDependentTemplateName(Qualifier, |
| 6853 | Import(DTN->getIdentifier())); |
| 6854 | } |
| 6855 | |
| 6856 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); |
| 6857 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6858 | |
| 6859 | case TemplateName::SubstTemplateTemplateParm: { |
| 6860 | SubstTemplateTemplateParmStorage *subst |
| 6861 | = From.getAsSubstTemplateTemplateParm(); |
| 6862 | TemplateTemplateParmDecl *param |
| 6863 | = cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); |
| 6864 | if (!param) |
| 6865 | return TemplateName(); |
| 6866 | |
| 6867 | TemplateName replacement = Import(subst->getReplacement()); |
| 6868 | if (replacement.isNull()) return TemplateName(); |
| 6869 | |
| 6870 | return ToContext.getSubstTemplateTemplateParm(param, replacement); |
| 6871 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6872 | |
| 6873 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 6874 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 6875 | = From.getAsSubstTemplateTemplateParmPack(); |
| 6876 | TemplateTemplateParmDecl *Param |
| 6877 | = cast_or_null<TemplateTemplateParmDecl>( |
| 6878 | Import(SubstPack->getParameterPack())); |
| 6879 | if (!Param) |
| 6880 | return TemplateName(); |
| 6881 | |
| 6882 | ASTNodeImporter Importer(*this); |
| 6883 | TemplateArgument ArgPack |
| 6884 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 6885 | if (ArgPack.isNull()) |
| 6886 | return TemplateName(); |
| 6887 | |
| 6888 | return ToContext.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 6889 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6890 | } |
| 6891 | |
| 6892 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6893 | } |
| 6894 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6895 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { |
| 6896 | if (FromLoc.isInvalid()) |
| 6897 | return SourceLocation(); |
| 6898 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6899 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 6900 | |
Sean Callanan | 24c5fe6 | 2016-11-07 20:42:25 +0000 | [diff] [blame] | 6901 | // For now, map everything down to its file location, so that we |
Chandler Carruth | 2536641 | 2011-07-15 00:04:35 +0000 | [diff] [blame] | 6902 | // don't have to import macro expansions. |
| 6903 | // FIXME: Import macro expansions! |
Sean Callanan | 24c5fe6 | 2016-11-07 20:42:25 +0000 | [diff] [blame] | 6904 | FromLoc = FromSM.getFileLoc(FromLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6905 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
| 6906 | SourceManager &ToSM = ToContext.getSourceManager(); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 6907 | FileID ToFileID = Import(Decomposed.first); |
| 6908 | if (ToFileID.isInvalid()) |
| 6909 | return SourceLocation(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6910 | SourceLocation ret = ToSM.getLocForStartOfFile(ToFileID) |
| 6911 | .getLocWithOffset(Decomposed.second); |
| 6912 | return ret; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6913 | } |
| 6914 | |
| 6915 | SourceRange ASTImporter::Import(SourceRange FromRange) { |
| 6916 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); |
| 6917 | } |
| 6918 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6919 | FileID ASTImporter::Import(FileID FromID) { |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 6920 | llvm::DenseMap<FileID, FileID>::iterator Pos |
| 6921 | = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6922 | if (Pos != ImportedFileIDs.end()) |
| 6923 | return Pos->second; |
| 6924 | |
| 6925 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 6926 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 6927 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Chandler Carruth | 2536641 | 2011-07-15 00:04:35 +0000 | [diff] [blame] | 6928 | assert(FromSLoc.isFile() && "Cannot handle macro expansions yet"); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6929 | |
| 6930 | // Include location of this file. |
| 6931 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| 6932 | |
| 6933 | // Map the FileID for to the "to" source manager. |
| 6934 | FileID ToID; |
| 6935 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
Sean Callanan | 25d34af | 2015-04-30 00:44:21 +0000 | [diff] [blame] | 6936 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6937 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 6938 | // disk again |
| 6939 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 6940 | // than mmap the files several times. |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 6941 | const FileEntry *Entry = ToFileManager.getFile(Cache->OrigEntry->getName()); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 6942 | if (!Entry) |
| 6943 | return FileID(); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6944 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, |
| 6945 | FromSLoc.getFile().getFileCharacteristic()); |
| 6946 | } else { |
| 6947 | // FIXME: We want to re-use the existing MemoryBuffer! |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6948 | const llvm::MemoryBuffer * |
| 6949 | FromBuf = Cache->getBuffer(FromContext.getDiagnostics(), FromSM); |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 6950 | std::unique_ptr<llvm::MemoryBuffer> ToBuf |
Chris Lattner | 58c7934 | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 6951 | = llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6952 | FromBuf->getBufferIdentifier()); |
David Blaikie | 50a5f97 | 2014-08-29 07:59:55 +0000 | [diff] [blame] | 6953 | ToID = ToSM.createFileID(std::move(ToBuf), |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 6954 | FromSLoc.getFile().getFileCharacteristic()); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6955 | } |
| 6956 | |
| 6957 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 6958 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6959 | return ToID; |
| 6960 | } |
| 6961 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6962 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { |
| 6963 | Expr *ToExpr = Import(From->getInit()); |
| 6964 | if (!ToExpr && From->getInit()) |
| 6965 | return nullptr; |
| 6966 | |
| 6967 | if (From->isBaseInitializer()) { |
| 6968 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 6969 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 6970 | return nullptr; |
| 6971 | |
| 6972 | return new (ToContext) CXXCtorInitializer( |
| 6973 | ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()), |
| 6974 | ToExpr, Import(From->getRParenLoc()), |
| 6975 | From->isPackExpansion() ? Import(From->getEllipsisLoc()) |
| 6976 | : SourceLocation()); |
| 6977 | } else if (From->isMemberInitializer()) { |
| 6978 | FieldDecl *ToField = |
| 6979 | llvm::cast_or_null<FieldDecl>(Import(From->getMember())); |
| 6980 | if (!ToField && From->getMember()) |
| 6981 | return nullptr; |
| 6982 | |
| 6983 | return new (ToContext) CXXCtorInitializer( |
| 6984 | ToContext, ToField, Import(From->getMemberLocation()), |
| 6985 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 6986 | } else if (From->isIndirectMemberInitializer()) { |
| 6987 | IndirectFieldDecl *ToIField = llvm::cast_or_null<IndirectFieldDecl>( |
| 6988 | Import(From->getIndirectMember())); |
| 6989 | if (!ToIField && From->getIndirectMember()) |
| 6990 | return nullptr; |
| 6991 | |
| 6992 | return new (ToContext) CXXCtorInitializer( |
| 6993 | ToContext, ToIField, Import(From->getMemberLocation()), |
| 6994 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 6995 | } else if (From->isDelegatingInitializer()) { |
| 6996 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 6997 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 6998 | return nullptr; |
| 6999 | |
| 7000 | return new (ToContext) |
| 7001 | CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()), |
| 7002 | ToExpr, Import(From->getRParenLoc())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7003 | } else { |
| 7004 | return nullptr; |
| 7005 | } |
| 7006 | } |
| 7007 | |
| 7008 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7009 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| 7010 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 7011 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 7012 | return Pos->second; |
| 7013 | |
| 7014 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| 7015 | Import(BaseSpec->getSourceRange()), |
| 7016 | BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 7017 | BaseSpec->getAccessSpecifierAsWritten(), |
| 7018 | Import(BaseSpec->getTypeSourceInfo()), |
| 7019 | Import(BaseSpec->getEllipsisLoc())); |
| 7020 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 7021 | return Imported; |
| 7022 | } |
| 7023 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7024 | void ASTImporter::ImportDefinition(Decl *From) { |
| 7025 | Decl *To = Import(From); |
| 7026 | if (!To) |
| 7027 | return; |
| 7028 | |
| 7029 | if (DeclContext *FromDC = cast<DeclContext>(From)) { |
| 7030 | ASTNodeImporter Importer(*this); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7031 | |
| 7032 | if (RecordDecl *ToRecord = dyn_cast<RecordDecl>(To)) { |
| 7033 | if (!ToRecord->getDefinition()) { |
| 7034 | Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7035 | ASTNodeImporter::IDK_Everything); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7036 | return; |
| 7037 | } |
| 7038 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7039 | |
| 7040 | if (EnumDecl *ToEnum = dyn_cast<EnumDecl>(To)) { |
| 7041 | if (!ToEnum->getDefinition()) { |
| 7042 | Importer.ImportDefinition(cast<EnumDecl>(FromDC), ToEnum, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7043 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7044 | return; |
| 7045 | } |
| 7046 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7047 | |
| 7048 | if (ObjCInterfaceDecl *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
| 7049 | if (!ToIFace->getDefinition()) { |
| 7050 | Importer.ImportDefinition(cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7051 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7052 | return; |
| 7053 | } |
| 7054 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7055 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7056 | if (ObjCProtocolDecl *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
| 7057 | if (!ToProto->getDefinition()) { |
| 7058 | Importer.ImportDefinition(cast<ObjCProtocolDecl>(FromDC), ToProto, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7059 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7060 | return; |
| 7061 | } |
| 7062 | } |
| 7063 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7064 | Importer.ImportDeclContext(FromDC, true); |
| 7065 | } |
| 7066 | } |
| 7067 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7068 | DeclarationName ASTImporter::Import(DeclarationName FromName) { |
| 7069 | if (!FromName) |
| 7070 | return DeclarationName(); |
| 7071 | |
| 7072 | switch (FromName.getNameKind()) { |
| 7073 | case DeclarationName::Identifier: |
| 7074 | return Import(FromName.getAsIdentifierInfo()); |
| 7075 | |
| 7076 | case DeclarationName::ObjCZeroArgSelector: |
| 7077 | case DeclarationName::ObjCOneArgSelector: |
| 7078 | case DeclarationName::ObjCMultiArgSelector: |
| 7079 | return Import(FromName.getObjCSelector()); |
| 7080 | |
| 7081 | case DeclarationName::CXXConstructorName: { |
| 7082 | QualType T = Import(FromName.getCXXNameType()); |
| 7083 | if (T.isNull()) |
| 7084 | return DeclarationName(); |
| 7085 | |
| 7086 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 7087 | ToContext.getCanonicalType(T)); |
| 7088 | } |
| 7089 | |
| 7090 | case DeclarationName::CXXDestructorName: { |
| 7091 | QualType T = Import(FromName.getCXXNameType()); |
| 7092 | if (T.isNull()) |
| 7093 | return DeclarationName(); |
| 7094 | |
| 7095 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 7096 | ToContext.getCanonicalType(T)); |
| 7097 | } |
| 7098 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7099 | case DeclarationName::CXXDeductionGuideName: { |
| 7100 | TemplateDecl *Template = cast_or_null<TemplateDecl>( |
| 7101 | Import(FromName.getCXXDeductionGuideTemplate())); |
| 7102 | if (!Template) |
| 7103 | return DeclarationName(); |
| 7104 | return ToContext.DeclarationNames.getCXXDeductionGuideName(Template); |
| 7105 | } |
| 7106 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7107 | case DeclarationName::CXXConversionFunctionName: { |
| 7108 | QualType T = Import(FromName.getCXXNameType()); |
| 7109 | if (T.isNull()) |
| 7110 | return DeclarationName(); |
| 7111 | |
| 7112 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 7113 | ToContext.getCanonicalType(T)); |
| 7114 | } |
| 7115 | |
| 7116 | case DeclarationName::CXXOperatorName: |
| 7117 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 7118 | FromName.getCXXOverloadedOperator()); |
| 7119 | |
| 7120 | case DeclarationName::CXXLiteralOperatorName: |
| 7121 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| 7122 | Import(FromName.getCXXLiteralIdentifier())); |
| 7123 | |
| 7124 | case DeclarationName::CXXUsingDirective: |
| 7125 | // FIXME: STATICS! |
| 7126 | return DeclarationName::getUsingDirectiveName(); |
| 7127 | } |
| 7128 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 7129 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7130 | } |
| 7131 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7132 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7133 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7134 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7135 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 7136 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 7137 | |
| 7138 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 7139 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 7140 | |
| 7141 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7142 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7143 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7144 | Selector ASTImporter::Import(Selector FromSel) { |
| 7145 | if (FromSel.isNull()) |
| 7146 | return Selector(); |
| 7147 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 7148 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7149 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 7150 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 7151 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 7152 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 7153 | } |
| 7154 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7155 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 7156 | DeclContext *DC, |
| 7157 | unsigned IDNS, |
| 7158 | NamedDecl **Decls, |
| 7159 | unsigned NumDecls) { |
| 7160 | return Name; |
| 7161 | } |
| 7162 | |
| 7163 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 7164 | if (LastDiagFromFrom) |
| 7165 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 7166 | FromContext.getDiagnostics()); |
| 7167 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7168 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7169 | } |
| 7170 | |
| 7171 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 7172 | if (!LastDiagFromFrom) |
| 7173 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 7174 | ToContext.getDiagnostics()); |
| 7175 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7176 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7177 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7178 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7179 | void ASTImporter::CompleteDecl (Decl *D) { |
| 7180 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
| 7181 | if (!ID->getDefinition()) |
| 7182 | ID->startDefinition(); |
| 7183 | } |
| 7184 | else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
| 7185 | if (!PD->getDefinition()) |
| 7186 | PD->startDefinition(); |
| 7187 | } |
| 7188 | else if (TagDecl *TD = dyn_cast<TagDecl>(D)) { |
| 7189 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 7190 | TD->startDefinition(); |
| 7191 | TD->setCompleteDefinition(true); |
| 7192 | } |
| 7193 | } |
| 7194 | else { |
| 7195 | assert (0 && "CompleteDecl called on a Decl that can't be completed"); |
| 7196 | } |
| 7197 | } |
| 7198 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7199 | Decl *ASTImporter::Imported(Decl *From, Decl *To) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7200 | if (From->hasAttrs()) { |
| 7201 | for (Attr *FromAttr : From->getAttrs()) |
| 7202 | To->addAttr(FromAttr->clone(To->getASTContext())); |
| 7203 | } |
| 7204 | if (From->isUsed()) { |
| 7205 | To->setIsUsed(); |
| 7206 | } |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7207 | if (From->isImplicit()) { |
| 7208 | To->setImplicit(); |
| 7209 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7210 | ImportedDecls[From] = To; |
| 7211 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 7212 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7213 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 7214 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 7215 | bool Complain) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7216 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7217 | = ImportedTypes.find(From.getTypePtr()); |
| 7218 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) |
| 7219 | return true; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 7220 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 7221 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
| 7222 | false, Complain); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 7223 | return Ctx.IsStructurallyEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7224 | } |