File: | tools/clang/lib/AST/ASTImporter.cpp |
Warning: | line 2776, column 9 1st function call argument is an uninitialized value |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===// | |||
2 | // | |||
3 | // The LLVM Compiler Infrastructure | |||
4 | // | |||
5 | // This file is distributed under the University of Illinois Open Source | |||
6 | // License. See LICENSE.TXT for details. | |||
7 | // | |||
8 | //===----------------------------------------------------------------------===// | |||
9 | // | |||
10 | // This file defines the ASTImporter class which imports AST nodes from one | |||
11 | // context into another context. | |||
12 | // | |||
13 | //===----------------------------------------------------------------------===// | |||
14 | ||||
15 | #include "clang/AST/ASTImporter.h" | |||
16 | #include "clang/AST/ASTContext.h" | |||
17 | #include "clang/AST/ASTDiagnostic.h" | |||
18 | #include "clang/AST/ASTStructuralEquivalence.h" | |||
19 | #include "clang/AST/Attr.h" | |||
20 | #include "clang/AST/Decl.h" | |||
21 | #include "clang/AST/DeclAccessPair.h" | |||
22 | #include "clang/AST/DeclBase.h" | |||
23 | #include "clang/AST/DeclCXX.h" | |||
24 | #include "clang/AST/DeclFriend.h" | |||
25 | #include "clang/AST/DeclGroup.h" | |||
26 | #include "clang/AST/DeclObjC.h" | |||
27 | #include "clang/AST/DeclTemplate.h" | |||
28 | #include "clang/AST/DeclVisitor.h" | |||
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" | |||
40 | #include "clang/AST/StmtVisitor.h" | |||
41 | #include "clang/AST/TemplateBase.h" | |||
42 | #include "clang/AST/TemplateName.h" | |||
43 | #include "clang/AST/Type.h" | |||
44 | #include "clang/AST/TypeLoc.h" | |||
45 | #include "clang/AST/TypeVisitor.h" | |||
46 | #include "clang/AST/UnresolvedSet.h" | |||
47 | #include "clang/Basic/ExceptionSpecificationType.h" | |||
48 | #include "clang/Basic/FileManager.h" | |||
49 | #include "clang/Basic/IdentifierTable.h" | |||
50 | #include "clang/Basic/LLVM.h" | |||
51 | #include "clang/Basic/LangOptions.h" | |||
52 | #include "clang/Basic/SourceLocation.h" | |||
53 | #include "clang/Basic/SourceManager.h" | |||
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" | |||
64 | #include "llvm/Support/MemoryBuffer.h" | |||
65 | #include <algorithm> | |||
66 | #include <cassert> | |||
67 | #include <cstddef> | |||
68 | #include <memory> | |||
69 | #include <type_traits> | |||
70 | #include <utility> | |||
71 | ||||
72 | namespace clang { | |||
73 | ||||
74 | using llvm::make_error; | |||
75 | using llvm::Error; | |||
76 | using llvm::Expected; | |||
77 | using ExpectedType = llvm::Expected<QualType>; | |||
78 | using ExpectedStmt = llvm::Expected<Stmt *>; | |||
79 | using ExpectedExpr = llvm::Expected<Expr *>; | |||
80 | using ExpectedDecl = llvm::Expected<Decl *>; | |||
81 | using ExpectedSLoc = llvm::Expected<SourceLocation>; | |||
82 | ||||
83 | std::string ImportError::toString() const { | |||
84 | // FIXME: Improve error texts. | |||
85 | switch (Error) { | |||
86 | case NameConflict: | |||
87 | return "NameConflict"; | |||
88 | case UnsupportedConstruct: | |||
89 | return "UnsupportedConstruct"; | |||
90 | case Unknown: | |||
91 | return "Unknown error"; | |||
92 | } | |||
93 | llvm_unreachable("Invalid error code.")::llvm::llvm_unreachable_internal("Invalid error code.", "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 93); | |||
94 | return "Invalid error code."; | |||
95 | } | |||
96 | ||||
97 | void ImportError::log(raw_ostream &OS) const { | |||
98 | OS << toString(); | |||
99 | } | |||
100 | ||||
101 | std::error_code ImportError::convertToErrorCode() const { | |||
102 | llvm_unreachable("Function not implemented.")::llvm::llvm_unreachable_internal("Function not implemented." , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 102); | |||
103 | } | |||
104 | ||||
105 | char ImportError::ID; | |||
106 | ||||
107 | template <class T> | |||
108 | SmallVector<Decl *, 2> | |||
109 | getCanonicalForwardRedeclChain(Redeclarable<T>* D) { | |||
110 | SmallVector<Decl *, 2> Redecls; | |||
111 | for (auto *R : D->getFirstDecl()->redecls()) { | |||
112 | if (R != D->getFirstDecl()) | |||
113 | Redecls.push_back(R); | |||
114 | } | |||
115 | Redecls.push_back(D->getFirstDecl()); | |||
116 | std::reverse(Redecls.begin(), Redecls.end()); | |||
117 | return Redecls; | |||
118 | } | |||
119 | ||||
120 | SmallVector<Decl*, 2> getCanonicalForwardRedeclChain(Decl* D) { | |||
121 | if (auto *FD = dyn_cast<FunctionDecl>(D)) | |||
122 | return getCanonicalForwardRedeclChain<FunctionDecl>(FD); | |||
123 | if (auto *VD = dyn_cast<VarDecl>(D)) | |||
124 | return getCanonicalForwardRedeclChain<VarDecl>(VD); | |||
125 | llvm_unreachable("Bad declaration kind")::llvm::llvm_unreachable_internal("Bad declaration kind", "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 125); | |||
126 | } | |||
127 | ||||
128 | void updateFlags(const Decl *From, Decl *To) { | |||
129 | // Check if some flags or attrs are new in 'From' and copy into 'To'. | |||
130 | // FIXME: Other flags or attrs? | |||
131 | if (From->isUsed(false) && !To->isUsed(false)) | |||
132 | To->setIsUsed(); | |||
133 | } | |||
134 | ||||
135 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { | |||
136 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&((F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl >(*F)) && "Try to get field index for non-field.") ? static_cast<void> (0) : __assert_fail ("F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && \"Try to get field index for non-field.\"" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 137, __PRETTY_FUNCTION__)) | |||
137 | "Try to get field index for non-field.")((F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl >(*F)) && "Try to get field index for non-field.") ? static_cast<void> (0) : __assert_fail ("F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && \"Try to get field index for non-field.\"" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 137, __PRETTY_FUNCTION__)); | |||
138 | ||||
139 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); | |||
140 | if (!Owner) | |||
141 | return None; | |||
142 | ||||
143 | unsigned Index = 0; | |||
144 | for (const auto *D : Owner->decls()) { | |||
145 | if (D == F) | |||
146 | return Index; | |||
147 | ||||
148 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) | |||
149 | ++Index; | |||
150 | } | |||
151 | ||||
152 | llvm_unreachable("Field was not found in its parent context.")::llvm::llvm_unreachable_internal("Field was not found in its parent context." , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 152); | |||
153 | ||||
154 | return None; | |||
155 | } | |||
156 | ||||
157 | // FIXME: Temporary until every import returns Expected. | |||
158 | template <> | |||
159 | LLVM_NODISCARD[[clang::warn_unused_result]] Error | |||
160 | ASTImporter::importInto(SourceLocation &To, const SourceLocation &From) { | |||
161 | To = Import(From); | |||
162 | if (From.isValid() && To.isInvalid()) | |||
163 | return llvm::make_error<ImportError>(); | |||
164 | return Error::success(); | |||
165 | } | |||
166 | // FIXME: Temporary until every import returns Expected. | |||
167 | template <> | |||
168 | LLVM_NODISCARD[[clang::warn_unused_result]] Error | |||
169 | ASTImporter::importInto(QualType &To, const QualType &From) { | |||
170 | To = Import(From); | |||
171 | if (!From.isNull() && To.isNull()) | |||
172 | return llvm::make_error<ImportError>(); | |||
173 | return Error::success(); | |||
174 | } | |||
175 | ||||
176 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>, | |||
177 | public DeclVisitor<ASTNodeImporter, ExpectedDecl>, | |||
178 | public StmtVisitor<ASTNodeImporter, ExpectedStmt> { | |||
179 | ASTImporter &Importer; | |||
180 | ||||
181 | // Use this instead of Importer.importInto . | |||
182 | template <typename ImportT> | |||
183 | LLVM_NODISCARD[[clang::warn_unused_result]] Error importInto(ImportT &To, const ImportT &From) { | |||
184 | return Importer.importInto(To, From); | |||
185 | } | |||
186 | ||||
187 | // Use this to import pointers of specific type. | |||
188 | template <typename ImportT> | |||
189 | LLVM_NODISCARD[[clang::warn_unused_result]] Error importInto(ImportT *&To, ImportT *From) { | |||
190 | auto ToI = Importer.Import(From); | |||
191 | if (!ToI && From) | |||
192 | return make_error<ImportError>(); | |||
193 | To = cast_or_null<ImportT>(ToI); | |||
194 | return Error::success(); | |||
195 | // FIXME: This should be the final code. | |||
196 | //auto ToOrErr = Importer.Import(From); | |||
197 | //if (ToOrErr) { | |||
198 | // To = cast_or_null<ImportT>(*ToOrErr); | |||
199 | //} | |||
200 | //return ToOrErr.takeError(); | |||
201 | } | |||
202 | ||||
203 | // Call the import function of ASTImporter for a baseclass of type `T` and | |||
204 | // cast the return value to `T`. | |||
205 | template <typename T> | |||
206 | Expected<T *> import(T *From) { | |||
207 | auto *To = Importer.Import(From); | |||
208 | if (!To && From) | |||
209 | return make_error<ImportError>(); | |||
210 | return cast_or_null<T>(To); | |||
211 | // FIXME: This should be the final code. | |||
212 | //auto ToOrErr = Importer.Import(From); | |||
213 | //if (!ToOrErr) | |||
214 | // return ToOrErr.takeError(); | |||
215 | //return cast_or_null<T>(*ToOrErr); | |||
216 | } | |||
217 | ||||
218 | template <typename T> | |||
219 | Expected<T *> import(const T *From) { | |||
220 | return import(const_cast<T *>(From)); | |||
221 | } | |||
222 | ||||
223 | // Call the import function of ASTImporter for type `T`. | |||
224 | template <typename T> | |||
225 | Expected<T> import(const T &From) { | |||
226 | T To = Importer.Import(From); | |||
227 | T DefaultT; | |||
228 | if (To == DefaultT && !(From == DefaultT)) | |||
229 | return make_error<ImportError>(); | |||
230 | return To; | |||
231 | // FIXME: This should be the final code. | |||
232 | //return Importer.Import(From); | |||
233 | } | |||
234 | ||||
235 | template <class T> | |||
236 | Expected<std::tuple<T>> | |||
237 | importSeq(const T &From) { | |||
238 | Expected<T> ToOrErr = import(From); | |||
239 | if (!ToOrErr) | |||
240 | return ToOrErr.takeError(); | |||
241 | return std::make_tuple<T>(std::move(*ToOrErr)); | |||
242 | } | |||
243 | ||||
244 | // Import multiple objects with a single function call. | |||
245 | // This should work for every type for which a variant of `import` exists. | |||
246 | // The arguments are processed from left to right and import is stopped on | |||
247 | // first error. | |||
248 | template <class THead, class... TTail> | |||
249 | Expected<std::tuple<THead, TTail...>> | |||
250 | importSeq(const THead &FromHead, const TTail &...FromTail) { | |||
251 | Expected<std::tuple<THead>> ToHeadOrErr = importSeq(FromHead); | |||
252 | if (!ToHeadOrErr) | |||
253 | return ToHeadOrErr.takeError(); | |||
254 | Expected<std::tuple<TTail...>> ToTailOrErr = importSeq(FromTail...); | |||
255 | if (!ToTailOrErr) | |||
256 | return ToTailOrErr.takeError(); | |||
257 | return std::tuple_cat(*ToHeadOrErr, *ToTailOrErr); | |||
258 | } | |||
259 | ||||
260 | // Wrapper for an overload set. | |||
261 | template <typename ToDeclT> struct CallOverloadedCreateFun { | |||
262 | template <typename... Args> | |||
263 | auto operator()(Args &&... args) | |||
264 | -> decltype(ToDeclT::Create(std::forward<Args>(args)...)) { | |||
265 | return ToDeclT::Create(std::forward<Args>(args)...); | |||
266 | } | |||
267 | }; | |||
268 | ||||
269 | // Always use these functions to create a Decl during import. There are | |||
270 | // certain tasks which must be done after the Decl was created, e.g. we | |||
271 | // must immediately register that as an imported Decl. The parameter `ToD` | |||
272 | // will be set to the newly created Decl or if had been imported before | |||
273 | // then to the already imported Decl. Returns a bool value set to true if | |||
274 | // the `FromD` had been imported before. | |||
275 | template <typename ToDeclT, typename FromDeclT, typename... Args> | |||
276 | LLVM_NODISCARD[[clang::warn_unused_result]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, | |||
277 | Args &&... args) { | |||
278 | // There may be several overloads of ToDeclT::Create. We must make sure | |||
279 | // to call the one which would be chosen by the arguments, thus we use a | |||
280 | // wrapper for the overload set. | |||
281 | CallOverloadedCreateFun<ToDeclT> OC; | |||
282 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, | |||
283 | std::forward<Args>(args)...); | |||
284 | } | |||
285 | // Use this overload if a special Type is needed to be created. E.g if we | |||
286 | // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl` | |||
287 | // then: | |||
288 | // TypedefNameDecl *ToTypedef; | |||
289 | // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...); | |||
290 | template <typename NewDeclT, typename ToDeclT, typename FromDeclT, | |||
291 | typename... Args> | |||
292 | LLVM_NODISCARD[[clang::warn_unused_result]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, | |||
293 | Args &&... args) { | |||
294 | CallOverloadedCreateFun<NewDeclT> OC; | |||
295 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, | |||
296 | std::forward<Args>(args)...); | |||
297 | } | |||
298 | // Use this version if a special create function must be | |||
299 | // used, e.g. CXXRecordDecl::CreateLambda . | |||
300 | template <typename ToDeclT, typename CreateFunT, typename FromDeclT, | |||
301 | typename... Args> | |||
302 | LLVM_NODISCARD[[clang::warn_unused_result]] bool | |||
303 | GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun, | |||
304 | FromDeclT *FromD, Args &&... args) { | |||
305 | // FIXME: This code is needed later. | |||
306 | //if (Importer.getImportDeclErrorIfAny(FromD)) { | |||
307 | // ToD = nullptr; | |||
308 | // return true; // Already imported but with error. | |||
309 | //} | |||
310 | ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD)); | |||
311 | if (ToD) | |||
312 | return true; // Already imported. | |||
313 | ToD = CreateFun(std::forward<Args>(args)...); | |||
314 | InitializeImportedDecl(FromD, ToD); | |||
315 | return false; // A new Decl is created. | |||
316 | } | |||
317 | ||||
318 | void InitializeImportedDecl(Decl *FromD, Decl *ToD) { | |||
319 | Importer.MapImported(FromD, ToD); | |||
320 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; | |||
321 | if (FromD->hasAttrs()) | |||
322 | for (const Attr *FromAttr : FromD->getAttrs()) | |||
323 | ToD->addAttr(Importer.Import(FromAttr)); | |||
324 | if (FromD->isUsed()) | |||
325 | ToD->setIsUsed(); | |||
326 | if (FromD->isImplicit()) | |||
327 | ToD->setImplicit(); | |||
328 | } | |||
329 | ||||
330 | public: | |||
331 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} | |||
332 | ||||
333 | using TypeVisitor<ASTNodeImporter, ExpectedType>::Visit; | |||
334 | using DeclVisitor<ASTNodeImporter, ExpectedDecl>::Visit; | |||
335 | using StmtVisitor<ASTNodeImporter, ExpectedStmt>::Visit; | |||
336 | ||||
337 | // Importing types | |||
338 | ExpectedType VisitType(const Type *T); | |||
339 | ExpectedType VisitAtomicType(const AtomicType *T); | |||
340 | ExpectedType VisitBuiltinType(const BuiltinType *T); | |||
341 | ExpectedType VisitDecayedType(const DecayedType *T); | |||
342 | ExpectedType VisitComplexType(const ComplexType *T); | |||
343 | ExpectedType VisitPointerType(const PointerType *T); | |||
344 | ExpectedType VisitBlockPointerType(const BlockPointerType *T); | |||
345 | ExpectedType VisitLValueReferenceType(const LValueReferenceType *T); | |||
346 | ExpectedType VisitRValueReferenceType(const RValueReferenceType *T); | |||
347 | ExpectedType VisitMemberPointerType(const MemberPointerType *T); | |||
348 | ExpectedType VisitConstantArrayType(const ConstantArrayType *T); | |||
349 | ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T); | |||
350 | ExpectedType VisitVariableArrayType(const VariableArrayType *T); | |||
351 | ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T); | |||
352 | // FIXME: DependentSizedExtVectorType | |||
353 | ExpectedType VisitVectorType(const VectorType *T); | |||
354 | ExpectedType VisitExtVectorType(const ExtVectorType *T); | |||
355 | ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T); | |||
356 | ExpectedType VisitFunctionProtoType(const FunctionProtoType *T); | |||
357 | ExpectedType VisitUnresolvedUsingType(const UnresolvedUsingType *T); | |||
358 | ExpectedType VisitParenType(const ParenType *T); | |||
359 | ExpectedType VisitTypedefType(const TypedefType *T); | |||
360 | ExpectedType VisitTypeOfExprType(const TypeOfExprType *T); | |||
361 | // FIXME: DependentTypeOfExprType | |||
362 | ExpectedType VisitTypeOfType(const TypeOfType *T); | |||
363 | ExpectedType VisitDecltypeType(const DecltypeType *T); | |||
364 | ExpectedType VisitUnaryTransformType(const UnaryTransformType *T); | |||
365 | ExpectedType VisitAutoType(const AutoType *T); | |||
366 | ExpectedType VisitInjectedClassNameType(const InjectedClassNameType *T); | |||
367 | // FIXME: DependentDecltypeType | |||
368 | ExpectedType VisitRecordType(const RecordType *T); | |||
369 | ExpectedType VisitEnumType(const EnumType *T); | |||
370 | ExpectedType VisitAttributedType(const AttributedType *T); | |||
371 | ExpectedType VisitTemplateTypeParmType(const TemplateTypeParmType *T); | |||
372 | ExpectedType VisitSubstTemplateTypeParmType( | |||
373 | const SubstTemplateTypeParmType *T); | |||
374 | ExpectedType VisitTemplateSpecializationType( | |||
375 | const TemplateSpecializationType *T); | |||
376 | ExpectedType VisitElaboratedType(const ElaboratedType *T); | |||
377 | ExpectedType VisitDependentNameType(const DependentNameType *T); | |||
378 | ExpectedType VisitPackExpansionType(const PackExpansionType *T); | |||
379 | ExpectedType VisitDependentTemplateSpecializationType( | |||
380 | const DependentTemplateSpecializationType *T); | |||
381 | ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T); | |||
382 | ExpectedType VisitObjCObjectType(const ObjCObjectType *T); | |||
383 | ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); | |||
384 | ||||
385 | // Importing declarations | |||
386 | Error ImportDeclParts( | |||
387 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, | |||
388 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc); | |||
389 | Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); | |||
390 | Error ImportDeclarationNameLoc( | |||
391 | const DeclarationNameInfo &From, DeclarationNameInfo &To); | |||
392 | Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); | |||
393 | Error ImportDeclContext( | |||
394 | Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC); | |||
395 | Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To); | |||
396 | ||||
397 | Expected<CXXCastPath> ImportCastPath(CastExpr *E); | |||
398 | ||||
399 | using Designator = DesignatedInitExpr::Designator; | |||
400 | ||||
401 | /// What we should import from the definition. | |||
402 | enum ImportDefinitionKind { | |||
403 | /// Import the default subset of the definition, which might be | |||
404 | /// nothing (if minimal import is set) or might be everything (if minimal | |||
405 | /// import is not set). | |||
406 | IDK_Default, | |||
407 | /// Import everything. | |||
408 | IDK_Everything, | |||
409 | /// Import only the bare bones needed to establish a valid | |||
410 | /// DeclContext. | |||
411 | IDK_Basic | |||
412 | }; | |||
413 | ||||
414 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { | |||
415 | return IDK == IDK_Everything || | |||
416 | (IDK == IDK_Default && !Importer.isMinimalImport()); | |||
417 | } | |||
418 | ||||
419 | Error ImportInitializer(VarDecl *From, VarDecl *To); | |||
420 | Error ImportDefinition( | |||
421 | RecordDecl *From, RecordDecl *To, | |||
422 | ImportDefinitionKind Kind = IDK_Default); | |||
423 | Error ImportDefinition( | |||
424 | EnumDecl *From, EnumDecl *To, | |||
425 | ImportDefinitionKind Kind = IDK_Default); | |||
426 | Error ImportDefinition( | |||
427 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, | |||
428 | ImportDefinitionKind Kind = IDK_Default); | |||
429 | Error ImportDefinition( | |||
430 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, | |||
431 | ImportDefinitionKind Kind = IDK_Default); | |||
432 | Expected<TemplateParameterList *> ImportTemplateParameterList( | |||
433 | TemplateParameterList *Params); | |||
434 | Error ImportTemplateArguments( | |||
435 | const TemplateArgument *FromArgs, unsigned NumFromArgs, | |||
436 | SmallVectorImpl<TemplateArgument> &ToArgs); | |||
437 | Expected<TemplateArgument> | |||
438 | ImportTemplateArgument(const TemplateArgument &From); | |||
439 | ||||
440 | template <typename InContainerTy> | |||
441 | Error ImportTemplateArgumentListInfo( | |||
442 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo); | |||
443 | ||||
444 | template<typename InContainerTy> | |||
445 | Error ImportTemplateArgumentListInfo( | |||
446 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, | |||
447 | const InContainerTy &Container, TemplateArgumentListInfo &Result); | |||
448 | ||||
449 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; | |||
450 | using FunctionTemplateAndArgsTy = | |||
451 | std::tuple<FunctionTemplateDecl *, TemplateArgsTy>; | |||
452 | Expected<FunctionTemplateAndArgsTy> | |||
453 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( | |||
454 | FunctionDecl *FromFD); | |||
455 | ||||
456 | Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); | |||
457 | ||||
458 | bool IsStructuralMatch(Decl *From, Decl *To, bool Complain); | |||
459 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, | |||
460 | bool Complain = true); | |||
461 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, | |||
462 | bool Complain = true); | |||
463 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); | |||
464 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); | |||
465 | bool IsStructuralMatch(FunctionTemplateDecl *From, | |||
466 | FunctionTemplateDecl *To); | |||
467 | bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To); | |||
468 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); | |||
469 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); | |||
470 | ExpectedDecl VisitDecl(Decl *D); | |||
471 | ExpectedDecl VisitImportDecl(ImportDecl *D); | |||
472 | ExpectedDecl VisitEmptyDecl(EmptyDecl *D); | |||
473 | ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D); | |||
474 | ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D); | |||
475 | ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D); | |||
476 | ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D); | |||
477 | ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D); | |||
478 | ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); | |||
479 | ExpectedDecl VisitTypedefDecl(TypedefDecl *D); | |||
480 | ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D); | |||
481 | ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); | |||
482 | ExpectedDecl VisitLabelDecl(LabelDecl *D); | |||
483 | ExpectedDecl VisitEnumDecl(EnumDecl *D); | |||
484 | ExpectedDecl VisitRecordDecl(RecordDecl *D); | |||
485 | ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D); | |||
486 | ExpectedDecl VisitFunctionDecl(FunctionDecl *D); | |||
487 | ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D); | |||
488 | ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); | |||
489 | ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); | |||
490 | ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); | |||
491 | ExpectedDecl VisitFieldDecl(FieldDecl *D); | |||
492 | ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); | |||
493 | ExpectedDecl VisitFriendDecl(FriendDecl *D); | |||
494 | ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D); | |||
495 | ExpectedDecl VisitVarDecl(VarDecl *D); | |||
496 | ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D); | |||
497 | ExpectedDecl VisitParmVarDecl(ParmVarDecl *D); | |||
498 | ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D); | |||
499 | ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); | |||
500 | ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D); | |||
501 | ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D); | |||
502 | ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D); | |||
503 | ExpectedDecl VisitUsingDecl(UsingDecl *D); | |||
504 | ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D); | |||
505 | ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D); | |||
506 | ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); | |||
507 | ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); | |||
508 | ||||
509 | Expected<ObjCTypeParamList *> | |||
510 | ImportObjCTypeParamList(ObjCTypeParamList *list); | |||
511 | ||||
512 | ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); | |||
513 | ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); | |||
514 | ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D); | |||
515 | ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D); | |||
516 | ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); | |||
517 | ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); | |||
518 | ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); | |||
519 | ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); | |||
520 | ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D); | |||
521 | ExpectedDecl VisitClassTemplateSpecializationDecl( | |||
522 | ClassTemplateSpecializationDecl *D); | |||
523 | ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D); | |||
524 | ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); | |||
525 | ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D); | |||
526 | ||||
527 | // Importing statements | |||
528 | ExpectedStmt VisitStmt(Stmt *S); | |||
529 | ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S); | |||
530 | ExpectedStmt VisitDeclStmt(DeclStmt *S); | |||
531 | ExpectedStmt VisitNullStmt(NullStmt *S); | |||
532 | ExpectedStmt VisitCompoundStmt(CompoundStmt *S); | |||
533 | ExpectedStmt VisitCaseStmt(CaseStmt *S); | |||
534 | ExpectedStmt VisitDefaultStmt(DefaultStmt *S); | |||
535 | ExpectedStmt VisitLabelStmt(LabelStmt *S); | |||
536 | ExpectedStmt VisitAttributedStmt(AttributedStmt *S); | |||
537 | ExpectedStmt VisitIfStmt(IfStmt *S); | |||
538 | ExpectedStmt VisitSwitchStmt(SwitchStmt *S); | |||
539 | ExpectedStmt VisitWhileStmt(WhileStmt *S); | |||
540 | ExpectedStmt VisitDoStmt(DoStmt *S); | |||
541 | ExpectedStmt VisitForStmt(ForStmt *S); | |||
542 | ExpectedStmt VisitGotoStmt(GotoStmt *S); | |||
543 | ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S); | |||
544 | ExpectedStmt VisitContinueStmt(ContinueStmt *S); | |||
545 | ExpectedStmt VisitBreakStmt(BreakStmt *S); | |||
546 | ExpectedStmt VisitReturnStmt(ReturnStmt *S); | |||
547 | // FIXME: MSAsmStmt | |||
548 | // FIXME: SEHExceptStmt | |||
549 | // FIXME: SEHFinallyStmt | |||
550 | // FIXME: SEHTryStmt | |||
551 | // FIXME: SEHLeaveStmt | |||
552 | // FIXME: CapturedStmt | |||
553 | ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S); | |||
554 | ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S); | |||
555 | ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S); | |||
556 | // FIXME: MSDependentExistsStmt | |||
557 | ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); | |||
558 | ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); | |||
559 | ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); | |||
560 | ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S); | |||
561 | ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); | |||
562 | ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); | |||
563 | ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); | |||
564 | ||||
565 | // Importing expressions | |||
566 | ExpectedStmt VisitExpr(Expr *E); | |||
567 | ExpectedStmt VisitVAArgExpr(VAArgExpr *E); | |||
568 | ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E); | |||
569 | ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E); | |||
570 | ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E); | |||
571 | ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); | |||
572 | ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E); | |||
573 | ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); | |||
574 | ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E); | |||
575 | ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E); | |||
576 | ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E); | |||
577 | ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E); | |||
578 | ExpectedStmt VisitStringLiteral(StringLiteral *E); | |||
579 | ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E); | |||
580 | ExpectedStmt VisitAtomicExpr(AtomicExpr *E); | |||
581 | ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E); | |||
582 | ExpectedStmt VisitConstantExpr(ConstantExpr *E); | |||
583 | ExpectedStmt VisitParenExpr(ParenExpr *E); | |||
584 | ExpectedStmt VisitParenListExpr(ParenListExpr *E); | |||
585 | ExpectedStmt VisitStmtExpr(StmtExpr *E); | |||
586 | ExpectedStmt VisitUnaryOperator(UnaryOperator *E); | |||
587 | ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); | |||
588 | ExpectedStmt VisitBinaryOperator(BinaryOperator *E); | |||
589 | ExpectedStmt VisitConditionalOperator(ConditionalOperator *E); | |||
590 | ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E); | |||
591 | ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E); | |||
592 | ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); | |||
593 | ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E); | |||
594 | ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E); | |||
595 | ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E); | |||
596 | ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E); | |||
597 | ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E); | |||
598 | ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE); | |||
599 | ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E); | |||
600 | ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E); | |||
601 | ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); | |||
602 | ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); | |||
603 | ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); | |||
604 | ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); | |||
605 | ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); | |||
606 | ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E); | |||
607 | ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E); | |||
608 | ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E); | |||
609 | ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E); | |||
610 | ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E); | |||
611 | ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E); | |||
612 | ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); | |||
613 | ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); | |||
614 | ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); | |||
615 | ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); | |||
616 | ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); | |||
617 | ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E); | |||
618 | ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E); | |||
619 | ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); | |||
620 | ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); | |||
621 | ExpectedStmt VisitMemberExpr(MemberExpr *E); | |||
622 | ExpectedStmt VisitCallExpr(CallExpr *E); | |||
623 | ExpectedStmt VisitLambdaExpr(LambdaExpr *LE); | |||
624 | ExpectedStmt VisitInitListExpr(InitListExpr *E); | |||
625 | ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); | |||
626 | ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); | |||
627 | ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); | |||
628 | ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); | |||
629 | ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); | |||
630 | ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E); | |||
631 | ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); | |||
632 | ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); | |||
633 | ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); | |||
634 | ||||
635 | template<typename IIter, typename OIter> | |||
636 | Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { | |||
637 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; | |||
638 | for (; Ibegin != Iend; ++Ibegin, ++Obegin) { | |||
639 | Expected<ItemT> ToOrErr = import(*Ibegin); | |||
640 | if (!ToOrErr) | |||
641 | return ToOrErr.takeError(); | |||
642 | *Obegin = *ToOrErr; | |||
643 | } | |||
644 | return Error::success(); | |||
645 | } | |||
646 | ||||
647 | // Import every item from a container structure into an output container. | |||
648 | // If error occurs, stops at first error and returns the error. | |||
649 | // The output container should have space for all needed elements (it is not | |||
650 | // expanded, new items are put into from the beginning). | |||
651 | template<typename InContainerTy, typename OutContainerTy> | |||
652 | Error ImportContainerChecked( | |||
653 | const InContainerTy &InContainer, OutContainerTy &OutContainer) { | |||
654 | return ImportArrayChecked( | |||
655 | InContainer.begin(), InContainer.end(), OutContainer.begin()); | |||
656 | } | |||
657 | ||||
658 | template<typename InContainerTy, typename OIter> | |||
659 | Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { | |||
660 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); | |||
661 | } | |||
662 | ||||
663 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); | |||
664 | ||||
665 | Expected<FunctionDecl *> FindFunctionTemplateSpecialization( | |||
666 | FunctionDecl *FromFD); | |||
667 | }; | |||
668 | ||||
669 | // FIXME: Temporary until every import returns Expected. | |||
670 | template <> | |||
671 | Expected<TemplateName> ASTNodeImporter::import(const TemplateName &From) { | |||
672 | TemplateName To = Importer.Import(From); | |||
673 | if (To.isNull() && !From.isNull()) | |||
674 | return make_error<ImportError>(); | |||
675 | return To; | |||
676 | } | |||
677 | ||||
678 | template <typename InContainerTy> | |||
679 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( | |||
680 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, | |||
681 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { | |||
682 | auto ToLAngleLocOrErr = import(FromLAngleLoc); | |||
683 | if (!ToLAngleLocOrErr) | |||
684 | return ToLAngleLocOrErr.takeError(); | |||
685 | auto ToRAngleLocOrErr = import(FromRAngleLoc); | |||
686 | if (!ToRAngleLocOrErr) | |||
687 | return ToRAngleLocOrErr.takeError(); | |||
688 | ||||
689 | TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr); | |||
690 | if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo)) | |||
691 | return Err; | |||
692 | Result = ToTAInfo; | |||
693 | return Error::success(); | |||
694 | } | |||
695 | ||||
696 | template <> | |||
697 | Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( | |||
698 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { | |||
699 | return ImportTemplateArgumentListInfo( | |||
700 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); | |||
701 | } | |||
702 | ||||
703 | template <> | |||
704 | Error ASTNodeImporter::ImportTemplateArgumentListInfo< | |||
705 | ASTTemplateArgumentListInfo>( | |||
706 | const ASTTemplateArgumentListInfo &From, | |||
707 | TemplateArgumentListInfo &Result) { | |||
708 | return ImportTemplateArgumentListInfo( | |||
709 | From.LAngleLoc, From.RAngleLoc, From.arguments(), Result); | |||
710 | } | |||
711 | ||||
712 | Expected<ASTNodeImporter::FunctionTemplateAndArgsTy> | |||
713 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( | |||
714 | FunctionDecl *FromFD) { | |||
715 | assert(FromFD->getTemplatedKind() ==((FromFD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplateSpecialization ) ? static_cast<void> (0) : __assert_fail ("FromFD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplateSpecialization" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 716, __PRETTY_FUNCTION__)) | |||
716 | FunctionDecl::TK_FunctionTemplateSpecialization)((FromFD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplateSpecialization ) ? static_cast<void> (0) : __assert_fail ("FromFD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplateSpecialization" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 716, __PRETTY_FUNCTION__)); | |||
717 | ||||
718 | FunctionTemplateAndArgsTy Result; | |||
719 | ||||
720 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); | |||
721 | if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate())) | |||
722 | return std::move(Err); | |||
723 | ||||
724 | // Import template arguments. | |||
725 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); | |||
726 | if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), | |||
727 | std::get<1>(Result))) | |||
728 | return std::move(Err); | |||
729 | ||||
730 | return Result; | |||
731 | } | |||
732 | ||||
733 | template <> | |||
734 | Expected<TemplateParameterList *> | |||
735 | ASTNodeImporter::import(TemplateParameterList *From) { | |||
736 | SmallVector<NamedDecl *, 4> To(From->size()); | |||
737 | if (Error Err = ImportContainerChecked(*From, To)) | |||
738 | return std::move(Err); | |||
739 | ||||
740 | ExpectedExpr ToRequiresClause = import(From->getRequiresClause()); | |||
741 | if (!ToRequiresClause) | |||
742 | return ToRequiresClause.takeError(); | |||
743 | ||||
744 | auto ToTemplateLocOrErr = import(From->getTemplateLoc()); | |||
745 | if (!ToTemplateLocOrErr) | |||
746 | return ToTemplateLocOrErr.takeError(); | |||
747 | auto ToLAngleLocOrErr = import(From->getLAngleLoc()); | |||
748 | if (!ToLAngleLocOrErr) | |||
749 | return ToLAngleLocOrErr.takeError(); | |||
750 | auto ToRAngleLocOrErr = import(From->getRAngleLoc()); | |||
751 | if (!ToRAngleLocOrErr) | |||
752 | return ToRAngleLocOrErr.takeError(); | |||
753 | ||||
754 | return TemplateParameterList::Create( | |||
755 | Importer.getToContext(), | |||
756 | *ToTemplateLocOrErr, | |||
757 | *ToLAngleLocOrErr, | |||
758 | To, | |||
759 | *ToRAngleLocOrErr, | |||
760 | *ToRequiresClause); | |||
761 | } | |||
762 | ||||
763 | template <> | |||
764 | Expected<TemplateArgument> | |||
765 | ASTNodeImporter::import(const TemplateArgument &From) { | |||
766 | switch (From.getKind()) { | |||
767 | case TemplateArgument::Null: | |||
768 | return TemplateArgument(); | |||
769 | ||||
770 | case TemplateArgument::Type: { | |||
771 | ExpectedType ToTypeOrErr = import(From.getAsType()); | |||
772 | if (!ToTypeOrErr) | |||
773 | return ToTypeOrErr.takeError(); | |||
774 | return TemplateArgument(*ToTypeOrErr); | |||
775 | } | |||
776 | ||||
777 | case TemplateArgument::Integral: { | |||
778 | ExpectedType ToTypeOrErr = import(From.getIntegralType()); | |||
779 | if (!ToTypeOrErr) | |||
780 | return ToTypeOrErr.takeError(); | |||
781 | return TemplateArgument(From, *ToTypeOrErr); | |||
782 | } | |||
783 | ||||
784 | case TemplateArgument::Declaration: { | |||
785 | Expected<ValueDecl *> ToOrErr = import(From.getAsDecl()); | |||
786 | if (!ToOrErr) | |||
787 | return ToOrErr.takeError(); | |||
788 | ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); | |||
789 | if (!ToTypeOrErr) | |||
790 | return ToTypeOrErr.takeError(); | |||
791 | return TemplateArgument(*ToOrErr, *ToTypeOrErr); | |||
792 | } | |||
793 | ||||
794 | case TemplateArgument::NullPtr: { | |||
795 | ExpectedType ToTypeOrErr = import(From.getNullPtrType()); | |||
796 | if (!ToTypeOrErr) | |||
797 | return ToTypeOrErr.takeError(); | |||
798 | return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); | |||
799 | } | |||
800 | ||||
801 | case TemplateArgument::Template: { | |||
802 | Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate()); | |||
803 | if (!ToTemplateOrErr) | |||
804 | return ToTemplateOrErr.takeError(); | |||
805 | ||||
806 | return TemplateArgument(*ToTemplateOrErr); | |||
807 | } | |||
808 | ||||
809 | case TemplateArgument::TemplateExpansion: { | |||
810 | Expected<TemplateName> ToTemplateOrErr = | |||
811 | import(From.getAsTemplateOrTemplatePattern()); | |||
812 | if (!ToTemplateOrErr) | |||
813 | return ToTemplateOrErr.takeError(); | |||
814 | ||||
815 | return TemplateArgument( | |||
816 | *ToTemplateOrErr, From.getNumTemplateExpansions()); | |||
817 | } | |||
818 | ||||
819 | case TemplateArgument::Expression: | |||
820 | if (ExpectedExpr ToExpr = import(From.getAsExpr())) | |||
821 | return TemplateArgument(*ToExpr); | |||
822 | else | |||
823 | return ToExpr.takeError(); | |||
824 | ||||
825 | case TemplateArgument::Pack: { | |||
826 | SmallVector<TemplateArgument, 2> ToPack; | |||
827 | ToPack.reserve(From.pack_size()); | |||
828 | if (Error Err = ImportTemplateArguments( | |||
829 | From.pack_begin(), From.pack_size(), ToPack)) | |||
830 | return std::move(Err); | |||
831 | ||||
832 | return TemplateArgument( | |||
833 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); | |||
834 | } | |||
835 | } | |||
836 | ||||
837 | llvm_unreachable("Invalid template argument kind")::llvm::llvm_unreachable_internal("Invalid template argument kind" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 837); | |||
838 | } | |||
839 | ||||
840 | template <> | |||
841 | Expected<TemplateArgumentLoc> | |||
842 | ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) { | |||
843 | Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument()); | |||
844 | if (!ArgOrErr) | |||
845 | return ArgOrErr.takeError(); | |||
846 | TemplateArgument Arg = *ArgOrErr; | |||
847 | ||||
848 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); | |||
849 | ||||
850 | TemplateArgumentLocInfo ToInfo; | |||
851 | if (Arg.getKind() == TemplateArgument::Expression) { | |||
852 | ExpectedExpr E = import(FromInfo.getAsExpr()); | |||
853 | if (!E) | |||
854 | return E.takeError(); | |||
855 | ToInfo = TemplateArgumentLocInfo(*E); | |||
856 | } else if (Arg.getKind() == TemplateArgument::Type) { | |||
857 | if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo())) | |||
858 | ToInfo = TemplateArgumentLocInfo(*TSIOrErr); | |||
859 | else | |||
860 | return TSIOrErr.takeError(); | |||
861 | } else { | |||
862 | auto ToTemplateQualifierLocOrErr = | |||
863 | import(FromInfo.getTemplateQualifierLoc()); | |||
864 | if (!ToTemplateQualifierLocOrErr) | |||
865 | return ToTemplateQualifierLocOrErr.takeError(); | |||
866 | auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc()); | |||
867 | if (!ToTemplateNameLocOrErr) | |||
868 | return ToTemplateNameLocOrErr.takeError(); | |||
869 | auto ToTemplateEllipsisLocOrErr = | |||
870 | import(FromInfo.getTemplateEllipsisLoc()); | |||
871 | if (!ToTemplateEllipsisLocOrErr) | |||
872 | return ToTemplateEllipsisLocOrErr.takeError(); | |||
873 | ||||
874 | ToInfo = TemplateArgumentLocInfo( | |||
875 | *ToTemplateQualifierLocOrErr, | |||
876 | *ToTemplateNameLocOrErr, | |||
877 | *ToTemplateEllipsisLocOrErr); | |||
878 | } | |||
879 | ||||
880 | return TemplateArgumentLoc(Arg, ToInfo); | |||
881 | } | |||
882 | ||||
883 | template <> | |||
884 | Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) { | |||
885 | if (DG.isNull()) | |||
886 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); | |||
887 | size_t NumDecls = DG.end() - DG.begin(); | |||
888 | SmallVector<Decl *, 1> ToDecls; | |||
889 | ToDecls.reserve(NumDecls); | |||
890 | for (Decl *FromD : DG) { | |||
891 | if (auto ToDOrErr = import(FromD)) | |||
892 | ToDecls.push_back(*ToDOrErr); | |||
893 | else | |||
894 | return ToDOrErr.takeError(); | |||
895 | } | |||
896 | return DeclGroupRef::Create(Importer.getToContext(), | |||
897 | ToDecls.begin(), | |||
898 | NumDecls); | |||
899 | } | |||
900 | ||||
901 | template <> | |||
902 | Expected<ASTNodeImporter::Designator> | |||
903 | ASTNodeImporter::import(const Designator &D) { | |||
904 | if (D.isFieldDesignator()) { | |||
905 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); | |||
906 | ||||
907 | ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc()); | |||
908 | if (!ToDotLocOrErr) | |||
909 | return ToDotLocOrErr.takeError(); | |||
910 | ||||
911 | ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc()); | |||
912 | if (!ToFieldLocOrErr) | |||
913 | return ToFieldLocOrErr.takeError(); | |||
914 | ||||
915 | return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr); | |||
916 | } | |||
917 | ||||
918 | ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc()); | |||
919 | if (!ToLBracketLocOrErr) | |||
920 | return ToLBracketLocOrErr.takeError(); | |||
921 | ||||
922 | ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc()); | |||
923 | if (!ToRBracketLocOrErr) | |||
924 | return ToRBracketLocOrErr.takeError(); | |||
925 | ||||
926 | if (D.isArrayDesignator()) | |||
927 | return Designator(D.getFirstExprIndex(), | |||
928 | *ToLBracketLocOrErr, *ToRBracketLocOrErr); | |||
929 | ||||
930 | ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc()); | |||
931 | if (!ToEllipsisLocOrErr) | |||
932 | return ToEllipsisLocOrErr.takeError(); | |||
933 | ||||
934 | assert(D.isArrayRangeDesignator())((D.isArrayRangeDesignator()) ? static_cast<void> (0) : __assert_fail ("D.isArrayRangeDesignator()", "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 934, __PRETTY_FUNCTION__)); | |||
935 | return Designator( | |||
936 | D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr, | |||
937 | *ToRBracketLocOrErr); | |||
938 | } | |||
939 | ||||
940 | template <> | |||
941 | Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) { | |||
942 | VarDecl *Var = nullptr; | |||
943 | if (From.capturesVariable()) { | |||
944 | if (auto VarOrErr = import(From.getCapturedVar())) | |||
945 | Var = *VarOrErr; | |||
946 | else | |||
947 | return VarOrErr.takeError(); | |||
948 | } | |||
949 | ||||
950 | auto LocationOrErr = import(From.getLocation()); | |||
951 | if (!LocationOrErr) | |||
952 | return LocationOrErr.takeError(); | |||
953 | ||||
954 | SourceLocation EllipsisLoc; | |||
955 | if (From.isPackExpansion()) | |||
956 | if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc())) | |||
957 | return std::move(Err); | |||
958 | ||||
959 | return LambdaCapture( | |||
960 | *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var, | |||
961 | EllipsisLoc); | |||
962 | } | |||
963 | ||||
964 | } // namespace clang | |||
965 | ||||
966 | //---------------------------------------------------------------------------- | |||
967 | // Import Types | |||
968 | //---------------------------------------------------------------------------- | |||
969 | ||||
970 | using namespace clang; | |||
971 | ||||
972 | ExpectedType ASTNodeImporter::VisitType(const Type *T) { | |||
973 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) | |||
974 | << T->getTypeClassName(); | |||
975 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
976 | } | |||
977 | ||||
978 | ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ | |||
979 | ExpectedType UnderlyingTypeOrErr = import(T->getValueType()); | |||
980 | if (!UnderlyingTypeOrErr) | |||
981 | return UnderlyingTypeOrErr.takeError(); | |||
982 | ||||
983 | return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr); | |||
984 | } | |||
985 | ||||
986 | ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { | |||
987 | switch (T->getKind()) { | |||
988 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ | |||
989 | case BuiltinType::Id: \ | |||
990 | return Importer.getToContext().SingletonId; | |||
991 | #include "clang/Basic/OpenCLImageTypes.def" | |||
992 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ | |||
993 | case BuiltinType::Id: \ | |||
994 | return Importer.getToContext().Id##Ty; | |||
995 | #include "clang/Basic/OpenCLExtensionTypes.def" | |||
996 | #define SHARED_SINGLETON_TYPE(Expansion) | |||
997 | #define BUILTIN_TYPE(Id, SingletonId) \ | |||
998 | case BuiltinType::Id: return Importer.getToContext().SingletonId; | |||
999 | #include "clang/AST/BuiltinTypes.def" | |||
1000 | ||||
1001 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" | |||
1002 | // context supports C++. | |||
1003 | ||||
1004 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" | |||
1005 | // context supports ObjC. | |||
1006 | ||||
1007 | case BuiltinType::Char_U: | |||
1008 | // The context we're importing from has an unsigned 'char'. If we're | |||
1009 | // importing into a context with a signed 'char', translate to | |||
1010 | // 'unsigned char' instead. | |||
1011 | if (Importer.getToContext().getLangOpts().CharIsSigned) | |||
1012 | return Importer.getToContext().UnsignedCharTy; | |||
1013 | ||||
1014 | return Importer.getToContext().CharTy; | |||
1015 | ||||
1016 | case BuiltinType::Char_S: | |||
1017 | // The context we're importing from has an unsigned 'char'. If we're | |||
1018 | // importing into a context with a signed 'char', translate to | |||
1019 | // 'unsigned char' instead. | |||
1020 | if (!Importer.getToContext().getLangOpts().CharIsSigned) | |||
1021 | return Importer.getToContext().SignedCharTy; | |||
1022 | ||||
1023 | return Importer.getToContext().CharTy; | |||
1024 | ||||
1025 | case BuiltinType::WChar_S: | |||
1026 | case BuiltinType::WChar_U: | |||
1027 | // FIXME: If not in C++, shall we translate to the C equivalent of | |||
1028 | // wchar_t? | |||
1029 | return Importer.getToContext().WCharTy; | |||
1030 | } | |||
1031 | ||||
1032 | llvm_unreachable("Invalid BuiltinType Kind!")::llvm::llvm_unreachable_internal("Invalid BuiltinType Kind!" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 1032); | |||
1033 | } | |||
1034 | ||||
1035 | ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { | |||
1036 | ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType()); | |||
1037 | if (!ToOriginalTypeOrErr) | |||
1038 | return ToOriginalTypeOrErr.takeError(); | |||
1039 | ||||
1040 | return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr); | |||
1041 | } | |||
1042 | ||||
1043 | ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) { | |||
1044 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | |||
1045 | if (!ToElementTypeOrErr) | |||
1046 | return ToElementTypeOrErr.takeError(); | |||
1047 | ||||
1048 | return Importer.getToContext().getComplexType(*ToElementTypeOrErr); | |||
1049 | } | |||
1050 | ||||
1051 | ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) { | |||
1052 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | |||
1053 | if (!ToPointeeTypeOrErr) | |||
1054 | return ToPointeeTypeOrErr.takeError(); | |||
1055 | ||||
1056 | return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr); | |||
1057 | } | |||
1058 | ||||
1059 | ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { | |||
1060 | // FIXME: Check for blocks support in "to" context. | |||
1061 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | |||
1062 | if (!ToPointeeTypeOrErr) | |||
1063 | return ToPointeeTypeOrErr.takeError(); | |||
1064 | ||||
1065 | return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr); | |||
1066 | } | |||
1067 | ||||
1068 | ExpectedType | |||
1069 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { | |||
1070 | // FIXME: Check for C++ support in "to" context. | |||
1071 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); | |||
1072 | if (!ToPointeeTypeOrErr) | |||
1073 | return ToPointeeTypeOrErr.takeError(); | |||
1074 | ||||
1075 | return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr); | |||
1076 | } | |||
1077 | ||||
1078 | ExpectedType | |||
1079 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { | |||
1080 | // FIXME: Check for C++0x support in "to" context. | |||
1081 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); | |||
1082 | if (!ToPointeeTypeOrErr) | |||
1083 | return ToPointeeTypeOrErr.takeError(); | |||
1084 | ||||
1085 | return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr); | |||
1086 | } | |||
1087 | ||||
1088 | ExpectedType | |||
1089 | ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { | |||
1090 | // FIXME: Check for C++ support in "to" context. | |||
1091 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | |||
1092 | if (!ToPointeeTypeOrErr) | |||
1093 | return ToPointeeTypeOrErr.takeError(); | |||
1094 | ||||
1095 | ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0)); | |||
1096 | if (!ClassTypeOrErr) | |||
1097 | return ClassTypeOrErr.takeError(); | |||
1098 | ||||
1099 | return Importer.getToContext().getMemberPointerType( | |||
1100 | *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr()); | |||
1101 | } | |||
1102 | ||||
1103 | ExpectedType | |||
1104 | ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { | |||
1105 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | |||
1106 | if (!ToElementTypeOrErr) | |||
1107 | return ToElementTypeOrErr.takeError(); | |||
1108 | ||||
1109 | return Importer.getToContext().getConstantArrayType(*ToElementTypeOrErr, | |||
1110 | T->getSize(), | |||
1111 | T->getSizeModifier(), | |||
1112 | T->getIndexTypeCVRQualifiers()); | |||
1113 | } | |||
1114 | ||||
1115 | ExpectedType | |||
1116 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { | |||
1117 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | |||
1118 | if (!ToElementTypeOrErr) | |||
1119 | return ToElementTypeOrErr.takeError(); | |||
1120 | ||||
1121 | return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr, | |||
1122 | T->getSizeModifier(), | |||
1123 | T->getIndexTypeCVRQualifiers()); | |||
1124 | } | |||
1125 | ||||
1126 | ExpectedType | |||
1127 | ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { | |||
1128 | QualType ToElementType; | |||
1129 | Expr *ToSizeExpr; | |||
1130 | SourceRange ToBracketsRange; | |||
1131 | if (auto Imp = importSeq( | |||
1132 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) | |||
1133 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; | |||
1134 | else | |||
1135 | return Imp.takeError(); | |||
1136 | ||||
1137 | return Importer.getToContext().getVariableArrayType( | |||
1138 | ToElementType, ToSizeExpr, T->getSizeModifier(), | |||
1139 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); | |||
1140 | } | |||
1141 | ||||
1142 | ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( | |||
1143 | const DependentSizedArrayType *T) { | |||
1144 | QualType ToElementType; | |||
1145 | Expr *ToSizeExpr; | |||
1146 | SourceRange ToBracketsRange; | |||
1147 | if (auto Imp = importSeq( | |||
1148 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) | |||
1149 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; | |||
1150 | else | |||
1151 | return Imp.takeError(); | |||
1152 | // SizeExpr may be null if size is not specified directly. | |||
1153 | // For example, 'int a[]'. | |||
1154 | ||||
1155 | return Importer.getToContext().getDependentSizedArrayType( | |||
1156 | ToElementType, ToSizeExpr, T->getSizeModifier(), | |||
1157 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); | |||
1158 | } | |||
1159 | ||||
1160 | ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) { | |||
1161 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | |||
1162 | if (!ToElementTypeOrErr) | |||
1163 | return ToElementTypeOrErr.takeError(); | |||
1164 | ||||
1165 | return Importer.getToContext().getVectorType(*ToElementTypeOrErr, | |||
1166 | T->getNumElements(), | |||
1167 | T->getVectorKind()); | |||
1168 | } | |||
1169 | ||||
1170 | ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { | |||
1171 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | |||
1172 | if (!ToElementTypeOrErr) | |||
1173 | return ToElementTypeOrErr.takeError(); | |||
1174 | ||||
1175 | return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr, | |||
1176 | T->getNumElements()); | |||
1177 | } | |||
1178 | ||||
1179 | ExpectedType | |||
1180 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { | |||
1181 | // FIXME: What happens if we're importing a function without a prototype | |||
1182 | // into C++? Should we make it variadic? | |||
1183 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); | |||
1184 | if (!ToReturnTypeOrErr) | |||
1185 | return ToReturnTypeOrErr.takeError(); | |||
1186 | ||||
1187 | return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr, | |||
1188 | T->getExtInfo()); | |||
1189 | } | |||
1190 | ||||
1191 | ExpectedType | |||
1192 | ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { | |||
1193 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); | |||
1194 | if (!ToReturnTypeOrErr) | |||
1195 | return ToReturnTypeOrErr.takeError(); | |||
1196 | ||||
1197 | // Import argument types | |||
1198 | SmallVector<QualType, 4> ArgTypes; | |||
1199 | for (const auto &A : T->param_types()) { | |||
1200 | ExpectedType TyOrErr = import(A); | |||
1201 | if (!TyOrErr) | |||
1202 | return TyOrErr.takeError(); | |||
1203 | ArgTypes.push_back(*TyOrErr); | |||
1204 | } | |||
1205 | ||||
1206 | // Import exception types | |||
1207 | SmallVector<QualType, 4> ExceptionTypes; | |||
1208 | for (const auto &E : T->exceptions()) { | |||
1209 | ExpectedType TyOrErr = import(E); | |||
1210 | if (!TyOrErr) | |||
1211 | return TyOrErr.takeError(); | |||
1212 | ExceptionTypes.push_back(*TyOrErr); | |||
1213 | } | |||
1214 | ||||
1215 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); | |||
1216 | FunctionProtoType::ExtProtoInfo ToEPI; | |||
1217 | ||||
1218 | auto Imp = importSeq( | |||
1219 | FromEPI.ExceptionSpec.NoexceptExpr, | |||
1220 | FromEPI.ExceptionSpec.SourceDecl, | |||
1221 | FromEPI.ExceptionSpec.SourceTemplate); | |||
1222 | if (!Imp) | |||
1223 | return Imp.takeError(); | |||
1224 | ||||
1225 | ToEPI.ExtInfo = FromEPI.ExtInfo; | |||
1226 | ToEPI.Variadic = FromEPI.Variadic; | |||
1227 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; | |||
1228 | ToEPI.TypeQuals = FromEPI.TypeQuals; | |||
1229 | ToEPI.RefQualifier = FromEPI.RefQualifier; | |||
1230 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; | |||
1231 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; | |||
1232 | std::tie( | |||
1233 | ToEPI.ExceptionSpec.NoexceptExpr, | |||
1234 | ToEPI.ExceptionSpec.SourceDecl, | |||
1235 | ToEPI.ExceptionSpec.SourceTemplate) = *Imp; | |||
1236 | ||||
1237 | return Importer.getToContext().getFunctionType( | |||
1238 | *ToReturnTypeOrErr, ArgTypes, ToEPI); | |||
1239 | } | |||
1240 | ||||
1241 | ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( | |||
1242 | const UnresolvedUsingType *T) { | |||
1243 | UnresolvedUsingTypenameDecl *ToD; | |||
1244 | Decl *ToPrevD; | |||
1245 | if (auto Imp = importSeq(T->getDecl(), T->getDecl()->getPreviousDecl())) | |||
1246 | std::tie(ToD, ToPrevD) = *Imp; | |||
1247 | else | |||
1248 | return Imp.takeError(); | |||
1249 | ||||
1250 | return Importer.getToContext().getTypeDeclType( | |||
1251 | ToD, cast_or_null<TypeDecl>(ToPrevD)); | |||
1252 | } | |||
1253 | ||||
1254 | ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) { | |||
1255 | ExpectedType ToInnerTypeOrErr = import(T->getInnerType()); | |||
1256 | if (!ToInnerTypeOrErr) | |||
1257 | return ToInnerTypeOrErr.takeError(); | |||
1258 | ||||
1259 | return Importer.getToContext().getParenType(*ToInnerTypeOrErr); | |||
1260 | } | |||
1261 | ||||
1262 | ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { | |||
1263 | Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl()); | |||
1264 | if (!ToDeclOrErr) | |||
1265 | return ToDeclOrErr.takeError(); | |||
1266 | ||||
1267 | return Importer.getToContext().getTypeDeclType(*ToDeclOrErr); | |||
1268 | } | |||
1269 | ||||
1270 | ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { | |||
1271 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); | |||
1272 | if (!ToExprOrErr) | |||
1273 | return ToExprOrErr.takeError(); | |||
1274 | ||||
1275 | return Importer.getToContext().getTypeOfExprType(*ToExprOrErr); | |||
1276 | } | |||
1277 | ||||
1278 | ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { | |||
1279 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | |||
1280 | if (!ToUnderlyingTypeOrErr) | |||
1281 | return ToUnderlyingTypeOrErr.takeError(); | |||
1282 | ||||
1283 | return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr); | |||
1284 | } | |||
1285 | ||||
1286 | ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { | |||
1287 | // FIXME: Make sure that the "to" context supports C++0x! | |||
1288 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); | |||
1289 | if (!ToExprOrErr) | |||
1290 | return ToExprOrErr.takeError(); | |||
1291 | ||||
1292 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | |||
1293 | if (!ToUnderlyingTypeOrErr) | |||
1294 | return ToUnderlyingTypeOrErr.takeError(); | |||
1295 | ||||
1296 | return Importer.getToContext().getDecltypeType( | |||
1297 | *ToExprOrErr, *ToUnderlyingTypeOrErr); | |||
1298 | } | |||
1299 | ||||
1300 | ExpectedType | |||
1301 | ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { | |||
1302 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); | |||
1303 | if (!ToBaseTypeOrErr) | |||
1304 | return ToBaseTypeOrErr.takeError(); | |||
1305 | ||||
1306 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | |||
1307 | if (!ToUnderlyingTypeOrErr) | |||
1308 | return ToUnderlyingTypeOrErr.takeError(); | |||
1309 | ||||
1310 | return Importer.getToContext().getUnaryTransformType( | |||
1311 | *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind()); | |||
1312 | } | |||
1313 | ||||
1314 | ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) { | |||
1315 | // FIXME: Make sure that the "to" context supports C++11! | |||
1316 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); | |||
1317 | if (!ToDeducedTypeOrErr) | |||
1318 | return ToDeducedTypeOrErr.takeError(); | |||
1319 | ||||
1320 | return Importer.getToContext().getAutoType(*ToDeducedTypeOrErr, | |||
1321 | T->getKeyword(), | |||
1322 | /*IsDependent*/false); | |||
1323 | } | |||
1324 | ||||
1325 | ExpectedType ASTNodeImporter::VisitInjectedClassNameType( | |||
1326 | const InjectedClassNameType *T) { | |||
1327 | Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl()); | |||
1328 | if (!ToDeclOrErr) | |||
1329 | return ToDeclOrErr.takeError(); | |||
1330 | ||||
1331 | ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType()); | |||
1332 | if (!ToInjTypeOrErr) | |||
1333 | return ToInjTypeOrErr.takeError(); | |||
1334 | ||||
1335 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading | |||
1336 | // See comments in InjectedClassNameType definition for details | |||
1337 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); | |||
1338 | enum { | |||
1339 | TypeAlignmentInBits = 4, | |||
1340 | TypeAlignment = 1 << TypeAlignmentInBits | |||
1341 | }; | |||
1342 | ||||
1343 | return QualType(new (Importer.getToContext(), TypeAlignment) | |||
1344 | InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0); | |||
1345 | } | |||
1346 | ||||
1347 | ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) { | |||
1348 | Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl()); | |||
1349 | if (!ToDeclOrErr) | |||
1350 | return ToDeclOrErr.takeError(); | |||
1351 | ||||
1352 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); | |||
1353 | } | |||
1354 | ||||
1355 | ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) { | |||
1356 | Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl()); | |||
1357 | if (!ToDeclOrErr) | |||
1358 | return ToDeclOrErr.takeError(); | |||
1359 | ||||
1360 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); | |||
1361 | } | |||
1362 | ||||
1363 | ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { | |||
1364 | ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType()); | |||
1365 | if (!ToModifiedTypeOrErr) | |||
1366 | return ToModifiedTypeOrErr.takeError(); | |||
1367 | ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType()); | |||
1368 | if (!ToEquivalentTypeOrErr) | |||
1369 | return ToEquivalentTypeOrErr.takeError(); | |||
1370 | ||||
1371 | return Importer.getToContext().getAttributedType(T->getAttrKind(), | |||
1372 | *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr); | |||
1373 | } | |||
1374 | ||||
1375 | ExpectedType ASTNodeImporter::VisitTemplateTypeParmType( | |||
1376 | const TemplateTypeParmType *T) { | |||
1377 | Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl()); | |||
1378 | if (!ToDeclOrErr) | |||
1379 | return ToDeclOrErr.takeError(); | |||
1380 | ||||
1381 | return Importer.getToContext().getTemplateTypeParmType( | |||
1382 | T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr); | |||
1383 | } | |||
1384 | ||||
1385 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( | |||
1386 | const SubstTemplateTypeParmType *T) { | |||
1387 | ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); | |||
1388 | if (!ReplacedOrErr) | |||
1389 | return ReplacedOrErr.takeError(); | |||
1390 | const TemplateTypeParmType *Replaced = | |||
1391 | cast<TemplateTypeParmType>((*ReplacedOrErr).getTypePtr()); | |||
1392 | ||||
1393 | ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); | |||
1394 | if (!ToReplacementTypeOrErr) | |||
1395 | return ToReplacementTypeOrErr.takeError(); | |||
1396 | ||||
1397 | return Importer.getToContext().getSubstTemplateTypeParmType( | |||
1398 | Replaced, (*ToReplacementTypeOrErr).getCanonicalType()); | |||
1399 | } | |||
1400 | ||||
1401 | ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( | |||
1402 | const TemplateSpecializationType *T) { | |||
1403 | auto ToTemplateOrErr = import(T->getTemplateName()); | |||
1404 | if (!ToTemplateOrErr) | |||
1405 | return ToTemplateOrErr.takeError(); | |||
1406 | ||||
1407 | SmallVector<TemplateArgument, 2> ToTemplateArgs; | |||
1408 | if (Error Err = ImportTemplateArguments( | |||
1409 | T->getArgs(), T->getNumArgs(), ToTemplateArgs)) | |||
1410 | return std::move(Err); | |||
1411 | ||||
1412 | QualType ToCanonType; | |||
1413 | if (!QualType(T, 0).isCanonical()) { | |||
1414 | QualType FromCanonType | |||
1415 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); | |||
1416 | if (ExpectedType TyOrErr = import(FromCanonType)) | |||
1417 | ToCanonType = *TyOrErr; | |||
1418 | else | |||
1419 | return TyOrErr.takeError(); | |||
1420 | } | |||
1421 | return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr, | |||
1422 | ToTemplateArgs, | |||
1423 | ToCanonType); | |||
1424 | } | |||
1425 | ||||
1426 | ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { | |||
1427 | // Note: the qualifier in an ElaboratedType is optional. | |||
1428 | auto ToQualifierOrErr = import(T->getQualifier()); | |||
1429 | if (!ToQualifierOrErr) | |||
1430 | return ToQualifierOrErr.takeError(); | |||
1431 | ||||
1432 | ExpectedType ToNamedTypeOrErr = import(T->getNamedType()); | |||
1433 | if (!ToNamedTypeOrErr) | |||
1434 | return ToNamedTypeOrErr.takeError(); | |||
1435 | ||||
1436 | Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl()); | |||
1437 | if (!ToOwnedTagDeclOrErr) | |||
1438 | return ToOwnedTagDeclOrErr.takeError(); | |||
1439 | ||||
1440 | return Importer.getToContext().getElaboratedType(T->getKeyword(), | |||
1441 | *ToQualifierOrErr, | |||
1442 | *ToNamedTypeOrErr, | |||
1443 | *ToOwnedTagDeclOrErr); | |||
1444 | } | |||
1445 | ||||
1446 | ExpectedType | |||
1447 | ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { | |||
1448 | ExpectedType ToPatternOrErr = import(T->getPattern()); | |||
1449 | if (!ToPatternOrErr) | |||
1450 | return ToPatternOrErr.takeError(); | |||
1451 | ||||
1452 | return Importer.getToContext().getPackExpansionType(*ToPatternOrErr, | |||
1453 | T->getNumExpansions()); | |||
1454 | } | |||
1455 | ||||
1456 | ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType( | |||
1457 | const DependentTemplateSpecializationType *T) { | |||
1458 | auto ToQualifierOrErr = import(T->getQualifier()); | |||
1459 | if (!ToQualifierOrErr) | |||
1460 | return ToQualifierOrErr.takeError(); | |||
1461 | ||||
1462 | IdentifierInfo *ToName = Importer.Import(T->getIdentifier()); | |||
1463 | ||||
1464 | SmallVector<TemplateArgument, 2> ToPack; | |||
1465 | ToPack.reserve(T->getNumArgs()); | |||
1466 | if (Error Err = ImportTemplateArguments( | |||
1467 | T->getArgs(), T->getNumArgs(), ToPack)) | |||
1468 | return std::move(Err); | |||
1469 | ||||
1470 | return Importer.getToContext().getDependentTemplateSpecializationType( | |||
1471 | T->getKeyword(), *ToQualifierOrErr, ToName, ToPack); | |||
1472 | } | |||
1473 | ||||
1474 | ExpectedType | |||
1475 | ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { | |||
1476 | auto ToQualifierOrErr = import(T->getQualifier()); | |||
1477 | if (!ToQualifierOrErr) | |||
1478 | return ToQualifierOrErr.takeError(); | |||
1479 | ||||
1480 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); | |||
1481 | ||||
1482 | QualType Canon; | |||
1483 | if (T != T->getCanonicalTypeInternal().getTypePtr()) { | |||
1484 | if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal())) | |||
1485 | Canon = (*TyOrErr).getCanonicalType(); | |||
1486 | else | |||
1487 | return TyOrErr.takeError(); | |||
1488 | } | |||
1489 | ||||
1490 | return Importer.getToContext().getDependentNameType(T->getKeyword(), | |||
1491 | *ToQualifierOrErr, | |||
1492 | Name, Canon); | |||
1493 | } | |||
1494 | ||||
1495 | ExpectedType | |||
1496 | ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { | |||
1497 | Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl()); | |||
1498 | if (!ToDeclOrErr) | |||
1499 | return ToDeclOrErr.takeError(); | |||
1500 | ||||
1501 | return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr); | |||
1502 | } | |||
1503 | ||||
1504 | ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { | |||
1505 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); | |||
1506 | if (!ToBaseTypeOrErr) | |||
1507 | return ToBaseTypeOrErr.takeError(); | |||
1508 | ||||
1509 | SmallVector<QualType, 4> TypeArgs; | |||
1510 | for (auto TypeArg : T->getTypeArgsAsWritten()) { | |||
1511 | if (ExpectedType TyOrErr = import(TypeArg)) | |||
1512 | TypeArgs.push_back(*TyOrErr); | |||
1513 | else | |||
1514 | return TyOrErr.takeError(); | |||
1515 | } | |||
1516 | ||||
1517 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | |||
1518 | for (auto *P : T->quals()) { | |||
1519 | if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P)) | |||
1520 | Protocols.push_back(*ProtocolOrErr); | |||
1521 | else | |||
1522 | return ProtocolOrErr.takeError(); | |||
1523 | ||||
1524 | } | |||
1525 | ||||
1526 | return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs, | |||
1527 | Protocols, | |||
1528 | T->isKindOfTypeAsWritten()); | |||
1529 | } | |||
1530 | ||||
1531 | ExpectedType | |||
1532 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { | |||
1533 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | |||
1534 | if (!ToPointeeTypeOrErr) | |||
1535 | return ToPointeeTypeOrErr.takeError(); | |||
1536 | ||||
1537 | return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr); | |||
1538 | } | |||
1539 | ||||
1540 | //---------------------------------------------------------------------------- | |||
1541 | // Import Declarations | |||
1542 | //---------------------------------------------------------------------------- | |||
1543 | Error ASTNodeImporter::ImportDeclParts( | |||
1544 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, | |||
1545 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) { | |||
1546 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. | |||
1547 | // example: int struct_in_proto(struct data_t{int a;int b;} *d); | |||
1548 | DeclContext *OrigDC = D->getDeclContext(); | |||
1549 | FunctionDecl *FunDecl; | |||
1550 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && | |||
1551 | FunDecl->hasBody()) { | |||
1552 | auto getLeafPointeeType = [](const Type *T) { | |||
1553 | while (T->isPointerType() || T->isArrayType()) { | |||
1554 | T = T->getPointeeOrArrayElementType(); | |||
1555 | } | |||
1556 | return T; | |||
1557 | }; | |||
1558 | for (const ParmVarDecl *P : FunDecl->parameters()) { | |||
1559 | const Type *LeafT = | |||
1560 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); | |||
1561 | auto *RT = dyn_cast<RecordType>(LeafT); | |||
1562 | if (RT && RT->getDecl() == D) { | |||
1563 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | |||
1564 | << D->getDeclKindName(); | |||
1565 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
1566 | } | |||
1567 | } | |||
1568 | } | |||
1569 | ||||
1570 | // Import the context of this declaration. | |||
1571 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
1572 | return Err; | |||
1573 | ||||
1574 | // Import the name of this declaration. | |||
1575 | if (Error Err = importInto(Name, D->getDeclName())) | |||
1576 | return Err; | |||
1577 | ||||
1578 | // Import the location of this declaration. | |||
1579 | if (Error Err = importInto(Loc, D->getLocation())) | |||
1580 | return Err; | |||
1581 | ||||
1582 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); | |||
1583 | if (ToD) | |||
1584 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD)) | |||
1585 | return Err; | |||
1586 | ||||
1587 | return Error::success(); | |||
1588 | } | |||
1589 | ||||
1590 | Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { | |||
1591 | if (!FromD) | |||
1592 | return Error::success(); | |||
1593 | ||||
1594 | if (!ToD) | |||
1595 | if (Error Err = importInto(ToD, FromD)) | |||
1596 | return Err; | |||
1597 | ||||
1598 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { | |||
1599 | if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) { | |||
1600 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && | |||
1601 | !ToRecord->getDefinition()) { | |||
1602 | if (Error Err = ImportDefinition(FromRecord, ToRecord)) | |||
1603 | return Err; | |||
1604 | } | |||
1605 | } | |||
1606 | return Error::success(); | |||
1607 | } | |||
1608 | ||||
1609 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { | |||
1610 | if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) { | |||
1611 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { | |||
1612 | if (Error Err = ImportDefinition(FromEnum, ToEnum)) | |||
1613 | return Err; | |||
1614 | } | |||
1615 | } | |||
1616 | return Error::success(); | |||
1617 | } | |||
1618 | ||||
1619 | return Error::success(); | |||
1620 | } | |||
1621 | ||||
1622 | Error | |||
1623 | ASTNodeImporter::ImportDeclarationNameLoc( | |||
1624 | const DeclarationNameInfo &From, DeclarationNameInfo& To) { | |||
1625 | // NOTE: To.Name and To.Loc are already imported. | |||
1626 | // We only have to import To.LocInfo. | |||
1627 | switch (To.getName().getNameKind()) { | |||
1628 | case DeclarationName::Identifier: | |||
1629 | case DeclarationName::ObjCZeroArgSelector: | |||
1630 | case DeclarationName::ObjCOneArgSelector: | |||
1631 | case DeclarationName::ObjCMultiArgSelector: | |||
1632 | case DeclarationName::CXXUsingDirective: | |||
1633 | case DeclarationName::CXXDeductionGuideName: | |||
1634 | return Error::success(); | |||
1635 | ||||
1636 | case DeclarationName::CXXOperatorName: { | |||
1637 | if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange())) | |||
1638 | To.setCXXOperatorNameRange(*ToRangeOrErr); | |||
1639 | else | |||
1640 | return ToRangeOrErr.takeError(); | |||
1641 | return Error::success(); | |||
1642 | } | |||
1643 | case DeclarationName::CXXLiteralOperatorName: { | |||
1644 | if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc())) | |||
1645 | To.setCXXLiteralOperatorNameLoc(*LocOrErr); | |||
1646 | else | |||
1647 | return LocOrErr.takeError(); | |||
1648 | return Error::success(); | |||
1649 | } | |||
1650 | case DeclarationName::CXXConstructorName: | |||
1651 | case DeclarationName::CXXDestructorName: | |||
1652 | case DeclarationName::CXXConversionFunctionName: { | |||
1653 | if (auto ToTInfoOrErr = import(From.getNamedTypeInfo())) | |||
1654 | To.setNamedTypeInfo(*ToTInfoOrErr); | |||
1655 | else | |||
1656 | return ToTInfoOrErr.takeError(); | |||
1657 | return Error::success(); | |||
1658 | } | |||
1659 | } | |||
1660 | llvm_unreachable("Unknown name kind.")::llvm::llvm_unreachable_internal("Unknown name kind.", "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 1660); | |||
1661 | } | |||
1662 | ||||
1663 | Error | |||
1664 | ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { | |||
1665 | if (Importer.isMinimalImport() && !ForceImport) { | |||
1666 | auto ToDCOrErr = Importer.ImportContext(FromDC); | |||
1667 | return ToDCOrErr.takeError(); | |||
1668 | } | |||
1669 | llvm::SmallVector<Decl *, 8> ImportedDecls; | |||
1670 | for (auto *From : FromDC->decls()) { | |||
1671 | ExpectedDecl ImportedOrErr = import(From); | |||
1672 | if (!ImportedOrErr) | |||
1673 | // Ignore the error, continue with next Decl. | |||
1674 | // FIXME: Handle this case somehow better. | |||
1675 | consumeError(ImportedOrErr.takeError()); | |||
1676 | } | |||
1677 | ||||
1678 | return Error::success(); | |||
1679 | } | |||
1680 | ||||
1681 | Error ASTNodeImporter::ImportDeclContext( | |||
1682 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { | |||
1683 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); | |||
1684 | if (!ToDCOrErr) | |||
1685 | return ToDCOrErr.takeError(); | |||
1686 | ToDC = *ToDCOrErr; | |||
1687 | ||||
1688 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { | |||
1689 | auto ToLexicalDCOrErr = Importer.ImportContext( | |||
1690 | FromD->getLexicalDeclContext()); | |||
1691 | if (!ToLexicalDCOrErr) | |||
1692 | return ToLexicalDCOrErr.takeError(); | |||
1693 | ToLexicalDC = *ToLexicalDCOrErr; | |||
1694 | } else | |||
1695 | ToLexicalDC = ToDC; | |||
1696 | ||||
1697 | return Error::success(); | |||
1698 | } | |||
1699 | ||||
1700 | Error ASTNodeImporter::ImportImplicitMethods( | |||
1701 | const CXXRecordDecl *From, CXXRecordDecl *To) { | |||
1702 | assert(From->isCompleteDefinition() && To->getDefinition() == To &&((From->isCompleteDefinition() && To->getDefinition () == To && "Import implicit methods to or from non-definition" ) ? static_cast<void> (0) : __assert_fail ("From->isCompleteDefinition() && To->getDefinition() == To && \"Import implicit methods to or from non-definition\"" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 1703, __PRETTY_FUNCTION__)) | |||
1703 | "Import implicit methods to or from non-definition")((From->isCompleteDefinition() && To->getDefinition () == To && "Import implicit methods to or from non-definition" ) ? static_cast<void> (0) : __assert_fail ("From->isCompleteDefinition() && To->getDefinition() == To && \"Import implicit methods to or from non-definition\"" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 1703, __PRETTY_FUNCTION__)); | |||
1704 | ||||
1705 | for (CXXMethodDecl *FromM : From->methods()) | |||
1706 | if (FromM->isImplicit()) { | |||
1707 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); | |||
1708 | if (!ToMOrErr) | |||
1709 | return ToMOrErr.takeError(); | |||
1710 | } | |||
1711 | ||||
1712 | return Error::success(); | |||
1713 | } | |||
1714 | ||||
1715 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, | |||
1716 | ASTImporter &Importer) { | |||
1717 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { | |||
1718 | Decl *ToTypedef = Importer.Import(FromTypedef); | |||
1719 | if (!ToTypedef) | |||
1720 | return make_error<ImportError>(); | |||
1721 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(ToTypedef)); | |||
1722 | // FIXME: This should be the final code. | |||
1723 | //if (Expected<Decl *> ToTypedefOrErr = Importer.Import(FromTypedef)) | |||
1724 | // To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); | |||
1725 | //else | |||
1726 | // return ToTypedefOrErr.takeError(); | |||
1727 | } | |||
1728 | return Error::success(); | |||
1729 | } | |||
1730 | ||||
1731 | Error ASTNodeImporter::ImportDefinition( | |||
1732 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { | |||
1733 | if (To->getDefinition() || To->isBeingDefined()) { | |||
1734 | if (Kind == IDK_Everything) | |||
1735 | return ImportDeclContext(From, /*ForceImport=*/true); | |||
1736 | ||||
1737 | return Error::success(); | |||
1738 | } | |||
1739 | ||||
1740 | To->startDefinition(); | |||
1741 | ||||
1742 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) | |||
1743 | return Err; | |||
1744 | ||||
1745 | // Add base classes. | |||
1746 | auto *ToCXX = dyn_cast<CXXRecordDecl>(To); | |||
1747 | auto *FromCXX = dyn_cast<CXXRecordDecl>(From); | |||
1748 | if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) { | |||
1749 | ||||
1750 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); | |||
1751 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); | |||
1752 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; | |||
1753 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; | |||
1754 | ToData.Aggregate = FromData.Aggregate; | |||
1755 | ToData.PlainOldData = FromData.PlainOldData; | |||
1756 | ToData.Empty = FromData.Empty; | |||
1757 | ToData.Polymorphic = FromData.Polymorphic; | |||
1758 | ToData.Abstract = FromData.Abstract; | |||
1759 | ToData.IsStandardLayout = FromData.IsStandardLayout; | |||
1760 | ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout; | |||
1761 | ToData.HasBasesWithFields = FromData.HasBasesWithFields; | |||
1762 | ToData.HasBasesWithNonStaticDataMembers = | |||
1763 | FromData.HasBasesWithNonStaticDataMembers; | |||
1764 | ToData.HasPrivateFields = FromData.HasPrivateFields; | |||
1765 | ToData.HasProtectedFields = FromData.HasProtectedFields; | |||
1766 | ToData.HasPublicFields = FromData.HasPublicFields; | |||
1767 | ToData.HasMutableFields = FromData.HasMutableFields; | |||
1768 | ToData.HasVariantMembers = FromData.HasVariantMembers; | |||
1769 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; | |||
1770 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; | |||
1771 | ToData.HasUninitializedReferenceMember | |||
1772 | = FromData.HasUninitializedReferenceMember; | |||
1773 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; | |||
1774 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; | |||
1775 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; | |||
1776 | ToData.NeedOverloadResolutionForCopyConstructor | |||
1777 | = FromData.NeedOverloadResolutionForCopyConstructor; | |||
1778 | ToData.NeedOverloadResolutionForMoveConstructor | |||
1779 | = FromData.NeedOverloadResolutionForMoveConstructor; | |||
1780 | ToData.NeedOverloadResolutionForMoveAssignment | |||
1781 | = FromData.NeedOverloadResolutionForMoveAssignment; | |||
1782 | ToData.NeedOverloadResolutionForDestructor | |||
1783 | = FromData.NeedOverloadResolutionForDestructor; | |||
1784 | ToData.DefaultedCopyConstructorIsDeleted | |||
1785 | = FromData.DefaultedCopyConstructorIsDeleted; | |||
1786 | ToData.DefaultedMoveConstructorIsDeleted | |||
1787 | = FromData.DefaultedMoveConstructorIsDeleted; | |||
1788 | ToData.DefaultedMoveAssignmentIsDeleted | |||
1789 | = FromData.DefaultedMoveAssignmentIsDeleted; | |||
1790 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; | |||
1791 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; | |||
1792 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; | |||
1793 | ToData.HasConstexprNonCopyMoveConstructor | |||
1794 | = FromData.HasConstexprNonCopyMoveConstructor; | |||
1795 | ToData.HasDefaultedDefaultConstructor | |||
1796 | = FromData.HasDefaultedDefaultConstructor; | |||
1797 | ToData.DefaultedDefaultConstructorIsConstexpr | |||
1798 | = FromData.DefaultedDefaultConstructorIsConstexpr; | |||
1799 | ToData.HasConstexprDefaultConstructor | |||
1800 | = FromData.HasConstexprDefaultConstructor; | |||
1801 | ToData.HasNonLiteralTypeFieldsOrBases | |||
1802 | = FromData.HasNonLiteralTypeFieldsOrBases; | |||
1803 | // ComputedVisibleConversions not imported. | |||
1804 | ToData.UserProvidedDefaultConstructor | |||
1805 | = FromData.UserProvidedDefaultConstructor; | |||
1806 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; | |||
1807 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase | |||
1808 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; | |||
1809 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase | |||
1810 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; | |||
1811 | ToData.ImplicitCopyAssignmentHasConstParam | |||
1812 | = FromData.ImplicitCopyAssignmentHasConstParam; | |||
1813 | ToData.HasDeclaredCopyConstructorWithConstParam | |||
1814 | = FromData.HasDeclaredCopyConstructorWithConstParam; | |||
1815 | ToData.HasDeclaredCopyAssignmentWithConstParam | |||
1816 | = FromData.HasDeclaredCopyAssignmentWithConstParam; | |||
1817 | ||||
1818 | SmallVector<CXXBaseSpecifier *, 4> Bases; | |||
1819 | for (const auto &Base1 : FromCXX->bases()) { | |||
1820 | ExpectedType TyOrErr = import(Base1.getType()); | |||
1821 | if (!TyOrErr) | |||
1822 | return TyOrErr.takeError(); | |||
1823 | ||||
1824 | SourceLocation EllipsisLoc; | |||
1825 | if (Base1.isPackExpansion()) { | |||
1826 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) | |||
1827 | EllipsisLoc = *LocOrErr; | |||
1828 | else | |||
1829 | return LocOrErr.takeError(); | |||
1830 | } | |||
1831 | ||||
1832 | // Ensure that we have a definition for the base. | |||
1833 | if (Error Err = | |||
1834 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) | |||
1835 | return Err; | |||
1836 | ||||
1837 | auto RangeOrErr = import(Base1.getSourceRange()); | |||
1838 | if (!RangeOrErr) | |||
1839 | return RangeOrErr.takeError(); | |||
1840 | ||||
1841 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); | |||
1842 | if (!TSIOrErr) | |||
1843 | return TSIOrErr.takeError(); | |||
1844 | ||||
1845 | Bases.push_back( | |||
1846 | new (Importer.getToContext()) CXXBaseSpecifier( | |||
1847 | *RangeOrErr, | |||
1848 | Base1.isVirtual(), | |||
1849 | Base1.isBaseOfClass(), | |||
1850 | Base1.getAccessSpecifierAsWritten(), | |||
1851 | *TSIOrErr, | |||
1852 | EllipsisLoc)); | |||
1853 | } | |||
1854 | if (!Bases.empty()) | |||
1855 | ToCXX->setBases(Bases.data(), Bases.size()); | |||
1856 | } | |||
1857 | ||||
1858 | if (shouldForceImportDeclContext(Kind)) | |||
1859 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | |||
1860 | return Err; | |||
1861 | ||||
1862 | To->completeDefinition(); | |||
1863 | return Error::success(); | |||
1864 | } | |||
1865 | ||||
1866 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { | |||
1867 | if (To->getAnyInitializer()) | |||
1868 | return Error::success(); | |||
1869 | ||||
1870 | Expr *FromInit = From->getInit(); | |||
1871 | if (!FromInit) | |||
1872 | return Error::success(); | |||
1873 | ||||
1874 | ExpectedExpr ToInitOrErr = import(FromInit); | |||
1875 | if (!ToInitOrErr) | |||
1876 | return ToInitOrErr.takeError(); | |||
1877 | ||||
1878 | To->setInit(*ToInitOrErr); | |||
1879 | if (From->isInitKnownICE()) { | |||
1880 | EvaluatedStmt *Eval = To->ensureEvaluatedStmt(); | |||
1881 | Eval->CheckedICE = true; | |||
1882 | Eval->IsICE = From->isInitICE(); | |||
1883 | } | |||
1884 | ||||
1885 | // FIXME: Other bits to merge? | |||
1886 | return Error::success(); | |||
1887 | } | |||
1888 | ||||
1889 | Error ASTNodeImporter::ImportDefinition( | |||
1890 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { | |||
1891 | if (To->getDefinition() || To->isBeingDefined()) { | |||
1892 | if (Kind == IDK_Everything) | |||
1893 | return ImportDeclContext(From, /*ForceImport=*/true); | |||
1894 | return Error::success(); | |||
1895 | } | |||
1896 | ||||
1897 | To->startDefinition(); | |||
1898 | ||||
1899 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) | |||
1900 | return Err; | |||
1901 | ||||
1902 | ExpectedType ToTypeOrErr = | |||
1903 | import(Importer.getFromContext().getTypeDeclType(From)); | |||
1904 | if (!ToTypeOrErr) | |||
1905 | return ToTypeOrErr.takeError(); | |||
1906 | ||||
1907 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); | |||
1908 | if (!ToPromotionTypeOrErr) | |||
1909 | return ToPromotionTypeOrErr.takeError(); | |||
1910 | ||||
1911 | if (shouldForceImportDeclContext(Kind)) | |||
1912 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | |||
1913 | return Err; | |||
1914 | ||||
1915 | // FIXME: we might need to merge the number of positive or negative bits | |||
1916 | // if the enumerator lists don't match. | |||
1917 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, | |||
1918 | From->getNumPositiveBits(), | |||
1919 | From->getNumNegativeBits()); | |||
1920 | return Error::success(); | |||
1921 | } | |||
1922 | ||||
1923 | // FIXME: Remove this, use `import` instead. | |||
1924 | Expected<TemplateParameterList *> ASTNodeImporter::ImportTemplateParameterList( | |||
1925 | TemplateParameterList *Params) { | |||
1926 | SmallVector<NamedDecl *, 4> ToParams(Params->size()); | |||
1927 | if (Error Err = ImportContainerChecked(*Params, ToParams)) | |||
1928 | return std::move(Err); | |||
1929 | ||||
1930 | Expr *ToRequiresClause; | |||
1931 | if (Expr *const R = Params->getRequiresClause()) { | |||
1932 | if (Error Err = importInto(ToRequiresClause, R)) | |||
1933 | return std::move(Err); | |||
1934 | } else { | |||
1935 | ToRequiresClause = nullptr; | |||
1936 | } | |||
1937 | ||||
1938 | auto ToTemplateLocOrErr = import(Params->getTemplateLoc()); | |||
1939 | if (!ToTemplateLocOrErr) | |||
1940 | return ToTemplateLocOrErr.takeError(); | |||
1941 | auto ToLAngleLocOrErr = import(Params->getLAngleLoc()); | |||
1942 | if (!ToLAngleLocOrErr) | |||
1943 | return ToLAngleLocOrErr.takeError(); | |||
1944 | auto ToRAngleLocOrErr = import(Params->getRAngleLoc()); | |||
1945 | if (!ToRAngleLocOrErr) | |||
1946 | return ToRAngleLocOrErr.takeError(); | |||
1947 | ||||
1948 | return TemplateParameterList::Create( | |||
1949 | Importer.getToContext(), | |||
1950 | *ToTemplateLocOrErr, | |||
1951 | *ToLAngleLocOrErr, | |||
1952 | ToParams, | |||
1953 | *ToRAngleLocOrErr, | |||
1954 | ToRequiresClause); | |||
1955 | } | |||
1956 | ||||
1957 | Error ASTNodeImporter::ImportTemplateArguments( | |||
1958 | const TemplateArgument *FromArgs, unsigned NumFromArgs, | |||
1959 | SmallVectorImpl<TemplateArgument> &ToArgs) { | |||
1960 | for (unsigned I = 0; I != NumFromArgs; ++I) { | |||
1961 | if (auto ToOrErr = import(FromArgs[I])) | |||
1962 | ToArgs.push_back(*ToOrErr); | |||
1963 | else | |||
1964 | return ToOrErr.takeError(); | |||
1965 | } | |||
1966 | ||||
1967 | return Error::success(); | |||
1968 | } | |||
1969 | ||||
1970 | // FIXME: Do not forget to remove this and use only 'import'. | |||
1971 | Expected<TemplateArgument> | |||
1972 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { | |||
1973 | return import(From); | |||
1974 | } | |||
1975 | ||||
1976 | template <typename InContainerTy> | |||
1977 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( | |||
1978 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { | |||
1979 | for (const auto &FromLoc : Container) { | |||
1980 | if (auto ToLocOrErr = import(FromLoc)) | |||
1981 | ToTAInfo.addArgument(*ToLocOrErr); | |||
1982 | else | |||
1983 | return ToLocOrErr.takeError(); | |||
1984 | } | |||
1985 | return Error::success(); | |||
1986 | } | |||
1987 | ||||
1988 | static StructuralEquivalenceKind | |||
1989 | getStructuralEquivalenceKind(const ASTImporter &Importer) { | |||
1990 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal | |||
1991 | : StructuralEquivalenceKind::Default; | |||
1992 | } | |||
1993 | ||||
1994 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { | |||
1995 | StructuralEquivalenceContext Ctx( | |||
1996 | Importer.getFromContext(), Importer.getToContext(), | |||
1997 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | |||
1998 | false, Complain); | |||
1999 | return Ctx.IsEquivalent(From, To); | |||
2000 | } | |||
2001 | ||||
2002 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, | |||
2003 | RecordDecl *ToRecord, bool Complain) { | |||
2004 | // Eliminate a potential failure point where we attempt to re-import | |||
2005 | // something we're trying to import while completing ToRecord. | |||
2006 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); | |||
2007 | if (ToOrigin) { | |||
2008 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); | |||
2009 | if (ToOriginRecord) | |||
2010 | ToRecord = ToOriginRecord; | |||
2011 | } | |||
2012 | ||||
2013 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | |||
2014 | ToRecord->getASTContext(), | |||
2015 | Importer.getNonEquivalentDecls(), | |||
2016 | getStructuralEquivalenceKind(Importer), | |||
2017 | false, Complain); | |||
2018 | return Ctx.IsEquivalent(FromRecord, ToRecord); | |||
2019 | } | |||
2020 | ||||
2021 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, | |||
2022 | bool Complain) { | |||
2023 | StructuralEquivalenceContext Ctx( | |||
2024 | Importer.getFromContext(), Importer.getToContext(), | |||
2025 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | |||
2026 | false, Complain); | |||
2027 | return Ctx.IsEquivalent(FromVar, ToVar); | |||
2028 | } | |||
2029 | ||||
2030 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { | |||
2031 | StructuralEquivalenceContext Ctx( | |||
2032 | Importer.getFromContext(), Importer.getToContext(), | |||
2033 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); | |||
2034 | return Ctx.IsEquivalent(FromEnum, ToEnum); | |||
2035 | } | |||
2036 | ||||
2037 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, | |||
2038 | FunctionTemplateDecl *To) { | |||
2039 | StructuralEquivalenceContext Ctx( | |||
2040 | Importer.getFromContext(), Importer.getToContext(), | |||
2041 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | |||
2042 | false, false); | |||
2043 | return Ctx.IsEquivalent(From, To); | |||
2044 | } | |||
2045 | ||||
2046 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { | |||
2047 | StructuralEquivalenceContext Ctx( | |||
2048 | Importer.getFromContext(), Importer.getToContext(), | |||
2049 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | |||
2050 | false, false); | |||
2051 | return Ctx.IsEquivalent(From, To); | |||
2052 | } | |||
2053 | ||||
2054 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, | |||
2055 | EnumConstantDecl *ToEC) { | |||
2056 | const llvm::APSInt &FromVal = FromEC->getInitVal(); | |||
2057 | const llvm::APSInt &ToVal = ToEC->getInitVal(); | |||
2058 | ||||
2059 | return FromVal.isSigned() == ToVal.isSigned() && | |||
2060 | FromVal.getBitWidth() == ToVal.getBitWidth() && | |||
2061 | FromVal == ToVal; | |||
2062 | } | |||
2063 | ||||
2064 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, | |||
2065 | ClassTemplateDecl *To) { | |||
2066 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | |||
2067 | Importer.getToContext(), | |||
2068 | Importer.getNonEquivalentDecls(), | |||
2069 | getStructuralEquivalenceKind(Importer)); | |||
2070 | return Ctx.IsEquivalent(From, To); | |||
2071 | } | |||
2072 | ||||
2073 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, | |||
2074 | VarTemplateDecl *To) { | |||
2075 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | |||
2076 | Importer.getToContext(), | |||
2077 | Importer.getNonEquivalentDecls(), | |||
2078 | getStructuralEquivalenceKind(Importer)); | |||
2079 | return Ctx.IsEquivalent(From, To); | |||
2080 | } | |||
2081 | ||||
2082 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { | |||
2083 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | |||
2084 | << D->getDeclKindName(); | |||
2085 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
2086 | } | |||
2087 | ||||
2088 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { | |||
2089 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | |||
2090 | << D->getDeclKindName(); | |||
2091 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
2092 | } | |||
2093 | ||||
2094 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { | |||
2095 | // Import the context of this declaration. | |||
2096 | DeclContext *DC, *LexicalDC; | |||
2097 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
2098 | return std::move(Err); | |||
2099 | ||||
2100 | // Import the location of this declaration. | |||
2101 | ExpectedSLoc LocOrErr = import(D->getLocation()); | |||
2102 | if (!LocOrErr) | |||
2103 | return LocOrErr.takeError(); | |||
2104 | ||||
2105 | EmptyDecl *ToD; | |||
2106 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) | |||
2107 | return ToD; | |||
2108 | ||||
2109 | ToD->setLexicalDeclContext(LexicalDC); | |||
2110 | LexicalDC->addDeclInternal(ToD); | |||
2111 | return ToD; | |||
2112 | } | |||
2113 | ||||
2114 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { | |||
2115 | TranslationUnitDecl *ToD = | |||
2116 | Importer.getToContext().getTranslationUnitDecl(); | |||
2117 | ||||
2118 | Importer.MapImported(D, ToD); | |||
2119 | ||||
2120 | return ToD; | |||
2121 | } | |||
2122 | ||||
2123 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { | |||
2124 | ExpectedSLoc LocOrErr = import(D->getLocation()); | |||
2125 | if (!LocOrErr) | |||
2126 | return LocOrErr.takeError(); | |||
2127 | auto ColonLocOrErr = import(D->getColonLoc()); | |||
2128 | if (!ColonLocOrErr) | |||
2129 | return ColonLocOrErr.takeError(); | |||
2130 | ||||
2131 | // Import the context of this declaration. | |||
2132 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); | |||
2133 | if (!DCOrErr) | |||
2134 | return DCOrErr.takeError(); | |||
2135 | DeclContext *DC = *DCOrErr; | |||
2136 | ||||
2137 | AccessSpecDecl *ToD; | |||
2138 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), | |||
2139 | DC, *LocOrErr, *ColonLocOrErr)) | |||
2140 | return ToD; | |||
2141 | ||||
2142 | // Lexical DeclContext and Semantic DeclContext | |||
2143 | // is always the same for the accessSpec. | |||
2144 | ToD->setLexicalDeclContext(DC); | |||
2145 | DC->addDeclInternal(ToD); | |||
2146 | ||||
2147 | return ToD; | |||
2148 | } | |||
2149 | ||||
2150 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { | |||
2151 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); | |||
2152 | if (!DCOrErr) | |||
2153 | return DCOrErr.takeError(); | |||
2154 | DeclContext *DC = *DCOrErr; | |||
2155 | DeclContext *LexicalDC = DC; | |||
2156 | ||||
2157 | SourceLocation ToLocation, ToRParenLoc; | |||
2158 | Expr *ToAssertExpr; | |||
2159 | StringLiteral *ToMessage; | |||
2160 | if (auto Imp = importSeq( | |||
2161 | D->getLocation(), D->getAssertExpr(), D->getMessage(), D->getRParenLoc())) | |||
2162 | std::tie(ToLocation, ToAssertExpr, ToMessage, ToRParenLoc) = *Imp; | |||
2163 | else | |||
2164 | return Imp.takeError(); | |||
2165 | ||||
2166 | StaticAssertDecl *ToD; | |||
2167 | if (GetImportedOrCreateDecl( | |||
2168 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, | |||
2169 | ToRParenLoc, D->isFailed())) | |||
2170 | return ToD; | |||
2171 | ||||
2172 | ToD->setLexicalDeclContext(LexicalDC); | |||
2173 | LexicalDC->addDeclInternal(ToD); | |||
2174 | return ToD; | |||
2175 | } | |||
2176 | ||||
2177 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { | |||
2178 | // Import the major distinguishing characteristics of this namespace. | |||
2179 | DeclContext *DC, *LexicalDC; | |||
2180 | DeclarationName Name; | |||
2181 | SourceLocation Loc; | |||
2182 | NamedDecl *ToD; | |||
2183 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
2184 | return std::move(Err); | |||
2185 | if (ToD) | |||
2186 | return ToD; | |||
2187 | ||||
2188 | NamespaceDecl *MergeWithNamespace = nullptr; | |||
2189 | if (!Name) { | |||
2190 | // This is an anonymous namespace. Adopt an existing anonymous | |||
2191 | // namespace if we can. | |||
2192 | // FIXME: Not testable. | |||
2193 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) | |||
2194 | MergeWithNamespace = TU->getAnonymousNamespace(); | |||
2195 | else | |||
2196 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); | |||
2197 | } else { | |||
2198 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
2199 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
2200 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
2201 | for (auto *FoundDecl : FoundDecls) { | |||
2202 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) | |||
2203 | continue; | |||
2204 | ||||
2205 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { | |||
2206 | MergeWithNamespace = FoundNS; | |||
2207 | ConflictingDecls.clear(); | |||
2208 | break; | |||
2209 | } | |||
2210 | ||||
2211 | ConflictingDecls.push_back(FoundDecl); | |||
2212 | } | |||
2213 | ||||
2214 | if (!ConflictingDecls.empty()) { | |||
2215 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, | |||
2216 | ConflictingDecls.data(), | |||
2217 | ConflictingDecls.size()); | |||
2218 | if (!Name) | |||
2219 | return make_error<ImportError>(ImportError::NameConflict); | |||
2220 | } | |||
2221 | } | |||
2222 | ||||
2223 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | |||
2224 | if (!BeginLocOrErr) | |||
2225 | return BeginLocOrErr.takeError(); | |||
2226 | ||||
2227 | // Create the "to" namespace, if needed. | |||
2228 | NamespaceDecl *ToNamespace = MergeWithNamespace; | |||
2229 | if (!ToNamespace) { | |||
2230 | if (GetImportedOrCreateDecl( | |||
2231 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), | |||
2232 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), | |||
2233 | /*PrevDecl=*/nullptr)) | |||
2234 | return ToNamespace; | |||
2235 | ToNamespace->setLexicalDeclContext(LexicalDC); | |||
2236 | LexicalDC->addDeclInternal(ToNamespace); | |||
2237 | ||||
2238 | // If this is an anonymous namespace, register it as the anonymous | |||
2239 | // namespace within its context. | |||
2240 | if (!Name) { | |||
2241 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) | |||
2242 | TU->setAnonymousNamespace(ToNamespace); | |||
2243 | else | |||
2244 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); | |||
2245 | } | |||
2246 | } | |||
2247 | Importer.MapImported(D, ToNamespace); | |||
2248 | ||||
2249 | if (Error Err = ImportDeclContext(D)) | |||
2250 | return std::move(Err); | |||
2251 | ||||
2252 | return ToNamespace; | |||
2253 | } | |||
2254 | ||||
2255 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { | |||
2256 | // Import the major distinguishing characteristics of this namespace. | |||
2257 | DeclContext *DC, *LexicalDC; | |||
2258 | DeclarationName Name; | |||
2259 | SourceLocation Loc; | |||
2260 | NamedDecl *LookupD; | |||
2261 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) | |||
2262 | return std::move(Err); | |||
2263 | if (LookupD) | |||
2264 | return LookupD; | |||
2265 | ||||
2266 | // NOTE: No conflict resolution is done for namespace aliases now. | |||
2267 | ||||
2268 | SourceLocation ToNamespaceLoc, ToAliasLoc, ToTargetNameLoc; | |||
2269 | NestedNameSpecifierLoc ToQualifierLoc; | |||
2270 | NamespaceDecl *ToNamespace; | |||
2271 | if (auto Imp = importSeq( | |||
2272 | D->getNamespaceLoc(), D->getAliasLoc(), D->getQualifierLoc(), | |||
2273 | D->getTargetNameLoc(), D->getNamespace())) | |||
2274 | std::tie( | |||
2275 | ToNamespaceLoc, ToAliasLoc, ToQualifierLoc, ToTargetNameLoc, | |||
2276 | ToNamespace) = *Imp; | |||
2277 | else | |||
2278 | return Imp.takeError(); | |||
2279 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); | |||
2280 | ||||
2281 | NamespaceAliasDecl *ToD; | |||
2282 | if (GetImportedOrCreateDecl( | |||
2283 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, | |||
2284 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) | |||
2285 | return ToD; | |||
2286 | ||||
2287 | ToD->setLexicalDeclContext(LexicalDC); | |||
2288 | LexicalDC->addDeclInternal(ToD); | |||
2289 | ||||
2290 | return ToD; | |||
2291 | } | |||
2292 | ||||
2293 | ExpectedDecl | |||
2294 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { | |||
2295 | // Import the major distinguishing characteristics of this typedef. | |||
2296 | DeclContext *DC, *LexicalDC; | |||
2297 | DeclarationName Name; | |||
2298 | SourceLocation Loc; | |||
2299 | NamedDecl *ToD; | |||
2300 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
2301 | return std::move(Err); | |||
2302 | if (ToD) | |||
2303 | return ToD; | |||
2304 | ||||
2305 | // If this typedef is not in block scope, determine whether we've | |||
2306 | // seen a typedef with the same name (that we can merge with) or any | |||
2307 | // other entity by that name (which name lookup could conflict with). | |||
2308 | if (!DC->isFunctionOrMethod()) { | |||
2309 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
2310 | unsigned IDNS = Decl::IDNS_Ordinary; | |||
2311 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
2312 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
2313 | for (auto *FoundDecl : FoundDecls) { | |||
2314 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
2315 | continue; | |||
2316 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { | |||
2317 | QualType FromUT = D->getUnderlyingType(); | |||
2318 | QualType FoundUT = FoundTypedef->getUnderlyingType(); | |||
2319 | if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) { | |||
2320 | // If the "From" context has a complete underlying type but we | |||
2321 | // already have a complete underlying type then return with that. | |||
2322 | if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType()) | |||
2323 | return Importer.MapImported(D, FoundTypedef); | |||
2324 | } | |||
2325 | // FIXME Handle redecl chain. | |||
2326 | break; | |||
2327 | } | |||
2328 | ||||
2329 | ConflictingDecls.push_back(FoundDecl); | |||
2330 | } | |||
2331 | ||||
2332 | if (!ConflictingDecls.empty()) { | |||
2333 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | |||
2334 | ConflictingDecls.data(), | |||
2335 | ConflictingDecls.size()); | |||
2336 | if (!Name) | |||
2337 | return make_error<ImportError>(ImportError::NameConflict); | |||
2338 | } | |||
2339 | } | |||
2340 | ||||
2341 | QualType ToUnderlyingType; | |||
2342 | TypeSourceInfo *ToTypeSourceInfo; | |||
2343 | SourceLocation ToBeginLoc; | |||
2344 | if (auto Imp = importSeq( | |||
2345 | D->getUnderlyingType(), D->getTypeSourceInfo(), D->getBeginLoc())) | |||
2346 | std::tie(ToUnderlyingType, ToTypeSourceInfo, ToBeginLoc) = *Imp; | |||
2347 | else | |||
2348 | return Imp.takeError(); | |||
2349 | ||||
2350 | // Create the new typedef node. | |||
2351 | // FIXME: ToUnderlyingType is not used. | |||
2352 | TypedefNameDecl *ToTypedef; | |||
2353 | if (IsAlias) { | |||
2354 | if (GetImportedOrCreateDecl<TypeAliasDecl>( | |||
2355 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, | |||
2356 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) | |||
2357 | return ToTypedef; | |||
2358 | } else if (GetImportedOrCreateDecl<TypedefDecl>( | |||
2359 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, | |||
2360 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) | |||
2361 | return ToTypedef; | |||
2362 | ||||
2363 | ToTypedef->setAccess(D->getAccess()); | |||
2364 | ToTypedef->setLexicalDeclContext(LexicalDC); | |||
2365 | ||||
2366 | // Templated declarations should not appear in DeclContext. | |||
2367 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; | |||
2368 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) | |||
2369 | LexicalDC->addDeclInternal(ToTypedef); | |||
2370 | ||||
2371 | return ToTypedef; | |||
2372 | } | |||
2373 | ||||
2374 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { | |||
2375 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); | |||
2376 | } | |||
2377 | ||||
2378 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { | |||
2379 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); | |||
2380 | } | |||
2381 | ||||
2382 | ExpectedDecl | |||
2383 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { | |||
2384 | // Import the major distinguishing characteristics of this typedef. | |||
2385 | DeclContext *DC, *LexicalDC; | |||
2386 | DeclarationName Name; | |||
2387 | SourceLocation Loc; | |||
2388 | NamedDecl *FoundD; | |||
2389 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) | |||
2390 | return std::move(Err); | |||
2391 | if (FoundD) | |||
2392 | return FoundD; | |||
2393 | ||||
2394 | // If this typedef is not in block scope, determine whether we've | |||
2395 | // seen a typedef with the same name (that we can merge with) or any | |||
2396 | // other entity by that name (which name lookup could conflict with). | |||
2397 | if (!DC->isFunctionOrMethod()) { | |||
2398 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
2399 | unsigned IDNS = Decl::IDNS_Ordinary; | |||
2400 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
2401 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
2402 | for (auto *FoundDecl : FoundDecls) { | |||
2403 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
2404 | continue; | |||
2405 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) | |||
2406 | return Importer.MapImported(D, FoundAlias); | |||
2407 | ConflictingDecls.push_back(FoundDecl); | |||
2408 | } | |||
2409 | ||||
2410 | if (!ConflictingDecls.empty()) { | |||
2411 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | |||
2412 | ConflictingDecls.data(), | |||
2413 | ConflictingDecls.size()); | |||
2414 | if (!Name) | |||
2415 | return make_error<ImportError>(ImportError::NameConflict); | |||
2416 | } | |||
2417 | } | |||
2418 | ||||
2419 | TemplateParameterList *ToTemplateParameters; | |||
2420 | TypeAliasDecl *ToTemplatedDecl; | |||
2421 | if (auto Imp = importSeq(D->getTemplateParameters(), D->getTemplatedDecl())) | |||
2422 | std::tie(ToTemplateParameters, ToTemplatedDecl) = *Imp; | |||
2423 | else | |||
2424 | return Imp.takeError(); | |||
2425 | ||||
2426 | TypeAliasTemplateDecl *ToAlias; | |||
2427 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, | |||
2428 | Name, ToTemplateParameters, ToTemplatedDecl)) | |||
2429 | return ToAlias; | |||
2430 | ||||
2431 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); | |||
2432 | ||||
2433 | ToAlias->setAccess(D->getAccess()); | |||
2434 | ToAlias->setLexicalDeclContext(LexicalDC); | |||
2435 | LexicalDC->addDeclInternal(ToAlias); | |||
2436 | return ToAlias; | |||
2437 | } | |||
2438 | ||||
2439 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { | |||
2440 | // Import the major distinguishing characteristics of this label. | |||
2441 | DeclContext *DC, *LexicalDC; | |||
2442 | DeclarationName Name; | |||
2443 | SourceLocation Loc; | |||
2444 | NamedDecl *ToD; | |||
2445 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
2446 | return std::move(Err); | |||
2447 | if (ToD) | |||
2448 | return ToD; | |||
2449 | ||||
2450 | assert(LexicalDC->isFunctionOrMethod())((LexicalDC->isFunctionOrMethod()) ? static_cast<void> (0) : __assert_fail ("LexicalDC->isFunctionOrMethod()", "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 2450, __PRETTY_FUNCTION__)); | |||
2451 | ||||
2452 | LabelDecl *ToLabel; | |||
2453 | if (D->isGnuLocal()) { | |||
2454 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | |||
2455 | if (!BeginLocOrErr) | |||
2456 | return BeginLocOrErr.takeError(); | |||
2457 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, | |||
2458 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) | |||
2459 | return ToLabel; | |||
2460 | ||||
2461 | } else { | |||
2462 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, | |||
2463 | Name.getAsIdentifierInfo())) | |||
2464 | return ToLabel; | |||
2465 | ||||
2466 | } | |||
2467 | ||||
2468 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); | |||
2469 | if (!ToStmtOrErr) | |||
2470 | return ToStmtOrErr.takeError(); | |||
2471 | ||||
2472 | ToLabel->setStmt(*ToStmtOrErr); | |||
2473 | ToLabel->setLexicalDeclContext(LexicalDC); | |||
2474 | LexicalDC->addDeclInternal(ToLabel); | |||
2475 | return ToLabel; | |||
2476 | } | |||
2477 | ||||
2478 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { | |||
2479 | // Import the major distinguishing characteristics of this enum. | |||
2480 | DeclContext *DC, *LexicalDC; | |||
2481 | DeclarationName Name; | |||
2482 | SourceLocation Loc; | |||
2483 | NamedDecl *ToD; | |||
2484 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
2485 | return std::move(Err); | |||
2486 | if (ToD) | |||
2487 | return ToD; | |||
2488 | ||||
2489 | // Figure out what enum name we're looking for. | |||
2490 | unsigned IDNS = Decl::IDNS_Tag; | |||
2491 | DeclarationName SearchName = Name; | |||
2492 | if (!SearchName && D->getTypedefNameForAnonDecl()) { | |||
2493 | if (Error Err = importInto( | |||
2494 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) | |||
2495 | return std::move(Err); | |||
2496 | IDNS = Decl::IDNS_Ordinary; | |||
2497 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) | |||
2498 | IDNS |= Decl::IDNS_Ordinary; | |||
2499 | ||||
2500 | // We may already have an enum of the same name; try to find and match it. | |||
2501 | if (!DC->isFunctionOrMethod() && SearchName) { | |||
2502 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
2503 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
2504 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); | |||
2505 | for (auto *FoundDecl : FoundDecls) { | |||
2506 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
2507 | continue; | |||
2508 | ||||
2509 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { | |||
2510 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) | |||
2511 | FoundDecl = Tag->getDecl(); | |||
2512 | } | |||
2513 | ||||
2514 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { | |||
2515 | if (IsStructuralMatch(D, FoundEnum)) | |||
2516 | return Importer.MapImported(D, FoundEnum); | |||
2517 | } | |||
2518 | ||||
2519 | ConflictingDecls.push_back(FoundDecl); | |||
2520 | } | |||
2521 | ||||
2522 | if (!ConflictingDecls.empty()) { | |||
2523 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | |||
2524 | ConflictingDecls.data(), | |||
2525 | ConflictingDecls.size()); | |||
2526 | if (!Name) | |||
2527 | return make_error<ImportError>(ImportError::NameConflict); | |||
2528 | } | |||
2529 | } | |||
2530 | ||||
2531 | SourceLocation ToBeginLoc; | |||
2532 | NestedNameSpecifierLoc ToQualifierLoc; | |||
2533 | QualType ToIntegerType; | |||
2534 | if (auto Imp = importSeq( | |||
2535 | D->getBeginLoc(), D->getQualifierLoc(), D->getIntegerType())) | |||
2536 | std::tie(ToBeginLoc, ToQualifierLoc, ToIntegerType) = *Imp; | |||
2537 | else | |||
2538 | return Imp.takeError(); | |||
2539 | ||||
2540 | // Create the enum declaration. | |||
2541 | EnumDecl *D2; | |||
2542 | if (GetImportedOrCreateDecl( | |||
2543 | D2, D, Importer.getToContext(), DC, ToBeginLoc, | |||
2544 | Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(), | |||
2545 | D->isScopedUsingClassTag(), D->isFixed())) | |||
2546 | return D2; | |||
2547 | ||||
2548 | D2->setQualifierInfo(ToQualifierLoc); | |||
2549 | D2->setIntegerType(ToIntegerType); | |||
2550 | D2->setAccess(D->getAccess()); | |||
2551 | D2->setLexicalDeclContext(LexicalDC); | |||
2552 | LexicalDC->addDeclInternal(D2); | |||
2553 | ||||
2554 | // Import the definition | |||
2555 | if (D->isCompleteDefinition()) | |||
2556 | if (Error Err = ImportDefinition(D, D2)) | |||
2557 | return std::move(Err); | |||
2558 | ||||
2559 | return D2; | |||
2560 | } | |||
2561 | ||||
2562 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { | |||
2563 | bool IsFriendTemplate = false; | |||
2564 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | |||
| ||||
2565 | IsFriendTemplate = | |||
2566 | DCXX->getDescribedClassTemplate() && | |||
2567 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != | |||
2568 | Decl::FOK_None; | |||
2569 | } | |||
2570 | ||||
2571 | // If this record has a definition in the translation unit we're coming from, | |||
2572 | // but this particular declaration is not that definition, import the | |||
2573 | // definition and map to that. | |||
2574 | TagDecl *Definition = D->getDefinition(); | |||
2575 | if (Definition && Definition != D && | |||
2576 | // Friend template declaration must be imported on its own. | |||
2577 | !IsFriendTemplate && | |||
2578 | // In contrast to a normal CXXRecordDecl, the implicit | |||
2579 | // CXXRecordDecl of ClassTemplateSpecializationDecl is its redeclaration. | |||
2580 | // The definition of the implicit CXXRecordDecl in this case is the | |||
2581 | // ClassTemplateSpecializationDecl itself. Thus, we start with an extra | |||
2582 | // condition in order to be able to import the implict Decl. | |||
2583 | !D->isImplicit()) { | |||
2584 | ExpectedDecl ImportedDefOrErr = import(Definition); | |||
2585 | if (!ImportedDefOrErr) | |||
2586 | return ImportedDefOrErr.takeError(); | |||
2587 | ||||
2588 | return Importer.MapImported(D, *ImportedDefOrErr); | |||
2589 | } | |||
2590 | ||||
2591 | // Import the major distinguishing characteristics of this record. | |||
2592 | DeclContext *DC, *LexicalDC; | |||
2593 | DeclarationName Name; | |||
2594 | SourceLocation Loc; | |||
2595 | NamedDecl *ToD; | |||
2596 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
2597 | return std::move(Err); | |||
2598 | if (ToD) | |||
2599 | return ToD; | |||
2600 | ||||
2601 | // Figure out what structure name we're looking for. | |||
2602 | unsigned IDNS = Decl::IDNS_Tag; | |||
2603 | DeclarationName SearchName = Name; | |||
2604 | if (!SearchName && D->getTypedefNameForAnonDecl()) { | |||
2605 | if (Error Err = importInto( | |||
2606 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) | |||
2607 | return std::move(Err); | |||
2608 | IDNS = Decl::IDNS_Ordinary; | |||
2609 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) | |||
2610 | IDNS |= Decl::IDNS_Ordinary; | |||
2611 | ||||
2612 | // We may already have a record of the same name; try to find and match it. | |||
2613 | RecordDecl *AdoptDecl = nullptr; | |||
2614 | RecordDecl *PrevDecl = nullptr; | |||
2615 | if (!DC->isFunctionOrMethod()) { | |||
2616 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
2617 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
2618 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); | |||
2619 | ||||
2620 | if (!FoundDecls.empty()) { | |||
2621 | // We're going to have to compare D against potentially conflicting Decls, so complete it. | |||
2622 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) | |||
2623 | D->getASTContext().getExternalSource()->CompleteType(D); | |||
2624 | } | |||
2625 | ||||
2626 | for (auto *FoundDecl : FoundDecls) { | |||
2627 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
2628 | continue; | |||
2629 | ||||
2630 | Decl *Found = FoundDecl; | |||
2631 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { | |||
2632 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) | |||
2633 | Found = Tag->getDecl(); | |||
2634 | } | |||
2635 | ||||
2636 | if (D->getDescribedTemplate()) { | |||
2637 | if (auto *Template = dyn_cast<ClassTemplateDecl>(Found)) { | |||
2638 | Found = Template->getTemplatedDecl(); | |||
2639 | } else { | |||
2640 | ConflictingDecls.push_back(FoundDecl); | |||
2641 | continue; | |||
2642 | } | |||
2643 | } | |||
2644 | ||||
2645 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { | |||
2646 | if (!SearchName) { | |||
2647 | if (!IsStructuralMatch(D, FoundRecord, false)) | |||
2648 | continue; | |||
2649 | } else { | |||
2650 | if (!IsStructuralMatch(D, FoundRecord)) { | |||
2651 | ConflictingDecls.push_back(FoundDecl); | |||
2652 | continue; | |||
2653 | } | |||
2654 | } | |||
2655 | ||||
2656 | PrevDecl = FoundRecord; | |||
2657 | ||||
2658 | if (RecordDecl *FoundDef = FoundRecord->getDefinition()) { | |||
2659 | if ((SearchName && !D->isCompleteDefinition() && !IsFriendTemplate) | |||
2660 | || (D->isCompleteDefinition() && | |||
2661 | D->isAnonymousStructOrUnion() | |||
2662 | == FoundDef->isAnonymousStructOrUnion())) { | |||
2663 | // The record types structurally match, or the "from" translation | |||
2664 | // unit only had a forward declaration anyway; call it the same | |||
2665 | // function. | |||
2666 | // FIXME: Structural equivalence check should check for same | |||
2667 | // user-defined methods. | |||
2668 | Importer.MapImported(D, FoundDef); | |||
2669 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | |||
2670 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); | |||
2671 | assert(FoundCXX && "Record type mismatch")((FoundCXX && "Record type mismatch") ? static_cast< void> (0) : __assert_fail ("FoundCXX && \"Record type mismatch\"" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 2671, __PRETTY_FUNCTION__)); | |||
2672 | ||||
2673 | if (D->isCompleteDefinition() && !Importer.isMinimalImport()) | |||
2674 | // FoundDef may not have every implicit method that D has | |||
2675 | // because implicit methods are created only if they are used. | |||
2676 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) | |||
2677 | return std::move(Err); | |||
2678 | } | |||
2679 | return FoundDef; | |||
2680 | } | |||
2681 | if (IsFriendTemplate) | |||
2682 | continue; | |||
2683 | } else if (!D->isCompleteDefinition()) { | |||
2684 | // We have a forward declaration of this type, so adopt that forward | |||
2685 | // declaration rather than building a new one. | |||
2686 | ||||
2687 | // If one or both can be completed from external storage then try one | |||
2688 | // last time to complete and compare them before doing this. | |||
2689 | ||||
2690 | if (FoundRecord->hasExternalLexicalStorage() && | |||
2691 | !FoundRecord->isCompleteDefinition()) | |||
2692 | FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord); | |||
2693 | if (D->hasExternalLexicalStorage()) | |||
2694 | D->getASTContext().getExternalSource()->CompleteType(D); | |||
2695 | ||||
2696 | if (FoundRecord->isCompleteDefinition() && | |||
2697 | D->isCompleteDefinition() && | |||
2698 | !IsStructuralMatch(D, FoundRecord)) { | |||
2699 | ConflictingDecls.push_back(FoundDecl); | |||
2700 | continue; | |||
2701 | } | |||
2702 | ||||
2703 | AdoptDecl = FoundRecord; | |||
2704 | continue; | |||
2705 | } | |||
2706 | ||||
2707 | continue; | |||
2708 | } else if (isa<ValueDecl>(Found)) | |||
2709 | continue; | |||
2710 | ||||
2711 | ConflictingDecls.push_back(FoundDecl); | |||
2712 | } | |||
2713 | ||||
2714 | if (!ConflictingDecls.empty() && SearchName) { | |||
2715 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | |||
2716 | ConflictingDecls.data(), | |||
2717 | ConflictingDecls.size()); | |||
2718 | if (!Name) | |||
2719 | return make_error<ImportError>(ImportError::NameConflict); | |||
2720 | } | |||
2721 | } | |||
2722 | ||||
2723 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | |||
2724 | if (!BeginLocOrErr) | |||
2725 | return BeginLocOrErr.takeError(); | |||
2726 | ||||
2727 | // Create the record declaration. | |||
2728 | RecordDecl *D2 = AdoptDecl; | |||
2729 | if (!D2) { | |||
2730 | CXXRecordDecl *D2CXX = nullptr; | |||
2731 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | |||
2732 | if (DCXX->isLambda()) { | |||
2733 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); | |||
2734 | if (!TInfoOrErr) | |||
2735 | return TInfoOrErr.takeError(); | |||
2736 | if (GetImportedOrCreateSpecialDecl( | |||
2737 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), | |||
2738 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), | |||
2739 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) | |||
2740 | return D2CXX; | |||
2741 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); | |||
2742 | if (!CDeclOrErr) | |||
2743 | return CDeclOrErr.takeError(); | |||
2744 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr); | |||
2745 | } else if (DCXX->isInjectedClassName()) { | |||
2746 | // We have to be careful to do a similar dance to the one in | |||
2747 | // Sema::ActOnStartCXXMemberDeclarations | |||
2748 | CXXRecordDecl *const PrevDecl = nullptr; | |||
2749 | const bool DelayTypeCreation = true; | |||
2750 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), | |||
2751 | D->getTagKind(), DC, *BeginLocOrErr, Loc, | |||
2752 | Name.getAsIdentifierInfo(), PrevDecl, | |||
2753 | DelayTypeCreation)) | |||
2754 | return D2CXX; | |||
2755 | Importer.getToContext().getTypeDeclType( | |||
2756 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); | |||
2757 | } else { | |||
2758 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), | |||
2759 | D->getTagKind(), DC, *BeginLocOrErr, Loc, | |||
2760 | Name.getAsIdentifierInfo(), | |||
2761 | cast_or_null<CXXRecordDecl>(PrevDecl))) | |||
2762 | return D2CXX; | |||
2763 | } | |||
2764 | ||||
2765 | D2 = D2CXX; | |||
2766 | D2->setAccess(D->getAccess()); | |||
2767 | D2->setLexicalDeclContext(LexicalDC); | |||
2768 | if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit()) | |||
2769 | LexicalDC->addDeclInternal(D2); | |||
2770 | ||||
2771 | if (ClassTemplateDecl *FromDescribed = | |||
2772 | DCXX->getDescribedClassTemplate()) { | |||
2773 | ClassTemplateDecl *ToDescribed; | |||
2774 | if (Error Err = importInto(ToDescribed, FromDescribed)) | |||
2775 | return std::move(Err); | |||
2776 | D2CXX->setDescribedClassTemplate(ToDescribed); | |||
| ||||
2777 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { | |||
2778 | // In a record describing a template the type should be an | |||
2779 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the | |||
2780 | // previously set type to the correct value here (ToDescribed is not | |||
2781 | // available at record create). | |||
2782 | // FIXME: The previous type is cleared but not removed from | |||
2783 | // ASTContext's internal storage. | |||
2784 | CXXRecordDecl *Injected = nullptr; | |||
2785 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { | |||
2786 | auto *Record = dyn_cast<CXXRecordDecl>(Found); | |||
2787 | if (Record && Record->isInjectedClassName()) { | |||
2788 | Injected = Record; | |||
2789 | break; | |||
2790 | } | |||
2791 | } | |||
2792 | D2CXX->setTypeForDecl(nullptr); | |||
2793 | Importer.getToContext().getInjectedClassNameType(D2CXX, | |||
2794 | ToDescribed->getInjectedClassNameSpecialization()); | |||
2795 | if (Injected) { | |||
2796 | Injected->setTypeForDecl(nullptr); | |||
2797 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); | |||
2798 | } | |||
2799 | } | |||
2800 | } else if (MemberSpecializationInfo *MemberInfo = | |||
2801 | DCXX->getMemberSpecializationInfo()) { | |||
2802 | TemplateSpecializationKind SK = | |||
2803 | MemberInfo->getTemplateSpecializationKind(); | |||
2804 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); | |||
2805 | ||||
2806 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) | |||
2807 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); | |||
2808 | else | |||
2809 | return ToInstOrErr.takeError(); | |||
2810 | ||||
2811 | if (ExpectedSLoc POIOrErr = | |||
2812 | import(MemberInfo->getPointOfInstantiation())) | |||
2813 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( | |||
2814 | *POIOrErr); | |||
2815 | else | |||
2816 | return POIOrErr.takeError(); | |||
2817 | } | |||
2818 | ||||
2819 | } else { | |||
2820 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), | |||
2821 | D->getTagKind(), DC, *BeginLocOrErr, Loc, | |||
2822 | Name.getAsIdentifierInfo(), PrevDecl)) | |||
2823 | return D2; | |||
2824 | D2->setLexicalDeclContext(LexicalDC); | |||
2825 | LexicalDC->addDeclInternal(D2); | |||
2826 | } | |||
2827 | ||||
2828 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) | |||
2829 | D2->setQualifierInfo(*QualifierLocOrErr); | |||
2830 | else | |||
2831 | return QualifierLocOrErr.takeError(); | |||
2832 | ||||
2833 | if (D->isAnonymousStructOrUnion()) | |||
2834 | D2->setAnonymousStructOrUnion(true); | |||
2835 | } | |||
2836 | ||||
2837 | Importer.MapImported(D, D2); | |||
2838 | ||||
2839 | if (D->isCompleteDefinition()) | |||
2840 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) | |||
2841 | return std::move(Err); | |||
2842 | ||||
2843 | return D2; | |||
2844 | } | |||
2845 | ||||
2846 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { | |||
2847 | // Import the major distinguishing characteristics of this enumerator. | |||
2848 | DeclContext *DC, *LexicalDC; | |||
2849 | DeclarationName Name; | |||
2850 | SourceLocation Loc; | |||
2851 | NamedDecl *ToD; | |||
2852 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
2853 | return std::move(Err); | |||
2854 | if (ToD) | |||
2855 | return ToD; | |||
2856 | ||||
2857 | // Determine whether there are any other declarations with the same name and | |||
2858 | // in the same context. | |||
2859 | if (!LexicalDC->isFunctionOrMethod()) { | |||
2860 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
2861 | unsigned IDNS = Decl::IDNS_Ordinary; | |||
2862 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
2863 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
2864 | for (auto *FoundDecl : FoundDecls) { | |||
2865 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
2866 | continue; | |||
2867 | ||||
2868 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { | |||
2869 | if (IsStructuralMatch(D, FoundEnumConstant)) | |||
2870 | return Importer.MapImported(D, FoundEnumConstant); | |||
2871 | } | |||
2872 | ||||
2873 | ConflictingDecls.push_back(FoundDecl); | |||
2874 | } | |||
2875 | ||||
2876 | if (!ConflictingDecls.empty()) { | |||
2877 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | |||
2878 | ConflictingDecls.data(), | |||
2879 | ConflictingDecls.size()); | |||
2880 | if (!Name) | |||
2881 | return make_error<ImportError>(ImportError::NameConflict); | |||
2882 | } | |||
2883 | } | |||
2884 | ||||
2885 | ExpectedType TypeOrErr = import(D->getType()); | |||
2886 | if (!TypeOrErr) | |||
2887 | return TypeOrErr.takeError(); | |||
2888 | ||||
2889 | ExpectedExpr InitOrErr = import(D->getInitExpr()); | |||
2890 | if (!InitOrErr) | |||
2891 | return InitOrErr.takeError(); | |||
2892 | ||||
2893 | EnumConstantDecl *ToEnumerator; | |||
2894 | if (GetImportedOrCreateDecl( | |||
2895 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, | |||
2896 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) | |||
2897 | return ToEnumerator; | |||
2898 | ||||
2899 | ToEnumerator->setAccess(D->getAccess()); | |||
2900 | ToEnumerator->setLexicalDeclContext(LexicalDC); | |||
2901 | LexicalDC->addDeclInternal(ToEnumerator); | |||
2902 | return ToEnumerator; | |||
2903 | } | |||
2904 | ||||
2905 | Error ASTNodeImporter::ImportTemplateInformation( | |||
2906 | FunctionDecl *FromFD, FunctionDecl *ToFD) { | |||
2907 | switch (FromFD->getTemplatedKind()) { | |||
2908 | case FunctionDecl::TK_NonTemplate: | |||
2909 | case FunctionDecl::TK_FunctionTemplate: | |||
2910 | return Error::success(); | |||
2911 | ||||
2912 | case FunctionDecl::TK_MemberSpecialization: { | |||
2913 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); | |||
2914 | ||||
2915 | if (Expected<FunctionDecl *> InstFDOrErr = | |||
2916 | import(FromFD->getInstantiatedFromMemberFunction())) | |||
2917 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); | |||
2918 | else | |||
2919 | return InstFDOrErr.takeError(); | |||
2920 | ||||
2921 | if (ExpectedSLoc POIOrErr = import( | |||
2922 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) | |||
2923 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); | |||
2924 | else | |||
2925 | return POIOrErr.takeError(); | |||
2926 | ||||
2927 | return Error::success(); | |||
2928 | } | |||
2929 | ||||
2930 | case FunctionDecl::TK_FunctionTemplateSpecialization: { | |||
2931 | auto FunctionAndArgsOrErr = | |||
2932 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); | |||
2933 | if (!FunctionAndArgsOrErr) | |||
2934 | return FunctionAndArgsOrErr.takeError(); | |||
2935 | ||||
2936 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( | |||
2937 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); | |||
2938 | ||||
2939 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); | |||
2940 | TemplateArgumentListInfo ToTAInfo; | |||
2941 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; | |||
2942 | if (FromTAArgsAsWritten) | |||
2943 | if (Error Err = ImportTemplateArgumentListInfo( | |||
2944 | *FromTAArgsAsWritten, ToTAInfo)) | |||
2945 | return Err; | |||
2946 | ||||
2947 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); | |||
2948 | if (!POIOrErr) | |||
2949 | return POIOrErr.takeError(); | |||
2950 | ||||
2951 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); | |||
2952 | ToFD->setFunctionTemplateSpecialization( | |||
2953 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, | |||
2954 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); | |||
2955 | return Error::success(); | |||
2956 | } | |||
2957 | ||||
2958 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { | |||
2959 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); | |||
2960 | UnresolvedSet<8> TemplDecls; | |||
2961 | unsigned NumTemplates = FromInfo->getNumTemplates(); | |||
2962 | for (unsigned I = 0; I < NumTemplates; I++) { | |||
2963 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = | |||
2964 | import(FromInfo->getTemplate(I))) | |||
2965 | TemplDecls.addDecl(*ToFTDOrErr); | |||
2966 | else | |||
2967 | return ToFTDOrErr.takeError(); | |||
2968 | } | |||
2969 | ||||
2970 | // Import TemplateArgumentListInfo. | |||
2971 | TemplateArgumentListInfo ToTAInfo; | |||
2972 | if (Error Err = ImportTemplateArgumentListInfo( | |||
2973 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), | |||
2974 | llvm::makeArrayRef( | |||
2975 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), | |||
2976 | ToTAInfo)) | |||
2977 | return Err; | |||
2978 | ||||
2979 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), | |||
2980 | TemplDecls, ToTAInfo); | |||
2981 | return Error::success(); | |||
2982 | } | |||
2983 | } | |||
2984 | llvm_unreachable("All cases should be covered!")::llvm::llvm_unreachable_internal("All cases should be covered!" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 2984); | |||
2985 | } | |||
2986 | ||||
2987 | Expected<FunctionDecl *> | |||
2988 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { | |||
2989 | auto FunctionAndArgsOrErr = | |||
2990 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); | |||
2991 | if (!FunctionAndArgsOrErr) | |||
2992 | return FunctionAndArgsOrErr.takeError(); | |||
2993 | ||||
2994 | FunctionTemplateDecl *Template; | |||
2995 | TemplateArgsTy ToTemplArgs; | |||
2996 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; | |||
2997 | void *InsertPos = nullptr; | |||
2998 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); | |||
2999 | return FoundSpec; | |||
3000 | } | |||
3001 | ||||
3002 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { | |||
3003 | ||||
3004 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); | |||
3005 | auto RedeclIt = Redecls.begin(); | |||
3006 | // Import the first part of the decl chain. I.e. import all previous | |||
3007 | // declarations starting from the canonical decl. | |||
3008 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { | |||
3009 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); | |||
3010 | if (!ToRedeclOrErr) | |||
3011 | return ToRedeclOrErr.takeError(); | |||
3012 | } | |||
3013 | assert(*RedeclIt == D)((*RedeclIt == D) ? static_cast<void> (0) : __assert_fail ("*RedeclIt == D", "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 3013, __PRETTY_FUNCTION__)); | |||
3014 | ||||
3015 | // Import the major distinguishing characteristics of this function. | |||
3016 | DeclContext *DC, *LexicalDC; | |||
3017 | DeclarationName Name; | |||
3018 | SourceLocation Loc; | |||
3019 | NamedDecl *ToD; | |||
3020 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3021 | return std::move(Err); | |||
3022 | if (ToD) | |||
3023 | return ToD; | |||
3024 | ||||
3025 | const FunctionDecl *FoundByLookup = nullptr; | |||
3026 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); | |||
3027 | ||||
3028 | // If this is a function template specialization, then try to find the same | |||
3029 | // existing specialization in the "to" context. The localUncachedLookup | |||
3030 | // below will not find any specialization, but would find the primary | |||
3031 | // template; thus, we have to skip normal lookup in case of specializations. | |||
3032 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? | |||
3033 | if (D->getTemplatedKind() == | |||
3034 | FunctionDecl::TK_FunctionTemplateSpecialization) { | |||
3035 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); | |||
3036 | if (!FoundFunctionOrErr) | |||
3037 | return FoundFunctionOrErr.takeError(); | |||
3038 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { | |||
3039 | if (D->doesThisDeclarationHaveABody() && FoundFunction->hasBody()) | |||
3040 | return Importer.MapImported(D, FoundFunction); | |||
3041 | FoundByLookup = FoundFunction; | |||
3042 | } | |||
3043 | } | |||
3044 | // Try to find a function in our own ("to") context with the same name, same | |||
3045 | // type, and in the same context as the function we're importing. | |||
3046 | else if (!LexicalDC->isFunctionOrMethod()) { | |||
3047 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
3048 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; | |||
3049 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
3050 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
3051 | for (auto *FoundDecl : FoundDecls) { | |||
3052 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
3053 | continue; | |||
3054 | ||||
3055 | // If template was found, look at the templated function. | |||
3056 | if (FromFT) { | |||
3057 | if (auto *Template = dyn_cast<FunctionTemplateDecl>(FoundDecl)) | |||
3058 | FoundDecl = Template->getTemplatedDecl(); | |||
3059 | else | |||
3060 | continue; | |||
3061 | } | |||
3062 | ||||
3063 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { | |||
3064 | if (FoundFunction->hasExternalFormalLinkage() && | |||
3065 | D->hasExternalFormalLinkage()) { | |||
3066 | if (IsStructuralMatch(D, FoundFunction)) { | |||
3067 | const FunctionDecl *Definition = nullptr; | |||
3068 | if (D->doesThisDeclarationHaveABody() && | |||
3069 | FoundFunction->hasBody(Definition)) { | |||
3070 | return Importer.MapImported( | |||
3071 | D, const_cast<FunctionDecl *>(Definition)); | |||
3072 | } | |||
3073 | FoundByLookup = FoundFunction; | |||
3074 | break; | |||
3075 | } | |||
3076 | ||||
3077 | // FIXME: Check for overloading more carefully, e.g., by boosting | |||
3078 | // Sema::IsOverload out to the AST library. | |||
3079 | ||||
3080 | // Function overloading is okay in C++. | |||
3081 | if (Importer.getToContext().getLangOpts().CPlusPlus) | |||
3082 | continue; | |||
3083 | ||||
3084 | // Complain about inconsistent function types. | |||
3085 | Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent) | |||
3086 | << Name << D->getType() << FoundFunction->getType(); | |||
3087 | Importer.ToDiag(FoundFunction->getLocation(), | |||
3088 | diag::note_odr_value_here) | |||
3089 | << FoundFunction->getType(); | |||
3090 | } | |||
3091 | } | |||
3092 | ||||
3093 | ConflictingDecls.push_back(FoundDecl); | |||
3094 | } | |||
3095 | ||||
3096 | if (!ConflictingDecls.empty()) { | |||
3097 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | |||
3098 | ConflictingDecls.data(), | |||
3099 | ConflictingDecls.size()); | |||
3100 | if (!Name) | |||
3101 | return make_error<ImportError>(ImportError::NameConflict); | |||
3102 | } | |||
3103 | } | |||
3104 | ||||
3105 | DeclarationNameInfo NameInfo(Name, Loc); | |||
3106 | // Import additional name location/type info. | |||
3107 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | |||
3108 | return std::move(Err); | |||
3109 | ||||
3110 | QualType FromTy = D->getType(); | |||
3111 | bool usedDifferentExceptionSpec = false; | |||
3112 | ||||
3113 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { | |||
3114 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); | |||
3115 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the | |||
3116 | // FunctionDecl that we are importing the FunctionProtoType for. | |||
3117 | // To avoid an infinite recursion when importing, create the FunctionDecl | |||
3118 | // with a simplified function type and update it afterwards. | |||
3119 | if (FromEPI.ExceptionSpec.SourceDecl || | |||
3120 | FromEPI.ExceptionSpec.SourceTemplate || | |||
3121 | FromEPI.ExceptionSpec.NoexceptExpr) { | |||
3122 | FunctionProtoType::ExtProtoInfo DefaultEPI; | |||
3123 | FromTy = Importer.getFromContext().getFunctionType( | |||
3124 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); | |||
3125 | usedDifferentExceptionSpec = true; | |||
3126 | } | |||
3127 | } | |||
3128 | ||||
3129 | QualType T; | |||
3130 | TypeSourceInfo *TInfo; | |||
3131 | SourceLocation ToInnerLocStart, ToEndLoc; | |||
3132 | NestedNameSpecifierLoc ToQualifierLoc; | |||
3133 | if (auto Imp = importSeq( | |||
3134 | FromTy, D->getTypeSourceInfo(), D->getInnerLocStart(), | |||
3135 | D->getQualifierLoc(), D->getEndLoc())) | |||
3136 | std::tie(T, TInfo, ToInnerLocStart, ToQualifierLoc, ToEndLoc) = *Imp; | |||
3137 | else | |||
3138 | return Imp.takeError(); | |||
3139 | ||||
3140 | // Import the function parameters. | |||
3141 | SmallVector<ParmVarDecl *, 8> Parameters; | |||
3142 | for (auto P : D->parameters()) { | |||
3143 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) | |||
3144 | Parameters.push_back(*ToPOrErr); | |||
3145 | else | |||
3146 | return ToPOrErr.takeError(); | |||
3147 | } | |||
3148 | ||||
3149 | // Create the imported function. | |||
3150 | FunctionDecl *ToFunction = nullptr; | |||
3151 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { | |||
3152 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( | |||
3153 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | |||
3154 | ToInnerLocStart, NameInfo, T, TInfo, | |||
3155 | FromConstructor->isExplicit(), | |||
3156 | D->isInlineSpecified(), D->isImplicit(), D->isConstexpr())) | |||
3157 | return ToFunction; | |||
3158 | } else if (isa<CXXDestructorDecl>(D)) { | |||
3159 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( | |||
3160 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | |||
3161 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), | |||
3162 | D->isImplicit())) | |||
3163 | return ToFunction; | |||
3164 | } else if (CXXConversionDecl *FromConversion = | |||
3165 | dyn_cast<CXXConversionDecl>(D)) { | |||
3166 | if (GetImportedOrCreateDecl<CXXConversionDecl>( | |||
3167 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | |||
3168 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), | |||
3169 | FromConversion->isExplicit(), D->isConstexpr(), SourceLocation())) | |||
3170 | return ToFunction; | |||
3171 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { | |||
3172 | if (GetImportedOrCreateDecl<CXXMethodDecl>( | |||
3173 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | |||
3174 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), | |||
3175 | Method->isInlineSpecified(), D->isConstexpr(), SourceLocation())) | |||
3176 | return ToFunction; | |||
3177 | } else { | |||
3178 | if (GetImportedOrCreateDecl(ToFunction, D, Importer.getToContext(), DC, | |||
3179 | ToInnerLocStart, NameInfo, T, TInfo, | |||
3180 | D->getStorageClass(), D->isInlineSpecified(), | |||
3181 | D->hasWrittenPrototype(), D->isConstexpr())) | |||
3182 | return ToFunction; | |||
3183 | } | |||
3184 | ||||
3185 | // Connect the redecl chain. | |||
3186 | if (FoundByLookup) { | |||
3187 | auto *Recent = const_cast<FunctionDecl *>( | |||
3188 | FoundByLookup->getMostRecentDecl()); | |||
3189 | ToFunction->setPreviousDecl(Recent); | |||
3190 | } | |||
3191 | ||||
3192 | // Import Ctor initializers. | |||
3193 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { | |||
3194 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { | |||
3195 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); | |||
3196 | // Import first, then allocate memory and copy if there was no error. | |||
3197 | if (Error Err = ImportContainerChecked( | |||
3198 | FromConstructor->inits(), CtorInitializers)) | |||
3199 | return std::move(Err); | |||
3200 | auto **Memory = | |||
3201 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; | |||
3202 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); | |||
3203 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); | |||
3204 | ToCtor->setCtorInitializers(Memory); | |||
3205 | ToCtor->setNumCtorInitializers(NumInitializers); | |||
3206 | } | |||
3207 | } | |||
3208 | ||||
3209 | ToFunction->setQualifierInfo(ToQualifierLoc); | |||
3210 | ToFunction->setAccess(D->getAccess()); | |||
3211 | ToFunction->setLexicalDeclContext(LexicalDC); | |||
3212 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); | |||
3213 | ToFunction->setTrivial(D->isTrivial()); | |||
3214 | ToFunction->setPure(D->isPure()); | |||
3215 | ToFunction->setRangeEnd(ToEndLoc); | |||
3216 | ||||
3217 | // Set the parameters. | |||
3218 | for (auto *Param : Parameters) { | |||
3219 | Param->setOwningFunction(ToFunction); | |||
3220 | ToFunction->addDeclInternal(Param); | |||
3221 | } | |||
3222 | ToFunction->setParams(Parameters); | |||
3223 | ||||
3224 | // We need to complete creation of FunctionProtoTypeLoc manually with setting | |||
3225 | // params it refers to. | |||
3226 | if (TInfo) { | |||
3227 | if (auto ProtoLoc = | |||
3228 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { | |||
3229 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) | |||
3230 | ProtoLoc.setParam(I, Parameters[I]); | |||
3231 | } | |||
3232 | } | |||
3233 | ||||
3234 | if (usedDifferentExceptionSpec) { | |||
3235 | // Update FunctionProtoType::ExtProtoInfo. | |||
3236 | if (ExpectedType TyOrErr = import(D->getType())) | |||
3237 | ToFunction->setType(*TyOrErr); | |||
3238 | else | |||
3239 | return TyOrErr.takeError(); | |||
3240 | } | |||
3241 | ||||
3242 | // Import the describing template function, if any. | |||
3243 | if (FromFT) { | |||
3244 | auto ToFTOrErr = import(FromFT); | |||
3245 | if (!ToFTOrErr) | |||
3246 | return ToFTOrErr.takeError(); | |||
3247 | } | |||
3248 | ||||
3249 | if (D->doesThisDeclarationHaveABody()) { | |||
3250 | if (Stmt *FromBody = D->getBody()) { | |||
3251 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) | |||
3252 | ToFunction->setBody(*ToBodyOrErr); | |||
3253 | else | |||
3254 | return ToBodyOrErr.takeError(); | |||
3255 | } | |||
3256 | } | |||
3257 | ||||
3258 | // FIXME: Other bits to merge? | |||
3259 | ||||
3260 | // If it is a template, import all related things. | |||
3261 | if (Error Err = ImportTemplateInformation(D, ToFunction)) | |||
3262 | return std::move(Err); | |||
3263 | ||||
3264 | bool IsFriend = D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend); | |||
3265 | ||||
3266 | // TODO Can we generalize this approach to other AST nodes as well? | |||
3267 | if (D->getDeclContext()->containsDeclAndLoad(D)) | |||
3268 | DC->addDeclInternal(ToFunction); | |||
3269 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) | |||
3270 | LexicalDC->addDeclInternal(ToFunction); | |||
3271 | ||||
3272 | // Friend declaration's lexical context is the befriending class, but the | |||
3273 | // semantic context is the enclosing scope of the befriending class. | |||
3274 | // We want the friend functions to be found in the semantic context by lookup. | |||
3275 | // FIXME should we handle this generically in VisitFriendDecl? | |||
3276 | // In Other cases when LexicalDC != DC we don't want it to be added, | |||
3277 | // e.g out-of-class definitions like void B::f() {} . | |||
3278 | if (LexicalDC != DC && IsFriend) { | |||
3279 | DC->makeDeclVisibleInContext(ToFunction); | |||
3280 | } | |||
3281 | ||||
3282 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) | |||
3283 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); | |||
3284 | ||||
3285 | // Import the rest of the chain. I.e. import all subsequent declarations. | |||
3286 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { | |||
3287 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); | |||
3288 | if (!ToRedeclOrErr) | |||
3289 | return ToRedeclOrErr.takeError(); | |||
3290 | } | |||
3291 | ||||
3292 | return ToFunction; | |||
3293 | } | |||
3294 | ||||
3295 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { | |||
3296 | return VisitFunctionDecl(D); | |||
3297 | } | |||
3298 | ||||
3299 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { | |||
3300 | return VisitCXXMethodDecl(D); | |||
3301 | } | |||
3302 | ||||
3303 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { | |||
3304 | return VisitCXXMethodDecl(D); | |||
3305 | } | |||
3306 | ||||
3307 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { | |||
3308 | return VisitCXXMethodDecl(D); | |||
3309 | } | |||
3310 | ||||
3311 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { | |||
3312 | // Import the major distinguishing characteristics of a variable. | |||
3313 | DeclContext *DC, *LexicalDC; | |||
3314 | DeclarationName Name; | |||
3315 | SourceLocation Loc; | |||
3316 | NamedDecl *ToD; | |||
3317 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3318 | return std::move(Err); | |||
3319 | if (ToD) | |||
3320 | return ToD; | |||
3321 | ||||
3322 | // Determine whether we've already imported this field. | |||
3323 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
3324 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
3325 | for (auto *FoundDecl : FoundDecls) { | |||
3326 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { | |||
3327 | // For anonymous fields, match up by index. | |||
3328 | if (!Name && | |||
3329 | ASTImporter::getFieldIndex(D) != | |||
3330 | ASTImporter::getFieldIndex(FoundField)) | |||
3331 | continue; | |||
3332 | ||||
3333 | if (Importer.IsStructurallyEquivalent(D->getType(), | |||
3334 | FoundField->getType())) { | |||
3335 | Importer.MapImported(D, FoundField); | |||
3336 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the | |||
3337 | // initializer of a FieldDecl might not had been instantiated in the | |||
3338 | // "To" context. However, the "From" context might instantiated that, | |||
3339 | // thus we have to merge that. | |||
3340 | if (Expr *FromInitializer = D->getInClassInitializer()) { | |||
3341 | // We don't have yet the initializer set. | |||
3342 | if (FoundField->hasInClassInitializer() && | |||
3343 | !FoundField->getInClassInitializer()) { | |||
3344 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) | |||
3345 | FoundField->setInClassInitializer(*ToInitializerOrErr); | |||
3346 | else { | |||
3347 | // We can't return error here, | |||
3348 | // since we already mapped D as imported. | |||
3349 | // FIXME: warning message? | |||
3350 | consumeError(ToInitializerOrErr.takeError()); | |||
3351 | return FoundField; | |||
3352 | } | |||
3353 | } | |||
3354 | } | |||
3355 | return FoundField; | |||
3356 | } | |||
3357 | ||||
3358 | // FIXME: Why is this case not handled with calling HandleNameConflict? | |||
3359 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) | |||
3360 | << Name << D->getType() << FoundField->getType(); | |||
3361 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) | |||
3362 | << FoundField->getType(); | |||
3363 | ||||
3364 | return make_error<ImportError>(ImportError::NameConflict); | |||
3365 | } | |||
3366 | } | |||
3367 | ||||
3368 | QualType ToType; | |||
3369 | TypeSourceInfo *ToTInfo; | |||
3370 | Expr *ToBitWidth; | |||
3371 | SourceLocation ToInnerLocStart; | |||
3372 | Expr *ToInitializer; | |||
3373 | if (auto Imp = importSeq( | |||
3374 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), | |||
3375 | D->getInnerLocStart(), D->getInClassInitializer())) | |||
3376 | std::tie( | |||
3377 | ToType, ToTInfo, ToBitWidth, ToInnerLocStart, ToInitializer) = *Imp; | |||
3378 | else | |||
3379 | return Imp.takeError(); | |||
3380 | ||||
3381 | FieldDecl *ToField; | |||
3382 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, | |||
3383 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), | |||
3384 | ToType, ToTInfo, ToBitWidth, D->isMutable(), | |||
3385 | D->getInClassInitStyle())) | |||
3386 | return ToField; | |||
3387 | ||||
3388 | ToField->setAccess(D->getAccess()); | |||
3389 | ToField->setLexicalDeclContext(LexicalDC); | |||
3390 | if (ToInitializer) | |||
3391 | ToField->setInClassInitializer(ToInitializer); | |||
3392 | ToField->setImplicit(D->isImplicit()); | |||
3393 | LexicalDC->addDeclInternal(ToField); | |||
3394 | return ToField; | |||
3395 | } | |||
3396 | ||||
3397 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { | |||
3398 | // Import the major distinguishing characteristics of a variable. | |||
3399 | DeclContext *DC, *LexicalDC; | |||
3400 | DeclarationName Name; | |||
3401 | SourceLocation Loc; | |||
3402 | NamedDecl *ToD; | |||
3403 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3404 | return std::move(Err); | |||
3405 | if (ToD) | |||
3406 | return ToD; | |||
3407 | ||||
3408 | // Determine whether we've already imported this field. | |||
3409 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
3410 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
3411 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | |||
3412 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { | |||
3413 | // For anonymous indirect fields, match up by index. | |||
3414 | if (!Name && | |||
3415 | ASTImporter::getFieldIndex(D) != | |||
3416 | ASTImporter::getFieldIndex(FoundField)) | |||
3417 | continue; | |||
3418 | ||||
3419 | if (Importer.IsStructurallyEquivalent(D->getType(), | |||
3420 | FoundField->getType(), | |||
3421 | !Name.isEmpty())) { | |||
3422 | Importer.MapImported(D, FoundField); | |||
3423 | return FoundField; | |||
3424 | } | |||
3425 | ||||
3426 | // If there are more anonymous fields to check, continue. | |||
3427 | if (!Name && I < N-1) | |||
3428 | continue; | |||
3429 | ||||
3430 | // FIXME: Why is this case not handled with calling HandleNameConflict? | |||
3431 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) | |||
3432 | << Name << D->getType() << FoundField->getType(); | |||
3433 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) | |||
3434 | << FoundField->getType(); | |||
3435 | ||||
3436 | return make_error<ImportError>(ImportError::NameConflict); | |||
3437 | } | |||
3438 | } | |||
3439 | ||||
3440 | // Import the type. | |||
3441 | auto TypeOrErr = import(D->getType()); | |||
3442 | if (!TypeOrErr) | |||
3443 | return TypeOrErr.takeError(); | |||
3444 | ||||
3445 | auto **NamedChain = | |||
3446 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; | |||
3447 | ||||
3448 | unsigned i = 0; | |||
3449 | for (auto *PI : D->chain()) | |||
3450 | if (Expected<NamedDecl *> ToD = import(PI)) | |||
3451 | NamedChain[i++] = *ToD; | |||
3452 | else | |||
3453 | return ToD.takeError(); | |||
3454 | ||||
3455 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; | |||
3456 | IndirectFieldDecl *ToIndirectField; | |||
3457 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, | |||
3458 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) | |||
3459 | // FIXME here we leak `NamedChain` which is allocated before | |||
3460 | return ToIndirectField; | |||
3461 | ||||
3462 | for (const auto *Attr : D->attrs()) | |||
3463 | ToIndirectField->addAttr(Importer.Import(Attr)); | |||
3464 | ||||
3465 | ToIndirectField->setAccess(D->getAccess()); | |||
3466 | ToIndirectField->setLexicalDeclContext(LexicalDC); | |||
3467 | LexicalDC->addDeclInternal(ToIndirectField); | |||
3468 | return ToIndirectField; | |||
3469 | } | |||
3470 | ||||
3471 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { | |||
3472 | // Import the major distinguishing characteristics of a declaration. | |||
3473 | DeclContext *DC, *LexicalDC; | |||
3474 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
3475 | return std::move(Err); | |||
3476 | ||||
3477 | // Determine whether we've already imported this decl. | |||
3478 | // FriendDecl is not a NamedDecl so we cannot use localUncachedLookup. | |||
3479 | auto *RD = cast<CXXRecordDecl>(DC); | |||
3480 | FriendDecl *ImportedFriend = RD->getFirstFriend(); | |||
3481 | ||||
3482 | while (ImportedFriend) { | |||
3483 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { | |||
3484 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), | |||
3485 | /*Complain=*/false)) | |||
3486 | return Importer.MapImported(D, ImportedFriend); | |||
3487 | ||||
3488 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { | |||
3489 | if (Importer.IsStructurallyEquivalent( | |||
3490 | D->getFriendType()->getType(), | |||
3491 | ImportedFriend->getFriendType()->getType(), true)) | |||
3492 | return Importer.MapImported(D, ImportedFriend); | |||
3493 | } | |||
3494 | ImportedFriend = ImportedFriend->getNextFriend(); | |||
3495 | } | |||
3496 | ||||
3497 | // Not found. Create it. | |||
3498 | FriendDecl::FriendUnion ToFU; | |||
3499 | if (NamedDecl *FriendD = D->getFriendDecl()) { | |||
3500 | NamedDecl *ToFriendD; | |||
3501 | if (Error Err = importInto(ToFriendD, FriendD)) | |||
3502 | return std::move(Err); | |||
3503 | ||||
3504 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && | |||
3505 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) | |||
3506 | ToFriendD->setObjectOfFriendDecl(false); | |||
3507 | ||||
3508 | ToFU = ToFriendD; | |||
3509 | } else { // The friend is a type, not a decl. | |||
3510 | if (auto TSIOrErr = import(D->getFriendType())) | |||
3511 | ToFU = *TSIOrErr; | |||
3512 | else | |||
3513 | return TSIOrErr.takeError(); | |||
3514 | } | |||
3515 | ||||
3516 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); | |||
3517 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); | |||
3518 | for (unsigned I = 0; I < D->NumTPLists; I++) { | |||
3519 | if (auto ListOrErr = ImportTemplateParameterList(FromTPLists[I])) | |||
3520 | ToTPLists[I] = *ListOrErr; | |||
3521 | else | |||
3522 | return ListOrErr.takeError(); | |||
3523 | } | |||
3524 | ||||
3525 | auto LocationOrErr = import(D->getLocation()); | |||
3526 | if (!LocationOrErr) | |||
3527 | return LocationOrErr.takeError(); | |||
3528 | auto FriendLocOrErr = import(D->getFriendLoc()); | |||
3529 | if (!FriendLocOrErr) | |||
3530 | return FriendLocOrErr.takeError(); | |||
3531 | ||||
3532 | FriendDecl *FrD; | |||
3533 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, | |||
3534 | *LocationOrErr, ToFU, | |||
3535 | *FriendLocOrErr, ToTPLists)) | |||
3536 | return FrD; | |||
3537 | ||||
3538 | FrD->setAccess(D->getAccess()); | |||
3539 | FrD->setLexicalDeclContext(LexicalDC); | |||
3540 | LexicalDC->addDeclInternal(FrD); | |||
3541 | return FrD; | |||
3542 | } | |||
3543 | ||||
3544 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { | |||
3545 | // Import the major distinguishing characteristics of an ivar. | |||
3546 | DeclContext *DC, *LexicalDC; | |||
3547 | DeclarationName Name; | |||
3548 | SourceLocation Loc; | |||
3549 | NamedDecl *ToD; | |||
3550 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3551 | return std::move(Err); | |||
3552 | if (ToD) | |||
3553 | return ToD; | |||
3554 | ||||
3555 | // Determine whether we've already imported this ivar | |||
3556 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
3557 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
3558 | for (auto *FoundDecl : FoundDecls) { | |||
3559 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { | |||
3560 | if (Importer.IsStructurallyEquivalent(D->getType(), | |||
3561 | FoundIvar->getType())) { | |||
3562 | Importer.MapImported(D, FoundIvar); | |||
3563 | return FoundIvar; | |||
3564 | } | |||
3565 | ||||
3566 | Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent) | |||
3567 | << Name << D->getType() << FoundIvar->getType(); | |||
3568 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) | |||
3569 | << FoundIvar->getType(); | |||
3570 | ||||
3571 | return make_error<ImportError>(ImportError::NameConflict); | |||
3572 | } | |||
3573 | } | |||
3574 | ||||
3575 | QualType ToType; | |||
3576 | TypeSourceInfo *ToTypeSourceInfo; | |||
3577 | Expr *ToBitWidth; | |||
3578 | SourceLocation ToInnerLocStart; | |||
3579 | if (auto Imp = importSeq( | |||
3580 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), D->getInnerLocStart())) | |||
3581 | std::tie(ToType, ToTypeSourceInfo, ToBitWidth, ToInnerLocStart) = *Imp; | |||
3582 | else | |||
3583 | return Imp.takeError(); | |||
3584 | ||||
3585 | ObjCIvarDecl *ToIvar; | |||
3586 | if (GetImportedOrCreateDecl( | |||
3587 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), | |||
3588 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), | |||
3589 | ToType, ToTypeSourceInfo, | |||
3590 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) | |||
3591 | return ToIvar; | |||
3592 | ||||
3593 | ToIvar->setLexicalDeclContext(LexicalDC); | |||
3594 | LexicalDC->addDeclInternal(ToIvar); | |||
3595 | return ToIvar; | |||
3596 | } | |||
3597 | ||||
3598 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { | |||
3599 | ||||
3600 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); | |||
3601 | auto RedeclIt = Redecls.begin(); | |||
3602 | // Import the first part of the decl chain. I.e. import all previous | |||
3603 | // declarations starting from the canonical decl. | |||
3604 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { | |||
3605 | ExpectedDecl RedeclOrErr = import(*RedeclIt); | |||
3606 | if (!RedeclOrErr) | |||
3607 | return RedeclOrErr.takeError(); | |||
3608 | } | |||
3609 | assert(*RedeclIt == D)((*RedeclIt == D) ? static_cast<void> (0) : __assert_fail ("*RedeclIt == D", "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 3609, __PRETTY_FUNCTION__)); | |||
3610 | ||||
3611 | // Import the major distinguishing characteristics of a variable. | |||
3612 | DeclContext *DC, *LexicalDC; | |||
3613 | DeclarationName Name; | |||
3614 | SourceLocation Loc; | |||
3615 | NamedDecl *ToD; | |||
3616 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3617 | return std::move(Err); | |||
3618 | if (ToD) | |||
3619 | return ToD; | |||
3620 | ||||
3621 | // Try to find a variable in our own ("to") context with the same name and | |||
3622 | // in the same context as the variable we're importing. | |||
3623 | VarDecl *FoundByLookup = nullptr; | |||
3624 | if (D->isFileVarDecl()) { | |||
3625 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
3626 | unsigned IDNS = Decl::IDNS_Ordinary; | |||
3627 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
3628 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
3629 | for (auto *FoundDecl : FoundDecls) { | |||
3630 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
3631 | continue; | |||
3632 | ||||
3633 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { | |||
3634 | // We have found a variable that we may need to merge with. Check it. | |||
3635 | if (FoundVar->hasExternalFormalLinkage() && | |||
3636 | D->hasExternalFormalLinkage()) { | |||
3637 | if (Importer.IsStructurallyEquivalent(D->getType(), | |||
3638 | FoundVar->getType())) { | |||
3639 | ||||
3640 | // The VarDecl in the "From" context has a definition, but in the | |||
3641 | // "To" context we already have a definition. | |||
3642 | VarDecl *FoundDef = FoundVar->getDefinition(); | |||
3643 | if (D->isThisDeclarationADefinition() && FoundDef) | |||
3644 | // FIXME Check for ODR error if the two definitions have | |||
3645 | // different initializers? | |||
3646 | return Importer.MapImported(D, FoundDef); | |||
3647 | ||||
3648 | // The VarDecl in the "From" context has an initializer, but in the | |||
3649 | // "To" context we already have an initializer. | |||
3650 | const VarDecl *FoundDInit = nullptr; | |||
3651 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) | |||
3652 | // FIXME Diagnose ODR error if the two initializers are different? | |||
3653 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); | |||
3654 | ||||
3655 | FoundByLookup = FoundVar; | |||
3656 | break; | |||
3657 | } | |||
3658 | ||||
3659 | const ArrayType *FoundArray | |||
3660 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); | |||
3661 | const ArrayType *TArray | |||
3662 | = Importer.getToContext().getAsArrayType(D->getType()); | |||
3663 | if (FoundArray && TArray) { | |||
3664 | if (isa<IncompleteArrayType>(FoundArray) && | |||
3665 | isa<ConstantArrayType>(TArray)) { | |||
3666 | // Import the type. | |||
3667 | if (auto TyOrErr = import(D->getType())) | |||
3668 | FoundVar->setType(*TyOrErr); | |||
3669 | else | |||
3670 | return TyOrErr.takeError(); | |||
3671 | ||||
3672 | FoundByLookup = FoundVar; | |||
3673 | break; | |||
3674 | } else if (isa<IncompleteArrayType>(TArray) && | |||
3675 | isa<ConstantArrayType>(FoundArray)) { | |||
3676 | FoundByLookup = FoundVar; | |||
3677 | break; | |||
3678 | } | |||
3679 | } | |||
3680 | ||||
3681 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) | |||
3682 | << Name << D->getType() << FoundVar->getType(); | |||
3683 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) | |||
3684 | << FoundVar->getType(); | |||
3685 | } | |||
3686 | } | |||
3687 | ||||
3688 | ConflictingDecls.push_back(FoundDecl); | |||
3689 | } | |||
3690 | ||||
3691 | if (!ConflictingDecls.empty()) { | |||
3692 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | |||
3693 | ConflictingDecls.data(), | |||
3694 | ConflictingDecls.size()); | |||
3695 | if (!Name) | |||
3696 | return make_error<ImportError>(ImportError::NameConflict); | |||
3697 | } | |||
3698 | } | |||
3699 | ||||
3700 | QualType ToType; | |||
3701 | TypeSourceInfo *ToTypeSourceInfo; | |||
3702 | SourceLocation ToInnerLocStart; | |||
3703 | NestedNameSpecifierLoc ToQualifierLoc; | |||
3704 | if (auto Imp = importSeq( | |||
3705 | D->getType(), D->getTypeSourceInfo(), D->getInnerLocStart(), | |||
3706 | D->getQualifierLoc())) | |||
3707 | std::tie(ToType, ToTypeSourceInfo, ToInnerLocStart, ToQualifierLoc) = *Imp; | |||
3708 | else | |||
3709 | return Imp.takeError(); | |||
3710 | ||||
3711 | // Create the imported variable. | |||
3712 | VarDecl *ToVar; | |||
3713 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, | |||
3714 | ToInnerLocStart, Loc, | |||
3715 | Name.getAsIdentifierInfo(), | |||
3716 | ToType, ToTypeSourceInfo, | |||
3717 | D->getStorageClass())) | |||
3718 | return ToVar; | |||
3719 | ||||
3720 | ToVar->setQualifierInfo(ToQualifierLoc); | |||
3721 | ToVar->setAccess(D->getAccess()); | |||
3722 | ToVar->setLexicalDeclContext(LexicalDC); | |||
3723 | ||||
3724 | if (FoundByLookup) { | |||
3725 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); | |||
3726 | ToVar->setPreviousDecl(Recent); | |||
3727 | } | |||
3728 | ||||
3729 | if (Error Err = ImportInitializer(D, ToVar)) | |||
3730 | return std::move(Err); | |||
3731 | ||||
3732 | if (D->isConstexpr()) | |||
3733 | ToVar->setConstexpr(true); | |||
3734 | ||||
3735 | if (D->getDeclContext()->containsDeclAndLoad(D)) | |||
3736 | DC->addDeclInternal(ToVar); | |||
3737 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) | |||
3738 | LexicalDC->addDeclInternal(ToVar); | |||
3739 | ||||
3740 | // Import the rest of the chain. I.e. import all subsequent declarations. | |||
3741 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { | |||
3742 | ExpectedDecl RedeclOrErr = import(*RedeclIt); | |||
3743 | if (!RedeclOrErr) | |||
3744 | return RedeclOrErr.takeError(); | |||
3745 | } | |||
3746 | ||||
3747 | return ToVar; | |||
3748 | } | |||
3749 | ||||
3750 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { | |||
3751 | // Parameters are created in the translation unit's context, then moved | |||
3752 | // into the function declaration's context afterward. | |||
3753 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); | |||
3754 | ||||
3755 | DeclarationName ToDeclName; | |||
3756 | SourceLocation ToLocation; | |||
3757 | QualType ToType; | |||
3758 | if (auto Imp = importSeq(D->getDeclName(), D->getLocation(), D->getType())) | |||
3759 | std::tie(ToDeclName, ToLocation, ToType) = *Imp; | |||
3760 | else | |||
3761 | return Imp.takeError(); | |||
3762 | ||||
3763 | // Create the imported parameter. | |||
3764 | ImplicitParamDecl *ToParm = nullptr; | |||
3765 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, | |||
3766 | ToLocation, ToDeclName.getAsIdentifierInfo(), | |||
3767 | ToType, D->getParameterKind())) | |||
3768 | return ToParm; | |||
3769 | return ToParm; | |||
3770 | } | |||
3771 | ||||
3772 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { | |||
3773 | // Parameters are created in the translation unit's context, then moved | |||
3774 | // into the function declaration's context afterward. | |||
3775 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); | |||
3776 | ||||
3777 | DeclarationName ToDeclName; | |||
3778 | SourceLocation ToLocation, ToInnerLocStart; | |||
3779 | QualType ToType; | |||
3780 | TypeSourceInfo *ToTypeSourceInfo; | |||
3781 | if (auto Imp = importSeq( | |||
3782 | D->getDeclName(), D->getLocation(), D->getType(), D->getInnerLocStart(), | |||
3783 | D->getTypeSourceInfo())) | |||
3784 | std::tie( | |||
3785 | ToDeclName, ToLocation, ToType, ToInnerLocStart, | |||
3786 | ToTypeSourceInfo) = *Imp; | |||
3787 | else | |||
3788 | return Imp.takeError(); | |||
3789 | ||||
3790 | ParmVarDecl *ToParm; | |||
3791 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, | |||
3792 | ToInnerLocStart, ToLocation, | |||
3793 | ToDeclName.getAsIdentifierInfo(), ToType, | |||
3794 | ToTypeSourceInfo, D->getStorageClass(), | |||
3795 | /*DefaultArg*/ nullptr)) | |||
3796 | return ToParm; | |||
3797 | ||||
3798 | // Set the default argument. | |||
3799 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); | |||
3800 | ToParm->setKNRPromoted(D->isKNRPromoted()); | |||
3801 | ||||
3802 | if (D->hasUninstantiatedDefaultArg()) { | |||
3803 | if (auto ToDefArgOrErr = import(D->getUninstantiatedDefaultArg())) | |||
3804 | ToParm->setUninstantiatedDefaultArg(*ToDefArgOrErr); | |||
3805 | else | |||
3806 | return ToDefArgOrErr.takeError(); | |||
3807 | } else if (D->hasUnparsedDefaultArg()) { | |||
3808 | ToParm->setUnparsedDefaultArg(); | |||
3809 | } else if (D->hasDefaultArg()) { | |||
3810 | if (auto ToDefArgOrErr = import(D->getDefaultArg())) | |||
3811 | ToParm->setDefaultArg(*ToDefArgOrErr); | |||
3812 | else | |||
3813 | return ToDefArgOrErr.takeError(); | |||
3814 | } | |||
3815 | ||||
3816 | if (D->isObjCMethodParameter()) { | |||
3817 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); | |||
3818 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); | |||
3819 | } else { | |||
3820 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), | |||
3821 | D->getFunctionScopeIndex()); | |||
3822 | } | |||
3823 | ||||
3824 | return ToParm; | |||
3825 | } | |||
3826 | ||||
3827 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { | |||
3828 | // Import the major distinguishing characteristics of a method. | |||
3829 | DeclContext *DC, *LexicalDC; | |||
3830 | DeclarationName Name; | |||
3831 | SourceLocation Loc; | |||
3832 | NamedDecl *ToD; | |||
3833 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3834 | return std::move(Err); | |||
3835 | if (ToD) | |||
3836 | return ToD; | |||
3837 | ||||
3838 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
3839 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
3840 | for (auto *FoundDecl : FoundDecls) { | |||
3841 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { | |||
3842 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) | |||
3843 | continue; | |||
3844 | ||||
3845 | // Check return types. | |||
3846 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), | |||
3847 | FoundMethod->getReturnType())) { | |||
3848 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) | |||
3849 | << D->isInstanceMethod() << Name << D->getReturnType() | |||
3850 | << FoundMethod->getReturnType(); | |||
3851 | Importer.ToDiag(FoundMethod->getLocation(), | |||
3852 | diag::note_odr_objc_method_here) | |||
3853 | << D->isInstanceMethod() << Name; | |||
3854 | ||||
3855 | return make_error<ImportError>(ImportError::NameConflict); | |||
3856 | } | |||
3857 | ||||
3858 | // Check the number of parameters. | |||
3859 | if (D->param_size() != FoundMethod->param_size()) { | |||
3860 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) | |||
3861 | << D->isInstanceMethod() << Name | |||
3862 | << D->param_size() << FoundMethod->param_size(); | |||
3863 | Importer.ToDiag(FoundMethod->getLocation(), | |||
3864 | diag::note_odr_objc_method_here) | |||
3865 | << D->isInstanceMethod() << Name; | |||
3866 | ||||
3867 | return make_error<ImportError>(ImportError::NameConflict); | |||
3868 | } | |||
3869 | ||||
3870 | // Check parameter types. | |||
3871 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), | |||
3872 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); | |||
3873 | P != PEnd; ++P, ++FoundP) { | |||
3874 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), | |||
3875 | (*FoundP)->getType())) { | |||
3876 | Importer.FromDiag((*P)->getLocation(), | |||
3877 | diag::err_odr_objc_method_param_type_inconsistent) | |||
3878 | << D->isInstanceMethod() << Name | |||
3879 | << (*P)->getType() << (*FoundP)->getType(); | |||
3880 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) | |||
3881 | << (*FoundP)->getType(); | |||
3882 | ||||
3883 | return make_error<ImportError>(ImportError::NameConflict); | |||
3884 | } | |||
3885 | } | |||
3886 | ||||
3887 | // Check variadic/non-variadic. | |||
3888 | // Check the number of parameters. | |||
3889 | if (D->isVariadic() != FoundMethod->isVariadic()) { | |||
3890 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) | |||
3891 | << D->isInstanceMethod() << Name; | |||
3892 | Importer.ToDiag(FoundMethod->getLocation(), | |||
3893 | diag::note_odr_objc_method_here) | |||
3894 | << D->isInstanceMethod() << Name; | |||
3895 | ||||
3896 | return make_error<ImportError>(ImportError::NameConflict); | |||
3897 | } | |||
3898 | ||||
3899 | // FIXME: Any other bits we need to merge? | |||
3900 | return Importer.MapImported(D, FoundMethod); | |||
3901 | } | |||
3902 | } | |||
3903 | ||||
3904 | SourceLocation ToEndLoc; | |||
3905 | QualType ToReturnType; | |||
3906 | TypeSourceInfo *ToReturnTypeSourceInfo; | |||
3907 | if (auto Imp = importSeq( | |||
3908 | D->getEndLoc(), D->getReturnType(), D->getReturnTypeSourceInfo())) | |||
3909 | std::tie(ToEndLoc, ToReturnType, ToReturnTypeSourceInfo) = *Imp; | |||
3910 | else | |||
3911 | return Imp.takeError(); | |||
3912 | ||||
3913 | ObjCMethodDecl *ToMethod; | |||
3914 | if (GetImportedOrCreateDecl( | |||
3915 | ToMethod, D, Importer.getToContext(), Loc, | |||
3916 | ToEndLoc, Name.getObjCSelector(), ToReturnType, | |||
3917 | ToReturnTypeSourceInfo, DC, D->isInstanceMethod(), D->isVariadic(), | |||
3918 | D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), | |||
3919 | D->getImplementationControl(), D->hasRelatedResultType())) | |||
3920 | return ToMethod; | |||
3921 | ||||
3922 | // FIXME: When we decide to merge method definitions, we'll need to | |||
3923 | // deal with implicit parameters. | |||
3924 | ||||
3925 | // Import the parameters | |||
3926 | SmallVector<ParmVarDecl *, 5> ToParams; | |||
3927 | for (auto *FromP : D->parameters()) { | |||
3928 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) | |||
3929 | ToParams.push_back(*ToPOrErr); | |||
3930 | else | |||
3931 | return ToPOrErr.takeError(); | |||
3932 | } | |||
3933 | ||||
3934 | // Set the parameters. | |||
3935 | for (auto *ToParam : ToParams) { | |||
3936 | ToParam->setOwningFunction(ToMethod); | |||
3937 | ToMethod->addDeclInternal(ToParam); | |||
3938 | } | |||
3939 | ||||
3940 | SmallVector<SourceLocation, 12> FromSelLocs; | |||
3941 | D->getSelectorLocs(FromSelLocs); | |||
3942 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); | |||
3943 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) | |||
3944 | return std::move(Err); | |||
3945 | ||||
3946 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); | |||
3947 | ||||
3948 | ToMethod->setLexicalDeclContext(LexicalDC); | |||
3949 | LexicalDC->addDeclInternal(ToMethod); | |||
3950 | return ToMethod; | |||
3951 | } | |||
3952 | ||||
3953 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { | |||
3954 | // Import the major distinguishing characteristics of a category. | |||
3955 | DeclContext *DC, *LexicalDC; | |||
3956 | DeclarationName Name; | |||
3957 | SourceLocation Loc; | |||
3958 | NamedDecl *ToD; | |||
3959 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3960 | return std::move(Err); | |||
3961 | if (ToD) | |||
3962 | return ToD; | |||
3963 | ||||
3964 | SourceLocation ToVarianceLoc, ToLocation, ToColonLoc; | |||
3965 | TypeSourceInfo *ToTypeSourceInfo; | |||
3966 | if (auto Imp = importSeq( | |||
3967 | D->getVarianceLoc(), D->getLocation(), D->getColonLoc(), | |||
3968 | D->getTypeSourceInfo())) | |||
3969 | std::tie(ToVarianceLoc, ToLocation, ToColonLoc, ToTypeSourceInfo) = *Imp; | |||
3970 | else | |||
3971 | return Imp.takeError(); | |||
3972 | ||||
3973 | ObjCTypeParamDecl *Result; | |||
3974 | if (GetImportedOrCreateDecl( | |||
3975 | Result, D, Importer.getToContext(), DC, D->getVariance(), | |||
3976 | ToVarianceLoc, D->getIndex(), | |||
3977 | ToLocation, Name.getAsIdentifierInfo(), | |||
3978 | ToColonLoc, ToTypeSourceInfo)) | |||
3979 | return Result; | |||
3980 | ||||
3981 | Result->setLexicalDeclContext(LexicalDC); | |||
3982 | return Result; | |||
3983 | } | |||
3984 | ||||
3985 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { | |||
3986 | // Import the major distinguishing characteristics of a category. | |||
3987 | DeclContext *DC, *LexicalDC; | |||
3988 | DeclarationName Name; | |||
3989 | SourceLocation Loc; | |||
3990 | NamedDecl *ToD; | |||
3991 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3992 | return std::move(Err); | |||
3993 | if (ToD) | |||
3994 | return ToD; | |||
3995 | ||||
3996 | ObjCInterfaceDecl *ToInterface; | |||
3997 | if (Error Err = importInto(ToInterface, D->getClassInterface())) | |||
3998 | return std::move(Err); | |||
3999 | ||||
4000 | // Determine if we've already encountered this category. | |||
4001 | ObjCCategoryDecl *MergeWithCategory | |||
4002 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); | |||
4003 | ObjCCategoryDecl *ToCategory = MergeWithCategory; | |||
4004 | if (!ToCategory) { | |||
4005 | SourceLocation ToAtStartLoc, ToCategoryNameLoc; | |||
4006 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; | |||
4007 | if (auto Imp = importSeq( | |||
4008 | D->getAtStartLoc(), D->getCategoryNameLoc(), | |||
4009 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) | |||
4010 | std::tie( | |||
4011 | ToAtStartLoc, ToCategoryNameLoc, | |||
4012 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; | |||
4013 | else | |||
4014 | return Imp.takeError(); | |||
4015 | ||||
4016 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, | |||
4017 | ToAtStartLoc, Loc, | |||
4018 | ToCategoryNameLoc, | |||
4019 | Name.getAsIdentifierInfo(), ToInterface, | |||
4020 | /*TypeParamList=*/nullptr, | |||
4021 | ToIvarLBraceLoc, | |||
4022 | ToIvarRBraceLoc)) | |||
4023 | return ToCategory; | |||
4024 | ||||
4025 | ToCategory->setLexicalDeclContext(LexicalDC); | |||
4026 | LexicalDC->addDeclInternal(ToCategory); | |||
4027 | // Import the type parameter list after MapImported, to avoid | |||
4028 | // loops when bringing in their DeclContext. | |||
4029 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) | |||
4030 | ToCategory->setTypeParamList(*PListOrErr); | |||
4031 | else | |||
4032 | return PListOrErr.takeError(); | |||
4033 | ||||
4034 | // Import protocols | |||
4035 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | |||
4036 | SmallVector<SourceLocation, 4> ProtocolLocs; | |||
4037 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc | |||
4038 | = D->protocol_loc_begin(); | |||
4039 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), | |||
4040 | FromProtoEnd = D->protocol_end(); | |||
4041 | FromProto != FromProtoEnd; | |||
4042 | ++FromProto, ++FromProtoLoc) { | |||
4043 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | |||
4044 | Protocols.push_back(*ToProtoOrErr); | |||
4045 | else | |||
4046 | return ToProtoOrErr.takeError(); | |||
4047 | ||||
4048 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | |||
4049 | ProtocolLocs.push_back(*ToProtoLocOrErr); | |||
4050 | else | |||
4051 | return ToProtoLocOrErr.takeError(); | |||
4052 | } | |||
4053 | ||||
4054 | // FIXME: If we're merging, make sure that the protocol list is the same. | |||
4055 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), | |||
4056 | ProtocolLocs.data(), Importer.getToContext()); | |||
4057 | ||||
4058 | } else { | |||
4059 | Importer.MapImported(D, ToCategory); | |||
4060 | } | |||
4061 | ||||
4062 | // Import all of the members of this category. | |||
4063 | if (Error Err = ImportDeclContext(D)) | |||
4064 | return std::move(Err); | |||
4065 | ||||
4066 | // If we have an implementation, import it as well. | |||
4067 | if (D->getImplementation()) { | |||
4068 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = | |||
4069 | import(D->getImplementation())) | |||
4070 | ToCategory->setImplementation(*ToImplOrErr); | |||
4071 | else | |||
4072 | return ToImplOrErr.takeError(); | |||
4073 | } | |||
4074 | ||||
4075 | return ToCategory; | |||
4076 | } | |||
4077 | ||||
4078 | Error ASTNodeImporter::ImportDefinition( | |||
4079 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { | |||
4080 | if (To->getDefinition()) { | |||
4081 | if (shouldForceImportDeclContext(Kind)) | |||
4082 | if (Error Err = ImportDeclContext(From)) | |||
4083 | return Err; | |||
4084 | return Error::success(); | |||
4085 | } | |||
4086 | ||||
4087 | // Start the protocol definition | |||
4088 | To->startDefinition(); | |||
4089 | ||||
4090 | // Import protocols | |||
4091 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | |||
4092 | SmallVector<SourceLocation, 4> ProtocolLocs; | |||
4093 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = | |||
4094 | From->protocol_loc_begin(); | |||
4095 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), | |||
4096 | FromProtoEnd = From->protocol_end(); | |||
4097 | FromProto != FromProtoEnd; | |||
4098 | ++FromProto, ++FromProtoLoc) { | |||
4099 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | |||
4100 | Protocols.push_back(*ToProtoOrErr); | |||
4101 | else | |||
4102 | return ToProtoOrErr.takeError(); | |||
4103 | ||||
4104 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | |||
4105 | ProtocolLocs.push_back(*ToProtoLocOrErr); | |||
4106 | else | |||
4107 | return ToProtoLocOrErr.takeError(); | |||
4108 | ||||
4109 | } | |||
4110 | ||||
4111 | // FIXME: If we're merging, make sure that the protocol list is the same. | |||
4112 | To->setProtocolList(Protocols.data(), Protocols.size(), | |||
4113 | ProtocolLocs.data(), Importer.getToContext()); | |||
4114 | ||||
4115 | if (shouldForceImportDeclContext(Kind)) { | |||
4116 | // Import all of the members of this protocol. | |||
4117 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | |||
4118 | return Err; | |||
4119 | } | |||
4120 | return Error::success(); | |||
4121 | } | |||
4122 | ||||
4123 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { | |||
4124 | // If this protocol has a definition in the translation unit we're coming | |||
4125 | // from, but this particular declaration is not that definition, import the | |||
4126 | // definition and map to that. | |||
4127 | ObjCProtocolDecl *Definition = D->getDefinition(); | |||
4128 | if (Definition && Definition != D) { | |||
4129 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | |||
4130 | return Importer.MapImported(D, *ImportedDefOrErr); | |||
4131 | else | |||
4132 | return ImportedDefOrErr.takeError(); | |||
4133 | } | |||
4134 | ||||
4135 | // Import the major distinguishing characteristics of a protocol. | |||
4136 | DeclContext *DC, *LexicalDC; | |||
4137 | DeclarationName Name; | |||
4138 | SourceLocation Loc; | |||
4139 | NamedDecl *ToD; | |||
4140 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4141 | return std::move(Err); | |||
4142 | if (ToD) | |||
4143 | return ToD; | |||
4144 | ||||
4145 | ObjCProtocolDecl *MergeWithProtocol = nullptr; | |||
4146 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
4147 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
4148 | for (auto *FoundDecl : FoundDecls) { | |||
4149 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) | |||
4150 | continue; | |||
4151 | ||||
4152 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) | |||
4153 | break; | |||
4154 | } | |||
4155 | ||||
4156 | ObjCProtocolDecl *ToProto = MergeWithProtocol; | |||
4157 | if (!ToProto) { | |||
4158 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); | |||
4159 | if (!ToAtBeginLocOrErr) | |||
4160 | return ToAtBeginLocOrErr.takeError(); | |||
4161 | ||||
4162 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, | |||
4163 | Name.getAsIdentifierInfo(), Loc, | |||
4164 | *ToAtBeginLocOrErr, | |||
4165 | /*PrevDecl=*/nullptr)) | |||
4166 | return ToProto; | |||
4167 | ToProto->setLexicalDeclContext(LexicalDC); | |||
4168 | LexicalDC->addDeclInternal(ToProto); | |||
4169 | } | |||
4170 | ||||
4171 | Importer.MapImported(D, ToProto); | |||
4172 | ||||
4173 | if (D->isThisDeclarationADefinition()) | |||
4174 | if (Error Err = ImportDefinition(D, ToProto)) | |||
4175 | return std::move(Err); | |||
4176 | ||||
4177 | return ToProto; | |||
4178 | } | |||
4179 | ||||
4180 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { | |||
4181 | DeclContext *DC, *LexicalDC; | |||
4182 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
4183 | return std::move(Err); | |||
4184 | ||||
4185 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); | |||
4186 | if (!ExternLocOrErr) | |||
4187 | return ExternLocOrErr.takeError(); | |||
4188 | ||||
4189 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); | |||
4190 | if (!LangLocOrErr) | |||
4191 | return LangLocOrErr.takeError(); | |||
4192 | ||||
4193 | bool HasBraces = D->hasBraces(); | |||
4194 | ||||
4195 | LinkageSpecDecl *ToLinkageSpec; | |||
4196 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, | |||
4197 | *ExternLocOrErr, *LangLocOrErr, | |||
4198 | D->getLanguage(), HasBraces)) | |||
4199 | return ToLinkageSpec; | |||
4200 | ||||
4201 | if (HasBraces) { | |||
4202 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); | |||
4203 | if (!RBraceLocOrErr) | |||
4204 | return RBraceLocOrErr.takeError(); | |||
4205 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); | |||
4206 | } | |||
4207 | ||||
4208 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); | |||
4209 | LexicalDC->addDeclInternal(ToLinkageSpec); | |||
4210 | ||||
4211 | return ToLinkageSpec; | |||
4212 | } | |||
4213 | ||||
4214 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { | |||
4215 | DeclContext *DC, *LexicalDC; | |||
4216 | DeclarationName Name; | |||
4217 | SourceLocation Loc; | |||
4218 | NamedDecl *ToD = nullptr; | |||
4219 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4220 | return std::move(Err); | |||
4221 | if (ToD) | |||
4222 | return ToD; | |||
4223 | ||||
4224 | SourceLocation ToLoc, ToUsingLoc; | |||
4225 | NestedNameSpecifierLoc ToQualifierLoc; | |||
4226 | if (auto Imp = importSeq( | |||
4227 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc())) | |||
4228 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc) = *Imp; | |||
4229 | else | |||
4230 | return Imp.takeError(); | |||
4231 | ||||
4232 | DeclarationNameInfo NameInfo(Name, ToLoc); | |||
4233 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | |||
4234 | return std::move(Err); | |||
4235 | ||||
4236 | UsingDecl *ToUsing; | |||
4237 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, | |||
4238 | ToUsingLoc, ToQualifierLoc, NameInfo, | |||
4239 | D->hasTypename())) | |||
4240 | return ToUsing; | |||
4241 | ||||
4242 | ToUsing->setLexicalDeclContext(LexicalDC); | |||
4243 | LexicalDC->addDeclInternal(ToUsing); | |||
4244 | ||||
4245 | if (NamedDecl *FromPattern = | |||
4246 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { | |||
4247 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) | |||
4248 | Importer.getToContext().setInstantiatedFromUsingDecl( | |||
4249 | ToUsing, *ToPatternOrErr); | |||
4250 | else | |||
4251 | return ToPatternOrErr.takeError(); | |||
4252 | } | |||
4253 | ||||
4254 | for (UsingShadowDecl *FromShadow : D->shadows()) { | |||
4255 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) | |||
4256 | ToUsing->addShadowDecl(*ToShadowOrErr); | |||
4257 | else | |||
4258 | // FIXME: We return error here but the definition is already created | |||
4259 | // and available with lookups. How to fix this?.. | |||
4260 | return ToShadowOrErr.takeError(); | |||
4261 | } | |||
4262 | return ToUsing; | |||
4263 | } | |||
4264 | ||||
4265 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { | |||
4266 | DeclContext *DC, *LexicalDC; | |||
4267 | DeclarationName Name; | |||
4268 | SourceLocation Loc; | |||
4269 | NamedDecl *ToD = nullptr; | |||
4270 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4271 | return std::move(Err); | |||
4272 | if (ToD) | |||
4273 | return ToD; | |||
4274 | ||||
4275 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); | |||
4276 | if (!ToUsingOrErr) | |||
4277 | return ToUsingOrErr.takeError(); | |||
4278 | ||||
4279 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); | |||
4280 | if (!ToTargetOrErr) | |||
4281 | return ToTargetOrErr.takeError(); | |||
4282 | ||||
4283 | UsingShadowDecl *ToShadow; | |||
4284 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, | |||
4285 | *ToUsingOrErr, *ToTargetOrErr)) | |||
4286 | return ToShadow; | |||
4287 | ||||
4288 | ToShadow->setLexicalDeclContext(LexicalDC); | |||
4289 | ToShadow->setAccess(D->getAccess()); | |||
4290 | ||||
4291 | if (UsingShadowDecl *FromPattern = | |||
4292 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { | |||
4293 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) | |||
4294 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( | |||
4295 | ToShadow, *ToPatternOrErr); | |||
4296 | else | |||
4297 | // FIXME: We return error here but the definition is already created | |||
4298 | // and available with lookups. How to fix this?.. | |||
4299 | return ToPatternOrErr.takeError(); | |||
4300 | } | |||
4301 | ||||
4302 | LexicalDC->addDeclInternal(ToShadow); | |||
4303 | ||||
4304 | return ToShadow; | |||
4305 | } | |||
4306 | ||||
4307 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { | |||
4308 | DeclContext *DC, *LexicalDC; | |||
4309 | DeclarationName Name; | |||
4310 | SourceLocation Loc; | |||
4311 | NamedDecl *ToD = nullptr; | |||
4312 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4313 | return std::move(Err); | |||
4314 | if (ToD) | |||
4315 | return ToD; | |||
4316 | ||||
4317 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); | |||
4318 | if (!ToComAncestorOrErr) | |||
4319 | return ToComAncestorOrErr.takeError(); | |||
4320 | ||||
4321 | NamespaceDecl *ToNominatedNamespace; | |||
4322 | SourceLocation ToUsingLoc, ToNamespaceKeyLocation, ToIdentLocation; | |||
4323 | NestedNameSpecifierLoc ToQualifierLoc; | |||
4324 | if (auto Imp = importSeq( | |||
4325 | D->getNominatedNamespace(), D->getUsingLoc(), | |||
4326 | D->getNamespaceKeyLocation(), D->getQualifierLoc(), | |||
4327 | D->getIdentLocation())) | |||
4328 | std::tie( | |||
4329 | ToNominatedNamespace, ToUsingLoc, ToNamespaceKeyLocation, | |||
4330 | ToQualifierLoc, ToIdentLocation) = *Imp; | |||
4331 | else | |||
4332 | return Imp.takeError(); | |||
4333 | ||||
4334 | UsingDirectiveDecl *ToUsingDir; | |||
4335 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, | |||
4336 | ToUsingLoc, | |||
4337 | ToNamespaceKeyLocation, | |||
4338 | ToQualifierLoc, | |||
4339 | ToIdentLocation, | |||
4340 | ToNominatedNamespace, *ToComAncestorOrErr)) | |||
4341 | return ToUsingDir; | |||
4342 | ||||
4343 | ToUsingDir->setLexicalDeclContext(LexicalDC); | |||
4344 | LexicalDC->addDeclInternal(ToUsingDir); | |||
4345 | ||||
4346 | return ToUsingDir; | |||
4347 | } | |||
4348 | ||||
4349 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( | |||
4350 | UnresolvedUsingValueDecl *D) { | |||
4351 | DeclContext *DC, *LexicalDC; | |||
4352 | DeclarationName Name; | |||
4353 | SourceLocation Loc; | |||
4354 | NamedDecl *ToD = nullptr; | |||
4355 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4356 | return std::move(Err); | |||
4357 | if (ToD) | |||
4358 | return ToD; | |||
4359 | ||||
4360 | SourceLocation ToLoc, ToUsingLoc, ToEllipsisLoc; | |||
4361 | NestedNameSpecifierLoc ToQualifierLoc; | |||
4362 | if (auto Imp = importSeq( | |||
4363 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc(), | |||
4364 | D->getEllipsisLoc())) | |||
4365 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; | |||
4366 | else | |||
4367 | return Imp.takeError(); | |||
4368 | ||||
4369 | DeclarationNameInfo NameInfo(Name, ToLoc); | |||
4370 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | |||
4371 | return std::move(Err); | |||
4372 | ||||
4373 | UnresolvedUsingValueDecl *ToUsingValue; | |||
4374 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, | |||
4375 | ToUsingLoc, ToQualifierLoc, NameInfo, | |||
4376 | ToEllipsisLoc)) | |||
4377 | return ToUsingValue; | |||
4378 | ||||
4379 | ToUsingValue->setAccess(D->getAccess()); | |||
4380 | ToUsingValue->setLexicalDeclContext(LexicalDC); | |||
4381 | LexicalDC->addDeclInternal(ToUsingValue); | |||
4382 | ||||
4383 | return ToUsingValue; | |||
4384 | } | |||
4385 | ||||
4386 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( | |||
4387 | UnresolvedUsingTypenameDecl *D) { | |||
4388 | DeclContext *DC, *LexicalDC; | |||
4389 | DeclarationName Name; | |||
4390 | SourceLocation Loc; | |||
4391 | NamedDecl *ToD = nullptr; | |||
4392 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4393 | return std::move(Err); | |||
4394 | if (ToD) | |||
4395 | return ToD; | |||
4396 | ||||
4397 | SourceLocation ToUsingLoc, ToTypenameLoc, ToEllipsisLoc; | |||
4398 | NestedNameSpecifierLoc ToQualifierLoc; | |||
4399 | if (auto Imp = importSeq( | |||
4400 | D->getUsingLoc(), D->getTypenameLoc(), D->getQualifierLoc(), | |||
4401 | D->getEllipsisLoc())) | |||
4402 | std::tie(ToUsingLoc, ToTypenameLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; | |||
4403 | else | |||
4404 | return Imp.takeError(); | |||
4405 | ||||
4406 | UnresolvedUsingTypenameDecl *ToUsing; | |||
4407 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, | |||
4408 | ToUsingLoc, ToTypenameLoc, | |||
4409 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) | |||
4410 | return ToUsing; | |||
4411 | ||||
4412 | ToUsing->setAccess(D->getAccess()); | |||
4413 | ToUsing->setLexicalDeclContext(LexicalDC); | |||
4414 | LexicalDC->addDeclInternal(ToUsing); | |||
4415 | ||||
4416 | return ToUsing; | |||
4417 | } | |||
4418 | ||||
4419 | ||||
4420 | Error ASTNodeImporter::ImportDefinition( | |||
4421 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { | |||
4422 | if (To->getDefinition()) { | |||
4423 | // Check consistency of superclass. | |||
4424 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); | |||
4425 | if (FromSuper) { | |||
4426 | if (auto FromSuperOrErr = import(FromSuper)) | |||
4427 | FromSuper = *FromSuperOrErr; | |||
4428 | else | |||
4429 | return FromSuperOrErr.takeError(); | |||
4430 | } | |||
4431 | ||||
4432 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); | |||
4433 | if ((bool)FromSuper != (bool)ToSuper || | |||
4434 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { | |||
4435 | Importer.ToDiag(To->getLocation(), | |||
4436 | diag::err_odr_objc_superclass_inconsistent) | |||
4437 | << To->getDeclName(); | |||
4438 | if (ToSuper) | |||
4439 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) | |||
4440 | << To->getSuperClass()->getDeclName(); | |||
4441 | else | |||
4442 | Importer.ToDiag(To->getLocation(), | |||
4443 | diag::note_odr_objc_missing_superclass); | |||
4444 | if (From->getSuperClass()) | |||
4445 | Importer.FromDiag(From->getSuperClassLoc(), | |||
4446 | diag::note_odr_objc_superclass) | |||
4447 | << From->getSuperClass()->getDeclName(); | |||
4448 | else | |||
4449 | Importer.FromDiag(From->getLocation(), | |||
4450 | diag::note_odr_objc_missing_superclass); | |||
4451 | } | |||
4452 | ||||
4453 | if (shouldForceImportDeclContext(Kind)) | |||
4454 | if (Error Err = ImportDeclContext(From)) | |||
4455 | return Err; | |||
4456 | return Error::success(); | |||
4457 | } | |||
4458 | ||||
4459 | // Start the definition. | |||
4460 | To->startDefinition(); | |||
4461 | ||||
4462 | // If this class has a superclass, import it. | |||
4463 | if (From->getSuperClass()) { | |||
4464 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) | |||
4465 | To->setSuperClass(*SuperTInfoOrErr); | |||
4466 | else | |||
4467 | return SuperTInfoOrErr.takeError(); | |||
4468 | } | |||
4469 | ||||
4470 | // Import protocols | |||
4471 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | |||
4472 | SmallVector<SourceLocation, 4> ProtocolLocs; | |||
4473 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = | |||
4474 | From->protocol_loc_begin(); | |||
4475 | ||||
4476 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), | |||
4477 | FromProtoEnd = From->protocol_end(); | |||
4478 | FromProto != FromProtoEnd; | |||
4479 | ++FromProto, ++FromProtoLoc) { | |||
4480 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | |||
4481 | Protocols.push_back(*ToProtoOrErr); | |||
4482 | else | |||
4483 | return ToProtoOrErr.takeError(); | |||
4484 | ||||
4485 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | |||
4486 | ProtocolLocs.push_back(*ToProtoLocOrErr); | |||
4487 | else | |||
4488 | return ToProtoLocOrErr.takeError(); | |||
4489 | ||||
4490 | } | |||
4491 | ||||
4492 | // FIXME: If we're merging, make sure that the protocol list is the same. | |||
4493 | To->setProtocolList(Protocols.data(), Protocols.size(), | |||
4494 | ProtocolLocs.data(), Importer.getToContext()); | |||
4495 | ||||
4496 | // Import categories. When the categories themselves are imported, they'll | |||
4497 | // hook themselves into this interface. | |||
4498 | for (auto *Cat : From->known_categories()) { | |||
4499 | auto ToCatOrErr = import(Cat); | |||
4500 | if (!ToCatOrErr) | |||
4501 | return ToCatOrErr.takeError(); | |||
4502 | } | |||
4503 | ||||
4504 | // If we have an @implementation, import it as well. | |||
4505 | if (From->getImplementation()) { | |||
4506 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = | |||
4507 | import(From->getImplementation())) | |||
4508 | To->setImplementation(*ToImplOrErr); | |||
4509 | else | |||
4510 | return ToImplOrErr.takeError(); | |||
4511 | } | |||
4512 | ||||
4513 | if (shouldForceImportDeclContext(Kind)) { | |||
4514 | // Import all of the members of this class. | |||
4515 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | |||
4516 | return Err; | |||
4517 | } | |||
4518 | return Error::success(); | |||
4519 | } | |||
4520 | ||||
4521 | Expected<ObjCTypeParamList *> | |||
4522 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { | |||
4523 | if (!list) | |||
4524 | return nullptr; | |||
4525 | ||||
4526 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; | |||
4527 | for (auto *fromTypeParam : *list) { | |||
4528 | if (auto toTypeParamOrErr = import(fromTypeParam)) | |||
4529 | toTypeParams.push_back(*toTypeParamOrErr); | |||
4530 | else | |||
4531 | return toTypeParamOrErr.takeError(); | |||
4532 | } | |||
4533 | ||||
4534 | auto LAngleLocOrErr = import(list->getLAngleLoc()); | |||
4535 | if (!LAngleLocOrErr) | |||
4536 | return LAngleLocOrErr.takeError(); | |||
4537 | ||||
4538 | auto RAngleLocOrErr = import(list->getRAngleLoc()); | |||
4539 | if (!RAngleLocOrErr) | |||
4540 | return RAngleLocOrErr.takeError(); | |||
4541 | ||||
4542 | return ObjCTypeParamList::create(Importer.getToContext(), | |||
4543 | *LAngleLocOrErr, | |||
4544 | toTypeParams, | |||
4545 | *RAngleLocOrErr); | |||
4546 | } | |||
4547 | ||||
4548 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { | |||
4549 | // If this class has a definition in the translation unit we're coming from, | |||
4550 | // but this particular declaration is not that definition, import the | |||
4551 | // definition and map to that. | |||
4552 | ObjCInterfaceDecl *Definition = D->getDefinition(); | |||
4553 | if (Definition && Definition != D) { | |||
4554 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | |||
4555 | return Importer.MapImported(D, *ImportedDefOrErr); | |||
4556 | else | |||
4557 | return ImportedDefOrErr.takeError(); | |||
4558 | } | |||
4559 | ||||
4560 | // Import the major distinguishing characteristics of an @interface. | |||
4561 | DeclContext *DC, *LexicalDC; | |||
4562 | DeclarationName Name; | |||
4563 | SourceLocation Loc; | |||
4564 | NamedDecl *ToD; | |||
4565 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4566 | return std::move(Err); | |||
4567 | if (ToD) | |||
4568 | return ToD; | |||
4569 | ||||
4570 | // Look for an existing interface with the same name. | |||
4571 | ObjCInterfaceDecl *MergeWithIface = nullptr; | |||
4572 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
4573 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
4574 | for (auto *FoundDecl : FoundDecls) { | |||
4575 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) | |||
4576 | continue; | |||
4577 | ||||
4578 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) | |||
4579 | break; | |||
4580 | } | |||
4581 | ||||
4582 | // Create an interface declaration, if one does not already exist. | |||
4583 | ObjCInterfaceDecl *ToIface = MergeWithIface; | |||
4584 | if (!ToIface) { | |||
4585 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); | |||
4586 | if (!AtBeginLocOrErr) | |||
4587 | return AtBeginLocOrErr.takeError(); | |||
4588 | ||||
4589 | if (GetImportedOrCreateDecl( | |||
4590 | ToIface, D, Importer.getToContext(), DC, | |||
4591 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), | |||
4592 | /*TypeParamList=*/nullptr, | |||
4593 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) | |||
4594 | return ToIface; | |||
4595 | ToIface->setLexicalDeclContext(LexicalDC); | |||
4596 | LexicalDC->addDeclInternal(ToIface); | |||
4597 | } | |||
4598 | Importer.MapImported(D, ToIface); | |||
4599 | // Import the type parameter list after MapImported, to avoid | |||
4600 | // loops when bringing in their DeclContext. | |||
4601 | if (auto ToPListOrErr = | |||
4602 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) | |||
4603 | ToIface->setTypeParamList(*ToPListOrErr); | |||
4604 | else | |||
4605 | return ToPListOrErr.takeError(); | |||
4606 | ||||
4607 | if (D->isThisDeclarationADefinition()) | |||
4608 | if (Error Err = ImportDefinition(D, ToIface)) | |||
4609 | return std::move(Err); | |||
4610 | ||||
4611 | return ToIface; | |||
4612 | } | |||
4613 | ||||
4614 | ExpectedDecl | |||
4615 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { | |||
4616 | ObjCCategoryDecl *Category; | |||
4617 | if (Error Err = importInto(Category, D->getCategoryDecl())) | |||
4618 | return std::move(Err); | |||
4619 | ||||
4620 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); | |||
4621 | if (!ToImpl) { | |||
4622 | DeclContext *DC, *LexicalDC; | |||
4623 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
4624 | return std::move(Err); | |||
4625 | ||||
4626 | SourceLocation ToLocation, ToAtStartLoc, ToCategoryNameLoc; | |||
4627 | if (auto Imp = importSeq( | |||
4628 | D->getLocation(), D->getAtStartLoc(), D->getCategoryNameLoc())) | |||
4629 | std::tie(ToLocation, ToAtStartLoc, ToCategoryNameLoc) = *Imp; | |||
4630 | else | |||
4631 | return Imp.takeError(); | |||
4632 | ||||
4633 | if (GetImportedOrCreateDecl( | |||
4634 | ToImpl, D, Importer.getToContext(), DC, | |||
4635 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), | |||
4636 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) | |||
4637 | return ToImpl; | |||
4638 | ||||
4639 | ToImpl->setLexicalDeclContext(LexicalDC); | |||
4640 | LexicalDC->addDeclInternal(ToImpl); | |||
4641 | Category->setImplementation(ToImpl); | |||
4642 | } | |||
4643 | ||||
4644 | Importer.MapImported(D, ToImpl); | |||
4645 | if (Error Err = ImportDeclContext(D)) | |||
4646 | return std::move(Err); | |||
4647 | ||||
4648 | return ToImpl; | |||
4649 | } | |||
4650 | ||||
4651 | ExpectedDecl | |||
4652 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { | |||
4653 | // Find the corresponding interface. | |||
4654 | ObjCInterfaceDecl *Iface; | |||
4655 | if (Error Err = importInto(Iface, D->getClassInterface())) | |||
4656 | return std::move(Err); | |||
4657 | ||||
4658 | // Import the superclass, if any. | |||
4659 | ObjCInterfaceDecl *Super; | |||
4660 | if (Error Err = importInto(Super, D->getSuperClass())) | |||
4661 | return std::move(Err); | |||
4662 | ||||
4663 | ObjCImplementationDecl *Impl = Iface->getImplementation(); | |||
4664 | if (!Impl) { | |||
4665 | // We haven't imported an implementation yet. Create a new @implementation | |||
4666 | // now. | |||
4667 | DeclContext *DC, *LexicalDC; | |||
4668 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
4669 | return std::move(Err); | |||
4670 | ||||
4671 | SourceLocation ToLocation, ToAtStartLoc, ToSuperClassLoc; | |||
4672 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; | |||
4673 | if (auto Imp = importSeq( | |||
4674 | D->getLocation(), D->getAtStartLoc(), D->getSuperClassLoc(), | |||
4675 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) | |||
4676 | std::tie( | |||
4677 | ToLocation, ToAtStartLoc, ToSuperClassLoc, | |||
4678 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; | |||
4679 | else | |||
4680 | return Imp.takeError(); | |||
4681 | ||||
4682 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), | |||
4683 | DC, Iface, Super, | |||
4684 | ToLocation, | |||
4685 | ToAtStartLoc, | |||
4686 | ToSuperClassLoc, | |||
4687 | ToIvarLBraceLoc, | |||
4688 | ToIvarRBraceLoc)) | |||
4689 | return Impl; | |||
4690 | ||||
4691 | Impl->setLexicalDeclContext(LexicalDC); | |||
4692 | ||||
4693 | // Associate the implementation with the class it implements. | |||
4694 | Iface->setImplementation(Impl); | |||
4695 | Importer.MapImported(D, Iface->getImplementation()); | |||
4696 | } else { | |||
4697 | Importer.MapImported(D, Iface->getImplementation()); | |||
4698 | ||||
4699 | // Verify that the existing @implementation has the same superclass. | |||
4700 | if ((Super && !Impl->getSuperClass()) || | |||
4701 | (!Super && Impl->getSuperClass()) || | |||
4702 | (Super && Impl->getSuperClass() && | |||
4703 | !declaresSameEntity(Super->getCanonicalDecl(), | |||
4704 | Impl->getSuperClass()))) { | |||
4705 | Importer.ToDiag(Impl->getLocation(), | |||
4706 | diag::err_odr_objc_superclass_inconsistent) | |||
4707 | << Iface->getDeclName(); | |||
4708 | // FIXME: It would be nice to have the location of the superclass | |||
4709 | // below. | |||
4710 | if (Impl->getSuperClass()) | |||
4711 | Importer.ToDiag(Impl->getLocation(), | |||
4712 | diag::note_odr_objc_superclass) | |||
4713 | << Impl->getSuperClass()->getDeclName(); | |||
4714 | else | |||
4715 | Importer.ToDiag(Impl->getLocation(), | |||
4716 | diag::note_odr_objc_missing_superclass); | |||
4717 | if (D->getSuperClass()) | |||
4718 | Importer.FromDiag(D->getLocation(), | |||
4719 | diag::note_odr_objc_superclass) | |||
4720 | << D->getSuperClass()->getDeclName(); | |||
4721 | else | |||
4722 | Importer.FromDiag(D->getLocation(), | |||
4723 | diag::note_odr_objc_missing_superclass); | |||
4724 | ||||
4725 | return make_error<ImportError>(ImportError::NameConflict); | |||
4726 | } | |||
4727 | } | |||
4728 | ||||
4729 | // Import all of the members of this @implementation. | |||
4730 | if (Error Err = ImportDeclContext(D)) | |||
4731 | return std::move(Err); | |||
4732 | ||||
4733 | return Impl; | |||
4734 | } | |||
4735 | ||||
4736 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { | |||
4737 | // Import the major distinguishing characteristics of an @property. | |||
4738 | DeclContext *DC, *LexicalDC; | |||
4739 | DeclarationName Name; | |||
4740 | SourceLocation Loc; | |||
4741 | NamedDecl *ToD; | |||
4742 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4743 | return std::move(Err); | |||
4744 | if (ToD) | |||
4745 | return ToD; | |||
4746 | ||||
4747 | // Check whether we have already imported this property. | |||
4748 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
4749 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
4750 | for (auto *FoundDecl : FoundDecls) { | |||
4751 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { | |||
4752 | // Check property types. | |||
4753 | if (!Importer.IsStructurallyEquivalent(D->getType(), | |||
4754 | FoundProp->getType())) { | |||
4755 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) | |||
4756 | << Name << D->getType() << FoundProp->getType(); | |||
4757 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) | |||
4758 | << FoundProp->getType(); | |||
4759 | ||||
4760 | return make_error<ImportError>(ImportError::NameConflict); | |||
4761 | } | |||
4762 | ||||
4763 | // FIXME: Check property attributes, getters, setters, etc.? | |||
4764 | ||||
4765 | // Consider these properties to be equivalent. | |||
4766 | Importer.MapImported(D, FoundProp); | |||
4767 | return FoundProp; | |||
4768 | } | |||
4769 | } | |||
4770 | ||||
4771 | QualType ToType; | |||
4772 | TypeSourceInfo *ToTypeSourceInfo; | |||
4773 | SourceLocation ToAtLoc, ToLParenLoc; | |||
4774 | if (auto Imp = importSeq( | |||
4775 | D->getType(), D->getTypeSourceInfo(), D->getAtLoc(), D->getLParenLoc())) | |||
4776 | std::tie(ToType, ToTypeSourceInfo, ToAtLoc, ToLParenLoc) = *Imp; | |||
4777 | else | |||
4778 | return Imp.takeError(); | |||
4779 | ||||
4780 | // Create the new property. | |||
4781 | ObjCPropertyDecl *ToProperty; | |||
4782 | if (GetImportedOrCreateDecl( | |||
4783 | ToProperty, D, Importer.getToContext(), DC, Loc, | |||
4784 | Name.getAsIdentifierInfo(), ToAtLoc, | |||
4785 | ToLParenLoc, ToType, | |||
4786 | ToTypeSourceInfo, D->getPropertyImplementation())) | |||
4787 | return ToProperty; | |||
4788 | ||||
4789 | Selector ToGetterName, ToSetterName; | |||
4790 | SourceLocation ToGetterNameLoc, ToSetterNameLoc; | |||
4791 | ObjCMethodDecl *ToGetterMethodDecl, *ToSetterMethodDecl; | |||
4792 | ObjCIvarDecl *ToPropertyIvarDecl; | |||
4793 | if (auto Imp = importSeq( | |||
4794 | D->getGetterName(), D->getSetterName(), | |||
4795 | D->getGetterNameLoc(), D->getSetterNameLoc(), | |||
4796 | D->getGetterMethodDecl(), D->getSetterMethodDecl(), | |||
4797 | D->getPropertyIvarDecl())) | |||
4798 | std::tie( | |||
4799 | ToGetterName, ToSetterName, | |||
4800 | ToGetterNameLoc, ToSetterNameLoc, | |||
4801 | ToGetterMethodDecl, ToSetterMethodDecl, | |||
4802 | ToPropertyIvarDecl) = *Imp; | |||
4803 | else | |||
4804 | return Imp.takeError(); | |||
4805 | ||||
4806 | ToProperty->setLexicalDeclContext(LexicalDC); | |||
4807 | LexicalDC->addDeclInternal(ToProperty); | |||
4808 | ||||
4809 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); | |||
4810 | ToProperty->setPropertyAttributesAsWritten( | |||
4811 | D->getPropertyAttributesAsWritten()); | |||
4812 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); | |||
4813 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); | |||
4814 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); | |||
4815 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); | |||
4816 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); | |||
4817 | return ToProperty; | |||
4818 | } | |||
4819 | ||||
4820 | ExpectedDecl | |||
4821 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { | |||
4822 | ObjCPropertyDecl *Property; | |||
4823 | if (Error Err = importInto(Property, D->getPropertyDecl())) | |||
4824 | return std::move(Err); | |||
4825 | ||||
4826 | DeclContext *DC, *LexicalDC; | |||
4827 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
4828 | return std::move(Err); | |||
4829 | ||||
4830 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); | |||
4831 | ||||
4832 | // Import the ivar (for an @synthesize). | |||
4833 | ObjCIvarDecl *Ivar = nullptr; | |||
4834 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) | |||
4835 | return std::move(Err); | |||
4836 | ||||
4837 | ObjCPropertyImplDecl *ToImpl | |||
4838 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), | |||
4839 | Property->getQueryKind()); | |||
4840 | if (!ToImpl) { | |||
4841 | SourceLocation ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc; | |||
4842 | if (auto Imp = importSeq( | |||
4843 | D->getBeginLoc(), D->getLocation(), D->getPropertyIvarDeclLoc())) | |||
4844 | std::tie(ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc) = *Imp; | |||
4845 | else | |||
4846 | return Imp.takeError(); | |||
4847 | ||||
4848 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, | |||
4849 | ToBeginLoc, | |||
4850 | ToLocation, Property, | |||
4851 | D->getPropertyImplementation(), Ivar, | |||
4852 | ToPropertyIvarDeclLoc)) | |||
4853 | return ToImpl; | |||
4854 | ||||
4855 | ToImpl->setLexicalDeclContext(LexicalDC); | |||
4856 | LexicalDC->addDeclInternal(ToImpl); | |||
4857 | } else { | |||
4858 | // Check that we have the same kind of property implementation (@synthesize | |||
4859 | // vs. @dynamic). | |||
4860 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { | |||
4861 | Importer.ToDiag(ToImpl->getLocation(), | |||
4862 | diag::err_odr_objc_property_impl_kind_inconsistent) | |||
4863 | << Property->getDeclName() | |||
4864 | << (ToImpl->getPropertyImplementation() | |||
4865 | == ObjCPropertyImplDecl::Dynamic); | |||
4866 | Importer.FromDiag(D->getLocation(), | |||
4867 | diag::note_odr_objc_property_impl_kind) | |||
4868 | << D->getPropertyDecl()->getDeclName() | |||
4869 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); | |||
4870 | ||||
4871 | return make_error<ImportError>(ImportError::NameConflict); | |||
4872 | } | |||
4873 | ||||
4874 | // For @synthesize, check that we have the same | |||
4875 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && | |||
4876 | Ivar != ToImpl->getPropertyIvarDecl()) { | |||
4877 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), | |||
4878 | diag::err_odr_objc_synthesize_ivar_inconsistent) | |||
4879 | << Property->getDeclName() | |||
4880 | << ToImpl->getPropertyIvarDecl()->getDeclName() | |||
4881 | << Ivar->getDeclName(); | |||
4882 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), | |||
4883 | diag::note_odr_objc_synthesize_ivar_here) | |||
4884 | << D->getPropertyIvarDecl()->getDeclName(); | |||
4885 | ||||
4886 | return make_error<ImportError>(ImportError::NameConflict); | |||
4887 | } | |||
4888 | ||||
4889 | // Merge the existing implementation with the new implementation. | |||
4890 | Importer.MapImported(D, ToImpl); | |||
4891 | } | |||
4892 | ||||
4893 | return ToImpl; | |||
4894 | } | |||
4895 | ||||
4896 | ExpectedDecl | |||
4897 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { | |||
4898 | // For template arguments, we adopt the translation unit as our declaration | |||
4899 | // context. This context will be fixed when the actual template declaration | |||
4900 | // is created. | |||
4901 | ||||
4902 | // FIXME: Import default argument. | |||
4903 | ||||
4904 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | |||
4905 | if (!BeginLocOrErr) | |||
4906 | return BeginLocOrErr.takeError(); | |||
4907 | ||||
4908 | ExpectedSLoc LocationOrErr = import(D->getLocation()); | |||
4909 | if (!LocationOrErr) | |||
4910 | return LocationOrErr.takeError(); | |||
4911 | ||||
4912 | TemplateTypeParmDecl *ToD = nullptr; | |||
4913 | (void)GetImportedOrCreateDecl( | |||
4914 | ToD, D, Importer.getToContext(), | |||
4915 | Importer.getToContext().getTranslationUnitDecl(), | |||
4916 | *BeginLocOrErr, *LocationOrErr, | |||
4917 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), | |||
4918 | D->wasDeclaredWithTypename(), D->isParameterPack()); | |||
4919 | return ToD; | |||
4920 | } | |||
4921 | ||||
4922 | ExpectedDecl | |||
4923 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { | |||
4924 | DeclarationName ToDeclName; | |||
4925 | SourceLocation ToLocation, ToInnerLocStart; | |||
4926 | QualType ToType; | |||
4927 | TypeSourceInfo *ToTypeSourceInfo; | |||
4928 | if (auto Imp = importSeq( | |||
4929 | D->getDeclName(), D->getLocation(), D->getType(), D->getTypeSourceInfo(), | |||
4930 | D->getInnerLocStart())) | |||
4931 | std::tie( | |||
4932 | ToDeclName, ToLocation, ToType, ToTypeSourceInfo, | |||
4933 | ToInnerLocStart) = *Imp; | |||
4934 | else | |||
4935 | return Imp.takeError(); | |||
4936 | ||||
4937 | // FIXME: Import default argument. | |||
4938 | ||||
4939 | NonTypeTemplateParmDecl *ToD = nullptr; | |||
4940 | (void)GetImportedOrCreateDecl( | |||
4941 | ToD, D, Importer.getToContext(), | |||
4942 | Importer.getToContext().getTranslationUnitDecl(), | |||
4943 | ToInnerLocStart, ToLocation, D->getDepth(), | |||
4944 | D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType, | |||
4945 | D->isParameterPack(), ToTypeSourceInfo); | |||
4946 | return ToD; | |||
4947 | } | |||
4948 | ||||
4949 | ExpectedDecl | |||
4950 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { | |||
4951 | // Import the name of this declaration. | |||
4952 | auto NameOrErr = import(D->getDeclName()); | |||
4953 | if (!NameOrErr) | |||
4954 | return NameOrErr.takeError(); | |||
4955 | ||||
4956 | // Import the location of this declaration. | |||
4957 | ExpectedSLoc LocationOrErr = import(D->getLocation()); | |||
4958 | if (!LocationOrErr) | |||
4959 | return LocationOrErr.takeError(); | |||
4960 | ||||
4961 | // Import template parameters. | |||
4962 | auto TemplateParamsOrErr = ImportTemplateParameterList( | |||
4963 | D->getTemplateParameters()); | |||
4964 | if (!TemplateParamsOrErr) | |||
4965 | return TemplateParamsOrErr.takeError(); | |||
4966 | ||||
4967 | // FIXME: Import default argument. | |||
4968 | ||||
4969 | TemplateTemplateParmDecl *ToD = nullptr; | |||
4970 | (void)GetImportedOrCreateDecl( | |||
4971 | ToD, D, Importer.getToContext(), | |||
4972 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, | |||
4973 | D->getDepth(), D->getPosition(), D->isParameterPack(), | |||
4974 | (*NameOrErr).getAsIdentifierInfo(), | |||
4975 | *TemplateParamsOrErr); | |||
4976 | return ToD; | |||
4977 | } | |||
4978 | ||||
4979 | // Returns the definition for a (forward) declaration of a ClassTemplateDecl, if | |||
4980 | // it has any definition in the redecl chain. | |||
4981 | static ClassTemplateDecl *getDefinition(ClassTemplateDecl *D) { | |||
4982 | CXXRecordDecl *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); | |||
4983 | if (!ToTemplatedDef) | |||
4984 | return nullptr; | |||
4985 | ClassTemplateDecl *TemplateWithDef = | |||
4986 | ToTemplatedDef->getDescribedClassTemplate(); | |||
4987 | return TemplateWithDef; | |||
4988 | } | |||
4989 | ||||
4990 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { | |||
4991 | bool IsFriend = D->getFriendObjectKind() != Decl::FOK_None; | |||
4992 | ||||
4993 | // If this record has a definition in the translation unit we're coming from, | |||
4994 | // but this particular declaration is not that definition, import the | |||
4995 | // definition and map to that. | |||
4996 | auto *Definition = | |||
4997 | cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition()); | |||
4998 | if (Definition && Definition != D->getTemplatedDecl() && !IsFriend) { | |||
4999 | if (ExpectedDecl ImportedDefOrErr = import( | |||
5000 | Definition->getDescribedClassTemplate())) | |||
5001 | return Importer.MapImported(D, *ImportedDefOrErr); | |||
5002 | else | |||
5003 | return ImportedDefOrErr.takeError(); | |||
5004 | } | |||
5005 | ||||
5006 | // Import the major distinguishing characteristics of this class template. | |||
5007 | DeclContext *DC, *LexicalDC; | |||
5008 | DeclarationName Name; | |||
5009 | SourceLocation Loc; | |||
5010 | NamedDecl *ToD; | |||
5011 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
5012 | return std::move(Err); | |||
5013 | if (ToD) | |||
5014 | return ToD; | |||
5015 | ||||
5016 | // We may already have a template of the same name; try to find and match it. | |||
5017 | if (!DC->isFunctionOrMethod()) { | |||
5018 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
5019 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
5020 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
5021 | for (auto *FoundDecl : FoundDecls) { | |||
5022 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) | |||
5023 | continue; | |||
5024 | ||||
5025 | Decl *Found = FoundDecl; | |||
5026 | if (auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found)) { | |||
5027 | ||||
5028 | // The class to be imported is a definition. | |||
5029 | if (D->isThisDeclarationADefinition()) { | |||
5030 | // Lookup will find the fwd decl only if that is more recent than the | |||
5031 | // definition. So, try to get the definition if that is available in | |||
5032 | // the redecl chain. | |||
5033 | ClassTemplateDecl *TemplateWithDef = getDefinition(FoundTemplate); | |||
5034 | if (TemplateWithDef) | |||
5035 | FoundTemplate = TemplateWithDef; | |||
5036 | else | |||
5037 | continue; | |||
5038 | } | |||
5039 | ||||
5040 | if (IsStructuralMatch(D, FoundTemplate)) { | |||
5041 | if (!IsFriend) { | |||
5042 | Importer.MapImported(D->getTemplatedDecl(), | |||
5043 | FoundTemplate->getTemplatedDecl()); | |||
5044 | return Importer.MapImported(D, FoundTemplate); | |||
5045 | } | |||
5046 | ||||
5047 | continue; | |||
5048 | } | |||
5049 | } | |||
5050 | ||||
5051 | ConflictingDecls.push_back(FoundDecl); | |||
5052 | } | |||
5053 | ||||
5054 | if (!ConflictingDecls.empty()) { | |||
5055 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, | |||
5056 | ConflictingDecls.data(), | |||
5057 | ConflictingDecls.size()); | |||
5058 | } | |||
5059 | ||||
5060 | if (!Name) | |||
5061 | return make_error<ImportError>(ImportError::NameConflict); | |||
5062 | } | |||
5063 | ||||
5064 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); | |||
5065 | ||||
5066 | // Create the declaration that is being templated. | |||
5067 | CXXRecordDecl *ToTemplated; | |||
5068 | if (Error Err = importInto(ToTemplated, FromTemplated)) | |||
5069 | return std::move(Err); | |||
5070 | ||||
5071 | // Create the class template declaration itself. | |||
5072 | auto TemplateParamsOrErr = ImportTemplateParameterList( | |||
5073 | D->getTemplateParameters()); | |||
5074 | if (!TemplateParamsOrErr) | |||
5075 | return TemplateParamsOrErr.takeError(); | |||
5076 | ||||
5077 | ClassTemplateDecl *D2; | |||
5078 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, | |||
5079 | *TemplateParamsOrErr, ToTemplated)) | |||
5080 | return D2; | |||
5081 | ||||
5082 | ToTemplated->setDescribedClassTemplate(D2); | |||
5083 | ||||
5084 | if (ToTemplated->getPreviousDecl()) { | |||
5085 | assert(((ToTemplated->getPreviousDecl()->getDescribedClassTemplate () && "Missing described template") ? static_cast< void> (0) : __assert_fail ("ToTemplated->getPreviousDecl()->getDescribedClassTemplate() && \"Missing described template\"" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 5087, __PRETTY_FUNCTION__)) | |||
5086 | ToTemplated->getPreviousDecl()->getDescribedClassTemplate() &&((ToTemplated->getPreviousDecl()->getDescribedClassTemplate () && "Missing described template") ? static_cast< void> (0) : __assert_fail ("ToTemplated->getPreviousDecl()->getDescribedClassTemplate() && \"Missing described template\"" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 5087, __PRETTY_FUNCTION__)) | |||
5087 | "Missing described template")((ToTemplated->getPreviousDecl()->getDescribedClassTemplate () && "Missing described template") ? static_cast< void> (0) : __assert_fail ("ToTemplated->getPreviousDecl()->getDescribedClassTemplate() && \"Missing described template\"" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 5087, __PRETTY_FUNCTION__)); | |||
5088 | D2->setPreviousDecl( | |||
5089 | ToTemplated->getPreviousDecl()->getDescribedClassTemplate()); | |||
5090 | } | |||
5091 | D2->setAccess(D->getAccess()); | |||
5092 | D2->setLexicalDeclContext(LexicalDC); | |||
5093 | if (!IsFriend) | |||
5094 | LexicalDC->addDeclInternal(D2); | |||
5095 | ||||
5096 | if (FromTemplated->isCompleteDefinition() && | |||
5097 | !ToTemplated->isCompleteDefinition()) { | |||
5098 | // FIXME: Import definition! | |||
5099 | } | |||
5100 | ||||
5101 | return D2; | |||
5102 | } | |||
5103 | ||||
5104 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( | |||
5105 | ClassTemplateSpecializationDecl *D) { | |||
5106 | // If this record has a definition in the translation unit we're coming from, | |||
5107 | // but this particular declaration is not that definition, import the | |||
5108 | // definition and map to that. | |||
5109 | TagDecl *Definition = D->getDefinition(); | |||
5110 | if (Definition && Definition != D) { | |||
5111 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | |||
5112 | return Importer.MapImported(D, *ImportedDefOrErr); | |||
5113 | else | |||
5114 | return ImportedDefOrErr.takeError(); | |||
5115 | } | |||
5116 | ||||
5117 | ClassTemplateDecl *ClassTemplate; | |||
5118 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) | |||
5119 | return std::move(Err); | |||
5120 | ||||
5121 | // Import the context of this declaration. | |||
5122 | DeclContext *DC, *LexicalDC; | |||
5123 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
5124 | return std::move(Err); | |||
5125 | ||||
5126 | // Import template arguments. | |||
5127 | SmallVector<TemplateArgument, 2> TemplateArgs; | |||
5128 | if (Error Err = ImportTemplateArguments( | |||
5129 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) | |||
5130 | return std::move(Err); | |||
5131 | ||||
5132 | // Try to find an existing specialization with these template arguments. | |||
5133 | void *InsertPos = nullptr; | |||
5134 | ClassTemplateSpecializationDecl *D2 = nullptr; | |||
5135 | ClassTemplatePartialSpecializationDecl *PartialSpec = | |||
5136 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); | |||
5137 | if (PartialSpec) | |||
5138 | D2 = ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos); | |||
5139 | else | |||
5140 | D2 = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); | |||
5141 | ClassTemplateSpecializationDecl * const PrevDecl = D2; | |||
5142 | RecordDecl *FoundDef = D2 ? D2->getDefinition() : nullptr; | |||
5143 | if (FoundDef) { | |||
5144 | if (!D->isCompleteDefinition()) { | |||
5145 | // The "From" translation unit only had a forward declaration; call it | |||
5146 | // the same declaration. | |||
5147 | // TODO Handle the redecl chain properly! | |||
5148 | return Importer.MapImported(D, FoundDef); | |||
5149 | } | |||
5150 | ||||
5151 | if (IsStructuralMatch(D, FoundDef)) { | |||
5152 | ||||
5153 | Importer.MapImported(D, FoundDef); | |||
5154 | ||||
5155 | // Import those those default field initializers which have been | |||
5156 | // instantiated in the "From" context, but not in the "To" context. | |||
5157 | for (auto *FromField : D->fields()) { | |||
5158 | auto ToOrErr = import(FromField); | |||
5159 | if (!ToOrErr) | |||
5160 | // FIXME: return the error? | |||
5161 | consumeError(ToOrErr.takeError()); | |||
5162 | } | |||
5163 | ||||
5164 | // Import those methods which have been instantiated in the | |||
5165 | // "From" context, but not in the "To" context. | |||
5166 | for (CXXMethodDecl *FromM : D->methods()) { | |||
5167 | auto ToOrErr = import(FromM); | |||
5168 | if (!ToOrErr) | |||
5169 | // FIXME: return the error? | |||
5170 | consumeError(ToOrErr.takeError()); | |||
5171 | } | |||
5172 | ||||
5173 | // TODO Import instantiated default arguments. | |||
5174 | // TODO Import instantiated exception specifications. | |||
5175 | // | |||
5176 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint what | |||
5177 | // else could be fused during an AST merge. | |||
5178 | ||||
5179 | return FoundDef; | |||
5180 | } | |||
5181 | } else { // We either couldn't find any previous specialization in the "To" | |||
5182 | // context, or we found one but without definition. Let's create a | |||
5183 | // new specialization and register that at the class template. | |||
5184 | ||||
5185 | // Import the location of this declaration. | |||
5186 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | |||
5187 | if (!BeginLocOrErr) | |||
5188 | return BeginLocOrErr.takeError(); | |||
5189 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); | |||
5190 | if (!IdLocOrErr) | |||
5191 | return IdLocOrErr.takeError(); | |||
5192 | ||||
5193 | if (PartialSpec) { | |||
5194 | // Import TemplateArgumentListInfo. | |||
5195 | TemplateArgumentListInfo ToTAInfo; | |||
5196 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); | |||
5197 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) | |||
5198 | return std::move(Err); | |||
5199 | ||||
5200 | QualType CanonInjType; | |||
5201 | if (Error Err = importInto( | |||
5202 | CanonInjType, PartialSpec->getInjectedSpecializationType())) | |||
5203 | return std::move(Err); | |||
5204 | CanonInjType = CanonInjType.getCanonicalType(); | |||
5205 | ||||
5206 | auto ToTPListOrErr = ImportTemplateParameterList( | |||
5207 | PartialSpec->getTemplateParameters()); | |||
5208 | if (!ToTPListOrErr) | |||
5209 | return ToTPListOrErr.takeError(); | |||
5210 | ||||
5211 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( | |||
5212 | D2, D, Importer.getToContext(), D->getTagKind(), DC, | |||
5213 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, ClassTemplate, | |||
5214 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), | |||
5215 | ToTAInfo, CanonInjType, | |||
5216 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) | |||
5217 | return D2; | |||
5218 | ||||
5219 | // Update InsertPos, because preceding import calls may have invalidated | |||
5220 | // it by adding new specializations. | |||
5221 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos)) | |||
5222 | // Add this partial specialization to the class template. | |||
5223 | ClassTemplate->AddPartialSpecialization( | |||
5224 | cast<ClassTemplatePartialSpecializationDecl>(D2), InsertPos); | |||
5225 | ||||
5226 | } else { // Not a partial specialization. | |||
5227 | if (GetImportedOrCreateDecl( | |||
5228 | D2, D, Importer.getToContext(), D->getTagKind(), DC, | |||
5229 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, | |||
5230 | PrevDecl)) | |||
5231 | return D2; | |||
5232 | ||||
5233 | // Update InsertPos, because preceding import calls may have invalidated | |||
5234 | // it by adding new specializations. | |||
5235 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) | |||
5236 | // Add this specialization to the class template. | |||
5237 | ClassTemplate->AddSpecialization(D2, InsertPos); | |||
5238 | } | |||
5239 | ||||
5240 | D2->setSpecializationKind(D->getSpecializationKind()); | |||
5241 | ||||
5242 | // Import the qualifier, if any. | |||
5243 | if (auto LocOrErr = import(D->getQualifierLoc())) | |||
5244 | D2->setQualifierInfo(*LocOrErr); | |||
5245 | else | |||
5246 | return LocOrErr.takeError(); | |||
5247 | ||||
5248 | if (auto *TSI = D->getTypeAsWritten()) { | |||
5249 | if (auto TInfoOrErr = import(TSI)) | |||
5250 | D2->setTypeAsWritten(*TInfoOrErr); | |||
5251 | else | |||
5252 | return TInfoOrErr.takeError(); | |||
5253 | ||||
5254 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) | |||
5255 | D2->setTemplateKeywordLoc(*LocOrErr); | |||
5256 | else | |||
5257 | return LocOrErr.takeError(); | |||
5258 | ||||
5259 | if (auto LocOrErr = import(D->getExternLoc())) | |||
5260 | D2->setExternLoc(*LocOrErr); | |||
5261 | else | |||
5262 | return LocOrErr.takeError(); | |||
5263 | } | |||
5264 | ||||
5265 | if (D->getPointOfInstantiation().isValid()) { | |||
5266 | if (auto POIOrErr = import(D->getPointOfInstantiation())) | |||
5267 | D2->setPointOfInstantiation(*POIOrErr); | |||
5268 | else | |||
5269 | return POIOrErr.takeError(); | |||
5270 | } | |||
5271 | ||||
5272 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); | |||
5273 | ||||
5274 | // Set the context of this specialization/instantiation. | |||
5275 | D2->setLexicalDeclContext(LexicalDC); | |||
5276 | ||||
5277 | // Add to the DC only if it was an explicit specialization/instantiation. | |||
5278 | if (D2->isExplicitInstantiationOrSpecialization()) { | |||
5279 | LexicalDC->addDeclInternal(D2); | |||
5280 | } | |||
5281 | } | |||
5282 | if (D->isCompleteDefinition()) | |||
5283 | if (Error Err = ImportDefinition(D, D2)) | |||
5284 | return std::move(Err); | |||
5285 | ||||
5286 | return D2; | |||
5287 | } | |||
5288 | ||||
5289 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { | |||
5290 | // If this variable has a definition in the translation unit we're coming | |||
5291 | // from, | |||
5292 | // but this particular declaration is not that definition, import the | |||
5293 | // definition and map to that. | |||
5294 | auto *Definition = | |||
5295 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); | |||
5296 | if (Definition && Definition != D->getTemplatedDecl()) { | |||
5297 | if (ExpectedDecl ImportedDefOrErr = import( | |||
5298 | Definition->getDescribedVarTemplate())) | |||
5299 | return Importer.MapImported(D, *ImportedDefOrErr); | |||
5300 | else | |||
5301 | return ImportedDefOrErr.takeError(); | |||
5302 | } | |||
5303 | ||||
5304 | // Import the major distinguishing characteristics of this variable template. | |||
5305 | DeclContext *DC, *LexicalDC; | |||
5306 | DeclarationName Name; | |||
5307 | SourceLocation Loc; | |||
5308 | NamedDecl *ToD; | |||
5309 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
5310 | return std::move(Err); | |||
5311 | if (ToD) | |||
5312 | return ToD; | |||
5313 | ||||
5314 | // We may already have a template of the same name; try to find and match it. | |||
5315 | assert(!DC->isFunctionOrMethod() &&((!DC->isFunctionOrMethod() && "Variable templates cannot be declared at function scope" ) ? static_cast<void> (0) : __assert_fail ("!DC->isFunctionOrMethod() && \"Variable templates cannot be declared at function scope\"" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 5316, __PRETTY_FUNCTION__)) | |||
5316 | "Variable templates cannot be declared at function scope")((!DC->isFunctionOrMethod() && "Variable templates cannot be declared at function scope" ) ? static_cast<void> (0) : __assert_fail ("!DC->isFunctionOrMethod() && \"Variable templates cannot be declared at function scope\"" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 5316, __PRETTY_FUNCTION__)); | |||
5317 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
5318 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
5319 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
5320 | for (auto *FoundDecl : FoundDecls) { | |||
5321 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) | |||
5322 | continue; | |||
5323 | ||||
5324 | Decl *Found = FoundDecl; | |||
5325 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { | |||
5326 | if (IsStructuralMatch(D, FoundTemplate)) { | |||
5327 | // The variable templates structurally match; call it the same template. | |||
5328 | Importer.MapImported(D->getTemplatedDecl(), | |||
5329 | FoundTemplate->getTemplatedDecl()); | |||
5330 | return Importer.MapImported(D, FoundTemplate); | |||
5331 | } | |||
5332 | } | |||
5333 | ||||
5334 | ConflictingDecls.push_back(FoundDecl); | |||
5335 | } | |||
5336 | ||||
5337 | if (!ConflictingDecls.empty()) { | |||
5338 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, | |||
5339 | ConflictingDecls.data(), | |||
5340 | ConflictingDecls.size()); | |||
5341 | } | |||
5342 | ||||
5343 | if (!Name) | |||
5344 | // FIXME: Is it possible to get other error than name conflict? | |||
5345 | // (Put this `if` into the previous `if`?) | |||
5346 | return make_error<ImportError>(ImportError::NameConflict); | |||
5347 | ||||
5348 | VarDecl *DTemplated = D->getTemplatedDecl(); | |||
5349 | ||||
5350 | // Import the type. | |||
5351 | // FIXME: Value not used? | |||
5352 | ExpectedType TypeOrErr = import(DTemplated->getType()); | |||
5353 | if (!TypeOrErr) | |||
5354 | return TypeOrErr.takeError(); | |||
5355 | ||||
5356 | // Create the declaration that is being templated. | |||
5357 | VarDecl *ToTemplated; | |||
5358 | if (Error Err = importInto(ToTemplated, DTemplated)) | |||
5359 | return std::move(Err); | |||
5360 | ||||
5361 | // Create the variable template declaration itself. | |||
5362 | auto TemplateParamsOrErr = ImportTemplateParameterList( | |||
5363 | D->getTemplateParameters()); | |||
5364 | if (!TemplateParamsOrErr) | |||
5365 | return TemplateParamsOrErr.takeError(); | |||
5366 | ||||
5367 | VarTemplateDecl *ToVarTD; | |||
5368 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, | |||
5369 | Name, *TemplateParamsOrErr, ToTemplated)) | |||
5370 | return ToVarTD; | |||
5371 | ||||
5372 | ToTemplated->setDescribedVarTemplate(ToVarTD); | |||
5373 | ||||
5374 | ToVarTD->setAccess(D->getAccess()); | |||
5375 | ToVarTD->setLexicalDeclContext(LexicalDC); | |||
5376 | LexicalDC->addDeclInternal(ToVarTD); | |||
5377 | ||||
5378 | if (DTemplated->isThisDeclarationADefinition() && | |||
5379 | !ToTemplated->isThisDeclarationADefinition()) { | |||
5380 | // FIXME: Import definition! | |||
5381 | } | |||
5382 | ||||
5383 | return ToVarTD; | |||
5384 | } | |||
5385 | ||||
5386 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( | |||
5387 | VarTemplateSpecializationDecl *D) { | |||
5388 | // If this record has a definition in the translation unit we're coming from, | |||
5389 | // but this particular declaration is not that definition, import the | |||
5390 | // definition and map to that. | |||
5391 | VarDecl *Definition = D->getDefinition(); | |||
5392 | if (Definition && Definition != D) { | |||
5393 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | |||
5394 | return Importer.MapImported(D, *ImportedDefOrErr); | |||
5395 | else | |||
5396 | return ImportedDefOrErr.takeError(); | |||
5397 | } | |||
5398 | ||||
5399 | VarTemplateDecl *VarTemplate; | |||
5400 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) | |||
5401 | return std::move(Err); | |||
5402 | ||||
5403 | // Import the context of this declaration. | |||
5404 | DeclContext *DC, *LexicalDC; | |||
5405 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
5406 | return std::move(Err); | |||
5407 | ||||
5408 | // Import the location of this declaration. | |||
5409 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | |||
5410 | if (!BeginLocOrErr) | |||
5411 | return BeginLocOrErr.takeError(); | |||
5412 | ||||
5413 | auto IdLocOrErr = import(D->getLocation()); | |||
5414 | if (!IdLocOrErr) | |||
5415 | return IdLocOrErr.takeError(); | |||
5416 | ||||
5417 | // Import template arguments. | |||
5418 | SmallVector<TemplateArgument, 2> TemplateArgs; | |||
5419 | if (Error Err = ImportTemplateArguments( | |||
5420 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) | |||
5421 | return std::move(Err); | |||
5422 | ||||
5423 | // Try to find an existing specialization with these template arguments. | |||
5424 | void *InsertPos = nullptr; | |||
5425 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( | |||
5426 | TemplateArgs, InsertPos); | |||
5427 | if (D2) { | |||
5428 | // We already have a variable template specialization with these template | |||
5429 | // arguments. | |||
5430 | ||||
5431 | // FIXME: Check for specialization vs. instantiation errors. | |||
5432 | ||||
5433 | if (VarDecl *FoundDef = D2->getDefinition()) { | |||
5434 | if (!D->isThisDeclarationADefinition() || | |||
5435 | IsStructuralMatch(D, FoundDef)) { | |||
5436 | // The record types structurally match, or the "from" translation | |||
5437 | // unit only had a forward declaration anyway; call it the same | |||
5438 | // variable. | |||
5439 | return Importer.MapImported(D, FoundDef); | |||
5440 | } | |||
5441 | } | |||
5442 | } else { | |||
5443 | // Import the type. | |||
5444 | QualType T; | |||
5445 | if (Error Err = importInto(T, D->getType())) | |||
5446 | return std::move(Err); | |||
5447 | ||||
5448 | auto TInfoOrErr = import(D->getTypeSourceInfo()); | |||
5449 | if (!TInfoOrErr) | |||
5450 | return TInfoOrErr.takeError(); | |||
5451 | ||||
5452 | TemplateArgumentListInfo ToTAInfo; | |||
5453 | if (Error Err = ImportTemplateArgumentListInfo( | |||
5454 | D->getTemplateArgsInfo(), ToTAInfo)) | |||
5455 | return std::move(Err); | |||
5456 | ||||
5457 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; | |||
5458 | // Create a new specialization. | |||
5459 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { | |||
5460 | // Import TemplateArgumentListInfo | |||
5461 | TemplateArgumentListInfo ArgInfos; | |||
5462 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); | |||
5463 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. | |||
5464 | if (Error Err = ImportTemplateArgumentListInfo( | |||
5465 | *FromTAArgsAsWritten, ArgInfos)) | |||
5466 | return std::move(Err); | |||
5467 | ||||
5468 | auto ToTPListOrErr = ImportTemplateParameterList( | |||
5469 | FromPartial->getTemplateParameters()); | |||
5470 | if (!ToTPListOrErr) | |||
5471 | return ToTPListOrErr.takeError(); | |||
5472 | ||||
5473 | PartVarSpecDecl *ToPartial; | |||
5474 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, | |||
5475 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, | |||
5476 | VarTemplate, T, *TInfoOrErr, | |||
5477 | D->getStorageClass(), TemplateArgs, ArgInfos)) | |||
5478 | return ToPartial; | |||
5479 | ||||
5480 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( | |||
5481 | FromPartial->getInstantiatedFromMember())) | |||
5482 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); | |||
5483 | else | |||
5484 | return ToInstOrErr.takeError(); | |||
5485 | ||||
5486 | if (FromPartial->isMemberSpecialization()) | |||
5487 | ToPartial->setMemberSpecialization(); | |||
5488 | ||||
5489 | D2 = ToPartial; | |||
5490 | ||||
5491 | } else { // Full specialization | |||
5492 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, | |||
5493 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, | |||
5494 | T, *TInfoOrErr, | |||
5495 | D->getStorageClass(), TemplateArgs)) | |||
5496 | return D2; | |||
5497 | } | |||
5498 | ||||
5499 | if (D->getPointOfInstantiation().isValid()) { | |||
5500 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) | |||
5501 | D2->setPointOfInstantiation(*POIOrErr); | |||
5502 | else | |||
5503 | return POIOrErr.takeError(); | |||
5504 | } | |||
5505 | ||||
5506 | D2->setSpecializationKind(D->getSpecializationKind()); | |||
5507 | D2->setTemplateArgsInfo(ToTAInfo); | |||
5508 | ||||
5509 | // Add this specialization to the class template. | |||
5510 | VarTemplate->AddSpecialization(D2, InsertPos); | |||
5511 | ||||
5512 | // Import the qualifier, if any. | |||
5513 | if (auto LocOrErr = import(D->getQualifierLoc())) | |||
5514 | D2->setQualifierInfo(*LocOrErr); | |||
5515 | else | |||
5516 | return LocOrErr.takeError(); | |||
5517 | ||||
5518 | if (D->isConstexpr()) | |||
5519 | D2->setConstexpr(true); | |||
5520 | ||||
5521 | // Add the specialization to this context. | |||
5522 | D2->setLexicalDeclContext(LexicalDC); | |||
5523 | LexicalDC->addDeclInternal(D2); | |||
5524 | ||||
5525 | D2->setAccess(D->getAccess()); | |||
5526 | } | |||
5527 | ||||
5528 | if (Error Err = ImportInitializer(D, D2)) | |||
5529 | return std::move(Err); | |||
5530 | ||||
5531 | return D2; | |||
5532 | } | |||
5533 | ||||
5534 | ExpectedDecl | |||
5535 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { | |||
5536 | DeclContext *DC, *LexicalDC; | |||
5537 | DeclarationName Name; | |||
5538 | SourceLocation Loc; | |||
5539 | NamedDecl *ToD; | |||
5540 | ||||
5541 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
5542 | return std::move(Err); | |||
5543 | ||||
5544 | if (ToD) | |||
5545 | return ToD; | |||
5546 | ||||
5547 | // Try to find a function in our own ("to") context with the same name, same | |||
5548 | // type, and in the same context as the function we're importing. | |||
5549 | if (!LexicalDC->isFunctionOrMethod()) { | |||
5550 | unsigned IDNS = Decl::IDNS_Ordinary; | |||
5551 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
5552 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
5553 | for (auto *FoundDecl : FoundDecls) { | |||
5554 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
5555 | continue; | |||
5556 | ||||
5557 | if (auto *FoundFunction = | |||
5558 | dyn_cast<FunctionTemplateDecl>(FoundDecl)) { | |||
5559 | if (FoundFunction->hasExternalFormalLinkage() && | |||
5560 | D->hasExternalFormalLinkage()) { | |||
5561 | if (IsStructuralMatch(D, FoundFunction)) { | |||
5562 | Importer.MapImported(D, FoundFunction); | |||
5563 | // FIXME: Actually try to merge the body and other attributes. | |||
5564 | return FoundFunction; | |||
5565 | } | |||
5566 | } | |||
5567 | } | |||
5568 | // TODO: handle conflicting names | |||
5569 | } | |||
5570 | } | |||
5571 | ||||
5572 | auto ParamsOrErr = ImportTemplateParameterList( | |||
5573 | D->getTemplateParameters()); | |||
5574 | if (!ParamsOrErr) | |||
5575 | return ParamsOrErr.takeError(); | |||
5576 | ||||
5577 | FunctionDecl *TemplatedFD; | |||
5578 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) | |||
5579 | return std::move(Err); | |||
5580 | ||||
5581 | FunctionTemplateDecl *ToFunc; | |||
5582 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, | |||
5583 | *ParamsOrErr, TemplatedFD)) | |||
5584 | return ToFunc; | |||
5585 | ||||
5586 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); | |||
5587 | ToFunc->setAccess(D->getAccess()); | |||
5588 | ToFunc->setLexicalDeclContext(LexicalDC); | |||
5589 | ||||
5590 | LexicalDC->addDeclInternal(ToFunc); | |||
5591 | return ToFunc; | |||
5592 | } | |||
5593 | ||||
5594 | //---------------------------------------------------------------------------- | |||
5595 | // Import Statements | |||
5596 | //---------------------------------------------------------------------------- | |||
5597 | ||||
5598 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { | |||
5599 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) | |||
5600 | << S->getStmtClassName(); | |||
5601 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
5602 | } | |||
5603 | ||||
5604 | ||||
5605 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { | |||
5606 | SmallVector<IdentifierInfo *, 4> Names; | |||
5607 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { | |||
5608 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); | |||
5609 | // ToII is nullptr when no symbolic name is given for output operand | |||
5610 | // see ParseStmtAsm::ParseAsmOperandsOpt | |||
5611 | Names.push_back(ToII); | |||
5612 | } | |||
5613 | ||||
5614 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { | |||
5615 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); | |||
5616 | // ToII is nullptr when no symbolic name is given for input operand | |||
5617 | // see ParseStmtAsm::ParseAsmOperandsOpt | |||
5618 | Names.push_back(ToII); | |||
5619 | } | |||
5620 | ||||
5621 | SmallVector<StringLiteral *, 4> Clobbers; | |||
5622 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { | |||
5623 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) | |||
5624 | Clobbers.push_back(*ClobberOrErr); | |||
5625 | else | |||
5626 | return ClobberOrErr.takeError(); | |||
5627 | ||||
5628 | } | |||
5629 | ||||
5630 | SmallVector<StringLiteral *, 4> Constraints; | |||
5631 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { | |||
5632 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) | |||
5633 | Constraints.push_back(*OutputOrErr); | |||
5634 | else | |||
5635 | return OutputOrErr.takeError(); | |||
5636 | } | |||
5637 | ||||
5638 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { | |||
5639 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) | |||
5640 | Constraints.push_back(*InputOrErr); | |||
5641 | else | |||
5642 | return InputOrErr.takeError(); | |||
5643 | } | |||
5644 | ||||
5645 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); | |||
5646 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) | |||
5647 | return std::move(Err); | |||
5648 | ||||
5649 | if (Error Err = ImportArrayChecked( | |||
5650 | S->inputs(), Exprs.begin() + S->getNumOutputs())) | |||
5651 | return std::move(Err); | |||
5652 | ||||
5653 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); | |||
5654 | if (!AsmLocOrErr) | |||
5655 | return AsmLocOrErr.takeError(); | |||
5656 | auto AsmStrOrErr = import(S->getAsmString()); | |||
5657 | if (!AsmStrOrErr) | |||
5658 | return AsmStrOrErr.takeError(); | |||
5659 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); | |||
5660 | if (!RParenLocOrErr) | |||
5661 | return RParenLocOrErr.takeError(); | |||
5662 | ||||
5663 | return new (Importer.getToContext()) GCCAsmStmt( | |||
5664 | Importer.getToContext(), | |||
5665 | *AsmLocOrErr, | |||
5666 | S->isSimple(), | |||
5667 | S->isVolatile(), | |||
5668 | S->getNumOutputs(), | |||
5669 | S->getNumInputs(), | |||
5670 | Names.data(), | |||
5671 | Constraints.data(), | |||
5672 | Exprs.data(), | |||
5673 | *AsmStrOrErr, | |||
5674 | S->getNumClobbers(), | |||
5675 | Clobbers.data(), | |||
5676 | *RParenLocOrErr); | |||
5677 | } | |||
5678 | ||||
5679 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { | |||
5680 | auto Imp = importSeq(S->getDeclGroup(), S->getBeginLoc(), S->getEndLoc()); | |||
5681 | if (!Imp) | |||
5682 | return Imp.takeError(); | |||
5683 | ||||
5684 | DeclGroupRef ToDG; | |||
5685 | SourceLocation ToBeginLoc, ToEndLoc; | |||
5686 | std::tie(ToDG, ToBeginLoc, ToEndLoc) = *Imp; | |||
5687 | ||||
5688 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); | |||
5689 | } | |||
5690 | ||||
5691 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { | |||
5692 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); | |||
5693 | if (!ToSemiLocOrErr) | |||
5694 | return ToSemiLocOrErr.takeError(); | |||
5695 | return new (Importer.getToContext()) NullStmt( | |||
5696 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); | |||
5697 | } | |||
5698 | ||||
5699 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { | |||
5700 | SmallVector<Stmt *, 8> ToStmts(S->size()); | |||
5701 | ||||
5702 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) | |||
5703 | return std::move(Err); | |||
5704 | ||||
5705 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); | |||
5706 | if (!ToLBracLocOrErr) | |||
5707 | return ToLBracLocOrErr.takeError(); | |||
5708 | ||||
5709 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); | |||
5710 | if (!ToRBracLocOrErr) | |||
5711 | return ToRBracLocOrErr.takeError(); | |||
5712 | ||||
5713 | return CompoundStmt::Create( | |||
5714 | Importer.getToContext(), ToStmts, | |||
5715 | *ToLBracLocOrErr, *ToRBracLocOrErr); | |||
5716 | } | |||
5717 | ||||
5718 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { | |||
5719 | auto Imp = importSeq( | |||
5720 | S->getLHS(), S->getRHS(), S->getSubStmt(), S->getCaseLoc(), | |||
5721 | S->getEllipsisLoc(), S->getColonLoc()); | |||
5722 | if (!Imp) | |||
5723 | return Imp.takeError(); | |||
5724 | ||||
5725 | Expr *ToLHS, *ToRHS; | |||
5726 | Stmt *ToSubStmt; | |||
5727 | SourceLocation ToCaseLoc, ToEllipsisLoc, ToColonLoc; | |||
5728 | std::tie(ToLHS, ToRHS, ToSubStmt, ToCaseLoc, ToEllipsisLoc, ToColonLoc) = | |||
5729 | *Imp; | |||
5730 | ||||
5731 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, | |||
5732 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); | |||
5733 | ToStmt->setSubStmt(ToSubStmt); | |||
5734 | ||||
5735 | return ToStmt; | |||
5736 | } | |||
5737 | ||||
5738 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { | |||
5739 | auto Imp = importSeq(S->getDefaultLoc(), S->getColonLoc(), S->getSubStmt()); | |||
5740 | if (!Imp) | |||
5741 | return Imp.takeError(); | |||
5742 | ||||
5743 | SourceLocation ToDefaultLoc, ToColonLoc; | |||
5744 | Stmt *ToSubStmt; | |||
5745 | std::tie(ToDefaultLoc, ToColonLoc, ToSubStmt) = *Imp; | |||
5746 | ||||
5747 | return new (Importer.getToContext()) DefaultStmt( | |||
5748 | ToDefaultLoc, ToColonLoc, ToSubStmt); | |||
5749 | } | |||
5750 | ||||
5751 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { | |||
5752 | auto Imp = importSeq(S->getIdentLoc(), S->getDecl(), S->getSubStmt()); | |||
5753 | if (!Imp) | |||
5754 | return Imp.takeError(); | |||
5755 | ||||
5756 | SourceLocation ToIdentLoc; | |||
5757 | LabelDecl *ToLabelDecl; | |||
5758 | Stmt *ToSubStmt; | |||
5759 | std::tie(ToIdentLoc, ToLabelDecl, ToSubStmt) = *Imp; | |||
5760 | ||||
5761 | return new (Importer.getToContext()) LabelStmt( | |||
5762 | ToIdentLoc, ToLabelDecl, ToSubStmt); | |||
5763 | } | |||
5764 | ||||
5765 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { | |||
5766 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); | |||
5767 | if (!ToAttrLocOrErr) | |||
5768 | return ToAttrLocOrErr.takeError(); | |||
5769 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); | |||
5770 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); | |||
5771 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) | |||
5772 | return std::move(Err); | |||
5773 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); | |||
5774 | if (!ToSubStmtOrErr) | |||
5775 | return ToSubStmtOrErr.takeError(); | |||
5776 | ||||
5777 | return AttributedStmt::Create( | |||
5778 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); | |||
5779 | } | |||
5780 | ||||
5781 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { | |||
5782 | auto Imp = importSeq( | |||
5783 | S->getIfLoc(), S->getInit(), S->getConditionVariable(), S->getCond(), | |||
5784 | S->getThen(), S->getElseLoc(), S->getElse()); | |||
5785 | if (!Imp) | |||
5786 | return Imp.takeError(); | |||
5787 | ||||
5788 | SourceLocation ToIfLoc, ToElseLoc; | |||
5789 | Stmt *ToInit, *ToThen, *ToElse; | |||
5790 | VarDecl *ToConditionVariable; | |||
5791 | Expr *ToCond; | |||
5792 | std::tie( | |||
5793 | ToIfLoc, ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, ToElse) = | |||
5794 | *Imp; | |||
5795 | ||||
5796 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), | |||
5797 | ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, | |||
5798 | ToElse); | |||
5799 | } | |||
5800 | ||||
5801 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { | |||
5802 | auto Imp = importSeq( | |||
5803 | S->getInit(), S->getConditionVariable(), S->getCond(), | |||
5804 | S->getBody(), S->getSwitchLoc()); | |||
5805 | if (!Imp) | |||
5806 | return Imp.takeError(); | |||
5807 | ||||
5808 | Stmt *ToInit, *ToBody; | |||
5809 | VarDecl *ToConditionVariable; | |||
5810 | Expr *ToCond; | |||
5811 | SourceLocation ToSwitchLoc; | |||
5812 | std::tie(ToInit, ToConditionVariable, ToCond, ToBody, ToSwitchLoc) = *Imp; | |||
5813 | ||||
5814 | auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit, | |||
5815 | ToConditionVariable, ToCond); | |||
5816 | ToStmt->setBody(ToBody); | |||
5817 | ToStmt->setSwitchLoc(ToSwitchLoc); | |||
5818 | ||||
5819 | // Now we have to re-chain the cases. | |||
5820 | SwitchCase *LastChainedSwitchCase = nullptr; | |||
5821 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; | |||
5822 | SC = SC->getNextSwitchCase()) { | |||
5823 | Expected<SwitchCase *> ToSCOrErr = import(SC); | |||
5824 | if (!ToSCOrErr) | |||
5825 | return ToSCOrErr.takeError(); | |||
5826 | if (LastChainedSwitchCase) | |||
5827 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); | |||
5828 | else | |||
5829 | ToStmt->setSwitchCaseList(*ToSCOrErr); | |||
5830 | LastChainedSwitchCase = *ToSCOrErr; | |||
5831 | } | |||
5832 | ||||
5833 | return ToStmt; | |||
5834 | } | |||
5835 | ||||
5836 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { | |||
5837 | auto Imp = importSeq( | |||
5838 | S->getConditionVariable(), S->getCond(), S->getBody(), S->getWhileLoc()); | |||
5839 | if (!Imp) | |||
5840 | return Imp.takeError(); | |||
5841 | ||||
5842 | VarDecl *ToConditionVariable; | |||
5843 | Expr *ToCond; | |||
5844 | Stmt *ToBody; | |||
5845 | SourceLocation ToWhileLoc; | |||
5846 | std::tie(ToConditionVariable, ToCond, ToBody, ToWhileLoc) = *Imp; | |||
5847 | ||||
5848 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, | |||
5849 | ToBody, ToWhileLoc); | |||
5850 | } | |||
5851 | ||||
5852 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { | |||
5853 | auto Imp = importSeq( | |||
5854 | S->getBody(), S->getCond(), S->getDoLoc(), S->getWhileLoc(), | |||
5855 | S->getRParenLoc()); | |||
5856 | if (!Imp) | |||
5857 | return Imp.takeError(); | |||
5858 | ||||
5859 | Stmt *ToBody; | |||
5860 | Expr *ToCond; | |||
5861 | SourceLocation ToDoLoc, ToWhileLoc, ToRParenLoc; | |||
5862 | std::tie(ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc) = *Imp; | |||
5863 | ||||
5864 | return new (Importer.getToContext()) DoStmt( | |||
5865 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); | |||
5866 | } | |||
5867 | ||||
5868 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { | |||
5869 | auto Imp = importSeq( | |||
5870 | S->getInit(), S->getCond(), S->getConditionVariable(), S->getInc(), | |||
5871 | S->getBody(), S->getForLoc(), S->getLParenLoc(), S->getRParenLoc()); | |||
5872 | if (!Imp) | |||
5873 | return Imp.takeError(); | |||
5874 | ||||
5875 | Stmt *ToInit; | |||
5876 | Expr *ToCond, *ToInc; | |||
5877 | VarDecl *ToConditionVariable; | |||
5878 | Stmt *ToBody; | |||
5879 | SourceLocation ToForLoc, ToLParenLoc, ToRParenLoc; | |||
5880 | std::tie( | |||
5881 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, | |||
5882 | ToLParenLoc, ToRParenLoc) = *Imp; | |||
5883 | ||||
5884 | return new (Importer.getToContext()) ForStmt( | |||
5885 | Importer.getToContext(), | |||
5886 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, | |||
5887 | ToRParenLoc); | |||
5888 | } | |||
5889 | ||||
5890 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { | |||
5891 | auto Imp = importSeq(S->getLabel(), S->getGotoLoc(), S->getLabelLoc()); | |||
5892 | if (!Imp) | |||
5893 | return Imp.takeError(); | |||
5894 | ||||
5895 | LabelDecl *ToLabel; | |||
5896 | SourceLocation ToGotoLoc, ToLabelLoc; | |||
5897 | std::tie(ToLabel, ToGotoLoc, ToLabelLoc) = *Imp; | |||
5898 | ||||
5899 | return new (Importer.getToContext()) GotoStmt( | |||
5900 | ToLabel, ToGotoLoc, ToLabelLoc); | |||
5901 | } | |||
5902 | ||||
5903 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { | |||
5904 | auto Imp = importSeq(S->getGotoLoc(), S->getStarLoc(), S->getTarget()); | |||
5905 | if (!Imp) | |||
5906 | return Imp.takeError(); | |||
5907 | ||||
5908 | SourceLocation ToGotoLoc, ToStarLoc; | |||
5909 | Expr *ToTarget; | |||
5910 | std::tie(ToGotoLoc, ToStarLoc, ToTarget) = *Imp; | |||
5911 | ||||
5912 | return new (Importer.getToContext()) IndirectGotoStmt( | |||
5913 | ToGotoLoc, ToStarLoc, ToTarget); | |||
5914 | } | |||
5915 | ||||
5916 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { | |||
5917 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); | |||
5918 | if (!ToContinueLocOrErr) | |||
5919 | return ToContinueLocOrErr.takeError(); | |||
5920 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); | |||
5921 | } | |||
5922 | ||||
5923 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { | |||
5924 | auto ToBreakLocOrErr = import(S->getBreakLoc()); | |||
5925 | if (!ToBreakLocOrErr) | |||
5926 | return ToBreakLocOrErr.takeError(); | |||
5927 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); | |||
5928 | } | |||
5929 | ||||
5930 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { | |||
5931 | auto Imp = importSeq( | |||
5932 | S->getReturnLoc(), S->getRetValue(), S->getNRVOCandidate()); | |||
5933 | if (!Imp) | |||
5934 | return Imp.takeError(); | |||
5935 | ||||
5936 | SourceLocation ToReturnLoc; | |||
5937 | Expr *ToRetValue; | |||
5938 | const VarDecl *ToNRVOCandidate; | |||
5939 | std::tie(ToReturnLoc, ToRetValue, ToNRVOCandidate) = *Imp; | |||
5940 | ||||
5941 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, | |||
5942 | ToNRVOCandidate); | |||
5943 | } | |||
5944 | ||||
5945 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { | |||
5946 | auto Imp = importSeq( | |||
5947 | S->getCatchLoc(), S->getExceptionDecl(), S->getHandlerBlock()); | |||
5948 | if (!Imp) | |||
5949 | return Imp.takeError(); | |||
5950 | ||||
5951 | SourceLocation ToCatchLoc; | |||
5952 | VarDecl *ToExceptionDecl; | |||
5953 | Stmt *ToHandlerBlock; | |||
5954 | std::tie(ToCatchLoc, ToExceptionDecl, ToHandlerBlock) = *Imp; | |||
5955 | ||||
5956 | return new (Importer.getToContext()) CXXCatchStmt ( | |||
5957 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); | |||
5958 | } | |||
5959 | ||||
5960 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { | |||
5961 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); | |||
5962 | if (!ToTryLocOrErr) | |||
5963 | return ToTryLocOrErr.takeError(); | |||
5964 | ||||
5965 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); | |||
5966 | if (!ToTryBlockOrErr) | |||
5967 | return ToTryBlockOrErr.takeError(); | |||
5968 | ||||
5969 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); | |||
5970 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { | |||
5971 | CXXCatchStmt *FromHandler = S->getHandler(HI); | |||
5972 | if (auto ToHandlerOrErr = import(FromHandler)) | |||
5973 | ToHandlers[HI] = *ToHandlerOrErr; | |||
5974 | else | |||
5975 | return ToHandlerOrErr.takeError(); | |||
5976 | } | |||
5977 | ||||
5978 | return CXXTryStmt::Create( | |||
5979 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); | |||
5980 | } | |||
5981 | ||||
5982 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { | |||
5983 | auto Imp1 = importSeq( | |||
5984 | S->getInit(), S->getRangeStmt(), S->getBeginStmt(), S->getEndStmt(), | |||
5985 | S->getCond(), S->getInc(), S->getLoopVarStmt(), S->getBody()); | |||
5986 | if (!Imp1) | |||
5987 | return Imp1.takeError(); | |||
5988 | auto Imp2 = importSeq( | |||
5989 | S->getForLoc(), S->getCoawaitLoc(), S->getColonLoc(), S->getRParenLoc()); | |||
5990 | if (!Imp2) | |||
5991 | return Imp2.takeError(); | |||
5992 | ||||
5993 | DeclStmt *ToRangeStmt, *ToBeginStmt, *ToEndStmt, *ToLoopVarStmt; | |||
5994 | Expr *ToCond, *ToInc; | |||
5995 | Stmt *ToInit, *ToBody; | |||
5996 | std::tie( | |||
5997 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, | |||
5998 | ToBody) = *Imp1; | |||
5999 | SourceLocation ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc; | |||
6000 | std::tie(ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc) = *Imp2; | |||
6001 | ||||
6002 | return new (Importer.getToContext()) CXXForRangeStmt( | |||
6003 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, | |||
6004 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); | |||
6005 | } | |||
6006 | ||||
6007 | ExpectedStmt | |||
6008 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { | |||
6009 | auto Imp = importSeq( | |||
6010 | S->getElement(), S->getCollection(), S->getBody(), | |||
6011 | S->getForLoc(), S->getRParenLoc()); | |||
6012 | if (!Imp) | |||
6013 | return Imp.takeError(); | |||
6014 | ||||
6015 | Stmt *ToElement, *ToBody; | |||
6016 | Expr *ToCollection; | |||
6017 | SourceLocation ToForLoc, ToRParenLoc; | |||
6018 | std::tie(ToElement, ToCollection, ToBody, ToForLoc, ToRParenLoc) = *Imp; | |||
6019 | ||||
6020 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, | |||
6021 | ToCollection, | |||
6022 | ToBody, | |||
6023 | ToForLoc, | |||
6024 | ToRParenLoc); | |||
6025 | } | |||
6026 | ||||
6027 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { | |||
6028 | auto Imp = importSeq( | |||
6029 | S->getAtCatchLoc(), S->getRParenLoc(), S->getCatchParamDecl(), | |||
6030 | S->getCatchBody()); | |||
6031 | if (!Imp) | |||
6032 | return Imp.takeError(); | |||
6033 | ||||
6034 | SourceLocation ToAtCatchLoc, ToRParenLoc; | |||
6035 | VarDecl *ToCatchParamDecl; | |||
6036 | Stmt *ToCatchBody; | |||
6037 | std::tie(ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody) = *Imp; | |||
6038 | ||||
6039 | return new (Importer.getToContext()) ObjCAtCatchStmt ( | |||
6040 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); | |||
6041 | } | |||
6042 | ||||
6043 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { | |||
6044 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); | |||
6045 | if (!ToAtFinallyLocOrErr) | |||
6046 | return ToAtFinallyLocOrErr.takeError(); | |||
6047 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); | |||
6048 | if (!ToAtFinallyStmtOrErr) | |||
6049 | return ToAtFinallyStmtOrErr.takeError(); | |||
6050 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, | |||
6051 | *ToAtFinallyStmtOrErr); | |||
6052 | } | |||
6053 | ||||
6054 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { | |||
6055 | auto Imp = importSeq( | |||
6056 | S->getAtTryLoc(), S->getTryBody(), S->getFinallyStmt()); | |||
6057 | if (!Imp) | |||
6058 | return Imp.takeError(); | |||
6059 | ||||
6060 | SourceLocation ToAtTryLoc; | |||
6061 | Stmt *ToTryBody, *ToFinallyStmt; | |||
6062 | std::tie(ToAtTryLoc, ToTryBody, ToFinallyStmt) = *Imp; | |||
6063 | ||||
6064 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); | |||
6065 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { | |||
6066 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); | |||
6067 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) | |||
6068 | ToCatchStmts[CI] = *ToCatchStmtOrErr; | |||
6069 | else | |||
6070 | return ToCatchStmtOrErr.takeError(); | |||
6071 | } | |||
6072 | ||||
6073 | return ObjCAtTryStmt::Create(Importer.getToContext(), | |||
6074 | ToAtTryLoc, ToTryBody, | |||
6075 | ToCatchStmts.begin(), ToCatchStmts.size(), | |||
6076 | ToFinallyStmt); | |||
6077 | } | |||
6078 | ||||
6079 | ExpectedStmt ASTNodeImporter::VisitObjCAtSynchronizedStmt | |||
6080 | (ObjCAtSynchronizedStmt *S) { | |||
6081 | auto Imp = importSeq( | |||
6082 | S->getAtSynchronizedLoc(), S->getSynchExpr(), S->getSynchBody()); | |||
6083 | if (!Imp) | |||
6084 | return Imp.takeError(); | |||
6085 | ||||
6086 | SourceLocation ToAtSynchronizedLoc; | |||
6087 | Expr *ToSynchExpr; | |||
6088 | Stmt *ToSynchBody; | |||
6089 | std::tie(ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody) = *Imp; | |||
6090 | ||||
6091 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( | |||
6092 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); | |||
6093 | } | |||
6094 | ||||
6095 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { | |||
6096 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); | |||
6097 | if (!ToThrowLocOrErr) | |||
6098 | return ToThrowLocOrErr.takeError(); | |||
6099 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); | |||
6100 | if (!ToThrowExprOrErr) | |||
6101 | return ToThrowExprOrErr.takeError(); | |||
6102 | return new (Importer.getToContext()) ObjCAtThrowStmt( | |||
6103 | *ToThrowLocOrErr, *ToThrowExprOrErr); | |||
6104 | } | |||
6105 | ||||
6106 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( | |||
6107 | ObjCAutoreleasePoolStmt *S) { | |||
6108 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); | |||
6109 | if (!ToAtLocOrErr) | |||
6110 | return ToAtLocOrErr.takeError(); | |||
6111 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); | |||
6112 | if (!ToSubStmtOrErr) | |||
6113 | return ToSubStmtOrErr.takeError(); | |||
6114 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, | |||
6115 | *ToSubStmtOrErr); | |||
6116 | } | |||
6117 | ||||
6118 | //---------------------------------------------------------------------------- | |||
6119 | // Import Expressions | |||
6120 | //---------------------------------------------------------------------------- | |||
6121 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { | |||
6122 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) | |||
6123 | << E->getStmtClassName(); | |||
6124 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
6125 | } | |||
6126 | ||||
6127 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { | |||
6128 | auto Imp = importSeq( | |||
6129 | E->getBuiltinLoc(), E->getSubExpr(), E->getWrittenTypeInfo(), | |||
6130 | E->getRParenLoc(), E->getType()); | |||
6131 | if (!Imp) | |||
6132 | return Imp.takeError(); | |||
6133 | ||||
6134 | SourceLocation ToBuiltinLoc, ToRParenLoc; | |||
6135 | Expr *ToSubExpr; | |||
6136 | TypeSourceInfo *ToWrittenTypeInfo; | |||
6137 | QualType ToType; | |||
6138 | std::tie(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType) = | |||
6139 | *Imp; | |||
6140 | ||||
6141 | return new (Importer.getToContext()) VAArgExpr( | |||
6142 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, | |||
6143 | E->isMicrosoftABI()); | |||
6144 | } | |||
6145 | ||||
6146 | ||||
6147 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { | |||
6148 | ExpectedType TypeOrErr = import(E->getType()); | |||
6149 | if (!TypeOrErr) | |||
6150 | return TypeOrErr.takeError(); | |||
6151 | ||||
6152 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); | |||
6153 | if (!BeginLocOrErr) | |||
6154 | return BeginLocOrErr.takeError(); | |||
6155 | ||||
6156 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); | |||
6157 | } | |||
6158 | ||||
6159 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { | |||
6160 | auto Imp = importSeq( | |||
6161 | E->getBeginLoc(), E->getType(), E->getFunctionName()); | |||
6162 | if (!Imp) | |||
6163 | return Imp.takeError(); | |||
6164 | ||||
6165 | SourceLocation ToBeginLoc; | |||
6166 | QualType ToType; | |||
6167 | StringLiteral *ToFunctionName; | |||
6168 | std::tie(ToBeginLoc, ToType, ToFunctionName) = *Imp; | |||
6169 | ||||
6170 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, | |||
6171 | E->getIdentKind(), ToFunctionName); | |||
6172 | } | |||
6173 | ||||
6174 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { | |||
6175 | auto Imp = importSeq( | |||
6176 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDecl(), | |||
6177 | E->getLocation(), E->getType()); | |||
6178 | if (!Imp) | |||
6179 | return Imp.takeError(); | |||
6180 | ||||
6181 | NestedNameSpecifierLoc ToQualifierLoc; | |||
6182 | SourceLocation ToTemplateKeywordLoc, ToLocation; | |||
6183 | ValueDecl *ToDecl; | |||
6184 | QualType ToType; | |||
6185 | std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, ToLocation, ToType) = | |||
6186 | *Imp; | |||
6187 | ||||
6188 | NamedDecl *ToFoundD = nullptr; | |||
6189 | if (E->getDecl() != E->getFoundDecl()) { | |||
6190 | auto FoundDOrErr = import(E->getFoundDecl()); | |||
6191 | if (!FoundDOrErr) | |||
6192 | return FoundDOrErr.takeError(); | |||
6193 | ToFoundD = *FoundDOrErr; | |||
6194 | } | |||
6195 | ||||
6196 | TemplateArgumentListInfo ToTAInfo; | |||
6197 | TemplateArgumentListInfo *ToResInfo = nullptr; | |||
6198 | if (E->hasExplicitTemplateArgs()) { | |||
6199 | if (Error Err = | |||
6200 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) | |||
6201 | return std::move(Err); | |||
6202 | ToResInfo = &ToTAInfo; | |||
6203 | } | |||
6204 | ||||
6205 | auto *ToE = DeclRefExpr::Create( | |||
6206 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, | |||
6207 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, | |||
6208 | E->getValueKind(), ToFoundD, ToResInfo); | |||
6209 | if (E->hadMultipleCandidates()) | |||
6210 | ToE->setHadMultipleCandidates(true); | |||
6211 | return ToE; | |||
6212 | } | |||
6213 | ||||
6214 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { | |||
6215 | ExpectedType TypeOrErr = import(E->getType()); | |||
6216 | if (!TypeOrErr) | |||
6217 | return TypeOrErr.takeError(); | |||
6218 | ||||
6219 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); | |||
6220 | } | |||
6221 | ||||
6222 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { | |||
6223 | ExpectedExpr ToInitOrErr = import(E->getInit()); | |||
6224 | if (!ToInitOrErr) | |||
6225 | return ToInitOrErr.takeError(); | |||
6226 | ||||
6227 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); | |||
6228 | if (!ToEqualOrColonLocOrErr) | |||
6229 | return ToEqualOrColonLocOrErr.takeError(); | |||
6230 | ||||
6231 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); | |||
6232 | // List elements from the second, the first is Init itself | |||
6233 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { | |||
6234 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) | |||
6235 | ToIndexExprs[I - 1] = *ToArgOrErr; | |||
6236 | else | |||
6237 | return ToArgOrErr.takeError(); | |||
6238 | } | |||
6239 | ||||
6240 | SmallVector<Designator, 4> ToDesignators(E->size()); | |||
6241 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) | |||
6242 | return std::move(Err); | |||
6243 | ||||
6244 | return DesignatedInitExpr::Create( | |||
6245 | Importer.getToContext(), ToDesignators, | |||
6246 | ToIndexExprs, *ToEqualOrColonLocOrErr, | |||
6247 | E->usesGNUSyntax(), *ToInitOrErr); | |||
6248 | } | |||
6249 | ||||
6250 | ExpectedStmt | |||
6251 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { | |||
6252 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
6253 | if (!ToTypeOrErr) | |||
6254 | return ToTypeOrErr.takeError(); | |||
6255 | ||||
6256 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | |||
6257 | if (!ToLocationOrErr) | |||
6258 | return ToLocationOrErr.takeError(); | |||
6259 | ||||
6260 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( | |||
6261 | *ToTypeOrErr, *ToLocationOrErr); | |||
6262 | } | |||
6263 | ||||
6264 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { | |||
6265 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
6266 | if (!ToTypeOrErr) | |||
6267 | return ToTypeOrErr.takeError(); | |||
6268 | ||||
6269 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | |||
6270 | if (!ToLocationOrErr) | |||
6271 | return ToLocationOrErr.takeError(); | |||
6272 | ||||
6273 | return IntegerLiteral::Create( | |||
6274 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); | |||
6275 | } | |||
6276 | ||||
6277 | ||||
6278 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { | |||
6279 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
6280 | if (!ToTypeOrErr) | |||
6281 | return ToTypeOrErr.takeError(); | |||
6282 | ||||
6283 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | |||
6284 | if (!ToLocationOrErr) | |||
6285 | return ToLocationOrErr.takeError(); | |||
6286 | ||||
6287 | return FloatingLiteral::Create( | |||
6288 | Importer.getToContext(), E->getValue(), E->isExact(), | |||
6289 | *ToTypeOrErr, *ToLocationOrErr); | |||
6290 | } | |||
6291 | ||||
6292 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { | |||
6293 | auto ToTypeOrErr = import(E->getType()); | |||
6294 | if (!ToTypeOrErr) | |||
6295 | return ToTypeOrErr.takeError(); | |||
6296 | ||||
6297 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | |||
6298 | if (!ToSubExprOrErr) | |||
6299 | return ToSubExprOrErr.takeError(); | |||
6300 | ||||
6301 | return new (Importer.getToContext()) ImaginaryLiteral( | |||
6302 | *ToSubExprOrErr, *ToTypeOrErr); | |||
6303 | } | |||
6304 | ||||
6305 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { | |||
6306 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
6307 | if (!ToTypeOrErr) | |||
6308 | return ToTypeOrErr.takeError(); | |||
6309 | ||||
6310 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | |||
6311 | if (!ToLocationOrErr) | |||
6312 | return ToLocationOrErr.takeError(); | |||
6313 | ||||
6314 | return new (Importer.getToContext()) CharacterLiteral( | |||
6315 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); | |||
6316 | } | |||
6317 | ||||
6318 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { | |||
6319 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
6320 | if (!ToTypeOrErr) | |||
6321 | return ToTypeOrErr.takeError(); | |||
6322 | ||||
6323 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); | |||
6324 | if (Error Err = ImportArrayChecked( | |||
6325 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) | |||
6326 | return std::move(Err); | |||
6327 | ||||
6328 | return StringLiteral::Create( | |||
6329 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), | |||
6330 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); | |||
6331 | } | |||
6332 | ||||
6333 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { | |||
6334 | auto Imp = importSeq( | |||
6335 | E->getLParenLoc(), E->getTypeSourceInfo(), E->getType(), | |||
6336 | E->getInitializer()); | |||
6337 | if (!Imp) | |||
6338 | return Imp.takeError(); | |||
6339 | ||||
6340 | SourceLocation ToLParenLoc; | |||
6341 | TypeSourceInfo *ToTypeSourceInfo; | |||
6342 | QualType ToType; | |||
6343 | Expr *ToInitializer; | |||
6344 | std::tie(ToLParenLoc, ToTypeSourceInfo, ToType, ToInitializer) = *Imp; | |||
6345 | ||||
6346 | return new (Importer.getToContext()) CompoundLiteralExpr( | |||
6347 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), | |||
6348 | ToInitializer, E->isFileScope()); | |||
6349 | } | |||
6350 | ||||
6351 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { | |||
6352 | auto Imp = importSeq( | |||
6353 | E->getBuiltinLoc(), E->getType(), E->getRParenLoc()); | |||
6354 | if (!Imp) | |||
6355 | return Imp.takeError(); | |||
6356 | ||||
6357 | SourceLocation ToBuiltinLoc, ToRParenLoc; | |||
6358 | QualType ToType; | |||
6359 | std::tie(ToBuiltinLoc, ToType, ToRParenLoc) = *Imp; | |||
6360 | ||||
6361 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); | |||
6362 | if (Error Err = ImportArrayChecked( | |||
6363 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), | |||
6364 | ToExprs.begin())) | |||
6365 | return std::move(Err); | |||
6366 | ||||
6367 | return new (Importer.getToContext()) AtomicExpr( | |||
6368 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); | |||
6369 | } | |||
6370 | ||||
6371 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { | |||
6372 | auto Imp = importSeq( | |||
6373 | E->getAmpAmpLoc(), E->getLabelLoc(), E->getLabel(), E->getType()); | |||
6374 | if (!Imp) | |||
6375 | return Imp.takeError(); | |||
6376 | ||||
6377 | SourceLocation ToAmpAmpLoc, ToLabelLoc; | |||
6378 | LabelDecl *ToLabel; | |||
6379 | QualType ToType; | |||
6380 | std::tie(ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType) = *Imp; | |||
6381 | ||||
6382 | return new (Importer.getToContext()) AddrLabelExpr( | |||
6383 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); | |||
6384 | } | |||
6385 | ||||
6386 | ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { | |||
6387 | auto Imp = importSeq(E->getSubExpr()); | |||
6388 | if (!Imp) | |||
6389 | return Imp.takeError(); | |||
6390 | ||||
6391 | Expr *ToSubExpr; | |||
6392 | std::tie(ToSubExpr) = *Imp; | |||
6393 | ||||
6394 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr); | |||
6395 | } | |||
6396 | ||||
6397 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { | |||
6398 | auto Imp = importSeq(E->getLParen(), E->getRParen(), E->getSubExpr()); | |||
6399 | if (!Imp) | |||
6400 | return Imp.takeError(); | |||
6401 | ||||
6402 | SourceLocation ToLParen, ToRParen; | |||
6403 | Expr *ToSubExpr; | |||
6404 | std::tie(ToLParen, ToRParen, ToSubExpr) = *Imp; | |||
6405 | ||||
6406 | return new (Importer.getToContext()) | |||
6407 | ParenExpr(ToLParen, ToRParen, ToSubExpr); | |||
6408 | } | |||
6409 | ||||
6410 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { | |||
6411 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); | |||
6412 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) | |||
6413 | return std::move(Err); | |||
6414 | ||||
6415 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); | |||
6416 | if (!ToLParenLocOrErr) | |||
6417 | return ToLParenLocOrErr.takeError(); | |||
6418 | ||||
6419 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); | |||
6420 | if (!ToRParenLocOrErr) | |||
6421 | return ToRParenLocOrErr.takeError(); | |||
6422 | ||||
6423 | return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr, | |||
6424 | ToExprs, *ToRParenLocOrErr); | |||
6425 | } | |||
6426 | ||||
6427 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { | |||
6428 | auto Imp = importSeq( | |||
6429 | E->getSubStmt(), E->getType(), E->getLParenLoc(), E->getRParenLoc()); | |||
6430 | if (!Imp) | |||
6431 | return Imp.takeError(); | |||
6432 | ||||
6433 | CompoundStmt *ToSubStmt; | |||
6434 | QualType ToType; | |||
6435 | SourceLocation ToLParenLoc, ToRParenLoc; | |||
6436 | std::tie(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc) = *Imp; | |||
6437 | ||||
6438 | return new (Importer.getToContext()) StmtExpr( | |||
6439 | ToSubStmt, ToType, ToLParenLoc, ToRParenLoc); | |||
6440 | } | |||
6441 | ||||
6442 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { | |||
6443 | auto Imp = importSeq( | |||
6444 | E->getSubExpr(), E->getType(), E->getOperatorLoc()); | |||
6445 | if (!Imp) | |||
6446 | return Imp.takeError(); | |||
6447 | ||||
6448 | Expr *ToSubExpr; | |||
6449 | QualType ToType; | |||
6450 | SourceLocation ToOperatorLoc; | |||
6451 | std::tie(ToSubExpr, ToType, ToOperatorLoc) = *Imp; | |||
6452 | ||||
6453 | return new (Importer.getToContext()) UnaryOperator( | |||
6454 | ToSubExpr, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(), | |||
6455 | ToOperatorLoc, E->canOverflow()); | |||
6456 | } | |||
6457 | ||||
6458 | ExpectedStmt | |||
6459 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { | |||
6460 | auto Imp = importSeq(E->getType(), E->getOperatorLoc(), E->getRParenLoc()); | |||
6461 | if (!Imp) | |||
6462 | return Imp.takeError(); | |||
6463 | ||||
6464 | QualType ToType; | |||
6465 | SourceLocation ToOperatorLoc, ToRParenLoc; | |||
6466 | std::tie(ToType, ToOperatorLoc, ToRParenLoc) = *Imp; | |||
6467 | ||||
6468 | if (E->isArgumentType()) { | |||
6469 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = | |||
6470 | import(E->getArgumentTypeInfo()); | |||
6471 | if (!ToArgumentTypeInfoOrErr) | |||
6472 | return ToArgumentTypeInfoOrErr.takeError(); | |||
6473 | ||||
6474 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( | |||
6475 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, | |||
6476 | ToRParenLoc); | |||
6477 | } | |||
6478 | ||||
6479 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); | |||
6480 | if (!ToArgumentExprOrErr) | |||
6481 | return ToArgumentExprOrErr.takeError(); | |||
6482 | ||||
6483 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( | |||
6484 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); | |||
6485 | } | |||
6486 | ||||
6487 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { | |||
6488 | auto Imp = importSeq( | |||
6489 | E->getLHS(), E->getRHS(), E->getType(), E->getOperatorLoc()); | |||
6490 | if (!Imp) | |||
6491 | return Imp.takeError(); | |||
6492 | ||||
6493 | Expr *ToLHS, *ToRHS; | |||
6494 | QualType ToType; | |||
6495 | SourceLocation ToOperatorLoc; | |||
6496 | std::tie(ToLHS, ToRHS, ToType, ToOperatorLoc) = *Imp; | |||
6497 | ||||
6498 | return new (Importer.getToContext()) BinaryOperator( | |||
6499 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), | |||
6500 | E->getObjectKind(), ToOperatorLoc, E->getFPFeatures()); | |||
6501 | } | |||
6502 | ||||
6503 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { | |||
6504 | auto Imp = importSeq( | |||
6505 | E->getCond(), E->getQuestionLoc(), E->getLHS(), E->getColonLoc(), | |||
6506 | E->getRHS(), E->getType()); | |||
6507 | if (!Imp) | |||
6508 | return Imp.takeError(); | |||
6509 | ||||
6510 | Expr *ToCond, *ToLHS, *ToRHS; | |||
6511 | SourceLocation ToQuestionLoc, ToColonLoc; | |||
6512 | QualType ToType; | |||
6513 | std::tie(ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType) = *Imp; | |||
6514 | ||||
6515 | return new (Importer.getToContext()) ConditionalOperator( | |||
6516 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, | |||
6517 | E->getValueKind(), E->getObjectKind()); | |||
6518 | } | |||
6519 | ||||
6520 | ExpectedStmt ASTNodeImporter::VisitBinaryConditionalOperator( | |||
6521 | BinaryConditionalOperator *E) { | |||
6522 | auto Imp = importSeq( | |||
6523 | E->getCommon(), E->getOpaqueValue(), E->getCond(), E->getTrueExpr(), | |||
6524 | E->getFalseExpr(), E->getQuestionLoc(), E->getColonLoc(), E->getType()); | |||
6525 | if (!Imp) | |||
6526 | return Imp.takeError(); | |||
6527 | ||||
6528 | Expr *ToCommon, *ToCond, *ToTrueExpr, *ToFalseExpr; | |||
6529 | OpaqueValueExpr *ToOpaqueValue; | |||
6530 | SourceLocation ToQuestionLoc, ToColonLoc; | |||
6531 | QualType ToType; | |||
6532 | std::tie( | |||
6533 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, ToQuestionLoc, | |||
6534 | ToColonLoc, ToType) = *Imp; | |||
6535 | ||||
6536 | return new (Importer.getToContext()) BinaryConditionalOperator( | |||
6537 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, | |||
6538 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), | |||
6539 | E->getObjectKind()); | |||
6540 | } | |||
6541 | ||||
6542 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { | |||
6543 | auto Imp = importSeq( | |||
6544 | E->getBeginLoc(), E->getQueriedTypeSourceInfo(), | |||
6545 | E->getDimensionExpression(), E->getEndLoc(), E->getType()); | |||
6546 | if (!Imp) | |||
6547 | return Imp.takeError(); | |||
6548 | ||||
6549 | SourceLocation ToBeginLoc, ToEndLoc; | |||
6550 | TypeSourceInfo *ToQueriedTypeSourceInfo; | |||
6551 | Expr *ToDimensionExpression; | |||
6552 | QualType ToType; | |||
6553 | std::tie( | |||
6554 | ToBeginLoc, ToQueriedTypeSourceInfo, ToDimensionExpression, ToEndLoc, | |||
6555 | ToType) = *Imp; | |||
6556 | ||||
6557 | return new (Importer.getToContext()) ArrayTypeTraitExpr( | |||
6558 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), | |||
6559 | ToDimensionExpression, ToEndLoc, ToType); | |||
6560 | } | |||
6561 | ||||
6562 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { | |||
6563 | auto Imp = importSeq( | |||
6564 | E->getBeginLoc(), E->getQueriedExpression(), E->getEndLoc(), E->getType()); | |||
6565 | if (!Imp) | |||
6566 | return Imp.takeError(); | |||
6567 | ||||
6568 | SourceLocation ToBeginLoc, ToEndLoc; | |||
6569 | Expr *ToQueriedExpression; | |||
6570 | QualType ToType; | |||
6571 | std::tie(ToBeginLoc, ToQueriedExpression, ToEndLoc, ToType) = *Imp; | |||
6572 | ||||
6573 | return new (Importer.getToContext()) ExpressionTraitExpr( | |||
6574 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), | |||
6575 | ToEndLoc, ToType); | |||
6576 | } | |||
6577 | ||||
6578 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { | |||
6579 | auto Imp = importSeq( | |||
6580 | E->getLocation(), E->getType(), E->getSourceExpr()); | |||
6581 | if (!Imp) | |||
6582 | return Imp.takeError(); | |||
6583 | ||||
6584 | SourceLocation ToLocation; | |||
6585 | QualType ToType; | |||
6586 | Expr *ToSourceExpr; | |||
6587 | std::tie(ToLocation, ToType, ToSourceExpr) = *Imp; | |||
6588 | ||||
6589 | return new (Importer.getToContext()) OpaqueValueExpr( | |||
6590 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); | |||
6591 | } | |||
6592 | ||||
6593 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { | |||
6594 | auto Imp = importSeq( | |||
6595 | E->getLHS(), E->getRHS(), E->getType(), E->getRBracketLoc()); | |||
6596 | if (!Imp) | |||
6597 | return Imp.takeError(); | |||
6598 | ||||
6599 | Expr *ToLHS, *ToRHS; | |||
6600 | SourceLocation ToRBracketLoc; | |||
6601 | QualType ToType; | |||
6602 | std::tie(ToLHS, ToRHS, ToType, ToRBracketLoc) = *Imp; | |||
6603 | ||||
6604 | return new (Importer.getToContext()) ArraySubscriptExpr( | |||
6605 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), | |||
6606 | ToRBracketLoc); | |||
6607 | } | |||
6608 | ||||
6609 | ExpectedStmt | |||
6610 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { | |||
6611 | auto Imp = importSeq( | |||
6612 | E->getLHS(), E->getRHS(), E->getType(), E->getComputationLHSType(), | |||
6613 | E->getComputationResultType(), E->getOperatorLoc()); | |||
6614 | if (!Imp) | |||
6615 | return Imp.takeError(); | |||
6616 | ||||
6617 | Expr *ToLHS, *ToRHS; | |||
6618 | QualType ToType, ToComputationLHSType, ToComputationResultType; | |||
6619 | SourceLocation ToOperatorLoc; | |||
6620 | std::tie(ToLHS, ToRHS, ToType, ToComputationLHSType, ToComputationResultType, | |||
6621 | ToOperatorLoc) = *Imp; | |||
6622 | ||||
6623 | return new (Importer.getToContext()) CompoundAssignOperator( | |||
6624 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), | |||
6625 | E->getObjectKind(), ToComputationLHSType, ToComputationResultType, | |||
6626 | ToOperatorLoc, E->getFPFeatures()); | |||
6627 | } | |||
6628 | ||||
6629 | Expected<CXXCastPath> | |||
6630 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { | |||
6631 | CXXCastPath Path; | |||
6632 | for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) { | |||
6633 | if (auto SpecOrErr = import(*I)) | |||
6634 | Path.push_back(*SpecOrErr); | |||
6635 | else | |||
6636 | return SpecOrErr.takeError(); | |||
6637 | } | |||
6638 | return Path; | |||
6639 | } | |||
6640 | ||||
6641 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { | |||
6642 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
6643 | if (!ToTypeOrErr) | |||
6644 | return ToTypeOrErr.takeError(); | |||
6645 | ||||
6646 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | |||
6647 | if (!ToSubExprOrErr) | |||
6648 | return ToSubExprOrErr.takeError(); | |||
6649 | ||||
6650 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); | |||
6651 | if (!ToBasePathOrErr) | |||
6652 | return ToBasePathOrErr.takeError(); | |||
6653 | ||||
6654 | return ImplicitCastExpr::Create( | |||
6655 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, | |||
6656 | &(*ToBasePathOrErr), E->getValueKind()); | |||
6657 | } | |||
6658 | ||||
6659 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { | |||
6660 | auto Imp1 = importSeq( | |||
6661 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten()); | |||
6662 | if (!Imp1) | |||
6663 | return Imp1.takeError(); | |||
6664 | ||||
6665 | QualType ToType; | |||
6666 | Expr *ToSubExpr; | |||
6667 | TypeSourceInfo *ToTypeInfoAsWritten; | |||
6668 | std::tie(ToType, ToSubExpr, ToTypeInfoAsWritten) = *Imp1; | |||
6669 | ||||
6670 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); | |||
6671 | if (!ToBasePathOrErr) | |||
6672 | return ToBasePathOrErr.takeError(); | |||
6673 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); | |||
6674 | ||||
6675 | switch (E->getStmtClass()) { | |||
6676 | case Stmt::CStyleCastExprClass: { | |||
6677 | auto *CCE = cast<CStyleCastExpr>(E); | |||
6678 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); | |||
6679 | if (!ToLParenLocOrErr) | |||
6680 | return ToLParenLocOrErr.takeError(); | |||
6681 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); | |||
6682 | if (!ToRParenLocOrErr) | |||
6683 | return ToRParenLocOrErr.takeError(); | |||
6684 | return CStyleCastExpr::Create( | |||
6685 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), | |||
6686 | ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr, | |||
6687 | *ToRParenLocOrErr); | |||
6688 | } | |||
6689 | ||||
6690 | case Stmt::CXXFunctionalCastExprClass: { | |||
6691 | auto *FCE = cast<CXXFunctionalCastExpr>(E); | |||
6692 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); | |||
6693 | if (!ToLParenLocOrErr) | |||
6694 | return ToLParenLocOrErr.takeError(); | |||
6695 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); | |||
6696 | if (!ToRParenLocOrErr) | |||
6697 | return ToRParenLocOrErr.takeError(); | |||
6698 | return CXXFunctionalCastExpr::Create( | |||
6699 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, | |||
6700 | E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr, | |||
6701 | *ToRParenLocOrErr); | |||
6702 | } | |||
6703 | ||||
6704 | case Stmt::ObjCBridgedCastExprClass: { | |||
6705 | auto *OCE = cast<ObjCBridgedCastExpr>(E); | |||
6706 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); | |||
6707 | if (!ToLParenLocOrErr) | |||
6708 | return ToLParenLocOrErr.takeError(); | |||
6709 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); | |||
6710 | if (!ToBridgeKeywordLocOrErr) | |||
6711 | return ToBridgeKeywordLocOrErr.takeError(); | |||
6712 | return new (Importer.getToContext()) ObjCBridgedCastExpr( | |||
6713 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), | |||
6714 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); | |||
6715 | } | |||
6716 | default: | |||
6717 | llvm_unreachable("Cast expression of unsupported type!")::llvm::llvm_unreachable_internal("Cast expression of unsupported type!" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 6717); | |||
6718 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
6719 | } | |||
6720 | } | |||
6721 | ||||
6722 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { | |||
6723 | SmallVector<OffsetOfNode, 4> ToNodes; | |||
6724 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { | |||
6725 | const OffsetOfNode &FromNode = E->getComponent(I); | |||
6726 | ||||
6727 | SourceLocation ToBeginLoc, ToEndLoc; | |||
6728 | if (FromNode.getKind() != OffsetOfNode::Base) { | |||
6729 | auto Imp = importSeq(FromNode.getBeginLoc(), FromNode.getEndLoc()); | |||
6730 | if (!Imp) | |||
6731 | return Imp.takeError(); | |||
6732 | std::tie(ToBeginLoc, ToEndLoc) = *Imp; | |||
6733 | } | |||
6734 | ||||
6735 | switch (FromNode.getKind()) { | |||
6736 | case OffsetOfNode::Array: | |||
6737 | ToNodes.push_back( | |||
6738 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); | |||
6739 | break; | |||
6740 | case OffsetOfNode::Base: { | |||
6741 | auto ToBSOrErr = import(FromNode.getBase()); | |||
6742 | if (!ToBSOrErr) | |||
6743 | return ToBSOrErr.takeError(); | |||
6744 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); | |||
6745 | break; | |||
6746 | } | |||
6747 | case OffsetOfNode::Field: { | |||
6748 | auto ToFieldOrErr = import(FromNode.getField()); | |||
6749 | if (!ToFieldOrErr) | |||
6750 | return ToFieldOrErr.takeError(); | |||
6751 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); | |||
6752 | break; | |||
6753 | } | |||
6754 | case OffsetOfNode::Identifier: { | |||
6755 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); | |||
6756 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); | |||
6757 | break; | |||
6758 | } | |||
6759 | } | |||
6760 | } | |||
6761 | ||||
6762 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); | |||
6763 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { | |||
6764 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); | |||
6765 | if (!ToIndexExprOrErr) | |||
6766 | return ToIndexExprOrErr.takeError(); | |||
6767 | ToExprs[I] = *ToIndexExprOrErr; | |||
6768 | } | |||
6769 | ||||
6770 | auto Imp = importSeq( | |||
6771 | E->getType(), E->getTypeSourceInfo(), E->getOperatorLoc(), | |||
6772 | E->getRParenLoc()); | |||
6773 | if (!Imp) | |||
6774 | return Imp.takeError(); | |||
6775 | ||||
6776 | QualType ToType; | |||
6777 | TypeSourceInfo *ToTypeSourceInfo; | |||
6778 | SourceLocation ToOperatorLoc, ToRParenLoc; | |||
6779 | std::tie(ToType, ToTypeSourceInfo, ToOperatorLoc, ToRParenLoc) = *Imp; | |||
6780 | ||||
6781 | return OffsetOfExpr::Create( | |||
6782 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, | |||
6783 | ToExprs, ToRParenLoc); | |||
6784 | } | |||
6785 | ||||
6786 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { | |||
6787 | auto Imp = importSeq( | |||
6788 | E->getType(), E->getOperand(), E->getBeginLoc(), E->getEndLoc()); | |||
6789 | if (!Imp) | |||
6790 | return Imp.takeError(); | |||
6791 | ||||
6792 | QualType ToType; | |||
6793 | Expr *ToOperand; | |||
6794 | SourceLocation ToBeginLoc, ToEndLoc; | |||
6795 | std::tie(ToType, ToOperand, ToBeginLoc, ToEndLoc) = *Imp; | |||
6796 | ||||
6797 | CanThrowResult ToCanThrow; | |||
6798 | if (E->isValueDependent()) | |||
6799 | ToCanThrow = CT_Dependent; | |||
6800 | else | |||
6801 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; | |||
6802 | ||||
6803 | return new (Importer.getToContext()) CXXNoexceptExpr( | |||
6804 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); | |||
6805 | } | |||
6806 | ||||
6807 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { | |||
6808 | auto Imp = importSeq(E->getSubExpr(), E->getType(), E->getThrowLoc()); | |||
6809 | if (!Imp) | |||
6810 | return Imp.takeError(); | |||
6811 | ||||
6812 | Expr *ToSubExpr; | |||
6813 | QualType ToType; | |||
6814 | SourceLocation ToThrowLoc; | |||
6815 | std::tie(ToSubExpr, ToType, ToThrowLoc) = *Imp; | |||
6816 | ||||
6817 | return new (Importer.getToContext()) CXXThrowExpr( | |||
6818 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); | |||
6819 | } | |||
6820 | ||||
6821 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { | |||
6822 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); | |||
6823 | if (!ToUsedLocOrErr) | |||
6824 | return ToUsedLocOrErr.takeError(); | |||
6825 | ||||
6826 | auto ToParamOrErr = import(E->getParam()); | |||
6827 | if (!ToParamOrErr) | |||
6828 | return ToParamOrErr.takeError(); | |||
6829 | ||||
6830 | return CXXDefaultArgExpr::Create( | |||
6831 | Importer.getToContext(), *ToUsedLocOrErr, *ToParamOrErr); | |||
6832 | } | |||
6833 | ||||
6834 | ExpectedStmt | |||
6835 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { | |||
6836 | auto Imp = importSeq( | |||
6837 | E->getType(), E->getTypeSourceInfo(), E->getRParenLoc()); | |||
6838 | if (!Imp) | |||
6839 | return Imp.takeError(); | |||
6840 | ||||
6841 | QualType ToType; | |||
6842 | TypeSourceInfo *ToTypeSourceInfo; | |||
6843 | SourceLocation ToRParenLoc; | |||
6844 | std::tie(ToType, ToTypeSourceInfo, ToRParenLoc) = *Imp; | |||
6845 | ||||
6846 | return new (Importer.getToContext()) CXXScalarValueInitExpr( | |||
6847 | ToType, ToTypeSourceInfo, ToRParenLoc); | |||
6848 | } | |||
6849 | ||||
6850 | ExpectedStmt | |||
6851 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { | |||
6852 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | |||
6853 | if (!ToSubExprOrErr) | |||
6854 | return ToSubExprOrErr.takeError(); | |||
6855 | ||||
6856 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); | |||
6857 | if (!ToDtorOrErr) | |||
6858 | return ToDtorOrErr.takeError(); | |||
6859 | ||||
6860 | ASTContext &ToCtx = Importer.getToContext(); | |||
6861 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); | |||
6862 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); | |||
6863 | } | |||
6864 | ||||
6865 | ExpectedStmt | |||
6866 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { | |||
6867 | auto Imp = importSeq( | |||
6868 | E->getConstructor(), E->getType(), E->getTypeSourceInfo(), | |||
6869 | E->getParenOrBraceRange()); | |||
6870 | if (!Imp) | |||
6871 | return Imp.takeError(); | |||
6872 | ||||
6873 | CXXConstructorDecl *ToConstructor; | |||
6874 | QualType ToType; | |||
6875 | TypeSourceInfo *ToTypeSourceInfo; | |||
6876 | SourceRange ToParenOrBraceRange; | |||
6877 | std::tie(ToConstructor, ToType, ToTypeSourceInfo, ToParenOrBraceRange) = *Imp; | |||
6878 | ||||
6879 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); | |||
6880 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | |||
6881 | return std::move(Err); | |||
6882 | ||||
6883 | return new (Importer.getToContext()) CXXTemporaryObjectExpr( | |||
6884 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, | |||
6885 | ToParenOrBraceRange, E->hadMultipleCandidates(), | |||
6886 | E->isListInitialization(), E->isStdInitListInitialization(), | |||
6887 | E->requiresZeroInitialization()); | |||
6888 | } | |||
6889 | ||||
6890 | ExpectedStmt | |||
6891 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { | |||
6892 | auto Imp = importSeq( | |||
6893 | E->getType(), E->GetTemporaryExpr(), E->getExtendingDecl()); | |||
6894 | if (!Imp) | |||
6895 | return Imp.takeError(); | |||
6896 | ||||
6897 | QualType ToType; | |||
6898 | Expr *ToTemporaryExpr; | |||
6899 | const ValueDecl *ToExtendingDecl; | |||
6900 | std::tie(ToType, ToTemporaryExpr, ToExtendingDecl) = *Imp; | |||
6901 | ||||
6902 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( | |||
6903 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference()); | |||
6904 | ||||
6905 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? | |||
6906 | ToMTE->setExtendingDecl(ToExtendingDecl, E->getManglingNumber()); | |||
6907 | return ToMTE; | |||
6908 | } | |||
6909 | ||||
6910 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { | |||
6911 | auto Imp = importSeq( | |||
6912 | E->getType(), E->getPattern(), E->getEllipsisLoc()); | |||
6913 | if (!Imp) | |||
6914 | return Imp.takeError(); | |||
6915 | ||||
6916 | QualType ToType; | |||
6917 | Expr *ToPattern; | |||
6918 | SourceLocation ToEllipsisLoc; | |||
6919 | std::tie(ToType, ToPattern, ToEllipsisLoc) = *Imp; | |||
6920 | ||||
6921 | return new (Importer.getToContext()) PackExpansionExpr( | |||
6922 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); | |||
6923 | } | |||
6924 | ||||
6925 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { | |||
6926 | auto Imp = importSeq( | |||
6927 | E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc()); | |||
6928 | if (!Imp) | |||
6929 | return Imp.takeError(); | |||
6930 | ||||
6931 | SourceLocation ToOperatorLoc, ToPackLoc, ToRParenLoc; | |||
6932 | NamedDecl *ToPack; | |||
6933 | std::tie(ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc) = *Imp; | |||
6934 | ||||
6935 | Optional<unsigned> Length; | |||
6936 | if (!E->isValueDependent()) | |||
6937 | Length = E->getPackLength(); | |||
6938 | ||||
6939 | SmallVector<TemplateArgument, 8> ToPartialArguments; | |||
6940 | if (E->isPartiallySubstituted()) { | |||
6941 | if (Error Err = ImportTemplateArguments( | |||
6942 | E->getPartialArguments().data(), | |||
6943 | E->getPartialArguments().size(), | |||
6944 | ToPartialArguments)) | |||
6945 | return std::move(Err); | |||
6946 | } | |||
6947 | ||||
6948 | return SizeOfPackExpr::Create( | |||
6949 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, | |||
6950 | Length, ToPartialArguments); | |||
6951 | } | |||
6952 | ||||
6953 | ||||
6954 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { | |||
6955 | auto Imp = importSeq( | |||
6956 | E->getOperatorNew(), E->getOperatorDelete(), E->getTypeIdParens(), | |||
6957 | E->getArraySize(), E->getInitializer(), E->getType(), | |||
6958 | E->getAllocatedTypeSourceInfo(), E->getSourceRange(), | |||
6959 | E->getDirectInitRange()); | |||
6960 | if (!Imp) | |||
6961 | return Imp.takeError(); | |||
6962 | ||||
6963 | FunctionDecl *ToOperatorNew, *ToOperatorDelete; | |||
6964 | SourceRange ToTypeIdParens, ToSourceRange, ToDirectInitRange; | |||
6965 | Expr *ToArraySize, *ToInitializer; | |||
6966 | QualType ToType; | |||
6967 | TypeSourceInfo *ToAllocatedTypeSourceInfo; | |||
6968 | std::tie( | |||
6969 | ToOperatorNew, ToOperatorDelete, ToTypeIdParens, ToArraySize, ToInitializer, | |||
6970 | ToType, ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange) = *Imp; | |||
6971 | ||||
6972 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); | |||
6973 | if (Error Err = | |||
6974 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) | |||
6975 | return std::move(Err); | |||
6976 | ||||
6977 | return new (Importer.getToContext()) CXXNewExpr( | |||
6978 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, | |||
6979 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), | |||
6980 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), | |||
6981 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, | |||
6982 | ToDirectInitRange); | |||
6983 | } | |||
6984 | ||||
6985 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { | |||
6986 | auto Imp = importSeq( | |||
6987 | E->getType(), E->getOperatorDelete(), E->getArgument(), E->getBeginLoc()); | |||
6988 | if (!Imp) | |||
6989 | return Imp.takeError(); | |||
6990 | ||||
6991 | QualType ToType; | |||
6992 | FunctionDecl *ToOperatorDelete; | |||
6993 | Expr *ToArgument; | |||
6994 | SourceLocation ToBeginLoc; | |||
6995 | std::tie(ToType, ToOperatorDelete, ToArgument, ToBeginLoc) = *Imp; | |||
6996 | ||||
6997 | return new (Importer.getToContext()) CXXDeleteExpr( | |||
6998 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), | |||
6999 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, | |||
7000 | ToBeginLoc); | |||
7001 | } | |||
7002 | ||||
7003 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { | |||
7004 | auto Imp = importSeq( | |||
7005 | E->getType(), E->getLocation(), E->getConstructor(), | |||
7006 | E->getParenOrBraceRange()); | |||
7007 | if (!Imp) | |||
7008 | return Imp.takeError(); | |||
7009 | ||||
7010 | QualType ToType; | |||
7011 | SourceLocation ToLocation; | |||
7012 | CXXConstructorDecl *ToConstructor; | |||
7013 | SourceRange ToParenOrBraceRange; | |||
7014 | std::tie(ToType, ToLocation, ToConstructor, ToParenOrBraceRange) = *Imp; | |||
7015 | ||||
7016 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); | |||
7017 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | |||
7018 | return std::move(Err); | |||
7019 | ||||
7020 | return CXXConstructExpr::Create( | |||
7021 | Importer.getToContext(), ToType, ToLocation, ToConstructor, | |||
7022 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), | |||
7023 | E->isListInitialization(), E->isStdInitListInitialization(), | |||
7024 | E->requiresZeroInitialization(), E->getConstructionKind(), | |||
7025 | ToParenOrBraceRange); | |||
7026 | } | |||
7027 | ||||
7028 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { | |||
7029 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | |||
7030 | if (!ToSubExprOrErr) | |||
7031 | return ToSubExprOrErr.takeError(); | |||
7032 | ||||
7033 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); | |||
7034 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) | |||
7035 | return std::move(Err); | |||
7036 | ||||
7037 | return ExprWithCleanups::Create( | |||
7038 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), | |||
7039 | ToObjects); | |||
7040 | } | |||
7041 | ||||
7042 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { | |||
7043 | auto Imp = importSeq( | |||
7044 | E->getCallee(), E->getType(), E->getRParenLoc()); | |||
7045 | if (!Imp) | |||
7046 | return Imp.takeError(); | |||
7047 | ||||
7048 | Expr *ToCallee; | |||
7049 | QualType ToType; | |||
7050 | SourceLocation ToRParenLoc; | |||
7051 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; | |||
7052 | ||||
7053 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); | |||
7054 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | |||
7055 | return std::move(Err); | |||
7056 | ||||
7057 | return new (Importer.getToContext()) CXXMemberCallExpr( | |||
7058 | Importer.getToContext(), ToCallee, ToArgs, ToType, E->getValueKind(), | |||
7059 | ToRParenLoc); | |||
7060 | } | |||
7061 | ||||
7062 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { | |||
7063 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
7064 | if (!ToTypeOrErr) | |||
7065 | return ToTypeOrErr.takeError(); | |||
7066 | ||||
7067 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | |||
7068 | if (!ToLocationOrErr) | |||
7069 | return ToLocationOrErr.takeError(); | |||
7070 | ||||
7071 | return new (Importer.getToContext()) CXXThisExpr( | |||
7072 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); | |||
7073 | } | |||
7074 | ||||
7075 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { | |||
7076 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
7077 | if (!ToTypeOrErr) | |||
7078 | return ToTypeOrErr.takeError(); | |||
7079 | ||||
7080 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | |||
7081 | if (!ToLocationOrErr) | |||
7082 | return ToLocationOrErr.takeError(); | |||
7083 | ||||
7084 | return new (Importer.getToContext()) CXXBoolLiteralExpr( | |||
7085 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); | |||
7086 | } | |||
7087 | ||||
7088 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { | |||
7089 | auto Imp1 = importSeq( | |||
7090 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), | |||
7091 | E->getTemplateKeywordLoc(), E->getMemberDecl(), E->getType()); | |||
7092 | if (!Imp1) | |||
7093 | return Imp1.takeError(); | |||
7094 | ||||
7095 | Expr *ToBase; | |||
7096 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; | |||
7097 | NestedNameSpecifierLoc ToQualifierLoc; | |||
7098 | ValueDecl *ToMemberDecl; | |||
7099 | QualType ToType; | |||
7100 | std::tie( | |||
7101 | ToBase, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, | |||
7102 | ToType) = *Imp1; | |||
7103 | ||||
7104 | auto Imp2 = importSeq( | |||
7105 | E->getFoundDecl().getDecl(), E->getMemberNameInfo().getName(), | |||
7106 | E->getMemberNameInfo().getLoc(), E->getLAngleLoc(), E->getRAngleLoc()); | |||
7107 | if (!Imp2) | |||
7108 | return Imp2.takeError(); | |||
7109 | NamedDecl *ToDecl; | |||
7110 | DeclarationName ToName; | |||
7111 | SourceLocation ToLoc, ToLAngleLoc, ToRAngleLoc; | |||
7112 | std::tie(ToDecl, ToName, ToLoc, ToLAngleLoc, ToRAngleLoc) = *Imp2; | |||
7113 | ||||
7114 | DeclAccessPair ToFoundDecl = | |||
7115 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); | |||
7116 | ||||
7117 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); | |||
7118 | ||||
7119 | if (E->hasExplicitTemplateArgs()) { | |||
7120 | // FIXME: handle template arguments | |||
7121 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
7122 | } | |||
7123 | ||||
7124 | return MemberExpr::Create( | |||
7125 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, | |||
7126 | ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, ToFoundDecl, | |||
7127 | ToMemberNameInfo, nullptr, ToType, E->getValueKind(), E->getObjectKind()); | |||
7128 | } | |||
7129 | ||||
7130 | ExpectedStmt | |||
7131 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { | |||
7132 | auto Imp = importSeq( | |||
7133 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), | |||
7134 | E->getScopeTypeInfo(), E->getColonColonLoc(), E->getTildeLoc()); | |||
7135 | if (!Imp) | |||
7136 | return Imp.takeError(); | |||
7137 | ||||
7138 | Expr *ToBase; | |||
7139 | SourceLocation ToOperatorLoc, ToColonColonLoc, ToTildeLoc; | |||
7140 | NestedNameSpecifierLoc ToQualifierLoc; | |||
7141 | TypeSourceInfo *ToScopeTypeInfo; | |||
7142 | std::tie( | |||
7143 | ToBase, ToOperatorLoc, ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, | |||
7144 | ToTildeLoc) = *Imp; | |||
7145 | ||||
7146 | PseudoDestructorTypeStorage Storage; | |||
7147 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { | |||
7148 | IdentifierInfo *ToII = Importer.Import(FromII); | |||
7149 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); | |||
7150 | if (!ToDestroyedTypeLocOrErr) | |||
7151 | return ToDestroyedTypeLocOrErr.takeError(); | |||
7152 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); | |||
7153 | } else { | |||
7154 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) | |||
7155 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); | |||
7156 | else | |||
7157 | return ToTIOrErr.takeError(); | |||
7158 | } | |||
7159 | ||||
7160 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( | |||
7161 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, | |||
7162 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); | |||
7163 | } | |||
7164 | ||||
7165 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( | |||
7166 | CXXDependentScopeMemberExpr *E) { | |||
7167 | auto Imp = importSeq( | |||
7168 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), | |||
7169 | E->getTemplateKeywordLoc(), E->getFirstQualifierFoundInScope()); | |||
7170 | if (!Imp) | |||
7171 | return Imp.takeError(); | |||
7172 | ||||
7173 | QualType ToType; | |||
7174 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; | |||
7175 | NestedNameSpecifierLoc ToQualifierLoc; | |||
7176 | NamedDecl *ToFirstQualifierFoundInScope; | |||
7177 | std::tie( | |||
7178 | ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, | |||
7179 | ToFirstQualifierFoundInScope) = *Imp; | |||
7180 | ||||
7181 | Expr *ToBase = nullptr; | |||
7182 | if (!E->isImplicitAccess()) { | |||
7183 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) | |||
7184 | ToBase = *ToBaseOrErr; | |||
7185 | else | |||
7186 | return ToBaseOrErr.takeError(); | |||
7187 | } | |||
7188 | ||||
7189 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; | |||
7190 | if (E->hasExplicitTemplateArgs()) { | |||
7191 | if (Error Err = ImportTemplateArgumentListInfo( | |||
7192 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), | |||
7193 | ToTAInfo)) | |||
7194 | return std::move(Err); | |||
7195 | ResInfo = &ToTAInfo; | |||
7196 | } | |||
7197 | ||||
7198 | auto ToMemberNameInfoOrErr = importSeq(E->getMember(), E->getMemberLoc()); | |||
7199 | if (!ToMemberNameInfoOrErr) | |||
7200 | return ToMemberNameInfoOrErr.takeError(); | |||
7201 | DeclarationNameInfo ToMemberNameInfo( | |||
7202 | std::get<0>(*ToMemberNameInfoOrErr), std::get<1>(*ToMemberNameInfoOrErr)); | |||
7203 | // Import additional name location/type info. | |||
7204 | if (Error Err = ImportDeclarationNameLoc( | |||
7205 | E->getMemberNameInfo(), ToMemberNameInfo)) | |||
7206 | return std::move(Err); | |||
7207 | ||||
7208 | return CXXDependentScopeMemberExpr::Create( | |||
7209 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, | |||
7210 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, | |||
7211 | ToMemberNameInfo, ResInfo); | |||
7212 | } | |||
7213 | ||||
7214 | ExpectedStmt | |||
7215 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { | |||
7216 | auto Imp = importSeq( | |||
7217 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDeclName(), | |||
7218 | E->getExprLoc(), E->getLAngleLoc(), E->getRAngleLoc()); | |||
7219 | if (!Imp) | |||
7220 | return Imp.takeError(); | |||
7221 | ||||
7222 | NestedNameSpecifierLoc ToQualifierLoc; | |||
7223 | SourceLocation ToTemplateKeywordLoc, ToExprLoc, ToLAngleLoc, ToRAngleLoc; | |||
7224 | DeclarationName ToDeclName; | |||
7225 | std::tie( | |||
7226 | ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToExprLoc, | |||
7227 | ToLAngleLoc, ToRAngleLoc) = *Imp; | |||
7228 | ||||
7229 | DeclarationNameInfo ToNameInfo(ToDeclName, ToExprLoc); | |||
7230 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | |||
7231 | return std::move(Err); | |||
7232 | ||||
7233 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); | |||
7234 | TemplateArgumentListInfo *ResInfo = nullptr; | |||
7235 | if (E->hasExplicitTemplateArgs()) { | |||
7236 | if (Error Err = | |||
7237 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) | |||
7238 | return std::move(Err); | |||
7239 | ResInfo = &ToTAInfo; | |||
7240 | } | |||
7241 | ||||
7242 | return DependentScopeDeclRefExpr::Create( | |||
7243 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, | |||
7244 | ToNameInfo, ResInfo); | |||
7245 | } | |||
7246 | ||||
7247 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( | |||
7248 | CXXUnresolvedConstructExpr *E) { | |||
7249 | auto Imp = importSeq( | |||
7250 | E->getLParenLoc(), E->getRParenLoc(), E->getTypeSourceInfo()); | |||
7251 | if (!Imp) | |||
7252 | return Imp.takeError(); | |||
7253 | ||||
7254 | SourceLocation ToLParenLoc, ToRParenLoc; | |||
7255 | TypeSourceInfo *ToTypeSourceInfo; | |||
7256 | std::tie(ToLParenLoc, ToRParenLoc, ToTypeSourceInfo) = *Imp; | |||
7257 | ||||
7258 | SmallVector<Expr *, 8> ToArgs(E->arg_size()); | |||
7259 | if (Error Err = | |||
7260 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) | |||
7261 | return std::move(Err); | |||
7262 | ||||
7263 | return CXXUnresolvedConstructExpr::Create( | |||
7264 | Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc, | |||
7265 | llvm::makeArrayRef(ToArgs), ToRParenLoc); | |||
7266 | } | |||
7267 | ||||
7268 | ExpectedStmt | |||
7269 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { | |||
7270 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); | |||
7271 | if (!ToNamingClassOrErr) | |||
7272 | return ToNamingClassOrErr.takeError(); | |||
7273 | ||||
7274 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); | |||
7275 | if (!ToQualifierLocOrErr) | |||
7276 | return ToQualifierLocOrErr.takeError(); | |||
7277 | ||||
7278 | auto ToNameInfoOrErr = importSeq(E->getName(), E->getNameLoc()); | |||
7279 | if (!ToNameInfoOrErr) | |||
7280 | return ToNameInfoOrErr.takeError(); | |||
7281 | DeclarationNameInfo ToNameInfo( | |||
7282 | std::get<0>(*ToNameInfoOrErr), std::get<1>(*ToNameInfoOrErr)); | |||
7283 | // Import additional name location/type info. | |||
7284 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | |||
7285 | return std::move(Err); | |||
7286 | ||||
7287 | UnresolvedSet<8> ToDecls; | |||
7288 | for (auto *D : E->decls()) | |||
7289 | if (auto ToDOrErr = import(D)) | |||
7290 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); | |||
7291 | else | |||
7292 | return ToDOrErr.takeError(); | |||
7293 | ||||
7294 | if (E->hasExplicitTemplateArgs() && E->getTemplateKeywordLoc().isValid()) { | |||
7295 | TemplateArgumentListInfo ToTAInfo; | |||
7296 | if (Error Err = ImportTemplateArgumentListInfo( | |||
7297 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), | |||
7298 | ToTAInfo)) | |||
7299 | return std::move(Err); | |||
7300 | ||||
7301 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); | |||
7302 | if (!ToTemplateKeywordLocOrErr) | |||
7303 | return ToTemplateKeywordLocOrErr.takeError(); | |||
7304 | ||||
7305 | return UnresolvedLookupExpr::Create( | |||
7306 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, | |||
7307 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, | |||
7308 | ToDecls.begin(), ToDecls.end()); | |||
7309 | } | |||
7310 | ||||
7311 | return UnresolvedLookupExpr::Create( | |||
7312 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, | |||
7313 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), | |||
7314 | ToDecls.end()); | |||
7315 | } | |||
7316 | ||||
7317 | ExpectedStmt | |||
7318 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { | |||
7319 | auto Imp1 = importSeq( | |||
7320 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), | |||
7321 | E->getTemplateKeywordLoc()); | |||
7322 | if (!Imp1) | |||
7323 | return Imp1.takeError(); | |||
7324 | ||||
7325 | QualType ToType; | |||
7326 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; | |||
7327 | NestedNameSpecifierLoc ToQualifierLoc; | |||
7328 | std::tie(ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc) = *Imp1; | |||
7329 | ||||
7330 | auto Imp2 = importSeq(E->getName(), E->getNameLoc()); | |||
7331 | if (!Imp2) | |||
7332 | return Imp2.takeError(); | |||
7333 | DeclarationNameInfo ToNameInfo(std::get<0>(*Imp2), std::get<1>(*Imp2)); | |||
7334 | // Import additional name location/type info. | |||
7335 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | |||
7336 | return std::move(Err); | |||
7337 | ||||
7338 | UnresolvedSet<8> ToDecls; | |||
7339 | for (Decl *D : E->decls()) | |||
7340 | if (auto ToDOrErr = import(D)) | |||
7341 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); | |||
7342 | else | |||
7343 | return ToDOrErr.takeError(); | |||
7344 | ||||
7345 | TemplateArgumentListInfo ToTAInfo; | |||
7346 | TemplateArgumentListInfo *ResInfo = nullptr; | |||
7347 | if (E->hasExplicitTemplateArgs()) { | |||
7348 | if (Error Err = | |||
7349 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) | |||
7350 | return std::move(Err); | |||
7351 | ResInfo = &ToTAInfo; | |||
7352 | } | |||
7353 | ||||
7354 | Expr *ToBase = nullptr; | |||
7355 | if (!E->isImplicitAccess()) { | |||
7356 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) | |||
7357 | ToBase = *ToBaseOrErr; | |||
7358 | else | |||
7359 | return ToBaseOrErr.takeError(); | |||
7360 | } | |||
7361 | ||||
7362 | return UnresolvedMemberExpr::Create( | |||
7363 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, | |||
7364 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, | |||
7365 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); | |||
7366 | } | |||
7367 | ||||
7368 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { | |||
7369 | auto Imp = importSeq(E->getCallee(), E->getType(), E->getRParenLoc()); | |||
7370 | if (!Imp) | |||
7371 | return Imp.takeError(); | |||
7372 | ||||
7373 | Expr *ToCallee; | |||
7374 | QualType ToType; | |||
7375 | SourceLocation ToRParenLoc; | |||
7376 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; | |||
7377 | ||||
7378 | unsigned NumArgs = E->getNumArgs(); | |||
7379 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); | |||
7380 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | |||
7381 | return std::move(Err); | |||
7382 | ||||
7383 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { | |||
7384 | return new (Importer.getToContext()) CXXOperatorCallExpr( | |||
7385 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, | |||
7386 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(), | |||
7387 | OCE->getADLCallKind()); | |||
7388 | } | |||
7389 | ||||
7390 | return new (Importer.getToContext()) CallExpr( | |||
7391 | Importer.getToContext(), ToCallee, ToArgs, ToType, E->getValueKind(), | |||
7392 | ToRParenLoc, /*MinNumArgs=*/0, E->getADLCallKind()); | |||
7393 | } | |||
7394 | ||||
7395 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { | |||
7396 | CXXRecordDecl *FromClass = E->getLambdaClass(); | |||
7397 | auto ToClassOrErr = import(FromClass); | |||
7398 | if (!ToClassOrErr) | |||
7399 | return ToClassOrErr.takeError(); | |||
7400 | CXXRecordDecl *ToClass = *ToClassOrErr; | |||
7401 | ||||
7402 | // NOTE: lambda classes are created with BeingDefined flag set up. | |||
7403 | // It means that ImportDefinition doesn't work for them and we should fill it | |||
7404 | // manually. | |||
7405 | if (ToClass->isBeingDefined()) { | |||
7406 | for (auto FromField : FromClass->fields()) { | |||
7407 | auto ToFieldOrErr = import(FromField); | |||
7408 | if (!ToFieldOrErr) | |||
7409 | return ToFieldOrErr.takeError(); | |||
7410 | } | |||
7411 | } | |||
7412 | ||||
7413 | auto ToCallOpOrErr = import(E->getCallOperator()); | |||
7414 | if (!ToCallOpOrErr) | |||
7415 | return ToCallOpOrErr.takeError(); | |||
7416 | ||||
7417 | ToClass->completeDefinition(); | |||
7418 | ||||
7419 | SmallVector<LambdaCapture, 8> ToCaptures; | |||
7420 | ToCaptures.reserve(E->capture_size()); | |||
7421 | for (const auto &FromCapture : E->captures()) { | |||
7422 | if (auto ToCaptureOrErr = import(FromCapture)) | |||
7423 | ToCaptures.push_back(*ToCaptureOrErr); | |||
7424 | else | |||
7425 | return ToCaptureOrErr.takeError(); | |||
7426 | } | |||
7427 | ||||
7428 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); | |||
7429 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) | |||
7430 | return std::move(Err); | |||
7431 | ||||
7432 | auto Imp = importSeq( | |||
7433 | E->getIntroducerRange(), E->getCaptureDefaultLoc(), E->getEndLoc()); | |||
7434 | if (!Imp) | |||
7435 | return Imp.takeError(); | |||
7436 | ||||
7437 | SourceRange ToIntroducerRange; | |||
7438 | SourceLocation ToCaptureDefaultLoc, ToEndLoc; | |||
7439 | std::tie(ToIntroducerRange, ToCaptureDefaultLoc, ToEndLoc) = *Imp; | |||
7440 | ||||
7441 | return LambdaExpr::Create( | |||
7442 | Importer.getToContext(), ToClass, ToIntroducerRange, | |||
7443 | E->getCaptureDefault(), ToCaptureDefaultLoc, ToCaptures, | |||
7444 | E->hasExplicitParameters(), E->hasExplicitResultType(), ToCaptureInits, | |||
7445 | ToEndLoc, E->containsUnexpandedParameterPack()); | |||
7446 | } | |||
7447 | ||||
7448 | ||||
7449 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { | |||
7450 | auto Imp = importSeq(E->getLBraceLoc(), E->getRBraceLoc(), E->getType()); | |||
7451 | if (!Imp) | |||
7452 | return Imp.takeError(); | |||
7453 | ||||
7454 | SourceLocation ToLBraceLoc, ToRBraceLoc; | |||
7455 | QualType ToType; | |||
7456 | std::tie(ToLBraceLoc, ToRBraceLoc, ToType) = *Imp; | |||
7457 | ||||
7458 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); | |||
7459 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) | |||
7460 | return std::move(Err); | |||
7461 | ||||
7462 | ASTContext &ToCtx = Importer.getToContext(); | |||
7463 | InitListExpr *To = new (ToCtx) InitListExpr( | |||
7464 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); | |||
7465 | To->setType(ToType); | |||
7466 | ||||
7467 | if (E->hasArrayFiller()) { | |||
7468 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) | |||
7469 | To->setArrayFiller(*ToFillerOrErr); | |||
7470 | else | |||
7471 | return ToFillerOrErr.takeError(); | |||
7472 | } | |||
7473 | ||||
7474 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { | |||
7475 | if (auto ToFDOrErr = import(FromFD)) | |||
7476 | To->setInitializedFieldInUnion(*ToFDOrErr); | |||
7477 | else | |||
7478 | return ToFDOrErr.takeError(); | |||
7479 | } | |||
7480 | ||||
7481 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { | |||
7482 | if (auto ToSyntFormOrErr = import(SyntForm)) | |||
7483 | To->setSyntacticForm(*ToSyntFormOrErr); | |||
7484 | else | |||
7485 | return ToSyntFormOrErr.takeError(); | |||
7486 | } | |||
7487 | ||||
7488 | // Copy InitListExprBitfields, which are not handled in the ctor of | |||
7489 | // InitListExpr. | |||
7490 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); | |||
7491 | ||||
7492 | return To; | |||
7493 | } | |||
7494 | ||||
7495 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( | |||
7496 | CXXStdInitializerListExpr *E) { | |||
7497 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
7498 | if (!ToTypeOrErr) | |||
7499 | return ToTypeOrErr.takeError(); | |||
7500 | ||||
7501 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | |||
7502 | if (!ToSubExprOrErr) | |||
7503 | return ToSubExprOrErr.takeError(); | |||
7504 | ||||
7505 | return new (Importer.getToContext()) CXXStdInitializerListExpr( | |||
7506 | *ToTypeOrErr, *ToSubExprOrErr); | |||
7507 | } | |||
7508 | ||||
7509 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( | |||
7510 | CXXInheritedCtorInitExpr *E) { | |||
7511 | auto Imp = importSeq(E->getLocation(), E->getType(), E->getConstructor()); | |||
7512 | if (!Imp) | |||
7513 | return Imp.takeError(); | |||
7514 | ||||
7515 | SourceLocation ToLocation; | |||
7516 | QualType ToType; | |||
7517 | CXXConstructorDecl *ToConstructor; | |||
7518 | std::tie(ToLocation, ToType, ToConstructor) = *Imp; | |||
7519 | ||||
7520 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( | |||
7521 | ToLocation, ToType, ToConstructor, E->constructsVBase(), | |||
7522 | E->inheritedFromVBase()); | |||
7523 | } | |||
7524 | ||||
7525 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { | |||
7526 | auto Imp = importSeq(E->getType(), E->getCommonExpr(), E->getSubExpr()); | |||
7527 | if (!Imp) | |||
7528 | return Imp.takeError(); | |||
7529 | ||||
7530 | QualType ToType; | |||
7531 | Expr *ToCommonExpr, *ToSubExpr; | |||
7532 | std::tie(ToType, ToCommonExpr, ToSubExpr) = *Imp; | |||
7533 | ||||
7534 | return new (Importer.getToContext()) ArrayInitLoopExpr( | |||
7535 | ToType, ToCommonExpr, ToSubExpr); | |||
7536 | } | |||
7537 | ||||
7538 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { | |||
7539 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
7540 | if (!ToTypeOrErr) | |||
7541 | return ToTypeOrErr.takeError(); | |||
7542 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); | |||
7543 | } | |||
7544 | ||||
7545 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { | |||
7546 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); | |||
7547 | if (!ToBeginLocOrErr) | |||
7548 | return ToBeginLocOrErr.takeError(); | |||
7549 | ||||
7550 | auto ToFieldOrErr = import(E->getField()); | |||
7551 | if (!ToFieldOrErr) | |||
7552 | return ToFieldOrErr.takeError(); | |||
7553 | ||||
7554 | return CXXDefaultInitExpr::Create( | |||
7555 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr); | |||
7556 | } | |||
7557 | ||||
7558 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { | |||
7559 | auto Imp = importSeq( | |||
7560 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten(), | |||
7561 | E->getOperatorLoc(), E->getRParenLoc(), E->getAngleBrackets()); | |||
7562 | if (!Imp) | |||
7563 | return Imp.takeError(); | |||
7564 | ||||
7565 | QualType ToType; | |||
7566 | Expr *ToSubExpr; | |||
7567 | TypeSourceInfo *ToTypeInfoAsWritten; | |||
7568 | SourceLocation ToOperatorLoc, ToRParenLoc; | |||
7569 | SourceRange ToAngleBrackets; | |||
7570 | std::tie( | |||
7571 | ToType, ToSubExpr, ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, | |||
7572 | ToAngleBrackets) = *Imp; | |||
7573 | ||||
7574 | ExprValueKind VK = E->getValueKind(); | |||
7575 | CastKind CK = E->getCastKind(); | |||
7576 | auto ToBasePathOrErr = ImportCastPath(E); | |||
7577 | if (!ToBasePathOrErr) | |||
7578 | return ToBasePathOrErr.takeError(); | |||
7579 | ||||
7580 | if (isa<CXXStaticCastExpr>(E)) { | |||
7581 | return CXXStaticCastExpr::Create( | |||
7582 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | |||
7583 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | |||
7584 | } else if (isa<CXXDynamicCastExpr>(E)) { | |||
7585 | return CXXDynamicCastExpr::Create( | |||
7586 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | |||
7587 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | |||
7588 | } else if (isa<CXXReinterpretCastExpr>(E)) { | |||
7589 | return CXXReinterpretCastExpr::Create( | |||
7590 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | |||
7591 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | |||
7592 | } else if (isa<CXXConstCastExpr>(E)) { | |||
7593 | return CXXConstCastExpr::Create( | |||
7594 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, | |||
7595 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | |||
7596 | } else { | |||
7597 | llvm_unreachable("Unknown cast type")::llvm::llvm_unreachable_internal("Unknown cast type", "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 7597); | |||
7598 | return make_error<ImportError>(); | |||
7599 | } | |||
7600 | } | |||
7601 | ||||
7602 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( | |||
7603 | SubstNonTypeTemplateParmExpr *E) { | |||
7604 | auto Imp = importSeq( | |||
7605 | E->getType(), E->getExprLoc(), E->getParameter(), E->getReplacement()); | |||
7606 | if (!Imp) | |||
7607 | return Imp.takeError(); | |||
7608 | ||||
7609 | QualType ToType; | |||
7610 | SourceLocation ToExprLoc; | |||
7611 | NonTypeTemplateParmDecl *ToParameter; | |||
7612 | Expr *ToReplacement; | |||
7613 | std::tie(ToType, ToExprLoc, ToParameter, ToReplacement) = *Imp; | |||
7614 | ||||
7615 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( | |||
7616 | ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); | |||
7617 | } | |||
7618 | ||||
7619 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { | |||
7620 | auto Imp = importSeq( | |||
7621 | E->getType(), E->getBeginLoc(), E->getEndLoc()); | |||
7622 | if (!Imp) | |||
7623 | return Imp.takeError(); | |||
7624 | ||||
7625 | QualType ToType; | |||
7626 | SourceLocation ToBeginLoc, ToEndLoc; | |||
7627 | std::tie(ToType, ToBeginLoc, ToEndLoc) = *Imp; | |||
7628 | ||||
7629 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); | |||
7630 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) | |||
7631 | return std::move(Err); | |||
7632 | ||||
7633 | // According to Sema::BuildTypeTrait(), if E is value-dependent, | |||
7634 | // Value is always false. | |||
7635 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); | |||
7636 | ||||
7637 | return TypeTraitExpr::Create( | |||
7638 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, | |||
7639 | ToEndLoc, ToValue); | |||
7640 | } | |||
7641 | ||||
7642 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { | |||
7643 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
7644 | if (!ToTypeOrErr) | |||
7645 | return ToTypeOrErr.takeError(); | |||
7646 | ||||
7647 | auto ToSourceRangeOrErr = import(E->getSourceRange()); | |||
7648 | if (!ToSourceRangeOrErr) | |||
7649 | return ToSourceRangeOrErr.takeError(); | |||
7650 | ||||
7651 | if (E->isTypeOperand()) { | |||
7652 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) | |||
7653 | return new (Importer.getToContext()) CXXTypeidExpr( | |||
7654 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); | |||
7655 | else | |||
7656 | return ToTSIOrErr.takeError(); | |||
7657 | } | |||
7658 | ||||
7659 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); | |||
7660 | if (!ToExprOperandOrErr) | |||
7661 | return ToExprOperandOrErr.takeError(); | |||
7662 | ||||
7663 | return new (Importer.getToContext()) CXXTypeidExpr( | |||
7664 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); | |||
7665 | } | |||
7666 | ||||
7667 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, | |||
7668 | CXXMethodDecl *FromMethod) { | |||
7669 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { | |||
7670 | if (auto ImportedOrErr = import(FromOverriddenMethod)) | |||
7671 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( | |||
7672 | (*ImportedOrErr)->getCanonicalDecl())); | |||
7673 | else | |||
7674 | consumeError(ImportedOrErr.takeError()); | |||
7675 | } | |||
7676 | } | |||
7677 | ||||
7678 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, | |||
7679 | ASTContext &FromContext, FileManager &FromFileManager, | |||
7680 | bool MinimalImport) | |||
7681 | : ToContext(ToContext), FromContext(FromContext), | |||
7682 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), | |||
7683 | Minimal(MinimalImport) { | |||
7684 | ImportedDecls[FromContext.getTranslationUnitDecl()] | |||
7685 | = ToContext.getTranslationUnitDecl(); | |||
7686 | } | |||
7687 | ||||
7688 | ASTImporter::~ASTImporter() = default; | |||
7689 | ||||
7690 | Expected<QualType> ASTImporter::Import_New(QualType FromT) { | |||
7691 | QualType ToT = Import(FromT); | |||
7692 | if (ToT.isNull() && !FromT.isNull()) | |||
7693 | return make_error<ImportError>(); | |||
7694 | return ToT; | |||
7695 | } | |||
7696 | QualType ASTImporter::Import(QualType FromT) { | |||
7697 | if (FromT.isNull()) | |||
7698 | return {}; | |||
7699 | ||||
7700 | const Type *FromTy = FromT.getTypePtr(); | |||
7701 | ||||
7702 | // Check whether we've already imported this type. | |||
7703 | llvm::DenseMap<const Type *, const Type *>::iterator Pos | |||
7704 | = ImportedTypes.find(FromTy); | |||
7705 | if (Pos != ImportedTypes.end()) | |||
7706 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); | |||
7707 | ||||
7708 | // Import the type | |||
7709 | ASTNodeImporter Importer(*this); | |||
7710 | ExpectedType ToTOrErr = Importer.Visit(FromTy); | |||
7711 | if (!ToTOrErr) { | |||
7712 | llvm::consumeError(ToTOrErr.takeError()); | |||
7713 | return {}; | |||
7714 | } | |||
7715 | ||||
7716 | // Record the imported type. | |||
7717 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); | |||
7718 | ||||
7719 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); | |||
7720 | } | |||
7721 | ||||
7722 | Expected<TypeSourceInfo *> ASTImporter::Import_New(TypeSourceInfo *FromTSI) { | |||
7723 | TypeSourceInfo *ToTSI = Import(FromTSI); | |||
7724 | if (!ToTSI && FromTSI) | |||
7725 | return llvm::make_error<ImportError>(); | |||
7726 | return ToTSI; | |||
7727 | } | |||
7728 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { | |||
7729 | if (!FromTSI) | |||
7730 | return FromTSI; | |||
7731 | ||||
7732 | // FIXME: For now we just create a "trivial" type source info based | |||
7733 | // on the type and a single location. Implement a real version of this. | |||
7734 | QualType T = Import(FromTSI->getType()); | |||
7735 | if (T.isNull()) | |||
7736 | return nullptr; | |||
7737 | ||||
7738 | return ToContext.getTrivialTypeSourceInfo( | |||
7739 | T, Import(FromTSI->getTypeLoc().getBeginLoc())); | |||
7740 | } | |||
7741 | ||||
7742 | Expected<Attr *> ASTImporter::Import_New(const Attr *FromAttr) { | |||
7743 | return Import(FromAttr); | |||
7744 | } | |||
7745 | Attr *ASTImporter::Import(const Attr *FromAttr) { | |||
7746 | Attr *ToAttr = FromAttr->clone(ToContext); | |||
7747 | // NOTE: Import of SourceRange may fail. | |||
7748 | ToAttr->setRange(Import(FromAttr->getRange())); | |||
7749 | return ToAttr; | |||
7750 | } | |||
7751 | ||||
7752 | Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const { | |||
7753 | auto Pos = ImportedDecls.find(FromD); | |||
7754 | if (Pos != ImportedDecls.end()) | |||
7755 | return Pos->second; | |||
7756 | else | |||
7757 | return nullptr; | |||
7758 | } | |||
7759 | ||||
7760 | Expected<Decl *> ASTImporter::Import_New(Decl *FromD) { | |||
7761 | Decl *ToD = Import(FromD); | |||
7762 | if (!ToD && FromD) | |||
7763 | return llvm::make_error<ImportError>(); | |||
7764 | return ToD; | |||
7765 | } | |||
7766 | Decl *ASTImporter::Import(Decl *FromD) { | |||
7767 | if (!FromD) | |||
7768 | return nullptr; | |||
7769 | ||||
7770 | ASTNodeImporter Importer(*this); | |||
7771 | ||||
7772 | // Check whether we've already imported this declaration. | |||
7773 | Decl *ToD = GetAlreadyImportedOrNull(FromD); | |||
7774 | if (ToD) { | |||
7775 | // If FromD has some updated flags after last import, apply it | |||
7776 | updateFlags(FromD, ToD); | |||
7777 | return ToD; | |||
7778 | } | |||
7779 | ||||
7780 | // Import the type. | |||
7781 | ExpectedDecl ToDOrErr = Importer.Visit(FromD); | |||
7782 | if (!ToDOrErr) { | |||
7783 | llvm::consumeError(ToDOrErr.takeError()); | |||
7784 | return nullptr; | |||
7785 | } | |||
7786 | ToD = *ToDOrErr; | |||
7787 | ||||
7788 | // Notify subclasses. | |||
7789 | Imported(FromD, ToD); | |||
7790 | ||||
7791 | updateFlags(FromD, ToD); | |||
7792 | return ToD; | |||
7793 | } | |||
7794 | ||||
7795 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { | |||
7796 | if (!FromDC) | |||
7797 | return FromDC; | |||
7798 | ||||
7799 | auto *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); | |||
7800 | if (!ToDC) | |||
7801 | return nullptr; | |||
7802 | ||||
7803 | // When we're using a record/enum/Objective-C class/protocol as a context, we | |||
7804 | // need it to have a definition. | |||
7805 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { | |||
7806 | auto *FromRecord = cast<RecordDecl>(FromDC); | |||
7807 | if (ToRecord->isCompleteDefinition()) { | |||
7808 | // Do nothing. | |||
7809 | } else if (FromRecord->isCompleteDefinition()) { | |||
7810 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | |||
7811 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) | |||
7812 | return std::move(Err); | |||
7813 | } else { | |||
7814 | CompleteDecl(ToRecord); | |||
7815 | } | |||
7816 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { | |||
7817 | auto *FromEnum = cast<EnumDecl>(FromDC); | |||
7818 | if (ToEnum->isCompleteDefinition()) { | |||
7819 | // Do nothing. | |||
7820 | } else if (FromEnum->isCompleteDefinition()) { | |||
7821 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | |||
7822 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) | |||
7823 | return std::move(Err); | |||
7824 | } else { | |||
7825 | CompleteDecl(ToEnum); | |||
7826 | } | |||
7827 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { | |||
7828 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); | |||
7829 | if (ToClass->getDefinition()) { | |||
7830 | // Do nothing. | |||
7831 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { | |||
7832 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | |||
7833 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) | |||
7834 | return std::move(Err); | |||
7835 | } else { | |||
7836 | CompleteDecl(ToClass); | |||
7837 | } | |||
7838 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { | |||
7839 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); | |||
7840 | if (ToProto->getDefinition()) { | |||
7841 | // Do nothing. | |||
7842 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { | |||
7843 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | |||
7844 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) | |||
7845 | return std::move(Err); | |||
7846 | } else { | |||
7847 | CompleteDecl(ToProto); | |||
7848 | } | |||
7849 | } | |||
7850 | ||||
7851 | return ToDC; | |||
7852 | } | |||
7853 | ||||
7854 | Expected<Expr *> ASTImporter::Import_New(Expr *FromE) { | |||
7855 | Expr *ToE = Import(FromE); | |||
7856 | if (!ToE && FromE) | |||
7857 | return llvm::make_error<ImportError>(); | |||
7858 | return ToE; | |||
7859 | } | |||
7860 | Expr *ASTImporter::Import(Expr *FromE) { | |||
7861 | if (!FromE) | |||
7862 | return nullptr; | |||
7863 | ||||
7864 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); | |||
7865 | } | |||
7866 | ||||
7867 | Expected<Stmt *> ASTImporter::Import_New(Stmt *FromS) { | |||
7868 | Stmt *ToS = Import(FromS); | |||
7869 | if (!ToS && FromS) | |||
7870 | return llvm::make_error<ImportError>(); | |||
7871 | return ToS; | |||
7872 | } | |||
7873 | Stmt *ASTImporter::Import(Stmt *FromS) { | |||
7874 | if (!FromS) | |||
7875 | return nullptr; | |||
7876 | ||||
7877 | // Check whether we've already imported this declaration. | |||
7878 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); | |||
7879 | if (Pos != ImportedStmts.end()) | |||
7880 | return Pos->second; | |||
7881 | ||||
7882 | // Import the statement. | |||
7883 | ASTNodeImporter Importer(*this); | |||
7884 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); | |||
7885 | if (!ToSOrErr) { | |||
7886 | llvm::consumeError(ToSOrErr.takeError()); | |||
7887 | return nullptr; | |||
7888 | } | |||
7889 | ||||
7890 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { | |||
7891 | auto *FromE = cast<Expr>(FromS); | |||
7892 | // Copy ExprBitfields, which may not be handled in Expr subclasses | |||
7893 | // constructors. | |||
7894 | ToE->setValueKind(FromE->getValueKind()); | |||
7895 | ToE->setObjectKind(FromE->getObjectKind()); | |||
7896 | ToE->setTypeDependent(FromE->isTypeDependent()); | |||
7897 | ToE->setValueDependent(FromE->isValueDependent()); | |||
7898 | ToE->setInstantiationDependent(FromE->isInstantiationDependent()); | |||
7899 | ToE->setContainsUnexpandedParameterPack( | |||
7900 | FromE->containsUnexpandedParameterPack()); | |||
7901 | } | |||
7902 | ||||
7903 | // Record the imported declaration. | |||
7904 | ImportedStmts[FromS] = *ToSOrErr; | |||
7905 | return *ToSOrErr; | |||
7906 | } | |||
7907 | ||||
7908 | Expected<NestedNameSpecifier *> | |||
7909 | ASTImporter::Import_New(NestedNameSpecifier *FromNNS) { | |||
7910 | NestedNameSpecifier *ToNNS = Import(FromNNS); | |||
7911 | if (!ToNNS && FromNNS) | |||
7912 | return llvm::make_error<ImportError>(); | |||
7913 | return ToNNS; | |||
7914 | } | |||
7915 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { | |||
7916 | if (!FromNNS) | |||
7917 | return nullptr; | |||
7918 | ||||
7919 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); | |||
7920 | ||||
7921 | switch (FromNNS->getKind()) { | |||
7922 | case NestedNameSpecifier::Identifier: | |||
7923 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { | |||
7924 | return NestedNameSpecifier::Create(ToContext, prefix, II); | |||
7925 | } | |||
7926 | return nullptr; | |||
7927 | ||||
7928 | case NestedNameSpecifier::Namespace: | |||
7929 | if (auto *NS = | |||
7930 | cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { | |||
7931 | return NestedNameSpecifier::Create(ToContext, prefix, NS); | |||
7932 | } | |||
7933 | return nullptr; | |||
7934 | ||||
7935 | case NestedNameSpecifier::NamespaceAlias: | |||
7936 | if (auto *NSAD = | |||
7937 | cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { | |||
7938 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); | |||
7939 | } | |||
7940 | return nullptr; | |||
7941 | ||||
7942 | case NestedNameSpecifier::Global: | |||
7943 | return NestedNameSpecifier::GlobalSpecifier(ToContext); | |||
7944 | ||||
7945 | case NestedNameSpecifier::Super: | |||
7946 | if (auto *RD = | |||
7947 | cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) { | |||
7948 | return NestedNameSpecifier::SuperSpecifier(ToContext, RD); | |||
7949 | } | |||
7950 | return nullptr; | |||
7951 | ||||
7952 | case NestedNameSpecifier::TypeSpec: | |||
7953 | case NestedNameSpecifier::TypeSpecWithTemplate: { | |||
7954 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); | |||
7955 | if (!T.isNull()) { | |||
7956 | bool bTemplate = FromNNS->getKind() == | |||
7957 | NestedNameSpecifier::TypeSpecWithTemplate; | |||
7958 | return NestedNameSpecifier::Create(ToContext, prefix, | |||
7959 | bTemplate, T.getTypePtr()); | |||
7960 | } | |||
7961 | } | |||
7962 | return nullptr; | |||
7963 | } | |||
7964 | ||||
7965 | llvm_unreachable("Invalid nested name specifier kind")::llvm::llvm_unreachable_internal("Invalid nested name specifier kind" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 7965); | |||
7966 | } | |||
7967 | ||||
7968 | Expected<NestedNameSpecifierLoc> | |||
7969 | ASTImporter::Import_New(NestedNameSpecifierLoc FromNNS) { | |||
7970 | NestedNameSpecifierLoc ToNNS = Import(FromNNS); | |||
7971 | return ToNNS; | |||
7972 | } | |||
7973 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { | |||
7974 | // Copied from NestedNameSpecifier mostly. | |||
7975 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; | |||
7976 | NestedNameSpecifierLoc NNS = FromNNS; | |||
7977 | ||||
7978 | // Push each of the nested-name-specifiers's onto a stack for | |||
7979 | // serialization in reverse order. | |||
7980 | while (NNS) { | |||
7981 | NestedNames.push_back(NNS); | |||
7982 | NNS = NNS.getPrefix(); | |||
7983 | } | |||
7984 | ||||
7985 | NestedNameSpecifierLocBuilder Builder; | |||
7986 | ||||
7987 | while (!NestedNames.empty()) { | |||
7988 | NNS = NestedNames.pop_back_val(); | |||
7989 | NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier()); | |||
7990 | if (!Spec) | |||
7991 | return NestedNameSpecifierLoc(); | |||
7992 | ||||
7993 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); | |||
7994 | switch (Kind) { | |||
7995 | case NestedNameSpecifier::Identifier: | |||
7996 | Builder.Extend(getToContext(), | |||
7997 | Spec->getAsIdentifier(), | |||
7998 | Import(NNS.getLocalBeginLoc()), | |||
7999 | Import(NNS.getLocalEndLoc())); | |||
8000 | break; | |||
8001 | ||||
8002 | case NestedNameSpecifier::Namespace: | |||
8003 | Builder.Extend(getToContext(), | |||
8004 | Spec->getAsNamespace(), | |||
8005 | Import(NNS.getLocalBeginLoc()), | |||
8006 | Import(NNS.getLocalEndLoc())); | |||
8007 | break; | |||
8008 | ||||
8009 | case NestedNameSpecifier::NamespaceAlias: | |||
8010 | Builder.Extend(getToContext(), | |||
8011 | Spec->getAsNamespaceAlias(), | |||
8012 | Import(NNS.getLocalBeginLoc()), | |||
8013 | Import(NNS.getLocalEndLoc())); | |||
8014 | break; | |||
8015 | ||||
8016 | case NestedNameSpecifier::TypeSpec: | |||
8017 | case NestedNameSpecifier::TypeSpecWithTemplate: { | |||
8018 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( | |||
8019 | QualType(Spec->getAsType(), 0)); | |||
8020 | Builder.Extend(getToContext(), | |||
8021 | Import(NNS.getLocalBeginLoc()), | |||
8022 | TSI->getTypeLoc(), | |||
8023 | Import(NNS.getLocalEndLoc())); | |||
8024 | break; | |||
8025 | } | |||
8026 | ||||
8027 | case NestedNameSpecifier::Global: | |||
8028 | Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc())); | |||
8029 | break; | |||
8030 | ||||
8031 | case NestedNameSpecifier::Super: { | |||
8032 | SourceRange ToRange = Import(NNS.getSourceRange()); | |||
8033 | Builder.MakeSuper(getToContext(), | |||
8034 | Spec->getAsRecordDecl(), | |||
8035 | ToRange.getBegin(), | |||
8036 | ToRange.getEnd()); | |||
8037 | } | |||
8038 | } | |||
8039 | } | |||
8040 | ||||
8041 | return Builder.getWithLocInContext(getToContext()); | |||
8042 | } | |||
8043 | ||||
8044 | Expected<TemplateName> ASTImporter::Import_New(TemplateName From) { | |||
8045 | TemplateName To = Import(From); | |||
8046 | if (To.isNull() && !From.isNull()) | |||
8047 | return llvm::make_error<ImportError>(); | |||
8048 | return To; | |||
8049 | } | |||
8050 | TemplateName ASTImporter::Import(TemplateName From) { | |||
8051 | switch (From.getKind()) { | |||
8052 | case TemplateName::Template: | |||
8053 | if (auto *ToTemplate = | |||
8054 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) | |||
8055 | return TemplateName(ToTemplate); | |||
8056 | ||||
8057 | return {}; | |||
8058 | ||||
8059 | case TemplateName::OverloadedTemplate: { | |||
8060 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); | |||
8061 | UnresolvedSet<2> ToTemplates; | |||
8062 | for (auto *I : *FromStorage) { | |||
8063 | if (auto *To = cast_or_null<NamedDecl>(Import(I))) | |||
8064 | ToTemplates.addDecl(To); | |||
8065 | else | |||
8066 | return {}; | |||
8067 | } | |||
8068 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), | |||
8069 | ToTemplates.end()); | |||
8070 | } | |||
8071 | ||||
8072 | case TemplateName::QualifiedTemplate: { | |||
8073 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); | |||
8074 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); | |||
8075 | if (!Qualifier) | |||
8076 | return {}; | |||
8077 | ||||
8078 | if (auto *ToTemplate = | |||
8079 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) | |||
8080 | return ToContext.getQualifiedTemplateName(Qualifier, | |||
8081 | QTN->hasTemplateKeyword(), | |||
8082 | ToTemplate); | |||
8083 | ||||
8084 | return {}; | |||
8085 | } | |||
8086 | ||||
8087 | case TemplateName::DependentTemplate: { | |||
8088 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); | |||
8089 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); | |||
8090 | if (!Qualifier) | |||
8091 | return {}; | |||
8092 | ||||
8093 | if (DTN->isIdentifier()) { | |||
8094 | return ToContext.getDependentTemplateName(Qualifier, | |||
8095 | Import(DTN->getIdentifier())); | |||
8096 | } | |||
8097 | ||||
8098 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); | |||
8099 | } | |||
8100 | ||||
8101 | case TemplateName::SubstTemplateTemplateParm: { | |||
8102 | SubstTemplateTemplateParmStorage *subst | |||
8103 | = From.getAsSubstTemplateTemplateParm(); | |||
8104 | auto *param = | |||
8105 | cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); | |||
8106 | if (!param) | |||
8107 | return {}; | |||
8108 | ||||
8109 | TemplateName replacement = Import(subst->getReplacement()); | |||
8110 | if (replacement.isNull()) | |||
8111 | return {}; | |||
8112 | ||||
8113 | return ToContext.getSubstTemplateTemplateParm(param, replacement); | |||
8114 | } | |||
8115 | ||||
8116 | case TemplateName::SubstTemplateTemplateParmPack: { | |||
8117 | SubstTemplateTemplateParmPackStorage *SubstPack | |||
8118 | = From.getAsSubstTemplateTemplateParmPack(); | |||
8119 | auto *Param = | |||
8120 | cast_or_null<TemplateTemplateParmDecl>( | |||
8121 | Import(SubstPack->getParameterPack())); | |||
8122 | if (!Param) | |||
8123 | return {}; | |||
8124 | ||||
8125 | ASTNodeImporter Importer(*this); | |||
8126 | Expected<TemplateArgument> ArgPack | |||
8127 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); | |||
8128 | if (!ArgPack) { | |||
8129 | llvm::consumeError(ArgPack.takeError()); | |||
8130 | return {}; | |||
8131 | } | |||
8132 | ||||
8133 | return ToContext.getSubstTemplateTemplateParmPack(Param, *ArgPack); | |||
8134 | } | |||
8135 | } | |||
8136 | ||||
8137 | llvm_unreachable("Invalid template name kind")::llvm::llvm_unreachable_internal("Invalid template name kind" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 8137); | |||
8138 | } | |||
8139 | ||||
8140 | Expected<SourceLocation> ASTImporter::Import_New(SourceLocation FromLoc) { | |||
8141 | SourceLocation ToLoc = Import(FromLoc); | |||
8142 | if (ToLoc.isInvalid() && !FromLoc.isInvalid()) | |||
8143 | return llvm::make_error<ImportError>(); | |||
8144 | return ToLoc; | |||
8145 | } | |||
8146 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { | |||
8147 | if (FromLoc.isInvalid()) | |||
8148 | return {}; | |||
8149 | ||||
8150 | SourceManager &FromSM = FromContext.getSourceManager(); | |||
8151 | ||||
8152 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); | |||
8153 | FileID ToFileID = Import(Decomposed.first); | |||
8154 | if (ToFileID.isInvalid()) | |||
8155 | return {}; | |||
8156 | SourceManager &ToSM = ToContext.getSourceManager(); | |||
8157 | return ToSM.getComposedLoc(ToFileID, Decomposed.second); | |||
8158 | } | |||
8159 | ||||
8160 | Expected<SourceRange> ASTImporter::Import_New(SourceRange FromRange) { | |||
8161 | SourceRange ToRange = Import(FromRange); | |||
8162 | return ToRange; | |||
8163 | } | |||
8164 | SourceRange ASTImporter::Import(SourceRange FromRange) { | |||
8165 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); | |||
8166 | } | |||
8167 | ||||
8168 | Expected<FileID> ASTImporter::Import_New(FileID FromID) { | |||
8169 | FileID ToID = Import(FromID); | |||
8170 | if (ToID.isInvalid() && FromID.isValid()) | |||
8171 | return llvm::make_error<ImportError>(); | |||
8172 | return ToID; | |||
8173 | } | |||
8174 | FileID ASTImporter::Import(FileID FromID) { | |||
8175 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); | |||
8176 | if (Pos != ImportedFileIDs.end()) | |||
8177 | return Pos->second; | |||
8178 | ||||
8179 | SourceManager &FromSM = FromContext.getSourceManager(); | |||
8180 | SourceManager &ToSM = ToContext.getSourceManager(); | |||
8181 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); | |||
8182 | ||||
8183 | // Map the FromID to the "to" source manager. | |||
8184 | FileID ToID; | |||
8185 | if (FromSLoc.isExpansion()) { | |||
8186 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); | |||
8187 | SourceLocation ToSpLoc = Import(FromEx.getSpellingLoc()); | |||
8188 | SourceLocation ToExLocS = Import(FromEx.getExpansionLocStart()); | |||
8189 | unsigned TokenLen = FromSM.getFileIDSize(FromID); | |||
8190 | SourceLocation MLoc; | |||
8191 | if (FromEx.isMacroArgExpansion()) { | |||
8192 | MLoc = ToSM.createMacroArgExpansionLoc(ToSpLoc, ToExLocS, TokenLen); | |||
8193 | } else { | |||
8194 | SourceLocation ToExLocE = Import(FromEx.getExpansionLocEnd()); | |||
8195 | MLoc = ToSM.createExpansionLoc(ToSpLoc, ToExLocS, ToExLocE, TokenLen, | |||
8196 | FromEx.isExpansionTokenRange()); | |||
8197 | } | |||
8198 | ToID = ToSM.getFileID(MLoc); | |||
8199 | } else { | |||
8200 | // Include location of this file. | |||
8201 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); | |||
8202 | ||||
8203 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); | |||
8204 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { | |||
8205 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the | |||
8206 | // disk again | |||
8207 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather | |||
8208 | // than mmap the files several times. | |||
8209 | const FileEntry *Entry = | |||
8210 | ToFileManager.getFile(Cache->OrigEntry->getName()); | |||
8211 | if (!Entry) | |||
8212 | return {}; | |||
8213 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, | |||
8214 | FromSLoc.getFile().getFileCharacteristic()); | |||
8215 | } else { | |||
8216 | // FIXME: We want to re-use the existing MemoryBuffer! | |||
8217 | const llvm::MemoryBuffer *FromBuf = | |||
8218 | Cache->getBuffer(FromContext.getDiagnostics(), FromSM); | |||
8219 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = | |||
8220 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), | |||
8221 | FromBuf->getBufferIdentifier()); | |||
8222 | ToID = ToSM.createFileID(std::move(ToBuf), | |||
8223 | FromSLoc.getFile().getFileCharacteristic()); | |||
8224 | } | |||
8225 | } | |||
8226 | ||||
8227 | ImportedFileIDs[FromID] = ToID; | |||
8228 | return ToID; | |||
8229 | } | |||
8230 | ||||
8231 | Expected<CXXCtorInitializer *> | |||
8232 | ASTImporter::Import_New(CXXCtorInitializer *From) { | |||
8233 | CXXCtorInitializer *To = Import(From); | |||
8234 | if (!To && From) | |||
8235 | return llvm::make_error<ImportError>(); | |||
8236 | return To; | |||
8237 | } | |||
8238 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { | |||
8239 | Expr *ToExpr = Import(From->getInit()); | |||
8240 | if (!ToExpr && From->getInit()) | |||
8241 | return nullptr; | |||
8242 | ||||
8243 | if (From->isBaseInitializer()) { | |||
8244 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); | |||
8245 | if (!ToTInfo && From->getTypeSourceInfo()) | |||
8246 | return nullptr; | |||
8247 | ||||
8248 | return new (ToContext) CXXCtorInitializer( | |||
8249 | ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()), | |||
8250 | ToExpr, Import(From->getRParenLoc()), | |||
8251 | From->isPackExpansion() ? Import(From->getEllipsisLoc()) | |||
8252 | : SourceLocation()); | |||
8253 | } else if (From->isMemberInitializer()) { | |||
8254 | auto *ToField = cast_or_null<FieldDecl>(Import(From->getMember())); | |||
8255 | if (!ToField && From->getMember()) | |||
8256 | return nullptr; | |||
8257 | ||||
8258 | return new (ToContext) CXXCtorInitializer( | |||
8259 | ToContext, ToField, Import(From->getMemberLocation()), | |||
8260 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); | |||
8261 | } else if (From->isIndirectMemberInitializer()) { | |||
8262 | auto *ToIField = cast_or_null<IndirectFieldDecl>( | |||
8263 | Import(From->getIndirectMember())); | |||
8264 | if (!ToIField && From->getIndirectMember()) | |||
8265 | return nullptr; | |||
8266 | ||||
8267 | return new (ToContext) CXXCtorInitializer( | |||
8268 | ToContext, ToIField, Import(From->getMemberLocation()), | |||
8269 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); | |||
8270 | } else if (From->isDelegatingInitializer()) { | |||
8271 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); | |||
8272 | if (!ToTInfo && From->getTypeSourceInfo()) | |||
8273 | return nullptr; | |||
8274 | ||||
8275 | return new (ToContext) | |||
8276 | CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()), | |||
8277 | ToExpr, Import(From->getRParenLoc())); | |||
8278 | } else { | |||
8279 | return nullptr; | |||
8280 | } | |||
8281 | } | |||
8282 | ||||
8283 | Expected<CXXBaseSpecifier *> | |||
8284 | ASTImporter::Import_New(const CXXBaseSpecifier *From) { | |||
8285 | CXXBaseSpecifier *To = Import(From); | |||
8286 | if (!To && From) | |||
8287 | return llvm::make_error<ImportError>(); | |||
8288 | return To; | |||
8289 | } | |||
8290 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { | |||
8291 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); | |||
8292 | if (Pos != ImportedCXXBaseSpecifiers.end()) | |||
8293 | return Pos->second; | |||
8294 | ||||
8295 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( | |||
8296 | Import(BaseSpec->getSourceRange()), | |||
8297 | BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), | |||
8298 | BaseSpec->getAccessSpecifierAsWritten(), | |||
8299 | Import(BaseSpec->getTypeSourceInfo()), | |||
8300 | Import(BaseSpec->getEllipsisLoc())); | |||
8301 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; | |||
8302 | return Imported; | |||
8303 | } | |||
8304 | ||||
8305 | Error ASTImporter::ImportDefinition_New(Decl *From) { | |||
8306 | Decl *To = Import(From); | |||
8307 | if (!To) | |||
8308 | return llvm::make_error<ImportError>(); | |||
8309 | ||||
8310 | if (auto *FromDC = cast<DeclContext>(From)) { | |||
8311 | ASTNodeImporter Importer(*this); | |||
8312 | ||||
8313 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { | |||
8314 | if (!ToRecord->getDefinition()) { | |||
8315 | return Importer.ImportDefinition( | |||
8316 | cast<RecordDecl>(FromDC), ToRecord, | |||
8317 | ASTNodeImporter::IDK_Everything); | |||
8318 | } | |||
8319 | } | |||
8320 | ||||
8321 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { | |||
8322 | if (!ToEnum->getDefinition()) { | |||
8323 | return Importer.ImportDefinition( | |||
8324 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); | |||
8325 | } | |||
8326 | } | |||
8327 | ||||
8328 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { | |||
8329 | if (!ToIFace->getDefinition()) { | |||
8330 | return Importer.ImportDefinition( | |||
8331 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, | |||
8332 | ASTNodeImporter::IDK_Everything); | |||
8333 | } | |||
8334 | } | |||
8335 | ||||
8336 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { | |||
8337 | if (!ToProto->getDefinition()) { | |||
8338 | return Importer.ImportDefinition( | |||
8339 | cast<ObjCProtocolDecl>(FromDC), ToProto, | |||
8340 | ASTNodeImporter::IDK_Everything); | |||
8341 | } | |||
8342 | } | |||
8343 | ||||
8344 | return Importer.ImportDeclContext(FromDC, true); | |||
8345 | } | |||
8346 | ||||
8347 | return Error::success(); | |||
8348 | } | |||
8349 | ||||
8350 | void ASTImporter::ImportDefinition(Decl *From) { | |||
8351 | Error Err = ImportDefinition_New(From); | |||
8352 | llvm::consumeError(std::move(Err)); | |||
8353 | } | |||
8354 | ||||
8355 | Expected<DeclarationName> ASTImporter::Import_New(DeclarationName FromName) { | |||
8356 | DeclarationName ToName = Import(FromName); | |||
8357 | if (!ToName && FromName) | |||
8358 | return llvm::make_error<ImportError>(); | |||
8359 | return ToName; | |||
8360 | } | |||
8361 | DeclarationName ASTImporter::Import(DeclarationName FromName) { | |||
8362 | if (!FromName) | |||
8363 | return {}; | |||
8364 | ||||
8365 | switch (FromName.getNameKind()) { | |||
8366 | case DeclarationName::Identifier: | |||
8367 | return Import(FromName.getAsIdentifierInfo()); | |||
8368 | ||||
8369 | case DeclarationName::ObjCZeroArgSelector: | |||
8370 | case DeclarationName::ObjCOneArgSelector: | |||
8371 | case DeclarationName::ObjCMultiArgSelector: | |||
8372 | return Import(FromName.getObjCSelector()); | |||
8373 | ||||
8374 | case DeclarationName::CXXConstructorName: { | |||
8375 | QualType T = Import(FromName.getCXXNameType()); | |||
8376 | if (T.isNull()) | |||
8377 | return {}; | |||
8378 | ||||
8379 | return ToContext.DeclarationNames.getCXXConstructorName( | |||
8380 | ToContext.getCanonicalType(T)); | |||
8381 | } | |||
8382 | ||||
8383 | case DeclarationName::CXXDestructorName: { | |||
8384 | QualType T = Import(FromName.getCXXNameType()); | |||
8385 | if (T.isNull()) | |||
8386 | return {}; | |||
8387 | ||||
8388 | return ToContext.DeclarationNames.getCXXDestructorName( | |||
8389 | ToContext.getCanonicalType(T)); | |||
8390 | } | |||
8391 | ||||
8392 | case DeclarationName::CXXDeductionGuideName: { | |||
8393 | auto *Template = cast_or_null<TemplateDecl>( | |||
8394 | Import(FromName.getCXXDeductionGuideTemplate())); | |||
8395 | if (!Template) | |||
8396 | return {}; | |||
8397 | return ToContext.DeclarationNames.getCXXDeductionGuideName(Template); | |||
8398 | } | |||
8399 | ||||
8400 | case DeclarationName::CXXConversionFunctionName: { | |||
8401 | QualType T = Import(FromName.getCXXNameType()); | |||
8402 | if (T.isNull()) | |||
8403 | return {}; | |||
8404 | ||||
8405 | return ToContext.DeclarationNames.getCXXConversionFunctionName( | |||
8406 | ToContext.getCanonicalType(T)); | |||
8407 | } | |||
8408 | ||||
8409 | case DeclarationName::CXXOperatorName: | |||
8410 | return ToContext.DeclarationNames.getCXXOperatorName( | |||
8411 | FromName.getCXXOverloadedOperator()); | |||
8412 | ||||
8413 | case DeclarationName::CXXLiteralOperatorName: | |||
8414 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( | |||
8415 | Import(FromName.getCXXLiteralIdentifier())); | |||
8416 | ||||
8417 | case DeclarationName::CXXUsingDirective: | |||
8418 | // FIXME: STATICS! | |||
8419 | return DeclarationName::getUsingDirectiveName(); | |||
8420 | } | |||
8421 | ||||
8422 | llvm_unreachable("Invalid DeclarationName Kind!")::llvm::llvm_unreachable_internal("Invalid DeclarationName Kind!" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 8422); | |||
8423 | } | |||
8424 | ||||
8425 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { | |||
8426 | if (!FromId) | |||
8427 | return nullptr; | |||
8428 | ||||
8429 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); | |||
8430 | ||||
8431 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) | |||
8432 | ToId->setBuiltinID(FromId->getBuiltinID()); | |||
8433 | ||||
8434 | return ToId; | |||
8435 | } | |||
8436 | ||||
8437 | Expected<Selector> ASTImporter::Import_New(Selector FromSel) { | |||
8438 | Selector ToSel = Import(FromSel); | |||
8439 | if (ToSel.isNull() && !FromSel.isNull()) | |||
8440 | return llvm::make_error<ImportError>(); | |||
8441 | return ToSel; | |||
8442 | } | |||
8443 | Selector ASTImporter::Import(Selector FromSel) { | |||
8444 | if (FromSel.isNull()) | |||
8445 | return {}; | |||
8446 | ||||
8447 | SmallVector<IdentifierInfo *, 4> Idents; | |||
8448 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); | |||
8449 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) | |||
8450 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); | |||
8451 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); | |||
8452 | } | |||
8453 | ||||
8454 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, | |||
8455 | DeclContext *DC, | |||
8456 | unsigned IDNS, | |||
8457 | NamedDecl **Decls, | |||
8458 | unsigned NumDecls) { | |||
8459 | return Name; | |||
8460 | } | |||
8461 | ||||
8462 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { | |||
8463 | if (LastDiagFromFrom) | |||
8464 | ToContext.getDiagnostics().notePriorDiagnosticFrom( | |||
8465 | FromContext.getDiagnostics()); | |||
8466 | LastDiagFromFrom = false; | |||
8467 | return ToContext.getDiagnostics().Report(Loc, DiagID); | |||
8468 | } | |||
8469 | ||||
8470 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { | |||
8471 | if (!LastDiagFromFrom) | |||
8472 | FromContext.getDiagnostics().notePriorDiagnosticFrom( | |||
8473 | ToContext.getDiagnostics()); | |||
8474 | LastDiagFromFrom = true; | |||
8475 | return FromContext.getDiagnostics().Report(Loc, DiagID); | |||
8476 | } | |||
8477 | ||||
8478 | void ASTImporter::CompleteDecl (Decl *D) { | |||
8479 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { | |||
8480 | if (!ID->getDefinition()) | |||
8481 | ID->startDefinition(); | |||
8482 | } | |||
8483 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { | |||
8484 | if (!PD->getDefinition()) | |||
8485 | PD->startDefinition(); | |||
8486 | } | |||
8487 | else if (auto *TD = dyn_cast<TagDecl>(D)) { | |||
8488 | if (!TD->getDefinition() && !TD->isBeingDefined()) { | |||
8489 | TD->startDefinition(); | |||
8490 | TD->setCompleteDefinition(true); | |||
8491 | } | |||
8492 | } | |||
8493 | else { | |||
8494 | assert(0 && "CompleteDecl called on a Decl that can't be completed")((0 && "CompleteDecl called on a Decl that can't be completed" ) ? static_cast<void> (0) : __assert_fail ("0 && \"CompleteDecl called on a Decl that can't be completed\"" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 8494, __PRETTY_FUNCTION__)); | |||
8495 | } | |||
8496 | } | |||
8497 | ||||
8498 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { | |||
8499 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); | |||
8500 | assert((Pos == ImportedDecls.end() || Pos->second == To) &&(((Pos == ImportedDecls.end() || Pos->second == To) && "Try to import an already imported Decl") ? static_cast<void > (0) : __assert_fail ("(Pos == ImportedDecls.end() || Pos->second == To) && \"Try to import an already imported Decl\"" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 8501, __PRETTY_FUNCTION__)) | |||
8501 | "Try to import an already imported Decl")(((Pos == ImportedDecls.end() || Pos->second == To) && "Try to import an already imported Decl") ? static_cast<void > (0) : __assert_fail ("(Pos == ImportedDecls.end() || Pos->second == To) && \"Try to import an already imported Decl\"" , "/build/llvm-toolchain-snapshot-8~svn349319/tools/clang/lib/AST/ASTImporter.cpp" , 8501, __PRETTY_FUNCTION__)); | |||
8502 | if (Pos != ImportedDecls.end()) | |||
8503 | return Pos->second; | |||
8504 | ImportedDecls[From] = To; | |||
8505 | return To; | |||
8506 | } | |||
8507 | ||||
8508 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, | |||
8509 | bool Complain) { | |||
8510 | llvm::DenseMap<const Type *, const Type *>::iterator Pos | |||
8511 | = ImportedTypes.find(From.getTypePtr()); | |||
8512 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) | |||
8513 | return true; | |||
8514 | ||||
8515 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, | |||
8516 | getStructuralEquivalenceKind(*this), false, | |||
8517 | Complain); | |||
8518 | return Ctx.IsEquivalent(From, To); | |||
8519 | } |