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 | |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 74 | unsigned ASTImporter::getFieldIndex(Decl *F) { |
| 75 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && |
| 76 | "Try to get field index for non-field."); |
| 77 | |
| 78 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
| 79 | if (!Owner) |
| 80 | return 0; |
| 81 | |
| 82 | unsigned Index = 1; |
| 83 | for (const auto *D : Owner->decls()) { |
| 84 | if (D == F) |
| 85 | return Index; |
| 86 | |
| 87 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 88 | ++Index; |
| 89 | } |
| 90 | |
| 91 | llvm_unreachable("Field was not found in its parent context."); |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 96 | template <class T> |
| 97 | SmallVector<Decl*, 2> |
| 98 | getCanonicalForwardRedeclChain(Redeclarable<T>* D) { |
| 99 | SmallVector<Decl*, 2> Redecls; |
| 100 | for (auto *R : D->getFirstDecl()->redecls()) { |
| 101 | if (R != D->getFirstDecl()) |
| 102 | Redecls.push_back(R); |
| 103 | } |
| 104 | Redecls.push_back(D->getFirstDecl()); |
| 105 | std::reverse(Redecls.begin(), Redecls.end()); |
| 106 | return Redecls; |
| 107 | } |
| 108 | |
| 109 | SmallVector<Decl*, 2> getCanonicalForwardRedeclChain(Decl* D) { |
| 110 | // Currently only FunctionDecl is supported |
| 111 | auto FD = cast<FunctionDecl>(D); |
| 112 | return getCanonicalForwardRedeclChain<FunctionDecl>(FD); |
| 113 | } |
| 114 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 115 | void updateFlags(const Decl *From, Decl *To) { |
| 116 | // Check if some flags or attrs are new in 'From' and copy into 'To'. |
| 117 | // FIXME: Other flags or attrs? |
| 118 | if (From->isUsed(false) && !To->isUsed(false)) |
| 119 | To->setIsUsed(); |
| 120 | } |
| 121 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 122 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, QualType>, |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 123 | public DeclVisitor<ASTNodeImporter, Decl *>, |
| 124 | public StmtVisitor<ASTNodeImporter, Stmt *> { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 125 | ASTImporter &Importer; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 126 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 127 | // Wrapper for an overload set. |
| 128 | template <typename ToDeclT> struct CallOverloadedCreateFun { |
| 129 | template <typename... Args> |
| 130 | auto operator()(Args &&... args) |
| 131 | -> decltype(ToDeclT::Create(std::forward<Args>(args)...)) { |
| 132 | return ToDeclT::Create(std::forward<Args>(args)...); |
| 133 | } |
| 134 | }; |
| 135 | |
| 136 | // Always use these functions to create a Decl during import. There are |
| 137 | // certain tasks which must be done after the Decl was created, e.g. we |
| 138 | // must immediately register that as an imported Decl. The parameter `ToD` |
| 139 | // will be set to the newly created Decl or if had been imported before |
| 140 | // then to the already imported Decl. Returns a bool value set to true if |
| 141 | // the `FromD` had been imported before. |
| 142 | template <typename ToDeclT, typename FromDeclT, typename... Args> |
| 143 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 144 | Args &&... args) { |
| 145 | // There may be several overloads of ToDeclT::Create. We must make sure |
| 146 | // to call the one which would be chosen by the arguments, thus we use a |
| 147 | // wrapper for the overload set. |
| 148 | CallOverloadedCreateFun<ToDeclT> OC; |
| 149 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 150 | std::forward<Args>(args)...); |
| 151 | } |
| 152 | // Use this overload if a special Type is needed to be created. E.g if we |
| 153 | // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl` |
| 154 | // then: |
| 155 | // TypedefNameDecl *ToTypedef; |
| 156 | // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...); |
| 157 | template <typename NewDeclT, typename ToDeclT, typename FromDeclT, |
| 158 | typename... Args> |
| 159 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 160 | Args &&... args) { |
| 161 | CallOverloadedCreateFun<NewDeclT> OC; |
| 162 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 163 | std::forward<Args>(args)...); |
| 164 | } |
| 165 | // Use this version if a special create function must be |
| 166 | // used, e.g. CXXRecordDecl::CreateLambda . |
| 167 | template <typename ToDeclT, typename CreateFunT, typename FromDeclT, |
| 168 | typename... Args> |
| 169 | LLVM_NODISCARD bool |
| 170 | GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun, |
| 171 | FromDeclT *FromD, Args &&... args) { |
| 172 | ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD)); |
| 173 | if (ToD) |
| 174 | return true; // Already imported. |
| 175 | ToD = CreateFun(std::forward<Args>(args)...); |
| 176 | InitializeImportedDecl(FromD, ToD); |
| 177 | return false; // A new Decl is created. |
| 178 | } |
| 179 | |
| 180 | void InitializeImportedDecl(Decl *FromD, Decl *ToD) { |
| 181 | Importer.MapImported(FromD, ToD); |
| 182 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; |
| 183 | if (FromD->hasAttrs()) |
| 184 | for (const Attr *FromAttr : FromD->getAttrs()) |
| 185 | ToD->addAttr(Importer.Import(FromAttr)); |
| 186 | if (FromD->isUsed()) |
| 187 | ToD->setIsUsed(); |
| 188 | if (FromD->isImplicit()) |
| 189 | ToD->setImplicit(); |
| 190 | } |
| 191 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 192 | public: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 193 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} |
Gabor Marton | 344b099 | 2018-05-16 11:48:11 +0000 | [diff] [blame] | 194 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 195 | using TypeVisitor<ASTNodeImporter, QualType>::Visit; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 196 | using DeclVisitor<ASTNodeImporter, Decl *>::Visit; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 197 | using StmtVisitor<ASTNodeImporter, Stmt *>::Visit; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 198 | |
| 199 | // Importing types |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 200 | QualType VisitType(const Type *T); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 201 | QualType VisitAtomicType(const AtomicType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 202 | QualType VisitBuiltinType(const BuiltinType *T); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 203 | QualType VisitDecayedType(const DecayedType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 204 | QualType VisitComplexType(const ComplexType *T); |
| 205 | QualType VisitPointerType(const PointerType *T); |
| 206 | QualType VisitBlockPointerType(const BlockPointerType *T); |
| 207 | QualType VisitLValueReferenceType(const LValueReferenceType *T); |
| 208 | QualType VisitRValueReferenceType(const RValueReferenceType *T); |
| 209 | QualType VisitMemberPointerType(const MemberPointerType *T); |
| 210 | QualType VisitConstantArrayType(const ConstantArrayType *T); |
| 211 | QualType VisitIncompleteArrayType(const IncompleteArrayType *T); |
| 212 | QualType VisitVariableArrayType(const VariableArrayType *T); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 213 | QualType VisitDependentSizedArrayType(const DependentSizedArrayType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 214 | // FIXME: DependentSizedExtVectorType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 215 | QualType VisitVectorType(const VectorType *T); |
| 216 | QualType VisitExtVectorType(const ExtVectorType *T); |
| 217 | QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T); |
| 218 | QualType VisitFunctionProtoType(const FunctionProtoType *T); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 219 | QualType VisitUnresolvedUsingType(const UnresolvedUsingType *T); |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 220 | QualType VisitParenType(const ParenType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 221 | QualType VisitTypedefType(const TypedefType *T); |
| 222 | QualType VisitTypeOfExprType(const TypeOfExprType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 223 | // FIXME: DependentTypeOfExprType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 224 | QualType VisitTypeOfType(const TypeOfType *T); |
| 225 | QualType VisitDecltypeType(const DecltypeType *T); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 226 | QualType VisitUnaryTransformType(const UnaryTransformType *T); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 227 | QualType VisitAutoType(const AutoType *T); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 228 | QualType VisitInjectedClassNameType(const InjectedClassNameType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 229 | // FIXME: DependentDecltypeType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 230 | QualType VisitRecordType(const RecordType *T); |
| 231 | QualType VisitEnumType(const EnumType *T); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 232 | QualType VisitAttributedType(const AttributedType *T); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 233 | QualType VisitTemplateTypeParmType(const TemplateTypeParmType *T); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 234 | QualType VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 235 | QualType VisitTemplateSpecializationType(const TemplateSpecializationType *T); |
| 236 | QualType VisitElaboratedType(const ElaboratedType *T); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 237 | QualType VisitDependentNameType(const DependentNameType *T); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 238 | QualType VisitPackExpansionType(const PackExpansionType *T); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 239 | QualType VisitDependentTemplateSpecializationType( |
| 240 | const DependentTemplateSpecializationType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 241 | QualType VisitObjCInterfaceType(const ObjCInterfaceType *T); |
| 242 | QualType VisitObjCObjectType(const ObjCObjectType *T); |
| 243 | QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); |
Rafael Stahl | df55620 | 2018-05-29 08:12:15 +0000 | [diff] [blame] | 244 | |
| 245 | // Importing declarations |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 246 | bool ImportDeclParts(NamedDecl *D, DeclContext *&DC, |
| 247 | DeclContext *&LexicalDC, DeclarationName &Name, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 248 | NamedDecl *&ToD, SourceLocation &Loc); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 249 | void ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 250 | void ImportDeclarationNameLoc(const DeclarationNameInfo &From, |
| 251 | DeclarationNameInfo& To); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 252 | void ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 253 | void ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 254 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 255 | bool ImportCastPath(CastExpr *E, CXXCastPath &Path); |
| 256 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 257 | using Designator = DesignatedInitExpr::Designator; |
| 258 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 259 | Designator ImportDesignator(const Designator &D); |
| 260 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 261 | Optional<LambdaCapture> ImportLambdaCapture(const LambdaCapture &From); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 262 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 263 | /// What we should import from the definition. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 264 | enum ImportDefinitionKind { |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 265 | /// Import the default subset of the definition, which might be |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 266 | /// nothing (if minimal import is set) or might be everything (if minimal |
| 267 | /// import is not set). |
| 268 | IDK_Default, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 269 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 270 | /// Import everything. |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 271 | IDK_Everything, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 272 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 273 | /// Import only the bare bones needed to establish a valid |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 274 | /// DeclContext. |
| 275 | IDK_Basic |
| 276 | }; |
| 277 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 278 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { |
| 279 | return IDK == IDK_Everything || |
| 280 | (IDK == IDK_Default && !Importer.isMinimalImport()); |
| 281 | } |
| 282 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 283 | bool ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 284 | ImportDefinitionKind Kind = IDK_Default); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 285 | bool ImportDefinition(VarDecl *From, VarDecl *To, |
| 286 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 287 | bool ImportDefinition(EnumDecl *From, EnumDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 288 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 289 | bool ImportDefinition(ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 290 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 291 | bool ImportDefinition(ObjCProtocolDecl *From, ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 292 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 293 | TemplateParameterList *ImportTemplateParameterList( |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 294 | TemplateParameterList *Params); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 295 | TemplateArgument ImportTemplateArgument(const TemplateArgument &From); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 296 | Optional<TemplateArgumentLoc> ImportTemplateArgumentLoc( |
| 297 | const TemplateArgumentLoc &TALoc); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 298 | bool ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 299 | unsigned NumFromArgs, |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 300 | SmallVectorImpl<TemplateArgument> &ToArgs); |
| 301 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 302 | template <typename InContainerTy> |
| 303 | bool ImportTemplateArgumentListInfo(const InContainerTy &Container, |
| 304 | TemplateArgumentListInfo &ToTAInfo); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 305 | |
| 306 | template<typename InContainerTy> |
| 307 | bool ImportTemplateArgumentListInfo(SourceLocation FromLAngleLoc, |
| 308 | SourceLocation FromRAngleLoc, |
| 309 | const InContainerTy &Container, |
| 310 | TemplateArgumentListInfo &Result); |
| 311 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 312 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; |
| 313 | using OptionalTemplateArgsTy = Optional<TemplateArgsTy>; |
| 314 | std::tuple<FunctionTemplateDecl *, OptionalTemplateArgsTy> |
| 315 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 316 | FunctionDecl *FromFD); |
| 317 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 318 | bool ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); |
| 319 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 320 | bool IsStructuralMatch(Decl *From, Decl *To, bool Complain); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 321 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, |
| 322 | bool Complain = true); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 323 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 324 | bool Complain = true); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 325 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 326 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 327 | bool IsStructuralMatch(FunctionTemplateDecl *From, |
| 328 | FunctionTemplateDecl *To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 329 | bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 330 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 331 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 332 | Decl *VisitDecl(Decl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 333 | Decl *VisitEmptyDecl(EmptyDecl *D); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 334 | Decl *VisitAccessSpecDecl(AccessSpecDecl *D); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 335 | Decl *VisitStaticAssertDecl(StaticAssertDecl *D); |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 336 | Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 337 | Decl *VisitNamespaceDecl(NamespaceDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 338 | Decl *VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 339 | Decl *VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 340 | Decl *VisitTypedefDecl(TypedefDecl *D); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 341 | Decl *VisitTypeAliasDecl(TypeAliasDecl *D); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 342 | Decl *VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 343 | Decl *VisitLabelDecl(LabelDecl *D); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 344 | Decl *VisitEnumDecl(EnumDecl *D); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 345 | Decl *VisitRecordDecl(RecordDecl *D); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 346 | Decl *VisitEnumConstantDecl(EnumConstantDecl *D); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 347 | Decl *VisitFunctionDecl(FunctionDecl *D); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 348 | Decl *VisitCXXMethodDecl(CXXMethodDecl *D); |
| 349 | Decl *VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 350 | Decl *VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 351 | Decl *VisitCXXConversionDecl(CXXConversionDecl *D); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 352 | Decl *VisitFieldDecl(FieldDecl *D); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 353 | Decl *VisitIndirectFieldDecl(IndirectFieldDecl *D); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 354 | Decl *VisitFriendDecl(FriendDecl *D); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 355 | Decl *VisitObjCIvarDecl(ObjCIvarDecl *D); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 356 | Decl *VisitVarDecl(VarDecl *D); |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 357 | Decl *VisitImplicitParamDecl(ImplicitParamDecl *D); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 358 | Decl *VisitParmVarDecl(ParmVarDecl *D); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 359 | Decl *VisitObjCMethodDecl(ObjCMethodDecl *D); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 360 | Decl *VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 361 | Decl *VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 362 | Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 363 | Decl *VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 364 | Decl *VisitUsingDecl(UsingDecl *D); |
| 365 | Decl *VisitUsingShadowDecl(UsingShadowDecl *D); |
| 366 | Decl *VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 367 | Decl *VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| 368 | Decl *VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
| 369 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 370 | ObjCTypeParamList *ImportObjCTypeParamList(ObjCTypeParamList *list); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 371 | Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 372 | Decl *VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 373 | Decl *VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 374 | Decl *VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 375 | Decl *VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 376 | Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 377 | Decl *VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 378 | Decl *VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 379 | Decl *VisitClassTemplateDecl(ClassTemplateDecl *D); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 380 | Decl *VisitClassTemplateSpecializationDecl( |
| 381 | ClassTemplateSpecializationDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 382 | Decl *VisitVarTemplateDecl(VarTemplateDecl *D); |
| 383 | Decl *VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 384 | Decl *VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 385 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 386 | // Importing statements |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 387 | DeclGroupRef ImportDeclGroup(DeclGroupRef DG); |
| 388 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 389 | Stmt *VisitStmt(Stmt *S); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 390 | Stmt *VisitGCCAsmStmt(GCCAsmStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 391 | Stmt *VisitDeclStmt(DeclStmt *S); |
| 392 | Stmt *VisitNullStmt(NullStmt *S); |
| 393 | Stmt *VisitCompoundStmt(CompoundStmt *S); |
| 394 | Stmt *VisitCaseStmt(CaseStmt *S); |
| 395 | Stmt *VisitDefaultStmt(DefaultStmt *S); |
| 396 | Stmt *VisitLabelStmt(LabelStmt *S); |
| 397 | Stmt *VisitAttributedStmt(AttributedStmt *S); |
| 398 | Stmt *VisitIfStmt(IfStmt *S); |
| 399 | Stmt *VisitSwitchStmt(SwitchStmt *S); |
| 400 | Stmt *VisitWhileStmt(WhileStmt *S); |
| 401 | Stmt *VisitDoStmt(DoStmt *S); |
| 402 | Stmt *VisitForStmt(ForStmt *S); |
| 403 | Stmt *VisitGotoStmt(GotoStmt *S); |
| 404 | Stmt *VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 405 | Stmt *VisitContinueStmt(ContinueStmt *S); |
| 406 | Stmt *VisitBreakStmt(BreakStmt *S); |
| 407 | Stmt *VisitReturnStmt(ReturnStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 408 | // FIXME: MSAsmStmt |
| 409 | // FIXME: SEHExceptStmt |
| 410 | // FIXME: SEHFinallyStmt |
| 411 | // FIXME: SEHTryStmt |
| 412 | // FIXME: SEHLeaveStmt |
| 413 | // FIXME: CapturedStmt |
| 414 | Stmt *VisitCXXCatchStmt(CXXCatchStmt *S); |
| 415 | Stmt *VisitCXXTryStmt(CXXTryStmt *S); |
| 416 | Stmt *VisitCXXForRangeStmt(CXXForRangeStmt *S); |
| 417 | // FIXME: MSDependentExistsStmt |
| 418 | Stmt *VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); |
| 419 | Stmt *VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); |
| 420 | Stmt *VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); |
| 421 | Stmt *VisitObjCAtTryStmt(ObjCAtTryStmt *S); |
| 422 | Stmt *VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); |
| 423 | Stmt *VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); |
| 424 | Stmt *VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 425 | |
| 426 | // Importing expressions |
| 427 | Expr *VisitExpr(Expr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 428 | Expr *VisitVAArgExpr(VAArgExpr *E); |
| 429 | Expr *VisitGNUNullExpr(GNUNullExpr *E); |
| 430 | Expr *VisitPredefinedExpr(PredefinedExpr *E); |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 431 | Expr *VisitDeclRefExpr(DeclRefExpr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 432 | Expr *VisitImplicitValueInitExpr(ImplicitValueInitExpr *ILE); |
| 433 | Expr *VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 434 | Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 435 | Expr *VisitIntegerLiteral(IntegerLiteral *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 436 | Expr *VisitFloatingLiteral(FloatingLiteral *E); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 437 | Expr *VisitImaginaryLiteral(ImaginaryLiteral *E); |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 438 | Expr *VisitCharacterLiteral(CharacterLiteral *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 439 | Expr *VisitStringLiteral(StringLiteral *E); |
| 440 | Expr *VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 441 | Expr *VisitAtomicExpr(AtomicExpr *E); |
| 442 | Expr *VisitAddrLabelExpr(AddrLabelExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 443 | Expr *VisitParenExpr(ParenExpr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 444 | Expr *VisitParenListExpr(ParenListExpr *E); |
| 445 | Expr *VisitStmtExpr(StmtExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 446 | Expr *VisitUnaryOperator(UnaryOperator *E); |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 447 | Expr *VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 448 | Expr *VisitBinaryOperator(BinaryOperator *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 449 | Expr *VisitConditionalOperator(ConditionalOperator *E); |
| 450 | Expr *VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 451 | Expr *VisitOpaqueValueExpr(OpaqueValueExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 452 | Expr *VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 453 | Expr *VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 454 | Expr *VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 455 | Expr *VisitCompoundAssignOperator(CompoundAssignOperator *E); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 456 | Expr *VisitImplicitCastExpr(ImplicitCastExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 457 | Expr *VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 458 | Expr *VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 459 | Expr *VisitCXXThrowExpr(CXXThrowExpr *E); |
| 460 | Expr *VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 461 | Expr *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 462 | Expr *VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 463 | Expr *VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 464 | Expr *VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE); |
| 465 | Expr *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 466 | Expr *VisitPackExpansionExpr(PackExpansionExpr *E); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 467 | Expr *VisitSizeOfPackExpr(SizeOfPackExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 468 | Expr *VisitCXXNewExpr(CXXNewExpr *CE); |
| 469 | Expr *VisitCXXDeleteExpr(CXXDeleteExpr *E); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 470 | Expr *VisitCXXConstructExpr(CXXConstructExpr *E); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 471 | Expr *VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 472 | Expr *VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 473 | Expr *VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 474 | Expr *VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *CE); |
| 475 | Expr *VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 476 | Expr *VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 477 | Expr *VisitExprWithCleanups(ExprWithCleanups *EWC); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 478 | Expr *VisitCXXThisExpr(CXXThisExpr *E); |
| 479 | Expr *VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 480 | Expr *VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 481 | Expr *VisitMemberExpr(MemberExpr *E); |
| 482 | Expr *VisitCallExpr(CallExpr *E); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 483 | Expr *VisitLambdaExpr(LambdaExpr *LE); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 484 | Expr *VisitInitListExpr(InitListExpr *E); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 485 | Expr *VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 486 | Expr *VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 487 | Expr *VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 488 | Expr *VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 489 | Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 490 | Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 491 | Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 492 | Expr *VisitTypeTraitExpr(TypeTraitExpr *E); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 493 | Expr *VisitCXXTypeidExpr(CXXTypeidExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 494 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 495 | template<typename IIter, typename OIter> |
| 496 | void ImportArray(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 497 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; |
| 498 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 499 | ASTImporter &ImporterRef = Importer; |
| 500 | std::transform(Ibegin, Iend, Obegin, |
| 501 | [&ImporterRef](ItemT From) -> ItemT { |
| 502 | return ImporterRef.Import(From); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 503 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | template<typename IIter, typename OIter> |
| 507 | bool ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 508 | using ItemT = typename std::remove_reference<decltype(**Obegin)>::type; |
| 509 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 510 | ASTImporter &ImporterRef = Importer; |
| 511 | bool Failed = false; |
| 512 | std::transform(Ibegin, Iend, Obegin, |
| 513 | [&ImporterRef, &Failed](ItemT *From) -> ItemT * { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 514 | auto *To = cast_or_null<ItemT>(ImporterRef.Import(From)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 515 | if (!To && From) |
| 516 | Failed = true; |
| 517 | return To; |
| 518 | }); |
| 519 | return Failed; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 520 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 521 | |
| 522 | template<typename InContainerTy, typename OutContainerTy> |
| 523 | bool ImportContainerChecked(const InContainerTy &InContainer, |
| 524 | OutContainerTy &OutContainer) { |
| 525 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), |
| 526 | OutContainer.begin()); |
| 527 | } |
| 528 | |
| 529 | template<typename InContainerTy, typename OIter> |
| 530 | bool ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
| 531 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 532 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 533 | |
| 534 | // Importing overrides. |
| 535 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 536 | |
| 537 | FunctionDecl *FindFunctionTemplateSpecialization(FunctionDecl *FromFD); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 538 | }; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 539 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 540 | template <typename InContainerTy> |
| 541 | bool ASTNodeImporter::ImportTemplateArgumentListInfo( |
| 542 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 543 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { |
| 544 | TemplateArgumentListInfo ToTAInfo(Importer.Import(FromLAngleLoc), |
| 545 | Importer.Import(FromRAngleLoc)); |
| 546 | if (ImportTemplateArgumentListInfo(Container, ToTAInfo)) |
| 547 | return true; |
| 548 | Result = ToTAInfo; |
| 549 | return false; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 550 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 551 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 552 | template <> |
| 553 | bool ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( |
| 554 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { |
| 555 | return ImportTemplateArgumentListInfo( |
| 556 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); |
| 557 | } |
| 558 | |
| 559 | template <> |
| 560 | bool ASTNodeImporter::ImportTemplateArgumentListInfo< |
| 561 | ASTTemplateArgumentListInfo>(const ASTTemplateArgumentListInfo &From, |
| 562 | TemplateArgumentListInfo &Result) { |
| 563 | return ImportTemplateArgumentListInfo(From.LAngleLoc, From.RAngleLoc, |
| 564 | From.arguments(), Result); |
| 565 | } |
| 566 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 567 | std::tuple<FunctionTemplateDecl *, ASTNodeImporter::OptionalTemplateArgsTy> |
| 568 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 569 | FunctionDecl *FromFD) { |
| 570 | assert(FromFD->getTemplatedKind() == |
| 571 | FunctionDecl::TK_FunctionTemplateSpecialization); |
| 572 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
| 573 | auto *Template = cast_or_null<FunctionTemplateDecl>( |
| 574 | Importer.Import(FTSInfo->getTemplate())); |
| 575 | |
| 576 | // Import template arguments. |
| 577 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); |
| 578 | TemplateArgsTy ToTemplArgs; |
| 579 | if (ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), |
| 580 | ToTemplArgs)) // Error during import. |
| 581 | return std::make_tuple(Template, OptionalTemplateArgsTy()); |
| 582 | |
| 583 | return std::make_tuple(Template, ToTemplArgs); |
| 584 | } |
| 585 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 586 | } // namespace clang |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 587 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 588 | //---------------------------------------------------------------------------- |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 589 | // Import Types |
| 590 | //---------------------------------------------------------------------------- |
| 591 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 592 | using namespace clang; |
| 593 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 594 | QualType ASTNodeImporter::VisitType(const Type *T) { |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 595 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 596 | << T->getTypeClassName(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 597 | return {}; |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 598 | } |
| 599 | |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 600 | QualType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 601 | QualType UnderlyingType = Importer.Import(T->getValueType()); |
| 602 | if(UnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 603 | return {}; |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 604 | |
| 605 | return Importer.getToContext().getAtomicType(UnderlyingType); |
| 606 | } |
| 607 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 608 | QualType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 609 | switch (T->getKind()) { |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 610 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 611 | case BuiltinType::Id: \ |
| 612 | return Importer.getToContext().SingletonId; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 613 | #include "clang/Basic/OpenCLImageTypes.def" |
John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 614 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 615 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 616 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 617 | #include "clang/AST/BuiltinTypes.def" |
| 618 | |
| 619 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 620 | // context supports C++. |
| 621 | |
| 622 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 623 | // context supports ObjC. |
| 624 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 625 | case BuiltinType::Char_U: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 626 | // The context we're importing from has an unsigned 'char'. If we're |
| 627 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 628 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 629 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 630 | return Importer.getToContext().UnsignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 631 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 632 | return Importer.getToContext().CharTy; |
| 633 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 634 | case BuiltinType::Char_S: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 635 | // The context we're importing from has an unsigned 'char'. If we're |
| 636 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 637 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 638 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 639 | return Importer.getToContext().SignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 640 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 641 | return Importer.getToContext().CharTy; |
| 642 | |
Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 643 | case BuiltinType::WChar_S: |
| 644 | case BuiltinType::WChar_U: |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 645 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 646 | // wchar_t? |
| 647 | return Importer.getToContext().WCharTy; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 648 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 649 | |
| 650 | llvm_unreachable("Invalid BuiltinType Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 651 | } |
| 652 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 653 | QualType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 654 | QualType OrigT = Importer.Import(T->getOriginalType()); |
| 655 | if (OrigT.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 656 | return {}; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 657 | |
| 658 | return Importer.getToContext().getDecayedType(OrigT); |
| 659 | } |
| 660 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 661 | QualType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 662 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 663 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 664 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 665 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 666 | return Importer.getToContext().getComplexType(ToElementType); |
| 667 | } |
| 668 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 669 | QualType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 670 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 671 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 672 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 673 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 674 | return Importer.getToContext().getPointerType(ToPointeeType); |
| 675 | } |
| 676 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 677 | QualType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 678 | // FIXME: Check for blocks support in "to" context. |
| 679 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 680 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 681 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 682 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 683 | return Importer.getToContext().getBlockPointerType(ToPointeeType); |
| 684 | } |
| 685 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 686 | QualType |
| 687 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 688 | // FIXME: Check for C++ support in "to" context. |
| 689 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 690 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 691 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 692 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 693 | return Importer.getToContext().getLValueReferenceType(ToPointeeType); |
| 694 | } |
| 695 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 696 | QualType |
| 697 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 698 | // FIXME: Check for C++0x support in "to" context. |
| 699 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 700 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 701 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 702 | |
| 703 | return Importer.getToContext().getRValueReferenceType(ToPointeeType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 704 | } |
| 705 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 706 | QualType ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 707 | // FIXME: Check for C++ support in "to" context. |
| 708 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 709 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 710 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 711 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 712 | QualType ClassType = Importer.Import(QualType(T->getClass(), 0)); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 713 | return Importer.getToContext().getMemberPointerType(ToPointeeType, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 714 | ClassType.getTypePtr()); |
| 715 | } |
| 716 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 717 | QualType ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 718 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 719 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 720 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 721 | |
| 722 | return Importer.getToContext().getConstantArrayType(ToElementType, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 723 | T->getSize(), |
| 724 | T->getSizeModifier(), |
| 725 | T->getIndexTypeCVRQualifiers()); |
| 726 | } |
| 727 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 728 | QualType |
| 729 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 730 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 731 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 732 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 733 | |
| 734 | return Importer.getToContext().getIncompleteArrayType(ToElementType, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 735 | T->getSizeModifier(), |
| 736 | T->getIndexTypeCVRQualifiers()); |
| 737 | } |
| 738 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 739 | QualType ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 740 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 741 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 742 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 743 | |
| 744 | Expr *Size = Importer.Import(T->getSizeExpr()); |
| 745 | if (!Size) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 746 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 747 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 748 | SourceRange Brackets = Importer.Import(T->getBracketsRange()); |
| 749 | return Importer.getToContext().getVariableArrayType(ToElementType, Size, |
| 750 | T->getSizeModifier(), |
| 751 | T->getIndexTypeCVRQualifiers(), |
| 752 | Brackets); |
| 753 | } |
| 754 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 755 | QualType ASTNodeImporter::VisitDependentSizedArrayType( |
| 756 | const DependentSizedArrayType *T) { |
| 757 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 758 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 759 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 760 | |
| 761 | // SizeExpr may be null if size is not specified directly. |
| 762 | // For example, 'int a[]'. |
| 763 | Expr *Size = Importer.Import(T->getSizeExpr()); |
| 764 | if (!Size && T->getSizeExpr()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 765 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 766 | |
| 767 | SourceRange Brackets = Importer.Import(T->getBracketsRange()); |
| 768 | return Importer.getToContext().getDependentSizedArrayType( |
| 769 | ToElementType, Size, T->getSizeModifier(), T->getIndexTypeCVRQualifiers(), |
| 770 | Brackets); |
| 771 | } |
| 772 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 773 | QualType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 774 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 775 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 776 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 777 | |
| 778 | return Importer.getToContext().getVectorType(ToElementType, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 779 | T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 780 | T->getVectorKind()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 781 | } |
| 782 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 783 | QualType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 784 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 785 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 786 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 787 | |
| 788 | return Importer.getToContext().getExtVectorType(ToElementType, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 789 | T->getNumElements()); |
| 790 | } |
| 791 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 792 | QualType |
| 793 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 794 | // FIXME: What happens if we're importing a function without a prototype |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 795 | // into C++? Should we make it variadic? |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 796 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 797 | if (ToResultType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 798 | return {}; |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 799 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 800 | return Importer.getToContext().getFunctionNoProtoType(ToResultType, |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 801 | T->getExtInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 802 | } |
| 803 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 804 | QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 805 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 806 | if (ToResultType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 807 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 808 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 809 | // Import argument types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 810 | SmallVector<QualType, 4> ArgTypes; |
Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 811 | for (const auto &A : T->param_types()) { |
| 812 | QualType ArgType = Importer.Import(A); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 813 | if (ArgType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 814 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 815 | ArgTypes.push_back(ArgType); |
| 816 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 817 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 818 | // Import exception types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 819 | SmallVector<QualType, 4> ExceptionTypes; |
Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 820 | for (const auto &E : T->exceptions()) { |
| 821 | QualType ExceptionType = Importer.Import(E); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 822 | if (ExceptionType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 823 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 824 | ExceptionTypes.push_back(ExceptionType); |
| 825 | } |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 826 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 827 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 828 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 829 | |
| 830 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 831 | ToEPI.Variadic = FromEPI.Variadic; |
| 832 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 833 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 834 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 835 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 836 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
| 837 | ToEPI.ExceptionSpec.NoexceptExpr = |
| 838 | Importer.Import(FromEPI.ExceptionSpec.NoexceptExpr); |
| 839 | ToEPI.ExceptionSpec.SourceDecl = cast_or_null<FunctionDecl>( |
| 840 | Importer.Import(FromEPI.ExceptionSpec.SourceDecl)); |
| 841 | ToEPI.ExceptionSpec.SourceTemplate = cast_or_null<FunctionDecl>( |
| 842 | Importer.Import(FromEPI.ExceptionSpec.SourceTemplate)); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 843 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 844 | return Importer.getToContext().getFunctionType(ToResultType, ArgTypes, ToEPI); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 845 | } |
| 846 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 847 | QualType ASTNodeImporter::VisitUnresolvedUsingType( |
| 848 | const UnresolvedUsingType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 849 | const auto *ToD = |
| 850 | cast_or_null<UnresolvedUsingTypenameDecl>(Importer.Import(T->getDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 851 | if (!ToD) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 852 | return {}; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 853 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 854 | auto *ToPrevD = |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 855 | cast_or_null<UnresolvedUsingTypenameDecl>( |
| 856 | Importer.Import(T->getDecl()->getPreviousDecl())); |
| 857 | if (!ToPrevD && T->getDecl()->getPreviousDecl()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 858 | return {}; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 859 | |
| 860 | return Importer.getToContext().getTypeDeclType(ToD, ToPrevD); |
| 861 | } |
| 862 | |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 863 | QualType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 864 | QualType ToInnerType = Importer.Import(T->getInnerType()); |
| 865 | if (ToInnerType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 866 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 867 | |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 868 | return Importer.getToContext().getParenType(ToInnerType); |
| 869 | } |
| 870 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 871 | QualType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 872 | auto *ToDecl = |
| 873 | dyn_cast_or_null<TypedefNameDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 874 | if (!ToDecl) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 875 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 876 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 877 | return Importer.getToContext().getTypeDeclType(ToDecl); |
| 878 | } |
| 879 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 880 | QualType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 881 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 882 | if (!ToExpr) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 883 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 884 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 885 | return Importer.getToContext().getTypeOfExprType(ToExpr); |
| 886 | } |
| 887 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 888 | QualType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 889 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 890 | if (ToUnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 891 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 892 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 893 | return Importer.getToContext().getTypeOfType(ToUnderlyingType); |
| 894 | } |
| 895 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 896 | QualType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 897 | // FIXME: Make sure that the "to" context supports C++0x! |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 898 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 899 | if (!ToExpr) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 900 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 901 | |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 902 | QualType UnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 903 | if (UnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 904 | return {}; |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 905 | |
| 906 | return Importer.getToContext().getDecltypeType(ToExpr, UnderlyingType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 907 | } |
| 908 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 909 | QualType ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 910 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 911 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 912 | if (ToBaseType.isNull() || ToUnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 913 | return {}; |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 914 | |
| 915 | return Importer.getToContext().getUnaryTransformType(ToBaseType, |
| 916 | ToUnderlyingType, |
| 917 | T->getUTTKind()); |
| 918 | } |
| 919 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 920 | QualType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 921 | // FIXME: Make sure that the "to" context supports C++11! |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 922 | QualType FromDeduced = T->getDeducedType(); |
| 923 | QualType ToDeduced; |
| 924 | if (!FromDeduced.isNull()) { |
| 925 | ToDeduced = Importer.Import(FromDeduced); |
| 926 | if (ToDeduced.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 927 | return {}; |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 928 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 929 | |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 930 | return Importer.getToContext().getAutoType(ToDeduced, T->getKeyword(), |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 931 | /*IsDependent*/false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 932 | } |
| 933 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 934 | QualType ASTNodeImporter::VisitInjectedClassNameType( |
| 935 | const InjectedClassNameType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 936 | auto *D = cast_or_null<CXXRecordDecl>(Importer.Import(T->getDecl())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 937 | if (!D) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 938 | return {}; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 939 | |
| 940 | QualType InjType = Importer.Import(T->getInjectedSpecializationType()); |
| 941 | if (InjType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 942 | return {}; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 943 | |
| 944 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 945 | // See comments in InjectedClassNameType definition for details |
| 946 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 947 | enum { |
| 948 | TypeAlignmentInBits = 4, |
| 949 | TypeAlignment = 1 << TypeAlignmentInBits |
| 950 | }; |
| 951 | |
| 952 | return QualType(new (Importer.getToContext(), TypeAlignment) |
| 953 | InjectedClassNameType(D, InjType), 0); |
| 954 | } |
| 955 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 956 | QualType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 957 | auto *ToDecl = dyn_cast_or_null<RecordDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 958 | if (!ToDecl) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 959 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 960 | |
| 961 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 962 | } |
| 963 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 964 | QualType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 965 | auto *ToDecl = dyn_cast_or_null<EnumDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 966 | if (!ToDecl) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 967 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 968 | |
| 969 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 970 | } |
| 971 | |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 972 | QualType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 973 | QualType FromModifiedType = T->getModifiedType(); |
| 974 | QualType FromEquivalentType = T->getEquivalentType(); |
| 975 | QualType ToModifiedType; |
| 976 | QualType ToEquivalentType; |
| 977 | |
| 978 | if (!FromModifiedType.isNull()) { |
| 979 | ToModifiedType = Importer.Import(FromModifiedType); |
| 980 | if (ToModifiedType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 981 | return {}; |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 982 | } |
| 983 | if (!FromEquivalentType.isNull()) { |
| 984 | ToEquivalentType = Importer.Import(FromEquivalentType); |
| 985 | if (ToEquivalentType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 986 | return {}; |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
| 990 | ToModifiedType, ToEquivalentType); |
| 991 | } |
| 992 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 993 | QualType ASTNodeImporter::VisitTemplateTypeParmType( |
| 994 | const TemplateTypeParmType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 995 | auto *ParmDecl = |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 996 | cast_or_null<TemplateTypeParmDecl>(Importer.Import(T->getDecl())); |
| 997 | if (!ParmDecl && T->getDecl()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 998 | return {}; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 999 | |
| 1000 | return Importer.getToContext().getTemplateTypeParmType( |
| 1001 | T->getDepth(), T->getIndex(), T->isParameterPack(), ParmDecl); |
| 1002 | } |
| 1003 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1004 | QualType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
| 1005 | const SubstTemplateTypeParmType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1006 | const auto *Replaced = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1007 | cast_or_null<TemplateTypeParmType>(Importer.Import( |
| 1008 | QualType(T->getReplacedParameter(), 0)).getTypePtr()); |
| 1009 | if (!Replaced) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1010 | return {}; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1011 | |
| 1012 | QualType Replacement = Importer.Import(T->getReplacementType()); |
| 1013 | if (Replacement.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1014 | return {}; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1015 | Replacement = Replacement.getCanonicalType(); |
| 1016 | |
| 1017 | return Importer.getToContext().getSubstTemplateTypeParmType( |
| 1018 | Replaced, Replacement); |
| 1019 | } |
| 1020 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1021 | QualType ASTNodeImporter::VisitTemplateSpecializationType( |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1022 | const TemplateSpecializationType *T) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1023 | TemplateName ToTemplate = Importer.Import(T->getTemplateName()); |
| 1024 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1025 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1026 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1027 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1028 | if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1029 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1030 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1031 | QualType ToCanonType; |
| 1032 | if (!QualType(T, 0).isCanonical()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1033 | QualType FromCanonType |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1034 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
| 1035 | ToCanonType =Importer.Import(FromCanonType); |
| 1036 | if (ToCanonType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1037 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1038 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1039 | return Importer.getToContext().getTemplateSpecializationType(ToTemplate, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 1040 | ToTemplateArgs, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1041 | ToCanonType); |
| 1042 | } |
| 1043 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1044 | QualType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1045 | NestedNameSpecifier *ToQualifier = nullptr; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1046 | // Note: the qualifier in an ElaboratedType is optional. |
| 1047 | if (T->getQualifier()) { |
| 1048 | ToQualifier = Importer.Import(T->getQualifier()); |
| 1049 | if (!ToQualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1050 | return {}; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1051 | } |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1052 | |
| 1053 | QualType ToNamedType = Importer.Import(T->getNamedType()); |
| 1054 | if (ToNamedType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1055 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1056 | |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1057 | TagDecl *OwnedTagDecl = |
| 1058 | cast_or_null<TagDecl>(Importer.Import(T->getOwnedTagDecl())); |
| 1059 | if (!OwnedTagDecl && T->getOwnedTagDecl()) |
| 1060 | return {}; |
| 1061 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1062 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1063 | ToQualifier, ToNamedType, |
| 1064 | OwnedTagDecl); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1067 | QualType ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 1068 | QualType Pattern = Importer.Import(T->getPattern()); |
| 1069 | if (Pattern.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1070 | return {}; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1071 | |
| 1072 | return Importer.getToContext().getPackExpansionType(Pattern, |
| 1073 | T->getNumExpansions()); |
| 1074 | } |
| 1075 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1076 | QualType ASTNodeImporter::VisitDependentTemplateSpecializationType( |
| 1077 | const DependentTemplateSpecializationType *T) { |
| 1078 | NestedNameSpecifier *Qualifier = Importer.Import(T->getQualifier()); |
| 1079 | if (!Qualifier && T->getQualifier()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1080 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1081 | |
| 1082 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
| 1083 | if (!Name && T->getIdentifier()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1084 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1085 | |
| 1086 | SmallVector<TemplateArgument, 2> ToPack; |
| 1087 | ToPack.reserve(T->getNumArgs()); |
| 1088 | if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToPack)) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1089 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1090 | |
| 1091 | return Importer.getToContext().getDependentTemplateSpecializationType( |
| 1092 | T->getKeyword(), Qualifier, Name, ToPack); |
| 1093 | } |
| 1094 | |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1095 | QualType ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { |
| 1096 | NestedNameSpecifier *NNS = Importer.Import(T->getQualifier()); |
| 1097 | if (!NNS && T->getQualifier()) |
| 1098 | return QualType(); |
| 1099 | |
| 1100 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
| 1101 | if (!Name && T->getIdentifier()) |
| 1102 | return QualType(); |
| 1103 | |
| 1104 | QualType Canon = (T == T->getCanonicalTypeInternal().getTypePtr()) |
| 1105 | ? QualType() |
| 1106 | : Importer.Import(T->getCanonicalTypeInternal()); |
| 1107 | if (!Canon.isNull()) |
| 1108 | Canon = Canon.getCanonicalType(); |
| 1109 | |
| 1110 | return Importer.getToContext().getDependentNameType(T->getKeyword(), NNS, |
| 1111 | Name, Canon); |
| 1112 | } |
| 1113 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1114 | QualType ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1115 | auto *Class = |
| 1116 | dyn_cast_or_null<ObjCInterfaceDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1117 | if (!Class) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1118 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1119 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1120 | return Importer.getToContext().getObjCInterfaceType(Class); |
| 1121 | } |
| 1122 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1123 | QualType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1124 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 1125 | if (ToBaseType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1126 | return {}; |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1127 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1128 | SmallVector<QualType, 4> TypeArgs; |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 1129 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1130 | QualType ImportedTypeArg = Importer.Import(TypeArg); |
| 1131 | if (ImportedTypeArg.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1132 | return {}; |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1133 | |
| 1134 | TypeArgs.push_back(ImportedTypeArg); |
| 1135 | } |
| 1136 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1137 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 1138 | for (auto *P : T->quals()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1139 | auto *Protocol = dyn_cast_or_null<ObjCProtocolDecl>(Importer.Import(P)); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1140 | if (!Protocol) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1141 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1142 | Protocols.push_back(Protocol); |
| 1143 | } |
| 1144 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1145 | return Importer.getToContext().getObjCObjectType(ToBaseType, TypeArgs, |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 1146 | Protocols, |
| 1147 | T->isKindOfTypeAsWritten()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1150 | QualType |
| 1151 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1152 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 1153 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1154 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1155 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1156 | return Importer.getToContext().getObjCObjectPointerType(ToPointeeType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1159 | //---------------------------------------------------------------------------- |
| 1160 | // Import Declarations |
| 1161 | //---------------------------------------------------------------------------- |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1162 | bool ASTNodeImporter::ImportDeclParts(NamedDecl *D, DeclContext *&DC, |
| 1163 | DeclContext *&LexicalDC, |
| 1164 | DeclarationName &Name, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1165 | NamedDecl *&ToD, |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1166 | SourceLocation &Loc) { |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1167 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. |
| 1168 | // example: int struct_in_proto(struct data_t{int a;int b;} *d); |
| 1169 | DeclContext *OrigDC = D->getDeclContext(); |
| 1170 | FunctionDecl *FunDecl; |
| 1171 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && |
| 1172 | FunDecl->hasBody()) { |
Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1173 | auto getLeafPointeeType = [](const Type *T) { |
| 1174 | while (T->isPointerType() || T->isArrayType()) { |
| 1175 | T = T->getPointeeOrArrayElementType(); |
| 1176 | } |
| 1177 | return T; |
| 1178 | }; |
| 1179 | for (const ParmVarDecl *P : FunDecl->parameters()) { |
| 1180 | const Type *LeafT = |
| 1181 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); |
| 1182 | auto *RT = dyn_cast<RecordType>(LeafT); |
| 1183 | if (RT && RT->getDecl() == D) { |
| 1184 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 1185 | << D->getDeclKindName(); |
| 1186 | return true; |
| 1187 | } |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1188 | } |
| 1189 | } |
| 1190 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1191 | // Import the context of this declaration. |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1192 | DC = Importer.ImportContext(OrigDC); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1193 | if (!DC) |
| 1194 | return true; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1195 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1196 | LexicalDC = DC; |
| 1197 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 1198 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 1199 | if (!LexicalDC) |
| 1200 | return true; |
| 1201 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1202 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1203 | // Import the name of this declaration. |
| 1204 | Name = Importer.Import(D->getDeclName()); |
| 1205 | if (D->getDeclName() && !Name) |
| 1206 | return true; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1207 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1208 | // Import the location of this declaration. |
| 1209 | Loc = Importer.Import(D->getLocation()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1210 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1211 | return false; |
| 1212 | } |
| 1213 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1214 | void ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
| 1215 | if (!FromD) |
| 1216 | return; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1217 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1218 | if (!ToD) { |
| 1219 | ToD = Importer.Import(FromD); |
| 1220 | if (!ToD) |
| 1221 | return; |
| 1222 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1223 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1224 | if (auto *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 1225 | if (auto *ToRecord = cast_or_null<RecordDecl>(ToD)) { |
Sean Callanan | 19dfc93 | 2013-01-11 23:17:47 +0000 | [diff] [blame] | 1226 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && !ToRecord->getDefinition()) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1227 | ImportDefinition(FromRecord, ToRecord); |
| 1228 | } |
| 1229 | } |
| 1230 | return; |
| 1231 | } |
| 1232 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1233 | if (auto *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 1234 | if (auto *ToEnum = cast_or_null<EnumDecl>(ToD)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1235 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
| 1236 | ImportDefinition(FromEnum, ToEnum); |
| 1237 | } |
| 1238 | } |
| 1239 | return; |
| 1240 | } |
| 1241 | } |
| 1242 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1243 | void |
| 1244 | ASTNodeImporter::ImportDeclarationNameLoc(const DeclarationNameInfo &From, |
| 1245 | DeclarationNameInfo& To) { |
| 1246 | // NOTE: To.Name and To.Loc are already imported. |
| 1247 | // We only have to import To.LocInfo. |
| 1248 | switch (To.getName().getNameKind()) { |
| 1249 | case DeclarationName::Identifier: |
| 1250 | case DeclarationName::ObjCZeroArgSelector: |
| 1251 | case DeclarationName::ObjCOneArgSelector: |
| 1252 | case DeclarationName::ObjCMultiArgSelector: |
| 1253 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1254 | case DeclarationName::CXXDeductionGuideName: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1255 | return; |
| 1256 | |
| 1257 | case DeclarationName::CXXOperatorName: { |
| 1258 | SourceRange Range = From.getCXXOperatorNameRange(); |
| 1259 | To.setCXXOperatorNameRange(Importer.Import(Range)); |
| 1260 | return; |
| 1261 | } |
| 1262 | case DeclarationName::CXXLiteralOperatorName: { |
| 1263 | SourceLocation Loc = From.getCXXLiteralOperatorNameLoc(); |
| 1264 | To.setCXXLiteralOperatorNameLoc(Importer.Import(Loc)); |
| 1265 | return; |
| 1266 | } |
| 1267 | case DeclarationName::CXXConstructorName: |
| 1268 | case DeclarationName::CXXDestructorName: |
| 1269 | case DeclarationName::CXXConversionFunctionName: { |
| 1270 | TypeSourceInfo *FromTInfo = From.getNamedTypeInfo(); |
| 1271 | To.setNamedTypeInfo(Importer.Import(FromTInfo)); |
| 1272 | return; |
| 1273 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1274 | } |
Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1275 | llvm_unreachable("Unknown name kind."); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1276 | } |
| 1277 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1278 | void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1279 | if (Importer.isMinimalImport() && !ForceImport) { |
Sean Callanan | 81d577c | 2011-07-22 23:46:03 +0000 | [diff] [blame] | 1280 | Importer.ImportContext(FromDC); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1281 | return; |
| 1282 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1283 | |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 1284 | for (auto *From : FromDC->decls()) |
| 1285 | Importer.Import(From); |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1288 | void ASTNodeImporter::ImportImplicitMethods( |
| 1289 | const CXXRecordDecl *From, CXXRecordDecl *To) { |
| 1290 | assert(From->isCompleteDefinition() && To->getDefinition() == To && |
| 1291 | "Import implicit methods to or from non-definition"); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1292 | |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1293 | for (CXXMethodDecl *FromM : From->methods()) |
| 1294 | if (FromM->isImplicit()) |
| 1295 | Importer.Import(FromM); |
| 1296 | } |
| 1297 | |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1298 | static void setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1299 | ASTImporter &Importer) { |
| 1300 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
| 1301 | auto *ToTypedef = |
| 1302 | cast_or_null<TypedefNameDecl>(Importer.Import(FromTypedef)); |
| 1303 | assert (ToTypedef && "Failed to import typedef of an anonymous structure"); |
| 1304 | |
| 1305 | To->setTypedefNameForAnonDecl(ToTypedef); |
| 1306 | } |
| 1307 | } |
| 1308 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1309 | bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1310 | ImportDefinitionKind Kind) { |
| 1311 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1312 | if (Kind == IDK_Everything) |
| 1313 | ImportDeclContext(From, /*ForceImport=*/true); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1314 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1315 | return false; |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1316 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1317 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1318 | To->startDefinition(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1319 | |
| 1320 | setTypedefNameForAnonDecl(From, To, Importer); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1321 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1322 | // Add base classes. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1323 | if (auto *ToCXX = dyn_cast<CXXRecordDecl>(To)) { |
| 1324 | auto *FromCXX = cast<CXXRecordDecl>(From); |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1325 | |
| 1326 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1327 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 1328 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1329 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1330 | ToData.Aggregate = FromData.Aggregate; |
| 1331 | ToData.PlainOldData = FromData.PlainOldData; |
| 1332 | ToData.Empty = FromData.Empty; |
| 1333 | ToData.Polymorphic = FromData.Polymorphic; |
| 1334 | ToData.Abstract = FromData.Abstract; |
| 1335 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 1336 | ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout; |
| 1337 | ToData.HasBasesWithFields = FromData.HasBasesWithFields; |
| 1338 | ToData.HasBasesWithNonStaticDataMembers = |
| 1339 | FromData.HasBasesWithNonStaticDataMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1340 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 1341 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 1342 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 1343 | ToData.HasMutableFields = FromData.HasMutableFields; |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 1344 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1345 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 1346 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 1347 | ToData.HasUninitializedReferenceMember |
| 1348 | = FromData.HasUninitializedReferenceMember; |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1349 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1350 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 1351 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1352 | ToData.NeedOverloadResolutionForCopyConstructor |
| 1353 | = FromData.NeedOverloadResolutionForCopyConstructor; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1354 | ToData.NeedOverloadResolutionForMoveConstructor |
| 1355 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 1356 | ToData.NeedOverloadResolutionForMoveAssignment |
| 1357 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 1358 | ToData.NeedOverloadResolutionForDestructor |
| 1359 | = FromData.NeedOverloadResolutionForDestructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1360 | ToData.DefaultedCopyConstructorIsDeleted |
| 1361 | = FromData.DefaultedCopyConstructorIsDeleted; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1362 | ToData.DefaultedMoveConstructorIsDeleted |
| 1363 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 1364 | ToData.DefaultedMoveAssignmentIsDeleted |
| 1365 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 1366 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1367 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 1368 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1369 | ToData.HasConstexprNonCopyMoveConstructor |
| 1370 | = FromData.HasConstexprNonCopyMoveConstructor; |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1371 | ToData.HasDefaultedDefaultConstructor |
| 1372 | = FromData.HasDefaultedDefaultConstructor; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1373 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 1374 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1375 | ToData.HasConstexprDefaultConstructor |
| 1376 | = FromData.HasConstexprDefaultConstructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1377 | ToData.HasNonLiteralTypeFieldsOrBases |
| 1378 | = FromData.HasNonLiteralTypeFieldsOrBases; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1379 | // ComputedVisibleConversions not imported. |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1380 | ToData.UserProvidedDefaultConstructor |
| 1381 | = FromData.UserProvidedDefaultConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1382 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1383 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 1384 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 1385 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 1386 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 1387 | ToData.ImplicitCopyAssignmentHasConstParam |
| 1388 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 1389 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 1390 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 1391 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 1392 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1393 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1394 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1395 | for (const auto &Base1 : FromCXX->bases()) { |
| 1396 | QualType T = Importer.Import(Base1.getType()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1397 | if (T.isNull()) |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1398 | return true; |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1399 | |
| 1400 | SourceLocation EllipsisLoc; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1401 | if (Base1.isPackExpansion()) |
| 1402 | EllipsisLoc = Importer.Import(Base1.getEllipsisLoc()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1403 | |
| 1404 | // Ensure that we have a definition for the base. |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1405 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1406 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1407 | Bases.push_back( |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1408 | new (Importer.getToContext()) |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1409 | CXXBaseSpecifier(Importer.Import(Base1.getSourceRange()), |
| 1410 | Base1.isVirtual(), |
| 1411 | Base1.isBaseOfClass(), |
| 1412 | Base1.getAccessSpecifierAsWritten(), |
| 1413 | Importer.Import(Base1.getTypeSourceInfo()), |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1414 | EllipsisLoc)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1415 | } |
| 1416 | if (!Bases.empty()) |
Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1417 | ToCXX->setBases(Bases.data(), Bases.size()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1418 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1419 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1420 | if (shouldForceImportDeclContext(Kind)) |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1421 | ImportDeclContext(From, /*ForceImport=*/true); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1422 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1423 | To->completeDefinition(); |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1424 | return false; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1425 | } |
| 1426 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1427 | bool ASTNodeImporter::ImportDefinition(VarDecl *From, VarDecl *To, |
| 1428 | ImportDefinitionKind Kind) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1429 | if (To->getAnyInitializer()) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1430 | return false; |
| 1431 | |
| 1432 | // FIXME: Can we really import any initializer? Alternatively, we could force |
| 1433 | // ourselves to import every declaration of a variable and then only use |
| 1434 | // getInit() here. |
| 1435 | To->setInit(Importer.Import(const_cast<Expr *>(From->getAnyInitializer()))); |
| 1436 | |
| 1437 | // FIXME: Other bits to merge? |
| 1438 | |
| 1439 | return false; |
| 1440 | } |
| 1441 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1442 | bool ASTNodeImporter::ImportDefinition(EnumDecl *From, EnumDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1443 | ImportDefinitionKind Kind) { |
| 1444 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1445 | if (Kind == IDK_Everything) |
| 1446 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1447 | return false; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1448 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1449 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1450 | To->startDefinition(); |
| 1451 | |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1452 | setTypedefNameForAnonDecl(From, To, Importer); |
| 1453 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1454 | QualType T = Importer.Import(Importer.getFromContext().getTypeDeclType(From)); |
| 1455 | if (T.isNull()) |
| 1456 | return true; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1457 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1458 | QualType ToPromotionType = Importer.Import(From->getPromotionType()); |
| 1459 | if (ToPromotionType.isNull()) |
| 1460 | return true; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1461 | |
| 1462 | if (shouldForceImportDeclContext(Kind)) |
| 1463 | ImportDeclContext(From, /*ForceImport=*/true); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1464 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1465 | // FIXME: we might need to merge the number of positive or negative bits |
| 1466 | // if the enumerator lists don't match. |
| 1467 | To->completeDefinition(T, ToPromotionType, |
| 1468 | From->getNumPositiveBits(), |
| 1469 | From->getNumNegativeBits()); |
| 1470 | return false; |
| 1471 | } |
| 1472 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1473 | TemplateParameterList *ASTNodeImporter::ImportTemplateParameterList( |
| 1474 | TemplateParameterList *Params) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1475 | SmallVector<NamedDecl *, 4> ToParams(Params->size()); |
| 1476 | if (ImportContainerChecked(*Params, ToParams)) |
| 1477 | return nullptr; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1478 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1479 | Expr *ToRequiresClause; |
| 1480 | if (Expr *const R = Params->getRequiresClause()) { |
| 1481 | ToRequiresClause = Importer.Import(R); |
| 1482 | if (!ToRequiresClause) |
| 1483 | return nullptr; |
| 1484 | } else { |
| 1485 | ToRequiresClause = nullptr; |
| 1486 | } |
| 1487 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1488 | return TemplateParameterList::Create(Importer.getToContext(), |
| 1489 | Importer.Import(Params->getTemplateLoc()), |
| 1490 | Importer.Import(Params->getLAngleLoc()), |
David Majnemer | 902f8c6 | 2015-12-27 07:16:27 +0000 | [diff] [blame] | 1491 | ToParams, |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1492 | Importer.Import(Params->getRAngleLoc()), |
| 1493 | ToRequiresClause); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1496 | TemplateArgument |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1497 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1498 | switch (From.getKind()) { |
| 1499 | case TemplateArgument::Null: |
| 1500 | return TemplateArgument(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1501 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1502 | case TemplateArgument::Type: { |
| 1503 | QualType ToType = Importer.Import(From.getAsType()); |
| 1504 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1505 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1506 | return TemplateArgument(ToType); |
| 1507 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1508 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1509 | case TemplateArgument::Integral: { |
| 1510 | QualType ToType = Importer.Import(From.getIntegralType()); |
| 1511 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1512 | return {}; |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 1513 | return TemplateArgument(From, ToType); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1514 | } |
| 1515 | |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1516 | case TemplateArgument::Declaration: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1517 | auto *To = cast_or_null<ValueDecl>(Importer.Import(From.getAsDecl())); |
David Blaikie | 3c7dd6b | 2014-10-22 19:54:16 +0000 | [diff] [blame] | 1518 | QualType ToType = Importer.Import(From.getParamTypeForDecl()); |
| 1519 | if (!To || ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1520 | return {}; |
David Blaikie | 3c7dd6b | 2014-10-22 19:54:16 +0000 | [diff] [blame] | 1521 | return TemplateArgument(To, ToType); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | case TemplateArgument::NullPtr: { |
| 1525 | QualType ToType = Importer.Import(From.getNullPtrType()); |
| 1526 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1527 | return {}; |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1528 | return TemplateArgument(ToType, /*isNullPtr*/true); |
| 1529 | } |
| 1530 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1531 | case TemplateArgument::Template: { |
| 1532 | TemplateName ToTemplate = Importer.Import(From.getAsTemplate()); |
| 1533 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1534 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1535 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1536 | return TemplateArgument(ToTemplate); |
| 1537 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1538 | |
| 1539 | case TemplateArgument::TemplateExpansion: { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1540 | TemplateName ToTemplate |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1541 | = Importer.Import(From.getAsTemplateOrTemplatePattern()); |
| 1542 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1543 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1544 | |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 1545 | return TemplateArgument(ToTemplate, From.getNumTemplateExpansions()); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1548 | case TemplateArgument::Expression: |
| 1549 | if (Expr *ToExpr = Importer.Import(From.getAsExpr())) |
| 1550 | return TemplateArgument(ToExpr); |
| 1551 | return TemplateArgument(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1552 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1553 | case TemplateArgument::Pack: { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1554 | SmallVector<TemplateArgument, 2> ToPack; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1555 | ToPack.reserve(From.pack_size()); |
| 1556 | if (ImportTemplateArguments(From.pack_begin(), From.pack_size(), ToPack)) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1557 | return {}; |
Benjamin Kramer | cce6347 | 2015-08-05 09:40:22 +0000 | [diff] [blame] | 1558 | |
| 1559 | return TemplateArgument( |
| 1560 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1561 | } |
| 1562 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1563 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1564 | llvm_unreachable("Invalid template argument kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1567 | Optional<TemplateArgumentLoc> |
| 1568 | ASTNodeImporter::ImportTemplateArgumentLoc(const TemplateArgumentLoc &TALoc) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1569 | TemplateArgument Arg = ImportTemplateArgument(TALoc.getArgument()); |
| 1570 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 1571 | TemplateArgumentLocInfo ToInfo; |
| 1572 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 1573 | Expr *E = Importer.Import(FromInfo.getAsExpr()); |
| 1574 | ToInfo = TemplateArgumentLocInfo(E); |
| 1575 | if (!E) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1576 | return None; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1577 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 1578 | if (TypeSourceInfo *TSI = Importer.Import(FromInfo.getAsTypeSourceInfo())) |
| 1579 | ToInfo = TemplateArgumentLocInfo(TSI); |
| 1580 | else |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1581 | return None; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1582 | } else { |
| 1583 | ToInfo = TemplateArgumentLocInfo( |
| 1584 | Importer.Import(FromInfo.getTemplateQualifierLoc()), |
| 1585 | Importer.Import(FromInfo.getTemplateNameLoc()), |
| 1586 | Importer.Import(FromInfo.getTemplateEllipsisLoc())); |
| 1587 | } |
| 1588 | return TemplateArgumentLoc(Arg, ToInfo); |
| 1589 | } |
| 1590 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1591 | bool ASTNodeImporter::ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 1592 | unsigned NumFromArgs, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1593 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1594 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
| 1595 | TemplateArgument To = ImportTemplateArgument(FromArgs[I]); |
| 1596 | if (To.isNull() && !FromArgs[I].isNull()) |
| 1597 | return true; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1598 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1599 | ToArgs.push_back(To); |
| 1600 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1601 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1602 | return false; |
| 1603 | } |
| 1604 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 1605 | // We cannot use Optional<> pattern here and below because |
| 1606 | // TemplateArgumentListInfo's operator new is declared as deleted so it cannot |
| 1607 | // be stored in Optional. |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1608 | template <typename InContainerTy> |
| 1609 | bool ASTNodeImporter::ImportTemplateArgumentListInfo( |
| 1610 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 1611 | for (const auto &FromLoc : Container) { |
| 1612 | if (auto ToLoc = ImportTemplateArgumentLoc(FromLoc)) |
| 1613 | ToTAInfo.addArgument(*ToLoc); |
| 1614 | else |
| 1615 | return true; |
| 1616 | } |
| 1617 | return false; |
| 1618 | } |
| 1619 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1620 | static StructuralEquivalenceKind |
| 1621 | getStructuralEquivalenceKind(const ASTImporter &Importer) { |
| 1622 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal |
| 1623 | : StructuralEquivalenceKind::Default; |
| 1624 | } |
| 1625 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1626 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { |
| 1627 | StructuralEquivalenceContext Ctx( |
| 1628 | Importer.getFromContext(), Importer.getToContext(), |
| 1629 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1630 | false, Complain); |
| 1631 | return Ctx.IsEquivalent(From, To); |
| 1632 | } |
| 1633 | |
| 1634 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1635 | RecordDecl *ToRecord, bool Complain) { |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1636 | // Eliminate a potential failure point where we attempt to re-import |
| 1637 | // something we're trying to import while completing ToRecord. |
| 1638 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 1639 | if (ToOrigin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1640 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1641 | if (ToOriginRecord) |
| 1642 | ToRecord = ToOriginRecord; |
| 1643 | } |
| 1644 | |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1645 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1646 | ToRecord->getASTContext(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1647 | Importer.getNonEquivalentDecls(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1648 | getStructuralEquivalenceKind(Importer), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1649 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1650 | return Ctx.IsEquivalent(FromRecord, ToRecord); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1651 | } |
| 1652 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1653 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 1654 | bool Complain) { |
| 1655 | StructuralEquivalenceContext Ctx( |
| 1656 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1657 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1658 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1659 | return Ctx.IsEquivalent(FromVar, ToVar); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1660 | } |
| 1661 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1662 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1663 | StructuralEquivalenceContext Ctx( |
| 1664 | Importer.getFromContext(), Importer.getToContext(), |
| 1665 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1666 | return Ctx.IsEquivalent(FromEnum, ToEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1667 | } |
| 1668 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1669 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 1670 | FunctionTemplateDecl *To) { |
| 1671 | StructuralEquivalenceContext Ctx( |
| 1672 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1673 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1674 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1675 | return Ctx.IsEquivalent(From, To); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1676 | } |
| 1677 | |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 1678 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { |
| 1679 | StructuralEquivalenceContext Ctx( |
| 1680 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1681 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1682 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1683 | return Ctx.IsEquivalent(From, To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1686 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1687 | EnumConstantDecl *ToEC) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1688 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 1689 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 1690 | |
| 1691 | return FromVal.isSigned() == ToVal.isSigned() && |
| 1692 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 1693 | FromVal == ToVal; |
| 1694 | } |
| 1695 | |
| 1696 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1697 | ClassTemplateDecl *To) { |
| 1698 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1699 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1700 | Importer.getNonEquivalentDecls(), |
| 1701 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1702 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1703 | } |
| 1704 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1705 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 1706 | VarTemplateDecl *To) { |
| 1707 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1708 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1709 | Importer.getNonEquivalentDecls(), |
| 1710 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1711 | return Ctx.IsEquivalent(From, To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1712 | } |
| 1713 | |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1714 | Decl *ASTNodeImporter::VisitDecl(Decl *D) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 1715 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1716 | << D->getDeclKindName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1717 | return nullptr; |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1718 | } |
| 1719 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1720 | Decl *ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 1721 | // Import the context of this declaration. |
| 1722 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1723 | if (!DC) |
| 1724 | return nullptr; |
| 1725 | |
| 1726 | DeclContext *LexicalDC = DC; |
| 1727 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 1728 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 1729 | if (!LexicalDC) |
| 1730 | return nullptr; |
| 1731 | } |
| 1732 | |
| 1733 | // Import the location of this declaration. |
| 1734 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1735 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1736 | EmptyDecl *ToD; |
| 1737 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc)) |
| 1738 | return ToD; |
| 1739 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1740 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1741 | LexicalDC->addDeclInternal(ToD); |
| 1742 | return ToD; |
| 1743 | } |
| 1744 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 1745 | Decl *ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1746 | TranslationUnitDecl *ToD = |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 1747 | Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1748 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1749 | Importer.MapImported(D, ToD); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1750 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 1751 | return ToD; |
| 1752 | } |
| 1753 | |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1754 | Decl *ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1755 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1756 | SourceLocation ColonLoc = Importer.Import(D->getColonLoc()); |
| 1757 | |
| 1758 | // Import the context of this declaration. |
| 1759 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1760 | if (!DC) |
| 1761 | return nullptr; |
| 1762 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1763 | AccessSpecDecl *ToD; |
| 1764 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), |
| 1765 | DC, Loc, ColonLoc)) |
| 1766 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1767 | |
| 1768 | // Lexical DeclContext and Semantic DeclContext |
| 1769 | // is always the same for the accessSpec. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1770 | ToD->setLexicalDeclContext(DC); |
| 1771 | DC->addDeclInternal(ToD); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1772 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1773 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1774 | } |
| 1775 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1776 | Decl *ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 1777 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1778 | if (!DC) |
| 1779 | return nullptr; |
| 1780 | |
| 1781 | DeclContext *LexicalDC = DC; |
| 1782 | |
| 1783 | // Import the location of this declaration. |
| 1784 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1785 | |
| 1786 | Expr *AssertExpr = Importer.Import(D->getAssertExpr()); |
| 1787 | if (!AssertExpr) |
| 1788 | return nullptr; |
| 1789 | |
| 1790 | StringLiteral *FromMsg = D->getMessage(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1791 | auto *ToMsg = cast_or_null<StringLiteral>(Importer.Import(FromMsg)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1792 | if (!ToMsg && FromMsg) |
| 1793 | return nullptr; |
| 1794 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1795 | StaticAssertDecl *ToD; |
| 1796 | if (GetImportedOrCreateDecl( |
| 1797 | ToD, D, Importer.getToContext(), DC, Loc, AssertExpr, ToMsg, |
| 1798 | Importer.Import(D->getRParenLoc()), D->isFailed())) |
| 1799 | return ToD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1800 | |
| 1801 | ToD->setLexicalDeclContext(LexicalDC); |
| 1802 | LexicalDC->addDeclInternal(ToD); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1803 | return ToD; |
| 1804 | } |
| 1805 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1806 | Decl *ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
| 1807 | // Import the major distinguishing characteristics of this namespace. |
| 1808 | DeclContext *DC, *LexicalDC; |
| 1809 | DeclarationName Name; |
| 1810 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1811 | NamedDecl *ToD; |
| 1812 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1813 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1814 | if (ToD) |
| 1815 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1816 | |
| 1817 | NamespaceDecl *MergeWithNamespace = nullptr; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1818 | if (!Name) { |
| 1819 | // This is an anonymous namespace. Adopt an existing anonymous |
| 1820 | // namespace if we can. |
| 1821 | // FIXME: Not testable. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1822 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1823 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 1824 | else |
| 1825 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 1826 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1827 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1828 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1829 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1830 | for (auto *FoundDecl : FoundDecls) { |
| 1831 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1832 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1833 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1834 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1835 | MergeWithNamespace = FoundNS; |
| 1836 | ConflictingDecls.clear(); |
| 1837 | break; |
| 1838 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1839 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1840 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1841 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1842 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1843 | if (!ConflictingDecls.empty()) { |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 1844 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1845 | ConflictingDecls.data(), |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1846 | ConflictingDecls.size()); |
| 1847 | } |
| 1848 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1849 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1850 | // Create the "to" namespace, if needed. |
| 1851 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 1852 | if (!ToNamespace) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1853 | if (GetImportedOrCreateDecl( |
| 1854 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 1855 | Importer.Import(D->getBeginLoc()), Loc, Name.getAsIdentifierInfo(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1856 | /*PrevDecl=*/nullptr)) |
| 1857 | return ToNamespace; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1858 | ToNamespace->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1859 | LexicalDC->addDeclInternal(ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1860 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1861 | // If this is an anonymous namespace, register it as the anonymous |
| 1862 | // namespace within its context. |
| 1863 | if (!Name) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1864 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1865 | TU->setAnonymousNamespace(ToNamespace); |
| 1866 | else |
| 1867 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 1868 | } |
| 1869 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1870 | Importer.MapImported(D, ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1871 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1872 | ImportDeclContext(D); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1873 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1874 | return ToNamespace; |
| 1875 | } |
| 1876 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1877 | Decl *ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| 1878 | // Import the major distinguishing characteristics of this namespace. |
| 1879 | DeclContext *DC, *LexicalDC; |
| 1880 | DeclarationName Name; |
| 1881 | SourceLocation Loc; |
| 1882 | NamedDecl *LookupD; |
| 1883 | if (ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 1884 | return nullptr; |
| 1885 | if (LookupD) |
| 1886 | return LookupD; |
| 1887 | |
| 1888 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 1889 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1890 | auto *TargetDecl = cast_or_null<NamespaceDecl>( |
| 1891 | Importer.Import(D->getNamespace())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1892 | if (!TargetDecl) |
| 1893 | return nullptr; |
| 1894 | |
| 1895 | IdentifierInfo *ToII = Importer.Import(D->getIdentifier()); |
| 1896 | if (!ToII) |
| 1897 | return nullptr; |
| 1898 | |
| 1899 | NestedNameSpecifierLoc ToQLoc = Importer.Import(D->getQualifierLoc()); |
| 1900 | if (D->getQualifierLoc() && !ToQLoc) |
| 1901 | return nullptr; |
| 1902 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1903 | NamespaceAliasDecl *ToD; |
| 1904 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, |
| 1905 | Importer.Import(D->getNamespaceLoc()), |
| 1906 | Importer.Import(D->getAliasLoc()), ToII, ToQLoc, |
| 1907 | Importer.Import(D->getTargetNameLoc()), |
| 1908 | TargetDecl)) |
| 1909 | return ToD; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1910 | |
| 1911 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1912 | LexicalDC->addDeclInternal(ToD); |
| 1913 | |
| 1914 | return ToD; |
| 1915 | } |
| 1916 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1917 | Decl *ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1918 | // Import the major distinguishing characteristics of this typedef. |
| 1919 | DeclContext *DC, *LexicalDC; |
| 1920 | DeclarationName Name; |
| 1921 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1922 | NamedDecl *ToD; |
| 1923 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1924 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1925 | if (ToD) |
| 1926 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1927 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1928 | // If this typedef is not in block scope, determine whether we've |
| 1929 | // seen a typedef with the same name (that we can merge with) or any |
| 1930 | // other entity by that name (which name lookup could conflict with). |
| 1931 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1932 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1933 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1934 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1935 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1936 | for (auto *FoundDecl : FoundDecls) { |
| 1937 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1938 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1939 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1940 | if (Importer.IsStructurallyEquivalent(D->getUnderlyingType(), |
| 1941 | FoundTypedef->getUnderlyingType())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1942 | return Importer.MapImported(D, FoundTypedef); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1943 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1944 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1945 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1946 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1947 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1948 | if (!ConflictingDecls.empty()) { |
| 1949 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1950 | ConflictingDecls.data(), |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1951 | ConflictingDecls.size()); |
| 1952 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1953 | return nullptr; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1954 | } |
| 1955 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1956 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1957 | // Import the underlying type of this typedef; |
| 1958 | QualType T = Importer.Import(D->getUnderlyingType()); |
| 1959 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1960 | return nullptr; |
| 1961 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1962 | // Create the new typedef node. |
| 1963 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 1964 | SourceLocation StartL = Importer.Import(D->getBeginLoc()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1965 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1966 | TypedefNameDecl *ToTypedef; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1967 | if (IsAlias) { |
| 1968 | if (GetImportedOrCreateDecl<TypeAliasDecl>( |
| 1969 | ToTypedef, D, Importer.getToContext(), DC, StartL, Loc, |
| 1970 | Name.getAsIdentifierInfo(), TInfo)) |
| 1971 | return ToTypedef; |
| 1972 | } else if (GetImportedOrCreateDecl<TypedefDecl>( |
| 1973 | ToTypedef, D, Importer.getToContext(), DC, StartL, Loc, |
| 1974 | Name.getAsIdentifierInfo(), TInfo)) |
| 1975 | return ToTypedef; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1976 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1977 | ToTypedef->setAccess(D->getAccess()); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1978 | ToTypedef->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1979 | |
| 1980 | // Templated declarations should not appear in DeclContext. |
| 1981 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 1982 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 1983 | LexicalDC->addDeclInternal(ToTypedef); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1984 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1985 | return ToTypedef; |
| 1986 | } |
| 1987 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1988 | Decl *ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
| 1989 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 1990 | } |
| 1991 | |
| 1992 | Decl *ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| 1993 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 1994 | } |
| 1995 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1996 | Decl *ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| 1997 | // Import the major distinguishing characteristics of this typedef. |
| 1998 | DeclContext *DC, *LexicalDC; |
| 1999 | DeclarationName Name; |
| 2000 | SourceLocation Loc; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2001 | NamedDecl *FoundD; |
| 2002 | if (ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2003 | return nullptr; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2004 | if (FoundD) |
| 2005 | return FoundD; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2006 | |
| 2007 | // If this typedef is not in block scope, determine whether we've |
| 2008 | // seen a typedef with the same name (that we can merge with) or any |
| 2009 | // other entity by that name (which name lookup could conflict with). |
| 2010 | if (!DC->isFunctionOrMethod()) { |
| 2011 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 2012 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 2013 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 2014 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2015 | for (auto *FoundDecl : FoundDecls) { |
| 2016 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2017 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2018 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2019 | return Importer.MapImported(D, FoundAlias); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2020 | ConflictingDecls.push_back(FoundDecl); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | if (!ConflictingDecls.empty()) { |
| 2024 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2025 | ConflictingDecls.data(), |
| 2026 | ConflictingDecls.size()); |
| 2027 | if (!Name) |
| 2028 | return nullptr; |
| 2029 | } |
| 2030 | } |
| 2031 | |
| 2032 | TemplateParameterList *Params = ImportTemplateParameterList( |
| 2033 | D->getTemplateParameters()); |
| 2034 | if (!Params) |
| 2035 | return nullptr; |
| 2036 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2037 | auto *TemplDecl = cast_or_null<TypeAliasDecl>( |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2038 | Importer.Import(D->getTemplatedDecl())); |
| 2039 | if (!TemplDecl) |
| 2040 | return nullptr; |
| 2041 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2042 | TypeAliasTemplateDecl *ToAlias; |
| 2043 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, |
| 2044 | Name, Params, TemplDecl)) |
| 2045 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2046 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2047 | TemplDecl->setDescribedAliasTemplate(ToAlias); |
| 2048 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2049 | ToAlias->setAccess(D->getAccess()); |
| 2050 | ToAlias->setLexicalDeclContext(LexicalDC); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2051 | LexicalDC->addDeclInternal(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2052 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2053 | } |
| 2054 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2055 | Decl *ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
| 2056 | // Import the major distinguishing characteristics of this label. |
| 2057 | DeclContext *DC, *LexicalDC; |
| 2058 | DeclarationName Name; |
| 2059 | SourceLocation Loc; |
| 2060 | NamedDecl *ToD; |
| 2061 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2062 | return nullptr; |
| 2063 | if (ToD) |
| 2064 | return ToD; |
| 2065 | |
| 2066 | assert(LexicalDC->isFunctionOrMethod()); |
| 2067 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2068 | LabelDecl *ToLabel; |
| 2069 | if (D->isGnuLocal() |
| 2070 | ? GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, |
| 2071 | Importer.Import(D->getLocation()), |
| 2072 | Name.getAsIdentifierInfo(), |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 2073 | Importer.Import(D->getBeginLoc())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2074 | : GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, |
| 2075 | Importer.Import(D->getLocation()), |
| 2076 | Name.getAsIdentifierInfo())) |
| 2077 | return ToLabel; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2078 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2079 | auto *Label = cast_or_null<LabelStmt>(Importer.Import(D->getStmt())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2080 | if (!Label) |
| 2081 | return nullptr; |
| 2082 | |
| 2083 | ToLabel->setStmt(Label); |
| 2084 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 2085 | LexicalDC->addDeclInternal(ToLabel); |
| 2086 | return ToLabel; |
| 2087 | } |
| 2088 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2089 | Decl *ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
| 2090 | // Import the major distinguishing characteristics of this enum. |
| 2091 | DeclContext *DC, *LexicalDC; |
| 2092 | DeclarationName Name; |
| 2093 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2094 | NamedDecl *ToD; |
| 2095 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2096 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2097 | if (ToD) |
| 2098 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2099 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2100 | // Figure out what enum name we're looking for. |
| 2101 | unsigned IDNS = Decl::IDNS_Tag; |
| 2102 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2103 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 2104 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2105 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2106 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2107 | IDNS |= Decl::IDNS_Ordinary; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2108 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2109 | // We may already have an enum of the same name; try to find and match it. |
| 2110 | if (!DC->isFunctionOrMethod() && SearchName) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2111 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2112 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 2113 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2114 | for (auto *FoundDecl : FoundDecls) { |
| 2115 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2116 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2117 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2118 | Decl *Found = FoundDecl; |
| 2119 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2120 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2121 | Found = Tag->getDecl(); |
| 2122 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2123 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2124 | if (auto *FoundEnum = dyn_cast<EnumDecl>(Found)) { |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2125 | if (IsStructuralMatch(D, FoundEnum)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2126 | return Importer.MapImported(D, FoundEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2127 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2128 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2129 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2130 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2131 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2132 | if (!ConflictingDecls.empty()) { |
| 2133 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2134 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2135 | ConflictingDecls.size()); |
| 2136 | } |
| 2137 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2138 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2139 | // Create the enum declaration. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2140 | EnumDecl *D2; |
| 2141 | if (GetImportedOrCreateDecl( |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 2142 | D2, D, Importer.getToContext(), DC, Importer.Import(D->getBeginLoc()), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2143 | Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(), |
| 2144 | D->isScopedUsingClassTag(), D->isFixed())) |
| 2145 | return D2; |
| 2146 | |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 2147 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2148 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2149 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2150 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2151 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2152 | |
| 2153 | // Import the integer type. |
| 2154 | QualType ToIntegerType = Importer.Import(D->getIntegerType()); |
| 2155 | if (ToIntegerType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2156 | return nullptr; |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2157 | D2->setIntegerType(ToIntegerType); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2158 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2159 | // Import the definition |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 2160 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2161 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2162 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2163 | return D2; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2164 | } |
| 2165 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2166 | Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2167 | bool IsFriendTemplate = false; |
| 2168 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2169 | IsFriendTemplate = |
| 2170 | DCXX->getDescribedClassTemplate() && |
| 2171 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != |
| 2172 | Decl::FOK_None; |
| 2173 | } |
| 2174 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2175 | // If this record has a definition in the translation unit we're coming from, |
| 2176 | // but this particular declaration is not that definition, import the |
| 2177 | // definition and map to that. |
Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 2178 | TagDecl *Definition = D->getDefinition(); |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2179 | if (Definition && Definition != D && |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2180 | // Friend template declaration must be imported on its own. |
| 2181 | !IsFriendTemplate && |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2182 | // In contrast to a normal CXXRecordDecl, the implicit |
| 2183 | // CXXRecordDecl of ClassTemplateSpecializationDecl is its redeclaration. |
| 2184 | // The definition of the implicit CXXRecordDecl in this case is the |
| 2185 | // ClassTemplateSpecializationDecl itself. Thus, we start with an extra |
| 2186 | // condition in order to be able to import the implict Decl. |
| 2187 | !D->isImplicit()) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2188 | Decl *ImportedDef = Importer.Import(Definition); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2189 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2190 | return nullptr; |
| 2191 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2192 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2193 | } |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2194 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2195 | // Import the major distinguishing characteristics of this record. |
| 2196 | DeclContext *DC, *LexicalDC; |
| 2197 | DeclarationName Name; |
| 2198 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2199 | NamedDecl *ToD; |
| 2200 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2201 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2202 | if (ToD) |
| 2203 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2204 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2205 | // Figure out what structure name we're looking for. |
| 2206 | unsigned IDNS = Decl::IDNS_Tag; |
| 2207 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2208 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 2209 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2210 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2211 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2212 | IDNS |= Decl::IDNS_Ordinary; |
| 2213 | |
| 2214 | // 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] | 2215 | RecordDecl *AdoptDecl = nullptr; |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2216 | RecordDecl *PrevDecl = nullptr; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2217 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2218 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2219 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 2220 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2221 | |
| 2222 | if (!FoundDecls.empty()) { |
| 2223 | // We're going to have to compare D against potentially conflicting Decls, so complete it. |
| 2224 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2225 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2226 | } |
| 2227 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2228 | for (auto *FoundDecl : FoundDecls) { |
| 2229 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2230 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2231 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2232 | Decl *Found = FoundDecl; |
| 2233 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2234 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2235 | Found = Tag->getDecl(); |
| 2236 | } |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2237 | |
| 2238 | if (D->getDescribedTemplate()) { |
| 2239 | if (auto *Template = dyn_cast<ClassTemplateDecl>(Found)) |
| 2240 | Found = Template->getTemplatedDecl(); |
| 2241 | else |
| 2242 | continue; |
| 2243 | } |
| 2244 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2245 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
Aleksei Sidorin | 499de6c | 2018-04-05 15:31:49 +0000 | [diff] [blame] | 2246 | if (!SearchName) { |
Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2247 | if (!IsStructuralMatch(D, FoundRecord, false)) |
| 2248 | continue; |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2249 | } |
| 2250 | |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2251 | PrevDecl = FoundRecord; |
| 2252 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2253 | if (RecordDecl *FoundDef = FoundRecord->getDefinition()) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2254 | if ((SearchName && !D->isCompleteDefinition() && !IsFriendTemplate) |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2255 | || (D->isCompleteDefinition() && |
| 2256 | D->isAnonymousStructOrUnion() |
| 2257 | == FoundDef->isAnonymousStructOrUnion() && |
| 2258 | IsStructuralMatch(D, FoundDef))) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2259 | // The record types structurally match, or the "from" translation |
| 2260 | // unit only had a forward declaration anyway; call it the same |
| 2261 | // function. |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2262 | // FIXME: Structural equivalence check should check for same |
| 2263 | // user-defined methods. |
| 2264 | Importer.MapImported(D, FoundDef); |
| 2265 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2266 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); |
| 2267 | assert(FoundCXX && "Record type mismatch"); |
| 2268 | |
| 2269 | if (D->isCompleteDefinition() && !Importer.isMinimalImport()) |
| 2270 | // FoundDef may not have every implicit method that D has |
| 2271 | // because implicit methods are created only if they are used. |
| 2272 | ImportImplicitMethods(DCXX, FoundCXX); |
| 2273 | } |
| 2274 | return FoundDef; |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2275 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2276 | } else if (!D->isCompleteDefinition()) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2277 | // We have a forward declaration of this type, so adopt that forward |
| 2278 | // declaration rather than building a new one. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2279 | |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2280 | // If one or both can be completed from external storage then try one |
| 2281 | // last time to complete and compare them before doing this. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2282 | |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2283 | if (FoundRecord->hasExternalLexicalStorage() && |
| 2284 | !FoundRecord->isCompleteDefinition()) |
| 2285 | FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord); |
| 2286 | if (D->hasExternalLexicalStorage()) |
| 2287 | D->getASTContext().getExternalSource()->CompleteType(D); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2288 | |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2289 | if (FoundRecord->isCompleteDefinition() && |
| 2290 | D->isCompleteDefinition() && |
| 2291 | !IsStructuralMatch(D, FoundRecord)) |
| 2292 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2293 | |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2294 | if (IsFriendTemplate) |
| 2295 | continue; |
| 2296 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2297 | AdoptDecl = FoundRecord; |
| 2298 | continue; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2299 | } else if (!SearchName) { |
| 2300 | continue; |
| 2301 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2302 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2303 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2304 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2305 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2306 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2307 | if (!ConflictingDecls.empty() && SearchName) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2308 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2309 | ConflictingDecls.data(), |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2310 | ConflictingDecls.size()); |
| 2311 | } |
| 2312 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2313 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2314 | // Create the record declaration. |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2315 | RecordDecl *D2 = AdoptDecl; |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 2316 | SourceLocation StartLoc = Importer.Import(D->getBeginLoc()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2317 | if (!D2) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2318 | CXXRecordDecl *D2CXX = nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2319 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2320 | if (DCXX->isLambda()) { |
| 2321 | TypeSourceInfo *TInfo = Importer.Import(DCXX->getLambdaTypeInfo()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2322 | if (GetImportedOrCreateSpecialDecl( |
| 2323 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), |
| 2324 | DC, TInfo, Loc, DCXX->isDependentLambda(), |
| 2325 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) |
| 2326 | return D2CXX; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2327 | Decl *CDecl = Importer.Import(DCXX->getLambdaContextDecl()); |
| 2328 | if (DCXX->getLambdaContextDecl() && !CDecl) |
| 2329 | return nullptr; |
Sean Callanan | 041cceb | 2016-05-14 05:43:57 +0000 | [diff] [blame] | 2330 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), CDecl); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2331 | } else if (DCXX->isInjectedClassName()) { |
| 2332 | // We have to be careful to do a similar dance to the one in |
| 2333 | // Sema::ActOnStartCXXMemberDeclarations |
| 2334 | CXXRecordDecl *const PrevDecl = nullptr; |
| 2335 | const bool DelayTypeCreation = true; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2336 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
| 2337 | D->getTagKind(), DC, StartLoc, Loc, |
| 2338 | Name.getAsIdentifierInfo(), PrevDecl, |
| 2339 | DelayTypeCreation)) |
| 2340 | return D2CXX; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2341 | Importer.getToContext().getTypeDeclType( |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2342 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2343 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2344 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
| 2345 | D->getTagKind(), DC, StartLoc, Loc, |
| 2346 | Name.getAsIdentifierInfo(), |
| 2347 | cast_or_null<CXXRecordDecl>(PrevDecl))) |
| 2348 | return D2CXX; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2349 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2350 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2351 | D2 = D2CXX; |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2352 | D2->setAccess(D->getAccess()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2353 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | de8bf26 | 2018-05-17 09:46:07 +0000 | [diff] [blame] | 2354 | if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit()) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2355 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2356 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2357 | if (ClassTemplateDecl *FromDescribed = |
| 2358 | DCXX->getDescribedClassTemplate()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2359 | auto *ToDescribed = cast_or_null<ClassTemplateDecl>( |
| 2360 | Importer.Import(FromDescribed)); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2361 | if (!ToDescribed) |
| 2362 | return nullptr; |
| 2363 | D2CXX->setDescribedClassTemplate(ToDescribed); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2364 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { |
Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2365 | // In a record describing a template the type should be an |
| 2366 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the |
| 2367 | // previously set type to the correct value here (ToDescribed is not |
| 2368 | // available at record create). |
| 2369 | // FIXME: The previous type is cleared but not removed from |
| 2370 | // ASTContext's internal storage. |
| 2371 | CXXRecordDecl *Injected = nullptr; |
| 2372 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { |
| 2373 | auto *Record = dyn_cast<CXXRecordDecl>(Found); |
| 2374 | if (Record && Record->isInjectedClassName()) { |
| 2375 | Injected = Record; |
| 2376 | break; |
| 2377 | } |
| 2378 | } |
| 2379 | D2CXX->setTypeForDecl(nullptr); |
| 2380 | Importer.getToContext().getInjectedClassNameType(D2CXX, |
| 2381 | ToDescribed->getInjectedClassNameSpecialization()); |
| 2382 | if (Injected) { |
| 2383 | Injected->setTypeForDecl(nullptr); |
| 2384 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); |
| 2385 | } |
| 2386 | } |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2387 | } else if (MemberSpecializationInfo *MemberInfo = |
| 2388 | DCXX->getMemberSpecializationInfo()) { |
| 2389 | TemplateSpecializationKind SK = |
| 2390 | MemberInfo->getTemplateSpecializationKind(); |
| 2391 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2392 | auto *ToInst = |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2393 | cast_or_null<CXXRecordDecl>(Importer.Import(FromInst)); |
| 2394 | if (FromInst && !ToInst) |
| 2395 | return nullptr; |
| 2396 | D2CXX->setInstantiationOfMemberClass(ToInst, SK); |
| 2397 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2398 | Importer.Import(MemberInfo->getPointOfInstantiation())); |
| 2399 | } |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2400 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2401 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), |
| 2402 | D->getTagKind(), DC, StartLoc, Loc, |
| 2403 | Name.getAsIdentifierInfo(), PrevDecl)) |
| 2404 | return D2; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2405 | D2->setLexicalDeclContext(LexicalDC); |
| 2406 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2407 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2408 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2409 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2410 | if (D->isAnonymousStructOrUnion()) |
| 2411 | D2->setAnonymousStructOrUnion(true); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2412 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2413 | |
| 2414 | Importer.MapImported(D, D2); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2415 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 2416 | if (D->isCompleteDefinition() && ImportDefinition(D, D2, IDK_Default)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2417 | return nullptr; |
| 2418 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2419 | return D2; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2420 | } |
| 2421 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2422 | Decl *ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| 2423 | // Import the major distinguishing characteristics of this enumerator. |
| 2424 | DeclContext *DC, *LexicalDC; |
| 2425 | DeclarationName Name; |
| 2426 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2427 | NamedDecl *ToD; |
| 2428 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2429 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2430 | if (ToD) |
| 2431 | return ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2432 | |
| 2433 | QualType T = Importer.Import(D->getType()); |
| 2434 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2435 | return nullptr; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2436 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2437 | // Determine whether there are any other declarations with the same name and |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2438 | // in the same context. |
| 2439 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2440 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2441 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2442 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2443 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2444 | for (auto *FoundDecl : FoundDecls) { |
| 2445 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2446 | continue; |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2447 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2448 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2449 | if (IsStructuralMatch(D, FoundEnumConstant)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2450 | return Importer.MapImported(D, FoundEnumConstant); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2451 | } |
| 2452 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2453 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2454 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2455 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2456 | if (!ConflictingDecls.empty()) { |
| 2457 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2458 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2459 | ConflictingDecls.size()); |
| 2460 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2461 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2462 | } |
| 2463 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2464 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2465 | Expr *Init = Importer.Import(D->getInitExpr()); |
| 2466 | if (D->getInitExpr() && !Init) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2467 | return nullptr; |
| 2468 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2469 | EnumConstantDecl *ToEnumerator; |
| 2470 | if (GetImportedOrCreateDecl( |
| 2471 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
| 2472 | Name.getAsIdentifierInfo(), T, Init, D->getInitVal())) |
| 2473 | return ToEnumerator; |
| 2474 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2475 | ToEnumerator->setAccess(D->getAccess()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2476 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2477 | LexicalDC->addDeclInternal(ToEnumerator); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2478 | return ToEnumerator; |
| 2479 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2480 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2481 | bool ASTNodeImporter::ImportTemplateInformation(FunctionDecl *FromFD, |
| 2482 | FunctionDecl *ToFD) { |
| 2483 | switch (FromFD->getTemplatedKind()) { |
| 2484 | case FunctionDecl::TK_NonTemplate: |
| 2485 | case FunctionDecl::TK_FunctionTemplate: |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2486 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2487 | |
| 2488 | case FunctionDecl::TK_MemberSpecialization: { |
| 2489 | auto *InstFD = cast_or_null<FunctionDecl>( |
| 2490 | Importer.Import(FromFD->getInstantiatedFromMemberFunction())); |
| 2491 | if (!InstFD) |
| 2492 | return true; |
| 2493 | |
| 2494 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
| 2495 | SourceLocation POI = Importer.Import( |
| 2496 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation()); |
| 2497 | ToFD->setInstantiationOfMemberFunction(InstFD, TSK); |
| 2498 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2499 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2500 | } |
| 2501 | |
| 2502 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2503 | FunctionTemplateDecl* Template; |
| 2504 | OptionalTemplateArgsTy ToTemplArgs; |
| 2505 | std::tie(Template, ToTemplArgs) = |
| 2506 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| 2507 | if (!Template || !ToTemplArgs) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2508 | return true; |
| 2509 | |
| 2510 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2511 | Importer.getToContext(), *ToTemplArgs); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2512 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2513 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2514 | TemplateArgumentListInfo ToTAInfo; |
| 2515 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2516 | if (FromTAArgsAsWritten) |
| 2517 | if (ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2518 | return true; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2519 | |
| 2520 | SourceLocation POI = Importer.Import(FTSInfo->getPointOfInstantiation()); |
| 2521 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2522 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2523 | ToFD->setFunctionTemplateSpecialization( |
| 2524 | Template, ToTAList, /* InsertPos= */ nullptr, |
| 2525 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, POI); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2526 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2527 | } |
| 2528 | |
| 2529 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 2530 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 2531 | UnresolvedSet<8> TemplDecls; |
| 2532 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 2533 | for (unsigned I = 0; I < NumTemplates; I++) { |
| 2534 | if (auto *ToFTD = cast_or_null<FunctionTemplateDecl>( |
| 2535 | Importer.Import(FromInfo->getTemplate(I)))) |
| 2536 | TemplDecls.addDecl(ToFTD); |
| 2537 | else |
| 2538 | return true; |
| 2539 | } |
| 2540 | |
| 2541 | // Import TemplateArgumentListInfo. |
| 2542 | TemplateArgumentListInfo ToTAInfo; |
| 2543 | if (ImportTemplateArgumentListInfo( |
| 2544 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 2545 | llvm::makeArrayRef(FromInfo->getTemplateArgs(), |
| 2546 | FromInfo->getNumTemplateArgs()), |
| 2547 | ToTAInfo)) |
| 2548 | return true; |
| 2549 | |
| 2550 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 2551 | TemplDecls, ToTAInfo); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2552 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2553 | } |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2554 | } |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2555 | llvm_unreachable("All cases should be covered!"); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2556 | } |
| 2557 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2558 | FunctionDecl * |
| 2559 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { |
| 2560 | FunctionTemplateDecl* Template; |
| 2561 | OptionalTemplateArgsTy ToTemplArgs; |
| 2562 | std::tie(Template, ToTemplArgs) = |
| 2563 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| 2564 | if (!Template || !ToTemplArgs) |
| 2565 | return nullptr; |
| 2566 | |
| 2567 | void *InsertPos = nullptr; |
| 2568 | auto *FoundSpec = Template->findSpecialization(*ToTemplArgs, InsertPos); |
| 2569 | return FoundSpec; |
| 2570 | } |
| 2571 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2572 | Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2573 | |
| 2574 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| 2575 | auto RedeclIt = Redecls.begin(); |
| 2576 | // Import the first part of the decl chain. I.e. import all previous |
| 2577 | // declarations starting from the canonical decl. |
| 2578 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) |
| 2579 | if (!Importer.Import(*RedeclIt)) |
| 2580 | return nullptr; |
| 2581 | assert(*RedeclIt == D); |
| 2582 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2583 | // Import the major distinguishing characteristics of this function. |
| 2584 | DeclContext *DC, *LexicalDC; |
| 2585 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2586 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2587 | NamedDecl *ToD; |
| 2588 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2589 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2590 | if (ToD) |
| 2591 | return ToD; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2592 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2593 | const FunctionDecl *FoundByLookup = nullptr; |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 2594 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2595 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2596 | // If this is a function template specialization, then try to find the same |
| 2597 | // existing specialization in the "to" context. The localUncachedLookup |
| 2598 | // below will not find any specialization, but would find the primary |
| 2599 | // template; thus, we have to skip normal lookup in case of specializations. |
| 2600 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? |
| 2601 | if (D->getTemplatedKind() == |
| 2602 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
| 2603 | if (FunctionDecl *FoundFunction = FindFunctionTemplateSpecialization(D)) { |
| 2604 | if (D->doesThisDeclarationHaveABody() && |
| 2605 | FoundFunction->hasBody()) |
| 2606 | return Importer.Imported(D, FoundFunction); |
| 2607 | FoundByLookup = FoundFunction; |
| 2608 | } |
| 2609 | } |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2610 | // Try to find a function in our own ("to") context with the same name, same |
| 2611 | // type, and in the same context as the function we're importing. |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2612 | else if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2613 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2614 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2615 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2616 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2617 | for (auto *FoundDecl : FoundDecls) { |
| 2618 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2619 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2620 | |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 2621 | // If template was found, look at the templated function. |
| 2622 | if (FromFT) { |
| 2623 | if (auto *Template = dyn_cast<FunctionTemplateDecl>(FoundDecl)) |
| 2624 | FoundDecl = Template->getTemplatedDecl(); |
| 2625 | else |
| 2626 | continue; |
| 2627 | } |
| 2628 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2629 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 2630 | if (FoundFunction->hasExternalFormalLinkage() && |
| 2631 | D->hasExternalFormalLinkage()) { |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2632 | if (IsStructuralMatch(D, FoundFunction)) { |
| 2633 | const FunctionDecl *Definition = nullptr; |
| 2634 | if (D->doesThisDeclarationHaveABody() && |
| 2635 | FoundFunction->hasBody(Definition)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2636 | return Importer.MapImported( |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2637 | D, const_cast<FunctionDecl *>(Definition)); |
| 2638 | } |
| 2639 | FoundByLookup = FoundFunction; |
| 2640 | break; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2641 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2642 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2643 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 2644 | // Sema::IsOverload out to the AST library. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2645 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2646 | // Function overloading is okay in C++. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2647 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2648 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2649 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2650 | // Complain about inconsistent function types. |
| 2651 | Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2652 | << Name << D->getType() << FoundFunction->getType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2653 | Importer.ToDiag(FoundFunction->getLocation(), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2654 | diag::note_odr_value_here) |
| 2655 | << FoundFunction->getType(); |
| 2656 | } |
| 2657 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2658 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2659 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2660 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2661 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2662 | if (!ConflictingDecls.empty()) { |
| 2663 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2664 | ConflictingDecls.data(), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2665 | ConflictingDecls.size()); |
| 2666 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2667 | return nullptr; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2668 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2669 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2670 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2671 | DeclarationNameInfo NameInfo(Name, Loc); |
| 2672 | // Import additional name location/type info. |
| 2673 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 2674 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2675 | QualType FromTy = D->getType(); |
| 2676 | bool usedDifferentExceptionSpec = false; |
| 2677 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2678 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2679 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 2680 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 2681 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 2682 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 2683 | // with a simplified function type and update it afterwards. |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 2684 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 2685 | FromEPI.ExceptionSpec.SourceTemplate || |
| 2686 | FromEPI.ExceptionSpec.NoexceptExpr) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2687 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 2688 | FromTy = Importer.getFromContext().getFunctionType( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2689 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2690 | usedDifferentExceptionSpec = true; |
| 2691 | } |
| 2692 | } |
| 2693 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2694 | // Import the type. |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2695 | QualType T = Importer.Import(FromTy); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2696 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2697 | return nullptr; |
| 2698 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2699 | // Import the function parameters. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2700 | SmallVector<ParmVarDecl *, 8> Parameters; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2701 | for (auto P : D->parameters()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2702 | auto *ToP = cast_or_null<ParmVarDecl>(Importer.Import(P)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2703 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2704 | return nullptr; |
| 2705 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2706 | Parameters.push_back(ToP); |
| 2707 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2708 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2709 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2710 | if (D->getTypeSourceInfo() && !TInfo) |
| 2711 | return nullptr; |
| 2712 | |
| 2713 | // Create the imported function. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2714 | FunctionDecl *ToFunction = nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2715 | SourceLocation InnerLocStart = Importer.Import(D->getInnerLocStart()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2716 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2717 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( |
| 2718 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 2719 | InnerLocStart, NameInfo, T, TInfo, FromConstructor->isExplicit(), |
| 2720 | D->isInlineSpecified(), D->isImplicit(), D->isConstexpr())) |
| 2721 | return ToFunction; |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2722 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 2723 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2724 | for (auto *I : FromConstructor->inits()) { |
| 2725 | auto *ToI = cast_or_null<CXXCtorInitializer>(Importer.Import(I)); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2726 | if (!ToI && I) |
| 2727 | return nullptr; |
| 2728 | CtorInitializers.push_back(ToI); |
| 2729 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2730 | auto **Memory = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2731 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 2732 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2733 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2734 | ToCtor->setCtorInitializers(Memory); |
| 2735 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 2736 | } |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2737 | } else if (isa<CXXDestructorDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2738 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( |
| 2739 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 2740 | InnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| 2741 | D->isImplicit())) |
| 2742 | return ToFunction; |
| 2743 | } else if (CXXConversionDecl *FromConversion = |
| 2744 | dyn_cast<CXXConversionDecl>(D)) { |
| 2745 | if (GetImportedOrCreateDecl<CXXConversionDecl>( |
| 2746 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 2747 | InnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| 2748 | FromConversion->isExplicit(), D->isConstexpr(), SourceLocation())) |
| 2749 | return ToFunction; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2750 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2751 | if (GetImportedOrCreateDecl<CXXMethodDecl>( |
| 2752 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 2753 | InnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), |
| 2754 | Method->isInlineSpecified(), D->isConstexpr(), SourceLocation())) |
| 2755 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2756 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2757 | if (GetImportedOrCreateDecl(ToFunction, D, Importer.getToContext(), DC, |
| 2758 | InnerLocStart, NameInfo, T, TInfo, |
| 2759 | D->getStorageClass(), D->isInlineSpecified(), |
| 2760 | D->hasWrittenPrototype(), D->isConstexpr())) |
| 2761 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2762 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 2763 | |
| 2764 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2765 | ToFunction->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2766 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2767 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 2768 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 2769 | ToFunction->setTrivial(D->isTrivial()); |
| 2770 | ToFunction->setPure(D->isPure()); |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 2771 | ToFunction->setRangeEnd(Importer.Import(D->getEndLoc())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2772 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2773 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2774 | for (auto *Param : Parameters) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2775 | Param->setOwningFunction(ToFunction); |
| 2776 | ToFunction->addDeclInternal(Param); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2777 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 2778 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2779 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2780 | if (FoundByLookup) { |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2781 | auto *Recent = const_cast<FunctionDecl *>( |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2782 | FoundByLookup->getMostRecentDecl()); |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2783 | ToFunction->setPreviousDecl(Recent); |
| 2784 | } |
| 2785 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2786 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 2787 | // params it refers to. |
| 2788 | if (TInfo) { |
| 2789 | if (auto ProtoLoc = |
| 2790 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 2791 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 2792 | ProtoLoc.setParam(I, Parameters[I]); |
| 2793 | } |
| 2794 | } |
| 2795 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2796 | if (usedDifferentExceptionSpec) { |
| 2797 | // Update FunctionProtoType::ExtProtoInfo. |
| 2798 | QualType T = Importer.Import(D->getType()); |
| 2799 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2800 | return nullptr; |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2801 | ToFunction->setType(T); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 2802 | } |
| 2803 | |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 2804 | // Import the describing template function, if any. |
| 2805 | if (FromFT) |
| 2806 | if (!Importer.Import(FromFT)) |
| 2807 | return nullptr; |
| 2808 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2809 | if (D->doesThisDeclarationHaveABody()) { |
| 2810 | if (Stmt *FromBody = D->getBody()) { |
| 2811 | if (Stmt *ToBody = Importer.Import(FromBody)) { |
| 2812 | ToFunction->setBody(ToBody); |
| 2813 | } |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2814 | } |
| 2815 | } |
| 2816 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2817 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2818 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2819 | // If it is a template, import all related things. |
| 2820 | if (ImportTemplateInformation(D, ToFunction)) |
| 2821 | return nullptr; |
| 2822 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2823 | bool IsFriend = D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend); |
| 2824 | |
| 2825 | // TODO Can we generalize this approach to other AST nodes as well? |
| 2826 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 2827 | DC->addDeclInternal(ToFunction); |
| 2828 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2829 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2830 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2831 | // Friend declaration's lexical context is the befriending class, but the |
| 2832 | // semantic context is the enclosing scope of the befriending class. |
| 2833 | // We want the friend functions to be found in the semantic context by lookup. |
| 2834 | // FIXME should we handle this generically in VisitFriendDecl? |
| 2835 | // In Other cases when LexicalDC != DC we don't want it to be added, |
| 2836 | // e.g out-of-class definitions like void B::f() {} . |
| 2837 | if (LexicalDC != DC && IsFriend) { |
| 2838 | DC->makeDeclVisibleInContext(ToFunction); |
| 2839 | } |
| 2840 | |
| 2841 | // Import the rest of the chain. I.e. import all subsequent declarations. |
| 2842 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) |
| 2843 | if (!Importer.Import(*RedeclIt)) |
| 2844 | return nullptr; |
| 2845 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 2846 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 2847 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 2848 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2849 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2850 | } |
| 2851 | |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2852 | Decl *ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| 2853 | return VisitFunctionDecl(D); |
| 2854 | } |
| 2855 | |
| 2856 | Decl *ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| 2857 | return VisitCXXMethodDecl(D); |
| 2858 | } |
| 2859 | |
| 2860 | Decl *ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| 2861 | return VisitCXXMethodDecl(D); |
| 2862 | } |
| 2863 | |
| 2864 | Decl *ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| 2865 | return VisitCXXMethodDecl(D); |
| 2866 | } |
| 2867 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2868 | Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
| 2869 | // Import the major distinguishing characteristics of a variable. |
| 2870 | DeclContext *DC, *LexicalDC; |
| 2871 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2872 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2873 | NamedDecl *ToD; |
| 2874 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2875 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2876 | if (ToD) |
| 2877 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2878 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2879 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2880 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2881 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2882 | for (auto *FoundDecl : FoundDecls) { |
| 2883 | if (auto *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2884 | // For anonymous fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 2885 | if (!Name && |
| 2886 | ASTImporter::getFieldIndex(D) != |
| 2887 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2888 | continue; |
| 2889 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2890 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2891 | FoundField->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2892 | Importer.MapImported(D, FoundField); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame^] | 2893 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the |
| 2894 | // initializer of a FieldDecl might not had been instantiated in the |
| 2895 | // "To" context. However, the "From" context might instantiated that, |
| 2896 | // thus we have to merge that. |
| 2897 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
| 2898 | // We don't have yet the initializer set. |
| 2899 | if (FoundField->hasInClassInitializer() && |
| 2900 | !FoundField->getInClassInitializer()) { |
| 2901 | Expr *ToInitializer = Importer.Import(FromInitializer); |
| 2902 | if (!ToInitializer) |
| 2903 | // We can't return a nullptr here, |
| 2904 | // since we already mapped D as imported. |
| 2905 | return FoundField; |
| 2906 | FoundField->setInClassInitializer(ToInitializer); |
| 2907 | } |
| 2908 | } |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2909 | return FoundField; |
| 2910 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2911 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2912 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2913 | << Name << D->getType() << FoundField->getType(); |
| 2914 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2915 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2916 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2917 | } |
| 2918 | } |
| 2919 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2920 | // Import the type. |
| 2921 | QualType T = Importer.Import(D->getType()); |
| 2922 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2923 | return nullptr; |
| 2924 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2925 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2926 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 2927 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2928 | return nullptr; |
| 2929 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2930 | FieldDecl *ToField; |
| 2931 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, |
| 2932 | Importer.Import(D->getInnerLocStart()), Loc, |
| 2933 | Name.getAsIdentifierInfo(), T, TInfo, BitWidth, |
| 2934 | D->isMutable(), D->getInClassInitStyle())) |
| 2935 | return ToField; |
| 2936 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2937 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2938 | ToField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 3a83ea7 | 2016-03-03 02:22:05 +0000 | [diff] [blame] | 2939 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
Sean Callanan | bb33f58 | 2016-03-03 01:21:28 +0000 | [diff] [blame] | 2940 | Expr *ToInitializer = Importer.Import(FromInitializer); |
| 2941 | if (ToInitializer) |
| 2942 | ToField->setInClassInitializer(ToInitializer); |
| 2943 | else |
| 2944 | return nullptr; |
| 2945 | } |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2946 | ToField->setImplicit(D->isImplicit()); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2947 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2948 | return ToField; |
| 2949 | } |
| 2950 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2951 | Decl *ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| 2952 | // Import the major distinguishing characteristics of a variable. |
| 2953 | DeclContext *DC, *LexicalDC; |
| 2954 | DeclarationName Name; |
| 2955 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2956 | NamedDecl *ToD; |
| 2957 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2958 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2959 | if (ToD) |
| 2960 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2961 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2962 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2963 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2964 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2965 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2966 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2967 | // For anonymous indirect fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 2968 | if (!Name && |
| 2969 | ASTImporter::getFieldIndex(D) != |
| 2970 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2971 | continue; |
| 2972 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2973 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2974 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 2975 | !Name.isEmpty())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2976 | Importer.MapImported(D, FoundField); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2977 | return FoundField; |
| 2978 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2979 | |
| 2980 | // If there are more anonymous fields to check, continue. |
| 2981 | if (!Name && I < N-1) |
| 2982 | continue; |
| 2983 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2984 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2985 | << Name << D->getType() << FoundField->getType(); |
| 2986 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2987 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2988 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2989 | } |
| 2990 | } |
| 2991 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +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; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2996 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2997 | auto **NamedChain = |
| 2998 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2999 | |
| 3000 | unsigned i = 0; |
Aaron Ballman | 29c9460 | 2014-03-07 18:36:15 +0000 | [diff] [blame] | 3001 | for (auto *PI : D->chain()) { |
Aaron Ballman | 1391608 | 2014-03-07 18:11:58 +0000 | [diff] [blame] | 3002 | Decl *D = Importer.Import(PI); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3003 | if (!D) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3004 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3005 | NamedChain[i++] = cast<NamedDecl>(D); |
| 3006 | } |
| 3007 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3008 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; |
| 3009 | IndirectFieldDecl *ToIndirectField; |
| 3010 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, |
| 3011 | Loc, Name.getAsIdentifierInfo(), T, CH)) |
| 3012 | // FIXME here we leak `NamedChain` which is allocated before |
| 3013 | return ToIndirectField; |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3014 | |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 3015 | for (const auto *A : D->attrs()) |
| 3016 | ToIndirectField->addAttr(Importer.Import(A)); |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3017 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3018 | ToIndirectField->setAccess(D->getAccess()); |
| 3019 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3020 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3021 | return ToIndirectField; |
| 3022 | } |
| 3023 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3024 | Decl *ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
| 3025 | // Import the major distinguishing characteristics of a declaration. |
| 3026 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3027 | DeclContext *LexicalDC = D->getDeclContext() == D->getLexicalDeclContext() |
| 3028 | ? DC : Importer.ImportContext(D->getLexicalDeclContext()); |
| 3029 | if (!DC || !LexicalDC) |
| 3030 | return nullptr; |
| 3031 | |
| 3032 | // Determine whether we've already imported this decl. |
| 3033 | // FriendDecl is not a NamedDecl so we cannot use localUncachedLookup. |
| 3034 | auto *RD = cast<CXXRecordDecl>(DC); |
| 3035 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3036 | |
| 3037 | while (ImportedFriend) { |
| 3038 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 3039 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), |
| 3040 | /*Complain=*/false)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3041 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3042 | |
| 3043 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 3044 | if (Importer.IsStructurallyEquivalent( |
| 3045 | D->getFriendType()->getType(), |
| 3046 | ImportedFriend->getFriendType()->getType(), true)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3047 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3048 | } |
| 3049 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 3050 | } |
| 3051 | |
| 3052 | // Not found. Create it. |
| 3053 | FriendDecl::FriendUnion ToFU; |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3054 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
| 3055 | auto *ToFriendD = cast_or_null<NamedDecl>(Importer.Import(FriendD)); |
| 3056 | if (ToFriendD && FriendD->getFriendObjectKind() != Decl::FOK_None && |
| 3057 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 3058 | ToFriendD->setObjectOfFriendDecl(false); |
| 3059 | |
| 3060 | ToFU = ToFriendD; |
| 3061 | } else // The friend is a type, not a decl. |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3062 | ToFU = Importer.Import(D->getFriendType()); |
| 3063 | if (!ToFU) |
| 3064 | return nullptr; |
| 3065 | |
| 3066 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3067 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3068 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
| 3069 | TemplateParameterList *List = ImportTemplateParameterList(FromTPLists[I]); |
| 3070 | if (!List) |
| 3071 | return nullptr; |
| 3072 | ToTPLists[I] = List; |
| 3073 | } |
| 3074 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3075 | FriendDecl *FrD; |
| 3076 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, |
| 3077 | Importer.Import(D->getLocation()), ToFU, |
| 3078 | Importer.Import(D->getFriendLoc()), ToTPLists)) |
| 3079 | return FrD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3080 | |
| 3081 | FrD->setAccess(D->getAccess()); |
| 3082 | FrD->setLexicalDeclContext(LexicalDC); |
| 3083 | LexicalDC->addDeclInternal(FrD); |
| 3084 | return FrD; |
| 3085 | } |
| 3086 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3087 | Decl *ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| 3088 | // Import the major distinguishing characteristics of an ivar. |
| 3089 | DeclContext *DC, *LexicalDC; |
| 3090 | DeclarationName Name; |
| 3091 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3092 | NamedDecl *ToD; |
| 3093 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3094 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3095 | if (ToD) |
| 3096 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3097 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3098 | // Determine whether we've already imported this ivar |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3099 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3100 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3101 | for (auto *FoundDecl : FoundDecls) { |
| 3102 | if (auto *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3103 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3104 | FoundIvar->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3105 | Importer.MapImported(D, FoundIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3106 | return FoundIvar; |
| 3107 | } |
| 3108 | |
| 3109 | Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent) |
| 3110 | << Name << D->getType() << FoundIvar->getType(); |
| 3111 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 3112 | << FoundIvar->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3113 | return nullptr; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3114 | } |
| 3115 | } |
| 3116 | |
| 3117 | // Import the type. |
| 3118 | QualType T = Importer.Import(D->getType()); |
| 3119 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3120 | return nullptr; |
| 3121 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3122 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3123 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 3124 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3125 | return nullptr; |
| 3126 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3127 | ObjCIvarDecl *ToIvar; |
| 3128 | if (GetImportedOrCreateDecl( |
| 3129 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), |
| 3130 | Importer.Import(D->getInnerLocStart()), Loc, |
| 3131 | Name.getAsIdentifierInfo(), T, TInfo, D->getAccessControl(), BitWidth, |
| 3132 | D->getSynthesize())) |
| 3133 | return ToIvar; |
| 3134 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3135 | ToIvar->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3136 | LexicalDC->addDeclInternal(ToIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3137 | return ToIvar; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3138 | } |
| 3139 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3140 | Decl *ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
| 3141 | // Import the major distinguishing characteristics of a variable. |
| 3142 | DeclContext *DC, *LexicalDC; |
| 3143 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3144 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3145 | NamedDecl *ToD; |
| 3146 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3147 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3148 | if (ToD) |
| 3149 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3150 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3151 | // Try to find a variable in our own ("to") context with the same name and |
| 3152 | // in the same context as the variable we're importing. |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3153 | if (D->isFileVarDecl()) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3154 | VarDecl *MergeWithVar = nullptr; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3155 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3156 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3157 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3158 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3159 | for (auto *FoundDecl : FoundDecls) { |
| 3160 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3161 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3162 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3163 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3164 | // 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] | 3165 | if (FoundVar->hasExternalFormalLinkage() && |
| 3166 | D->hasExternalFormalLinkage()) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3167 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3168 | FoundVar->getType())) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3169 | MergeWithVar = FoundVar; |
| 3170 | break; |
| 3171 | } |
| 3172 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3173 | const ArrayType *FoundArray |
| 3174 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 3175 | const ArrayType *TArray |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3176 | = Importer.getToContext().getAsArrayType(D->getType()); |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3177 | if (FoundArray && TArray) { |
| 3178 | if (isa<IncompleteArrayType>(FoundArray) && |
| 3179 | isa<ConstantArrayType>(TArray)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3180 | // Import the type. |
| 3181 | QualType T = Importer.Import(D->getType()); |
| 3182 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3183 | return nullptr; |
| 3184 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3185 | FoundVar->setType(T); |
| 3186 | MergeWithVar = FoundVar; |
| 3187 | break; |
| 3188 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3189 | isa<ConstantArrayType>(FoundArray)) { |
| 3190 | MergeWithVar = FoundVar; |
| 3191 | break; |
Douglas Gregor | 2fbe558 | 2010-02-10 17:16:49 +0000 | [diff] [blame] | 3192 | } |
| 3193 | } |
| 3194 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3195 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3196 | << Name << D->getType() << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3197 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3198 | << FoundVar->getType(); |
| 3199 | } |
| 3200 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3201 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3202 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3203 | } |
| 3204 | |
| 3205 | if (MergeWithVar) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3206 | // An equivalent variable with external linkage has been found. Link |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3207 | // the two declarations, then merge them. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3208 | Importer.MapImported(D, MergeWithVar); |
| 3209 | updateFlags(D, MergeWithVar); |
| 3210 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3211 | if (VarDecl *DDef = D->getDefinition()) { |
| 3212 | if (VarDecl *ExistingDef = MergeWithVar->getDefinition()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3213 | Importer.ToDiag(ExistingDef->getLocation(), |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3214 | diag::err_odr_variable_multiple_def) |
| 3215 | << Name; |
| 3216 | Importer.FromDiag(DDef->getLocation(), diag::note_odr_defined_here); |
| 3217 | } else { |
| 3218 | Expr *Init = Importer.Import(DDef->getInit()); |
Douglas Gregor | d505812 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 3219 | MergeWithVar->setInit(Init); |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 3220 | if (DDef->isInitKnownICE()) { |
| 3221 | EvaluatedStmt *Eval = MergeWithVar->ensureEvaluatedStmt(); |
| 3222 | Eval->CheckedICE = true; |
| 3223 | Eval->IsICE = DDef->isInitICE(); |
| 3224 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3225 | } |
| 3226 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3227 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3228 | return MergeWithVar; |
| 3229 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3230 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3231 | if (!ConflictingDecls.empty()) { |
| 3232 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3233 | ConflictingDecls.data(), |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3234 | ConflictingDecls.size()); |
| 3235 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3236 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3237 | } |
| 3238 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3239 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3240 | // Import the type. |
| 3241 | QualType T = Importer.Import(D->getType()); |
| 3242 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3243 | return nullptr; |
| 3244 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3245 | // Create the imported variable. |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 3246 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3247 | VarDecl *ToVar; |
| 3248 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, |
| 3249 | Importer.Import(D->getInnerLocStart()), Loc, |
| 3250 | Name.getAsIdentifierInfo(), T, TInfo, |
| 3251 | D->getStorageClass())) |
| 3252 | return ToVar; |
| 3253 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3254 | ToVar->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3255 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3256 | ToVar->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3257 | |
| 3258 | // Templated declarations should never appear in the enclosing DeclContext. |
| 3259 | if (!D->getDescribedVarTemplate()) |
| 3260 | LexicalDC->addDeclInternal(ToVar); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3261 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3262 | // Merge the initializer. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3263 | if (ImportDefinition(D, ToVar)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3264 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3265 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3266 | if (D->isConstexpr()) |
| 3267 | ToVar->setConstexpr(true); |
| 3268 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3269 | return ToVar; |
| 3270 | } |
| 3271 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3272 | Decl *ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| 3273 | // Parameters are created in the translation unit's context, then moved |
| 3274 | // into the function declaration's context afterward. |
| 3275 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3276 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3277 | // Import the name of this declaration. |
| 3278 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 3279 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3280 | return nullptr; |
| 3281 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3282 | // Import the location of this declaration. |
| 3283 | SourceLocation Loc = Importer.Import(D->getLocation()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3284 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3285 | // Import the parameter's type. |
| 3286 | QualType T = Importer.Import(D->getType()); |
| 3287 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3288 | return nullptr; |
| 3289 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3290 | // Create the imported parameter. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3291 | ImplicitParamDecl *ToParm = nullptr; |
| 3292 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, Loc, |
| 3293 | Name.getAsIdentifierInfo(), T, |
| 3294 | D->getParameterKind())) |
| 3295 | return ToParm; |
| 3296 | return ToParm; |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3297 | } |
| 3298 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3299 | Decl *ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
| 3300 | // Parameters are created in the translation unit's context, then moved |
| 3301 | // into the function declaration's context afterward. |
| 3302 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3303 | |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 3304 | // Import the name of this declaration. |
| 3305 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 3306 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3307 | return nullptr; |
| 3308 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3309 | // Import the location of this declaration. |
| 3310 | SourceLocation Loc = Importer.Import(D->getLocation()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3311 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3312 | // Import the parameter's type. |
| 3313 | QualType T = Importer.Import(D->getType()); |
| 3314 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3315 | return nullptr; |
| 3316 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3317 | // Create the imported parameter. |
| 3318 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3319 | ParmVarDecl *ToParm; |
| 3320 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| 3321 | Importer.Import(D->getInnerLocStart()), Loc, |
| 3322 | Name.getAsIdentifierInfo(), T, TInfo, |
| 3323 | D->getStorageClass(), |
| 3324 | /*DefaultArg*/ nullptr)) |
| 3325 | return ToParm; |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3326 | |
| 3327 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 3328 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3329 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 3330 | |
| 3331 | Expr *ToDefArg = nullptr; |
| 3332 | Expr *FromDefArg = nullptr; |
| 3333 | if (D->hasUninstantiatedDefaultArg()) { |
| 3334 | FromDefArg = D->getUninstantiatedDefaultArg(); |
| 3335 | ToDefArg = Importer.Import(FromDefArg); |
| 3336 | ToParm->setUninstantiatedDefaultArg(ToDefArg); |
| 3337 | } else if (D->hasUnparsedDefaultArg()) { |
| 3338 | ToParm->setUnparsedDefaultArg(); |
| 3339 | } else if (D->hasDefaultArg()) { |
| 3340 | FromDefArg = D->getDefaultArg(); |
| 3341 | ToDefArg = Importer.Import(FromDefArg); |
| 3342 | ToParm->setDefaultArg(ToDefArg); |
| 3343 | } |
| 3344 | if (FromDefArg && !ToDefArg) |
| 3345 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3346 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3347 | if (D->isObjCMethodParameter()) { |
| 3348 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3349 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3350 | } else { |
| 3351 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3352 | D->getFunctionScopeIndex()); |
| 3353 | } |
| 3354 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3355 | return ToParm; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3356 | } |
| 3357 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3358 | Decl *ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| 3359 | // Import the major distinguishing characteristics of a method. |
| 3360 | DeclContext *DC, *LexicalDC; |
| 3361 | DeclarationName Name; |
| 3362 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3363 | NamedDecl *ToD; |
| 3364 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3365 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3366 | if (ToD) |
| 3367 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3368 | |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3369 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3370 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3371 | for (auto *FoundDecl : FoundDecls) { |
| 3372 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3373 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 3374 | continue; |
| 3375 | |
| 3376 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3377 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 3378 | FoundMethod->getReturnType())) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3379 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3380 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 3381 | << FoundMethod->getReturnType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3382 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3383 | diag::note_odr_objc_method_here) |
| 3384 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3385 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3386 | } |
| 3387 | |
| 3388 | // Check the number of parameters. |
| 3389 | if (D->param_size() != FoundMethod->param_size()) { |
| 3390 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) |
| 3391 | << D->isInstanceMethod() << Name |
| 3392 | << D->param_size() << FoundMethod->param_size(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3393 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3394 | diag::note_odr_objc_method_here) |
| 3395 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3396 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3400 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3401 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 3402 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3403 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3404 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3405 | Importer.FromDiag((*P)->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3406 | diag::err_odr_objc_method_param_type_inconsistent) |
| 3407 | << D->isInstanceMethod() << Name |
| 3408 | << (*P)->getType() << (*FoundP)->getType(); |
| 3409 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 3410 | << (*FoundP)->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3411 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3412 | } |
| 3413 | } |
| 3414 | |
| 3415 | // Check variadic/non-variadic. |
| 3416 | // Check the number of parameters. |
| 3417 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| 3418 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) |
| 3419 | << D->isInstanceMethod() << Name; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3420 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3421 | diag::note_odr_objc_method_here) |
| 3422 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3423 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3424 | } |
| 3425 | |
| 3426 | // FIXME: Any other bits we need to merge? |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3427 | return Importer.MapImported(D, FoundMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3428 | } |
| 3429 | } |
| 3430 | |
| 3431 | // Import the result type. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3432 | QualType ResultTy = Importer.Import(D->getReturnType()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3433 | if (ResultTy.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3434 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3435 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3436 | TypeSourceInfo *ReturnTInfo = Importer.Import(D->getReturnTypeSourceInfo()); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3437 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3438 | ObjCMethodDecl *ToMethod; |
| 3439 | if (GetImportedOrCreateDecl( |
| 3440 | ToMethod, D, Importer.getToContext(), Loc, |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 3441 | Importer.Import(D->getEndLoc()), Name.getObjCSelector(), ResultTy, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3442 | ReturnTInfo, DC, D->isInstanceMethod(), D->isVariadic(), |
| 3443 | D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 3444 | D->getImplementationControl(), D->hasRelatedResultType())) |
| 3445 | return ToMethod; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3446 | |
| 3447 | // FIXME: When we decide to merge method definitions, we'll need to |
| 3448 | // deal with implicit parameters. |
| 3449 | |
| 3450 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3451 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3452 | for (auto *FromP : D->parameters()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3453 | auto *ToP = cast_or_null<ParmVarDecl>(Importer.Import(FromP)); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3454 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3455 | return nullptr; |
| 3456 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3457 | ToParams.push_back(ToP); |
| 3458 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3459 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3460 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3461 | for (auto *ToParam : ToParams) { |
| 3462 | ToParam->setOwningFunction(ToMethod); |
| 3463 | ToMethod->addDeclInternal(ToParam); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3464 | } |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3465 | |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 3466 | SmallVector<SourceLocation, 12> SelLocs; |
| 3467 | D->getSelectorLocs(SelLocs); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3468 | for (auto &Loc : SelLocs) |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3469 | Loc = Importer.Import(Loc); |
| 3470 | |
| 3471 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, SelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3472 | |
| 3473 | ToMethod->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3474 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3475 | return ToMethod; |
| 3476 | } |
| 3477 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3478 | Decl *ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| 3479 | // Import the major distinguishing characteristics of a category. |
| 3480 | DeclContext *DC, *LexicalDC; |
| 3481 | DeclarationName Name; |
| 3482 | SourceLocation Loc; |
| 3483 | NamedDecl *ToD; |
| 3484 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3485 | return nullptr; |
| 3486 | if (ToD) |
| 3487 | return ToD; |
| 3488 | |
| 3489 | TypeSourceInfo *BoundInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3490 | if (!BoundInfo) |
| 3491 | return nullptr; |
| 3492 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3493 | ObjCTypeParamDecl *Result; |
| 3494 | if (GetImportedOrCreateDecl( |
| 3495 | Result, D, Importer.getToContext(), DC, D->getVariance(), |
| 3496 | Importer.Import(D->getVarianceLoc()), D->getIndex(), |
| 3497 | Importer.Import(D->getLocation()), Name.getAsIdentifierInfo(), |
| 3498 | Importer.Import(D->getColonLoc()), BoundInfo)) |
| 3499 | return Result; |
| 3500 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3501 | Result->setLexicalDeclContext(LexicalDC); |
| 3502 | return Result; |
| 3503 | } |
| 3504 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3505 | Decl *ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| 3506 | // Import the major distinguishing characteristics of a category. |
| 3507 | DeclContext *DC, *LexicalDC; |
| 3508 | DeclarationName Name; |
| 3509 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3510 | NamedDecl *ToD; |
| 3511 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3512 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3513 | if (ToD) |
| 3514 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3515 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3516 | auto *ToInterface = |
| 3517 | cast_or_null<ObjCInterfaceDecl>(Importer.Import(D->getClassInterface())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3518 | if (!ToInterface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3519 | return nullptr; |
| 3520 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3521 | // Determine if we've already encountered this category. |
| 3522 | ObjCCategoryDecl *MergeWithCategory |
| 3523 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 3524 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 3525 | if (!ToCategory) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3526 | |
| 3527 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, |
| 3528 | Importer.Import(D->getAtStartLoc()), Loc, |
| 3529 | Importer.Import(D->getCategoryNameLoc()), |
| 3530 | Name.getAsIdentifierInfo(), ToInterface, |
| 3531 | /*TypeParamList=*/nullptr, |
| 3532 | Importer.Import(D->getIvarLBraceLoc()), |
| 3533 | Importer.Import(D->getIvarRBraceLoc()))) |
| 3534 | return ToCategory; |
| 3535 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3536 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3537 | LexicalDC->addDeclInternal(ToCategory); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3538 | // Import the type parameter list after calling Imported, to avoid |
| 3539 | // loops when bringing in their DeclContext. |
| 3540 | ToCategory->setTypeParamList(ImportObjCTypeParamList( |
| 3541 | D->getTypeParamList())); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3542 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3543 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3544 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3545 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3546 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 3547 | = D->protocol_loc_begin(); |
| 3548 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 3549 | FromProtoEnd = D->protocol_end(); |
| 3550 | FromProto != FromProtoEnd; |
| 3551 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3552 | auto *ToProto = |
| 3553 | cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3554 | if (!ToProto) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3555 | return nullptr; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3556 | Protocols.push_back(ToProto); |
| 3557 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3558 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3559 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3560 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3561 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 3562 | ProtocolLocs.data(), Importer.getToContext()); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3563 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3564 | Importer.MapImported(D, ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3565 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3566 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3567 | // Import all of the members of this category. |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 3568 | ImportDeclContext(D); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3569 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3570 | // If we have an implementation, import it as well. |
| 3571 | if (D->getImplementation()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3572 | auto *Impl = |
| 3573 | cast_or_null<ObjCCategoryImplDecl>( |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 3574 | Importer.Import(D->getImplementation())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3575 | if (!Impl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3576 | return nullptr; |
| 3577 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3578 | ToCategory->setImplementation(Impl); |
| 3579 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3580 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3581 | return ToCategory; |
| 3582 | } |
| 3583 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3584 | bool ASTNodeImporter::ImportDefinition(ObjCProtocolDecl *From, |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3585 | ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3586 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3587 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3588 | if (shouldForceImportDeclContext(Kind)) |
| 3589 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3590 | return false; |
| 3591 | } |
| 3592 | |
| 3593 | // Start the protocol definition |
| 3594 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3595 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3596 | // Import protocols |
| 3597 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3598 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3599 | ObjCProtocolDecl::protocol_loc_iterator |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3600 | FromProtoLoc = From->protocol_loc_begin(); |
| 3601 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3602 | FromProtoEnd = From->protocol_end(); |
| 3603 | FromProto != FromProtoEnd; |
| 3604 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3605 | auto *ToProto = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3606 | if (!ToProto) |
| 3607 | return true; |
| 3608 | Protocols.push_back(ToProto); |
| 3609 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3610 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3611 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3612 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3613 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 3614 | ProtocolLocs.data(), Importer.getToContext()); |
| 3615 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3616 | if (shouldForceImportDeclContext(Kind)) { |
| 3617 | // Import all of the members of this protocol. |
| 3618 | ImportDeclContext(From, /*ForceImport=*/true); |
| 3619 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3620 | return false; |
| 3621 | } |
| 3622 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3623 | Decl *ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3624 | // If this protocol has a definition in the translation unit we're coming |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3625 | // from, but this particular declaration is not that definition, import the |
| 3626 | // definition and map to that. |
| 3627 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 3628 | if (Definition && Definition != D) { |
| 3629 | Decl *ImportedDef = Importer.Import(Definition); |
| 3630 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3631 | return nullptr; |
| 3632 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3633 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3634 | } |
| 3635 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3636 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3637 | DeclContext *DC, *LexicalDC; |
| 3638 | DeclarationName Name; |
| 3639 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3640 | NamedDecl *ToD; |
| 3641 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3642 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3643 | if (ToD) |
| 3644 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3645 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3646 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3647 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3648 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3649 | for (auto *FoundDecl : FoundDecls) { |
| 3650 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3651 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3652 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3653 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3654 | break; |
| 3655 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3656 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3657 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3658 | if (!ToProto) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3659 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, |
| 3660 | Name.getAsIdentifierInfo(), Loc, |
| 3661 | Importer.Import(D->getAtStartLoc()), |
| 3662 | /*PrevDecl=*/nullptr)) |
| 3663 | return ToProto; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3664 | ToProto->setLexicalDeclContext(LexicalDC); |
| 3665 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3666 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3667 | |
| 3668 | Importer.MapImported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3669 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3670 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToProto)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3671 | return nullptr; |
| 3672 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3673 | return ToProto; |
| 3674 | } |
| 3675 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3676 | Decl *ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 3677 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3678 | DeclContext *LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3679 | |
| 3680 | SourceLocation ExternLoc = Importer.Import(D->getExternLoc()); |
| 3681 | SourceLocation LangLoc = Importer.Import(D->getLocation()); |
| 3682 | |
| 3683 | bool HasBraces = D->hasBraces(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3684 | |
| 3685 | LinkageSpecDecl *ToLinkageSpec; |
| 3686 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, |
| 3687 | ExternLoc, LangLoc, D->getLanguage(), HasBraces)) |
| 3688 | return ToLinkageSpec; |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3689 | |
| 3690 | if (HasBraces) { |
| 3691 | SourceLocation RBraceLoc = Importer.Import(D->getRBraceLoc()); |
| 3692 | ToLinkageSpec->setRBraceLoc(RBraceLoc); |
| 3693 | } |
| 3694 | |
| 3695 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 3696 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 3697 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3698 | return ToLinkageSpec; |
| 3699 | } |
| 3700 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3701 | Decl *ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
| 3702 | DeclContext *DC, *LexicalDC; |
| 3703 | DeclarationName Name; |
| 3704 | SourceLocation Loc; |
| 3705 | NamedDecl *ToD = nullptr; |
| 3706 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3707 | return nullptr; |
| 3708 | if (ToD) |
| 3709 | return ToD; |
| 3710 | |
| 3711 | DeclarationNameInfo NameInfo(Name, |
| 3712 | Importer.Import(D->getNameInfo().getLoc())); |
| 3713 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 3714 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3715 | UsingDecl *ToUsing; |
| 3716 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| 3717 | Importer.Import(D->getUsingLoc()), |
| 3718 | Importer.Import(D->getQualifierLoc()), NameInfo, |
| 3719 | D->hasTypename())) |
| 3720 | return ToUsing; |
| 3721 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3722 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 3723 | LexicalDC->addDeclInternal(ToUsing); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3724 | |
| 3725 | if (NamedDecl *FromPattern = |
| 3726 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3727 | if (auto *ToPattern = |
| 3728 | dyn_cast_or_null<NamedDecl>(Importer.Import(FromPattern))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3729 | Importer.getToContext().setInstantiatedFromUsingDecl(ToUsing, ToPattern); |
| 3730 | else |
| 3731 | return nullptr; |
| 3732 | } |
| 3733 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3734 | for (auto *FromShadow : D->shadows()) { |
| 3735 | if (auto *ToShadow = |
| 3736 | dyn_cast_or_null<UsingShadowDecl>(Importer.Import(FromShadow))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3737 | ToUsing->addShadowDecl(ToShadow); |
| 3738 | else |
| 3739 | // FIXME: We return a nullptr here but the definition is already created |
| 3740 | // and available with lookups. How to fix this?.. |
| 3741 | return nullptr; |
| 3742 | } |
| 3743 | return ToUsing; |
| 3744 | } |
| 3745 | |
| 3746 | Decl *ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| 3747 | DeclContext *DC, *LexicalDC; |
| 3748 | DeclarationName Name; |
| 3749 | SourceLocation Loc; |
| 3750 | NamedDecl *ToD = nullptr; |
| 3751 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3752 | return nullptr; |
| 3753 | if (ToD) |
| 3754 | return ToD; |
| 3755 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3756 | auto *ToUsing = dyn_cast_or_null<UsingDecl>( |
| 3757 | Importer.Import(D->getUsingDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3758 | if (!ToUsing) |
| 3759 | return nullptr; |
| 3760 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3761 | auto *ToTarget = dyn_cast_or_null<NamedDecl>( |
| 3762 | Importer.Import(D->getTargetDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3763 | if (!ToTarget) |
| 3764 | return nullptr; |
| 3765 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3766 | UsingShadowDecl *ToShadow; |
| 3767 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, |
| 3768 | ToUsing, ToTarget)) |
| 3769 | return ToShadow; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3770 | |
| 3771 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 3772 | ToShadow->setAccess(D->getAccess()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3773 | |
| 3774 | if (UsingShadowDecl *FromPattern = |
| 3775 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3776 | if (auto *ToPattern = |
| 3777 | dyn_cast_or_null<UsingShadowDecl>(Importer.Import(FromPattern))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3778 | Importer.getToContext().setInstantiatedFromUsingShadowDecl(ToShadow, |
| 3779 | ToPattern); |
| 3780 | else |
| 3781 | // FIXME: We return a nullptr here but the definition is already created |
| 3782 | // and available with lookups. How to fix this?.. |
| 3783 | return nullptr; |
| 3784 | } |
| 3785 | |
| 3786 | LexicalDC->addDeclInternal(ToShadow); |
| 3787 | |
| 3788 | return ToShadow; |
| 3789 | } |
| 3790 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3791 | Decl *ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 3792 | DeclContext *DC, *LexicalDC; |
| 3793 | DeclarationName Name; |
| 3794 | SourceLocation Loc; |
| 3795 | NamedDecl *ToD = nullptr; |
| 3796 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3797 | return nullptr; |
| 3798 | if (ToD) |
| 3799 | return ToD; |
| 3800 | |
| 3801 | DeclContext *ToComAncestor = Importer.ImportContext(D->getCommonAncestor()); |
| 3802 | if (!ToComAncestor) |
| 3803 | return nullptr; |
| 3804 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3805 | auto *ToNominated = cast_or_null<NamespaceDecl>( |
| 3806 | Importer.Import(D->getNominatedNamespace())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3807 | if (!ToNominated) |
| 3808 | return nullptr; |
| 3809 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3810 | UsingDirectiveDecl *ToUsingDir; |
| 3811 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, |
| 3812 | Importer.Import(D->getUsingLoc()), |
| 3813 | Importer.Import(D->getNamespaceKeyLocation()), |
| 3814 | Importer.Import(D->getQualifierLoc()), |
| 3815 | Importer.Import(D->getIdentLocation()), |
| 3816 | ToNominated, ToComAncestor)) |
| 3817 | return ToUsingDir; |
| 3818 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3819 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 3820 | LexicalDC->addDeclInternal(ToUsingDir); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3821 | |
| 3822 | return ToUsingDir; |
| 3823 | } |
| 3824 | |
| 3825 | Decl *ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
| 3826 | UnresolvedUsingValueDecl *D) { |
| 3827 | DeclContext *DC, *LexicalDC; |
| 3828 | DeclarationName Name; |
| 3829 | SourceLocation Loc; |
| 3830 | NamedDecl *ToD = nullptr; |
| 3831 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3832 | return nullptr; |
| 3833 | if (ToD) |
| 3834 | return ToD; |
| 3835 | |
| 3836 | DeclarationNameInfo NameInfo(Name, Importer.Import(D->getNameInfo().getLoc())); |
| 3837 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 3838 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3839 | UnresolvedUsingValueDecl *ToUsingValue; |
| 3840 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, |
| 3841 | Importer.Import(D->getUsingLoc()), |
| 3842 | Importer.Import(D->getQualifierLoc()), NameInfo, |
| 3843 | Importer.Import(D->getEllipsisLoc()))) |
| 3844 | return ToUsingValue; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3845 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3846 | ToUsingValue->setAccess(D->getAccess()); |
| 3847 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 3848 | LexicalDC->addDeclInternal(ToUsingValue); |
| 3849 | |
| 3850 | return ToUsingValue; |
| 3851 | } |
| 3852 | |
| 3853 | Decl *ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
| 3854 | UnresolvedUsingTypenameDecl *D) { |
| 3855 | DeclContext *DC, *LexicalDC; |
| 3856 | DeclarationName Name; |
| 3857 | SourceLocation Loc; |
| 3858 | NamedDecl *ToD = nullptr; |
| 3859 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3860 | return nullptr; |
| 3861 | if (ToD) |
| 3862 | return ToD; |
| 3863 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3864 | UnresolvedUsingTypenameDecl *ToUsing; |
| 3865 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| 3866 | Importer.Import(D->getUsingLoc()), |
| 3867 | Importer.Import(D->getTypenameLoc()), |
| 3868 | Importer.Import(D->getQualifierLoc()), Loc, Name, |
| 3869 | Importer.Import(D->getEllipsisLoc()))) |
| 3870 | return ToUsing; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3871 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3872 | ToUsing->setAccess(D->getAccess()); |
| 3873 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 3874 | LexicalDC->addDeclInternal(ToUsing); |
| 3875 | |
| 3876 | return ToUsing; |
| 3877 | } |
| 3878 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3879 | bool ASTNodeImporter::ImportDefinition(ObjCInterfaceDecl *From, |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3880 | ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3881 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3882 | if (To->getDefinition()) { |
| 3883 | // Check consistency of superclass. |
| 3884 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 3885 | if (FromSuper) { |
| 3886 | FromSuper = cast_or_null<ObjCInterfaceDecl>(Importer.Import(FromSuper)); |
| 3887 | if (!FromSuper) |
| 3888 | return true; |
| 3889 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3890 | |
| 3891 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3892 | if ((bool)FromSuper != (bool)ToSuper || |
| 3893 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3894 | Importer.ToDiag(To->getLocation(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3895 | diag::err_odr_objc_superclass_inconsistent) |
| 3896 | << To->getDeclName(); |
| 3897 | if (ToSuper) |
| 3898 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 3899 | << To->getSuperClass()->getDeclName(); |
| 3900 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3901 | Importer.ToDiag(To->getLocation(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3902 | diag::note_odr_objc_missing_superclass); |
| 3903 | if (From->getSuperClass()) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3904 | Importer.FromDiag(From->getSuperClassLoc(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3905 | diag::note_odr_objc_superclass) |
| 3906 | << From->getSuperClass()->getDeclName(); |
| 3907 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3908 | Importer.FromDiag(From->getLocation(), |
| 3909 | diag::note_odr_objc_missing_superclass); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3910 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3911 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3912 | if (shouldForceImportDeclContext(Kind)) |
| 3913 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3914 | return false; |
| 3915 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3916 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3917 | // Start the definition. |
| 3918 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3919 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3920 | // If this class has a superclass, import it. |
| 3921 | if (From->getSuperClass()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 3922 | TypeSourceInfo *SuperTInfo = Importer.Import(From->getSuperClassTInfo()); |
| 3923 | if (!SuperTInfo) |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3924 | return true; |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 3925 | |
| 3926 | To->setSuperClass(SuperTInfo); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3927 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3928 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3929 | // Import protocols |
| 3930 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3931 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3932 | ObjCInterfaceDecl::protocol_loc_iterator |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3933 | FromProtoLoc = From->protocol_loc_begin(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3934 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3935 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3936 | FromProtoEnd = From->protocol_end(); |
| 3937 | FromProto != FromProtoEnd; |
| 3938 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3939 | auto *ToProto = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3940 | if (!ToProto) |
| 3941 | return true; |
| 3942 | Protocols.push_back(ToProto); |
| 3943 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3944 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3945 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3946 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3947 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 3948 | ProtocolLocs.data(), Importer.getToContext()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3949 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3950 | // Import categories. When the categories themselves are imported, they'll |
| 3951 | // hook themselves into this interface. |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 3952 | for (auto *Cat : From->known_categories()) |
| 3953 | Importer.Import(Cat); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3954 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3955 | // If we have an @implementation, import it as well. |
| 3956 | if (From->getImplementation()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3957 | auto *Impl = cast_or_null<ObjCImplementationDecl>( |
| 3958 | Importer.Import(From->getImplementation())); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3959 | if (!Impl) |
| 3960 | return true; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3961 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3962 | To->setImplementation(Impl); |
| 3963 | } |
| 3964 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3965 | if (shouldForceImportDeclContext(Kind)) { |
| 3966 | // Import all of the members of this class. |
| 3967 | ImportDeclContext(From, /*ForceImport=*/true); |
| 3968 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3969 | return false; |
| 3970 | } |
| 3971 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3972 | ObjCTypeParamList * |
| 3973 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 3974 | if (!list) |
| 3975 | return nullptr; |
| 3976 | |
| 3977 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
| 3978 | for (auto fromTypeParam : *list) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3979 | auto *toTypeParam = cast_or_null<ObjCTypeParamDecl>( |
| 3980 | Importer.Import(fromTypeParam)); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3981 | if (!toTypeParam) |
| 3982 | return nullptr; |
| 3983 | |
| 3984 | toTypeParams.push_back(toTypeParam); |
| 3985 | } |
| 3986 | |
| 3987 | return ObjCTypeParamList::create(Importer.getToContext(), |
| 3988 | Importer.Import(list->getLAngleLoc()), |
| 3989 | toTypeParams, |
| 3990 | Importer.Import(list->getRAngleLoc())); |
| 3991 | } |
| 3992 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3993 | Decl *ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3994 | // If this class has a definition in the translation unit we're coming from, |
| 3995 | // but this particular declaration is not that definition, import the |
| 3996 | // definition and map to that. |
| 3997 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 3998 | if (Definition && Definition != D) { |
| 3999 | Decl *ImportedDef = Importer.Import(Definition); |
| 4000 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4001 | return nullptr; |
| 4002 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4003 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4004 | } |
| 4005 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4006 | // Import the major distinguishing characteristics of an @interface. |
| 4007 | DeclContext *DC, *LexicalDC; |
| 4008 | DeclarationName Name; |
| 4009 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4010 | NamedDecl *ToD; |
| 4011 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4012 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4013 | if (ToD) |
| 4014 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4015 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4016 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4017 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4018 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4019 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4020 | for (auto *FoundDecl : FoundDecls) { |
| 4021 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4022 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4023 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4024 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4025 | break; |
| 4026 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4027 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4028 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4029 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4030 | if (!ToIface) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4031 | if (GetImportedOrCreateDecl( |
| 4032 | ToIface, D, Importer.getToContext(), DC, |
| 4033 | Importer.Import(D->getAtStartLoc()), Name.getAsIdentifierInfo(), |
| 4034 | /*TypeParamList=*/nullptr, |
| 4035 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) |
| 4036 | return ToIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4037 | ToIface->setLexicalDeclContext(LexicalDC); |
| 4038 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4039 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4040 | Importer.MapImported(D, ToIface); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4041 | // Import the type parameter list after calling Imported, to avoid |
| 4042 | // loops when bringing in their DeclContext. |
| 4043 | ToIface->setTypeParamList(ImportObjCTypeParamList( |
| 4044 | D->getTypeParamListAsWritten())); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4045 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4046 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToIface)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4047 | return nullptr; |
| 4048 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4049 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4050 | } |
| 4051 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4052 | Decl *ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4053 | auto *Category = cast_or_null<ObjCCategoryDecl>( |
| 4054 | Importer.Import(D->getCategoryDecl())); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4055 | if (!Category) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4056 | return nullptr; |
| 4057 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4058 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 4059 | if (!ToImpl) { |
| 4060 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 4061 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4062 | return nullptr; |
| 4063 | |
Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 4064 | SourceLocation CategoryNameLoc = Importer.Import(D->getCategoryNameLoc()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4065 | if (GetImportedOrCreateDecl( |
| 4066 | ToImpl, D, Importer.getToContext(), DC, |
| 4067 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), |
| 4068 | Importer.Import(D->getLocation()), |
| 4069 | Importer.Import(D->getAtStartLoc()), CategoryNameLoc)) |
| 4070 | return ToImpl; |
| 4071 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4072 | DeclContext *LexicalDC = DC; |
| 4073 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4074 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4075 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4076 | return nullptr; |
| 4077 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4078 | ToImpl->setLexicalDeclContext(LexicalDC); |
| 4079 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4080 | |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4081 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4082 | Category->setImplementation(ToImpl); |
| 4083 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4084 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4085 | Importer.MapImported(D, ToImpl); |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 4086 | ImportDeclContext(D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4087 | return ToImpl; |
| 4088 | } |
| 4089 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4090 | Decl *ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 4091 | // Find the corresponding interface. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4092 | auto *Iface = cast_or_null<ObjCInterfaceDecl>( |
| 4093 | Importer.Import(D->getClassInterface())); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4094 | if (!Iface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4095 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4096 | |
| 4097 | // Import the superclass, if any. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4098 | ObjCInterfaceDecl *Super = nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4099 | if (D->getSuperClass()) { |
| 4100 | Super = cast_or_null<ObjCInterfaceDecl>( |
| 4101 | Importer.Import(D->getSuperClass())); |
| 4102 | if (!Super) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4103 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4104 | } |
| 4105 | |
| 4106 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 4107 | if (!Impl) { |
| 4108 | // We haven't imported an implementation yet. Create a new @implementation |
| 4109 | // now. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4110 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), |
| 4111 | Importer.ImportContext(D->getDeclContext()), |
| 4112 | Iface, Super, Importer.Import(D->getLocation()), |
| 4113 | Importer.Import(D->getAtStartLoc()), |
| 4114 | Importer.Import(D->getSuperClassLoc()), |
| 4115 | Importer.Import(D->getIvarLBraceLoc()), |
| 4116 | Importer.Import(D->getIvarRBraceLoc()))) |
| 4117 | return Impl; |
| 4118 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4119 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4120 | DeclContext *LexicalDC |
| 4121 | = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4122 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4123 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4124 | Impl->setLexicalDeclContext(LexicalDC); |
| 4125 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4126 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4127 | // Associate the implementation with the class it implements. |
| 4128 | Iface->setImplementation(Impl); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4129 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4130 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4131 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4132 | |
| 4133 | // Verify that the existing @implementation has the same superclass. |
| 4134 | if ((Super && !Impl->getSuperClass()) || |
| 4135 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4136 | (Super && Impl->getSuperClass() && |
| 4137 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 4138 | Impl->getSuperClass()))) { |
| 4139 | Importer.ToDiag(Impl->getLocation(), |
| 4140 | diag::err_odr_objc_superclass_inconsistent) |
| 4141 | << Iface->getDeclName(); |
| 4142 | // FIXME: It would be nice to have the location of the superclass |
| 4143 | // below. |
| 4144 | if (Impl->getSuperClass()) |
| 4145 | Importer.ToDiag(Impl->getLocation(), |
| 4146 | diag::note_odr_objc_superclass) |
| 4147 | << Impl->getSuperClass()->getDeclName(); |
| 4148 | else |
| 4149 | Importer.ToDiag(Impl->getLocation(), |
| 4150 | diag::note_odr_objc_missing_superclass); |
| 4151 | if (D->getSuperClass()) |
| 4152 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4153 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4154 | << D->getSuperClass()->getDeclName(); |
| 4155 | else |
| 4156 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4157 | diag::note_odr_objc_missing_superclass); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4158 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4159 | } |
| 4160 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4161 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4162 | // Import all of the members of this @implementation. |
| 4163 | ImportDeclContext(D); |
| 4164 | |
| 4165 | return Impl; |
| 4166 | } |
| 4167 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4168 | Decl *ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| 4169 | // Import the major distinguishing characteristics of an @property. |
| 4170 | DeclContext *DC, *LexicalDC; |
| 4171 | DeclarationName Name; |
| 4172 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4173 | NamedDecl *ToD; |
| 4174 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4175 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4176 | if (ToD) |
| 4177 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4178 | |
| 4179 | // Check whether we have already imported this property. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4180 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4181 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4182 | for (auto *FoundDecl : FoundDecls) { |
| 4183 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4184 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4185 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4186 | FoundProp->getType())) { |
| 4187 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) |
| 4188 | << Name << D->getType() << FoundProp->getType(); |
| 4189 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 4190 | << FoundProp->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4191 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4192 | } |
| 4193 | |
| 4194 | // FIXME: Check property attributes, getters, setters, etc.? |
| 4195 | |
| 4196 | // Consider these properties to be equivalent. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4197 | Importer.MapImported(D, FoundProp); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4198 | return FoundProp; |
| 4199 | } |
| 4200 | } |
| 4201 | |
| 4202 | // Import the type. |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 4203 | TypeSourceInfo *TSI = Importer.Import(D->getTypeSourceInfo()); |
| 4204 | if (!TSI) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4205 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4206 | |
| 4207 | // Create the new property. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4208 | ObjCPropertyDecl *ToProperty; |
| 4209 | if (GetImportedOrCreateDecl( |
| 4210 | ToProperty, D, Importer.getToContext(), DC, Loc, |
| 4211 | Name.getAsIdentifierInfo(), Importer.Import(D->getAtLoc()), |
| 4212 | Importer.Import(D->getLParenLoc()), Importer.Import(D->getType()), |
| 4213 | TSI, D->getPropertyImplementation())) |
| 4214 | return ToProperty; |
| 4215 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4216 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4217 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4218 | |
| 4219 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4220 | ToProperty->setPropertyAttributesAsWritten( |
| 4221 | D->getPropertyAttributesAsWritten()); |
Argyrios Kyrtzidis | 194b28e | 2017-03-16 18:25:40 +0000 | [diff] [blame] | 4222 | ToProperty->setGetterName(Importer.Import(D->getGetterName()), |
| 4223 | Importer.Import(D->getGetterNameLoc())); |
| 4224 | ToProperty->setSetterName(Importer.Import(D->getSetterName()), |
| 4225 | Importer.Import(D->getSetterNameLoc())); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4226 | ToProperty->setGetterMethodDecl( |
| 4227 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getGetterMethodDecl()))); |
| 4228 | ToProperty->setSetterMethodDecl( |
| 4229 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getSetterMethodDecl()))); |
| 4230 | ToProperty->setPropertyIvarDecl( |
| 4231 | cast_or_null<ObjCIvarDecl>(Importer.Import(D->getPropertyIvarDecl()))); |
| 4232 | return ToProperty; |
| 4233 | } |
| 4234 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4235 | Decl *ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4236 | auto *Property = cast_or_null<ObjCPropertyDecl>( |
| 4237 | Importer.Import(D->getPropertyDecl())); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4238 | if (!Property) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4239 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4240 | |
| 4241 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 4242 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4243 | return nullptr; |
| 4244 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4245 | // Import the lexical declaration context. |
| 4246 | DeclContext *LexicalDC = DC; |
| 4247 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4248 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4249 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4250 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4251 | } |
| 4252 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4253 | auto *InImpl = dyn_cast<ObjCImplDecl>(LexicalDC); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4254 | if (!InImpl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4255 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4256 | |
| 4257 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4258 | ObjCIvarDecl *Ivar = nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4259 | if (D->getPropertyIvarDecl()) { |
| 4260 | Ivar = cast_or_null<ObjCIvarDecl>( |
| 4261 | Importer.Import(D->getPropertyIvarDecl())); |
| 4262 | if (!Ivar) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4263 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4264 | } |
| 4265 | |
| 4266 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 4267 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 4268 | Property->getQueryKind()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4269 | if (!ToImpl) { |
| 4270 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4271 | Importer.Import(D->getBeginLoc()), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4272 | Importer.Import(D->getLocation()), Property, |
| 4273 | D->getPropertyImplementation(), Ivar, |
| 4274 | Importer.Import(D->getPropertyIvarDeclLoc()))) |
| 4275 | return ToImpl; |
| 4276 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4277 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4278 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4279 | } else { |
| 4280 | // Check that we have the same kind of property implementation (@synthesize |
| 4281 | // vs. @dynamic). |
| 4282 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4283 | Importer.ToDiag(ToImpl->getLocation(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4284 | diag::err_odr_objc_property_impl_kind_inconsistent) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4285 | << Property->getDeclName() |
| 4286 | << (ToImpl->getPropertyImplementation() |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4287 | == ObjCPropertyImplDecl::Dynamic); |
| 4288 | Importer.FromDiag(D->getLocation(), |
| 4289 | diag::note_odr_objc_property_impl_kind) |
| 4290 | << D->getPropertyDecl()->getDeclName() |
| 4291 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4292 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4293 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4294 | |
| 4295 | // For @synthesize, check that we have the same |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4296 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 4297 | Ivar != ToImpl->getPropertyIvarDecl()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4298 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4299 | diag::err_odr_objc_synthesize_ivar_inconsistent) |
| 4300 | << Property->getDeclName() |
| 4301 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 4302 | << Ivar->getDeclName(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4303 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4304 | diag::note_odr_objc_synthesize_ivar_here) |
| 4305 | << D->getPropertyIvarDecl()->getDeclName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4306 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4307 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4308 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4309 | // Merge the existing implementation with the new implementation. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4310 | Importer.MapImported(D, ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4311 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4312 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4313 | return ToImpl; |
| 4314 | } |
| 4315 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4316 | Decl *ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| 4317 | // For template arguments, we adopt the translation unit as our declaration |
| 4318 | // context. This context will be fixed when the actual template declaration |
| 4319 | // is created. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4320 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4321 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4322 | TemplateTypeParmDecl *ToD = nullptr; |
| 4323 | (void)GetImportedOrCreateDecl( |
| 4324 | ToD, D, Importer.getToContext(), |
| 4325 | Importer.getToContext().getTranslationUnitDecl(), |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4326 | Importer.Import(D->getBeginLoc()), Importer.Import(D->getLocation()), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4327 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), |
| 4328 | D->wasDeclaredWithTypename(), D->isParameterPack()); |
| 4329 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4330 | } |
| 4331 | |
| 4332 | Decl * |
| 4333 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| 4334 | // Import the name of this declaration. |
| 4335 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 4336 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4337 | return nullptr; |
| 4338 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4339 | // Import the location of this declaration. |
| 4340 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 4341 | |
| 4342 | // Import the type of this declaration. |
| 4343 | QualType T = Importer.Import(D->getType()); |
| 4344 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4345 | return nullptr; |
| 4346 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4347 | // Import type-source information. |
| 4348 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 4349 | if (D->getTypeSourceInfo() && !TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4350 | return nullptr; |
| 4351 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4352 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4353 | |
| 4354 | NonTypeTemplateParmDecl *ToD = nullptr; |
| 4355 | (void)GetImportedOrCreateDecl( |
| 4356 | ToD, D, Importer.getToContext(), |
| 4357 | Importer.getToContext().getTranslationUnitDecl(), |
| 4358 | Importer.Import(D->getInnerLocStart()), Loc, D->getDepth(), |
| 4359 | D->getPosition(), Name.getAsIdentifierInfo(), T, D->isParameterPack(), |
| 4360 | TInfo); |
| 4361 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4362 | } |
| 4363 | |
| 4364 | Decl * |
| 4365 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 4366 | // Import the name of this declaration. |
| 4367 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 4368 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4369 | return nullptr; |
| 4370 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4371 | // Import the location of this declaration. |
| 4372 | SourceLocation Loc = Importer.Import(D->getLocation()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4373 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4374 | // Import template parameters. |
| 4375 | TemplateParameterList *TemplateParams |
| 4376 | = ImportTemplateParameterList(D->getTemplateParameters()); |
| 4377 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4378 | return nullptr; |
| 4379 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4380 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4381 | |
| 4382 | TemplateTemplateParmDecl *ToD = nullptr; |
| 4383 | (void)GetImportedOrCreateDecl( |
| 4384 | ToD, D, Importer.getToContext(), |
| 4385 | Importer.getToContext().getTranslationUnitDecl(), Loc, D->getDepth(), |
| 4386 | D->getPosition(), D->isParameterPack(), Name.getAsIdentifierInfo(), |
| 4387 | TemplateParams); |
| 4388 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4389 | } |
| 4390 | |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4391 | // Returns the definition for a (forward) declaration of a ClassTemplateDecl, if |
| 4392 | // it has any definition in the redecl chain. |
| 4393 | static ClassTemplateDecl *getDefinition(ClassTemplateDecl *D) { |
| 4394 | CXXRecordDecl *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
| 4395 | if (!ToTemplatedDef) |
| 4396 | return nullptr; |
| 4397 | ClassTemplateDecl *TemplateWithDef = |
| 4398 | ToTemplatedDef->getDescribedClassTemplate(); |
| 4399 | return TemplateWithDef; |
| 4400 | } |
| 4401 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4402 | Decl *ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4403 | bool IsFriend = D->getFriendObjectKind() != Decl::FOK_None; |
| 4404 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4405 | // If this record has a definition in the translation unit we're coming from, |
| 4406 | // but this particular declaration is not that definition, import the |
| 4407 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4408 | auto *Definition = |
| 4409 | cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition()); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4410 | if (Definition && Definition != D->getTemplatedDecl() && !IsFriend) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4411 | Decl *ImportedDef |
| 4412 | = Importer.Import(Definition->getDescribedClassTemplate()); |
| 4413 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4414 | return nullptr; |
| 4415 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4416 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4417 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4418 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4419 | // Import the major distinguishing characteristics of this class template. |
| 4420 | DeclContext *DC, *LexicalDC; |
| 4421 | DeclarationName Name; |
| 4422 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4423 | NamedDecl *ToD; |
| 4424 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4425 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4426 | if (ToD) |
| 4427 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4428 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4429 | // We may already have a template of the same name; try to find and match it. |
| 4430 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4431 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4432 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4433 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4434 | for (auto *FoundDecl : FoundDecls) { |
| 4435 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4436 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4437 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4438 | Decl *Found = FoundDecl; |
| 4439 | if (auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found)) { |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4440 | |
| 4441 | // The class to be imported is a definition. |
| 4442 | if (D->isThisDeclarationADefinition()) { |
| 4443 | // Lookup will find the fwd decl only if that is more recent than the |
| 4444 | // definition. So, try to get the definition if that is available in |
| 4445 | // the redecl chain. |
| 4446 | ClassTemplateDecl *TemplateWithDef = getDefinition(FoundTemplate); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4447 | if (TemplateWithDef) |
| 4448 | FoundTemplate = TemplateWithDef; |
| 4449 | else |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4450 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4451 | } |
| 4452 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4453 | if (IsStructuralMatch(D, FoundTemplate)) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4454 | if (!IsFriend) { |
| 4455 | Importer.MapImported(D->getTemplatedDecl(), |
| 4456 | FoundTemplate->getTemplatedDecl()); |
| 4457 | return Importer.MapImported(D, FoundTemplate); |
| 4458 | } |
Aleksei Sidorin | 761c224 | 2018-05-15 11:09:07 +0000 | [diff] [blame] | 4459 | |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4460 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4461 | } |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4462 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4463 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4464 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4465 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4466 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4467 | if (!ConflictingDecls.empty()) { |
| 4468 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4469 | ConflictingDecls.data(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4470 | ConflictingDecls.size()); |
| 4471 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4472 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4473 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4474 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4475 | } |
| 4476 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4477 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 4478 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4479 | // Create the declaration that is being templated. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4480 | auto *ToTemplated = cast_or_null<CXXRecordDecl>( |
| 4481 | Importer.Import(FromTemplated)); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4482 | if (!ToTemplated) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4483 | return nullptr; |
| 4484 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4485 | // Create the class template declaration itself. |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4486 | TemplateParameterList *TemplateParams = |
| 4487 | ImportTemplateParameterList(D->getTemplateParameters()); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4488 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4489 | return nullptr; |
| 4490 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4491 | ClassTemplateDecl *D2; |
| 4492 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, |
| 4493 | TemplateParams, ToTemplated)) |
| 4494 | return D2; |
| 4495 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4496 | ToTemplated->setDescribedClassTemplate(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4497 | |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4498 | if (ToTemplated->getPreviousDecl()) { |
| 4499 | assert( |
| 4500 | ToTemplated->getPreviousDecl()->getDescribedClassTemplate() && |
| 4501 | "Missing described template"); |
| 4502 | D2->setPreviousDecl( |
| 4503 | ToTemplated->getPreviousDecl()->getDescribedClassTemplate()); |
| 4504 | } |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4505 | D2->setAccess(D->getAccess()); |
| 4506 | D2->setLexicalDeclContext(LexicalDC); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4507 | if (!IsFriend) |
| 4508 | LexicalDC->addDeclInternal(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4509 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4510 | if (FromTemplated->isCompleteDefinition() && |
| 4511 | !ToTemplated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4512 | // FIXME: Import definition! |
| 4513 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4514 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4515 | return D2; |
| 4516 | } |
| 4517 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4518 | Decl *ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
| 4519 | ClassTemplateSpecializationDecl *D) { |
| 4520 | // If this record has a definition in the translation unit we're coming from, |
| 4521 | // but this particular declaration is not that definition, import the |
| 4522 | // definition and map to that. |
| 4523 | TagDecl *Definition = D->getDefinition(); |
| 4524 | if (Definition && Definition != D) { |
| 4525 | Decl *ImportedDef = Importer.Import(Definition); |
| 4526 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4527 | return nullptr; |
| 4528 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4529 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4530 | } |
| 4531 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4532 | auto *ClassTemplate = |
| 4533 | cast_or_null<ClassTemplateDecl>(Importer.Import( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4534 | D->getSpecializedTemplate())); |
| 4535 | if (!ClassTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4536 | return nullptr; |
| 4537 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4538 | // Import the context of this declaration. |
| 4539 | DeclContext *DC = ClassTemplate->getDeclContext(); |
| 4540 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4541 | return nullptr; |
| 4542 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4543 | DeclContext *LexicalDC = DC; |
| 4544 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4545 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4546 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4547 | return nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4548 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4549 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4550 | // Import the location of this declaration. |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4551 | SourceLocation StartLoc = Importer.Import(D->getBeginLoc()); |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 4552 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4553 | |
| 4554 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4555 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4556 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4557 | D->getTemplateArgs().size(), |
| 4558 | TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4559 | return nullptr; |
| 4560 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4561 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4562 | void *InsertPos = nullptr; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame^] | 4563 | ClassTemplateSpecializationDecl *D2 = nullptr; |
| 4564 | ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 4565 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); |
| 4566 | if (PartialSpec) |
| 4567 | D2 = ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos); |
| 4568 | else |
| 4569 | D2 = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
| 4570 | ClassTemplateSpecializationDecl * const PrevDecl = D2; |
| 4571 | RecordDecl *FoundDef = D2 ? D2->getDefinition() : nullptr; |
| 4572 | if (FoundDef) { |
| 4573 | if (!D->isCompleteDefinition()) { |
| 4574 | // The "From" translation unit only had a forward declaration; call it |
| 4575 | // the same declaration. |
| 4576 | // TODO Handle the redecl chain properly! |
| 4577 | return Importer.MapImported(D, FoundDef); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4578 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame^] | 4579 | |
| 4580 | if (IsStructuralMatch(D, FoundDef)) { |
| 4581 | |
| 4582 | Importer.MapImported(D, FoundDef); |
| 4583 | |
| 4584 | // Import those those default field initializers which have been |
| 4585 | // instantiated in the "From" context, but not in the "To" context. |
| 4586 | for (auto *FromField : D->fields()) |
| 4587 | Importer.Import(FromField); |
| 4588 | |
| 4589 | // Import those methods which have been instantiated in the |
| 4590 | // "From" context, but not in the "To" context. |
| 4591 | for (CXXMethodDecl *FromM : D->methods()) |
| 4592 | Importer.Import(FromM); |
| 4593 | |
| 4594 | // TODO Import instantiated default arguments. |
| 4595 | // TODO Import instantiated exception specifications. |
| 4596 | // |
| 4597 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint what |
| 4598 | // else could be fused during an AST merge. |
| 4599 | |
| 4600 | return FoundDef; |
| 4601 | } |
| 4602 | } else { // We either couldn't find any previous specialization in the "To" |
| 4603 | // context, or we found one but without definition. Let's create a |
| 4604 | // new specialization and register that at the class template. |
| 4605 | if (PartialSpec) { |
| 4606 | // Import TemplateArgumentListInfo. |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4607 | TemplateArgumentListInfo ToTAInfo; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4608 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 4609 | if (ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4610 | return nullptr; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4611 | |
| 4612 | QualType CanonInjType = Importer.Import( |
| 4613 | PartialSpec->getInjectedSpecializationType()); |
| 4614 | if (CanonInjType.isNull()) |
| 4615 | return nullptr; |
| 4616 | CanonInjType = CanonInjType.getCanonicalType(); |
| 4617 | |
| 4618 | TemplateParameterList *ToTPList = ImportTemplateParameterList( |
| 4619 | PartialSpec->getTemplateParameters()); |
| 4620 | if (!ToTPList && PartialSpec->getTemplateParameters()) |
| 4621 | return nullptr; |
| 4622 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4623 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( |
| 4624 | D2, D, Importer.getToContext(), D->getTagKind(), DC, StartLoc, |
| 4625 | IdLoc, ToTPList, ClassTemplate, |
| 4626 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame^] | 4627 | ToTAInfo, CanonInjType, |
| 4628 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4629 | return D2; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4630 | |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame^] | 4631 | // Update InsertPos, because preceding import calls may have invalidated |
| 4632 | // it by adding new specializations. |
| 4633 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos)) |
| 4634 | // Add this partial specialization to the class template. |
| 4635 | ClassTemplate->AddPartialSpecialization( |
| 4636 | cast<ClassTemplatePartialSpecializationDecl>(D2), InsertPos); |
| 4637 | |
| 4638 | } else { // Not a partial specialization. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4639 | if (GetImportedOrCreateDecl( |
| 4640 | D2, D, Importer.getToContext(), D->getTagKind(), DC, StartLoc, |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame^] | 4641 | IdLoc, ClassTemplate, TemplateArgs, PrevDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4642 | return D2; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame^] | 4643 | |
| 4644 | // Update InsertPos, because preceding import calls may have invalidated |
| 4645 | // it by adding new specializations. |
| 4646 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) |
| 4647 | // Add this specialization to the class template. |
| 4648 | ClassTemplate->AddSpecialization(D2, InsertPos); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4649 | } |
| 4650 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4651 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 4652 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4653 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4654 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4655 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4656 | if (auto *TSI = D->getTypeAsWritten()) { |
| 4657 | TypeSourceInfo *TInfo = Importer.Import(TSI); |
| 4658 | if (!TInfo) |
| 4659 | return nullptr; |
| 4660 | D2->setTypeAsWritten(TInfo); |
| 4661 | D2->setTemplateKeywordLoc(Importer.Import(D->getTemplateKeywordLoc())); |
| 4662 | D2->setExternLoc(Importer.Import(D->getExternLoc())); |
| 4663 | } |
| 4664 | |
| 4665 | SourceLocation POI = Importer.Import(D->getPointOfInstantiation()); |
| 4666 | if (POI.isValid()) |
| 4667 | D2->setPointOfInstantiation(POI); |
| 4668 | else if (D->getPointOfInstantiation().isValid()) |
| 4669 | return nullptr; |
| 4670 | |
| 4671 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 4672 | |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 4673 | // Set the context of this specialization/instantiation. |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4674 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 4675 | |
| 4676 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 4677 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 4678 | LexicalDC->addDeclInternal(D2); |
| 4679 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4680 | } |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4681 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4682 | return nullptr; |
| 4683 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4684 | return D2; |
| 4685 | } |
| 4686 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4687 | Decl *ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| 4688 | // If this variable has a definition in the translation unit we're coming |
| 4689 | // from, |
| 4690 | // but this particular declaration is not that definition, import the |
| 4691 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4692 | auto *Definition = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4693 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 4694 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 4695 | Decl *ImportedDef = Importer.Import(Definition->getDescribedVarTemplate()); |
| 4696 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4697 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4698 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4699 | return Importer.MapImported(D, ImportedDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4700 | } |
| 4701 | |
| 4702 | // Import the major distinguishing characteristics of this variable template. |
| 4703 | DeclContext *DC, *LexicalDC; |
| 4704 | DeclarationName Name; |
| 4705 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4706 | NamedDecl *ToD; |
| 4707 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4708 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4709 | if (ToD) |
| 4710 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4711 | |
| 4712 | // We may already have a template of the same name; try to find and match it. |
| 4713 | assert(!DC->isFunctionOrMethod() && |
| 4714 | "Variable templates cannot be declared at function scope"); |
| 4715 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 4716 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4717 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4718 | for (auto *FoundDecl : FoundDecls) { |
| 4719 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4720 | continue; |
| 4721 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4722 | Decl *Found = FoundDecl; |
| 4723 | if (auto *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4724 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 4725 | // The variable templates structurally match; call it the same template. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4726 | Importer.MapImported(D->getTemplatedDecl(), |
| 4727 | FoundTemplate->getTemplatedDecl()); |
| 4728 | return Importer.MapImported(D, FoundTemplate); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4729 | } |
| 4730 | } |
| 4731 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4732 | ConflictingDecls.push_back(FoundDecl); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | if (!ConflictingDecls.empty()) { |
| 4736 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 4737 | ConflictingDecls.data(), |
| 4738 | ConflictingDecls.size()); |
| 4739 | } |
| 4740 | |
| 4741 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4742 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4743 | |
| 4744 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 4745 | |
| 4746 | // Import the type. |
| 4747 | QualType T = Importer.Import(DTemplated->getType()); |
| 4748 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4749 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4750 | |
| 4751 | // Create the declaration that is being templated. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4752 | auto *ToTemplated = dyn_cast_or_null<VarDecl>(Importer.Import(DTemplated)); |
| 4753 | if (!ToTemplated) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4754 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4755 | |
| 4756 | // Create the variable template declaration itself. |
| 4757 | TemplateParameterList *TemplateParams = |
| 4758 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 4759 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4760 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4761 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4762 | VarTemplateDecl *ToVarTD; |
| 4763 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, |
| 4764 | Name, TemplateParams, ToTemplated)) |
| 4765 | return ToVarTD; |
| 4766 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4767 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4768 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4769 | ToVarTD->setAccess(D->getAccess()); |
| 4770 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 4771 | LexicalDC->addDeclInternal(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4772 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4773 | if (DTemplated->isThisDeclarationADefinition() && |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4774 | !ToTemplated->isThisDeclarationADefinition()) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4775 | // FIXME: Import definition! |
| 4776 | } |
| 4777 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4778 | return ToVarTD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4779 | } |
| 4780 | |
| 4781 | Decl *ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
| 4782 | VarTemplateSpecializationDecl *D) { |
| 4783 | // If this record has a definition in the translation unit we're coming from, |
| 4784 | // but this particular declaration is not that definition, import the |
| 4785 | // definition and map to that. |
| 4786 | VarDecl *Definition = D->getDefinition(); |
| 4787 | if (Definition && Definition != D) { |
| 4788 | Decl *ImportedDef = Importer.Import(Definition); |
| 4789 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4790 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4791 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4792 | return Importer.MapImported(D, ImportedDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4793 | } |
| 4794 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4795 | auto *VarTemplate = cast_or_null<VarTemplateDecl>( |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4796 | Importer.Import(D->getSpecializedTemplate())); |
| 4797 | if (!VarTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4798 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4799 | |
| 4800 | // Import the context of this declaration. |
| 4801 | DeclContext *DC = VarTemplate->getDeclContext(); |
| 4802 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4803 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4804 | |
| 4805 | DeclContext *LexicalDC = DC; |
| 4806 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4807 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4808 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4809 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4810 | } |
| 4811 | |
| 4812 | // Import the location of this declaration. |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4813 | SourceLocation StartLoc = Importer.Import(D->getBeginLoc()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4814 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
| 4815 | |
| 4816 | // Import template arguments. |
| 4817 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| 4818 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 4819 | D->getTemplateArgs().size(), TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4820 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4821 | |
| 4822 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4823 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4824 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 4825 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4826 | if (D2) { |
| 4827 | // We already have a variable template specialization with these template |
| 4828 | // arguments. |
| 4829 | |
| 4830 | // FIXME: Check for specialization vs. instantiation errors. |
| 4831 | |
| 4832 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 4833 | if (!D->isThisDeclarationADefinition() || |
| 4834 | IsStructuralMatch(D, FoundDef)) { |
| 4835 | // The record types structurally match, or the "from" translation |
| 4836 | // unit only had a forward declaration anyway; call it the same |
| 4837 | // variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4838 | return Importer.MapImported(D, FoundDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4839 | } |
| 4840 | } |
| 4841 | } else { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4842 | // Import the type. |
| 4843 | QualType T = Importer.Import(D->getType()); |
| 4844 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4845 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4846 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4847 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 4848 | if (D->getTypeSourceInfo() && !TInfo) |
| 4849 | return nullptr; |
| 4850 | |
| 4851 | TemplateArgumentListInfo ToTAInfo; |
| 4852 | if (ImportTemplateArgumentListInfo(D->getTemplateArgsInfo(), ToTAInfo)) |
| 4853 | return nullptr; |
| 4854 | |
| 4855 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4856 | // Create a new specialization. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4857 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 4858 | // Import TemplateArgumentListInfo |
| 4859 | TemplateArgumentListInfo ArgInfos; |
| 4860 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 4861 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
| 4862 | if (ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ArgInfos)) |
| 4863 | return nullptr; |
| 4864 | |
| 4865 | TemplateParameterList *ToTPList = ImportTemplateParameterList( |
| 4866 | FromPartial->getTemplateParameters()); |
| 4867 | if (!ToTPList) |
| 4868 | return nullptr; |
| 4869 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4870 | PartVarSpecDecl *ToPartial; |
| 4871 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, |
| 4872 | StartLoc, IdLoc, ToTPList, VarTemplate, T, |
| 4873 | TInfo, D->getStorageClass(), TemplateArgs, |
| 4874 | ArgInfos)) |
| 4875 | return ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4876 | |
| 4877 | auto *FromInst = FromPartial->getInstantiatedFromMember(); |
| 4878 | auto *ToInst = cast_or_null<PartVarSpecDecl>(Importer.Import(FromInst)); |
| 4879 | if (FromInst && !ToInst) |
| 4880 | return nullptr; |
| 4881 | |
| 4882 | ToPartial->setInstantiatedFromMember(ToInst); |
| 4883 | if (FromPartial->isMemberSpecialization()) |
| 4884 | ToPartial->setMemberSpecialization(); |
| 4885 | |
| 4886 | D2 = ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4887 | } else { // Full specialization |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4888 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, StartLoc, |
| 4889 | IdLoc, VarTemplate, T, TInfo, |
| 4890 | D->getStorageClass(), TemplateArgs)) |
| 4891 | return D2; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4892 | } |
| 4893 | |
| 4894 | SourceLocation POI = D->getPointOfInstantiation(); |
| 4895 | if (POI.isValid()) |
| 4896 | D2->setPointOfInstantiation(Importer.Import(POI)); |
| 4897 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4898 | D2->setSpecializationKind(D->getSpecializationKind()); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4899 | D2->setTemplateArgsInfo(ToTAInfo); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4900 | |
| 4901 | // Add this specialization to the class template. |
| 4902 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 4903 | |
| 4904 | // Import the qualifier, if any. |
| 4905 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
| 4906 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4907 | if (D->isConstexpr()) |
| 4908 | D2->setConstexpr(true); |
| 4909 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4910 | // Add the specialization to this context. |
| 4911 | D2->setLexicalDeclContext(LexicalDC); |
| 4912 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4913 | |
| 4914 | D2->setAccess(D->getAccess()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4915 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4916 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4917 | // NOTE: isThisDeclarationADefinition() can return DeclarationOnly even if |
| 4918 | // declaration has initializer. Should this be fixed in the AST?.. Anyway, |
| 4919 | // we have to check the declaration for initializer - otherwise, it won't be |
| 4920 | // imported. |
| 4921 | if ((D->isThisDeclarationADefinition() || D->hasInit()) && |
| 4922 | ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4923 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4924 | |
| 4925 | return D2; |
| 4926 | } |
| 4927 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4928 | Decl *ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 4929 | DeclContext *DC, *LexicalDC; |
| 4930 | DeclarationName Name; |
| 4931 | SourceLocation Loc; |
| 4932 | NamedDecl *ToD; |
| 4933 | |
| 4934 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4935 | return nullptr; |
| 4936 | |
| 4937 | if (ToD) |
| 4938 | return ToD; |
| 4939 | |
| 4940 | // Try to find a function in our own ("to") context with the same name, same |
| 4941 | // type, and in the same context as the function we're importing. |
| 4942 | if (!LexicalDC->isFunctionOrMethod()) { |
| 4943 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 4944 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 4945 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4946 | for (auto *FoundDecl : FoundDecls) { |
| 4947 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4948 | continue; |
| 4949 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4950 | if (auto *FoundFunction = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4951 | if (FoundFunction->hasExternalFormalLinkage() && |
| 4952 | D->hasExternalFormalLinkage()) { |
| 4953 | if (IsStructuralMatch(D, FoundFunction)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4954 | Importer.MapImported(D, FoundFunction); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4955 | // FIXME: Actually try to merge the body and other attributes. |
| 4956 | return FoundFunction; |
| 4957 | } |
| 4958 | } |
| 4959 | } |
| 4960 | } |
| 4961 | } |
| 4962 | |
| 4963 | TemplateParameterList *Params = |
| 4964 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 4965 | if (!Params) |
| 4966 | return nullptr; |
| 4967 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4968 | auto *TemplatedFD = |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4969 | cast_or_null<FunctionDecl>(Importer.Import(D->getTemplatedDecl())); |
| 4970 | if (!TemplatedFD) |
| 4971 | return nullptr; |
| 4972 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4973 | FunctionTemplateDecl *ToFunc; |
| 4974 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, |
| 4975 | Params, TemplatedFD)) |
| 4976 | return ToFunc; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4977 | |
| 4978 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| 4979 | ToFunc->setAccess(D->getAccess()); |
| 4980 | ToFunc->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4981 | |
| 4982 | LexicalDC->addDeclInternal(ToFunc); |
| 4983 | return ToFunc; |
| 4984 | } |
| 4985 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4986 | //---------------------------------------------------------------------------- |
| 4987 | // Import Statements |
| 4988 | //---------------------------------------------------------------------------- |
| 4989 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4990 | DeclGroupRef ASTNodeImporter::ImportDeclGroup(DeclGroupRef DG) { |
| 4991 | if (DG.isNull()) |
| 4992 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 4993 | size_t NumDecls = DG.end() - DG.begin(); |
| 4994 | SmallVector<Decl *, 1> ToDecls(NumDecls); |
| 4995 | auto &_Importer = this->Importer; |
| 4996 | std::transform(DG.begin(), DG.end(), ToDecls.begin(), |
| 4997 | [&_Importer](Decl *D) -> Decl * { |
| 4998 | return _Importer.Import(D); |
| 4999 | }); |
| 5000 | return DeclGroupRef::Create(Importer.getToContext(), |
| 5001 | ToDecls.begin(), |
| 5002 | NumDecls); |
| 5003 | } |
| 5004 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5005 | Stmt *ASTNodeImporter::VisitStmt(Stmt *S) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5006 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) |
| 5007 | << S->getStmtClassName(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5008 | return nullptr; |
| 5009 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5010 | |
| 5011 | Stmt *ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
| 5012 | SmallVector<IdentifierInfo *, 4> Names; |
| 5013 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 5014 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5015 | // ToII is nullptr when no symbolic name is given for output operand |
| 5016 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 5017 | if (!ToII && S->getOutputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5018 | return nullptr; |
| 5019 | Names.push_back(ToII); |
| 5020 | } |
| 5021 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 5022 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5023 | // ToII is nullptr when no symbolic name is given for input operand |
| 5024 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 5025 | if (!ToII && S->getInputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5026 | return nullptr; |
| 5027 | Names.push_back(ToII); |
| 5028 | } |
| 5029 | |
| 5030 | SmallVector<StringLiteral *, 4> Clobbers; |
| 5031 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5032 | auto *Clobber = cast_or_null<StringLiteral>( |
| 5033 | Importer.Import(S->getClobberStringLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5034 | if (!Clobber) |
| 5035 | return nullptr; |
| 5036 | Clobbers.push_back(Clobber); |
| 5037 | } |
| 5038 | |
| 5039 | SmallVector<StringLiteral *, 4> Constraints; |
| 5040 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5041 | auto *Output = cast_or_null<StringLiteral>( |
| 5042 | Importer.Import(S->getOutputConstraintLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5043 | if (!Output) |
| 5044 | return nullptr; |
| 5045 | Constraints.push_back(Output); |
| 5046 | } |
| 5047 | |
| 5048 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5049 | auto *Input = cast_or_null<StringLiteral>( |
| 5050 | Importer.Import(S->getInputConstraintLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5051 | if (!Input) |
| 5052 | return nullptr; |
| 5053 | Constraints.push_back(Input); |
| 5054 | } |
| 5055 | |
| 5056 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5057 | if (ImportContainerChecked(S->outputs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5058 | return nullptr; |
| 5059 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5060 | if (ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5061 | return nullptr; |
| 5062 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5063 | auto *AsmStr = cast_or_null<StringLiteral>( |
| 5064 | Importer.Import(S->getAsmString())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5065 | if (!AsmStr) |
| 5066 | return nullptr; |
| 5067 | |
| 5068 | return new (Importer.getToContext()) GCCAsmStmt( |
| 5069 | Importer.getToContext(), |
| 5070 | Importer.Import(S->getAsmLoc()), |
| 5071 | S->isSimple(), |
| 5072 | S->isVolatile(), |
| 5073 | S->getNumOutputs(), |
| 5074 | S->getNumInputs(), |
| 5075 | Names.data(), |
| 5076 | Constraints.data(), |
| 5077 | Exprs.data(), |
| 5078 | AsmStr, |
| 5079 | S->getNumClobbers(), |
| 5080 | Clobbers.data(), |
| 5081 | Importer.Import(S->getRParenLoc())); |
| 5082 | } |
| 5083 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5084 | Stmt *ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 5085 | DeclGroupRef ToDG = ImportDeclGroup(S->getDeclGroup()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5086 | for (auto *ToD : ToDG) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5087 | if (!ToD) |
| 5088 | return nullptr; |
| 5089 | } |
Stephen Kelly | a6e4358 | 2018-08-09 21:05:56 +0000 | [diff] [blame] | 5090 | SourceLocation ToStartLoc = Importer.Import(S->getBeginLoc()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5091 | SourceLocation ToEndLoc = Importer.Import(S->getEndLoc()); |
| 5092 | return new (Importer.getToContext()) DeclStmt(ToDG, ToStartLoc, ToEndLoc); |
| 5093 | } |
| 5094 | |
| 5095 | Stmt *ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 5096 | SourceLocation ToSemiLoc = Importer.Import(S->getSemiLoc()); |
| 5097 | return new (Importer.getToContext()) NullStmt(ToSemiLoc, |
| 5098 | S->hasLeadingEmptyMacro()); |
| 5099 | } |
| 5100 | |
| 5101 | Stmt *ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5102 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5103 | |
| 5104 | if (ImportContainerChecked(S->body(), ToStmts)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5105 | return nullptr; |
| 5106 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5107 | SourceLocation ToLBraceLoc = Importer.Import(S->getLBracLoc()); |
| 5108 | SourceLocation ToRBraceLoc = Importer.Import(S->getRBracLoc()); |
Benjamin Kramer | 0742090 | 2017-12-24 16:24:20 +0000 | [diff] [blame] | 5109 | return CompoundStmt::Create(Importer.getToContext(), ToStmts, ToLBraceLoc, |
| 5110 | ToRBraceLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5111 | } |
| 5112 | |
| 5113 | Stmt *ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 5114 | Expr *ToLHS = Importer.Import(S->getLHS()); |
| 5115 | if (!ToLHS) |
| 5116 | return nullptr; |
| 5117 | Expr *ToRHS = Importer.Import(S->getRHS()); |
| 5118 | if (!ToRHS && S->getRHS()) |
| 5119 | return nullptr; |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5120 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5121 | if (!ToSubStmt && S->getSubStmt()) |
| 5122 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5123 | SourceLocation ToCaseLoc = Importer.Import(S->getCaseLoc()); |
| 5124 | SourceLocation ToEllipsisLoc = Importer.Import(S->getEllipsisLoc()); |
| 5125 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5126 | auto *ToStmt = new (Importer.getToContext()) |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5127 | CaseStmt(ToLHS, ToRHS, ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
| 5128 | ToStmt->setSubStmt(ToSubStmt); |
| 5129 | return ToStmt; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5130 | } |
| 5131 | |
| 5132 | Stmt *ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 5133 | SourceLocation ToDefaultLoc = Importer.Import(S->getDefaultLoc()); |
| 5134 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 5135 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5136 | if (!ToSubStmt && S->getSubStmt()) |
| 5137 | return nullptr; |
| 5138 | return new (Importer.getToContext()) DefaultStmt(ToDefaultLoc, ToColonLoc, |
| 5139 | ToSubStmt); |
| 5140 | } |
| 5141 | |
| 5142 | Stmt *ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 5143 | SourceLocation ToIdentLoc = Importer.Import(S->getIdentLoc()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5144 | auto *ToLabelDecl = cast_or_null<LabelDecl>(Importer.Import(S->getDecl())); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5145 | if (!ToLabelDecl && S->getDecl()) |
| 5146 | return nullptr; |
| 5147 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5148 | if (!ToSubStmt && S->getSubStmt()) |
| 5149 | return nullptr; |
| 5150 | return new (Importer.getToContext()) LabelStmt(ToIdentLoc, ToLabelDecl, |
| 5151 | ToSubStmt); |
| 5152 | } |
| 5153 | |
| 5154 | Stmt *ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 5155 | SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc()); |
| 5156 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 5157 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 5158 | if (ImportContainerChecked(FromAttrs, ToAttrs)) |
| 5159 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5160 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5161 | if (!ToSubStmt && S->getSubStmt()) |
| 5162 | return nullptr; |
| 5163 | return AttributedStmt::Create(Importer.getToContext(), ToAttrLoc, |
| 5164 | ToAttrs, ToSubStmt); |
| 5165 | } |
| 5166 | |
| 5167 | Stmt *ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 5168 | SourceLocation ToIfLoc = Importer.Import(S->getIfLoc()); |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 5169 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 5170 | if (!ToInit && S->getInit()) |
| 5171 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5172 | VarDecl *ToConditionVariable = nullptr; |
| 5173 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 5174 | ToConditionVariable = |
| 5175 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 5176 | if (!ToConditionVariable) |
| 5177 | return nullptr; |
| 5178 | } |
| 5179 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5180 | if (!ToCondition && S->getCond()) |
| 5181 | return nullptr; |
| 5182 | Stmt *ToThenStmt = Importer.Import(S->getThen()); |
| 5183 | if (!ToThenStmt && S->getThen()) |
| 5184 | return nullptr; |
| 5185 | SourceLocation ToElseLoc = Importer.Import(S->getElseLoc()); |
| 5186 | Stmt *ToElseStmt = Importer.Import(S->getElse()); |
| 5187 | if (!ToElseStmt && S->getElse()) |
| 5188 | return nullptr; |
| 5189 | return new (Importer.getToContext()) IfStmt(Importer.getToContext(), |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 5190 | ToIfLoc, S->isConstexpr(), |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 5191 | ToInit, |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 5192 | ToConditionVariable, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5193 | ToCondition, ToThenStmt, |
| 5194 | ToElseLoc, ToElseStmt); |
| 5195 | } |
| 5196 | |
| 5197 | Stmt *ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 5198 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 5199 | if (!ToInit && S->getInit()) |
| 5200 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5201 | VarDecl *ToConditionVariable = nullptr; |
| 5202 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 5203 | ToConditionVariable = |
| 5204 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 5205 | if (!ToConditionVariable) |
| 5206 | return nullptr; |
| 5207 | } |
| 5208 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5209 | if (!ToCondition && S->getCond()) |
| 5210 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5211 | auto *ToStmt = new (Importer.getToContext()) SwitchStmt( |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 5212 | Importer.getToContext(), ToInit, |
| 5213 | ToConditionVariable, ToCondition); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5214 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5215 | if (!ToBody && S->getBody()) |
| 5216 | return nullptr; |
| 5217 | ToStmt->setBody(ToBody); |
| 5218 | ToStmt->setSwitchLoc(Importer.Import(S->getSwitchLoc())); |
| 5219 | // Now we have to re-chain the cases. |
| 5220 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 5221 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 5222 | SC = SC->getNextSwitchCase()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5223 | auto *ToSC = dyn_cast_or_null<SwitchCase>(Importer.Import(SC)); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5224 | if (!ToSC) |
| 5225 | return nullptr; |
| 5226 | if (LastChainedSwitchCase) |
| 5227 | LastChainedSwitchCase->setNextSwitchCase(ToSC); |
| 5228 | else |
| 5229 | ToStmt->setSwitchCaseList(ToSC); |
| 5230 | LastChainedSwitchCase = ToSC; |
| 5231 | } |
| 5232 | return ToStmt; |
| 5233 | } |
| 5234 | |
| 5235 | Stmt *ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 5236 | VarDecl *ToConditionVariable = nullptr; |
| 5237 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 5238 | ToConditionVariable = |
| 5239 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 5240 | if (!ToConditionVariable) |
| 5241 | return nullptr; |
| 5242 | } |
| 5243 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5244 | if (!ToCondition && S->getCond()) |
| 5245 | return nullptr; |
| 5246 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5247 | if (!ToBody && S->getBody()) |
| 5248 | return nullptr; |
| 5249 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 5250 | return new (Importer.getToContext()) WhileStmt(Importer.getToContext(), |
| 5251 | ToConditionVariable, |
| 5252 | ToCondition, ToBody, |
| 5253 | ToWhileLoc); |
| 5254 | } |
| 5255 | |
| 5256 | Stmt *ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 5257 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5258 | if (!ToBody && S->getBody()) |
| 5259 | return nullptr; |
| 5260 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5261 | if (!ToCondition && S->getCond()) |
| 5262 | return nullptr; |
| 5263 | SourceLocation ToDoLoc = Importer.Import(S->getDoLoc()); |
| 5264 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 5265 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5266 | return new (Importer.getToContext()) DoStmt(ToBody, ToCondition, |
| 5267 | ToDoLoc, ToWhileLoc, |
| 5268 | ToRParenLoc); |
| 5269 | } |
| 5270 | |
| 5271 | Stmt *ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 5272 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 5273 | if (!ToInit && S->getInit()) |
| 5274 | return nullptr; |
| 5275 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5276 | if (!ToCondition && S->getCond()) |
| 5277 | return nullptr; |
| 5278 | VarDecl *ToConditionVariable = nullptr; |
| 5279 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 5280 | ToConditionVariable = |
| 5281 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 5282 | if (!ToConditionVariable) |
| 5283 | return nullptr; |
| 5284 | } |
| 5285 | Expr *ToInc = Importer.Import(S->getInc()); |
| 5286 | if (!ToInc && S->getInc()) |
| 5287 | return nullptr; |
| 5288 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5289 | if (!ToBody && S->getBody()) |
| 5290 | return nullptr; |
| 5291 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 5292 | SourceLocation ToLParenLoc = Importer.Import(S->getLParenLoc()); |
| 5293 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5294 | return new (Importer.getToContext()) ForStmt(Importer.getToContext(), |
| 5295 | ToInit, ToCondition, |
| 5296 | ToConditionVariable, |
| 5297 | ToInc, ToBody, |
| 5298 | ToForLoc, ToLParenLoc, |
| 5299 | ToRParenLoc); |
| 5300 | } |
| 5301 | |
| 5302 | Stmt *ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 5303 | LabelDecl *ToLabel = nullptr; |
| 5304 | if (LabelDecl *FromLabel = S->getLabel()) { |
| 5305 | ToLabel = dyn_cast_or_null<LabelDecl>(Importer.Import(FromLabel)); |
| 5306 | if (!ToLabel) |
| 5307 | return nullptr; |
| 5308 | } |
| 5309 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 5310 | SourceLocation ToLabelLoc = Importer.Import(S->getLabelLoc()); |
| 5311 | return new (Importer.getToContext()) GotoStmt(ToLabel, |
| 5312 | ToGotoLoc, ToLabelLoc); |
| 5313 | } |
| 5314 | |
| 5315 | Stmt *ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 5316 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 5317 | SourceLocation ToStarLoc = Importer.Import(S->getStarLoc()); |
| 5318 | Expr *ToTarget = Importer.Import(S->getTarget()); |
| 5319 | if (!ToTarget && S->getTarget()) |
| 5320 | return nullptr; |
| 5321 | return new (Importer.getToContext()) IndirectGotoStmt(ToGotoLoc, ToStarLoc, |
| 5322 | ToTarget); |
| 5323 | } |
| 5324 | |
| 5325 | Stmt *ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 5326 | SourceLocation ToContinueLoc = Importer.Import(S->getContinueLoc()); |
| 5327 | return new (Importer.getToContext()) ContinueStmt(ToContinueLoc); |
| 5328 | } |
| 5329 | |
| 5330 | Stmt *ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 5331 | SourceLocation ToBreakLoc = Importer.Import(S->getBreakLoc()); |
| 5332 | return new (Importer.getToContext()) BreakStmt(ToBreakLoc); |
| 5333 | } |
| 5334 | |
| 5335 | Stmt *ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 5336 | SourceLocation ToRetLoc = Importer.Import(S->getReturnLoc()); |
| 5337 | Expr *ToRetExpr = Importer.Import(S->getRetValue()); |
| 5338 | if (!ToRetExpr && S->getRetValue()) |
| 5339 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5340 | auto *NRVOCandidate = const_cast<VarDecl *>(S->getNRVOCandidate()); |
| 5341 | auto *ToNRVOCandidate = cast_or_null<VarDecl>(Importer.Import(NRVOCandidate)); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5342 | if (!ToNRVOCandidate && NRVOCandidate) |
| 5343 | return nullptr; |
| 5344 | return new (Importer.getToContext()) ReturnStmt(ToRetLoc, ToRetExpr, |
| 5345 | ToNRVOCandidate); |
| 5346 | } |
| 5347 | |
| 5348 | Stmt *ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 5349 | SourceLocation ToCatchLoc = Importer.Import(S->getCatchLoc()); |
| 5350 | VarDecl *ToExceptionDecl = nullptr; |
| 5351 | if (VarDecl *FromExceptionDecl = S->getExceptionDecl()) { |
| 5352 | ToExceptionDecl = |
| 5353 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 5354 | if (!ToExceptionDecl) |
| 5355 | return nullptr; |
| 5356 | } |
| 5357 | Stmt *ToHandlerBlock = Importer.Import(S->getHandlerBlock()); |
| 5358 | if (!ToHandlerBlock && S->getHandlerBlock()) |
| 5359 | return nullptr; |
| 5360 | return new (Importer.getToContext()) CXXCatchStmt(ToCatchLoc, |
| 5361 | ToExceptionDecl, |
| 5362 | ToHandlerBlock); |
| 5363 | } |
| 5364 | |
| 5365 | Stmt *ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 5366 | SourceLocation ToTryLoc = Importer.Import(S->getTryLoc()); |
| 5367 | Stmt *ToTryBlock = Importer.Import(S->getTryBlock()); |
| 5368 | if (!ToTryBlock && S->getTryBlock()) |
| 5369 | return nullptr; |
| 5370 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 5371 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 5372 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
| 5373 | if (Stmt *ToHandler = Importer.Import(FromHandler)) |
| 5374 | ToHandlers[HI] = ToHandler; |
| 5375 | else |
| 5376 | return nullptr; |
| 5377 | } |
| 5378 | return CXXTryStmt::Create(Importer.getToContext(), ToTryLoc, ToTryBlock, |
| 5379 | ToHandlers); |
| 5380 | } |
| 5381 | |
| 5382 | Stmt *ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5383 | auto *ToRange = |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5384 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getRangeStmt())); |
| 5385 | if (!ToRange && S->getRangeStmt()) |
| 5386 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5387 | auto *ToBegin = |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 5388 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getBeginStmt())); |
| 5389 | if (!ToBegin && S->getBeginStmt()) |
| 5390 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5391 | auto *ToEnd = |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 5392 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getEndStmt())); |
| 5393 | if (!ToEnd && S->getEndStmt()) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5394 | return nullptr; |
| 5395 | Expr *ToCond = Importer.Import(S->getCond()); |
| 5396 | if (!ToCond && S->getCond()) |
| 5397 | return nullptr; |
| 5398 | Expr *ToInc = Importer.Import(S->getInc()); |
| 5399 | if (!ToInc && S->getInc()) |
| 5400 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5401 | auto *ToLoopVar = |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5402 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getLoopVarStmt())); |
| 5403 | if (!ToLoopVar && S->getLoopVarStmt()) |
| 5404 | return nullptr; |
| 5405 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5406 | if (!ToBody && S->getBody()) |
| 5407 | return nullptr; |
| 5408 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 5409 | SourceLocation ToCoawaitLoc = Importer.Import(S->getCoawaitLoc()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5410 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 5411 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 5412 | return new (Importer.getToContext()) CXXForRangeStmt(ToRange, ToBegin, ToEnd, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5413 | ToCond, ToInc, |
| 5414 | ToLoopVar, ToBody, |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 5415 | ToForLoc, ToCoawaitLoc, |
| 5416 | ToColonLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5417 | } |
| 5418 | |
| 5419 | Stmt *ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 5420 | Stmt *ToElem = Importer.Import(S->getElement()); |
| 5421 | if (!ToElem && S->getElement()) |
| 5422 | return nullptr; |
| 5423 | Expr *ToCollect = Importer.Import(S->getCollection()); |
| 5424 | if (!ToCollect && S->getCollection()) |
| 5425 | return nullptr; |
| 5426 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5427 | if (!ToBody && S->getBody()) |
| 5428 | return nullptr; |
| 5429 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 5430 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5431 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElem, |
| 5432 | ToCollect, |
| 5433 | ToBody, ToForLoc, |
| 5434 | ToRParenLoc); |
| 5435 | } |
| 5436 | |
| 5437 | Stmt *ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 5438 | SourceLocation ToAtCatchLoc = Importer.Import(S->getAtCatchLoc()); |
| 5439 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5440 | VarDecl *ToExceptionDecl = nullptr; |
| 5441 | if (VarDecl *FromExceptionDecl = S->getCatchParamDecl()) { |
| 5442 | ToExceptionDecl = |
| 5443 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 5444 | if (!ToExceptionDecl) |
| 5445 | return nullptr; |
| 5446 | } |
| 5447 | Stmt *ToBody = Importer.Import(S->getCatchBody()); |
| 5448 | if (!ToBody && S->getCatchBody()) |
| 5449 | return nullptr; |
| 5450 | return new (Importer.getToContext()) ObjCAtCatchStmt(ToAtCatchLoc, |
| 5451 | ToRParenLoc, |
| 5452 | ToExceptionDecl, |
| 5453 | ToBody); |
| 5454 | } |
| 5455 | |
| 5456 | Stmt *ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 5457 | SourceLocation ToAtFinallyLoc = Importer.Import(S->getAtFinallyLoc()); |
| 5458 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyBody()); |
| 5459 | if (!ToAtFinallyStmt && S->getFinallyBody()) |
| 5460 | return nullptr; |
| 5461 | return new (Importer.getToContext()) ObjCAtFinallyStmt(ToAtFinallyLoc, |
| 5462 | ToAtFinallyStmt); |
| 5463 | } |
| 5464 | |
| 5465 | Stmt *ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 5466 | SourceLocation ToAtTryLoc = Importer.Import(S->getAtTryLoc()); |
| 5467 | Stmt *ToAtTryStmt = Importer.Import(S->getTryBody()); |
| 5468 | if (!ToAtTryStmt && S->getTryBody()) |
| 5469 | return nullptr; |
| 5470 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 5471 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 5472 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
| 5473 | if (Stmt *ToCatchStmt = Importer.Import(FromCatchStmt)) |
| 5474 | ToCatchStmts[CI] = ToCatchStmt; |
| 5475 | else |
| 5476 | return nullptr; |
| 5477 | } |
| 5478 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyStmt()); |
| 5479 | if (!ToAtFinallyStmt && S->getFinallyStmt()) |
| 5480 | return nullptr; |
| 5481 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
| 5482 | ToAtTryLoc, ToAtTryStmt, |
| 5483 | ToCatchStmts.begin(), ToCatchStmts.size(), |
| 5484 | ToAtFinallyStmt); |
| 5485 | } |
| 5486 | |
| 5487 | Stmt *ASTNodeImporter::VisitObjCAtSynchronizedStmt |
| 5488 | (ObjCAtSynchronizedStmt *S) { |
| 5489 | SourceLocation ToAtSynchronizedLoc = |
| 5490 | Importer.Import(S->getAtSynchronizedLoc()); |
| 5491 | Expr *ToSynchExpr = Importer.Import(S->getSynchExpr()); |
| 5492 | if (!ToSynchExpr && S->getSynchExpr()) |
| 5493 | return nullptr; |
| 5494 | Stmt *ToSynchBody = Importer.Import(S->getSynchBody()); |
| 5495 | if (!ToSynchBody && S->getSynchBody()) |
| 5496 | return nullptr; |
| 5497 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 5498 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 5499 | } |
| 5500 | |
| 5501 | Stmt *ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 5502 | SourceLocation ToAtThrowLoc = Importer.Import(S->getThrowLoc()); |
| 5503 | Expr *ToThrow = Importer.Import(S->getThrowExpr()); |
| 5504 | if (!ToThrow && S->getThrowExpr()) |
| 5505 | return nullptr; |
| 5506 | return new (Importer.getToContext()) ObjCAtThrowStmt(ToAtThrowLoc, ToThrow); |
| 5507 | } |
| 5508 | |
| 5509 | Stmt *ASTNodeImporter::VisitObjCAutoreleasePoolStmt |
| 5510 | (ObjCAutoreleasePoolStmt *S) { |
| 5511 | SourceLocation ToAtLoc = Importer.Import(S->getAtLoc()); |
| 5512 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5513 | if (!ToSubStmt && S->getSubStmt()) |
| 5514 | return nullptr; |
| 5515 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(ToAtLoc, |
| 5516 | ToSubStmt); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5517 | } |
| 5518 | |
| 5519 | //---------------------------------------------------------------------------- |
| 5520 | // Import Expressions |
| 5521 | //---------------------------------------------------------------------------- |
| 5522 | Expr *ASTNodeImporter::VisitExpr(Expr *E) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5523 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) |
| 5524 | << E->getStmtClassName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5525 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5526 | } |
| 5527 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5528 | Expr *ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 5529 | QualType T = Importer.Import(E->getType()); |
| 5530 | if (T.isNull()) |
| 5531 | return nullptr; |
| 5532 | |
| 5533 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5534 | if (!SubExpr && E->getSubExpr()) |
| 5535 | return nullptr; |
| 5536 | |
| 5537 | TypeSourceInfo *TInfo = Importer.Import(E->getWrittenTypeInfo()); |
| 5538 | if (!TInfo) |
| 5539 | return nullptr; |
| 5540 | |
| 5541 | return new (Importer.getToContext()) VAArgExpr( |
| 5542 | Importer.Import(E->getBuiltinLoc()), SubExpr, TInfo, |
| 5543 | Importer.Import(E->getRParenLoc()), T, E->isMicrosoftABI()); |
| 5544 | } |
| 5545 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5546 | Expr *ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 5547 | QualType T = Importer.Import(E->getType()); |
| 5548 | if (T.isNull()) |
| 5549 | return nullptr; |
| 5550 | |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5551 | return new (Importer.getToContext()) |
| 5552 | GNUNullExpr(T, Importer.Import(E->getBeginLoc())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5553 | } |
| 5554 | |
| 5555 | Expr *ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *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 *SL = cast_or_null<StringLiteral>(Importer.Import(E->getFunctionName())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5561 | if (!SL && E->getFunctionName()) |
| 5562 | return nullptr; |
| 5563 | |
| 5564 | return new (Importer.getToContext()) PredefinedExpr( |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5565 | Importer.Import(E->getBeginLoc()), T, E->getIdentType(), SL); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5566 | } |
| 5567 | |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5568 | Expr *ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5569 | auto *ToD = cast_or_null<ValueDecl>(Importer.Import(E->getDecl())); |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5570 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5571 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5572 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5573 | NamedDecl *FoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5574 | if (E->getDecl() != E->getFoundDecl()) { |
| 5575 | FoundD = cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl())); |
| 5576 | if (!FoundD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5577 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5578 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5579 | |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5580 | QualType T = Importer.Import(E->getType()); |
| 5581 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5582 | return nullptr; |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5583 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5584 | TemplateArgumentListInfo ToTAInfo; |
| 5585 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 5586 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5587 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 5588 | return nullptr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5589 | ResInfo = &ToTAInfo; |
| 5590 | } |
| 5591 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5592 | DeclRefExpr *DRE = DeclRefExpr::Create(Importer.getToContext(), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5593 | Importer.Import(E->getQualifierLoc()), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 5594 | Importer.Import(E->getTemplateKeywordLoc()), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5595 | ToD, |
Alexey Bataev | 19acc3d | 2015-01-12 10:17:46 +0000 | [diff] [blame] | 5596 | E->refersToEnclosingVariableOrCapture(), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5597 | Importer.Import(E->getLocation()), |
| 5598 | T, E->getValueKind(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5599 | FoundD, ResInfo); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5600 | if (E->hadMultipleCandidates()) |
| 5601 | DRE->setHadMultipleCandidates(true); |
| 5602 | return DRE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5603 | } |
| 5604 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5605 | Expr *ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 5606 | QualType T = Importer.Import(E->getType()); |
| 5607 | if (T.isNull()) |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5608 | return nullptr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5609 | |
| 5610 | return new (Importer.getToContext()) ImplicitValueInitExpr(T); |
| 5611 | } |
| 5612 | |
| 5613 | ASTNodeImporter::Designator |
| 5614 | ASTNodeImporter::ImportDesignator(const Designator &D) { |
| 5615 | if (D.isFieldDesignator()) { |
| 5616 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 5617 | // Caller checks for import error |
| 5618 | return Designator(ToFieldName, Importer.Import(D.getDotLoc()), |
| 5619 | Importer.Import(D.getFieldLoc())); |
| 5620 | } |
| 5621 | if (D.isArrayDesignator()) |
| 5622 | return Designator(D.getFirstExprIndex(), |
| 5623 | Importer.Import(D.getLBracketLoc()), |
| 5624 | Importer.Import(D.getRBracketLoc())); |
| 5625 | |
| 5626 | assert(D.isArrayRangeDesignator()); |
| 5627 | return Designator(D.getFirstExprIndex(), |
| 5628 | Importer.Import(D.getLBracketLoc()), |
| 5629 | Importer.Import(D.getEllipsisLoc()), |
| 5630 | Importer.Import(D.getRBracketLoc())); |
| 5631 | } |
| 5632 | |
| 5633 | |
| 5634 | Expr *ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *DIE) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5635 | auto *Init = cast_or_null<Expr>(Importer.Import(DIE->getInit())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5636 | if (!Init) |
| 5637 | return nullptr; |
| 5638 | |
| 5639 | SmallVector<Expr *, 4> IndexExprs(DIE->getNumSubExprs() - 1); |
| 5640 | // List elements from the second, the first is Init itself |
| 5641 | for (unsigned I = 1, E = DIE->getNumSubExprs(); I < E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5642 | if (auto *Arg = cast_or_null<Expr>(Importer.Import(DIE->getSubExpr(I)))) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5643 | IndexExprs[I - 1] = Arg; |
| 5644 | else |
| 5645 | return nullptr; |
| 5646 | } |
| 5647 | |
| 5648 | SmallVector<Designator, 4> Designators(DIE->size()); |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5649 | llvm::transform(DIE->designators(), Designators.begin(), |
| 5650 | [this](const Designator &D) -> Designator { |
| 5651 | return ImportDesignator(D); |
| 5652 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5653 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5654 | for (const auto &D : DIE->designators()) |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5655 | if (D.isFieldDesignator() && !D.getFieldName()) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5656 | return nullptr; |
| 5657 | |
| 5658 | return DesignatedInitExpr::Create( |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5659 | Importer.getToContext(), Designators, |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5660 | IndexExprs, Importer.Import(DIE->getEqualOrColonLoc()), |
| 5661 | DIE->usesGNUSyntax(), Init); |
| 5662 | } |
| 5663 | |
| 5664 | Expr *ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 5665 | QualType T = Importer.Import(E->getType()); |
| 5666 | if (T.isNull()) |
| 5667 | return nullptr; |
| 5668 | |
| 5669 | return new (Importer.getToContext()) |
| 5670 | CXXNullPtrLiteralExpr(T, Importer.Import(E->getLocation())); |
| 5671 | } |
| 5672 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5673 | Expr *ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 5674 | QualType T = Importer.Import(E->getType()); |
| 5675 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5676 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5677 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5678 | return IntegerLiteral::Create(Importer.getToContext(), |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 5679 | E->getValue(), T, |
| 5680 | Importer.Import(E->getLocation())); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5681 | } |
| 5682 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5683 | Expr *ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 5684 | QualType T = Importer.Import(E->getType()); |
| 5685 | if (T.isNull()) |
| 5686 | return nullptr; |
| 5687 | |
| 5688 | return FloatingLiteral::Create(Importer.getToContext(), |
| 5689 | E->getValue(), E->isExact(), T, |
| 5690 | Importer.Import(E->getLocation())); |
| 5691 | } |
| 5692 | |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 5693 | Expr *ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 5694 | QualType T = Importer.Import(E->getType()); |
| 5695 | if (T.isNull()) |
| 5696 | return nullptr; |
| 5697 | |
| 5698 | Expr *SubE = Importer.Import(E->getSubExpr()); |
| 5699 | if (!SubE) |
| 5700 | return nullptr; |
| 5701 | |
| 5702 | return new (Importer.getToContext()) ImaginaryLiteral(SubE, T); |
| 5703 | } |
| 5704 | |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 5705 | Expr *ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 5706 | QualType T = Importer.Import(E->getType()); |
| 5707 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5708 | return nullptr; |
| 5709 | |
Douglas Gregor | fb65e59 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 5710 | return new (Importer.getToContext()) CharacterLiteral(E->getValue(), |
| 5711 | E->getKind(), T, |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 5712 | Importer.Import(E->getLocation())); |
| 5713 | } |
| 5714 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5715 | Expr *ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 5716 | QualType T = Importer.Import(E->getType()); |
| 5717 | if (T.isNull()) |
| 5718 | return nullptr; |
| 5719 | |
| 5720 | SmallVector<SourceLocation, 4> Locations(E->getNumConcatenated()); |
| 5721 | ImportArray(E->tokloc_begin(), E->tokloc_end(), Locations.begin()); |
| 5722 | |
| 5723 | return StringLiteral::Create(Importer.getToContext(), E->getBytes(), |
| 5724 | E->getKind(), E->isPascal(), T, |
| 5725 | Locations.data(), Locations.size()); |
| 5726 | } |
| 5727 | |
| 5728 | Expr *ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 5729 | QualType T = Importer.Import(E->getType()); |
| 5730 | if (T.isNull()) |
| 5731 | return nullptr; |
| 5732 | |
| 5733 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeSourceInfo()); |
| 5734 | if (!TInfo) |
| 5735 | return nullptr; |
| 5736 | |
| 5737 | Expr *Init = Importer.Import(E->getInitializer()); |
| 5738 | if (!Init) |
| 5739 | return nullptr; |
| 5740 | |
| 5741 | return new (Importer.getToContext()) CompoundLiteralExpr( |
| 5742 | Importer.Import(E->getLParenLoc()), TInfo, T, E->getValueKind(), |
| 5743 | Init, E->isFileScope()); |
| 5744 | } |
| 5745 | |
| 5746 | Expr *ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 5747 | QualType T = Importer.Import(E->getType()); |
| 5748 | if (T.isNull()) |
| 5749 | return nullptr; |
| 5750 | |
| 5751 | SmallVector<Expr *, 6> Exprs(E->getNumSubExprs()); |
| 5752 | if (ImportArrayChecked( |
| 5753 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 5754 | Exprs.begin())) |
| 5755 | return nullptr; |
| 5756 | |
| 5757 | return new (Importer.getToContext()) AtomicExpr( |
| 5758 | Importer.Import(E->getBuiltinLoc()), Exprs, T, E->getOp(), |
| 5759 | Importer.Import(E->getRParenLoc())); |
| 5760 | } |
| 5761 | |
| 5762 | Expr *ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 5763 | QualType T = Importer.Import(E->getType()); |
| 5764 | if (T.isNull()) |
| 5765 | return nullptr; |
| 5766 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5767 | auto *ToLabel = cast_or_null<LabelDecl>(Importer.Import(E->getLabel())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5768 | if (!ToLabel) |
| 5769 | return nullptr; |
| 5770 | |
| 5771 | return new (Importer.getToContext()) AddrLabelExpr( |
| 5772 | Importer.Import(E->getAmpAmpLoc()), Importer.Import(E->getLabelLoc()), |
| 5773 | ToLabel, T); |
| 5774 | } |
| 5775 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5776 | Expr *ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 5777 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5778 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5779 | return nullptr; |
| 5780 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5781 | return new (Importer.getToContext()) |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5782 | ParenExpr(Importer.Import(E->getLParen()), |
| 5783 | Importer.Import(E->getRParen()), |
| 5784 | SubExpr); |
| 5785 | } |
| 5786 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5787 | Expr *ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 5788 | SmallVector<Expr *, 4> Exprs(E->getNumExprs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5789 | if (ImportContainerChecked(E->exprs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5790 | return nullptr; |
| 5791 | |
| 5792 | return new (Importer.getToContext()) ParenListExpr( |
| 5793 | Importer.getToContext(), Importer.Import(E->getLParenLoc()), |
| 5794 | Exprs, Importer.Import(E->getLParenLoc())); |
| 5795 | } |
| 5796 | |
| 5797 | Expr *ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 5798 | QualType T = Importer.Import(E->getType()); |
| 5799 | if (T.isNull()) |
| 5800 | return nullptr; |
| 5801 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5802 | auto *ToSubStmt = cast_or_null<CompoundStmt>( |
| 5803 | Importer.Import(E->getSubStmt())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5804 | if (!ToSubStmt && E->getSubStmt()) |
| 5805 | return nullptr; |
| 5806 | |
| 5807 | return new (Importer.getToContext()) StmtExpr(ToSubStmt, T, |
| 5808 | Importer.Import(E->getLParenLoc()), Importer.Import(E->getRParenLoc())); |
| 5809 | } |
| 5810 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5811 | Expr *ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 5812 | QualType T = Importer.Import(E->getType()); |
| 5813 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5814 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5815 | |
| 5816 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5817 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5818 | return nullptr; |
| 5819 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 5820 | return new (Importer.getToContext()) UnaryOperator( |
| 5821 | SubExpr, E->getOpcode(), T, E->getValueKind(), E->getObjectKind(), |
| 5822 | Importer.Import(E->getOperatorLoc()), E->canOverflow()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5823 | } |
| 5824 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 5825 | Expr * |
| 5826 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5827 | QualType ResultType = Importer.Import(E->getType()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5828 | |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5829 | if (E->isArgumentType()) { |
| 5830 | TypeSourceInfo *TInfo = Importer.Import(E->getArgumentTypeInfo()); |
| 5831 | if (!TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5832 | return nullptr; |
| 5833 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5834 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 5835 | TInfo, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5836 | Importer.Import(E->getOperatorLoc()), |
| 5837 | Importer.Import(E->getRParenLoc())); |
| 5838 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5839 | |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5840 | Expr *SubExpr = Importer.Import(E->getArgumentExpr()); |
| 5841 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5842 | return nullptr; |
| 5843 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5844 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 5845 | SubExpr, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5846 | Importer.Import(E->getOperatorLoc()), |
| 5847 | Importer.Import(E->getRParenLoc())); |
| 5848 | } |
| 5849 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5850 | Expr *ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 5851 | QualType T = Importer.Import(E->getType()); |
| 5852 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5853 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5854 | |
| 5855 | Expr *LHS = Importer.Import(E->getLHS()); |
| 5856 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5857 | return nullptr; |
| 5858 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5859 | Expr *RHS = Importer.Import(E->getRHS()); |
| 5860 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5861 | return nullptr; |
| 5862 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5863 | return new (Importer.getToContext()) BinaryOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 5864 | T, E->getValueKind(), |
| 5865 | E->getObjectKind(), |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 5866 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 5867 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5868 | } |
| 5869 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5870 | Expr *ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 5871 | QualType T = Importer.Import(E->getType()); |
| 5872 | if (T.isNull()) |
| 5873 | return nullptr; |
| 5874 | |
| 5875 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 5876 | if (!ToLHS) |
| 5877 | return nullptr; |
| 5878 | |
| 5879 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 5880 | if (!ToRHS) |
| 5881 | return nullptr; |
| 5882 | |
| 5883 | Expr *ToCond = Importer.Import(E->getCond()); |
| 5884 | if (!ToCond) |
| 5885 | return nullptr; |
| 5886 | |
| 5887 | return new (Importer.getToContext()) ConditionalOperator( |
| 5888 | ToCond, Importer.Import(E->getQuestionLoc()), |
| 5889 | ToLHS, Importer.Import(E->getColonLoc()), |
| 5890 | ToRHS, T, E->getValueKind(), E->getObjectKind()); |
| 5891 | } |
| 5892 | |
| 5893 | Expr *ASTNodeImporter::VisitBinaryConditionalOperator( |
| 5894 | BinaryConditionalOperator *E) { |
| 5895 | QualType T = Importer.Import(E->getType()); |
| 5896 | if (T.isNull()) |
| 5897 | return nullptr; |
| 5898 | |
| 5899 | Expr *Common = Importer.Import(E->getCommon()); |
| 5900 | if (!Common) |
| 5901 | return nullptr; |
| 5902 | |
| 5903 | Expr *Cond = Importer.Import(E->getCond()); |
| 5904 | if (!Cond) |
| 5905 | return nullptr; |
| 5906 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5907 | auto *OpaqueValue = cast_or_null<OpaqueValueExpr>( |
| 5908 | Importer.Import(E->getOpaqueValue())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5909 | if (!OpaqueValue) |
| 5910 | return nullptr; |
| 5911 | |
| 5912 | Expr *TrueExpr = Importer.Import(E->getTrueExpr()); |
| 5913 | if (!TrueExpr) |
| 5914 | return nullptr; |
| 5915 | |
| 5916 | Expr *FalseExpr = Importer.Import(E->getFalseExpr()); |
| 5917 | if (!FalseExpr) |
| 5918 | return nullptr; |
| 5919 | |
| 5920 | return new (Importer.getToContext()) BinaryConditionalOperator( |
| 5921 | Common, OpaqueValue, Cond, TrueExpr, FalseExpr, |
| 5922 | Importer.Import(E->getQuestionLoc()), Importer.Import(E->getColonLoc()), |
| 5923 | T, E->getValueKind(), E->getObjectKind()); |
| 5924 | } |
| 5925 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5926 | Expr *ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 5927 | QualType T = Importer.Import(E->getType()); |
| 5928 | if (T.isNull()) |
| 5929 | return nullptr; |
| 5930 | |
| 5931 | TypeSourceInfo *ToQueried = Importer.Import(E->getQueriedTypeSourceInfo()); |
| 5932 | if (!ToQueried) |
| 5933 | return nullptr; |
| 5934 | |
| 5935 | Expr *Dim = Importer.Import(E->getDimensionExpression()); |
| 5936 | if (!Dim && E->getDimensionExpression()) |
| 5937 | return nullptr; |
| 5938 | |
| 5939 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5940 | Importer.Import(E->getBeginLoc()), E->getTrait(), ToQueried, |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 5941 | E->getValue(), Dim, Importer.Import(E->getEndLoc()), T); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5942 | } |
| 5943 | |
| 5944 | Expr *ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 5945 | QualType T = Importer.Import(E->getType()); |
| 5946 | if (T.isNull()) |
| 5947 | return nullptr; |
| 5948 | |
| 5949 | Expr *ToQueried = Importer.Import(E->getQueriedExpression()); |
| 5950 | if (!ToQueried) |
| 5951 | return nullptr; |
| 5952 | |
| 5953 | return new (Importer.getToContext()) ExpressionTraitExpr( |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5954 | Importer.Import(E->getBeginLoc()), E->getTrait(), ToQueried, |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 5955 | E->getValue(), Importer.Import(E->getEndLoc()), T); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5956 | } |
| 5957 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5958 | Expr *ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 5959 | QualType T = Importer.Import(E->getType()); |
| 5960 | if (T.isNull()) |
| 5961 | return nullptr; |
| 5962 | |
| 5963 | Expr *SourceExpr = Importer.Import(E->getSourceExpr()); |
| 5964 | if (!SourceExpr && E->getSourceExpr()) |
| 5965 | return nullptr; |
| 5966 | |
| 5967 | return new (Importer.getToContext()) OpaqueValueExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5968 | Importer.Import(E->getLocation()), T, E->getValueKind(), |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5969 | E->getObjectKind(), SourceExpr); |
| 5970 | } |
| 5971 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5972 | Expr *ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 5973 | QualType T = Importer.Import(E->getType()); |
| 5974 | if (T.isNull()) |
| 5975 | return nullptr; |
| 5976 | |
| 5977 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 5978 | if (!ToLHS) |
| 5979 | return nullptr; |
| 5980 | |
| 5981 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 5982 | if (!ToRHS) |
| 5983 | return nullptr; |
| 5984 | |
| 5985 | return new (Importer.getToContext()) ArraySubscriptExpr( |
| 5986 | ToLHS, ToRHS, T, E->getValueKind(), E->getObjectKind(), |
| 5987 | Importer.Import(E->getRBracketLoc())); |
| 5988 | } |
| 5989 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5990 | Expr *ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 5991 | QualType T = Importer.Import(E->getType()); |
| 5992 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5993 | return nullptr; |
| 5994 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5995 | QualType CompLHSType = Importer.Import(E->getComputationLHSType()); |
| 5996 | if (CompLHSType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5997 | return nullptr; |
| 5998 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5999 | QualType CompResultType = Importer.Import(E->getComputationResultType()); |
| 6000 | if (CompResultType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6001 | return nullptr; |
| 6002 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6003 | Expr *LHS = Importer.Import(E->getLHS()); |
| 6004 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6005 | return nullptr; |
| 6006 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6007 | Expr *RHS = Importer.Import(E->getRHS()); |
| 6008 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6009 | return nullptr; |
| 6010 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6011 | return new (Importer.getToContext()) |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6012 | CompoundAssignOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 6013 | T, E->getValueKind(), |
| 6014 | E->getObjectKind(), |
| 6015 | CompLHSType, CompResultType, |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 6016 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 6017 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6018 | } |
| 6019 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6020 | bool ASTNodeImporter::ImportCastPath(CastExpr *CE, CXXCastPath &Path) { |
| 6021 | for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) { |
| 6022 | if (CXXBaseSpecifier *Spec = Importer.Import(*I)) |
| 6023 | Path.push_back(Spec); |
| 6024 | else |
| 6025 | return true; |
| 6026 | } |
| 6027 | return false; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6028 | } |
| 6029 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6030 | Expr *ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 6031 | QualType T = Importer.Import(E->getType()); |
| 6032 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6033 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6034 | |
| 6035 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 6036 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6037 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6038 | |
| 6039 | CXXCastPath BasePath; |
| 6040 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6041 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6042 | |
| 6043 | return ImplicitCastExpr::Create(Importer.getToContext(), T, E->getCastKind(), |
John McCall | 2536c6d | 2010-08-25 10:28:54 +0000 | [diff] [blame] | 6044 | SubExpr, &BasePath, E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6045 | } |
| 6046 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6047 | Expr *ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6048 | QualType T = Importer.Import(E->getType()); |
| 6049 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6050 | return nullptr; |
| 6051 | |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6052 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 6053 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6054 | return nullptr; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6055 | |
| 6056 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeInfoAsWritten()); |
| 6057 | if (!TInfo && E->getTypeInfoAsWritten()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6058 | return nullptr; |
| 6059 | |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6060 | CXXCastPath BasePath; |
| 6061 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6062 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6063 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6064 | switch (E->getStmtClass()) { |
| 6065 | case Stmt::CStyleCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6066 | auto *CCE = cast<CStyleCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6067 | return CStyleCastExpr::Create(Importer.getToContext(), T, |
| 6068 | E->getValueKind(), E->getCastKind(), |
| 6069 | SubExpr, &BasePath, TInfo, |
| 6070 | Importer.Import(CCE->getLParenLoc()), |
| 6071 | Importer.Import(CCE->getRParenLoc())); |
| 6072 | } |
| 6073 | |
| 6074 | case Stmt::CXXFunctionalCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6075 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6076 | return CXXFunctionalCastExpr::Create(Importer.getToContext(), T, |
| 6077 | E->getValueKind(), TInfo, |
| 6078 | E->getCastKind(), SubExpr, &BasePath, |
| 6079 | Importer.Import(FCE->getLParenLoc()), |
| 6080 | Importer.Import(FCE->getRParenLoc())); |
| 6081 | } |
| 6082 | |
| 6083 | case Stmt::ObjCBridgedCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6084 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6085 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 6086 | Importer.Import(OCE->getLParenLoc()), OCE->getBridgeKind(), |
| 6087 | E->getCastKind(), Importer.Import(OCE->getBridgeKeywordLoc()), |
| 6088 | TInfo, SubExpr); |
| 6089 | } |
| 6090 | default: |
| 6091 | break; // just fall through |
| 6092 | } |
| 6093 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6094 | auto *Named = cast<CXXNamedCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6095 | SourceLocation ExprLoc = Importer.Import(Named->getOperatorLoc()), |
| 6096 | RParenLoc = Importer.Import(Named->getRParenLoc()); |
| 6097 | SourceRange Brackets = Importer.Import(Named->getAngleBrackets()); |
| 6098 | |
| 6099 | switch (E->getStmtClass()) { |
| 6100 | case Stmt::CXXStaticCastExprClass: |
| 6101 | return CXXStaticCastExpr::Create(Importer.getToContext(), T, |
| 6102 | E->getValueKind(), E->getCastKind(), |
| 6103 | SubExpr, &BasePath, TInfo, |
| 6104 | ExprLoc, RParenLoc, Brackets); |
| 6105 | |
| 6106 | case Stmt::CXXDynamicCastExprClass: |
| 6107 | return CXXDynamicCastExpr::Create(Importer.getToContext(), T, |
| 6108 | E->getValueKind(), E->getCastKind(), |
| 6109 | SubExpr, &BasePath, TInfo, |
| 6110 | ExprLoc, RParenLoc, Brackets); |
| 6111 | |
| 6112 | case Stmt::CXXReinterpretCastExprClass: |
| 6113 | return CXXReinterpretCastExpr::Create(Importer.getToContext(), T, |
| 6114 | E->getValueKind(), E->getCastKind(), |
| 6115 | SubExpr, &BasePath, TInfo, |
| 6116 | ExprLoc, RParenLoc, Brackets); |
| 6117 | |
| 6118 | case Stmt::CXXConstCastExprClass: |
| 6119 | return CXXConstCastExpr::Create(Importer.getToContext(), T, |
| 6120 | E->getValueKind(), SubExpr, TInfo, ExprLoc, |
| 6121 | RParenLoc, Brackets); |
| 6122 | default: |
| 6123 | llvm_unreachable("Cast expression of unsupported type!"); |
| 6124 | return nullptr; |
| 6125 | } |
| 6126 | } |
| 6127 | |
| 6128 | Expr *ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *OE) { |
| 6129 | QualType T = Importer.Import(OE->getType()); |
| 6130 | if (T.isNull()) |
| 6131 | return nullptr; |
| 6132 | |
| 6133 | SmallVector<OffsetOfNode, 4> Nodes; |
| 6134 | for (int I = 0, E = OE->getNumComponents(); I < E; ++I) { |
| 6135 | const OffsetOfNode &Node = OE->getComponent(I); |
| 6136 | |
| 6137 | switch (Node.getKind()) { |
| 6138 | case OffsetOfNode::Array: |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6139 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getBeginLoc()), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6140 | Node.getArrayExprIndex(), |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 6141 | Importer.Import(Node.getEndLoc()))); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6142 | break; |
| 6143 | |
| 6144 | case OffsetOfNode::Base: { |
| 6145 | CXXBaseSpecifier *BS = Importer.Import(Node.getBase()); |
| 6146 | if (!BS && Node.getBase()) |
| 6147 | return nullptr; |
| 6148 | Nodes.push_back(OffsetOfNode(BS)); |
| 6149 | break; |
| 6150 | } |
| 6151 | case OffsetOfNode::Field: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6152 | auto *FD = cast_or_null<FieldDecl>(Importer.Import(Node.getField())); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6153 | if (!FD) |
| 6154 | return nullptr; |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6155 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getBeginLoc()), FD, |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 6156 | Importer.Import(Node.getEndLoc()))); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6157 | break; |
| 6158 | } |
| 6159 | case OffsetOfNode::Identifier: { |
| 6160 | IdentifierInfo *ToII = Importer.Import(Node.getFieldName()); |
| 6161 | if (!ToII) |
| 6162 | return nullptr; |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6163 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getBeginLoc()), ToII, |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 6164 | Importer.Import(Node.getEndLoc()))); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6165 | break; |
| 6166 | } |
| 6167 | } |
| 6168 | } |
| 6169 | |
| 6170 | SmallVector<Expr *, 4> Exprs(OE->getNumExpressions()); |
| 6171 | for (int I = 0, E = OE->getNumExpressions(); I < E; ++I) { |
| 6172 | Expr *ToIndexExpr = Importer.Import(OE->getIndexExpr(I)); |
| 6173 | if (!ToIndexExpr) |
| 6174 | return nullptr; |
| 6175 | Exprs[I] = ToIndexExpr; |
| 6176 | } |
| 6177 | |
| 6178 | TypeSourceInfo *TInfo = Importer.Import(OE->getTypeSourceInfo()); |
| 6179 | if (!TInfo && OE->getTypeSourceInfo()) |
| 6180 | return nullptr; |
| 6181 | |
| 6182 | return OffsetOfExpr::Create(Importer.getToContext(), T, |
| 6183 | Importer.Import(OE->getOperatorLoc()), |
| 6184 | TInfo, Nodes, Exprs, |
| 6185 | Importer.Import(OE->getRParenLoc())); |
| 6186 | } |
| 6187 | |
| 6188 | Expr *ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 6189 | QualType T = Importer.Import(E->getType()); |
| 6190 | if (T.isNull()) |
| 6191 | return nullptr; |
| 6192 | |
| 6193 | Expr *Operand = Importer.Import(E->getOperand()); |
| 6194 | if (!Operand) |
| 6195 | return nullptr; |
| 6196 | |
| 6197 | CanThrowResult CanThrow; |
| 6198 | if (E->isValueDependent()) |
| 6199 | CanThrow = CT_Dependent; |
| 6200 | else |
| 6201 | CanThrow = E->getValue() ? CT_Can : CT_Cannot; |
| 6202 | |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6203 | return new (Importer.getToContext()) |
| 6204 | CXXNoexceptExpr(T, Operand, CanThrow, Importer.Import(E->getBeginLoc()), |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 6205 | Importer.Import(E->getEndLoc())); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6206 | } |
| 6207 | |
| 6208 | Expr *ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 6209 | QualType T = Importer.Import(E->getType()); |
| 6210 | if (T.isNull()) |
| 6211 | return nullptr; |
| 6212 | |
| 6213 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 6214 | if (!SubExpr && E->getSubExpr()) |
| 6215 | return nullptr; |
| 6216 | |
| 6217 | return new (Importer.getToContext()) CXXThrowExpr( |
| 6218 | SubExpr, T, Importer.Import(E->getThrowLoc()), |
| 6219 | E->isThrownVariableInScope()); |
| 6220 | } |
| 6221 | |
| 6222 | Expr *ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6223 | auto *Param = cast_or_null<ParmVarDecl>(Importer.Import(E->getParam())); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6224 | if (!Param) |
| 6225 | return nullptr; |
| 6226 | |
| 6227 | return CXXDefaultArgExpr::Create( |
| 6228 | Importer.getToContext(), Importer.Import(E->getUsedLocation()), Param); |
| 6229 | } |
| 6230 | |
| 6231 | Expr *ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 6232 | QualType T = Importer.Import(E->getType()); |
| 6233 | if (T.isNull()) |
| 6234 | return nullptr; |
| 6235 | |
| 6236 | TypeSourceInfo *TypeInfo = Importer.Import(E->getTypeSourceInfo()); |
| 6237 | if (!TypeInfo) |
| 6238 | return nullptr; |
| 6239 | |
| 6240 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
| 6241 | T, TypeInfo, Importer.Import(E->getRParenLoc())); |
| 6242 | } |
| 6243 | |
| 6244 | Expr *ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 6245 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 6246 | if (!SubExpr) |
| 6247 | return nullptr; |
| 6248 | |
| 6249 | auto *Dtor = cast_or_null<CXXDestructorDecl>( |
| 6250 | Importer.Import(const_cast<CXXDestructorDecl *>( |
| 6251 | E->getTemporary()->getDestructor()))); |
| 6252 | if (!Dtor) |
| 6253 | return nullptr; |
| 6254 | |
| 6255 | ASTContext &ToCtx = Importer.getToContext(); |
| 6256 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, Dtor); |
| 6257 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, SubExpr); |
| 6258 | } |
| 6259 | |
| 6260 | Expr *ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE) { |
| 6261 | QualType T = Importer.Import(CE->getType()); |
| 6262 | if (T.isNull()) |
| 6263 | return nullptr; |
| 6264 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6265 | TypeSourceInfo *TInfo = Importer.Import(CE->getTypeSourceInfo()); |
| 6266 | if (!TInfo) |
| 6267 | return nullptr; |
| 6268 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6269 | SmallVector<Expr *, 8> Args(CE->getNumArgs()); |
| 6270 | if (ImportContainerChecked(CE->arguments(), Args)) |
| 6271 | return nullptr; |
| 6272 | |
| 6273 | auto *Ctor = cast_or_null<CXXConstructorDecl>( |
| 6274 | Importer.Import(CE->getConstructor())); |
| 6275 | if (!Ctor) |
| 6276 | return nullptr; |
| 6277 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6278 | return new (Importer.getToContext()) CXXTemporaryObjectExpr( |
| 6279 | Importer.getToContext(), Ctor, T, TInfo, Args, |
| 6280 | Importer.Import(CE->getParenOrBraceRange()), CE->hadMultipleCandidates(), |
| 6281 | CE->isListInitialization(), CE->isStdInitListInitialization(), |
| 6282 | CE->requiresZeroInitialization()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6283 | } |
| 6284 | |
| 6285 | Expr * |
| 6286 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
| 6287 | QualType T = Importer.Import(E->getType()); |
| 6288 | if (T.isNull()) |
| 6289 | return nullptr; |
| 6290 | |
| 6291 | Expr *TempE = Importer.Import(E->GetTemporaryExpr()); |
| 6292 | if (!TempE) |
| 6293 | return nullptr; |
| 6294 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6295 | auto *ExtendedBy = cast_or_null<ValueDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6296 | Importer.Import(const_cast<ValueDecl *>(E->getExtendingDecl()))); |
| 6297 | if (!ExtendedBy && E->getExtendingDecl()) |
| 6298 | return nullptr; |
| 6299 | |
| 6300 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
| 6301 | T, TempE, E->isBoundToLvalueReference()); |
| 6302 | |
| 6303 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
| 6304 | ToMTE->setExtendingDecl(ExtendedBy, E->getManglingNumber()); |
| 6305 | return ToMTE; |
| 6306 | } |
| 6307 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6308 | Expr *ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 6309 | QualType T = Importer.Import(E->getType()); |
| 6310 | if (T.isNull()) |
| 6311 | return nullptr; |
| 6312 | |
| 6313 | Expr *Pattern = Importer.Import(E->getPattern()); |
| 6314 | if (!Pattern) |
| 6315 | return nullptr; |
| 6316 | |
| 6317 | return new (Importer.getToContext()) PackExpansionExpr( |
| 6318 | T, Pattern, Importer.Import(E->getEllipsisLoc()), |
| 6319 | E->getNumExpansions()); |
| 6320 | } |
| 6321 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6322 | Expr *ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 6323 | auto *Pack = cast_or_null<NamedDecl>(Importer.Import(E->getPack())); |
| 6324 | if (!Pack) |
| 6325 | return nullptr; |
| 6326 | |
| 6327 | Optional<unsigned> Length; |
| 6328 | |
| 6329 | if (!E->isValueDependent()) |
| 6330 | Length = E->getPackLength(); |
| 6331 | |
| 6332 | SmallVector<TemplateArgument, 8> PartialArguments; |
| 6333 | if (E->isPartiallySubstituted()) { |
| 6334 | if (ImportTemplateArguments(E->getPartialArguments().data(), |
| 6335 | E->getPartialArguments().size(), |
| 6336 | PartialArguments)) |
| 6337 | return nullptr; |
| 6338 | } |
| 6339 | |
| 6340 | return SizeOfPackExpr::Create( |
| 6341 | Importer.getToContext(), Importer.Import(E->getOperatorLoc()), Pack, |
| 6342 | Importer.Import(E->getPackLoc()), Importer.Import(E->getRParenLoc()), |
| 6343 | Length, PartialArguments); |
| 6344 | } |
| 6345 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6346 | Expr *ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *CE) { |
| 6347 | QualType T = Importer.Import(CE->getType()); |
| 6348 | if (T.isNull()) |
| 6349 | return nullptr; |
| 6350 | |
| 6351 | SmallVector<Expr *, 4> PlacementArgs(CE->getNumPlacementArgs()); |
| 6352 | if (ImportContainerChecked(CE->placement_arguments(), PlacementArgs)) |
| 6353 | return nullptr; |
| 6354 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6355 | auto *OperatorNewDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6356 | Importer.Import(CE->getOperatorNew())); |
| 6357 | if (!OperatorNewDecl && CE->getOperatorNew()) |
| 6358 | return nullptr; |
| 6359 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6360 | auto *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6361 | Importer.Import(CE->getOperatorDelete())); |
| 6362 | if (!OperatorDeleteDecl && CE->getOperatorDelete()) |
| 6363 | return nullptr; |
| 6364 | |
| 6365 | Expr *ToInit = Importer.Import(CE->getInitializer()); |
| 6366 | if (!ToInit && CE->getInitializer()) |
| 6367 | return nullptr; |
| 6368 | |
| 6369 | TypeSourceInfo *TInfo = Importer.Import(CE->getAllocatedTypeSourceInfo()); |
| 6370 | if (!TInfo) |
| 6371 | return nullptr; |
| 6372 | |
| 6373 | Expr *ToArrSize = Importer.Import(CE->getArraySize()); |
| 6374 | if (!ToArrSize && CE->getArraySize()) |
| 6375 | return nullptr; |
| 6376 | |
| 6377 | return new (Importer.getToContext()) CXXNewExpr( |
| 6378 | Importer.getToContext(), |
| 6379 | CE->isGlobalNew(), |
| 6380 | OperatorNewDecl, OperatorDeleteDecl, |
Richard Smith | b2f0f05 | 2016-10-10 18:54:32 +0000 | [diff] [blame] | 6381 | CE->passAlignment(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6382 | CE->doesUsualArrayDeleteWantSize(), |
| 6383 | PlacementArgs, |
| 6384 | Importer.Import(CE->getTypeIdParens()), |
| 6385 | ToArrSize, CE->getInitializationStyle(), ToInit, T, TInfo, |
| 6386 | Importer.Import(CE->getSourceRange()), |
| 6387 | Importer.Import(CE->getDirectInitRange())); |
| 6388 | } |
| 6389 | |
| 6390 | Expr *ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 6391 | QualType T = Importer.Import(E->getType()); |
| 6392 | if (T.isNull()) |
| 6393 | return nullptr; |
| 6394 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6395 | auto *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6396 | Importer.Import(E->getOperatorDelete())); |
| 6397 | if (!OperatorDeleteDecl && E->getOperatorDelete()) |
| 6398 | return nullptr; |
| 6399 | |
| 6400 | Expr *ToArg = Importer.Import(E->getArgument()); |
| 6401 | if (!ToArg && E->getArgument()) |
| 6402 | return nullptr; |
| 6403 | |
| 6404 | return new (Importer.getToContext()) CXXDeleteExpr( |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6405 | T, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), |
| 6406 | E->doesUsualArrayDeleteWantSize(), OperatorDeleteDecl, ToArg, |
| 6407 | Importer.Import(E->getBeginLoc())); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6408 | } |
| 6409 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6410 | Expr *ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 6411 | QualType T = Importer.Import(E->getType()); |
| 6412 | if (T.isNull()) |
| 6413 | return nullptr; |
| 6414 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6415 | auto *ToCCD = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6416 | dyn_cast_or_null<CXXConstructorDecl>(Importer.Import(E->getConstructor())); |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 6417 | if (!ToCCD) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6418 | return nullptr; |
| 6419 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6420 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6421 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6422 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6423 | |
| 6424 | return CXXConstructExpr::Create(Importer.getToContext(), T, |
| 6425 | Importer.Import(E->getLocation()), |
Richard Smith | c83bf82 | 2016-06-10 00:58:19 +0000 | [diff] [blame] | 6426 | ToCCD, E->isElidable(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6427 | ToArgs, E->hadMultipleCandidates(), |
| 6428 | E->isListInitialization(), |
| 6429 | E->isStdInitListInitialization(), |
| 6430 | E->requiresZeroInitialization(), |
| 6431 | E->getConstructionKind(), |
| 6432 | Importer.Import(E->getParenOrBraceRange())); |
| 6433 | } |
| 6434 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6435 | Expr *ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *EWC) { |
| 6436 | Expr *SubExpr = Importer.Import(EWC->getSubExpr()); |
| 6437 | if (!SubExpr && EWC->getSubExpr()) |
| 6438 | return nullptr; |
| 6439 | |
| 6440 | SmallVector<ExprWithCleanups::CleanupObject, 8> Objs(EWC->getNumObjects()); |
| 6441 | for (unsigned I = 0, E = EWC->getNumObjects(); I < E; I++) |
| 6442 | if (ExprWithCleanups::CleanupObject Obj = |
| 6443 | cast_or_null<BlockDecl>(Importer.Import(EWC->getObject(I)))) |
| 6444 | Objs[I] = Obj; |
| 6445 | else |
| 6446 | return nullptr; |
| 6447 | |
| 6448 | return ExprWithCleanups::Create(Importer.getToContext(), |
| 6449 | SubExpr, EWC->cleanupsHaveSideEffects(), |
| 6450 | Objs); |
| 6451 | } |
| 6452 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6453 | Expr *ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 6454 | QualType T = Importer.Import(E->getType()); |
| 6455 | if (T.isNull()) |
| 6456 | return nullptr; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6457 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6458 | Expr *ToFn = Importer.Import(E->getCallee()); |
| 6459 | if (!ToFn) |
| 6460 | return nullptr; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6461 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6462 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6463 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6464 | return nullptr; |
| 6465 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6466 | return new (Importer.getToContext()) CXXMemberCallExpr( |
| 6467 | Importer.getToContext(), ToFn, ToArgs, T, E->getValueKind(), |
| 6468 | Importer.Import(E->getRParenLoc())); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6469 | } |
| 6470 | |
| 6471 | Expr *ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 6472 | QualType T = Importer.Import(E->getType()); |
| 6473 | if (T.isNull()) |
| 6474 | return nullptr; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6475 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6476 | return new (Importer.getToContext()) |
| 6477 | CXXThisExpr(Importer.Import(E->getLocation()), T, E->isImplicit()); |
| 6478 | } |
| 6479 | |
| 6480 | Expr *ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 6481 | QualType T = Importer.Import(E->getType()); |
| 6482 | if (T.isNull()) |
| 6483 | return nullptr; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6484 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6485 | return new (Importer.getToContext()) |
| 6486 | CXXBoolLiteralExpr(E->getValue(), T, Importer.Import(E->getLocation())); |
| 6487 | } |
| 6488 | |
| 6489 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6490 | Expr *ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 6491 | QualType T = Importer.Import(E->getType()); |
| 6492 | if (T.isNull()) |
| 6493 | return nullptr; |
| 6494 | |
| 6495 | Expr *ToBase = Importer.Import(E->getBase()); |
| 6496 | if (!ToBase && E->getBase()) |
| 6497 | return nullptr; |
| 6498 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6499 | auto *ToMember = dyn_cast<ValueDecl>(Importer.Import(E->getMemberDecl())); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6500 | if (!ToMember && E->getMemberDecl()) |
| 6501 | return nullptr; |
| 6502 | |
Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 6503 | auto *ToDecl = |
| 6504 | dyn_cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl().getDecl())); |
| 6505 | if (!ToDecl && E->getFoundDecl().getDecl()) |
| 6506 | return nullptr; |
| 6507 | |
| 6508 | DeclAccessPair ToFoundDecl = |
| 6509 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6510 | |
| 6511 | DeclarationNameInfo ToMemberNameInfo( |
| 6512 | Importer.Import(E->getMemberNameInfo().getName()), |
| 6513 | Importer.Import(E->getMemberNameInfo().getLoc())); |
| 6514 | |
| 6515 | if (E->hasExplicitTemplateArgs()) { |
| 6516 | return nullptr; // FIXME: handle template arguments |
| 6517 | } |
| 6518 | |
| 6519 | return MemberExpr::Create(Importer.getToContext(), ToBase, |
| 6520 | E->isArrow(), |
| 6521 | Importer.Import(E->getOperatorLoc()), |
| 6522 | Importer.Import(E->getQualifierLoc()), |
| 6523 | Importer.Import(E->getTemplateKeywordLoc()), |
| 6524 | ToMember, ToFoundDecl, ToMemberNameInfo, |
| 6525 | nullptr, T, E->getValueKind(), |
| 6526 | E->getObjectKind()); |
| 6527 | } |
| 6528 | |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 6529 | Expr *ASTNodeImporter::VisitCXXPseudoDestructorExpr( |
| 6530 | CXXPseudoDestructorExpr *E) { |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 6531 | Expr *BaseE = Importer.Import(E->getBase()); |
| 6532 | if (!BaseE) |
| 6533 | return nullptr; |
| 6534 | |
| 6535 | TypeSourceInfo *ScopeInfo = Importer.Import(E->getScopeTypeInfo()); |
| 6536 | if (!ScopeInfo && E->getScopeTypeInfo()) |
| 6537 | return nullptr; |
| 6538 | |
| 6539 | PseudoDestructorTypeStorage Storage; |
| 6540 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 6541 | IdentifierInfo *ToII = Importer.Import(FromII); |
| 6542 | if (!ToII) |
| 6543 | return nullptr; |
| 6544 | Storage = PseudoDestructorTypeStorage( |
| 6545 | ToII, Importer.Import(E->getDestroyedTypeLoc())); |
| 6546 | } else { |
| 6547 | TypeSourceInfo *TI = Importer.Import(E->getDestroyedTypeInfo()); |
| 6548 | if (!TI) |
| 6549 | return nullptr; |
| 6550 | Storage = PseudoDestructorTypeStorage(TI); |
| 6551 | } |
| 6552 | |
| 6553 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
| 6554 | Importer.getToContext(), BaseE, E->isArrow(), |
| 6555 | Importer.Import(E->getOperatorLoc()), |
| 6556 | Importer.Import(E->getQualifierLoc()), |
| 6557 | ScopeInfo, Importer.Import(E->getColonColonLoc()), |
| 6558 | Importer.Import(E->getTildeLoc()), Storage); |
| 6559 | } |
| 6560 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6561 | Expr *ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
| 6562 | CXXDependentScopeMemberExpr *E) { |
| 6563 | Expr *Base = nullptr; |
| 6564 | if (!E->isImplicitAccess()) { |
| 6565 | Base = Importer.Import(E->getBase()); |
| 6566 | if (!Base) |
| 6567 | return nullptr; |
| 6568 | } |
| 6569 | |
| 6570 | QualType BaseType = Importer.Import(E->getBaseType()); |
| 6571 | if (BaseType.isNull()) |
| 6572 | return nullptr; |
| 6573 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6574 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6575 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6576 | if (ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6577 | E->template_arguments(), ToTAInfo)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6578 | return nullptr; |
| 6579 | ResInfo = &ToTAInfo; |
| 6580 | } |
| 6581 | |
| 6582 | DeclarationName Name = Importer.Import(E->getMember()); |
| 6583 | if (!E->getMember().isEmpty() && Name.isEmpty()) |
| 6584 | return nullptr; |
| 6585 | |
| 6586 | DeclarationNameInfo MemberNameInfo(Name, Importer.Import(E->getMemberLoc())); |
| 6587 | // Import additional name location/type info. |
| 6588 | ImportDeclarationNameLoc(E->getMemberNameInfo(), MemberNameInfo); |
| 6589 | auto ToFQ = Importer.Import(E->getFirstQualifierFoundInScope()); |
| 6590 | if (!ToFQ && E->getFirstQualifierFoundInScope()) |
| 6591 | return nullptr; |
| 6592 | |
| 6593 | return CXXDependentScopeMemberExpr::Create( |
| 6594 | Importer.getToContext(), Base, BaseType, E->isArrow(), |
| 6595 | Importer.Import(E->getOperatorLoc()), |
| 6596 | Importer.Import(E->getQualifierLoc()), |
| 6597 | Importer.Import(E->getTemplateKeywordLoc()), |
| 6598 | cast_or_null<NamedDecl>(ToFQ), MemberNameInfo, ResInfo); |
| 6599 | } |
| 6600 | |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 6601 | Expr * |
| 6602 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
| 6603 | DeclarationName Name = Importer.Import(E->getDeclName()); |
| 6604 | if (!E->getDeclName().isEmpty() && Name.isEmpty()) |
| 6605 | return nullptr; |
| 6606 | |
| 6607 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getExprLoc())); |
| 6608 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6609 | |
| 6610 | TemplateArgumentListInfo ToTAInfo(Importer.Import(E->getLAngleLoc()), |
| 6611 | Importer.Import(E->getRAngleLoc())); |
| 6612 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 6613 | if (E->hasExplicitTemplateArgs()) { |
| 6614 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6615 | return nullptr; |
| 6616 | ResInfo = &ToTAInfo; |
| 6617 | } |
| 6618 | |
| 6619 | return DependentScopeDeclRefExpr::Create( |
| 6620 | Importer.getToContext(), Importer.Import(E->getQualifierLoc()), |
| 6621 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, ResInfo); |
| 6622 | } |
| 6623 | |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6624 | Expr *ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 6625 | CXXUnresolvedConstructExpr *CE) { |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6626 | unsigned NumArgs = CE->arg_size(); |
| 6627 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6628 | SmallVector<Expr *, 8> ToArgs(NumArgs); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6629 | if (ImportArrayChecked(CE->arg_begin(), CE->arg_end(), ToArgs.begin())) |
| 6630 | return nullptr; |
| 6631 | |
| 6632 | return CXXUnresolvedConstructExpr::Create( |
| 6633 | Importer.getToContext(), Importer.Import(CE->getTypeSourceInfo()), |
| 6634 | Importer.Import(CE->getLParenLoc()), llvm::makeArrayRef(ToArgs), |
| 6635 | Importer.Import(CE->getRParenLoc())); |
| 6636 | } |
| 6637 | |
| 6638 | Expr *ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6639 | auto *NamingClass = |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6640 | cast_or_null<CXXRecordDecl>(Importer.Import(E->getNamingClass())); |
| 6641 | if (E->getNamingClass() && !NamingClass) |
| 6642 | return nullptr; |
| 6643 | |
| 6644 | DeclarationName Name = Importer.Import(E->getName()); |
| 6645 | if (E->getName() && !Name) |
| 6646 | return nullptr; |
| 6647 | |
| 6648 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getNameLoc())); |
| 6649 | // Import additional name location/type info. |
| 6650 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6651 | |
| 6652 | UnresolvedSet<8> ToDecls; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6653 | for (auto *D : E->decls()) { |
| 6654 | if (auto *To = cast_or_null<NamedDecl>(Importer.Import(D))) |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6655 | ToDecls.addDecl(To); |
| 6656 | else |
| 6657 | return nullptr; |
| 6658 | } |
| 6659 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6660 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6661 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6662 | if (ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6663 | E->template_arguments(), ToTAInfo)) |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6664 | return nullptr; |
| 6665 | ResInfo = &ToTAInfo; |
| 6666 | } |
| 6667 | |
| 6668 | if (ResInfo || E->getTemplateKeywordLoc().isValid()) |
| 6669 | return UnresolvedLookupExpr::Create( |
| 6670 | Importer.getToContext(), NamingClass, |
| 6671 | Importer.Import(E->getQualifierLoc()), |
| 6672 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, E->requiresADL(), |
| 6673 | ResInfo, ToDecls.begin(), ToDecls.end()); |
| 6674 | |
| 6675 | return UnresolvedLookupExpr::Create( |
| 6676 | Importer.getToContext(), NamingClass, |
| 6677 | Importer.Import(E->getQualifierLoc()), NameInfo, E->requiresADL(), |
| 6678 | E->isOverloaded(), ToDecls.begin(), ToDecls.end()); |
| 6679 | } |
| 6680 | |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 6681 | Expr *ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| 6682 | DeclarationName Name = Importer.Import(E->getName()); |
| 6683 | if (!E->getName().isEmpty() && Name.isEmpty()) |
| 6684 | return nullptr; |
| 6685 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getNameLoc())); |
| 6686 | // Import additional name location/type info. |
| 6687 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6688 | |
| 6689 | QualType BaseType = Importer.Import(E->getType()); |
| 6690 | if (!E->getType().isNull() && BaseType.isNull()) |
| 6691 | return nullptr; |
| 6692 | |
| 6693 | UnresolvedSet<8> ToDecls; |
| 6694 | for (Decl *D : E->decls()) { |
| 6695 | if (NamedDecl *To = cast_or_null<NamedDecl>(Importer.Import(D))) |
| 6696 | ToDecls.addDecl(To); |
| 6697 | else |
| 6698 | return nullptr; |
| 6699 | } |
| 6700 | |
| 6701 | TemplateArgumentListInfo ToTAInfo; |
| 6702 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 6703 | if (E->hasExplicitTemplateArgs()) { |
| 6704 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6705 | return nullptr; |
| 6706 | ResInfo = &ToTAInfo; |
| 6707 | } |
| 6708 | |
| 6709 | Expr *BaseE = E->isImplicitAccess() ? nullptr : Importer.Import(E->getBase()); |
| 6710 | if (!BaseE && !E->isImplicitAccess() && E->getBase()) { |
| 6711 | return nullptr; |
| 6712 | } |
| 6713 | |
| 6714 | return UnresolvedMemberExpr::Create( |
| 6715 | Importer.getToContext(), E->hasUnresolvedUsing(), BaseE, BaseType, |
| 6716 | E->isArrow(), Importer.Import(E->getOperatorLoc()), |
| 6717 | Importer.Import(E->getQualifierLoc()), |
| 6718 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, ResInfo, |
| 6719 | ToDecls.begin(), ToDecls.end()); |
| 6720 | } |
| 6721 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6722 | Expr *ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 6723 | QualType T = Importer.Import(E->getType()); |
| 6724 | if (T.isNull()) |
| 6725 | return nullptr; |
| 6726 | |
| 6727 | Expr *ToCallee = Importer.Import(E->getCallee()); |
| 6728 | if (!ToCallee && E->getCallee()) |
| 6729 | return nullptr; |
| 6730 | |
| 6731 | unsigned NumArgs = E->getNumArgs(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6732 | SmallVector<Expr *, 2> ToArgs(NumArgs); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6733 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
| 6734 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6735 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6736 | auto **ToArgs_Copied = new (Importer.getToContext()) Expr*[NumArgs]; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6737 | |
| 6738 | for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) |
| 6739 | ToArgs_Copied[ai] = ToArgs[ai]; |
| 6740 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6741 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
| 6742 | return new (Importer.getToContext()) CXXOperatorCallExpr( |
| 6743 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, T, |
| 6744 | OCE->getValueKind(), Importer.Import(OCE->getRParenLoc()), |
| 6745 | OCE->getFPFeatures()); |
| 6746 | } |
| 6747 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6748 | return new (Importer.getToContext()) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6749 | CallExpr(Importer.getToContext(), ToCallee, |
Craig Topper | c005cc0 | 2015-09-27 03:44:08 +0000 | [diff] [blame] | 6750 | llvm::makeArrayRef(ToArgs_Copied, NumArgs), T, E->getValueKind(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6751 | Importer.Import(E->getRParenLoc())); |
| 6752 | } |
| 6753 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6754 | Optional<LambdaCapture> |
| 6755 | ASTNodeImporter::ImportLambdaCapture(const LambdaCapture &From) { |
| 6756 | VarDecl *Var = nullptr; |
| 6757 | if (From.capturesVariable()) { |
| 6758 | Var = cast_or_null<VarDecl>(Importer.Import(From.getCapturedVar())); |
| 6759 | if (!Var) |
| 6760 | return None; |
| 6761 | } |
| 6762 | |
| 6763 | return LambdaCapture(Importer.Import(From.getLocation()), From.isImplicit(), |
| 6764 | From.getCaptureKind(), Var, |
| 6765 | From.isPackExpansion() |
| 6766 | ? Importer.Import(From.getEllipsisLoc()) |
| 6767 | : SourceLocation()); |
| 6768 | } |
| 6769 | |
| 6770 | Expr *ASTNodeImporter::VisitLambdaExpr(LambdaExpr *LE) { |
| 6771 | CXXRecordDecl *FromClass = LE->getLambdaClass(); |
| 6772 | auto *ToClass = dyn_cast_or_null<CXXRecordDecl>(Importer.Import(FromClass)); |
| 6773 | if (!ToClass) |
| 6774 | return nullptr; |
| 6775 | |
| 6776 | // NOTE: lambda classes are created with BeingDefined flag set up. |
| 6777 | // It means that ImportDefinition doesn't work for them and we should fill it |
| 6778 | // manually. |
| 6779 | if (ToClass->isBeingDefined()) { |
| 6780 | for (auto FromField : FromClass->fields()) { |
| 6781 | auto *ToField = cast_or_null<FieldDecl>(Importer.Import(FromField)); |
| 6782 | if (!ToField) |
| 6783 | return nullptr; |
| 6784 | } |
| 6785 | } |
| 6786 | |
| 6787 | auto *ToCallOp = dyn_cast_or_null<CXXMethodDecl>( |
| 6788 | Importer.Import(LE->getCallOperator())); |
| 6789 | if (!ToCallOp) |
| 6790 | return nullptr; |
| 6791 | |
| 6792 | ToClass->completeDefinition(); |
| 6793 | |
| 6794 | unsigned NumCaptures = LE->capture_size(); |
| 6795 | SmallVector<LambdaCapture, 8> Captures; |
| 6796 | Captures.reserve(NumCaptures); |
| 6797 | for (const auto &FromCapture : LE->captures()) { |
| 6798 | if (auto ToCapture = ImportLambdaCapture(FromCapture)) |
| 6799 | Captures.push_back(*ToCapture); |
| 6800 | else |
| 6801 | return nullptr; |
| 6802 | } |
| 6803 | |
| 6804 | SmallVector<Expr *, 8> InitCaptures(NumCaptures); |
| 6805 | if (ImportContainerChecked(LE->capture_inits(), InitCaptures)) |
| 6806 | return nullptr; |
| 6807 | |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 6808 | return LambdaExpr::Create( |
| 6809 | Importer.getToContext(), ToClass, |
| 6810 | Importer.Import(LE->getIntroducerRange()), LE->getCaptureDefault(), |
| 6811 | Importer.Import(LE->getCaptureDefaultLoc()), Captures, |
| 6812 | LE->hasExplicitParameters(), LE->hasExplicitResultType(), InitCaptures, |
| 6813 | Importer.Import(LE->getEndLoc()), LE->containsUnexpandedParameterPack()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6814 | } |
| 6815 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6816 | Expr *ASTNodeImporter::VisitInitListExpr(InitListExpr *ILE) { |
| 6817 | QualType T = Importer.Import(ILE->getType()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6818 | if (T.isNull()) |
| 6819 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6820 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6821 | SmallVector<Expr *, 4> Exprs(ILE->getNumInits()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6822 | if (ImportContainerChecked(ILE->inits(), Exprs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6823 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6824 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6825 | ASTContext &ToCtx = Importer.getToContext(); |
| 6826 | InitListExpr *To = new (ToCtx) InitListExpr( |
| 6827 | ToCtx, Importer.Import(ILE->getLBraceLoc()), |
| 6828 | Exprs, Importer.Import(ILE->getLBraceLoc())); |
| 6829 | To->setType(T); |
| 6830 | |
| 6831 | if (ILE->hasArrayFiller()) { |
| 6832 | Expr *Filler = Importer.Import(ILE->getArrayFiller()); |
| 6833 | if (!Filler) |
| 6834 | return nullptr; |
| 6835 | To->setArrayFiller(Filler); |
| 6836 | } |
| 6837 | |
| 6838 | if (FieldDecl *FromFD = ILE->getInitializedFieldInUnion()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6839 | auto *ToFD = cast_or_null<FieldDecl>(Importer.Import(FromFD)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6840 | if (!ToFD) |
| 6841 | return nullptr; |
| 6842 | To->setInitializedFieldInUnion(ToFD); |
| 6843 | } |
| 6844 | |
| 6845 | if (InitListExpr *SyntForm = ILE->getSyntacticForm()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6846 | auto *ToSyntForm = cast_or_null<InitListExpr>(Importer.Import(SyntForm)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6847 | if (!ToSyntForm) |
| 6848 | return nullptr; |
| 6849 | To->setSyntacticForm(ToSyntForm); |
| 6850 | } |
| 6851 | |
| 6852 | To->sawArrayRangeDesignator(ILE->hadArrayRangeDesignator()); |
| 6853 | To->setValueDependent(ILE->isValueDependent()); |
| 6854 | To->setInstantiationDependent(ILE->isInstantiationDependent()); |
| 6855 | |
| 6856 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6857 | } |
| 6858 | |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 6859 | Expr *ASTNodeImporter::VisitCXXStdInitializerListExpr( |
| 6860 | CXXStdInitializerListExpr *E) { |
| 6861 | QualType T = Importer.Import(E->getType()); |
| 6862 | if (T.isNull()) |
| 6863 | return nullptr; |
| 6864 | |
| 6865 | Expr *SE = Importer.Import(E->getSubExpr()); |
| 6866 | if (!SE) |
| 6867 | return nullptr; |
| 6868 | |
| 6869 | return new (Importer.getToContext()) CXXStdInitializerListExpr(T, SE); |
| 6870 | } |
| 6871 | |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 6872 | Expr *ASTNodeImporter::VisitCXXInheritedCtorInitExpr( |
| 6873 | CXXInheritedCtorInitExpr *E) { |
| 6874 | QualType T = Importer.Import(E->getType()); |
| 6875 | if (T.isNull()) |
| 6876 | return nullptr; |
| 6877 | |
| 6878 | auto *Ctor = cast_or_null<CXXConstructorDecl>(Importer.Import( |
| 6879 | E->getConstructor())); |
| 6880 | if (!Ctor) |
| 6881 | return nullptr; |
| 6882 | |
| 6883 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( |
| 6884 | Importer.Import(E->getLocation()), T, Ctor, |
| 6885 | E->constructsVBase(), E->inheritedFromVBase()); |
| 6886 | } |
| 6887 | |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 6888 | Expr *ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 6889 | QualType ToType = Importer.Import(E->getType()); |
| 6890 | if (ToType.isNull()) |
| 6891 | return nullptr; |
| 6892 | |
| 6893 | Expr *ToCommon = Importer.Import(E->getCommonExpr()); |
| 6894 | if (!ToCommon && E->getCommonExpr()) |
| 6895 | return nullptr; |
| 6896 | |
| 6897 | Expr *ToSubExpr = Importer.Import(E->getSubExpr()); |
| 6898 | if (!ToSubExpr && E->getSubExpr()) |
| 6899 | return nullptr; |
| 6900 | |
| 6901 | return new (Importer.getToContext()) |
| 6902 | ArrayInitLoopExpr(ToType, ToCommon, ToSubExpr); |
| 6903 | } |
| 6904 | |
| 6905 | Expr *ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 6906 | QualType ToType = Importer.Import(E->getType()); |
| 6907 | if (ToType.isNull()) |
| 6908 | return nullptr; |
| 6909 | return new (Importer.getToContext()) ArrayInitIndexExpr(ToType); |
| 6910 | } |
| 6911 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6912 | Expr *ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6913 | auto *ToField = dyn_cast_or_null<FieldDecl>(Importer.Import(DIE->getField())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6914 | if (!ToField && DIE->getField()) |
| 6915 | return nullptr; |
| 6916 | |
| 6917 | return CXXDefaultInitExpr::Create( |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6918 | Importer.getToContext(), Importer.Import(DIE->getBeginLoc()), ToField); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6919 | } |
| 6920 | |
| 6921 | Expr *ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 6922 | QualType ToType = Importer.Import(E->getType()); |
| 6923 | if (ToType.isNull() && !E->getType().isNull()) |
| 6924 | return nullptr; |
| 6925 | ExprValueKind VK = E->getValueKind(); |
| 6926 | CastKind CK = E->getCastKind(); |
| 6927 | Expr *ToOp = Importer.Import(E->getSubExpr()); |
| 6928 | if (!ToOp && E->getSubExpr()) |
| 6929 | return nullptr; |
| 6930 | CXXCastPath BasePath; |
| 6931 | if (ImportCastPath(E, BasePath)) |
| 6932 | return nullptr; |
| 6933 | TypeSourceInfo *ToWritten = Importer.Import(E->getTypeInfoAsWritten()); |
| 6934 | SourceLocation ToOperatorLoc = Importer.Import(E->getOperatorLoc()); |
| 6935 | SourceLocation ToRParenLoc = Importer.Import(E->getRParenLoc()); |
| 6936 | SourceRange ToAngleBrackets = Importer.Import(E->getAngleBrackets()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6937 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6938 | if (isa<CXXStaticCastExpr>(E)) { |
| 6939 | return CXXStaticCastExpr::Create( |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6940 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6941 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6942 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 6943 | return CXXDynamicCastExpr::Create( |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6944 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6945 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6946 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 6947 | return CXXReinterpretCastExpr::Create( |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6948 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6949 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Raphael Isemann | c705bb8 | 2018-08-20 16:20:01 +0000 | [diff] [blame] | 6950 | } else if (isa<CXXConstCastExpr>(E)) { |
| 6951 | return CXXConstCastExpr::Create(Importer.getToContext(), ToType, VK, ToOp, |
| 6952 | ToWritten, ToOperatorLoc, ToRParenLoc, |
| 6953 | ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6954 | } else { |
| 6955 | return nullptr; |
| 6956 | } |
| 6957 | } |
| 6958 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6959 | Expr *ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
| 6960 | SubstNonTypeTemplateParmExpr *E) { |
| 6961 | QualType T = Importer.Import(E->getType()); |
| 6962 | if (T.isNull()) |
| 6963 | return nullptr; |
| 6964 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6965 | auto *Param = cast_or_null<NonTypeTemplateParmDecl>( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6966 | Importer.Import(E->getParameter())); |
| 6967 | if (!Param) |
| 6968 | return nullptr; |
| 6969 | |
| 6970 | Expr *Replacement = Importer.Import(E->getReplacement()); |
| 6971 | if (!Replacement) |
| 6972 | return nullptr; |
| 6973 | |
| 6974 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
| 6975 | T, E->getValueKind(), Importer.Import(E->getExprLoc()), Param, |
| 6976 | Replacement); |
| 6977 | } |
| 6978 | |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 6979 | Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 6980 | QualType ToType = Importer.Import(E->getType()); |
| 6981 | if (ToType.isNull()) |
| 6982 | return nullptr; |
| 6983 | |
| 6984 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
| 6985 | if (ImportContainerChecked(E->getArgs(), ToArgs)) |
| 6986 | return nullptr; |
| 6987 | |
| 6988 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 6989 | // Value is always false. |
| 6990 | bool ToValue = false; |
| 6991 | if (!E->isValueDependent()) |
| 6992 | ToValue = E->getValue(); |
| 6993 | |
| 6994 | return TypeTraitExpr::Create( |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6995 | Importer.getToContext(), ToType, Importer.Import(E->getBeginLoc()), |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 6996 | E->getTrait(), ToArgs, Importer.Import(E->getEndLoc()), ToValue); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 6997 | } |
| 6998 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6999 | Expr *ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 7000 | QualType ToType = Importer.Import(E->getType()); |
| 7001 | if (ToType.isNull()) |
| 7002 | return nullptr; |
| 7003 | |
| 7004 | if (E->isTypeOperand()) { |
| 7005 | TypeSourceInfo *TSI = Importer.Import(E->getTypeOperandSourceInfo()); |
| 7006 | if (!TSI) |
| 7007 | return nullptr; |
| 7008 | |
| 7009 | return new (Importer.getToContext()) |
| 7010 | CXXTypeidExpr(ToType, TSI, Importer.Import(E->getSourceRange())); |
| 7011 | } |
| 7012 | |
| 7013 | Expr *Op = Importer.Import(E->getExprOperand()); |
| 7014 | if (!Op) |
| 7015 | return nullptr; |
| 7016 | |
| 7017 | return new (Importer.getToContext()) |
| 7018 | CXXTypeidExpr(ToType, Op, Importer.Import(E->getSourceRange())); |
| 7019 | } |
| 7020 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7021 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 7022 | CXXMethodDecl *FromMethod) { |
| 7023 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) |
| 7024 | ToMethod->addOverriddenMethod( |
| 7025 | cast<CXXMethodDecl>(Importer.Import(const_cast<CXXMethodDecl*>( |
| 7026 | FromOverriddenMethod)))); |
| 7027 | } |
| 7028 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7029 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7030 | ASTContext &FromContext, FileManager &FromFileManager, |
| 7031 | bool MinimalImport) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7032 | : ToContext(ToContext), FromContext(FromContext), |
| 7033 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| 7034 | Minimal(MinimalImport) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7035 | ImportedDecls[FromContext.getTranslationUnitDecl()] |
| 7036 | = ToContext.getTranslationUnitDecl(); |
| 7037 | } |
| 7038 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7039 | ASTImporter::~ASTImporter() = default; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7040 | |
| 7041 | QualType ASTImporter::Import(QualType FromT) { |
| 7042 | if (FromT.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7043 | return {}; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7044 | |
| 7045 | const Type *fromTy = FromT.getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7046 | |
| 7047 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7048 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
| 7049 | = ImportedTypes.find(fromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7050 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7051 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7052 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7053 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7054 | ASTNodeImporter Importer(*this); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7055 | QualType ToT = Importer.Visit(fromTy); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7056 | if (ToT.isNull()) |
| 7057 | return ToT; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7058 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7059 | // Record the imported type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7060 | ImportedTypes[fromTy] = ToT.getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7061 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7062 | return ToContext.getQualifiedType(ToT, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7063 | } |
| 7064 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7065 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7066 | if (!FromTSI) |
| 7067 | return FromTSI; |
| 7068 | |
| 7069 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 7070 | // 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] | 7071 | QualType T = Import(FromTSI->getType()); |
| 7072 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7073 | return nullptr; |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7074 | |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7075 | return ToContext.getTrivialTypeSourceInfo( |
| 7076 | T, Import(FromTSI->getTypeLoc().getBeginLoc())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7077 | } |
| 7078 | |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 7079 | Attr *ASTImporter::Import(const Attr *FromAttr) { |
| 7080 | Attr *ToAttr = FromAttr->clone(ToContext); |
| 7081 | ToAttr->setRange(Import(FromAttr->getRange())); |
| 7082 | return ToAttr; |
| 7083 | } |
| 7084 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7085 | Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) { |
| 7086 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
| 7087 | if (Pos != ImportedDecls.end()) { |
| 7088 | Decl *ToD = Pos->second; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7089 | // FIXME: move this call to ImportDeclParts(). |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7090 | ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD); |
| 7091 | return ToD; |
| 7092 | } else { |
| 7093 | return nullptr; |
| 7094 | } |
| 7095 | } |
| 7096 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7097 | Decl *ASTImporter::Import(Decl *FromD) { |
| 7098 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7099 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7100 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7101 | ASTNodeImporter Importer(*this); |
| 7102 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7103 | // Check whether we've already imported this declaration. |
| 7104 | Decl *ToD = GetAlreadyImportedOrNull(FromD); |
| 7105 | if (ToD) { |
| 7106 | // If FromD has some updated flags after last import, apply it |
| 7107 | updateFlags(FromD, ToD); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7108 | return ToD; |
| 7109 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7110 | |
| 7111 | // Import the type. |
| 7112 | ToD = Importer.Visit(FromD); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7113 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7114 | return nullptr; |
| 7115 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7116 | // Notify subclasses. |
| 7117 | Imported(FromD, ToD); |
| 7118 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7119 | return ToD; |
| 7120 | } |
| 7121 | |
| 7122 | DeclContext *ASTImporter::ImportContext(DeclContext *FromDC) { |
| 7123 | if (!FromDC) |
| 7124 | return FromDC; |
| 7125 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7126 | auto *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7127 | if (!ToDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7128 | return nullptr; |
| 7129 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7130 | // When we're using a record/enum/Objective-C class/protocol as a context, we |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7131 | // need it to have a definition. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7132 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 7133 | auto *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7134 | if (ToRecord->isCompleteDefinition()) { |
| 7135 | // Do nothing. |
| 7136 | } else if (FromRecord->isCompleteDefinition()) { |
| 7137 | ASTNodeImporter(*this).ImportDefinition(FromRecord, ToRecord, |
| 7138 | ASTNodeImporter::IDK_Basic); |
| 7139 | } else { |
| 7140 | CompleteDecl(ToRecord); |
| 7141 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7142 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 7143 | auto *FromEnum = cast<EnumDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7144 | if (ToEnum->isCompleteDefinition()) { |
| 7145 | // Do nothing. |
| 7146 | } else if (FromEnum->isCompleteDefinition()) { |
| 7147 | ASTNodeImporter(*this).ImportDefinition(FromEnum, ToEnum, |
| 7148 | ASTNodeImporter::IDK_Basic); |
| 7149 | } else { |
| 7150 | CompleteDecl(ToEnum); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7151 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7152 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 7153 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7154 | if (ToClass->getDefinition()) { |
| 7155 | // Do nothing. |
| 7156 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
| 7157 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToClass, |
| 7158 | ASTNodeImporter::IDK_Basic); |
| 7159 | } else { |
| 7160 | CompleteDecl(ToClass); |
| 7161 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7162 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 7163 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7164 | if (ToProto->getDefinition()) { |
| 7165 | // Do nothing. |
| 7166 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
| 7167 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToProto, |
| 7168 | ASTNodeImporter::IDK_Basic); |
| 7169 | } else { |
| 7170 | CompleteDecl(ToProto); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7171 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7172 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7173 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7174 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7175 | } |
| 7176 | |
| 7177 | Expr *ASTImporter::Import(Expr *FromE) { |
| 7178 | if (!FromE) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7179 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7180 | |
| 7181 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); |
| 7182 | } |
| 7183 | |
| 7184 | Stmt *ASTImporter::Import(Stmt *FromS) { |
| 7185 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7186 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7187 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7188 | // Check whether we've already imported this declaration. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7189 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 7190 | if (Pos != ImportedStmts.end()) |
| 7191 | return Pos->second; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7192 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7193 | // Import the type |
| 7194 | ASTNodeImporter Importer(*this); |
| 7195 | Stmt *ToS = Importer.Visit(FromS); |
| 7196 | if (!ToS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7197 | return nullptr; |
| 7198 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7199 | // Record the imported declaration. |
| 7200 | ImportedStmts[FromS] = ToS; |
| 7201 | return ToS; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7202 | } |
| 7203 | |
| 7204 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| 7205 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7206 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7207 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7208 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); |
| 7209 | |
| 7210 | switch (FromNNS->getKind()) { |
| 7211 | case NestedNameSpecifier::Identifier: |
| 7212 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { |
| 7213 | return NestedNameSpecifier::Create(ToContext, prefix, II); |
| 7214 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7215 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7216 | |
| 7217 | case NestedNameSpecifier::Namespace: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7218 | if (auto *NS = |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7219 | cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7220 | return NestedNameSpecifier::Create(ToContext, prefix, NS); |
| 7221 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7222 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7223 | |
| 7224 | case NestedNameSpecifier::NamespaceAlias: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7225 | if (auto *NSAD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7226 | cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7227 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); |
| 7228 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7229 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7230 | |
| 7231 | case NestedNameSpecifier::Global: |
| 7232 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 7233 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7234 | case NestedNameSpecifier::Super: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7235 | if (auto *RD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7236 | cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) { |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7237 | return NestedNameSpecifier::SuperSpecifier(ToContext, RD); |
| 7238 | } |
| 7239 | return nullptr; |
| 7240 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7241 | case NestedNameSpecifier::TypeSpec: |
| 7242 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7243 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); |
| 7244 | if (!T.isNull()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7245 | bool bTemplate = FromNNS->getKind() == |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7246 | NestedNameSpecifier::TypeSpecWithTemplate; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7247 | return NestedNameSpecifier::Create(ToContext, prefix, |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7248 | bTemplate, T.getTypePtr()); |
| 7249 | } |
| 7250 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7251 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7252 | } |
| 7253 | |
| 7254 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7255 | } |
| 7256 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 7257 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7258 | // Copied from NestedNameSpecifier mostly. |
| 7259 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 7260 | NestedNameSpecifierLoc NNS = FromNNS; |
| 7261 | |
| 7262 | // Push each of the nested-name-specifiers's onto a stack for |
| 7263 | // serialization in reverse order. |
| 7264 | while (NNS) { |
| 7265 | NestedNames.push_back(NNS); |
| 7266 | NNS = NNS.getPrefix(); |
| 7267 | } |
| 7268 | |
| 7269 | NestedNameSpecifierLocBuilder Builder; |
| 7270 | |
| 7271 | while (!NestedNames.empty()) { |
| 7272 | NNS = NestedNames.pop_back_val(); |
| 7273 | NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier()); |
| 7274 | if (!Spec) |
| 7275 | return NestedNameSpecifierLoc(); |
| 7276 | |
| 7277 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| 7278 | switch (Kind) { |
| 7279 | case NestedNameSpecifier::Identifier: |
| 7280 | Builder.Extend(getToContext(), |
| 7281 | Spec->getAsIdentifier(), |
| 7282 | Import(NNS.getLocalBeginLoc()), |
| 7283 | Import(NNS.getLocalEndLoc())); |
| 7284 | break; |
| 7285 | |
| 7286 | case NestedNameSpecifier::Namespace: |
| 7287 | Builder.Extend(getToContext(), |
| 7288 | Spec->getAsNamespace(), |
| 7289 | Import(NNS.getLocalBeginLoc()), |
| 7290 | Import(NNS.getLocalEndLoc())); |
| 7291 | break; |
| 7292 | |
| 7293 | case NestedNameSpecifier::NamespaceAlias: |
| 7294 | Builder.Extend(getToContext(), |
| 7295 | Spec->getAsNamespaceAlias(), |
| 7296 | Import(NNS.getLocalBeginLoc()), |
| 7297 | Import(NNS.getLocalEndLoc())); |
| 7298 | break; |
| 7299 | |
| 7300 | case NestedNameSpecifier::TypeSpec: |
| 7301 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7302 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| 7303 | QualType(Spec->getAsType(), 0)); |
| 7304 | Builder.Extend(getToContext(), |
| 7305 | Import(NNS.getLocalBeginLoc()), |
| 7306 | TSI->getTypeLoc(), |
| 7307 | Import(NNS.getLocalEndLoc())); |
| 7308 | break; |
| 7309 | } |
| 7310 | |
| 7311 | case NestedNameSpecifier::Global: |
| 7312 | Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc())); |
| 7313 | break; |
| 7314 | |
| 7315 | case NestedNameSpecifier::Super: { |
| 7316 | SourceRange ToRange = Import(NNS.getSourceRange()); |
| 7317 | Builder.MakeSuper(getToContext(), |
| 7318 | Spec->getAsRecordDecl(), |
| 7319 | ToRange.getBegin(), |
| 7320 | ToRange.getEnd()); |
| 7321 | } |
| 7322 | } |
| 7323 | } |
| 7324 | |
| 7325 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 7326 | } |
| 7327 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7328 | TemplateName ASTImporter::Import(TemplateName From) { |
| 7329 | switch (From.getKind()) { |
| 7330 | case TemplateName::Template: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7331 | if (auto *ToTemplate = |
| 7332 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7333 | return TemplateName(ToTemplate); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7334 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7335 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7336 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7337 | case TemplateName::OverloadedTemplate: { |
| 7338 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 7339 | UnresolvedSet<2> ToTemplates; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7340 | for (auto *I : *FromStorage) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7341 | if (auto *To = cast_or_null<NamedDecl>(Import(I))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7342 | ToTemplates.addDecl(To); |
| 7343 | else |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7344 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7345 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7346 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7347 | ToTemplates.end()); |
| 7348 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7349 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7350 | case TemplateName::QualifiedTemplate: { |
| 7351 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| 7352 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); |
| 7353 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7354 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7355 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7356 | if (auto *ToTemplate = |
| 7357 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7358 | return ToContext.getQualifiedTemplateName(Qualifier, |
| 7359 | QTN->hasTemplateKeyword(), |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7360 | ToTemplate); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7361 | |
| 7362 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7363 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7364 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7365 | case TemplateName::DependentTemplate: { |
| 7366 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| 7367 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); |
| 7368 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7369 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7370 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7371 | if (DTN->isIdentifier()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7372 | return ToContext.getDependentTemplateName(Qualifier, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7373 | Import(DTN->getIdentifier())); |
| 7374 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7375 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7376 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); |
| 7377 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7378 | |
| 7379 | case TemplateName::SubstTemplateTemplateParm: { |
| 7380 | SubstTemplateTemplateParmStorage *subst |
| 7381 | = From.getAsSubstTemplateTemplateParm(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7382 | auto *param = |
| 7383 | cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7384 | if (!param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7385 | return {}; |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7386 | |
| 7387 | TemplateName replacement = Import(subst->getReplacement()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7388 | if (replacement.isNull()) |
| 7389 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7390 | |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7391 | return ToContext.getSubstTemplateTemplateParm(param, replacement); |
| 7392 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7393 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7394 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 7395 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 7396 | = From.getAsSubstTemplateTemplateParmPack(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7397 | auto *Param = |
| 7398 | cast_or_null<TemplateTemplateParmDecl>( |
| 7399 | Import(SubstPack->getParameterPack())); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7400 | if (!Param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7401 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7402 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7403 | ASTNodeImporter Importer(*this); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7404 | TemplateArgument ArgPack |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7405 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 7406 | if (ArgPack.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7407 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7408 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7409 | return ToContext.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 7410 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7411 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7412 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7413 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7414 | } |
| 7415 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7416 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { |
| 7417 | if (FromLoc.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7418 | return {}; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7419 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7420 | SourceManager &FromSM = FromContext.getSourceManager(); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7421 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7422 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 7423 | FileID ToFileID = Import(Decomposed.first); |
| 7424 | if (ToFileID.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7425 | return {}; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7426 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 7427 | return ToSM.getComposedLoc(ToFileID, Decomposed.second); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7428 | } |
| 7429 | |
| 7430 | SourceRange ASTImporter::Import(SourceRange FromRange) { |
| 7431 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); |
| 7432 | } |
| 7433 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7434 | FileID ASTImporter::Import(FileID FromID) { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7435 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7436 | if (Pos != ImportedFileIDs.end()) |
| 7437 | return Pos->second; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7438 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7439 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 7440 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 7441 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7442 | |
| 7443 | // Map the FromID to the "to" source manager. |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7444 | FileID ToID; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7445 | if (FromSLoc.isExpansion()) { |
| 7446 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); |
| 7447 | SourceLocation ToSpLoc = Import(FromEx.getSpellingLoc()); |
| 7448 | SourceLocation ToExLocS = Import(FromEx.getExpansionLocStart()); |
| 7449 | unsigned TokenLen = FromSM.getFileIDSize(FromID); |
| 7450 | SourceLocation MLoc; |
| 7451 | if (FromEx.isMacroArgExpansion()) { |
| 7452 | MLoc = ToSM.createMacroArgExpansionLoc(ToSpLoc, ToExLocS, TokenLen); |
| 7453 | } else { |
| 7454 | SourceLocation ToExLocE = Import(FromEx.getExpansionLocEnd()); |
| 7455 | MLoc = ToSM.createExpansionLoc(ToSpLoc, ToExLocS, ToExLocE, TokenLen, |
| 7456 | FromEx.isExpansionTokenRange()); |
| 7457 | } |
| 7458 | ToID = ToSM.getFileID(MLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7459 | } else { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7460 | // Include location of this file. |
| 7461 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| 7462 | |
| 7463 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
| 7464 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
| 7465 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 7466 | // disk again |
| 7467 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 7468 | // than mmap the files several times. |
| 7469 | const FileEntry *Entry = |
| 7470 | ToFileManager.getFile(Cache->OrigEntry->getName()); |
| 7471 | if (!Entry) |
| 7472 | return {}; |
| 7473 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, |
| 7474 | FromSLoc.getFile().getFileCharacteristic()); |
| 7475 | } else { |
| 7476 | // FIXME: We want to re-use the existing MemoryBuffer! |
| 7477 | const llvm::MemoryBuffer *FromBuf = |
| 7478 | Cache->getBuffer(FromContext.getDiagnostics(), FromSM); |
| 7479 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = |
| 7480 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
| 7481 | FromBuf->getBufferIdentifier()); |
| 7482 | ToID = ToSM.createFileID(std::move(ToBuf), |
| 7483 | FromSLoc.getFile().getFileCharacteristic()); |
| 7484 | } |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7485 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7486 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 7487 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7488 | return ToID; |
| 7489 | } |
| 7490 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7491 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { |
| 7492 | Expr *ToExpr = Import(From->getInit()); |
| 7493 | if (!ToExpr && From->getInit()) |
| 7494 | return nullptr; |
| 7495 | |
| 7496 | if (From->isBaseInitializer()) { |
| 7497 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 7498 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 7499 | return nullptr; |
| 7500 | |
| 7501 | return new (ToContext) CXXCtorInitializer( |
| 7502 | ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()), |
| 7503 | ToExpr, Import(From->getRParenLoc()), |
| 7504 | From->isPackExpansion() ? Import(From->getEllipsisLoc()) |
| 7505 | : SourceLocation()); |
| 7506 | } else if (From->isMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7507 | auto *ToField = cast_or_null<FieldDecl>(Import(From->getMember())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7508 | if (!ToField && From->getMember()) |
| 7509 | return nullptr; |
| 7510 | |
| 7511 | return new (ToContext) CXXCtorInitializer( |
| 7512 | ToContext, ToField, Import(From->getMemberLocation()), |
| 7513 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 7514 | } else if (From->isIndirectMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7515 | auto *ToIField = cast_or_null<IndirectFieldDecl>( |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7516 | Import(From->getIndirectMember())); |
| 7517 | if (!ToIField && From->getIndirectMember()) |
| 7518 | return nullptr; |
| 7519 | |
| 7520 | return new (ToContext) CXXCtorInitializer( |
| 7521 | ToContext, ToIField, Import(From->getMemberLocation()), |
| 7522 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 7523 | } else if (From->isDelegatingInitializer()) { |
| 7524 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 7525 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 7526 | return nullptr; |
| 7527 | |
| 7528 | return new (ToContext) |
| 7529 | CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()), |
| 7530 | ToExpr, Import(From->getRParenLoc())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7531 | } else { |
| 7532 | return nullptr; |
| 7533 | } |
| 7534 | } |
| 7535 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7536 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| 7537 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 7538 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 7539 | return Pos->second; |
| 7540 | |
| 7541 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| 7542 | Import(BaseSpec->getSourceRange()), |
| 7543 | BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 7544 | BaseSpec->getAccessSpecifierAsWritten(), |
| 7545 | Import(BaseSpec->getTypeSourceInfo()), |
| 7546 | Import(BaseSpec->getEllipsisLoc())); |
| 7547 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 7548 | return Imported; |
| 7549 | } |
| 7550 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7551 | void ASTImporter::ImportDefinition(Decl *From) { |
| 7552 | Decl *To = Import(From); |
| 7553 | if (!To) |
| 7554 | return; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7555 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7556 | if (auto *FromDC = cast<DeclContext>(From)) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7557 | ASTNodeImporter Importer(*this); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7558 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7559 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7560 | if (!ToRecord->getDefinition()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7561 | Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7562 | ASTNodeImporter::IDK_Everything); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7563 | return; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7564 | } |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7565 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7566 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7567 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7568 | if (!ToEnum->getDefinition()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7569 | Importer.ImportDefinition(cast<EnumDecl>(FromDC), ToEnum, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7570 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7571 | return; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7572 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7573 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7574 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7575 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7576 | if (!ToIFace->getDefinition()) { |
| 7577 | Importer.ImportDefinition(cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7578 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7579 | return; |
| 7580 | } |
| 7581 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7582 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7583 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7584 | if (!ToProto->getDefinition()) { |
| 7585 | Importer.ImportDefinition(cast<ObjCProtocolDecl>(FromDC), ToProto, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7586 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7587 | return; |
| 7588 | } |
| 7589 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7590 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7591 | Importer.ImportDeclContext(FromDC, true); |
| 7592 | } |
| 7593 | } |
| 7594 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7595 | DeclarationName ASTImporter::Import(DeclarationName FromName) { |
| 7596 | if (!FromName) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7597 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7598 | |
| 7599 | switch (FromName.getNameKind()) { |
| 7600 | case DeclarationName::Identifier: |
| 7601 | return Import(FromName.getAsIdentifierInfo()); |
| 7602 | |
| 7603 | case DeclarationName::ObjCZeroArgSelector: |
| 7604 | case DeclarationName::ObjCOneArgSelector: |
| 7605 | case DeclarationName::ObjCMultiArgSelector: |
| 7606 | return Import(FromName.getObjCSelector()); |
| 7607 | |
| 7608 | case DeclarationName::CXXConstructorName: { |
| 7609 | QualType T = Import(FromName.getCXXNameType()); |
| 7610 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7611 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7612 | |
| 7613 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 7614 | ToContext.getCanonicalType(T)); |
| 7615 | } |
| 7616 | |
| 7617 | case DeclarationName::CXXDestructorName: { |
| 7618 | QualType T = Import(FromName.getCXXNameType()); |
| 7619 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7620 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7621 | |
| 7622 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 7623 | ToContext.getCanonicalType(T)); |
| 7624 | } |
| 7625 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7626 | case DeclarationName::CXXDeductionGuideName: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7627 | auto *Template = cast_or_null<TemplateDecl>( |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7628 | Import(FromName.getCXXDeductionGuideTemplate())); |
| 7629 | if (!Template) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7630 | return {}; |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7631 | return ToContext.DeclarationNames.getCXXDeductionGuideName(Template); |
| 7632 | } |
| 7633 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7634 | case DeclarationName::CXXConversionFunctionName: { |
| 7635 | QualType T = Import(FromName.getCXXNameType()); |
| 7636 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7637 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7638 | |
| 7639 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 7640 | ToContext.getCanonicalType(T)); |
| 7641 | } |
| 7642 | |
| 7643 | case DeclarationName::CXXOperatorName: |
| 7644 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 7645 | FromName.getCXXOverloadedOperator()); |
| 7646 | |
| 7647 | case DeclarationName::CXXLiteralOperatorName: |
| 7648 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| 7649 | Import(FromName.getCXXLiteralIdentifier())); |
| 7650 | |
| 7651 | case DeclarationName::CXXUsingDirective: |
| 7652 | // FIXME: STATICS! |
| 7653 | return DeclarationName::getUsingDirectiveName(); |
| 7654 | } |
| 7655 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 7656 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7657 | } |
| 7658 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7659 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7660 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7661 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7662 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 7663 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 7664 | |
| 7665 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 7666 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 7667 | |
| 7668 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7669 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7670 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7671 | Selector ASTImporter::Import(Selector FromSel) { |
| 7672 | if (FromSel.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7673 | return {}; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7674 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 7675 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7676 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 7677 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 7678 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 7679 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 7680 | } |
| 7681 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7682 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 7683 | DeclContext *DC, |
| 7684 | unsigned IDNS, |
| 7685 | NamedDecl **Decls, |
| 7686 | unsigned NumDecls) { |
| 7687 | return Name; |
| 7688 | } |
| 7689 | |
| 7690 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 7691 | if (LastDiagFromFrom) |
| 7692 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 7693 | FromContext.getDiagnostics()); |
| 7694 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7695 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7696 | } |
| 7697 | |
| 7698 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 7699 | if (!LastDiagFromFrom) |
| 7700 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 7701 | ToContext.getDiagnostics()); |
| 7702 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7703 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7704 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7705 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7706 | void ASTImporter::CompleteDecl (Decl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7707 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7708 | if (!ID->getDefinition()) |
| 7709 | ID->startDefinition(); |
| 7710 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7711 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7712 | if (!PD->getDefinition()) |
| 7713 | PD->startDefinition(); |
| 7714 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7715 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7716 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 7717 | TD->startDefinition(); |
| 7718 | TD->setCompleteDefinition(true); |
| 7719 | } |
| 7720 | } |
| 7721 | else { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7722 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7723 | } |
| 7724 | } |
| 7725 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7726 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { |
| 7727 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); |
| 7728 | assert((Pos == ImportedDecls.end() || Pos->second == To) && |
| 7729 | "Try to import an already imported Decl"); |
| 7730 | if (Pos != ImportedDecls.end()) |
| 7731 | return Pos->second; |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7732 | ImportedDecls[From] = To; |
| 7733 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 7734 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7735 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 7736 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 7737 | bool Complain) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7738 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7739 | = ImportedTypes.find(From.getTypePtr()); |
| 7740 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) |
| 7741 | return true; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 7742 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 7743 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7744 | getStructuralEquivalenceKind(*this), false, |
| 7745 | Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 7746 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7747 | } |