Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1 | //===--- ASTImporter.cpp - Importing ASTs from other Contexts ---*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the ASTImporter class which imports AST nodes from one |
| 11 | // context into another context. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | #include "clang/AST/ASTImporter.h" |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTDiagnostic.h" |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTStructuralEquivalence.h" |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclObjC.h" |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclVisitor.h" |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 21 | #include "clang/AST/StmtVisitor.h" |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 22 | #include "clang/AST/TypeVisitor.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 23 | #include "clang/Basic/FileManager.h" |
| 24 | #include "clang/Basic/SourceManager.h" |
| 25 | #include "llvm/Support/MemoryBuffer.h" |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 26 | #include <deque> |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 27 | |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 28 | namespace clang { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 29 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, QualType>, |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 30 | public DeclVisitor<ASTNodeImporter, Decl *>, |
| 31 | public StmtVisitor<ASTNodeImporter, Stmt *> { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 32 | ASTImporter &Importer; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 33 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 34 | public: |
| 35 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) { } |
| 36 | |
| 37 | using TypeVisitor<ASTNodeImporter, QualType>::Visit; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 38 | using DeclVisitor<ASTNodeImporter, Decl *>::Visit; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 39 | using StmtVisitor<ASTNodeImporter, Stmt *>::Visit; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 40 | |
| 41 | // Importing types |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 42 | QualType VisitType(const Type *T); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 43 | QualType VisitAtomicType(const AtomicType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 44 | QualType VisitBuiltinType(const BuiltinType *T); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 45 | QualType VisitDecayedType(const DecayedType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 46 | QualType VisitComplexType(const ComplexType *T); |
| 47 | QualType VisitPointerType(const PointerType *T); |
| 48 | QualType VisitBlockPointerType(const BlockPointerType *T); |
| 49 | QualType VisitLValueReferenceType(const LValueReferenceType *T); |
| 50 | QualType VisitRValueReferenceType(const RValueReferenceType *T); |
| 51 | QualType VisitMemberPointerType(const MemberPointerType *T); |
| 52 | QualType VisitConstantArrayType(const ConstantArrayType *T); |
| 53 | QualType VisitIncompleteArrayType(const IncompleteArrayType *T); |
| 54 | QualType VisitVariableArrayType(const VariableArrayType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 55 | // FIXME: DependentSizedArrayType |
| 56 | // FIXME: DependentSizedExtVectorType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 57 | QualType VisitVectorType(const VectorType *T); |
| 58 | QualType VisitExtVectorType(const ExtVectorType *T); |
| 59 | QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T); |
| 60 | QualType VisitFunctionProtoType(const FunctionProtoType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 61 | // FIXME: UnresolvedUsingType |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 62 | QualType VisitParenType(const ParenType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 63 | QualType VisitTypedefType(const TypedefType *T); |
| 64 | QualType VisitTypeOfExprType(const TypeOfExprType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 65 | // FIXME: DependentTypeOfExprType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 66 | QualType VisitTypeOfType(const TypeOfType *T); |
| 67 | QualType VisitDecltypeType(const DecltypeType *T); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 68 | QualType VisitUnaryTransformType(const UnaryTransformType *T); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 69 | QualType VisitAutoType(const AutoType *T); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 70 | QualType VisitInjectedClassNameType(const InjectedClassNameType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 71 | // FIXME: DependentDecltypeType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 72 | QualType VisitRecordType(const RecordType *T); |
| 73 | QualType VisitEnumType(const EnumType *T); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 74 | QualType VisitAttributedType(const AttributedType *T); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 75 | QualType VisitTemplateTypeParmType(const TemplateTypeParmType *T); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 76 | QualType VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 77 | QualType VisitTemplateSpecializationType(const TemplateSpecializationType *T); |
| 78 | QualType VisitElaboratedType(const ElaboratedType *T); |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 79 | // FIXME: DependentNameType |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 80 | // FIXME: DependentTemplateSpecializationType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 81 | QualType VisitObjCInterfaceType(const ObjCInterfaceType *T); |
| 82 | QualType VisitObjCObjectType(const ObjCObjectType *T); |
| 83 | QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 84 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 85 | // Importing declarations |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 86 | bool ImportDeclParts(NamedDecl *D, DeclContext *&DC, |
| 87 | DeclContext *&LexicalDC, DeclarationName &Name, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 88 | NamedDecl *&ToD, SourceLocation &Loc); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 89 | void ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 90 | void ImportDeclarationNameLoc(const DeclarationNameInfo &From, |
| 91 | DeclarationNameInfo& To); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 92 | void ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 93 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 94 | bool ImportCastPath(CastExpr *E, CXXCastPath &Path); |
| 95 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 96 | typedef DesignatedInitExpr::Designator Designator; |
| 97 | Designator ImportDesignator(const Designator &D); |
| 98 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 99 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 100 | /// \brief What we should import from the definition. |
| 101 | enum ImportDefinitionKind { |
| 102 | /// \brief Import the default subset of the definition, which might be |
| 103 | /// nothing (if minimal import is set) or might be everything (if minimal |
| 104 | /// import is not set). |
| 105 | IDK_Default, |
| 106 | /// \brief Import everything. |
| 107 | IDK_Everything, |
| 108 | /// \brief Import only the bare bones needed to establish a valid |
| 109 | /// DeclContext. |
| 110 | IDK_Basic |
| 111 | }; |
| 112 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 113 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { |
| 114 | return IDK == IDK_Everything || |
| 115 | (IDK == IDK_Default && !Importer.isMinimalImport()); |
| 116 | } |
| 117 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 118 | bool ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 119 | ImportDefinitionKind Kind = IDK_Default); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 120 | bool ImportDefinition(VarDecl *From, VarDecl *To, |
| 121 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 122 | bool ImportDefinition(EnumDecl *From, EnumDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 123 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 124 | bool ImportDefinition(ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 125 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 126 | bool ImportDefinition(ObjCProtocolDecl *From, ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 127 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 128 | TemplateParameterList *ImportTemplateParameterList( |
| 129 | TemplateParameterList *Params); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 130 | TemplateArgument ImportTemplateArgument(const TemplateArgument &From); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 131 | TemplateArgumentLoc ImportTemplateArgumentLoc( |
| 132 | const TemplateArgumentLoc &TALoc, bool &Error); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 133 | bool ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 134 | unsigned NumFromArgs, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 135 | SmallVectorImpl<TemplateArgument> &ToArgs); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 136 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, |
| 137 | bool Complain = true); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 138 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 139 | bool Complain = true); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 140 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 141 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 142 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 143 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 144 | Decl *VisitDecl(Decl *D); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 145 | Decl *VisitAccessSpecDecl(AccessSpecDecl *D); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 146 | Decl *VisitStaticAssertDecl(StaticAssertDecl *D); |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 147 | Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 148 | Decl *VisitNamespaceDecl(NamespaceDecl *D); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 149 | Decl *VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 150 | Decl *VisitTypedefDecl(TypedefDecl *D); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 151 | Decl *VisitTypeAliasDecl(TypeAliasDecl *D); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 152 | Decl *VisitLabelDecl(LabelDecl *D); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 153 | Decl *VisitEnumDecl(EnumDecl *D); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 154 | Decl *VisitRecordDecl(RecordDecl *D); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 155 | Decl *VisitEnumConstantDecl(EnumConstantDecl *D); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 156 | Decl *VisitFunctionDecl(FunctionDecl *D); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 157 | Decl *VisitCXXMethodDecl(CXXMethodDecl *D); |
| 158 | Decl *VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 159 | Decl *VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 160 | Decl *VisitCXXConversionDecl(CXXConversionDecl *D); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 161 | Decl *VisitFieldDecl(FieldDecl *D); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 162 | Decl *VisitIndirectFieldDecl(IndirectFieldDecl *D); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 163 | Decl *VisitFriendDecl(FriendDecl *D); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 164 | Decl *VisitObjCIvarDecl(ObjCIvarDecl *D); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 165 | Decl *VisitVarDecl(VarDecl *D); |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 166 | Decl *VisitImplicitParamDecl(ImplicitParamDecl *D); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 167 | Decl *VisitParmVarDecl(ParmVarDecl *D); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 168 | Decl *VisitObjCMethodDecl(ObjCMethodDecl *D); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 169 | Decl *VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 170 | Decl *VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 171 | Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 172 | Decl *VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 173 | |
| 174 | ObjCTypeParamList *ImportObjCTypeParamList(ObjCTypeParamList *list); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 175 | Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 176 | Decl *VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 177 | Decl *VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 178 | Decl *VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 179 | Decl *VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 180 | Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 181 | Decl *VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 182 | Decl *VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 183 | Decl *VisitClassTemplateDecl(ClassTemplateDecl *D); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 184 | Decl *VisitClassTemplateSpecializationDecl( |
| 185 | ClassTemplateSpecializationDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 186 | Decl *VisitVarTemplateDecl(VarTemplateDecl *D); |
| 187 | Decl *VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
| 188 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 189 | // Importing statements |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 190 | DeclGroupRef ImportDeclGroup(DeclGroupRef DG); |
| 191 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 192 | Stmt *VisitStmt(Stmt *S); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 193 | Stmt *VisitGCCAsmStmt(GCCAsmStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 194 | Stmt *VisitDeclStmt(DeclStmt *S); |
| 195 | Stmt *VisitNullStmt(NullStmt *S); |
| 196 | Stmt *VisitCompoundStmt(CompoundStmt *S); |
| 197 | Stmt *VisitCaseStmt(CaseStmt *S); |
| 198 | Stmt *VisitDefaultStmt(DefaultStmt *S); |
| 199 | Stmt *VisitLabelStmt(LabelStmt *S); |
| 200 | Stmt *VisitAttributedStmt(AttributedStmt *S); |
| 201 | Stmt *VisitIfStmt(IfStmt *S); |
| 202 | Stmt *VisitSwitchStmt(SwitchStmt *S); |
| 203 | Stmt *VisitWhileStmt(WhileStmt *S); |
| 204 | Stmt *VisitDoStmt(DoStmt *S); |
| 205 | Stmt *VisitForStmt(ForStmt *S); |
| 206 | Stmt *VisitGotoStmt(GotoStmt *S); |
| 207 | Stmt *VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 208 | Stmt *VisitContinueStmt(ContinueStmt *S); |
| 209 | Stmt *VisitBreakStmt(BreakStmt *S); |
| 210 | Stmt *VisitReturnStmt(ReturnStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 211 | // FIXME: MSAsmStmt |
| 212 | // FIXME: SEHExceptStmt |
| 213 | // FIXME: SEHFinallyStmt |
| 214 | // FIXME: SEHTryStmt |
| 215 | // FIXME: SEHLeaveStmt |
| 216 | // FIXME: CapturedStmt |
| 217 | Stmt *VisitCXXCatchStmt(CXXCatchStmt *S); |
| 218 | Stmt *VisitCXXTryStmt(CXXTryStmt *S); |
| 219 | Stmt *VisitCXXForRangeStmt(CXXForRangeStmt *S); |
| 220 | // FIXME: MSDependentExistsStmt |
| 221 | Stmt *VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); |
| 222 | Stmt *VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); |
| 223 | Stmt *VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); |
| 224 | Stmt *VisitObjCAtTryStmt(ObjCAtTryStmt *S); |
| 225 | Stmt *VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); |
| 226 | Stmt *VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); |
| 227 | Stmt *VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 228 | |
| 229 | // Importing expressions |
| 230 | Expr *VisitExpr(Expr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 231 | Expr *VisitVAArgExpr(VAArgExpr *E); |
| 232 | Expr *VisitGNUNullExpr(GNUNullExpr *E); |
| 233 | Expr *VisitPredefinedExpr(PredefinedExpr *E); |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 234 | Expr *VisitDeclRefExpr(DeclRefExpr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 235 | Expr *VisitImplicitValueInitExpr(ImplicitValueInitExpr *ILE); |
| 236 | Expr *VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 237 | Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 238 | Expr *VisitIntegerLiteral(IntegerLiteral *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 239 | Expr *VisitFloatingLiteral(FloatingLiteral *E); |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 240 | Expr *VisitCharacterLiteral(CharacterLiteral *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 241 | Expr *VisitStringLiteral(StringLiteral *E); |
| 242 | Expr *VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 243 | Expr *VisitAtomicExpr(AtomicExpr *E); |
| 244 | Expr *VisitAddrLabelExpr(AddrLabelExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 245 | Expr *VisitParenExpr(ParenExpr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 246 | Expr *VisitParenListExpr(ParenListExpr *E); |
| 247 | Expr *VisitStmtExpr(StmtExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 248 | Expr *VisitUnaryOperator(UnaryOperator *E); |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 249 | Expr *VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 250 | Expr *VisitBinaryOperator(BinaryOperator *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 251 | Expr *VisitConditionalOperator(ConditionalOperator *E); |
| 252 | Expr *VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 253 | Expr *VisitOpaqueValueExpr(OpaqueValueExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 254 | Expr *VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 255 | Expr *VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 256 | Expr *VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 257 | Expr *VisitCompoundAssignOperator(CompoundAssignOperator *E); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 258 | Expr *VisitImplicitCastExpr(ImplicitCastExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 259 | Expr *VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 260 | Expr *VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 261 | Expr *VisitCXXThrowExpr(CXXThrowExpr *E); |
| 262 | Expr *VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 263 | Expr *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 264 | Expr *VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 265 | Expr *VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 266 | Expr *VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE); |
| 267 | Expr *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
| 268 | Expr *VisitCXXNewExpr(CXXNewExpr *CE); |
| 269 | Expr *VisitCXXDeleteExpr(CXXDeleteExpr *E); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 270 | Expr *VisitCXXConstructExpr(CXXConstructExpr *E); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 271 | Expr *VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 272 | Expr *VisitExprWithCleanups(ExprWithCleanups *EWC); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 273 | Expr *VisitCXXThisExpr(CXXThisExpr *E); |
| 274 | Expr *VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 275 | Expr *VisitMemberExpr(MemberExpr *E); |
| 276 | Expr *VisitCallExpr(CallExpr *E); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 277 | Expr *VisitInitListExpr(InitListExpr *E); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 278 | Expr *VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 279 | Expr *VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 280 | Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 281 | Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 282 | Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
| 283 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 284 | |
| 285 | template<typename IIter, typename OIter> |
| 286 | void ImportArray(IIter Ibegin, IIter Iend, OIter Obegin) { |
| 287 | typedef typename std::remove_reference<decltype(*Obegin)>::type ItemT; |
| 288 | ASTImporter &ImporterRef = Importer; |
| 289 | std::transform(Ibegin, Iend, Obegin, |
| 290 | [&ImporterRef](ItemT From) -> ItemT { |
| 291 | return ImporterRef.Import(From); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 292 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | template<typename IIter, typename OIter> |
| 296 | bool ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
| 297 | typedef typename std::remove_reference<decltype(**Obegin)>::type ItemT; |
| 298 | ASTImporter &ImporterRef = Importer; |
| 299 | bool Failed = false; |
| 300 | std::transform(Ibegin, Iend, Obegin, |
| 301 | [&ImporterRef, &Failed](ItemT *From) -> ItemT * { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 302 | ItemT *To = cast_or_null<ItemT>( |
| 303 | ImporterRef.Import(From)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 304 | if (!To && From) |
| 305 | Failed = true; |
| 306 | return To; |
| 307 | }); |
| 308 | return Failed; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 309 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 310 | |
| 311 | template<typename InContainerTy, typename OutContainerTy> |
| 312 | bool ImportContainerChecked(const InContainerTy &InContainer, |
| 313 | OutContainerTy &OutContainer) { |
| 314 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), |
| 315 | OutContainer.begin()); |
| 316 | } |
| 317 | |
| 318 | template<typename InContainerTy, typename OIter> |
| 319 | bool ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
| 320 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 321 | } |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 322 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 323 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 324 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 325 | //---------------------------------------------------------------------------- |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 326 | // Import Types |
| 327 | //---------------------------------------------------------------------------- |
| 328 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 329 | using namespace clang; |
| 330 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 331 | QualType ASTNodeImporter::VisitType(const Type *T) { |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 332 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 333 | << T->getTypeClassName(); |
| 334 | return QualType(); |
| 335 | } |
| 336 | |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 337 | QualType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 338 | QualType UnderlyingType = Importer.Import(T->getValueType()); |
| 339 | if(UnderlyingType.isNull()) |
| 340 | return QualType(); |
| 341 | |
| 342 | return Importer.getToContext().getAtomicType(UnderlyingType); |
| 343 | } |
| 344 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 345 | QualType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 346 | switch (T->getKind()) { |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 347 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 348 | case BuiltinType::Id: \ |
| 349 | return Importer.getToContext().SingletonId; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 350 | #include "clang/Basic/OpenCLImageTypes.def" |
John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 351 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 352 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 353 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 354 | #include "clang/AST/BuiltinTypes.def" |
| 355 | |
| 356 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 357 | // context supports C++. |
| 358 | |
| 359 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 360 | // context supports ObjC. |
| 361 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 362 | case BuiltinType::Char_U: |
| 363 | // The context we're importing from has an unsigned 'char'. If we're |
| 364 | // importing into a context with a signed 'char', translate to |
| 365 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 366 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 367 | return Importer.getToContext().UnsignedCharTy; |
| 368 | |
| 369 | return Importer.getToContext().CharTy; |
| 370 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 371 | case BuiltinType::Char_S: |
| 372 | // The context we're importing from has an unsigned 'char'. If we're |
| 373 | // importing into a context with a signed 'char', translate to |
| 374 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 375 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 376 | return Importer.getToContext().SignedCharTy; |
| 377 | |
| 378 | return Importer.getToContext().CharTy; |
| 379 | |
Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 380 | case BuiltinType::WChar_S: |
| 381 | case BuiltinType::WChar_U: |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 382 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 383 | // wchar_t? |
| 384 | return Importer.getToContext().WCharTy; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 385 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 386 | |
| 387 | llvm_unreachable("Invalid BuiltinType Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 390 | QualType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 391 | QualType OrigT = Importer.Import(T->getOriginalType()); |
| 392 | if (OrigT.isNull()) |
| 393 | return QualType(); |
| 394 | |
| 395 | return Importer.getToContext().getDecayedType(OrigT); |
| 396 | } |
| 397 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 398 | QualType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 399 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 400 | if (ToElementType.isNull()) |
| 401 | return QualType(); |
| 402 | |
| 403 | return Importer.getToContext().getComplexType(ToElementType); |
| 404 | } |
| 405 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 406 | QualType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 407 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 408 | if (ToPointeeType.isNull()) |
| 409 | return QualType(); |
| 410 | |
| 411 | return Importer.getToContext().getPointerType(ToPointeeType); |
| 412 | } |
| 413 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 414 | QualType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 415 | // FIXME: Check for blocks support in "to" context. |
| 416 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 417 | if (ToPointeeType.isNull()) |
| 418 | return QualType(); |
| 419 | |
| 420 | return Importer.getToContext().getBlockPointerType(ToPointeeType); |
| 421 | } |
| 422 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 423 | QualType |
| 424 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 425 | // FIXME: Check for C++ support in "to" context. |
| 426 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 427 | if (ToPointeeType.isNull()) |
| 428 | return QualType(); |
| 429 | |
| 430 | return Importer.getToContext().getLValueReferenceType(ToPointeeType); |
| 431 | } |
| 432 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 433 | QualType |
| 434 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 435 | // FIXME: Check for C++0x support in "to" context. |
| 436 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 437 | if (ToPointeeType.isNull()) |
| 438 | return QualType(); |
| 439 | |
| 440 | return Importer.getToContext().getRValueReferenceType(ToPointeeType); |
| 441 | } |
| 442 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 443 | QualType ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 444 | // FIXME: Check for C++ support in "to" context. |
| 445 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 446 | if (ToPointeeType.isNull()) |
| 447 | return QualType(); |
| 448 | |
| 449 | QualType ClassType = Importer.Import(QualType(T->getClass(), 0)); |
| 450 | return Importer.getToContext().getMemberPointerType(ToPointeeType, |
| 451 | ClassType.getTypePtr()); |
| 452 | } |
| 453 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 454 | QualType ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 455 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 456 | if (ToElementType.isNull()) |
| 457 | return QualType(); |
| 458 | |
| 459 | return Importer.getToContext().getConstantArrayType(ToElementType, |
| 460 | T->getSize(), |
| 461 | T->getSizeModifier(), |
| 462 | T->getIndexTypeCVRQualifiers()); |
| 463 | } |
| 464 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 465 | QualType |
| 466 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 467 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 468 | if (ToElementType.isNull()) |
| 469 | return QualType(); |
| 470 | |
| 471 | return Importer.getToContext().getIncompleteArrayType(ToElementType, |
| 472 | T->getSizeModifier(), |
| 473 | T->getIndexTypeCVRQualifiers()); |
| 474 | } |
| 475 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 476 | QualType ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 477 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 478 | if (ToElementType.isNull()) |
| 479 | return QualType(); |
| 480 | |
| 481 | Expr *Size = Importer.Import(T->getSizeExpr()); |
| 482 | if (!Size) |
| 483 | return QualType(); |
| 484 | |
| 485 | SourceRange Brackets = Importer.Import(T->getBracketsRange()); |
| 486 | return Importer.getToContext().getVariableArrayType(ToElementType, Size, |
| 487 | T->getSizeModifier(), |
| 488 | T->getIndexTypeCVRQualifiers(), |
| 489 | Brackets); |
| 490 | } |
| 491 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 492 | QualType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 493 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 494 | if (ToElementType.isNull()) |
| 495 | return QualType(); |
| 496 | |
| 497 | return Importer.getToContext().getVectorType(ToElementType, |
| 498 | T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 499 | T->getVectorKind()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 500 | } |
| 501 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 502 | QualType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 503 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 504 | if (ToElementType.isNull()) |
| 505 | return QualType(); |
| 506 | |
| 507 | return Importer.getToContext().getExtVectorType(ToElementType, |
| 508 | T->getNumElements()); |
| 509 | } |
| 510 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 511 | QualType |
| 512 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 513 | // FIXME: What happens if we're importing a function without a prototype |
| 514 | // into C++? Should we make it variadic? |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 515 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 516 | if (ToResultType.isNull()) |
| 517 | return QualType(); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 518 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 519 | return Importer.getToContext().getFunctionNoProtoType(ToResultType, |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 520 | T->getExtInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 521 | } |
| 522 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 523 | QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 524 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 525 | if (ToResultType.isNull()) |
| 526 | return QualType(); |
| 527 | |
| 528 | // Import argument types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 529 | SmallVector<QualType, 4> ArgTypes; |
Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 530 | for (const auto &A : T->param_types()) { |
| 531 | QualType ArgType = Importer.Import(A); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 532 | if (ArgType.isNull()) |
| 533 | return QualType(); |
| 534 | ArgTypes.push_back(ArgType); |
| 535 | } |
| 536 | |
| 537 | // Import exception types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 538 | SmallVector<QualType, 4> ExceptionTypes; |
Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 539 | for (const auto &E : T->exceptions()) { |
| 540 | QualType ExceptionType = Importer.Import(E); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 541 | if (ExceptionType.isNull()) |
| 542 | return QualType(); |
| 543 | ExceptionTypes.push_back(ExceptionType); |
| 544 | } |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 545 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 546 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 547 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 548 | |
| 549 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 550 | ToEPI.Variadic = FromEPI.Variadic; |
| 551 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 552 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 553 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 554 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 555 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
| 556 | ToEPI.ExceptionSpec.NoexceptExpr = |
| 557 | Importer.Import(FromEPI.ExceptionSpec.NoexceptExpr); |
| 558 | ToEPI.ExceptionSpec.SourceDecl = cast_or_null<FunctionDecl>( |
| 559 | Importer.Import(FromEPI.ExceptionSpec.SourceDecl)); |
| 560 | ToEPI.ExceptionSpec.SourceTemplate = cast_or_null<FunctionDecl>( |
| 561 | Importer.Import(FromEPI.ExceptionSpec.SourceTemplate)); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 562 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 563 | return Importer.getToContext().getFunctionType(ToResultType, ArgTypes, ToEPI); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 564 | } |
| 565 | |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 566 | QualType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 567 | QualType ToInnerType = Importer.Import(T->getInnerType()); |
| 568 | if (ToInnerType.isNull()) |
| 569 | return QualType(); |
| 570 | |
| 571 | return Importer.getToContext().getParenType(ToInnerType); |
| 572 | } |
| 573 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 574 | QualType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 575 | TypedefNameDecl *ToDecl |
| 576 | = dyn_cast_or_null<TypedefNameDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 577 | if (!ToDecl) |
| 578 | return QualType(); |
| 579 | |
| 580 | return Importer.getToContext().getTypeDeclType(ToDecl); |
| 581 | } |
| 582 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 583 | QualType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 584 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 585 | if (!ToExpr) |
| 586 | return QualType(); |
| 587 | |
| 588 | return Importer.getToContext().getTypeOfExprType(ToExpr); |
| 589 | } |
| 590 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 591 | QualType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 592 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 593 | if (ToUnderlyingType.isNull()) |
| 594 | return QualType(); |
| 595 | |
| 596 | return Importer.getToContext().getTypeOfType(ToUnderlyingType); |
| 597 | } |
| 598 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 599 | QualType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 600 | // FIXME: Make sure that the "to" context supports C++0x! |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 601 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 602 | if (!ToExpr) |
| 603 | return QualType(); |
| 604 | |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 605 | QualType UnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 606 | if (UnderlyingType.isNull()) |
| 607 | return QualType(); |
| 608 | |
| 609 | return Importer.getToContext().getDecltypeType(ToExpr, UnderlyingType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 610 | } |
| 611 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 612 | QualType ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 613 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 614 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 615 | if (ToBaseType.isNull() || ToUnderlyingType.isNull()) |
| 616 | return QualType(); |
| 617 | |
| 618 | return Importer.getToContext().getUnaryTransformType(ToBaseType, |
| 619 | ToUnderlyingType, |
| 620 | T->getUTTKind()); |
| 621 | } |
| 622 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 623 | QualType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 624 | // FIXME: Make sure that the "to" context supports C++11! |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 625 | QualType FromDeduced = T->getDeducedType(); |
| 626 | QualType ToDeduced; |
| 627 | if (!FromDeduced.isNull()) { |
| 628 | ToDeduced = Importer.Import(FromDeduced); |
| 629 | if (ToDeduced.isNull()) |
| 630 | return QualType(); |
| 631 | } |
| 632 | |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 633 | return Importer.getToContext().getAutoType(ToDeduced, T->getKeyword(), |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 634 | /*IsDependent*/false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 635 | } |
| 636 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 637 | QualType ASTNodeImporter::VisitInjectedClassNameType( |
| 638 | const InjectedClassNameType *T) { |
| 639 | CXXRecordDecl *D = cast_or_null<CXXRecordDecl>(Importer.Import(T->getDecl())); |
| 640 | if (!D) |
| 641 | return QualType(); |
| 642 | |
| 643 | QualType InjType = Importer.Import(T->getInjectedSpecializationType()); |
| 644 | if (InjType.isNull()) |
| 645 | return QualType(); |
| 646 | |
| 647 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 648 | // See comments in InjectedClassNameType definition for details |
| 649 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 650 | enum { |
| 651 | TypeAlignmentInBits = 4, |
| 652 | TypeAlignment = 1 << TypeAlignmentInBits |
| 653 | }; |
| 654 | |
| 655 | return QualType(new (Importer.getToContext(), TypeAlignment) |
| 656 | InjectedClassNameType(D, InjType), 0); |
| 657 | } |
| 658 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 659 | QualType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 660 | RecordDecl *ToDecl |
| 661 | = dyn_cast_or_null<RecordDecl>(Importer.Import(T->getDecl())); |
| 662 | if (!ToDecl) |
| 663 | return QualType(); |
| 664 | |
| 665 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 666 | } |
| 667 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 668 | QualType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 669 | EnumDecl *ToDecl |
| 670 | = dyn_cast_or_null<EnumDecl>(Importer.Import(T->getDecl())); |
| 671 | if (!ToDecl) |
| 672 | return QualType(); |
| 673 | |
| 674 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 675 | } |
| 676 | |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 677 | QualType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 678 | QualType FromModifiedType = T->getModifiedType(); |
| 679 | QualType FromEquivalentType = T->getEquivalentType(); |
| 680 | QualType ToModifiedType; |
| 681 | QualType ToEquivalentType; |
| 682 | |
| 683 | if (!FromModifiedType.isNull()) { |
| 684 | ToModifiedType = Importer.Import(FromModifiedType); |
| 685 | if (ToModifiedType.isNull()) |
| 686 | return QualType(); |
| 687 | } |
| 688 | if (!FromEquivalentType.isNull()) { |
| 689 | ToEquivalentType = Importer.Import(FromEquivalentType); |
| 690 | if (ToEquivalentType.isNull()) |
| 691 | return QualType(); |
| 692 | } |
| 693 | |
| 694 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
| 695 | ToModifiedType, ToEquivalentType); |
| 696 | } |
| 697 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 698 | |
| 699 | QualType ASTNodeImporter::VisitTemplateTypeParmType( |
| 700 | const TemplateTypeParmType *T) { |
| 701 | TemplateTypeParmDecl *ParmDecl = |
| 702 | cast_or_null<TemplateTypeParmDecl>(Importer.Import(T->getDecl())); |
| 703 | if (!ParmDecl && T->getDecl()) |
| 704 | return QualType(); |
| 705 | |
| 706 | return Importer.getToContext().getTemplateTypeParmType( |
| 707 | T->getDepth(), T->getIndex(), T->isParameterPack(), ParmDecl); |
| 708 | } |
| 709 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 710 | QualType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
| 711 | const SubstTemplateTypeParmType *T) { |
| 712 | const TemplateTypeParmType *Replaced = |
| 713 | cast_or_null<TemplateTypeParmType>(Importer.Import( |
| 714 | QualType(T->getReplacedParameter(), 0)).getTypePtr()); |
| 715 | if (!Replaced) |
| 716 | return QualType(); |
| 717 | |
| 718 | QualType Replacement = Importer.Import(T->getReplacementType()); |
| 719 | if (Replacement.isNull()) |
| 720 | return QualType(); |
| 721 | Replacement = Replacement.getCanonicalType(); |
| 722 | |
| 723 | return Importer.getToContext().getSubstTemplateTypeParmType( |
| 724 | Replaced, Replacement); |
| 725 | } |
| 726 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 727 | QualType ASTNodeImporter::VisitTemplateSpecializationType( |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 728 | const TemplateSpecializationType *T) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 729 | TemplateName ToTemplate = Importer.Import(T->getTemplateName()); |
| 730 | if (ToTemplate.isNull()) |
| 731 | return QualType(); |
| 732 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 733 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 734 | if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
| 735 | return QualType(); |
| 736 | |
| 737 | QualType ToCanonType; |
| 738 | if (!QualType(T, 0).isCanonical()) { |
| 739 | QualType FromCanonType |
| 740 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
| 741 | ToCanonType =Importer.Import(FromCanonType); |
| 742 | if (ToCanonType.isNull()) |
| 743 | return QualType(); |
| 744 | } |
| 745 | return Importer.getToContext().getTemplateSpecializationType(ToTemplate, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 746 | ToTemplateArgs, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 747 | ToCanonType); |
| 748 | } |
| 749 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 750 | QualType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 751 | NestedNameSpecifier *ToQualifier = nullptr; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 752 | // Note: the qualifier in an ElaboratedType is optional. |
| 753 | if (T->getQualifier()) { |
| 754 | ToQualifier = Importer.Import(T->getQualifier()); |
| 755 | if (!ToQualifier) |
| 756 | return QualType(); |
| 757 | } |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 758 | |
| 759 | QualType ToNamedType = Importer.Import(T->getNamedType()); |
| 760 | if (ToNamedType.isNull()) |
| 761 | return QualType(); |
| 762 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 763 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
| 764 | ToQualifier, ToNamedType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 765 | } |
| 766 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 767 | QualType ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 768 | ObjCInterfaceDecl *Class |
| 769 | = dyn_cast_or_null<ObjCInterfaceDecl>(Importer.Import(T->getDecl())); |
| 770 | if (!Class) |
| 771 | return QualType(); |
| 772 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 773 | return Importer.getToContext().getObjCInterfaceType(Class); |
| 774 | } |
| 775 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 776 | QualType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 777 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 778 | if (ToBaseType.isNull()) |
| 779 | return QualType(); |
| 780 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 781 | SmallVector<QualType, 4> TypeArgs; |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 782 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 783 | QualType ImportedTypeArg = Importer.Import(TypeArg); |
| 784 | if (ImportedTypeArg.isNull()) |
| 785 | return QualType(); |
| 786 | |
| 787 | TypeArgs.push_back(ImportedTypeArg); |
| 788 | } |
| 789 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 790 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 791 | for (auto *P : T->quals()) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 792 | ObjCProtocolDecl *Protocol |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 793 | = dyn_cast_or_null<ObjCProtocolDecl>(Importer.Import(P)); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 794 | if (!Protocol) |
| 795 | return QualType(); |
| 796 | Protocols.push_back(Protocol); |
| 797 | } |
| 798 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 799 | return Importer.getToContext().getObjCObjectType(ToBaseType, TypeArgs, |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 800 | Protocols, |
| 801 | T->isKindOfTypeAsWritten()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 802 | } |
| 803 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 804 | QualType |
| 805 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 806 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 807 | if (ToPointeeType.isNull()) |
| 808 | return QualType(); |
| 809 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 810 | return Importer.getToContext().getObjCObjectPointerType(ToPointeeType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 811 | } |
| 812 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 813 | //---------------------------------------------------------------------------- |
| 814 | // Import Declarations |
| 815 | //---------------------------------------------------------------------------- |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 816 | bool ASTNodeImporter::ImportDeclParts(NamedDecl *D, DeclContext *&DC, |
| 817 | DeclContext *&LexicalDC, |
| 818 | DeclarationName &Name, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 819 | NamedDecl *&ToD, |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 820 | SourceLocation &Loc) { |
| 821 | // Import the context of this declaration. |
| 822 | DC = Importer.ImportContext(D->getDeclContext()); |
| 823 | if (!DC) |
| 824 | return true; |
| 825 | |
| 826 | LexicalDC = DC; |
| 827 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 828 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 829 | if (!LexicalDC) |
| 830 | return true; |
| 831 | } |
| 832 | |
| 833 | // Import the name of this declaration. |
| 834 | Name = Importer.Import(D->getDeclName()); |
| 835 | if (D->getDeclName() && !Name) |
| 836 | return true; |
| 837 | |
| 838 | // Import the location of this declaration. |
| 839 | Loc = Importer.Import(D->getLocation()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 840 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 841 | return false; |
| 842 | } |
| 843 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 844 | void ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
| 845 | if (!FromD) |
| 846 | return; |
| 847 | |
| 848 | if (!ToD) { |
| 849 | ToD = Importer.Import(FromD); |
| 850 | if (!ToD) |
| 851 | return; |
| 852 | } |
| 853 | |
| 854 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 855 | if (RecordDecl *ToRecord = cast_or_null<RecordDecl>(ToD)) { |
Sean Callanan | 19dfc93 | 2013-01-11 23:17:47 +0000 | [diff] [blame] | 856 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && !ToRecord->getDefinition()) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 857 | ImportDefinition(FromRecord, ToRecord); |
| 858 | } |
| 859 | } |
| 860 | return; |
| 861 | } |
| 862 | |
| 863 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 864 | if (EnumDecl *ToEnum = cast_or_null<EnumDecl>(ToD)) { |
| 865 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
| 866 | ImportDefinition(FromEnum, ToEnum); |
| 867 | } |
| 868 | } |
| 869 | return; |
| 870 | } |
| 871 | } |
| 872 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 873 | void |
| 874 | ASTNodeImporter::ImportDeclarationNameLoc(const DeclarationNameInfo &From, |
| 875 | DeclarationNameInfo& To) { |
| 876 | // NOTE: To.Name and To.Loc are already imported. |
| 877 | // We only have to import To.LocInfo. |
| 878 | switch (To.getName().getNameKind()) { |
| 879 | case DeclarationName::Identifier: |
| 880 | case DeclarationName::ObjCZeroArgSelector: |
| 881 | case DeclarationName::ObjCOneArgSelector: |
| 882 | case DeclarationName::ObjCMultiArgSelector: |
| 883 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 884 | case DeclarationName::CXXDeductionGuideName: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 885 | return; |
| 886 | |
| 887 | case DeclarationName::CXXOperatorName: { |
| 888 | SourceRange Range = From.getCXXOperatorNameRange(); |
| 889 | To.setCXXOperatorNameRange(Importer.Import(Range)); |
| 890 | return; |
| 891 | } |
| 892 | case DeclarationName::CXXLiteralOperatorName: { |
| 893 | SourceLocation Loc = From.getCXXLiteralOperatorNameLoc(); |
| 894 | To.setCXXLiteralOperatorNameLoc(Importer.Import(Loc)); |
| 895 | return; |
| 896 | } |
| 897 | case DeclarationName::CXXConstructorName: |
| 898 | case DeclarationName::CXXDestructorName: |
| 899 | case DeclarationName::CXXConversionFunctionName: { |
| 900 | TypeSourceInfo *FromTInfo = From.getNamedTypeInfo(); |
| 901 | To.setNamedTypeInfo(Importer.Import(FromTInfo)); |
| 902 | return; |
| 903 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 904 | } |
Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 905 | llvm_unreachable("Unknown name kind."); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 906 | } |
| 907 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 908 | void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 909 | if (Importer.isMinimalImport() && !ForceImport) { |
Sean Callanan | 81d577c | 2011-07-22 23:46:03 +0000 | [diff] [blame] | 910 | Importer.ImportContext(FromDC); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 911 | return; |
| 912 | } |
| 913 | |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 914 | for (auto *From : FromDC->decls()) |
| 915 | Importer.Import(From); |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 916 | } |
| 917 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 918 | bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 919 | ImportDefinitionKind Kind) { |
| 920 | if (To->getDefinition() || To->isBeingDefined()) { |
| 921 | if (Kind == IDK_Everything) |
| 922 | ImportDeclContext(From, /*ForceImport=*/true); |
| 923 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 924 | return false; |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 925 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 926 | |
| 927 | To->startDefinition(); |
| 928 | |
| 929 | // Add base classes. |
| 930 | if (CXXRecordDecl *ToCXX = dyn_cast<CXXRecordDecl>(To)) { |
| 931 | CXXRecordDecl *FromCXX = cast<CXXRecordDecl>(From); |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 932 | |
| 933 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 934 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 935 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 936 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 937 | ToData.Aggregate = FromData.Aggregate; |
| 938 | ToData.PlainOldData = FromData.PlainOldData; |
| 939 | ToData.Empty = FromData.Empty; |
| 940 | ToData.Polymorphic = FromData.Polymorphic; |
| 941 | ToData.Abstract = FromData.Abstract; |
| 942 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
| 943 | ToData.HasNoNonEmptyBases = FromData.HasNoNonEmptyBases; |
| 944 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 945 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 946 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 947 | ToData.HasMutableFields = FromData.HasMutableFields; |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 948 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 949 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 950 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 951 | ToData.HasUninitializedReferenceMember |
| 952 | = FromData.HasUninitializedReferenceMember; |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 953 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 954 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 955 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 956 | ToData.NeedOverloadResolutionForMoveConstructor |
| 957 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 958 | ToData.NeedOverloadResolutionForMoveAssignment |
| 959 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 960 | ToData.NeedOverloadResolutionForDestructor |
| 961 | = FromData.NeedOverloadResolutionForDestructor; |
| 962 | ToData.DefaultedMoveConstructorIsDeleted |
| 963 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 964 | ToData.DefaultedMoveAssignmentIsDeleted |
| 965 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 966 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 967 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 968 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 969 | ToData.HasConstexprNonCopyMoveConstructor |
| 970 | = FromData.HasConstexprNonCopyMoveConstructor; |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 971 | ToData.HasDefaultedDefaultConstructor |
| 972 | = FromData.HasDefaultedDefaultConstructor; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 973 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 974 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 975 | ToData.HasConstexprDefaultConstructor |
| 976 | = FromData.HasConstexprDefaultConstructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 977 | ToData.HasNonLiteralTypeFieldsOrBases |
| 978 | = FromData.HasNonLiteralTypeFieldsOrBases; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 979 | // ComputedVisibleConversions not imported. |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 980 | ToData.UserProvidedDefaultConstructor |
| 981 | = FromData.UserProvidedDefaultConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 982 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 983 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 984 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 985 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 986 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 987 | ToData.ImplicitCopyAssignmentHasConstParam |
| 988 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 989 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 990 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 991 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 992 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 993 | ToData.IsLambda = FromData.IsLambda; |
| 994 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 995 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 996 | for (const auto &Base1 : FromCXX->bases()) { |
| 997 | QualType T = Importer.Import(Base1.getType()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 998 | if (T.isNull()) |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 999 | return true; |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1000 | |
| 1001 | SourceLocation EllipsisLoc; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1002 | if (Base1.isPackExpansion()) |
| 1003 | EllipsisLoc = Importer.Import(Base1.getEllipsisLoc()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1004 | |
| 1005 | // Ensure that we have a definition for the base. |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1006 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1007 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1008 | Bases.push_back( |
| 1009 | new (Importer.getToContext()) |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1010 | CXXBaseSpecifier(Importer.Import(Base1.getSourceRange()), |
| 1011 | Base1.isVirtual(), |
| 1012 | Base1.isBaseOfClass(), |
| 1013 | Base1.getAccessSpecifierAsWritten(), |
| 1014 | Importer.Import(Base1.getTypeSourceInfo()), |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1015 | EllipsisLoc)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1016 | } |
| 1017 | if (!Bases.empty()) |
Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1018 | ToCXX->setBases(Bases.data(), Bases.size()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1021 | if (shouldForceImportDeclContext(Kind)) |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1022 | ImportDeclContext(From, /*ForceImport=*/true); |
| 1023 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1024 | To->completeDefinition(); |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1025 | return false; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1026 | } |
| 1027 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1028 | bool ASTNodeImporter::ImportDefinition(VarDecl *From, VarDecl *To, |
| 1029 | ImportDefinitionKind Kind) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1030 | if (To->getAnyInitializer()) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1031 | return false; |
| 1032 | |
| 1033 | // FIXME: Can we really import any initializer? Alternatively, we could force |
| 1034 | // ourselves to import every declaration of a variable and then only use |
| 1035 | // getInit() here. |
| 1036 | To->setInit(Importer.Import(const_cast<Expr *>(From->getAnyInitializer()))); |
| 1037 | |
| 1038 | // FIXME: Other bits to merge? |
| 1039 | |
| 1040 | return false; |
| 1041 | } |
| 1042 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1043 | bool ASTNodeImporter::ImportDefinition(EnumDecl *From, EnumDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1044 | ImportDefinitionKind Kind) { |
| 1045 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1046 | if (Kind == IDK_Everything) |
| 1047 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1048 | return false; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1049 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1050 | |
| 1051 | To->startDefinition(); |
| 1052 | |
| 1053 | QualType T = Importer.Import(Importer.getFromContext().getTypeDeclType(From)); |
| 1054 | if (T.isNull()) |
| 1055 | return true; |
| 1056 | |
| 1057 | QualType ToPromotionType = Importer.Import(From->getPromotionType()); |
| 1058 | if (ToPromotionType.isNull()) |
| 1059 | return true; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1060 | |
| 1061 | if (shouldForceImportDeclContext(Kind)) |
| 1062 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1063 | |
| 1064 | // FIXME: we might need to merge the number of positive or negative bits |
| 1065 | // if the enumerator lists don't match. |
| 1066 | To->completeDefinition(T, ToPromotionType, |
| 1067 | From->getNumPositiveBits(), |
| 1068 | From->getNumNegativeBits()); |
| 1069 | return false; |
| 1070 | } |
| 1071 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1072 | TemplateParameterList *ASTNodeImporter::ImportTemplateParameterList( |
| 1073 | TemplateParameterList *Params) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1074 | SmallVector<NamedDecl *, 4> ToParams(Params->size()); |
| 1075 | if (ImportContainerChecked(*Params, ToParams)) |
| 1076 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1077 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1078 | Expr *ToRequiresClause; |
| 1079 | if (Expr *const R = Params->getRequiresClause()) { |
| 1080 | ToRequiresClause = Importer.Import(R); |
| 1081 | if (!ToRequiresClause) |
| 1082 | return nullptr; |
| 1083 | } else { |
| 1084 | ToRequiresClause = nullptr; |
| 1085 | } |
| 1086 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1087 | return TemplateParameterList::Create(Importer.getToContext(), |
| 1088 | Importer.Import(Params->getTemplateLoc()), |
| 1089 | Importer.Import(Params->getLAngleLoc()), |
David Majnemer | 902f8c6 | 2015-12-27 07:16:27 +0000 | [diff] [blame] | 1090 | ToParams, |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1091 | Importer.Import(Params->getRAngleLoc()), |
| 1092 | ToRequiresClause); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1095 | TemplateArgument |
| 1096 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1097 | switch (From.getKind()) { |
| 1098 | case TemplateArgument::Null: |
| 1099 | return TemplateArgument(); |
| 1100 | |
| 1101 | case TemplateArgument::Type: { |
| 1102 | QualType ToType = Importer.Import(From.getAsType()); |
| 1103 | if (ToType.isNull()) |
| 1104 | return TemplateArgument(); |
| 1105 | return TemplateArgument(ToType); |
| 1106 | } |
| 1107 | |
| 1108 | case TemplateArgument::Integral: { |
| 1109 | QualType ToType = Importer.Import(From.getIntegralType()); |
| 1110 | if (ToType.isNull()) |
| 1111 | return TemplateArgument(); |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 1112 | return TemplateArgument(From, ToType); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1115 | case TemplateArgument::Declaration: { |
David Blaikie | 3c7dd6b | 2014-10-22 19:54:16 +0000 | [diff] [blame] | 1116 | ValueDecl *To = cast_or_null<ValueDecl>(Importer.Import(From.getAsDecl())); |
| 1117 | QualType ToType = Importer.Import(From.getParamTypeForDecl()); |
| 1118 | if (!To || ToType.isNull()) |
| 1119 | return TemplateArgument(); |
| 1120 | return TemplateArgument(To, ToType); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | case TemplateArgument::NullPtr: { |
| 1124 | QualType ToType = Importer.Import(From.getNullPtrType()); |
| 1125 | if (ToType.isNull()) |
| 1126 | return TemplateArgument(); |
| 1127 | return TemplateArgument(ToType, /*isNullPtr*/true); |
| 1128 | } |
| 1129 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1130 | case TemplateArgument::Template: { |
| 1131 | TemplateName ToTemplate = Importer.Import(From.getAsTemplate()); |
| 1132 | if (ToTemplate.isNull()) |
| 1133 | return TemplateArgument(); |
| 1134 | |
| 1135 | return TemplateArgument(ToTemplate); |
| 1136 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1137 | |
| 1138 | case TemplateArgument::TemplateExpansion: { |
| 1139 | TemplateName ToTemplate |
| 1140 | = Importer.Import(From.getAsTemplateOrTemplatePattern()); |
| 1141 | if (ToTemplate.isNull()) |
| 1142 | return TemplateArgument(); |
| 1143 | |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 1144 | return TemplateArgument(ToTemplate, From.getNumTemplateExpansions()); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1147 | case TemplateArgument::Expression: |
| 1148 | if (Expr *ToExpr = Importer.Import(From.getAsExpr())) |
| 1149 | return TemplateArgument(ToExpr); |
| 1150 | return TemplateArgument(); |
| 1151 | |
| 1152 | case TemplateArgument::Pack: { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1153 | SmallVector<TemplateArgument, 2> ToPack; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1154 | ToPack.reserve(From.pack_size()); |
| 1155 | if (ImportTemplateArguments(From.pack_begin(), From.pack_size(), ToPack)) |
| 1156 | return TemplateArgument(); |
Benjamin Kramer | cce6347 | 2015-08-05 09:40:22 +0000 | [diff] [blame] | 1157 | |
| 1158 | return TemplateArgument( |
| 1159 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | llvm_unreachable("Invalid template argument kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1164 | } |
| 1165 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1166 | TemplateArgumentLoc ASTNodeImporter::ImportTemplateArgumentLoc( |
| 1167 | const TemplateArgumentLoc &TALoc, bool &Error) { |
| 1168 | Error = false; |
| 1169 | TemplateArgument Arg = ImportTemplateArgument(TALoc.getArgument()); |
| 1170 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 1171 | TemplateArgumentLocInfo ToInfo; |
| 1172 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 1173 | Expr *E = Importer.Import(FromInfo.getAsExpr()); |
| 1174 | ToInfo = TemplateArgumentLocInfo(E); |
| 1175 | if (!E) |
| 1176 | Error = true; |
| 1177 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 1178 | if (TypeSourceInfo *TSI = Importer.Import(FromInfo.getAsTypeSourceInfo())) |
| 1179 | ToInfo = TemplateArgumentLocInfo(TSI); |
| 1180 | else |
| 1181 | Error = true; |
| 1182 | } else { |
| 1183 | ToInfo = TemplateArgumentLocInfo( |
| 1184 | Importer.Import(FromInfo.getTemplateQualifierLoc()), |
| 1185 | Importer.Import(FromInfo.getTemplateNameLoc()), |
| 1186 | Importer.Import(FromInfo.getTemplateEllipsisLoc())); |
| 1187 | } |
| 1188 | return TemplateArgumentLoc(Arg, ToInfo); |
| 1189 | } |
| 1190 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1191 | bool ASTNodeImporter::ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 1192 | unsigned NumFromArgs, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1193 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1194 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
| 1195 | TemplateArgument To = ImportTemplateArgument(FromArgs[I]); |
| 1196 | if (To.isNull() && !FromArgs[I].isNull()) |
| 1197 | return true; |
| 1198 | |
| 1199 | ToArgs.push_back(To); |
| 1200 | } |
| 1201 | |
| 1202 | return false; |
| 1203 | } |
| 1204 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1205 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1206 | RecordDecl *ToRecord, bool Complain) { |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1207 | // Eliminate a potential failure point where we attempt to re-import |
| 1208 | // something we're trying to import while completing ToRecord. |
| 1209 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 1210 | if (ToOrigin) { |
| 1211 | RecordDecl *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
| 1212 | if (ToOriginRecord) |
| 1213 | ToRecord = ToOriginRecord; |
| 1214 | } |
| 1215 | |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1216 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1217 | ToRecord->getASTContext(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1218 | Importer.getNonEquivalentDecls(), |
| 1219 | false, Complain); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1220 | return Ctx.IsStructurallyEquivalent(FromRecord, ToRecord); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1223 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 1224 | bool Complain) { |
| 1225 | StructuralEquivalenceContext Ctx( |
| 1226 | Importer.getFromContext(), Importer.getToContext(), |
| 1227 | Importer.getNonEquivalentDecls(), false, Complain); |
| 1228 | return Ctx.IsStructurallyEquivalent(FromVar, ToVar); |
| 1229 | } |
| 1230 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1231 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1232 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1233 | Importer.getToContext(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1234 | Importer.getNonEquivalentDecls()); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1235 | return Ctx.IsStructurallyEquivalent(FromEnum, ToEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1238 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
| 1239 | EnumConstantDecl *ToEC) |
| 1240 | { |
| 1241 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 1242 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 1243 | |
| 1244 | return FromVal.isSigned() == ToVal.isSigned() && |
| 1245 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 1246 | FromVal == ToVal; |
| 1247 | } |
| 1248 | |
| 1249 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1250 | ClassTemplateDecl *To) { |
| 1251 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1252 | Importer.getToContext(), |
| 1253 | Importer.getNonEquivalentDecls()); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1254 | return Ctx.IsStructurallyEquivalent(From, To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1257 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 1258 | VarTemplateDecl *To) { |
| 1259 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1260 | Importer.getToContext(), |
| 1261 | Importer.getNonEquivalentDecls()); |
| 1262 | return Ctx.IsStructurallyEquivalent(From, To); |
| 1263 | } |
| 1264 | |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1265 | Decl *ASTNodeImporter::VisitDecl(Decl *D) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 1266 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1267 | << D->getDeclKindName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1268 | return nullptr; |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 1271 | Decl *ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 1272 | TranslationUnitDecl *ToD = |
| 1273 | Importer.getToContext().getTranslationUnitDecl(); |
| 1274 | |
| 1275 | Importer.Imported(D, ToD); |
| 1276 | |
| 1277 | return ToD; |
| 1278 | } |
| 1279 | |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1280 | Decl *ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 1281 | |
| 1282 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1283 | SourceLocation ColonLoc = Importer.Import(D->getColonLoc()); |
| 1284 | |
| 1285 | // Import the context of this declaration. |
| 1286 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1287 | if (!DC) |
| 1288 | return nullptr; |
| 1289 | |
| 1290 | AccessSpecDecl *accessSpecDecl |
| 1291 | = AccessSpecDecl::Create(Importer.getToContext(), D->getAccess(), |
| 1292 | DC, Loc, ColonLoc); |
| 1293 | |
| 1294 | if (!accessSpecDecl) |
| 1295 | return nullptr; |
| 1296 | |
| 1297 | // Lexical DeclContext and Semantic DeclContext |
| 1298 | // is always the same for the accessSpec. |
| 1299 | accessSpecDecl->setLexicalDeclContext(DC); |
| 1300 | DC->addDeclInternal(accessSpecDecl); |
| 1301 | |
| 1302 | return accessSpecDecl; |
| 1303 | } |
| 1304 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1305 | Decl *ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 1306 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1307 | if (!DC) |
| 1308 | return nullptr; |
| 1309 | |
| 1310 | DeclContext *LexicalDC = DC; |
| 1311 | |
| 1312 | // Import the location of this declaration. |
| 1313 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1314 | |
| 1315 | Expr *AssertExpr = Importer.Import(D->getAssertExpr()); |
| 1316 | if (!AssertExpr) |
| 1317 | return nullptr; |
| 1318 | |
| 1319 | StringLiteral *FromMsg = D->getMessage(); |
| 1320 | StringLiteral *ToMsg = cast_or_null<StringLiteral>(Importer.Import(FromMsg)); |
| 1321 | if (!ToMsg && FromMsg) |
| 1322 | return nullptr; |
| 1323 | |
| 1324 | StaticAssertDecl *ToD = StaticAssertDecl::Create( |
| 1325 | Importer.getToContext(), DC, Loc, AssertExpr, ToMsg, |
| 1326 | Importer.Import(D->getRParenLoc()), D->isFailed()); |
| 1327 | |
| 1328 | ToD->setLexicalDeclContext(LexicalDC); |
| 1329 | LexicalDC->addDeclInternal(ToD); |
| 1330 | Importer.Imported(D, ToD); |
| 1331 | return ToD; |
| 1332 | } |
| 1333 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1334 | Decl *ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
| 1335 | // Import the major distinguishing characteristics of this namespace. |
| 1336 | DeclContext *DC, *LexicalDC; |
| 1337 | DeclarationName Name; |
| 1338 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1339 | NamedDecl *ToD; |
| 1340 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1341 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1342 | if (ToD) |
| 1343 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1344 | |
| 1345 | NamespaceDecl *MergeWithNamespace = nullptr; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1346 | if (!Name) { |
| 1347 | // This is an anonymous namespace. Adopt an existing anonymous |
| 1348 | // namespace if we can. |
| 1349 | // FIXME: Not testable. |
| 1350 | if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| 1351 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 1352 | else |
| 1353 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 1354 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1355 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1356 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1357 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1358 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1359 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1360 | continue; |
| 1361 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1362 | if (NamespaceDecl *FoundNS = dyn_cast<NamespaceDecl>(FoundDecls[I])) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1363 | MergeWithNamespace = FoundNS; |
| 1364 | ConflictingDecls.clear(); |
| 1365 | break; |
| 1366 | } |
| 1367 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1368 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | if (!ConflictingDecls.empty()) { |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 1372 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1373 | ConflictingDecls.data(), |
| 1374 | ConflictingDecls.size()); |
| 1375 | } |
| 1376 | } |
| 1377 | |
| 1378 | // Create the "to" namespace, if needed. |
| 1379 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 1380 | if (!ToNamespace) { |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 1381 | ToNamespace = NamespaceDecl::Create(Importer.getToContext(), DC, |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1382 | D->isInline(), |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 1383 | Importer.Import(D->getLocStart()), |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1384 | Loc, Name.getAsIdentifierInfo(), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1385 | /*PrevDecl=*/nullptr); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1386 | ToNamespace->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1387 | LexicalDC->addDeclInternal(ToNamespace); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1388 | |
| 1389 | // If this is an anonymous namespace, register it as the anonymous |
| 1390 | // namespace within its context. |
| 1391 | if (!Name) { |
| 1392 | if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| 1393 | TU->setAnonymousNamespace(ToNamespace); |
| 1394 | else |
| 1395 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 1396 | } |
| 1397 | } |
| 1398 | Importer.Imported(D, ToNamespace); |
| 1399 | |
| 1400 | ImportDeclContext(D); |
| 1401 | |
| 1402 | return ToNamespace; |
| 1403 | } |
| 1404 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1405 | Decl *ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1406 | // Import the major distinguishing characteristics of this typedef. |
| 1407 | DeclContext *DC, *LexicalDC; |
| 1408 | DeclarationName Name; |
| 1409 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1410 | NamedDecl *ToD; |
| 1411 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1412 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1413 | if (ToD) |
| 1414 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1415 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1416 | // If this typedef is not in block scope, determine whether we've |
| 1417 | // seen a typedef with the same name (that we can merge with) or any |
| 1418 | // other entity by that name (which name lookup could conflict with). |
| 1419 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1420 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1421 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1422 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1423 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1424 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1425 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1426 | continue; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1427 | if (TypedefNameDecl *FoundTypedef = |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1428 | dyn_cast<TypedefNameDecl>(FoundDecls[I])) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1429 | if (Importer.IsStructurallyEquivalent(D->getUnderlyingType(), |
| 1430 | FoundTypedef->getUnderlyingType())) |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1431 | return Importer.Imported(D, FoundTypedef); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1432 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1433 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1434 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1435 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1436 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1437 | if (!ConflictingDecls.empty()) { |
| 1438 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1439 | ConflictingDecls.data(), |
| 1440 | ConflictingDecls.size()); |
| 1441 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1442 | return nullptr; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1443 | } |
| 1444 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1445 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1446 | // Import the underlying type of this typedef; |
| 1447 | QualType T = Importer.Import(D->getUnderlyingType()); |
| 1448 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1449 | return nullptr; |
| 1450 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1451 | // Create the new typedef node. |
| 1452 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 1453 | SourceLocation StartL = Importer.Import(D->getLocStart()); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1454 | TypedefNameDecl *ToTypedef; |
| 1455 | if (IsAlias) |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 1456 | ToTypedef = TypeAliasDecl::Create(Importer.getToContext(), DC, |
| 1457 | StartL, Loc, |
| 1458 | Name.getAsIdentifierInfo(), |
| 1459 | TInfo); |
| 1460 | else |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1461 | ToTypedef = TypedefDecl::Create(Importer.getToContext(), DC, |
| 1462 | StartL, Loc, |
| 1463 | Name.getAsIdentifierInfo(), |
| 1464 | TInfo); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1465 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1466 | ToTypedef->setAccess(D->getAccess()); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1467 | ToTypedef->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1468 | Importer.Imported(D, ToTypedef); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1469 | LexicalDC->addDeclInternal(ToTypedef); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1470 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1471 | return ToTypedef; |
| 1472 | } |
| 1473 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1474 | Decl *ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
| 1475 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 1476 | } |
| 1477 | |
| 1478 | Decl *ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| 1479 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 1480 | } |
| 1481 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1482 | Decl *ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
| 1483 | // Import the major distinguishing characteristics of this label. |
| 1484 | DeclContext *DC, *LexicalDC; |
| 1485 | DeclarationName Name; |
| 1486 | SourceLocation Loc; |
| 1487 | NamedDecl *ToD; |
| 1488 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 1489 | return nullptr; |
| 1490 | if (ToD) |
| 1491 | return ToD; |
| 1492 | |
| 1493 | assert(LexicalDC->isFunctionOrMethod()); |
| 1494 | |
| 1495 | LabelDecl *ToLabel = D->isGnuLocal() |
| 1496 | ? LabelDecl::Create(Importer.getToContext(), |
| 1497 | DC, Importer.Import(D->getLocation()), |
| 1498 | Name.getAsIdentifierInfo(), |
| 1499 | Importer.Import(D->getLocStart())) |
| 1500 | : LabelDecl::Create(Importer.getToContext(), |
| 1501 | DC, Importer.Import(D->getLocation()), |
| 1502 | Name.getAsIdentifierInfo()); |
| 1503 | Importer.Imported(D, ToLabel); |
| 1504 | |
| 1505 | LabelStmt *Label = cast_or_null<LabelStmt>(Importer.Import(D->getStmt())); |
| 1506 | if (!Label) |
| 1507 | return nullptr; |
| 1508 | |
| 1509 | ToLabel->setStmt(Label); |
| 1510 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 1511 | LexicalDC->addDeclInternal(ToLabel); |
| 1512 | return ToLabel; |
| 1513 | } |
| 1514 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1515 | Decl *ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
| 1516 | // Import the major distinguishing characteristics of this enum. |
| 1517 | DeclContext *DC, *LexicalDC; |
| 1518 | DeclarationName Name; |
| 1519 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1520 | NamedDecl *ToD; |
| 1521 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1522 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1523 | if (ToD) |
| 1524 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1525 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1526 | // Figure out what enum name we're looking for. |
| 1527 | unsigned IDNS = Decl::IDNS_Tag; |
| 1528 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1529 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 1530 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1531 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1532 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1533 | IDNS |= Decl::IDNS_Ordinary; |
| 1534 | |
| 1535 | // We may already have an enum of the same name; try to find and match it. |
| 1536 | if (!DC->isFunctionOrMethod() && SearchName) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1537 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1538 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 1539 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1540 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1541 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1542 | continue; |
| 1543 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1544 | Decl *Found = FoundDecls[I]; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1545 | if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1546 | if (const TagType *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| 1547 | Found = Tag->getDecl(); |
| 1548 | } |
| 1549 | |
| 1550 | if (EnumDecl *FoundEnum = dyn_cast<EnumDecl>(Found)) { |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1551 | if (IsStructuralMatch(D, FoundEnum)) |
| 1552 | return Importer.Imported(D, FoundEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1553 | } |
| 1554 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1555 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | if (!ConflictingDecls.empty()) { |
| 1559 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1560 | ConflictingDecls.data(), |
| 1561 | ConflictingDecls.size()); |
| 1562 | } |
| 1563 | } |
| 1564 | |
| 1565 | // Create the enum declaration. |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 1566 | EnumDecl *D2 = EnumDecl::Create(Importer.getToContext(), DC, |
| 1567 | Importer.Import(D->getLocStart()), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1568 | Loc, Name.getAsIdentifierInfo(), nullptr, |
Abramo Bagnara | 0e05e24 | 2010-12-03 18:54:17 +0000 | [diff] [blame] | 1569 | D->isScoped(), D->isScopedUsingClassTag(), |
| 1570 | D->isFixed()); |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 1571 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 1572 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1573 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1574 | D2->setLexicalDeclContext(LexicalDC); |
| 1575 | Importer.Imported(D, D2); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1576 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1577 | |
| 1578 | // Import the integer type. |
| 1579 | QualType ToIntegerType = Importer.Import(D->getIntegerType()); |
| 1580 | if (ToIntegerType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1581 | return nullptr; |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1582 | D2->setIntegerType(ToIntegerType); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1583 | |
| 1584 | // Import the definition |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 1585 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1586 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1587 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1588 | return D2; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1589 | } |
| 1590 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1591 | Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
| 1592 | // If this record has a definition in the translation unit we're coming from, |
| 1593 | // but this particular declaration is not that definition, import the |
| 1594 | // definition and map to that. |
Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 1595 | TagDecl *Definition = D->getDefinition(); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1596 | if (Definition && Definition != D) { |
| 1597 | Decl *ImportedDef = Importer.Import(Definition); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1598 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1599 | return nullptr; |
| 1600 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1601 | return Importer.Imported(D, ImportedDef); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | // Import the major distinguishing characteristics of this record. |
| 1605 | DeclContext *DC, *LexicalDC; |
| 1606 | DeclarationName Name; |
| 1607 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1608 | NamedDecl *ToD; |
| 1609 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1610 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1611 | if (ToD) |
| 1612 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1613 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1614 | // Figure out what structure name we're looking for. |
| 1615 | unsigned IDNS = Decl::IDNS_Tag; |
| 1616 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1617 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 1618 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1619 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1620 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1621 | IDNS |= Decl::IDNS_Ordinary; |
| 1622 | |
| 1623 | // 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] | 1624 | RecordDecl *AdoptDecl = nullptr; |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame^] | 1625 | RecordDecl *PrevDecl = nullptr; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1626 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1627 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1628 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 1629 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame^] | 1630 | |
| 1631 | if (!FoundDecls.empty()) { |
| 1632 | // We're going to have to compare D against potentially conflicting Decls, so complete it. |
| 1633 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 1634 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 1635 | } |
| 1636 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1637 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1638 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1639 | continue; |
| 1640 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1641 | Decl *Found = FoundDecls[I]; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1642 | if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1643 | if (const TagType *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| 1644 | Found = Tag->getDecl(); |
| 1645 | } |
| 1646 | |
| 1647 | if (RecordDecl *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
Gabor Horvath | 3b392bb | 2017-04-03 21:06:45 +0000 | [diff] [blame] | 1648 | if (D->isAnonymousStructOrUnion() && |
| 1649 | FoundRecord->isAnonymousStructOrUnion()) { |
| 1650 | // If both anonymous structs/unions are in a record context, make sure |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 1651 | // they occur in the same location in the context records. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1652 | if (Optional<unsigned> Index1 = |
| 1653 | StructuralEquivalenceContext::findUntaggedStructOrUnionIndex( |
| 1654 | D)) { |
| 1655 | if (Optional<unsigned> Index2 = StructuralEquivalenceContext:: |
Sean Callanan | 488f861 | 2016-07-14 19:53:44 +0000 | [diff] [blame] | 1656 | findUntaggedStructOrUnionIndex(FoundRecord)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 1657 | if (*Index1 != *Index2) |
| 1658 | continue; |
| 1659 | } |
| 1660 | } |
| 1661 | } |
| 1662 | |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame^] | 1663 | PrevDecl = FoundRecord; |
| 1664 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1665 | if (RecordDecl *FoundDef = FoundRecord->getDefinition()) { |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1666 | if ((SearchName && !D->isCompleteDefinition()) |
| 1667 | || (D->isCompleteDefinition() && |
| 1668 | D->isAnonymousStructOrUnion() |
| 1669 | == FoundDef->isAnonymousStructOrUnion() && |
| 1670 | IsStructuralMatch(D, FoundDef))) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1671 | // The record types structurally match, or the "from" translation |
| 1672 | // unit only had a forward declaration anyway; call it the same |
| 1673 | // function. |
| 1674 | // FIXME: For C++, we should also merge methods here. |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1675 | return Importer.Imported(D, FoundDef); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1676 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1677 | } else if (!D->isCompleteDefinition()) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1678 | // We have a forward declaration of this type, so adopt that forward |
| 1679 | // declaration rather than building a new one. |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 1680 | |
| 1681 | // If one or both can be completed from external storage then try one |
| 1682 | // last time to complete and compare them before doing this. |
| 1683 | |
| 1684 | if (FoundRecord->hasExternalLexicalStorage() && |
| 1685 | !FoundRecord->isCompleteDefinition()) |
| 1686 | FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord); |
| 1687 | if (D->hasExternalLexicalStorage()) |
| 1688 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 1689 | |
| 1690 | if (FoundRecord->isCompleteDefinition() && |
| 1691 | D->isCompleteDefinition() && |
| 1692 | !IsStructuralMatch(D, FoundRecord)) |
| 1693 | continue; |
| 1694 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1695 | AdoptDecl = FoundRecord; |
| 1696 | continue; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1697 | } else if (!SearchName) { |
| 1698 | continue; |
| 1699 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1702 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1703 | } |
| 1704 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1705 | if (!ConflictingDecls.empty() && SearchName) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1706 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1707 | ConflictingDecls.data(), |
| 1708 | ConflictingDecls.size()); |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | // Create the record declaration. |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1713 | RecordDecl *D2 = AdoptDecl; |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 1714 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1715 | if (!D2) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 1716 | CXXRecordDecl *D2CXX = nullptr; |
| 1717 | if (CXXRecordDecl *DCXX = llvm::dyn_cast<CXXRecordDecl>(D)) { |
| 1718 | if (DCXX->isLambda()) { |
| 1719 | TypeSourceInfo *TInfo = Importer.Import(DCXX->getLambdaTypeInfo()); |
| 1720 | D2CXX = CXXRecordDecl::CreateLambda(Importer.getToContext(), |
| 1721 | DC, TInfo, Loc, |
| 1722 | DCXX->isDependentLambda(), |
| 1723 | DCXX->isGenericLambda(), |
| 1724 | DCXX->getLambdaCaptureDefault()); |
| 1725 | Decl *CDecl = Importer.Import(DCXX->getLambdaContextDecl()); |
| 1726 | if (DCXX->getLambdaContextDecl() && !CDecl) |
| 1727 | return nullptr; |
Sean Callanan | 041cceb | 2016-05-14 05:43:57 +0000 | [diff] [blame] | 1728 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), CDecl); |
| 1729 | } else if (DCXX->isInjectedClassName()) { |
| 1730 | // We have to be careful to do a similar dance to the one in |
| 1731 | // Sema::ActOnStartCXXMemberDeclarations |
| 1732 | CXXRecordDecl *const PrevDecl = nullptr; |
| 1733 | const bool DelayTypeCreation = true; |
| 1734 | D2CXX = CXXRecordDecl::Create( |
| 1735 | Importer.getToContext(), D->getTagKind(), DC, StartLoc, Loc, |
| 1736 | Name.getAsIdentifierInfo(), PrevDecl, DelayTypeCreation); |
| 1737 | Importer.getToContext().getTypeDeclType( |
| 1738 | D2CXX, llvm::dyn_cast<CXXRecordDecl>(DC)); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 1739 | } else { |
| 1740 | D2CXX = CXXRecordDecl::Create(Importer.getToContext(), |
| 1741 | D->getTagKind(), |
| 1742 | DC, StartLoc, Loc, |
| 1743 | Name.getAsIdentifierInfo()); |
| 1744 | } |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1745 | D2 = D2CXX; |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1746 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1747 | } else { |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1748 | D2 = RecordDecl::Create(Importer.getToContext(), D->getTagKind(), |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 1749 | DC, StartLoc, Loc, Name.getAsIdentifierInfo()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1750 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 1751 | |
| 1752 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1753 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1754 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1755 | if (D->isAnonymousStructOrUnion()) |
| 1756 | D2->setAnonymousStructOrUnion(true); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame^] | 1757 | if (PrevDecl) { |
| 1758 | // FIXME: do this for all Redeclarables, not just RecordDecls. |
| 1759 | D2->setPreviousDecl(PrevDecl); |
| 1760 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1761 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1762 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1763 | Importer.Imported(D, D2); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 1764 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1765 | if (D->isCompleteDefinition() && ImportDefinition(D, D2, IDK_Default)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1766 | return nullptr; |
| 1767 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1768 | return D2; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1769 | } |
| 1770 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1771 | Decl *ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| 1772 | // Import the major distinguishing characteristics of this enumerator. |
| 1773 | DeclContext *DC, *LexicalDC; |
| 1774 | DeclarationName Name; |
| 1775 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1776 | NamedDecl *ToD; |
| 1777 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1778 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1779 | if (ToD) |
| 1780 | return ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1781 | |
| 1782 | QualType T = Importer.Import(D->getType()); |
| 1783 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1784 | return nullptr; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1785 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1786 | // Determine whether there are any other declarations with the same name and |
| 1787 | // in the same context. |
| 1788 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1789 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1790 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1791 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1792 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1793 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1794 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1795 | continue; |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1796 | |
| 1797 | if (EnumConstantDecl *FoundEnumConstant |
| 1798 | = dyn_cast<EnumConstantDecl>(FoundDecls[I])) { |
| 1799 | if (IsStructuralMatch(D, FoundEnumConstant)) |
| 1800 | return Importer.Imported(D, FoundEnumConstant); |
| 1801 | } |
| 1802 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1803 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1804 | } |
| 1805 | |
| 1806 | if (!ConflictingDecls.empty()) { |
| 1807 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1808 | ConflictingDecls.data(), |
| 1809 | ConflictingDecls.size()); |
| 1810 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1811 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | Expr *Init = Importer.Import(D->getInitExpr()); |
| 1816 | if (D->getInitExpr() && !Init) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1817 | return nullptr; |
| 1818 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1819 | EnumConstantDecl *ToEnumerator |
| 1820 | = EnumConstantDecl::Create(Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
| 1821 | Name.getAsIdentifierInfo(), T, |
| 1822 | Init, D->getInitVal()); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1823 | ToEnumerator->setAccess(D->getAccess()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1824 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1825 | Importer.Imported(D, ToEnumerator); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1826 | LexicalDC->addDeclInternal(ToEnumerator); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1827 | return ToEnumerator; |
| 1828 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1829 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1830 | Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
| 1831 | // Import the major distinguishing characteristics of this function. |
| 1832 | DeclContext *DC, *LexicalDC; |
| 1833 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1834 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1835 | NamedDecl *ToD; |
| 1836 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1837 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1838 | if (ToD) |
| 1839 | return ToD; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1840 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1841 | // Try to find a function in our own ("to") context with the same name, same |
| 1842 | // type, and in the same context as the function we're importing. |
| 1843 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1844 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1845 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1846 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1847 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1848 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 1849 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1850 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1851 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1852 | if (FunctionDecl *FoundFunction = dyn_cast<FunctionDecl>(FoundDecls[I])) { |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 1853 | if (FoundFunction->hasExternalFormalLinkage() && |
| 1854 | D->hasExternalFormalLinkage()) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1855 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| 1856 | FoundFunction->getType())) { |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1857 | // FIXME: Actually try to merge the body and other attributes. |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1858 | return Importer.Imported(D, FoundFunction); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1859 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1860 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1861 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 1862 | // Sema::IsOverload out to the AST library. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1863 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1864 | // Function overloading is okay in C++. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1865 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1866 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1867 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1868 | // Complain about inconsistent function types. |
| 1869 | Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1870 | << Name << D->getType() << FoundFunction->getType(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1871 | Importer.ToDiag(FoundFunction->getLocation(), |
| 1872 | diag::note_odr_value_here) |
| 1873 | << FoundFunction->getType(); |
| 1874 | } |
| 1875 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1876 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 1877 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1878 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1879 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1880 | if (!ConflictingDecls.empty()) { |
| 1881 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1882 | ConflictingDecls.data(), |
| 1883 | ConflictingDecls.size()); |
| 1884 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1885 | return nullptr; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1886 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 1887 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1888 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1889 | DeclarationNameInfo NameInfo(Name, Loc); |
| 1890 | // Import additional name location/type info. |
| 1891 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 1892 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 1893 | QualType FromTy = D->getType(); |
| 1894 | bool usedDifferentExceptionSpec = false; |
| 1895 | |
| 1896 | if (const FunctionProtoType * |
| 1897 | FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
| 1898 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 1899 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 1900 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 1901 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 1902 | // with a simplified function type and update it afterwards. |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 1903 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 1904 | FromEPI.ExceptionSpec.SourceTemplate || |
| 1905 | FromEPI.ExceptionSpec.NoexceptExpr) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 1906 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 1907 | FromTy = Importer.getFromContext().getFunctionType( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 1908 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 1909 | usedDifferentExceptionSpec = true; |
| 1910 | } |
| 1911 | } |
| 1912 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1913 | // Import the type. |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 1914 | QualType T = Importer.Import(FromTy); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1915 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1916 | return nullptr; |
| 1917 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1918 | // Import the function parameters. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1919 | SmallVector<ParmVarDecl *, 8> Parameters; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 1920 | for (auto P : D->parameters()) { |
Aaron Ballman | f6bf62e | 2014-03-07 15:12:56 +0000 | [diff] [blame] | 1921 | ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(P)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1922 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1923 | return nullptr; |
| 1924 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1925 | Parameters.push_back(ToP); |
| 1926 | } |
| 1927 | |
| 1928 | // Create the imported function. |
| 1929 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1930 | FunctionDecl *ToFunction = nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1931 | SourceLocation InnerLocStart = Importer.Import(D->getInnerLocStart()); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 1932 | if (CXXConstructorDecl *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| 1933 | ToFunction = CXXConstructorDecl::Create(Importer.getToContext(), |
| 1934 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1935 | InnerLocStart, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1936 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 1937 | FromConstructor->isExplicit(), |
| 1938 | D->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1939 | D->isImplicit(), |
| 1940 | D->isConstexpr()); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 1941 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 1942 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers; |
| 1943 | for (CXXCtorInitializer *I : FromConstructor->inits()) { |
| 1944 | CXXCtorInitializer *ToI = |
| 1945 | cast_or_null<CXXCtorInitializer>(Importer.Import(I)); |
| 1946 | if (!ToI && I) |
| 1947 | return nullptr; |
| 1948 | CtorInitializers.push_back(ToI); |
| 1949 | } |
| 1950 | CXXCtorInitializer **Memory = |
| 1951 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 1952 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
| 1953 | CXXConstructorDecl *ToCtor = llvm::cast<CXXConstructorDecl>(ToFunction); |
| 1954 | ToCtor->setCtorInitializers(Memory); |
| 1955 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 1956 | } |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 1957 | } else if (isa<CXXDestructorDecl>(D)) { |
| 1958 | ToFunction = CXXDestructorDecl::Create(Importer.getToContext(), |
| 1959 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1960 | InnerLocStart, |
Craig Silverstein | af8808d | 2010-10-21 00:44:50 +0000 | [diff] [blame] | 1961 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 1962 | D->isInlineSpecified(), |
| 1963 | D->isImplicit()); |
| 1964 | } else if (CXXConversionDecl *FromConversion |
| 1965 | = dyn_cast<CXXConversionDecl>(D)) { |
| 1966 | ToFunction = CXXConversionDecl::Create(Importer.getToContext(), |
| 1967 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1968 | InnerLocStart, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1969 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 1970 | D->isInlineSpecified(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 1971 | FromConversion->isExplicit(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1972 | D->isConstexpr(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 1973 | Importer.Import(D->getLocEnd())); |
Douglas Gregor | a50ad13 | 2010-11-29 16:04:58 +0000 | [diff] [blame] | 1974 | } else if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { |
| 1975 | ToFunction = CXXMethodDecl::Create(Importer.getToContext(), |
| 1976 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1977 | InnerLocStart, |
Douglas Gregor | a50ad13 | 2010-11-29 16:04:58 +0000 | [diff] [blame] | 1978 | NameInfo, T, TInfo, |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 1979 | Method->getStorageClass(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 1980 | Method->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1981 | D->isConstexpr(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 1982 | Importer.Import(D->getLocEnd())); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 1983 | } else { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1984 | ToFunction = FunctionDecl::Create(Importer.getToContext(), DC, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1985 | InnerLocStart, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1986 | NameInfo, T, TInfo, D->getStorageClass(), |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 1987 | D->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1988 | D->hasWrittenPrototype(), |
| 1989 | D->isConstexpr()); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 1990 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 1991 | |
| 1992 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 1993 | ToFunction->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1994 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 1995 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 1996 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 1997 | ToFunction->setTrivial(D->isTrivial()); |
| 1998 | ToFunction->setPure(D->isPure()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 1999 | Importer.Imported(D, ToFunction); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2000 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2001 | // Set the parameters. |
| 2002 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2003 | Parameters[I]->setOwningFunction(ToFunction); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2004 | ToFunction->addDeclInternal(Parameters[I]); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2005 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 2006 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2007 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2008 | if (usedDifferentExceptionSpec) { |
| 2009 | // Update FunctionProtoType::ExtProtoInfo. |
| 2010 | QualType T = Importer.Import(D->getType()); |
| 2011 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2012 | return nullptr; |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2013 | ToFunction->setType(T); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2016 | // Import the body, if any. |
| 2017 | if (Stmt *FromBody = D->getBody()) { |
| 2018 | if (Stmt *ToBody = Importer.Import(FromBody)) { |
| 2019 | ToFunction->setBody(ToBody); |
| 2020 | } |
| 2021 | } |
| 2022 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2023 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2024 | |
| 2025 | // Add this function to the lexical context. |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2026 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2027 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2028 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2029 | } |
| 2030 | |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2031 | Decl *ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| 2032 | return VisitFunctionDecl(D); |
| 2033 | } |
| 2034 | |
| 2035 | Decl *ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| 2036 | return VisitCXXMethodDecl(D); |
| 2037 | } |
| 2038 | |
| 2039 | Decl *ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| 2040 | return VisitCXXMethodDecl(D); |
| 2041 | } |
| 2042 | |
| 2043 | Decl *ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| 2044 | return VisitCXXMethodDecl(D); |
| 2045 | } |
| 2046 | |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2047 | static unsigned getFieldIndex(Decl *F) { |
| 2048 | RecordDecl *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
| 2049 | if (!Owner) |
| 2050 | return 0; |
| 2051 | |
| 2052 | unsigned Index = 1; |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2053 | for (const auto *D : Owner->noload_decls()) { |
| 2054 | if (D == F) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2055 | return Index; |
| 2056 | |
| 2057 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 2058 | ++Index; |
| 2059 | } |
| 2060 | |
| 2061 | return Index; |
| 2062 | } |
| 2063 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2064 | Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
| 2065 | // Import the major distinguishing characteristics of a variable. |
| 2066 | DeclContext *DC, *LexicalDC; |
| 2067 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2068 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2069 | NamedDecl *ToD; |
| 2070 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2071 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2072 | if (ToD) |
| 2073 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2074 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2075 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2076 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2077 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2078 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2079 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2080 | // For anonymous fields, match up by index. |
| 2081 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2082 | continue; |
| 2083 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2084 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2085 | FoundField->getType())) { |
| 2086 | Importer.Imported(D, FoundField); |
| 2087 | return FoundField; |
| 2088 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2089 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2090 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2091 | << Name << D->getType() << FoundField->getType(); |
| 2092 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2093 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2094 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2095 | } |
| 2096 | } |
| 2097 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2098 | // Import the type. |
| 2099 | QualType T = Importer.Import(D->getType()); |
| 2100 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2101 | return nullptr; |
| 2102 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2103 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2104 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 2105 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2106 | return nullptr; |
| 2107 | |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2108 | FieldDecl *ToField = FieldDecl::Create(Importer.getToContext(), DC, |
| 2109 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2110 | Loc, Name.getAsIdentifierInfo(), |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2111 | T, TInfo, BitWidth, D->isMutable(), |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2112 | D->getInClassInitStyle()); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2113 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2114 | ToField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 3a83ea7 | 2016-03-03 02:22:05 +0000 | [diff] [blame] | 2115 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
Sean Callanan | bb33f58 | 2016-03-03 01:21:28 +0000 | [diff] [blame] | 2116 | Expr *ToInitializer = Importer.Import(FromInitializer); |
| 2117 | if (ToInitializer) |
| 2118 | ToField->setInClassInitializer(ToInitializer); |
| 2119 | else |
| 2120 | return nullptr; |
| 2121 | } |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2122 | ToField->setImplicit(D->isImplicit()); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2123 | Importer.Imported(D, ToField); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2124 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2125 | return ToField; |
| 2126 | } |
| 2127 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2128 | Decl *ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| 2129 | // Import the major distinguishing characteristics of a variable. |
| 2130 | DeclContext *DC, *LexicalDC; |
| 2131 | DeclarationName Name; |
| 2132 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2133 | NamedDecl *ToD; |
| 2134 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2135 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2136 | if (ToD) |
| 2137 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2138 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2139 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2140 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2141 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2142 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2143 | if (IndirectFieldDecl *FoundField |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2144 | = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2145 | // For anonymous indirect fields, match up by index. |
| 2146 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2147 | continue; |
| 2148 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2149 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2150 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 2151 | !Name.isEmpty())) { |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2152 | Importer.Imported(D, FoundField); |
| 2153 | return FoundField; |
| 2154 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2155 | |
| 2156 | // If there are more anonymous fields to check, continue. |
| 2157 | if (!Name && I < N-1) |
| 2158 | continue; |
| 2159 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2160 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2161 | << Name << D->getType() << FoundField->getType(); |
| 2162 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2163 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2164 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2165 | } |
| 2166 | } |
| 2167 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2168 | // Import the type. |
| 2169 | QualType T = Importer.Import(D->getType()); |
| 2170 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2171 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2172 | |
| 2173 | NamedDecl **NamedChain = |
| 2174 | new (Importer.getToContext())NamedDecl*[D->getChainingSize()]; |
| 2175 | |
| 2176 | unsigned i = 0; |
Aaron Ballman | 29c9460 | 2014-03-07 18:36:15 +0000 | [diff] [blame] | 2177 | for (auto *PI : D->chain()) { |
Aaron Ballman | 1391608 | 2014-03-07 18:11:58 +0000 | [diff] [blame] | 2178 | Decl *D = Importer.Import(PI); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2179 | if (!D) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2180 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2181 | NamedChain[i++] = cast<NamedDecl>(D); |
| 2182 | } |
| 2183 | |
| 2184 | IndirectFieldDecl *ToIndirectField = IndirectFieldDecl::Create( |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2185 | Importer.getToContext(), DC, Loc, Name.getAsIdentifierInfo(), T, |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2186 | {NamedChain, D->getChainingSize()}); |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2187 | |
| 2188 | for (const auto *Attr : D->attrs()) |
| 2189 | ToIndirectField->addAttr(Attr->clone(Importer.getToContext())); |
| 2190 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2191 | ToIndirectField->setAccess(D->getAccess()); |
| 2192 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
| 2193 | Importer.Imported(D, ToIndirectField); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2194 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2195 | return ToIndirectField; |
| 2196 | } |
| 2197 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2198 | Decl *ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
| 2199 | // Import the major distinguishing characteristics of a declaration. |
| 2200 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 2201 | DeclContext *LexicalDC = D->getDeclContext() == D->getLexicalDeclContext() |
| 2202 | ? DC : Importer.ImportContext(D->getLexicalDeclContext()); |
| 2203 | if (!DC || !LexicalDC) |
| 2204 | return nullptr; |
| 2205 | |
| 2206 | // Determine whether we've already imported this decl. |
| 2207 | // FriendDecl is not a NamedDecl so we cannot use localUncachedLookup. |
| 2208 | auto *RD = cast<CXXRecordDecl>(DC); |
| 2209 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
| 2210 | StructuralEquivalenceContext Context( |
| 2211 | Importer.getFromContext(), Importer.getToContext(), |
| 2212 | Importer.getNonEquivalentDecls(), false, false); |
| 2213 | |
| 2214 | while (ImportedFriend) { |
| 2215 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
| 2216 | if (Context.IsStructurallyEquivalent(D->getFriendDecl(), |
| 2217 | ImportedFriend->getFriendDecl())) |
| 2218 | return Importer.Imported(D, ImportedFriend); |
| 2219 | |
| 2220 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 2221 | if (Importer.IsStructurallyEquivalent( |
| 2222 | D->getFriendType()->getType(), |
| 2223 | ImportedFriend->getFriendType()->getType(), true)) |
| 2224 | return Importer.Imported(D, ImportedFriend); |
| 2225 | } |
| 2226 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 2227 | } |
| 2228 | |
| 2229 | // Not found. Create it. |
| 2230 | FriendDecl::FriendUnion ToFU; |
| 2231 | if (NamedDecl *FriendD = D->getFriendDecl()) |
| 2232 | ToFU = cast_or_null<NamedDecl>(Importer.Import(FriendD)); |
| 2233 | else |
| 2234 | ToFU = Importer.Import(D->getFriendType()); |
| 2235 | if (!ToFU) |
| 2236 | return nullptr; |
| 2237 | |
| 2238 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
| 2239 | TemplateParameterList **FromTPLists = |
| 2240 | D->getTrailingObjects<TemplateParameterList *>(); |
| 2241 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
| 2242 | TemplateParameterList *List = ImportTemplateParameterList(FromTPLists[I]); |
| 2243 | if (!List) |
| 2244 | return nullptr; |
| 2245 | ToTPLists[I] = List; |
| 2246 | } |
| 2247 | |
| 2248 | FriendDecl *FrD = FriendDecl::Create(Importer.getToContext(), DC, |
| 2249 | Importer.Import(D->getLocation()), |
| 2250 | ToFU, Importer.Import(D->getFriendLoc()), |
| 2251 | ToTPLists); |
| 2252 | |
| 2253 | Importer.Imported(D, FrD); |
| 2254 | RD->pushFriendDecl(FrD); |
| 2255 | |
| 2256 | FrD->setAccess(D->getAccess()); |
| 2257 | FrD->setLexicalDeclContext(LexicalDC); |
| 2258 | LexicalDC->addDeclInternal(FrD); |
| 2259 | return FrD; |
| 2260 | } |
| 2261 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2262 | Decl *ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| 2263 | // Import the major distinguishing characteristics of an ivar. |
| 2264 | DeclContext *DC, *LexicalDC; |
| 2265 | DeclarationName Name; |
| 2266 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2267 | NamedDecl *ToD; |
| 2268 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2269 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2270 | if (ToD) |
| 2271 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2272 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2273 | // Determine whether we've already imported this ivar |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2274 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2275 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2276 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2277 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecls[I])) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2278 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2279 | FoundIvar->getType())) { |
| 2280 | Importer.Imported(D, FoundIvar); |
| 2281 | return FoundIvar; |
| 2282 | } |
| 2283 | |
| 2284 | Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent) |
| 2285 | << Name << D->getType() << FoundIvar->getType(); |
| 2286 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 2287 | << FoundIvar->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2288 | return nullptr; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2289 | } |
| 2290 | } |
| 2291 | |
| 2292 | // Import the type. |
| 2293 | QualType T = Importer.Import(D->getType()); |
| 2294 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2295 | return nullptr; |
| 2296 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2297 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2298 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 2299 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2300 | return nullptr; |
| 2301 | |
Daniel Dunbar | fe3ead7 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 2302 | ObjCIvarDecl *ToIvar = ObjCIvarDecl::Create(Importer.getToContext(), |
| 2303 | cast<ObjCContainerDecl>(DC), |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2304 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2305 | Loc, Name.getAsIdentifierInfo(), |
| 2306 | T, TInfo, D->getAccessControl(), |
Argyrios Kyrtzidis | 2080d90 | 2014-01-03 18:32:18 +0000 | [diff] [blame] | 2307 | BitWidth, D->getSynthesize()); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2308 | ToIvar->setLexicalDeclContext(LexicalDC); |
| 2309 | Importer.Imported(D, ToIvar); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2310 | LexicalDC->addDeclInternal(ToIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2311 | return ToIvar; |
| 2312 | |
| 2313 | } |
| 2314 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2315 | Decl *ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
| 2316 | // Import the major distinguishing characteristics of a variable. |
| 2317 | DeclContext *DC, *LexicalDC; |
| 2318 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2319 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2320 | NamedDecl *ToD; |
| 2321 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2322 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2323 | if (ToD) |
| 2324 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2325 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2326 | // Try to find a variable in our own ("to") context with the same name and |
| 2327 | // in the same context as the variable we're importing. |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2328 | if (D->isFileVarDecl()) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2329 | VarDecl *MergeWithVar = nullptr; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2330 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2331 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2332 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2333 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2334 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2335 | if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2336 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2337 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2338 | if (VarDecl *FoundVar = dyn_cast<VarDecl>(FoundDecls[I])) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2339 | // 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] | 2340 | if (FoundVar->hasExternalFormalLinkage() && |
| 2341 | D->hasExternalFormalLinkage()) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2342 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2343 | FoundVar->getType())) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2344 | MergeWithVar = FoundVar; |
| 2345 | break; |
| 2346 | } |
| 2347 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2348 | const ArrayType *FoundArray |
| 2349 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 2350 | const ArrayType *TArray |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2351 | = Importer.getToContext().getAsArrayType(D->getType()); |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2352 | if (FoundArray && TArray) { |
| 2353 | if (isa<IncompleteArrayType>(FoundArray) && |
| 2354 | isa<ConstantArrayType>(TArray)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2355 | // Import the type. |
| 2356 | QualType T = Importer.Import(D->getType()); |
| 2357 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2358 | return nullptr; |
| 2359 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2360 | FoundVar->setType(T); |
| 2361 | MergeWithVar = FoundVar; |
| 2362 | break; |
| 2363 | } else if (isa<IncompleteArrayType>(TArray) && |
| 2364 | isa<ConstantArrayType>(FoundArray)) { |
| 2365 | MergeWithVar = FoundVar; |
| 2366 | break; |
Douglas Gregor | 2fbe558 | 2010-02-10 17:16:49 +0000 | [diff] [blame] | 2367 | } |
| 2368 | } |
| 2369 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2370 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2371 | << Name << D->getType() << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2372 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 2373 | << FoundVar->getType(); |
| 2374 | } |
| 2375 | } |
| 2376 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2377 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | if (MergeWithVar) { |
| 2381 | // An equivalent variable with external linkage has been found. Link |
| 2382 | // the two declarations, then merge them. |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2383 | Importer.Imported(D, MergeWithVar); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2384 | |
| 2385 | if (VarDecl *DDef = D->getDefinition()) { |
| 2386 | if (VarDecl *ExistingDef = MergeWithVar->getDefinition()) { |
| 2387 | Importer.ToDiag(ExistingDef->getLocation(), |
| 2388 | diag::err_odr_variable_multiple_def) |
| 2389 | << Name; |
| 2390 | Importer.FromDiag(DDef->getLocation(), diag::note_odr_defined_here); |
| 2391 | } else { |
| 2392 | Expr *Init = Importer.Import(DDef->getInit()); |
Douglas Gregor | d505812 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 2393 | MergeWithVar->setInit(Init); |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 2394 | if (DDef->isInitKnownICE()) { |
| 2395 | EvaluatedStmt *Eval = MergeWithVar->ensureEvaluatedStmt(); |
| 2396 | Eval->CheckedICE = true; |
| 2397 | Eval->IsICE = DDef->isInitICE(); |
| 2398 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2399 | } |
| 2400 | } |
| 2401 | |
| 2402 | return MergeWithVar; |
| 2403 | } |
| 2404 | |
| 2405 | if (!ConflictingDecls.empty()) { |
| 2406 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2407 | ConflictingDecls.data(), |
| 2408 | ConflictingDecls.size()); |
| 2409 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2410 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2411 | } |
| 2412 | } |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2413 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2414 | // Import the type. |
| 2415 | QualType T = Importer.Import(D->getType()); |
| 2416 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2417 | return nullptr; |
| 2418 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2419 | // Create the imported variable. |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2420 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2421 | VarDecl *ToVar = VarDecl::Create(Importer.getToContext(), DC, |
| 2422 | Importer.Import(D->getInnerLocStart()), |
| 2423 | Loc, Name.getAsIdentifierInfo(), |
| 2424 | T, TInfo, |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 2425 | D->getStorageClass()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2426 | ToVar->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2427 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2428 | ToVar->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2429 | Importer.Imported(D, ToVar); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2430 | LexicalDC->addDeclInternal(ToVar); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2431 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2432 | if (!D->isFileVarDecl() && |
| 2433 | D->isUsed()) |
| 2434 | ToVar->setIsUsed(); |
| 2435 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2436 | // Merge the initializer. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2437 | if (ImportDefinition(D, ToVar)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2438 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2439 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 2440 | if (D->isConstexpr()) |
| 2441 | ToVar->setConstexpr(true); |
| 2442 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2443 | return ToVar; |
| 2444 | } |
| 2445 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2446 | Decl *ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| 2447 | // Parameters are created in the translation unit's context, then moved |
| 2448 | // into the function declaration's context afterward. |
| 2449 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| 2450 | |
| 2451 | // Import the name of this declaration. |
| 2452 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 2453 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2454 | return nullptr; |
| 2455 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2456 | // Import the location of this declaration. |
| 2457 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 2458 | |
| 2459 | // Import the parameter's type. |
| 2460 | QualType T = Importer.Import(D->getType()); |
| 2461 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2462 | return nullptr; |
| 2463 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2464 | // Create the imported parameter. |
| 2465 | ImplicitParamDecl *ToParm |
| 2466 | = ImplicitParamDecl::Create(Importer.getToContext(), DC, |
| 2467 | Loc, Name.getAsIdentifierInfo(), |
| 2468 | T); |
| 2469 | return Importer.Imported(D, ToParm); |
| 2470 | } |
| 2471 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2472 | Decl *ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
| 2473 | // Parameters are created in the translation unit's context, then moved |
| 2474 | // into the function declaration's context afterward. |
| 2475 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| 2476 | |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2477 | // Import the name of this declaration. |
| 2478 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 2479 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2480 | return nullptr; |
| 2481 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2482 | // Import the location of this declaration. |
| 2483 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 2484 | |
| 2485 | // Import the parameter's type. |
| 2486 | QualType T = Importer.Import(D->getType()); |
| 2487 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2488 | return nullptr; |
| 2489 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2490 | // Create the imported parameter. |
| 2491 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2492 | ParmVarDecl *ToParm = ParmVarDecl::Create(Importer.getToContext(), DC, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2493 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2494 | Loc, Name.getAsIdentifierInfo(), |
| 2495 | T, TInfo, D->getStorageClass(), |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 2496 | /*DefaultArg*/ nullptr); |
| 2497 | |
| 2498 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 2499 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 2500 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 2501 | |
| 2502 | Expr *ToDefArg = nullptr; |
| 2503 | Expr *FromDefArg = nullptr; |
| 2504 | if (D->hasUninstantiatedDefaultArg()) { |
| 2505 | FromDefArg = D->getUninstantiatedDefaultArg(); |
| 2506 | ToDefArg = Importer.Import(FromDefArg); |
| 2507 | ToParm->setUninstantiatedDefaultArg(ToDefArg); |
| 2508 | } else if (D->hasUnparsedDefaultArg()) { |
| 2509 | ToParm->setUnparsedDefaultArg(); |
| 2510 | } else if (D->hasDefaultArg()) { |
| 2511 | FromDefArg = D->getDefaultArg(); |
| 2512 | ToDefArg = Importer.Import(FromDefArg); |
| 2513 | ToParm->setDefaultArg(ToDefArg); |
| 2514 | } |
| 2515 | if (FromDefArg && !ToDefArg) |
| 2516 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2517 | |
| 2518 | if (D->isUsed()) |
| 2519 | ToParm->setIsUsed(); |
| 2520 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2521 | return Importer.Imported(D, ToParm); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2522 | } |
| 2523 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2524 | Decl *ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| 2525 | // Import the major distinguishing characteristics of a method. |
| 2526 | DeclContext *DC, *LexicalDC; |
| 2527 | DeclarationName Name; |
| 2528 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2529 | NamedDecl *ToD; |
| 2530 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2531 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2532 | if (ToD) |
| 2533 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2534 | |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2535 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2536 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2537 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2538 | if (ObjCMethodDecl *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecls[I])) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2539 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 2540 | continue; |
| 2541 | |
| 2542 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2543 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 2544 | FoundMethod->getReturnType())) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2545 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2546 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 2547 | << FoundMethod->getReturnType(); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2548 | Importer.ToDiag(FoundMethod->getLocation(), |
| 2549 | diag::note_odr_objc_method_here) |
| 2550 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2551 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | // Check the number of parameters. |
| 2555 | if (D->param_size() != FoundMethod->param_size()) { |
| 2556 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) |
| 2557 | << D->isInstanceMethod() << Name |
| 2558 | << D->param_size() << FoundMethod->param_size(); |
| 2559 | Importer.ToDiag(FoundMethod->getLocation(), |
| 2560 | diag::note_odr_objc_method_here) |
| 2561 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2562 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2563 | } |
| 2564 | |
| 2565 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2566 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2567 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 2568 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2569 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2570 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2571 | Importer.FromDiag((*P)->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2572 | diag::err_odr_objc_method_param_type_inconsistent) |
| 2573 | << D->isInstanceMethod() << Name |
| 2574 | << (*P)->getType() << (*FoundP)->getType(); |
| 2575 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 2576 | << (*FoundP)->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2577 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2578 | } |
| 2579 | } |
| 2580 | |
| 2581 | // Check variadic/non-variadic. |
| 2582 | // Check the number of parameters. |
| 2583 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| 2584 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) |
| 2585 | << D->isInstanceMethod() << Name; |
| 2586 | Importer.ToDiag(FoundMethod->getLocation(), |
| 2587 | diag::note_odr_objc_method_here) |
| 2588 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2589 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2590 | } |
| 2591 | |
| 2592 | // FIXME: Any other bits we need to merge? |
| 2593 | return Importer.Imported(D, FoundMethod); |
| 2594 | } |
| 2595 | } |
| 2596 | |
| 2597 | // Import the result type. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2598 | QualType ResultTy = Importer.Import(D->getReturnType()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2599 | if (ResultTy.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2600 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2601 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2602 | TypeSourceInfo *ReturnTInfo = Importer.Import(D->getReturnTypeSourceInfo()); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 2603 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2604 | ObjCMethodDecl *ToMethod = ObjCMethodDecl::Create( |
| 2605 | Importer.getToContext(), Loc, Importer.Import(D->getLocEnd()), |
| 2606 | Name.getObjCSelector(), ResultTy, ReturnTInfo, DC, D->isInstanceMethod(), |
| 2607 | D->isVariadic(), D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 2608 | D->getImplementationControl(), D->hasRelatedResultType()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2609 | |
| 2610 | // FIXME: When we decide to merge method definitions, we'll need to |
| 2611 | // deal with implicit parameters. |
| 2612 | |
| 2613 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2614 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2615 | for (auto *FromP : D->parameters()) { |
Aaron Ballman | 43b68be | 2014-03-07 17:50:17 +0000 | [diff] [blame] | 2616 | ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(FromP)); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2617 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2618 | return nullptr; |
| 2619 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2620 | ToParams.push_back(ToP); |
| 2621 | } |
| 2622 | |
| 2623 | // Set the parameters. |
| 2624 | for (unsigned I = 0, N = ToParams.size(); I != N; ++I) { |
| 2625 | ToParams[I]->setOwningFunction(ToMethod); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2626 | ToMethod->addDeclInternal(ToParams[I]); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2627 | } |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 2628 | SmallVector<SourceLocation, 12> SelLocs; |
| 2629 | D->getSelectorLocs(SelLocs); |
| 2630 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, SelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2631 | |
| 2632 | ToMethod->setLexicalDeclContext(LexicalDC); |
| 2633 | Importer.Imported(D, ToMethod); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2634 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2635 | return ToMethod; |
| 2636 | } |
| 2637 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 2638 | Decl *ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| 2639 | // Import the major distinguishing characteristics of a category. |
| 2640 | DeclContext *DC, *LexicalDC; |
| 2641 | DeclarationName Name; |
| 2642 | SourceLocation Loc; |
| 2643 | NamedDecl *ToD; |
| 2644 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2645 | return nullptr; |
| 2646 | if (ToD) |
| 2647 | return ToD; |
| 2648 | |
| 2649 | TypeSourceInfo *BoundInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2650 | if (!BoundInfo) |
| 2651 | return nullptr; |
| 2652 | |
| 2653 | ObjCTypeParamDecl *Result = ObjCTypeParamDecl::Create( |
| 2654 | Importer.getToContext(), DC, |
Douglas Gregor | 1ac1b63 | 2015-07-07 03:58:54 +0000 | [diff] [blame] | 2655 | D->getVariance(), |
| 2656 | Importer.Import(D->getVarianceLoc()), |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 2657 | D->getIndex(), |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 2658 | Importer.Import(D->getLocation()), |
| 2659 | Name.getAsIdentifierInfo(), |
| 2660 | Importer.Import(D->getColonLoc()), |
| 2661 | BoundInfo); |
| 2662 | Importer.Imported(D, Result); |
| 2663 | Result->setLexicalDeclContext(LexicalDC); |
| 2664 | return Result; |
| 2665 | } |
| 2666 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2667 | Decl *ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| 2668 | // Import the major distinguishing characteristics of a category. |
| 2669 | DeclContext *DC, *LexicalDC; |
| 2670 | DeclarationName Name; |
| 2671 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2672 | NamedDecl *ToD; |
| 2673 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2674 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2675 | if (ToD) |
| 2676 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2677 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2678 | ObjCInterfaceDecl *ToInterface |
| 2679 | = cast_or_null<ObjCInterfaceDecl>(Importer.Import(D->getClassInterface())); |
| 2680 | if (!ToInterface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2681 | return nullptr; |
| 2682 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2683 | // Determine if we've already encountered this category. |
| 2684 | ObjCCategoryDecl *MergeWithCategory |
| 2685 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 2686 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 2687 | if (!ToCategory) { |
| 2688 | ToCategory = ObjCCategoryDecl::Create(Importer.getToContext(), DC, |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 2689 | Importer.Import(D->getAtStartLoc()), |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2690 | Loc, |
| 2691 | Importer.Import(D->getCategoryNameLoc()), |
Argyrios Kyrtzidis | 3a5094b | 2011-08-30 19:43:26 +0000 | [diff] [blame] | 2692 | Name.getAsIdentifierInfo(), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 2693 | ToInterface, |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 2694 | /*TypeParamList=*/nullptr, |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 2695 | Importer.Import(D->getIvarLBraceLoc()), |
| 2696 | Importer.Import(D->getIvarRBraceLoc())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2697 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2698 | LexicalDC->addDeclInternal(ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2699 | Importer.Imported(D, ToCategory); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 2700 | // Import the type parameter list after calling Imported, to avoid |
| 2701 | // loops when bringing in their DeclContext. |
| 2702 | ToCategory->setTypeParamList(ImportObjCTypeParamList( |
| 2703 | D->getTypeParamList())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2704 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2705 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2706 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 2707 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2708 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 2709 | = D->protocol_loc_begin(); |
| 2710 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 2711 | FromProtoEnd = D->protocol_end(); |
| 2712 | FromProto != FromProtoEnd; |
| 2713 | ++FromProto, ++FromProtoLoc) { |
| 2714 | ObjCProtocolDecl *ToProto |
| 2715 | = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
| 2716 | if (!ToProto) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2717 | return nullptr; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2718 | Protocols.push_back(ToProto); |
| 2719 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 2720 | } |
| 2721 | |
| 2722 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 2723 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 2724 | ProtocolLocs.data(), Importer.getToContext()); |
| 2725 | |
| 2726 | } else { |
| 2727 | Importer.Imported(D, ToCategory); |
| 2728 | } |
| 2729 | |
| 2730 | // Import all of the members of this category. |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 2731 | ImportDeclContext(D); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2732 | |
| 2733 | // If we have an implementation, import it as well. |
| 2734 | if (D->getImplementation()) { |
| 2735 | ObjCCategoryImplDecl *Impl |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 2736 | = cast_or_null<ObjCCategoryImplDecl>( |
| 2737 | Importer.Import(D->getImplementation())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2738 | if (!Impl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2739 | return nullptr; |
| 2740 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2741 | ToCategory->setImplementation(Impl); |
| 2742 | } |
| 2743 | |
| 2744 | return ToCategory; |
| 2745 | } |
| 2746 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2747 | bool ASTNodeImporter::ImportDefinition(ObjCProtocolDecl *From, |
| 2748 | ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2749 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2750 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2751 | if (shouldForceImportDeclContext(Kind)) |
| 2752 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2753 | return false; |
| 2754 | } |
| 2755 | |
| 2756 | // Start the protocol definition |
| 2757 | To->startDefinition(); |
| 2758 | |
| 2759 | // Import protocols |
| 2760 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 2761 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| 2762 | ObjCProtocolDecl::protocol_loc_iterator |
| 2763 | FromProtoLoc = From->protocol_loc_begin(); |
| 2764 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 2765 | FromProtoEnd = From->protocol_end(); |
| 2766 | FromProto != FromProtoEnd; |
| 2767 | ++FromProto, ++FromProtoLoc) { |
| 2768 | ObjCProtocolDecl *ToProto |
| 2769 | = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
| 2770 | if (!ToProto) |
| 2771 | return true; |
| 2772 | Protocols.push_back(ToProto); |
| 2773 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 2774 | } |
| 2775 | |
| 2776 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 2777 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 2778 | ProtocolLocs.data(), Importer.getToContext()); |
| 2779 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2780 | if (shouldForceImportDeclContext(Kind)) { |
| 2781 | // Import all of the members of this protocol. |
| 2782 | ImportDeclContext(From, /*ForceImport=*/true); |
| 2783 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2784 | return false; |
| 2785 | } |
| 2786 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 2787 | Decl *ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2788 | // If this protocol has a definition in the translation unit we're coming |
| 2789 | // from, but this particular declaration is not that definition, import the |
| 2790 | // definition and map to that. |
| 2791 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 2792 | if (Definition && Definition != D) { |
| 2793 | Decl *ImportedDef = Importer.Import(Definition); |
| 2794 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2795 | return nullptr; |
| 2796 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2797 | return Importer.Imported(D, ImportedDef); |
| 2798 | } |
| 2799 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 2800 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 2801 | DeclContext *DC, *LexicalDC; |
| 2802 | DeclarationName Name; |
| 2803 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2804 | NamedDecl *ToD; |
| 2805 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2806 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2807 | if (ToD) |
| 2808 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 2809 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2810 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2811 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2812 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2813 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 2814 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 2815 | continue; |
| 2816 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2817 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecls[I]))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 2818 | break; |
| 2819 | } |
| 2820 | |
| 2821 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2822 | if (!ToProto) { |
| 2823 | ToProto = ObjCProtocolDecl::Create(Importer.getToContext(), DC, |
| 2824 | Name.getAsIdentifierInfo(), Loc, |
| 2825 | Importer.Import(D->getAtStartLoc()), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2826 | /*PrevDecl=*/nullptr); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2827 | ToProto->setLexicalDeclContext(LexicalDC); |
| 2828 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 2829 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2830 | |
| 2831 | Importer.Imported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 2832 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2833 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToProto)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2834 | return nullptr; |
| 2835 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 2836 | return ToProto; |
| 2837 | } |
| 2838 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 2839 | Decl *ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 2840 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 2841 | DeclContext *LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 2842 | |
| 2843 | SourceLocation ExternLoc = Importer.Import(D->getExternLoc()); |
| 2844 | SourceLocation LangLoc = Importer.Import(D->getLocation()); |
| 2845 | |
| 2846 | bool HasBraces = D->hasBraces(); |
| 2847 | |
Sean Callanan | b12a855 | 2014-12-10 21:22:20 +0000 | [diff] [blame] | 2848 | LinkageSpecDecl *ToLinkageSpec = |
| 2849 | LinkageSpecDecl::Create(Importer.getToContext(), |
| 2850 | DC, |
| 2851 | ExternLoc, |
| 2852 | LangLoc, |
| 2853 | D->getLanguage(), |
| 2854 | HasBraces); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 2855 | |
| 2856 | if (HasBraces) { |
| 2857 | SourceLocation RBraceLoc = Importer.Import(D->getRBraceLoc()); |
| 2858 | ToLinkageSpec->setRBraceLoc(RBraceLoc); |
| 2859 | } |
| 2860 | |
| 2861 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 2862 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 2863 | |
| 2864 | Importer.Imported(D, ToLinkageSpec); |
| 2865 | |
| 2866 | return ToLinkageSpec; |
| 2867 | } |
| 2868 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2869 | bool ASTNodeImporter::ImportDefinition(ObjCInterfaceDecl *From, |
| 2870 | ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2871 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2872 | if (To->getDefinition()) { |
| 2873 | // Check consistency of superclass. |
| 2874 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 2875 | if (FromSuper) { |
| 2876 | FromSuper = cast_or_null<ObjCInterfaceDecl>(Importer.Import(FromSuper)); |
| 2877 | if (!FromSuper) |
| 2878 | return true; |
| 2879 | } |
| 2880 | |
| 2881 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
| 2882 | if ((bool)FromSuper != (bool)ToSuper || |
| 2883 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
| 2884 | Importer.ToDiag(To->getLocation(), |
| 2885 | diag::err_odr_objc_superclass_inconsistent) |
| 2886 | << To->getDeclName(); |
| 2887 | if (ToSuper) |
| 2888 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 2889 | << To->getSuperClass()->getDeclName(); |
| 2890 | else |
| 2891 | Importer.ToDiag(To->getLocation(), |
| 2892 | diag::note_odr_objc_missing_superclass); |
| 2893 | if (From->getSuperClass()) |
| 2894 | Importer.FromDiag(From->getSuperClassLoc(), |
| 2895 | diag::note_odr_objc_superclass) |
| 2896 | << From->getSuperClass()->getDeclName(); |
| 2897 | else |
| 2898 | Importer.FromDiag(From->getLocation(), |
| 2899 | diag::note_odr_objc_missing_superclass); |
| 2900 | } |
| 2901 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2902 | if (shouldForceImportDeclContext(Kind)) |
| 2903 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2904 | return false; |
| 2905 | } |
| 2906 | |
| 2907 | // Start the definition. |
| 2908 | To->startDefinition(); |
| 2909 | |
| 2910 | // If this class has a superclass, import it. |
| 2911 | if (From->getSuperClass()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 2912 | TypeSourceInfo *SuperTInfo = Importer.Import(From->getSuperClassTInfo()); |
| 2913 | if (!SuperTInfo) |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2914 | return true; |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 2915 | |
| 2916 | To->setSuperClass(SuperTInfo); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | // Import protocols |
| 2920 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 2921 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| 2922 | ObjCInterfaceDecl::protocol_loc_iterator |
| 2923 | FromProtoLoc = From->protocol_loc_begin(); |
| 2924 | |
| 2925 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 2926 | FromProtoEnd = From->protocol_end(); |
| 2927 | FromProto != FromProtoEnd; |
| 2928 | ++FromProto, ++FromProtoLoc) { |
| 2929 | ObjCProtocolDecl *ToProto |
| 2930 | = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
| 2931 | if (!ToProto) |
| 2932 | return true; |
| 2933 | Protocols.push_back(ToProto); |
| 2934 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 2935 | } |
| 2936 | |
| 2937 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 2938 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 2939 | ProtocolLocs.data(), Importer.getToContext()); |
| 2940 | |
| 2941 | // Import categories. When the categories themselves are imported, they'll |
| 2942 | // hook themselves into this interface. |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 2943 | for (auto *Cat : From->known_categories()) |
| 2944 | Importer.Import(Cat); |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 2945 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2946 | // If we have an @implementation, import it as well. |
| 2947 | if (From->getImplementation()) { |
| 2948 | ObjCImplementationDecl *Impl = cast_or_null<ObjCImplementationDecl>( |
| 2949 | Importer.Import(From->getImplementation())); |
| 2950 | if (!Impl) |
| 2951 | return true; |
| 2952 | |
| 2953 | To->setImplementation(Impl); |
| 2954 | } |
| 2955 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2956 | if (shouldForceImportDeclContext(Kind)) { |
| 2957 | // Import all of the members of this class. |
| 2958 | ImportDeclContext(From, /*ForceImport=*/true); |
| 2959 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2960 | return false; |
| 2961 | } |
| 2962 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 2963 | ObjCTypeParamList * |
| 2964 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 2965 | if (!list) |
| 2966 | return nullptr; |
| 2967 | |
| 2968 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
| 2969 | for (auto fromTypeParam : *list) { |
| 2970 | auto toTypeParam = cast_or_null<ObjCTypeParamDecl>( |
| 2971 | Importer.Import(fromTypeParam)); |
| 2972 | if (!toTypeParam) |
| 2973 | return nullptr; |
| 2974 | |
| 2975 | toTypeParams.push_back(toTypeParam); |
| 2976 | } |
| 2977 | |
| 2978 | return ObjCTypeParamList::create(Importer.getToContext(), |
| 2979 | Importer.Import(list->getLAngleLoc()), |
| 2980 | toTypeParams, |
| 2981 | Importer.Import(list->getRAngleLoc())); |
| 2982 | } |
| 2983 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 2984 | Decl *ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2985 | // If this class has a definition in the translation unit we're coming from, |
| 2986 | // but this particular declaration is not that definition, import the |
| 2987 | // definition and map to that. |
| 2988 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 2989 | if (Definition && Definition != D) { |
| 2990 | Decl *ImportedDef = Importer.Import(Definition); |
| 2991 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2992 | return nullptr; |
| 2993 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 2994 | return Importer.Imported(D, ImportedDef); |
| 2995 | } |
| 2996 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 2997 | // Import the major distinguishing characteristics of an @interface. |
| 2998 | DeclContext *DC, *LexicalDC; |
| 2999 | DeclarationName Name; |
| 3000 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3001 | NamedDecl *ToD; |
| 3002 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3003 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3004 | if (ToD) |
| 3005 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3006 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3007 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3008 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3009 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3010 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3011 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 3012 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3013 | continue; |
| 3014 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3015 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecls[I]))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3016 | break; |
| 3017 | } |
| 3018 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3019 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3020 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3021 | if (!ToIface) { |
| 3022 | ToIface = ObjCInterfaceDecl::Create(Importer.getToContext(), DC, |
| 3023 | Importer.Import(D->getAtStartLoc()), |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3024 | Name.getAsIdentifierInfo(), |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3025 | /*TypeParamList=*/nullptr, |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3026 | /*PrevDecl=*/nullptr, Loc, |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3027 | D->isImplicitInterfaceDecl()); |
| 3028 | ToIface->setLexicalDeclContext(LexicalDC); |
| 3029 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3030 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3031 | Importer.Imported(D, ToIface); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3032 | // Import the type parameter list after calling Imported, to avoid |
| 3033 | // loops when bringing in their DeclContext. |
| 3034 | ToIface->setTypeParamList(ImportObjCTypeParamList( |
| 3035 | D->getTypeParamListAsWritten())); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3036 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3037 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToIface)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3038 | return nullptr; |
| 3039 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3040 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3041 | } |
| 3042 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3043 | Decl *ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 3044 | ObjCCategoryDecl *Category = cast_or_null<ObjCCategoryDecl>( |
| 3045 | Importer.Import(D->getCategoryDecl())); |
| 3046 | if (!Category) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3047 | return nullptr; |
| 3048 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3049 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 3050 | if (!ToImpl) { |
| 3051 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3052 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3053 | return nullptr; |
| 3054 | |
Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 3055 | SourceLocation CategoryNameLoc = Importer.Import(D->getCategoryNameLoc()); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3056 | ToImpl = ObjCCategoryImplDecl::Create(Importer.getToContext(), DC, |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3057 | Importer.Import(D->getIdentifier()), |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3058 | Category->getClassInterface(), |
| 3059 | Importer.Import(D->getLocation()), |
Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 3060 | Importer.Import(D->getAtStartLoc()), |
| 3061 | CategoryNameLoc); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3062 | |
| 3063 | DeclContext *LexicalDC = DC; |
| 3064 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3065 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3066 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3067 | return nullptr; |
| 3068 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3069 | ToImpl->setLexicalDeclContext(LexicalDC); |
| 3070 | } |
| 3071 | |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3072 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3073 | Category->setImplementation(ToImpl); |
| 3074 | } |
| 3075 | |
| 3076 | Importer.Imported(D, ToImpl); |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 3077 | ImportDeclContext(D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3078 | return ToImpl; |
| 3079 | } |
| 3080 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3081 | Decl *ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 3082 | // Find the corresponding interface. |
| 3083 | ObjCInterfaceDecl *Iface = cast_or_null<ObjCInterfaceDecl>( |
| 3084 | Importer.Import(D->getClassInterface())); |
| 3085 | if (!Iface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3086 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3087 | |
| 3088 | // Import the superclass, if any. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3089 | ObjCInterfaceDecl *Super = nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3090 | if (D->getSuperClass()) { |
| 3091 | Super = cast_or_null<ObjCInterfaceDecl>( |
| 3092 | Importer.Import(D->getSuperClass())); |
| 3093 | if (!Super) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3094 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3095 | } |
| 3096 | |
| 3097 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 3098 | if (!Impl) { |
| 3099 | // We haven't imported an implementation yet. Create a new @implementation |
| 3100 | // now. |
| 3101 | Impl = ObjCImplementationDecl::Create(Importer.getToContext(), |
| 3102 | Importer.ImportContext(D->getDeclContext()), |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3103 | Iface, Super, |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3104 | Importer.Import(D->getLocation()), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3105 | Importer.Import(D->getAtStartLoc()), |
Argyrios Kyrtzidis | 5d2ce84 | 2013-05-03 22:31:26 +0000 | [diff] [blame] | 3106 | Importer.Import(D->getSuperClassLoc()), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3107 | Importer.Import(D->getIvarLBraceLoc()), |
| 3108 | Importer.Import(D->getIvarRBraceLoc())); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3109 | |
| 3110 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3111 | DeclContext *LexicalDC |
| 3112 | = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3113 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3114 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3115 | Impl->setLexicalDeclContext(LexicalDC); |
| 3116 | } |
| 3117 | |
| 3118 | // Associate the implementation with the class it implements. |
| 3119 | Iface->setImplementation(Impl); |
| 3120 | Importer.Imported(D, Iface->getImplementation()); |
| 3121 | } else { |
| 3122 | Importer.Imported(D, Iface->getImplementation()); |
| 3123 | |
| 3124 | // Verify that the existing @implementation has the same superclass. |
| 3125 | if ((Super && !Impl->getSuperClass()) || |
| 3126 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 3127 | (Super && Impl->getSuperClass() && |
| 3128 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 3129 | Impl->getSuperClass()))) { |
| 3130 | Importer.ToDiag(Impl->getLocation(), |
| 3131 | diag::err_odr_objc_superclass_inconsistent) |
| 3132 | << Iface->getDeclName(); |
| 3133 | // FIXME: It would be nice to have the location of the superclass |
| 3134 | // below. |
| 3135 | if (Impl->getSuperClass()) |
| 3136 | Importer.ToDiag(Impl->getLocation(), |
| 3137 | diag::note_odr_objc_superclass) |
| 3138 | << Impl->getSuperClass()->getDeclName(); |
| 3139 | else |
| 3140 | Importer.ToDiag(Impl->getLocation(), |
| 3141 | diag::note_odr_objc_missing_superclass); |
| 3142 | if (D->getSuperClass()) |
| 3143 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3144 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 3145 | << D->getSuperClass()->getDeclName(); |
| 3146 | else |
| 3147 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3148 | diag::note_odr_objc_missing_superclass); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3149 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3150 | } |
| 3151 | } |
| 3152 | |
| 3153 | // Import all of the members of this @implementation. |
| 3154 | ImportDeclContext(D); |
| 3155 | |
| 3156 | return Impl; |
| 3157 | } |
| 3158 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3159 | Decl *ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| 3160 | // Import the major distinguishing characteristics of an @property. |
| 3161 | DeclContext *DC, *LexicalDC; |
| 3162 | DeclarationName Name; |
| 3163 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3164 | NamedDecl *ToD; |
| 3165 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3166 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3167 | if (ToD) |
| 3168 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3169 | |
| 3170 | // Check whether we have already imported this property. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3171 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3172 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3173 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3174 | if (ObjCPropertyDecl *FoundProp |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3175 | = dyn_cast<ObjCPropertyDecl>(FoundDecls[I])) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3176 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3177 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3178 | FoundProp->getType())) { |
| 3179 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) |
| 3180 | << Name << D->getType() << FoundProp->getType(); |
| 3181 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 3182 | << FoundProp->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3183 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3184 | } |
| 3185 | |
| 3186 | // FIXME: Check property attributes, getters, setters, etc.? |
| 3187 | |
| 3188 | // Consider these properties to be equivalent. |
| 3189 | Importer.Imported(D, FoundProp); |
| 3190 | return FoundProp; |
| 3191 | } |
| 3192 | } |
| 3193 | |
| 3194 | // Import the type. |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 3195 | TypeSourceInfo *TSI = Importer.Import(D->getTypeSourceInfo()); |
| 3196 | if (!TSI) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3197 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3198 | |
| 3199 | // Create the new property. |
| 3200 | ObjCPropertyDecl *ToProperty |
| 3201 | = ObjCPropertyDecl::Create(Importer.getToContext(), DC, Loc, |
| 3202 | Name.getAsIdentifierInfo(), |
| 3203 | Importer.Import(D->getAtLoc()), |
Fariborz Jahanian | 86c2f5c | 2012-02-29 22:18:55 +0000 | [diff] [blame] | 3204 | Importer.Import(D->getLParenLoc()), |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 3205 | Importer.Import(D->getType()), |
| 3206 | TSI, |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3207 | D->getPropertyImplementation()); |
| 3208 | Importer.Imported(D, ToProperty); |
| 3209 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3210 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3211 | |
| 3212 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 3213 | ToProperty->setPropertyAttributesAsWritten( |
| 3214 | D->getPropertyAttributesAsWritten()); |
Argyrios Kyrtzidis | 194b28e | 2017-03-16 18:25:40 +0000 | [diff] [blame] | 3215 | ToProperty->setGetterName(Importer.Import(D->getGetterName()), |
| 3216 | Importer.Import(D->getGetterNameLoc())); |
| 3217 | ToProperty->setSetterName(Importer.Import(D->getSetterName()), |
| 3218 | Importer.Import(D->getSetterNameLoc())); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3219 | ToProperty->setGetterMethodDecl( |
| 3220 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getGetterMethodDecl()))); |
| 3221 | ToProperty->setSetterMethodDecl( |
| 3222 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getSetterMethodDecl()))); |
| 3223 | ToProperty->setPropertyIvarDecl( |
| 3224 | cast_or_null<ObjCIvarDecl>(Importer.Import(D->getPropertyIvarDecl()))); |
| 3225 | return ToProperty; |
| 3226 | } |
| 3227 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3228 | Decl *ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 3229 | ObjCPropertyDecl *Property = cast_or_null<ObjCPropertyDecl>( |
| 3230 | Importer.Import(D->getPropertyDecl())); |
| 3231 | if (!Property) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3232 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3233 | |
| 3234 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3235 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3236 | return nullptr; |
| 3237 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3238 | // Import the lexical declaration context. |
| 3239 | DeclContext *LexicalDC = DC; |
| 3240 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3241 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3242 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3243 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | ObjCImplDecl *InImpl = dyn_cast<ObjCImplDecl>(LexicalDC); |
| 3247 | if (!InImpl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3248 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3249 | |
| 3250 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3251 | ObjCIvarDecl *Ivar = nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3252 | if (D->getPropertyIvarDecl()) { |
| 3253 | Ivar = cast_or_null<ObjCIvarDecl>( |
| 3254 | Importer.Import(D->getPropertyIvarDecl())); |
| 3255 | if (!Ivar) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3256 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3257 | } |
| 3258 | |
| 3259 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 3260 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 3261 | Property->getQueryKind()); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3262 | if (!ToImpl) { |
| 3263 | ToImpl = ObjCPropertyImplDecl::Create(Importer.getToContext(), DC, |
| 3264 | Importer.Import(D->getLocStart()), |
| 3265 | Importer.Import(D->getLocation()), |
| 3266 | Property, |
| 3267 | D->getPropertyImplementation(), |
| 3268 | Ivar, |
| 3269 | Importer.Import(D->getPropertyIvarDeclLoc())); |
| 3270 | ToImpl->setLexicalDeclContext(LexicalDC); |
| 3271 | Importer.Imported(D, ToImpl); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3272 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3273 | } else { |
| 3274 | // Check that we have the same kind of property implementation (@synthesize |
| 3275 | // vs. @dynamic). |
| 3276 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
| 3277 | Importer.ToDiag(ToImpl->getLocation(), |
| 3278 | diag::err_odr_objc_property_impl_kind_inconsistent) |
| 3279 | << Property->getDeclName() |
| 3280 | << (ToImpl->getPropertyImplementation() |
| 3281 | == ObjCPropertyImplDecl::Dynamic); |
| 3282 | Importer.FromDiag(D->getLocation(), |
| 3283 | diag::note_odr_objc_property_impl_kind) |
| 3284 | << D->getPropertyDecl()->getDeclName() |
| 3285 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3286 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3287 | } |
| 3288 | |
| 3289 | // For @synthesize, check that we have the same |
| 3290 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 3291 | Ivar != ToImpl->getPropertyIvarDecl()) { |
| 3292 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
| 3293 | diag::err_odr_objc_synthesize_ivar_inconsistent) |
| 3294 | << Property->getDeclName() |
| 3295 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 3296 | << Ivar->getDeclName(); |
| 3297 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
| 3298 | diag::note_odr_objc_synthesize_ivar_here) |
| 3299 | << D->getPropertyIvarDecl()->getDeclName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3300 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3301 | } |
| 3302 | |
| 3303 | // Merge the existing implementation with the new implementation. |
| 3304 | Importer.Imported(D, ToImpl); |
| 3305 | } |
| 3306 | |
| 3307 | return ToImpl; |
| 3308 | } |
| 3309 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3310 | Decl *ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| 3311 | // For template arguments, we adopt the translation unit as our declaration |
| 3312 | // context. This context will be fixed when the actual template declaration |
| 3313 | // is created. |
| 3314 | |
| 3315 | // FIXME: Import default argument. |
| 3316 | return TemplateTypeParmDecl::Create(Importer.getToContext(), |
| 3317 | Importer.getToContext().getTranslationUnitDecl(), |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 3318 | Importer.Import(D->getLocStart()), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3319 | Importer.Import(D->getLocation()), |
| 3320 | D->getDepth(), |
| 3321 | D->getIndex(), |
| 3322 | Importer.Import(D->getIdentifier()), |
| 3323 | D->wasDeclaredWithTypename(), |
| 3324 | D->isParameterPack()); |
| 3325 | } |
| 3326 | |
| 3327 | Decl * |
| 3328 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| 3329 | // Import the name of this declaration. |
| 3330 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 3331 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3332 | return nullptr; |
| 3333 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3334 | // Import the location of this declaration. |
| 3335 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 3336 | |
| 3337 | // Import the type of this declaration. |
| 3338 | QualType T = Importer.Import(D->getType()); |
| 3339 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3340 | return nullptr; |
| 3341 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3342 | // Import type-source information. |
| 3343 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3344 | if (D->getTypeSourceInfo() && !TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3345 | return nullptr; |
| 3346 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3347 | // FIXME: Import default argument. |
| 3348 | |
| 3349 | return NonTypeTemplateParmDecl::Create(Importer.getToContext(), |
| 3350 | Importer.getToContext().getTranslationUnitDecl(), |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 3351 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3352 | Loc, D->getDepth(), D->getPosition(), |
| 3353 | Name.getAsIdentifierInfo(), |
Douglas Gregor | da3cc0d | 2010-12-23 23:51:58 +0000 | [diff] [blame] | 3354 | T, D->isParameterPack(), TInfo); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3355 | } |
| 3356 | |
| 3357 | Decl * |
| 3358 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 3359 | // Import the name of this declaration. |
| 3360 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 3361 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3362 | return nullptr; |
| 3363 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3364 | // Import the location of this declaration. |
| 3365 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 3366 | |
| 3367 | // Import template parameters. |
| 3368 | TemplateParameterList *TemplateParams |
| 3369 | = ImportTemplateParameterList(D->getTemplateParameters()); |
| 3370 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3371 | return nullptr; |
| 3372 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3373 | // FIXME: Import default argument. |
| 3374 | |
| 3375 | return TemplateTemplateParmDecl::Create(Importer.getToContext(), |
| 3376 | Importer.getToContext().getTranslationUnitDecl(), |
| 3377 | Loc, D->getDepth(), D->getPosition(), |
Douglas Gregor | f550077 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 3378 | D->isParameterPack(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3379 | Name.getAsIdentifierInfo(), |
| 3380 | TemplateParams); |
| 3381 | } |
| 3382 | |
| 3383 | Decl *ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 3384 | // If this record has a definition in the translation unit we're coming from, |
| 3385 | // but this particular declaration is not that definition, import the |
| 3386 | // definition and map to that. |
| 3387 | CXXRecordDecl *Definition |
| 3388 | = cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition()); |
| 3389 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 3390 | Decl *ImportedDef |
| 3391 | = Importer.Import(Definition->getDescribedClassTemplate()); |
| 3392 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3393 | return nullptr; |
| 3394 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3395 | return Importer.Imported(D, ImportedDef); |
| 3396 | } |
| 3397 | |
| 3398 | // Import the major distinguishing characteristics of this class template. |
| 3399 | DeclContext *DC, *LexicalDC; |
| 3400 | DeclarationName Name; |
| 3401 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3402 | NamedDecl *ToD; |
| 3403 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3404 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3405 | if (ToD) |
| 3406 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3407 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3408 | // We may already have a template of the same name; try to find and match it. |
| 3409 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3410 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3411 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3412 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3413 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 3414 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3415 | continue; |
| 3416 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3417 | Decl *Found = FoundDecls[I]; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3418 | if (ClassTemplateDecl *FoundTemplate |
| 3419 | = dyn_cast<ClassTemplateDecl>(Found)) { |
| 3420 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 3421 | // The class templates structurally match; call it the same template. |
| 3422 | // FIXME: We may be filling in a forward declaration here. Handle |
| 3423 | // this case! |
| 3424 | Importer.Imported(D->getTemplatedDecl(), |
| 3425 | FoundTemplate->getTemplatedDecl()); |
| 3426 | return Importer.Imported(D, FoundTemplate); |
| 3427 | } |
| 3428 | } |
| 3429 | |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3430 | ConflictingDecls.push_back(FoundDecls[I]); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3431 | } |
| 3432 | |
| 3433 | if (!ConflictingDecls.empty()) { |
| 3434 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 3435 | ConflictingDecls.data(), |
| 3436 | ConflictingDecls.size()); |
| 3437 | } |
| 3438 | |
| 3439 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3440 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3441 | } |
| 3442 | |
| 3443 | CXXRecordDecl *DTemplated = D->getTemplatedDecl(); |
| 3444 | |
| 3445 | // Create the declaration that is being templated. |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 3446 | // Create the declaration that is being templated. |
| 3447 | CXXRecordDecl *D2Templated = cast_or_null<CXXRecordDecl>( |
| 3448 | Importer.Import(DTemplated)); |
| 3449 | if (!D2Templated) |
| 3450 | return nullptr; |
| 3451 | |
| 3452 | // Resolve possible cyclic import. |
| 3453 | if (Decl *AlreadyImported = Importer.GetAlreadyImportedOrNull(D)) |
| 3454 | return AlreadyImported; |
| 3455 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3456 | // Create the class template declaration itself. |
| 3457 | TemplateParameterList *TemplateParams |
| 3458 | = ImportTemplateParameterList(D->getTemplateParameters()); |
| 3459 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3460 | return nullptr; |
| 3461 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3462 | ClassTemplateDecl *D2 = ClassTemplateDecl::Create(Importer.getToContext(), DC, |
| 3463 | Loc, Name, TemplateParams, |
Vassil Vassilev | 352e441 | 2017-01-12 09:16:26 +0000 | [diff] [blame] | 3464 | D2Templated); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3465 | D2Templated->setDescribedClassTemplate(D2); |
| 3466 | |
| 3467 | D2->setAccess(D->getAccess()); |
| 3468 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3469 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3470 | |
| 3471 | // Note the relationship between the class templates. |
| 3472 | Importer.Imported(D, D2); |
| 3473 | Importer.Imported(DTemplated, D2Templated); |
| 3474 | |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 3475 | if (DTemplated->isCompleteDefinition() && |
| 3476 | !D2Templated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3477 | // FIXME: Import definition! |
| 3478 | } |
| 3479 | |
| 3480 | return D2; |
| 3481 | } |
| 3482 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3483 | Decl *ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
| 3484 | ClassTemplateSpecializationDecl *D) { |
| 3485 | // If this record has a definition in the translation unit we're coming from, |
| 3486 | // but this particular declaration is not that definition, import the |
| 3487 | // definition and map to that. |
| 3488 | TagDecl *Definition = D->getDefinition(); |
| 3489 | if (Definition && Definition != D) { |
| 3490 | Decl *ImportedDef = Importer.Import(Definition); |
| 3491 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3492 | return nullptr; |
| 3493 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3494 | return Importer.Imported(D, ImportedDef); |
| 3495 | } |
| 3496 | |
| 3497 | ClassTemplateDecl *ClassTemplate |
| 3498 | = cast_or_null<ClassTemplateDecl>(Importer.Import( |
| 3499 | D->getSpecializedTemplate())); |
| 3500 | if (!ClassTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3501 | return nullptr; |
| 3502 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3503 | // Import the context of this declaration. |
| 3504 | DeclContext *DC = ClassTemplate->getDeclContext(); |
| 3505 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3506 | return nullptr; |
| 3507 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3508 | DeclContext *LexicalDC = DC; |
| 3509 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3510 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3511 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3512 | return nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | // Import the location of this declaration. |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 3516 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 3517 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3518 | |
| 3519 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3520 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3521 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 3522 | D->getTemplateArgs().size(), |
| 3523 | TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3524 | return nullptr; |
| 3525 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3526 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3527 | void *InsertPos = nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3528 | ClassTemplateSpecializationDecl *D2 |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 3529 | = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3530 | if (D2) { |
| 3531 | // We already have a class template specialization with these template |
| 3532 | // arguments. |
| 3533 | |
| 3534 | // FIXME: Check for specialization vs. instantiation errors. |
| 3535 | |
| 3536 | if (RecordDecl *FoundDef = D2->getDefinition()) { |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 3537 | if (!D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3538 | // The record types structurally match, or the "from" translation |
| 3539 | // unit only had a forward declaration anyway; call it the same |
| 3540 | // function. |
| 3541 | return Importer.Imported(D, FoundDef); |
| 3542 | } |
| 3543 | } |
| 3544 | } else { |
| 3545 | // Create a new specialization. |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3546 | if (ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 3547 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { |
| 3548 | |
| 3549 | // Import TemplateArgumentListInfo |
| 3550 | TemplateArgumentListInfo ToTAInfo; |
| 3551 | auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 3552 | for (unsigned I = 0, E = ASTTemplateArgs.NumTemplateArgs; I < E; ++I) { |
| 3553 | bool Error = false; |
| 3554 | auto ToLoc = ImportTemplateArgumentLoc(ASTTemplateArgs[I], Error); |
| 3555 | if (Error) |
| 3556 | return nullptr; |
| 3557 | ToTAInfo.addArgument(ToLoc); |
| 3558 | } |
| 3559 | |
| 3560 | QualType CanonInjType = Importer.Import( |
| 3561 | PartialSpec->getInjectedSpecializationType()); |
| 3562 | if (CanonInjType.isNull()) |
| 3563 | return nullptr; |
| 3564 | CanonInjType = CanonInjType.getCanonicalType(); |
| 3565 | |
| 3566 | TemplateParameterList *ToTPList = ImportTemplateParameterList( |
| 3567 | PartialSpec->getTemplateParameters()); |
| 3568 | if (!ToTPList && PartialSpec->getTemplateParameters()) |
| 3569 | return nullptr; |
| 3570 | |
| 3571 | D2 = ClassTemplatePartialSpecializationDecl::Create( |
| 3572 | Importer.getToContext(), D->getTagKind(), DC, StartLoc, IdLoc, |
| 3573 | ToTPList, ClassTemplate, |
| 3574 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
| 3575 | ToTAInfo, CanonInjType, nullptr); |
| 3576 | |
| 3577 | } else { |
| 3578 | D2 = ClassTemplateSpecializationDecl::Create(Importer.getToContext(), |
| 3579 | D->getTagKind(), DC, |
| 3580 | StartLoc, IdLoc, |
| 3581 | ClassTemplate, |
| 3582 | TemplateArgs, |
| 3583 | /*PrevDecl=*/nullptr); |
| 3584 | } |
| 3585 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3586 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 3587 | |
| 3588 | // Add this specialization to the class template. |
| 3589 | ClassTemplate->AddSpecialization(D2, InsertPos); |
| 3590 | |
| 3591 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3592 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3593 | |
| 3594 | Importer.Imported(D, D2); |
| 3595 | |
| 3596 | if (auto *TSI = D->getTypeAsWritten()) { |
| 3597 | TypeSourceInfo *TInfo = Importer.Import(TSI); |
| 3598 | if (!TInfo) |
| 3599 | return nullptr; |
| 3600 | D2->setTypeAsWritten(TInfo); |
| 3601 | D2->setTemplateKeywordLoc(Importer.Import(D->getTemplateKeywordLoc())); |
| 3602 | D2->setExternLoc(Importer.Import(D->getExternLoc())); |
| 3603 | } |
| 3604 | |
| 3605 | SourceLocation POI = Importer.Import(D->getPointOfInstantiation()); |
| 3606 | if (POI.isValid()) |
| 3607 | D2->setPointOfInstantiation(POI); |
| 3608 | else if (D->getPointOfInstantiation().isValid()) |
| 3609 | return nullptr; |
| 3610 | |
| 3611 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 3612 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3613 | // Add the specialization to this context. |
| 3614 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3615 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3616 | } |
| 3617 | Importer.Imported(D, D2); |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 3618 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3619 | return nullptr; |
| 3620 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 3621 | return D2; |
| 3622 | } |
| 3623 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3624 | Decl *ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| 3625 | // If this variable has a definition in the translation unit we're coming |
| 3626 | // from, |
| 3627 | // but this particular declaration is not that definition, import the |
| 3628 | // definition and map to that. |
| 3629 | VarDecl *Definition = |
| 3630 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 3631 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 3632 | Decl *ImportedDef = Importer.Import(Definition->getDescribedVarTemplate()); |
| 3633 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3634 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3635 | |
| 3636 | return Importer.Imported(D, ImportedDef); |
| 3637 | } |
| 3638 | |
| 3639 | // Import the major distinguishing characteristics of this variable template. |
| 3640 | DeclContext *DC, *LexicalDC; |
| 3641 | DeclarationName Name; |
| 3642 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3643 | NamedDecl *ToD; |
| 3644 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3645 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3646 | if (ToD) |
| 3647 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3648 | |
| 3649 | // We may already have a template of the same name; try to find and match it. |
| 3650 | assert(!DC->isFunctionOrMethod() && |
| 3651 | "Variable templates cannot be declared at function scope"); |
| 3652 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 3653 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3654 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3655 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| 3656 | if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
| 3657 | continue; |
| 3658 | |
| 3659 | Decl *Found = FoundDecls[I]; |
| 3660 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
| 3661 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 3662 | // The variable templates structurally match; call it the same template. |
| 3663 | Importer.Imported(D->getTemplatedDecl(), |
| 3664 | FoundTemplate->getTemplatedDecl()); |
| 3665 | return Importer.Imported(D, FoundTemplate); |
| 3666 | } |
| 3667 | } |
| 3668 | |
| 3669 | ConflictingDecls.push_back(FoundDecls[I]); |
| 3670 | } |
| 3671 | |
| 3672 | if (!ConflictingDecls.empty()) { |
| 3673 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 3674 | ConflictingDecls.data(), |
| 3675 | ConflictingDecls.size()); |
| 3676 | } |
| 3677 | |
| 3678 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3679 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3680 | |
| 3681 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 3682 | |
| 3683 | // Import the type. |
| 3684 | QualType T = Importer.Import(DTemplated->getType()); |
| 3685 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3686 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3687 | |
| 3688 | // Create the declaration that is being templated. |
| 3689 | SourceLocation StartLoc = Importer.Import(DTemplated->getLocStart()); |
| 3690 | SourceLocation IdLoc = Importer.Import(DTemplated->getLocation()); |
| 3691 | TypeSourceInfo *TInfo = Importer.Import(DTemplated->getTypeSourceInfo()); |
| 3692 | VarDecl *D2Templated = VarDecl::Create(Importer.getToContext(), DC, StartLoc, |
| 3693 | IdLoc, Name.getAsIdentifierInfo(), T, |
| 3694 | TInfo, DTemplated->getStorageClass()); |
| 3695 | D2Templated->setAccess(DTemplated->getAccess()); |
| 3696 | D2Templated->setQualifierInfo(Importer.Import(DTemplated->getQualifierLoc())); |
| 3697 | D2Templated->setLexicalDeclContext(LexicalDC); |
| 3698 | |
| 3699 | // Importer.Imported(DTemplated, D2Templated); |
| 3700 | // LexicalDC->addDeclInternal(D2Templated); |
| 3701 | |
| 3702 | // Merge the initializer. |
| 3703 | if (ImportDefinition(DTemplated, D2Templated)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3704 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3705 | |
| 3706 | // Create the variable template declaration itself. |
| 3707 | TemplateParameterList *TemplateParams = |
| 3708 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 3709 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3710 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3711 | |
| 3712 | VarTemplateDecl *D2 = VarTemplateDecl::Create( |
Richard Smith | beef345 | 2014-01-16 23:39:20 +0000 | [diff] [blame] | 3713 | Importer.getToContext(), DC, Loc, Name, TemplateParams, D2Templated); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3714 | D2Templated->setDescribedVarTemplate(D2); |
| 3715 | |
| 3716 | D2->setAccess(D->getAccess()); |
| 3717 | D2->setLexicalDeclContext(LexicalDC); |
| 3718 | LexicalDC->addDeclInternal(D2); |
| 3719 | |
| 3720 | // Note the relationship between the variable templates. |
| 3721 | Importer.Imported(D, D2); |
| 3722 | Importer.Imported(DTemplated, D2Templated); |
| 3723 | |
| 3724 | if (DTemplated->isThisDeclarationADefinition() && |
| 3725 | !D2Templated->isThisDeclarationADefinition()) { |
| 3726 | // FIXME: Import definition! |
| 3727 | } |
| 3728 | |
| 3729 | return D2; |
| 3730 | } |
| 3731 | |
| 3732 | Decl *ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
| 3733 | VarTemplateSpecializationDecl *D) { |
| 3734 | // If this record has a definition in the translation unit we're coming from, |
| 3735 | // but this particular declaration is not that definition, import the |
| 3736 | // definition and map to that. |
| 3737 | VarDecl *Definition = D->getDefinition(); |
| 3738 | if (Definition && Definition != D) { |
| 3739 | Decl *ImportedDef = Importer.Import(Definition); |
| 3740 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3741 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3742 | |
| 3743 | return Importer.Imported(D, ImportedDef); |
| 3744 | } |
| 3745 | |
| 3746 | VarTemplateDecl *VarTemplate = cast_or_null<VarTemplateDecl>( |
| 3747 | Importer.Import(D->getSpecializedTemplate())); |
| 3748 | if (!VarTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3749 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3750 | |
| 3751 | // Import the context of this declaration. |
| 3752 | DeclContext *DC = VarTemplate->getDeclContext(); |
| 3753 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3754 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3755 | |
| 3756 | DeclContext *LexicalDC = DC; |
| 3757 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3758 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3759 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3760 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3761 | } |
| 3762 | |
| 3763 | // Import the location of this declaration. |
| 3764 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 3765 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
| 3766 | |
| 3767 | // Import template arguments. |
| 3768 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| 3769 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 3770 | D->getTemplateArgs().size(), TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3771 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3772 | |
| 3773 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3774 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3775 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 3776 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3777 | if (D2) { |
| 3778 | // We already have a variable template specialization with these template |
| 3779 | // arguments. |
| 3780 | |
| 3781 | // FIXME: Check for specialization vs. instantiation errors. |
| 3782 | |
| 3783 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 3784 | if (!D->isThisDeclarationADefinition() || |
| 3785 | IsStructuralMatch(D, FoundDef)) { |
| 3786 | // The record types structurally match, or the "from" translation |
| 3787 | // unit only had a forward declaration anyway; call it the same |
| 3788 | // variable. |
| 3789 | return Importer.Imported(D, FoundDef); |
| 3790 | } |
| 3791 | } |
| 3792 | } else { |
| 3793 | |
| 3794 | // Import the type. |
| 3795 | QualType T = Importer.Import(D->getType()); |
| 3796 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3797 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3798 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3799 | |
| 3800 | // Create a new specialization. |
| 3801 | D2 = VarTemplateSpecializationDecl::Create( |
| 3802 | Importer.getToContext(), DC, StartLoc, IdLoc, VarTemplate, T, TInfo, |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 3803 | D->getStorageClass(), TemplateArgs); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3804 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 3805 | D2->setTemplateArgsInfo(D->getTemplateArgsInfo()); |
| 3806 | |
| 3807 | // Add this specialization to the class template. |
| 3808 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 3809 | |
| 3810 | // Import the qualifier, if any. |
| 3811 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
| 3812 | |
| 3813 | // Add the specialization to this context. |
| 3814 | D2->setLexicalDeclContext(LexicalDC); |
| 3815 | LexicalDC->addDeclInternal(D2); |
| 3816 | } |
| 3817 | Importer.Imported(D, D2); |
| 3818 | |
| 3819 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3820 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3821 | |
| 3822 | return D2; |
| 3823 | } |
| 3824 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 3825 | //---------------------------------------------------------------------------- |
| 3826 | // Import Statements |
| 3827 | //---------------------------------------------------------------------------- |
| 3828 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3829 | DeclGroupRef ASTNodeImporter::ImportDeclGroup(DeclGroupRef DG) { |
| 3830 | if (DG.isNull()) |
| 3831 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 3832 | size_t NumDecls = DG.end() - DG.begin(); |
| 3833 | SmallVector<Decl *, 1> ToDecls(NumDecls); |
| 3834 | auto &_Importer = this->Importer; |
| 3835 | std::transform(DG.begin(), DG.end(), ToDecls.begin(), |
| 3836 | [&_Importer](Decl *D) -> Decl * { |
| 3837 | return _Importer.Import(D); |
| 3838 | }); |
| 3839 | return DeclGroupRef::Create(Importer.getToContext(), |
| 3840 | ToDecls.begin(), |
| 3841 | NumDecls); |
| 3842 | } |
| 3843 | |
| 3844 | Stmt *ASTNodeImporter::VisitStmt(Stmt *S) { |
| 3845 | Importer.FromDiag(S->getLocStart(), diag::err_unsupported_ast_node) |
| 3846 | << S->getStmtClassName(); |
| 3847 | return nullptr; |
| 3848 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 3849 | |
| 3850 | |
| 3851 | Stmt *ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
| 3852 | SmallVector<IdentifierInfo *, 4> Names; |
| 3853 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 3854 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 3855 | // ToII is nullptr when no symbolic name is given for output operand |
| 3856 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 3857 | if (!ToII && S->getOutputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 3858 | return nullptr; |
| 3859 | Names.push_back(ToII); |
| 3860 | } |
| 3861 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 3862 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 3863 | // ToII is nullptr when no symbolic name is given for input operand |
| 3864 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 3865 | if (!ToII && S->getInputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 3866 | return nullptr; |
| 3867 | Names.push_back(ToII); |
| 3868 | } |
| 3869 | |
| 3870 | SmallVector<StringLiteral *, 4> Clobbers; |
| 3871 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
| 3872 | StringLiteral *Clobber = cast_or_null<StringLiteral>( |
| 3873 | Importer.Import(S->getClobberStringLiteral(I))); |
| 3874 | if (!Clobber) |
| 3875 | return nullptr; |
| 3876 | Clobbers.push_back(Clobber); |
| 3877 | } |
| 3878 | |
| 3879 | SmallVector<StringLiteral *, 4> Constraints; |
| 3880 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 3881 | StringLiteral *Output = cast_or_null<StringLiteral>( |
| 3882 | Importer.Import(S->getOutputConstraintLiteral(I))); |
| 3883 | if (!Output) |
| 3884 | return nullptr; |
| 3885 | Constraints.push_back(Output); |
| 3886 | } |
| 3887 | |
| 3888 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 3889 | StringLiteral *Input = cast_or_null<StringLiteral>( |
| 3890 | Importer.Import(S->getInputConstraintLiteral(I))); |
| 3891 | if (!Input) |
| 3892 | return nullptr; |
| 3893 | Constraints.push_back(Input); |
| 3894 | } |
| 3895 | |
| 3896 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3897 | if (ImportContainerChecked(S->outputs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 3898 | return nullptr; |
| 3899 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3900 | if (ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 3901 | return nullptr; |
| 3902 | |
| 3903 | StringLiteral *AsmStr = cast_or_null<StringLiteral>( |
| 3904 | Importer.Import(S->getAsmString())); |
| 3905 | if (!AsmStr) |
| 3906 | return nullptr; |
| 3907 | |
| 3908 | return new (Importer.getToContext()) GCCAsmStmt( |
| 3909 | Importer.getToContext(), |
| 3910 | Importer.Import(S->getAsmLoc()), |
| 3911 | S->isSimple(), |
| 3912 | S->isVolatile(), |
| 3913 | S->getNumOutputs(), |
| 3914 | S->getNumInputs(), |
| 3915 | Names.data(), |
| 3916 | Constraints.data(), |
| 3917 | Exprs.data(), |
| 3918 | AsmStr, |
| 3919 | S->getNumClobbers(), |
| 3920 | Clobbers.data(), |
| 3921 | Importer.Import(S->getRParenLoc())); |
| 3922 | } |
| 3923 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3924 | Stmt *ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 3925 | DeclGroupRef ToDG = ImportDeclGroup(S->getDeclGroup()); |
| 3926 | for (Decl *ToD : ToDG) { |
| 3927 | if (!ToD) |
| 3928 | return nullptr; |
| 3929 | } |
| 3930 | SourceLocation ToStartLoc = Importer.Import(S->getStartLoc()); |
| 3931 | SourceLocation ToEndLoc = Importer.Import(S->getEndLoc()); |
| 3932 | return new (Importer.getToContext()) DeclStmt(ToDG, ToStartLoc, ToEndLoc); |
| 3933 | } |
| 3934 | |
| 3935 | Stmt *ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 3936 | SourceLocation ToSemiLoc = Importer.Import(S->getSemiLoc()); |
| 3937 | return new (Importer.getToContext()) NullStmt(ToSemiLoc, |
| 3938 | S->hasLeadingEmptyMacro()); |
| 3939 | } |
| 3940 | |
| 3941 | Stmt *ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 3942 | llvm::SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3943 | |
| 3944 | if (ImportContainerChecked(S->body(), ToStmts)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 3945 | return nullptr; |
| 3946 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3947 | SourceLocation ToLBraceLoc = Importer.Import(S->getLBracLoc()); |
| 3948 | SourceLocation ToRBraceLoc = Importer.Import(S->getRBracLoc()); |
| 3949 | return new (Importer.getToContext()) CompoundStmt(Importer.getToContext(), |
| 3950 | ToStmts, |
| 3951 | ToLBraceLoc, ToRBraceLoc); |
| 3952 | } |
| 3953 | |
| 3954 | Stmt *ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 3955 | Expr *ToLHS = Importer.Import(S->getLHS()); |
| 3956 | if (!ToLHS) |
| 3957 | return nullptr; |
| 3958 | Expr *ToRHS = Importer.Import(S->getRHS()); |
| 3959 | if (!ToRHS && S->getRHS()) |
| 3960 | return nullptr; |
| 3961 | SourceLocation ToCaseLoc = Importer.Import(S->getCaseLoc()); |
| 3962 | SourceLocation ToEllipsisLoc = Importer.Import(S->getEllipsisLoc()); |
| 3963 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 3964 | return new (Importer.getToContext()) CaseStmt(ToLHS, ToRHS, |
| 3965 | ToCaseLoc, ToEllipsisLoc, |
| 3966 | ToColonLoc); |
| 3967 | } |
| 3968 | |
| 3969 | Stmt *ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 3970 | SourceLocation ToDefaultLoc = Importer.Import(S->getDefaultLoc()); |
| 3971 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 3972 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 3973 | if (!ToSubStmt && S->getSubStmt()) |
| 3974 | return nullptr; |
| 3975 | return new (Importer.getToContext()) DefaultStmt(ToDefaultLoc, ToColonLoc, |
| 3976 | ToSubStmt); |
| 3977 | } |
| 3978 | |
| 3979 | Stmt *ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 3980 | SourceLocation ToIdentLoc = Importer.Import(S->getIdentLoc()); |
| 3981 | LabelDecl *ToLabelDecl = |
| 3982 | cast_or_null<LabelDecl>(Importer.Import(S->getDecl())); |
| 3983 | if (!ToLabelDecl && S->getDecl()) |
| 3984 | return nullptr; |
| 3985 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 3986 | if (!ToSubStmt && S->getSubStmt()) |
| 3987 | return nullptr; |
| 3988 | return new (Importer.getToContext()) LabelStmt(ToIdentLoc, ToLabelDecl, |
| 3989 | ToSubStmt); |
| 3990 | } |
| 3991 | |
| 3992 | Stmt *ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 3993 | SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc()); |
| 3994 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 3995 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
| 3996 | ASTContext &_ToContext = Importer.getToContext(); |
| 3997 | std::transform(FromAttrs.begin(), FromAttrs.end(), ToAttrs.begin(), |
| 3998 | [&_ToContext](const Attr *A) -> const Attr * { |
| 3999 | return A->clone(_ToContext); |
| 4000 | }); |
| 4001 | for (const Attr *ToA : ToAttrs) { |
| 4002 | if (!ToA) |
| 4003 | return nullptr; |
| 4004 | } |
| 4005 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4006 | if (!ToSubStmt && S->getSubStmt()) |
| 4007 | return nullptr; |
| 4008 | return AttributedStmt::Create(Importer.getToContext(), ToAttrLoc, |
| 4009 | ToAttrs, ToSubStmt); |
| 4010 | } |
| 4011 | |
| 4012 | Stmt *ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 4013 | SourceLocation ToIfLoc = Importer.Import(S->getIfLoc()); |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4014 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4015 | if (!ToInit && S->getInit()) |
| 4016 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4017 | VarDecl *ToConditionVariable = nullptr; |
| 4018 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4019 | ToConditionVariable = |
| 4020 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4021 | if (!ToConditionVariable) |
| 4022 | return nullptr; |
| 4023 | } |
| 4024 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4025 | if (!ToCondition && S->getCond()) |
| 4026 | return nullptr; |
| 4027 | Stmt *ToThenStmt = Importer.Import(S->getThen()); |
| 4028 | if (!ToThenStmt && S->getThen()) |
| 4029 | return nullptr; |
| 4030 | SourceLocation ToElseLoc = Importer.Import(S->getElseLoc()); |
| 4031 | Stmt *ToElseStmt = Importer.Import(S->getElse()); |
| 4032 | if (!ToElseStmt && S->getElse()) |
| 4033 | return nullptr; |
| 4034 | return new (Importer.getToContext()) IfStmt(Importer.getToContext(), |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 4035 | ToIfLoc, S->isConstexpr(), |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4036 | ToInit, |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 4037 | ToConditionVariable, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4038 | ToCondition, ToThenStmt, |
| 4039 | ToElseLoc, ToElseStmt); |
| 4040 | } |
| 4041 | |
| 4042 | Stmt *ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4043 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4044 | if (!ToInit && S->getInit()) |
| 4045 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4046 | VarDecl *ToConditionVariable = nullptr; |
| 4047 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4048 | ToConditionVariable = |
| 4049 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4050 | if (!ToConditionVariable) |
| 4051 | return nullptr; |
| 4052 | } |
| 4053 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4054 | if (!ToCondition && S->getCond()) |
| 4055 | return nullptr; |
| 4056 | SwitchStmt *ToStmt = new (Importer.getToContext()) SwitchStmt( |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4057 | Importer.getToContext(), ToInit, |
| 4058 | ToConditionVariable, ToCondition); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4059 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4060 | if (!ToBody && S->getBody()) |
| 4061 | return nullptr; |
| 4062 | ToStmt->setBody(ToBody); |
| 4063 | ToStmt->setSwitchLoc(Importer.Import(S->getSwitchLoc())); |
| 4064 | // Now we have to re-chain the cases. |
| 4065 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 4066 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 4067 | SC = SC->getNextSwitchCase()) { |
| 4068 | SwitchCase *ToSC = dyn_cast_or_null<SwitchCase>(Importer.Import(SC)); |
| 4069 | if (!ToSC) |
| 4070 | return nullptr; |
| 4071 | if (LastChainedSwitchCase) |
| 4072 | LastChainedSwitchCase->setNextSwitchCase(ToSC); |
| 4073 | else |
| 4074 | ToStmt->setSwitchCaseList(ToSC); |
| 4075 | LastChainedSwitchCase = ToSC; |
| 4076 | } |
| 4077 | return ToStmt; |
| 4078 | } |
| 4079 | |
| 4080 | Stmt *ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 4081 | VarDecl *ToConditionVariable = nullptr; |
| 4082 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4083 | ToConditionVariable = |
| 4084 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4085 | if (!ToConditionVariable) |
| 4086 | return nullptr; |
| 4087 | } |
| 4088 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4089 | if (!ToCondition && S->getCond()) |
| 4090 | return nullptr; |
| 4091 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4092 | if (!ToBody && S->getBody()) |
| 4093 | return nullptr; |
| 4094 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 4095 | return new (Importer.getToContext()) WhileStmt(Importer.getToContext(), |
| 4096 | ToConditionVariable, |
| 4097 | ToCondition, ToBody, |
| 4098 | ToWhileLoc); |
| 4099 | } |
| 4100 | |
| 4101 | Stmt *ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 4102 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4103 | if (!ToBody && S->getBody()) |
| 4104 | return nullptr; |
| 4105 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4106 | if (!ToCondition && S->getCond()) |
| 4107 | return nullptr; |
| 4108 | SourceLocation ToDoLoc = Importer.Import(S->getDoLoc()); |
| 4109 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 4110 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4111 | return new (Importer.getToContext()) DoStmt(ToBody, ToCondition, |
| 4112 | ToDoLoc, ToWhileLoc, |
| 4113 | ToRParenLoc); |
| 4114 | } |
| 4115 | |
| 4116 | Stmt *ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 4117 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4118 | if (!ToInit && S->getInit()) |
| 4119 | return nullptr; |
| 4120 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4121 | if (!ToCondition && S->getCond()) |
| 4122 | return nullptr; |
| 4123 | VarDecl *ToConditionVariable = nullptr; |
| 4124 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4125 | ToConditionVariable = |
| 4126 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4127 | if (!ToConditionVariable) |
| 4128 | return nullptr; |
| 4129 | } |
| 4130 | Expr *ToInc = Importer.Import(S->getInc()); |
| 4131 | if (!ToInc && S->getInc()) |
| 4132 | return nullptr; |
| 4133 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4134 | if (!ToBody && S->getBody()) |
| 4135 | return nullptr; |
| 4136 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 4137 | SourceLocation ToLParenLoc = Importer.Import(S->getLParenLoc()); |
| 4138 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4139 | return new (Importer.getToContext()) ForStmt(Importer.getToContext(), |
| 4140 | ToInit, ToCondition, |
| 4141 | ToConditionVariable, |
| 4142 | ToInc, ToBody, |
| 4143 | ToForLoc, ToLParenLoc, |
| 4144 | ToRParenLoc); |
| 4145 | } |
| 4146 | |
| 4147 | Stmt *ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 4148 | LabelDecl *ToLabel = nullptr; |
| 4149 | if (LabelDecl *FromLabel = S->getLabel()) { |
| 4150 | ToLabel = dyn_cast_or_null<LabelDecl>(Importer.Import(FromLabel)); |
| 4151 | if (!ToLabel) |
| 4152 | return nullptr; |
| 4153 | } |
| 4154 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 4155 | SourceLocation ToLabelLoc = Importer.Import(S->getLabelLoc()); |
| 4156 | return new (Importer.getToContext()) GotoStmt(ToLabel, |
| 4157 | ToGotoLoc, ToLabelLoc); |
| 4158 | } |
| 4159 | |
| 4160 | Stmt *ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 4161 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 4162 | SourceLocation ToStarLoc = Importer.Import(S->getStarLoc()); |
| 4163 | Expr *ToTarget = Importer.Import(S->getTarget()); |
| 4164 | if (!ToTarget && S->getTarget()) |
| 4165 | return nullptr; |
| 4166 | return new (Importer.getToContext()) IndirectGotoStmt(ToGotoLoc, ToStarLoc, |
| 4167 | ToTarget); |
| 4168 | } |
| 4169 | |
| 4170 | Stmt *ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 4171 | SourceLocation ToContinueLoc = Importer.Import(S->getContinueLoc()); |
| 4172 | return new (Importer.getToContext()) ContinueStmt(ToContinueLoc); |
| 4173 | } |
| 4174 | |
| 4175 | Stmt *ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 4176 | SourceLocation ToBreakLoc = Importer.Import(S->getBreakLoc()); |
| 4177 | return new (Importer.getToContext()) BreakStmt(ToBreakLoc); |
| 4178 | } |
| 4179 | |
| 4180 | Stmt *ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 4181 | SourceLocation ToRetLoc = Importer.Import(S->getReturnLoc()); |
| 4182 | Expr *ToRetExpr = Importer.Import(S->getRetValue()); |
| 4183 | if (!ToRetExpr && S->getRetValue()) |
| 4184 | return nullptr; |
| 4185 | VarDecl *NRVOCandidate = const_cast<VarDecl*>(S->getNRVOCandidate()); |
| 4186 | VarDecl *ToNRVOCandidate = cast_or_null<VarDecl>(Importer.Import(NRVOCandidate)); |
| 4187 | if (!ToNRVOCandidate && NRVOCandidate) |
| 4188 | return nullptr; |
| 4189 | return new (Importer.getToContext()) ReturnStmt(ToRetLoc, ToRetExpr, |
| 4190 | ToNRVOCandidate); |
| 4191 | } |
| 4192 | |
| 4193 | Stmt *ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 4194 | SourceLocation ToCatchLoc = Importer.Import(S->getCatchLoc()); |
| 4195 | VarDecl *ToExceptionDecl = nullptr; |
| 4196 | if (VarDecl *FromExceptionDecl = S->getExceptionDecl()) { |
| 4197 | ToExceptionDecl = |
| 4198 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 4199 | if (!ToExceptionDecl) |
| 4200 | return nullptr; |
| 4201 | } |
| 4202 | Stmt *ToHandlerBlock = Importer.Import(S->getHandlerBlock()); |
| 4203 | if (!ToHandlerBlock && S->getHandlerBlock()) |
| 4204 | return nullptr; |
| 4205 | return new (Importer.getToContext()) CXXCatchStmt(ToCatchLoc, |
| 4206 | ToExceptionDecl, |
| 4207 | ToHandlerBlock); |
| 4208 | } |
| 4209 | |
| 4210 | Stmt *ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 4211 | SourceLocation ToTryLoc = Importer.Import(S->getTryLoc()); |
| 4212 | Stmt *ToTryBlock = Importer.Import(S->getTryBlock()); |
| 4213 | if (!ToTryBlock && S->getTryBlock()) |
| 4214 | return nullptr; |
| 4215 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 4216 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 4217 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
| 4218 | if (Stmt *ToHandler = Importer.Import(FromHandler)) |
| 4219 | ToHandlers[HI] = ToHandler; |
| 4220 | else |
| 4221 | return nullptr; |
| 4222 | } |
| 4223 | return CXXTryStmt::Create(Importer.getToContext(), ToTryLoc, ToTryBlock, |
| 4224 | ToHandlers); |
| 4225 | } |
| 4226 | |
| 4227 | Stmt *ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
| 4228 | DeclStmt *ToRange = |
| 4229 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getRangeStmt())); |
| 4230 | if (!ToRange && S->getRangeStmt()) |
| 4231 | return nullptr; |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 4232 | DeclStmt *ToBegin = |
| 4233 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getBeginStmt())); |
| 4234 | if (!ToBegin && S->getBeginStmt()) |
| 4235 | return nullptr; |
| 4236 | DeclStmt *ToEnd = |
| 4237 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getEndStmt())); |
| 4238 | if (!ToEnd && S->getEndStmt()) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4239 | return nullptr; |
| 4240 | Expr *ToCond = Importer.Import(S->getCond()); |
| 4241 | if (!ToCond && S->getCond()) |
| 4242 | return nullptr; |
| 4243 | Expr *ToInc = Importer.Import(S->getInc()); |
| 4244 | if (!ToInc && S->getInc()) |
| 4245 | return nullptr; |
| 4246 | DeclStmt *ToLoopVar = |
| 4247 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getLoopVarStmt())); |
| 4248 | if (!ToLoopVar && S->getLoopVarStmt()) |
| 4249 | return nullptr; |
| 4250 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4251 | if (!ToBody && S->getBody()) |
| 4252 | return nullptr; |
| 4253 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 4254 | SourceLocation ToCoawaitLoc = Importer.Import(S->getCoawaitLoc()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4255 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 4256 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 4257 | return new (Importer.getToContext()) CXXForRangeStmt(ToRange, ToBegin, ToEnd, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4258 | ToCond, ToInc, |
| 4259 | ToLoopVar, ToBody, |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 4260 | ToForLoc, ToCoawaitLoc, |
| 4261 | ToColonLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | Stmt *ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 4265 | Stmt *ToElem = Importer.Import(S->getElement()); |
| 4266 | if (!ToElem && S->getElement()) |
| 4267 | return nullptr; |
| 4268 | Expr *ToCollect = Importer.Import(S->getCollection()); |
| 4269 | if (!ToCollect && S->getCollection()) |
| 4270 | return nullptr; |
| 4271 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4272 | if (!ToBody && S->getBody()) |
| 4273 | return nullptr; |
| 4274 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 4275 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4276 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElem, |
| 4277 | ToCollect, |
| 4278 | ToBody, ToForLoc, |
| 4279 | ToRParenLoc); |
| 4280 | } |
| 4281 | |
| 4282 | Stmt *ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 4283 | SourceLocation ToAtCatchLoc = Importer.Import(S->getAtCatchLoc()); |
| 4284 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4285 | VarDecl *ToExceptionDecl = nullptr; |
| 4286 | if (VarDecl *FromExceptionDecl = S->getCatchParamDecl()) { |
| 4287 | ToExceptionDecl = |
| 4288 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 4289 | if (!ToExceptionDecl) |
| 4290 | return nullptr; |
| 4291 | } |
| 4292 | Stmt *ToBody = Importer.Import(S->getCatchBody()); |
| 4293 | if (!ToBody && S->getCatchBody()) |
| 4294 | return nullptr; |
| 4295 | return new (Importer.getToContext()) ObjCAtCatchStmt(ToAtCatchLoc, |
| 4296 | ToRParenLoc, |
| 4297 | ToExceptionDecl, |
| 4298 | ToBody); |
| 4299 | } |
| 4300 | |
| 4301 | Stmt *ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 4302 | SourceLocation ToAtFinallyLoc = Importer.Import(S->getAtFinallyLoc()); |
| 4303 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyBody()); |
| 4304 | if (!ToAtFinallyStmt && S->getFinallyBody()) |
| 4305 | return nullptr; |
| 4306 | return new (Importer.getToContext()) ObjCAtFinallyStmt(ToAtFinallyLoc, |
| 4307 | ToAtFinallyStmt); |
| 4308 | } |
| 4309 | |
| 4310 | Stmt *ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 4311 | SourceLocation ToAtTryLoc = Importer.Import(S->getAtTryLoc()); |
| 4312 | Stmt *ToAtTryStmt = Importer.Import(S->getTryBody()); |
| 4313 | if (!ToAtTryStmt && S->getTryBody()) |
| 4314 | return nullptr; |
| 4315 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 4316 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 4317 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
| 4318 | if (Stmt *ToCatchStmt = Importer.Import(FromCatchStmt)) |
| 4319 | ToCatchStmts[CI] = ToCatchStmt; |
| 4320 | else |
| 4321 | return nullptr; |
| 4322 | } |
| 4323 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyStmt()); |
| 4324 | if (!ToAtFinallyStmt && S->getFinallyStmt()) |
| 4325 | return nullptr; |
| 4326 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
| 4327 | ToAtTryLoc, ToAtTryStmt, |
| 4328 | ToCatchStmts.begin(), ToCatchStmts.size(), |
| 4329 | ToAtFinallyStmt); |
| 4330 | } |
| 4331 | |
| 4332 | Stmt *ASTNodeImporter::VisitObjCAtSynchronizedStmt |
| 4333 | (ObjCAtSynchronizedStmt *S) { |
| 4334 | SourceLocation ToAtSynchronizedLoc = |
| 4335 | Importer.Import(S->getAtSynchronizedLoc()); |
| 4336 | Expr *ToSynchExpr = Importer.Import(S->getSynchExpr()); |
| 4337 | if (!ToSynchExpr && S->getSynchExpr()) |
| 4338 | return nullptr; |
| 4339 | Stmt *ToSynchBody = Importer.Import(S->getSynchBody()); |
| 4340 | if (!ToSynchBody && S->getSynchBody()) |
| 4341 | return nullptr; |
| 4342 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 4343 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 4344 | } |
| 4345 | |
| 4346 | Stmt *ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 4347 | SourceLocation ToAtThrowLoc = Importer.Import(S->getThrowLoc()); |
| 4348 | Expr *ToThrow = Importer.Import(S->getThrowExpr()); |
| 4349 | if (!ToThrow && S->getThrowExpr()) |
| 4350 | return nullptr; |
| 4351 | return new (Importer.getToContext()) ObjCAtThrowStmt(ToAtThrowLoc, ToThrow); |
| 4352 | } |
| 4353 | |
| 4354 | Stmt *ASTNodeImporter::VisitObjCAutoreleasePoolStmt |
| 4355 | (ObjCAutoreleasePoolStmt *S) { |
| 4356 | SourceLocation ToAtLoc = Importer.Import(S->getAtLoc()); |
| 4357 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4358 | if (!ToSubStmt && S->getSubStmt()) |
| 4359 | return nullptr; |
| 4360 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(ToAtLoc, |
| 4361 | ToSubStmt); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4362 | } |
| 4363 | |
| 4364 | //---------------------------------------------------------------------------- |
| 4365 | // Import Expressions |
| 4366 | //---------------------------------------------------------------------------- |
| 4367 | Expr *ASTNodeImporter::VisitExpr(Expr *E) { |
| 4368 | Importer.FromDiag(E->getLocStart(), diag::err_unsupported_ast_node) |
| 4369 | << E->getStmtClassName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4370 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4371 | } |
| 4372 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4373 | Expr *ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 4374 | QualType T = Importer.Import(E->getType()); |
| 4375 | if (T.isNull()) |
| 4376 | return nullptr; |
| 4377 | |
| 4378 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 4379 | if (!SubExpr && E->getSubExpr()) |
| 4380 | return nullptr; |
| 4381 | |
| 4382 | TypeSourceInfo *TInfo = Importer.Import(E->getWrittenTypeInfo()); |
| 4383 | if (!TInfo) |
| 4384 | return nullptr; |
| 4385 | |
| 4386 | return new (Importer.getToContext()) VAArgExpr( |
| 4387 | Importer.Import(E->getBuiltinLoc()), SubExpr, TInfo, |
| 4388 | Importer.Import(E->getRParenLoc()), T, E->isMicrosoftABI()); |
| 4389 | } |
| 4390 | |
| 4391 | |
| 4392 | Expr *ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 4393 | QualType T = Importer.Import(E->getType()); |
| 4394 | if (T.isNull()) |
| 4395 | return nullptr; |
| 4396 | |
| 4397 | return new (Importer.getToContext()) GNUNullExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4398 | T, Importer.Import(E->getLocStart())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4399 | } |
| 4400 | |
| 4401 | Expr *ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 4402 | QualType T = Importer.Import(E->getType()); |
| 4403 | if (T.isNull()) |
| 4404 | return nullptr; |
| 4405 | |
| 4406 | StringLiteral *SL = cast_or_null<StringLiteral>( |
| 4407 | Importer.Import(E->getFunctionName())); |
| 4408 | if (!SL && E->getFunctionName()) |
| 4409 | return nullptr; |
| 4410 | |
| 4411 | return new (Importer.getToContext()) PredefinedExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4412 | Importer.Import(E->getLocStart()), T, E->getIdentType(), SL); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4413 | } |
| 4414 | |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 4415 | Expr *ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 4416 | ValueDecl *ToD = cast_or_null<ValueDecl>(Importer.Import(E->getDecl())); |
| 4417 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4418 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 4419 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4420 | NamedDecl *FoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 4421 | if (E->getDecl() != E->getFoundDecl()) { |
| 4422 | FoundD = cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl())); |
| 4423 | if (!FoundD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4424 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 4425 | } |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 4426 | |
| 4427 | QualType T = Importer.Import(E->getType()); |
| 4428 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4429 | return nullptr; |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 4430 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4431 | |
| 4432 | TemplateArgumentListInfo ToTAInfo; |
| 4433 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 4434 | if (E->hasExplicitTemplateArgs()) { |
| 4435 | for (const auto &FromLoc : E->template_arguments()) { |
| 4436 | bool Error = false; |
| 4437 | TemplateArgumentLoc ToTALoc = ImportTemplateArgumentLoc(FromLoc, Error); |
| 4438 | if (Error) |
| 4439 | return nullptr; |
| 4440 | ToTAInfo.addArgument(ToTALoc); |
| 4441 | } |
| 4442 | ResInfo = &ToTAInfo; |
| 4443 | } |
| 4444 | |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 4445 | DeclRefExpr *DRE = DeclRefExpr::Create(Importer.getToContext(), |
| 4446 | Importer.Import(E->getQualifierLoc()), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 4447 | Importer.Import(E->getTemplateKeywordLoc()), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 4448 | ToD, |
Alexey Bataev | 19acc3d | 2015-01-12 10:17:46 +0000 | [diff] [blame] | 4449 | E->refersToEnclosingVariableOrCapture(), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 4450 | Importer.Import(E->getLocation()), |
| 4451 | T, E->getValueKind(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4452 | FoundD, ResInfo); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 4453 | if (E->hadMultipleCandidates()) |
| 4454 | DRE->setHadMultipleCandidates(true); |
| 4455 | return DRE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 4456 | } |
| 4457 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4458 | Expr *ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 4459 | QualType T = Importer.Import(E->getType()); |
| 4460 | if (T.isNull()) |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4461 | return nullptr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4462 | |
| 4463 | return new (Importer.getToContext()) ImplicitValueInitExpr(T); |
| 4464 | } |
| 4465 | |
| 4466 | ASTNodeImporter::Designator |
| 4467 | ASTNodeImporter::ImportDesignator(const Designator &D) { |
| 4468 | if (D.isFieldDesignator()) { |
| 4469 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 4470 | // Caller checks for import error |
| 4471 | return Designator(ToFieldName, Importer.Import(D.getDotLoc()), |
| 4472 | Importer.Import(D.getFieldLoc())); |
| 4473 | } |
| 4474 | if (D.isArrayDesignator()) |
| 4475 | return Designator(D.getFirstExprIndex(), |
| 4476 | Importer.Import(D.getLBracketLoc()), |
| 4477 | Importer.Import(D.getRBracketLoc())); |
| 4478 | |
| 4479 | assert(D.isArrayRangeDesignator()); |
| 4480 | return Designator(D.getFirstExprIndex(), |
| 4481 | Importer.Import(D.getLBracketLoc()), |
| 4482 | Importer.Import(D.getEllipsisLoc()), |
| 4483 | Importer.Import(D.getRBracketLoc())); |
| 4484 | } |
| 4485 | |
| 4486 | |
| 4487 | Expr *ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *DIE) { |
| 4488 | Expr *Init = cast_or_null<Expr>(Importer.Import(DIE->getInit())); |
| 4489 | if (!Init) |
| 4490 | return nullptr; |
| 4491 | |
| 4492 | SmallVector<Expr *, 4> IndexExprs(DIE->getNumSubExprs() - 1); |
| 4493 | // List elements from the second, the first is Init itself |
| 4494 | for (unsigned I = 1, E = DIE->getNumSubExprs(); I < E; I++) { |
| 4495 | if (Expr *Arg = cast_or_null<Expr>(Importer.Import(DIE->getSubExpr(I)))) |
| 4496 | IndexExprs[I - 1] = Arg; |
| 4497 | else |
| 4498 | return nullptr; |
| 4499 | } |
| 4500 | |
| 4501 | SmallVector<Designator, 4> Designators(DIE->size()); |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 4502 | llvm::transform(DIE->designators(), Designators.begin(), |
| 4503 | [this](const Designator &D) -> Designator { |
| 4504 | return ImportDesignator(D); |
| 4505 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4506 | |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 4507 | for (const Designator &D : DIE->designators()) |
| 4508 | if (D.isFieldDesignator() && !D.getFieldName()) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4509 | return nullptr; |
| 4510 | |
| 4511 | return DesignatedInitExpr::Create( |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 4512 | Importer.getToContext(), Designators, |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4513 | IndexExprs, Importer.Import(DIE->getEqualOrColonLoc()), |
| 4514 | DIE->usesGNUSyntax(), Init); |
| 4515 | } |
| 4516 | |
| 4517 | Expr *ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 4518 | QualType T = Importer.Import(E->getType()); |
| 4519 | if (T.isNull()) |
| 4520 | return nullptr; |
| 4521 | |
| 4522 | return new (Importer.getToContext()) |
| 4523 | CXXNullPtrLiteralExpr(T, Importer.Import(E->getLocation())); |
| 4524 | } |
| 4525 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4526 | Expr *ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 4527 | QualType T = Importer.Import(E->getType()); |
| 4528 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4529 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4530 | |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 4531 | return IntegerLiteral::Create(Importer.getToContext(), |
| 4532 | E->getValue(), T, |
| 4533 | Importer.Import(E->getLocation())); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4534 | } |
| 4535 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4536 | Expr *ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 4537 | QualType T = Importer.Import(E->getType()); |
| 4538 | if (T.isNull()) |
| 4539 | return nullptr; |
| 4540 | |
| 4541 | return FloatingLiteral::Create(Importer.getToContext(), |
| 4542 | E->getValue(), E->isExact(), T, |
| 4543 | Importer.Import(E->getLocation())); |
| 4544 | } |
| 4545 | |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 4546 | Expr *ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 4547 | QualType T = Importer.Import(E->getType()); |
| 4548 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4549 | return nullptr; |
| 4550 | |
Douglas Gregor | fb65e59 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 4551 | return new (Importer.getToContext()) CharacterLiteral(E->getValue(), |
| 4552 | E->getKind(), T, |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 4553 | Importer.Import(E->getLocation())); |
| 4554 | } |
| 4555 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4556 | Expr *ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 4557 | QualType T = Importer.Import(E->getType()); |
| 4558 | if (T.isNull()) |
| 4559 | return nullptr; |
| 4560 | |
| 4561 | SmallVector<SourceLocation, 4> Locations(E->getNumConcatenated()); |
| 4562 | ImportArray(E->tokloc_begin(), E->tokloc_end(), Locations.begin()); |
| 4563 | |
| 4564 | return StringLiteral::Create(Importer.getToContext(), E->getBytes(), |
| 4565 | E->getKind(), E->isPascal(), T, |
| 4566 | Locations.data(), Locations.size()); |
| 4567 | } |
| 4568 | |
| 4569 | Expr *ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 4570 | QualType T = Importer.Import(E->getType()); |
| 4571 | if (T.isNull()) |
| 4572 | return nullptr; |
| 4573 | |
| 4574 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeSourceInfo()); |
| 4575 | if (!TInfo) |
| 4576 | return nullptr; |
| 4577 | |
| 4578 | Expr *Init = Importer.Import(E->getInitializer()); |
| 4579 | if (!Init) |
| 4580 | return nullptr; |
| 4581 | |
| 4582 | return new (Importer.getToContext()) CompoundLiteralExpr( |
| 4583 | Importer.Import(E->getLParenLoc()), TInfo, T, E->getValueKind(), |
| 4584 | Init, E->isFileScope()); |
| 4585 | } |
| 4586 | |
| 4587 | Expr *ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 4588 | QualType T = Importer.Import(E->getType()); |
| 4589 | if (T.isNull()) |
| 4590 | return nullptr; |
| 4591 | |
| 4592 | SmallVector<Expr *, 6> Exprs(E->getNumSubExprs()); |
| 4593 | if (ImportArrayChecked( |
| 4594 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 4595 | Exprs.begin())) |
| 4596 | return nullptr; |
| 4597 | |
| 4598 | return new (Importer.getToContext()) AtomicExpr( |
| 4599 | Importer.Import(E->getBuiltinLoc()), Exprs, T, E->getOp(), |
| 4600 | Importer.Import(E->getRParenLoc())); |
| 4601 | } |
| 4602 | |
| 4603 | Expr *ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 4604 | QualType T = Importer.Import(E->getType()); |
| 4605 | if (T.isNull()) |
| 4606 | return nullptr; |
| 4607 | |
| 4608 | LabelDecl *ToLabel = cast_or_null<LabelDecl>(Importer.Import(E->getLabel())); |
| 4609 | if (!ToLabel) |
| 4610 | return nullptr; |
| 4611 | |
| 4612 | return new (Importer.getToContext()) AddrLabelExpr( |
| 4613 | Importer.Import(E->getAmpAmpLoc()), Importer.Import(E->getLabelLoc()), |
| 4614 | ToLabel, T); |
| 4615 | } |
| 4616 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4617 | Expr *ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 4618 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 4619 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4620 | return nullptr; |
| 4621 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4622 | return new (Importer.getToContext()) |
| 4623 | ParenExpr(Importer.Import(E->getLParen()), |
| 4624 | Importer.Import(E->getRParen()), |
| 4625 | SubExpr); |
| 4626 | } |
| 4627 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4628 | Expr *ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 4629 | SmallVector<Expr *, 4> Exprs(E->getNumExprs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4630 | if (ImportContainerChecked(E->exprs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4631 | return nullptr; |
| 4632 | |
| 4633 | return new (Importer.getToContext()) ParenListExpr( |
| 4634 | Importer.getToContext(), Importer.Import(E->getLParenLoc()), |
| 4635 | Exprs, Importer.Import(E->getLParenLoc())); |
| 4636 | } |
| 4637 | |
| 4638 | Expr *ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 4639 | QualType T = Importer.Import(E->getType()); |
| 4640 | if (T.isNull()) |
| 4641 | return nullptr; |
| 4642 | |
| 4643 | CompoundStmt *ToSubStmt = cast_or_null<CompoundStmt>( |
| 4644 | Importer.Import(E->getSubStmt())); |
| 4645 | if (!ToSubStmt && E->getSubStmt()) |
| 4646 | return nullptr; |
| 4647 | |
| 4648 | return new (Importer.getToContext()) StmtExpr(ToSubStmt, T, |
| 4649 | Importer.Import(E->getLParenLoc()), Importer.Import(E->getRParenLoc())); |
| 4650 | } |
| 4651 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4652 | Expr *ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 4653 | QualType T = Importer.Import(E->getType()); |
| 4654 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4655 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4656 | |
| 4657 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 4658 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4659 | return nullptr; |
| 4660 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4661 | return new (Importer.getToContext()) UnaryOperator(SubExpr, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 4662 | T, E->getValueKind(), |
| 4663 | E->getObjectKind(), |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4664 | Importer.Import(E->getOperatorLoc())); |
| 4665 | } |
| 4666 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 4667 | Expr *ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr( |
| 4668 | UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 4669 | QualType ResultType = Importer.Import(E->getType()); |
| 4670 | |
| 4671 | if (E->isArgumentType()) { |
| 4672 | TypeSourceInfo *TInfo = Importer.Import(E->getArgumentTypeInfo()); |
| 4673 | if (!TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4674 | return nullptr; |
| 4675 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 4676 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 4677 | TInfo, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 4678 | Importer.Import(E->getOperatorLoc()), |
| 4679 | Importer.Import(E->getRParenLoc())); |
| 4680 | } |
| 4681 | |
| 4682 | Expr *SubExpr = Importer.Import(E->getArgumentExpr()); |
| 4683 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4684 | return nullptr; |
| 4685 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 4686 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 4687 | SubExpr, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 4688 | Importer.Import(E->getOperatorLoc()), |
| 4689 | Importer.Import(E->getRParenLoc())); |
| 4690 | } |
| 4691 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4692 | Expr *ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 4693 | QualType T = Importer.Import(E->getType()); |
| 4694 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4695 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4696 | |
| 4697 | Expr *LHS = Importer.Import(E->getLHS()); |
| 4698 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4699 | return nullptr; |
| 4700 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4701 | Expr *RHS = Importer.Import(E->getRHS()); |
| 4702 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4703 | return nullptr; |
| 4704 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4705 | return new (Importer.getToContext()) BinaryOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 4706 | T, E->getValueKind(), |
| 4707 | E->getObjectKind(), |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 4708 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 4709 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4710 | } |
| 4711 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4712 | Expr *ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 4713 | QualType T = Importer.Import(E->getType()); |
| 4714 | if (T.isNull()) |
| 4715 | return nullptr; |
| 4716 | |
| 4717 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 4718 | if (!ToLHS) |
| 4719 | return nullptr; |
| 4720 | |
| 4721 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 4722 | if (!ToRHS) |
| 4723 | return nullptr; |
| 4724 | |
| 4725 | Expr *ToCond = Importer.Import(E->getCond()); |
| 4726 | if (!ToCond) |
| 4727 | return nullptr; |
| 4728 | |
| 4729 | return new (Importer.getToContext()) ConditionalOperator( |
| 4730 | ToCond, Importer.Import(E->getQuestionLoc()), |
| 4731 | ToLHS, Importer.Import(E->getColonLoc()), |
| 4732 | ToRHS, T, E->getValueKind(), E->getObjectKind()); |
| 4733 | } |
| 4734 | |
| 4735 | Expr *ASTNodeImporter::VisitBinaryConditionalOperator( |
| 4736 | BinaryConditionalOperator *E) { |
| 4737 | QualType T = Importer.Import(E->getType()); |
| 4738 | if (T.isNull()) |
| 4739 | return nullptr; |
| 4740 | |
| 4741 | Expr *Common = Importer.Import(E->getCommon()); |
| 4742 | if (!Common) |
| 4743 | return nullptr; |
| 4744 | |
| 4745 | Expr *Cond = Importer.Import(E->getCond()); |
| 4746 | if (!Cond) |
| 4747 | return nullptr; |
| 4748 | |
| 4749 | OpaqueValueExpr *OpaqueValue = cast_or_null<OpaqueValueExpr>( |
| 4750 | Importer.Import(E->getOpaqueValue())); |
| 4751 | if (!OpaqueValue) |
| 4752 | return nullptr; |
| 4753 | |
| 4754 | Expr *TrueExpr = Importer.Import(E->getTrueExpr()); |
| 4755 | if (!TrueExpr) |
| 4756 | return nullptr; |
| 4757 | |
| 4758 | Expr *FalseExpr = Importer.Import(E->getFalseExpr()); |
| 4759 | if (!FalseExpr) |
| 4760 | return nullptr; |
| 4761 | |
| 4762 | return new (Importer.getToContext()) BinaryConditionalOperator( |
| 4763 | Common, OpaqueValue, Cond, TrueExpr, FalseExpr, |
| 4764 | Importer.Import(E->getQuestionLoc()), Importer.Import(E->getColonLoc()), |
| 4765 | T, E->getValueKind(), E->getObjectKind()); |
| 4766 | } |
| 4767 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4768 | Expr *ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 4769 | QualType T = Importer.Import(E->getType()); |
| 4770 | if (T.isNull()) |
| 4771 | return nullptr; |
| 4772 | |
| 4773 | TypeSourceInfo *ToQueried = Importer.Import(E->getQueriedTypeSourceInfo()); |
| 4774 | if (!ToQueried) |
| 4775 | return nullptr; |
| 4776 | |
| 4777 | Expr *Dim = Importer.Import(E->getDimensionExpression()); |
| 4778 | if (!Dim && E->getDimensionExpression()) |
| 4779 | return nullptr; |
| 4780 | |
| 4781 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
| 4782 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 4783 | E->getValue(), Dim, Importer.Import(E->getLocEnd()), T); |
| 4784 | } |
| 4785 | |
| 4786 | Expr *ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 4787 | QualType T = Importer.Import(E->getType()); |
| 4788 | if (T.isNull()) |
| 4789 | return nullptr; |
| 4790 | |
| 4791 | Expr *ToQueried = Importer.Import(E->getQueriedExpression()); |
| 4792 | if (!ToQueried) |
| 4793 | return nullptr; |
| 4794 | |
| 4795 | return new (Importer.getToContext()) ExpressionTraitExpr( |
| 4796 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 4797 | E->getValue(), Importer.Import(E->getLocEnd()), T); |
| 4798 | } |
| 4799 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4800 | Expr *ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 4801 | QualType T = Importer.Import(E->getType()); |
| 4802 | if (T.isNull()) |
| 4803 | return nullptr; |
| 4804 | |
| 4805 | Expr *SourceExpr = Importer.Import(E->getSourceExpr()); |
| 4806 | if (!SourceExpr && E->getSourceExpr()) |
| 4807 | return nullptr; |
| 4808 | |
| 4809 | return new (Importer.getToContext()) OpaqueValueExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4810 | Importer.Import(E->getLocation()), T, E->getValueKind(), |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4811 | E->getObjectKind(), SourceExpr); |
| 4812 | } |
| 4813 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4814 | Expr *ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 4815 | QualType T = Importer.Import(E->getType()); |
| 4816 | if (T.isNull()) |
| 4817 | return nullptr; |
| 4818 | |
| 4819 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 4820 | if (!ToLHS) |
| 4821 | return nullptr; |
| 4822 | |
| 4823 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 4824 | if (!ToRHS) |
| 4825 | return nullptr; |
| 4826 | |
| 4827 | return new (Importer.getToContext()) ArraySubscriptExpr( |
| 4828 | ToLHS, ToRHS, T, E->getValueKind(), E->getObjectKind(), |
| 4829 | Importer.Import(E->getRBracketLoc())); |
| 4830 | } |
| 4831 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4832 | Expr *ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 4833 | QualType T = Importer.Import(E->getType()); |
| 4834 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4835 | return nullptr; |
| 4836 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4837 | QualType CompLHSType = Importer.Import(E->getComputationLHSType()); |
| 4838 | if (CompLHSType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4839 | return nullptr; |
| 4840 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4841 | QualType CompResultType = Importer.Import(E->getComputationResultType()); |
| 4842 | if (CompResultType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4843 | return nullptr; |
| 4844 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4845 | Expr *LHS = Importer.Import(E->getLHS()); |
| 4846 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4847 | return nullptr; |
| 4848 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4849 | Expr *RHS = Importer.Import(E->getRHS()); |
| 4850 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4851 | return nullptr; |
| 4852 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4853 | return new (Importer.getToContext()) |
| 4854 | CompoundAssignOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 4855 | T, E->getValueKind(), |
| 4856 | E->getObjectKind(), |
| 4857 | CompLHSType, CompResultType, |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 4858 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 4859 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 4860 | } |
| 4861 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4862 | bool ASTNodeImporter::ImportCastPath(CastExpr *CE, CXXCastPath &Path) { |
| 4863 | for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) { |
| 4864 | if (CXXBaseSpecifier *Spec = Importer.Import(*I)) |
| 4865 | Path.push_back(Spec); |
| 4866 | else |
| 4867 | return true; |
| 4868 | } |
| 4869 | return false; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 4870 | } |
| 4871 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 4872 | Expr *ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 4873 | QualType T = Importer.Import(E->getType()); |
| 4874 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4875 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 4876 | |
| 4877 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 4878 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4879 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 4880 | |
| 4881 | CXXCastPath BasePath; |
| 4882 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4883 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 4884 | |
| 4885 | return ImplicitCastExpr::Create(Importer.getToContext(), T, E->getCastKind(), |
John McCall | 2536c6d | 2010-08-25 10:28:54 +0000 | [diff] [blame] | 4886 | SubExpr, &BasePath, E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 4887 | } |
| 4888 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4889 | Expr *ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 4890 | QualType T = Importer.Import(E->getType()); |
| 4891 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4892 | return nullptr; |
| 4893 | |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 4894 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 4895 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4896 | return nullptr; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 4897 | |
| 4898 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeInfoAsWritten()); |
| 4899 | if (!TInfo && E->getTypeInfoAsWritten()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4900 | return nullptr; |
| 4901 | |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 4902 | CXXCastPath BasePath; |
| 4903 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4904 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 4905 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4906 | switch (E->getStmtClass()) { |
| 4907 | case Stmt::CStyleCastExprClass: { |
| 4908 | CStyleCastExpr *CCE = cast<CStyleCastExpr>(E); |
| 4909 | return CStyleCastExpr::Create(Importer.getToContext(), T, |
| 4910 | E->getValueKind(), E->getCastKind(), |
| 4911 | SubExpr, &BasePath, TInfo, |
| 4912 | Importer.Import(CCE->getLParenLoc()), |
| 4913 | Importer.Import(CCE->getRParenLoc())); |
| 4914 | } |
| 4915 | |
| 4916 | case Stmt::CXXFunctionalCastExprClass: { |
| 4917 | CXXFunctionalCastExpr *FCE = cast<CXXFunctionalCastExpr>(E); |
| 4918 | return CXXFunctionalCastExpr::Create(Importer.getToContext(), T, |
| 4919 | E->getValueKind(), TInfo, |
| 4920 | E->getCastKind(), SubExpr, &BasePath, |
| 4921 | Importer.Import(FCE->getLParenLoc()), |
| 4922 | Importer.Import(FCE->getRParenLoc())); |
| 4923 | } |
| 4924 | |
| 4925 | case Stmt::ObjCBridgedCastExprClass: { |
| 4926 | ObjCBridgedCastExpr *OCE = cast<ObjCBridgedCastExpr>(E); |
| 4927 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 4928 | Importer.Import(OCE->getLParenLoc()), OCE->getBridgeKind(), |
| 4929 | E->getCastKind(), Importer.Import(OCE->getBridgeKeywordLoc()), |
| 4930 | TInfo, SubExpr); |
| 4931 | } |
| 4932 | default: |
| 4933 | break; // just fall through |
| 4934 | } |
| 4935 | |
| 4936 | CXXNamedCastExpr *Named = cast<CXXNamedCastExpr>(E); |
| 4937 | SourceLocation ExprLoc = Importer.Import(Named->getOperatorLoc()), |
| 4938 | RParenLoc = Importer.Import(Named->getRParenLoc()); |
| 4939 | SourceRange Brackets = Importer.Import(Named->getAngleBrackets()); |
| 4940 | |
| 4941 | switch (E->getStmtClass()) { |
| 4942 | case Stmt::CXXStaticCastExprClass: |
| 4943 | return CXXStaticCastExpr::Create(Importer.getToContext(), T, |
| 4944 | E->getValueKind(), E->getCastKind(), |
| 4945 | SubExpr, &BasePath, TInfo, |
| 4946 | ExprLoc, RParenLoc, Brackets); |
| 4947 | |
| 4948 | case Stmt::CXXDynamicCastExprClass: |
| 4949 | return CXXDynamicCastExpr::Create(Importer.getToContext(), T, |
| 4950 | E->getValueKind(), E->getCastKind(), |
| 4951 | SubExpr, &BasePath, TInfo, |
| 4952 | ExprLoc, RParenLoc, Brackets); |
| 4953 | |
| 4954 | case Stmt::CXXReinterpretCastExprClass: |
| 4955 | return CXXReinterpretCastExpr::Create(Importer.getToContext(), T, |
| 4956 | E->getValueKind(), E->getCastKind(), |
| 4957 | SubExpr, &BasePath, TInfo, |
| 4958 | ExprLoc, RParenLoc, Brackets); |
| 4959 | |
| 4960 | case Stmt::CXXConstCastExprClass: |
| 4961 | return CXXConstCastExpr::Create(Importer.getToContext(), T, |
| 4962 | E->getValueKind(), SubExpr, TInfo, ExprLoc, |
| 4963 | RParenLoc, Brackets); |
| 4964 | default: |
| 4965 | llvm_unreachable("Cast expression of unsupported type!"); |
| 4966 | return nullptr; |
| 4967 | } |
| 4968 | } |
| 4969 | |
| 4970 | Expr *ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *OE) { |
| 4971 | QualType T = Importer.Import(OE->getType()); |
| 4972 | if (T.isNull()) |
| 4973 | return nullptr; |
| 4974 | |
| 4975 | SmallVector<OffsetOfNode, 4> Nodes; |
| 4976 | for (int I = 0, E = OE->getNumComponents(); I < E; ++I) { |
| 4977 | const OffsetOfNode &Node = OE->getComponent(I); |
| 4978 | |
| 4979 | switch (Node.getKind()) { |
| 4980 | case OffsetOfNode::Array: |
| 4981 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), |
| 4982 | Node.getArrayExprIndex(), |
| 4983 | Importer.Import(Node.getLocEnd()))); |
| 4984 | break; |
| 4985 | |
| 4986 | case OffsetOfNode::Base: { |
| 4987 | CXXBaseSpecifier *BS = Importer.Import(Node.getBase()); |
| 4988 | if (!BS && Node.getBase()) |
| 4989 | return nullptr; |
| 4990 | Nodes.push_back(OffsetOfNode(BS)); |
| 4991 | break; |
| 4992 | } |
| 4993 | case OffsetOfNode::Field: { |
| 4994 | FieldDecl *FD = cast_or_null<FieldDecl>(Importer.Import(Node.getField())); |
| 4995 | if (!FD) |
| 4996 | return nullptr; |
| 4997 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), FD, |
| 4998 | Importer.Import(Node.getLocEnd()))); |
| 4999 | break; |
| 5000 | } |
| 5001 | case OffsetOfNode::Identifier: { |
| 5002 | IdentifierInfo *ToII = Importer.Import(Node.getFieldName()); |
| 5003 | if (!ToII) |
| 5004 | return nullptr; |
| 5005 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), ToII, |
| 5006 | Importer.Import(Node.getLocEnd()))); |
| 5007 | break; |
| 5008 | } |
| 5009 | } |
| 5010 | } |
| 5011 | |
| 5012 | SmallVector<Expr *, 4> Exprs(OE->getNumExpressions()); |
| 5013 | for (int I = 0, E = OE->getNumExpressions(); I < E; ++I) { |
| 5014 | Expr *ToIndexExpr = Importer.Import(OE->getIndexExpr(I)); |
| 5015 | if (!ToIndexExpr) |
| 5016 | return nullptr; |
| 5017 | Exprs[I] = ToIndexExpr; |
| 5018 | } |
| 5019 | |
| 5020 | TypeSourceInfo *TInfo = Importer.Import(OE->getTypeSourceInfo()); |
| 5021 | if (!TInfo && OE->getTypeSourceInfo()) |
| 5022 | return nullptr; |
| 5023 | |
| 5024 | return OffsetOfExpr::Create(Importer.getToContext(), T, |
| 5025 | Importer.Import(OE->getOperatorLoc()), |
| 5026 | TInfo, Nodes, Exprs, |
| 5027 | Importer.Import(OE->getRParenLoc())); |
| 5028 | } |
| 5029 | |
| 5030 | Expr *ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 5031 | QualType T = Importer.Import(E->getType()); |
| 5032 | if (T.isNull()) |
| 5033 | return nullptr; |
| 5034 | |
| 5035 | Expr *Operand = Importer.Import(E->getOperand()); |
| 5036 | if (!Operand) |
| 5037 | return nullptr; |
| 5038 | |
| 5039 | CanThrowResult CanThrow; |
| 5040 | if (E->isValueDependent()) |
| 5041 | CanThrow = CT_Dependent; |
| 5042 | else |
| 5043 | CanThrow = E->getValue() ? CT_Can : CT_Cannot; |
| 5044 | |
| 5045 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 5046 | T, Operand, CanThrow, |
| 5047 | Importer.Import(E->getLocStart()), Importer.Import(E->getLocEnd())); |
| 5048 | } |
| 5049 | |
| 5050 | Expr *ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 5051 | QualType T = Importer.Import(E->getType()); |
| 5052 | if (T.isNull()) |
| 5053 | return nullptr; |
| 5054 | |
| 5055 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5056 | if (!SubExpr && E->getSubExpr()) |
| 5057 | return nullptr; |
| 5058 | |
| 5059 | return new (Importer.getToContext()) CXXThrowExpr( |
| 5060 | SubExpr, T, Importer.Import(E->getThrowLoc()), |
| 5061 | E->isThrownVariableInScope()); |
| 5062 | } |
| 5063 | |
| 5064 | Expr *ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 5065 | ParmVarDecl *Param = cast_or_null<ParmVarDecl>( |
| 5066 | Importer.Import(E->getParam())); |
| 5067 | if (!Param) |
| 5068 | return nullptr; |
| 5069 | |
| 5070 | return CXXDefaultArgExpr::Create( |
| 5071 | Importer.getToContext(), Importer.Import(E->getUsedLocation()), Param); |
| 5072 | } |
| 5073 | |
| 5074 | Expr *ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 5075 | QualType T = Importer.Import(E->getType()); |
| 5076 | if (T.isNull()) |
| 5077 | return nullptr; |
| 5078 | |
| 5079 | TypeSourceInfo *TypeInfo = Importer.Import(E->getTypeSourceInfo()); |
| 5080 | if (!TypeInfo) |
| 5081 | return nullptr; |
| 5082 | |
| 5083 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
| 5084 | T, TypeInfo, Importer.Import(E->getRParenLoc())); |
| 5085 | } |
| 5086 | |
| 5087 | Expr *ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 5088 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5089 | if (!SubExpr) |
| 5090 | return nullptr; |
| 5091 | |
| 5092 | auto *Dtor = cast_or_null<CXXDestructorDecl>( |
| 5093 | Importer.Import(const_cast<CXXDestructorDecl *>( |
| 5094 | E->getTemporary()->getDestructor()))); |
| 5095 | if (!Dtor) |
| 5096 | return nullptr; |
| 5097 | |
| 5098 | ASTContext &ToCtx = Importer.getToContext(); |
| 5099 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, Dtor); |
| 5100 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, SubExpr); |
| 5101 | } |
| 5102 | |
| 5103 | Expr *ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE) { |
| 5104 | QualType T = Importer.Import(CE->getType()); |
| 5105 | if (T.isNull()) |
| 5106 | return nullptr; |
| 5107 | |
| 5108 | SmallVector<Expr *, 8> Args(CE->getNumArgs()); |
| 5109 | if (ImportContainerChecked(CE->arguments(), Args)) |
| 5110 | return nullptr; |
| 5111 | |
| 5112 | auto *Ctor = cast_or_null<CXXConstructorDecl>( |
| 5113 | Importer.Import(CE->getConstructor())); |
| 5114 | if (!Ctor) |
| 5115 | return nullptr; |
| 5116 | |
| 5117 | return CXXTemporaryObjectExpr::Create( |
| 5118 | Importer.getToContext(), T, |
| 5119 | Importer.Import(CE->getLocStart()), |
| 5120 | Ctor, |
| 5121 | CE->isElidable(), |
| 5122 | Args, |
| 5123 | CE->hadMultipleCandidates(), |
| 5124 | CE->isListInitialization(), |
| 5125 | CE->isStdInitListInitialization(), |
| 5126 | CE->requiresZeroInitialization(), |
| 5127 | CE->getConstructionKind(), |
| 5128 | Importer.Import(CE->getParenOrBraceRange())); |
| 5129 | } |
| 5130 | |
| 5131 | Expr * |
| 5132 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
| 5133 | QualType T = Importer.Import(E->getType()); |
| 5134 | if (T.isNull()) |
| 5135 | return nullptr; |
| 5136 | |
| 5137 | Expr *TempE = Importer.Import(E->GetTemporaryExpr()); |
| 5138 | if (!TempE) |
| 5139 | return nullptr; |
| 5140 | |
| 5141 | ValueDecl *ExtendedBy = cast_or_null<ValueDecl>( |
| 5142 | Importer.Import(const_cast<ValueDecl *>(E->getExtendingDecl()))); |
| 5143 | if (!ExtendedBy && E->getExtendingDecl()) |
| 5144 | return nullptr; |
| 5145 | |
| 5146 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
| 5147 | T, TempE, E->isBoundToLvalueReference()); |
| 5148 | |
| 5149 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
| 5150 | ToMTE->setExtendingDecl(ExtendedBy, E->getManglingNumber()); |
| 5151 | return ToMTE; |
| 5152 | } |
| 5153 | |
| 5154 | Expr *ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *CE) { |
| 5155 | QualType T = Importer.Import(CE->getType()); |
| 5156 | if (T.isNull()) |
| 5157 | return nullptr; |
| 5158 | |
| 5159 | SmallVector<Expr *, 4> PlacementArgs(CE->getNumPlacementArgs()); |
| 5160 | if (ImportContainerChecked(CE->placement_arguments(), PlacementArgs)) |
| 5161 | return nullptr; |
| 5162 | |
| 5163 | FunctionDecl *OperatorNewDecl = cast_or_null<FunctionDecl>( |
| 5164 | Importer.Import(CE->getOperatorNew())); |
| 5165 | if (!OperatorNewDecl && CE->getOperatorNew()) |
| 5166 | return nullptr; |
| 5167 | |
| 5168 | FunctionDecl *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
| 5169 | Importer.Import(CE->getOperatorDelete())); |
| 5170 | if (!OperatorDeleteDecl && CE->getOperatorDelete()) |
| 5171 | return nullptr; |
| 5172 | |
| 5173 | Expr *ToInit = Importer.Import(CE->getInitializer()); |
| 5174 | if (!ToInit && CE->getInitializer()) |
| 5175 | return nullptr; |
| 5176 | |
| 5177 | TypeSourceInfo *TInfo = Importer.Import(CE->getAllocatedTypeSourceInfo()); |
| 5178 | if (!TInfo) |
| 5179 | return nullptr; |
| 5180 | |
| 5181 | Expr *ToArrSize = Importer.Import(CE->getArraySize()); |
| 5182 | if (!ToArrSize && CE->getArraySize()) |
| 5183 | return nullptr; |
| 5184 | |
| 5185 | return new (Importer.getToContext()) CXXNewExpr( |
| 5186 | Importer.getToContext(), |
| 5187 | CE->isGlobalNew(), |
| 5188 | OperatorNewDecl, OperatorDeleteDecl, |
Richard Smith | b2f0f05 | 2016-10-10 18:54:32 +0000 | [diff] [blame] | 5189 | CE->passAlignment(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5190 | CE->doesUsualArrayDeleteWantSize(), |
| 5191 | PlacementArgs, |
| 5192 | Importer.Import(CE->getTypeIdParens()), |
| 5193 | ToArrSize, CE->getInitializationStyle(), ToInit, T, TInfo, |
| 5194 | Importer.Import(CE->getSourceRange()), |
| 5195 | Importer.Import(CE->getDirectInitRange())); |
| 5196 | } |
| 5197 | |
| 5198 | Expr *ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 5199 | QualType T = Importer.Import(E->getType()); |
| 5200 | if (T.isNull()) |
| 5201 | return nullptr; |
| 5202 | |
| 5203 | FunctionDecl *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
| 5204 | Importer.Import(E->getOperatorDelete())); |
| 5205 | if (!OperatorDeleteDecl && E->getOperatorDelete()) |
| 5206 | return nullptr; |
| 5207 | |
| 5208 | Expr *ToArg = Importer.Import(E->getArgument()); |
| 5209 | if (!ToArg && E->getArgument()) |
| 5210 | return nullptr; |
| 5211 | |
| 5212 | return new (Importer.getToContext()) CXXDeleteExpr( |
| 5213 | T, E->isGlobalDelete(), |
| 5214 | E->isArrayForm(), |
| 5215 | E->isArrayFormAsWritten(), |
| 5216 | E->doesUsualArrayDeleteWantSize(), |
| 5217 | OperatorDeleteDecl, |
| 5218 | ToArg, |
| 5219 | Importer.Import(E->getLocStart())); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5220 | } |
| 5221 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5222 | Expr *ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 5223 | QualType T = Importer.Import(E->getType()); |
| 5224 | if (T.isNull()) |
| 5225 | return nullptr; |
| 5226 | |
| 5227 | CXXConstructorDecl *ToCCD = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 5228 | dyn_cast_or_null<CXXConstructorDecl>(Importer.Import(E->getConstructor())); |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 5229 | if (!ToCCD) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5230 | return nullptr; |
| 5231 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5232 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5233 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5234 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5235 | |
| 5236 | return CXXConstructExpr::Create(Importer.getToContext(), T, |
| 5237 | Importer.Import(E->getLocation()), |
Richard Smith | c83bf82 | 2016-06-10 00:58:19 +0000 | [diff] [blame] | 5238 | ToCCD, E->isElidable(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5239 | ToArgs, E->hadMultipleCandidates(), |
| 5240 | E->isListInitialization(), |
| 5241 | E->isStdInitListInitialization(), |
| 5242 | E->requiresZeroInitialization(), |
| 5243 | E->getConstructionKind(), |
| 5244 | Importer.Import(E->getParenOrBraceRange())); |
| 5245 | } |
| 5246 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5247 | Expr *ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *EWC) { |
| 5248 | Expr *SubExpr = Importer.Import(EWC->getSubExpr()); |
| 5249 | if (!SubExpr && EWC->getSubExpr()) |
| 5250 | return nullptr; |
| 5251 | |
| 5252 | SmallVector<ExprWithCleanups::CleanupObject, 8> Objs(EWC->getNumObjects()); |
| 5253 | for (unsigned I = 0, E = EWC->getNumObjects(); I < E; I++) |
| 5254 | if (ExprWithCleanups::CleanupObject Obj = |
| 5255 | cast_or_null<BlockDecl>(Importer.Import(EWC->getObject(I)))) |
| 5256 | Objs[I] = Obj; |
| 5257 | else |
| 5258 | return nullptr; |
| 5259 | |
| 5260 | return ExprWithCleanups::Create(Importer.getToContext(), |
| 5261 | SubExpr, EWC->cleanupsHaveSideEffects(), |
| 5262 | Objs); |
| 5263 | } |
| 5264 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5265 | Expr *ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 5266 | QualType T = Importer.Import(E->getType()); |
| 5267 | if (T.isNull()) |
| 5268 | return nullptr; |
| 5269 | |
| 5270 | Expr *ToFn = Importer.Import(E->getCallee()); |
| 5271 | if (!ToFn) |
| 5272 | return nullptr; |
| 5273 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5274 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5275 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5276 | return nullptr; |
| 5277 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5278 | return new (Importer.getToContext()) CXXMemberCallExpr( |
| 5279 | Importer.getToContext(), ToFn, ToArgs, T, E->getValueKind(), |
| 5280 | Importer.Import(E->getRParenLoc())); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5281 | } |
| 5282 | |
| 5283 | Expr *ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 5284 | QualType T = Importer.Import(E->getType()); |
| 5285 | if (T.isNull()) |
| 5286 | return nullptr; |
| 5287 | |
| 5288 | return new (Importer.getToContext()) |
| 5289 | CXXThisExpr(Importer.Import(E->getLocation()), T, E->isImplicit()); |
| 5290 | } |
| 5291 | |
| 5292 | Expr *ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 5293 | QualType T = Importer.Import(E->getType()); |
| 5294 | if (T.isNull()) |
| 5295 | return nullptr; |
| 5296 | |
| 5297 | return new (Importer.getToContext()) |
| 5298 | CXXBoolLiteralExpr(E->getValue(), T, Importer.Import(E->getLocation())); |
| 5299 | } |
| 5300 | |
| 5301 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5302 | Expr *ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 5303 | QualType T = Importer.Import(E->getType()); |
| 5304 | if (T.isNull()) |
| 5305 | return nullptr; |
| 5306 | |
| 5307 | Expr *ToBase = Importer.Import(E->getBase()); |
| 5308 | if (!ToBase && E->getBase()) |
| 5309 | return nullptr; |
| 5310 | |
| 5311 | ValueDecl *ToMember = dyn_cast<ValueDecl>(Importer.Import(E->getMemberDecl())); |
| 5312 | if (!ToMember && E->getMemberDecl()) |
| 5313 | return nullptr; |
| 5314 | |
| 5315 | DeclAccessPair ToFoundDecl = DeclAccessPair::make( |
| 5316 | dyn_cast<NamedDecl>(Importer.Import(E->getFoundDecl().getDecl())), |
| 5317 | E->getFoundDecl().getAccess()); |
| 5318 | |
| 5319 | DeclarationNameInfo ToMemberNameInfo( |
| 5320 | Importer.Import(E->getMemberNameInfo().getName()), |
| 5321 | Importer.Import(E->getMemberNameInfo().getLoc())); |
| 5322 | |
| 5323 | if (E->hasExplicitTemplateArgs()) { |
| 5324 | return nullptr; // FIXME: handle template arguments |
| 5325 | } |
| 5326 | |
| 5327 | return MemberExpr::Create(Importer.getToContext(), ToBase, |
| 5328 | E->isArrow(), |
| 5329 | Importer.Import(E->getOperatorLoc()), |
| 5330 | Importer.Import(E->getQualifierLoc()), |
| 5331 | Importer.Import(E->getTemplateKeywordLoc()), |
| 5332 | ToMember, ToFoundDecl, ToMemberNameInfo, |
| 5333 | nullptr, T, E->getValueKind(), |
| 5334 | E->getObjectKind()); |
| 5335 | } |
| 5336 | |
| 5337 | Expr *ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 5338 | QualType T = Importer.Import(E->getType()); |
| 5339 | if (T.isNull()) |
| 5340 | return nullptr; |
| 5341 | |
| 5342 | Expr *ToCallee = Importer.Import(E->getCallee()); |
| 5343 | if (!ToCallee && E->getCallee()) |
| 5344 | return nullptr; |
| 5345 | |
| 5346 | unsigned NumArgs = E->getNumArgs(); |
| 5347 | |
| 5348 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); |
| 5349 | |
| 5350 | for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) { |
| 5351 | Expr *FromArg = E->getArg(ai); |
| 5352 | Expr *ToArg = Importer.Import(FromArg); |
| 5353 | if (!ToArg) |
| 5354 | return nullptr; |
| 5355 | ToArgs[ai] = ToArg; |
| 5356 | } |
| 5357 | |
| 5358 | Expr **ToArgs_Copied = new (Importer.getToContext()) |
| 5359 | Expr*[NumArgs]; |
| 5360 | |
| 5361 | for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) |
| 5362 | ToArgs_Copied[ai] = ToArgs[ai]; |
| 5363 | |
| 5364 | return new (Importer.getToContext()) |
| 5365 | CallExpr(Importer.getToContext(), ToCallee, |
Craig Topper | c005cc0 | 2015-09-27 03:44:08 +0000 | [diff] [blame] | 5366 | llvm::makeArrayRef(ToArgs_Copied, NumArgs), T, E->getValueKind(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5367 | Importer.Import(E->getRParenLoc())); |
| 5368 | } |
| 5369 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5370 | Expr *ASTNodeImporter::VisitInitListExpr(InitListExpr *ILE) { |
| 5371 | QualType T = Importer.Import(ILE->getType()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5372 | if (T.isNull()) |
| 5373 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5374 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5375 | llvm::SmallVector<Expr *, 4> Exprs(ILE->getNumInits()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5376 | if (ImportContainerChecked(ILE->inits(), Exprs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5377 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5378 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5379 | ASTContext &ToCtx = Importer.getToContext(); |
| 5380 | InitListExpr *To = new (ToCtx) InitListExpr( |
| 5381 | ToCtx, Importer.Import(ILE->getLBraceLoc()), |
| 5382 | Exprs, Importer.Import(ILE->getLBraceLoc())); |
| 5383 | To->setType(T); |
| 5384 | |
| 5385 | if (ILE->hasArrayFiller()) { |
| 5386 | Expr *Filler = Importer.Import(ILE->getArrayFiller()); |
| 5387 | if (!Filler) |
| 5388 | return nullptr; |
| 5389 | To->setArrayFiller(Filler); |
| 5390 | } |
| 5391 | |
| 5392 | if (FieldDecl *FromFD = ILE->getInitializedFieldInUnion()) { |
| 5393 | FieldDecl *ToFD = cast_or_null<FieldDecl>(Importer.Import(FromFD)); |
| 5394 | if (!ToFD) |
| 5395 | return nullptr; |
| 5396 | To->setInitializedFieldInUnion(ToFD); |
| 5397 | } |
| 5398 | |
| 5399 | if (InitListExpr *SyntForm = ILE->getSyntacticForm()) { |
| 5400 | InitListExpr *ToSyntForm = cast_or_null<InitListExpr>( |
| 5401 | Importer.Import(SyntForm)); |
| 5402 | if (!ToSyntForm) |
| 5403 | return nullptr; |
| 5404 | To->setSyntacticForm(ToSyntForm); |
| 5405 | } |
| 5406 | |
| 5407 | To->sawArrayRangeDesignator(ILE->hadArrayRangeDesignator()); |
| 5408 | To->setValueDependent(ILE->isValueDependent()); |
| 5409 | To->setInstantiationDependent(ILE->isInstantiationDependent()); |
| 5410 | |
| 5411 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5412 | } |
| 5413 | |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 5414 | Expr *ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 5415 | QualType ToType = Importer.Import(E->getType()); |
| 5416 | if (ToType.isNull()) |
| 5417 | return nullptr; |
| 5418 | |
| 5419 | Expr *ToCommon = Importer.Import(E->getCommonExpr()); |
| 5420 | if (!ToCommon && E->getCommonExpr()) |
| 5421 | return nullptr; |
| 5422 | |
| 5423 | Expr *ToSubExpr = Importer.Import(E->getSubExpr()); |
| 5424 | if (!ToSubExpr && E->getSubExpr()) |
| 5425 | return nullptr; |
| 5426 | |
| 5427 | return new (Importer.getToContext()) |
| 5428 | ArrayInitLoopExpr(ToType, ToCommon, ToSubExpr); |
| 5429 | } |
| 5430 | |
| 5431 | Expr *ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 5432 | QualType ToType = Importer.Import(E->getType()); |
| 5433 | if (ToType.isNull()) |
| 5434 | return nullptr; |
| 5435 | return new (Importer.getToContext()) ArrayInitIndexExpr(ToType); |
| 5436 | } |
| 5437 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 5438 | Expr *ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) { |
| 5439 | FieldDecl *ToField = llvm::dyn_cast_or_null<FieldDecl>( |
| 5440 | Importer.Import(DIE->getField())); |
| 5441 | if (!ToField && DIE->getField()) |
| 5442 | return nullptr; |
| 5443 | |
| 5444 | return CXXDefaultInitExpr::Create( |
| 5445 | Importer.getToContext(), Importer.Import(DIE->getLocStart()), ToField); |
| 5446 | } |
| 5447 | |
| 5448 | Expr *ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 5449 | QualType ToType = Importer.Import(E->getType()); |
| 5450 | if (ToType.isNull() && !E->getType().isNull()) |
| 5451 | return nullptr; |
| 5452 | ExprValueKind VK = E->getValueKind(); |
| 5453 | CastKind CK = E->getCastKind(); |
| 5454 | Expr *ToOp = Importer.Import(E->getSubExpr()); |
| 5455 | if (!ToOp && E->getSubExpr()) |
| 5456 | return nullptr; |
| 5457 | CXXCastPath BasePath; |
| 5458 | if (ImportCastPath(E, BasePath)) |
| 5459 | return nullptr; |
| 5460 | TypeSourceInfo *ToWritten = Importer.Import(E->getTypeInfoAsWritten()); |
| 5461 | SourceLocation ToOperatorLoc = Importer.Import(E->getOperatorLoc()); |
| 5462 | SourceLocation ToRParenLoc = Importer.Import(E->getRParenLoc()); |
| 5463 | SourceRange ToAngleBrackets = Importer.Import(E->getAngleBrackets()); |
| 5464 | |
| 5465 | if (isa<CXXStaticCastExpr>(E)) { |
| 5466 | return CXXStaticCastExpr::Create( |
| 5467 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 5468 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 5469 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 5470 | return CXXDynamicCastExpr::Create( |
| 5471 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 5472 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 5473 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 5474 | return CXXReinterpretCastExpr::Create( |
| 5475 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 5476 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 5477 | } else { |
| 5478 | return nullptr; |
| 5479 | } |
| 5480 | } |
| 5481 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5482 | |
| 5483 | Expr *ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
| 5484 | SubstNonTypeTemplateParmExpr *E) { |
| 5485 | QualType T = Importer.Import(E->getType()); |
| 5486 | if (T.isNull()) |
| 5487 | return nullptr; |
| 5488 | |
| 5489 | NonTypeTemplateParmDecl *Param = cast_or_null<NonTypeTemplateParmDecl>( |
| 5490 | Importer.Import(E->getParameter())); |
| 5491 | if (!Param) |
| 5492 | return nullptr; |
| 5493 | |
| 5494 | Expr *Replacement = Importer.Import(E->getReplacement()); |
| 5495 | if (!Replacement) |
| 5496 | return nullptr; |
| 5497 | |
| 5498 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
| 5499 | T, E->getValueKind(), Importer.Import(E->getExprLoc()), Param, |
| 5500 | Replacement); |
| 5501 | } |
| 5502 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 5503 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 5504 | ASTContext &FromContext, FileManager &FromFileManager, |
| 5505 | bool MinimalImport) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 5506 | : ToContext(ToContext), FromContext(FromContext), |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 5507 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 5508 | Minimal(MinimalImport), LastDiagFromFrom(false) |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 5509 | { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5510 | ImportedDecls[FromContext.getTranslationUnitDecl()] |
| 5511 | = ToContext.getTranslationUnitDecl(); |
| 5512 | } |
| 5513 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 5514 | ASTImporter::~ASTImporter() { } |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 5515 | |
| 5516 | QualType ASTImporter::Import(QualType FromT) { |
| 5517 | if (FromT.isNull()) |
| 5518 | return QualType(); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5519 | |
| 5520 | const Type *fromTy = FromT.getTypePtr(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 5521 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 5522 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5523 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
| 5524 | = ImportedTypes.find(fromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 5525 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5526 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 5527 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 5528 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 5529 | ASTNodeImporter Importer(*this); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5530 | QualType ToT = Importer.Visit(fromTy); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 5531 | if (ToT.isNull()) |
| 5532 | return ToT; |
| 5533 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 5534 | // Record the imported type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5535 | ImportedTypes[fromTy] = ToT.getTypePtr(); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 5536 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5537 | return ToContext.getQualifiedType(ToT, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 5538 | } |
| 5539 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5540 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 5541 | if (!FromTSI) |
| 5542 | return FromTSI; |
| 5543 | |
| 5544 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 5545 | // 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] | 5546 | QualType T = Import(FromTSI->getType()); |
| 5547 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5548 | return nullptr; |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 5549 | |
| 5550 | return ToContext.getTrivialTypeSourceInfo(T, |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 5551 | Import(FromTSI->getTypeLoc().getLocStart())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5552 | } |
| 5553 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5554 | Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) { |
| 5555 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
| 5556 | if (Pos != ImportedDecls.end()) { |
| 5557 | Decl *ToD = Pos->second; |
| 5558 | ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD); |
| 5559 | return ToD; |
| 5560 | } else { |
| 5561 | return nullptr; |
| 5562 | } |
| 5563 | } |
| 5564 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5565 | Decl *ASTImporter::Import(Decl *FromD) { |
| 5566 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5567 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5568 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 5569 | ASTNodeImporter Importer(*this); |
| 5570 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5571 | // Check whether we've already imported this declaration. |
| 5572 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 5573 | if (Pos != ImportedDecls.end()) { |
| 5574 | Decl *ToD = Pos->second; |
| 5575 | Importer.ImportDefinitionIfNeeded(FromD, ToD); |
| 5576 | return ToD; |
| 5577 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5578 | |
| 5579 | // Import the type |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5580 | Decl *ToD = Importer.Visit(FromD); |
| 5581 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5582 | return nullptr; |
| 5583 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5584 | // Record the imported declaration. |
| 5585 | ImportedDecls[FromD] = ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 5586 | |
| 5587 | if (TagDecl *FromTag = dyn_cast<TagDecl>(FromD)) { |
| 5588 | // Keep track of anonymous tags that have an associated typedef. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 5589 | if (FromTag->getTypedefNameForAnonDecl()) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 5590 | AnonTagsWithPendingTypedefs.push_back(FromTag); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 5591 | } else if (TypedefNameDecl *FromTypedef = dyn_cast<TypedefNameDecl>(FromD)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 5592 | // When we've finished transforming a typedef, see whether it was the |
| 5593 | // typedef for an anonymous tag. |
Craig Topper | 2341c0d | 2013-07-04 03:08:24 +0000 | [diff] [blame] | 5594 | for (SmallVectorImpl<TagDecl *>::iterator |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 5595 | FromTag = AnonTagsWithPendingTypedefs.begin(), |
| 5596 | FromTagEnd = AnonTagsWithPendingTypedefs.end(); |
| 5597 | FromTag != FromTagEnd; ++FromTag) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 5598 | if ((*FromTag)->getTypedefNameForAnonDecl() == FromTypedef) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 5599 | if (TagDecl *ToTag = cast_or_null<TagDecl>(Import(*FromTag))) { |
| 5600 | // We found the typedef for an anonymous tag; link them. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 5601 | ToTag->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(ToD)); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 5602 | AnonTagsWithPendingTypedefs.erase(FromTag); |
| 5603 | break; |
| 5604 | } |
| 5605 | } |
| 5606 | } |
| 5607 | } |
| 5608 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5609 | return ToD; |
| 5610 | } |
| 5611 | |
| 5612 | DeclContext *ASTImporter::ImportContext(DeclContext *FromDC) { |
| 5613 | if (!FromDC) |
| 5614 | return FromDC; |
| 5615 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 5616 | DeclContext *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 5617 | if (!ToDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5618 | return nullptr; |
| 5619 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 5620 | // When we're using a record/enum/Objective-C class/protocol as a context, we |
| 5621 | // need it to have a definition. |
| 5622 | if (RecordDecl *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
Douglas Gregor | 63db971 | 2012-01-25 01:13:20 +0000 | [diff] [blame] | 5623 | RecordDecl *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 5624 | if (ToRecord->isCompleteDefinition()) { |
| 5625 | // Do nothing. |
| 5626 | } else if (FromRecord->isCompleteDefinition()) { |
| 5627 | ASTNodeImporter(*this).ImportDefinition(FromRecord, ToRecord, |
| 5628 | ASTNodeImporter::IDK_Basic); |
| 5629 | } else { |
| 5630 | CompleteDecl(ToRecord); |
| 5631 | } |
| 5632 | } else if (EnumDecl *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 5633 | EnumDecl *FromEnum = cast<EnumDecl>(FromDC); |
| 5634 | if (ToEnum->isCompleteDefinition()) { |
| 5635 | // Do nothing. |
| 5636 | } else if (FromEnum->isCompleteDefinition()) { |
| 5637 | ASTNodeImporter(*this).ImportDefinition(FromEnum, ToEnum, |
| 5638 | ASTNodeImporter::IDK_Basic); |
| 5639 | } else { |
| 5640 | CompleteDecl(ToEnum); |
| 5641 | } |
| 5642 | } else if (ObjCInterfaceDecl *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 5643 | ObjCInterfaceDecl *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
| 5644 | if (ToClass->getDefinition()) { |
| 5645 | // Do nothing. |
| 5646 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
| 5647 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToClass, |
| 5648 | ASTNodeImporter::IDK_Basic); |
| 5649 | } else { |
| 5650 | CompleteDecl(ToClass); |
| 5651 | } |
| 5652 | } else if (ObjCProtocolDecl *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 5653 | ObjCProtocolDecl *FromProto = cast<ObjCProtocolDecl>(FromDC); |
| 5654 | if (ToProto->getDefinition()) { |
| 5655 | // Do nothing. |
| 5656 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
| 5657 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToProto, |
| 5658 | ASTNodeImporter::IDK_Basic); |
| 5659 | } else { |
| 5660 | CompleteDecl(ToProto); |
| 5661 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 5662 | } |
| 5663 | |
| 5664 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5665 | } |
| 5666 | |
| 5667 | Expr *ASTImporter::Import(Expr *FromE) { |
| 5668 | if (!FromE) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5669 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5670 | |
| 5671 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); |
| 5672 | } |
| 5673 | |
| 5674 | Stmt *ASTImporter::Import(Stmt *FromS) { |
| 5675 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5676 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5677 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5678 | // Check whether we've already imported this declaration. |
| 5679 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 5680 | if (Pos != ImportedStmts.end()) |
| 5681 | return Pos->second; |
| 5682 | |
| 5683 | // Import the type |
| 5684 | ASTNodeImporter Importer(*this); |
| 5685 | Stmt *ToS = Importer.Visit(FromS); |
| 5686 | if (!ToS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5687 | return nullptr; |
| 5688 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5689 | // Record the imported declaration. |
| 5690 | ImportedStmts[FromS] = ToS; |
| 5691 | return ToS; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5692 | } |
| 5693 | |
| 5694 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| 5695 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5696 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5697 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 5698 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); |
| 5699 | |
| 5700 | switch (FromNNS->getKind()) { |
| 5701 | case NestedNameSpecifier::Identifier: |
| 5702 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { |
| 5703 | return NestedNameSpecifier::Create(ToContext, prefix, II); |
| 5704 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5705 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 5706 | |
| 5707 | case NestedNameSpecifier::Namespace: |
| 5708 | if (NamespaceDecl *NS = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5709 | cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 5710 | return NestedNameSpecifier::Create(ToContext, prefix, NS); |
| 5711 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5712 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 5713 | |
| 5714 | case NestedNameSpecifier::NamespaceAlias: |
| 5715 | if (NamespaceAliasDecl *NSAD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5716 | cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 5717 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); |
| 5718 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5719 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 5720 | |
| 5721 | case NestedNameSpecifier::Global: |
| 5722 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 5723 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5724 | case NestedNameSpecifier::Super: |
| 5725 | if (CXXRecordDecl *RD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5726 | cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) { |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5727 | return NestedNameSpecifier::SuperSpecifier(ToContext, RD); |
| 5728 | } |
| 5729 | return nullptr; |
| 5730 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 5731 | case NestedNameSpecifier::TypeSpec: |
| 5732 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 5733 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); |
| 5734 | if (!T.isNull()) { |
| 5735 | bool bTemplate = FromNNS->getKind() == |
| 5736 | NestedNameSpecifier::TypeSpecWithTemplate; |
| 5737 | return NestedNameSpecifier::Create(ToContext, prefix, |
| 5738 | bTemplate, T.getTypePtr()); |
| 5739 | } |
| 5740 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5741 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 5742 | } |
| 5743 | |
| 5744 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5745 | } |
| 5746 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 5747 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5748 | // Copied from NestedNameSpecifier mostly. |
| 5749 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 5750 | NestedNameSpecifierLoc NNS = FromNNS; |
| 5751 | |
| 5752 | // Push each of the nested-name-specifiers's onto a stack for |
| 5753 | // serialization in reverse order. |
| 5754 | while (NNS) { |
| 5755 | NestedNames.push_back(NNS); |
| 5756 | NNS = NNS.getPrefix(); |
| 5757 | } |
| 5758 | |
| 5759 | NestedNameSpecifierLocBuilder Builder; |
| 5760 | |
| 5761 | while (!NestedNames.empty()) { |
| 5762 | NNS = NestedNames.pop_back_val(); |
| 5763 | NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier()); |
| 5764 | if (!Spec) |
| 5765 | return NestedNameSpecifierLoc(); |
| 5766 | |
| 5767 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| 5768 | switch (Kind) { |
| 5769 | case NestedNameSpecifier::Identifier: |
| 5770 | Builder.Extend(getToContext(), |
| 5771 | Spec->getAsIdentifier(), |
| 5772 | Import(NNS.getLocalBeginLoc()), |
| 5773 | Import(NNS.getLocalEndLoc())); |
| 5774 | break; |
| 5775 | |
| 5776 | case NestedNameSpecifier::Namespace: |
| 5777 | Builder.Extend(getToContext(), |
| 5778 | Spec->getAsNamespace(), |
| 5779 | Import(NNS.getLocalBeginLoc()), |
| 5780 | Import(NNS.getLocalEndLoc())); |
| 5781 | break; |
| 5782 | |
| 5783 | case NestedNameSpecifier::NamespaceAlias: |
| 5784 | Builder.Extend(getToContext(), |
| 5785 | Spec->getAsNamespaceAlias(), |
| 5786 | Import(NNS.getLocalBeginLoc()), |
| 5787 | Import(NNS.getLocalEndLoc())); |
| 5788 | break; |
| 5789 | |
| 5790 | case NestedNameSpecifier::TypeSpec: |
| 5791 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 5792 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| 5793 | QualType(Spec->getAsType(), 0)); |
| 5794 | Builder.Extend(getToContext(), |
| 5795 | Import(NNS.getLocalBeginLoc()), |
| 5796 | TSI->getTypeLoc(), |
| 5797 | Import(NNS.getLocalEndLoc())); |
| 5798 | break; |
| 5799 | } |
| 5800 | |
| 5801 | case NestedNameSpecifier::Global: |
| 5802 | Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc())); |
| 5803 | break; |
| 5804 | |
| 5805 | case NestedNameSpecifier::Super: { |
| 5806 | SourceRange ToRange = Import(NNS.getSourceRange()); |
| 5807 | Builder.MakeSuper(getToContext(), |
| 5808 | Spec->getAsRecordDecl(), |
| 5809 | ToRange.getBegin(), |
| 5810 | ToRange.getEnd()); |
| 5811 | } |
| 5812 | } |
| 5813 | } |
| 5814 | |
| 5815 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 5816 | } |
| 5817 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5818 | TemplateName ASTImporter::Import(TemplateName From) { |
| 5819 | switch (From.getKind()) { |
| 5820 | case TemplateName::Template: |
| 5821 | if (TemplateDecl *ToTemplate |
| 5822 | = cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
| 5823 | return TemplateName(ToTemplate); |
| 5824 | |
| 5825 | return TemplateName(); |
| 5826 | |
| 5827 | case TemplateName::OverloadedTemplate: { |
| 5828 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 5829 | UnresolvedSet<2> ToTemplates; |
| 5830 | for (OverloadedTemplateStorage::iterator I = FromStorage->begin(), |
| 5831 | E = FromStorage->end(); |
| 5832 | I != E; ++I) { |
| 5833 | if (NamedDecl *To = cast_or_null<NamedDecl>(Import(*I))) |
| 5834 | ToTemplates.addDecl(To); |
| 5835 | else |
| 5836 | return TemplateName(); |
| 5837 | } |
| 5838 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
| 5839 | ToTemplates.end()); |
| 5840 | } |
| 5841 | |
| 5842 | case TemplateName::QualifiedTemplate: { |
| 5843 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| 5844 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); |
| 5845 | if (!Qualifier) |
| 5846 | return TemplateName(); |
| 5847 | |
| 5848 | if (TemplateDecl *ToTemplate |
| 5849 | = cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
| 5850 | return ToContext.getQualifiedTemplateName(Qualifier, |
| 5851 | QTN->hasTemplateKeyword(), |
| 5852 | ToTemplate); |
| 5853 | |
| 5854 | return TemplateName(); |
| 5855 | } |
| 5856 | |
| 5857 | case TemplateName::DependentTemplate: { |
| 5858 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| 5859 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); |
| 5860 | if (!Qualifier) |
| 5861 | return TemplateName(); |
| 5862 | |
| 5863 | if (DTN->isIdentifier()) { |
| 5864 | return ToContext.getDependentTemplateName(Qualifier, |
| 5865 | Import(DTN->getIdentifier())); |
| 5866 | } |
| 5867 | |
| 5868 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); |
| 5869 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5870 | |
| 5871 | case TemplateName::SubstTemplateTemplateParm: { |
| 5872 | SubstTemplateTemplateParmStorage *subst |
| 5873 | = From.getAsSubstTemplateTemplateParm(); |
| 5874 | TemplateTemplateParmDecl *param |
| 5875 | = cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); |
| 5876 | if (!param) |
| 5877 | return TemplateName(); |
| 5878 | |
| 5879 | TemplateName replacement = Import(subst->getReplacement()); |
| 5880 | if (replacement.isNull()) return TemplateName(); |
| 5881 | |
| 5882 | return ToContext.getSubstTemplateTemplateParm(param, replacement); |
| 5883 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5884 | |
| 5885 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5886 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 5887 | = From.getAsSubstTemplateTemplateParmPack(); |
| 5888 | TemplateTemplateParmDecl *Param |
| 5889 | = cast_or_null<TemplateTemplateParmDecl>( |
| 5890 | Import(SubstPack->getParameterPack())); |
| 5891 | if (!Param) |
| 5892 | return TemplateName(); |
| 5893 | |
| 5894 | ASTNodeImporter Importer(*this); |
| 5895 | TemplateArgument ArgPack |
| 5896 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 5897 | if (ArgPack.isNull()) |
| 5898 | return TemplateName(); |
| 5899 | |
| 5900 | return ToContext.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 5901 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5902 | } |
| 5903 | |
| 5904 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5905 | } |
| 5906 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5907 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { |
| 5908 | if (FromLoc.isInvalid()) |
| 5909 | return SourceLocation(); |
| 5910 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 5911 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 5912 | |
Sean Callanan | 24c5fe6 | 2016-11-07 20:42:25 +0000 | [diff] [blame] | 5913 | // For now, map everything down to its file location, so that we |
Chandler Carruth | 2536641 | 2011-07-15 00:04:35 +0000 | [diff] [blame] | 5914 | // don't have to import macro expansions. |
| 5915 | // FIXME: Import macro expansions! |
Sean Callanan | 24c5fe6 | 2016-11-07 20:42:25 +0000 | [diff] [blame] | 5916 | FromLoc = FromSM.getFileLoc(FromLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 5917 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
| 5918 | SourceManager &ToSM = ToContext.getSourceManager(); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 5919 | FileID ToFileID = Import(Decomposed.first); |
| 5920 | if (ToFileID.isInvalid()) |
| 5921 | return SourceLocation(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5922 | SourceLocation ret = ToSM.getLocForStartOfFile(ToFileID) |
| 5923 | .getLocWithOffset(Decomposed.second); |
| 5924 | return ret; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 5925 | } |
| 5926 | |
| 5927 | SourceRange ASTImporter::Import(SourceRange FromRange) { |
| 5928 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); |
| 5929 | } |
| 5930 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 5931 | FileID ASTImporter::Import(FileID FromID) { |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 5932 | llvm::DenseMap<FileID, FileID>::iterator Pos |
| 5933 | = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 5934 | if (Pos != ImportedFileIDs.end()) |
| 5935 | return Pos->second; |
| 5936 | |
| 5937 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 5938 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 5939 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Chandler Carruth | 2536641 | 2011-07-15 00:04:35 +0000 | [diff] [blame] | 5940 | assert(FromSLoc.isFile() && "Cannot handle macro expansions yet"); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 5941 | |
| 5942 | // Include location of this file. |
| 5943 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| 5944 | |
| 5945 | // Map the FileID for to the "to" source manager. |
| 5946 | FileID ToID; |
| 5947 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
Sean Callanan | 25d34af | 2015-04-30 00:44:21 +0000 | [diff] [blame] | 5948 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 5949 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 5950 | // disk again |
| 5951 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 5952 | // than mmap the files several times. |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 5953 | const FileEntry *Entry = ToFileManager.getFile(Cache->OrigEntry->getName()); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 5954 | if (!Entry) |
| 5955 | return FileID(); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 5956 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, |
| 5957 | FromSLoc.getFile().getFileCharacteristic()); |
| 5958 | } else { |
| 5959 | // FIXME: We want to re-use the existing MemoryBuffer! |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 5960 | const llvm::MemoryBuffer * |
| 5961 | FromBuf = Cache->getBuffer(FromContext.getDiagnostics(), FromSM); |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 5962 | std::unique_ptr<llvm::MemoryBuffer> ToBuf |
Chris Lattner | 58c7934 | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 5963 | = llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 5964 | FromBuf->getBufferIdentifier()); |
David Blaikie | 50a5f97 | 2014-08-29 07:59:55 +0000 | [diff] [blame] | 5965 | ToID = ToSM.createFileID(std::move(ToBuf), |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 5966 | FromSLoc.getFile().getFileCharacteristic()); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 5967 | } |
| 5968 | |
| 5969 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 5970 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 5971 | return ToID; |
| 5972 | } |
| 5973 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 5974 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { |
| 5975 | Expr *ToExpr = Import(From->getInit()); |
| 5976 | if (!ToExpr && From->getInit()) |
| 5977 | return nullptr; |
| 5978 | |
| 5979 | if (From->isBaseInitializer()) { |
| 5980 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 5981 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 5982 | return nullptr; |
| 5983 | |
| 5984 | return new (ToContext) CXXCtorInitializer( |
| 5985 | ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()), |
| 5986 | ToExpr, Import(From->getRParenLoc()), |
| 5987 | From->isPackExpansion() ? Import(From->getEllipsisLoc()) |
| 5988 | : SourceLocation()); |
| 5989 | } else if (From->isMemberInitializer()) { |
| 5990 | FieldDecl *ToField = |
| 5991 | llvm::cast_or_null<FieldDecl>(Import(From->getMember())); |
| 5992 | if (!ToField && From->getMember()) |
| 5993 | return nullptr; |
| 5994 | |
| 5995 | return new (ToContext) CXXCtorInitializer( |
| 5996 | ToContext, ToField, Import(From->getMemberLocation()), |
| 5997 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 5998 | } else if (From->isIndirectMemberInitializer()) { |
| 5999 | IndirectFieldDecl *ToIField = llvm::cast_or_null<IndirectFieldDecl>( |
| 6000 | Import(From->getIndirectMember())); |
| 6001 | if (!ToIField && From->getIndirectMember()) |
| 6002 | return nullptr; |
| 6003 | |
| 6004 | return new (ToContext) CXXCtorInitializer( |
| 6005 | ToContext, ToIField, Import(From->getMemberLocation()), |
| 6006 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 6007 | } else if (From->isDelegatingInitializer()) { |
| 6008 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 6009 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 6010 | return nullptr; |
| 6011 | |
| 6012 | return new (ToContext) |
| 6013 | CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()), |
| 6014 | ToExpr, Import(From->getRParenLoc())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6015 | } else { |
| 6016 | return nullptr; |
| 6017 | } |
| 6018 | } |
| 6019 | |
| 6020 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6021 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| 6022 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 6023 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 6024 | return Pos->second; |
| 6025 | |
| 6026 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| 6027 | Import(BaseSpec->getSourceRange()), |
| 6028 | BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 6029 | BaseSpec->getAccessSpecifierAsWritten(), |
| 6030 | Import(BaseSpec->getTypeSourceInfo()), |
| 6031 | Import(BaseSpec->getEllipsisLoc())); |
| 6032 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 6033 | return Imported; |
| 6034 | } |
| 6035 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 6036 | void ASTImporter::ImportDefinition(Decl *From) { |
| 6037 | Decl *To = Import(From); |
| 6038 | if (!To) |
| 6039 | return; |
| 6040 | |
| 6041 | if (DeclContext *FromDC = cast<DeclContext>(From)) { |
| 6042 | ASTNodeImporter Importer(*this); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 6043 | |
| 6044 | if (RecordDecl *ToRecord = dyn_cast<RecordDecl>(To)) { |
| 6045 | if (!ToRecord->getDefinition()) { |
| 6046 | Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 6047 | ASTNodeImporter::IDK_Everything); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 6048 | return; |
| 6049 | } |
| 6050 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6051 | |
| 6052 | if (EnumDecl *ToEnum = dyn_cast<EnumDecl>(To)) { |
| 6053 | if (!ToEnum->getDefinition()) { |
| 6054 | Importer.ImportDefinition(cast<EnumDecl>(FromDC), ToEnum, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6055 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6056 | return; |
| 6057 | } |
| 6058 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 6059 | |
| 6060 | if (ObjCInterfaceDecl *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
| 6061 | if (!ToIFace->getDefinition()) { |
| 6062 | Importer.ImportDefinition(cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6063 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 6064 | return; |
| 6065 | } |
| 6066 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6067 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 6068 | if (ObjCProtocolDecl *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
| 6069 | if (!ToProto->getDefinition()) { |
| 6070 | Importer.ImportDefinition(cast<ObjCProtocolDecl>(FromDC), ToProto, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6071 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 6072 | return; |
| 6073 | } |
| 6074 | } |
| 6075 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 6076 | Importer.ImportDeclContext(FromDC, true); |
| 6077 | } |
| 6078 | } |
| 6079 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6080 | DeclarationName ASTImporter::Import(DeclarationName FromName) { |
| 6081 | if (!FromName) |
| 6082 | return DeclarationName(); |
| 6083 | |
| 6084 | switch (FromName.getNameKind()) { |
| 6085 | case DeclarationName::Identifier: |
| 6086 | return Import(FromName.getAsIdentifierInfo()); |
| 6087 | |
| 6088 | case DeclarationName::ObjCZeroArgSelector: |
| 6089 | case DeclarationName::ObjCOneArgSelector: |
| 6090 | case DeclarationName::ObjCMultiArgSelector: |
| 6091 | return Import(FromName.getObjCSelector()); |
| 6092 | |
| 6093 | case DeclarationName::CXXConstructorName: { |
| 6094 | QualType T = Import(FromName.getCXXNameType()); |
| 6095 | if (T.isNull()) |
| 6096 | return DeclarationName(); |
| 6097 | |
| 6098 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 6099 | ToContext.getCanonicalType(T)); |
| 6100 | } |
| 6101 | |
| 6102 | case DeclarationName::CXXDestructorName: { |
| 6103 | QualType T = Import(FromName.getCXXNameType()); |
| 6104 | if (T.isNull()) |
| 6105 | return DeclarationName(); |
| 6106 | |
| 6107 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 6108 | ToContext.getCanonicalType(T)); |
| 6109 | } |
| 6110 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 6111 | case DeclarationName::CXXDeductionGuideName: { |
| 6112 | TemplateDecl *Template = cast_or_null<TemplateDecl>( |
| 6113 | Import(FromName.getCXXDeductionGuideTemplate())); |
| 6114 | if (!Template) |
| 6115 | return DeclarationName(); |
| 6116 | return ToContext.DeclarationNames.getCXXDeductionGuideName(Template); |
| 6117 | } |
| 6118 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6119 | case DeclarationName::CXXConversionFunctionName: { |
| 6120 | QualType T = Import(FromName.getCXXNameType()); |
| 6121 | if (T.isNull()) |
| 6122 | return DeclarationName(); |
| 6123 | |
| 6124 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 6125 | ToContext.getCanonicalType(T)); |
| 6126 | } |
| 6127 | |
| 6128 | case DeclarationName::CXXOperatorName: |
| 6129 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 6130 | FromName.getCXXOverloadedOperator()); |
| 6131 | |
| 6132 | case DeclarationName::CXXLiteralOperatorName: |
| 6133 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| 6134 | Import(FromName.getCXXLiteralIdentifier())); |
| 6135 | |
| 6136 | case DeclarationName::CXXUsingDirective: |
| 6137 | // FIXME: STATICS! |
| 6138 | return DeclarationName::getUsingDirectiveName(); |
| 6139 | } |
| 6140 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 6141 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6142 | } |
| 6143 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6144 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6145 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6146 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6147 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 6148 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 6149 | |
| 6150 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 6151 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 6152 | |
| 6153 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6154 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 6155 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 6156 | Selector ASTImporter::Import(Selector FromSel) { |
| 6157 | if (FromSel.isNull()) |
| 6158 | return Selector(); |
| 6159 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6160 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 6161 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 6162 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 6163 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 6164 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 6165 | } |
| 6166 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 6167 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 6168 | DeclContext *DC, |
| 6169 | unsigned IDNS, |
| 6170 | NamedDecl **Decls, |
| 6171 | unsigned NumDecls) { |
| 6172 | return Name; |
| 6173 | } |
| 6174 | |
| 6175 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 6176 | if (LastDiagFromFrom) |
| 6177 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 6178 | FromContext.getDiagnostics()); |
| 6179 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6180 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 6181 | } |
| 6182 | |
| 6183 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 6184 | if (!LastDiagFromFrom) |
| 6185 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 6186 | ToContext.getDiagnostics()); |
| 6187 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6188 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 6189 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 6190 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6191 | void ASTImporter::CompleteDecl (Decl *D) { |
| 6192 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
| 6193 | if (!ID->getDefinition()) |
| 6194 | ID->startDefinition(); |
| 6195 | } |
| 6196 | else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
| 6197 | if (!PD->getDefinition()) |
| 6198 | PD->startDefinition(); |
| 6199 | } |
| 6200 | else if (TagDecl *TD = dyn_cast<TagDecl>(D)) { |
| 6201 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 6202 | TD->startDefinition(); |
| 6203 | TD->setCompleteDefinition(true); |
| 6204 | } |
| 6205 | } |
| 6206 | else { |
| 6207 | assert (0 && "CompleteDecl called on a Decl that can't be completed"); |
| 6208 | } |
| 6209 | } |
| 6210 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 6211 | Decl *ASTImporter::Imported(Decl *From, Decl *To) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6212 | if (From->hasAttrs()) { |
| 6213 | for (Attr *FromAttr : From->getAttrs()) |
| 6214 | To->addAttr(FromAttr->clone(To->getASTContext())); |
| 6215 | } |
| 6216 | if (From->isUsed()) { |
| 6217 | To->setIsUsed(); |
| 6218 | } |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6219 | if (From->isImplicit()) { |
| 6220 | To->setImplicit(); |
| 6221 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 6222 | ImportedDecls[From] = To; |
| 6223 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 6224 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6225 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 6226 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 6227 | bool Complain) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6228 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6229 | = ImportedTypes.find(From.getTypePtr()); |
| 6230 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) |
| 6231 | return true; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 6232 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 6233 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
| 6234 | false, Complain); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 6235 | return Ctx.IsStructurallyEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 6236 | } |