Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1 | //===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===// |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 14 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTImporter.h" |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTDiagnostic.h" |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTStructuralEquivalence.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 19 | #include "clang/AST/Attr.h" |
| 20 | #include "clang/AST/Decl.h" |
| 21 | #include "clang/AST/DeclAccessPair.h" |
| 22 | #include "clang/AST/DeclBase.h" |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclCXX.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclFriend.h" |
| 25 | #include "clang/AST/DeclGroup.h" |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 26 | #include "clang/AST/DeclObjC.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 27 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 28 | #include "clang/AST/DeclVisitor.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 29 | #include "clang/AST/DeclarationName.h" |
| 30 | #include "clang/AST/Expr.h" |
| 31 | #include "clang/AST/ExprCXX.h" |
| 32 | #include "clang/AST/ExprObjC.h" |
| 33 | #include "clang/AST/ExternalASTSource.h" |
| 34 | #include "clang/AST/LambdaCapture.h" |
| 35 | #include "clang/AST/NestedNameSpecifier.h" |
| 36 | #include "clang/AST/OperationKinds.h" |
| 37 | #include "clang/AST/Stmt.h" |
| 38 | #include "clang/AST/StmtCXX.h" |
| 39 | #include "clang/AST/StmtObjC.h" |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 40 | #include "clang/AST/StmtVisitor.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 41 | #include "clang/AST/TemplateBase.h" |
| 42 | #include "clang/AST/TemplateName.h" |
| 43 | #include "clang/AST/Type.h" |
| 44 | #include "clang/AST/TypeLoc.h" |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 45 | #include "clang/AST/TypeVisitor.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 46 | #include "clang/AST/UnresolvedSet.h" |
| 47 | #include "clang/Basic/ExceptionSpecificationType.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 48 | #include "clang/Basic/FileManager.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 49 | #include "clang/Basic/IdentifierTable.h" |
| 50 | #include "clang/Basic/LLVM.h" |
| 51 | #include "clang/Basic/LangOptions.h" |
| 52 | #include "clang/Basic/SourceLocation.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 53 | #include "clang/Basic/SourceManager.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 54 | #include "clang/Basic/Specifiers.h" |
| 55 | #include "llvm/ADT/APSInt.h" |
| 56 | #include "llvm/ADT/ArrayRef.h" |
| 57 | #include "llvm/ADT/DenseMap.h" |
| 58 | #include "llvm/ADT/None.h" |
| 59 | #include "llvm/ADT/Optional.h" |
| 60 | #include "llvm/ADT/STLExtras.h" |
| 61 | #include "llvm/ADT/SmallVector.h" |
| 62 | #include "llvm/Support/Casting.h" |
| 63 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 64 | #include "llvm/Support/MemoryBuffer.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 65 | #include <algorithm> |
| 66 | #include <cassert> |
| 67 | #include <cstddef> |
| 68 | #include <memory> |
| 69 | #include <type_traits> |
| 70 | #include <utility> |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 71 | |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 72 | namespace clang { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 73 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 74 | template <class T> |
| 75 | SmallVector<Decl*, 2> |
| 76 | getCanonicalForwardRedeclChain(Redeclarable<T>* D) { |
| 77 | SmallVector<Decl*, 2> Redecls; |
| 78 | for (auto *R : D->getFirstDecl()->redecls()) { |
| 79 | if (R != D->getFirstDecl()) |
| 80 | Redecls.push_back(R); |
| 81 | } |
| 82 | Redecls.push_back(D->getFirstDecl()); |
| 83 | std::reverse(Redecls.begin(), Redecls.end()); |
| 84 | return Redecls; |
| 85 | } |
| 86 | |
| 87 | SmallVector<Decl*, 2> getCanonicalForwardRedeclChain(Decl* D) { |
| 88 | // Currently only FunctionDecl is supported |
| 89 | auto FD = cast<FunctionDecl>(D); |
| 90 | return getCanonicalForwardRedeclChain<FunctionDecl>(FD); |
| 91 | } |
| 92 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 93 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, QualType>, |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 94 | public DeclVisitor<ASTNodeImporter, Decl *>, |
| 95 | public StmtVisitor<ASTNodeImporter, Stmt *> { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 96 | ASTImporter &Importer; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 97 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 98 | public: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 99 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} |
Gabor Marton | 344b099 | 2018-05-16 11:48:11 +0000 | [diff] [blame] | 100 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 101 | using TypeVisitor<ASTNodeImporter, QualType>::Visit; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 102 | using DeclVisitor<ASTNodeImporter, Decl *>::Visit; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 103 | using StmtVisitor<ASTNodeImporter, Stmt *>::Visit; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 104 | |
| 105 | // Importing types |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 106 | QualType VisitType(const Type *T); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 107 | QualType VisitAtomicType(const AtomicType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 108 | QualType VisitBuiltinType(const BuiltinType *T); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 109 | QualType VisitDecayedType(const DecayedType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 110 | QualType VisitComplexType(const ComplexType *T); |
| 111 | QualType VisitPointerType(const PointerType *T); |
| 112 | QualType VisitBlockPointerType(const BlockPointerType *T); |
| 113 | QualType VisitLValueReferenceType(const LValueReferenceType *T); |
| 114 | QualType VisitRValueReferenceType(const RValueReferenceType *T); |
| 115 | QualType VisitMemberPointerType(const MemberPointerType *T); |
| 116 | QualType VisitConstantArrayType(const ConstantArrayType *T); |
| 117 | QualType VisitIncompleteArrayType(const IncompleteArrayType *T); |
| 118 | QualType VisitVariableArrayType(const VariableArrayType *T); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 119 | QualType VisitDependentSizedArrayType(const DependentSizedArrayType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 120 | // FIXME: DependentSizedExtVectorType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 121 | QualType VisitVectorType(const VectorType *T); |
| 122 | QualType VisitExtVectorType(const ExtVectorType *T); |
| 123 | QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T); |
| 124 | QualType VisitFunctionProtoType(const FunctionProtoType *T); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 125 | QualType VisitUnresolvedUsingType(const UnresolvedUsingType *T); |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 126 | QualType VisitParenType(const ParenType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 127 | QualType VisitTypedefType(const TypedefType *T); |
| 128 | QualType VisitTypeOfExprType(const TypeOfExprType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 129 | // FIXME: DependentTypeOfExprType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 130 | QualType VisitTypeOfType(const TypeOfType *T); |
| 131 | QualType VisitDecltypeType(const DecltypeType *T); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 132 | QualType VisitUnaryTransformType(const UnaryTransformType *T); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 133 | QualType VisitAutoType(const AutoType *T); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 134 | QualType VisitInjectedClassNameType(const InjectedClassNameType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 135 | // FIXME: DependentDecltypeType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 136 | QualType VisitRecordType(const RecordType *T); |
| 137 | QualType VisitEnumType(const EnumType *T); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 138 | QualType VisitAttributedType(const AttributedType *T); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 139 | QualType VisitTemplateTypeParmType(const TemplateTypeParmType *T); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 140 | QualType VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 141 | QualType VisitTemplateSpecializationType(const TemplateSpecializationType *T); |
| 142 | QualType VisitElaboratedType(const ElaboratedType *T); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 143 | QualType VisitDependentNameType(const DependentNameType *T); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 144 | QualType VisitPackExpansionType(const PackExpansionType *T); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 145 | QualType VisitDependentTemplateSpecializationType( |
| 146 | const DependentTemplateSpecializationType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 147 | QualType VisitObjCInterfaceType(const ObjCInterfaceType *T); |
| 148 | QualType VisitObjCObjectType(const ObjCObjectType *T); |
| 149 | QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); |
Rafael Stahl | df55620 | 2018-05-29 08:12:15 +0000 | [diff] [blame] | 150 | |
| 151 | // Importing declarations |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 152 | bool ImportDeclParts(NamedDecl *D, DeclContext *&DC, |
| 153 | DeclContext *&LexicalDC, DeclarationName &Name, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 154 | NamedDecl *&ToD, SourceLocation &Loc); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 155 | void ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 156 | void ImportDeclarationNameLoc(const DeclarationNameInfo &From, |
| 157 | DeclarationNameInfo& To); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 158 | void ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 159 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 160 | bool ImportCastPath(CastExpr *E, CXXCastPath &Path); |
| 161 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 162 | using Designator = DesignatedInitExpr::Designator; |
| 163 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 164 | Designator ImportDesignator(const Designator &D); |
| 165 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 166 | Optional<LambdaCapture> ImportLambdaCapture(const LambdaCapture &From); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 167 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 168 | /// What we should import from the definition. |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 169 | enum ImportDefinitionKind { |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 170 | /// Import the default subset of the definition, which might be |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 171 | /// nothing (if minimal import is set) or might be everything (if minimal |
| 172 | /// import is not set). |
| 173 | IDK_Default, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 174 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 175 | /// Import everything. |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 176 | IDK_Everything, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 177 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 178 | /// Import only the bare bones needed to establish a valid |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 179 | /// DeclContext. |
| 180 | IDK_Basic |
| 181 | }; |
| 182 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 183 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { |
| 184 | return IDK == IDK_Everything || |
| 185 | (IDK == IDK_Default && !Importer.isMinimalImport()); |
| 186 | } |
| 187 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 188 | bool ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 189 | ImportDefinitionKind Kind = IDK_Default); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 190 | bool ImportDefinition(VarDecl *From, VarDecl *To, |
| 191 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 192 | bool ImportDefinition(EnumDecl *From, EnumDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 193 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 194 | bool ImportDefinition(ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 195 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 196 | bool ImportDefinition(ObjCProtocolDecl *From, ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 197 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 198 | TemplateParameterList *ImportTemplateParameterList( |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 199 | TemplateParameterList *Params); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 200 | TemplateArgument ImportTemplateArgument(const TemplateArgument &From); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 201 | Optional<TemplateArgumentLoc> ImportTemplateArgumentLoc( |
| 202 | const TemplateArgumentLoc &TALoc); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 203 | bool ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 204 | unsigned NumFromArgs, |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 205 | SmallVectorImpl<TemplateArgument> &ToArgs); |
| 206 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 207 | template <typename InContainerTy> |
| 208 | bool ImportTemplateArgumentListInfo(const InContainerTy &Container, |
| 209 | TemplateArgumentListInfo &ToTAInfo); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 210 | |
| 211 | template<typename InContainerTy> |
| 212 | bool ImportTemplateArgumentListInfo(SourceLocation FromLAngleLoc, |
| 213 | SourceLocation FromRAngleLoc, |
| 214 | const InContainerTy &Container, |
| 215 | TemplateArgumentListInfo &Result); |
| 216 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 217 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; |
| 218 | using OptionalTemplateArgsTy = Optional<TemplateArgsTy>; |
| 219 | std::tuple<FunctionTemplateDecl *, OptionalTemplateArgsTy> |
| 220 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 221 | FunctionDecl *FromFD); |
| 222 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 223 | bool ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); |
| 224 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 225 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, |
| 226 | bool Complain = true); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 227 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 228 | bool Complain = true); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 229 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 230 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 231 | bool IsStructuralMatch(FunctionTemplateDecl *From, |
| 232 | FunctionTemplateDecl *To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 233 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 234 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 235 | Decl *VisitDecl(Decl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 236 | Decl *VisitEmptyDecl(EmptyDecl *D); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 237 | Decl *VisitAccessSpecDecl(AccessSpecDecl *D); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 238 | Decl *VisitStaticAssertDecl(StaticAssertDecl *D); |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 239 | Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 240 | Decl *VisitNamespaceDecl(NamespaceDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 241 | Decl *VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 242 | Decl *VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 243 | Decl *VisitTypedefDecl(TypedefDecl *D); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 244 | Decl *VisitTypeAliasDecl(TypeAliasDecl *D); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 245 | Decl *VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 246 | Decl *VisitLabelDecl(LabelDecl *D); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 247 | Decl *VisitEnumDecl(EnumDecl *D); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 248 | Decl *VisitRecordDecl(RecordDecl *D); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 249 | Decl *VisitEnumConstantDecl(EnumConstantDecl *D); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 250 | Decl *VisitFunctionDecl(FunctionDecl *D); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 251 | Decl *VisitCXXMethodDecl(CXXMethodDecl *D); |
| 252 | Decl *VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 253 | Decl *VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 254 | Decl *VisitCXXConversionDecl(CXXConversionDecl *D); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 255 | Decl *VisitFieldDecl(FieldDecl *D); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 256 | Decl *VisitIndirectFieldDecl(IndirectFieldDecl *D); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 257 | Decl *VisitFriendDecl(FriendDecl *D); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 258 | Decl *VisitObjCIvarDecl(ObjCIvarDecl *D); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 259 | Decl *VisitVarDecl(VarDecl *D); |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 260 | Decl *VisitImplicitParamDecl(ImplicitParamDecl *D); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 261 | Decl *VisitParmVarDecl(ParmVarDecl *D); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 262 | Decl *VisitObjCMethodDecl(ObjCMethodDecl *D); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 263 | Decl *VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 264 | Decl *VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 265 | Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 266 | Decl *VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 267 | Decl *VisitUsingDecl(UsingDecl *D); |
| 268 | Decl *VisitUsingShadowDecl(UsingShadowDecl *D); |
| 269 | Decl *VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 270 | Decl *VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| 271 | Decl *VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
| 272 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 273 | ObjCTypeParamList *ImportObjCTypeParamList(ObjCTypeParamList *list); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 274 | Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 275 | Decl *VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 276 | Decl *VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 277 | Decl *VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 278 | Decl *VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 279 | Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 280 | Decl *VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 281 | Decl *VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 282 | Decl *VisitClassTemplateDecl(ClassTemplateDecl *D); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 283 | Decl *VisitClassTemplateSpecializationDecl( |
| 284 | ClassTemplateSpecializationDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 285 | Decl *VisitVarTemplateDecl(VarTemplateDecl *D); |
| 286 | Decl *VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 287 | Decl *VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 288 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 289 | // Importing statements |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 290 | DeclGroupRef ImportDeclGroup(DeclGroupRef DG); |
| 291 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 292 | Stmt *VisitStmt(Stmt *S); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 293 | Stmt *VisitGCCAsmStmt(GCCAsmStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 294 | Stmt *VisitDeclStmt(DeclStmt *S); |
| 295 | Stmt *VisitNullStmt(NullStmt *S); |
| 296 | Stmt *VisitCompoundStmt(CompoundStmt *S); |
| 297 | Stmt *VisitCaseStmt(CaseStmt *S); |
| 298 | Stmt *VisitDefaultStmt(DefaultStmt *S); |
| 299 | Stmt *VisitLabelStmt(LabelStmt *S); |
| 300 | Stmt *VisitAttributedStmt(AttributedStmt *S); |
| 301 | Stmt *VisitIfStmt(IfStmt *S); |
| 302 | Stmt *VisitSwitchStmt(SwitchStmt *S); |
| 303 | Stmt *VisitWhileStmt(WhileStmt *S); |
| 304 | Stmt *VisitDoStmt(DoStmt *S); |
| 305 | Stmt *VisitForStmt(ForStmt *S); |
| 306 | Stmt *VisitGotoStmt(GotoStmt *S); |
| 307 | Stmt *VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 308 | Stmt *VisitContinueStmt(ContinueStmt *S); |
| 309 | Stmt *VisitBreakStmt(BreakStmt *S); |
| 310 | Stmt *VisitReturnStmt(ReturnStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 311 | // FIXME: MSAsmStmt |
| 312 | // FIXME: SEHExceptStmt |
| 313 | // FIXME: SEHFinallyStmt |
| 314 | // FIXME: SEHTryStmt |
| 315 | // FIXME: SEHLeaveStmt |
| 316 | // FIXME: CapturedStmt |
| 317 | Stmt *VisitCXXCatchStmt(CXXCatchStmt *S); |
| 318 | Stmt *VisitCXXTryStmt(CXXTryStmt *S); |
| 319 | Stmt *VisitCXXForRangeStmt(CXXForRangeStmt *S); |
| 320 | // FIXME: MSDependentExistsStmt |
| 321 | Stmt *VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); |
| 322 | Stmt *VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); |
| 323 | Stmt *VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); |
| 324 | Stmt *VisitObjCAtTryStmt(ObjCAtTryStmt *S); |
| 325 | Stmt *VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); |
| 326 | Stmt *VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); |
| 327 | Stmt *VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 328 | |
| 329 | // Importing expressions |
| 330 | Expr *VisitExpr(Expr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 331 | Expr *VisitVAArgExpr(VAArgExpr *E); |
| 332 | Expr *VisitGNUNullExpr(GNUNullExpr *E); |
| 333 | Expr *VisitPredefinedExpr(PredefinedExpr *E); |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 334 | Expr *VisitDeclRefExpr(DeclRefExpr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 335 | Expr *VisitImplicitValueInitExpr(ImplicitValueInitExpr *ILE); |
| 336 | Expr *VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 337 | Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 338 | Expr *VisitIntegerLiteral(IntegerLiteral *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 339 | Expr *VisitFloatingLiteral(FloatingLiteral *E); |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 340 | Expr *VisitCharacterLiteral(CharacterLiteral *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 341 | Expr *VisitStringLiteral(StringLiteral *E); |
| 342 | Expr *VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 343 | Expr *VisitAtomicExpr(AtomicExpr *E); |
| 344 | Expr *VisitAddrLabelExpr(AddrLabelExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 345 | Expr *VisitParenExpr(ParenExpr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 346 | Expr *VisitParenListExpr(ParenListExpr *E); |
| 347 | Expr *VisitStmtExpr(StmtExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 348 | Expr *VisitUnaryOperator(UnaryOperator *E); |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 349 | Expr *VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 350 | Expr *VisitBinaryOperator(BinaryOperator *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 351 | Expr *VisitConditionalOperator(ConditionalOperator *E); |
| 352 | Expr *VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 353 | Expr *VisitOpaqueValueExpr(OpaqueValueExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 354 | Expr *VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 355 | Expr *VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 356 | Expr *VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 357 | Expr *VisitCompoundAssignOperator(CompoundAssignOperator *E); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 358 | Expr *VisitImplicitCastExpr(ImplicitCastExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 359 | Expr *VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 360 | Expr *VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 361 | Expr *VisitCXXThrowExpr(CXXThrowExpr *E); |
| 362 | Expr *VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 363 | Expr *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 364 | Expr *VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 365 | Expr *VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 366 | Expr *VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE); |
| 367 | Expr *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 368 | Expr *VisitPackExpansionExpr(PackExpansionExpr *E); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 369 | Expr *VisitSizeOfPackExpr(SizeOfPackExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 370 | Expr *VisitCXXNewExpr(CXXNewExpr *CE); |
| 371 | Expr *VisitCXXDeleteExpr(CXXDeleteExpr *E); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 372 | Expr *VisitCXXConstructExpr(CXXConstructExpr *E); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 373 | Expr *VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 374 | Expr *VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 375 | Expr *VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 376 | Expr *VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *CE); |
| 377 | Expr *VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 378 | Expr *VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 379 | Expr *VisitExprWithCleanups(ExprWithCleanups *EWC); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 380 | Expr *VisitCXXThisExpr(CXXThisExpr *E); |
| 381 | Expr *VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 382 | Expr *VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 383 | Expr *VisitMemberExpr(MemberExpr *E); |
| 384 | Expr *VisitCallExpr(CallExpr *E); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 385 | Expr *VisitLambdaExpr(LambdaExpr *LE); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 386 | Expr *VisitInitListExpr(InitListExpr *E); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 387 | Expr *VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 388 | Expr *VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 389 | Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 390 | Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 391 | Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 392 | Expr *VisitTypeTraitExpr(TypeTraitExpr *E); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 393 | Expr *VisitCXXTypeidExpr(CXXTypeidExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 394 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 395 | template<typename IIter, typename OIter> |
| 396 | void ImportArray(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 397 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; |
| 398 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 399 | ASTImporter &ImporterRef = Importer; |
| 400 | std::transform(Ibegin, Iend, Obegin, |
| 401 | [&ImporterRef](ItemT From) -> ItemT { |
| 402 | return ImporterRef.Import(From); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 403 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | template<typename IIter, typename OIter> |
| 407 | bool ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 408 | using ItemT = typename std::remove_reference<decltype(**Obegin)>::type; |
| 409 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 410 | ASTImporter &ImporterRef = Importer; |
| 411 | bool Failed = false; |
| 412 | std::transform(Ibegin, Iend, Obegin, |
| 413 | [&ImporterRef, &Failed](ItemT *From) -> ItemT * { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 414 | auto *To = cast_or_null<ItemT>(ImporterRef.Import(From)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 415 | if (!To && From) |
| 416 | Failed = true; |
| 417 | return To; |
| 418 | }); |
| 419 | return Failed; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 420 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 421 | |
| 422 | template<typename InContainerTy, typename OutContainerTy> |
| 423 | bool ImportContainerChecked(const InContainerTy &InContainer, |
| 424 | OutContainerTy &OutContainer) { |
| 425 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), |
| 426 | OutContainer.begin()); |
| 427 | } |
| 428 | |
| 429 | template<typename InContainerTy, typename OIter> |
| 430 | bool ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
| 431 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 432 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 433 | |
| 434 | // Importing overrides. |
| 435 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 436 | |
| 437 | FunctionDecl *FindFunctionTemplateSpecialization(FunctionDecl *FromFD); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 438 | }; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 439 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 440 | template <typename InContainerTy> |
| 441 | bool ASTNodeImporter::ImportTemplateArgumentListInfo( |
| 442 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 443 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { |
| 444 | TemplateArgumentListInfo ToTAInfo(Importer.Import(FromLAngleLoc), |
| 445 | Importer.Import(FromRAngleLoc)); |
| 446 | if (ImportTemplateArgumentListInfo(Container, ToTAInfo)) |
| 447 | return true; |
| 448 | Result = ToTAInfo; |
| 449 | return false; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 450 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 451 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 452 | template <> |
| 453 | bool ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( |
| 454 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { |
| 455 | return ImportTemplateArgumentListInfo( |
| 456 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); |
| 457 | } |
| 458 | |
| 459 | template <> |
| 460 | bool ASTNodeImporter::ImportTemplateArgumentListInfo< |
| 461 | ASTTemplateArgumentListInfo>(const ASTTemplateArgumentListInfo &From, |
| 462 | TemplateArgumentListInfo &Result) { |
| 463 | return ImportTemplateArgumentListInfo(From.LAngleLoc, From.RAngleLoc, |
| 464 | From.arguments(), Result); |
| 465 | } |
| 466 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 467 | std::tuple<FunctionTemplateDecl *, ASTNodeImporter::OptionalTemplateArgsTy> |
| 468 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 469 | FunctionDecl *FromFD) { |
| 470 | assert(FromFD->getTemplatedKind() == |
| 471 | FunctionDecl::TK_FunctionTemplateSpecialization); |
| 472 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
| 473 | auto *Template = cast_or_null<FunctionTemplateDecl>( |
| 474 | Importer.Import(FTSInfo->getTemplate())); |
| 475 | |
| 476 | // Import template arguments. |
| 477 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); |
| 478 | TemplateArgsTy ToTemplArgs; |
| 479 | if (ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), |
| 480 | ToTemplArgs)) // Error during import. |
| 481 | return std::make_tuple(Template, OptionalTemplateArgsTy()); |
| 482 | |
| 483 | return std::make_tuple(Template, ToTemplArgs); |
| 484 | } |
| 485 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 486 | } // namespace clang |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 487 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 488 | //---------------------------------------------------------------------------- |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 489 | // Import Types |
| 490 | //---------------------------------------------------------------------------- |
| 491 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 492 | using namespace clang; |
| 493 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 494 | QualType ASTNodeImporter::VisitType(const Type *T) { |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 495 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 496 | << T->getTypeClassName(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 497 | return {}; |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 500 | QualType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 501 | QualType UnderlyingType = Importer.Import(T->getValueType()); |
| 502 | if(UnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 503 | return {}; |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 504 | |
| 505 | return Importer.getToContext().getAtomicType(UnderlyingType); |
| 506 | } |
| 507 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 508 | QualType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 509 | switch (T->getKind()) { |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 510 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 511 | case BuiltinType::Id: \ |
| 512 | return Importer.getToContext().SingletonId; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 513 | #include "clang/Basic/OpenCLImageTypes.def" |
John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 514 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 515 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 516 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 517 | #include "clang/AST/BuiltinTypes.def" |
| 518 | |
| 519 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 520 | // context supports C++. |
| 521 | |
| 522 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 523 | // context supports ObjC. |
| 524 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 525 | case BuiltinType::Char_U: |
| 526 | // The context we're importing from has an unsigned 'char'. If we're |
| 527 | // importing into a context with a signed 'char', translate to |
| 528 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 529 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 530 | return Importer.getToContext().UnsignedCharTy; |
| 531 | |
| 532 | return Importer.getToContext().CharTy; |
| 533 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 534 | case BuiltinType::Char_S: |
| 535 | // The context we're importing from has an unsigned 'char'. If we're |
| 536 | // importing into a context with a signed 'char', translate to |
| 537 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 538 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 539 | return Importer.getToContext().SignedCharTy; |
| 540 | |
| 541 | return Importer.getToContext().CharTy; |
| 542 | |
Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 543 | case BuiltinType::WChar_S: |
| 544 | case BuiltinType::WChar_U: |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 545 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 546 | // wchar_t? |
| 547 | return Importer.getToContext().WCharTy; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 548 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 549 | |
| 550 | llvm_unreachable("Invalid BuiltinType Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 551 | } |
| 552 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 553 | QualType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 554 | QualType OrigT = Importer.Import(T->getOriginalType()); |
| 555 | if (OrigT.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 556 | return {}; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 557 | |
| 558 | return Importer.getToContext().getDecayedType(OrigT); |
| 559 | } |
| 560 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 561 | QualType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 562 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 563 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 564 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 565 | |
| 566 | return Importer.getToContext().getComplexType(ToElementType); |
| 567 | } |
| 568 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 569 | QualType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 570 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 571 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 572 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 573 | |
| 574 | return Importer.getToContext().getPointerType(ToPointeeType); |
| 575 | } |
| 576 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 577 | QualType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 578 | // FIXME: Check for blocks support in "to" context. |
| 579 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 580 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 581 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 582 | |
| 583 | return Importer.getToContext().getBlockPointerType(ToPointeeType); |
| 584 | } |
| 585 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 586 | QualType |
| 587 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 588 | // FIXME: Check for C++ support in "to" context. |
| 589 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 590 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 591 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 592 | |
| 593 | return Importer.getToContext().getLValueReferenceType(ToPointeeType); |
| 594 | } |
| 595 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 596 | QualType |
| 597 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 598 | // FIXME: Check for C++0x support in "to" context. |
| 599 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 600 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 601 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 602 | |
| 603 | return Importer.getToContext().getRValueReferenceType(ToPointeeType); |
| 604 | } |
| 605 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 606 | QualType ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 607 | // FIXME: Check for C++ support in "to" context. |
| 608 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 609 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 610 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 611 | |
| 612 | QualType ClassType = Importer.Import(QualType(T->getClass(), 0)); |
| 613 | return Importer.getToContext().getMemberPointerType(ToPointeeType, |
| 614 | ClassType.getTypePtr()); |
| 615 | } |
| 616 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 617 | QualType ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 618 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 619 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 620 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 621 | |
| 622 | return Importer.getToContext().getConstantArrayType(ToElementType, |
| 623 | T->getSize(), |
| 624 | T->getSizeModifier(), |
| 625 | T->getIndexTypeCVRQualifiers()); |
| 626 | } |
| 627 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 628 | QualType |
| 629 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 630 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 631 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 632 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 633 | |
| 634 | return Importer.getToContext().getIncompleteArrayType(ToElementType, |
| 635 | T->getSizeModifier(), |
| 636 | T->getIndexTypeCVRQualifiers()); |
| 637 | } |
| 638 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 639 | QualType ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 640 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 641 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 642 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 643 | |
| 644 | Expr *Size = Importer.Import(T->getSizeExpr()); |
| 645 | if (!Size) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 646 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 647 | |
| 648 | SourceRange Brackets = Importer.Import(T->getBracketsRange()); |
| 649 | return Importer.getToContext().getVariableArrayType(ToElementType, Size, |
| 650 | T->getSizeModifier(), |
| 651 | T->getIndexTypeCVRQualifiers(), |
| 652 | Brackets); |
| 653 | } |
| 654 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 655 | QualType ASTNodeImporter::VisitDependentSizedArrayType( |
| 656 | const DependentSizedArrayType *T) { |
| 657 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 658 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 659 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 660 | |
| 661 | // SizeExpr may be null if size is not specified directly. |
| 662 | // For example, 'int a[]'. |
| 663 | Expr *Size = Importer.Import(T->getSizeExpr()); |
| 664 | if (!Size && T->getSizeExpr()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 665 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 666 | |
| 667 | SourceRange Brackets = Importer.Import(T->getBracketsRange()); |
| 668 | return Importer.getToContext().getDependentSizedArrayType( |
| 669 | ToElementType, Size, T->getSizeModifier(), T->getIndexTypeCVRQualifiers(), |
| 670 | Brackets); |
| 671 | } |
| 672 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 673 | QualType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 674 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 675 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 676 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 677 | |
| 678 | return Importer.getToContext().getVectorType(ToElementType, |
| 679 | T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 680 | T->getVectorKind()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 681 | } |
| 682 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 683 | QualType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 684 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 685 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 686 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 687 | |
| 688 | return Importer.getToContext().getExtVectorType(ToElementType, |
| 689 | T->getNumElements()); |
| 690 | } |
| 691 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 692 | QualType |
| 693 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 694 | // FIXME: What happens if we're importing a function without a prototype |
| 695 | // into C++? Should we make it variadic? |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 696 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 697 | if (ToResultType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 698 | return {}; |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 699 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 700 | return Importer.getToContext().getFunctionNoProtoType(ToResultType, |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 701 | T->getExtInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 702 | } |
| 703 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 704 | QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 705 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 706 | if (ToResultType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 707 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 708 | |
| 709 | // Import argument types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 710 | SmallVector<QualType, 4> ArgTypes; |
Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 711 | for (const auto &A : T->param_types()) { |
| 712 | QualType ArgType = Importer.Import(A); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 713 | if (ArgType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 714 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 715 | ArgTypes.push_back(ArgType); |
| 716 | } |
| 717 | |
| 718 | // Import exception types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 719 | SmallVector<QualType, 4> ExceptionTypes; |
Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 720 | for (const auto &E : T->exceptions()) { |
| 721 | QualType ExceptionType = Importer.Import(E); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 722 | if (ExceptionType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 723 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 724 | ExceptionTypes.push_back(ExceptionType); |
| 725 | } |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 726 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 727 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 728 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 729 | |
| 730 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 731 | ToEPI.Variadic = FromEPI.Variadic; |
| 732 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 733 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 734 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 735 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 736 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
| 737 | ToEPI.ExceptionSpec.NoexceptExpr = |
| 738 | Importer.Import(FromEPI.ExceptionSpec.NoexceptExpr); |
| 739 | ToEPI.ExceptionSpec.SourceDecl = cast_or_null<FunctionDecl>( |
| 740 | Importer.Import(FromEPI.ExceptionSpec.SourceDecl)); |
| 741 | ToEPI.ExceptionSpec.SourceTemplate = cast_or_null<FunctionDecl>( |
| 742 | Importer.Import(FromEPI.ExceptionSpec.SourceTemplate)); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 743 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 744 | return Importer.getToContext().getFunctionType(ToResultType, ArgTypes, ToEPI); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 745 | } |
| 746 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 747 | QualType ASTNodeImporter::VisitUnresolvedUsingType( |
| 748 | const UnresolvedUsingType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 749 | const auto *ToD = |
| 750 | cast_or_null<UnresolvedUsingTypenameDecl>(Importer.Import(T->getDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 751 | if (!ToD) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 752 | return {}; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 753 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 754 | auto *ToPrevD = |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 755 | cast_or_null<UnresolvedUsingTypenameDecl>( |
| 756 | Importer.Import(T->getDecl()->getPreviousDecl())); |
| 757 | if (!ToPrevD && T->getDecl()->getPreviousDecl()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 758 | return {}; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 759 | |
| 760 | return Importer.getToContext().getTypeDeclType(ToD, ToPrevD); |
| 761 | } |
| 762 | |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 763 | QualType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 764 | QualType ToInnerType = Importer.Import(T->getInnerType()); |
| 765 | if (ToInnerType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 766 | return {}; |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 767 | |
| 768 | return Importer.getToContext().getParenType(ToInnerType); |
| 769 | } |
| 770 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 771 | QualType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 772 | auto *ToDecl = |
| 773 | dyn_cast_or_null<TypedefNameDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 774 | if (!ToDecl) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 775 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 776 | |
| 777 | return Importer.getToContext().getTypeDeclType(ToDecl); |
| 778 | } |
| 779 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 780 | QualType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 781 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 782 | if (!ToExpr) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 783 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 784 | |
| 785 | return Importer.getToContext().getTypeOfExprType(ToExpr); |
| 786 | } |
| 787 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 788 | QualType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 789 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 790 | if (ToUnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 791 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 792 | |
| 793 | return Importer.getToContext().getTypeOfType(ToUnderlyingType); |
| 794 | } |
| 795 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 796 | QualType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 797 | // FIXME: Make sure that the "to" context supports C++0x! |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 798 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 799 | if (!ToExpr) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 800 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 801 | |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 802 | QualType UnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 803 | if (UnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 804 | return {}; |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 805 | |
| 806 | return Importer.getToContext().getDecltypeType(ToExpr, UnderlyingType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 807 | } |
| 808 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 809 | QualType ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 810 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 811 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 812 | if (ToBaseType.isNull() || ToUnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 813 | return {}; |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 814 | |
| 815 | return Importer.getToContext().getUnaryTransformType(ToBaseType, |
| 816 | ToUnderlyingType, |
| 817 | T->getUTTKind()); |
| 818 | } |
| 819 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 820 | QualType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 821 | // FIXME: Make sure that the "to" context supports C++11! |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 822 | QualType FromDeduced = T->getDeducedType(); |
| 823 | QualType ToDeduced; |
| 824 | if (!FromDeduced.isNull()) { |
| 825 | ToDeduced = Importer.Import(FromDeduced); |
| 826 | if (ToDeduced.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 827 | return {}; |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 828 | } |
| 829 | |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 830 | return Importer.getToContext().getAutoType(ToDeduced, T->getKeyword(), |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 831 | /*IsDependent*/false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 832 | } |
| 833 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 834 | QualType ASTNodeImporter::VisitInjectedClassNameType( |
| 835 | const InjectedClassNameType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 836 | auto *D = cast_or_null<CXXRecordDecl>(Importer.Import(T->getDecl())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 837 | if (!D) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 838 | return {}; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 839 | |
| 840 | QualType InjType = Importer.Import(T->getInjectedSpecializationType()); |
| 841 | if (InjType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 842 | return {}; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 843 | |
| 844 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 845 | // See comments in InjectedClassNameType definition for details |
| 846 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 847 | enum { |
| 848 | TypeAlignmentInBits = 4, |
| 849 | TypeAlignment = 1 << TypeAlignmentInBits |
| 850 | }; |
| 851 | |
| 852 | return QualType(new (Importer.getToContext(), TypeAlignment) |
| 853 | InjectedClassNameType(D, InjType), 0); |
| 854 | } |
| 855 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 856 | QualType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 857 | auto *ToDecl = dyn_cast_or_null<RecordDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 858 | if (!ToDecl) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 859 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 860 | |
| 861 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 862 | } |
| 863 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 864 | QualType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 865 | auto *ToDecl = dyn_cast_or_null<EnumDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 866 | if (!ToDecl) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 867 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 868 | |
| 869 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 870 | } |
| 871 | |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 872 | QualType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 873 | QualType FromModifiedType = T->getModifiedType(); |
| 874 | QualType FromEquivalentType = T->getEquivalentType(); |
| 875 | QualType ToModifiedType; |
| 876 | QualType ToEquivalentType; |
| 877 | |
| 878 | if (!FromModifiedType.isNull()) { |
| 879 | ToModifiedType = Importer.Import(FromModifiedType); |
| 880 | if (ToModifiedType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 881 | return {}; |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 882 | } |
| 883 | if (!FromEquivalentType.isNull()) { |
| 884 | ToEquivalentType = Importer.Import(FromEquivalentType); |
| 885 | if (ToEquivalentType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 886 | return {}; |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
| 890 | ToModifiedType, ToEquivalentType); |
| 891 | } |
| 892 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 893 | QualType ASTNodeImporter::VisitTemplateTypeParmType( |
| 894 | const TemplateTypeParmType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 895 | auto *ParmDecl = |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 896 | cast_or_null<TemplateTypeParmDecl>(Importer.Import(T->getDecl())); |
| 897 | if (!ParmDecl && T->getDecl()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 898 | return {}; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 899 | |
| 900 | return Importer.getToContext().getTemplateTypeParmType( |
| 901 | T->getDepth(), T->getIndex(), T->isParameterPack(), ParmDecl); |
| 902 | } |
| 903 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 904 | QualType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
| 905 | const SubstTemplateTypeParmType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 906 | const auto *Replaced = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 907 | cast_or_null<TemplateTypeParmType>(Importer.Import( |
| 908 | QualType(T->getReplacedParameter(), 0)).getTypePtr()); |
| 909 | if (!Replaced) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 910 | return {}; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 911 | |
| 912 | QualType Replacement = Importer.Import(T->getReplacementType()); |
| 913 | if (Replacement.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 914 | return {}; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 915 | Replacement = Replacement.getCanonicalType(); |
| 916 | |
| 917 | return Importer.getToContext().getSubstTemplateTypeParmType( |
| 918 | Replaced, Replacement); |
| 919 | } |
| 920 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 921 | QualType ASTNodeImporter::VisitTemplateSpecializationType( |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 922 | const TemplateSpecializationType *T) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 923 | TemplateName ToTemplate = Importer.Import(T->getTemplateName()); |
| 924 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 925 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 926 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 927 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 928 | if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 929 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 930 | |
| 931 | QualType ToCanonType; |
| 932 | if (!QualType(T, 0).isCanonical()) { |
| 933 | QualType FromCanonType |
| 934 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
| 935 | ToCanonType =Importer.Import(FromCanonType); |
| 936 | if (ToCanonType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 937 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 938 | } |
| 939 | return Importer.getToContext().getTemplateSpecializationType(ToTemplate, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 940 | ToTemplateArgs, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 941 | ToCanonType); |
| 942 | } |
| 943 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 944 | QualType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 945 | NestedNameSpecifier *ToQualifier = nullptr; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 946 | // Note: the qualifier in an ElaboratedType is optional. |
| 947 | if (T->getQualifier()) { |
| 948 | ToQualifier = Importer.Import(T->getQualifier()); |
| 949 | if (!ToQualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 950 | return {}; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 951 | } |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 952 | |
| 953 | QualType ToNamedType = Importer.Import(T->getNamedType()); |
| 954 | if (ToNamedType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 955 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 956 | |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 957 | TagDecl *OwnedTagDecl = |
| 958 | cast_or_null<TagDecl>(Importer.Import(T->getOwnedTagDecl())); |
| 959 | if (!OwnedTagDecl && T->getOwnedTagDecl()) |
| 960 | return {}; |
| 961 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 962 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 963 | ToQualifier, ToNamedType, |
| 964 | OwnedTagDecl); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 965 | } |
| 966 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 967 | QualType ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 968 | QualType Pattern = Importer.Import(T->getPattern()); |
| 969 | if (Pattern.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 970 | return {}; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 971 | |
| 972 | return Importer.getToContext().getPackExpansionType(Pattern, |
| 973 | T->getNumExpansions()); |
| 974 | } |
| 975 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 976 | QualType ASTNodeImporter::VisitDependentTemplateSpecializationType( |
| 977 | const DependentTemplateSpecializationType *T) { |
| 978 | NestedNameSpecifier *Qualifier = Importer.Import(T->getQualifier()); |
| 979 | if (!Qualifier && T->getQualifier()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 980 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 981 | |
| 982 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
| 983 | if (!Name && T->getIdentifier()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 984 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 985 | |
| 986 | SmallVector<TemplateArgument, 2> ToPack; |
| 987 | ToPack.reserve(T->getNumArgs()); |
| 988 | if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToPack)) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 989 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 990 | |
| 991 | return Importer.getToContext().getDependentTemplateSpecializationType( |
| 992 | T->getKeyword(), Qualifier, Name, ToPack); |
| 993 | } |
| 994 | |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 995 | QualType ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { |
| 996 | NestedNameSpecifier *NNS = Importer.Import(T->getQualifier()); |
| 997 | if (!NNS && T->getQualifier()) |
| 998 | return QualType(); |
| 999 | |
| 1000 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
| 1001 | if (!Name && T->getIdentifier()) |
| 1002 | return QualType(); |
| 1003 | |
| 1004 | QualType Canon = (T == T->getCanonicalTypeInternal().getTypePtr()) |
| 1005 | ? QualType() |
| 1006 | : Importer.Import(T->getCanonicalTypeInternal()); |
| 1007 | if (!Canon.isNull()) |
| 1008 | Canon = Canon.getCanonicalType(); |
| 1009 | |
| 1010 | return Importer.getToContext().getDependentNameType(T->getKeyword(), NNS, |
| 1011 | Name, Canon); |
| 1012 | } |
| 1013 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1014 | QualType ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1015 | auto *Class = |
| 1016 | dyn_cast_or_null<ObjCInterfaceDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1017 | if (!Class) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1018 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1019 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1020 | return Importer.getToContext().getObjCInterfaceType(Class); |
| 1021 | } |
| 1022 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1023 | QualType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1024 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 1025 | if (ToBaseType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1026 | return {}; |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1027 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1028 | SmallVector<QualType, 4> TypeArgs; |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 1029 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1030 | QualType ImportedTypeArg = Importer.Import(TypeArg); |
| 1031 | if (ImportedTypeArg.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1032 | return {}; |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1033 | |
| 1034 | TypeArgs.push_back(ImportedTypeArg); |
| 1035 | } |
| 1036 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1037 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 1038 | for (auto *P : T->quals()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1039 | auto *Protocol = dyn_cast_or_null<ObjCProtocolDecl>(Importer.Import(P)); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1040 | if (!Protocol) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1041 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1042 | Protocols.push_back(Protocol); |
| 1043 | } |
| 1044 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1045 | return Importer.getToContext().getObjCObjectType(ToBaseType, TypeArgs, |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 1046 | Protocols, |
| 1047 | T->isKindOfTypeAsWritten()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1050 | QualType |
| 1051 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1052 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 1053 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1054 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1055 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1056 | return Importer.getToContext().getObjCObjectPointerType(ToPointeeType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1059 | //---------------------------------------------------------------------------- |
| 1060 | // Import Declarations |
| 1061 | //---------------------------------------------------------------------------- |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1062 | bool ASTNodeImporter::ImportDeclParts(NamedDecl *D, DeclContext *&DC, |
| 1063 | DeclContext *&LexicalDC, |
| 1064 | DeclarationName &Name, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1065 | NamedDecl *&ToD, |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1066 | SourceLocation &Loc) { |
| 1067 | // Import the context of this declaration. |
| 1068 | DC = Importer.ImportContext(D->getDeclContext()); |
| 1069 | if (!DC) |
| 1070 | return true; |
| 1071 | |
| 1072 | LexicalDC = DC; |
| 1073 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 1074 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 1075 | if (!LexicalDC) |
| 1076 | return true; |
| 1077 | } |
| 1078 | |
| 1079 | // Import the name of this declaration. |
| 1080 | Name = Importer.Import(D->getDeclName()); |
| 1081 | if (D->getDeclName() && !Name) |
| 1082 | return true; |
| 1083 | |
| 1084 | // Import the location of this declaration. |
| 1085 | Loc = Importer.Import(D->getLocation()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1086 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1087 | return false; |
| 1088 | } |
| 1089 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1090 | void ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
| 1091 | if (!FromD) |
| 1092 | return; |
| 1093 | |
| 1094 | if (!ToD) { |
| 1095 | ToD = Importer.Import(FromD); |
| 1096 | if (!ToD) |
| 1097 | return; |
| 1098 | } |
| 1099 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1100 | if (auto *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 1101 | if (auto *ToRecord = cast_or_null<RecordDecl>(ToD)) { |
Sean Callanan | 19dfc93 | 2013-01-11 23:17:47 +0000 | [diff] [blame] | 1102 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && !ToRecord->getDefinition()) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1103 | ImportDefinition(FromRecord, ToRecord); |
| 1104 | } |
| 1105 | } |
| 1106 | return; |
| 1107 | } |
| 1108 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1109 | if (auto *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 1110 | if (auto *ToEnum = cast_or_null<EnumDecl>(ToD)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1111 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
| 1112 | ImportDefinition(FromEnum, ToEnum); |
| 1113 | } |
| 1114 | } |
| 1115 | return; |
| 1116 | } |
| 1117 | } |
| 1118 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1119 | void |
| 1120 | ASTNodeImporter::ImportDeclarationNameLoc(const DeclarationNameInfo &From, |
| 1121 | DeclarationNameInfo& To) { |
| 1122 | // NOTE: To.Name and To.Loc are already imported. |
| 1123 | // We only have to import To.LocInfo. |
| 1124 | switch (To.getName().getNameKind()) { |
| 1125 | case DeclarationName::Identifier: |
| 1126 | case DeclarationName::ObjCZeroArgSelector: |
| 1127 | case DeclarationName::ObjCOneArgSelector: |
| 1128 | case DeclarationName::ObjCMultiArgSelector: |
| 1129 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1130 | case DeclarationName::CXXDeductionGuideName: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1131 | return; |
| 1132 | |
| 1133 | case DeclarationName::CXXOperatorName: { |
| 1134 | SourceRange Range = From.getCXXOperatorNameRange(); |
| 1135 | To.setCXXOperatorNameRange(Importer.Import(Range)); |
| 1136 | return; |
| 1137 | } |
| 1138 | case DeclarationName::CXXLiteralOperatorName: { |
| 1139 | SourceLocation Loc = From.getCXXLiteralOperatorNameLoc(); |
| 1140 | To.setCXXLiteralOperatorNameLoc(Importer.Import(Loc)); |
| 1141 | return; |
| 1142 | } |
| 1143 | case DeclarationName::CXXConstructorName: |
| 1144 | case DeclarationName::CXXDestructorName: |
| 1145 | case DeclarationName::CXXConversionFunctionName: { |
| 1146 | TypeSourceInfo *FromTInfo = From.getNamedTypeInfo(); |
| 1147 | To.setNamedTypeInfo(Importer.Import(FromTInfo)); |
| 1148 | return; |
| 1149 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1150 | } |
Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1151 | llvm_unreachable("Unknown name kind."); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1154 | void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1155 | if (Importer.isMinimalImport() && !ForceImport) { |
Sean Callanan | 81d577c | 2011-07-22 23:46:03 +0000 | [diff] [blame] | 1156 | Importer.ImportContext(FromDC); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1157 | return; |
| 1158 | } |
| 1159 | |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 1160 | for (auto *From : FromDC->decls()) |
| 1161 | Importer.Import(From); |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1162 | } |
| 1163 | |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1164 | static void setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1165 | ASTImporter &Importer) { |
| 1166 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
| 1167 | auto *ToTypedef = |
| 1168 | cast_or_null<TypedefNameDecl>(Importer.Import(FromTypedef)); |
| 1169 | assert (ToTypedef && "Failed to import typedef of an anonymous structure"); |
| 1170 | |
| 1171 | To->setTypedefNameForAnonDecl(ToTypedef); |
| 1172 | } |
| 1173 | } |
| 1174 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1175 | bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1176 | ImportDefinitionKind Kind) { |
| 1177 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1178 | if (Kind == IDK_Everything) |
| 1179 | ImportDeclContext(From, /*ForceImport=*/true); |
| 1180 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1181 | return false; |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1182 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1183 | |
| 1184 | To->startDefinition(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1185 | |
| 1186 | setTypedefNameForAnonDecl(From, To, Importer); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1187 | |
| 1188 | // Add base classes. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1189 | if (auto *ToCXX = dyn_cast<CXXRecordDecl>(To)) { |
| 1190 | auto *FromCXX = cast<CXXRecordDecl>(From); |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1191 | |
| 1192 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1193 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 1194 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1195 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1196 | ToData.Aggregate = FromData.Aggregate; |
| 1197 | ToData.PlainOldData = FromData.PlainOldData; |
| 1198 | ToData.Empty = FromData.Empty; |
| 1199 | ToData.Polymorphic = FromData.Polymorphic; |
| 1200 | ToData.Abstract = FromData.Abstract; |
| 1201 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 1202 | ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout; |
| 1203 | ToData.HasBasesWithFields = FromData.HasBasesWithFields; |
| 1204 | ToData.HasBasesWithNonStaticDataMembers = |
| 1205 | FromData.HasBasesWithNonStaticDataMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1206 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 1207 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 1208 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 1209 | ToData.HasMutableFields = FromData.HasMutableFields; |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 1210 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1211 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 1212 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 1213 | ToData.HasUninitializedReferenceMember |
| 1214 | = FromData.HasUninitializedReferenceMember; |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1215 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1216 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 1217 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1218 | ToData.NeedOverloadResolutionForCopyConstructor |
| 1219 | = FromData.NeedOverloadResolutionForCopyConstructor; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1220 | ToData.NeedOverloadResolutionForMoveConstructor |
| 1221 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 1222 | ToData.NeedOverloadResolutionForMoveAssignment |
| 1223 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 1224 | ToData.NeedOverloadResolutionForDestructor |
| 1225 | = FromData.NeedOverloadResolutionForDestructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1226 | ToData.DefaultedCopyConstructorIsDeleted |
| 1227 | = FromData.DefaultedCopyConstructorIsDeleted; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1228 | ToData.DefaultedMoveConstructorIsDeleted |
| 1229 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 1230 | ToData.DefaultedMoveAssignmentIsDeleted |
| 1231 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 1232 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1233 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 1234 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1235 | ToData.HasConstexprNonCopyMoveConstructor |
| 1236 | = FromData.HasConstexprNonCopyMoveConstructor; |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1237 | ToData.HasDefaultedDefaultConstructor |
| 1238 | = FromData.HasDefaultedDefaultConstructor; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1239 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 1240 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1241 | ToData.HasConstexprDefaultConstructor |
| 1242 | = FromData.HasConstexprDefaultConstructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1243 | ToData.HasNonLiteralTypeFieldsOrBases |
| 1244 | = FromData.HasNonLiteralTypeFieldsOrBases; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1245 | // ComputedVisibleConversions not imported. |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1246 | ToData.UserProvidedDefaultConstructor |
| 1247 | = FromData.UserProvidedDefaultConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1248 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1249 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 1250 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 1251 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 1252 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 1253 | ToData.ImplicitCopyAssignmentHasConstParam |
| 1254 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 1255 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 1256 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 1257 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 1258 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1259 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1260 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1261 | for (const auto &Base1 : FromCXX->bases()) { |
| 1262 | QualType T = Importer.Import(Base1.getType()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1263 | if (T.isNull()) |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1264 | return true; |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1265 | |
| 1266 | SourceLocation EllipsisLoc; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1267 | if (Base1.isPackExpansion()) |
| 1268 | EllipsisLoc = Importer.Import(Base1.getEllipsisLoc()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1269 | |
| 1270 | // Ensure that we have a definition for the base. |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1271 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1272 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1273 | Bases.push_back( |
| 1274 | new (Importer.getToContext()) |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1275 | CXXBaseSpecifier(Importer.Import(Base1.getSourceRange()), |
| 1276 | Base1.isVirtual(), |
| 1277 | Base1.isBaseOfClass(), |
| 1278 | Base1.getAccessSpecifierAsWritten(), |
| 1279 | Importer.Import(Base1.getTypeSourceInfo()), |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1280 | EllipsisLoc)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1281 | } |
| 1282 | if (!Bases.empty()) |
Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1283 | ToCXX->setBases(Bases.data(), Bases.size()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1284 | } |
| 1285 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1286 | if (shouldForceImportDeclContext(Kind)) |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1287 | ImportDeclContext(From, /*ForceImport=*/true); |
| 1288 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1289 | To->completeDefinition(); |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1290 | return false; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1291 | } |
| 1292 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1293 | bool ASTNodeImporter::ImportDefinition(VarDecl *From, VarDecl *To, |
| 1294 | ImportDefinitionKind Kind) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1295 | if (To->getAnyInitializer()) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1296 | return false; |
| 1297 | |
| 1298 | // FIXME: Can we really import any initializer? Alternatively, we could force |
| 1299 | // ourselves to import every declaration of a variable and then only use |
| 1300 | // getInit() here. |
| 1301 | To->setInit(Importer.Import(const_cast<Expr *>(From->getAnyInitializer()))); |
| 1302 | |
| 1303 | // FIXME: Other bits to merge? |
| 1304 | |
| 1305 | return false; |
| 1306 | } |
| 1307 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1308 | bool ASTNodeImporter::ImportDefinition(EnumDecl *From, EnumDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1309 | ImportDefinitionKind Kind) { |
| 1310 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1311 | if (Kind == IDK_Everything) |
| 1312 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1313 | return false; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1314 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1315 | |
| 1316 | To->startDefinition(); |
| 1317 | |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1318 | setTypedefNameForAnonDecl(From, To, Importer); |
| 1319 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1320 | QualType T = Importer.Import(Importer.getFromContext().getTypeDeclType(From)); |
| 1321 | if (T.isNull()) |
| 1322 | return true; |
| 1323 | |
| 1324 | QualType ToPromotionType = Importer.Import(From->getPromotionType()); |
| 1325 | if (ToPromotionType.isNull()) |
| 1326 | return true; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1327 | |
| 1328 | if (shouldForceImportDeclContext(Kind)) |
| 1329 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1330 | |
| 1331 | // FIXME: we might need to merge the number of positive or negative bits |
| 1332 | // if the enumerator lists don't match. |
| 1333 | To->completeDefinition(T, ToPromotionType, |
| 1334 | From->getNumPositiveBits(), |
| 1335 | From->getNumNegativeBits()); |
| 1336 | return false; |
| 1337 | } |
| 1338 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1339 | TemplateParameterList *ASTNodeImporter::ImportTemplateParameterList( |
| 1340 | TemplateParameterList *Params) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1341 | SmallVector<NamedDecl *, 4> ToParams(Params->size()); |
| 1342 | if (ImportContainerChecked(*Params, ToParams)) |
| 1343 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1344 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1345 | Expr *ToRequiresClause; |
| 1346 | if (Expr *const R = Params->getRequiresClause()) { |
| 1347 | ToRequiresClause = Importer.Import(R); |
| 1348 | if (!ToRequiresClause) |
| 1349 | return nullptr; |
| 1350 | } else { |
| 1351 | ToRequiresClause = nullptr; |
| 1352 | } |
| 1353 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1354 | return TemplateParameterList::Create(Importer.getToContext(), |
| 1355 | Importer.Import(Params->getTemplateLoc()), |
| 1356 | Importer.Import(Params->getLAngleLoc()), |
David Majnemer | 902f8c6 | 2015-12-27 07:16:27 +0000 | [diff] [blame] | 1357 | ToParams, |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1358 | Importer.Import(Params->getRAngleLoc()), |
| 1359 | ToRequiresClause); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1362 | TemplateArgument |
| 1363 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1364 | switch (From.getKind()) { |
| 1365 | case TemplateArgument::Null: |
| 1366 | return TemplateArgument(); |
| 1367 | |
| 1368 | case TemplateArgument::Type: { |
| 1369 | QualType ToType = Importer.Import(From.getAsType()); |
| 1370 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1371 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1372 | return TemplateArgument(ToType); |
| 1373 | } |
| 1374 | |
| 1375 | case TemplateArgument::Integral: { |
| 1376 | QualType ToType = Importer.Import(From.getIntegralType()); |
| 1377 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1378 | return {}; |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 1379 | return TemplateArgument(From, ToType); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1380 | } |
| 1381 | |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1382 | case TemplateArgument::Declaration: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1383 | auto *To = cast_or_null<ValueDecl>(Importer.Import(From.getAsDecl())); |
David Blaikie | 3c7dd6b | 2014-10-22 19:54:16 +0000 | [diff] [blame] | 1384 | QualType ToType = Importer.Import(From.getParamTypeForDecl()); |
| 1385 | if (!To || ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1386 | return {}; |
David Blaikie | 3c7dd6b | 2014-10-22 19:54:16 +0000 | [diff] [blame] | 1387 | return TemplateArgument(To, ToType); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | case TemplateArgument::NullPtr: { |
| 1391 | QualType ToType = Importer.Import(From.getNullPtrType()); |
| 1392 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1393 | return {}; |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1394 | return TemplateArgument(ToType, /*isNullPtr*/true); |
| 1395 | } |
| 1396 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1397 | case TemplateArgument::Template: { |
| 1398 | TemplateName ToTemplate = Importer.Import(From.getAsTemplate()); |
| 1399 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1400 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1401 | |
| 1402 | return TemplateArgument(ToTemplate); |
| 1403 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1404 | |
| 1405 | case TemplateArgument::TemplateExpansion: { |
| 1406 | TemplateName ToTemplate |
| 1407 | = Importer.Import(From.getAsTemplateOrTemplatePattern()); |
| 1408 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1409 | return {}; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1410 | |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 1411 | return TemplateArgument(ToTemplate, From.getNumTemplateExpansions()); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1412 | } |
| 1413 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1414 | case TemplateArgument::Expression: |
| 1415 | if (Expr *ToExpr = Importer.Import(From.getAsExpr())) |
| 1416 | return TemplateArgument(ToExpr); |
| 1417 | return TemplateArgument(); |
| 1418 | |
| 1419 | case TemplateArgument::Pack: { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1420 | SmallVector<TemplateArgument, 2> ToPack; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1421 | ToPack.reserve(From.pack_size()); |
| 1422 | if (ImportTemplateArguments(From.pack_begin(), From.pack_size(), ToPack)) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1423 | return {}; |
Benjamin Kramer | cce6347 | 2015-08-05 09:40:22 +0000 | [diff] [blame] | 1424 | |
| 1425 | return TemplateArgument( |
| 1426 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | llvm_unreachable("Invalid template argument kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1431 | } |
| 1432 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1433 | Optional<TemplateArgumentLoc> |
| 1434 | ASTNodeImporter::ImportTemplateArgumentLoc(const TemplateArgumentLoc &TALoc) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1435 | TemplateArgument Arg = ImportTemplateArgument(TALoc.getArgument()); |
| 1436 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 1437 | TemplateArgumentLocInfo ToInfo; |
| 1438 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 1439 | Expr *E = Importer.Import(FromInfo.getAsExpr()); |
| 1440 | ToInfo = TemplateArgumentLocInfo(E); |
| 1441 | if (!E) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1442 | return None; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1443 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 1444 | if (TypeSourceInfo *TSI = Importer.Import(FromInfo.getAsTypeSourceInfo())) |
| 1445 | ToInfo = TemplateArgumentLocInfo(TSI); |
| 1446 | else |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1447 | return None; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1448 | } else { |
| 1449 | ToInfo = TemplateArgumentLocInfo( |
| 1450 | Importer.Import(FromInfo.getTemplateQualifierLoc()), |
| 1451 | Importer.Import(FromInfo.getTemplateNameLoc()), |
| 1452 | Importer.Import(FromInfo.getTemplateEllipsisLoc())); |
| 1453 | } |
| 1454 | return TemplateArgumentLoc(Arg, ToInfo); |
| 1455 | } |
| 1456 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1457 | bool ASTNodeImporter::ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 1458 | unsigned NumFromArgs, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1459 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1460 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
| 1461 | TemplateArgument To = ImportTemplateArgument(FromArgs[I]); |
| 1462 | if (To.isNull() && !FromArgs[I].isNull()) |
| 1463 | return true; |
| 1464 | |
| 1465 | ToArgs.push_back(To); |
| 1466 | } |
| 1467 | |
| 1468 | return false; |
| 1469 | } |
| 1470 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 1471 | // We cannot use Optional<> pattern here and below because |
| 1472 | // TemplateArgumentListInfo's operator new is declared as deleted so it cannot |
| 1473 | // be stored in Optional. |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1474 | template <typename InContainerTy> |
| 1475 | bool ASTNodeImporter::ImportTemplateArgumentListInfo( |
| 1476 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 1477 | for (const auto &FromLoc : Container) { |
| 1478 | if (auto ToLoc = ImportTemplateArgumentLoc(FromLoc)) |
| 1479 | ToTAInfo.addArgument(*ToLoc); |
| 1480 | else |
| 1481 | return true; |
| 1482 | } |
| 1483 | return false; |
| 1484 | } |
| 1485 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1486 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1487 | RecordDecl *ToRecord, bool Complain) { |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1488 | // Eliminate a potential failure point where we attempt to re-import |
| 1489 | // something we're trying to import while completing ToRecord. |
| 1490 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 1491 | if (ToOrigin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1492 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1493 | if (ToOriginRecord) |
| 1494 | ToRecord = ToOriginRecord; |
| 1495 | } |
| 1496 | |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1497 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1498 | ToRecord->getASTContext(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1499 | Importer.getNonEquivalentDecls(), |
| 1500 | false, Complain); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1501 | return Ctx.IsStructurallyEquivalent(FromRecord, ToRecord); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1502 | } |
| 1503 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1504 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 1505 | bool Complain) { |
| 1506 | StructuralEquivalenceContext Ctx( |
| 1507 | Importer.getFromContext(), Importer.getToContext(), |
| 1508 | Importer.getNonEquivalentDecls(), false, Complain); |
| 1509 | return Ctx.IsStructurallyEquivalent(FromVar, ToVar); |
| 1510 | } |
| 1511 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1512 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1513 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1514 | Importer.getToContext(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1515 | Importer.getNonEquivalentDecls()); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1516 | return Ctx.IsStructurallyEquivalent(FromEnum, ToEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1519 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 1520 | FunctionTemplateDecl *To) { |
| 1521 | StructuralEquivalenceContext Ctx( |
| 1522 | Importer.getFromContext(), Importer.getToContext(), |
| 1523 | Importer.getNonEquivalentDecls(), false, false); |
| 1524 | return Ctx.IsStructurallyEquivalent(From, To); |
| 1525 | } |
| 1526 | |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1527 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1528 | EnumConstantDecl *ToEC) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1529 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 1530 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 1531 | |
| 1532 | return FromVal.isSigned() == ToVal.isSigned() && |
| 1533 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 1534 | FromVal == ToVal; |
| 1535 | } |
| 1536 | |
| 1537 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1538 | ClassTemplateDecl *To) { |
| 1539 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1540 | Importer.getToContext(), |
| 1541 | Importer.getNonEquivalentDecls()); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1542 | return Ctx.IsStructurallyEquivalent(From, To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1545 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 1546 | VarTemplateDecl *To) { |
| 1547 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1548 | Importer.getToContext(), |
| 1549 | Importer.getNonEquivalentDecls()); |
| 1550 | return Ctx.IsStructurallyEquivalent(From, To); |
| 1551 | } |
| 1552 | |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1553 | Decl *ASTNodeImporter::VisitDecl(Decl *D) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 1554 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1555 | << D->getDeclKindName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1556 | return nullptr; |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1557 | } |
| 1558 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1559 | Decl *ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 1560 | // Import the context of this declaration. |
| 1561 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1562 | if (!DC) |
| 1563 | return nullptr; |
| 1564 | |
| 1565 | DeclContext *LexicalDC = DC; |
| 1566 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 1567 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 1568 | if (!LexicalDC) |
| 1569 | return nullptr; |
| 1570 | } |
| 1571 | |
| 1572 | // Import the location of this declaration. |
| 1573 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1574 | |
| 1575 | EmptyDecl *ToD = EmptyDecl::Create(Importer.getToContext(), DC, Loc); |
| 1576 | ToD->setLexicalDeclContext(LexicalDC); |
| 1577 | Importer.Imported(D, ToD); |
| 1578 | LexicalDC->addDeclInternal(ToD); |
| 1579 | return ToD; |
| 1580 | } |
| 1581 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 1582 | Decl *ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 1583 | TranslationUnitDecl *ToD = |
| 1584 | Importer.getToContext().getTranslationUnitDecl(); |
| 1585 | |
| 1586 | Importer.Imported(D, ToD); |
| 1587 | |
| 1588 | return ToD; |
| 1589 | } |
| 1590 | |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1591 | Decl *ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1592 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1593 | SourceLocation ColonLoc = Importer.Import(D->getColonLoc()); |
| 1594 | |
| 1595 | // Import the context of this declaration. |
| 1596 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1597 | if (!DC) |
| 1598 | return nullptr; |
| 1599 | |
| 1600 | AccessSpecDecl *accessSpecDecl |
| 1601 | = AccessSpecDecl::Create(Importer.getToContext(), D->getAccess(), |
| 1602 | DC, Loc, ColonLoc); |
| 1603 | |
| 1604 | if (!accessSpecDecl) |
| 1605 | return nullptr; |
| 1606 | |
| 1607 | // Lexical DeclContext and Semantic DeclContext |
| 1608 | // is always the same for the accessSpec. |
| 1609 | accessSpecDecl->setLexicalDeclContext(DC); |
| 1610 | DC->addDeclInternal(accessSpecDecl); |
| 1611 | |
| 1612 | return accessSpecDecl; |
| 1613 | } |
| 1614 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1615 | Decl *ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 1616 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1617 | if (!DC) |
| 1618 | return nullptr; |
| 1619 | |
| 1620 | DeclContext *LexicalDC = DC; |
| 1621 | |
| 1622 | // Import the location of this declaration. |
| 1623 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1624 | |
| 1625 | Expr *AssertExpr = Importer.Import(D->getAssertExpr()); |
| 1626 | if (!AssertExpr) |
| 1627 | return nullptr; |
| 1628 | |
| 1629 | StringLiteral *FromMsg = D->getMessage(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1630 | auto *ToMsg = cast_or_null<StringLiteral>(Importer.Import(FromMsg)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1631 | if (!ToMsg && FromMsg) |
| 1632 | return nullptr; |
| 1633 | |
| 1634 | StaticAssertDecl *ToD = StaticAssertDecl::Create( |
| 1635 | Importer.getToContext(), DC, Loc, AssertExpr, ToMsg, |
| 1636 | Importer.Import(D->getRParenLoc()), D->isFailed()); |
| 1637 | |
| 1638 | ToD->setLexicalDeclContext(LexicalDC); |
| 1639 | LexicalDC->addDeclInternal(ToD); |
| 1640 | Importer.Imported(D, ToD); |
| 1641 | return ToD; |
| 1642 | } |
| 1643 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1644 | Decl *ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
| 1645 | // Import the major distinguishing characteristics of this namespace. |
| 1646 | DeclContext *DC, *LexicalDC; |
| 1647 | DeclarationName Name; |
| 1648 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1649 | NamedDecl *ToD; |
| 1650 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1651 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1652 | if (ToD) |
| 1653 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1654 | |
| 1655 | NamespaceDecl *MergeWithNamespace = nullptr; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1656 | if (!Name) { |
| 1657 | // This is an anonymous namespace. Adopt an existing anonymous |
| 1658 | // namespace if we can. |
| 1659 | // FIXME: Not testable. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1660 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1661 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 1662 | else |
| 1663 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 1664 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1665 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1666 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1667 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1668 | for (auto *FoundDecl : FoundDecls) { |
| 1669 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1670 | continue; |
| 1671 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1672 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1673 | MergeWithNamespace = FoundNS; |
| 1674 | ConflictingDecls.clear(); |
| 1675 | break; |
| 1676 | } |
| 1677 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1678 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | if (!ConflictingDecls.empty()) { |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 1682 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1683 | ConflictingDecls.data(), |
| 1684 | ConflictingDecls.size()); |
| 1685 | } |
| 1686 | } |
| 1687 | |
| 1688 | // Create the "to" namespace, if needed. |
| 1689 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 1690 | if (!ToNamespace) { |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 1691 | ToNamespace = NamespaceDecl::Create(Importer.getToContext(), DC, |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1692 | D->isInline(), |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 1693 | Importer.Import(D->getLocStart()), |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1694 | Loc, Name.getAsIdentifierInfo(), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1695 | /*PrevDecl=*/nullptr); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1696 | ToNamespace->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1697 | LexicalDC->addDeclInternal(ToNamespace); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1698 | |
| 1699 | // If this is an anonymous namespace, register it as the anonymous |
| 1700 | // namespace within its context. |
| 1701 | if (!Name) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1702 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1703 | TU->setAnonymousNamespace(ToNamespace); |
| 1704 | else |
| 1705 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 1706 | } |
| 1707 | } |
| 1708 | Importer.Imported(D, ToNamespace); |
| 1709 | |
| 1710 | ImportDeclContext(D); |
| 1711 | |
| 1712 | return ToNamespace; |
| 1713 | } |
| 1714 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1715 | Decl *ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| 1716 | // Import the major distinguishing characteristics of this namespace. |
| 1717 | DeclContext *DC, *LexicalDC; |
| 1718 | DeclarationName Name; |
| 1719 | SourceLocation Loc; |
| 1720 | NamedDecl *LookupD; |
| 1721 | if (ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 1722 | return nullptr; |
| 1723 | if (LookupD) |
| 1724 | return LookupD; |
| 1725 | |
| 1726 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 1727 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1728 | auto *TargetDecl = cast_or_null<NamespaceDecl>( |
| 1729 | Importer.Import(D->getNamespace())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1730 | if (!TargetDecl) |
| 1731 | return nullptr; |
| 1732 | |
| 1733 | IdentifierInfo *ToII = Importer.Import(D->getIdentifier()); |
| 1734 | if (!ToII) |
| 1735 | return nullptr; |
| 1736 | |
| 1737 | NestedNameSpecifierLoc ToQLoc = Importer.Import(D->getQualifierLoc()); |
| 1738 | if (D->getQualifierLoc() && !ToQLoc) |
| 1739 | return nullptr; |
| 1740 | |
| 1741 | NamespaceAliasDecl *ToD = NamespaceAliasDecl::Create( |
| 1742 | Importer.getToContext(), DC, Importer.Import(D->getNamespaceLoc()), |
| 1743 | Importer.Import(D->getAliasLoc()), ToII, ToQLoc, |
| 1744 | Importer.Import(D->getTargetNameLoc()), TargetDecl); |
| 1745 | |
| 1746 | ToD->setLexicalDeclContext(LexicalDC); |
| 1747 | Importer.Imported(D, ToD); |
| 1748 | LexicalDC->addDeclInternal(ToD); |
| 1749 | |
| 1750 | return ToD; |
| 1751 | } |
| 1752 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1753 | Decl *ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1754 | // Import the major distinguishing characteristics of this typedef. |
| 1755 | DeclContext *DC, *LexicalDC; |
| 1756 | DeclarationName Name; |
| 1757 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1758 | NamedDecl *ToD; |
| 1759 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1760 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1761 | if (ToD) |
| 1762 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1763 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1764 | // If this typedef is not in block scope, determine whether we've |
| 1765 | // seen a typedef with the same name (that we can merge with) or any |
| 1766 | // other entity by that name (which name lookup could conflict with). |
| 1767 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1768 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1769 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1770 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1771 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1772 | for (auto *FoundDecl : FoundDecls) { |
| 1773 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1774 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1775 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1776 | if (Importer.IsStructurallyEquivalent(D->getUnderlyingType(), |
| 1777 | FoundTypedef->getUnderlyingType())) |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1778 | return Importer.Imported(D, FoundTypedef); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1779 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1780 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1781 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1782 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1783 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1784 | if (!ConflictingDecls.empty()) { |
| 1785 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1786 | ConflictingDecls.data(), |
| 1787 | ConflictingDecls.size()); |
| 1788 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1789 | return nullptr; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1790 | } |
| 1791 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1792 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1793 | // Import the underlying type of this typedef; |
| 1794 | QualType T = Importer.Import(D->getUnderlyingType()); |
| 1795 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1796 | return nullptr; |
| 1797 | |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1798 | // Some nodes (like anonymous tags referred by typedefs) are allowed to |
| 1799 | // import their enclosing typedef directly. Check if this is the case. |
| 1800 | if (Decl *AlreadyImported = Importer.GetAlreadyImportedOrNull(D)) |
| 1801 | return AlreadyImported; |
| 1802 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1803 | // Create the new typedef node. |
| 1804 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 1805 | SourceLocation StartL = Importer.Import(D->getLocStart()); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1806 | TypedefNameDecl *ToTypedef; |
| 1807 | if (IsAlias) |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1808 | ToTypedef = TypeAliasDecl::Create(Importer.getToContext(), DC, StartL, Loc, |
| 1809 | Name.getAsIdentifierInfo(), TInfo); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 1810 | else |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1811 | ToTypedef = TypedefDecl::Create(Importer.getToContext(), DC, |
| 1812 | StartL, Loc, |
| 1813 | Name.getAsIdentifierInfo(), |
| 1814 | TInfo); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1815 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1816 | ToTypedef->setAccess(D->getAccess()); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1817 | ToTypedef->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1818 | Importer.Imported(D, ToTypedef); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1819 | |
| 1820 | // Templated declarations should not appear in DeclContext. |
| 1821 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 1822 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 1823 | LexicalDC->addDeclInternal(ToTypedef); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1824 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1825 | return ToTypedef; |
| 1826 | } |
| 1827 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1828 | Decl *ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
| 1829 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 1830 | } |
| 1831 | |
| 1832 | Decl *ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| 1833 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 1834 | } |
| 1835 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1836 | Decl *ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| 1837 | // Import the major distinguishing characteristics of this typedef. |
| 1838 | DeclContext *DC, *LexicalDC; |
| 1839 | DeclarationName Name; |
| 1840 | SourceLocation Loc; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1841 | NamedDecl *FoundD; |
| 1842 | if (ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1843 | return nullptr; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1844 | if (FoundD) |
| 1845 | return FoundD; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1846 | |
| 1847 | // If this typedef is not in block scope, determine whether we've |
| 1848 | // seen a typedef with the same name (that we can merge with) or any |
| 1849 | // other entity by that name (which name lookup could conflict with). |
| 1850 | if (!DC->isFunctionOrMethod()) { |
| 1851 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 1852 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 1853 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 1854 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1855 | for (auto *FoundDecl : FoundDecls) { |
| 1856 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1857 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1858 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1859 | return Importer.Imported(D, FoundAlias); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1860 | ConflictingDecls.push_back(FoundDecl); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | if (!ConflictingDecls.empty()) { |
| 1864 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1865 | ConflictingDecls.data(), |
| 1866 | ConflictingDecls.size()); |
| 1867 | if (!Name) |
| 1868 | return nullptr; |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | TemplateParameterList *Params = ImportTemplateParameterList( |
| 1873 | D->getTemplateParameters()); |
| 1874 | if (!Params) |
| 1875 | return nullptr; |
| 1876 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1877 | auto *TemplDecl = cast_or_null<TypeAliasDecl>( |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1878 | Importer.Import(D->getTemplatedDecl())); |
| 1879 | if (!TemplDecl) |
| 1880 | return nullptr; |
| 1881 | |
| 1882 | TypeAliasTemplateDecl *ToAlias = TypeAliasTemplateDecl::Create( |
| 1883 | Importer.getToContext(), DC, Loc, Name, Params, TemplDecl); |
| 1884 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1885 | TemplDecl->setDescribedAliasTemplate(ToAlias); |
| 1886 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1887 | ToAlias->setAccess(D->getAccess()); |
| 1888 | ToAlias->setLexicalDeclContext(LexicalDC); |
| 1889 | Importer.Imported(D, ToAlias); |
| 1890 | LexicalDC->addDeclInternal(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1891 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1892 | } |
| 1893 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1894 | Decl *ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
| 1895 | // Import the major distinguishing characteristics of this label. |
| 1896 | DeclContext *DC, *LexicalDC; |
| 1897 | DeclarationName Name; |
| 1898 | SourceLocation Loc; |
| 1899 | NamedDecl *ToD; |
| 1900 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 1901 | return nullptr; |
| 1902 | if (ToD) |
| 1903 | return ToD; |
| 1904 | |
| 1905 | assert(LexicalDC->isFunctionOrMethod()); |
| 1906 | |
| 1907 | LabelDecl *ToLabel = D->isGnuLocal() |
| 1908 | ? LabelDecl::Create(Importer.getToContext(), |
| 1909 | DC, Importer.Import(D->getLocation()), |
| 1910 | Name.getAsIdentifierInfo(), |
| 1911 | Importer.Import(D->getLocStart())) |
| 1912 | : LabelDecl::Create(Importer.getToContext(), |
| 1913 | DC, Importer.Import(D->getLocation()), |
| 1914 | Name.getAsIdentifierInfo()); |
| 1915 | Importer.Imported(D, ToLabel); |
| 1916 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1917 | auto *Label = cast_or_null<LabelStmt>(Importer.Import(D->getStmt())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1918 | if (!Label) |
| 1919 | return nullptr; |
| 1920 | |
| 1921 | ToLabel->setStmt(Label); |
| 1922 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 1923 | LexicalDC->addDeclInternal(ToLabel); |
| 1924 | return ToLabel; |
| 1925 | } |
| 1926 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1927 | Decl *ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
| 1928 | // Import the major distinguishing characteristics of this enum. |
| 1929 | DeclContext *DC, *LexicalDC; |
| 1930 | DeclarationName Name; |
| 1931 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1932 | NamedDecl *ToD; |
| 1933 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1934 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1935 | if (ToD) |
| 1936 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1937 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1938 | // Figure out what enum name we're looking for. |
| 1939 | unsigned IDNS = Decl::IDNS_Tag; |
| 1940 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1941 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 1942 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1943 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1944 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1945 | IDNS |= Decl::IDNS_Ordinary; |
| 1946 | |
| 1947 | // We may already have an enum of the same name; try to find and match it. |
| 1948 | if (!DC->isFunctionOrMethod() && SearchName) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1949 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1950 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 1951 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1952 | for (auto *FoundDecl : FoundDecls) { |
| 1953 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1954 | continue; |
| 1955 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1956 | Decl *Found = FoundDecl; |
| 1957 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 1958 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1959 | Found = Tag->getDecl(); |
| 1960 | } |
| 1961 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1962 | if (auto *FoundEnum = dyn_cast<EnumDecl>(Found)) { |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1963 | if (IsStructuralMatch(D, FoundEnum)) |
| 1964 | return Importer.Imported(D, FoundEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1965 | } |
| 1966 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1967 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | if (!ConflictingDecls.empty()) { |
| 1971 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1972 | ConflictingDecls.data(), |
| 1973 | ConflictingDecls.size()); |
| 1974 | } |
| 1975 | } |
| 1976 | |
| 1977 | // Create the enum declaration. |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 1978 | EnumDecl *D2 = EnumDecl::Create(Importer.getToContext(), DC, |
| 1979 | Importer.Import(D->getLocStart()), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1980 | Loc, Name.getAsIdentifierInfo(), nullptr, |
Abramo Bagnara | 0e05e24 | 2010-12-03 18:54:17 +0000 | [diff] [blame] | 1981 | D->isScoped(), D->isScopedUsingClassTag(), |
| 1982 | D->isFixed()); |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 1983 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 1984 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1985 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1986 | D2->setLexicalDeclContext(LexicalDC); |
| 1987 | Importer.Imported(D, D2); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1988 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1989 | |
| 1990 | // Import the integer type. |
| 1991 | QualType ToIntegerType = Importer.Import(D->getIntegerType()); |
| 1992 | if (ToIntegerType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1993 | return nullptr; |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1994 | D2->setIntegerType(ToIntegerType); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1995 | |
| 1996 | // Import the definition |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 1997 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1998 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1999 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2000 | return D2; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2001 | } |
| 2002 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2003 | Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
| 2004 | // If this record has a definition in the translation unit we're coming from, |
| 2005 | // but this particular declaration is not that definition, import the |
| 2006 | // definition and map to that. |
Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 2007 | TagDecl *Definition = D->getDefinition(); |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2008 | if (Definition && Definition != D && |
| 2009 | // In contrast to a normal CXXRecordDecl, the implicit |
| 2010 | // CXXRecordDecl of ClassTemplateSpecializationDecl is its redeclaration. |
| 2011 | // The definition of the implicit CXXRecordDecl in this case is the |
| 2012 | // ClassTemplateSpecializationDecl itself. Thus, we start with an extra |
| 2013 | // condition in order to be able to import the implict Decl. |
| 2014 | !D->isImplicit()) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2015 | Decl *ImportedDef = Importer.Import(Definition); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2016 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2017 | return nullptr; |
| 2018 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2019 | return Importer.Imported(D, ImportedDef); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2020 | } |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2021 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2022 | // Import the major distinguishing characteristics of this record. |
| 2023 | DeclContext *DC, *LexicalDC; |
| 2024 | DeclarationName Name; |
| 2025 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2026 | NamedDecl *ToD; |
| 2027 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2028 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2029 | if (ToD) |
| 2030 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2031 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2032 | // Figure out what structure name we're looking for. |
| 2033 | unsigned IDNS = Decl::IDNS_Tag; |
| 2034 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2035 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 2036 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2037 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2038 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2039 | IDNS |= Decl::IDNS_Ordinary; |
| 2040 | |
| 2041 | // 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] | 2042 | RecordDecl *AdoptDecl = nullptr; |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2043 | RecordDecl *PrevDecl = nullptr; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2044 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2045 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2046 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 2047 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2048 | |
| 2049 | if (!FoundDecls.empty()) { |
| 2050 | // We're going to have to compare D against potentially conflicting Decls, so complete it. |
| 2051 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2052 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2053 | } |
| 2054 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2055 | for (auto *FoundDecl : FoundDecls) { |
| 2056 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2057 | continue; |
| 2058 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2059 | Decl *Found = FoundDecl; |
| 2060 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2061 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2062 | Found = Tag->getDecl(); |
| 2063 | } |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2064 | |
| 2065 | if (D->getDescribedTemplate()) { |
| 2066 | if (auto *Template = dyn_cast<ClassTemplateDecl>(Found)) |
| 2067 | Found = Template->getTemplatedDecl(); |
| 2068 | else |
| 2069 | continue; |
| 2070 | } |
| 2071 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2072 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
Aleksei Sidorin | 499de6c | 2018-04-05 15:31:49 +0000 | [diff] [blame] | 2073 | if (!SearchName) { |
| 2074 | // If both unnamed structs/unions are in a record context, make sure |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2075 | // they occur in the same location in the context records. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2076 | if (Optional<unsigned> Index1 = |
| 2077 | StructuralEquivalenceContext::findUntaggedStructOrUnionIndex( |
| 2078 | D)) { |
| 2079 | if (Optional<unsigned> Index2 = StructuralEquivalenceContext:: |
Sean Callanan | 488f861 | 2016-07-14 19:53:44 +0000 | [diff] [blame] | 2080 | findUntaggedStructOrUnionIndex(FoundRecord)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2081 | if (*Index1 != *Index2) |
| 2082 | continue; |
| 2083 | } |
| 2084 | } |
| 2085 | } |
| 2086 | |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2087 | PrevDecl = FoundRecord; |
| 2088 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2089 | if (RecordDecl *FoundDef = FoundRecord->getDefinition()) { |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2090 | if ((SearchName && !D->isCompleteDefinition()) |
| 2091 | || (D->isCompleteDefinition() && |
| 2092 | D->isAnonymousStructOrUnion() |
| 2093 | == FoundDef->isAnonymousStructOrUnion() && |
| 2094 | IsStructuralMatch(D, FoundDef))) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2095 | // The record types structurally match, or the "from" translation |
| 2096 | // unit only had a forward declaration anyway; call it the same |
| 2097 | // function. |
| 2098 | // FIXME: For C++, we should also merge methods here. |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2099 | return Importer.Imported(D, FoundDef); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2100 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2101 | } else if (!D->isCompleteDefinition()) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2102 | // We have a forward declaration of this type, so adopt that forward |
| 2103 | // declaration rather than building a new one. |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2104 | |
| 2105 | // If one or both can be completed from external storage then try one |
| 2106 | // last time to complete and compare them before doing this. |
| 2107 | |
| 2108 | if (FoundRecord->hasExternalLexicalStorage() && |
| 2109 | !FoundRecord->isCompleteDefinition()) |
| 2110 | FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord); |
| 2111 | if (D->hasExternalLexicalStorage()) |
| 2112 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2113 | |
| 2114 | if (FoundRecord->isCompleteDefinition() && |
| 2115 | D->isCompleteDefinition() && |
| 2116 | !IsStructuralMatch(D, FoundRecord)) |
| 2117 | continue; |
| 2118 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2119 | AdoptDecl = FoundRecord; |
| 2120 | continue; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2121 | } else if (!SearchName) { |
| 2122 | continue; |
| 2123 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2124 | } |
| 2125 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2126 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2127 | } |
| 2128 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2129 | if (!ConflictingDecls.empty() && SearchName) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2130 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2131 | ConflictingDecls.data(), |
| 2132 | ConflictingDecls.size()); |
| 2133 | } |
| 2134 | } |
| 2135 | |
| 2136 | // Create the record declaration. |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2137 | RecordDecl *D2 = AdoptDecl; |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 2138 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2139 | if (!D2) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2140 | CXXRecordDecl *D2CXX = nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2141 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2142 | if (DCXX->isLambda()) { |
| 2143 | TypeSourceInfo *TInfo = Importer.Import(DCXX->getLambdaTypeInfo()); |
| 2144 | D2CXX = CXXRecordDecl::CreateLambda(Importer.getToContext(), |
| 2145 | DC, TInfo, Loc, |
| 2146 | DCXX->isDependentLambda(), |
| 2147 | DCXX->isGenericLambda(), |
| 2148 | DCXX->getLambdaCaptureDefault()); |
| 2149 | Decl *CDecl = Importer.Import(DCXX->getLambdaContextDecl()); |
| 2150 | if (DCXX->getLambdaContextDecl() && !CDecl) |
| 2151 | return nullptr; |
Sean Callanan | 041cceb | 2016-05-14 05:43:57 +0000 | [diff] [blame] | 2152 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), CDecl); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2153 | } else if (DCXX->isInjectedClassName()) { |
| 2154 | // We have to be careful to do a similar dance to the one in |
| 2155 | // Sema::ActOnStartCXXMemberDeclarations |
| 2156 | CXXRecordDecl *const PrevDecl = nullptr; |
| 2157 | const bool DelayTypeCreation = true; |
| 2158 | D2CXX = CXXRecordDecl::Create( |
| 2159 | Importer.getToContext(), D->getTagKind(), DC, StartLoc, Loc, |
| 2160 | Name.getAsIdentifierInfo(), PrevDecl, DelayTypeCreation); |
| 2161 | Importer.getToContext().getTypeDeclType( |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2162 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2163 | } else { |
| 2164 | D2CXX = CXXRecordDecl::Create(Importer.getToContext(), |
| 2165 | D->getTagKind(), |
| 2166 | DC, StartLoc, Loc, |
| 2167 | Name.getAsIdentifierInfo()); |
| 2168 | } |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2169 | D2 = D2CXX; |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2170 | D2->setAccess(D->getAccess()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2171 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | de8bf26 | 2018-05-17 09:46:07 +0000 | [diff] [blame] | 2172 | if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit()) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2173 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2174 | |
| 2175 | Importer.Imported(D, D2); |
| 2176 | |
| 2177 | if (ClassTemplateDecl *FromDescribed = |
| 2178 | DCXX->getDescribedClassTemplate()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2179 | auto *ToDescribed = cast_or_null<ClassTemplateDecl>( |
| 2180 | Importer.Import(FromDescribed)); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2181 | if (!ToDescribed) |
| 2182 | return nullptr; |
| 2183 | D2CXX->setDescribedClassTemplate(ToDescribed); |
Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2184 | if (!DCXX->isInjectedClassName()) { |
| 2185 | // In a record describing a template the type should be an |
| 2186 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the |
| 2187 | // previously set type to the correct value here (ToDescribed is not |
| 2188 | // available at record create). |
| 2189 | // FIXME: The previous type is cleared but not removed from |
| 2190 | // ASTContext's internal storage. |
| 2191 | CXXRecordDecl *Injected = nullptr; |
| 2192 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { |
| 2193 | auto *Record = dyn_cast<CXXRecordDecl>(Found); |
| 2194 | if (Record && Record->isInjectedClassName()) { |
| 2195 | Injected = Record; |
| 2196 | break; |
| 2197 | } |
| 2198 | } |
| 2199 | D2CXX->setTypeForDecl(nullptr); |
| 2200 | Importer.getToContext().getInjectedClassNameType(D2CXX, |
| 2201 | ToDescribed->getInjectedClassNameSpecialization()); |
| 2202 | if (Injected) { |
| 2203 | Injected->setTypeForDecl(nullptr); |
| 2204 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); |
| 2205 | } |
| 2206 | } |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2207 | } else if (MemberSpecializationInfo *MemberInfo = |
| 2208 | DCXX->getMemberSpecializationInfo()) { |
| 2209 | TemplateSpecializationKind SK = |
| 2210 | MemberInfo->getTemplateSpecializationKind(); |
| 2211 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2212 | auto *ToInst = |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2213 | cast_or_null<CXXRecordDecl>(Importer.Import(FromInst)); |
| 2214 | if (FromInst && !ToInst) |
| 2215 | return nullptr; |
| 2216 | D2CXX->setInstantiationOfMemberClass(ToInst, SK); |
| 2217 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2218 | Importer.Import(MemberInfo->getPointOfInstantiation())); |
| 2219 | } |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2220 | } else { |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2221 | D2 = RecordDecl::Create(Importer.getToContext(), D->getTagKind(), |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 2222 | DC, StartLoc, Loc, Name.getAsIdentifierInfo()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2223 | D2->setLexicalDeclContext(LexicalDC); |
| 2224 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2225 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2226 | |
| 2227 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2228 | if (D->isAnonymousStructOrUnion()) |
| 2229 | D2->setAnonymousStructOrUnion(true); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2230 | if (PrevDecl) { |
| 2231 | // FIXME: do this for all Redeclarables, not just RecordDecls. |
| 2232 | D2->setPreviousDecl(PrevDecl); |
| 2233 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2234 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2235 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2236 | Importer.Imported(D, D2); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2237 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 2238 | if (D->isCompleteDefinition() && ImportDefinition(D, D2, IDK_Default)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2239 | return nullptr; |
| 2240 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2241 | return D2; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2242 | } |
| 2243 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2244 | Decl *ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| 2245 | // Import the major distinguishing characteristics of this enumerator. |
| 2246 | DeclContext *DC, *LexicalDC; |
| 2247 | DeclarationName Name; |
| 2248 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2249 | NamedDecl *ToD; |
| 2250 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2251 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2252 | if (ToD) |
| 2253 | return ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2254 | |
| 2255 | QualType T = Importer.Import(D->getType()); |
| 2256 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2257 | return nullptr; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2258 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2259 | // Determine whether there are any other declarations with the same name and |
| 2260 | // in the same context. |
| 2261 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2262 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2263 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2264 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2265 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2266 | for (auto *FoundDecl : FoundDecls) { |
| 2267 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2268 | continue; |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2269 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2270 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2271 | if (IsStructuralMatch(D, FoundEnumConstant)) |
| 2272 | return Importer.Imported(D, FoundEnumConstant); |
| 2273 | } |
| 2274 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2275 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | if (!ConflictingDecls.empty()) { |
| 2279 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2280 | ConflictingDecls.data(), |
| 2281 | ConflictingDecls.size()); |
| 2282 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2283 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2284 | } |
| 2285 | } |
| 2286 | |
| 2287 | Expr *Init = Importer.Import(D->getInitExpr()); |
| 2288 | if (D->getInitExpr() && !Init) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2289 | return nullptr; |
| 2290 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2291 | EnumConstantDecl *ToEnumerator |
| 2292 | = EnumConstantDecl::Create(Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
| 2293 | Name.getAsIdentifierInfo(), T, |
| 2294 | Init, D->getInitVal()); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2295 | ToEnumerator->setAccess(D->getAccess()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2296 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2297 | Importer.Imported(D, ToEnumerator); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2298 | LexicalDC->addDeclInternal(ToEnumerator); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2299 | return ToEnumerator; |
| 2300 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2301 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2302 | bool ASTNodeImporter::ImportTemplateInformation(FunctionDecl *FromFD, |
| 2303 | FunctionDecl *ToFD) { |
| 2304 | switch (FromFD->getTemplatedKind()) { |
| 2305 | case FunctionDecl::TK_NonTemplate: |
| 2306 | case FunctionDecl::TK_FunctionTemplate: |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2307 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2308 | |
| 2309 | case FunctionDecl::TK_MemberSpecialization: { |
| 2310 | auto *InstFD = cast_or_null<FunctionDecl>( |
| 2311 | Importer.Import(FromFD->getInstantiatedFromMemberFunction())); |
| 2312 | if (!InstFD) |
| 2313 | return true; |
| 2314 | |
| 2315 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
| 2316 | SourceLocation POI = Importer.Import( |
| 2317 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation()); |
| 2318 | ToFD->setInstantiationOfMemberFunction(InstFD, TSK); |
| 2319 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2320 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2324 | FunctionTemplateDecl* Template; |
| 2325 | OptionalTemplateArgsTy ToTemplArgs; |
| 2326 | std::tie(Template, ToTemplArgs) = |
| 2327 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| 2328 | if (!Template || !ToTemplArgs) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2329 | return true; |
| 2330 | |
| 2331 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2332 | Importer.getToContext(), *ToTemplArgs); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2333 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2334 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2335 | TemplateArgumentListInfo ToTAInfo; |
| 2336 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2337 | if (FromTAArgsAsWritten) |
| 2338 | if (ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2339 | return true; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2340 | |
| 2341 | SourceLocation POI = Importer.Import(FTSInfo->getPointOfInstantiation()); |
| 2342 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2343 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2344 | ToFD->setFunctionTemplateSpecialization( |
| 2345 | Template, ToTAList, /* InsertPos= */ nullptr, |
| 2346 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, POI); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2347 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2348 | } |
| 2349 | |
| 2350 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 2351 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 2352 | UnresolvedSet<8> TemplDecls; |
| 2353 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 2354 | for (unsigned I = 0; I < NumTemplates; I++) { |
| 2355 | if (auto *ToFTD = cast_or_null<FunctionTemplateDecl>( |
| 2356 | Importer.Import(FromInfo->getTemplate(I)))) |
| 2357 | TemplDecls.addDecl(ToFTD); |
| 2358 | else |
| 2359 | return true; |
| 2360 | } |
| 2361 | |
| 2362 | // Import TemplateArgumentListInfo. |
| 2363 | TemplateArgumentListInfo ToTAInfo; |
| 2364 | if (ImportTemplateArgumentListInfo( |
| 2365 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 2366 | llvm::makeArrayRef(FromInfo->getTemplateArgs(), |
| 2367 | FromInfo->getNumTemplateArgs()), |
| 2368 | ToTAInfo)) |
| 2369 | return true; |
| 2370 | |
| 2371 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 2372 | TemplDecls, ToTAInfo); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2373 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2374 | } |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2375 | } |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2376 | llvm_unreachable("All cases should be covered!"); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2377 | } |
| 2378 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2379 | FunctionDecl * |
| 2380 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { |
| 2381 | FunctionTemplateDecl* Template; |
| 2382 | OptionalTemplateArgsTy ToTemplArgs; |
| 2383 | std::tie(Template, ToTemplArgs) = |
| 2384 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| 2385 | if (!Template || !ToTemplArgs) |
| 2386 | return nullptr; |
| 2387 | |
| 2388 | void *InsertPos = nullptr; |
| 2389 | auto *FoundSpec = Template->findSpecialization(*ToTemplArgs, InsertPos); |
| 2390 | return FoundSpec; |
| 2391 | } |
| 2392 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2393 | Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2394 | |
| 2395 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| 2396 | auto RedeclIt = Redecls.begin(); |
| 2397 | // Import the first part of the decl chain. I.e. import all previous |
| 2398 | // declarations starting from the canonical decl. |
| 2399 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) |
| 2400 | if (!Importer.Import(*RedeclIt)) |
| 2401 | return nullptr; |
| 2402 | assert(*RedeclIt == D); |
| 2403 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2404 | // Import the major distinguishing characteristics of this function. |
| 2405 | DeclContext *DC, *LexicalDC; |
| 2406 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2407 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2408 | NamedDecl *ToD; |
| 2409 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2410 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2411 | if (ToD) |
| 2412 | return ToD; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2413 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2414 | const FunctionDecl *FoundByLookup = nullptr; |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2415 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2416 | // If this is a function template specialization, then try to find the same |
| 2417 | // existing specialization in the "to" context. The localUncachedLookup |
| 2418 | // below will not find any specialization, but would find the primary |
| 2419 | // template; thus, we have to skip normal lookup in case of specializations. |
| 2420 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? |
| 2421 | if (D->getTemplatedKind() == |
| 2422 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
| 2423 | if (FunctionDecl *FoundFunction = FindFunctionTemplateSpecialization(D)) { |
| 2424 | if (D->doesThisDeclarationHaveABody() && |
| 2425 | FoundFunction->hasBody()) |
| 2426 | return Importer.Imported(D, FoundFunction); |
| 2427 | FoundByLookup = FoundFunction; |
| 2428 | } |
| 2429 | } |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2430 | // Try to find a function in our own ("to") context with the same name, same |
| 2431 | // type, and in the same context as the function we're importing. |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2432 | else if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2433 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2434 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2435 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2436 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2437 | for (auto *FoundDecl : FoundDecls) { |
| 2438 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2439 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2440 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2441 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 2442 | if (FoundFunction->hasExternalFormalLinkage() && |
| 2443 | D->hasExternalFormalLinkage()) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2444 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| 2445 | FoundFunction->getType())) { |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2446 | if (D->doesThisDeclarationHaveABody() && |
| 2447 | FoundFunction->hasBody()) |
| 2448 | return Importer.Imported(D, FoundFunction); |
| 2449 | FoundByLookup = FoundFunction; |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2450 | break; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2451 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2452 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2453 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 2454 | // Sema::IsOverload out to the AST library. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2455 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2456 | // Function overloading is okay in C++. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2457 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2458 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2459 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2460 | // Complain about inconsistent function types. |
| 2461 | Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2462 | << Name << D->getType() << FoundFunction->getType(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2463 | Importer.ToDiag(FoundFunction->getLocation(), |
| 2464 | diag::note_odr_value_here) |
| 2465 | << FoundFunction->getType(); |
| 2466 | } |
| 2467 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2468 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2469 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2470 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2471 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2472 | if (!ConflictingDecls.empty()) { |
| 2473 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2474 | ConflictingDecls.data(), |
| 2475 | ConflictingDecls.size()); |
| 2476 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2477 | return nullptr; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2478 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2479 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2480 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2481 | DeclarationNameInfo NameInfo(Name, Loc); |
| 2482 | // Import additional name location/type info. |
| 2483 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 2484 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2485 | QualType FromTy = D->getType(); |
| 2486 | bool usedDifferentExceptionSpec = false; |
| 2487 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2488 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2489 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 2490 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 2491 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 2492 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 2493 | // with a simplified function type and update it afterwards. |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 2494 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 2495 | FromEPI.ExceptionSpec.SourceTemplate || |
| 2496 | FromEPI.ExceptionSpec.NoexceptExpr) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2497 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 2498 | FromTy = Importer.getFromContext().getFunctionType( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2499 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2500 | usedDifferentExceptionSpec = true; |
| 2501 | } |
| 2502 | } |
| 2503 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2504 | // Import the type. |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2505 | QualType T = Importer.Import(FromTy); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2506 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2507 | return nullptr; |
| 2508 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2509 | // Import the function parameters. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2510 | SmallVector<ParmVarDecl *, 8> Parameters; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2511 | for (auto P : D->parameters()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2512 | auto *ToP = cast_or_null<ParmVarDecl>(Importer.Import(P)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2513 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2514 | return nullptr; |
| 2515 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2516 | Parameters.push_back(ToP); |
| 2517 | } |
| 2518 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2519 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2520 | if (D->getTypeSourceInfo() && !TInfo) |
| 2521 | return nullptr; |
| 2522 | |
| 2523 | // Create the imported function. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2524 | FunctionDecl *ToFunction = nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2525 | SourceLocation InnerLocStart = Importer.Import(D->getInnerLocStart()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2526 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2527 | ToFunction = CXXConstructorDecl::Create(Importer.getToContext(), |
| 2528 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2529 | InnerLocStart, |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2530 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2531 | FromConstructor->isExplicit(), |
| 2532 | D->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2533 | D->isImplicit(), |
| 2534 | D->isConstexpr()); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2535 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 2536 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2537 | for (auto *I : FromConstructor->inits()) { |
| 2538 | auto *ToI = cast_or_null<CXXCtorInitializer>(Importer.Import(I)); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2539 | if (!ToI && I) |
| 2540 | return nullptr; |
| 2541 | CtorInitializers.push_back(ToI); |
| 2542 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2543 | auto **Memory = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2544 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 2545 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2546 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2547 | ToCtor->setCtorInitializers(Memory); |
| 2548 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 2549 | } |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2550 | } else if (isa<CXXDestructorDecl>(D)) { |
| 2551 | ToFunction = CXXDestructorDecl::Create(Importer.getToContext(), |
| 2552 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2553 | InnerLocStart, |
Craig Silverstein | af8808d | 2010-10-21 00:44:50 +0000 | [diff] [blame] | 2554 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2555 | D->isInlineSpecified(), |
| 2556 | D->isImplicit()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2557 | } else if (auto *FromConversion = dyn_cast<CXXConversionDecl>(D)) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2558 | ToFunction = CXXConversionDecl::Create(Importer.getToContext(), |
| 2559 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2560 | InnerLocStart, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2561 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2562 | D->isInlineSpecified(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2563 | FromConversion->isExplicit(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2564 | D->isConstexpr(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2565 | Importer.Import(D->getLocEnd())); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2566 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
Douglas Gregor | a50ad13 | 2010-11-29 16:04:58 +0000 | [diff] [blame] | 2567 | ToFunction = CXXMethodDecl::Create(Importer.getToContext(), |
| 2568 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2569 | InnerLocStart, |
Douglas Gregor | a50ad13 | 2010-11-29 16:04:58 +0000 | [diff] [blame] | 2570 | NameInfo, T, TInfo, |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 2571 | Method->getStorageClass(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2572 | Method->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2573 | D->isConstexpr(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2574 | Importer.Import(D->getLocEnd())); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2575 | } else { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2576 | ToFunction = FunctionDecl::Create(Importer.getToContext(), DC, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2577 | InnerLocStart, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2578 | NameInfo, T, TInfo, D->getStorageClass(), |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2579 | D->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2580 | D->hasWrittenPrototype(), |
| 2581 | D->isConstexpr()); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2582 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 2583 | |
| 2584 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2585 | ToFunction->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2586 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2587 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 2588 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 2589 | ToFunction->setTrivial(D->isTrivial()); |
| 2590 | ToFunction->setPure(D->isPure()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2591 | Importer.Imported(D, ToFunction); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2592 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2593 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2594 | for (auto *Param : Parameters) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2595 | Param->setOwningFunction(ToFunction); |
| 2596 | ToFunction->addDeclInternal(Param); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2597 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 2598 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2599 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2600 | if (FoundByLookup) { |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2601 | auto *Recent = const_cast<FunctionDecl *>( |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2602 | FoundByLookup->getMostRecentDecl()); |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2603 | ToFunction->setPreviousDecl(Recent); |
| 2604 | } |
| 2605 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2606 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 2607 | // params it refers to. |
| 2608 | if (TInfo) { |
| 2609 | if (auto ProtoLoc = |
| 2610 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 2611 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 2612 | ProtoLoc.setParam(I, Parameters[I]); |
| 2613 | } |
| 2614 | } |
| 2615 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2616 | if (usedDifferentExceptionSpec) { |
| 2617 | // Update FunctionProtoType::ExtProtoInfo. |
| 2618 | QualType T = Importer.Import(D->getType()); |
| 2619 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2620 | return nullptr; |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2621 | ToFunction->setType(T); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 2622 | } |
| 2623 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2624 | if (D->doesThisDeclarationHaveABody()) { |
| 2625 | if (Stmt *FromBody = D->getBody()) { |
| 2626 | if (Stmt *ToBody = Importer.Import(FromBody)) { |
| 2627 | ToFunction->setBody(ToBody); |
| 2628 | } |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2629 | } |
| 2630 | } |
| 2631 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2632 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2633 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2634 | // If it is a template, import all related things. |
| 2635 | if (ImportTemplateInformation(D, ToFunction)) |
| 2636 | return nullptr; |
| 2637 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2638 | bool IsFriend = D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend); |
| 2639 | |
| 2640 | // TODO Can we generalize this approach to other AST nodes as well? |
| 2641 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 2642 | DC->addDeclInternal(ToFunction); |
| 2643 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2644 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2645 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2646 | // Friend declaration's lexical context is the befriending class, but the |
| 2647 | // semantic context is the enclosing scope of the befriending class. |
| 2648 | // We want the friend functions to be found in the semantic context by lookup. |
| 2649 | // FIXME should we handle this generically in VisitFriendDecl? |
| 2650 | // In Other cases when LexicalDC != DC we don't want it to be added, |
| 2651 | // e.g out-of-class definitions like void B::f() {} . |
| 2652 | if (LexicalDC != DC && IsFriend) { |
| 2653 | DC->makeDeclVisibleInContext(ToFunction); |
| 2654 | } |
| 2655 | |
| 2656 | // Import the rest of the chain. I.e. import all subsequent declarations. |
| 2657 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) |
| 2658 | if (!Importer.Import(*RedeclIt)) |
| 2659 | return nullptr; |
| 2660 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 2661 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 2662 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 2663 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2664 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2665 | } |
| 2666 | |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2667 | Decl *ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| 2668 | return VisitFunctionDecl(D); |
| 2669 | } |
| 2670 | |
| 2671 | Decl *ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| 2672 | return VisitCXXMethodDecl(D); |
| 2673 | } |
| 2674 | |
| 2675 | Decl *ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| 2676 | return VisitCXXMethodDecl(D); |
| 2677 | } |
| 2678 | |
| 2679 | Decl *ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| 2680 | return VisitCXXMethodDecl(D); |
| 2681 | } |
| 2682 | |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2683 | static unsigned getFieldIndex(Decl *F) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2684 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2685 | if (!Owner) |
| 2686 | return 0; |
| 2687 | |
| 2688 | unsigned Index = 1; |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2689 | for (const auto *D : Owner->noload_decls()) { |
| 2690 | if (D == F) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2691 | return Index; |
| 2692 | |
| 2693 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 2694 | ++Index; |
| 2695 | } |
| 2696 | |
| 2697 | return Index; |
| 2698 | } |
| 2699 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2700 | Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
| 2701 | // Import the major distinguishing characteristics of a variable. |
| 2702 | DeclContext *DC, *LexicalDC; |
| 2703 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2704 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2705 | NamedDecl *ToD; |
| 2706 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2707 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2708 | if (ToD) |
| 2709 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2710 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2711 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2712 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2713 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2714 | for (auto *FoundDecl : FoundDecls) { |
| 2715 | if (auto *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2716 | // For anonymous fields, match up by index. |
| 2717 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2718 | continue; |
| 2719 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2720 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2721 | FoundField->getType())) { |
| 2722 | Importer.Imported(D, FoundField); |
| 2723 | return FoundField; |
| 2724 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2725 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2726 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2727 | << Name << D->getType() << FoundField->getType(); |
| 2728 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2729 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2730 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2731 | } |
| 2732 | } |
| 2733 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2734 | // Import the type. |
| 2735 | QualType T = Importer.Import(D->getType()); |
| 2736 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2737 | return nullptr; |
| 2738 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2739 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2740 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 2741 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2742 | return nullptr; |
| 2743 | |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2744 | FieldDecl *ToField = FieldDecl::Create(Importer.getToContext(), DC, |
| 2745 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2746 | Loc, Name.getAsIdentifierInfo(), |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2747 | T, TInfo, BitWidth, D->isMutable(), |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2748 | D->getInClassInitStyle()); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2749 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2750 | ToField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 3a83ea7 | 2016-03-03 02:22:05 +0000 | [diff] [blame] | 2751 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
Sean Callanan | bb33f58 | 2016-03-03 01:21:28 +0000 | [diff] [blame] | 2752 | Expr *ToInitializer = Importer.Import(FromInitializer); |
| 2753 | if (ToInitializer) |
| 2754 | ToField->setInClassInitializer(ToInitializer); |
| 2755 | else |
| 2756 | return nullptr; |
| 2757 | } |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2758 | ToField->setImplicit(D->isImplicit()); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2759 | Importer.Imported(D, ToField); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2760 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2761 | return ToField; |
| 2762 | } |
| 2763 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2764 | Decl *ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| 2765 | // Import the major distinguishing characteristics of a variable. |
| 2766 | DeclContext *DC, *LexicalDC; |
| 2767 | DeclarationName Name; |
| 2768 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2769 | NamedDecl *ToD; |
| 2770 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2771 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2772 | if (ToD) |
| 2773 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2774 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2775 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2776 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2777 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2778 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2779 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2780 | // For anonymous indirect fields, match up by index. |
| 2781 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2782 | continue; |
| 2783 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2784 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2785 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 2786 | !Name.isEmpty())) { |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2787 | Importer.Imported(D, FoundField); |
| 2788 | return FoundField; |
| 2789 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2790 | |
| 2791 | // If there are more anonymous fields to check, continue. |
| 2792 | if (!Name && I < N-1) |
| 2793 | continue; |
| 2794 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2795 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2796 | << Name << D->getType() << FoundField->getType(); |
| 2797 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2798 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2799 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2800 | } |
| 2801 | } |
| 2802 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2803 | // Import the type. |
| 2804 | QualType T = Importer.Import(D->getType()); |
| 2805 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2806 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2807 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2808 | auto **NamedChain = |
| 2809 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2810 | |
| 2811 | unsigned i = 0; |
Aaron Ballman | 29c9460 | 2014-03-07 18:36:15 +0000 | [diff] [blame] | 2812 | for (auto *PI : D->chain()) { |
Aaron Ballman | 1391608 | 2014-03-07 18:11:58 +0000 | [diff] [blame] | 2813 | Decl *D = Importer.Import(PI); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2814 | if (!D) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2815 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2816 | NamedChain[i++] = cast<NamedDecl>(D); |
| 2817 | } |
| 2818 | |
| 2819 | IndirectFieldDecl *ToIndirectField = IndirectFieldDecl::Create( |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2820 | Importer.getToContext(), DC, Loc, Name.getAsIdentifierInfo(), T, |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2821 | {NamedChain, D->getChainingSize()}); |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2822 | |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 2823 | for (const auto *A : D->attrs()) |
| 2824 | ToIndirectField->addAttr(Importer.Import(A)); |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2825 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2826 | ToIndirectField->setAccess(D->getAccess()); |
| 2827 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
| 2828 | Importer.Imported(D, ToIndirectField); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2829 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2830 | return ToIndirectField; |
| 2831 | } |
| 2832 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2833 | Decl *ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
| 2834 | // Import the major distinguishing characteristics of a declaration. |
| 2835 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 2836 | DeclContext *LexicalDC = D->getDeclContext() == D->getLexicalDeclContext() |
| 2837 | ? DC : Importer.ImportContext(D->getLexicalDeclContext()); |
| 2838 | if (!DC || !LexicalDC) |
| 2839 | return nullptr; |
| 2840 | |
| 2841 | // Determine whether we've already imported this decl. |
| 2842 | // FriendDecl is not a NamedDecl so we cannot use localUncachedLookup. |
| 2843 | auto *RD = cast<CXXRecordDecl>(DC); |
| 2844 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
| 2845 | StructuralEquivalenceContext Context( |
| 2846 | Importer.getFromContext(), Importer.getToContext(), |
| 2847 | Importer.getNonEquivalentDecls(), false, false); |
| 2848 | |
| 2849 | while (ImportedFriend) { |
| 2850 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
| 2851 | if (Context.IsStructurallyEquivalent(D->getFriendDecl(), |
| 2852 | ImportedFriend->getFriendDecl())) |
| 2853 | return Importer.Imported(D, ImportedFriend); |
| 2854 | |
| 2855 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 2856 | if (Importer.IsStructurallyEquivalent( |
| 2857 | D->getFriendType()->getType(), |
| 2858 | ImportedFriend->getFriendType()->getType(), true)) |
| 2859 | return Importer.Imported(D, ImportedFriend); |
| 2860 | } |
| 2861 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 2862 | } |
| 2863 | |
| 2864 | // Not found. Create it. |
| 2865 | FriendDecl::FriendUnion ToFU; |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 2866 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
| 2867 | auto *ToFriendD = cast_or_null<NamedDecl>(Importer.Import(FriendD)); |
| 2868 | if (ToFriendD && FriendD->getFriendObjectKind() != Decl::FOK_None && |
| 2869 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 2870 | ToFriendD->setObjectOfFriendDecl(false); |
| 2871 | |
| 2872 | ToFU = ToFriendD; |
| 2873 | } else // The friend is a type, not a decl. |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2874 | ToFU = Importer.Import(D->getFriendType()); |
| 2875 | if (!ToFU) |
| 2876 | return nullptr; |
| 2877 | |
| 2878 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2879 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2880 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
| 2881 | TemplateParameterList *List = ImportTemplateParameterList(FromTPLists[I]); |
| 2882 | if (!List) |
| 2883 | return nullptr; |
| 2884 | ToTPLists[I] = List; |
| 2885 | } |
| 2886 | |
| 2887 | FriendDecl *FrD = FriendDecl::Create(Importer.getToContext(), DC, |
| 2888 | Importer.Import(D->getLocation()), |
| 2889 | ToFU, Importer.Import(D->getFriendLoc()), |
| 2890 | ToTPLists); |
| 2891 | |
| 2892 | Importer.Imported(D, FrD); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2893 | |
| 2894 | FrD->setAccess(D->getAccess()); |
| 2895 | FrD->setLexicalDeclContext(LexicalDC); |
| 2896 | LexicalDC->addDeclInternal(FrD); |
| 2897 | return FrD; |
| 2898 | } |
| 2899 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2900 | Decl *ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| 2901 | // Import the major distinguishing characteristics of an ivar. |
| 2902 | DeclContext *DC, *LexicalDC; |
| 2903 | DeclarationName Name; |
| 2904 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2905 | NamedDecl *ToD; |
| 2906 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2907 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2908 | if (ToD) |
| 2909 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2910 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2911 | // Determine whether we've already imported this ivar |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2912 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2913 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2914 | for (auto *FoundDecl : FoundDecls) { |
| 2915 | if (auto *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2916 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2917 | FoundIvar->getType())) { |
| 2918 | Importer.Imported(D, FoundIvar); |
| 2919 | return FoundIvar; |
| 2920 | } |
| 2921 | |
| 2922 | Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent) |
| 2923 | << Name << D->getType() << FoundIvar->getType(); |
| 2924 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 2925 | << FoundIvar->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2926 | return nullptr; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2927 | } |
| 2928 | } |
| 2929 | |
| 2930 | // Import the type. |
| 2931 | QualType T = Importer.Import(D->getType()); |
| 2932 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2933 | return nullptr; |
| 2934 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2935 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2936 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 2937 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2938 | return nullptr; |
| 2939 | |
Daniel Dunbar | fe3ead7 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 2940 | ObjCIvarDecl *ToIvar = ObjCIvarDecl::Create(Importer.getToContext(), |
| 2941 | cast<ObjCContainerDecl>(DC), |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2942 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2943 | Loc, Name.getAsIdentifierInfo(), |
| 2944 | T, TInfo, D->getAccessControl(), |
Argyrios Kyrtzidis | 2080d90 | 2014-01-03 18:32:18 +0000 | [diff] [blame] | 2945 | BitWidth, D->getSynthesize()); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2946 | ToIvar->setLexicalDeclContext(LexicalDC); |
| 2947 | Importer.Imported(D, ToIvar); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2948 | LexicalDC->addDeclInternal(ToIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2949 | return ToIvar; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2950 | } |
| 2951 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2952 | Decl *ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
| 2953 | // Import the major distinguishing characteristics of a variable. |
| 2954 | DeclContext *DC, *LexicalDC; |
| 2955 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2956 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2957 | NamedDecl *ToD; |
| 2958 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2959 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2960 | if (ToD) |
| 2961 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2962 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2963 | // Try to find a variable in our own ("to") context with the same name and |
| 2964 | // in the same context as the variable we're importing. |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2965 | if (D->isFileVarDecl()) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2966 | VarDecl *MergeWithVar = nullptr; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2967 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2968 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2969 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2970 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2971 | for (auto *FoundDecl : FoundDecls) { |
| 2972 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2973 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2974 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2975 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2976 | // 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] | 2977 | if (FoundVar->hasExternalFormalLinkage() && |
| 2978 | D->hasExternalFormalLinkage()) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2979 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2980 | FoundVar->getType())) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2981 | MergeWithVar = FoundVar; |
| 2982 | break; |
| 2983 | } |
| 2984 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2985 | const ArrayType *FoundArray |
| 2986 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 2987 | const ArrayType *TArray |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2988 | = Importer.getToContext().getAsArrayType(D->getType()); |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2989 | if (FoundArray && TArray) { |
| 2990 | if (isa<IncompleteArrayType>(FoundArray) && |
| 2991 | isa<ConstantArrayType>(TArray)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2992 | // Import the type. |
| 2993 | QualType T = Importer.Import(D->getType()); |
| 2994 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2995 | return nullptr; |
| 2996 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2997 | FoundVar->setType(T); |
| 2998 | MergeWithVar = FoundVar; |
| 2999 | break; |
| 3000 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3001 | isa<ConstantArrayType>(FoundArray)) { |
| 3002 | MergeWithVar = FoundVar; |
| 3003 | break; |
Douglas Gregor | 2fbe558 | 2010-02-10 17:16:49 +0000 | [diff] [blame] | 3004 | } |
| 3005 | } |
| 3006 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3007 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3008 | << Name << D->getType() << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3009 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3010 | << FoundVar->getType(); |
| 3011 | } |
| 3012 | } |
| 3013 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3014 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3015 | } |
| 3016 | |
| 3017 | if (MergeWithVar) { |
| 3018 | // An equivalent variable with external linkage has been found. Link |
| 3019 | // the two declarations, then merge them. |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 3020 | Importer.Imported(D, MergeWithVar); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3021 | |
| 3022 | if (VarDecl *DDef = D->getDefinition()) { |
| 3023 | if (VarDecl *ExistingDef = MergeWithVar->getDefinition()) { |
| 3024 | Importer.ToDiag(ExistingDef->getLocation(), |
| 3025 | diag::err_odr_variable_multiple_def) |
| 3026 | << Name; |
| 3027 | Importer.FromDiag(DDef->getLocation(), diag::note_odr_defined_here); |
| 3028 | } else { |
| 3029 | Expr *Init = Importer.Import(DDef->getInit()); |
Douglas Gregor | d505812 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 3030 | MergeWithVar->setInit(Init); |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 3031 | if (DDef->isInitKnownICE()) { |
| 3032 | EvaluatedStmt *Eval = MergeWithVar->ensureEvaluatedStmt(); |
| 3033 | Eval->CheckedICE = true; |
| 3034 | Eval->IsICE = DDef->isInitICE(); |
| 3035 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3036 | } |
| 3037 | } |
| 3038 | |
| 3039 | return MergeWithVar; |
| 3040 | } |
| 3041 | |
| 3042 | if (!ConflictingDecls.empty()) { |
| 3043 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 3044 | ConflictingDecls.data(), |
| 3045 | ConflictingDecls.size()); |
| 3046 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3047 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3048 | } |
| 3049 | } |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 3050 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3051 | // Import the type. |
| 3052 | QualType T = Importer.Import(D->getType()); |
| 3053 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3054 | return nullptr; |
| 3055 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3056 | // Create the imported variable. |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 3057 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 3058 | VarDecl *ToVar = VarDecl::Create(Importer.getToContext(), DC, |
| 3059 | Importer.Import(D->getInnerLocStart()), |
| 3060 | Loc, Name.getAsIdentifierInfo(), |
| 3061 | T, TInfo, |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 3062 | D->getStorageClass()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3063 | ToVar->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3064 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3065 | ToVar->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 3066 | Importer.Imported(D, ToVar); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3067 | |
| 3068 | // Templated declarations should never appear in the enclosing DeclContext. |
| 3069 | if (!D->getDescribedVarTemplate()) |
| 3070 | LexicalDC->addDeclInternal(ToVar); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3071 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3072 | if (!D->isFileVarDecl() && |
| 3073 | D->isUsed()) |
| 3074 | ToVar->setIsUsed(); |
| 3075 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3076 | // Merge the initializer. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3077 | if (ImportDefinition(D, ToVar)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3078 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3079 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3080 | if (D->isConstexpr()) |
| 3081 | ToVar->setConstexpr(true); |
| 3082 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3083 | return ToVar; |
| 3084 | } |
| 3085 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3086 | Decl *ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| 3087 | // Parameters are created in the translation unit's context, then moved |
| 3088 | // into the function declaration's context afterward. |
| 3089 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| 3090 | |
| 3091 | // Import the name of this declaration. |
| 3092 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 3093 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3094 | return nullptr; |
| 3095 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3096 | // Import the location of this declaration. |
| 3097 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 3098 | |
| 3099 | // Import the parameter's type. |
| 3100 | QualType T = Importer.Import(D->getType()); |
| 3101 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3102 | return nullptr; |
| 3103 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3104 | // Create the imported parameter. |
Alexey Bataev | 5622323 | 2017-06-09 13:40:18 +0000 | [diff] [blame] | 3105 | auto *ToParm = ImplicitParamDecl::Create(Importer.getToContext(), DC, Loc, |
| 3106 | Name.getAsIdentifierInfo(), T, |
| 3107 | D->getParameterKind()); |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3108 | return Importer.Imported(D, ToParm); |
| 3109 | } |
| 3110 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3111 | Decl *ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
| 3112 | // Parameters are created in the translation unit's context, then moved |
| 3113 | // into the function declaration's context afterward. |
| 3114 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| 3115 | |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 3116 | // Import the name of this declaration. |
| 3117 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 3118 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3119 | return nullptr; |
| 3120 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3121 | // Import the location of this declaration. |
| 3122 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 3123 | |
| 3124 | // Import the parameter's type. |
| 3125 | QualType T = Importer.Import(D->getType()); |
| 3126 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3127 | return nullptr; |
| 3128 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3129 | // Create the imported parameter. |
| 3130 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3131 | ParmVarDecl *ToParm = ParmVarDecl::Create(Importer.getToContext(), DC, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 3132 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3133 | Loc, Name.getAsIdentifierInfo(), |
| 3134 | T, TInfo, D->getStorageClass(), |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3135 | /*DefaultArg*/ nullptr); |
| 3136 | |
| 3137 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 3138 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3139 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 3140 | |
| 3141 | Expr *ToDefArg = nullptr; |
| 3142 | Expr *FromDefArg = nullptr; |
| 3143 | if (D->hasUninstantiatedDefaultArg()) { |
| 3144 | FromDefArg = D->getUninstantiatedDefaultArg(); |
| 3145 | ToDefArg = Importer.Import(FromDefArg); |
| 3146 | ToParm->setUninstantiatedDefaultArg(ToDefArg); |
| 3147 | } else if (D->hasUnparsedDefaultArg()) { |
| 3148 | ToParm->setUnparsedDefaultArg(); |
| 3149 | } else if (D->hasDefaultArg()) { |
| 3150 | FromDefArg = D->getDefaultArg(); |
| 3151 | ToDefArg = Importer.Import(FromDefArg); |
| 3152 | ToParm->setDefaultArg(ToDefArg); |
| 3153 | } |
| 3154 | if (FromDefArg && !ToDefArg) |
| 3155 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3156 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3157 | if (D->isObjCMethodParameter()) { |
| 3158 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3159 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3160 | } else { |
| 3161 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3162 | D->getFunctionScopeIndex()); |
| 3163 | } |
| 3164 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3165 | if (D->isUsed()) |
| 3166 | ToParm->setIsUsed(); |
| 3167 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 3168 | return Importer.Imported(D, ToParm); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3169 | } |
| 3170 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3171 | Decl *ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| 3172 | // Import the major distinguishing characteristics of a method. |
| 3173 | DeclContext *DC, *LexicalDC; |
| 3174 | DeclarationName Name; |
| 3175 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3176 | NamedDecl *ToD; |
| 3177 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3178 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3179 | if (ToD) |
| 3180 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3181 | |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3182 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3183 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3184 | for (auto *FoundDecl : FoundDecls) { |
| 3185 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3186 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 3187 | continue; |
| 3188 | |
| 3189 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3190 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 3191 | FoundMethod->getReturnType())) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3192 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3193 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 3194 | << FoundMethod->getReturnType(); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3195 | Importer.ToDiag(FoundMethod->getLocation(), |
| 3196 | diag::note_odr_objc_method_here) |
| 3197 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3198 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3199 | } |
| 3200 | |
| 3201 | // Check the number of parameters. |
| 3202 | if (D->param_size() != FoundMethod->param_size()) { |
| 3203 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) |
| 3204 | << D->isInstanceMethod() << Name |
| 3205 | << D->param_size() << FoundMethod->param_size(); |
| 3206 | Importer.ToDiag(FoundMethod->getLocation(), |
| 3207 | diag::note_odr_objc_method_here) |
| 3208 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3209 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3210 | } |
| 3211 | |
| 3212 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3213 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3214 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 3215 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3216 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3217 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3218 | Importer.FromDiag((*P)->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3219 | diag::err_odr_objc_method_param_type_inconsistent) |
| 3220 | << D->isInstanceMethod() << Name |
| 3221 | << (*P)->getType() << (*FoundP)->getType(); |
| 3222 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 3223 | << (*FoundP)->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3224 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3225 | } |
| 3226 | } |
| 3227 | |
| 3228 | // Check variadic/non-variadic. |
| 3229 | // Check the number of parameters. |
| 3230 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| 3231 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) |
| 3232 | << D->isInstanceMethod() << Name; |
| 3233 | Importer.ToDiag(FoundMethod->getLocation(), |
| 3234 | diag::note_odr_objc_method_here) |
| 3235 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3236 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3237 | } |
| 3238 | |
| 3239 | // FIXME: Any other bits we need to merge? |
| 3240 | return Importer.Imported(D, FoundMethod); |
| 3241 | } |
| 3242 | } |
| 3243 | |
| 3244 | // Import the result type. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3245 | QualType ResultTy = Importer.Import(D->getReturnType()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3246 | if (ResultTy.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3247 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3248 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3249 | TypeSourceInfo *ReturnTInfo = Importer.Import(D->getReturnTypeSourceInfo()); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3250 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3251 | ObjCMethodDecl *ToMethod = ObjCMethodDecl::Create( |
| 3252 | Importer.getToContext(), Loc, Importer.Import(D->getLocEnd()), |
| 3253 | Name.getObjCSelector(), ResultTy, ReturnTInfo, DC, D->isInstanceMethod(), |
| 3254 | D->isVariadic(), D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 3255 | D->getImplementationControl(), D->hasRelatedResultType()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3256 | |
| 3257 | // FIXME: When we decide to merge method definitions, we'll need to |
| 3258 | // deal with implicit parameters. |
| 3259 | |
| 3260 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3261 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3262 | for (auto *FromP : D->parameters()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3263 | auto *ToP = cast_or_null<ParmVarDecl>(Importer.Import(FromP)); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3264 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3265 | return nullptr; |
| 3266 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3267 | ToParams.push_back(ToP); |
| 3268 | } |
| 3269 | |
| 3270 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3271 | for (auto *ToParam : ToParams) { |
| 3272 | ToParam->setOwningFunction(ToMethod); |
| 3273 | ToMethod->addDeclInternal(ToParam); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3274 | } |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3275 | |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 3276 | SmallVector<SourceLocation, 12> SelLocs; |
| 3277 | D->getSelectorLocs(SelLocs); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3278 | for (auto &Loc : SelLocs) |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3279 | Loc = Importer.Import(Loc); |
| 3280 | |
| 3281 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, SelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3282 | |
| 3283 | ToMethod->setLexicalDeclContext(LexicalDC); |
| 3284 | Importer.Imported(D, ToMethod); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3285 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3286 | return ToMethod; |
| 3287 | } |
| 3288 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3289 | Decl *ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| 3290 | // Import the major distinguishing characteristics of a category. |
| 3291 | DeclContext *DC, *LexicalDC; |
| 3292 | DeclarationName Name; |
| 3293 | SourceLocation Loc; |
| 3294 | NamedDecl *ToD; |
| 3295 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3296 | return nullptr; |
| 3297 | if (ToD) |
| 3298 | return ToD; |
| 3299 | |
| 3300 | TypeSourceInfo *BoundInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3301 | if (!BoundInfo) |
| 3302 | return nullptr; |
| 3303 | |
| 3304 | ObjCTypeParamDecl *Result = ObjCTypeParamDecl::Create( |
| 3305 | Importer.getToContext(), DC, |
Douglas Gregor | 1ac1b63 | 2015-07-07 03:58:54 +0000 | [diff] [blame] | 3306 | D->getVariance(), |
| 3307 | Importer.Import(D->getVarianceLoc()), |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 3308 | D->getIndex(), |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3309 | Importer.Import(D->getLocation()), |
| 3310 | Name.getAsIdentifierInfo(), |
| 3311 | Importer.Import(D->getColonLoc()), |
| 3312 | BoundInfo); |
| 3313 | Importer.Imported(D, Result); |
| 3314 | Result->setLexicalDeclContext(LexicalDC); |
| 3315 | return Result; |
| 3316 | } |
| 3317 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3318 | Decl *ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| 3319 | // Import the major distinguishing characteristics of a category. |
| 3320 | DeclContext *DC, *LexicalDC; |
| 3321 | DeclarationName Name; |
| 3322 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3323 | NamedDecl *ToD; |
| 3324 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3325 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3326 | if (ToD) |
| 3327 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3328 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3329 | auto *ToInterface = |
| 3330 | cast_or_null<ObjCInterfaceDecl>(Importer.Import(D->getClassInterface())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3331 | if (!ToInterface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3332 | return nullptr; |
| 3333 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3334 | // Determine if we've already encountered this category. |
| 3335 | ObjCCategoryDecl *MergeWithCategory |
| 3336 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 3337 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 3338 | if (!ToCategory) { |
| 3339 | ToCategory = ObjCCategoryDecl::Create(Importer.getToContext(), DC, |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3340 | Importer.Import(D->getAtStartLoc()), |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3341 | Loc, |
| 3342 | Importer.Import(D->getCategoryNameLoc()), |
Argyrios Kyrtzidis | 3a5094b | 2011-08-30 19:43:26 +0000 | [diff] [blame] | 3343 | Name.getAsIdentifierInfo(), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3344 | ToInterface, |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3345 | /*TypeParamList=*/nullptr, |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3346 | Importer.Import(D->getIvarLBraceLoc()), |
| 3347 | Importer.Import(D->getIvarRBraceLoc())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3348 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3349 | LexicalDC->addDeclInternal(ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3350 | Importer.Imported(D, ToCategory); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3351 | // Import the type parameter list after calling Imported, to avoid |
| 3352 | // loops when bringing in their DeclContext. |
| 3353 | ToCategory->setTypeParamList(ImportObjCTypeParamList( |
| 3354 | D->getTypeParamList())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3355 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3356 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3357 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3358 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3359 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 3360 | = D->protocol_loc_begin(); |
| 3361 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 3362 | FromProtoEnd = D->protocol_end(); |
| 3363 | FromProto != FromProtoEnd; |
| 3364 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3365 | auto *ToProto = |
| 3366 | cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3367 | if (!ToProto) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3368 | return nullptr; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3369 | Protocols.push_back(ToProto); |
| 3370 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3371 | } |
| 3372 | |
| 3373 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3374 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 3375 | ProtocolLocs.data(), Importer.getToContext()); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3376 | } else { |
| 3377 | Importer.Imported(D, ToCategory); |
| 3378 | } |
| 3379 | |
| 3380 | // Import all of the members of this category. |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 3381 | ImportDeclContext(D); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3382 | |
| 3383 | // If we have an implementation, import it as well. |
| 3384 | if (D->getImplementation()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3385 | auto *Impl = |
| 3386 | cast_or_null<ObjCCategoryImplDecl>( |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 3387 | Importer.Import(D->getImplementation())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3388 | if (!Impl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3389 | return nullptr; |
| 3390 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3391 | ToCategory->setImplementation(Impl); |
| 3392 | } |
| 3393 | |
| 3394 | return ToCategory; |
| 3395 | } |
| 3396 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3397 | bool ASTNodeImporter::ImportDefinition(ObjCProtocolDecl *From, |
| 3398 | ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3399 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3400 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3401 | if (shouldForceImportDeclContext(Kind)) |
| 3402 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3403 | return false; |
| 3404 | } |
| 3405 | |
| 3406 | // Start the protocol definition |
| 3407 | To->startDefinition(); |
| 3408 | |
| 3409 | // Import protocols |
| 3410 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3411 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| 3412 | ObjCProtocolDecl::protocol_loc_iterator |
| 3413 | FromProtoLoc = From->protocol_loc_begin(); |
| 3414 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3415 | FromProtoEnd = From->protocol_end(); |
| 3416 | FromProto != FromProtoEnd; |
| 3417 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3418 | auto *ToProto = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3419 | if (!ToProto) |
| 3420 | return true; |
| 3421 | Protocols.push_back(ToProto); |
| 3422 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3423 | } |
| 3424 | |
| 3425 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3426 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 3427 | ProtocolLocs.data(), Importer.getToContext()); |
| 3428 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3429 | if (shouldForceImportDeclContext(Kind)) { |
| 3430 | // Import all of the members of this protocol. |
| 3431 | ImportDeclContext(From, /*ForceImport=*/true); |
| 3432 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3433 | return false; |
| 3434 | } |
| 3435 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3436 | Decl *ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3437 | // If this protocol has a definition in the translation unit we're coming |
| 3438 | // from, but this particular declaration is not that definition, import the |
| 3439 | // definition and map to that. |
| 3440 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 3441 | if (Definition && Definition != D) { |
| 3442 | Decl *ImportedDef = Importer.Import(Definition); |
| 3443 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3444 | return nullptr; |
| 3445 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3446 | return Importer.Imported(D, ImportedDef); |
| 3447 | } |
| 3448 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3449 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3450 | DeclContext *DC, *LexicalDC; |
| 3451 | DeclarationName Name; |
| 3452 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3453 | NamedDecl *ToD; |
| 3454 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3455 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3456 | if (ToD) |
| 3457 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3458 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3459 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3460 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3461 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3462 | for (auto *FoundDecl : FoundDecls) { |
| 3463 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3464 | continue; |
| 3465 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3466 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3467 | break; |
| 3468 | } |
| 3469 | |
| 3470 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3471 | if (!ToProto) { |
| 3472 | ToProto = ObjCProtocolDecl::Create(Importer.getToContext(), DC, |
| 3473 | Name.getAsIdentifierInfo(), Loc, |
| 3474 | Importer.Import(D->getAtStartLoc()), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3475 | /*PrevDecl=*/nullptr); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3476 | ToProto->setLexicalDeclContext(LexicalDC); |
| 3477 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3478 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3479 | |
| 3480 | Importer.Imported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3481 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3482 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToProto)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3483 | return nullptr; |
| 3484 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3485 | return ToProto; |
| 3486 | } |
| 3487 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3488 | Decl *ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 3489 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3490 | DeclContext *LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3491 | |
| 3492 | SourceLocation ExternLoc = Importer.Import(D->getExternLoc()); |
| 3493 | SourceLocation LangLoc = Importer.Import(D->getLocation()); |
| 3494 | |
| 3495 | bool HasBraces = D->hasBraces(); |
| 3496 | |
Sean Callanan | b12a855 | 2014-12-10 21:22:20 +0000 | [diff] [blame] | 3497 | LinkageSpecDecl *ToLinkageSpec = |
| 3498 | LinkageSpecDecl::Create(Importer.getToContext(), |
| 3499 | DC, |
| 3500 | ExternLoc, |
| 3501 | LangLoc, |
| 3502 | D->getLanguage(), |
| 3503 | HasBraces); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3504 | |
| 3505 | if (HasBraces) { |
| 3506 | SourceLocation RBraceLoc = Importer.Import(D->getRBraceLoc()); |
| 3507 | ToLinkageSpec->setRBraceLoc(RBraceLoc); |
| 3508 | } |
| 3509 | |
| 3510 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 3511 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 3512 | |
| 3513 | Importer.Imported(D, ToLinkageSpec); |
| 3514 | |
| 3515 | return ToLinkageSpec; |
| 3516 | } |
| 3517 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3518 | Decl *ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
| 3519 | DeclContext *DC, *LexicalDC; |
| 3520 | DeclarationName Name; |
| 3521 | SourceLocation Loc; |
| 3522 | NamedDecl *ToD = nullptr; |
| 3523 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3524 | return nullptr; |
| 3525 | if (ToD) |
| 3526 | return ToD; |
| 3527 | |
| 3528 | DeclarationNameInfo NameInfo(Name, |
| 3529 | Importer.Import(D->getNameInfo().getLoc())); |
| 3530 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 3531 | |
| 3532 | UsingDecl *ToUsing = UsingDecl::Create(Importer.getToContext(), DC, |
| 3533 | Importer.Import(D->getUsingLoc()), |
| 3534 | Importer.Import(D->getQualifierLoc()), |
| 3535 | NameInfo, D->hasTypename()); |
| 3536 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 3537 | LexicalDC->addDeclInternal(ToUsing); |
| 3538 | Importer.Imported(D, ToUsing); |
| 3539 | |
| 3540 | if (NamedDecl *FromPattern = |
| 3541 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3542 | if (auto *ToPattern = |
| 3543 | dyn_cast_or_null<NamedDecl>(Importer.Import(FromPattern))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3544 | Importer.getToContext().setInstantiatedFromUsingDecl(ToUsing, ToPattern); |
| 3545 | else |
| 3546 | return nullptr; |
| 3547 | } |
| 3548 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3549 | for (auto *FromShadow : D->shadows()) { |
| 3550 | if (auto *ToShadow = |
| 3551 | dyn_cast_or_null<UsingShadowDecl>(Importer.Import(FromShadow))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3552 | ToUsing->addShadowDecl(ToShadow); |
| 3553 | else |
| 3554 | // FIXME: We return a nullptr here but the definition is already created |
| 3555 | // and available with lookups. How to fix this?.. |
| 3556 | return nullptr; |
| 3557 | } |
| 3558 | return ToUsing; |
| 3559 | } |
| 3560 | |
| 3561 | Decl *ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| 3562 | DeclContext *DC, *LexicalDC; |
| 3563 | DeclarationName Name; |
| 3564 | SourceLocation Loc; |
| 3565 | NamedDecl *ToD = nullptr; |
| 3566 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3567 | return nullptr; |
| 3568 | if (ToD) |
| 3569 | return ToD; |
| 3570 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3571 | auto *ToUsing = dyn_cast_or_null<UsingDecl>( |
| 3572 | Importer.Import(D->getUsingDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3573 | if (!ToUsing) |
| 3574 | return nullptr; |
| 3575 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3576 | auto *ToTarget = dyn_cast_or_null<NamedDecl>( |
| 3577 | Importer.Import(D->getTargetDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3578 | if (!ToTarget) |
| 3579 | return nullptr; |
| 3580 | |
| 3581 | UsingShadowDecl *ToShadow = UsingShadowDecl::Create( |
| 3582 | Importer.getToContext(), DC, Loc, ToUsing, ToTarget); |
| 3583 | |
| 3584 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 3585 | ToShadow->setAccess(D->getAccess()); |
| 3586 | Importer.Imported(D, ToShadow); |
| 3587 | |
| 3588 | if (UsingShadowDecl *FromPattern = |
| 3589 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3590 | if (auto *ToPattern = |
| 3591 | dyn_cast_or_null<UsingShadowDecl>(Importer.Import(FromPattern))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3592 | Importer.getToContext().setInstantiatedFromUsingShadowDecl(ToShadow, |
| 3593 | ToPattern); |
| 3594 | else |
| 3595 | // FIXME: We return a nullptr here but the definition is already created |
| 3596 | // and available with lookups. How to fix this?.. |
| 3597 | return nullptr; |
| 3598 | } |
| 3599 | |
| 3600 | LexicalDC->addDeclInternal(ToShadow); |
| 3601 | |
| 3602 | return ToShadow; |
| 3603 | } |
| 3604 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3605 | Decl *ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 3606 | DeclContext *DC, *LexicalDC; |
| 3607 | DeclarationName Name; |
| 3608 | SourceLocation Loc; |
| 3609 | NamedDecl *ToD = nullptr; |
| 3610 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3611 | return nullptr; |
| 3612 | if (ToD) |
| 3613 | return ToD; |
| 3614 | |
| 3615 | DeclContext *ToComAncestor = Importer.ImportContext(D->getCommonAncestor()); |
| 3616 | if (!ToComAncestor) |
| 3617 | return nullptr; |
| 3618 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3619 | auto *ToNominated = cast_or_null<NamespaceDecl>( |
| 3620 | Importer.Import(D->getNominatedNamespace())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3621 | if (!ToNominated) |
| 3622 | return nullptr; |
| 3623 | |
| 3624 | UsingDirectiveDecl *ToUsingDir = UsingDirectiveDecl::Create( |
| 3625 | Importer.getToContext(), DC, Importer.Import(D->getUsingLoc()), |
| 3626 | Importer.Import(D->getNamespaceKeyLocation()), |
| 3627 | Importer.Import(D->getQualifierLoc()), |
| 3628 | Importer.Import(D->getIdentLocation()), ToNominated, ToComAncestor); |
| 3629 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 3630 | LexicalDC->addDeclInternal(ToUsingDir); |
| 3631 | Importer.Imported(D, ToUsingDir); |
| 3632 | |
| 3633 | return ToUsingDir; |
| 3634 | } |
| 3635 | |
| 3636 | Decl *ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
| 3637 | UnresolvedUsingValueDecl *D) { |
| 3638 | DeclContext *DC, *LexicalDC; |
| 3639 | DeclarationName Name; |
| 3640 | SourceLocation Loc; |
| 3641 | NamedDecl *ToD = nullptr; |
| 3642 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3643 | return nullptr; |
| 3644 | if (ToD) |
| 3645 | return ToD; |
| 3646 | |
| 3647 | DeclarationNameInfo NameInfo(Name, Importer.Import(D->getNameInfo().getLoc())); |
| 3648 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 3649 | |
| 3650 | UnresolvedUsingValueDecl *ToUsingValue = UnresolvedUsingValueDecl::Create( |
| 3651 | Importer.getToContext(), DC, Importer.Import(D->getUsingLoc()), |
| 3652 | Importer.Import(D->getQualifierLoc()), NameInfo, |
| 3653 | Importer.Import(D->getEllipsisLoc())); |
| 3654 | |
| 3655 | Importer.Imported(D, ToUsingValue); |
| 3656 | ToUsingValue->setAccess(D->getAccess()); |
| 3657 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 3658 | LexicalDC->addDeclInternal(ToUsingValue); |
| 3659 | |
| 3660 | return ToUsingValue; |
| 3661 | } |
| 3662 | |
| 3663 | Decl *ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
| 3664 | UnresolvedUsingTypenameDecl *D) { |
| 3665 | DeclContext *DC, *LexicalDC; |
| 3666 | DeclarationName Name; |
| 3667 | SourceLocation Loc; |
| 3668 | NamedDecl *ToD = nullptr; |
| 3669 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3670 | return nullptr; |
| 3671 | if (ToD) |
| 3672 | return ToD; |
| 3673 | |
| 3674 | UnresolvedUsingTypenameDecl *ToUsing = UnresolvedUsingTypenameDecl::Create( |
| 3675 | Importer.getToContext(), DC, Importer.Import(D->getUsingLoc()), |
| 3676 | Importer.Import(D->getTypenameLoc()), |
| 3677 | Importer.Import(D->getQualifierLoc()), Loc, Name, |
| 3678 | Importer.Import(D->getEllipsisLoc())); |
| 3679 | |
| 3680 | Importer.Imported(D, ToUsing); |
| 3681 | ToUsing->setAccess(D->getAccess()); |
| 3682 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 3683 | LexicalDC->addDeclInternal(ToUsing); |
| 3684 | |
| 3685 | return ToUsing; |
| 3686 | } |
| 3687 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3688 | bool ASTNodeImporter::ImportDefinition(ObjCInterfaceDecl *From, |
| 3689 | ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3690 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3691 | if (To->getDefinition()) { |
| 3692 | // Check consistency of superclass. |
| 3693 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 3694 | if (FromSuper) { |
| 3695 | FromSuper = cast_or_null<ObjCInterfaceDecl>(Importer.Import(FromSuper)); |
| 3696 | if (!FromSuper) |
| 3697 | return true; |
| 3698 | } |
| 3699 | |
| 3700 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
| 3701 | if ((bool)FromSuper != (bool)ToSuper || |
| 3702 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
| 3703 | Importer.ToDiag(To->getLocation(), |
| 3704 | diag::err_odr_objc_superclass_inconsistent) |
| 3705 | << To->getDeclName(); |
| 3706 | if (ToSuper) |
| 3707 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 3708 | << To->getSuperClass()->getDeclName(); |
| 3709 | else |
| 3710 | Importer.ToDiag(To->getLocation(), |
| 3711 | diag::note_odr_objc_missing_superclass); |
| 3712 | if (From->getSuperClass()) |
| 3713 | Importer.FromDiag(From->getSuperClassLoc(), |
| 3714 | diag::note_odr_objc_superclass) |
| 3715 | << From->getSuperClass()->getDeclName(); |
| 3716 | else |
| 3717 | Importer.FromDiag(From->getLocation(), |
| 3718 | diag::note_odr_objc_missing_superclass); |
| 3719 | } |
| 3720 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3721 | if (shouldForceImportDeclContext(Kind)) |
| 3722 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3723 | return false; |
| 3724 | } |
| 3725 | |
| 3726 | // Start the definition. |
| 3727 | To->startDefinition(); |
| 3728 | |
| 3729 | // If this class has a superclass, import it. |
| 3730 | if (From->getSuperClass()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 3731 | TypeSourceInfo *SuperTInfo = Importer.Import(From->getSuperClassTInfo()); |
| 3732 | if (!SuperTInfo) |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3733 | return true; |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 3734 | |
| 3735 | To->setSuperClass(SuperTInfo); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3736 | } |
| 3737 | |
| 3738 | // Import protocols |
| 3739 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3740 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| 3741 | ObjCInterfaceDecl::protocol_loc_iterator |
| 3742 | FromProtoLoc = From->protocol_loc_begin(); |
| 3743 | |
| 3744 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3745 | FromProtoEnd = From->protocol_end(); |
| 3746 | FromProto != FromProtoEnd; |
| 3747 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3748 | auto *ToProto = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3749 | if (!ToProto) |
| 3750 | return true; |
| 3751 | Protocols.push_back(ToProto); |
| 3752 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3753 | } |
| 3754 | |
| 3755 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3756 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 3757 | ProtocolLocs.data(), Importer.getToContext()); |
| 3758 | |
| 3759 | // Import categories. When the categories themselves are imported, they'll |
| 3760 | // hook themselves into this interface. |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 3761 | for (auto *Cat : From->known_categories()) |
| 3762 | Importer.Import(Cat); |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 3763 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3764 | // If we have an @implementation, import it as well. |
| 3765 | if (From->getImplementation()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3766 | auto *Impl = cast_or_null<ObjCImplementationDecl>( |
| 3767 | Importer.Import(From->getImplementation())); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3768 | if (!Impl) |
| 3769 | return true; |
| 3770 | |
| 3771 | To->setImplementation(Impl); |
| 3772 | } |
| 3773 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3774 | if (shouldForceImportDeclContext(Kind)) { |
| 3775 | // Import all of the members of this class. |
| 3776 | ImportDeclContext(From, /*ForceImport=*/true); |
| 3777 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3778 | return false; |
| 3779 | } |
| 3780 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3781 | ObjCTypeParamList * |
| 3782 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 3783 | if (!list) |
| 3784 | return nullptr; |
| 3785 | |
| 3786 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
| 3787 | for (auto fromTypeParam : *list) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3788 | auto *toTypeParam = cast_or_null<ObjCTypeParamDecl>( |
| 3789 | Importer.Import(fromTypeParam)); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3790 | if (!toTypeParam) |
| 3791 | return nullptr; |
| 3792 | |
| 3793 | toTypeParams.push_back(toTypeParam); |
| 3794 | } |
| 3795 | |
| 3796 | return ObjCTypeParamList::create(Importer.getToContext(), |
| 3797 | Importer.Import(list->getLAngleLoc()), |
| 3798 | toTypeParams, |
| 3799 | Importer.Import(list->getRAngleLoc())); |
| 3800 | } |
| 3801 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3802 | Decl *ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3803 | // If this class has a definition in the translation unit we're coming from, |
| 3804 | // but this particular declaration is not that definition, import the |
| 3805 | // definition and map to that. |
| 3806 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 3807 | if (Definition && Definition != D) { |
| 3808 | Decl *ImportedDef = Importer.Import(Definition); |
| 3809 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3810 | return nullptr; |
| 3811 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3812 | return Importer.Imported(D, ImportedDef); |
| 3813 | } |
| 3814 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3815 | // Import the major distinguishing characteristics of an @interface. |
| 3816 | DeclContext *DC, *LexicalDC; |
| 3817 | DeclarationName Name; |
| 3818 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3819 | NamedDecl *ToD; |
| 3820 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3821 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3822 | if (ToD) |
| 3823 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3824 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3825 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3826 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3827 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3828 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3829 | for (auto *FoundDecl : FoundDecls) { |
| 3830 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3831 | continue; |
| 3832 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3833 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3834 | break; |
| 3835 | } |
| 3836 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3837 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3838 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3839 | if (!ToIface) { |
| 3840 | ToIface = ObjCInterfaceDecl::Create(Importer.getToContext(), DC, |
| 3841 | Importer.Import(D->getAtStartLoc()), |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3842 | Name.getAsIdentifierInfo(), |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3843 | /*TypeParamList=*/nullptr, |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3844 | /*PrevDecl=*/nullptr, Loc, |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3845 | D->isImplicitInterfaceDecl()); |
| 3846 | ToIface->setLexicalDeclContext(LexicalDC); |
| 3847 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3848 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3849 | Importer.Imported(D, ToIface); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3850 | // Import the type parameter list after calling Imported, to avoid |
| 3851 | // loops when bringing in their DeclContext. |
| 3852 | ToIface->setTypeParamList(ImportObjCTypeParamList( |
| 3853 | D->getTypeParamListAsWritten())); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3854 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3855 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToIface)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3856 | return nullptr; |
| 3857 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3858 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3859 | } |
| 3860 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3861 | Decl *ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3862 | auto *Category = cast_or_null<ObjCCategoryDecl>( |
| 3863 | Importer.Import(D->getCategoryDecl())); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3864 | if (!Category) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3865 | return nullptr; |
| 3866 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3867 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 3868 | if (!ToImpl) { |
| 3869 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3870 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3871 | return nullptr; |
| 3872 | |
Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 3873 | SourceLocation CategoryNameLoc = Importer.Import(D->getCategoryNameLoc()); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3874 | ToImpl = ObjCCategoryImplDecl::Create(Importer.getToContext(), DC, |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3875 | Importer.Import(D->getIdentifier()), |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3876 | Category->getClassInterface(), |
| 3877 | Importer.Import(D->getLocation()), |
Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 3878 | Importer.Import(D->getAtStartLoc()), |
| 3879 | CategoryNameLoc); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3880 | |
| 3881 | DeclContext *LexicalDC = DC; |
| 3882 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3883 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3884 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3885 | return nullptr; |
| 3886 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3887 | ToImpl->setLexicalDeclContext(LexicalDC); |
| 3888 | } |
| 3889 | |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3890 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3891 | Category->setImplementation(ToImpl); |
| 3892 | } |
| 3893 | |
| 3894 | Importer.Imported(D, ToImpl); |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 3895 | ImportDeclContext(D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3896 | return ToImpl; |
| 3897 | } |
| 3898 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3899 | Decl *ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 3900 | // Find the corresponding interface. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3901 | auto *Iface = cast_or_null<ObjCInterfaceDecl>( |
| 3902 | Importer.Import(D->getClassInterface())); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3903 | if (!Iface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3904 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3905 | |
| 3906 | // Import the superclass, if any. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3907 | ObjCInterfaceDecl *Super = nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3908 | if (D->getSuperClass()) { |
| 3909 | Super = cast_or_null<ObjCInterfaceDecl>( |
| 3910 | Importer.Import(D->getSuperClass())); |
| 3911 | if (!Super) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3912 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3913 | } |
| 3914 | |
| 3915 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 3916 | if (!Impl) { |
| 3917 | // We haven't imported an implementation yet. Create a new @implementation |
| 3918 | // now. |
| 3919 | Impl = ObjCImplementationDecl::Create(Importer.getToContext(), |
| 3920 | Importer.ImportContext(D->getDeclContext()), |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3921 | Iface, Super, |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3922 | Importer.Import(D->getLocation()), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3923 | Importer.Import(D->getAtStartLoc()), |
Argyrios Kyrtzidis | 5d2ce84 | 2013-05-03 22:31:26 +0000 | [diff] [blame] | 3924 | Importer.Import(D->getSuperClassLoc()), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3925 | Importer.Import(D->getIvarLBraceLoc()), |
| 3926 | Importer.Import(D->getIvarRBraceLoc())); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3927 | |
| 3928 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3929 | DeclContext *LexicalDC |
| 3930 | = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3931 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3932 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3933 | Impl->setLexicalDeclContext(LexicalDC); |
| 3934 | } |
| 3935 | |
| 3936 | // Associate the implementation with the class it implements. |
| 3937 | Iface->setImplementation(Impl); |
| 3938 | Importer.Imported(D, Iface->getImplementation()); |
| 3939 | } else { |
| 3940 | Importer.Imported(D, Iface->getImplementation()); |
| 3941 | |
| 3942 | // Verify that the existing @implementation has the same superclass. |
| 3943 | if ((Super && !Impl->getSuperClass()) || |
| 3944 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 3945 | (Super && Impl->getSuperClass() && |
| 3946 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 3947 | Impl->getSuperClass()))) { |
| 3948 | Importer.ToDiag(Impl->getLocation(), |
| 3949 | diag::err_odr_objc_superclass_inconsistent) |
| 3950 | << Iface->getDeclName(); |
| 3951 | // FIXME: It would be nice to have the location of the superclass |
| 3952 | // below. |
| 3953 | if (Impl->getSuperClass()) |
| 3954 | Importer.ToDiag(Impl->getLocation(), |
| 3955 | diag::note_odr_objc_superclass) |
| 3956 | << Impl->getSuperClass()->getDeclName(); |
| 3957 | else |
| 3958 | Importer.ToDiag(Impl->getLocation(), |
| 3959 | diag::note_odr_objc_missing_superclass); |
| 3960 | if (D->getSuperClass()) |
| 3961 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3962 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 3963 | << D->getSuperClass()->getDeclName(); |
| 3964 | else |
| 3965 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3966 | diag::note_odr_objc_missing_superclass); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3967 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3968 | } |
| 3969 | } |
| 3970 | |
| 3971 | // Import all of the members of this @implementation. |
| 3972 | ImportDeclContext(D); |
| 3973 | |
| 3974 | return Impl; |
| 3975 | } |
| 3976 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3977 | Decl *ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| 3978 | // Import the major distinguishing characteristics of an @property. |
| 3979 | DeclContext *DC, *LexicalDC; |
| 3980 | DeclarationName Name; |
| 3981 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3982 | NamedDecl *ToD; |
| 3983 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3984 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3985 | if (ToD) |
| 3986 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3987 | |
| 3988 | // Check whether we have already imported this property. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3989 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3990 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3991 | for (auto *FoundDecl : FoundDecls) { |
| 3992 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3993 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3994 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3995 | FoundProp->getType())) { |
| 3996 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) |
| 3997 | << Name << D->getType() << FoundProp->getType(); |
| 3998 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 3999 | << FoundProp->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4000 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4001 | } |
| 4002 | |
| 4003 | // FIXME: Check property attributes, getters, setters, etc.? |
| 4004 | |
| 4005 | // Consider these properties to be equivalent. |
| 4006 | Importer.Imported(D, FoundProp); |
| 4007 | return FoundProp; |
| 4008 | } |
| 4009 | } |
| 4010 | |
| 4011 | // Import the type. |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 4012 | TypeSourceInfo *TSI = Importer.Import(D->getTypeSourceInfo()); |
| 4013 | if (!TSI) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4014 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4015 | |
| 4016 | // Create the new property. |
| 4017 | ObjCPropertyDecl *ToProperty |
| 4018 | = ObjCPropertyDecl::Create(Importer.getToContext(), DC, Loc, |
| 4019 | Name.getAsIdentifierInfo(), |
| 4020 | Importer.Import(D->getAtLoc()), |
Fariborz Jahanian | 86c2f5c | 2012-02-29 22:18:55 +0000 | [diff] [blame] | 4021 | Importer.Import(D->getLParenLoc()), |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 4022 | Importer.Import(D->getType()), |
| 4023 | TSI, |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4024 | D->getPropertyImplementation()); |
| 4025 | Importer.Imported(D, ToProperty); |
| 4026 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4027 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4028 | |
| 4029 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4030 | ToProperty->setPropertyAttributesAsWritten( |
| 4031 | D->getPropertyAttributesAsWritten()); |
Argyrios Kyrtzidis | 194b28e | 2017-03-16 18:25:40 +0000 | [diff] [blame] | 4032 | ToProperty->setGetterName(Importer.Import(D->getGetterName()), |
| 4033 | Importer.Import(D->getGetterNameLoc())); |
| 4034 | ToProperty->setSetterName(Importer.Import(D->getSetterName()), |
| 4035 | Importer.Import(D->getSetterNameLoc())); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4036 | ToProperty->setGetterMethodDecl( |
| 4037 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getGetterMethodDecl()))); |
| 4038 | ToProperty->setSetterMethodDecl( |
| 4039 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getSetterMethodDecl()))); |
| 4040 | ToProperty->setPropertyIvarDecl( |
| 4041 | cast_or_null<ObjCIvarDecl>(Importer.Import(D->getPropertyIvarDecl()))); |
| 4042 | return ToProperty; |
| 4043 | } |
| 4044 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4045 | Decl *ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4046 | auto *Property = cast_or_null<ObjCPropertyDecl>( |
| 4047 | Importer.Import(D->getPropertyDecl())); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4048 | if (!Property) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4049 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4050 | |
| 4051 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 4052 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4053 | return nullptr; |
| 4054 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4055 | // Import the lexical declaration context. |
| 4056 | DeclContext *LexicalDC = DC; |
| 4057 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4058 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4059 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4060 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4061 | } |
| 4062 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4063 | auto *InImpl = dyn_cast<ObjCImplDecl>(LexicalDC); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4064 | if (!InImpl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4065 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4066 | |
| 4067 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4068 | ObjCIvarDecl *Ivar = nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4069 | if (D->getPropertyIvarDecl()) { |
| 4070 | Ivar = cast_or_null<ObjCIvarDecl>( |
| 4071 | Importer.Import(D->getPropertyIvarDecl())); |
| 4072 | if (!Ivar) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4073 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4074 | } |
| 4075 | |
| 4076 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 4077 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 4078 | Property->getQueryKind()); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4079 | if (!ToImpl) { |
| 4080 | ToImpl = ObjCPropertyImplDecl::Create(Importer.getToContext(), DC, |
| 4081 | Importer.Import(D->getLocStart()), |
| 4082 | Importer.Import(D->getLocation()), |
| 4083 | Property, |
| 4084 | D->getPropertyImplementation(), |
| 4085 | Ivar, |
| 4086 | Importer.Import(D->getPropertyIvarDeclLoc())); |
| 4087 | ToImpl->setLexicalDeclContext(LexicalDC); |
| 4088 | Importer.Imported(D, ToImpl); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4089 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4090 | } else { |
| 4091 | // Check that we have the same kind of property implementation (@synthesize |
| 4092 | // vs. @dynamic). |
| 4093 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
| 4094 | Importer.ToDiag(ToImpl->getLocation(), |
| 4095 | diag::err_odr_objc_property_impl_kind_inconsistent) |
| 4096 | << Property->getDeclName() |
| 4097 | << (ToImpl->getPropertyImplementation() |
| 4098 | == ObjCPropertyImplDecl::Dynamic); |
| 4099 | Importer.FromDiag(D->getLocation(), |
| 4100 | diag::note_odr_objc_property_impl_kind) |
| 4101 | << D->getPropertyDecl()->getDeclName() |
| 4102 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4103 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4104 | } |
| 4105 | |
| 4106 | // For @synthesize, check that we have the same |
| 4107 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 4108 | Ivar != ToImpl->getPropertyIvarDecl()) { |
| 4109 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
| 4110 | diag::err_odr_objc_synthesize_ivar_inconsistent) |
| 4111 | << Property->getDeclName() |
| 4112 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 4113 | << Ivar->getDeclName(); |
| 4114 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
| 4115 | diag::note_odr_objc_synthesize_ivar_here) |
| 4116 | << D->getPropertyIvarDecl()->getDeclName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4117 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4118 | } |
| 4119 | |
| 4120 | // Merge the existing implementation with the new implementation. |
| 4121 | Importer.Imported(D, ToImpl); |
| 4122 | } |
| 4123 | |
| 4124 | return ToImpl; |
| 4125 | } |
| 4126 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4127 | Decl *ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| 4128 | // For template arguments, we adopt the translation unit as our declaration |
| 4129 | // context. This context will be fixed when the actual template declaration |
| 4130 | // is created. |
| 4131 | |
| 4132 | // FIXME: Import default argument. |
| 4133 | return TemplateTypeParmDecl::Create(Importer.getToContext(), |
| 4134 | Importer.getToContext().getTranslationUnitDecl(), |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 4135 | Importer.Import(D->getLocStart()), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4136 | Importer.Import(D->getLocation()), |
| 4137 | D->getDepth(), |
| 4138 | D->getIndex(), |
| 4139 | Importer.Import(D->getIdentifier()), |
| 4140 | D->wasDeclaredWithTypename(), |
| 4141 | D->isParameterPack()); |
| 4142 | } |
| 4143 | |
| 4144 | Decl * |
| 4145 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| 4146 | // Import the name of this declaration. |
| 4147 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 4148 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4149 | return nullptr; |
| 4150 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4151 | // Import the location of this declaration. |
| 4152 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 4153 | |
| 4154 | // Import the type of this declaration. |
| 4155 | QualType T = Importer.Import(D->getType()); |
| 4156 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4157 | return nullptr; |
| 4158 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4159 | // Import type-source information. |
| 4160 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 4161 | if (D->getTypeSourceInfo() && !TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4162 | return nullptr; |
| 4163 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4164 | // FIXME: Import default argument. |
| 4165 | |
| 4166 | return NonTypeTemplateParmDecl::Create(Importer.getToContext(), |
| 4167 | Importer.getToContext().getTranslationUnitDecl(), |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 4168 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4169 | Loc, D->getDepth(), D->getPosition(), |
| 4170 | Name.getAsIdentifierInfo(), |
Douglas Gregor | da3cc0d | 2010-12-23 23:51:58 +0000 | [diff] [blame] | 4171 | T, D->isParameterPack(), TInfo); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4172 | } |
| 4173 | |
| 4174 | Decl * |
| 4175 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 4176 | // Import the name of this declaration. |
| 4177 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 4178 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4179 | return nullptr; |
| 4180 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4181 | // Import the location of this declaration. |
| 4182 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 4183 | |
| 4184 | // Import template parameters. |
| 4185 | TemplateParameterList *TemplateParams |
| 4186 | = ImportTemplateParameterList(D->getTemplateParameters()); |
| 4187 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4188 | return nullptr; |
| 4189 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4190 | // FIXME: Import default argument. |
| 4191 | |
| 4192 | return TemplateTemplateParmDecl::Create(Importer.getToContext(), |
| 4193 | Importer.getToContext().getTranslationUnitDecl(), |
| 4194 | Loc, D->getDepth(), D->getPosition(), |
Douglas Gregor | f550077 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 4195 | D->isParameterPack(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4196 | Name.getAsIdentifierInfo(), |
| 4197 | TemplateParams); |
| 4198 | } |
| 4199 | |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4200 | // Returns the definition for a (forward) declaration of a ClassTemplateDecl, if |
| 4201 | // it has any definition in the redecl chain. |
| 4202 | static ClassTemplateDecl *getDefinition(ClassTemplateDecl *D) { |
| 4203 | CXXRecordDecl *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
| 4204 | if (!ToTemplatedDef) |
| 4205 | return nullptr; |
| 4206 | ClassTemplateDecl *TemplateWithDef = |
| 4207 | ToTemplatedDef->getDescribedClassTemplate(); |
| 4208 | return TemplateWithDef; |
| 4209 | } |
| 4210 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4211 | Decl *ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 4212 | // If this record has a definition in the translation unit we're coming from, |
| 4213 | // but this particular declaration is not that definition, import the |
| 4214 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4215 | auto *Definition = |
| 4216 | cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition()); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4217 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 4218 | Decl *ImportedDef |
| 4219 | = Importer.Import(Definition->getDescribedClassTemplate()); |
| 4220 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4221 | return nullptr; |
| 4222 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4223 | return Importer.Imported(D, ImportedDef); |
| 4224 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4225 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4226 | // Import the major distinguishing characteristics of this class template. |
| 4227 | DeclContext *DC, *LexicalDC; |
| 4228 | DeclarationName Name; |
| 4229 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4230 | NamedDecl *ToD; |
| 4231 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4232 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4233 | if (ToD) |
| 4234 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4235 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4236 | // We may already have a template of the same name; try to find and match it. |
| 4237 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4238 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4239 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4240 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4241 | for (auto *FoundDecl : FoundDecls) { |
| 4242 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4243 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4244 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4245 | Decl *Found = FoundDecl; |
| 4246 | if (auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found)) { |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4247 | |
| 4248 | // The class to be imported is a definition. |
| 4249 | if (D->isThisDeclarationADefinition()) { |
| 4250 | // Lookup will find the fwd decl only if that is more recent than the |
| 4251 | // definition. So, try to get the definition if that is available in |
| 4252 | // the redecl chain. |
| 4253 | ClassTemplateDecl *TemplateWithDef = getDefinition(FoundTemplate); |
| 4254 | if (!TemplateWithDef) |
| 4255 | continue; |
| 4256 | FoundTemplate = TemplateWithDef; // Continue with the definition. |
| 4257 | } |
| 4258 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4259 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 4260 | // The class templates structurally match; call it the same template. |
Aleksei Sidorin | 761c224 | 2018-05-15 11:09:07 +0000 | [diff] [blame] | 4261 | |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4262 | Importer.Imported(D->getTemplatedDecl(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4263 | FoundTemplate->getTemplatedDecl()); |
| 4264 | return Importer.Imported(D, FoundTemplate); |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4265 | } |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4266 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4267 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4268 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4269 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4270 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4271 | if (!ConflictingDecls.empty()) { |
| 4272 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4273 | ConflictingDecls.data(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4274 | ConflictingDecls.size()); |
| 4275 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4276 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4277 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4278 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4279 | } |
| 4280 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4281 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 4282 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4283 | // Create the declaration that is being templated. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4284 | auto *ToTemplated = cast_or_null<CXXRecordDecl>( |
| 4285 | Importer.Import(FromTemplated)); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4286 | if (!ToTemplated) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4287 | return nullptr; |
| 4288 | |
| 4289 | // Resolve possible cyclic import. |
| 4290 | if (Decl *AlreadyImported = Importer.GetAlreadyImportedOrNull(D)) |
| 4291 | return AlreadyImported; |
| 4292 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4293 | // Create the class template declaration itself. |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4294 | TemplateParameterList *TemplateParams = |
| 4295 | ImportTemplateParameterList(D->getTemplateParameters()); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4296 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4297 | return nullptr; |
| 4298 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4299 | ClassTemplateDecl *D2 = ClassTemplateDecl::Create(Importer.getToContext(), DC, |
| 4300 | Loc, Name, TemplateParams, |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4301 | ToTemplated); |
| 4302 | ToTemplated->setDescribedClassTemplate(D2); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4303 | |
| 4304 | D2->setAccess(D->getAccess()); |
| 4305 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4306 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4307 | |
| 4308 | // Note the relationship between the class templates. |
| 4309 | Importer.Imported(D, D2); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4310 | Importer.Imported(FromTemplated, ToTemplated); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4311 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4312 | if (FromTemplated->isCompleteDefinition() && |
| 4313 | !ToTemplated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4314 | // FIXME: Import definition! |
| 4315 | } |
| 4316 | |
| 4317 | return D2; |
| 4318 | } |
| 4319 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4320 | Decl *ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
| 4321 | ClassTemplateSpecializationDecl *D) { |
| 4322 | // If this record has a definition in the translation unit we're coming from, |
| 4323 | // but this particular declaration is not that definition, import the |
| 4324 | // definition and map to that. |
| 4325 | TagDecl *Definition = D->getDefinition(); |
| 4326 | if (Definition && Definition != D) { |
| 4327 | Decl *ImportedDef = Importer.Import(Definition); |
| 4328 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4329 | return nullptr; |
| 4330 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4331 | return Importer.Imported(D, ImportedDef); |
| 4332 | } |
| 4333 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4334 | auto *ClassTemplate = |
| 4335 | cast_or_null<ClassTemplateDecl>(Importer.Import( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4336 | D->getSpecializedTemplate())); |
| 4337 | if (!ClassTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4338 | return nullptr; |
| 4339 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4340 | // Import the context of this declaration. |
| 4341 | DeclContext *DC = ClassTemplate->getDeclContext(); |
| 4342 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4343 | return nullptr; |
| 4344 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4345 | DeclContext *LexicalDC = DC; |
| 4346 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4347 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4348 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4349 | return nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4350 | } |
| 4351 | |
| 4352 | // Import the location of this declaration. |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 4353 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 4354 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4355 | |
| 4356 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4357 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4358 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 4359 | D->getTemplateArgs().size(), |
| 4360 | TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4361 | return nullptr; |
| 4362 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4363 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4364 | void *InsertPos = nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4365 | ClassTemplateSpecializationDecl *D2 |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 4366 | = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4367 | if (D2) { |
| 4368 | // We already have a class template specialization with these template |
| 4369 | // arguments. |
| 4370 | |
| 4371 | // FIXME: Check for specialization vs. instantiation errors. |
| 4372 | |
| 4373 | if (RecordDecl *FoundDef = D2->getDefinition()) { |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4374 | if (!D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4375 | // The record types structurally match, or the "from" translation |
| 4376 | // unit only had a forward declaration anyway; call it the same |
| 4377 | // function. |
| 4378 | return Importer.Imported(D, FoundDef); |
| 4379 | } |
| 4380 | } |
| 4381 | } else { |
| 4382 | // Create a new specialization. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4383 | if (auto *PartialSpec = |
| 4384 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4385 | // Import TemplateArgumentListInfo |
| 4386 | TemplateArgumentListInfo ToTAInfo; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4387 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 4388 | if (ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4389 | return nullptr; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4390 | |
| 4391 | QualType CanonInjType = Importer.Import( |
| 4392 | PartialSpec->getInjectedSpecializationType()); |
| 4393 | if (CanonInjType.isNull()) |
| 4394 | return nullptr; |
| 4395 | CanonInjType = CanonInjType.getCanonicalType(); |
| 4396 | |
| 4397 | TemplateParameterList *ToTPList = ImportTemplateParameterList( |
| 4398 | PartialSpec->getTemplateParameters()); |
| 4399 | if (!ToTPList && PartialSpec->getTemplateParameters()) |
| 4400 | return nullptr; |
| 4401 | |
| 4402 | D2 = ClassTemplatePartialSpecializationDecl::Create( |
| 4403 | Importer.getToContext(), D->getTagKind(), DC, StartLoc, IdLoc, |
| 4404 | ToTPList, ClassTemplate, |
| 4405 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
| 4406 | ToTAInfo, CanonInjType, nullptr); |
| 4407 | |
| 4408 | } else { |
| 4409 | D2 = ClassTemplateSpecializationDecl::Create(Importer.getToContext(), |
| 4410 | D->getTagKind(), DC, |
| 4411 | StartLoc, IdLoc, |
| 4412 | ClassTemplate, |
| 4413 | TemplateArgs, |
| 4414 | /*PrevDecl=*/nullptr); |
| 4415 | } |
| 4416 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4417 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 4418 | |
| 4419 | // Add this specialization to the class template. |
| 4420 | ClassTemplate->AddSpecialization(D2, InsertPos); |
| 4421 | |
| 4422 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4423 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4424 | |
| 4425 | Importer.Imported(D, D2); |
| 4426 | |
| 4427 | if (auto *TSI = D->getTypeAsWritten()) { |
| 4428 | TypeSourceInfo *TInfo = Importer.Import(TSI); |
| 4429 | if (!TInfo) |
| 4430 | return nullptr; |
| 4431 | D2->setTypeAsWritten(TInfo); |
| 4432 | D2->setTemplateKeywordLoc(Importer.Import(D->getTemplateKeywordLoc())); |
| 4433 | D2->setExternLoc(Importer.Import(D->getExternLoc())); |
| 4434 | } |
| 4435 | |
| 4436 | SourceLocation POI = Importer.Import(D->getPointOfInstantiation()); |
| 4437 | if (POI.isValid()) |
| 4438 | D2->setPointOfInstantiation(POI); |
| 4439 | else if (D->getPointOfInstantiation().isValid()) |
| 4440 | return nullptr; |
| 4441 | |
| 4442 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 4443 | |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 4444 | // Set the context of this specialization/instantiation. |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4445 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 4446 | |
| 4447 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 4448 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 4449 | LexicalDC->addDeclInternal(D2); |
| 4450 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4451 | } |
| 4452 | Importer.Imported(D, D2); |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4453 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4454 | return nullptr; |
| 4455 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4456 | return D2; |
| 4457 | } |
| 4458 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4459 | Decl *ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| 4460 | // If this variable has a definition in the translation unit we're coming |
| 4461 | // from, |
| 4462 | // but this particular declaration is not that definition, import the |
| 4463 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4464 | auto *Definition = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4465 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 4466 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 4467 | Decl *ImportedDef = Importer.Import(Definition->getDescribedVarTemplate()); |
| 4468 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4469 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4470 | |
| 4471 | return Importer.Imported(D, ImportedDef); |
| 4472 | } |
| 4473 | |
| 4474 | // Import the major distinguishing characteristics of this variable template. |
| 4475 | DeclContext *DC, *LexicalDC; |
| 4476 | DeclarationName Name; |
| 4477 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4478 | NamedDecl *ToD; |
| 4479 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4480 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4481 | if (ToD) |
| 4482 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4483 | |
| 4484 | // We may already have a template of the same name; try to find and match it. |
| 4485 | assert(!DC->isFunctionOrMethod() && |
| 4486 | "Variable templates cannot be declared at function scope"); |
| 4487 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 4488 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4489 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4490 | for (auto *FoundDecl : FoundDecls) { |
| 4491 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4492 | continue; |
| 4493 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4494 | Decl *Found = FoundDecl; |
| 4495 | if (auto *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4496 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 4497 | // The variable templates structurally match; call it the same template. |
| 4498 | Importer.Imported(D->getTemplatedDecl(), |
| 4499 | FoundTemplate->getTemplatedDecl()); |
| 4500 | return Importer.Imported(D, FoundTemplate); |
| 4501 | } |
| 4502 | } |
| 4503 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4504 | ConflictingDecls.push_back(FoundDecl); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4505 | } |
| 4506 | |
| 4507 | if (!ConflictingDecls.empty()) { |
| 4508 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 4509 | ConflictingDecls.data(), |
| 4510 | ConflictingDecls.size()); |
| 4511 | } |
| 4512 | |
| 4513 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4514 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4515 | |
| 4516 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 4517 | |
| 4518 | // Import the type. |
| 4519 | QualType T = Importer.Import(DTemplated->getType()); |
| 4520 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4521 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4522 | |
| 4523 | // Create the declaration that is being templated. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4524 | auto *ToTemplated = dyn_cast_or_null<VarDecl>(Importer.Import(DTemplated)); |
| 4525 | if (!ToTemplated) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4526 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4527 | |
| 4528 | // Create the variable template declaration itself. |
| 4529 | TemplateParameterList *TemplateParams = |
| 4530 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 4531 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4532 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4533 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4534 | VarTemplateDecl *ToVarTD = VarTemplateDecl::Create( |
| 4535 | Importer.getToContext(), DC, Loc, Name, TemplateParams, ToTemplated); |
| 4536 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4537 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4538 | ToVarTD->setAccess(D->getAccess()); |
| 4539 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 4540 | LexicalDC->addDeclInternal(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4541 | |
| 4542 | // Note the relationship between the variable templates. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4543 | Importer.Imported(D, ToVarTD); |
| 4544 | Importer.Imported(DTemplated, ToTemplated); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4545 | |
| 4546 | if (DTemplated->isThisDeclarationADefinition() && |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4547 | !ToTemplated->isThisDeclarationADefinition()) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4548 | // FIXME: Import definition! |
| 4549 | } |
| 4550 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4551 | return ToVarTD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4552 | } |
| 4553 | |
| 4554 | Decl *ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
| 4555 | VarTemplateSpecializationDecl *D) { |
| 4556 | // If this record has a definition in the translation unit we're coming from, |
| 4557 | // but this particular declaration is not that definition, import the |
| 4558 | // definition and map to that. |
| 4559 | VarDecl *Definition = D->getDefinition(); |
| 4560 | if (Definition && Definition != D) { |
| 4561 | Decl *ImportedDef = Importer.Import(Definition); |
| 4562 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4563 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4564 | |
| 4565 | return Importer.Imported(D, ImportedDef); |
| 4566 | } |
| 4567 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4568 | auto *VarTemplate = cast_or_null<VarTemplateDecl>( |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4569 | Importer.Import(D->getSpecializedTemplate())); |
| 4570 | if (!VarTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4571 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4572 | |
| 4573 | // Import the context of this declaration. |
| 4574 | DeclContext *DC = VarTemplate->getDeclContext(); |
| 4575 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4576 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4577 | |
| 4578 | DeclContext *LexicalDC = DC; |
| 4579 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4580 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4581 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4582 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4583 | } |
| 4584 | |
| 4585 | // Import the location of this declaration. |
| 4586 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 4587 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
| 4588 | |
| 4589 | // Import template arguments. |
| 4590 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| 4591 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 4592 | D->getTemplateArgs().size(), TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4593 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4594 | |
| 4595 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4596 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4597 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 4598 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4599 | if (D2) { |
| 4600 | // We already have a variable template specialization with these template |
| 4601 | // arguments. |
| 4602 | |
| 4603 | // FIXME: Check for specialization vs. instantiation errors. |
| 4604 | |
| 4605 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 4606 | if (!D->isThisDeclarationADefinition() || |
| 4607 | IsStructuralMatch(D, FoundDef)) { |
| 4608 | // The record types structurally match, or the "from" translation |
| 4609 | // unit only had a forward declaration anyway; call it the same |
| 4610 | // variable. |
| 4611 | return Importer.Imported(D, FoundDef); |
| 4612 | } |
| 4613 | } |
| 4614 | } else { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4615 | // Import the type. |
| 4616 | QualType T = Importer.Import(D->getType()); |
| 4617 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4618 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4619 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4620 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 4621 | if (D->getTypeSourceInfo() && !TInfo) |
| 4622 | return nullptr; |
| 4623 | |
| 4624 | TemplateArgumentListInfo ToTAInfo; |
| 4625 | if (ImportTemplateArgumentListInfo(D->getTemplateArgsInfo(), ToTAInfo)) |
| 4626 | return nullptr; |
| 4627 | |
| 4628 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4629 | // Create a new specialization. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4630 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 4631 | // Import TemplateArgumentListInfo |
| 4632 | TemplateArgumentListInfo ArgInfos; |
| 4633 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 4634 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
| 4635 | if (ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ArgInfos)) |
| 4636 | return nullptr; |
| 4637 | |
| 4638 | TemplateParameterList *ToTPList = ImportTemplateParameterList( |
| 4639 | FromPartial->getTemplateParameters()); |
| 4640 | if (!ToTPList) |
| 4641 | return nullptr; |
| 4642 | |
| 4643 | auto *ToPartial = PartVarSpecDecl::Create( |
| 4644 | Importer.getToContext(), DC, StartLoc, IdLoc, ToTPList, VarTemplate, |
| 4645 | T, TInfo, D->getStorageClass(), TemplateArgs, ArgInfos); |
| 4646 | |
| 4647 | auto *FromInst = FromPartial->getInstantiatedFromMember(); |
| 4648 | auto *ToInst = cast_or_null<PartVarSpecDecl>(Importer.Import(FromInst)); |
| 4649 | if (FromInst && !ToInst) |
| 4650 | return nullptr; |
| 4651 | |
| 4652 | ToPartial->setInstantiatedFromMember(ToInst); |
| 4653 | if (FromPartial->isMemberSpecialization()) |
| 4654 | ToPartial->setMemberSpecialization(); |
| 4655 | |
| 4656 | D2 = ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4657 | } else { // Full specialization |
| 4658 | D2 = VarTemplateSpecializationDecl::Create( |
| 4659 | Importer.getToContext(), DC, StartLoc, IdLoc, VarTemplate, T, TInfo, |
| 4660 | D->getStorageClass(), TemplateArgs); |
| 4661 | } |
| 4662 | |
| 4663 | SourceLocation POI = D->getPointOfInstantiation(); |
| 4664 | if (POI.isValid()) |
| 4665 | D2->setPointOfInstantiation(Importer.Import(POI)); |
| 4666 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4667 | D2->setSpecializationKind(D->getSpecializationKind()); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4668 | D2->setTemplateArgsInfo(ToTAInfo); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4669 | |
| 4670 | // Add this specialization to the class template. |
| 4671 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 4672 | |
| 4673 | // Import the qualifier, if any. |
| 4674 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
| 4675 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4676 | if (D->isConstexpr()) |
| 4677 | D2->setConstexpr(true); |
| 4678 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4679 | // Add the specialization to this context. |
| 4680 | D2->setLexicalDeclContext(LexicalDC); |
| 4681 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4682 | |
| 4683 | D2->setAccess(D->getAccess()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4684 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4685 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4686 | Importer.Imported(D, D2); |
| 4687 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4688 | // NOTE: isThisDeclarationADefinition() can return DeclarationOnly even if |
| 4689 | // declaration has initializer. Should this be fixed in the AST?.. Anyway, |
| 4690 | // we have to check the declaration for initializer - otherwise, it won't be |
| 4691 | // imported. |
| 4692 | if ((D->isThisDeclarationADefinition() || D->hasInit()) && |
| 4693 | ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4694 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4695 | |
| 4696 | return D2; |
| 4697 | } |
| 4698 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4699 | Decl *ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 4700 | DeclContext *DC, *LexicalDC; |
| 4701 | DeclarationName Name; |
| 4702 | SourceLocation Loc; |
| 4703 | NamedDecl *ToD; |
| 4704 | |
| 4705 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4706 | return nullptr; |
| 4707 | |
| 4708 | if (ToD) |
| 4709 | return ToD; |
| 4710 | |
| 4711 | // Try to find a function in our own ("to") context with the same name, same |
| 4712 | // type, and in the same context as the function we're importing. |
| 4713 | if (!LexicalDC->isFunctionOrMethod()) { |
| 4714 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 4715 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 4716 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4717 | for (auto *FoundDecl : FoundDecls) { |
| 4718 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4719 | continue; |
| 4720 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4721 | if (auto *FoundFunction = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4722 | if (FoundFunction->hasExternalFormalLinkage() && |
| 4723 | D->hasExternalFormalLinkage()) { |
| 4724 | if (IsStructuralMatch(D, FoundFunction)) { |
| 4725 | Importer.Imported(D, FoundFunction); |
| 4726 | // FIXME: Actually try to merge the body and other attributes. |
| 4727 | return FoundFunction; |
| 4728 | } |
| 4729 | } |
| 4730 | } |
| 4731 | } |
| 4732 | } |
| 4733 | |
| 4734 | TemplateParameterList *Params = |
| 4735 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 4736 | if (!Params) |
| 4737 | return nullptr; |
| 4738 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4739 | auto *TemplatedFD = |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4740 | cast_or_null<FunctionDecl>(Importer.Import(D->getTemplatedDecl())); |
| 4741 | if (!TemplatedFD) |
| 4742 | return nullptr; |
| 4743 | |
| 4744 | FunctionTemplateDecl *ToFunc = FunctionTemplateDecl::Create( |
| 4745 | Importer.getToContext(), DC, Loc, Name, Params, TemplatedFD); |
| 4746 | |
| 4747 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| 4748 | ToFunc->setAccess(D->getAccess()); |
| 4749 | ToFunc->setLexicalDeclContext(LexicalDC); |
| 4750 | Importer.Imported(D, ToFunc); |
| 4751 | |
| 4752 | LexicalDC->addDeclInternal(ToFunc); |
| 4753 | return ToFunc; |
| 4754 | } |
| 4755 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4756 | //---------------------------------------------------------------------------- |
| 4757 | // Import Statements |
| 4758 | //---------------------------------------------------------------------------- |
| 4759 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4760 | DeclGroupRef ASTNodeImporter::ImportDeclGroup(DeclGroupRef DG) { |
| 4761 | if (DG.isNull()) |
| 4762 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 4763 | size_t NumDecls = DG.end() - DG.begin(); |
| 4764 | SmallVector<Decl *, 1> ToDecls(NumDecls); |
| 4765 | auto &_Importer = this->Importer; |
| 4766 | std::transform(DG.begin(), DG.end(), ToDecls.begin(), |
| 4767 | [&_Importer](Decl *D) -> Decl * { |
| 4768 | return _Importer.Import(D); |
| 4769 | }); |
| 4770 | return DeclGroupRef::Create(Importer.getToContext(), |
| 4771 | ToDecls.begin(), |
| 4772 | NumDecls); |
| 4773 | } |
| 4774 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4775 | Stmt *ASTNodeImporter::VisitStmt(Stmt *S) { |
| 4776 | Importer.FromDiag(S->getLocStart(), diag::err_unsupported_ast_node) |
| 4777 | << S->getStmtClassName(); |
| 4778 | return nullptr; |
| 4779 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4780 | |
| 4781 | Stmt *ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
| 4782 | SmallVector<IdentifierInfo *, 4> Names; |
| 4783 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 4784 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 4785 | // ToII is nullptr when no symbolic name is given for output operand |
| 4786 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 4787 | if (!ToII && S->getOutputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4788 | return nullptr; |
| 4789 | Names.push_back(ToII); |
| 4790 | } |
| 4791 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 4792 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 4793 | // ToII is nullptr when no symbolic name is given for input operand |
| 4794 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 4795 | if (!ToII && S->getInputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4796 | return nullptr; |
| 4797 | Names.push_back(ToII); |
| 4798 | } |
| 4799 | |
| 4800 | SmallVector<StringLiteral *, 4> Clobbers; |
| 4801 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4802 | auto *Clobber = cast_or_null<StringLiteral>( |
| 4803 | Importer.Import(S->getClobberStringLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4804 | if (!Clobber) |
| 4805 | return nullptr; |
| 4806 | Clobbers.push_back(Clobber); |
| 4807 | } |
| 4808 | |
| 4809 | SmallVector<StringLiteral *, 4> Constraints; |
| 4810 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4811 | auto *Output = cast_or_null<StringLiteral>( |
| 4812 | Importer.Import(S->getOutputConstraintLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4813 | if (!Output) |
| 4814 | return nullptr; |
| 4815 | Constraints.push_back(Output); |
| 4816 | } |
| 4817 | |
| 4818 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4819 | auto *Input = cast_or_null<StringLiteral>( |
| 4820 | Importer.Import(S->getInputConstraintLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4821 | if (!Input) |
| 4822 | return nullptr; |
| 4823 | Constraints.push_back(Input); |
| 4824 | } |
| 4825 | |
| 4826 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4827 | if (ImportContainerChecked(S->outputs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4828 | return nullptr; |
| 4829 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4830 | if (ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4831 | return nullptr; |
| 4832 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4833 | auto *AsmStr = cast_or_null<StringLiteral>( |
| 4834 | Importer.Import(S->getAsmString())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4835 | if (!AsmStr) |
| 4836 | return nullptr; |
| 4837 | |
| 4838 | return new (Importer.getToContext()) GCCAsmStmt( |
| 4839 | Importer.getToContext(), |
| 4840 | Importer.Import(S->getAsmLoc()), |
| 4841 | S->isSimple(), |
| 4842 | S->isVolatile(), |
| 4843 | S->getNumOutputs(), |
| 4844 | S->getNumInputs(), |
| 4845 | Names.data(), |
| 4846 | Constraints.data(), |
| 4847 | Exprs.data(), |
| 4848 | AsmStr, |
| 4849 | S->getNumClobbers(), |
| 4850 | Clobbers.data(), |
| 4851 | Importer.Import(S->getRParenLoc())); |
| 4852 | } |
| 4853 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4854 | Stmt *ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 4855 | DeclGroupRef ToDG = ImportDeclGroup(S->getDeclGroup()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4856 | for (auto *ToD : ToDG) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4857 | if (!ToD) |
| 4858 | return nullptr; |
| 4859 | } |
| 4860 | SourceLocation ToStartLoc = Importer.Import(S->getStartLoc()); |
| 4861 | SourceLocation ToEndLoc = Importer.Import(S->getEndLoc()); |
| 4862 | return new (Importer.getToContext()) DeclStmt(ToDG, ToStartLoc, ToEndLoc); |
| 4863 | } |
| 4864 | |
| 4865 | Stmt *ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 4866 | SourceLocation ToSemiLoc = Importer.Import(S->getSemiLoc()); |
| 4867 | return new (Importer.getToContext()) NullStmt(ToSemiLoc, |
| 4868 | S->hasLeadingEmptyMacro()); |
| 4869 | } |
| 4870 | |
| 4871 | Stmt *ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4872 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4873 | |
| 4874 | if (ImportContainerChecked(S->body(), ToStmts)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 4875 | return nullptr; |
| 4876 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4877 | SourceLocation ToLBraceLoc = Importer.Import(S->getLBracLoc()); |
| 4878 | SourceLocation ToRBraceLoc = Importer.Import(S->getRBracLoc()); |
Benjamin Kramer | 0742090 | 2017-12-24 16:24:20 +0000 | [diff] [blame] | 4879 | return CompoundStmt::Create(Importer.getToContext(), ToStmts, ToLBraceLoc, |
| 4880 | ToRBraceLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4881 | } |
| 4882 | |
| 4883 | Stmt *ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 4884 | Expr *ToLHS = Importer.Import(S->getLHS()); |
| 4885 | if (!ToLHS) |
| 4886 | return nullptr; |
| 4887 | Expr *ToRHS = Importer.Import(S->getRHS()); |
| 4888 | if (!ToRHS && S->getRHS()) |
| 4889 | return nullptr; |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 4890 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4891 | if (!ToSubStmt && S->getSubStmt()) |
| 4892 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4893 | SourceLocation ToCaseLoc = Importer.Import(S->getCaseLoc()); |
| 4894 | SourceLocation ToEllipsisLoc = Importer.Import(S->getEllipsisLoc()); |
| 4895 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4896 | auto *ToStmt = new (Importer.getToContext()) |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 4897 | CaseStmt(ToLHS, ToRHS, ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
| 4898 | ToStmt->setSubStmt(ToSubStmt); |
| 4899 | return ToStmt; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4900 | } |
| 4901 | |
| 4902 | Stmt *ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 4903 | SourceLocation ToDefaultLoc = Importer.Import(S->getDefaultLoc()); |
| 4904 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 4905 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4906 | if (!ToSubStmt && S->getSubStmt()) |
| 4907 | return nullptr; |
| 4908 | return new (Importer.getToContext()) DefaultStmt(ToDefaultLoc, ToColonLoc, |
| 4909 | ToSubStmt); |
| 4910 | } |
| 4911 | |
| 4912 | Stmt *ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 4913 | SourceLocation ToIdentLoc = Importer.Import(S->getIdentLoc()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4914 | auto *ToLabelDecl = cast_or_null<LabelDecl>(Importer.Import(S->getDecl())); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4915 | if (!ToLabelDecl && S->getDecl()) |
| 4916 | return nullptr; |
| 4917 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4918 | if (!ToSubStmt && S->getSubStmt()) |
| 4919 | return nullptr; |
| 4920 | return new (Importer.getToContext()) LabelStmt(ToIdentLoc, ToLabelDecl, |
| 4921 | ToSubStmt); |
| 4922 | } |
| 4923 | |
| 4924 | Stmt *ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 4925 | SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc()); |
| 4926 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 4927 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 4928 | if (ImportContainerChecked(FromAttrs, ToAttrs)) |
| 4929 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4930 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4931 | if (!ToSubStmt && S->getSubStmt()) |
| 4932 | return nullptr; |
| 4933 | return AttributedStmt::Create(Importer.getToContext(), ToAttrLoc, |
| 4934 | ToAttrs, ToSubStmt); |
| 4935 | } |
| 4936 | |
| 4937 | Stmt *ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 4938 | SourceLocation ToIfLoc = Importer.Import(S->getIfLoc()); |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4939 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4940 | if (!ToInit && S->getInit()) |
| 4941 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4942 | VarDecl *ToConditionVariable = nullptr; |
| 4943 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4944 | ToConditionVariable = |
| 4945 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4946 | if (!ToConditionVariable) |
| 4947 | return nullptr; |
| 4948 | } |
| 4949 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4950 | if (!ToCondition && S->getCond()) |
| 4951 | return nullptr; |
| 4952 | Stmt *ToThenStmt = Importer.Import(S->getThen()); |
| 4953 | if (!ToThenStmt && S->getThen()) |
| 4954 | return nullptr; |
| 4955 | SourceLocation ToElseLoc = Importer.Import(S->getElseLoc()); |
| 4956 | Stmt *ToElseStmt = Importer.Import(S->getElse()); |
| 4957 | if (!ToElseStmt && S->getElse()) |
| 4958 | return nullptr; |
| 4959 | return new (Importer.getToContext()) IfStmt(Importer.getToContext(), |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 4960 | ToIfLoc, S->isConstexpr(), |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4961 | ToInit, |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 4962 | ToConditionVariable, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4963 | ToCondition, ToThenStmt, |
| 4964 | ToElseLoc, ToElseStmt); |
| 4965 | } |
| 4966 | |
| 4967 | Stmt *ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4968 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4969 | if (!ToInit && S->getInit()) |
| 4970 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4971 | VarDecl *ToConditionVariable = nullptr; |
| 4972 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4973 | ToConditionVariable = |
| 4974 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4975 | if (!ToConditionVariable) |
| 4976 | return nullptr; |
| 4977 | } |
| 4978 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4979 | if (!ToCondition && S->getCond()) |
| 4980 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4981 | auto *ToStmt = new (Importer.getToContext()) SwitchStmt( |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4982 | Importer.getToContext(), ToInit, |
| 4983 | ToConditionVariable, ToCondition); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4984 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4985 | if (!ToBody && S->getBody()) |
| 4986 | return nullptr; |
| 4987 | ToStmt->setBody(ToBody); |
| 4988 | ToStmt->setSwitchLoc(Importer.Import(S->getSwitchLoc())); |
| 4989 | // Now we have to re-chain the cases. |
| 4990 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 4991 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 4992 | SC = SC->getNextSwitchCase()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4993 | auto *ToSC = dyn_cast_or_null<SwitchCase>(Importer.Import(SC)); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4994 | if (!ToSC) |
| 4995 | return nullptr; |
| 4996 | if (LastChainedSwitchCase) |
| 4997 | LastChainedSwitchCase->setNextSwitchCase(ToSC); |
| 4998 | else |
| 4999 | ToStmt->setSwitchCaseList(ToSC); |
| 5000 | LastChainedSwitchCase = ToSC; |
| 5001 | } |
| 5002 | return ToStmt; |
| 5003 | } |
| 5004 | |
| 5005 | Stmt *ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 5006 | VarDecl *ToConditionVariable = nullptr; |
| 5007 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 5008 | ToConditionVariable = |
| 5009 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 5010 | if (!ToConditionVariable) |
| 5011 | return nullptr; |
| 5012 | } |
| 5013 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5014 | if (!ToCondition && S->getCond()) |
| 5015 | return nullptr; |
| 5016 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5017 | if (!ToBody && S->getBody()) |
| 5018 | return nullptr; |
| 5019 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 5020 | return new (Importer.getToContext()) WhileStmt(Importer.getToContext(), |
| 5021 | ToConditionVariable, |
| 5022 | ToCondition, ToBody, |
| 5023 | ToWhileLoc); |
| 5024 | } |
| 5025 | |
| 5026 | Stmt *ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 5027 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5028 | if (!ToBody && S->getBody()) |
| 5029 | return nullptr; |
| 5030 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5031 | if (!ToCondition && S->getCond()) |
| 5032 | return nullptr; |
| 5033 | SourceLocation ToDoLoc = Importer.Import(S->getDoLoc()); |
| 5034 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 5035 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5036 | return new (Importer.getToContext()) DoStmt(ToBody, ToCondition, |
| 5037 | ToDoLoc, ToWhileLoc, |
| 5038 | ToRParenLoc); |
| 5039 | } |
| 5040 | |
| 5041 | Stmt *ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 5042 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 5043 | if (!ToInit && S->getInit()) |
| 5044 | return nullptr; |
| 5045 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5046 | if (!ToCondition && S->getCond()) |
| 5047 | return nullptr; |
| 5048 | VarDecl *ToConditionVariable = nullptr; |
| 5049 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 5050 | ToConditionVariable = |
| 5051 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 5052 | if (!ToConditionVariable) |
| 5053 | return nullptr; |
| 5054 | } |
| 5055 | Expr *ToInc = Importer.Import(S->getInc()); |
| 5056 | if (!ToInc && S->getInc()) |
| 5057 | return nullptr; |
| 5058 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5059 | if (!ToBody && S->getBody()) |
| 5060 | return nullptr; |
| 5061 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 5062 | SourceLocation ToLParenLoc = Importer.Import(S->getLParenLoc()); |
| 5063 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5064 | return new (Importer.getToContext()) ForStmt(Importer.getToContext(), |
| 5065 | ToInit, ToCondition, |
| 5066 | ToConditionVariable, |
| 5067 | ToInc, ToBody, |
| 5068 | ToForLoc, ToLParenLoc, |
| 5069 | ToRParenLoc); |
| 5070 | } |
| 5071 | |
| 5072 | Stmt *ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 5073 | LabelDecl *ToLabel = nullptr; |
| 5074 | if (LabelDecl *FromLabel = S->getLabel()) { |
| 5075 | ToLabel = dyn_cast_or_null<LabelDecl>(Importer.Import(FromLabel)); |
| 5076 | if (!ToLabel) |
| 5077 | return nullptr; |
| 5078 | } |
| 5079 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 5080 | SourceLocation ToLabelLoc = Importer.Import(S->getLabelLoc()); |
| 5081 | return new (Importer.getToContext()) GotoStmt(ToLabel, |
| 5082 | ToGotoLoc, ToLabelLoc); |
| 5083 | } |
| 5084 | |
| 5085 | Stmt *ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 5086 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 5087 | SourceLocation ToStarLoc = Importer.Import(S->getStarLoc()); |
| 5088 | Expr *ToTarget = Importer.Import(S->getTarget()); |
| 5089 | if (!ToTarget && S->getTarget()) |
| 5090 | return nullptr; |
| 5091 | return new (Importer.getToContext()) IndirectGotoStmt(ToGotoLoc, ToStarLoc, |
| 5092 | ToTarget); |
| 5093 | } |
| 5094 | |
| 5095 | Stmt *ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 5096 | SourceLocation ToContinueLoc = Importer.Import(S->getContinueLoc()); |
| 5097 | return new (Importer.getToContext()) ContinueStmt(ToContinueLoc); |
| 5098 | } |
| 5099 | |
| 5100 | Stmt *ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 5101 | SourceLocation ToBreakLoc = Importer.Import(S->getBreakLoc()); |
| 5102 | return new (Importer.getToContext()) BreakStmt(ToBreakLoc); |
| 5103 | } |
| 5104 | |
| 5105 | Stmt *ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 5106 | SourceLocation ToRetLoc = Importer.Import(S->getReturnLoc()); |
| 5107 | Expr *ToRetExpr = Importer.Import(S->getRetValue()); |
| 5108 | if (!ToRetExpr && S->getRetValue()) |
| 5109 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5110 | auto *NRVOCandidate = const_cast<VarDecl *>(S->getNRVOCandidate()); |
| 5111 | auto *ToNRVOCandidate = cast_or_null<VarDecl>(Importer.Import(NRVOCandidate)); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5112 | if (!ToNRVOCandidate && NRVOCandidate) |
| 5113 | return nullptr; |
| 5114 | return new (Importer.getToContext()) ReturnStmt(ToRetLoc, ToRetExpr, |
| 5115 | ToNRVOCandidate); |
| 5116 | } |
| 5117 | |
| 5118 | Stmt *ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 5119 | SourceLocation ToCatchLoc = Importer.Import(S->getCatchLoc()); |
| 5120 | VarDecl *ToExceptionDecl = nullptr; |
| 5121 | if (VarDecl *FromExceptionDecl = S->getExceptionDecl()) { |
| 5122 | ToExceptionDecl = |
| 5123 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 5124 | if (!ToExceptionDecl) |
| 5125 | return nullptr; |
| 5126 | } |
| 5127 | Stmt *ToHandlerBlock = Importer.Import(S->getHandlerBlock()); |
| 5128 | if (!ToHandlerBlock && S->getHandlerBlock()) |
| 5129 | return nullptr; |
| 5130 | return new (Importer.getToContext()) CXXCatchStmt(ToCatchLoc, |
| 5131 | ToExceptionDecl, |
| 5132 | ToHandlerBlock); |
| 5133 | } |
| 5134 | |
| 5135 | Stmt *ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 5136 | SourceLocation ToTryLoc = Importer.Import(S->getTryLoc()); |
| 5137 | Stmt *ToTryBlock = Importer.Import(S->getTryBlock()); |
| 5138 | if (!ToTryBlock && S->getTryBlock()) |
| 5139 | return nullptr; |
| 5140 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 5141 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 5142 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
| 5143 | if (Stmt *ToHandler = Importer.Import(FromHandler)) |
| 5144 | ToHandlers[HI] = ToHandler; |
| 5145 | else |
| 5146 | return nullptr; |
| 5147 | } |
| 5148 | return CXXTryStmt::Create(Importer.getToContext(), ToTryLoc, ToTryBlock, |
| 5149 | ToHandlers); |
| 5150 | } |
| 5151 | |
| 5152 | Stmt *ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5153 | auto *ToRange = |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5154 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getRangeStmt())); |
| 5155 | if (!ToRange && S->getRangeStmt()) |
| 5156 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5157 | auto *ToBegin = |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 5158 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getBeginStmt())); |
| 5159 | if (!ToBegin && S->getBeginStmt()) |
| 5160 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5161 | auto *ToEnd = |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 5162 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getEndStmt())); |
| 5163 | if (!ToEnd && S->getEndStmt()) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5164 | return nullptr; |
| 5165 | Expr *ToCond = Importer.Import(S->getCond()); |
| 5166 | if (!ToCond && S->getCond()) |
| 5167 | return nullptr; |
| 5168 | Expr *ToInc = Importer.Import(S->getInc()); |
| 5169 | if (!ToInc && S->getInc()) |
| 5170 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5171 | auto *ToLoopVar = |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5172 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getLoopVarStmt())); |
| 5173 | if (!ToLoopVar && S->getLoopVarStmt()) |
| 5174 | return nullptr; |
| 5175 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5176 | if (!ToBody && S->getBody()) |
| 5177 | return nullptr; |
| 5178 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 5179 | SourceLocation ToCoawaitLoc = Importer.Import(S->getCoawaitLoc()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5180 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 5181 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 5182 | return new (Importer.getToContext()) CXXForRangeStmt(ToRange, ToBegin, ToEnd, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5183 | ToCond, ToInc, |
| 5184 | ToLoopVar, ToBody, |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 5185 | ToForLoc, ToCoawaitLoc, |
| 5186 | ToColonLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5187 | } |
| 5188 | |
| 5189 | Stmt *ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 5190 | Stmt *ToElem = Importer.Import(S->getElement()); |
| 5191 | if (!ToElem && S->getElement()) |
| 5192 | return nullptr; |
| 5193 | Expr *ToCollect = Importer.Import(S->getCollection()); |
| 5194 | if (!ToCollect && S->getCollection()) |
| 5195 | return nullptr; |
| 5196 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5197 | if (!ToBody && S->getBody()) |
| 5198 | return nullptr; |
| 5199 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 5200 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5201 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElem, |
| 5202 | ToCollect, |
| 5203 | ToBody, ToForLoc, |
| 5204 | ToRParenLoc); |
| 5205 | } |
| 5206 | |
| 5207 | Stmt *ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 5208 | SourceLocation ToAtCatchLoc = Importer.Import(S->getAtCatchLoc()); |
| 5209 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5210 | VarDecl *ToExceptionDecl = nullptr; |
| 5211 | if (VarDecl *FromExceptionDecl = S->getCatchParamDecl()) { |
| 5212 | ToExceptionDecl = |
| 5213 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 5214 | if (!ToExceptionDecl) |
| 5215 | return nullptr; |
| 5216 | } |
| 5217 | Stmt *ToBody = Importer.Import(S->getCatchBody()); |
| 5218 | if (!ToBody && S->getCatchBody()) |
| 5219 | return nullptr; |
| 5220 | return new (Importer.getToContext()) ObjCAtCatchStmt(ToAtCatchLoc, |
| 5221 | ToRParenLoc, |
| 5222 | ToExceptionDecl, |
| 5223 | ToBody); |
| 5224 | } |
| 5225 | |
| 5226 | Stmt *ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 5227 | SourceLocation ToAtFinallyLoc = Importer.Import(S->getAtFinallyLoc()); |
| 5228 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyBody()); |
| 5229 | if (!ToAtFinallyStmt && S->getFinallyBody()) |
| 5230 | return nullptr; |
| 5231 | return new (Importer.getToContext()) ObjCAtFinallyStmt(ToAtFinallyLoc, |
| 5232 | ToAtFinallyStmt); |
| 5233 | } |
| 5234 | |
| 5235 | Stmt *ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 5236 | SourceLocation ToAtTryLoc = Importer.Import(S->getAtTryLoc()); |
| 5237 | Stmt *ToAtTryStmt = Importer.Import(S->getTryBody()); |
| 5238 | if (!ToAtTryStmt && S->getTryBody()) |
| 5239 | return nullptr; |
| 5240 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 5241 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 5242 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
| 5243 | if (Stmt *ToCatchStmt = Importer.Import(FromCatchStmt)) |
| 5244 | ToCatchStmts[CI] = ToCatchStmt; |
| 5245 | else |
| 5246 | return nullptr; |
| 5247 | } |
| 5248 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyStmt()); |
| 5249 | if (!ToAtFinallyStmt && S->getFinallyStmt()) |
| 5250 | return nullptr; |
| 5251 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
| 5252 | ToAtTryLoc, ToAtTryStmt, |
| 5253 | ToCatchStmts.begin(), ToCatchStmts.size(), |
| 5254 | ToAtFinallyStmt); |
| 5255 | } |
| 5256 | |
| 5257 | Stmt *ASTNodeImporter::VisitObjCAtSynchronizedStmt |
| 5258 | (ObjCAtSynchronizedStmt *S) { |
| 5259 | SourceLocation ToAtSynchronizedLoc = |
| 5260 | Importer.Import(S->getAtSynchronizedLoc()); |
| 5261 | Expr *ToSynchExpr = Importer.Import(S->getSynchExpr()); |
| 5262 | if (!ToSynchExpr && S->getSynchExpr()) |
| 5263 | return nullptr; |
| 5264 | Stmt *ToSynchBody = Importer.Import(S->getSynchBody()); |
| 5265 | if (!ToSynchBody && S->getSynchBody()) |
| 5266 | return nullptr; |
| 5267 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 5268 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 5269 | } |
| 5270 | |
| 5271 | Stmt *ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 5272 | SourceLocation ToAtThrowLoc = Importer.Import(S->getThrowLoc()); |
| 5273 | Expr *ToThrow = Importer.Import(S->getThrowExpr()); |
| 5274 | if (!ToThrow && S->getThrowExpr()) |
| 5275 | return nullptr; |
| 5276 | return new (Importer.getToContext()) ObjCAtThrowStmt(ToAtThrowLoc, ToThrow); |
| 5277 | } |
| 5278 | |
| 5279 | Stmt *ASTNodeImporter::VisitObjCAutoreleasePoolStmt |
| 5280 | (ObjCAutoreleasePoolStmt *S) { |
| 5281 | SourceLocation ToAtLoc = Importer.Import(S->getAtLoc()); |
| 5282 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5283 | if (!ToSubStmt && S->getSubStmt()) |
| 5284 | return nullptr; |
| 5285 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(ToAtLoc, |
| 5286 | ToSubStmt); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5287 | } |
| 5288 | |
| 5289 | //---------------------------------------------------------------------------- |
| 5290 | // Import Expressions |
| 5291 | //---------------------------------------------------------------------------- |
| 5292 | Expr *ASTNodeImporter::VisitExpr(Expr *E) { |
| 5293 | Importer.FromDiag(E->getLocStart(), diag::err_unsupported_ast_node) |
| 5294 | << E->getStmtClassName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5295 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5296 | } |
| 5297 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5298 | Expr *ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 5299 | QualType T = Importer.Import(E->getType()); |
| 5300 | if (T.isNull()) |
| 5301 | return nullptr; |
| 5302 | |
| 5303 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5304 | if (!SubExpr && E->getSubExpr()) |
| 5305 | return nullptr; |
| 5306 | |
| 5307 | TypeSourceInfo *TInfo = Importer.Import(E->getWrittenTypeInfo()); |
| 5308 | if (!TInfo) |
| 5309 | return nullptr; |
| 5310 | |
| 5311 | return new (Importer.getToContext()) VAArgExpr( |
| 5312 | Importer.Import(E->getBuiltinLoc()), SubExpr, TInfo, |
| 5313 | Importer.Import(E->getRParenLoc()), T, E->isMicrosoftABI()); |
| 5314 | } |
| 5315 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5316 | Expr *ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 5317 | QualType T = Importer.Import(E->getType()); |
| 5318 | if (T.isNull()) |
| 5319 | return nullptr; |
| 5320 | |
| 5321 | return new (Importer.getToContext()) GNUNullExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5322 | T, Importer.Import(E->getLocStart())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5323 | } |
| 5324 | |
| 5325 | Expr *ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 5326 | QualType T = Importer.Import(E->getType()); |
| 5327 | if (T.isNull()) |
| 5328 | return nullptr; |
| 5329 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5330 | auto *SL = cast_or_null<StringLiteral>(Importer.Import(E->getFunctionName())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5331 | if (!SL && E->getFunctionName()) |
| 5332 | return nullptr; |
| 5333 | |
| 5334 | return new (Importer.getToContext()) PredefinedExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5335 | Importer.Import(E->getLocStart()), T, E->getIdentType(), SL); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5336 | } |
| 5337 | |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5338 | Expr *ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5339 | auto *ToD = cast_or_null<ValueDecl>(Importer.Import(E->getDecl())); |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5340 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5341 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5342 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5343 | NamedDecl *FoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5344 | if (E->getDecl() != E->getFoundDecl()) { |
| 5345 | FoundD = cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl())); |
| 5346 | if (!FoundD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5347 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5348 | } |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5349 | |
| 5350 | QualType T = Importer.Import(E->getType()); |
| 5351 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5352 | return nullptr; |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5353 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5354 | TemplateArgumentListInfo ToTAInfo; |
| 5355 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 5356 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5357 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 5358 | return nullptr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5359 | ResInfo = &ToTAInfo; |
| 5360 | } |
| 5361 | |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5362 | DeclRefExpr *DRE = DeclRefExpr::Create(Importer.getToContext(), |
| 5363 | Importer.Import(E->getQualifierLoc()), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 5364 | Importer.Import(E->getTemplateKeywordLoc()), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5365 | ToD, |
Alexey Bataev | 19acc3d | 2015-01-12 10:17:46 +0000 | [diff] [blame] | 5366 | E->refersToEnclosingVariableOrCapture(), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5367 | Importer.Import(E->getLocation()), |
| 5368 | T, E->getValueKind(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5369 | FoundD, ResInfo); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5370 | if (E->hadMultipleCandidates()) |
| 5371 | DRE->setHadMultipleCandidates(true); |
| 5372 | return DRE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5373 | } |
| 5374 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5375 | Expr *ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 5376 | QualType T = Importer.Import(E->getType()); |
| 5377 | if (T.isNull()) |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5378 | return nullptr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5379 | |
| 5380 | return new (Importer.getToContext()) ImplicitValueInitExpr(T); |
| 5381 | } |
| 5382 | |
| 5383 | ASTNodeImporter::Designator |
| 5384 | ASTNodeImporter::ImportDesignator(const Designator &D) { |
| 5385 | if (D.isFieldDesignator()) { |
| 5386 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 5387 | // Caller checks for import error |
| 5388 | return Designator(ToFieldName, Importer.Import(D.getDotLoc()), |
| 5389 | Importer.Import(D.getFieldLoc())); |
| 5390 | } |
| 5391 | if (D.isArrayDesignator()) |
| 5392 | return Designator(D.getFirstExprIndex(), |
| 5393 | Importer.Import(D.getLBracketLoc()), |
| 5394 | Importer.Import(D.getRBracketLoc())); |
| 5395 | |
| 5396 | assert(D.isArrayRangeDesignator()); |
| 5397 | return Designator(D.getFirstExprIndex(), |
| 5398 | Importer.Import(D.getLBracketLoc()), |
| 5399 | Importer.Import(D.getEllipsisLoc()), |
| 5400 | Importer.Import(D.getRBracketLoc())); |
| 5401 | } |
| 5402 | |
| 5403 | |
| 5404 | Expr *ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *DIE) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5405 | auto *Init = cast_or_null<Expr>(Importer.Import(DIE->getInit())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5406 | if (!Init) |
| 5407 | return nullptr; |
| 5408 | |
| 5409 | SmallVector<Expr *, 4> IndexExprs(DIE->getNumSubExprs() - 1); |
| 5410 | // List elements from the second, the first is Init itself |
| 5411 | for (unsigned I = 1, E = DIE->getNumSubExprs(); I < E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5412 | if (auto *Arg = cast_or_null<Expr>(Importer.Import(DIE->getSubExpr(I)))) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5413 | IndexExprs[I - 1] = Arg; |
| 5414 | else |
| 5415 | return nullptr; |
| 5416 | } |
| 5417 | |
| 5418 | SmallVector<Designator, 4> Designators(DIE->size()); |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5419 | llvm::transform(DIE->designators(), Designators.begin(), |
| 5420 | [this](const Designator &D) -> Designator { |
| 5421 | return ImportDesignator(D); |
| 5422 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5423 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5424 | for (const auto &D : DIE->designators()) |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5425 | if (D.isFieldDesignator() && !D.getFieldName()) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5426 | return nullptr; |
| 5427 | |
| 5428 | return DesignatedInitExpr::Create( |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5429 | Importer.getToContext(), Designators, |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5430 | IndexExprs, Importer.Import(DIE->getEqualOrColonLoc()), |
| 5431 | DIE->usesGNUSyntax(), Init); |
| 5432 | } |
| 5433 | |
| 5434 | Expr *ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 5435 | QualType T = Importer.Import(E->getType()); |
| 5436 | if (T.isNull()) |
| 5437 | return nullptr; |
| 5438 | |
| 5439 | return new (Importer.getToContext()) |
| 5440 | CXXNullPtrLiteralExpr(T, Importer.Import(E->getLocation())); |
| 5441 | } |
| 5442 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5443 | Expr *ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 5444 | QualType T = Importer.Import(E->getType()); |
| 5445 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5446 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5447 | |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 5448 | return IntegerLiteral::Create(Importer.getToContext(), |
| 5449 | E->getValue(), T, |
| 5450 | Importer.Import(E->getLocation())); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5451 | } |
| 5452 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5453 | Expr *ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 5454 | QualType T = Importer.Import(E->getType()); |
| 5455 | if (T.isNull()) |
| 5456 | return nullptr; |
| 5457 | |
| 5458 | return FloatingLiteral::Create(Importer.getToContext(), |
| 5459 | E->getValue(), E->isExact(), T, |
| 5460 | Importer.Import(E->getLocation())); |
| 5461 | } |
| 5462 | |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 5463 | Expr *ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 5464 | QualType T = Importer.Import(E->getType()); |
| 5465 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5466 | return nullptr; |
| 5467 | |
Douglas Gregor | fb65e59 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 5468 | return new (Importer.getToContext()) CharacterLiteral(E->getValue(), |
| 5469 | E->getKind(), T, |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 5470 | Importer.Import(E->getLocation())); |
| 5471 | } |
| 5472 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5473 | Expr *ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 5474 | QualType T = Importer.Import(E->getType()); |
| 5475 | if (T.isNull()) |
| 5476 | return nullptr; |
| 5477 | |
| 5478 | SmallVector<SourceLocation, 4> Locations(E->getNumConcatenated()); |
| 5479 | ImportArray(E->tokloc_begin(), E->tokloc_end(), Locations.begin()); |
| 5480 | |
| 5481 | return StringLiteral::Create(Importer.getToContext(), E->getBytes(), |
| 5482 | E->getKind(), E->isPascal(), T, |
| 5483 | Locations.data(), Locations.size()); |
| 5484 | } |
| 5485 | |
| 5486 | Expr *ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 5487 | QualType T = Importer.Import(E->getType()); |
| 5488 | if (T.isNull()) |
| 5489 | return nullptr; |
| 5490 | |
| 5491 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeSourceInfo()); |
| 5492 | if (!TInfo) |
| 5493 | return nullptr; |
| 5494 | |
| 5495 | Expr *Init = Importer.Import(E->getInitializer()); |
| 5496 | if (!Init) |
| 5497 | return nullptr; |
| 5498 | |
| 5499 | return new (Importer.getToContext()) CompoundLiteralExpr( |
| 5500 | Importer.Import(E->getLParenLoc()), TInfo, T, E->getValueKind(), |
| 5501 | Init, E->isFileScope()); |
| 5502 | } |
| 5503 | |
| 5504 | Expr *ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 5505 | QualType T = Importer.Import(E->getType()); |
| 5506 | if (T.isNull()) |
| 5507 | return nullptr; |
| 5508 | |
| 5509 | SmallVector<Expr *, 6> Exprs(E->getNumSubExprs()); |
| 5510 | if (ImportArrayChecked( |
| 5511 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 5512 | Exprs.begin())) |
| 5513 | return nullptr; |
| 5514 | |
| 5515 | return new (Importer.getToContext()) AtomicExpr( |
| 5516 | Importer.Import(E->getBuiltinLoc()), Exprs, T, E->getOp(), |
| 5517 | Importer.Import(E->getRParenLoc())); |
| 5518 | } |
| 5519 | |
| 5520 | Expr *ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 5521 | QualType T = Importer.Import(E->getType()); |
| 5522 | if (T.isNull()) |
| 5523 | return nullptr; |
| 5524 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5525 | auto *ToLabel = cast_or_null<LabelDecl>(Importer.Import(E->getLabel())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5526 | if (!ToLabel) |
| 5527 | return nullptr; |
| 5528 | |
| 5529 | return new (Importer.getToContext()) AddrLabelExpr( |
| 5530 | Importer.Import(E->getAmpAmpLoc()), Importer.Import(E->getLabelLoc()), |
| 5531 | ToLabel, T); |
| 5532 | } |
| 5533 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5534 | Expr *ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 5535 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5536 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5537 | return nullptr; |
| 5538 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5539 | return new (Importer.getToContext()) |
| 5540 | ParenExpr(Importer.Import(E->getLParen()), |
| 5541 | Importer.Import(E->getRParen()), |
| 5542 | SubExpr); |
| 5543 | } |
| 5544 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5545 | Expr *ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 5546 | SmallVector<Expr *, 4> Exprs(E->getNumExprs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5547 | if (ImportContainerChecked(E->exprs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5548 | return nullptr; |
| 5549 | |
| 5550 | return new (Importer.getToContext()) ParenListExpr( |
| 5551 | Importer.getToContext(), Importer.Import(E->getLParenLoc()), |
| 5552 | Exprs, Importer.Import(E->getLParenLoc())); |
| 5553 | } |
| 5554 | |
| 5555 | Expr *ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 5556 | QualType T = Importer.Import(E->getType()); |
| 5557 | if (T.isNull()) |
| 5558 | return nullptr; |
| 5559 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5560 | auto *ToSubStmt = cast_or_null<CompoundStmt>( |
| 5561 | Importer.Import(E->getSubStmt())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5562 | if (!ToSubStmt && E->getSubStmt()) |
| 5563 | return nullptr; |
| 5564 | |
| 5565 | return new (Importer.getToContext()) StmtExpr(ToSubStmt, T, |
| 5566 | Importer.Import(E->getLParenLoc()), Importer.Import(E->getRParenLoc())); |
| 5567 | } |
| 5568 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5569 | Expr *ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 5570 | QualType T = Importer.Import(E->getType()); |
| 5571 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5572 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5573 | |
| 5574 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5575 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5576 | return nullptr; |
| 5577 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 5578 | return new (Importer.getToContext()) UnaryOperator( |
| 5579 | SubExpr, E->getOpcode(), T, E->getValueKind(), E->getObjectKind(), |
| 5580 | Importer.Import(E->getOperatorLoc()), E->canOverflow()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5581 | } |
| 5582 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 5583 | Expr * |
| 5584 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5585 | QualType ResultType = Importer.Import(E->getType()); |
| 5586 | |
| 5587 | if (E->isArgumentType()) { |
| 5588 | TypeSourceInfo *TInfo = Importer.Import(E->getArgumentTypeInfo()); |
| 5589 | if (!TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5590 | return nullptr; |
| 5591 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5592 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 5593 | TInfo, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5594 | Importer.Import(E->getOperatorLoc()), |
| 5595 | Importer.Import(E->getRParenLoc())); |
| 5596 | } |
| 5597 | |
| 5598 | Expr *SubExpr = Importer.Import(E->getArgumentExpr()); |
| 5599 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5600 | return nullptr; |
| 5601 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5602 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 5603 | SubExpr, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5604 | Importer.Import(E->getOperatorLoc()), |
| 5605 | Importer.Import(E->getRParenLoc())); |
| 5606 | } |
| 5607 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5608 | Expr *ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 5609 | QualType T = Importer.Import(E->getType()); |
| 5610 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5611 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5612 | |
| 5613 | Expr *LHS = Importer.Import(E->getLHS()); |
| 5614 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5615 | return nullptr; |
| 5616 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5617 | Expr *RHS = Importer.Import(E->getRHS()); |
| 5618 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5619 | return nullptr; |
| 5620 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5621 | return new (Importer.getToContext()) BinaryOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 5622 | T, E->getValueKind(), |
| 5623 | E->getObjectKind(), |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 5624 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 5625 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5626 | } |
| 5627 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5628 | Expr *ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 5629 | QualType T = Importer.Import(E->getType()); |
| 5630 | if (T.isNull()) |
| 5631 | return nullptr; |
| 5632 | |
| 5633 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 5634 | if (!ToLHS) |
| 5635 | return nullptr; |
| 5636 | |
| 5637 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 5638 | if (!ToRHS) |
| 5639 | return nullptr; |
| 5640 | |
| 5641 | Expr *ToCond = Importer.Import(E->getCond()); |
| 5642 | if (!ToCond) |
| 5643 | return nullptr; |
| 5644 | |
| 5645 | return new (Importer.getToContext()) ConditionalOperator( |
| 5646 | ToCond, Importer.Import(E->getQuestionLoc()), |
| 5647 | ToLHS, Importer.Import(E->getColonLoc()), |
| 5648 | ToRHS, T, E->getValueKind(), E->getObjectKind()); |
| 5649 | } |
| 5650 | |
| 5651 | Expr *ASTNodeImporter::VisitBinaryConditionalOperator( |
| 5652 | BinaryConditionalOperator *E) { |
| 5653 | QualType T = Importer.Import(E->getType()); |
| 5654 | if (T.isNull()) |
| 5655 | return nullptr; |
| 5656 | |
| 5657 | Expr *Common = Importer.Import(E->getCommon()); |
| 5658 | if (!Common) |
| 5659 | return nullptr; |
| 5660 | |
| 5661 | Expr *Cond = Importer.Import(E->getCond()); |
| 5662 | if (!Cond) |
| 5663 | return nullptr; |
| 5664 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5665 | auto *OpaqueValue = cast_or_null<OpaqueValueExpr>( |
| 5666 | Importer.Import(E->getOpaqueValue())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5667 | if (!OpaqueValue) |
| 5668 | return nullptr; |
| 5669 | |
| 5670 | Expr *TrueExpr = Importer.Import(E->getTrueExpr()); |
| 5671 | if (!TrueExpr) |
| 5672 | return nullptr; |
| 5673 | |
| 5674 | Expr *FalseExpr = Importer.Import(E->getFalseExpr()); |
| 5675 | if (!FalseExpr) |
| 5676 | return nullptr; |
| 5677 | |
| 5678 | return new (Importer.getToContext()) BinaryConditionalOperator( |
| 5679 | Common, OpaqueValue, Cond, TrueExpr, FalseExpr, |
| 5680 | Importer.Import(E->getQuestionLoc()), Importer.Import(E->getColonLoc()), |
| 5681 | T, E->getValueKind(), E->getObjectKind()); |
| 5682 | } |
| 5683 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5684 | Expr *ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 5685 | QualType T = Importer.Import(E->getType()); |
| 5686 | if (T.isNull()) |
| 5687 | return nullptr; |
| 5688 | |
| 5689 | TypeSourceInfo *ToQueried = Importer.Import(E->getQueriedTypeSourceInfo()); |
| 5690 | if (!ToQueried) |
| 5691 | return nullptr; |
| 5692 | |
| 5693 | Expr *Dim = Importer.Import(E->getDimensionExpression()); |
| 5694 | if (!Dim && E->getDimensionExpression()) |
| 5695 | return nullptr; |
| 5696 | |
| 5697 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
| 5698 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 5699 | E->getValue(), Dim, Importer.Import(E->getLocEnd()), T); |
| 5700 | } |
| 5701 | |
| 5702 | Expr *ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 5703 | QualType T = Importer.Import(E->getType()); |
| 5704 | if (T.isNull()) |
| 5705 | return nullptr; |
| 5706 | |
| 5707 | Expr *ToQueried = Importer.Import(E->getQueriedExpression()); |
| 5708 | if (!ToQueried) |
| 5709 | return nullptr; |
| 5710 | |
| 5711 | return new (Importer.getToContext()) ExpressionTraitExpr( |
| 5712 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 5713 | E->getValue(), Importer.Import(E->getLocEnd()), T); |
| 5714 | } |
| 5715 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5716 | Expr *ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 5717 | QualType T = Importer.Import(E->getType()); |
| 5718 | if (T.isNull()) |
| 5719 | return nullptr; |
| 5720 | |
| 5721 | Expr *SourceExpr = Importer.Import(E->getSourceExpr()); |
| 5722 | if (!SourceExpr && E->getSourceExpr()) |
| 5723 | return nullptr; |
| 5724 | |
| 5725 | return new (Importer.getToContext()) OpaqueValueExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5726 | Importer.Import(E->getLocation()), T, E->getValueKind(), |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5727 | E->getObjectKind(), SourceExpr); |
| 5728 | } |
| 5729 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5730 | Expr *ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 5731 | QualType T = Importer.Import(E->getType()); |
| 5732 | if (T.isNull()) |
| 5733 | return nullptr; |
| 5734 | |
| 5735 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 5736 | if (!ToLHS) |
| 5737 | return nullptr; |
| 5738 | |
| 5739 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 5740 | if (!ToRHS) |
| 5741 | return nullptr; |
| 5742 | |
| 5743 | return new (Importer.getToContext()) ArraySubscriptExpr( |
| 5744 | ToLHS, ToRHS, T, E->getValueKind(), E->getObjectKind(), |
| 5745 | Importer.Import(E->getRBracketLoc())); |
| 5746 | } |
| 5747 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5748 | Expr *ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 5749 | QualType T = Importer.Import(E->getType()); |
| 5750 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5751 | return nullptr; |
| 5752 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5753 | QualType CompLHSType = Importer.Import(E->getComputationLHSType()); |
| 5754 | if (CompLHSType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5755 | return nullptr; |
| 5756 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5757 | QualType CompResultType = Importer.Import(E->getComputationResultType()); |
| 5758 | if (CompResultType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5759 | return nullptr; |
| 5760 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5761 | Expr *LHS = Importer.Import(E->getLHS()); |
| 5762 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5763 | return nullptr; |
| 5764 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5765 | Expr *RHS = Importer.Import(E->getRHS()); |
| 5766 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5767 | return nullptr; |
| 5768 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5769 | return new (Importer.getToContext()) |
| 5770 | CompoundAssignOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 5771 | T, E->getValueKind(), |
| 5772 | E->getObjectKind(), |
| 5773 | CompLHSType, CompResultType, |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 5774 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 5775 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5776 | } |
| 5777 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5778 | bool ASTNodeImporter::ImportCastPath(CastExpr *CE, CXXCastPath &Path) { |
| 5779 | for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) { |
| 5780 | if (CXXBaseSpecifier *Spec = Importer.Import(*I)) |
| 5781 | Path.push_back(Spec); |
| 5782 | else |
| 5783 | return true; |
| 5784 | } |
| 5785 | return false; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5786 | } |
| 5787 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5788 | Expr *ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 5789 | QualType T = Importer.Import(E->getType()); |
| 5790 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5791 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5792 | |
| 5793 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5794 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5795 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5796 | |
| 5797 | CXXCastPath BasePath; |
| 5798 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5799 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5800 | |
| 5801 | return ImplicitCastExpr::Create(Importer.getToContext(), T, E->getCastKind(), |
John McCall | 2536c6d | 2010-08-25 10:28:54 +0000 | [diff] [blame] | 5802 | SubExpr, &BasePath, E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5803 | } |
| 5804 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5805 | Expr *ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5806 | QualType T = Importer.Import(E->getType()); |
| 5807 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5808 | return nullptr; |
| 5809 | |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5810 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5811 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5812 | return nullptr; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5813 | |
| 5814 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeInfoAsWritten()); |
| 5815 | if (!TInfo && E->getTypeInfoAsWritten()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5816 | return nullptr; |
| 5817 | |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5818 | CXXCastPath BasePath; |
| 5819 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5820 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5821 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5822 | switch (E->getStmtClass()) { |
| 5823 | case Stmt::CStyleCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5824 | auto *CCE = cast<CStyleCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5825 | return CStyleCastExpr::Create(Importer.getToContext(), T, |
| 5826 | E->getValueKind(), E->getCastKind(), |
| 5827 | SubExpr, &BasePath, TInfo, |
| 5828 | Importer.Import(CCE->getLParenLoc()), |
| 5829 | Importer.Import(CCE->getRParenLoc())); |
| 5830 | } |
| 5831 | |
| 5832 | case Stmt::CXXFunctionalCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5833 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5834 | return CXXFunctionalCastExpr::Create(Importer.getToContext(), T, |
| 5835 | E->getValueKind(), TInfo, |
| 5836 | E->getCastKind(), SubExpr, &BasePath, |
| 5837 | Importer.Import(FCE->getLParenLoc()), |
| 5838 | Importer.Import(FCE->getRParenLoc())); |
| 5839 | } |
| 5840 | |
| 5841 | case Stmt::ObjCBridgedCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5842 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5843 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 5844 | Importer.Import(OCE->getLParenLoc()), OCE->getBridgeKind(), |
| 5845 | E->getCastKind(), Importer.Import(OCE->getBridgeKeywordLoc()), |
| 5846 | TInfo, SubExpr); |
| 5847 | } |
| 5848 | default: |
| 5849 | break; // just fall through |
| 5850 | } |
| 5851 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5852 | auto *Named = cast<CXXNamedCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5853 | SourceLocation ExprLoc = Importer.Import(Named->getOperatorLoc()), |
| 5854 | RParenLoc = Importer.Import(Named->getRParenLoc()); |
| 5855 | SourceRange Brackets = Importer.Import(Named->getAngleBrackets()); |
| 5856 | |
| 5857 | switch (E->getStmtClass()) { |
| 5858 | case Stmt::CXXStaticCastExprClass: |
| 5859 | return CXXStaticCastExpr::Create(Importer.getToContext(), T, |
| 5860 | E->getValueKind(), E->getCastKind(), |
| 5861 | SubExpr, &BasePath, TInfo, |
| 5862 | ExprLoc, RParenLoc, Brackets); |
| 5863 | |
| 5864 | case Stmt::CXXDynamicCastExprClass: |
| 5865 | return CXXDynamicCastExpr::Create(Importer.getToContext(), T, |
| 5866 | E->getValueKind(), E->getCastKind(), |
| 5867 | SubExpr, &BasePath, TInfo, |
| 5868 | ExprLoc, RParenLoc, Brackets); |
| 5869 | |
| 5870 | case Stmt::CXXReinterpretCastExprClass: |
| 5871 | return CXXReinterpretCastExpr::Create(Importer.getToContext(), T, |
| 5872 | E->getValueKind(), E->getCastKind(), |
| 5873 | SubExpr, &BasePath, TInfo, |
| 5874 | ExprLoc, RParenLoc, Brackets); |
| 5875 | |
| 5876 | case Stmt::CXXConstCastExprClass: |
| 5877 | return CXXConstCastExpr::Create(Importer.getToContext(), T, |
| 5878 | E->getValueKind(), SubExpr, TInfo, ExprLoc, |
| 5879 | RParenLoc, Brackets); |
| 5880 | default: |
| 5881 | llvm_unreachable("Cast expression of unsupported type!"); |
| 5882 | return nullptr; |
| 5883 | } |
| 5884 | } |
| 5885 | |
| 5886 | Expr *ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *OE) { |
| 5887 | QualType T = Importer.Import(OE->getType()); |
| 5888 | if (T.isNull()) |
| 5889 | return nullptr; |
| 5890 | |
| 5891 | SmallVector<OffsetOfNode, 4> Nodes; |
| 5892 | for (int I = 0, E = OE->getNumComponents(); I < E; ++I) { |
| 5893 | const OffsetOfNode &Node = OE->getComponent(I); |
| 5894 | |
| 5895 | switch (Node.getKind()) { |
| 5896 | case OffsetOfNode::Array: |
| 5897 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), |
| 5898 | Node.getArrayExprIndex(), |
| 5899 | Importer.Import(Node.getLocEnd()))); |
| 5900 | break; |
| 5901 | |
| 5902 | case OffsetOfNode::Base: { |
| 5903 | CXXBaseSpecifier *BS = Importer.Import(Node.getBase()); |
| 5904 | if (!BS && Node.getBase()) |
| 5905 | return nullptr; |
| 5906 | Nodes.push_back(OffsetOfNode(BS)); |
| 5907 | break; |
| 5908 | } |
| 5909 | case OffsetOfNode::Field: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5910 | auto *FD = cast_or_null<FieldDecl>(Importer.Import(Node.getField())); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5911 | if (!FD) |
| 5912 | return nullptr; |
| 5913 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), FD, |
| 5914 | Importer.Import(Node.getLocEnd()))); |
| 5915 | break; |
| 5916 | } |
| 5917 | case OffsetOfNode::Identifier: { |
| 5918 | IdentifierInfo *ToII = Importer.Import(Node.getFieldName()); |
| 5919 | if (!ToII) |
| 5920 | return nullptr; |
| 5921 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), ToII, |
| 5922 | Importer.Import(Node.getLocEnd()))); |
| 5923 | break; |
| 5924 | } |
| 5925 | } |
| 5926 | } |
| 5927 | |
| 5928 | SmallVector<Expr *, 4> Exprs(OE->getNumExpressions()); |
| 5929 | for (int I = 0, E = OE->getNumExpressions(); I < E; ++I) { |
| 5930 | Expr *ToIndexExpr = Importer.Import(OE->getIndexExpr(I)); |
| 5931 | if (!ToIndexExpr) |
| 5932 | return nullptr; |
| 5933 | Exprs[I] = ToIndexExpr; |
| 5934 | } |
| 5935 | |
| 5936 | TypeSourceInfo *TInfo = Importer.Import(OE->getTypeSourceInfo()); |
| 5937 | if (!TInfo && OE->getTypeSourceInfo()) |
| 5938 | return nullptr; |
| 5939 | |
| 5940 | return OffsetOfExpr::Create(Importer.getToContext(), T, |
| 5941 | Importer.Import(OE->getOperatorLoc()), |
| 5942 | TInfo, Nodes, Exprs, |
| 5943 | Importer.Import(OE->getRParenLoc())); |
| 5944 | } |
| 5945 | |
| 5946 | Expr *ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 5947 | QualType T = Importer.Import(E->getType()); |
| 5948 | if (T.isNull()) |
| 5949 | return nullptr; |
| 5950 | |
| 5951 | Expr *Operand = Importer.Import(E->getOperand()); |
| 5952 | if (!Operand) |
| 5953 | return nullptr; |
| 5954 | |
| 5955 | CanThrowResult CanThrow; |
| 5956 | if (E->isValueDependent()) |
| 5957 | CanThrow = CT_Dependent; |
| 5958 | else |
| 5959 | CanThrow = E->getValue() ? CT_Can : CT_Cannot; |
| 5960 | |
| 5961 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 5962 | T, Operand, CanThrow, |
| 5963 | Importer.Import(E->getLocStart()), Importer.Import(E->getLocEnd())); |
| 5964 | } |
| 5965 | |
| 5966 | Expr *ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 5967 | QualType T = Importer.Import(E->getType()); |
| 5968 | if (T.isNull()) |
| 5969 | return nullptr; |
| 5970 | |
| 5971 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5972 | if (!SubExpr && E->getSubExpr()) |
| 5973 | return nullptr; |
| 5974 | |
| 5975 | return new (Importer.getToContext()) CXXThrowExpr( |
| 5976 | SubExpr, T, Importer.Import(E->getThrowLoc()), |
| 5977 | E->isThrownVariableInScope()); |
| 5978 | } |
| 5979 | |
| 5980 | Expr *ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5981 | auto *Param = cast_or_null<ParmVarDecl>(Importer.Import(E->getParam())); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5982 | if (!Param) |
| 5983 | return nullptr; |
| 5984 | |
| 5985 | return CXXDefaultArgExpr::Create( |
| 5986 | Importer.getToContext(), Importer.Import(E->getUsedLocation()), Param); |
| 5987 | } |
| 5988 | |
| 5989 | Expr *ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 5990 | QualType T = Importer.Import(E->getType()); |
| 5991 | if (T.isNull()) |
| 5992 | return nullptr; |
| 5993 | |
| 5994 | TypeSourceInfo *TypeInfo = Importer.Import(E->getTypeSourceInfo()); |
| 5995 | if (!TypeInfo) |
| 5996 | return nullptr; |
| 5997 | |
| 5998 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
| 5999 | T, TypeInfo, Importer.Import(E->getRParenLoc())); |
| 6000 | } |
| 6001 | |
| 6002 | Expr *ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 6003 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 6004 | if (!SubExpr) |
| 6005 | return nullptr; |
| 6006 | |
| 6007 | auto *Dtor = cast_or_null<CXXDestructorDecl>( |
| 6008 | Importer.Import(const_cast<CXXDestructorDecl *>( |
| 6009 | E->getTemporary()->getDestructor()))); |
| 6010 | if (!Dtor) |
| 6011 | return nullptr; |
| 6012 | |
| 6013 | ASTContext &ToCtx = Importer.getToContext(); |
| 6014 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, Dtor); |
| 6015 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, SubExpr); |
| 6016 | } |
| 6017 | |
| 6018 | Expr *ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE) { |
| 6019 | QualType T = Importer.Import(CE->getType()); |
| 6020 | if (T.isNull()) |
| 6021 | return nullptr; |
| 6022 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6023 | TypeSourceInfo *TInfo = Importer.Import(CE->getTypeSourceInfo()); |
| 6024 | if (!TInfo) |
| 6025 | return nullptr; |
| 6026 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6027 | SmallVector<Expr *, 8> Args(CE->getNumArgs()); |
| 6028 | if (ImportContainerChecked(CE->arguments(), Args)) |
| 6029 | return nullptr; |
| 6030 | |
| 6031 | auto *Ctor = cast_or_null<CXXConstructorDecl>( |
| 6032 | Importer.Import(CE->getConstructor())); |
| 6033 | if (!Ctor) |
| 6034 | return nullptr; |
| 6035 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6036 | return new (Importer.getToContext()) CXXTemporaryObjectExpr( |
| 6037 | Importer.getToContext(), Ctor, T, TInfo, Args, |
| 6038 | Importer.Import(CE->getParenOrBraceRange()), CE->hadMultipleCandidates(), |
| 6039 | CE->isListInitialization(), CE->isStdInitListInitialization(), |
| 6040 | CE->requiresZeroInitialization()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6041 | } |
| 6042 | |
| 6043 | Expr * |
| 6044 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
| 6045 | QualType T = Importer.Import(E->getType()); |
| 6046 | if (T.isNull()) |
| 6047 | return nullptr; |
| 6048 | |
| 6049 | Expr *TempE = Importer.Import(E->GetTemporaryExpr()); |
| 6050 | if (!TempE) |
| 6051 | return nullptr; |
| 6052 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6053 | auto *ExtendedBy = cast_or_null<ValueDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6054 | Importer.Import(const_cast<ValueDecl *>(E->getExtendingDecl()))); |
| 6055 | if (!ExtendedBy && E->getExtendingDecl()) |
| 6056 | return nullptr; |
| 6057 | |
| 6058 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
| 6059 | T, TempE, E->isBoundToLvalueReference()); |
| 6060 | |
| 6061 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
| 6062 | ToMTE->setExtendingDecl(ExtendedBy, E->getManglingNumber()); |
| 6063 | return ToMTE; |
| 6064 | } |
| 6065 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6066 | Expr *ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 6067 | QualType T = Importer.Import(E->getType()); |
| 6068 | if (T.isNull()) |
| 6069 | return nullptr; |
| 6070 | |
| 6071 | Expr *Pattern = Importer.Import(E->getPattern()); |
| 6072 | if (!Pattern) |
| 6073 | return nullptr; |
| 6074 | |
| 6075 | return new (Importer.getToContext()) PackExpansionExpr( |
| 6076 | T, Pattern, Importer.Import(E->getEllipsisLoc()), |
| 6077 | E->getNumExpansions()); |
| 6078 | } |
| 6079 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6080 | Expr *ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 6081 | auto *Pack = cast_or_null<NamedDecl>(Importer.Import(E->getPack())); |
| 6082 | if (!Pack) |
| 6083 | return nullptr; |
| 6084 | |
| 6085 | Optional<unsigned> Length; |
| 6086 | |
| 6087 | if (!E->isValueDependent()) |
| 6088 | Length = E->getPackLength(); |
| 6089 | |
| 6090 | SmallVector<TemplateArgument, 8> PartialArguments; |
| 6091 | if (E->isPartiallySubstituted()) { |
| 6092 | if (ImportTemplateArguments(E->getPartialArguments().data(), |
| 6093 | E->getPartialArguments().size(), |
| 6094 | PartialArguments)) |
| 6095 | return nullptr; |
| 6096 | } |
| 6097 | |
| 6098 | return SizeOfPackExpr::Create( |
| 6099 | Importer.getToContext(), Importer.Import(E->getOperatorLoc()), Pack, |
| 6100 | Importer.Import(E->getPackLoc()), Importer.Import(E->getRParenLoc()), |
| 6101 | Length, PartialArguments); |
| 6102 | } |
| 6103 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6104 | Expr *ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *CE) { |
| 6105 | QualType T = Importer.Import(CE->getType()); |
| 6106 | if (T.isNull()) |
| 6107 | return nullptr; |
| 6108 | |
| 6109 | SmallVector<Expr *, 4> PlacementArgs(CE->getNumPlacementArgs()); |
| 6110 | if (ImportContainerChecked(CE->placement_arguments(), PlacementArgs)) |
| 6111 | return nullptr; |
| 6112 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6113 | auto *OperatorNewDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6114 | Importer.Import(CE->getOperatorNew())); |
| 6115 | if (!OperatorNewDecl && CE->getOperatorNew()) |
| 6116 | return nullptr; |
| 6117 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6118 | auto *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6119 | Importer.Import(CE->getOperatorDelete())); |
| 6120 | if (!OperatorDeleteDecl && CE->getOperatorDelete()) |
| 6121 | return nullptr; |
| 6122 | |
| 6123 | Expr *ToInit = Importer.Import(CE->getInitializer()); |
| 6124 | if (!ToInit && CE->getInitializer()) |
| 6125 | return nullptr; |
| 6126 | |
| 6127 | TypeSourceInfo *TInfo = Importer.Import(CE->getAllocatedTypeSourceInfo()); |
| 6128 | if (!TInfo) |
| 6129 | return nullptr; |
| 6130 | |
| 6131 | Expr *ToArrSize = Importer.Import(CE->getArraySize()); |
| 6132 | if (!ToArrSize && CE->getArraySize()) |
| 6133 | return nullptr; |
| 6134 | |
| 6135 | return new (Importer.getToContext()) CXXNewExpr( |
| 6136 | Importer.getToContext(), |
| 6137 | CE->isGlobalNew(), |
| 6138 | OperatorNewDecl, OperatorDeleteDecl, |
Richard Smith | b2f0f05 | 2016-10-10 18:54:32 +0000 | [diff] [blame] | 6139 | CE->passAlignment(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6140 | CE->doesUsualArrayDeleteWantSize(), |
| 6141 | PlacementArgs, |
| 6142 | Importer.Import(CE->getTypeIdParens()), |
| 6143 | ToArrSize, CE->getInitializationStyle(), ToInit, T, TInfo, |
| 6144 | Importer.Import(CE->getSourceRange()), |
| 6145 | Importer.Import(CE->getDirectInitRange())); |
| 6146 | } |
| 6147 | |
| 6148 | Expr *ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 6149 | QualType T = Importer.Import(E->getType()); |
| 6150 | if (T.isNull()) |
| 6151 | return nullptr; |
| 6152 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6153 | auto *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6154 | Importer.Import(E->getOperatorDelete())); |
| 6155 | if (!OperatorDeleteDecl && E->getOperatorDelete()) |
| 6156 | return nullptr; |
| 6157 | |
| 6158 | Expr *ToArg = Importer.Import(E->getArgument()); |
| 6159 | if (!ToArg && E->getArgument()) |
| 6160 | return nullptr; |
| 6161 | |
| 6162 | return new (Importer.getToContext()) CXXDeleteExpr( |
| 6163 | T, E->isGlobalDelete(), |
| 6164 | E->isArrayForm(), |
| 6165 | E->isArrayFormAsWritten(), |
| 6166 | E->doesUsualArrayDeleteWantSize(), |
| 6167 | OperatorDeleteDecl, |
| 6168 | ToArg, |
| 6169 | Importer.Import(E->getLocStart())); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6170 | } |
| 6171 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6172 | Expr *ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 6173 | QualType T = Importer.Import(E->getType()); |
| 6174 | if (T.isNull()) |
| 6175 | return nullptr; |
| 6176 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6177 | auto *ToCCD = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6178 | dyn_cast_or_null<CXXConstructorDecl>(Importer.Import(E->getConstructor())); |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 6179 | if (!ToCCD) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6180 | return nullptr; |
| 6181 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6182 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6183 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6184 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6185 | |
| 6186 | return CXXConstructExpr::Create(Importer.getToContext(), T, |
| 6187 | Importer.Import(E->getLocation()), |
Richard Smith | c83bf82 | 2016-06-10 00:58:19 +0000 | [diff] [blame] | 6188 | ToCCD, E->isElidable(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6189 | ToArgs, E->hadMultipleCandidates(), |
| 6190 | E->isListInitialization(), |
| 6191 | E->isStdInitListInitialization(), |
| 6192 | E->requiresZeroInitialization(), |
| 6193 | E->getConstructionKind(), |
| 6194 | Importer.Import(E->getParenOrBraceRange())); |
| 6195 | } |
| 6196 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6197 | Expr *ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *EWC) { |
| 6198 | Expr *SubExpr = Importer.Import(EWC->getSubExpr()); |
| 6199 | if (!SubExpr && EWC->getSubExpr()) |
| 6200 | return nullptr; |
| 6201 | |
| 6202 | SmallVector<ExprWithCleanups::CleanupObject, 8> Objs(EWC->getNumObjects()); |
| 6203 | for (unsigned I = 0, E = EWC->getNumObjects(); I < E; I++) |
| 6204 | if (ExprWithCleanups::CleanupObject Obj = |
| 6205 | cast_or_null<BlockDecl>(Importer.Import(EWC->getObject(I)))) |
| 6206 | Objs[I] = Obj; |
| 6207 | else |
| 6208 | return nullptr; |
| 6209 | |
| 6210 | return ExprWithCleanups::Create(Importer.getToContext(), |
| 6211 | SubExpr, EWC->cleanupsHaveSideEffects(), |
| 6212 | Objs); |
| 6213 | } |
| 6214 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6215 | Expr *ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 6216 | QualType T = Importer.Import(E->getType()); |
| 6217 | if (T.isNull()) |
| 6218 | return nullptr; |
| 6219 | |
| 6220 | Expr *ToFn = Importer.Import(E->getCallee()); |
| 6221 | if (!ToFn) |
| 6222 | return nullptr; |
| 6223 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6224 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6225 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6226 | return nullptr; |
| 6227 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6228 | return new (Importer.getToContext()) CXXMemberCallExpr( |
| 6229 | Importer.getToContext(), ToFn, ToArgs, T, E->getValueKind(), |
| 6230 | Importer.Import(E->getRParenLoc())); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6231 | } |
| 6232 | |
| 6233 | Expr *ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 6234 | QualType T = Importer.Import(E->getType()); |
| 6235 | if (T.isNull()) |
| 6236 | return nullptr; |
| 6237 | |
| 6238 | return new (Importer.getToContext()) |
| 6239 | CXXThisExpr(Importer.Import(E->getLocation()), T, E->isImplicit()); |
| 6240 | } |
| 6241 | |
| 6242 | Expr *ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 6243 | QualType T = Importer.Import(E->getType()); |
| 6244 | if (T.isNull()) |
| 6245 | return nullptr; |
| 6246 | |
| 6247 | return new (Importer.getToContext()) |
| 6248 | CXXBoolLiteralExpr(E->getValue(), T, Importer.Import(E->getLocation())); |
| 6249 | } |
| 6250 | |
| 6251 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6252 | Expr *ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 6253 | QualType T = Importer.Import(E->getType()); |
| 6254 | if (T.isNull()) |
| 6255 | return nullptr; |
| 6256 | |
| 6257 | Expr *ToBase = Importer.Import(E->getBase()); |
| 6258 | if (!ToBase && E->getBase()) |
| 6259 | return nullptr; |
| 6260 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6261 | auto *ToMember = dyn_cast<ValueDecl>(Importer.Import(E->getMemberDecl())); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6262 | if (!ToMember && E->getMemberDecl()) |
| 6263 | return nullptr; |
| 6264 | |
Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 6265 | auto *ToDecl = |
| 6266 | dyn_cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl().getDecl())); |
| 6267 | if (!ToDecl && E->getFoundDecl().getDecl()) |
| 6268 | return nullptr; |
| 6269 | |
| 6270 | DeclAccessPair ToFoundDecl = |
| 6271 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6272 | |
| 6273 | DeclarationNameInfo ToMemberNameInfo( |
| 6274 | Importer.Import(E->getMemberNameInfo().getName()), |
| 6275 | Importer.Import(E->getMemberNameInfo().getLoc())); |
| 6276 | |
| 6277 | if (E->hasExplicitTemplateArgs()) { |
| 6278 | return nullptr; // FIXME: handle template arguments |
| 6279 | } |
| 6280 | |
| 6281 | return MemberExpr::Create(Importer.getToContext(), ToBase, |
| 6282 | E->isArrow(), |
| 6283 | Importer.Import(E->getOperatorLoc()), |
| 6284 | Importer.Import(E->getQualifierLoc()), |
| 6285 | Importer.Import(E->getTemplateKeywordLoc()), |
| 6286 | ToMember, ToFoundDecl, ToMemberNameInfo, |
| 6287 | nullptr, T, E->getValueKind(), |
| 6288 | E->getObjectKind()); |
| 6289 | } |
| 6290 | |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 6291 | Expr *ASTNodeImporter::VisitCXXPseudoDestructorExpr( |
| 6292 | CXXPseudoDestructorExpr *E) { |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 6293 | Expr *BaseE = Importer.Import(E->getBase()); |
| 6294 | if (!BaseE) |
| 6295 | return nullptr; |
| 6296 | |
| 6297 | TypeSourceInfo *ScopeInfo = Importer.Import(E->getScopeTypeInfo()); |
| 6298 | if (!ScopeInfo && E->getScopeTypeInfo()) |
| 6299 | return nullptr; |
| 6300 | |
| 6301 | PseudoDestructorTypeStorage Storage; |
| 6302 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 6303 | IdentifierInfo *ToII = Importer.Import(FromII); |
| 6304 | if (!ToII) |
| 6305 | return nullptr; |
| 6306 | Storage = PseudoDestructorTypeStorage( |
| 6307 | ToII, Importer.Import(E->getDestroyedTypeLoc())); |
| 6308 | } else { |
| 6309 | TypeSourceInfo *TI = Importer.Import(E->getDestroyedTypeInfo()); |
| 6310 | if (!TI) |
| 6311 | return nullptr; |
| 6312 | Storage = PseudoDestructorTypeStorage(TI); |
| 6313 | } |
| 6314 | |
| 6315 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
| 6316 | Importer.getToContext(), BaseE, E->isArrow(), |
| 6317 | Importer.Import(E->getOperatorLoc()), |
| 6318 | Importer.Import(E->getQualifierLoc()), |
| 6319 | ScopeInfo, Importer.Import(E->getColonColonLoc()), |
| 6320 | Importer.Import(E->getTildeLoc()), Storage); |
| 6321 | } |
| 6322 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6323 | Expr *ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
| 6324 | CXXDependentScopeMemberExpr *E) { |
| 6325 | Expr *Base = nullptr; |
| 6326 | if (!E->isImplicitAccess()) { |
| 6327 | Base = Importer.Import(E->getBase()); |
| 6328 | if (!Base) |
| 6329 | return nullptr; |
| 6330 | } |
| 6331 | |
| 6332 | QualType BaseType = Importer.Import(E->getBaseType()); |
| 6333 | if (BaseType.isNull()) |
| 6334 | return nullptr; |
| 6335 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6336 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6337 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6338 | if (ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6339 | E->template_arguments(), ToTAInfo)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6340 | return nullptr; |
| 6341 | ResInfo = &ToTAInfo; |
| 6342 | } |
| 6343 | |
| 6344 | DeclarationName Name = Importer.Import(E->getMember()); |
| 6345 | if (!E->getMember().isEmpty() && Name.isEmpty()) |
| 6346 | return nullptr; |
| 6347 | |
| 6348 | DeclarationNameInfo MemberNameInfo(Name, Importer.Import(E->getMemberLoc())); |
| 6349 | // Import additional name location/type info. |
| 6350 | ImportDeclarationNameLoc(E->getMemberNameInfo(), MemberNameInfo); |
| 6351 | auto ToFQ = Importer.Import(E->getFirstQualifierFoundInScope()); |
| 6352 | if (!ToFQ && E->getFirstQualifierFoundInScope()) |
| 6353 | return nullptr; |
| 6354 | |
| 6355 | return CXXDependentScopeMemberExpr::Create( |
| 6356 | Importer.getToContext(), Base, BaseType, E->isArrow(), |
| 6357 | Importer.Import(E->getOperatorLoc()), |
| 6358 | Importer.Import(E->getQualifierLoc()), |
| 6359 | Importer.Import(E->getTemplateKeywordLoc()), |
| 6360 | cast_or_null<NamedDecl>(ToFQ), MemberNameInfo, ResInfo); |
| 6361 | } |
| 6362 | |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 6363 | Expr * |
| 6364 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
| 6365 | DeclarationName Name = Importer.Import(E->getDeclName()); |
| 6366 | if (!E->getDeclName().isEmpty() && Name.isEmpty()) |
| 6367 | return nullptr; |
| 6368 | |
| 6369 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getExprLoc())); |
| 6370 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6371 | |
| 6372 | TemplateArgumentListInfo ToTAInfo(Importer.Import(E->getLAngleLoc()), |
| 6373 | Importer.Import(E->getRAngleLoc())); |
| 6374 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 6375 | if (E->hasExplicitTemplateArgs()) { |
| 6376 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6377 | return nullptr; |
| 6378 | ResInfo = &ToTAInfo; |
| 6379 | } |
| 6380 | |
| 6381 | return DependentScopeDeclRefExpr::Create( |
| 6382 | Importer.getToContext(), Importer.Import(E->getQualifierLoc()), |
| 6383 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, ResInfo); |
| 6384 | } |
| 6385 | |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6386 | Expr *ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 6387 | CXXUnresolvedConstructExpr *CE) { |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6388 | unsigned NumArgs = CE->arg_size(); |
| 6389 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6390 | SmallVector<Expr *, 8> ToArgs(NumArgs); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6391 | if (ImportArrayChecked(CE->arg_begin(), CE->arg_end(), ToArgs.begin())) |
| 6392 | return nullptr; |
| 6393 | |
| 6394 | return CXXUnresolvedConstructExpr::Create( |
| 6395 | Importer.getToContext(), Importer.Import(CE->getTypeSourceInfo()), |
| 6396 | Importer.Import(CE->getLParenLoc()), llvm::makeArrayRef(ToArgs), |
| 6397 | Importer.Import(CE->getRParenLoc())); |
| 6398 | } |
| 6399 | |
| 6400 | Expr *ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6401 | auto *NamingClass = |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6402 | cast_or_null<CXXRecordDecl>(Importer.Import(E->getNamingClass())); |
| 6403 | if (E->getNamingClass() && !NamingClass) |
| 6404 | return nullptr; |
| 6405 | |
| 6406 | DeclarationName Name = Importer.Import(E->getName()); |
| 6407 | if (E->getName() && !Name) |
| 6408 | return nullptr; |
| 6409 | |
| 6410 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getNameLoc())); |
| 6411 | // Import additional name location/type info. |
| 6412 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6413 | |
| 6414 | UnresolvedSet<8> ToDecls; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6415 | for (auto *D : E->decls()) { |
| 6416 | if (auto *To = cast_or_null<NamedDecl>(Importer.Import(D))) |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6417 | ToDecls.addDecl(To); |
| 6418 | else |
| 6419 | return nullptr; |
| 6420 | } |
| 6421 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6422 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6423 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6424 | if (ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6425 | E->template_arguments(), ToTAInfo)) |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6426 | return nullptr; |
| 6427 | ResInfo = &ToTAInfo; |
| 6428 | } |
| 6429 | |
| 6430 | if (ResInfo || E->getTemplateKeywordLoc().isValid()) |
| 6431 | return UnresolvedLookupExpr::Create( |
| 6432 | Importer.getToContext(), NamingClass, |
| 6433 | Importer.Import(E->getQualifierLoc()), |
| 6434 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, E->requiresADL(), |
| 6435 | ResInfo, ToDecls.begin(), ToDecls.end()); |
| 6436 | |
| 6437 | return UnresolvedLookupExpr::Create( |
| 6438 | Importer.getToContext(), NamingClass, |
| 6439 | Importer.Import(E->getQualifierLoc()), NameInfo, E->requiresADL(), |
| 6440 | E->isOverloaded(), ToDecls.begin(), ToDecls.end()); |
| 6441 | } |
| 6442 | |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 6443 | Expr *ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| 6444 | DeclarationName Name = Importer.Import(E->getName()); |
| 6445 | if (!E->getName().isEmpty() && Name.isEmpty()) |
| 6446 | return nullptr; |
| 6447 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getNameLoc())); |
| 6448 | // Import additional name location/type info. |
| 6449 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6450 | |
| 6451 | QualType BaseType = Importer.Import(E->getType()); |
| 6452 | if (!E->getType().isNull() && BaseType.isNull()) |
| 6453 | return nullptr; |
| 6454 | |
| 6455 | UnresolvedSet<8> ToDecls; |
| 6456 | for (Decl *D : E->decls()) { |
| 6457 | if (NamedDecl *To = cast_or_null<NamedDecl>(Importer.Import(D))) |
| 6458 | ToDecls.addDecl(To); |
| 6459 | else |
| 6460 | return nullptr; |
| 6461 | } |
| 6462 | |
| 6463 | TemplateArgumentListInfo ToTAInfo; |
| 6464 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 6465 | if (E->hasExplicitTemplateArgs()) { |
| 6466 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6467 | return nullptr; |
| 6468 | ResInfo = &ToTAInfo; |
| 6469 | } |
| 6470 | |
| 6471 | Expr *BaseE = E->isImplicitAccess() ? nullptr : Importer.Import(E->getBase()); |
| 6472 | if (!BaseE && !E->isImplicitAccess() && E->getBase()) { |
| 6473 | return nullptr; |
| 6474 | } |
| 6475 | |
| 6476 | return UnresolvedMemberExpr::Create( |
| 6477 | Importer.getToContext(), E->hasUnresolvedUsing(), BaseE, BaseType, |
| 6478 | E->isArrow(), Importer.Import(E->getOperatorLoc()), |
| 6479 | Importer.Import(E->getQualifierLoc()), |
| 6480 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, ResInfo, |
| 6481 | ToDecls.begin(), ToDecls.end()); |
| 6482 | } |
| 6483 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6484 | Expr *ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 6485 | QualType T = Importer.Import(E->getType()); |
| 6486 | if (T.isNull()) |
| 6487 | return nullptr; |
| 6488 | |
| 6489 | Expr *ToCallee = Importer.Import(E->getCallee()); |
| 6490 | if (!ToCallee && E->getCallee()) |
| 6491 | return nullptr; |
| 6492 | |
| 6493 | unsigned NumArgs = E->getNumArgs(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6494 | SmallVector<Expr *, 2> ToArgs(NumArgs); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6495 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
| 6496 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6497 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6498 | auto **ToArgs_Copied = new (Importer.getToContext()) Expr*[NumArgs]; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6499 | |
| 6500 | for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) |
| 6501 | ToArgs_Copied[ai] = ToArgs[ai]; |
| 6502 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6503 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
| 6504 | return new (Importer.getToContext()) CXXOperatorCallExpr( |
| 6505 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, T, |
| 6506 | OCE->getValueKind(), Importer.Import(OCE->getRParenLoc()), |
| 6507 | OCE->getFPFeatures()); |
| 6508 | } |
| 6509 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6510 | return new (Importer.getToContext()) |
| 6511 | CallExpr(Importer.getToContext(), ToCallee, |
Craig Topper | c005cc0 | 2015-09-27 03:44:08 +0000 | [diff] [blame] | 6512 | llvm::makeArrayRef(ToArgs_Copied, NumArgs), T, E->getValueKind(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6513 | Importer.Import(E->getRParenLoc())); |
| 6514 | } |
| 6515 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6516 | Optional<LambdaCapture> |
| 6517 | ASTNodeImporter::ImportLambdaCapture(const LambdaCapture &From) { |
| 6518 | VarDecl *Var = nullptr; |
| 6519 | if (From.capturesVariable()) { |
| 6520 | Var = cast_or_null<VarDecl>(Importer.Import(From.getCapturedVar())); |
| 6521 | if (!Var) |
| 6522 | return None; |
| 6523 | } |
| 6524 | |
| 6525 | return LambdaCapture(Importer.Import(From.getLocation()), From.isImplicit(), |
| 6526 | From.getCaptureKind(), Var, |
| 6527 | From.isPackExpansion() |
| 6528 | ? Importer.Import(From.getEllipsisLoc()) |
| 6529 | : SourceLocation()); |
| 6530 | } |
| 6531 | |
| 6532 | Expr *ASTNodeImporter::VisitLambdaExpr(LambdaExpr *LE) { |
| 6533 | CXXRecordDecl *FromClass = LE->getLambdaClass(); |
| 6534 | auto *ToClass = dyn_cast_or_null<CXXRecordDecl>(Importer.Import(FromClass)); |
| 6535 | if (!ToClass) |
| 6536 | return nullptr; |
| 6537 | |
| 6538 | // NOTE: lambda classes are created with BeingDefined flag set up. |
| 6539 | // It means that ImportDefinition doesn't work for them and we should fill it |
| 6540 | // manually. |
| 6541 | if (ToClass->isBeingDefined()) { |
| 6542 | for (auto FromField : FromClass->fields()) { |
| 6543 | auto *ToField = cast_or_null<FieldDecl>(Importer.Import(FromField)); |
| 6544 | if (!ToField) |
| 6545 | return nullptr; |
| 6546 | } |
| 6547 | } |
| 6548 | |
| 6549 | auto *ToCallOp = dyn_cast_or_null<CXXMethodDecl>( |
| 6550 | Importer.Import(LE->getCallOperator())); |
| 6551 | if (!ToCallOp) |
| 6552 | return nullptr; |
| 6553 | |
| 6554 | ToClass->completeDefinition(); |
| 6555 | |
| 6556 | unsigned NumCaptures = LE->capture_size(); |
| 6557 | SmallVector<LambdaCapture, 8> Captures; |
| 6558 | Captures.reserve(NumCaptures); |
| 6559 | for (const auto &FromCapture : LE->captures()) { |
| 6560 | if (auto ToCapture = ImportLambdaCapture(FromCapture)) |
| 6561 | Captures.push_back(*ToCapture); |
| 6562 | else |
| 6563 | return nullptr; |
| 6564 | } |
| 6565 | |
| 6566 | SmallVector<Expr *, 8> InitCaptures(NumCaptures); |
| 6567 | if (ImportContainerChecked(LE->capture_inits(), InitCaptures)) |
| 6568 | return nullptr; |
| 6569 | |
| 6570 | return LambdaExpr::Create(Importer.getToContext(), ToClass, |
| 6571 | Importer.Import(LE->getIntroducerRange()), |
| 6572 | LE->getCaptureDefault(), |
| 6573 | Importer.Import(LE->getCaptureDefaultLoc()), |
| 6574 | Captures, |
| 6575 | LE->hasExplicitParameters(), |
| 6576 | LE->hasExplicitResultType(), |
| 6577 | InitCaptures, |
| 6578 | Importer.Import(LE->getLocEnd()), |
| 6579 | LE->containsUnexpandedParameterPack()); |
| 6580 | } |
| 6581 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6582 | Expr *ASTNodeImporter::VisitInitListExpr(InitListExpr *ILE) { |
| 6583 | QualType T = Importer.Import(ILE->getType()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6584 | if (T.isNull()) |
| 6585 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6586 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6587 | SmallVector<Expr *, 4> Exprs(ILE->getNumInits()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6588 | if (ImportContainerChecked(ILE->inits(), Exprs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6589 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6590 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6591 | ASTContext &ToCtx = Importer.getToContext(); |
| 6592 | InitListExpr *To = new (ToCtx) InitListExpr( |
| 6593 | ToCtx, Importer.Import(ILE->getLBraceLoc()), |
| 6594 | Exprs, Importer.Import(ILE->getLBraceLoc())); |
| 6595 | To->setType(T); |
| 6596 | |
| 6597 | if (ILE->hasArrayFiller()) { |
| 6598 | Expr *Filler = Importer.Import(ILE->getArrayFiller()); |
| 6599 | if (!Filler) |
| 6600 | return nullptr; |
| 6601 | To->setArrayFiller(Filler); |
| 6602 | } |
| 6603 | |
| 6604 | if (FieldDecl *FromFD = ILE->getInitializedFieldInUnion()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6605 | auto *ToFD = cast_or_null<FieldDecl>(Importer.Import(FromFD)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6606 | if (!ToFD) |
| 6607 | return nullptr; |
| 6608 | To->setInitializedFieldInUnion(ToFD); |
| 6609 | } |
| 6610 | |
| 6611 | if (InitListExpr *SyntForm = ILE->getSyntacticForm()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6612 | auto *ToSyntForm = cast_or_null<InitListExpr>(Importer.Import(SyntForm)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6613 | if (!ToSyntForm) |
| 6614 | return nullptr; |
| 6615 | To->setSyntacticForm(ToSyntForm); |
| 6616 | } |
| 6617 | |
| 6618 | To->sawArrayRangeDesignator(ILE->hadArrayRangeDesignator()); |
| 6619 | To->setValueDependent(ILE->isValueDependent()); |
| 6620 | To->setInstantiationDependent(ILE->isInstantiationDependent()); |
| 6621 | |
| 6622 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6623 | } |
| 6624 | |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 6625 | Expr *ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 6626 | QualType ToType = Importer.Import(E->getType()); |
| 6627 | if (ToType.isNull()) |
| 6628 | return nullptr; |
| 6629 | |
| 6630 | Expr *ToCommon = Importer.Import(E->getCommonExpr()); |
| 6631 | if (!ToCommon && E->getCommonExpr()) |
| 6632 | return nullptr; |
| 6633 | |
| 6634 | Expr *ToSubExpr = Importer.Import(E->getSubExpr()); |
| 6635 | if (!ToSubExpr && E->getSubExpr()) |
| 6636 | return nullptr; |
| 6637 | |
| 6638 | return new (Importer.getToContext()) |
| 6639 | ArrayInitLoopExpr(ToType, ToCommon, ToSubExpr); |
| 6640 | } |
| 6641 | |
| 6642 | Expr *ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 6643 | QualType ToType = Importer.Import(E->getType()); |
| 6644 | if (ToType.isNull()) |
| 6645 | return nullptr; |
| 6646 | return new (Importer.getToContext()) ArrayInitIndexExpr(ToType); |
| 6647 | } |
| 6648 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6649 | Expr *ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6650 | auto *ToField = dyn_cast_or_null<FieldDecl>(Importer.Import(DIE->getField())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6651 | if (!ToField && DIE->getField()) |
| 6652 | return nullptr; |
| 6653 | |
| 6654 | return CXXDefaultInitExpr::Create( |
| 6655 | Importer.getToContext(), Importer.Import(DIE->getLocStart()), ToField); |
| 6656 | } |
| 6657 | |
| 6658 | Expr *ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 6659 | QualType ToType = Importer.Import(E->getType()); |
| 6660 | if (ToType.isNull() && !E->getType().isNull()) |
| 6661 | return nullptr; |
| 6662 | ExprValueKind VK = E->getValueKind(); |
| 6663 | CastKind CK = E->getCastKind(); |
| 6664 | Expr *ToOp = Importer.Import(E->getSubExpr()); |
| 6665 | if (!ToOp && E->getSubExpr()) |
| 6666 | return nullptr; |
| 6667 | CXXCastPath BasePath; |
| 6668 | if (ImportCastPath(E, BasePath)) |
| 6669 | return nullptr; |
| 6670 | TypeSourceInfo *ToWritten = Importer.Import(E->getTypeInfoAsWritten()); |
| 6671 | SourceLocation ToOperatorLoc = Importer.Import(E->getOperatorLoc()); |
| 6672 | SourceLocation ToRParenLoc = Importer.Import(E->getRParenLoc()); |
| 6673 | SourceRange ToAngleBrackets = Importer.Import(E->getAngleBrackets()); |
| 6674 | |
| 6675 | if (isa<CXXStaticCastExpr>(E)) { |
| 6676 | return CXXStaticCastExpr::Create( |
| 6677 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6678 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6679 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 6680 | return CXXDynamicCastExpr::Create( |
| 6681 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6682 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6683 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 6684 | return CXXReinterpretCastExpr::Create( |
| 6685 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6686 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6687 | } else { |
| 6688 | return nullptr; |
| 6689 | } |
| 6690 | } |
| 6691 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6692 | Expr *ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
| 6693 | SubstNonTypeTemplateParmExpr *E) { |
| 6694 | QualType T = Importer.Import(E->getType()); |
| 6695 | if (T.isNull()) |
| 6696 | return nullptr; |
| 6697 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6698 | auto *Param = cast_or_null<NonTypeTemplateParmDecl>( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6699 | Importer.Import(E->getParameter())); |
| 6700 | if (!Param) |
| 6701 | return nullptr; |
| 6702 | |
| 6703 | Expr *Replacement = Importer.Import(E->getReplacement()); |
| 6704 | if (!Replacement) |
| 6705 | return nullptr; |
| 6706 | |
| 6707 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
| 6708 | T, E->getValueKind(), Importer.Import(E->getExprLoc()), Param, |
| 6709 | Replacement); |
| 6710 | } |
| 6711 | |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 6712 | Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 6713 | QualType ToType = Importer.Import(E->getType()); |
| 6714 | if (ToType.isNull()) |
| 6715 | return nullptr; |
| 6716 | |
| 6717 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
| 6718 | if (ImportContainerChecked(E->getArgs(), ToArgs)) |
| 6719 | return nullptr; |
| 6720 | |
| 6721 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 6722 | // Value is always false. |
| 6723 | bool ToValue = false; |
| 6724 | if (!E->isValueDependent()) |
| 6725 | ToValue = E->getValue(); |
| 6726 | |
| 6727 | return TypeTraitExpr::Create( |
| 6728 | Importer.getToContext(), ToType, Importer.Import(E->getLocStart()), |
| 6729 | E->getTrait(), ToArgs, Importer.Import(E->getLocEnd()), ToValue); |
| 6730 | } |
| 6731 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6732 | Expr *ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 6733 | QualType ToType = Importer.Import(E->getType()); |
| 6734 | if (ToType.isNull()) |
| 6735 | return nullptr; |
| 6736 | |
| 6737 | if (E->isTypeOperand()) { |
| 6738 | TypeSourceInfo *TSI = Importer.Import(E->getTypeOperandSourceInfo()); |
| 6739 | if (!TSI) |
| 6740 | return nullptr; |
| 6741 | |
| 6742 | return new (Importer.getToContext()) |
| 6743 | CXXTypeidExpr(ToType, TSI, Importer.Import(E->getSourceRange())); |
| 6744 | } |
| 6745 | |
| 6746 | Expr *Op = Importer.Import(E->getExprOperand()); |
| 6747 | if (!Op) |
| 6748 | return nullptr; |
| 6749 | |
| 6750 | return new (Importer.getToContext()) |
| 6751 | CXXTypeidExpr(ToType, Op, Importer.Import(E->getSourceRange())); |
| 6752 | } |
| 6753 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 6754 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 6755 | CXXMethodDecl *FromMethod) { |
| 6756 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) |
| 6757 | ToMethod->addOverriddenMethod( |
| 6758 | cast<CXXMethodDecl>(Importer.Import(const_cast<CXXMethodDecl*>( |
| 6759 | FromOverriddenMethod)))); |
| 6760 | } |
| 6761 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6762 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 6763 | ASTContext &FromContext, FileManager &FromFileManager, |
| 6764 | bool MinimalImport) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6765 | : ToContext(ToContext), FromContext(FromContext), |
| 6766 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| 6767 | Minimal(MinimalImport) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6768 | ImportedDecls[FromContext.getTranslationUnitDecl()] |
| 6769 | = ToContext.getTranslationUnitDecl(); |
| 6770 | } |
| 6771 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6772 | ASTImporter::~ASTImporter() = default; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6773 | |
| 6774 | QualType ASTImporter::Import(QualType FromT) { |
| 6775 | if (FromT.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6776 | return {}; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6777 | |
| 6778 | const Type *fromTy = FromT.getTypePtr(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6779 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6780 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6781 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
| 6782 | = ImportedTypes.find(fromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6783 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6784 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6785 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6786 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6787 | ASTNodeImporter Importer(*this); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6788 | QualType ToT = Importer.Visit(fromTy); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6789 | if (ToT.isNull()) |
| 6790 | return ToT; |
| 6791 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6792 | // Record the imported type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6793 | ImportedTypes[fromTy] = ToT.getTypePtr(); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6794 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6795 | return ToContext.getQualifiedType(ToT, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6796 | } |
| 6797 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6798 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 6799 | if (!FromTSI) |
| 6800 | return FromTSI; |
| 6801 | |
| 6802 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 6803 | // 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] | 6804 | QualType T = Import(FromTSI->getType()); |
| 6805 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6806 | return nullptr; |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 6807 | |
| 6808 | return ToContext.getTrivialTypeSourceInfo(T, |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 6809 | Import(FromTSI->getTypeLoc().getLocStart())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6810 | } |
| 6811 | |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 6812 | Attr *ASTImporter::Import(const Attr *FromAttr) { |
| 6813 | Attr *ToAttr = FromAttr->clone(ToContext); |
| 6814 | ToAttr->setRange(Import(FromAttr->getRange())); |
| 6815 | return ToAttr; |
| 6816 | } |
| 6817 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6818 | Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) { |
| 6819 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
| 6820 | if (Pos != ImportedDecls.end()) { |
| 6821 | Decl *ToD = Pos->second; |
| 6822 | ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD); |
| 6823 | return ToD; |
| 6824 | } else { |
| 6825 | return nullptr; |
| 6826 | } |
| 6827 | } |
| 6828 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6829 | Decl *ASTImporter::Import(Decl *FromD) { |
| 6830 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6831 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6832 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6833 | ASTNodeImporter Importer(*this); |
| 6834 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6835 | // Check whether we've already imported this declaration. |
| 6836 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6837 | if (Pos != ImportedDecls.end()) { |
| 6838 | Decl *ToD = Pos->second; |
| 6839 | Importer.ImportDefinitionIfNeeded(FromD, ToD); |
| 6840 | return ToD; |
| 6841 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6842 | |
| 6843 | // Import the type |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6844 | Decl *ToD = Importer.Visit(FromD); |
| 6845 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6846 | return nullptr; |
| 6847 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6848 | // Record the imported declaration. |
| 6849 | ImportedDecls[FromD] = ToD; |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 6850 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6851 | return ToD; |
| 6852 | } |
| 6853 | |
| 6854 | DeclContext *ASTImporter::ImportContext(DeclContext *FromDC) { |
| 6855 | if (!FromDC) |
| 6856 | return FromDC; |
| 6857 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6858 | auto *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6859 | if (!ToDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6860 | return nullptr; |
| 6861 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6862 | // When we're using a record/enum/Objective-C class/protocol as a context, we |
| 6863 | // need it to have a definition. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6864 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 6865 | auto *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6866 | if (ToRecord->isCompleteDefinition()) { |
| 6867 | // Do nothing. |
| 6868 | } else if (FromRecord->isCompleteDefinition()) { |
| 6869 | ASTNodeImporter(*this).ImportDefinition(FromRecord, ToRecord, |
| 6870 | ASTNodeImporter::IDK_Basic); |
| 6871 | } else { |
| 6872 | CompleteDecl(ToRecord); |
| 6873 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6874 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 6875 | auto *FromEnum = cast<EnumDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6876 | if (ToEnum->isCompleteDefinition()) { |
| 6877 | // Do nothing. |
| 6878 | } else if (FromEnum->isCompleteDefinition()) { |
| 6879 | ASTNodeImporter(*this).ImportDefinition(FromEnum, ToEnum, |
| 6880 | ASTNodeImporter::IDK_Basic); |
| 6881 | } else { |
| 6882 | CompleteDecl(ToEnum); |
| 6883 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6884 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 6885 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6886 | if (ToClass->getDefinition()) { |
| 6887 | // Do nothing. |
| 6888 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
| 6889 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToClass, |
| 6890 | ASTNodeImporter::IDK_Basic); |
| 6891 | } else { |
| 6892 | CompleteDecl(ToClass); |
| 6893 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6894 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 6895 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6896 | if (ToProto->getDefinition()) { |
| 6897 | // Do nothing. |
| 6898 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
| 6899 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToProto, |
| 6900 | ASTNodeImporter::IDK_Basic); |
| 6901 | } else { |
| 6902 | CompleteDecl(ToProto); |
| 6903 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 6904 | } |
| 6905 | |
| 6906 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6907 | } |
| 6908 | |
| 6909 | Expr *ASTImporter::Import(Expr *FromE) { |
| 6910 | if (!FromE) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6911 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6912 | |
| 6913 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); |
| 6914 | } |
| 6915 | |
| 6916 | Stmt *ASTImporter::Import(Stmt *FromS) { |
| 6917 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6918 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6919 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6920 | // Check whether we've already imported this declaration. |
| 6921 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 6922 | if (Pos != ImportedStmts.end()) |
| 6923 | return Pos->second; |
| 6924 | |
| 6925 | // Import the type |
| 6926 | ASTNodeImporter Importer(*this); |
| 6927 | Stmt *ToS = Importer.Visit(FromS); |
| 6928 | if (!ToS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6929 | return nullptr; |
| 6930 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6931 | // Record the imported declaration. |
| 6932 | ImportedStmts[FromS] = ToS; |
| 6933 | return ToS; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6934 | } |
| 6935 | |
| 6936 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| 6937 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6938 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6939 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6940 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); |
| 6941 | |
| 6942 | switch (FromNNS->getKind()) { |
| 6943 | case NestedNameSpecifier::Identifier: |
| 6944 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { |
| 6945 | return NestedNameSpecifier::Create(ToContext, prefix, II); |
| 6946 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6947 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6948 | |
| 6949 | case NestedNameSpecifier::Namespace: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6950 | if (auto *NS = |
| 6951 | cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6952 | return NestedNameSpecifier::Create(ToContext, prefix, NS); |
| 6953 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6954 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6955 | |
| 6956 | case NestedNameSpecifier::NamespaceAlias: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6957 | if (auto *NSAD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6958 | cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6959 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); |
| 6960 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6961 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6962 | |
| 6963 | case NestedNameSpecifier::Global: |
| 6964 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 6965 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 6966 | case NestedNameSpecifier::Super: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6967 | if (auto *RD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6968 | cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) { |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 6969 | return NestedNameSpecifier::SuperSpecifier(ToContext, RD); |
| 6970 | } |
| 6971 | return nullptr; |
| 6972 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6973 | case NestedNameSpecifier::TypeSpec: |
| 6974 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 6975 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); |
| 6976 | if (!T.isNull()) { |
| 6977 | bool bTemplate = FromNNS->getKind() == |
| 6978 | NestedNameSpecifier::TypeSpecWithTemplate; |
| 6979 | return NestedNameSpecifier::Create(ToContext, prefix, |
| 6980 | bTemplate, T.getTypePtr()); |
| 6981 | } |
| 6982 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6983 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6984 | } |
| 6985 | |
| 6986 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6987 | } |
| 6988 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 6989 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6990 | // Copied from NestedNameSpecifier mostly. |
| 6991 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 6992 | NestedNameSpecifierLoc NNS = FromNNS; |
| 6993 | |
| 6994 | // Push each of the nested-name-specifiers's onto a stack for |
| 6995 | // serialization in reverse order. |
| 6996 | while (NNS) { |
| 6997 | NestedNames.push_back(NNS); |
| 6998 | NNS = NNS.getPrefix(); |
| 6999 | } |
| 7000 | |
| 7001 | NestedNameSpecifierLocBuilder Builder; |
| 7002 | |
| 7003 | while (!NestedNames.empty()) { |
| 7004 | NNS = NestedNames.pop_back_val(); |
| 7005 | NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier()); |
| 7006 | if (!Spec) |
| 7007 | return NestedNameSpecifierLoc(); |
| 7008 | |
| 7009 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| 7010 | switch (Kind) { |
| 7011 | case NestedNameSpecifier::Identifier: |
| 7012 | Builder.Extend(getToContext(), |
| 7013 | Spec->getAsIdentifier(), |
| 7014 | Import(NNS.getLocalBeginLoc()), |
| 7015 | Import(NNS.getLocalEndLoc())); |
| 7016 | break; |
| 7017 | |
| 7018 | case NestedNameSpecifier::Namespace: |
| 7019 | Builder.Extend(getToContext(), |
| 7020 | Spec->getAsNamespace(), |
| 7021 | Import(NNS.getLocalBeginLoc()), |
| 7022 | Import(NNS.getLocalEndLoc())); |
| 7023 | break; |
| 7024 | |
| 7025 | case NestedNameSpecifier::NamespaceAlias: |
| 7026 | Builder.Extend(getToContext(), |
| 7027 | Spec->getAsNamespaceAlias(), |
| 7028 | Import(NNS.getLocalBeginLoc()), |
| 7029 | Import(NNS.getLocalEndLoc())); |
| 7030 | break; |
| 7031 | |
| 7032 | case NestedNameSpecifier::TypeSpec: |
| 7033 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7034 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| 7035 | QualType(Spec->getAsType(), 0)); |
| 7036 | Builder.Extend(getToContext(), |
| 7037 | Import(NNS.getLocalBeginLoc()), |
| 7038 | TSI->getTypeLoc(), |
| 7039 | Import(NNS.getLocalEndLoc())); |
| 7040 | break; |
| 7041 | } |
| 7042 | |
| 7043 | case NestedNameSpecifier::Global: |
| 7044 | Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc())); |
| 7045 | break; |
| 7046 | |
| 7047 | case NestedNameSpecifier::Super: { |
| 7048 | SourceRange ToRange = Import(NNS.getSourceRange()); |
| 7049 | Builder.MakeSuper(getToContext(), |
| 7050 | Spec->getAsRecordDecl(), |
| 7051 | ToRange.getBegin(), |
| 7052 | ToRange.getEnd()); |
| 7053 | } |
| 7054 | } |
| 7055 | } |
| 7056 | |
| 7057 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 7058 | } |
| 7059 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7060 | TemplateName ASTImporter::Import(TemplateName From) { |
| 7061 | switch (From.getKind()) { |
| 7062 | case TemplateName::Template: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7063 | if (auto *ToTemplate = |
| 7064 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7065 | return TemplateName(ToTemplate); |
| 7066 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7067 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7068 | |
| 7069 | case TemplateName::OverloadedTemplate: { |
| 7070 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 7071 | UnresolvedSet<2> ToTemplates; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7072 | for (auto *I : *FromStorage) { |
| 7073 | if (auto *To = cast_or_null<NamedDecl>(Import(I))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7074 | ToTemplates.addDecl(To); |
| 7075 | else |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7076 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7077 | } |
| 7078 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
| 7079 | ToTemplates.end()); |
| 7080 | } |
| 7081 | |
| 7082 | case TemplateName::QualifiedTemplate: { |
| 7083 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| 7084 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); |
| 7085 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7086 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7087 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7088 | if (auto *ToTemplate = |
| 7089 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7090 | return ToContext.getQualifiedTemplateName(Qualifier, |
| 7091 | QTN->hasTemplateKeyword(), |
| 7092 | ToTemplate); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7093 | |
| 7094 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7095 | } |
| 7096 | |
| 7097 | case TemplateName::DependentTemplate: { |
| 7098 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| 7099 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); |
| 7100 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7101 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7102 | |
| 7103 | if (DTN->isIdentifier()) { |
| 7104 | return ToContext.getDependentTemplateName(Qualifier, |
| 7105 | Import(DTN->getIdentifier())); |
| 7106 | } |
| 7107 | |
| 7108 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); |
| 7109 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7110 | |
| 7111 | case TemplateName::SubstTemplateTemplateParm: { |
| 7112 | SubstTemplateTemplateParmStorage *subst |
| 7113 | = From.getAsSubstTemplateTemplateParm(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7114 | auto *param = |
| 7115 | cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7116 | if (!param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7117 | return {}; |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7118 | |
| 7119 | TemplateName replacement = Import(subst->getReplacement()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7120 | if (replacement.isNull()) |
| 7121 | return {}; |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7122 | |
| 7123 | return ToContext.getSubstTemplateTemplateParm(param, replacement); |
| 7124 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7125 | |
| 7126 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 7127 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 7128 | = From.getAsSubstTemplateTemplateParmPack(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7129 | auto *Param = |
| 7130 | cast_or_null<TemplateTemplateParmDecl>( |
| 7131 | Import(SubstPack->getParameterPack())); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7132 | if (!Param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7133 | return {}; |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7134 | |
| 7135 | ASTNodeImporter Importer(*this); |
| 7136 | TemplateArgument ArgPack |
| 7137 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 7138 | if (ArgPack.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7139 | return {}; |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7140 | |
| 7141 | return ToContext.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 7142 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7143 | } |
| 7144 | |
| 7145 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7146 | } |
| 7147 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7148 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { |
| 7149 | if (FromLoc.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7150 | return {}; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7151 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7152 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 7153 | |
Sean Callanan | 24c5fe6 | 2016-11-07 20:42:25 +0000 | [diff] [blame] | 7154 | // For now, map everything down to its file location, so that we |
Chandler Carruth | 2536641 | 2011-07-15 00:04:35 +0000 | [diff] [blame] | 7155 | // don't have to import macro expansions. |
| 7156 | // FIXME: Import macro expansions! |
Sean Callanan | 24c5fe6 | 2016-11-07 20:42:25 +0000 | [diff] [blame] | 7157 | FromLoc = FromSM.getFileLoc(FromLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7158 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
| 7159 | SourceManager &ToSM = ToContext.getSourceManager(); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 7160 | FileID ToFileID = Import(Decomposed.first); |
| 7161 | if (ToFileID.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7162 | return {}; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7163 | SourceLocation ret = ToSM.getLocForStartOfFile(ToFileID) |
| 7164 | .getLocWithOffset(Decomposed.second); |
| 7165 | return ret; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7166 | } |
| 7167 | |
| 7168 | SourceRange ASTImporter::Import(SourceRange FromRange) { |
| 7169 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); |
| 7170 | } |
| 7171 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7172 | FileID ASTImporter::Import(FileID FromID) { |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 7173 | llvm::DenseMap<FileID, FileID>::iterator Pos |
| 7174 | = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7175 | if (Pos != ImportedFileIDs.end()) |
| 7176 | return Pos->second; |
| 7177 | |
| 7178 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 7179 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 7180 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Chandler Carruth | 2536641 | 2011-07-15 00:04:35 +0000 | [diff] [blame] | 7181 | assert(FromSLoc.isFile() && "Cannot handle macro expansions yet"); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7182 | |
| 7183 | // Include location of this file. |
| 7184 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| 7185 | |
| 7186 | // Map the FileID for to the "to" source manager. |
| 7187 | FileID ToID; |
| 7188 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
Sean Callanan | 25d34af | 2015-04-30 00:44:21 +0000 | [diff] [blame] | 7189 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7190 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 7191 | // disk again |
| 7192 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 7193 | // than mmap the files several times. |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 7194 | const FileEntry *Entry = ToFileManager.getFile(Cache->OrigEntry->getName()); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 7195 | if (!Entry) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7196 | return {}; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7197 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, |
| 7198 | FromSLoc.getFile().getFileCharacteristic()); |
| 7199 | } else { |
| 7200 | // FIXME: We want to re-use the existing MemoryBuffer! |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7201 | const llvm::MemoryBuffer * |
| 7202 | FromBuf = Cache->getBuffer(FromContext.getDiagnostics(), FromSM); |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 7203 | std::unique_ptr<llvm::MemoryBuffer> ToBuf |
Chris Lattner | 58c7934 | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 7204 | = llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7205 | FromBuf->getBufferIdentifier()); |
David Blaikie | 50a5f97 | 2014-08-29 07:59:55 +0000 | [diff] [blame] | 7206 | ToID = ToSM.createFileID(std::move(ToBuf), |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 7207 | FromSLoc.getFile().getFileCharacteristic()); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7208 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7209 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 7210 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7211 | return ToID; |
| 7212 | } |
| 7213 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7214 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { |
| 7215 | Expr *ToExpr = Import(From->getInit()); |
| 7216 | if (!ToExpr && From->getInit()) |
| 7217 | return nullptr; |
| 7218 | |
| 7219 | if (From->isBaseInitializer()) { |
| 7220 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 7221 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 7222 | return nullptr; |
| 7223 | |
| 7224 | return new (ToContext) CXXCtorInitializer( |
| 7225 | ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()), |
| 7226 | ToExpr, Import(From->getRParenLoc()), |
| 7227 | From->isPackExpansion() ? Import(From->getEllipsisLoc()) |
| 7228 | : SourceLocation()); |
| 7229 | } else if (From->isMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7230 | auto *ToField = cast_or_null<FieldDecl>(Import(From->getMember())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7231 | if (!ToField && From->getMember()) |
| 7232 | return nullptr; |
| 7233 | |
| 7234 | return new (ToContext) CXXCtorInitializer( |
| 7235 | ToContext, ToField, Import(From->getMemberLocation()), |
| 7236 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 7237 | } else if (From->isIndirectMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7238 | auto *ToIField = cast_or_null<IndirectFieldDecl>( |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7239 | Import(From->getIndirectMember())); |
| 7240 | if (!ToIField && From->getIndirectMember()) |
| 7241 | return nullptr; |
| 7242 | |
| 7243 | return new (ToContext) CXXCtorInitializer( |
| 7244 | ToContext, ToIField, Import(From->getMemberLocation()), |
| 7245 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 7246 | } else if (From->isDelegatingInitializer()) { |
| 7247 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 7248 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 7249 | return nullptr; |
| 7250 | |
| 7251 | return new (ToContext) |
| 7252 | CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()), |
| 7253 | ToExpr, Import(From->getRParenLoc())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7254 | } else { |
| 7255 | return nullptr; |
| 7256 | } |
| 7257 | } |
| 7258 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7259 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| 7260 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 7261 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 7262 | return Pos->second; |
| 7263 | |
| 7264 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| 7265 | Import(BaseSpec->getSourceRange()), |
| 7266 | BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 7267 | BaseSpec->getAccessSpecifierAsWritten(), |
| 7268 | Import(BaseSpec->getTypeSourceInfo()), |
| 7269 | Import(BaseSpec->getEllipsisLoc())); |
| 7270 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 7271 | return Imported; |
| 7272 | } |
| 7273 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7274 | void ASTImporter::ImportDefinition(Decl *From) { |
| 7275 | Decl *To = Import(From); |
| 7276 | if (!To) |
| 7277 | return; |
| 7278 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7279 | if (auto *FromDC = cast<DeclContext>(From)) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7280 | ASTNodeImporter Importer(*this); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7281 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7282 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7283 | if (!ToRecord->getDefinition()) { |
| 7284 | Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7285 | ASTNodeImporter::IDK_Everything); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7286 | return; |
| 7287 | } |
| 7288 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7289 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7290 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7291 | if (!ToEnum->getDefinition()) { |
| 7292 | Importer.ImportDefinition(cast<EnumDecl>(FromDC), ToEnum, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7293 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7294 | return; |
| 7295 | } |
| 7296 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7297 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7298 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7299 | if (!ToIFace->getDefinition()) { |
| 7300 | Importer.ImportDefinition(cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7301 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7302 | return; |
| 7303 | } |
| 7304 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7305 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7306 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7307 | if (!ToProto->getDefinition()) { |
| 7308 | Importer.ImportDefinition(cast<ObjCProtocolDecl>(FromDC), ToProto, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7309 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7310 | return; |
| 7311 | } |
| 7312 | } |
| 7313 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7314 | Importer.ImportDeclContext(FromDC, true); |
| 7315 | } |
| 7316 | } |
| 7317 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7318 | DeclarationName ASTImporter::Import(DeclarationName FromName) { |
| 7319 | if (!FromName) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7320 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7321 | |
| 7322 | switch (FromName.getNameKind()) { |
| 7323 | case DeclarationName::Identifier: |
| 7324 | return Import(FromName.getAsIdentifierInfo()); |
| 7325 | |
| 7326 | case DeclarationName::ObjCZeroArgSelector: |
| 7327 | case DeclarationName::ObjCOneArgSelector: |
| 7328 | case DeclarationName::ObjCMultiArgSelector: |
| 7329 | return Import(FromName.getObjCSelector()); |
| 7330 | |
| 7331 | case DeclarationName::CXXConstructorName: { |
| 7332 | QualType T = Import(FromName.getCXXNameType()); |
| 7333 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7334 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7335 | |
| 7336 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 7337 | ToContext.getCanonicalType(T)); |
| 7338 | } |
| 7339 | |
| 7340 | case DeclarationName::CXXDestructorName: { |
| 7341 | QualType T = Import(FromName.getCXXNameType()); |
| 7342 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7343 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7344 | |
| 7345 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 7346 | ToContext.getCanonicalType(T)); |
| 7347 | } |
| 7348 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7349 | case DeclarationName::CXXDeductionGuideName: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7350 | auto *Template = cast_or_null<TemplateDecl>( |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7351 | Import(FromName.getCXXDeductionGuideTemplate())); |
| 7352 | if (!Template) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7353 | return {}; |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7354 | return ToContext.DeclarationNames.getCXXDeductionGuideName(Template); |
| 7355 | } |
| 7356 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7357 | case DeclarationName::CXXConversionFunctionName: { |
| 7358 | QualType T = Import(FromName.getCXXNameType()); |
| 7359 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7360 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7361 | |
| 7362 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 7363 | ToContext.getCanonicalType(T)); |
| 7364 | } |
| 7365 | |
| 7366 | case DeclarationName::CXXOperatorName: |
| 7367 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 7368 | FromName.getCXXOverloadedOperator()); |
| 7369 | |
| 7370 | case DeclarationName::CXXLiteralOperatorName: |
| 7371 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| 7372 | Import(FromName.getCXXLiteralIdentifier())); |
| 7373 | |
| 7374 | case DeclarationName::CXXUsingDirective: |
| 7375 | // FIXME: STATICS! |
| 7376 | return DeclarationName::getUsingDirectiveName(); |
| 7377 | } |
| 7378 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 7379 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7380 | } |
| 7381 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7382 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7383 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7384 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7385 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 7386 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 7387 | |
| 7388 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 7389 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 7390 | |
| 7391 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7392 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7393 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7394 | Selector ASTImporter::Import(Selector FromSel) { |
| 7395 | if (FromSel.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7396 | return {}; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7397 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 7398 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7399 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 7400 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 7401 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 7402 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 7403 | } |
| 7404 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7405 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 7406 | DeclContext *DC, |
| 7407 | unsigned IDNS, |
| 7408 | NamedDecl **Decls, |
| 7409 | unsigned NumDecls) { |
| 7410 | return Name; |
| 7411 | } |
| 7412 | |
| 7413 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 7414 | if (LastDiagFromFrom) |
| 7415 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 7416 | FromContext.getDiagnostics()); |
| 7417 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7418 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7419 | } |
| 7420 | |
| 7421 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 7422 | if (!LastDiagFromFrom) |
| 7423 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 7424 | ToContext.getDiagnostics()); |
| 7425 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7426 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7427 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7428 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7429 | void ASTImporter::CompleteDecl (Decl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7430 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7431 | if (!ID->getDefinition()) |
| 7432 | ID->startDefinition(); |
| 7433 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7434 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7435 | if (!PD->getDefinition()) |
| 7436 | PD->startDefinition(); |
| 7437 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7438 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7439 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 7440 | TD->startDefinition(); |
| 7441 | TD->setCompleteDefinition(true); |
| 7442 | } |
| 7443 | } |
| 7444 | else { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7445 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7446 | } |
| 7447 | } |
| 7448 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7449 | Decl *ASTImporter::Imported(Decl *From, Decl *To) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7450 | if (From->hasAttrs()) { |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 7451 | for (const auto *FromAttr : From->getAttrs()) |
| 7452 | To->addAttr(Import(FromAttr)); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7453 | } |
| 7454 | if (From->isUsed()) { |
| 7455 | To->setIsUsed(); |
| 7456 | } |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7457 | if (From->isImplicit()) { |
| 7458 | To->setImplicit(); |
| 7459 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7460 | ImportedDecls[From] = To; |
| 7461 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 7462 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7463 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 7464 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 7465 | bool Complain) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7466 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7467 | = ImportedTypes.find(From.getTypePtr()); |
| 7468 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) |
| 7469 | return true; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 7470 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 7471 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
| 7472 | false, Complain); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 7473 | return Ctx.IsStructurallyEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7474 | } |