File: | clang/lib/AST/ASTImporter.cpp |
Warning: | line 2591, column 5 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 ExpectedType = llvm::Expected<QualType>; | ||||||
80 | using ExpectedStmt = llvm::Expected<Stmt *>; | ||||||
81 | using ExpectedExpr = llvm::Expected<Expr *>; | ||||||
82 | using ExpectedDecl = llvm::Expected<Decl *>; | ||||||
83 | using ExpectedSLoc = llvm::Expected<SourceLocation>; | ||||||
84 | using ExpectedName = llvm::Expected<DeclarationName>; | ||||||
85 | |||||||
86 | std::string ImportError::toString() const { | ||||||
87 | // FIXME: Improve error texts. | ||||||
88 | switch (Error) { | ||||||
89 | case NameConflict: | ||||||
90 | return "NameConflict"; | ||||||
91 | case UnsupportedConstruct: | ||||||
92 | return "UnsupportedConstruct"; | ||||||
93 | case Unknown: | ||||||
94 | return "Unknown error"; | ||||||
95 | } | ||||||
96 | llvm_unreachable("Invalid error code.")::llvm::llvm_unreachable_internal("Invalid error code.", "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 96); | ||||||
97 | return "Invalid error code."; | ||||||
98 | } | ||||||
99 | |||||||
100 | void ImportError::log(raw_ostream &OS) const { | ||||||
101 | OS << toString(); | ||||||
102 | } | ||||||
103 | |||||||
104 | std::error_code ImportError::convertToErrorCode() const { | ||||||
105 | llvm_unreachable("Function not implemented.")::llvm::llvm_unreachable_internal("Function not implemented." , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 105); | ||||||
106 | } | ||||||
107 | |||||||
108 | char ImportError::ID; | ||||||
109 | |||||||
110 | template <class T> | ||||||
111 | SmallVector<Decl *, 2> | ||||||
112 | getCanonicalForwardRedeclChain(Redeclarable<T>* D) { | ||||||
113 | SmallVector<Decl *, 2> Redecls; | ||||||
114 | for (auto *R : D->getFirstDecl()->redecls()) { | ||||||
115 | if (R != D->getFirstDecl()) | ||||||
116 | Redecls.push_back(R); | ||||||
117 | } | ||||||
118 | Redecls.push_back(D->getFirstDecl()); | ||||||
119 | std::reverse(Redecls.begin(), Redecls.end()); | ||||||
120 | return Redecls; | ||||||
121 | } | ||||||
122 | |||||||
123 | SmallVector<Decl*, 2> getCanonicalForwardRedeclChain(Decl* D) { | ||||||
124 | if (auto *FD = dyn_cast<FunctionDecl>(D)) | ||||||
125 | return getCanonicalForwardRedeclChain<FunctionDecl>(FD); | ||||||
126 | if (auto *VD = dyn_cast<VarDecl>(D)) | ||||||
127 | return getCanonicalForwardRedeclChain<VarDecl>(VD); | ||||||
128 | if (auto *TD = dyn_cast<TagDecl>(D)) | ||||||
129 | return getCanonicalForwardRedeclChain<TagDecl>(TD); | ||||||
130 | llvm_unreachable("Bad declaration kind")::llvm::llvm_unreachable_internal("Bad declaration kind", "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 130); | ||||||
131 | } | ||||||
132 | |||||||
133 | void updateFlags(const Decl *From, Decl *To) { | ||||||
134 | // Check if some flags or attrs are new in 'From' and copy into 'To'. | ||||||
135 | // FIXME: Other flags or attrs? | ||||||
136 | if (From->isUsed(false) && !To->isUsed(false)) | ||||||
137 | To->setIsUsed(); | ||||||
138 | } | ||||||
139 | |||||||
140 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>, | ||||||
141 | public DeclVisitor<ASTNodeImporter, ExpectedDecl>, | ||||||
142 | public StmtVisitor<ASTNodeImporter, ExpectedStmt> { | ||||||
143 | ASTImporter &Importer; | ||||||
144 | |||||||
145 | // Use this instead of Importer.importInto . | ||||||
146 | template <typename ImportT> | ||||||
147 | LLVM_NODISCARD[[clang::warn_unused_result]] Error importInto(ImportT &To, const ImportT &From) { | ||||||
148 | return Importer.importInto(To, From); | ||||||
149 | } | ||||||
150 | |||||||
151 | // Use this to import pointers of specific type. | ||||||
152 | template <typename ImportT> | ||||||
153 | LLVM_NODISCARD[[clang::warn_unused_result]] Error importInto(ImportT *&To, ImportT *From) { | ||||||
154 | auto ToOrErr = Importer.Import(From); | ||||||
155 | if (ToOrErr) | ||||||
156 | To = cast_or_null<ImportT>(*ToOrErr); | ||||||
157 | return ToOrErr.takeError(); | ||||||
158 | } | ||||||
159 | |||||||
160 | // Call the import function of ASTImporter for a baseclass of type `T` and | ||||||
161 | // cast the return value to `T`. | ||||||
162 | template <typename T> | ||||||
163 | Expected<T *> import(T *From) { | ||||||
164 | auto ToOrErr = Importer.Import(From); | ||||||
| |||||||
165 | if (!ToOrErr) | ||||||
166 | return ToOrErr.takeError(); | ||||||
167 | return cast_or_null<T>(*ToOrErr); | ||||||
168 | } | ||||||
169 | |||||||
170 | template <typename T> | ||||||
171 | Expected<T *> import(const T *From) { | ||||||
172 | return import(const_cast<T *>(From)); | ||||||
173 | } | ||||||
174 | |||||||
175 | // Call the import function of ASTImporter for type `T`. | ||||||
176 | template <typename T> | ||||||
177 | Expected<T> import(const T &From) { | ||||||
178 | return Importer.Import(From); | ||||||
179 | } | ||||||
180 | |||||||
181 | // Import an Optional<T> by importing the contained T, if any. | ||||||
182 | template<typename T> | ||||||
183 | Expected<Optional<T>> import(Optional<T> From) { | ||||||
184 | if (!From) | ||||||
185 | return Optional<T>(); | ||||||
186 | return import(*From); | ||||||
187 | } | ||||||
188 | |||||||
189 | // Helper for chaining together multiple imports. If an error is detected, | ||||||
190 | // subsequent imports will return default constructed nodes, so that failure | ||||||
191 | // can be detected with a single conditional branch after a sequence of | ||||||
192 | // imports. | ||||||
193 | template <typename T> T importChecked(Error &Err, const T &From) { | ||||||
194 | // Don't attempt to import nodes if we hit an error earlier. | ||||||
195 | if (Err) | ||||||
196 | return T{}; | ||||||
197 | Expected<T> MaybeVal = import(From); | ||||||
198 | if (!MaybeVal) { | ||||||
199 | Err = MaybeVal.takeError(); | ||||||
200 | return T{}; | ||||||
201 | } | ||||||
202 | return *MaybeVal; | ||||||
203 | } | ||||||
204 | |||||||
205 | ExplicitSpecifier importExplicitSpecifier(Error &Err, | ||||||
206 | ExplicitSpecifier ESpec); | ||||||
207 | |||||||
208 | // Wrapper for an overload set. | ||||||
209 | template <typename ToDeclT> struct CallOverloadedCreateFun { | ||||||
210 | template <typename... Args> decltype(auto) operator()(Args &&... args) { | ||||||
211 | return ToDeclT::Create(std::forward<Args>(args)...); | ||||||
212 | } | ||||||
213 | }; | ||||||
214 | |||||||
215 | // Always use these functions to create a Decl during import. There are | ||||||
216 | // certain tasks which must be done after the Decl was created, e.g. we | ||||||
217 | // must immediately register that as an imported Decl. The parameter `ToD` | ||||||
218 | // will be set to the newly created Decl or if had been imported before | ||||||
219 | // then to the already imported Decl. Returns a bool value set to true if | ||||||
220 | // the `FromD` had been imported before. | ||||||
221 | template <typename ToDeclT, typename FromDeclT, typename... Args> | ||||||
222 | LLVM_NODISCARD[[clang::warn_unused_result]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, | ||||||
223 | Args &&... args) { | ||||||
224 | // There may be several overloads of ToDeclT::Create. We must make sure | ||||||
225 | // to call the one which would be chosen by the arguments, thus we use a | ||||||
226 | // wrapper for the overload set. | ||||||
227 | CallOverloadedCreateFun<ToDeclT> OC; | ||||||
228 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, | ||||||
229 | std::forward<Args>(args)...); | ||||||
230 | } | ||||||
231 | // Use this overload if a special Type is needed to be created. E.g if we | ||||||
232 | // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl` | ||||||
233 | // then: | ||||||
234 | // TypedefNameDecl *ToTypedef; | ||||||
235 | // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...); | ||||||
236 | template <typename NewDeclT, typename ToDeclT, typename FromDeclT, | ||||||
237 | typename... Args> | ||||||
238 | LLVM_NODISCARD[[clang::warn_unused_result]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, | ||||||
239 | Args &&... args) { | ||||||
240 | CallOverloadedCreateFun<NewDeclT> OC; | ||||||
241 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, | ||||||
242 | std::forward<Args>(args)...); | ||||||
243 | } | ||||||
244 | // Use this version if a special create function must be | ||||||
245 | // used, e.g. CXXRecordDecl::CreateLambda . | ||||||
246 | template <typename ToDeclT, typename CreateFunT, typename FromDeclT, | ||||||
247 | typename... Args> | ||||||
248 | LLVM_NODISCARD[[clang::warn_unused_result]] bool | ||||||
249 | GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun, | ||||||
250 | FromDeclT *FromD, Args &&... args) { | ||||||
251 | if (Importer.getImportDeclErrorIfAny(FromD)) { | ||||||
252 | ToD = nullptr; | ||||||
253 | return true; // Already imported but with error. | ||||||
254 | } | ||||||
255 | ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD)); | ||||||
256 | if (ToD
| ||||||
257 | return true; // Already imported. | ||||||
258 | ToD = CreateFun(std::forward<Args>(args)...); | ||||||
259 | // Keep track of imported Decls. | ||||||
260 | Importer.RegisterImportedDecl(FromD, ToD); | ||||||
261 | InitializeImportedDecl(FromD, ToD); | ||||||
262 | return false; // A new Decl is created. | ||||||
263 | } | ||||||
264 | |||||||
265 | void InitializeImportedDecl(Decl *FromD, Decl *ToD) { | ||||||
266 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; | ||||||
267 | if (FromD->isUsed()) | ||||||
268 | ToD->setIsUsed(); | ||||||
269 | if (FromD->isImplicit()) | ||||||
270 | ToD->setImplicit(); | ||||||
271 | } | ||||||
272 | |||||||
273 | // Check if we have found an existing definition. Returns with that | ||||||
274 | // definition if yes, otherwise returns null. | ||||||
275 | Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) { | ||||||
276 | const FunctionDecl *Definition = nullptr; | ||||||
277 | if (D->doesThisDeclarationHaveABody() && | ||||||
278 | FoundFunction->hasBody(Definition)) | ||||||
279 | return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition)); | ||||||
280 | return nullptr; | ||||||
281 | } | ||||||
282 | |||||||
283 | void addDeclToContexts(Decl *FromD, Decl *ToD) { | ||||||
284 | if (Importer.isMinimalImport()) { | ||||||
285 | // In minimal import case the decl must be added even if it is not | ||||||
286 | // contained in original context, for LLDB compatibility. | ||||||
287 | // FIXME: Check if a better solution is possible. | ||||||
288 | if (!FromD->getDescribedTemplate() && | ||||||
289 | FromD->getFriendObjectKind() == Decl::FOK_None) | ||||||
290 | ToD->getLexicalDeclContext()->addDeclInternal(ToD); | ||||||
291 | return; | ||||||
292 | } | ||||||
293 | |||||||
294 | DeclContext *FromDC = FromD->getDeclContext(); | ||||||
295 | DeclContext *FromLexicalDC = FromD->getLexicalDeclContext(); | ||||||
296 | DeclContext *ToDC = ToD->getDeclContext(); | ||||||
297 | DeclContext *ToLexicalDC = ToD->getLexicalDeclContext(); | ||||||
298 | |||||||
299 | bool Visible = false; | ||||||
300 | if (FromDC->containsDeclAndLoad(FromD)) { | ||||||
301 | ToDC->addDeclInternal(ToD); | ||||||
302 | Visible = true; | ||||||
303 | } | ||||||
304 | if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) { | ||||||
305 | ToLexicalDC->addDeclInternal(ToD); | ||||||
306 | Visible = true; | ||||||
307 | } | ||||||
308 | |||||||
309 | // If the Decl was added to any context, it was made already visible. | ||||||
310 | // Otherwise it is still possible that it should be visible. | ||||||
311 | if (!Visible) { | ||||||
312 | if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) { | ||||||
313 | auto *ToNamed = cast<NamedDecl>(ToD); | ||||||
314 | DeclContextLookupResult FromLookup = | ||||||
315 | FromDC->lookup(FromNamed->getDeclName()); | ||||||
316 | for (NamedDecl *ND : FromLookup) | ||||||
317 | if (ND == FromNamed) { | ||||||
318 | ToDC->makeDeclVisibleInContext(ToNamed); | ||||||
319 | break; | ||||||
320 | } | ||||||
321 | } | ||||||
322 | } | ||||||
323 | } | ||||||
324 | |||||||
325 | void updateLookupTableForTemplateParameters(TemplateParameterList &Params, | ||||||
326 | DeclContext *OldDC) { | ||||||
327 | ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable(); | ||||||
328 | if (!LT) | ||||||
329 | return; | ||||||
330 | |||||||
331 | for (NamedDecl *TP : Params) | ||||||
332 | LT->update(TP, OldDC); | ||||||
333 | } | ||||||
334 | |||||||
335 | void updateLookupTableForTemplateParameters(TemplateParameterList &Params) { | ||||||
336 | updateLookupTableForTemplateParameters( | ||||||
337 | Params, Importer.getToContext().getTranslationUnitDecl()); | ||||||
338 | } | ||||||
339 | |||||||
340 | public: | ||||||
341 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} | ||||||
342 | |||||||
343 | using TypeVisitor<ASTNodeImporter, ExpectedType>::Visit; | ||||||
344 | using DeclVisitor<ASTNodeImporter, ExpectedDecl>::Visit; | ||||||
345 | using StmtVisitor<ASTNodeImporter, ExpectedStmt>::Visit; | ||||||
346 | |||||||
347 | // Importing types | ||||||
348 | ExpectedType VisitType(const Type *T); | ||||||
349 | ExpectedType VisitAtomicType(const AtomicType *T); | ||||||
350 | ExpectedType VisitBuiltinType(const BuiltinType *T); | ||||||
351 | ExpectedType VisitDecayedType(const DecayedType *T); | ||||||
352 | ExpectedType VisitComplexType(const ComplexType *T); | ||||||
353 | ExpectedType VisitPointerType(const PointerType *T); | ||||||
354 | ExpectedType VisitBlockPointerType(const BlockPointerType *T); | ||||||
355 | ExpectedType VisitLValueReferenceType(const LValueReferenceType *T); | ||||||
356 | ExpectedType VisitRValueReferenceType(const RValueReferenceType *T); | ||||||
357 | ExpectedType VisitMemberPointerType(const MemberPointerType *T); | ||||||
358 | ExpectedType VisitConstantArrayType(const ConstantArrayType *T); | ||||||
359 | ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T); | ||||||
360 | ExpectedType VisitVariableArrayType(const VariableArrayType *T); | ||||||
361 | ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T); | ||||||
362 | // FIXME: DependentSizedExtVectorType | ||||||
363 | ExpectedType VisitVectorType(const VectorType *T); | ||||||
364 | ExpectedType VisitExtVectorType(const ExtVectorType *T); | ||||||
365 | ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T); | ||||||
366 | ExpectedType VisitFunctionProtoType(const FunctionProtoType *T); | ||||||
367 | ExpectedType VisitUnresolvedUsingType(const UnresolvedUsingType *T); | ||||||
368 | ExpectedType VisitParenType(const ParenType *T); | ||||||
369 | ExpectedType VisitTypedefType(const TypedefType *T); | ||||||
370 | ExpectedType VisitTypeOfExprType(const TypeOfExprType *T); | ||||||
371 | // FIXME: DependentTypeOfExprType | ||||||
372 | ExpectedType VisitTypeOfType(const TypeOfType *T); | ||||||
373 | ExpectedType VisitDecltypeType(const DecltypeType *T); | ||||||
374 | ExpectedType VisitUnaryTransformType(const UnaryTransformType *T); | ||||||
375 | ExpectedType VisitAutoType(const AutoType *T); | ||||||
376 | ExpectedType VisitDeducedTemplateSpecializationType( | ||||||
377 | const DeducedTemplateSpecializationType *T); | ||||||
378 | ExpectedType VisitInjectedClassNameType(const InjectedClassNameType *T); | ||||||
379 | // FIXME: DependentDecltypeType | ||||||
380 | ExpectedType VisitRecordType(const RecordType *T); | ||||||
381 | ExpectedType VisitEnumType(const EnumType *T); | ||||||
382 | ExpectedType VisitAttributedType(const AttributedType *T); | ||||||
383 | ExpectedType VisitTemplateTypeParmType(const TemplateTypeParmType *T); | ||||||
384 | ExpectedType VisitSubstTemplateTypeParmType( | ||||||
385 | const SubstTemplateTypeParmType *T); | ||||||
386 | ExpectedType VisitTemplateSpecializationType( | ||||||
387 | const TemplateSpecializationType *T); | ||||||
388 | ExpectedType VisitElaboratedType(const ElaboratedType *T); | ||||||
389 | ExpectedType VisitDependentNameType(const DependentNameType *T); | ||||||
390 | ExpectedType VisitPackExpansionType(const PackExpansionType *T); | ||||||
391 | ExpectedType VisitDependentTemplateSpecializationType( | ||||||
392 | const DependentTemplateSpecializationType *T); | ||||||
393 | ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T); | ||||||
394 | ExpectedType VisitObjCObjectType(const ObjCObjectType *T); | ||||||
395 | ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); | ||||||
396 | |||||||
397 | // Importing declarations | ||||||
398 | Error ImportDeclParts(NamedDecl *D, DeclarationName &Name, NamedDecl *&ToD, | ||||||
399 | SourceLocation &Loc); | ||||||
400 | Error ImportDeclParts( | ||||||
401 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, | ||||||
402 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc); | ||||||
403 | Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); | ||||||
404 | Error ImportDeclarationNameLoc( | ||||||
405 | const DeclarationNameInfo &From, DeclarationNameInfo &To); | ||||||
406 | Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); | ||||||
407 | Error ImportDeclContext( | ||||||
408 | Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC); | ||||||
409 | Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To); | ||||||
410 | |||||||
411 | Expected<CXXCastPath> ImportCastPath(CastExpr *E); | ||||||
412 | Expected<APValue> ImportAPValue(const APValue &FromValue); | ||||||
413 | |||||||
414 | using Designator = DesignatedInitExpr::Designator; | ||||||
415 | |||||||
416 | /// What we should import from the definition. | ||||||
417 | enum ImportDefinitionKind { | ||||||
418 | /// Import the default subset of the definition, which might be | ||||||
419 | /// nothing (if minimal import is set) or might be everything (if minimal | ||||||
420 | /// import is not set). | ||||||
421 | IDK_Default, | ||||||
422 | /// Import everything. | ||||||
423 | IDK_Everything, | ||||||
424 | /// Import only the bare bones needed to establish a valid | ||||||
425 | /// DeclContext. | ||||||
426 | IDK_Basic | ||||||
427 | }; | ||||||
428 | |||||||
429 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { | ||||||
430 | return IDK == IDK_Everything || | ||||||
431 | (IDK == IDK_Default && !Importer.isMinimalImport()); | ||||||
432 | } | ||||||
433 | |||||||
434 | Error ImportInitializer(VarDecl *From, VarDecl *To); | ||||||
435 | Error ImportDefinition( | ||||||
436 | RecordDecl *From, RecordDecl *To, | ||||||
437 | ImportDefinitionKind Kind = IDK_Default); | ||||||
438 | Error ImportDefinition( | ||||||
439 | EnumDecl *From, EnumDecl *To, | ||||||
440 | ImportDefinitionKind Kind = IDK_Default); | ||||||
441 | Error ImportDefinition( | ||||||
442 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, | ||||||
443 | ImportDefinitionKind Kind = IDK_Default); | ||||||
444 | Error ImportDefinition( | ||||||
445 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, | ||||||
446 | ImportDefinitionKind Kind = IDK_Default); | ||||||
447 | Error ImportTemplateArguments( | ||||||
448 | const TemplateArgument *FromArgs, unsigned NumFromArgs, | ||||||
449 | SmallVectorImpl<TemplateArgument> &ToArgs); | ||||||
450 | Expected<TemplateArgument> | ||||||
451 | ImportTemplateArgument(const TemplateArgument &From); | ||||||
452 | |||||||
453 | template <typename InContainerTy> | ||||||
454 | Error ImportTemplateArgumentListInfo( | ||||||
455 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo); | ||||||
456 | |||||||
457 | template<typename InContainerTy> | ||||||
458 | Error ImportTemplateArgumentListInfo( | ||||||
459 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, | ||||||
460 | const InContainerTy &Container, TemplateArgumentListInfo &Result); | ||||||
461 | |||||||
462 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; | ||||||
463 | using FunctionTemplateAndArgsTy = | ||||||
464 | std::tuple<FunctionTemplateDecl *, TemplateArgsTy>; | ||||||
465 | Expected<FunctionTemplateAndArgsTy> | ||||||
466 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( | ||||||
467 | FunctionDecl *FromFD); | ||||||
468 | Error ImportTemplateParameterLists(const DeclaratorDecl *FromD, | ||||||
469 | DeclaratorDecl *ToD); | ||||||
470 | |||||||
471 | Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); | ||||||
472 | |||||||
473 | Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD); | ||||||
474 | |||||||
475 | Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam, | ||||||
476 | ParmVarDecl *ToParam); | ||||||
477 | |||||||
478 | template <typename T> | ||||||
479 | bool hasSameVisibilityContextAndLinkage(T *Found, T *From); | ||||||
480 | |||||||
481 | bool IsStructuralMatch(Decl *From, Decl *To, bool Complain); | ||||||
482 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, | ||||||
483 | bool Complain = true); | ||||||
484 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, | ||||||
485 | bool Complain = true); | ||||||
486 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); | ||||||
487 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); | ||||||
488 | bool IsStructuralMatch(FunctionTemplateDecl *From, | ||||||
489 | FunctionTemplateDecl *To); | ||||||
490 | bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To); | ||||||
491 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); | ||||||
492 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); | ||||||
493 | ExpectedDecl VisitDecl(Decl *D); | ||||||
494 | ExpectedDecl VisitImportDecl(ImportDecl *D); | ||||||
495 | ExpectedDecl VisitEmptyDecl(EmptyDecl *D); | ||||||
496 | ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D); | ||||||
497 | ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D); | ||||||
498 | ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D); | ||||||
499 | ExpectedDecl VisitBindingDecl(BindingDecl *D); | ||||||
500 | ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D); | ||||||
501 | ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D); | ||||||
502 | ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); | ||||||
503 | ExpectedDecl VisitTypedefDecl(TypedefDecl *D); | ||||||
504 | ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D); | ||||||
505 | ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); | ||||||
506 | ExpectedDecl VisitLabelDecl(LabelDecl *D); | ||||||
507 | ExpectedDecl VisitEnumDecl(EnumDecl *D); | ||||||
508 | ExpectedDecl VisitRecordDecl(RecordDecl *D); | ||||||
509 | ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D); | ||||||
510 | ExpectedDecl VisitFunctionDecl(FunctionDecl *D); | ||||||
511 | ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D); | ||||||
512 | ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); | ||||||
513 | ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); | ||||||
514 | ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); | ||||||
515 | ExpectedDecl VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D); | ||||||
516 | ExpectedDecl VisitFieldDecl(FieldDecl *D); | ||||||
517 | ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); | ||||||
518 | ExpectedDecl VisitFriendDecl(FriendDecl *D); | ||||||
519 | ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D); | ||||||
520 | ExpectedDecl VisitVarDecl(VarDecl *D); | ||||||
521 | ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D); | ||||||
522 | ExpectedDecl VisitParmVarDecl(ParmVarDecl *D); | ||||||
523 | ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D); | ||||||
524 | ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); | ||||||
525 | ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D); | ||||||
526 | ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D); | ||||||
527 | ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D); | ||||||
528 | ExpectedDecl VisitUsingDecl(UsingDecl *D); | ||||||
529 | ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D); | ||||||
530 | ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D); | ||||||
531 | ExpectedDecl ImportUsingShadowDecls(BaseUsingDecl *D, BaseUsingDecl *ToSI); | ||||||
532 | ExpectedDecl VisitUsingEnumDecl(UsingEnumDecl *D); | ||||||
533 | ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); | ||||||
534 | ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); | ||||||
535 | ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D); | ||||||
536 | ExpectedDecl | ||||||
537 | VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D); | ||||||
538 | |||||||
539 | Expected<ObjCTypeParamList *> | ||||||
540 | ImportObjCTypeParamList(ObjCTypeParamList *list); | ||||||
541 | |||||||
542 | ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); | ||||||
543 | ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); | ||||||
544 | ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D); | ||||||
545 | ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D); | ||||||
546 | ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); | ||||||
547 | ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); | ||||||
548 | ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); | ||||||
549 | ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); | ||||||
550 | ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D); | ||||||
551 | ExpectedDecl VisitClassTemplateSpecializationDecl( | ||||||
552 | ClassTemplateSpecializationDecl *D); | ||||||
553 | ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D); | ||||||
554 | ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); | ||||||
555 | ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D); | ||||||
556 | |||||||
557 | // Importing statements | ||||||
558 | ExpectedStmt VisitStmt(Stmt *S); | ||||||
559 | ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S); | ||||||
560 | ExpectedStmt VisitDeclStmt(DeclStmt *S); | ||||||
561 | ExpectedStmt VisitNullStmt(NullStmt *S); | ||||||
562 | ExpectedStmt VisitCompoundStmt(CompoundStmt *S); | ||||||
563 | ExpectedStmt VisitCaseStmt(CaseStmt *S); | ||||||
564 | ExpectedStmt VisitDefaultStmt(DefaultStmt *S); | ||||||
565 | ExpectedStmt VisitLabelStmt(LabelStmt *S); | ||||||
566 | ExpectedStmt VisitAttributedStmt(AttributedStmt *S); | ||||||
567 | ExpectedStmt VisitIfStmt(IfStmt *S); | ||||||
568 | ExpectedStmt VisitSwitchStmt(SwitchStmt *S); | ||||||
569 | ExpectedStmt VisitWhileStmt(WhileStmt *S); | ||||||
570 | ExpectedStmt VisitDoStmt(DoStmt *S); | ||||||
571 | ExpectedStmt VisitForStmt(ForStmt *S); | ||||||
572 | ExpectedStmt VisitGotoStmt(GotoStmt *S); | ||||||
573 | ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S); | ||||||
574 | ExpectedStmt VisitContinueStmt(ContinueStmt *S); | ||||||
575 | ExpectedStmt VisitBreakStmt(BreakStmt *S); | ||||||
576 | ExpectedStmt VisitReturnStmt(ReturnStmt *S); | ||||||
577 | // FIXME: MSAsmStmt | ||||||
578 | // FIXME: SEHExceptStmt | ||||||
579 | // FIXME: SEHFinallyStmt | ||||||
580 | // FIXME: SEHTryStmt | ||||||
581 | // FIXME: SEHLeaveStmt | ||||||
582 | // FIXME: CapturedStmt | ||||||
583 | ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S); | ||||||
584 | ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S); | ||||||
585 | ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S); | ||||||
586 | // FIXME: MSDependentExistsStmt | ||||||
587 | ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); | ||||||
588 | ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); | ||||||
589 | ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); | ||||||
590 | ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S); | ||||||
591 | ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); | ||||||
592 | ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); | ||||||
593 | ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); | ||||||
594 | |||||||
595 | // Importing expressions | ||||||
596 | ExpectedStmt VisitExpr(Expr *E); | ||||||
597 | ExpectedStmt VisitSourceLocExpr(SourceLocExpr *E); | ||||||
598 | ExpectedStmt VisitVAArgExpr(VAArgExpr *E); | ||||||
599 | ExpectedStmt VisitChooseExpr(ChooseExpr *E); | ||||||
600 | ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E); | ||||||
601 | ExpectedStmt VisitGenericSelectionExpr(GenericSelectionExpr *E); | ||||||
602 | ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E); | ||||||
603 | ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E); | ||||||
604 | ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); | ||||||
605 | ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E); | ||||||
606 | ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); | ||||||
607 | ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E); | ||||||
608 | ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E); | ||||||
609 | ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E); | ||||||
610 | ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E); | ||||||
611 | ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E); | ||||||
612 | ExpectedStmt VisitStringLiteral(StringLiteral *E); | ||||||
613 | ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E); | ||||||
614 | ExpectedStmt VisitAtomicExpr(AtomicExpr *E); | ||||||
615 | ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E); | ||||||
616 | ExpectedStmt VisitConstantExpr(ConstantExpr *E); | ||||||
617 | ExpectedStmt VisitParenExpr(ParenExpr *E); | ||||||
618 | ExpectedStmt VisitParenListExpr(ParenListExpr *E); | ||||||
619 | ExpectedStmt VisitStmtExpr(StmtExpr *E); | ||||||
620 | ExpectedStmt VisitUnaryOperator(UnaryOperator *E); | ||||||
621 | ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); | ||||||
622 | ExpectedStmt VisitBinaryOperator(BinaryOperator *E); | ||||||
623 | ExpectedStmt VisitConditionalOperator(ConditionalOperator *E); | ||||||
624 | ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E); | ||||||
625 | ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E); | ||||||
626 | ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); | ||||||
627 | ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E); | ||||||
628 | ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E); | ||||||
629 | ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E); | ||||||
630 | ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E); | ||||||
631 | ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E); | ||||||
632 | ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE); | ||||||
633 | ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E); | ||||||
634 | ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E); | ||||||
635 | ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); | ||||||
636 | ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); | ||||||
637 | ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); | ||||||
638 | ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); | ||||||
639 | ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); | ||||||
640 | ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E); | ||||||
641 | ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E); | ||||||
642 | ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E); | ||||||
643 | ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E); | ||||||
644 | ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E); | ||||||
645 | ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E); | ||||||
646 | ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); | ||||||
647 | ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); | ||||||
648 | ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); | ||||||
649 | ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); | ||||||
650 | ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); | ||||||
651 | ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E); | ||||||
652 | ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E); | ||||||
653 | ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); | ||||||
654 | ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); | ||||||
655 | ExpectedStmt VisitMemberExpr(MemberExpr *E); | ||||||
656 | ExpectedStmt VisitCallExpr(CallExpr *E); | ||||||
657 | ExpectedStmt VisitLambdaExpr(LambdaExpr *LE); | ||||||
658 | ExpectedStmt VisitInitListExpr(InitListExpr *E); | ||||||
659 | ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); | ||||||
660 | ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); | ||||||
661 | ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); | ||||||
662 | ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); | ||||||
663 | ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); | ||||||
664 | ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E); | ||||||
665 | ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); | ||||||
666 | ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); | ||||||
667 | ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); | ||||||
668 | ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E); | ||||||
669 | |||||||
670 | template<typename IIter, typename OIter> | ||||||
671 | Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { | ||||||
672 | using ItemT = std::remove_reference_t<decltype(*Obegin)>; | ||||||
673 | for (; Ibegin != Iend; ++Ibegin, ++Obegin) { | ||||||
674 | Expected<ItemT> ToOrErr = import(*Ibegin); | ||||||
675 | if (!ToOrErr) | ||||||
676 | return ToOrErr.takeError(); | ||||||
677 | *Obegin = *ToOrErr; | ||||||
678 | } | ||||||
679 | return Error::success(); | ||||||
680 | } | ||||||
681 | |||||||
682 | // Import every item from a container structure into an output container. | ||||||
683 | // If error occurs, stops at first error and returns the error. | ||||||
684 | // The output container should have space for all needed elements (it is not | ||||||
685 | // expanded, new items are put into from the beginning). | ||||||
686 | template<typename InContainerTy, typename OutContainerTy> | ||||||
687 | Error ImportContainerChecked( | ||||||
688 | const InContainerTy &InContainer, OutContainerTy &OutContainer) { | ||||||
689 | return ImportArrayChecked( | ||||||
690 | InContainer.begin(), InContainer.end(), OutContainer.begin()); | ||||||
691 | } | ||||||
692 | |||||||
693 | template<typename InContainerTy, typename OIter> | ||||||
694 | Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { | ||||||
695 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); | ||||||
696 | } | ||||||
697 | |||||||
698 | Error ImportOverriddenMethods(CXXMethodDecl *ToMethod, | ||||||
699 | CXXMethodDecl *FromMethod); | ||||||
700 | |||||||
701 | Expected<FunctionDecl *> FindFunctionTemplateSpecialization( | ||||||
702 | FunctionDecl *FromFD); | ||||||
703 | |||||||
704 | // Returns true if the given function has a placeholder return type and | ||||||
705 | // that type is declared inside the body of the function. | ||||||
706 | // E.g. auto f() { struct X{}; return X(); } | ||||||
707 | bool hasAutoReturnTypeDeclaredInside(FunctionDecl *D); | ||||||
708 | }; | ||||||
709 | |||||||
710 | template <typename InContainerTy> | ||||||
711 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( | ||||||
712 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, | ||||||
713 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { | ||||||
714 | auto ToLAngleLocOrErr = import(FromLAngleLoc); | ||||||
715 | if (!ToLAngleLocOrErr) | ||||||
716 | return ToLAngleLocOrErr.takeError(); | ||||||
717 | auto ToRAngleLocOrErr = import(FromRAngleLoc); | ||||||
718 | if (!ToRAngleLocOrErr) | ||||||
719 | return ToRAngleLocOrErr.takeError(); | ||||||
720 | |||||||
721 | TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr); | ||||||
722 | if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo)) | ||||||
723 | return Err; | ||||||
724 | Result = ToTAInfo; | ||||||
725 | return Error::success(); | ||||||
726 | } | ||||||
727 | |||||||
728 | template <> | ||||||
729 | Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( | ||||||
730 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { | ||||||
731 | return ImportTemplateArgumentListInfo( | ||||||
732 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); | ||||||
733 | } | ||||||
734 | |||||||
735 | template <> | ||||||
736 | Error ASTNodeImporter::ImportTemplateArgumentListInfo< | ||||||
737 | ASTTemplateArgumentListInfo>( | ||||||
738 | const ASTTemplateArgumentListInfo &From, | ||||||
739 | TemplateArgumentListInfo &Result) { | ||||||
740 | return ImportTemplateArgumentListInfo( | ||||||
741 | From.LAngleLoc, From.RAngleLoc, From.arguments(), Result); | ||||||
742 | } | ||||||
743 | |||||||
744 | Expected<ASTNodeImporter::FunctionTemplateAndArgsTy> | ||||||
745 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( | ||||||
746 | FunctionDecl *FromFD) { | ||||||
747 | assert(FromFD->getTemplatedKind() ==(static_cast <bool> (FromFD->getTemplatedKind() == FunctionDecl ::TK_FunctionTemplateSpecialization) ? void (0) : __assert_fail ("FromFD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplateSpecialization" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 748, __extension__ __PRETTY_FUNCTION__)) | ||||||
748 | FunctionDecl::TK_FunctionTemplateSpecialization)(static_cast <bool> (FromFD->getTemplatedKind() == FunctionDecl ::TK_FunctionTemplateSpecialization) ? void (0) : __assert_fail ("FromFD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplateSpecialization" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 748, __extension__ __PRETTY_FUNCTION__)); | ||||||
749 | |||||||
750 | FunctionTemplateAndArgsTy Result; | ||||||
751 | |||||||
752 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); | ||||||
753 | if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate())) | ||||||
754 | return std::move(Err); | ||||||
755 | |||||||
756 | // Import template arguments. | ||||||
757 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); | ||||||
758 | if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), | ||||||
759 | std::get<1>(Result))) | ||||||
760 | return std::move(Err); | ||||||
761 | |||||||
762 | return Result; | ||||||
763 | } | ||||||
764 | |||||||
765 | template <> | ||||||
766 | Expected<TemplateParameterList *> | ||||||
767 | ASTNodeImporter::import(TemplateParameterList *From) { | ||||||
768 | SmallVector<NamedDecl *, 4> To(From->size()); | ||||||
769 | if (Error Err = ImportContainerChecked(*From, To)) | ||||||
770 | return std::move(Err); | ||||||
771 | |||||||
772 | ExpectedExpr ToRequiresClause = import(From->getRequiresClause()); | ||||||
773 | if (!ToRequiresClause) | ||||||
774 | return ToRequiresClause.takeError(); | ||||||
775 | |||||||
776 | auto ToTemplateLocOrErr = import(From->getTemplateLoc()); | ||||||
777 | if (!ToTemplateLocOrErr) | ||||||
778 | return ToTemplateLocOrErr.takeError(); | ||||||
779 | auto ToLAngleLocOrErr = import(From->getLAngleLoc()); | ||||||
780 | if (!ToLAngleLocOrErr) | ||||||
781 | return ToLAngleLocOrErr.takeError(); | ||||||
782 | auto ToRAngleLocOrErr = import(From->getRAngleLoc()); | ||||||
783 | if (!ToRAngleLocOrErr) | ||||||
784 | return ToRAngleLocOrErr.takeError(); | ||||||
785 | |||||||
786 | return TemplateParameterList::Create( | ||||||
787 | Importer.getToContext(), | ||||||
788 | *ToTemplateLocOrErr, | ||||||
789 | *ToLAngleLocOrErr, | ||||||
790 | To, | ||||||
791 | *ToRAngleLocOrErr, | ||||||
792 | *ToRequiresClause); | ||||||
793 | } | ||||||
794 | |||||||
795 | template <> | ||||||
796 | Expected<TemplateArgument> | ||||||
797 | ASTNodeImporter::import(const TemplateArgument &From) { | ||||||
798 | switch (From.getKind()) { | ||||||
799 | case TemplateArgument::Null: | ||||||
800 | return TemplateArgument(); | ||||||
801 | |||||||
802 | case TemplateArgument::Type: { | ||||||
803 | ExpectedType ToTypeOrErr = import(From.getAsType()); | ||||||
804 | if (!ToTypeOrErr) | ||||||
805 | return ToTypeOrErr.takeError(); | ||||||
806 | return TemplateArgument(*ToTypeOrErr); | ||||||
807 | } | ||||||
808 | |||||||
809 | case TemplateArgument::Integral: { | ||||||
810 | ExpectedType ToTypeOrErr = import(From.getIntegralType()); | ||||||
811 | if (!ToTypeOrErr) | ||||||
812 | return ToTypeOrErr.takeError(); | ||||||
813 | return TemplateArgument(From, *ToTypeOrErr); | ||||||
814 | } | ||||||
815 | |||||||
816 | case TemplateArgument::Declaration: { | ||||||
817 | Expected<ValueDecl *> ToOrErr = import(From.getAsDecl()); | ||||||
818 | if (!ToOrErr) | ||||||
819 | return ToOrErr.takeError(); | ||||||
820 | ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); | ||||||
821 | if (!ToTypeOrErr) | ||||||
822 | return ToTypeOrErr.takeError(); | ||||||
823 | return TemplateArgument(*ToOrErr, *ToTypeOrErr); | ||||||
824 | } | ||||||
825 | |||||||
826 | case TemplateArgument::NullPtr: { | ||||||
827 | ExpectedType ToTypeOrErr = import(From.getNullPtrType()); | ||||||
828 | if (!ToTypeOrErr) | ||||||
829 | return ToTypeOrErr.takeError(); | ||||||
830 | return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); | ||||||
831 | } | ||||||
832 | |||||||
833 | case TemplateArgument::Template: { | ||||||
834 | Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate()); | ||||||
835 | if (!ToTemplateOrErr) | ||||||
836 | return ToTemplateOrErr.takeError(); | ||||||
837 | |||||||
838 | return TemplateArgument(*ToTemplateOrErr); | ||||||
839 | } | ||||||
840 | |||||||
841 | case TemplateArgument::TemplateExpansion: { | ||||||
842 | Expected<TemplateName> ToTemplateOrErr = | ||||||
843 | import(From.getAsTemplateOrTemplatePattern()); | ||||||
844 | if (!ToTemplateOrErr) | ||||||
845 | return ToTemplateOrErr.takeError(); | ||||||
846 | |||||||
847 | return TemplateArgument( | ||||||
848 | *ToTemplateOrErr, From.getNumTemplateExpansions()); | ||||||
849 | } | ||||||
850 | |||||||
851 | case TemplateArgument::Expression: | ||||||
852 | if (ExpectedExpr ToExpr = import(From.getAsExpr())) | ||||||
853 | return TemplateArgument(*ToExpr); | ||||||
854 | else | ||||||
855 | return ToExpr.takeError(); | ||||||
856 | |||||||
857 | case TemplateArgument::Pack: { | ||||||
858 | SmallVector<TemplateArgument, 2> ToPack; | ||||||
859 | ToPack.reserve(From.pack_size()); | ||||||
860 | if (Error Err = ImportTemplateArguments( | ||||||
861 | From.pack_begin(), From.pack_size(), ToPack)) | ||||||
862 | return std::move(Err); | ||||||
863 | |||||||
864 | return TemplateArgument( | ||||||
865 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); | ||||||
866 | } | ||||||
867 | } | ||||||
868 | |||||||
869 | llvm_unreachable("Invalid template argument kind")::llvm::llvm_unreachable_internal("Invalid template argument kind" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 869); | ||||||
870 | } | ||||||
871 | |||||||
872 | template <> | ||||||
873 | Expected<TemplateArgumentLoc> | ||||||
874 | ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) { | ||||||
875 | Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument()); | ||||||
876 | if (!ArgOrErr) | ||||||
877 | return ArgOrErr.takeError(); | ||||||
878 | TemplateArgument Arg = *ArgOrErr; | ||||||
879 | |||||||
880 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); | ||||||
881 | |||||||
882 | TemplateArgumentLocInfo ToInfo; | ||||||
883 | if (Arg.getKind() == TemplateArgument::Expression) { | ||||||
884 | ExpectedExpr E = import(FromInfo.getAsExpr()); | ||||||
885 | if (!E) | ||||||
886 | return E.takeError(); | ||||||
887 | ToInfo = TemplateArgumentLocInfo(*E); | ||||||
888 | } else if (Arg.getKind() == TemplateArgument::Type) { | ||||||
889 | if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo())) | ||||||
890 | ToInfo = TemplateArgumentLocInfo(*TSIOrErr); | ||||||
891 | else | ||||||
892 | return TSIOrErr.takeError(); | ||||||
893 | } else { | ||||||
894 | auto ToTemplateQualifierLocOrErr = | ||||||
895 | import(FromInfo.getTemplateQualifierLoc()); | ||||||
896 | if (!ToTemplateQualifierLocOrErr) | ||||||
897 | return ToTemplateQualifierLocOrErr.takeError(); | ||||||
898 | auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc()); | ||||||
899 | if (!ToTemplateNameLocOrErr) | ||||||
900 | return ToTemplateNameLocOrErr.takeError(); | ||||||
901 | auto ToTemplateEllipsisLocOrErr = | ||||||
902 | import(FromInfo.getTemplateEllipsisLoc()); | ||||||
903 | if (!ToTemplateEllipsisLocOrErr) | ||||||
904 | return ToTemplateEllipsisLocOrErr.takeError(); | ||||||
905 | ToInfo = TemplateArgumentLocInfo( | ||||||
906 | Importer.getToContext(), *ToTemplateQualifierLocOrErr, | ||||||
907 | *ToTemplateNameLocOrErr, *ToTemplateEllipsisLocOrErr); | ||||||
908 | } | ||||||
909 | |||||||
910 | return TemplateArgumentLoc(Arg, ToInfo); | ||||||
911 | } | ||||||
912 | |||||||
913 | template <> | ||||||
914 | Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) { | ||||||
915 | if (DG.isNull()) | ||||||
916 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); | ||||||
917 | size_t NumDecls = DG.end() - DG.begin(); | ||||||
918 | SmallVector<Decl *, 1> ToDecls; | ||||||
919 | ToDecls.reserve(NumDecls); | ||||||
920 | for (Decl *FromD : DG) { | ||||||
921 | if (auto ToDOrErr = import(FromD)) | ||||||
922 | ToDecls.push_back(*ToDOrErr); | ||||||
923 | else | ||||||
924 | return ToDOrErr.takeError(); | ||||||
925 | } | ||||||
926 | return DeclGroupRef::Create(Importer.getToContext(), | ||||||
927 | ToDecls.begin(), | ||||||
928 | NumDecls); | ||||||
929 | } | ||||||
930 | |||||||
931 | template <> | ||||||
932 | Expected<ASTNodeImporter::Designator> | ||||||
933 | ASTNodeImporter::import(const Designator &D) { | ||||||
934 | if (D.isFieldDesignator()) { | ||||||
935 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); | ||||||
936 | |||||||
937 | ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc()); | ||||||
938 | if (!ToDotLocOrErr) | ||||||
939 | return ToDotLocOrErr.takeError(); | ||||||
940 | |||||||
941 | ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc()); | ||||||
942 | if (!ToFieldLocOrErr) | ||||||
943 | return ToFieldLocOrErr.takeError(); | ||||||
944 | |||||||
945 | return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr); | ||||||
946 | } | ||||||
947 | |||||||
948 | ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc()); | ||||||
949 | if (!ToLBracketLocOrErr) | ||||||
950 | return ToLBracketLocOrErr.takeError(); | ||||||
951 | |||||||
952 | ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc()); | ||||||
953 | if (!ToRBracketLocOrErr) | ||||||
954 | return ToRBracketLocOrErr.takeError(); | ||||||
955 | |||||||
956 | if (D.isArrayDesignator()) | ||||||
957 | return Designator(D.getFirstExprIndex(), | ||||||
958 | *ToLBracketLocOrErr, *ToRBracketLocOrErr); | ||||||
959 | |||||||
960 | ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc()); | ||||||
961 | if (!ToEllipsisLocOrErr) | ||||||
962 | return ToEllipsisLocOrErr.takeError(); | ||||||
963 | |||||||
964 | assert(D.isArrayRangeDesignator())(static_cast <bool> (D.isArrayRangeDesignator()) ? void (0) : __assert_fail ("D.isArrayRangeDesignator()", "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 964, __extension__ __PRETTY_FUNCTION__)); | ||||||
965 | return Designator( | ||||||
966 | D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr, | ||||||
967 | *ToRBracketLocOrErr); | ||||||
968 | } | ||||||
969 | |||||||
970 | template <> | ||||||
971 | Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) { | ||||||
972 | VarDecl *Var = nullptr; | ||||||
973 | if (From.capturesVariable()) { | ||||||
974 | if (auto VarOrErr = import(From.getCapturedVar())) | ||||||
975 | Var = *VarOrErr; | ||||||
976 | else | ||||||
977 | return VarOrErr.takeError(); | ||||||
978 | } | ||||||
979 | |||||||
980 | auto LocationOrErr = import(From.getLocation()); | ||||||
981 | if (!LocationOrErr) | ||||||
982 | return LocationOrErr.takeError(); | ||||||
983 | |||||||
984 | SourceLocation EllipsisLoc; | ||||||
985 | if (From.isPackExpansion()) | ||||||
986 | if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc())) | ||||||
987 | return std::move(Err); | ||||||
988 | |||||||
989 | return LambdaCapture( | ||||||
990 | *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var, | ||||||
991 | EllipsisLoc); | ||||||
992 | } | ||||||
993 | |||||||
994 | template <typename T> | ||||||
995 | bool ASTNodeImporter::hasSameVisibilityContextAndLinkage(T *Found, T *From) { | ||||||
996 | if (Found->getLinkageInternal() != From->getLinkageInternal()) | ||||||
997 | return false; | ||||||
998 | |||||||
999 | if (From->hasExternalFormalLinkage()) | ||||||
1000 | return Found->hasExternalFormalLinkage(); | ||||||
1001 | if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl()) | ||||||
1002 | return false; | ||||||
1003 | if (From->isInAnonymousNamespace()) | ||||||
1004 | return Found->isInAnonymousNamespace(); | ||||||
1005 | else | ||||||
1006 | return !Found->isInAnonymousNamespace() && | ||||||
1007 | !Found->hasExternalFormalLinkage(); | ||||||
1008 | } | ||||||
1009 | |||||||
1010 | template <> | ||||||
1011 | bool ASTNodeImporter::hasSameVisibilityContextAndLinkage(TypedefNameDecl *Found, | ||||||
1012 | TypedefNameDecl *From) { | ||||||
1013 | if (Found->getLinkageInternal() != From->getLinkageInternal()) | ||||||
1014 | return false; | ||||||
1015 | |||||||
1016 | if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace()) | ||||||
1017 | return Importer.GetFromTU(Found) == From->getTranslationUnitDecl(); | ||||||
1018 | return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace(); | ||||||
1019 | } | ||||||
1020 | |||||||
1021 | } // namespace clang | ||||||
1022 | |||||||
1023 | //---------------------------------------------------------------------------- | ||||||
1024 | // Import Types | ||||||
1025 | //---------------------------------------------------------------------------- | ||||||
1026 | |||||||
1027 | using namespace clang; | ||||||
1028 | |||||||
1029 | ExpectedType ASTNodeImporter::VisitType(const Type *T) { | ||||||
1030 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) | ||||||
1031 | << T->getTypeClassName(); | ||||||
1032 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | ||||||
1033 | } | ||||||
1034 | |||||||
1035 | ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ | ||||||
1036 | ExpectedType UnderlyingTypeOrErr = import(T->getValueType()); | ||||||
1037 | if (!UnderlyingTypeOrErr) | ||||||
1038 | return UnderlyingTypeOrErr.takeError(); | ||||||
1039 | |||||||
1040 | return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr); | ||||||
1041 | } | ||||||
1042 | |||||||
1043 | ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { | ||||||
1044 | switch (T->getKind()) { | ||||||
1045 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ | ||||||
1046 | case BuiltinType::Id: \ | ||||||
1047 | return Importer.getToContext().SingletonId; | ||||||
1048 | #include "clang/Basic/OpenCLImageTypes.def" | ||||||
1049 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ | ||||||
1050 | case BuiltinType::Id: \ | ||||||
1051 | return Importer.getToContext().Id##Ty; | ||||||
1052 | #include "clang/Basic/OpenCLExtensionTypes.def" | ||||||
1053 | #define SVE_TYPE(Name, Id, SingletonId) \ | ||||||
1054 | case BuiltinType::Id: \ | ||||||
1055 | return Importer.getToContext().SingletonId; | ||||||
1056 | #include "clang/Basic/AArch64SVEACLETypes.def" | ||||||
1057 | #define PPC_VECTOR_TYPE(Name, Id, Size) \ | ||||||
1058 | case BuiltinType::Id: \ | ||||||
1059 | return Importer.getToContext().Id##Ty; | ||||||
1060 | #include "clang/Basic/PPCTypes.def" | ||||||
1061 | #define RVV_TYPE(Name, Id, SingletonId) \ | ||||||
1062 | case BuiltinType::Id: \ | ||||||
1063 | return Importer.getToContext().SingletonId; | ||||||
1064 | #include "clang/Basic/RISCVVTypes.def" | ||||||
1065 | #define SHARED_SINGLETON_TYPE(Expansion) | ||||||
1066 | #define BUILTIN_TYPE(Id, SingletonId) \ | ||||||
1067 | case BuiltinType::Id: return Importer.getToContext().SingletonId; | ||||||
1068 | #include "clang/AST/BuiltinTypes.def" | ||||||
1069 | |||||||
1070 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" | ||||||
1071 | // context supports C++. | ||||||
1072 | |||||||
1073 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" | ||||||
1074 | // context supports ObjC. | ||||||
1075 | |||||||
1076 | case BuiltinType::Char_U: | ||||||
1077 | // The context we're importing from has an unsigned 'char'. If we're | ||||||
1078 | // importing into a context with a signed 'char', translate to | ||||||
1079 | // 'unsigned char' instead. | ||||||
1080 | if (Importer.getToContext().getLangOpts().CharIsSigned) | ||||||
1081 | return Importer.getToContext().UnsignedCharTy; | ||||||
1082 | |||||||
1083 | return Importer.getToContext().CharTy; | ||||||
1084 | |||||||
1085 | case BuiltinType::Char_S: | ||||||
1086 | // The context we're importing from has an unsigned 'char'. If we're | ||||||
1087 | // importing into a context with a signed 'char', translate to | ||||||
1088 | // 'unsigned char' instead. | ||||||
1089 | if (!Importer.getToContext().getLangOpts().CharIsSigned) | ||||||
1090 | return Importer.getToContext().SignedCharTy; | ||||||
1091 | |||||||
1092 | return Importer.getToContext().CharTy; | ||||||
1093 | |||||||
1094 | case BuiltinType::WChar_S: | ||||||
1095 | case BuiltinType::WChar_U: | ||||||
1096 | // FIXME: If not in C++, shall we translate to the C equivalent of | ||||||
1097 | // wchar_t? | ||||||
1098 | return Importer.getToContext().WCharTy; | ||||||
1099 | } | ||||||
1100 | |||||||
1101 | llvm_unreachable("Invalid BuiltinType Kind!")::llvm::llvm_unreachable_internal("Invalid BuiltinType Kind!" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 1101); | ||||||
1102 | } | ||||||
1103 | |||||||
1104 | ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { | ||||||
1105 | ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType()); | ||||||
1106 | if (!ToOriginalTypeOrErr) | ||||||
1107 | return ToOriginalTypeOrErr.takeError(); | ||||||
1108 | |||||||
1109 | return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr); | ||||||
1110 | } | ||||||
1111 | |||||||
1112 | ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) { | ||||||
1113 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | ||||||
1114 | if (!ToElementTypeOrErr) | ||||||
1115 | return ToElementTypeOrErr.takeError(); | ||||||
1116 | |||||||
1117 | return Importer.getToContext().getComplexType(*ToElementTypeOrErr); | ||||||
1118 | } | ||||||
1119 | |||||||
1120 | ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) { | ||||||
1121 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | ||||||
1122 | if (!ToPointeeTypeOrErr) | ||||||
1123 | return ToPointeeTypeOrErr.takeError(); | ||||||
1124 | |||||||
1125 | return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr); | ||||||
1126 | } | ||||||
1127 | |||||||
1128 | ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { | ||||||
1129 | // FIXME: Check for blocks support in "to" context. | ||||||
1130 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | ||||||
1131 | if (!ToPointeeTypeOrErr) | ||||||
1132 | return ToPointeeTypeOrErr.takeError(); | ||||||
1133 | |||||||
1134 | return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr); | ||||||
1135 | } | ||||||
1136 | |||||||
1137 | ExpectedType | ||||||
1138 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { | ||||||
1139 | // FIXME: Check for C++ support in "to" context. | ||||||
1140 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); | ||||||
1141 | if (!ToPointeeTypeOrErr) | ||||||
1142 | return ToPointeeTypeOrErr.takeError(); | ||||||
1143 | |||||||
1144 | return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr); | ||||||
1145 | } | ||||||
1146 | |||||||
1147 | ExpectedType | ||||||
1148 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { | ||||||
1149 | // FIXME: Check for C++0x support in "to" context. | ||||||
1150 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); | ||||||
1151 | if (!ToPointeeTypeOrErr) | ||||||
1152 | return ToPointeeTypeOrErr.takeError(); | ||||||
1153 | |||||||
1154 | return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr); | ||||||
1155 | } | ||||||
1156 | |||||||
1157 | ExpectedType | ||||||
1158 | ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { | ||||||
1159 | // FIXME: Check for C++ support in "to" context. | ||||||
1160 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | ||||||
1161 | if (!ToPointeeTypeOrErr) | ||||||
1162 | return ToPointeeTypeOrErr.takeError(); | ||||||
1163 | |||||||
1164 | ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0)); | ||||||
1165 | if (!ClassTypeOrErr) | ||||||
1166 | return ClassTypeOrErr.takeError(); | ||||||
1167 | |||||||
1168 | return Importer.getToContext().getMemberPointerType( | ||||||
1169 | *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr()); | ||||||
1170 | } | ||||||
1171 | |||||||
1172 | ExpectedType | ||||||
1173 | ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { | ||||||
1174 | Error Err = Error::success(); | ||||||
1175 | auto ToElementType = importChecked(Err, T->getElementType()); | ||||||
1176 | auto ToSizeExpr = importChecked(Err, T->getSizeExpr()); | ||||||
1177 | if (Err) | ||||||
1178 | return std::move(Err); | ||||||
1179 | |||||||
1180 | return Importer.getToContext().getConstantArrayType( | ||||||
1181 | ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(), | ||||||
1182 | T->getIndexTypeCVRQualifiers()); | ||||||
1183 | } | ||||||
1184 | |||||||
1185 | ExpectedType | ||||||
1186 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { | ||||||
1187 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | ||||||
1188 | if (!ToElementTypeOrErr) | ||||||
1189 | return ToElementTypeOrErr.takeError(); | ||||||
1190 | |||||||
1191 | return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr, | ||||||
1192 | T->getSizeModifier(), | ||||||
1193 | T->getIndexTypeCVRQualifiers()); | ||||||
1194 | } | ||||||
1195 | |||||||
1196 | ExpectedType | ||||||
1197 | ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { | ||||||
1198 | Error Err = Error::success(); | ||||||
1199 | QualType ToElementType = importChecked(Err, T->getElementType()); | ||||||
1200 | Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr()); | ||||||
1201 | SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange()); | ||||||
1202 | if (Err) | ||||||
1203 | return std::move(Err); | ||||||
1204 | return Importer.getToContext().getVariableArrayType( | ||||||
1205 | ToElementType, ToSizeExpr, T->getSizeModifier(), | ||||||
1206 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); | ||||||
1207 | } | ||||||
1208 | |||||||
1209 | ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( | ||||||
1210 | const DependentSizedArrayType *T) { | ||||||
1211 | Error Err = Error::success(); | ||||||
1212 | QualType ToElementType = importChecked(Err, T->getElementType()); | ||||||
1213 | Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr()); | ||||||
1214 | SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange()); | ||||||
1215 | if (Err) | ||||||
1216 | return std::move(Err); | ||||||
1217 | // SizeExpr may be null if size is not specified directly. | ||||||
1218 | // For example, 'int a[]'. | ||||||
1219 | |||||||
1220 | return Importer.getToContext().getDependentSizedArrayType( | ||||||
1221 | ToElementType, ToSizeExpr, T->getSizeModifier(), | ||||||
1222 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); | ||||||
1223 | } | ||||||
1224 | |||||||
1225 | ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) { | ||||||
1226 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | ||||||
1227 | if (!ToElementTypeOrErr) | ||||||
1228 | return ToElementTypeOrErr.takeError(); | ||||||
1229 | |||||||
1230 | return Importer.getToContext().getVectorType(*ToElementTypeOrErr, | ||||||
1231 | T->getNumElements(), | ||||||
1232 | T->getVectorKind()); | ||||||
1233 | } | ||||||
1234 | |||||||
1235 | ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { | ||||||
1236 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | ||||||
1237 | if (!ToElementTypeOrErr) | ||||||
1238 | return ToElementTypeOrErr.takeError(); | ||||||
1239 | |||||||
1240 | return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr, | ||||||
1241 | T->getNumElements()); | ||||||
1242 | } | ||||||
1243 | |||||||
1244 | ExpectedType | ||||||
1245 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { | ||||||
1246 | // FIXME: What happens if we're importing a function without a prototype | ||||||
1247 | // into C++? Should we make it variadic? | ||||||
1248 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); | ||||||
1249 | if (!ToReturnTypeOrErr) | ||||||
1250 | return ToReturnTypeOrErr.takeError(); | ||||||
1251 | |||||||
1252 | return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr, | ||||||
1253 | T->getExtInfo()); | ||||||
1254 | } | ||||||
1255 | |||||||
1256 | ExpectedType | ||||||
1257 | ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { | ||||||
1258 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); | ||||||
1259 | if (!ToReturnTypeOrErr) | ||||||
1260 | return ToReturnTypeOrErr.takeError(); | ||||||
1261 | |||||||
1262 | // Import argument types | ||||||
1263 | SmallVector<QualType, 4> ArgTypes; | ||||||
1264 | for (const auto &A : T->param_types()) { | ||||||
1265 | ExpectedType TyOrErr = import(A); | ||||||
1266 | if (!TyOrErr) | ||||||
1267 | return TyOrErr.takeError(); | ||||||
1268 | ArgTypes.push_back(*TyOrErr); | ||||||
1269 | } | ||||||
1270 | |||||||
1271 | // Import exception types | ||||||
1272 | SmallVector<QualType, 4> ExceptionTypes; | ||||||
1273 | for (const auto &E : T->exceptions()) { | ||||||
1274 | ExpectedType TyOrErr = import(E); | ||||||
1275 | if (!TyOrErr) | ||||||
1276 | return TyOrErr.takeError(); | ||||||
1277 | ExceptionTypes.push_back(*TyOrErr); | ||||||
1278 | } | ||||||
1279 | |||||||
1280 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); | ||||||
1281 | Error Err = Error::success(); | ||||||
1282 | FunctionProtoType::ExtProtoInfo ToEPI; | ||||||
1283 | ToEPI.ExtInfo = FromEPI.ExtInfo; | ||||||
1284 | ToEPI.Variadic = FromEPI.Variadic; | ||||||
1285 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; | ||||||
1286 | ToEPI.TypeQuals = FromEPI.TypeQuals; | ||||||
1287 | ToEPI.RefQualifier = FromEPI.RefQualifier; | ||||||
1288 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; | ||||||
1289 | ToEPI.ExceptionSpec.NoexceptExpr = | ||||||
1290 | importChecked(Err, FromEPI.ExceptionSpec.NoexceptExpr); | ||||||
1291 | ToEPI.ExceptionSpec.SourceDecl = | ||||||
1292 | importChecked(Err, FromEPI.ExceptionSpec.SourceDecl); | ||||||
1293 | ToEPI.ExceptionSpec.SourceTemplate = | ||||||
1294 | importChecked(Err, FromEPI.ExceptionSpec.SourceTemplate); | ||||||
1295 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; | ||||||
1296 | |||||||
1297 | if (Err) | ||||||
1298 | return std::move(Err); | ||||||
1299 | |||||||
1300 | return Importer.getToContext().getFunctionType( | ||||||
1301 | *ToReturnTypeOrErr, ArgTypes, ToEPI); | ||||||
1302 | } | ||||||
1303 | |||||||
1304 | ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( | ||||||
1305 | const UnresolvedUsingType *T) { | ||||||
1306 | Error Err = Error::success(); | ||||||
1307 | auto ToD = importChecked(Err, T->getDecl()); | ||||||
1308 | auto ToPrevD = importChecked(Err, T->getDecl()->getPreviousDecl()); | ||||||
1309 | if (Err) | ||||||
1310 | return std::move(Err); | ||||||
1311 | |||||||
1312 | return Importer.getToContext().getTypeDeclType( | ||||||
1313 | ToD, cast_or_null<TypeDecl>(ToPrevD)); | ||||||
1314 | } | ||||||
1315 | |||||||
1316 | ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) { | ||||||
1317 | ExpectedType ToInnerTypeOrErr = import(T->getInnerType()); | ||||||
1318 | if (!ToInnerTypeOrErr) | ||||||
1319 | return ToInnerTypeOrErr.takeError(); | ||||||
1320 | |||||||
1321 | return Importer.getToContext().getParenType(*ToInnerTypeOrErr); | ||||||
1322 | } | ||||||
1323 | |||||||
1324 | ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { | ||||||
1325 | Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl()); | ||||||
1326 | if (!ToDeclOrErr) | ||||||
1327 | return ToDeclOrErr.takeError(); | ||||||
1328 | |||||||
1329 | return Importer.getToContext().getTypeDeclType(*ToDeclOrErr); | ||||||
1330 | } | ||||||
1331 | |||||||
1332 | ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { | ||||||
1333 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); | ||||||
1334 | if (!ToExprOrErr) | ||||||
1335 | return ToExprOrErr.takeError(); | ||||||
1336 | |||||||
1337 | return Importer.getToContext().getTypeOfExprType(*ToExprOrErr); | ||||||
1338 | } | ||||||
1339 | |||||||
1340 | ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { | ||||||
1341 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | ||||||
1342 | if (!ToUnderlyingTypeOrErr) | ||||||
1343 | return ToUnderlyingTypeOrErr.takeError(); | ||||||
1344 | |||||||
1345 | return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr); | ||||||
1346 | } | ||||||
1347 | |||||||
1348 | ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { | ||||||
1349 | // FIXME: Make sure that the "to" context supports C++0x! | ||||||
1350 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); | ||||||
1351 | if (!ToExprOrErr) | ||||||
1352 | return ToExprOrErr.takeError(); | ||||||
1353 | |||||||
1354 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | ||||||
1355 | if (!ToUnderlyingTypeOrErr) | ||||||
1356 | return ToUnderlyingTypeOrErr.takeError(); | ||||||
1357 | |||||||
1358 | return Importer.getToContext().getDecltypeType( | ||||||
1359 | *ToExprOrErr, *ToUnderlyingTypeOrErr); | ||||||
1360 | } | ||||||
1361 | |||||||
1362 | ExpectedType | ||||||
1363 | ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { | ||||||
1364 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); | ||||||
1365 | if (!ToBaseTypeOrErr) | ||||||
1366 | return ToBaseTypeOrErr.takeError(); | ||||||
1367 | |||||||
1368 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | ||||||
1369 | if (!ToUnderlyingTypeOrErr) | ||||||
1370 | return ToUnderlyingTypeOrErr.takeError(); | ||||||
1371 | |||||||
1372 | return Importer.getToContext().getUnaryTransformType( | ||||||
1373 | *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind()); | ||||||
1374 | } | ||||||
1375 | |||||||
1376 | ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) { | ||||||
1377 | // FIXME: Make sure that the "to" context supports C++11! | ||||||
1378 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); | ||||||
1379 | if (!ToDeducedTypeOrErr) | ||||||
1380 | return ToDeducedTypeOrErr.takeError(); | ||||||
1381 | |||||||
1382 | ExpectedDecl ToTypeConstraintConcept = import(T->getTypeConstraintConcept()); | ||||||
1383 | if (!ToTypeConstraintConcept) | ||||||
1384 | return ToTypeConstraintConcept.takeError(); | ||||||
1385 | |||||||
1386 | SmallVector<TemplateArgument, 2> ToTemplateArgs; | ||||||
1387 | ArrayRef<TemplateArgument> FromTemplateArgs = T->getTypeConstraintArguments(); | ||||||
1388 | if (Error Err = ImportTemplateArguments(FromTemplateArgs.data(), | ||||||
1389 | FromTemplateArgs.size(), | ||||||
1390 | ToTemplateArgs)) | ||||||
1391 | return std::move(Err); | ||||||
1392 | |||||||
1393 | return Importer.getToContext().getAutoType( | ||||||
1394 | *ToDeducedTypeOrErr, T->getKeyword(), /*IsDependent*/false, | ||||||
1395 | /*IsPack=*/false, cast_or_null<ConceptDecl>(*ToTypeConstraintConcept), | ||||||
1396 | ToTemplateArgs); | ||||||
1397 | } | ||||||
1398 | |||||||
1399 | ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType( | ||||||
1400 | const DeducedTemplateSpecializationType *T) { | ||||||
1401 | // FIXME: Make sure that the "to" context supports C++17! | ||||||
1402 | Expected<TemplateName> ToTemplateNameOrErr = import(T->getTemplateName()); | ||||||
1403 | if (!ToTemplateNameOrErr) | ||||||
1404 | return ToTemplateNameOrErr.takeError(); | ||||||
1405 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); | ||||||
1406 | if (!ToDeducedTypeOrErr) | ||||||
1407 | return ToDeducedTypeOrErr.takeError(); | ||||||
1408 | |||||||
1409 | return Importer.getToContext().getDeducedTemplateSpecializationType( | ||||||
1410 | *ToTemplateNameOrErr, *ToDeducedTypeOrErr, T->isDependentType()); | ||||||
1411 | } | ||||||
1412 | |||||||
1413 | ExpectedType ASTNodeImporter::VisitInjectedClassNameType( | ||||||
1414 | const InjectedClassNameType *T) { | ||||||
1415 | Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl()); | ||||||
1416 | if (!ToDeclOrErr) | ||||||
1417 | return ToDeclOrErr.takeError(); | ||||||
1418 | |||||||
1419 | ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType()); | ||||||
1420 | if (!ToInjTypeOrErr) | ||||||
1421 | return ToInjTypeOrErr.takeError(); | ||||||
1422 | |||||||
1423 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading | ||||||
1424 | // See comments in InjectedClassNameType definition for details | ||||||
1425 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); | ||||||
1426 | enum { | ||||||
1427 | TypeAlignmentInBits = 4, | ||||||
1428 | TypeAlignment = 1 << TypeAlignmentInBits | ||||||
1429 | }; | ||||||
1430 | |||||||
1431 | return QualType(new (Importer.getToContext(), TypeAlignment) | ||||||
1432 | InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0); | ||||||
1433 | } | ||||||
1434 | |||||||
1435 | ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) { | ||||||
1436 | Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl()); | ||||||
1437 | if (!ToDeclOrErr) | ||||||
1438 | return ToDeclOrErr.takeError(); | ||||||
1439 | |||||||
1440 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); | ||||||
1441 | } | ||||||
1442 | |||||||
1443 | ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) { | ||||||
1444 | Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl()); | ||||||
1445 | if (!ToDeclOrErr) | ||||||
1446 | return ToDeclOrErr.takeError(); | ||||||
1447 | |||||||
1448 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); | ||||||
1449 | } | ||||||
1450 | |||||||
1451 | ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { | ||||||
1452 | ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType()); | ||||||
1453 | if (!ToModifiedTypeOrErr) | ||||||
1454 | return ToModifiedTypeOrErr.takeError(); | ||||||
1455 | ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType()); | ||||||
1456 | if (!ToEquivalentTypeOrErr) | ||||||
1457 | return ToEquivalentTypeOrErr.takeError(); | ||||||
1458 | |||||||
1459 | return Importer.getToContext().getAttributedType(T->getAttrKind(), | ||||||
1460 | *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr); | ||||||
1461 | } | ||||||
1462 | |||||||
1463 | ExpectedType ASTNodeImporter::VisitTemplateTypeParmType( | ||||||
1464 | const TemplateTypeParmType *T) { | ||||||
1465 | Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl()); | ||||||
1466 | if (!ToDeclOrErr) | ||||||
1467 | return ToDeclOrErr.takeError(); | ||||||
1468 | |||||||
1469 | return Importer.getToContext().getTemplateTypeParmType( | ||||||
1470 | T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr); | ||||||
1471 | } | ||||||
1472 | |||||||
1473 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( | ||||||
1474 | const SubstTemplateTypeParmType *T) { | ||||||
1475 | ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); | ||||||
1476 | if (!ReplacedOrErr) | ||||||
1477 | return ReplacedOrErr.takeError(); | ||||||
1478 | const TemplateTypeParmType *Replaced = | ||||||
1479 | cast<TemplateTypeParmType>((*ReplacedOrErr).getTypePtr()); | ||||||
1480 | |||||||
1481 | ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); | ||||||
1482 | if (!ToReplacementTypeOrErr) | ||||||
1483 | return ToReplacementTypeOrErr.takeError(); | ||||||
1484 | |||||||
1485 | return Importer.getToContext().getSubstTemplateTypeParmType( | ||||||
1486 | Replaced, (*ToReplacementTypeOrErr).getCanonicalType()); | ||||||
1487 | } | ||||||
1488 | |||||||
1489 | ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( | ||||||
1490 | const TemplateSpecializationType *T) { | ||||||
1491 | auto ToTemplateOrErr = import(T->getTemplateName()); | ||||||
1492 | if (!ToTemplateOrErr) | ||||||
1493 | return ToTemplateOrErr.takeError(); | ||||||
1494 | |||||||
1495 | SmallVector<TemplateArgument, 2> ToTemplateArgs; | ||||||
1496 | if (Error Err = ImportTemplateArguments( | ||||||
1497 | T->getArgs(), T->getNumArgs(), ToTemplateArgs)) | ||||||
1498 | return std::move(Err); | ||||||
1499 | |||||||
1500 | QualType ToCanonType; | ||||||
1501 | if (!QualType(T, 0).isCanonical()) { | ||||||
1502 | QualType FromCanonType | ||||||
1503 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); | ||||||
1504 | if (ExpectedType TyOrErr = import(FromCanonType)) | ||||||
1505 | ToCanonType = *TyOrErr; | ||||||
1506 | else | ||||||
1507 | return TyOrErr.takeError(); | ||||||
1508 | } | ||||||
1509 | return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr, | ||||||
1510 | ToTemplateArgs, | ||||||
1511 | ToCanonType); | ||||||
1512 | } | ||||||
1513 | |||||||
1514 | ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { | ||||||
1515 | // Note: the qualifier in an ElaboratedType is optional. | ||||||
1516 | auto ToQualifierOrErr = import(T->getQualifier()); | ||||||
1517 | if (!ToQualifierOrErr) | ||||||
1518 | return ToQualifierOrErr.takeError(); | ||||||
1519 | |||||||
1520 | ExpectedType ToNamedTypeOrErr = import(T->getNamedType()); | ||||||
1521 | if (!ToNamedTypeOrErr) | ||||||
1522 | return ToNamedTypeOrErr.takeError(); | ||||||
1523 | |||||||
1524 | Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl()); | ||||||
1525 | if (!ToOwnedTagDeclOrErr) | ||||||
1526 | return ToOwnedTagDeclOrErr.takeError(); | ||||||
1527 | |||||||
1528 | return Importer.getToContext().getElaboratedType(T->getKeyword(), | ||||||
1529 | *ToQualifierOrErr, | ||||||
1530 | *ToNamedTypeOrErr, | ||||||
1531 | *ToOwnedTagDeclOrErr); | ||||||
1532 | } | ||||||
1533 | |||||||
1534 | ExpectedType | ||||||
1535 | ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { | ||||||
1536 | ExpectedType ToPatternOrErr = import(T->getPattern()); | ||||||
1537 | if (!ToPatternOrErr) | ||||||
1538 | return ToPatternOrErr.takeError(); | ||||||
1539 | |||||||
1540 | return Importer.getToContext().getPackExpansionType(*ToPatternOrErr, | ||||||
1541 | T->getNumExpansions(), | ||||||
1542 | /*ExpactPack=*/false); | ||||||
1543 | } | ||||||
1544 | |||||||
1545 | ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType( | ||||||
1546 | const DependentTemplateSpecializationType *T) { | ||||||
1547 | auto ToQualifierOrErr = import(T->getQualifier()); | ||||||
1548 | if (!ToQualifierOrErr) | ||||||
1549 | return ToQualifierOrErr.takeError(); | ||||||
1550 | |||||||
1551 | IdentifierInfo *ToName = Importer.Import(T->getIdentifier()); | ||||||
1552 | |||||||
1553 | SmallVector<TemplateArgument, 2> ToPack; | ||||||
1554 | ToPack.reserve(T->getNumArgs()); | ||||||
1555 | if (Error Err = ImportTemplateArguments( | ||||||
1556 | T->getArgs(), T->getNumArgs(), ToPack)) | ||||||
1557 | return std::move(Err); | ||||||
1558 | |||||||
1559 | return Importer.getToContext().getDependentTemplateSpecializationType( | ||||||
1560 | T->getKeyword(), *ToQualifierOrErr, ToName, ToPack); | ||||||
1561 | } | ||||||
1562 | |||||||
1563 | ExpectedType | ||||||
1564 | ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { | ||||||
1565 | auto ToQualifierOrErr = import(T->getQualifier()); | ||||||
1566 | if (!ToQualifierOrErr) | ||||||
1567 | return ToQualifierOrErr.takeError(); | ||||||
1568 | |||||||
1569 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); | ||||||
1570 | |||||||
1571 | QualType Canon; | ||||||
1572 | if (T != T->getCanonicalTypeInternal().getTypePtr()) { | ||||||
1573 | if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal())) | ||||||
1574 | Canon = (*TyOrErr).getCanonicalType(); | ||||||
1575 | else | ||||||
1576 | return TyOrErr.takeError(); | ||||||
1577 | } | ||||||
1578 | |||||||
1579 | return Importer.getToContext().getDependentNameType(T->getKeyword(), | ||||||
1580 | *ToQualifierOrErr, | ||||||
1581 | Name, Canon); | ||||||
1582 | } | ||||||
1583 | |||||||
1584 | ExpectedType | ||||||
1585 | ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { | ||||||
1586 | Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl()); | ||||||
1587 | if (!ToDeclOrErr) | ||||||
1588 | return ToDeclOrErr.takeError(); | ||||||
1589 | |||||||
1590 | return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr); | ||||||
1591 | } | ||||||
1592 | |||||||
1593 | ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { | ||||||
1594 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); | ||||||
1595 | if (!ToBaseTypeOrErr) | ||||||
1596 | return ToBaseTypeOrErr.takeError(); | ||||||
1597 | |||||||
1598 | SmallVector<QualType, 4> TypeArgs; | ||||||
1599 | for (auto TypeArg : T->getTypeArgsAsWritten()) { | ||||||
1600 | if (ExpectedType TyOrErr = import(TypeArg)) | ||||||
1601 | TypeArgs.push_back(*TyOrErr); | ||||||
1602 | else | ||||||
1603 | return TyOrErr.takeError(); | ||||||
1604 | } | ||||||
1605 | |||||||
1606 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | ||||||
1607 | for (auto *P : T->quals()) { | ||||||
1608 | if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P)) | ||||||
1609 | Protocols.push_back(*ProtocolOrErr); | ||||||
1610 | else | ||||||
1611 | return ProtocolOrErr.takeError(); | ||||||
1612 | |||||||
1613 | } | ||||||
1614 | |||||||
1615 | return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs, | ||||||
1616 | Protocols, | ||||||
1617 | T->isKindOfTypeAsWritten()); | ||||||
1618 | } | ||||||
1619 | |||||||
1620 | ExpectedType | ||||||
1621 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { | ||||||
1622 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | ||||||
1623 | if (!ToPointeeTypeOrErr) | ||||||
1624 | return ToPointeeTypeOrErr.takeError(); | ||||||
1625 | |||||||
1626 | return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr); | ||||||
1627 | } | ||||||
1628 | |||||||
1629 | //---------------------------------------------------------------------------- | ||||||
1630 | // Import Declarations | ||||||
1631 | //---------------------------------------------------------------------------- | ||||||
1632 | Error ASTNodeImporter::ImportDeclParts( | ||||||
1633 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, | ||||||
1634 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) { | ||||||
1635 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. | ||||||
1636 | // example: int struct_in_proto(struct data_t{int a;int b;} *d); | ||||||
1637 | // FIXME: We could support these constructs by importing a different type of | ||||||
1638 | // this parameter and by importing the original type of the parameter only | ||||||
1639 | // after the FunctionDecl is created. See | ||||||
1640 | // VisitFunctionDecl::UsedDifferentProtoType. | ||||||
1641 | DeclContext *OrigDC = D->getDeclContext(); | ||||||
1642 | FunctionDecl *FunDecl; | ||||||
1643 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && | ||||||
1644 | FunDecl->hasBody()) { | ||||||
1645 | auto getLeafPointeeType = [](const Type *T) { | ||||||
1646 | while (T->isPointerType() || T->isArrayType()) { | ||||||
1647 | T = T->getPointeeOrArrayElementType(); | ||||||
1648 | } | ||||||
1649 | return T; | ||||||
1650 | }; | ||||||
1651 | for (const ParmVarDecl *P : FunDecl->parameters()) { | ||||||
1652 | const Type *LeafT = | ||||||
1653 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); | ||||||
1654 | auto *RT = dyn_cast<RecordType>(LeafT); | ||||||
1655 | if (RT && RT->getDecl() == D) { | ||||||
1656 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | ||||||
1657 | << D->getDeclKindName(); | ||||||
1658 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | ||||||
1659 | } | ||||||
1660 | } | ||||||
1661 | } | ||||||
1662 | |||||||
1663 | // Import the context of this declaration. | ||||||
1664 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | ||||||
1665 | return Err; | ||||||
1666 | |||||||
1667 | // Import the name of this declaration. | ||||||
1668 | if (Error Err = importInto(Name, D->getDeclName())) | ||||||
1669 | return Err; | ||||||
1670 | |||||||
1671 | // Import the location of this declaration. | ||||||
1672 | if (Error Err = importInto(Loc, D->getLocation())) | ||||||
1673 | return Err; | ||||||
1674 | |||||||
1675 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); | ||||||
1676 | if (ToD) | ||||||
1677 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD)) | ||||||
1678 | return Err; | ||||||
1679 | |||||||
1680 | return Error::success(); | ||||||
1681 | } | ||||||
1682 | |||||||
1683 | Error ASTNodeImporter::ImportDeclParts(NamedDecl *D, DeclarationName &Name, | ||||||
1684 | NamedDecl *&ToD, SourceLocation &Loc) { | ||||||
1685 | |||||||
1686 | // Import the name of this declaration. | ||||||
1687 | if (Error Err = importInto(Name, D->getDeclName())) | ||||||
1688 | return Err; | ||||||
1689 | |||||||
1690 | // Import the location of this declaration. | ||||||
1691 | if (Error Err = importInto(Loc, D->getLocation())) | ||||||
1692 | return Err; | ||||||
1693 | |||||||
1694 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); | ||||||
1695 | if (ToD
| ||||||
1696 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD)) | ||||||
1697 | return Err; | ||||||
1698 | |||||||
1699 | return Error::success(); | ||||||
1700 | } | ||||||
1701 | |||||||
1702 | Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { | ||||||
1703 | if (!FromD) | ||||||
1704 | return Error::success(); | ||||||
1705 | |||||||
1706 | if (!ToD) | ||||||
1707 | if (Error Err = importInto(ToD, FromD)) | ||||||
1708 | return Err; | ||||||
1709 | |||||||
1710 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { | ||||||
1711 | if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) { | ||||||
1712 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && | ||||||
1713 | !ToRecord->getDefinition()) { | ||||||
1714 | if (Error Err = ImportDefinition(FromRecord, ToRecord)) | ||||||
1715 | return Err; | ||||||
1716 | } | ||||||
1717 | } | ||||||
1718 | return Error::success(); | ||||||
1719 | } | ||||||
1720 | |||||||
1721 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { | ||||||
1722 | if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) { | ||||||
1723 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { | ||||||
1724 | if (Error Err = ImportDefinition(FromEnum, ToEnum)) | ||||||
1725 | return Err; | ||||||
1726 | } | ||||||
1727 | } | ||||||
1728 | return Error::success(); | ||||||
1729 | } | ||||||
1730 | |||||||
1731 | return Error::success(); | ||||||
1732 | } | ||||||
1733 | |||||||
1734 | Error | ||||||
1735 | ASTNodeImporter::ImportDeclarationNameLoc( | ||||||
1736 | const DeclarationNameInfo &From, DeclarationNameInfo& To) { | ||||||
1737 | // NOTE: To.Name and To.Loc are already imported. | ||||||
1738 | // We only have to import To.LocInfo. | ||||||
1739 | switch (To.getName().getNameKind()) { | ||||||
1740 | case DeclarationName::Identifier: | ||||||
1741 | case DeclarationName::ObjCZeroArgSelector: | ||||||
1742 | case DeclarationName::ObjCOneArgSelector: | ||||||
1743 | case DeclarationName::ObjCMultiArgSelector: | ||||||
1744 | case DeclarationName::CXXUsingDirective: | ||||||
1745 | case DeclarationName::CXXDeductionGuideName: | ||||||
1746 | return Error::success(); | ||||||
1747 | |||||||
1748 | case DeclarationName::CXXOperatorName: { | ||||||
1749 | if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange())) | ||||||
1750 | To.setCXXOperatorNameRange(*ToRangeOrErr); | ||||||
1751 | else | ||||||
1752 | return ToRangeOrErr.takeError(); | ||||||
1753 | return Error::success(); | ||||||
1754 | } | ||||||
1755 | case DeclarationName::CXXLiteralOperatorName: { | ||||||
1756 | if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc())) | ||||||
1757 | To.setCXXLiteralOperatorNameLoc(*LocOrErr); | ||||||
1758 | else | ||||||
1759 | return LocOrErr.takeError(); | ||||||
1760 | return Error::success(); | ||||||
1761 | } | ||||||
1762 | case DeclarationName::CXXConstructorName: | ||||||
1763 | case DeclarationName::CXXDestructorName: | ||||||
1764 | case DeclarationName::CXXConversionFunctionName: { | ||||||
1765 | if (auto ToTInfoOrErr = import(From.getNamedTypeInfo())) | ||||||
1766 | To.setNamedTypeInfo(*ToTInfoOrErr); | ||||||
1767 | else | ||||||
1768 | return ToTInfoOrErr.takeError(); | ||||||
1769 | return Error::success(); | ||||||
1770 | } | ||||||
1771 | } | ||||||
1772 | llvm_unreachable("Unknown name kind.")::llvm::llvm_unreachable_internal("Unknown name kind.", "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 1772); | ||||||
1773 | } | ||||||
1774 | |||||||
1775 | Error | ||||||
1776 | ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { | ||||||
1777 | if (Importer.isMinimalImport() && !ForceImport) { | ||||||
1778 | auto ToDCOrErr = Importer.ImportContext(FromDC); | ||||||
1779 | return ToDCOrErr.takeError(); | ||||||
1780 | } | ||||||
1781 | |||||||
1782 | // We use strict error handling in case of records and enums, but not | ||||||
1783 | // with e.g. namespaces. | ||||||
1784 | // | ||||||
1785 | // FIXME Clients of the ASTImporter should be able to choose an | ||||||
1786 | // appropriate error handling strategy for their needs. For instance, | ||||||
1787 | // they may not want to mark an entire namespace as erroneous merely | ||||||
1788 | // because there is an ODR error with two typedefs. As another example, | ||||||
1789 | // the client may allow EnumConstantDecls with same names but with | ||||||
1790 | // different values in two distinct translation units. | ||||||
1791 | bool AccumulateChildErrors = isa<TagDecl>(FromDC); | ||||||
1792 | |||||||
1793 | Error ChildErrors = Error::success(); | ||||||
1794 | for (auto *From : FromDC->decls()) { | ||||||
1795 | ExpectedDecl ImportedOrErr = import(From); | ||||||
1796 | |||||||
1797 | // If we are in the process of ImportDefinition(...) for a RecordDecl we | ||||||
1798 | // want to make sure that we are also completing each FieldDecl. There | ||||||
1799 | // are currently cases where this does not happen and this is correctness | ||||||
1800 | // fix since operations such as code generation will expect this to be so. | ||||||
1801 | if (ImportedOrErr) { | ||||||
1802 | FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From); | ||||||
1803 | Decl *ImportedDecl = *ImportedOrErr; | ||||||
1804 | FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl); | ||||||
1805 | if (FieldFrom && FieldTo) { | ||||||
1806 | RecordDecl *FromRecordDecl = nullptr; | ||||||
1807 | RecordDecl *ToRecordDecl = nullptr; | ||||||
1808 | // If we have a field that is an ArrayType we need to check if the array | ||||||
1809 | // element is a RecordDecl and if so we need to import the defintion. | ||||||
1810 | if (FieldFrom->getType()->isArrayType()) { | ||||||
1811 | // getBaseElementTypeUnsafe(...) handles multi-dimensonal arrays for us. | ||||||
1812 | FromRecordDecl = FieldFrom->getType()->getBaseElementTypeUnsafe()->getAsRecordDecl(); | ||||||
1813 | ToRecordDecl = FieldTo->getType()->getBaseElementTypeUnsafe()->getAsRecordDecl(); | ||||||
1814 | } | ||||||
1815 | |||||||
1816 | if (!FromRecordDecl || !ToRecordDecl) { | ||||||
1817 | const RecordType *RecordFrom = | ||||||
1818 | FieldFrom->getType()->getAs<RecordType>(); | ||||||
1819 | const RecordType *RecordTo = FieldTo->getType()->getAs<RecordType>(); | ||||||
1820 | |||||||
1821 | if (RecordFrom && RecordTo) { | ||||||
1822 | FromRecordDecl = RecordFrom->getDecl(); | ||||||
1823 | ToRecordDecl = RecordTo->getDecl(); | ||||||
1824 | } | ||||||
1825 | } | ||||||
1826 | |||||||
1827 | if (FromRecordDecl && ToRecordDecl) { | ||||||
1828 | if (FromRecordDecl->isCompleteDefinition() && | ||||||
1829 | !ToRecordDecl->isCompleteDefinition()) { | ||||||
1830 | Error Err = ImportDefinition(FromRecordDecl, ToRecordDecl); | ||||||
1831 | |||||||
1832 | if (Err && AccumulateChildErrors) | ||||||
1833 | ChildErrors = joinErrors(std::move(ChildErrors), std::move(Err)); | ||||||
1834 | else | ||||||
1835 | consumeError(std::move(Err)); | ||||||
1836 | } | ||||||
1837 | } | ||||||
1838 | } | ||||||
1839 | } else { | ||||||
1840 | if (AccumulateChildErrors) | ||||||
1841 | ChildErrors = | ||||||
1842 | joinErrors(std::move(ChildErrors), ImportedOrErr.takeError()); | ||||||
1843 | else | ||||||
1844 | consumeError(ImportedOrErr.takeError()); | ||||||
1845 | } | ||||||
1846 | } | ||||||
1847 | |||||||
1848 | // We reorder declarations in RecordDecls because they may have another order | ||||||
1849 | // in the "to" context than they have in the "from" context. This may happen | ||||||
1850 | // e.g when we import a class like this: | ||||||
1851 | // struct declToImport { | ||||||
1852 | // int a = c + b; | ||||||
1853 | // int b = 1; | ||||||
1854 | // int c = 2; | ||||||
1855 | // }; | ||||||
1856 | // During the import of `a` we import first the dependencies in sequence, | ||||||
1857 | // thus the order would be `c`, `b`, `a`. We will get the normal order by | ||||||
1858 | // first removing the already imported members and then adding them in the | ||||||
1859 | // order as they apper in the "from" context. | ||||||
1860 | // | ||||||
1861 | // Keeping field order is vital because it determines structure layout. | ||||||
1862 | // | ||||||
1863 | // Here and below, we cannot call field_begin() method and its callers on | ||||||
1864 | // ToDC if it has an external storage. Calling field_begin() will | ||||||
1865 | // automatically load all the fields by calling | ||||||
1866 | // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would | ||||||
1867 | // call ASTImporter::Import(). This is because the ExternalASTSource | ||||||
1868 | // interface in LLDB is implemented by the means of the ASTImporter. However, | ||||||
1869 | // calling an import at this point would result in an uncontrolled import, we | ||||||
1870 | // must avoid that. | ||||||
1871 | const auto *FromRD = dyn_cast<RecordDecl>(FromDC); | ||||||
1872 | if (!FromRD) | ||||||
1873 | return ChildErrors; | ||||||
1874 | |||||||
1875 | auto ToDCOrErr = Importer.ImportContext(FromDC); | ||||||
1876 | if (!ToDCOrErr) { | ||||||
1877 | consumeError(std::move(ChildErrors)); | ||||||
1878 | return ToDCOrErr.takeError(); | ||||||
1879 | } | ||||||
1880 | |||||||
1881 | DeclContext *ToDC = *ToDCOrErr; | ||||||
1882 | // Remove all declarations, which may be in wrong order in the | ||||||
1883 | // lexical DeclContext and then add them in the proper order. | ||||||
1884 | for (auto *D : FromRD->decls()) { | ||||||
1885 | if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<FriendDecl>(D)) { | ||||||
1886 | 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\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 1886, __extension__ __PRETTY_FUNCTION__)); | ||||||
1887 | Decl *ToD = Importer.GetAlreadyImportedOrNull(D); | ||||||
1888 | // Remove only the decls which we successfully imported. | ||||||
1889 | if (ToD) { | ||||||
1890 | 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)" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 1890, __extension__ __PRETTY_FUNCTION__)); | ||||||
1891 | // Remove the decl from its wrong place in the linked list. | ||||||
1892 | ToDC->removeDecl(ToD); | ||||||
1893 | // Add the decl to the end of the linked list. | ||||||
1894 | // This time it will be at the proper place because the enclosing for | ||||||
1895 | // loop iterates in the original (good) order of the decls. | ||||||
1896 | ToDC->addDeclInternal(ToD); | ||||||
1897 | } | ||||||
1898 | } | ||||||
1899 | } | ||||||
1900 | |||||||
1901 | return ChildErrors; | ||||||
1902 | } | ||||||
1903 | |||||||
1904 | Error ASTNodeImporter::ImportDeclContext( | ||||||
1905 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { | ||||||
1906 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); | ||||||
1907 | if (!ToDCOrErr) | ||||||
1908 | return ToDCOrErr.takeError(); | ||||||
1909 | ToDC = *ToDCOrErr; | ||||||
1910 | |||||||
1911 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { | ||||||
1912 | auto ToLexicalDCOrErr = Importer.ImportContext( | ||||||
1913 | FromD->getLexicalDeclContext()); | ||||||
1914 | if (!ToLexicalDCOrErr) | ||||||
1915 | return ToLexicalDCOrErr.takeError(); | ||||||
1916 | ToLexicalDC = *ToLexicalDCOrErr; | ||||||
1917 | } else | ||||||
1918 | ToLexicalDC = ToDC; | ||||||
1919 | |||||||
1920 | return Error::success(); | ||||||
1921 | } | ||||||
1922 | |||||||
1923 | Error ASTNodeImporter::ImportImplicitMethods( | ||||||
1924 | const CXXRecordDecl *From, CXXRecordDecl *To) { | ||||||
1925 | 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\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 1926, __extension__ __PRETTY_FUNCTION__)) | ||||||
1926 | "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\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 1926, __extension__ __PRETTY_FUNCTION__)); | ||||||
1927 | |||||||
1928 | for (CXXMethodDecl *FromM : From->methods()) | ||||||
1929 | if (FromM->isImplicit()) { | ||||||
1930 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); | ||||||
1931 | if (!ToMOrErr) | ||||||
1932 | return ToMOrErr.takeError(); | ||||||
1933 | } | ||||||
1934 | |||||||
1935 | return Error::success(); | ||||||
1936 | } | ||||||
1937 | |||||||
1938 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, | ||||||
1939 | ASTImporter &Importer) { | ||||||
1940 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { | ||||||
1941 | if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef)) | ||||||
1942 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); | ||||||
1943 | else | ||||||
1944 | return ToTypedefOrErr.takeError(); | ||||||
1945 | } | ||||||
1946 | return Error::success(); | ||||||
1947 | } | ||||||
1948 | |||||||
1949 | Error ASTNodeImporter::ImportDefinition( | ||||||
1950 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { | ||||||
1951 | auto DefinitionCompleter = [To]() { | ||||||
1952 | // There are cases in LLDB when we first import a class without its | ||||||
1953 | // members. The class will have DefinitionData, but no members. Then, | ||||||
1954 | // importDefinition is called from LLDB, which tries to get the members, so | ||||||
1955 | // when we get here, the class already has the DefinitionData set, so we | ||||||
1956 | // must unset the CompleteDefinition here to be able to complete again the | ||||||
1957 | // definition. | ||||||
1958 | To->setCompleteDefinition(false); | ||||||
1959 | To->completeDefinition(); | ||||||
1960 | }; | ||||||
1961 | |||||||
1962 | if (To->getDefinition() || To->isBeingDefined()) { | ||||||
1963 | if (Kind == IDK_Everything || | ||||||
1964 | // In case of lambdas, the class already has a definition ptr set, but | ||||||
1965 | // the contained decls are not imported yet. Also, isBeingDefined was | ||||||
1966 | // set in CXXRecordDecl::CreateLambda. We must import the contained | ||||||
1967 | // decls here and finish the definition. | ||||||
1968 | (To->isLambda() && shouldForceImportDeclContext(Kind))) { | ||||||
1969 | if (To->isLambda()) { | ||||||
1970 | auto *FromCXXRD = cast<CXXRecordDecl>(From); | ||||||
1971 | SmallVector<LambdaCapture, 8> ToCaptures; | ||||||
1972 | ToCaptures.reserve(FromCXXRD->capture_size()); | ||||||
1973 | for (const auto &FromCapture : FromCXXRD->captures()) { | ||||||
1974 | if (auto ToCaptureOrErr = import(FromCapture)) | ||||||
1975 | ToCaptures.push_back(*ToCaptureOrErr); | ||||||
1976 | else | ||||||
1977 | return ToCaptureOrErr.takeError(); | ||||||
1978 | } | ||||||
1979 | cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(), | ||||||
1980 | ToCaptures); | ||||||
1981 | } | ||||||
1982 | |||||||
1983 | Error Result = ImportDeclContext(From, /*ForceImport=*/true); | ||||||
1984 | // Finish the definition of the lambda, set isBeingDefined to false. | ||||||
1985 | if (To->isLambda()) | ||||||
1986 | DefinitionCompleter(); | ||||||
1987 | return Result; | ||||||
1988 | } | ||||||
1989 | |||||||
1990 | return Error::success(); | ||||||
1991 | } | ||||||
1992 | |||||||
1993 | To->startDefinition(); | ||||||
1994 | // Complete the definition even if error is returned. | ||||||
1995 | // The RecordDecl may be already part of the AST so it is better to | ||||||
1996 | // have it in complete state even if something is wrong with it. | ||||||
1997 | auto DefinitionCompleterScopeExit = | ||||||
1998 | llvm::make_scope_exit(DefinitionCompleter); | ||||||
1999 | |||||||
2000 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) | ||||||
2001 | return Err; | ||||||
2002 | |||||||
2003 | // Add base classes. | ||||||
2004 | auto *ToCXX = dyn_cast<CXXRecordDecl>(To); | ||||||
2005 | auto *FromCXX = dyn_cast<CXXRecordDecl>(From); | ||||||
2006 | if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) { | ||||||
2007 | |||||||
2008 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); | ||||||
2009 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); | ||||||
2010 | |||||||
2011 | #define FIELD(Name, Width, Merge) \ | ||||||
2012 | ToData.Name = FromData.Name; | ||||||
2013 | #include "clang/AST/CXXRecordDeclDefinitionBits.def" | ||||||
2014 | |||||||
2015 | // Copy over the data stored in RecordDeclBits | ||||||
2016 | ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions()); | ||||||
2017 | |||||||
2018 | SmallVector<CXXBaseSpecifier *, 4> Bases; | ||||||
2019 | for (const auto &Base1 : FromCXX->bases()) { | ||||||
2020 | ExpectedType TyOrErr = import(Base1.getType()); | ||||||
2021 | if (!TyOrErr) | ||||||
2022 | return TyOrErr.takeError(); | ||||||
2023 | |||||||
2024 | SourceLocation EllipsisLoc; | ||||||
2025 | if (Base1.isPackExpansion()) { | ||||||
2026 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) | ||||||
2027 | EllipsisLoc = *LocOrErr; | ||||||
2028 | else | ||||||
2029 | return LocOrErr.takeError(); | ||||||
2030 | } | ||||||
2031 | |||||||
2032 | // Ensure that we have a definition for the base. | ||||||
2033 | if (Error Err = | ||||||
2034 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) | ||||||
2035 | return Err; | ||||||
2036 | |||||||
2037 | auto RangeOrErr = import(Base1.getSourceRange()); | ||||||
2038 | if (!RangeOrErr) | ||||||
2039 | return RangeOrErr.takeError(); | ||||||
2040 | |||||||
2041 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); | ||||||
2042 | if (!TSIOrErr) | ||||||
2043 | return TSIOrErr.takeError(); | ||||||
2044 | |||||||
2045 | Bases.push_back( | ||||||
2046 | new (Importer.getToContext()) CXXBaseSpecifier( | ||||||
2047 | *RangeOrErr, | ||||||
2048 | Base1.isVirtual(), | ||||||
2049 | Base1.isBaseOfClass(), | ||||||
2050 | Base1.getAccessSpecifierAsWritten(), | ||||||
2051 | *TSIOrErr, | ||||||
2052 | EllipsisLoc)); | ||||||
2053 | } | ||||||
2054 | if (!Bases.empty()) | ||||||
2055 | ToCXX->setBases(Bases.data(), Bases.size()); | ||||||
2056 | } | ||||||
2057 | |||||||
2058 | if (shouldForceImportDeclContext(Kind)) | ||||||
2059 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | ||||||
2060 | return Err; | ||||||
2061 | |||||||
2062 | return Error::success(); | ||||||
2063 | } | ||||||
2064 | |||||||
2065 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { | ||||||
2066 | if (To->getAnyInitializer()) | ||||||
2067 | return Error::success(); | ||||||
2068 | |||||||
2069 | Expr *FromInit = From->getInit(); | ||||||
2070 | if (!FromInit) | ||||||
2071 | return Error::success(); | ||||||
2072 | |||||||
2073 | ExpectedExpr ToInitOrErr = import(FromInit); | ||||||
2074 | if (!ToInitOrErr) | ||||||
2075 | return ToInitOrErr.takeError(); | ||||||
2076 | |||||||
2077 | To->setInit(*ToInitOrErr); | ||||||
2078 | if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) { | ||||||
2079 | EvaluatedStmt *ToEval = To->ensureEvaluatedStmt(); | ||||||
2080 | ToEval->HasConstantInitialization = FromEval->HasConstantInitialization; | ||||||
2081 | ToEval->HasConstantDestruction = FromEval->HasConstantDestruction; | ||||||
2082 | // FIXME: Also import the initializer value. | ||||||
2083 | } | ||||||
2084 | |||||||
2085 | // FIXME: Other bits to merge? | ||||||
2086 | return Error::success(); | ||||||
2087 | } | ||||||
2088 | |||||||
2089 | Error ASTNodeImporter::ImportDefinition( | ||||||
2090 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { | ||||||
2091 | if (To->getDefinition() || To->isBeingDefined()) { | ||||||
2092 | if (Kind == IDK_Everything) | ||||||
2093 | return ImportDeclContext(From, /*ForceImport=*/true); | ||||||
2094 | return Error::success(); | ||||||
2095 | } | ||||||
2096 | |||||||
2097 | To->startDefinition(); | ||||||
2098 | |||||||
2099 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) | ||||||
2100 | return Err; | ||||||
2101 | |||||||
2102 | ExpectedType ToTypeOrErr = | ||||||
2103 | import(Importer.getFromContext().getTypeDeclType(From)); | ||||||
2104 | if (!ToTypeOrErr) | ||||||
2105 | return ToTypeOrErr.takeError(); | ||||||
2106 | |||||||
2107 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); | ||||||
2108 | if (!ToPromotionTypeOrErr) | ||||||
2109 | return ToPromotionTypeOrErr.takeError(); | ||||||
2110 | |||||||
2111 | if (shouldForceImportDeclContext(Kind)) | ||||||
2112 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | ||||||
2113 | return Err; | ||||||
2114 | |||||||
2115 | // FIXME: we might need to merge the number of positive or negative bits | ||||||
2116 | // if the enumerator lists don't match. | ||||||
2117 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, | ||||||
2118 | From->getNumPositiveBits(), | ||||||
2119 | From->getNumNegativeBits()); | ||||||
2120 | return Error::success(); | ||||||
2121 | } | ||||||
2122 | |||||||
2123 | Error ASTNodeImporter::ImportTemplateArguments( | ||||||
2124 | const TemplateArgument *FromArgs, unsigned NumFromArgs, | ||||||
2125 | SmallVectorImpl<TemplateArgument> &ToArgs) { | ||||||
2126 | for (unsigned I = 0; I != NumFromArgs; ++I) { | ||||||
2127 | if (auto ToOrErr = import(FromArgs[I])) | ||||||
2128 | ToArgs.push_back(*ToOrErr); | ||||||
2129 | else | ||||||
2130 | return ToOrErr.takeError(); | ||||||
2131 | } | ||||||
2132 | |||||||
2133 | return Error::success(); | ||||||
2134 | } | ||||||
2135 | |||||||
2136 | // FIXME: Do not forget to remove this and use only 'import'. | ||||||
2137 | Expected<TemplateArgument> | ||||||
2138 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { | ||||||
2139 | return import(From); | ||||||
2140 | } | ||||||
2141 | |||||||
2142 | template <typename InContainerTy> | ||||||
2143 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( | ||||||
2144 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { | ||||||
2145 | for (const auto &FromLoc : Container) { | ||||||
2146 | if (auto ToLocOrErr = import(FromLoc)) | ||||||
2147 | ToTAInfo.addArgument(*ToLocOrErr); | ||||||
2148 | else | ||||||
2149 | return ToLocOrErr.takeError(); | ||||||
2150 | } | ||||||
2151 | return Error::success(); | ||||||
2152 | } | ||||||
2153 | |||||||
2154 | static StructuralEquivalenceKind | ||||||
2155 | getStructuralEquivalenceKind(const ASTImporter &Importer) { | ||||||
2156 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal | ||||||
2157 | : StructuralEquivalenceKind::Default; | ||||||
2158 | } | ||||||
2159 | |||||||
2160 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { | ||||||
2161 | StructuralEquivalenceContext Ctx( | ||||||
2162 | Importer.getFromContext(), Importer.getToContext(), | ||||||
2163 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | ||||||
2164 | false, Complain); | ||||||
2165 | return Ctx.IsEquivalent(From, To); | ||||||
2166 | } | ||||||
2167 | |||||||
2168 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, | ||||||
2169 | RecordDecl *ToRecord, bool Complain) { | ||||||
2170 | // Eliminate a potential failure point where we attempt to re-import | ||||||
2171 | // something we're trying to import while completing ToRecord. | ||||||
2172 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); | ||||||
2173 | if (ToOrigin) { | ||||||
2174 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); | ||||||
2175 | if (ToOriginRecord) | ||||||
2176 | ToRecord = ToOriginRecord; | ||||||
2177 | } | ||||||
2178 | |||||||
2179 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | ||||||
2180 | ToRecord->getASTContext(), | ||||||
2181 | Importer.getNonEquivalentDecls(), | ||||||
2182 | getStructuralEquivalenceKind(Importer), | ||||||
2183 | false, Complain); | ||||||
2184 | return Ctx.IsEquivalent(FromRecord, ToRecord); | ||||||
2185 | } | ||||||
2186 | |||||||
2187 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, | ||||||
2188 | bool Complain) { | ||||||
2189 | StructuralEquivalenceContext Ctx( | ||||||
2190 | Importer.getFromContext(), Importer.getToContext(), | ||||||
2191 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | ||||||
2192 | false, Complain); | ||||||
2193 | return Ctx.IsEquivalent(FromVar, ToVar); | ||||||
2194 | } | ||||||
2195 | |||||||
2196 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { | ||||||
2197 | // Eliminate a potential failure point where we attempt to re-import | ||||||
2198 | // something we're trying to import while completing ToEnum. | ||||||
2199 | if (Decl *ToOrigin = Importer.GetOriginalDecl(ToEnum)) | ||||||
2200 | if (auto *ToOriginEnum = dyn_cast<EnumDecl>(ToOrigin)) | ||||||
2201 | ToEnum = ToOriginEnum; | ||||||
2202 | |||||||
2203 | StructuralEquivalenceContext Ctx( | ||||||
2204 | Importer.getFromContext(), Importer.getToContext(), | ||||||
2205 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); | ||||||
2206 | return Ctx.IsEquivalent(FromEnum, ToEnum); | ||||||
2207 | } | ||||||
2208 | |||||||
2209 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, | ||||||
2210 | FunctionTemplateDecl *To) { | ||||||
2211 | StructuralEquivalenceContext Ctx( | ||||||
2212 | Importer.getFromContext(), Importer.getToContext(), | ||||||
2213 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | ||||||
2214 | false, false); | ||||||
2215 | return Ctx.IsEquivalent(From, To); | ||||||
2216 | } | ||||||
2217 | |||||||
2218 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { | ||||||
2219 | StructuralEquivalenceContext Ctx( | ||||||
2220 | Importer.getFromContext(), Importer.getToContext(), | ||||||
2221 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | ||||||
2222 | false, false); | ||||||
2223 | return Ctx.IsEquivalent(From, To); | ||||||
2224 | } | ||||||
2225 | |||||||
2226 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, | ||||||
2227 | EnumConstantDecl *ToEC) { | ||||||
2228 | const llvm::APSInt &FromVal = FromEC->getInitVal(); | ||||||
2229 | const llvm::APSInt &ToVal = ToEC->getInitVal(); | ||||||
2230 | |||||||
2231 | return FromVal.isSigned() == ToVal.isSigned() && | ||||||
2232 | FromVal.getBitWidth() == ToVal.getBitWidth() && | ||||||
2233 | FromVal == ToVal; | ||||||
2234 | } | ||||||
2235 | |||||||
2236 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, | ||||||
2237 | ClassTemplateDecl *To) { | ||||||
2238 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | ||||||
2239 | Importer.getToContext(), | ||||||
2240 | Importer.getNonEquivalentDecls(), | ||||||
2241 | getStructuralEquivalenceKind(Importer)); | ||||||
2242 | return Ctx.IsEquivalent(From, To); | ||||||
2243 | } | ||||||
2244 | |||||||
2245 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, | ||||||
2246 | VarTemplateDecl *To) { | ||||||
2247 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | ||||||
2248 | Importer.getToContext(), | ||||||
2249 | Importer.getNonEquivalentDecls(), | ||||||
2250 | getStructuralEquivalenceKind(Importer)); | ||||||
2251 | return Ctx.IsEquivalent(From, To); | ||||||
2252 | } | ||||||
2253 | |||||||
2254 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { | ||||||
2255 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | ||||||
2256 | << D->getDeclKindName(); | ||||||
2257 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | ||||||
2258 | } | ||||||
2259 | |||||||
2260 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { | ||||||
2261 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | ||||||
2262 | << D->getDeclKindName(); | ||||||
2263 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | ||||||
2264 | } | ||||||
2265 | |||||||
2266 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { | ||||||
2267 | // Import the context of this declaration. | ||||||
2268 | DeclContext *DC, *LexicalDC; | ||||||
2269 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | ||||||
2270 | return std::move(Err); | ||||||
2271 | |||||||
2272 | // Import the location of this declaration. | ||||||
2273 | ExpectedSLoc LocOrErr = import(D->getLocation()); | ||||||
2274 | if (!LocOrErr) | ||||||
2275 | return LocOrErr.takeError(); | ||||||
2276 | |||||||
2277 | EmptyDecl *ToD; | ||||||
2278 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) | ||||||
2279 | return ToD; | ||||||
2280 | |||||||
2281 | ToD->setLexicalDeclContext(LexicalDC); | ||||||
2282 | LexicalDC->addDeclInternal(ToD); | ||||||
2283 | return ToD; | ||||||
2284 | } | ||||||
2285 | |||||||
2286 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { | ||||||
2287 | TranslationUnitDecl *ToD = | ||||||
2288 | Importer.getToContext().getTranslationUnitDecl(); | ||||||
2289 | |||||||
2290 | Importer.MapImported(D, ToD); | ||||||
2291 | |||||||
2292 | return ToD; | ||||||
2293 | } | ||||||
2294 | |||||||
2295 | ExpectedDecl ASTNodeImporter::VisitBindingDecl(BindingDecl *D) { | ||||||
2296 | DeclContext *DC, *LexicalDC; | ||||||
2297 | DeclarationName Name; | ||||||
2298 | SourceLocation Loc; | ||||||
2299 | NamedDecl *ToND; | ||||||
2300 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc)) | ||||||
2301 | return std::move(Err); | ||||||
2302 | if (ToND) | ||||||
2303 | return ToND; | ||||||
2304 | |||||||
2305 | BindingDecl *ToD; | ||||||
2306 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc, | ||||||
2307 | Name.getAsIdentifierInfo())) | ||||||
2308 | return ToD; | ||||||
2309 | |||||||
2310 | Error Err = Error::success(); | ||||||
2311 | QualType ToType = importChecked(Err, D->getType()); | ||||||
2312 | Expr *ToBinding = importChecked(Err, D->getBinding()); | ||||||
2313 | ValueDecl *ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl()); | ||||||
2314 | if (Err) | ||||||
2315 | return std::move(Err); | ||||||
2316 | |||||||
2317 | ToD->setBinding(ToType, ToBinding); | ||||||
2318 | ToD->setDecomposedDecl(ToDecomposedDecl); | ||||||
2319 | addDeclToContexts(D, ToD); | ||||||
2320 | |||||||
2321 | return ToD; | ||||||
2322 | } | ||||||
2323 | |||||||
2324 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { | ||||||
2325 | ExpectedSLoc LocOrErr = import(D->getLocation()); | ||||||
2326 | if (!LocOrErr) | ||||||
2327 | return LocOrErr.takeError(); | ||||||
2328 | auto ColonLocOrErr = import(D->getColonLoc()); | ||||||
2329 | if (!ColonLocOrErr) | ||||||
2330 | return ColonLocOrErr.takeError(); | ||||||
2331 | |||||||
2332 | // Import the context of this declaration. | ||||||
2333 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); | ||||||
2334 | if (!DCOrErr) | ||||||
2335 | return DCOrErr.takeError(); | ||||||
2336 | DeclContext *DC = *DCOrErr; | ||||||
2337 | |||||||
2338 | AccessSpecDecl *ToD; | ||||||
2339 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), | ||||||
2340 | DC, *LocOrErr, *ColonLocOrErr)) | ||||||
2341 | return ToD; | ||||||
2342 | |||||||
2343 | // Lexical DeclContext and Semantic DeclContext | ||||||
2344 | // is always the same for the accessSpec. | ||||||
2345 | ToD->setLexicalDeclContext(DC); | ||||||
2346 | DC->addDeclInternal(ToD); | ||||||
2347 | |||||||
2348 | return ToD; | ||||||
2349 | } | ||||||
2350 | |||||||
2351 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { | ||||||
2352 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); | ||||||
2353 | if (!DCOrErr) | ||||||
2354 | return DCOrErr.takeError(); | ||||||
2355 | DeclContext *DC = *DCOrErr; | ||||||
2356 | DeclContext *LexicalDC = DC; | ||||||
2357 | |||||||
2358 | Error Err = Error::success(); | ||||||
2359 | auto ToLocation = importChecked(Err, D->getLocation()); | ||||||
2360 | auto ToRParenLoc = importChecked(Err, D->getRParenLoc()); | ||||||
2361 | auto ToAssertExpr = importChecked(Err, D->getAssertExpr()); | ||||||
2362 | auto ToMessage = importChecked(Err, D->getMessage()); | ||||||
2363 | if (Err) | ||||||
2364 | return std::move(Err); | ||||||
2365 | |||||||
2366 | StaticAssertDecl *ToD; | ||||||
2367 | if (GetImportedOrCreateDecl( | ||||||
2368 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, | ||||||
2369 | ToRParenLoc, D->isFailed())) | ||||||
2370 | return ToD; | ||||||
2371 | |||||||
2372 | ToD->setLexicalDeclContext(LexicalDC); | ||||||
2373 | LexicalDC->addDeclInternal(ToD); | ||||||
2374 | return ToD; | ||||||
2375 | } | ||||||
2376 | |||||||
2377 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { | ||||||
2378 | // Import the major distinguishing characteristics of this namespace. | ||||||
2379 | DeclContext *DC, *LexicalDC; | ||||||
2380 | DeclarationName Name; | ||||||
2381 | SourceLocation Loc; | ||||||
2382 | NamedDecl *ToD; | ||||||
2383 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
2384 | return std::move(Err); | ||||||
2385 | if (ToD) | ||||||
2386 | return ToD; | ||||||
2387 | |||||||
2388 | NamespaceDecl *MergeWithNamespace = nullptr; | ||||||
2389 | if (!Name) { | ||||||
2390 | // This is an anonymous namespace. Adopt an existing anonymous | ||||||
2391 | // namespace if we can. | ||||||
2392 | // FIXME: Not testable. | ||||||
2393 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) | ||||||
2394 | MergeWithNamespace = TU->getAnonymousNamespace(); | ||||||
2395 | else | ||||||
2396 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); | ||||||
2397 | } else { | ||||||
2398 | SmallVector<NamedDecl *, 4> ConflictingDecls; | ||||||
2399 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||
2400 | for (auto *FoundDecl : FoundDecls) { | ||||||
2401 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) | ||||||
2402 | continue; | ||||||
2403 | |||||||
2404 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { | ||||||
2405 | MergeWithNamespace = FoundNS; | ||||||
2406 | ConflictingDecls.clear(); | ||||||
2407 | break; | ||||||
2408 | } | ||||||
2409 | |||||||
2410 | ConflictingDecls.push_back(FoundDecl); | ||||||
2411 | } | ||||||
2412 | |||||||
2413 | if (!ConflictingDecls.empty()) { | ||||||
2414 | ExpectedName NameOrErr = Importer.HandleNameConflict( | ||||||
2415 | Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(), | ||||||
2416 | ConflictingDecls.size()); | ||||||
2417 | if (NameOrErr) | ||||||
2418 | Name = NameOrErr.get(); | ||||||
2419 | else | ||||||
2420 | return NameOrErr.takeError(); | ||||||
2421 | } | ||||||
2422 | } | ||||||
2423 | |||||||
2424 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | ||||||
2425 | if (!BeginLocOrErr) | ||||||
2426 | return BeginLocOrErr.takeError(); | ||||||
2427 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); | ||||||
2428 | if (!RBraceLocOrErr) | ||||||
2429 | return RBraceLocOrErr.takeError(); | ||||||
2430 | |||||||
2431 | // Create the "to" namespace, if needed. | ||||||
2432 | NamespaceDecl *ToNamespace = MergeWithNamespace; | ||||||
2433 | if (!ToNamespace) { | ||||||
2434 | if (GetImportedOrCreateDecl( | ||||||
2435 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), | ||||||
2436 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), | ||||||
2437 | /*PrevDecl=*/nullptr)) | ||||||
2438 | return ToNamespace; | ||||||
2439 | ToNamespace->setRBraceLoc(*RBraceLocOrErr); | ||||||
2440 | ToNamespace->setLexicalDeclContext(LexicalDC); | ||||||
2441 | LexicalDC->addDeclInternal(ToNamespace); | ||||||
2442 | |||||||
2443 | // If this is an anonymous namespace, register it as the anonymous | ||||||
2444 | // namespace within its context. | ||||||
2445 | if (!Name) { | ||||||
2446 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) | ||||||
2447 | TU->setAnonymousNamespace(ToNamespace); | ||||||
2448 | else | ||||||
2449 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); | ||||||
2450 | } | ||||||
2451 | } | ||||||
2452 | Importer.MapImported(D, ToNamespace); | ||||||
2453 | |||||||
2454 | if (Error Err = ImportDeclContext(D)) | ||||||
2455 | return std::move(Err); | ||||||
2456 | |||||||
2457 | return ToNamespace; | ||||||
2458 | } | ||||||
2459 | |||||||
2460 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { | ||||||
2461 | // Import the major distinguishing characteristics of this namespace. | ||||||
2462 | DeclContext *DC, *LexicalDC; | ||||||
2463 | DeclarationName Name; | ||||||
2464 | SourceLocation Loc; | ||||||
2465 | NamedDecl *LookupD; | ||||||
2466 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) | ||||||
2467 | return std::move(Err); | ||||||
2468 | if (LookupD) | ||||||
2469 | return LookupD; | ||||||
2470 | |||||||
2471 | // NOTE: No conflict resolution is done for namespace aliases now. | ||||||
2472 | |||||||
2473 | Error Err = Error::success(); | ||||||
2474 | auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc()); | ||||||
2475 | auto ToAliasLoc = importChecked(Err, D->getAliasLoc()); | ||||||
2476 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | ||||||
2477 | auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc()); | ||||||
2478 | auto ToNamespace = importChecked(Err, D->getNamespace()); | ||||||
2479 | if (Err) | ||||||
2480 | return std::move(Err); | ||||||
2481 | |||||||
2482 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); | ||||||
2483 | |||||||
2484 | NamespaceAliasDecl *ToD; | ||||||
2485 | if (GetImportedOrCreateDecl( | ||||||
2486 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, | ||||||
2487 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) | ||||||
2488 | return ToD; | ||||||
2489 | |||||||
2490 | ToD->setLexicalDeclContext(LexicalDC); | ||||||
2491 | LexicalDC->addDeclInternal(ToD); | ||||||
2492 | |||||||
2493 | return ToD; | ||||||
2494 | } | ||||||
2495 | |||||||
2496 | ExpectedDecl | ||||||
2497 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { | ||||||
2498 | // Import the major distinguishing characteristics of this typedef. | ||||||
2499 | DeclarationName Name; | ||||||
2500 | SourceLocation Loc; | ||||||
2501 | NamedDecl *ToD; | ||||||
2502 | // Do not import the DeclContext, we will import it once the TypedefNameDecl | ||||||
2503 | // is created. | ||||||
2504 | if (Error Err = ImportDeclParts(D, Name, ToD, Loc)) | ||||||
2505 | return std::move(Err); | ||||||
2506 | if (ToD
| ||||||
2507 | return ToD; | ||||||
2508 | |||||||
2509 | DeclContext *DC = cast_or_null<DeclContext>( | ||||||
2510 | Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext()))); | ||||||
2511 | DeclContext *LexicalDC = | ||||||
2512 | cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull( | ||||||
2513 | cast<Decl>(D->getLexicalDeclContext()))); | ||||||
2514 | |||||||
2515 | // If this typedef is not in block scope, determine whether we've | ||||||
2516 | // seen a typedef with the same name (that we can merge with) or any | ||||||
2517 | // other entity by that name (which name lookup could conflict with). | ||||||
2518 | // Note: Repeated typedefs are not valid in C99: | ||||||
2519 | // 'typedef int T; typedef int T;' is invalid | ||||||
2520 | // We do not care about this now. | ||||||
2521 | if (DC
| ||||||
2522 | SmallVector<NamedDecl *, 4> ConflictingDecls; | ||||||
2523 | unsigned IDNS = Decl::IDNS_Ordinary; | ||||||
2524 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||
2525 | for (auto *FoundDecl : FoundDecls) { | ||||||
2526 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | ||||||
2527 | continue; | ||||||
2528 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { | ||||||
2529 | if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D)) | ||||||
2530 | continue; | ||||||
2531 | |||||||
2532 | QualType FromUT = D->getUnderlyingType(); | ||||||
2533 | QualType FoundUT = FoundTypedef->getUnderlyingType(); | ||||||
2534 | if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) { | ||||||
2535 | // If the "From" context has a complete underlying type but we | ||||||
2536 | // already have a complete underlying type then return with that. | ||||||
2537 | if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType()) | ||||||
2538 | return Importer.MapImported(D, FoundTypedef); | ||||||
2539 | // FIXME Handle redecl chain. When you do that make consistent changes | ||||||
2540 | // in ASTImporterLookupTable too. | ||||||
2541 | } else { | ||||||
2542 | ConflictingDecls.push_back(FoundDecl); | ||||||
2543 | } | ||||||
2544 | } | ||||||
2545 | } | ||||||
2546 | |||||||
2547 | if (!ConflictingDecls.empty()) { | ||||||
2548 | ExpectedName NameOrErr = Importer.HandleNameConflict( | ||||||
2549 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); | ||||||
2550 | if (NameOrErr) | ||||||
2551 | Name = NameOrErr.get(); | ||||||
2552 | else | ||||||
2553 | return NameOrErr.takeError(); | ||||||
2554 | } | ||||||
2555 | } | ||||||
2556 | |||||||
2557 | Error Err = Error::success(); | ||||||
2558 | auto ToUnderlyingType = importChecked(Err, D->getUnderlyingType()); | ||||||
2559 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); | ||||||
2560 | auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); | ||||||
2561 | if (Err) | ||||||
2562 | return std::move(Err); | ||||||
2563 | |||||||
2564 | // Create the new typedef node. | ||||||
2565 | // FIXME: ToUnderlyingType is not used. | ||||||
2566 | (void)ToUnderlyingType; | ||||||
2567 | TypedefNameDecl *ToTypedef; | ||||||
2568 | if (IsAlias
| ||||||
2569 | if (GetImportedOrCreateDecl<TypeAliasDecl>( | ||||||
2570 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, | ||||||
2571 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) | ||||||
2572 | return ToTypedef; | ||||||
2573 | } else if (GetImportedOrCreateDecl<TypedefDecl>( | ||||||
2574 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, | ||||||
2575 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) | ||||||
2576 | return ToTypedef; | ||||||
2577 | |||||||
2578 | // Import the DeclContext and set it to the Typedef. | ||||||
2579 | if ((Err = ImportDeclContext(D, DC, LexicalDC))) | ||||||
2580 | return std::move(Err); | ||||||
2581 | ToTypedef->setDeclContext(DC); | ||||||
2582 | ToTypedef->setLexicalDeclContext(LexicalDC); | ||||||
2583 | // Add to the lookupTable because we could not do that in MapImported. | ||||||
2584 | Importer.AddToLookupTable(ToTypedef); | ||||||
2585 | |||||||
2586 | ToTypedef->setAccess(D->getAccess()); | ||||||
2587 | |||||||
2588 | // Templated declarations should not appear in DeclContext. | ||||||
2589 | TypeAliasDecl *FromAlias = IsAlias
| ||||||
2590 | if (!FromAlias
| ||||||
2591 | LexicalDC->addDeclInternal(ToTypedef); | ||||||
| |||||||
2592 | |||||||
2593 | return ToTypedef; | ||||||
2594 | } | ||||||
2595 | |||||||
2596 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { | ||||||
2597 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); | ||||||
2598 | } | ||||||
2599 | |||||||
2600 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { | ||||||
2601 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); | ||||||
2602 | } | ||||||
2603 | |||||||
2604 | ExpectedDecl | ||||||
2605 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { | ||||||
2606 | // Import the major distinguishing characteristics of this typedef. | ||||||
2607 | DeclContext *DC, *LexicalDC; | ||||||
2608 | DeclarationName Name; | ||||||
2609 | SourceLocation Loc; | ||||||
2610 | NamedDecl *FoundD; | ||||||
2611 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) | ||||||
2612 | return std::move(Err); | ||||||
2613 | if (FoundD) | ||||||
2614 | return FoundD; | ||||||
2615 | |||||||
2616 | // If this typedef is not in block scope, determine whether we've | ||||||
2617 | // seen a typedef with the same name (that we can merge with) or any | ||||||
2618 | // other entity by that name (which name lookup could conflict with). | ||||||
2619 | if (!DC->isFunctionOrMethod()) { | ||||||
2620 | SmallVector<NamedDecl *, 4> ConflictingDecls; | ||||||
2621 | unsigned IDNS = Decl::IDNS_Ordinary; | ||||||
2622 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||
2623 | for (auto *FoundDecl : FoundDecls) { | ||||||
2624 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | ||||||
2625 | continue; | ||||||
2626 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) | ||||||
2627 | return Importer.MapImported(D, FoundAlias); | ||||||
2628 | ConflictingDecls.push_back(FoundDecl); | ||||||
2629 | } | ||||||
2630 | |||||||
2631 | if (!ConflictingDecls.empty()) { | ||||||
2632 | ExpectedName NameOrErr = Importer.HandleNameConflict( | ||||||
2633 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); | ||||||
2634 | if (NameOrErr) | ||||||
2635 | Name = NameOrErr.get(); | ||||||
2636 | else | ||||||
2637 | return NameOrErr.takeError(); | ||||||
2638 | } | ||||||
2639 | } | ||||||
2640 | |||||||
2641 | Error Err = Error::success(); | ||||||
2642 | auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters()); | ||||||
2643 | auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl()); | ||||||
2644 | if (Err) | ||||||
2645 | return std::move(Err); | ||||||
2646 | |||||||
2647 | TypeAliasTemplateDecl *ToAlias; | ||||||
2648 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, | ||||||
2649 | Name, ToTemplateParameters, ToTemplatedDecl)) | ||||||
2650 | return ToAlias; | ||||||
2651 | |||||||
2652 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); | ||||||
2653 | |||||||
2654 | ToAlias->setAccess(D->getAccess()); | ||||||
2655 | ToAlias->setLexicalDeclContext(LexicalDC); | ||||||
2656 | LexicalDC->addDeclInternal(ToAlias); | ||||||
2657 | if (DC != Importer.getToContext().getTranslationUnitDecl()) | ||||||
2658 | updateLookupTableForTemplateParameters(*ToTemplateParameters); | ||||||
2659 | return ToAlias; | ||||||
2660 | } | ||||||
2661 | |||||||
2662 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { | ||||||
2663 | // Import the major distinguishing characteristics of this label. | ||||||
2664 | DeclContext *DC, *LexicalDC; | ||||||
2665 | DeclarationName Name; | ||||||
2666 | SourceLocation Loc; | ||||||
2667 | NamedDecl *ToD; | ||||||
2668 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
2669 | return std::move(Err); | ||||||
2670 | if (ToD) | ||||||
2671 | return ToD; | ||||||
2672 | |||||||
2673 | assert(LexicalDC->isFunctionOrMethod())(static_cast <bool> (LexicalDC->isFunctionOrMethod() ) ? void (0) : __assert_fail ("LexicalDC->isFunctionOrMethod()" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 2673, __extension__ __PRETTY_FUNCTION__)); | ||||||
2674 | |||||||
2675 | LabelDecl *ToLabel; | ||||||
2676 | if (D->isGnuLocal()) { | ||||||
2677 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | ||||||
2678 | if (!BeginLocOrErr) | ||||||
2679 | return BeginLocOrErr.takeError(); | ||||||
2680 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, | ||||||
2681 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) | ||||||
2682 | return ToLabel; | ||||||
2683 | |||||||
2684 | } else { | ||||||
2685 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, | ||||||
2686 | Name.getAsIdentifierInfo())) | ||||||
2687 | return ToLabel; | ||||||
2688 | |||||||
2689 | } | ||||||
2690 | |||||||
2691 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); | ||||||
2692 | if (!ToStmtOrErr) | ||||||
2693 | return ToStmtOrErr.takeError(); | ||||||
2694 | |||||||
2695 | ToLabel->setStmt(*ToStmtOrErr); | ||||||
2696 | ToLabel->setLexicalDeclContext(LexicalDC); | ||||||
2697 | LexicalDC->addDeclInternal(ToLabel); | ||||||
2698 | return ToLabel; | ||||||
2699 | } | ||||||
2700 | |||||||
2701 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { | ||||||
2702 | // Import the major distinguishing characteristics of this enum. | ||||||
2703 | DeclContext *DC, *LexicalDC; | ||||||
2704 | DeclarationName Name; | ||||||
2705 | SourceLocation Loc; | ||||||
2706 | NamedDecl *ToD; | ||||||
2707 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
2708 | return std::move(Err); | ||||||
2709 | if (ToD) | ||||||
2710 | return ToD; | ||||||
2711 | |||||||
2712 | // Figure out what enum name we're looking for. | ||||||
2713 | unsigned IDNS = Decl::IDNS_Tag; | ||||||
2714 | DeclarationName SearchName = Name; | ||||||
2715 | if (!SearchName && D->getTypedefNameForAnonDecl()) { | ||||||
2716 | if (Error Err = importInto( | ||||||
2717 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) | ||||||
2718 | return std::move(Err); | ||||||
2719 | IDNS = Decl::IDNS_Ordinary; | ||||||
2720 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) | ||||||
2721 | IDNS |= Decl::IDNS_Ordinary; | ||||||
2722 | |||||||
2723 | // We may already have an enum of the same name; try to find and match it. | ||||||
2724 | EnumDecl *PrevDecl = nullptr; | ||||||
2725 | if (!DC->isFunctionOrMethod() && SearchName) { | ||||||
2726 | SmallVector<NamedDecl *, 4> ConflictingDecls; | ||||||
2727 | auto FoundDecls = | ||||||
2728 | Importer.findDeclsInToCtx(DC, SearchName); | ||||||
2729 | for (auto *FoundDecl : FoundDecls) { | ||||||
2730 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | ||||||
2731 | continue; | ||||||
2732 | |||||||
2733 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { | ||||||
2734 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) | ||||||
2735 | FoundDecl = Tag->getDecl(); | ||||||
2736 | } | ||||||
2737 | |||||||
2738 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { | ||||||
2739 | if (!hasSameVisibilityContextAndLinkage(FoundEnum, D)) | ||||||
2740 | continue; | ||||||
2741 | if (IsStructuralMatch(D, FoundEnum)) { | ||||||
2742 | EnumDecl *FoundDef = FoundEnum->getDefinition(); | ||||||
2743 | if (D->isThisDeclarationADefinition() && FoundDef) | ||||||
2744 | return Importer.MapImported(D, FoundDef); | ||||||
2745 | PrevDecl = FoundEnum->getMostRecentDecl(); | ||||||
2746 | break; | ||||||
2747 | } | ||||||
2748 | ConflictingDecls.push_back(FoundDecl); | ||||||
2749 | } | ||||||
2750 | } | ||||||
2751 | |||||||
2752 | if (!ConflictingDecls.empty()) { | ||||||
2753 | ExpectedName NameOrErr = Importer.HandleNameConflict( | ||||||
2754 | SearchName, DC, IDNS, ConflictingDecls.data(), | ||||||
2755 | ConflictingDecls.size()); | ||||||
2756 | if (NameOrErr) | ||||||
2757 | Name = NameOrErr.get(); | ||||||
2758 | else | ||||||
2759 | return NameOrErr.takeError(); | ||||||
2760 | } | ||||||
2761 | } | ||||||
2762 | |||||||
2763 | Error Err = Error::success(); | ||||||
2764 | auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); | ||||||
2765 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | ||||||
2766 | auto ToIntegerType = importChecked(Err, D->getIntegerType()); | ||||||
2767 | auto ToBraceRange = importChecked(Err, D->getBraceRange()); | ||||||
2768 | if (Err) | ||||||
2769 | return std::move(Err); | ||||||
2770 | |||||||
2771 | // Create the enum declaration. | ||||||
2772 | EnumDecl *D2; | ||||||
2773 | if (GetImportedOrCreateDecl( | ||||||
2774 | D2, D, Importer.getToContext(), DC, ToBeginLoc, | ||||||
2775 | Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(), | ||||||
2776 | D->isScopedUsingClassTag(), D->isFixed())) | ||||||
2777 | return D2; | ||||||
2778 | |||||||
2779 | D2->setQualifierInfo(ToQualifierLoc); | ||||||
2780 | D2->setIntegerType(ToIntegerType); | ||||||
2781 | D2->setBraceRange(ToBraceRange); | ||||||
2782 | D2->setAccess(D->getAccess()); | ||||||
2783 | D2->setLexicalDeclContext(LexicalDC); | ||||||
2784 | addDeclToContexts(D, D2); | ||||||
2785 | |||||||
2786 | if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) { | ||||||
2787 | TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind(); | ||||||
2788 | EnumDecl *FromInst = D->getInstantiatedFromMemberEnum(); | ||||||
2789 | if (Expected<EnumDecl *> ToInstOrErr = import(FromInst)) | ||||||
2790 | D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK); | ||||||
2791 | else | ||||||
2792 | return ToInstOrErr.takeError(); | ||||||
2793 | if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation())) | ||||||
2794 | D2->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); | ||||||
2795 | else | ||||||
2796 | return POIOrErr.takeError(); | ||||||
2797 | } | ||||||
2798 | |||||||
2799 | // Import the definition | ||||||
2800 | if (D->isCompleteDefinition()) | ||||||
2801 | if (Error Err = ImportDefinition(D, D2)) | ||||||
2802 | return std::move(Err); | ||||||
2803 | |||||||
2804 | return D2; | ||||||
2805 | } | ||||||
2806 | |||||||
2807 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { | ||||||
2808 | bool IsFriendTemplate = false; | ||||||
2809 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | ||||||
2810 | IsFriendTemplate = | ||||||
2811 | DCXX->getDescribedClassTemplate() && | ||||||
2812 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != | ||||||
2813 | Decl::FOK_None; | ||||||
2814 | } | ||||||
2815 | |||||||
2816 | // Import the major distinguishing characteristics of this record. | ||||||
2817 | DeclContext *DC = nullptr, *LexicalDC = nullptr; | ||||||
2818 | DeclarationName Name; | ||||||
2819 | SourceLocation Loc; | ||||||
2820 | NamedDecl *ToD = nullptr; | ||||||
2821 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
2822 | return std::move(Err); | ||||||
2823 | if (ToD) | ||||||
2824 | return ToD; | ||||||
2825 | |||||||
2826 | // Figure out what structure name we're looking for. | ||||||
2827 | unsigned IDNS = Decl::IDNS_Tag; | ||||||
2828 | DeclarationName SearchName = Name; | ||||||
2829 | if (!SearchName && D->getTypedefNameForAnonDecl()) { | ||||||
2830 | if (Error Err = importInto( | ||||||
2831 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) | ||||||
2832 | return std::move(Err); | ||||||
2833 | IDNS = Decl::IDNS_Ordinary; | ||||||
2834 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) | ||||||
2835 | IDNS |= Decl::IDNS_Ordinary | Decl::IDNS_TagFriend; | ||||||
2836 | |||||||
2837 | // We may already have a record of the same name; try to find and match it. | ||||||
2838 | RecordDecl *PrevDecl = nullptr; | ||||||
2839 | if (!DC->isFunctionOrMethod() && !D->isLambda()) { | ||||||
2840 | SmallVector<NamedDecl *, 4> ConflictingDecls; | ||||||
2841 | auto FoundDecls = | ||||||
2842 | Importer.findDeclsInToCtx(DC, SearchName); | ||||||
2843 | if (!FoundDecls.empty()) { | ||||||
2844 | // We're going to have to compare D against potentially conflicting Decls, | ||||||
2845 | // so complete it. | ||||||
2846 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) | ||||||
2847 | D->getASTContext().getExternalSource()->CompleteType(D); | ||||||
2848 | } | ||||||
2849 | |||||||
2850 | for (auto *FoundDecl : FoundDecls) { | ||||||
2851 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | ||||||
2852 | continue; | ||||||
2853 | |||||||
2854 | Decl *Found = FoundDecl; | ||||||
2855 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { | ||||||
2856 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) | ||||||
2857 | Found = Tag->getDecl(); | ||||||
2858 | } | ||||||
2859 | |||||||
2860 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { | ||||||
2861 | // Do not emit false positive diagnostic in case of unnamed | ||||||
2862 | // struct/union and in case of anonymous structs. Would be false | ||||||
2863 | // because there may be several anonymous/unnamed structs in a class. | ||||||
2864 | // E.g. these are both valid: | ||||||
2865 | // struct A { // unnamed structs | ||||||
2866 | // struct { struct A *next; } entry0; | ||||||
2867 | // struct { struct A *next; } entry1; | ||||||
2868 | // }; | ||||||
2869 | // struct X { struct { int a; }; struct { int b; }; }; // anon structs | ||||||
2870 | if (!SearchName) | ||||||
2871 | if (!IsStructuralMatch(D, FoundRecord, false)) | ||||||
2872 | continue; | ||||||
2873 | |||||||
2874 | if (!hasSameVisibilityContextAndLinkage(FoundRecord, D)) | ||||||
2875 | continue; | ||||||
2876 | |||||||
2877 | if (IsStructuralMatch(D, FoundRecord)) { | ||||||
2878 | RecordDecl *FoundDef = FoundRecord->getDefinition(); | ||||||
2879 | if (D->isThisDeclarationADefinition() && FoundDef) { | ||||||
2880 | // FIXME: Structural equivalence check should check for same | ||||||
2881 | // user-defined methods. | ||||||
2882 | Importer.MapImported(D, FoundDef); | ||||||
2883 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | ||||||
2884 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); | ||||||
2885 | assert(FoundCXX && "Record type mismatch")(static_cast <bool> (FoundCXX && "Record type mismatch" ) ? void (0) : __assert_fail ("FoundCXX && \"Record type mismatch\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 2885, __extension__ __PRETTY_FUNCTION__)); | ||||||
2886 | |||||||
2887 | if (!Importer.isMinimalImport()) | ||||||
2888 | // FoundDef may not have every implicit method that D has | ||||||
2889 | // because implicit methods are created only if they are used. | ||||||
2890 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) | ||||||
2891 | return std::move(Err); | ||||||
2892 | } | ||||||
2893 | } | ||||||
2894 | PrevDecl = FoundRecord->getMostRecentDecl(); | ||||||
2895 | break; | ||||||
2896 | } | ||||||
2897 | ConflictingDecls.push_back(FoundDecl); | ||||||
2898 | } // kind is RecordDecl | ||||||
2899 | } // for | ||||||
2900 | |||||||
2901 | if (!ConflictingDecls.empty() && SearchName) { | ||||||
2902 | ExpectedName NameOrErr = Importer.HandleNameConflict( | ||||||
2903 | SearchName, DC, IDNS, ConflictingDecls.data(), | ||||||
2904 | ConflictingDecls.size()); | ||||||
2905 | if (NameOrErr) | ||||||
2906 | Name = NameOrErr.get(); | ||||||
2907 | else | ||||||
2908 | return NameOrErr.takeError(); | ||||||
2909 | } | ||||||
2910 | } | ||||||
2911 | |||||||
2912 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | ||||||
2913 | if (!BeginLocOrErr) | ||||||
2914 | return BeginLocOrErr.takeError(); | ||||||
2915 | |||||||
2916 | // Create the record declaration. | ||||||
2917 | RecordDecl *D2 = nullptr; | ||||||
2918 | CXXRecordDecl *D2CXX = nullptr; | ||||||
2919 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | ||||||
2920 | if (DCXX->isLambda()) { | ||||||
2921 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); | ||||||
2922 | if (!TInfoOrErr) | ||||||
2923 | return TInfoOrErr.takeError(); | ||||||
2924 | if (GetImportedOrCreateSpecialDecl( | ||||||
2925 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), | ||||||
2926 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), | ||||||
2927 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) | ||||||
2928 | return D2CXX; | ||||||
2929 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); | ||||||
2930 | if (!CDeclOrErr) | ||||||
2931 | return CDeclOrErr.takeError(); | ||||||
2932 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr, | ||||||
2933 | DCXX->hasKnownLambdaInternalLinkage()); | ||||||
2934 | D2CXX->setDeviceLambdaManglingNumber( | ||||||
2935 | DCXX->getDeviceLambdaManglingNumber()); | ||||||
2936 | } else if (DCXX->isInjectedClassName()) { | ||||||
2937 | // We have to be careful to do a similar dance to the one in | ||||||
2938 | // Sema::ActOnStartCXXMemberDeclarations | ||||||
2939 | const bool DelayTypeCreation = true; | ||||||
2940 | if (GetImportedOrCreateDecl( | ||||||
2941 | D2CXX, D, Importer.getToContext(), D->getTagKind(), DC, | ||||||
2942 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), | ||||||
2943 | cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation)) | ||||||
2944 | return D2CXX; | ||||||
2945 | Importer.getToContext().getTypeDeclType( | ||||||
2946 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); | ||||||
2947 | } else { | ||||||
2948 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), | ||||||
2949 | D->getTagKind(), DC, *BeginLocOrErr, Loc, | ||||||
2950 | Name.getAsIdentifierInfo(), | ||||||
2951 | cast_or_null<CXXRecordDecl>(PrevDecl))) | ||||||
2952 | return D2CXX; | ||||||
2953 | } | ||||||
2954 | |||||||
2955 | D2 = D2CXX; | ||||||
2956 | D2->setAccess(D->getAccess()); | ||||||
2957 | D2->setLexicalDeclContext(LexicalDC); | ||||||
2958 | addDeclToContexts(D, D2); | ||||||
2959 | |||||||
2960 | if (ClassTemplateDecl *FromDescribed = | ||||||
2961 | DCXX->getDescribedClassTemplate()) { | ||||||
2962 | ClassTemplateDecl *ToDescribed; | ||||||
2963 | if (Error Err = importInto(ToDescribed, FromDescribed)) | ||||||
2964 | return std::move(Err); | ||||||
2965 | D2CXX->setDescribedClassTemplate(ToDescribed); | ||||||
2966 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { | ||||||
2967 | // In a record describing a template the type should be an | ||||||
2968 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the | ||||||
2969 | // previously set type to the correct value here (ToDescribed is not | ||||||
2970 | // available at record create). | ||||||
2971 | // FIXME: The previous type is cleared but not removed from | ||||||
2972 | // ASTContext's internal storage. | ||||||
2973 | CXXRecordDecl *Injected = nullptr; | ||||||
2974 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { | ||||||
2975 | auto *Record = dyn_cast<CXXRecordDecl>(Found); | ||||||
2976 | if (Record && Record->isInjectedClassName()) { | ||||||
2977 | Injected = Record; | ||||||
2978 | break; | ||||||
2979 | } | ||||||
2980 | } | ||||||
2981 | // Create an injected type for the whole redecl chain. | ||||||
2982 | SmallVector<Decl *, 2> Redecls = | ||||||
2983 | getCanonicalForwardRedeclChain(D2CXX); | ||||||
2984 | for (auto *R : Redecls) { | ||||||
2985 | auto *RI = cast<CXXRecordDecl>(R); | ||||||
2986 | RI->setTypeForDecl(nullptr); | ||||||
2987 | // Below we create a new injected type and assign that to the | ||||||
2988 | // canonical decl, subsequent declarations in the chain will reuse | ||||||
2989 | // that type. | ||||||
2990 | Importer.getToContext().getInjectedClassNameType( | ||||||
2991 | RI, ToDescribed->getInjectedClassNameSpecialization()); | ||||||
2992 | } | ||||||
2993 | // Set the new type for the previous injected decl too. | ||||||
2994 | if (Injected) { | ||||||
2995 | Injected->setTypeForDecl(nullptr); | ||||||
2996 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); | ||||||
2997 | } | ||||||
2998 | } | ||||||
2999 | } else if (MemberSpecializationInfo *MemberInfo = | ||||||
3000 | DCXX->getMemberSpecializationInfo()) { | ||||||
3001 | TemplateSpecializationKind SK = | ||||||
3002 | MemberInfo->getTemplateSpecializationKind(); | ||||||
3003 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); | ||||||
3004 | |||||||
3005 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) | ||||||
3006 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); | ||||||
3007 | else | ||||||
3008 | return ToInstOrErr.takeError(); | ||||||
3009 | |||||||
3010 | if (ExpectedSLoc POIOrErr = | ||||||
3011 | import(MemberInfo->getPointOfInstantiation())) | ||||||
3012 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( | ||||||
3013 | *POIOrErr); | ||||||
3014 | else | ||||||
3015 | return POIOrErr.takeError(); | ||||||
3016 | } | ||||||
3017 | |||||||
3018 | } else { | ||||||
3019 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), | ||||||
3020 | D->getTagKind(), DC, *BeginLocOrErr, Loc, | ||||||
3021 | Name.getAsIdentifierInfo(), PrevDecl)) | ||||||
3022 | return D2; | ||||||
3023 | D2->setLexicalDeclContext(LexicalDC); | ||||||
3024 | addDeclToContexts(D, D2); | ||||||
3025 | } | ||||||
3026 | |||||||
3027 | if (auto BraceRangeOrErr = import(D->getBraceRange())) | ||||||
3028 | D2->setBraceRange(*BraceRangeOrErr); | ||||||
3029 | else | ||||||
3030 | return BraceRangeOrErr.takeError(); | ||||||
3031 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) | ||||||
3032 | D2->setQualifierInfo(*QualifierLocOrErr); | ||||||
3033 | else | ||||||
3034 | return QualifierLocOrErr.takeError(); | ||||||
3035 | |||||||
3036 | if (D->isAnonymousStructOrUnion()) | ||||||
3037 | D2->setAnonymousStructOrUnion(true); | ||||||
3038 | |||||||
3039 | if (D->isCompleteDefinition()) | ||||||
3040 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) | ||||||
3041 | return std::move(Err); | ||||||
3042 | |||||||
3043 | return D2; | ||||||
3044 | } | ||||||
3045 | |||||||
3046 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { | ||||||
3047 | // Import the major distinguishing characteristics of this enumerator. | ||||||
3048 | DeclContext *DC, *LexicalDC; | ||||||
3049 | DeclarationName Name; | ||||||
3050 | SourceLocation Loc; | ||||||
3051 | NamedDecl *ToD; | ||||||
3052 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
3053 | return std::move(Err); | ||||||
3054 | if (ToD) | ||||||
3055 | return ToD; | ||||||
3056 | |||||||
3057 | // Determine whether there are any other declarations with the same name and | ||||||
3058 | // in the same context. | ||||||
3059 | if (!LexicalDC->isFunctionOrMethod()) { | ||||||
3060 | SmallVector<NamedDecl *, 4> ConflictingDecls; | ||||||
3061 | unsigned IDNS = Decl::IDNS_Ordinary; | ||||||
3062 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||
3063 | for (auto *FoundDecl : FoundDecls) { | ||||||
3064 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | ||||||
3065 | continue; | ||||||
3066 | |||||||
3067 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { | ||||||
3068 | if (IsStructuralMatch(D, FoundEnumConstant)) | ||||||
3069 | return Importer.MapImported(D, FoundEnumConstant); | ||||||
3070 | ConflictingDecls.push_back(FoundDecl); | ||||||
3071 | } | ||||||
3072 | } | ||||||
3073 | |||||||
3074 | if (!ConflictingDecls.empty()) { | ||||||
3075 | ExpectedName NameOrErr = Importer.HandleNameConflict( | ||||||
3076 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); | ||||||
3077 | if (NameOrErr) | ||||||
3078 | Name = NameOrErr.get(); | ||||||
3079 | else | ||||||
3080 | return NameOrErr.takeError(); | ||||||
3081 | } | ||||||
3082 | } | ||||||
3083 | |||||||
3084 | ExpectedType TypeOrErr = import(D->getType()); | ||||||
3085 | if (!TypeOrErr) | ||||||
3086 | return TypeOrErr.takeError(); | ||||||
3087 | |||||||
3088 | ExpectedExpr InitOrErr = import(D->getInitExpr()); | ||||||
3089 | if (!InitOrErr) | ||||||
3090 | return InitOrErr.takeError(); | ||||||
3091 | |||||||
3092 | EnumConstantDecl *ToEnumerator; | ||||||
3093 | if (GetImportedOrCreateDecl( | ||||||
3094 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, | ||||||
3095 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) | ||||||
3096 | return ToEnumerator; | ||||||
3097 | |||||||
3098 | ToEnumerator->setAccess(D->getAccess()); | ||||||
3099 | ToEnumerator->setLexicalDeclContext(LexicalDC); | ||||||
3100 | LexicalDC->addDeclInternal(ToEnumerator); | ||||||
3101 | return ToEnumerator; | ||||||
3102 | } | ||||||
3103 | |||||||
3104 | Error ASTNodeImporter::ImportTemplateParameterLists(const DeclaratorDecl *FromD, | ||||||
3105 | DeclaratorDecl *ToD) { | ||||||
3106 | unsigned int Num = FromD->getNumTemplateParameterLists(); | ||||||
3107 | if (Num == 0) | ||||||
3108 | return Error::success(); | ||||||
3109 | SmallVector<TemplateParameterList *, 2> ToTPLists(Num); | ||||||
3110 | for (unsigned int I = 0; I < Num; ++I) | ||||||
3111 | if (Expected<TemplateParameterList *> ToTPListOrErr = | ||||||
3112 | import(FromD->getTemplateParameterList(I))) | ||||||
3113 | ToTPLists[I] = *ToTPListOrErr; | ||||||
3114 | else | ||||||
3115 | return ToTPListOrErr.takeError(); | ||||||
3116 | ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists); | ||||||
3117 | return Error::success(); | ||||||
3118 | } | ||||||
3119 | |||||||
3120 | Error ASTNodeImporter::ImportTemplateInformation( | ||||||
3121 | FunctionDecl *FromFD, FunctionDecl *ToFD) { | ||||||
3122 | switch (FromFD->getTemplatedKind()) { | ||||||
3123 | case FunctionDecl::TK_NonTemplate: | ||||||
3124 | case FunctionDecl::TK_FunctionTemplate: | ||||||
3125 | return Error::success(); | ||||||
3126 | |||||||
3127 | case FunctionDecl::TK_MemberSpecialization: { | ||||||
3128 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); | ||||||
3129 | |||||||
3130 | if (Expected<FunctionDecl *> InstFDOrErr = | ||||||
3131 | import(FromFD->getInstantiatedFromMemberFunction())) | ||||||
3132 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); | ||||||
3133 | else | ||||||
3134 | return InstFDOrErr.takeError(); | ||||||
3135 | |||||||
3136 | if (ExpectedSLoc POIOrErr = import( | ||||||
3137 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) | ||||||
3138 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); | ||||||
3139 | else | ||||||
3140 | return POIOrErr.takeError(); | ||||||
3141 | |||||||
3142 | return Error::success(); | ||||||
3143 | } | ||||||
3144 | |||||||
3145 | case FunctionDecl::TK_FunctionTemplateSpecialization: { | ||||||
3146 | auto FunctionAndArgsOrErr = | ||||||
3147 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); | ||||||
3148 | if (!FunctionAndArgsOrErr) | ||||||
3149 | return FunctionAndArgsOrErr.takeError(); | ||||||
3150 | |||||||
3151 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( | ||||||
3152 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); | ||||||
3153 | |||||||
3154 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); | ||||||
3155 | TemplateArgumentListInfo ToTAInfo; | ||||||
3156 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; | ||||||
3157 | if (FromTAArgsAsWritten) | ||||||
3158 | if (Error Err = ImportTemplateArgumentListInfo( | ||||||
3159 | *FromTAArgsAsWritten, ToTAInfo)) | ||||||
3160 | return Err; | ||||||
3161 | |||||||
3162 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); | ||||||
3163 | if (!POIOrErr) | ||||||
3164 | return POIOrErr.takeError(); | ||||||
3165 | |||||||
3166 | if (Error Err = ImportTemplateParameterLists(FromFD, ToFD)) | ||||||
3167 | return Err; | ||||||
3168 | |||||||
3169 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); | ||||||
3170 | ToFD->setFunctionTemplateSpecialization( | ||||||
3171 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, | ||||||
3172 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); | ||||||
3173 | return Error::success(); | ||||||
3174 | } | ||||||
3175 | |||||||
3176 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { | ||||||
3177 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); | ||||||
3178 | UnresolvedSet<8> TemplDecls; | ||||||
3179 | unsigned NumTemplates = FromInfo->getNumTemplates(); | ||||||
3180 | for (unsigned I = 0; I < NumTemplates; I++) { | ||||||
3181 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = | ||||||
3182 | import(FromInfo->getTemplate(I))) | ||||||
3183 | TemplDecls.addDecl(*ToFTDOrErr); | ||||||
3184 | else | ||||||
3185 | return ToFTDOrErr.takeError(); | ||||||
3186 | } | ||||||
3187 | |||||||
3188 | // Import TemplateArgumentListInfo. | ||||||
3189 | TemplateArgumentListInfo ToTAInfo; | ||||||
3190 | if (Error Err = ImportTemplateArgumentListInfo( | ||||||
3191 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), | ||||||
3192 | llvm::makeArrayRef( | ||||||
3193 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), | ||||||
3194 | ToTAInfo)) | ||||||
3195 | return Err; | ||||||
3196 | |||||||
3197 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), | ||||||
3198 | TemplDecls, ToTAInfo); | ||||||
3199 | return Error::success(); | ||||||
3200 | } | ||||||
3201 | } | ||||||
3202 | llvm_unreachable("All cases should be covered!")::llvm::llvm_unreachable_internal("All cases should be covered!" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 3202); | ||||||
3203 | } | ||||||
3204 | |||||||
3205 | Expected<FunctionDecl *> | ||||||
3206 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { | ||||||
3207 | auto FunctionAndArgsOrErr = | ||||||
3208 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); | ||||||
3209 | if (!FunctionAndArgsOrErr) | ||||||
3210 | return FunctionAndArgsOrErr.takeError(); | ||||||
3211 | |||||||
3212 | FunctionTemplateDecl *Template; | ||||||
3213 | TemplateArgsTy ToTemplArgs; | ||||||
3214 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; | ||||||
3215 | void *InsertPos = nullptr; | ||||||
3216 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); | ||||||
3217 | return FoundSpec; | ||||||
3218 | } | ||||||
3219 | |||||||
3220 | Error ASTNodeImporter::ImportFunctionDeclBody(FunctionDecl *FromFD, | ||||||
3221 | FunctionDecl *ToFD) { | ||||||
3222 | if (Stmt *FromBody = FromFD->getBody()) { | ||||||
3223 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) | ||||||
3224 | ToFD->setBody(*ToBodyOrErr); | ||||||
3225 | else | ||||||
3226 | return ToBodyOrErr.takeError(); | ||||||
3227 | } | ||||||
3228 | return Error::success(); | ||||||
3229 | } | ||||||
3230 | |||||||
3231 | // Returns true if the given D has a DeclContext up to the TranslationUnitDecl | ||||||
3232 | // which is equal to the given DC. | ||||||
3233 | static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) { | ||||||
3234 | const DeclContext *DCi = D->getDeclContext(); | ||||||
3235 | while (DCi != D->getTranslationUnitDecl()) { | ||||||
3236 | if (DCi == DC) | ||||||
3237 | return true; | ||||||
3238 | DCi = DCi->getParent(); | ||||||
3239 | } | ||||||
3240 | return false; | ||||||
3241 | } | ||||||
3242 | |||||||
3243 | bool ASTNodeImporter::hasAutoReturnTypeDeclaredInside(FunctionDecl *D) { | ||||||
3244 | QualType FromTy = D->getType(); | ||||||
3245 | const FunctionProtoType *FromFPT = FromTy->getAs<FunctionProtoType>(); | ||||||
3246 | 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\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 3246, __extension__ __PRETTY_FUNCTION__)); | ||||||
3247 | if (AutoType *AutoT = FromFPT->getReturnType()->getContainedAutoType()) { | ||||||
3248 | QualType DeducedT = AutoT->getDeducedType(); | ||||||
3249 | if (const RecordType *RecordT = | ||||||
3250 | DeducedT.isNull() ? nullptr : dyn_cast<RecordType>(DeducedT)) { | ||||||
3251 | RecordDecl *RD = RecordT->getDecl(); | ||||||
3252 | assert(RD)(static_cast <bool> (RD) ? void (0) : __assert_fail ("RD" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 3252, __extension__ __PRETTY_FUNCTION__)); | ||||||
3253 | if (isAncestorDeclContextOf(D, RD)) { | ||||||
3254 | assert(RD->getLexicalDeclContext() == RD->getDeclContext())(static_cast <bool> (RD->getLexicalDeclContext() == RD ->getDeclContext()) ? void (0) : __assert_fail ("RD->getLexicalDeclContext() == RD->getDeclContext()" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 3254, __extension__ __PRETTY_FUNCTION__)); | ||||||
3255 | return true; | ||||||
3256 | } | ||||||
3257 | } | ||||||
3258 | } | ||||||
3259 | if (const TypedefType *TypedefT = | ||||||
3260 | dyn_cast<TypedefType>(FromFPT->getReturnType())) { | ||||||
3261 | TypedefNameDecl *TD = TypedefT->getDecl(); | ||||||
3262 | assert(TD)(static_cast <bool> (TD) ? void (0) : __assert_fail ("TD" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 3262, __extension__ __PRETTY_FUNCTION__)); | ||||||
3263 | if (isAncestorDeclContextOf(D, TD)) { | ||||||
3264 | assert(TD->getLexicalDeclContext() == TD->getDeclContext())(static_cast <bool> (TD->getLexicalDeclContext() == TD ->getDeclContext()) ? void (0) : __assert_fail ("TD->getLexicalDeclContext() == TD->getDeclContext()" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 3264, __extension__ __PRETTY_FUNCTION__)); | ||||||
3265 | return true; | ||||||
3266 | } | ||||||
3267 | } | ||||||
3268 | return false; | ||||||
3269 | } | ||||||
3270 | |||||||
3271 | ExplicitSpecifier | ||||||
3272 | ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) { | ||||||
3273 | Expr *ExplicitExpr = ESpec.getExpr(); | ||||||
3274 | if (ExplicitExpr) | ||||||
3275 | ExplicitExpr = importChecked(Err, ESpec.getExpr()); | ||||||
3276 | return ExplicitSpecifier(ExplicitExpr, ESpec.getKind()); | ||||||
3277 | } | ||||||
3278 | |||||||
3279 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { | ||||||
3280 | |||||||
3281 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); | ||||||
3282 | auto RedeclIt = Redecls.begin(); | ||||||
3283 | // Import the first part of the decl chain. I.e. import all previous | ||||||
3284 | // declarations starting from the canonical decl. | ||||||
3285 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { | ||||||
3286 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); | ||||||
3287 | if (!ToRedeclOrErr) | ||||||
3288 | return ToRedeclOrErr.takeError(); | ||||||
3289 | } | ||||||
3290 | assert(*RedeclIt == D)(static_cast <bool> (*RedeclIt == D) ? void (0) : __assert_fail ("*RedeclIt == D", "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 3290, __extension__ __PRETTY_FUNCTION__)); | ||||||
3291 | |||||||
3292 | // Import the major distinguishing characteristics of this function. | ||||||
3293 | DeclContext *DC, *LexicalDC; | ||||||
3294 | DeclarationName Name; | ||||||
3295 | SourceLocation Loc; | ||||||
3296 | NamedDecl *ToD; | ||||||
3297 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
3298 | return std::move(Err); | ||||||
3299 | if (ToD) | ||||||
3300 | return ToD; | ||||||
3301 | |||||||
3302 | FunctionDecl *FoundByLookup = nullptr; | ||||||
3303 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); | ||||||
3304 | |||||||
3305 | // If this is a function template specialization, then try to find the same | ||||||
3306 | // existing specialization in the "to" context. The lookup below will not | ||||||
3307 | // find any specialization, but would find the primary template; thus, we | ||||||
3308 | // have to skip normal lookup in case of specializations. | ||||||
3309 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? | ||||||
3310 | if (D->getTemplatedKind() == | ||||||
3311 | FunctionDecl::TK_FunctionTemplateSpecialization) { | ||||||
3312 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); | ||||||
3313 | if (!FoundFunctionOrErr) | ||||||
3314 | return FoundFunctionOrErr.takeError(); | ||||||
3315 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { | ||||||
3316 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) | ||||||
3317 | return Def; | ||||||
3318 | FoundByLookup = FoundFunction; | ||||||
3319 | } | ||||||
3320 | } | ||||||
3321 | // Try to find a function in our own ("to") context with the same name, same | ||||||
3322 | // type, and in the same context as the function we're importing. | ||||||
3323 | else if (!LexicalDC->isFunctionOrMethod()) { | ||||||
3324 | SmallVector<NamedDecl *, 4> ConflictingDecls; | ||||||
3325 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; | ||||||
3326 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||
3327 | for (auto *FoundDecl : FoundDecls) { | ||||||
3328 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | ||||||
3329 | continue; | ||||||
3330 | |||||||
3331 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { | ||||||
3332 | if (!hasSameVisibilityContextAndLinkage(FoundFunction, D)) | ||||||
3333 | continue; | ||||||
3334 | |||||||
3335 | if (IsStructuralMatch(D, FoundFunction)) { | ||||||
3336 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) | ||||||
3337 | return Def; | ||||||
3338 | FoundByLookup = FoundFunction; | ||||||
3339 | break; | ||||||
3340 | } | ||||||
3341 | // FIXME: Check for overloading more carefully, e.g., by boosting | ||||||
3342 | // Sema::IsOverload out to the AST library. | ||||||
3343 | |||||||
3344 | // Function overloading is okay in C++. | ||||||
3345 | if (Importer.getToContext().getLangOpts().CPlusPlus) | ||||||
3346 | continue; | ||||||
3347 | |||||||
3348 | // Complain about inconsistent function types. | ||||||
3349 | Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent) | ||||||
3350 | << Name << D->getType() << FoundFunction->getType(); | ||||||
3351 | Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here) | ||||||
3352 | << FoundFunction->getType(); | ||||||
3353 | ConflictingDecls.push_back(FoundDecl); | ||||||
3354 | } | ||||||
3355 | } | ||||||
3356 | |||||||
3357 | if (!ConflictingDecls.empty()) { | ||||||
3358 | ExpectedName NameOrErr = Importer.HandleNameConflict( | ||||||
3359 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); | ||||||
3360 | if (NameOrErr) | ||||||
3361 | Name = NameOrErr.get(); | ||||||
3362 | else | ||||||
3363 | return NameOrErr.takeError(); | ||||||
3364 | } | ||||||
3365 | } | ||||||
3366 | |||||||
3367 | // We do not allow more than one in-class declaration of a function. This is | ||||||
3368 | // because AST clients like VTableBuilder asserts on this. VTableBuilder | ||||||
3369 | // assumes there is only one in-class declaration. Building a redecl | ||||||
3370 | // chain would result in more than one in-class declaration for | ||||||
3371 | // overrides (even if they are part of the same redecl chain inside the | ||||||
3372 | // derived class.) | ||||||
3373 | if (FoundByLookup) { | ||||||
3374 | if (isa<CXXMethodDecl>(FoundByLookup)) { | ||||||
3375 | if (D->getLexicalDeclContext() == D->getDeclContext()) { | ||||||
3376 | if (!D->doesThisDeclarationHaveABody()) { | ||||||
3377 | if (FunctionTemplateDecl *DescribedD = | ||||||
3378 | D->getDescribedFunctionTemplate()) { | ||||||
3379 | // Handle a "templated" function together with its described | ||||||
3380 | // template. This avoids need for a similar check at import of the | ||||||
3381 | // described template. | ||||||
3382 | 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?\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 3383, __extension__ __PRETTY_FUNCTION__)) | ||||||
3383 | "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?\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 3383, __extension__ __PRETTY_FUNCTION__)); | ||||||
3384 | Importer.MapImported(DescribedD, | ||||||
3385 | FoundByLookup->getDescribedFunctionTemplate()); | ||||||
3386 | } | ||||||
3387 | return Importer.MapImported(D, FoundByLookup); | ||||||
3388 | } else { | ||||||
3389 | // Let's continue and build up the redecl chain in this case. | ||||||
3390 | // FIXME Merge the functions into one decl. | ||||||
3391 | } | ||||||
3392 | } | ||||||
3393 | } | ||||||
3394 | } | ||||||
3395 | |||||||
3396 | DeclarationNameInfo NameInfo(Name, Loc); | ||||||
3397 | // Import additional name location/type info. | ||||||
3398 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | ||||||
3399 | return std::move(Err); | ||||||
3400 | |||||||
3401 | QualType FromTy = D->getType(); | ||||||
3402 | // Set to true if we do not import the type of the function as is. There are | ||||||
3403 | // cases when the original type would result in an infinite recursion during | ||||||
3404 | // the import. To avoid an infinite recursion when importing, we create the | ||||||
3405 | // FunctionDecl with a simplified function type and update it only after the | ||||||
3406 | // relevant AST nodes are already imported. | ||||||
3407 | bool UsedDifferentProtoType = false; | ||||||
3408 | if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) { | ||||||
3409 | QualType FromReturnTy = FromFPT->getReturnType(); | ||||||
3410 | // Functions with auto return type may define a struct inside their body | ||||||
3411 | // and the return type could refer to that struct. | ||||||
3412 | // E.g.: auto foo() { struct X{}; return X(); } | ||||||
3413 | // To avoid an infinite recursion when importing, create the FunctionDecl | ||||||
3414 | // with a simplified return type. | ||||||
3415 | if (hasAutoReturnTypeDeclaredInside(D)) { | ||||||
3416 | FromReturnTy = Importer.getFromContext().VoidTy; | ||||||
3417 | UsedDifferentProtoType = true; | ||||||
3418 | } | ||||||
3419 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); | ||||||
3420 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the | ||||||
3421 | // FunctionDecl that we are importing the FunctionProtoType for. | ||||||
3422 | // To avoid an infinite recursion when importing, create the FunctionDecl | ||||||
3423 | // with a simplified function type. | ||||||
3424 | if (FromEPI.ExceptionSpec.SourceDecl || | ||||||
3425 | FromEPI.ExceptionSpec.SourceTemplate || | ||||||
3426 | FromEPI.ExceptionSpec.NoexceptExpr) { | ||||||
3427 | FunctionProtoType::ExtProtoInfo DefaultEPI; | ||||||
3428 | FromEPI = DefaultEPI; | ||||||
3429 | UsedDifferentProtoType = true; | ||||||
3430 | } | ||||||
3431 | FromTy = Importer.getFromContext().getFunctionType( | ||||||
3432 | FromReturnTy, FromFPT->getParamTypes(), FromEPI); | ||||||
3433 | } | ||||||
3434 | |||||||
3435 | Error Err = Error::success(); | ||||||
3436 | auto T = importChecked(Err, FromTy); | ||||||
3437 | auto TInfo = importChecked(Err, D->getTypeSourceInfo()); | ||||||
3438 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); | ||||||
3439 | auto ToEndLoc = importChecked(Err, D->getEndLoc()); | ||||||
3440 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | ||||||
3441 | auto TrailingRequiresClause = | ||||||
3442 | importChecked(Err, D->getTrailingRequiresClause()); | ||||||
3443 | if (Err) | ||||||
3444 | return std::move(Err); | ||||||
3445 | |||||||
3446 | // Import the function parameters. | ||||||
3447 | SmallVector<ParmVarDecl *, 8> Parameters; | ||||||
3448 | for (auto P : D->parameters()) { | ||||||
3449 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) | ||||||
3450 | Parameters.push_back(*ToPOrErr); | ||||||
3451 | else | ||||||
3452 | return ToPOrErr.takeError(); | ||||||
3453 | } | ||||||
3454 | |||||||
3455 | // Create the imported function. | ||||||
3456 | FunctionDecl *ToFunction = nullptr; | ||||||
3457 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { | ||||||
3458 | ExplicitSpecifier ESpec = | ||||||
3459 | importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier()); | ||||||
3460 | if (Err) | ||||||
3461 | return std::move(Err); | ||||||
3462 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( | ||||||
3463 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | ||||||
3464 | ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(), | ||||||
3465 | D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(), | ||||||
3466 | InheritedConstructor(), // FIXME: Properly import inherited | ||||||
3467 | // constructor info | ||||||
3468 | TrailingRequiresClause)) | ||||||
3469 | return ToFunction; | ||||||
3470 | } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) { | ||||||
3471 | |||||||
3472 | Error Err = Error::success(); | ||||||
3473 | auto ToOperatorDelete = importChecked( | ||||||
3474 | Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete())); | ||||||
3475 | auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg()); | ||||||
3476 | if (Err) | ||||||
3477 | return std::move(Err); | ||||||
3478 | |||||||
3479 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( | ||||||
3480 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | ||||||
3481 | ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(), | ||||||
3482 | D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(), | ||||||
3483 | TrailingRequiresClause)) | ||||||
3484 | return ToFunction; | ||||||
3485 | |||||||
3486 | CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction); | ||||||
3487 | |||||||
3488 | ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); | ||||||
3489 | } else if (CXXConversionDecl *FromConversion = | ||||||
3490 | dyn_cast<CXXConversionDecl>(D)) { | ||||||
3491 | ExplicitSpecifier ESpec = | ||||||
3492 | importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier()); | ||||||
3493 | if (Err) | ||||||
3494 | return std::move(Err); | ||||||
3495 | if (GetImportedOrCreateDecl<CXXConversionDecl>( | ||||||
3496 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | ||||||
3497 | ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(), | ||||||
3498 | D->isInlineSpecified(), ESpec, D->getConstexprKind(), | ||||||
3499 | SourceLocation(), TrailingRequiresClause)) | ||||||
3500 | return ToFunction; | ||||||
3501 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { | ||||||
3502 | if (GetImportedOrCreateDecl<CXXMethodDecl>( | ||||||
3503 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | ||||||
3504 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), | ||||||
3505 | Method->UsesFPIntrin(), Method->isInlineSpecified(), | ||||||
3506 | D->getConstexprKind(), SourceLocation(), TrailingRequiresClause)) | ||||||
3507 | return ToFunction; | ||||||
3508 | } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) { | ||||||
3509 | ExplicitSpecifier ESpec = | ||||||
3510 | importExplicitSpecifier(Err, Guide->getExplicitSpecifier()); | ||||||
3511 | CXXConstructorDecl *Ctor = | ||||||
3512 | importChecked(Err, Guide->getCorrespondingConstructor()); | ||||||
3513 | if (Err) | ||||||
3514 | return std::move(Err); | ||||||
3515 | if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>( | ||||||
3516 | ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec, | ||||||
3517 | NameInfo, T, TInfo, ToEndLoc, Ctor)) | ||||||
3518 | return ToFunction; | ||||||
3519 | cast<CXXDeductionGuideDecl>(ToFunction) | ||||||
3520 | ->setIsCopyDeductionCandidate(Guide->isCopyDeductionCandidate()); | ||||||
3521 | } else { | ||||||
3522 | if (GetImportedOrCreateDecl( | ||||||
3523 | ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, | ||||||
3524 | NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(), | ||||||
3525 | D->isInlineSpecified(), D->hasWrittenPrototype(), | ||||||
3526 | D->getConstexprKind(), TrailingRequiresClause)) | ||||||
3527 | return ToFunction; | ||||||
3528 | } | ||||||
3529 | |||||||
3530 | // Connect the redecl chain. | ||||||
3531 | if (FoundByLookup) { | ||||||
3532 | auto *Recent = const_cast<FunctionDecl *>( | ||||||
3533 | FoundByLookup->getMostRecentDecl()); | ||||||
3534 | ToFunction->setPreviousDecl(Recent); | ||||||
3535 | // FIXME Probably we should merge exception specifications. E.g. In the | ||||||
3536 | // "To" context the existing function may have exception specification with | ||||||
3537 | // noexcept-unevaluated, while the newly imported function may have an | ||||||
3538 | // evaluated noexcept. A call to adjustExceptionSpec() on the imported | ||||||
3539 | // decl and its redeclarations may be required. | ||||||
3540 | } | ||||||
3541 | |||||||
3542 | ToFunction->setQualifierInfo(ToQualifierLoc); | ||||||
3543 | ToFunction->setAccess(D->getAccess()); | ||||||
3544 | ToFunction->setLexicalDeclContext(LexicalDC); | ||||||
3545 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); | ||||||
3546 | ToFunction->setTrivial(D->isTrivial()); | ||||||
3547 | ToFunction->setPure(D->isPure()); | ||||||
3548 | ToFunction->setDefaulted(D->isDefaulted()); | ||||||
3549 | ToFunction->setExplicitlyDefaulted(D->isExplicitlyDefaulted()); | ||||||
3550 | ToFunction->setDeletedAsWritten(D->isDeletedAsWritten()); | ||||||
3551 | ToFunction->setRangeEnd(ToEndLoc); | ||||||
3552 | |||||||
3553 | // Set the parameters. | ||||||
3554 | for (auto *Param : Parameters) { | ||||||
3555 | Param->setOwningFunction(ToFunction); | ||||||
3556 | ToFunction->addDeclInternal(Param); | ||||||
3557 | if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable()) | ||||||
3558 | LT->update(Param, Importer.getToContext().getTranslationUnitDecl()); | ||||||
3559 | } | ||||||
3560 | ToFunction->setParams(Parameters); | ||||||
3561 | |||||||
3562 | // We need to complete creation of FunctionProtoTypeLoc manually with setting | ||||||
3563 | // params it refers to. | ||||||
3564 | if (TInfo) { | ||||||
3565 | if (auto ProtoLoc = | ||||||
3566 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { | ||||||
3567 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) | ||||||
3568 | ProtoLoc.setParam(I, Parameters[I]); | ||||||
3569 | } | ||||||
3570 | } | ||||||
3571 | |||||||
3572 | // Import the describing template function, if any. | ||||||
3573 | if (FromFT) { | ||||||
3574 | auto ToFTOrErr = import(FromFT); | ||||||
3575 | if (!ToFTOrErr) | ||||||
3576 | return ToFTOrErr.takeError(); | ||||||
3577 | } | ||||||
3578 | |||||||
3579 | // Import Ctor initializers. | ||||||
3580 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { | ||||||
3581 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { | ||||||
3582 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); | ||||||
3583 | // Import first, then allocate memory and copy if there was no error. | ||||||
3584 | if (Error Err = ImportContainerChecked( | ||||||
3585 | FromConstructor->inits(), CtorInitializers)) | ||||||
3586 | return std::move(Err); | ||||||
3587 | auto **Memory = | ||||||
3588 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; | ||||||
3589 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); | ||||||
3590 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); | ||||||
3591 | ToCtor->setCtorInitializers(Memory); | ||||||
3592 | ToCtor->setNumCtorInitializers(NumInitializers); | ||||||
3593 | } | ||||||
3594 | } | ||||||
3595 | |||||||
3596 | if (D->doesThisDeclarationHaveABody()) { | ||||||
3597 | Error Err = ImportFunctionDeclBody(D, ToFunction); | ||||||
3598 | |||||||
3599 | if (Err) | ||||||
3600 | return std::move(Err); | ||||||
3601 | } | ||||||
3602 | |||||||
3603 | // Import and set the original type in case we used another type. | ||||||
3604 | if (UsedDifferentProtoType) { | ||||||
3605 | if (ExpectedType TyOrErr = import(D->getType())) | ||||||
3606 | ToFunction->setType(*TyOrErr); | ||||||
3607 | else | ||||||
3608 | return TyOrErr.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 | if (Expr *FromInitializer = D->getInClassInitializer()) { | ||||||
3684 | // We don't have yet the initializer set. | ||||||
3685 | if (FoundField->hasInClassInitializer() && | ||||||
3686 | !FoundField->getInClassInitializer()) { | ||||||
3687 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) | ||||||
3688 | FoundField->setInClassInitializer(*ToInitializerOrErr); | ||||||
3689 | else { | ||||||
3690 | // We can't return error here, | ||||||
3691 | // since we already mapped D as imported. | ||||||
3692 | // FIXME: warning message? | ||||||
3693 | consumeError(ToInitializerOrErr.takeError()); | ||||||
3694 | return FoundField; | ||||||
3695 | } | ||||||
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.\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/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." , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/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." , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/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?\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/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?\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/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", "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/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 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { | ||||||
4203 | // Parameters are created in the translation unit's context, then moved | ||||||
4204 | // into the function declaration's context afterward. | ||||||
4205 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); | ||||||
4206 | |||||||
4207 | Error Err = Error::success(); | ||||||
4208 | auto ToDeclName = importChecked(Err, D->getDeclName()); | ||||||
4209 | auto ToLocation = importChecked(Err, D->getLocation()); | ||||||
4210 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); | ||||||
4211 | auto ToType = importChecked(Err, D->getType()); | ||||||
4212 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); | ||||||
4213 | if (Err) | ||||||
4214 | return std::move(Err); | ||||||
4215 | |||||||
4216 | ParmVarDecl *ToParm; | ||||||
4217 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, | ||||||
4218 | ToInnerLocStart, ToLocation, | ||||||
4219 | ToDeclName.getAsIdentifierInfo(), ToType, | ||||||
4220 | ToTypeSourceInfo, D->getStorageClass(), | ||||||
4221 | /*DefaultArg*/ nullptr)) | ||||||
4222 | return ToParm; | ||||||
4223 | |||||||
4224 | // Set the default argument. It should be no problem if it was already done. | ||||||
4225 | // Do not import the default expression before GetImportedOrCreateDecl call | ||||||
4226 | // to avoid possible infinite import loop because circular dependency. | ||||||
4227 | if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm)) | ||||||
4228 | return std::move(Err); | ||||||
4229 | |||||||
4230 | if (D->isObjCMethodParameter()) { | ||||||
4231 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); | ||||||
4232 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); | ||||||
4233 | } else { | ||||||
4234 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), | ||||||
4235 | D->getFunctionScopeIndex()); | ||||||
4236 | } | ||||||
4237 | |||||||
4238 | return ToParm; | ||||||
4239 | } | ||||||
4240 | |||||||
4241 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { | ||||||
4242 | // Import the major distinguishing characteristics of a method. | ||||||
4243 | DeclContext *DC, *LexicalDC; | ||||||
4244 | DeclarationName Name; | ||||||
4245 | SourceLocation Loc; | ||||||
4246 | NamedDecl *ToD; | ||||||
4247 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
4248 | return std::move(Err); | ||||||
4249 | if (ToD) | ||||||
4250 | return ToD; | ||||||
4251 | |||||||
4252 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||
4253 | for (auto *FoundDecl : FoundDecls) { | ||||||
4254 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { | ||||||
4255 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) | ||||||
4256 | continue; | ||||||
4257 | |||||||
4258 | // Check return types. | ||||||
4259 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), | ||||||
4260 | FoundMethod->getReturnType())) { | ||||||
4261 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent) | ||||||
4262 | << D->isInstanceMethod() << Name << D->getReturnType() | ||||||
4263 | << FoundMethod->getReturnType(); | ||||||
4264 | Importer.ToDiag(FoundMethod->getLocation(), | ||||||
4265 | diag::note_odr_objc_method_here) | ||||||
4266 | << D->isInstanceMethod() << Name; | ||||||
4267 | |||||||
4268 | return make_error<ImportError>(ImportError::NameConflict); | ||||||
4269 | } | ||||||
4270 | |||||||
4271 | // Check the number of parameters. | ||||||
4272 | if (D->param_size() != FoundMethod->param_size()) { | ||||||
4273 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent) | ||||||
4274 | << D->isInstanceMethod() << Name | ||||||
4275 | << D->param_size() << FoundMethod->param_size(); | ||||||
4276 | Importer.ToDiag(FoundMethod->getLocation(), | ||||||
4277 | diag::note_odr_objc_method_here) | ||||||
4278 | << D->isInstanceMethod() << Name; | ||||||
4279 | |||||||
4280 | return make_error<ImportError>(ImportError::NameConflict); | ||||||
4281 | } | ||||||
4282 | |||||||
4283 | // Check parameter types. | ||||||
4284 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), | ||||||
4285 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); | ||||||
4286 | P != PEnd; ++P, ++FoundP) { | ||||||
4287 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), | ||||||
4288 | (*FoundP)->getType())) { | ||||||
4289 | Importer.FromDiag((*P)->getLocation(), | ||||||
4290 | diag::warn_odr_objc_method_param_type_inconsistent) | ||||||
4291 | << D->isInstanceMethod() << Name | ||||||
4292 | << (*P)->getType() << (*FoundP)->getType(); | ||||||
4293 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) | ||||||
4294 | << (*FoundP)->getType(); | ||||||
4295 | |||||||
4296 | return make_error<ImportError>(ImportError::NameConflict); | ||||||
4297 | } | ||||||
4298 | } | ||||||
4299 | |||||||
4300 | // Check variadic/non-variadic. | ||||||
4301 | // Check the number of parameters. | ||||||
4302 | if (D->isVariadic() != FoundMethod->isVariadic()) { | ||||||
4303 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent) | ||||||
4304 | << D->isInstanceMethod() << Name; | ||||||
4305 | Importer.ToDiag(FoundMethod->getLocation(), | ||||||
4306 | diag::note_odr_objc_method_here) | ||||||
4307 | << D->isInstanceMethod() << Name; | ||||||
4308 | |||||||
4309 | return make_error<ImportError>(ImportError::NameConflict); | ||||||
4310 | } | ||||||
4311 | |||||||
4312 | // FIXME: Any other bits we need to merge? | ||||||
4313 | return Importer.MapImported(D, FoundMethod); | ||||||
4314 | } | ||||||
4315 | } | ||||||
4316 | |||||||
4317 | Error Err = Error::success(); | ||||||
4318 | auto ToEndLoc = importChecked(Err, D->getEndLoc()); | ||||||
4319 | auto ToReturnType = importChecked(Err, D->getReturnType()); | ||||||
4320 | auto ToReturnTypeSourceInfo = | ||||||
4321 | importChecked(Err, D->getReturnTypeSourceInfo()); | ||||||
4322 | if (Err) | ||||||
4323 | return std::move(Err); | ||||||
4324 | |||||||
4325 | ObjCMethodDecl *ToMethod; | ||||||
4326 | if (GetImportedOrCreateDecl( | ||||||
4327 | ToMethod, D, Importer.getToContext(), Loc, ToEndLoc, | ||||||
4328 | Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC, | ||||||
4329 | D->isInstanceMethod(), D->isVariadic(), D->isPropertyAccessor(), | ||||||
4330 | D->isSynthesizedAccessorStub(), D->isImplicit(), D->isDefined(), | ||||||
4331 | D->getImplementationControl(), D->hasRelatedResultType())) | ||||||
4332 | return ToMethod; | ||||||
4333 | |||||||
4334 | // FIXME: When we decide to merge method definitions, we'll need to | ||||||
4335 | // deal with implicit parameters. | ||||||
4336 | |||||||
4337 | // Import the parameters | ||||||
4338 | SmallVector<ParmVarDecl *, 5> ToParams; | ||||||
4339 | for (auto *FromP : D->parameters()) { | ||||||
4340 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) | ||||||
4341 | ToParams.push_back(*ToPOrErr); | ||||||
4342 | else | ||||||
4343 | return ToPOrErr.takeError(); | ||||||
4344 | } | ||||||
4345 | |||||||
4346 | // Set the parameters. | ||||||
4347 | for (auto *ToParam : ToParams) { | ||||||
4348 | ToParam->setOwningFunction(ToMethod); | ||||||
4349 | ToMethod->addDeclInternal(ToParam); | ||||||
4350 | } | ||||||
4351 | |||||||
4352 | SmallVector<SourceLocation, 12> FromSelLocs; | ||||||
4353 | D->getSelectorLocs(FromSelLocs); | ||||||
4354 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); | ||||||
4355 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) | ||||||
4356 | return std::move(Err); | ||||||
4357 | |||||||
4358 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); | ||||||
4359 | |||||||
4360 | ToMethod->setLexicalDeclContext(LexicalDC); | ||||||
4361 | LexicalDC->addDeclInternal(ToMethod); | ||||||
4362 | |||||||
4363 | // Implicit params are declared when Sema encounters the definition but this | ||||||
4364 | // never happens when the method is imported. Manually declare the implicit | ||||||
4365 | // params now that the MethodDecl knows its class interface. | ||||||
4366 | if (D->getSelfDecl()) | ||||||
4367 | ToMethod->createImplicitParams(Importer.getToContext(), | ||||||
4368 | ToMethod->getClassInterface()); | ||||||
4369 | |||||||
4370 | return ToMethod; | ||||||
4371 | } | ||||||
4372 | |||||||
4373 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { | ||||||
4374 | // Import the major distinguishing characteristics of a category. | ||||||
4375 | DeclContext *DC, *LexicalDC; | ||||||
4376 | DeclarationName Name; | ||||||
4377 | SourceLocation Loc; | ||||||
4378 | NamedDecl *ToD; | ||||||
4379 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
4380 | return std::move(Err); | ||||||
4381 | if (ToD) | ||||||
4382 | return ToD; | ||||||
4383 | |||||||
4384 | Error Err = Error::success(); | ||||||
4385 | auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc()); | ||||||
4386 | auto ToLocation = importChecked(Err, D->getLocation()); | ||||||
4387 | auto ToColonLoc = importChecked(Err, D->getColonLoc()); | ||||||
4388 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); | ||||||
4389 | if (Err) | ||||||
4390 | return std::move(Err); | ||||||
4391 | |||||||
4392 | ObjCTypeParamDecl *Result; | ||||||
4393 | if (GetImportedOrCreateDecl( | ||||||
4394 | Result, D, Importer.getToContext(), DC, D->getVariance(), | ||||||
4395 | ToVarianceLoc, D->getIndex(), | ||||||
4396 | ToLocation, Name.getAsIdentifierInfo(), | ||||||
4397 | ToColonLoc, ToTypeSourceInfo)) | ||||||
4398 | return Result; | ||||||
4399 | |||||||
4400 | Result->setLexicalDeclContext(LexicalDC); | ||||||
4401 | return Result; | ||||||
4402 | } | ||||||
4403 | |||||||
4404 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { | ||||||
4405 | // Import the major distinguishing characteristics of a category. | ||||||
4406 | DeclContext *DC, *LexicalDC; | ||||||
4407 | DeclarationName Name; | ||||||
4408 | SourceLocation Loc; | ||||||
4409 | NamedDecl *ToD; | ||||||
4410 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
4411 | return std::move(Err); | ||||||
4412 | if (ToD) | ||||||
4413 | return ToD; | ||||||
4414 | |||||||
4415 | ObjCInterfaceDecl *ToInterface; | ||||||
4416 | if (Error Err = importInto(ToInterface, D->getClassInterface())) | ||||||
4417 | return std::move(Err); | ||||||
4418 | |||||||
4419 | // Determine if we've already encountered this category. | ||||||
4420 | ObjCCategoryDecl *MergeWithCategory | ||||||
4421 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); | ||||||
4422 | ObjCCategoryDecl *ToCategory = MergeWithCategory; | ||||||
4423 | if (!ToCategory) { | ||||||
4424 | |||||||
4425 | Error Err = Error::success(); | ||||||
4426 | auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); | ||||||
4427 | auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc()); | ||||||
4428 | auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc()); | ||||||
4429 | auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc()); | ||||||
4430 | if (Err) | ||||||
4431 | return std::move(Err); | ||||||
4432 | |||||||
4433 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, | ||||||
4434 | ToAtStartLoc, Loc, | ||||||
4435 | ToCategoryNameLoc, | ||||||
4436 | Name.getAsIdentifierInfo(), ToInterface, | ||||||
4437 | /*TypeParamList=*/nullptr, | ||||||
4438 | ToIvarLBraceLoc, | ||||||
4439 | ToIvarRBraceLoc)) | ||||||
4440 | return ToCategory; | ||||||
4441 | |||||||
4442 | ToCategory->setLexicalDeclContext(LexicalDC); | ||||||
4443 | LexicalDC->addDeclInternal(ToCategory); | ||||||
4444 | // Import the type parameter list after MapImported, to avoid | ||||||
4445 | // loops when bringing in their DeclContext. | ||||||
4446 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) | ||||||
4447 | ToCategory->setTypeParamList(*PListOrErr); | ||||||
4448 | else | ||||||
4449 | return PListOrErr.takeError(); | ||||||
4450 | |||||||
4451 | // Import protocols | ||||||
4452 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | ||||||
4453 | SmallVector<SourceLocation, 4> ProtocolLocs; | ||||||
4454 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc | ||||||
4455 | = D->protocol_loc_begin(); | ||||||
4456 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), | ||||||
4457 | FromProtoEnd = D->protocol_end(); | ||||||
4458 | FromProto != FromProtoEnd; | ||||||
4459 | ++FromProto, ++FromProtoLoc) { | ||||||
4460 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | ||||||
4461 | Protocols.push_back(*ToProtoOrErr); | ||||||
4462 | else | ||||||
4463 | return ToProtoOrErr.takeError(); | ||||||
4464 | |||||||
4465 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | ||||||
4466 | ProtocolLocs.push_back(*ToProtoLocOrErr); | ||||||
4467 | else | ||||||
4468 | return ToProtoLocOrErr.takeError(); | ||||||
4469 | } | ||||||
4470 | |||||||
4471 | // FIXME: If we're merging, make sure that the protocol list is the same. | ||||||
4472 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), | ||||||
4473 | ProtocolLocs.data(), Importer.getToContext()); | ||||||
4474 | |||||||
4475 | } else { | ||||||
4476 | Importer.MapImported(D, ToCategory); | ||||||
4477 | } | ||||||
4478 | |||||||
4479 | // Import all of the members of this category. | ||||||
4480 | if (Error Err = ImportDeclContext(D)) | ||||||
4481 | return std::move(Err); | ||||||
4482 | |||||||
4483 | // If we have an implementation, import it as well. | ||||||
4484 | if (D->getImplementation()) { | ||||||
4485 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = | ||||||
4486 | import(D->getImplementation())) | ||||||
4487 | ToCategory->setImplementation(*ToImplOrErr); | ||||||
4488 | else | ||||||
4489 | return ToImplOrErr.takeError(); | ||||||
4490 | } | ||||||
4491 | |||||||
4492 | return ToCategory; | ||||||
4493 | } | ||||||
4494 | |||||||
4495 | Error ASTNodeImporter::ImportDefinition( | ||||||
4496 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { | ||||||
4497 | if (To->getDefinition()) { | ||||||
4498 | if (shouldForceImportDeclContext(Kind)) | ||||||
4499 | if (Error Err = ImportDeclContext(From)) | ||||||
4500 | return Err; | ||||||
4501 | return Error::success(); | ||||||
4502 | } | ||||||
4503 | |||||||
4504 | // Start the protocol definition | ||||||
4505 | To->startDefinition(); | ||||||
4506 | |||||||
4507 | // Import protocols | ||||||
4508 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | ||||||
4509 | SmallVector<SourceLocation, 4> ProtocolLocs; | ||||||
4510 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = | ||||||
4511 | From->protocol_loc_begin(); | ||||||
4512 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), | ||||||
4513 | FromProtoEnd = From->protocol_end(); | ||||||
4514 | FromProto != FromProtoEnd; | ||||||
4515 | ++FromProto, ++FromProtoLoc) { | ||||||
4516 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | ||||||
4517 | Protocols.push_back(*ToProtoOrErr); | ||||||
4518 | else | ||||||
4519 | return ToProtoOrErr.takeError(); | ||||||
4520 | |||||||
4521 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | ||||||
4522 | ProtocolLocs.push_back(*ToProtoLocOrErr); | ||||||
4523 | else | ||||||
4524 | return ToProtoLocOrErr.takeError(); | ||||||
4525 | |||||||
4526 | } | ||||||
4527 | |||||||
4528 | // FIXME: If we're merging, make sure that the protocol list is the same. | ||||||
4529 | To->setProtocolList(Protocols.data(), Protocols.size(), | ||||||
4530 | ProtocolLocs.data(), Importer.getToContext()); | ||||||
4531 | |||||||
4532 | if (shouldForceImportDeclContext(Kind)) { | ||||||
4533 | // Import all of the members of this protocol. | ||||||
4534 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | ||||||
4535 | return Err; | ||||||
4536 | } | ||||||
4537 | return Error::success(); | ||||||
4538 | } | ||||||
4539 | |||||||
4540 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { | ||||||
4541 | // If this protocol has a definition in the translation unit we're coming | ||||||
4542 | // from, but this particular declaration is not that definition, import the | ||||||
4543 | // definition and map to that. | ||||||
4544 | ObjCProtocolDecl *Definition = D->getDefinition(); | ||||||
4545 | if (Definition && Definition != D) { | ||||||
4546 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | ||||||
4547 | return Importer.MapImported(D, *ImportedDefOrErr); | ||||||
4548 | else | ||||||
4549 | return ImportedDefOrErr.takeError(); | ||||||
4550 | } | ||||||
4551 | |||||||
4552 | // Import the major distinguishing characteristics of a protocol. | ||||||
4553 | DeclContext *DC, *LexicalDC; | ||||||
4554 | DeclarationName Name; | ||||||
4555 | SourceLocation Loc; | ||||||
4556 | NamedDecl *ToD; | ||||||
4557 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
4558 | return std::move(Err); | ||||||
4559 | if (ToD) | ||||||
4560 | return ToD; | ||||||
4561 | |||||||
4562 | ObjCProtocolDecl *MergeWithProtocol = nullptr; | ||||||
4563 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||
4564 | for (auto *FoundDecl : FoundDecls) { | ||||||
4565 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) | ||||||
4566 | continue; | ||||||
4567 | |||||||
4568 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) | ||||||
4569 | break; | ||||||
4570 | } | ||||||
4571 | |||||||
4572 | ObjCProtocolDecl *ToProto = MergeWithProtocol; | ||||||
4573 | if (!ToProto) { | ||||||
4574 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); | ||||||
4575 | if (!ToAtBeginLocOrErr) | ||||||
4576 | return ToAtBeginLocOrErr.takeError(); | ||||||
4577 | |||||||
4578 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, | ||||||
4579 | Name.getAsIdentifierInfo(), Loc, | ||||||
4580 | *ToAtBeginLocOrErr, | ||||||
4581 | /*PrevDecl=*/nullptr)) | ||||||
4582 | return ToProto; | ||||||
4583 | ToProto->setLexicalDeclContext(LexicalDC); | ||||||
4584 | LexicalDC->addDeclInternal(ToProto); | ||||||
4585 | } | ||||||
4586 | |||||||
4587 | Importer.MapImported(D, ToProto); | ||||||
4588 | |||||||
4589 | if (D->isThisDeclarationADefinition()) | ||||||
4590 | if (Error Err = ImportDefinition(D, ToProto)) | ||||||
4591 | return std::move(Err); | ||||||
4592 | |||||||
4593 | return ToProto; | ||||||
4594 | } | ||||||
4595 | |||||||
4596 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { | ||||||
4597 | DeclContext *DC, *LexicalDC; | ||||||
4598 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | ||||||
4599 | return std::move(Err); | ||||||
4600 | |||||||
4601 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); | ||||||
4602 | if (!ExternLocOrErr) | ||||||
4603 | return ExternLocOrErr.takeError(); | ||||||
4604 | |||||||
4605 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); | ||||||
4606 | if (!LangLocOrErr) | ||||||
4607 | return LangLocOrErr.takeError(); | ||||||
4608 | |||||||
4609 | bool HasBraces = D->hasBraces(); | ||||||
4610 | |||||||
4611 | LinkageSpecDecl *ToLinkageSpec; | ||||||
4612 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, | ||||||
4613 | *ExternLocOrErr, *LangLocOrErr, | ||||||
4614 | D->getLanguage(), HasBraces)) | ||||||
4615 | return ToLinkageSpec; | ||||||
4616 | |||||||
4617 | if (HasBraces) { | ||||||
4618 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); | ||||||
4619 | if (!RBraceLocOrErr) | ||||||
4620 | return RBraceLocOrErr.takeError(); | ||||||
4621 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); | ||||||
4622 | } | ||||||
4623 | |||||||
4624 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); | ||||||
4625 | LexicalDC->addDeclInternal(ToLinkageSpec); | ||||||
4626 | |||||||
4627 | return ToLinkageSpec; | ||||||
4628 | } | ||||||
4629 | |||||||
4630 | ExpectedDecl ASTNodeImporter::ImportUsingShadowDecls(BaseUsingDecl *D, | ||||||
4631 | BaseUsingDecl *ToSI) { | ||||||
4632 | for (UsingShadowDecl *FromShadow : D->shadows()) { | ||||||
4633 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) | ||||||
4634 | ToSI->addShadowDecl(*ToShadowOrErr); | ||||||
4635 | else | ||||||
4636 | // FIXME: We return error here but the definition is already created | ||||||
4637 | // and available with lookups. How to fix this?.. | ||||||
4638 | return ToShadowOrErr.takeError(); | ||||||
4639 | } | ||||||
4640 | return ToSI; | ||||||
4641 | } | ||||||
4642 | |||||||
4643 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { | ||||||
4644 | DeclContext *DC, *LexicalDC; | ||||||
4645 | DeclarationName Name; | ||||||
4646 | SourceLocation Loc; | ||||||
4647 | NamedDecl *ToD = nullptr; | ||||||
4648 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
4649 | return std::move(Err); | ||||||
4650 | if (ToD) | ||||||
4651 | return ToD; | ||||||
4652 | |||||||
4653 | Error Err = Error::success(); | ||||||
4654 | auto ToLoc = importChecked(Err, D->getNameInfo().getLoc()); | ||||||
4655 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); | ||||||
4656 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | ||||||
4657 | if (Err) | ||||||
4658 | return std::move(Err); | ||||||
4659 | |||||||
4660 | DeclarationNameInfo NameInfo(Name, ToLoc); | ||||||
4661 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | ||||||
4662 | return std::move(Err); | ||||||
4663 | |||||||
4664 | UsingDecl *ToUsing; | ||||||
4665 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, | ||||||
4666 | ToUsingLoc, ToQualifierLoc, NameInfo, | ||||||
4667 | D->hasTypename())) | ||||||
4668 | return ToUsing; | ||||||
4669 | |||||||
4670 | ToUsing->setLexicalDeclContext(LexicalDC); | ||||||
4671 | LexicalDC->addDeclInternal(ToUsing); | ||||||
4672 | |||||||
4673 | if (NamedDecl *FromPattern = | ||||||
4674 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { | ||||||
4675 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) | ||||||
4676 | Importer.getToContext().setInstantiatedFromUsingDecl( | ||||||
4677 | ToUsing, *ToPatternOrErr); | ||||||
4678 | else | ||||||
4679 | return ToPatternOrErr.takeError(); | ||||||
4680 | } | ||||||
4681 | |||||||
4682 | return ImportUsingShadowDecls(D, ToUsing); | ||||||
4683 | } | ||||||
4684 | |||||||
4685 | ExpectedDecl ASTNodeImporter::VisitUsingEnumDecl(UsingEnumDecl *D) { | ||||||
4686 | DeclContext *DC, *LexicalDC; | ||||||
4687 | DeclarationName Name; | ||||||
4688 | SourceLocation Loc; | ||||||
4689 | NamedDecl *ToD = nullptr; | ||||||
4690 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
4691 | return std::move(Err); | ||||||
4692 | if (ToD) | ||||||
4693 | return ToD; | ||||||
4694 | |||||||
4695 | Error Err = Error::success(); | ||||||
4696 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); | ||||||
4697 | auto ToEnumLoc = importChecked(Err, D->getEnumLoc()); | ||||||
4698 | auto ToEnumDecl = importChecked(Err, D->getEnumDecl()); | ||||||
4699 | if (Err) | ||||||
4700 | return std::move(Err); | ||||||
4701 | |||||||
4702 | UsingEnumDecl *ToUsingEnum; | ||||||
4703 | if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC, | ||||||
4704 | ToUsingLoc, ToEnumLoc, Loc, ToEnumDecl)) | ||||||
4705 | return ToUsingEnum; | ||||||
4706 | |||||||
4707 | ToUsingEnum->setLexicalDeclContext(LexicalDC); | ||||||
4708 | LexicalDC->addDeclInternal(ToUsingEnum); | ||||||
4709 | |||||||
4710 | if (UsingEnumDecl *FromPattern = | ||||||
4711 | Importer.getFromContext().getInstantiatedFromUsingEnumDecl(D)) { | ||||||
4712 | if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern)) | ||||||
4713 | Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum, | ||||||
4714 | *ToPatternOrErr); | ||||||
4715 | else | ||||||
4716 | return ToPatternOrErr.takeError(); | ||||||
4717 | } | ||||||
4718 | |||||||
4719 | return ImportUsingShadowDecls(D, ToUsingEnum); | ||||||
4720 | } | ||||||
4721 | |||||||
4722 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { | ||||||
4723 | DeclContext *DC, *LexicalDC; | ||||||
4724 | DeclarationName Name; | ||||||
4725 | SourceLocation Loc; | ||||||
4726 | NamedDecl *ToD = nullptr; | ||||||
4727 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
4728 | return std::move(Err); | ||||||
4729 | if (ToD) | ||||||
4730 | return ToD; | ||||||
4731 | |||||||
4732 | Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer()); | ||||||
4733 | if (!ToIntroducerOrErr) | ||||||
4734 | return ToIntroducerOrErr.takeError(); | ||||||
4735 | |||||||
4736 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); | ||||||
4737 | if (!ToTargetOrErr) | ||||||
4738 | return ToTargetOrErr.takeError(); | ||||||
4739 | |||||||
4740 | UsingShadowDecl *ToShadow; | ||||||
4741 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, | ||||||
4742 | Name, *ToIntroducerOrErr, *ToTargetOrErr)) | ||||||
4743 | return ToShadow; | ||||||
4744 | |||||||
4745 | ToShadow->setLexicalDeclContext(LexicalDC); | ||||||
4746 | ToShadow->setAccess(D->getAccess()); | ||||||
4747 | |||||||
4748 | if (UsingShadowDecl *FromPattern = | ||||||
4749 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { | ||||||
4750 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) | ||||||
4751 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( | ||||||
4752 | ToShadow, *ToPatternOrErr); | ||||||
4753 | else | ||||||
4754 | // FIXME: We return error here but the definition is already created | ||||||
4755 | // and available with lookups. How to fix this?.. | ||||||
4756 | return ToPatternOrErr.takeError(); | ||||||
4757 | } | ||||||
4758 | |||||||
4759 | LexicalDC->addDeclInternal(ToShadow); | ||||||
4760 | |||||||
4761 | return ToShadow; | ||||||
4762 | } | ||||||
4763 | |||||||
4764 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { | ||||||
4765 | DeclContext *DC, *LexicalDC; | ||||||
4766 | DeclarationName Name; | ||||||
4767 | SourceLocation Loc; | ||||||
4768 | NamedDecl *ToD = nullptr; | ||||||
4769 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
4770 | return std::move(Err); | ||||||
4771 | if (ToD) | ||||||
4772 | return ToD; | ||||||
4773 | |||||||
4774 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); | ||||||
4775 | if (!ToComAncestorOrErr) | ||||||
4776 | return ToComAncestorOrErr.takeError(); | ||||||
4777 | |||||||
4778 | Error Err = Error::success(); | ||||||
4779 | auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace()); | ||||||
4780 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); | ||||||
4781 | auto ToNamespaceKeyLocation = | ||||||
4782 | importChecked(Err, D->getNamespaceKeyLocation()); | ||||||
4783 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | ||||||
4784 | auto ToIdentLocation = importChecked(Err, D->getIdentLocation()); | ||||||
4785 | if (Err) | ||||||
4786 | return std::move(Err); | ||||||
4787 | |||||||
4788 | UsingDirectiveDecl *ToUsingDir; | ||||||
4789 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, | ||||||
4790 | ToUsingLoc, | ||||||
4791 | ToNamespaceKeyLocation, | ||||||
4792 | ToQualifierLoc, | ||||||
4793 | ToIdentLocation, | ||||||
4794 | ToNominatedNamespace, *ToComAncestorOrErr)) | ||||||
4795 | return ToUsingDir; | ||||||
4796 | |||||||
4797 | ToUsingDir->setLexicalDeclContext(LexicalDC); | ||||||
4798 | LexicalDC->addDeclInternal(ToUsingDir); | ||||||
4799 | |||||||
4800 | return ToUsingDir; | ||||||
4801 | } | ||||||
4802 | |||||||
4803 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( | ||||||
4804 | UnresolvedUsingValueDecl *D) { | ||||||
4805 | DeclContext *DC, *LexicalDC; | ||||||
4806 | DeclarationName Name; | ||||||
4807 | SourceLocation Loc; | ||||||
4808 | NamedDecl *ToD = nullptr; | ||||||
4809 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
4810 | return std::move(Err); | ||||||
4811 | if (ToD) | ||||||
4812 | return ToD; | ||||||
4813 | |||||||
4814 | Error Err = Error::success(); | ||||||
4815 | auto ToLoc = importChecked(Err, D->getNameInfo().getLoc()); | ||||||
4816 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); | ||||||
4817 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | ||||||
4818 | auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc()); | ||||||
4819 | if (Err) | ||||||
4820 | return std::move(Err); | ||||||
4821 | |||||||
4822 | DeclarationNameInfo NameInfo(Name, ToLoc); | ||||||
4823 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | ||||||
4824 | return std::move(Err); | ||||||
4825 | |||||||
4826 | UnresolvedUsingValueDecl *ToUsingValue; | ||||||
4827 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, | ||||||
4828 | ToUsingLoc, ToQualifierLoc, NameInfo, | ||||||
4829 | ToEllipsisLoc)) | ||||||
4830 | return ToUsingValue; | ||||||
4831 | |||||||
4832 | ToUsingValue->setAccess(D->getAccess()); | ||||||
4833 | ToUsingValue->setLexicalDeclContext(LexicalDC); | ||||||
4834 | LexicalDC->addDeclInternal(ToUsingValue); | ||||||
4835 | |||||||
4836 | return ToUsingValue; | ||||||
4837 | } | ||||||
4838 | |||||||
4839 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( | ||||||
4840 | UnresolvedUsingTypenameDecl *D) { | ||||||
4841 | DeclContext *DC, *LexicalDC; | ||||||
4842 | DeclarationName Name; | ||||||
4843 | SourceLocation Loc; | ||||||
4844 | NamedDecl *ToD = nullptr; | ||||||
4845 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
4846 | return std::move(Err); | ||||||
4847 | if (ToD) | ||||||
4848 | return ToD; | ||||||
4849 | |||||||
4850 | Error Err = Error::success(); | ||||||
4851 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); | ||||||
4852 | auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc()); | ||||||
4853 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | ||||||
4854 | auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc()); | ||||||
4855 | if (Err) | ||||||
4856 | return std::move(Err); | ||||||
4857 | |||||||
4858 | UnresolvedUsingTypenameDecl *ToUsing; | ||||||
4859 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, | ||||||
4860 | ToUsingLoc, ToTypenameLoc, | ||||||
4861 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) | ||||||
4862 | return ToUsing; | ||||||
4863 | |||||||
4864 | ToUsing->setAccess(D->getAccess()); | ||||||
4865 | ToUsing->setLexicalDeclContext(LexicalDC); | ||||||
4866 | LexicalDC->addDeclInternal(ToUsing); | ||||||
4867 | |||||||
4868 | return ToUsing; | ||||||
4869 | } | ||||||
4870 | |||||||
4871 | ExpectedDecl ASTNodeImporter::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) { | ||||||
4872 | Decl* ToD = nullptr; | ||||||
4873 | switch (D->getBuiltinTemplateKind()) { | ||||||
4874 | case BuiltinTemplateKind::BTK__make_integer_seq: | ||||||
4875 | ToD = Importer.getToContext().getMakeIntegerSeqDecl(); | ||||||
4876 | break; | ||||||
4877 | case BuiltinTemplateKind::BTK__type_pack_element: | ||||||
4878 | ToD = Importer.getToContext().getTypePackElementDecl(); | ||||||
4879 | break; | ||||||
4880 | } | ||||||
4881 | assert(ToD && "BuiltinTemplateDecl of unsupported kind!")(static_cast <bool> (ToD && "BuiltinTemplateDecl of unsupported kind!" ) ? void (0) : __assert_fail ("ToD && \"BuiltinTemplateDecl of unsupported kind!\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 4881, __extension__ __PRETTY_FUNCTION__)); | ||||||
4882 | Importer.MapImported(D, ToD); | ||||||
4883 | return ToD; | ||||||
4884 | } | ||||||
4885 | |||||||
4886 | Error ASTNodeImporter::ImportDefinition( | ||||||
4887 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { | ||||||
4888 | if (To->getDefinition()) { | ||||||
4889 | // Check consistency of superclass. | ||||||
4890 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); | ||||||
4891 | if (FromSuper) { | ||||||
4892 | if (auto FromSuperOrErr = import(FromSuper)) | ||||||
4893 | FromSuper = *FromSuperOrErr; | ||||||
4894 | else | ||||||
4895 | return FromSuperOrErr.takeError(); | ||||||
4896 | } | ||||||
4897 | |||||||
4898 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); | ||||||
4899 | if ((bool)FromSuper != (bool)ToSuper || | ||||||
4900 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { | ||||||
4901 | Importer.ToDiag(To->getLocation(), | ||||||
4902 | diag::warn_odr_objc_superclass_inconsistent) | ||||||
4903 | << To->getDeclName(); | ||||||
4904 | if (ToSuper) | ||||||
4905 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) | ||||||
4906 | << To->getSuperClass()->getDeclName(); | ||||||
4907 | else | ||||||
4908 | Importer.ToDiag(To->getLocation(), | ||||||
4909 | diag::note_odr_objc_missing_superclass); | ||||||
4910 | if (From->getSuperClass()) | ||||||
4911 | Importer.FromDiag(From->getSuperClassLoc(), | ||||||
4912 | diag::note_odr_objc_superclass) | ||||||
4913 | << From->getSuperClass()->getDeclName(); | ||||||
4914 | else | ||||||
4915 | Importer.FromDiag(From->getLocation(), | ||||||
4916 | diag::note_odr_objc_missing_superclass); | ||||||
4917 | } | ||||||
4918 | |||||||
4919 | if (shouldForceImportDeclContext(Kind)) | ||||||
4920 | if (Error Err = ImportDeclContext(From)) | ||||||
4921 | return Err; | ||||||
4922 | return Error::success(); | ||||||
4923 | } | ||||||
4924 | |||||||
4925 | // Start the definition. | ||||||
4926 | To->startDefinition(); | ||||||
4927 | |||||||
4928 | // If this class has a superclass, import it. | ||||||
4929 | if (From->getSuperClass()) { | ||||||
4930 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) | ||||||
4931 | To->setSuperClass(*SuperTInfoOrErr); | ||||||
4932 | else | ||||||
4933 | return SuperTInfoOrErr.takeError(); | ||||||
4934 | } | ||||||
4935 | |||||||
4936 | // Import protocols | ||||||
4937 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | ||||||
4938 | SmallVector<SourceLocation, 4> ProtocolLocs; | ||||||
4939 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = | ||||||
4940 | From->protocol_loc_begin(); | ||||||
4941 | |||||||
4942 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), | ||||||
4943 | FromProtoEnd = From->protocol_end(); | ||||||
4944 | FromProto != FromProtoEnd; | ||||||
4945 | ++FromProto, ++FromProtoLoc) { | ||||||
4946 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | ||||||
4947 | Protocols.push_back(*ToProtoOrErr); | ||||||
4948 | else | ||||||
4949 | return ToProtoOrErr.takeError(); | ||||||
4950 | |||||||
4951 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | ||||||
4952 | ProtocolLocs.push_back(*ToProtoLocOrErr); | ||||||
4953 | else | ||||||
4954 | return ToProtoLocOrErr.takeError(); | ||||||
4955 | |||||||
4956 | } | ||||||
4957 | |||||||
4958 | // FIXME: If we're merging, make sure that the protocol list is the same. | ||||||
4959 | To->setProtocolList(Protocols.data(), Protocols.size(), | ||||||
4960 | ProtocolLocs.data(), Importer.getToContext()); | ||||||
4961 | |||||||
4962 | // Import categories. When the categories themselves are imported, they'll | ||||||
4963 | // hook themselves into this interface. | ||||||
4964 | for (auto *Cat : From->known_categories()) { | ||||||
4965 | auto ToCatOrErr = import(Cat); | ||||||
4966 | if (!ToCatOrErr) | ||||||
4967 | return ToCatOrErr.takeError(); | ||||||
4968 | } | ||||||
4969 | |||||||
4970 | // If we have an @implementation, import it as well. | ||||||
4971 | if (From->getImplementation()) { | ||||||
4972 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = | ||||||
4973 | import(From->getImplementation())) | ||||||
4974 | To->setImplementation(*ToImplOrErr); | ||||||
4975 | else | ||||||
4976 | return ToImplOrErr.takeError(); | ||||||
4977 | } | ||||||
4978 | |||||||
4979 | // Import all of the members of this class. | ||||||
4980 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | ||||||
4981 | return Err; | ||||||
4982 | |||||||
4983 | return Error::success(); | ||||||
4984 | } | ||||||
4985 | |||||||
4986 | Expected<ObjCTypeParamList *> | ||||||
4987 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { | ||||||
4988 | if (!list) | ||||||
4989 | return nullptr; | ||||||
4990 | |||||||
4991 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; | ||||||
4992 | for (auto *fromTypeParam : *list) { | ||||||
4993 | if (auto toTypeParamOrErr = import(fromTypeParam)) | ||||||
4994 | toTypeParams.push_back(*toTypeParamOrErr); | ||||||
4995 | else | ||||||
4996 | return toTypeParamOrErr.takeError(); | ||||||
4997 | } | ||||||
4998 | |||||||
4999 | auto LAngleLocOrErr = import(list->getLAngleLoc()); | ||||||
5000 | if (!LAngleLocOrErr) | ||||||
5001 | return LAngleLocOrErr.takeError(); | ||||||
5002 | |||||||
5003 | auto RAngleLocOrErr = import(list->getRAngleLoc()); | ||||||
5004 | if (!RAngleLocOrErr) | ||||||
5005 | return RAngleLocOrErr.takeError(); | ||||||
5006 | |||||||
5007 | return ObjCTypeParamList::create(Importer.getToContext(), | ||||||
5008 | *LAngleLocOrErr, | ||||||
5009 | toTypeParams, | ||||||
5010 | *RAngleLocOrErr); | ||||||
5011 | } | ||||||
5012 | |||||||
5013 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { | ||||||
5014 | // If this class has a definition in the translation unit we're coming from, | ||||||
5015 | // but this particular declaration is not that definition, import the | ||||||
5016 | // definition and map to that. | ||||||
5017 | ObjCInterfaceDecl *Definition = D->getDefinition(); | ||||||
5018 | if (Definition && Definition != D) { | ||||||
5019 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | ||||||
5020 | return Importer.MapImported(D, *ImportedDefOrErr); | ||||||
5021 | else | ||||||
5022 | return ImportedDefOrErr.takeError(); | ||||||
5023 | } | ||||||
5024 | |||||||
5025 | // Import the major distinguishing characteristics of an @interface. | ||||||
5026 | DeclContext *DC, *LexicalDC; | ||||||
5027 | DeclarationName Name; | ||||||
5028 | SourceLocation Loc; | ||||||
5029 | NamedDecl *ToD; | ||||||
5030 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
5031 | return std::move(Err); | ||||||
5032 | if (ToD) | ||||||
5033 | return ToD; | ||||||
5034 | |||||||
5035 | // Look for an existing interface with the same name. | ||||||
5036 | ObjCInterfaceDecl *MergeWithIface = nullptr; | ||||||
5037 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||
5038 | for (auto *FoundDecl : FoundDecls) { | ||||||
5039 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) | ||||||
5040 | continue; | ||||||
5041 | |||||||
5042 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) | ||||||
5043 | break; | ||||||
5044 | } | ||||||
5045 | |||||||
5046 | // Create an interface declaration, if one does not already exist. | ||||||
5047 | ObjCInterfaceDecl *ToIface = MergeWithIface; | ||||||
5048 | if (!ToIface) { | ||||||
5049 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); | ||||||
5050 | if (!AtBeginLocOrErr) | ||||||
5051 | return AtBeginLocOrErr.takeError(); | ||||||
5052 | |||||||
5053 | if (GetImportedOrCreateDecl( | ||||||
5054 | ToIface, D, Importer.getToContext(), DC, | ||||||
5055 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), | ||||||
5056 | /*TypeParamList=*/nullptr, | ||||||
5057 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) | ||||||
5058 | return ToIface; | ||||||
5059 | ToIface->setLexicalDeclContext(LexicalDC); | ||||||
5060 | LexicalDC->addDeclInternal(ToIface); | ||||||
5061 | } | ||||||
5062 | Importer.MapImported(D, ToIface); | ||||||
5063 | // Import the type parameter list after MapImported, to avoid | ||||||
5064 | // loops when bringing in their DeclContext. | ||||||
5065 | if (auto ToPListOrErr = | ||||||
5066 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) | ||||||
5067 | ToIface->setTypeParamList(*ToPListOrErr); | ||||||
5068 | else | ||||||
5069 | return ToPListOrErr.takeError(); | ||||||
5070 | |||||||
5071 | if (D->isThisDeclarationADefinition()) | ||||||
5072 | if (Error Err = ImportDefinition(D, ToIface)) | ||||||
5073 | return std::move(Err); | ||||||
5074 | |||||||
5075 | return ToIface; | ||||||
5076 | } | ||||||
5077 | |||||||
5078 | ExpectedDecl | ||||||
5079 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { | ||||||
5080 | ObjCCategoryDecl *Category; | ||||||
5081 | if (Error Err = importInto(Category, D->getCategoryDecl())) | ||||||
5082 | return std::move(Err); | ||||||
5083 | |||||||
5084 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); | ||||||
5085 | if (!ToImpl) { | ||||||
5086 | DeclContext *DC, *LexicalDC; | ||||||
5087 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | ||||||
5088 | return std::move(Err); | ||||||
5089 | |||||||
5090 | Error Err = Error::success(); | ||||||
5091 | auto ToLocation = importChecked(Err, D->getLocation()); | ||||||
5092 | auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); | ||||||
5093 | auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc()); | ||||||
5094 | if (Err) | ||||||
5095 | return std::move(Err); | ||||||
5096 | |||||||
5097 | if (GetImportedOrCreateDecl( | ||||||
5098 | ToImpl, D, Importer.getToContext(), DC, | ||||||
5099 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), | ||||||
5100 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) | ||||||
5101 | return ToImpl; | ||||||
5102 | |||||||
5103 | ToImpl->setLexicalDeclContext(LexicalDC); | ||||||
5104 | LexicalDC->addDeclInternal(ToImpl); | ||||||
5105 | Category->setImplementation(ToImpl); | ||||||
5106 | } | ||||||
5107 | |||||||
5108 | Importer.MapImported(D, ToImpl); | ||||||
5109 | if (Error Err = ImportDeclContext(D)) | ||||||
5110 | return std::move(Err); | ||||||
5111 | |||||||
5112 | return ToImpl; | ||||||
5113 | } | ||||||
5114 | |||||||
5115 | ExpectedDecl | ||||||
5116 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { | ||||||
5117 | // Find the corresponding interface. | ||||||
5118 | ObjCInterfaceDecl *Iface; | ||||||
5119 | if (Error Err = importInto(Iface, D->getClassInterface())) | ||||||
5120 | return std::move(Err); | ||||||
5121 | |||||||
5122 | // Import the superclass, if any. | ||||||
5123 | ObjCInterfaceDecl *Super; | ||||||
5124 | if (Error Err = importInto(Super, D->getSuperClass())) | ||||||
5125 | return std::move(Err); | ||||||
5126 | |||||||
5127 | ObjCImplementationDecl *Impl = Iface->getImplementation(); | ||||||
5128 | if (!Impl) { | ||||||
5129 | // We haven't imported an implementation yet. Create a new @implementation | ||||||
5130 | // now. | ||||||
5131 | DeclContext *DC, *LexicalDC; | ||||||
5132 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | ||||||
5133 | return std::move(Err); | ||||||
5134 | |||||||
5135 | Error Err = Error::success(); | ||||||
5136 | auto ToLocation = importChecked(Err, D->getLocation()); | ||||||
5137 | auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); | ||||||
5138 | auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc()); | ||||||
5139 | auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc()); | ||||||
5140 | auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc()); | ||||||
5141 | if (Err) | ||||||
5142 | return std::move(Err); | ||||||
5143 | |||||||
5144 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), | ||||||
5145 | DC, Iface, Super, | ||||||
5146 | ToLocation, | ||||||
5147 | ToAtStartLoc, | ||||||
5148 | ToSuperClassLoc, | ||||||
5149 | ToIvarLBraceLoc, | ||||||
5150 | ToIvarRBraceLoc)) | ||||||
5151 | return Impl; | ||||||
5152 | |||||||
5153 | Impl->setLexicalDeclContext(LexicalDC); | ||||||
5154 | |||||||
5155 | // Associate the implementation with the class it implements. | ||||||
5156 | Iface->setImplementation(Impl); | ||||||
5157 | Importer.MapImported(D, Iface->getImplementation()); | ||||||
5158 | } else { | ||||||
5159 | Importer.MapImported(D, Iface->getImplementation()); | ||||||
5160 | |||||||
5161 | // Verify that the existing @implementation has the same superclass. | ||||||
5162 | if ((Super && !Impl->getSuperClass()) || | ||||||
5163 | (!Super && Impl->getSuperClass()) || | ||||||
5164 | (Super && Impl->getSuperClass() && | ||||||
5165 | !declaresSameEntity(Super->getCanonicalDecl(), | ||||||
5166 | Impl->getSuperClass()))) { | ||||||
5167 | Importer.ToDiag(Impl->getLocation(), | ||||||
5168 | diag::warn_odr_objc_superclass_inconsistent) | ||||||
5169 | << Iface->getDeclName(); | ||||||
5170 | // FIXME: It would be nice to have the location of the superclass | ||||||
5171 | // below. | ||||||
5172 | if (Impl->getSuperClass()) | ||||||
5173 | Importer.ToDiag(Impl->getLocation(), | ||||||
5174 | diag::note_odr_objc_superclass) | ||||||
5175 | << Impl->getSuperClass()->getDeclName(); | ||||||
5176 | else | ||||||
5177 | Importer.ToDiag(Impl->getLocation(), | ||||||
5178 | diag::note_odr_objc_missing_superclass); | ||||||
5179 | if (D->getSuperClass()) | ||||||
5180 | Importer.FromDiag(D->getLocation(), | ||||||
5181 | diag::note_odr_objc_superclass) | ||||||
5182 | << D->getSuperClass()->getDeclName(); | ||||||
5183 | else | ||||||
5184 | Importer.FromDiag(D->getLocation(), | ||||||
5185 | diag::note_odr_objc_missing_superclass); | ||||||
5186 | |||||||
5187 | return make_error<ImportError>(ImportError::NameConflict); | ||||||
5188 | } | ||||||
5189 | } | ||||||
5190 | |||||||
5191 | // Import all of the members of this @implementation. | ||||||
5192 | if (Error Err = ImportDeclContext(D)) | ||||||
5193 | return std::move(Err); | ||||||
5194 | |||||||
5195 | return Impl; | ||||||
5196 | } | ||||||
5197 | |||||||
5198 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { | ||||||
5199 | // Import the major distinguishing characteristics of an @property. | ||||||
5200 | DeclContext *DC, *LexicalDC; | ||||||
5201 | DeclarationName Name; | ||||||
5202 | SourceLocation Loc; | ||||||
5203 | NamedDecl *ToD; | ||||||
5204 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
5205 | return std::move(Err); | ||||||
5206 | if (ToD) | ||||||
5207 | return ToD; | ||||||
5208 | |||||||
5209 | // Check whether we have already imported this property. | ||||||
5210 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||
5211 | for (auto *FoundDecl : FoundDecls) { | ||||||
5212 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { | ||||||
5213 | // Instance and class properties can share the same name but are different | ||||||
5214 | // declarations. | ||||||
5215 | if (FoundProp->isInstanceProperty() != D->isInstanceProperty()) | ||||||
5216 | continue; | ||||||
5217 | |||||||
5218 | // Check property types. | ||||||
5219 | if (!Importer.IsStructurallyEquivalent(D->getType(), | ||||||
5220 | FoundProp->getType())) { | ||||||
5221 | Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent) | ||||||
5222 | << Name << D->getType() << FoundProp->getType(); | ||||||
5223 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) | ||||||
5224 | << FoundProp->getType(); | ||||||
5225 | |||||||
5226 | return make_error<ImportError>(ImportError::NameConflict); | ||||||
5227 | } | ||||||
5228 | |||||||
5229 | // FIXME: Check property attributes, getters, setters, etc.? | ||||||
5230 | |||||||
5231 | // Consider these properties to be equivalent. | ||||||
5232 | Importer.MapImported(D, FoundProp); | ||||||
5233 | return FoundProp; | ||||||
5234 | } | ||||||
5235 | } | ||||||
5236 | |||||||
5237 | Error Err = Error::success(); | ||||||
5238 | auto ToType = importChecked(Err, D->getType()); | ||||||
5239 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); | ||||||
5240 | auto ToAtLoc = importChecked(Err, D->getAtLoc()); | ||||||
5241 | auto ToLParenLoc = importChecked(Err, D->getLParenLoc()); | ||||||
5242 | if (Err) | ||||||
5243 | return std::move(Err); | ||||||
5244 | |||||||
5245 | // Create the new property. | ||||||
5246 | ObjCPropertyDecl *ToProperty; | ||||||
5247 | if (GetImportedOrCreateDecl( | ||||||
5248 | ToProperty, D, Importer.getToContext(), DC, Loc, | ||||||
5249 | Name.getAsIdentifierInfo(), ToAtLoc, | ||||||
5250 | ToLParenLoc, ToType, | ||||||
5251 | ToTypeSourceInfo, D->getPropertyImplementation())) | ||||||
5252 | return ToProperty; | ||||||
5253 | |||||||
5254 | auto ToGetterName = importChecked(Err, D->getGetterName()); | ||||||
5255 | auto ToSetterName = importChecked(Err, D->getSetterName()); | ||||||
5256 | auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc()); | ||||||
5257 | auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc()); | ||||||
5258 | auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl()); | ||||||
5259 | auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl()); | ||||||
5260 | auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl()); | ||||||
5261 | if (Err) | ||||||
5262 | return std::move(Err); | ||||||
5263 | |||||||
5264 | ToProperty->setLexicalDeclContext(LexicalDC); | ||||||
5265 | LexicalDC->addDeclInternal(ToProperty); | ||||||
5266 | |||||||
5267 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); | ||||||
5268 | ToProperty->setPropertyAttributesAsWritten( | ||||||
5269 | D->getPropertyAttributesAsWritten()); | ||||||
5270 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); | ||||||
5271 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); | ||||||
5272 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); | ||||||
5273 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); | ||||||
5274 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); | ||||||
5275 | return ToProperty; | ||||||
5276 | } | ||||||
5277 | |||||||
5278 | ExpectedDecl | ||||||
5279 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { | ||||||
5280 | ObjCPropertyDecl *Property; | ||||||
5281 | if (Error Err = importInto(Property, D->getPropertyDecl())) | ||||||
5282 | return std::move(Err); | ||||||
5283 | |||||||
5284 | DeclContext *DC, *LexicalDC; | ||||||
5285 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | ||||||
5286 | return std::move(Err); | ||||||
5287 | |||||||
5288 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); | ||||||
5289 | |||||||
5290 | // Import the ivar (for an @synthesize). | ||||||
5291 | ObjCIvarDecl *Ivar = nullptr; | ||||||
5292 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) | ||||||
5293 | return std::move(Err); | ||||||
5294 | |||||||
5295 | ObjCPropertyImplDecl *ToImpl | ||||||
5296 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), | ||||||
5297 | Property->getQueryKind()); | ||||||
5298 | if (!ToImpl) { | ||||||
5299 | |||||||
5300 | Error Err = Error::success(); | ||||||
5301 | auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); | ||||||
5302 | auto ToLocation = importChecked(Err, D->getLocation()); | ||||||
5303 | auto ToPropertyIvarDeclLoc = | ||||||
5304 | importChecked(Err, D->getPropertyIvarDeclLoc()); | ||||||
5305 | if (Err) | ||||||
5306 | return std::move(Err); | ||||||
5307 | |||||||
5308 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, | ||||||
5309 | ToBeginLoc, | ||||||
5310 | ToLocation, Property, | ||||||
5311 | D->getPropertyImplementation(), Ivar, | ||||||
5312 | ToPropertyIvarDeclLoc)) | ||||||
5313 | return ToImpl; | ||||||
5314 | |||||||
5315 | ToImpl->setLexicalDeclContext(LexicalDC); | ||||||
5316 | LexicalDC->addDeclInternal(ToImpl); | ||||||
5317 | } else { | ||||||
5318 | // Check that we have the same kind of property implementation (@synthesize | ||||||
5319 | // vs. @dynamic). | ||||||
5320 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { | ||||||
5321 | Importer.ToDiag(ToImpl->getLocation(), | ||||||
5322 | diag::warn_odr_objc_property_impl_kind_inconsistent) | ||||||
5323 | << Property->getDeclName() | ||||||
5324 | << (ToImpl->getPropertyImplementation() | ||||||
5325 | == ObjCPropertyImplDecl::Dynamic); | ||||||
5326 | Importer.FromDiag(D->getLocation(), | ||||||
5327 | diag::note_odr_objc_property_impl_kind) | ||||||
5328 | << D->getPropertyDecl()->getDeclName() | ||||||
5329 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); | ||||||
5330 | |||||||
5331 | return make_error<ImportError>(ImportError::NameConflict); | ||||||
5332 | } | ||||||
5333 | |||||||
5334 | // For @synthesize, check that we have the same | ||||||
5335 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && | ||||||
5336 | Ivar != ToImpl->getPropertyIvarDecl()) { | ||||||
5337 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), | ||||||
5338 | diag::warn_odr_objc_synthesize_ivar_inconsistent) | ||||||
5339 | << Property->getDeclName() | ||||||
5340 | << ToImpl->getPropertyIvarDecl()->getDeclName() | ||||||
5341 | << Ivar->getDeclName(); | ||||||
5342 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), | ||||||
5343 | diag::note_odr_objc_synthesize_ivar_here) | ||||||
5344 | << D->getPropertyIvarDecl()->getDeclName(); | ||||||
5345 | |||||||
5346 | return make_error<ImportError>(ImportError::NameConflict); | ||||||
5347 | } | ||||||
5348 | |||||||
5349 | // Merge the existing implementation with the new implementation. | ||||||
5350 | Importer.MapImported(D, ToImpl); | ||||||
5351 | } | ||||||
5352 | |||||||
5353 | return ToImpl; | ||||||
5354 | } | ||||||
5355 | |||||||
5356 | ExpectedDecl | ||||||
5357 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { | ||||||
5358 | // For template arguments, we adopt the translation unit as our declaration | ||||||
5359 | // context. This context will be fixed when the actual template declaration | ||||||
5360 | // is created. | ||||||
5361 | |||||||
5362 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | ||||||
5363 | if (!BeginLocOrErr) | ||||||
5364 | return BeginLocOrErr.takeError(); | ||||||
5365 | |||||||
5366 | ExpectedSLoc LocationOrErr = import(D->getLocation()); | ||||||
5367 | if (!LocationOrErr) | ||||||
5368 | return LocationOrErr.takeError(); | ||||||
5369 | |||||||
5370 | TemplateTypeParmDecl *ToD = nullptr; | ||||||
5371 | if (GetImportedOrCreateDecl( | ||||||
5372 | ToD, D, Importer.getToContext(), | ||||||
5373 | Importer.getToContext().getTranslationUnitDecl(), | ||||||
5374 | *BeginLocOrErr, *LocationOrErr, | ||||||
5375 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), | ||||||
5376 | D->wasDeclaredWithTypename(), D->isParameterPack(), | ||||||
5377 | D->hasTypeConstraint())) | ||||||
5378 | return ToD; | ||||||
5379 | |||||||
5380 | // Import the type-constraint | ||||||
5381 | if (const TypeConstraint *TC = D->getTypeConstraint()) { | ||||||
5382 | |||||||
5383 | Error Err = Error::success(); | ||||||
5384 | auto ToNNS = importChecked(Err, TC->getNestedNameSpecifierLoc()); | ||||||
5385 | auto ToName = importChecked(Err, TC->getConceptNameInfo().getName()); | ||||||
5386 | auto ToNameLoc = importChecked(Err, TC->getConceptNameInfo().getLoc()); | ||||||
5387 | auto ToFoundDecl = importChecked(Err, TC->getFoundDecl()); | ||||||
5388 | auto ToNamedConcept = importChecked(Err, TC->getNamedConcept()); | ||||||
5389 | auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint()); | ||||||
5390 | if (Err) | ||||||
5391 | return std::move(Err); | ||||||
5392 | |||||||
5393 | TemplateArgumentListInfo ToTAInfo; | ||||||
5394 | const auto *ASTTemplateArgs = TC->getTemplateArgsAsWritten(); | ||||||
5395 | if (ASTTemplateArgs) | ||||||
5396 | if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, | ||||||
5397 | ToTAInfo)) | ||||||
5398 | return std::move(Err); | ||||||
5399 | |||||||
5400 | ToD->setTypeConstraint(ToNNS, DeclarationNameInfo(ToName, ToNameLoc), | ||||||
5401 | ToFoundDecl, ToNamedConcept, | ||||||
5402 | ASTTemplateArgs ? | ||||||
5403 | ASTTemplateArgumentListInfo::Create(Importer.getToContext(), | ||||||
5404 | ToTAInfo) : nullptr, | ||||||
5405 | ToIDC); | ||||||
5406 | } | ||||||
5407 | |||||||
5408 | if (D->hasDefaultArgument()) { | ||||||
5409 | Expected<TypeSourceInfo *> ToDefaultArgOrErr = | ||||||
5410 | import(D->getDefaultArgumentInfo()); | ||||||
5411 | if (!ToDefaultArgOrErr) | ||||||
5412 | return ToDefaultArgOrErr.takeError(); | ||||||
5413 | ToD->setDefaultArgument(*ToDefaultArgOrErr); | ||||||
5414 | } | ||||||
5415 | |||||||
5416 | return ToD; | ||||||
5417 | } | ||||||
5418 | |||||||
5419 | ExpectedDecl | ||||||
5420 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { | ||||||
5421 | |||||||
5422 | Error Err = Error::success(); | ||||||
5423 | auto ToDeclName = importChecked(Err, D->getDeclName()); | ||||||
5424 | auto ToLocation = importChecked(Err, D->getLocation()); | ||||||
5425 | auto ToType = importChecked(Err, D->getType()); | ||||||
5426 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); | ||||||
5427 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); | ||||||
5428 | if (Err) | ||||||
5429 | return std::move(Err); | ||||||
5430 | |||||||
5431 | NonTypeTemplateParmDecl *ToD = nullptr; | ||||||
5432 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), | ||||||
5433 | Importer.getToContext().getTranslationUnitDecl(), | ||||||
5434 | ToInnerLocStart, ToLocation, D->getDepth(), | ||||||
5435 | D->getPosition(), | ||||||
5436 | ToDeclName.getAsIdentifierInfo(), ToType, | ||||||
5437 | D->isParameterPack(), ToTypeSourceInfo)) | ||||||
5438 | return ToD; | ||||||
5439 | |||||||
5440 | if (D->hasDefaultArgument()) { | ||||||
5441 | ExpectedExpr ToDefaultArgOrErr = import(D->getDefaultArgument()); | ||||||
5442 | if (!ToDefaultArgOrErr) | ||||||
5443 | return ToDefaultArgOrErr.takeError(); | ||||||
5444 | ToD->setDefaultArgument(*ToDefaultArgOrErr); | ||||||
5445 | } | ||||||
5446 | |||||||
5447 | return ToD; | ||||||
5448 | } | ||||||
5449 | |||||||
5450 | ExpectedDecl | ||||||
5451 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { | ||||||
5452 | // Import the name of this declaration. | ||||||
5453 | auto NameOrErr = import(D->getDeclName()); | ||||||
5454 | if (!NameOrErr) | ||||||
5455 | return NameOrErr.takeError(); | ||||||
5456 | |||||||
5457 | // Import the location of this declaration. | ||||||
5458 | ExpectedSLoc LocationOrErr = import(D->getLocation()); | ||||||
5459 | if (!LocationOrErr) | ||||||
5460 | return LocationOrErr.takeError(); | ||||||
5461 | |||||||
5462 | // Import template parameters. | ||||||
5463 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); | ||||||
5464 | if (!TemplateParamsOrErr) | ||||||
5465 | return TemplateParamsOrErr.takeError(); | ||||||
5466 | |||||||
5467 | TemplateTemplateParmDecl *ToD = nullptr; | ||||||
5468 | if (GetImportedOrCreateDecl( | ||||||
5469 | ToD, D, Importer.getToContext(), | ||||||
5470 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, | ||||||
5471 | D->getDepth(), D->getPosition(), D->isParameterPack(), | ||||||
5472 | (*NameOrErr).getAsIdentifierInfo(), *TemplateParamsOrErr)) | ||||||
5473 | return ToD; | ||||||
5474 | |||||||
5475 | if (D->hasDefaultArgument()) { | ||||||
5476 | Expected<TemplateArgumentLoc> ToDefaultArgOrErr = | ||||||
5477 | import(D->getDefaultArgument()); | ||||||
5478 | if (!ToDefaultArgOrErr) | ||||||
5479 | return ToDefaultArgOrErr.takeError(); | ||||||
5480 | ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr); | ||||||
5481 | } | ||||||
5482 | |||||||
5483 | return ToD; | ||||||
5484 | } | ||||||
5485 | |||||||
5486 | // Returns the definition for a (forward) declaration of a TemplateDecl, if | ||||||
5487 | // it has any definition in the redecl chain. | ||||||
5488 | template <typename T> static auto getTemplateDefinition(T *D) -> T * { | ||||||
5489 | 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\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 5489, __extension__ __PRETTY_FUNCTION__)); | ||||||
5490 | auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); | ||||||
5491 | if (!ToTemplatedDef) | ||||||
5492 | return nullptr; | ||||||
5493 | auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate(); | ||||||
5494 | return cast_or_null<T>(TemplateWithDef); | ||||||
5495 | } | ||||||
5496 | |||||||
5497 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { | ||||||
5498 | |||||||
5499 | // Import the major distinguishing characteristics of this class template. | ||||||
5500 | DeclContext *DC, *LexicalDC; | ||||||
5501 | DeclarationName Name; | ||||||
5502 | SourceLocation Loc; | ||||||
5503 | NamedDecl *ToD; | ||||||
5504 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
5505 | return std::move(Err); | ||||||
5506 | if (ToD) | ||||||
5507 | return ToD; | ||||||
5508 | |||||||
5509 | ClassTemplateDecl *FoundByLookup = nullptr; | ||||||
5510 | |||||||
5511 | // We may already have a template of the same name; try to find and match it. | ||||||
5512 | if (!DC->isFunctionOrMethod()) { | ||||||
5513 | SmallVector<NamedDecl *, 4> ConflictingDecls; | ||||||
5514 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||
5515 | for (auto *FoundDecl : FoundDecls) { | ||||||
5516 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary | | ||||||
5517 | Decl::IDNS_TagFriend)) | ||||||
5518 | continue; | ||||||
5519 | |||||||
5520 | Decl *Found = FoundDecl; | ||||||
5521 | auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found); | ||||||
5522 | if (FoundTemplate) { | ||||||
5523 | if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D)) | ||||||
5524 | continue; | ||||||
5525 | |||||||
5526 | if (IsStructuralMatch(D, FoundTemplate)) { | ||||||
5527 | ClassTemplateDecl *TemplateWithDef = | ||||||
5528 | getTemplateDefinition(FoundTemplate); | ||||||
5529 | if (D->isThisDeclarationADefinition() && TemplateWithDef) | ||||||
5530 | return Importer.MapImported(D, TemplateWithDef); | ||||||
5531 | if (!FoundByLookup) | ||||||
5532 | FoundByLookup = FoundTemplate; | ||||||
5533 | // Search in all matches because there may be multiple decl chains, | ||||||
5534 | // see ASTTests test ImportExistingFriendClassTemplateDef. | ||||||
5535 | continue; | ||||||
5536 | } | ||||||
5537 | ConflictingDecls.push_back(FoundDecl); | ||||||
5538 | } | ||||||
5539 | } | ||||||
5540 | |||||||
5541 | if (!ConflictingDecls.empty()) { | ||||||
5542 | ExpectedName NameOrErr = Importer.HandleNameConflict( | ||||||
5543 | Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(), | ||||||
5544 | ConflictingDecls.size()); | ||||||
5545 | if (NameOrErr) | ||||||
5546 | Name = NameOrErr.get(); | ||||||
5547 | else | ||||||
5548 | return NameOrErr.takeError(); | ||||||
5549 | } | ||||||
5550 | } | ||||||
5551 | |||||||
5552 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); | ||||||
5553 | |||||||
5554 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); | ||||||
5555 | if (!TemplateParamsOrErr) | ||||||
5556 | return TemplateParamsOrErr.takeError(); | ||||||
5557 | |||||||
5558 | // Create the declaration that is being templated. | ||||||
5559 | CXXRecordDecl *ToTemplated; | ||||||
5560 | if (Error Err = importInto(ToTemplated, FromTemplated)) | ||||||
5561 | return std::move(Err); | ||||||
5562 | |||||||
5563 | // Create the class template declaration itself. | ||||||
5564 | ClassTemplateDecl *D2; | ||||||
5565 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, | ||||||
5566 | *TemplateParamsOrErr, ToTemplated)) | ||||||
5567 | return D2; | ||||||
5568 | |||||||
5569 | ToTemplated->setDescribedClassTemplate(D2); | ||||||
5570 | |||||||
5571 | D2->setAccess(D->getAccess()); | ||||||
5572 | D2->setLexicalDeclContext(LexicalDC); | ||||||
5573 | |||||||
5574 | addDeclToContexts(D, D2); | ||||||
5575 | updateLookupTableForTemplateParameters(**TemplateParamsOrErr); | ||||||
5576 | |||||||
5577 | if (FoundByLookup) { | ||||||
5578 | auto *Recent = | ||||||
5579 | const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl()); | ||||||
5580 | |||||||
5581 | // It is possible that during the import of the class template definition | ||||||
5582 | // we start the import of a fwd friend decl of the very same class template | ||||||
5583 | // and we add the fwd friend decl to the lookup table. But the ToTemplated | ||||||
5584 | // had been created earlier and by that time the lookup could not find | ||||||
5585 | // anything existing, so it has no previous decl. Later, (still during the | ||||||
5586 | // import of the fwd friend decl) we start to import the definition again | ||||||
5587 | // and this time the lookup finds the previous fwd friend class template. | ||||||
5588 | // In this case we must set up the previous decl for the templated decl. | ||||||
5589 | if (!ToTemplated->getPreviousDecl()) { | ||||||
5590 | 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\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 5591, __extension__ __PRETTY_FUNCTION__)) | ||||||
5591 | "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\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 5591, __extension__ __PRETTY_FUNCTION__)); | ||||||
5592 | CXXRecordDecl *PrevTemplated = | ||||||
5593 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); | ||||||
5594 | if (ToTemplated != PrevTemplated) | ||||||
5595 | ToTemplated->setPreviousDecl(PrevTemplated); | ||||||
5596 | } | ||||||
5597 | |||||||
5598 | D2->setPreviousDecl(Recent); | ||||||
5599 | } | ||||||
5600 | |||||||
5601 | if (FromTemplated->isCompleteDefinition() && | ||||||
5602 | !ToTemplated->isCompleteDefinition()) { | ||||||
5603 | // FIXME: Import definition! | ||||||
5604 | } | ||||||
5605 | |||||||
5606 | return D2; | ||||||
5607 | } | ||||||
5608 | |||||||
5609 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( | ||||||
5610 | ClassTemplateSpecializationDecl *D) { | ||||||
5611 | ClassTemplateDecl *ClassTemplate; | ||||||
5612 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) | ||||||
5613 | return std::move(Err); | ||||||
5614 | |||||||
5615 | // Import the context of this declaration. | ||||||
5616 | DeclContext *DC, *LexicalDC; | ||||||
5617 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | ||||||
5618 | return std::move(Err); | ||||||
5619 | |||||||
5620 | // Import template arguments. | ||||||
5621 | SmallVector<TemplateArgument, 2> TemplateArgs; | ||||||
5622 | if (Error Err = ImportTemplateArguments( | ||||||
5623 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) | ||||||
5624 | return std::move(Err); | ||||||
5625 | // Try to find an existing specialization with these template arguments and | ||||||
5626 | // template parameter list. | ||||||
5627 | void *InsertPos = nullptr; | ||||||
5628 | ClassTemplateSpecializationDecl *PrevDecl = nullptr; | ||||||
5629 | ClassTemplatePartialSpecializationDecl *PartialSpec = | ||||||
5630 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); | ||||||
5631 | |||||||
5632 | // Import template parameters. | ||||||
5633 | TemplateParameterList *ToTPList = nullptr; | ||||||
5634 | |||||||
5635 | if (PartialSpec) { | ||||||
5636 | auto ToTPListOrErr = import(PartialSpec->getTemplateParameters()); | ||||||
5637 | if (!ToTPListOrErr) | ||||||
5638 | return ToTPListOrErr.takeError(); | ||||||
5639 | ToTPList = *ToTPListOrErr; | ||||||
5640 | PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs, | ||||||
5641 | *ToTPListOrErr, | ||||||
5642 | InsertPos); | ||||||
5643 | } else | ||||||
5644 | PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); | ||||||
5645 | |||||||
5646 | if (PrevDecl) { | ||||||
5647 | if (IsStructuralMatch(D, PrevDecl)) { | ||||||
5648 | CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition(); | ||||||
5649 | if (D->isThisDeclarationADefinition() && PrevDefinition) { | ||||||
5650 | Importer.MapImported(D, PrevDefinition); | ||||||
5651 | // Import those default field initializers which have been | ||||||
5652 | // instantiated in the "From" context, but not in the "To" context. | ||||||
5653 | for (auto *FromField : D->fields()) { | ||||||
5654 | auto ToOrErr = import(FromField); | ||||||
5655 | if (!ToOrErr) | ||||||
5656 | return ToOrErr.takeError(); | ||||||
5657 | } | ||||||
5658 | |||||||
5659 | // Import those methods which have been instantiated in the | ||||||
5660 | // "From" context, but not in the "To" context. | ||||||
5661 | for (CXXMethodDecl *FromM : D->methods()) { | ||||||
5662 | auto ToOrErr = import(FromM); | ||||||
5663 | if (!ToOrErr) | ||||||
5664 | return ToOrErr.takeError(); | ||||||
5665 | } | ||||||
5666 | |||||||
5667 | // TODO Import instantiated default arguments. | ||||||
5668 | // TODO Import instantiated exception specifications. | ||||||
5669 | // | ||||||
5670 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint | ||||||
5671 | // what else could be fused during an AST merge. | ||||||
5672 | return PrevDefinition; | ||||||
5673 | } | ||||||
5674 | } else { // ODR violation. | ||||||
5675 | // FIXME HandleNameConflict | ||||||
5676 | return make_error<ImportError>(ImportError::NameConflict); | ||||||
5677 | } | ||||||
5678 | } | ||||||
5679 | |||||||
5680 | // Import the location of this declaration. | ||||||
5681 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | ||||||
5682 | if (!BeginLocOrErr) | ||||||
5683 | return BeginLocOrErr.takeError(); | ||||||
5684 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); | ||||||
5685 | if (!IdLocOrErr) | ||||||
5686 | return IdLocOrErr.takeError(); | ||||||
5687 | |||||||
5688 | // Create the specialization. | ||||||
5689 | ClassTemplateSpecializationDecl *D2 = nullptr; | ||||||
5690 | if (PartialSpec) { | ||||||
5691 | // Import TemplateArgumentListInfo. | ||||||
5692 | TemplateArgumentListInfo ToTAInfo; | ||||||
5693 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); | ||||||
5694 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) | ||||||
5695 | return std::move(Err); | ||||||
5696 | |||||||
5697 | QualType CanonInjType; | ||||||
5698 | if (Error Err = importInto( | ||||||
5699 | CanonInjType, PartialSpec->getInjectedSpecializationType())) | ||||||
5700 | return std::move(Err); | ||||||
5701 | CanonInjType = CanonInjType.getCanonicalType(); | ||||||
5702 | |||||||
5703 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( | ||||||
5704 | D2, D, Importer.getToContext(), D->getTagKind(), DC, | ||||||
5705 | *BeginLocOrErr, *IdLocOrErr, ToTPList, ClassTemplate, | ||||||
5706 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), | ||||||
5707 | ToTAInfo, CanonInjType, | ||||||
5708 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) | ||||||
5709 | return D2; | ||||||
5710 | |||||||
5711 | // Update InsertPos, because preceding import calls may have invalidated | ||||||
5712 | // it by adding new specializations. | ||||||
5713 | auto *PartSpec2 = cast<ClassTemplatePartialSpecializationDecl>(D2); | ||||||
5714 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList, | ||||||
5715 | InsertPos)) | ||||||
5716 | // Add this partial specialization to the class template. | ||||||
5717 | ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos); | ||||||
5718 | |||||||
5719 | updateLookupTableForTemplateParameters(*ToTPList); | ||||||
5720 | } else { // Not a partial specialization. | ||||||
5721 | if (GetImportedOrCreateDecl( | ||||||
5722 | D2, D, Importer.getToContext(), D->getTagKind(), DC, | ||||||
5723 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, | ||||||
5724 | PrevDecl)) | ||||||
5725 | return D2; | ||||||
5726 | |||||||
5727 | // Update InsertPos, because preceding import calls may have invalidated | ||||||
5728 | // it by adding new specializations. | ||||||
5729 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) | ||||||
5730 | // Add this specialization to the class template. | ||||||
5731 | ClassTemplate->AddSpecialization(D2, InsertPos); | ||||||
5732 | } | ||||||
5733 | |||||||
5734 | D2->setSpecializationKind(D->getSpecializationKind()); | ||||||
5735 | |||||||
5736 | // Set the context of this specialization/instantiation. | ||||||
5737 | D2->setLexicalDeclContext(LexicalDC); | ||||||
5738 | |||||||
5739 | // Add to the DC only if it was an explicit specialization/instantiation. | ||||||
5740 | if (D2->isExplicitInstantiationOrSpecialization()) { | ||||||
5741 | LexicalDC->addDeclInternal(D2); | ||||||
5742 | } | ||||||
5743 | |||||||
5744 | if (auto BraceRangeOrErr = import(D->getBraceRange())) | ||||||
5745 | D2->setBraceRange(*BraceRangeOrErr); | ||||||
5746 | else | ||||||
5747 | return BraceRangeOrErr.takeError(); | ||||||
5748 | |||||||
5749 | // Import the qualifier, if any. | ||||||
5750 | if (auto LocOrErr = import(D->getQualifierLoc())) | ||||||
5751 | D2->setQualifierInfo(*LocOrErr); | ||||||
5752 | else | ||||||
5753 | return LocOrErr.takeError(); | ||||||
5754 | |||||||
5755 | if (auto *TSI = D->getTypeAsWritten()) { | ||||||
5756 | if (auto TInfoOrErr = import(TSI)) | ||||||
5757 | D2->setTypeAsWritten(*TInfoOrErr); | ||||||
5758 | else | ||||||
5759 | return TInfoOrErr.takeError(); | ||||||
5760 | |||||||
5761 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) | ||||||
5762 | D2->setTemplateKeywordLoc(*LocOrErr); | ||||||
5763 | else | ||||||
5764 | return LocOrErr.takeError(); | ||||||
5765 | |||||||
5766 | if (auto LocOrErr = import(D->getExternLoc())) | ||||||
5767 | D2->setExternLoc(*LocOrErr); | ||||||
5768 | else | ||||||
5769 | return LocOrErr.takeError(); | ||||||
5770 | } | ||||||
5771 | |||||||
5772 | if (D->getPointOfInstantiation().isValid()) { | ||||||
5773 | if (auto POIOrErr = import(D->getPointOfInstantiation())) | ||||||
5774 | D2->setPointOfInstantiation(*POIOrErr); | ||||||
5775 | else | ||||||
5776 | return POIOrErr.takeError(); | ||||||
5777 | } | ||||||
5778 | |||||||
5779 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); | ||||||
5780 | |||||||
5781 | if (D->isCompleteDefinition()) | ||||||
5782 | if (Error Err = ImportDefinition(D, D2)) | ||||||
5783 | return std::move(Err); | ||||||
5784 | |||||||
5785 | return D2; | ||||||
5786 | } | ||||||
5787 | |||||||
5788 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { | ||||||
5789 | // Import the major distinguishing characteristics of this variable template. | ||||||
5790 | DeclContext *DC, *LexicalDC; | ||||||
5791 | DeclarationName Name; | ||||||
5792 | SourceLocation Loc; | ||||||
5793 | NamedDecl *ToD; | ||||||
5794 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
5795 | return std::move(Err); | ||||||
5796 | if (ToD) | ||||||
5797 | return ToD; | ||||||
5798 | |||||||
5799 | // We may already have a template of the same name; try to find and match it. | ||||||
5800 | 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\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 5801, __extension__ __PRETTY_FUNCTION__)) | ||||||
5801 | "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\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 5801, __extension__ __PRETTY_FUNCTION__)); | ||||||
5802 | |||||||
5803 | SmallVector<NamedDecl *, 4> ConflictingDecls; | ||||||
5804 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||
5805 | VarTemplateDecl *FoundByLookup = nullptr; | ||||||
5806 | for (auto *FoundDecl : FoundDecls) { | ||||||
5807 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) | ||||||
5808 | continue; | ||||||
5809 | |||||||
5810 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) { | ||||||
5811 | // Use the templated decl, some linkage flags are set only there. | ||||||
5812 | if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(), | ||||||
5813 | D->getTemplatedDecl())) | ||||||
5814 | continue; | ||||||
5815 | if (IsStructuralMatch(D, FoundTemplate)) { | ||||||
5816 | // The Decl in the "From" context has a definition, but in the | ||||||
5817 | // "To" context we already have a definition. | ||||||
5818 | VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate); | ||||||
5819 | if (D->isThisDeclarationADefinition() && FoundDef) | ||||||
5820 | // FIXME Check for ODR error if the two definitions have | ||||||
5821 | // different initializers? | ||||||
5822 | return Importer.MapImported(D, FoundDef); | ||||||
5823 | |||||||
5824 | FoundByLookup = FoundTemplate; | ||||||
5825 | break; | ||||||
5826 | } | ||||||
5827 | ConflictingDecls.push_back(FoundDecl); | ||||||
5828 | } | ||||||
5829 | } | ||||||
5830 | |||||||
5831 | if (!ConflictingDecls.empty()) { | ||||||
5832 | ExpectedName NameOrErr = Importer.HandleNameConflict( | ||||||
5833 | Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(), | ||||||
5834 | ConflictingDecls.size()); | ||||||
5835 | if (NameOrErr) | ||||||
5836 | Name = NameOrErr.get(); | ||||||
5837 | else | ||||||
5838 | return NameOrErr.takeError(); | ||||||
5839 | } | ||||||
5840 | |||||||
5841 | VarDecl *DTemplated = D->getTemplatedDecl(); | ||||||
5842 | |||||||
5843 | // Import the type. | ||||||
5844 | // FIXME: Value not used? | ||||||
5845 | ExpectedType TypeOrErr = import(DTemplated->getType()); | ||||||
5846 | if (!TypeOrErr) | ||||||
5847 | return TypeOrErr.takeError(); | ||||||
5848 | |||||||
5849 | // Create the declaration that is being templated. | ||||||
5850 | VarDecl *ToTemplated; | ||||||
5851 | if (Error Err = importInto(ToTemplated, DTemplated)) | ||||||
5852 | return std::move(Err); | ||||||
5853 | |||||||
5854 | // Create the variable template declaration itself. | ||||||
5855 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); | ||||||
5856 | if (!TemplateParamsOrErr) | ||||||
5857 | return TemplateParamsOrErr.takeError(); | ||||||
5858 | |||||||
5859 | VarTemplateDecl *ToVarTD; | ||||||
5860 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, | ||||||
5861 | Name, *TemplateParamsOrErr, ToTemplated)) | ||||||
5862 | return ToVarTD; | ||||||
5863 | |||||||
5864 | ToTemplated->setDescribedVarTemplate(ToVarTD); | ||||||
5865 | |||||||
5866 | ToVarTD->setAccess(D->getAccess()); | ||||||
5867 | ToVarTD->setLexicalDeclContext(LexicalDC); | ||||||
5868 | LexicalDC->addDeclInternal(ToVarTD); | ||||||
5869 | if (DC != Importer.getToContext().getTranslationUnitDecl()) | ||||||
5870 | updateLookupTableForTemplateParameters(**TemplateParamsOrErr); | ||||||
5871 | |||||||
5872 | if (FoundByLookup) { | ||||||
5873 | auto *Recent = | ||||||
5874 | const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl()); | ||||||
5875 | if (!ToTemplated->getPreviousDecl()) { | ||||||
5876 | auto *PrevTemplated = | ||||||
5877 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); | ||||||
5878 | if (ToTemplated != PrevTemplated) | ||||||
5879 | ToTemplated->setPreviousDecl(PrevTemplated); | ||||||
5880 | } | ||||||
5881 | ToVarTD->setPreviousDecl(Recent); | ||||||
5882 | } | ||||||
5883 | |||||||
5884 | if (DTemplated->isThisDeclarationADefinition() && | ||||||
5885 | !ToTemplated->isThisDeclarationADefinition()) { | ||||||
5886 | // FIXME: Import definition! | ||||||
5887 | } | ||||||
5888 | |||||||
5889 | return ToVarTD; | ||||||
5890 | } | ||||||
5891 | |||||||
5892 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( | ||||||
5893 | VarTemplateSpecializationDecl *D) { | ||||||
5894 | // If this record has a definition in the translation unit we're coming from, | ||||||
5895 | // but this particular declaration is not that definition, import the | ||||||
5896 | // definition and map to that. | ||||||
5897 | VarDecl *Definition = D->getDefinition(); | ||||||
5898 | if (Definition && Definition != D) { | ||||||
5899 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | ||||||
5900 | return Importer.MapImported(D, *ImportedDefOrErr); | ||||||
5901 | else | ||||||
5902 | return ImportedDefOrErr.takeError(); | ||||||
5903 | } | ||||||
5904 | |||||||
5905 | VarTemplateDecl *VarTemplate = nullptr; | ||||||
5906 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) | ||||||
5907 | return std::move(Err); | ||||||
5908 | |||||||
5909 | // Import the context of this declaration. | ||||||
5910 | DeclContext *DC, *LexicalDC; | ||||||
5911 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | ||||||
5912 | return std::move(Err); | ||||||
5913 | |||||||
5914 | // Import the location of this declaration. | ||||||
5915 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | ||||||
5916 | if (!BeginLocOrErr) | ||||||
5917 | return BeginLocOrErr.takeError(); | ||||||
5918 | |||||||
5919 | auto IdLocOrErr = import(D->getLocation()); | ||||||
5920 | if (!IdLocOrErr) | ||||||
5921 | return IdLocOrErr.takeError(); | ||||||
5922 | |||||||
5923 | // Import template arguments. | ||||||
5924 | SmallVector<TemplateArgument, 2> TemplateArgs; | ||||||
5925 | if (Error Err = ImportTemplateArguments( | ||||||
5926 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) | ||||||
5927 | return std::move(Err); | ||||||
5928 | |||||||
5929 | // Try to find an existing specialization with these template arguments. | ||||||
5930 | void *InsertPos = nullptr; | ||||||
5931 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( | ||||||
5932 | TemplateArgs, InsertPos); | ||||||
5933 | if (D2) { | ||||||
5934 | // We already have a variable template specialization with these template | ||||||
5935 | // arguments. | ||||||
5936 | |||||||
5937 | // FIXME: Check for specialization vs. instantiation errors. | ||||||
5938 | |||||||
5939 | if (VarDecl *FoundDef = D2->getDefinition()) { | ||||||
5940 | if (!D->isThisDeclarationADefinition() || | ||||||
5941 | IsStructuralMatch(D, FoundDef)) { | ||||||
5942 | // The record types structurally match, or the "from" translation | ||||||
5943 | // unit only had a forward declaration anyway; call it the same | ||||||
5944 | // variable. | ||||||
5945 | return Importer.MapImported(D, FoundDef); | ||||||
5946 | } | ||||||
5947 | } | ||||||
5948 | } else { | ||||||
5949 | // Import the type. | ||||||
5950 | QualType T; | ||||||
5951 | if (Error Err = importInto(T, D->getType())) | ||||||
5952 | return std::move(Err); | ||||||
5953 | |||||||
5954 | auto TInfoOrErr = import(D->getTypeSourceInfo()); | ||||||
5955 | if (!TInfoOrErr) | ||||||
5956 | return TInfoOrErr.takeError(); | ||||||
5957 | |||||||
5958 | TemplateArgumentListInfo ToTAInfo; | ||||||
5959 | if (Error Err = ImportTemplateArgumentListInfo( | ||||||
5960 | D->getTemplateArgsInfo(), ToTAInfo)) | ||||||
5961 | return std::move(Err); | ||||||
5962 | |||||||
5963 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; | ||||||
5964 | // Create a new specialization. | ||||||
5965 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { | ||||||
5966 | // Import TemplateArgumentListInfo | ||||||
5967 | TemplateArgumentListInfo ArgInfos; | ||||||
5968 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); | ||||||
5969 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. | ||||||
5970 | if (Error Err = ImportTemplateArgumentListInfo( | ||||||
5971 | *FromTAArgsAsWritten, ArgInfos)) | ||||||
5972 | return std::move(Err); | ||||||
5973 | |||||||
5974 | auto ToTPListOrErr = import(FromPartial->getTemplateParameters()); | ||||||
5975 | if (!ToTPListOrErr) | ||||||
5976 | return ToTPListOrErr.takeError(); | ||||||
5977 | |||||||
5978 | PartVarSpecDecl *ToPartial; | ||||||
5979 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, | ||||||
5980 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, | ||||||
5981 | VarTemplate, T, *TInfoOrErr, | ||||||
5982 | D->getStorageClass(), TemplateArgs, ArgInfos)) | ||||||
5983 | return ToPartial; | ||||||
5984 | |||||||
5985 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( | ||||||
5986 | FromPartial->getInstantiatedFromMember())) | ||||||
5987 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); | ||||||
5988 | else | ||||||
5989 | return ToInstOrErr.takeError(); | ||||||
5990 | |||||||
5991 | if (FromPartial->isMemberSpecialization()) | ||||||
5992 | ToPartial->setMemberSpecialization(); | ||||||
5993 | |||||||
5994 | D2 = ToPartial; | ||||||
5995 | |||||||
5996 | // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed | ||||||
5997 | // to adopt template parameters. | ||||||
5998 | // updateLookupTableForTemplateParameters(**ToTPListOrErr); | ||||||
5999 | } else { // Full specialization | ||||||
6000 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, | ||||||
6001 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, | ||||||
6002 | T, *TInfoOrErr, | ||||||
6003 | D->getStorageClass(), TemplateArgs)) | ||||||
6004 | return D2; | ||||||
6005 | } | ||||||
6006 | |||||||
6007 | if (D->getPointOfInstantiation().isValid()) { | ||||||
6008 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) | ||||||
6009 | D2->setPointOfInstantiation(*POIOrErr); | ||||||
6010 | else | ||||||
6011 | return POIOrErr.takeError(); | ||||||
6012 | } | ||||||
6013 | |||||||
6014 | D2->setSpecializationKind(D->getSpecializationKind()); | ||||||
6015 | D2->setTemplateArgsInfo(ToTAInfo); | ||||||
6016 | |||||||
6017 | // Add this specialization to the class template. | ||||||
6018 | VarTemplate->AddSpecialization(D2, InsertPos); | ||||||
6019 | |||||||
6020 | // Import the qualifier, if any. | ||||||
6021 | if (auto LocOrErr = import(D->getQualifierLoc())) | ||||||
6022 | D2->setQualifierInfo(*LocOrErr); | ||||||
6023 | else | ||||||
6024 | return LocOrErr.takeError(); | ||||||
6025 | |||||||
6026 | if (D->isConstexpr()) | ||||||
6027 | D2->setConstexpr(true); | ||||||
6028 | |||||||
6029 | // Add the specialization to this context. | ||||||
6030 | D2->setLexicalDeclContext(LexicalDC); | ||||||
6031 | LexicalDC->addDeclInternal(D2); | ||||||
6032 | |||||||
6033 | D2->setAccess(D->getAccess()); | ||||||
6034 | } | ||||||
6035 | |||||||
6036 | if (Error Err = ImportInitializer(D, D2)) | ||||||
6037 | return std::move(Err); | ||||||
6038 | |||||||
6039 | return D2; | ||||||
6040 | } | ||||||
6041 | |||||||
6042 | ExpectedDecl | ||||||
6043 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { | ||||||
6044 | DeclContext *DC, *LexicalDC; | ||||||
6045 | DeclarationName Name; | ||||||
6046 | SourceLocation Loc; | ||||||
6047 | NamedDecl *ToD; | ||||||
6048 | |||||||
6049 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||
6050 | return std::move(Err); | ||||||
6051 | |||||||
6052 | if (ToD) | ||||||
6053 | return ToD; | ||||||
6054 | |||||||
6055 | const FunctionTemplateDecl *FoundByLookup = nullptr; | ||||||
6056 | |||||||
6057 | // Try to find a function in our own ("to") context with the same name, same | ||||||
6058 | // type, and in the same context as the function we're importing. | ||||||
6059 | // FIXME Split this into a separate function. | ||||||
6060 | if (!LexicalDC->isFunctionOrMethod()) { | ||||||
6061 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; | ||||||
6062 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||
6063 | for (auto *FoundDecl : FoundDecls) { | ||||||
6064 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | ||||||
6065 | continue; | ||||||
6066 | |||||||
6067 | if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { | ||||||
6068 | if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D)) | ||||||
6069 | continue; | ||||||
6070 | if (IsStructuralMatch(D, FoundTemplate)) { | ||||||
6071 | FunctionTemplateDecl *TemplateWithDef = | ||||||
6072 | getTemplateDefinition(FoundTemplate); | ||||||
6073 | if (D->isThisDeclarationADefinition() && TemplateWithDef) | ||||||
6074 | return Importer.MapImported(D, TemplateWithDef); | ||||||
6075 | |||||||
6076 | FoundByLookup = FoundTemplate; | ||||||
6077 | break; | ||||||
6078 | // TODO: handle conflicting names | ||||||
6079 | } | ||||||
6080 | } | ||||||
6081 | } | ||||||
6082 | } | ||||||
6083 | |||||||
6084 | auto ParamsOrErr = import(D->getTemplateParameters()); | ||||||
6085 | if (!ParamsOrErr) | ||||||
6086 | return ParamsOrErr.takeError(); | ||||||
6087 | TemplateParameterList *Params = *ParamsOrErr; | ||||||
6088 | |||||||
6089 | FunctionDecl *TemplatedFD; | ||||||
6090 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) | ||||||
6091 | return std::move(Err); | ||||||
6092 | |||||||
6093 | // Template parameters of the ClassTemplateDecl and FunctionTemplateDecl are | ||||||
6094 | // shared, if the FunctionTemplateDecl is a deduction guide for the class. | ||||||
6095 | // At import the ClassTemplateDecl object is always created first (FIXME: is | ||||||
6096 | // this really true?) because the dependency, then the FunctionTemplateDecl. | ||||||
6097 | // The DeclContext of the template parameters is changed when the | ||||||
6098 | // FunctionTemplateDecl is created, but was set already when the class | ||||||
6099 | // template was created. So here it is not the TU (default value) any more. | ||||||
6100 | // FIXME: The DeclContext of the parameters is now set finally to the | ||||||
6101 | // CXXDeductionGuideDecl object that was imported later. This may not be the | ||||||
6102 | // same that is in the original AST, specially if there are multiple deduction | ||||||
6103 | // guides. | ||||||
6104 | DeclContext *OldParamDC = nullptr; | ||||||
6105 | if (Params->size() > 0) | ||||||
6106 | OldParamDC = Params->getParam(0)->getDeclContext(); | ||||||
6107 | |||||||
6108 | FunctionTemplateDecl *ToFunc; | ||||||
6109 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, | ||||||
6110 | Params, TemplatedFD)) | ||||||
6111 | return ToFunc; | ||||||
6112 | |||||||
6113 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); | ||||||
6114 | |||||||
6115 | ToFunc->setAccess(D->getAccess()); | ||||||
6116 | ToFunc->setLexicalDeclContext(LexicalDC); | ||||||
6117 | LexicalDC->addDeclInternal(ToFunc); | ||||||
6118 | updateLookupTableForTemplateParameters(*Params, OldParamDC); | ||||||
6119 | |||||||
6120 | if (FoundByLookup) { | ||||||
6121 | auto *Recent = | ||||||
6122 | const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl()); | ||||||
6123 | if (!TemplatedFD->getPreviousDecl()) { | ||||||
6124 | 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\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 6125, __extension__ __PRETTY_FUNCTION__)) | ||||||
6125 | "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\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 6125, __extension__ __PRETTY_FUNCTION__)); | ||||||
6126 | auto *PrevTemplated = | ||||||
6127 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); | ||||||
6128 | if (TemplatedFD != PrevTemplated) | ||||||
6129 | TemplatedFD->setPreviousDecl(PrevTemplated); | ||||||
6130 | } | ||||||
6131 | ToFunc->setPreviousDecl(Recent); | ||||||
6132 | } | ||||||
6133 | |||||||
6134 | return ToFunc; | ||||||
6135 | } | ||||||
6136 | |||||||
6137 | //---------------------------------------------------------------------------- | ||||||
6138 | // Import Statements | ||||||
6139 | //---------------------------------------------------------------------------- | ||||||
6140 | |||||||
6141 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { | ||||||
6142 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) | ||||||
6143 | << S->getStmtClassName(); | ||||||
6144 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | ||||||
6145 | } | ||||||
6146 | |||||||
6147 | |||||||
6148 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { | ||||||
6149 | if (Importer.returnWithErrorInTest()) | ||||||
6150 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | ||||||
6151 | SmallVector<IdentifierInfo *, 4> Names; | ||||||
6152 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { | ||||||
6153 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); | ||||||
6154 | // ToII is nullptr when no symbolic name is given for output operand | ||||||
6155 | // see ParseStmtAsm::ParseAsmOperandsOpt | ||||||
6156 | Names.push_back(ToII); | ||||||
6157 | } | ||||||
6158 | |||||||
6159 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { | ||||||
6160 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); | ||||||
6161 | // ToII is nullptr when no symbolic name is given for input operand | ||||||
6162 | // see ParseStmtAsm::ParseAsmOperandsOpt | ||||||
6163 | Names.push_back(ToII); | ||||||
6164 | } | ||||||
6165 | |||||||
6166 | SmallVector<StringLiteral *, 4> Clobbers; | ||||||
6167 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { | ||||||
6168 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) | ||||||
6169 | Clobbers.push_back(*ClobberOrErr); | ||||||
6170 | else | ||||||
6171 | return ClobberOrErr.takeError(); | ||||||
6172 | |||||||
6173 | } | ||||||
6174 | |||||||
6175 | SmallVector<StringLiteral *, 4> Constraints; | ||||||
6176 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { | ||||||
6177 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) | ||||||
6178 | Constraints.push_back(*OutputOrErr); | ||||||
6179 | else | ||||||
6180 | return OutputOrErr.takeError(); | ||||||
6181 | } | ||||||
6182 | |||||||
6183 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { | ||||||
6184 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) | ||||||
6185 | Constraints.push_back(*InputOrErr); | ||||||
6186 | else | ||||||
6187 | return InputOrErr.takeError(); | ||||||
6188 | } | ||||||
6189 | |||||||
6190 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs() + | ||||||
6191 | S->getNumLabels()); | ||||||
6192 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) | ||||||
6193 | return std::move(Err); | ||||||
6194 | |||||||
6195 | if (Error Err = | ||||||
6196 | ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) | ||||||
6197 | return std::move(Err); | ||||||
6198 | |||||||
6199 | if (Error Err = ImportArrayChecked( | ||||||
6200 | S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs())) | ||||||
6201 | return std::move(Err); | ||||||
6202 | |||||||
6203 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); | ||||||
6204 | if (!AsmLocOrErr) | ||||||
6205 | return AsmLocOrErr.takeError(); | ||||||
6206 | auto AsmStrOrErr = import(S->getAsmString()); | ||||||
6207 | if (!AsmStrOrErr) | ||||||
6208 | return AsmStrOrErr.takeError(); | ||||||
6209 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); | ||||||
6210 | if (!RParenLocOrErr) | ||||||
6211 | return RParenLocOrErr.takeError(); | ||||||
6212 | |||||||
6213 | return new (Importer.getToContext()) GCCAsmStmt( | ||||||
6214 | Importer.getToContext(), | ||||||
6215 | *AsmLocOrErr, | ||||||
6216 | S->isSimple(), | ||||||
6217 | S->isVolatile(), | ||||||
6218 | S->getNumOutputs(), | ||||||
6219 | S->getNumInputs(), | ||||||
6220 | Names.data(), | ||||||
6221 | Constraints.data(), | ||||||
6222 | Exprs.data(), | ||||||
6223 | *AsmStrOrErr, | ||||||
6224 | S->getNumClobbers(), | ||||||
6225 | Clobbers.data(), | ||||||
6226 | S->getNumLabels(), | ||||||
6227 | *RParenLocOrErr); | ||||||
6228 | } | ||||||
6229 | |||||||
6230 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { | ||||||
6231 | |||||||
6232 | Error Err = Error::success(); | ||||||
6233 | auto ToDG = importChecked(Err, S->getDeclGroup()); | ||||||
6234 | auto ToBeginLoc = importChecked(Err, S->getBeginLoc()); | ||||||
6235 | auto ToEndLoc = importChecked(Err, S->getEndLoc()); | ||||||
6236 | if (Err) | ||||||
6237 | return std::move(Err); | ||||||
6238 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); | ||||||
6239 | } | ||||||
6240 | |||||||
6241 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { | ||||||
6242 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); | ||||||
6243 | if (!ToSemiLocOrErr) | ||||||
6244 | return ToSemiLocOrErr.takeError(); | ||||||
6245 | return new (Importer.getToContext()) NullStmt( | ||||||
6246 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); | ||||||
6247 | } | ||||||
6248 | |||||||
6249 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { | ||||||
6250 | SmallVector<Stmt *, 8> ToStmts(S->size()); | ||||||
6251 | |||||||
6252 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) | ||||||
6253 | return std::move(Err); | ||||||
6254 | |||||||
6255 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); | ||||||
6256 | if (!ToLBracLocOrErr) | ||||||
6257 | return ToLBracLocOrErr.takeError(); | ||||||
6258 | |||||||
6259 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); | ||||||
6260 | if (!ToRBracLocOrErr) | ||||||
6261 | return ToRBracLocOrErr.takeError(); | ||||||
6262 | |||||||
6263 | return CompoundStmt::Create( | ||||||
6264 | Importer.getToContext(), ToStmts, | ||||||
6265 | *ToLBracLocOrErr, *ToRBracLocOrErr); | ||||||
6266 | } | ||||||
6267 | |||||||
6268 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { | ||||||
6269 | |||||||
6270 | Error Err = Error::success(); | ||||||
6271 | auto ToLHS = importChecked(Err, S->getLHS()); | ||||||
6272 | auto ToRHS = importChecked(Err, S->getRHS()); | ||||||
6273 | auto ToSubStmt = importChecked(Err, S->getSubStmt()); | ||||||
6274 | auto ToCaseLoc = importChecked(Err, S->getCaseLoc()); | ||||||
6275 | auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc()); | ||||||
6276 | auto ToColonLoc = importChecked(Err, S->getColonLoc()); | ||||||
6277 | if (Err) | ||||||
6278 | return std::move(Err); | ||||||
6279 | |||||||
6280 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, | ||||||
6281 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); | ||||||
6282 | ToStmt->setSubStmt(ToSubStmt); | ||||||
6283 | |||||||
6284 | return ToStmt; | ||||||
6285 | } | ||||||
6286 | |||||||
6287 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { | ||||||
6288 | |||||||
6289 | Error Err = Error::success(); | ||||||
6290 | auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc()); | ||||||
6291 | auto ToColonLoc = importChecked(Err, S->getColonLoc()); | ||||||
6292 | auto ToSubStmt = importChecked(Err, S->getSubStmt()); | ||||||
6293 | if (Err) | ||||||
6294 | return std::move(Err); | ||||||
6295 | |||||||
6296 | return new (Importer.getToContext()) DefaultStmt( | ||||||
6297 | ToDefaultLoc, ToColonLoc, ToSubStmt); | ||||||
6298 | } | ||||||
6299 | |||||||
6300 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { | ||||||
6301 | |||||||
6302 | Error Err = Error::success(); | ||||||
6303 | auto ToIdentLoc = importChecked(Err, S->getIdentLoc()); | ||||||
6304 | auto ToLabelDecl = importChecked(Err, S->getDecl()); | ||||||
6305 | auto ToSubStmt = importChecked(Err, S->getSubStmt()); | ||||||
6306 | if (Err) | ||||||
6307 | return std::move(Err); | ||||||
6308 | |||||||
6309 | return new (Importer.getToContext()) LabelStmt( | ||||||
6310 | ToIdentLoc, ToLabelDecl, ToSubStmt); | ||||||
6311 | } | ||||||
6312 | |||||||
6313 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { | ||||||
6314 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); | ||||||
6315 | if (!ToAttrLocOrErr) | ||||||
6316 | return ToAttrLocOrErr.takeError(); | ||||||
6317 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); | ||||||
6318 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); | ||||||
6319 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) | ||||||
6320 | return std::move(Err); | ||||||
6321 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); | ||||||
6322 | if (!ToSubStmtOrErr) | ||||||
6323 | return ToSubStmtOrErr.takeError(); | ||||||
6324 | |||||||
6325 | return AttributedStmt::Create( | ||||||
6326 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); | ||||||
6327 | } | ||||||
6328 | |||||||
6329 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { | ||||||
6330 | |||||||
6331 | Error Err = Error::success(); | ||||||
6332 | auto ToIfLoc = importChecked(Err, S->getIfLoc()); | ||||||
6333 | auto ToInit = importChecked(Err, S->getInit()); | ||||||
6334 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); | ||||||
6335 | auto ToCond = importChecked(Err, S->getCond()); | ||||||
6336 | auto ToLParenLoc = importChecked(Err, S->getLParenLoc()); | ||||||
6337 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | ||||||
6338 | auto ToThen = importChecked(Err, S->getThen()); | ||||||
6339 | auto ToElseLoc = importChecked(Err, S->getElseLoc()); | ||||||
6340 | auto ToElse = importChecked(Err, S->getElse()); | ||||||
6341 | if (Err) | ||||||
6342 | return std::move(Err); | ||||||
6343 | |||||||
6344 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), | ||||||
6345 | ToInit, ToConditionVariable, ToCond, ToLParenLoc, | ||||||
6346 | ToRParenLoc, ToThen, ToElseLoc, ToElse); | ||||||
6347 | } | ||||||
6348 | |||||||
6349 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { | ||||||
6350 | |||||||
6351 | Error Err = Error::success(); | ||||||
6352 | auto ToInit = importChecked(Err, S->getInit()); | ||||||
6353 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); | ||||||
6354 | auto ToCond = importChecked(Err, S->getCond()); | ||||||
6355 | auto ToLParenLoc = importChecked(Err, S->getLParenLoc()); | ||||||
6356 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | ||||||
6357 | auto ToBody = importChecked(Err, S->getBody()); | ||||||
6358 | auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc()); | ||||||
6359 | if (Err) | ||||||
6360 | return std::move(Err); | ||||||
6361 | |||||||
6362 | auto *ToStmt = | ||||||
6363 | SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable, | ||||||
6364 | ToCond, ToLParenLoc, ToRParenLoc); | ||||||
6365 | ToStmt->setBody(ToBody); | ||||||
6366 | ToStmt->setSwitchLoc(ToSwitchLoc); | ||||||
6367 | |||||||
6368 | // Now we have to re-chain the cases. | ||||||
6369 | SwitchCase *LastChainedSwitchCase = nullptr; | ||||||
6370 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; | ||||||
6371 | SC = SC->getNextSwitchCase()) { | ||||||
6372 | Expected<SwitchCase *> ToSCOrErr = import(SC); | ||||||
6373 | if (!ToSCOrErr) | ||||||
6374 | return ToSCOrErr.takeError(); | ||||||
6375 | if (LastChainedSwitchCase) | ||||||
6376 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); | ||||||
6377 | else | ||||||
6378 | ToStmt->setSwitchCaseList(*ToSCOrErr); | ||||||
6379 | LastChainedSwitchCase = *ToSCOrErr; | ||||||
6380 | } | ||||||
6381 | |||||||
6382 | return ToStmt; | ||||||
6383 | } | ||||||
6384 | |||||||
6385 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { | ||||||
6386 | |||||||
6387 | Error Err = Error::success(); | ||||||
6388 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); | ||||||
6389 | auto ToCond = importChecked(Err, S->getCond()); | ||||||
6390 | auto ToBody = importChecked(Err, S->getBody()); | ||||||
6391 | auto ToWhileLoc = importChecked(Err, S->getWhileLoc()); | ||||||
6392 | auto ToLParenLoc = importChecked(Err, S->getLParenLoc()); | ||||||
6393 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | ||||||
6394 | if (Err) | ||||||
6395 | return std::move(Err); | ||||||
6396 | |||||||
6397 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, | ||||||
6398 | ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc); | ||||||
6399 | } | ||||||
6400 | |||||||
6401 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { | ||||||
6402 | |||||||
6403 | Error Err = Error::success(); | ||||||
6404 | auto ToBody = importChecked(Err, S->getBody()); | ||||||
6405 | auto ToCond = importChecked(Err, S->getCond()); | ||||||
6406 | auto ToDoLoc = importChecked(Err, S->getDoLoc()); | ||||||
6407 | auto ToWhileLoc = importChecked(Err, S->getWhileLoc()); | ||||||
6408 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | ||||||
6409 | if (Err) | ||||||
6410 | return std::move(Err); | ||||||
6411 | |||||||
6412 | return new (Importer.getToContext()) DoStmt( | ||||||
6413 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); | ||||||
6414 | } | ||||||
6415 | |||||||
6416 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { | ||||||
6417 | |||||||
6418 | Error Err = Error::success(); | ||||||
6419 | auto ToInit = importChecked(Err, S->getInit()); | ||||||
6420 | auto ToCond = importChecked(Err, S->getCond()); | ||||||
6421 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); | ||||||
6422 | auto ToInc = importChecked(Err, S->getInc()); | ||||||
6423 | auto ToBody = importChecked(Err, S->getBody()); | ||||||
6424 | auto ToForLoc = importChecked(Err, S->getForLoc()); | ||||||
6425 | auto ToLParenLoc = importChecked(Err, S->getLParenLoc()); | ||||||
6426 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | ||||||
6427 | if (Err) | ||||||
6428 | return std::move(Err); | ||||||
6429 | |||||||
6430 | return new (Importer.getToContext()) ForStmt( | ||||||
6431 | Importer.getToContext(), | ||||||
6432 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, | ||||||
6433 | ToRParenLoc); | ||||||
6434 | } | ||||||
6435 | |||||||
6436 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { | ||||||
6437 | |||||||
6438 | Error Err = Error::success(); | ||||||
6439 | auto ToLabel = importChecked(Err, S->getLabel()); | ||||||
6440 | auto ToGotoLoc = importChecked(Err, S->getGotoLoc()); | ||||||
6441 | auto ToLabelLoc = importChecked(Err, S->getLabelLoc()); | ||||||
6442 | if (Err) | ||||||
6443 | return std::move(Err); | ||||||
6444 | |||||||
6445 | return new (Importer.getToContext()) GotoStmt( | ||||||
6446 | ToLabel, ToGotoLoc, ToLabelLoc); | ||||||
6447 | } | ||||||
6448 | |||||||
6449 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { | ||||||
6450 | |||||||
6451 | Error Err = Error::success(); | ||||||
6452 | auto ToGotoLoc = importChecked(Err, S->getGotoLoc()); | ||||||
6453 | auto ToStarLoc = importChecked(Err, S->getStarLoc()); | ||||||
6454 | auto ToTarget = importChecked(Err, S->getTarget()); | ||||||
6455 | if (Err) | ||||||
6456 | return std::move(Err); | ||||||
6457 | |||||||
6458 | return new (Importer.getToContext()) IndirectGotoStmt( | ||||||
6459 | ToGotoLoc, ToStarLoc, ToTarget); | ||||||
6460 | } | ||||||
6461 | |||||||
6462 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { | ||||||
6463 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); | ||||||
6464 | if (!ToContinueLocOrErr) | ||||||
6465 | return ToContinueLocOrErr.takeError(); | ||||||
6466 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); | ||||||
6467 | } | ||||||
6468 | |||||||
6469 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { | ||||||
6470 | auto ToBreakLocOrErr = import(S->getBreakLoc()); | ||||||
6471 | if (!ToBreakLocOrErr) | ||||||
6472 | return ToBreakLocOrErr.takeError(); | ||||||
6473 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); | ||||||
6474 | } | ||||||
6475 | |||||||
6476 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { | ||||||
6477 | |||||||
6478 | Error Err = Error::success(); | ||||||
6479 | auto ToReturnLoc = importChecked(Err, S->getReturnLoc()); | ||||||
6480 | auto ToRetValue = importChecked(Err, S->getRetValue()); | ||||||
6481 | auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate()); | ||||||
6482 | if (Err) | ||||||
6483 | return std::move(Err); | ||||||
6484 | |||||||
6485 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, | ||||||
6486 | ToNRVOCandidate); | ||||||
6487 | } | ||||||
6488 | |||||||
6489 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { | ||||||
6490 | |||||||
6491 | Error Err = Error::success(); | ||||||
6492 | auto ToCatchLoc = importChecked(Err, S->getCatchLoc()); | ||||||
6493 | auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl()); | ||||||
6494 | auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock()); | ||||||
6495 | if (Err) | ||||||
6496 | return std::move(Err); | ||||||
6497 | |||||||
6498 | return new (Importer.getToContext()) CXXCatchStmt ( | ||||||
6499 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); | ||||||
6500 | } | ||||||
6501 | |||||||
6502 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { | ||||||
6503 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); | ||||||
6504 | if (!ToTryLocOrErr) | ||||||
6505 | return ToTryLocOrErr.takeError(); | ||||||
6506 | |||||||
6507 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); | ||||||
6508 | if (!ToTryBlockOrErr) | ||||||
6509 | return ToTryBlockOrErr.takeError(); | ||||||
6510 | |||||||
6511 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); | ||||||
6512 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { | ||||||
6513 | CXXCatchStmt *FromHandler = S->getHandler(HI); | ||||||
6514 | if (auto ToHandlerOrErr = import(FromHandler)) | ||||||
6515 | ToHandlers[HI] = *ToHandlerOrErr; | ||||||
6516 | else | ||||||
6517 | return ToHandlerOrErr.takeError(); | ||||||
6518 | } | ||||||
6519 | |||||||
6520 | return CXXTryStmt::Create( | ||||||
6521 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); | ||||||
6522 | } | ||||||
6523 | |||||||
6524 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { | ||||||
6525 | |||||||
6526 | Error Err = Error::success(); | ||||||
6527 | auto ToInit = importChecked(Err, S->getInit()); | ||||||
6528 | auto ToRangeStmt = importChecked(Err, S->getRangeStmt()); | ||||||
6529 | auto ToBeginStmt = importChecked(Err, S->getBeginStmt()); | ||||||
6530 | auto ToEndStmt = importChecked(Err, S->getEndStmt()); | ||||||
6531 | auto ToCond = importChecked(Err, S->getCond()); | ||||||
6532 | auto ToInc = importChecked(Err, S->getInc()); | ||||||
6533 | auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt()); | ||||||
6534 | auto ToBody = importChecked(Err, S->getBody()); | ||||||
6535 | auto ToForLoc = importChecked(Err, S->getForLoc()); | ||||||
6536 | auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc()); | ||||||
6537 | auto ToColonLoc = importChecked(Err, S->getColonLoc()); | ||||||
6538 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | ||||||
6539 | if (Err) | ||||||
6540 | return std::move(Err); | ||||||
6541 | |||||||
6542 | return new (Importer.getToContext()) CXXForRangeStmt( | ||||||
6543 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, | ||||||
6544 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); | ||||||
6545 | } | ||||||
6546 | |||||||
6547 | ExpectedStmt | ||||||
6548 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { | ||||||
6549 | Error Err = Error::success(); | ||||||
6550 | auto ToElement = importChecked(Err, S->getElement()); | ||||||
6551 | auto ToCollection = importChecked(Err, S->getCollection()); | ||||||
6552 | auto ToBody = importChecked(Err, S->getBody()); | ||||||
6553 | auto ToForLoc = importChecked(Err, S->getForLoc()); | ||||||
6554 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | ||||||
6555 | if (Err) | ||||||
6556 | return std::move(Err); | ||||||
6557 | |||||||
6558 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, | ||||||
6559 | ToCollection, | ||||||
6560 | ToBody, | ||||||
6561 | ToForLoc, | ||||||
6562 | ToRParenLoc); | ||||||
6563 | } | ||||||
6564 | |||||||
6565 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { | ||||||
6566 | |||||||
6567 | Error Err = Error::success(); | ||||||
6568 | auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc()); | ||||||
6569 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | ||||||
6570 | auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl()); | ||||||
6571 | auto ToCatchBody = importChecked(Err, S->getCatchBody()); | ||||||
6572 | if (Err) | ||||||
6573 | return std::move(Err); | ||||||
6574 | |||||||
6575 | return new (Importer.getToContext()) ObjCAtCatchStmt ( | ||||||
6576 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); | ||||||
6577 | } | ||||||
6578 | |||||||
6579 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { | ||||||
6580 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); | ||||||
6581 | if (!ToAtFinallyLocOrErr) | ||||||
6582 | return ToAtFinallyLocOrErr.takeError(); | ||||||
6583 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); | ||||||
6584 | if (!ToAtFinallyStmtOrErr) | ||||||
6585 | return ToAtFinallyStmtOrErr.takeError(); | ||||||
6586 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, | ||||||
6587 | *ToAtFinallyStmtOrErr); | ||||||
6588 | } | ||||||
6589 | |||||||
6590 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { | ||||||
6591 | |||||||
6592 | Error Err = Error::success(); | ||||||
6593 | auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc()); | ||||||
6594 | auto ToTryBody = importChecked(Err, S->getTryBody()); | ||||||
6595 | auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt()); | ||||||
6596 | if (Err) | ||||||
6597 | return std::move(Err); | ||||||
6598 | |||||||
6599 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); | ||||||
6600 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { | ||||||
6601 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); | ||||||
6602 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) | ||||||
6603 | ToCatchStmts[CI] = *ToCatchStmtOrErr; | ||||||
6604 | else | ||||||
6605 | return ToCatchStmtOrErr.takeError(); | ||||||
6606 | } | ||||||
6607 | |||||||
6608 | return ObjCAtTryStmt::Create(Importer.getToContext(), | ||||||
6609 | ToAtTryLoc, ToTryBody, | ||||||
6610 | ToCatchStmts.begin(), ToCatchStmts.size(), | ||||||
6611 | ToFinallyStmt); | ||||||
6612 | } | ||||||
6613 | |||||||
6614 | ExpectedStmt | ||||||
6615 | ASTNodeImporter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { | ||||||
6616 | |||||||
6617 | Error Err = Error::success(); | ||||||
6618 | auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc()); | ||||||
6619 | auto ToSynchExpr = importChecked(Err, S->getSynchExpr()); | ||||||
6620 | auto ToSynchBody = importChecked(Err, S->getSynchBody()); | ||||||
6621 | if (Err) | ||||||
6622 | return std::move(Err); | ||||||
6623 | |||||||
6624 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( | ||||||
6625 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); | ||||||
6626 | } | ||||||
6627 | |||||||
6628 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { | ||||||
6629 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); | ||||||
6630 | if (!ToThrowLocOrErr) | ||||||
6631 | return ToThrowLocOrErr.takeError(); | ||||||
6632 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); | ||||||
6633 | if (!ToThrowExprOrErr) | ||||||
6634 | return ToThrowExprOrErr.takeError(); | ||||||
6635 | return new (Importer.getToContext()) ObjCAtThrowStmt( | ||||||
6636 | *ToThrowLocOrErr, *ToThrowExprOrErr); | ||||||
6637 | } | ||||||
6638 | |||||||
6639 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( | ||||||
6640 | ObjCAutoreleasePoolStmt *S) { | ||||||
6641 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); | ||||||
6642 | if (!ToAtLocOrErr) | ||||||
6643 | return ToAtLocOrErr.takeError(); | ||||||
6644 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); | ||||||
6645 | if (!ToSubStmtOrErr) | ||||||
6646 | return ToSubStmtOrErr.takeError(); | ||||||
6647 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, | ||||||
6648 | *ToSubStmtOrErr); | ||||||
6649 | } | ||||||
6650 | |||||||
6651 | //---------------------------------------------------------------------------- | ||||||
6652 | // Import Expressions | ||||||
6653 | //---------------------------------------------------------------------------- | ||||||
6654 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { | ||||||
6655 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) | ||||||
6656 | << E->getStmtClassName(); | ||||||
6657 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | ||||||
6658 | } | ||||||
6659 | |||||||
6660 | ExpectedStmt ASTNodeImporter::VisitSourceLocExpr(SourceLocExpr *E) { | ||||||
6661 | Error Err = Error::success(); | ||||||
6662 | auto BLoc = importChecked(Err, E->getBeginLoc()); | ||||||
6663 | auto RParenLoc = importChecked(Err, E->getEndLoc()); | ||||||
6664 | if (Err) | ||||||
6665 | return std::move(Err); | ||||||
6666 | auto ParentContextOrErr = Importer.ImportContext(E->getParentContext()); | ||||||
6667 | if (!ParentContextOrErr) | ||||||
6668 | return ParentContextOrErr.takeError(); | ||||||
6669 | |||||||
6670 | return new (Importer.getToContext()) | ||||||
6671 | SourceLocExpr(Importer.getToContext(), E->getIdentKind(), BLoc, RParenLoc, | ||||||
6672 | *ParentContextOrErr); | ||||||
6673 | } | ||||||
6674 | |||||||
6675 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { | ||||||
6676 | |||||||
6677 | Error Err = Error::success(); | ||||||
6678 | auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); | ||||||
6679 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | ||||||
6680 | auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo()); | ||||||
6681 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||
6682 | auto ToType = importChecked(Err, E->getType()); | ||||||
6683 | if (Err) | ||||||
6684 | return std::move(Err); | ||||||
6685 | |||||||
6686 | return new (Importer.getToContext()) VAArgExpr( | ||||||
6687 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, | ||||||
6688 | E->isMicrosoftABI()); | ||||||
6689 | } | ||||||
6690 | |||||||
6691 | ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) { | ||||||
6692 | |||||||
6693 | Error Err = Error::success(); | ||||||
6694 | auto ToCond = importChecked(Err, E->getCond()); | ||||||
6695 | auto ToLHS = importChecked(Err, E->getLHS()); | ||||||
6696 | auto ToRHS = importChecked(Err, E->getRHS()); | ||||||
6697 | auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); | ||||||
6698 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||
6699 | auto ToType = importChecked(Err, E->getType()); | ||||||
6700 | if (Err) | ||||||
6701 | return std::move(Err); | ||||||
6702 | |||||||
6703 | ExprValueKind VK = E->getValueKind(); | ||||||
6704 | ExprObjectKind OK = E->getObjectKind(); | ||||||
6705 | |||||||
6706 | // The value of CondIsTrue only matters if the value is not | ||||||
6707 | // condition-dependent. | ||||||
6708 | bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue(); | ||||||
6709 | |||||||
6710 | return new (Importer.getToContext()) | ||||||
6711 | ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK, | ||||||
6712 | ToRParenLoc, CondIsTrue); | ||||||
6713 | } | ||||||
6714 | |||||||
6715 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { | ||||||
6716 | ExpectedType TypeOrErr = import(E->getType()); | ||||||
6717 | if (!TypeOrErr) | ||||||
6718 | return TypeOrErr.takeError(); | ||||||
6719 | |||||||
6720 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); | ||||||
6721 | if (!BeginLocOrErr) | ||||||
6722 | return BeginLocOrErr.takeError(); | ||||||
6723 | |||||||
6724 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); | ||||||
6725 | } | ||||||
6726 | |||||||
6727 | ExpectedStmt | ||||||
6728 | ASTNodeImporter::VisitGenericSelectionExpr(GenericSelectionExpr *E) { | ||||||
6729 | Error Err = Error::success(); | ||||||
6730 | auto ToGenericLoc = importChecked(Err, E->getGenericLoc()); | ||||||
6731 | auto *ToControllingExpr = importChecked(Err, E->getControllingExpr()); | ||||||
6732 | auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc()); | ||||||
6733 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||
6734 | if (Err) | ||||||
6735 | return std::move(Err); | ||||||
6736 | |||||||
6737 | ArrayRef<const TypeSourceInfo *> FromAssocTypes(E->getAssocTypeSourceInfos()); | ||||||
6738 | SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size()); | ||||||
6739 | if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes)) | ||||||
6740 | return std::move(Err); | ||||||
6741 | |||||||
6742 | ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs()); | ||||||
6743 | SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size()); | ||||||
6744 | if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs)) | ||||||
6745 | return std::move(Err); | ||||||
6746 | |||||||
6747 | const ASTContext &ToCtx = Importer.getToContext(); | ||||||
6748 | if (E->isResultDependent()) { | ||||||
6749 | return GenericSelectionExpr::Create( | ||||||
6750 | ToCtx, ToGenericLoc, ToControllingExpr, | ||||||
6751 | llvm::makeArrayRef(ToAssocTypes), llvm::makeArrayRef(ToAssocExprs), | ||||||
6752 | ToDefaultLoc, ToRParenLoc, E->containsUnexpandedParameterPack()); | ||||||
6753 | } | ||||||
6754 | |||||||
6755 | return GenericSelectionExpr::Create( | ||||||
6756 | ToCtx, ToGenericLoc, ToControllingExpr, llvm::makeArrayRef(ToAssocTypes), | ||||||
6757 | llvm::makeArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc, | ||||||
6758 | E->containsUnexpandedParameterPack(), E->getResultIndex()); | ||||||
6759 | } | ||||||
6760 | |||||||
6761 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { | ||||||
6762 | |||||||
6763 | Error Err = Error::success(); | ||||||
6764 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); | ||||||
6765 | auto ToType = importChecked(Err, E->getType()); | ||||||
6766 | auto ToFunctionName = importChecked(Err, E->getFunctionName()); | ||||||
6767 | if (Err) | ||||||
6768 | return std::move(Err); | ||||||
6769 | |||||||
6770 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, | ||||||
6771 | E->getIdentKind(), ToFunctionName); | ||||||
6772 | } | ||||||
6773 | |||||||
6774 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { | ||||||
6775 | |||||||
6776 | Error Err = Error::success(); | ||||||
6777 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); | ||||||
6778 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); | ||||||
6779 | auto ToDecl = importChecked(Err, E->getDecl()); | ||||||
6780 | auto ToLocation = importChecked(Err, E->getLocation()); | ||||||
6781 | auto ToType = importChecked(Err, E->getType()); | ||||||
6782 | if (Err) | ||||||
6783 | return std::move(Err); | ||||||
6784 | |||||||
6785 | NamedDecl *ToFoundD = nullptr; | ||||||
6786 | if (E->getDecl() != E->getFoundDecl()) { | ||||||
6787 | auto FoundDOrErr = import(E->getFoundDecl()); | ||||||
6788 | if (!FoundDOrErr) | ||||||
6789 | return FoundDOrErr.takeError(); | ||||||
6790 | ToFoundD = *FoundDOrErr; | ||||||
6791 | } | ||||||
6792 | |||||||
6793 | TemplateArgumentListInfo ToTAInfo; | ||||||
6794 | TemplateArgumentListInfo *ToResInfo = nullptr; | ||||||
6795 | if (E->hasExplicitTemplateArgs()) { | ||||||
6796 | if (Error Err = | ||||||
6797 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), | ||||||
6798 | E->template_arguments(), ToTAInfo)) | ||||||
6799 | return std::move(Err); | ||||||
6800 | ToResInfo = &ToTAInfo; | ||||||
6801 | } | ||||||
6802 | |||||||
6803 | auto *ToE = DeclRefExpr::Create( | ||||||
6804 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, | ||||||
6805 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, | ||||||
6806 | E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse()); | ||||||
6807 | if (E->hadMultipleCandidates()) | ||||||
6808 | ToE->setHadMultipleCandidates(true); | ||||||
6809 | return ToE; | ||||||
6810 | } | ||||||
6811 | |||||||
6812 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { | ||||||
6813 | ExpectedType TypeOrErr = import(E->getType()); | ||||||
6814 | if (!TypeOrErr) | ||||||
6815 | return TypeOrErr.takeError(); | ||||||
6816 | |||||||
6817 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); | ||||||
6818 | } | ||||||
6819 | |||||||
6820 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { | ||||||
6821 | ExpectedExpr ToInitOrErr = import(E->getInit()); | ||||||
6822 | if (!ToInitOrErr) | ||||||
6823 | return ToInitOrErr.takeError(); | ||||||
6824 | |||||||
6825 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); | ||||||
6826 | if (!ToEqualOrColonLocOrErr) | ||||||
6827 | return ToEqualOrColonLocOrErr.takeError(); | ||||||
6828 | |||||||
6829 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); | ||||||
6830 | // List elements from the second, the first is Init itself | ||||||
6831 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { | ||||||
6832 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) | ||||||
6833 | ToIndexExprs[I - 1] = *ToArgOrErr; | ||||||
6834 | else | ||||||
6835 | return ToArgOrErr.takeError(); | ||||||
6836 | } | ||||||
6837 | |||||||
6838 | SmallVector<Designator, 4> ToDesignators(E->size()); | ||||||
6839 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) | ||||||
6840 | return std::move(Err); | ||||||
6841 | |||||||
6842 | return DesignatedInitExpr::Create( | ||||||
6843 | Importer.getToContext(), ToDesignators, | ||||||
6844 | ToIndexExprs, *ToEqualOrColonLocOrErr, | ||||||
6845 | E->usesGNUSyntax(), *ToInitOrErr); | ||||||
6846 | } | ||||||
6847 | |||||||
6848 | ExpectedStmt | ||||||
6849 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { | ||||||
6850 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||
6851 | if (!ToTypeOrErr) | ||||||
6852 | return ToTypeOrErr.takeError(); | ||||||
6853 | |||||||
6854 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | ||||||
6855 | if (!ToLocationOrErr) | ||||||
6856 | return ToLocationOrErr.takeError(); | ||||||
6857 | |||||||
6858 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( | ||||||
6859 | *ToTypeOrErr, *ToLocationOrErr); | ||||||
6860 | } | ||||||
6861 | |||||||
6862 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { | ||||||
6863 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||
6864 | if (!ToTypeOrErr) | ||||||
6865 | return ToTypeOrErr.takeError(); | ||||||
6866 | |||||||
6867 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | ||||||
6868 | if (!ToLocationOrErr) | ||||||
6869 | return ToLocationOrErr.takeError(); | ||||||
6870 | |||||||
6871 | return IntegerLiteral::Create( | ||||||
6872 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); | ||||||
6873 | } | ||||||
6874 | |||||||
6875 | |||||||
6876 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { | ||||||
6877 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||
6878 | if (!ToTypeOrErr) | ||||||
6879 | return ToTypeOrErr.takeError(); | ||||||
6880 | |||||||
6881 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | ||||||
6882 | if (!ToLocationOrErr) | ||||||
6883 | return ToLocationOrErr.takeError(); | ||||||
6884 | |||||||
6885 | return FloatingLiteral::Create( | ||||||
6886 | Importer.getToContext(), E->getValue(), E->isExact(), | ||||||
6887 | *ToTypeOrErr, *ToLocationOrErr); | ||||||
6888 | } | ||||||
6889 | |||||||
6890 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { | ||||||
6891 | auto ToTypeOrErr = import(E->getType()); | ||||||
6892 | if (!ToTypeOrErr) | ||||||
6893 | return ToTypeOrErr.takeError(); | ||||||
6894 | |||||||
6895 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | ||||||
6896 | if (!ToSubExprOrErr) | ||||||
6897 | return ToSubExprOrErr.takeError(); | ||||||
6898 | |||||||
6899 | return new (Importer.getToContext()) ImaginaryLiteral( | ||||||
6900 | *ToSubExprOrErr, *ToTypeOrErr); | ||||||
6901 | } | ||||||
6902 | |||||||
6903 | ExpectedStmt ASTNodeImporter::VisitFixedPointLiteral(FixedPointLiteral *E) { | ||||||
6904 | auto ToTypeOrErr = import(E->getType()); | ||||||
6905 | if (!ToTypeOrErr) | ||||||
6906 | return ToTypeOrErr.takeError(); | ||||||
6907 | |||||||
6908 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | ||||||
6909 | if (!ToLocationOrErr) | ||||||
6910 | return ToLocationOrErr.takeError(); | ||||||
6911 | |||||||
6912 | return new (Importer.getToContext()) FixedPointLiteral( | ||||||
6913 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr, | ||||||
6914 | Importer.getToContext().getFixedPointScale(*ToTypeOrErr)); | ||||||
6915 | } | ||||||
6916 | |||||||
6917 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { | ||||||
6918 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||
6919 | if (!ToTypeOrErr) | ||||||
6920 | return ToTypeOrErr.takeError(); | ||||||
6921 | |||||||
6922 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | ||||||
6923 | if (!ToLocationOrErr) | ||||||
6924 | return ToLocationOrErr.takeError(); | ||||||
6925 | |||||||
6926 | return new (Importer.getToContext()) CharacterLiteral( | ||||||
6927 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); | ||||||
6928 | } | ||||||
6929 | |||||||
6930 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { | ||||||
6931 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||
6932 | if (!ToTypeOrErr) | ||||||
6933 | return ToTypeOrErr.takeError(); | ||||||
6934 | |||||||
6935 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); | ||||||
6936 | if (Error Err = ImportArrayChecked( | ||||||
6937 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) | ||||||
6938 | return std::move(Err); | ||||||
6939 | |||||||
6940 | return StringLiteral::Create( | ||||||
6941 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), | ||||||
6942 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); | ||||||
6943 | } | ||||||
6944 | |||||||
6945 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { | ||||||
6946 | |||||||
6947 | Error Err = Error::success(); | ||||||
6948 | auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); | ||||||
6949 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); | ||||||
6950 | auto ToType = importChecked(Err, E->getType()); | ||||||
6951 | auto ToInitializer = importChecked(Err, E->getInitializer()); | ||||||
6952 | if (Err) | ||||||
6953 | return std::move(Err); | ||||||
6954 | |||||||
6955 | return new (Importer.getToContext()) CompoundLiteralExpr( | ||||||
6956 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), | ||||||
6957 | ToInitializer, E->isFileScope()); | ||||||
6958 | } | ||||||
6959 | |||||||
6960 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { | ||||||
6961 | |||||||
6962 | Error Err = Error::success(); | ||||||
6963 | auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); | ||||||
6964 | auto ToType = importChecked(Err, E->getType()); | ||||||
6965 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||
6966 | if (Err) | ||||||
6967 | return std::move(Err); | ||||||
6968 | |||||||
6969 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); | ||||||
6970 | if (Error Err = ImportArrayChecked( | ||||||
6971 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), | ||||||
6972 | ToExprs.begin())) | ||||||
6973 | return std::move(Err); | ||||||
6974 | |||||||
6975 | return new (Importer.getToContext()) AtomicExpr( | ||||||
6976 | |||||||
6977 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); | ||||||
6978 | } | ||||||
6979 | |||||||
6980 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { | ||||||
6981 | Error Err = Error::success(); | ||||||
6982 | auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc()); | ||||||
6983 | auto ToLabelLoc = importChecked(Err, E->getLabelLoc()); | ||||||
6984 | auto ToLabel = importChecked(Err, E->getLabel()); | ||||||
6985 | auto ToType = importChecked(Err, E->getType()); | ||||||
6986 | if (Err) | ||||||
6987 | return std::move(Err); | ||||||
6988 | |||||||
6989 | return new (Importer.getToContext()) AddrLabelExpr( | ||||||
6990 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); | ||||||
6991 | } | ||||||
6992 | ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { | ||||||
6993 | Error Err = Error::success(); | ||||||
6994 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | ||||||
6995 | auto ToResult = importChecked(Err, E->getAPValueResult()); | ||||||
6996 | if (Err) | ||||||
6997 | return std::move(Err); | ||||||
6998 | |||||||
6999 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult); | ||||||
7000 | } | ||||||
7001 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { | ||||||
7002 | Error Err = Error::success(); | ||||||
7003 | auto ToLParen = importChecked(Err, E->getLParen()); | ||||||
7004 | auto ToRParen = importChecked(Err, E->getRParen()); | ||||||
7005 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | ||||||
7006 | if (Err) | ||||||
7007 | return std::move(Err); | ||||||
7008 | |||||||
7009 | return new (Importer.getToContext()) | ||||||
7010 | ParenExpr(ToLParen, ToRParen, ToSubExpr); | ||||||
7011 | } | ||||||
7012 | |||||||
7013 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { | ||||||
7014 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); | ||||||
7015 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) | ||||||
7016 | return std::move(Err); | ||||||
7017 | |||||||
7018 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); | ||||||
7019 | if (!ToLParenLocOrErr) | ||||||
7020 | return ToLParenLocOrErr.takeError(); | ||||||
7021 | |||||||
7022 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); | ||||||
7023 | if (!ToRParenLocOrErr) | ||||||
7024 | return ToRParenLocOrErr.takeError(); | ||||||
7025 | |||||||
7026 | return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr, | ||||||
7027 | ToExprs, *ToRParenLocOrErr); | ||||||
7028 | } | ||||||
7029 | |||||||
7030 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { | ||||||
7031 | Error Err = Error::success(); | ||||||
7032 | auto ToSubStmt = importChecked(Err, E->getSubStmt()); | ||||||
7033 | auto ToType = importChecked(Err, E->getType()); | ||||||
7034 | auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); | ||||||
7035 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||
7036 | if (Err) | ||||||
7037 | return std::move(Err); | ||||||
7038 | |||||||
7039 | return new (Importer.getToContext()) | ||||||
7040 | StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc, | ||||||
7041 | E->getTemplateDepth()); | ||||||
7042 | } | ||||||
7043 | |||||||
7044 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { | ||||||
7045 | Error Err = Error::success(); | ||||||
7046 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | ||||||
7047 | auto ToType = importChecked(Err, E->getType()); | ||||||
7048 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||
7049 | if (Err) | ||||||
7050 | return std::move(Err); | ||||||
7051 | |||||||
7052 | return UnaryOperator::Create( | ||||||
7053 | Importer.getToContext(), ToSubExpr, E->getOpcode(), ToType, | ||||||
7054 | E->getValueKind(), E->getObjectKind(), ToOperatorLoc, E->canOverflow(), | ||||||
7055 | E->getFPOptionsOverride()); | ||||||
7056 | } | ||||||
7057 | |||||||
7058 | ExpectedStmt | ||||||
7059 | |||||||
7060 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { | ||||||
7061 | Error Err = Error::success(); | ||||||
7062 | auto ToType = importChecked(Err, E->getType()); | ||||||
7063 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||
7064 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||
7065 | if (Err) | ||||||
7066 | return std::move(Err); | ||||||
7067 | |||||||
7068 | if (E->isArgumentType()) { | ||||||
7069 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = | ||||||
7070 | import(E->getArgumentTypeInfo()); | ||||||
7071 | if (!ToArgumentTypeInfoOrErr) | ||||||
7072 | return ToArgumentTypeInfoOrErr.takeError(); | ||||||
7073 | |||||||
7074 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( | ||||||
7075 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, | ||||||
7076 | ToRParenLoc); | ||||||
7077 | } | ||||||
7078 | |||||||
7079 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); | ||||||
7080 | if (!ToArgumentExprOrErr) | ||||||
7081 | return ToArgumentExprOrErr.takeError(); | ||||||
7082 | |||||||
7083 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( | ||||||
7084 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); | ||||||
7085 | } | ||||||
7086 | |||||||
7087 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { | ||||||
7088 | Error Err = Error::success(); | ||||||
7089 | auto ToLHS = importChecked(Err, E->getLHS()); | ||||||
7090 | auto ToRHS = importChecked(Err, E->getRHS()); | ||||||
7091 | auto ToType = importChecked(Err, E->getType()); | ||||||
7092 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||
7093 | if (Err) | ||||||
7094 | return std::move(Err); | ||||||
7095 | |||||||
7096 | return BinaryOperator::Create( | ||||||
7097 | Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType, | ||||||
7098 | E->getValueKind(), E->getObjectKind(), ToOperatorLoc, | ||||||
7099 | E->getFPFeatures(Importer.getFromContext().getLangOpts())); | ||||||
7100 | } | ||||||
7101 | |||||||
7102 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { | ||||||
7103 | Error Err = Error::success(); | ||||||
7104 | auto ToCond = importChecked(Err, E->getCond()); | ||||||
7105 | auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc()); | ||||||
7106 | auto ToLHS = importChecked(Err, E->getLHS()); | ||||||
7107 | auto ToColonLoc = importChecked(Err, E->getColonLoc()); | ||||||
7108 | auto ToRHS = importChecked(Err, E->getRHS()); | ||||||
7109 | auto ToType = importChecked(Err, E->getType()); | ||||||
7110 | if (Err) | ||||||
7111 | return std::move(Err); | ||||||
7112 | |||||||
7113 | return new (Importer.getToContext()) ConditionalOperator( | ||||||
7114 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, | ||||||
7115 | E->getValueKind(), E->getObjectKind()); | ||||||
7116 | } | ||||||
7117 | |||||||
7118 | ExpectedStmt | ||||||
7119 | ASTNodeImporter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) { | ||||||
7120 | Error Err = Error::success(); | ||||||
7121 | auto ToCommon = importChecked(Err, E->getCommon()); | ||||||
7122 | auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue()); | ||||||
7123 | auto ToCond = importChecked(Err, E->getCond()); | ||||||
7124 | auto ToTrueExpr = importChecked(Err, E->getTrueExpr()); | ||||||
7125 | auto ToFalseExpr = importChecked(Err, E->getFalseExpr()); | ||||||
7126 | auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc()); | ||||||
7127 | auto ToColonLoc = importChecked(Err, E->getColonLoc()); | ||||||
7128 | auto ToType = importChecked(Err, E->getType()); | ||||||
7129 | if (Err) | ||||||
7130 | return std::move(Err); | ||||||
7131 | |||||||
7132 | return new (Importer.getToContext()) BinaryConditionalOperator( | ||||||
7133 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, | ||||||
7134 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), | ||||||
7135 | E->getObjectKind()); | ||||||
7136 | } | ||||||
7137 | |||||||
7138 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { | ||||||
7139 | Error Err = Error::success(); | ||||||
7140 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); | ||||||
7141 | auto ToQueriedTypeSourceInfo = | ||||||
7142 | importChecked(Err, E->getQueriedTypeSourceInfo()); | ||||||
7143 | auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression()); | ||||||
7144 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); | ||||||
7145 | auto ToType = importChecked(Err, E->getType()); | ||||||
7146 | if (Err) | ||||||
7147 | return std::move(Err); | ||||||
7148 | |||||||
7149 | return new (Importer.getToContext()) ArrayTypeTraitExpr( | ||||||
7150 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), | ||||||
7151 | ToDimensionExpression, ToEndLoc, ToType); | ||||||
7152 | } | ||||||
7153 | |||||||
7154 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { | ||||||
7155 | Error Err = Error::success(); | ||||||
7156 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); | ||||||
7157 | auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression()); | ||||||
7158 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); | ||||||
7159 | auto ToType = importChecked(Err, E->getType()); | ||||||
7160 | if (Err) | ||||||
7161 | return std::move(Err); | ||||||
7162 | |||||||
7163 | return new (Importer.getToContext()) ExpressionTraitExpr( | ||||||
7164 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), | ||||||
7165 | ToEndLoc, ToType); | ||||||
7166 | } | ||||||
7167 | |||||||
7168 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { | ||||||
7169 | Error Err = Error::success(); | ||||||
7170 | auto ToLocation = importChecked(Err, E->getLocation()); | ||||||
7171 | auto ToType = importChecked(Err, E->getType()); | ||||||
7172 | auto ToSourceExpr = importChecked(Err, E->getSourceExpr()); | ||||||
7173 | if (Err) | ||||||
7174 | return std::move(Err); | ||||||
7175 | |||||||
7176 | return new (Importer.getToContext()) OpaqueValueExpr( | ||||||
7177 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); | ||||||
7178 | } | ||||||
7179 | |||||||
7180 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { | ||||||
7181 | Error Err = Error::success(); | ||||||
7182 | auto ToLHS = importChecked(Err, E->getLHS()); | ||||||
7183 | auto ToRHS = importChecked(Err, E->getRHS()); | ||||||
7184 | auto ToType = importChecked(Err, E->getType()); | ||||||
7185 | auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc()); | ||||||
7186 | if (Err) | ||||||
7187 | return std::move(Err); | ||||||
7188 | |||||||
7189 | return new (Importer.getToContext()) ArraySubscriptExpr( | ||||||
7190 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), | ||||||
7191 | ToRBracketLoc); | ||||||
7192 | } | ||||||
7193 | |||||||
7194 | ExpectedStmt | ||||||
7195 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { | ||||||
7196 | Error Err = Error::success(); | ||||||
7197 | auto ToLHS = importChecked(Err, E->getLHS()); | ||||||
7198 | auto ToRHS = importChecked(Err, E->getRHS()); | ||||||
7199 | auto ToType = importChecked(Err, E->getType()); | ||||||
7200 | auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType()); | ||||||
7201 | auto ToComputationResultType = | ||||||
7202 | importChecked(Err, E->getComputationResultType()); | ||||||
7203 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||
7204 | if (Err) | ||||||
7205 | return std::move(Err); | ||||||
7206 | |||||||
7207 | return CompoundAssignOperator::Create( | ||||||
7208 | Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType, | ||||||
7209 | E->getValueKind(), E->getObjectKind(), ToOperatorLoc, | ||||||
7210 | E->getFPFeatures(Importer.getFromContext().getLangOpts()), | ||||||
7211 | ToComputationLHSType, ToComputationResultType); | ||||||
7212 | } | ||||||
7213 | |||||||
7214 | Expected<CXXCastPath> | ||||||
7215 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { | ||||||
7216 | CXXCastPath Path; | ||||||
7217 | for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) { | ||||||
7218 | if (auto SpecOrErr = import(*I)) | ||||||
7219 | Path.push_back(*SpecOrErr); | ||||||
7220 | else | ||||||
7221 | return SpecOrErr.takeError(); | ||||||
7222 | } | ||||||
7223 | return Path; | ||||||
7224 | } | ||||||
7225 | |||||||
7226 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { | ||||||
7227 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||
7228 | if (!ToTypeOrErr) | ||||||
7229 | return ToTypeOrErr.takeError(); | ||||||
7230 | |||||||
7231 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | ||||||
7232 | if (!ToSubExprOrErr) | ||||||
7233 | return ToSubExprOrErr.takeError(); | ||||||
7234 | |||||||
7235 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); | ||||||
7236 | if (!ToBasePathOrErr) | ||||||
7237 | return ToBasePathOrErr.takeError(); | ||||||
7238 | |||||||
7239 | return ImplicitCastExpr::Create( | ||||||
7240 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, | ||||||
7241 | &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures()); | ||||||
7242 | } | ||||||
7243 | |||||||
7244 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { | ||||||
7245 | Error Err = Error::success(); | ||||||
7246 | auto ToType = importChecked(Err, E->getType()); | ||||||
7247 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | ||||||
7248 | auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten()); | ||||||
7249 | if (Err) | ||||||
7250 | return std::move(Err); | ||||||
7251 | |||||||
7252 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); | ||||||
7253 | if (!ToBasePathOrErr) | ||||||
7254 | return ToBasePathOrErr.takeError(); | ||||||
7255 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); | ||||||
7256 | |||||||
7257 | switch (E->getStmtClass()) { | ||||||
7258 | case Stmt::CStyleCastExprClass: { | ||||||
7259 | auto *CCE = cast<CStyleCastExpr>(E); | ||||||
7260 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); | ||||||
7261 | if (!ToLParenLocOrErr) | ||||||
7262 | return ToLParenLocOrErr.takeError(); | ||||||
7263 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); | ||||||
7264 | if (!ToRParenLocOrErr) | ||||||
7265 | return ToRParenLocOrErr.takeError(); | ||||||
7266 | return CStyleCastExpr::Create( | ||||||
7267 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), | ||||||
7268 | ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten, | ||||||
7269 | *ToLParenLocOrErr, *ToRParenLocOrErr); | ||||||
7270 | } | ||||||
7271 | |||||||
7272 | case Stmt::CXXFunctionalCastExprClass: { | ||||||
7273 | auto *FCE = cast<CXXFunctionalCastExpr>(E); | ||||||
7274 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); | ||||||
7275 | if (!ToLParenLocOrErr) | ||||||
7276 | return ToLParenLocOrErr.takeError(); | ||||||
7277 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); | ||||||
7278 | if (!ToRParenLocOrErr) | ||||||
7279 | return ToRParenLocOrErr.takeError(); | ||||||
7280 | return CXXFunctionalCastExpr::Create( | ||||||
7281 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, | ||||||
7282 | E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(), | ||||||
7283 | *ToLParenLocOrErr, *ToRParenLocOrErr); | ||||||
7284 | } | ||||||
7285 | |||||||
7286 | case Stmt::ObjCBridgedCastExprClass: { | ||||||
7287 | auto *OCE = cast<ObjCBridgedCastExpr>(E); | ||||||
7288 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); | ||||||
7289 | if (!ToLParenLocOrErr) | ||||||
7290 | return ToLParenLocOrErr.takeError(); | ||||||
7291 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); | ||||||
7292 | if (!ToBridgeKeywordLocOrErr) | ||||||
7293 | return ToBridgeKeywordLocOrErr.takeError(); | ||||||
7294 | return new (Importer.getToContext()) ObjCBridgedCastExpr( | ||||||
7295 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), | ||||||
7296 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); | ||||||
7297 | } | ||||||
7298 | default: | ||||||
7299 | llvm_unreachable("Cast expression of unsupported type!")::llvm::llvm_unreachable_internal("Cast expression of unsupported type!" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 7299); | ||||||
7300 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | ||||||
7301 | } | ||||||
7302 | } | ||||||
7303 | |||||||
7304 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { | ||||||
7305 | SmallVector<OffsetOfNode, 4> ToNodes; | ||||||
7306 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { | ||||||
7307 | const OffsetOfNode &FromNode = E->getComponent(I); | ||||||
7308 | |||||||
7309 | SourceLocation ToBeginLoc, ToEndLoc; | ||||||
7310 | |||||||
7311 | if (FromNode.getKind() != OffsetOfNode::Base) { | ||||||
7312 | Error Err = Error::success(); | ||||||
7313 | ToBeginLoc = importChecked(Err, FromNode.getBeginLoc()); | ||||||
7314 | ToEndLoc = importChecked(Err, FromNode.getEndLoc()); | ||||||
7315 | if (Err) | ||||||
7316 | return std::move(Err); | ||||||
7317 | } | ||||||
7318 | |||||||
7319 | switch (FromNode.getKind()) { | ||||||
7320 | case OffsetOfNode::Array: | ||||||
7321 | ToNodes.push_back( | ||||||
7322 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); | ||||||
7323 | break; | ||||||
7324 | case OffsetOfNode::Base: { | ||||||
7325 | auto ToBSOrErr = import(FromNode.getBase()); | ||||||
7326 | if (!ToBSOrErr) | ||||||
7327 | return ToBSOrErr.takeError(); | ||||||
7328 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); | ||||||
7329 | break; | ||||||
7330 | } | ||||||
7331 | case OffsetOfNode::Field: { | ||||||
7332 | auto ToFieldOrErr = import(FromNode.getField()); | ||||||
7333 | if (!ToFieldOrErr) | ||||||
7334 | return ToFieldOrErr.takeError(); | ||||||
7335 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); | ||||||
7336 | break; | ||||||
7337 | } | ||||||
7338 | case OffsetOfNode::Identifier: { | ||||||
7339 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); | ||||||
7340 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); | ||||||
7341 | break; | ||||||
7342 | } | ||||||
7343 | } | ||||||
7344 | } | ||||||
7345 | |||||||
7346 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); | ||||||
7347 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { | ||||||
7348 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); | ||||||
7349 | if (!ToIndexExprOrErr) | ||||||
7350 | return ToIndexExprOrErr.takeError(); | ||||||
7351 | ToExprs[I] = *ToIndexExprOrErr; | ||||||
7352 | } | ||||||
7353 | |||||||
7354 | Error Err = Error::success(); | ||||||
7355 | auto ToType = importChecked(Err, E->getType()); | ||||||
7356 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); | ||||||
7357 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||
7358 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||
7359 | if (Err) | ||||||
7360 | return std::move(Err); | ||||||
7361 | |||||||
7362 | return OffsetOfExpr::Create( | ||||||
7363 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, | ||||||
7364 | ToExprs, ToRParenLoc); | ||||||
7365 | } | ||||||
7366 | |||||||
7367 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { | ||||||
7368 | Error Err = Error::success(); | ||||||
7369 | auto ToType = importChecked(Err, E->getType()); | ||||||
7370 | auto ToOperand = importChecked(Err, E->getOperand()); | ||||||
7371 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); | ||||||
7372 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); | ||||||
7373 | if (Err) | ||||||
7374 | return std::move(Err); | ||||||
7375 | |||||||
7376 | CanThrowResult ToCanThrow; | ||||||
7377 | if (E->isValueDependent()) | ||||||
7378 | ToCanThrow = CT_Dependent; | ||||||
7379 | else | ||||||
7380 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; | ||||||
7381 | |||||||
7382 | return new (Importer.getToContext()) CXXNoexceptExpr( | ||||||
7383 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); | ||||||
7384 | } | ||||||
7385 | |||||||
7386 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { | ||||||
7387 | Error Err = Error::success(); | ||||||
7388 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | ||||||
7389 | auto ToType = importChecked(Err, E->getType()); | ||||||
7390 | auto ToThrowLoc = importChecked(Err, E->getThrowLoc()); | ||||||
7391 | if (Err) | ||||||
7392 | return std::move(Err); | ||||||
7393 | |||||||
7394 | return new (Importer.getToContext()) CXXThrowExpr( | ||||||
7395 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); | ||||||
7396 | } | ||||||
7397 | |||||||
7398 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { | ||||||
7399 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); | ||||||
7400 | if (!ToUsedLocOrErr) | ||||||
7401 | return ToUsedLocOrErr.takeError(); | ||||||
7402 | |||||||
7403 | auto ToParamOrErr = import(E->getParam()); | ||||||
7404 | if (!ToParamOrErr) | ||||||
7405 | return ToParamOrErr.takeError(); | ||||||
7406 | |||||||
7407 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); | ||||||
7408 | if (!UsedContextOrErr) | ||||||
7409 | return UsedContextOrErr.takeError(); | ||||||
7410 | |||||||
7411 | // Import the default arg if it was not imported yet. | ||||||
7412 | // This is needed because it can happen that during the import of the | ||||||
7413 | // default expression (from VisitParmVarDecl) the same ParmVarDecl is | ||||||
7414 | // encountered here. The default argument for a ParmVarDecl is set in the | ||||||
7415 | // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here, | ||||||
7416 | // see VisitParmVarDecl). | ||||||
7417 | ParmVarDecl *ToParam = *ToParamOrErr; | ||||||
7418 | if (!ToParam->getDefaultArg()) { | ||||||
7419 | Optional<ParmVarDecl *> FromParam = Importer.getImportedFromDecl(ToParam); | ||||||
7420 | assert(FromParam && "ParmVarDecl was not imported?")(static_cast <bool> (FromParam && "ParmVarDecl was not imported?" ) ? void (0) : __assert_fail ("FromParam && \"ParmVarDecl was not imported?\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 7420, __extension__ __PRETTY_FUNCTION__)); | ||||||
7421 | |||||||
7422 | if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam)) | ||||||
7423 | return std::move(Err); | ||||||
7424 | } | ||||||
7425 | |||||||
7426 | return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr, | ||||||
7427 | *ToParamOrErr, *UsedContextOrErr); | ||||||
7428 | } | ||||||
7429 | |||||||
7430 | ExpectedStmt | ||||||
7431 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { | ||||||
7432 | Error Err = Error::success(); | ||||||
7433 | auto ToType = importChecked(Err, E->getType()); | ||||||
7434 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); | ||||||
7435 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||
7436 | if (Err) | ||||||
7437 | return std::move(Err); | ||||||
7438 | |||||||
7439 | return new (Importer.getToContext()) CXXScalarValueInitExpr( | ||||||
7440 | ToType, ToTypeSourceInfo, ToRParenLoc); | ||||||
7441 | } | ||||||
7442 | |||||||
7443 | ExpectedStmt | ||||||
7444 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { | ||||||
7445 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | ||||||
7446 | if (!ToSubExprOrErr) | ||||||
7447 | return ToSubExprOrErr.takeError(); | ||||||
7448 | |||||||
7449 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); | ||||||
7450 | if (!ToDtorOrErr) | ||||||
7451 | return ToDtorOrErr.takeError(); | ||||||
7452 | |||||||
7453 | ASTContext &ToCtx = Importer.getToContext(); | ||||||
7454 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); | ||||||
7455 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); | ||||||
7456 | } | ||||||
7457 | |||||||
7458 | ExpectedStmt | ||||||
7459 | |||||||
7460 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { | ||||||
7461 | Error Err = Error::success(); | ||||||
7462 | auto ToConstructor = importChecked(Err, E->getConstructor()); | ||||||
7463 | auto ToType = importChecked(Err, E->getType()); | ||||||
7464 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); | ||||||
7465 | auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange()); | ||||||
7466 | if (Err) | ||||||
7467 | return std::move(Err); | ||||||
7468 | |||||||
7469 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); | ||||||
7470 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | ||||||
7471 | return std::move(Err); | ||||||
7472 | |||||||
7473 | return CXXTemporaryObjectExpr::Create( | ||||||
7474 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, | ||||||
7475 | ToParenOrBraceRange, E->hadMultipleCandidates(), | ||||||
7476 | E->isListInitialization(), E->isStdInitListInitialization(), | ||||||
7477 | E->requiresZeroInitialization()); | ||||||
7478 | } | ||||||
7479 | |||||||
7480 | ExpectedDecl ASTNodeImporter::VisitLifetimeExtendedTemporaryDecl( | ||||||
7481 | LifetimeExtendedTemporaryDecl *D) { | ||||||
7482 | DeclContext *DC, *LexicalDC; | ||||||
7483 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | ||||||
7484 | return std::move(Err); | ||||||
7485 | |||||||
7486 | Error Err = Error::success(); | ||||||
7487 | auto Temporary = importChecked(Err, D->getTemporaryExpr()); | ||||||
7488 | auto ExtendingDecl = importChecked(Err, D->getExtendingDecl()); | ||||||
7489 | if (Err) | ||||||
7490 | return std::move(Err); | ||||||
7491 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? | ||||||
7492 | |||||||
7493 | LifetimeExtendedTemporaryDecl *To; | ||||||
7494 | if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl, | ||||||
7495 | D->getManglingNumber())) | ||||||
7496 | return To; | ||||||
7497 | |||||||
7498 | To->setLexicalDeclContext(LexicalDC); | ||||||
7499 | LexicalDC->addDeclInternal(To); | ||||||
7500 | return To; | ||||||
7501 | } | ||||||
7502 | |||||||
7503 | ExpectedStmt | ||||||
7504 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { | ||||||
7505 | Error Err = Error::success(); | ||||||
7506 | auto ToType = importChecked(Err, E->getType()); | ||||||
7507 | Expr *ToTemporaryExpr = importChecked( | ||||||
7508 | Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr()); | ||||||
7509 | auto ToMaterializedDecl = | ||||||
7510 | importChecked(Err, E->getLifetimeExtendedTemporaryDecl()); | ||||||
7511 | if (Err) | ||||||
7512 | return std::move(Err); | ||||||
7513 | |||||||
7514 | if (!ToTemporaryExpr) | ||||||
7515 | ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr()); | ||||||
7516 | |||||||
7517 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( | ||||||
7518 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference(), | ||||||
7519 | ToMaterializedDecl); | ||||||
7520 | |||||||
7521 | return ToMTE; | ||||||
7522 | } | ||||||
7523 | |||||||
7524 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { | ||||||
7525 | Error Err = Error::success(); | ||||||
7526 | auto ToType = importChecked(Err, E->getType()); | ||||||
7527 | auto ToPattern = importChecked(Err, E->getPattern()); | ||||||
7528 | auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc()); | ||||||
7529 | if (Err) | ||||||
7530 | return std::move(Err); | ||||||
7531 | |||||||
7532 | return new (Importer.getToContext()) PackExpansionExpr( | ||||||
7533 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); | ||||||
7534 | } | ||||||
7535 | |||||||
7536 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { | ||||||
7537 | Error Err = Error::success(); | ||||||
7538 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||
7539 | auto ToPack = importChecked(Err, E->getPack()); | ||||||
7540 | auto ToPackLoc = importChecked(Err, E->getPackLoc()); | ||||||
7541 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||
7542 | if (Err) | ||||||
7543 | return std::move(Err); | ||||||
7544 | |||||||
7545 | Optional<unsigned> Length; | ||||||
7546 | if (!E->isValueDependent()) | ||||||
7547 | Length = E->getPackLength(); | ||||||
7548 | |||||||
7549 | SmallVector<TemplateArgument, 8> ToPartialArguments; | ||||||
7550 | if (E->isPartiallySubstituted()) { | ||||||
7551 | if (Error Err = ImportTemplateArguments( | ||||||
7552 | E->getPartialArguments().data(), | ||||||
7553 | E->getPartialArguments().size(), | ||||||
7554 | ToPartialArguments)) | ||||||
7555 | return std::move(Err); | ||||||
7556 | } | ||||||
7557 | |||||||
7558 | return SizeOfPackExpr::Create( | ||||||
7559 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, | ||||||
7560 | Length, ToPartialArguments); | ||||||
7561 | } | ||||||
7562 | |||||||
7563 | |||||||
7564 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { | ||||||
7565 | Error Err = Error::success(); | ||||||
7566 | auto ToOperatorNew = importChecked(Err, E->getOperatorNew()); | ||||||
7567 | auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete()); | ||||||
7568 | auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens()); | ||||||
7569 | auto ToArraySize = importChecked(Err, E->getArraySize()); | ||||||
7570 | auto ToInitializer = importChecked(Err, E->getInitializer()); | ||||||
7571 | auto ToType = importChecked(Err, E->getType()); | ||||||
7572 | auto ToAllocatedTypeSourceInfo = | ||||||
7573 | importChecked(Err, E->getAllocatedTypeSourceInfo()); | ||||||
7574 | auto ToSourceRange = importChecked(Err, E->getSourceRange()); | ||||||
7575 | auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange()); | ||||||
7576 | if (Err) | ||||||
7577 | return std::move(Err); | ||||||
7578 | |||||||
7579 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); | ||||||
7580 | if (Error Err = | ||||||
7581 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) | ||||||
7582 | return std::move(Err); | ||||||
7583 | |||||||
7584 | return CXXNewExpr::Create( | ||||||
7585 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, | ||||||
7586 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), | ||||||
7587 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), | ||||||
7588 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, | ||||||
7589 | ToDirectInitRange); | ||||||
7590 | } | ||||||
7591 | |||||||
7592 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { | ||||||
7593 | Error Err = Error::success(); | ||||||
7594 | auto ToType = importChecked(Err, E->getType()); | ||||||
7595 | auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete()); | ||||||
7596 | auto ToArgument = importChecked(Err, E->getArgument()); | ||||||
7597 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); | ||||||
7598 | if (Err) | ||||||
7599 | return std::move(Err); | ||||||
7600 | |||||||
7601 | return new (Importer.getToContext()) CXXDeleteExpr( | ||||||
7602 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), | ||||||
7603 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, | ||||||
7604 | ToBeginLoc); | ||||||
7605 | } | ||||||
7606 | |||||||
7607 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { | ||||||
7608 | Error Err = Error::success(); | ||||||
7609 | auto ToType = importChecked(Err, E->getType()); | ||||||
7610 | auto ToLocation = importChecked(Err, E->getLocation()); | ||||||
7611 | auto ToConstructor = importChecked(Err, E->getConstructor()); | ||||||
7612 | auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange()); | ||||||
7613 | if (Err) | ||||||
7614 | return std::move(Err); | ||||||
7615 | |||||||
7616 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); | ||||||
7617 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | ||||||
7618 | return std::move(Err); | ||||||
7619 | |||||||
7620 | return CXXConstructExpr::Create( | ||||||
7621 | Importer.getToContext(), ToType, ToLocation, ToConstructor, | ||||||
7622 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), | ||||||
7623 | E->isListInitialization(), E->isStdInitListInitialization(), | ||||||
7624 | E->requiresZeroInitialization(), E->getConstructionKind(), | ||||||
7625 | ToParenOrBraceRange); | ||||||
7626 | } | ||||||
7627 | |||||||
7628 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { | ||||||
7629 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | ||||||
7630 | if (!ToSubExprOrErr) | ||||||
7631 | return ToSubExprOrErr.takeError(); | ||||||
7632 | |||||||
7633 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); | ||||||
7634 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) | ||||||
7635 | return std::move(Err); | ||||||
7636 | |||||||
7637 | return ExprWithCleanups::Create( | ||||||
7638 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), | ||||||
7639 | ToObjects); | ||||||
7640 | } | ||||||
7641 | |||||||
7642 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { | ||||||
7643 | Error Err = Error::success(); | ||||||
7644 | auto ToCallee = importChecked(Err, E->getCallee()); | ||||||
7645 | auto ToType = importChecked(Err, E->getType()); | ||||||
7646 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||
7647 | if (Err) | ||||||
7648 | return std::move(Err); | ||||||
7649 | |||||||
7650 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); | ||||||
7651 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | ||||||
7652 | return std::move(Err); | ||||||
7653 | |||||||
7654 | return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, | ||||||
7655 | ToType, E->getValueKind(), ToRParenLoc, | ||||||
7656 | E->getFPFeatures()); | ||||||
7657 | } | ||||||
7658 | |||||||
7659 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { | ||||||
7660 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||
7661 | if (!ToTypeOrErr) | ||||||
7662 | return ToTypeOrErr.takeError(); | ||||||
7663 | |||||||
7664 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | ||||||
7665 | if (!ToLocationOrErr) | ||||||
7666 | return ToLocationOrErr.takeError(); | ||||||
7667 | |||||||
7668 | return new (Importer.getToContext()) CXXThisExpr( | ||||||
7669 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); | ||||||
7670 | } | ||||||
7671 | |||||||
7672 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { | ||||||
7673 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||
7674 | if (!ToTypeOrErr) | ||||||
7675 | return ToTypeOrErr.takeError(); | ||||||
7676 | |||||||
7677 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | ||||||
7678 | if (!ToLocationOrErr) | ||||||
7679 | return ToLocationOrErr.takeError(); | ||||||
7680 | |||||||
7681 | return new (Importer.getToContext()) CXXBoolLiteralExpr( | ||||||
7682 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); | ||||||
7683 | } | ||||||
7684 | |||||||
7685 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { | ||||||
7686 | Error Err = Error::success(); | ||||||
7687 | auto ToBase = importChecked(Err, E->getBase()); | ||||||
7688 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||
7689 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); | ||||||
7690 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); | ||||||
7691 | auto ToMemberDecl = importChecked(Err, E->getMemberDecl()); | ||||||
7692 | auto ToType = importChecked(Err, E->getType()); | ||||||
7693 | auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl()); | ||||||
7694 | auto ToName = importChecked(Err, E->getMemberNameInfo().getName()); | ||||||
7695 | auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc()); | ||||||
7696 | if (Err) | ||||||
7697 | return std::move(Err); | ||||||
7698 | |||||||
7699 | DeclAccessPair ToFoundDecl = | ||||||
7700 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); | ||||||
7701 | |||||||
7702 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); | ||||||
7703 | |||||||
7704 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; | ||||||
7705 | if (E->hasExplicitTemplateArgs()) { | ||||||
7706 | if (Error Err = | ||||||
7707 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), | ||||||
7708 | E->template_arguments(), ToTAInfo)) | ||||||
7709 | return std::move(Err); | ||||||
7710 | ResInfo = &ToTAInfo; | ||||||
7711 | } | ||||||
7712 | |||||||
7713 | return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(), | ||||||
7714 | ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, | ||||||
7715 | ToMemberDecl, ToFoundDecl, ToMemberNameInfo, | ||||||
7716 | ResInfo, ToType, E->getValueKind(), | ||||||
7717 | E->getObjectKind(), E->isNonOdrUse()); | ||||||
7718 | } | ||||||
7719 | |||||||
7720 | ExpectedStmt | ||||||
7721 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { | ||||||
7722 | Error Err = Error::success(); | ||||||
7723 | auto ToBase = importChecked(Err, E->getBase()); | ||||||
7724 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||
7725 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); | ||||||
7726 | auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo()); | ||||||
7727 | auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc()); | ||||||
7728 | auto ToTildeLoc = importChecked(Err, E->getTildeLoc()); | ||||||
7729 | if (Err) | ||||||
7730 | return std::move(Err); | ||||||
7731 | |||||||
7732 | PseudoDestructorTypeStorage Storage; | ||||||
7733 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { | ||||||
7734 | IdentifierInfo *ToII = Importer.Import(FromII); | ||||||
7735 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); | ||||||
7736 | if (!ToDestroyedTypeLocOrErr) | ||||||
7737 | return ToDestroyedTypeLocOrErr.takeError(); | ||||||
7738 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); | ||||||
7739 | } else { | ||||||
7740 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) | ||||||
7741 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); | ||||||
7742 | else | ||||||
7743 | return ToTIOrErr.takeError(); | ||||||
7744 | } | ||||||
7745 | |||||||
7746 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( | ||||||
7747 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, | ||||||
7748 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); | ||||||
7749 | } | ||||||
7750 | |||||||
7751 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( | ||||||
7752 | CXXDependentScopeMemberExpr *E) { | ||||||
7753 | Error Err = Error::success(); | ||||||
7754 | auto ToType = importChecked(Err, E->getType()); | ||||||
7755 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||
7756 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); | ||||||
7757 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); | ||||||
7758 | auto ToFirstQualifierFoundInScope = | ||||||
7759 | importChecked(Err, E->getFirstQualifierFoundInScope()); | ||||||
7760 | if (Err) | ||||||
7761 | return std::move(Err); | ||||||
7762 | |||||||
7763 | Expr *ToBase = nullptr; | ||||||
7764 | if (!E->isImplicitAccess()) { | ||||||
7765 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) | ||||||
7766 | ToBase = *ToBaseOrErr; | ||||||
7767 | else | ||||||
7768 | return ToBaseOrErr.takeError(); | ||||||
7769 | } | ||||||
7770 | |||||||
7771 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; | ||||||
7772 | |||||||
7773 | if (E->hasExplicitTemplateArgs()) { | ||||||
7774 | if (Error Err = | ||||||
7775 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), | ||||||
7776 | E->template_arguments(), ToTAInfo)) | ||||||
7777 | return std::move(Err); | ||||||
7778 | ResInfo = &ToTAInfo; | ||||||
7779 | } | ||||||
7780 | auto ToMember = importChecked(Err, E->getMember()); | ||||||
7781 | auto ToMemberLoc = importChecked(Err, E->getMemberLoc()); | ||||||
7782 | if (Err) | ||||||
7783 | return std::move(Err); | ||||||
7784 | DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc); | ||||||
7785 | |||||||
7786 | // Import additional name location/type info. | ||||||
7787 | if (Error Err = | ||||||
7788 | ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo)) | ||||||
7789 | return std::move(Err); | ||||||
7790 | |||||||
7791 | return CXXDependentScopeMemberExpr::Create( | ||||||
7792 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, | ||||||
7793 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, | ||||||
7794 | ToMemberNameInfo, ResInfo); | ||||||
7795 | } | ||||||
7796 | |||||||
7797 | ExpectedStmt | ||||||
7798 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { | ||||||
7799 | Error Err = Error::success(); | ||||||
7800 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); | ||||||
7801 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); | ||||||
7802 | auto ToDeclName = importChecked(Err, E->getDeclName()); | ||||||
7803 | auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc()); | ||||||
7804 | auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc()); | ||||||
7805 | auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc()); | ||||||
7806 | if (Err) | ||||||
7807 | return std::move(Err); | ||||||
7808 | |||||||
7809 | DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc); | ||||||
7810 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | ||||||
7811 | return std::move(Err); | ||||||
7812 | |||||||
7813 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); | ||||||
7814 | TemplateArgumentListInfo *ResInfo = nullptr; | ||||||
7815 | if (E->hasExplicitTemplateArgs()) { | ||||||
7816 | if (Error Err = | ||||||
7817 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) | ||||||
7818 | return std::move(Err); | ||||||
7819 | ResInfo = &ToTAInfo; | ||||||
7820 | } | ||||||
7821 | |||||||
7822 | return DependentScopeDeclRefExpr::Create( | ||||||
7823 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, | ||||||
7824 | ToNameInfo, ResInfo); | ||||||
7825 | } | ||||||
7826 | |||||||
7827 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( | ||||||
7828 | CXXUnresolvedConstructExpr *E) { | ||||||
7829 | Error Err = Error::success(); | ||||||
7830 | auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); | ||||||
7831 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||
7832 | auto ToType = importChecked(Err, E->getType()); | ||||||
7833 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); | ||||||
7834 | if (Err) | ||||||
7835 | return std::move(Err); | ||||||
7836 | |||||||
7837 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); | ||||||
7838 | if (Error Err = | ||||||
7839 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) | ||||||
7840 | return std::move(Err); | ||||||
7841 | |||||||
7842 | return CXXUnresolvedConstructExpr::Create( | ||||||
7843 | Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc, | ||||||
7844 | llvm::makeArrayRef(ToArgs), ToRParenLoc); | ||||||
7845 | } | ||||||
7846 | |||||||
7847 | ExpectedStmt | ||||||
7848 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { | ||||||
7849 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); | ||||||
7850 | if (!ToNamingClassOrErr) | ||||||
7851 | return ToNamingClassOrErr.takeError(); | ||||||
7852 | |||||||
7853 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); | ||||||
7854 | if (!ToQualifierLocOrErr) | ||||||
7855 | return ToQualifierLocOrErr.takeError(); | ||||||
7856 | |||||||
7857 | Error Err = Error::success(); | ||||||
7858 | auto ToName = importChecked(Err, E->getName()); | ||||||
7859 | auto ToNameLoc = importChecked(Err, E->getNameLoc()); | ||||||
7860 | if (Err) | ||||||
7861 | return std::move(Err); | ||||||
7862 | DeclarationNameInfo ToNameInfo(ToName, ToNameLoc); | ||||||
7863 | |||||||
7864 | // Import additional name location/type info. | ||||||
7865 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | ||||||
7866 | return std::move(Err); | ||||||
7867 | |||||||
7868 | UnresolvedSet<8> ToDecls; | ||||||
7869 | for (auto *D : E->decls()) | ||||||
7870 | if (auto ToDOrErr = import(D)) | ||||||
7871 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); | ||||||
7872 | else | ||||||
7873 | return ToDOrErr.takeError(); | ||||||
7874 | |||||||
7875 | if (E->hasExplicitTemplateArgs()) { | ||||||
7876 | TemplateArgumentListInfo ToTAInfo; | ||||||
7877 | if (Error Err = ImportTemplateArgumentListInfo( | ||||||
7878 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), | ||||||
7879 | ToTAInfo)) | ||||||
7880 | return std::move(Err); | ||||||
7881 | |||||||
7882 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); | ||||||
7883 | if (!ToTemplateKeywordLocOrErr) | ||||||
7884 | return ToTemplateKeywordLocOrErr.takeError(); | ||||||
7885 | |||||||
7886 | return UnresolvedLookupExpr::Create( | ||||||
7887 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, | ||||||
7888 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, | ||||||
7889 | ToDecls.begin(), ToDecls.end()); | ||||||
7890 | } | ||||||
7891 | |||||||
7892 | return UnresolvedLookupExpr::Create( | ||||||
7893 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, | ||||||
7894 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), | ||||||
7895 | ToDecls.end()); | ||||||
7896 | } | ||||||
7897 | |||||||
7898 | ExpectedStmt | ||||||
7899 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { | ||||||
7900 | Error Err = Error::success(); | ||||||
7901 | auto ToType = importChecked(Err, E->getType()); | ||||||
7902 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||
7903 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); | ||||||
7904 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); | ||||||
7905 | auto ToName = importChecked(Err, E->getName()); | ||||||
7906 | auto ToNameLoc = importChecked(Err, E->getNameLoc()); | ||||||
7907 | if (Err) | ||||||
7908 | return std::move(Err); | ||||||
7909 | |||||||
7910 | DeclarationNameInfo ToNameInfo(ToName, ToNameLoc); | ||||||
7911 | // Import additional name location/type info. | ||||||
7912 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | ||||||
7913 | return std::move(Err); | ||||||
7914 | |||||||
7915 | UnresolvedSet<8> ToDecls; | ||||||
7916 | for (Decl *D : E->decls()) | ||||||
7917 | if (auto ToDOrErr = import(D)) | ||||||
7918 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); | ||||||
7919 | else | ||||||
7920 | return ToDOrErr.takeError(); | ||||||
7921 | |||||||
7922 | TemplateArgumentListInfo ToTAInfo; | ||||||
7923 | TemplateArgumentListInfo *ResInfo = nullptr; | ||||||
7924 | if (E->hasExplicitTemplateArgs()) { | ||||||
7925 | TemplateArgumentListInfo FromTAInfo; | ||||||
7926 | E->copyTemplateArgumentsInto(FromTAInfo); | ||||||
7927 | if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo)) | ||||||
7928 | return std::move(Err); | ||||||
7929 | ResInfo = &ToTAInfo; | ||||||
7930 | } | ||||||
7931 | |||||||
7932 | Expr *ToBase = nullptr; | ||||||
7933 | if (!E->isImplicitAccess()) { | ||||||
7934 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) | ||||||
7935 | ToBase = *ToBaseOrErr; | ||||||
7936 | else | ||||||
7937 | return ToBaseOrErr.takeError(); | ||||||
7938 | } | ||||||
7939 | |||||||
7940 | return UnresolvedMemberExpr::Create( | ||||||
7941 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, | ||||||
7942 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, | ||||||
7943 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); | ||||||
7944 | } | ||||||
7945 | |||||||
7946 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { | ||||||
7947 | Error Err = Error::success(); | ||||||
7948 | auto ToCallee = importChecked(Err, E->getCallee()); | ||||||
7949 | auto ToType = importChecked(Err, E->getType()); | ||||||
7950 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||
7951 | if (Err) | ||||||
7952 | return std::move(Err); | ||||||
7953 | |||||||
7954 | unsigned NumArgs = E->getNumArgs(); | ||||||
7955 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); | ||||||
7956 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | ||||||
7957 | return std::move(Err); | ||||||
7958 | |||||||
7959 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { | ||||||
7960 | return CXXOperatorCallExpr::Create( | ||||||
7961 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, | ||||||
7962 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(), | ||||||
7963 | OCE->getADLCallKind()); | ||||||
7964 | } | ||||||
7965 | |||||||
7966 | return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType, | ||||||
7967 | E->getValueKind(), ToRParenLoc, E->getFPFeatures(), | ||||||
7968 | /*MinNumArgs=*/0, E->getADLCallKind()); | ||||||
7969 | } | ||||||
7970 | |||||||
7971 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { | ||||||
7972 | CXXRecordDecl *FromClass = E->getLambdaClass(); | ||||||
7973 | auto ToClassOrErr = import(FromClass); | ||||||
7974 | if (!ToClassOrErr) | ||||||
7975 | return ToClassOrErr.takeError(); | ||||||
7976 | CXXRecordDecl *ToClass = *ToClassOrErr; | ||||||
7977 | |||||||
7978 | auto ToCallOpOrErr = import(E->getCallOperator()); | ||||||
7979 | if (!ToCallOpOrErr) | ||||||
7980 | return ToCallOpOrErr.takeError(); | ||||||
7981 | |||||||
7982 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); | ||||||
7983 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) | ||||||
7984 | return std::move(Err); | ||||||
7985 | |||||||
7986 | Error Err = Error::success(); | ||||||
7987 | auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange()); | ||||||
7988 | auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc()); | ||||||
7989 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); | ||||||
7990 | if (Err) | ||||||
7991 | return std::move(Err); | ||||||
7992 | |||||||
7993 | return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange, | ||||||
7994 | E->getCaptureDefault(), ToCaptureDefaultLoc, | ||||||
7995 | E->hasExplicitParameters(), | ||||||
7996 | E->hasExplicitResultType(), ToCaptureInits, | ||||||
7997 | ToEndLoc, E->containsUnexpandedParameterPack()); | ||||||
7998 | } | ||||||
7999 | |||||||
8000 | |||||||
8001 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { | ||||||
8002 | Error Err = Error::success(); | ||||||
8003 | auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc()); | ||||||
8004 | auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc()); | ||||||
8005 | auto ToType = importChecked(Err, E->getType()); | ||||||
8006 | if (Err) | ||||||
8007 | return std::move(Err); | ||||||
8008 | |||||||
8009 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); | ||||||
8010 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) | ||||||
8011 | return std::move(Err); | ||||||
8012 | |||||||
8013 | ASTContext &ToCtx = Importer.getToContext(); | ||||||
8014 | InitListExpr *To = new (ToCtx) InitListExpr( | ||||||
8015 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); | ||||||
8016 | To->setType(ToType); | ||||||
8017 | |||||||
8018 | if (E->hasArrayFiller()) { | ||||||
8019 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) | ||||||
8020 | To->setArrayFiller(*ToFillerOrErr); | ||||||
8021 | else | ||||||
8022 | return ToFillerOrErr.takeError(); | ||||||
8023 | } | ||||||
8024 | |||||||
8025 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { | ||||||
8026 | if (auto ToFDOrErr = import(FromFD)) | ||||||
8027 | To->setInitializedFieldInUnion(*ToFDOrErr); | ||||||
8028 | else | ||||||
8029 | return ToFDOrErr.takeError(); | ||||||
8030 | } | ||||||
8031 | |||||||
8032 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { | ||||||
8033 | if (auto ToSyntFormOrErr = import(SyntForm)) | ||||||
8034 | To->setSyntacticForm(*ToSyntFormOrErr); | ||||||
8035 | else | ||||||
8036 | return ToSyntFormOrErr.takeError(); | ||||||
8037 | } | ||||||
8038 | |||||||
8039 | // Copy InitListExprBitfields, which are not handled in the ctor of | ||||||
8040 | // InitListExpr. | ||||||
8041 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); | ||||||
8042 | |||||||
8043 | return To; | ||||||
8044 | } | ||||||
8045 | |||||||
8046 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( | ||||||
8047 | CXXStdInitializerListExpr *E) { | ||||||
8048 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||
8049 | if (!ToTypeOrErr) | ||||||
8050 | return ToTypeOrErr.takeError(); | ||||||
8051 | |||||||
8052 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | ||||||
8053 | if (!ToSubExprOrErr) | ||||||
8054 | return ToSubExprOrErr.takeError(); | ||||||
8055 | |||||||
8056 | return new (Importer.getToContext()) CXXStdInitializerListExpr( | ||||||
8057 | *ToTypeOrErr, *ToSubExprOrErr); | ||||||
8058 | } | ||||||
8059 | |||||||
8060 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( | ||||||
8061 | CXXInheritedCtorInitExpr *E) { | ||||||
8062 | Error Err = Error::success(); | ||||||
8063 | auto ToLocation = importChecked(Err, E->getLocation()); | ||||||
8064 | auto ToType = importChecked(Err, E->getType()); | ||||||
8065 | auto ToConstructor = importChecked(Err, E->getConstructor()); | ||||||
8066 | if (Err) | ||||||
8067 | return std::move(Err); | ||||||
8068 | |||||||
8069 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( | ||||||
8070 | ToLocation, ToType, ToConstructor, E->constructsVBase(), | ||||||
8071 | E->inheritedFromVBase()); | ||||||
8072 | } | ||||||
8073 | |||||||
8074 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { | ||||||
8075 | Error Err = Error::success(); | ||||||
8076 | auto ToType = importChecked(Err, E->getType()); | ||||||
8077 | auto ToCommonExpr = importChecked(Err, E->getCommonExpr()); | ||||||
8078 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | ||||||
8079 | if (Err) | ||||||
8080 | return std::move(Err); | ||||||
8081 | |||||||
8082 | return new (Importer.getToContext()) ArrayInitLoopExpr( | ||||||
8083 | ToType, ToCommonExpr, ToSubExpr); | ||||||
8084 | } | ||||||
8085 | |||||||
8086 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { | ||||||
8087 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||
8088 | if (!ToTypeOrErr) | ||||||
8089 | return ToTypeOrErr.takeError(); | ||||||
8090 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); | ||||||
8091 | } | ||||||
8092 | |||||||
8093 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { | ||||||
8094 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); | ||||||
8095 | if (!ToBeginLocOrErr) | ||||||
8096 | return ToBeginLocOrErr.takeError(); | ||||||
8097 | |||||||
8098 | auto ToFieldOrErr = import(E->getField()); | ||||||
8099 | if (!ToFieldOrErr) | ||||||
8100 | return ToFieldOrErr.takeError(); | ||||||
8101 | |||||||
8102 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); | ||||||
8103 | if (!UsedContextOrErr) | ||||||
8104 | return UsedContextOrErr.takeError(); | ||||||
8105 | |||||||
8106 | return CXXDefaultInitExpr::Create( | ||||||
8107 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr, *UsedContextOrErr); | ||||||
8108 | } | ||||||
8109 | |||||||
8110 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { | ||||||
8111 | Error Err = Error::success(); | ||||||
8112 | auto ToType = importChecked(Err, E->getType()); | ||||||
8113 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | ||||||
8114 | auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten()); | ||||||
8115 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||
8116 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||
8117 | auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets()); | ||||||
8118 | if (Err) | ||||||
8119 | return std::move(Err); | ||||||
8120 | |||||||
8121 | ExprValueKind VK = E->getValueKind(); | ||||||
8122 | CastKind CK = E->getCastKind(); | ||||||
8123 | auto ToBasePathOrErr = ImportCastPath(E); | ||||||
8124 | if (!ToBasePathOrErr) | ||||||
8125 | return ToBasePathOrErr.takeError(); | ||||||
8126 | |||||||
8127 | if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) { | ||||||
8128 | return CXXStaticCastExpr::Create( | ||||||
8129 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | ||||||
8130 | ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc, | ||||||
8131 | ToAngleBrackets); | ||||||
8132 | } else if (isa<CXXDynamicCastExpr>(E)) { | ||||||
8133 | return CXXDynamicCastExpr::Create( | ||||||
8134 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | ||||||
8135 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | ||||||
8136 | } else if (isa<CXXReinterpretCastExpr>(E)) { | ||||||
8137 | return CXXReinterpretCastExpr::Create( | ||||||
8138 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | ||||||
8139 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | ||||||
8140 | } else if (isa<CXXConstCastExpr>(E)) { | ||||||
8141 | return CXXConstCastExpr::Create( | ||||||
8142 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, | ||||||
8143 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | ||||||
8144 | } else { | ||||||
8145 | llvm_unreachable("Unknown cast type")::llvm::llvm_unreachable_internal("Unknown cast type", "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 8145); | ||||||
8146 | return make_error<ImportError>(); | ||||||
8147 | } | ||||||
8148 | } | ||||||
8149 | |||||||
8150 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( | ||||||
8151 | SubstNonTypeTemplateParmExpr *E) { | ||||||
8152 | Error Err = Error::success(); | ||||||
8153 | auto ToType = importChecked(Err, E->getType()); | ||||||
8154 | auto ToExprLoc = importChecked(Err, E->getExprLoc()); | ||||||
8155 | auto ToParameter = importChecked(Err, E->getParameter()); | ||||||
8156 | auto ToReplacement = importChecked(Err, E->getReplacement()); | ||||||
8157 | if (Err) | ||||||
8158 | return std::move(Err); | ||||||
8159 | |||||||
8160 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( | ||||||
8161 | ToType, E->getValueKind(), ToExprLoc, ToParameter, | ||||||
8162 | E->isReferenceParameter(), ToReplacement); | ||||||
8163 | } | ||||||
8164 | |||||||
8165 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { | ||||||
8166 | Error Err = Error::success(); | ||||||
8167 | auto ToType = importChecked(Err, E->getType()); | ||||||
8168 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); | ||||||
8169 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); | ||||||
8170 | if (Err) | ||||||
8171 | return std::move(Err); | ||||||
8172 | |||||||
8173 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); | ||||||
8174 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) | ||||||
8175 | return std::move(Err); | ||||||
8176 | |||||||
8177 | // According to Sema::BuildTypeTrait(), if E is value-dependent, | ||||||
8178 | // Value is always false. | ||||||
8179 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); | ||||||
8180 | |||||||
8181 | return TypeTraitExpr::Create( | ||||||
8182 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, | ||||||
8183 | ToEndLoc, ToValue); | ||||||
8184 | } | ||||||
8185 | |||||||
8186 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { | ||||||
8187 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||
8188 | if (!ToTypeOrErr) | ||||||
8189 | return ToTypeOrErr.takeError(); | ||||||
8190 | |||||||
8191 | auto ToSourceRangeOrErr = import(E->getSourceRange()); | ||||||
8192 | if (!ToSourceRangeOrErr) | ||||||
8193 | return ToSourceRangeOrErr.takeError(); | ||||||
8194 | |||||||
8195 | if (E->isTypeOperand()) { | ||||||
8196 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) | ||||||
8197 | return new (Importer.getToContext()) CXXTypeidExpr( | ||||||
8198 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); | ||||||
8199 | else | ||||||
8200 | return ToTSIOrErr.takeError(); | ||||||
8201 | } | ||||||
8202 | |||||||
8203 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); | ||||||
8204 | if (!ToExprOperandOrErr) | ||||||
8205 | return ToExprOperandOrErr.takeError(); | ||||||
8206 | |||||||
8207 | return new (Importer.getToContext()) CXXTypeidExpr( | ||||||
8208 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); | ||||||
8209 | } | ||||||
8210 | |||||||
8211 | ExpectedStmt ASTNodeImporter::VisitCXXFoldExpr(CXXFoldExpr *E) { | ||||||
8212 | Error Err = Error::success(); | ||||||
8213 | |||||||
8214 | QualType ToType = importChecked(Err, E->getType()); | ||||||
8215 | UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee()); | ||||||
8216 | SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc()); | ||||||
8217 | Expr *ToLHS = importChecked(Err, E->getLHS()); | ||||||
8218 | SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc()); | ||||||
8219 | Expr *ToRHS = importChecked(Err, E->getRHS()); | ||||||
8220 | SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||
8221 | |||||||
8222 | if (Err) | ||||||
8223 | return std::move(Err); | ||||||
8224 | |||||||
8225 | return new (Importer.getToContext()) | ||||||
8226 | CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(), | ||||||
8227 | ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions()); | ||||||
8228 | } | ||||||
8229 | |||||||
8230 | Error ASTNodeImporter::ImportOverriddenMethods(CXXMethodDecl *ToMethod, | ||||||
8231 | CXXMethodDecl *FromMethod) { | ||||||
8232 | Error ImportErrors = Error::success(); | ||||||
8233 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { | ||||||
8234 | if (auto ImportedOrErr = import(FromOverriddenMethod)) | ||||||
8235 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( | ||||||
8236 | (*ImportedOrErr)->getCanonicalDecl())); | ||||||
8237 | else | ||||||
8238 | ImportErrors = | ||||||
8239 | joinErrors(std::move(ImportErrors), ImportedOrErr.takeError()); | ||||||
8240 | } | ||||||
8241 | return ImportErrors; | ||||||
8242 | } | ||||||
8243 | |||||||
8244 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, | ||||||
8245 | ASTContext &FromContext, FileManager &FromFileManager, | ||||||
8246 | bool MinimalImport, | ||||||
8247 | std::shared_ptr<ASTImporterSharedState> SharedState) | ||||||
8248 | : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext), | ||||||
8249 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), | ||||||
8250 | Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) { | ||||||
8251 | |||||||
8252 | // Create a default state without the lookup table: LLDB case. | ||||||
8253 | if (!SharedState) { | ||||||
8254 | this->SharedState = std::make_shared<ASTImporterSharedState>(); | ||||||
8255 | } | ||||||
8256 | |||||||
8257 | ImportedDecls[FromContext.getTranslationUnitDecl()] = | ||||||
8258 | ToContext.getTranslationUnitDecl(); | ||||||
8259 | } | ||||||
8260 | |||||||
8261 | ASTImporter::~ASTImporter() = default; | ||||||
8262 | |||||||
8263 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { | ||||||
8264 | 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.\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 8265, __extension__ __PRETTY_FUNCTION__)) | ||||||
8265 | "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.\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 8265, __extension__ __PRETTY_FUNCTION__)); | ||||||
8266 | |||||||
8267 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); | ||||||
8268 | if (!Owner) | ||||||
8269 | return None; | ||||||
8270 | |||||||
8271 | unsigned Index = 0; | ||||||
8272 | for (const auto *D : Owner->decls()) { | ||||||
8273 | if (D == F) | ||||||
8274 | return Index; | ||||||
8275 | |||||||
8276 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) | ||||||
8277 | ++Index; | ||||||
8278 | } | ||||||
8279 | |||||||
8280 | llvm_unreachable("Field was not found in its parent context.")::llvm::llvm_unreachable_internal("Field was not found in its parent context." , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 8280); | ||||||
8281 | |||||||
8282 | return None; | ||||||
8283 | } | ||||||
8284 | |||||||
8285 | ASTImporter::FoundDeclsTy | ||||||
8286 | ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) { | ||||||
8287 | // We search in the redecl context because of transparent contexts. | ||||||
8288 | // E.g. a simple C language enum is a transparent context: | ||||||
8289 | // enum E { A, B }; | ||||||
8290 | // Now if we had a global variable in the TU | ||||||
8291 | // int A; | ||||||
8292 | // then the enum constant 'A' and the variable 'A' violates ODR. | ||||||
8293 | // We can diagnose this only if we search in the redecl context. | ||||||
8294 | DeclContext *ReDC = DC->getRedeclContext(); | ||||||
8295 | if (SharedState->getLookupTable()) { | ||||||
8296 | ASTImporterLookupTable::LookupResult LookupResult = | ||||||
8297 | SharedState->getLookupTable()->lookup(ReDC, Name); | ||||||
8298 | return FoundDeclsTy(LookupResult.begin(), LookupResult.end()); | ||||||
8299 | } else { | ||||||
8300 | DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name); | ||||||
8301 | FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end()); | ||||||
8302 | // We must search by the slow case of localUncachedLookup because that is | ||||||
8303 | // working even if there is no LookupPtr for the DC. We could use | ||||||
8304 | // DC::buildLookup() to create the LookupPtr, but that would load external | ||||||
8305 | // decls again, we must avoid that case. | ||||||
8306 | // Also, even if we had the LookupPtr, we must find Decls which are not | ||||||
8307 | // in the LookupPtr, so we need the slow case. | ||||||
8308 | // These cases are handled in ASTImporterLookupTable, but we cannot use | ||||||
8309 | // that with LLDB since that traverses through the AST which initiates the | ||||||
8310 | // load of external decls again via DC::decls(). And again, we must avoid | ||||||
8311 | // loading external decls during the import. | ||||||
8312 | if (Result.empty()) | ||||||
8313 | ReDC->localUncachedLookup(Name, Result); | ||||||
8314 | return Result; | ||||||
8315 | } | ||||||
8316 | } | ||||||
8317 | |||||||
8318 | void ASTImporter::AddToLookupTable(Decl *ToD) { | ||||||
8319 | SharedState->addDeclToLookup(ToD); | ||||||
8320 | } | ||||||
8321 | |||||||
8322 | Expected<Decl *> ASTImporter::ImportImpl(Decl *FromD) { | ||||||
8323 | // Import the decl using ASTNodeImporter. | ||||||
8324 | ASTNodeImporter Importer(*this); | ||||||
8325 | return Importer.Visit(FromD); | ||||||
8326 | } | ||||||
8327 | |||||||
8328 | void ASTImporter::RegisterImportedDecl(Decl *FromD, Decl *ToD) { | ||||||
8329 | MapImported(FromD, ToD); | ||||||
8330 | } | ||||||
8331 | |||||||
8332 | llvm::Expected<ExprWithCleanups::CleanupObject> | ||||||
8333 | ASTImporter::Import(ExprWithCleanups::CleanupObject From) { | ||||||
8334 | if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) { | ||||||
8335 | if (Expected<Expr *> R = Import(CLE)) | ||||||
8336 | return ExprWithCleanups::CleanupObject(cast<CompoundLiteralExpr>(*R)); | ||||||
8337 | } | ||||||
8338 | |||||||
8339 | // FIXME: Handle BlockDecl when we implement importing BlockExpr in | ||||||
8340 | // ASTNodeImporter. | ||||||
8341 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | ||||||
8342 | } | ||||||
8343 | |||||||
8344 | Expected<const Type *> ASTImporter::Import(const Type *FromT) { | ||||||
8345 | if (!FromT) | ||||||
8346 | return FromT; | ||||||
8347 | |||||||
8348 | // Check whether we've already imported this type. | ||||||
8349 | llvm::DenseMap<const Type *, const Type *>::iterator Pos = | ||||||
8350 | ImportedTypes.find(FromT); | ||||||
8351 | if (Pos != ImportedTypes.end()) | ||||||
8352 | return Pos->second; | ||||||
8353 | |||||||
8354 | // Import the type | ||||||
8355 | ASTNodeImporter Importer(*this); | ||||||
8356 | ExpectedType ToTOrErr = Importer.Visit(FromT); | ||||||
8357 | if (!ToTOrErr) | ||||||
8358 | return ToTOrErr.takeError(); | ||||||
8359 | |||||||
8360 | // Record the imported type. | ||||||
8361 | ImportedTypes[FromT] = ToTOrErr->getTypePtr(); | ||||||
8362 | |||||||
8363 | return ToTOrErr->getTypePtr(); | ||||||
8364 | } | ||||||
8365 | |||||||
8366 | Expected<QualType> ASTImporter::Import(QualType FromT) { | ||||||
8367 | if (FromT.isNull()) | ||||||
8368 | return QualType{}; | ||||||
8369 | |||||||
8370 | Expected<const Type *> ToTyOrErr = Import(FromT.getTypePtr()); | ||||||
8371 | if (!ToTyOrErr) | ||||||
8372 | return ToTyOrErr.takeError(); | ||||||
8373 | |||||||
8374 | return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers()); | ||||||
8375 | } | ||||||
8376 | |||||||
8377 | Expected<TypeSourceInfo *> ASTImporter::Import(TypeSourceInfo *FromTSI) { | ||||||
8378 | if (!FromTSI) | ||||||
8379 | return FromTSI; | ||||||
8380 | |||||||
8381 | // FIXME: For now we just create a "trivial" type source info based | ||||||
8382 | // on the type and a single location. Implement a real version of this. | ||||||
8383 | ExpectedType TOrErr = Import(FromTSI->getType()); | ||||||
8384 | if (!TOrErr) | ||||||
8385 | return TOrErr.takeError(); | ||||||
8386 | ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc()); | ||||||
8387 | if (!BeginLocOrErr) | ||||||
8388 | return BeginLocOrErr.takeError(); | ||||||
8389 | |||||||
8390 | return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr); | ||||||
8391 | } | ||||||
8392 | |||||||
8393 | Expected<Attr *> ASTImporter::Import(const Attr *FromAttr) { | ||||||
8394 | Attr *ToAttr = nullptr; | ||||||
8395 | SourceRange ToRange; | ||||||
8396 | if (Error Err = importInto(ToRange, FromAttr->getRange())) | ||||||
8397 | return std::move(Err); | ||||||
8398 | |||||||
8399 | // FIXME: Is there some kind of AttrVisitor to use here? | ||||||
8400 | switch (FromAttr->getKind()) { | ||||||
8401 | case attr::Aligned: { | ||||||
8402 | auto *From = cast<AlignedAttr>(FromAttr); | ||||||
8403 | AlignedAttr *To; | ||||||
8404 | auto CreateAlign = [&](bool IsAlignmentExpr, void *Alignment) { | ||||||
8405 | return AlignedAttr::Create(ToContext, IsAlignmentExpr, Alignment, ToRange, | ||||||
8406 | From->getSyntax(), | ||||||
8407 | From->getSemanticSpelling()); | ||||||
8408 | }; | ||||||
8409 | if (From->isAlignmentExpr()) { | ||||||
8410 | if (auto ToEOrErr = Import(From->getAlignmentExpr())) | ||||||
8411 | To = CreateAlign(true, *ToEOrErr); | ||||||
8412 | else | ||||||
8413 | return ToEOrErr.takeError(); | ||||||
8414 | } else { | ||||||
8415 | if (auto ToTOrErr = Import(From->getAlignmentType())) | ||||||
8416 | To = CreateAlign(false, *ToTOrErr); | ||||||
8417 | else | ||||||
8418 | return ToTOrErr.takeError(); | ||||||
8419 | } | ||||||
8420 | To->setInherited(From->isInherited()); | ||||||
8421 | To->setPackExpansion(From->isPackExpansion()); | ||||||
8422 | To->setImplicit(From->isImplicit()); | ||||||
8423 | ToAttr = To; | ||||||
8424 | break; | ||||||
8425 | } | ||||||
8426 | case attr::Format: { | ||||||
8427 | const auto *From = cast<FormatAttr>(FromAttr); | ||||||
8428 | FormatAttr *To; | ||||||
8429 | IdentifierInfo *ToAttrType = Import(From->getType()); | ||||||
8430 | To = FormatAttr::Create(ToContext, ToAttrType, From->getFormatIdx(), | ||||||
8431 | From->getFirstArg(), ToRange, From->getSyntax()); | ||||||
8432 | To->setInherited(From->isInherited()); | ||||||
8433 | ToAttr = To; | ||||||
8434 | break; | ||||||
8435 | } | ||||||
8436 | default: | ||||||
8437 | // FIXME: 'clone' copies every member but some of them should be imported. | ||||||
8438 | // Handle other Attrs that have parameters that should be imported. | ||||||
8439 | ToAttr = FromAttr->clone(ToContext); | ||||||
8440 | ToAttr->setRange(ToRange); | ||||||
8441 | break; | ||||||
8442 | } | ||||||
8443 | assert(ToAttr && "Attribute should be created.")(static_cast <bool> (ToAttr && "Attribute should be created." ) ? void (0) : __assert_fail ("ToAttr && \"Attribute should be created.\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 8443, __extension__ __PRETTY_FUNCTION__)); | ||||||
8444 | |||||||
8445 | return ToAttr; | ||||||
8446 | } | ||||||
8447 | |||||||
8448 | Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const { | ||||||
8449 | auto Pos = ImportedDecls.find(FromD); | ||||||
8450 | if (Pos != ImportedDecls.end()) | ||||||
8451 | return Pos->second; | ||||||
8452 | else | ||||||
8453 | return nullptr; | ||||||
8454 | } | ||||||
8455 | |||||||
8456 | TranslationUnitDecl *ASTImporter::GetFromTU(Decl *ToD) { | ||||||
8457 | auto FromDPos = ImportedFromDecls.find(ToD); | ||||||
8458 | if (FromDPos == ImportedFromDecls.end()) | ||||||
8459 | return nullptr; | ||||||
8460 | return FromDPos->second->getTranslationUnitDecl(); | ||||||
8461 | } | ||||||
8462 | |||||||
8463 | Expected<Decl *> ASTImporter::Import(Decl *FromD) { | ||||||
8464 | if (!FromD) | ||||||
8465 | return nullptr; | ||||||
8466 | |||||||
8467 | // Push FromD to the stack, and remove that when we return. | ||||||
8468 | ImportPath.push(FromD); | ||||||
8469 | auto ImportPathBuilder = | ||||||
8470 | llvm::make_scope_exit([this]() { ImportPath.pop(); }); | ||||||
8471 | |||||||
8472 | // Check whether there was a previous failed import. | ||||||
8473 | // If yes return the existing error. | ||||||
8474 | if (auto Error = getImportDeclErrorIfAny(FromD)) | ||||||
8475 | return make_error<ImportError>(*Error); | ||||||
8476 | |||||||
8477 | // Check whether we've already imported this declaration. | ||||||
8478 | Decl *ToD = GetAlreadyImportedOrNull(FromD); | ||||||
8479 | if (ToD) { | ||||||
8480 | // Already imported (possibly from another TU) and with an error. | ||||||
8481 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { | ||||||
8482 | setImportDeclError(FromD, *Error); | ||||||
8483 | return make_error<ImportError>(*Error); | ||||||
8484 | } | ||||||
8485 | |||||||
8486 | // If FromD has some updated flags after last import, apply it. | ||||||
8487 | updateFlags(FromD, ToD); | ||||||
8488 | // If we encounter a cycle during an import then we save the relevant part | ||||||
8489 | // of the import path associated to the Decl. | ||||||
8490 | if (ImportPath.hasCycleAtBack()) | ||||||
8491 | SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack()); | ||||||
8492 | return ToD; | ||||||
8493 | } | ||||||
8494 | |||||||
8495 | // Import the declaration. | ||||||
8496 | ExpectedDecl ToDOrErr = ImportImpl(FromD); | ||||||
8497 | if (!ToDOrErr) { | ||||||
8498 | // Failed to import. | ||||||
8499 | |||||||
8500 | auto Pos = ImportedDecls.find(FromD); | ||||||
8501 | if (Pos != ImportedDecls.end()) { | ||||||
8502 | // Import failed after the object was created. | ||||||
8503 | // Remove all references to it. | ||||||
8504 | auto *ToD = Pos->second; | ||||||
8505 | ImportedDecls.erase(Pos); | ||||||
8506 | |||||||
8507 | // ImportedDecls and ImportedFromDecls are not symmetric. It may happen | ||||||
8508 | // (e.g. with namespaces) that several decls from the 'from' context are | ||||||
8509 | // mapped to the same decl in the 'to' context. If we removed entries | ||||||
8510 | // from the LookupTable here then we may end up removing them multiple | ||||||
8511 | // times. | ||||||
8512 | |||||||
8513 | // The Lookuptable contains decls only which are in the 'to' context. | ||||||
8514 | // Remove from the Lookuptable only if it is *imported* into the 'to' | ||||||
8515 | // context (and do not remove it if it was added during the initial | ||||||
8516 | // traverse of the 'to' context). | ||||||
8517 | auto PosF = ImportedFromDecls.find(ToD); | ||||||
8518 | if (PosF != ImportedFromDecls.end()) { | ||||||
8519 | // In the case of TypedefNameDecl we create the Decl first and only | ||||||
8520 | // then we import and set its DeclContext. So, the DC might not be set | ||||||
8521 | // when we reach here. | ||||||
8522 | if (ToD->getDeclContext()) | ||||||
8523 | SharedState->removeDeclFromLookup(ToD); | ||||||
8524 | ImportedFromDecls.erase(PosF); | ||||||
8525 | } | ||||||
8526 | |||||||
8527 | // FIXME: AST may contain remaining references to the failed object. | ||||||
8528 | // However, the ImportDeclErrors in the shared state contains all the | ||||||
8529 | // failed objects together with their error. | ||||||
8530 | } | ||||||
8531 | |||||||
8532 | // Error encountered for the first time. | ||||||
8533 | // After takeError the error is not usable any more in ToDOrErr. | ||||||
8534 | // Get a copy of the error object (any more simple solution for this?). | ||||||
8535 | ImportError ErrOut; | ||||||
8536 | handleAllErrors(ToDOrErr.takeError(), | ||||||
8537 | [&ErrOut](const ImportError &E) { ErrOut = E; }); | ||||||
8538 | setImportDeclError(FromD, ErrOut); | ||||||
8539 | // Set the error for the mapped to Decl, which is in the "to" context. | ||||||
8540 | if (Pos != ImportedDecls.end()) | ||||||
8541 | SharedState->setImportDeclError(Pos->second, ErrOut); | ||||||
8542 | |||||||
8543 | // Set the error for all nodes which have been created before we | ||||||
8544 | // recognized the error. | ||||||
8545 | for (const auto &Path : SavedImportPaths[FromD]) | ||||||
8546 | for (Decl *FromDi : Path) { | ||||||
8547 | setImportDeclError(FromDi, ErrOut); | ||||||
8548 | //FIXME Should we remove these Decls from ImportedDecls? | ||||||
8549 | // Set the error for the mapped to Decl, which is in the "to" context. | ||||||
8550 | auto Ii = ImportedDecls.find(FromDi); | ||||||
8551 | if (Ii != ImportedDecls.end()) | ||||||
8552 | SharedState->setImportDeclError(Ii->second, ErrOut); | ||||||
8553 | // FIXME Should we remove these Decls from the LookupTable, | ||||||
8554 | // and from ImportedFromDecls? | ||||||
8555 | } | ||||||
8556 | SavedImportPaths.erase(FromD); | ||||||
8557 | |||||||
8558 | // Do not return ToDOrErr, error was taken out of it. | ||||||
8559 | return make_error<ImportError>(ErrOut); | ||||||
8560 | } | ||||||
8561 | |||||||
8562 | ToD = *ToDOrErr; | ||||||
8563 | |||||||
8564 | // FIXME: Handle the "already imported with error" case. We can get here | ||||||
8565 | // nullptr only if GetImportedOrCreateDecl returned nullptr (after a | ||||||
8566 | // previously failed create was requested). | ||||||
8567 | // Later GetImportedOrCreateDecl can be updated to return the error. | ||||||
8568 | if (!ToD) { | ||||||
8569 | auto Err = getImportDeclErrorIfAny(FromD); | ||||||
8570 | assert(Err)(static_cast <bool> (Err) ? void (0) : __assert_fail ("Err" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 8570, __extension__ __PRETTY_FUNCTION__)); | ||||||
8571 | return make_error<ImportError>(*Err); | ||||||
8572 | } | ||||||
8573 | |||||||
8574 | // We could import from the current TU without error. But previously we | ||||||
8575 | // already had imported a Decl as `ToD` from another TU (with another | ||||||
8576 | // ASTImporter object) and with an error. | ||||||
8577 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { | ||||||
8578 | setImportDeclError(FromD, *Error); | ||||||
8579 | return make_error<ImportError>(*Error); | ||||||
8580 | } | ||||||
8581 | |||||||
8582 | // Make sure that ImportImpl registered the imported decl. | ||||||
8583 | 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?\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 8583, __extension__ __PRETTY_FUNCTION__)); | ||||||
8584 | |||||||
8585 | if (FromD->hasAttrs()) | ||||||
8586 | for (const Attr *FromAttr : FromD->getAttrs()) { | ||||||
8587 | auto ToAttrOrErr = Import(FromAttr); | ||||||
8588 | if (ToAttrOrErr) | ||||||
8589 | ToD->addAttr(*ToAttrOrErr); | ||||||
8590 | else | ||||||
8591 | return ToAttrOrErr.takeError(); | ||||||
8592 | } | ||||||
8593 | |||||||
8594 | // Notify subclasses. | ||||||
8595 | Imported(FromD, ToD); | ||||||
8596 | |||||||
8597 | updateFlags(FromD, ToD); | ||||||
8598 | SavedImportPaths.erase(FromD); | ||||||
8599 | return ToDOrErr; | ||||||
8600 | } | ||||||
8601 | |||||||
8602 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { | ||||||
8603 | if (!FromDC) | ||||||
8604 | return FromDC; | ||||||
8605 | |||||||
8606 | ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC)); | ||||||
8607 | if (!ToDCOrErr) | ||||||
8608 | return ToDCOrErr.takeError(); | ||||||
8609 | auto *ToDC = cast<DeclContext>(*ToDCOrErr); | ||||||
8610 | |||||||
8611 | // When we're using a record/enum/Objective-C class/protocol as a context, we | ||||||
8612 | // need it to have a definition. | ||||||
8613 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { | ||||||
8614 | auto *FromRecord = cast<RecordDecl>(FromDC); | ||||||
8615 | if (ToRecord->isCompleteDefinition()) | ||||||
8616 | return ToDC; | ||||||
8617 | |||||||
8618 | // If FromRecord is not defined we need to force it to be. | ||||||
8619 | // Simply calling CompleteDecl(...) for a RecordDecl will break some cases | ||||||
8620 | // it will start the definition but we never finish it. | ||||||
8621 | // If there are base classes they won't be imported and we will | ||||||
8622 | // be missing anything that we inherit from those bases. | ||||||
8623 | if (FromRecord->getASTContext().getExternalSource() && | ||||||
8624 | !FromRecord->isCompleteDefinition()) | ||||||
8625 | FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord); | ||||||
8626 | |||||||
8627 | if (FromRecord->isCompleteDefinition()) | ||||||
8628 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | ||||||
8629 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) | ||||||
8630 | return std::move(Err); | ||||||
8631 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { | ||||||
8632 | auto *FromEnum = cast<EnumDecl>(FromDC); | ||||||
8633 | if (ToEnum->isCompleteDefinition()) { | ||||||
8634 | // Do nothing. | ||||||
8635 | } else if (FromEnum->isCompleteDefinition()) { | ||||||
8636 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | ||||||
8637 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) | ||||||
8638 | return std::move(Err); | ||||||
8639 | } else { | ||||||
8640 | CompleteDecl(ToEnum); | ||||||
8641 | } | ||||||
8642 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { | ||||||
8643 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); | ||||||
8644 | if (ToClass->getDefinition()) { | ||||||
8645 | // Do nothing. | ||||||
8646 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { | ||||||
8647 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | ||||||
8648 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) | ||||||
8649 | return std::move(Err); | ||||||
8650 | } else { | ||||||
8651 | CompleteDecl(ToClass); | ||||||
8652 | } | ||||||
8653 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { | ||||||
8654 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); | ||||||
8655 | if (ToProto->getDefinition()) { | ||||||
8656 | // Do nothing. | ||||||
8657 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { | ||||||
8658 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | ||||||
8659 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) | ||||||
8660 | return std::move(Err); | ||||||
8661 | } else { | ||||||
8662 | CompleteDecl(ToProto); | ||||||
8663 | } | ||||||
8664 | } | ||||||
8665 | |||||||
8666 | return ToDC; | ||||||
8667 | } | ||||||
8668 | |||||||
8669 | Expected<Expr *> ASTImporter::Import(Expr *FromE) { | ||||||
8670 | if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE))) | ||||||
8671 | return cast_or_null<Expr>(*ToSOrErr); | ||||||
8672 | else | ||||||
8673 | return ToSOrErr.takeError(); | ||||||
8674 | } | ||||||
8675 | |||||||
8676 | Expected<Stmt *> ASTImporter::Import(Stmt *FromS) { | ||||||
8677 | if (!FromS) | ||||||
8678 | return nullptr; | ||||||
8679 | |||||||
8680 | // Check whether we've already imported this statement. | ||||||
8681 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); | ||||||
8682 | if (Pos != ImportedStmts.end()) | ||||||
8683 | return Pos->second; | ||||||
8684 | |||||||
8685 | // Import the statement. | ||||||
8686 | ASTNodeImporter Importer(*this); | ||||||
8687 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); | ||||||
8688 | if (!ToSOrErr) | ||||||
8689 | return ToSOrErr; | ||||||
8690 | |||||||
8691 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { | ||||||
8692 | auto *FromE = cast<Expr>(FromS); | ||||||
8693 | // Copy ExprBitfields, which may not be handled in Expr subclasses | ||||||
8694 | // constructors. | ||||||
8695 | ToE->setValueKind(FromE->getValueKind()); | ||||||
8696 | ToE->setObjectKind(FromE->getObjectKind()); | ||||||
8697 | ToE->setDependence(FromE->getDependence()); | ||||||
8698 | } | ||||||
8699 | |||||||
8700 | // Record the imported statement object. | ||||||
8701 | ImportedStmts[FromS] = *ToSOrErr; | ||||||
8702 | return ToSOrErr; | ||||||
8703 | } | ||||||
8704 | |||||||
8705 | Expected<NestedNameSpecifier *> | ||||||
8706 | ASTImporter::Import(NestedNameSpecifier *FromNNS) { | ||||||
8707 | if (!FromNNS) | ||||||
8708 | return nullptr; | ||||||
8709 | |||||||
8710 | NestedNameSpecifier *Prefix = nullptr; | ||||||
8711 | if (Error Err = importInto(Prefix, FromNNS->getPrefix())) | ||||||
8712 | return std::move(Err); | ||||||
8713 | |||||||
8714 | switch (FromNNS->getKind()) { | ||||||
8715 | case NestedNameSpecifier::Identifier: | ||||||
8716 | 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.\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 8716, __extension__ __PRETTY_FUNCTION__)); | ||||||
8717 | return NestedNameSpecifier::Create(ToContext, Prefix, | ||||||
8718 | Import(FromNNS->getAsIdentifier())); | ||||||
8719 | |||||||
8720 | case NestedNameSpecifier::Namespace: | ||||||
8721 | if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) { | ||||||
8722 | return NestedNameSpecifier::Create(ToContext, Prefix, | ||||||
8723 | cast<NamespaceDecl>(*NSOrErr)); | ||||||
8724 | } else | ||||||
8725 | return NSOrErr.takeError(); | ||||||
8726 | |||||||
8727 | case NestedNameSpecifier::NamespaceAlias: | ||||||
8728 | if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias())) | ||||||
8729 | return NestedNameSpecifier::Create(ToContext, Prefix, | ||||||
8730 | cast<NamespaceAliasDecl>(*NSADOrErr)); | ||||||
8731 | else | ||||||
8732 | return NSADOrErr.takeError(); | ||||||
8733 | |||||||
8734 | case NestedNameSpecifier::Global: | ||||||
8735 | return NestedNameSpecifier::GlobalSpecifier(ToContext); | ||||||
8736 | |||||||
8737 | case NestedNameSpecifier::Super: | ||||||
8738 | if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl())) | ||||||
8739 | return NestedNameSpecifier::SuperSpecifier(ToContext, | ||||||
8740 | cast<CXXRecordDecl>(*RDOrErr)); | ||||||
8741 | else | ||||||
8742 | return RDOrErr.takeError(); | ||||||
8743 | |||||||
8744 | case NestedNameSpecifier::TypeSpec: | ||||||
8745 | case NestedNameSpecifier::TypeSpecWithTemplate: | ||||||
8746 | if (Expected<QualType> TyOrErr = | ||||||
8747 | Import(QualType(FromNNS->getAsType(), 0u))) { | ||||||
8748 | bool TSTemplate = | ||||||
8749 | FromNNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate; | ||||||
8750 | return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate, | ||||||
8751 | TyOrErr->getTypePtr()); | ||||||
8752 | } else { | ||||||
8753 | return TyOrErr.takeError(); | ||||||
8754 | } | ||||||
8755 | } | ||||||
8756 | |||||||
8757 | llvm_unreachable("Invalid nested name specifier kind")::llvm::llvm_unreachable_internal("Invalid nested name specifier kind" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 8757); | ||||||
8758 | } | ||||||
8759 | |||||||
8760 | Expected<NestedNameSpecifierLoc> | ||||||
8761 | ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { | ||||||
8762 | // Copied from NestedNameSpecifier mostly. | ||||||
8763 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; | ||||||
8764 | NestedNameSpecifierLoc NNS = FromNNS; | ||||||
8765 | |||||||
8766 | // Push each of the nested-name-specifiers's onto a stack for | ||||||
8767 | // serialization in reverse order. | ||||||
8768 | while (NNS) { | ||||||
8769 | NestedNames.push_back(NNS); | ||||||
8770 | NNS = NNS.getPrefix(); | ||||||
8771 | } | ||||||
8772 | |||||||
8773 | NestedNameSpecifierLocBuilder Builder; | ||||||
8774 | |||||||
8775 | while (!NestedNames.empty()) { | ||||||
8776 | NNS = NestedNames.pop_back_val(); | ||||||
8777 | NestedNameSpecifier *Spec = nullptr; | ||||||
8778 | if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier())) | ||||||
8779 | return std::move(Err); | ||||||
8780 | |||||||
8781 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); | ||||||
8782 | |||||||
8783 | SourceLocation ToLocalBeginLoc, ToLocalEndLoc; | ||||||
8784 | if (Kind != NestedNameSpecifier::Super) { | ||||||
8785 | if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc())) | ||||||
8786 | return std::move(Err); | ||||||
8787 | |||||||
8788 | if (Kind != NestedNameSpecifier::Global) | ||||||
8789 | if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc())) | ||||||
8790 | return std::move(Err); | ||||||
8791 | } | ||||||
8792 | |||||||
8793 | switch (Kind) { | ||||||
8794 | case NestedNameSpecifier::Identifier: | ||||||
8795 | Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc, | ||||||
8796 | ToLocalEndLoc); | ||||||
8797 | break; | ||||||
8798 | |||||||
8799 | case NestedNameSpecifier::Namespace: | ||||||
8800 | Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc, | ||||||
8801 | ToLocalEndLoc); | ||||||
8802 | break; | ||||||
8803 | |||||||
8804 | case NestedNameSpecifier::NamespaceAlias: | ||||||
8805 | Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(), | ||||||
8806 | ToLocalBeginLoc, ToLocalEndLoc); | ||||||
8807 | break; | ||||||
8808 | |||||||
8809 | case NestedNameSpecifier::TypeSpec: | ||||||
8810 | case NestedNameSpecifier::TypeSpecWithTemplate: { | ||||||
8811 | SourceLocation ToTLoc; | ||||||
8812 | if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc())) | ||||||
8813 | return std::move(Err); | ||||||
8814 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( | ||||||
8815 | QualType(Spec->getAsType(), 0), ToTLoc); | ||||||
8816 | if (Kind == NestedNameSpecifier::TypeSpecWithTemplate) | ||||||
8817 | // ToLocalBeginLoc is here the location of the 'template' keyword. | ||||||
8818 | Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(), | ||||||
8819 | ToLocalEndLoc); | ||||||
8820 | else | ||||||
8821 | // No location for 'template' keyword here. | ||||||
8822 | Builder.Extend(getToContext(), SourceLocation{}, TSI->getTypeLoc(), | ||||||
8823 | ToLocalEndLoc); | ||||||
8824 | break; | ||||||
8825 | } | ||||||
8826 | |||||||
8827 | case NestedNameSpecifier::Global: | ||||||
8828 | Builder.MakeGlobal(getToContext(), ToLocalBeginLoc); | ||||||
8829 | break; | ||||||
8830 | |||||||
8831 | case NestedNameSpecifier::Super: { | ||||||
8832 | auto ToSourceRangeOrErr = Import(NNS.getSourceRange()); | ||||||
8833 | if (!ToSourceRangeOrErr) | ||||||
8834 | return ToSourceRangeOrErr.takeError(); | ||||||
8835 | |||||||
8836 | Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(), | ||||||
8837 | ToSourceRangeOrErr->getBegin(), | ||||||
8838 | ToSourceRangeOrErr->getEnd()); | ||||||
8839 | } | ||||||
8840 | } | ||||||
8841 | } | ||||||
8842 | |||||||
8843 | return Builder.getWithLocInContext(getToContext()); | ||||||
8844 | } | ||||||
8845 | |||||||
8846 | Expected<TemplateName> ASTImporter::Import(TemplateName From) { | ||||||
8847 | switch (From.getKind()) { | ||||||
8848 | case TemplateName::Template: | ||||||
8849 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) | ||||||
8850 | return TemplateName(cast<TemplateDecl>(*ToTemplateOrErr)); | ||||||
8851 | else | ||||||
8852 | return ToTemplateOrErr.takeError(); | ||||||
8853 | |||||||
8854 | case TemplateName::OverloadedTemplate: { | ||||||
8855 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); | ||||||
8856 | UnresolvedSet<2> ToTemplates; | ||||||
8857 | for (auto *I : *FromStorage) { | ||||||
8858 | if (auto ToOrErr = Import(I)) | ||||||
8859 | ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr)); | ||||||
8860 | else | ||||||
8861 | return ToOrErr.takeError(); | ||||||
8862 | } | ||||||
8863 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), | ||||||
8864 | ToTemplates.end()); | ||||||
8865 | } | ||||||
8866 | |||||||
8867 | case TemplateName::AssumedTemplate: { | ||||||
8868 | AssumedTemplateStorage *FromStorage = From.getAsAssumedTemplateName(); | ||||||
8869 | auto DeclNameOrErr = Import(FromStorage->getDeclName()); | ||||||
8870 | if (!DeclNameOrErr) | ||||||
8871 | return DeclNameOrErr.takeError(); | ||||||
8872 | return ToContext.getAssumedTemplateName(*DeclNameOrErr); | ||||||
8873 | } | ||||||
8874 | |||||||
8875 | case TemplateName::QualifiedTemplate: { | ||||||
8876 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); | ||||||
8877 | auto QualifierOrErr = Import(QTN->getQualifier()); | ||||||
8878 | if (!QualifierOrErr) | ||||||
8879 | return QualifierOrErr.takeError(); | ||||||
8880 | |||||||
8881 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) | ||||||
8882 | return ToContext.getQualifiedTemplateName( | ||||||
8883 | *QualifierOrErr, QTN->hasTemplateKeyword(), | ||||||
8884 | cast<TemplateDecl>(*ToTemplateOrErr)); | ||||||
8885 | else | ||||||
8886 | return ToTemplateOrErr.takeError(); | ||||||
8887 | } | ||||||
8888 | |||||||
8889 | case TemplateName::DependentTemplate: { | ||||||
8890 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); | ||||||
8891 | auto QualifierOrErr = Import(DTN->getQualifier()); | ||||||
8892 | if (!QualifierOrErr) | ||||||
8893 | return QualifierOrErr.takeError(); | ||||||
8894 | |||||||
8895 | if (DTN->isIdentifier()) { | ||||||
8896 | return ToContext.getDependentTemplateName(*QualifierOrErr, | ||||||
8897 | Import(DTN->getIdentifier())); | ||||||
8898 | } | ||||||
8899 | |||||||
8900 | return ToContext.getDependentTemplateName(*QualifierOrErr, | ||||||
8901 | DTN->getOperator()); | ||||||
8902 | } | ||||||
8903 | |||||||
8904 | case TemplateName::SubstTemplateTemplateParm: { | ||||||
8905 | SubstTemplateTemplateParmStorage *Subst = | ||||||
8906 | From.getAsSubstTemplateTemplateParm(); | ||||||
8907 | ExpectedDecl ParamOrErr = Import(Subst->getParameter()); | ||||||
8908 | if (!ParamOrErr) | ||||||
8909 | return ParamOrErr.takeError(); | ||||||
8910 | |||||||
8911 | auto ReplacementOrErr = Import(Subst->getReplacement()); | ||||||
8912 | if (!ReplacementOrErr) | ||||||
8913 | return ReplacementOrErr.takeError(); | ||||||
8914 | |||||||
8915 | return ToContext.getSubstTemplateTemplateParm( | ||||||
8916 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ReplacementOrErr); | ||||||
8917 | } | ||||||
8918 | |||||||
8919 | case TemplateName::SubstTemplateTemplateParmPack: { | ||||||
8920 | SubstTemplateTemplateParmPackStorage *SubstPack | ||||||
8921 | = From.getAsSubstTemplateTemplateParmPack(); | ||||||
8922 | ExpectedDecl ParamOrErr = Import(SubstPack->getParameterPack()); | ||||||
8923 | if (!ParamOrErr) | ||||||
8924 | return ParamOrErr.takeError(); | ||||||
8925 | |||||||
8926 | ASTNodeImporter Importer(*this); | ||||||
8927 | auto ArgPackOrErr = | ||||||
8928 | Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); | ||||||
8929 | if (!ArgPackOrErr) | ||||||
8930 | return ArgPackOrErr.takeError(); | ||||||
8931 | |||||||
8932 | return ToContext.getSubstTemplateTemplateParmPack( | ||||||
8933 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ArgPackOrErr); | ||||||
8934 | } | ||||||
8935 | } | ||||||
8936 | |||||||
8937 | llvm_unreachable("Invalid template name kind")::llvm::llvm_unreachable_internal("Invalid template name kind" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 8937); | ||||||
8938 | } | ||||||
8939 | |||||||
8940 | Expected<SourceLocation> ASTImporter::Import(SourceLocation FromLoc) { | ||||||
8941 | if (FromLoc.isInvalid()) | ||||||
8942 | return SourceLocation{}; | ||||||
8943 | |||||||
8944 | SourceManager &FromSM = FromContext.getSourceManager(); | ||||||
8945 | bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc); | ||||||
8946 | |||||||
8947 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); | ||||||
8948 | Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin); | ||||||
8949 | if (!ToFileIDOrErr) | ||||||
8950 | return ToFileIDOrErr.takeError(); | ||||||
8951 | SourceManager &ToSM = ToContext.getSourceManager(); | ||||||
8952 | return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second); | ||||||
8953 | } | ||||||
8954 | |||||||
8955 | Expected<SourceRange> ASTImporter::Import(SourceRange FromRange) { | ||||||
8956 | SourceLocation ToBegin, ToEnd; | ||||||
8957 | if (Error Err = importInto(ToBegin, FromRange.getBegin())) | ||||||
8958 | return std::move(Err); | ||||||
8959 | if (Error Err = importInto(ToEnd, FromRange.getEnd())) | ||||||
8960 | return std::move(Err); | ||||||
8961 | |||||||
8962 | return SourceRange(ToBegin, ToEnd); | ||||||
8963 | } | ||||||
8964 | |||||||
8965 | Expected<FileID> ASTImporter::Import(FileID FromID, bool IsBuiltin) { | ||||||
8966 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); | ||||||
8967 | if (Pos != ImportedFileIDs.end()) | ||||||
8968 | return Pos->second; | ||||||
8969 | |||||||
8970 | SourceManager &FromSM = FromContext.getSourceManager(); | ||||||
8971 | SourceManager &ToSM = ToContext.getSourceManager(); | ||||||
8972 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); | ||||||
8973 | |||||||
8974 | // Map the FromID to the "to" source manager. | ||||||
8975 | FileID ToID; | ||||||
8976 | if (FromSLoc.isExpansion()) { | ||||||
8977 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); | ||||||
8978 | ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc()); | ||||||
8979 | if (!ToSpLoc) | ||||||
8980 | return ToSpLoc.takeError(); | ||||||
8981 | ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart()); | ||||||
8982 | if (!ToExLocS) | ||||||
8983 | return ToExLocS.takeError(); | ||||||
8984 | unsigned TokenLen = FromSM.getFileIDSize(FromID); | ||||||
8985 | SourceLocation MLoc; | ||||||
8986 | if (FromEx.isMacroArgExpansion()) { | ||||||
8987 | MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, TokenLen); | ||||||
8988 | } else { | ||||||
8989 | if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd())) | ||||||
8990 | MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, TokenLen, | ||||||
8991 | FromEx.isExpansionTokenRange()); | ||||||
8992 | else | ||||||
8993 | return ToExLocE.takeError(); | ||||||
8994 | } | ||||||
8995 | ToID = ToSM.getFileID(MLoc); | ||||||
8996 | } else { | ||||||
8997 | const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache(); | ||||||
8998 | |||||||
8999 | if (!IsBuiltin && !Cache->BufferOverridden) { | ||||||
9000 | // Include location of this file. | ||||||
9001 | ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); | ||||||
9002 | if (!ToIncludeLoc) | ||||||
9003 | return ToIncludeLoc.takeError(); | ||||||
9004 | |||||||
9005 | // Every FileID that is not the main FileID needs to have a valid include | ||||||
9006 | // location so that the include chain points to the main FileID. When | ||||||
9007 | // importing the main FileID (which has no include location), we need to | ||||||
9008 | // create a fake include location in the main file to keep this property | ||||||
9009 | // intact. | ||||||
9010 | SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc; | ||||||
9011 | if (FromID == FromSM.getMainFileID()) | ||||||
9012 | ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID()); | ||||||
9013 | |||||||
9014 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { | ||||||
9015 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the | ||||||
9016 | // disk again | ||||||
9017 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather | ||||||
9018 | // than mmap the files several times. | ||||||
9019 | auto Entry = | ||||||
9020 | ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName()); | ||||||
9021 | // FIXME: The filename may be a virtual name that does probably not | ||||||
9022 | // point to a valid file and we get no Entry here. In this case try with | ||||||
9023 | // the memory buffer below. | ||||||
9024 | if (Entry) | ||||||
9025 | ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc, | ||||||
9026 | FromSLoc.getFile().getFileCharacteristic()); | ||||||
9027 | } | ||||||
9028 | } | ||||||
9029 | |||||||
9030 | if (ToID.isInvalid() || IsBuiltin) { | ||||||
9031 | // FIXME: We want to re-use the existing MemoryBuffer! | ||||||
9032 | llvm::Optional<llvm::MemoryBufferRef> FromBuf = | ||||||
9033 | Cache->getBufferOrNone(FromContext.getDiagnostics(), | ||||||
9034 | FromSM.getFileManager(), SourceLocation{}); | ||||||
9035 | if (!FromBuf) | ||||||
9036 | return llvm::make_error<ImportError>(ImportError::Unknown); | ||||||
9037 | |||||||
9038 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = | ||||||
9039 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), | ||||||
9040 | FromBuf->getBufferIdentifier()); | ||||||
9041 | ToID = ToSM.createFileID(std::move(ToBuf), | ||||||
9042 | FromSLoc.getFile().getFileCharacteristic()); | ||||||
9043 | } | ||||||
9044 | } | ||||||
9045 | |||||||
9046 | 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.\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 9046, __extension__ __PRETTY_FUNCTION__)); | ||||||
9047 | |||||||
9048 | ImportedFileIDs[FromID] = ToID; | ||||||
9049 | return ToID; | ||||||
9050 | } | ||||||
9051 | |||||||
9052 | Expected<CXXCtorInitializer *> ASTImporter::Import(CXXCtorInitializer *From) { | ||||||
9053 | ExpectedExpr ToExprOrErr = Import(From->getInit()); | ||||||
9054 | if (!ToExprOrErr) | ||||||
9055 | return ToExprOrErr.takeError(); | ||||||
9056 | |||||||
9057 | auto LParenLocOrErr = Import(From->getLParenLoc()); | ||||||
9058 | if (!LParenLocOrErr) | ||||||
9059 | return LParenLocOrErr.takeError(); | ||||||
9060 | |||||||
9061 | auto RParenLocOrErr = Import(From->getRParenLoc()); | ||||||
9062 | if (!RParenLocOrErr) | ||||||
9063 | return RParenLocOrErr.takeError(); | ||||||
9064 | |||||||
9065 | if (From->isBaseInitializer()) { | ||||||
9066 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); | ||||||
9067 | if (!ToTInfoOrErr) | ||||||
9068 | return ToTInfoOrErr.takeError(); | ||||||
9069 | |||||||
9070 | SourceLocation EllipsisLoc; | ||||||
9071 | if (From->isPackExpansion()) | ||||||
9072 | if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc())) | ||||||
9073 | return std::move(Err); | ||||||
9074 | |||||||
9075 | return new (ToContext) CXXCtorInitializer( | ||||||
9076 | ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr, | ||||||
9077 | *ToExprOrErr, *RParenLocOrErr, EllipsisLoc); | ||||||
9078 | } else if (From->isMemberInitializer()) { | ||||||
9079 | ExpectedDecl ToFieldOrErr = Import(From->getMember()); | ||||||
9080 | if (!ToFieldOrErr) | ||||||
9081 | return ToFieldOrErr.takeError(); | ||||||
9082 | |||||||
9083 | auto MemberLocOrErr = Import(From->getMemberLocation()); | ||||||
9084 | if (!MemberLocOrErr) | ||||||
9085 | return MemberLocOrErr.takeError(); | ||||||
9086 | |||||||
9087 | return new (ToContext) CXXCtorInitializer( | ||||||
9088 | ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr, | ||||||
9089 | *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); | ||||||
9090 | } else if (From->isIndirectMemberInitializer()) { | ||||||
9091 | ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember()); | ||||||
9092 | if (!ToIFieldOrErr) | ||||||
9093 | return ToIFieldOrErr.takeError(); | ||||||
9094 | |||||||
9095 | auto MemberLocOrErr = Import(From->getMemberLocation()); | ||||||
9096 | if (!MemberLocOrErr) | ||||||
9097 | return MemberLocOrErr.takeError(); | ||||||
9098 | |||||||
9099 | return new (ToContext) CXXCtorInitializer( | ||||||
9100 | ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr), | ||||||
9101 | *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); | ||||||
9102 | } else if (From->isDelegatingInitializer()) { | ||||||
9103 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); | ||||||
9104 | if (!ToTInfoOrErr) | ||||||
9105 | return ToTInfoOrErr.takeError(); | ||||||
9106 | |||||||
9107 | return new (ToContext) | ||||||
9108 | CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr, | ||||||
9109 | *ToExprOrErr, *RParenLocOrErr); | ||||||
9110 | } else { | ||||||
9111 | // FIXME: assert? | ||||||
9112 | return make_error<ImportError>(); | ||||||
9113 | } | ||||||
9114 | } | ||||||
9115 | |||||||
9116 | Expected<CXXBaseSpecifier *> | ||||||
9117 | ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { | ||||||
9118 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); | ||||||
9119 | if (Pos != ImportedCXXBaseSpecifiers.end()) | ||||||
9120 | return Pos->second; | ||||||
9121 | |||||||
9122 | Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange()); | ||||||
9123 | if (!ToSourceRange) | ||||||
9124 | return ToSourceRange.takeError(); | ||||||
9125 | Expected<TypeSourceInfo *> ToTSI = Import(BaseSpec->getTypeSourceInfo()); | ||||||
9126 | if (!ToTSI) | ||||||
9127 | return ToTSI.takeError(); | ||||||
9128 | ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc()); | ||||||
9129 | if (!ToEllipsisLoc) | ||||||
9130 | return ToEllipsisLoc.takeError(); | ||||||
9131 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( | ||||||
9132 | *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), | ||||||
9133 | BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc); | ||||||
9134 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; | ||||||
9135 | return Imported; | ||||||
9136 | } | ||||||
9137 | |||||||
9138 | llvm::Expected<APValue> ASTImporter::Import(const APValue &FromValue) { | ||||||
9139 | ASTNodeImporter Importer(*this); | ||||||
9140 | return Importer.ImportAPValue(FromValue); | ||||||
9141 | } | ||||||
9142 | |||||||
9143 | Error ASTImporter::ImportDefinition(Decl *From) { | ||||||
9144 | ExpectedDecl ToOrErr = Import(From); | ||||||
9145 | if (!ToOrErr) | ||||||
9146 | return ToOrErr.takeError(); | ||||||
9147 | Decl *To = *ToOrErr; | ||||||
9148 | |||||||
9149 | auto *FromDC = cast<DeclContext>(From); | ||||||
9150 | ASTNodeImporter Importer(*this); | ||||||
9151 | |||||||
9152 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { | ||||||
9153 | if (!ToRecord->getDefinition()) { | ||||||
9154 | return Importer.ImportDefinition( | ||||||
9155 | cast<RecordDecl>(FromDC), ToRecord, | ||||||
9156 | ASTNodeImporter::IDK_Everything); | ||||||
9157 | } | ||||||
9158 | } | ||||||
9159 | |||||||
9160 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { | ||||||
9161 | if (!ToEnum->getDefinition()) { | ||||||
9162 | return Importer.ImportDefinition( | ||||||
9163 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); | ||||||
9164 | } | ||||||
9165 | } | ||||||
9166 | |||||||
9167 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { | ||||||
9168 | if (!ToIFace->getDefinition()) { | ||||||
9169 | return Importer.ImportDefinition( | ||||||
9170 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, | ||||||
9171 | ASTNodeImporter::IDK_Everything); | ||||||
9172 | } | ||||||
9173 | } | ||||||
9174 | |||||||
9175 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { | ||||||
9176 | if (!ToProto->getDefinition()) { | ||||||
9177 | return Importer.ImportDefinition( | ||||||
9178 | cast<ObjCProtocolDecl>(FromDC), ToProto, | ||||||
9179 | ASTNodeImporter::IDK_Everything); | ||||||
9180 | } | ||||||
9181 | } | ||||||
9182 | |||||||
9183 | return Importer.ImportDeclContext(FromDC, true); | ||||||
9184 | } | ||||||
9185 | |||||||
9186 | Expected<DeclarationName> ASTImporter::Import(DeclarationName FromName) { | ||||||
9187 | if (!FromName) | ||||||
9188 | return DeclarationName{}; | ||||||
9189 | |||||||
9190 | switch (FromName.getNameKind()) { | ||||||
9191 | case DeclarationName::Identifier: | ||||||
9192 | return DeclarationName(Import(FromName.getAsIdentifierInfo())); | ||||||
9193 | |||||||
9194 | case DeclarationName::ObjCZeroArgSelector: | ||||||
9195 | case DeclarationName::ObjCOneArgSelector: | ||||||
9196 | case DeclarationName::ObjCMultiArgSelector: | ||||||
9197 | if (auto ToSelOrErr = Import(FromName.getObjCSelector())) | ||||||
9198 | return DeclarationName(*ToSelOrErr); | ||||||
9199 | else | ||||||
9200 | return ToSelOrErr.takeError(); | ||||||
9201 | |||||||
9202 | case DeclarationName::CXXConstructorName: { | ||||||
9203 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) | ||||||
9204 | return ToContext.DeclarationNames.getCXXConstructorName( | ||||||
9205 | ToContext.getCanonicalType(*ToTyOrErr)); | ||||||
9206 | else | ||||||
9207 | return ToTyOrErr.takeError(); | ||||||
9208 | } | ||||||
9209 | |||||||
9210 | case DeclarationName::CXXDestructorName: { | ||||||
9211 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) | ||||||
9212 | return ToContext.DeclarationNames.getCXXDestructorName( | ||||||
9213 | ToContext.getCanonicalType(*ToTyOrErr)); | ||||||
9214 | else | ||||||
9215 | return ToTyOrErr.takeError(); | ||||||
9216 | } | ||||||
9217 | |||||||
9218 | case DeclarationName::CXXDeductionGuideName: { | ||||||
9219 | if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate())) | ||||||
9220 | return ToContext.DeclarationNames.getCXXDeductionGuideName( | ||||||
9221 | cast<TemplateDecl>(*ToTemplateOrErr)); | ||||||
9222 | else | ||||||
9223 | return ToTemplateOrErr.takeError(); | ||||||
9224 | } | ||||||
9225 | |||||||
9226 | case DeclarationName::CXXConversionFunctionName: { | ||||||
9227 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) | ||||||
9228 | return ToContext.DeclarationNames.getCXXConversionFunctionName( | ||||||
9229 | ToContext.getCanonicalType(*ToTyOrErr)); | ||||||
9230 | else | ||||||
9231 | return ToTyOrErr.takeError(); | ||||||
9232 | } | ||||||
9233 | |||||||
9234 | case DeclarationName::CXXOperatorName: | ||||||
9235 | return ToContext.DeclarationNames.getCXXOperatorName( | ||||||
9236 | FromName.getCXXOverloadedOperator()); | ||||||
9237 | |||||||
9238 | case DeclarationName::CXXLiteralOperatorName: | ||||||
9239 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( | ||||||
9240 | Import(FromName.getCXXLiteralIdentifier())); | ||||||
9241 | |||||||
9242 | case DeclarationName::CXXUsingDirective: | ||||||
9243 | // FIXME: STATICS! | ||||||
9244 | return DeclarationName::getUsingDirectiveName(); | ||||||
9245 | } | ||||||
9246 | |||||||
9247 | llvm_unreachable("Invalid DeclarationName Kind!")::llvm::llvm_unreachable_internal("Invalid DeclarationName Kind!" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 9247); | ||||||
9248 | } | ||||||
9249 | |||||||
9250 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { | ||||||
9251 | if (!FromId) | ||||||
9252 | return nullptr; | ||||||
9253 | |||||||
9254 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); | ||||||
9255 | |||||||
9256 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) | ||||||
9257 | ToId->setBuiltinID(FromId->getBuiltinID()); | ||||||
9258 | |||||||
9259 | return ToId; | ||||||
9260 | } | ||||||
9261 | |||||||
9262 | Expected<Selector> ASTImporter::Import(Selector FromSel) { | ||||||
9263 | if (FromSel.isNull()) | ||||||
9264 | return Selector{}; | ||||||
9265 | |||||||
9266 | SmallVector<IdentifierInfo *, 4> Idents; | ||||||
9267 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); | ||||||
9268 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) | ||||||
9269 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); | ||||||
9270 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); | ||||||
9271 | } | ||||||
9272 | |||||||
9273 | llvm::Expected<APValue> | ||||||
9274 | ASTNodeImporter::ImportAPValue(const APValue &FromValue) { | ||||||
9275 | APValue Result; | ||||||
9276 | llvm::Error Err = llvm::Error::success(); | ||||||
9277 | auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) { | ||||||
9278 | for (unsigned Idx = 0; Idx < Size; Idx++) { | ||||||
9279 | APValue Tmp = importChecked(Err, From[Idx]); | ||||||
9280 | To[Idx] = Tmp; | ||||||
9281 | } | ||||||
9282 | }; | ||||||
9283 | switch (FromValue.getKind()) { | ||||||
9284 | case APValue::None: | ||||||
9285 | case APValue::Indeterminate: | ||||||
9286 | case APValue::Int: | ||||||
9287 | case APValue::Float: | ||||||
9288 | case APValue::FixedPoint: | ||||||
9289 | case APValue::ComplexInt: | ||||||
9290 | case APValue::ComplexFloat: | ||||||
9291 | Result = FromValue; | ||||||
9292 | break; | ||||||
9293 | case APValue::Vector: { | ||||||
9294 | Result.MakeVector(); | ||||||
9295 | MutableArrayRef<APValue> Elts = | ||||||
9296 | Result.setVectorUninit(FromValue.getVectorLength()); | ||||||
9297 | ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts, | ||||||
9298 | Elts.data(), FromValue.getVectorLength()); | ||||||
9299 | break; | ||||||
9300 | } | ||||||
9301 | case APValue::Array: | ||||||
9302 | Result.MakeArray(FromValue.getArrayInitializedElts(), | ||||||
9303 | FromValue.getArraySize()); | ||||||
9304 | ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts, | ||||||
9305 | ((const APValue::Arr *)(const char *)&Result.Data)->Elts, | ||||||
9306 | FromValue.getArrayInitializedElts()); | ||||||
9307 | break; | ||||||
9308 | case APValue::Struct: | ||||||
9309 | Result.MakeStruct(FromValue.getStructNumBases(), | ||||||
9310 | FromValue.getStructNumFields()); | ||||||
9311 | ImportLoop( | ||||||
9312 | ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts, | ||||||
9313 | ((const APValue::StructData *)(const char *)&Result.Data)->Elts, | ||||||
9314 | FromValue.getStructNumBases() + FromValue.getStructNumFields()); | ||||||
9315 | break; | ||||||
9316 | case APValue::Union: { | ||||||
9317 | Result.MakeUnion(); | ||||||
9318 | const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField()); | ||||||
9319 | APValue ImpValue = importChecked(Err, FromValue.getUnionValue()); | ||||||
9320 | if (Err) | ||||||
9321 | return std::move(Err); | ||||||
9322 | Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue); | ||||||
9323 | break; | ||||||
9324 | } | ||||||
9325 | case APValue::AddrLabelDiff: { | ||||||
9326 | Result.MakeAddrLabelDiff(); | ||||||
9327 | const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS()); | ||||||
9328 | const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS()); | ||||||
9329 | if (Err) | ||||||
9330 | return std::move(Err); | ||||||
9331 | Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS), | ||||||
9332 | cast<AddrLabelExpr>(ImpRHS)); | ||||||
9333 | break; | ||||||
9334 | } | ||||||
9335 | case APValue::MemberPointer: { | ||||||
9336 | const Decl *ImpMemPtrDecl = | ||||||
9337 | importChecked(Err, FromValue.getMemberPointerDecl()); | ||||||
9338 | if (Err) | ||||||
9339 | return std::move(Err); | ||||||
9340 | MutableArrayRef<const CXXRecordDecl *> ToPath = | ||||||
9341 | Result.setMemberPointerUninit( | ||||||
9342 | cast<const ValueDecl>(ImpMemPtrDecl), | ||||||
9343 | FromValue.isMemberPointerToDerivedMember(), | ||||||
9344 | FromValue.getMemberPointerPath().size()); | ||||||
9345 | llvm::ArrayRef<const CXXRecordDecl *> FromPath = | ||||||
9346 | Result.getMemberPointerPath(); | ||||||
9347 | for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size(); | ||||||
9348 | Idx++) { | ||||||
9349 | const Decl *ImpDecl = importChecked(Err, FromPath[Idx]); | ||||||
9350 | if (Err) | ||||||
9351 | return std::move(Err); | ||||||
9352 | ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl()); | ||||||
9353 | } | ||||||
9354 | break; | ||||||
9355 | } | ||||||
9356 | case APValue::LValue: | ||||||
9357 | APValue::LValueBase Base; | ||||||
9358 | QualType FromElemTy; | ||||||
9359 | if (FromValue.getLValueBase()) { | ||||||
9360 | 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\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 9362, __extension__ __PRETTY_FUNCTION__)) | ||||||
9361 | "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\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 9362, __extension__ __PRETTY_FUNCTION__)) | ||||||
9362 | "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\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 9362, __extension__ __PRETTY_FUNCTION__)); | ||||||
9363 | if (!FromValue.getLValueBase().is<TypeInfoLValue>()) { | ||||||
9364 | if (const auto *E = | ||||||
9365 | FromValue.getLValueBase().dyn_cast<const Expr *>()) { | ||||||
9366 | FromElemTy = E->getType(); | ||||||
9367 | const Expr *ImpExpr = importChecked(Err, E); | ||||||
9368 | if (Err) | ||||||
9369 | return std::move(Err); | ||||||
9370 | Base = APValue::LValueBase(ImpExpr, | ||||||
9371 | FromValue.getLValueBase().getCallIndex(), | ||||||
9372 | FromValue.getLValueBase().getVersion()); | ||||||
9373 | } else { | ||||||
9374 | FromElemTy = | ||||||
9375 | FromValue.getLValueBase().get<const ValueDecl *>()->getType(); | ||||||
9376 | const Decl *ImpDecl = importChecked( | ||||||
9377 | Err, FromValue.getLValueBase().get<const ValueDecl *>()); | ||||||
9378 | if (Err) | ||||||
9379 | return std::move(Err); | ||||||
9380 | Base = APValue::LValueBase(cast<ValueDecl>(ImpDecl), | ||||||
9381 | FromValue.getLValueBase().getCallIndex(), | ||||||
9382 | FromValue.getLValueBase().getVersion()); | ||||||
9383 | } | ||||||
9384 | } else { | ||||||
9385 | FromElemTy = FromValue.getLValueBase().getTypeInfoType(); | ||||||
9386 | QualType ImpTypeInfo = importChecked( | ||||||
9387 | Err, | ||||||
9388 | QualType(FromValue.getLValueBase().get<TypeInfoLValue>().getType(), | ||||||
9389 | 0)); | ||||||
9390 | QualType ImpType = | ||||||
9391 | importChecked(Err, FromValue.getLValueBase().getTypeInfoType()); | ||||||
9392 | if (Err) | ||||||
9393 | return std::move(Err); | ||||||
9394 | Base = APValue::LValueBase::getTypeInfo( | ||||||
9395 | TypeInfoLValue(ImpTypeInfo.getTypePtr()), ImpType); | ||||||
9396 | } | ||||||
9397 | } | ||||||
9398 | CharUnits Offset = FromValue.getLValueOffset(); | ||||||
9399 | unsigned PathLength = FromValue.getLValuePath().size(); | ||||||
9400 | Result.MakeLValue(); | ||||||
9401 | if (FromValue.hasLValuePath()) { | ||||||
9402 | MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit( | ||||||
9403 | Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(), | ||||||
9404 | FromValue.isNullPointer()); | ||||||
9405 | llvm::ArrayRef<APValue::LValuePathEntry> FromPath = | ||||||
9406 | FromValue.getLValuePath(); | ||||||
9407 | for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) { | ||||||
9408 | if (FromElemTy->isRecordType()) { | ||||||
9409 | const Decl *FromDecl = | ||||||
9410 | FromPath[LoopIdx].getAsBaseOrMember().getPointer(); | ||||||
9411 | const Decl *ImpDecl = importChecked(Err, FromDecl); | ||||||
9412 | if (Err) | ||||||
9413 | return std::move(Err); | ||||||
9414 | if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl)) | ||||||
9415 | FromElemTy = Importer.FromContext.getRecordType(RD); | ||||||
9416 | else | ||||||
9417 | FromElemTy = cast<ValueDecl>(FromDecl)->getType(); | ||||||
9418 | ToPath[LoopIdx] = APValue::LValuePathEntry(APValue::BaseOrMemberType( | ||||||
9419 | ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt())); | ||||||
9420 | } else { | ||||||
9421 | FromElemTy = | ||||||
9422 | Importer.FromContext.getAsArrayType(FromElemTy)->getElementType(); | ||||||
9423 | ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex( | ||||||
9424 | FromPath[LoopIdx].getAsArrayIndex()); | ||||||
9425 | } | ||||||
9426 | } | ||||||
9427 | } else | ||||||
9428 | Result.setLValue(Base, Offset, APValue::NoLValuePath{}, | ||||||
9429 | FromValue.isNullPointer()); | ||||||
9430 | } | ||||||
9431 | if (Err) | ||||||
9432 | return std::move(Err); | ||||||
9433 | return Result; | ||||||
9434 | } | ||||||
9435 | |||||||
9436 | Expected<DeclarationName> ASTImporter::HandleNameConflict(DeclarationName Name, | ||||||
9437 | DeclContext *DC, | ||||||
9438 | unsigned IDNS, | ||||||
9439 | NamedDecl **Decls, | ||||||
9440 | unsigned NumDecls) { | ||||||
9441 | if (ODRHandling == ODRHandlingType::Conservative) | ||||||
9442 | // Report error at any name conflict. | ||||||
9443 | return make_error<ImportError>(ImportError::NameConflict); | ||||||
9444 | else | ||||||
9445 | // Allow to create the new Decl with the same name. | ||||||
9446 | return Name; | ||||||
9447 | } | ||||||
9448 | |||||||
9449 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { | ||||||
9450 | if (LastDiagFromFrom) | ||||||
9451 | ToContext.getDiagnostics().notePriorDiagnosticFrom( | ||||||
9452 | FromContext.getDiagnostics()); | ||||||
9453 | LastDiagFromFrom = false; | ||||||
9454 | return ToContext.getDiagnostics().Report(Loc, DiagID); | ||||||
9455 | } | ||||||
9456 | |||||||
9457 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { | ||||||
9458 | if (!LastDiagFromFrom) | ||||||
9459 | FromContext.getDiagnostics().notePriorDiagnosticFrom( | ||||||
9460 | ToContext.getDiagnostics()); | ||||||
9461 | LastDiagFromFrom = true; | ||||||
9462 | return FromContext.getDiagnostics().Report(Loc, DiagID); | ||||||
9463 | } | ||||||
9464 | |||||||
9465 | void ASTImporter::CompleteDecl (Decl *D) { | ||||||
9466 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { | ||||||
9467 | if (!ID->getDefinition()) | ||||||
9468 | ID->startDefinition(); | ||||||
9469 | } | ||||||
9470 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { | ||||||
9471 | if (!PD->getDefinition()) | ||||||
9472 | PD->startDefinition(); | ||||||
9473 | } | ||||||
9474 | else if (auto *TD = dyn_cast<TagDecl>(D)) { | ||||||
9475 | if (!TD->getDefinition() && !TD->isBeingDefined()) { | ||||||
9476 | TD->startDefinition(); | ||||||
9477 | TD->setCompleteDefinition(true); | ||||||
9478 | } | ||||||
9479 | } | ||||||
9480 | else { | ||||||
9481 | 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\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 9481, __extension__ __PRETTY_FUNCTION__)); | ||||||
9482 | } | ||||||
9483 | } | ||||||
9484 | |||||||
9485 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { | ||||||
9486 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); | ||||||
9487 | 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\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 9488, __extension__ __PRETTY_FUNCTION__)) | ||||||
9488 | "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\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 9488, __extension__ __PRETTY_FUNCTION__)); | ||||||
9489 | if (Pos != ImportedDecls.end()) | ||||||
9490 | return Pos->second; | ||||||
9491 | ImportedDecls[From] = To; | ||||||
9492 | // This mapping should be maintained only in this function. Therefore do not | ||||||
9493 | // check for additional consistency. | ||||||
9494 | ImportedFromDecls[To] = From; | ||||||
9495 | // In the case of TypedefNameDecl we create the Decl first and only then we | ||||||
9496 | // import and set its DeclContext. So, the DC is still not set when we reach | ||||||
9497 | // here from GetImportedOrCreateDecl. | ||||||
9498 | if (To->getDeclContext()) | ||||||
9499 | AddToLookupTable(To); | ||||||
9500 | return To; | ||||||
9501 | } | ||||||
9502 | |||||||
9503 | llvm::Optional<ImportError> | ||||||
9504 | ASTImporter::getImportDeclErrorIfAny(Decl *FromD) const { | ||||||
9505 | auto Pos = ImportDeclErrors.find(FromD); | ||||||
9506 | if (Pos != ImportDeclErrors.end()) | ||||||
9507 | return Pos->second; | ||||||
9508 | else | ||||||
9509 | return Optional<ImportError>(); | ||||||
9510 | } | ||||||
9511 | |||||||
9512 | void ASTImporter::setImportDeclError(Decl *From, ImportError Error) { | ||||||
9513 | auto InsertRes = ImportDeclErrors.insert({From, Error}); | ||||||
9514 | (void)InsertRes; | ||||||
9515 | // Either we set the error for the first time, or we already had set one and | ||||||
9516 | // now we want to set the same error. | ||||||
9517 | 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" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/AST/ASTImporter.cpp" , 9517, __extension__ __PRETTY_FUNCTION__)); | ||||||
9518 | } | ||||||
9519 | |||||||
9520 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, | ||||||
9521 | bool Complain) { | ||||||
9522 | llvm::DenseMap<const Type *, const Type *>::iterator Pos = | ||||||
9523 | ImportedTypes.find(From.getTypePtr()); | ||||||
9524 | if (Pos != ImportedTypes.end()) { | ||||||
9525 | if (ExpectedType ToFromOrErr = Import(From)) { | ||||||
9526 | if (ToContext.hasSameType(*ToFromOrErr, To)) | ||||||
9527 | return true; | ||||||
9528 | } else { | ||||||
9529 | llvm::consumeError(ToFromOrErr.takeError()); | ||||||
9530 | } | ||||||
9531 | } | ||||||
9532 | |||||||
9533 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, | ||||||
9534 | getStructuralEquivalenceKind(*this), false, | ||||||
9535 | Complain); | ||||||
9536 | return Ctx.IsEquivalent(From, To); | ||||||
9537 | } |
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!" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/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 UNRESOLVEDUSINGVALUE |
557 | # define UNRESOLVEDUSINGVALUE(Type, Base) VALUE(Type, Base) |
558 | #endif |
559 | UNRESOLVEDUSINGVALUE(UnresolvedUsingValue, ValueDecl) |
560 | #undef UNRESOLVEDUSINGVALUE |
561 | |
562 | DECL_RANGE(Value, Binding, UnresolvedUsingValue) |
563 | |
564 | #undef VALUE |
565 | |
566 | DECL_RANGE(Named, Using, UnresolvedUsingValue) |
567 | |
568 | #undef NAMED |
569 | |
570 | #ifndef OMPALLOCATE |
571 | # define OMPALLOCATE(Type, Base) DECL(Type, Base) |
572 | #endif |
573 | OMPALLOCATE(OMPAllocate, Decl) |
574 | #undef OMPALLOCATE |
575 | |
576 | #ifndef OMPREQUIRES |
577 | # define OMPREQUIRES(Type, Base) DECL(Type, Base) |
578 | #endif |
579 | OMPREQUIRES(OMPRequires, Decl) |
580 | #undef OMPREQUIRES |
581 | |
582 | #ifndef OMPTHREADPRIVATE |
583 | # define OMPTHREADPRIVATE(Type, Base) DECL(Type, Base) |
584 | #endif |
585 | OMPTHREADPRIVATE(OMPThreadPrivate, Decl) |
586 | #undef OMPTHREADPRIVATE |
587 | |
588 | #ifndef OBJCPROPERTYIMPL |
589 | # define OBJCPROPERTYIMPL(Type, Base) DECL(Type, Base) |
590 | #endif |
591 | OBJCPROPERTYIMPL(ObjCPropertyImpl, Decl) |
592 | #undef OBJCPROPERTYIMPL |
593 | |
594 | #ifndef PRAGMACOMMENT |
595 | # define PRAGMACOMMENT(Type, Base) DECL(Type, Base) |
596 | #endif |
597 | PRAGMACOMMENT(PragmaComment, Decl) |
598 | #undef PRAGMACOMMENT |
599 | |
600 | #ifndef PRAGMADETECTMISMATCH |
601 | # define PRAGMADETECTMISMATCH(Type, Base) DECL(Type, Base) |
602 | #endif |
603 | PRAGMADETECTMISMATCH(PragmaDetectMismatch, Decl) |
604 | #undef PRAGMADETECTMISMATCH |
605 | |
606 | #ifndef REQUIRESEXPRBODY |
607 | # define REQUIRESEXPRBODY(Type, Base) DECL(Type, Base) |
608 | #endif |
609 | REQUIRESEXPRBODY(RequiresExprBody, Decl) |
610 | #undef REQUIRESEXPRBODY |
611 | |
612 | #ifndef STATICASSERT |
613 | # define STATICASSERT(Type, Base) DECL(Type, Base) |
614 | #endif |
615 | STATICASSERT(StaticAssert, Decl) |
616 | #undef STATICASSERT |
617 | |
618 | #ifndef TRANSLATIONUNIT |
619 | # define TRANSLATIONUNIT(Type, Base) DECL(Type, Base) |
620 | #endif |
621 | TRANSLATIONUNIT(TranslationUnit, Decl) |
622 | #undef TRANSLATIONUNIT |
623 | |
624 | LAST_DECL_RANGE(Decl, AccessSpec, TranslationUnit) |
625 | |
626 | #undef DECL |
627 | #undef DECL_RANGE |
628 | #undef LAST_DECL_RANGE |
629 | #undef ABSTRACT_DECL |
630 | /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ |
631 | |* *| |
632 | |* List of AST Decl nodes *| |
633 | |* *| |
634 | |* Automatically generated file, do not edit! *| |
635 | |* *| |
636 | \*===----------------------------------------------------------------------===*/ |
637 | |
638 | #ifndef DECL_CONTEXT |
639 | # define DECL_CONTEXT(DECL) |
640 | #endif |
641 | #ifndef DECL_CONTEXT_BASE |
642 | # define DECL_CONTEXT_BASE(DECL) DECL_CONTEXT(DECL) |
643 | #endif |
644 | DECL_CONTEXT_BASE(Function) |
645 | DECL_CONTEXT_BASE(Tag) |
646 | DECL_CONTEXT_BASE(ObjCContainer) |
647 | DECL_CONTEXT(Block) |
648 | DECL_CONTEXT(Captured) |
649 | DECL_CONTEXT(Export) |
650 | DECL_CONTEXT(ExternCContext) |
651 | DECL_CONTEXT(LinkageSpec) |
652 | DECL_CONTEXT(Namespace) |
653 | DECL_CONTEXT(OMPDeclareMapper) |
654 | DECL_CONTEXT(OMPDeclareReduction) |
655 | DECL_CONTEXT(ObjCMethod) |
656 | DECL_CONTEXT(RequiresExprBody) |
657 | DECL_CONTEXT(TranslationUnit) |
658 | #undef DECL_CONTEXT |
659 | #undef DECL_CONTEXT_BASE |