File: | build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/clang/lib/AST/ASTImporter.cpp |
Warning: | line 5962, column 39 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===// | |||
2 | // | |||
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |||
4 | // See https://llvm.org/LICENSE.txt for license information. | |||
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |||
6 | // | |||
7 | //===----------------------------------------------------------------------===// | |||
8 | // | |||
9 | // This file defines the ASTImporter class which imports AST nodes from one | |||
10 | // context into another context. | |||
11 | // | |||
12 | //===----------------------------------------------------------------------===// | |||
13 | ||||
14 | #include "clang/AST/ASTImporter.h" | |||
15 | #include "clang/AST/ASTImporterSharedState.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/Builtins.h" | |||
48 | #include "clang/Basic/ExceptionSpecificationType.h" | |||
49 | #include "clang/Basic/FileManager.h" | |||
50 | #include "clang/Basic/IdentifierTable.h" | |||
51 | #include "clang/Basic/LLVM.h" | |||
52 | #include "clang/Basic/LangOptions.h" | |||
53 | #include "clang/Basic/SourceLocation.h" | |||
54 | #include "clang/Basic/SourceManager.h" | |||
55 | #include "clang/Basic/Specifiers.h" | |||
56 | #include "llvm/ADT/APSInt.h" | |||
57 | #include "llvm/ADT/ArrayRef.h" | |||
58 | #include "llvm/ADT/DenseMap.h" | |||
59 | #include "llvm/ADT/None.h" | |||
60 | #include "llvm/ADT/Optional.h" | |||
61 | #include "llvm/ADT/ScopeExit.h" | |||
62 | #include "llvm/ADT/STLExtras.h" | |||
63 | #include "llvm/ADT/SmallVector.h" | |||
64 | #include "llvm/Support/Casting.h" | |||
65 | #include "llvm/Support/ErrorHandling.h" | |||
66 | #include "llvm/Support/MemoryBuffer.h" | |||
67 | #include <algorithm> | |||
68 | #include <cassert> | |||
69 | #include <cstddef> | |||
70 | #include <memory> | |||
71 | #include <type_traits> | |||
72 | #include <utility> | |||
73 | ||||
74 | namespace clang { | |||
75 | ||||
76 | using llvm::make_error; | |||
77 | using llvm::Error; | |||
78 | using llvm::Expected; | |||
79 | using ExpectedTypePtr = llvm::Expected<const Type *>; | |||
80 | using ExpectedType = llvm::Expected<QualType>; | |||
81 | using ExpectedStmt = llvm::Expected<Stmt *>; | |||
82 | using ExpectedExpr = llvm::Expected<Expr *>; | |||
83 | using ExpectedDecl = llvm::Expected<Decl *>; | |||
84 | using ExpectedSLoc = llvm::Expected<SourceLocation>; | |||
85 | using ExpectedName = llvm::Expected<DeclarationName>; | |||
86 | ||||
87 | std::string ImportError::toString() const { | |||
88 | // FIXME: Improve error texts. | |||
89 | switch (Error) { | |||
90 | case NameConflict: | |||
91 | return "NameConflict"; | |||
92 | case UnsupportedConstruct: | |||
93 | return "UnsupportedConstruct"; | |||
94 | case Unknown: | |||
95 | return "Unknown error"; | |||
96 | } | |||
97 | llvm_unreachable("Invalid error code.")::llvm::llvm_unreachable_internal("Invalid error code.", "clang/lib/AST/ASTImporter.cpp" , 97); | |||
98 | return "Invalid error code."; | |||
99 | } | |||
100 | ||||
101 | void ImportError::log(raw_ostream &OS) const { | |||
102 | OS << toString(); | |||
103 | } | |||
104 | ||||
105 | std::error_code ImportError::convertToErrorCode() const { | |||
106 | llvm_unreachable("Function not implemented.")::llvm::llvm_unreachable_internal("Function not implemented." , "clang/lib/AST/ASTImporter.cpp", 106); | |||
107 | } | |||
108 | ||||
109 | char ImportError::ID; | |||
110 | ||||
111 | template <class T> | |||
112 | SmallVector<Decl *, 2> | |||
113 | getCanonicalForwardRedeclChain(Redeclarable<T>* D) { | |||
114 | SmallVector<Decl *, 2> Redecls; | |||
115 | for (auto *R : D->getFirstDecl()->redecls()) { | |||
116 | if (R != D->getFirstDecl()) | |||
117 | Redecls.push_back(R); | |||
118 | } | |||
119 | Redecls.push_back(D->getFirstDecl()); | |||
120 | std::reverse(Redecls.begin(), Redecls.end()); | |||
121 | return Redecls; | |||
122 | } | |||
123 | ||||
124 | SmallVector<Decl*, 2> getCanonicalForwardRedeclChain(Decl* D) { | |||
125 | if (auto *FD = dyn_cast<FunctionDecl>(D)) | |||
126 | return getCanonicalForwardRedeclChain<FunctionDecl>(FD); | |||
127 | if (auto *VD = dyn_cast<VarDecl>(D)) | |||
128 | return getCanonicalForwardRedeclChain<VarDecl>(VD); | |||
129 | if (auto *TD = dyn_cast<TagDecl>(D)) | |||
130 | return getCanonicalForwardRedeclChain<TagDecl>(TD); | |||
131 | llvm_unreachable("Bad declaration kind")::llvm::llvm_unreachable_internal("Bad declaration kind", "clang/lib/AST/ASTImporter.cpp" , 131); | |||
132 | } | |||
133 | ||||
134 | void updateFlags(const Decl *From, Decl *To) { | |||
135 | // Check if some flags or attrs are new in 'From' and copy into 'To'. | |||
136 | // FIXME: Other flags or attrs? | |||
137 | if (From->isUsed(false) && !To->isUsed(false)) | |||
138 | To->setIsUsed(); | |||
139 | } | |||
140 | ||||
141 | /// How to handle import errors that occur when import of a child declaration | |||
142 | /// of a DeclContext fails. | |||
143 | class ChildErrorHandlingStrategy { | |||
144 | /// This context is imported (in the 'from' domain). | |||
145 | /// It is nullptr if a non-DeclContext is imported. | |||
146 | const DeclContext *const FromDC; | |||
147 | /// Ignore import errors of the children. | |||
148 | /// If true, the context can be imported successfully if a child | |||
149 | /// of it failed to import. Otherwise the import errors of the child nodes | |||
150 | /// are accumulated (joined) into the import error object of the parent. | |||
151 | /// (Import of a parent can fail in other ways.) | |||
152 | bool const IgnoreChildErrors; | |||
153 | ||||
154 | public: | |||
155 | ChildErrorHandlingStrategy(const DeclContext *FromDC) | |||
156 | : FromDC(FromDC), IgnoreChildErrors(!isa<TagDecl>(FromDC)) {} | |||
157 | ChildErrorHandlingStrategy(const Decl *FromD) | |||
158 | : FromDC(dyn_cast<DeclContext>(FromD)), | |||
159 | IgnoreChildErrors(!isa<TagDecl>(FromD)) {} | |||
160 | ||||
161 | /// Process the import result of a child (of the current declaration). | |||
162 | /// \param ResultErr The import error that can be used as result of | |||
163 | /// importing the parent. This may be changed by the function. | |||
164 | /// \param ChildErr Result of importing a child. Can be success or error. | |||
165 | void handleChildImportResult(Error &ResultErr, Error &&ChildErr) { | |||
166 | if (ChildErr && !IgnoreChildErrors) | |||
167 | ResultErr = joinErrors(std::move(ResultErr), std::move(ChildErr)); | |||
168 | else | |||
169 | consumeError(std::move(ChildErr)); | |||
170 | } | |||
171 | ||||
172 | /// Determine if import failure of a child does not cause import failure of | |||
173 | /// its parent. | |||
174 | bool ignoreChildErrorOnParent(Decl *FromChildD) const { | |||
175 | if (!IgnoreChildErrors || !FromDC) | |||
176 | return false; | |||
177 | return FromDC->containsDecl(FromChildD); | |||
178 | } | |||
179 | }; | |||
180 | ||||
181 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>, | |||
182 | public DeclVisitor<ASTNodeImporter, ExpectedDecl>, | |||
183 | public StmtVisitor<ASTNodeImporter, ExpectedStmt> { | |||
184 | ASTImporter &Importer; | |||
185 | ||||
186 | // Use this instead of Importer.importInto . | |||
187 | template <typename ImportT> | |||
188 | LLVM_NODISCARD[[clang::warn_unused_result]] Error importInto(ImportT &To, const ImportT &From) { | |||
189 | return Importer.importInto(To, From); | |||
190 | } | |||
191 | ||||
192 | // Use this to import pointers of specific type. | |||
193 | template <typename ImportT> | |||
194 | LLVM_NODISCARD[[clang::warn_unused_result]] Error importInto(ImportT *&To, ImportT *From) { | |||
195 | auto ToOrErr = Importer.Import(From); | |||
196 | if (ToOrErr) | |||
197 | To = cast_or_null<ImportT>(*ToOrErr); | |||
198 | return ToOrErr.takeError(); | |||
199 | } | |||
200 | ||||
201 | // Call the import function of ASTImporter for a baseclass of type `T` and | |||
202 | // cast the return value to `T`. | |||
203 | template <typename T> | |||
204 | auto import(T *From) | |||
205 | -> std::conditional_t<std::is_base_of<Type, T>::value, | |||
206 | Expected<const T *>, Expected<T *>> { | |||
207 | auto ToOrErr = Importer.Import(From); | |||
| ||||
208 | if (!ToOrErr) | |||
209 | return ToOrErr.takeError(); | |||
210 | return cast_or_null<T>(*ToOrErr); | |||
211 | } | |||
212 | ||||
213 | template <typename T> | |||
214 | auto import(const T *From) { | |||
215 | return import(const_cast<T *>(From)); | |||
216 | } | |||
217 | ||||
218 | // Call the import function of ASTImporter for type `T`. | |||
219 | template <typename T> | |||
220 | Expected<T> import(const T &From) { | |||
221 | return Importer.Import(From); | |||
222 | } | |||
223 | ||||
224 | // Import an Optional<T> by importing the contained T, if any. | |||
225 | template<typename T> | |||
226 | Expected<Optional<T>> import(Optional<T> From) { | |||
227 | if (!From) | |||
228 | return Optional<T>(); | |||
229 | return import(*From); | |||
230 | } | |||
231 | ||||
232 | ExplicitSpecifier importExplicitSpecifier(Error &Err, | |||
233 | ExplicitSpecifier ESpec); | |||
234 | ||||
235 | // Wrapper for an overload set. | |||
236 | template <typename ToDeclT> struct CallOverloadedCreateFun { | |||
237 | template <typename... Args> decltype(auto) operator()(Args &&... args) { | |||
238 | return ToDeclT::Create(std::forward<Args>(args)...); | |||
239 | } | |||
240 | }; | |||
241 | ||||
242 | // Always use these functions to create a Decl during import. There are | |||
243 | // certain tasks which must be done after the Decl was created, e.g. we | |||
244 | // must immediately register that as an imported Decl. The parameter `ToD` | |||
245 | // will be set to the newly created Decl or if had been imported before | |||
246 | // then to the already imported Decl. Returns a bool value set to true if | |||
247 | // the `FromD` had been imported before. | |||
248 | template <typename ToDeclT, typename FromDeclT, typename... Args> | |||
249 | LLVM_NODISCARD[[clang::warn_unused_result]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, | |||
250 | Args &&... args) { | |||
251 | // There may be several overloads of ToDeclT::Create. We must make sure | |||
252 | // to call the one which would be chosen by the arguments, thus we use a | |||
253 | // wrapper for the overload set. | |||
254 | CallOverloadedCreateFun<ToDeclT> OC; | |||
255 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, | |||
256 | std::forward<Args>(args)...); | |||
257 | } | |||
258 | // Use this overload if a special Type is needed to be created. E.g if we | |||
259 | // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl` | |||
260 | // then: | |||
261 | // TypedefNameDecl *ToTypedef; | |||
262 | // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...); | |||
263 | template <typename NewDeclT, typename ToDeclT, typename FromDeclT, | |||
264 | typename... Args> | |||
265 | LLVM_NODISCARD[[clang::warn_unused_result]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, | |||
266 | Args &&... args) { | |||
267 | CallOverloadedCreateFun<NewDeclT> OC; | |||
268 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, | |||
269 | std::forward<Args>(args)...); | |||
270 | } | |||
271 | // Use this version if a special create function must be | |||
272 | // used, e.g. CXXRecordDecl::CreateLambda . | |||
273 | template <typename ToDeclT, typename CreateFunT, typename FromDeclT, | |||
274 | typename... Args> | |||
275 | LLVM_NODISCARD[[clang::warn_unused_result]] bool | |||
276 | GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun, | |||
277 | FromDeclT *FromD, Args &&... args) { | |||
278 | if (Importer.getImportDeclErrorIfAny(FromD)) { | |||
279 | ToD = nullptr; | |||
280 | return true; // Already imported but with error. | |||
281 | } | |||
282 | ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD)); | |||
283 | if (ToD) | |||
284 | return true; // Already imported. | |||
285 | ToD = CreateFun(std::forward<Args>(args)...); | |||
286 | // Keep track of imported Decls. | |||
287 | Importer.RegisterImportedDecl(FromD, ToD); | |||
288 | InitializeImportedDecl(FromD, ToD); | |||
289 | return false; // A new Decl is created. | |||
290 | } | |||
291 | ||||
292 | void InitializeImportedDecl(Decl *FromD, Decl *ToD) { | |||
293 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; | |||
294 | if (FromD->isUsed()) | |||
295 | ToD->setIsUsed(); | |||
296 | if (FromD->isImplicit()) | |||
297 | ToD->setImplicit(); | |||
298 | } | |||
299 | ||||
300 | // Check if we have found an existing definition. Returns with that | |||
301 | // definition if yes, otherwise returns null. | |||
302 | Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) { | |||
303 | const FunctionDecl *Definition = nullptr; | |||
304 | if (D->doesThisDeclarationHaveABody() && | |||
305 | FoundFunction->hasBody(Definition)) | |||
306 | return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition)); | |||
307 | return nullptr; | |||
308 | } | |||
309 | ||||
310 | void addDeclToContexts(Decl *FromD, Decl *ToD) { | |||
311 | if (Importer.isMinimalImport()) { | |||
312 | // In minimal import case the decl must be added even if it is not | |||
313 | // contained in original context, for LLDB compatibility. | |||
314 | // FIXME: Check if a better solution is possible. | |||
315 | if (!FromD->getDescribedTemplate() && | |||
316 | FromD->getFriendObjectKind() == Decl::FOK_None) | |||
317 | ToD->getLexicalDeclContext()->addDeclInternal(ToD); | |||
318 | return; | |||
319 | } | |||
320 | ||||
321 | DeclContext *FromDC = FromD->getDeclContext(); | |||
322 | DeclContext *FromLexicalDC = FromD->getLexicalDeclContext(); | |||
323 | DeclContext *ToDC = ToD->getDeclContext(); | |||
324 | DeclContext *ToLexicalDC = ToD->getLexicalDeclContext(); | |||
325 | ||||
326 | bool Visible = false; | |||
327 | if (FromDC->containsDeclAndLoad(FromD)) { | |||
328 | ToDC->addDeclInternal(ToD); | |||
329 | Visible = true; | |||
330 | } | |||
331 | if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) { | |||
332 | ToLexicalDC->addDeclInternal(ToD); | |||
333 | Visible = true; | |||
334 | } | |||
335 | ||||
336 | // If the Decl was added to any context, it was made already visible. | |||
337 | // Otherwise it is still possible that it should be visible. | |||
338 | if (!Visible) { | |||
339 | if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) { | |||
340 | auto *ToNamed = cast<NamedDecl>(ToD); | |||
341 | DeclContextLookupResult FromLookup = | |||
342 | FromDC->lookup(FromNamed->getDeclName()); | |||
343 | if (llvm::is_contained(FromLookup, FromNamed)) | |||
344 | ToDC->makeDeclVisibleInContext(ToNamed); | |||
345 | } | |||
346 | } | |||
347 | } | |||
348 | ||||
349 | void updateLookupTableForTemplateParameters(TemplateParameterList &Params, | |||
350 | DeclContext *OldDC) { | |||
351 | ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable(); | |||
352 | if (!LT) | |||
353 | return; | |||
354 | ||||
355 | for (NamedDecl *TP : Params) | |||
356 | LT->update(TP, OldDC); | |||
357 | } | |||
358 | ||||
359 | void updateLookupTableForTemplateParameters(TemplateParameterList &Params) { | |||
360 | updateLookupTableForTemplateParameters( | |||
361 | Params, Importer.getToContext().getTranslationUnitDecl()); | |||
362 | } | |||
363 | ||||
364 | public: | |||
365 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} | |||
366 | ||||
367 | using TypeVisitor<ASTNodeImporter, ExpectedType>::Visit; | |||
368 | using DeclVisitor<ASTNodeImporter, ExpectedDecl>::Visit; | |||
369 | using StmtVisitor<ASTNodeImporter, ExpectedStmt>::Visit; | |||
370 | ||||
371 | // Importing types | |||
372 | ExpectedType VisitType(const Type *T); | |||
373 | ExpectedType VisitAtomicType(const AtomicType *T); | |||
374 | ExpectedType VisitBuiltinType(const BuiltinType *T); | |||
375 | ExpectedType VisitDecayedType(const DecayedType *T); | |||
376 | ExpectedType VisitComplexType(const ComplexType *T); | |||
377 | ExpectedType VisitPointerType(const PointerType *T); | |||
378 | ExpectedType VisitBlockPointerType(const BlockPointerType *T); | |||
379 | ExpectedType VisitLValueReferenceType(const LValueReferenceType *T); | |||
380 | ExpectedType VisitRValueReferenceType(const RValueReferenceType *T); | |||
381 | ExpectedType VisitMemberPointerType(const MemberPointerType *T); | |||
382 | ExpectedType VisitConstantArrayType(const ConstantArrayType *T); | |||
383 | ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T); | |||
384 | ExpectedType VisitVariableArrayType(const VariableArrayType *T); | |||
385 | ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T); | |||
386 | // FIXME: DependentSizedExtVectorType | |||
387 | ExpectedType VisitVectorType(const VectorType *T); | |||
388 | ExpectedType VisitExtVectorType(const ExtVectorType *T); | |||
389 | ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T); | |||
390 | ExpectedType VisitFunctionProtoType(const FunctionProtoType *T); | |||
391 | ExpectedType VisitUnresolvedUsingType(const UnresolvedUsingType *T); | |||
392 | ExpectedType VisitParenType(const ParenType *T); | |||
393 | ExpectedType VisitTypedefType(const TypedefType *T); | |||
394 | ExpectedType VisitTypeOfExprType(const TypeOfExprType *T); | |||
395 | // FIXME: DependentTypeOfExprType | |||
396 | ExpectedType VisitTypeOfType(const TypeOfType *T); | |||
397 | ExpectedType VisitUsingType(const UsingType *T); | |||
398 | ExpectedType VisitDecltypeType(const DecltypeType *T); | |||
399 | ExpectedType VisitUnaryTransformType(const UnaryTransformType *T); | |||
400 | ExpectedType VisitAutoType(const AutoType *T); | |||
401 | ExpectedType VisitDeducedTemplateSpecializationType( | |||
402 | const DeducedTemplateSpecializationType *T); | |||
403 | ExpectedType VisitInjectedClassNameType(const InjectedClassNameType *T); | |||
404 | // FIXME: DependentDecltypeType | |||
405 | ExpectedType VisitRecordType(const RecordType *T); | |||
406 | ExpectedType VisitEnumType(const EnumType *T); | |||
407 | ExpectedType VisitAttributedType(const AttributedType *T); | |||
408 | ExpectedType VisitTemplateTypeParmType(const TemplateTypeParmType *T); | |||
409 | ExpectedType VisitSubstTemplateTypeParmType( | |||
410 | const SubstTemplateTypeParmType *T); | |||
411 | ExpectedType | |||
412 | VisitSubstTemplateTypeParmPackType(const SubstTemplateTypeParmPackType *T); | |||
413 | ExpectedType VisitTemplateSpecializationType( | |||
414 | const TemplateSpecializationType *T); | |||
415 | ExpectedType VisitElaboratedType(const ElaboratedType *T); | |||
416 | ExpectedType VisitDependentNameType(const DependentNameType *T); | |||
417 | ExpectedType VisitPackExpansionType(const PackExpansionType *T); | |||
418 | ExpectedType VisitDependentTemplateSpecializationType( | |||
419 | const DependentTemplateSpecializationType *T); | |||
420 | ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T); | |||
421 | ExpectedType VisitObjCObjectType(const ObjCObjectType *T); | |||
422 | ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); | |||
423 | ||||
424 | // Importing declarations | |||
425 | Error ImportDeclParts(NamedDecl *D, DeclarationName &Name, NamedDecl *&ToD, | |||
426 | SourceLocation &Loc); | |||
427 | Error ImportDeclParts( | |||
428 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, | |||
429 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc); | |||
430 | Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); | |||
431 | Error ImportDeclarationNameLoc( | |||
432 | const DeclarationNameInfo &From, DeclarationNameInfo &To); | |||
433 | Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); | |||
434 | Error ImportDeclContext( | |||
435 | Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC); | |||
436 | Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To); | |||
437 | ||||
438 | Expected<CXXCastPath> ImportCastPath(CastExpr *E); | |||
439 | Expected<APValue> ImportAPValue(const APValue &FromValue); | |||
440 | ||||
441 | using Designator = DesignatedInitExpr::Designator; | |||
442 | ||||
443 | /// What we should import from the definition. | |||
444 | enum ImportDefinitionKind { | |||
445 | /// Import the default subset of the definition, which might be | |||
446 | /// nothing (if minimal import is set) or might be everything (if minimal | |||
447 | /// import is not set). | |||
448 | IDK_Default, | |||
449 | /// Import everything. | |||
450 | IDK_Everything, | |||
451 | /// Import only the bare bones needed to establish a valid | |||
452 | /// DeclContext. | |||
453 | IDK_Basic | |||
454 | }; | |||
455 | ||||
456 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { | |||
457 | return IDK == IDK_Everything || | |||
458 | (IDK == IDK_Default && !Importer.isMinimalImport()); | |||
459 | } | |||
460 | ||||
461 | Error ImportInitializer(VarDecl *From, VarDecl *To); | |||
462 | Error ImportDefinition( | |||
463 | RecordDecl *From, RecordDecl *To, | |||
464 | ImportDefinitionKind Kind = IDK_Default); | |||
465 | Error ImportDefinition( | |||
466 | EnumDecl *From, EnumDecl *To, | |||
467 | ImportDefinitionKind Kind = IDK_Default); | |||
468 | Error ImportDefinition( | |||
469 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, | |||
470 | ImportDefinitionKind Kind = IDK_Default); | |||
471 | Error ImportDefinition( | |||
472 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, | |||
473 | ImportDefinitionKind Kind = IDK_Default); | |||
474 | Error ImportTemplateArguments( | |||
475 | const TemplateArgument *FromArgs, unsigned NumFromArgs, | |||
476 | SmallVectorImpl<TemplateArgument> &ToArgs); | |||
477 | Expected<TemplateArgument> | |||
478 | ImportTemplateArgument(const TemplateArgument &From); | |||
479 | ||||
480 | template <typename InContainerTy> | |||
481 | Error ImportTemplateArgumentListInfo( | |||
482 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo); | |||
483 | ||||
484 | template<typename InContainerTy> | |||
485 | Error ImportTemplateArgumentListInfo( | |||
486 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, | |||
487 | const InContainerTy &Container, TemplateArgumentListInfo &Result); | |||
488 | ||||
489 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; | |||
490 | using FunctionTemplateAndArgsTy = | |||
491 | std::tuple<FunctionTemplateDecl *, TemplateArgsTy>; | |||
492 | Expected<FunctionTemplateAndArgsTy> | |||
493 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( | |||
494 | FunctionDecl *FromFD); | |||
495 | Error ImportTemplateParameterLists(const DeclaratorDecl *FromD, | |||
496 | DeclaratorDecl *ToD); | |||
497 | ||||
498 | Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); | |||
499 | ||||
500 | Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD); | |||
501 | ||||
502 | Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam, | |||
503 | ParmVarDecl *ToParam); | |||
504 | ||||
505 | Expected<InheritedConstructor> | |||
506 | ImportInheritedConstructor(const InheritedConstructor &From); | |||
507 | ||||
508 | template <typename T> | |||
509 | bool hasSameVisibilityContextAndLinkage(T *Found, T *From); | |||
510 | ||||
511 | bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true); | |||
512 | ExpectedDecl VisitDecl(Decl *D); | |||
513 | ExpectedDecl VisitImportDecl(ImportDecl *D); | |||
514 | ExpectedDecl VisitEmptyDecl(EmptyDecl *D); | |||
515 | ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D); | |||
516 | ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D); | |||
517 | ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D); | |||
518 | ExpectedDecl VisitBindingDecl(BindingDecl *D); | |||
519 | ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D); | |||
520 | ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D); | |||
521 | ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); | |||
522 | ExpectedDecl VisitTypedefDecl(TypedefDecl *D); | |||
523 | ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D); | |||
524 | ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); | |||
525 | ExpectedDecl VisitLabelDecl(LabelDecl *D); | |||
526 | ExpectedDecl VisitEnumDecl(EnumDecl *D); | |||
527 | ExpectedDecl VisitRecordDecl(RecordDecl *D); | |||
528 | ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D); | |||
529 | ExpectedDecl VisitFunctionDecl(FunctionDecl *D); | |||
530 | ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D); | |||
531 | ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); | |||
532 | ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); | |||
533 | ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); | |||
534 | ExpectedDecl VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D); | |||
535 | ExpectedDecl VisitFieldDecl(FieldDecl *D); | |||
536 | ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); | |||
537 | ExpectedDecl VisitFriendDecl(FriendDecl *D); | |||
538 | ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D); | |||
539 | ExpectedDecl VisitVarDecl(VarDecl *D); | |||
540 | ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D); | |||
541 | ExpectedDecl VisitParmVarDecl(ParmVarDecl *D); | |||
542 | ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D); | |||
543 | ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); | |||
544 | ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D); | |||
545 | ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D); | |||
546 | ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D); | |||
547 | ExpectedDecl VisitUsingDecl(UsingDecl *D); | |||
548 | ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D); | |||
549 | ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D); | |||
550 | ExpectedDecl ImportUsingShadowDecls(BaseUsingDecl *D, BaseUsingDecl *ToSI); | |||
551 | ExpectedDecl VisitUsingEnumDecl(UsingEnumDecl *D); | |||
552 | ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); | |||
553 | ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); | |||
554 | ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D); | |||
555 | ExpectedDecl | |||
556 | VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D); | |||
557 | ||||
558 | Expected<ObjCTypeParamList *> | |||
559 | ImportObjCTypeParamList(ObjCTypeParamList *list); | |||
560 | ||||
561 | ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); | |||
562 | ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); | |||
563 | ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D); | |||
564 | ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D); | |||
565 | ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); | |||
566 | ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); | |||
567 | ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); | |||
568 | ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); | |||
569 | ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D); | |||
570 | ExpectedDecl VisitClassTemplateSpecializationDecl( | |||
571 | ClassTemplateSpecializationDecl *D); | |||
572 | ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D); | |||
573 | ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); | |||
574 | ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D); | |||
575 | ||||
576 | // Importing statements | |||
577 | ExpectedStmt VisitStmt(Stmt *S); | |||
578 | ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S); | |||
579 | ExpectedStmt VisitDeclStmt(DeclStmt *S); | |||
580 | ExpectedStmt VisitNullStmt(NullStmt *S); | |||
581 | ExpectedStmt VisitCompoundStmt(CompoundStmt *S); | |||
582 | ExpectedStmt VisitCaseStmt(CaseStmt *S); | |||
583 | ExpectedStmt VisitDefaultStmt(DefaultStmt *S); | |||
584 | ExpectedStmt VisitLabelStmt(LabelStmt *S); | |||
585 | ExpectedStmt VisitAttributedStmt(AttributedStmt *S); | |||
586 | ExpectedStmt VisitIfStmt(IfStmt *S); | |||
587 | ExpectedStmt VisitSwitchStmt(SwitchStmt *S); | |||
588 | ExpectedStmt VisitWhileStmt(WhileStmt *S); | |||
589 | ExpectedStmt VisitDoStmt(DoStmt *S); | |||
590 | ExpectedStmt VisitForStmt(ForStmt *S); | |||
591 | ExpectedStmt VisitGotoStmt(GotoStmt *S); | |||
592 | ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S); | |||
593 | ExpectedStmt VisitContinueStmt(ContinueStmt *S); | |||
594 | ExpectedStmt VisitBreakStmt(BreakStmt *S); | |||
595 | ExpectedStmt VisitReturnStmt(ReturnStmt *S); | |||
596 | // FIXME: MSAsmStmt | |||
597 | // FIXME: SEHExceptStmt | |||
598 | // FIXME: SEHFinallyStmt | |||
599 | // FIXME: SEHTryStmt | |||
600 | // FIXME: SEHLeaveStmt | |||
601 | // FIXME: CapturedStmt | |||
602 | ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S); | |||
603 | ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S); | |||
604 | ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S); | |||
605 | // FIXME: MSDependentExistsStmt | |||
606 | ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); | |||
607 | ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); | |||
608 | ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); | |||
609 | ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S); | |||
610 | ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); | |||
611 | ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); | |||
612 | ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); | |||
613 | ||||
614 | // Importing expressions | |||
615 | ExpectedStmt VisitExpr(Expr *E); | |||
616 | ExpectedStmt VisitSourceLocExpr(SourceLocExpr *E); | |||
617 | ExpectedStmt VisitVAArgExpr(VAArgExpr *E); | |||
618 | ExpectedStmt VisitChooseExpr(ChooseExpr *E); | |||
619 | ExpectedStmt VisitShuffleVectorExpr(ShuffleVectorExpr *E); | |||
620 | ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E); | |||
621 | ExpectedStmt VisitGenericSelectionExpr(GenericSelectionExpr *E); | |||
622 | ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E); | |||
623 | ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E); | |||
624 | ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); | |||
625 | ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E); | |||
626 | ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); | |||
627 | ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E); | |||
628 | ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E); | |||
629 | ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E); | |||
630 | ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E); | |||
631 | ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E); | |||
632 | ExpectedStmt VisitStringLiteral(StringLiteral *E); | |||
633 | ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E); | |||
634 | ExpectedStmt VisitAtomicExpr(AtomicExpr *E); | |||
635 | ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E); | |||
636 | ExpectedStmt VisitConstantExpr(ConstantExpr *E); | |||
637 | ExpectedStmt VisitParenExpr(ParenExpr *E); | |||
638 | ExpectedStmt VisitParenListExpr(ParenListExpr *E); | |||
639 | ExpectedStmt VisitStmtExpr(StmtExpr *E); | |||
640 | ExpectedStmt VisitUnaryOperator(UnaryOperator *E); | |||
641 | ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); | |||
642 | ExpectedStmt VisitBinaryOperator(BinaryOperator *E); | |||
643 | ExpectedStmt VisitConditionalOperator(ConditionalOperator *E); | |||
644 | ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E); | |||
645 | ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E); | |||
646 | ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); | |||
647 | ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E); | |||
648 | ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E); | |||
649 | ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E); | |||
650 | ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E); | |||
651 | ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E); | |||
652 | ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE); | |||
653 | ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E); | |||
654 | ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E); | |||
655 | ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); | |||
656 | ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); | |||
657 | ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); | |||
658 | ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); | |||
659 | ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); | |||
660 | ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E); | |||
661 | ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E); | |||
662 | ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E); | |||
663 | ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E); | |||
664 | ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E); | |||
665 | ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E); | |||
666 | ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); | |||
667 | ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); | |||
668 | ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); | |||
669 | ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); | |||
670 | ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); | |||
671 | ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E); | |||
672 | ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E); | |||
673 | ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); | |||
674 | ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); | |||
675 | ExpectedStmt VisitMemberExpr(MemberExpr *E); | |||
676 | ExpectedStmt VisitCallExpr(CallExpr *E); | |||
677 | ExpectedStmt VisitLambdaExpr(LambdaExpr *LE); | |||
678 | ExpectedStmt VisitInitListExpr(InitListExpr *E); | |||
679 | ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); | |||
680 | ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); | |||
681 | ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); | |||
682 | ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); | |||
683 | ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); | |||
684 | ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E); | |||
685 | ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); | |||
686 | ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); | |||
687 | ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); | |||
688 | ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E); | |||
689 | ||||
690 | // Helper for chaining together multiple imports. If an error is detected, | |||
691 | // subsequent imports will return default constructed nodes, so that failure | |||
692 | // can be detected with a single conditional branch after a sequence of | |||
693 | // imports. | |||
694 | template <typename T> T importChecked(Error &Err, const T &From) { | |||
695 | // Don't attempt to import nodes if we hit an error earlier. | |||
696 | if (Err) | |||
697 | return T{}; | |||
698 | Expected<T> MaybeVal = import(From); | |||
699 | if (!MaybeVal) { | |||
700 | Err = MaybeVal.takeError(); | |||
701 | return T{}; | |||
702 | } | |||
703 | return *MaybeVal; | |||
704 | } | |||
705 | ||||
706 | template<typename IIter, typename OIter> | |||
707 | Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { | |||
708 | using ItemT = std::remove_reference_t<decltype(*Obegin)>; | |||
709 | for (; Ibegin != Iend; ++Ibegin, ++Obegin) { | |||
710 | Expected<ItemT> ToOrErr = import(*Ibegin); | |||
711 | if (!ToOrErr) | |||
712 | return ToOrErr.takeError(); | |||
713 | *Obegin = *ToOrErr; | |||
714 | } | |||
715 | return Error::success(); | |||
716 | } | |||
717 | ||||
718 | // Import every item from a container structure into an output container. | |||
719 | // If error occurs, stops at first error and returns the error. | |||
720 | // The output container should have space for all needed elements (it is not | |||
721 | // expanded, new items are put into from the beginning). | |||
722 | template<typename InContainerTy, typename OutContainerTy> | |||
723 | Error ImportContainerChecked( | |||
724 | const InContainerTy &InContainer, OutContainerTy &OutContainer) { | |||
725 | return ImportArrayChecked( | |||
726 | InContainer.begin(), InContainer.end(), OutContainer.begin()); | |||
727 | } | |||
728 | ||||
729 | template<typename InContainerTy, typename OIter> | |||
730 | Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { | |||
731 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); | |||
732 | } | |||
733 | ||||
734 | Error ImportOverriddenMethods(CXXMethodDecl *ToMethod, | |||
735 | CXXMethodDecl *FromMethod); | |||
736 | ||||
737 | Expected<FunctionDecl *> FindFunctionTemplateSpecialization( | |||
738 | FunctionDecl *FromFD); | |||
739 | ||||
740 | // Returns true if the given function has a placeholder return type and | |||
741 | // that type is declared inside the body of the function. | |||
742 | // E.g. auto f() { struct X{}; return X(); } | |||
743 | bool hasAutoReturnTypeDeclaredInside(FunctionDecl *D); | |||
744 | }; | |||
745 | ||||
746 | template <typename InContainerTy> | |||
747 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( | |||
748 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, | |||
749 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { | |||
750 | auto ToLAngleLocOrErr = import(FromLAngleLoc); | |||
751 | if (!ToLAngleLocOrErr) | |||
752 | return ToLAngleLocOrErr.takeError(); | |||
753 | auto ToRAngleLocOrErr = import(FromRAngleLoc); | |||
754 | if (!ToRAngleLocOrErr) | |||
755 | return ToRAngleLocOrErr.takeError(); | |||
756 | ||||
757 | TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr); | |||
758 | if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo)) | |||
759 | return Err; | |||
760 | Result = ToTAInfo; | |||
761 | return Error::success(); | |||
762 | } | |||
763 | ||||
764 | template <> | |||
765 | Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( | |||
766 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { | |||
767 | return ImportTemplateArgumentListInfo( | |||
768 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); | |||
769 | } | |||
770 | ||||
771 | template <> | |||
772 | Error ASTNodeImporter::ImportTemplateArgumentListInfo< | |||
773 | ASTTemplateArgumentListInfo>( | |||
774 | const ASTTemplateArgumentListInfo &From, | |||
775 | TemplateArgumentListInfo &Result) { | |||
776 | return ImportTemplateArgumentListInfo( | |||
777 | From.LAngleLoc, From.RAngleLoc, From.arguments(), Result); | |||
778 | } | |||
779 | ||||
780 | Expected<ASTNodeImporter::FunctionTemplateAndArgsTy> | |||
781 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( | |||
782 | FunctionDecl *FromFD) { | |||
783 | assert(FromFD->getTemplatedKind() ==(static_cast <bool> (FromFD->getTemplatedKind() == FunctionDecl ::TK_FunctionTemplateSpecialization) ? void (0) : __assert_fail ("FromFD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplateSpecialization" , "clang/lib/AST/ASTImporter.cpp", 784, __extension__ __PRETTY_FUNCTION__ )) | |||
784 | FunctionDecl::TK_FunctionTemplateSpecialization)(static_cast <bool> (FromFD->getTemplatedKind() == FunctionDecl ::TK_FunctionTemplateSpecialization) ? void (0) : __assert_fail ("FromFD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplateSpecialization" , "clang/lib/AST/ASTImporter.cpp", 784, __extension__ __PRETTY_FUNCTION__ )); | |||
785 | ||||
786 | FunctionTemplateAndArgsTy Result; | |||
787 | ||||
788 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); | |||
789 | if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate())) | |||
790 | return std::move(Err); | |||
791 | ||||
792 | // Import template arguments. | |||
793 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); | |||
794 | if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), | |||
795 | std::get<1>(Result))) | |||
796 | return std::move(Err); | |||
797 | ||||
798 | return Result; | |||
799 | } | |||
800 | ||||
801 | template <> | |||
802 | Expected<TemplateParameterList *> | |||
803 | ASTNodeImporter::import(TemplateParameterList *From) { | |||
804 | SmallVector<NamedDecl *, 4> To(From->size()); | |||
805 | if (Error Err = ImportContainerChecked(*From, To)) | |||
806 | return std::move(Err); | |||
807 | ||||
808 | ExpectedExpr ToRequiresClause = import(From->getRequiresClause()); | |||
809 | if (!ToRequiresClause) | |||
810 | return ToRequiresClause.takeError(); | |||
811 | ||||
812 | auto ToTemplateLocOrErr = import(From->getTemplateLoc()); | |||
813 | if (!ToTemplateLocOrErr) | |||
814 | return ToTemplateLocOrErr.takeError(); | |||
815 | auto ToLAngleLocOrErr = import(From->getLAngleLoc()); | |||
816 | if (!ToLAngleLocOrErr) | |||
817 | return ToLAngleLocOrErr.takeError(); | |||
818 | auto ToRAngleLocOrErr = import(From->getRAngleLoc()); | |||
819 | if (!ToRAngleLocOrErr) | |||
820 | return ToRAngleLocOrErr.takeError(); | |||
821 | ||||
822 | return TemplateParameterList::Create( | |||
823 | Importer.getToContext(), | |||
824 | *ToTemplateLocOrErr, | |||
825 | *ToLAngleLocOrErr, | |||
826 | To, | |||
827 | *ToRAngleLocOrErr, | |||
828 | *ToRequiresClause); | |||
829 | } | |||
830 | ||||
831 | template <> | |||
832 | Expected<TemplateArgument> | |||
833 | ASTNodeImporter::import(const TemplateArgument &From) { | |||
834 | switch (From.getKind()) { | |||
835 | case TemplateArgument::Null: | |||
836 | return TemplateArgument(); | |||
837 | ||||
838 | case TemplateArgument::Type: { | |||
839 | ExpectedType ToTypeOrErr = import(From.getAsType()); | |||
840 | if (!ToTypeOrErr) | |||
841 | return ToTypeOrErr.takeError(); | |||
842 | return TemplateArgument(*ToTypeOrErr); | |||
843 | } | |||
844 | ||||
845 | case TemplateArgument::Integral: { | |||
846 | ExpectedType ToTypeOrErr = import(From.getIntegralType()); | |||
847 | if (!ToTypeOrErr) | |||
848 | return ToTypeOrErr.takeError(); | |||
849 | return TemplateArgument(From, *ToTypeOrErr); | |||
850 | } | |||
851 | ||||
852 | case TemplateArgument::Declaration: { | |||
853 | Expected<ValueDecl *> ToOrErr = import(From.getAsDecl()); | |||
854 | if (!ToOrErr) | |||
855 | return ToOrErr.takeError(); | |||
856 | ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); | |||
857 | if (!ToTypeOrErr) | |||
858 | return ToTypeOrErr.takeError(); | |||
859 | return TemplateArgument(*ToOrErr, *ToTypeOrErr); | |||
860 | } | |||
861 | ||||
862 | case TemplateArgument::NullPtr: { | |||
863 | ExpectedType ToTypeOrErr = import(From.getNullPtrType()); | |||
864 | if (!ToTypeOrErr) | |||
865 | return ToTypeOrErr.takeError(); | |||
866 | return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); | |||
867 | } | |||
868 | ||||
869 | case TemplateArgument::Template: { | |||
870 | Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate()); | |||
871 | if (!ToTemplateOrErr) | |||
872 | return ToTemplateOrErr.takeError(); | |||
873 | ||||
874 | return TemplateArgument(*ToTemplateOrErr); | |||
875 | } | |||
876 | ||||
877 | case TemplateArgument::TemplateExpansion: { | |||
878 | Expected<TemplateName> ToTemplateOrErr = | |||
879 | import(From.getAsTemplateOrTemplatePattern()); | |||
880 | if (!ToTemplateOrErr) | |||
881 | return ToTemplateOrErr.takeError(); | |||
882 | ||||
883 | return TemplateArgument( | |||
884 | *ToTemplateOrErr, From.getNumTemplateExpansions()); | |||
885 | } | |||
886 | ||||
887 | case TemplateArgument::Expression: | |||
888 | if (ExpectedExpr ToExpr = import(From.getAsExpr())) | |||
889 | return TemplateArgument(*ToExpr); | |||
890 | else | |||
891 | return ToExpr.takeError(); | |||
892 | ||||
893 | case TemplateArgument::Pack: { | |||
894 | SmallVector<TemplateArgument, 2> ToPack; | |||
895 | ToPack.reserve(From.pack_size()); | |||
896 | if (Error Err = ImportTemplateArguments( | |||
897 | From.pack_begin(), From.pack_size(), ToPack)) | |||
898 | return std::move(Err); | |||
899 | ||||
900 | return TemplateArgument( | |||
901 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); | |||
902 | } | |||
903 | } | |||
904 | ||||
905 | llvm_unreachable("Invalid template argument kind")::llvm::llvm_unreachable_internal("Invalid template argument kind" , "clang/lib/AST/ASTImporter.cpp", 905); | |||
906 | } | |||
907 | ||||
908 | template <> | |||
909 | Expected<TemplateArgumentLoc> | |||
910 | ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) { | |||
911 | Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument()); | |||
912 | if (!ArgOrErr) | |||
913 | return ArgOrErr.takeError(); | |||
914 | TemplateArgument Arg = *ArgOrErr; | |||
915 | ||||
916 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); | |||
917 | ||||
918 | TemplateArgumentLocInfo ToInfo; | |||
919 | if (Arg.getKind() == TemplateArgument::Expression) { | |||
920 | ExpectedExpr E = import(FromInfo.getAsExpr()); | |||
921 | if (!E) | |||
922 | return E.takeError(); | |||
923 | ToInfo = TemplateArgumentLocInfo(*E); | |||
924 | } else if (Arg.getKind() == TemplateArgument::Type) { | |||
925 | if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo())) | |||
926 | ToInfo = TemplateArgumentLocInfo(*TSIOrErr); | |||
927 | else | |||
928 | return TSIOrErr.takeError(); | |||
929 | } else { | |||
930 | auto ToTemplateQualifierLocOrErr = | |||
931 | import(FromInfo.getTemplateQualifierLoc()); | |||
932 | if (!ToTemplateQualifierLocOrErr) | |||
933 | return ToTemplateQualifierLocOrErr.takeError(); | |||
934 | auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc()); | |||
935 | if (!ToTemplateNameLocOrErr) | |||
936 | return ToTemplateNameLocOrErr.takeError(); | |||
937 | auto ToTemplateEllipsisLocOrErr = | |||
938 | import(FromInfo.getTemplateEllipsisLoc()); | |||
939 | if (!ToTemplateEllipsisLocOrErr) | |||
940 | return ToTemplateEllipsisLocOrErr.takeError(); | |||
941 | ToInfo = TemplateArgumentLocInfo( | |||
942 | Importer.getToContext(), *ToTemplateQualifierLocOrErr, | |||
943 | *ToTemplateNameLocOrErr, *ToTemplateEllipsisLocOrErr); | |||
944 | } | |||
945 | ||||
946 | return TemplateArgumentLoc(Arg, ToInfo); | |||
947 | } | |||
948 | ||||
949 | template <> | |||
950 | Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) { | |||
951 | if (DG.isNull()) | |||
952 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); | |||
953 | size_t NumDecls = DG.end() - DG.begin(); | |||
954 | SmallVector<Decl *, 1> ToDecls; | |||
955 | ToDecls.reserve(NumDecls); | |||
956 | for (Decl *FromD : DG) { | |||
957 | if (auto ToDOrErr = import(FromD)) | |||
958 | ToDecls.push_back(*ToDOrErr); | |||
959 | else | |||
960 | return ToDOrErr.takeError(); | |||
961 | } | |||
962 | return DeclGroupRef::Create(Importer.getToContext(), | |||
963 | ToDecls.begin(), | |||
964 | NumDecls); | |||
965 | } | |||
966 | ||||
967 | template <> | |||
968 | Expected<ASTNodeImporter::Designator> | |||
969 | ASTNodeImporter::import(const Designator &D) { | |||
970 | if (D.isFieldDesignator()) { | |||
971 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); | |||
972 | ||||
973 | ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc()); | |||
974 | if (!ToDotLocOrErr) | |||
975 | return ToDotLocOrErr.takeError(); | |||
976 | ||||
977 | ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc()); | |||
978 | if (!ToFieldLocOrErr) | |||
979 | return ToFieldLocOrErr.takeError(); | |||
980 | ||||
981 | return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr); | |||
982 | } | |||
983 | ||||
984 | ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc()); | |||
985 | if (!ToLBracketLocOrErr) | |||
986 | return ToLBracketLocOrErr.takeError(); | |||
987 | ||||
988 | ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc()); | |||
989 | if (!ToRBracketLocOrErr) | |||
990 | return ToRBracketLocOrErr.takeError(); | |||
991 | ||||
992 | if (D.isArrayDesignator()) | |||
993 | return Designator(D.getFirstExprIndex(), | |||
994 | *ToLBracketLocOrErr, *ToRBracketLocOrErr); | |||
995 | ||||
996 | ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc()); | |||
997 | if (!ToEllipsisLocOrErr) | |||
998 | return ToEllipsisLocOrErr.takeError(); | |||
999 | ||||
1000 | assert(D.isArrayRangeDesignator())(static_cast <bool> (D.isArrayRangeDesignator()) ? void (0) : __assert_fail ("D.isArrayRangeDesignator()", "clang/lib/AST/ASTImporter.cpp" , 1000, __extension__ __PRETTY_FUNCTION__)); | |||
1001 | return Designator( | |||
1002 | D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr, | |||
1003 | *ToRBracketLocOrErr); | |||
1004 | } | |||
1005 | ||||
1006 | template <> | |||
1007 | Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) { | |||
1008 | VarDecl *Var = nullptr; | |||
1009 | if (From.capturesVariable()) { | |||
1010 | if (auto VarOrErr = import(From.getCapturedVar())) | |||
1011 | Var = *VarOrErr; | |||
1012 | else | |||
1013 | return VarOrErr.takeError(); | |||
1014 | } | |||
1015 | ||||
1016 | auto LocationOrErr = import(From.getLocation()); | |||
1017 | if (!LocationOrErr) | |||
1018 | return LocationOrErr.takeError(); | |||
1019 | ||||
1020 | SourceLocation EllipsisLoc; | |||
1021 | if (From.isPackExpansion()) | |||
1022 | if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc())) | |||
1023 | return std::move(Err); | |||
1024 | ||||
1025 | return LambdaCapture( | |||
1026 | *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var, | |||
1027 | EllipsisLoc); | |||
1028 | } | |||
1029 | ||||
1030 | template <typename T> | |||
1031 | bool ASTNodeImporter::hasSameVisibilityContextAndLinkage(T *Found, T *From) { | |||
1032 | if (Found->getLinkageInternal() != From->getLinkageInternal()) | |||
1033 | return false; | |||
1034 | ||||
1035 | if (From->hasExternalFormalLinkage()) | |||
1036 | return Found->hasExternalFormalLinkage(); | |||
1037 | if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl()) | |||
1038 | return false; | |||
1039 | if (From->isInAnonymousNamespace()) | |||
1040 | return Found->isInAnonymousNamespace(); | |||
1041 | else | |||
1042 | return !Found->isInAnonymousNamespace() && | |||
1043 | !Found->hasExternalFormalLinkage(); | |||
1044 | } | |||
1045 | ||||
1046 | template <> | |||
1047 | bool ASTNodeImporter::hasSameVisibilityContextAndLinkage(TypedefNameDecl *Found, | |||
1048 | TypedefNameDecl *From) { | |||
1049 | if (Found->getLinkageInternal() != From->getLinkageInternal()) | |||
1050 | return false; | |||
1051 | ||||
1052 | if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace()) | |||
1053 | return Importer.GetFromTU(Found) == From->getTranslationUnitDecl(); | |||
1054 | return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace(); | |||
1055 | } | |||
1056 | ||||
1057 | } // namespace clang | |||
1058 | ||||
1059 | //---------------------------------------------------------------------------- | |||
1060 | // Import Types | |||
1061 | //---------------------------------------------------------------------------- | |||
1062 | ||||
1063 | using namespace clang; | |||
1064 | ||||
1065 | ExpectedType ASTNodeImporter::VisitType(const Type *T) { | |||
1066 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) | |||
1067 | << T->getTypeClassName(); | |||
1068 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
1069 | } | |||
1070 | ||||
1071 | ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ | |||
1072 | ExpectedType UnderlyingTypeOrErr = import(T->getValueType()); | |||
1073 | if (!UnderlyingTypeOrErr) | |||
1074 | return UnderlyingTypeOrErr.takeError(); | |||
1075 | ||||
1076 | return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr); | |||
1077 | } | |||
1078 | ||||
1079 | ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { | |||
1080 | switch (T->getKind()) { | |||
1081 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ | |||
1082 | case BuiltinType::Id: \ | |||
1083 | return Importer.getToContext().SingletonId; | |||
1084 | #include "clang/Basic/OpenCLImageTypes.def" | |||
1085 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ | |||
1086 | case BuiltinType::Id: \ | |||
1087 | return Importer.getToContext().Id##Ty; | |||
1088 | #include "clang/Basic/OpenCLExtensionTypes.def" | |||
1089 | #define SVE_TYPE(Name, Id, SingletonId) \ | |||
1090 | case BuiltinType::Id: \ | |||
1091 | return Importer.getToContext().SingletonId; | |||
1092 | #include "clang/Basic/AArch64SVEACLETypes.def" | |||
1093 | #define PPC_VECTOR_TYPE(Name, Id, Size) \ | |||
1094 | case BuiltinType::Id: \ | |||
1095 | return Importer.getToContext().Id##Ty; | |||
1096 | #include "clang/Basic/PPCTypes.def" | |||
1097 | #define RVV_TYPE(Name, Id, SingletonId) \ | |||
1098 | case BuiltinType::Id: \ | |||
1099 | return Importer.getToContext().SingletonId; | |||
1100 | #include "clang/Basic/RISCVVTypes.def" | |||
1101 | #define SHARED_SINGLETON_TYPE(Expansion) | |||
1102 | #define BUILTIN_TYPE(Id, SingletonId) \ | |||
1103 | case BuiltinType::Id: return Importer.getToContext().SingletonId; | |||
1104 | #include "clang/AST/BuiltinTypes.def" | |||
1105 | ||||
1106 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" | |||
1107 | // context supports C++. | |||
1108 | ||||
1109 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" | |||
1110 | // context supports ObjC. | |||
1111 | ||||
1112 | case BuiltinType::Char_U: | |||
1113 | // The context we're importing from has an unsigned 'char'. If we're | |||
1114 | // importing into a context with a signed 'char', translate to | |||
1115 | // 'unsigned char' instead. | |||
1116 | if (Importer.getToContext().getLangOpts().CharIsSigned) | |||
1117 | return Importer.getToContext().UnsignedCharTy; | |||
1118 | ||||
1119 | return Importer.getToContext().CharTy; | |||
1120 | ||||
1121 | case BuiltinType::Char_S: | |||
1122 | // The context we're importing from has an unsigned 'char'. If we're | |||
1123 | // importing into a context with a signed 'char', translate to | |||
1124 | // 'unsigned char' instead. | |||
1125 | if (!Importer.getToContext().getLangOpts().CharIsSigned) | |||
1126 | return Importer.getToContext().SignedCharTy; | |||
1127 | ||||
1128 | return Importer.getToContext().CharTy; | |||
1129 | ||||
1130 | case BuiltinType::WChar_S: | |||
1131 | case BuiltinType::WChar_U: | |||
1132 | // FIXME: If not in C++, shall we translate to the C equivalent of | |||
1133 | // wchar_t? | |||
1134 | return Importer.getToContext().WCharTy; | |||
1135 | } | |||
1136 | ||||
1137 | llvm_unreachable("Invalid BuiltinType Kind!")::llvm::llvm_unreachable_internal("Invalid BuiltinType Kind!" , "clang/lib/AST/ASTImporter.cpp", 1137); | |||
1138 | } | |||
1139 | ||||
1140 | ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { | |||
1141 | ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType()); | |||
1142 | if (!ToOriginalTypeOrErr) | |||
1143 | return ToOriginalTypeOrErr.takeError(); | |||
1144 | ||||
1145 | return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr); | |||
1146 | } | |||
1147 | ||||
1148 | ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) { | |||
1149 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | |||
1150 | if (!ToElementTypeOrErr) | |||
1151 | return ToElementTypeOrErr.takeError(); | |||
1152 | ||||
1153 | return Importer.getToContext().getComplexType(*ToElementTypeOrErr); | |||
1154 | } | |||
1155 | ||||
1156 | ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) { | |||
1157 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | |||
1158 | if (!ToPointeeTypeOrErr) | |||
1159 | return ToPointeeTypeOrErr.takeError(); | |||
1160 | ||||
1161 | return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr); | |||
1162 | } | |||
1163 | ||||
1164 | ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { | |||
1165 | // FIXME: Check for blocks support in "to" context. | |||
1166 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | |||
1167 | if (!ToPointeeTypeOrErr) | |||
1168 | return ToPointeeTypeOrErr.takeError(); | |||
1169 | ||||
1170 | return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr); | |||
1171 | } | |||
1172 | ||||
1173 | ExpectedType | |||
1174 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { | |||
1175 | // FIXME: Check for C++ support in "to" context. | |||
1176 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); | |||
1177 | if (!ToPointeeTypeOrErr) | |||
1178 | return ToPointeeTypeOrErr.takeError(); | |||
1179 | ||||
1180 | return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr); | |||
1181 | } | |||
1182 | ||||
1183 | ExpectedType | |||
1184 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { | |||
1185 | // FIXME: Check for C++0x support in "to" context. | |||
1186 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); | |||
1187 | if (!ToPointeeTypeOrErr) | |||
1188 | return ToPointeeTypeOrErr.takeError(); | |||
1189 | ||||
1190 | return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr); | |||
1191 | } | |||
1192 | ||||
1193 | ExpectedType | |||
1194 | ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { | |||
1195 | // FIXME: Check for C++ support in "to" context. | |||
1196 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | |||
1197 | if (!ToPointeeTypeOrErr) | |||
1198 | return ToPointeeTypeOrErr.takeError(); | |||
1199 | ||||
1200 | ExpectedTypePtr ClassTypeOrErr = import(T->getClass()); | |||
1201 | if (!ClassTypeOrErr) | |||
1202 | return ClassTypeOrErr.takeError(); | |||
1203 | ||||
1204 | return Importer.getToContext().getMemberPointerType(*ToPointeeTypeOrErr, | |||
1205 | *ClassTypeOrErr); | |||
1206 | } | |||
1207 | ||||
1208 | ExpectedType | |||
1209 | ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { | |||
1210 | Error Err = Error::success(); | |||
1211 | auto ToElementType = importChecked(Err, T->getElementType()); | |||
1212 | auto ToSizeExpr = importChecked(Err, T->getSizeExpr()); | |||
1213 | if (Err) | |||
1214 | return std::move(Err); | |||
1215 | ||||
1216 | return Importer.getToContext().getConstantArrayType( | |||
1217 | ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(), | |||
1218 | T->getIndexTypeCVRQualifiers()); | |||
1219 | } | |||
1220 | ||||
1221 | ExpectedType | |||
1222 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { | |||
1223 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | |||
1224 | if (!ToElementTypeOrErr) | |||
1225 | return ToElementTypeOrErr.takeError(); | |||
1226 | ||||
1227 | return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr, | |||
1228 | T->getSizeModifier(), | |||
1229 | T->getIndexTypeCVRQualifiers()); | |||
1230 | } | |||
1231 | ||||
1232 | ExpectedType | |||
1233 | ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { | |||
1234 | Error Err = Error::success(); | |||
1235 | QualType ToElementType = importChecked(Err, T->getElementType()); | |||
1236 | Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr()); | |||
1237 | SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange()); | |||
1238 | if (Err) | |||
1239 | return std::move(Err); | |||
1240 | return Importer.getToContext().getVariableArrayType( | |||
1241 | ToElementType, ToSizeExpr, T->getSizeModifier(), | |||
1242 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); | |||
1243 | } | |||
1244 | ||||
1245 | ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( | |||
1246 | const DependentSizedArrayType *T) { | |||
1247 | Error Err = Error::success(); | |||
1248 | QualType ToElementType = importChecked(Err, T->getElementType()); | |||
1249 | Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr()); | |||
1250 | SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange()); | |||
1251 | if (Err) | |||
1252 | return std::move(Err); | |||
1253 | // SizeExpr may be null if size is not specified directly. | |||
1254 | // For example, 'int a[]'. | |||
1255 | ||||
1256 | return Importer.getToContext().getDependentSizedArrayType( | |||
1257 | ToElementType, ToSizeExpr, T->getSizeModifier(), | |||
1258 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); | |||
1259 | } | |||
1260 | ||||
1261 | ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) { | |||
1262 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | |||
1263 | if (!ToElementTypeOrErr) | |||
1264 | return ToElementTypeOrErr.takeError(); | |||
1265 | ||||
1266 | return Importer.getToContext().getVectorType(*ToElementTypeOrErr, | |||
1267 | T->getNumElements(), | |||
1268 | T->getVectorKind()); | |||
1269 | } | |||
1270 | ||||
1271 | ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { | |||
1272 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | |||
1273 | if (!ToElementTypeOrErr) | |||
1274 | return ToElementTypeOrErr.takeError(); | |||
1275 | ||||
1276 | return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr, | |||
1277 | T->getNumElements()); | |||
1278 | } | |||
1279 | ||||
1280 | ExpectedType | |||
1281 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { | |||
1282 | // FIXME: What happens if we're importing a function without a prototype | |||
1283 | // into C++? Should we make it variadic? | |||
1284 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); | |||
1285 | if (!ToReturnTypeOrErr) | |||
1286 | return ToReturnTypeOrErr.takeError(); | |||
1287 | ||||
1288 | return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr, | |||
1289 | T->getExtInfo()); | |||
1290 | } | |||
1291 | ||||
1292 | ExpectedType | |||
1293 | ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { | |||
1294 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); | |||
1295 | if (!ToReturnTypeOrErr) | |||
1296 | return ToReturnTypeOrErr.takeError(); | |||
1297 | ||||
1298 | // Import argument types | |||
1299 | SmallVector<QualType, 4> ArgTypes; | |||
1300 | for (const auto &A : T->param_types()) { | |||
1301 | ExpectedType TyOrErr = import(A); | |||
1302 | if (!TyOrErr) | |||
1303 | return TyOrErr.takeError(); | |||
1304 | ArgTypes.push_back(*TyOrErr); | |||
1305 | } | |||
1306 | ||||
1307 | // Import exception types | |||
1308 | SmallVector<QualType, 4> ExceptionTypes; | |||
1309 | for (const auto &E : T->exceptions()) { | |||
1310 | ExpectedType TyOrErr = import(E); | |||
1311 | if (!TyOrErr) | |||
1312 | return TyOrErr.takeError(); | |||
1313 | ExceptionTypes.push_back(*TyOrErr); | |||
1314 | } | |||
1315 | ||||
1316 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); | |||
1317 | Error Err = Error::success(); | |||
1318 | FunctionProtoType::ExtProtoInfo ToEPI; | |||
1319 | ToEPI.ExtInfo = FromEPI.ExtInfo; | |||
1320 | ToEPI.Variadic = FromEPI.Variadic; | |||
1321 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; | |||
1322 | ToEPI.TypeQuals = FromEPI.TypeQuals; | |||
1323 | ToEPI.RefQualifier = FromEPI.RefQualifier; | |||
1324 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; | |||
1325 | ToEPI.ExceptionSpec.NoexceptExpr = | |||
1326 | importChecked(Err, FromEPI.ExceptionSpec.NoexceptExpr); | |||
1327 | ToEPI.ExceptionSpec.SourceDecl = | |||
1328 | importChecked(Err, FromEPI.ExceptionSpec.SourceDecl); | |||
1329 | ToEPI.ExceptionSpec.SourceTemplate = | |||
1330 | importChecked(Err, FromEPI.ExceptionSpec.SourceTemplate); | |||
1331 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; | |||
1332 | ||||
1333 | if (Err) | |||
1334 | return std::move(Err); | |||
1335 | ||||
1336 | return Importer.getToContext().getFunctionType( | |||
1337 | *ToReturnTypeOrErr, ArgTypes, ToEPI); | |||
1338 | } | |||
1339 | ||||
1340 | ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( | |||
1341 | const UnresolvedUsingType *T) { | |||
1342 | Error Err = Error::success(); | |||
1343 | auto ToD = importChecked(Err, T->getDecl()); | |||
1344 | auto ToPrevD = importChecked(Err, T->getDecl()->getPreviousDecl()); | |||
1345 | if (Err) | |||
1346 | return std::move(Err); | |||
1347 | ||||
1348 | return Importer.getToContext().getTypeDeclType( | |||
1349 | ToD, cast_or_null<TypeDecl>(ToPrevD)); | |||
1350 | } | |||
1351 | ||||
1352 | ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) { | |||
1353 | ExpectedType ToInnerTypeOrErr = import(T->getInnerType()); | |||
1354 | if (!ToInnerTypeOrErr) | |||
1355 | return ToInnerTypeOrErr.takeError(); | |||
1356 | ||||
1357 | return Importer.getToContext().getParenType(*ToInnerTypeOrErr); | |||
1358 | } | |||
1359 | ||||
1360 | ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { | |||
1361 | Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl()); | |||
1362 | if (!ToDeclOrErr) | |||
1363 | return ToDeclOrErr.takeError(); | |||
1364 | ||||
1365 | return Importer.getToContext().getTypeDeclType(*ToDeclOrErr); | |||
1366 | } | |||
1367 | ||||
1368 | ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { | |||
1369 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); | |||
1370 | if (!ToExprOrErr) | |||
1371 | return ToExprOrErr.takeError(); | |||
1372 | ||||
1373 | return Importer.getToContext().getTypeOfExprType(*ToExprOrErr); | |||
1374 | } | |||
1375 | ||||
1376 | ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { | |||
1377 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | |||
1378 | if (!ToUnderlyingTypeOrErr) | |||
1379 | return ToUnderlyingTypeOrErr.takeError(); | |||
1380 | ||||
1381 | return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr); | |||
1382 | } | |||
1383 | ||||
1384 | ExpectedType ASTNodeImporter::VisitUsingType(const UsingType *T) { | |||
1385 | Expected<UsingShadowDecl *> FoundOrErr = import(T->getFoundDecl()); | |||
1386 | if (!FoundOrErr) | |||
1387 | return FoundOrErr.takeError(); | |||
1388 | Expected<QualType> UnderlyingOrErr = import(T->getUnderlyingType()); | |||
1389 | if (!UnderlyingOrErr) | |||
1390 | return UnderlyingOrErr.takeError(); | |||
1391 | ||||
1392 | return Importer.getToContext().getUsingType(*FoundOrErr, *UnderlyingOrErr); | |||
1393 | } | |||
1394 | ||||
1395 | ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { | |||
1396 | // FIXME: Make sure that the "to" context supports C++0x! | |||
1397 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); | |||
1398 | if (!ToExprOrErr) | |||
1399 | return ToExprOrErr.takeError(); | |||
1400 | ||||
1401 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | |||
1402 | if (!ToUnderlyingTypeOrErr) | |||
1403 | return ToUnderlyingTypeOrErr.takeError(); | |||
1404 | ||||
1405 | return Importer.getToContext().getDecltypeType( | |||
1406 | *ToExprOrErr, *ToUnderlyingTypeOrErr); | |||
1407 | } | |||
1408 | ||||
1409 | ExpectedType | |||
1410 | ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { | |||
1411 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); | |||
1412 | if (!ToBaseTypeOrErr) | |||
1413 | return ToBaseTypeOrErr.takeError(); | |||
1414 | ||||
1415 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | |||
1416 | if (!ToUnderlyingTypeOrErr) | |||
1417 | return ToUnderlyingTypeOrErr.takeError(); | |||
1418 | ||||
1419 | return Importer.getToContext().getUnaryTransformType( | |||
1420 | *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind()); | |||
1421 | } | |||
1422 | ||||
1423 | ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) { | |||
1424 | // FIXME: Make sure that the "to" context supports C++11! | |||
1425 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); | |||
1426 | if (!ToDeducedTypeOrErr) | |||
1427 | return ToDeducedTypeOrErr.takeError(); | |||
1428 | ||||
1429 | ExpectedDecl ToTypeConstraintConcept = import(T->getTypeConstraintConcept()); | |||
1430 | if (!ToTypeConstraintConcept) | |||
1431 | return ToTypeConstraintConcept.takeError(); | |||
1432 | ||||
1433 | SmallVector<TemplateArgument, 2> ToTemplateArgs; | |||
1434 | ArrayRef<TemplateArgument> FromTemplateArgs = T->getTypeConstraintArguments(); | |||
1435 | if (Error Err = ImportTemplateArguments(FromTemplateArgs.data(), | |||
1436 | FromTemplateArgs.size(), | |||
1437 | ToTemplateArgs)) | |||
1438 | return std::move(Err); | |||
1439 | ||||
1440 | return Importer.getToContext().getAutoType( | |||
1441 | *ToDeducedTypeOrErr, T->getKeyword(), /*IsDependent*/false, | |||
1442 | /*IsPack=*/false, cast_or_null<ConceptDecl>(*ToTypeConstraintConcept), | |||
1443 | ToTemplateArgs); | |||
1444 | } | |||
1445 | ||||
1446 | ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType( | |||
1447 | const DeducedTemplateSpecializationType *T) { | |||
1448 | // FIXME: Make sure that the "to" context supports C++17! | |||
1449 | Expected<TemplateName> ToTemplateNameOrErr = import(T->getTemplateName()); | |||
1450 | if (!ToTemplateNameOrErr) | |||
1451 | return ToTemplateNameOrErr.takeError(); | |||
1452 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); | |||
1453 | if (!ToDeducedTypeOrErr) | |||
1454 | return ToDeducedTypeOrErr.takeError(); | |||
1455 | ||||
1456 | return Importer.getToContext().getDeducedTemplateSpecializationType( | |||
1457 | *ToTemplateNameOrErr, *ToDeducedTypeOrErr, T->isDependentType()); | |||
1458 | } | |||
1459 | ||||
1460 | ExpectedType ASTNodeImporter::VisitInjectedClassNameType( | |||
1461 | const InjectedClassNameType *T) { | |||
1462 | Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl()); | |||
1463 | if (!ToDeclOrErr) | |||
1464 | return ToDeclOrErr.takeError(); | |||
1465 | ||||
1466 | ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType()); | |||
1467 | if (!ToInjTypeOrErr) | |||
1468 | return ToInjTypeOrErr.takeError(); | |||
1469 | ||||
1470 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading | |||
1471 | // See comments in InjectedClassNameType definition for details | |||
1472 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); | |||
1473 | enum { | |||
1474 | TypeAlignmentInBits = 4, | |||
1475 | TypeAlignment = 1 << TypeAlignmentInBits | |||
1476 | }; | |||
1477 | ||||
1478 | return QualType(new (Importer.getToContext(), TypeAlignment) | |||
1479 | InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0); | |||
1480 | } | |||
1481 | ||||
1482 | ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) { | |||
1483 | Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl()); | |||
1484 | if (!ToDeclOrErr) | |||
1485 | return ToDeclOrErr.takeError(); | |||
1486 | ||||
1487 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); | |||
1488 | } | |||
1489 | ||||
1490 | ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) { | |||
1491 | Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl()); | |||
1492 | if (!ToDeclOrErr) | |||
1493 | return ToDeclOrErr.takeError(); | |||
1494 | ||||
1495 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); | |||
1496 | } | |||
1497 | ||||
1498 | ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { | |||
1499 | ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType()); | |||
1500 | if (!ToModifiedTypeOrErr) | |||
1501 | return ToModifiedTypeOrErr.takeError(); | |||
1502 | ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType()); | |||
1503 | if (!ToEquivalentTypeOrErr) | |||
1504 | return ToEquivalentTypeOrErr.takeError(); | |||
1505 | ||||
1506 | return Importer.getToContext().getAttributedType(T->getAttrKind(), | |||
1507 | *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr); | |||
1508 | } | |||
1509 | ||||
1510 | ExpectedType ASTNodeImporter::VisitTemplateTypeParmType( | |||
1511 | const TemplateTypeParmType *T) { | |||
1512 | Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl()); | |||
1513 | if (!ToDeclOrErr) | |||
1514 | return ToDeclOrErr.takeError(); | |||
1515 | ||||
1516 | return Importer.getToContext().getTemplateTypeParmType( | |||
1517 | T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr); | |||
1518 | } | |||
1519 | ||||
1520 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( | |||
1521 | const SubstTemplateTypeParmType *T) { | |||
1522 | Expected<const TemplateTypeParmType *> ReplacedOrErr = | |||
1523 | import(T->getReplacedParameter()); | |||
1524 | if (!ReplacedOrErr) | |||
1525 | return ReplacedOrErr.takeError(); | |||
1526 | ||||
1527 | ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); | |||
1528 | if (!ToReplacementTypeOrErr) | |||
1529 | return ToReplacementTypeOrErr.takeError(); | |||
1530 | ||||
1531 | return Importer.getToContext().getSubstTemplateTypeParmType( | |||
1532 | *ReplacedOrErr, ToReplacementTypeOrErr->getCanonicalType()); | |||
1533 | } | |||
1534 | ||||
1535 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType( | |||
1536 | const SubstTemplateTypeParmPackType *T) { | |||
1537 | Expected<const TemplateTypeParmType *> ReplacedOrErr = | |||
1538 | import(T->getReplacedParameter()); | |||
1539 | if (!ReplacedOrErr) | |||
1540 | return ReplacedOrErr.takeError(); | |||
1541 | ||||
1542 | Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack()); | |||
1543 | if (!ToArgumentPack) | |||
1544 | return ToArgumentPack.takeError(); | |||
1545 | ||||
1546 | return Importer.getToContext().getSubstTemplateTypeParmPackType( | |||
1547 | *ReplacedOrErr, *ToArgumentPack); | |||
1548 | } | |||
1549 | ||||
1550 | ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( | |||
1551 | const TemplateSpecializationType *T) { | |||
1552 | auto ToTemplateOrErr = import(T->getTemplateName()); | |||
1553 | if (!ToTemplateOrErr) | |||
1554 | return ToTemplateOrErr.takeError(); | |||
1555 | ||||
1556 | SmallVector<TemplateArgument, 2> ToTemplateArgs; | |||
1557 | if (Error Err = ImportTemplateArguments( | |||
1558 | T->getArgs(), T->getNumArgs(), ToTemplateArgs)) | |||
1559 | return std::move(Err); | |||
1560 | ||||
1561 | QualType ToCanonType; | |||
1562 | if (!T->isCanonicalUnqualified()) { | |||
1563 | QualType FromCanonType | |||
1564 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); | |||
1565 | if (ExpectedType TyOrErr = import(FromCanonType)) | |||
1566 | ToCanonType = *TyOrErr; | |||
1567 | else | |||
1568 | return TyOrErr.takeError(); | |||
1569 | } | |||
1570 | return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr, | |||
1571 | ToTemplateArgs, | |||
1572 | ToCanonType); | |||
1573 | } | |||
1574 | ||||
1575 | ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { | |||
1576 | // Note: the qualifier in an ElaboratedType is optional. | |||
1577 | auto ToQualifierOrErr = import(T->getQualifier()); | |||
1578 | if (!ToQualifierOrErr) | |||
1579 | return ToQualifierOrErr.takeError(); | |||
1580 | ||||
1581 | ExpectedType ToNamedTypeOrErr = import(T->getNamedType()); | |||
1582 | if (!ToNamedTypeOrErr) | |||
1583 | return ToNamedTypeOrErr.takeError(); | |||
1584 | ||||
1585 | Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl()); | |||
1586 | if (!ToOwnedTagDeclOrErr) | |||
1587 | return ToOwnedTagDeclOrErr.takeError(); | |||
1588 | ||||
1589 | return Importer.getToContext().getElaboratedType(T->getKeyword(), | |||
1590 | *ToQualifierOrErr, | |||
1591 | *ToNamedTypeOrErr, | |||
1592 | *ToOwnedTagDeclOrErr); | |||
1593 | } | |||
1594 | ||||
1595 | ExpectedType | |||
1596 | ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { | |||
1597 | ExpectedType ToPatternOrErr = import(T->getPattern()); | |||
1598 | if (!ToPatternOrErr) | |||
1599 | return ToPatternOrErr.takeError(); | |||
1600 | ||||
1601 | return Importer.getToContext().getPackExpansionType(*ToPatternOrErr, | |||
1602 | T->getNumExpansions(), | |||
1603 | /*ExpactPack=*/false); | |||
1604 | } | |||
1605 | ||||
1606 | ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType( | |||
1607 | const DependentTemplateSpecializationType *T) { | |||
1608 | auto ToQualifierOrErr = import(T->getQualifier()); | |||
1609 | if (!ToQualifierOrErr) | |||
1610 | return ToQualifierOrErr.takeError(); | |||
1611 | ||||
1612 | IdentifierInfo *ToName = Importer.Import(T->getIdentifier()); | |||
1613 | ||||
1614 | SmallVector<TemplateArgument, 2> ToPack; | |||
1615 | ToPack.reserve(T->getNumArgs()); | |||
1616 | if (Error Err = ImportTemplateArguments( | |||
1617 | T->getArgs(), T->getNumArgs(), ToPack)) | |||
1618 | return std::move(Err); | |||
1619 | ||||
1620 | return Importer.getToContext().getDependentTemplateSpecializationType( | |||
1621 | T->getKeyword(), *ToQualifierOrErr, ToName, ToPack); | |||
1622 | } | |||
1623 | ||||
1624 | ExpectedType | |||
1625 | ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { | |||
1626 | auto ToQualifierOrErr = import(T->getQualifier()); | |||
1627 | if (!ToQualifierOrErr) | |||
1628 | return ToQualifierOrErr.takeError(); | |||
1629 | ||||
1630 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); | |||
1631 | ||||
1632 | QualType Canon; | |||
1633 | if (T != T->getCanonicalTypeInternal().getTypePtr()) { | |||
1634 | if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal())) | |||
1635 | Canon = (*TyOrErr).getCanonicalType(); | |||
1636 | else | |||
1637 | return TyOrErr.takeError(); | |||
1638 | } | |||
1639 | ||||
1640 | return Importer.getToContext().getDependentNameType(T->getKeyword(), | |||
1641 | *ToQualifierOrErr, | |||
1642 | Name, Canon); | |||
1643 | } | |||
1644 | ||||
1645 | ExpectedType | |||
1646 | ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { | |||
1647 | Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl()); | |||
1648 | if (!ToDeclOrErr) | |||
1649 | return ToDeclOrErr.takeError(); | |||
1650 | ||||
1651 | return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr); | |||
1652 | } | |||
1653 | ||||
1654 | ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { | |||
1655 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); | |||
1656 | if (!ToBaseTypeOrErr) | |||
1657 | return ToBaseTypeOrErr.takeError(); | |||
1658 | ||||
1659 | SmallVector<QualType, 4> TypeArgs; | |||
1660 | for (auto TypeArg : T->getTypeArgsAsWritten()) { | |||
1661 | if (ExpectedType TyOrErr = import(TypeArg)) | |||
1662 | TypeArgs.push_back(*TyOrErr); | |||
1663 | else | |||
1664 | return TyOrErr.takeError(); | |||
1665 | } | |||
1666 | ||||
1667 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | |||
1668 | for (auto *P : T->quals()) { | |||
1669 | if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P)) | |||
1670 | Protocols.push_back(*ProtocolOrErr); | |||
1671 | else | |||
1672 | return ProtocolOrErr.takeError(); | |||
1673 | ||||
1674 | } | |||
1675 | ||||
1676 | return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs, | |||
1677 | Protocols, | |||
1678 | T->isKindOfTypeAsWritten()); | |||
1679 | } | |||
1680 | ||||
1681 | ExpectedType | |||
1682 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { | |||
1683 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | |||
1684 | if (!ToPointeeTypeOrErr) | |||
1685 | return ToPointeeTypeOrErr.takeError(); | |||
1686 | ||||
1687 | return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr); | |||
1688 | } | |||
1689 | ||||
1690 | //---------------------------------------------------------------------------- | |||
1691 | // Import Declarations | |||
1692 | //---------------------------------------------------------------------------- | |||
1693 | Error ASTNodeImporter::ImportDeclParts( | |||
1694 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, | |||
1695 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) { | |||
1696 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. | |||
1697 | // example: int struct_in_proto(struct data_t{int a;int b;} *d); | |||
1698 | // FIXME: We could support these constructs by importing a different type of | |||
1699 | // this parameter and by importing the original type of the parameter only | |||
1700 | // after the FunctionDecl is created. See | |||
1701 | // VisitFunctionDecl::UsedDifferentProtoType. | |||
1702 | DeclContext *OrigDC = D->getDeclContext(); | |||
1703 | FunctionDecl *FunDecl; | |||
1704 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && | |||
1705 | FunDecl->hasBody()) { | |||
1706 | auto getLeafPointeeType = [](const Type *T) { | |||
1707 | while (T->isPointerType() || T->isArrayType()) { | |||
1708 | T = T->getPointeeOrArrayElementType(); | |||
1709 | } | |||
1710 | return T; | |||
1711 | }; | |||
1712 | for (const ParmVarDecl *P : FunDecl->parameters()) { | |||
1713 | const Type *LeafT = | |||
1714 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); | |||
1715 | auto *RT = dyn_cast<RecordType>(LeafT); | |||
1716 | if (RT && RT->getDecl() == D) { | |||
1717 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | |||
1718 | << D->getDeclKindName(); | |||
1719 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
1720 | } | |||
1721 | } | |||
1722 | } | |||
1723 | ||||
1724 | // Import the context of this declaration. | |||
1725 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
1726 | return Err; | |||
1727 | ||||
1728 | // Import the name of this declaration. | |||
1729 | if (Error Err = importInto(Name, D->getDeclName())) | |||
1730 | return Err; | |||
1731 | ||||
1732 | // Import the location of this declaration. | |||
1733 | if (Error Err = importInto(Loc, D->getLocation())) | |||
1734 | return Err; | |||
1735 | ||||
1736 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); | |||
1737 | if (ToD) | |||
1738 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD)) | |||
1739 | return Err; | |||
1740 | ||||
1741 | return Error::success(); | |||
1742 | } | |||
1743 | ||||
1744 | Error ASTNodeImporter::ImportDeclParts(NamedDecl *D, DeclarationName &Name, | |||
1745 | NamedDecl *&ToD, SourceLocation &Loc) { | |||
1746 | ||||
1747 | // Import the name of this declaration. | |||
1748 | if (Error Err = importInto(Name, D->getDeclName())) | |||
1749 | return Err; | |||
1750 | ||||
1751 | // Import the location of this declaration. | |||
1752 | if (Error Err = importInto(Loc, D->getLocation())) | |||
1753 | return Err; | |||
1754 | ||||
1755 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); | |||
1756 | if (ToD) | |||
1757 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD)) | |||
1758 | return Err; | |||
1759 | ||||
1760 | return Error::success(); | |||
1761 | } | |||
1762 | ||||
1763 | Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { | |||
1764 | if (!FromD) | |||
1765 | return Error::success(); | |||
1766 | ||||
1767 | if (!ToD) | |||
1768 | if (Error Err = importInto(ToD, FromD)) | |||
1769 | return Err; | |||
1770 | ||||
1771 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { | |||
1772 | if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) { | |||
1773 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && | |||
1774 | !ToRecord->getDefinition()) { | |||
1775 | if (Error Err = ImportDefinition(FromRecord, ToRecord)) | |||
1776 | return Err; | |||
1777 | } | |||
1778 | } | |||
1779 | return Error::success(); | |||
1780 | } | |||
1781 | ||||
1782 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { | |||
1783 | if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) { | |||
1784 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { | |||
1785 | if (Error Err = ImportDefinition(FromEnum, ToEnum)) | |||
1786 | return Err; | |||
1787 | } | |||
1788 | } | |||
1789 | return Error::success(); | |||
1790 | } | |||
1791 | ||||
1792 | return Error::success(); | |||
1793 | } | |||
1794 | ||||
1795 | Error | |||
1796 | ASTNodeImporter::ImportDeclarationNameLoc( | |||
1797 | const DeclarationNameInfo &From, DeclarationNameInfo& To) { | |||
1798 | // NOTE: To.Name and To.Loc are already imported. | |||
1799 | // We only have to import To.LocInfo. | |||
1800 | switch (To.getName().getNameKind()) { | |||
1801 | case DeclarationName::Identifier: | |||
1802 | case DeclarationName::ObjCZeroArgSelector: | |||
1803 | case DeclarationName::ObjCOneArgSelector: | |||
1804 | case DeclarationName::ObjCMultiArgSelector: | |||
1805 | case DeclarationName::CXXUsingDirective: | |||
1806 | case DeclarationName::CXXDeductionGuideName: | |||
1807 | return Error::success(); | |||
1808 | ||||
1809 | case DeclarationName::CXXOperatorName: { | |||
1810 | if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange())) | |||
1811 | To.setCXXOperatorNameRange(*ToRangeOrErr); | |||
1812 | else | |||
1813 | return ToRangeOrErr.takeError(); | |||
1814 | return Error::success(); | |||
1815 | } | |||
1816 | case DeclarationName::CXXLiteralOperatorName: { | |||
1817 | if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc())) | |||
1818 | To.setCXXLiteralOperatorNameLoc(*LocOrErr); | |||
1819 | else | |||
1820 | return LocOrErr.takeError(); | |||
1821 | return Error::success(); | |||
1822 | } | |||
1823 | case DeclarationName::CXXConstructorName: | |||
1824 | case DeclarationName::CXXDestructorName: | |||
1825 | case DeclarationName::CXXConversionFunctionName: { | |||
1826 | if (auto ToTInfoOrErr = import(From.getNamedTypeInfo())) | |||
1827 | To.setNamedTypeInfo(*ToTInfoOrErr); | |||
1828 | else | |||
1829 | return ToTInfoOrErr.takeError(); | |||
1830 | return Error::success(); | |||
1831 | } | |||
1832 | } | |||
1833 | llvm_unreachable("Unknown name kind.")::llvm::llvm_unreachable_internal("Unknown name kind.", "clang/lib/AST/ASTImporter.cpp" , 1833); | |||
1834 | } | |||
1835 | ||||
1836 | Error | |||
1837 | ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { | |||
1838 | if (Importer.isMinimalImport() && !ForceImport) { | |||
1839 | auto ToDCOrErr = Importer.ImportContext(FromDC); | |||
1840 | return ToDCOrErr.takeError(); | |||
1841 | } | |||
1842 | ||||
1843 | // We use strict error handling in case of records and enums, but not | |||
1844 | // with e.g. namespaces. | |||
1845 | // | |||
1846 | // FIXME Clients of the ASTImporter should be able to choose an | |||
1847 | // appropriate error handling strategy for their needs. For instance, | |||
1848 | // they may not want to mark an entire namespace as erroneous merely | |||
1849 | // because there is an ODR error with two typedefs. As another example, | |||
1850 | // the client may allow EnumConstantDecls with same names but with | |||
1851 | // different values in two distinct translation units. | |||
1852 | ChildErrorHandlingStrategy HandleChildErrors(FromDC); | |||
1853 | ||||
1854 | Error ChildErrors = Error::success(); | |||
1855 | for (auto *From : FromDC->decls()) { | |||
1856 | ExpectedDecl ImportedOrErr = import(From); | |||
1857 | ||||
1858 | // If we are in the process of ImportDefinition(...) for a RecordDecl we | |||
1859 | // want to make sure that we are also completing each FieldDecl. There | |||
1860 | // are currently cases where this does not happen and this is correctness | |||
1861 | // fix since operations such as code generation will expect this to be so. | |||
1862 | if (ImportedOrErr) { | |||
1863 | FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From); | |||
1864 | Decl *ImportedDecl = *ImportedOrErr; | |||
1865 | FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl); | |||
1866 | if (FieldFrom && FieldTo) { | |||
1867 | RecordDecl *FromRecordDecl = nullptr; | |||
1868 | RecordDecl *ToRecordDecl = nullptr; | |||
1869 | // If we have a field that is an ArrayType we need to check if the array | |||
1870 | // element is a RecordDecl and if so we need to import the definition. | |||
1871 | if (FieldFrom->getType()->isArrayType()) { | |||
1872 | // getBaseElementTypeUnsafe(...) handles multi-dimensonal arrays for us. | |||
1873 | FromRecordDecl = FieldFrom->getType()->getBaseElementTypeUnsafe()->getAsRecordDecl(); | |||
1874 | ToRecordDecl = FieldTo->getType()->getBaseElementTypeUnsafe()->getAsRecordDecl(); | |||
1875 | } | |||
1876 | ||||
1877 | if (!FromRecordDecl || !ToRecordDecl) { | |||
1878 | const RecordType *RecordFrom = | |||
1879 | FieldFrom->getType()->getAs<RecordType>(); | |||
1880 | const RecordType *RecordTo = FieldTo->getType()->getAs<RecordType>(); | |||
1881 | ||||
1882 | if (RecordFrom && RecordTo) { | |||
1883 | FromRecordDecl = RecordFrom->getDecl(); | |||
1884 | ToRecordDecl = RecordTo->getDecl(); | |||
1885 | } | |||
1886 | } | |||
1887 | ||||
1888 | if (FromRecordDecl && ToRecordDecl) { | |||
1889 | if (FromRecordDecl->isCompleteDefinition() && | |||
1890 | !ToRecordDecl->isCompleteDefinition()) { | |||
1891 | Error Err = ImportDefinition(FromRecordDecl, ToRecordDecl); | |||
1892 | HandleChildErrors.handleChildImportResult(ChildErrors, | |||
1893 | std::move(Err)); | |||
1894 | } | |||
1895 | } | |||
1896 | } | |||
1897 | } else { | |||
1898 | HandleChildErrors.handleChildImportResult(ChildErrors, | |||
1899 | ImportedOrErr.takeError()); | |||
1900 | } | |||
1901 | } | |||
1902 | ||||
1903 | // We reorder declarations in RecordDecls because they may have another order | |||
1904 | // in the "to" context than they have in the "from" context. This may happen | |||
1905 | // e.g when we import a class like this: | |||
1906 | // struct declToImport { | |||
1907 | // int a = c + b; | |||
1908 | // int b = 1; | |||
1909 | // int c = 2; | |||
1910 | // }; | |||
1911 | // During the import of `a` we import first the dependencies in sequence, | |||
1912 | // thus the order would be `c`, `b`, `a`. We will get the normal order by | |||
1913 | // first removing the already imported members and then adding them in the | |||
1914 | // order as they apper in the "from" context. | |||
1915 | // | |||
1916 | // Keeping field order is vital because it determines structure layout. | |||
1917 | // | |||
1918 | // Here and below, we cannot call field_begin() method and its callers on | |||
1919 | // ToDC if it has an external storage. Calling field_begin() will | |||
1920 | // automatically load all the fields by calling | |||
1921 | // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would | |||
1922 | // call ASTImporter::Import(). This is because the ExternalASTSource | |||
1923 | // interface in LLDB is implemented by the means of the ASTImporter. However, | |||
1924 | // calling an import at this point would result in an uncontrolled import, we | |||
1925 | // must avoid that. | |||
1926 | const auto *FromRD = dyn_cast<RecordDecl>(FromDC); | |||
1927 | if (!FromRD) | |||
1928 | return ChildErrors; | |||
1929 | ||||
1930 | auto ToDCOrErr = Importer.ImportContext(FromDC); | |||
1931 | if (!ToDCOrErr) { | |||
1932 | consumeError(std::move(ChildErrors)); | |||
1933 | return ToDCOrErr.takeError(); | |||
1934 | } | |||
1935 | ||||
1936 | DeclContext *ToDC = *ToDCOrErr; | |||
1937 | // Remove all declarations, which may be in wrong order in the | |||
1938 | // lexical DeclContext and then add them in the proper order. | |||
1939 | for (auto *D : FromRD->decls()) { | |||
1940 | if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<FriendDecl>(D)) { | |||
1941 | assert(D && "DC contains a null decl")(static_cast <bool> (D && "DC contains a null decl" ) ? void (0) : __assert_fail ("D && \"DC contains a null decl\"" , "clang/lib/AST/ASTImporter.cpp", 1941, __extension__ __PRETTY_FUNCTION__ )); | |||
1942 | Decl *ToD = Importer.GetAlreadyImportedOrNull(D); | |||
1943 | // Remove only the decls which we successfully imported. | |||
1944 | if (ToD) { | |||
1945 | assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD))(static_cast <bool> (ToDC == ToD->getLexicalDeclContext () && ToDC->containsDecl(ToD)) ? void (0) : __assert_fail ("ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD)" , "clang/lib/AST/ASTImporter.cpp", 1945, __extension__ __PRETTY_FUNCTION__ )); | |||
1946 | // Remove the decl from its wrong place in the linked list. | |||
1947 | ToDC->removeDecl(ToD); | |||
1948 | // Add the decl to the end of the linked list. | |||
1949 | // This time it will be at the proper place because the enclosing for | |||
1950 | // loop iterates in the original (good) order of the decls. | |||
1951 | ToDC->addDeclInternal(ToD); | |||
1952 | } | |||
1953 | } | |||
1954 | } | |||
1955 | ||||
1956 | return ChildErrors; | |||
1957 | } | |||
1958 | ||||
1959 | Error ASTNodeImporter::ImportDeclContext( | |||
1960 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { | |||
1961 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); | |||
1962 | if (!ToDCOrErr) | |||
1963 | return ToDCOrErr.takeError(); | |||
1964 | ToDC = *ToDCOrErr; | |||
1965 | ||||
1966 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { | |||
1967 | auto ToLexicalDCOrErr = Importer.ImportContext( | |||
1968 | FromD->getLexicalDeclContext()); | |||
1969 | if (!ToLexicalDCOrErr) | |||
1970 | return ToLexicalDCOrErr.takeError(); | |||
1971 | ToLexicalDC = *ToLexicalDCOrErr; | |||
1972 | } else | |||
1973 | ToLexicalDC = ToDC; | |||
1974 | ||||
1975 | return Error::success(); | |||
1976 | } | |||
1977 | ||||
1978 | Error ASTNodeImporter::ImportImplicitMethods( | |||
1979 | const CXXRecordDecl *From, CXXRecordDecl *To) { | |||
1980 | assert(From->isCompleteDefinition() && To->getDefinition() == To &&(static_cast <bool> (From->isCompleteDefinition() && To->getDefinition() == To && "Import implicit methods to or from non-definition" ) ? void (0) : __assert_fail ("From->isCompleteDefinition() && To->getDefinition() == To && \"Import implicit methods to or from non-definition\"" , "clang/lib/AST/ASTImporter.cpp", 1981, __extension__ __PRETTY_FUNCTION__ )) | |||
1981 | "Import implicit methods to or from non-definition")(static_cast <bool> (From->isCompleteDefinition() && To->getDefinition() == To && "Import implicit methods to or from non-definition" ) ? void (0) : __assert_fail ("From->isCompleteDefinition() && To->getDefinition() == To && \"Import implicit methods to or from non-definition\"" , "clang/lib/AST/ASTImporter.cpp", 1981, __extension__ __PRETTY_FUNCTION__ )); | |||
1982 | ||||
1983 | for (CXXMethodDecl *FromM : From->methods()) | |||
1984 | if (FromM->isImplicit()) { | |||
1985 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); | |||
1986 | if (!ToMOrErr) | |||
1987 | return ToMOrErr.takeError(); | |||
1988 | } | |||
1989 | ||||
1990 | return Error::success(); | |||
1991 | } | |||
1992 | ||||
1993 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, | |||
1994 | ASTImporter &Importer) { | |||
1995 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { | |||
1996 | if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef)) | |||
1997 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); | |||
1998 | else | |||
1999 | return ToTypedefOrErr.takeError(); | |||
2000 | } | |||
2001 | return Error::success(); | |||
2002 | } | |||
2003 | ||||
2004 | Error ASTNodeImporter::ImportDefinition( | |||
2005 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { | |||
2006 | auto DefinitionCompleter = [To]() { | |||
2007 | // There are cases in LLDB when we first import a class without its | |||
2008 | // members. The class will have DefinitionData, but no members. Then, | |||
2009 | // importDefinition is called from LLDB, which tries to get the members, so | |||
2010 | // when we get here, the class already has the DefinitionData set, so we | |||
2011 | // must unset the CompleteDefinition here to be able to complete again the | |||
2012 | // definition. | |||
2013 | To->setCompleteDefinition(false); | |||
2014 | To->completeDefinition(); | |||
2015 | }; | |||
2016 | ||||
2017 | if (To->getDefinition() || To->isBeingDefined()) { | |||
2018 | if (Kind == IDK_Everything || | |||
2019 | // In case of lambdas, the class already has a definition ptr set, but | |||
2020 | // the contained decls are not imported yet. Also, isBeingDefined was | |||
2021 | // set in CXXRecordDecl::CreateLambda. We must import the contained | |||
2022 | // decls here and finish the definition. | |||
2023 | (To->isLambda() && shouldForceImportDeclContext(Kind))) { | |||
2024 | if (To->isLambda()) { | |||
2025 | auto *FromCXXRD = cast<CXXRecordDecl>(From); | |||
2026 | SmallVector<LambdaCapture, 8> ToCaptures; | |||
2027 | ToCaptures.reserve(FromCXXRD->capture_size()); | |||
2028 | for (const auto &FromCapture : FromCXXRD->captures()) { | |||
2029 | if (auto ToCaptureOrErr = import(FromCapture)) | |||
2030 | ToCaptures.push_back(*ToCaptureOrErr); | |||
2031 | else | |||
2032 | return ToCaptureOrErr.takeError(); | |||
2033 | } | |||
2034 | cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(), | |||
2035 | ToCaptures); | |||
2036 | } | |||
2037 | ||||
2038 | Error Result = ImportDeclContext(From, /*ForceImport=*/true); | |||
2039 | // Finish the definition of the lambda, set isBeingDefined to false. | |||
2040 | if (To->isLambda()) | |||
2041 | DefinitionCompleter(); | |||
2042 | return Result; | |||
2043 | } | |||
2044 | ||||
2045 | return Error::success(); | |||
2046 | } | |||
2047 | ||||
2048 | To->startDefinition(); | |||
2049 | // Set the definition to complete even if it is really not complete during | |||
2050 | // import. Some AST constructs (expressions) require the record layout | |||
2051 | // to be calculated (see 'clang::computeDependence') at the time they are | |||
2052 | // constructed. Import of such AST node is possible during import of the | |||
2053 | // same record, there is no way to have a completely defined record (all | |||
2054 | // fields imported) at that time without multiple AST import passes. | |||
2055 | if (!Importer.isMinimalImport()) | |||
2056 | To->setCompleteDefinition(true); | |||
2057 | // Complete the definition even if error is returned. | |||
2058 | // The RecordDecl may be already part of the AST so it is better to | |||
2059 | // have it in complete state even if something is wrong with it. | |||
2060 | auto DefinitionCompleterScopeExit = | |||
2061 | llvm::make_scope_exit(DefinitionCompleter); | |||
2062 | ||||
2063 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) | |||
2064 | return Err; | |||
2065 | ||||
2066 | // Add base classes. | |||
2067 | auto *ToCXX = dyn_cast<CXXRecordDecl>(To); | |||
2068 | auto *FromCXX = dyn_cast<CXXRecordDecl>(From); | |||
2069 | if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) { | |||
2070 | ||||
2071 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); | |||
2072 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); | |||
2073 | ||||
2074 | #define FIELD(Name, Width, Merge) \ | |||
2075 | ToData.Name = FromData.Name; | |||
2076 | #include "clang/AST/CXXRecordDeclDefinitionBits.def" | |||
2077 | ||||
2078 | // Copy over the data stored in RecordDeclBits | |||
2079 | ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions()); | |||
2080 | ||||
2081 | SmallVector<CXXBaseSpecifier *, 4> Bases; | |||
2082 | for (const auto &Base1 : FromCXX->bases()) { | |||
2083 | ExpectedType TyOrErr = import(Base1.getType()); | |||
2084 | if (!TyOrErr) | |||
2085 | return TyOrErr.takeError(); | |||
2086 | ||||
2087 | SourceLocation EllipsisLoc; | |||
2088 | if (Base1.isPackExpansion()) { | |||
2089 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) | |||
2090 | EllipsisLoc = *LocOrErr; | |||
2091 | else | |||
2092 | return LocOrErr.takeError(); | |||
2093 | } | |||
2094 | ||||
2095 | // Ensure that we have a definition for the base. | |||
2096 | if (Error Err = | |||
2097 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) | |||
2098 | return Err; | |||
2099 | ||||
2100 | auto RangeOrErr = import(Base1.getSourceRange()); | |||
2101 | if (!RangeOrErr) | |||
2102 | return RangeOrErr.takeError(); | |||
2103 | ||||
2104 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); | |||
2105 | if (!TSIOrErr) | |||
2106 | return TSIOrErr.takeError(); | |||
2107 | ||||
2108 | Bases.push_back( | |||
2109 | new (Importer.getToContext()) CXXBaseSpecifier( | |||
2110 | *RangeOrErr, | |||
2111 | Base1.isVirtual(), | |||
2112 | Base1.isBaseOfClass(), | |||
2113 | Base1.getAccessSpecifierAsWritten(), | |||
2114 | *TSIOrErr, | |||
2115 | EllipsisLoc)); | |||
2116 | } | |||
2117 | if (!Bases.empty()) | |||
2118 | ToCXX->setBases(Bases.data(), Bases.size()); | |||
2119 | } | |||
2120 | ||||
2121 | if (shouldForceImportDeclContext(Kind)) { | |||
2122 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | |||
2123 | return Err; | |||
2124 | } | |||
2125 | ||||
2126 | return Error::success(); | |||
2127 | } | |||
2128 | ||||
2129 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { | |||
2130 | if (To->getAnyInitializer()) | |||
2131 | return Error::success(); | |||
2132 | ||||
2133 | Expr *FromInit = From->getInit(); | |||
2134 | if (!FromInit) | |||
2135 | return Error::success(); | |||
2136 | ||||
2137 | ExpectedExpr ToInitOrErr = import(FromInit); | |||
2138 | if (!ToInitOrErr) | |||
2139 | return ToInitOrErr.takeError(); | |||
2140 | ||||
2141 | To->setInit(*ToInitOrErr); | |||
2142 | if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) { | |||
2143 | EvaluatedStmt *ToEval = To->ensureEvaluatedStmt(); | |||
2144 | ToEval->HasConstantInitialization = FromEval->HasConstantInitialization; | |||
2145 | ToEval->HasConstantDestruction = FromEval->HasConstantDestruction; | |||
2146 | // FIXME: Also import the initializer value. | |||
2147 | } | |||
2148 | ||||
2149 | // FIXME: Other bits to merge? | |||
2150 | return Error::success(); | |||
2151 | } | |||
2152 | ||||
2153 | Error ASTNodeImporter::ImportDefinition( | |||
2154 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { | |||
2155 | if (To->getDefinition() || To->isBeingDefined()) { | |||
2156 | if (Kind == IDK_Everything) | |||
2157 | return ImportDeclContext(From, /*ForceImport=*/true); | |||
2158 | return Error::success(); | |||
2159 | } | |||
2160 | ||||
2161 | To->startDefinition(); | |||
2162 | ||||
2163 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) | |||
2164 | return Err; | |||
2165 | ||||
2166 | ExpectedType ToTypeOrErr = | |||
2167 | import(Importer.getFromContext().getTypeDeclType(From)); | |||
2168 | if (!ToTypeOrErr) | |||
2169 | return ToTypeOrErr.takeError(); | |||
2170 | ||||
2171 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); | |||
2172 | if (!ToPromotionTypeOrErr) | |||
2173 | return ToPromotionTypeOrErr.takeError(); | |||
2174 | ||||
2175 | if (shouldForceImportDeclContext(Kind)) | |||
2176 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | |||
2177 | return Err; | |||
2178 | ||||
2179 | // FIXME: we might need to merge the number of positive or negative bits | |||
2180 | // if the enumerator lists don't match. | |||
2181 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, | |||
2182 | From->getNumPositiveBits(), | |||
2183 | From->getNumNegativeBits()); | |||
2184 | return Error::success(); | |||
2185 | } | |||
2186 | ||||
2187 | Error ASTNodeImporter::ImportTemplateArguments( | |||
2188 | const TemplateArgument *FromArgs, unsigned NumFromArgs, | |||
2189 | SmallVectorImpl<TemplateArgument> &ToArgs) { | |||
2190 | for (unsigned I = 0; I != NumFromArgs; ++I) { | |||
2191 | if (auto ToOrErr = import(FromArgs[I])) | |||
2192 | ToArgs.push_back(*ToOrErr); | |||
2193 | else | |||
2194 | return ToOrErr.takeError(); | |||
2195 | } | |||
2196 | ||||
2197 | return Error::success(); | |||
2198 | } | |||
2199 | ||||
2200 | // FIXME: Do not forget to remove this and use only 'import'. | |||
2201 | Expected<TemplateArgument> | |||
2202 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { | |||
2203 | return import(From); | |||
2204 | } | |||
2205 | ||||
2206 | template <typename InContainerTy> | |||
2207 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( | |||
2208 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { | |||
2209 | for (const auto &FromLoc : Container) { | |||
2210 | if (auto ToLocOrErr = import(FromLoc)) | |||
2211 | ToTAInfo.addArgument(*ToLocOrErr); | |||
2212 | else | |||
2213 | return ToLocOrErr.takeError(); | |||
2214 | } | |||
2215 | return Error::success(); | |||
2216 | } | |||
2217 | ||||
2218 | static StructuralEquivalenceKind | |||
2219 | getStructuralEquivalenceKind(const ASTImporter &Importer) { | |||
2220 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal | |||
2221 | : StructuralEquivalenceKind::Default; | |||
2222 | } | |||
2223 | ||||
2224 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { | |||
2225 | // Eliminate a potential failure point where we attempt to re-import | |||
2226 | // something we're trying to import while completing ToRecord. | |||
2227 | Decl *ToOrigin = Importer.GetOriginalDecl(To); | |||
2228 | if (ToOrigin) { | |||
2229 | To = ToOrigin; | |||
2230 | } | |||
2231 | ||||
2232 | StructuralEquivalenceContext Ctx( | |||
2233 | Importer.getFromContext(), Importer.getToContext(), | |||
2234 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | |||
2235 | false, Complain); | |||
2236 | return Ctx.IsEquivalent(From, To); | |||
2237 | } | |||
2238 | ||||
2239 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { | |||
2240 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | |||
2241 | << D->getDeclKindName(); | |||
2242 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
2243 | } | |||
2244 | ||||
2245 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { | |||
2246 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | |||
2247 | << D->getDeclKindName(); | |||
2248 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
2249 | } | |||
2250 | ||||
2251 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { | |||
2252 | // Import the context of this declaration. | |||
2253 | DeclContext *DC, *LexicalDC; | |||
2254 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
2255 | return std::move(Err); | |||
2256 | ||||
2257 | // Import the location of this declaration. | |||
2258 | ExpectedSLoc LocOrErr = import(D->getLocation()); | |||
2259 | if (!LocOrErr) | |||
2260 | return LocOrErr.takeError(); | |||
2261 | ||||
2262 | EmptyDecl *ToD; | |||
2263 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) | |||
2264 | return ToD; | |||
2265 | ||||
2266 | ToD->setLexicalDeclContext(LexicalDC); | |||
2267 | LexicalDC->addDeclInternal(ToD); | |||
2268 | return ToD; | |||
2269 | } | |||
2270 | ||||
2271 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { | |||
2272 | TranslationUnitDecl *ToD = | |||
2273 | Importer.getToContext().getTranslationUnitDecl(); | |||
2274 | ||||
2275 | Importer.MapImported(D, ToD); | |||
2276 | ||||
2277 | return ToD; | |||
2278 | } | |||
2279 | ||||
2280 | ExpectedDecl ASTNodeImporter::VisitBindingDecl(BindingDecl *D) { | |||
2281 | DeclContext *DC, *LexicalDC; | |||
2282 | DeclarationName Name; | |||
2283 | SourceLocation Loc; | |||
2284 | NamedDecl *ToND; | |||
2285 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc)) | |||
2286 | return std::move(Err); | |||
2287 | if (ToND) | |||
2288 | return ToND; | |||
2289 | ||||
2290 | BindingDecl *ToD; | |||
2291 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc, | |||
2292 | Name.getAsIdentifierInfo())) | |||
2293 | return ToD; | |||
2294 | ||||
2295 | Error Err = Error::success(); | |||
2296 | QualType ToType = importChecked(Err, D->getType()); | |||
2297 | Expr *ToBinding = importChecked(Err, D->getBinding()); | |||
2298 | ValueDecl *ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl()); | |||
2299 | if (Err) | |||
2300 | return std::move(Err); | |||
2301 | ||||
2302 | ToD->setBinding(ToType, ToBinding); | |||
2303 | ToD->setDecomposedDecl(ToDecomposedDecl); | |||
2304 | addDeclToContexts(D, ToD); | |||
2305 | ||||
2306 | return ToD; | |||
2307 | } | |||
2308 | ||||
2309 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { | |||
2310 | ExpectedSLoc LocOrErr = import(D->getLocation()); | |||
2311 | if (!LocOrErr) | |||
2312 | return LocOrErr.takeError(); | |||
2313 | auto ColonLocOrErr = import(D->getColonLoc()); | |||
2314 | if (!ColonLocOrErr) | |||
2315 | return ColonLocOrErr.takeError(); | |||
2316 | ||||
2317 | // Import the context of this declaration. | |||
2318 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); | |||
2319 | if (!DCOrErr) | |||
2320 | return DCOrErr.takeError(); | |||
2321 | DeclContext *DC = *DCOrErr; | |||
2322 | ||||
2323 | AccessSpecDecl *ToD; | |||
2324 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), | |||
2325 | DC, *LocOrErr, *ColonLocOrErr)) | |||
2326 | return ToD; | |||
2327 | ||||
2328 | // Lexical DeclContext and Semantic DeclContext | |||
2329 | // is always the same for the accessSpec. | |||
2330 | ToD->setLexicalDeclContext(DC); | |||
2331 | DC->addDeclInternal(ToD); | |||
2332 | ||||
2333 | return ToD; | |||
2334 | } | |||
2335 | ||||
2336 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { | |||
2337 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); | |||
2338 | if (!DCOrErr) | |||
2339 | return DCOrErr.takeError(); | |||
2340 | DeclContext *DC = *DCOrErr; | |||
2341 | DeclContext *LexicalDC = DC; | |||
2342 | ||||
2343 | Error Err = Error::success(); | |||
2344 | auto ToLocation = importChecked(Err, D->getLocation()); | |||
2345 | auto ToRParenLoc = importChecked(Err, D->getRParenLoc()); | |||
2346 | auto ToAssertExpr = importChecked(Err, D->getAssertExpr()); | |||
2347 | auto ToMessage = importChecked(Err, D->getMessage()); | |||
2348 | if (Err) | |||
2349 | return std::move(Err); | |||
2350 | ||||
2351 | StaticAssertDecl *ToD; | |||
2352 | if (GetImportedOrCreateDecl( | |||
2353 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, | |||
2354 | ToRParenLoc, D->isFailed())) | |||
2355 | return ToD; | |||
2356 | ||||
2357 | ToD->setLexicalDeclContext(LexicalDC); | |||
2358 | LexicalDC->addDeclInternal(ToD); | |||
2359 | return ToD; | |||
2360 | } | |||
2361 | ||||
2362 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { | |||
2363 | // Import the major distinguishing characteristics of this namespace. | |||
2364 | DeclContext *DC, *LexicalDC; | |||
2365 | DeclarationName Name; | |||
2366 | SourceLocation Loc; | |||
2367 | NamedDecl *ToD; | |||
2368 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
2369 | return std::move(Err); | |||
2370 | if (ToD) | |||
2371 | return ToD; | |||
2372 | ||||
2373 | NamespaceDecl *MergeWithNamespace = nullptr; | |||
2374 | if (!Name) { | |||
2375 | // This is an anonymous namespace. Adopt an existing anonymous | |||
2376 | // namespace if we can. | |||
2377 | // FIXME: Not testable. | |||
2378 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) | |||
2379 | MergeWithNamespace = TU->getAnonymousNamespace(); | |||
2380 | else | |||
2381 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); | |||
2382 | } else { | |||
2383 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
2384 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | |||
2385 | for (auto *FoundDecl : FoundDecls) { | |||
2386 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) | |||
2387 | continue; | |||
2388 | ||||
2389 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { | |||
2390 | MergeWithNamespace = FoundNS; | |||
2391 | ConflictingDecls.clear(); | |||
2392 | break; | |||
2393 | } | |||
2394 | ||||
2395 | ConflictingDecls.push_back(FoundDecl); | |||
2396 | } | |||
2397 | ||||
2398 | if (!ConflictingDecls.empty()) { | |||
2399 | ExpectedName NameOrErr = Importer.HandleNameConflict( | |||
2400 | Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(), | |||
2401 | ConflictingDecls.size()); | |||
2402 | if (NameOrErr) | |||
2403 | Name = NameOrErr.get(); | |||
2404 | else | |||
2405 | return NameOrErr.takeError(); | |||
2406 | } | |||
2407 | } | |||
2408 | ||||
2409 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | |||
2410 | if (!BeginLocOrErr) | |||
2411 | return BeginLocOrErr.takeError(); | |||
2412 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); | |||
2413 | if (!RBraceLocOrErr) | |||
2414 | return RBraceLocOrErr.takeError(); | |||
2415 | ||||
2416 | // Create the "to" namespace, if needed. | |||
2417 | NamespaceDecl *ToNamespace = MergeWithNamespace; | |||
2418 | if (!ToNamespace) { | |||
2419 | if (GetImportedOrCreateDecl( | |||
2420 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), | |||
2421 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), | |||
2422 | /*PrevDecl=*/nullptr)) | |||
2423 | return ToNamespace; | |||
2424 | ToNamespace->setRBraceLoc(*RBraceLocOrErr); | |||
2425 | ToNamespace->setLexicalDeclContext(LexicalDC); | |||
2426 | LexicalDC->addDeclInternal(ToNamespace); | |||
2427 | ||||
2428 | // If this is an anonymous namespace, register it as the anonymous | |||
2429 | // namespace within its context. | |||
2430 | if (!Name) { | |||
2431 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) | |||
2432 | TU->setAnonymousNamespace(ToNamespace); | |||
2433 | else | |||
2434 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); | |||
2435 | } | |||
2436 | } | |||
2437 | Importer.MapImported(D, ToNamespace); | |||
2438 | ||||
2439 | if (Error Err = ImportDeclContext(D)) | |||
2440 | return std::move(Err); | |||
2441 | ||||
2442 | return ToNamespace; | |||
2443 | } | |||
2444 | ||||
2445 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { | |||
2446 | // Import the major distinguishing characteristics of this namespace. | |||
2447 | DeclContext *DC, *LexicalDC; | |||
2448 | DeclarationName Name; | |||
2449 | SourceLocation Loc; | |||
2450 | NamedDecl *LookupD; | |||
2451 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) | |||
2452 | return std::move(Err); | |||
2453 | if (LookupD) | |||
2454 | return LookupD; | |||
2455 | ||||
2456 | // NOTE: No conflict resolution is done for namespace aliases now. | |||
2457 | ||||
2458 | Error Err = Error::success(); | |||
2459 | auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc()); | |||
2460 | auto ToAliasLoc = importChecked(Err, D->getAliasLoc()); | |||
2461 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | |||
2462 | auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc()); | |||
2463 | auto ToNamespace = importChecked(Err, D->getNamespace()); | |||
2464 | if (Err) | |||
2465 | return std::move(Err); | |||
2466 | ||||
2467 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); | |||
2468 | ||||
2469 | NamespaceAliasDecl *ToD; | |||
2470 | if (GetImportedOrCreateDecl( | |||
2471 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, | |||
2472 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) | |||
2473 | return ToD; | |||
2474 | ||||
2475 | ToD->setLexicalDeclContext(LexicalDC); | |||
2476 | LexicalDC->addDeclInternal(ToD); | |||
2477 | ||||
2478 | return ToD; | |||
2479 | } | |||
2480 | ||||
2481 | ExpectedDecl | |||
2482 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { | |||
2483 | // Import the major distinguishing characteristics of this typedef. | |||
2484 | DeclarationName Name; | |||
2485 | SourceLocation Loc; | |||
2486 | NamedDecl *ToD; | |||
2487 | // Do not import the DeclContext, we will import it once the TypedefNameDecl | |||
2488 | // is created. | |||
2489 | if (Error Err = ImportDeclParts(D, Name, ToD, Loc)) | |||
2490 | return std::move(Err); | |||
2491 | if (ToD) | |||
2492 | return ToD; | |||
2493 | ||||
2494 | DeclContext *DC = cast_or_null<DeclContext>( | |||
2495 | Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext()))); | |||
2496 | DeclContext *LexicalDC = | |||
2497 | cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull( | |||
2498 | cast<Decl>(D->getLexicalDeclContext()))); | |||
2499 | ||||
2500 | // If this typedef is not in block scope, determine whether we've | |||
2501 | // seen a typedef with the same name (that we can merge with) or any | |||
2502 | // other entity by that name (which name lookup could conflict with). | |||
2503 | // Note: Repeated typedefs are not valid in C99: | |||
2504 | // 'typedef int T; typedef int T;' is invalid | |||
2505 | // We do not care about this now. | |||
2506 | if (DC && !DC->isFunctionOrMethod()) { | |||
2507 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
2508 | unsigned IDNS = Decl::IDNS_Ordinary; | |||
2509 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | |||
2510 | for (auto *FoundDecl : FoundDecls) { | |||
2511 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
2512 | continue; | |||
2513 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { | |||
2514 | if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D)) | |||
2515 | continue; | |||
2516 | ||||
2517 | QualType FromUT = D->getUnderlyingType(); | |||
2518 | QualType FoundUT = FoundTypedef->getUnderlyingType(); | |||
2519 | if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) { | |||
2520 | // If the "From" context has a complete underlying type but we | |||
2521 | // already have a complete underlying type then return with that. | |||
2522 | if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType()) | |||
2523 | return Importer.MapImported(D, FoundTypedef); | |||
2524 | // FIXME Handle redecl chain. When you do that make consistent changes | |||
2525 | // in ASTImporterLookupTable too. | |||
2526 | } else { | |||
2527 | ConflictingDecls.push_back(FoundDecl); | |||
2528 | } | |||
2529 | } | |||
2530 | } | |||
2531 | ||||
2532 | if (!ConflictingDecls.empty()) { | |||
2533 | ExpectedName NameOrErr = Importer.HandleNameConflict( | |||
2534 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); | |||
2535 | if (NameOrErr) | |||
2536 | Name = NameOrErr.get(); | |||
2537 | else | |||
2538 | return NameOrErr.takeError(); | |||
2539 | } | |||
2540 | } | |||
2541 | ||||
2542 | Error Err = Error::success(); | |||
2543 | auto ToUnderlyingType = importChecked(Err, D->getUnderlyingType()); | |||
2544 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); | |||
2545 | auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); | |||
2546 | if (Err) | |||
2547 | return std::move(Err); | |||
2548 | ||||
2549 | // Create the new typedef node. | |||
2550 | // FIXME: ToUnderlyingType is not used. | |||
2551 | (void)ToUnderlyingType; | |||
2552 | TypedefNameDecl *ToTypedef; | |||
2553 | if (IsAlias) { | |||
2554 | if (GetImportedOrCreateDecl<TypeAliasDecl>( | |||
2555 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, | |||
2556 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) | |||
2557 | return ToTypedef; | |||
2558 | } else if (GetImportedOrCreateDecl<TypedefDecl>( | |||
2559 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, | |||
2560 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) | |||
2561 | return ToTypedef; | |||
2562 | ||||
2563 | // Import the DeclContext and set it to the Typedef. | |||
2564 | if ((Err = ImportDeclContext(D, DC, LexicalDC))) | |||
2565 | return std::move(Err); | |||
2566 | ToTypedef->setDeclContext(DC); | |||
2567 | ToTypedef->setLexicalDeclContext(LexicalDC); | |||
2568 | // Add to the lookupTable because we could not do that in MapImported. | |||
2569 | Importer.AddToLookupTable(ToTypedef); | |||
2570 | ||||
2571 | ToTypedef->setAccess(D->getAccess()); | |||
2572 | ||||
2573 | // Templated declarations should not appear in DeclContext. | |||
2574 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; | |||
2575 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) | |||
2576 | LexicalDC->addDeclInternal(ToTypedef); | |||
2577 | ||||
2578 | return ToTypedef; | |||
2579 | } | |||
2580 | ||||
2581 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { | |||
2582 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); | |||
2583 | } | |||
2584 | ||||
2585 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { | |||
2586 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); | |||
2587 | } | |||
2588 | ||||
2589 | ExpectedDecl | |||
2590 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { | |||
2591 | // Import the major distinguishing characteristics of this typedef. | |||
2592 | DeclContext *DC, *LexicalDC; | |||
2593 | DeclarationName Name; | |||
2594 | SourceLocation Loc; | |||
2595 | NamedDecl *FoundD; | |||
2596 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) | |||
2597 | return std::move(Err); | |||
2598 | if (FoundD) | |||
2599 | return FoundD; | |||
2600 | ||||
2601 | // If this typedef is not in block scope, determine whether we've | |||
2602 | // seen a typedef with the same name (that we can merge with) or any | |||
2603 | // other entity by that name (which name lookup could conflict with). | |||
2604 | if (!DC->isFunctionOrMethod()) { | |||
2605 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
2606 | unsigned IDNS = Decl::IDNS_Ordinary; | |||
2607 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | |||
2608 | for (auto *FoundDecl : FoundDecls) { | |||
2609 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
2610 | continue; | |||
2611 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) | |||
2612 | return Importer.MapImported(D, FoundAlias); | |||
2613 | ConflictingDecls.push_back(FoundDecl); | |||
2614 | } | |||
2615 | ||||
2616 | if (!ConflictingDecls.empty()) { | |||
2617 | ExpectedName NameOrErr = Importer.HandleNameConflict( | |||
2618 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); | |||
2619 | if (NameOrErr) | |||
2620 | Name = NameOrErr.get(); | |||
2621 | else | |||
2622 | return NameOrErr.takeError(); | |||
2623 | } | |||
2624 | } | |||
2625 | ||||
2626 | Error Err = Error::success(); | |||
2627 | auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters()); | |||
2628 | auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl()); | |||
2629 | if (Err) | |||
2630 | return std::move(Err); | |||
2631 | ||||
2632 | TypeAliasTemplateDecl *ToAlias; | |||
2633 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, | |||
2634 | Name, ToTemplateParameters, ToTemplatedDecl)) | |||
2635 | return ToAlias; | |||
2636 | ||||
2637 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); | |||
2638 | ||||
2639 | ToAlias->setAccess(D->getAccess()); | |||
2640 | ToAlias->setLexicalDeclContext(LexicalDC); | |||
2641 | LexicalDC->addDeclInternal(ToAlias); | |||
2642 | if (DC != Importer.getToContext().getTranslationUnitDecl()) | |||
2643 | updateLookupTableForTemplateParameters(*ToTemplateParameters); | |||
2644 | return ToAlias; | |||
2645 | } | |||
2646 | ||||
2647 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { | |||
2648 | // Import the major distinguishing characteristics of this label. | |||
2649 | DeclContext *DC, *LexicalDC; | |||
2650 | DeclarationName Name; | |||
2651 | SourceLocation Loc; | |||
2652 | NamedDecl *ToD; | |||
2653 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
2654 | return std::move(Err); | |||
2655 | if (ToD) | |||
2656 | return ToD; | |||
2657 | ||||
2658 | assert(LexicalDC->isFunctionOrMethod())(static_cast <bool> (LexicalDC->isFunctionOrMethod() ) ? void (0) : __assert_fail ("LexicalDC->isFunctionOrMethod()" , "clang/lib/AST/ASTImporter.cpp", 2658, __extension__ __PRETTY_FUNCTION__ )); | |||
2659 | ||||
2660 | LabelDecl *ToLabel; | |||
2661 | if (D->isGnuLocal()) { | |||
2662 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | |||
2663 | if (!BeginLocOrErr) | |||
2664 | return BeginLocOrErr.takeError(); | |||
2665 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, | |||
2666 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) | |||
2667 | return ToLabel; | |||
2668 | ||||
2669 | } else { | |||
2670 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, | |||
2671 | Name.getAsIdentifierInfo())) | |||
2672 | return ToLabel; | |||
2673 | ||||
2674 | } | |||
2675 | ||||
2676 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); | |||
2677 | if (!ToStmtOrErr) | |||
2678 | return ToStmtOrErr.takeError(); | |||
2679 | ||||
2680 | ToLabel->setStmt(*ToStmtOrErr); | |||
2681 | ToLabel->setLexicalDeclContext(LexicalDC); | |||
2682 | LexicalDC->addDeclInternal(ToLabel); | |||
2683 | return ToLabel; | |||
2684 | } | |||
2685 | ||||
2686 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { | |||
2687 | // Import the major distinguishing characteristics of this enum. | |||
2688 | DeclContext *DC, *LexicalDC; | |||
2689 | DeclarationName Name; | |||
2690 | SourceLocation Loc; | |||
2691 | NamedDecl *ToD; | |||
2692 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
2693 | return std::move(Err); | |||
2694 | if (ToD) | |||
2695 | return ToD; | |||
2696 | ||||
2697 | // Figure out what enum name we're looking for. | |||
2698 | unsigned IDNS = Decl::IDNS_Tag; | |||
2699 | DeclarationName SearchName = Name; | |||
2700 | if (!SearchName && D->getTypedefNameForAnonDecl()) { | |||
2701 | if (Error Err = importInto( | |||
2702 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) | |||
2703 | return std::move(Err); | |||
2704 | IDNS = Decl::IDNS_Ordinary; | |||
2705 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) | |||
2706 | IDNS |= Decl::IDNS_Ordinary; | |||
2707 | ||||
2708 | // We may already have an enum of the same name; try to find and match it. | |||
2709 | EnumDecl *PrevDecl = nullptr; | |||
2710 | if (!DC->isFunctionOrMethod() && SearchName) { | |||
2711 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
2712 | auto FoundDecls = | |||
2713 | Importer.findDeclsInToCtx(DC, SearchName); | |||
2714 | for (auto *FoundDecl : FoundDecls) { | |||
2715 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
2716 | continue; | |||
2717 | ||||
2718 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { | |||
2719 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) | |||
2720 | FoundDecl = Tag->getDecl(); | |||
2721 | } | |||
2722 | ||||
2723 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { | |||
2724 | if (!hasSameVisibilityContextAndLinkage(FoundEnum, D)) | |||
2725 | continue; | |||
2726 | if (IsStructuralMatch(D, FoundEnum)) { | |||
2727 | EnumDecl *FoundDef = FoundEnum->getDefinition(); | |||
2728 | if (D->isThisDeclarationADefinition() && FoundDef) | |||
2729 | return Importer.MapImported(D, FoundDef); | |||
2730 | PrevDecl = FoundEnum->getMostRecentDecl(); | |||
2731 | break; | |||
2732 | } | |||
2733 | ConflictingDecls.push_back(FoundDecl); | |||
2734 | } | |||
2735 | } | |||
2736 | ||||
2737 | if (!ConflictingDecls.empty()) { | |||
2738 | ExpectedName NameOrErr = Importer.HandleNameConflict( | |||
2739 | SearchName, DC, IDNS, ConflictingDecls.data(), | |||
2740 | ConflictingDecls.size()); | |||
2741 | if (NameOrErr) | |||
2742 | Name = NameOrErr.get(); | |||
2743 | else | |||
2744 | return NameOrErr.takeError(); | |||
2745 | } | |||
2746 | } | |||
2747 | ||||
2748 | Error Err = Error::success(); | |||
2749 | auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); | |||
2750 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | |||
2751 | auto ToIntegerType = importChecked(Err, D->getIntegerType()); | |||
2752 | auto ToBraceRange = importChecked(Err, D->getBraceRange()); | |||
2753 | if (Err) | |||
2754 | return std::move(Err); | |||
2755 | ||||
2756 | // Create the enum declaration. | |||
2757 | EnumDecl *D2; | |||
2758 | if (GetImportedOrCreateDecl( | |||
2759 | D2, D, Importer.getToContext(), DC, ToBeginLoc, | |||
2760 | Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(), | |||
2761 | D->isScopedUsingClassTag(), D->isFixed())) | |||
2762 | return D2; | |||
2763 | ||||
2764 | D2->setQualifierInfo(ToQualifierLoc); | |||
2765 | D2->setIntegerType(ToIntegerType); | |||
2766 | D2->setBraceRange(ToBraceRange); | |||
2767 | D2->setAccess(D->getAccess()); | |||
2768 | D2->setLexicalDeclContext(LexicalDC); | |||
2769 | addDeclToContexts(D, D2); | |||
2770 | ||||
2771 | if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) { | |||
2772 | TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind(); | |||
2773 | EnumDecl *FromInst = D->getInstantiatedFromMemberEnum(); | |||
2774 | if (Expected<EnumDecl *> ToInstOrErr = import(FromInst)) | |||
2775 | D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK); | |||
2776 | else | |||
2777 | return ToInstOrErr.takeError(); | |||
2778 | if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation())) | |||
2779 | D2->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); | |||
2780 | else | |||
2781 | return POIOrErr.takeError(); | |||
2782 | } | |||
2783 | ||||
2784 | // Import the definition | |||
2785 | if (D->isCompleteDefinition()) | |||
2786 | if (Error Err = ImportDefinition(D, D2)) | |||
2787 | return std::move(Err); | |||
2788 | ||||
2789 | return D2; | |||
2790 | } | |||
2791 | ||||
2792 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { | |||
2793 | bool IsFriendTemplate = false; | |||
2794 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | |||
2795 | IsFriendTemplate = | |||
2796 | DCXX->getDescribedClassTemplate() && | |||
2797 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != | |||
2798 | Decl::FOK_None; | |||
2799 | } | |||
2800 | ||||
2801 | // Import the major distinguishing characteristics of this record. | |||
2802 | DeclContext *DC = nullptr, *LexicalDC = nullptr; | |||
2803 | DeclarationName Name; | |||
2804 | SourceLocation Loc; | |||
2805 | NamedDecl *ToD = nullptr; | |||
2806 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
2807 | return std::move(Err); | |||
2808 | if (ToD) | |||
2809 | return ToD; | |||
2810 | ||||
2811 | // Figure out what structure name we're looking for. | |||
2812 | unsigned IDNS = Decl::IDNS_Tag; | |||
2813 | DeclarationName SearchName = Name; | |||
2814 | if (!SearchName && D->getTypedefNameForAnonDecl()) { | |||
2815 | if (Error Err = importInto( | |||
2816 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) | |||
2817 | return std::move(Err); | |||
2818 | IDNS = Decl::IDNS_Ordinary; | |||
2819 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) | |||
2820 | IDNS |= Decl::IDNS_Ordinary | Decl::IDNS_TagFriend; | |||
2821 | ||||
2822 | // We may already have a record of the same name; try to find and match it. | |||
2823 | RecordDecl *PrevDecl = nullptr; | |||
2824 | if (!DC->isFunctionOrMethod() && !D->isLambda()) { | |||
2825 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
2826 | auto FoundDecls = | |||
2827 | Importer.findDeclsInToCtx(DC, SearchName); | |||
2828 | if (!FoundDecls.empty()) { | |||
2829 | // We're going to have to compare D against potentially conflicting Decls, | |||
2830 | // so complete it. | |||
2831 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) | |||
2832 | D->getASTContext().getExternalSource()->CompleteType(D); | |||
2833 | } | |||
2834 | ||||
2835 | for (auto *FoundDecl : FoundDecls) { | |||
2836 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
2837 | continue; | |||
2838 | ||||
2839 | Decl *Found = FoundDecl; | |||
2840 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { | |||
2841 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) | |||
2842 | Found = Tag->getDecl(); | |||
2843 | } | |||
2844 | ||||
2845 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { | |||
2846 | // Do not emit false positive diagnostic in case of unnamed | |||
2847 | // struct/union and in case of anonymous structs. Would be false | |||
2848 | // because there may be several anonymous/unnamed structs in a class. | |||
2849 | // E.g. these are both valid: | |||
2850 | // struct A { // unnamed structs | |||
2851 | // struct { struct A *next; } entry0; | |||
2852 | // struct { struct A *next; } entry1; | |||
2853 | // }; | |||
2854 | // struct X { struct { int a; }; struct { int b; }; }; // anon structs | |||
2855 | if (!SearchName) | |||
2856 | if (!IsStructuralMatch(D, FoundRecord, false)) | |||
2857 | continue; | |||
2858 | ||||
2859 | if (!hasSameVisibilityContextAndLinkage(FoundRecord, D)) | |||
2860 | continue; | |||
2861 | ||||
2862 | if (IsStructuralMatch(D, FoundRecord)) { | |||
2863 | RecordDecl *FoundDef = FoundRecord->getDefinition(); | |||
2864 | if (D->isThisDeclarationADefinition() && FoundDef) { | |||
2865 | // FIXME: Structural equivalence check should check for same | |||
2866 | // user-defined methods. | |||
2867 | Importer.MapImported(D, FoundDef); | |||
2868 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | |||
2869 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); | |||
2870 | assert(FoundCXX && "Record type mismatch")(static_cast <bool> (FoundCXX && "Record type mismatch" ) ? void (0) : __assert_fail ("FoundCXX && \"Record type mismatch\"" , "clang/lib/AST/ASTImporter.cpp", 2870, __extension__ __PRETTY_FUNCTION__ )); | |||
2871 | ||||
2872 | if (!Importer.isMinimalImport()) | |||
2873 | // FoundDef may not have every implicit method that D has | |||
2874 | // because implicit methods are created only if they are used. | |||
2875 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) | |||
2876 | return std::move(Err); | |||
2877 | } | |||
2878 | } | |||
2879 | PrevDecl = FoundRecord->getMostRecentDecl(); | |||
2880 | break; | |||
2881 | } | |||
2882 | ConflictingDecls.push_back(FoundDecl); | |||
2883 | } // kind is RecordDecl | |||
2884 | } // for | |||
2885 | ||||
2886 | if (!ConflictingDecls.empty() && SearchName) { | |||
2887 | ExpectedName NameOrErr = Importer.HandleNameConflict( | |||
2888 | SearchName, DC, IDNS, ConflictingDecls.data(), | |||
2889 | ConflictingDecls.size()); | |||
2890 | if (NameOrErr) | |||
2891 | Name = NameOrErr.get(); | |||
2892 | else | |||
2893 | return NameOrErr.takeError(); | |||
2894 | } | |||
2895 | } | |||
2896 | ||||
2897 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | |||
2898 | if (!BeginLocOrErr) | |||
2899 | return BeginLocOrErr.takeError(); | |||
2900 | ||||
2901 | // Create the record declaration. | |||
2902 | RecordDecl *D2 = nullptr; | |||
2903 | CXXRecordDecl *D2CXX = nullptr; | |||
2904 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | |||
2905 | if (DCXX->isLambda()) { | |||
2906 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); | |||
2907 | if (!TInfoOrErr) | |||
2908 | return TInfoOrErr.takeError(); | |||
2909 | if (GetImportedOrCreateSpecialDecl( | |||
2910 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), | |||
2911 | DC, *TInfoOrErr, Loc, DCXX->getLambdaDependencyKind(), | |||
2912 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) | |||
2913 | return D2CXX; | |||
2914 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); | |||
2915 | if (!CDeclOrErr) | |||
2916 | return CDeclOrErr.takeError(); | |||
2917 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr, | |||
2918 | DCXX->hasKnownLambdaInternalLinkage()); | |||
2919 | D2CXX->setDeviceLambdaManglingNumber( | |||
2920 | DCXX->getDeviceLambdaManglingNumber()); | |||
2921 | } else if (DCXX->isInjectedClassName()) { | |||
2922 | // We have to be careful to do a similar dance to the one in | |||
2923 | // Sema::ActOnStartCXXMemberDeclarations | |||
2924 | const bool DelayTypeCreation = true; | |||
2925 | if (GetImportedOrCreateDecl( | |||
2926 | D2CXX, D, Importer.getToContext(), D->getTagKind(), DC, | |||
2927 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), | |||
2928 | cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation)) | |||
2929 | return D2CXX; | |||
2930 | Importer.getToContext().getTypeDeclType( | |||
2931 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); | |||
2932 | } else { | |||
2933 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), | |||
2934 | D->getTagKind(), DC, *BeginLocOrErr, Loc, | |||
2935 | Name.getAsIdentifierInfo(), | |||
2936 | cast_or_null<CXXRecordDecl>(PrevDecl))) | |||
2937 | return D2CXX; | |||
2938 | } | |||
2939 | ||||
2940 | D2 = D2CXX; | |||
2941 | D2->setAccess(D->getAccess()); | |||
2942 | D2->setLexicalDeclContext(LexicalDC); | |||
2943 | addDeclToContexts(D, D2); | |||
2944 | ||||
2945 | if (ClassTemplateDecl *FromDescribed = | |||
2946 | DCXX->getDescribedClassTemplate()) { | |||
2947 | ClassTemplateDecl *ToDescribed; | |||
2948 | if (Error Err = importInto(ToDescribed, FromDescribed)) | |||
2949 | return std::move(Err); | |||
2950 | D2CXX->setDescribedClassTemplate(ToDescribed); | |||
2951 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { | |||
2952 | // In a record describing a template the type should be an | |||
2953 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the | |||
2954 | // previously set type to the correct value here (ToDescribed is not | |||
2955 | // available at record create). | |||
2956 | // FIXME: The previous type is cleared but not removed from | |||
2957 | // ASTContext's internal storage. | |||
2958 | CXXRecordDecl *Injected = nullptr; | |||
2959 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { | |||
2960 | auto *Record = dyn_cast<CXXRecordDecl>(Found); | |||
2961 | if (Record && Record->isInjectedClassName()) { | |||
2962 | Injected = Record; | |||
2963 | break; | |||
2964 | } | |||
2965 | } | |||
2966 | // Create an injected type for the whole redecl chain. | |||
2967 | SmallVector<Decl *, 2> Redecls = | |||
2968 | getCanonicalForwardRedeclChain(D2CXX); | |||
2969 | for (auto *R : Redecls) { | |||
2970 | auto *RI = cast<CXXRecordDecl>(R); | |||
2971 | RI->setTypeForDecl(nullptr); | |||
2972 | // Below we create a new injected type and assign that to the | |||
2973 | // canonical decl, subsequent declarations in the chain will reuse | |||
2974 | // that type. | |||
2975 | Importer.getToContext().getInjectedClassNameType( | |||
2976 | RI, ToDescribed->getInjectedClassNameSpecialization()); | |||
2977 | } | |||
2978 | // Set the new type for the previous injected decl too. | |||
2979 | if (Injected) { | |||
2980 | Injected->setTypeForDecl(nullptr); | |||
2981 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); | |||
2982 | } | |||
2983 | } | |||
2984 | } else if (MemberSpecializationInfo *MemberInfo = | |||
2985 | DCXX->getMemberSpecializationInfo()) { | |||
2986 | TemplateSpecializationKind SK = | |||
2987 | MemberInfo->getTemplateSpecializationKind(); | |||
2988 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); | |||
2989 | ||||
2990 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) | |||
2991 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); | |||
2992 | else | |||
2993 | return ToInstOrErr.takeError(); | |||
2994 | ||||
2995 | if (ExpectedSLoc POIOrErr = | |||
2996 | import(MemberInfo->getPointOfInstantiation())) | |||
2997 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( | |||
2998 | *POIOrErr); | |||
2999 | else | |||
3000 | return POIOrErr.takeError(); | |||
3001 | } | |||
3002 | ||||
3003 | } else { | |||
3004 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), | |||
3005 | D->getTagKind(), DC, *BeginLocOrErr, Loc, | |||
3006 | Name.getAsIdentifierInfo(), PrevDecl)) | |||
3007 | return D2; | |||
3008 | D2->setLexicalDeclContext(LexicalDC); | |||
3009 | addDeclToContexts(D, D2); | |||
3010 | } | |||
3011 | ||||
3012 | if (auto BraceRangeOrErr = import(D->getBraceRange())) | |||
3013 | D2->setBraceRange(*BraceRangeOrErr); | |||
3014 | else | |||
3015 | return BraceRangeOrErr.takeError(); | |||
3016 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) | |||
3017 | D2->setQualifierInfo(*QualifierLocOrErr); | |||
3018 | else | |||
3019 | return QualifierLocOrErr.takeError(); | |||
3020 | ||||
3021 | if (D->isAnonymousStructOrUnion()) | |||
3022 | D2->setAnonymousStructOrUnion(true); | |||
3023 | ||||
3024 | if (D->isCompleteDefinition()) | |||
3025 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) | |||
3026 | return std::move(Err); | |||
3027 | ||||
3028 | return D2; | |||
3029 | } | |||
3030 | ||||
3031 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { | |||
3032 | // Import the major distinguishing characteristics of this enumerator. | |||
3033 | DeclContext *DC, *LexicalDC; | |||
3034 | DeclarationName Name; | |||
3035 | SourceLocation Loc; | |||
3036 | NamedDecl *ToD; | |||
3037 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3038 | return std::move(Err); | |||
3039 | if (ToD) | |||
3040 | return ToD; | |||
3041 | ||||
3042 | // Determine whether there are any other declarations with the same name and | |||
3043 | // in the same context. | |||
3044 | if (!LexicalDC->isFunctionOrMethod()) { | |||
3045 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
3046 | unsigned IDNS = Decl::IDNS_Ordinary; | |||
3047 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | |||
3048 | for (auto *FoundDecl : FoundDecls) { | |||
3049 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
3050 | continue; | |||
3051 | ||||
3052 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { | |||
3053 | if (IsStructuralMatch(D, FoundEnumConstant)) | |||
3054 | return Importer.MapImported(D, FoundEnumConstant); | |||
3055 | ConflictingDecls.push_back(FoundDecl); | |||
3056 | } | |||
3057 | } | |||
3058 | ||||
3059 | if (!ConflictingDecls.empty()) { | |||
3060 | ExpectedName NameOrErr = Importer.HandleNameConflict( | |||
3061 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); | |||
3062 | if (NameOrErr) | |||
3063 | Name = NameOrErr.get(); | |||
3064 | else | |||
3065 | return NameOrErr.takeError(); | |||
3066 | } | |||
3067 | } | |||
3068 | ||||
3069 | ExpectedType TypeOrErr = import(D->getType()); | |||
3070 | if (!TypeOrErr) | |||
3071 | return TypeOrErr.takeError(); | |||
3072 | ||||
3073 | ExpectedExpr InitOrErr = import(D->getInitExpr()); | |||
3074 | if (!InitOrErr) | |||
3075 | return InitOrErr.takeError(); | |||
3076 | ||||
3077 | EnumConstantDecl *ToEnumerator; | |||
3078 | if (GetImportedOrCreateDecl( | |||
3079 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, | |||
3080 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) | |||
3081 | return ToEnumerator; | |||
3082 | ||||
3083 | ToEnumerator->setAccess(D->getAccess()); | |||
3084 | ToEnumerator->setLexicalDeclContext(LexicalDC); | |||
3085 | LexicalDC->addDeclInternal(ToEnumerator); | |||
3086 | return ToEnumerator; | |||
3087 | } | |||
3088 | ||||
3089 | Error ASTNodeImporter::ImportTemplateParameterLists(const DeclaratorDecl *FromD, | |||
3090 | DeclaratorDecl *ToD) { | |||
3091 | unsigned int Num = FromD->getNumTemplateParameterLists(); | |||
3092 | if (Num == 0) | |||
3093 | return Error::success(); | |||
3094 | SmallVector<TemplateParameterList *, 2> ToTPLists(Num); | |||
3095 | for (unsigned int I = 0; I < Num; ++I) | |||
3096 | if (Expected<TemplateParameterList *> ToTPListOrErr = | |||
3097 | import(FromD->getTemplateParameterList(I))) | |||
3098 | ToTPLists[I] = *ToTPListOrErr; | |||
3099 | else | |||
3100 | return ToTPListOrErr.takeError(); | |||
3101 | ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists); | |||
3102 | return Error::success(); | |||
3103 | } | |||
3104 | ||||
3105 | Error ASTNodeImporter::ImportTemplateInformation( | |||
3106 | FunctionDecl *FromFD, FunctionDecl *ToFD) { | |||
3107 | switch (FromFD->getTemplatedKind()) { | |||
3108 | case FunctionDecl::TK_NonTemplate: | |||
3109 | case FunctionDecl::TK_FunctionTemplate: | |||
3110 | return Error::success(); | |||
3111 | ||||
3112 | case FunctionDecl::TK_MemberSpecialization: { | |||
3113 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); | |||
3114 | ||||
3115 | if (Expected<FunctionDecl *> InstFDOrErr = | |||
3116 | import(FromFD->getInstantiatedFromMemberFunction())) | |||
3117 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); | |||
3118 | else | |||
3119 | return InstFDOrErr.takeError(); | |||
3120 | ||||
3121 | if (ExpectedSLoc POIOrErr = import( | |||
3122 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) | |||
3123 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); | |||
3124 | else | |||
3125 | return POIOrErr.takeError(); | |||
3126 | ||||
3127 | return Error::success(); | |||
3128 | } | |||
3129 | ||||
3130 | case FunctionDecl::TK_FunctionTemplateSpecialization: { | |||
3131 | auto FunctionAndArgsOrErr = | |||
3132 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); | |||
3133 | if (!FunctionAndArgsOrErr) | |||
3134 | return FunctionAndArgsOrErr.takeError(); | |||
3135 | ||||
3136 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( | |||
3137 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); | |||
3138 | ||||
3139 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); | |||
3140 | TemplateArgumentListInfo ToTAInfo; | |||
3141 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; | |||
3142 | if (FromTAArgsAsWritten) | |||
3143 | if (Error Err = ImportTemplateArgumentListInfo( | |||
3144 | *FromTAArgsAsWritten, ToTAInfo)) | |||
3145 | return Err; | |||
3146 | ||||
3147 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); | |||
3148 | if (!POIOrErr) | |||
3149 | return POIOrErr.takeError(); | |||
3150 | ||||
3151 | if (Error Err = ImportTemplateParameterLists(FromFD, ToFD)) | |||
3152 | return Err; | |||
3153 | ||||
3154 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); | |||
3155 | ToFD->setFunctionTemplateSpecialization( | |||
3156 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, | |||
3157 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); | |||
3158 | return Error::success(); | |||
3159 | } | |||
3160 | ||||
3161 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { | |||
3162 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); | |||
3163 | UnresolvedSet<8> TemplDecls; | |||
3164 | unsigned NumTemplates = FromInfo->getNumTemplates(); | |||
3165 | for (unsigned I = 0; I < NumTemplates; I++) { | |||
3166 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = | |||
3167 | import(FromInfo->getTemplate(I))) | |||
3168 | TemplDecls.addDecl(*ToFTDOrErr); | |||
3169 | else | |||
3170 | return ToFTDOrErr.takeError(); | |||
3171 | } | |||
3172 | ||||
3173 | // Import TemplateArgumentListInfo. | |||
3174 | TemplateArgumentListInfo ToTAInfo; | |||
3175 | if (Error Err = ImportTemplateArgumentListInfo( | |||
3176 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), | |||
3177 | llvm::makeArrayRef( | |||
3178 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), | |||
3179 | ToTAInfo)) | |||
3180 | return Err; | |||
3181 | ||||
3182 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), | |||
3183 | TemplDecls, ToTAInfo); | |||
3184 | return Error::success(); | |||
3185 | } | |||
3186 | } | |||
3187 | llvm_unreachable("All cases should be covered!")::llvm::llvm_unreachable_internal("All cases should be covered!" , "clang/lib/AST/ASTImporter.cpp", 3187); | |||
3188 | } | |||
3189 | ||||
3190 | Expected<FunctionDecl *> | |||
3191 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { | |||
3192 | auto FunctionAndArgsOrErr = | |||
3193 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); | |||
3194 | if (!FunctionAndArgsOrErr) | |||
3195 | return FunctionAndArgsOrErr.takeError(); | |||
3196 | ||||
3197 | FunctionTemplateDecl *Template; | |||
3198 | TemplateArgsTy ToTemplArgs; | |||
3199 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; | |||
3200 | void *InsertPos = nullptr; | |||
3201 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); | |||
3202 | return FoundSpec; | |||
3203 | } | |||
3204 | ||||
3205 | Error ASTNodeImporter::ImportFunctionDeclBody(FunctionDecl *FromFD, | |||
3206 | FunctionDecl *ToFD) { | |||
3207 | if (Stmt *FromBody = FromFD->getBody()) { | |||
3208 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) | |||
3209 | ToFD->setBody(*ToBodyOrErr); | |||
3210 | else | |||
3211 | return ToBodyOrErr.takeError(); | |||
3212 | } | |||
3213 | return Error::success(); | |||
3214 | } | |||
3215 | ||||
3216 | // Returns true if the given D has a DeclContext up to the TranslationUnitDecl | |||
3217 | // which is equal to the given DC. | |||
3218 | static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) { | |||
3219 | const DeclContext *DCi = D->getDeclContext(); | |||
3220 | while (DCi != D->getTranslationUnitDecl()) { | |||
3221 | if (DCi == DC) | |||
3222 | return true; | |||
3223 | DCi = DCi->getParent(); | |||
3224 | } | |||
3225 | return false; | |||
3226 | } | |||
3227 | ||||
3228 | bool ASTNodeImporter::hasAutoReturnTypeDeclaredInside(FunctionDecl *D) { | |||
3229 | QualType FromTy = D->getType(); | |||
3230 | const auto *FromFPT = FromTy->getAs<FunctionProtoType>(); | |||
3231 | assert(FromFPT && "Must be called on FunctionProtoType")(static_cast <bool> (FromFPT && "Must be called on FunctionProtoType" ) ? void (0) : __assert_fail ("FromFPT && \"Must be called on FunctionProtoType\"" , "clang/lib/AST/ASTImporter.cpp", 3231, __extension__ __PRETTY_FUNCTION__ )); | |||
3232 | if (const AutoType *AutoT = | |||
3233 | FromFPT->getReturnType()->getContainedAutoType()) { | |||
3234 | QualType DeducedT = AutoT->getDeducedType(); | |||
3235 | if (const auto *RecordT = | |||
3236 | !DeducedT.isNull() ? DeducedT->getAs<RecordType>() : nullptr) { | |||
3237 | const RecordDecl *RD = RecordT->getDecl(); | |||
3238 | assert(RD)(static_cast <bool> (RD) ? void (0) : __assert_fail ("RD" , "clang/lib/AST/ASTImporter.cpp", 3238, __extension__ __PRETTY_FUNCTION__ )); | |||
3239 | if (isAncestorDeclContextOf(D, RD)) { | |||
3240 | assert(RD->getLexicalDeclContext() == RD->getDeclContext())(static_cast <bool> (RD->getLexicalDeclContext() == RD ->getDeclContext()) ? void (0) : __assert_fail ("RD->getLexicalDeclContext() == RD->getDeclContext()" , "clang/lib/AST/ASTImporter.cpp", 3240, __extension__ __PRETTY_FUNCTION__ )); | |||
3241 | return true; | |||
3242 | } | |||
3243 | } | |||
3244 | } | |||
3245 | if (const auto *TypedefT = FromFPT->getReturnType()->getAs<TypedefType>()) { | |||
3246 | const TypedefNameDecl *TD = TypedefT->getDecl(); | |||
3247 | assert(TD)(static_cast <bool> (TD) ? void (0) : __assert_fail ("TD" , "clang/lib/AST/ASTImporter.cpp", 3247, __extension__ __PRETTY_FUNCTION__ )); | |||
3248 | if (isAncestorDeclContextOf(D, TD)) { | |||
3249 | assert(TD->getLexicalDeclContext() == TD->getDeclContext())(static_cast <bool> (TD->getLexicalDeclContext() == TD ->getDeclContext()) ? void (0) : __assert_fail ("TD->getLexicalDeclContext() == TD->getDeclContext()" , "clang/lib/AST/ASTImporter.cpp", 3249, __extension__ __PRETTY_FUNCTION__ )); | |||
3250 | return true; | |||
3251 | } | |||
3252 | } | |||
3253 | return false; | |||
3254 | } | |||
3255 | ||||
3256 | ExplicitSpecifier | |||
3257 | ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) { | |||
3258 | Expr *ExplicitExpr = ESpec.getExpr(); | |||
3259 | if (ExplicitExpr) | |||
3260 | ExplicitExpr = importChecked(Err, ESpec.getExpr()); | |||
3261 | return ExplicitSpecifier(ExplicitExpr, ESpec.getKind()); | |||
3262 | } | |||
3263 | ||||
3264 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { | |||
3265 | ||||
3266 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); | |||
3267 | auto RedeclIt = Redecls.begin(); | |||
3268 | // Import the first part of the decl chain. I.e. import all previous | |||
3269 | // declarations starting from the canonical decl. | |||
3270 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { | |||
3271 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); | |||
3272 | if (!ToRedeclOrErr) | |||
3273 | return ToRedeclOrErr.takeError(); | |||
3274 | } | |||
3275 | assert(*RedeclIt == D)(static_cast <bool> (*RedeclIt == D) ? void (0) : __assert_fail ("*RedeclIt == D", "clang/lib/AST/ASTImporter.cpp", 3275, __extension__ __PRETTY_FUNCTION__)); | |||
3276 | ||||
3277 | // Import the major distinguishing characteristics of this function. | |||
3278 | DeclContext *DC, *LexicalDC; | |||
3279 | DeclarationName Name; | |||
3280 | SourceLocation Loc; | |||
3281 | NamedDecl *ToD; | |||
3282 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3283 | return std::move(Err); | |||
3284 | if (ToD) | |||
3285 | return ToD; | |||
3286 | ||||
3287 | FunctionDecl *FoundByLookup = nullptr; | |||
3288 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); | |||
3289 | ||||
3290 | // If this is a function template specialization, then try to find the same | |||
3291 | // existing specialization in the "to" context. The lookup below will not | |||
3292 | // find any specialization, but would find the primary template; thus, we | |||
3293 | // have to skip normal lookup in case of specializations. | |||
3294 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? | |||
3295 | if (D->getTemplatedKind() == | |||
3296 | FunctionDecl::TK_FunctionTemplateSpecialization) { | |||
3297 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); | |||
3298 | if (!FoundFunctionOrErr) | |||
3299 | return FoundFunctionOrErr.takeError(); | |||
3300 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { | |||
3301 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) | |||
3302 | return Def; | |||
3303 | FoundByLookup = FoundFunction; | |||
3304 | } | |||
3305 | } | |||
3306 | // Try to find a function in our own ("to") context with the same name, same | |||
3307 | // type, and in the same context as the function we're importing. | |||
3308 | else if (!LexicalDC->isFunctionOrMethod()) { | |||
3309 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
3310 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; | |||
3311 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | |||
3312 | for (auto *FoundDecl : FoundDecls) { | |||
3313 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
3314 | continue; | |||
3315 | ||||
3316 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { | |||
3317 | if (!hasSameVisibilityContextAndLinkage(FoundFunction, D)) | |||
3318 | continue; | |||
3319 | ||||
3320 | if (IsStructuralMatch(D, FoundFunction)) { | |||
3321 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) | |||
3322 | return Def; | |||
3323 | FoundByLookup = FoundFunction; | |||
3324 | break; | |||
3325 | } | |||
3326 | // FIXME: Check for overloading more carefully, e.g., by boosting | |||
3327 | // Sema::IsOverload out to the AST library. | |||
3328 | ||||
3329 | // Function overloading is okay in C++. | |||
3330 | if (Importer.getToContext().getLangOpts().CPlusPlus) | |||
3331 | continue; | |||
3332 | ||||
3333 | // Complain about inconsistent function types. | |||
3334 | Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent) | |||
3335 | << Name << D->getType() << FoundFunction->getType(); | |||
3336 | Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here) | |||
3337 | << FoundFunction->getType(); | |||
3338 | ConflictingDecls.push_back(FoundDecl); | |||
3339 | } | |||
3340 | } | |||
3341 | ||||
3342 | if (!ConflictingDecls.empty()) { | |||
3343 | ExpectedName NameOrErr = Importer.HandleNameConflict( | |||
3344 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); | |||
3345 | if (NameOrErr) | |||
3346 | Name = NameOrErr.get(); | |||
3347 | else | |||
3348 | return NameOrErr.takeError(); | |||
3349 | } | |||
3350 | } | |||
3351 | ||||
3352 | // We do not allow more than one in-class declaration of a function. This is | |||
3353 | // because AST clients like VTableBuilder asserts on this. VTableBuilder | |||
3354 | // assumes there is only one in-class declaration. Building a redecl | |||
3355 | // chain would result in more than one in-class declaration for | |||
3356 | // overrides (even if they are part of the same redecl chain inside the | |||
3357 | // derived class.) | |||
3358 | if (FoundByLookup) { | |||
3359 | if (isa<CXXMethodDecl>(FoundByLookup)) { | |||
3360 | if (D->getLexicalDeclContext() == D->getDeclContext()) { | |||
3361 | if (!D->doesThisDeclarationHaveABody()) { | |||
3362 | if (FunctionTemplateDecl *DescribedD = | |||
3363 | D->getDescribedFunctionTemplate()) { | |||
3364 | // Handle a "templated" function together with its described | |||
3365 | // template. This avoids need for a similar check at import of the | |||
3366 | // described template. | |||
3367 | assert(FoundByLookup->getDescribedFunctionTemplate() &&(static_cast <bool> (FoundByLookup->getDescribedFunctionTemplate () && "Templated function mapped to non-templated?") ? void (0) : __assert_fail ("FoundByLookup->getDescribedFunctionTemplate() && \"Templated function mapped to non-templated?\"" , "clang/lib/AST/ASTImporter.cpp", 3368, __extension__ __PRETTY_FUNCTION__ )) | |||
3368 | "Templated function mapped to non-templated?")(static_cast <bool> (FoundByLookup->getDescribedFunctionTemplate () && "Templated function mapped to non-templated?") ? void (0) : __assert_fail ("FoundByLookup->getDescribedFunctionTemplate() && \"Templated function mapped to non-templated?\"" , "clang/lib/AST/ASTImporter.cpp", 3368, __extension__ __PRETTY_FUNCTION__ )); | |||
3369 | Importer.MapImported(DescribedD, | |||
3370 | FoundByLookup->getDescribedFunctionTemplate()); | |||
3371 | } | |||
3372 | return Importer.MapImported(D, FoundByLookup); | |||
3373 | } else { | |||
3374 | // Let's continue and build up the redecl chain in this case. | |||
3375 | // FIXME Merge the functions into one decl. | |||
3376 | } | |||
3377 | } | |||
3378 | } | |||
3379 | } | |||
3380 | ||||
3381 | DeclarationNameInfo NameInfo(Name, Loc); | |||
3382 | // Import additional name location/type info. | |||
3383 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | |||
3384 | return std::move(Err); | |||
3385 | ||||
3386 | QualType FromTy = D->getType(); | |||
3387 | TypeSourceInfo *FromTSI = D->getTypeSourceInfo(); | |||
3388 | // Set to true if we do not import the type of the function as is. There are | |||
3389 | // cases when the original type would result in an infinite recursion during | |||
3390 | // the import. To avoid an infinite recursion when importing, we create the | |||
3391 | // FunctionDecl with a simplified function type and update it only after the | |||
3392 | // relevant AST nodes are already imported. | |||
3393 | // The type is related to TypeSourceInfo (it references the type), so we must | |||
3394 | // do the same with TypeSourceInfo. | |||
3395 | bool UsedDifferentProtoType = false; | |||
3396 | if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) { | |||
3397 | QualType FromReturnTy = FromFPT->getReturnType(); | |||
3398 | // Functions with auto return type may define a struct inside their body | |||
3399 | // and the return type could refer to that struct. | |||
3400 | // E.g.: auto foo() { struct X{}; return X(); } | |||
3401 | // To avoid an infinite recursion when importing, create the FunctionDecl | |||
3402 | // with a simplified return type. | |||
3403 | if (hasAutoReturnTypeDeclaredInside(D)) { | |||
3404 | FromReturnTy = Importer.getFromContext().VoidTy; | |||
3405 | UsedDifferentProtoType = true; | |||
3406 | } | |||
3407 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); | |||
3408 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the | |||
3409 | // FunctionDecl that we are importing the FunctionProtoType for. | |||
3410 | // To avoid an infinite recursion when importing, create the FunctionDecl | |||
3411 | // with a simplified function type. | |||
3412 | if (FromEPI.ExceptionSpec.SourceDecl || | |||
3413 | FromEPI.ExceptionSpec.SourceTemplate || | |||
3414 | FromEPI.ExceptionSpec.NoexceptExpr) { | |||
3415 | FunctionProtoType::ExtProtoInfo DefaultEPI; | |||
3416 | FromEPI = DefaultEPI; | |||
3417 | UsedDifferentProtoType = true; | |||
3418 | } | |||
3419 | FromTy = Importer.getFromContext().getFunctionType( | |||
3420 | FromReturnTy, FromFPT->getParamTypes(), FromEPI); | |||
3421 | FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo( | |||
3422 | FromTy, D->getBeginLoc()); | |||
3423 | } | |||
3424 | ||||
3425 | Error Err = Error::success(); | |||
3426 | auto T = importChecked(Err, FromTy); | |||
3427 | auto TInfo = importChecked(Err, FromTSI); | |||
3428 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); | |||
3429 | auto ToEndLoc = importChecked(Err, D->getEndLoc()); | |||
3430 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | |||
3431 | auto TrailingRequiresClause = | |||
3432 | importChecked(Err, D->getTrailingRequiresClause()); | |||
3433 | if (Err) | |||
3434 | return std::move(Err); | |||
3435 | ||||
3436 | // Import the function parameters. | |||
3437 | SmallVector<ParmVarDecl *, 8> Parameters; | |||
3438 | for (auto P : D->parameters()) { | |||
3439 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) | |||
3440 | Parameters.push_back(*ToPOrErr); | |||
3441 | else | |||
3442 | return ToPOrErr.takeError(); | |||
3443 | } | |||
3444 | ||||
3445 | // Create the imported function. | |||
3446 | FunctionDecl *ToFunction = nullptr; | |||
3447 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { | |||
3448 | ExplicitSpecifier ESpec = | |||
3449 | importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier()); | |||
3450 | if (Err) | |||
3451 | return std::move(Err); | |||
3452 | auto ToInheritedConstructor = InheritedConstructor(); | |||
3453 | if (FromConstructor->isInheritingConstructor()) { | |||
3454 | Expected<InheritedConstructor> ImportedInheritedCtor = | |||
3455 | import(FromConstructor->getInheritedConstructor()); | |||
3456 | if (!ImportedInheritedCtor) | |||
3457 | return ImportedInheritedCtor.takeError(); | |||
3458 | ToInheritedConstructor = *ImportedInheritedCtor; | |||
3459 | } | |||
3460 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( | |||
3461 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | |||
3462 | ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(), | |||
3463 | D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(), | |||
3464 | ToInheritedConstructor, TrailingRequiresClause)) | |||
3465 | return ToFunction; | |||
3466 | } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) { | |||
3467 | ||||
3468 | Error Err = Error::success(); | |||
3469 | auto ToOperatorDelete = importChecked( | |||
3470 | Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete())); | |||
3471 | auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg()); | |||
3472 | if (Err) | |||
3473 | return std::move(Err); | |||
3474 | ||||
3475 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( | |||
3476 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | |||
3477 | ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(), | |||
3478 | D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(), | |||
3479 | TrailingRequiresClause)) | |||
3480 | return ToFunction; | |||
3481 | ||||
3482 | CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction); | |||
3483 | ||||
3484 | ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); | |||
3485 | } else if (CXXConversionDecl *FromConversion = | |||
3486 | dyn_cast<CXXConversionDecl>(D)) { | |||
3487 | ExplicitSpecifier ESpec = | |||
3488 | importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier()); | |||
3489 | if (Err) | |||
3490 | return std::move(Err); | |||
3491 | if (GetImportedOrCreateDecl<CXXConversionDecl>( | |||
3492 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | |||
3493 | ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(), | |||
3494 | D->isInlineSpecified(), ESpec, D->getConstexprKind(), | |||
3495 | SourceLocation(), TrailingRequiresClause)) | |||
3496 | return ToFunction; | |||
3497 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { | |||
3498 | if (GetImportedOrCreateDecl<CXXMethodDecl>( | |||
3499 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | |||
3500 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), | |||
3501 | Method->UsesFPIntrin(), Method->isInlineSpecified(), | |||
3502 | D->getConstexprKind(), SourceLocation(), TrailingRequiresClause)) | |||
3503 | return ToFunction; | |||
3504 | } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) { | |||
3505 | ExplicitSpecifier ESpec = | |||
3506 | importExplicitSpecifier(Err, Guide->getExplicitSpecifier()); | |||
3507 | CXXConstructorDecl *Ctor = | |||
3508 | importChecked(Err, Guide->getCorrespondingConstructor()); | |||
3509 | if (Err) | |||
3510 | return std::move(Err); | |||
3511 | if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>( | |||
3512 | ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec, | |||
3513 | NameInfo, T, TInfo, ToEndLoc, Ctor)) | |||
3514 | return ToFunction; | |||
3515 | cast<CXXDeductionGuideDecl>(ToFunction) | |||
3516 | ->setIsCopyDeductionCandidate(Guide->isCopyDeductionCandidate()); | |||
3517 | } else { | |||
3518 | if (GetImportedOrCreateDecl( | |||
3519 | ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, | |||
3520 | NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(), | |||
3521 | D->isInlineSpecified(), D->hasWrittenPrototype(), | |||
3522 | D->getConstexprKind(), TrailingRequiresClause)) | |||
3523 | return ToFunction; | |||
3524 | } | |||
3525 | ||||
3526 | // Connect the redecl chain. | |||
3527 | if (FoundByLookup) { | |||
3528 | auto *Recent = const_cast<FunctionDecl *>( | |||
3529 | FoundByLookup->getMostRecentDecl()); | |||
3530 | ToFunction->setPreviousDecl(Recent); | |||
3531 | // FIXME Probably we should merge exception specifications. E.g. In the | |||
3532 | // "To" context the existing function may have exception specification with | |||
3533 | // noexcept-unevaluated, while the newly imported function may have an | |||
3534 | // evaluated noexcept. A call to adjustExceptionSpec() on the imported | |||
3535 | // decl and its redeclarations may be required. | |||
3536 | } | |||
3537 | ||||
3538 | ToFunction->setQualifierInfo(ToQualifierLoc); | |||
3539 | ToFunction->setAccess(D->getAccess()); | |||
3540 | ToFunction->setLexicalDeclContext(LexicalDC); | |||
3541 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); | |||
3542 | ToFunction->setTrivial(D->isTrivial()); | |||
3543 | ToFunction->setPure(D->isPure()); | |||
3544 | ToFunction->setDefaulted(D->isDefaulted()); | |||
3545 | ToFunction->setExplicitlyDefaulted(D->isExplicitlyDefaulted()); | |||
3546 | ToFunction->setDeletedAsWritten(D->isDeletedAsWritten()); | |||
3547 | ToFunction->setRangeEnd(ToEndLoc); | |||
3548 | ||||
3549 | // Set the parameters. | |||
3550 | for (auto *Param : Parameters) { | |||
3551 | Param->setOwningFunction(ToFunction); | |||
3552 | ToFunction->addDeclInternal(Param); | |||
3553 | if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable()) | |||
3554 | LT->update(Param, Importer.getToContext().getTranslationUnitDecl()); | |||
3555 | } | |||
3556 | ToFunction->setParams(Parameters); | |||
3557 | ||||
3558 | // We need to complete creation of FunctionProtoTypeLoc manually with setting | |||
3559 | // params it refers to. | |||
3560 | if (TInfo) { | |||
3561 | if (auto ProtoLoc = | |||
3562 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { | |||
3563 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) | |||
3564 | ProtoLoc.setParam(I, Parameters[I]); | |||
3565 | } | |||
3566 | } | |||
3567 | ||||
3568 | // Import the describing template function, if any. | |||
3569 | if (FromFT) { | |||
3570 | auto ToFTOrErr = import(FromFT); | |||
3571 | if (!ToFTOrErr) | |||
3572 | return ToFTOrErr.takeError(); | |||
3573 | } | |||
3574 | ||||
3575 | // Import Ctor initializers. | |||
3576 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { | |||
3577 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { | |||
3578 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); | |||
3579 | // Import first, then allocate memory and copy if there was no error. | |||
3580 | if (Error Err = ImportContainerChecked( | |||
3581 | FromConstructor->inits(), CtorInitializers)) | |||
3582 | return std::move(Err); | |||
3583 | auto **Memory = | |||
3584 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; | |||
3585 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); | |||
3586 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); | |||
3587 | ToCtor->setCtorInitializers(Memory); | |||
3588 | ToCtor->setNumCtorInitializers(NumInitializers); | |||
3589 | } | |||
3590 | } | |||
3591 | ||||
3592 | if (D->doesThisDeclarationHaveABody()) { | |||
3593 | Error Err = ImportFunctionDeclBody(D, ToFunction); | |||
3594 | ||||
3595 | if (Err) | |||
3596 | return std::move(Err); | |||
3597 | } | |||
3598 | ||||
3599 | // Import and set the original type in case we used another type. | |||
3600 | if (UsedDifferentProtoType) { | |||
3601 | if (ExpectedType TyOrErr = import(D->getType())) | |||
3602 | ToFunction->setType(*TyOrErr); | |||
3603 | else | |||
3604 | return TyOrErr.takeError(); | |||
3605 | if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo())) | |||
3606 | ToFunction->setTypeSourceInfo(*TSIOrErr); | |||
3607 | else | |||
3608 | return TSIOrErr.takeError(); | |||
3609 | } | |||
3610 | ||||
3611 | // FIXME: Other bits to merge? | |||
3612 | ||||
3613 | // If it is a template, import all related things. | |||
3614 | if (Error Err = ImportTemplateInformation(D, ToFunction)) | |||
3615 | return std::move(Err); | |||
3616 | ||||
3617 | addDeclToContexts(D, ToFunction); | |||
3618 | ||||
3619 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) | |||
3620 | if (Error Err = ImportOverriddenMethods(cast<CXXMethodDecl>(ToFunction), | |||
3621 | FromCXXMethod)) | |||
3622 | return std::move(Err); | |||
3623 | ||||
3624 | // Import the rest of the chain. I.e. import all subsequent declarations. | |||
3625 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { | |||
3626 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); | |||
3627 | if (!ToRedeclOrErr) | |||
3628 | return ToRedeclOrErr.takeError(); | |||
3629 | } | |||
3630 | ||||
3631 | return ToFunction; | |||
3632 | } | |||
3633 | ||||
3634 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { | |||
3635 | return VisitFunctionDecl(D); | |||
3636 | } | |||
3637 | ||||
3638 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { | |||
3639 | return VisitCXXMethodDecl(D); | |||
3640 | } | |||
3641 | ||||
3642 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { | |||
3643 | return VisitCXXMethodDecl(D); | |||
3644 | } | |||
3645 | ||||
3646 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { | |||
3647 | return VisitCXXMethodDecl(D); | |||
3648 | } | |||
3649 | ||||
3650 | ExpectedDecl | |||
3651 | ASTNodeImporter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) { | |||
3652 | return VisitFunctionDecl(D); | |||
3653 | } | |||
3654 | ||||
3655 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { | |||
3656 | // Import the major distinguishing characteristics of a variable. | |||
3657 | DeclContext *DC, *LexicalDC; | |||
3658 | DeclarationName Name; | |||
3659 | SourceLocation Loc; | |||
3660 | NamedDecl *ToD; | |||
3661 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3662 | return std::move(Err); | |||
3663 | if (ToD) | |||
3664 | return ToD; | |||
3665 | ||||
3666 | // Determine whether we've already imported this field. | |||
3667 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | |||
3668 | for (auto *FoundDecl : FoundDecls) { | |||
3669 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { | |||
3670 | // For anonymous fields, match up by index. | |||
3671 | if (!Name && | |||
3672 | ASTImporter::getFieldIndex(D) != | |||
3673 | ASTImporter::getFieldIndex(FoundField)) | |||
3674 | continue; | |||
3675 | ||||
3676 | if (Importer.IsStructurallyEquivalent(D->getType(), | |||
3677 | FoundField->getType())) { | |||
3678 | Importer.MapImported(D, FoundField); | |||
3679 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the | |||
3680 | // initializer of a FieldDecl might not had been instantiated in the | |||
3681 | // "To" context. However, the "From" context might instantiated that, | |||
3682 | // thus we have to merge that. | |||
3683 | // Note: `hasInClassInitializer()` is not the same as non-null | |||
3684 | // `getInClassInitializer()` value. | |||
3685 | if (Expr *FromInitializer = D->getInClassInitializer()) { | |||
3686 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) { | |||
3687 | // Import of the FromInitializer may result in the setting of | |||
3688 | // InClassInitializer. If not, set it here. | |||
3689 | assert(FoundField->hasInClassInitializer() &&(static_cast <bool> (FoundField->hasInClassInitializer () && "Field should have an in-class initializer if it has an " "expression for it.") ? void (0) : __assert_fail ("FoundField->hasInClassInitializer() && \"Field should have an in-class initializer if it has an \" \"expression for it.\"" , "clang/lib/AST/ASTImporter.cpp", 3691, __extension__ __PRETTY_FUNCTION__ )) | |||
3690 | "Field should have an in-class initializer if it has an "(static_cast <bool> (FoundField->hasInClassInitializer () && "Field should have an in-class initializer if it has an " "expression for it.") ? void (0) : __assert_fail ("FoundField->hasInClassInitializer() && \"Field should have an in-class initializer if it has an \" \"expression for it.\"" , "clang/lib/AST/ASTImporter.cpp", 3691, __extension__ __PRETTY_FUNCTION__ )) | |||
3691 | "expression for it.")(static_cast <bool> (FoundField->hasInClassInitializer () && "Field should have an in-class initializer if it has an " "expression for it.") ? void (0) : __assert_fail ("FoundField->hasInClassInitializer() && \"Field should have an in-class initializer if it has an \" \"expression for it.\"" , "clang/lib/AST/ASTImporter.cpp", 3691, __extension__ __PRETTY_FUNCTION__ )); | |||
3692 | if (!FoundField->getInClassInitializer()) | |||
3693 | FoundField->setInClassInitializer(*ToInitializerOrErr); | |||
3694 | } else { | |||
3695 | return ToInitializerOrErr.takeError(); | |||
3696 | } | |||
3697 | } | |||
3698 | return FoundField; | |||
3699 | } | |||
3700 | ||||
3701 | // FIXME: Why is this case not handled with calling HandleNameConflict? | |||
3702 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) | |||
3703 | << Name << D->getType() << FoundField->getType(); | |||
3704 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) | |||
3705 | << FoundField->getType(); | |||
3706 | ||||
3707 | return make_error<ImportError>(ImportError::NameConflict); | |||
3708 | } | |||
3709 | } | |||
3710 | ||||
3711 | Error Err = Error::success(); | |||
3712 | auto ToType = importChecked(Err, D->getType()); | |||
3713 | auto ToTInfo = importChecked(Err, D->getTypeSourceInfo()); | |||
3714 | auto ToBitWidth = importChecked(Err, D->getBitWidth()); | |||
3715 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); | |||
3716 | auto ToInitializer = importChecked(Err, D->getInClassInitializer()); | |||
3717 | if (Err) | |||
3718 | return std::move(Err); | |||
3719 | const Type *ToCapturedVLAType = nullptr; | |||
3720 | if (Error Err = Importer.importInto( | |||
3721 | ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType()))) | |||
3722 | return std::move(Err); | |||
3723 | ||||
3724 | FieldDecl *ToField; | |||
3725 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, | |||
3726 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), | |||
3727 | ToType, ToTInfo, ToBitWidth, D->isMutable(), | |||
3728 | D->getInClassInitStyle())) | |||
3729 | return ToField; | |||
3730 | ||||
3731 | ToField->setAccess(D->getAccess()); | |||
3732 | ToField->setLexicalDeclContext(LexicalDC); | |||
3733 | if (ToInitializer) | |||
3734 | ToField->setInClassInitializer(ToInitializer); | |||
3735 | ToField->setImplicit(D->isImplicit()); | |||
3736 | if (ToCapturedVLAType) | |||
3737 | ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType)); | |||
3738 | LexicalDC->addDeclInternal(ToField); | |||
3739 | return ToField; | |||
3740 | } | |||
3741 | ||||
3742 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { | |||
3743 | // Import the major distinguishing characteristics of a variable. | |||
3744 | DeclContext *DC, *LexicalDC; | |||
3745 | DeclarationName Name; | |||
3746 | SourceLocation Loc; | |||
3747 | NamedDecl *ToD; | |||
3748 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3749 | return std::move(Err); | |||
3750 | if (ToD) | |||
3751 | return ToD; | |||
3752 | ||||
3753 | // Determine whether we've already imported this field. | |||
3754 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | |||
3755 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | |||
3756 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { | |||
3757 | // For anonymous indirect fields, match up by index. | |||
3758 | if (!Name && | |||
3759 | ASTImporter::getFieldIndex(D) != | |||
3760 | ASTImporter::getFieldIndex(FoundField)) | |||
3761 | continue; | |||
3762 | ||||
3763 | if (Importer.IsStructurallyEquivalent(D->getType(), | |||
3764 | FoundField->getType(), | |||
3765 | !Name.isEmpty())) { | |||
3766 | Importer.MapImported(D, FoundField); | |||
3767 | return FoundField; | |||
3768 | } | |||
3769 | ||||
3770 | // If there are more anonymous fields to check, continue. | |||
3771 | if (!Name && I < N-1) | |||
3772 | continue; | |||
3773 | ||||
3774 | // FIXME: Why is this case not handled with calling HandleNameConflict? | |||
3775 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) | |||
3776 | << Name << D->getType() << FoundField->getType(); | |||
3777 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) | |||
3778 | << FoundField->getType(); | |||
3779 | ||||
3780 | return make_error<ImportError>(ImportError::NameConflict); | |||
3781 | } | |||
3782 | } | |||
3783 | ||||
3784 | // Import the type. | |||
3785 | auto TypeOrErr = import(D->getType()); | |||
3786 | if (!TypeOrErr) | |||
3787 | return TypeOrErr.takeError(); | |||
3788 | ||||
3789 | auto **NamedChain = | |||
3790 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; | |||
3791 | ||||
3792 | unsigned i = 0; | |||
3793 | for (auto *PI : D->chain()) | |||
3794 | if (Expected<NamedDecl *> ToD = import(PI)) | |||
3795 | NamedChain[i++] = *ToD; | |||
3796 | else | |||
3797 | return ToD.takeError(); | |||
3798 | ||||
3799 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; | |||
3800 | IndirectFieldDecl *ToIndirectField; | |||
3801 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, | |||
3802 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) | |||
3803 | // FIXME here we leak `NamedChain` which is allocated before | |||
3804 | return ToIndirectField; | |||
3805 | ||||
3806 | ToIndirectField->setAccess(D->getAccess()); | |||
3807 | ToIndirectField->setLexicalDeclContext(LexicalDC); | |||
3808 | LexicalDC->addDeclInternal(ToIndirectField); | |||
3809 | return ToIndirectField; | |||
3810 | } | |||
3811 | ||||
3812 | /// Used as return type of getFriendCountAndPosition. | |||
3813 | struct FriendCountAndPosition { | |||
3814 | /// Number of similar looking friends. | |||
3815 | unsigned int TotalCount; | |||
3816 | /// Index of the specific FriendDecl. | |||
3817 | unsigned int IndexOfDecl; | |||
3818 | }; | |||
3819 | ||||
3820 | template <class T> | |||
3821 | static FriendCountAndPosition getFriendCountAndPosition( | |||
3822 | const FriendDecl *FD, | |||
3823 | llvm::function_ref<T(const FriendDecl *)> GetCanTypeOrDecl) { | |||
3824 | unsigned int FriendCount = 0; | |||
3825 | llvm::Optional<unsigned int> FriendPosition; | |||
3826 | const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext()); | |||
3827 | ||||
3828 | T TypeOrDecl = GetCanTypeOrDecl(FD); | |||
3829 | ||||
3830 | for (const FriendDecl *FoundFriend : RD->friends()) { | |||
3831 | if (FoundFriend == FD) { | |||
3832 | FriendPosition = FriendCount; | |||
3833 | ++FriendCount; | |||
3834 | } else if (!FoundFriend->getFriendDecl() == !FD->getFriendDecl() && | |||
3835 | GetCanTypeOrDecl(FoundFriend) == TypeOrDecl) { | |||
3836 | ++FriendCount; | |||
3837 | } | |||
3838 | } | |||
3839 | ||||
3840 | assert(FriendPosition && "Friend decl not found in own parent.")(static_cast <bool> (FriendPosition && "Friend decl not found in own parent." ) ? void (0) : __assert_fail ("FriendPosition && \"Friend decl not found in own parent.\"" , "clang/lib/AST/ASTImporter.cpp", 3840, __extension__ __PRETTY_FUNCTION__ )); | |||
3841 | ||||
3842 | return {FriendCount, *FriendPosition}; | |||
3843 | } | |||
3844 | ||||
3845 | static FriendCountAndPosition getFriendCountAndPosition(const FriendDecl *FD) { | |||
3846 | if (FD->getFriendType()) | |||
3847 | return getFriendCountAndPosition<QualType>(FD, [](const FriendDecl *F) { | |||
3848 | if (TypeSourceInfo *TSI = F->getFriendType()) | |||
3849 | return TSI->getType().getCanonicalType(); | |||
3850 | llvm_unreachable("Wrong friend object type.")::llvm::llvm_unreachable_internal("Wrong friend object type." , "clang/lib/AST/ASTImporter.cpp", 3850); | |||
3851 | }); | |||
3852 | else | |||
3853 | return getFriendCountAndPosition<Decl *>(FD, [](const FriendDecl *F) { | |||
3854 | if (Decl *D = F->getFriendDecl()) | |||
3855 | return D->getCanonicalDecl(); | |||
3856 | llvm_unreachable("Wrong friend object type.")::llvm::llvm_unreachable_internal("Wrong friend object type." , "clang/lib/AST/ASTImporter.cpp", 3856); | |||
3857 | }); | |||
3858 | } | |||
3859 | ||||
3860 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { | |||
3861 | // Import the major distinguishing characteristics of a declaration. | |||
3862 | DeclContext *DC, *LexicalDC; | |||
3863 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
3864 | return std::move(Err); | |||
3865 | ||||
3866 | // Determine whether we've already imported this decl. | |||
3867 | // FriendDecl is not a NamedDecl so we cannot use lookup. | |||
3868 | // We try to maintain order and count of redundant friend declarations. | |||
3869 | const auto *RD = cast<CXXRecordDecl>(DC); | |||
3870 | FriendDecl *ImportedFriend = RD->getFirstFriend(); | |||
3871 | SmallVector<FriendDecl *, 2> ImportedEquivalentFriends; | |||
3872 | ||||
3873 | while (ImportedFriend) { | |||
3874 | bool Match = false; | |||
3875 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { | |||
3876 | Match = | |||
3877 | IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), | |||
3878 | /*Complain=*/false); | |||
3879 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { | |||
3880 | Match = Importer.IsStructurallyEquivalent( | |||
3881 | D->getFriendType()->getType(), | |||
3882 | ImportedFriend->getFriendType()->getType(), /*Complain=*/false); | |||
3883 | } | |||
3884 | if (Match) | |||
3885 | ImportedEquivalentFriends.push_back(ImportedFriend); | |||
3886 | ||||
3887 | ImportedFriend = ImportedFriend->getNextFriend(); | |||
3888 | } | |||
3889 | FriendCountAndPosition CountAndPosition = getFriendCountAndPosition(D); | |||
3890 | ||||
3891 | assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&(static_cast <bool> (ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount && "Class with non-matching friends is imported, ODR check wrong?" ) ? void (0) : __assert_fail ("ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount && \"Class with non-matching friends is imported, ODR check wrong?\"" , "clang/lib/AST/ASTImporter.cpp", 3892, __extension__ __PRETTY_FUNCTION__ )) | |||
3892 | "Class with non-matching friends is imported, ODR check wrong?")(static_cast <bool> (ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount && "Class with non-matching friends is imported, ODR check wrong?" ) ? void (0) : __assert_fail ("ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount && \"Class with non-matching friends is imported, ODR check wrong?\"" , "clang/lib/AST/ASTImporter.cpp", 3892, __extension__ __PRETTY_FUNCTION__ )); | |||
3893 | if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount) | |||
3894 | return Importer.MapImported( | |||
3895 | D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]); | |||
3896 | ||||
3897 | // Not found. Create it. | |||
3898 | // The declarations will be put into order later by ImportDeclContext. | |||
3899 | FriendDecl::FriendUnion ToFU; | |||
3900 | if (NamedDecl *FriendD = D->getFriendDecl()) { | |||
3901 | NamedDecl *ToFriendD; | |||
3902 | if (Error Err = importInto(ToFriendD, FriendD)) | |||
3903 | return std::move(Err); | |||
3904 | ||||
3905 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && | |||
3906 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) | |||
3907 | ToFriendD->setObjectOfFriendDecl(false); | |||
3908 | ||||
3909 | ToFU = ToFriendD; | |||
3910 | } else { // The friend is a type, not a decl. | |||
3911 | if (auto TSIOrErr = import(D->getFriendType())) | |||
3912 | ToFU = *TSIOrErr; | |||
3913 | else | |||
3914 | return TSIOrErr.takeError(); | |||
3915 | } | |||
3916 | ||||
3917 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); | |||
3918 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); | |||
3919 | for (unsigned I = 0; I < D->NumTPLists; I++) { | |||
3920 | if (auto ListOrErr = import(FromTPLists[I])) | |||
3921 | ToTPLists[I] = *ListOrErr; | |||
3922 | else | |||
3923 | return ListOrErr.takeError(); | |||
3924 | } | |||
3925 | ||||
3926 | auto LocationOrErr = import(D->getLocation()); | |||
3927 | if (!LocationOrErr) | |||
3928 | return LocationOrErr.takeError(); | |||
3929 | auto FriendLocOrErr = import(D->getFriendLoc()); | |||
3930 | if (!FriendLocOrErr) | |||
3931 | return FriendLocOrErr.takeError(); | |||
3932 | ||||
3933 | FriendDecl *FrD; | |||
3934 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, | |||
3935 | *LocationOrErr, ToFU, | |||
3936 | *FriendLocOrErr, ToTPLists)) | |||
3937 | return FrD; | |||
3938 | ||||
3939 | FrD->setAccess(D->getAccess()); | |||
3940 | FrD->setLexicalDeclContext(LexicalDC); | |||
3941 | LexicalDC->addDeclInternal(FrD); | |||
3942 | return FrD; | |||
3943 | } | |||
3944 | ||||
3945 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { | |||
3946 | // Import the major distinguishing characteristics of an ivar. | |||
3947 | DeclContext *DC, *LexicalDC; | |||
3948 | DeclarationName Name; | |||
3949 | SourceLocation Loc; | |||
3950 | NamedDecl *ToD; | |||
3951 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3952 | return std::move(Err); | |||
3953 | if (ToD) | |||
3954 | return ToD; | |||
3955 | ||||
3956 | // Determine whether we've already imported this ivar | |||
3957 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | |||
3958 | for (auto *FoundDecl : FoundDecls) { | |||
3959 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { | |||
3960 | if (Importer.IsStructurallyEquivalent(D->getType(), | |||
3961 | FoundIvar->getType())) { | |||
3962 | Importer.MapImported(D, FoundIvar); | |||
3963 | return FoundIvar; | |||
3964 | } | |||
3965 | ||||
3966 | Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent) | |||
3967 | << Name << D->getType() << FoundIvar->getType(); | |||
3968 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) | |||
3969 | << FoundIvar->getType(); | |||
3970 | ||||
3971 | return make_error<ImportError>(ImportError::NameConflict); | |||
3972 | } | |||
3973 | } | |||
3974 | ||||
3975 | Error Err = Error::success(); | |||
3976 | auto ToType = importChecked(Err, D->getType()); | |||
3977 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); | |||
3978 | auto ToBitWidth = importChecked(Err, D->getBitWidth()); | |||
3979 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); | |||
3980 | if (Err) | |||
3981 | return std::move(Err); | |||
3982 | ||||
3983 | ObjCIvarDecl *ToIvar; | |||
3984 | if (GetImportedOrCreateDecl( | |||
3985 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), | |||
3986 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), | |||
3987 | ToType, ToTypeSourceInfo, | |||
3988 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) | |||
3989 | return ToIvar; | |||
3990 | ||||
3991 | ToIvar->setLexicalDeclContext(LexicalDC); | |||
3992 | LexicalDC->addDeclInternal(ToIvar); | |||
3993 | return ToIvar; | |||
3994 | } | |||
3995 | ||||
3996 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { | |||
3997 | ||||
3998 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); | |||
3999 | auto RedeclIt = Redecls.begin(); | |||
4000 | // Import the first part of the decl chain. I.e. import all previous | |||
4001 | // declarations starting from the canonical decl. | |||
4002 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { | |||
4003 | ExpectedDecl RedeclOrErr = import(*RedeclIt); | |||
4004 | if (!RedeclOrErr) | |||
4005 | return RedeclOrErr.takeError(); | |||
4006 | } | |||
4007 | assert(*RedeclIt == D)(static_cast <bool> (*RedeclIt == D) ? void (0) : __assert_fail ("*RedeclIt == D", "clang/lib/AST/ASTImporter.cpp", 4007, __extension__ __PRETTY_FUNCTION__)); | |||
4008 | ||||
4009 | // Import the major distinguishing characteristics of a variable. | |||
4010 | DeclContext *DC, *LexicalDC; | |||
4011 | DeclarationName Name; | |||
4012 | SourceLocation Loc; | |||
4013 | NamedDecl *ToD; | |||
4014 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4015 | return std::move(Err); | |||
4016 | if (ToD) | |||
4017 | return ToD; | |||
4018 | ||||
4019 | // Try to find a variable in our own ("to") context with the same name and | |||
4020 | // in the same context as the variable we're importing. | |||
4021 | VarDecl *FoundByLookup = nullptr; | |||
4022 | if (D->isFileVarDecl()) { | |||
4023 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
4024 | unsigned IDNS = Decl::IDNS_Ordinary; | |||
4025 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | |||
4026 | for (auto *FoundDecl : FoundDecls) { | |||
4027 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
4028 | continue; | |||
4029 | ||||
4030 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { | |||
4031 | if (!hasSameVisibilityContextAndLinkage(FoundVar, D)) | |||
4032 | continue; | |||
4033 | if (Importer.IsStructurallyEquivalent(D->getType(), | |||
4034 | FoundVar->getType())) { | |||
4035 | ||||
4036 | // The VarDecl in the "From" context has a definition, but in the | |||
4037 | // "To" context we already have a definition. | |||
4038 | VarDecl *FoundDef = FoundVar->getDefinition(); | |||
4039 | if (D->isThisDeclarationADefinition() && FoundDef) | |||
4040 | // FIXME Check for ODR error if the two definitions have | |||
4041 | // different initializers? | |||
4042 | return Importer.MapImported(D, FoundDef); | |||
4043 | ||||
4044 | // The VarDecl in the "From" context has an initializer, but in the | |||
4045 | // "To" context we already have an initializer. | |||
4046 | const VarDecl *FoundDInit = nullptr; | |||
4047 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) | |||
4048 | // FIXME Diagnose ODR error if the two initializers are different? | |||
4049 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); | |||
4050 | ||||
4051 | FoundByLookup = FoundVar; | |||
4052 | break; | |||
4053 | } | |||
4054 | ||||
4055 | const ArrayType *FoundArray | |||
4056 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); | |||
4057 | const ArrayType *TArray | |||
4058 | = Importer.getToContext().getAsArrayType(D->getType()); | |||
4059 | if (FoundArray && TArray) { | |||
4060 | if (isa<IncompleteArrayType>(FoundArray) && | |||
4061 | isa<ConstantArrayType>(TArray)) { | |||
4062 | // Import the type. | |||
4063 | if (auto TyOrErr = import(D->getType())) | |||
4064 | FoundVar->setType(*TyOrErr); | |||
4065 | else | |||
4066 | return TyOrErr.takeError(); | |||
4067 | ||||
4068 | FoundByLookup = FoundVar; | |||
4069 | break; | |||
4070 | } else if (isa<IncompleteArrayType>(TArray) && | |||
4071 | isa<ConstantArrayType>(FoundArray)) { | |||
4072 | FoundByLookup = FoundVar; | |||
4073 | break; | |||
4074 | } | |||
4075 | } | |||
4076 | ||||
4077 | Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent) | |||
4078 | << Name << D->getType() << FoundVar->getType(); | |||
4079 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) | |||
4080 | << FoundVar->getType(); | |||
4081 | ConflictingDecls.push_back(FoundDecl); | |||
4082 | } | |||
4083 | } | |||
4084 | ||||
4085 | if (!ConflictingDecls.empty()) { | |||
4086 | ExpectedName NameOrErr = Importer.HandleNameConflict( | |||
4087 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); | |||
4088 | if (NameOrErr) | |||
4089 | Name = NameOrErr.get(); | |||
4090 | else | |||
4091 | return NameOrErr.takeError(); | |||
4092 | } | |||
4093 | } | |||
4094 | ||||
4095 | Error Err = Error::success(); | |||
4096 | auto ToType = importChecked(Err, D->getType()); | |||
4097 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); | |||
4098 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); | |||
4099 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | |||
4100 | if (Err) | |||
4101 | return std::move(Err); | |||
4102 | ||||
4103 | VarDecl *ToVar; | |||
4104 | if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) { | |||
4105 | SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size()); | |||
4106 | if (Error Err = | |||
4107 | ImportArrayChecked(FromDecomp->bindings(), Bindings.begin())) | |||
4108 | return std::move(Err); | |||
4109 | DecompositionDecl *ToDecomp; | |||
4110 | if (GetImportedOrCreateDecl( | |||
4111 | ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart, | |||
4112 | Loc, ToType, ToTypeSourceInfo, D->getStorageClass(), Bindings)) | |||
4113 | return ToDecomp; | |||
4114 | ToVar = ToDecomp; | |||
4115 | } else { | |||
4116 | // Create the imported variable. | |||
4117 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, | |||
4118 | ToInnerLocStart, Loc, | |||
4119 | Name.getAsIdentifierInfo(), ToType, | |||
4120 | ToTypeSourceInfo, D->getStorageClass())) | |||
4121 | return ToVar; | |||
4122 | } | |||
4123 | ||||
4124 | ToVar->setTSCSpec(D->getTSCSpec()); | |||
4125 | ToVar->setQualifierInfo(ToQualifierLoc); | |||
4126 | ToVar->setAccess(D->getAccess()); | |||
4127 | ToVar->setLexicalDeclContext(LexicalDC); | |||
4128 | ||||
4129 | if (FoundByLookup) { | |||
4130 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); | |||
4131 | ToVar->setPreviousDecl(Recent); | |||
4132 | } | |||
4133 | ||||
4134 | // Import the described template, if any. | |||
4135 | if (D->getDescribedVarTemplate()) { | |||
4136 | auto ToVTOrErr = import(D->getDescribedVarTemplate()); | |||
4137 | if (!ToVTOrErr) | |||
4138 | return ToVTOrErr.takeError(); | |||
4139 | } | |||
4140 | ||||
4141 | if (Error Err = ImportInitializer(D, ToVar)) | |||
4142 | return std::move(Err); | |||
4143 | ||||
4144 | if (D->isConstexpr()) | |||
4145 | ToVar->setConstexpr(true); | |||
4146 | ||||
4147 | addDeclToContexts(D, ToVar); | |||
4148 | ||||
4149 | // Import the rest of the chain. I.e. import all subsequent declarations. | |||
4150 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { | |||
4151 | ExpectedDecl RedeclOrErr = import(*RedeclIt); | |||
4152 | if (!RedeclOrErr) | |||
4153 | return RedeclOrErr.takeError(); | |||
4154 | } | |||
4155 | ||||
4156 | return ToVar; | |||
4157 | } | |||
4158 | ||||
4159 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { | |||
4160 | // Parameters are created in the translation unit's context, then moved | |||
4161 | // into the function declaration's context afterward. | |||
4162 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); | |||
4163 | ||||
4164 | Error Err = Error::success(); | |||
4165 | auto ToDeclName = importChecked(Err, D->getDeclName()); | |||
4166 | auto ToLocation = importChecked(Err, D->getLocation()); | |||
4167 | auto ToType = importChecked(Err, D->getType()); | |||
4168 | if (Err) | |||
4169 | return std::move(Err); | |||
4170 | ||||
4171 | // Create the imported parameter. | |||
4172 | ImplicitParamDecl *ToParm = nullptr; | |||
4173 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, | |||
4174 | ToLocation, ToDeclName.getAsIdentifierInfo(), | |||
4175 | ToType, D->getParameterKind())) | |||
4176 | return ToParm; | |||
4177 | return ToParm; | |||
4178 | } | |||
4179 | ||||
4180 | Error ASTNodeImporter::ImportDefaultArgOfParmVarDecl( | |||
4181 | const ParmVarDecl *FromParam, ParmVarDecl *ToParam) { | |||
4182 | ToParam->setHasInheritedDefaultArg(FromParam->hasInheritedDefaultArg()); | |||
4183 | ToParam->setKNRPromoted(FromParam->isKNRPromoted()); | |||
4184 | ||||
4185 | if (FromParam->hasUninstantiatedDefaultArg()) { | |||
4186 | if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg())) | |||
4187 | ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr); | |||
4188 | else | |||
4189 | return ToDefArgOrErr.takeError(); | |||
4190 | } else if (FromParam->hasUnparsedDefaultArg()) { | |||
4191 | ToParam->setUnparsedDefaultArg(); | |||
4192 | } else if (FromParam->hasDefaultArg()) { | |||
4193 | if (auto ToDefArgOrErr = import(FromParam->getDefaultArg())) | |||
4194 | ToParam->setDefaultArg(*ToDefArgOrErr); | |||
4195 | else | |||
4196 | return ToDefArgOrErr.takeError(); | |||
4197 | } | |||
4198 | ||||
4199 | return Error::success(); | |||
4200 | } | |||
4201 | ||||
4202 | Expected<InheritedConstructor> | |||
4203 | ASTNodeImporter::ImportInheritedConstructor(const InheritedConstructor &From) { | |||
4204 | Error Err = Error::success(); | |||
4205 | CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor()); | |||
4206 | ConstructorUsingShadowDecl *ToShadow = | |||
4207 | importChecked(Err, From.getShadowDecl()); | |||
4208 | if (Err) | |||
4209 | return std::move(Err); | |||
4210 | return InheritedConstructor(ToShadow, ToBaseCtor); | |||
4211 | } | |||
4212 | ||||
4213 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { | |||
4214 | // Parameters are created in the translation unit's context, then moved | |||
4215 | // into the function declaration's context afterward. | |||
4216 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); | |||
4217 | ||||
4218 | Error Err = Error::success(); | |||
4219 | auto ToDeclName = importChecked(Err, D->getDeclName()); | |||
4220 | auto ToLocation = importChecked(Err, D->getLocation()); | |||
4221 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); | |||
4222 | auto ToType = importChecked(Err, D->getType()); | |||
4223 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); | |||
4224 | if (Err) | |||
4225 | return std::move(Err); | |||
4226 | ||||
4227 | ParmVarDecl *ToParm; | |||
4228 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, | |||
4229 | ToInnerLocStart, ToLocation, | |||
4230 | ToDeclName.getAsIdentifierInfo(), ToType, | |||
4231 | ToTypeSourceInfo, D->getStorageClass(), | |||
4232 | /*DefaultArg*/ nullptr)) | |||
4233 | return ToParm; | |||
4234 | ||||
4235 | // Set the default argument. It should be no problem if it was already done. | |||
4236 | // Do not import the default expression before GetImportedOrCreateDecl call | |||
4237 | // to avoid possible infinite import loop because circular dependency. | |||
4238 | if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm)) | |||
4239 | return std::move(Err); | |||
4240 | ||||
4241 | if (D->isObjCMethodParameter()) { | |||
4242 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); | |||
4243 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); | |||
4244 | } else { | |||
4245 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), | |||
4246 | D->getFunctionScopeIndex()); | |||
4247 | } | |||
4248 | ||||
4249 | return ToParm; | |||
4250 | } | |||
4251 | ||||
4252 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { | |||
4253 | // Import the major distinguishing characteristics of a method. | |||
4254 | DeclContext *DC, *LexicalDC; | |||
4255 | DeclarationName Name; | |||
4256 | SourceLocation Loc; | |||
4257 | NamedDecl *ToD; | |||
4258 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4259 | return std::move(Err); | |||
4260 | if (ToD) | |||
4261 | return ToD; | |||
4262 | ||||
4263 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | |||
4264 | for (auto *FoundDecl : FoundDecls) { | |||
4265 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { | |||
4266 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) | |||
4267 | continue; | |||
4268 | ||||
4269 | // Check return types. | |||
4270 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), | |||
4271 | FoundMethod->getReturnType())) { | |||
4272 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent) | |||
4273 | << D->isInstanceMethod() << Name << D->getReturnType() | |||
4274 | << FoundMethod->getReturnType(); | |||
4275 | Importer.ToDiag(FoundMethod->getLocation(), | |||
4276 | diag::note_odr_objc_method_here) | |||
4277 | << D->isInstanceMethod() << Name; | |||
4278 | ||||
4279 | return make_error<ImportError>(ImportError::NameConflict); | |||
4280 | } | |||
4281 | ||||
4282 | // Check the number of parameters. | |||
4283 | if (D->param_size() != FoundMethod->param_size()) { | |||
4284 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent) | |||
4285 | << D->isInstanceMethod() << Name | |||
4286 | << D->param_size() << FoundMethod->param_size(); | |||
4287 | Importer.ToDiag(FoundMethod->getLocation(), | |||
4288 | diag::note_odr_objc_method_here) | |||
4289 | << D->isInstanceMethod() << Name; | |||
4290 | ||||
4291 | return make_error<ImportError>(ImportError::NameConflict); | |||
4292 | } | |||
4293 | ||||
4294 | // Check parameter types. | |||
4295 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), | |||
4296 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); | |||
4297 | P != PEnd; ++P, ++FoundP) { | |||
4298 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), | |||
4299 | (*FoundP)->getType())) { | |||
4300 | Importer.FromDiag((*P)->getLocation(), | |||
4301 | diag::warn_odr_objc_method_param_type_inconsistent) | |||
4302 | << D->isInstanceMethod() << Name | |||
4303 | << (*P)->getType() << (*FoundP)->getType(); | |||
4304 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) | |||
4305 | << (*FoundP)->getType(); | |||
4306 | ||||
4307 | return make_error<ImportError>(ImportError::NameConflict); | |||
4308 | } | |||
4309 | } | |||
4310 | ||||
4311 | // Check variadic/non-variadic. | |||
4312 | // Check the number of parameters. | |||
4313 | if (D->isVariadic() != FoundMethod->isVariadic()) { | |||
4314 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent) | |||
4315 | << D->isInstanceMethod() << Name; | |||
4316 | Importer.ToDiag(FoundMethod->getLocation(), | |||
4317 | diag::note_odr_objc_method_here) | |||
4318 | << D->isInstanceMethod() << Name; | |||
4319 | ||||
4320 | return make_error<ImportError>(ImportError::NameConflict); | |||
4321 | } | |||
4322 | ||||
4323 | // FIXME: Any other bits we need to merge? | |||
4324 | return Importer.MapImported(D, FoundMethod); | |||
4325 | } | |||
4326 | } | |||
4327 | ||||
4328 | Error Err = Error::success(); | |||
4329 | auto ToEndLoc = importChecked(Err, D->getEndLoc()); | |||
4330 | auto ToReturnType = importChecked(Err, D->getReturnType()); | |||
4331 | auto ToReturnTypeSourceInfo = | |||
4332 | importChecked(Err, D->getReturnTypeSourceInfo()); | |||
4333 | if (Err) | |||
4334 | return std::move(Err); | |||
4335 | ||||
4336 | ObjCMethodDecl *ToMethod; | |||
4337 | if (GetImportedOrCreateDecl( | |||
4338 | ToMethod, D, Importer.getToContext(), Loc, ToEndLoc, | |||
4339 | Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC, | |||
4340 | D->isInstanceMethod(), D->isVariadic(), D->isPropertyAccessor(), | |||
4341 | D->isSynthesizedAccessorStub(), D->isImplicit(), D->isDefined(), | |||
4342 | D->getImplementationControl(), D->hasRelatedResultType())) | |||
4343 | return ToMethod; | |||
4344 | ||||
4345 | // FIXME: When we decide to merge method definitions, we'll need to | |||
4346 | // deal with implicit parameters. | |||
4347 | ||||
4348 | // Import the parameters | |||
4349 | SmallVector<ParmVarDecl *, 5> ToParams; | |||
4350 | for (auto *FromP : D->parameters()) { | |||
4351 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) | |||
4352 | ToParams.push_back(*ToPOrErr); | |||
4353 | else | |||
4354 | return ToPOrErr.takeError(); | |||
4355 | } | |||
4356 | ||||
4357 | // Set the parameters. | |||
4358 | for (auto *ToParam : ToParams) { | |||
4359 | ToParam->setOwningFunction(ToMethod); | |||
4360 | ToMethod->addDeclInternal(ToParam); | |||
4361 | } | |||
4362 | ||||
4363 | SmallVector<SourceLocation, 12> FromSelLocs; | |||
4364 | D->getSelectorLocs(FromSelLocs); | |||
4365 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); | |||
4366 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) | |||
4367 | return std::move(Err); | |||
4368 | ||||
4369 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); | |||
4370 | ||||
4371 | ToMethod->setLexicalDeclContext(LexicalDC); | |||
4372 | LexicalDC->addDeclInternal(ToMethod); | |||
4373 | ||||
4374 | // Implicit params are declared when Sema encounters the definition but this | |||
4375 | // never happens when the method is imported. Manually declare the implicit | |||
4376 | // params now that the MethodDecl knows its class interface. | |||
4377 | if (D->getSelfDecl()) | |||
4378 | ToMethod->createImplicitParams(Importer.getToContext(), | |||
4379 | ToMethod->getClassInterface()); | |||
4380 | ||||
4381 | return ToMethod; | |||
4382 | } | |||
4383 | ||||
4384 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { | |||
4385 | // Import the major distinguishing characteristics of a category. | |||
4386 | DeclContext *DC, *LexicalDC; | |||
4387 | DeclarationName Name; | |||
4388 | SourceLocation Loc; | |||
4389 | NamedDecl *ToD; | |||
4390 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4391 | return std::move(Err); | |||
4392 | if (ToD) | |||
4393 | return ToD; | |||
4394 | ||||
4395 | Error Err = Error::success(); | |||
4396 | auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc()); | |||
4397 | auto ToLocation = importChecked(Err, D->getLocation()); | |||
4398 | auto ToColonLoc = importChecked(Err, D->getColonLoc()); | |||
4399 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); | |||
4400 | if (Err) | |||
4401 | return std::move(Err); | |||
4402 | ||||
4403 | ObjCTypeParamDecl *Result; | |||
4404 | if (GetImportedOrCreateDecl( | |||
4405 | Result, D, Importer.getToContext(), DC, D->getVariance(), | |||
4406 | ToVarianceLoc, D->getIndex(), | |||
4407 | ToLocation, Name.getAsIdentifierInfo(), | |||
4408 | ToColonLoc, ToTypeSourceInfo)) | |||
4409 | return Result; | |||
4410 | ||||
4411 | Result->setLexicalDeclContext(LexicalDC); | |||
4412 | return Result; | |||
4413 | } | |||
4414 | ||||
4415 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { | |||
4416 | // Import the major distinguishing characteristics of a category. | |||
4417 | DeclContext *DC, *LexicalDC; | |||
4418 | DeclarationName Name; | |||
4419 | SourceLocation Loc; | |||
4420 | NamedDecl *ToD; | |||
4421 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4422 | return std::move(Err); | |||
4423 | if (ToD) | |||
4424 | return ToD; | |||
4425 | ||||
4426 | ObjCInterfaceDecl *ToInterface; | |||
4427 | if (Error Err = importInto(ToInterface, D->getClassInterface())) | |||
4428 | return std::move(Err); | |||
4429 | ||||
4430 | // Determine if we've already encountered this category. | |||
4431 | ObjCCategoryDecl *MergeWithCategory | |||
4432 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); | |||
4433 | ObjCCategoryDecl *ToCategory = MergeWithCategory; | |||
4434 | if (!ToCategory) { | |||
4435 | ||||
4436 | Error Err = Error::success(); | |||
4437 | auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); | |||
4438 | auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc()); | |||
4439 | auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc()); | |||
4440 | auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc()); | |||
4441 | if (Err) | |||
4442 | return std::move(Err); | |||
4443 | ||||
4444 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, | |||
4445 | ToAtStartLoc, Loc, | |||
4446 | ToCategoryNameLoc, | |||
4447 | Name.getAsIdentifierInfo(), ToInterface, | |||
4448 | /*TypeParamList=*/nullptr, | |||
4449 | ToIvarLBraceLoc, | |||
4450 | ToIvarRBraceLoc)) | |||
4451 | return ToCategory; | |||
4452 | ||||
4453 | ToCategory->setLexicalDeclContext(LexicalDC); | |||
4454 | LexicalDC->addDeclInternal(ToCategory); | |||
4455 | // Import the type parameter list after MapImported, to avoid | |||
4456 | // loops when bringing in their DeclContext. | |||
4457 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) | |||
4458 | ToCategory->setTypeParamList(*PListOrErr); | |||
4459 | else | |||
4460 | return PListOrErr.takeError(); | |||
4461 | ||||
4462 | // Import protocols | |||
4463 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | |||
4464 | SmallVector<SourceLocation, 4> ProtocolLocs; | |||
4465 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc | |||
4466 | = D->protocol_loc_begin(); | |||
4467 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), | |||
4468 | FromProtoEnd = D->protocol_end(); | |||
4469 | FromProto != FromProtoEnd; | |||
4470 | ++FromProto, ++FromProtoLoc) { | |||
4471 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | |||
4472 | Protocols.push_back(*ToProtoOrErr); | |||
4473 | else | |||
4474 | return ToProtoOrErr.takeError(); | |||
4475 | ||||
4476 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | |||
4477 | ProtocolLocs.push_back(*ToProtoLocOrErr); | |||
4478 | else | |||
4479 | return ToProtoLocOrErr.takeError(); | |||
4480 | } | |||
4481 | ||||
4482 | // FIXME: If we're merging, make sure that the protocol list is the same. | |||
4483 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), | |||
4484 | ProtocolLocs.data(), Importer.getToContext()); | |||
4485 | ||||
4486 | } else { | |||
4487 | Importer.MapImported(D, ToCategory); | |||
4488 | } | |||
4489 | ||||
4490 | // Import all of the members of this category. | |||
4491 | if (Error Err = ImportDeclContext(D)) | |||
4492 | return std::move(Err); | |||
4493 | ||||
4494 | // If we have an implementation, import it as well. | |||
4495 | if (D->getImplementation()) { | |||
4496 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = | |||
4497 | import(D->getImplementation())) | |||
4498 | ToCategory->setImplementation(*ToImplOrErr); | |||
4499 | else | |||
4500 | return ToImplOrErr.takeError(); | |||
4501 | } | |||
4502 | ||||
4503 | return ToCategory; | |||
4504 | } | |||
4505 | ||||
4506 | Error ASTNodeImporter::ImportDefinition( | |||
4507 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { | |||
4508 | if (To->getDefinition()) { | |||
4509 | if (shouldForceImportDeclContext(Kind)) | |||
4510 | if (Error Err = ImportDeclContext(From)) | |||
4511 | return Err; | |||
4512 | return Error::success(); | |||
4513 | } | |||
4514 | ||||
4515 | // Start the protocol definition | |||
4516 | To->startDefinition(); | |||
4517 | ||||
4518 | // Import protocols | |||
4519 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | |||
4520 | SmallVector<SourceLocation, 4> ProtocolLocs; | |||
4521 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = | |||
4522 | From->protocol_loc_begin(); | |||
4523 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), | |||
4524 | FromProtoEnd = From->protocol_end(); | |||
4525 | FromProto != FromProtoEnd; | |||
4526 | ++FromProto, ++FromProtoLoc) { | |||
4527 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | |||
4528 | Protocols.push_back(*ToProtoOrErr); | |||
4529 | else | |||
4530 | return ToProtoOrErr.takeError(); | |||
4531 | ||||
4532 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | |||
4533 | ProtocolLocs.push_back(*ToProtoLocOrErr); | |||
4534 | else | |||
4535 | return ToProtoLocOrErr.takeError(); | |||
4536 | ||||
4537 | } | |||
4538 | ||||
4539 | // FIXME: If we're merging, make sure that the protocol list is the same. | |||
4540 | To->setProtocolList(Protocols.data(), Protocols.size(), | |||
4541 | ProtocolLocs.data(), Importer.getToContext()); | |||
4542 | ||||
4543 | if (shouldForceImportDeclContext(Kind)) { | |||
4544 | // Import all of the members of this protocol. | |||
4545 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | |||
4546 | return Err; | |||
4547 | } | |||
4548 | return Error::success(); | |||
4549 | } | |||
4550 | ||||
4551 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { | |||
4552 | // If this protocol has a definition in the translation unit we're coming | |||
4553 | // from, but this particular declaration is not that definition, import the | |||
4554 | // definition and map to that. | |||
4555 | ObjCProtocolDecl *Definition = D->getDefinition(); | |||
4556 | if (Definition && Definition != D) { | |||
4557 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | |||
4558 | return Importer.MapImported(D, *ImportedDefOrErr); | |||
4559 | else | |||
4560 | return ImportedDefOrErr.takeError(); | |||
4561 | } | |||
4562 | ||||
4563 | // Import the major distinguishing characteristics of a protocol. | |||
4564 | DeclContext *DC, *LexicalDC; | |||
4565 | DeclarationName Name; | |||
4566 | SourceLocation Loc; | |||
4567 | NamedDecl *ToD; | |||
4568 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4569 | return std::move(Err); | |||
4570 | if (ToD) | |||
4571 | return ToD; | |||
4572 | ||||
4573 | ObjCProtocolDecl *MergeWithProtocol = nullptr; | |||
4574 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | |||
4575 | for (auto *FoundDecl : FoundDecls) { | |||
4576 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) | |||
4577 | continue; | |||
4578 | ||||
4579 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) | |||
4580 | break; | |||
4581 | } | |||
4582 | ||||
4583 | ObjCProtocolDecl *ToProto = MergeWithProtocol; | |||
4584 | if (!ToProto) { | |||
4585 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); | |||
4586 | if (!ToAtBeginLocOrErr) | |||
4587 | return ToAtBeginLocOrErr.takeError(); | |||
4588 | ||||
4589 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, | |||
4590 | Name.getAsIdentifierInfo(), Loc, | |||
4591 | *ToAtBeginLocOrErr, | |||
4592 | /*PrevDecl=*/nullptr)) | |||
4593 | return ToProto; | |||
4594 | ToProto->setLexicalDeclContext(LexicalDC); | |||
4595 | LexicalDC->addDeclInternal(ToProto); | |||
4596 | } | |||
4597 | ||||
4598 | Importer.MapImported(D, ToProto); | |||
4599 | ||||
4600 | if (D->isThisDeclarationADefinition()) | |||
4601 | if (Error Err = ImportDefinition(D, ToProto)) | |||
4602 | return std::move(Err); | |||
4603 | ||||
4604 | return ToProto; | |||
4605 | } | |||
4606 | ||||
4607 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { | |||
4608 | DeclContext *DC, *LexicalDC; | |||
4609 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
4610 | return std::move(Err); | |||
4611 | ||||
4612 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); | |||
4613 | if (!ExternLocOrErr) | |||
4614 | return ExternLocOrErr.takeError(); | |||
4615 | ||||
4616 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); | |||
4617 | if (!LangLocOrErr) | |||
4618 | return LangLocOrErr.takeError(); | |||
4619 | ||||
4620 | bool HasBraces = D->hasBraces(); | |||
4621 | ||||
4622 | LinkageSpecDecl *ToLinkageSpec; | |||
4623 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, | |||
4624 | *ExternLocOrErr, *LangLocOrErr, | |||
4625 | D->getLanguage(), HasBraces)) | |||
4626 | return ToLinkageSpec; | |||
4627 | ||||
4628 | if (HasBraces) { | |||
4629 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); | |||
4630 | if (!RBraceLocOrErr) | |||
4631 | return RBraceLocOrErr.takeError(); | |||
4632 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); | |||
4633 | } | |||
4634 | ||||
4635 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); | |||
4636 | LexicalDC->addDeclInternal(ToLinkageSpec); | |||
4637 | ||||
4638 | return ToLinkageSpec; | |||
4639 | } | |||
4640 | ||||
4641 | ExpectedDecl ASTNodeImporter::ImportUsingShadowDecls(BaseUsingDecl *D, | |||
4642 | BaseUsingDecl *ToSI) { | |||
4643 | for (UsingShadowDecl *FromShadow : D->shadows()) { | |||
4644 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) | |||
4645 | ToSI->addShadowDecl(*ToShadowOrErr); | |||
4646 | else | |||
4647 | // FIXME: We return error here but the definition is already created | |||
4648 | // and available with lookups. How to fix this?.. | |||
4649 | return ToShadowOrErr.takeError(); | |||
4650 | } | |||
4651 | return ToSI; | |||
4652 | } | |||
4653 | ||||
4654 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { | |||
4655 | DeclContext *DC, *LexicalDC; | |||
4656 | DeclarationName Name; | |||
4657 | SourceLocation Loc; | |||
4658 | NamedDecl *ToD = nullptr; | |||
4659 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4660 | return std::move(Err); | |||
4661 | if (ToD) | |||
4662 | return ToD; | |||
4663 | ||||
4664 | Error Err = Error::success(); | |||
4665 | auto ToLoc = importChecked(Err, D->getNameInfo().getLoc()); | |||
4666 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); | |||
4667 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | |||
4668 | if (Err) | |||
4669 | return std::move(Err); | |||
4670 | ||||
4671 | DeclarationNameInfo NameInfo(Name, ToLoc); | |||
4672 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | |||
4673 | return std::move(Err); | |||
4674 | ||||
4675 | UsingDecl *ToUsing; | |||
4676 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, | |||
4677 | ToUsingLoc, ToQualifierLoc, NameInfo, | |||
4678 | D->hasTypename())) | |||
4679 | return ToUsing; | |||
4680 | ||||
4681 | ToUsing->setLexicalDeclContext(LexicalDC); | |||
4682 | LexicalDC->addDeclInternal(ToUsing); | |||
4683 | ||||
4684 | if (NamedDecl *FromPattern = | |||
4685 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { | |||
4686 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) | |||
4687 | Importer.getToContext().setInstantiatedFromUsingDecl( | |||
4688 | ToUsing, *ToPatternOrErr); | |||
4689 | else | |||
4690 | return ToPatternOrErr.takeError(); | |||
4691 | } | |||
4692 | ||||
4693 | return ImportUsingShadowDecls(D, ToUsing); | |||
4694 | } | |||
4695 | ||||
4696 | ExpectedDecl ASTNodeImporter::VisitUsingEnumDecl(UsingEnumDecl *D) { | |||
4697 | DeclContext *DC, *LexicalDC; | |||
4698 | DeclarationName Name; | |||
4699 | SourceLocation Loc; | |||
4700 | NamedDecl *ToD = nullptr; | |||
4701 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4702 | return std::move(Err); | |||
4703 | if (ToD) | |||
4704 | return ToD; | |||
4705 | ||||
4706 | Error Err = Error::success(); | |||
4707 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); | |||
4708 | auto ToEnumLoc = importChecked(Err, D->getEnumLoc()); | |||
4709 | auto ToEnumDecl = importChecked(Err, D->getEnumDecl()); | |||
4710 | if (Err) | |||
4711 | return std::move(Err); | |||
4712 | ||||
4713 | UsingEnumDecl *ToUsingEnum; | |||
4714 | if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC, | |||
4715 | ToUsingLoc, ToEnumLoc, Loc, ToEnumDecl)) | |||
4716 | return ToUsingEnum; | |||
4717 | ||||
4718 | ToUsingEnum->setLexicalDeclContext(LexicalDC); | |||
4719 | LexicalDC->addDeclInternal(ToUsingEnum); | |||
4720 | ||||
4721 | if (UsingEnumDecl *FromPattern = | |||
4722 | Importer.getFromContext().getInstantiatedFromUsingEnumDecl(D)) { | |||
4723 | if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern)) | |||
4724 | Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum, | |||
4725 | *ToPatternOrErr); | |||
4726 | else | |||
4727 | return ToPatternOrErr.takeError(); | |||
4728 | } | |||
4729 | ||||
4730 | return ImportUsingShadowDecls(D, ToUsingEnum); | |||
4731 | } | |||
4732 | ||||
4733 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { | |||
4734 | DeclContext *DC, *LexicalDC; | |||
4735 | DeclarationName Name; | |||
4736 | SourceLocation Loc; | |||
4737 | NamedDecl *ToD = nullptr; | |||
4738 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4739 | return std::move(Err); | |||
4740 | if (ToD) | |||
4741 | return ToD; | |||
4742 | ||||
4743 | Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer()); | |||
4744 | if (!ToIntroducerOrErr) | |||
4745 | return ToIntroducerOrErr.takeError(); | |||
4746 | ||||
4747 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); | |||
4748 | if (!ToTargetOrErr) | |||
4749 | return ToTargetOrErr.takeError(); | |||
4750 | ||||
4751 | UsingShadowDecl *ToShadow; | |||
4752 | if (auto *FromConstructorUsingShadow = | |||
4753 | dyn_cast<ConstructorUsingShadowDecl>(D)) { | |||
4754 | Error Err = Error::success(); | |||
4755 | ConstructorUsingShadowDecl *Nominated = importChecked( | |||
4756 | Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl()); | |||
4757 | if (Err) | |||
4758 | return std::move(Err); | |||
4759 | // The 'Target' parameter of ConstructorUsingShadowDecl constructor | |||
4760 | // is really the "NominatedBaseClassShadowDecl" value if it exists | |||
4761 | // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl). | |||
4762 | // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to | |||
4763 | // get the correct values. | |||
4764 | if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>( | |||
4765 | ToShadow, D, Importer.getToContext(), DC, Loc, | |||
4766 | cast<UsingDecl>(*ToIntroducerOrErr), | |||
4767 | Nominated ? Nominated : *ToTargetOrErr, | |||
4768 | FromConstructorUsingShadow->constructsVirtualBase())) | |||
4769 | return ToShadow; | |||
4770 | } else { | |||
4771 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, | |||
4772 | Name, *ToIntroducerOrErr, *ToTargetOrErr)) | |||
4773 | return ToShadow; | |||
4774 | } | |||
4775 | ||||
4776 | ToShadow->setLexicalDeclContext(LexicalDC); | |||
4777 | ToShadow->setAccess(D->getAccess()); | |||
4778 | ||||
4779 | if (UsingShadowDecl *FromPattern = | |||
4780 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { | |||
4781 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) | |||
4782 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( | |||
4783 | ToShadow, *ToPatternOrErr); | |||
4784 | else | |||
4785 | // FIXME: We return error here but the definition is already created | |||
4786 | // and available with lookups. How to fix this?.. | |||
4787 | return ToPatternOrErr.takeError(); | |||
4788 | } | |||
4789 | ||||
4790 | LexicalDC->addDeclInternal(ToShadow); | |||
4791 | ||||
4792 | return ToShadow; | |||
4793 | } | |||
4794 | ||||
4795 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { | |||
4796 | DeclContext *DC, *LexicalDC; | |||
4797 | DeclarationName Name; | |||
4798 | SourceLocation Loc; | |||
4799 | NamedDecl *ToD = nullptr; | |||
4800 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4801 | return std::move(Err); | |||
4802 | if (ToD) | |||
4803 | return ToD; | |||
4804 | ||||
4805 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); | |||
4806 | if (!ToComAncestorOrErr) | |||
4807 | return ToComAncestorOrErr.takeError(); | |||
4808 | ||||
4809 | Error Err = Error::success(); | |||
4810 | auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace()); | |||
4811 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); | |||
4812 | auto ToNamespaceKeyLocation = | |||
4813 | importChecked(Err, D->getNamespaceKeyLocation()); | |||
4814 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | |||
4815 | auto ToIdentLocation = importChecked(Err, D->getIdentLocation()); | |||
4816 | if (Err) | |||
4817 | return std::move(Err); | |||
4818 | ||||
4819 | UsingDirectiveDecl *ToUsingDir; | |||
4820 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, | |||
4821 | ToUsingLoc, | |||
4822 | ToNamespaceKeyLocation, | |||
4823 | ToQualifierLoc, | |||
4824 | ToIdentLocation, | |||
4825 | ToNominatedNamespace, *ToComAncestorOrErr)) | |||
4826 | return ToUsingDir; | |||
4827 | ||||
4828 | ToUsingDir->setLexicalDeclContext(LexicalDC); | |||
4829 | LexicalDC->addDeclInternal(ToUsingDir); | |||
4830 | ||||
4831 | return ToUsingDir; | |||
4832 | } | |||
4833 | ||||
4834 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( | |||
4835 | UnresolvedUsingValueDecl *D) { | |||
4836 | DeclContext *DC, *LexicalDC; | |||
4837 | DeclarationName Name; | |||
4838 | SourceLocation Loc; | |||
4839 | NamedDecl *ToD = nullptr; | |||
4840 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4841 | return std::move(Err); | |||
4842 | if (ToD) | |||
4843 | return ToD; | |||
4844 | ||||
4845 | Error Err = Error::success(); | |||
4846 | auto ToLoc = importChecked(Err, D->getNameInfo().getLoc()); | |||
4847 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); | |||
4848 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | |||
4849 | auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc()); | |||
4850 | if (Err) | |||
4851 | return std::move(Err); | |||
4852 | ||||
4853 | DeclarationNameInfo NameInfo(Name, ToLoc); | |||
4854 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | |||
4855 | return std::move(Err); | |||
4856 | ||||
4857 | UnresolvedUsingValueDecl *ToUsingValue; | |||
4858 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, | |||
4859 | ToUsingLoc, ToQualifierLoc, NameInfo, | |||
4860 | ToEllipsisLoc)) | |||
4861 | return ToUsingValue; | |||
4862 | ||||
4863 | ToUsingValue->setAccess(D->getAccess()); | |||
4864 | ToUsingValue->setLexicalDeclContext(LexicalDC); | |||
4865 | LexicalDC->addDeclInternal(ToUsingValue); | |||
4866 | ||||
4867 | return ToUsingValue; | |||
4868 | } | |||
4869 | ||||
4870 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( | |||
4871 | UnresolvedUsingTypenameDecl *D) { | |||
4872 | DeclContext *DC, *LexicalDC; | |||
4873 | DeclarationName Name; | |||
4874 | SourceLocation Loc; | |||
4875 | NamedDecl *ToD = nullptr; | |||
4876 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4877 | return std::move(Err); | |||
4878 | if (ToD) | |||
4879 | return ToD; | |||
4880 | ||||
4881 | Error Err = Error::success(); | |||
4882 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); | |||
4883 | auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc()); | |||
4884 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | |||
4885 | auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc()); | |||
4886 | if (Err) | |||
4887 | return std::move(Err); | |||
4888 | ||||
4889 | UnresolvedUsingTypenameDecl *ToUsing; | |||
4890 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, | |||
4891 | ToUsingLoc, ToTypenameLoc, | |||
4892 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) | |||
4893 | return ToUsing; | |||
4894 | ||||
4895 | ToUsing->setAccess(D->getAccess()); | |||
4896 | ToUsing->setLexicalDeclContext(LexicalDC); | |||
4897 | LexicalDC->addDeclInternal(ToUsing); | |||
4898 | ||||
4899 | return ToUsing; | |||
4900 | } | |||
4901 | ||||
4902 | ExpectedDecl ASTNodeImporter::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) { | |||
4903 | Decl* ToD = nullptr; | |||
4904 | switch (D->getBuiltinTemplateKind()) { | |||
4905 | case BuiltinTemplateKind::BTK__make_integer_seq: | |||
4906 | ToD = Importer.getToContext().getMakeIntegerSeqDecl(); | |||
4907 | break; | |||
4908 | case BuiltinTemplateKind::BTK__type_pack_element: | |||
4909 | ToD = Importer.getToContext().getTypePackElementDecl(); | |||
4910 | break; | |||
4911 | } | |||
4912 | assert(ToD && "BuiltinTemplateDecl of unsupported kind!")(static_cast <bool> (ToD && "BuiltinTemplateDecl of unsupported kind!" ) ? void (0) : __assert_fail ("ToD && \"BuiltinTemplateDecl of unsupported kind!\"" , "clang/lib/AST/ASTImporter.cpp", 4912, __extension__ __PRETTY_FUNCTION__ )); | |||
4913 | Importer.MapImported(D, ToD); | |||
4914 | return ToD; | |||
4915 | } | |||
4916 | ||||
4917 | Error ASTNodeImporter::ImportDefinition( | |||
4918 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { | |||
4919 | if (To->getDefinition()) { | |||
4920 | // Check consistency of superclass. | |||
4921 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); | |||
4922 | if (FromSuper) { | |||
4923 | if (auto FromSuperOrErr = import(FromSuper)) | |||
4924 | FromSuper = *FromSuperOrErr; | |||
4925 | else | |||
4926 | return FromSuperOrErr.takeError(); | |||
4927 | } | |||
4928 | ||||
4929 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); | |||
4930 | if ((bool)FromSuper != (bool)ToSuper || | |||
4931 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { | |||
4932 | Importer.ToDiag(To->getLocation(), | |||
4933 | diag::warn_odr_objc_superclass_inconsistent) | |||
4934 | << To->getDeclName(); | |||
4935 | if (ToSuper) | |||
4936 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) | |||
4937 | << To->getSuperClass()->getDeclName(); | |||
4938 | else | |||
4939 | Importer.ToDiag(To->getLocation(), | |||
4940 | diag::note_odr_objc_missing_superclass); | |||
4941 | if (From->getSuperClass()) | |||
4942 | Importer.FromDiag(From->getSuperClassLoc(), | |||
4943 | diag::note_odr_objc_superclass) | |||
4944 | << From->getSuperClass()->getDeclName(); | |||
4945 | else | |||
4946 | Importer.FromDiag(From->getLocation(), | |||
4947 | diag::note_odr_objc_missing_superclass); | |||
4948 | } | |||
4949 | ||||
4950 | if (shouldForceImportDeclContext(Kind)) | |||
4951 | if (Error Err = ImportDeclContext(From)) | |||
4952 | return Err; | |||
4953 | return Error::success(); | |||
4954 | } | |||
4955 | ||||
4956 | // Start the definition. | |||
4957 | To->startDefinition(); | |||
4958 | ||||
4959 | // If this class has a superclass, import it. | |||
4960 | if (From->getSuperClass()) { | |||
4961 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) | |||
4962 | To->setSuperClass(*SuperTInfoOrErr); | |||
4963 | else | |||
4964 | return SuperTInfoOrErr.takeError(); | |||
4965 | } | |||
4966 | ||||
4967 | // Import protocols | |||
4968 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | |||
4969 | SmallVector<SourceLocation, 4> ProtocolLocs; | |||
4970 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = | |||
4971 | From->protocol_loc_begin(); | |||
4972 | ||||
4973 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), | |||
4974 | FromProtoEnd = From->protocol_end(); | |||
4975 | FromProto != FromProtoEnd; | |||
4976 | ++FromProto, ++FromProtoLoc) { | |||
4977 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | |||
4978 | Protocols.push_back(*ToProtoOrErr); | |||
4979 | else | |||
4980 | return ToProtoOrErr.takeError(); | |||
4981 | ||||
4982 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | |||
4983 | ProtocolLocs.push_back(*ToProtoLocOrErr); | |||
4984 | else | |||
4985 | return ToProtoLocOrErr.takeError(); | |||
4986 | ||||
4987 | } | |||
4988 | ||||
4989 | // FIXME: If we're merging, make sure that the protocol list is the same. | |||
4990 | To->setProtocolList(Protocols.data(), Protocols.size(), | |||
4991 | ProtocolLocs.data(), Importer.getToContext()); | |||
4992 | ||||
4993 | // Import categories. When the categories themselves are imported, they'll | |||
4994 | // hook themselves into this interface. | |||
4995 | for (auto *Cat : From->known_categories()) { | |||
4996 | auto ToCatOrErr = import(Cat); | |||
4997 | if (!ToCatOrErr) | |||
4998 | return ToCatOrErr.takeError(); | |||
4999 | } | |||
5000 | ||||
5001 | // If we have an @implementation, import it as well. | |||
5002 | if (From->getImplementation()) { | |||
5003 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = | |||
5004 | import(From->getImplementation())) | |||
5005 | To->setImplementation(*ToImplOrErr); | |||
5006 | else | |||
5007 | return ToImplOrErr.takeError(); | |||
5008 | } | |||
5009 | ||||
5010 | // Import all of the members of this class. | |||
5011 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | |||
5012 | return Err; | |||
5013 | ||||
5014 | return Error::success(); | |||
5015 | } | |||
5016 | ||||
5017 | Expected<ObjCTypeParamList *> | |||
5018 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { | |||
5019 | if (!list) | |||
5020 | return nullptr; | |||
5021 | ||||
5022 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; | |||
5023 | for (auto *fromTypeParam : *list) { | |||
5024 | if (auto toTypeParamOrErr = import(fromTypeParam)) | |||
5025 | toTypeParams.push_back(*toTypeParamOrErr); | |||
5026 | else | |||
5027 | return toTypeParamOrErr.takeError(); | |||
5028 | } | |||
5029 | ||||
5030 | auto LAngleLocOrErr = import(list->getLAngleLoc()); | |||
5031 | if (!LAngleLocOrErr) | |||
5032 | return LAngleLocOrErr.takeError(); | |||
5033 | ||||
5034 | auto RAngleLocOrErr = import(list->getRAngleLoc()); | |||
5035 | if (!RAngleLocOrErr) | |||
5036 | return RAngleLocOrErr.takeError(); | |||
5037 | ||||
5038 | return ObjCTypeParamList::create(Importer.getToContext(), | |||
5039 | *LAngleLocOrErr, | |||
5040 | toTypeParams, | |||
5041 | *RAngleLocOrErr); | |||
5042 | } | |||
5043 | ||||
5044 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { | |||
5045 | // If this class has a definition in the translation unit we're coming from, | |||
5046 | // but this particular declaration is not that definition, import the | |||
5047 | // definition and map to that. | |||
5048 | ObjCInterfaceDecl *Definition = D->getDefinition(); | |||
5049 | if (Definition && Definition != D) { | |||
5050 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | |||
5051 | return Importer.MapImported(D, *ImportedDefOrErr); | |||
5052 | else | |||
5053 | return ImportedDefOrErr.takeError(); | |||
5054 | } | |||
5055 | ||||
5056 | // Import the major distinguishing characteristics of an @interface. | |||
5057 | DeclContext *DC, *LexicalDC; | |||
5058 | DeclarationName Name; | |||
5059 | SourceLocation Loc; | |||
5060 | NamedDecl *ToD; | |||
5061 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
5062 | return std::move(Err); | |||
5063 | if (ToD) | |||
5064 | return ToD; | |||
5065 | ||||
5066 | // Look for an existing interface with the same name. | |||
5067 | ObjCInterfaceDecl *MergeWithIface = nullptr; | |||
5068 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | |||
5069 | for (auto *FoundDecl : FoundDecls) { | |||
5070 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) | |||
5071 | continue; | |||
5072 | ||||
5073 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) | |||
5074 | break; | |||
5075 | } | |||
5076 | ||||
5077 | // Create an interface declaration, if one does not already exist. | |||
5078 | ObjCInterfaceDecl *ToIface = MergeWithIface; | |||
5079 | if (!ToIface) { | |||
5080 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); | |||
5081 | if (!AtBeginLocOrErr) | |||
5082 | return AtBeginLocOrErr.takeError(); | |||
5083 | ||||
5084 | if (GetImportedOrCreateDecl( | |||
5085 | ToIface, D, Importer.getToContext(), DC, | |||
5086 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), | |||
5087 | /*TypeParamList=*/nullptr, | |||
5088 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) | |||
5089 | return ToIface; | |||
5090 | ToIface->setLexicalDeclContext(LexicalDC); | |||
5091 | LexicalDC->addDeclInternal(ToIface); | |||
5092 | } | |||
5093 | Importer.MapImported(D, ToIface); | |||
5094 | // Import the type parameter list after MapImported, to avoid | |||
5095 | // loops when bringing in their DeclContext. | |||
5096 | if (auto ToPListOrErr = | |||
5097 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) | |||
5098 | ToIface->setTypeParamList(*ToPListOrErr); | |||
5099 | else | |||
5100 | return ToPListOrErr.takeError(); | |||
5101 | ||||
5102 | if (D->isThisDeclarationADefinition()) | |||
5103 | if (Error Err = ImportDefinition(D, ToIface)) | |||
5104 | return std::move(Err); | |||
5105 | ||||
5106 | return ToIface; | |||
5107 | } | |||
5108 | ||||
5109 | ExpectedDecl | |||
5110 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { | |||
5111 | ObjCCategoryDecl *Category; | |||
5112 | if (Error Err = importInto(Category, D->getCategoryDecl())) | |||
5113 | return std::move(Err); | |||
5114 | ||||
5115 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); | |||
5116 | if (!ToImpl) { | |||
5117 | DeclContext *DC, *LexicalDC; | |||
5118 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
5119 | return std::move(Err); | |||
5120 | ||||
5121 | Error Err = Error::success(); | |||
5122 | auto ToLocation = importChecked(Err, D->getLocation()); | |||
5123 | auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); | |||
5124 | auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc()); | |||
5125 | if (Err) | |||
5126 | return std::move(Err); | |||
5127 | ||||
5128 | if (GetImportedOrCreateDecl( | |||
5129 | ToImpl, D, Importer.getToContext(), DC, | |||
5130 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), | |||
5131 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) | |||
5132 | return ToImpl; | |||
5133 | ||||
5134 | ToImpl->setLexicalDeclContext(LexicalDC); | |||
5135 | LexicalDC->addDeclInternal(ToImpl); | |||
5136 | Category->setImplementation(ToImpl); | |||
5137 | } | |||
5138 | ||||
5139 | Importer.MapImported(D, ToImpl); | |||
5140 | if (Error Err = ImportDeclContext(D)) | |||
5141 | return std::move(Err); | |||
5142 | ||||
5143 | return ToImpl; | |||
5144 | } | |||
5145 | ||||
5146 | ExpectedDecl | |||
5147 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { | |||
5148 | // Find the corresponding interface. | |||
5149 | ObjCInterfaceDecl *Iface; | |||
5150 | if (Error Err = importInto(Iface, D->getClassInterface())) | |||
5151 | return std::move(Err); | |||
5152 | ||||
5153 | // Import the superclass, if any. | |||
5154 | ObjCInterfaceDecl *Super; | |||
5155 | if (Error Err = importInto(Super, D->getSuperClass())) | |||
5156 | return std::move(Err); | |||
5157 | ||||
5158 | ObjCImplementationDecl *Impl = Iface->getImplementation(); | |||
5159 | if (!Impl) { | |||
5160 | // We haven't imported an implementation yet. Create a new @implementation | |||
5161 | // now. | |||
5162 | DeclContext *DC, *LexicalDC; | |||
5163 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
5164 | return std::move(Err); | |||
5165 | ||||
5166 | Error Err = Error::success(); | |||
5167 | auto ToLocation = importChecked(Err, D->getLocation()); | |||
5168 | auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); | |||
5169 | auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc()); | |||
5170 | auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc()); | |||
5171 | auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc()); | |||
5172 | if (Err) | |||
5173 | return std::move(Err); | |||
5174 | ||||
5175 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), | |||
5176 | DC, Iface, Super, | |||
5177 | ToLocation, | |||
5178 | ToAtStartLoc, | |||
5179 | ToSuperClassLoc, | |||
5180 | ToIvarLBraceLoc, | |||
5181 | ToIvarRBraceLoc)) | |||
5182 | return Impl; | |||
5183 | ||||
5184 | Impl->setLexicalDeclContext(LexicalDC); | |||
5185 | ||||
5186 | // Associate the implementation with the class it implements. | |||
5187 | Iface->setImplementation(Impl); | |||
5188 | Importer.MapImported(D, Iface->getImplementation()); | |||
5189 | } else { | |||
5190 | Importer.MapImported(D, Iface->getImplementation()); | |||
5191 | ||||
5192 | // Verify that the existing @implementation has the same superclass. | |||
5193 | if ((Super && !Impl->getSuperClass()) || | |||
5194 | (!Super && Impl->getSuperClass()) || | |||
5195 | (Super && Impl->getSuperClass() && | |||
5196 | !declaresSameEntity(Super->getCanonicalDecl(), | |||
5197 | Impl->getSuperClass()))) { | |||
5198 | Importer.ToDiag(Impl->getLocation(), | |||
5199 | diag::warn_odr_objc_superclass_inconsistent) | |||
5200 | << Iface->getDeclName(); | |||
5201 | // FIXME: It would be nice to have the location of the superclass | |||
5202 | // below. | |||
5203 | if (Impl->getSuperClass()) | |||
5204 | Importer.ToDiag(Impl->getLocation(), | |||
5205 | diag::note_odr_objc_superclass) | |||
5206 | << Impl->getSuperClass()->getDeclName(); | |||
5207 | else | |||
5208 | Importer.ToDiag(Impl->getLocation(), | |||
5209 | diag::note_odr_objc_missing_superclass); | |||
5210 | if (D->getSuperClass()) | |||
5211 | Importer.FromDiag(D->getLocation(), | |||
5212 | diag::note_odr_objc_superclass) | |||
5213 | << D->getSuperClass()->getDeclName(); | |||
5214 | else | |||
5215 | Importer.FromDiag(D->getLocation(), | |||
5216 | diag::note_odr_objc_missing_superclass); | |||
5217 | ||||
5218 | return make_error<ImportError>(ImportError::NameConflict); | |||
5219 | } | |||
5220 | } | |||
5221 | ||||
5222 | // Import all of the members of this @implementation. | |||
5223 | if (Error Err = ImportDeclContext(D)) | |||
5224 | return std::move(Err); | |||
5225 | ||||
5226 | return Impl; | |||
5227 | } | |||
5228 | ||||
5229 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { | |||
5230 | // Import the major distinguishing characteristics of an @property. | |||
5231 | DeclContext *DC, *LexicalDC; | |||
5232 | DeclarationName Name; | |||
5233 | SourceLocation Loc; | |||
5234 | NamedDecl *ToD; | |||
5235 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
5236 | return std::move(Err); | |||
5237 | if (ToD) | |||
5238 | return ToD; | |||
5239 | ||||
5240 | // Check whether we have already imported this property. | |||
5241 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | |||
5242 | for (auto *FoundDecl : FoundDecls) { | |||
5243 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { | |||
5244 | // Instance and class properties can share the same name but are different | |||
5245 | // declarations. | |||
5246 | if (FoundProp->isInstanceProperty() != D->isInstanceProperty()) | |||
5247 | continue; | |||
5248 | ||||
5249 | // Check property types. | |||
5250 | if (!Importer.IsStructurallyEquivalent(D->getType(), | |||
5251 | FoundProp->getType())) { | |||
5252 | Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent) | |||
5253 | << Name << D->getType() << FoundProp->getType(); | |||
5254 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) | |||
5255 | << FoundProp->getType(); | |||
5256 | ||||
5257 | return make_error<ImportError>(ImportError::NameConflict); | |||
5258 | } | |||
5259 | ||||
5260 | // FIXME: Check property attributes, getters, setters, etc.? | |||
5261 | ||||
5262 | // Consider these properties to be equivalent. | |||
5263 | Importer.MapImported(D, FoundProp); | |||
5264 | return FoundProp; | |||
5265 | } | |||
5266 | } | |||
5267 | ||||
5268 | Error Err = Error::success(); | |||
5269 | auto ToType = importChecked(Err, D->getType()); | |||
5270 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); | |||
5271 | auto ToAtLoc = importChecked(Err, D->getAtLoc()); | |||
5272 | auto ToLParenLoc = importChecked(Err, D->getLParenLoc()); | |||
5273 | if (Err) | |||
5274 | return std::move(Err); | |||
5275 | ||||
5276 | // Create the new property. | |||
5277 | ObjCPropertyDecl *ToProperty; | |||
5278 | if (GetImportedOrCreateDecl( | |||
5279 | ToProperty, D, Importer.getToContext(), DC, Loc, | |||
5280 | Name.getAsIdentifierInfo(), ToAtLoc, | |||
5281 | ToLParenLoc, ToType, | |||
5282 | ToTypeSourceInfo, D->getPropertyImplementation())) | |||
5283 | return ToProperty; | |||
5284 | ||||
5285 | auto ToGetterName = importChecked(Err, D->getGetterName()); | |||
5286 | auto ToSetterName = importChecked(Err, D->getSetterName()); | |||
5287 | auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc()); | |||
5288 | auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc()); | |||
5289 | auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl()); | |||
5290 | auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl()); | |||
5291 | auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl()); | |||
5292 | if (Err) | |||
5293 | return std::move(Err); | |||
5294 | ||||
5295 | ToProperty->setLexicalDeclContext(LexicalDC); | |||
5296 | LexicalDC->addDeclInternal(ToProperty); | |||
5297 | ||||
5298 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); | |||
5299 | ToProperty->setPropertyAttributesAsWritten( | |||
5300 | D->getPropertyAttributesAsWritten()); | |||
5301 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); | |||
5302 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); | |||
5303 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); | |||
5304 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); | |||
5305 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); | |||
5306 | return ToProperty; | |||
5307 | } | |||
5308 | ||||
5309 | ExpectedDecl | |||
5310 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { | |||
5311 | ObjCPropertyDecl *Property; | |||
5312 | if (Error Err = importInto(Property, D->getPropertyDecl())) | |||
5313 | return std::move(Err); | |||
5314 | ||||
5315 | DeclContext *DC, *LexicalDC; | |||
5316 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
5317 | return std::move(Err); | |||
5318 | ||||
5319 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); | |||
5320 | ||||
5321 | // Import the ivar (for an @synthesize). | |||
5322 | ObjCIvarDecl *Ivar = nullptr; | |||
5323 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) | |||
5324 | return std::move(Err); | |||
5325 | ||||
5326 | ObjCPropertyImplDecl *ToImpl | |||
5327 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), | |||
5328 | Property->getQueryKind()); | |||
5329 | if (!ToImpl) { | |||
5330 | ||||
5331 | Error Err = Error::success(); | |||
5332 | auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); | |||
5333 | auto ToLocation = importChecked(Err, D->getLocation()); | |||
5334 | auto ToPropertyIvarDeclLoc = | |||
5335 | importChecked(Err, D->getPropertyIvarDeclLoc()); | |||
5336 | if (Err) | |||
5337 | return std::move(Err); | |||
5338 | ||||
5339 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, | |||
5340 | ToBeginLoc, | |||
5341 | ToLocation, Property, | |||
5342 | D->getPropertyImplementation(), Ivar, | |||
5343 | ToPropertyIvarDeclLoc)) | |||
5344 | return ToImpl; | |||
5345 | ||||
5346 | ToImpl->setLexicalDeclContext(LexicalDC); | |||
5347 | LexicalDC->addDeclInternal(ToImpl); | |||
5348 | } else { | |||
5349 | // Check that we have the same kind of property implementation (@synthesize | |||
5350 | // vs. @dynamic). | |||
5351 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { | |||
5352 | Importer.ToDiag(ToImpl->getLocation(), | |||
5353 | diag::warn_odr_objc_property_impl_kind_inconsistent) | |||
5354 | << Property->getDeclName() | |||
5355 | << (ToImpl->getPropertyImplementation() | |||
5356 | == ObjCPropertyImplDecl::Dynamic); | |||
5357 | Importer.FromDiag(D->getLocation(), | |||
5358 | diag::note_odr_objc_property_impl_kind) | |||
5359 | << D->getPropertyDecl()->getDeclName() | |||
5360 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); | |||
5361 | ||||
5362 | return make_error<ImportError>(ImportError::NameConflict); | |||
5363 | } | |||
5364 | ||||
5365 | // For @synthesize, check that we have the same | |||
5366 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && | |||
5367 | Ivar != ToImpl->getPropertyIvarDecl()) { | |||
5368 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), | |||
5369 | diag::warn_odr_objc_synthesize_ivar_inconsistent) | |||
5370 | << Property->getDeclName() | |||
5371 | << ToImpl->getPropertyIvarDecl()->getDeclName() | |||
5372 | << Ivar->getDeclName(); | |||
5373 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), | |||
5374 | diag::note_odr_objc_synthesize_ivar_here) | |||
5375 | << D->getPropertyIvarDecl()->getDeclName(); | |||
5376 | ||||
5377 | return make_error<ImportError>(ImportError::NameConflict); | |||
5378 | } | |||
5379 | ||||
5380 | // Merge the existing implementation with the new implementation. | |||
5381 | Importer.MapImported(D, ToImpl); | |||
5382 | } | |||
5383 | ||||
5384 | return ToImpl; | |||
5385 | } | |||
5386 | ||||
5387 | ExpectedDecl | |||
5388 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { | |||
5389 | // For template arguments, we adopt the translation unit as our declaration | |||
5390 | // context. This context will be fixed when the actual template declaration | |||
5391 | // is created. | |||
5392 | ||||
5393 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | |||
5394 | if (!BeginLocOrErr) | |||
5395 | return BeginLocOrErr.takeError(); | |||
5396 | ||||
5397 | ExpectedSLoc LocationOrErr = import(D->getLocation()); | |||
5398 | if (!LocationOrErr) | |||
5399 | return LocationOrErr.takeError(); | |||
5400 | ||||
5401 | TemplateTypeParmDecl *ToD = nullptr; | |||
5402 | if (GetImportedOrCreateDecl( | |||
5403 | ToD, D, Importer.getToContext(), | |||
5404 | Importer.getToContext().getTranslationUnitDecl(), | |||
5405 | *BeginLocOrErr, *LocationOrErr, | |||
5406 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), | |||
5407 | D->wasDeclaredWithTypename(), D->isParameterPack(), | |||
5408 | D->hasTypeConstraint())) | |||
5409 | return ToD; | |||
5410 | ||||
5411 | // Import the type-constraint | |||
5412 | if (const TypeConstraint *TC = D->getTypeConstraint()) { | |||
5413 | ||||
5414 | Error Err = Error::success(); | |||
5415 | auto ToNNS = importChecked(Err, TC->getNestedNameSpecifierLoc()); | |||
5416 | auto ToName = importChecked(Err, TC->getConceptNameInfo().getName()); | |||
5417 | auto ToNameLoc = importChecked(Err, TC->getConceptNameInfo().getLoc()); | |||
5418 | auto ToFoundDecl = importChecked(Err, TC->getFoundDecl()); | |||
5419 | auto ToNamedConcept = importChecked(Err, TC->getNamedConcept()); | |||
5420 | auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint()); | |||
5421 | if (Err) | |||
5422 | return std::move(Err); | |||
5423 | ||||
5424 | TemplateArgumentListInfo ToTAInfo; | |||
5425 | const auto *ASTTemplateArgs = TC->getTemplateArgsAsWritten(); | |||
5426 | if (ASTTemplateArgs) | |||
5427 | if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, | |||
5428 | ToTAInfo)) | |||
5429 | return std::move(Err); | |||
5430 | ||||
5431 | ToD->setTypeConstraint(ToNNS, DeclarationNameInfo(ToName, ToNameLoc), | |||
5432 | ToFoundDecl, ToNamedConcept, | |||
5433 | ASTTemplateArgs ? | |||
5434 | ASTTemplateArgumentListInfo::Create(Importer.getToContext(), | |||
5435 | ToTAInfo) : nullptr, | |||
5436 | ToIDC); | |||
5437 | } | |||
5438 | ||||
5439 | if (D->hasDefaultArgument()) { | |||
5440 | Expected<TypeSourceInfo *> ToDefaultArgOrErr = | |||
5441 | import(D->getDefaultArgumentInfo()); | |||
5442 | if (!ToDefaultArgOrErr) | |||
5443 | return ToDefaultArgOrErr.takeError(); | |||
5444 | ToD->setDefaultArgument(*ToDefaultArgOrErr); | |||
5445 | } | |||
5446 | ||||
5447 | return ToD; | |||
5448 | } | |||
5449 | ||||
5450 | ExpectedDecl | |||
5451 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { | |||
5452 | ||||
5453 | Error Err = Error::success(); | |||
5454 | auto ToDeclName = importChecked(Err, D->getDeclName()); | |||
5455 | auto ToLocation = importChecked(Err, D->getLocation()); | |||
5456 | auto ToType = importChecked(Err, D->getType()); | |||
5457 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); | |||
5458 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); | |||
5459 | if (Err) | |||
5460 | return std::move(Err); | |||
5461 | ||||
5462 | NonTypeTemplateParmDecl *ToD = nullptr; | |||
5463 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), | |||
5464 | Importer.getToContext().getTranslationUnitDecl(), | |||
5465 | ToInnerLocStart, ToLocation, D->getDepth(), | |||
5466 | D->getPosition(), | |||
5467 | ToDeclName.getAsIdentifierInfo(), ToType, | |||
5468 | D->isParameterPack(), ToTypeSourceInfo)) | |||
5469 | return ToD; | |||
5470 | ||||
5471 | if (D->hasDefaultArgument()) { | |||
5472 | ExpectedExpr ToDefaultArgOrErr = import(D->getDefaultArgument()); | |||
5473 | if (!ToDefaultArgOrErr) | |||
5474 | return ToDefaultArgOrErr.takeError(); | |||
5475 | ToD->setDefaultArgument(*ToDefaultArgOrErr); | |||
5476 | } | |||
5477 | ||||
5478 | return ToD; | |||
5479 | } | |||
5480 | ||||
5481 | ExpectedDecl | |||
5482 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { | |||
5483 | // Import the name of this declaration. | |||
5484 | auto NameOrErr = import(D->getDeclName()); | |||
5485 | if (!NameOrErr) | |||
5486 | return NameOrErr.takeError(); | |||
5487 | ||||
5488 | // Import the location of this declaration. | |||
5489 | ExpectedSLoc LocationOrErr = import(D->getLocation()); | |||
5490 | if (!LocationOrErr) | |||
5491 | return LocationOrErr.takeError(); | |||
5492 | ||||
5493 | // Import template parameters. | |||
5494 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); | |||
5495 | if (!TemplateParamsOrErr) | |||
5496 | return TemplateParamsOrErr.takeError(); | |||
5497 | ||||
5498 | TemplateTemplateParmDecl *ToD = nullptr; | |||
5499 | if (GetImportedOrCreateDecl( | |||
5500 | ToD, D, Importer.getToContext(), | |||
5501 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, | |||
5502 | D->getDepth(), D->getPosition(), D->isParameterPack(), | |||
5503 | (*NameOrErr).getAsIdentifierInfo(), *TemplateParamsOrErr)) | |||
5504 | return ToD; | |||
5505 | ||||
5506 | if (D->hasDefaultArgument()) { | |||
5507 | Expected<TemplateArgumentLoc> ToDefaultArgOrErr = | |||
5508 | import(D->getDefaultArgument()); | |||
5509 | if (!ToDefaultArgOrErr) | |||
5510 | return ToDefaultArgOrErr.takeError(); | |||
5511 | ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr); | |||
5512 | } | |||
5513 | ||||
5514 | return ToD; | |||
5515 | } | |||
5516 | ||||
5517 | // Returns the definition for a (forward) declaration of a TemplateDecl, if | |||
5518 | // it has any definition in the redecl chain. | |||
5519 | template <typename T> static auto getTemplateDefinition(T *D) -> T * { | |||
5520 | assert(D->getTemplatedDecl() && "Should be called on templates only")(static_cast <bool> (D->getTemplatedDecl() && "Should be called on templates only") ? void (0) : __assert_fail ("D->getTemplatedDecl() && \"Should be called on templates only\"" , "clang/lib/AST/ASTImporter.cpp", 5520, __extension__ __PRETTY_FUNCTION__ )); | |||
5521 | auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); | |||
5522 | if (!ToTemplatedDef) | |||
5523 | return nullptr; | |||
5524 | auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate(); | |||
5525 | return cast_or_null<T>(TemplateWithDef); | |||
5526 | } | |||
5527 | ||||
5528 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { | |||
5529 | ||||
5530 | // Import the major distinguishing characteristics of this class template. | |||
5531 | DeclContext *DC, *LexicalDC; | |||
5532 | DeclarationName Name; | |||
5533 | SourceLocation Loc; | |||
5534 | NamedDecl *ToD; | |||
5535 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
5536 | return std::move(Err); | |||
5537 | if (ToD) | |||
5538 | return ToD; | |||
5539 | ||||
5540 | ClassTemplateDecl *FoundByLookup = nullptr; | |||
5541 | ||||
5542 | // We may already have a template of the same name; try to find and match it. | |||
5543 | if (!DC->isFunctionOrMethod()) { | |||
5544 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
5545 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | |||
5546 | for (auto *FoundDecl : FoundDecls) { | |||
5547 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary | | |||
5548 | Decl::IDNS_TagFriend)) | |||
5549 | continue; | |||
5550 | ||||
5551 | Decl *Found = FoundDecl; | |||
5552 | auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found); | |||
5553 | if (FoundTemplate) { | |||
5554 | if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D)) | |||
5555 | continue; | |||
5556 | ||||
5557 | if (IsStructuralMatch(D, FoundTemplate)) { | |||
5558 | ClassTemplateDecl *TemplateWithDef = | |||
5559 | getTemplateDefinition(FoundTemplate); | |||
5560 | if (D->isThisDeclarationADefinition() && TemplateWithDef) | |||
5561 | return Importer.MapImported(D, TemplateWithDef); | |||
5562 | if (!FoundByLookup) | |||
5563 | FoundByLookup = FoundTemplate; | |||
5564 | // Search in all matches because there may be multiple decl chains, | |||
5565 | // see ASTTests test ImportExistingFriendClassTemplateDef. | |||
5566 | continue; | |||
5567 | } | |||
5568 | ConflictingDecls.push_back(FoundDecl); | |||
5569 | } | |||
5570 | } | |||
5571 | ||||
5572 | if (!ConflictingDecls.empty()) { | |||
5573 | ExpectedName NameOrErr = Importer.HandleNameConflict( | |||
5574 | Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(), | |||
5575 | ConflictingDecls.size()); | |||
5576 | if (NameOrErr) | |||
5577 | Name = NameOrErr.get(); | |||
5578 | else | |||
5579 | return NameOrErr.takeError(); | |||
5580 | } | |||
5581 | } | |||
5582 | ||||
5583 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); | |||
5584 | ||||
5585 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); | |||
5586 | if (!TemplateParamsOrErr) | |||
5587 | return TemplateParamsOrErr.takeError(); | |||
5588 | ||||
5589 | // Create the declaration that is being templated. | |||
5590 | CXXRecordDecl *ToTemplated; | |||
5591 | if (Error Err = importInto(ToTemplated, FromTemplated)) | |||
5592 | return std::move(Err); | |||
5593 | ||||
5594 | // Create the class template declaration itself. | |||
5595 | ClassTemplateDecl *D2; | |||
5596 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, | |||
5597 | *TemplateParamsOrErr, ToTemplated)) | |||
5598 | return D2; | |||
5599 | ||||
5600 | ToTemplated->setDescribedClassTemplate(D2); | |||
5601 | ||||
5602 | D2->setAccess(D->getAccess()); | |||
5603 | D2->setLexicalDeclContext(LexicalDC); | |||
5604 | ||||
5605 | addDeclToContexts(D, D2); | |||
5606 | updateLookupTableForTemplateParameters(**TemplateParamsOrErr); | |||
5607 | ||||
5608 | if (FoundByLookup) { | |||
5609 | auto *Recent = | |||
5610 | const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl()); | |||
5611 | ||||
5612 | // It is possible that during the import of the class template definition | |||
5613 | // we start the import of a fwd friend decl of the very same class template | |||
5614 | // and we add the fwd friend decl to the lookup table. But the ToTemplated | |||
5615 | // had been created earlier and by that time the lookup could not find | |||
5616 | // anything existing, so it has no previous decl. Later, (still during the | |||
5617 | // import of the fwd friend decl) we start to import the definition again | |||
5618 | // and this time the lookup finds the previous fwd friend class template. | |||
5619 | // In this case we must set up the previous decl for the templated decl. | |||
5620 | if (!ToTemplated->getPreviousDecl()) { | |||
5621 | assert(FoundByLookup->getTemplatedDecl() &&(static_cast <bool> (FoundByLookup->getTemplatedDecl () && "Found decl must have its templated decl set") ? void (0) : __assert_fail ("FoundByLookup->getTemplatedDecl() && \"Found decl must have its templated decl set\"" , "clang/lib/AST/ASTImporter.cpp", 5622, __extension__ __PRETTY_FUNCTION__ )) | |||
5622 | "Found decl must have its templated decl set")(static_cast <bool> (FoundByLookup->getTemplatedDecl () && "Found decl must have its templated decl set") ? void (0) : __assert_fail ("FoundByLookup->getTemplatedDecl() && \"Found decl must have its templated decl set\"" , "clang/lib/AST/ASTImporter.cpp", 5622, __extension__ __PRETTY_FUNCTION__ )); | |||
5623 | CXXRecordDecl *PrevTemplated = | |||
5624 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); | |||
5625 | if (ToTemplated != PrevTemplated) | |||
5626 | ToTemplated->setPreviousDecl(PrevTemplated); | |||
5627 | } | |||
5628 | ||||
5629 | D2->setPreviousDecl(Recent); | |||
5630 | } | |||
5631 | ||||
5632 | if (FromTemplated->isCompleteDefinition() && | |||
5633 | !ToTemplated->isCompleteDefinition()) { | |||
5634 | // FIXME: Import definition! | |||
5635 | } | |||
5636 | ||||
5637 | return D2; | |||
5638 | } | |||
5639 | ||||
5640 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( | |||
5641 | ClassTemplateSpecializationDecl *D) { | |||
5642 | ClassTemplateDecl *ClassTemplate; | |||
5643 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) | |||
5644 | return std::move(Err); | |||
5645 | ||||
5646 | // Import the context of this declaration. | |||
5647 | DeclContext *DC, *LexicalDC; | |||
5648 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
5649 | return std::move(Err); | |||
5650 | ||||
5651 | // Import template arguments. | |||
5652 | SmallVector<TemplateArgument, 2> TemplateArgs; | |||
5653 | if (Error Err = ImportTemplateArguments( | |||
5654 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) | |||
5655 | return std::move(Err); | |||
5656 | // Try to find an existing specialization with these template arguments and | |||
5657 | // template parameter list. | |||
5658 | void *InsertPos = nullptr; | |||
5659 | ClassTemplateSpecializationDecl *PrevDecl = nullptr; | |||
5660 | ClassTemplatePartialSpecializationDecl *PartialSpec = | |||
5661 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); | |||
5662 | ||||
5663 | // Import template parameters. | |||
5664 | TemplateParameterList *ToTPList = nullptr; | |||
5665 | ||||
5666 | if (PartialSpec) { | |||
5667 | auto ToTPListOrErr = import(PartialSpec->getTemplateParameters()); | |||
5668 | if (!ToTPListOrErr) | |||
5669 | return ToTPListOrErr.takeError(); | |||
5670 | ToTPList = *ToTPListOrErr; | |||
5671 | PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs, | |||
5672 | *ToTPListOrErr, | |||
5673 | InsertPos); | |||
5674 | } else | |||
5675 | PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); | |||
5676 | ||||
5677 | if (PrevDecl) { | |||
5678 | if (IsStructuralMatch(D, PrevDecl)) { | |||
5679 | CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition(); | |||
5680 | if (D->isThisDeclarationADefinition() && PrevDefinition) { | |||
5681 | Importer.MapImported(D, PrevDefinition); | |||
5682 | // Import those default field initializers which have been | |||
5683 | // instantiated in the "From" context, but not in the "To" context. | |||
5684 | for (auto *FromField : D->fields()) { | |||
5685 | auto ToOrErr = import(FromField); | |||
5686 | if (!ToOrErr) | |||
5687 | return ToOrErr.takeError(); | |||
5688 | } | |||
5689 | ||||
5690 | // Import those methods which have been instantiated in the | |||
5691 | // "From" context, but not in the "To" context. | |||
5692 | for (CXXMethodDecl *FromM : D->methods()) { | |||
5693 | auto ToOrErr = import(FromM); | |||
5694 | if (!ToOrErr) | |||
5695 | return ToOrErr.takeError(); | |||
5696 | } | |||
5697 | ||||
5698 | // TODO Import instantiated default arguments. | |||
5699 | // TODO Import instantiated exception specifications. | |||
5700 | // | |||
5701 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint | |||
5702 | // what else could be fused during an AST merge. | |||
5703 | return PrevDefinition; | |||
5704 | } | |||
5705 | } else { // ODR violation. | |||
5706 | // FIXME HandleNameConflict | |||
5707 | return make_error<ImportError>(ImportError::NameConflict); | |||
5708 | } | |||
5709 | } | |||
5710 | ||||
5711 | // Import the location of this declaration. | |||
5712 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | |||
5713 | if (!BeginLocOrErr) | |||
5714 | return BeginLocOrErr.takeError(); | |||
5715 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); | |||
5716 | if (!IdLocOrErr) | |||
5717 | return IdLocOrErr.takeError(); | |||
5718 | ||||
5719 | // Create the specialization. | |||
5720 | ClassTemplateSpecializationDecl *D2 = nullptr; | |||
5721 | if (PartialSpec) { | |||
5722 | // Import TemplateArgumentListInfo. | |||
5723 | TemplateArgumentListInfo ToTAInfo; | |||
5724 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); | |||
5725 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) | |||
5726 | return std::move(Err); | |||
5727 | ||||
5728 | QualType CanonInjType; | |||
5729 | if (Error Err = importInto( | |||
5730 | CanonInjType, PartialSpec->getInjectedSpecializationType())) | |||
5731 | return std::move(Err); | |||
5732 | CanonInjType = CanonInjType.getCanonicalType(); | |||
5733 | ||||
5734 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( | |||
5735 | D2, D, Importer.getToContext(), D->getTagKind(), DC, | |||
5736 | *BeginLocOrErr, *IdLocOrErr, ToTPList, ClassTemplate, | |||
5737 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), | |||
5738 | ToTAInfo, CanonInjType, | |||
5739 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) | |||
5740 | return D2; | |||
5741 | ||||
5742 | // Update InsertPos, because preceding import calls may have invalidated | |||
5743 | // it by adding new specializations. | |||
5744 | auto *PartSpec2 = cast<ClassTemplatePartialSpecializationDecl>(D2); | |||
5745 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList, | |||
5746 | InsertPos)) | |||
5747 | // Add this partial specialization to the class template. | |||
5748 | ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos); | |||
5749 | ||||
5750 | updateLookupTableForTemplateParameters(*ToTPList); | |||
5751 | } else { // Not a partial specialization. | |||
5752 | if (GetImportedOrCreateDecl( | |||
5753 | D2, D, Importer.getToContext(), D->getTagKind(), DC, | |||
5754 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, | |||
5755 | PrevDecl)) | |||
5756 | return D2; | |||
5757 | ||||
5758 | // Update InsertPos, because preceding import calls may have invalidated | |||
5759 | // it by adding new specializations. | |||
5760 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) | |||
5761 | // Add this specialization to the class template. | |||
5762 | ClassTemplate->AddSpecialization(D2, InsertPos); | |||
5763 | } | |||
5764 | ||||
5765 | D2->setSpecializationKind(D->getSpecializationKind()); | |||
5766 | ||||
5767 | // Set the context of this specialization/instantiation. | |||
5768 | D2->setLexicalDeclContext(LexicalDC); | |||
5769 | ||||
5770 | // Add to the DC only if it was an explicit specialization/instantiation. | |||
5771 | if (D2->isExplicitInstantiationOrSpecialization()) { | |||
5772 | LexicalDC->addDeclInternal(D2); | |||
5773 | } | |||
5774 | ||||
5775 | if (auto BraceRangeOrErr = import(D->getBraceRange())) | |||
5776 | D2->setBraceRange(*BraceRangeOrErr); | |||
5777 | else | |||
5778 | return BraceRangeOrErr.takeError(); | |||
5779 | ||||
5780 | // Import the qualifier, if any. | |||
5781 | if (auto LocOrErr = import(D->getQualifierLoc())) | |||
5782 | D2->setQualifierInfo(*LocOrErr); | |||
5783 | else | |||
5784 | return LocOrErr.takeError(); | |||
5785 | ||||
5786 | if (auto *TSI = D->getTypeAsWritten()) { | |||
5787 | if (auto TInfoOrErr = import(TSI)) | |||
5788 | D2->setTypeAsWritten(*TInfoOrErr); | |||
5789 | else | |||
5790 | return TInfoOrErr.takeError(); | |||
5791 | ||||
5792 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) | |||
5793 | D2->setTemplateKeywordLoc(*LocOrErr); | |||
5794 | else | |||
5795 | return LocOrErr.takeError(); | |||
5796 | ||||
5797 | if (auto LocOrErr = import(D->getExternLoc())) | |||
5798 | D2->setExternLoc(*LocOrErr); | |||
5799 | else | |||
5800 | return LocOrErr.takeError(); | |||
5801 | } | |||
5802 | ||||
5803 | if (D->getPointOfInstantiation().isValid()) { | |||
5804 | if (auto POIOrErr = import(D->getPointOfInstantiation())) | |||
5805 | D2->setPointOfInstantiation(*POIOrErr); | |||
5806 | else | |||
5807 | return POIOrErr.takeError(); | |||
5808 | } | |||
5809 | ||||
5810 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); | |||
5811 | ||||
5812 | if (D->isCompleteDefinition()) | |||
5813 | if (Error Err = ImportDefinition(D, D2)) | |||
5814 | return std::move(Err); | |||
5815 | ||||
5816 | return D2; | |||
5817 | } | |||
5818 | ||||
5819 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { | |||
5820 | // Import the major distinguishing characteristics of this variable template. | |||
5821 | DeclContext *DC, *LexicalDC; | |||
5822 | DeclarationName Name; | |||
5823 | SourceLocation Loc; | |||
5824 | NamedDecl *ToD; | |||
5825 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
5826 | return std::move(Err); | |||
5827 | if (ToD) | |||
5828 | return ToD; | |||
5829 | ||||
5830 | // We may already have a template of the same name; try to find and match it. | |||
5831 | assert(!DC->isFunctionOrMethod() &&(static_cast <bool> (!DC->isFunctionOrMethod() && "Variable templates cannot be declared at function scope") ? void (0) : __assert_fail ("!DC->isFunctionOrMethod() && \"Variable templates cannot be declared at function scope\"" , "clang/lib/AST/ASTImporter.cpp", 5832, __extension__ __PRETTY_FUNCTION__ )) | |||
5832 | "Variable templates cannot be declared at function scope")(static_cast <bool> (!DC->isFunctionOrMethod() && "Variable templates cannot be declared at function scope") ? void (0) : __assert_fail ("!DC->isFunctionOrMethod() && \"Variable templates cannot be declared at function scope\"" , "clang/lib/AST/ASTImporter.cpp", 5832, __extension__ __PRETTY_FUNCTION__ )); | |||
5833 | ||||
5834 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
5835 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | |||
5836 | VarTemplateDecl *FoundByLookup = nullptr; | |||
5837 | for (auto *FoundDecl : FoundDecls) { | |||
5838 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) | |||
5839 | continue; | |||
5840 | ||||
5841 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) { | |||
5842 | // Use the templated decl, some linkage flags are set only there. | |||
5843 | if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(), | |||
5844 | D->getTemplatedDecl())) | |||
5845 | continue; | |||
5846 | if (IsStructuralMatch(D, FoundTemplate)) { | |||
5847 | // The Decl in the "From" context has a definition, but in the | |||
5848 | // "To" context we already have a definition. | |||
5849 | VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate); | |||
5850 | if (D->isThisDeclarationADefinition() && FoundDef) | |||
5851 | // FIXME Check for ODR error if the two definitions have | |||
5852 | // different initializers? | |||
5853 | return Importer.MapImported(D, FoundDef); | |||
5854 | ||||
5855 | FoundByLookup = FoundTemplate; | |||
5856 | break; | |||
5857 | } | |||
5858 | ConflictingDecls.push_back(FoundDecl); | |||
5859 | } | |||
5860 | } | |||
5861 | ||||
5862 | if (!ConflictingDecls.empty()) { | |||
5863 | ExpectedName NameOrErr = Importer.HandleNameConflict( | |||
5864 | Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(), | |||
5865 | ConflictingDecls.size()); | |||
5866 | if (NameOrErr) | |||
5867 | Name = NameOrErr.get(); | |||
5868 | else | |||
5869 | return NameOrErr.takeError(); | |||
5870 | } | |||
5871 | ||||
5872 | VarDecl *DTemplated = D->getTemplatedDecl(); | |||
5873 | ||||
5874 | // Import the type. | |||
5875 | // FIXME: Value not used? | |||
5876 | ExpectedType TypeOrErr = import(DTemplated->getType()); | |||
5877 | if (!TypeOrErr) | |||
5878 | return TypeOrErr.takeError(); | |||
5879 | ||||
5880 | // Create the declaration that is being templated. | |||
5881 | VarDecl *ToTemplated; | |||
5882 | if (Error Err = importInto(ToTemplated, DTemplated)) | |||
5883 | return std::move(Err); | |||
5884 | ||||
5885 | // Create the variable template declaration itself. | |||
5886 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); | |||
5887 | if (!TemplateParamsOrErr) | |||
5888 | return TemplateParamsOrErr.takeError(); | |||
5889 | ||||
5890 | VarTemplateDecl *ToVarTD; | |||
5891 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, | |||
5892 | Name, *TemplateParamsOrErr, ToTemplated)) | |||
5893 | return ToVarTD; | |||
5894 | ||||
5895 | ToTemplated->setDescribedVarTemplate(ToVarTD); | |||
5896 | ||||
5897 | ToVarTD->setAccess(D->getAccess()); | |||
5898 | ToVarTD->setLexicalDeclContext(LexicalDC); | |||
5899 | LexicalDC->addDeclInternal(ToVarTD); | |||
5900 | if (DC != Importer.getToContext().getTranslationUnitDecl()) | |||
5901 | updateLookupTableForTemplateParameters(**TemplateParamsOrErr); | |||
5902 | ||||
5903 | if (FoundByLookup) { | |||
5904 | auto *Recent = | |||
5905 | const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl()); | |||
5906 | if (!ToTemplated->getPreviousDecl()) { | |||
5907 | auto *PrevTemplated = | |||
5908 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); | |||
5909 | if (ToTemplated != PrevTemplated) | |||
5910 | ToTemplated->setPreviousDecl(PrevTemplated); | |||
5911 | } | |||
5912 | ToVarTD->setPreviousDecl(Recent); | |||
5913 | } | |||
5914 | ||||
5915 | if (DTemplated->isThisDeclarationADefinition() && | |||
5916 | !ToTemplated->isThisDeclarationADefinition()) { | |||
5917 | // FIXME: Import definition! | |||
5918 | } | |||
5919 | ||||
5920 | return ToVarTD; | |||
5921 | } | |||
5922 | ||||
5923 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( | |||
5924 | VarTemplateSpecializationDecl *D) { | |||
5925 | // If this record has a definition in the translation unit we're coming from, | |||
5926 | // but this particular declaration is not that definition, import the | |||
5927 | // definition and map to that. | |||
5928 | VarDecl *Definition = D->getDefinition(); | |||
5929 | if (Definition && Definition != D) { | |||
5930 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | |||
5931 | return Importer.MapImported(D, *ImportedDefOrErr); | |||
5932 | else | |||
5933 | return ImportedDefOrErr.takeError(); | |||
5934 | } | |||
5935 | ||||
5936 | VarTemplateDecl *VarTemplate = nullptr; | |||
5937 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) | |||
5938 | return std::move(Err); | |||
5939 | ||||
5940 | // Import the context of this declaration. | |||
5941 | DeclContext *DC, *LexicalDC; | |||
5942 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
5943 | return std::move(Err); | |||
5944 | ||||
5945 | // Import the location of this declaration. | |||
5946 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | |||
5947 | if (!BeginLocOrErr) | |||
5948 | return BeginLocOrErr.takeError(); | |||
5949 | ||||
5950 | auto IdLocOrErr = import(D->getLocation()); | |||
5951 | if (!IdLocOrErr) | |||
5952 | return IdLocOrErr.takeError(); | |||
5953 | ||||
5954 | // Import template arguments. | |||
5955 | SmallVector<TemplateArgument, 2> TemplateArgs; | |||
5956 | if (Error Err = ImportTemplateArguments( | |||
5957 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) | |||
5958 | return std::move(Err); | |||
5959 | ||||
5960 | // Try to find an existing specialization with these template arguments. | |||
5961 | void *InsertPos = nullptr; | |||
5962 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( | |||
| ||||
5963 | TemplateArgs, InsertPos); | |||
5964 | if (D2) { | |||
5965 | // We already have a variable template specialization with these template | |||
5966 | // arguments. | |||
5967 | ||||
5968 | // FIXME: Check for specialization vs. instantiation errors. | |||
5969 | ||||
5970 | if (VarDecl *FoundDef = D2->getDefinition()) { | |||
5971 | if (!D->isThisDeclarationADefinition() || | |||
5972 | IsStructuralMatch(D, FoundDef)) { | |||
5973 | // The record types structurally match, or the "from" translation | |||
5974 | // unit only had a forward declaration anyway; call it the same | |||
5975 | // variable. | |||
5976 | return Importer.MapImported(D, FoundDef); | |||
5977 | } | |||
5978 | } | |||
5979 | } else { | |||
5980 | // Import the type. | |||
5981 | QualType T; | |||
5982 | if (Error Err = importInto(T, D->getType())) | |||
5983 | return std::move(Err); | |||
5984 | ||||
5985 | auto TInfoOrErr = import(D->getTypeSourceInfo()); | |||
5986 | if (!TInfoOrErr) | |||
5987 | return TInfoOrErr.takeError(); | |||
5988 | ||||
5989 | TemplateArgumentListInfo ToTAInfo; | |||
5990 | if (Error Err = ImportTemplateArgumentListInfo( | |||
5991 | D->getTemplateArgsInfo(), ToTAInfo)) | |||
5992 | return std::move(Err); | |||
5993 | ||||
5994 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; | |||
5995 | // Create a new specialization. | |||
5996 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { | |||
5997 | // Import TemplateArgumentListInfo | |||
5998 | TemplateArgumentListInfo ArgInfos; | |||
5999 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); | |||
6000 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. | |||
6001 | if (Error Err = ImportTemplateArgumentListInfo( | |||
6002 | *FromTAArgsAsWritten, ArgInfos)) | |||
6003 | return std::move(Err); | |||
6004 | ||||
6005 | auto ToTPListOrErr = import(FromPartial->getTemplateParameters()); | |||
6006 | if (!ToTPListOrErr) | |||
6007 | return ToTPListOrErr.takeError(); | |||
6008 | ||||
6009 | PartVarSpecDecl *ToPartial; | |||
6010 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, | |||
6011 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, | |||
6012 | VarTemplate, T, *TInfoOrErr, | |||
6013 | D->getStorageClass(), TemplateArgs, ArgInfos)) | |||
6014 | return ToPartial; | |||
6015 | ||||
6016 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( | |||
6017 | FromPartial->getInstantiatedFromMember())) | |||
6018 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); | |||
6019 | else | |||
6020 | return ToInstOrErr.takeError(); | |||
6021 | ||||
6022 | if (FromPartial->isMemberSpecialization()) | |||
6023 | ToPartial->setMemberSpecialization(); | |||
6024 | ||||
6025 | D2 = ToPartial; | |||
6026 | ||||
6027 | // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed | |||
6028 | // to adopt template parameters. | |||
6029 | // updateLookupTableForTemplateParameters(**ToTPListOrErr); | |||
6030 | } else { // Full specialization | |||
6031 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, | |||
6032 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, | |||
6033 | T, *TInfoOrErr, | |||
6034 | D->getStorageClass(), TemplateArgs)) | |||
6035 | return D2; | |||
6036 | } | |||
6037 | ||||
6038 | if (D->getPointOfInstantiation().isValid()) { | |||
6039 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) | |||
6040 | D2->setPointOfInstantiation(*POIOrErr); | |||
6041 | else | |||
6042 | return POIOrErr.takeError(); | |||
6043 | } | |||
6044 | ||||
6045 | D2->setSpecializationKind(D->getSpecializationKind()); | |||
6046 | D2->setTemplateArgsInfo(ToTAInfo); | |||
6047 | ||||
6048 | // Add this specialization to the class template. | |||
6049 | VarTemplate->AddSpecialization(D2, InsertPos); | |||
6050 | ||||
6051 | // Import the qualifier, if any. | |||
6052 | if (auto LocOrErr = import(D->getQualifierLoc())) | |||
6053 | D2->setQualifierInfo(*LocOrErr); | |||
6054 | else | |||
6055 | return LocOrErr.takeError(); | |||
6056 | ||||
6057 | if (D->isConstexpr()) | |||
6058 | D2->setConstexpr(true); | |||
6059 | ||||
6060 | // Add the specialization to this context. | |||
6061 | D2->setLexicalDeclContext(LexicalDC); | |||
6062 | LexicalDC->addDeclInternal(D2); | |||
6063 | ||||
6064 | D2->setAccess(D->getAccess()); | |||
6065 | } | |||
6066 | ||||
6067 | if (Error Err = ImportInitializer(D, D2)) | |||
6068 | return std::move(Err); | |||
6069 | ||||
6070 | return D2; | |||
6071 | } | |||
6072 | ||||
6073 | ExpectedDecl | |||
6074 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { | |||
6075 | DeclContext *DC, *LexicalDC; | |||
6076 | DeclarationName Name; | |||
6077 | SourceLocation Loc; | |||
6078 | NamedDecl *ToD; | |||
6079 | ||||
6080 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
6081 | return std::move(Err); | |||
6082 | ||||
6083 | if (ToD) | |||
6084 | return ToD; | |||
6085 | ||||
6086 | const FunctionTemplateDecl *FoundByLookup = nullptr; | |||
6087 | ||||
6088 | // Try to find a function in our own ("to") context with the same name, same | |||
6089 | // type, and in the same context as the function we're importing. | |||
6090 | // FIXME Split this into a separate function. | |||
6091 | if (!LexicalDC->isFunctionOrMethod()) { | |||
6092 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; | |||
6093 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | |||
6094 | for (auto *FoundDecl : FoundDecls) { | |||
6095 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
6096 | continue; | |||
6097 | ||||
6098 | if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { | |||
6099 | if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D)) | |||
6100 | continue; | |||
6101 | if (IsStructuralMatch(D, FoundTemplate)) { | |||
6102 | FunctionTemplateDecl *TemplateWithDef = | |||
6103 | getTemplateDefinition(FoundTemplate); | |||
6104 | if (D->isThisDeclarationADefinition() && TemplateWithDef) | |||
6105 | return Importer.MapImported(D, TemplateWithDef); | |||
6106 | ||||
6107 | FoundByLookup = FoundTemplate; | |||
6108 | break; | |||
6109 | // TODO: handle conflicting names | |||
6110 | } | |||
6111 | } | |||
6112 | } | |||
6113 | } | |||
6114 | ||||
6115 | auto ParamsOrErr = import(D->getTemplateParameters()); | |||
6116 | if (!ParamsOrErr) | |||
6117 | return ParamsOrErr.takeError(); | |||
6118 | TemplateParameterList *Params = *ParamsOrErr; | |||
6119 | ||||
6120 | FunctionDecl *TemplatedFD; | |||
6121 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) | |||
6122 | return std::move(Err); | |||
6123 | ||||
6124 | // At creation of the template the template parameters are "adopted" | |||
6125 | // (DeclContext is changed). After this possible change the lookup table | |||
6126 | // must be updated. | |||
6127 | // At deduction guides the DeclContext of the template parameters may be | |||
6128 | // different from what we would expect, it may be the class template, or a | |||
6129 | // probably different CXXDeductionGuideDecl. This may come from the fact that | |||
6130 | // the template parameter objects may be shared between deduction guides or | |||
6131 | // the class template, and at creation of multiple FunctionTemplateDecl | |||
6132 | // objects (for deduction guides) the same parameters are re-used. The | |||
6133 | // "adoption" happens multiple times with different parent, even recursively | |||
6134 | // for TemplateTemplateParmDecl. The same happens at import when the | |||
6135 | // FunctionTemplateDecl objects are created, but in different order. | |||
6136 | // In this way the DeclContext of these template parameters is not necessarily | |||
6137 | // the same as in the "from" context. | |||
6138 | SmallVector<DeclContext *, 2> OldParamDC; | |||
6139 | OldParamDC.reserve(Params->size()); | |||
6140 | llvm::transform(*Params, std::back_inserter(OldParamDC), | |||
6141 | [](NamedDecl *ND) { return ND->getDeclContext(); }); | |||
6142 | ||||
6143 | FunctionTemplateDecl *ToFunc; | |||
6144 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, | |||
6145 | Params, TemplatedFD)) | |||
6146 | return ToFunc; | |||
6147 | ||||
6148 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); | |||
6149 | ||||
6150 | ToFunc->setAccess(D->getAccess()); | |||
6151 | ToFunc->setLexicalDeclContext(LexicalDC); | |||
6152 | LexicalDC->addDeclInternal(ToFunc); | |||
6153 | ||||
6154 | ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable(); | |||
6155 | if (LT && !OldParamDC.empty()) { | |||
6156 | for (unsigned int I = 0; I < OldParamDC.size(); ++I) | |||
6157 | LT->updateForced(Params->getParam(I), OldParamDC[I]); | |||
6158 | } | |||
6159 | ||||
6160 | if (FoundByLookup) { | |||
6161 | auto *Recent = | |||
6162 | const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl()); | |||
6163 | if (!TemplatedFD->getPreviousDecl()) { | |||
6164 | assert(FoundByLookup->getTemplatedDecl() &&(static_cast <bool> (FoundByLookup->getTemplatedDecl () && "Found decl must have its templated decl set") ? void (0) : __assert_fail ("FoundByLookup->getTemplatedDecl() && \"Found decl must have its templated decl set\"" , "clang/lib/AST/ASTImporter.cpp", 6165, __extension__ __PRETTY_FUNCTION__ )) | |||
6165 | "Found decl must have its templated decl set")(static_cast <bool> (FoundByLookup->getTemplatedDecl () && "Found decl must have its templated decl set") ? void (0) : __assert_fail ("FoundByLookup->getTemplatedDecl() && \"Found decl must have its templated decl set\"" , "clang/lib/AST/ASTImporter.cpp", 6165, __extension__ __PRETTY_FUNCTION__ )); | |||
6166 | auto *PrevTemplated = | |||
6167 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); | |||
6168 | if (TemplatedFD != PrevTemplated) | |||
6169 | TemplatedFD->setPreviousDecl(PrevTemplated); | |||
6170 | } | |||
6171 | ToFunc->setPreviousDecl(Recent); | |||
6172 | } | |||
6173 | ||||
6174 | return ToFunc; | |||
6175 | } | |||
6176 | ||||
6177 | //---------------------------------------------------------------------------- | |||
6178 | // Import Statements | |||
6179 | //---------------------------------------------------------------------------- | |||
6180 | ||||
6181 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { | |||
6182 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) | |||
6183 | << S->getStmtClassName(); | |||
6184 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
6185 | } | |||
6186 | ||||
6187 | ||||
6188 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { | |||
6189 | if (Importer.returnWithErrorInTest()) | |||
6190 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
6191 | SmallVector<IdentifierInfo *, 4> Names; | |||
6192 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { | |||
6193 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); | |||
6194 | // ToII is nullptr when no symbolic name is given for output operand | |||
6195 | // see ParseStmtAsm::ParseAsmOperandsOpt | |||
6196 | Names.push_back(ToII); | |||
6197 | } | |||
6198 | ||||
6199 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { | |||
6200 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); | |||
6201 | // ToII is nullptr when no symbolic name is given for input operand | |||
6202 | // see ParseStmtAsm::ParseAsmOperandsOpt | |||
6203 | Names.push_back(ToII); | |||
6204 | } | |||
6205 | ||||
6206 | SmallVector<StringLiteral *, 4> Clobbers; | |||
6207 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { | |||
6208 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) | |||
6209 | Clobbers.push_back(*ClobberOrErr); | |||
6210 | else | |||
6211 | return ClobberOrErr.takeError(); | |||
6212 | ||||
6213 | } | |||
6214 | ||||
6215 | SmallVector<StringLiteral *, 4> Constraints; | |||
6216 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { | |||
6217 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) | |||
6218 | Constraints.push_back(*OutputOrErr); | |||
6219 | else | |||
6220 | return OutputOrErr.takeError(); | |||
6221 | } | |||
6222 | ||||
6223 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { | |||
6224 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) | |||
6225 | Constraints.push_back(*InputOrErr); | |||
6226 | else | |||
6227 | return InputOrErr.takeError(); | |||
6228 | } | |||
6229 | ||||
6230 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs() + | |||
6231 | S->getNumLabels()); | |||
6232 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) | |||
6233 | return std::move(Err); | |||
6234 | ||||
6235 | if (Error Err = | |||
6236 | ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) | |||
6237 | return std::move(Err); | |||
6238 | ||||
6239 | if (Error Err = ImportArrayChecked( | |||
6240 | S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs())) | |||
6241 | return std::move(Err); | |||
6242 | ||||
6243 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); | |||
6244 | if (!AsmLocOrErr) | |||
6245 | return AsmLocOrErr.takeError(); | |||
6246 | auto AsmStrOrErr = import(S->getAsmString()); | |||
6247 | if (!AsmStrOrErr) | |||
6248 | return AsmStrOrErr.takeError(); | |||
6249 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); | |||
6250 | if (!RParenLocOrErr) | |||
6251 | return RParenLocOrErr.takeError(); | |||
6252 | ||||
6253 | return new (Importer.getToContext()) GCCAsmStmt( | |||
6254 | Importer.getToContext(), | |||
6255 | *AsmLocOrErr, | |||
6256 | S->isSimple(), | |||
6257 | S->isVolatile(), | |||
6258 | S->getNumOutputs(), | |||
6259 | S->getNumInputs(), | |||
6260 | Names.data(), | |||
6261 | Constraints.data(), | |||
6262 | Exprs.data(), | |||
6263 | *AsmStrOrErr, | |||
6264 | S->getNumClobbers(), | |||
6265 | Clobbers.data(), | |||
6266 | S->getNumLabels(), | |||
6267 | *RParenLocOrErr); | |||
6268 | } | |||
6269 | ||||
6270 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { | |||
6271 | ||||
6272 | Error Err = Error::success(); | |||
6273 | auto ToDG = importChecked(Err, S->getDeclGroup()); | |||
6274 | auto ToBeginLoc = importChecked(Err, S->getBeginLoc()); | |||
6275 | auto ToEndLoc = importChecked(Err, S->getEndLoc()); | |||
6276 | if (Err) | |||
6277 | return std::move(Err); | |||
6278 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); | |||
6279 | } | |||
6280 | ||||
6281 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { | |||
6282 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); | |||
6283 | if (!ToSemiLocOrErr) | |||
6284 | return ToSemiLocOrErr.takeError(); | |||
6285 | return new (Importer.getToContext()) NullStmt( | |||
6286 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); | |||
6287 | } | |||
6288 | ||||
6289 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { | |||
6290 | SmallVector<Stmt *, 8> ToStmts(S->size()); | |||
6291 | ||||
6292 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) | |||
6293 | return std::move(Err); | |||
6294 | ||||
6295 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); | |||
6296 | if (!ToLBracLocOrErr) | |||
6297 | return ToLBracLocOrErr.takeError(); | |||
6298 | ||||
6299 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); | |||
6300 | if (!ToRBracLocOrErr) | |||
6301 | return ToRBracLocOrErr.takeError(); | |||
6302 | ||||
6303 | return CompoundStmt::Create( | |||
6304 | Importer.getToContext(), ToStmts, | |||
6305 | *ToLBracLocOrErr, *ToRBracLocOrErr); | |||
6306 | } | |||
6307 | ||||
6308 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { | |||
6309 | ||||
6310 | Error Err = Error::success(); | |||
6311 | auto ToLHS = importChecked(Err, S->getLHS()); | |||
6312 | auto ToRHS = importChecked(Err, S->getRHS()); | |||
6313 | auto ToSubStmt = importChecked(Err, S->getSubStmt()); | |||
6314 | auto ToCaseLoc = importChecked(Err, S->getCaseLoc()); | |||
6315 | auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc()); | |||
6316 | auto ToColonLoc = importChecked(Err, S->getColonLoc()); | |||
6317 | if (Err) | |||
6318 | return std::move(Err); | |||
6319 | ||||
6320 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, | |||
6321 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); | |||
6322 | ToStmt->setSubStmt(ToSubStmt); | |||
6323 | ||||
6324 | return ToStmt; | |||
6325 | } | |||
6326 | ||||
6327 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { | |||
6328 | ||||
6329 | Error Err = Error::success(); | |||
6330 | auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc()); | |||
6331 | auto ToColonLoc = importChecked(Err, S->getColonLoc()); | |||
6332 | auto ToSubStmt = importChecked(Err, S->getSubStmt()); | |||
6333 | if (Err) | |||
6334 | return std::move(Err); | |||
6335 | ||||
6336 | return new (Importer.getToContext()) DefaultStmt( | |||
6337 | ToDefaultLoc, ToColonLoc, ToSubStmt); | |||
6338 | } | |||
6339 | ||||
6340 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { | |||
6341 | ||||
6342 | Error Err = Error::success(); | |||
6343 | auto ToIdentLoc = importChecked(Err, S->getIdentLoc()); | |||
6344 | auto ToLabelDecl = importChecked(Err, S->getDecl()); | |||
6345 | auto ToSubStmt = importChecked(Err, S->getSubStmt()); | |||
6346 | if (Err) | |||
6347 | return std::move(Err); | |||
6348 | ||||
6349 | return new (Importer.getToContext()) LabelStmt( | |||
6350 | ToIdentLoc, ToLabelDecl, ToSubStmt); | |||
6351 | } | |||
6352 | ||||
6353 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { | |||
6354 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); | |||
6355 | if (!ToAttrLocOrErr) | |||
6356 | return ToAttrLocOrErr.takeError(); | |||
6357 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); | |||
6358 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); | |||
6359 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) | |||
6360 | return std::move(Err); | |||
6361 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); | |||
6362 | if (!ToSubStmtOrErr) | |||
6363 | return ToSubStmtOrErr.takeError(); | |||
6364 | ||||
6365 | return AttributedStmt::Create( | |||
6366 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); | |||
6367 | } | |||
6368 | ||||
6369 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { | |||
6370 | ||||
6371 | Error Err = Error::success(); | |||
6372 | auto ToIfLoc = importChecked(Err, S->getIfLoc()); | |||
6373 | auto ToInit = importChecked(Err, S->getInit()); | |||
6374 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); | |||
6375 | auto ToCond = importChecked(Err, S->getCond()); | |||
6376 | auto ToLParenLoc = importChecked(Err, S->getLParenLoc()); | |||
6377 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | |||
6378 | auto ToThen = importChecked(Err, S->getThen()); | |||
6379 | auto ToElseLoc = importChecked(Err, S->getElseLoc()); | |||
6380 | auto ToElse = importChecked(Err, S->getElse()); | |||
6381 | if (Err) | |||
6382 | return std::move(Err); | |||
6383 | ||||
6384 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(), | |||
6385 | ToInit, ToConditionVariable, ToCond, ToLParenLoc, | |||
6386 | ToRParenLoc, ToThen, ToElseLoc, ToElse); | |||
6387 | } | |||
6388 | ||||
6389 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { | |||
6390 | ||||
6391 | Error Err = Error::success(); | |||
6392 | auto ToInit = importChecked(Err, S->getInit()); | |||
6393 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); | |||
6394 | auto ToCond = importChecked(Err, S->getCond()); | |||
6395 | auto ToLParenLoc = importChecked(Err, S->getLParenLoc()); | |||
6396 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | |||
6397 | auto ToBody = importChecked(Err, S->getBody()); | |||
6398 | auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc()); | |||
6399 | if (Err) | |||
6400 | return std::move(Err); | |||
6401 | ||||
6402 | auto *ToStmt = | |||
6403 | SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable, | |||
6404 | ToCond, ToLParenLoc, ToRParenLoc); | |||
6405 | ToStmt->setBody(ToBody); | |||
6406 | ToStmt->setSwitchLoc(ToSwitchLoc); | |||
6407 | ||||
6408 | // Now we have to re-chain the cases. | |||
6409 | SwitchCase *LastChainedSwitchCase = nullptr; | |||
6410 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; | |||
6411 | SC = SC->getNextSwitchCase()) { | |||
6412 | Expected<SwitchCase *> ToSCOrErr = import(SC); | |||
6413 | if (!ToSCOrErr) | |||
6414 | return ToSCOrErr.takeError(); | |||
6415 | if (LastChainedSwitchCase) | |||
6416 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); | |||
6417 | else | |||
6418 | ToStmt->setSwitchCaseList(*ToSCOrErr); | |||
6419 | LastChainedSwitchCase = *ToSCOrErr; | |||
6420 | } | |||
6421 | ||||
6422 | return ToStmt; | |||
6423 | } | |||
6424 | ||||
6425 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { | |||
6426 | ||||
6427 | Error Err = Error::success(); | |||
6428 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); | |||
6429 | auto ToCond = importChecked(Err, S->getCond()); | |||
6430 | auto ToBody = importChecked(Err, S->getBody()); | |||
6431 | auto ToWhileLoc = importChecked(Err, S->getWhileLoc()); | |||
6432 | auto ToLParenLoc = importChecked(Err, S->getLParenLoc()); | |||
6433 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | |||
6434 | if (Err) | |||
6435 | return std::move(Err); | |||
6436 | ||||
6437 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, | |||
6438 | ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc); | |||
6439 | } | |||
6440 | ||||
6441 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { | |||
6442 | ||||
6443 | Error Err = Error::success(); | |||
6444 | auto ToBody = importChecked(Err, S->getBody()); | |||
6445 | auto ToCond = importChecked(Err, S->getCond()); | |||
6446 | auto ToDoLoc = importChecked(Err, S->getDoLoc()); | |||
6447 | auto ToWhileLoc = importChecked(Err, S->getWhileLoc()); | |||
6448 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | |||
6449 | if (Err) | |||
6450 | return std::move(Err); | |||
6451 | ||||
6452 | return new (Importer.getToContext()) DoStmt( | |||
6453 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); | |||
6454 | } | |||
6455 | ||||
6456 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { | |||
6457 | ||||
6458 | Error Err = Error::success(); | |||
6459 | auto ToInit = importChecked(Err, S->getInit()); | |||
6460 | auto ToCond = importChecked(Err, S->getCond()); | |||
6461 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); | |||
6462 | auto ToInc = importChecked(Err, S->getInc()); | |||
6463 | auto ToBody = importChecked(Err, S->getBody()); | |||
6464 | auto ToForLoc = importChecked(Err, S->getForLoc()); | |||
6465 | auto ToLParenLoc = importChecked(Err, S->getLParenLoc()); | |||
6466 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | |||
6467 | if (Err) | |||
6468 | return std::move(Err); | |||
6469 | ||||
6470 | return new (Importer.getToContext()) ForStmt( | |||
6471 | Importer.getToContext(), | |||
6472 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, | |||
6473 | ToRParenLoc); | |||
6474 | } | |||
6475 | ||||
6476 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { | |||
6477 | ||||
6478 | Error Err = Error::success(); | |||
6479 | auto ToLabel = importChecked(Err, S->getLabel()); | |||
6480 | auto ToGotoLoc = importChecked(Err, S->getGotoLoc()); | |||
6481 | auto ToLabelLoc = importChecked(Err, S->getLabelLoc()); | |||
6482 | if (Err) | |||
6483 | return std::move(Err); | |||
6484 | ||||
6485 | return new (Importer.getToContext()) GotoStmt( | |||
6486 | ToLabel, ToGotoLoc, ToLabelLoc); | |||
6487 | } | |||
6488 | ||||
6489 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { | |||
6490 | ||||
6491 | Error Err = Error::success(); | |||
6492 | auto ToGotoLoc = importChecked(Err, S->getGotoLoc()); | |||
6493 | auto ToStarLoc = importChecked(Err, S->getStarLoc()); | |||
6494 | auto ToTarget = importChecked(Err, S->getTarget()); | |||
6495 | if (Err) | |||
6496 | return std::move(Err); | |||
6497 | ||||
6498 | return new (Importer.getToContext()) IndirectGotoStmt( | |||
6499 | ToGotoLoc, ToStarLoc, ToTarget); | |||
6500 | } | |||
6501 | ||||
6502 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { | |||
6503 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); | |||
6504 | if (!ToContinueLocOrErr) | |||
6505 | return ToContinueLocOrErr.takeError(); | |||
6506 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); | |||
6507 | } | |||
6508 | ||||
6509 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { | |||
6510 | auto ToBreakLocOrErr = import(S->getBreakLoc()); | |||
6511 | if (!ToBreakLocOrErr) | |||
6512 | return ToBreakLocOrErr.takeError(); | |||
6513 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); | |||
6514 | } | |||
6515 | ||||
6516 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { | |||
6517 | ||||
6518 | Error Err = Error::success(); | |||
6519 | auto ToReturnLoc = importChecked(Err, S->getReturnLoc()); | |||
6520 | auto ToRetValue = importChecked(Err, S->getRetValue()); | |||
6521 | auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate()); | |||
6522 | if (Err) | |||
6523 | return std::move(Err); | |||
6524 | ||||
6525 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, | |||
6526 | ToNRVOCandidate); | |||
6527 | } | |||
6528 | ||||
6529 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { | |||
6530 | ||||
6531 | Error Err = Error::success(); | |||
6532 | auto ToCatchLoc = importChecked(Err, S->getCatchLoc()); | |||
6533 | auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl()); | |||
6534 | auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock()); | |||
6535 | if (Err) | |||
6536 | return std::move(Err); | |||
6537 | ||||
6538 | return new (Importer.getToContext()) CXXCatchStmt ( | |||
6539 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); | |||
6540 | } | |||
6541 | ||||
6542 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { | |||
6543 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); | |||
6544 | if (!ToTryLocOrErr) | |||
6545 | return ToTryLocOrErr.takeError(); | |||
6546 | ||||
6547 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); | |||
6548 | if (!ToTryBlockOrErr) | |||
6549 | return ToTryBlockOrErr.takeError(); | |||
6550 | ||||
6551 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); | |||
6552 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { | |||
6553 | CXXCatchStmt *FromHandler = S->getHandler(HI); | |||
6554 | if (auto ToHandlerOrErr = import(FromHandler)) | |||
6555 | ToHandlers[HI] = *ToHandlerOrErr; | |||
6556 | else | |||
6557 | return ToHandlerOrErr.takeError(); | |||
6558 | } | |||
6559 | ||||
6560 | return CXXTryStmt::Create( | |||
6561 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); | |||
6562 | } | |||
6563 | ||||
6564 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { | |||
6565 | ||||
6566 | Error Err = Error::success(); | |||
6567 | auto ToInit = importChecked(Err, S->getInit()); | |||
6568 | auto ToRangeStmt = importChecked(Err, S->getRangeStmt()); | |||
6569 | auto ToBeginStmt = importChecked(Err, S->getBeginStmt()); | |||
6570 | auto ToEndStmt = importChecked(Err, S->getEndStmt()); | |||
6571 | auto ToCond = importChecked(Err, S->getCond()); | |||
6572 | auto ToInc = importChecked(Err, S->getInc()); | |||
6573 | auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt()); | |||
6574 | auto ToBody = importChecked(Err, S->getBody()); | |||
6575 | auto ToForLoc = importChecked(Err, S->getForLoc()); | |||
6576 | auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc()); | |||
6577 | auto ToColonLoc = importChecked(Err, S->getColonLoc()); | |||
6578 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | |||
6579 | if (Err) | |||
6580 | return std::move(Err); | |||
6581 | ||||
6582 | return new (Importer.getToContext()) CXXForRangeStmt( | |||
6583 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, | |||
6584 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); | |||
6585 | } | |||
6586 | ||||
6587 | ExpectedStmt | |||
6588 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { | |||
6589 | Error Err = Error::success(); | |||
6590 | auto ToElement = importChecked(Err, S->getElement()); | |||
6591 | auto ToCollection = importChecked(Err, S->getCollection()); | |||
6592 | auto ToBody = importChecked(Err, S->getBody()); | |||
6593 | auto ToForLoc = importChecked(Err, S->getForLoc()); | |||
6594 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | |||
6595 | if (Err) | |||
6596 | return std::move(Err); | |||
6597 | ||||
6598 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, | |||
6599 | ToCollection, | |||
6600 | ToBody, | |||
6601 | ToForLoc, | |||
6602 | ToRParenLoc); | |||
6603 | } | |||
6604 | ||||
6605 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { | |||
6606 | ||||
6607 | Error Err = Error::success(); | |||
6608 | auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc()); | |||
6609 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | |||
6610 | auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl()); | |||
6611 | auto ToCatchBody = importChecked(Err, S->getCatchBody()); | |||
6612 | if (Err) | |||
6613 | return std::move(Err); | |||
6614 | ||||
6615 | return new (Importer.getToContext()) ObjCAtCatchStmt ( | |||
6616 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); | |||
6617 | } | |||
6618 | ||||
6619 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { | |||
6620 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); | |||
6621 | if (!ToAtFinallyLocOrErr) | |||
6622 | return ToAtFinallyLocOrErr.takeError(); | |||
6623 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); | |||
6624 | if (!ToAtFinallyStmtOrErr) | |||
6625 | return ToAtFinallyStmtOrErr.takeError(); | |||
6626 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, | |||
6627 | *ToAtFinallyStmtOrErr); | |||
6628 | } | |||
6629 | ||||
6630 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { | |||
6631 | ||||
6632 | Error Err = Error::success(); | |||
6633 | auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc()); | |||
6634 | auto ToTryBody = importChecked(Err, S->getTryBody()); | |||
6635 | auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt()); | |||
6636 | if (Err) | |||
6637 | return std::move(Err); | |||
6638 | ||||
6639 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); | |||
6640 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { | |||
6641 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); | |||
6642 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) | |||
6643 | ToCatchStmts[CI] = *ToCatchStmtOrErr; | |||
6644 | else | |||
6645 | return ToCatchStmtOrErr.takeError(); | |||
6646 | } | |||
6647 | ||||
6648 | return ObjCAtTryStmt::Create(Importer.getToContext(), | |||
6649 | ToAtTryLoc, ToTryBody, | |||
6650 | ToCatchStmts.begin(), ToCatchStmts.size(), | |||
6651 | ToFinallyStmt); | |||
6652 | } | |||
6653 | ||||
6654 | ExpectedStmt | |||
6655 | ASTNodeImporter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { | |||
6656 | ||||
6657 | Error Err = Error::success(); | |||
6658 | auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc()); | |||
6659 | auto ToSynchExpr = importChecked(Err, S->getSynchExpr()); | |||
6660 | auto ToSynchBody = importChecked(Err, S->getSynchBody()); | |||
6661 | if (Err) | |||
6662 | return std::move(Err); | |||
6663 | ||||
6664 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( | |||
6665 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); | |||
6666 | } | |||
6667 | ||||
6668 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { | |||
6669 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); | |||
6670 | if (!ToThrowLocOrErr) | |||
6671 | return ToThrowLocOrErr.takeError(); | |||
6672 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); | |||
6673 | if (!ToThrowExprOrErr) | |||
6674 | return ToThrowExprOrErr.takeError(); | |||
6675 | return new (Importer.getToContext()) ObjCAtThrowStmt( | |||
6676 | *ToThrowLocOrErr, *ToThrowExprOrErr); | |||
6677 | } | |||
6678 | ||||
6679 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( | |||
6680 | ObjCAutoreleasePoolStmt *S) { | |||
6681 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); | |||
6682 | if (!ToAtLocOrErr) | |||
6683 | return ToAtLocOrErr.takeError(); | |||
6684 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); | |||
6685 | if (!ToSubStmtOrErr) | |||
6686 | return ToSubStmtOrErr.takeError(); | |||
6687 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, | |||
6688 | *ToSubStmtOrErr); | |||
6689 | } | |||
6690 | ||||
6691 | //---------------------------------------------------------------------------- | |||
6692 | // Import Expressions | |||
6693 | //---------------------------------------------------------------------------- | |||
6694 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { | |||
6695 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) | |||
6696 | << E->getStmtClassName(); | |||
6697 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
6698 | } | |||
6699 | ||||
6700 | ExpectedStmt ASTNodeImporter::VisitSourceLocExpr(SourceLocExpr *E) { | |||
6701 | Error Err = Error::success(); | |||
6702 | auto ToType = importChecked(Err, E->getType()); | |||
6703 | auto BLoc = importChecked(Err, E->getBeginLoc()); | |||
6704 | auto RParenLoc = importChecked(Err, E->getEndLoc()); | |||
6705 | if (Err) | |||
6706 | return std::move(Err); | |||
6707 | auto ParentContextOrErr = Importer.ImportContext(E->getParentContext()); | |||
6708 | if (!ParentContextOrErr) | |||
6709 | return ParentContextOrErr.takeError(); | |||
6710 | ||||
6711 | return new (Importer.getToContext()) | |||
6712 | SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc, | |||
6713 | RParenLoc, *ParentContextOrErr); | |||
6714 | } | |||
6715 | ||||
6716 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { | |||
6717 | ||||
6718 | Error Err = Error::success(); | |||
6719 | auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); | |||
6720 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | |||
6721 | auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo()); | |||
6722 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | |||
6723 | auto ToType = importChecked(Err, E->getType()); | |||
6724 | if (Err) | |||
6725 | return std::move(Err); | |||
6726 | ||||
6727 | return new (Importer.getToContext()) VAArgExpr( | |||
6728 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, | |||
6729 | E->isMicrosoftABI()); | |||
6730 | } | |||
6731 | ||||
6732 | ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) { | |||
6733 | ||||
6734 | Error Err = Error::success(); | |||
6735 | auto ToCond = importChecked(Err, E->getCond()); | |||
6736 | auto ToLHS = importChecked(Err, E->getLHS()); | |||
6737 | auto ToRHS = importChecked(Err, E->getRHS()); | |||
6738 | auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); | |||
6739 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | |||
6740 | auto ToType = importChecked(Err, E->getType()); | |||
6741 | if (Err) | |||
6742 | return std::move(Err); | |||
6743 | ||||
6744 | ExprValueKind VK = E->getValueKind(); | |||
6745 | ExprObjectKind OK = E->getObjectKind(); | |||
6746 | ||||
6747 | // The value of CondIsTrue only matters if the value is not | |||
6748 | // condition-dependent. | |||
6749 | bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue(); | |||
6750 | ||||
6751 | return new (Importer.getToContext()) | |||
6752 | ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK, | |||
6753 | ToRParenLoc, CondIsTrue); | |||
6754 | } | |||
6755 | ||||
6756 | ExpectedStmt ASTNodeImporter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) { | |||
6757 | Error Err = Error::success(); | |||
6758 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | |||
6759 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); | |||
6760 | auto ToType = importChecked(Err, E->getType()); | |||
6761 | const unsigned NumSubExprs = E->getNumSubExprs(); | |||
6762 | ||||
6763 | llvm::SmallVector<Expr *, 8> ToSubExprs; | |||
6764 | llvm::ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs); | |||
6765 | ToSubExprs.resize(NumSubExprs); | |||
6766 | ||||
6767 | if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs))) | |||
6768 | return std::move(Err); | |||
6769 | ||||
6770 | return new (Importer.getToContext()) ShuffleVectorExpr( | |||
6771 | Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc); | |||
6772 | } | |||
6773 | ||||
6774 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { | |||
6775 | ExpectedType TypeOrErr = import(E->getType()); | |||
6776 | if (!TypeOrErr) | |||
6777 | return TypeOrErr.takeError(); | |||
6778 | ||||
6779 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); | |||
6780 | if (!BeginLocOrErr) | |||
6781 | return BeginLocOrErr.takeError(); | |||
6782 | ||||
6783 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); | |||
6784 | } | |||
6785 | ||||
6786 | ExpectedStmt | |||
6787 | ASTNodeImporter::VisitGenericSelectionExpr(GenericSelectionExpr *E) { | |||
6788 | Error Err = Error::success(); | |||
6789 | auto ToGenericLoc = importChecked(Err, E->getGenericLoc()); | |||
6790 | auto *ToControllingExpr = importChecked(Err, E->getControllingExpr()); | |||
6791 | auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc()); | |||
6792 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | |||
6793 | if (Err) | |||
6794 | return std::move(Err); | |||
6795 | ||||
6796 | ArrayRef<const TypeSourceInfo *> FromAssocTypes(E->getAssocTypeSourceInfos()); | |||
6797 | SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size()); | |||
6798 | if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes)) | |||
6799 | return std::move(Err); | |||
6800 | ||||
6801 | ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs()); | |||
6802 | SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size()); | |||
6803 | if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs)) | |||
6804 | return std::move(Err); | |||
6805 | ||||
6806 | const ASTContext &ToCtx = Importer.getToContext(); | |||
6807 | if (E->isResultDependent()) { | |||
6808 | return GenericSelectionExpr::Create( | |||
6809 | ToCtx, ToGenericLoc, ToControllingExpr, | |||
6810 | llvm::makeArrayRef(ToAssocTypes), llvm::makeArrayRef(ToAssocExprs), | |||
6811 | ToDefaultLoc, ToRParenLoc, E->containsUnexpandedParameterPack()); | |||
6812 | } | |||
6813 | ||||
6814 | return GenericSelectionExpr::Create( | |||
6815 | ToCtx, ToGenericLoc, ToControllingExpr, llvm::makeArrayRef(ToAssocTypes), | |||
6816 | llvm::makeArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc, | |||
6817 | E->containsUnexpandedParameterPack(), E->getResultIndex()); | |||
6818 | } | |||
6819 | ||||
6820 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { | |||
6821 | ||||
6822 | Error Err = Error::success(); | |||
6823 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); | |||
6824 | auto ToType = importChecked(Err, E->getType()); | |||
6825 | auto ToFunctionName = importChecked(Err, E->getFunctionName()); | |||
6826 | if (Err) | |||
6827 | return std::move(Err); | |||
6828 | ||||
6829 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, | |||
6830 | E->getIdentKind(), ToFunctionName); | |||
6831 | } | |||
6832 | ||||
6833 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { | |||
6834 | ||||
6835 | Error Err = Error::success(); | |||
6836 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); | |||
6837 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); | |||
6838 | auto ToDecl = importChecked(Err, E->getDecl()); | |||
6839 | auto ToLocation = importChecked(Err, E->getLocation()); | |||
6840 | auto ToType = importChecked(Err, E->getType()); | |||
6841 | if (Err) | |||
6842 | return std::move(Err); | |||
6843 | ||||
6844 | NamedDecl *ToFoundD = nullptr; | |||
6845 | if (E->getDecl() != E->getFoundDecl()) { | |||
6846 | auto FoundDOrErr = import(E->getFoundDecl()); | |||
6847 | if (!FoundDOrErr) | |||
6848 | return FoundDOrErr.takeError(); | |||
6849 | ToFoundD = *FoundDOrErr; | |||
6850 | } | |||
6851 | ||||
6852 | TemplateArgumentListInfo ToTAInfo; | |||
6853 | TemplateArgumentListInfo *ToResInfo = nullptr; | |||
6854 | if (E->hasExplicitTemplateArgs()) { | |||
6855 | if (Error Err = | |||
6856 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), | |||
6857 | E->template_arguments(), ToTAInfo)) | |||
6858 | return std::move(Err); | |||
6859 | ToResInfo = &ToTAInfo; | |||
6860 | } | |||
6861 | ||||
6862 | auto *ToE = DeclRefExpr::Create( | |||
6863 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, | |||
6864 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, | |||
6865 | E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse()); | |||
6866 | if (E->hadMultipleCandidates()) | |||
6867 | ToE->setHadMultipleCandidates(true); | |||
6868 | return ToE; | |||
6869 | } | |||
6870 | ||||
6871 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { | |||
6872 | ExpectedType TypeOrErr = import(E->getType()); | |||
6873 | if (!TypeOrErr) | |||
6874 | return TypeOrErr.takeError(); | |||
6875 | ||||
6876 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); | |||
6877 | } | |||
6878 | ||||
6879 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { | |||
6880 | ExpectedExpr ToInitOrErr = import(E->getInit()); | |||
6881 | if (!ToInitOrErr) | |||
6882 | return ToInitOrErr.takeError(); | |||
6883 | ||||
6884 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); | |||
6885 | if (!ToEqualOrColonLocOrErr) | |||
6886 | return ToEqualOrColonLocOrErr.takeError(); | |||
6887 | ||||
6888 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); | |||
6889 | // List elements from the second, the first is Init itself | |||
6890 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { | |||
6891 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) | |||
6892 | ToIndexExprs[I - 1] = *ToArgOrErr; | |||
6893 | else | |||
6894 | return ToArgOrErr.takeError(); | |||
6895 | } | |||
6896 | ||||
6897 | SmallVector<Designator, 4> ToDesignators(E->size()); | |||
6898 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) | |||
6899 | return std::move(Err); | |||
6900 | ||||
6901 | return DesignatedInitExpr::Create( | |||
6902 | Importer.getToContext(), ToDesignators, | |||
6903 | ToIndexExprs, *ToEqualOrColonLocOrErr, | |||
6904 | E->usesGNUSyntax(), *ToInitOrErr); | |||
6905 | } | |||
6906 | ||||
6907 | ExpectedStmt | |||
6908 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { | |||
6909 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
6910 | if (!ToTypeOrErr) | |||
6911 | return ToTypeOrErr.takeError(); | |||
6912 | ||||
6913 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | |||
6914 | if (!ToLocationOrErr) | |||
6915 | return ToLocationOrErr.takeError(); | |||
6916 | ||||
6917 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( | |||
6918 | *ToTypeOrErr, *ToLocationOrErr); | |||
6919 | } | |||
6920 | ||||
6921 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { | |||
6922 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
6923 | if (!ToTypeOrErr) | |||
6924 | return ToTypeOrErr.takeError(); | |||
6925 | ||||
6926 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | |||
6927 | if (!ToLocationOrErr) | |||
6928 | return ToLocationOrErr.takeError(); | |||
6929 | ||||
6930 | return IntegerLiteral::Create( | |||
6931 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); | |||
6932 | } | |||
6933 | ||||
6934 | ||||
6935 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { | |||
6936 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
6937 | if (!ToTypeOrErr) | |||
6938 | return ToTypeOrErr.takeError(); | |||
6939 | ||||
6940 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | |||
6941 | if (!ToLocationOrErr) | |||
6942 | return ToLocationOrErr.takeError(); | |||
6943 | ||||
6944 | return FloatingLiteral::Create( | |||
6945 | Importer.getToContext(), E->getValue(), E->isExact(), | |||
6946 | *ToTypeOrErr, *ToLocationOrErr); | |||
6947 | } | |||
6948 | ||||
6949 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { | |||
6950 | auto ToTypeOrErr = import(E->getType()); | |||
6951 | if (!ToTypeOrErr) | |||
6952 | return ToTypeOrErr.takeError(); | |||
6953 | ||||
6954 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | |||
6955 | if (!ToSubExprOrErr) | |||
6956 | return ToSubExprOrErr.takeError(); | |||
6957 | ||||
6958 | return new (Importer.getToContext()) ImaginaryLiteral( | |||
6959 | *ToSubExprOrErr, *ToTypeOrErr); | |||
6960 | } | |||
6961 | ||||
6962 | ExpectedStmt ASTNodeImporter::VisitFixedPointLiteral(FixedPointLiteral *E) { | |||
6963 | auto ToTypeOrErr = import(E->getType()); | |||
6964 | if (!ToTypeOrErr) | |||
6965 | return ToTypeOrErr.takeError(); | |||
6966 | ||||
6967 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | |||
6968 | if (!ToLocationOrErr) | |||
6969 | return ToLocationOrErr.takeError(); | |||
6970 | ||||
6971 | return new (Importer.getToContext()) FixedPointLiteral( | |||
6972 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr, | |||
6973 | Importer.getToContext().getFixedPointScale(*ToTypeOrErr)); | |||
6974 | } | |||
6975 | ||||
6976 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { | |||
6977 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
6978 | if (!ToTypeOrErr) | |||
6979 | return ToTypeOrErr.takeError(); | |||
6980 | ||||
6981 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | |||
6982 | if (!ToLocationOrErr) | |||
6983 | return ToLocationOrErr.takeError(); | |||
6984 | ||||
6985 | return new (Importer.getToContext()) CharacterLiteral( | |||
6986 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); | |||
6987 | } | |||
6988 | ||||
6989 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { | |||
6990 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
6991 | if (!ToTypeOrErr) | |||
6992 | return ToTypeOrErr.takeError(); | |||
6993 | ||||
6994 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); | |||
6995 | if (Error Err = ImportArrayChecked( | |||
6996 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) | |||
6997 | return std::move(Err); | |||
6998 | ||||
6999 | return StringLiteral::Create( | |||
7000 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), | |||
7001 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); | |||
7002 | } | |||
7003 | ||||
7004 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { | |||
7005 | ||||
7006 | Error Err = Error::success(); | |||
7007 | auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); | |||
7008 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); | |||
7009 | auto ToType = importChecked(Err, E->getType()); | |||
7010 | auto ToInitializer = importChecked(Err, E->getInitializer()); | |||
7011 | if (Err) | |||
7012 | return std::move(Err); | |||
7013 | ||||
7014 | return new (Importer.getToContext()) CompoundLiteralExpr( | |||
7015 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), | |||
7016 | ToInitializer, E->isFileScope()); | |||
7017 | } | |||
7018 | ||||
7019 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { | |||
7020 | ||||
7021 | Error Err = Error::success(); | |||
7022 | auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); | |||
7023 | auto ToType = importChecked(Err, E->getType()); | |||
7024 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | |||
7025 | if (Err) | |||
7026 | return std::move(Err); | |||
7027 | ||||
7028 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); | |||
7029 | if (Error Err = ImportArrayChecked( | |||
7030 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), | |||
7031 | ToExprs.begin())) | |||
7032 | return std::move(Err); | |||
7033 | ||||
7034 | return new (Importer.getToContext()) AtomicExpr( | |||
7035 | ||||
7036 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); | |||
7037 | } | |||
7038 | ||||
7039 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { | |||
7040 | Error Err = Error::success(); | |||
7041 | auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc()); | |||
7042 | auto ToLabelLoc = importChecked(Err, E->getLabelLoc()); | |||
7043 | auto ToLabel = importChecked(Err, E->getLabel()); | |||
7044 | auto ToType = importChecked(Err, E->getType()); | |||
7045 | if (Err) | |||
7046 | return std::move(Err); | |||
7047 | ||||
7048 | return new (Importer.getToContext()) AddrLabelExpr( | |||
7049 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); | |||
7050 | } | |||
7051 | ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { | |||
7052 | Error Err = Error::success(); | |||
7053 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | |||
7054 | auto ToResult = importChecked(Err, E->getAPValueResult()); | |||
7055 | if (Err) | |||
7056 | return std::move(Err); | |||
7057 | ||||
7058 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult); | |||
7059 | } | |||
7060 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { | |||
7061 | Error Err = Error::success(); | |||
7062 | auto ToLParen = importChecked(Err, E->getLParen()); | |||
7063 | auto ToRParen = importChecked(Err, E->getRParen()); | |||
7064 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | |||
7065 | if (Err) | |||
7066 | return std::move(Err); | |||
7067 | ||||
7068 | return new (Importer.getToContext()) | |||
7069 | ParenExpr(ToLParen, ToRParen, ToSubExpr); | |||
7070 | } | |||
7071 | ||||
7072 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { | |||
7073 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); | |||
7074 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) | |||
7075 | return std::move(Err); | |||
7076 | ||||
7077 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); | |||
7078 | if (!ToLParenLocOrErr) | |||
7079 | return ToLParenLocOrErr.takeError(); | |||
7080 | ||||
7081 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); | |||
7082 | if (!ToRParenLocOrErr) | |||
7083 | return ToRParenLocOrErr.takeError(); | |||
7084 | ||||
7085 | return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr, | |||
7086 | ToExprs, *ToRParenLocOrErr); | |||
7087 | } | |||
7088 | ||||
7089 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { | |||
7090 | Error Err = Error::success(); | |||
7091 | auto ToSubStmt = importChecked(Err, E->getSubStmt()); | |||
7092 | auto ToType = importChecked(Err, E->getType()); | |||
7093 | auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); | |||
7094 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | |||
7095 | if (Err) | |||
7096 | return std::move(Err); | |||
7097 | ||||
7098 | return new (Importer.getToContext()) | |||
7099 | StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc, | |||
7100 | E->getTemplateDepth()); | |||
7101 | } | |||
7102 | ||||
7103 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { | |||
7104 | Error Err = Error::success(); | |||
7105 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | |||
7106 | auto ToType = importChecked(Err, E->getType()); | |||
7107 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | |||
7108 | if (Err) | |||
7109 | return std::move(Err); | |||
7110 | ||||
7111 | return UnaryOperator::Create( | |||
7112 | Importer.getToContext(), ToSubExpr, E->getOpcode(), ToType, | |||
7113 | E->getValueKind(), E->getObjectKind(), ToOperatorLoc, E->canOverflow(), | |||
7114 | E->getFPOptionsOverride()); | |||
7115 | } | |||
7116 | ||||
7117 | ExpectedStmt | |||
7118 | ||||
7119 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { | |||
7120 | Error Err = Error::success(); | |||
7121 | auto ToType = importChecked(Err, E->getType()); | |||
7122 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | |||
7123 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | |||
7124 | if (Err) | |||
7125 | return std::move(Err); | |||
7126 | ||||
7127 | if (E->isArgumentType()) { | |||
7128 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = | |||
7129 | import(E->getArgumentTypeInfo()); | |||
7130 | if (!ToArgumentTypeInfoOrErr) | |||
7131 | return ToArgumentTypeInfoOrErr.takeError(); | |||
7132 | ||||
7133 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( | |||
7134 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, | |||
7135 | ToRParenLoc); | |||
7136 | } | |||
7137 | ||||
7138 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); | |||
7139 | if (!ToArgumentExprOrErr) | |||
7140 | return ToArgumentExprOrErr.takeError(); | |||
7141 | ||||
7142 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( | |||
7143 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); | |||
7144 | } | |||
7145 | ||||
7146 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { | |||
7147 | Error Err = Error::success(); | |||
7148 | auto ToLHS = importChecked(Err, E->getLHS()); | |||
7149 | auto ToRHS = importChecked(Err, E->getRHS()); | |||
7150 | auto ToType = importChecked(Err, E->getType()); | |||
7151 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | |||
7152 | if (Err) | |||
7153 | return std::move(Err); | |||
7154 | ||||
7155 | return BinaryOperator::Create( | |||
7156 | Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType, | |||
7157 | E->getValueKind(), E->getObjectKind(), ToOperatorLoc, | |||
7158 | E->getFPFeatures(Importer.getFromContext().getLangOpts())); | |||
7159 | } | |||
7160 | ||||
7161 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { | |||
7162 | Error Err = Error::success(); | |||
7163 | auto ToCond = importChecked(Err, E->getCond()); | |||
7164 | auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc()); | |||
7165 | auto ToLHS = importChecked(Err, E->getLHS()); | |||
7166 | auto ToColonLoc = importChecked(Err, E->getColonLoc()); | |||
7167 | auto ToRHS = importChecked(Err, E->getRHS()); | |||
7168 | auto ToType = importChecked(Err, E->getType()); | |||
7169 | if (Err) | |||
7170 | return std::move(Err); | |||
7171 | ||||
7172 | return new (Importer.getToContext()) ConditionalOperator( | |||
7173 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, | |||
7174 | E->getValueKind(), E->getObjectKind()); | |||
7175 | } | |||
7176 | ||||
7177 | ExpectedStmt | |||
7178 | ASTNodeImporter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) { | |||
7179 | Error Err = Error::success(); | |||
7180 | auto ToCommon = importChecked(Err, E->getCommon()); | |||
7181 | auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue()); | |||
7182 | auto ToCond = importChecked(Err, E->getCond()); | |||
7183 | auto ToTrueExpr = importChecked(Err, E->getTrueExpr()); | |||
7184 | auto ToFalseExpr = importChecked(Err, E->getFalseExpr()); | |||
7185 | auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc()); | |||
7186 | auto ToColonLoc = importChecked(Err, E->getColonLoc()); | |||
7187 | auto ToType = importChecked(Err, E->getType()); | |||
7188 | if (Err) | |||
7189 | return std::move(Err); | |||
7190 | ||||
7191 | return new (Importer.getToContext()) BinaryConditionalOperator( | |||
7192 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, | |||
7193 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), | |||
7194 | E->getObjectKind()); | |||
7195 | } | |||
7196 | ||||
7197 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { | |||
7198 | Error Err = Error::success(); | |||
7199 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); | |||
7200 | auto ToQueriedTypeSourceInfo = | |||
7201 | importChecked(Err, E->getQueriedTypeSourceInfo()); | |||
7202 | auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression()); | |||
7203 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); | |||
7204 | auto ToType = importChecked(Err, E->getType()); | |||
7205 | if (Err) | |||
7206 | return std::move(Err); | |||
7207 | ||||
7208 | return new (Importer.getToContext()) ArrayTypeTraitExpr( | |||
7209 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), | |||
7210 | ToDimensionExpression, ToEndLoc, ToType); | |||
7211 | } | |||
7212 | ||||
7213 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { | |||
7214 | Error Err = Error::success(); | |||
7215 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); | |||
7216 | auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression()); | |||
7217 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); | |||
7218 | auto ToType = importChecked(Err, E->getType()); | |||
7219 | if (Err) | |||
7220 | return std::move(Err); | |||
7221 | ||||
7222 | return new (Importer.getToContext()) ExpressionTraitExpr( | |||
7223 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), | |||
7224 | ToEndLoc, ToType); | |||
7225 | } | |||
7226 | ||||
7227 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { | |||
7228 | Error Err = Error::success(); | |||
7229 | auto ToLocation = importChecked(Err, E->getLocation()); | |||
7230 | auto ToType = importChecked(Err, E->getType()); | |||
7231 | auto ToSourceExpr = importChecked(Err, E->getSourceExpr()); | |||
7232 | if (Err) | |||
7233 | return std::move(Err); | |||
7234 | ||||
7235 | return new (Importer.getToContext()) OpaqueValueExpr( | |||
7236 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); | |||
7237 | } | |||
7238 | ||||
7239 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { | |||
7240 | Error Err = Error::success(); | |||
7241 | auto ToLHS = importChecked(Err, E->getLHS()); | |||
7242 | auto ToRHS = importChecked(Err, E->getRHS()); | |||
7243 | auto ToType = importChecked(Err, E->getType()); | |||
7244 | auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc()); | |||
7245 | if (Err) | |||
7246 | return std::move(Err); | |||
7247 | ||||
7248 | return new (Importer.getToContext()) ArraySubscriptExpr( | |||
7249 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), | |||
7250 | ToRBracketLoc); | |||
7251 | } | |||
7252 | ||||
7253 | ExpectedStmt | |||
7254 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { | |||
7255 | Error Err = Error::success(); | |||
7256 | auto ToLHS = importChecked(Err, E->getLHS()); | |||
7257 | auto ToRHS = importChecked(Err, E->getRHS()); | |||
7258 | auto ToType = importChecked(Err, E->getType()); | |||
7259 | auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType()); | |||
7260 | auto ToComputationResultType = | |||
7261 | importChecked(Err, E->getComputationResultType()); | |||
7262 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | |||
7263 | if (Err) | |||
7264 | return std::move(Err); | |||
7265 | ||||
7266 | return CompoundAssignOperator::Create( | |||
7267 | Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType, | |||
7268 | E->getValueKind(), E->getObjectKind(), ToOperatorLoc, | |||
7269 | E->getFPFeatures(Importer.getFromContext().getLangOpts()), | |||
7270 | ToComputationLHSType, ToComputationResultType); | |||
7271 | } | |||
7272 | ||||
7273 | Expected<CXXCastPath> | |||
7274 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { | |||
7275 | CXXCastPath Path; | |||
7276 | for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) { | |||
7277 | if (auto SpecOrErr = import(*I)) | |||
7278 | Path.push_back(*SpecOrErr); | |||
7279 | else | |||
7280 | return SpecOrErr.takeError(); | |||
7281 | } | |||
7282 | return Path; | |||
7283 | } | |||
7284 | ||||
7285 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { | |||
7286 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
7287 | if (!ToTypeOrErr) | |||
7288 | return ToTypeOrErr.takeError(); | |||
7289 | ||||
7290 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | |||
7291 | if (!ToSubExprOrErr) | |||
7292 | return ToSubExprOrErr.takeError(); | |||
7293 | ||||
7294 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); | |||
7295 | if (!ToBasePathOrErr) | |||
7296 | return ToBasePathOrErr.takeError(); | |||
7297 | ||||
7298 | return ImplicitCastExpr::Create( | |||
7299 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, | |||
7300 | &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures()); | |||
7301 | } | |||
7302 | ||||
7303 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { | |||
7304 | Error Err = Error::success(); | |||
7305 | auto ToType = importChecked(Err, E->getType()); | |||
7306 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | |||
7307 | auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten()); | |||
7308 | if (Err) | |||
7309 | return std::move(Err); | |||
7310 | ||||
7311 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); | |||
7312 | if (!ToBasePathOrErr) | |||
7313 | return ToBasePathOrErr.takeError(); | |||
7314 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); | |||
7315 | ||||
7316 | switch (E->getStmtClass()) { | |||
7317 | case Stmt::CStyleCastExprClass: { | |||
7318 | auto *CCE = cast<CStyleCastExpr>(E); | |||
7319 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); | |||
7320 | if (!ToLParenLocOrErr) | |||
7321 | return ToLParenLocOrErr.takeError(); | |||
7322 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); | |||
7323 | if (!ToRParenLocOrErr) | |||
7324 | return ToRParenLocOrErr.takeError(); | |||
7325 | return CStyleCastExpr::Create( | |||
7326 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), | |||
7327 | ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten, | |||
7328 | *ToLParenLocOrErr, *ToRParenLocOrErr); | |||
7329 | } | |||
7330 | ||||
7331 | case Stmt::CXXFunctionalCastExprClass: { | |||
7332 | auto *FCE = cast<CXXFunctionalCastExpr>(E); | |||
7333 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); | |||
7334 | if (!ToLParenLocOrErr) | |||
7335 | return ToLParenLocOrErr.takeError(); | |||
7336 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); | |||
7337 | if (!ToRParenLocOrErr) | |||
7338 | return ToRParenLocOrErr.takeError(); | |||
7339 | return CXXFunctionalCastExpr::Create( | |||
7340 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, | |||
7341 | E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(), | |||
7342 | *ToLParenLocOrErr, *ToRParenLocOrErr); | |||
7343 | } | |||
7344 | ||||
7345 | case Stmt::ObjCBridgedCastExprClass: { | |||
7346 | auto *OCE = cast<ObjCBridgedCastExpr>(E); | |||
7347 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); | |||
7348 | if (!ToLParenLocOrErr) | |||
7349 | return ToLParenLocOrErr.takeError(); | |||
7350 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); | |||
7351 | if (!ToBridgeKeywordLocOrErr) | |||
7352 | return ToBridgeKeywordLocOrErr.takeError(); | |||
7353 | return new (Importer.getToContext()) ObjCBridgedCastExpr( | |||
7354 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), | |||
7355 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); | |||
7356 | } | |||
7357 | default: | |||
7358 | llvm_unreachable("Cast expression of unsupported type!")::llvm::llvm_unreachable_internal("Cast expression of unsupported type!" , "clang/lib/AST/ASTImporter.cpp", 7358); | |||
7359 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
7360 | } | |||
7361 | } | |||
7362 | ||||
7363 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { | |||
7364 | SmallVector<OffsetOfNode, 4> ToNodes; | |||
7365 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { | |||
7366 | const OffsetOfNode &FromNode = E->getComponent(I); | |||
7367 | ||||
7368 | SourceLocation ToBeginLoc, ToEndLoc; | |||
7369 | ||||
7370 | if (FromNode.getKind() != OffsetOfNode::Base) { | |||
7371 | Error Err = Error::success(); | |||
7372 | ToBeginLoc = importChecked(Err, FromNode.getBeginLoc()); | |||
7373 | ToEndLoc = importChecked(Err, FromNode.getEndLoc()); | |||
7374 | if (Err) | |||
7375 | return std::move(Err); | |||
7376 | } | |||
7377 | ||||
7378 | switch (FromNode.getKind()) { | |||
7379 | case OffsetOfNode::Array: | |||
7380 | ToNodes.push_back( | |||
7381 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); | |||
7382 | break; | |||
7383 | case OffsetOfNode::Base: { | |||
7384 | auto ToBSOrErr = import(FromNode.getBase()); | |||
7385 | if (!ToBSOrErr) | |||
7386 | return ToBSOrErr.takeError(); | |||
7387 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); | |||
7388 | break; | |||
7389 | } | |||
7390 | case OffsetOfNode::Field: { | |||
7391 | auto ToFieldOrErr = import(FromNode.getField()); | |||
7392 | if (!ToFieldOrErr) | |||
7393 | return ToFieldOrErr.takeError(); | |||
7394 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); | |||
7395 | break; | |||
7396 | } | |||
7397 | case OffsetOfNode::Identifier: { | |||
7398 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); | |||
7399 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); | |||
7400 | break; | |||
7401 | } | |||
7402 | } | |||
7403 | } | |||
7404 | ||||
7405 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); | |||
7406 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { | |||
7407 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); | |||
7408 | if (!ToIndexExprOrErr) | |||
7409 | return ToIndexExprOrErr.takeError(); | |||
7410 | ToExprs[I] = *ToIndexExprOrErr; | |||
7411 | } | |||
7412 | ||||
7413 | Error Err = Error::success(); | |||
7414 | auto ToType = importChecked(Err, E->getType()); | |||
7415 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); | |||
7416 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | |||
7417 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | |||
7418 | if (Err) | |||
7419 | return std::move(Err); | |||
7420 | ||||
7421 | return OffsetOfExpr::Create( | |||
7422 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, | |||
7423 | ToExprs, ToRParenLoc); | |||
7424 | } | |||
7425 | ||||
7426 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { | |||
7427 | Error Err = Error::success(); | |||
7428 | auto ToType = importChecked(Err, E->getType()); | |||
7429 | auto ToOperand = importChecked(Err, E->getOperand()); | |||
7430 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); | |||
7431 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); | |||
7432 | if (Err) | |||
7433 | return std::move(Err); | |||
7434 | ||||
7435 | CanThrowResult ToCanThrow; | |||
7436 | if (E->isValueDependent()) | |||
7437 | ToCanThrow = CT_Dependent; | |||
7438 | else | |||
7439 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; | |||
7440 | ||||
7441 | return new (Importer.getToContext()) CXXNoexceptExpr( | |||
7442 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); | |||
7443 | } | |||
7444 | ||||
7445 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { | |||
7446 | Error Err = Error::success(); | |||
7447 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | |||
7448 | auto ToType = importChecked(Err, E->getType()); | |||
7449 | auto ToThrowLoc = importChecked(Err, E->getThrowLoc()); | |||
7450 | if (Err) | |||
7451 | return std::move(Err); | |||
7452 | ||||
7453 | return new (Importer.getToContext()) CXXThrowExpr( | |||
7454 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); | |||
7455 | } | |||
7456 | ||||
7457 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { | |||
7458 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); | |||
7459 | if (!ToUsedLocOrErr) | |||
7460 | return ToUsedLocOrErr.takeError(); | |||
7461 | ||||
7462 | auto ToParamOrErr = import(E->getParam()); | |||
7463 | if (!ToParamOrErr) | |||
7464 | return ToParamOrErr.takeError(); | |||
7465 | ||||
7466 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); | |||
7467 | if (!UsedContextOrErr) | |||
7468 | return UsedContextOrErr.takeError(); | |||
7469 | ||||
7470 | // Import the default arg if it was not imported yet. | |||
7471 | // This is needed because it can happen that during the import of the | |||
7472 | // default expression (from VisitParmVarDecl) the same ParmVarDecl is | |||
7473 | // encountered here. The default argument for a ParmVarDecl is set in the | |||
7474 | // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here, | |||
7475 | // see VisitParmVarDecl). | |||
7476 | ParmVarDecl *ToParam = *ToParamOrErr; | |||
7477 | if (!ToParam->getDefaultArg()) { | |||
7478 | Optional<ParmVarDecl *> FromParam = Importer.getImportedFromDecl(ToParam); | |||
7479 | assert(FromParam && "ParmVarDecl was not imported?")(static_cast <bool> (FromParam && "ParmVarDecl was not imported?" ) ? void (0) : __assert_fail ("FromParam && \"ParmVarDecl was not imported?\"" , "clang/lib/AST/ASTImporter.cpp", 7479, __extension__ __PRETTY_FUNCTION__ )); | |||
7480 | ||||
7481 | if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam)) | |||
7482 | return std::move(Err); | |||
7483 | } | |||
7484 | ||||
7485 | return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr, | |||
7486 | *ToParamOrErr, *UsedContextOrErr); | |||
7487 | } | |||
7488 | ||||
7489 | ExpectedStmt | |||
7490 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { | |||
7491 | Error Err = Error::success(); | |||
7492 | auto ToType = importChecked(Err, E->getType()); | |||
7493 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); | |||
7494 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | |||
7495 | if (Err) | |||
7496 | return std::move(Err); | |||
7497 | ||||
7498 | return new (Importer.getToContext()) CXXScalarValueInitExpr( | |||
7499 | ToType, ToTypeSourceInfo, ToRParenLoc); | |||
7500 | } | |||
7501 | ||||
7502 | ExpectedStmt | |||
7503 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { | |||
7504 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | |||
7505 | if (!ToSubExprOrErr) | |||
7506 | return ToSubExprOrErr.takeError(); | |||
7507 | ||||
7508 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); | |||
7509 | if (!ToDtorOrErr) | |||
7510 | return ToDtorOrErr.takeError(); | |||
7511 | ||||
7512 | ASTContext &ToCtx = Importer.getToContext(); | |||
7513 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); | |||
7514 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); | |||
7515 | } | |||
7516 | ||||
7517 | ExpectedStmt | |||
7518 | ||||
7519 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { | |||
7520 | Error Err = Error::success(); | |||
7521 | auto ToConstructor = importChecked(Err, E->getConstructor()); | |||
7522 | auto ToType = importChecked(Err, E->getType()); | |||
7523 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); | |||
7524 | auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange()); | |||
7525 | if (Err) | |||
7526 | return std::move(Err); | |||
7527 | ||||
7528 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); | |||
7529 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | |||
7530 | return std::move(Err); | |||
7531 | ||||
7532 | return CXXTemporaryObjectExpr::Create( | |||
7533 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, | |||
7534 | ToParenOrBraceRange, E->hadMultipleCandidates(), | |||
7535 | E->isListInitialization(), E->isStdInitListInitialization(), | |||
7536 | E->requiresZeroInitialization()); | |||
7537 | } | |||
7538 | ||||
7539 | ExpectedDecl ASTNodeImporter::VisitLifetimeExtendedTemporaryDecl( | |||
7540 | LifetimeExtendedTemporaryDecl *D) { | |||
7541 | DeclContext *DC, *LexicalDC; | |||
7542 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
7543 | return std::move(Err); | |||
7544 | ||||
7545 | Error Err = Error::success(); | |||
7546 | auto Temporary = importChecked(Err, D->getTemporaryExpr()); | |||
7547 | auto ExtendingDecl = importChecked(Err, D->getExtendingDecl()); | |||
7548 | if (Err) | |||
7549 | return std::move(Err); | |||
7550 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? | |||
7551 | ||||
7552 | LifetimeExtendedTemporaryDecl *To; | |||
7553 | if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl, | |||
7554 | D->getManglingNumber())) | |||
7555 | return To; | |||
7556 | ||||
7557 | To->setLexicalDeclContext(LexicalDC); | |||
7558 | LexicalDC->addDeclInternal(To); | |||
7559 | return To; | |||
7560 | } | |||
7561 | ||||
7562 | ExpectedStmt | |||
7563 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { | |||
7564 | Error Err = Error::success(); | |||
7565 | auto ToType = importChecked(Err, E->getType()); | |||
7566 | Expr *ToTemporaryExpr = importChecked( | |||
7567 | Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr()); | |||
7568 | auto ToMaterializedDecl = | |||
7569 | importChecked(Err, E->getLifetimeExtendedTemporaryDecl()); | |||
7570 | if (Err) | |||
7571 | return std::move(Err); | |||
7572 | ||||
7573 | if (!ToTemporaryExpr) | |||
7574 | ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr()); | |||
7575 | ||||
7576 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( | |||
7577 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference(), | |||
7578 | ToMaterializedDecl); | |||
7579 | ||||
7580 | return ToMTE; | |||
7581 | } | |||
7582 | ||||
7583 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { | |||
7584 | Error Err = Error::success(); | |||
7585 | auto ToType = importChecked(Err, E->getType()); | |||
7586 | auto ToPattern = importChecked(Err, E->getPattern()); | |||
7587 | auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc()); | |||
7588 | if (Err) | |||
7589 | return std::move(Err); | |||
7590 | ||||
7591 | return new (Importer.getToContext()) PackExpansionExpr( | |||
7592 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); | |||
7593 | } | |||
7594 | ||||
7595 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { | |||
7596 | Error Err = Error::success(); | |||
7597 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | |||
7598 | auto ToPack = importChecked(Err, E->getPack()); | |||
7599 | auto ToPackLoc = importChecked(Err, E->getPackLoc()); | |||
7600 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | |||
7601 | if (Err) | |||
7602 | return std::move(Err); | |||
7603 | ||||
7604 | Optional<unsigned> Length; | |||
7605 | if (!E->isValueDependent()) | |||
7606 | Length = E->getPackLength(); | |||
7607 | ||||
7608 | SmallVector<TemplateArgument, 8> ToPartialArguments; | |||
7609 | if (E->isPartiallySubstituted()) { | |||
7610 | if (Error Err = ImportTemplateArguments( | |||
7611 | E->getPartialArguments().data(), | |||
7612 | E->getPartialArguments().size(), | |||
7613 | ToPartialArguments)) | |||
7614 | return std::move(Err); | |||
7615 | } | |||
7616 | ||||
7617 | return SizeOfPackExpr::Create( | |||
7618 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, | |||
7619 | Length, ToPartialArguments); | |||
7620 | } | |||
7621 | ||||
7622 | ||||
7623 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { | |||
7624 | Error Err = Error::success(); | |||
7625 | auto ToOperatorNew = importChecked(Err, E->getOperatorNew()); | |||
7626 | auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete()); | |||
7627 | auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens()); | |||
7628 | auto ToArraySize = importChecked(Err, E->getArraySize()); | |||
7629 | auto ToInitializer = importChecked(Err, E->getInitializer()); | |||
7630 | auto ToType = importChecked(Err, E->getType()); | |||
7631 | auto ToAllocatedTypeSourceInfo = | |||
7632 | importChecked(Err, E->getAllocatedTypeSourceInfo()); | |||
7633 | auto ToSourceRange = importChecked(Err, E->getSourceRange()); | |||
7634 | auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange()); | |||
7635 | if (Err) | |||
7636 | return std::move(Err); | |||
7637 | ||||
7638 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); | |||
7639 | if (Error Err = | |||
7640 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) | |||
7641 | return std::move(Err); | |||
7642 | ||||
7643 | return CXXNewExpr::Create( | |||
7644 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, | |||
7645 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), | |||
7646 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), | |||
7647 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, | |||
7648 | ToDirectInitRange); | |||
7649 | } | |||
7650 | ||||
7651 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { | |||
7652 | Error Err = Error::success(); | |||
7653 | auto ToType = importChecked(Err, E->getType()); | |||
7654 | auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete()); | |||
7655 | auto ToArgument = importChecked(Err, E->getArgument()); | |||
7656 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); | |||
7657 | if (Err) | |||
7658 | return std::move(Err); | |||
7659 | ||||
7660 | return new (Importer.getToContext()) CXXDeleteExpr( | |||
7661 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), | |||
7662 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, | |||
7663 | ToBeginLoc); | |||
7664 | } | |||
7665 | ||||
7666 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { | |||
7667 | Error Err = Error::success(); | |||
7668 | auto ToType = importChecked(Err, E->getType()); | |||
7669 | auto ToLocation = importChecked(Err, E->getLocation()); | |||
7670 | auto ToConstructor = importChecked(Err, E->getConstructor()); | |||
7671 | auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange()); | |||
7672 | if (Err) | |||
7673 | return std::move(Err); | |||
7674 | ||||
7675 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); | |||
7676 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | |||
7677 | return std::move(Err); | |||
7678 | ||||
7679 | return CXXConstructExpr::Create( | |||
7680 | Importer.getToContext(), ToType, ToLocation, ToConstructor, | |||
7681 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), | |||
7682 | E->isListInitialization(), E->isStdInitListInitialization(), | |||
7683 | E->requiresZeroInitialization(), E->getConstructionKind(), | |||
7684 | ToParenOrBraceRange); | |||
7685 | } | |||
7686 | ||||
7687 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { | |||
7688 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | |||
7689 | if (!ToSubExprOrErr) | |||
7690 | return ToSubExprOrErr.takeError(); | |||
7691 | ||||
7692 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); | |||
7693 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) | |||
7694 | return std::move(Err); | |||
7695 | ||||
7696 | return ExprWithCleanups::Create( | |||
7697 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), | |||
7698 | ToObjects); | |||
7699 | } | |||
7700 | ||||
7701 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { | |||
7702 | Error Err = Error::success(); | |||
7703 | auto ToCallee = importChecked(Err, E->getCallee()); | |||
7704 | auto ToType = importChecked(Err, E->getType()); | |||
7705 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | |||
7706 | if (Err) | |||
7707 | return std::move(Err); | |||
7708 | ||||
7709 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); | |||
7710 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | |||
7711 | return std::move(Err); | |||
7712 | ||||
7713 | return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, | |||
7714 | ToType, E->getValueKind(), ToRParenLoc, | |||
7715 | E->getFPFeatures()); | |||
7716 | } | |||
7717 | ||||
7718 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { | |||
7719 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
7720 | if (!ToTypeOrErr) | |||
7721 | return ToTypeOrErr.takeError(); | |||
7722 | ||||
7723 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | |||
7724 | if (!ToLocationOrErr) | |||
7725 | return ToLocationOrErr.takeError(); | |||
7726 | ||||
7727 | return new (Importer.getToContext()) CXXThisExpr( | |||
7728 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); | |||
7729 | } | |||
7730 | ||||
7731 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { | |||
7732 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
7733 | if (!ToTypeOrErr) | |||
7734 | return ToTypeOrErr.takeError(); | |||
7735 | ||||
7736 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | |||
7737 | if (!ToLocationOrErr) | |||
7738 | return ToLocationOrErr.takeError(); | |||
7739 | ||||
7740 | return new (Importer.getToContext()) CXXBoolLiteralExpr( | |||
7741 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); | |||
7742 | } | |||
7743 | ||||
7744 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { | |||
7745 | Error Err = Error::success(); | |||
7746 | auto ToBase = importChecked(Err, E->getBase()); | |||
7747 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | |||
7748 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); | |||
7749 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); | |||
7750 | auto ToMemberDecl = importChecked(Err, E->getMemberDecl()); | |||
7751 | auto ToType = importChecked(Err, E->getType()); | |||
7752 | auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl()); | |||
7753 | auto ToName = importChecked(Err, E->getMemberNameInfo().getName()); | |||
7754 | auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc()); | |||
7755 | if (Err) | |||
7756 | return std::move(Err); | |||
7757 | ||||
7758 | DeclAccessPair ToFoundDecl = | |||
7759 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); | |||
7760 | ||||
7761 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); | |||
7762 | ||||
7763 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; | |||
7764 | if (E->hasExplicitTemplateArgs()) { | |||
7765 | if (Error Err = | |||
7766 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), | |||
7767 | E->template_arguments(), ToTAInfo)) | |||
7768 | return std::move(Err); | |||
7769 | ResInfo = &ToTAInfo; | |||
7770 | } | |||
7771 | ||||
7772 | return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(), | |||
7773 | ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, | |||
7774 | ToMemberDecl, ToFoundDecl, ToMemberNameInfo, | |||
7775 | ResInfo, ToType, E->getValueKind(), | |||
7776 | E->getObjectKind(), E->isNonOdrUse()); | |||
7777 | } | |||
7778 | ||||
7779 | ExpectedStmt | |||
7780 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { | |||
7781 | Error Err = Error::success(); | |||
7782 | auto ToBase = importChecked(Err, E->getBase()); | |||
7783 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | |||
7784 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); | |||
7785 | auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo()); | |||
7786 | auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc()); | |||
7787 | auto ToTildeLoc = importChecked(Err, E->getTildeLoc()); | |||
7788 | if (Err) | |||
7789 | return std::move(Err); | |||
7790 | ||||
7791 | PseudoDestructorTypeStorage Storage; | |||
7792 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { | |||
7793 | IdentifierInfo *ToII = Importer.Import(FromII); | |||
7794 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); | |||
7795 | if (!ToDestroyedTypeLocOrErr) | |||
7796 | return ToDestroyedTypeLocOrErr.takeError(); | |||
7797 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); | |||
7798 | } else { | |||
7799 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) | |||
7800 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); | |||
7801 | else | |||
7802 | return ToTIOrErr.takeError(); | |||
7803 | } | |||
7804 | ||||
7805 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( | |||
7806 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, | |||
7807 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); | |||
7808 | } | |||
7809 | ||||
7810 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( | |||
7811 | CXXDependentScopeMemberExpr *E) { | |||
7812 | Error Err = Error::success(); | |||
7813 | auto ToType = importChecked(Err, E->getType()); | |||
7814 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | |||
7815 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); | |||
7816 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); | |||
7817 | auto ToFirstQualifierFoundInScope = | |||
7818 | importChecked(Err, E->getFirstQualifierFoundInScope()); | |||
7819 | if (Err) | |||
7820 | return std::move(Err); | |||
7821 | ||||
7822 | Expr *ToBase = nullptr; | |||
7823 | if (!E->isImplicitAccess()) { | |||
7824 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) | |||
7825 | ToBase = *ToBaseOrErr; | |||
7826 | else | |||
7827 | return ToBaseOrErr.takeError(); | |||
7828 | } | |||
7829 | ||||
7830 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; | |||
7831 | ||||
7832 | if (E->hasExplicitTemplateArgs()) { | |||
7833 | if (Error Err = | |||
7834 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), | |||
7835 | E->template_arguments(), ToTAInfo)) | |||
7836 | return std::move(Err); | |||
7837 | ResInfo = &ToTAInfo; | |||
7838 | } | |||
7839 | auto ToMember = importChecked(Err, E->getMember()); | |||
7840 | auto ToMemberLoc = importChecked(Err, E->getMemberLoc()); | |||
7841 | if (Err) | |||
7842 | return std::move(Err); | |||
7843 | DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc); | |||
7844 | ||||
7845 | // Import additional name location/type info. | |||
7846 | if (Error Err = | |||
7847 | ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo)) | |||
7848 | return std::move(Err); | |||
7849 | ||||
7850 | return CXXDependentScopeMemberExpr::Create( | |||
7851 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, | |||
7852 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, | |||
7853 | ToMemberNameInfo, ResInfo); | |||
7854 | } | |||
7855 | ||||
7856 | ExpectedStmt | |||
7857 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { | |||
7858 | Error Err = Error::success(); | |||
7859 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); | |||
7860 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); | |||
7861 | auto ToDeclName = importChecked(Err, E->getDeclName()); | |||
7862 | auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc()); | |||
7863 | auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc()); | |||
7864 | auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc()); | |||
7865 | if (Err) | |||
7866 | return std::move(Err); | |||
7867 | ||||
7868 | DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc); | |||
7869 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | |||
7870 | return std::move(Err); | |||
7871 | ||||
7872 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); | |||
7873 | TemplateArgumentListInfo *ResInfo = nullptr; | |||
7874 | if (E->hasExplicitTemplateArgs()) { | |||
7875 | if (Error Err = | |||
7876 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) | |||
7877 | return std::move(Err); | |||
7878 | ResInfo = &ToTAInfo; | |||
7879 | } | |||
7880 | ||||
7881 | return DependentScopeDeclRefExpr::Create( | |||
7882 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, | |||
7883 | ToNameInfo, ResInfo); | |||
7884 | } | |||
7885 | ||||
7886 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( | |||
7887 | CXXUnresolvedConstructExpr *E) { | |||
7888 | Error Err = Error::success(); | |||
7889 | auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); | |||
7890 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | |||
7891 | auto ToType = importChecked(Err, E->getType()); | |||
7892 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); | |||
7893 | if (Err) | |||
7894 | return std::move(Err); | |||
7895 | ||||
7896 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); | |||
7897 | if (Error Err = | |||
7898 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) | |||
7899 | return std::move(Err); | |||
7900 | ||||
7901 | return CXXUnresolvedConstructExpr::Create( | |||
7902 | Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc, | |||
7903 | llvm::makeArrayRef(ToArgs), ToRParenLoc); | |||
7904 | } | |||
7905 | ||||
7906 | ExpectedStmt | |||
7907 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { | |||
7908 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); | |||
7909 | if (!ToNamingClassOrErr) | |||
7910 | return ToNamingClassOrErr.takeError(); | |||
7911 | ||||
7912 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); | |||
7913 | if (!ToQualifierLocOrErr) | |||
7914 | return ToQualifierLocOrErr.takeError(); | |||
7915 | ||||
7916 | Error Err = Error::success(); | |||
7917 | auto ToName = importChecked(Err, E->getName()); | |||
7918 | auto ToNameLoc = importChecked(Err, E->getNameLoc()); | |||
7919 | if (Err) | |||
7920 | return std::move(Err); | |||
7921 | DeclarationNameInfo ToNameInfo(ToName, ToNameLoc); | |||
7922 | ||||
7923 | // Import additional name location/type info. | |||
7924 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | |||
7925 | return std::move(Err); | |||
7926 | ||||
7927 | UnresolvedSet<8> ToDecls; | |||
7928 | for (auto *D : E->decls()) | |||
7929 | if (auto ToDOrErr = import(D)) | |||
7930 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); | |||
7931 | else | |||
7932 | return ToDOrErr.takeError(); | |||
7933 | ||||
7934 | if (E->hasExplicitTemplateArgs()) { | |||
7935 | TemplateArgumentListInfo ToTAInfo; | |||
7936 | if (Error Err = ImportTemplateArgumentListInfo( | |||
7937 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), | |||
7938 | ToTAInfo)) | |||
7939 | return std::move(Err); | |||
7940 | ||||
7941 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); | |||
7942 | if (!ToTemplateKeywordLocOrErr) | |||
7943 | return ToTemplateKeywordLocOrErr.takeError(); | |||
7944 | ||||
7945 | return UnresolvedLookupExpr::Create( | |||
7946 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, | |||
7947 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, | |||
7948 | ToDecls.begin(), ToDecls.end()); | |||
7949 | } | |||
7950 | ||||
7951 | return UnresolvedLookupExpr::Create( | |||
7952 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, | |||
7953 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), | |||
7954 | ToDecls.end()); | |||
7955 | } | |||
7956 | ||||
7957 | ExpectedStmt | |||
7958 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { | |||
7959 | Error Err = Error::success(); | |||
7960 | auto ToType = importChecked(Err, E->getType()); | |||
7961 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | |||
7962 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); | |||
7963 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); | |||
7964 | auto ToName = importChecked(Err, E->getName()); | |||
7965 | auto ToNameLoc = importChecked(Err, E->getNameLoc()); | |||
7966 | if (Err) | |||
7967 | return std::move(Err); | |||
7968 | ||||
7969 | DeclarationNameInfo ToNameInfo(ToName, ToNameLoc); | |||
7970 | // Import additional name location/type info. | |||
7971 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | |||
7972 | return std::move(Err); | |||
7973 | ||||
7974 | UnresolvedSet<8> ToDecls; | |||
7975 | for (Decl *D : E->decls()) | |||
7976 | if (auto ToDOrErr = import(D)) | |||
7977 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); | |||
7978 | else | |||
7979 | return ToDOrErr.takeError(); | |||
7980 | ||||
7981 | TemplateArgumentListInfo ToTAInfo; | |||
7982 | TemplateArgumentListInfo *ResInfo = nullptr; | |||
7983 | if (E->hasExplicitTemplateArgs()) { | |||
7984 | TemplateArgumentListInfo FromTAInfo; | |||
7985 | E->copyTemplateArgumentsInto(FromTAInfo); | |||
7986 | if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo)) | |||
7987 | return std::move(Err); | |||
7988 | ResInfo = &ToTAInfo; | |||
7989 | } | |||
7990 | ||||
7991 | Expr *ToBase = nullptr; | |||
7992 | if (!E->isImplicitAccess()) { | |||
7993 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) | |||
7994 | ToBase = *ToBaseOrErr; | |||
7995 | else | |||
7996 | return ToBaseOrErr.takeError(); | |||
7997 | } | |||
7998 | ||||
7999 | return UnresolvedMemberExpr::Create( | |||
8000 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, | |||
8001 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, | |||
8002 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); | |||
8003 | } | |||
8004 | ||||
8005 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { | |||
8006 | Error Err = Error::success(); | |||
8007 | auto ToCallee = importChecked(Err, E->getCallee()); | |||
8008 | auto ToType = importChecked(Err, E->getType()); | |||
8009 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | |||
8010 | if (Err) | |||
8011 | return std::move(Err); | |||
8012 | ||||
8013 | unsigned NumArgs = E->getNumArgs(); | |||
8014 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); | |||
8015 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | |||
8016 | return std::move(Err); | |||
8017 | ||||
8018 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { | |||
8019 | return CXXOperatorCallExpr::Create( | |||
8020 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, | |||
8021 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(), | |||
8022 | OCE->getADLCallKind()); | |||
8023 | } | |||
8024 | ||||
8025 | return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType, | |||
8026 | E->getValueKind(), ToRParenLoc, E->getFPFeatures(), | |||
8027 | /*MinNumArgs=*/0, E->getADLCallKind()); | |||
8028 | } | |||
8029 | ||||
8030 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { | |||
8031 | CXXRecordDecl *FromClass = E->getLambdaClass(); | |||
8032 | auto ToClassOrErr = import(FromClass); | |||
8033 | if (!ToClassOrErr) | |||
8034 | return ToClassOrErr.takeError(); | |||
8035 | CXXRecordDecl *ToClass = *ToClassOrErr; | |||
8036 | ||||
8037 | auto ToCallOpOrErr = import(E->getCallOperator()); | |||
8038 | if (!ToCallOpOrErr) | |||
8039 | return ToCallOpOrErr.takeError(); | |||
8040 | ||||
8041 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); | |||
8042 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) | |||
8043 | return std::move(Err); | |||
8044 | ||||
8045 | Error Err = Error::success(); | |||
8046 | auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange()); | |||
8047 | auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc()); | |||
8048 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); | |||
8049 | if (Err) | |||
8050 | return std::move(Err); | |||
8051 | ||||
8052 | return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange, | |||
8053 | E->getCaptureDefault(), ToCaptureDefaultLoc, | |||
8054 | E->hasExplicitParameters(), | |||
8055 | E->hasExplicitResultType(), ToCaptureInits, | |||
8056 | ToEndLoc, E->containsUnexpandedParameterPack()); | |||
8057 | } | |||
8058 | ||||
8059 | ||||
8060 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { | |||
8061 | Error Err = Error::success(); | |||
8062 | auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc()); | |||
8063 | auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc()); | |||
8064 | auto ToType = importChecked(Err, E->getType()); | |||
8065 | if (Err) | |||
8066 | return std::move(Err); | |||
8067 | ||||
8068 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); | |||
8069 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) | |||
8070 | return std::move(Err); | |||
8071 | ||||
8072 | ASTContext &ToCtx = Importer.getToContext(); | |||
8073 | InitListExpr *To = new (ToCtx) InitListExpr( | |||
8074 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); | |||
8075 | To->setType(ToType); | |||
8076 | ||||
8077 | if (E->hasArrayFiller()) { | |||
8078 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) | |||
8079 | To->setArrayFiller(*ToFillerOrErr); | |||
8080 | else | |||
8081 | return ToFillerOrErr.takeError(); | |||
8082 | } | |||
8083 | ||||
8084 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { | |||
8085 | if (auto ToFDOrErr = import(FromFD)) | |||
8086 | To->setInitializedFieldInUnion(*ToFDOrErr); | |||
8087 | else | |||
8088 | return ToFDOrErr.takeError(); | |||
8089 | } | |||
8090 | ||||
8091 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { | |||
8092 | if (auto ToSyntFormOrErr = import(SyntForm)) | |||
8093 | To->setSyntacticForm(*ToSyntFormOrErr); | |||
8094 | else | |||
8095 | return ToSyntFormOrErr.takeError(); | |||
8096 | } | |||
8097 | ||||
8098 | // Copy InitListExprBitfields, which are not handled in the ctor of | |||
8099 | // InitListExpr. | |||
8100 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); | |||
8101 | ||||
8102 | return To; | |||
8103 | } | |||
8104 | ||||
8105 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( | |||
8106 | CXXStdInitializerListExpr *E) { | |||
8107 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
8108 | if (!ToTypeOrErr) | |||
8109 | return ToTypeOrErr.takeError(); | |||
8110 | ||||
8111 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | |||
8112 | if (!ToSubExprOrErr) | |||
8113 | return ToSubExprOrErr.takeError(); | |||
8114 | ||||
8115 | return new (Importer.getToContext()) CXXStdInitializerListExpr( | |||
8116 | *ToTypeOrErr, *ToSubExprOrErr); | |||
8117 | } | |||
8118 | ||||
8119 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( | |||
8120 | CXXInheritedCtorInitExpr *E) { | |||
8121 | Error Err = Error::success(); | |||
8122 | auto ToLocation = importChecked(Err, E->getLocation()); | |||
8123 | auto ToType = importChecked(Err, E->getType()); | |||
8124 | auto ToConstructor = importChecked(Err, E->getConstructor()); | |||
8125 | if (Err) | |||
8126 | return std::move(Err); | |||
8127 | ||||
8128 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( | |||
8129 | ToLocation, ToType, ToConstructor, E->constructsVBase(), | |||
8130 | E->inheritedFromVBase()); | |||
8131 | } | |||
8132 | ||||
8133 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { | |||
8134 | Error Err = Error::success(); | |||
8135 | auto ToType = importChecked(Err, E->getType()); | |||
8136 | auto ToCommonExpr = importChecked(Err, E->getCommonExpr()); | |||
8137 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | |||
8138 | if (Err) | |||
8139 | return std::move(Err); | |||
8140 | ||||
8141 | return new (Importer.getToContext()) ArrayInitLoopExpr( | |||
8142 | ToType, ToCommonExpr, ToSubExpr); | |||
8143 | } | |||
8144 | ||||
8145 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { | |||
8146 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
8147 | if (!ToTypeOrErr) | |||
8148 | return ToTypeOrErr.takeError(); | |||
8149 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); | |||
8150 | } | |||
8151 | ||||
8152 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { | |||
8153 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); | |||
8154 | if (!ToBeginLocOrErr) | |||
8155 | return ToBeginLocOrErr.takeError(); | |||
8156 | ||||
8157 | auto ToFieldOrErr = import(E->getField()); | |||
8158 | if (!ToFieldOrErr) | |||
8159 | return ToFieldOrErr.takeError(); | |||
8160 | ||||
8161 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); | |||
8162 | if (!UsedContextOrErr) | |||
8163 | return UsedContextOrErr.takeError(); | |||
8164 | ||||
8165 | FieldDecl *ToField = *ToFieldOrErr; | |||
8166 | assert(ToField->hasInClassInitializer() &&(static_cast <bool> (ToField->hasInClassInitializer( ) && "Field should have in-class initializer if there is a default init " "expression that uses it.") ? void (0) : __assert_fail ("ToField->hasInClassInitializer() && \"Field should have in-class initializer if there is a default init \" \"expression that uses it.\"" , "clang/lib/AST/ASTImporter.cpp", 8168, __extension__ __PRETTY_FUNCTION__ )) | |||
8167 | "Field should have in-class initializer if there is a default init "(static_cast <bool> (ToField->hasInClassInitializer( ) && "Field should have in-class initializer if there is a default init " "expression that uses it.") ? void (0) : __assert_fail ("ToField->hasInClassInitializer() && \"Field should have in-class initializer if there is a default init \" \"expression that uses it.\"" , "clang/lib/AST/ASTImporter.cpp", 8168, __extension__ __PRETTY_FUNCTION__ )) | |||
8168 | "expression that uses it.")(static_cast <bool> (ToField->hasInClassInitializer( ) && "Field should have in-class initializer if there is a default init " "expression that uses it.") ? void (0) : __assert_fail ("ToField->hasInClassInitializer() && \"Field should have in-class initializer if there is a default init \" \"expression that uses it.\"" , "clang/lib/AST/ASTImporter.cpp", 8168, __extension__ __PRETTY_FUNCTION__ )); | |||
8169 | if (!ToField->getInClassInitializer()) { | |||
8170 | // The in-class initializer may be not yet set in "To" AST even if the | |||
8171 | // field is already there. This must be set here to make construction of | |||
8172 | // CXXDefaultInitExpr work. | |||
8173 | auto ToInClassInitializerOrErr = | |||
8174 | import(E->getField()->getInClassInitializer()); | |||
8175 | if (!ToInClassInitializerOrErr) | |||
8176 | return ToInClassInitializerOrErr.takeError(); | |||
8177 | ToField->setInClassInitializer(*ToInClassInitializerOrErr); | |||
8178 | } | |||
8179 | ||||
8180 | return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr, | |||
8181 | ToField, *UsedContextOrErr); | |||
8182 | } | |||
8183 | ||||
8184 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { | |||
8185 | Error Err = Error::success(); | |||
8186 | auto ToType = importChecked(Err, E->getType()); | |||
8187 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | |||
8188 | auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten()); | |||
8189 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | |||
8190 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | |||
8191 | auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets()); | |||
8192 | if (Err) | |||
8193 | return std::move(Err); | |||
8194 | ||||
8195 | ExprValueKind VK = E->getValueKind(); | |||
8196 | CastKind CK = E->getCastKind(); | |||
8197 | auto ToBasePathOrErr = ImportCastPath(E); | |||
8198 | if (!ToBasePathOrErr) | |||
8199 | return ToBasePathOrErr.takeError(); | |||
8200 | ||||
8201 | if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) { | |||
8202 | return CXXStaticCastExpr::Create( | |||
8203 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | |||
8204 | ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc, | |||
8205 | ToAngleBrackets); | |||
8206 | } else if (isa<CXXDynamicCastExpr>(E)) { | |||
8207 | return CXXDynamicCastExpr::Create( | |||
8208 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | |||
8209 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | |||
8210 | } else if (isa<CXXReinterpretCastExpr>(E)) { | |||
8211 | return CXXReinterpretCastExpr::Create( | |||
8212 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | |||
8213 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | |||
8214 | } else if (isa<CXXConstCastExpr>(E)) { | |||
8215 | return CXXConstCastExpr::Create( | |||
8216 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, | |||
8217 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | |||
8218 | } else { | |||
8219 | llvm_unreachable("Unknown cast type")::llvm::llvm_unreachable_internal("Unknown cast type", "clang/lib/AST/ASTImporter.cpp" , 8219); | |||
8220 | return make_error<ImportError>(); | |||
8221 | } | |||
8222 | } | |||
8223 | ||||
8224 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( | |||
8225 | SubstNonTypeTemplateParmExpr *E) { | |||
8226 | Error Err = Error::success(); | |||
8227 | auto ToType = importChecked(Err, E->getType()); | |||
8228 | auto ToExprLoc = importChecked(Err, E->getExprLoc()); | |||
8229 | auto ToParameter = importChecked(Err, E->getParameter()); | |||
8230 | auto ToReplacement = importChecked(Err, E->getReplacement()); | |||
8231 | if (Err) | |||
8232 | return std::move(Err); | |||
8233 | ||||
8234 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( | |||
8235 | ToType, E->getValueKind(), ToExprLoc, ToParameter, | |||
8236 | E->isReferenceParameter(), ToReplacement); | |||
8237 | } | |||
8238 | ||||
8239 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { | |||
8240 | Error Err = Error::success(); | |||
8241 | auto ToType = importChecked(Err, E->getType()); | |||
8242 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); | |||
8243 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); | |||
8244 | if (Err) | |||
8245 | return std::move(Err); | |||
8246 | ||||
8247 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); | |||
8248 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) | |||
8249 | return std::move(Err); | |||
8250 | ||||
8251 | // According to Sema::BuildTypeTrait(), if E is value-dependent, | |||
8252 | // Value is always false. | |||
8253 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); | |||
8254 | ||||
8255 | return TypeTraitExpr::Create( | |||
8256 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, | |||
8257 | ToEndLoc, ToValue); | |||
8258 | } | |||
8259 | ||||
8260 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { | |||
8261 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
8262 | if (!ToTypeOrErr) | |||
8263 | return ToTypeOrErr.takeError(); | |||
8264 | ||||
8265 | auto ToSourceRangeOrErr = import(E->getSourceRange()); | |||
8266 | if (!ToSourceRangeOrErr) | |||
8267 | return ToSourceRangeOrErr.takeError(); | |||
8268 | ||||
8269 | if (E->isTypeOperand()) { | |||
8270 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) | |||
8271 | return new (Importer.getToContext()) CXXTypeidExpr( | |||
8272 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); | |||
8273 | else | |||
8274 | return ToTSIOrErr.takeError(); | |||
8275 | } | |||
8276 | ||||
8277 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); | |||
8278 | if (!ToExprOperandOrErr) | |||
8279 | return ToExprOperandOrErr.takeError(); | |||
8280 | ||||
8281 | return new (Importer.getToContext()) CXXTypeidExpr( | |||
8282 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); | |||
8283 | } | |||
8284 | ||||
8285 | ExpectedStmt ASTNodeImporter::VisitCXXFoldExpr(CXXFoldExpr *E) { | |||
8286 | Error Err = Error::success(); | |||
8287 | ||||
8288 | QualType ToType = importChecked(Err, E->getType()); | |||
8289 | UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee()); | |||
8290 | SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc()); | |||
8291 | Expr *ToLHS = importChecked(Err, E->getLHS()); | |||
8292 | SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc()); | |||
8293 | Expr *ToRHS = importChecked(Err, E->getRHS()); | |||
8294 | SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc()); | |||
8295 | ||||
8296 | if (Err) | |||
8297 | return std::move(Err); | |||
8298 | ||||
8299 | return new (Importer.getToContext()) | |||
8300 | CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(), | |||
8301 | ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions()); | |||
8302 | } | |||
8303 | ||||
8304 | Error ASTNodeImporter::ImportOverriddenMethods(CXXMethodDecl *ToMethod, | |||
8305 | CXXMethodDecl *FromMethod) { | |||
8306 | Error ImportErrors = Error::success(); | |||
8307 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { | |||
8308 | if (auto ImportedOrErr = import(FromOverriddenMethod)) | |||
8309 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( | |||
8310 | (*ImportedOrErr)->getCanonicalDecl())); | |||
8311 | else | |||
8312 | ImportErrors = | |||
8313 | joinErrors(std::move(ImportErrors), ImportedOrErr.takeError()); | |||
8314 | } | |||
8315 | return ImportErrors; | |||
8316 | } | |||
8317 | ||||
8318 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, | |||
8319 | ASTContext &FromContext, FileManager &FromFileManager, | |||
8320 | bool MinimalImport, | |||
8321 | std::shared_ptr<ASTImporterSharedState> SharedState) | |||
8322 | : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext), | |||
8323 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), | |||
8324 | Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) { | |||
8325 | ||||
8326 | // Create a default state without the lookup table: LLDB case. | |||
8327 | if (!SharedState) { | |||
8328 | this->SharedState = std::make_shared<ASTImporterSharedState>(); | |||
8329 | } | |||
8330 | ||||
8331 | ImportedDecls[FromContext.getTranslationUnitDecl()] = | |||
8332 | ToContext.getTranslationUnitDecl(); | |||
8333 | } | |||
8334 | ||||
8335 | ASTImporter::~ASTImporter() = default; | |||
8336 | ||||
8337 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { | |||
8338 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&(static_cast <bool> (F && (isa<FieldDecl> (*F) || isa<IndirectFieldDecl>(*F)) && "Try to get field index for non-field." ) ? void (0) : __assert_fail ("F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && \"Try to get field index for non-field.\"" , "clang/lib/AST/ASTImporter.cpp", 8339, __extension__ __PRETTY_FUNCTION__ )) | |||
8339 | "Try to get field index for non-field.")(static_cast <bool> (F && (isa<FieldDecl> (*F) || isa<IndirectFieldDecl>(*F)) && "Try to get field index for non-field." ) ? void (0) : __assert_fail ("F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && \"Try to get field index for non-field.\"" , "clang/lib/AST/ASTImporter.cpp", 8339, __extension__ __PRETTY_FUNCTION__ )); | |||
8340 | ||||
8341 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); | |||
8342 | if (!Owner) | |||
8343 | return None; | |||
8344 | ||||
8345 | unsigned Index = 0; | |||
8346 | for (const auto *D : Owner->decls()) { | |||
8347 | if (D == F) | |||
8348 | return Index; | |||
8349 | ||||
8350 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) | |||
8351 | ++Index; | |||
8352 | } | |||
8353 | ||||
8354 | llvm_unreachable("Field was not found in its parent context.")::llvm::llvm_unreachable_internal("Field was not found in its parent context." , "clang/lib/AST/ASTImporter.cpp", 8354); | |||
8355 | ||||
8356 | return None; | |||
8357 | } | |||
8358 | ||||
8359 | ASTImporter::FoundDeclsTy | |||
8360 | ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) { | |||
8361 | // We search in the redecl context because of transparent contexts. | |||
8362 | // E.g. a simple C language enum is a transparent context: | |||
8363 | // enum E { A, B }; | |||
8364 | // Now if we had a global variable in the TU | |||
8365 | // int A; | |||
8366 | // then the enum constant 'A' and the variable 'A' violates ODR. | |||
8367 | // We can diagnose this only if we search in the redecl context. | |||
8368 | DeclContext *ReDC = DC->getRedeclContext(); | |||
8369 | if (SharedState->getLookupTable()) { | |||
8370 | ASTImporterLookupTable::LookupResult LookupResult = | |||
8371 | SharedState->getLookupTable()->lookup(ReDC, Name); | |||
8372 | return FoundDeclsTy(LookupResult.begin(), LookupResult.end()); | |||
8373 | } else { | |||
8374 | DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name); | |||
8375 | FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end()); | |||
8376 | // We must search by the slow case of localUncachedLookup because that is | |||
8377 | // working even if there is no LookupPtr for the DC. We could use | |||
8378 | // DC::buildLookup() to create the LookupPtr, but that would load external | |||
8379 | // decls again, we must avoid that case. | |||
8380 | // Also, even if we had the LookupPtr, we must find Decls which are not | |||
8381 | // in the LookupPtr, so we need the slow case. | |||
8382 | // These cases are handled in ASTImporterLookupTable, but we cannot use | |||
8383 | // that with LLDB since that traverses through the AST which initiates the | |||
8384 | // load of external decls again via DC::decls(). And again, we must avoid | |||
8385 | // loading external decls during the import. | |||
8386 | if (Result.empty()) | |||
8387 | ReDC->localUncachedLookup(Name, Result); | |||
8388 | return Result; | |||
8389 | } | |||
8390 | } | |||
8391 | ||||
8392 | void ASTImporter::AddToLookupTable(Decl *ToD) { | |||
8393 | SharedState->addDeclToLookup(ToD); | |||
8394 | } | |||
8395 | ||||
8396 | Expected<Decl *> ASTImporter::ImportImpl(Decl *FromD) { | |||
8397 | // Import the decl using ASTNodeImporter. | |||
8398 | ASTNodeImporter Importer(*this); | |||
8399 | return Importer.Visit(FromD); | |||
8400 | } | |||
8401 | ||||
8402 | void ASTImporter::RegisterImportedDecl(Decl *FromD, Decl *ToD) { | |||
8403 | MapImported(FromD, ToD); | |||
8404 | } | |||
8405 | ||||
8406 | llvm::Expected<ExprWithCleanups::CleanupObject> | |||
8407 | ASTImporter::Import(ExprWithCleanups::CleanupObject From) { | |||
8408 | if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) { | |||
8409 | if (Expected<Expr *> R = Import(CLE)) | |||
8410 | return ExprWithCleanups::CleanupObject(cast<CompoundLiteralExpr>(*R)); | |||
8411 | } | |||
8412 | ||||
8413 | // FIXME: Handle BlockDecl when we implement importing BlockExpr in | |||
8414 | // ASTNodeImporter. | |||
8415 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
8416 | } | |||
8417 | ||||
8418 | ExpectedTypePtr ASTImporter::Import(const Type *FromT) { | |||
8419 | if (!FromT) | |||
8420 | return FromT; | |||
8421 | ||||
8422 | // Check whether we've already imported this type. | |||
8423 | llvm::DenseMap<const Type *, const Type *>::iterator Pos = | |||
8424 | ImportedTypes.find(FromT); | |||
8425 | if (Pos != ImportedTypes.end()) | |||
8426 | return Pos->second; | |||
8427 | ||||
8428 | // Import the type. | |||
8429 | ASTNodeImporter Importer(*this); | |||
8430 | ExpectedType ToTOrErr = Importer.Visit(FromT); | |||
8431 | if (!ToTOrErr) | |||
8432 | return ToTOrErr.takeError(); | |||
8433 | ||||
8434 | // Record the imported type. | |||
8435 | ImportedTypes[FromT] = ToTOrErr->getTypePtr(); | |||
8436 | ||||
8437 | return ToTOrErr->getTypePtr(); | |||
8438 | } | |||
8439 | ||||
8440 | Expected<QualType> ASTImporter::Import(QualType FromT) { | |||
8441 | if (FromT.isNull()) | |||
8442 | return QualType{}; | |||
8443 | ||||
8444 | ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr()); | |||
8445 | if (!ToTyOrErr) | |||
8446 | return ToTyOrErr.takeError(); | |||
8447 | ||||
8448 | return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers()); | |||
8449 | } | |||
8450 | ||||
8451 | Expected<TypeSourceInfo *> ASTImporter::Import(TypeSourceInfo *FromTSI) { | |||
8452 | if (!FromTSI) | |||
8453 | return FromTSI; | |||
8454 | ||||
8455 | // FIXME: For now we just create a "trivial" type source info based | |||
8456 | // on the type and a single location. Implement a real version of this. | |||
8457 | ExpectedType TOrErr = Import(FromTSI->getType()); | |||
8458 | if (!TOrErr) | |||
8459 | return TOrErr.takeError(); | |||
8460 | ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc()); | |||
8461 | if (!BeginLocOrErr) | |||
8462 | return BeginLocOrErr.takeError(); | |||
8463 | ||||
8464 | return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr); | |||
8465 | } | |||
8466 | ||||
8467 | // To use this object, it should be created before the new attribute is created, | |||
8468 | // and destructed after it is created. The construction already performs the | |||
8469 | // import of the data. | |||
8470 | template <typename T> struct AttrArgImporter { | |||
8471 | AttrArgImporter(const AttrArgImporter<T> &) = delete; | |||
8472 | AttrArgImporter(AttrArgImporter<T> &&) = default; | |||
8473 | AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete; | |||
8474 | AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default; | |||
8475 | ||||
8476 | AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From) | |||
8477 | : To(I.importChecked(Err, From)) {} | |||
8478 | ||||
8479 | const T &value() { return To; } | |||
8480 | ||||
8481 | private: | |||
8482 | T To; | |||
8483 | }; | |||
8484 | ||||
8485 | // To use this object, it should be created before the new attribute is created, | |||
8486 | // and destructed after it is created. The construction already performs the | |||
8487 | // import of the data. The array data is accessible in a pointer form, this form | |||
8488 | // is used by the attribute classes. This object should be created once for the | |||
8489 | // array data to be imported (the array size is not imported, just copied). | |||
8490 | template <typename T> struct AttrArgArrayImporter { | |||
8491 | AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete; | |||
8492 | AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default; | |||
8493 | AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete; | |||
8494 | AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default; | |||
8495 | ||||
8496 | AttrArgArrayImporter(ASTNodeImporter &I, Error &Err, | |||
8497 | const llvm::iterator_range<T *> &From, | |||
8498 | unsigned ArraySize) { | |||
8499 | if (Err) | |||
8500 | return; | |||
8501 | To.reserve(ArraySize); | |||
8502 | Err = I.ImportContainerChecked(From, To); | |||
8503 | } | |||
8504 | ||||
8505 | T *value() { return To.data(); } | |||
8506 | ||||
8507 | private: | |||
8508 | llvm::SmallVector<T, 2> To; | |||
8509 | }; | |||
8510 | ||||
8511 | class AttrImporter { | |||
8512 | Error Err{Error::success()}; | |||
8513 | Attr *ToAttr = nullptr; | |||
8514 | ASTImporter &Importer; | |||
8515 | ASTNodeImporter NImporter; | |||
8516 | ||||
8517 | public: | |||
8518 | AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {} | |||
8519 | ||||
8520 | // Create an "importer" for an attribute parameter. | |||
8521 | // Result of the 'value()' of that object is to be passed to the function | |||
8522 | // 'importAttr', in the order that is expected by the attribute class. | |||
8523 | template <class T> AttrArgImporter<T> importArg(const T &From) { | |||
8524 | return AttrArgImporter<T>(NImporter, Err, From); | |||
8525 | } | |||
8526 | ||||
8527 | // Create an "importer" for an attribute parameter that has array type. | |||
8528 | // Result of the 'value()' of that object is to be passed to the function | |||
8529 | // 'importAttr', then the size of the array as next argument. | |||
8530 | template <typename T> | |||
8531 | AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From, | |||
8532 | unsigned ArraySize) { | |||
8533 | return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize); | |||
8534 | } | |||
8535 | ||||
8536 | // Create an attribute object with the specified arguments. | |||
8537 | // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg' | |||
8538 | // should be values that are passed to the 'Create' function of the attribute. | |||
8539 | // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is | |||
8540 | // used here.) As much data is copied or imported from the old attribute | |||
8541 | // as possible. The passed arguments should be already imported. | |||
8542 | // If an import error happens, the internal error is set to it, and any | |||
8543 | // further import attempt is ignored. | |||
8544 | template <typename T, typename... Arg> | |||
8545 | void importAttr(const T *FromAttr, Arg &&...ImportedArg) { | |||
8546 | static_assert(std::is_base_of<Attr, T>::value, | |||
8547 | "T should be subclass of Attr."); | |||
8548 | assert(!ToAttr && "Use one AttrImporter to import one Attribute object.")(static_cast <bool> (!ToAttr && "Use one AttrImporter to import one Attribute object." ) ? void (0) : __assert_fail ("!ToAttr && \"Use one AttrImporter to import one Attribute object.\"" , "clang/lib/AST/ASTImporter.cpp", 8548, __extension__ __PRETTY_FUNCTION__ )); | |||
8549 | ||||
8550 | const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName()); | |||
8551 | const IdentifierInfo *ToScopeName = | |||
8552 | Importer.Import(FromAttr->getScopeName()); | |||
8553 | SourceRange ToAttrRange = | |||
8554 | NImporter.importChecked(Err, FromAttr->getRange()); | |||
8555 | SourceLocation ToScopeLoc = | |||
8556 | NImporter.importChecked(Err, FromAttr->getScopeLoc()); | |||
8557 | ||||
8558 | if (Err) | |||
8559 | return; | |||
8560 | ||||
8561 | AttributeCommonInfo ToI(ToAttrName, ToScopeName, ToAttrRange, ToScopeLoc, | |||
8562 | FromAttr->getParsedKind(), FromAttr->getSyntax(), | |||
8563 | FromAttr->getAttributeSpellingListIndex()); | |||
8564 | // The "SemanticSpelling" is not needed to be passed to the constructor. | |||
8565 | // That value is recalculated from the SpellingListIndex if needed. | |||
8566 | ToAttr = T::Create(Importer.getToContext(), | |||
8567 | std::forward<Arg>(ImportedArg)..., ToI); | |||
8568 | ||||
8569 | ToAttr->setImplicit(FromAttr->isImplicit()); | |||
8570 | ToAttr->setPackExpansion(FromAttr->isPackExpansion()); | |||
8571 | if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr)) | |||
8572 | ToInheritableAttr->setInherited(FromAttr->isInherited()); | |||
8573 | } | |||
8574 | ||||
8575 | // Create a clone of the 'FromAttr' and import its source range only. | |||
8576 | // This causes objects with invalid references to be created if the 'FromAttr' | |||
8577 | // contains other data that should be imported. | |||
8578 | void cloneAttr(const Attr *FromAttr) { | |||
8579 | assert(!ToAttr && "Use one AttrImporter to import one Attribute object.")(static_cast <bool> (!ToAttr && "Use one AttrImporter to import one Attribute object." ) ? void (0) : __assert_fail ("!ToAttr && \"Use one AttrImporter to import one Attribute object.\"" , "clang/lib/AST/ASTImporter.cpp", 8579, __extension__ __PRETTY_FUNCTION__ )); | |||
8580 | ||||
8581 | SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange()); | |||
8582 | if (Err) | |||
8583 | return; | |||
8584 | ||||
8585 | ToAttr = FromAttr->clone(Importer.getToContext()); | |||
8586 | ToAttr->setRange(ToRange); | |||
8587 | } | |||
8588 | ||||
8589 | // Get the result of the previous import attempt (can be used only once). | |||
8590 | llvm::Expected<Attr *> getResult() && { | |||
8591 | if (Err) | |||
8592 | return std::move(Err); | |||
8593 | assert(ToAttr && "Attribute should be created.")(static_cast <bool> (ToAttr && "Attribute should be created." ) ? void (0) : __assert_fail ("ToAttr && \"Attribute should be created.\"" , "clang/lib/AST/ASTImporter.cpp", 8593, __extension__ __PRETTY_FUNCTION__ )); | |||
8594 | return ToAttr; | |||
8595 | } | |||
8596 | }; | |||
8597 | ||||
8598 | Expected<Attr *> ASTImporter::Import(const Attr *FromAttr) { | |||
8599 | AttrImporter AI(*this); | |||
8600 | ||||
8601 | // FIXME: Is there some kind of AttrVisitor to use here? | |||
8602 | switch (FromAttr->getKind()) { | |||
8603 | case attr::Aligned: { | |||
8604 | auto *From = cast<AlignedAttr>(FromAttr); | |||
8605 | if (From->isAlignmentExpr()) | |||
8606 | AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value()); | |||
8607 | else | |||
8608 | AI.importAttr(From, false, | |||
8609 | AI.importArg(From->getAlignmentType()).value()); | |||
8610 | break; | |||
8611 | } | |||
8612 | ||||
8613 | case attr::Format: { | |||
8614 | const auto *From = cast<FormatAttr>(FromAttr); | |||
8615 | AI.importAttr(From, Import(From->getType()), From->getFormatIdx(), | |||
8616 | From->getFirstArg()); | |||
8617 | break; | |||
8618 | } | |||
8619 | ||||
8620 | case attr::EnableIf: { | |||
8621 | const auto *From = cast<EnableIfAttr>(FromAttr); | |||
8622 | AI.importAttr(From, AI.importArg(From->getCond()).value(), | |||
8623 | From->getMessage()); | |||
8624 | break; | |||
8625 | } | |||
8626 | ||||
8627 | case attr::AssertCapability: { | |||
8628 | const auto *From = cast<AssertCapabilityAttr>(FromAttr); | |||
8629 | AI.importAttr(From, | |||
8630 | AI.importArrayArg(From->args(), From->args_size()).value(), | |||
8631 | From->args_size()); | |||
8632 | break; | |||
8633 | } | |||
8634 | case attr::AcquireCapability: { | |||
8635 | const auto *From = cast<AcquireCapabilityAttr>(FromAttr); | |||
8636 | AI.importAttr(From, | |||
8637 | AI.importArrayArg(From->args(), From->args_size()).value(), | |||
8638 | From->args_size()); | |||
8639 | break; | |||
8640 | } | |||
8641 | case attr::TryAcquireCapability: { | |||
8642 | const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr); | |||
8643 | AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(), | |||
8644 | AI.importArrayArg(From->args(), From->args_size()).value(), | |||
8645 | From->args_size()); | |||
8646 | break; | |||
8647 | } | |||
8648 | case attr::ReleaseCapability: { | |||
8649 | const auto *From = cast<ReleaseCapabilityAttr>(FromAttr); | |||
8650 | AI.importAttr(From, | |||
8651 | AI.importArrayArg(From->args(), From->args_size()).value(), | |||
8652 | From->args_size()); | |||
8653 | break; | |||
8654 | } | |||
8655 | case attr::RequiresCapability: { | |||
8656 | const auto *From = cast<RequiresCapabilityAttr>(FromAttr); | |||
8657 | AI.importAttr(From, | |||
8658 | AI.importArrayArg(From->args(), From->args_size()).value(), | |||
8659 | From->args_size()); | |||
8660 | break; | |||
8661 | } | |||
8662 | case attr::GuardedBy: { | |||
8663 | const auto *From = cast<GuardedByAttr>(FromAttr); | |||
8664 | AI.importAttr(From, AI.importArg(From->getArg()).value()); | |||
8665 | break; | |||
8666 | } | |||
8667 | case attr::PtGuardedBy: { | |||
8668 | const auto *From = cast<PtGuardedByAttr>(FromAttr); | |||
8669 | AI.importAttr(From, AI.importArg(From->getArg()).value()); | |||
8670 | break; | |||
8671 | } | |||
8672 | case attr::AcquiredAfter: { | |||
8673 | const auto *From = cast<AcquiredAfterAttr>(FromAttr); | |||
8674 | AI.importAttr(From, | |||
8675 | AI.importArrayArg(From->args(), From->args_size()).value(), | |||
8676 | From->args_size()); | |||
8677 | break; | |||
8678 | } | |||
8679 | case attr::AcquiredBefore: { | |||
8680 | const auto *From = cast<AcquiredBeforeAttr>(FromAttr); | |||
8681 | AI.importAttr(From, | |||
8682 | AI.importArrayArg(From->args(), From->args_size()).value(), | |||
8683 | From->args_size()); | |||
8684 | break; | |||
8685 | } | |||
8686 | case attr::AssertExclusiveLock: { | |||
8687 | const auto *From = cast<AssertExclusiveLockAttr>(FromAttr); | |||
8688 | AI.importAttr(From, | |||
8689 | AI.importArrayArg(From->args(), From->args_size()).value(), | |||
8690 | From->args_size()); | |||
8691 | break; | |||
8692 | } | |||
8693 | case attr::AssertSharedLock: { | |||
8694 | const auto *From = cast<AssertSharedLockAttr>(FromAttr); | |||
8695 | AI.importAttr(From, | |||
8696 | AI.importArrayArg(From->args(), From->args_size()).value(), | |||
8697 | From->args_size()); | |||
8698 | break; | |||
8699 | } | |||
8700 | case attr::ExclusiveTrylockFunction: { | |||
8701 | const auto *From = cast<ExclusiveTrylockFunctionAttr>(FromAttr); | |||
8702 | AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(), | |||
8703 | AI.importArrayArg(From->args(), From->args_size()).value(), | |||
8704 | From->args_size()); | |||
8705 | break; | |||
8706 | } | |||
8707 | case attr::SharedTrylockFunction: { | |||
8708 | const auto *From = cast<SharedTrylockFunctionAttr>(FromAttr); | |||
8709 | AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(), | |||
8710 | AI.importArrayArg(From->args(), From->args_size()).value(), | |||
8711 | From->args_size()); | |||
8712 | break; | |||
8713 | } | |||
8714 | case attr::LockReturned: { | |||
8715 | const auto *From = cast<LockReturnedAttr>(FromAttr); | |||
8716 | AI.importAttr(From, AI.importArg(From->getArg()).value()); | |||
8717 | break; | |||
8718 | } | |||
8719 | case attr::LocksExcluded: { | |||
8720 | const auto *From = cast<LocksExcludedAttr>(FromAttr); | |||
8721 | AI.importAttr(From, | |||
8722 | AI.importArrayArg(From->args(), From->args_size()).value(), | |||
8723 | From->args_size()); | |||
8724 | break; | |||
8725 | } | |||
8726 | ||||
8727 | default: { | |||
8728 | // The default branch works for attributes that have no arguments to import. | |||
8729 | // FIXME: Handle every attribute type that has arguments of type to import | |||
8730 | // (most often Expr* or Decl* or type) in the switch above. | |||
8731 | AI.cloneAttr(FromAttr); | |||
8732 | break; | |||
8733 | } | |||
8734 | } | |||
8735 | ||||
8736 | return std::move(AI).getResult(); | |||
8737 | } | |||
8738 | ||||
8739 | Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const { | |||
8740 | auto Pos = ImportedDecls.find(FromD); | |||
8741 | if (Pos != ImportedDecls.end()) | |||
8742 | return Pos->second; | |||
8743 | else | |||
8744 | return nullptr; | |||
8745 | } | |||
8746 | ||||
8747 | TranslationUnitDecl *ASTImporter::GetFromTU(Decl *ToD) { | |||
8748 | auto FromDPos = ImportedFromDecls.find(ToD); | |||
8749 | if (FromDPos == ImportedFromDecls.end()) | |||
8750 | return nullptr; | |||
8751 | return FromDPos->second->getTranslationUnitDecl(); | |||
8752 | } | |||
8753 | ||||
8754 | Expected<Decl *> ASTImporter::Import(Decl *FromD) { | |||
8755 | if (!FromD) | |||
8756 | return nullptr; | |||
8757 | ||||
8758 | // Push FromD to the stack, and remove that when we return. | |||
8759 | ImportPath.push(FromD); | |||
8760 | auto ImportPathBuilder = | |||
8761 | llvm::make_scope_exit([this]() { ImportPath.pop(); }); | |||
8762 | ||||
8763 | // Check whether there was a previous failed import. | |||
8764 | // If yes return the existing error. | |||
8765 | if (auto Error = getImportDeclErrorIfAny(FromD)) | |||
8766 | return make_error<ImportError>(*Error); | |||
8767 | ||||
8768 | // Check whether we've already imported this declaration. | |||
8769 | Decl *ToD = GetAlreadyImportedOrNull(FromD); | |||
8770 | if (ToD) { | |||
8771 | // Already imported (possibly from another TU) and with an error. | |||
8772 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { | |||
8773 | setImportDeclError(FromD, *Error); | |||
8774 | return make_error<ImportError>(*Error); | |||
8775 | } | |||
8776 | ||||
8777 | // If FromD has some updated flags after last import, apply it. | |||
8778 | updateFlags(FromD, ToD); | |||
8779 | // If we encounter a cycle during an import then we save the relevant part | |||
8780 | // of the import path associated to the Decl. | |||
8781 | if (ImportPath.hasCycleAtBack()) | |||
8782 | SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack()); | |||
8783 | return ToD; | |||
8784 | } | |||
8785 | ||||
8786 | // Import the declaration. | |||
8787 | ExpectedDecl ToDOrErr = ImportImpl(FromD); | |||
8788 | if (!ToDOrErr) { | |||
8789 | // Failed to import. | |||
8790 | ||||
8791 | auto Pos = ImportedDecls.find(FromD); | |||
8792 | if (Pos != ImportedDecls.end()) { | |||
8793 | // Import failed after the object was created. | |||
8794 | // Remove all references to it. | |||
8795 | auto *ToD = Pos->second; | |||
8796 | ImportedDecls.erase(Pos); | |||
8797 | ||||
8798 | // ImportedDecls and ImportedFromDecls are not symmetric. It may happen | |||
8799 | // (e.g. with namespaces) that several decls from the 'from' context are | |||
8800 | // mapped to the same decl in the 'to' context. If we removed entries | |||
8801 | // from the LookupTable here then we may end up removing them multiple | |||
8802 | // times. | |||
8803 | ||||
8804 | // The Lookuptable contains decls only which are in the 'to' context. | |||
8805 | // Remove from the Lookuptable only if it is *imported* into the 'to' | |||
8806 | // context (and do not remove it if it was added during the initial | |||
8807 | // traverse of the 'to' context). | |||
8808 | auto PosF = ImportedFromDecls.find(ToD); | |||
8809 | if (PosF != ImportedFromDecls.end()) { | |||
8810 | // In the case of TypedefNameDecl we create the Decl first and only | |||
8811 | // then we import and set its DeclContext. So, the DC might not be set | |||
8812 | // when we reach here. | |||
8813 | if (ToD->getDeclContext()) | |||
8814 | SharedState->removeDeclFromLookup(ToD); | |||
8815 | ImportedFromDecls.erase(PosF); | |||
8816 | } | |||
8817 | ||||
8818 | // FIXME: AST may contain remaining references to the failed object. | |||
8819 | // However, the ImportDeclErrors in the shared state contains all the | |||
8820 | // failed objects together with their error. | |||
8821 | } | |||
8822 | ||||
8823 | // Error encountered for the first time. | |||
8824 | // After takeError the error is not usable any more in ToDOrErr. | |||
8825 | // Get a copy of the error object (any more simple solution for this?). | |||
8826 | ImportError ErrOut; | |||
8827 | handleAllErrors(ToDOrErr.takeError(), | |||
8828 | [&ErrOut](const ImportError &E) { ErrOut = E; }); | |||
8829 | setImportDeclError(FromD, ErrOut); | |||
8830 | // Set the error for the mapped to Decl, which is in the "to" context. | |||
8831 | if (Pos != ImportedDecls.end()) | |||
8832 | SharedState->setImportDeclError(Pos->second, ErrOut); | |||
8833 | ||||
8834 | // Set the error for all nodes which have been created before we | |||
8835 | // recognized the error. | |||
8836 | for (const auto &Path : SavedImportPaths[FromD]) { | |||
8837 | // The import path contains import-dependency nodes first. | |||
8838 | // Save the node that was imported as dependency of the current node. | |||
8839 | Decl *PrevFromDi = FromD; | |||
8840 | for (Decl *FromDi : Path) { | |||
8841 | // Begin and end of the path equals 'FromD', skip it. | |||
8842 | if (FromDi == FromD) | |||
8843 | continue; | |||
8844 | // We should not set import error on a node and all following nodes in | |||
8845 | // the path if child import errors are ignored. | |||
8846 | if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent( | |||
8847 | PrevFromDi)) | |||
8848 | break; | |||
8849 | PrevFromDi = FromDi; | |||
8850 | setImportDeclError(FromDi, ErrOut); | |||
8851 | //FIXME Should we remove these Decls from ImportedDecls? | |||
8852 | // Set the error for the mapped to Decl, which is in the "to" context. | |||
8853 | auto Ii = ImportedDecls.find(FromDi); | |||
8854 | if (Ii != ImportedDecls.end()) | |||
8855 | SharedState->setImportDeclError(Ii->second, ErrOut); | |||
8856 | // FIXME Should we remove these Decls from the LookupTable, | |||
8857 | // and from ImportedFromDecls? | |||
8858 | } | |||
8859 | } | |||
8860 | SavedImportPaths.erase(FromD); | |||
8861 | ||||
8862 | // Do not return ToDOrErr, error was taken out of it. | |||
8863 | return make_error<ImportError>(ErrOut); | |||
8864 | } | |||
8865 | ||||
8866 | ToD = *ToDOrErr; | |||
8867 | ||||
8868 | // FIXME: Handle the "already imported with error" case. We can get here | |||
8869 | // nullptr only if GetImportedOrCreateDecl returned nullptr (after a | |||
8870 | // previously failed create was requested). | |||
8871 | // Later GetImportedOrCreateDecl can be updated to return the error. | |||
8872 | if (!ToD) { | |||
8873 | auto Err = getImportDeclErrorIfAny(FromD); | |||
8874 | assert(Err)(static_cast <bool> (Err) ? void (0) : __assert_fail ("Err" , "clang/lib/AST/ASTImporter.cpp", 8874, __extension__ __PRETTY_FUNCTION__ )); | |||
8875 | return make_error<ImportError>(*Err); | |||
8876 | } | |||
8877 | ||||
8878 | // We could import from the current TU without error. But previously we | |||
8879 | // already had imported a Decl as `ToD` from another TU (with another | |||
8880 | // ASTImporter object) and with an error. | |||
8881 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { | |||
8882 | setImportDeclError(FromD, *Error); | |||
8883 | return make_error<ImportError>(*Error); | |||
8884 | } | |||
8885 | ||||
8886 | // Make sure that ImportImpl registered the imported decl. | |||
8887 | assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?")(static_cast <bool> (ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?") ? void (0) : __assert_fail ( "ImportedDecls.count(FromD) != 0 && \"Missing call to MapImported?\"" , "clang/lib/AST/ASTImporter.cpp", 8887, __extension__ __PRETTY_FUNCTION__ )); | |||
8888 | ||||
8889 | if (FromD->hasAttrs()) | |||
8890 | for (const Attr *FromAttr : FromD->getAttrs()) { | |||
8891 | auto ToAttrOrErr = Import(FromAttr); | |||
8892 | if (ToAttrOrErr) | |||
8893 | ToD->addAttr(*ToAttrOrErr); | |||
8894 | else | |||
8895 | return ToAttrOrErr.takeError(); | |||
8896 | } | |||
8897 | ||||
8898 | // Notify subclasses. | |||
8899 | Imported(FromD, ToD); | |||
8900 | ||||
8901 | updateFlags(FromD, ToD); | |||
8902 | SavedImportPaths.erase(FromD); | |||
8903 | return ToDOrErr; | |||
8904 | } | |||
8905 | ||||
8906 | llvm::Expected<InheritedConstructor> | |||
8907 | ASTImporter::Import(const InheritedConstructor &From) { | |||
8908 | return ASTNodeImporter(*this).ImportInheritedConstructor(From); | |||
8909 | } | |||
8910 | ||||
8911 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { | |||
8912 | if (!FromDC) | |||
8913 | return FromDC; | |||
8914 | ||||
8915 | ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC)); | |||
8916 | if (!ToDCOrErr) | |||
8917 | return ToDCOrErr.takeError(); | |||
8918 | auto *ToDC = cast<DeclContext>(*ToDCOrErr); | |||
8919 | ||||
8920 | // When we're using a record/enum/Objective-C class/protocol as a context, we | |||
8921 | // need it to have a definition. | |||
8922 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { | |||
8923 | auto *FromRecord = cast<RecordDecl>(FromDC); | |||
8924 | if (ToRecord->isCompleteDefinition()) | |||
8925 | return ToDC; | |||
8926 | ||||
8927 | // If FromRecord is not defined we need to force it to be. | |||
8928 | // Simply calling CompleteDecl(...) for a RecordDecl will break some cases | |||
8929 | // it will start the definition but we never finish it. | |||
8930 | // If there are base classes they won't be imported and we will | |||
8931 | // be missing anything that we inherit from those bases. | |||
8932 | if (FromRecord->getASTContext().getExternalSource() && | |||
8933 | !FromRecord->isCompleteDefinition()) | |||
8934 | FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord); | |||
8935 | ||||
8936 | if (FromRecord->isCompleteDefinition()) | |||
8937 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | |||
8938 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) | |||
8939 | return std::move(Err); | |||
8940 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { | |||
8941 | auto *FromEnum = cast<EnumDecl>(FromDC); | |||
8942 | if (ToEnum->isCompleteDefinition()) { | |||
8943 | // Do nothing. | |||
8944 | } else if (FromEnum->isCompleteDefinition()) { | |||
8945 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | |||
8946 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) | |||
8947 | return std::move(Err); | |||
8948 | } else { | |||
8949 | CompleteDecl(ToEnum); | |||
8950 | } | |||
8951 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { | |||
8952 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); | |||
8953 | if (ToClass->getDefinition()) { | |||
8954 | // Do nothing. | |||
8955 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { | |||
8956 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | |||
8957 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) | |||
8958 | return std::move(Err); | |||
8959 | } else { | |||
8960 | CompleteDecl(ToClass); | |||
8961 | } | |||
8962 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { | |||
8963 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); | |||
8964 | if (ToProto->getDefinition()) { | |||
8965 | // Do nothing. | |||
8966 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { | |||
8967 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | |||
8968 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) | |||
8969 | return std::move(Err); | |||
8970 | } else { | |||
8971 | CompleteDecl(ToProto); | |||
8972 | } | |||
8973 | } | |||
8974 | ||||
8975 | return ToDC; | |||
8976 | } | |||
8977 | ||||
8978 | Expected<Expr *> ASTImporter::Import(Expr *FromE) { | |||
8979 | if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE))) | |||
8980 | return cast_or_null<Expr>(*ToSOrErr); | |||
8981 | else | |||
8982 | return ToSOrErr.takeError(); | |||
8983 | } | |||
8984 | ||||
8985 | Expected<Stmt *> ASTImporter::Import(Stmt *FromS) { | |||
8986 | if (!FromS) | |||
8987 | return nullptr; | |||
8988 | ||||
8989 | // Check whether we've already imported this statement. | |||
8990 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); | |||
8991 | if (Pos != ImportedStmts.end()) | |||
8992 | return Pos->second; | |||
8993 | ||||
8994 | // Import the statement. | |||
8995 | ASTNodeImporter Importer(*this); | |||
8996 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); | |||
8997 | if (!ToSOrErr) | |||
8998 | return ToSOrErr; | |||
8999 | ||||
9000 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { | |||
9001 | auto *FromE = cast<Expr>(FromS); | |||
9002 | // Copy ExprBitfields, which may not be handled in Expr subclasses | |||
9003 | // constructors. | |||
9004 | ToE->setValueKind(FromE->getValueKind()); | |||
9005 | ToE->setObjectKind(FromE->getObjectKind()); | |||
9006 | ToE->setDependence(FromE->getDependence()); | |||
9007 | } | |||
9008 | ||||
9009 | // Record the imported statement object. | |||
9010 | ImportedStmts[FromS] = *ToSOrErr; | |||
9011 | return ToSOrErr; | |||
9012 | } | |||
9013 | ||||
9014 | Expected<NestedNameSpecifier *> | |||
9015 | ASTImporter::Import(NestedNameSpecifier *FromNNS) { | |||
9016 | if (!FromNNS) | |||
9017 | return nullptr; | |||
9018 | ||||
9019 | NestedNameSpecifier *Prefix = nullptr; | |||
9020 | if (Error Err = importInto(Prefix, FromNNS->getPrefix())) | |||
9021 | return std::move(Err); | |||
9022 | ||||
9023 | switch (FromNNS->getKind()) { | |||
9024 | case NestedNameSpecifier::Identifier: | |||
9025 | assert(FromNNS->getAsIdentifier() && "NNS should contain identifier.")(static_cast <bool> (FromNNS->getAsIdentifier() && "NNS should contain identifier.") ? void (0) : __assert_fail ("FromNNS->getAsIdentifier() && \"NNS should contain identifier.\"" , "clang/lib/AST/ASTImporter.cpp", 9025, __extension__ __PRETTY_FUNCTION__ )); | |||
9026 | return NestedNameSpecifier::Create(ToContext, Prefix, | |||
9027 | Import(FromNNS->getAsIdentifier())); | |||
9028 | ||||
9029 | case NestedNameSpecifier::Namespace: | |||
9030 | if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) { | |||
9031 | return NestedNameSpecifier::Create(ToContext, Prefix, | |||
9032 | cast<NamespaceDecl>(*NSOrErr)); | |||
9033 | } else | |||
9034 | return NSOrErr.takeError(); | |||
9035 | ||||
9036 | case NestedNameSpecifier::NamespaceAlias: | |||
9037 | if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias())) | |||
9038 | return NestedNameSpecifier::Create(ToContext, Prefix, | |||
9039 | cast<NamespaceAliasDecl>(*NSADOrErr)); | |||
9040 | else | |||
9041 | return NSADOrErr.takeError(); | |||
9042 | ||||
9043 | case NestedNameSpecifier::Global: | |||
9044 | return NestedNameSpecifier::GlobalSpecifier(ToContext); | |||
9045 | ||||
9046 | case NestedNameSpecifier::Super: | |||
9047 | if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl())) | |||
9048 | return NestedNameSpecifier::SuperSpecifier(ToContext, | |||
9049 | cast<CXXRecordDecl>(*RDOrErr)); | |||
9050 | else | |||
9051 | return RDOrErr.takeError(); | |||
9052 | ||||
9053 | case NestedNameSpecifier::TypeSpec: | |||
9054 | case NestedNameSpecifier::TypeSpecWithTemplate: | |||
9055 | if (ExpectedTypePtr TyOrErr = Import(FromNNS->getAsType())) { | |||
9056 | bool TSTemplate = | |||
9057 | FromNNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate; | |||
9058 | return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate, | |||
9059 | *TyOrErr); | |||
9060 | } else { | |||
9061 | return TyOrErr.takeError(); | |||
9062 | } | |||
9063 | } | |||
9064 | ||||
9065 | llvm_unreachable("Invalid nested name specifier kind")::llvm::llvm_unreachable_internal("Invalid nested name specifier kind" , "clang/lib/AST/ASTImporter.cpp", 9065); | |||
9066 | } | |||
9067 | ||||
9068 | Expected<NestedNameSpecifierLoc> | |||
9069 | ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { | |||
9070 | // Copied from NestedNameSpecifier mostly. | |||
9071 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; | |||
9072 | NestedNameSpecifierLoc NNS = FromNNS; | |||
9073 | ||||
9074 | // Push each of the nested-name-specifiers's onto a stack for | |||
9075 | // serialization in reverse order. | |||
9076 | while (NNS) { | |||
9077 | NestedNames.push_back(NNS); | |||
9078 | NNS = NNS.getPrefix(); | |||
9079 | } | |||
9080 | ||||
9081 | NestedNameSpecifierLocBuilder Builder; | |||
9082 | ||||
9083 | while (!NestedNames.empty()) { | |||
9084 | NNS = NestedNames.pop_back_val(); | |||
9085 | NestedNameSpecifier *Spec = nullptr; | |||
9086 | if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier())) | |||
9087 | return std::move(Err); | |||
9088 | ||||
9089 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); | |||
9090 | ||||
9091 | SourceLocation ToLocalBeginLoc, ToLocalEndLoc; | |||
9092 | if (Kind != NestedNameSpecifier::Super) { | |||
9093 | if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc())) | |||
9094 | return std::move(Err); | |||
9095 | ||||
9096 | if (Kind != NestedNameSpecifier::Global) | |||
9097 | if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc())) | |||
9098 | return std::move(Err); | |||
9099 | } | |||
9100 | ||||
9101 | switch (Kind) { | |||
9102 | case NestedNameSpecifier::Identifier: | |||
9103 | Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc, | |||
9104 | ToLocalEndLoc); | |||
9105 | break; | |||
9106 | ||||
9107 | case NestedNameSpecifier::Namespace: | |||
9108 | Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc, | |||
9109 | ToLocalEndLoc); | |||
9110 | break; | |||
9111 | ||||
9112 | case NestedNameSpecifier::NamespaceAlias: | |||
9113 | Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(), | |||
9114 | ToLocalBeginLoc, ToLocalEndLoc); | |||
9115 | break; | |||
9116 | ||||
9117 | case NestedNameSpecifier::TypeSpec: | |||
9118 | case NestedNameSpecifier::TypeSpecWithTemplate: { | |||
9119 | SourceLocation ToTLoc; | |||
9120 | if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc())) | |||
9121 | return std::move(Err); | |||
9122 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( | |||
9123 | QualType(Spec->getAsType(), 0), ToTLoc); | |||
9124 | if (Kind == NestedNameSpecifier::TypeSpecWithTemplate) | |||
9125 | // ToLocalBeginLoc is here the location of the 'template' keyword. | |||
9126 | Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(), | |||
9127 | ToLocalEndLoc); | |||
9128 | else | |||
9129 | // No location for 'template' keyword here. | |||
9130 | Builder.Extend(getToContext(), SourceLocation{}, TSI->getTypeLoc(), | |||
9131 | ToLocalEndLoc); | |||
9132 | break; | |||
9133 | } | |||
9134 | ||||
9135 | case NestedNameSpecifier::Global: | |||
9136 | Builder.MakeGlobal(getToContext(), ToLocalBeginLoc); | |||
9137 | break; | |||
9138 | ||||
9139 | case NestedNameSpecifier::Super: { | |||
9140 | auto ToSourceRangeOrErr = Import(NNS.getSourceRange()); | |||
9141 | if (!ToSourceRangeOrErr) | |||
9142 | return ToSourceRangeOrErr.takeError(); | |||
9143 | ||||
9144 | Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(), | |||
9145 | ToSourceRangeOrErr->getBegin(), | |||
9146 | ToSourceRangeOrErr->getEnd()); | |||
9147 | } | |||
9148 | } | |||
9149 | } | |||
9150 | ||||
9151 | return Builder.getWithLocInContext(getToContext()); | |||
9152 | } | |||
9153 | ||||
9154 | Expected<TemplateName> ASTImporter::Import(TemplateName From) { | |||
9155 | switch (From.getKind()) { | |||
9156 | case TemplateName::Template: | |||
9157 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) | |||
9158 | return TemplateName(cast<TemplateDecl>(*ToTemplateOrErr)); | |||
9159 | else | |||
9160 | return ToTemplateOrErr.takeError(); | |||
9161 | ||||
9162 | case TemplateName::OverloadedTemplate: { | |||
9163 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); | |||
9164 | UnresolvedSet<2> ToTemplates; | |||
9165 | for (auto *I : *FromStorage) { | |||
9166 | if (auto ToOrErr = Import(I)) | |||
9167 | ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr)); | |||
9168 | else | |||
9169 | return ToOrErr.takeError(); | |||
9170 | } | |||
9171 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), | |||
9172 | ToTemplates.end()); | |||
9173 | } | |||
9174 | ||||
9175 | case TemplateName::AssumedTemplate: { | |||
9176 | AssumedTemplateStorage *FromStorage = From.getAsAssumedTemplateName(); | |||
9177 | auto DeclNameOrErr = Import(FromStorage->getDeclName()); | |||
9178 | if (!DeclNameOrErr) | |||
9179 | return DeclNameOrErr.takeError(); | |||
9180 | return ToContext.getAssumedTemplateName(*DeclNameOrErr); | |||
9181 | } | |||
9182 | ||||
9183 | case TemplateName::QualifiedTemplate: { | |||
9184 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); | |||
9185 | auto QualifierOrErr = Import(QTN->getQualifier()); | |||
9186 | if (!QualifierOrErr) | |||
9187 | return QualifierOrErr.takeError(); | |||
9188 | ||||
9189 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) | |||
9190 | return ToContext.getQualifiedTemplateName( | |||
9191 | *QualifierOrErr, QTN->hasTemplateKeyword(), | |||
9192 | cast<TemplateDecl>(*ToTemplateOrErr)); | |||
9193 | else | |||
9194 | return ToTemplateOrErr.takeError(); | |||
9195 | } | |||
9196 | ||||
9197 | case TemplateName::DependentTemplate: { | |||
9198 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); | |||
9199 | auto QualifierOrErr = Import(DTN->getQualifier()); | |||
9200 | if (!QualifierOrErr) | |||
9201 | return QualifierOrErr.takeError(); | |||
9202 | ||||
9203 | if (DTN->isIdentifier()) { | |||
9204 | return ToContext.getDependentTemplateName(*QualifierOrErr, | |||
9205 | Import(DTN->getIdentifier())); | |||
9206 | } | |||
9207 | ||||
9208 | return ToContext.getDependentTemplateName(*QualifierOrErr, | |||
9209 | DTN->getOperator()); | |||
9210 | } | |||
9211 | ||||
9212 | case TemplateName::SubstTemplateTemplateParm: { | |||
9213 | SubstTemplateTemplateParmStorage *Subst = | |||
9214 | From.getAsSubstTemplateTemplateParm(); | |||
9215 | ExpectedDecl ParamOrErr = Import(Subst->getParameter()); | |||
9216 | if (!ParamOrErr) | |||
9217 | return ParamOrErr.takeError(); | |||
9218 | ||||
9219 | auto ReplacementOrErr = Import(Subst->getReplacement()); | |||
9220 | if (!ReplacementOrErr) | |||
9221 | return ReplacementOrErr.takeError(); | |||
9222 | ||||
9223 | return ToContext.getSubstTemplateTemplateParm( | |||
9224 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ReplacementOrErr); | |||
9225 | } | |||
9226 | ||||
9227 | case TemplateName::SubstTemplateTemplateParmPack: { | |||
9228 | SubstTemplateTemplateParmPackStorage *SubstPack | |||
9229 | = From.getAsSubstTemplateTemplateParmPack(); | |||
9230 | ExpectedDecl ParamOrErr = Import(SubstPack->getParameterPack()); | |||
9231 | if (!ParamOrErr) | |||
9232 | return ParamOrErr.takeError(); | |||
9233 | ||||
9234 | ASTNodeImporter Importer(*this); | |||
9235 | auto ArgPackOrErr = | |||
9236 | Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); | |||
9237 | if (!ArgPackOrErr) | |||
9238 | return ArgPackOrErr.takeError(); | |||
9239 | ||||
9240 | return ToContext.getSubstTemplateTemplateParmPack( | |||
9241 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ArgPackOrErr); | |||
9242 | } | |||
9243 | case TemplateName::UsingTemplate: { | |||
9244 | auto UsingOrError = Import(From.getAsUsingShadowDecl()); | |||
9245 | if (!UsingOrError) | |||
9246 | return UsingOrError.takeError(); | |||
9247 | return TemplateName(cast<UsingShadowDecl>(*UsingOrError)); | |||
9248 | } | |||
9249 | } | |||
9250 | ||||
9251 | llvm_unreachable("Invalid template name kind")::llvm::llvm_unreachable_internal("Invalid template name kind" , "clang/lib/AST/ASTImporter.cpp", 9251); | |||
9252 | } | |||
9253 | ||||
9254 | Expected<SourceLocation> ASTImporter::Import(SourceLocation FromLoc) { | |||
9255 | if (FromLoc.isInvalid()) | |||
9256 | return SourceLocation{}; | |||
9257 | ||||
9258 | SourceManager &FromSM = FromContext.getSourceManager(); | |||
9259 | bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc); | |||
9260 | ||||
9261 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); | |||
9262 | Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin); | |||
9263 | if (!ToFileIDOrErr) | |||
9264 | return ToFileIDOrErr.takeError(); | |||
9265 | SourceManager &ToSM = ToContext.getSourceManager(); | |||
9266 | return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second); | |||
9267 | } | |||
9268 | ||||
9269 | Expected<SourceRange> ASTImporter::Import(SourceRange FromRange) { | |||
9270 | SourceLocation ToBegin, ToEnd; | |||
9271 | if (Error Err = importInto(ToBegin, FromRange.getBegin())) | |||
9272 | return std::move(Err); | |||
9273 | if (Error Err = importInto(ToEnd, FromRange.getEnd())) | |||
9274 | return std::move(Err); | |||
9275 | ||||
9276 | return SourceRange(ToBegin, ToEnd); | |||
9277 | } | |||
9278 | ||||
9279 | Expected<FileID> ASTImporter::Import(FileID FromID, bool IsBuiltin) { | |||
9280 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); | |||
9281 | if (Pos != ImportedFileIDs.end()) | |||
9282 | return Pos->second; | |||
9283 | ||||
9284 | SourceManager &FromSM = FromContext.getSourceManager(); | |||
9285 | SourceManager &ToSM = ToContext.getSourceManager(); | |||
9286 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); | |||
9287 | ||||
9288 | // Map the FromID to the "to" source manager. | |||
9289 | FileID ToID; | |||
9290 | if (FromSLoc.isExpansion()) { | |||
9291 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); | |||
9292 | ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc()); | |||
9293 | if (!ToSpLoc) | |||
9294 | return ToSpLoc.takeError(); | |||
9295 | ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart()); | |||
9296 | if (!ToExLocS) | |||
9297 | return ToExLocS.takeError(); | |||
9298 | unsigned TokenLen = FromSM.getFileIDSize(FromID); | |||
9299 | SourceLocation MLoc; | |||
9300 | if (FromEx.isMacroArgExpansion()) { | |||
9301 | MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, TokenLen); | |||
9302 | } else { | |||
9303 | if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd())) | |||
9304 | MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, TokenLen, | |||
9305 | FromEx.isExpansionTokenRange()); | |||
9306 | else | |||
9307 | return ToExLocE.takeError(); | |||
9308 | } | |||
9309 | ToID = ToSM.getFileID(MLoc); | |||
9310 | } else { | |||
9311 | const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache(); | |||
9312 | ||||
9313 | if (!IsBuiltin && !Cache->BufferOverridden) { | |||
9314 | // Include location of this file. | |||
9315 | ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); | |||
9316 | if (!ToIncludeLoc) | |||
9317 | return ToIncludeLoc.takeError(); | |||
9318 | ||||
9319 | // Every FileID that is not the main FileID needs to have a valid include | |||
9320 | // location so that the include chain points to the main FileID. When | |||
9321 | // importing the main FileID (which has no include location), we need to | |||
9322 | // create a fake include location in the main file to keep this property | |||
9323 | // intact. | |||
9324 | SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc; | |||
9325 | if (FromID == FromSM.getMainFileID()) | |||
9326 | ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID()); | |||
9327 | ||||
9328 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { | |||
9329 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the | |||
9330 | // disk again | |||
9331 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather | |||
9332 | // than mmap the files several times. | |||
9333 | auto Entry = | |||
9334 | ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName()); | |||
9335 | // FIXME: The filename may be a virtual name that does probably not | |||
9336 | // point to a valid file and we get no Entry here. In this case try with | |||
9337 | // the memory buffer below. | |||
9338 | if (Entry) | |||
9339 | ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc, | |||
9340 | FromSLoc.getFile().getFileCharacteristic()); | |||
9341 | } | |||
9342 | } | |||
9343 | ||||
9344 | if (ToID.isInvalid() || IsBuiltin) { | |||
9345 | // FIXME: We want to re-use the existing MemoryBuffer! | |||
9346 | llvm::Optional<llvm::MemoryBufferRef> FromBuf = | |||
9347 | Cache->getBufferOrNone(FromContext.getDiagnostics(), | |||
9348 | FromSM.getFileManager(), SourceLocation{}); | |||
9349 | if (!FromBuf) | |||
9350 | return llvm::make_error<ImportError>(ImportError::Unknown); | |||
9351 | ||||
9352 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = | |||
9353 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), | |||
9354 | FromBuf->getBufferIdentifier()); | |||
9355 | ToID = ToSM.createFileID(std::move(ToBuf), | |||
9356 | FromSLoc.getFile().getFileCharacteristic()); | |||
9357 | } | |||
9358 | } | |||
9359 | ||||
9360 | assert(ToID.isValid() && "Unexpected invalid fileID was created.")(static_cast <bool> (ToID.isValid() && "Unexpected invalid fileID was created." ) ? void (0) : __assert_fail ("ToID.isValid() && \"Unexpected invalid fileID was created.\"" , "clang/lib/AST/ASTImporter.cpp", 9360, __extension__ __PRETTY_FUNCTION__ )); | |||
9361 | ||||
9362 | ImportedFileIDs[FromID] = ToID; | |||
9363 | return ToID; | |||
9364 | } | |||
9365 | ||||
9366 | Expected<CXXCtorInitializer *> ASTImporter::Import(CXXCtorInitializer *From) { | |||
9367 | ExpectedExpr ToExprOrErr = Import(From->getInit()); | |||
9368 | if (!ToExprOrErr) | |||
9369 | return ToExprOrErr.takeError(); | |||
9370 | ||||
9371 | auto LParenLocOrErr = Import(From->getLParenLoc()); | |||
9372 | if (!LParenLocOrErr) | |||
9373 | return LParenLocOrErr.takeError(); | |||
9374 | ||||
9375 | auto RParenLocOrErr = Import(From->getRParenLoc()); | |||
9376 | if (!RParenLocOrErr) | |||
9377 | return RParenLocOrErr.takeError(); | |||
9378 | ||||
9379 | if (From->isBaseInitializer()) { | |||
9380 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); | |||
9381 | if (!ToTInfoOrErr) | |||
9382 | return ToTInfoOrErr.takeError(); | |||
9383 | ||||
9384 | SourceLocation EllipsisLoc; | |||
9385 | if (From->isPackExpansion()) | |||
9386 | if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc())) | |||
9387 | return std::move(Err); | |||
9388 | ||||
9389 | return new (ToContext) CXXCtorInitializer( | |||
9390 | ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr, | |||
9391 | *ToExprOrErr, *RParenLocOrErr, EllipsisLoc); | |||
9392 | } else if (From->isMemberInitializer()) { | |||
9393 | ExpectedDecl ToFieldOrErr = Import(From->getMember()); | |||
9394 | if (!ToFieldOrErr) | |||
9395 | return ToFieldOrErr.takeError(); | |||
9396 | ||||
9397 | auto MemberLocOrErr = Import(From->getMemberLocation()); | |||
9398 | if (!MemberLocOrErr) | |||
9399 | return MemberLocOrErr.takeError(); | |||
9400 | ||||
9401 | return new (ToContext) CXXCtorInitializer( | |||
9402 | ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr, | |||
9403 | *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); | |||
9404 | } else if (From->isIndirectMemberInitializer()) { | |||
9405 | ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember()); | |||
9406 | if (!ToIFieldOrErr) | |||
9407 | return ToIFieldOrErr.takeError(); | |||
9408 | ||||
9409 | auto MemberLocOrErr = Import(From->getMemberLocation()); | |||
9410 | if (!MemberLocOrErr) | |||
9411 | return MemberLocOrErr.takeError(); | |||
9412 | ||||
9413 | return new (ToContext) CXXCtorInitializer( | |||
9414 | ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr), | |||
9415 | *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); | |||
9416 | } else if (From->isDelegatingInitializer()) { | |||
9417 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); | |||
9418 | if (!ToTInfoOrErr) | |||
9419 | return ToTInfoOrErr.takeError(); | |||
9420 | ||||
9421 | return new (ToContext) | |||
9422 | CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr, | |||
9423 | *ToExprOrErr, *RParenLocOrErr); | |||
9424 | } else { | |||
9425 | // FIXME: assert? | |||
9426 | return make_error<ImportError>(); | |||
9427 | } | |||
9428 | } | |||
9429 | ||||
9430 | Expected<CXXBaseSpecifier *> | |||
9431 | ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { | |||
9432 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); | |||
9433 | if (Pos != ImportedCXXBaseSpecifiers.end()) | |||
9434 | return Pos->second; | |||
9435 | ||||
9436 | Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange()); | |||
9437 | if (!ToSourceRange) | |||
9438 | return ToSourceRange.takeError(); | |||
9439 | Expected<TypeSourceInfo *> ToTSI = Import(BaseSpec->getTypeSourceInfo()); | |||
9440 | if (!ToTSI) | |||
9441 | return ToTSI.takeError(); | |||
9442 | ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc()); | |||
9443 | if (!ToEllipsisLoc) | |||
9444 | return ToEllipsisLoc.takeError(); | |||
9445 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( | |||
9446 | *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), | |||
9447 | BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc); | |||
9448 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; | |||
9449 | return Imported; | |||
9450 | } | |||
9451 | ||||
9452 | llvm::Expected<APValue> ASTImporter::Import(const APValue &FromValue) { | |||
9453 | ASTNodeImporter Importer(*this); | |||
9454 | return Importer.ImportAPValue(FromValue); | |||
9455 | } | |||
9456 | ||||
9457 | Error ASTImporter::ImportDefinition(Decl *From) { | |||
9458 | ExpectedDecl ToOrErr = Import(From); | |||
9459 | if (!ToOrErr) | |||
9460 | return ToOrErr.takeError(); | |||
9461 | Decl *To = *ToOrErr; | |||
9462 | ||||
9463 | auto *FromDC = cast<DeclContext>(From); | |||
9464 | ASTNodeImporter Importer(*this); | |||
9465 | ||||
9466 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { | |||
9467 | if (!ToRecord->getDefinition()) { | |||
9468 | return Importer.ImportDefinition( | |||
9469 | cast<RecordDecl>(FromDC), ToRecord, | |||
9470 | ASTNodeImporter::IDK_Everything); | |||
9471 | } | |||
9472 | } | |||
9473 | ||||
9474 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { | |||
9475 | if (!ToEnum->getDefinition()) { | |||
9476 | return Importer.ImportDefinition( | |||
9477 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); | |||
9478 | } | |||
9479 | } | |||
9480 | ||||
9481 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { | |||
9482 | if (!ToIFace->getDefinition()) { | |||
9483 | return Importer.ImportDefinition( | |||
9484 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, | |||
9485 | ASTNodeImporter::IDK_Everything); | |||
9486 | } | |||
9487 | } | |||
9488 | ||||
9489 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { | |||
9490 | if (!ToProto->getDefinition()) { | |||
9491 | return Importer.ImportDefinition( | |||
9492 | cast<ObjCProtocolDecl>(FromDC), ToProto, | |||
9493 | ASTNodeImporter::IDK_Everything); | |||
9494 | } | |||
9495 | } | |||
9496 | ||||
9497 | return Importer.ImportDeclContext(FromDC, true); | |||
9498 | } | |||
9499 | ||||
9500 | Expected<DeclarationName> ASTImporter::Import(DeclarationName FromName) { | |||
9501 | if (!FromName) | |||
9502 | return DeclarationName{}; | |||
9503 | ||||
9504 | switch (FromName.getNameKind()) { | |||
9505 | case DeclarationName::Identifier: | |||
9506 | return DeclarationName(Import(FromName.getAsIdentifierInfo())); | |||
9507 | ||||
9508 | case DeclarationName::ObjCZeroArgSelector: | |||
9509 | case DeclarationName::ObjCOneArgSelector: | |||
9510 | case DeclarationName::ObjCMultiArgSelector: | |||
9511 | if (auto ToSelOrErr = Import(FromName.getObjCSelector())) | |||
9512 | return DeclarationName(*ToSelOrErr); | |||
9513 | else | |||
9514 | return ToSelOrErr.takeError(); | |||
9515 | ||||
9516 | case DeclarationName::CXXConstructorName: { | |||
9517 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) | |||
9518 | return ToContext.DeclarationNames.getCXXConstructorName( | |||
9519 | ToContext.getCanonicalType(*ToTyOrErr)); | |||
9520 | else | |||
9521 | return ToTyOrErr.takeError(); | |||
9522 | } | |||
9523 | ||||
9524 | case DeclarationName::CXXDestructorName: { | |||
9525 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) | |||
9526 | return ToContext.DeclarationNames.getCXXDestructorName( | |||
9527 | ToContext.getCanonicalType(*ToTyOrErr)); | |||
9528 | else | |||
9529 | return ToTyOrErr.takeError(); | |||
9530 | } | |||
9531 | ||||
9532 | case DeclarationName::CXXDeductionGuideName: { | |||
9533 | if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate())) | |||
9534 | return ToContext.DeclarationNames.getCXXDeductionGuideName( | |||
9535 | cast<TemplateDecl>(*ToTemplateOrErr)); | |||
9536 | else | |||
9537 | return ToTemplateOrErr.takeError(); | |||
9538 | } | |||
9539 | ||||
9540 | case DeclarationName::CXXConversionFunctionName: { | |||
9541 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) | |||
9542 | return ToContext.DeclarationNames.getCXXConversionFunctionName( | |||
9543 | ToContext.getCanonicalType(*ToTyOrErr)); | |||
9544 | else | |||
9545 | return ToTyOrErr.takeError(); | |||
9546 | } | |||
9547 | ||||
9548 | case DeclarationName::CXXOperatorName: | |||
9549 | return ToContext.DeclarationNames.getCXXOperatorName( | |||
9550 | FromName.getCXXOverloadedOperator()); | |||
9551 | ||||
9552 | case DeclarationName::CXXLiteralOperatorName: | |||
9553 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( | |||
9554 | Import(FromName.getCXXLiteralIdentifier())); | |||
9555 | ||||
9556 | case DeclarationName::CXXUsingDirective: | |||
9557 | // FIXME: STATICS! | |||
9558 | return DeclarationName::getUsingDirectiveName(); | |||
9559 | } | |||
9560 | ||||
9561 | llvm_unreachable("Invalid DeclarationName Kind!")::llvm::llvm_unreachable_internal("Invalid DeclarationName Kind!" , "clang/lib/AST/ASTImporter.cpp", 9561); | |||
9562 | } | |||
9563 | ||||
9564 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { | |||
9565 | if (!FromId) | |||
9566 | return nullptr; | |||
9567 | ||||
9568 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); | |||
9569 | ||||
9570 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) | |||
9571 | ToId->setBuiltinID(FromId->getBuiltinID()); | |||
9572 | ||||
9573 | return ToId; | |||
9574 | } | |||
9575 | ||||
9576 | Expected<Selector> ASTImporter::Import(Selector FromSel) { | |||
9577 | if (FromSel.isNull()) | |||
9578 | return Selector{}; | |||
9579 | ||||
9580 | SmallVector<IdentifierInfo *, 4> Idents; | |||
9581 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); | |||
9582 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) | |||
9583 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); | |||
9584 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); | |||
9585 | } | |||
9586 | ||||
9587 | llvm::Expected<APValue> | |||
9588 | ASTNodeImporter::ImportAPValue(const APValue &FromValue) { | |||
9589 | APValue Result; | |||
9590 | llvm::Error Err = llvm::Error::success(); | |||
9591 | auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) { | |||
9592 | for (unsigned Idx = 0; Idx < Size; Idx++) { | |||
9593 | APValue Tmp = importChecked(Err, From[Idx]); | |||
9594 | To[Idx] = Tmp; | |||
9595 | } | |||
9596 | }; | |||
9597 | switch (FromValue.getKind()) { | |||
9598 | case APValue::None: | |||
9599 | case APValue::Indeterminate: | |||
9600 | case APValue::Int: | |||
9601 | case APValue::Float: | |||
9602 | case APValue::FixedPoint: | |||
9603 | case APValue::ComplexInt: | |||
9604 | case APValue::ComplexFloat: | |||
9605 | Result = FromValue; | |||
9606 | break; | |||
9607 | case APValue::Vector: { | |||
9608 | Result.MakeVector(); | |||
9609 | MutableArrayRef<APValue> Elts = | |||
9610 | Result.setVectorUninit(FromValue.getVectorLength()); | |||
9611 | ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts, | |||
9612 | Elts.data(), FromValue.getVectorLength()); | |||
9613 | break; | |||
9614 | } | |||
9615 | case APValue::Array: | |||
9616 | Result.MakeArray(FromValue.getArrayInitializedElts(), | |||
9617 | FromValue.getArraySize()); | |||
9618 | ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts, | |||
9619 | ((const APValue::Arr *)(const char *)&Result.Data)->Elts, | |||
9620 | FromValue.getArrayInitializedElts()); | |||
9621 | break; | |||
9622 | case APValue::Struct: | |||
9623 | Result.MakeStruct(FromValue.getStructNumBases(), | |||
9624 | FromValue.getStructNumFields()); | |||
9625 | ImportLoop( | |||
9626 | ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts, | |||
9627 | ((const APValue::StructData *)(const char *)&Result.Data)->Elts, | |||
9628 | FromValue.getStructNumBases() + FromValue.getStructNumFields()); | |||
9629 | break; | |||
9630 | case APValue::Union: { | |||
9631 | Result.MakeUnion(); | |||
9632 | const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField()); | |||
9633 | APValue ImpValue = importChecked(Err, FromValue.getUnionValue()); | |||
9634 | if (Err) | |||
9635 | return std::move(Err); | |||
9636 | Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue); | |||
9637 | break; | |||
9638 | } | |||
9639 | case APValue::AddrLabelDiff: { | |||
9640 | Result.MakeAddrLabelDiff(); | |||
9641 | const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS()); | |||
9642 | const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS()); | |||
9643 | if (Err) | |||
9644 | return std::move(Err); | |||
9645 | Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS), | |||
9646 | cast<AddrLabelExpr>(ImpRHS)); | |||
9647 | break; | |||
9648 | } | |||
9649 | case APValue::MemberPointer: { | |||
9650 | const Decl *ImpMemPtrDecl = | |||
9651 | importChecked(Err, FromValue.getMemberPointerDecl()); | |||
9652 | if (Err) | |||
9653 | return std::move(Err); | |||
9654 | MutableArrayRef<const CXXRecordDecl *> ToPath = | |||
9655 | Result.setMemberPointerUninit( | |||
9656 | cast<const ValueDecl>(ImpMemPtrDecl), | |||
9657 | FromValue.isMemberPointerToDerivedMember(), | |||
9658 | FromValue.getMemberPointerPath().size()); | |||
9659 | llvm::ArrayRef<const CXXRecordDecl *> FromPath = | |||
9660 | Result.getMemberPointerPath(); | |||
9661 | for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size(); | |||
9662 | Idx++) { | |||
9663 | const Decl *ImpDecl = importChecked(Err, FromPath[Idx]); | |||
9664 | if (Err) | |||
9665 | return std::move(Err); | |||
9666 | ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl()); | |||
9667 | } | |||
9668 | break; | |||
9669 | } | |||
9670 | case APValue::LValue: | |||
9671 | APValue::LValueBase Base; | |||
9672 | QualType FromElemTy; | |||
9673 | if (FromValue.getLValueBase()) { | |||
9674 | assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&(static_cast <bool> (!FromValue.getLValueBase().is<DynamicAllocLValue >() && "in C++20 dynamic allocation are transient so they shouldn't " "appear in the AST") ? void (0) : __assert_fail ("!FromValue.getLValueBase().is<DynamicAllocLValue>() && \"in C++20 dynamic allocation are transient so they shouldn't \" \"appear in the AST\"" , "clang/lib/AST/ASTImporter.cpp", 9676, __extension__ __PRETTY_FUNCTION__ )) | |||
9675 | "in C++20 dynamic allocation are transient so they shouldn't "(static_cast <bool> (!FromValue.getLValueBase().is<DynamicAllocLValue >() && "in C++20 dynamic allocation are transient so they shouldn't " "appear in the AST") ? void (0) : __assert_fail ("!FromValue.getLValueBase().is<DynamicAllocLValue>() && \"in C++20 dynamic allocation are transient so they shouldn't \" \"appear in the AST\"" , "clang/lib/AST/ASTImporter.cpp", 9676, __extension__ __PRETTY_FUNCTION__ )) | |||
9676 | "appear in the AST")(static_cast <bool> (!FromValue.getLValueBase().is<DynamicAllocLValue >() && "in C++20 dynamic allocation are transient so they shouldn't " "appear in the AST") ? void (0) : __assert_fail ("!FromValue.getLValueBase().is<DynamicAllocLValue>() && \"in C++20 dynamic allocation are transient so they shouldn't \" \"appear in the AST\"" , "clang/lib/AST/ASTImporter.cpp", 9676, __extension__ __PRETTY_FUNCTION__ )); | |||
9677 | if (!FromValue.getLValueBase().is<TypeInfoLValue>()) { | |||
9678 | if (const auto *E = | |||
9679 | FromValue.getLValueBase().dyn_cast<const Expr *>()) { | |||
9680 | FromElemTy = E->getType(); | |||
9681 | const Expr *ImpExpr = importChecked(Err, E); | |||
9682 | if (Err) | |||
9683 | return std::move(Err); | |||
9684 | Base = APValue::LValueBase(ImpExpr, | |||
9685 | FromValue.getLValueBase().getCallIndex(), | |||
9686 | FromValue.getLValueBase().getVersion()); | |||
9687 | } else { | |||
9688 | FromElemTy = | |||
9689 | FromValue.getLValueBase().get<const ValueDecl *>()->getType(); | |||
9690 | const Decl *ImpDecl = importChecked( | |||
9691 | Err, FromValue.getLValueBase().get<const ValueDecl *>()); | |||
9692 | if (Err) | |||
9693 | return std::move(Err); | |||
9694 | Base = APValue::LValueBase(cast<ValueDecl>(ImpDecl), | |||
9695 | FromValue.getLValueBase().getCallIndex(), | |||
9696 | FromValue.getLValueBase().getVersion()); | |||
9697 | } | |||
9698 | } else { | |||
9699 | FromElemTy = FromValue.getLValueBase().getTypeInfoType(); | |||
9700 | const Type *ImpTypeInfo = importChecked( | |||
9701 | Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType()); | |||
9702 | QualType ImpType = | |||
9703 | importChecked(Err, FromValue.getLValueBase().getTypeInfoType()); | |||
9704 | if (Err) | |||
9705 | return std::move(Err); | |||
9706 | Base = APValue::LValueBase::getTypeInfo(TypeInfoLValue(ImpTypeInfo), | |||
9707 | ImpType); | |||
9708 | } | |||
9709 | } | |||
9710 | CharUnits Offset = FromValue.getLValueOffset(); | |||
9711 | unsigned PathLength = FromValue.getLValuePath().size(); | |||
9712 | Result.MakeLValue(); | |||
9713 | if (FromValue.hasLValuePath()) { | |||
9714 | MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit( | |||
9715 | Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(), | |||
9716 | FromValue.isNullPointer()); | |||
9717 | llvm::ArrayRef<APValue::LValuePathEntry> FromPath = | |||
9718 | FromValue.getLValuePath(); | |||
9719 | for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) { | |||
9720 | if (FromElemTy->isRecordType()) { | |||
9721 | const Decl *FromDecl = | |||
9722 | FromPath[LoopIdx].getAsBaseOrMember().getPointer(); | |||
9723 | const Decl *ImpDecl = importChecked(Err, FromDecl); | |||
9724 | if (Err) | |||
9725 | return std::move(Err); | |||
9726 | if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl)) | |||
9727 | FromElemTy = Importer.FromContext.getRecordType(RD); | |||
9728 | else | |||
9729 | FromElemTy = cast<ValueDecl>(FromDecl)->getType(); | |||
9730 | ToPath[LoopIdx] = APValue::LValuePathEntry(APValue::BaseOrMemberType( | |||
9731 | ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt())); | |||
9732 | } else { | |||
9733 | FromElemTy = | |||
9734 | Importer.FromContext.getAsArrayType(FromElemTy)->getElementType(); | |||
9735 | ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex( | |||
9736 | FromPath[LoopIdx].getAsArrayIndex()); | |||
9737 | } | |||
9738 | } | |||
9739 | } else | |||
9740 | Result.setLValue(Base, Offset, APValue::NoLValuePath{}, | |||
9741 | FromValue.isNullPointer()); | |||
9742 | } | |||
9743 | if (Err) | |||
9744 | return std::move(Err); | |||
9745 | return Result; | |||
9746 | } | |||
9747 | ||||
9748 | Expected<DeclarationName> ASTImporter::HandleNameConflict(DeclarationName Name, | |||
9749 | DeclContext *DC, | |||
9750 | unsigned IDNS, | |||
9751 | NamedDecl **Decls, | |||
9752 | unsigned NumDecls) { | |||
9753 | if (ODRHandling == ODRHandlingType::Conservative) | |||
9754 | // Report error at any name conflict. | |||
9755 | return make_error<ImportError>(ImportError::NameConflict); | |||
9756 | else | |||
9757 | // Allow to create the new Decl with the same name. | |||
9758 | return Name; | |||
9759 | } | |||
9760 | ||||
9761 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { | |||
9762 | if (LastDiagFromFrom) | |||
9763 | ToContext.getDiagnostics().notePriorDiagnosticFrom( | |||
9764 | FromContext.getDiagnostics()); | |||
9765 | LastDiagFromFrom = false; | |||
9766 | return ToContext.getDiagnostics().Report(Loc, DiagID); | |||
9767 | } | |||
9768 | ||||
9769 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { | |||
9770 | if (!LastDiagFromFrom) | |||
9771 | FromContext.getDiagnostics().notePriorDiagnosticFrom( | |||
9772 | ToContext.getDiagnostics()); | |||
9773 | LastDiagFromFrom = true; | |||
9774 | return FromContext.getDiagnostics().Report(Loc, DiagID); | |||
9775 | } | |||
9776 | ||||
9777 | void ASTImporter::CompleteDecl (Decl *D) { | |||
9778 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { | |||
9779 | if (!ID->getDefinition()) | |||
9780 | ID->startDefinition(); | |||
9781 | } | |||
9782 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { | |||
9783 | if (!PD->getDefinition()) | |||
9784 | PD->startDefinition(); | |||
9785 | } | |||
9786 | else if (auto *TD = dyn_cast<TagDecl>(D)) { | |||
9787 | if (!TD->getDefinition() && !TD->isBeingDefined()) { | |||
9788 | TD->startDefinition(); | |||
9789 | TD->setCompleteDefinition(true); | |||
9790 | } | |||
9791 | } | |||
9792 | else { | |||
9793 | assert(0 && "CompleteDecl called on a Decl that can't be completed")(static_cast <bool> (0 && "CompleteDecl called on a Decl that can't be completed" ) ? void (0) : __assert_fail ("0 && \"CompleteDecl called on a Decl that can't be completed\"" , "clang/lib/AST/ASTImporter.cpp", 9793, __extension__ __PRETTY_FUNCTION__ )); | |||
9794 | } | |||
9795 | } | |||
9796 | ||||
9797 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { | |||
9798 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); | |||
9799 | assert((Pos == ImportedDecls.end() || Pos->second == To) &&(static_cast <bool> ((Pos == ImportedDecls.end() || Pos ->second == To) && "Try to import an already imported Decl" ) ? void (0) : __assert_fail ("(Pos == ImportedDecls.end() || Pos->second == To) && \"Try to import an already imported Decl\"" , "clang/lib/AST/ASTImporter.cpp", 9800, __extension__ __PRETTY_FUNCTION__ )) | |||
9800 | "Try to import an already imported Decl")(static_cast <bool> ((Pos == ImportedDecls.end() || Pos ->second == To) && "Try to import an already imported Decl" ) ? void (0) : __assert_fail ("(Pos == ImportedDecls.end() || Pos->second == To) && \"Try to import an already imported Decl\"" , "clang/lib/AST/ASTImporter.cpp", 9800, __extension__ __PRETTY_FUNCTION__ )); | |||
9801 | if (Pos != ImportedDecls.end()) | |||
9802 | return Pos->second; | |||
9803 | ImportedDecls[From] = To; | |||
9804 | // This mapping should be maintained only in this function. Therefore do not | |||
9805 | // check for additional consistency. | |||
9806 | ImportedFromDecls[To] = From; | |||
9807 | // In the case of TypedefNameDecl we create the Decl first and only then we | |||
9808 | // import and set its DeclContext. So, the DC is still not set when we reach | |||
9809 | // here from GetImportedOrCreateDecl. | |||
9810 | if (To->getDeclContext()) | |||
9811 | AddToLookupTable(To); | |||
9812 | return To; | |||
9813 | } | |||
9814 | ||||
9815 | llvm::Optional<ImportError> | |||
9816 | ASTImporter::getImportDeclErrorIfAny(Decl *FromD) const { | |||
9817 | auto Pos = ImportDeclErrors.find(FromD); | |||
9818 | if (Pos != ImportDeclErrors.end()) | |||
9819 | return Pos->second; | |||
9820 | else | |||
9821 | return Optional<ImportError>(); | |||
9822 | } | |||
9823 | ||||
9824 | void ASTImporter::setImportDeclError(Decl *From, ImportError Error) { | |||
9825 | auto InsertRes = ImportDeclErrors.insert({From, Error}); | |||
9826 | (void)InsertRes; | |||
9827 | // Either we set the error for the first time, or we already had set one and | |||
9828 | // now we want to set the same error. | |||
9829 | assert(InsertRes.second || InsertRes.first->second.Error == Error.Error)(static_cast <bool> (InsertRes.second || InsertRes.first ->second.Error == Error.Error) ? void (0) : __assert_fail ( "InsertRes.second || InsertRes.first->second.Error == Error.Error" , "clang/lib/AST/ASTImporter.cpp", 9829, __extension__ __PRETTY_FUNCTION__ )); | |||
9830 | } | |||
9831 | ||||
9832 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, | |||
9833 | bool Complain) { | |||
9834 | llvm::DenseMap<const Type *, const Type *>::iterator Pos = | |||
9835 | ImportedTypes.find(From.getTypePtr()); | |||
9836 | if (Pos != ImportedTypes.end()) { | |||
9837 | if (ExpectedType ToFromOrErr = Import(From)) { | |||
9838 | if (ToContext.hasSameType(*ToFromOrErr, To)) | |||
9839 | return true; | |||
9840 | } else { | |||
9841 | llvm::consumeError(ToFromOrErr.takeError()); | |||
9842 | } | |||
9843 | } | |||
9844 | ||||
9845 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, | |||
9846 | getStructuralEquivalenceKind(*this), false, | |||
9847 | Complain); | |||
9848 | return Ctx.IsEquivalent(From, To); | |||
9849 | } |
1 | //===- DeclVisitor.h - Visitor for Decl subclasses --------------*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // This file defines the DeclVisitor interface. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #ifndef LLVM_CLANG_AST_DECLVISITOR_H |
14 | #define LLVM_CLANG_AST_DECLVISITOR_H |
15 | |
16 | #include "clang/AST/Decl.h" |
17 | #include "clang/AST/DeclBase.h" |
18 | #include "clang/AST/DeclCXX.h" |
19 | #include "clang/AST/DeclFriend.h" |
20 | #include "clang/AST/DeclObjC.h" |
21 | #include "clang/AST/DeclOpenMP.h" |
22 | #include "clang/AST/DeclTemplate.h" |
23 | #include "llvm/ADT/STLExtras.h" |
24 | #include "llvm/Support/ErrorHandling.h" |
25 | |
26 | namespace clang { |
27 | |
28 | namespace declvisitor { |
29 | /// A simple visitor class that helps create declaration visitors. |
30 | template<template <typename> class Ptr, typename ImplClass, typename RetTy=void> |
31 | class Base { |
32 | public: |
33 | #define PTR(CLASS) typename Ptr<CLASS>::type |
34 | #define DISPATCH(NAME, CLASS) \ |
35 | return static_cast<ImplClass*>(this)->Visit##NAME(static_cast<PTR(CLASS)>(D)) |
36 | |
37 | RetTy Visit(PTR(Decl) D) { |
38 | switch (D->getKind()) { |
39 | #define DECL(DERIVED, BASE) \ |
40 | case Decl::DERIVED: DISPATCH(DERIVED##Decl, DERIVED##Decl); |
41 | #define ABSTRACT_DECL(DECL) |
42 | #include "clang/AST/DeclNodes.inc" |
43 | } |
44 | llvm_unreachable("Decl that isn't part of DeclNodes.inc!")::llvm::llvm_unreachable_internal("Decl that isn't part of DeclNodes.inc!" , "clang/include/clang/AST/DeclVisitor.h", 44); |
45 | } |
46 | |
47 | // If the implementation chooses not to implement a certain visit |
48 | // method, fall back to the parent. |
49 | #define DECL(DERIVED, BASE) \ |
50 | RetTy Visit##DERIVED##Decl(PTR(DERIVED##Decl) D) { DISPATCH(BASE, BASE); } |
51 | #include "clang/AST/DeclNodes.inc" |
52 | |
53 | RetTy VisitDecl(PTR(Decl) D) { return RetTy(); } |
54 | |
55 | #undef PTR |
56 | #undef DISPATCH |
57 | }; |
58 | |
59 | } // namespace declvisitor |
60 | |
61 | /// A simple visitor class that helps create declaration visitors. |
62 | /// |
63 | /// This class does not preserve constness of Decl pointers (see also |
64 | /// ConstDeclVisitor). |
65 | template <typename ImplClass, typename RetTy = void> |
66 | class DeclVisitor |
67 | : public declvisitor::Base<std::add_pointer, ImplClass, RetTy> {}; |
68 | |
69 | /// A simple visitor class that helps create declaration visitors. |
70 | /// |
71 | /// This class preserves constness of Decl pointers (see also DeclVisitor). |
72 | template <typename ImplClass, typename RetTy = void> |
73 | class ConstDeclVisitor |
74 | : public declvisitor::Base<llvm::make_const_ptr, ImplClass, RetTy> {}; |
75 | |
76 | } // namespace clang |
77 | |
78 | #endif // LLVM_CLANG_AST_DECLVISITOR_H |
1 | /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ |
2 | |* *| |
3 | |* List of AST nodes of a particular kind *| |
4 | |* *| |
5 | |* Automatically generated file, do not edit! *| |
6 | |* *| |
7 | \*===----------------------------------------------------------------------===*/ |
8 | |
9 | #ifndef ABSTRACT_DECL |
10 | # define ABSTRACT_DECL(Type) Type |
11 | #endif |
12 | #ifndef DECL_RANGE |
13 | # define DECL_RANGE(Base, First, Last) |
14 | #endif |
15 | |
16 | #ifndef LAST_DECL_RANGE |
17 | # define LAST_DECL_RANGE(Base, First, Last) DECL_RANGE(Base, First, Last) |
18 | #endif |
19 | |
20 | #ifndef ACCESSSPEC |
21 | # define ACCESSSPEC(Type, Base) DECL(Type, Base) |
22 | #endif |
23 | ACCESSSPEC(AccessSpec, Decl) |
24 | #undef ACCESSSPEC |
25 | |
26 | #ifndef BLOCK |
27 | # define BLOCK(Type, Base) DECL(Type, Base) |
28 | #endif |
29 | BLOCK(Block, Decl) |
30 | #undef BLOCK |
31 | |
32 | #ifndef CAPTURED |
33 | # define CAPTURED(Type, Base) DECL(Type, Base) |
34 | #endif |
35 | CAPTURED(Captured, Decl) |
36 | #undef CAPTURED |
37 | |
38 | #ifndef CLASSSCOPEFUNCTIONSPECIALIZATION |
39 | # define CLASSSCOPEFUNCTIONSPECIALIZATION(Type, Base) DECL(Type, Base) |
40 | #endif |
41 | CLASSSCOPEFUNCTIONSPECIALIZATION(ClassScopeFunctionSpecialization, Decl) |
42 | #undef CLASSSCOPEFUNCTIONSPECIALIZATION |
43 | |
44 | #ifndef EMPTY |
45 | # define EMPTY(Type, Base) DECL(Type, Base) |
46 | #endif |
47 | EMPTY(Empty, Decl) |
48 | #undef EMPTY |
49 | |
50 | #ifndef EXPORT |
51 | # define EXPORT(Type, Base) DECL(Type, Base) |
52 | #endif |
53 | EXPORT(Export, Decl) |
54 | #undef EXPORT |
55 | |
56 | #ifndef EXTERNCCONTEXT |
57 | # define EXTERNCCONTEXT(Type, Base) DECL(Type, Base) |
58 | #endif |
59 | EXTERNCCONTEXT(ExternCContext, Decl) |
60 | #undef EXTERNCCONTEXT |
61 | |
62 | #ifndef FILESCOPEASM |
63 | # define FILESCOPEASM(Type, Base) DECL(Type, Base) |
64 | #endif |
65 | FILESCOPEASM(FileScopeAsm, Decl) |
66 | #undef FILESCOPEASM |
67 | |
68 | #ifndef FRIEND |
69 | # define FRIEND(Type, Base) DECL(Type, Base) |
70 | #endif |
71 | FRIEND(Friend, Decl) |
72 | #undef FRIEND |
73 | |
74 | #ifndef FRIENDTEMPLATE |
75 | # define FRIENDTEMPLATE(Type, Base) DECL(Type, Base) |
76 | #endif |
77 | FRIENDTEMPLATE(FriendTemplate, Decl) |
78 | #undef FRIENDTEMPLATE |
79 | |
80 | #ifndef IMPORT |
81 | # define IMPORT(Type, Base) DECL(Type, Base) |
82 | #endif |
83 | IMPORT(Import, Decl) |
84 | #undef IMPORT |
85 | |
86 | #ifndef LIFETIMEEXTENDEDTEMPORARY |
87 | # define LIFETIMEEXTENDEDTEMPORARY(Type, Base) DECL(Type, Base) |
88 | #endif |
89 | LIFETIMEEXTENDEDTEMPORARY(LifetimeExtendedTemporary, Decl) |
90 | #undef LIFETIMEEXTENDEDTEMPORARY |
91 | |
92 | #ifndef LINKAGESPEC |
93 | # define LINKAGESPEC(Type, Base) DECL(Type, Base) |
94 | #endif |
95 | LINKAGESPEC(LinkageSpec, Decl) |
96 | #undef LINKAGESPEC |
97 | |
98 | #ifndef NAMED |
99 | # define NAMED(Type, Base) DECL(Type, Base) |
100 | #endif |
101 | ABSTRACT_DECL(NAMED(Named, Decl)) |
102 | #ifndef BASEUSING |
103 | # define BASEUSING(Type, Base) NAMED(Type, Base) |
104 | #endif |
105 | ABSTRACT_DECL(BASEUSING(BaseUsing, NamedDecl)) |
106 | #ifndef USING |
107 | # define USING(Type, Base) BASEUSING(Type, Base) |
108 | #endif |
109 | USING(Using, BaseUsingDecl) |
110 | #undef USING |
111 | |
112 | #ifndef USINGENUM |
113 | # define USINGENUM(Type, Base) BASEUSING(Type, Base) |
114 | #endif |
115 | USINGENUM(UsingEnum, BaseUsingDecl) |
116 | #undef USINGENUM |
117 | |
118 | DECL_RANGE(BaseUsing, Using, UsingEnum) |
119 | |
120 | #undef BASEUSING |
121 | |
122 | #ifndef LABEL |
123 | # define LABEL(Type, Base) NAMED(Type, Base) |
124 | #endif |
125 | LABEL(Label, NamedDecl) |
126 | #undef LABEL |
127 | |
128 | #ifndef NAMESPACE |
129 | # define NAMESPACE(Type, Base) NAMED(Type, Base) |
130 | #endif |
131 | NAMESPACE(Namespace, NamedDecl) |
132 | #undef NAMESPACE |
133 | |
134 | #ifndef NAMESPACEALIAS |
135 | # define NAMESPACEALIAS(Type, Base) NAMED(Type, Base) |
136 | #endif |
137 | NAMESPACEALIAS(NamespaceAlias, NamedDecl) |
138 | #undef NAMESPACEALIAS |
139 | |
140 | #ifndef OBJCCOMPATIBLEALIAS |
141 | # define OBJCCOMPATIBLEALIAS(Type, Base) NAMED(Type, Base) |
142 | #endif |
143 | OBJCCOMPATIBLEALIAS(ObjCCompatibleAlias, NamedDecl) |
144 | #undef OBJCCOMPATIBLEALIAS |
145 | |
146 | #ifndef OBJCCONTAINER |
147 | # define OBJCCONTAINER(Type, Base) NAMED(Type, Base) |
148 | #endif |
149 | ABSTRACT_DECL(OBJCCONTAINER(ObjCContainer, NamedDecl)) |
150 | #ifndef OBJCCATEGORY |
151 | # define OBJCCATEGORY(Type, Base) OBJCCONTAINER(Type, Base) |
152 | #endif |
153 | OBJCCATEGORY(ObjCCategory, ObjCContainerDecl) |
154 | #undef OBJCCATEGORY |
155 | |
156 | #ifndef OBJCIMPL |
157 | # define OBJCIMPL(Type, Base) OBJCCONTAINER(Type, Base) |
158 | #endif |
159 | ABSTRACT_DECL(OBJCIMPL(ObjCImpl, ObjCContainerDecl)) |
160 | #ifndef OBJCCATEGORYIMPL |
161 | # define OBJCCATEGORYIMPL(Type, Base) OBJCIMPL(Type, Base) |
162 | #endif |
163 | OBJCCATEGORYIMPL(ObjCCategoryImpl, ObjCImplDecl) |
164 | #undef OBJCCATEGORYIMPL |
165 | |
166 | #ifndef OBJCIMPLEMENTATION |
167 | # define OBJCIMPLEMENTATION(Type, Base) OBJCIMPL(Type, Base) |
168 | #endif |
169 | OBJCIMPLEMENTATION(ObjCImplementation, ObjCImplDecl) |
170 | #undef OBJCIMPLEMENTATION |
171 | |
172 | DECL_RANGE(ObjCImpl, ObjCCategoryImpl, ObjCImplementation) |
173 | |
174 | #undef OBJCIMPL |
175 | |
176 | #ifndef OBJCINTERFACE |
177 | # define OBJCINTERFACE(Type, Base) OBJCCONTAINER(Type, Base) |
178 | #endif |
179 | OBJCINTERFACE(ObjCInterface, ObjCContainerDecl) |
180 | #undef OBJCINTERFACE |
181 | |
182 | #ifndef OBJCPROTOCOL |
183 | # define OBJCPROTOCOL(Type, Base) OBJCCONTAINER(Type, Base) |
184 | #endif |
185 | OBJCPROTOCOL(ObjCProtocol, ObjCContainerDecl) |
186 | #undef OBJCPROTOCOL |
187 | |
188 | DECL_RANGE(ObjCContainer, ObjCCategory, ObjCProtocol) |
189 | |
190 | #undef OBJCCONTAINER |
191 | |
192 | #ifndef OBJCMETHOD |
193 | # define OBJCMETHOD(Type, Base) NAMED(Type, Base) |
194 | #endif |
195 | OBJCMETHOD(ObjCMethod, NamedDecl) |
196 | #undef OBJCMETHOD |
197 | |
198 | #ifndef OBJCPROPERTY |
199 | # define OBJCPROPERTY(Type, Base) NAMED(Type, Base) |
200 | #endif |
201 | OBJCPROPERTY(ObjCProperty, NamedDecl) |
202 | #undef OBJCPROPERTY |
203 | |
204 | #ifndef TEMPLATE |
205 | # define TEMPLATE(Type, Base) NAMED(Type, Base) |
206 | #endif |
207 | ABSTRACT_DECL(TEMPLATE(Template, NamedDecl)) |
208 | #ifndef BUILTINTEMPLATE |
209 | # define BUILTINTEMPLATE(Type, Base) TEMPLATE(Type, Base) |
210 | #endif |
211 | BUILTINTEMPLATE(BuiltinTemplate, TemplateDecl) |
212 | #undef BUILTINTEMPLATE |
213 | |
214 | #ifndef CONCEPT |
215 | # define CONCEPT(Type, Base) TEMPLATE(Type, Base) |
216 | #endif |
217 | CONCEPT(Concept, TemplateDecl) |
218 | #undef CONCEPT |
219 | |
220 | #ifndef REDECLARABLETEMPLATE |
221 | # define REDECLARABLETEMPLATE(Type, Base) TEMPLATE(Type, Base) |
222 | #endif |
223 | ABSTRACT_DECL(REDECLARABLETEMPLATE(RedeclarableTemplate, TemplateDecl)) |
224 | #ifndef CLASSTEMPLATE |
225 | # define CLASSTEMPLATE(Type, Base) REDECLARABLETEMPLATE(Type, Base) |
226 | #endif |
227 | CLASSTEMPLATE(ClassTemplate, RedeclarableTemplateDecl) |
228 | #undef CLASSTEMPLATE |
229 | |
230 | #ifndef FUNCTIONTEMPLATE |
231 | # define FUNCTIONTEMPLATE(Type, Base) REDECLARABLETEMPLATE(Type, Base) |
232 | #endif |
233 | FUNCTIONTEMPLATE(FunctionTemplate, RedeclarableTemplateDecl) |
234 | #undef FUNCTIONTEMPLATE |
235 | |
236 | #ifndef TYPEALIASTEMPLATE |
237 | # define TYPEALIASTEMPLATE(Type, Base) REDECLARABLETEMPLATE(Type, Base) |
238 | #endif |
239 | TYPEALIASTEMPLATE(TypeAliasTemplate, RedeclarableTemplateDecl) |
240 | #undef TYPEALIASTEMPLATE |
241 | |
242 | #ifndef VARTEMPLATE |
243 | # define VARTEMPLATE(Type, Base) REDECLARABLETEMPLATE(Type, Base) |
244 | #endif |
245 | VARTEMPLATE(VarTemplate, RedeclarableTemplateDecl) |
246 | #undef VARTEMPLATE |
247 | |
248 | DECL_RANGE(RedeclarableTemplate, ClassTemplate, VarTemplate) |
249 | |
250 | #undef REDECLARABLETEMPLATE |
251 | |
252 | #ifndef TEMPLATETEMPLATEPARM |
253 | # define TEMPLATETEMPLATEPARM(Type, Base) TEMPLATE(Type, Base) |
254 | #endif |
255 | TEMPLATETEMPLATEPARM(TemplateTemplateParm, TemplateDecl) |
256 | #undef TEMPLATETEMPLATEPARM |
257 | |
258 | DECL_RANGE(Template, BuiltinTemplate, TemplateTemplateParm) |
259 | |
260 | #undef TEMPLATE |
261 | |
262 | #ifndef TYPE |
263 | # define TYPE(Type, Base) NAMED(Type, Base) |
264 | #endif |
265 | ABSTRACT_DECL(TYPE(Type, NamedDecl)) |
266 | #ifndef TAG |
267 | # define TAG(Type, Base) TYPE(Type, Base) |
268 | #endif |
269 | ABSTRACT_DECL(TAG(Tag, TypeDecl)) |
270 | #ifndef ENUM |
271 | # define ENUM(Type, Base) TAG(Type, Base) |
272 | #endif |
273 | ENUM(Enum, TagDecl) |
274 | #undef ENUM |
275 | |
276 | #ifndef RECORD |
277 | # define RECORD(Type, Base) TAG(Type, Base) |
278 | #endif |
279 | RECORD(Record, TagDecl) |
280 | #ifndef CXXRECORD |
281 | # define CXXRECORD(Type, Base) RECORD(Type, Base) |
282 | #endif |
283 | CXXRECORD(CXXRecord, RecordDecl) |
284 | #ifndef CLASSTEMPLATESPECIALIZATION |
285 | # define CLASSTEMPLATESPECIALIZATION(Type, Base) CXXRECORD(Type, Base) |
286 | #endif |
287 | CLASSTEMPLATESPECIALIZATION(ClassTemplateSpecialization, CXXRecordDecl) |
288 | #ifndef CLASSTEMPLATEPARTIALSPECIALIZATION |
289 | # define CLASSTEMPLATEPARTIALSPECIALIZATION(Type, Base) CLASSTEMPLATESPECIALIZATION(Type, Base) |
290 | #endif |
291 | CLASSTEMPLATEPARTIALSPECIALIZATION(ClassTemplatePartialSpecialization, ClassTemplateSpecializationDecl) |
292 | #undef CLASSTEMPLATEPARTIALSPECIALIZATION |
293 | |
294 | DECL_RANGE(ClassTemplateSpecialization, ClassTemplateSpecialization, ClassTemplatePartialSpecialization) |
295 | |
296 | #undef CLASSTEMPLATESPECIALIZATION |
297 | |
298 | DECL_RANGE(CXXRecord, CXXRecord, ClassTemplatePartialSpecialization) |
299 | |
300 | #undef CXXRECORD |
301 | |
302 | DECL_RANGE(Record, Record, ClassTemplatePartialSpecialization) |
303 | |
304 | #undef RECORD |
305 | |
306 | DECL_RANGE(Tag, Enum, ClassTemplatePartialSpecialization) |
307 | |
308 | #undef TAG |
309 | |
310 | #ifndef TEMPLATETYPEPARM |
311 | # define TEMPLATETYPEPARM(Type, Base) TYPE(Type, Base) |
312 | #endif |
313 | TEMPLATETYPEPARM(TemplateTypeParm, TypeDecl) |
314 | #undef TEMPLATETYPEPARM |
315 | |
316 | #ifndef TYPEDEFNAME |
317 | # define TYPEDEFNAME(Type, Base) TYPE(Type, Base) |
318 | #endif |
319 | ABSTRACT_DECL(TYPEDEFNAME(TypedefName, TypeDecl)) |
320 | #ifndef OBJCTYPEPARAM |
321 | # define OBJCTYPEPARAM(Type, Base) TYPEDEFNAME(Type, Base) |
322 | #endif |
323 | OBJCTYPEPARAM(ObjCTypeParam, TypedefNameDecl) |
324 | #undef OBJCTYPEPARAM |
325 | |
326 | #ifndef TYPEALIAS |
327 | # define TYPEALIAS(Type, Base) TYPEDEFNAME(Type, Base) |
328 | #endif |
329 | TYPEALIAS(TypeAlias, TypedefNameDecl) |
330 | #undef TYPEALIAS |
331 | |
332 | #ifndef TYPEDEF |
333 | # define TYPEDEF(Type, Base) TYPEDEFNAME(Type, Base) |
334 | #endif |
335 | TYPEDEF(Typedef, TypedefNameDecl) |
336 | #undef TYPEDEF |
337 | |
338 | DECL_RANGE(TypedefName, ObjCTypeParam, Typedef) |
339 | |
340 | #undef TYPEDEFNAME |
341 | |
342 | #ifndef UNRESOLVEDUSINGTYPENAME |
343 | # define UNRESOLVEDUSINGTYPENAME(Type, Base) TYPE(Type, Base) |
344 | #endif |
345 | UNRESOLVEDUSINGTYPENAME(UnresolvedUsingTypename, TypeDecl) |
346 | #undef UNRESOLVEDUSINGTYPENAME |
347 | |
348 | DECL_RANGE(Type, Enum, UnresolvedUsingTypename) |
349 | |
350 | #undef TYPE |
351 | |
352 | #ifndef UNRESOLVEDUSINGIFEXISTS |
353 | # define UNRESOLVEDUSINGIFEXISTS(Type, Base) NAMED(Type, Base) |
354 | #endif |
355 | UNRESOLVEDUSINGIFEXISTS(UnresolvedUsingIfExists, NamedDecl) |
356 | #undef UNRESOLVEDUSINGIFEXISTS |
357 | |
358 | #ifndef USINGDIRECTIVE |
359 | # define USINGDIRECTIVE(Type, Base) NAMED(Type, Base) |
360 | #endif |
361 | USINGDIRECTIVE(UsingDirective, NamedDecl) |
362 | #undef USINGDIRECTIVE |
363 | |
364 | #ifndef USINGPACK |
365 | # define USINGPACK(Type, Base) NAMED(Type, Base) |
366 | #endif |
367 | USINGPACK(UsingPack, NamedDecl) |
368 | #undef USINGPACK |
369 | |
370 | #ifndef USINGSHADOW |
371 | # define USINGSHADOW(Type, Base) NAMED(Type, Base) |
372 | #endif |
373 | USINGSHADOW(UsingShadow, NamedDecl) |
374 | #ifndef CONSTRUCTORUSINGSHADOW |
375 | # define CONSTRUCTORUSINGSHADOW(Type, Base) USINGSHADOW(Type, Base) |
376 | #endif |
377 | CONSTRUCTORUSINGSHADOW(ConstructorUsingShadow, UsingShadowDecl) |
378 | #undef CONSTRUCTORUSINGSHADOW |
379 | |
380 | DECL_RANGE(UsingShadow, UsingShadow, ConstructorUsingShadow) |
381 | |
382 | #undef USINGSHADOW |
383 | |
384 | #ifndef VALUE |
385 | # define VALUE(Type, Base) NAMED(Type, Base) |
386 | #endif |
387 | ABSTRACT_DECL(VALUE(Value, NamedDecl)) |
388 | #ifndef BINDING |
389 | # define BINDING(Type, Base) VALUE(Type, Base) |
390 | #endif |
391 | BINDING(Binding, ValueDecl) |
392 | #undef BINDING |
393 | |
394 | #ifndef DECLARATOR |
395 | # define DECLARATOR(Type, Base) VALUE(Type, Base) |
396 | #endif |
397 | ABSTRACT_DECL(DECLARATOR(Declarator, ValueDecl)) |
398 | #ifndef FIELD |
399 | # define FIELD(Type, Base) DECLARATOR(Type, Base) |
400 | #endif |
401 | FIELD(Field, DeclaratorDecl) |
402 | #ifndef OBJCATDEFSFIELD |
403 | # define OBJCATDEFSFIELD(Type, Base) FIELD(Type, Base) |
404 | #endif |
405 | OBJCATDEFSFIELD(ObjCAtDefsField, FieldDecl) |
406 | #undef OBJCATDEFSFIELD |
407 | |
408 | #ifndef OBJCIVAR |
409 | # define OBJCIVAR(Type, Base) FIELD(Type, Base) |
410 | #endif |
411 | OBJCIVAR(ObjCIvar, FieldDecl) |
412 | #undef OBJCIVAR |
413 | |
414 | DECL_RANGE(Field, Field, ObjCIvar) |
415 | |
416 | #undef FIELD |
417 | |
418 | #ifndef FUNCTION |
419 | # define FUNCTION(Type, Base) DECLARATOR(Type, Base) |
420 | #endif |
421 | FUNCTION(Function, DeclaratorDecl) |
422 | #ifndef CXXDEDUCTIONGUIDE |
423 | # define CXXDEDUCTIONGUIDE(Type, Base) FUNCTION(Type, Base) |
424 | #endif |
425 | CXXDEDUCTIONGUIDE(CXXDeductionGuide, FunctionDecl) |
426 | #undef CXXDEDUCTIONGUIDE |
427 | |
428 | #ifndef CXXMETHOD |
429 | # define CXXMETHOD(Type, Base) FUNCTION(Type, Base) |
430 | #endif |
431 | CXXMETHOD(CXXMethod, FunctionDecl) |
432 | #ifndef CXXCONSTRUCTOR |
433 | # define CXXCONSTRUCTOR(Type, Base) CXXMETHOD(Type, Base) |
434 | #endif |
435 | CXXCONSTRUCTOR(CXXConstructor, CXXMethodDecl) |
436 | #undef CXXCONSTRUCTOR |
437 | |
438 | #ifndef CXXCONVERSION |
439 | # define CXXCONVERSION(Type, Base) CXXMETHOD(Type, Base) |
440 | #endif |
441 | CXXCONVERSION(CXXConversion, CXXMethodDecl) |
442 | #undef CXXCONVERSION |
443 | |
444 | #ifndef CXXDESTRUCTOR |
445 | # define CXXDESTRUCTOR(Type, Base) CXXMETHOD(Type, Base) |
446 | #endif |
447 | CXXDESTRUCTOR(CXXDestructor, CXXMethodDecl) |
448 | #undef CXXDESTRUCTOR |
449 | |
450 | DECL_RANGE(CXXMethod, CXXMethod, CXXDestructor) |
451 | |
452 | #undef CXXMETHOD |
453 | |
454 | DECL_RANGE(Function, Function, CXXDestructor) |
455 | |
456 | #undef FUNCTION |
457 | |
458 | #ifndef MSPROPERTY |
459 | # define MSPROPERTY(Type, Base) DECLARATOR(Type, Base) |
460 | #endif |
461 | MSPROPERTY(MSProperty, DeclaratorDecl) |
462 | #undef MSPROPERTY |
463 | |
464 | #ifndef NONTYPETEMPLATEPARM |
465 | # define NONTYPETEMPLATEPARM(Type, Base) DECLARATOR(Type, Base) |
466 | #endif |
467 | NONTYPETEMPLATEPARM(NonTypeTemplateParm, DeclaratorDecl) |
468 | #undef NONTYPETEMPLATEPARM |
469 | |
470 | #ifndef VAR |
471 | # define VAR(Type, Base) DECLARATOR(Type, Base) |
472 | #endif |
473 | VAR(Var, DeclaratorDecl) |
474 | #ifndef DECOMPOSITION |
475 | # define DECOMPOSITION(Type, Base) VAR(Type, Base) |
476 | #endif |
477 | DECOMPOSITION(Decomposition, VarDecl) |
478 | #undef DECOMPOSITION |
479 | |
480 | #ifndef IMPLICITPARAM |
481 | # define IMPLICITPARAM(Type, Base) VAR(Type, Base) |
482 | #endif |
483 | IMPLICITPARAM(ImplicitParam, VarDecl) |
484 | #undef IMPLICITPARAM |
485 | |
486 | #ifndef OMPCAPTUREDEXPR |
487 | # define OMPCAPTUREDEXPR(Type, Base) VAR(Type, Base) |
488 | #endif |
489 | OMPCAPTUREDEXPR(OMPCapturedExpr, VarDecl) |
490 | #undef OMPCAPTUREDEXPR |
491 | |
492 | #ifndef PARMVAR |
493 | # define PARMVAR(Type, Base) VAR(Type, Base) |
494 | #endif |
495 | PARMVAR(ParmVar, VarDecl) |
496 | #undef PARMVAR |
497 | |
498 | #ifndef VARTEMPLATESPECIALIZATION |
499 | # define VARTEMPLATESPECIALIZATION(Type, Base) VAR(Type, Base) |
500 | #endif |
501 | VARTEMPLATESPECIALIZATION(VarTemplateSpecialization, VarDecl) |
502 | #ifndef VARTEMPLATEPARTIALSPECIALIZATION |
503 | # define VARTEMPLATEPARTIALSPECIALIZATION(Type, Base) VARTEMPLATESPECIALIZATION(Type, Base) |
504 | #endif |
505 | VARTEMPLATEPARTIALSPECIALIZATION(VarTemplatePartialSpecialization, VarTemplateSpecializationDecl) |
506 | #undef VARTEMPLATEPARTIALSPECIALIZATION |
507 | |
508 | DECL_RANGE(VarTemplateSpecialization, VarTemplateSpecialization, VarTemplatePartialSpecialization) |
509 | |
510 | #undef VARTEMPLATESPECIALIZATION |
511 | |
512 | DECL_RANGE(Var, Var, VarTemplatePartialSpecialization) |
513 | |
514 | #undef VAR |
515 | |
516 | DECL_RANGE(Declarator, Field, VarTemplatePartialSpecialization) |
517 | |
518 | #undef DECLARATOR |
519 | |
520 | #ifndef ENUMCONSTANT |
521 | # define ENUMCONSTANT(Type, Base) VALUE(Type, Base) |
522 | #endif |
523 | ENUMCONSTANT(EnumConstant, ValueDecl) |
524 | #undef ENUMCONSTANT |
525 | |
526 | #ifndef INDIRECTFIELD |
527 | # define INDIRECTFIELD(Type, Base) VALUE(Type, Base) |
528 | #endif |
529 | INDIRECTFIELD(IndirectField, ValueDecl) |
530 | #undef INDIRECTFIELD |
531 | |
532 | #ifndef MSGUID |
533 | # define MSGUID(Type, Base) VALUE(Type, Base) |
534 | #endif |
535 | MSGUID(MSGuid, ValueDecl) |
536 | #undef MSGUID |
537 | |
538 | #ifndef OMPDECLAREMAPPER |
539 | # define OMPDECLAREMAPPER(Type, Base) VALUE(Type, Base) |
540 | #endif |
541 | OMPDECLAREMAPPER(OMPDeclareMapper, ValueDecl) |
542 | #undef OMPDECLAREMAPPER |
543 | |
544 | #ifndef OMPDECLAREREDUCTION |
545 | # define OMPDECLAREREDUCTION(Type, Base) VALUE(Type, Base) |
546 | #endif |
547 | OMPDECLAREREDUCTION(OMPDeclareReduction, ValueDecl) |
548 | #undef OMPDECLAREREDUCTION |
549 | |
550 | #ifndef TEMPLATEPARAMOBJECT |
551 | # define TEMPLATEPARAMOBJECT(Type, Base) VALUE(Type, Base) |
552 | #endif |
553 | TEMPLATEPARAMOBJECT(TemplateParamObject, ValueDecl) |
554 | #undef TEMPLATEPARAMOBJECT |
555 | |
556 | #ifndef UNNAMEDGLOBALCONSTANT |
557 | # define UNNAMEDGLOBALCONSTANT(Type, Base) VALUE(Type, Base) |
558 | #endif |
559 | UNNAMEDGLOBALCONSTANT(UnnamedGlobalConstant, ValueDecl) |
560 | #undef UNNAMEDGLOBALCONSTANT |
561 | |
562 | #ifndef UNRESOLVEDUSINGVALUE |
563 | # define UNRESOLVEDUSINGVALUE(Type, Base) VALUE(Type, Base) |
564 | #endif |
565 | UNRESOLVEDUSINGVALUE(UnresolvedUsingValue, ValueDecl) |
566 | #undef UNRESOLVEDUSINGVALUE |
567 | |
568 | DECL_RANGE(Value, Binding, UnresolvedUsingValue) |
569 | |
570 | #undef VALUE |
571 | |
572 | DECL_RANGE(Named, Using, UnresolvedUsingValue) |
573 | |
574 | #undef NAMED |
575 | |
576 | #ifndef OMPALLOCATE |
577 | # define OMPALLOCATE(Type, Base) DECL(Type, Base) |
578 | #endif |
579 | OMPALLOCATE(OMPAllocate, Decl) |
580 | #undef OMPALLOCATE |
581 | |
582 | #ifndef OMPREQUIRES |
583 | # define OMPREQUIRES(Type, Base) DECL(Type, Base) |
584 | #endif |
585 | OMPREQUIRES(OMPRequires, Decl) |
586 | #undef OMPREQUIRES |
587 | |
588 | #ifndef OMPTHREADPRIVATE |
589 | # define OMPTHREADPRIVATE(Type, Base) DECL(Type, Base) |
590 | #endif |
591 | OMPTHREADPRIVATE(OMPThreadPrivate, Decl) |
592 | #undef OMPTHREADPRIVATE |
593 | |
594 | #ifndef OBJCPROPERTYIMPL |
595 | # define OBJCPROPERTYIMPL(Type, Base) DECL(Type, Base) |
596 | #endif |
597 | OBJCPROPERTYIMPL(ObjCPropertyImpl, Decl) |
598 | #undef OBJCPROPERTYIMPL |
599 | |
600 | #ifndef PRAGMACOMMENT |
601 | # define PRAGMACOMMENT(Type, Base) DECL(Type, Base) |
602 | #endif |
603 | PRAGMACOMMENT(PragmaComment, Decl) |
604 | #undef PRAGMACOMMENT |
605 | |
606 | #ifndef PRAGMADETECTMISMATCH |
607 | # define PRAGMADETECTMISMATCH(Type, Base) DECL(Type, Base) |
608 | #endif |
609 | PRAGMADETECTMISMATCH(PragmaDetectMismatch, Decl) |
610 | #undef PRAGMADETECTMISMATCH |
611 | |
612 | #ifndef REQUIRESEXPRBODY |
613 | # define REQUIRESEXPRBODY(Type, Base) DECL(Type, Base) |
614 | #endif |
615 | REQUIRESEXPRBODY(RequiresExprBody, Decl) |
616 | #undef REQUIRESEXPRBODY |
617 | |
618 | #ifndef STATICASSERT |
619 | # define STATICASSERT(Type, Base) DECL(Type, Base) |
620 | #endif |
621 | STATICASSERT(StaticAssert, Decl) |
622 | #undef STATICASSERT |
623 | |
624 | #ifndef TRANSLATIONUNIT |
625 | # define TRANSLATIONUNIT(Type, Base) DECL(Type, Base) |
626 | #endif |
627 | TRANSLATIONUNIT(TranslationUnit, Decl) |
628 | #undef TRANSLATIONUNIT |
629 | |
630 | LAST_DECL_RANGE(Decl, AccessSpec, TranslationUnit) |
631 | |
632 | #undef DECL |
633 | #undef DECL_RANGE |
634 | #undef LAST_DECL_RANGE |
635 | #undef ABSTRACT_DECL |
636 | /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ |
637 | |* *| |
638 | |* List of AST Decl nodes *| |
639 | |* *| |
640 | |* Automatically generated file, do not edit! *| |
641 | |* *| |
642 | \*===----------------------------------------------------------------------===*/ |
643 | |
644 | #ifndef DECL_CONTEXT |
645 | # define DECL_CONTEXT(DECL) |
646 | #endif |
647 | #ifndef DECL_CONTEXT_BASE |
648 | # define DECL_CONTEXT_BASE(DECL) DECL_CONTEXT(DECL) |
649 | #endif |
650 | DECL_CONTEXT_BASE(Function) |
651 | DECL_CONTEXT_BASE(Tag) |
652 | DECL_CONTEXT_BASE(ObjCContainer) |
653 | DECL_CONTEXT(Block) |
654 | DECL_CONTEXT(Captured) |
655 | DECL_CONTEXT(Export) |
656 | DECL_CONTEXT(ExternCContext) |
657 | DECL_CONTEXT(LinkageSpec) |
658 | DECL_CONTEXT(Namespace) |
659 | DECL_CONTEXT(OMPDeclareMapper) |
660 | DECL_CONTEXT(OMPDeclareReduction) |
661 | DECL_CONTEXT(ObjCMethod) |
662 | DECL_CONTEXT(RequiresExprBody) |
663 | DECL_CONTEXT(TranslationUnit) |
664 | #undef DECL_CONTEXT |
665 | #undef DECL_CONTEXT_BASE |