File: | clang/lib/AST/ASTImporter.cpp |
Warning: | line 3342, column 53 1st function call argument is an uninitialized value |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===// | ||||||||||
2 | // | ||||||||||
3 | // 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-12~++20201130111130+b5fbc60e4de/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-12~++20201130111130+b5fbc60e4de/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-12~++20201130111130+b5fbc60e4de/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 | // Wrapper for an overload set. | ||||||||||
206 | template <typename ToDeclT> struct CallOverloadedCreateFun { | ||||||||||
207 | template <typename... Args> decltype(auto) operator()(Args &&... args) { | ||||||||||
208 | return ToDeclT::Create(std::forward<Args>(args)...); | ||||||||||
209 | } | ||||||||||
210 | }; | ||||||||||
211 | |||||||||||
212 | // Always use these functions to create a Decl during import. There are | ||||||||||
213 | // certain tasks which must be done after the Decl was created, e.g. we | ||||||||||
214 | // must immediately register that as an imported Decl. The parameter `ToD` | ||||||||||
215 | // will be set to the newly created Decl or if had been imported before | ||||||||||
216 | // then to the already imported Decl. Returns a bool value set to true if | ||||||||||
217 | // the `FromD` had been imported before. | ||||||||||
218 | template <typename ToDeclT, typename FromDeclT, typename... Args> | ||||||||||
219 | LLVM_NODISCARD[[clang::warn_unused_result]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, | ||||||||||
220 | Args &&... args) { | ||||||||||
221 | // There may be several overloads of ToDeclT::Create. We must make sure | ||||||||||
222 | // to call the one which would be chosen by the arguments, thus we use a | ||||||||||
223 | // wrapper for the overload set. | ||||||||||
224 | CallOverloadedCreateFun<ToDeclT> OC; | ||||||||||
225 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, | ||||||||||
226 | std::forward<Args>(args)...); | ||||||||||
227 | } | ||||||||||
228 | // Use this overload if a special Type is needed to be created. E.g if we | ||||||||||
229 | // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl` | ||||||||||
230 | // then: | ||||||||||
231 | // TypedefNameDecl *ToTypedef; | ||||||||||
232 | // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...); | ||||||||||
233 | template <typename NewDeclT, typename ToDeclT, typename FromDeclT, | ||||||||||
234 | typename... Args> | ||||||||||
235 | LLVM_NODISCARD[[clang::warn_unused_result]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, | ||||||||||
236 | Args &&... args) { | ||||||||||
237 | CallOverloadedCreateFun<NewDeclT> OC; | ||||||||||
238 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, | ||||||||||
239 | std::forward<Args>(args)...); | ||||||||||
240 | } | ||||||||||
241 | // Use this version if a special create function must be | ||||||||||
242 | // used, e.g. CXXRecordDecl::CreateLambda . | ||||||||||
243 | template <typename ToDeclT, typename CreateFunT, typename FromDeclT, | ||||||||||
244 | typename... Args> | ||||||||||
245 | LLVM_NODISCARD[[clang::warn_unused_result]] bool | ||||||||||
246 | GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun, | ||||||||||
247 | FromDeclT *FromD, Args &&... args) { | ||||||||||
248 | if (Importer.getImportDeclErrorIfAny(FromD)) { | ||||||||||
249 | ToD = nullptr; | ||||||||||
250 | return true; // Already imported but with error. | ||||||||||
251 | } | ||||||||||
252 | ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD)); | ||||||||||
253 | if (ToD) | ||||||||||
254 | return true; // Already imported. | ||||||||||
255 | ToD = CreateFun(std::forward<Args>(args)...); | ||||||||||
256 | // Keep track of imported Decls. | ||||||||||
257 | Importer.RegisterImportedDecl(FromD, ToD); | ||||||||||
258 | InitializeImportedDecl(FromD, ToD); | ||||||||||
259 | return false; // A new Decl is created. | ||||||||||
260 | } | ||||||||||
261 | |||||||||||
262 | void InitializeImportedDecl(Decl *FromD, Decl *ToD) { | ||||||||||
263 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; | ||||||||||
264 | if (FromD->hasAttrs()) | ||||||||||
265 | for (const Attr *FromAttr : FromD->getAttrs()) { | ||||||||||
266 | // FIXME: Return of the error here is not possible until store of | ||||||||||
267 | // import errors is implemented. | ||||||||||
268 | auto ToAttrOrErr = import(FromAttr); | ||||||||||
269 | if (ToAttrOrErr) | ||||||||||
270 | ToD->addAttr(*ToAttrOrErr); | ||||||||||
271 | else | ||||||||||
272 | llvm::consumeError(ToAttrOrErr.takeError()); | ||||||||||
273 | } | ||||||||||
274 | if (FromD->isUsed()) | ||||||||||
275 | ToD->setIsUsed(); | ||||||||||
276 | if (FromD->isImplicit()) | ||||||||||
277 | ToD->setImplicit(); | ||||||||||
278 | } | ||||||||||
279 | |||||||||||
280 | // Check if we have found an existing definition. Returns with that | ||||||||||
281 | // definition if yes, otherwise returns null. | ||||||||||
282 | Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) { | ||||||||||
283 | const FunctionDecl *Definition = nullptr; | ||||||||||
284 | if (D->doesThisDeclarationHaveABody() && | ||||||||||
285 | FoundFunction->hasBody(Definition)) | ||||||||||
286 | return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition)); | ||||||||||
287 | return nullptr; | ||||||||||
288 | } | ||||||||||
289 | |||||||||||
290 | void addDeclToContexts(Decl *FromD, Decl *ToD) { | ||||||||||
291 | if (Importer.isMinimalImport()) { | ||||||||||
292 | // In minimal import case the decl must be added even if it is not | ||||||||||
293 | // contained in original context, for LLDB compatibility. | ||||||||||
294 | // FIXME: Check if a better solution is possible. | ||||||||||
295 | if (!FromD->getDescribedTemplate() && | ||||||||||
296 | FromD->getFriendObjectKind() == Decl::FOK_None) | ||||||||||
297 | ToD->getLexicalDeclContext()->addDeclInternal(ToD); | ||||||||||
298 | return; | ||||||||||
299 | } | ||||||||||
300 | |||||||||||
301 | DeclContext *FromDC = FromD->getDeclContext(); | ||||||||||
302 | DeclContext *FromLexicalDC = FromD->getLexicalDeclContext(); | ||||||||||
303 | DeclContext *ToDC = ToD->getDeclContext(); | ||||||||||
304 | DeclContext *ToLexicalDC = ToD->getLexicalDeclContext(); | ||||||||||
305 | |||||||||||
306 | bool Visible = false; | ||||||||||
307 | if (FromDC->containsDeclAndLoad(FromD)) { | ||||||||||
308 | ToDC->addDeclInternal(ToD); | ||||||||||
309 | Visible = true; | ||||||||||
310 | } | ||||||||||
311 | if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) { | ||||||||||
312 | ToLexicalDC->addDeclInternal(ToD); | ||||||||||
313 | Visible = true; | ||||||||||
314 | } | ||||||||||
315 | |||||||||||
316 | // If the Decl was added to any context, it was made already visible. | ||||||||||
317 | // Otherwise it is still possible that it should be visible. | ||||||||||
318 | if (!Visible) { | ||||||||||
319 | if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) { | ||||||||||
320 | auto *ToNamed = cast<NamedDecl>(ToD); | ||||||||||
321 | DeclContextLookupResult FromLookup = | ||||||||||
322 | FromDC->lookup(FromNamed->getDeclName()); | ||||||||||
323 | for (NamedDecl *ND : FromLookup) | ||||||||||
324 | if (ND == FromNamed) { | ||||||||||
325 | ToDC->makeDeclVisibleInContext(ToNamed); | ||||||||||
326 | break; | ||||||||||
327 | } | ||||||||||
328 | } | ||||||||||
329 | } | ||||||||||
330 | } | ||||||||||
331 | |||||||||||
332 | public: | ||||||||||
333 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} | ||||||||||
334 | |||||||||||
335 | using TypeVisitor<ASTNodeImporter, ExpectedType>::Visit; | ||||||||||
336 | using DeclVisitor<ASTNodeImporter, ExpectedDecl>::Visit; | ||||||||||
337 | using StmtVisitor<ASTNodeImporter, ExpectedStmt>::Visit; | ||||||||||
338 | |||||||||||
339 | // Importing types | ||||||||||
340 | ExpectedType VisitType(const Type *T); | ||||||||||
341 | ExpectedType VisitAtomicType(const AtomicType *T); | ||||||||||
342 | ExpectedType VisitBuiltinType(const BuiltinType *T); | ||||||||||
343 | ExpectedType VisitDecayedType(const DecayedType *T); | ||||||||||
344 | ExpectedType VisitComplexType(const ComplexType *T); | ||||||||||
345 | ExpectedType VisitPointerType(const PointerType *T); | ||||||||||
346 | ExpectedType VisitBlockPointerType(const BlockPointerType *T); | ||||||||||
347 | ExpectedType VisitLValueReferenceType(const LValueReferenceType *T); | ||||||||||
348 | ExpectedType VisitRValueReferenceType(const RValueReferenceType *T); | ||||||||||
349 | ExpectedType VisitMemberPointerType(const MemberPointerType *T); | ||||||||||
350 | ExpectedType VisitConstantArrayType(const ConstantArrayType *T); | ||||||||||
351 | ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T); | ||||||||||
352 | ExpectedType VisitVariableArrayType(const VariableArrayType *T); | ||||||||||
353 | ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T); | ||||||||||
354 | // FIXME: DependentSizedExtVectorType | ||||||||||
355 | ExpectedType VisitVectorType(const VectorType *T); | ||||||||||
356 | ExpectedType VisitExtVectorType(const ExtVectorType *T); | ||||||||||
357 | ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T); | ||||||||||
358 | ExpectedType VisitFunctionProtoType(const FunctionProtoType *T); | ||||||||||
359 | ExpectedType VisitUnresolvedUsingType(const UnresolvedUsingType *T); | ||||||||||
360 | ExpectedType VisitParenType(const ParenType *T); | ||||||||||
361 | ExpectedType VisitTypedefType(const TypedefType *T); | ||||||||||
362 | ExpectedType VisitTypeOfExprType(const TypeOfExprType *T); | ||||||||||
363 | // FIXME: DependentTypeOfExprType | ||||||||||
364 | ExpectedType VisitTypeOfType(const TypeOfType *T); | ||||||||||
365 | ExpectedType VisitDecltypeType(const DecltypeType *T); | ||||||||||
366 | ExpectedType VisitUnaryTransformType(const UnaryTransformType *T); | ||||||||||
367 | ExpectedType VisitAutoType(const AutoType *T); | ||||||||||
368 | ExpectedType VisitInjectedClassNameType(const InjectedClassNameType *T); | ||||||||||
369 | // FIXME: DependentDecltypeType | ||||||||||
370 | ExpectedType VisitRecordType(const RecordType *T); | ||||||||||
371 | ExpectedType VisitEnumType(const EnumType *T); | ||||||||||
372 | ExpectedType VisitAttributedType(const AttributedType *T); | ||||||||||
373 | ExpectedType VisitTemplateTypeParmType(const TemplateTypeParmType *T); | ||||||||||
374 | ExpectedType VisitSubstTemplateTypeParmType( | ||||||||||
375 | const SubstTemplateTypeParmType *T); | ||||||||||
376 | ExpectedType VisitTemplateSpecializationType( | ||||||||||
377 | const TemplateSpecializationType *T); | ||||||||||
378 | ExpectedType VisitElaboratedType(const ElaboratedType *T); | ||||||||||
379 | ExpectedType VisitDependentNameType(const DependentNameType *T); | ||||||||||
380 | ExpectedType VisitPackExpansionType(const PackExpansionType *T); | ||||||||||
381 | ExpectedType VisitDependentTemplateSpecializationType( | ||||||||||
382 | const DependentTemplateSpecializationType *T); | ||||||||||
383 | ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T); | ||||||||||
384 | ExpectedType VisitObjCObjectType(const ObjCObjectType *T); | ||||||||||
385 | ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); | ||||||||||
386 | |||||||||||
387 | // Importing declarations | ||||||||||
388 | Error ImportDeclParts( | ||||||||||
389 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, | ||||||||||
390 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc); | ||||||||||
391 | Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); | ||||||||||
392 | Error ImportDeclarationNameLoc( | ||||||||||
393 | const DeclarationNameInfo &From, DeclarationNameInfo &To); | ||||||||||
394 | Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); | ||||||||||
395 | Error ImportDeclContext( | ||||||||||
396 | Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC); | ||||||||||
397 | Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To); | ||||||||||
398 | |||||||||||
399 | Expected<CXXCastPath> ImportCastPath(CastExpr *E); | ||||||||||
400 | Expected<APValue> ImportAPValue(const APValue &FromValue); | ||||||||||
401 | |||||||||||
402 | using Designator = DesignatedInitExpr::Designator; | ||||||||||
403 | |||||||||||
404 | /// What we should import from the definition. | ||||||||||
405 | enum ImportDefinitionKind { | ||||||||||
406 | /// Import the default subset of the definition, which might be | ||||||||||
407 | /// nothing (if minimal import is set) or might be everything (if minimal | ||||||||||
408 | /// import is not set). | ||||||||||
409 | IDK_Default, | ||||||||||
410 | /// Import everything. | ||||||||||
411 | IDK_Everything, | ||||||||||
412 | /// Import only the bare bones needed to establish a valid | ||||||||||
413 | /// DeclContext. | ||||||||||
414 | IDK_Basic | ||||||||||
415 | }; | ||||||||||
416 | |||||||||||
417 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { | ||||||||||
418 | return IDK == IDK_Everything || | ||||||||||
419 | (IDK == IDK_Default && !Importer.isMinimalImport()); | ||||||||||
420 | } | ||||||||||
421 | |||||||||||
422 | Error ImportInitializer(VarDecl *From, VarDecl *To); | ||||||||||
423 | Error ImportDefinition( | ||||||||||
424 | RecordDecl *From, RecordDecl *To, | ||||||||||
425 | ImportDefinitionKind Kind = IDK_Default); | ||||||||||
426 | Error ImportDefinition( | ||||||||||
427 | EnumDecl *From, EnumDecl *To, | ||||||||||
428 | ImportDefinitionKind Kind = IDK_Default); | ||||||||||
429 | Error ImportDefinition( | ||||||||||
430 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, | ||||||||||
431 | ImportDefinitionKind Kind = IDK_Default); | ||||||||||
432 | Error ImportDefinition( | ||||||||||
433 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, | ||||||||||
434 | ImportDefinitionKind Kind = IDK_Default); | ||||||||||
435 | Error ImportTemplateArguments( | ||||||||||
436 | const TemplateArgument *FromArgs, unsigned NumFromArgs, | ||||||||||
437 | SmallVectorImpl<TemplateArgument> &ToArgs); | ||||||||||
438 | Expected<TemplateArgument> | ||||||||||
439 | ImportTemplateArgument(const TemplateArgument &From); | ||||||||||
440 | |||||||||||
441 | template <typename InContainerTy> | ||||||||||
442 | Error ImportTemplateArgumentListInfo( | ||||||||||
443 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo); | ||||||||||
444 | |||||||||||
445 | template<typename InContainerTy> | ||||||||||
446 | Error ImportTemplateArgumentListInfo( | ||||||||||
447 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, | ||||||||||
448 | const InContainerTy &Container, TemplateArgumentListInfo &Result); | ||||||||||
449 | |||||||||||
450 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; | ||||||||||
451 | using FunctionTemplateAndArgsTy = | ||||||||||
452 | std::tuple<FunctionTemplateDecl *, TemplateArgsTy>; | ||||||||||
453 | Expected<FunctionTemplateAndArgsTy> | ||||||||||
454 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( | ||||||||||
455 | FunctionDecl *FromFD); | ||||||||||
456 | Error ImportTemplateParameterLists(const DeclaratorDecl *FromD, | ||||||||||
457 | DeclaratorDecl *ToD); | ||||||||||
458 | |||||||||||
459 | Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); | ||||||||||
460 | |||||||||||
461 | Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD); | ||||||||||
462 | |||||||||||
463 | Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam, | ||||||||||
464 | ParmVarDecl *ToParam); | ||||||||||
465 | |||||||||||
466 | template <typename T> | ||||||||||
467 | bool hasSameVisibilityContextAndLinkage(T *Found, T *From); | ||||||||||
468 | |||||||||||
469 | bool IsStructuralMatch(Decl *From, Decl *To, bool Complain); | ||||||||||
470 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, | ||||||||||
471 | bool Complain = true); | ||||||||||
472 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, | ||||||||||
473 | bool Complain = true); | ||||||||||
474 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); | ||||||||||
475 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); | ||||||||||
476 | bool IsStructuralMatch(FunctionTemplateDecl *From, | ||||||||||
477 | FunctionTemplateDecl *To); | ||||||||||
478 | bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To); | ||||||||||
479 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); | ||||||||||
480 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); | ||||||||||
481 | ExpectedDecl VisitDecl(Decl *D); | ||||||||||
482 | ExpectedDecl VisitImportDecl(ImportDecl *D); | ||||||||||
483 | ExpectedDecl VisitEmptyDecl(EmptyDecl *D); | ||||||||||
484 | ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D); | ||||||||||
485 | ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D); | ||||||||||
486 | ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D); | ||||||||||
487 | ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D); | ||||||||||
488 | ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D); | ||||||||||
489 | ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); | ||||||||||
490 | ExpectedDecl VisitTypedefDecl(TypedefDecl *D); | ||||||||||
491 | ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D); | ||||||||||
492 | ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); | ||||||||||
493 | ExpectedDecl VisitLabelDecl(LabelDecl *D); | ||||||||||
494 | ExpectedDecl VisitEnumDecl(EnumDecl *D); | ||||||||||
495 | ExpectedDecl VisitRecordDecl(RecordDecl *D); | ||||||||||
496 | ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D); | ||||||||||
497 | ExpectedDecl VisitFunctionDecl(FunctionDecl *D); | ||||||||||
498 | ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D); | ||||||||||
499 | ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); | ||||||||||
500 | ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); | ||||||||||
501 | ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); | ||||||||||
502 | ExpectedDecl VisitFieldDecl(FieldDecl *D); | ||||||||||
503 | ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); | ||||||||||
504 | ExpectedDecl VisitFriendDecl(FriendDecl *D); | ||||||||||
505 | ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D); | ||||||||||
506 | ExpectedDecl VisitVarDecl(VarDecl *D); | ||||||||||
507 | ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D); | ||||||||||
508 | ExpectedDecl VisitParmVarDecl(ParmVarDecl *D); | ||||||||||
509 | ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D); | ||||||||||
510 | ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); | ||||||||||
511 | ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D); | ||||||||||
512 | ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D); | ||||||||||
513 | ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D); | ||||||||||
514 | ExpectedDecl VisitUsingDecl(UsingDecl *D); | ||||||||||
515 | ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D); | ||||||||||
516 | ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D); | ||||||||||
517 | ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); | ||||||||||
518 | ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); | ||||||||||
519 | ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D); | ||||||||||
520 | ExpectedDecl | ||||||||||
521 | VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D); | ||||||||||
522 | |||||||||||
523 | Expected<ObjCTypeParamList *> | ||||||||||
524 | ImportObjCTypeParamList(ObjCTypeParamList *list); | ||||||||||
525 | |||||||||||
526 | ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); | ||||||||||
527 | ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); | ||||||||||
528 | ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D); | ||||||||||
529 | ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D); | ||||||||||
530 | ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); | ||||||||||
531 | ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); | ||||||||||
532 | ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); | ||||||||||
533 | ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); | ||||||||||
534 | ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D); | ||||||||||
535 | ExpectedDecl VisitClassTemplateSpecializationDecl( | ||||||||||
536 | ClassTemplateSpecializationDecl *D); | ||||||||||
537 | ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D); | ||||||||||
538 | ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); | ||||||||||
539 | ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D); | ||||||||||
540 | |||||||||||
541 | // Importing statements | ||||||||||
542 | ExpectedStmt VisitStmt(Stmt *S); | ||||||||||
543 | ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S); | ||||||||||
544 | ExpectedStmt VisitDeclStmt(DeclStmt *S); | ||||||||||
545 | ExpectedStmt VisitNullStmt(NullStmt *S); | ||||||||||
546 | ExpectedStmt VisitCompoundStmt(CompoundStmt *S); | ||||||||||
547 | ExpectedStmt VisitCaseStmt(CaseStmt *S); | ||||||||||
548 | ExpectedStmt VisitDefaultStmt(DefaultStmt *S); | ||||||||||
549 | ExpectedStmt VisitLabelStmt(LabelStmt *S); | ||||||||||
550 | ExpectedStmt VisitAttributedStmt(AttributedStmt *S); | ||||||||||
551 | ExpectedStmt VisitIfStmt(IfStmt *S); | ||||||||||
552 | ExpectedStmt VisitSwitchStmt(SwitchStmt *S); | ||||||||||
553 | ExpectedStmt VisitWhileStmt(WhileStmt *S); | ||||||||||
554 | ExpectedStmt VisitDoStmt(DoStmt *S); | ||||||||||
555 | ExpectedStmt VisitForStmt(ForStmt *S); | ||||||||||
556 | ExpectedStmt VisitGotoStmt(GotoStmt *S); | ||||||||||
557 | ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S); | ||||||||||
558 | ExpectedStmt VisitContinueStmt(ContinueStmt *S); | ||||||||||
559 | ExpectedStmt VisitBreakStmt(BreakStmt *S); | ||||||||||
560 | ExpectedStmt VisitReturnStmt(ReturnStmt *S); | ||||||||||
561 | // FIXME: MSAsmStmt | ||||||||||
562 | // FIXME: SEHExceptStmt | ||||||||||
563 | // FIXME: SEHFinallyStmt | ||||||||||
564 | // FIXME: SEHTryStmt | ||||||||||
565 | // FIXME: SEHLeaveStmt | ||||||||||
566 | // FIXME: CapturedStmt | ||||||||||
567 | ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S); | ||||||||||
568 | ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S); | ||||||||||
569 | ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S); | ||||||||||
570 | // FIXME: MSDependentExistsStmt | ||||||||||
571 | ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); | ||||||||||
572 | ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); | ||||||||||
573 | ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); | ||||||||||
574 | ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S); | ||||||||||
575 | ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); | ||||||||||
576 | ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); | ||||||||||
577 | ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); | ||||||||||
578 | |||||||||||
579 | // Importing expressions | ||||||||||
580 | ExpectedStmt VisitExpr(Expr *E); | ||||||||||
581 | ExpectedStmt VisitVAArgExpr(VAArgExpr *E); | ||||||||||
582 | ExpectedStmt VisitChooseExpr(ChooseExpr *E); | ||||||||||
583 | ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E); | ||||||||||
584 | ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E); | ||||||||||
585 | ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E); | ||||||||||
586 | ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); | ||||||||||
587 | ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E); | ||||||||||
588 | ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); | ||||||||||
589 | ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E); | ||||||||||
590 | ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E); | ||||||||||
591 | ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E); | ||||||||||
592 | ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E); | ||||||||||
593 | ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E); | ||||||||||
594 | ExpectedStmt VisitStringLiteral(StringLiteral *E); | ||||||||||
595 | ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E); | ||||||||||
596 | ExpectedStmt VisitAtomicExpr(AtomicExpr *E); | ||||||||||
597 | ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E); | ||||||||||
598 | ExpectedStmt VisitConstantExpr(ConstantExpr *E); | ||||||||||
599 | ExpectedStmt VisitParenExpr(ParenExpr *E); | ||||||||||
600 | ExpectedStmt VisitParenListExpr(ParenListExpr *E); | ||||||||||
601 | ExpectedStmt VisitStmtExpr(StmtExpr *E); | ||||||||||
602 | ExpectedStmt VisitUnaryOperator(UnaryOperator *E); | ||||||||||
603 | ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); | ||||||||||
604 | ExpectedStmt VisitBinaryOperator(BinaryOperator *E); | ||||||||||
605 | ExpectedStmt VisitConditionalOperator(ConditionalOperator *E); | ||||||||||
606 | ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E); | ||||||||||
607 | ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E); | ||||||||||
608 | ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); | ||||||||||
609 | ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E); | ||||||||||
610 | ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E); | ||||||||||
611 | ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E); | ||||||||||
612 | ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E); | ||||||||||
613 | ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E); | ||||||||||
614 | ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE); | ||||||||||
615 | ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E); | ||||||||||
616 | ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E); | ||||||||||
617 | ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); | ||||||||||
618 | ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); | ||||||||||
619 | ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); | ||||||||||
620 | ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); | ||||||||||
621 | ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); | ||||||||||
622 | ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E); | ||||||||||
623 | ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E); | ||||||||||
624 | ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E); | ||||||||||
625 | ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E); | ||||||||||
626 | ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E); | ||||||||||
627 | ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E); | ||||||||||
628 | ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); | ||||||||||
629 | ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); | ||||||||||
630 | ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); | ||||||||||
631 | ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); | ||||||||||
632 | ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); | ||||||||||
633 | ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E); | ||||||||||
634 | ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E); | ||||||||||
635 | ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); | ||||||||||
636 | ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); | ||||||||||
637 | ExpectedStmt VisitMemberExpr(MemberExpr *E); | ||||||||||
638 | ExpectedStmt VisitCallExpr(CallExpr *E); | ||||||||||
639 | ExpectedStmt VisitLambdaExpr(LambdaExpr *LE); | ||||||||||
640 | ExpectedStmt VisitInitListExpr(InitListExpr *E); | ||||||||||
641 | ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); | ||||||||||
642 | ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); | ||||||||||
643 | ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); | ||||||||||
644 | ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); | ||||||||||
645 | ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); | ||||||||||
646 | ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E); | ||||||||||
647 | ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); | ||||||||||
648 | ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); | ||||||||||
649 | ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); | ||||||||||
650 | |||||||||||
651 | template<typename IIter, typename OIter> | ||||||||||
652 | Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { | ||||||||||
653 | using ItemT = std::remove_reference_t<decltype(*Obegin)>; | ||||||||||
654 | for (; Ibegin != Iend; ++Ibegin, ++Obegin) { | ||||||||||
655 | Expected<ItemT> ToOrErr = import(*Ibegin); | ||||||||||
656 | if (!ToOrErr) | ||||||||||
657 | return ToOrErr.takeError(); | ||||||||||
658 | *Obegin = *ToOrErr; | ||||||||||
659 | } | ||||||||||
660 | return Error::success(); | ||||||||||
661 | } | ||||||||||
662 | |||||||||||
663 | // Import every item from a container structure into an output container. | ||||||||||
664 | // If error occurs, stops at first error and returns the error. | ||||||||||
665 | // The output container should have space for all needed elements (it is not | ||||||||||
666 | // expanded, new items are put into from the beginning). | ||||||||||
667 | template<typename InContainerTy, typename OutContainerTy> | ||||||||||
668 | Error ImportContainerChecked( | ||||||||||
669 | const InContainerTy &InContainer, OutContainerTy &OutContainer) { | ||||||||||
670 | return ImportArrayChecked( | ||||||||||
671 | InContainer.begin(), InContainer.end(), OutContainer.begin()); | ||||||||||
672 | } | ||||||||||
673 | |||||||||||
674 | template<typename InContainerTy, typename OIter> | ||||||||||
675 | Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { | ||||||||||
676 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); | ||||||||||
677 | } | ||||||||||
678 | |||||||||||
679 | Error ImportOverriddenMethods(CXXMethodDecl *ToMethod, | ||||||||||
680 | CXXMethodDecl *FromMethod); | ||||||||||
681 | |||||||||||
682 | Expected<FunctionDecl *> FindFunctionTemplateSpecialization( | ||||||||||
683 | FunctionDecl *FromFD); | ||||||||||
684 | |||||||||||
685 | // Returns true if the given function has a placeholder return type and | ||||||||||
686 | // that type is declared inside the body of the function. | ||||||||||
687 | // E.g. auto f() { struct X{}; return X(); } | ||||||||||
688 | bool hasAutoReturnTypeDeclaredInside(FunctionDecl *D); | ||||||||||
689 | }; | ||||||||||
690 | |||||||||||
691 | template <typename InContainerTy> | ||||||||||
692 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( | ||||||||||
693 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, | ||||||||||
694 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { | ||||||||||
695 | auto ToLAngleLocOrErr = import(FromLAngleLoc); | ||||||||||
696 | if (!ToLAngleLocOrErr) | ||||||||||
697 | return ToLAngleLocOrErr.takeError(); | ||||||||||
698 | auto ToRAngleLocOrErr = import(FromRAngleLoc); | ||||||||||
699 | if (!ToRAngleLocOrErr) | ||||||||||
700 | return ToRAngleLocOrErr.takeError(); | ||||||||||
701 | |||||||||||
702 | TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr); | ||||||||||
703 | if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo)) | ||||||||||
704 | return Err; | ||||||||||
705 | Result = ToTAInfo; | ||||||||||
706 | return Error::success(); | ||||||||||
707 | } | ||||||||||
708 | |||||||||||
709 | template <> | ||||||||||
710 | Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( | ||||||||||
711 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { | ||||||||||
712 | return ImportTemplateArgumentListInfo( | ||||||||||
713 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); | ||||||||||
714 | } | ||||||||||
715 | |||||||||||
716 | template <> | ||||||||||
717 | Error ASTNodeImporter::ImportTemplateArgumentListInfo< | ||||||||||
718 | ASTTemplateArgumentListInfo>( | ||||||||||
719 | const ASTTemplateArgumentListInfo &From, | ||||||||||
720 | TemplateArgumentListInfo &Result) { | ||||||||||
721 | return ImportTemplateArgumentListInfo( | ||||||||||
722 | From.LAngleLoc, From.RAngleLoc, From.arguments(), Result); | ||||||||||
723 | } | ||||||||||
724 | |||||||||||
725 | Expected<ASTNodeImporter::FunctionTemplateAndArgsTy> | ||||||||||
726 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( | ||||||||||
727 | FunctionDecl *FromFD) { | ||||||||||
728 | assert(FromFD->getTemplatedKind() ==((FromFD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplateSpecialization ) ? static_cast<void> (0) : __assert_fail ("FromFD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplateSpecialization" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 729, __PRETTY_FUNCTION__)) | ||||||||||
729 | FunctionDecl::TK_FunctionTemplateSpecialization)((FromFD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplateSpecialization ) ? static_cast<void> (0) : __assert_fail ("FromFD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplateSpecialization" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 729, __PRETTY_FUNCTION__)); | ||||||||||
730 | |||||||||||
731 | FunctionTemplateAndArgsTy Result; | ||||||||||
732 | |||||||||||
733 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); | ||||||||||
734 | if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate())) | ||||||||||
735 | return std::move(Err); | ||||||||||
736 | |||||||||||
737 | // Import template arguments. | ||||||||||
738 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); | ||||||||||
739 | if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), | ||||||||||
740 | std::get<1>(Result))) | ||||||||||
741 | return std::move(Err); | ||||||||||
742 | |||||||||||
743 | return Result; | ||||||||||
744 | } | ||||||||||
745 | |||||||||||
746 | template <> | ||||||||||
747 | Expected<TemplateParameterList *> | ||||||||||
748 | ASTNodeImporter::import(TemplateParameterList *From) { | ||||||||||
749 | SmallVector<NamedDecl *, 4> To(From->size()); | ||||||||||
750 | if (Error Err = ImportContainerChecked(*From, To)) | ||||||||||
751 | return std::move(Err); | ||||||||||
752 | |||||||||||
753 | ExpectedExpr ToRequiresClause = import(From->getRequiresClause()); | ||||||||||
754 | if (!ToRequiresClause) | ||||||||||
755 | return ToRequiresClause.takeError(); | ||||||||||
756 | |||||||||||
757 | auto ToTemplateLocOrErr = import(From->getTemplateLoc()); | ||||||||||
758 | if (!ToTemplateLocOrErr) | ||||||||||
759 | return ToTemplateLocOrErr.takeError(); | ||||||||||
760 | auto ToLAngleLocOrErr = import(From->getLAngleLoc()); | ||||||||||
761 | if (!ToLAngleLocOrErr) | ||||||||||
762 | return ToLAngleLocOrErr.takeError(); | ||||||||||
763 | auto ToRAngleLocOrErr = import(From->getRAngleLoc()); | ||||||||||
764 | if (!ToRAngleLocOrErr) | ||||||||||
765 | return ToRAngleLocOrErr.takeError(); | ||||||||||
766 | |||||||||||
767 | return TemplateParameterList::Create( | ||||||||||
768 | Importer.getToContext(), | ||||||||||
769 | *ToTemplateLocOrErr, | ||||||||||
770 | *ToLAngleLocOrErr, | ||||||||||
771 | To, | ||||||||||
772 | *ToRAngleLocOrErr, | ||||||||||
773 | *ToRequiresClause); | ||||||||||
774 | } | ||||||||||
775 | |||||||||||
776 | template <> | ||||||||||
777 | Expected<TemplateArgument> | ||||||||||
778 | ASTNodeImporter::import(const TemplateArgument &From) { | ||||||||||
779 | switch (From.getKind()) { | ||||||||||
780 | case TemplateArgument::Null: | ||||||||||
781 | return TemplateArgument(); | ||||||||||
782 | |||||||||||
783 | case TemplateArgument::Type: { | ||||||||||
784 | ExpectedType ToTypeOrErr = import(From.getAsType()); | ||||||||||
785 | if (!ToTypeOrErr) | ||||||||||
786 | return ToTypeOrErr.takeError(); | ||||||||||
787 | return TemplateArgument(*ToTypeOrErr); | ||||||||||
788 | } | ||||||||||
789 | |||||||||||
790 | case TemplateArgument::Integral: { | ||||||||||
791 | ExpectedType ToTypeOrErr = import(From.getIntegralType()); | ||||||||||
792 | if (!ToTypeOrErr) | ||||||||||
793 | return ToTypeOrErr.takeError(); | ||||||||||
794 | return TemplateArgument(From, *ToTypeOrErr); | ||||||||||
795 | } | ||||||||||
796 | |||||||||||
797 | case TemplateArgument::Declaration: { | ||||||||||
798 | Expected<ValueDecl *> ToOrErr = import(From.getAsDecl()); | ||||||||||
799 | if (!ToOrErr) | ||||||||||
800 | return ToOrErr.takeError(); | ||||||||||
801 | ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); | ||||||||||
802 | if (!ToTypeOrErr) | ||||||||||
803 | return ToTypeOrErr.takeError(); | ||||||||||
804 | return TemplateArgument(*ToOrErr, *ToTypeOrErr); | ||||||||||
805 | } | ||||||||||
806 | |||||||||||
807 | case TemplateArgument::NullPtr: { | ||||||||||
808 | ExpectedType ToTypeOrErr = import(From.getNullPtrType()); | ||||||||||
809 | if (!ToTypeOrErr) | ||||||||||
810 | return ToTypeOrErr.takeError(); | ||||||||||
811 | return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); | ||||||||||
812 | } | ||||||||||
813 | |||||||||||
814 | case TemplateArgument::Template: { | ||||||||||
815 | Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate()); | ||||||||||
816 | if (!ToTemplateOrErr) | ||||||||||
817 | return ToTemplateOrErr.takeError(); | ||||||||||
818 | |||||||||||
819 | return TemplateArgument(*ToTemplateOrErr); | ||||||||||
820 | } | ||||||||||
821 | |||||||||||
822 | case TemplateArgument::TemplateExpansion: { | ||||||||||
823 | Expected<TemplateName> ToTemplateOrErr = | ||||||||||
824 | import(From.getAsTemplateOrTemplatePattern()); | ||||||||||
825 | if (!ToTemplateOrErr) | ||||||||||
826 | return ToTemplateOrErr.takeError(); | ||||||||||
827 | |||||||||||
828 | return TemplateArgument( | ||||||||||
829 | *ToTemplateOrErr, From.getNumTemplateExpansions()); | ||||||||||
830 | } | ||||||||||
831 | |||||||||||
832 | case TemplateArgument::Expression: | ||||||||||
833 | if (ExpectedExpr ToExpr = import(From.getAsExpr())) | ||||||||||
834 | return TemplateArgument(*ToExpr); | ||||||||||
835 | else | ||||||||||
836 | return ToExpr.takeError(); | ||||||||||
837 | |||||||||||
838 | case TemplateArgument::Pack: { | ||||||||||
839 | SmallVector<TemplateArgument, 2> ToPack; | ||||||||||
840 | ToPack.reserve(From.pack_size()); | ||||||||||
841 | if (Error Err = ImportTemplateArguments( | ||||||||||
842 | From.pack_begin(), From.pack_size(), ToPack)) | ||||||||||
843 | return std::move(Err); | ||||||||||
844 | |||||||||||
845 | return TemplateArgument( | ||||||||||
846 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); | ||||||||||
847 | } | ||||||||||
848 | } | ||||||||||
849 | |||||||||||
850 | llvm_unreachable("Invalid template argument kind")::llvm::llvm_unreachable_internal("Invalid template argument kind" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 850); | ||||||||||
851 | } | ||||||||||
852 | |||||||||||
853 | template <> | ||||||||||
854 | Expected<TemplateArgumentLoc> | ||||||||||
855 | ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) { | ||||||||||
856 | Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument()); | ||||||||||
857 | if (!ArgOrErr) | ||||||||||
858 | return ArgOrErr.takeError(); | ||||||||||
859 | TemplateArgument Arg = *ArgOrErr; | ||||||||||
860 | |||||||||||
861 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); | ||||||||||
862 | |||||||||||
863 | TemplateArgumentLocInfo ToInfo; | ||||||||||
864 | if (Arg.getKind() == TemplateArgument::Expression) { | ||||||||||
865 | ExpectedExpr E = import(FromInfo.getAsExpr()); | ||||||||||
866 | if (!E) | ||||||||||
867 | return E.takeError(); | ||||||||||
868 | ToInfo = TemplateArgumentLocInfo(*E); | ||||||||||
869 | } else if (Arg.getKind() == TemplateArgument::Type) { | ||||||||||
870 | if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo())) | ||||||||||
871 | ToInfo = TemplateArgumentLocInfo(*TSIOrErr); | ||||||||||
872 | else | ||||||||||
873 | return TSIOrErr.takeError(); | ||||||||||
874 | } else { | ||||||||||
875 | auto ToTemplateQualifierLocOrErr = | ||||||||||
876 | import(FromInfo.getTemplateQualifierLoc()); | ||||||||||
877 | if (!ToTemplateQualifierLocOrErr) | ||||||||||
878 | return ToTemplateQualifierLocOrErr.takeError(); | ||||||||||
879 | auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc()); | ||||||||||
880 | if (!ToTemplateNameLocOrErr) | ||||||||||
881 | return ToTemplateNameLocOrErr.takeError(); | ||||||||||
882 | auto ToTemplateEllipsisLocOrErr = | ||||||||||
883 | import(FromInfo.getTemplateEllipsisLoc()); | ||||||||||
884 | if (!ToTemplateEllipsisLocOrErr) | ||||||||||
885 | return ToTemplateEllipsisLocOrErr.takeError(); | ||||||||||
886 | ToInfo = TemplateArgumentLocInfo( | ||||||||||
887 | Importer.getToContext(), *ToTemplateQualifierLocOrErr, | ||||||||||
888 | *ToTemplateNameLocOrErr, *ToTemplateEllipsisLocOrErr); | ||||||||||
889 | } | ||||||||||
890 | |||||||||||
891 | return TemplateArgumentLoc(Arg, ToInfo); | ||||||||||
892 | } | ||||||||||
893 | |||||||||||
894 | template <> | ||||||||||
895 | Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) { | ||||||||||
896 | if (DG.isNull()) | ||||||||||
897 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); | ||||||||||
898 | size_t NumDecls = DG.end() - DG.begin(); | ||||||||||
899 | SmallVector<Decl *, 1> ToDecls; | ||||||||||
900 | ToDecls.reserve(NumDecls); | ||||||||||
901 | for (Decl *FromD : DG) { | ||||||||||
902 | if (auto ToDOrErr = import(FromD)) | ||||||||||
903 | ToDecls.push_back(*ToDOrErr); | ||||||||||
904 | else | ||||||||||
905 | return ToDOrErr.takeError(); | ||||||||||
906 | } | ||||||||||
907 | return DeclGroupRef::Create(Importer.getToContext(), | ||||||||||
908 | ToDecls.begin(), | ||||||||||
909 | NumDecls); | ||||||||||
910 | } | ||||||||||
911 | |||||||||||
912 | template <> | ||||||||||
913 | Expected<ASTNodeImporter::Designator> | ||||||||||
914 | ASTNodeImporter::import(const Designator &D) { | ||||||||||
915 | if (D.isFieldDesignator()) { | ||||||||||
916 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); | ||||||||||
917 | |||||||||||
918 | ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc()); | ||||||||||
919 | if (!ToDotLocOrErr) | ||||||||||
920 | return ToDotLocOrErr.takeError(); | ||||||||||
921 | |||||||||||
922 | ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc()); | ||||||||||
923 | if (!ToFieldLocOrErr) | ||||||||||
924 | return ToFieldLocOrErr.takeError(); | ||||||||||
925 | |||||||||||
926 | return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr); | ||||||||||
927 | } | ||||||||||
928 | |||||||||||
929 | ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc()); | ||||||||||
930 | if (!ToLBracketLocOrErr) | ||||||||||
931 | return ToLBracketLocOrErr.takeError(); | ||||||||||
932 | |||||||||||
933 | ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc()); | ||||||||||
934 | if (!ToRBracketLocOrErr) | ||||||||||
935 | return ToRBracketLocOrErr.takeError(); | ||||||||||
936 | |||||||||||
937 | if (D.isArrayDesignator()) | ||||||||||
938 | return Designator(D.getFirstExprIndex(), | ||||||||||
939 | *ToLBracketLocOrErr, *ToRBracketLocOrErr); | ||||||||||
940 | |||||||||||
941 | ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc()); | ||||||||||
942 | if (!ToEllipsisLocOrErr) | ||||||||||
943 | return ToEllipsisLocOrErr.takeError(); | ||||||||||
944 | |||||||||||
945 | assert(D.isArrayRangeDesignator())((D.isArrayRangeDesignator()) ? static_cast<void> (0) : __assert_fail ("D.isArrayRangeDesignator()", "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 945, __PRETTY_FUNCTION__)); | ||||||||||
946 | return Designator( | ||||||||||
947 | D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr, | ||||||||||
948 | *ToRBracketLocOrErr); | ||||||||||
949 | } | ||||||||||
950 | |||||||||||
951 | template <> | ||||||||||
952 | Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) { | ||||||||||
953 | VarDecl *Var = nullptr; | ||||||||||
954 | if (From.capturesVariable()) { | ||||||||||
955 | if (auto VarOrErr = import(From.getCapturedVar())) | ||||||||||
956 | Var = *VarOrErr; | ||||||||||
957 | else | ||||||||||
958 | return VarOrErr.takeError(); | ||||||||||
959 | } | ||||||||||
960 | |||||||||||
961 | auto LocationOrErr = import(From.getLocation()); | ||||||||||
962 | if (!LocationOrErr) | ||||||||||
963 | return LocationOrErr.takeError(); | ||||||||||
964 | |||||||||||
965 | SourceLocation EllipsisLoc; | ||||||||||
966 | if (From.isPackExpansion()) | ||||||||||
967 | if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc())) | ||||||||||
968 | return std::move(Err); | ||||||||||
969 | |||||||||||
970 | return LambdaCapture( | ||||||||||
971 | *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var, | ||||||||||
972 | EllipsisLoc); | ||||||||||
973 | } | ||||||||||
974 | |||||||||||
975 | template <typename T> | ||||||||||
976 | bool ASTNodeImporter::hasSameVisibilityContextAndLinkage(T *Found, T *From) { | ||||||||||
977 | if (Found->getLinkageInternal() != From->getLinkageInternal()) | ||||||||||
978 | return false; | ||||||||||
979 | |||||||||||
980 | if (From->hasExternalFormalLinkage()) | ||||||||||
981 | return Found->hasExternalFormalLinkage(); | ||||||||||
982 | if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl()) | ||||||||||
983 | return false; | ||||||||||
984 | if (From->isInAnonymousNamespace()) | ||||||||||
985 | return Found->isInAnonymousNamespace(); | ||||||||||
986 | else | ||||||||||
987 | return !Found->isInAnonymousNamespace() && | ||||||||||
988 | !Found->hasExternalFormalLinkage(); | ||||||||||
989 | } | ||||||||||
990 | |||||||||||
991 | template <> | ||||||||||
992 | bool ASTNodeImporter::hasSameVisibilityContextAndLinkage(TypedefNameDecl *Found, | ||||||||||
993 | TypedefNameDecl *From) { | ||||||||||
994 | if (Found->getLinkageInternal() != From->getLinkageInternal()) | ||||||||||
995 | return false; | ||||||||||
996 | |||||||||||
997 | if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace()) | ||||||||||
998 | return Importer.GetFromTU(Found) == From->getTranslationUnitDecl(); | ||||||||||
999 | return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace(); | ||||||||||
1000 | } | ||||||||||
1001 | |||||||||||
1002 | } // namespace clang | ||||||||||
1003 | |||||||||||
1004 | //---------------------------------------------------------------------------- | ||||||||||
1005 | // Import Types | ||||||||||
1006 | //---------------------------------------------------------------------------- | ||||||||||
1007 | |||||||||||
1008 | using namespace clang; | ||||||||||
1009 | |||||||||||
1010 | ExpectedType ASTNodeImporter::VisitType(const Type *T) { | ||||||||||
1011 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) | ||||||||||
1012 | << T->getTypeClassName(); | ||||||||||
1013 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | ||||||||||
1014 | } | ||||||||||
1015 | |||||||||||
1016 | ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ | ||||||||||
1017 | ExpectedType UnderlyingTypeOrErr = import(T->getValueType()); | ||||||||||
1018 | if (!UnderlyingTypeOrErr) | ||||||||||
1019 | return UnderlyingTypeOrErr.takeError(); | ||||||||||
1020 | |||||||||||
1021 | return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr); | ||||||||||
1022 | } | ||||||||||
1023 | |||||||||||
1024 | ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { | ||||||||||
1025 | switch (T->getKind()) { | ||||||||||
1026 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ | ||||||||||
1027 | case BuiltinType::Id: \ | ||||||||||
1028 | return Importer.getToContext().SingletonId; | ||||||||||
1029 | #include "clang/Basic/OpenCLImageTypes.def" | ||||||||||
1030 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ | ||||||||||
1031 | case BuiltinType::Id: \ | ||||||||||
1032 | return Importer.getToContext().Id##Ty; | ||||||||||
1033 | #include "clang/Basic/OpenCLExtensionTypes.def" | ||||||||||
1034 | #define SVE_TYPE(Name, Id, SingletonId) \ | ||||||||||
1035 | case BuiltinType::Id: \ | ||||||||||
1036 | return Importer.getToContext().SingletonId; | ||||||||||
1037 | #include "clang/Basic/AArch64SVEACLETypes.def" | ||||||||||
1038 | #define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ | ||||||||||
1039 | case BuiltinType::Id: \ | ||||||||||
1040 | return Importer.getToContext().Id##Ty; | ||||||||||
1041 | #include "clang/Basic/PPCTypes.def" | ||||||||||
1042 | #define SHARED_SINGLETON_TYPE(Expansion) | ||||||||||
1043 | #define BUILTIN_TYPE(Id, SingletonId) \ | ||||||||||
1044 | case BuiltinType::Id: return Importer.getToContext().SingletonId; | ||||||||||
1045 | #include "clang/AST/BuiltinTypes.def" | ||||||||||
1046 | |||||||||||
1047 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" | ||||||||||
1048 | // context supports C++. | ||||||||||
1049 | |||||||||||
1050 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" | ||||||||||
1051 | // context supports ObjC. | ||||||||||
1052 | |||||||||||
1053 | case BuiltinType::Char_U: | ||||||||||
1054 | // The context we're importing from has an unsigned 'char'. If we're | ||||||||||
1055 | // importing into a context with a signed 'char', translate to | ||||||||||
1056 | // 'unsigned char' instead. | ||||||||||
1057 | if (Importer.getToContext().getLangOpts().CharIsSigned) | ||||||||||
1058 | return Importer.getToContext().UnsignedCharTy; | ||||||||||
1059 | |||||||||||
1060 | return Importer.getToContext().CharTy; | ||||||||||
1061 | |||||||||||
1062 | case BuiltinType::Char_S: | ||||||||||
1063 | // The context we're importing from has an unsigned 'char'. If we're | ||||||||||
1064 | // importing into a context with a signed 'char', translate to | ||||||||||
1065 | // 'unsigned char' instead. | ||||||||||
1066 | if (!Importer.getToContext().getLangOpts().CharIsSigned) | ||||||||||
1067 | return Importer.getToContext().SignedCharTy; | ||||||||||
1068 | |||||||||||
1069 | return Importer.getToContext().CharTy; | ||||||||||
1070 | |||||||||||
1071 | case BuiltinType::WChar_S: | ||||||||||
1072 | case BuiltinType::WChar_U: | ||||||||||
1073 | // FIXME: If not in C++, shall we translate to the C equivalent of | ||||||||||
1074 | // wchar_t? | ||||||||||
1075 | return Importer.getToContext().WCharTy; | ||||||||||
1076 | } | ||||||||||
1077 | |||||||||||
1078 | llvm_unreachable("Invalid BuiltinType Kind!")::llvm::llvm_unreachable_internal("Invalid BuiltinType Kind!" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 1078); | ||||||||||
1079 | } | ||||||||||
1080 | |||||||||||
1081 | ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { | ||||||||||
1082 | ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType()); | ||||||||||
1083 | if (!ToOriginalTypeOrErr) | ||||||||||
1084 | return ToOriginalTypeOrErr.takeError(); | ||||||||||
1085 | |||||||||||
1086 | return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr); | ||||||||||
1087 | } | ||||||||||
1088 | |||||||||||
1089 | ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) { | ||||||||||
1090 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | ||||||||||
1091 | if (!ToElementTypeOrErr) | ||||||||||
1092 | return ToElementTypeOrErr.takeError(); | ||||||||||
1093 | |||||||||||
1094 | return Importer.getToContext().getComplexType(*ToElementTypeOrErr); | ||||||||||
1095 | } | ||||||||||
1096 | |||||||||||
1097 | ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) { | ||||||||||
1098 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | ||||||||||
1099 | if (!ToPointeeTypeOrErr) | ||||||||||
1100 | return ToPointeeTypeOrErr.takeError(); | ||||||||||
1101 | |||||||||||
1102 | return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr); | ||||||||||
1103 | } | ||||||||||
1104 | |||||||||||
1105 | ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { | ||||||||||
1106 | // FIXME: Check for blocks support in "to" context. | ||||||||||
1107 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | ||||||||||
1108 | if (!ToPointeeTypeOrErr) | ||||||||||
1109 | return ToPointeeTypeOrErr.takeError(); | ||||||||||
1110 | |||||||||||
1111 | return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr); | ||||||||||
1112 | } | ||||||||||
1113 | |||||||||||
1114 | ExpectedType | ||||||||||
1115 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { | ||||||||||
1116 | // FIXME: Check for C++ support in "to" context. | ||||||||||
1117 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); | ||||||||||
1118 | if (!ToPointeeTypeOrErr) | ||||||||||
1119 | return ToPointeeTypeOrErr.takeError(); | ||||||||||
1120 | |||||||||||
1121 | return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr); | ||||||||||
1122 | } | ||||||||||
1123 | |||||||||||
1124 | ExpectedType | ||||||||||
1125 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { | ||||||||||
1126 | // FIXME: Check for C++0x support in "to" context. | ||||||||||
1127 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); | ||||||||||
1128 | if (!ToPointeeTypeOrErr) | ||||||||||
1129 | return ToPointeeTypeOrErr.takeError(); | ||||||||||
1130 | |||||||||||
1131 | return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr); | ||||||||||
1132 | } | ||||||||||
1133 | |||||||||||
1134 | ExpectedType | ||||||||||
1135 | ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { | ||||||||||
1136 | // FIXME: Check for C++ support in "to" context. | ||||||||||
1137 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | ||||||||||
1138 | if (!ToPointeeTypeOrErr) | ||||||||||
1139 | return ToPointeeTypeOrErr.takeError(); | ||||||||||
1140 | |||||||||||
1141 | ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0)); | ||||||||||
1142 | if (!ClassTypeOrErr) | ||||||||||
1143 | return ClassTypeOrErr.takeError(); | ||||||||||
1144 | |||||||||||
1145 | return Importer.getToContext().getMemberPointerType( | ||||||||||
1146 | *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr()); | ||||||||||
1147 | } | ||||||||||
1148 | |||||||||||
1149 | ExpectedType | ||||||||||
1150 | ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { | ||||||||||
1151 | Error Err = Error::success(); | ||||||||||
1152 | auto ToElementType = importChecked(Err, T->getElementType()); | ||||||||||
1153 | auto ToSizeExpr = importChecked(Err, T->getSizeExpr()); | ||||||||||
1154 | if (Err) | ||||||||||
1155 | return std::move(Err); | ||||||||||
1156 | |||||||||||
1157 | return Importer.getToContext().getConstantArrayType( | ||||||||||
1158 | ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(), | ||||||||||
1159 | T->getIndexTypeCVRQualifiers()); | ||||||||||
1160 | } | ||||||||||
1161 | |||||||||||
1162 | ExpectedType | ||||||||||
1163 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { | ||||||||||
1164 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | ||||||||||
1165 | if (!ToElementTypeOrErr) | ||||||||||
1166 | return ToElementTypeOrErr.takeError(); | ||||||||||
1167 | |||||||||||
1168 | return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr, | ||||||||||
1169 | T->getSizeModifier(), | ||||||||||
1170 | T->getIndexTypeCVRQualifiers()); | ||||||||||
1171 | } | ||||||||||
1172 | |||||||||||
1173 | ExpectedType | ||||||||||
1174 | ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { | ||||||||||
1175 | Error Err = Error::success(); | ||||||||||
1176 | QualType ToElementType = importChecked(Err, T->getElementType()); | ||||||||||
1177 | Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr()); | ||||||||||
1178 | SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange()); | ||||||||||
1179 | if (Err) | ||||||||||
1180 | return std::move(Err); | ||||||||||
1181 | return Importer.getToContext().getVariableArrayType( | ||||||||||
1182 | ToElementType, ToSizeExpr, T->getSizeModifier(), | ||||||||||
1183 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); | ||||||||||
1184 | } | ||||||||||
1185 | |||||||||||
1186 | ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( | ||||||||||
1187 | const DependentSizedArrayType *T) { | ||||||||||
1188 | Error Err = Error::success(); | ||||||||||
1189 | QualType ToElementType = importChecked(Err, T->getElementType()); | ||||||||||
1190 | Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr()); | ||||||||||
1191 | SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange()); | ||||||||||
1192 | if (Err) | ||||||||||
1193 | return std::move(Err); | ||||||||||
1194 | // SizeExpr may be null if size is not specified directly. | ||||||||||
1195 | // For example, 'int a[]'. | ||||||||||
1196 | |||||||||||
1197 | return Importer.getToContext().getDependentSizedArrayType( | ||||||||||
1198 | ToElementType, ToSizeExpr, T->getSizeModifier(), | ||||||||||
1199 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); | ||||||||||
1200 | } | ||||||||||
1201 | |||||||||||
1202 | ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) { | ||||||||||
1203 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | ||||||||||
1204 | if (!ToElementTypeOrErr) | ||||||||||
1205 | return ToElementTypeOrErr.takeError(); | ||||||||||
1206 | |||||||||||
1207 | return Importer.getToContext().getVectorType(*ToElementTypeOrErr, | ||||||||||
1208 | T->getNumElements(), | ||||||||||
1209 | T->getVectorKind()); | ||||||||||
1210 | } | ||||||||||
1211 | |||||||||||
1212 | ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { | ||||||||||
1213 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | ||||||||||
1214 | if (!ToElementTypeOrErr) | ||||||||||
1215 | return ToElementTypeOrErr.takeError(); | ||||||||||
1216 | |||||||||||
1217 | return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr, | ||||||||||
1218 | T->getNumElements()); | ||||||||||
1219 | } | ||||||||||
1220 | |||||||||||
1221 | ExpectedType | ||||||||||
1222 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { | ||||||||||
1223 | // FIXME: What happens if we're importing a function without a prototype | ||||||||||
1224 | // into C++? Should we make it variadic? | ||||||||||
1225 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); | ||||||||||
1226 | if (!ToReturnTypeOrErr) | ||||||||||
1227 | return ToReturnTypeOrErr.takeError(); | ||||||||||
1228 | |||||||||||
1229 | return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr, | ||||||||||
1230 | T->getExtInfo()); | ||||||||||
1231 | } | ||||||||||
1232 | |||||||||||
1233 | ExpectedType | ||||||||||
1234 | ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { | ||||||||||
1235 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); | ||||||||||
1236 | if (!ToReturnTypeOrErr) | ||||||||||
1237 | return ToReturnTypeOrErr.takeError(); | ||||||||||
1238 | |||||||||||
1239 | // Import argument types | ||||||||||
1240 | SmallVector<QualType, 4> ArgTypes; | ||||||||||
1241 | for (const auto &A : T->param_types()) { | ||||||||||
1242 | ExpectedType TyOrErr = import(A); | ||||||||||
1243 | if (!TyOrErr) | ||||||||||
1244 | return TyOrErr.takeError(); | ||||||||||
1245 | ArgTypes.push_back(*TyOrErr); | ||||||||||
1246 | } | ||||||||||
1247 | |||||||||||
1248 | // Import exception types | ||||||||||
1249 | SmallVector<QualType, 4> ExceptionTypes; | ||||||||||
1250 | for (const auto &E : T->exceptions()) { | ||||||||||
1251 | ExpectedType TyOrErr = import(E); | ||||||||||
1252 | if (!TyOrErr) | ||||||||||
1253 | return TyOrErr.takeError(); | ||||||||||
1254 | ExceptionTypes.push_back(*TyOrErr); | ||||||||||
1255 | } | ||||||||||
1256 | |||||||||||
1257 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); | ||||||||||
1258 | Error Err = Error::success(); | ||||||||||
1259 | FunctionProtoType::ExtProtoInfo ToEPI; | ||||||||||
1260 | ToEPI.ExtInfo = FromEPI.ExtInfo; | ||||||||||
1261 | ToEPI.Variadic = FromEPI.Variadic; | ||||||||||
1262 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; | ||||||||||
1263 | ToEPI.TypeQuals = FromEPI.TypeQuals; | ||||||||||
1264 | ToEPI.RefQualifier = FromEPI.RefQualifier; | ||||||||||
1265 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; | ||||||||||
1266 | ToEPI.ExceptionSpec.NoexceptExpr = | ||||||||||
1267 | importChecked(Err, FromEPI.ExceptionSpec.NoexceptExpr); | ||||||||||
1268 | ToEPI.ExceptionSpec.SourceDecl = | ||||||||||
1269 | importChecked(Err, FromEPI.ExceptionSpec.SourceDecl); | ||||||||||
1270 | ToEPI.ExceptionSpec.SourceTemplate = | ||||||||||
1271 | importChecked(Err, FromEPI.ExceptionSpec.SourceTemplate); | ||||||||||
1272 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; | ||||||||||
1273 | |||||||||||
1274 | if (Err) | ||||||||||
1275 | return std::move(Err); | ||||||||||
1276 | |||||||||||
1277 | return Importer.getToContext().getFunctionType( | ||||||||||
1278 | *ToReturnTypeOrErr, ArgTypes, ToEPI); | ||||||||||
1279 | } | ||||||||||
1280 | |||||||||||
1281 | ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( | ||||||||||
1282 | const UnresolvedUsingType *T) { | ||||||||||
1283 | Error Err = Error::success(); | ||||||||||
1284 | auto ToD = importChecked(Err, T->getDecl()); | ||||||||||
1285 | auto ToPrevD = importChecked(Err, T->getDecl()->getPreviousDecl()); | ||||||||||
1286 | if (Err) | ||||||||||
1287 | return std::move(Err); | ||||||||||
1288 | |||||||||||
1289 | return Importer.getToContext().getTypeDeclType( | ||||||||||
1290 | ToD, cast_or_null<TypeDecl>(ToPrevD)); | ||||||||||
1291 | } | ||||||||||
1292 | |||||||||||
1293 | ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) { | ||||||||||
1294 | ExpectedType ToInnerTypeOrErr = import(T->getInnerType()); | ||||||||||
1295 | if (!ToInnerTypeOrErr) | ||||||||||
1296 | return ToInnerTypeOrErr.takeError(); | ||||||||||
1297 | |||||||||||
1298 | return Importer.getToContext().getParenType(*ToInnerTypeOrErr); | ||||||||||
1299 | } | ||||||||||
1300 | |||||||||||
1301 | ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { | ||||||||||
1302 | Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl()); | ||||||||||
1303 | if (!ToDeclOrErr) | ||||||||||
1304 | return ToDeclOrErr.takeError(); | ||||||||||
1305 | |||||||||||
1306 | return Importer.getToContext().getTypeDeclType(*ToDeclOrErr); | ||||||||||
1307 | } | ||||||||||
1308 | |||||||||||
1309 | ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { | ||||||||||
1310 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); | ||||||||||
1311 | if (!ToExprOrErr) | ||||||||||
1312 | return ToExprOrErr.takeError(); | ||||||||||
1313 | |||||||||||
1314 | return Importer.getToContext().getTypeOfExprType(*ToExprOrErr); | ||||||||||
1315 | } | ||||||||||
1316 | |||||||||||
1317 | ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { | ||||||||||
1318 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | ||||||||||
1319 | if (!ToUnderlyingTypeOrErr) | ||||||||||
1320 | return ToUnderlyingTypeOrErr.takeError(); | ||||||||||
1321 | |||||||||||
1322 | return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr); | ||||||||||
1323 | } | ||||||||||
1324 | |||||||||||
1325 | ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { | ||||||||||
1326 | // FIXME: Make sure that the "to" context supports C++0x! | ||||||||||
1327 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); | ||||||||||
1328 | if (!ToExprOrErr) | ||||||||||
1329 | return ToExprOrErr.takeError(); | ||||||||||
1330 | |||||||||||
1331 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | ||||||||||
1332 | if (!ToUnderlyingTypeOrErr) | ||||||||||
1333 | return ToUnderlyingTypeOrErr.takeError(); | ||||||||||
1334 | |||||||||||
1335 | return Importer.getToContext().getDecltypeType( | ||||||||||
1336 | *ToExprOrErr, *ToUnderlyingTypeOrErr); | ||||||||||
1337 | } | ||||||||||
1338 | |||||||||||
1339 | ExpectedType | ||||||||||
1340 | ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { | ||||||||||
1341 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); | ||||||||||
1342 | if (!ToBaseTypeOrErr) | ||||||||||
1343 | return ToBaseTypeOrErr.takeError(); | ||||||||||
1344 | |||||||||||
1345 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | ||||||||||
1346 | if (!ToUnderlyingTypeOrErr) | ||||||||||
1347 | return ToUnderlyingTypeOrErr.takeError(); | ||||||||||
1348 | |||||||||||
1349 | return Importer.getToContext().getUnaryTransformType( | ||||||||||
1350 | *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind()); | ||||||||||
1351 | } | ||||||||||
1352 | |||||||||||
1353 | ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) { | ||||||||||
1354 | // FIXME: Make sure that the "to" context supports C++11! | ||||||||||
1355 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); | ||||||||||
1356 | if (!ToDeducedTypeOrErr) | ||||||||||
1357 | return ToDeducedTypeOrErr.takeError(); | ||||||||||
1358 | |||||||||||
1359 | ExpectedDecl ToTypeConstraintConcept = import(T->getTypeConstraintConcept()); | ||||||||||
1360 | if (!ToTypeConstraintConcept) | ||||||||||
1361 | return ToTypeConstraintConcept.takeError(); | ||||||||||
1362 | |||||||||||
1363 | SmallVector<TemplateArgument, 2> ToTemplateArgs; | ||||||||||
1364 | ArrayRef<TemplateArgument> FromTemplateArgs = T->getTypeConstraintArguments(); | ||||||||||
1365 | if (Error Err = ImportTemplateArguments(FromTemplateArgs.data(), | ||||||||||
1366 | FromTemplateArgs.size(), | ||||||||||
1367 | ToTemplateArgs)) | ||||||||||
1368 | return std::move(Err); | ||||||||||
1369 | |||||||||||
1370 | return Importer.getToContext().getAutoType( | ||||||||||
1371 | *ToDeducedTypeOrErr, T->getKeyword(), /*IsDependent*/false, | ||||||||||
1372 | /*IsPack=*/false, cast_or_null<ConceptDecl>(*ToTypeConstraintConcept), | ||||||||||
1373 | ToTemplateArgs); | ||||||||||
1374 | } | ||||||||||
1375 | |||||||||||
1376 | ExpectedType ASTNodeImporter::VisitInjectedClassNameType( | ||||||||||
1377 | const InjectedClassNameType *T) { | ||||||||||
1378 | Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl()); | ||||||||||
1379 | if (!ToDeclOrErr) | ||||||||||
1380 | return ToDeclOrErr.takeError(); | ||||||||||
1381 | |||||||||||
1382 | ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType()); | ||||||||||
1383 | if (!ToInjTypeOrErr) | ||||||||||
1384 | return ToInjTypeOrErr.takeError(); | ||||||||||
1385 | |||||||||||
1386 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading | ||||||||||
1387 | // See comments in InjectedClassNameType definition for details | ||||||||||
1388 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); | ||||||||||
1389 | enum { | ||||||||||
1390 | TypeAlignmentInBits = 4, | ||||||||||
1391 | TypeAlignment = 1 << TypeAlignmentInBits | ||||||||||
1392 | }; | ||||||||||
1393 | |||||||||||
1394 | return QualType(new (Importer.getToContext(), TypeAlignment) | ||||||||||
1395 | InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0); | ||||||||||
1396 | } | ||||||||||
1397 | |||||||||||
1398 | ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) { | ||||||||||
1399 | Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl()); | ||||||||||
1400 | if (!ToDeclOrErr) | ||||||||||
1401 | return ToDeclOrErr.takeError(); | ||||||||||
1402 | |||||||||||
1403 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); | ||||||||||
1404 | } | ||||||||||
1405 | |||||||||||
1406 | ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) { | ||||||||||
1407 | Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl()); | ||||||||||
1408 | if (!ToDeclOrErr) | ||||||||||
1409 | return ToDeclOrErr.takeError(); | ||||||||||
1410 | |||||||||||
1411 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); | ||||||||||
1412 | } | ||||||||||
1413 | |||||||||||
1414 | ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { | ||||||||||
1415 | ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType()); | ||||||||||
1416 | if (!ToModifiedTypeOrErr) | ||||||||||
1417 | return ToModifiedTypeOrErr.takeError(); | ||||||||||
1418 | ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType()); | ||||||||||
1419 | if (!ToEquivalentTypeOrErr) | ||||||||||
1420 | return ToEquivalentTypeOrErr.takeError(); | ||||||||||
1421 | |||||||||||
1422 | return Importer.getToContext().getAttributedType(T->getAttrKind(), | ||||||||||
1423 | *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr); | ||||||||||
1424 | } | ||||||||||
1425 | |||||||||||
1426 | ExpectedType ASTNodeImporter::VisitTemplateTypeParmType( | ||||||||||
1427 | const TemplateTypeParmType *T) { | ||||||||||
1428 | Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl()); | ||||||||||
1429 | if (!ToDeclOrErr) | ||||||||||
1430 | return ToDeclOrErr.takeError(); | ||||||||||
1431 | |||||||||||
1432 | return Importer.getToContext().getTemplateTypeParmType( | ||||||||||
1433 | T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr); | ||||||||||
1434 | } | ||||||||||
1435 | |||||||||||
1436 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( | ||||||||||
1437 | const SubstTemplateTypeParmType *T) { | ||||||||||
1438 | ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); | ||||||||||
1439 | if (!ReplacedOrErr) | ||||||||||
1440 | return ReplacedOrErr.takeError(); | ||||||||||
1441 | const TemplateTypeParmType *Replaced = | ||||||||||
1442 | cast<TemplateTypeParmType>((*ReplacedOrErr).getTypePtr()); | ||||||||||
1443 | |||||||||||
1444 | ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); | ||||||||||
1445 | if (!ToReplacementTypeOrErr) | ||||||||||
1446 | return ToReplacementTypeOrErr.takeError(); | ||||||||||
1447 | |||||||||||
1448 | return Importer.getToContext().getSubstTemplateTypeParmType( | ||||||||||
1449 | Replaced, (*ToReplacementTypeOrErr).getCanonicalType()); | ||||||||||
1450 | } | ||||||||||
1451 | |||||||||||
1452 | ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( | ||||||||||
1453 | const TemplateSpecializationType *T) { | ||||||||||
1454 | auto ToTemplateOrErr = import(T->getTemplateName()); | ||||||||||
1455 | if (!ToTemplateOrErr) | ||||||||||
1456 | return ToTemplateOrErr.takeError(); | ||||||||||
1457 | |||||||||||
1458 | SmallVector<TemplateArgument, 2> ToTemplateArgs; | ||||||||||
1459 | if (Error Err = ImportTemplateArguments( | ||||||||||
1460 | T->getArgs(), T->getNumArgs(), ToTemplateArgs)) | ||||||||||
1461 | return std::move(Err); | ||||||||||
1462 | |||||||||||
1463 | QualType ToCanonType; | ||||||||||
1464 | if (!QualType(T, 0).isCanonical()) { | ||||||||||
1465 | QualType FromCanonType | ||||||||||
1466 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); | ||||||||||
1467 | if (ExpectedType TyOrErr = import(FromCanonType)) | ||||||||||
1468 | ToCanonType = *TyOrErr; | ||||||||||
1469 | else | ||||||||||
1470 | return TyOrErr.takeError(); | ||||||||||
1471 | } | ||||||||||
1472 | return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr, | ||||||||||
1473 | ToTemplateArgs, | ||||||||||
1474 | ToCanonType); | ||||||||||
1475 | } | ||||||||||
1476 | |||||||||||
1477 | ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { | ||||||||||
1478 | // Note: the qualifier in an ElaboratedType is optional. | ||||||||||
1479 | auto ToQualifierOrErr = import(T->getQualifier()); | ||||||||||
1480 | if (!ToQualifierOrErr) | ||||||||||
1481 | return ToQualifierOrErr.takeError(); | ||||||||||
1482 | |||||||||||
1483 | ExpectedType ToNamedTypeOrErr = import(T->getNamedType()); | ||||||||||
1484 | if (!ToNamedTypeOrErr) | ||||||||||
1485 | return ToNamedTypeOrErr.takeError(); | ||||||||||
1486 | |||||||||||
1487 | Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl()); | ||||||||||
1488 | if (!ToOwnedTagDeclOrErr) | ||||||||||
1489 | return ToOwnedTagDeclOrErr.takeError(); | ||||||||||
1490 | |||||||||||
1491 | return Importer.getToContext().getElaboratedType(T->getKeyword(), | ||||||||||
1492 | *ToQualifierOrErr, | ||||||||||
1493 | *ToNamedTypeOrErr, | ||||||||||
1494 | *ToOwnedTagDeclOrErr); | ||||||||||
1495 | } | ||||||||||
1496 | |||||||||||
1497 | ExpectedType | ||||||||||
1498 | ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { | ||||||||||
1499 | ExpectedType ToPatternOrErr = import(T->getPattern()); | ||||||||||
1500 | if (!ToPatternOrErr) | ||||||||||
1501 | return ToPatternOrErr.takeError(); | ||||||||||
1502 | |||||||||||
1503 | return Importer.getToContext().getPackExpansionType(*ToPatternOrErr, | ||||||||||
1504 | T->getNumExpansions(), | ||||||||||
1505 | /*ExpactPack=*/false); | ||||||||||
1506 | } | ||||||||||
1507 | |||||||||||
1508 | ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType( | ||||||||||
1509 | const DependentTemplateSpecializationType *T) { | ||||||||||
1510 | auto ToQualifierOrErr = import(T->getQualifier()); | ||||||||||
1511 | if (!ToQualifierOrErr) | ||||||||||
1512 | return ToQualifierOrErr.takeError(); | ||||||||||
1513 | |||||||||||
1514 | IdentifierInfo *ToName = Importer.Import(T->getIdentifier()); | ||||||||||
1515 | |||||||||||
1516 | SmallVector<TemplateArgument, 2> ToPack; | ||||||||||
1517 | ToPack.reserve(T->getNumArgs()); | ||||||||||
1518 | if (Error Err = ImportTemplateArguments( | ||||||||||
1519 | T->getArgs(), T->getNumArgs(), ToPack)) | ||||||||||
1520 | return std::move(Err); | ||||||||||
1521 | |||||||||||
1522 | return Importer.getToContext().getDependentTemplateSpecializationType( | ||||||||||
1523 | T->getKeyword(), *ToQualifierOrErr, ToName, ToPack); | ||||||||||
1524 | } | ||||||||||
1525 | |||||||||||
1526 | ExpectedType | ||||||||||
1527 | ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { | ||||||||||
1528 | auto ToQualifierOrErr = import(T->getQualifier()); | ||||||||||
1529 | if (!ToQualifierOrErr) | ||||||||||
1530 | return ToQualifierOrErr.takeError(); | ||||||||||
1531 | |||||||||||
1532 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); | ||||||||||
1533 | |||||||||||
1534 | QualType Canon; | ||||||||||
1535 | if (T != T->getCanonicalTypeInternal().getTypePtr()) { | ||||||||||
1536 | if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal())) | ||||||||||
1537 | Canon = (*TyOrErr).getCanonicalType(); | ||||||||||
1538 | else | ||||||||||
1539 | return TyOrErr.takeError(); | ||||||||||
1540 | } | ||||||||||
1541 | |||||||||||
1542 | return Importer.getToContext().getDependentNameType(T->getKeyword(), | ||||||||||
1543 | *ToQualifierOrErr, | ||||||||||
1544 | Name, Canon); | ||||||||||
1545 | } | ||||||||||
1546 | |||||||||||
1547 | ExpectedType | ||||||||||
1548 | ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { | ||||||||||
1549 | Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl()); | ||||||||||
1550 | if (!ToDeclOrErr) | ||||||||||
1551 | return ToDeclOrErr.takeError(); | ||||||||||
1552 | |||||||||||
1553 | return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr); | ||||||||||
1554 | } | ||||||||||
1555 | |||||||||||
1556 | ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { | ||||||||||
1557 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); | ||||||||||
1558 | if (!ToBaseTypeOrErr) | ||||||||||
1559 | return ToBaseTypeOrErr.takeError(); | ||||||||||
1560 | |||||||||||
1561 | SmallVector<QualType, 4> TypeArgs; | ||||||||||
1562 | for (auto TypeArg : T->getTypeArgsAsWritten()) { | ||||||||||
1563 | if (ExpectedType TyOrErr = import(TypeArg)) | ||||||||||
1564 | TypeArgs.push_back(*TyOrErr); | ||||||||||
1565 | else | ||||||||||
1566 | return TyOrErr.takeError(); | ||||||||||
1567 | } | ||||||||||
1568 | |||||||||||
1569 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | ||||||||||
1570 | for (auto *P : T->quals()) { | ||||||||||
1571 | if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P)) | ||||||||||
1572 | Protocols.push_back(*ProtocolOrErr); | ||||||||||
1573 | else | ||||||||||
1574 | return ProtocolOrErr.takeError(); | ||||||||||
1575 | |||||||||||
1576 | } | ||||||||||
1577 | |||||||||||
1578 | return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs, | ||||||||||
1579 | Protocols, | ||||||||||
1580 | T->isKindOfTypeAsWritten()); | ||||||||||
1581 | } | ||||||||||
1582 | |||||||||||
1583 | ExpectedType | ||||||||||
1584 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { | ||||||||||
1585 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | ||||||||||
1586 | if (!ToPointeeTypeOrErr) | ||||||||||
1587 | return ToPointeeTypeOrErr.takeError(); | ||||||||||
1588 | |||||||||||
1589 | return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr); | ||||||||||
1590 | } | ||||||||||
1591 | |||||||||||
1592 | //---------------------------------------------------------------------------- | ||||||||||
1593 | // Import Declarations | ||||||||||
1594 | //---------------------------------------------------------------------------- | ||||||||||
1595 | Error ASTNodeImporter::ImportDeclParts( | ||||||||||
1596 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, | ||||||||||
1597 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) { | ||||||||||
1598 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. | ||||||||||
1599 | // example: int struct_in_proto(struct data_t{int a;int b;} *d); | ||||||||||
1600 | // FIXME: We could support these constructs by importing a different type of | ||||||||||
1601 | // this parameter and by importing the original type of the parameter only | ||||||||||
1602 | // after the FunctionDecl is created. See | ||||||||||
1603 | // VisitFunctionDecl::UsedDifferentProtoType. | ||||||||||
1604 | DeclContext *OrigDC = D->getDeclContext(); | ||||||||||
1605 | FunctionDecl *FunDecl; | ||||||||||
1606 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && | ||||||||||
1607 | FunDecl->hasBody()) { | ||||||||||
1608 | auto getLeafPointeeType = [](const Type *T) { | ||||||||||
1609 | while (T->isPointerType() || T->isArrayType()) { | ||||||||||
1610 | T = T->getPointeeOrArrayElementType(); | ||||||||||
1611 | } | ||||||||||
1612 | return T; | ||||||||||
1613 | }; | ||||||||||
1614 | for (const ParmVarDecl *P : FunDecl->parameters()) { | ||||||||||
1615 | const Type *LeafT = | ||||||||||
1616 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); | ||||||||||
1617 | auto *RT = dyn_cast<RecordType>(LeafT); | ||||||||||
1618 | if (RT && RT->getDecl() == D) { | ||||||||||
1619 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | ||||||||||
1620 | << D->getDeclKindName(); | ||||||||||
1621 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | ||||||||||
1622 | } | ||||||||||
1623 | } | ||||||||||
1624 | } | ||||||||||
1625 | |||||||||||
1626 | // Import the context of this declaration. | ||||||||||
1627 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | ||||||||||
1628 | return Err; | ||||||||||
1629 | |||||||||||
1630 | // Import the name of this declaration. | ||||||||||
1631 | if (Error Err = importInto(Name, D->getDeclName())) | ||||||||||
1632 | return Err; | ||||||||||
1633 | |||||||||||
1634 | // Import the location of this declaration. | ||||||||||
1635 | if (Error Err = importInto(Loc, D->getLocation())) | ||||||||||
1636 | return Err; | ||||||||||
1637 | |||||||||||
1638 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); | ||||||||||
1639 | if (ToD
| ||||||||||
1640 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD)) | ||||||||||
1641 | return Err; | ||||||||||
1642 | |||||||||||
1643 | return Error::success(); | ||||||||||
1644 | } | ||||||||||
1645 | |||||||||||
1646 | Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { | ||||||||||
1647 | if (!FromD) | ||||||||||
1648 | return Error::success(); | ||||||||||
1649 | |||||||||||
1650 | if (!ToD) | ||||||||||
1651 | if (Error Err = importInto(ToD, FromD)) | ||||||||||
1652 | return Err; | ||||||||||
1653 | |||||||||||
1654 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { | ||||||||||
1655 | if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) { | ||||||||||
1656 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && | ||||||||||
1657 | !ToRecord->getDefinition()) { | ||||||||||
1658 | if (Error Err = ImportDefinition(FromRecord, ToRecord)) | ||||||||||
1659 | return Err; | ||||||||||
1660 | } | ||||||||||
1661 | } | ||||||||||
1662 | return Error::success(); | ||||||||||
1663 | } | ||||||||||
1664 | |||||||||||
1665 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { | ||||||||||
1666 | if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) { | ||||||||||
1667 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { | ||||||||||
1668 | if (Error Err = ImportDefinition(FromEnum, ToEnum)) | ||||||||||
1669 | return Err; | ||||||||||
1670 | } | ||||||||||
1671 | } | ||||||||||
1672 | return Error::success(); | ||||||||||
1673 | } | ||||||||||
1674 | |||||||||||
1675 | return Error::success(); | ||||||||||
1676 | } | ||||||||||
1677 | |||||||||||
1678 | Error | ||||||||||
1679 | ASTNodeImporter::ImportDeclarationNameLoc( | ||||||||||
1680 | const DeclarationNameInfo &From, DeclarationNameInfo& To) { | ||||||||||
1681 | // NOTE: To.Name and To.Loc are already imported. | ||||||||||
1682 | // We only have to import To.LocInfo. | ||||||||||
1683 | switch (To.getName().getNameKind()) { | ||||||||||
1684 | case DeclarationName::Identifier: | ||||||||||
1685 | case DeclarationName::ObjCZeroArgSelector: | ||||||||||
1686 | case DeclarationName::ObjCOneArgSelector: | ||||||||||
1687 | case DeclarationName::ObjCMultiArgSelector: | ||||||||||
1688 | case DeclarationName::CXXUsingDirective: | ||||||||||
1689 | case DeclarationName::CXXDeductionGuideName: | ||||||||||
1690 | return Error::success(); | ||||||||||
1691 | |||||||||||
1692 | case DeclarationName::CXXOperatorName: { | ||||||||||
1693 | if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange())) | ||||||||||
1694 | To.setCXXOperatorNameRange(*ToRangeOrErr); | ||||||||||
1695 | else | ||||||||||
1696 | return ToRangeOrErr.takeError(); | ||||||||||
1697 | return Error::success(); | ||||||||||
1698 | } | ||||||||||
1699 | case DeclarationName::CXXLiteralOperatorName: { | ||||||||||
1700 | if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc())) | ||||||||||
1701 | To.setCXXLiteralOperatorNameLoc(*LocOrErr); | ||||||||||
1702 | else | ||||||||||
1703 | return LocOrErr.takeError(); | ||||||||||
1704 | return Error::success(); | ||||||||||
1705 | } | ||||||||||
1706 | case DeclarationName::CXXConstructorName: | ||||||||||
1707 | case DeclarationName::CXXDestructorName: | ||||||||||
1708 | case DeclarationName::CXXConversionFunctionName: { | ||||||||||
1709 | if (auto ToTInfoOrErr = import(From.getNamedTypeInfo())) | ||||||||||
1710 | To.setNamedTypeInfo(*ToTInfoOrErr); | ||||||||||
1711 | else | ||||||||||
1712 | return ToTInfoOrErr.takeError(); | ||||||||||
1713 | return Error::success(); | ||||||||||
1714 | } | ||||||||||
1715 | } | ||||||||||
1716 | llvm_unreachable("Unknown name kind.")::llvm::llvm_unreachable_internal("Unknown name kind.", "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 1716); | ||||||||||
1717 | } | ||||||||||
1718 | |||||||||||
1719 | Error | ||||||||||
1720 | ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { | ||||||||||
1721 | if (Importer.isMinimalImport() && !ForceImport) { | ||||||||||
1722 | auto ToDCOrErr = Importer.ImportContext(FromDC); | ||||||||||
1723 | return ToDCOrErr.takeError(); | ||||||||||
1724 | } | ||||||||||
1725 | |||||||||||
1726 | // We use strict error handling in case of records and enums, but not | ||||||||||
1727 | // with e.g. namespaces. | ||||||||||
1728 | // | ||||||||||
1729 | // FIXME Clients of the ASTImporter should be able to choose an | ||||||||||
1730 | // appropriate error handling strategy for their needs. For instance, | ||||||||||
1731 | // they may not want to mark an entire namespace as erroneous merely | ||||||||||
1732 | // because there is an ODR error with two typedefs. As another example, | ||||||||||
1733 | // the client may allow EnumConstantDecls with same names but with | ||||||||||
1734 | // different values in two distinct translation units. | ||||||||||
1735 | bool AccumulateChildErrors = isa<TagDecl>(FromDC); | ||||||||||
1736 | |||||||||||
1737 | Error ChildErrors = Error::success(); | ||||||||||
1738 | for (auto *From : FromDC->decls()) { | ||||||||||
1739 | ExpectedDecl ImportedOrErr = import(From); | ||||||||||
1740 | |||||||||||
1741 | // If we are in the process of ImportDefinition(...) for a RecordDecl we | ||||||||||
1742 | // want to make sure that we are also completing each FieldDecl. There | ||||||||||
1743 | // are currently cases where this does not happen and this is correctness | ||||||||||
1744 | // fix since operations such as code generation will expect this to be so. | ||||||||||
1745 | if (ImportedOrErr) { | ||||||||||
1746 | FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From); | ||||||||||
1747 | Decl *ImportedDecl = *ImportedOrErr; | ||||||||||
1748 | FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl); | ||||||||||
1749 | if (FieldFrom && FieldTo) { | ||||||||||
1750 | RecordDecl *FromRecordDecl = nullptr; | ||||||||||
1751 | RecordDecl *ToRecordDecl = nullptr; | ||||||||||
1752 | // If we have a field that is an ArrayType we need to check if the array | ||||||||||
1753 | // element is a RecordDecl and if so we need to import the defintion. | ||||||||||
1754 | if (FieldFrom->getType()->isArrayType()) { | ||||||||||
1755 | // getBaseElementTypeUnsafe(...) handles multi-dimensonal arrays for us. | ||||||||||
1756 | FromRecordDecl = FieldFrom->getType()->getBaseElementTypeUnsafe()->getAsRecordDecl(); | ||||||||||
1757 | ToRecordDecl = FieldTo->getType()->getBaseElementTypeUnsafe()->getAsRecordDecl(); | ||||||||||
1758 | } | ||||||||||
1759 | |||||||||||
1760 | if (!FromRecordDecl || !ToRecordDecl) { | ||||||||||
1761 | const RecordType *RecordFrom = | ||||||||||
1762 | FieldFrom->getType()->getAs<RecordType>(); | ||||||||||
1763 | const RecordType *RecordTo = FieldTo->getType()->getAs<RecordType>(); | ||||||||||
1764 | |||||||||||
1765 | if (RecordFrom && RecordTo) { | ||||||||||
1766 | FromRecordDecl = RecordFrom->getDecl(); | ||||||||||
1767 | ToRecordDecl = RecordTo->getDecl(); | ||||||||||
1768 | } | ||||||||||
1769 | } | ||||||||||
1770 | |||||||||||
1771 | if (FromRecordDecl && ToRecordDecl) { | ||||||||||
1772 | if (FromRecordDecl->isCompleteDefinition() && | ||||||||||
1773 | !ToRecordDecl->isCompleteDefinition()) { | ||||||||||
1774 | Error Err = ImportDefinition(FromRecordDecl, ToRecordDecl); | ||||||||||
1775 | |||||||||||
1776 | if (Err && AccumulateChildErrors) | ||||||||||
1777 | ChildErrors = joinErrors(std::move(ChildErrors), std::move(Err)); | ||||||||||
1778 | else | ||||||||||
1779 | consumeError(std::move(Err)); | ||||||||||
1780 | } | ||||||||||
1781 | } | ||||||||||
1782 | } | ||||||||||
1783 | } else { | ||||||||||
1784 | if (AccumulateChildErrors) | ||||||||||
1785 | ChildErrors = | ||||||||||
1786 | joinErrors(std::move(ChildErrors), ImportedOrErr.takeError()); | ||||||||||
1787 | else | ||||||||||
1788 | consumeError(ImportedOrErr.takeError()); | ||||||||||
1789 | } | ||||||||||
1790 | } | ||||||||||
1791 | |||||||||||
1792 | // We reorder declarations in RecordDecls because they may have another order | ||||||||||
1793 | // in the "to" context than they have in the "from" context. This may happen | ||||||||||
1794 | // e.g when we import a class like this: | ||||||||||
1795 | // struct declToImport { | ||||||||||
1796 | // int a = c + b; | ||||||||||
1797 | // int b = 1; | ||||||||||
1798 | // int c = 2; | ||||||||||
1799 | // }; | ||||||||||
1800 | // During the import of `a` we import first the dependencies in sequence, | ||||||||||
1801 | // thus the order would be `c`, `b`, `a`. We will get the normal order by | ||||||||||
1802 | // first removing the already imported members and then adding them in the | ||||||||||
1803 | // order as they apper in the "from" context. | ||||||||||
1804 | // | ||||||||||
1805 | // Keeping field order is vital because it determines structure layout. | ||||||||||
1806 | // | ||||||||||
1807 | // Here and below, we cannot call field_begin() method and its callers on | ||||||||||
1808 | // ToDC if it has an external storage. Calling field_begin() will | ||||||||||
1809 | // automatically load all the fields by calling | ||||||||||
1810 | // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would | ||||||||||
1811 | // call ASTImporter::Import(). This is because the ExternalASTSource | ||||||||||
1812 | // interface in LLDB is implemented by the means of the ASTImporter. However, | ||||||||||
1813 | // calling an import at this point would result in an uncontrolled import, we | ||||||||||
1814 | // must avoid that. | ||||||||||
1815 | const auto *FromRD = dyn_cast<RecordDecl>(FromDC); | ||||||||||
1816 | if (!FromRD) | ||||||||||
1817 | return ChildErrors; | ||||||||||
1818 | |||||||||||
1819 | auto ToDCOrErr = Importer.ImportContext(FromDC); | ||||||||||
1820 | if (!ToDCOrErr) { | ||||||||||
1821 | consumeError(std::move(ChildErrors)); | ||||||||||
1822 | return ToDCOrErr.takeError(); | ||||||||||
1823 | } | ||||||||||
1824 | |||||||||||
1825 | DeclContext *ToDC = *ToDCOrErr; | ||||||||||
1826 | // Remove all declarations, which may be in wrong order in the | ||||||||||
1827 | // lexical DeclContext and then add them in the proper order. | ||||||||||
1828 | for (auto *D : FromRD->decls()) { | ||||||||||
1829 | if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<FriendDecl>(D)) { | ||||||||||
1830 | assert(D && "DC contains a null decl")((D && "DC contains a null decl") ? static_cast<void > (0) : __assert_fail ("D && \"DC contains a null decl\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 1830, __PRETTY_FUNCTION__)); | ||||||||||
1831 | Decl *ToD = Importer.GetAlreadyImportedOrNull(D); | ||||||||||
1832 | // Remove only the decls which we successfully imported. | ||||||||||
1833 | if (ToD) { | ||||||||||
1834 | assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD))((ToDC == ToD->getLexicalDeclContext() && ToDC-> containsDecl(ToD)) ? static_cast<void> (0) : __assert_fail ("ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD)" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 1834, __PRETTY_FUNCTION__)); | ||||||||||
1835 | // Remove the decl from its wrong place in the linked list. | ||||||||||
1836 | ToDC->removeDecl(ToD); | ||||||||||
1837 | // Add the decl to the end of the linked list. | ||||||||||
1838 | // This time it will be at the proper place because the enclosing for | ||||||||||
1839 | // loop iterates in the original (good) order of the decls. | ||||||||||
1840 | ToDC->addDeclInternal(ToD); | ||||||||||
1841 | } | ||||||||||
1842 | } | ||||||||||
1843 | } | ||||||||||
1844 | |||||||||||
1845 | return ChildErrors; | ||||||||||
1846 | } | ||||||||||
1847 | |||||||||||
1848 | Error ASTNodeImporter::ImportDeclContext( | ||||||||||
1849 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { | ||||||||||
1850 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); | ||||||||||
1851 | if (!ToDCOrErr) | ||||||||||
1852 | return ToDCOrErr.takeError(); | ||||||||||
1853 | ToDC = *ToDCOrErr; | ||||||||||
1854 | |||||||||||
1855 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { | ||||||||||
1856 | auto ToLexicalDCOrErr = Importer.ImportContext( | ||||||||||
1857 | FromD->getLexicalDeclContext()); | ||||||||||
1858 | if (!ToLexicalDCOrErr) | ||||||||||
1859 | return ToLexicalDCOrErr.takeError(); | ||||||||||
1860 | ToLexicalDC = *ToLexicalDCOrErr; | ||||||||||
1861 | } else | ||||||||||
1862 | ToLexicalDC = ToDC; | ||||||||||
1863 | |||||||||||
1864 | return Error::success(); | ||||||||||
1865 | } | ||||||||||
1866 | |||||||||||
1867 | Error ASTNodeImporter::ImportImplicitMethods( | ||||||||||
1868 | const CXXRecordDecl *From, CXXRecordDecl *To) { | ||||||||||
1869 | assert(From->isCompleteDefinition() && To->getDefinition() == To &&((From->isCompleteDefinition() && To->getDefinition () == To && "Import implicit methods to or from non-definition" ) ? static_cast<void> (0) : __assert_fail ("From->isCompleteDefinition() && To->getDefinition() == To && \"Import implicit methods to or from non-definition\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 1870, __PRETTY_FUNCTION__)) | ||||||||||
1870 | "Import implicit methods to or from non-definition")((From->isCompleteDefinition() && To->getDefinition () == To && "Import implicit methods to or from non-definition" ) ? static_cast<void> (0) : __assert_fail ("From->isCompleteDefinition() && To->getDefinition() == To && \"Import implicit methods to or from non-definition\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 1870, __PRETTY_FUNCTION__)); | ||||||||||
1871 | |||||||||||
1872 | for (CXXMethodDecl *FromM : From->methods()) | ||||||||||
1873 | if (FromM->isImplicit()) { | ||||||||||
1874 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); | ||||||||||
1875 | if (!ToMOrErr) | ||||||||||
1876 | return ToMOrErr.takeError(); | ||||||||||
1877 | } | ||||||||||
1878 | |||||||||||
1879 | return Error::success(); | ||||||||||
1880 | } | ||||||||||
1881 | |||||||||||
1882 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, | ||||||||||
1883 | ASTImporter &Importer) { | ||||||||||
1884 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { | ||||||||||
1885 | if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef)) | ||||||||||
1886 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); | ||||||||||
1887 | else | ||||||||||
1888 | return ToTypedefOrErr.takeError(); | ||||||||||
1889 | } | ||||||||||
1890 | return Error::success(); | ||||||||||
1891 | } | ||||||||||
1892 | |||||||||||
1893 | Error ASTNodeImporter::ImportDefinition( | ||||||||||
1894 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { | ||||||||||
1895 | auto DefinitionCompleter = [To]() { | ||||||||||
1896 | // There are cases in LLDB when we first import a class without its | ||||||||||
1897 | // members. The class will have DefinitionData, but no members. Then, | ||||||||||
1898 | // importDefinition is called from LLDB, which tries to get the members, so | ||||||||||
1899 | // when we get here, the class already has the DefinitionData set, so we | ||||||||||
1900 | // must unset the CompleteDefinition here to be able to complete again the | ||||||||||
1901 | // definition. | ||||||||||
1902 | To->setCompleteDefinition(false); | ||||||||||
1903 | To->completeDefinition(); | ||||||||||
1904 | }; | ||||||||||
1905 | |||||||||||
1906 | if (To->getDefinition() || To->isBeingDefined()) { | ||||||||||
1907 | if (Kind == IDK_Everything || | ||||||||||
1908 | // In case of lambdas, the class already has a definition ptr set, but | ||||||||||
1909 | // the contained decls are not imported yet. Also, isBeingDefined was | ||||||||||
1910 | // set in CXXRecordDecl::CreateLambda. We must import the contained | ||||||||||
1911 | // decls here and finish the definition. | ||||||||||
1912 | (To->isLambda() && shouldForceImportDeclContext(Kind))) { | ||||||||||
1913 | if (To->isLambda()) { | ||||||||||
1914 | auto *FromCXXRD = cast<CXXRecordDecl>(From); | ||||||||||
1915 | SmallVector<LambdaCapture, 8> ToCaptures; | ||||||||||
1916 | ToCaptures.reserve(FromCXXRD->capture_size()); | ||||||||||
1917 | for (const auto &FromCapture : FromCXXRD->captures()) { | ||||||||||
1918 | if (auto ToCaptureOrErr = import(FromCapture)) | ||||||||||
1919 | ToCaptures.push_back(*ToCaptureOrErr); | ||||||||||
1920 | else | ||||||||||
1921 | return ToCaptureOrErr.takeError(); | ||||||||||
1922 | } | ||||||||||
1923 | cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(), | ||||||||||
1924 | ToCaptures); | ||||||||||
1925 | } | ||||||||||
1926 | |||||||||||
1927 | Error Result = ImportDeclContext(From, /*ForceImport=*/true); | ||||||||||
1928 | // Finish the definition of the lambda, set isBeingDefined to false. | ||||||||||
1929 | if (To->isLambda()) | ||||||||||
1930 | DefinitionCompleter(); | ||||||||||
1931 | return Result; | ||||||||||
1932 | } | ||||||||||
1933 | |||||||||||
1934 | return Error::success(); | ||||||||||
1935 | } | ||||||||||
1936 | |||||||||||
1937 | To->startDefinition(); | ||||||||||
1938 | // Complete the definition even if error is returned. | ||||||||||
1939 | // The RecordDecl may be already part of the AST so it is better to | ||||||||||
1940 | // have it in complete state even if something is wrong with it. | ||||||||||
1941 | auto DefinitionCompleterScopeExit = | ||||||||||
1942 | llvm::make_scope_exit(DefinitionCompleter); | ||||||||||
1943 | |||||||||||
1944 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) | ||||||||||
1945 | return Err; | ||||||||||
1946 | |||||||||||
1947 | // Add base classes. | ||||||||||
1948 | auto *ToCXX = dyn_cast<CXXRecordDecl>(To); | ||||||||||
1949 | auto *FromCXX = dyn_cast<CXXRecordDecl>(From); | ||||||||||
1950 | if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) { | ||||||||||
1951 | |||||||||||
1952 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); | ||||||||||
1953 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); | ||||||||||
1954 | |||||||||||
1955 | #define FIELD(Name, Width, Merge) \ | ||||||||||
1956 | ToData.Name = FromData.Name; | ||||||||||
1957 | #include "clang/AST/CXXRecordDeclDefinitionBits.def" | ||||||||||
1958 | |||||||||||
1959 | // Copy over the data stored in RecordDeclBits | ||||||||||
1960 | ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions()); | ||||||||||
1961 | |||||||||||
1962 | SmallVector<CXXBaseSpecifier *, 4> Bases; | ||||||||||
1963 | for (const auto &Base1 : FromCXX->bases()) { | ||||||||||
1964 | ExpectedType TyOrErr = import(Base1.getType()); | ||||||||||
1965 | if (!TyOrErr) | ||||||||||
1966 | return TyOrErr.takeError(); | ||||||||||
1967 | |||||||||||
1968 | SourceLocation EllipsisLoc; | ||||||||||
1969 | if (Base1.isPackExpansion()) { | ||||||||||
1970 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) | ||||||||||
1971 | EllipsisLoc = *LocOrErr; | ||||||||||
1972 | else | ||||||||||
1973 | return LocOrErr.takeError(); | ||||||||||
1974 | } | ||||||||||
1975 | |||||||||||
1976 | // Ensure that we have a definition for the base. | ||||||||||
1977 | if (Error Err = | ||||||||||
1978 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) | ||||||||||
1979 | return Err; | ||||||||||
1980 | |||||||||||
1981 | auto RangeOrErr = import(Base1.getSourceRange()); | ||||||||||
1982 | if (!RangeOrErr) | ||||||||||
1983 | return RangeOrErr.takeError(); | ||||||||||
1984 | |||||||||||
1985 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); | ||||||||||
1986 | if (!TSIOrErr) | ||||||||||
1987 | return TSIOrErr.takeError(); | ||||||||||
1988 | |||||||||||
1989 | Bases.push_back( | ||||||||||
1990 | new (Importer.getToContext()) CXXBaseSpecifier( | ||||||||||
1991 | *RangeOrErr, | ||||||||||
1992 | Base1.isVirtual(), | ||||||||||
1993 | Base1.isBaseOfClass(), | ||||||||||
1994 | Base1.getAccessSpecifierAsWritten(), | ||||||||||
1995 | *TSIOrErr, | ||||||||||
1996 | EllipsisLoc)); | ||||||||||
1997 | } | ||||||||||
1998 | if (!Bases.empty()) | ||||||||||
1999 | ToCXX->setBases(Bases.data(), Bases.size()); | ||||||||||
2000 | } | ||||||||||
2001 | |||||||||||
2002 | if (shouldForceImportDeclContext(Kind)) | ||||||||||
2003 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | ||||||||||
2004 | return Err; | ||||||||||
2005 | |||||||||||
2006 | return Error::success(); | ||||||||||
2007 | } | ||||||||||
2008 | |||||||||||
2009 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { | ||||||||||
2010 | if (To->getAnyInitializer()) | ||||||||||
2011 | return Error::success(); | ||||||||||
2012 | |||||||||||
2013 | Expr *FromInit = From->getInit(); | ||||||||||
2014 | if (!FromInit) | ||||||||||
2015 | return Error::success(); | ||||||||||
2016 | |||||||||||
2017 | ExpectedExpr ToInitOrErr = import(FromInit); | ||||||||||
2018 | if (!ToInitOrErr) | ||||||||||
2019 | return ToInitOrErr.takeError(); | ||||||||||
2020 | |||||||||||
2021 | To->setInit(*ToInitOrErr); | ||||||||||
2022 | if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) { | ||||||||||
2023 | EvaluatedStmt *ToEval = To->ensureEvaluatedStmt(); | ||||||||||
2024 | ToEval->HasConstantInitialization = FromEval->HasConstantInitialization; | ||||||||||
2025 | ToEval->HasConstantDestruction = FromEval->HasConstantDestruction; | ||||||||||
2026 | // FIXME: Also import the initializer value. | ||||||||||
2027 | } | ||||||||||
2028 | |||||||||||
2029 | // FIXME: Other bits to merge? | ||||||||||
2030 | return Error::success(); | ||||||||||
2031 | } | ||||||||||
2032 | |||||||||||
2033 | Error ASTNodeImporter::ImportDefinition( | ||||||||||
2034 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { | ||||||||||
2035 | if (To->getDefinition() || To->isBeingDefined()) { | ||||||||||
2036 | if (Kind == IDK_Everything) | ||||||||||
2037 | return ImportDeclContext(From, /*ForceImport=*/true); | ||||||||||
2038 | return Error::success(); | ||||||||||
2039 | } | ||||||||||
2040 | |||||||||||
2041 | To->startDefinition(); | ||||||||||
2042 | |||||||||||
2043 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) | ||||||||||
2044 | return Err; | ||||||||||
2045 | |||||||||||
2046 | ExpectedType ToTypeOrErr = | ||||||||||
2047 | import(Importer.getFromContext().getTypeDeclType(From)); | ||||||||||
2048 | if (!ToTypeOrErr) | ||||||||||
2049 | return ToTypeOrErr.takeError(); | ||||||||||
2050 | |||||||||||
2051 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); | ||||||||||
2052 | if (!ToPromotionTypeOrErr) | ||||||||||
2053 | return ToPromotionTypeOrErr.takeError(); | ||||||||||
2054 | |||||||||||
2055 | if (shouldForceImportDeclContext(Kind)) | ||||||||||
2056 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | ||||||||||
2057 | return Err; | ||||||||||
2058 | |||||||||||
2059 | // FIXME: we might need to merge the number of positive or negative bits | ||||||||||
2060 | // if the enumerator lists don't match. | ||||||||||
2061 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, | ||||||||||
2062 | From->getNumPositiveBits(), | ||||||||||
2063 | From->getNumNegativeBits()); | ||||||||||
2064 | return Error::success(); | ||||||||||
2065 | } | ||||||||||
2066 | |||||||||||
2067 | Error ASTNodeImporter::ImportTemplateArguments( | ||||||||||
2068 | const TemplateArgument *FromArgs, unsigned NumFromArgs, | ||||||||||
2069 | SmallVectorImpl<TemplateArgument> &ToArgs) { | ||||||||||
2070 | for (unsigned I = 0; I != NumFromArgs; ++I) { | ||||||||||
2071 | if (auto ToOrErr = import(FromArgs[I])) | ||||||||||
2072 | ToArgs.push_back(*ToOrErr); | ||||||||||
2073 | else | ||||||||||
2074 | return ToOrErr.takeError(); | ||||||||||
2075 | } | ||||||||||
2076 | |||||||||||
2077 | return Error::success(); | ||||||||||
2078 | } | ||||||||||
2079 | |||||||||||
2080 | // FIXME: Do not forget to remove this and use only 'import'. | ||||||||||
2081 | Expected<TemplateArgument> | ||||||||||
2082 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { | ||||||||||
2083 | return import(From); | ||||||||||
2084 | } | ||||||||||
2085 | |||||||||||
2086 | template <typename InContainerTy> | ||||||||||
2087 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( | ||||||||||
2088 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { | ||||||||||
2089 | for (const auto &FromLoc : Container) { | ||||||||||
2090 | if (auto ToLocOrErr = import(FromLoc)) | ||||||||||
2091 | ToTAInfo.addArgument(*ToLocOrErr); | ||||||||||
2092 | else | ||||||||||
2093 | return ToLocOrErr.takeError(); | ||||||||||
2094 | } | ||||||||||
2095 | return Error::success(); | ||||||||||
2096 | } | ||||||||||
2097 | |||||||||||
2098 | static StructuralEquivalenceKind | ||||||||||
2099 | getStructuralEquivalenceKind(const ASTImporter &Importer) { | ||||||||||
2100 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal | ||||||||||
2101 | : StructuralEquivalenceKind::Default; | ||||||||||
2102 | } | ||||||||||
2103 | |||||||||||
2104 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { | ||||||||||
2105 | StructuralEquivalenceContext Ctx( | ||||||||||
2106 | Importer.getFromContext(), Importer.getToContext(), | ||||||||||
2107 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | ||||||||||
2108 | false, Complain); | ||||||||||
2109 | return Ctx.IsEquivalent(From, To); | ||||||||||
2110 | } | ||||||||||
2111 | |||||||||||
2112 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, | ||||||||||
2113 | RecordDecl *ToRecord, bool Complain) { | ||||||||||
2114 | // Eliminate a potential failure point where we attempt to re-import | ||||||||||
2115 | // something we're trying to import while completing ToRecord. | ||||||||||
2116 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); | ||||||||||
2117 | if (ToOrigin) { | ||||||||||
2118 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); | ||||||||||
2119 | if (ToOriginRecord) | ||||||||||
2120 | ToRecord = ToOriginRecord; | ||||||||||
2121 | } | ||||||||||
2122 | |||||||||||
2123 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | ||||||||||
2124 | ToRecord->getASTContext(), | ||||||||||
2125 | Importer.getNonEquivalentDecls(), | ||||||||||
2126 | getStructuralEquivalenceKind(Importer), | ||||||||||
2127 | false, Complain); | ||||||||||
2128 | return Ctx.IsEquivalent(FromRecord, ToRecord); | ||||||||||
2129 | } | ||||||||||
2130 | |||||||||||
2131 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, | ||||||||||
2132 | bool Complain) { | ||||||||||
2133 | StructuralEquivalenceContext Ctx( | ||||||||||
2134 | Importer.getFromContext(), Importer.getToContext(), | ||||||||||
2135 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | ||||||||||
2136 | false, Complain); | ||||||||||
2137 | return Ctx.IsEquivalent(FromVar, ToVar); | ||||||||||
2138 | } | ||||||||||
2139 | |||||||||||
2140 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { | ||||||||||
2141 | // Eliminate a potential failure point where we attempt to re-import | ||||||||||
2142 | // something we're trying to import while completing ToEnum. | ||||||||||
2143 | if (Decl *ToOrigin = Importer.GetOriginalDecl(ToEnum)) | ||||||||||
2144 | if (auto *ToOriginEnum = dyn_cast<EnumDecl>(ToOrigin)) | ||||||||||
2145 | ToEnum = ToOriginEnum; | ||||||||||
2146 | |||||||||||
2147 | StructuralEquivalenceContext Ctx( | ||||||||||
2148 | Importer.getFromContext(), Importer.getToContext(), | ||||||||||
2149 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); | ||||||||||
2150 | return Ctx.IsEquivalent(FromEnum, ToEnum); | ||||||||||
2151 | } | ||||||||||
2152 | |||||||||||
2153 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, | ||||||||||
2154 | FunctionTemplateDecl *To) { | ||||||||||
2155 | StructuralEquivalenceContext Ctx( | ||||||||||
2156 | Importer.getFromContext(), Importer.getToContext(), | ||||||||||
2157 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | ||||||||||
2158 | false, false); | ||||||||||
2159 | return Ctx.IsEquivalent(From, To); | ||||||||||
2160 | } | ||||||||||
2161 | |||||||||||
2162 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { | ||||||||||
2163 | StructuralEquivalenceContext Ctx( | ||||||||||
2164 | Importer.getFromContext(), Importer.getToContext(), | ||||||||||
2165 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | ||||||||||
2166 | false, false); | ||||||||||
2167 | return Ctx.IsEquivalent(From, To); | ||||||||||
2168 | } | ||||||||||
2169 | |||||||||||
2170 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, | ||||||||||
2171 | EnumConstantDecl *ToEC) { | ||||||||||
2172 | const llvm::APSInt &FromVal = FromEC->getInitVal(); | ||||||||||
2173 | const llvm::APSInt &ToVal = ToEC->getInitVal(); | ||||||||||
2174 | |||||||||||
2175 | return FromVal.isSigned() == ToVal.isSigned() && | ||||||||||
2176 | FromVal.getBitWidth() == ToVal.getBitWidth() && | ||||||||||
2177 | FromVal == ToVal; | ||||||||||
2178 | } | ||||||||||
2179 | |||||||||||
2180 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, | ||||||||||
2181 | ClassTemplateDecl *To) { | ||||||||||
2182 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | ||||||||||
2183 | Importer.getToContext(), | ||||||||||
2184 | Importer.getNonEquivalentDecls(), | ||||||||||
2185 | getStructuralEquivalenceKind(Importer)); | ||||||||||
2186 | return Ctx.IsEquivalent(From, To); | ||||||||||
2187 | } | ||||||||||
2188 | |||||||||||
2189 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, | ||||||||||
2190 | VarTemplateDecl *To) { | ||||||||||
2191 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | ||||||||||
2192 | Importer.getToContext(), | ||||||||||
2193 | Importer.getNonEquivalentDecls(), | ||||||||||
2194 | getStructuralEquivalenceKind(Importer)); | ||||||||||
2195 | return Ctx.IsEquivalent(From, To); | ||||||||||
2196 | } | ||||||||||
2197 | |||||||||||
2198 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { | ||||||||||
2199 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | ||||||||||
2200 | << D->getDeclKindName(); | ||||||||||
2201 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | ||||||||||
2202 | } | ||||||||||
2203 | |||||||||||
2204 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { | ||||||||||
2205 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | ||||||||||
2206 | << D->getDeclKindName(); | ||||||||||
2207 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | ||||||||||
2208 | } | ||||||||||
2209 | |||||||||||
2210 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { | ||||||||||
2211 | // Import the context of this declaration. | ||||||||||
2212 | DeclContext *DC, *LexicalDC; | ||||||||||
2213 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | ||||||||||
2214 | return std::move(Err); | ||||||||||
2215 | |||||||||||
2216 | // Import the location of this declaration. | ||||||||||
2217 | ExpectedSLoc LocOrErr = import(D->getLocation()); | ||||||||||
2218 | if (!LocOrErr) | ||||||||||
2219 | return LocOrErr.takeError(); | ||||||||||
2220 | |||||||||||
2221 | EmptyDecl *ToD; | ||||||||||
2222 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) | ||||||||||
2223 | return ToD; | ||||||||||
2224 | |||||||||||
2225 | ToD->setLexicalDeclContext(LexicalDC); | ||||||||||
2226 | LexicalDC->addDeclInternal(ToD); | ||||||||||
2227 | return ToD; | ||||||||||
2228 | } | ||||||||||
2229 | |||||||||||
2230 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { | ||||||||||
2231 | TranslationUnitDecl *ToD = | ||||||||||
2232 | Importer.getToContext().getTranslationUnitDecl(); | ||||||||||
2233 | |||||||||||
2234 | Importer.MapImported(D, ToD); | ||||||||||
2235 | |||||||||||
2236 | return ToD; | ||||||||||
2237 | } | ||||||||||
2238 | |||||||||||
2239 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { | ||||||||||
2240 | ExpectedSLoc LocOrErr = import(D->getLocation()); | ||||||||||
2241 | if (!LocOrErr) | ||||||||||
2242 | return LocOrErr.takeError(); | ||||||||||
2243 | auto ColonLocOrErr = import(D->getColonLoc()); | ||||||||||
2244 | if (!ColonLocOrErr) | ||||||||||
2245 | return ColonLocOrErr.takeError(); | ||||||||||
2246 | |||||||||||
2247 | // Import the context of this declaration. | ||||||||||
2248 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); | ||||||||||
2249 | if (!DCOrErr) | ||||||||||
2250 | return DCOrErr.takeError(); | ||||||||||
2251 | DeclContext *DC = *DCOrErr; | ||||||||||
2252 | |||||||||||
2253 | AccessSpecDecl *ToD; | ||||||||||
2254 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), | ||||||||||
2255 | DC, *LocOrErr, *ColonLocOrErr)) | ||||||||||
2256 | return ToD; | ||||||||||
2257 | |||||||||||
2258 | // Lexical DeclContext and Semantic DeclContext | ||||||||||
2259 | // is always the same for the accessSpec. | ||||||||||
2260 | ToD->setLexicalDeclContext(DC); | ||||||||||
2261 | DC->addDeclInternal(ToD); | ||||||||||
2262 | |||||||||||
2263 | return ToD; | ||||||||||
2264 | } | ||||||||||
2265 | |||||||||||
2266 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { | ||||||||||
2267 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); | ||||||||||
2268 | if (!DCOrErr) | ||||||||||
2269 | return DCOrErr.takeError(); | ||||||||||
2270 | DeclContext *DC = *DCOrErr; | ||||||||||
2271 | DeclContext *LexicalDC = DC; | ||||||||||
2272 | |||||||||||
2273 | Error Err = Error::success(); | ||||||||||
2274 | auto ToLocation = importChecked(Err, D->getLocation()); | ||||||||||
2275 | auto ToRParenLoc = importChecked(Err, D->getRParenLoc()); | ||||||||||
2276 | auto ToAssertExpr = importChecked(Err, D->getAssertExpr()); | ||||||||||
2277 | auto ToMessage = importChecked(Err, D->getMessage()); | ||||||||||
2278 | if (Err) | ||||||||||
2279 | return std::move(Err); | ||||||||||
2280 | |||||||||||
2281 | StaticAssertDecl *ToD; | ||||||||||
2282 | if (GetImportedOrCreateDecl( | ||||||||||
2283 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, | ||||||||||
2284 | ToRParenLoc, D->isFailed())) | ||||||||||
2285 | return ToD; | ||||||||||
2286 | |||||||||||
2287 | ToD->setLexicalDeclContext(LexicalDC); | ||||||||||
2288 | LexicalDC->addDeclInternal(ToD); | ||||||||||
2289 | return ToD; | ||||||||||
2290 | } | ||||||||||
2291 | |||||||||||
2292 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { | ||||||||||
2293 | // Import the major distinguishing characteristics of this namespace. | ||||||||||
2294 | DeclContext *DC, *LexicalDC; | ||||||||||
2295 | DeclarationName Name; | ||||||||||
2296 | SourceLocation Loc; | ||||||||||
2297 | NamedDecl *ToD; | ||||||||||
2298 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
2299 | return std::move(Err); | ||||||||||
2300 | if (ToD) | ||||||||||
2301 | return ToD; | ||||||||||
2302 | |||||||||||
2303 | NamespaceDecl *MergeWithNamespace = nullptr; | ||||||||||
2304 | if (!Name) { | ||||||||||
2305 | // This is an anonymous namespace. Adopt an existing anonymous | ||||||||||
2306 | // namespace if we can. | ||||||||||
2307 | // FIXME: Not testable. | ||||||||||
2308 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) | ||||||||||
2309 | MergeWithNamespace = TU->getAnonymousNamespace(); | ||||||||||
2310 | else | ||||||||||
2311 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); | ||||||||||
2312 | } else { | ||||||||||
2313 | SmallVector<NamedDecl *, 4> ConflictingDecls; | ||||||||||
2314 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||||||
2315 | for (auto *FoundDecl : FoundDecls) { | ||||||||||
2316 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) | ||||||||||
2317 | continue; | ||||||||||
2318 | |||||||||||
2319 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { | ||||||||||
2320 | MergeWithNamespace = FoundNS; | ||||||||||
2321 | ConflictingDecls.clear(); | ||||||||||
2322 | break; | ||||||||||
2323 | } | ||||||||||
2324 | |||||||||||
2325 | ConflictingDecls.push_back(FoundDecl); | ||||||||||
2326 | } | ||||||||||
2327 | |||||||||||
2328 | if (!ConflictingDecls.empty()) { | ||||||||||
2329 | ExpectedName NameOrErr = Importer.HandleNameConflict( | ||||||||||
2330 | Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(), | ||||||||||
2331 | ConflictingDecls.size()); | ||||||||||
2332 | if (NameOrErr) | ||||||||||
2333 | Name = NameOrErr.get(); | ||||||||||
2334 | else | ||||||||||
2335 | return NameOrErr.takeError(); | ||||||||||
2336 | } | ||||||||||
2337 | } | ||||||||||
2338 | |||||||||||
2339 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | ||||||||||
2340 | if (!BeginLocOrErr) | ||||||||||
2341 | return BeginLocOrErr.takeError(); | ||||||||||
2342 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); | ||||||||||
2343 | if (!RBraceLocOrErr) | ||||||||||
2344 | return RBraceLocOrErr.takeError(); | ||||||||||
2345 | |||||||||||
2346 | // Create the "to" namespace, if needed. | ||||||||||
2347 | NamespaceDecl *ToNamespace = MergeWithNamespace; | ||||||||||
2348 | if (!ToNamespace) { | ||||||||||
2349 | if (GetImportedOrCreateDecl( | ||||||||||
2350 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), | ||||||||||
2351 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), | ||||||||||
2352 | /*PrevDecl=*/nullptr)) | ||||||||||
2353 | return ToNamespace; | ||||||||||
2354 | ToNamespace->setRBraceLoc(*RBraceLocOrErr); | ||||||||||
2355 | ToNamespace->setLexicalDeclContext(LexicalDC); | ||||||||||
2356 | LexicalDC->addDeclInternal(ToNamespace); | ||||||||||
2357 | |||||||||||
2358 | // If this is an anonymous namespace, register it as the anonymous | ||||||||||
2359 | // namespace within its context. | ||||||||||
2360 | if (!Name) { | ||||||||||
2361 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) | ||||||||||
2362 | TU->setAnonymousNamespace(ToNamespace); | ||||||||||
2363 | else | ||||||||||
2364 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); | ||||||||||
2365 | } | ||||||||||
2366 | } | ||||||||||
2367 | Importer.MapImported(D, ToNamespace); | ||||||||||
2368 | |||||||||||
2369 | if (Error Err = ImportDeclContext(D)) | ||||||||||
2370 | return std::move(Err); | ||||||||||
2371 | |||||||||||
2372 | return ToNamespace; | ||||||||||
2373 | } | ||||||||||
2374 | |||||||||||
2375 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { | ||||||||||
2376 | // Import the major distinguishing characteristics of this namespace. | ||||||||||
2377 | DeclContext *DC, *LexicalDC; | ||||||||||
2378 | DeclarationName Name; | ||||||||||
2379 | SourceLocation Loc; | ||||||||||
2380 | NamedDecl *LookupD; | ||||||||||
2381 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) | ||||||||||
2382 | return std::move(Err); | ||||||||||
2383 | if (LookupD) | ||||||||||
2384 | return LookupD; | ||||||||||
2385 | |||||||||||
2386 | // NOTE: No conflict resolution is done for namespace aliases now. | ||||||||||
2387 | |||||||||||
2388 | Error Err = Error::success(); | ||||||||||
2389 | auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc()); | ||||||||||
2390 | auto ToAliasLoc = importChecked(Err, D->getAliasLoc()); | ||||||||||
2391 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | ||||||||||
2392 | auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc()); | ||||||||||
2393 | auto ToNamespace = importChecked(Err, D->getNamespace()); | ||||||||||
2394 | if (Err) | ||||||||||
2395 | return std::move(Err); | ||||||||||
2396 | |||||||||||
2397 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); | ||||||||||
2398 | |||||||||||
2399 | NamespaceAliasDecl *ToD; | ||||||||||
2400 | if (GetImportedOrCreateDecl( | ||||||||||
2401 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, | ||||||||||
2402 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) | ||||||||||
2403 | return ToD; | ||||||||||
2404 | |||||||||||
2405 | ToD->setLexicalDeclContext(LexicalDC); | ||||||||||
2406 | LexicalDC->addDeclInternal(ToD); | ||||||||||
2407 | |||||||||||
2408 | return ToD; | ||||||||||
2409 | } | ||||||||||
2410 | |||||||||||
2411 | ExpectedDecl | ||||||||||
2412 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { | ||||||||||
2413 | // Import the major distinguishing characteristics of this typedef. | ||||||||||
2414 | DeclContext *DC, *LexicalDC; | ||||||||||
2415 | DeclarationName Name; | ||||||||||
2416 | SourceLocation Loc; | ||||||||||
2417 | NamedDecl *ToD; | ||||||||||
2418 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
2419 | return std::move(Err); | ||||||||||
2420 | if (ToD) | ||||||||||
2421 | return ToD; | ||||||||||
2422 | |||||||||||
2423 | // If this typedef is not in block scope, determine whether we've | ||||||||||
2424 | // seen a typedef with the same name (that we can merge with) or any | ||||||||||
2425 | // other entity by that name (which name lookup could conflict with). | ||||||||||
2426 | // Note: Repeated typedefs are not valid in C99: | ||||||||||
2427 | // 'typedef int T; typedef int T;' is invalid | ||||||||||
2428 | // We do not care about this now. | ||||||||||
2429 | if (!DC->isFunctionOrMethod()) { | ||||||||||
2430 | SmallVector<NamedDecl *, 4> ConflictingDecls; | ||||||||||
2431 | unsigned IDNS = Decl::IDNS_Ordinary; | ||||||||||
2432 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||||||
2433 | for (auto *FoundDecl : FoundDecls) { | ||||||||||
2434 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | ||||||||||
2435 | continue; | ||||||||||
2436 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { | ||||||||||
2437 | if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D)) | ||||||||||
2438 | continue; | ||||||||||
2439 | |||||||||||
2440 | QualType FromUT = D->getUnderlyingType(); | ||||||||||
2441 | QualType FoundUT = FoundTypedef->getUnderlyingType(); | ||||||||||
2442 | if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) { | ||||||||||
2443 | // If the "From" context has a complete underlying type but we | ||||||||||
2444 | // already have a complete underlying type then return with that. | ||||||||||
2445 | if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType()) | ||||||||||
2446 | return Importer.MapImported(D, FoundTypedef); | ||||||||||
2447 | // FIXME Handle redecl chain. When you do that make consistent changes | ||||||||||
2448 | // in ASTImporterLookupTable too. | ||||||||||
2449 | } else { | ||||||||||
2450 | ConflictingDecls.push_back(FoundDecl); | ||||||||||
2451 | } | ||||||||||
2452 | } | ||||||||||
2453 | } | ||||||||||
2454 | |||||||||||
2455 | if (!ConflictingDecls.empty()) { | ||||||||||
2456 | ExpectedName NameOrErr = Importer.HandleNameConflict( | ||||||||||
2457 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); | ||||||||||
2458 | if (NameOrErr) | ||||||||||
2459 | Name = NameOrErr.get(); | ||||||||||
2460 | else | ||||||||||
2461 | return NameOrErr.takeError(); | ||||||||||
2462 | } | ||||||||||
2463 | } | ||||||||||
2464 | |||||||||||
2465 | Error Err = Error::success(); | ||||||||||
2466 | auto ToUnderlyingType = importChecked(Err, D->getUnderlyingType()); | ||||||||||
2467 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); | ||||||||||
2468 | auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); | ||||||||||
2469 | if (Err) | ||||||||||
2470 | return std::move(Err); | ||||||||||
2471 | |||||||||||
2472 | // Create the new typedef node. | ||||||||||
2473 | // FIXME: ToUnderlyingType is not used. | ||||||||||
2474 | (void)ToUnderlyingType; | ||||||||||
2475 | TypedefNameDecl *ToTypedef; | ||||||||||
2476 | if (IsAlias) { | ||||||||||
2477 | if (GetImportedOrCreateDecl<TypeAliasDecl>( | ||||||||||
2478 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, | ||||||||||
2479 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) | ||||||||||
2480 | return ToTypedef; | ||||||||||
2481 | } else if (GetImportedOrCreateDecl<TypedefDecl>( | ||||||||||
2482 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, | ||||||||||
2483 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) | ||||||||||
2484 | return ToTypedef; | ||||||||||
2485 | |||||||||||
2486 | ToTypedef->setAccess(D->getAccess()); | ||||||||||
2487 | ToTypedef->setLexicalDeclContext(LexicalDC); | ||||||||||
2488 | |||||||||||
2489 | // Templated declarations should not appear in DeclContext. | ||||||||||
2490 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; | ||||||||||
2491 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) | ||||||||||
2492 | LexicalDC->addDeclInternal(ToTypedef); | ||||||||||
2493 | |||||||||||
2494 | return ToTypedef; | ||||||||||
2495 | } | ||||||||||
2496 | |||||||||||
2497 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { | ||||||||||
2498 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); | ||||||||||
2499 | } | ||||||||||
2500 | |||||||||||
2501 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { | ||||||||||
2502 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); | ||||||||||
2503 | } | ||||||||||
2504 | |||||||||||
2505 | ExpectedDecl | ||||||||||
2506 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { | ||||||||||
2507 | // Import the major distinguishing characteristics of this typedef. | ||||||||||
2508 | DeclContext *DC, *LexicalDC; | ||||||||||
2509 | DeclarationName Name; | ||||||||||
2510 | SourceLocation Loc; | ||||||||||
2511 | NamedDecl *FoundD; | ||||||||||
2512 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) | ||||||||||
2513 | return std::move(Err); | ||||||||||
2514 | if (FoundD) | ||||||||||
2515 | return FoundD; | ||||||||||
2516 | |||||||||||
2517 | // If this typedef is not in block scope, determine whether we've | ||||||||||
2518 | // seen a typedef with the same name (that we can merge with) or any | ||||||||||
2519 | // other entity by that name (which name lookup could conflict with). | ||||||||||
2520 | if (!DC->isFunctionOrMethod()) { | ||||||||||
2521 | SmallVector<NamedDecl *, 4> ConflictingDecls; | ||||||||||
2522 | unsigned IDNS = Decl::IDNS_Ordinary; | ||||||||||
2523 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||||||
2524 | for (auto *FoundDecl : FoundDecls) { | ||||||||||
2525 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | ||||||||||
2526 | continue; | ||||||||||
2527 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) | ||||||||||
2528 | return Importer.MapImported(D, FoundAlias); | ||||||||||
2529 | ConflictingDecls.push_back(FoundDecl); | ||||||||||
2530 | } | ||||||||||
2531 | |||||||||||
2532 | if (!ConflictingDecls.empty()) { | ||||||||||
2533 | ExpectedName NameOrErr = Importer.HandleNameConflict( | ||||||||||
2534 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); | ||||||||||
2535 | if (NameOrErr) | ||||||||||
2536 | Name = NameOrErr.get(); | ||||||||||
2537 | else | ||||||||||
2538 | return NameOrErr.takeError(); | ||||||||||
2539 | } | ||||||||||
2540 | } | ||||||||||
2541 | |||||||||||
2542 | Error Err = Error::success(); | ||||||||||
2543 | auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters()); | ||||||||||
2544 | auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl()); | ||||||||||
2545 | if (Err) | ||||||||||
2546 | return std::move(Err); | ||||||||||
2547 | |||||||||||
2548 | TypeAliasTemplateDecl *ToAlias; | ||||||||||
2549 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, | ||||||||||
2550 | Name, ToTemplateParameters, ToTemplatedDecl)) | ||||||||||
2551 | return ToAlias; | ||||||||||
2552 | |||||||||||
2553 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); | ||||||||||
2554 | |||||||||||
2555 | ToAlias->setAccess(D->getAccess()); | ||||||||||
2556 | ToAlias->setLexicalDeclContext(LexicalDC); | ||||||||||
2557 | LexicalDC->addDeclInternal(ToAlias); | ||||||||||
2558 | return ToAlias; | ||||||||||
2559 | } | ||||||||||
2560 | |||||||||||
2561 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { | ||||||||||
2562 | // Import the major distinguishing characteristics of this label. | ||||||||||
2563 | DeclContext *DC, *LexicalDC; | ||||||||||
2564 | DeclarationName Name; | ||||||||||
2565 | SourceLocation Loc; | ||||||||||
2566 | NamedDecl *ToD; | ||||||||||
2567 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
2568 | return std::move(Err); | ||||||||||
2569 | if (ToD) | ||||||||||
2570 | return ToD; | ||||||||||
2571 | |||||||||||
2572 | assert(LexicalDC->isFunctionOrMethod())((LexicalDC->isFunctionOrMethod()) ? static_cast<void> (0) : __assert_fail ("LexicalDC->isFunctionOrMethod()", "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 2572, __PRETTY_FUNCTION__)); | ||||||||||
2573 | |||||||||||
2574 | LabelDecl *ToLabel; | ||||||||||
2575 | if (D->isGnuLocal()) { | ||||||||||
2576 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | ||||||||||
2577 | if (!BeginLocOrErr) | ||||||||||
2578 | return BeginLocOrErr.takeError(); | ||||||||||
2579 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, | ||||||||||
2580 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) | ||||||||||
2581 | return ToLabel; | ||||||||||
2582 | |||||||||||
2583 | } else { | ||||||||||
2584 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, | ||||||||||
2585 | Name.getAsIdentifierInfo())) | ||||||||||
2586 | return ToLabel; | ||||||||||
2587 | |||||||||||
2588 | } | ||||||||||
2589 | |||||||||||
2590 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); | ||||||||||
2591 | if (!ToStmtOrErr) | ||||||||||
2592 | return ToStmtOrErr.takeError(); | ||||||||||
2593 | |||||||||||
2594 | ToLabel->setStmt(*ToStmtOrErr); | ||||||||||
2595 | ToLabel->setLexicalDeclContext(LexicalDC); | ||||||||||
2596 | LexicalDC->addDeclInternal(ToLabel); | ||||||||||
2597 | return ToLabel; | ||||||||||
2598 | } | ||||||||||
2599 | |||||||||||
2600 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { | ||||||||||
2601 | // Import the major distinguishing characteristics of this enum. | ||||||||||
2602 | DeclContext *DC, *LexicalDC; | ||||||||||
2603 | DeclarationName Name; | ||||||||||
2604 | SourceLocation Loc; | ||||||||||
2605 | NamedDecl *ToD; | ||||||||||
2606 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
2607 | return std::move(Err); | ||||||||||
2608 | if (ToD) | ||||||||||
2609 | return ToD; | ||||||||||
2610 | |||||||||||
2611 | // Figure out what enum name we're looking for. | ||||||||||
2612 | unsigned IDNS = Decl::IDNS_Tag; | ||||||||||
2613 | DeclarationName SearchName = Name; | ||||||||||
2614 | if (!SearchName && D->getTypedefNameForAnonDecl()) { | ||||||||||
2615 | if (Error Err = importInto( | ||||||||||
2616 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) | ||||||||||
2617 | return std::move(Err); | ||||||||||
2618 | IDNS = Decl::IDNS_Ordinary; | ||||||||||
2619 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) | ||||||||||
2620 | IDNS |= Decl::IDNS_Ordinary; | ||||||||||
2621 | |||||||||||
2622 | // We may already have an enum of the same name; try to find and match it. | ||||||||||
2623 | EnumDecl *PrevDecl = nullptr; | ||||||||||
2624 | if (!DC->isFunctionOrMethod() && SearchName) { | ||||||||||
2625 | SmallVector<NamedDecl *, 4> ConflictingDecls; | ||||||||||
2626 | auto FoundDecls = | ||||||||||
2627 | Importer.findDeclsInToCtx(DC, SearchName); | ||||||||||
2628 | for (auto *FoundDecl : FoundDecls) { | ||||||||||
2629 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | ||||||||||
2630 | continue; | ||||||||||
2631 | |||||||||||
2632 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { | ||||||||||
2633 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) | ||||||||||
2634 | FoundDecl = Tag->getDecl(); | ||||||||||
2635 | } | ||||||||||
2636 | |||||||||||
2637 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { | ||||||||||
2638 | if (!hasSameVisibilityContextAndLinkage(FoundEnum, D)) | ||||||||||
2639 | continue; | ||||||||||
2640 | if (IsStructuralMatch(D, FoundEnum)) { | ||||||||||
2641 | EnumDecl *FoundDef = FoundEnum->getDefinition(); | ||||||||||
2642 | if (D->isThisDeclarationADefinition() && FoundDef) | ||||||||||
2643 | return Importer.MapImported(D, FoundDef); | ||||||||||
2644 | PrevDecl = FoundEnum->getMostRecentDecl(); | ||||||||||
2645 | break; | ||||||||||
2646 | } | ||||||||||
2647 | ConflictingDecls.push_back(FoundDecl); | ||||||||||
2648 | } | ||||||||||
2649 | } | ||||||||||
2650 | |||||||||||
2651 | if (!ConflictingDecls.empty()) { | ||||||||||
2652 | ExpectedName NameOrErr = Importer.HandleNameConflict( | ||||||||||
2653 | SearchName, DC, IDNS, ConflictingDecls.data(), | ||||||||||
2654 | ConflictingDecls.size()); | ||||||||||
2655 | if (NameOrErr) | ||||||||||
2656 | Name = NameOrErr.get(); | ||||||||||
2657 | else | ||||||||||
2658 | return NameOrErr.takeError(); | ||||||||||
2659 | } | ||||||||||
2660 | } | ||||||||||
2661 | |||||||||||
2662 | Error Err = Error::success(); | ||||||||||
2663 | auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); | ||||||||||
2664 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | ||||||||||
2665 | auto ToIntegerType = importChecked(Err, D->getIntegerType()); | ||||||||||
2666 | auto ToBraceRange = importChecked(Err, D->getBraceRange()); | ||||||||||
2667 | if (Err) | ||||||||||
2668 | return std::move(Err); | ||||||||||
2669 | |||||||||||
2670 | // Create the enum declaration. | ||||||||||
2671 | EnumDecl *D2; | ||||||||||
2672 | if (GetImportedOrCreateDecl( | ||||||||||
2673 | D2, D, Importer.getToContext(), DC, ToBeginLoc, | ||||||||||
2674 | Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(), | ||||||||||
2675 | D->isScopedUsingClassTag(), D->isFixed())) | ||||||||||
2676 | return D2; | ||||||||||
2677 | |||||||||||
2678 | D2->setQualifierInfo(ToQualifierLoc); | ||||||||||
2679 | D2->setIntegerType(ToIntegerType); | ||||||||||
2680 | D2->setBraceRange(ToBraceRange); | ||||||||||
2681 | D2->setAccess(D->getAccess()); | ||||||||||
2682 | D2->setLexicalDeclContext(LexicalDC); | ||||||||||
2683 | LexicalDC->addDeclInternal(D2); | ||||||||||
2684 | |||||||||||
2685 | // Import the definition | ||||||||||
2686 | if (D->isCompleteDefinition()) | ||||||||||
2687 | if (Error Err = ImportDefinition(D, D2)) | ||||||||||
2688 | return std::move(Err); | ||||||||||
2689 | |||||||||||
2690 | return D2; | ||||||||||
2691 | } | ||||||||||
2692 | |||||||||||
2693 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { | ||||||||||
2694 | bool IsFriendTemplate = false; | ||||||||||
2695 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | ||||||||||
2696 | IsFriendTemplate = | ||||||||||
2697 | DCXX->getDescribedClassTemplate() && | ||||||||||
2698 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != | ||||||||||
2699 | Decl::FOK_None; | ||||||||||
2700 | } | ||||||||||
2701 | |||||||||||
2702 | // Import the major distinguishing characteristics of this record. | ||||||||||
2703 | DeclContext *DC = nullptr, *LexicalDC = nullptr; | ||||||||||
2704 | DeclarationName Name; | ||||||||||
2705 | SourceLocation Loc; | ||||||||||
2706 | NamedDecl *ToD = nullptr; | ||||||||||
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 structure 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 | Decl::IDNS_TagFriend; | ||||||||||
2722 | |||||||||||
2723 | // We may already have a record of the same name; try to find and match it. | ||||||||||
2724 | RecordDecl *PrevDecl = nullptr; | ||||||||||
2725 | if (!DC->isFunctionOrMethod() && !D->isLambda()) { | ||||||||||
2726 | SmallVector<NamedDecl *, 4> ConflictingDecls; | ||||||||||
2727 | auto FoundDecls = | ||||||||||
2728 | Importer.findDeclsInToCtx(DC, SearchName); | ||||||||||
2729 | if (!FoundDecls.empty()) { | ||||||||||
2730 | // We're going to have to compare D against potentially conflicting Decls, | ||||||||||
2731 | // so complete it. | ||||||||||
2732 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) | ||||||||||
2733 | D->getASTContext().getExternalSource()->CompleteType(D); | ||||||||||
2734 | } | ||||||||||
2735 | |||||||||||
2736 | for (auto *FoundDecl : FoundDecls) { | ||||||||||
2737 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | ||||||||||
2738 | continue; | ||||||||||
2739 | |||||||||||
2740 | Decl *Found = FoundDecl; | ||||||||||
2741 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { | ||||||||||
2742 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) | ||||||||||
2743 | Found = Tag->getDecl(); | ||||||||||
2744 | } | ||||||||||
2745 | |||||||||||
2746 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { | ||||||||||
2747 | // Do not emit false positive diagnostic in case of unnamed | ||||||||||
2748 | // struct/union and in case of anonymous structs. Would be false | ||||||||||
2749 | // because there may be several anonymous/unnamed structs in a class. | ||||||||||
2750 | // E.g. these are both valid: | ||||||||||
2751 | // struct A { // unnamed structs | ||||||||||
2752 | // struct { struct A *next; } entry0; | ||||||||||
2753 | // struct { struct A *next; } entry1; | ||||||||||
2754 | // }; | ||||||||||
2755 | // struct X { struct { int a; }; struct { int b; }; }; // anon structs | ||||||||||
2756 | if (!SearchName) | ||||||||||
2757 | if (!IsStructuralMatch(D, FoundRecord, false)) | ||||||||||
2758 | continue; | ||||||||||
2759 | |||||||||||
2760 | if (!hasSameVisibilityContextAndLinkage(FoundRecord, D)) | ||||||||||
2761 | continue; | ||||||||||
2762 | |||||||||||
2763 | if (IsStructuralMatch(D, FoundRecord)) { | ||||||||||
2764 | RecordDecl *FoundDef = FoundRecord->getDefinition(); | ||||||||||
2765 | if (D->isThisDeclarationADefinition() && FoundDef) { | ||||||||||
2766 | // FIXME: Structural equivalence check should check for same | ||||||||||
2767 | // user-defined methods. | ||||||||||
2768 | Importer.MapImported(D, FoundDef); | ||||||||||
2769 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | ||||||||||
2770 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); | ||||||||||
2771 | assert(FoundCXX && "Record type mismatch")((FoundCXX && "Record type mismatch") ? static_cast< void> (0) : __assert_fail ("FoundCXX && \"Record type mismatch\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 2771, __PRETTY_FUNCTION__)); | ||||||||||
2772 | |||||||||||
2773 | if (!Importer.isMinimalImport()) | ||||||||||
2774 | // FoundDef may not have every implicit method that D has | ||||||||||
2775 | // because implicit methods are created only if they are used. | ||||||||||
2776 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) | ||||||||||
2777 | return std::move(Err); | ||||||||||
2778 | } | ||||||||||
2779 | } | ||||||||||
2780 | PrevDecl = FoundRecord->getMostRecentDecl(); | ||||||||||
2781 | break; | ||||||||||
2782 | } | ||||||||||
2783 | ConflictingDecls.push_back(FoundDecl); | ||||||||||
2784 | } // kind is RecordDecl | ||||||||||
2785 | } // for | ||||||||||
2786 | |||||||||||
2787 | if (!ConflictingDecls.empty() && SearchName) { | ||||||||||
2788 | ExpectedName NameOrErr = Importer.HandleNameConflict( | ||||||||||
2789 | SearchName, DC, IDNS, ConflictingDecls.data(), | ||||||||||
2790 | ConflictingDecls.size()); | ||||||||||
2791 | if (NameOrErr) | ||||||||||
2792 | Name = NameOrErr.get(); | ||||||||||
2793 | else | ||||||||||
2794 | return NameOrErr.takeError(); | ||||||||||
2795 | } | ||||||||||
2796 | } | ||||||||||
2797 | |||||||||||
2798 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | ||||||||||
2799 | if (!BeginLocOrErr) | ||||||||||
2800 | return BeginLocOrErr.takeError(); | ||||||||||
2801 | |||||||||||
2802 | // Create the record declaration. | ||||||||||
2803 | RecordDecl *D2 = nullptr; | ||||||||||
2804 | CXXRecordDecl *D2CXX = nullptr; | ||||||||||
2805 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | ||||||||||
2806 | if (DCXX->isLambda()) { | ||||||||||
2807 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); | ||||||||||
2808 | if (!TInfoOrErr) | ||||||||||
2809 | return TInfoOrErr.takeError(); | ||||||||||
2810 | if (GetImportedOrCreateSpecialDecl( | ||||||||||
2811 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), | ||||||||||
2812 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), | ||||||||||
2813 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) | ||||||||||
2814 | return D2CXX; | ||||||||||
2815 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); | ||||||||||
2816 | if (!CDeclOrErr) | ||||||||||
2817 | return CDeclOrErr.takeError(); | ||||||||||
2818 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr, | ||||||||||
2819 | DCXX->hasKnownLambdaInternalLinkage()); | ||||||||||
2820 | } else if (DCXX->isInjectedClassName()) { | ||||||||||
2821 | // We have to be careful to do a similar dance to the one in | ||||||||||
2822 | // Sema::ActOnStartCXXMemberDeclarations | ||||||||||
2823 | const bool DelayTypeCreation = true; | ||||||||||
2824 | if (GetImportedOrCreateDecl( | ||||||||||
2825 | D2CXX, D, Importer.getToContext(), D->getTagKind(), DC, | ||||||||||
2826 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), | ||||||||||
2827 | cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation)) | ||||||||||
2828 | return D2CXX; | ||||||||||
2829 | Importer.getToContext().getTypeDeclType( | ||||||||||
2830 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); | ||||||||||
2831 | } else { | ||||||||||
2832 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), | ||||||||||
2833 | D->getTagKind(), DC, *BeginLocOrErr, Loc, | ||||||||||
2834 | Name.getAsIdentifierInfo(), | ||||||||||
2835 | cast_or_null<CXXRecordDecl>(PrevDecl))) | ||||||||||
2836 | return D2CXX; | ||||||||||
2837 | } | ||||||||||
2838 | |||||||||||
2839 | D2 = D2CXX; | ||||||||||
2840 | D2->setAccess(D->getAccess()); | ||||||||||
2841 | D2->setLexicalDeclContext(LexicalDC); | ||||||||||
2842 | addDeclToContexts(D, D2); | ||||||||||
2843 | |||||||||||
2844 | if (ClassTemplateDecl *FromDescribed = | ||||||||||
2845 | DCXX->getDescribedClassTemplate()) { | ||||||||||
2846 | ClassTemplateDecl *ToDescribed; | ||||||||||
2847 | if (Error Err = importInto(ToDescribed, FromDescribed)) | ||||||||||
2848 | return std::move(Err); | ||||||||||
2849 | D2CXX->setDescribedClassTemplate(ToDescribed); | ||||||||||
2850 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { | ||||||||||
2851 | // In a record describing a template the type should be an | ||||||||||
2852 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the | ||||||||||
2853 | // previously set type to the correct value here (ToDescribed is not | ||||||||||
2854 | // available at record create). | ||||||||||
2855 | // FIXME: The previous type is cleared but not removed from | ||||||||||
2856 | // ASTContext's internal storage. | ||||||||||
2857 | CXXRecordDecl *Injected = nullptr; | ||||||||||
2858 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { | ||||||||||
2859 | auto *Record = dyn_cast<CXXRecordDecl>(Found); | ||||||||||
2860 | if (Record && Record->isInjectedClassName()) { | ||||||||||
2861 | Injected = Record; | ||||||||||
2862 | break; | ||||||||||
2863 | } | ||||||||||
2864 | } | ||||||||||
2865 | // Create an injected type for the whole redecl chain. | ||||||||||
2866 | SmallVector<Decl *, 2> Redecls = | ||||||||||
2867 | getCanonicalForwardRedeclChain(D2CXX); | ||||||||||
2868 | for (auto *R : Redecls) { | ||||||||||
2869 | auto *RI = cast<CXXRecordDecl>(R); | ||||||||||
2870 | RI->setTypeForDecl(nullptr); | ||||||||||
2871 | // Below we create a new injected type and assign that to the | ||||||||||
2872 | // canonical decl, subsequent declarations in the chain will reuse | ||||||||||
2873 | // that type. | ||||||||||
2874 | Importer.getToContext().getInjectedClassNameType( | ||||||||||
2875 | RI, ToDescribed->getInjectedClassNameSpecialization()); | ||||||||||
2876 | } | ||||||||||
2877 | // Set the new type for the previous injected decl too. | ||||||||||
2878 | if (Injected) { | ||||||||||
2879 | Injected->setTypeForDecl(nullptr); | ||||||||||
2880 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); | ||||||||||
2881 | } | ||||||||||
2882 | } | ||||||||||
2883 | } else if (MemberSpecializationInfo *MemberInfo = | ||||||||||
2884 | DCXX->getMemberSpecializationInfo()) { | ||||||||||
2885 | TemplateSpecializationKind SK = | ||||||||||
2886 | MemberInfo->getTemplateSpecializationKind(); | ||||||||||
2887 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); | ||||||||||
2888 | |||||||||||
2889 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) | ||||||||||
2890 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); | ||||||||||
2891 | else | ||||||||||
2892 | return ToInstOrErr.takeError(); | ||||||||||
2893 | |||||||||||
2894 | if (ExpectedSLoc POIOrErr = | ||||||||||
2895 | import(MemberInfo->getPointOfInstantiation())) | ||||||||||
2896 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( | ||||||||||
2897 | *POIOrErr); | ||||||||||
2898 | else | ||||||||||
2899 | return POIOrErr.takeError(); | ||||||||||
2900 | } | ||||||||||
2901 | |||||||||||
2902 | } else { | ||||||||||
2903 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), | ||||||||||
2904 | D->getTagKind(), DC, *BeginLocOrErr, Loc, | ||||||||||
2905 | Name.getAsIdentifierInfo(), PrevDecl)) | ||||||||||
2906 | return D2; | ||||||||||
2907 | D2->setLexicalDeclContext(LexicalDC); | ||||||||||
2908 | addDeclToContexts(D, D2); | ||||||||||
2909 | } | ||||||||||
2910 | |||||||||||
2911 | if (auto BraceRangeOrErr = import(D->getBraceRange())) | ||||||||||
2912 | D2->setBraceRange(*BraceRangeOrErr); | ||||||||||
2913 | else | ||||||||||
2914 | return BraceRangeOrErr.takeError(); | ||||||||||
2915 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) | ||||||||||
2916 | D2->setQualifierInfo(*QualifierLocOrErr); | ||||||||||
2917 | else | ||||||||||
2918 | return QualifierLocOrErr.takeError(); | ||||||||||
2919 | |||||||||||
2920 | if (D->isAnonymousStructOrUnion()) | ||||||||||
2921 | D2->setAnonymousStructOrUnion(true); | ||||||||||
2922 | |||||||||||
2923 | if (D->isCompleteDefinition()) | ||||||||||
2924 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) | ||||||||||
2925 | return std::move(Err); | ||||||||||
2926 | |||||||||||
2927 | return D2; | ||||||||||
2928 | } | ||||||||||
2929 | |||||||||||
2930 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { | ||||||||||
2931 | // Import the major distinguishing characteristics of this enumerator. | ||||||||||
2932 | DeclContext *DC, *LexicalDC; | ||||||||||
2933 | DeclarationName Name; | ||||||||||
2934 | SourceLocation Loc; | ||||||||||
2935 | NamedDecl *ToD; | ||||||||||
2936 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
2937 | return std::move(Err); | ||||||||||
2938 | if (ToD) | ||||||||||
2939 | return ToD; | ||||||||||
2940 | |||||||||||
2941 | // Determine whether there are any other declarations with the same name and | ||||||||||
2942 | // in the same context. | ||||||||||
2943 | if (!LexicalDC->isFunctionOrMethod()) { | ||||||||||
2944 | SmallVector<NamedDecl *, 4> ConflictingDecls; | ||||||||||
2945 | unsigned IDNS = Decl::IDNS_Ordinary; | ||||||||||
2946 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||||||
2947 | for (auto *FoundDecl : FoundDecls) { | ||||||||||
2948 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | ||||||||||
2949 | continue; | ||||||||||
2950 | |||||||||||
2951 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { | ||||||||||
2952 | if (IsStructuralMatch(D, FoundEnumConstant)) | ||||||||||
2953 | return Importer.MapImported(D, FoundEnumConstant); | ||||||||||
2954 | ConflictingDecls.push_back(FoundDecl); | ||||||||||
2955 | } | ||||||||||
2956 | } | ||||||||||
2957 | |||||||||||
2958 | if (!ConflictingDecls.empty()) { | ||||||||||
2959 | ExpectedName NameOrErr = Importer.HandleNameConflict( | ||||||||||
2960 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); | ||||||||||
2961 | if (NameOrErr) | ||||||||||
2962 | Name = NameOrErr.get(); | ||||||||||
2963 | else | ||||||||||
2964 | return NameOrErr.takeError(); | ||||||||||
2965 | } | ||||||||||
2966 | } | ||||||||||
2967 | |||||||||||
2968 | ExpectedType TypeOrErr = import(D->getType()); | ||||||||||
2969 | if (!TypeOrErr) | ||||||||||
2970 | return TypeOrErr.takeError(); | ||||||||||
2971 | |||||||||||
2972 | ExpectedExpr InitOrErr = import(D->getInitExpr()); | ||||||||||
2973 | if (!InitOrErr) | ||||||||||
2974 | return InitOrErr.takeError(); | ||||||||||
2975 | |||||||||||
2976 | EnumConstantDecl *ToEnumerator; | ||||||||||
2977 | if (GetImportedOrCreateDecl( | ||||||||||
2978 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, | ||||||||||
2979 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) | ||||||||||
2980 | return ToEnumerator; | ||||||||||
2981 | |||||||||||
2982 | ToEnumerator->setAccess(D->getAccess()); | ||||||||||
2983 | ToEnumerator->setLexicalDeclContext(LexicalDC); | ||||||||||
2984 | LexicalDC->addDeclInternal(ToEnumerator); | ||||||||||
2985 | return ToEnumerator; | ||||||||||
2986 | } | ||||||||||
2987 | |||||||||||
2988 | Error ASTNodeImporter::ImportTemplateParameterLists(const DeclaratorDecl *FromD, | ||||||||||
2989 | DeclaratorDecl *ToD) { | ||||||||||
2990 | unsigned int Num = FromD->getNumTemplateParameterLists(); | ||||||||||
2991 | if (Num == 0) | ||||||||||
2992 | return Error::success(); | ||||||||||
2993 | SmallVector<TemplateParameterList *, 2> ToTPLists(Num); | ||||||||||
2994 | for (unsigned int I = 0; I < Num; ++I) | ||||||||||
2995 | if (Expected<TemplateParameterList *> ToTPListOrErr = | ||||||||||
2996 | import(FromD->getTemplateParameterList(I))) | ||||||||||
2997 | ToTPLists[I] = *ToTPListOrErr; | ||||||||||
2998 | else | ||||||||||
2999 | return ToTPListOrErr.takeError(); | ||||||||||
3000 | ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists); | ||||||||||
3001 | return Error::success(); | ||||||||||
3002 | } | ||||||||||
3003 | |||||||||||
3004 | Error ASTNodeImporter::ImportTemplateInformation( | ||||||||||
3005 | FunctionDecl *FromFD, FunctionDecl *ToFD) { | ||||||||||
3006 | switch (FromFD->getTemplatedKind()) { | ||||||||||
3007 | case FunctionDecl::TK_NonTemplate: | ||||||||||
3008 | case FunctionDecl::TK_FunctionTemplate: | ||||||||||
3009 | return Error::success(); | ||||||||||
3010 | |||||||||||
3011 | case FunctionDecl::TK_MemberSpecialization: { | ||||||||||
3012 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); | ||||||||||
3013 | |||||||||||
3014 | if (Expected<FunctionDecl *> InstFDOrErr = | ||||||||||
3015 | import(FromFD->getInstantiatedFromMemberFunction())) | ||||||||||
3016 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); | ||||||||||
3017 | else | ||||||||||
3018 | return InstFDOrErr.takeError(); | ||||||||||
3019 | |||||||||||
3020 | if (ExpectedSLoc POIOrErr = import( | ||||||||||
3021 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) | ||||||||||
3022 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); | ||||||||||
3023 | else | ||||||||||
3024 | return POIOrErr.takeError(); | ||||||||||
3025 | |||||||||||
3026 | return Error::success(); | ||||||||||
3027 | } | ||||||||||
3028 | |||||||||||
3029 | case FunctionDecl::TK_FunctionTemplateSpecialization: { | ||||||||||
3030 | auto FunctionAndArgsOrErr = | ||||||||||
3031 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); | ||||||||||
3032 | if (!FunctionAndArgsOrErr) | ||||||||||
3033 | return FunctionAndArgsOrErr.takeError(); | ||||||||||
3034 | |||||||||||
3035 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( | ||||||||||
3036 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); | ||||||||||
3037 | |||||||||||
3038 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); | ||||||||||
3039 | TemplateArgumentListInfo ToTAInfo; | ||||||||||
3040 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; | ||||||||||
3041 | if (FromTAArgsAsWritten) | ||||||||||
3042 | if (Error Err = ImportTemplateArgumentListInfo( | ||||||||||
3043 | *FromTAArgsAsWritten, ToTAInfo)) | ||||||||||
3044 | return Err; | ||||||||||
3045 | |||||||||||
3046 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); | ||||||||||
3047 | if (!POIOrErr) | ||||||||||
3048 | return POIOrErr.takeError(); | ||||||||||
3049 | |||||||||||
3050 | if (Error Err = ImportTemplateParameterLists(FromFD, ToFD)) | ||||||||||
3051 | return Err; | ||||||||||
3052 | |||||||||||
3053 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); | ||||||||||
3054 | ToFD->setFunctionTemplateSpecialization( | ||||||||||
3055 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, | ||||||||||
3056 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); | ||||||||||
3057 | return Error::success(); | ||||||||||
3058 | } | ||||||||||
3059 | |||||||||||
3060 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { | ||||||||||
3061 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); | ||||||||||
3062 | UnresolvedSet<8> TemplDecls; | ||||||||||
3063 | unsigned NumTemplates = FromInfo->getNumTemplates(); | ||||||||||
3064 | for (unsigned I = 0; I < NumTemplates; I++) { | ||||||||||
3065 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = | ||||||||||
3066 | import(FromInfo->getTemplate(I))) | ||||||||||
3067 | TemplDecls.addDecl(*ToFTDOrErr); | ||||||||||
3068 | else | ||||||||||
3069 | return ToFTDOrErr.takeError(); | ||||||||||
3070 | } | ||||||||||
3071 | |||||||||||
3072 | // Import TemplateArgumentListInfo. | ||||||||||
3073 | TemplateArgumentListInfo ToTAInfo; | ||||||||||
3074 | if (Error Err = ImportTemplateArgumentListInfo( | ||||||||||
3075 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), | ||||||||||
3076 | llvm::makeArrayRef( | ||||||||||
3077 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), | ||||||||||
3078 | ToTAInfo)) | ||||||||||
3079 | return Err; | ||||||||||
3080 | |||||||||||
3081 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), | ||||||||||
3082 | TemplDecls, ToTAInfo); | ||||||||||
3083 | return Error::success(); | ||||||||||
3084 | } | ||||||||||
3085 | } | ||||||||||
3086 | llvm_unreachable("All cases should be covered!")::llvm::llvm_unreachable_internal("All cases should be covered!" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 3086); | ||||||||||
3087 | } | ||||||||||
3088 | |||||||||||
3089 | Expected<FunctionDecl *> | ||||||||||
3090 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { | ||||||||||
3091 | auto FunctionAndArgsOrErr = | ||||||||||
3092 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); | ||||||||||
3093 | if (!FunctionAndArgsOrErr) | ||||||||||
3094 | return FunctionAndArgsOrErr.takeError(); | ||||||||||
3095 | |||||||||||
3096 | FunctionTemplateDecl *Template; | ||||||||||
3097 | TemplateArgsTy ToTemplArgs; | ||||||||||
3098 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; | ||||||||||
3099 | void *InsertPos = nullptr; | ||||||||||
3100 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); | ||||||||||
3101 | return FoundSpec; | ||||||||||
3102 | } | ||||||||||
3103 | |||||||||||
3104 | Error ASTNodeImporter::ImportFunctionDeclBody(FunctionDecl *FromFD, | ||||||||||
3105 | FunctionDecl *ToFD) { | ||||||||||
3106 | if (Stmt *FromBody = FromFD->getBody()) { | ||||||||||
3107 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) | ||||||||||
3108 | ToFD->setBody(*ToBodyOrErr); | ||||||||||
3109 | else | ||||||||||
3110 | return ToBodyOrErr.takeError(); | ||||||||||
3111 | } | ||||||||||
3112 | return Error::success(); | ||||||||||
3113 | } | ||||||||||
3114 | |||||||||||
3115 | // Returns true if the given D has a DeclContext up to the TranslationUnitDecl | ||||||||||
3116 | // which is equal to the given DC. | ||||||||||
3117 | static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) { | ||||||||||
3118 | const DeclContext *DCi = D->getDeclContext(); | ||||||||||
3119 | while (DCi != D->getTranslationUnitDecl()) { | ||||||||||
3120 | if (DCi == DC) | ||||||||||
3121 | return true; | ||||||||||
3122 | DCi = DCi->getParent(); | ||||||||||
3123 | } | ||||||||||
3124 | return false; | ||||||||||
3125 | } | ||||||||||
3126 | |||||||||||
3127 | bool ASTNodeImporter::hasAutoReturnTypeDeclaredInside(FunctionDecl *D) { | ||||||||||
3128 | QualType FromTy = D->getType(); | ||||||||||
3129 | const FunctionProtoType *FromFPT = FromTy->getAs<FunctionProtoType>(); | ||||||||||
3130 | assert(FromFPT && "Must be called on FunctionProtoType")((FromFPT && "Must be called on FunctionProtoType") ? static_cast<void> (0) : __assert_fail ("FromFPT && \"Must be called on FunctionProtoType\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 3130, __PRETTY_FUNCTION__)); | ||||||||||
3131 | if (AutoType *AutoT = FromFPT->getReturnType()->getContainedAutoType()) { | ||||||||||
3132 | QualType DeducedT = AutoT->getDeducedType(); | ||||||||||
3133 | if (const RecordType *RecordT = | ||||||||||
3134 | DeducedT.isNull() ? nullptr : dyn_cast<RecordType>(DeducedT)) { | ||||||||||
3135 | RecordDecl *RD = RecordT->getDecl(); | ||||||||||
3136 | assert(RD)((RD) ? static_cast<void> (0) : __assert_fail ("RD", "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 3136, __PRETTY_FUNCTION__)); | ||||||||||
3137 | if (isAncestorDeclContextOf(D, RD)) { | ||||||||||
3138 | assert(RD->getLexicalDeclContext() == RD->getDeclContext())((RD->getLexicalDeclContext() == RD->getDeclContext()) ? static_cast<void> (0) : __assert_fail ("RD->getLexicalDeclContext() == RD->getDeclContext()" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 3138, __PRETTY_FUNCTION__)); | ||||||||||
3139 | return true; | ||||||||||
3140 | } | ||||||||||
3141 | } | ||||||||||
3142 | } | ||||||||||
3143 | if (const TypedefType *TypedefT = | ||||||||||
3144 | dyn_cast<TypedefType>(FromFPT->getReturnType())) { | ||||||||||
3145 | TypedefNameDecl *TD = TypedefT->getDecl(); | ||||||||||
3146 | assert(TD)((TD) ? static_cast<void> (0) : __assert_fail ("TD", "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 3146, __PRETTY_FUNCTION__)); | ||||||||||
3147 | if (isAncestorDeclContextOf(D, TD)) { | ||||||||||
3148 | assert(TD->getLexicalDeclContext() == TD->getDeclContext())((TD->getLexicalDeclContext() == TD->getDeclContext()) ? static_cast<void> (0) : __assert_fail ("TD->getLexicalDeclContext() == TD->getDeclContext()" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 3148, __PRETTY_FUNCTION__)); | ||||||||||
3149 | return true; | ||||||||||
3150 | } | ||||||||||
3151 | } | ||||||||||
3152 | return false; | ||||||||||
3153 | } | ||||||||||
3154 | |||||||||||
3155 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { | ||||||||||
3156 | |||||||||||
3157 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); | ||||||||||
3158 | auto RedeclIt = Redecls.begin(); | ||||||||||
3159 | // Import the first part of the decl chain. I.e. import all previous | ||||||||||
3160 | // declarations starting from the canonical decl. | ||||||||||
3161 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { | ||||||||||
| |||||||||||
3162 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); | ||||||||||
3163 | if (!ToRedeclOrErr) | ||||||||||
3164 | return ToRedeclOrErr.takeError(); | ||||||||||
3165 | } | ||||||||||
3166 | assert(*RedeclIt == D)((*RedeclIt == D) ? static_cast<void> (0) : __assert_fail ("*RedeclIt == D", "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 3166, __PRETTY_FUNCTION__)); | ||||||||||
3167 | |||||||||||
3168 | // Import the major distinguishing characteristics of this function. | ||||||||||
3169 | DeclContext *DC, *LexicalDC; | ||||||||||
3170 | DeclarationName Name; | ||||||||||
3171 | SourceLocation Loc; | ||||||||||
3172 | NamedDecl *ToD; | ||||||||||
3173 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
3174 | return std::move(Err); | ||||||||||
3175 | if (ToD
| ||||||||||
3176 | return ToD; | ||||||||||
3177 | |||||||||||
3178 | FunctionDecl *FoundByLookup = nullptr; | ||||||||||
3179 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); | ||||||||||
3180 | |||||||||||
3181 | // If this is a function template specialization, then try to find the same | ||||||||||
3182 | // existing specialization in the "to" context. The lookup below will not | ||||||||||
3183 | // find any specialization, but would find the primary template; thus, we | ||||||||||
3184 | // have to skip normal lookup in case of specializations. | ||||||||||
3185 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? | ||||||||||
3186 | if (D->getTemplatedKind() == | ||||||||||
3187 | FunctionDecl::TK_FunctionTemplateSpecialization) { | ||||||||||
3188 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); | ||||||||||
3189 | if (!FoundFunctionOrErr) | ||||||||||
3190 | return FoundFunctionOrErr.takeError(); | ||||||||||
3191 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { | ||||||||||
3192 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) | ||||||||||
3193 | return Def; | ||||||||||
3194 | FoundByLookup = FoundFunction; | ||||||||||
3195 | } | ||||||||||
3196 | } | ||||||||||
3197 | // Try to find a function in our own ("to") context with the same name, same | ||||||||||
3198 | // type, and in the same context as the function we're importing. | ||||||||||
3199 | else if (!LexicalDC->isFunctionOrMethod()) { | ||||||||||
3200 | SmallVector<NamedDecl *, 4> ConflictingDecls; | ||||||||||
3201 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; | ||||||||||
3202 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||||||
3203 | for (auto *FoundDecl : FoundDecls) { | ||||||||||
3204 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | ||||||||||
3205 | continue; | ||||||||||
3206 | |||||||||||
3207 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { | ||||||||||
3208 | if (!hasSameVisibilityContextAndLinkage(FoundFunction, D)) | ||||||||||
3209 | continue; | ||||||||||
3210 | |||||||||||
3211 | if (IsStructuralMatch(D, FoundFunction)) { | ||||||||||
3212 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) | ||||||||||
3213 | return Def; | ||||||||||
3214 | FoundByLookup = FoundFunction; | ||||||||||
3215 | break; | ||||||||||
3216 | } | ||||||||||
3217 | // FIXME: Check for overloading more carefully, e.g., by boosting | ||||||||||
3218 | // Sema::IsOverload out to the AST library. | ||||||||||
3219 | |||||||||||
3220 | // Function overloading is okay in C++. | ||||||||||
3221 | if (Importer.getToContext().getLangOpts().CPlusPlus) | ||||||||||
3222 | continue; | ||||||||||
3223 | |||||||||||
3224 | // Complain about inconsistent function types. | ||||||||||
3225 | Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent) | ||||||||||
3226 | << Name << D->getType() << FoundFunction->getType(); | ||||||||||
3227 | Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here) | ||||||||||
3228 | << FoundFunction->getType(); | ||||||||||
3229 | ConflictingDecls.push_back(FoundDecl); | ||||||||||
3230 | } | ||||||||||
3231 | } | ||||||||||
3232 | |||||||||||
3233 | if (!ConflictingDecls.empty()) { | ||||||||||
3234 | ExpectedName NameOrErr = Importer.HandleNameConflict( | ||||||||||
3235 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); | ||||||||||
3236 | if (NameOrErr) | ||||||||||
3237 | Name = NameOrErr.get(); | ||||||||||
3238 | else | ||||||||||
3239 | return NameOrErr.takeError(); | ||||||||||
3240 | } | ||||||||||
3241 | } | ||||||||||
3242 | |||||||||||
3243 | // We do not allow more than one in-class declaration of a function. This is | ||||||||||
3244 | // because AST clients like VTableBuilder asserts on this. VTableBuilder | ||||||||||
3245 | // assumes there is only one in-class declaration. Building a redecl | ||||||||||
3246 | // chain would result in more than one in-class declaration for | ||||||||||
3247 | // overrides (even if they are part of the same redecl chain inside the | ||||||||||
3248 | // derived class.) | ||||||||||
3249 | if (FoundByLookup
| ||||||||||
3250 | if (isa<CXXMethodDecl>(FoundByLookup)) { | ||||||||||
3251 | if (D->getLexicalDeclContext() == D->getDeclContext()) { | ||||||||||
3252 | if (!D->doesThisDeclarationHaveABody()) { | ||||||||||
3253 | if (FunctionTemplateDecl *DescribedD = | ||||||||||
3254 | D->getDescribedFunctionTemplate()) { | ||||||||||
3255 | // Handle a "templated" function together with its described | ||||||||||
3256 | // template. This avoids need for a similar check at import of the | ||||||||||
3257 | // described template. | ||||||||||
3258 | assert(FoundByLookup->getDescribedFunctionTemplate() &&((FoundByLookup->getDescribedFunctionTemplate() && "Templated function mapped to non-templated?") ? static_cast <void> (0) : __assert_fail ("FoundByLookup->getDescribedFunctionTemplate() && \"Templated function mapped to non-templated?\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 3259, __PRETTY_FUNCTION__)) | ||||||||||
3259 | "Templated function mapped to non-templated?")((FoundByLookup->getDescribedFunctionTemplate() && "Templated function mapped to non-templated?") ? static_cast <void> (0) : __assert_fail ("FoundByLookup->getDescribedFunctionTemplate() && \"Templated function mapped to non-templated?\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 3259, __PRETTY_FUNCTION__)); | ||||||||||
3260 | Importer.MapImported(DescribedD, | ||||||||||
3261 | FoundByLookup->getDescribedFunctionTemplate()); | ||||||||||
3262 | } | ||||||||||
3263 | return Importer.MapImported(D, FoundByLookup); | ||||||||||
3264 | } else { | ||||||||||
3265 | // Let's continue and build up the redecl chain in this case. | ||||||||||
3266 | // FIXME Merge the functions into one decl. | ||||||||||
3267 | } | ||||||||||
3268 | } | ||||||||||
3269 | } | ||||||||||
3270 | } | ||||||||||
3271 | |||||||||||
3272 | DeclarationNameInfo NameInfo(Name, Loc); | ||||||||||
3273 | // Import additional name location/type info. | ||||||||||
3274 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | ||||||||||
3275 | return std::move(Err); | ||||||||||
3276 | |||||||||||
3277 | QualType FromTy = D->getType(); | ||||||||||
3278 | // Set to true if we do not import the type of the function as is. There are | ||||||||||
3279 | // cases when the original type would result in an infinite recursion during | ||||||||||
3280 | // the import. To avoid an infinite recursion when importing, we create the | ||||||||||
3281 | // FunctionDecl with a simplified function type and update it only after the | ||||||||||
3282 | // relevant AST nodes are already imported. | ||||||||||
3283 | bool UsedDifferentProtoType = false; | ||||||||||
3284 | if (const auto *FromFPT
| ||||||||||
3285 | QualType FromReturnTy = FromFPT->getReturnType(); | ||||||||||
3286 | // Functions with auto return type may define a struct inside their body | ||||||||||
3287 | // and the return type could refer to that struct. | ||||||||||
3288 | // E.g.: auto foo() { struct X{}; return X(); } | ||||||||||
3289 | // To avoid an infinite recursion when importing, create the FunctionDecl | ||||||||||
3290 | // with a simplified return type. | ||||||||||
3291 | if (hasAutoReturnTypeDeclaredInside(D)) { | ||||||||||
3292 | FromReturnTy = Importer.getFromContext().VoidTy; | ||||||||||
3293 | UsedDifferentProtoType = true; | ||||||||||
3294 | } | ||||||||||
3295 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); | ||||||||||
3296 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the | ||||||||||
3297 | // FunctionDecl that we are importing the FunctionProtoType for. | ||||||||||
3298 | // To avoid an infinite recursion when importing, create the FunctionDecl | ||||||||||
3299 | // with a simplified function type. | ||||||||||
3300 | if (FromEPI.ExceptionSpec.SourceDecl || | ||||||||||
3301 | FromEPI.ExceptionSpec.SourceTemplate || | ||||||||||
3302 | FromEPI.ExceptionSpec.NoexceptExpr) { | ||||||||||
3303 | FunctionProtoType::ExtProtoInfo DefaultEPI; | ||||||||||
3304 | FromEPI = DefaultEPI; | ||||||||||
3305 | UsedDifferentProtoType = true; | ||||||||||
3306 | } | ||||||||||
3307 | FromTy = Importer.getFromContext().getFunctionType( | ||||||||||
3308 | FromReturnTy, FromFPT->getParamTypes(), FromEPI); | ||||||||||
3309 | } | ||||||||||
3310 | |||||||||||
3311 | Error Err = Error::success(); | ||||||||||
3312 | auto T = importChecked(Err, FromTy); | ||||||||||
3313 | auto TInfo = importChecked(Err, D->getTypeSourceInfo()); | ||||||||||
3314 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); | ||||||||||
3315 | auto ToEndLoc = importChecked(Err, D->getEndLoc()); | ||||||||||
3316 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | ||||||||||
3317 | auto TrailingRequiresClause = | ||||||||||
3318 | importChecked(Err, D->getTrailingRequiresClause()); | ||||||||||
3319 | if (Err) | ||||||||||
3320 | return std::move(Err); | ||||||||||
3321 | |||||||||||
3322 | // Import the function parameters. | ||||||||||
3323 | SmallVector<ParmVarDecl *, 8> Parameters; | ||||||||||
3324 | for (auto P : D->parameters()) { | ||||||||||
3325 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) | ||||||||||
3326 | Parameters.push_back(*ToPOrErr); | ||||||||||
3327 | else | ||||||||||
3328 | return ToPOrErr.takeError(); | ||||||||||
3329 | } | ||||||||||
3330 | |||||||||||
3331 | // Create the imported function. | ||||||||||
3332 | FunctionDecl *ToFunction = nullptr; | ||||||||||
3333 | if (auto *FromConstructor
| ||||||||||
3334 | Expr *ExplicitExpr = nullptr; | ||||||||||
3335 | if (FromConstructor->getExplicitSpecifier().getExpr()) { | ||||||||||
3336 | auto Imp = import(FromConstructor->getExplicitSpecifier().getExpr()); | ||||||||||
3337 | if (!Imp) | ||||||||||
3338 | return Imp.takeError(); | ||||||||||
3339 | ExplicitExpr = *Imp; | ||||||||||
3340 | } | ||||||||||
3341 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( | ||||||||||
3342 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | ||||||||||
| |||||||||||
3343 | ToInnerLocStart, NameInfo, T, TInfo, | ||||||||||
3344 | ExplicitSpecifier( | ||||||||||
3345 | ExplicitExpr, | ||||||||||
3346 | FromConstructor->getExplicitSpecifier().getKind()), | ||||||||||
3347 | D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(), | ||||||||||
3348 | InheritedConstructor(), // FIXME: Properly import inherited | ||||||||||
3349 | // constructor info | ||||||||||
3350 | TrailingRequiresClause)) | ||||||||||
3351 | return ToFunction; | ||||||||||
3352 | } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) { | ||||||||||
3353 | |||||||||||
3354 | Error Err = Error::success(); | ||||||||||
3355 | auto ToOperatorDelete = importChecked( | ||||||||||
3356 | Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete())); | ||||||||||
3357 | auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg()); | ||||||||||
3358 | if (Err) | ||||||||||
3359 | return std::move(Err); | ||||||||||
3360 | |||||||||||
3361 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( | ||||||||||
3362 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | ||||||||||
3363 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), | ||||||||||
3364 | D->isImplicit(), D->getConstexprKind(), TrailingRequiresClause)) | ||||||||||
3365 | return ToFunction; | ||||||||||
3366 | |||||||||||
3367 | CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction); | ||||||||||
3368 | |||||||||||
3369 | ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); | ||||||||||
3370 | } else if (CXXConversionDecl *FromConversion = | ||||||||||
3371 | dyn_cast<CXXConversionDecl>(D)) { | ||||||||||
3372 | Expr *ExplicitExpr = nullptr; | ||||||||||
3373 | if (FromConversion->getExplicitSpecifier().getExpr()) { | ||||||||||
3374 | auto Imp = import(FromConversion->getExplicitSpecifier().getExpr()); | ||||||||||
3375 | if (!Imp) | ||||||||||
3376 | return Imp.takeError(); | ||||||||||
3377 | ExplicitExpr = *Imp; | ||||||||||
3378 | } | ||||||||||
3379 | if (GetImportedOrCreateDecl<CXXConversionDecl>( | ||||||||||
3380 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | ||||||||||
3381 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), | ||||||||||
3382 | ExplicitSpecifier(ExplicitExpr, | ||||||||||
3383 | FromConversion->getExplicitSpecifier().getKind()), | ||||||||||
3384 | D->getConstexprKind(), SourceLocation(), TrailingRequiresClause)) | ||||||||||
3385 | return ToFunction; | ||||||||||
3386 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { | ||||||||||
3387 | if (GetImportedOrCreateDecl<CXXMethodDecl>( | ||||||||||
3388 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | ||||||||||
3389 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), | ||||||||||
3390 | Method->isInlineSpecified(), D->getConstexprKind(), | ||||||||||
3391 | SourceLocation(), TrailingRequiresClause)) | ||||||||||
3392 | return ToFunction; | ||||||||||
3393 | } else { | ||||||||||
3394 | if (GetImportedOrCreateDecl( | ||||||||||
3395 | ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, | ||||||||||
3396 | NameInfo, T, TInfo, D->getStorageClass(), D->isInlineSpecified(), | ||||||||||
3397 | D->hasWrittenPrototype(), D->getConstexprKind(), | ||||||||||
3398 | TrailingRequiresClause)) | ||||||||||
3399 | return ToFunction; | ||||||||||
3400 | } | ||||||||||
3401 | |||||||||||
3402 | // Connect the redecl chain. | ||||||||||
3403 | if (FoundByLookup) { | ||||||||||
3404 | auto *Recent = const_cast<FunctionDecl *>( | ||||||||||
3405 | FoundByLookup->getMostRecentDecl()); | ||||||||||
3406 | ToFunction->setPreviousDecl(Recent); | ||||||||||
3407 | // FIXME Probably we should merge exception specifications. E.g. In the | ||||||||||
3408 | // "To" context the existing function may have exception specification with | ||||||||||
3409 | // noexcept-unevaluated, while the newly imported function may have an | ||||||||||
3410 | // evaluated noexcept. A call to adjustExceptionSpec() on the imported | ||||||||||
3411 | // decl and its redeclarations may be required. | ||||||||||
3412 | } | ||||||||||
3413 | |||||||||||
3414 | ToFunction->setQualifierInfo(ToQualifierLoc); | ||||||||||
3415 | ToFunction->setAccess(D->getAccess()); | ||||||||||
3416 | ToFunction->setLexicalDeclContext(LexicalDC); | ||||||||||
3417 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); | ||||||||||
3418 | ToFunction->setTrivial(D->isTrivial()); | ||||||||||
3419 | ToFunction->setPure(D->isPure()); | ||||||||||
3420 | ToFunction->setDefaulted(D->isDefaulted()); | ||||||||||
3421 | ToFunction->setExplicitlyDefaulted(D->isExplicitlyDefaulted()); | ||||||||||
3422 | ToFunction->setDeletedAsWritten(D->isDeletedAsWritten()); | ||||||||||
3423 | ToFunction->setRangeEnd(ToEndLoc); | ||||||||||
3424 | |||||||||||
3425 | // Set the parameters. | ||||||||||
3426 | for (auto *Param : Parameters) { | ||||||||||
3427 | Param->setOwningFunction(ToFunction); | ||||||||||
3428 | ToFunction->addDeclInternal(Param); | ||||||||||
3429 | } | ||||||||||
3430 | ToFunction->setParams(Parameters); | ||||||||||
3431 | |||||||||||
3432 | // We need to complete creation of FunctionProtoTypeLoc manually with setting | ||||||||||
3433 | // params it refers to. | ||||||||||
3434 | if (TInfo) { | ||||||||||
3435 | if (auto ProtoLoc = | ||||||||||
3436 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { | ||||||||||
3437 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) | ||||||||||
3438 | ProtoLoc.setParam(I, Parameters[I]); | ||||||||||
3439 | } | ||||||||||
3440 | } | ||||||||||
3441 | |||||||||||
3442 | // Import the describing template function, if any. | ||||||||||
3443 | if (FromFT) { | ||||||||||
3444 | auto ToFTOrErr = import(FromFT); | ||||||||||
3445 | if (!ToFTOrErr) | ||||||||||
3446 | return ToFTOrErr.takeError(); | ||||||||||
3447 | } | ||||||||||
3448 | |||||||||||
3449 | // Import Ctor initializers. | ||||||||||
3450 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { | ||||||||||
3451 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { | ||||||||||
3452 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); | ||||||||||
3453 | // Import first, then allocate memory and copy if there was no error. | ||||||||||
3454 | if (Error Err = ImportContainerChecked( | ||||||||||
3455 | FromConstructor->inits(), CtorInitializers)) | ||||||||||
3456 | return std::move(Err); | ||||||||||
3457 | auto **Memory = | ||||||||||
3458 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; | ||||||||||
3459 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); | ||||||||||
3460 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); | ||||||||||
3461 | ToCtor->setCtorInitializers(Memory); | ||||||||||
3462 | ToCtor->setNumCtorInitializers(NumInitializers); | ||||||||||
3463 | } | ||||||||||
3464 | } | ||||||||||
3465 | |||||||||||
3466 | if (D->doesThisDeclarationHaveABody()) { | ||||||||||
3467 | Error Err = ImportFunctionDeclBody(D, ToFunction); | ||||||||||
3468 | |||||||||||
3469 | if (Err) | ||||||||||
3470 | return std::move(Err); | ||||||||||
3471 | } | ||||||||||
3472 | |||||||||||
3473 | // Import and set the original type in case we used another type. | ||||||||||
3474 | if (UsedDifferentProtoType) { | ||||||||||
3475 | if (ExpectedType TyOrErr = import(D->getType())) | ||||||||||
3476 | ToFunction->setType(*TyOrErr); | ||||||||||
3477 | else | ||||||||||
3478 | return TyOrErr.takeError(); | ||||||||||
3479 | } | ||||||||||
3480 | |||||||||||
3481 | // FIXME: Other bits to merge? | ||||||||||
3482 | |||||||||||
3483 | // If it is a template, import all related things. | ||||||||||
3484 | if (Error Err = ImportTemplateInformation(D, ToFunction)) | ||||||||||
3485 | return std::move(Err); | ||||||||||
3486 | |||||||||||
3487 | addDeclToContexts(D, ToFunction); | ||||||||||
3488 | |||||||||||
3489 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) | ||||||||||
3490 | if (Error Err = ImportOverriddenMethods(cast<CXXMethodDecl>(ToFunction), | ||||||||||
3491 | FromCXXMethod)) | ||||||||||
3492 | return std::move(Err); | ||||||||||
3493 | |||||||||||
3494 | // Import the rest of the chain. I.e. import all subsequent declarations. | ||||||||||
3495 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { | ||||||||||
3496 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); | ||||||||||
3497 | if (!ToRedeclOrErr) | ||||||||||
3498 | return ToRedeclOrErr.takeError(); | ||||||||||
3499 | } | ||||||||||
3500 | |||||||||||
3501 | return ToFunction; | ||||||||||
3502 | } | ||||||||||
3503 | |||||||||||
3504 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { | ||||||||||
3505 | return VisitFunctionDecl(D); | ||||||||||
3506 | } | ||||||||||
3507 | |||||||||||
3508 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { | ||||||||||
3509 | return VisitCXXMethodDecl(D); | ||||||||||
3510 | } | ||||||||||
3511 | |||||||||||
3512 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { | ||||||||||
3513 | return VisitCXXMethodDecl(D); | ||||||||||
3514 | } | ||||||||||
3515 | |||||||||||
3516 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { | ||||||||||
3517 | return VisitCXXMethodDecl(D); | ||||||||||
3518 | } | ||||||||||
3519 | |||||||||||
3520 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { | ||||||||||
3521 | // Import the major distinguishing characteristics of a variable. | ||||||||||
3522 | DeclContext *DC, *LexicalDC; | ||||||||||
3523 | DeclarationName Name; | ||||||||||
3524 | SourceLocation Loc; | ||||||||||
3525 | NamedDecl *ToD; | ||||||||||
3526 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
3527 | return std::move(Err); | ||||||||||
3528 | if (ToD) | ||||||||||
3529 | return ToD; | ||||||||||
3530 | |||||||||||
3531 | // Determine whether we've already imported this field. | ||||||||||
3532 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||||||
3533 | for (auto *FoundDecl : FoundDecls) { | ||||||||||
3534 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { | ||||||||||
3535 | // For anonymous fields, match up by index. | ||||||||||
3536 | if (!Name && | ||||||||||
3537 | ASTImporter::getFieldIndex(D) != | ||||||||||
3538 | ASTImporter::getFieldIndex(FoundField)) | ||||||||||
3539 | continue; | ||||||||||
3540 | |||||||||||
3541 | if (Importer.IsStructurallyEquivalent(D->getType(), | ||||||||||
3542 | FoundField->getType())) { | ||||||||||
3543 | Importer.MapImported(D, FoundField); | ||||||||||
3544 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the | ||||||||||
3545 | // initializer of a FieldDecl might not had been instantiated in the | ||||||||||
3546 | // "To" context. However, the "From" context might instantiated that, | ||||||||||
3547 | // thus we have to merge that. | ||||||||||
3548 | if (Expr *FromInitializer = D->getInClassInitializer()) { | ||||||||||
3549 | // We don't have yet the initializer set. | ||||||||||
3550 | if (FoundField->hasInClassInitializer() && | ||||||||||
3551 | !FoundField->getInClassInitializer()) { | ||||||||||
3552 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) | ||||||||||
3553 | FoundField->setInClassInitializer(*ToInitializerOrErr); | ||||||||||
3554 | else { | ||||||||||
3555 | // We can't return error here, | ||||||||||
3556 | // since we already mapped D as imported. | ||||||||||
3557 | // FIXME: warning message? | ||||||||||
3558 | consumeError(ToInitializerOrErr.takeError()); | ||||||||||
3559 | return FoundField; | ||||||||||
3560 | } | ||||||||||
3561 | } | ||||||||||
3562 | } | ||||||||||
3563 | return FoundField; | ||||||||||
3564 | } | ||||||||||
3565 | |||||||||||
3566 | // FIXME: Why is this case not handled with calling HandleNameConflict? | ||||||||||
3567 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) | ||||||||||
3568 | << Name << D->getType() << FoundField->getType(); | ||||||||||
3569 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) | ||||||||||
3570 | << FoundField->getType(); | ||||||||||
3571 | |||||||||||
3572 | return make_error<ImportError>(ImportError::NameConflict); | ||||||||||
3573 | } | ||||||||||
3574 | } | ||||||||||
3575 | |||||||||||
3576 | Error Err = Error::success(); | ||||||||||
3577 | auto ToType = importChecked(Err, D->getType()); | ||||||||||
3578 | auto ToTInfo = importChecked(Err, D->getTypeSourceInfo()); | ||||||||||
3579 | auto ToBitWidth = importChecked(Err, D->getBitWidth()); | ||||||||||
3580 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); | ||||||||||
3581 | auto ToInitializer = importChecked(Err, D->getInClassInitializer()); | ||||||||||
3582 | if (Err) | ||||||||||
3583 | return std::move(Err); | ||||||||||
3584 | |||||||||||
3585 | FieldDecl *ToField; | ||||||||||
3586 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, | ||||||||||
3587 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), | ||||||||||
3588 | ToType, ToTInfo, ToBitWidth, D->isMutable(), | ||||||||||
3589 | D->getInClassInitStyle())) | ||||||||||
3590 | return ToField; | ||||||||||
3591 | |||||||||||
3592 | ToField->setAccess(D->getAccess()); | ||||||||||
3593 | ToField->setLexicalDeclContext(LexicalDC); | ||||||||||
3594 | if (ToInitializer) | ||||||||||
3595 | ToField->setInClassInitializer(ToInitializer); | ||||||||||
3596 | ToField->setImplicit(D->isImplicit()); | ||||||||||
3597 | LexicalDC->addDeclInternal(ToField); | ||||||||||
3598 | return ToField; | ||||||||||
3599 | } | ||||||||||
3600 | |||||||||||
3601 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { | ||||||||||
3602 | // Import the major distinguishing characteristics of a variable. | ||||||||||
3603 | DeclContext *DC, *LexicalDC; | ||||||||||
3604 | DeclarationName Name; | ||||||||||
3605 | SourceLocation Loc; | ||||||||||
3606 | NamedDecl *ToD; | ||||||||||
3607 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
3608 | return std::move(Err); | ||||||||||
3609 | if (ToD) | ||||||||||
3610 | return ToD; | ||||||||||
3611 | |||||||||||
3612 | // Determine whether we've already imported this field. | ||||||||||
3613 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||||||
3614 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | ||||||||||
3615 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { | ||||||||||
3616 | // For anonymous indirect fields, match up by index. | ||||||||||
3617 | if (!Name && | ||||||||||
3618 | ASTImporter::getFieldIndex(D) != | ||||||||||
3619 | ASTImporter::getFieldIndex(FoundField)) | ||||||||||
3620 | continue; | ||||||||||
3621 | |||||||||||
3622 | if (Importer.IsStructurallyEquivalent(D->getType(), | ||||||||||
3623 | FoundField->getType(), | ||||||||||
3624 | !Name.isEmpty())) { | ||||||||||
3625 | Importer.MapImported(D, FoundField); | ||||||||||
3626 | return FoundField; | ||||||||||
3627 | } | ||||||||||
3628 | |||||||||||
3629 | // If there are more anonymous fields to check, continue. | ||||||||||
3630 | if (!Name && I < N-1) | ||||||||||
3631 | continue; | ||||||||||
3632 | |||||||||||
3633 | // FIXME: Why is this case not handled with calling HandleNameConflict? | ||||||||||
3634 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) | ||||||||||
3635 | << Name << D->getType() << FoundField->getType(); | ||||||||||
3636 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) | ||||||||||
3637 | << FoundField->getType(); | ||||||||||
3638 | |||||||||||
3639 | return make_error<ImportError>(ImportError::NameConflict); | ||||||||||
3640 | } | ||||||||||
3641 | } | ||||||||||
3642 | |||||||||||
3643 | // Import the type. | ||||||||||
3644 | auto TypeOrErr = import(D->getType()); | ||||||||||
3645 | if (!TypeOrErr) | ||||||||||
3646 | return TypeOrErr.takeError(); | ||||||||||
3647 | |||||||||||
3648 | auto **NamedChain = | ||||||||||
3649 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; | ||||||||||
3650 | |||||||||||
3651 | unsigned i = 0; | ||||||||||
3652 | for (auto *PI : D->chain()) | ||||||||||
3653 | if (Expected<NamedDecl *> ToD = import(PI)) | ||||||||||
3654 | NamedChain[i++] = *ToD; | ||||||||||
3655 | else | ||||||||||
3656 | return ToD.takeError(); | ||||||||||
3657 | |||||||||||
3658 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; | ||||||||||
3659 | IndirectFieldDecl *ToIndirectField; | ||||||||||
3660 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, | ||||||||||
3661 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) | ||||||||||
3662 | // FIXME here we leak `NamedChain` which is allocated before | ||||||||||
3663 | return ToIndirectField; | ||||||||||
3664 | |||||||||||
3665 | ToIndirectField->setAccess(D->getAccess()); | ||||||||||
3666 | ToIndirectField->setLexicalDeclContext(LexicalDC); | ||||||||||
3667 | LexicalDC->addDeclInternal(ToIndirectField); | ||||||||||
3668 | return ToIndirectField; | ||||||||||
3669 | } | ||||||||||
3670 | |||||||||||
3671 | /// Used as return type of getFriendCountAndPosition. | ||||||||||
3672 | struct FriendCountAndPosition { | ||||||||||
3673 | /// Number of similar looking friends. | ||||||||||
3674 | unsigned int TotalCount; | ||||||||||
3675 | /// Index of the specific FriendDecl. | ||||||||||
3676 | unsigned int IndexOfDecl; | ||||||||||
3677 | }; | ||||||||||
3678 | |||||||||||
3679 | template <class T> | ||||||||||
3680 | static FriendCountAndPosition getFriendCountAndPosition( | ||||||||||
3681 | const FriendDecl *FD, | ||||||||||
3682 | llvm::function_ref<T(const FriendDecl *)> GetCanTypeOrDecl) { | ||||||||||
3683 | unsigned int FriendCount = 0; | ||||||||||
3684 | llvm::Optional<unsigned int> FriendPosition; | ||||||||||
3685 | const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext()); | ||||||||||
3686 | |||||||||||
3687 | T TypeOrDecl = GetCanTypeOrDecl(FD); | ||||||||||
3688 | |||||||||||
3689 | for (const FriendDecl *FoundFriend : RD->friends()) { | ||||||||||
3690 | if (FoundFriend == FD) { | ||||||||||
3691 | FriendPosition = FriendCount; | ||||||||||
3692 | ++FriendCount; | ||||||||||
3693 | } else if (!FoundFriend->getFriendDecl() == !FD->getFriendDecl() && | ||||||||||
3694 | GetCanTypeOrDecl(FoundFriend) == TypeOrDecl) { | ||||||||||
3695 | ++FriendCount; | ||||||||||
3696 | } | ||||||||||
3697 | } | ||||||||||
3698 | |||||||||||
3699 | assert(FriendPosition && "Friend decl not found in own parent.")((FriendPosition && "Friend decl not found in own parent." ) ? static_cast<void> (0) : __assert_fail ("FriendPosition && \"Friend decl not found in own parent.\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 3699, __PRETTY_FUNCTION__)); | ||||||||||
3700 | |||||||||||
3701 | return {FriendCount, *FriendPosition}; | ||||||||||
3702 | } | ||||||||||
3703 | |||||||||||
3704 | static FriendCountAndPosition getFriendCountAndPosition(const FriendDecl *FD) { | ||||||||||
3705 | if (FD->getFriendType()) | ||||||||||
3706 | return getFriendCountAndPosition<QualType>(FD, [](const FriendDecl *F) { | ||||||||||
3707 | if (TypeSourceInfo *TSI = F->getFriendType()) | ||||||||||
3708 | return TSI->getType().getCanonicalType(); | ||||||||||
3709 | llvm_unreachable("Wrong friend object type.")::llvm::llvm_unreachable_internal("Wrong friend object type." , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 3709); | ||||||||||
3710 | }); | ||||||||||
3711 | else | ||||||||||
3712 | return getFriendCountAndPosition<Decl *>(FD, [](const FriendDecl *F) { | ||||||||||
3713 | if (Decl *D = F->getFriendDecl()) | ||||||||||
3714 | return D->getCanonicalDecl(); | ||||||||||
3715 | llvm_unreachable("Wrong friend object type.")::llvm::llvm_unreachable_internal("Wrong friend object type." , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 3715); | ||||||||||
3716 | }); | ||||||||||
3717 | } | ||||||||||
3718 | |||||||||||
3719 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { | ||||||||||
3720 | // Import the major distinguishing characteristics of a declaration. | ||||||||||
3721 | DeclContext *DC, *LexicalDC; | ||||||||||
3722 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | ||||||||||
3723 | return std::move(Err); | ||||||||||
3724 | |||||||||||
3725 | // Determine whether we've already imported this decl. | ||||||||||
3726 | // FriendDecl is not a NamedDecl so we cannot use lookup. | ||||||||||
3727 | // We try to maintain order and count of redundant friend declarations. | ||||||||||
3728 | const auto *RD = cast<CXXRecordDecl>(DC); | ||||||||||
3729 | FriendDecl *ImportedFriend = RD->getFirstFriend(); | ||||||||||
3730 | SmallVector<FriendDecl *, 2> ImportedEquivalentFriends; | ||||||||||
3731 | |||||||||||
3732 | while (ImportedFriend) { | ||||||||||
3733 | bool Match = false; | ||||||||||
3734 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { | ||||||||||
3735 | Match = | ||||||||||
3736 | IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), | ||||||||||
3737 | /*Complain=*/false); | ||||||||||
3738 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { | ||||||||||
3739 | Match = Importer.IsStructurallyEquivalent( | ||||||||||
3740 | D->getFriendType()->getType(), | ||||||||||
3741 | ImportedFriend->getFriendType()->getType(), /*Complain=*/false); | ||||||||||
3742 | } | ||||||||||
3743 | if (Match) | ||||||||||
3744 | ImportedEquivalentFriends.push_back(ImportedFriend); | ||||||||||
3745 | |||||||||||
3746 | ImportedFriend = ImportedFriend->getNextFriend(); | ||||||||||
3747 | } | ||||||||||
3748 | FriendCountAndPosition CountAndPosition = getFriendCountAndPosition(D); | ||||||||||
3749 | |||||||||||
3750 | assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&((ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount && "Class with non-matching friends is imported, ODR check wrong?" ) ? static_cast<void> (0) : __assert_fail ("ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount && \"Class with non-matching friends is imported, ODR check wrong?\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 3751, __PRETTY_FUNCTION__)) | ||||||||||
3751 | "Class with non-matching friends is imported, ODR check wrong?")((ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount && "Class with non-matching friends is imported, ODR check wrong?" ) ? static_cast<void> (0) : __assert_fail ("ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount && \"Class with non-matching friends is imported, ODR check wrong?\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 3751, __PRETTY_FUNCTION__)); | ||||||||||
3752 | if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount) | ||||||||||
3753 | return Importer.MapImported( | ||||||||||
3754 | D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]); | ||||||||||
3755 | |||||||||||
3756 | // Not found. Create it. | ||||||||||
3757 | // The declarations will be put into order later by ImportDeclContext. | ||||||||||
3758 | FriendDecl::FriendUnion ToFU; | ||||||||||
3759 | if (NamedDecl *FriendD = D->getFriendDecl()) { | ||||||||||
3760 | NamedDecl *ToFriendD; | ||||||||||
3761 | if (Error Err = importInto(ToFriendD, FriendD)) | ||||||||||
3762 | return std::move(Err); | ||||||||||
3763 | |||||||||||
3764 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && | ||||||||||
3765 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) | ||||||||||
3766 | ToFriendD->setObjectOfFriendDecl(false); | ||||||||||
3767 | |||||||||||
3768 | ToFU = ToFriendD; | ||||||||||
3769 | } else { // The friend is a type, not a decl. | ||||||||||
3770 | if (auto TSIOrErr = import(D->getFriendType())) | ||||||||||
3771 | ToFU = *TSIOrErr; | ||||||||||
3772 | else | ||||||||||
3773 | return TSIOrErr.takeError(); | ||||||||||
3774 | } | ||||||||||
3775 | |||||||||||
3776 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); | ||||||||||
3777 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); | ||||||||||
3778 | for (unsigned I = 0; I < D->NumTPLists; I++) { | ||||||||||
3779 | if (auto ListOrErr = import(FromTPLists[I])) | ||||||||||
3780 | ToTPLists[I] = *ListOrErr; | ||||||||||
3781 | else | ||||||||||
3782 | return ListOrErr.takeError(); | ||||||||||
3783 | } | ||||||||||
3784 | |||||||||||
3785 | auto LocationOrErr = import(D->getLocation()); | ||||||||||
3786 | if (!LocationOrErr) | ||||||||||
3787 | return LocationOrErr.takeError(); | ||||||||||
3788 | auto FriendLocOrErr = import(D->getFriendLoc()); | ||||||||||
3789 | if (!FriendLocOrErr) | ||||||||||
3790 | return FriendLocOrErr.takeError(); | ||||||||||
3791 | |||||||||||
3792 | FriendDecl *FrD; | ||||||||||
3793 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, | ||||||||||
3794 | *LocationOrErr, ToFU, | ||||||||||
3795 | *FriendLocOrErr, ToTPLists)) | ||||||||||
3796 | return FrD; | ||||||||||
3797 | |||||||||||
3798 | FrD->setAccess(D->getAccess()); | ||||||||||
3799 | FrD->setLexicalDeclContext(LexicalDC); | ||||||||||
3800 | LexicalDC->addDeclInternal(FrD); | ||||||||||
3801 | return FrD; | ||||||||||
3802 | } | ||||||||||
3803 | |||||||||||
3804 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { | ||||||||||
3805 | // Import the major distinguishing characteristics of an ivar. | ||||||||||
3806 | DeclContext *DC, *LexicalDC; | ||||||||||
3807 | DeclarationName Name; | ||||||||||
3808 | SourceLocation Loc; | ||||||||||
3809 | NamedDecl *ToD; | ||||||||||
3810 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
3811 | return std::move(Err); | ||||||||||
3812 | if (ToD) | ||||||||||
3813 | return ToD; | ||||||||||
3814 | |||||||||||
3815 | // Determine whether we've already imported this ivar | ||||||||||
3816 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||||||
3817 | for (auto *FoundDecl : FoundDecls) { | ||||||||||
3818 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { | ||||||||||
3819 | if (Importer.IsStructurallyEquivalent(D->getType(), | ||||||||||
3820 | FoundIvar->getType())) { | ||||||||||
3821 | Importer.MapImported(D, FoundIvar); | ||||||||||
3822 | return FoundIvar; | ||||||||||
3823 | } | ||||||||||
3824 | |||||||||||
3825 | Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent) | ||||||||||
3826 | << Name << D->getType() << FoundIvar->getType(); | ||||||||||
3827 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) | ||||||||||
3828 | << FoundIvar->getType(); | ||||||||||
3829 | |||||||||||
3830 | return make_error<ImportError>(ImportError::NameConflict); | ||||||||||
3831 | } | ||||||||||
3832 | } | ||||||||||
3833 | |||||||||||
3834 | Error Err = Error::success(); | ||||||||||
3835 | auto ToType = importChecked(Err, D->getType()); | ||||||||||
3836 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); | ||||||||||
3837 | auto ToBitWidth = importChecked(Err, D->getBitWidth()); | ||||||||||
3838 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); | ||||||||||
3839 | if (Err) | ||||||||||
3840 | return std::move(Err); | ||||||||||
3841 | |||||||||||
3842 | ObjCIvarDecl *ToIvar; | ||||||||||
3843 | if (GetImportedOrCreateDecl( | ||||||||||
3844 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), | ||||||||||
3845 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), | ||||||||||
3846 | ToType, ToTypeSourceInfo, | ||||||||||
3847 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) | ||||||||||
3848 | return ToIvar; | ||||||||||
3849 | |||||||||||
3850 | ToIvar->setLexicalDeclContext(LexicalDC); | ||||||||||
3851 | LexicalDC->addDeclInternal(ToIvar); | ||||||||||
3852 | return ToIvar; | ||||||||||
3853 | } | ||||||||||
3854 | |||||||||||
3855 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { | ||||||||||
3856 | |||||||||||
3857 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); | ||||||||||
3858 | auto RedeclIt = Redecls.begin(); | ||||||||||
3859 | // Import the first part of the decl chain. I.e. import all previous | ||||||||||
3860 | // declarations starting from the canonical decl. | ||||||||||
3861 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { | ||||||||||
3862 | ExpectedDecl RedeclOrErr = import(*RedeclIt); | ||||||||||
3863 | if (!RedeclOrErr) | ||||||||||
3864 | return RedeclOrErr.takeError(); | ||||||||||
3865 | } | ||||||||||
3866 | assert(*RedeclIt == D)((*RedeclIt == D) ? static_cast<void> (0) : __assert_fail ("*RedeclIt == D", "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 3866, __PRETTY_FUNCTION__)); | ||||||||||
3867 | |||||||||||
3868 | // Import the major distinguishing characteristics of a variable. | ||||||||||
3869 | DeclContext *DC, *LexicalDC; | ||||||||||
3870 | DeclarationName Name; | ||||||||||
3871 | SourceLocation Loc; | ||||||||||
3872 | NamedDecl *ToD; | ||||||||||
3873 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
3874 | return std::move(Err); | ||||||||||
3875 | if (ToD) | ||||||||||
3876 | return ToD; | ||||||||||
3877 | |||||||||||
3878 | // Try to find a variable in our own ("to") context with the same name and | ||||||||||
3879 | // in the same context as the variable we're importing. | ||||||||||
3880 | VarDecl *FoundByLookup = nullptr; | ||||||||||
3881 | if (D->isFileVarDecl()) { | ||||||||||
3882 | SmallVector<NamedDecl *, 4> ConflictingDecls; | ||||||||||
3883 | unsigned IDNS = Decl::IDNS_Ordinary; | ||||||||||
3884 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||||||
3885 | for (auto *FoundDecl : FoundDecls) { | ||||||||||
3886 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | ||||||||||
3887 | continue; | ||||||||||
3888 | |||||||||||
3889 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { | ||||||||||
3890 | if (!hasSameVisibilityContextAndLinkage(FoundVar, D)) | ||||||||||
3891 | continue; | ||||||||||
3892 | if (Importer.IsStructurallyEquivalent(D->getType(), | ||||||||||
3893 | FoundVar->getType())) { | ||||||||||
3894 | |||||||||||
3895 | // The VarDecl in the "From" context has a definition, but in the | ||||||||||
3896 | // "To" context we already have a definition. | ||||||||||
3897 | VarDecl *FoundDef = FoundVar->getDefinition(); | ||||||||||
3898 | if (D->isThisDeclarationADefinition() && FoundDef) | ||||||||||
3899 | // FIXME Check for ODR error if the two definitions have | ||||||||||
3900 | // different initializers? | ||||||||||
3901 | return Importer.MapImported(D, FoundDef); | ||||||||||
3902 | |||||||||||
3903 | // The VarDecl in the "From" context has an initializer, but in the | ||||||||||
3904 | // "To" context we already have an initializer. | ||||||||||
3905 | const VarDecl *FoundDInit = nullptr; | ||||||||||
3906 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) | ||||||||||
3907 | // FIXME Diagnose ODR error if the two initializers are different? | ||||||||||
3908 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); | ||||||||||
3909 | |||||||||||
3910 | FoundByLookup = FoundVar; | ||||||||||
3911 | break; | ||||||||||
3912 | } | ||||||||||
3913 | |||||||||||
3914 | const ArrayType *FoundArray | ||||||||||
3915 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); | ||||||||||
3916 | const ArrayType *TArray | ||||||||||
3917 | = Importer.getToContext().getAsArrayType(D->getType()); | ||||||||||
3918 | if (FoundArray && TArray) { | ||||||||||
3919 | if (isa<IncompleteArrayType>(FoundArray) && | ||||||||||
3920 | isa<ConstantArrayType>(TArray)) { | ||||||||||
3921 | // Import the type. | ||||||||||
3922 | if (auto TyOrErr = import(D->getType())) | ||||||||||
3923 | FoundVar->setType(*TyOrErr); | ||||||||||
3924 | else | ||||||||||
3925 | return TyOrErr.takeError(); | ||||||||||
3926 | |||||||||||
3927 | FoundByLookup = FoundVar; | ||||||||||
3928 | break; | ||||||||||
3929 | } else if (isa<IncompleteArrayType>(TArray) && | ||||||||||
3930 | isa<ConstantArrayType>(FoundArray)) { | ||||||||||
3931 | FoundByLookup = FoundVar; | ||||||||||
3932 | break; | ||||||||||
3933 | } | ||||||||||
3934 | } | ||||||||||
3935 | |||||||||||
3936 | Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent) | ||||||||||
3937 | << Name << D->getType() << FoundVar->getType(); | ||||||||||
3938 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) | ||||||||||
3939 | << FoundVar->getType(); | ||||||||||
3940 | ConflictingDecls.push_back(FoundDecl); | ||||||||||
3941 | } | ||||||||||
3942 | } | ||||||||||
3943 | |||||||||||
3944 | if (!ConflictingDecls.empty()) { | ||||||||||
3945 | ExpectedName NameOrErr = Importer.HandleNameConflict( | ||||||||||
3946 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); | ||||||||||
3947 | if (NameOrErr) | ||||||||||
3948 | Name = NameOrErr.get(); | ||||||||||
3949 | else | ||||||||||
3950 | return NameOrErr.takeError(); | ||||||||||
3951 | } | ||||||||||
3952 | } | ||||||||||
3953 | |||||||||||
3954 | Error Err = Error::success(); | ||||||||||
3955 | auto ToType = importChecked(Err, D->getType()); | ||||||||||
3956 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); | ||||||||||
3957 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); | ||||||||||
3958 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | ||||||||||
3959 | if (Err) | ||||||||||
3960 | return std::move(Err); | ||||||||||
3961 | |||||||||||
3962 | // Create the imported variable. | ||||||||||
3963 | VarDecl *ToVar; | ||||||||||
3964 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, | ||||||||||
3965 | ToInnerLocStart, Loc, | ||||||||||
3966 | Name.getAsIdentifierInfo(), | ||||||||||
3967 | ToType, ToTypeSourceInfo, | ||||||||||
3968 | D->getStorageClass())) | ||||||||||
3969 | return ToVar; | ||||||||||
3970 | |||||||||||
3971 | ToVar->setQualifierInfo(ToQualifierLoc); | ||||||||||
3972 | ToVar->setAccess(D->getAccess()); | ||||||||||
3973 | ToVar->setLexicalDeclContext(LexicalDC); | ||||||||||
3974 | |||||||||||
3975 | if (FoundByLookup) { | ||||||||||
3976 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); | ||||||||||
3977 | ToVar->setPreviousDecl(Recent); | ||||||||||
3978 | } | ||||||||||
3979 | |||||||||||
3980 | // Import the described template, if any. | ||||||||||
3981 | if (D->getDescribedVarTemplate()) { | ||||||||||
3982 | auto ToVTOrErr = import(D->getDescribedVarTemplate()); | ||||||||||
3983 | if (!ToVTOrErr) | ||||||||||
3984 | return ToVTOrErr.takeError(); | ||||||||||
3985 | } | ||||||||||
3986 | |||||||||||
3987 | if (Error Err = ImportInitializer(D, ToVar)) | ||||||||||
3988 | return std::move(Err); | ||||||||||
3989 | |||||||||||
3990 | if (D->isConstexpr()) | ||||||||||
3991 | ToVar->setConstexpr(true); | ||||||||||
3992 | |||||||||||
3993 | addDeclToContexts(D, ToVar); | ||||||||||
3994 | |||||||||||
3995 | // Import the rest of the chain. I.e. import all subsequent declarations. | ||||||||||
3996 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { | ||||||||||
3997 | ExpectedDecl RedeclOrErr = import(*RedeclIt); | ||||||||||
3998 | if (!RedeclOrErr) | ||||||||||
3999 | return RedeclOrErr.takeError(); | ||||||||||
4000 | } | ||||||||||
4001 | |||||||||||
4002 | return ToVar; | ||||||||||
4003 | } | ||||||||||
4004 | |||||||||||
4005 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { | ||||||||||
4006 | // Parameters are created in the translation unit's context, then moved | ||||||||||
4007 | // into the function declaration's context afterward. | ||||||||||
4008 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); | ||||||||||
4009 | |||||||||||
4010 | Error Err = Error::success(); | ||||||||||
4011 | auto ToDeclName = importChecked(Err, D->getDeclName()); | ||||||||||
4012 | auto ToLocation = importChecked(Err, D->getLocation()); | ||||||||||
4013 | auto ToType = importChecked(Err, D->getType()); | ||||||||||
4014 | if (Err) | ||||||||||
4015 | return std::move(Err); | ||||||||||
4016 | |||||||||||
4017 | // Create the imported parameter. | ||||||||||
4018 | ImplicitParamDecl *ToParm = nullptr; | ||||||||||
4019 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, | ||||||||||
4020 | ToLocation, ToDeclName.getAsIdentifierInfo(), | ||||||||||
4021 | ToType, D->getParameterKind())) | ||||||||||
4022 | return ToParm; | ||||||||||
4023 | return ToParm; | ||||||||||
4024 | } | ||||||||||
4025 | |||||||||||
4026 | Error ASTNodeImporter::ImportDefaultArgOfParmVarDecl( | ||||||||||
4027 | const ParmVarDecl *FromParam, ParmVarDecl *ToParam) { | ||||||||||
4028 | ToParam->setHasInheritedDefaultArg(FromParam->hasInheritedDefaultArg()); | ||||||||||
4029 | ToParam->setKNRPromoted(FromParam->isKNRPromoted()); | ||||||||||
4030 | |||||||||||
4031 | if (FromParam->hasUninstantiatedDefaultArg()) { | ||||||||||
4032 | if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg())) | ||||||||||
4033 | ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr); | ||||||||||
4034 | else | ||||||||||
4035 | return ToDefArgOrErr.takeError(); | ||||||||||
4036 | } else if (FromParam->hasUnparsedDefaultArg()) { | ||||||||||
4037 | ToParam->setUnparsedDefaultArg(); | ||||||||||
4038 | } else if (FromParam->hasDefaultArg()) { | ||||||||||
4039 | if (auto ToDefArgOrErr = import(FromParam->getDefaultArg())) | ||||||||||
4040 | ToParam->setDefaultArg(*ToDefArgOrErr); | ||||||||||
4041 | else | ||||||||||
4042 | return ToDefArgOrErr.takeError(); | ||||||||||
4043 | } | ||||||||||
4044 | |||||||||||
4045 | return Error::success(); | ||||||||||
4046 | } | ||||||||||
4047 | |||||||||||
4048 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { | ||||||||||
4049 | // Parameters are created in the translation unit's context, then moved | ||||||||||
4050 | // into the function declaration's context afterward. | ||||||||||
4051 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); | ||||||||||
4052 | |||||||||||
4053 | Error Err = Error::success(); | ||||||||||
4054 | auto ToDeclName = importChecked(Err, D->getDeclName()); | ||||||||||
4055 | auto ToLocation = importChecked(Err, D->getLocation()); | ||||||||||
4056 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); | ||||||||||
4057 | auto ToType = importChecked(Err, D->getType()); | ||||||||||
4058 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); | ||||||||||
4059 | if (Err) | ||||||||||
4060 | return std::move(Err); | ||||||||||
4061 | |||||||||||
4062 | ParmVarDecl *ToParm; | ||||||||||
4063 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, | ||||||||||
4064 | ToInnerLocStart, ToLocation, | ||||||||||
4065 | ToDeclName.getAsIdentifierInfo(), ToType, | ||||||||||
4066 | ToTypeSourceInfo, D->getStorageClass(), | ||||||||||
4067 | /*DefaultArg*/ nullptr)) | ||||||||||
4068 | return ToParm; | ||||||||||
4069 | |||||||||||
4070 | // Set the default argument. It should be no problem if it was already done. | ||||||||||
4071 | // Do not import the default expression before GetImportedOrCreateDecl call | ||||||||||
4072 | // to avoid possible infinite import loop because circular dependency. | ||||||||||
4073 | if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm)) | ||||||||||
4074 | return std::move(Err); | ||||||||||
4075 | |||||||||||
4076 | if (D->isObjCMethodParameter()) { | ||||||||||
4077 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); | ||||||||||
4078 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); | ||||||||||
4079 | } else { | ||||||||||
4080 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), | ||||||||||
4081 | D->getFunctionScopeIndex()); | ||||||||||
4082 | } | ||||||||||
4083 | |||||||||||
4084 | return ToParm; | ||||||||||
4085 | } | ||||||||||
4086 | |||||||||||
4087 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { | ||||||||||
4088 | // Import the major distinguishing characteristics of a method. | ||||||||||
4089 | DeclContext *DC, *LexicalDC; | ||||||||||
4090 | DeclarationName Name; | ||||||||||
4091 | SourceLocation Loc; | ||||||||||
4092 | NamedDecl *ToD; | ||||||||||
4093 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
4094 | return std::move(Err); | ||||||||||
4095 | if (ToD) | ||||||||||
4096 | return ToD; | ||||||||||
4097 | |||||||||||
4098 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||||||
4099 | for (auto *FoundDecl : FoundDecls) { | ||||||||||
4100 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { | ||||||||||
4101 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) | ||||||||||
4102 | continue; | ||||||||||
4103 | |||||||||||
4104 | // Check return types. | ||||||||||
4105 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), | ||||||||||
4106 | FoundMethod->getReturnType())) { | ||||||||||
4107 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent) | ||||||||||
4108 | << D->isInstanceMethod() << Name << D->getReturnType() | ||||||||||
4109 | << FoundMethod->getReturnType(); | ||||||||||
4110 | Importer.ToDiag(FoundMethod->getLocation(), | ||||||||||
4111 | diag::note_odr_objc_method_here) | ||||||||||
4112 | << D->isInstanceMethod() << Name; | ||||||||||
4113 | |||||||||||
4114 | return make_error<ImportError>(ImportError::NameConflict); | ||||||||||
4115 | } | ||||||||||
4116 | |||||||||||
4117 | // Check the number of parameters. | ||||||||||
4118 | if (D->param_size() != FoundMethod->param_size()) { | ||||||||||
4119 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent) | ||||||||||
4120 | << D->isInstanceMethod() << Name | ||||||||||
4121 | << D->param_size() << FoundMethod->param_size(); | ||||||||||
4122 | Importer.ToDiag(FoundMethod->getLocation(), | ||||||||||
4123 | diag::note_odr_objc_method_here) | ||||||||||
4124 | << D->isInstanceMethod() << Name; | ||||||||||
4125 | |||||||||||
4126 | return make_error<ImportError>(ImportError::NameConflict); | ||||||||||
4127 | } | ||||||||||
4128 | |||||||||||
4129 | // Check parameter types. | ||||||||||
4130 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), | ||||||||||
4131 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); | ||||||||||
4132 | P != PEnd; ++P, ++FoundP) { | ||||||||||
4133 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), | ||||||||||
4134 | (*FoundP)->getType())) { | ||||||||||
4135 | Importer.FromDiag((*P)->getLocation(), | ||||||||||
4136 | diag::warn_odr_objc_method_param_type_inconsistent) | ||||||||||
4137 | << D->isInstanceMethod() << Name | ||||||||||
4138 | << (*P)->getType() << (*FoundP)->getType(); | ||||||||||
4139 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) | ||||||||||
4140 | << (*FoundP)->getType(); | ||||||||||
4141 | |||||||||||
4142 | return make_error<ImportError>(ImportError::NameConflict); | ||||||||||
4143 | } | ||||||||||
4144 | } | ||||||||||
4145 | |||||||||||
4146 | // Check variadic/non-variadic. | ||||||||||
4147 | // Check the number of parameters. | ||||||||||
4148 | if (D->isVariadic() != FoundMethod->isVariadic()) { | ||||||||||
4149 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent) | ||||||||||
4150 | << D->isInstanceMethod() << Name; | ||||||||||
4151 | Importer.ToDiag(FoundMethod->getLocation(), | ||||||||||
4152 | diag::note_odr_objc_method_here) | ||||||||||
4153 | << D->isInstanceMethod() << Name; | ||||||||||
4154 | |||||||||||
4155 | return make_error<ImportError>(ImportError::NameConflict); | ||||||||||
4156 | } | ||||||||||
4157 | |||||||||||
4158 | // FIXME: Any other bits we need to merge? | ||||||||||
4159 | return Importer.MapImported(D, FoundMethod); | ||||||||||
4160 | } | ||||||||||
4161 | } | ||||||||||
4162 | |||||||||||
4163 | Error Err = Error::success(); | ||||||||||
4164 | auto ToEndLoc = importChecked(Err, D->getEndLoc()); | ||||||||||
4165 | auto ToReturnType = importChecked(Err, D->getReturnType()); | ||||||||||
4166 | auto ToReturnTypeSourceInfo = | ||||||||||
4167 | importChecked(Err, D->getReturnTypeSourceInfo()); | ||||||||||
4168 | if (Err) | ||||||||||
4169 | return std::move(Err); | ||||||||||
4170 | |||||||||||
4171 | ObjCMethodDecl *ToMethod; | ||||||||||
4172 | if (GetImportedOrCreateDecl( | ||||||||||
4173 | ToMethod, D, Importer.getToContext(), Loc, ToEndLoc, | ||||||||||
4174 | Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC, | ||||||||||
4175 | D->isInstanceMethod(), D->isVariadic(), D->isPropertyAccessor(), | ||||||||||
4176 | D->isSynthesizedAccessorStub(), D->isImplicit(), D->isDefined(), | ||||||||||
4177 | D->getImplementationControl(), D->hasRelatedResultType())) | ||||||||||
4178 | return ToMethod; | ||||||||||
4179 | |||||||||||
4180 | // FIXME: When we decide to merge method definitions, we'll need to | ||||||||||
4181 | // deal with implicit parameters. | ||||||||||
4182 | |||||||||||
4183 | // Import the parameters | ||||||||||
4184 | SmallVector<ParmVarDecl *, 5> ToParams; | ||||||||||
4185 | for (auto *FromP : D->parameters()) { | ||||||||||
4186 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) | ||||||||||
4187 | ToParams.push_back(*ToPOrErr); | ||||||||||
4188 | else | ||||||||||
4189 | return ToPOrErr.takeError(); | ||||||||||
4190 | } | ||||||||||
4191 | |||||||||||
4192 | // Set the parameters. | ||||||||||
4193 | for (auto *ToParam : ToParams) { | ||||||||||
4194 | ToParam->setOwningFunction(ToMethod); | ||||||||||
4195 | ToMethod->addDeclInternal(ToParam); | ||||||||||
4196 | } | ||||||||||
4197 | |||||||||||
4198 | SmallVector<SourceLocation, 12> FromSelLocs; | ||||||||||
4199 | D->getSelectorLocs(FromSelLocs); | ||||||||||
4200 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); | ||||||||||
4201 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) | ||||||||||
4202 | return std::move(Err); | ||||||||||
4203 | |||||||||||
4204 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); | ||||||||||
4205 | |||||||||||
4206 | ToMethod->setLexicalDeclContext(LexicalDC); | ||||||||||
4207 | LexicalDC->addDeclInternal(ToMethod); | ||||||||||
4208 | |||||||||||
4209 | // Implicit params are declared when Sema encounters the definition but this | ||||||||||
4210 | // never happens when the method is imported. Manually declare the implicit | ||||||||||
4211 | // params now that the MethodDecl knows its class interface. | ||||||||||
4212 | if (D->getSelfDecl()) | ||||||||||
4213 | ToMethod->createImplicitParams(Importer.getToContext(), | ||||||||||
4214 | ToMethod->getClassInterface()); | ||||||||||
4215 | |||||||||||
4216 | return ToMethod; | ||||||||||
4217 | } | ||||||||||
4218 | |||||||||||
4219 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { | ||||||||||
4220 | // Import the major distinguishing characteristics of a category. | ||||||||||
4221 | DeclContext *DC, *LexicalDC; | ||||||||||
4222 | DeclarationName Name; | ||||||||||
4223 | SourceLocation Loc; | ||||||||||
4224 | NamedDecl *ToD; | ||||||||||
4225 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
4226 | return std::move(Err); | ||||||||||
4227 | if (ToD) | ||||||||||
4228 | return ToD; | ||||||||||
4229 | |||||||||||
4230 | Error Err = Error::success(); | ||||||||||
4231 | auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc()); | ||||||||||
4232 | auto ToLocation = importChecked(Err, D->getLocation()); | ||||||||||
4233 | auto ToColonLoc = importChecked(Err, D->getColonLoc()); | ||||||||||
4234 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); | ||||||||||
4235 | if (Err) | ||||||||||
4236 | return std::move(Err); | ||||||||||
4237 | |||||||||||
4238 | ObjCTypeParamDecl *Result; | ||||||||||
4239 | if (GetImportedOrCreateDecl( | ||||||||||
4240 | Result, D, Importer.getToContext(), DC, D->getVariance(), | ||||||||||
4241 | ToVarianceLoc, D->getIndex(), | ||||||||||
4242 | ToLocation, Name.getAsIdentifierInfo(), | ||||||||||
4243 | ToColonLoc, ToTypeSourceInfo)) | ||||||||||
4244 | return Result; | ||||||||||
4245 | |||||||||||
4246 | Result->setLexicalDeclContext(LexicalDC); | ||||||||||
4247 | return Result; | ||||||||||
4248 | } | ||||||||||
4249 | |||||||||||
4250 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { | ||||||||||
4251 | // Import the major distinguishing characteristics of a category. | ||||||||||
4252 | DeclContext *DC, *LexicalDC; | ||||||||||
4253 | DeclarationName Name; | ||||||||||
4254 | SourceLocation Loc; | ||||||||||
4255 | NamedDecl *ToD; | ||||||||||
4256 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
4257 | return std::move(Err); | ||||||||||
4258 | if (ToD) | ||||||||||
4259 | return ToD; | ||||||||||
4260 | |||||||||||
4261 | ObjCInterfaceDecl *ToInterface; | ||||||||||
4262 | if (Error Err = importInto(ToInterface, D->getClassInterface())) | ||||||||||
4263 | return std::move(Err); | ||||||||||
4264 | |||||||||||
4265 | // Determine if we've already encountered this category. | ||||||||||
4266 | ObjCCategoryDecl *MergeWithCategory | ||||||||||
4267 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); | ||||||||||
4268 | ObjCCategoryDecl *ToCategory = MergeWithCategory; | ||||||||||
4269 | if (!ToCategory) { | ||||||||||
4270 | |||||||||||
4271 | Error Err = Error::success(); | ||||||||||
4272 | auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); | ||||||||||
4273 | auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc()); | ||||||||||
4274 | auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc()); | ||||||||||
4275 | auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc()); | ||||||||||
4276 | if (Err) | ||||||||||
4277 | return std::move(Err); | ||||||||||
4278 | |||||||||||
4279 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, | ||||||||||
4280 | ToAtStartLoc, Loc, | ||||||||||
4281 | ToCategoryNameLoc, | ||||||||||
4282 | Name.getAsIdentifierInfo(), ToInterface, | ||||||||||
4283 | /*TypeParamList=*/nullptr, | ||||||||||
4284 | ToIvarLBraceLoc, | ||||||||||
4285 | ToIvarRBraceLoc)) | ||||||||||
4286 | return ToCategory; | ||||||||||
4287 | |||||||||||
4288 | ToCategory->setLexicalDeclContext(LexicalDC); | ||||||||||
4289 | LexicalDC->addDeclInternal(ToCategory); | ||||||||||
4290 | // Import the type parameter list after MapImported, to avoid | ||||||||||
4291 | // loops when bringing in their DeclContext. | ||||||||||
4292 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) | ||||||||||
4293 | ToCategory->setTypeParamList(*PListOrErr); | ||||||||||
4294 | else | ||||||||||
4295 | return PListOrErr.takeError(); | ||||||||||
4296 | |||||||||||
4297 | // Import protocols | ||||||||||
4298 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | ||||||||||
4299 | SmallVector<SourceLocation, 4> ProtocolLocs; | ||||||||||
4300 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc | ||||||||||
4301 | = D->protocol_loc_begin(); | ||||||||||
4302 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), | ||||||||||
4303 | FromProtoEnd = D->protocol_end(); | ||||||||||
4304 | FromProto != FromProtoEnd; | ||||||||||
4305 | ++FromProto, ++FromProtoLoc) { | ||||||||||
4306 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | ||||||||||
4307 | Protocols.push_back(*ToProtoOrErr); | ||||||||||
4308 | else | ||||||||||
4309 | return ToProtoOrErr.takeError(); | ||||||||||
4310 | |||||||||||
4311 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | ||||||||||
4312 | ProtocolLocs.push_back(*ToProtoLocOrErr); | ||||||||||
4313 | else | ||||||||||
4314 | return ToProtoLocOrErr.takeError(); | ||||||||||
4315 | } | ||||||||||
4316 | |||||||||||
4317 | // FIXME: If we're merging, make sure that the protocol list is the same. | ||||||||||
4318 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), | ||||||||||
4319 | ProtocolLocs.data(), Importer.getToContext()); | ||||||||||
4320 | |||||||||||
4321 | } else { | ||||||||||
4322 | Importer.MapImported(D, ToCategory); | ||||||||||
4323 | } | ||||||||||
4324 | |||||||||||
4325 | // Import all of the members of this category. | ||||||||||
4326 | if (Error Err = ImportDeclContext(D)) | ||||||||||
4327 | return std::move(Err); | ||||||||||
4328 | |||||||||||
4329 | // If we have an implementation, import it as well. | ||||||||||
4330 | if (D->getImplementation()) { | ||||||||||
4331 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = | ||||||||||
4332 | import(D->getImplementation())) | ||||||||||
4333 | ToCategory->setImplementation(*ToImplOrErr); | ||||||||||
4334 | else | ||||||||||
4335 | return ToImplOrErr.takeError(); | ||||||||||
4336 | } | ||||||||||
4337 | |||||||||||
4338 | return ToCategory; | ||||||||||
4339 | } | ||||||||||
4340 | |||||||||||
4341 | Error ASTNodeImporter::ImportDefinition( | ||||||||||
4342 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { | ||||||||||
4343 | if (To->getDefinition()) { | ||||||||||
4344 | if (shouldForceImportDeclContext(Kind)) | ||||||||||
4345 | if (Error Err = ImportDeclContext(From)) | ||||||||||
4346 | return Err; | ||||||||||
4347 | return Error::success(); | ||||||||||
4348 | } | ||||||||||
4349 | |||||||||||
4350 | // Start the protocol definition | ||||||||||
4351 | To->startDefinition(); | ||||||||||
4352 | |||||||||||
4353 | // Import protocols | ||||||||||
4354 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | ||||||||||
4355 | SmallVector<SourceLocation, 4> ProtocolLocs; | ||||||||||
4356 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = | ||||||||||
4357 | From->protocol_loc_begin(); | ||||||||||
4358 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), | ||||||||||
4359 | FromProtoEnd = From->protocol_end(); | ||||||||||
4360 | FromProto != FromProtoEnd; | ||||||||||
4361 | ++FromProto, ++FromProtoLoc) { | ||||||||||
4362 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | ||||||||||
4363 | Protocols.push_back(*ToProtoOrErr); | ||||||||||
4364 | else | ||||||||||
4365 | return ToProtoOrErr.takeError(); | ||||||||||
4366 | |||||||||||
4367 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | ||||||||||
4368 | ProtocolLocs.push_back(*ToProtoLocOrErr); | ||||||||||
4369 | else | ||||||||||
4370 | return ToProtoLocOrErr.takeError(); | ||||||||||
4371 | |||||||||||
4372 | } | ||||||||||
4373 | |||||||||||
4374 | // FIXME: If we're merging, make sure that the protocol list is the same. | ||||||||||
4375 | To->setProtocolList(Protocols.data(), Protocols.size(), | ||||||||||
4376 | ProtocolLocs.data(), Importer.getToContext()); | ||||||||||
4377 | |||||||||||
4378 | if (shouldForceImportDeclContext(Kind)) { | ||||||||||
4379 | // Import all of the members of this protocol. | ||||||||||
4380 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | ||||||||||
4381 | return Err; | ||||||||||
4382 | } | ||||||||||
4383 | return Error::success(); | ||||||||||
4384 | } | ||||||||||
4385 | |||||||||||
4386 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { | ||||||||||
4387 | // If this protocol has a definition in the translation unit we're coming | ||||||||||
4388 | // from, but this particular declaration is not that definition, import the | ||||||||||
4389 | // definition and map to that. | ||||||||||
4390 | ObjCProtocolDecl *Definition = D->getDefinition(); | ||||||||||
4391 | if (Definition && Definition != D) { | ||||||||||
4392 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | ||||||||||
4393 | return Importer.MapImported(D, *ImportedDefOrErr); | ||||||||||
4394 | else | ||||||||||
4395 | return ImportedDefOrErr.takeError(); | ||||||||||
4396 | } | ||||||||||
4397 | |||||||||||
4398 | // Import the major distinguishing characteristics of a protocol. | ||||||||||
4399 | DeclContext *DC, *LexicalDC; | ||||||||||
4400 | DeclarationName Name; | ||||||||||
4401 | SourceLocation Loc; | ||||||||||
4402 | NamedDecl *ToD; | ||||||||||
4403 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
4404 | return std::move(Err); | ||||||||||
4405 | if (ToD) | ||||||||||
4406 | return ToD; | ||||||||||
4407 | |||||||||||
4408 | ObjCProtocolDecl *MergeWithProtocol = nullptr; | ||||||||||
4409 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||||||
4410 | for (auto *FoundDecl : FoundDecls) { | ||||||||||
4411 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) | ||||||||||
4412 | continue; | ||||||||||
4413 | |||||||||||
4414 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) | ||||||||||
4415 | break; | ||||||||||
4416 | } | ||||||||||
4417 | |||||||||||
4418 | ObjCProtocolDecl *ToProto = MergeWithProtocol; | ||||||||||
4419 | if (!ToProto) { | ||||||||||
4420 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); | ||||||||||
4421 | if (!ToAtBeginLocOrErr) | ||||||||||
4422 | return ToAtBeginLocOrErr.takeError(); | ||||||||||
4423 | |||||||||||
4424 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, | ||||||||||
4425 | Name.getAsIdentifierInfo(), Loc, | ||||||||||
4426 | *ToAtBeginLocOrErr, | ||||||||||
4427 | /*PrevDecl=*/nullptr)) | ||||||||||
4428 | return ToProto; | ||||||||||
4429 | ToProto->setLexicalDeclContext(LexicalDC); | ||||||||||
4430 | LexicalDC->addDeclInternal(ToProto); | ||||||||||
4431 | } | ||||||||||
4432 | |||||||||||
4433 | Importer.MapImported(D, ToProto); | ||||||||||
4434 | |||||||||||
4435 | if (D->isThisDeclarationADefinition()) | ||||||||||
4436 | if (Error Err = ImportDefinition(D, ToProto)) | ||||||||||
4437 | return std::move(Err); | ||||||||||
4438 | |||||||||||
4439 | return ToProto; | ||||||||||
4440 | } | ||||||||||
4441 | |||||||||||
4442 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { | ||||||||||
4443 | DeclContext *DC, *LexicalDC; | ||||||||||
4444 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | ||||||||||
4445 | return std::move(Err); | ||||||||||
4446 | |||||||||||
4447 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); | ||||||||||
4448 | if (!ExternLocOrErr) | ||||||||||
4449 | return ExternLocOrErr.takeError(); | ||||||||||
4450 | |||||||||||
4451 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); | ||||||||||
4452 | if (!LangLocOrErr) | ||||||||||
4453 | return LangLocOrErr.takeError(); | ||||||||||
4454 | |||||||||||
4455 | bool HasBraces = D->hasBraces(); | ||||||||||
4456 | |||||||||||
4457 | LinkageSpecDecl *ToLinkageSpec; | ||||||||||
4458 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, | ||||||||||
4459 | *ExternLocOrErr, *LangLocOrErr, | ||||||||||
4460 | D->getLanguage(), HasBraces)) | ||||||||||
4461 | return ToLinkageSpec; | ||||||||||
4462 | |||||||||||
4463 | if (HasBraces) { | ||||||||||
4464 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); | ||||||||||
4465 | if (!RBraceLocOrErr) | ||||||||||
4466 | return RBraceLocOrErr.takeError(); | ||||||||||
4467 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); | ||||||||||
4468 | } | ||||||||||
4469 | |||||||||||
4470 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); | ||||||||||
4471 | LexicalDC->addDeclInternal(ToLinkageSpec); | ||||||||||
4472 | |||||||||||
4473 | return ToLinkageSpec; | ||||||||||
4474 | } | ||||||||||
4475 | |||||||||||
4476 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { | ||||||||||
4477 | DeclContext *DC, *LexicalDC; | ||||||||||
4478 | DeclarationName Name; | ||||||||||
4479 | SourceLocation Loc; | ||||||||||
4480 | NamedDecl *ToD = nullptr; | ||||||||||
4481 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
4482 | return std::move(Err); | ||||||||||
4483 | if (ToD) | ||||||||||
4484 | return ToD; | ||||||||||
4485 | |||||||||||
4486 | Error Err = Error::success(); | ||||||||||
4487 | auto ToLoc = importChecked(Err, D->getNameInfo().getLoc()); | ||||||||||
4488 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); | ||||||||||
4489 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | ||||||||||
4490 | if (Err) | ||||||||||
4491 | return std::move(Err); | ||||||||||
4492 | |||||||||||
4493 | DeclarationNameInfo NameInfo(Name, ToLoc); | ||||||||||
4494 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | ||||||||||
4495 | return std::move(Err); | ||||||||||
4496 | |||||||||||
4497 | UsingDecl *ToUsing; | ||||||||||
4498 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, | ||||||||||
4499 | ToUsingLoc, ToQualifierLoc, NameInfo, | ||||||||||
4500 | D->hasTypename())) | ||||||||||
4501 | return ToUsing; | ||||||||||
4502 | |||||||||||
4503 | ToUsing->setLexicalDeclContext(LexicalDC); | ||||||||||
4504 | LexicalDC->addDeclInternal(ToUsing); | ||||||||||
4505 | |||||||||||
4506 | if (NamedDecl *FromPattern = | ||||||||||
4507 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { | ||||||||||
4508 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) | ||||||||||
4509 | Importer.getToContext().setInstantiatedFromUsingDecl( | ||||||||||
4510 | ToUsing, *ToPatternOrErr); | ||||||||||
4511 | else | ||||||||||
4512 | return ToPatternOrErr.takeError(); | ||||||||||
4513 | } | ||||||||||
4514 | |||||||||||
4515 | for (UsingShadowDecl *FromShadow : D->shadows()) { | ||||||||||
4516 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) | ||||||||||
4517 | ToUsing->addShadowDecl(*ToShadowOrErr); | ||||||||||
4518 | else | ||||||||||
4519 | // FIXME: We return error here but the definition is already created | ||||||||||
4520 | // and available with lookups. How to fix this?.. | ||||||||||
4521 | return ToShadowOrErr.takeError(); | ||||||||||
4522 | } | ||||||||||
4523 | return ToUsing; | ||||||||||
4524 | } | ||||||||||
4525 | |||||||||||
4526 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { | ||||||||||
4527 | DeclContext *DC, *LexicalDC; | ||||||||||
4528 | DeclarationName Name; | ||||||||||
4529 | SourceLocation Loc; | ||||||||||
4530 | NamedDecl *ToD = nullptr; | ||||||||||
4531 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
4532 | return std::move(Err); | ||||||||||
4533 | if (ToD) | ||||||||||
4534 | return ToD; | ||||||||||
4535 | |||||||||||
4536 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); | ||||||||||
4537 | if (!ToUsingOrErr) | ||||||||||
4538 | return ToUsingOrErr.takeError(); | ||||||||||
4539 | |||||||||||
4540 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); | ||||||||||
4541 | if (!ToTargetOrErr) | ||||||||||
4542 | return ToTargetOrErr.takeError(); | ||||||||||
4543 | |||||||||||
4544 | UsingShadowDecl *ToShadow; | ||||||||||
4545 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, | ||||||||||
4546 | *ToUsingOrErr, *ToTargetOrErr)) | ||||||||||
4547 | return ToShadow; | ||||||||||
4548 | |||||||||||
4549 | ToShadow->setLexicalDeclContext(LexicalDC); | ||||||||||
4550 | ToShadow->setAccess(D->getAccess()); | ||||||||||
4551 | |||||||||||
4552 | if (UsingShadowDecl *FromPattern = | ||||||||||
4553 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { | ||||||||||
4554 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) | ||||||||||
4555 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( | ||||||||||
4556 | ToShadow, *ToPatternOrErr); | ||||||||||
4557 | else | ||||||||||
4558 | // FIXME: We return error here but the definition is already created | ||||||||||
4559 | // and available with lookups. How to fix this?.. | ||||||||||
4560 | return ToPatternOrErr.takeError(); | ||||||||||
4561 | } | ||||||||||
4562 | |||||||||||
4563 | LexicalDC->addDeclInternal(ToShadow); | ||||||||||
4564 | |||||||||||
4565 | return ToShadow; | ||||||||||
4566 | } | ||||||||||
4567 | |||||||||||
4568 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { | ||||||||||
4569 | DeclContext *DC, *LexicalDC; | ||||||||||
4570 | DeclarationName Name; | ||||||||||
4571 | SourceLocation Loc; | ||||||||||
4572 | NamedDecl *ToD = nullptr; | ||||||||||
4573 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
4574 | return std::move(Err); | ||||||||||
4575 | if (ToD) | ||||||||||
4576 | return ToD; | ||||||||||
4577 | |||||||||||
4578 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); | ||||||||||
4579 | if (!ToComAncestorOrErr) | ||||||||||
4580 | return ToComAncestorOrErr.takeError(); | ||||||||||
4581 | |||||||||||
4582 | Error Err = Error::success(); | ||||||||||
4583 | auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace()); | ||||||||||
4584 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); | ||||||||||
4585 | auto ToNamespaceKeyLocation = | ||||||||||
4586 | importChecked(Err, D->getNamespaceKeyLocation()); | ||||||||||
4587 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | ||||||||||
4588 | auto ToIdentLocation = importChecked(Err, D->getIdentLocation()); | ||||||||||
4589 | if (Err) | ||||||||||
4590 | return std::move(Err); | ||||||||||
4591 | |||||||||||
4592 | UsingDirectiveDecl *ToUsingDir; | ||||||||||
4593 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, | ||||||||||
4594 | ToUsingLoc, | ||||||||||
4595 | ToNamespaceKeyLocation, | ||||||||||
4596 | ToQualifierLoc, | ||||||||||
4597 | ToIdentLocation, | ||||||||||
4598 | ToNominatedNamespace, *ToComAncestorOrErr)) | ||||||||||
4599 | return ToUsingDir; | ||||||||||
4600 | |||||||||||
4601 | ToUsingDir->setLexicalDeclContext(LexicalDC); | ||||||||||
4602 | LexicalDC->addDeclInternal(ToUsingDir); | ||||||||||
4603 | |||||||||||
4604 | return ToUsingDir; | ||||||||||
4605 | } | ||||||||||
4606 | |||||||||||
4607 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( | ||||||||||
4608 | UnresolvedUsingValueDecl *D) { | ||||||||||
4609 | DeclContext *DC, *LexicalDC; | ||||||||||
4610 | DeclarationName Name; | ||||||||||
4611 | SourceLocation Loc; | ||||||||||
4612 | NamedDecl *ToD = nullptr; | ||||||||||
4613 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
4614 | return std::move(Err); | ||||||||||
4615 | if (ToD) | ||||||||||
4616 | return ToD; | ||||||||||
4617 | |||||||||||
4618 | Error Err = Error::success(); | ||||||||||
4619 | auto ToLoc = importChecked(Err, D->getNameInfo().getLoc()); | ||||||||||
4620 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); | ||||||||||
4621 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | ||||||||||
4622 | auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc()); | ||||||||||
4623 | if (Err) | ||||||||||
4624 | return std::move(Err); | ||||||||||
4625 | |||||||||||
4626 | DeclarationNameInfo NameInfo(Name, ToLoc); | ||||||||||
4627 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | ||||||||||
4628 | return std::move(Err); | ||||||||||
4629 | |||||||||||
4630 | UnresolvedUsingValueDecl *ToUsingValue; | ||||||||||
4631 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, | ||||||||||
4632 | ToUsingLoc, ToQualifierLoc, NameInfo, | ||||||||||
4633 | ToEllipsisLoc)) | ||||||||||
4634 | return ToUsingValue; | ||||||||||
4635 | |||||||||||
4636 | ToUsingValue->setAccess(D->getAccess()); | ||||||||||
4637 | ToUsingValue->setLexicalDeclContext(LexicalDC); | ||||||||||
4638 | LexicalDC->addDeclInternal(ToUsingValue); | ||||||||||
4639 | |||||||||||
4640 | return ToUsingValue; | ||||||||||
4641 | } | ||||||||||
4642 | |||||||||||
4643 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( | ||||||||||
4644 | UnresolvedUsingTypenameDecl *D) { | ||||||||||
4645 | DeclContext *DC, *LexicalDC; | ||||||||||
4646 | DeclarationName Name; | ||||||||||
4647 | SourceLocation Loc; | ||||||||||
4648 | NamedDecl *ToD = nullptr; | ||||||||||
4649 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
4650 | return std::move(Err); | ||||||||||
4651 | if (ToD) | ||||||||||
4652 | return ToD; | ||||||||||
4653 | |||||||||||
4654 | Error Err = Error::success(); | ||||||||||
4655 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); | ||||||||||
4656 | auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc()); | ||||||||||
4657 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); | ||||||||||
4658 | auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc()); | ||||||||||
4659 | if (Err) | ||||||||||
4660 | return std::move(Err); | ||||||||||
4661 | |||||||||||
4662 | UnresolvedUsingTypenameDecl *ToUsing; | ||||||||||
4663 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, | ||||||||||
4664 | ToUsingLoc, ToTypenameLoc, | ||||||||||
4665 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) | ||||||||||
4666 | return ToUsing; | ||||||||||
4667 | |||||||||||
4668 | ToUsing->setAccess(D->getAccess()); | ||||||||||
4669 | ToUsing->setLexicalDeclContext(LexicalDC); | ||||||||||
4670 | LexicalDC->addDeclInternal(ToUsing); | ||||||||||
4671 | |||||||||||
4672 | return ToUsing; | ||||||||||
4673 | } | ||||||||||
4674 | |||||||||||
4675 | ExpectedDecl ASTNodeImporter::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) { | ||||||||||
4676 | Decl* ToD = nullptr; | ||||||||||
4677 | switch (D->getBuiltinTemplateKind()) { | ||||||||||
4678 | case BuiltinTemplateKind::BTK__make_integer_seq: | ||||||||||
4679 | ToD = Importer.getToContext().getMakeIntegerSeqDecl(); | ||||||||||
4680 | break; | ||||||||||
4681 | case BuiltinTemplateKind::BTK__type_pack_element: | ||||||||||
4682 | ToD = Importer.getToContext().getTypePackElementDecl(); | ||||||||||
4683 | break; | ||||||||||
4684 | } | ||||||||||
4685 | assert(ToD && "BuiltinTemplateDecl of unsupported kind!")((ToD && "BuiltinTemplateDecl of unsupported kind!") ? static_cast<void> (0) : __assert_fail ("ToD && \"BuiltinTemplateDecl of unsupported kind!\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 4685, __PRETTY_FUNCTION__)); | ||||||||||
4686 | Importer.MapImported(D, ToD); | ||||||||||
4687 | return ToD; | ||||||||||
4688 | } | ||||||||||
4689 | |||||||||||
4690 | Error ASTNodeImporter::ImportDefinition( | ||||||||||
4691 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { | ||||||||||
4692 | if (To->getDefinition()) { | ||||||||||
4693 | // Check consistency of superclass. | ||||||||||
4694 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); | ||||||||||
4695 | if (FromSuper) { | ||||||||||
4696 | if (auto FromSuperOrErr = import(FromSuper)) | ||||||||||
4697 | FromSuper = *FromSuperOrErr; | ||||||||||
4698 | else | ||||||||||
4699 | return FromSuperOrErr.takeError(); | ||||||||||
4700 | } | ||||||||||
4701 | |||||||||||
4702 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); | ||||||||||
4703 | if ((bool)FromSuper != (bool)ToSuper || | ||||||||||
4704 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { | ||||||||||
4705 | Importer.ToDiag(To->getLocation(), | ||||||||||
4706 | diag::warn_odr_objc_superclass_inconsistent) | ||||||||||
4707 | << To->getDeclName(); | ||||||||||
4708 | if (ToSuper) | ||||||||||
4709 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) | ||||||||||
4710 | << To->getSuperClass()->getDeclName(); | ||||||||||
4711 | else | ||||||||||
4712 | Importer.ToDiag(To->getLocation(), | ||||||||||
4713 | diag::note_odr_objc_missing_superclass); | ||||||||||
4714 | if (From->getSuperClass()) | ||||||||||
4715 | Importer.FromDiag(From->getSuperClassLoc(), | ||||||||||
4716 | diag::note_odr_objc_superclass) | ||||||||||
4717 | << From->getSuperClass()->getDeclName(); | ||||||||||
4718 | else | ||||||||||
4719 | Importer.FromDiag(From->getLocation(), | ||||||||||
4720 | diag::note_odr_objc_missing_superclass); | ||||||||||
4721 | } | ||||||||||
4722 | |||||||||||
4723 | if (shouldForceImportDeclContext(Kind)) | ||||||||||
4724 | if (Error Err = ImportDeclContext(From)) | ||||||||||
4725 | return Err; | ||||||||||
4726 | return Error::success(); | ||||||||||
4727 | } | ||||||||||
4728 | |||||||||||
4729 | // Start the definition. | ||||||||||
4730 | To->startDefinition(); | ||||||||||
4731 | |||||||||||
4732 | // If this class has a superclass, import it. | ||||||||||
4733 | if (From->getSuperClass()) { | ||||||||||
4734 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) | ||||||||||
4735 | To->setSuperClass(*SuperTInfoOrErr); | ||||||||||
4736 | else | ||||||||||
4737 | return SuperTInfoOrErr.takeError(); | ||||||||||
4738 | } | ||||||||||
4739 | |||||||||||
4740 | // Import protocols | ||||||||||
4741 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | ||||||||||
4742 | SmallVector<SourceLocation, 4> ProtocolLocs; | ||||||||||
4743 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = | ||||||||||
4744 | From->protocol_loc_begin(); | ||||||||||
4745 | |||||||||||
4746 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), | ||||||||||
4747 | FromProtoEnd = From->protocol_end(); | ||||||||||
4748 | FromProto != FromProtoEnd; | ||||||||||
4749 | ++FromProto, ++FromProtoLoc) { | ||||||||||
4750 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | ||||||||||
4751 | Protocols.push_back(*ToProtoOrErr); | ||||||||||
4752 | else | ||||||||||
4753 | return ToProtoOrErr.takeError(); | ||||||||||
4754 | |||||||||||
4755 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | ||||||||||
4756 | ProtocolLocs.push_back(*ToProtoLocOrErr); | ||||||||||
4757 | else | ||||||||||
4758 | return ToProtoLocOrErr.takeError(); | ||||||||||
4759 | |||||||||||
4760 | } | ||||||||||
4761 | |||||||||||
4762 | // FIXME: If we're merging, make sure that the protocol list is the same. | ||||||||||
4763 | To->setProtocolList(Protocols.data(), Protocols.size(), | ||||||||||
4764 | ProtocolLocs.data(), Importer.getToContext()); | ||||||||||
4765 | |||||||||||
4766 | // Import categories. When the categories themselves are imported, they'll | ||||||||||
4767 | // hook themselves into this interface. | ||||||||||
4768 | for (auto *Cat : From->known_categories()) { | ||||||||||
4769 | auto ToCatOrErr = import(Cat); | ||||||||||
4770 | if (!ToCatOrErr) | ||||||||||
4771 | return ToCatOrErr.takeError(); | ||||||||||
4772 | } | ||||||||||
4773 | |||||||||||
4774 | // If we have an @implementation, import it as well. | ||||||||||
4775 | if (From->getImplementation()) { | ||||||||||
4776 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = | ||||||||||
4777 | import(From->getImplementation())) | ||||||||||
4778 | To->setImplementation(*ToImplOrErr); | ||||||||||
4779 | else | ||||||||||
4780 | return ToImplOrErr.takeError(); | ||||||||||
4781 | } | ||||||||||
4782 | |||||||||||
4783 | // Import all of the members of this class. | ||||||||||
4784 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | ||||||||||
4785 | return Err; | ||||||||||
4786 | |||||||||||
4787 | return Error::success(); | ||||||||||
4788 | } | ||||||||||
4789 | |||||||||||
4790 | Expected<ObjCTypeParamList *> | ||||||||||
4791 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { | ||||||||||
4792 | if (!list) | ||||||||||
4793 | return nullptr; | ||||||||||
4794 | |||||||||||
4795 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; | ||||||||||
4796 | for (auto *fromTypeParam : *list) { | ||||||||||
4797 | if (auto toTypeParamOrErr = import(fromTypeParam)) | ||||||||||
4798 | toTypeParams.push_back(*toTypeParamOrErr); | ||||||||||
4799 | else | ||||||||||
4800 | return toTypeParamOrErr.takeError(); | ||||||||||
4801 | } | ||||||||||
4802 | |||||||||||
4803 | auto LAngleLocOrErr = import(list->getLAngleLoc()); | ||||||||||
4804 | if (!LAngleLocOrErr) | ||||||||||
4805 | return LAngleLocOrErr.takeError(); | ||||||||||
4806 | |||||||||||
4807 | auto RAngleLocOrErr = import(list->getRAngleLoc()); | ||||||||||
4808 | if (!RAngleLocOrErr) | ||||||||||
4809 | return RAngleLocOrErr.takeError(); | ||||||||||
4810 | |||||||||||
4811 | return ObjCTypeParamList::create(Importer.getToContext(), | ||||||||||
4812 | *LAngleLocOrErr, | ||||||||||
4813 | toTypeParams, | ||||||||||
4814 | *RAngleLocOrErr); | ||||||||||
4815 | } | ||||||||||
4816 | |||||||||||
4817 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { | ||||||||||
4818 | // If this class has a definition in the translation unit we're coming from, | ||||||||||
4819 | // but this particular declaration is not that definition, import the | ||||||||||
4820 | // definition and map to that. | ||||||||||
4821 | ObjCInterfaceDecl *Definition = D->getDefinition(); | ||||||||||
4822 | if (Definition && Definition != D) { | ||||||||||
4823 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | ||||||||||
4824 | return Importer.MapImported(D, *ImportedDefOrErr); | ||||||||||
4825 | else | ||||||||||
4826 | return ImportedDefOrErr.takeError(); | ||||||||||
4827 | } | ||||||||||
4828 | |||||||||||
4829 | // Import the major distinguishing characteristics of an @interface. | ||||||||||
4830 | DeclContext *DC, *LexicalDC; | ||||||||||
4831 | DeclarationName Name; | ||||||||||
4832 | SourceLocation Loc; | ||||||||||
4833 | NamedDecl *ToD; | ||||||||||
4834 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
4835 | return std::move(Err); | ||||||||||
4836 | if (ToD) | ||||||||||
4837 | return ToD; | ||||||||||
4838 | |||||||||||
4839 | // Look for an existing interface with the same name. | ||||||||||
4840 | ObjCInterfaceDecl *MergeWithIface = nullptr; | ||||||||||
4841 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||||||
4842 | for (auto *FoundDecl : FoundDecls) { | ||||||||||
4843 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) | ||||||||||
4844 | continue; | ||||||||||
4845 | |||||||||||
4846 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) | ||||||||||
4847 | break; | ||||||||||
4848 | } | ||||||||||
4849 | |||||||||||
4850 | // Create an interface declaration, if one does not already exist. | ||||||||||
4851 | ObjCInterfaceDecl *ToIface = MergeWithIface; | ||||||||||
4852 | if (!ToIface) { | ||||||||||
4853 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); | ||||||||||
4854 | if (!AtBeginLocOrErr) | ||||||||||
4855 | return AtBeginLocOrErr.takeError(); | ||||||||||
4856 | |||||||||||
4857 | if (GetImportedOrCreateDecl( | ||||||||||
4858 | ToIface, D, Importer.getToContext(), DC, | ||||||||||
4859 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), | ||||||||||
4860 | /*TypeParamList=*/nullptr, | ||||||||||
4861 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) | ||||||||||
4862 | return ToIface; | ||||||||||
4863 | ToIface->setLexicalDeclContext(LexicalDC); | ||||||||||
4864 | LexicalDC->addDeclInternal(ToIface); | ||||||||||
4865 | } | ||||||||||
4866 | Importer.MapImported(D, ToIface); | ||||||||||
4867 | // Import the type parameter list after MapImported, to avoid | ||||||||||
4868 | // loops when bringing in their DeclContext. | ||||||||||
4869 | if (auto ToPListOrErr = | ||||||||||
4870 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) | ||||||||||
4871 | ToIface->setTypeParamList(*ToPListOrErr); | ||||||||||
4872 | else | ||||||||||
4873 | return ToPListOrErr.takeError(); | ||||||||||
4874 | |||||||||||
4875 | if (D->isThisDeclarationADefinition()) | ||||||||||
4876 | if (Error Err = ImportDefinition(D, ToIface)) | ||||||||||
4877 | return std::move(Err); | ||||||||||
4878 | |||||||||||
4879 | return ToIface; | ||||||||||
4880 | } | ||||||||||
4881 | |||||||||||
4882 | ExpectedDecl | ||||||||||
4883 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { | ||||||||||
4884 | ObjCCategoryDecl *Category; | ||||||||||
4885 | if (Error Err = importInto(Category, D->getCategoryDecl())) | ||||||||||
4886 | return std::move(Err); | ||||||||||
4887 | |||||||||||
4888 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); | ||||||||||
4889 | if (!ToImpl) { | ||||||||||
4890 | DeclContext *DC, *LexicalDC; | ||||||||||
4891 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | ||||||||||
4892 | return std::move(Err); | ||||||||||
4893 | |||||||||||
4894 | Error Err = Error::success(); | ||||||||||
4895 | auto ToLocation = importChecked(Err, D->getLocation()); | ||||||||||
4896 | auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); | ||||||||||
4897 | auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc()); | ||||||||||
4898 | if (Err) | ||||||||||
4899 | return std::move(Err); | ||||||||||
4900 | |||||||||||
4901 | if (GetImportedOrCreateDecl( | ||||||||||
4902 | ToImpl, D, Importer.getToContext(), DC, | ||||||||||
4903 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), | ||||||||||
4904 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) | ||||||||||
4905 | return ToImpl; | ||||||||||
4906 | |||||||||||
4907 | ToImpl->setLexicalDeclContext(LexicalDC); | ||||||||||
4908 | LexicalDC->addDeclInternal(ToImpl); | ||||||||||
4909 | Category->setImplementation(ToImpl); | ||||||||||
4910 | } | ||||||||||
4911 | |||||||||||
4912 | Importer.MapImported(D, ToImpl); | ||||||||||
4913 | if (Error Err = ImportDeclContext(D)) | ||||||||||
4914 | return std::move(Err); | ||||||||||
4915 | |||||||||||
4916 | return ToImpl; | ||||||||||
4917 | } | ||||||||||
4918 | |||||||||||
4919 | ExpectedDecl | ||||||||||
4920 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { | ||||||||||
4921 | // Find the corresponding interface. | ||||||||||
4922 | ObjCInterfaceDecl *Iface; | ||||||||||
4923 | if (Error Err = importInto(Iface, D->getClassInterface())) | ||||||||||
4924 | return std::move(Err); | ||||||||||
4925 | |||||||||||
4926 | // Import the superclass, if any. | ||||||||||
4927 | ObjCInterfaceDecl *Super; | ||||||||||
4928 | if (Error Err = importInto(Super, D->getSuperClass())) | ||||||||||
4929 | return std::move(Err); | ||||||||||
4930 | |||||||||||
4931 | ObjCImplementationDecl *Impl = Iface->getImplementation(); | ||||||||||
4932 | if (!Impl) { | ||||||||||
4933 | // We haven't imported an implementation yet. Create a new @implementation | ||||||||||
4934 | // now. | ||||||||||
4935 | DeclContext *DC, *LexicalDC; | ||||||||||
4936 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | ||||||||||
4937 | return std::move(Err); | ||||||||||
4938 | |||||||||||
4939 | Error Err = Error::success(); | ||||||||||
4940 | auto ToLocation = importChecked(Err, D->getLocation()); | ||||||||||
4941 | auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); | ||||||||||
4942 | auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc()); | ||||||||||
4943 | auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc()); | ||||||||||
4944 | auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc()); | ||||||||||
4945 | if (Err) | ||||||||||
4946 | return std::move(Err); | ||||||||||
4947 | |||||||||||
4948 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), | ||||||||||
4949 | DC, Iface, Super, | ||||||||||
4950 | ToLocation, | ||||||||||
4951 | ToAtStartLoc, | ||||||||||
4952 | ToSuperClassLoc, | ||||||||||
4953 | ToIvarLBraceLoc, | ||||||||||
4954 | ToIvarRBraceLoc)) | ||||||||||
4955 | return Impl; | ||||||||||
4956 | |||||||||||
4957 | Impl->setLexicalDeclContext(LexicalDC); | ||||||||||
4958 | |||||||||||
4959 | // Associate the implementation with the class it implements. | ||||||||||
4960 | Iface->setImplementation(Impl); | ||||||||||
4961 | Importer.MapImported(D, Iface->getImplementation()); | ||||||||||
4962 | } else { | ||||||||||
4963 | Importer.MapImported(D, Iface->getImplementation()); | ||||||||||
4964 | |||||||||||
4965 | // Verify that the existing @implementation has the same superclass. | ||||||||||
4966 | if ((Super && !Impl->getSuperClass()) || | ||||||||||
4967 | (!Super && Impl->getSuperClass()) || | ||||||||||
4968 | (Super && Impl->getSuperClass() && | ||||||||||
4969 | !declaresSameEntity(Super->getCanonicalDecl(), | ||||||||||
4970 | Impl->getSuperClass()))) { | ||||||||||
4971 | Importer.ToDiag(Impl->getLocation(), | ||||||||||
4972 | diag::warn_odr_objc_superclass_inconsistent) | ||||||||||
4973 | << Iface->getDeclName(); | ||||||||||
4974 | // FIXME: It would be nice to have the location of the superclass | ||||||||||
4975 | // below. | ||||||||||
4976 | if (Impl->getSuperClass()) | ||||||||||
4977 | Importer.ToDiag(Impl->getLocation(), | ||||||||||
4978 | diag::note_odr_objc_superclass) | ||||||||||
4979 | << Impl->getSuperClass()->getDeclName(); | ||||||||||
4980 | else | ||||||||||
4981 | Importer.ToDiag(Impl->getLocation(), | ||||||||||
4982 | diag::note_odr_objc_missing_superclass); | ||||||||||
4983 | if (D->getSuperClass()) | ||||||||||
4984 | Importer.FromDiag(D->getLocation(), | ||||||||||
4985 | diag::note_odr_objc_superclass) | ||||||||||
4986 | << D->getSuperClass()->getDeclName(); | ||||||||||
4987 | else | ||||||||||
4988 | Importer.FromDiag(D->getLocation(), | ||||||||||
4989 | diag::note_odr_objc_missing_superclass); | ||||||||||
4990 | |||||||||||
4991 | return make_error<ImportError>(ImportError::NameConflict); | ||||||||||
4992 | } | ||||||||||
4993 | } | ||||||||||
4994 | |||||||||||
4995 | // Import all of the members of this @implementation. | ||||||||||
4996 | if (Error Err = ImportDeclContext(D)) | ||||||||||
4997 | return std::move(Err); | ||||||||||
4998 | |||||||||||
4999 | return Impl; | ||||||||||
5000 | } | ||||||||||
5001 | |||||||||||
5002 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { | ||||||||||
5003 | // Import the major distinguishing characteristics of an @property. | ||||||||||
5004 | DeclContext *DC, *LexicalDC; | ||||||||||
5005 | DeclarationName Name; | ||||||||||
5006 | SourceLocation Loc; | ||||||||||
5007 | NamedDecl *ToD; | ||||||||||
5008 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
5009 | return std::move(Err); | ||||||||||
5010 | if (ToD) | ||||||||||
5011 | return ToD; | ||||||||||
5012 | |||||||||||
5013 | // Check whether we have already imported this property. | ||||||||||
5014 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||||||
5015 | for (auto *FoundDecl : FoundDecls) { | ||||||||||
5016 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { | ||||||||||
5017 | // Check property types. | ||||||||||
5018 | if (!Importer.IsStructurallyEquivalent(D->getType(), | ||||||||||
5019 | FoundProp->getType())) { | ||||||||||
5020 | Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent) | ||||||||||
5021 | << Name << D->getType() << FoundProp->getType(); | ||||||||||
5022 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) | ||||||||||
5023 | << FoundProp->getType(); | ||||||||||
5024 | |||||||||||
5025 | return make_error<ImportError>(ImportError::NameConflict); | ||||||||||
5026 | } | ||||||||||
5027 | |||||||||||
5028 | // FIXME: Check property attributes, getters, setters, etc.? | ||||||||||
5029 | |||||||||||
5030 | // Consider these properties to be equivalent. | ||||||||||
5031 | Importer.MapImported(D, FoundProp); | ||||||||||
5032 | return FoundProp; | ||||||||||
5033 | } | ||||||||||
5034 | } | ||||||||||
5035 | |||||||||||
5036 | Error Err = Error::success(); | ||||||||||
5037 | auto ToType = importChecked(Err, D->getType()); | ||||||||||
5038 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); | ||||||||||
5039 | auto ToAtLoc = importChecked(Err, D->getAtLoc()); | ||||||||||
5040 | auto ToLParenLoc = importChecked(Err, D->getLParenLoc()); | ||||||||||
5041 | if (Err) | ||||||||||
5042 | return std::move(Err); | ||||||||||
5043 | |||||||||||
5044 | // Create the new property. | ||||||||||
5045 | ObjCPropertyDecl *ToProperty; | ||||||||||
5046 | if (GetImportedOrCreateDecl( | ||||||||||
5047 | ToProperty, D, Importer.getToContext(), DC, Loc, | ||||||||||
5048 | Name.getAsIdentifierInfo(), ToAtLoc, | ||||||||||
5049 | ToLParenLoc, ToType, | ||||||||||
5050 | ToTypeSourceInfo, D->getPropertyImplementation())) | ||||||||||
5051 | return ToProperty; | ||||||||||
5052 | |||||||||||
5053 | auto ToGetterName = importChecked(Err, D->getGetterName()); | ||||||||||
5054 | auto ToSetterName = importChecked(Err, D->getSetterName()); | ||||||||||
5055 | auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc()); | ||||||||||
5056 | auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc()); | ||||||||||
5057 | auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl()); | ||||||||||
5058 | auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl()); | ||||||||||
5059 | auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl()); | ||||||||||
5060 | if (Err) | ||||||||||
5061 | return std::move(Err); | ||||||||||
5062 | |||||||||||
5063 | ToProperty->setLexicalDeclContext(LexicalDC); | ||||||||||
5064 | LexicalDC->addDeclInternal(ToProperty); | ||||||||||
5065 | |||||||||||
5066 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); | ||||||||||
5067 | ToProperty->setPropertyAttributesAsWritten( | ||||||||||
5068 | D->getPropertyAttributesAsWritten()); | ||||||||||
5069 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); | ||||||||||
5070 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); | ||||||||||
5071 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); | ||||||||||
5072 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); | ||||||||||
5073 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); | ||||||||||
5074 | return ToProperty; | ||||||||||
5075 | } | ||||||||||
5076 | |||||||||||
5077 | ExpectedDecl | ||||||||||
5078 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { | ||||||||||
5079 | ObjCPropertyDecl *Property; | ||||||||||
5080 | if (Error Err = importInto(Property, D->getPropertyDecl())) | ||||||||||
5081 | return std::move(Err); | ||||||||||
5082 | |||||||||||
5083 | DeclContext *DC, *LexicalDC; | ||||||||||
5084 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | ||||||||||
5085 | return std::move(Err); | ||||||||||
5086 | |||||||||||
5087 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); | ||||||||||
5088 | |||||||||||
5089 | // Import the ivar (for an @synthesize). | ||||||||||
5090 | ObjCIvarDecl *Ivar = nullptr; | ||||||||||
5091 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) | ||||||||||
5092 | return std::move(Err); | ||||||||||
5093 | |||||||||||
5094 | ObjCPropertyImplDecl *ToImpl | ||||||||||
5095 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), | ||||||||||
5096 | Property->getQueryKind()); | ||||||||||
5097 | if (!ToImpl) { | ||||||||||
5098 | |||||||||||
5099 | Error Err = Error::success(); | ||||||||||
5100 | auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); | ||||||||||
5101 | auto ToLocation = importChecked(Err, D->getLocation()); | ||||||||||
5102 | auto ToPropertyIvarDeclLoc = | ||||||||||
5103 | importChecked(Err, D->getPropertyIvarDeclLoc()); | ||||||||||
5104 | if (Err) | ||||||||||
5105 | return std::move(Err); | ||||||||||
5106 | |||||||||||
5107 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, | ||||||||||
5108 | ToBeginLoc, | ||||||||||
5109 | ToLocation, Property, | ||||||||||
5110 | D->getPropertyImplementation(), Ivar, | ||||||||||
5111 | ToPropertyIvarDeclLoc)) | ||||||||||
5112 | return ToImpl; | ||||||||||
5113 | |||||||||||
5114 | ToImpl->setLexicalDeclContext(LexicalDC); | ||||||||||
5115 | LexicalDC->addDeclInternal(ToImpl); | ||||||||||
5116 | } else { | ||||||||||
5117 | // Check that we have the same kind of property implementation (@synthesize | ||||||||||
5118 | // vs. @dynamic). | ||||||||||
5119 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { | ||||||||||
5120 | Importer.ToDiag(ToImpl->getLocation(), | ||||||||||
5121 | diag::warn_odr_objc_property_impl_kind_inconsistent) | ||||||||||
5122 | << Property->getDeclName() | ||||||||||
5123 | << (ToImpl->getPropertyImplementation() | ||||||||||
5124 | == ObjCPropertyImplDecl::Dynamic); | ||||||||||
5125 | Importer.FromDiag(D->getLocation(), | ||||||||||
5126 | diag::note_odr_objc_property_impl_kind) | ||||||||||
5127 | << D->getPropertyDecl()->getDeclName() | ||||||||||
5128 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); | ||||||||||
5129 | |||||||||||
5130 | return make_error<ImportError>(ImportError::NameConflict); | ||||||||||
5131 | } | ||||||||||
5132 | |||||||||||
5133 | // For @synthesize, check that we have the same | ||||||||||
5134 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && | ||||||||||
5135 | Ivar != ToImpl->getPropertyIvarDecl()) { | ||||||||||
5136 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), | ||||||||||
5137 | diag::warn_odr_objc_synthesize_ivar_inconsistent) | ||||||||||
5138 | << Property->getDeclName() | ||||||||||
5139 | << ToImpl->getPropertyIvarDecl()->getDeclName() | ||||||||||
5140 | << Ivar->getDeclName(); | ||||||||||
5141 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), | ||||||||||
5142 | diag::note_odr_objc_synthesize_ivar_here) | ||||||||||
5143 | << D->getPropertyIvarDecl()->getDeclName(); | ||||||||||
5144 | |||||||||||
5145 | return make_error<ImportError>(ImportError::NameConflict); | ||||||||||
5146 | } | ||||||||||
5147 | |||||||||||
5148 | // Merge the existing implementation with the new implementation. | ||||||||||
5149 | Importer.MapImported(D, ToImpl); | ||||||||||
5150 | } | ||||||||||
5151 | |||||||||||
5152 | return ToImpl; | ||||||||||
5153 | } | ||||||||||
5154 | |||||||||||
5155 | ExpectedDecl | ||||||||||
5156 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { | ||||||||||
5157 | // For template arguments, we adopt the translation unit as our declaration | ||||||||||
5158 | // context. This context will be fixed when the actual template declaration | ||||||||||
5159 | // is created. | ||||||||||
5160 | |||||||||||
5161 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | ||||||||||
5162 | if (!BeginLocOrErr) | ||||||||||
5163 | return BeginLocOrErr.takeError(); | ||||||||||
5164 | |||||||||||
5165 | ExpectedSLoc LocationOrErr = import(D->getLocation()); | ||||||||||
5166 | if (!LocationOrErr) | ||||||||||
5167 | return LocationOrErr.takeError(); | ||||||||||
5168 | |||||||||||
5169 | TemplateTypeParmDecl *ToD = nullptr; | ||||||||||
5170 | if (GetImportedOrCreateDecl( | ||||||||||
5171 | ToD, D, Importer.getToContext(), | ||||||||||
5172 | Importer.getToContext().getTranslationUnitDecl(), | ||||||||||
5173 | *BeginLocOrErr, *LocationOrErr, | ||||||||||
5174 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), | ||||||||||
5175 | D->wasDeclaredWithTypename(), D->isParameterPack(), | ||||||||||
5176 | D->hasTypeConstraint())) | ||||||||||
5177 | return ToD; | ||||||||||
5178 | |||||||||||
5179 | // Import the type-constraint | ||||||||||
5180 | if (const TypeConstraint *TC = D->getTypeConstraint()) { | ||||||||||
5181 | |||||||||||
5182 | Error Err = Error::success(); | ||||||||||
5183 | auto ToNNS = importChecked(Err, TC->getNestedNameSpecifierLoc()); | ||||||||||
5184 | auto ToName = importChecked(Err, TC->getConceptNameInfo().getName()); | ||||||||||
5185 | auto ToNameLoc = importChecked(Err, TC->getConceptNameInfo().getLoc()); | ||||||||||
5186 | auto ToFoundDecl = importChecked(Err, TC->getFoundDecl()); | ||||||||||
5187 | auto ToNamedConcept = importChecked(Err, TC->getNamedConcept()); | ||||||||||
5188 | auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint()); | ||||||||||
5189 | if (Err) | ||||||||||
5190 | return std::move(Err); | ||||||||||
5191 | |||||||||||
5192 | TemplateArgumentListInfo ToTAInfo; | ||||||||||
5193 | const auto *ASTTemplateArgs = TC->getTemplateArgsAsWritten(); | ||||||||||
5194 | if (ASTTemplateArgs) | ||||||||||
5195 | if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, | ||||||||||
5196 | ToTAInfo)) | ||||||||||
5197 | return std::move(Err); | ||||||||||
5198 | |||||||||||
5199 | ToD->setTypeConstraint(ToNNS, DeclarationNameInfo(ToName, ToNameLoc), | ||||||||||
5200 | ToFoundDecl, ToNamedConcept, | ||||||||||
5201 | ASTTemplateArgs ? | ||||||||||
5202 | ASTTemplateArgumentListInfo::Create(Importer.getToContext(), | ||||||||||
5203 | ToTAInfo) : nullptr, | ||||||||||
5204 | ToIDC); | ||||||||||
5205 | } | ||||||||||
5206 | |||||||||||
5207 | if (D->hasDefaultArgument()) { | ||||||||||
5208 | Expected<TypeSourceInfo *> ToDefaultArgOrErr = | ||||||||||
5209 | import(D->getDefaultArgumentInfo()); | ||||||||||
5210 | if (!ToDefaultArgOrErr) | ||||||||||
5211 | return ToDefaultArgOrErr.takeError(); | ||||||||||
5212 | ToD->setDefaultArgument(*ToDefaultArgOrErr); | ||||||||||
5213 | } | ||||||||||
5214 | |||||||||||
5215 | return ToD; | ||||||||||
5216 | } | ||||||||||
5217 | |||||||||||
5218 | ExpectedDecl | ||||||||||
5219 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { | ||||||||||
5220 | |||||||||||
5221 | Error Err = Error::success(); | ||||||||||
5222 | auto ToDeclName = importChecked(Err, D->getDeclName()); | ||||||||||
5223 | auto ToLocation = importChecked(Err, D->getLocation()); | ||||||||||
5224 | auto ToType = importChecked(Err, D->getType()); | ||||||||||
5225 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); | ||||||||||
5226 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); | ||||||||||
5227 | if (Err) | ||||||||||
5228 | return std::move(Err); | ||||||||||
5229 | |||||||||||
5230 | NonTypeTemplateParmDecl *ToD = nullptr; | ||||||||||
5231 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), | ||||||||||
5232 | Importer.getToContext().getTranslationUnitDecl(), | ||||||||||
5233 | ToInnerLocStart, ToLocation, D->getDepth(), | ||||||||||
5234 | D->getPosition(), | ||||||||||
5235 | ToDeclName.getAsIdentifierInfo(), ToType, | ||||||||||
5236 | D->isParameterPack(), ToTypeSourceInfo)) | ||||||||||
5237 | return ToD; | ||||||||||
5238 | |||||||||||
5239 | if (D->hasDefaultArgument()) { | ||||||||||
5240 | ExpectedExpr ToDefaultArgOrErr = import(D->getDefaultArgument()); | ||||||||||
5241 | if (!ToDefaultArgOrErr) | ||||||||||
5242 | return ToDefaultArgOrErr.takeError(); | ||||||||||
5243 | ToD->setDefaultArgument(*ToDefaultArgOrErr); | ||||||||||
5244 | } | ||||||||||
5245 | |||||||||||
5246 | return ToD; | ||||||||||
5247 | } | ||||||||||
5248 | |||||||||||
5249 | ExpectedDecl | ||||||||||
5250 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { | ||||||||||
5251 | // Import the name of this declaration. | ||||||||||
5252 | auto NameOrErr = import(D->getDeclName()); | ||||||||||
5253 | if (!NameOrErr) | ||||||||||
5254 | return NameOrErr.takeError(); | ||||||||||
5255 | |||||||||||
5256 | // Import the location of this declaration. | ||||||||||
5257 | ExpectedSLoc LocationOrErr = import(D->getLocation()); | ||||||||||
5258 | if (!LocationOrErr) | ||||||||||
5259 | return LocationOrErr.takeError(); | ||||||||||
5260 | |||||||||||
5261 | // Import template parameters. | ||||||||||
5262 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); | ||||||||||
5263 | if (!TemplateParamsOrErr) | ||||||||||
5264 | return TemplateParamsOrErr.takeError(); | ||||||||||
5265 | |||||||||||
5266 | TemplateTemplateParmDecl *ToD = nullptr; | ||||||||||
5267 | if (GetImportedOrCreateDecl( | ||||||||||
5268 | ToD, D, Importer.getToContext(), | ||||||||||
5269 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, | ||||||||||
5270 | D->getDepth(), D->getPosition(), D->isParameterPack(), | ||||||||||
5271 | (*NameOrErr).getAsIdentifierInfo(), *TemplateParamsOrErr)) | ||||||||||
5272 | return ToD; | ||||||||||
5273 | |||||||||||
5274 | if (D->hasDefaultArgument()) { | ||||||||||
5275 | Expected<TemplateArgumentLoc> ToDefaultArgOrErr = | ||||||||||
5276 | import(D->getDefaultArgument()); | ||||||||||
5277 | if (!ToDefaultArgOrErr) | ||||||||||
5278 | return ToDefaultArgOrErr.takeError(); | ||||||||||
5279 | ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr); | ||||||||||
5280 | } | ||||||||||
5281 | |||||||||||
5282 | return ToD; | ||||||||||
5283 | } | ||||||||||
5284 | |||||||||||
5285 | // Returns the definition for a (forward) declaration of a TemplateDecl, if | ||||||||||
5286 | // it has any definition in the redecl chain. | ||||||||||
5287 | template <typename T> static auto getTemplateDefinition(T *D) -> T * { | ||||||||||
5288 | assert(D->getTemplatedDecl() && "Should be called on templates only")((D->getTemplatedDecl() && "Should be called on templates only" ) ? static_cast<void> (0) : __assert_fail ("D->getTemplatedDecl() && \"Should be called on templates only\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 5288, __PRETTY_FUNCTION__)); | ||||||||||
5289 | auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); | ||||||||||
5290 | if (!ToTemplatedDef) | ||||||||||
5291 | return nullptr; | ||||||||||
5292 | auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate(); | ||||||||||
5293 | return cast_or_null<T>(TemplateWithDef); | ||||||||||
5294 | } | ||||||||||
5295 | |||||||||||
5296 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { | ||||||||||
5297 | |||||||||||
5298 | // Import the major distinguishing characteristics of this class template. | ||||||||||
5299 | DeclContext *DC, *LexicalDC; | ||||||||||
5300 | DeclarationName Name; | ||||||||||
5301 | SourceLocation Loc; | ||||||||||
5302 | NamedDecl *ToD; | ||||||||||
5303 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
5304 | return std::move(Err); | ||||||||||
5305 | if (ToD) | ||||||||||
5306 | return ToD; | ||||||||||
5307 | |||||||||||
5308 | ClassTemplateDecl *FoundByLookup = nullptr; | ||||||||||
5309 | |||||||||||
5310 | // We may already have a template of the same name; try to find and match it. | ||||||||||
5311 | if (!DC->isFunctionOrMethod()) { | ||||||||||
5312 | SmallVector<NamedDecl *, 4> ConflictingDecls; | ||||||||||
5313 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||||||
5314 | for (auto *FoundDecl : FoundDecls) { | ||||||||||
5315 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary | | ||||||||||
5316 | Decl::IDNS_TagFriend)) | ||||||||||
5317 | continue; | ||||||||||
5318 | |||||||||||
5319 | Decl *Found = FoundDecl; | ||||||||||
5320 | auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found); | ||||||||||
5321 | if (FoundTemplate) { | ||||||||||
5322 | if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D)) | ||||||||||
5323 | continue; | ||||||||||
5324 | |||||||||||
5325 | if (IsStructuralMatch(D, FoundTemplate)) { | ||||||||||
5326 | ClassTemplateDecl *TemplateWithDef = | ||||||||||
5327 | getTemplateDefinition(FoundTemplate); | ||||||||||
5328 | if (D->isThisDeclarationADefinition() && TemplateWithDef) | ||||||||||
5329 | return Importer.MapImported(D, TemplateWithDef); | ||||||||||
5330 | if (!FoundByLookup) | ||||||||||
5331 | FoundByLookup = FoundTemplate; | ||||||||||
5332 | // Search in all matches because there may be multiple decl chains, | ||||||||||
5333 | // see ASTTests test ImportExistingFriendClassTemplateDef. | ||||||||||
5334 | continue; | ||||||||||
5335 | } | ||||||||||
5336 | ConflictingDecls.push_back(FoundDecl); | ||||||||||
5337 | } | ||||||||||
5338 | } | ||||||||||
5339 | |||||||||||
5340 | if (!ConflictingDecls.empty()) { | ||||||||||
5341 | ExpectedName NameOrErr = Importer.HandleNameConflict( | ||||||||||
5342 | Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(), | ||||||||||
5343 | ConflictingDecls.size()); | ||||||||||
5344 | if (NameOrErr) | ||||||||||
5345 | Name = NameOrErr.get(); | ||||||||||
5346 | else | ||||||||||
5347 | return NameOrErr.takeError(); | ||||||||||
5348 | } | ||||||||||
5349 | } | ||||||||||
5350 | |||||||||||
5351 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); | ||||||||||
5352 | |||||||||||
5353 | // Create the declaration that is being templated. | ||||||||||
5354 | CXXRecordDecl *ToTemplated; | ||||||||||
5355 | if (Error Err = importInto(ToTemplated, FromTemplated)) | ||||||||||
5356 | return std::move(Err); | ||||||||||
5357 | |||||||||||
5358 | // Create the class template declaration itself. | ||||||||||
5359 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); | ||||||||||
5360 | if (!TemplateParamsOrErr) | ||||||||||
5361 | return TemplateParamsOrErr.takeError(); | ||||||||||
5362 | |||||||||||
5363 | ClassTemplateDecl *D2; | ||||||||||
5364 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, | ||||||||||
5365 | *TemplateParamsOrErr, ToTemplated)) | ||||||||||
5366 | return D2; | ||||||||||
5367 | |||||||||||
5368 | ToTemplated->setDescribedClassTemplate(D2); | ||||||||||
5369 | |||||||||||
5370 | D2->setAccess(D->getAccess()); | ||||||||||
5371 | D2->setLexicalDeclContext(LexicalDC); | ||||||||||
5372 | |||||||||||
5373 | addDeclToContexts(D, D2); | ||||||||||
5374 | |||||||||||
5375 | if (FoundByLookup) { | ||||||||||
5376 | auto *Recent = | ||||||||||
5377 | const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl()); | ||||||||||
5378 | |||||||||||
5379 | // It is possible that during the import of the class template definition | ||||||||||
5380 | // we start the import of a fwd friend decl of the very same class template | ||||||||||
5381 | // and we add the fwd friend decl to the lookup table. But the ToTemplated | ||||||||||
5382 | // had been created earlier and by that time the lookup could not find | ||||||||||
5383 | // anything existing, so it has no previous decl. Later, (still during the | ||||||||||
5384 | // import of the fwd friend decl) we start to import the definition again | ||||||||||
5385 | // and this time the lookup finds the previous fwd friend class template. | ||||||||||
5386 | // In this case we must set up the previous decl for the templated decl. | ||||||||||
5387 | if (!ToTemplated->getPreviousDecl()) { | ||||||||||
5388 | assert(FoundByLookup->getTemplatedDecl() &&((FoundByLookup->getTemplatedDecl() && "Found decl must have its templated decl set" ) ? static_cast<void> (0) : __assert_fail ("FoundByLookup->getTemplatedDecl() && \"Found decl must have its templated decl set\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 5389, __PRETTY_FUNCTION__)) | ||||||||||
5389 | "Found decl must have its templated decl set")((FoundByLookup->getTemplatedDecl() && "Found decl must have its templated decl set" ) ? static_cast<void> (0) : __assert_fail ("FoundByLookup->getTemplatedDecl() && \"Found decl must have its templated decl set\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 5389, __PRETTY_FUNCTION__)); | ||||||||||
5390 | CXXRecordDecl *PrevTemplated = | ||||||||||
5391 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); | ||||||||||
5392 | if (ToTemplated != PrevTemplated) | ||||||||||
5393 | ToTemplated->setPreviousDecl(PrevTemplated); | ||||||||||
5394 | } | ||||||||||
5395 | |||||||||||
5396 | D2->setPreviousDecl(Recent); | ||||||||||
5397 | } | ||||||||||
5398 | |||||||||||
5399 | if (FromTemplated->isCompleteDefinition() && | ||||||||||
5400 | !ToTemplated->isCompleteDefinition()) { | ||||||||||
5401 | // FIXME: Import definition! | ||||||||||
5402 | } | ||||||||||
5403 | |||||||||||
5404 | return D2; | ||||||||||
5405 | } | ||||||||||
5406 | |||||||||||
5407 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( | ||||||||||
5408 | ClassTemplateSpecializationDecl *D) { | ||||||||||
5409 | ClassTemplateDecl *ClassTemplate; | ||||||||||
5410 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) | ||||||||||
5411 | return std::move(Err); | ||||||||||
5412 | |||||||||||
5413 | // Import the context of this declaration. | ||||||||||
5414 | DeclContext *DC, *LexicalDC; | ||||||||||
5415 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | ||||||||||
5416 | return std::move(Err); | ||||||||||
5417 | |||||||||||
5418 | // Import template arguments. | ||||||||||
5419 | SmallVector<TemplateArgument, 2> TemplateArgs; | ||||||||||
5420 | if (Error Err = ImportTemplateArguments( | ||||||||||
5421 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) | ||||||||||
5422 | return std::move(Err); | ||||||||||
5423 | // Try to find an existing specialization with these template arguments and | ||||||||||
5424 | // template parameter list. | ||||||||||
5425 | void *InsertPos = nullptr; | ||||||||||
5426 | ClassTemplateSpecializationDecl *PrevDecl = nullptr; | ||||||||||
5427 | ClassTemplatePartialSpecializationDecl *PartialSpec = | ||||||||||
5428 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); | ||||||||||
5429 | |||||||||||
5430 | // Import template parameters. | ||||||||||
5431 | TemplateParameterList *ToTPList = nullptr; | ||||||||||
5432 | |||||||||||
5433 | if (PartialSpec) { | ||||||||||
5434 | auto ToTPListOrErr = import(PartialSpec->getTemplateParameters()); | ||||||||||
5435 | if (!ToTPListOrErr) | ||||||||||
5436 | return ToTPListOrErr.takeError(); | ||||||||||
5437 | ToTPList = *ToTPListOrErr; | ||||||||||
5438 | PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs, | ||||||||||
5439 | *ToTPListOrErr, | ||||||||||
5440 | InsertPos); | ||||||||||
5441 | } else | ||||||||||
5442 | PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); | ||||||||||
5443 | |||||||||||
5444 | if (PrevDecl) { | ||||||||||
5445 | if (IsStructuralMatch(D, PrevDecl)) { | ||||||||||
5446 | CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition(); | ||||||||||
5447 | if (D->isThisDeclarationADefinition() && PrevDefinition) { | ||||||||||
5448 | Importer.MapImported(D, PrevDefinition); | ||||||||||
5449 | // Import those default field initializers which have been | ||||||||||
5450 | // instantiated in the "From" context, but not in the "To" context. | ||||||||||
5451 | for (auto *FromField : D->fields()) { | ||||||||||
5452 | auto ToOrErr = import(FromField); | ||||||||||
5453 | if (!ToOrErr) | ||||||||||
5454 | return ToOrErr.takeError(); | ||||||||||
5455 | } | ||||||||||
5456 | |||||||||||
5457 | // Import those methods which have been instantiated in the | ||||||||||
5458 | // "From" context, but not in the "To" context. | ||||||||||
5459 | for (CXXMethodDecl *FromM : D->methods()) { | ||||||||||
5460 | auto ToOrErr = import(FromM); | ||||||||||
5461 | if (!ToOrErr) | ||||||||||
5462 | return ToOrErr.takeError(); | ||||||||||
5463 | } | ||||||||||
5464 | |||||||||||
5465 | // TODO Import instantiated default arguments. | ||||||||||
5466 | // TODO Import instantiated exception specifications. | ||||||||||
5467 | // | ||||||||||
5468 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint | ||||||||||
5469 | // what else could be fused during an AST merge. | ||||||||||
5470 | return PrevDefinition; | ||||||||||
5471 | } | ||||||||||
5472 | } else { // ODR violation. | ||||||||||
5473 | // FIXME HandleNameConflict | ||||||||||
5474 | return make_error<ImportError>(ImportError::NameConflict); | ||||||||||
5475 | } | ||||||||||
5476 | } | ||||||||||
5477 | |||||||||||
5478 | // Import the location of this declaration. | ||||||||||
5479 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | ||||||||||
5480 | if (!BeginLocOrErr) | ||||||||||
5481 | return BeginLocOrErr.takeError(); | ||||||||||
5482 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); | ||||||||||
5483 | if (!IdLocOrErr) | ||||||||||
5484 | return IdLocOrErr.takeError(); | ||||||||||
5485 | |||||||||||
5486 | // Create the specialization. | ||||||||||
5487 | ClassTemplateSpecializationDecl *D2 = nullptr; | ||||||||||
5488 | if (PartialSpec) { | ||||||||||
5489 | // Import TemplateArgumentListInfo. | ||||||||||
5490 | TemplateArgumentListInfo ToTAInfo; | ||||||||||
5491 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); | ||||||||||
5492 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) | ||||||||||
5493 | return std::move(Err); | ||||||||||
5494 | |||||||||||
5495 | QualType CanonInjType; | ||||||||||
5496 | if (Error Err = importInto( | ||||||||||
5497 | CanonInjType, PartialSpec->getInjectedSpecializationType())) | ||||||||||
5498 | return std::move(Err); | ||||||||||
5499 | CanonInjType = CanonInjType.getCanonicalType(); | ||||||||||
5500 | |||||||||||
5501 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( | ||||||||||
5502 | D2, D, Importer.getToContext(), D->getTagKind(), DC, | ||||||||||
5503 | *BeginLocOrErr, *IdLocOrErr, ToTPList, ClassTemplate, | ||||||||||
5504 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), | ||||||||||
5505 | ToTAInfo, CanonInjType, | ||||||||||
5506 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) | ||||||||||
5507 | return D2; | ||||||||||
5508 | |||||||||||
5509 | // Update InsertPos, because preceding import calls may have invalidated | ||||||||||
5510 | // it by adding new specializations. | ||||||||||
5511 | auto *PartSpec2 = cast<ClassTemplatePartialSpecializationDecl>(D2); | ||||||||||
5512 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList, | ||||||||||
5513 | InsertPos)) | ||||||||||
5514 | // Add this partial specialization to the class template. | ||||||||||
5515 | ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos); | ||||||||||
5516 | |||||||||||
5517 | } else { // Not a partial specialization. | ||||||||||
5518 | if (GetImportedOrCreateDecl( | ||||||||||
5519 | D2, D, Importer.getToContext(), D->getTagKind(), DC, | ||||||||||
5520 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, | ||||||||||
5521 | PrevDecl)) | ||||||||||
5522 | return D2; | ||||||||||
5523 | |||||||||||
5524 | // Update InsertPos, because preceding import calls may have invalidated | ||||||||||
5525 | // it by adding new specializations. | ||||||||||
5526 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) | ||||||||||
5527 | // Add this specialization to the class template. | ||||||||||
5528 | ClassTemplate->AddSpecialization(D2, InsertPos); | ||||||||||
5529 | } | ||||||||||
5530 | |||||||||||
5531 | D2->setSpecializationKind(D->getSpecializationKind()); | ||||||||||
5532 | |||||||||||
5533 | // Set the context of this specialization/instantiation. | ||||||||||
5534 | D2->setLexicalDeclContext(LexicalDC); | ||||||||||
5535 | |||||||||||
5536 | // Add to the DC only if it was an explicit specialization/instantiation. | ||||||||||
5537 | if (D2->isExplicitInstantiationOrSpecialization()) { | ||||||||||
5538 | LexicalDC->addDeclInternal(D2); | ||||||||||
5539 | } | ||||||||||
5540 | |||||||||||
5541 | if (auto BraceRangeOrErr = import(D->getBraceRange())) | ||||||||||
5542 | D2->setBraceRange(*BraceRangeOrErr); | ||||||||||
5543 | else | ||||||||||
5544 | return BraceRangeOrErr.takeError(); | ||||||||||
5545 | |||||||||||
5546 | // Import the qualifier, if any. | ||||||||||
5547 | if (auto LocOrErr = import(D->getQualifierLoc())) | ||||||||||
5548 | D2->setQualifierInfo(*LocOrErr); | ||||||||||
5549 | else | ||||||||||
5550 | return LocOrErr.takeError(); | ||||||||||
5551 | |||||||||||
5552 | if (auto *TSI = D->getTypeAsWritten()) { | ||||||||||
5553 | if (auto TInfoOrErr = import(TSI)) | ||||||||||
5554 | D2->setTypeAsWritten(*TInfoOrErr); | ||||||||||
5555 | else | ||||||||||
5556 | return TInfoOrErr.takeError(); | ||||||||||
5557 | |||||||||||
5558 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) | ||||||||||
5559 | D2->setTemplateKeywordLoc(*LocOrErr); | ||||||||||
5560 | else | ||||||||||
5561 | return LocOrErr.takeError(); | ||||||||||
5562 | |||||||||||
5563 | if (auto LocOrErr = import(D->getExternLoc())) | ||||||||||
5564 | D2->setExternLoc(*LocOrErr); | ||||||||||
5565 | else | ||||||||||
5566 | return LocOrErr.takeError(); | ||||||||||
5567 | } | ||||||||||
5568 | |||||||||||
5569 | if (D->getPointOfInstantiation().isValid()) { | ||||||||||
5570 | if (auto POIOrErr = import(D->getPointOfInstantiation())) | ||||||||||
5571 | D2->setPointOfInstantiation(*POIOrErr); | ||||||||||
5572 | else | ||||||||||
5573 | return POIOrErr.takeError(); | ||||||||||
5574 | } | ||||||||||
5575 | |||||||||||
5576 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); | ||||||||||
5577 | |||||||||||
5578 | if (D->isCompleteDefinition()) | ||||||||||
5579 | if (Error Err = ImportDefinition(D, D2)) | ||||||||||
5580 | return std::move(Err); | ||||||||||
5581 | |||||||||||
5582 | return D2; | ||||||||||
5583 | } | ||||||||||
5584 | |||||||||||
5585 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { | ||||||||||
5586 | // Import the major distinguishing characteristics of this variable template. | ||||||||||
5587 | DeclContext *DC, *LexicalDC; | ||||||||||
5588 | DeclarationName Name; | ||||||||||
5589 | SourceLocation Loc; | ||||||||||
5590 | NamedDecl *ToD; | ||||||||||
5591 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
5592 | return std::move(Err); | ||||||||||
5593 | if (ToD) | ||||||||||
5594 | return ToD; | ||||||||||
5595 | |||||||||||
5596 | // We may already have a template of the same name; try to find and match it. | ||||||||||
5597 | assert(!DC->isFunctionOrMethod() &&((!DC->isFunctionOrMethod() && "Variable templates cannot be declared at function scope" ) ? static_cast<void> (0) : __assert_fail ("!DC->isFunctionOrMethod() && \"Variable templates cannot be declared at function scope\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 5598, __PRETTY_FUNCTION__)) | ||||||||||
5598 | "Variable templates cannot be declared at function scope")((!DC->isFunctionOrMethod() && "Variable templates cannot be declared at function scope" ) ? static_cast<void> (0) : __assert_fail ("!DC->isFunctionOrMethod() && \"Variable templates cannot be declared at function scope\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 5598, __PRETTY_FUNCTION__)); | ||||||||||
5599 | |||||||||||
5600 | SmallVector<NamedDecl *, 4> ConflictingDecls; | ||||||||||
5601 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||||||
5602 | VarTemplateDecl *FoundByLookup = nullptr; | ||||||||||
5603 | for (auto *FoundDecl : FoundDecls) { | ||||||||||
5604 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) | ||||||||||
5605 | continue; | ||||||||||
5606 | |||||||||||
5607 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) { | ||||||||||
5608 | // Use the templated decl, some linkage flags are set only there. | ||||||||||
5609 | if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(), | ||||||||||
5610 | D->getTemplatedDecl())) | ||||||||||
5611 | continue; | ||||||||||
5612 | if (IsStructuralMatch(D, FoundTemplate)) { | ||||||||||
5613 | // The Decl in the "From" context has a definition, but in the | ||||||||||
5614 | // "To" context we already have a definition. | ||||||||||
5615 | VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate); | ||||||||||
5616 | if (D->isThisDeclarationADefinition() && FoundDef) | ||||||||||
5617 | // FIXME Check for ODR error if the two definitions have | ||||||||||
5618 | // different initializers? | ||||||||||
5619 | return Importer.MapImported(D, FoundDef); | ||||||||||
5620 | |||||||||||
5621 | FoundByLookup = FoundTemplate; | ||||||||||
5622 | break; | ||||||||||
5623 | } | ||||||||||
5624 | ConflictingDecls.push_back(FoundDecl); | ||||||||||
5625 | } | ||||||||||
5626 | } | ||||||||||
5627 | |||||||||||
5628 | if (!ConflictingDecls.empty()) { | ||||||||||
5629 | ExpectedName NameOrErr = Importer.HandleNameConflict( | ||||||||||
5630 | Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(), | ||||||||||
5631 | ConflictingDecls.size()); | ||||||||||
5632 | if (NameOrErr) | ||||||||||
5633 | Name = NameOrErr.get(); | ||||||||||
5634 | else | ||||||||||
5635 | return NameOrErr.takeError(); | ||||||||||
5636 | } | ||||||||||
5637 | |||||||||||
5638 | VarDecl *DTemplated = D->getTemplatedDecl(); | ||||||||||
5639 | |||||||||||
5640 | // Import the type. | ||||||||||
5641 | // FIXME: Value not used? | ||||||||||
5642 | ExpectedType TypeOrErr = import(DTemplated->getType()); | ||||||||||
5643 | if (!TypeOrErr) | ||||||||||
5644 | return TypeOrErr.takeError(); | ||||||||||
5645 | |||||||||||
5646 | // Create the declaration that is being templated. | ||||||||||
5647 | VarDecl *ToTemplated; | ||||||||||
5648 | if (Error Err = importInto(ToTemplated, DTemplated)) | ||||||||||
5649 | return std::move(Err); | ||||||||||
5650 | |||||||||||
5651 | // Create the variable template declaration itself. | ||||||||||
5652 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); | ||||||||||
5653 | if (!TemplateParamsOrErr) | ||||||||||
5654 | return TemplateParamsOrErr.takeError(); | ||||||||||
5655 | |||||||||||
5656 | VarTemplateDecl *ToVarTD; | ||||||||||
5657 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, | ||||||||||
5658 | Name, *TemplateParamsOrErr, ToTemplated)) | ||||||||||
5659 | return ToVarTD; | ||||||||||
5660 | |||||||||||
5661 | ToTemplated->setDescribedVarTemplate(ToVarTD); | ||||||||||
5662 | |||||||||||
5663 | ToVarTD->setAccess(D->getAccess()); | ||||||||||
5664 | ToVarTD->setLexicalDeclContext(LexicalDC); | ||||||||||
5665 | LexicalDC->addDeclInternal(ToVarTD); | ||||||||||
5666 | |||||||||||
5667 | if (FoundByLookup) { | ||||||||||
5668 | auto *Recent = | ||||||||||
5669 | const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl()); | ||||||||||
5670 | if (!ToTemplated->getPreviousDecl()) { | ||||||||||
5671 | auto *PrevTemplated = | ||||||||||
5672 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); | ||||||||||
5673 | if (ToTemplated != PrevTemplated) | ||||||||||
5674 | ToTemplated->setPreviousDecl(PrevTemplated); | ||||||||||
5675 | } | ||||||||||
5676 | ToVarTD->setPreviousDecl(Recent); | ||||||||||
5677 | } | ||||||||||
5678 | |||||||||||
5679 | if (DTemplated->isThisDeclarationADefinition() && | ||||||||||
5680 | !ToTemplated->isThisDeclarationADefinition()) { | ||||||||||
5681 | // FIXME: Import definition! | ||||||||||
5682 | } | ||||||||||
5683 | |||||||||||
5684 | return ToVarTD; | ||||||||||
5685 | } | ||||||||||
5686 | |||||||||||
5687 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( | ||||||||||
5688 | VarTemplateSpecializationDecl *D) { | ||||||||||
5689 | // If this record has a definition in the translation unit we're coming from, | ||||||||||
5690 | // but this particular declaration is not that definition, import the | ||||||||||
5691 | // definition and map to that. | ||||||||||
5692 | VarDecl *Definition = D->getDefinition(); | ||||||||||
5693 | if (Definition && Definition != D) { | ||||||||||
5694 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | ||||||||||
5695 | return Importer.MapImported(D, *ImportedDefOrErr); | ||||||||||
5696 | else | ||||||||||
5697 | return ImportedDefOrErr.takeError(); | ||||||||||
5698 | } | ||||||||||
5699 | |||||||||||
5700 | VarTemplateDecl *VarTemplate = nullptr; | ||||||||||
5701 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) | ||||||||||
5702 | return std::move(Err); | ||||||||||
5703 | |||||||||||
5704 | // Import the context of this declaration. | ||||||||||
5705 | DeclContext *DC, *LexicalDC; | ||||||||||
5706 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | ||||||||||
5707 | return std::move(Err); | ||||||||||
5708 | |||||||||||
5709 | // Import the location of this declaration. | ||||||||||
5710 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | ||||||||||
5711 | if (!BeginLocOrErr) | ||||||||||
5712 | return BeginLocOrErr.takeError(); | ||||||||||
5713 | |||||||||||
5714 | auto IdLocOrErr = import(D->getLocation()); | ||||||||||
5715 | if (!IdLocOrErr) | ||||||||||
5716 | return IdLocOrErr.takeError(); | ||||||||||
5717 | |||||||||||
5718 | // Import template arguments. | ||||||||||
5719 | SmallVector<TemplateArgument, 2> TemplateArgs; | ||||||||||
5720 | if (Error Err = ImportTemplateArguments( | ||||||||||
5721 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) | ||||||||||
5722 | return std::move(Err); | ||||||||||
5723 | |||||||||||
5724 | // Try to find an existing specialization with these template arguments. | ||||||||||
5725 | void *InsertPos = nullptr; | ||||||||||
5726 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( | ||||||||||
5727 | TemplateArgs, InsertPos); | ||||||||||
5728 | if (D2) { | ||||||||||
5729 | // We already have a variable template specialization with these template | ||||||||||
5730 | // arguments. | ||||||||||
5731 | |||||||||||
5732 | // FIXME: Check for specialization vs. instantiation errors. | ||||||||||
5733 | |||||||||||
5734 | if (VarDecl *FoundDef = D2->getDefinition()) { | ||||||||||
5735 | if (!D->isThisDeclarationADefinition() || | ||||||||||
5736 | IsStructuralMatch(D, FoundDef)) { | ||||||||||
5737 | // The record types structurally match, or the "from" translation | ||||||||||
5738 | // unit only had a forward declaration anyway; call it the same | ||||||||||
5739 | // variable. | ||||||||||
5740 | return Importer.MapImported(D, FoundDef); | ||||||||||
5741 | } | ||||||||||
5742 | } | ||||||||||
5743 | } else { | ||||||||||
5744 | // Import the type. | ||||||||||
5745 | QualType T; | ||||||||||
5746 | if (Error Err = importInto(T, D->getType())) | ||||||||||
5747 | return std::move(Err); | ||||||||||
5748 | |||||||||||
5749 | auto TInfoOrErr = import(D->getTypeSourceInfo()); | ||||||||||
5750 | if (!TInfoOrErr) | ||||||||||
5751 | return TInfoOrErr.takeError(); | ||||||||||
5752 | |||||||||||
5753 | TemplateArgumentListInfo ToTAInfo; | ||||||||||
5754 | if (Error Err = ImportTemplateArgumentListInfo( | ||||||||||
5755 | D->getTemplateArgsInfo(), ToTAInfo)) | ||||||||||
5756 | return std::move(Err); | ||||||||||
5757 | |||||||||||
5758 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; | ||||||||||
5759 | // Create a new specialization. | ||||||||||
5760 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { | ||||||||||
5761 | // Import TemplateArgumentListInfo | ||||||||||
5762 | TemplateArgumentListInfo ArgInfos; | ||||||||||
5763 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); | ||||||||||
5764 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. | ||||||||||
5765 | if (Error Err = ImportTemplateArgumentListInfo( | ||||||||||
5766 | *FromTAArgsAsWritten, ArgInfos)) | ||||||||||
5767 | return std::move(Err); | ||||||||||
5768 | |||||||||||
5769 | auto ToTPListOrErr = import(FromPartial->getTemplateParameters()); | ||||||||||
5770 | if (!ToTPListOrErr) | ||||||||||
5771 | return ToTPListOrErr.takeError(); | ||||||||||
5772 | |||||||||||
5773 | PartVarSpecDecl *ToPartial; | ||||||||||
5774 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, | ||||||||||
5775 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, | ||||||||||
5776 | VarTemplate, T, *TInfoOrErr, | ||||||||||
5777 | D->getStorageClass(), TemplateArgs, ArgInfos)) | ||||||||||
5778 | return ToPartial; | ||||||||||
5779 | |||||||||||
5780 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( | ||||||||||
5781 | FromPartial->getInstantiatedFromMember())) | ||||||||||
5782 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); | ||||||||||
5783 | else | ||||||||||
5784 | return ToInstOrErr.takeError(); | ||||||||||
5785 | |||||||||||
5786 | if (FromPartial->isMemberSpecialization()) | ||||||||||
5787 | ToPartial->setMemberSpecialization(); | ||||||||||
5788 | |||||||||||
5789 | D2 = ToPartial; | ||||||||||
5790 | |||||||||||
5791 | } else { // Full specialization | ||||||||||
5792 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, | ||||||||||
5793 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, | ||||||||||
5794 | T, *TInfoOrErr, | ||||||||||
5795 | D->getStorageClass(), TemplateArgs)) | ||||||||||
5796 | return D2; | ||||||||||
5797 | } | ||||||||||
5798 | |||||||||||
5799 | if (D->getPointOfInstantiation().isValid()) { | ||||||||||
5800 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) | ||||||||||
5801 | D2->setPointOfInstantiation(*POIOrErr); | ||||||||||
5802 | else | ||||||||||
5803 | return POIOrErr.takeError(); | ||||||||||
5804 | } | ||||||||||
5805 | |||||||||||
5806 | D2->setSpecializationKind(D->getSpecializationKind()); | ||||||||||
5807 | D2->setTemplateArgsInfo(ToTAInfo); | ||||||||||
5808 | |||||||||||
5809 | // Add this specialization to the class template. | ||||||||||
5810 | VarTemplate->AddSpecialization(D2, InsertPos); | ||||||||||
5811 | |||||||||||
5812 | // Import the qualifier, if any. | ||||||||||
5813 | if (auto LocOrErr = import(D->getQualifierLoc())) | ||||||||||
5814 | D2->setQualifierInfo(*LocOrErr); | ||||||||||
5815 | else | ||||||||||
5816 | return LocOrErr.takeError(); | ||||||||||
5817 | |||||||||||
5818 | if (D->isConstexpr()) | ||||||||||
5819 | D2->setConstexpr(true); | ||||||||||
5820 | |||||||||||
5821 | // Add the specialization to this context. | ||||||||||
5822 | D2->setLexicalDeclContext(LexicalDC); | ||||||||||
5823 | LexicalDC->addDeclInternal(D2); | ||||||||||
5824 | |||||||||||
5825 | D2->setAccess(D->getAccess()); | ||||||||||
5826 | } | ||||||||||
5827 | |||||||||||
5828 | if (Error Err = ImportInitializer(D, D2)) | ||||||||||
5829 | return std::move(Err); | ||||||||||
5830 | |||||||||||
5831 | return D2; | ||||||||||
5832 | } | ||||||||||
5833 | |||||||||||
5834 | ExpectedDecl | ||||||||||
5835 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { | ||||||||||
5836 | DeclContext *DC, *LexicalDC; | ||||||||||
5837 | DeclarationName Name; | ||||||||||
5838 | SourceLocation Loc; | ||||||||||
5839 | NamedDecl *ToD; | ||||||||||
5840 | |||||||||||
5841 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | ||||||||||
5842 | return std::move(Err); | ||||||||||
5843 | |||||||||||
5844 | if (ToD) | ||||||||||
5845 | return ToD; | ||||||||||
5846 | |||||||||||
5847 | const FunctionTemplateDecl *FoundByLookup = nullptr; | ||||||||||
5848 | |||||||||||
5849 | // Try to find a function in our own ("to") context with the same name, same | ||||||||||
5850 | // type, and in the same context as the function we're importing. | ||||||||||
5851 | // FIXME Split this into a separate function. | ||||||||||
5852 | if (!LexicalDC->isFunctionOrMethod()) { | ||||||||||
5853 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; | ||||||||||
5854 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | ||||||||||
5855 | for (auto *FoundDecl : FoundDecls) { | ||||||||||
5856 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | ||||||||||
5857 | continue; | ||||||||||
5858 | |||||||||||
5859 | if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { | ||||||||||
5860 | if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D)) | ||||||||||
5861 | continue; | ||||||||||
5862 | if (IsStructuralMatch(D, FoundTemplate)) { | ||||||||||
5863 | FunctionTemplateDecl *TemplateWithDef = | ||||||||||
5864 | getTemplateDefinition(FoundTemplate); | ||||||||||
5865 | if (D->isThisDeclarationADefinition() && TemplateWithDef) | ||||||||||
5866 | return Importer.MapImported(D, TemplateWithDef); | ||||||||||
5867 | |||||||||||
5868 | FoundByLookup = FoundTemplate; | ||||||||||
5869 | break; | ||||||||||
5870 | // TODO: handle conflicting names | ||||||||||
5871 | } | ||||||||||
5872 | } | ||||||||||
5873 | } | ||||||||||
5874 | } | ||||||||||
5875 | |||||||||||
5876 | auto ParamsOrErr = import(D->getTemplateParameters()); | ||||||||||
5877 | if (!ParamsOrErr) | ||||||||||
5878 | return ParamsOrErr.takeError(); | ||||||||||
5879 | |||||||||||
5880 | FunctionDecl *TemplatedFD; | ||||||||||
5881 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) | ||||||||||
5882 | return std::move(Err); | ||||||||||
5883 | |||||||||||
5884 | FunctionTemplateDecl *ToFunc; | ||||||||||
5885 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, | ||||||||||
5886 | *ParamsOrErr, TemplatedFD)) | ||||||||||
5887 | return ToFunc; | ||||||||||
5888 | |||||||||||
5889 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); | ||||||||||
5890 | |||||||||||
5891 | ToFunc->setAccess(D->getAccess()); | ||||||||||
5892 | ToFunc->setLexicalDeclContext(LexicalDC); | ||||||||||
5893 | LexicalDC->addDeclInternal(ToFunc); | ||||||||||
5894 | |||||||||||
5895 | if (FoundByLookup) { | ||||||||||
5896 | auto *Recent = | ||||||||||
5897 | const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl()); | ||||||||||
5898 | if (!TemplatedFD->getPreviousDecl()) { | ||||||||||
5899 | assert(FoundByLookup->getTemplatedDecl() &&((FoundByLookup->getTemplatedDecl() && "Found decl must have its templated decl set" ) ? static_cast<void> (0) : __assert_fail ("FoundByLookup->getTemplatedDecl() && \"Found decl must have its templated decl set\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 5900, __PRETTY_FUNCTION__)) | ||||||||||
5900 | "Found decl must have its templated decl set")((FoundByLookup->getTemplatedDecl() && "Found decl must have its templated decl set" ) ? static_cast<void> (0) : __assert_fail ("FoundByLookup->getTemplatedDecl() && \"Found decl must have its templated decl set\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 5900, __PRETTY_FUNCTION__)); | ||||||||||
5901 | auto *PrevTemplated = | ||||||||||
5902 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); | ||||||||||
5903 | if (TemplatedFD != PrevTemplated) | ||||||||||
5904 | TemplatedFD->setPreviousDecl(PrevTemplated); | ||||||||||
5905 | } | ||||||||||
5906 | ToFunc->setPreviousDecl(Recent); | ||||||||||
5907 | } | ||||||||||
5908 | |||||||||||
5909 | return ToFunc; | ||||||||||
5910 | } | ||||||||||
5911 | |||||||||||
5912 | //---------------------------------------------------------------------------- | ||||||||||
5913 | // Import Statements | ||||||||||
5914 | //---------------------------------------------------------------------------- | ||||||||||
5915 | |||||||||||
5916 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { | ||||||||||
5917 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) | ||||||||||
5918 | << S->getStmtClassName(); | ||||||||||
5919 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | ||||||||||
5920 | } | ||||||||||
5921 | |||||||||||
5922 | |||||||||||
5923 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { | ||||||||||
5924 | if (Importer.returnWithErrorInTest()) | ||||||||||
5925 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | ||||||||||
5926 | SmallVector<IdentifierInfo *, 4> Names; | ||||||||||
5927 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { | ||||||||||
5928 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); | ||||||||||
5929 | // ToII is nullptr when no symbolic name is given for output operand | ||||||||||
5930 | // see ParseStmtAsm::ParseAsmOperandsOpt | ||||||||||
5931 | Names.push_back(ToII); | ||||||||||
5932 | } | ||||||||||
5933 | |||||||||||
5934 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { | ||||||||||
5935 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); | ||||||||||
5936 | // ToII is nullptr when no symbolic name is given for input operand | ||||||||||
5937 | // see ParseStmtAsm::ParseAsmOperandsOpt | ||||||||||
5938 | Names.push_back(ToII); | ||||||||||
5939 | } | ||||||||||
5940 | |||||||||||
5941 | SmallVector<StringLiteral *, 4> Clobbers; | ||||||||||
5942 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { | ||||||||||
5943 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) | ||||||||||
5944 | Clobbers.push_back(*ClobberOrErr); | ||||||||||
5945 | else | ||||||||||
5946 | return ClobberOrErr.takeError(); | ||||||||||
5947 | |||||||||||
5948 | } | ||||||||||
5949 | |||||||||||
5950 | SmallVector<StringLiteral *, 4> Constraints; | ||||||||||
5951 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { | ||||||||||
5952 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) | ||||||||||
5953 | Constraints.push_back(*OutputOrErr); | ||||||||||
5954 | else | ||||||||||
5955 | return OutputOrErr.takeError(); | ||||||||||
5956 | } | ||||||||||
5957 | |||||||||||
5958 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { | ||||||||||
5959 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) | ||||||||||
5960 | Constraints.push_back(*InputOrErr); | ||||||||||
5961 | else | ||||||||||
5962 | return InputOrErr.takeError(); | ||||||||||
5963 | } | ||||||||||
5964 | |||||||||||
5965 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs() + | ||||||||||
5966 | S->getNumLabels()); | ||||||||||
5967 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) | ||||||||||
5968 | return std::move(Err); | ||||||||||
5969 | |||||||||||
5970 | if (Error Err = | ||||||||||
5971 | ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) | ||||||||||
5972 | return std::move(Err); | ||||||||||
5973 | |||||||||||
5974 | if (Error Err = ImportArrayChecked( | ||||||||||
5975 | S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs())) | ||||||||||
5976 | return std::move(Err); | ||||||||||
5977 | |||||||||||
5978 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); | ||||||||||
5979 | if (!AsmLocOrErr) | ||||||||||
5980 | return AsmLocOrErr.takeError(); | ||||||||||
5981 | auto AsmStrOrErr = import(S->getAsmString()); | ||||||||||
5982 | if (!AsmStrOrErr) | ||||||||||
5983 | return AsmStrOrErr.takeError(); | ||||||||||
5984 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); | ||||||||||
5985 | if (!RParenLocOrErr) | ||||||||||
5986 | return RParenLocOrErr.takeError(); | ||||||||||
5987 | |||||||||||
5988 | return new (Importer.getToContext()) GCCAsmStmt( | ||||||||||
5989 | Importer.getToContext(), | ||||||||||
5990 | *AsmLocOrErr, | ||||||||||
5991 | S->isSimple(), | ||||||||||
5992 | S->isVolatile(), | ||||||||||
5993 | S->getNumOutputs(), | ||||||||||
5994 | S->getNumInputs(), | ||||||||||
5995 | Names.data(), | ||||||||||
5996 | Constraints.data(), | ||||||||||
5997 | Exprs.data(), | ||||||||||
5998 | *AsmStrOrErr, | ||||||||||
5999 | S->getNumClobbers(), | ||||||||||
6000 | Clobbers.data(), | ||||||||||
6001 | S->getNumLabels(), | ||||||||||
6002 | *RParenLocOrErr); | ||||||||||
6003 | } | ||||||||||
6004 | |||||||||||
6005 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { | ||||||||||
6006 | |||||||||||
6007 | Error Err = Error::success(); | ||||||||||
6008 | auto ToDG = importChecked(Err, S->getDeclGroup()); | ||||||||||
6009 | auto ToBeginLoc = importChecked(Err, S->getBeginLoc()); | ||||||||||
6010 | auto ToEndLoc = importChecked(Err, S->getEndLoc()); | ||||||||||
6011 | if (Err) | ||||||||||
6012 | return std::move(Err); | ||||||||||
6013 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); | ||||||||||
6014 | } | ||||||||||
6015 | |||||||||||
6016 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { | ||||||||||
6017 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); | ||||||||||
6018 | if (!ToSemiLocOrErr) | ||||||||||
6019 | return ToSemiLocOrErr.takeError(); | ||||||||||
6020 | return new (Importer.getToContext()) NullStmt( | ||||||||||
6021 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); | ||||||||||
6022 | } | ||||||||||
6023 | |||||||||||
6024 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { | ||||||||||
6025 | SmallVector<Stmt *, 8> ToStmts(S->size()); | ||||||||||
6026 | |||||||||||
6027 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) | ||||||||||
6028 | return std::move(Err); | ||||||||||
6029 | |||||||||||
6030 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); | ||||||||||
6031 | if (!ToLBracLocOrErr) | ||||||||||
6032 | return ToLBracLocOrErr.takeError(); | ||||||||||
6033 | |||||||||||
6034 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); | ||||||||||
6035 | if (!ToRBracLocOrErr) | ||||||||||
6036 | return ToRBracLocOrErr.takeError(); | ||||||||||
6037 | |||||||||||
6038 | return CompoundStmt::Create( | ||||||||||
6039 | Importer.getToContext(), ToStmts, | ||||||||||
6040 | *ToLBracLocOrErr, *ToRBracLocOrErr); | ||||||||||
6041 | } | ||||||||||
6042 | |||||||||||
6043 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { | ||||||||||
6044 | |||||||||||
6045 | Error Err = Error::success(); | ||||||||||
6046 | auto ToLHS = importChecked(Err, S->getLHS()); | ||||||||||
6047 | auto ToRHS = importChecked(Err, S->getRHS()); | ||||||||||
6048 | auto ToSubStmt = importChecked(Err, S->getSubStmt()); | ||||||||||
6049 | auto ToCaseLoc = importChecked(Err, S->getCaseLoc()); | ||||||||||
6050 | auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc()); | ||||||||||
6051 | auto ToColonLoc = importChecked(Err, S->getColonLoc()); | ||||||||||
6052 | if (Err) | ||||||||||
6053 | return std::move(Err); | ||||||||||
6054 | |||||||||||
6055 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, | ||||||||||
6056 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); | ||||||||||
6057 | ToStmt->setSubStmt(ToSubStmt); | ||||||||||
6058 | |||||||||||
6059 | return ToStmt; | ||||||||||
6060 | } | ||||||||||
6061 | |||||||||||
6062 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { | ||||||||||
6063 | |||||||||||
6064 | Error Err = Error::success(); | ||||||||||
6065 | auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc()); | ||||||||||
6066 | auto ToColonLoc = importChecked(Err, S->getColonLoc()); | ||||||||||
6067 | auto ToSubStmt = importChecked(Err, S->getSubStmt()); | ||||||||||
6068 | if (Err) | ||||||||||
6069 | return std::move(Err); | ||||||||||
6070 | |||||||||||
6071 | return new (Importer.getToContext()) DefaultStmt( | ||||||||||
6072 | ToDefaultLoc, ToColonLoc, ToSubStmt); | ||||||||||
6073 | } | ||||||||||
6074 | |||||||||||
6075 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { | ||||||||||
6076 | |||||||||||
6077 | Error Err = Error::success(); | ||||||||||
6078 | auto ToIdentLoc = importChecked(Err, S->getIdentLoc()); | ||||||||||
6079 | auto ToLabelDecl = importChecked(Err, S->getDecl()); | ||||||||||
6080 | auto ToSubStmt = importChecked(Err, S->getSubStmt()); | ||||||||||
6081 | if (Err) | ||||||||||
6082 | return std::move(Err); | ||||||||||
6083 | |||||||||||
6084 | return new (Importer.getToContext()) LabelStmt( | ||||||||||
6085 | ToIdentLoc, ToLabelDecl, ToSubStmt); | ||||||||||
6086 | } | ||||||||||
6087 | |||||||||||
6088 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { | ||||||||||
6089 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); | ||||||||||
6090 | if (!ToAttrLocOrErr) | ||||||||||
6091 | return ToAttrLocOrErr.takeError(); | ||||||||||
6092 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); | ||||||||||
6093 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); | ||||||||||
6094 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) | ||||||||||
6095 | return std::move(Err); | ||||||||||
6096 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); | ||||||||||
6097 | if (!ToSubStmtOrErr) | ||||||||||
6098 | return ToSubStmtOrErr.takeError(); | ||||||||||
6099 | |||||||||||
6100 | return AttributedStmt::Create( | ||||||||||
6101 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); | ||||||||||
6102 | } | ||||||||||
6103 | |||||||||||
6104 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { | ||||||||||
6105 | |||||||||||
6106 | Error Err = Error::success(); | ||||||||||
6107 | auto ToIfLoc = importChecked(Err, S->getIfLoc()); | ||||||||||
6108 | auto ToInit = importChecked(Err, S->getInit()); | ||||||||||
6109 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); | ||||||||||
6110 | auto ToCond = importChecked(Err, S->getCond()); | ||||||||||
6111 | auto ToLParenLoc = importChecked(Err, S->getLParenLoc()); | ||||||||||
6112 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | ||||||||||
6113 | auto ToThen = importChecked(Err, S->getThen()); | ||||||||||
6114 | auto ToElseLoc = importChecked(Err, S->getElseLoc()); | ||||||||||
6115 | auto ToElse = importChecked(Err, S->getElse()); | ||||||||||
6116 | if (Err) | ||||||||||
6117 | return std::move(Err); | ||||||||||
6118 | |||||||||||
6119 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), | ||||||||||
6120 | ToInit, ToConditionVariable, ToCond, ToLParenLoc, | ||||||||||
6121 | ToRParenLoc, ToThen, ToElseLoc, ToElse); | ||||||||||
6122 | } | ||||||||||
6123 | |||||||||||
6124 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { | ||||||||||
6125 | |||||||||||
6126 | Error Err = Error::success(); | ||||||||||
6127 | auto ToInit = importChecked(Err, S->getInit()); | ||||||||||
6128 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); | ||||||||||
6129 | auto ToCond = importChecked(Err, S->getCond()); | ||||||||||
6130 | auto ToLParenLoc = importChecked(Err, S->getLParenLoc()); | ||||||||||
6131 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | ||||||||||
6132 | auto ToBody = importChecked(Err, S->getBody()); | ||||||||||
6133 | auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc()); | ||||||||||
6134 | if (Err) | ||||||||||
6135 | return std::move(Err); | ||||||||||
6136 | |||||||||||
6137 | auto *ToStmt = | ||||||||||
6138 | SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable, | ||||||||||
6139 | ToCond, ToLParenLoc, ToRParenLoc); | ||||||||||
6140 | ToStmt->setBody(ToBody); | ||||||||||
6141 | ToStmt->setSwitchLoc(ToSwitchLoc); | ||||||||||
6142 | |||||||||||
6143 | // Now we have to re-chain the cases. | ||||||||||
6144 | SwitchCase *LastChainedSwitchCase = nullptr; | ||||||||||
6145 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; | ||||||||||
6146 | SC = SC->getNextSwitchCase()) { | ||||||||||
6147 | Expected<SwitchCase *> ToSCOrErr = import(SC); | ||||||||||
6148 | if (!ToSCOrErr) | ||||||||||
6149 | return ToSCOrErr.takeError(); | ||||||||||
6150 | if (LastChainedSwitchCase) | ||||||||||
6151 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); | ||||||||||
6152 | else | ||||||||||
6153 | ToStmt->setSwitchCaseList(*ToSCOrErr); | ||||||||||
6154 | LastChainedSwitchCase = *ToSCOrErr; | ||||||||||
6155 | } | ||||||||||
6156 | |||||||||||
6157 | return ToStmt; | ||||||||||
6158 | } | ||||||||||
6159 | |||||||||||
6160 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { | ||||||||||
6161 | |||||||||||
6162 | Error Err = Error::success(); | ||||||||||
6163 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); | ||||||||||
6164 | auto ToCond = importChecked(Err, S->getCond()); | ||||||||||
6165 | auto ToBody = importChecked(Err, S->getBody()); | ||||||||||
6166 | auto ToWhileLoc = importChecked(Err, S->getWhileLoc()); | ||||||||||
6167 | auto ToLParenLoc = importChecked(Err, S->getLParenLoc()); | ||||||||||
6168 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | ||||||||||
6169 | if (Err) | ||||||||||
6170 | return std::move(Err); | ||||||||||
6171 | |||||||||||
6172 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, | ||||||||||
6173 | ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc); | ||||||||||
6174 | } | ||||||||||
6175 | |||||||||||
6176 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { | ||||||||||
6177 | |||||||||||
6178 | Error Err = Error::success(); | ||||||||||
6179 | auto ToBody = importChecked(Err, S->getBody()); | ||||||||||
6180 | auto ToCond = importChecked(Err, S->getCond()); | ||||||||||
6181 | auto ToDoLoc = importChecked(Err, S->getDoLoc()); | ||||||||||
6182 | auto ToWhileLoc = importChecked(Err, S->getWhileLoc()); | ||||||||||
6183 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | ||||||||||
6184 | if (Err) | ||||||||||
6185 | return std::move(Err); | ||||||||||
6186 | |||||||||||
6187 | return new (Importer.getToContext()) DoStmt( | ||||||||||
6188 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); | ||||||||||
6189 | } | ||||||||||
6190 | |||||||||||
6191 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { | ||||||||||
6192 | |||||||||||
6193 | Error Err = Error::success(); | ||||||||||
6194 | auto ToInit = importChecked(Err, S->getInit()); | ||||||||||
6195 | auto ToCond = importChecked(Err, S->getCond()); | ||||||||||
6196 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); | ||||||||||
6197 | auto ToInc = importChecked(Err, S->getInc()); | ||||||||||
6198 | auto ToBody = importChecked(Err, S->getBody()); | ||||||||||
6199 | auto ToForLoc = importChecked(Err, S->getForLoc()); | ||||||||||
6200 | auto ToLParenLoc = importChecked(Err, S->getLParenLoc()); | ||||||||||
6201 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | ||||||||||
6202 | if (Err) | ||||||||||
6203 | return std::move(Err); | ||||||||||
6204 | |||||||||||
6205 | return new (Importer.getToContext()) ForStmt( | ||||||||||
6206 | Importer.getToContext(), | ||||||||||
6207 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, | ||||||||||
6208 | ToRParenLoc); | ||||||||||
6209 | } | ||||||||||
6210 | |||||||||||
6211 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { | ||||||||||
6212 | |||||||||||
6213 | Error Err = Error::success(); | ||||||||||
6214 | auto ToLabel = importChecked(Err, S->getLabel()); | ||||||||||
6215 | auto ToGotoLoc = importChecked(Err, S->getGotoLoc()); | ||||||||||
6216 | auto ToLabelLoc = importChecked(Err, S->getLabelLoc()); | ||||||||||
6217 | if (Err) | ||||||||||
6218 | return std::move(Err); | ||||||||||
6219 | |||||||||||
6220 | return new (Importer.getToContext()) GotoStmt( | ||||||||||
6221 | ToLabel, ToGotoLoc, ToLabelLoc); | ||||||||||
6222 | } | ||||||||||
6223 | |||||||||||
6224 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { | ||||||||||
6225 | |||||||||||
6226 | Error Err = Error::success(); | ||||||||||
6227 | auto ToGotoLoc = importChecked(Err, S->getGotoLoc()); | ||||||||||
6228 | auto ToStarLoc = importChecked(Err, S->getStarLoc()); | ||||||||||
6229 | auto ToTarget = importChecked(Err, S->getTarget()); | ||||||||||
6230 | if (Err) | ||||||||||
6231 | return std::move(Err); | ||||||||||
6232 | |||||||||||
6233 | return new (Importer.getToContext()) IndirectGotoStmt( | ||||||||||
6234 | ToGotoLoc, ToStarLoc, ToTarget); | ||||||||||
6235 | } | ||||||||||
6236 | |||||||||||
6237 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { | ||||||||||
6238 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); | ||||||||||
6239 | if (!ToContinueLocOrErr) | ||||||||||
6240 | return ToContinueLocOrErr.takeError(); | ||||||||||
6241 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); | ||||||||||
6242 | } | ||||||||||
6243 | |||||||||||
6244 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { | ||||||||||
6245 | auto ToBreakLocOrErr = import(S->getBreakLoc()); | ||||||||||
6246 | if (!ToBreakLocOrErr) | ||||||||||
6247 | return ToBreakLocOrErr.takeError(); | ||||||||||
6248 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); | ||||||||||
6249 | } | ||||||||||
6250 | |||||||||||
6251 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { | ||||||||||
6252 | |||||||||||
6253 | Error Err = Error::success(); | ||||||||||
6254 | auto ToReturnLoc = importChecked(Err, S->getReturnLoc()); | ||||||||||
6255 | auto ToRetValue = importChecked(Err, S->getRetValue()); | ||||||||||
6256 | auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate()); | ||||||||||
6257 | if (Err) | ||||||||||
6258 | return std::move(Err); | ||||||||||
6259 | |||||||||||
6260 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, | ||||||||||
6261 | ToNRVOCandidate); | ||||||||||
6262 | } | ||||||||||
6263 | |||||||||||
6264 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { | ||||||||||
6265 | |||||||||||
6266 | Error Err = Error::success(); | ||||||||||
6267 | auto ToCatchLoc = importChecked(Err, S->getCatchLoc()); | ||||||||||
6268 | auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl()); | ||||||||||
6269 | auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock()); | ||||||||||
6270 | if (Err) | ||||||||||
6271 | return std::move(Err); | ||||||||||
6272 | |||||||||||
6273 | return new (Importer.getToContext()) CXXCatchStmt ( | ||||||||||
6274 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); | ||||||||||
6275 | } | ||||||||||
6276 | |||||||||||
6277 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { | ||||||||||
6278 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); | ||||||||||
6279 | if (!ToTryLocOrErr) | ||||||||||
6280 | return ToTryLocOrErr.takeError(); | ||||||||||
6281 | |||||||||||
6282 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); | ||||||||||
6283 | if (!ToTryBlockOrErr) | ||||||||||
6284 | return ToTryBlockOrErr.takeError(); | ||||||||||
6285 | |||||||||||
6286 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); | ||||||||||
6287 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { | ||||||||||
6288 | CXXCatchStmt *FromHandler = S->getHandler(HI); | ||||||||||
6289 | if (auto ToHandlerOrErr = import(FromHandler)) | ||||||||||
6290 | ToHandlers[HI] = *ToHandlerOrErr; | ||||||||||
6291 | else | ||||||||||
6292 | return ToHandlerOrErr.takeError(); | ||||||||||
6293 | } | ||||||||||
6294 | |||||||||||
6295 | return CXXTryStmt::Create( | ||||||||||
6296 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); | ||||||||||
6297 | } | ||||||||||
6298 | |||||||||||
6299 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { | ||||||||||
6300 | |||||||||||
6301 | Error Err = Error::success(); | ||||||||||
6302 | auto ToInit = importChecked(Err, S->getInit()); | ||||||||||
6303 | auto ToRangeStmt = importChecked(Err, S->getRangeStmt()); | ||||||||||
6304 | auto ToBeginStmt = importChecked(Err, S->getBeginStmt()); | ||||||||||
6305 | auto ToEndStmt = importChecked(Err, S->getEndStmt()); | ||||||||||
6306 | auto ToCond = importChecked(Err, S->getCond()); | ||||||||||
6307 | auto ToInc = importChecked(Err, S->getInc()); | ||||||||||
6308 | auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt()); | ||||||||||
6309 | auto ToBody = importChecked(Err, S->getBody()); | ||||||||||
6310 | auto ToForLoc = importChecked(Err, S->getForLoc()); | ||||||||||
6311 | auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc()); | ||||||||||
6312 | auto ToColonLoc = importChecked(Err, S->getColonLoc()); | ||||||||||
6313 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | ||||||||||
6314 | if (Err) | ||||||||||
6315 | return std::move(Err); | ||||||||||
6316 | |||||||||||
6317 | return new (Importer.getToContext()) CXXForRangeStmt( | ||||||||||
6318 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, | ||||||||||
6319 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); | ||||||||||
6320 | } | ||||||||||
6321 | |||||||||||
6322 | ExpectedStmt | ||||||||||
6323 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { | ||||||||||
6324 | Error Err = Error::success(); | ||||||||||
6325 | auto ToElement = importChecked(Err, S->getElement()); | ||||||||||
6326 | auto ToCollection = importChecked(Err, S->getCollection()); | ||||||||||
6327 | auto ToBody = importChecked(Err, S->getBody()); | ||||||||||
6328 | auto ToForLoc = importChecked(Err, S->getForLoc()); | ||||||||||
6329 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | ||||||||||
6330 | if (Err) | ||||||||||
6331 | return std::move(Err); | ||||||||||
6332 | |||||||||||
6333 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, | ||||||||||
6334 | ToCollection, | ||||||||||
6335 | ToBody, | ||||||||||
6336 | ToForLoc, | ||||||||||
6337 | ToRParenLoc); | ||||||||||
6338 | } | ||||||||||
6339 | |||||||||||
6340 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { | ||||||||||
6341 | |||||||||||
6342 | Error Err = Error::success(); | ||||||||||
6343 | auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc()); | ||||||||||
6344 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); | ||||||||||
6345 | auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl()); | ||||||||||
6346 | auto ToCatchBody = importChecked(Err, S->getCatchBody()); | ||||||||||
6347 | if (Err) | ||||||||||
6348 | return std::move(Err); | ||||||||||
6349 | |||||||||||
6350 | return new (Importer.getToContext()) ObjCAtCatchStmt ( | ||||||||||
6351 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); | ||||||||||
6352 | } | ||||||||||
6353 | |||||||||||
6354 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { | ||||||||||
6355 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); | ||||||||||
6356 | if (!ToAtFinallyLocOrErr) | ||||||||||
6357 | return ToAtFinallyLocOrErr.takeError(); | ||||||||||
6358 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); | ||||||||||
6359 | if (!ToAtFinallyStmtOrErr) | ||||||||||
6360 | return ToAtFinallyStmtOrErr.takeError(); | ||||||||||
6361 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, | ||||||||||
6362 | *ToAtFinallyStmtOrErr); | ||||||||||
6363 | } | ||||||||||
6364 | |||||||||||
6365 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { | ||||||||||
6366 | |||||||||||
6367 | Error Err = Error::success(); | ||||||||||
6368 | auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc()); | ||||||||||
6369 | auto ToTryBody = importChecked(Err, S->getTryBody()); | ||||||||||
6370 | auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt()); | ||||||||||
6371 | if (Err) | ||||||||||
6372 | return std::move(Err); | ||||||||||
6373 | |||||||||||
6374 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); | ||||||||||
6375 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { | ||||||||||
6376 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); | ||||||||||
6377 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) | ||||||||||
6378 | ToCatchStmts[CI] = *ToCatchStmtOrErr; | ||||||||||
6379 | else | ||||||||||
6380 | return ToCatchStmtOrErr.takeError(); | ||||||||||
6381 | } | ||||||||||
6382 | |||||||||||
6383 | return ObjCAtTryStmt::Create(Importer.getToContext(), | ||||||||||
6384 | ToAtTryLoc, ToTryBody, | ||||||||||
6385 | ToCatchStmts.begin(), ToCatchStmts.size(), | ||||||||||
6386 | ToFinallyStmt); | ||||||||||
6387 | } | ||||||||||
6388 | |||||||||||
6389 | ExpectedStmt | ||||||||||
6390 | ASTNodeImporter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { | ||||||||||
6391 | |||||||||||
6392 | Error Err = Error::success(); | ||||||||||
6393 | auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc()); | ||||||||||
6394 | auto ToSynchExpr = importChecked(Err, S->getSynchExpr()); | ||||||||||
6395 | auto ToSynchBody = importChecked(Err, S->getSynchBody()); | ||||||||||
6396 | if (Err) | ||||||||||
6397 | return std::move(Err); | ||||||||||
6398 | |||||||||||
6399 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( | ||||||||||
6400 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); | ||||||||||
6401 | } | ||||||||||
6402 | |||||||||||
6403 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { | ||||||||||
6404 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); | ||||||||||
6405 | if (!ToThrowLocOrErr) | ||||||||||
6406 | return ToThrowLocOrErr.takeError(); | ||||||||||
6407 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); | ||||||||||
6408 | if (!ToThrowExprOrErr) | ||||||||||
6409 | return ToThrowExprOrErr.takeError(); | ||||||||||
6410 | return new (Importer.getToContext()) ObjCAtThrowStmt( | ||||||||||
6411 | *ToThrowLocOrErr, *ToThrowExprOrErr); | ||||||||||
6412 | } | ||||||||||
6413 | |||||||||||
6414 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( | ||||||||||
6415 | ObjCAutoreleasePoolStmt *S) { | ||||||||||
6416 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); | ||||||||||
6417 | if (!ToAtLocOrErr) | ||||||||||
6418 | return ToAtLocOrErr.takeError(); | ||||||||||
6419 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); | ||||||||||
6420 | if (!ToSubStmtOrErr) | ||||||||||
6421 | return ToSubStmtOrErr.takeError(); | ||||||||||
6422 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, | ||||||||||
6423 | *ToSubStmtOrErr); | ||||||||||
6424 | } | ||||||||||
6425 | |||||||||||
6426 | //---------------------------------------------------------------------------- | ||||||||||
6427 | // Import Expressions | ||||||||||
6428 | //---------------------------------------------------------------------------- | ||||||||||
6429 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { | ||||||||||
6430 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) | ||||||||||
6431 | << E->getStmtClassName(); | ||||||||||
6432 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | ||||||||||
6433 | } | ||||||||||
6434 | |||||||||||
6435 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { | ||||||||||
6436 | |||||||||||
6437 | Error Err = Error::success(); | ||||||||||
6438 | auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); | ||||||||||
6439 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | ||||||||||
6440 | auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo()); | ||||||||||
6441 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||||||
6442 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
6443 | if (Err) | ||||||||||
6444 | return std::move(Err); | ||||||||||
6445 | |||||||||||
6446 | return new (Importer.getToContext()) VAArgExpr( | ||||||||||
6447 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, | ||||||||||
6448 | E->isMicrosoftABI()); | ||||||||||
6449 | } | ||||||||||
6450 | |||||||||||
6451 | ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) { | ||||||||||
6452 | |||||||||||
6453 | Error Err = Error::success(); | ||||||||||
6454 | auto ToCond = importChecked(Err, E->getCond()); | ||||||||||
6455 | auto ToLHS = importChecked(Err, E->getLHS()); | ||||||||||
6456 | auto ToRHS = importChecked(Err, E->getRHS()); | ||||||||||
6457 | auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); | ||||||||||
6458 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||||||
6459 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
6460 | if (Err) | ||||||||||
6461 | return std::move(Err); | ||||||||||
6462 | |||||||||||
6463 | ExprValueKind VK = E->getValueKind(); | ||||||||||
6464 | ExprObjectKind OK = E->getObjectKind(); | ||||||||||
6465 | |||||||||||
6466 | // The value of CondIsTrue only matters if the value is not | ||||||||||
6467 | // condition-dependent. | ||||||||||
6468 | bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue(); | ||||||||||
6469 | |||||||||||
6470 | return new (Importer.getToContext()) | ||||||||||
6471 | ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK, | ||||||||||
6472 | ToRParenLoc, CondIsTrue); | ||||||||||
6473 | } | ||||||||||
6474 | |||||||||||
6475 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { | ||||||||||
6476 | ExpectedType TypeOrErr = import(E->getType()); | ||||||||||
6477 | if (!TypeOrErr) | ||||||||||
6478 | return TypeOrErr.takeError(); | ||||||||||
6479 | |||||||||||
6480 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); | ||||||||||
6481 | if (!BeginLocOrErr) | ||||||||||
6482 | return BeginLocOrErr.takeError(); | ||||||||||
6483 | |||||||||||
6484 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); | ||||||||||
6485 | } | ||||||||||
6486 | |||||||||||
6487 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { | ||||||||||
6488 | |||||||||||
6489 | Error Err = Error::success(); | ||||||||||
6490 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); | ||||||||||
6491 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
6492 | auto ToFunctionName = importChecked(Err, E->getFunctionName()); | ||||||||||
6493 | if (Err) | ||||||||||
6494 | return std::move(Err); | ||||||||||
6495 | |||||||||||
6496 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, | ||||||||||
6497 | E->getIdentKind(), ToFunctionName); | ||||||||||
6498 | } | ||||||||||
6499 | |||||||||||
6500 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { | ||||||||||
6501 | |||||||||||
6502 | Error Err = Error::success(); | ||||||||||
6503 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); | ||||||||||
6504 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); | ||||||||||
6505 | auto ToDecl = importChecked(Err, E->getDecl()); | ||||||||||
6506 | auto ToLocation = importChecked(Err, E->getLocation()); | ||||||||||
6507 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
6508 | if (Err) | ||||||||||
6509 | return std::move(Err); | ||||||||||
6510 | |||||||||||
6511 | NamedDecl *ToFoundD = nullptr; | ||||||||||
6512 | if (E->getDecl() != E->getFoundDecl()) { | ||||||||||
6513 | auto FoundDOrErr = import(E->getFoundDecl()); | ||||||||||
6514 | if (!FoundDOrErr) | ||||||||||
6515 | return FoundDOrErr.takeError(); | ||||||||||
6516 | ToFoundD = *FoundDOrErr; | ||||||||||
6517 | } | ||||||||||
6518 | |||||||||||
6519 | TemplateArgumentListInfo ToTAInfo; | ||||||||||
6520 | TemplateArgumentListInfo *ToResInfo = nullptr; | ||||||||||
6521 | if (E->hasExplicitTemplateArgs()) { | ||||||||||
6522 | if (Error Err = | ||||||||||
6523 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), | ||||||||||
6524 | E->template_arguments(), ToTAInfo)) | ||||||||||
6525 | return std::move(Err); | ||||||||||
6526 | ToResInfo = &ToTAInfo; | ||||||||||
6527 | } | ||||||||||
6528 | |||||||||||
6529 | auto *ToE = DeclRefExpr::Create( | ||||||||||
6530 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, | ||||||||||
6531 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, | ||||||||||
6532 | E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse()); | ||||||||||
6533 | if (E->hadMultipleCandidates()) | ||||||||||
6534 | ToE->setHadMultipleCandidates(true); | ||||||||||
6535 | return ToE; | ||||||||||
6536 | } | ||||||||||
6537 | |||||||||||
6538 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { | ||||||||||
6539 | ExpectedType TypeOrErr = import(E->getType()); | ||||||||||
6540 | if (!TypeOrErr) | ||||||||||
6541 | return TypeOrErr.takeError(); | ||||||||||
6542 | |||||||||||
6543 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); | ||||||||||
6544 | } | ||||||||||
6545 | |||||||||||
6546 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { | ||||||||||
6547 | ExpectedExpr ToInitOrErr = import(E->getInit()); | ||||||||||
6548 | if (!ToInitOrErr) | ||||||||||
6549 | return ToInitOrErr.takeError(); | ||||||||||
6550 | |||||||||||
6551 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); | ||||||||||
6552 | if (!ToEqualOrColonLocOrErr) | ||||||||||
6553 | return ToEqualOrColonLocOrErr.takeError(); | ||||||||||
6554 | |||||||||||
6555 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); | ||||||||||
6556 | // List elements from the second, the first is Init itself | ||||||||||
6557 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { | ||||||||||
6558 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) | ||||||||||
6559 | ToIndexExprs[I - 1] = *ToArgOrErr; | ||||||||||
6560 | else | ||||||||||
6561 | return ToArgOrErr.takeError(); | ||||||||||
6562 | } | ||||||||||
6563 | |||||||||||
6564 | SmallVector<Designator, 4> ToDesignators(E->size()); | ||||||||||
6565 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) | ||||||||||
6566 | return std::move(Err); | ||||||||||
6567 | |||||||||||
6568 | return DesignatedInitExpr::Create( | ||||||||||
6569 | Importer.getToContext(), ToDesignators, | ||||||||||
6570 | ToIndexExprs, *ToEqualOrColonLocOrErr, | ||||||||||
6571 | E->usesGNUSyntax(), *ToInitOrErr); | ||||||||||
6572 | } | ||||||||||
6573 | |||||||||||
6574 | ExpectedStmt | ||||||||||
6575 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { | ||||||||||
6576 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||||||
6577 | if (!ToTypeOrErr) | ||||||||||
6578 | return ToTypeOrErr.takeError(); | ||||||||||
6579 | |||||||||||
6580 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | ||||||||||
6581 | if (!ToLocationOrErr) | ||||||||||
6582 | return ToLocationOrErr.takeError(); | ||||||||||
6583 | |||||||||||
6584 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( | ||||||||||
6585 | *ToTypeOrErr, *ToLocationOrErr); | ||||||||||
6586 | } | ||||||||||
6587 | |||||||||||
6588 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { | ||||||||||
6589 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||||||
6590 | if (!ToTypeOrErr) | ||||||||||
6591 | return ToTypeOrErr.takeError(); | ||||||||||
6592 | |||||||||||
6593 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | ||||||||||
6594 | if (!ToLocationOrErr) | ||||||||||
6595 | return ToLocationOrErr.takeError(); | ||||||||||
6596 | |||||||||||
6597 | return IntegerLiteral::Create( | ||||||||||
6598 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); | ||||||||||
6599 | } | ||||||||||
6600 | |||||||||||
6601 | |||||||||||
6602 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { | ||||||||||
6603 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||||||
6604 | if (!ToTypeOrErr) | ||||||||||
6605 | return ToTypeOrErr.takeError(); | ||||||||||
6606 | |||||||||||
6607 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | ||||||||||
6608 | if (!ToLocationOrErr) | ||||||||||
6609 | return ToLocationOrErr.takeError(); | ||||||||||
6610 | |||||||||||
6611 | return FloatingLiteral::Create( | ||||||||||
6612 | Importer.getToContext(), E->getValue(), E->isExact(), | ||||||||||
6613 | *ToTypeOrErr, *ToLocationOrErr); | ||||||||||
6614 | } | ||||||||||
6615 | |||||||||||
6616 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { | ||||||||||
6617 | auto ToTypeOrErr = import(E->getType()); | ||||||||||
6618 | if (!ToTypeOrErr) | ||||||||||
6619 | return ToTypeOrErr.takeError(); | ||||||||||
6620 | |||||||||||
6621 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | ||||||||||
6622 | if (!ToSubExprOrErr) | ||||||||||
6623 | return ToSubExprOrErr.takeError(); | ||||||||||
6624 | |||||||||||
6625 | return new (Importer.getToContext()) ImaginaryLiteral( | ||||||||||
6626 | *ToSubExprOrErr, *ToTypeOrErr); | ||||||||||
6627 | } | ||||||||||
6628 | |||||||||||
6629 | ExpectedStmt ASTNodeImporter::VisitFixedPointLiteral(FixedPointLiteral *E) { | ||||||||||
6630 | auto ToTypeOrErr = import(E->getType()); | ||||||||||
6631 | if (!ToTypeOrErr) | ||||||||||
6632 | return ToTypeOrErr.takeError(); | ||||||||||
6633 | |||||||||||
6634 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | ||||||||||
6635 | if (!ToLocationOrErr) | ||||||||||
6636 | return ToLocationOrErr.takeError(); | ||||||||||
6637 | |||||||||||
6638 | return new (Importer.getToContext()) FixedPointLiteral( | ||||||||||
6639 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr, | ||||||||||
6640 | Importer.getToContext().getFixedPointScale(*ToTypeOrErr)); | ||||||||||
6641 | } | ||||||||||
6642 | |||||||||||
6643 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { | ||||||||||
6644 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||||||
6645 | if (!ToTypeOrErr) | ||||||||||
6646 | return ToTypeOrErr.takeError(); | ||||||||||
6647 | |||||||||||
6648 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | ||||||||||
6649 | if (!ToLocationOrErr) | ||||||||||
6650 | return ToLocationOrErr.takeError(); | ||||||||||
6651 | |||||||||||
6652 | return new (Importer.getToContext()) CharacterLiteral( | ||||||||||
6653 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); | ||||||||||
6654 | } | ||||||||||
6655 | |||||||||||
6656 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { | ||||||||||
6657 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||||||
6658 | if (!ToTypeOrErr) | ||||||||||
6659 | return ToTypeOrErr.takeError(); | ||||||||||
6660 | |||||||||||
6661 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); | ||||||||||
6662 | if (Error Err = ImportArrayChecked( | ||||||||||
6663 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) | ||||||||||
6664 | return std::move(Err); | ||||||||||
6665 | |||||||||||
6666 | return StringLiteral::Create( | ||||||||||
6667 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), | ||||||||||
6668 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); | ||||||||||
6669 | } | ||||||||||
6670 | |||||||||||
6671 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { | ||||||||||
6672 | |||||||||||
6673 | Error Err = Error::success(); | ||||||||||
6674 | auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); | ||||||||||
6675 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); | ||||||||||
6676 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
6677 | auto ToInitializer = importChecked(Err, E->getInitializer()); | ||||||||||
6678 | if (Err) | ||||||||||
6679 | return std::move(Err); | ||||||||||
6680 | |||||||||||
6681 | return new (Importer.getToContext()) CompoundLiteralExpr( | ||||||||||
6682 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), | ||||||||||
6683 | ToInitializer, E->isFileScope()); | ||||||||||
6684 | } | ||||||||||
6685 | |||||||||||
6686 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { | ||||||||||
6687 | |||||||||||
6688 | Error Err = Error::success(); | ||||||||||
6689 | auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); | ||||||||||
6690 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
6691 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||||||
6692 | if (Err) | ||||||||||
6693 | return std::move(Err); | ||||||||||
6694 | |||||||||||
6695 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); | ||||||||||
6696 | if (Error Err = ImportArrayChecked( | ||||||||||
6697 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), | ||||||||||
6698 | ToExprs.begin())) | ||||||||||
6699 | return std::move(Err); | ||||||||||
6700 | |||||||||||
6701 | return new (Importer.getToContext()) AtomicExpr( | ||||||||||
6702 | |||||||||||
6703 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); | ||||||||||
6704 | } | ||||||||||
6705 | |||||||||||
6706 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { | ||||||||||
6707 | Error Err = Error::success(); | ||||||||||
6708 | auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc()); | ||||||||||
6709 | auto ToLabelLoc = importChecked(Err, E->getLabelLoc()); | ||||||||||
6710 | auto ToLabel = importChecked(Err, E->getLabel()); | ||||||||||
6711 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
6712 | if (Err) | ||||||||||
6713 | return std::move(Err); | ||||||||||
6714 | |||||||||||
6715 | return new (Importer.getToContext()) AddrLabelExpr( | ||||||||||
6716 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); | ||||||||||
6717 | } | ||||||||||
6718 | ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { | ||||||||||
6719 | Error Err = Error::success(); | ||||||||||
6720 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | ||||||||||
6721 | auto ToResult = importChecked(Err, E->getAPValueResult()); | ||||||||||
6722 | if (Err) | ||||||||||
6723 | return std::move(Err); | ||||||||||
6724 | |||||||||||
6725 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult); | ||||||||||
6726 | } | ||||||||||
6727 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { | ||||||||||
6728 | Error Err = Error::success(); | ||||||||||
6729 | auto ToLParen = importChecked(Err, E->getLParen()); | ||||||||||
6730 | auto ToRParen = importChecked(Err, E->getRParen()); | ||||||||||
6731 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | ||||||||||
6732 | if (Err) | ||||||||||
6733 | return std::move(Err); | ||||||||||
6734 | |||||||||||
6735 | return new (Importer.getToContext()) | ||||||||||
6736 | ParenExpr(ToLParen, ToRParen, ToSubExpr); | ||||||||||
6737 | } | ||||||||||
6738 | |||||||||||
6739 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { | ||||||||||
6740 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); | ||||||||||
6741 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) | ||||||||||
6742 | return std::move(Err); | ||||||||||
6743 | |||||||||||
6744 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); | ||||||||||
6745 | if (!ToLParenLocOrErr) | ||||||||||
6746 | return ToLParenLocOrErr.takeError(); | ||||||||||
6747 | |||||||||||
6748 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); | ||||||||||
6749 | if (!ToRParenLocOrErr) | ||||||||||
6750 | return ToRParenLocOrErr.takeError(); | ||||||||||
6751 | |||||||||||
6752 | return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr, | ||||||||||
6753 | ToExprs, *ToRParenLocOrErr); | ||||||||||
6754 | } | ||||||||||
6755 | |||||||||||
6756 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { | ||||||||||
6757 | Error Err = Error::success(); | ||||||||||
6758 | auto ToSubStmt = importChecked(Err, E->getSubStmt()); | ||||||||||
6759 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
6760 | auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); | ||||||||||
6761 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||||||
6762 | if (Err) | ||||||||||
6763 | return std::move(Err); | ||||||||||
6764 | |||||||||||
6765 | return new (Importer.getToContext()) | ||||||||||
6766 | StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc, | ||||||||||
6767 | E->getTemplateDepth()); | ||||||||||
6768 | } | ||||||||||
6769 | |||||||||||
6770 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { | ||||||||||
6771 | Error Err = Error::success(); | ||||||||||
6772 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | ||||||||||
6773 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
6774 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||||||
6775 | if (Err) | ||||||||||
6776 | return std::move(Err); | ||||||||||
6777 | |||||||||||
6778 | return UnaryOperator::Create( | ||||||||||
6779 | Importer.getToContext(), ToSubExpr, E->getOpcode(), ToType, | ||||||||||
6780 | E->getValueKind(), E->getObjectKind(), ToOperatorLoc, E->canOverflow(), | ||||||||||
6781 | E->getFPOptionsOverride()); | ||||||||||
6782 | } | ||||||||||
6783 | |||||||||||
6784 | ExpectedStmt | ||||||||||
6785 | |||||||||||
6786 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { | ||||||||||
6787 | Error Err = Error::success(); | ||||||||||
6788 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
6789 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||||||
6790 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||||||
6791 | if (Err) | ||||||||||
6792 | return std::move(Err); | ||||||||||
6793 | |||||||||||
6794 | if (E->isArgumentType()) { | ||||||||||
6795 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = | ||||||||||
6796 | import(E->getArgumentTypeInfo()); | ||||||||||
6797 | if (!ToArgumentTypeInfoOrErr) | ||||||||||
6798 | return ToArgumentTypeInfoOrErr.takeError(); | ||||||||||
6799 | |||||||||||
6800 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( | ||||||||||
6801 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, | ||||||||||
6802 | ToRParenLoc); | ||||||||||
6803 | } | ||||||||||
6804 | |||||||||||
6805 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); | ||||||||||
6806 | if (!ToArgumentExprOrErr) | ||||||||||
6807 | return ToArgumentExprOrErr.takeError(); | ||||||||||
6808 | |||||||||||
6809 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( | ||||||||||
6810 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); | ||||||||||
6811 | } | ||||||||||
6812 | |||||||||||
6813 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { | ||||||||||
6814 | Error Err = Error::success(); | ||||||||||
6815 | auto ToLHS = importChecked(Err, E->getLHS()); | ||||||||||
6816 | auto ToRHS = importChecked(Err, E->getRHS()); | ||||||||||
6817 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
6818 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||||||
6819 | if (Err) | ||||||||||
6820 | return std::move(Err); | ||||||||||
6821 | |||||||||||
6822 | return BinaryOperator::Create( | ||||||||||
6823 | Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType, | ||||||||||
6824 | E->getValueKind(), E->getObjectKind(), ToOperatorLoc, | ||||||||||
6825 | E->getFPFeatures(Importer.getFromContext().getLangOpts())); | ||||||||||
6826 | } | ||||||||||
6827 | |||||||||||
6828 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { | ||||||||||
6829 | Error Err = Error::success(); | ||||||||||
6830 | auto ToCond = importChecked(Err, E->getCond()); | ||||||||||
6831 | auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc()); | ||||||||||
6832 | auto ToLHS = importChecked(Err, E->getLHS()); | ||||||||||
6833 | auto ToColonLoc = importChecked(Err, E->getColonLoc()); | ||||||||||
6834 | auto ToRHS = importChecked(Err, E->getRHS()); | ||||||||||
6835 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
6836 | if (Err) | ||||||||||
6837 | return std::move(Err); | ||||||||||
6838 | |||||||||||
6839 | return new (Importer.getToContext()) ConditionalOperator( | ||||||||||
6840 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, | ||||||||||
6841 | E->getValueKind(), E->getObjectKind()); | ||||||||||
6842 | } | ||||||||||
6843 | |||||||||||
6844 | ExpectedStmt | ||||||||||
6845 | ASTNodeImporter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) { | ||||||||||
6846 | Error Err = Error::success(); | ||||||||||
6847 | auto ToCommon = importChecked(Err, E->getCommon()); | ||||||||||
6848 | auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue()); | ||||||||||
6849 | auto ToCond = importChecked(Err, E->getCond()); | ||||||||||
6850 | auto ToTrueExpr = importChecked(Err, E->getTrueExpr()); | ||||||||||
6851 | auto ToFalseExpr = importChecked(Err, E->getFalseExpr()); | ||||||||||
6852 | auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc()); | ||||||||||
6853 | auto ToColonLoc = importChecked(Err, E->getColonLoc()); | ||||||||||
6854 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
6855 | if (Err) | ||||||||||
6856 | return std::move(Err); | ||||||||||
6857 | |||||||||||
6858 | return new (Importer.getToContext()) BinaryConditionalOperator( | ||||||||||
6859 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, | ||||||||||
6860 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), | ||||||||||
6861 | E->getObjectKind()); | ||||||||||
6862 | } | ||||||||||
6863 | |||||||||||
6864 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { | ||||||||||
6865 | Error Err = Error::success(); | ||||||||||
6866 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); | ||||||||||
6867 | auto ToQueriedTypeSourceInfo = | ||||||||||
6868 | importChecked(Err, E->getQueriedTypeSourceInfo()); | ||||||||||
6869 | auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression()); | ||||||||||
6870 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); | ||||||||||
6871 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
6872 | if (Err) | ||||||||||
6873 | return std::move(Err); | ||||||||||
6874 | |||||||||||
6875 | return new (Importer.getToContext()) ArrayTypeTraitExpr( | ||||||||||
6876 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), | ||||||||||
6877 | ToDimensionExpression, ToEndLoc, ToType); | ||||||||||
6878 | } | ||||||||||
6879 | |||||||||||
6880 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { | ||||||||||
6881 | Error Err = Error::success(); | ||||||||||
6882 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); | ||||||||||
6883 | auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression()); | ||||||||||
6884 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); | ||||||||||
6885 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
6886 | if (Err) | ||||||||||
6887 | return std::move(Err); | ||||||||||
6888 | |||||||||||
6889 | return new (Importer.getToContext()) ExpressionTraitExpr( | ||||||||||
6890 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), | ||||||||||
6891 | ToEndLoc, ToType); | ||||||||||
6892 | } | ||||||||||
6893 | |||||||||||
6894 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { | ||||||||||
6895 | Error Err = Error::success(); | ||||||||||
6896 | auto ToLocation = importChecked(Err, E->getLocation()); | ||||||||||
6897 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
6898 | auto ToSourceExpr = importChecked(Err, E->getSourceExpr()); | ||||||||||
6899 | if (Err) | ||||||||||
6900 | return std::move(Err); | ||||||||||
6901 | |||||||||||
6902 | return new (Importer.getToContext()) OpaqueValueExpr( | ||||||||||
6903 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); | ||||||||||
6904 | } | ||||||||||
6905 | |||||||||||
6906 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { | ||||||||||
6907 | Error Err = Error::success(); | ||||||||||
6908 | auto ToLHS = importChecked(Err, E->getLHS()); | ||||||||||
6909 | auto ToRHS = importChecked(Err, E->getRHS()); | ||||||||||
6910 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
6911 | auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc()); | ||||||||||
6912 | if (Err) | ||||||||||
6913 | return std::move(Err); | ||||||||||
6914 | |||||||||||
6915 | return new (Importer.getToContext()) ArraySubscriptExpr( | ||||||||||
6916 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), | ||||||||||
6917 | ToRBracketLoc); | ||||||||||
6918 | } | ||||||||||
6919 | |||||||||||
6920 | ExpectedStmt | ||||||||||
6921 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { | ||||||||||
6922 | Error Err = Error::success(); | ||||||||||
6923 | auto ToLHS = importChecked(Err, E->getLHS()); | ||||||||||
6924 | auto ToRHS = importChecked(Err, E->getRHS()); | ||||||||||
6925 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
6926 | auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType()); | ||||||||||
6927 | auto ToComputationResultType = | ||||||||||
6928 | importChecked(Err, E->getComputationResultType()); | ||||||||||
6929 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||||||
6930 | if (Err) | ||||||||||
6931 | return std::move(Err); | ||||||||||
6932 | |||||||||||
6933 | return CompoundAssignOperator::Create( | ||||||||||
6934 | Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType, | ||||||||||
6935 | E->getValueKind(), E->getObjectKind(), ToOperatorLoc, | ||||||||||
6936 | E->getFPFeatures(Importer.getFromContext().getLangOpts()), | ||||||||||
6937 | ToComputationLHSType, ToComputationResultType); | ||||||||||
6938 | } | ||||||||||
6939 | |||||||||||
6940 | Expected<CXXCastPath> | ||||||||||
6941 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { | ||||||||||
6942 | CXXCastPath Path; | ||||||||||
6943 | for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) { | ||||||||||
6944 | if (auto SpecOrErr = import(*I)) | ||||||||||
6945 | Path.push_back(*SpecOrErr); | ||||||||||
6946 | else | ||||||||||
6947 | return SpecOrErr.takeError(); | ||||||||||
6948 | } | ||||||||||
6949 | return Path; | ||||||||||
6950 | } | ||||||||||
6951 | |||||||||||
6952 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { | ||||||||||
6953 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||||||
6954 | if (!ToTypeOrErr) | ||||||||||
6955 | return ToTypeOrErr.takeError(); | ||||||||||
6956 | |||||||||||
6957 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | ||||||||||
6958 | if (!ToSubExprOrErr) | ||||||||||
6959 | return ToSubExprOrErr.takeError(); | ||||||||||
6960 | |||||||||||
6961 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); | ||||||||||
6962 | if (!ToBasePathOrErr) | ||||||||||
6963 | return ToBasePathOrErr.takeError(); | ||||||||||
6964 | |||||||||||
6965 | return ImplicitCastExpr::Create( | ||||||||||
6966 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, | ||||||||||
6967 | &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures()); | ||||||||||
6968 | } | ||||||||||
6969 | |||||||||||
6970 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { | ||||||||||
6971 | Error Err = Error::success(); | ||||||||||
6972 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
6973 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | ||||||||||
6974 | auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten()); | ||||||||||
6975 | if (Err) | ||||||||||
6976 | return std::move(Err); | ||||||||||
6977 | |||||||||||
6978 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); | ||||||||||
6979 | if (!ToBasePathOrErr) | ||||||||||
6980 | return ToBasePathOrErr.takeError(); | ||||||||||
6981 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); | ||||||||||
6982 | |||||||||||
6983 | switch (E->getStmtClass()) { | ||||||||||
6984 | case Stmt::CStyleCastExprClass: { | ||||||||||
6985 | auto *CCE = cast<CStyleCastExpr>(E); | ||||||||||
6986 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); | ||||||||||
6987 | if (!ToLParenLocOrErr) | ||||||||||
6988 | return ToLParenLocOrErr.takeError(); | ||||||||||
6989 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); | ||||||||||
6990 | if (!ToRParenLocOrErr) | ||||||||||
6991 | return ToRParenLocOrErr.takeError(); | ||||||||||
6992 | return CStyleCastExpr::Create( | ||||||||||
6993 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), | ||||||||||
6994 | ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten, | ||||||||||
6995 | *ToLParenLocOrErr, *ToRParenLocOrErr); | ||||||||||
6996 | } | ||||||||||
6997 | |||||||||||
6998 | case Stmt::CXXFunctionalCastExprClass: { | ||||||||||
6999 | auto *FCE = cast<CXXFunctionalCastExpr>(E); | ||||||||||
7000 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); | ||||||||||
7001 | if (!ToLParenLocOrErr) | ||||||||||
7002 | return ToLParenLocOrErr.takeError(); | ||||||||||
7003 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); | ||||||||||
7004 | if (!ToRParenLocOrErr) | ||||||||||
7005 | return ToRParenLocOrErr.takeError(); | ||||||||||
7006 | return CXXFunctionalCastExpr::Create( | ||||||||||
7007 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, | ||||||||||
7008 | E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(), | ||||||||||
7009 | *ToLParenLocOrErr, *ToRParenLocOrErr); | ||||||||||
7010 | } | ||||||||||
7011 | |||||||||||
7012 | case Stmt::ObjCBridgedCastExprClass: { | ||||||||||
7013 | auto *OCE = cast<ObjCBridgedCastExpr>(E); | ||||||||||
7014 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); | ||||||||||
7015 | if (!ToLParenLocOrErr) | ||||||||||
7016 | return ToLParenLocOrErr.takeError(); | ||||||||||
7017 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); | ||||||||||
7018 | if (!ToBridgeKeywordLocOrErr) | ||||||||||
7019 | return ToBridgeKeywordLocOrErr.takeError(); | ||||||||||
7020 | return new (Importer.getToContext()) ObjCBridgedCastExpr( | ||||||||||
7021 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), | ||||||||||
7022 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); | ||||||||||
7023 | } | ||||||||||
7024 | default: | ||||||||||
7025 | llvm_unreachable("Cast expression of unsupported type!")::llvm::llvm_unreachable_internal("Cast expression of unsupported type!" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 7025); | ||||||||||
7026 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | ||||||||||
7027 | } | ||||||||||
7028 | } | ||||||||||
7029 | |||||||||||
7030 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { | ||||||||||
7031 | SmallVector<OffsetOfNode, 4> ToNodes; | ||||||||||
7032 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { | ||||||||||
7033 | const OffsetOfNode &FromNode = E->getComponent(I); | ||||||||||
7034 | |||||||||||
7035 | SourceLocation ToBeginLoc, ToEndLoc; | ||||||||||
7036 | |||||||||||
7037 | if (FromNode.getKind() != OffsetOfNode::Base) { | ||||||||||
7038 | Error Err = Error::success(); | ||||||||||
7039 | ToBeginLoc = importChecked(Err, FromNode.getBeginLoc()); | ||||||||||
7040 | ToEndLoc = importChecked(Err, FromNode.getEndLoc()); | ||||||||||
7041 | if (Err) | ||||||||||
7042 | return std::move(Err); | ||||||||||
7043 | } | ||||||||||
7044 | |||||||||||
7045 | switch (FromNode.getKind()) { | ||||||||||
7046 | case OffsetOfNode::Array: | ||||||||||
7047 | ToNodes.push_back( | ||||||||||
7048 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); | ||||||||||
7049 | break; | ||||||||||
7050 | case OffsetOfNode::Base: { | ||||||||||
7051 | auto ToBSOrErr = import(FromNode.getBase()); | ||||||||||
7052 | if (!ToBSOrErr) | ||||||||||
7053 | return ToBSOrErr.takeError(); | ||||||||||
7054 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); | ||||||||||
7055 | break; | ||||||||||
7056 | } | ||||||||||
7057 | case OffsetOfNode::Field: { | ||||||||||
7058 | auto ToFieldOrErr = import(FromNode.getField()); | ||||||||||
7059 | if (!ToFieldOrErr) | ||||||||||
7060 | return ToFieldOrErr.takeError(); | ||||||||||
7061 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); | ||||||||||
7062 | break; | ||||||||||
7063 | } | ||||||||||
7064 | case OffsetOfNode::Identifier: { | ||||||||||
7065 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); | ||||||||||
7066 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); | ||||||||||
7067 | break; | ||||||||||
7068 | } | ||||||||||
7069 | } | ||||||||||
7070 | } | ||||||||||
7071 | |||||||||||
7072 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); | ||||||||||
7073 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { | ||||||||||
7074 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); | ||||||||||
7075 | if (!ToIndexExprOrErr) | ||||||||||
7076 | return ToIndexExprOrErr.takeError(); | ||||||||||
7077 | ToExprs[I] = *ToIndexExprOrErr; | ||||||||||
7078 | } | ||||||||||
7079 | |||||||||||
7080 | Error Err = Error::success(); | ||||||||||
7081 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7082 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); | ||||||||||
7083 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||||||
7084 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||||||
7085 | if (Err) | ||||||||||
7086 | return std::move(Err); | ||||||||||
7087 | |||||||||||
7088 | return OffsetOfExpr::Create( | ||||||||||
7089 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, | ||||||||||
7090 | ToExprs, ToRParenLoc); | ||||||||||
7091 | } | ||||||||||
7092 | |||||||||||
7093 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { | ||||||||||
7094 | Error Err = Error::success(); | ||||||||||
7095 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7096 | auto ToOperand = importChecked(Err, E->getOperand()); | ||||||||||
7097 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); | ||||||||||
7098 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); | ||||||||||
7099 | if (Err) | ||||||||||
7100 | return std::move(Err); | ||||||||||
7101 | |||||||||||
7102 | CanThrowResult ToCanThrow; | ||||||||||
7103 | if (E->isValueDependent()) | ||||||||||
7104 | ToCanThrow = CT_Dependent; | ||||||||||
7105 | else | ||||||||||
7106 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; | ||||||||||
7107 | |||||||||||
7108 | return new (Importer.getToContext()) CXXNoexceptExpr( | ||||||||||
7109 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); | ||||||||||
7110 | } | ||||||||||
7111 | |||||||||||
7112 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { | ||||||||||
7113 | Error Err = Error::success(); | ||||||||||
7114 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | ||||||||||
7115 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7116 | auto ToThrowLoc = importChecked(Err, E->getThrowLoc()); | ||||||||||
7117 | if (Err) | ||||||||||
7118 | return std::move(Err); | ||||||||||
7119 | |||||||||||
7120 | return new (Importer.getToContext()) CXXThrowExpr( | ||||||||||
7121 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); | ||||||||||
7122 | } | ||||||||||
7123 | |||||||||||
7124 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { | ||||||||||
7125 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); | ||||||||||
7126 | if (!ToUsedLocOrErr) | ||||||||||
7127 | return ToUsedLocOrErr.takeError(); | ||||||||||
7128 | |||||||||||
7129 | auto ToParamOrErr = import(E->getParam()); | ||||||||||
7130 | if (!ToParamOrErr) | ||||||||||
7131 | return ToParamOrErr.takeError(); | ||||||||||
7132 | |||||||||||
7133 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); | ||||||||||
7134 | if (!UsedContextOrErr) | ||||||||||
7135 | return UsedContextOrErr.takeError(); | ||||||||||
7136 | |||||||||||
7137 | // Import the default arg if it was not imported yet. | ||||||||||
7138 | // This is needed because it can happen that during the import of the | ||||||||||
7139 | // default expression (from VisitParmVarDecl) the same ParmVarDecl is | ||||||||||
7140 | // encountered here. The default argument for a ParmVarDecl is set in the | ||||||||||
7141 | // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here, | ||||||||||
7142 | // see VisitParmVarDecl). | ||||||||||
7143 | ParmVarDecl *ToParam = *ToParamOrErr; | ||||||||||
7144 | if (!ToParam->getDefaultArg()) { | ||||||||||
7145 | Optional<ParmVarDecl *> FromParam = Importer.getImportedFromDecl(ToParam); | ||||||||||
7146 | assert(FromParam && "ParmVarDecl was not imported?")((FromParam && "ParmVarDecl was not imported?") ? static_cast <void> (0) : __assert_fail ("FromParam && \"ParmVarDecl was not imported?\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 7146, __PRETTY_FUNCTION__)); | ||||||||||
7147 | |||||||||||
7148 | if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam)) | ||||||||||
7149 | return std::move(Err); | ||||||||||
7150 | } | ||||||||||
7151 | |||||||||||
7152 | return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr, | ||||||||||
7153 | *ToParamOrErr, *UsedContextOrErr); | ||||||||||
7154 | } | ||||||||||
7155 | |||||||||||
7156 | ExpectedStmt | ||||||||||
7157 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { | ||||||||||
7158 | Error Err = Error::success(); | ||||||||||
7159 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7160 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); | ||||||||||
7161 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||||||
7162 | if (Err) | ||||||||||
7163 | return std::move(Err); | ||||||||||
7164 | |||||||||||
7165 | return new (Importer.getToContext()) CXXScalarValueInitExpr( | ||||||||||
7166 | ToType, ToTypeSourceInfo, ToRParenLoc); | ||||||||||
7167 | } | ||||||||||
7168 | |||||||||||
7169 | ExpectedStmt | ||||||||||
7170 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { | ||||||||||
7171 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | ||||||||||
7172 | if (!ToSubExprOrErr) | ||||||||||
7173 | return ToSubExprOrErr.takeError(); | ||||||||||
7174 | |||||||||||
7175 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); | ||||||||||
7176 | if (!ToDtorOrErr) | ||||||||||
7177 | return ToDtorOrErr.takeError(); | ||||||||||
7178 | |||||||||||
7179 | ASTContext &ToCtx = Importer.getToContext(); | ||||||||||
7180 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); | ||||||||||
7181 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); | ||||||||||
7182 | } | ||||||||||
7183 | |||||||||||
7184 | ExpectedStmt | ||||||||||
7185 | |||||||||||
7186 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { | ||||||||||
7187 | Error Err = Error::success(); | ||||||||||
7188 | auto ToConstructor = importChecked(Err, E->getConstructor()); | ||||||||||
7189 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7190 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); | ||||||||||
7191 | auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange()); | ||||||||||
7192 | if (Err) | ||||||||||
7193 | return std::move(Err); | ||||||||||
7194 | |||||||||||
7195 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); | ||||||||||
7196 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | ||||||||||
7197 | return std::move(Err); | ||||||||||
7198 | |||||||||||
7199 | return CXXTemporaryObjectExpr::Create( | ||||||||||
7200 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, | ||||||||||
7201 | ToParenOrBraceRange, E->hadMultipleCandidates(), | ||||||||||
7202 | E->isListInitialization(), E->isStdInitListInitialization(), | ||||||||||
7203 | E->requiresZeroInitialization()); | ||||||||||
7204 | } | ||||||||||
7205 | |||||||||||
7206 | ExpectedDecl ASTNodeImporter::VisitLifetimeExtendedTemporaryDecl( | ||||||||||
7207 | LifetimeExtendedTemporaryDecl *D) { | ||||||||||
7208 | DeclContext *DC, *LexicalDC; | ||||||||||
7209 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | ||||||||||
7210 | return std::move(Err); | ||||||||||
7211 | |||||||||||
7212 | Error Err = Error::success(); | ||||||||||
7213 | auto Temporary = importChecked(Err, D->getTemporaryExpr()); | ||||||||||
7214 | auto ExtendingDecl = importChecked(Err, D->getExtendingDecl()); | ||||||||||
7215 | if (Err) | ||||||||||
7216 | return std::move(Err); | ||||||||||
7217 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? | ||||||||||
7218 | |||||||||||
7219 | LifetimeExtendedTemporaryDecl *To; | ||||||||||
7220 | if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl, | ||||||||||
7221 | D->getManglingNumber())) | ||||||||||
7222 | return To; | ||||||||||
7223 | |||||||||||
7224 | To->setLexicalDeclContext(LexicalDC); | ||||||||||
7225 | LexicalDC->addDeclInternal(To); | ||||||||||
7226 | return To; | ||||||||||
7227 | } | ||||||||||
7228 | |||||||||||
7229 | ExpectedStmt | ||||||||||
7230 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { | ||||||||||
7231 | Error Err = Error::success(); | ||||||||||
7232 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7233 | Expr *ToTemporaryExpr = importChecked( | ||||||||||
7234 | Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr()); | ||||||||||
7235 | auto ToMaterializedDecl = | ||||||||||
7236 | importChecked(Err, E->getLifetimeExtendedTemporaryDecl()); | ||||||||||
7237 | if (Err) | ||||||||||
7238 | return std::move(Err); | ||||||||||
7239 | |||||||||||
7240 | if (!ToTemporaryExpr) | ||||||||||
7241 | ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr()); | ||||||||||
7242 | |||||||||||
7243 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( | ||||||||||
7244 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference(), | ||||||||||
7245 | ToMaterializedDecl); | ||||||||||
7246 | |||||||||||
7247 | return ToMTE; | ||||||||||
7248 | } | ||||||||||
7249 | |||||||||||
7250 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { | ||||||||||
7251 | Error Err = Error::success(); | ||||||||||
7252 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7253 | auto ToPattern = importChecked(Err, E->getPattern()); | ||||||||||
7254 | auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc()); | ||||||||||
7255 | if (Err) | ||||||||||
7256 | return std::move(Err); | ||||||||||
7257 | |||||||||||
7258 | return new (Importer.getToContext()) PackExpansionExpr( | ||||||||||
7259 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); | ||||||||||
7260 | } | ||||||||||
7261 | |||||||||||
7262 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { | ||||||||||
7263 | Error Err = Error::success(); | ||||||||||
7264 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||||||
7265 | auto ToPack = importChecked(Err, E->getPack()); | ||||||||||
7266 | auto ToPackLoc = importChecked(Err, E->getPackLoc()); | ||||||||||
7267 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||||||
7268 | if (Err) | ||||||||||
7269 | return std::move(Err); | ||||||||||
7270 | |||||||||||
7271 | Optional<unsigned> Length; | ||||||||||
7272 | if (!E->isValueDependent()) | ||||||||||
7273 | Length = E->getPackLength(); | ||||||||||
7274 | |||||||||||
7275 | SmallVector<TemplateArgument, 8> ToPartialArguments; | ||||||||||
7276 | if (E->isPartiallySubstituted()) { | ||||||||||
7277 | if (Error Err = ImportTemplateArguments( | ||||||||||
7278 | E->getPartialArguments().data(), | ||||||||||
7279 | E->getPartialArguments().size(), | ||||||||||
7280 | ToPartialArguments)) | ||||||||||
7281 | return std::move(Err); | ||||||||||
7282 | } | ||||||||||
7283 | |||||||||||
7284 | return SizeOfPackExpr::Create( | ||||||||||
7285 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, | ||||||||||
7286 | Length, ToPartialArguments); | ||||||||||
7287 | } | ||||||||||
7288 | |||||||||||
7289 | |||||||||||
7290 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { | ||||||||||
7291 | Error Err = Error::success(); | ||||||||||
7292 | auto ToOperatorNew = importChecked(Err, E->getOperatorNew()); | ||||||||||
7293 | auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete()); | ||||||||||
7294 | auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens()); | ||||||||||
7295 | auto ToArraySize = importChecked(Err, E->getArraySize()); | ||||||||||
7296 | auto ToInitializer = importChecked(Err, E->getInitializer()); | ||||||||||
7297 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7298 | auto ToAllocatedTypeSourceInfo = | ||||||||||
7299 | importChecked(Err, E->getAllocatedTypeSourceInfo()); | ||||||||||
7300 | auto ToSourceRange = importChecked(Err, E->getSourceRange()); | ||||||||||
7301 | auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange()); | ||||||||||
7302 | if (Err) | ||||||||||
7303 | return std::move(Err); | ||||||||||
7304 | |||||||||||
7305 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); | ||||||||||
7306 | if (Error Err = | ||||||||||
7307 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) | ||||||||||
7308 | return std::move(Err); | ||||||||||
7309 | |||||||||||
7310 | return CXXNewExpr::Create( | ||||||||||
7311 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, | ||||||||||
7312 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), | ||||||||||
7313 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), | ||||||||||
7314 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, | ||||||||||
7315 | ToDirectInitRange); | ||||||||||
7316 | } | ||||||||||
7317 | |||||||||||
7318 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { | ||||||||||
7319 | Error Err = Error::success(); | ||||||||||
7320 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7321 | auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete()); | ||||||||||
7322 | auto ToArgument = importChecked(Err, E->getArgument()); | ||||||||||
7323 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); | ||||||||||
7324 | if (Err) | ||||||||||
7325 | return std::move(Err); | ||||||||||
7326 | |||||||||||
7327 | return new (Importer.getToContext()) CXXDeleteExpr( | ||||||||||
7328 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), | ||||||||||
7329 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, | ||||||||||
7330 | ToBeginLoc); | ||||||||||
7331 | } | ||||||||||
7332 | |||||||||||
7333 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { | ||||||||||
7334 | Error Err = Error::success(); | ||||||||||
7335 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7336 | auto ToLocation = importChecked(Err, E->getLocation()); | ||||||||||
7337 | auto ToConstructor = importChecked(Err, E->getConstructor()); | ||||||||||
7338 | auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange()); | ||||||||||
7339 | if (Err) | ||||||||||
7340 | return std::move(Err); | ||||||||||
7341 | |||||||||||
7342 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); | ||||||||||
7343 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | ||||||||||
7344 | return std::move(Err); | ||||||||||
7345 | |||||||||||
7346 | return CXXConstructExpr::Create( | ||||||||||
7347 | Importer.getToContext(), ToType, ToLocation, ToConstructor, | ||||||||||
7348 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), | ||||||||||
7349 | E->isListInitialization(), E->isStdInitListInitialization(), | ||||||||||
7350 | E->requiresZeroInitialization(), E->getConstructionKind(), | ||||||||||
7351 | ToParenOrBraceRange); | ||||||||||
7352 | } | ||||||||||
7353 | |||||||||||
7354 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { | ||||||||||
7355 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | ||||||||||
7356 | if (!ToSubExprOrErr) | ||||||||||
7357 | return ToSubExprOrErr.takeError(); | ||||||||||
7358 | |||||||||||
7359 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); | ||||||||||
7360 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) | ||||||||||
7361 | return std::move(Err); | ||||||||||
7362 | |||||||||||
7363 | return ExprWithCleanups::Create( | ||||||||||
7364 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), | ||||||||||
7365 | ToObjects); | ||||||||||
7366 | } | ||||||||||
7367 | |||||||||||
7368 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { | ||||||||||
7369 | Error Err = Error::success(); | ||||||||||
7370 | auto ToCallee = importChecked(Err, E->getCallee()); | ||||||||||
7371 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7372 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||||||
7373 | if (Err) | ||||||||||
7374 | return std::move(Err); | ||||||||||
7375 | |||||||||||
7376 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); | ||||||||||
7377 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | ||||||||||
7378 | return std::move(Err); | ||||||||||
7379 | |||||||||||
7380 | return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, | ||||||||||
7381 | ToType, E->getValueKind(), ToRParenLoc, | ||||||||||
7382 | E->getFPFeatures()); | ||||||||||
7383 | } | ||||||||||
7384 | |||||||||||
7385 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { | ||||||||||
7386 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||||||
7387 | if (!ToTypeOrErr) | ||||||||||
7388 | return ToTypeOrErr.takeError(); | ||||||||||
7389 | |||||||||||
7390 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | ||||||||||
7391 | if (!ToLocationOrErr) | ||||||||||
7392 | return ToLocationOrErr.takeError(); | ||||||||||
7393 | |||||||||||
7394 | return new (Importer.getToContext()) CXXThisExpr( | ||||||||||
7395 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); | ||||||||||
7396 | } | ||||||||||
7397 | |||||||||||
7398 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { | ||||||||||
7399 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||||||
7400 | if (!ToTypeOrErr) | ||||||||||
7401 | return ToTypeOrErr.takeError(); | ||||||||||
7402 | |||||||||||
7403 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | ||||||||||
7404 | if (!ToLocationOrErr) | ||||||||||
7405 | return ToLocationOrErr.takeError(); | ||||||||||
7406 | |||||||||||
7407 | return new (Importer.getToContext()) CXXBoolLiteralExpr( | ||||||||||
7408 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); | ||||||||||
7409 | } | ||||||||||
7410 | |||||||||||
7411 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { | ||||||||||
7412 | Error Err = Error::success(); | ||||||||||
7413 | auto ToBase = importChecked(Err, E->getBase()); | ||||||||||
7414 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||||||
7415 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); | ||||||||||
7416 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); | ||||||||||
7417 | auto ToMemberDecl = importChecked(Err, E->getMemberDecl()); | ||||||||||
7418 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7419 | auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl()); | ||||||||||
7420 | auto ToName = importChecked(Err, E->getMemberNameInfo().getName()); | ||||||||||
7421 | auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc()); | ||||||||||
7422 | if (Err) | ||||||||||
7423 | return std::move(Err); | ||||||||||
7424 | |||||||||||
7425 | DeclAccessPair ToFoundDecl = | ||||||||||
7426 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); | ||||||||||
7427 | |||||||||||
7428 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); | ||||||||||
7429 | |||||||||||
7430 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; | ||||||||||
7431 | if (E->hasExplicitTemplateArgs()) { | ||||||||||
7432 | if (Error Err = | ||||||||||
7433 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), | ||||||||||
7434 | E->template_arguments(), ToTAInfo)) | ||||||||||
7435 | return std::move(Err); | ||||||||||
7436 | ResInfo = &ToTAInfo; | ||||||||||
7437 | } | ||||||||||
7438 | |||||||||||
7439 | return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(), | ||||||||||
7440 | ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, | ||||||||||
7441 | ToMemberDecl, ToFoundDecl, ToMemberNameInfo, | ||||||||||
7442 | ResInfo, ToType, E->getValueKind(), | ||||||||||
7443 | E->getObjectKind(), E->isNonOdrUse()); | ||||||||||
7444 | } | ||||||||||
7445 | |||||||||||
7446 | ExpectedStmt | ||||||||||
7447 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { | ||||||||||
7448 | Error Err = Error::success(); | ||||||||||
7449 | auto ToBase = importChecked(Err, E->getBase()); | ||||||||||
7450 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||||||
7451 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); | ||||||||||
7452 | auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo()); | ||||||||||
7453 | auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc()); | ||||||||||
7454 | auto ToTildeLoc = importChecked(Err, E->getTildeLoc()); | ||||||||||
7455 | if (Err) | ||||||||||
7456 | return std::move(Err); | ||||||||||
7457 | |||||||||||
7458 | PseudoDestructorTypeStorage Storage; | ||||||||||
7459 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { | ||||||||||
7460 | IdentifierInfo *ToII = Importer.Import(FromII); | ||||||||||
7461 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); | ||||||||||
7462 | if (!ToDestroyedTypeLocOrErr) | ||||||||||
7463 | return ToDestroyedTypeLocOrErr.takeError(); | ||||||||||
7464 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); | ||||||||||
7465 | } else { | ||||||||||
7466 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) | ||||||||||
7467 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); | ||||||||||
7468 | else | ||||||||||
7469 | return ToTIOrErr.takeError(); | ||||||||||
7470 | } | ||||||||||
7471 | |||||||||||
7472 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( | ||||||||||
7473 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, | ||||||||||
7474 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); | ||||||||||
7475 | } | ||||||||||
7476 | |||||||||||
7477 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( | ||||||||||
7478 | CXXDependentScopeMemberExpr *E) { | ||||||||||
7479 | Error Err = Error::success(); | ||||||||||
7480 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7481 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||||||
7482 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); | ||||||||||
7483 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); | ||||||||||
7484 | auto ToFirstQualifierFoundInScope = | ||||||||||
7485 | importChecked(Err, E->getFirstQualifierFoundInScope()); | ||||||||||
7486 | if (Err) | ||||||||||
7487 | return std::move(Err); | ||||||||||
7488 | |||||||||||
7489 | Expr *ToBase = nullptr; | ||||||||||
7490 | if (!E->isImplicitAccess()) { | ||||||||||
7491 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) | ||||||||||
7492 | ToBase = *ToBaseOrErr; | ||||||||||
7493 | else | ||||||||||
7494 | return ToBaseOrErr.takeError(); | ||||||||||
7495 | } | ||||||||||
7496 | |||||||||||
7497 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; | ||||||||||
7498 | |||||||||||
7499 | if (E->hasExplicitTemplateArgs()) { | ||||||||||
7500 | if (Error Err = | ||||||||||
7501 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), | ||||||||||
7502 | E->template_arguments(), ToTAInfo)) | ||||||||||
7503 | return std::move(Err); | ||||||||||
7504 | ResInfo = &ToTAInfo; | ||||||||||
7505 | } | ||||||||||
7506 | auto ToMember = importChecked(Err, E->getMember()); | ||||||||||
7507 | auto ToMemberLoc = importChecked(Err, E->getMemberLoc()); | ||||||||||
7508 | if (Err) | ||||||||||
7509 | return std::move(Err); | ||||||||||
7510 | DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc); | ||||||||||
7511 | |||||||||||
7512 | // Import additional name location/type info. | ||||||||||
7513 | if (Error Err = | ||||||||||
7514 | ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo)) | ||||||||||
7515 | return std::move(Err); | ||||||||||
7516 | |||||||||||
7517 | return CXXDependentScopeMemberExpr::Create( | ||||||||||
7518 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, | ||||||||||
7519 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, | ||||||||||
7520 | ToMemberNameInfo, ResInfo); | ||||||||||
7521 | } | ||||||||||
7522 | |||||||||||
7523 | ExpectedStmt | ||||||||||
7524 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { | ||||||||||
7525 | Error Err = Error::success(); | ||||||||||
7526 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); | ||||||||||
7527 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); | ||||||||||
7528 | auto ToDeclName = importChecked(Err, E->getDeclName()); | ||||||||||
7529 | auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc()); | ||||||||||
7530 | auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc()); | ||||||||||
7531 | auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc()); | ||||||||||
7532 | if (Err) | ||||||||||
7533 | return std::move(Err); | ||||||||||
7534 | |||||||||||
7535 | DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc); | ||||||||||
7536 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | ||||||||||
7537 | return std::move(Err); | ||||||||||
7538 | |||||||||||
7539 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); | ||||||||||
7540 | TemplateArgumentListInfo *ResInfo = nullptr; | ||||||||||
7541 | if (E->hasExplicitTemplateArgs()) { | ||||||||||
7542 | if (Error Err = | ||||||||||
7543 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) | ||||||||||
7544 | return std::move(Err); | ||||||||||
7545 | ResInfo = &ToTAInfo; | ||||||||||
7546 | } | ||||||||||
7547 | |||||||||||
7548 | return DependentScopeDeclRefExpr::Create( | ||||||||||
7549 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, | ||||||||||
7550 | ToNameInfo, ResInfo); | ||||||||||
7551 | } | ||||||||||
7552 | |||||||||||
7553 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( | ||||||||||
7554 | CXXUnresolvedConstructExpr *E) { | ||||||||||
7555 | Error Err = Error::success(); | ||||||||||
7556 | auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); | ||||||||||
7557 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||||||
7558 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7559 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); | ||||||||||
7560 | if (Err) | ||||||||||
7561 | return std::move(Err); | ||||||||||
7562 | |||||||||||
7563 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); | ||||||||||
7564 | if (Error Err = | ||||||||||
7565 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) | ||||||||||
7566 | return std::move(Err); | ||||||||||
7567 | |||||||||||
7568 | return CXXUnresolvedConstructExpr::Create( | ||||||||||
7569 | Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc, | ||||||||||
7570 | llvm::makeArrayRef(ToArgs), ToRParenLoc); | ||||||||||
7571 | } | ||||||||||
7572 | |||||||||||
7573 | ExpectedStmt | ||||||||||
7574 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { | ||||||||||
7575 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); | ||||||||||
7576 | if (!ToNamingClassOrErr) | ||||||||||
7577 | return ToNamingClassOrErr.takeError(); | ||||||||||
7578 | |||||||||||
7579 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); | ||||||||||
7580 | if (!ToQualifierLocOrErr) | ||||||||||
7581 | return ToQualifierLocOrErr.takeError(); | ||||||||||
7582 | |||||||||||
7583 | Error Err = Error::success(); | ||||||||||
7584 | auto ToName = importChecked(Err, E->getName()); | ||||||||||
7585 | auto ToNameLoc = importChecked(Err, E->getNameLoc()); | ||||||||||
7586 | if (Err) | ||||||||||
7587 | return std::move(Err); | ||||||||||
7588 | DeclarationNameInfo ToNameInfo(ToName, ToNameLoc); | ||||||||||
7589 | |||||||||||
7590 | // Import additional name location/type info. | ||||||||||
7591 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | ||||||||||
7592 | return std::move(Err); | ||||||||||
7593 | |||||||||||
7594 | UnresolvedSet<8> ToDecls; | ||||||||||
7595 | for (auto *D : E->decls()) | ||||||||||
7596 | if (auto ToDOrErr = import(D)) | ||||||||||
7597 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); | ||||||||||
7598 | else | ||||||||||
7599 | return ToDOrErr.takeError(); | ||||||||||
7600 | |||||||||||
7601 | if (E->hasExplicitTemplateArgs()) { | ||||||||||
7602 | TemplateArgumentListInfo ToTAInfo; | ||||||||||
7603 | if (Error Err = ImportTemplateArgumentListInfo( | ||||||||||
7604 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), | ||||||||||
7605 | ToTAInfo)) | ||||||||||
7606 | return std::move(Err); | ||||||||||
7607 | |||||||||||
7608 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); | ||||||||||
7609 | if (!ToTemplateKeywordLocOrErr) | ||||||||||
7610 | return ToTemplateKeywordLocOrErr.takeError(); | ||||||||||
7611 | |||||||||||
7612 | return UnresolvedLookupExpr::Create( | ||||||||||
7613 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, | ||||||||||
7614 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, | ||||||||||
7615 | ToDecls.begin(), ToDecls.end()); | ||||||||||
7616 | } | ||||||||||
7617 | |||||||||||
7618 | return UnresolvedLookupExpr::Create( | ||||||||||
7619 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, | ||||||||||
7620 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), | ||||||||||
7621 | ToDecls.end()); | ||||||||||
7622 | } | ||||||||||
7623 | |||||||||||
7624 | ExpectedStmt | ||||||||||
7625 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { | ||||||||||
7626 | Error Err = Error::success(); | ||||||||||
7627 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7628 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||||||
7629 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); | ||||||||||
7630 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); | ||||||||||
7631 | auto ToName = importChecked(Err, E->getName()); | ||||||||||
7632 | auto ToNameLoc = importChecked(Err, E->getNameLoc()); | ||||||||||
7633 | if (Err) | ||||||||||
7634 | return std::move(Err); | ||||||||||
7635 | |||||||||||
7636 | DeclarationNameInfo ToNameInfo(ToName, ToNameLoc); | ||||||||||
7637 | // Import additional name location/type info. | ||||||||||
7638 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | ||||||||||
7639 | return std::move(Err); | ||||||||||
7640 | |||||||||||
7641 | UnresolvedSet<8> ToDecls; | ||||||||||
7642 | for (Decl *D : E->decls()) | ||||||||||
7643 | if (auto ToDOrErr = import(D)) | ||||||||||
7644 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); | ||||||||||
7645 | else | ||||||||||
7646 | return ToDOrErr.takeError(); | ||||||||||
7647 | |||||||||||
7648 | TemplateArgumentListInfo ToTAInfo; | ||||||||||
7649 | TemplateArgumentListInfo *ResInfo = nullptr; | ||||||||||
7650 | if (E->hasExplicitTemplateArgs()) { | ||||||||||
7651 | TemplateArgumentListInfo FromTAInfo; | ||||||||||
7652 | E->copyTemplateArgumentsInto(FromTAInfo); | ||||||||||
7653 | if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo)) | ||||||||||
7654 | return std::move(Err); | ||||||||||
7655 | ResInfo = &ToTAInfo; | ||||||||||
7656 | } | ||||||||||
7657 | |||||||||||
7658 | Expr *ToBase = nullptr; | ||||||||||
7659 | if (!E->isImplicitAccess()) { | ||||||||||
7660 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) | ||||||||||
7661 | ToBase = *ToBaseOrErr; | ||||||||||
7662 | else | ||||||||||
7663 | return ToBaseOrErr.takeError(); | ||||||||||
7664 | } | ||||||||||
7665 | |||||||||||
7666 | return UnresolvedMemberExpr::Create( | ||||||||||
7667 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, | ||||||||||
7668 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, | ||||||||||
7669 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); | ||||||||||
7670 | } | ||||||||||
7671 | |||||||||||
7672 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { | ||||||||||
7673 | Error Err = Error::success(); | ||||||||||
7674 | auto ToCallee = importChecked(Err, E->getCallee()); | ||||||||||
7675 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7676 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||||||
7677 | if (Err) | ||||||||||
7678 | return std::move(Err); | ||||||||||
7679 | |||||||||||
7680 | unsigned NumArgs = E->getNumArgs(); | ||||||||||
7681 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); | ||||||||||
7682 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | ||||||||||
7683 | return std::move(Err); | ||||||||||
7684 | |||||||||||
7685 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { | ||||||||||
7686 | return CXXOperatorCallExpr::Create( | ||||||||||
7687 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, | ||||||||||
7688 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(), | ||||||||||
7689 | OCE->getADLCallKind()); | ||||||||||
7690 | } | ||||||||||
7691 | |||||||||||
7692 | return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType, | ||||||||||
7693 | E->getValueKind(), ToRParenLoc, E->getFPFeatures(), | ||||||||||
7694 | /*MinNumArgs=*/0, E->getADLCallKind()); | ||||||||||
7695 | } | ||||||||||
7696 | |||||||||||
7697 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { | ||||||||||
7698 | CXXRecordDecl *FromClass = E->getLambdaClass(); | ||||||||||
7699 | auto ToClassOrErr = import(FromClass); | ||||||||||
7700 | if (!ToClassOrErr) | ||||||||||
7701 | return ToClassOrErr.takeError(); | ||||||||||
7702 | CXXRecordDecl *ToClass = *ToClassOrErr; | ||||||||||
7703 | |||||||||||
7704 | auto ToCallOpOrErr = import(E->getCallOperator()); | ||||||||||
7705 | if (!ToCallOpOrErr) | ||||||||||
7706 | return ToCallOpOrErr.takeError(); | ||||||||||
7707 | |||||||||||
7708 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); | ||||||||||
7709 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) | ||||||||||
7710 | return std::move(Err); | ||||||||||
7711 | |||||||||||
7712 | Error Err = Error::success(); | ||||||||||
7713 | auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange()); | ||||||||||
7714 | auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc()); | ||||||||||
7715 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); | ||||||||||
7716 | if (Err) | ||||||||||
7717 | return std::move(Err); | ||||||||||
7718 | |||||||||||
7719 | return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange, | ||||||||||
7720 | E->getCaptureDefault(), ToCaptureDefaultLoc, | ||||||||||
7721 | E->hasExplicitParameters(), | ||||||||||
7722 | E->hasExplicitResultType(), ToCaptureInits, | ||||||||||
7723 | ToEndLoc, E->containsUnexpandedParameterPack()); | ||||||||||
7724 | } | ||||||||||
7725 | |||||||||||
7726 | |||||||||||
7727 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { | ||||||||||
7728 | Error Err = Error::success(); | ||||||||||
7729 | auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc()); | ||||||||||
7730 | auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc()); | ||||||||||
7731 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7732 | if (Err) | ||||||||||
7733 | return std::move(Err); | ||||||||||
7734 | |||||||||||
7735 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); | ||||||||||
7736 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) | ||||||||||
7737 | return std::move(Err); | ||||||||||
7738 | |||||||||||
7739 | ASTContext &ToCtx = Importer.getToContext(); | ||||||||||
7740 | InitListExpr *To = new (ToCtx) InitListExpr( | ||||||||||
7741 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); | ||||||||||
7742 | To->setType(ToType); | ||||||||||
7743 | |||||||||||
7744 | if (E->hasArrayFiller()) { | ||||||||||
7745 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) | ||||||||||
7746 | To->setArrayFiller(*ToFillerOrErr); | ||||||||||
7747 | else | ||||||||||
7748 | return ToFillerOrErr.takeError(); | ||||||||||
7749 | } | ||||||||||
7750 | |||||||||||
7751 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { | ||||||||||
7752 | if (auto ToFDOrErr = import(FromFD)) | ||||||||||
7753 | To->setInitializedFieldInUnion(*ToFDOrErr); | ||||||||||
7754 | else | ||||||||||
7755 | return ToFDOrErr.takeError(); | ||||||||||
7756 | } | ||||||||||
7757 | |||||||||||
7758 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { | ||||||||||
7759 | if (auto ToSyntFormOrErr = import(SyntForm)) | ||||||||||
7760 | To->setSyntacticForm(*ToSyntFormOrErr); | ||||||||||
7761 | else | ||||||||||
7762 | return ToSyntFormOrErr.takeError(); | ||||||||||
7763 | } | ||||||||||
7764 | |||||||||||
7765 | // Copy InitListExprBitfields, which are not handled in the ctor of | ||||||||||
7766 | // InitListExpr. | ||||||||||
7767 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); | ||||||||||
7768 | |||||||||||
7769 | return To; | ||||||||||
7770 | } | ||||||||||
7771 | |||||||||||
7772 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( | ||||||||||
7773 | CXXStdInitializerListExpr *E) { | ||||||||||
7774 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||||||
7775 | if (!ToTypeOrErr) | ||||||||||
7776 | return ToTypeOrErr.takeError(); | ||||||||||
7777 | |||||||||||
7778 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | ||||||||||
7779 | if (!ToSubExprOrErr) | ||||||||||
7780 | return ToSubExprOrErr.takeError(); | ||||||||||
7781 | |||||||||||
7782 | return new (Importer.getToContext()) CXXStdInitializerListExpr( | ||||||||||
7783 | *ToTypeOrErr, *ToSubExprOrErr); | ||||||||||
7784 | } | ||||||||||
7785 | |||||||||||
7786 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( | ||||||||||
7787 | CXXInheritedCtorInitExpr *E) { | ||||||||||
7788 | Error Err = Error::success(); | ||||||||||
7789 | auto ToLocation = importChecked(Err, E->getLocation()); | ||||||||||
7790 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7791 | auto ToConstructor = importChecked(Err, E->getConstructor()); | ||||||||||
7792 | if (Err) | ||||||||||
7793 | return std::move(Err); | ||||||||||
7794 | |||||||||||
7795 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( | ||||||||||
7796 | ToLocation, ToType, ToConstructor, E->constructsVBase(), | ||||||||||
7797 | E->inheritedFromVBase()); | ||||||||||
7798 | } | ||||||||||
7799 | |||||||||||
7800 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { | ||||||||||
7801 | Error Err = Error::success(); | ||||||||||
7802 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7803 | auto ToCommonExpr = importChecked(Err, E->getCommonExpr()); | ||||||||||
7804 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | ||||||||||
7805 | if (Err) | ||||||||||
7806 | return std::move(Err); | ||||||||||
7807 | |||||||||||
7808 | return new (Importer.getToContext()) ArrayInitLoopExpr( | ||||||||||
7809 | ToType, ToCommonExpr, ToSubExpr); | ||||||||||
7810 | } | ||||||||||
7811 | |||||||||||
7812 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { | ||||||||||
7813 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||||||
7814 | if (!ToTypeOrErr) | ||||||||||
7815 | return ToTypeOrErr.takeError(); | ||||||||||
7816 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); | ||||||||||
7817 | } | ||||||||||
7818 | |||||||||||
7819 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { | ||||||||||
7820 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); | ||||||||||
7821 | if (!ToBeginLocOrErr) | ||||||||||
7822 | return ToBeginLocOrErr.takeError(); | ||||||||||
7823 | |||||||||||
7824 | auto ToFieldOrErr = import(E->getField()); | ||||||||||
7825 | if (!ToFieldOrErr) | ||||||||||
7826 | return ToFieldOrErr.takeError(); | ||||||||||
7827 | |||||||||||
7828 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); | ||||||||||
7829 | if (!UsedContextOrErr) | ||||||||||
7830 | return UsedContextOrErr.takeError(); | ||||||||||
7831 | |||||||||||
7832 | return CXXDefaultInitExpr::Create( | ||||||||||
7833 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr, *UsedContextOrErr); | ||||||||||
7834 | } | ||||||||||
7835 | |||||||||||
7836 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { | ||||||||||
7837 | Error Err = Error::success(); | ||||||||||
7838 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7839 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); | ||||||||||
7840 | auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten()); | ||||||||||
7841 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); | ||||||||||
7842 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); | ||||||||||
7843 | auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets()); | ||||||||||
7844 | if (Err) | ||||||||||
7845 | return std::move(Err); | ||||||||||
7846 | |||||||||||
7847 | ExprValueKind VK = E->getValueKind(); | ||||||||||
7848 | CastKind CK = E->getCastKind(); | ||||||||||
7849 | auto ToBasePathOrErr = ImportCastPath(E); | ||||||||||
7850 | if (!ToBasePathOrErr) | ||||||||||
7851 | return ToBasePathOrErr.takeError(); | ||||||||||
7852 | |||||||||||
7853 | if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) { | ||||||||||
7854 | return CXXStaticCastExpr::Create( | ||||||||||
7855 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | ||||||||||
7856 | ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc, | ||||||||||
7857 | ToAngleBrackets); | ||||||||||
7858 | } else if (isa<CXXDynamicCastExpr>(E)) { | ||||||||||
7859 | return CXXDynamicCastExpr::Create( | ||||||||||
7860 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | ||||||||||
7861 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | ||||||||||
7862 | } else if (isa<CXXReinterpretCastExpr>(E)) { | ||||||||||
7863 | return CXXReinterpretCastExpr::Create( | ||||||||||
7864 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | ||||||||||
7865 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | ||||||||||
7866 | } else if (isa<CXXConstCastExpr>(E)) { | ||||||||||
7867 | return CXXConstCastExpr::Create( | ||||||||||
7868 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, | ||||||||||
7869 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | ||||||||||
7870 | } else { | ||||||||||
7871 | llvm_unreachable("Unknown cast type")::llvm::llvm_unreachable_internal("Unknown cast type", "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 7871); | ||||||||||
7872 | return make_error<ImportError>(); | ||||||||||
7873 | } | ||||||||||
7874 | } | ||||||||||
7875 | |||||||||||
7876 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( | ||||||||||
7877 | SubstNonTypeTemplateParmExpr *E) { | ||||||||||
7878 | Error Err = Error::success(); | ||||||||||
7879 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7880 | auto ToExprLoc = importChecked(Err, E->getExprLoc()); | ||||||||||
7881 | auto ToParameter = importChecked(Err, E->getParameter()); | ||||||||||
7882 | auto ToReplacement = importChecked(Err, E->getReplacement()); | ||||||||||
7883 | if (Err) | ||||||||||
7884 | return std::move(Err); | ||||||||||
7885 | |||||||||||
7886 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( | ||||||||||
7887 | ToType, E->getValueKind(), ToExprLoc, ToParameter, | ||||||||||
7888 | E->isReferenceParameter(), ToReplacement); | ||||||||||
7889 | } | ||||||||||
7890 | |||||||||||
7891 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { | ||||||||||
7892 | Error Err = Error::success(); | ||||||||||
7893 | auto ToType = importChecked(Err, E->getType()); | ||||||||||
7894 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); | ||||||||||
7895 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); | ||||||||||
7896 | if (Err) | ||||||||||
7897 | return std::move(Err); | ||||||||||
7898 | |||||||||||
7899 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); | ||||||||||
7900 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) | ||||||||||
7901 | return std::move(Err); | ||||||||||
7902 | |||||||||||
7903 | // According to Sema::BuildTypeTrait(), if E is value-dependent, | ||||||||||
7904 | // Value is always false. | ||||||||||
7905 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); | ||||||||||
7906 | |||||||||||
7907 | return TypeTraitExpr::Create( | ||||||||||
7908 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, | ||||||||||
7909 | ToEndLoc, ToValue); | ||||||||||
7910 | } | ||||||||||
7911 | |||||||||||
7912 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { | ||||||||||
7913 | ExpectedType ToTypeOrErr = import(E->getType()); | ||||||||||
7914 | if (!ToTypeOrErr) | ||||||||||
7915 | return ToTypeOrErr.takeError(); | ||||||||||
7916 | |||||||||||
7917 | auto ToSourceRangeOrErr = import(E->getSourceRange()); | ||||||||||
7918 | if (!ToSourceRangeOrErr) | ||||||||||
7919 | return ToSourceRangeOrErr.takeError(); | ||||||||||
7920 | |||||||||||
7921 | if (E->isTypeOperand()) { | ||||||||||
7922 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) | ||||||||||
7923 | return new (Importer.getToContext()) CXXTypeidExpr( | ||||||||||
7924 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); | ||||||||||
7925 | else | ||||||||||
7926 | return ToTSIOrErr.takeError(); | ||||||||||
7927 | } | ||||||||||
7928 | |||||||||||
7929 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); | ||||||||||
7930 | if (!ToExprOperandOrErr) | ||||||||||
7931 | return ToExprOperandOrErr.takeError(); | ||||||||||
7932 | |||||||||||
7933 | return new (Importer.getToContext()) CXXTypeidExpr( | ||||||||||
7934 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); | ||||||||||
7935 | } | ||||||||||
7936 | |||||||||||
7937 | Error ASTNodeImporter::ImportOverriddenMethods(CXXMethodDecl *ToMethod, | ||||||||||
7938 | CXXMethodDecl *FromMethod) { | ||||||||||
7939 | Error ImportErrors = Error::success(); | ||||||||||
7940 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { | ||||||||||
7941 | if (auto ImportedOrErr = import(FromOverriddenMethod)) | ||||||||||
7942 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( | ||||||||||
7943 | (*ImportedOrErr)->getCanonicalDecl())); | ||||||||||
7944 | else | ||||||||||
7945 | ImportErrors = | ||||||||||
7946 | joinErrors(std::move(ImportErrors), ImportedOrErr.takeError()); | ||||||||||
7947 | } | ||||||||||
7948 | return ImportErrors; | ||||||||||
7949 | } | ||||||||||
7950 | |||||||||||
7951 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, | ||||||||||
7952 | ASTContext &FromContext, FileManager &FromFileManager, | ||||||||||
7953 | bool MinimalImport, | ||||||||||
7954 | std::shared_ptr<ASTImporterSharedState> SharedState) | ||||||||||
7955 | : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext), | ||||||||||
7956 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), | ||||||||||
7957 | Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) { | ||||||||||
7958 | |||||||||||
7959 | // Create a default state without the lookup table: LLDB case. | ||||||||||
7960 | if (!SharedState) { | ||||||||||
7961 | this->SharedState = std::make_shared<ASTImporterSharedState>(); | ||||||||||
7962 | } | ||||||||||
7963 | |||||||||||
7964 | ImportedDecls[FromContext.getTranslationUnitDecl()] = | ||||||||||
7965 | ToContext.getTranslationUnitDecl(); | ||||||||||
7966 | } | ||||||||||
7967 | |||||||||||
7968 | ASTImporter::~ASTImporter() = default; | ||||||||||
7969 | |||||||||||
7970 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { | ||||||||||
7971 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&((F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl >(*F)) && "Try to get field index for non-field.") ? static_cast<void> (0) : __assert_fail ("F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && \"Try to get field index for non-field.\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 7972, __PRETTY_FUNCTION__)) | ||||||||||
7972 | "Try to get field index for non-field.")((F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl >(*F)) && "Try to get field index for non-field.") ? static_cast<void> (0) : __assert_fail ("F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && \"Try to get field index for non-field.\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 7972, __PRETTY_FUNCTION__)); | ||||||||||
7973 | |||||||||||
7974 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); | ||||||||||
7975 | if (!Owner) | ||||||||||
7976 | return None; | ||||||||||
7977 | |||||||||||
7978 | unsigned Index = 0; | ||||||||||
7979 | for (const auto *D : Owner->decls()) { | ||||||||||
7980 | if (D == F) | ||||||||||
7981 | return Index; | ||||||||||
7982 | |||||||||||
7983 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) | ||||||||||
7984 | ++Index; | ||||||||||
7985 | } | ||||||||||
7986 | |||||||||||
7987 | 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-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 7987); | ||||||||||
7988 | |||||||||||
7989 | return None; | ||||||||||
7990 | } | ||||||||||
7991 | |||||||||||
7992 | ASTImporter::FoundDeclsTy | ||||||||||
7993 | ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) { | ||||||||||
7994 | // We search in the redecl context because of transparent contexts. | ||||||||||
7995 | // E.g. a simple C language enum is a transparent context: | ||||||||||
7996 | // enum E { A, B }; | ||||||||||
7997 | // Now if we had a global variable in the TU | ||||||||||
7998 | // int A; | ||||||||||
7999 | // then the enum constant 'A' and the variable 'A' violates ODR. | ||||||||||
8000 | // We can diagnose this only if we search in the redecl context. | ||||||||||
8001 | DeclContext *ReDC = DC->getRedeclContext(); | ||||||||||
8002 | if (SharedState->getLookupTable()) { | ||||||||||
8003 | ASTImporterLookupTable::LookupResult LookupResult = | ||||||||||
8004 | SharedState->getLookupTable()->lookup(ReDC, Name); | ||||||||||
8005 | return FoundDeclsTy(LookupResult.begin(), LookupResult.end()); | ||||||||||
8006 | } else { | ||||||||||
8007 | DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name); | ||||||||||
8008 | FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end()); | ||||||||||
8009 | // We must search by the slow case of localUncachedLookup because that is | ||||||||||
8010 | // working even if there is no LookupPtr for the DC. We could use | ||||||||||
8011 | // DC::buildLookup() to create the LookupPtr, but that would load external | ||||||||||
8012 | // decls again, we must avoid that case. | ||||||||||
8013 | // Also, even if we had the LookupPtr, we must find Decls which are not | ||||||||||
8014 | // in the LookupPtr, so we need the slow case. | ||||||||||
8015 | // These cases are handled in ASTImporterLookupTable, but we cannot use | ||||||||||
8016 | // that with LLDB since that traverses through the AST which initiates the | ||||||||||
8017 | // load of external decls again via DC::decls(). And again, we must avoid | ||||||||||
8018 | // loading external decls during the import. | ||||||||||
8019 | if (Result.empty()) | ||||||||||
8020 | ReDC->localUncachedLookup(Name, Result); | ||||||||||
8021 | return Result; | ||||||||||
8022 | } | ||||||||||
8023 | } | ||||||||||
8024 | |||||||||||
8025 | void ASTImporter::AddToLookupTable(Decl *ToD) { | ||||||||||
8026 | SharedState->addDeclToLookup(ToD); | ||||||||||
8027 | } | ||||||||||
8028 | |||||||||||
8029 | Expected<Decl *> ASTImporter::ImportImpl(Decl *FromD) { | ||||||||||
8030 | // Import the decl using ASTNodeImporter. | ||||||||||
8031 | ASTNodeImporter Importer(*this); | ||||||||||
8032 | return Importer.Visit(FromD); | ||||||||||
8033 | } | ||||||||||
8034 | |||||||||||
8035 | void ASTImporter::RegisterImportedDecl(Decl *FromD, Decl *ToD) { | ||||||||||
8036 | MapImported(FromD, ToD); | ||||||||||
8037 | } | ||||||||||
8038 | |||||||||||
8039 | llvm::Expected<ExprWithCleanups::CleanupObject> | ||||||||||
8040 | ASTImporter::Import(ExprWithCleanups::CleanupObject From) { | ||||||||||
8041 | if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) { | ||||||||||
8042 | if (Expected<Expr *> R = Import(CLE)) | ||||||||||
8043 | return ExprWithCleanups::CleanupObject(cast<CompoundLiteralExpr>(*R)); | ||||||||||
8044 | } | ||||||||||
8045 | |||||||||||
8046 | // FIXME: Handle BlockDecl when we implement importing BlockExpr in | ||||||||||
8047 | // ASTNodeImporter. | ||||||||||
8048 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | ||||||||||
8049 | } | ||||||||||
8050 | |||||||||||
8051 | Expected<QualType> ASTImporter::Import(QualType FromT) { | ||||||||||
8052 | if (FromT.isNull()) | ||||||||||
8053 | return QualType{}; | ||||||||||
8054 | |||||||||||
8055 | const Type *FromTy = FromT.getTypePtr(); | ||||||||||
8056 | |||||||||||
8057 | // Check whether we've already imported this type. | ||||||||||
8058 | llvm::DenseMap<const Type *, const Type *>::iterator Pos | ||||||||||
8059 | = ImportedTypes.find(FromTy); | ||||||||||
8060 | if (Pos != ImportedTypes.end()) | ||||||||||
8061 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); | ||||||||||
8062 | |||||||||||
8063 | // Import the type | ||||||||||
8064 | ASTNodeImporter Importer(*this); | ||||||||||
8065 | ExpectedType ToTOrErr = Importer.Visit(FromTy); | ||||||||||
8066 | if (!ToTOrErr) | ||||||||||
8067 | return ToTOrErr.takeError(); | ||||||||||
8068 | |||||||||||
8069 | // Record the imported type. | ||||||||||
8070 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); | ||||||||||
8071 | |||||||||||
8072 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); | ||||||||||
8073 | } | ||||||||||
8074 | |||||||||||
8075 | Expected<TypeSourceInfo *> ASTImporter::Import(TypeSourceInfo *FromTSI) { | ||||||||||
8076 | if (!FromTSI) | ||||||||||
8077 | return FromTSI; | ||||||||||
8078 | |||||||||||
8079 | // FIXME: For now we just create a "trivial" type source info based | ||||||||||
8080 | // on the type and a single location. Implement a real version of this. | ||||||||||
8081 | ExpectedType TOrErr = Import(FromTSI->getType()); | ||||||||||
8082 | if (!TOrErr) | ||||||||||
8083 | return TOrErr.takeError(); | ||||||||||
8084 | ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc()); | ||||||||||
8085 | if (!BeginLocOrErr) | ||||||||||
8086 | return BeginLocOrErr.takeError(); | ||||||||||
8087 | |||||||||||
8088 | return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr); | ||||||||||
8089 | } | ||||||||||
8090 | |||||||||||
8091 | Expected<Attr *> ASTImporter::Import(const Attr *FromAttr) { | ||||||||||
8092 | Attr *ToAttr = nullptr; | ||||||||||
8093 | SourceRange ToRange; | ||||||||||
8094 | if (Error Err = importInto(ToRange, FromAttr->getRange())) | ||||||||||
8095 | return std::move(Err); | ||||||||||
8096 | |||||||||||
8097 | // FIXME: Is there some kind of AttrVisitor to use here? | ||||||||||
8098 | switch (FromAttr->getKind()) { | ||||||||||
8099 | case attr::Aligned: { | ||||||||||
8100 | auto *From = cast<AlignedAttr>(FromAttr); | ||||||||||
8101 | AlignedAttr *To; | ||||||||||
8102 | auto CreateAlign = [&](bool IsAlignmentExpr, void *Alignment) { | ||||||||||
8103 | return AlignedAttr::Create(ToContext, IsAlignmentExpr, Alignment, ToRange, | ||||||||||
8104 | From->getSyntax(), | ||||||||||
8105 | From->getSemanticSpelling()); | ||||||||||
8106 | }; | ||||||||||
8107 | if (From->isAlignmentExpr()) { | ||||||||||
8108 | if (auto ToEOrErr = Import(From->getAlignmentExpr())) | ||||||||||
8109 | To = CreateAlign(true, *ToEOrErr); | ||||||||||
8110 | else | ||||||||||
8111 | return ToEOrErr.takeError(); | ||||||||||
8112 | } else { | ||||||||||
8113 | if (auto ToTOrErr = Import(From->getAlignmentType())) | ||||||||||
8114 | To = CreateAlign(false, *ToTOrErr); | ||||||||||
8115 | else | ||||||||||
8116 | return ToTOrErr.takeError(); | ||||||||||
8117 | } | ||||||||||
8118 | To->setInherited(From->isInherited()); | ||||||||||
8119 | To->setPackExpansion(From->isPackExpansion()); | ||||||||||
8120 | To->setImplicit(From->isImplicit()); | ||||||||||
8121 | ToAttr = To; | ||||||||||
8122 | break; | ||||||||||
8123 | } | ||||||||||
8124 | case attr::Format: { | ||||||||||
8125 | const auto *From = cast<FormatAttr>(FromAttr); | ||||||||||
8126 | FormatAttr *To; | ||||||||||
8127 | IdentifierInfo *ToAttrType = Import(From->getType()); | ||||||||||
8128 | To = FormatAttr::Create(ToContext, ToAttrType, From->getFormatIdx(), | ||||||||||
8129 | From->getFirstArg(), ToRange, From->getSyntax()); | ||||||||||
8130 | To->setInherited(From->isInherited()); | ||||||||||
8131 | ToAttr = To; | ||||||||||
8132 | break; | ||||||||||
8133 | } | ||||||||||
8134 | default: | ||||||||||
8135 | // FIXME: 'clone' copies every member but some of them should be imported. | ||||||||||
8136 | // Handle other Attrs that have parameters that should be imported. | ||||||||||
8137 | ToAttr = FromAttr->clone(ToContext); | ||||||||||
8138 | ToAttr->setRange(ToRange); | ||||||||||
8139 | break; | ||||||||||
8140 | } | ||||||||||
8141 | assert(ToAttr && "Attribute should be created.")((ToAttr && "Attribute should be created.") ? static_cast <void> (0) : __assert_fail ("ToAttr && \"Attribute should be created.\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 8141, __PRETTY_FUNCTION__)); | ||||||||||
8142 | |||||||||||
8143 | return ToAttr; | ||||||||||
8144 | } | ||||||||||
8145 | |||||||||||
8146 | Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const { | ||||||||||
8147 | auto Pos = ImportedDecls.find(FromD); | ||||||||||
8148 | if (Pos != ImportedDecls.end()) | ||||||||||
8149 | return Pos->second; | ||||||||||
8150 | else | ||||||||||
8151 | return nullptr; | ||||||||||
8152 | } | ||||||||||
8153 | |||||||||||
8154 | TranslationUnitDecl *ASTImporter::GetFromTU(Decl *ToD) { | ||||||||||
8155 | auto FromDPos = ImportedFromDecls.find(ToD); | ||||||||||
8156 | if (FromDPos == ImportedFromDecls.end()) | ||||||||||
8157 | return nullptr; | ||||||||||
8158 | return FromDPos->second->getTranslationUnitDecl(); | ||||||||||
8159 | } | ||||||||||
8160 | |||||||||||
8161 | Expected<Decl *> ASTImporter::Import(Decl *FromD) { | ||||||||||
8162 | if (!FromD) | ||||||||||
8163 | return nullptr; | ||||||||||
8164 | |||||||||||
8165 | // Push FromD to the stack, and remove that when we return. | ||||||||||
8166 | ImportPath.push(FromD); | ||||||||||
8167 | auto ImportPathBuilder = | ||||||||||
8168 | llvm::make_scope_exit([this]() { ImportPath.pop(); }); | ||||||||||
8169 | |||||||||||
8170 | // Check whether there was a previous failed import. | ||||||||||
8171 | // If yes return the existing error. | ||||||||||
8172 | if (auto Error = getImportDeclErrorIfAny(FromD)) | ||||||||||
8173 | return make_error<ImportError>(*Error); | ||||||||||
8174 | |||||||||||
8175 | // Check whether we've already imported this declaration. | ||||||||||
8176 | Decl *ToD = GetAlreadyImportedOrNull(FromD); | ||||||||||
8177 | if (ToD) { | ||||||||||
8178 | // Already imported (possibly from another TU) and with an error. | ||||||||||
8179 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { | ||||||||||
8180 | setImportDeclError(FromD, *Error); | ||||||||||
8181 | return make_error<ImportError>(*Error); | ||||||||||
8182 | } | ||||||||||
8183 | |||||||||||
8184 | // If FromD has some updated flags after last import, apply it | ||||||||||
8185 | updateFlags(FromD, ToD); | ||||||||||
8186 | // If we encounter a cycle during an import then we save the relevant part | ||||||||||
8187 | // of the import path associated to the Decl. | ||||||||||
8188 | if (ImportPath.hasCycleAtBack()) | ||||||||||
8189 | SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack()); | ||||||||||
8190 | return ToD; | ||||||||||
8191 | } | ||||||||||
8192 | |||||||||||
8193 | // Import the declaration. | ||||||||||
8194 | ExpectedDecl ToDOrErr = ImportImpl(FromD); | ||||||||||
8195 | if (!ToDOrErr) { | ||||||||||
8196 | // Failed to import. | ||||||||||
8197 | |||||||||||
8198 | auto Pos = ImportedDecls.find(FromD); | ||||||||||
8199 | if (Pos != ImportedDecls.end()) { | ||||||||||
8200 | // Import failed after the object was created. | ||||||||||
8201 | // Remove all references to it. | ||||||||||
8202 | auto *ToD = Pos->second; | ||||||||||
8203 | ImportedDecls.erase(Pos); | ||||||||||
8204 | |||||||||||
8205 | // ImportedDecls and ImportedFromDecls are not symmetric. It may happen | ||||||||||
8206 | // (e.g. with namespaces) that several decls from the 'from' context are | ||||||||||
8207 | // mapped to the same decl in the 'to' context. If we removed entries | ||||||||||
8208 | // from the LookupTable here then we may end up removing them multiple | ||||||||||
8209 | // times. | ||||||||||
8210 | |||||||||||
8211 | // The Lookuptable contains decls only which are in the 'to' context. | ||||||||||
8212 | // Remove from the Lookuptable only if it is *imported* into the 'to' | ||||||||||
8213 | // context (and do not remove it if it was added during the initial | ||||||||||
8214 | // traverse of the 'to' context). | ||||||||||
8215 | auto PosF = ImportedFromDecls.find(ToD); | ||||||||||
8216 | if (PosF != ImportedFromDecls.end()) { | ||||||||||
8217 | SharedState->removeDeclFromLookup(ToD); | ||||||||||
8218 | ImportedFromDecls.erase(PosF); | ||||||||||
8219 | } | ||||||||||
8220 | |||||||||||
8221 | // FIXME: AST may contain remaining references to the failed object. | ||||||||||
8222 | // However, the ImportDeclErrors in the shared state contains all the | ||||||||||
8223 | // failed objects together with their error. | ||||||||||
8224 | } | ||||||||||
8225 | |||||||||||
8226 | // Error encountered for the first time. | ||||||||||
8227 | // After takeError the error is not usable any more in ToDOrErr. | ||||||||||
8228 | // Get a copy of the error object (any more simple solution for this?). | ||||||||||
8229 | ImportError ErrOut; | ||||||||||
8230 | handleAllErrors(ToDOrErr.takeError(), | ||||||||||
8231 | [&ErrOut](const ImportError &E) { ErrOut = E; }); | ||||||||||
8232 | setImportDeclError(FromD, ErrOut); | ||||||||||
8233 | // Set the error for the mapped to Decl, which is in the "to" context. | ||||||||||
8234 | if (Pos != ImportedDecls.end()) | ||||||||||
8235 | SharedState->setImportDeclError(Pos->second, ErrOut); | ||||||||||
8236 | |||||||||||
8237 | // Set the error for all nodes which have been created before we | ||||||||||
8238 | // recognized the error. | ||||||||||
8239 | for (const auto &Path : SavedImportPaths[FromD]) | ||||||||||
8240 | for (Decl *FromDi : Path) { | ||||||||||
8241 | setImportDeclError(FromDi, ErrOut); | ||||||||||
8242 | //FIXME Should we remove these Decls from ImportedDecls? | ||||||||||
8243 | // Set the error for the mapped to Decl, which is in the "to" context. | ||||||||||
8244 | auto Ii = ImportedDecls.find(FromDi); | ||||||||||
8245 | if (Ii != ImportedDecls.end()) | ||||||||||
8246 | SharedState->setImportDeclError(Ii->second, ErrOut); | ||||||||||
8247 | // FIXME Should we remove these Decls from the LookupTable, | ||||||||||
8248 | // and from ImportedFromDecls? | ||||||||||
8249 | } | ||||||||||
8250 | SavedImportPaths.erase(FromD); | ||||||||||
8251 | |||||||||||
8252 | // Do not return ToDOrErr, error was taken out of it. | ||||||||||
8253 | return make_error<ImportError>(ErrOut); | ||||||||||
8254 | } | ||||||||||
8255 | |||||||||||
8256 | ToD = *ToDOrErr; | ||||||||||
8257 | |||||||||||
8258 | // FIXME: Handle the "already imported with error" case. We can get here | ||||||||||
8259 | // nullptr only if GetImportedOrCreateDecl returned nullptr (after a | ||||||||||
8260 | // previously failed create was requested). | ||||||||||
8261 | // Later GetImportedOrCreateDecl can be updated to return the error. | ||||||||||
8262 | if (!ToD) { | ||||||||||
8263 | auto Err = getImportDeclErrorIfAny(FromD); | ||||||||||
8264 | assert(Err)((Err) ? static_cast<void> (0) : __assert_fail ("Err", "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 8264, __PRETTY_FUNCTION__)); | ||||||||||
8265 | return make_error<ImportError>(*Err); | ||||||||||
8266 | } | ||||||||||
8267 | |||||||||||
8268 | // We could import from the current TU without error. But previously we | ||||||||||
8269 | // already had imported a Decl as `ToD` from another TU (with another | ||||||||||
8270 | // ASTImporter object) and with an error. | ||||||||||
8271 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { | ||||||||||
8272 | setImportDeclError(FromD, *Error); | ||||||||||
8273 | return make_error<ImportError>(*Error); | ||||||||||
8274 | } | ||||||||||
8275 | |||||||||||
8276 | // Make sure that ImportImpl registered the imported decl. | ||||||||||
8277 | assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?")((ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?" ) ? static_cast<void> (0) : __assert_fail ("ImportedDecls.count(FromD) != 0 && \"Missing call to MapImported?\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 8277, __PRETTY_FUNCTION__)); | ||||||||||
8278 | |||||||||||
8279 | // Notify subclasses. | ||||||||||
8280 | Imported(FromD, ToD); | ||||||||||
8281 | |||||||||||
8282 | updateFlags(FromD, ToD); | ||||||||||
8283 | SavedImportPaths.erase(FromD); | ||||||||||
8284 | return ToDOrErr; | ||||||||||
8285 | } | ||||||||||
8286 | |||||||||||
8287 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { | ||||||||||
8288 | if (!FromDC) | ||||||||||
8289 | return FromDC; | ||||||||||
8290 | |||||||||||
8291 | ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC)); | ||||||||||
8292 | if (!ToDCOrErr) | ||||||||||
8293 | return ToDCOrErr.takeError(); | ||||||||||
8294 | auto *ToDC = cast<DeclContext>(*ToDCOrErr); | ||||||||||
8295 | |||||||||||
8296 | // When we're using a record/enum/Objective-C class/protocol as a context, we | ||||||||||
8297 | // need it to have a definition. | ||||||||||
8298 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { | ||||||||||
8299 | auto *FromRecord = cast<RecordDecl>(FromDC); | ||||||||||
8300 | if (ToRecord->isCompleteDefinition()) | ||||||||||
8301 | return ToDC; | ||||||||||
8302 | |||||||||||
8303 | // If FromRecord is not defined we need to force it to be. | ||||||||||
8304 | // Simply calling CompleteDecl(...) for a RecordDecl will break some cases | ||||||||||
8305 | // it will start the definition but we never finish it. | ||||||||||
8306 | // If there are base classes they won't be imported and we will | ||||||||||
8307 | // be missing anything that we inherit from those bases. | ||||||||||
8308 | if (FromRecord->getASTContext().getExternalSource() && | ||||||||||
8309 | !FromRecord->isCompleteDefinition()) | ||||||||||
8310 | FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord); | ||||||||||
8311 | |||||||||||
8312 | if (FromRecord->isCompleteDefinition()) | ||||||||||
8313 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | ||||||||||
8314 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) | ||||||||||
8315 | return std::move(Err); | ||||||||||
8316 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { | ||||||||||
8317 | auto *FromEnum = cast<EnumDecl>(FromDC); | ||||||||||
8318 | if (ToEnum->isCompleteDefinition()) { | ||||||||||
8319 | // Do nothing. | ||||||||||
8320 | } else if (FromEnum->isCompleteDefinition()) { | ||||||||||
8321 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | ||||||||||
8322 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) | ||||||||||
8323 | return std::move(Err); | ||||||||||
8324 | } else { | ||||||||||
8325 | CompleteDecl(ToEnum); | ||||||||||
8326 | } | ||||||||||
8327 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { | ||||||||||
8328 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); | ||||||||||
8329 | if (ToClass->getDefinition()) { | ||||||||||
8330 | // Do nothing. | ||||||||||
8331 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { | ||||||||||
8332 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | ||||||||||
8333 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) | ||||||||||
8334 | return std::move(Err); | ||||||||||
8335 | } else { | ||||||||||
8336 | CompleteDecl(ToClass); | ||||||||||
8337 | } | ||||||||||
8338 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { | ||||||||||
8339 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); | ||||||||||
8340 | if (ToProto->getDefinition()) { | ||||||||||
8341 | // Do nothing. | ||||||||||
8342 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { | ||||||||||
8343 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | ||||||||||
8344 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) | ||||||||||
8345 | return std::move(Err); | ||||||||||
8346 | } else { | ||||||||||
8347 | CompleteDecl(ToProto); | ||||||||||
8348 | } | ||||||||||
8349 | } | ||||||||||
8350 | |||||||||||
8351 | return ToDC; | ||||||||||
8352 | } | ||||||||||
8353 | |||||||||||
8354 | Expected<Expr *> ASTImporter::Import(Expr *FromE) { | ||||||||||
8355 | if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE))) | ||||||||||
8356 | return cast_or_null<Expr>(*ToSOrErr); | ||||||||||
8357 | else | ||||||||||
8358 | return ToSOrErr.takeError(); | ||||||||||
8359 | } | ||||||||||
8360 | |||||||||||
8361 | Expected<Stmt *> ASTImporter::Import(Stmt *FromS) { | ||||||||||
8362 | if (!FromS) | ||||||||||
8363 | return nullptr; | ||||||||||
8364 | |||||||||||
8365 | // Check whether we've already imported this statement. | ||||||||||
8366 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); | ||||||||||
8367 | if (Pos != ImportedStmts.end()) | ||||||||||
8368 | return Pos->second; | ||||||||||
8369 | |||||||||||
8370 | // Import the statement. | ||||||||||
8371 | ASTNodeImporter Importer(*this); | ||||||||||
8372 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); | ||||||||||
8373 | if (!ToSOrErr) | ||||||||||
8374 | return ToSOrErr; | ||||||||||
8375 | |||||||||||
8376 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { | ||||||||||
8377 | auto *FromE = cast<Expr>(FromS); | ||||||||||
8378 | // Copy ExprBitfields, which may not be handled in Expr subclasses | ||||||||||
8379 | // constructors. | ||||||||||
8380 | ToE->setValueKind(FromE->getValueKind()); | ||||||||||
8381 | ToE->setObjectKind(FromE->getObjectKind()); | ||||||||||
8382 | ToE->setDependence(FromE->getDependence()); | ||||||||||
8383 | } | ||||||||||
8384 | |||||||||||
8385 | // Record the imported statement object. | ||||||||||
8386 | ImportedStmts[FromS] = *ToSOrErr; | ||||||||||
8387 | return ToSOrErr; | ||||||||||
8388 | } | ||||||||||
8389 | |||||||||||
8390 | Expected<NestedNameSpecifier *> | ||||||||||
8391 | ASTImporter::Import(NestedNameSpecifier *FromNNS) { | ||||||||||
8392 | if (!FromNNS) | ||||||||||
8393 | return nullptr; | ||||||||||
8394 | |||||||||||
8395 | NestedNameSpecifier *Prefix = nullptr; | ||||||||||
8396 | if (Error Err = importInto(Prefix, FromNNS->getPrefix())) | ||||||||||
8397 | return std::move(Err); | ||||||||||
8398 | |||||||||||
8399 | switch (FromNNS->getKind()) { | ||||||||||
8400 | case NestedNameSpecifier::Identifier: | ||||||||||
8401 | assert(FromNNS->getAsIdentifier() && "NNS should contain identifier.")((FromNNS->getAsIdentifier() && "NNS should contain identifier." ) ? static_cast<void> (0) : __assert_fail ("FromNNS->getAsIdentifier() && \"NNS should contain identifier.\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 8401, __PRETTY_FUNCTION__)); | ||||||||||
8402 | return NestedNameSpecifier::Create(ToContext, Prefix, | ||||||||||
8403 | Import(FromNNS->getAsIdentifier())); | ||||||||||
8404 | |||||||||||
8405 | case NestedNameSpecifier::Namespace: | ||||||||||
8406 | if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) { | ||||||||||
8407 | return NestedNameSpecifier::Create(ToContext, Prefix, | ||||||||||
8408 | cast<NamespaceDecl>(*NSOrErr)); | ||||||||||
8409 | } else | ||||||||||
8410 | return NSOrErr.takeError(); | ||||||||||
8411 | |||||||||||
8412 | case NestedNameSpecifier::NamespaceAlias: | ||||||||||
8413 | if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias())) | ||||||||||
8414 | return NestedNameSpecifier::Create(ToContext, Prefix, | ||||||||||
8415 | cast<NamespaceAliasDecl>(*NSADOrErr)); | ||||||||||
8416 | else | ||||||||||
8417 | return NSADOrErr.takeError(); | ||||||||||
8418 | |||||||||||
8419 | case NestedNameSpecifier::Global: | ||||||||||
8420 | return NestedNameSpecifier::GlobalSpecifier(ToContext); | ||||||||||
8421 | |||||||||||
8422 | case NestedNameSpecifier::Super: | ||||||||||
8423 | if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl())) | ||||||||||
8424 | return NestedNameSpecifier::SuperSpecifier(ToContext, | ||||||||||
8425 | cast<CXXRecordDecl>(*RDOrErr)); | ||||||||||
8426 | else | ||||||||||
8427 | return RDOrErr.takeError(); | ||||||||||
8428 | |||||||||||
8429 | case NestedNameSpecifier::TypeSpec: | ||||||||||
8430 | case NestedNameSpecifier::TypeSpecWithTemplate: | ||||||||||
8431 | if (Expected<QualType> TyOrErr = | ||||||||||
8432 | Import(QualType(FromNNS->getAsType(), 0u))) { | ||||||||||
8433 | bool TSTemplate = | ||||||||||
8434 | FromNNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate; | ||||||||||
8435 | return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate, | ||||||||||
8436 | TyOrErr->getTypePtr()); | ||||||||||
8437 | } else { | ||||||||||
8438 | return TyOrErr.takeError(); | ||||||||||
8439 | } | ||||||||||
8440 | } | ||||||||||
8441 | |||||||||||
8442 | llvm_unreachable("Invalid nested name specifier kind")::llvm::llvm_unreachable_internal("Invalid nested name specifier kind" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 8442); | ||||||||||
8443 | } | ||||||||||
8444 | |||||||||||
8445 | Expected<NestedNameSpecifierLoc> | ||||||||||
8446 | ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { | ||||||||||
8447 | // Copied from NestedNameSpecifier mostly. | ||||||||||
8448 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; | ||||||||||
8449 | NestedNameSpecifierLoc NNS = FromNNS; | ||||||||||
8450 | |||||||||||
8451 | // Push each of the nested-name-specifiers's onto a stack for | ||||||||||
8452 | // serialization in reverse order. | ||||||||||
8453 | while (NNS) { | ||||||||||
8454 | NestedNames.push_back(NNS); | ||||||||||
8455 | NNS = NNS.getPrefix(); | ||||||||||
8456 | } | ||||||||||
8457 | |||||||||||
8458 | NestedNameSpecifierLocBuilder Builder; | ||||||||||
8459 | |||||||||||
8460 | while (!NestedNames.empty()) { | ||||||||||
8461 | NNS = NestedNames.pop_back_val(); | ||||||||||
8462 | NestedNameSpecifier *Spec = nullptr; | ||||||||||
8463 | if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier())) | ||||||||||
8464 | return std::move(Err); | ||||||||||
8465 | |||||||||||
8466 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); | ||||||||||
8467 | |||||||||||
8468 | SourceLocation ToLocalBeginLoc, ToLocalEndLoc; | ||||||||||
8469 | if (Kind != NestedNameSpecifier::Super) { | ||||||||||
8470 | if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc())) | ||||||||||
8471 | return std::move(Err); | ||||||||||
8472 | |||||||||||
8473 | if (Kind != NestedNameSpecifier::Global) | ||||||||||
8474 | if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc())) | ||||||||||
8475 | return std::move(Err); | ||||||||||
8476 | } | ||||||||||
8477 | |||||||||||
8478 | switch (Kind) { | ||||||||||
8479 | case NestedNameSpecifier::Identifier: | ||||||||||
8480 | Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc, | ||||||||||
8481 | ToLocalEndLoc); | ||||||||||
8482 | break; | ||||||||||
8483 | |||||||||||
8484 | case NestedNameSpecifier::Namespace: | ||||||||||
8485 | Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc, | ||||||||||
8486 | ToLocalEndLoc); | ||||||||||
8487 | break; | ||||||||||
8488 | |||||||||||
8489 | case NestedNameSpecifier::NamespaceAlias: | ||||||||||
8490 | Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(), | ||||||||||
8491 | ToLocalBeginLoc, ToLocalEndLoc); | ||||||||||
8492 | break; | ||||||||||
8493 | |||||||||||
8494 | case NestedNameSpecifier::TypeSpec: | ||||||||||
8495 | case NestedNameSpecifier::TypeSpecWithTemplate: { | ||||||||||
8496 | SourceLocation ToTLoc; | ||||||||||
8497 | if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc())) | ||||||||||
8498 | return std::move(Err); | ||||||||||
8499 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( | ||||||||||
8500 | QualType(Spec->getAsType(), 0), ToTLoc); | ||||||||||
8501 | if (Kind == NestedNameSpecifier::TypeSpecWithTemplate) | ||||||||||
8502 | // ToLocalBeginLoc is here the location of the 'template' keyword. | ||||||||||
8503 | Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(), | ||||||||||
8504 | ToLocalEndLoc); | ||||||||||
8505 | else | ||||||||||
8506 | // No location for 'template' keyword here. | ||||||||||
8507 | Builder.Extend(getToContext(), SourceLocation{}, TSI->getTypeLoc(), | ||||||||||
8508 | ToLocalEndLoc); | ||||||||||
8509 | break; | ||||||||||
8510 | } | ||||||||||
8511 | |||||||||||
8512 | case NestedNameSpecifier::Global: | ||||||||||
8513 | Builder.MakeGlobal(getToContext(), ToLocalBeginLoc); | ||||||||||
8514 | break; | ||||||||||
8515 | |||||||||||
8516 | case NestedNameSpecifier::Super: { | ||||||||||
8517 | auto ToSourceRangeOrErr = Import(NNS.getSourceRange()); | ||||||||||
8518 | if (!ToSourceRangeOrErr) | ||||||||||
8519 | return ToSourceRangeOrErr.takeError(); | ||||||||||
8520 | |||||||||||
8521 | Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(), | ||||||||||
8522 | ToSourceRangeOrErr->getBegin(), | ||||||||||
8523 | ToSourceRangeOrErr->getEnd()); | ||||||||||
8524 | } | ||||||||||
8525 | } | ||||||||||
8526 | } | ||||||||||
8527 | |||||||||||
8528 | return Builder.getWithLocInContext(getToContext()); | ||||||||||
8529 | } | ||||||||||
8530 | |||||||||||
8531 | Expected<TemplateName> ASTImporter::Import(TemplateName From) { | ||||||||||
8532 | switch (From.getKind()) { | ||||||||||
8533 | case TemplateName::Template: | ||||||||||
8534 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) | ||||||||||
8535 | return TemplateName(cast<TemplateDecl>(*ToTemplateOrErr)); | ||||||||||
8536 | else | ||||||||||
8537 | return ToTemplateOrErr.takeError(); | ||||||||||
8538 | |||||||||||
8539 | case TemplateName::OverloadedTemplate: { | ||||||||||
8540 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); | ||||||||||
8541 | UnresolvedSet<2> ToTemplates; | ||||||||||
8542 | for (auto *I : *FromStorage) { | ||||||||||
8543 | if (auto ToOrErr = Import(I)) | ||||||||||
8544 | ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr)); | ||||||||||
8545 | else | ||||||||||
8546 | return ToOrErr.takeError(); | ||||||||||
8547 | } | ||||||||||
8548 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), | ||||||||||
8549 | ToTemplates.end()); | ||||||||||
8550 | } | ||||||||||
8551 | |||||||||||
8552 | case TemplateName::AssumedTemplate: { | ||||||||||
8553 | AssumedTemplateStorage *FromStorage = From.getAsAssumedTemplateName(); | ||||||||||
8554 | auto DeclNameOrErr = Import(FromStorage->getDeclName()); | ||||||||||
8555 | if (!DeclNameOrErr) | ||||||||||
8556 | return DeclNameOrErr.takeError(); | ||||||||||
8557 | return ToContext.getAssumedTemplateName(*DeclNameOrErr); | ||||||||||
8558 | } | ||||||||||
8559 | |||||||||||
8560 | case TemplateName::QualifiedTemplate: { | ||||||||||
8561 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); | ||||||||||
8562 | auto QualifierOrErr = Import(QTN->getQualifier()); | ||||||||||
8563 | if (!QualifierOrErr) | ||||||||||
8564 | return QualifierOrErr.takeError(); | ||||||||||
8565 | |||||||||||
8566 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) | ||||||||||
8567 | return ToContext.getQualifiedTemplateName( | ||||||||||
8568 | *QualifierOrErr, QTN->hasTemplateKeyword(), | ||||||||||
8569 | cast<TemplateDecl>(*ToTemplateOrErr)); | ||||||||||
8570 | else | ||||||||||
8571 | return ToTemplateOrErr.takeError(); | ||||||||||
8572 | } | ||||||||||
8573 | |||||||||||
8574 | case TemplateName::DependentTemplate: { | ||||||||||
8575 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); | ||||||||||
8576 | auto QualifierOrErr = Import(DTN->getQualifier()); | ||||||||||
8577 | if (!QualifierOrErr) | ||||||||||
8578 | return QualifierOrErr.takeError(); | ||||||||||
8579 | |||||||||||
8580 | if (DTN->isIdentifier()) { | ||||||||||
8581 | return ToContext.getDependentTemplateName(*QualifierOrErr, | ||||||||||
8582 | Import(DTN->getIdentifier())); | ||||||||||
8583 | } | ||||||||||
8584 | |||||||||||
8585 | return ToContext.getDependentTemplateName(*QualifierOrErr, | ||||||||||
8586 | DTN->getOperator()); | ||||||||||
8587 | } | ||||||||||
8588 | |||||||||||
8589 | case TemplateName::SubstTemplateTemplateParm: { | ||||||||||
8590 | SubstTemplateTemplateParmStorage *Subst = | ||||||||||
8591 | From.getAsSubstTemplateTemplateParm(); | ||||||||||
8592 | ExpectedDecl ParamOrErr = Import(Subst->getParameter()); | ||||||||||
8593 | if (!ParamOrErr) | ||||||||||
8594 | return ParamOrErr.takeError(); | ||||||||||
8595 | |||||||||||
8596 | auto ReplacementOrErr = Import(Subst->getReplacement()); | ||||||||||
8597 | if (!ReplacementOrErr) | ||||||||||
8598 | return ReplacementOrErr.takeError(); | ||||||||||
8599 | |||||||||||
8600 | return ToContext.getSubstTemplateTemplateParm( | ||||||||||
8601 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ReplacementOrErr); | ||||||||||
8602 | } | ||||||||||
8603 | |||||||||||
8604 | case TemplateName::SubstTemplateTemplateParmPack: { | ||||||||||
8605 | SubstTemplateTemplateParmPackStorage *SubstPack | ||||||||||
8606 | = From.getAsSubstTemplateTemplateParmPack(); | ||||||||||
8607 | ExpectedDecl ParamOrErr = Import(SubstPack->getParameterPack()); | ||||||||||
8608 | if (!ParamOrErr) | ||||||||||
8609 | return ParamOrErr.takeError(); | ||||||||||
8610 | |||||||||||
8611 | ASTNodeImporter Importer(*this); | ||||||||||
8612 | auto ArgPackOrErr = | ||||||||||
8613 | Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); | ||||||||||
8614 | if (!ArgPackOrErr) | ||||||||||
8615 | return ArgPackOrErr.takeError(); | ||||||||||
8616 | |||||||||||
8617 | return ToContext.getSubstTemplateTemplateParmPack( | ||||||||||
8618 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ArgPackOrErr); | ||||||||||
8619 | } | ||||||||||
8620 | } | ||||||||||
8621 | |||||||||||
8622 | llvm_unreachable("Invalid template name kind")::llvm::llvm_unreachable_internal("Invalid template name kind" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 8622); | ||||||||||
8623 | } | ||||||||||
8624 | |||||||||||
8625 | Expected<SourceLocation> ASTImporter::Import(SourceLocation FromLoc) { | ||||||||||
8626 | if (FromLoc.isInvalid()) | ||||||||||
8627 | return SourceLocation{}; | ||||||||||
8628 | |||||||||||
8629 | SourceManager &FromSM = FromContext.getSourceManager(); | ||||||||||
8630 | bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc); | ||||||||||
8631 | |||||||||||
8632 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); | ||||||||||
8633 | Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin); | ||||||||||
8634 | if (!ToFileIDOrErr) | ||||||||||
8635 | return ToFileIDOrErr.takeError(); | ||||||||||
8636 | SourceManager &ToSM = ToContext.getSourceManager(); | ||||||||||
8637 | return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second); | ||||||||||
8638 | } | ||||||||||
8639 | |||||||||||
8640 | Expected<SourceRange> ASTImporter::Import(SourceRange FromRange) { | ||||||||||
8641 | SourceLocation ToBegin, ToEnd; | ||||||||||
8642 | if (Error Err = importInto(ToBegin, FromRange.getBegin())) | ||||||||||
8643 | return std::move(Err); | ||||||||||
8644 | if (Error Err = importInto(ToEnd, FromRange.getEnd())) | ||||||||||
8645 | return std::move(Err); | ||||||||||
8646 | |||||||||||
8647 | return SourceRange(ToBegin, ToEnd); | ||||||||||
8648 | } | ||||||||||
8649 | |||||||||||
8650 | Expected<FileID> ASTImporter::Import(FileID FromID, bool IsBuiltin) { | ||||||||||
8651 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); | ||||||||||
8652 | if (Pos != ImportedFileIDs.end()) | ||||||||||
8653 | return Pos->second; | ||||||||||
8654 | |||||||||||
8655 | SourceManager &FromSM = FromContext.getSourceManager(); | ||||||||||
8656 | SourceManager &ToSM = ToContext.getSourceManager(); | ||||||||||
8657 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); | ||||||||||
8658 | |||||||||||
8659 | // Map the FromID to the "to" source manager. | ||||||||||
8660 | FileID ToID; | ||||||||||
8661 | if (FromSLoc.isExpansion()) { | ||||||||||
8662 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); | ||||||||||
8663 | ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc()); | ||||||||||
8664 | if (!ToSpLoc) | ||||||||||
8665 | return ToSpLoc.takeError(); | ||||||||||
8666 | ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart()); | ||||||||||
8667 | if (!ToExLocS) | ||||||||||
8668 | return ToExLocS.takeError(); | ||||||||||
8669 | unsigned TokenLen = FromSM.getFileIDSize(FromID); | ||||||||||
8670 | SourceLocation MLoc; | ||||||||||
8671 | if (FromEx.isMacroArgExpansion()) { | ||||||||||
8672 | MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, TokenLen); | ||||||||||
8673 | } else { | ||||||||||
8674 | if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd())) | ||||||||||
8675 | MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, TokenLen, | ||||||||||
8676 | FromEx.isExpansionTokenRange()); | ||||||||||
8677 | else | ||||||||||
8678 | return ToExLocE.takeError(); | ||||||||||
8679 | } | ||||||||||
8680 | ToID = ToSM.getFileID(MLoc); | ||||||||||
8681 | } else { | ||||||||||
8682 | const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache(); | ||||||||||
8683 | |||||||||||
8684 | if (!IsBuiltin && !Cache->BufferOverridden) { | ||||||||||
8685 | // Include location of this file. | ||||||||||
8686 | ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); | ||||||||||
8687 | if (!ToIncludeLoc) | ||||||||||
8688 | return ToIncludeLoc.takeError(); | ||||||||||
8689 | |||||||||||
8690 | // Every FileID that is not the main FileID needs to have a valid include | ||||||||||
8691 | // location so that the include chain points to the main FileID. When | ||||||||||
8692 | // importing the main FileID (which has no include location), we need to | ||||||||||
8693 | // create a fake include location in the main file to keep this property | ||||||||||
8694 | // intact. | ||||||||||
8695 | SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc; | ||||||||||
8696 | if (FromID == FromSM.getMainFileID()) | ||||||||||
8697 | ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID()); | ||||||||||
8698 | |||||||||||
8699 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { | ||||||||||
8700 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the | ||||||||||
8701 | // disk again | ||||||||||
8702 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather | ||||||||||
8703 | // than mmap the files several times. | ||||||||||
8704 | auto Entry = | ||||||||||
8705 | ToFileManager.getFile(Cache->OrigEntry->getName()); | ||||||||||
8706 | // FIXME: The filename may be a virtual name that does probably not | ||||||||||
8707 | // point to a valid file and we get no Entry here. In this case try with | ||||||||||
8708 | // the memory buffer below. | ||||||||||
8709 | if (Entry) | ||||||||||
8710 | ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc, | ||||||||||
8711 | FromSLoc.getFile().getFileCharacteristic()); | ||||||||||
8712 | } | ||||||||||
8713 | } | ||||||||||
8714 | |||||||||||
8715 | if (ToID.isInvalid() || IsBuiltin) { | ||||||||||
8716 | // FIXME: We want to re-use the existing MemoryBuffer! | ||||||||||
8717 | llvm::Optional<llvm::MemoryBufferRef> FromBuf = | ||||||||||
8718 | Cache->getBufferOrNone(FromContext.getDiagnostics(), | ||||||||||
8719 | FromSM.getFileManager(), SourceLocation{}); | ||||||||||
8720 | if (!FromBuf) | ||||||||||
8721 | return llvm::make_error<ImportError>(ImportError::Unknown); | ||||||||||
8722 | |||||||||||
8723 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = | ||||||||||
8724 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), | ||||||||||
8725 | FromBuf->getBufferIdentifier()); | ||||||||||
8726 | ToID = ToSM.createFileID(std::move(ToBuf), | ||||||||||
8727 | FromSLoc.getFile().getFileCharacteristic()); | ||||||||||
8728 | } | ||||||||||
8729 | } | ||||||||||
8730 | |||||||||||
8731 | assert(ToID.isValid() && "Unexpected invalid fileID was created.")((ToID.isValid() && "Unexpected invalid fileID was created." ) ? static_cast<void> (0) : __assert_fail ("ToID.isValid() && \"Unexpected invalid fileID was created.\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 8731, __PRETTY_FUNCTION__)); | ||||||||||
8732 | |||||||||||
8733 | ImportedFileIDs[FromID] = ToID; | ||||||||||
8734 | |||||||||||
8735 | if (FileIDImportHandler) | ||||||||||
8736 | FileIDImportHandler(ToID, FromID); | ||||||||||
8737 | |||||||||||
8738 | return ToID; | ||||||||||
8739 | } | ||||||||||
8740 | |||||||||||
8741 | Expected<CXXCtorInitializer *> ASTImporter::Import(CXXCtorInitializer *From) { | ||||||||||
8742 | ExpectedExpr ToExprOrErr = Import(From->getInit()); | ||||||||||
8743 | if (!ToExprOrErr) | ||||||||||
8744 | return ToExprOrErr.takeError(); | ||||||||||
8745 | |||||||||||
8746 | auto LParenLocOrErr = Import(From->getLParenLoc()); | ||||||||||
8747 | if (!LParenLocOrErr) | ||||||||||
8748 | return LParenLocOrErr.takeError(); | ||||||||||
8749 | |||||||||||
8750 | auto RParenLocOrErr = Import(From->getRParenLoc()); | ||||||||||
8751 | if (!RParenLocOrErr) | ||||||||||
8752 | return RParenLocOrErr.takeError(); | ||||||||||
8753 | |||||||||||
8754 | if (From->isBaseInitializer()) { | ||||||||||
8755 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); | ||||||||||
8756 | if (!ToTInfoOrErr) | ||||||||||
8757 | return ToTInfoOrErr.takeError(); | ||||||||||
8758 | |||||||||||
8759 | SourceLocation EllipsisLoc; | ||||||||||
8760 | if (From->isPackExpansion()) | ||||||||||
8761 | if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc())) | ||||||||||
8762 | return std::move(Err); | ||||||||||
8763 | |||||||||||
8764 | return new (ToContext) CXXCtorInitializer( | ||||||||||
8765 | ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr, | ||||||||||
8766 | *ToExprOrErr, *RParenLocOrErr, EllipsisLoc); | ||||||||||
8767 | } else if (From->isMemberInitializer()) { | ||||||||||
8768 | ExpectedDecl ToFieldOrErr = Import(From->getMember()); | ||||||||||
8769 | if (!ToFieldOrErr) | ||||||||||
8770 | return ToFieldOrErr.takeError(); | ||||||||||
8771 | |||||||||||
8772 | auto MemberLocOrErr = Import(From->getMemberLocation()); | ||||||||||
8773 | if (!MemberLocOrErr) | ||||||||||
8774 | return MemberLocOrErr.takeError(); | ||||||||||
8775 | |||||||||||
8776 | return new (ToContext) CXXCtorInitializer( | ||||||||||
8777 | ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr, | ||||||||||
8778 | *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); | ||||||||||
8779 | } else if (From->isIndirectMemberInitializer()) { | ||||||||||
8780 | ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember()); | ||||||||||
8781 | if (!ToIFieldOrErr) | ||||||||||
8782 | return ToIFieldOrErr.takeError(); | ||||||||||
8783 | |||||||||||
8784 | auto MemberLocOrErr = Import(From->getMemberLocation()); | ||||||||||
8785 | if (!MemberLocOrErr) | ||||||||||
8786 | return MemberLocOrErr.takeError(); | ||||||||||
8787 | |||||||||||
8788 | return new (ToContext) CXXCtorInitializer( | ||||||||||
8789 | ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr), | ||||||||||
8790 | *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); | ||||||||||
8791 | } else if (From->isDelegatingInitializer()) { | ||||||||||
8792 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); | ||||||||||
8793 | if (!ToTInfoOrErr) | ||||||||||
8794 | return ToTInfoOrErr.takeError(); | ||||||||||
8795 | |||||||||||
8796 | return new (ToContext) | ||||||||||
8797 | CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr, | ||||||||||
8798 | *ToExprOrErr, *RParenLocOrErr); | ||||||||||
8799 | } else { | ||||||||||
8800 | // FIXME: assert? | ||||||||||
8801 | return make_error<ImportError>(); | ||||||||||
8802 | } | ||||||||||
8803 | } | ||||||||||
8804 | |||||||||||
8805 | Expected<CXXBaseSpecifier *> | ||||||||||
8806 | ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { | ||||||||||
8807 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); | ||||||||||
8808 | if (Pos != ImportedCXXBaseSpecifiers.end()) | ||||||||||
8809 | return Pos->second; | ||||||||||
8810 | |||||||||||
8811 | Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange()); | ||||||||||
8812 | if (!ToSourceRange) | ||||||||||
8813 | return ToSourceRange.takeError(); | ||||||||||
8814 | Expected<TypeSourceInfo *> ToTSI = Import(BaseSpec->getTypeSourceInfo()); | ||||||||||
8815 | if (!ToTSI) | ||||||||||
8816 | return ToTSI.takeError(); | ||||||||||
8817 | ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc()); | ||||||||||
8818 | if (!ToEllipsisLoc) | ||||||||||
8819 | return ToEllipsisLoc.takeError(); | ||||||||||
8820 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( | ||||||||||
8821 | *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), | ||||||||||
8822 | BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc); | ||||||||||
8823 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; | ||||||||||
8824 | return Imported; | ||||||||||
8825 | } | ||||||||||
8826 | |||||||||||
8827 | llvm::Expected<APValue> ASTImporter::Import(const APValue &FromValue) { | ||||||||||
8828 | ASTNodeImporter Importer(*this); | ||||||||||
8829 | return Importer.ImportAPValue(FromValue); | ||||||||||
8830 | } | ||||||||||
8831 | |||||||||||
8832 | Error ASTImporter::ImportDefinition(Decl *From) { | ||||||||||
8833 | ExpectedDecl ToOrErr = Import(From); | ||||||||||
8834 | if (!ToOrErr) | ||||||||||
8835 | return ToOrErr.takeError(); | ||||||||||
8836 | Decl *To = *ToOrErr; | ||||||||||
8837 | |||||||||||
8838 | auto *FromDC = cast<DeclContext>(From); | ||||||||||
8839 | ASTNodeImporter Importer(*this); | ||||||||||
8840 | |||||||||||
8841 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { | ||||||||||
8842 | if (!ToRecord->getDefinition()) { | ||||||||||
8843 | return Importer.ImportDefinition( | ||||||||||
8844 | cast<RecordDecl>(FromDC), ToRecord, | ||||||||||
8845 | ASTNodeImporter::IDK_Everything); | ||||||||||
8846 | } | ||||||||||
8847 | } | ||||||||||
8848 | |||||||||||
8849 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { | ||||||||||
8850 | if (!ToEnum->getDefinition()) { | ||||||||||
8851 | return Importer.ImportDefinition( | ||||||||||
8852 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); | ||||||||||
8853 | } | ||||||||||
8854 | } | ||||||||||
8855 | |||||||||||
8856 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { | ||||||||||
8857 | if (!ToIFace->getDefinition()) { | ||||||||||
8858 | return Importer.ImportDefinition( | ||||||||||
8859 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, | ||||||||||
8860 | ASTNodeImporter::IDK_Everything); | ||||||||||
8861 | } | ||||||||||
8862 | } | ||||||||||
8863 | |||||||||||
8864 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { | ||||||||||
8865 | if (!ToProto->getDefinition()) { | ||||||||||
8866 | return Importer.ImportDefinition( | ||||||||||
8867 | cast<ObjCProtocolDecl>(FromDC), ToProto, | ||||||||||
8868 | ASTNodeImporter::IDK_Everything); | ||||||||||
8869 | } | ||||||||||
8870 | } | ||||||||||
8871 | |||||||||||
8872 | return Importer.ImportDeclContext(FromDC, true); | ||||||||||
8873 | } | ||||||||||
8874 | |||||||||||
8875 | Expected<DeclarationName> ASTImporter::Import(DeclarationName FromName) { | ||||||||||
8876 | if (!FromName) | ||||||||||
8877 | return DeclarationName{}; | ||||||||||
8878 | |||||||||||
8879 | switch (FromName.getNameKind()) { | ||||||||||
8880 | case DeclarationName::Identifier: | ||||||||||
8881 | return DeclarationName(Import(FromName.getAsIdentifierInfo())); | ||||||||||
8882 | |||||||||||
8883 | case DeclarationName::ObjCZeroArgSelector: | ||||||||||
8884 | case DeclarationName::ObjCOneArgSelector: | ||||||||||
8885 | case DeclarationName::ObjCMultiArgSelector: | ||||||||||
8886 | if (auto ToSelOrErr = Import(FromName.getObjCSelector())) | ||||||||||
8887 | return DeclarationName(*ToSelOrErr); | ||||||||||
8888 | else | ||||||||||
8889 | return ToSelOrErr.takeError(); | ||||||||||
8890 | |||||||||||
8891 | case DeclarationName::CXXConstructorName: { | ||||||||||
8892 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) | ||||||||||
8893 | return ToContext.DeclarationNames.getCXXConstructorName( | ||||||||||
8894 | ToContext.getCanonicalType(*ToTyOrErr)); | ||||||||||
8895 | else | ||||||||||
8896 | return ToTyOrErr.takeError(); | ||||||||||
8897 | } | ||||||||||
8898 | |||||||||||
8899 | case DeclarationName::CXXDestructorName: { | ||||||||||
8900 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) | ||||||||||
8901 | return ToContext.DeclarationNames.getCXXDestructorName( | ||||||||||
8902 | ToContext.getCanonicalType(*ToTyOrErr)); | ||||||||||
8903 | else | ||||||||||
8904 | return ToTyOrErr.takeError(); | ||||||||||
8905 | } | ||||||||||
8906 | |||||||||||
8907 | case DeclarationName::CXXDeductionGuideName: { | ||||||||||
8908 | if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate())) | ||||||||||
8909 | return ToContext.DeclarationNames.getCXXDeductionGuideName( | ||||||||||
8910 | cast<TemplateDecl>(*ToTemplateOrErr)); | ||||||||||
8911 | else | ||||||||||
8912 | return ToTemplateOrErr.takeError(); | ||||||||||
8913 | } | ||||||||||
8914 | |||||||||||
8915 | case DeclarationName::CXXConversionFunctionName: { | ||||||||||
8916 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) | ||||||||||
8917 | return ToContext.DeclarationNames.getCXXConversionFunctionName( | ||||||||||
8918 | ToContext.getCanonicalType(*ToTyOrErr)); | ||||||||||
8919 | else | ||||||||||
8920 | return ToTyOrErr.takeError(); | ||||||||||
8921 | } | ||||||||||
8922 | |||||||||||
8923 | case DeclarationName::CXXOperatorName: | ||||||||||
8924 | return ToContext.DeclarationNames.getCXXOperatorName( | ||||||||||
8925 | FromName.getCXXOverloadedOperator()); | ||||||||||
8926 | |||||||||||
8927 | case DeclarationName::CXXLiteralOperatorName: | ||||||||||
8928 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( | ||||||||||
8929 | Import(FromName.getCXXLiteralIdentifier())); | ||||||||||
8930 | |||||||||||
8931 | case DeclarationName::CXXUsingDirective: | ||||||||||
8932 | // FIXME: STATICS! | ||||||||||
8933 | return DeclarationName::getUsingDirectiveName(); | ||||||||||
8934 | } | ||||||||||
8935 | |||||||||||
8936 | llvm_unreachable("Invalid DeclarationName Kind!")::llvm::llvm_unreachable_internal("Invalid DeclarationName Kind!" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 8936); | ||||||||||
8937 | } | ||||||||||
8938 | |||||||||||
8939 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { | ||||||||||
8940 | if (!FromId) | ||||||||||
8941 | return nullptr; | ||||||||||
8942 | |||||||||||
8943 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); | ||||||||||
8944 | |||||||||||
8945 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) | ||||||||||
8946 | ToId->setBuiltinID(FromId->getBuiltinID()); | ||||||||||
8947 | |||||||||||
8948 | return ToId; | ||||||||||
8949 | } | ||||||||||
8950 | |||||||||||
8951 | Expected<Selector> ASTImporter::Import(Selector FromSel) { | ||||||||||
8952 | if (FromSel.isNull()) | ||||||||||
8953 | return Selector{}; | ||||||||||
8954 | |||||||||||
8955 | SmallVector<IdentifierInfo *, 4> Idents; | ||||||||||
8956 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); | ||||||||||
8957 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) | ||||||||||
8958 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); | ||||||||||
8959 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); | ||||||||||
8960 | } | ||||||||||
8961 | |||||||||||
8962 | llvm::Expected<APValue> | ||||||||||
8963 | ASTNodeImporter::ImportAPValue(const APValue &FromValue) { | ||||||||||
8964 | APValue Result; | ||||||||||
8965 | llvm::Error Err = llvm::Error::success(); | ||||||||||
8966 | auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) { | ||||||||||
8967 | for (unsigned Idx = 0; Idx < Size; Idx++) { | ||||||||||
8968 | APValue Tmp = importChecked(Err, From[Idx]); | ||||||||||
8969 | To[Idx] = Tmp; | ||||||||||
8970 | } | ||||||||||
8971 | }; | ||||||||||
8972 | switch (FromValue.getKind()) { | ||||||||||
8973 | case APValue::None: | ||||||||||
8974 | case APValue::Indeterminate: | ||||||||||
8975 | case APValue::Int: | ||||||||||
8976 | case APValue::Float: | ||||||||||
8977 | case APValue::FixedPoint: | ||||||||||
8978 | case APValue::ComplexInt: | ||||||||||
8979 | case APValue::ComplexFloat: | ||||||||||
8980 | Result = FromValue; | ||||||||||
8981 | break; | ||||||||||
8982 | case APValue::Vector: { | ||||||||||
8983 | Result.MakeVector(); | ||||||||||
8984 | MutableArrayRef<APValue> Elts = | ||||||||||
8985 | Result.setVectorUninit(FromValue.getVectorLength()); | ||||||||||
8986 | ImportLoop( | ||||||||||
8987 | ((const APValue::Vec *)(const char *)FromValue.Data.buffer)->Elts, | ||||||||||
8988 | Elts.data(), FromValue.getVectorLength()); | ||||||||||
8989 | break; | ||||||||||
8990 | } | ||||||||||
8991 | case APValue::Array: | ||||||||||
8992 | Result.MakeArray(FromValue.getArrayInitializedElts(), | ||||||||||
8993 | FromValue.getArraySize()); | ||||||||||
8994 | ImportLoop( | ||||||||||
8995 | ((const APValue::Arr *)(const char *)FromValue.Data.buffer)->Elts, | ||||||||||
8996 | ((const APValue::Arr *)(const char *)Result.Data.buffer)->Elts, | ||||||||||
8997 | FromValue.getArrayInitializedElts()); | ||||||||||
8998 | break; | ||||||||||
8999 | case APValue::Struct: | ||||||||||
9000 | Result.MakeStruct(FromValue.getStructNumBases(), | ||||||||||
9001 | FromValue.getStructNumFields()); | ||||||||||
9002 | ImportLoop( | ||||||||||
9003 | ((const APValue::StructData *)(const char *)FromValue.Data.buffer) | ||||||||||
9004 | ->Elts, | ||||||||||
9005 | ((const APValue::StructData *)(const char *)Result.Data.buffer)->Elts, | ||||||||||
9006 | FromValue.getStructNumBases() + FromValue.getStructNumFields()); | ||||||||||
9007 | break; | ||||||||||
9008 | case APValue::Union: { | ||||||||||
9009 | Result.MakeUnion(); | ||||||||||
9010 | const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField()); | ||||||||||
9011 | APValue ImpValue = importChecked(Err, FromValue.getUnionValue()); | ||||||||||
9012 | if (Err) | ||||||||||
9013 | return std::move(Err); | ||||||||||
9014 | Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue); | ||||||||||
9015 | break; | ||||||||||
9016 | } | ||||||||||
9017 | case APValue::AddrLabelDiff: { | ||||||||||
9018 | Result.MakeAddrLabelDiff(); | ||||||||||
9019 | const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS()); | ||||||||||
9020 | const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS()); | ||||||||||
9021 | if (Err) | ||||||||||
9022 | return std::move(Err); | ||||||||||
9023 | Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS), | ||||||||||
9024 | cast<AddrLabelExpr>(ImpRHS)); | ||||||||||
9025 | break; | ||||||||||
9026 | } | ||||||||||
9027 | case APValue::MemberPointer: { | ||||||||||
9028 | const Decl *ImpMemPtrDecl = | ||||||||||
9029 | importChecked(Err, FromValue.getMemberPointerDecl()); | ||||||||||
9030 | if (Err) | ||||||||||
9031 | return std::move(Err); | ||||||||||
9032 | MutableArrayRef<const CXXRecordDecl *> ToPath = | ||||||||||
9033 | Result.setMemberPointerUninit( | ||||||||||
9034 | cast<const ValueDecl>(ImpMemPtrDecl), | ||||||||||
9035 | FromValue.isMemberPointerToDerivedMember(), | ||||||||||
9036 | FromValue.getMemberPointerPath().size()); | ||||||||||
9037 | llvm::ArrayRef<const CXXRecordDecl *> FromPath = | ||||||||||
9038 | Result.getMemberPointerPath(); | ||||||||||
9039 | for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size(); | ||||||||||
9040 | Idx++) { | ||||||||||
9041 | const Decl *ImpDecl = importChecked(Err, FromPath[Idx]); | ||||||||||
9042 | if (Err) | ||||||||||
9043 | return std::move(Err); | ||||||||||
9044 | ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl()); | ||||||||||
9045 | } | ||||||||||
9046 | break; | ||||||||||
9047 | } | ||||||||||
9048 | case APValue::LValue: | ||||||||||
9049 | APValue::LValueBase Base; | ||||||||||
9050 | QualType FromElemTy; | ||||||||||
9051 | if (FromValue.getLValueBase()) { | ||||||||||
9052 | assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&((!FromValue.getLValueBase().is<DynamicAllocLValue>() && "in C++20 dynamic allocation are transient so they shouldn't " "appear in the AST") ? static_cast<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-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 9054, __PRETTY_FUNCTION__)) | ||||||||||
9053 | "in C++20 dynamic allocation are transient so they shouldn't "((!FromValue.getLValueBase().is<DynamicAllocLValue>() && "in C++20 dynamic allocation are transient so they shouldn't " "appear in the AST") ? static_cast<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-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 9054, __PRETTY_FUNCTION__)) | ||||||||||
9054 | "appear in the AST")((!FromValue.getLValueBase().is<DynamicAllocLValue>() && "in C++20 dynamic allocation are transient so they shouldn't " "appear in the AST") ? static_cast<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-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 9054, __PRETTY_FUNCTION__)); | ||||||||||
9055 | if (!FromValue.getLValueBase().is<TypeInfoLValue>()) { | ||||||||||
9056 | if (const auto *E = | ||||||||||
9057 | FromValue.getLValueBase().dyn_cast<const Expr *>()) { | ||||||||||
9058 | FromElemTy = E->getType(); | ||||||||||
9059 | const Expr *ImpExpr = importChecked(Err, E); | ||||||||||
9060 | if (Err) | ||||||||||
9061 | return std::move(Err); | ||||||||||
9062 | Base = APValue::LValueBase(ImpExpr, | ||||||||||
9063 | FromValue.getLValueBase().getCallIndex(), | ||||||||||
9064 | FromValue.getLValueBase().getVersion()); | ||||||||||
9065 | } else { | ||||||||||
9066 | FromElemTy = | ||||||||||
9067 | FromValue.getLValueBase().get<const ValueDecl *>()->getType(); | ||||||||||
9068 | const Decl *ImpDecl = importChecked( | ||||||||||
9069 | Err, FromValue.getLValueBase().get<const ValueDecl *>()); | ||||||||||
9070 | if (Err) | ||||||||||
9071 | return std::move(Err); | ||||||||||
9072 | Base = APValue::LValueBase(cast<ValueDecl>(ImpDecl), | ||||||||||
9073 | FromValue.getLValueBase().getCallIndex(), | ||||||||||
9074 | FromValue.getLValueBase().getVersion()); | ||||||||||
9075 | } | ||||||||||
9076 | } else { | ||||||||||
9077 | FromElemTy = FromValue.getLValueBase().getTypeInfoType(); | ||||||||||
9078 | QualType ImpTypeInfo = importChecked( | ||||||||||
9079 | Err, | ||||||||||
9080 | QualType(FromValue.getLValueBase().get<TypeInfoLValue>().getType(), | ||||||||||
9081 | 0)); | ||||||||||
9082 | QualType ImpType = | ||||||||||
9083 | importChecked(Err, FromValue.getLValueBase().getTypeInfoType()); | ||||||||||
9084 | if (Err) | ||||||||||
9085 | return std::move(Err); | ||||||||||
9086 | Base = APValue::LValueBase::getTypeInfo( | ||||||||||
9087 | TypeInfoLValue(ImpTypeInfo.getTypePtr()), ImpType); | ||||||||||
9088 | } | ||||||||||
9089 | } | ||||||||||
9090 | CharUnits Offset = FromValue.getLValueOffset(); | ||||||||||
9091 | unsigned PathLength = FromValue.getLValuePath().size(); | ||||||||||
9092 | Result.MakeLValue(); | ||||||||||
9093 | if (FromValue.hasLValuePath()) { | ||||||||||
9094 | MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit( | ||||||||||
9095 | Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(), | ||||||||||
9096 | FromValue.isNullPointer()); | ||||||||||
9097 | llvm::ArrayRef<APValue::LValuePathEntry> FromPath = | ||||||||||
9098 | FromValue.getLValuePath(); | ||||||||||
9099 | for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) { | ||||||||||
9100 | if (FromElemTy->isRecordType()) { | ||||||||||
9101 | const Decl *FromDecl = | ||||||||||
9102 | FromPath[LoopIdx].getAsBaseOrMember().getPointer(); | ||||||||||
9103 | const Decl *ImpDecl = importChecked(Err, FromDecl); | ||||||||||
9104 | if (Err) | ||||||||||
9105 | return std::move(Err); | ||||||||||
9106 | if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl)) | ||||||||||
9107 | FromElemTy = Importer.FromContext.getRecordType(RD); | ||||||||||
9108 | else | ||||||||||
9109 | FromElemTy = cast<ValueDecl>(FromDecl)->getType(); | ||||||||||
9110 | ToPath[LoopIdx] = APValue::LValuePathEntry(APValue::BaseOrMemberType( | ||||||||||
9111 | ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt())); | ||||||||||
9112 | } else { | ||||||||||
9113 | FromElemTy = | ||||||||||
9114 | Importer.FromContext.getAsArrayType(FromElemTy)->getElementType(); | ||||||||||
9115 | ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex( | ||||||||||
9116 | FromPath[LoopIdx].getAsArrayIndex()); | ||||||||||
9117 | } | ||||||||||
9118 | } | ||||||||||
9119 | } else | ||||||||||
9120 | Result.setLValue(Base, Offset, APValue::NoLValuePath{}, | ||||||||||
9121 | FromValue.isNullPointer()); | ||||||||||
9122 | } | ||||||||||
9123 | if (Err) | ||||||||||
9124 | return std::move(Err); | ||||||||||
9125 | return Result; | ||||||||||
9126 | } | ||||||||||
9127 | |||||||||||
9128 | Expected<DeclarationName> ASTImporter::HandleNameConflict(DeclarationName Name, | ||||||||||
9129 | DeclContext *DC, | ||||||||||
9130 | unsigned IDNS, | ||||||||||
9131 | NamedDecl **Decls, | ||||||||||
9132 | unsigned NumDecls) { | ||||||||||
9133 | if (ODRHandling == ODRHandlingType::Conservative) | ||||||||||
9134 | // Report error at any name conflict. | ||||||||||
9135 | return make_error<ImportError>(ImportError::NameConflict); | ||||||||||
9136 | else | ||||||||||
9137 | // Allow to create the new Decl with the same name. | ||||||||||
9138 | return Name; | ||||||||||
9139 | } | ||||||||||
9140 | |||||||||||
9141 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { | ||||||||||
9142 | if (LastDiagFromFrom) | ||||||||||
9143 | ToContext.getDiagnostics().notePriorDiagnosticFrom( | ||||||||||
9144 | FromContext.getDiagnostics()); | ||||||||||
9145 | LastDiagFromFrom = false; | ||||||||||
9146 | return ToContext.getDiagnostics().Report(Loc, DiagID); | ||||||||||
9147 | } | ||||||||||
9148 | |||||||||||
9149 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { | ||||||||||
9150 | if (!LastDiagFromFrom) | ||||||||||
9151 | FromContext.getDiagnostics().notePriorDiagnosticFrom( | ||||||||||
9152 | ToContext.getDiagnostics()); | ||||||||||
9153 | LastDiagFromFrom = true; | ||||||||||
9154 | return FromContext.getDiagnostics().Report(Loc, DiagID); | ||||||||||
9155 | } | ||||||||||
9156 | |||||||||||
9157 | void ASTImporter::CompleteDecl (Decl *D) { | ||||||||||
9158 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { | ||||||||||
9159 | if (!ID->getDefinition()) | ||||||||||
9160 | ID->startDefinition(); | ||||||||||
9161 | } | ||||||||||
9162 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { | ||||||||||
9163 | if (!PD->getDefinition()) | ||||||||||
9164 | PD->startDefinition(); | ||||||||||
9165 | } | ||||||||||
9166 | else if (auto *TD = dyn_cast<TagDecl>(D)) { | ||||||||||
9167 | if (!TD->getDefinition() && !TD->isBeingDefined()) { | ||||||||||
9168 | TD->startDefinition(); | ||||||||||
9169 | TD->setCompleteDefinition(true); | ||||||||||
9170 | } | ||||||||||
9171 | } | ||||||||||
9172 | else { | ||||||||||
9173 | assert(0 && "CompleteDecl called on a Decl that can't be completed")((0 && "CompleteDecl called on a Decl that can't be completed" ) ? static_cast<void> (0) : __assert_fail ("0 && \"CompleteDecl called on a Decl that can't be completed\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 9173, __PRETTY_FUNCTION__)); | ||||||||||
9174 | } | ||||||||||
9175 | } | ||||||||||
9176 | |||||||||||
9177 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { | ||||||||||
9178 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); | ||||||||||
9179 | assert((Pos == ImportedDecls.end() || Pos->second == To) &&(((Pos == ImportedDecls.end() || Pos->second == To) && "Try to import an already imported Decl") ? static_cast<void > (0) : __assert_fail ("(Pos == ImportedDecls.end() || Pos->second == To) && \"Try to import an already imported Decl\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 9180, __PRETTY_FUNCTION__)) | ||||||||||
9180 | "Try to import an already imported Decl")(((Pos == ImportedDecls.end() || Pos->second == To) && "Try to import an already imported Decl") ? static_cast<void > (0) : __assert_fail ("(Pos == ImportedDecls.end() || Pos->second == To) && \"Try to import an already imported Decl\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 9180, __PRETTY_FUNCTION__)); | ||||||||||
9181 | if (Pos != ImportedDecls.end()) | ||||||||||
9182 | return Pos->second; | ||||||||||
9183 | ImportedDecls[From] = To; | ||||||||||
9184 | // This mapping should be maintained only in this function. Therefore do not | ||||||||||
9185 | // check for additional consistency. | ||||||||||
9186 | ImportedFromDecls[To] = From; | ||||||||||
9187 | AddToLookupTable(To); | ||||||||||
9188 | return To; | ||||||||||
9189 | } | ||||||||||
9190 | |||||||||||
9191 | llvm::Optional<ImportError> | ||||||||||
9192 | ASTImporter::getImportDeclErrorIfAny(Decl *FromD) const { | ||||||||||
9193 | auto Pos = ImportDeclErrors.find(FromD); | ||||||||||
9194 | if (Pos != ImportDeclErrors.end()) | ||||||||||
9195 | return Pos->second; | ||||||||||
9196 | else | ||||||||||
9197 | return Optional<ImportError>(); | ||||||||||
9198 | } | ||||||||||
9199 | |||||||||||
9200 | void ASTImporter::setImportDeclError(Decl *From, ImportError Error) { | ||||||||||
9201 | auto InsertRes = ImportDeclErrors.insert({From, Error}); | ||||||||||
9202 | (void)InsertRes; | ||||||||||
9203 | // Either we set the error for the first time, or we already had set one and | ||||||||||
9204 | // now we want to set the same error. | ||||||||||
9205 | assert(InsertRes.second || InsertRes.first->second.Error == Error.Error)((InsertRes.second || InsertRes.first->second.Error == Error .Error) ? static_cast<void> (0) : __assert_fail ("InsertRes.second || InsertRes.first->second.Error == Error.Error" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/lib/AST/ASTImporter.cpp" , 9205, __PRETTY_FUNCTION__)); | ||||||||||
9206 | } | ||||||||||
9207 | |||||||||||
9208 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, | ||||||||||
9209 | bool Complain) { | ||||||||||
9210 | llvm::DenseMap<const Type *, const Type *>::iterator Pos = | ||||||||||
9211 | ImportedTypes.find(From.getTypePtr()); | ||||||||||
9212 | if (Pos != ImportedTypes.end()) { | ||||||||||
9213 | if (ExpectedType ToFromOrErr = Import(From)) { | ||||||||||
9214 | if (ToContext.hasSameType(*ToFromOrErr, To)) | ||||||||||
9215 | return true; | ||||||||||
9216 | } else { | ||||||||||
9217 | llvm::consumeError(ToFromOrErr.takeError()); | ||||||||||
9218 | } | ||||||||||
9219 | } | ||||||||||
9220 | |||||||||||
9221 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, | ||||||||||
9222 | getStructuralEquivalenceKind(*this), false, | ||||||||||
9223 | Complain); | ||||||||||
9224 | return Ctx.IsEquivalent(From, To); | ||||||||||
9225 | } |
1 | //===- llvm/Support/Error.h - Recoverable error handling --------*- 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 an API used to report recoverable errors. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #ifndef LLVM_SUPPORT_ERROR_H |
14 | #define LLVM_SUPPORT_ERROR_H |
15 | |
16 | #include "llvm-c/Error.h" |
17 | #include "llvm/ADT/STLExtras.h" |
18 | #include "llvm/ADT/SmallVector.h" |
19 | #include "llvm/ADT/StringExtras.h" |
20 | #include "llvm/ADT/Twine.h" |
21 | #include "llvm/Config/abi-breaking.h" |
22 | #include "llvm/Support/AlignOf.h" |
23 | #include "llvm/Support/Compiler.h" |
24 | #include "llvm/Support/Debug.h" |
25 | #include "llvm/Support/ErrorHandling.h" |
26 | #include "llvm/Support/ErrorOr.h" |
27 | #include "llvm/Support/Format.h" |
28 | #include "llvm/Support/raw_ostream.h" |
29 | #include <algorithm> |
30 | #include <cassert> |
31 | #include <cstdint> |
32 | #include <cstdlib> |
33 | #include <functional> |
34 | #include <memory> |
35 | #include <new> |
36 | #include <string> |
37 | #include <system_error> |
38 | #include <type_traits> |
39 | #include <utility> |
40 | #include <vector> |
41 | |
42 | namespace llvm { |
43 | |
44 | class ErrorSuccess; |
45 | |
46 | /// Base class for error info classes. Do not extend this directly: Extend |
47 | /// the ErrorInfo template subclass instead. |
48 | class ErrorInfoBase { |
49 | public: |
50 | virtual ~ErrorInfoBase() = default; |
51 | |
52 | /// Print an error message to an output stream. |
53 | virtual void log(raw_ostream &OS) const = 0; |
54 | |
55 | /// Return the error message as a string. |
56 | virtual std::string message() const { |
57 | std::string Msg; |
58 | raw_string_ostream OS(Msg); |
59 | log(OS); |
60 | return OS.str(); |
61 | } |
62 | |
63 | /// Convert this error to a std::error_code. |
64 | /// |
65 | /// This is a temporary crutch to enable interaction with code still |
66 | /// using std::error_code. It will be removed in the future. |
67 | virtual std::error_code convertToErrorCode() const = 0; |
68 | |
69 | // Returns the class ID for this type. |
70 | static const void *classID() { return &ID; } |
71 | |
72 | // Returns the class ID for the dynamic type of this ErrorInfoBase instance. |
73 | virtual const void *dynamicClassID() const = 0; |
74 | |
75 | // Check whether this instance is a subclass of the class identified by |
76 | // ClassID. |
77 | virtual bool isA(const void *const ClassID) const { |
78 | return ClassID == classID(); |
79 | } |
80 | |
81 | // Check whether this instance is a subclass of ErrorInfoT. |
82 | template <typename ErrorInfoT> bool isA() const { |
83 | return isA(ErrorInfoT::classID()); |
84 | } |
85 | |
86 | private: |
87 | virtual void anchor(); |
88 | |
89 | static char ID; |
90 | }; |
91 | |
92 | /// Lightweight error class with error context and mandatory checking. |
93 | /// |
94 | /// Instances of this class wrap a ErrorInfoBase pointer. Failure states |
95 | /// are represented by setting the pointer to a ErrorInfoBase subclass |
96 | /// instance containing information describing the failure. Success is |
97 | /// represented by a null pointer value. |
98 | /// |
99 | /// Instances of Error also contains a 'Checked' flag, which must be set |
100 | /// before the destructor is called, otherwise the destructor will trigger a |
101 | /// runtime error. This enforces at runtime the requirement that all Error |
102 | /// instances be checked or returned to the caller. |
103 | /// |
104 | /// There are two ways to set the checked flag, depending on what state the |
105 | /// Error instance is in. For Error instances indicating success, it |
106 | /// is sufficient to invoke the boolean conversion operator. E.g.: |
107 | /// |
108 | /// @code{.cpp} |
109 | /// Error foo(<...>); |
110 | /// |
111 | /// if (auto E = foo(<...>)) |
112 | /// return E; // <- Return E if it is in the error state. |
113 | /// // We have verified that E was in the success state. It can now be safely |
114 | /// // destroyed. |
115 | /// @endcode |
116 | /// |
117 | /// A success value *can not* be dropped. For example, just calling 'foo(<...>)' |
118 | /// without testing the return value will raise a runtime error, even if foo |
119 | /// returns success. |
120 | /// |
121 | /// For Error instances representing failure, you must use either the |
122 | /// handleErrors or handleAllErrors function with a typed handler. E.g.: |
123 | /// |
124 | /// @code{.cpp} |
125 | /// class MyErrorInfo : public ErrorInfo<MyErrorInfo> { |
126 | /// // Custom error info. |
127 | /// }; |
128 | /// |
129 | /// Error foo(<...>) { return make_error<MyErrorInfo>(...); } |
130 | /// |
131 | /// auto E = foo(<...>); // <- foo returns failure with MyErrorInfo. |
132 | /// auto NewE = |
133 | /// handleErrors(E, |
134 | /// [](const MyErrorInfo &M) { |
135 | /// // Deal with the error. |
136 | /// }, |
137 | /// [](std::unique_ptr<OtherError> M) -> Error { |
138 | /// if (canHandle(*M)) { |
139 | /// // handle error. |
140 | /// return Error::success(); |
141 | /// } |
142 | /// // Couldn't handle this error instance. Pass it up the stack. |
143 | /// return Error(std::move(M)); |
144 | /// ); |
145 | /// // Note - we must check or return NewE in case any of the handlers |
146 | /// // returned a new error. |
147 | /// @endcode |
148 | /// |
149 | /// The handleAllErrors function is identical to handleErrors, except |
150 | /// that it has a void return type, and requires all errors to be handled and |
151 | /// no new errors be returned. It prevents errors (assuming they can all be |
152 | /// handled) from having to be bubbled all the way to the top-level. |
153 | /// |
154 | /// *All* Error instances must be checked before destruction, even if |
155 | /// they're moved-assigned or constructed from Success values that have already |
156 | /// been checked. This enforces checking through all levels of the call stack. |
157 | class LLVM_NODISCARD[[clang::warn_unused_result]] Error { |
158 | // ErrorList needs to be able to yank ErrorInfoBase pointers out of Errors |
159 | // to add to the error list. It can't rely on handleErrors for this, since |
160 | // handleErrors does not support ErrorList handlers. |
161 | friend class ErrorList; |
162 | |
163 | // handleErrors needs to be able to set the Checked flag. |
164 | template <typename... HandlerTs> |
165 | friend Error handleErrors(Error E, HandlerTs &&... Handlers); |
166 | |
167 | // Expected<T> needs to be able to steal the payload when constructed from an |
168 | // error. |
169 | template <typename T> friend class Expected; |
170 | |
171 | // wrap needs to be able to steal the payload. |
172 | friend LLVMErrorRef wrap(Error); |
173 | |
174 | protected: |
175 | /// Create a success value. Prefer using 'Error::success()' for readability |
176 | Error() { |
177 | setPtr(nullptr); |
178 | setChecked(false); |
179 | } |
180 | |
181 | public: |
182 | /// Create a success value. |
183 | static ErrorSuccess success(); |
184 | |
185 | // Errors are not copy-constructable. |
186 | Error(const Error &Other) = delete; |
187 | |
188 | /// Move-construct an error value. The newly constructed error is considered |
189 | /// unchecked, even if the source error had been checked. The original error |
190 | /// becomes a checked Success value, regardless of its original state. |
191 | Error(Error &&Other) { |
192 | setChecked(true); |
193 | *this = std::move(Other); |
194 | } |
195 | |
196 | /// Create an error value. Prefer using the 'make_error' function, but |
197 | /// this constructor can be useful when "re-throwing" errors from handlers. |
198 | Error(std::unique_ptr<ErrorInfoBase> Payload) { |
199 | setPtr(Payload.release()); |
200 | setChecked(false); |
201 | } |
202 | |
203 | // Errors are not copy-assignable. |
204 | Error &operator=(const Error &Other) = delete; |
205 | |
206 | /// Move-assign an error value. The current error must represent success, you |
207 | /// you cannot overwrite an unhandled error. The current error is then |
208 | /// considered unchecked. The source error becomes a checked success value, |
209 | /// regardless of its original state. |
210 | Error &operator=(Error &&Other) { |
211 | // Don't allow overwriting of unchecked values. |
212 | assertIsChecked(); |
213 | setPtr(Other.getPtr()); |
214 | |
215 | // This Error is unchecked, even if the source error was checked. |
216 | setChecked(false); |
217 | |
218 | // Null out Other's payload and set its checked bit. |
219 | Other.setPtr(nullptr); |
220 | Other.setChecked(true); |
221 | |
222 | return *this; |
223 | } |
224 | |
225 | /// Destroy a Error. Fails with a call to abort() if the error is |
226 | /// unchecked. |
227 | ~Error() { |
228 | assertIsChecked(); |
229 | delete getPtr(); |
230 | } |
231 | |
232 | /// Bool conversion. Returns true if this Error is in a failure state, |
233 | /// and false if it is in an accept state. If the error is in a Success state |
234 | /// it will be considered checked. |
235 | explicit operator bool() { |
236 | setChecked(getPtr() == nullptr); |
237 | return getPtr() != nullptr; |
238 | } |
239 | |
240 | /// Check whether one error is a subclass of another. |
241 | template <typename ErrT> bool isA() const { |
242 | return getPtr() && getPtr()->isA(ErrT::classID()); |
243 | } |
244 | |
245 | /// Returns the dynamic class id of this error, or null if this is a success |
246 | /// value. |
247 | const void* dynamicClassID() const { |
248 | if (!getPtr()) |
249 | return nullptr; |
250 | return getPtr()->dynamicClassID(); |
251 | } |
252 | |
253 | private: |
254 | #if LLVM_ENABLE_ABI_BREAKING_CHECKS1 |
255 | // assertIsChecked() happens very frequently, but under normal circumstances |
256 | // is supposed to be a no-op. So we want it to be inlined, but having a bunch |
257 | // of debug prints can cause the function to be too large for inlining. So |
258 | // it's important that we define this function out of line so that it can't be |
259 | // inlined. |
260 | LLVM_ATTRIBUTE_NORETURN__attribute__((noreturn)) |
261 | void fatalUncheckedError() const; |
262 | #endif |
263 | |
264 | void assertIsChecked() { |
265 | #if LLVM_ENABLE_ABI_BREAKING_CHECKS1 |
266 | if (LLVM_UNLIKELY(!getChecked() || getPtr())__builtin_expect((bool)(!getChecked() || getPtr()), false)) |
267 | fatalUncheckedError(); |
268 | #endif |
269 | } |
270 | |
271 | ErrorInfoBase *getPtr() const { |
272 | #if LLVM_ENABLE_ABI_BREAKING_CHECKS1 |
273 | return reinterpret_cast<ErrorInfoBase*>( |
274 | reinterpret_cast<uintptr_t>(Payload) & |
275 | ~static_cast<uintptr_t>(0x1)); |
276 | #else |
277 | return Payload; |
278 | #endif |
279 | } |
280 | |
281 | void setPtr(ErrorInfoBase *EI) { |
282 | #if LLVM_ENABLE_ABI_BREAKING_CHECKS1 |
283 | Payload = reinterpret_cast<ErrorInfoBase*>( |
284 | (reinterpret_cast<uintptr_t>(EI) & |
285 | ~static_cast<uintptr_t>(0x1)) | |
286 | (reinterpret_cast<uintptr_t>(Payload) & 0x1)); |
287 | #else |
288 | Payload = EI; |
289 | #endif |
290 | } |
291 | |
292 | bool getChecked() const { |
293 | #if LLVM_ENABLE_ABI_BREAKING_CHECKS1 |
294 | return (reinterpret_cast<uintptr_t>(Payload) & 0x1) == 0; |
295 | #else |
296 | return true; |
297 | #endif |
298 | } |
299 | |
300 | void setChecked(bool V) { |
301 | #if LLVM_ENABLE_ABI_BREAKING_CHECKS1 |
302 | Payload = reinterpret_cast<ErrorInfoBase*>( |
303 | (reinterpret_cast<uintptr_t>(Payload) & |
304 | ~static_cast<uintptr_t>(0x1)) | |
305 | (V ? 0 : 1)); |
306 | #endif |
307 | } |
308 | |
309 | std::unique_ptr<ErrorInfoBase> takePayload() { |
310 | std::unique_ptr<ErrorInfoBase> Tmp(getPtr()); |
311 | setPtr(nullptr); |
312 | setChecked(true); |
313 | return Tmp; |
314 | } |
315 | |
316 | friend raw_ostream &operator<<(raw_ostream &OS, const Error &E) { |
317 | if (auto P = E.getPtr()) |
318 | P->log(OS); |
319 | else |
320 | OS << "success"; |
321 | return OS; |
322 | } |
323 | |
324 | ErrorInfoBase *Payload = nullptr; |
325 | }; |
326 | |
327 | /// Subclass of Error for the sole purpose of identifying the success path in |
328 | /// the type system. This allows to catch invalid conversion to Expected<T> at |
329 | /// compile time. |
330 | class ErrorSuccess final : public Error {}; |
331 | |
332 | inline ErrorSuccess Error::success() { return ErrorSuccess(); } |
333 | |
334 | /// Make a Error instance representing failure using the given error info |
335 | /// type. |
336 | template <typename ErrT, typename... ArgTs> Error make_error(ArgTs &&... Args) { |
337 | return Error(std::make_unique<ErrT>(std::forward<ArgTs>(Args)...)); |
338 | } |
339 | |
340 | /// Base class for user error types. Users should declare their error types |
341 | /// like: |
342 | /// |
343 | /// class MyError : public ErrorInfo<MyError> { |
344 | /// .... |
345 | /// }; |
346 | /// |
347 | /// This class provides an implementation of the ErrorInfoBase::kind |
348 | /// method, which is used by the Error RTTI system. |
349 | template <typename ThisErrT, typename ParentErrT = ErrorInfoBase> |
350 | class ErrorInfo : public ParentErrT { |
351 | public: |
352 | using ParentErrT::ParentErrT; // inherit constructors |
353 | |
354 | static const void *classID() { return &ThisErrT::ID; } |
355 | |
356 | const void *dynamicClassID() const override { return &ThisErrT::ID; } |
357 | |
358 | bool isA(const void *const ClassID) const override { |
359 | return ClassID == classID() || ParentErrT::isA(ClassID); |
360 | } |
361 | }; |
362 | |
363 | /// Special ErrorInfo subclass representing a list of ErrorInfos. |
364 | /// Instances of this class are constructed by joinError. |
365 | class ErrorList final : public ErrorInfo<ErrorList> { |
366 | // handleErrors needs to be able to iterate the payload list of an |
367 | // ErrorList. |
368 | template <typename... HandlerTs> |
369 | friend Error handleErrors(Error E, HandlerTs &&... Handlers); |
370 | |
371 | // joinErrors is implemented in terms of join. |
372 | friend Error joinErrors(Error, Error); |
373 | |
374 | public: |
375 | void log(raw_ostream &OS) const override { |
376 | OS << "Multiple errors:\n"; |
377 | for (auto &ErrPayload : Payloads) { |
378 | ErrPayload->log(OS); |
379 | OS << "\n"; |
380 | } |
381 | } |
382 | |
383 | std::error_code convertToErrorCode() const override; |
384 | |
385 | // Used by ErrorInfo::classID. |
386 | static char ID; |
387 | |
388 | private: |
389 | ErrorList(std::unique_ptr<ErrorInfoBase> Payload1, |
390 | std::unique_ptr<ErrorInfoBase> Payload2) { |
391 | assert(!Payload1->isA<ErrorList>() && !Payload2->isA<ErrorList>() &&((!Payload1->isA<ErrorList>() && !Payload2-> isA<ErrorList>() && "ErrorList constructor payloads should be singleton errors" ) ? static_cast<void> (0) : __assert_fail ("!Payload1->isA<ErrorList>() && !Payload2->isA<ErrorList>() && \"ErrorList constructor payloads should be singleton errors\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/Support/Error.h" , 392, __PRETTY_FUNCTION__)) |
392 | "ErrorList constructor payloads should be singleton errors")((!Payload1->isA<ErrorList>() && !Payload2-> isA<ErrorList>() && "ErrorList constructor payloads should be singleton errors" ) ? static_cast<void> (0) : __assert_fail ("!Payload1->isA<ErrorList>() && !Payload2->isA<ErrorList>() && \"ErrorList constructor payloads should be singleton errors\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/Support/Error.h" , 392, __PRETTY_FUNCTION__)); |
393 | Payloads.push_back(std::move(Payload1)); |
394 | Payloads.push_back(std::move(Payload2)); |
395 | } |
396 | |
397 | static Error join(Error E1, Error E2) { |
398 | if (!E1) |
399 | return E2; |
400 | if (!E2) |
401 | return E1; |
402 | if (E1.isA<ErrorList>()) { |
403 | auto &E1List = static_cast<ErrorList &>(*E1.getPtr()); |
404 | if (E2.isA<ErrorList>()) { |
405 | auto E2Payload = E2.takePayload(); |
406 | auto &E2List = static_cast<ErrorList &>(*E2Payload); |
407 | for (auto &Payload : E2List.Payloads) |
408 | E1List.Payloads.push_back(std::move(Payload)); |
409 | } else |
410 | E1List.Payloads.push_back(E2.takePayload()); |
411 | |
412 | return E1; |
413 | } |
414 | if (E2.isA<ErrorList>()) { |
415 | auto &E2List = static_cast<ErrorList &>(*E2.getPtr()); |
416 | E2List.Payloads.insert(E2List.Payloads.begin(), E1.takePayload()); |
417 | return E2; |
418 | } |
419 | return Error(std::unique_ptr<ErrorList>( |
420 | new ErrorList(E1.takePayload(), E2.takePayload()))); |
421 | } |
422 | |
423 | std::vector<std::unique_ptr<ErrorInfoBase>> Payloads; |
424 | }; |
425 | |
426 | /// Concatenate errors. The resulting Error is unchecked, and contains the |
427 | /// ErrorInfo(s), if any, contained in E1, followed by the |
428 | /// ErrorInfo(s), if any, contained in E2. |
429 | inline Error joinErrors(Error E1, Error E2) { |
430 | return ErrorList::join(std::move(E1), std::move(E2)); |
431 | } |
432 | |
433 | /// Tagged union holding either a T or a Error. |
434 | /// |
435 | /// This class parallels ErrorOr, but replaces error_code with Error. Since |
436 | /// Error cannot be copied, this class replaces getError() with |
437 | /// takeError(). It also adds an bool errorIsA<ErrT>() method for testing the |
438 | /// error class type. |
439 | template <class T> class LLVM_NODISCARD[[clang::warn_unused_result]] Expected { |
440 | template <class T1> friend class ExpectedAsOutParameter; |
441 | template <class OtherT> friend class Expected; |
442 | |
443 | static constexpr bool isRef = std::is_reference<T>::value; |
444 | |
445 | using wrap = std::reference_wrapper<std::remove_reference_t<T>>; |
446 | |
447 | using error_type = std::unique_ptr<ErrorInfoBase>; |
448 | |
449 | public: |
450 | using storage_type = std::conditional_t<isRef, wrap, T>; |
451 | using value_type = T; |
452 | |
453 | private: |
454 | using reference = std::remove_reference_t<T> &; |
455 | using const_reference = const std::remove_reference_t<T> &; |
456 | using pointer = std::remove_reference_t<T> *; |
457 | using const_pointer = const std::remove_reference_t<T> *; |
458 | |
459 | public: |
460 | /// Create an Expected<T> error value from the given Error. |
461 | Expected(Error Err) |
462 | : HasError(true) |
463 | #if LLVM_ENABLE_ABI_BREAKING_CHECKS1 |
464 | // Expected is unchecked upon construction in Debug builds. |
465 | , Unchecked(true) |
466 | #endif |
467 | { |
468 | assert(Err && "Cannot create Expected<T> from Error success value.")((Err && "Cannot create Expected<T> from Error success value." ) ? static_cast<void> (0) : __assert_fail ("Err && \"Cannot create Expected<T> from Error success value.\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/Support/Error.h" , 468, __PRETTY_FUNCTION__)); |
469 | new (getErrorStorage()) error_type(Err.takePayload()); |
470 | } |
471 | |
472 | /// Forbid to convert from Error::success() implicitly, this avoids having |
473 | /// Expected<T> foo() { return Error::success(); } which compiles otherwise |
474 | /// but triggers the assertion above. |
475 | Expected(ErrorSuccess) = delete; |
476 | |
477 | /// Create an Expected<T> success value from the given OtherT value, which |
478 | /// must be convertible to T. |
479 | template <typename OtherT> |
480 | Expected(OtherT &&Val, |
481 | std::enable_if_t<std::is_convertible<OtherT, T>::value> * = nullptr) |
482 | : HasError(false) |
483 | #if LLVM_ENABLE_ABI_BREAKING_CHECKS1 |
484 | // Expected is unchecked upon construction in Debug builds. |
485 | , |
486 | Unchecked(true) |
487 | #endif |
488 | { |
489 | new (getStorage()) storage_type(std::forward<OtherT>(Val)); |
490 | } |
491 | |
492 | /// Move construct an Expected<T> value. |
493 | Expected(Expected &&Other) { moveConstruct(std::move(Other)); } |
494 | |
495 | /// Move construct an Expected<T> value from an Expected<OtherT>, where OtherT |
496 | /// must be convertible to T. |
497 | template <class OtherT> |
498 | Expected( |
499 | Expected<OtherT> &&Other, |
500 | std::enable_if_t<std::is_convertible<OtherT, T>::value> * = nullptr) { |
501 | moveConstruct(std::move(Other)); |
502 | } |
503 | |
504 | /// Move construct an Expected<T> value from an Expected<OtherT>, where OtherT |
505 | /// isn't convertible to T. |
506 | template <class OtherT> |
507 | explicit Expected( |
508 | Expected<OtherT> &&Other, |
509 | std::enable_if_t<!std::is_convertible<OtherT, T>::value> * = nullptr) { |
510 | moveConstruct(std::move(Other)); |
511 | } |
512 | |
513 | /// Move-assign from another Expected<T>. |
514 | Expected &operator=(Expected &&Other) { |
515 | moveAssign(std::move(Other)); |
516 | return *this; |
517 | } |
518 | |
519 | /// Destroy an Expected<T>. |
520 | ~Expected() { |
521 | assertIsChecked(); |
522 | if (!HasError) |
523 | getStorage()->~storage_type(); |
524 | else |
525 | getErrorStorage()->~error_type(); |
526 | } |
527 | |
528 | /// Return false if there is an error. |
529 | explicit operator bool() { |
530 | #if LLVM_ENABLE_ABI_BREAKING_CHECKS1 |
531 | Unchecked = HasError; |
532 | #endif |
533 | return !HasError; |
534 | } |
535 | |
536 | /// Returns a reference to the stored T value. |
537 | reference get() { |
538 | assertIsChecked(); |
539 | return *getStorage(); |
540 | } |
541 | |
542 | /// Returns a const reference to the stored T value. |
543 | const_reference get() const { |
544 | assertIsChecked(); |
545 | return const_cast<Expected<T> *>(this)->get(); |
546 | } |
547 | |
548 | /// Check that this Expected<T> is an error of type ErrT. |
549 | template <typename ErrT> bool errorIsA() const { |
550 | return HasError && (*getErrorStorage())->template isA<ErrT>(); |
551 | } |
552 | |
553 | /// Take ownership of the stored error. |
554 | /// After calling this the Expected<T> is in an indeterminate state that can |
555 | /// only be safely destructed. No further calls (beside the destructor) should |
556 | /// be made on the Expected<T> value. |
557 | Error takeError() { |
558 | #if LLVM_ENABLE_ABI_BREAKING_CHECKS1 |
559 | Unchecked = false; |
560 | #endif |
561 | return HasError ? Error(std::move(*getErrorStorage())) : Error::success(); |
562 | } |
563 | |
564 | /// Returns a pointer to the stored T value. |
565 | pointer operator->() { |
566 | assertIsChecked(); |
567 | return toPointer(getStorage()); |
568 | } |
569 | |
570 | /// Returns a const pointer to the stored T value. |
571 | const_pointer operator->() const { |
572 | assertIsChecked(); |
573 | return toPointer(getStorage()); |
574 | } |
575 | |
576 | /// Returns a reference to the stored T value. |
577 | reference operator*() { |
578 | assertIsChecked(); |
579 | return *getStorage(); |
580 | } |
581 | |
582 | /// Returns a const reference to the stored T value. |
583 | const_reference operator*() const { |
584 | assertIsChecked(); |
585 | return *getStorage(); |
586 | } |
587 | |
588 | private: |
589 | template <class T1> |
590 | static bool compareThisIfSameType(const T1 &a, const T1 &b) { |
591 | return &a == &b; |
592 | } |
593 | |
594 | template <class T1, class T2> |
595 | static bool compareThisIfSameType(const T1 &a, const T2 &b) { |
596 | return false; |
597 | } |
598 | |
599 | template <class OtherT> void moveConstruct(Expected<OtherT> &&Other) { |
600 | HasError = Other.HasError; |
601 | #if LLVM_ENABLE_ABI_BREAKING_CHECKS1 |
602 | Unchecked = true; |
603 | Other.Unchecked = false; |
604 | #endif |
605 | |
606 | if (!HasError) |
607 | new (getStorage()) storage_type(std::move(*Other.getStorage())); |
608 | else |
609 | new (getErrorStorage()) error_type(std::move(*Other.getErrorStorage())); |
610 | } |
611 | |
612 | template <class OtherT> void moveAssign(Expected<OtherT> &&Other) { |
613 | assertIsChecked(); |
614 | |
615 | if (compareThisIfSameType(*this, Other)) |
616 | return; |
617 | |
618 | this->~Expected(); |
619 | new (this) Expected(std::move(Other)); |
620 | } |
621 | |
622 | pointer toPointer(pointer Val) { return Val; } |
623 | |
624 | const_pointer toPointer(const_pointer Val) const { return Val; } |
625 | |
626 | pointer toPointer(wrap *Val) { return &Val->get(); } |
627 | |
628 | const_pointer toPointer(const wrap *Val) const { return &Val->get(); } |
629 | |
630 | storage_type *getStorage() { |
631 | assert(!HasError && "Cannot get value when an error exists!")((!HasError && "Cannot get value when an error exists!" ) ? static_cast<void> (0) : __assert_fail ("!HasError && \"Cannot get value when an error exists!\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/Support/Error.h" , 631, __PRETTY_FUNCTION__)); |
632 | return reinterpret_cast<storage_type *>(TStorage.buffer); |
633 | } |
634 | |
635 | const storage_type *getStorage() const { |
636 | assert(!HasError && "Cannot get value when an error exists!")((!HasError && "Cannot get value when an error exists!" ) ? static_cast<void> (0) : __assert_fail ("!HasError && \"Cannot get value when an error exists!\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/Support/Error.h" , 636, __PRETTY_FUNCTION__)); |
637 | return reinterpret_cast<const storage_type *>(TStorage.buffer); |
638 | } |
639 | |
640 | error_type *getErrorStorage() { |
641 | assert(HasError && "Cannot get error when a value exists!")((HasError && "Cannot get error when a value exists!" ) ? static_cast<void> (0) : __assert_fail ("HasError && \"Cannot get error when a value exists!\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/Support/Error.h" , 641, __PRETTY_FUNCTION__)); |
642 | return reinterpret_cast<error_type *>(ErrorStorage.buffer); |
643 | } |
644 | |
645 | const error_type *getErrorStorage() const { |
646 | assert(HasError && "Cannot get error when a value exists!")((HasError && "Cannot get error when a value exists!" ) ? static_cast<void> (0) : __assert_fail ("HasError && \"Cannot get error when a value exists!\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/Support/Error.h" , 646, __PRETTY_FUNCTION__)); |
647 | return reinterpret_cast<const error_type *>(ErrorStorage.buffer); |
648 | } |
649 | |
650 | // Used by ExpectedAsOutParameter to reset the checked flag. |
651 | void setUnchecked() { |
652 | #if LLVM_ENABLE_ABI_BREAKING_CHECKS1 |
653 | Unchecked = true; |
654 | #endif |
655 | } |
656 | |
657 | #if LLVM_ENABLE_ABI_BREAKING_CHECKS1 |
658 | LLVM_ATTRIBUTE_NORETURN__attribute__((noreturn)) |
659 | LLVM_ATTRIBUTE_NOINLINE__attribute__((noinline)) |
660 | void fatalUncheckedExpected() const { |
661 | dbgs() << "Expected<T> must be checked before access or destruction.\n"; |
662 | if (HasError) { |
663 | dbgs() << "Unchecked Expected<T> contained error:\n"; |
664 | (*getErrorStorage())->log(dbgs()); |
665 | } else |
666 | dbgs() << "Expected<T> value was in success state. (Note: Expected<T> " |
667 | "values in success mode must still be checked prior to being " |
668 | "destroyed).\n"; |
669 | abort(); |
670 | } |
671 | #endif |
672 | |
673 | void assertIsChecked() { |
674 | #if LLVM_ENABLE_ABI_BREAKING_CHECKS1 |
675 | if (LLVM_UNLIKELY(Unchecked)__builtin_expect((bool)(Unchecked), false)) |
676 | fatalUncheckedExpected(); |
677 | #endif |
678 | } |
679 | |
680 | union { |
681 | AlignedCharArrayUnion<storage_type> TStorage; |
682 | AlignedCharArrayUnion<error_type> ErrorStorage; |
683 | }; |
684 | bool HasError : 1; |
685 | #if LLVM_ENABLE_ABI_BREAKING_CHECKS1 |
686 | bool Unchecked : 1; |
687 | #endif |
688 | }; |
689 | |
690 | /// Report a serious error, calling any installed error handler. See |
691 | /// ErrorHandling.h. |
692 | LLVM_ATTRIBUTE_NORETURN__attribute__((noreturn)) void report_fatal_error(Error Err, |
693 | bool gen_crash_diag = true); |
694 | |
695 | /// Report a fatal error if Err is a failure value. |
696 | /// |
697 | /// This function can be used to wrap calls to fallible functions ONLY when it |
698 | /// is known that the Error will always be a success value. E.g. |
699 | /// |
700 | /// @code{.cpp} |
701 | /// // foo only attempts the fallible operation if DoFallibleOperation is |
702 | /// // true. If DoFallibleOperation is false then foo always returns |
703 | /// // Error::success(). |
704 | /// Error foo(bool DoFallibleOperation); |
705 | /// |
706 | /// cantFail(foo(false)); |
707 | /// @endcode |
708 | inline void cantFail(Error Err, const char *Msg = nullptr) { |
709 | if (Err) { |
710 | if (!Msg) |
711 | Msg = "Failure value returned from cantFail wrapped call"; |
712 | #ifndef NDEBUG |
713 | std::string Str; |
714 | raw_string_ostream OS(Str); |
715 | OS << Msg << "\n" << Err; |
716 | Msg = OS.str().c_str(); |
717 | #endif |
718 | llvm_unreachable(Msg)::llvm::llvm_unreachable_internal(Msg, "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/Support/Error.h" , 718); |
719 | } |
720 | } |
721 | |
722 | /// Report a fatal error if ValOrErr is a failure value, otherwise unwraps and |
723 | /// returns the contained value. |
724 | /// |
725 | /// This function can be used to wrap calls to fallible functions ONLY when it |
726 | /// is known that the Error will always be a success value. E.g. |
727 | /// |
728 | /// @code{.cpp} |
729 | /// // foo only attempts the fallible operation if DoFallibleOperation is |
730 | /// // true. If DoFallibleOperation is false then foo always returns an int. |
731 | /// Expected<int> foo(bool DoFallibleOperation); |
732 | /// |
733 | /// int X = cantFail(foo(false)); |
734 | /// @endcode |
735 | template <typename T> |
736 | T cantFail(Expected<T> ValOrErr, const char *Msg = nullptr) { |
737 | if (ValOrErr) |
738 | return std::move(*ValOrErr); |
739 | else { |
740 | if (!Msg) |
741 | Msg = "Failure value returned from cantFail wrapped call"; |
742 | #ifndef NDEBUG |
743 | std::string Str; |
744 | raw_string_ostream OS(Str); |
745 | auto E = ValOrErr.takeError(); |
746 | OS << Msg << "\n" << E; |
747 | Msg = OS.str().c_str(); |
748 | #endif |
749 | llvm_unreachable(Msg)::llvm::llvm_unreachable_internal(Msg, "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/Support/Error.h" , 749); |
750 | } |
751 | } |
752 | |
753 | /// Report a fatal error if ValOrErr is a failure value, otherwise unwraps and |
754 | /// returns the contained reference. |
755 | /// |
756 | /// This function can be used to wrap calls to fallible functions ONLY when it |
757 | /// is known that the Error will always be a success value. E.g. |
758 | /// |
759 | /// @code{.cpp} |
760 | /// // foo only attempts the fallible operation if DoFallibleOperation is |
761 | /// // true. If DoFallibleOperation is false then foo always returns a Bar&. |
762 | /// Expected<Bar&> foo(bool DoFallibleOperation); |
763 | /// |
764 | /// Bar &X = cantFail(foo(false)); |
765 | /// @endcode |
766 | template <typename T> |
767 | T& cantFail(Expected<T&> ValOrErr, const char *Msg = nullptr) { |
768 | if (ValOrErr) |
769 | return *ValOrErr; |
770 | else { |
771 | if (!Msg) |
772 | Msg = "Failure value returned from cantFail wrapped call"; |
773 | #ifndef NDEBUG |
774 | std::string Str; |
775 | raw_string_ostream OS(Str); |
776 | auto E = ValOrErr.takeError(); |
777 | OS << Msg << "\n" << E; |
778 | Msg = OS.str().c_str(); |
779 | #endif |
780 | llvm_unreachable(Msg)::llvm::llvm_unreachable_internal(Msg, "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/Support/Error.h" , 780); |
781 | } |
782 | } |
783 | |
784 | /// Helper for testing applicability of, and applying, handlers for |
785 | /// ErrorInfo types. |
786 | template <typename HandlerT> |
787 | class ErrorHandlerTraits |
788 | : public ErrorHandlerTraits<decltype( |
789 | &std::remove_reference<HandlerT>::type::operator())> {}; |
790 | |
791 | // Specialization functions of the form 'Error (const ErrT&)'. |
792 | template <typename ErrT> class ErrorHandlerTraits<Error (&)(ErrT &)> { |
793 | public: |
794 | static bool appliesTo(const ErrorInfoBase &E) { |
795 | return E.template isA<ErrT>(); |
796 | } |
797 | |
798 | template <typename HandlerT> |
799 | static Error apply(HandlerT &&H, std::unique_ptr<ErrorInfoBase> E) { |
800 | assert(appliesTo(*E) && "Applying incorrect handler")((appliesTo(*E) && "Applying incorrect handler") ? static_cast <void> (0) : __assert_fail ("appliesTo(*E) && \"Applying incorrect handler\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/Support/Error.h" , 800, __PRETTY_FUNCTION__)); |
801 | return H(static_cast<ErrT &>(*E)); |
802 | } |
803 | }; |
804 | |
805 | // Specialization functions of the form 'void (const ErrT&)'. |
806 | template <typename ErrT> class ErrorHandlerTraits<void (&)(ErrT &)> { |
807 | public: |
808 | static bool appliesTo(const ErrorInfoBase &E) { |
809 | return E.template isA<ErrT>(); |
810 | } |
811 | |
812 | template <typename HandlerT> |
813 | static Error apply(HandlerT &&H, std::unique_ptr<ErrorInfoBase> E) { |
814 | assert(appliesTo(*E) && "Applying incorrect handler")((appliesTo(*E) && "Applying incorrect handler") ? static_cast <void> (0) : __assert_fail ("appliesTo(*E) && \"Applying incorrect handler\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/Support/Error.h" , 814, __PRETTY_FUNCTION__)); |
815 | H(static_cast<ErrT &>(*E)); |
816 | return Error::success(); |
817 | } |
818 | }; |
819 | |
820 | /// Specialization for functions of the form 'Error (std::unique_ptr<ErrT>)'. |
821 | template <typename ErrT> |
822 | class ErrorHandlerTraits<Error (&)(std::unique_ptr<ErrT>)> { |
823 | public: |
824 | static bool appliesTo(const ErrorInfoBase &E) { |
825 | return E.template isA<ErrT>(); |
826 | } |
827 | |
828 | template <typename HandlerT> |
829 | static Error apply(HandlerT &&H, std::unique_ptr<ErrorInfoBase> E) { |
830 | assert(appliesTo(*E) && "Applying incorrect handler")((appliesTo(*E) && "Applying incorrect handler") ? static_cast <void> (0) : __assert_fail ("appliesTo(*E) && \"Applying incorrect handler\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/Support/Error.h" , 830, __PRETTY_FUNCTION__)); |
831 | std::unique_ptr<ErrT> SubE(static_cast<ErrT *>(E.release())); |
832 | return H(std::move(SubE)); |
833 | } |
834 | }; |
835 | |
836 | /// Specialization for functions of the form 'void (std::unique_ptr<ErrT>)'. |
837 | template <typename ErrT> |
838 | class ErrorHandlerTraits<void (&)(std::unique_ptr<ErrT>)> { |
839 | public: |
840 | static bool appliesTo(const ErrorInfoBase &E) { |
841 | return E.template isA<ErrT>(); |
842 | } |
843 | |
844 | template <typename HandlerT> |
845 | static Error apply(HandlerT &&H, std::unique_ptr<ErrorInfoBase> E) { |
846 | assert(appliesTo(*E) && "Applying incorrect handler")((appliesTo(*E) && "Applying incorrect handler") ? static_cast <void> (0) : __assert_fail ("appliesTo(*E) && \"Applying incorrect handler\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/Support/Error.h" , 846, __PRETTY_FUNCTION__)); |
847 | std::unique_ptr<ErrT> SubE(static_cast<ErrT *>(E.release())); |
848 | H(std::move(SubE)); |
849 | return Error::success(); |
850 | } |
851 | }; |
852 | |
853 | // Specialization for member functions of the form 'RetT (const ErrT&)'. |
854 | template <typename C, typename RetT, typename ErrT> |
855 | class ErrorHandlerTraits<RetT (C::*)(ErrT &)> |
856 | : public ErrorHandlerTraits<RetT (&)(ErrT &)> {}; |
857 | |
858 | // Specialization for member functions of the form 'RetT (const ErrT&) const'. |
859 | template <typename C, typename RetT, typename ErrT> |
860 | class ErrorHandlerTraits<RetT (C::*)(ErrT &) const> |
861 | : public ErrorHandlerTraits<RetT (&)(ErrT &)> {}; |
862 | |
863 | // Specialization for member functions of the form 'RetT (const ErrT&)'. |
864 | template <typename C, typename RetT, typename ErrT> |
865 | class ErrorHandlerTraits<RetT (C::*)(const ErrT &)> |
866 | : public ErrorHandlerTraits<RetT (&)(ErrT &)> {}; |
867 | |
868 | // Specialization for member functions of the form 'RetT (const ErrT&) const'. |
869 | template <typename C, typename RetT, typename ErrT> |
870 | class ErrorHandlerTraits<RetT (C::*)(const ErrT &) const> |
871 | : public ErrorHandlerTraits<RetT (&)(ErrT &)> {}; |
872 | |
873 | /// Specialization for member functions of the form |
874 | /// 'RetT (std::unique_ptr<ErrT>)'. |
875 | template <typename C, typename RetT, typename ErrT> |
876 | class ErrorHandlerTraits<RetT (C::*)(std::unique_ptr<ErrT>)> |
877 | : public ErrorHandlerTraits<RetT (&)(std::unique_ptr<ErrT>)> {}; |
878 | |
879 | /// Specialization for member functions of the form |
880 | /// 'RetT (std::unique_ptr<ErrT>) const'. |
881 | template <typename C, typename RetT, typename ErrT> |
882 | class ErrorHandlerTraits<RetT (C::*)(std::unique_ptr<ErrT>) const> |
883 | : public ErrorHandlerTraits<RetT (&)(std::unique_ptr<ErrT>)> {}; |
884 | |
885 | inline Error handleErrorImpl(std::unique_ptr<ErrorInfoBase> Payload) { |
886 | return Error(std::move(Payload)); |
887 | } |
888 | |
889 | template <typename HandlerT, typename... HandlerTs> |
890 | Error handleErrorImpl(std::unique_ptr<ErrorInfoBase> Payload, |
891 | HandlerT &&Handler, HandlerTs &&... Handlers) { |
892 | if (ErrorHandlerTraits<HandlerT>::appliesTo(*Payload)) |
893 | return ErrorHandlerTraits<HandlerT>::apply(std::forward<HandlerT>(Handler), |
894 | std::move(Payload)); |
895 | return handleErrorImpl(std::move(Payload), |
896 | std::forward<HandlerTs>(Handlers)...); |
897 | } |
898 | |
899 | /// Pass the ErrorInfo(s) contained in E to their respective handlers. Any |
900 | /// unhandled errors (or Errors returned by handlers) are re-concatenated and |
901 | /// returned. |
902 | /// Because this function returns an error, its result must also be checked |
903 | /// or returned. If you intend to handle all errors use handleAllErrors |
904 | /// (which returns void, and will abort() on unhandled errors) instead. |
905 | template <typename... HandlerTs> |
906 | Error handleErrors(Error E, HandlerTs &&... Hs) { |
907 | if (!E) |
908 | return Error::success(); |
909 | |
910 | std::unique_ptr<ErrorInfoBase> Payload = E.takePayload(); |
911 | |
912 | if (Payload->isA<ErrorList>()) { |
913 | ErrorList &List = static_cast<ErrorList &>(*Payload); |
914 | Error R; |
915 | for (auto &P : List.Payloads) |
916 | R = ErrorList::join( |
917 | std::move(R), |
918 | handleErrorImpl(std::move(P), std::forward<HandlerTs>(Hs)...)); |
919 | return R; |
920 | } |
921 | |
922 | return handleErrorImpl(std::move(Payload), std::forward<HandlerTs>(Hs)...); |
923 | } |
924 | |
925 | /// Behaves the same as handleErrors, except that by contract all errors |
926 | /// *must* be handled by the given handlers (i.e. there must be no remaining |
927 | /// errors after running the handlers, or llvm_unreachable is called). |
928 | template <typename... HandlerTs> |
929 | void handleAllErrors(Error E, HandlerTs &&... Handlers) { |
930 | cantFail(handleErrors(std::move(E), std::forward<HandlerTs>(Handlers)...)); |
931 | } |
932 | |
933 | /// Check that E is a non-error, then drop it. |
934 | /// If E is an error, llvm_unreachable will be called. |
935 | inline void handleAllErrors(Error E) { |
936 | cantFail(std::move(E)); |
937 | } |
938 | |
939 | /// Handle any errors (if present) in an Expected<T>, then try a recovery path. |
940 | /// |
941 | /// If the incoming value is a success value it is returned unmodified. If it |
942 | /// is a failure value then it the contained error is passed to handleErrors. |
943 | /// If handleErrors is able to handle the error then the RecoveryPath functor |
944 | /// is called to supply the final result. If handleErrors is not able to |
945 | /// handle all errors then the unhandled errors are returned. |
946 | /// |
947 | /// This utility enables the follow pattern: |
948 | /// |
949 | /// @code{.cpp} |
950 | /// enum FooStrategy { Aggressive, Conservative }; |
951 | /// Expected<Foo> foo(FooStrategy S); |
952 | /// |
953 | /// auto ResultOrErr = |
954 | /// handleExpected( |
955 | /// foo(Aggressive), |
956 | /// []() { return foo(Conservative); }, |
957 | /// [](AggressiveStrategyError&) { |
958 | /// // Implicitly conusme this - we'll recover by using a conservative |
959 | /// // strategy. |
960 | /// }); |
961 | /// |
962 | /// @endcode |
963 | template <typename T, typename RecoveryFtor, typename... HandlerTs> |
964 | Expected<T> handleExpected(Expected<T> ValOrErr, RecoveryFtor &&RecoveryPath, |
965 | HandlerTs &&... Handlers) { |
966 | if (ValOrErr) |
967 | return ValOrErr; |
968 | |
969 | if (auto Err = handleErrors(ValOrErr.takeError(), |
970 | std::forward<HandlerTs>(Handlers)...)) |
971 | return std::move(Err); |
972 | |
973 | return RecoveryPath(); |
974 | } |
975 | |
976 | /// Log all errors (if any) in E to OS. If there are any errors, ErrorBanner |
977 | /// will be printed before the first one is logged. A newline will be printed |
978 | /// after each error. |
979 | /// |
980 | /// This function is compatible with the helpers from Support/WithColor.h. You |
981 | /// can pass any of them as the OS. Please consider using them instead of |
982 | /// including 'error: ' in the ErrorBanner. |
983 | /// |
984 | /// This is useful in the base level of your program to allow clean termination |
985 | /// (allowing clean deallocation of resources, etc.), while reporting error |
986 | /// information to the user. |
987 | void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner = {}); |
988 | |
989 | /// Write all error messages (if any) in E to a string. The newline character |
990 | /// is used to separate error messages. |
991 | inline std::string toString(Error E) { |
992 | SmallVector<std::string, 2> Errors; |
993 | handleAllErrors(std::move(E), [&Errors](const ErrorInfoBase &EI) { |
994 | Errors.push_back(EI.message()); |
995 | }); |
996 | return join(Errors.begin(), Errors.end(), "\n"); |
997 | } |
998 | |
999 | /// Consume a Error without doing anything. This method should be used |
1000 | /// only where an error can be considered a reasonable and expected return |
1001 | /// value. |
1002 | /// |
1003 | /// Uses of this method are potentially indicative of design problems: If it's |
1004 | /// legitimate to do nothing while processing an "error", the error-producer |
1005 | /// might be more clearly refactored to return an Optional<T>. |
1006 | inline void consumeError(Error Err) { |
1007 | handleAllErrors(std::move(Err), [](const ErrorInfoBase &) {}); |
1008 | } |
1009 | |
1010 | /// Convert an Expected to an Optional without doing anything. This method |
1011 | /// should be used only where an error can be considered a reasonable and |
1012 | /// expected return value. |
1013 | /// |
1014 | /// Uses of this method are potentially indicative of problems: perhaps the |
1015 | /// error should be propagated further, or the error-producer should just |
1016 | /// return an Optional in the first place. |
1017 | template <typename T> Optional<T> expectedToOptional(Expected<T> &&E) { |
1018 | if (E) |
1019 | return std::move(*E); |
1020 | consumeError(E.takeError()); |
1021 | return None; |
1022 | } |
1023 | |
1024 | /// Helper for converting an Error to a bool. |
1025 | /// |
1026 | /// This method returns true if Err is in an error state, or false if it is |
1027 | /// in a success state. Puts Err in a checked state in both cases (unlike |
1028 | /// Error::operator bool(), which only does this for success states). |
1029 | inline bool errorToBool(Error Err) { |
1030 | bool IsError = static_cast<bool>(Err); |
1031 | if (IsError) |
1032 | consumeError(std::move(Err)); |
1033 | return IsError; |
1034 | } |
1035 | |
1036 | /// Helper for Errors used as out-parameters. |
1037 | /// |
1038 | /// This helper is for use with the Error-as-out-parameter idiom, where an error |
1039 | /// is passed to a function or method by reference, rather than being returned. |
1040 | /// In such cases it is helpful to set the checked bit on entry to the function |
1041 | /// so that the error can be written to (unchecked Errors abort on assignment) |
1042 | /// and clear the checked bit on exit so that clients cannot accidentally forget |
1043 | /// to check the result. This helper performs these actions automatically using |
1044 | /// RAII: |
1045 | /// |
1046 | /// @code{.cpp} |
1047 | /// Result foo(Error &Err) { |
1048 | /// ErrorAsOutParameter ErrAsOutParam(&Err); // 'Checked' flag set |
1049 | /// // <body of foo> |
1050 | /// // <- 'Checked' flag auto-cleared when ErrAsOutParam is destructed. |
1051 | /// } |
1052 | /// @endcode |
1053 | /// |
1054 | /// ErrorAsOutParameter takes an Error* rather than Error& so that it can be |
1055 | /// used with optional Errors (Error pointers that are allowed to be null). If |
1056 | /// ErrorAsOutParameter took an Error reference, an instance would have to be |
1057 | /// created inside every condition that verified that Error was non-null. By |
1058 | /// taking an Error pointer we can just create one instance at the top of the |
1059 | /// function. |
1060 | class ErrorAsOutParameter { |
1061 | public: |
1062 | ErrorAsOutParameter(Error *Err) : Err(Err) { |
1063 | // Raise the checked bit if Err is success. |
1064 | if (Err) |
1065 | (void)!!*Err; |
1066 | } |
1067 | |
1068 | ~ErrorAsOutParameter() { |
1069 | // Clear the checked bit. |
1070 | if (Err && !*Err) |
1071 | *Err = Error::success(); |
1072 | } |
1073 | |
1074 | private: |
1075 | Error *Err; |
1076 | }; |
1077 | |
1078 | /// Helper for Expected<T>s used as out-parameters. |
1079 | /// |
1080 | /// See ErrorAsOutParameter. |
1081 | template <typename T> |
1082 | class ExpectedAsOutParameter { |
1083 | public: |
1084 | ExpectedAsOutParameter(Expected<T> *ValOrErr) |
1085 | : ValOrErr(ValOrErr) { |
1086 | if (ValOrErr) |
1087 | (void)!!*ValOrErr; |
1088 | } |
1089 | |
1090 | ~ExpectedAsOutParameter() { |
1091 | if (ValOrErr) |
1092 | ValOrErr->setUnchecked(); |
1093 | } |
1094 | |
1095 | private: |
1096 | Expected<T> *ValOrErr; |
1097 | }; |
1098 | |
1099 | /// This class wraps a std::error_code in a Error. |
1100 | /// |
1101 | /// This is useful if you're writing an interface that returns a Error |
1102 | /// (or Expected) and you want to call code that still returns |
1103 | /// std::error_codes. |
1104 | class ECError : public ErrorInfo<ECError> { |
1105 | friend Error errorCodeToError(std::error_code); |
1106 | |
1107 | virtual void anchor() override; |
1108 | |
1109 | public: |
1110 | void setErrorCode(std::error_code EC) { this->EC = EC; } |
1111 | std::error_code convertToErrorCode() const override { return EC; } |
1112 | void log(raw_ostream &OS) const override { OS << EC.message(); } |
1113 | |
1114 | // Used by ErrorInfo::classID. |
1115 | static char ID; |
1116 | |
1117 | protected: |
1118 | ECError() = default; |
1119 | ECError(std::error_code EC) : EC(EC) {} |
1120 | |
1121 | std::error_code EC; |
1122 | }; |
1123 | |
1124 | /// The value returned by this function can be returned from convertToErrorCode |
1125 | /// for Error values where no sensible translation to std::error_code exists. |
1126 | /// It should only be used in this situation, and should never be used where a |
1127 | /// sensible conversion to std::error_code is available, as attempts to convert |
1128 | /// to/from this error will result in a fatal error. (i.e. it is a programmatic |
1129 | ///error to try to convert such a value). |
1130 | std::error_code inconvertibleErrorCode(); |
1131 | |
1132 | /// Helper for converting an std::error_code to a Error. |
1133 | Error errorCodeToError(std::error_code EC); |
1134 | |
1135 | /// Helper for converting an ECError to a std::error_code. |
1136 | /// |
1137 | /// This method requires that Err be Error() or an ECError, otherwise it |
1138 | /// will trigger a call to abort(). |
1139 | std::error_code errorToErrorCode(Error Err); |
1140 | |
1141 | /// Convert an ErrorOr<T> to an Expected<T>. |
1142 | template <typename T> Expected<T> errorOrToExpected(ErrorOr<T> &&EO) { |
1143 | if (auto EC = EO.getError()) |
1144 | return errorCodeToError(EC); |
1145 | return std::move(*EO); |
1146 | } |
1147 | |
1148 | /// Convert an Expected<T> to an ErrorOr<T>. |
1149 | template <typename T> ErrorOr<T> expectedToErrorOr(Expected<T> &&E) { |
1150 | if (auto Err = E.takeError()) |
1151 | return errorToErrorCode(std::move(Err)); |
1152 | return std::move(*E); |
1153 | } |
1154 | |
1155 | /// This class wraps a string in an Error. |
1156 | /// |
1157 | /// StringError is useful in cases where the client is not expected to be able |
1158 | /// to consume the specific error message programmatically (for example, if the |
1159 | /// error message is to be presented to the user). |
1160 | /// |
1161 | /// StringError can also be used when additional information is to be printed |
1162 | /// along with a error_code message. Depending on the constructor called, this |
1163 | /// class can either display: |
1164 | /// 1. the error_code message (ECError behavior) |
1165 | /// 2. a string |
1166 | /// 3. the error_code message and a string |
1167 | /// |
1168 | /// These behaviors are useful when subtyping is required; for example, when a |
1169 | /// specific library needs an explicit error type. In the example below, |
1170 | /// PDBError is derived from StringError: |
1171 | /// |
1172 | /// @code{.cpp} |
1173 | /// Expected<int> foo() { |
1174 | /// return llvm::make_error<PDBError>(pdb_error_code::dia_failed_loading, |
1175 | /// "Additional information"); |
1176 | /// } |
1177 | /// @endcode |
1178 | /// |
1179 | class StringError : public ErrorInfo<StringError> { |
1180 | public: |
1181 | static char ID; |
1182 | |
1183 | // Prints EC + S and converts to EC |
1184 | StringError(std::error_code EC, const Twine &S = Twine()); |
1185 | |
1186 | // Prints S and converts to EC |
1187 | StringError(const Twine &S, std::error_code EC); |
1188 | |
1189 | void log(raw_ostream &OS) const override; |
1190 | std::error_code convertToErrorCode() const override; |
1191 | |
1192 | const std::string &getMessage() const { return Msg; } |
1193 | |
1194 | private: |
1195 | std::string Msg; |
1196 | std::error_code EC; |
1197 | const bool PrintMsgOnly = false; |
1198 | }; |
1199 | |
1200 | /// Create formatted StringError object. |
1201 | template <typename... Ts> |
1202 | inline Error createStringError(std::error_code EC, char const *Fmt, |
1203 | const Ts &... Vals) { |
1204 | std::string Buffer; |
1205 | raw_string_ostream Stream(Buffer); |
1206 | Stream << format(Fmt, Vals...); |
1207 | return make_error<StringError>(Stream.str(), EC); |
1208 | } |
1209 | |
1210 | Error createStringError(std::error_code EC, char const *Msg); |
1211 | |
1212 | inline Error createStringError(std::error_code EC, const Twine &S) { |
1213 | return createStringError(EC, S.str().c_str()); |
1214 | } |
1215 | |
1216 | template <typename... Ts> |
1217 | inline Error createStringError(std::errc EC, char const *Fmt, |
1218 | const Ts &... Vals) { |
1219 | return createStringError(std::make_error_code(EC), Fmt, Vals...); |
1220 | } |
1221 | |
1222 | /// This class wraps a filename and another Error. |
1223 | /// |
1224 | /// In some cases, an error needs to live along a 'source' name, in order to |
1225 | /// show more detailed information to the user. |
1226 | class FileError final : public ErrorInfo<FileError> { |
1227 | |
1228 | friend Error createFileError(const Twine &, Error); |
1229 | friend Error createFileError(const Twine &, size_t, Error); |
1230 | |
1231 | public: |
1232 | void log(raw_ostream &OS) const override { |
1233 | assert(Err && !FileName.empty() && "Trying to log after takeError().")((Err && !FileName.empty() && "Trying to log after takeError()." ) ? static_cast<void> (0) : __assert_fail ("Err && !FileName.empty() && \"Trying to log after takeError().\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/Support/Error.h" , 1233, __PRETTY_FUNCTION__)); |
1234 | OS << "'" << FileName << "': "; |
1235 | if (Line.hasValue()) |
1236 | OS << "line " << Line.getValue() << ": "; |
1237 | Err->log(OS); |
1238 | } |
1239 | |
1240 | StringRef getFileName() { return FileName; } |
1241 | |
1242 | Error takeError() { return Error(std::move(Err)); } |
1243 | |
1244 | std::error_code convertToErrorCode() const override; |
1245 | |
1246 | // Used by ErrorInfo::classID. |
1247 | static char ID; |
1248 | |
1249 | private: |
1250 | FileError(const Twine &F, Optional<size_t> LineNum, |
1251 | std::unique_ptr<ErrorInfoBase> E) { |
1252 | assert(E && "Cannot create FileError from Error success value.")((E && "Cannot create FileError from Error success value." ) ? static_cast<void> (0) : __assert_fail ("E && \"Cannot create FileError from Error success value.\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/Support/Error.h" , 1252, __PRETTY_FUNCTION__)); |
1253 | assert(!F.isTriviallyEmpty() &&((!F.isTriviallyEmpty() && "The file name provided to FileError must not be empty." ) ? static_cast<void> (0) : __assert_fail ("!F.isTriviallyEmpty() && \"The file name provided to FileError must not be empty.\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/Support/Error.h" , 1254, __PRETTY_FUNCTION__)) |
1254 | "The file name provided to FileError must not be empty.")((!F.isTriviallyEmpty() && "The file name provided to FileError must not be empty." ) ? static_cast<void> (0) : __assert_fail ("!F.isTriviallyEmpty() && \"The file name provided to FileError must not be empty.\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/Support/Error.h" , 1254, __PRETTY_FUNCTION__)); |
1255 | FileName = F.str(); |
1256 | Err = std::move(E); |
1257 | Line = std::move(LineNum); |
1258 | } |
1259 | |
1260 | static Error build(const Twine &F, Optional<size_t> Line, Error E) { |
1261 | std::unique_ptr<ErrorInfoBase> Payload; |
1262 | handleAllErrors(std::move(E), |
1263 | [&](std::unique_ptr<ErrorInfoBase> EIB) -> Error { |
1264 | Payload = std::move(EIB); |
1265 | return Error::success(); |
1266 | }); |
1267 | return Error( |
1268 | std::unique_ptr<FileError>(new FileError(F, Line, std::move(Payload)))); |
1269 | } |
1270 | |
1271 | std::string FileName; |
1272 | Optional<size_t> Line; |
1273 | std::unique_ptr<ErrorInfoBase> Err; |
1274 | }; |
1275 | |
1276 | /// Concatenate a source file path and/or name with an Error. The resulting |
1277 | /// Error is unchecked. |
1278 | inline Error createFileError(const Twine &F, Error E) { |
1279 | return FileError::build(F, Optional<size_t>(), std::move(E)); |
1280 | } |
1281 | |
1282 | /// Concatenate a source file path and/or name with line number and an Error. |
1283 | /// The resulting Error is unchecked. |
1284 | inline Error createFileError(const Twine &F, size_t Line, Error E) { |
1285 | return FileError::build(F, Optional<size_t>(Line), std::move(E)); |
1286 | } |
1287 | |
1288 | /// Concatenate a source file path and/or name with a std::error_code |
1289 | /// to form an Error object. |
1290 | inline Error createFileError(const Twine &F, std::error_code EC) { |
1291 | return createFileError(F, errorCodeToError(EC)); |
1292 | } |
1293 | |
1294 | /// Concatenate a source file path and/or name with line number and |
1295 | /// std::error_code to form an Error object. |
1296 | inline Error createFileError(const Twine &F, size_t Line, std::error_code EC) { |
1297 | return createFileError(F, Line, errorCodeToError(EC)); |
1298 | } |
1299 | |
1300 | Error createFileError(const Twine &F, ErrorSuccess) = delete; |
1301 | |
1302 | /// Helper for check-and-exit error handling. |
1303 | /// |
1304 | /// For tool use only. NOT FOR USE IN LIBRARY CODE. |
1305 | /// |
1306 | class ExitOnError { |
1307 | public: |
1308 | /// Create an error on exit helper. |
1309 | ExitOnError(std::string Banner = "", int DefaultErrorExitCode = 1) |
1310 | : Banner(std::move(Banner)), |
1311 | GetExitCode([=](const Error &) { return DefaultErrorExitCode; }) {} |
1312 | |
1313 | /// Set the banner string for any errors caught by operator(). |
1314 | void setBanner(std::string Banner) { this->Banner = std::move(Banner); } |
1315 | |
1316 | /// Set the exit-code mapper function. |
1317 | void setExitCodeMapper(std::function<int(const Error &)> GetExitCode) { |
1318 | this->GetExitCode = std::move(GetExitCode); |
1319 | } |
1320 | |
1321 | /// Check Err. If it's in a failure state log the error(s) and exit. |
1322 | void operator()(Error Err) const { checkError(std::move(Err)); } |
1323 | |
1324 | /// Check E. If it's in a success state then return the contained value. If |
1325 | /// it's in a failure state log the error(s) and exit. |
1326 | template <typename T> T operator()(Expected<T> &&E) const { |
1327 | checkError(E.takeError()); |
1328 | return std::move(*E); |
1329 | } |
1330 | |
1331 | /// Check E. If it's in a success state then return the contained reference. If |
1332 | /// it's in a failure state log the error(s) and exit. |
1333 | template <typename T> T& operator()(Expected<T&> &&E) const { |
1334 | checkError(E.takeError()); |
1335 | return *E; |
1336 | } |
1337 | |
1338 | private: |
1339 | void checkError(Error Err) const { |
1340 | if (Err) { |
1341 | int ExitCode = GetExitCode(Err); |
1342 | logAllUnhandledErrors(std::move(Err), errs(), Banner); |
1343 | exit(ExitCode); |
1344 | } |
1345 | } |
1346 | |
1347 | std::string Banner; |
1348 | std::function<int(const Error &)> GetExitCode; |
1349 | }; |
1350 | |
1351 | /// Conversion from Error to LLVMErrorRef for C error bindings. |
1352 | inline LLVMErrorRef wrap(Error Err) { |
1353 | return reinterpret_cast<LLVMErrorRef>(Err.takePayload().release()); |
1354 | } |
1355 | |
1356 | /// Conversion from LLVMErrorRef to Error for C error bindings. |
1357 | inline Error unwrap(LLVMErrorRef ErrRef) { |
1358 | return Error(std::unique_ptr<ErrorInfoBase>( |
1359 | reinterpret_cast<ErrorInfoBase *>(ErrRef))); |
1360 | } |
1361 | |
1362 | } // end namespace llvm |
1363 | |
1364 | #endif // LLVM_SUPPORT_ERROR_H |
1 | //===- DeclCXX.h - Classes for representing C++ declarations --*- 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 | /// \file |
10 | /// Defines the C++ Decl subclasses, other than those for templates |
11 | /// (found in DeclTemplate.h) and friends (in DeclFriend.h). |
12 | // |
13 | //===----------------------------------------------------------------------===// |
14 | |
15 | #ifndef LLVM_CLANG_AST_DECLCXX_H |
16 | #define LLVM_CLANG_AST_DECLCXX_H |
17 | |
18 | #include "clang/AST/ASTUnresolvedSet.h" |
19 | #include "clang/AST/Decl.h" |
20 | #include "clang/AST/DeclBase.h" |
21 | #include "clang/AST/DeclarationName.h" |
22 | #include "clang/AST/Expr.h" |
23 | #include "clang/AST/ExternalASTSource.h" |
24 | #include "clang/AST/LambdaCapture.h" |
25 | #include "clang/AST/NestedNameSpecifier.h" |
26 | #include "clang/AST/Redeclarable.h" |
27 | #include "clang/AST/Stmt.h" |
28 | #include "clang/AST/Type.h" |
29 | #include "clang/AST/TypeLoc.h" |
30 | #include "clang/AST/UnresolvedSet.h" |
31 | #include "clang/Basic/LLVM.h" |
32 | #include "clang/Basic/Lambda.h" |
33 | #include "clang/Basic/LangOptions.h" |
34 | #include "clang/Basic/OperatorKinds.h" |
35 | #include "clang/Basic/SourceLocation.h" |
36 | #include "clang/Basic/Specifiers.h" |
37 | #include "llvm/ADT/ArrayRef.h" |
38 | #include "llvm/ADT/DenseMap.h" |
39 | #include "llvm/ADT/PointerIntPair.h" |
40 | #include "llvm/ADT/PointerUnion.h" |
41 | #include "llvm/ADT/STLExtras.h" |
42 | #include "llvm/ADT/TinyPtrVector.h" |
43 | #include "llvm/ADT/iterator_range.h" |
44 | #include "llvm/Support/Casting.h" |
45 | #include "llvm/Support/Compiler.h" |
46 | #include "llvm/Support/PointerLikeTypeTraits.h" |
47 | #include "llvm/Support/TrailingObjects.h" |
48 | #include <cassert> |
49 | #include <cstddef> |
50 | #include <iterator> |
51 | #include <memory> |
52 | #include <vector> |
53 | |
54 | namespace clang { |
55 | |
56 | class ASTContext; |
57 | class ClassTemplateDecl; |
58 | class ConstructorUsingShadowDecl; |
59 | class CXXBasePath; |
60 | class CXXBasePaths; |
61 | class CXXConstructorDecl; |
62 | class CXXDestructorDecl; |
63 | class CXXFinalOverriderMap; |
64 | class CXXIndirectPrimaryBaseSet; |
65 | class CXXMethodDecl; |
66 | class DecompositionDecl; |
67 | class DiagnosticBuilder; |
68 | class FriendDecl; |
69 | class FunctionTemplateDecl; |
70 | class IdentifierInfo; |
71 | class MemberSpecializationInfo; |
72 | class TemplateDecl; |
73 | class TemplateParameterList; |
74 | class UsingDecl; |
75 | |
76 | /// Represents an access specifier followed by colon ':'. |
77 | /// |
78 | /// An objects of this class represents sugar for the syntactic occurrence |
79 | /// of an access specifier followed by a colon in the list of member |
80 | /// specifiers of a C++ class definition. |
81 | /// |
82 | /// Note that they do not represent other uses of access specifiers, |
83 | /// such as those occurring in a list of base specifiers. |
84 | /// Also note that this class has nothing to do with so-called |
85 | /// "access declarations" (C++98 11.3 [class.access.dcl]). |
86 | class AccessSpecDecl : public Decl { |
87 | /// The location of the ':'. |
88 | SourceLocation ColonLoc; |
89 | |
90 | AccessSpecDecl(AccessSpecifier AS, DeclContext *DC, |
91 | SourceLocation ASLoc, SourceLocation ColonLoc) |
92 | : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) { |
93 | setAccess(AS); |
94 | } |
95 | |
96 | AccessSpecDecl(EmptyShell Empty) : Decl(AccessSpec, Empty) {} |
97 | |
98 | virtual void anchor(); |
99 | |
100 | public: |
101 | /// The location of the access specifier. |
102 | SourceLocation getAccessSpecifierLoc() const { return getLocation(); } |
103 | |
104 | /// Sets the location of the access specifier. |
105 | void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); } |
106 | |
107 | /// The location of the colon following the access specifier. |
108 | SourceLocation getColonLoc() const { return ColonLoc; } |
109 | |
110 | /// Sets the location of the colon. |
111 | void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; } |
112 | |
113 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
114 | return SourceRange(getAccessSpecifierLoc(), getColonLoc()); |
115 | } |
116 | |
117 | static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS, |
118 | DeclContext *DC, SourceLocation ASLoc, |
119 | SourceLocation ColonLoc) { |
120 | return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc); |
121 | } |
122 | |
123 | static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
124 | |
125 | // Implement isa/cast/dyncast/etc. |
126 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
127 | static bool classofKind(Kind K) { return K == AccessSpec; } |
128 | }; |
129 | |
130 | /// Represents a base class of a C++ class. |
131 | /// |
132 | /// Each CXXBaseSpecifier represents a single, direct base class (or |
133 | /// struct) of a C++ class (or struct). It specifies the type of that |
134 | /// base class, whether it is a virtual or non-virtual base, and what |
135 | /// level of access (public, protected, private) is used for the |
136 | /// derivation. For example: |
137 | /// |
138 | /// \code |
139 | /// class A { }; |
140 | /// class B { }; |
141 | /// class C : public virtual A, protected B { }; |
142 | /// \endcode |
143 | /// |
144 | /// In this code, C will have two CXXBaseSpecifiers, one for "public |
145 | /// virtual A" and the other for "protected B". |
146 | class CXXBaseSpecifier { |
147 | /// The source code range that covers the full base |
148 | /// specifier, including the "virtual" (if present) and access |
149 | /// specifier (if present). |
150 | SourceRange Range; |
151 | |
152 | /// The source location of the ellipsis, if this is a pack |
153 | /// expansion. |
154 | SourceLocation EllipsisLoc; |
155 | |
156 | /// Whether this is a virtual base class or not. |
157 | unsigned Virtual : 1; |
158 | |
159 | /// Whether this is the base of a class (true) or of a struct (false). |
160 | /// |
161 | /// This determines the mapping from the access specifier as written in the |
162 | /// source code to the access specifier used for semantic analysis. |
163 | unsigned BaseOfClass : 1; |
164 | |
165 | /// Access specifier as written in the source code (may be AS_none). |
166 | /// |
167 | /// The actual type of data stored here is an AccessSpecifier, but we use |
168 | /// "unsigned" here to work around a VC++ bug. |
169 | unsigned Access : 2; |
170 | |
171 | /// Whether the class contains a using declaration |
172 | /// to inherit the named class's constructors. |
173 | unsigned InheritConstructors : 1; |
174 | |
175 | /// The type of the base class. |
176 | /// |
177 | /// This will be a class or struct (or a typedef of such). The source code |
178 | /// range does not include the \c virtual or the access specifier. |
179 | TypeSourceInfo *BaseTypeInfo; |
180 | |
181 | public: |
182 | CXXBaseSpecifier() = default; |
183 | CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, |
184 | TypeSourceInfo *TInfo, SourceLocation EllipsisLoc) |
185 | : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC), |
186 | Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) {} |
187 | |
188 | /// Retrieves the source range that contains the entire base specifier. |
189 | SourceRange getSourceRange() const LLVM_READONLY__attribute__((__pure__)) { return Range; } |
190 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { return Range.getBegin(); } |
191 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { return Range.getEnd(); } |
192 | |
193 | /// Get the location at which the base class type was written. |
194 | SourceLocation getBaseTypeLoc() const LLVM_READONLY__attribute__((__pure__)) { |
195 | return BaseTypeInfo->getTypeLoc().getBeginLoc(); |
196 | } |
197 | |
198 | /// Determines whether the base class is a virtual base class (or not). |
199 | bool isVirtual() const { return Virtual; } |
200 | |
201 | /// Determine whether this base class is a base of a class declared |
202 | /// with the 'class' keyword (vs. one declared with the 'struct' keyword). |
203 | bool isBaseOfClass() const { return BaseOfClass; } |
204 | |
205 | /// Determine whether this base specifier is a pack expansion. |
206 | bool isPackExpansion() const { return EllipsisLoc.isValid(); } |
207 | |
208 | /// Determine whether this base class's constructors get inherited. |
209 | bool getInheritConstructors() const { return InheritConstructors; } |
210 | |
211 | /// Set that this base class's constructors should be inherited. |
212 | void setInheritConstructors(bool Inherit = true) { |
213 | InheritConstructors = Inherit; |
214 | } |
215 | |
216 | /// For a pack expansion, determine the location of the ellipsis. |
217 | SourceLocation getEllipsisLoc() const { |
218 | return EllipsisLoc; |
219 | } |
220 | |
221 | /// Returns the access specifier for this base specifier. |
222 | /// |
223 | /// This is the actual base specifier as used for semantic analysis, so |
224 | /// the result can never be AS_none. To retrieve the access specifier as |
225 | /// written in the source code, use getAccessSpecifierAsWritten(). |
226 | AccessSpecifier getAccessSpecifier() const { |
227 | if ((AccessSpecifier)Access == AS_none) |
228 | return BaseOfClass? AS_private : AS_public; |
229 | else |
230 | return (AccessSpecifier)Access; |
231 | } |
232 | |
233 | /// Retrieves the access specifier as written in the source code |
234 | /// (which may mean that no access specifier was explicitly written). |
235 | /// |
236 | /// Use getAccessSpecifier() to retrieve the access specifier for use in |
237 | /// semantic analysis. |
238 | AccessSpecifier getAccessSpecifierAsWritten() const { |
239 | return (AccessSpecifier)Access; |
240 | } |
241 | |
242 | /// Retrieves the type of the base class. |
243 | /// |
244 | /// This type will always be an unqualified class type. |
245 | QualType getType() const { |
246 | return BaseTypeInfo->getType().getUnqualifiedType(); |
247 | } |
248 | |
249 | /// Retrieves the type and source location of the base class. |
250 | TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; } |
251 | }; |
252 | |
253 | /// Represents a C++ struct/union/class. |
254 | class CXXRecordDecl : public RecordDecl { |
255 | friend class ASTDeclReader; |
256 | friend class ASTDeclWriter; |
257 | friend class ASTNodeImporter; |
258 | friend class ASTReader; |
259 | friend class ASTRecordWriter; |
260 | friend class ASTWriter; |
261 | friend class DeclContext; |
262 | friend class LambdaExpr; |
263 | |
264 | friend void FunctionDecl::setPure(bool); |
265 | friend void TagDecl::startDefinition(); |
266 | |
267 | /// Values used in DefinitionData fields to represent special members. |
268 | enum SpecialMemberFlags { |
269 | SMF_DefaultConstructor = 0x1, |
270 | SMF_CopyConstructor = 0x2, |
271 | SMF_MoveConstructor = 0x4, |
272 | SMF_CopyAssignment = 0x8, |
273 | SMF_MoveAssignment = 0x10, |
274 | SMF_Destructor = 0x20, |
275 | SMF_All = 0x3f |
276 | }; |
277 | |
278 | struct DefinitionData { |
279 | #define FIELD(Name, Width, Merge) \ |
280 | unsigned Name : Width; |
281 | #include "CXXRecordDeclDefinitionBits.def" |
282 | |
283 | /// Whether this class describes a C++ lambda. |
284 | unsigned IsLambda : 1; |
285 | |
286 | /// Whether we are currently parsing base specifiers. |
287 | unsigned IsParsingBaseSpecifiers : 1; |
288 | |
289 | /// True when visible conversion functions are already computed |
290 | /// and are available. |
291 | unsigned ComputedVisibleConversions : 1; |
292 | |
293 | unsigned HasODRHash : 1; |
294 | |
295 | /// A hash of parts of the class to help in ODR checking. |
296 | unsigned ODRHash = 0; |
297 | |
298 | /// The number of base class specifiers in Bases. |
299 | unsigned NumBases = 0; |
300 | |
301 | /// The number of virtual base class specifiers in VBases. |
302 | unsigned NumVBases = 0; |
303 | |
304 | /// Base classes of this class. |
305 | /// |
306 | /// FIXME: This is wasted space for a union. |
307 | LazyCXXBaseSpecifiersPtr Bases; |
308 | |
309 | /// direct and indirect virtual base classes of this class. |
310 | LazyCXXBaseSpecifiersPtr VBases; |
311 | |
312 | /// The conversion functions of this C++ class (but not its |
313 | /// inherited conversion functions). |
314 | /// |
315 | /// Each of the entries in this overload set is a CXXConversionDecl. |
316 | LazyASTUnresolvedSet Conversions; |
317 | |
318 | /// The conversion functions of this C++ class and all those |
319 | /// inherited conversion functions that are visible in this class. |
320 | /// |
321 | /// Each of the entries in this overload set is a CXXConversionDecl or a |
322 | /// FunctionTemplateDecl. |
323 | LazyASTUnresolvedSet VisibleConversions; |
324 | |
325 | /// The declaration which defines this record. |
326 | CXXRecordDecl *Definition; |
327 | |
328 | /// The first friend declaration in this class, or null if there |
329 | /// aren't any. |
330 | /// |
331 | /// This is actually currently stored in reverse order. |
332 | LazyDeclPtr FirstFriend; |
333 | |
334 | DefinitionData(CXXRecordDecl *D); |
335 | |
336 | /// Retrieve the set of direct base classes. |
337 | CXXBaseSpecifier *getBases() const { |
338 | if (!Bases.isOffset()) |
339 | return Bases.get(nullptr); |
340 | return getBasesSlowCase(); |
341 | } |
342 | |
343 | /// Retrieve the set of virtual base classes. |
344 | CXXBaseSpecifier *getVBases() const { |
345 | if (!VBases.isOffset()) |
346 | return VBases.get(nullptr); |
347 | return getVBasesSlowCase(); |
348 | } |
349 | |
350 | ArrayRef<CXXBaseSpecifier> bases() const { |
351 | return llvm::makeArrayRef(getBases(), NumBases); |
352 | } |
353 | |
354 | ArrayRef<CXXBaseSpecifier> vbases() const { |
355 | return llvm::makeArrayRef(getVBases(), NumVBases); |
356 | } |
357 | |
358 | private: |
359 | CXXBaseSpecifier *getBasesSlowCase() const; |
360 | CXXBaseSpecifier *getVBasesSlowCase() const; |
361 | }; |
362 | |
363 | struct DefinitionData *DefinitionData; |
364 | |
365 | /// Describes a C++ closure type (generated by a lambda expression). |
366 | struct LambdaDefinitionData : public DefinitionData { |
367 | using Capture = LambdaCapture; |
368 | |
369 | /// Whether this lambda is known to be dependent, even if its |
370 | /// context isn't dependent. |
371 | /// |
372 | /// A lambda with a non-dependent context can be dependent if it occurs |
373 | /// within the default argument of a function template, because the |
374 | /// lambda will have been created with the enclosing context as its |
375 | /// declaration context, rather than function. This is an unfortunate |
376 | /// artifact of having to parse the default arguments before. |
377 | unsigned Dependent : 1; |
378 | |
379 | /// Whether this lambda is a generic lambda. |
380 | unsigned IsGenericLambda : 1; |
381 | |
382 | /// The Default Capture. |
383 | unsigned CaptureDefault : 2; |
384 | |
385 | /// The number of captures in this lambda is limited 2^NumCaptures. |
386 | unsigned NumCaptures : 15; |
387 | |
388 | /// The number of explicit captures in this lambda. |
389 | unsigned NumExplicitCaptures : 13; |
390 | |
391 | /// Has known `internal` linkage. |
392 | unsigned HasKnownInternalLinkage : 1; |
393 | |
394 | /// The number used to indicate this lambda expression for name |
395 | /// mangling in the Itanium C++ ABI. |
396 | unsigned ManglingNumber : 31; |
397 | |
398 | /// The declaration that provides context for this lambda, if the |
399 | /// actual DeclContext does not suffice. This is used for lambdas that |
400 | /// occur within default arguments of function parameters within the class |
401 | /// or within a data member initializer. |
402 | LazyDeclPtr ContextDecl; |
403 | |
404 | /// The list of captures, both explicit and implicit, for this |
405 | /// lambda. |
406 | Capture *Captures = nullptr; |
407 | |
408 | /// The type of the call method. |
409 | TypeSourceInfo *MethodTyInfo; |
410 | |
411 | LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, bool Dependent, |
412 | bool IsGeneric, LambdaCaptureDefault CaptureDefault) |
413 | : DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric), |
414 | CaptureDefault(CaptureDefault), NumCaptures(0), |
415 | NumExplicitCaptures(0), HasKnownInternalLinkage(0), ManglingNumber(0), |
416 | MethodTyInfo(Info) { |
417 | IsLambda = true; |
418 | |
419 | // C++1z [expr.prim.lambda]p4: |
420 | // This class type is not an aggregate type. |
421 | Aggregate = false; |
422 | PlainOldData = false; |
423 | } |
424 | }; |
425 | |
426 | struct DefinitionData *dataPtr() const { |
427 | // Complete the redecl chain (if necessary). |
428 | getMostRecentDecl(); |
429 | return DefinitionData; |
430 | } |
431 | |
432 | struct DefinitionData &data() const { |
433 | auto *DD = dataPtr(); |
434 | assert(DD && "queried property of class with no definition")((DD && "queried property of class with no definition" ) ? static_cast<void> (0) : __assert_fail ("DD && \"queried property of class with no definition\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 434, __PRETTY_FUNCTION__)); |
435 | return *DD; |
436 | } |
437 | |
438 | struct LambdaDefinitionData &getLambdaData() const { |
439 | // No update required: a merged definition cannot change any lambda |
440 | // properties. |
441 | auto *DD = DefinitionData; |
442 | assert(DD && DD->IsLambda && "queried lambda property of non-lambda class")((DD && DD->IsLambda && "queried lambda property of non-lambda class" ) ? static_cast<void> (0) : __assert_fail ("DD && DD->IsLambda && \"queried lambda property of non-lambda class\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 442, __PRETTY_FUNCTION__)); |
443 | return static_cast<LambdaDefinitionData&>(*DD); |
444 | } |
445 | |
446 | /// The template or declaration that this declaration |
447 | /// describes or was instantiated from, respectively. |
448 | /// |
449 | /// For non-templates, this value will be null. For record |
450 | /// declarations that describe a class template, this will be a |
451 | /// pointer to a ClassTemplateDecl. For member |
452 | /// classes of class template specializations, this will be the |
453 | /// MemberSpecializationInfo referring to the member class that was |
454 | /// instantiated or specialized. |
455 | llvm::PointerUnion<ClassTemplateDecl *, MemberSpecializationInfo *> |
456 | TemplateOrInstantiation; |
457 | |
458 | /// Called from setBases and addedMember to notify the class that a |
459 | /// direct or virtual base class or a member of class type has been added. |
460 | void addedClassSubobject(CXXRecordDecl *Base); |
461 | |
462 | /// Notify the class that member has been added. |
463 | /// |
464 | /// This routine helps maintain information about the class based on which |
465 | /// members have been added. It will be invoked by DeclContext::addDecl() |
466 | /// whenever a member is added to this record. |
467 | void addedMember(Decl *D); |
468 | |
469 | void markedVirtualFunctionPure(); |
470 | |
471 | /// Get the head of our list of friend declarations, possibly |
472 | /// deserializing the friends from an external AST source. |
473 | FriendDecl *getFirstFriend() const; |
474 | |
475 | /// Determine whether this class has an empty base class subobject of type X |
476 | /// or of one of the types that might be at offset 0 within X (per the C++ |
477 | /// "standard layout" rules). |
478 | bool hasSubobjectAtOffsetZeroOfEmptyBaseType(ASTContext &Ctx, |
479 | const CXXRecordDecl *X); |
480 | |
481 | protected: |
482 | CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, DeclContext *DC, |
483 | SourceLocation StartLoc, SourceLocation IdLoc, |
484 | IdentifierInfo *Id, CXXRecordDecl *PrevDecl); |
485 | |
486 | public: |
487 | /// Iterator that traverses the base classes of a class. |
488 | using base_class_iterator = CXXBaseSpecifier *; |
489 | |
490 | /// Iterator that traverses the base classes of a class. |
491 | using base_class_const_iterator = const CXXBaseSpecifier *; |
492 | |
493 | CXXRecordDecl *getCanonicalDecl() override { |
494 | return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); |
495 | } |
496 | |
497 | const CXXRecordDecl *getCanonicalDecl() const { |
498 | return const_cast<CXXRecordDecl*>(this)->getCanonicalDecl(); |
499 | } |
500 | |
501 | CXXRecordDecl *getPreviousDecl() { |
502 | return cast_or_null<CXXRecordDecl>( |
503 | static_cast<RecordDecl *>(this)->getPreviousDecl()); |
504 | } |
505 | |
506 | const CXXRecordDecl *getPreviousDecl() const { |
507 | return const_cast<CXXRecordDecl*>(this)->getPreviousDecl(); |
508 | } |
509 | |
510 | CXXRecordDecl *getMostRecentDecl() { |
511 | return cast<CXXRecordDecl>( |
512 | static_cast<RecordDecl *>(this)->getMostRecentDecl()); |
513 | } |
514 | |
515 | const CXXRecordDecl *getMostRecentDecl() const { |
516 | return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl(); |
517 | } |
518 | |
519 | CXXRecordDecl *getMostRecentNonInjectedDecl() { |
520 | CXXRecordDecl *Recent = |
521 | static_cast<CXXRecordDecl *>(this)->getMostRecentDecl(); |
522 | while (Recent->isInjectedClassName()) { |
523 | // FIXME: Does injected class name need to be in the redeclarations chain? |
524 | assert(Recent->getPreviousDecl())((Recent->getPreviousDecl()) ? static_cast<void> (0) : __assert_fail ("Recent->getPreviousDecl()", "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 524, __PRETTY_FUNCTION__)); |
525 | Recent = Recent->getPreviousDecl(); |
526 | } |
527 | return Recent; |
528 | } |
529 | |
530 | const CXXRecordDecl *getMostRecentNonInjectedDecl() const { |
531 | return const_cast<CXXRecordDecl*>(this)->getMostRecentNonInjectedDecl(); |
532 | } |
533 | |
534 | CXXRecordDecl *getDefinition() const { |
535 | // We only need an update if we don't already know which |
536 | // declaration is the definition. |
537 | auto *DD = DefinitionData ? DefinitionData : dataPtr(); |
538 | return DD ? DD->Definition : nullptr; |
539 | } |
540 | |
541 | bool hasDefinition() const { return DefinitionData || dataPtr(); } |
542 | |
543 | static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC, |
544 | SourceLocation StartLoc, SourceLocation IdLoc, |
545 | IdentifierInfo *Id, |
546 | CXXRecordDecl *PrevDecl = nullptr, |
547 | bool DelayTypeCreation = false); |
548 | static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC, |
549 | TypeSourceInfo *Info, SourceLocation Loc, |
550 | bool DependentLambda, bool IsGeneric, |
551 | LambdaCaptureDefault CaptureDefault); |
552 | static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID); |
553 | |
554 | bool isDynamicClass() const { |
555 | return data().Polymorphic || data().NumVBases != 0; |
556 | } |
557 | |
558 | /// @returns true if class is dynamic or might be dynamic because the |
559 | /// definition is incomplete of dependent. |
560 | bool mayBeDynamicClass() const { |
561 | return !hasDefinition() || isDynamicClass() || hasAnyDependentBases(); |
562 | } |
563 | |
564 | /// @returns true if class is non dynamic or might be non dynamic because the |
565 | /// definition is incomplete of dependent. |
566 | bool mayBeNonDynamicClass() const { |
567 | return !hasDefinition() || !isDynamicClass() || hasAnyDependentBases(); |
568 | } |
569 | |
570 | void setIsParsingBaseSpecifiers() { data().IsParsingBaseSpecifiers = true; } |
571 | |
572 | bool isParsingBaseSpecifiers() const { |
573 | return data().IsParsingBaseSpecifiers; |
574 | } |
575 | |
576 | unsigned getODRHash() const; |
577 | |
578 | /// Sets the base classes of this struct or class. |
579 | void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases); |
580 | |
581 | /// Retrieves the number of base classes of this class. |
582 | unsigned getNumBases() const { return data().NumBases; } |
583 | |
584 | using base_class_range = llvm::iterator_range<base_class_iterator>; |
585 | using base_class_const_range = |
586 | llvm::iterator_range<base_class_const_iterator>; |
587 | |
588 | base_class_range bases() { |
589 | return base_class_range(bases_begin(), bases_end()); |
590 | } |
591 | base_class_const_range bases() const { |
592 | return base_class_const_range(bases_begin(), bases_end()); |
593 | } |
594 | |
595 | base_class_iterator bases_begin() { return data().getBases(); } |
596 | base_class_const_iterator bases_begin() const { return data().getBases(); } |
597 | base_class_iterator bases_end() { return bases_begin() + data().NumBases; } |
598 | base_class_const_iterator bases_end() const { |
599 | return bases_begin() + data().NumBases; |
600 | } |
601 | |
602 | /// Retrieves the number of virtual base classes of this class. |
603 | unsigned getNumVBases() const { return data().NumVBases; } |
604 | |
605 | base_class_range vbases() { |
606 | return base_class_range(vbases_begin(), vbases_end()); |
607 | } |
608 | base_class_const_range vbases() const { |
609 | return base_class_const_range(vbases_begin(), vbases_end()); |
610 | } |
611 | |
612 | base_class_iterator vbases_begin() { return data().getVBases(); } |
613 | base_class_const_iterator vbases_begin() const { return data().getVBases(); } |
614 | base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; } |
615 | base_class_const_iterator vbases_end() const { |
616 | return vbases_begin() + data().NumVBases; |
617 | } |
618 | |
619 | /// Determine whether this class has any dependent base classes which |
620 | /// are not the current instantiation. |
621 | bool hasAnyDependentBases() const; |
622 | |
623 | /// Iterator access to method members. The method iterator visits |
624 | /// all method members of the class, including non-instance methods, |
625 | /// special methods, etc. |
626 | using method_iterator = specific_decl_iterator<CXXMethodDecl>; |
627 | using method_range = |
628 | llvm::iterator_range<specific_decl_iterator<CXXMethodDecl>>; |
629 | |
630 | method_range methods() const { |
631 | return method_range(method_begin(), method_end()); |
632 | } |
633 | |
634 | /// Method begin iterator. Iterates in the order the methods |
635 | /// were declared. |
636 | method_iterator method_begin() const { |
637 | return method_iterator(decls_begin()); |
638 | } |
639 | |
640 | /// Method past-the-end iterator. |
641 | method_iterator method_end() const { |
642 | return method_iterator(decls_end()); |
643 | } |
644 | |
645 | /// Iterator access to constructor members. |
646 | using ctor_iterator = specific_decl_iterator<CXXConstructorDecl>; |
647 | using ctor_range = |
648 | llvm::iterator_range<specific_decl_iterator<CXXConstructorDecl>>; |
649 | |
650 | ctor_range ctors() const { return ctor_range(ctor_begin(), ctor_end()); } |
651 | |
652 | ctor_iterator ctor_begin() const { |
653 | return ctor_iterator(decls_begin()); |
654 | } |
655 | |
656 | ctor_iterator ctor_end() const { |
657 | return ctor_iterator(decls_end()); |
658 | } |
659 | |
660 | /// An iterator over friend declarations. All of these are defined |
661 | /// in DeclFriend.h. |
662 | class friend_iterator; |
663 | using friend_range = llvm::iterator_range<friend_iterator>; |
664 | |
665 | friend_range friends() const; |
666 | friend_iterator friend_begin() const; |
667 | friend_iterator friend_end() const; |
668 | void pushFriendDecl(FriendDecl *FD); |
669 | |
670 | /// Determines whether this record has any friends. |
671 | bool hasFriends() const { |
672 | return data().FirstFriend.isValid(); |
673 | } |
674 | |
675 | /// \c true if a defaulted copy constructor for this class would be |
676 | /// deleted. |
677 | bool defaultedCopyConstructorIsDeleted() const { |
678 | assert((!needsOverloadResolutionForCopyConstructor() ||(((!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 680, __PRETTY_FUNCTION__)) |
679 | (data().DeclaredSpecialMembers & SMF_CopyConstructor)) &&(((!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 680, __PRETTY_FUNCTION__)) |
680 | "this property has not yet been computed by Sema")(((!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 680, __PRETTY_FUNCTION__)); |
681 | return data().DefaultedCopyConstructorIsDeleted; |
682 | } |
683 | |
684 | /// \c true if a defaulted move constructor for this class would be |
685 | /// deleted. |
686 | bool defaultedMoveConstructorIsDeleted() const { |
687 | assert((!needsOverloadResolutionForMoveConstructor() ||(((!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 689, __PRETTY_FUNCTION__)) |
688 | (data().DeclaredSpecialMembers & SMF_MoveConstructor)) &&(((!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 689, __PRETTY_FUNCTION__)) |
689 | "this property has not yet been computed by Sema")(((!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 689, __PRETTY_FUNCTION__)); |
690 | return data().DefaultedMoveConstructorIsDeleted; |
691 | } |
692 | |
693 | /// \c true if a defaulted destructor for this class would be deleted. |
694 | bool defaultedDestructorIsDeleted() const { |
695 | assert((!needsOverloadResolutionForDestructor() ||(((!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 697, __PRETTY_FUNCTION__)) |
696 | (data().DeclaredSpecialMembers & SMF_Destructor)) &&(((!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 697, __PRETTY_FUNCTION__)) |
697 | "this property has not yet been computed by Sema")(((!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 697, __PRETTY_FUNCTION__)); |
698 | return data().DefaultedDestructorIsDeleted; |
699 | } |
700 | |
701 | /// \c true if we know for sure that this class has a single, |
702 | /// accessible, unambiguous copy constructor that is not deleted. |
703 | bool hasSimpleCopyConstructor() const { |
704 | return !hasUserDeclaredCopyConstructor() && |
705 | !data().DefaultedCopyConstructorIsDeleted; |
706 | } |
707 | |
708 | /// \c true if we know for sure that this class has a single, |
709 | /// accessible, unambiguous move constructor that is not deleted. |
710 | bool hasSimpleMoveConstructor() const { |
711 | return !hasUserDeclaredMoveConstructor() && hasMoveConstructor() && |
712 | !data().DefaultedMoveConstructorIsDeleted; |
713 | } |
714 | |
715 | /// \c true if we know for sure that this class has a single, |
716 | /// accessible, unambiguous copy assignment operator that is not deleted. |
717 | bool hasSimpleCopyAssignment() const { |
718 | return !hasUserDeclaredCopyAssignment() && |
719 | !data().DefaultedCopyAssignmentIsDeleted; |
720 | } |
721 | |
722 | /// \c true if we know for sure that this class has a single, |
723 | /// accessible, unambiguous move assignment operator that is not deleted. |
724 | bool hasSimpleMoveAssignment() const { |
725 | return !hasUserDeclaredMoveAssignment() && hasMoveAssignment() && |
726 | !data().DefaultedMoveAssignmentIsDeleted; |
727 | } |
728 | |
729 | /// \c true if we know for sure that this class has an accessible |
730 | /// destructor that is not deleted. |
731 | bool hasSimpleDestructor() const { |
732 | return !hasUserDeclaredDestructor() && |
733 | !data().DefaultedDestructorIsDeleted; |
734 | } |
735 | |
736 | /// Determine whether this class has any default constructors. |
737 | bool hasDefaultConstructor() const { |
738 | return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) || |
739 | needsImplicitDefaultConstructor(); |
740 | } |
741 | |
742 | /// Determine if we need to declare a default constructor for |
743 | /// this class. |
744 | /// |
745 | /// This value is used for lazy creation of default constructors. |
746 | bool needsImplicitDefaultConstructor() const { |
747 | return !data().UserDeclaredConstructor && |
748 | !(data().DeclaredSpecialMembers & SMF_DefaultConstructor) && |
749 | (!isLambda() || lambdaIsDefaultConstructibleAndAssignable()); |
750 | } |
751 | |
752 | /// Determine whether this class has any user-declared constructors. |
753 | /// |
754 | /// When true, a default constructor will not be implicitly declared. |
755 | bool hasUserDeclaredConstructor() const { |
756 | return data().UserDeclaredConstructor; |
757 | } |
758 | |
759 | /// Whether this class has a user-provided default constructor |
760 | /// per C++11. |
761 | bool hasUserProvidedDefaultConstructor() const { |
762 | return data().UserProvidedDefaultConstructor; |
763 | } |
764 | |
765 | /// Determine whether this class has a user-declared copy constructor. |
766 | /// |
767 | /// When false, a copy constructor will be implicitly declared. |
768 | bool hasUserDeclaredCopyConstructor() const { |
769 | return data().UserDeclaredSpecialMembers & SMF_CopyConstructor; |
770 | } |
771 | |
772 | /// Determine whether this class needs an implicit copy |
773 | /// constructor to be lazily declared. |
774 | bool needsImplicitCopyConstructor() const { |
775 | return !(data().DeclaredSpecialMembers & SMF_CopyConstructor); |
776 | } |
777 | |
778 | /// Determine whether we need to eagerly declare a defaulted copy |
779 | /// constructor for this class. |
780 | bool needsOverloadResolutionForCopyConstructor() const { |
781 | // C++17 [class.copy.ctor]p6: |
782 | // If the class definition declares a move constructor or move assignment |
783 | // operator, the implicitly declared copy constructor is defined as |
784 | // deleted. |
785 | // In MSVC mode, sometimes a declared move assignment does not delete an |
786 | // implicit copy constructor, so defer this choice to Sema. |
787 | if (data().UserDeclaredSpecialMembers & |
788 | (SMF_MoveConstructor | SMF_MoveAssignment)) |
789 | return true; |
790 | return data().NeedOverloadResolutionForCopyConstructor; |
791 | } |
792 | |
793 | /// Determine whether an implicit copy constructor for this type |
794 | /// would have a parameter with a const-qualified reference type. |
795 | bool implicitCopyConstructorHasConstParam() const { |
796 | return data().ImplicitCopyConstructorCanHaveConstParamForNonVBase && |
797 | (isAbstract() || |
798 | data().ImplicitCopyConstructorCanHaveConstParamForVBase); |
799 | } |
800 | |
801 | /// Determine whether this class has a copy constructor with |
802 | /// a parameter type which is a reference to a const-qualified type. |
803 | bool hasCopyConstructorWithConstParam() const { |
804 | return data().HasDeclaredCopyConstructorWithConstParam || |
805 | (needsImplicitCopyConstructor() && |
806 | implicitCopyConstructorHasConstParam()); |
807 | } |
808 | |
809 | /// Whether this class has a user-declared move constructor or |
810 | /// assignment operator. |
811 | /// |
812 | /// When false, a move constructor and assignment operator may be |
813 | /// implicitly declared. |
814 | bool hasUserDeclaredMoveOperation() const { |
815 | return data().UserDeclaredSpecialMembers & |
816 | (SMF_MoveConstructor | SMF_MoveAssignment); |
817 | } |
818 | |
819 | /// Determine whether this class has had a move constructor |
820 | /// declared by the user. |
821 | bool hasUserDeclaredMoveConstructor() const { |
822 | return data().UserDeclaredSpecialMembers & SMF_MoveConstructor; |
823 | } |
824 | |
825 | /// Determine whether this class has a move constructor. |
826 | bool hasMoveConstructor() const { |
827 | return (data().DeclaredSpecialMembers & SMF_MoveConstructor) || |
828 | needsImplicitMoveConstructor(); |
829 | } |
830 | |
831 | /// Set that we attempted to declare an implicit copy |
832 | /// constructor, but overload resolution failed so we deleted it. |
833 | void setImplicitCopyConstructorIsDeleted() { |
834 | assert((data().DefaultedCopyConstructorIsDeleted ||(((data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor ()) && "Copy constructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor()) && \"Copy constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 836, __PRETTY_FUNCTION__)) |
835 | needsOverloadResolutionForCopyConstructor()) &&(((data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor ()) && "Copy constructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor()) && \"Copy constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 836, __PRETTY_FUNCTION__)) |
836 | "Copy constructor should not be deleted")(((data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor ()) && "Copy constructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor()) && \"Copy constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 836, __PRETTY_FUNCTION__)); |
837 | data().DefaultedCopyConstructorIsDeleted = true; |
838 | } |
839 | |
840 | /// Set that we attempted to declare an implicit move |
841 | /// constructor, but overload resolution failed so we deleted it. |
842 | void setImplicitMoveConstructorIsDeleted() { |
843 | assert((data().DefaultedMoveConstructorIsDeleted ||(((data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor ()) && "move constructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor()) && \"move constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 845, __PRETTY_FUNCTION__)) |
844 | needsOverloadResolutionForMoveConstructor()) &&(((data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor ()) && "move constructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor()) && \"move constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 845, __PRETTY_FUNCTION__)) |
845 | "move constructor should not be deleted")(((data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor ()) && "move constructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor()) && \"move constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 845, __PRETTY_FUNCTION__)); |
846 | data().DefaultedMoveConstructorIsDeleted = true; |
847 | } |
848 | |
849 | /// Set that we attempted to declare an implicit destructor, |
850 | /// but overload resolution failed so we deleted it. |
851 | void setImplicitDestructorIsDeleted() { |
852 | assert((data().DefaultedDestructorIsDeleted ||(((data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor ()) && "destructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor()) && \"destructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 854, __PRETTY_FUNCTION__)) |
853 | needsOverloadResolutionForDestructor()) &&(((data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor ()) && "destructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor()) && \"destructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 854, __PRETTY_FUNCTION__)) |
854 | "destructor should not be deleted")(((data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor ()) && "destructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor()) && \"destructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 854, __PRETTY_FUNCTION__)); |
855 | data().DefaultedDestructorIsDeleted = true; |
856 | } |
857 | |
858 | /// Determine whether this class should get an implicit move |
859 | /// constructor or if any existing special member function inhibits this. |
860 | bool needsImplicitMoveConstructor() const { |
861 | return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) && |
862 | !hasUserDeclaredCopyConstructor() && |
863 | !hasUserDeclaredCopyAssignment() && |
864 | !hasUserDeclaredMoveAssignment() && |
865 | !hasUserDeclaredDestructor(); |
866 | } |
867 | |
868 | /// Determine whether we need to eagerly declare a defaulted move |
869 | /// constructor for this class. |
870 | bool needsOverloadResolutionForMoveConstructor() const { |
871 | return data().NeedOverloadResolutionForMoveConstructor; |
872 | } |
873 | |
874 | /// Determine whether this class has a user-declared copy assignment |
875 | /// operator. |
876 | /// |
877 | /// When false, a copy assignment operator will be implicitly declared. |
878 | bool hasUserDeclaredCopyAssignment() const { |
879 | return data().UserDeclaredSpecialMembers & SMF_CopyAssignment; |
880 | } |
881 | |
882 | /// Set that we attempted to declare an implicit copy assignment |
883 | /// operator, but overload resolution failed so we deleted it. |
884 | void setImplicitCopyAssignmentIsDeleted() { |
885 | assert((data().DefaultedCopyAssignmentIsDeleted ||(((data().DefaultedCopyAssignmentIsDeleted || needsOverloadResolutionForCopyAssignment ()) && "copy assignment should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedCopyAssignmentIsDeleted || needsOverloadResolutionForCopyAssignment()) && \"copy assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 887, __PRETTY_FUNCTION__)) |
886 | needsOverloadResolutionForCopyAssignment()) &&(((data().DefaultedCopyAssignmentIsDeleted || needsOverloadResolutionForCopyAssignment ()) && "copy assignment should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedCopyAssignmentIsDeleted || needsOverloadResolutionForCopyAssignment()) && \"copy assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 887, __PRETTY_FUNCTION__)) |
887 | "copy assignment should not be deleted")(((data().DefaultedCopyAssignmentIsDeleted || needsOverloadResolutionForCopyAssignment ()) && "copy assignment should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedCopyAssignmentIsDeleted || needsOverloadResolutionForCopyAssignment()) && \"copy assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 887, __PRETTY_FUNCTION__)); |
888 | data().DefaultedCopyAssignmentIsDeleted = true; |
889 | } |
890 | |
891 | /// Determine whether this class needs an implicit copy |
892 | /// assignment operator to be lazily declared. |
893 | bool needsImplicitCopyAssignment() const { |
894 | return !(data().DeclaredSpecialMembers & SMF_CopyAssignment); |
895 | } |
896 | |
897 | /// Determine whether we need to eagerly declare a defaulted copy |
898 | /// assignment operator for this class. |
899 | bool needsOverloadResolutionForCopyAssignment() const { |
900 | // C++20 [class.copy.assign]p2: |
901 | // If the class definition declares a move constructor or move assignment |
902 | // operator, the implicitly declared copy assignment operator is defined |
903 | // as deleted. |
904 | // In MSVC mode, sometimes a declared move constructor does not delete an |
905 | // implicit copy assignment, so defer this choice to Sema. |
906 | if (data().UserDeclaredSpecialMembers & |
907 | (SMF_MoveConstructor | SMF_MoveAssignment)) |
908 | return true; |
909 | return data().NeedOverloadResolutionForCopyAssignment; |
910 | } |
911 | |
912 | /// Determine whether an implicit copy assignment operator for this |
913 | /// type would have a parameter with a const-qualified reference type. |
914 | bool implicitCopyAssignmentHasConstParam() const { |
915 | return data().ImplicitCopyAssignmentHasConstParam; |
916 | } |
917 | |
918 | /// Determine whether this class has a copy assignment operator with |
919 | /// a parameter type which is a reference to a const-qualified type or is not |
920 | /// a reference. |
921 | bool hasCopyAssignmentWithConstParam() const { |
922 | return data().HasDeclaredCopyAssignmentWithConstParam || |
923 | (needsImplicitCopyAssignment() && |
924 | implicitCopyAssignmentHasConstParam()); |
925 | } |
926 | |
927 | /// Determine whether this class has had a move assignment |
928 | /// declared by the user. |
929 | bool hasUserDeclaredMoveAssignment() const { |
930 | return data().UserDeclaredSpecialMembers & SMF_MoveAssignment; |
931 | } |
932 | |
933 | /// Determine whether this class has a move assignment operator. |
934 | bool hasMoveAssignment() const { |
935 | return (data().DeclaredSpecialMembers & SMF_MoveAssignment) || |
936 | needsImplicitMoveAssignment(); |
937 | } |
938 | |
939 | /// Set that we attempted to declare an implicit move assignment |
940 | /// operator, but overload resolution failed so we deleted it. |
941 | void setImplicitMoveAssignmentIsDeleted() { |
942 | assert((data().DefaultedMoveAssignmentIsDeleted ||(((data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment ()) && "move assignment should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment()) && \"move assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 944, __PRETTY_FUNCTION__)) |
943 | needsOverloadResolutionForMoveAssignment()) &&(((data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment ()) && "move assignment should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment()) && \"move assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 944, __PRETTY_FUNCTION__)) |
944 | "move assignment should not be deleted")(((data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment ()) && "move assignment should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment()) && \"move assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 944, __PRETTY_FUNCTION__)); |
945 | data().DefaultedMoveAssignmentIsDeleted = true; |
946 | } |
947 | |
948 | /// Determine whether this class should get an implicit move |
949 | /// assignment operator or if any existing special member function inhibits |
950 | /// this. |
951 | bool needsImplicitMoveAssignment() const { |
952 | return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) && |
953 | !hasUserDeclaredCopyConstructor() && |
954 | !hasUserDeclaredCopyAssignment() && |
955 | !hasUserDeclaredMoveConstructor() && |
956 | !hasUserDeclaredDestructor() && |
957 | (!isLambda() || lambdaIsDefaultConstructibleAndAssignable()); |
958 | } |
959 | |
960 | /// Determine whether we need to eagerly declare a move assignment |
961 | /// operator for this class. |
962 | bool needsOverloadResolutionForMoveAssignment() const { |
963 | return data().NeedOverloadResolutionForMoveAssignment; |
964 | } |
965 | |
966 | /// Determine whether this class has a user-declared destructor. |
967 | /// |
968 | /// When false, a destructor will be implicitly declared. |
969 | bool hasUserDeclaredDestructor() const { |
970 | return data().UserDeclaredSpecialMembers & SMF_Destructor; |
971 | } |
972 | |
973 | /// Determine whether this class needs an implicit destructor to |
974 | /// be lazily declared. |
975 | bool needsImplicitDestructor() const { |
976 | return !(data().DeclaredSpecialMembers & SMF_Destructor); |
977 | } |
978 | |
979 | /// Determine whether we need to eagerly declare a destructor for this |
980 | /// class. |
981 | bool needsOverloadResolutionForDestructor() const { |
982 | return data().NeedOverloadResolutionForDestructor; |
983 | } |
984 | |
985 | /// Determine whether this class describes a lambda function object. |
986 | bool isLambda() const { |
987 | // An update record can't turn a non-lambda into a lambda. |
988 | auto *DD = DefinitionData; |
989 | return DD && DD->IsLambda; |
990 | } |
991 | |
992 | /// Determine whether this class describes a generic |
993 | /// lambda function object (i.e. function call operator is |
994 | /// a template). |
995 | bool isGenericLambda() const; |
996 | |
997 | /// Determine whether this lambda should have an implicit default constructor |
998 | /// and copy and move assignment operators. |
999 | bool lambdaIsDefaultConstructibleAndAssignable() const; |
1000 | |
1001 | /// Retrieve the lambda call operator of the closure type |
1002 | /// if this is a closure type. |
1003 | CXXMethodDecl *getLambdaCallOperator() const; |
1004 | |
1005 | /// Retrieve the dependent lambda call operator of the closure type |
1006 | /// if this is a templated closure type. |
1007 | FunctionTemplateDecl *getDependentLambdaCallOperator() const; |
1008 | |
1009 | /// Retrieve the lambda static invoker, the address of which |
1010 | /// is returned by the conversion operator, and the body of which |
1011 | /// is forwarded to the lambda call operator. The version that does not |
1012 | /// take a calling convention uses the 'default' calling convention for free |
1013 | /// functions if the Lambda's calling convention was not modified via |
1014 | /// attribute. Otherwise, it will return the calling convention specified for |
1015 | /// the lambda. |
1016 | CXXMethodDecl *getLambdaStaticInvoker() const; |
1017 | CXXMethodDecl *getLambdaStaticInvoker(CallingConv CC) const; |
1018 | |
1019 | /// Retrieve the generic lambda's template parameter list. |
1020 | /// Returns null if the class does not represent a lambda or a generic |
1021 | /// lambda. |
1022 | TemplateParameterList *getGenericLambdaTemplateParameterList() const; |
1023 | |
1024 | /// Retrieve the lambda template parameters that were specified explicitly. |
1025 | ArrayRef<NamedDecl *> getLambdaExplicitTemplateParameters() const; |
1026 | |
1027 | LambdaCaptureDefault getLambdaCaptureDefault() const { |
1028 | assert(isLambda())((isLambda()) ? static_cast<void> (0) : __assert_fail ( "isLambda()", "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 1028, __PRETTY_FUNCTION__)); |
1029 | return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault); |
1030 | } |
1031 | |
1032 | /// Set the captures for this lambda closure type. |
1033 | void setCaptures(ASTContext &Context, ArrayRef<LambdaCapture> Captures); |
1034 | |
1035 | /// For a closure type, retrieve the mapping from captured |
1036 | /// variables and \c this to the non-static data members that store the |
1037 | /// values or references of the captures. |
1038 | /// |
1039 | /// \param Captures Will be populated with the mapping from captured |
1040 | /// variables to the corresponding fields. |
1041 | /// |
1042 | /// \param ThisCapture Will be set to the field declaration for the |
1043 | /// \c this capture. |
1044 | /// |
1045 | /// \note No entries will be added for init-captures, as they do not capture |
1046 | /// variables. |
1047 | void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures, |
1048 | FieldDecl *&ThisCapture) const; |
1049 | |
1050 | using capture_const_iterator = const LambdaCapture *; |
1051 | using capture_const_range = llvm::iterator_range<capture_const_iterator>; |
1052 | |
1053 | capture_const_range captures() const { |
1054 | return capture_const_range(captures_begin(), captures_end()); |
1055 | } |
1056 | |
1057 | capture_const_iterator captures_begin() const { |
1058 | return isLambda() ? getLambdaData().Captures : nullptr; |
1059 | } |
1060 | |
1061 | capture_const_iterator captures_end() const { |
1062 | return isLambda() ? captures_begin() + getLambdaData().NumCaptures |
1063 | : nullptr; |
1064 | } |
1065 | |
1066 | unsigned capture_size() const { return getLambdaData().NumCaptures; } |
1067 | |
1068 | using conversion_iterator = UnresolvedSetIterator; |
1069 | |
1070 | conversion_iterator conversion_begin() const { |
1071 | return data().Conversions.get(getASTContext()).begin(); |
1072 | } |
1073 | |
1074 | conversion_iterator conversion_end() const { |
1075 | return data().Conversions.get(getASTContext()).end(); |
1076 | } |
1077 | |
1078 | /// Removes a conversion function from this class. The conversion |
1079 | /// function must currently be a member of this class. Furthermore, |
1080 | /// this class must currently be in the process of being defined. |
1081 | void removeConversion(const NamedDecl *Old); |
1082 | |
1083 | /// Get all conversion functions visible in current class, |
1084 | /// including conversion function templates. |
1085 | llvm::iterator_range<conversion_iterator> |
1086 | getVisibleConversionFunctions() const; |
1087 | |
1088 | /// Determine whether this class is an aggregate (C++ [dcl.init.aggr]), |
1089 | /// which is a class with no user-declared constructors, no private |
1090 | /// or protected non-static data members, no base classes, and no virtual |
1091 | /// functions (C++ [dcl.init.aggr]p1). |
1092 | bool isAggregate() const { return data().Aggregate; } |
1093 | |
1094 | /// Whether this class has any in-class initializers |
1095 | /// for non-static data members (including those in anonymous unions or |
1096 | /// structs). |
1097 | bool hasInClassInitializer() const { return data().HasInClassInitializer; } |
1098 | |
1099 | /// Whether this class or any of its subobjects has any members of |
1100 | /// reference type which would make value-initialization ill-formed. |
1101 | /// |
1102 | /// Per C++03 [dcl.init]p5: |
1103 | /// - if T is a non-union class type without a user-declared constructor, |
1104 | /// then every non-static data member and base-class component of T is |
1105 | /// value-initialized [...] A program that calls for [...] |
1106 | /// value-initialization of an entity of reference type is ill-formed. |
1107 | bool hasUninitializedReferenceMember() const { |
1108 | return !isUnion() && !hasUserDeclaredConstructor() && |
1109 | data().HasUninitializedReferenceMember; |
1110 | } |
1111 | |
1112 | /// Whether this class is a POD-type (C++ [class]p4) |
1113 | /// |
1114 | /// For purposes of this function a class is POD if it is an aggregate |
1115 | /// that has no non-static non-POD data members, no reference data |
1116 | /// members, no user-defined copy assignment operator and no |
1117 | /// user-defined destructor. |
1118 | /// |
1119 | /// Note that this is the C++ TR1 definition of POD. |
1120 | bool isPOD() const { return data().PlainOldData; } |
1121 | |
1122 | /// True if this class is C-like, without C++-specific features, e.g. |
1123 | /// it contains only public fields, no bases, tag kind is not 'class', etc. |
1124 | bool isCLike() const; |
1125 | |
1126 | /// Determine whether this is an empty class in the sense of |
1127 | /// (C++11 [meta.unary.prop]). |
1128 | /// |
1129 | /// The CXXRecordDecl is a class type, but not a union type, |
1130 | /// with no non-static data members other than bit-fields of length 0, |
1131 | /// no virtual member functions, no virtual base classes, |
1132 | /// and no base class B for which is_empty<B>::value is false. |
1133 | /// |
1134 | /// \note This does NOT include a check for union-ness. |
1135 | bool isEmpty() const { return data().Empty; } |
1136 | |
1137 | bool hasPrivateFields() const { |
1138 | return data().HasPrivateFields; |
1139 | } |
1140 | |
1141 | bool hasProtectedFields() const { |
1142 | return data().HasProtectedFields; |
1143 | } |
1144 | |
1145 | /// Determine whether this class has direct non-static data members. |
1146 | bool hasDirectFields() const { |
1147 | auto &D = data(); |
1148 | return D.HasPublicFields || D.HasProtectedFields || D.HasPrivateFields; |
1149 | } |
1150 | |
1151 | /// Whether this class is polymorphic (C++ [class.virtual]), |
1152 | /// which means that the class contains or inherits a virtual function. |
1153 | bool isPolymorphic() const { return data().Polymorphic; } |
1154 | |
1155 | /// Determine whether this class has a pure virtual function. |
1156 | /// |
1157 | /// The class is is abstract per (C++ [class.abstract]p2) if it declares |
1158 | /// a pure virtual function or inherits a pure virtual function that is |
1159 | /// not overridden. |
1160 | bool isAbstract() const { return data().Abstract; } |
1161 | |
1162 | /// Determine whether this class is standard-layout per |
1163 | /// C++ [class]p7. |
1164 | bool isStandardLayout() const { return data().IsStandardLayout; } |
1165 | |
1166 | /// Determine whether this class was standard-layout per |
1167 | /// C++11 [class]p7, specifically using the C++11 rules without any DRs. |
1168 | bool isCXX11StandardLayout() const { return data().IsCXX11StandardLayout; } |
1169 | |
1170 | /// Determine whether this class, or any of its class subobjects, |
1171 | /// contains a mutable field. |
1172 | bool hasMutableFields() const { return data().HasMutableFields; } |
1173 | |
1174 | /// Determine whether this class has any variant members. |
1175 | bool hasVariantMembers() const { return data().HasVariantMembers; } |
1176 | |
1177 | /// Determine whether this class has a trivial default constructor |
1178 | /// (C++11 [class.ctor]p5). |
1179 | bool hasTrivialDefaultConstructor() const { |
1180 | return hasDefaultConstructor() && |
1181 | (data().HasTrivialSpecialMembers & SMF_DefaultConstructor); |
1182 | } |
1183 | |
1184 | /// Determine whether this class has a non-trivial default constructor |
1185 | /// (C++11 [class.ctor]p5). |
1186 | bool hasNonTrivialDefaultConstructor() const { |
1187 | return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) || |
1188 | (needsImplicitDefaultConstructor() && |
1189 | !(data().HasTrivialSpecialMembers & SMF_DefaultConstructor)); |
1190 | } |
1191 | |
1192 | /// Determine whether this class has at least one constexpr constructor |
1193 | /// other than the copy or move constructors. |
1194 | bool hasConstexprNonCopyMoveConstructor() const { |
1195 | return data().HasConstexprNonCopyMoveConstructor || |
1196 | (needsImplicitDefaultConstructor() && |
1197 | defaultedDefaultConstructorIsConstexpr()); |
1198 | } |
1199 | |
1200 | /// Determine whether a defaulted default constructor for this class |
1201 | /// would be constexpr. |
1202 | bool defaultedDefaultConstructorIsConstexpr() const { |
1203 | return data().DefaultedDefaultConstructorIsConstexpr && |
1204 | (!isUnion() || hasInClassInitializer() || !hasVariantMembers() || |
1205 | getLangOpts().CPlusPlus20); |
1206 | } |
1207 | |
1208 | /// Determine whether this class has a constexpr default constructor. |
1209 | bool hasConstexprDefaultConstructor() const { |
1210 | return data().HasConstexprDefaultConstructor || |
1211 | (needsImplicitDefaultConstructor() && |
1212 | defaultedDefaultConstructorIsConstexpr()); |
1213 | } |
1214 | |
1215 | /// Determine whether this class has a trivial copy constructor |
1216 | /// (C++ [class.copy]p6, C++11 [class.copy]p12) |
1217 | bool hasTrivialCopyConstructor() const { |
1218 | return data().HasTrivialSpecialMembers & SMF_CopyConstructor; |
1219 | } |
1220 | |
1221 | bool hasTrivialCopyConstructorForCall() const { |
1222 | return data().HasTrivialSpecialMembersForCall & SMF_CopyConstructor; |
1223 | } |
1224 | |
1225 | /// Determine whether this class has a non-trivial copy constructor |
1226 | /// (C++ [class.copy]p6, C++11 [class.copy]p12) |
1227 | bool hasNonTrivialCopyConstructor() const { |
1228 | return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor || |
1229 | !hasTrivialCopyConstructor(); |
1230 | } |
1231 | |
1232 | bool hasNonTrivialCopyConstructorForCall() const { |
1233 | return (data().DeclaredNonTrivialSpecialMembersForCall & |
1234 | SMF_CopyConstructor) || |
1235 | !hasTrivialCopyConstructorForCall(); |
1236 | } |
1237 | |
1238 | /// Determine whether this class has a trivial move constructor |
1239 | /// (C++11 [class.copy]p12) |
1240 | bool hasTrivialMoveConstructor() const { |
1241 | return hasMoveConstructor() && |
1242 | (data().HasTrivialSpecialMembers & SMF_MoveConstructor); |
1243 | } |
1244 | |
1245 | bool hasTrivialMoveConstructorForCall() const { |
1246 | return hasMoveConstructor() && |
1247 | (data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor); |
1248 | } |
1249 | |
1250 | /// Determine whether this class has a non-trivial move constructor |
1251 | /// (C++11 [class.copy]p12) |
1252 | bool hasNonTrivialMoveConstructor() const { |
1253 | return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) || |
1254 | (needsImplicitMoveConstructor() && |
1255 | !(data().HasTrivialSpecialMembers & SMF_MoveConstructor)); |
1256 | } |
1257 | |
1258 | bool hasNonTrivialMoveConstructorForCall() const { |
1259 | return (data().DeclaredNonTrivialSpecialMembersForCall & |
1260 | SMF_MoveConstructor) || |
1261 | (needsImplicitMoveConstructor() && |
1262 | !(data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor)); |
1263 | } |
1264 | |
1265 | /// Determine whether this class has a trivial copy assignment operator |
1266 | /// (C++ [class.copy]p11, C++11 [class.copy]p25) |
1267 | bool hasTrivialCopyAssignment() const { |
1268 | return data().HasTrivialSpecialMembers & SMF_CopyAssignment; |
1269 | } |
1270 | |
1271 | /// Determine whether this class has a non-trivial copy assignment |
1272 | /// operator (C++ [class.copy]p11, C++11 [class.copy]p25) |
1273 | bool hasNonTrivialCopyAssignment() const { |
1274 | return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment || |
1275 | !hasTrivialCopyAssignment(); |
1276 | } |
1277 | |
1278 | /// Determine whether this class has a trivial move assignment operator |
1279 | /// (C++11 [class.copy]p25) |
1280 | bool hasTrivialMoveAssignment() const { |
1281 | return hasMoveAssignment() && |
1282 | (data().HasTrivialSpecialMembers & SMF_MoveAssignment); |
1283 | } |
1284 | |
1285 | /// Determine whether this class has a non-trivial move assignment |
1286 | /// operator (C++11 [class.copy]p25) |
1287 | bool hasNonTrivialMoveAssignment() const { |
1288 | return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) || |
1289 | (needsImplicitMoveAssignment() && |
1290 | !(data().HasTrivialSpecialMembers & SMF_MoveAssignment)); |
1291 | } |
1292 | |
1293 | /// Determine whether a defaulted default constructor for this class |
1294 | /// would be constexpr. |
1295 | bool defaultedDestructorIsConstexpr() const { |
1296 | return data().DefaultedDestructorIsConstexpr && |
1297 | getLangOpts().CPlusPlus20; |
1298 | } |
1299 | |
1300 | /// Determine whether this class has a constexpr destructor. |
1301 | bool hasConstexprDestructor() const; |
1302 | |
1303 | /// Determine whether this class has a trivial destructor |
1304 | /// (C++ [class.dtor]p3) |
1305 | bool hasTrivialDestructor() const { |
1306 | return data().HasTrivialSpecialMembers & SMF_Destructor; |
1307 | } |
1308 | |
1309 | bool hasTrivialDestructorForCall() const { |
1310 | return data().HasTrivialSpecialMembersForCall & SMF_Destructor; |
1311 | } |
1312 | |
1313 | /// Determine whether this class has a non-trivial destructor |
1314 | /// (C++ [class.dtor]p3) |
1315 | bool hasNonTrivialDestructor() const { |
1316 | return !(data().HasTrivialSpecialMembers & SMF_Destructor); |
1317 | } |
1318 | |
1319 | bool hasNonTrivialDestructorForCall() const { |
1320 | return !(data().HasTrivialSpecialMembersForCall & SMF_Destructor); |
1321 | } |
1322 | |
1323 | void setHasTrivialSpecialMemberForCall() { |
1324 | data().HasTrivialSpecialMembersForCall = |
1325 | (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor); |
1326 | } |
1327 | |
1328 | /// Determine whether declaring a const variable with this type is ok |
1329 | /// per core issue 253. |
1330 | bool allowConstDefaultInit() const { |
1331 | return !data().HasUninitializedFields || |
1332 | !(data().HasDefaultedDefaultConstructor || |
1333 | needsImplicitDefaultConstructor()); |
1334 | } |
1335 | |
1336 | /// Determine whether this class has a destructor which has no |
1337 | /// semantic effect. |
1338 | /// |
1339 | /// Any such destructor will be trivial, public, defaulted and not deleted, |
1340 | /// and will call only irrelevant destructors. |
1341 | bool hasIrrelevantDestructor() const { |
1342 | return data().HasIrrelevantDestructor; |
1343 | } |
1344 | |
1345 | /// Determine whether this class has a non-literal or/ volatile type |
1346 | /// non-static data member or base class. |
1347 | bool hasNonLiteralTypeFieldsOrBases() const { |
1348 | return data().HasNonLiteralTypeFieldsOrBases; |
1349 | } |
1350 | |
1351 | /// Determine whether this class has a using-declaration that names |
1352 | /// a user-declared base class constructor. |
1353 | bool hasInheritedConstructor() const { |
1354 | return data().HasInheritedConstructor; |
1355 | } |
1356 | |
1357 | /// Determine whether this class has a using-declaration that names |
1358 | /// a base class assignment operator. |
1359 | bool hasInheritedAssignment() const { |
1360 | return data().HasInheritedAssignment; |
1361 | } |
1362 | |
1363 | /// Determine whether this class is considered trivially copyable per |
1364 | /// (C++11 [class]p6). |
1365 | bool isTriviallyCopyable() const; |
1366 | |
1367 | /// Determine whether this class is considered trivial. |
1368 | /// |
1369 | /// C++11 [class]p6: |
1370 | /// "A trivial class is a class that has a trivial default constructor and |
1371 | /// is trivially copyable." |
1372 | bool isTrivial() const { |
1373 | return isTriviallyCopyable() && hasTrivialDefaultConstructor(); |
1374 | } |
1375 | |
1376 | /// Determine whether this class is a literal type. |
1377 | /// |
1378 | /// C++11 [basic.types]p10: |
1379 | /// A class type that has all the following properties: |
1380 | /// - it has a trivial destructor |
1381 | /// - every constructor call and full-expression in the |
1382 | /// brace-or-equal-intializers for non-static data members (if any) is |
1383 | /// a constant expression. |
1384 | /// - it is an aggregate type or has at least one constexpr constructor |
1385 | /// or constructor template that is not a copy or move constructor, and |
1386 | /// - all of its non-static data members and base classes are of literal |
1387 | /// types |
1388 | /// |
1389 | /// We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by |
1390 | /// treating types with trivial default constructors as literal types. |
1391 | /// |
1392 | /// Only in C++17 and beyond, are lambdas literal types. |
1393 | bool isLiteral() const { |
1394 | const LangOptions &LangOpts = getLangOpts(); |
1395 | return (LangOpts.CPlusPlus20 ? hasConstexprDestructor() |
1396 | : hasTrivialDestructor()) && |
1397 | (!isLambda() || LangOpts.CPlusPlus17) && |
1398 | !hasNonLiteralTypeFieldsOrBases() && |
1399 | (isAggregate() || isLambda() || |
1400 | hasConstexprNonCopyMoveConstructor() || |
1401 | hasTrivialDefaultConstructor()); |
1402 | } |
1403 | |
1404 | /// Determine whether this is a structural type. |
1405 | bool isStructural() const { |
1406 | return isLiteral() && data().StructuralIfLiteral; |
1407 | } |
1408 | |
1409 | /// If this record is an instantiation of a member class, |
1410 | /// retrieves the member class from which it was instantiated. |
1411 | /// |
1412 | /// This routine will return non-null for (non-templated) member |
1413 | /// classes of class templates. For example, given: |
1414 | /// |
1415 | /// \code |
1416 | /// template<typename T> |
1417 | /// struct X { |
1418 | /// struct A { }; |
1419 | /// }; |
1420 | /// \endcode |
1421 | /// |
1422 | /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl |
1423 | /// whose parent is the class template specialization X<int>. For |
1424 | /// this declaration, getInstantiatedFromMemberClass() will return |
1425 | /// the CXXRecordDecl X<T>::A. When a complete definition of |
1426 | /// X<int>::A is required, it will be instantiated from the |
1427 | /// declaration returned by getInstantiatedFromMemberClass(). |
1428 | CXXRecordDecl *getInstantiatedFromMemberClass() const; |
1429 | |
1430 | /// If this class is an instantiation of a member class of a |
1431 | /// class template specialization, retrieves the member specialization |
1432 | /// information. |
1433 | MemberSpecializationInfo *getMemberSpecializationInfo() const; |
1434 | |
1435 | /// Specify that this record is an instantiation of the |
1436 | /// member class \p RD. |
1437 | void setInstantiationOfMemberClass(CXXRecordDecl *RD, |
1438 | TemplateSpecializationKind TSK); |
1439 | |
1440 | /// Retrieves the class template that is described by this |
1441 | /// class declaration. |
1442 | /// |
1443 | /// Every class template is represented as a ClassTemplateDecl and a |
1444 | /// CXXRecordDecl. The former contains template properties (such as |
1445 | /// the template parameter lists) while the latter contains the |
1446 | /// actual description of the template's |
1447 | /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the |
1448 | /// CXXRecordDecl that from a ClassTemplateDecl, while |
1449 | /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from |
1450 | /// a CXXRecordDecl. |
1451 | ClassTemplateDecl *getDescribedClassTemplate() const; |
1452 | |
1453 | void setDescribedClassTemplate(ClassTemplateDecl *Template); |
1454 | |
1455 | /// Determine whether this particular class is a specialization or |
1456 | /// instantiation of a class template or member class of a class template, |
1457 | /// and how it was instantiated or specialized. |
1458 | TemplateSpecializationKind getTemplateSpecializationKind() const; |
1459 | |
1460 | /// Set the kind of specialization or template instantiation this is. |
1461 | void setTemplateSpecializationKind(TemplateSpecializationKind TSK); |
1462 | |
1463 | /// Retrieve the record declaration from which this record could be |
1464 | /// instantiated. Returns null if this class is not a template instantiation. |
1465 | const CXXRecordDecl *getTemplateInstantiationPattern() const; |
1466 | |
1467 | CXXRecordDecl *getTemplateInstantiationPattern() { |
1468 | return const_cast<CXXRecordDecl *>(const_cast<const CXXRecordDecl *>(this) |
1469 | ->getTemplateInstantiationPattern()); |
1470 | } |
1471 | |
1472 | /// Returns the destructor decl for this class. |
1473 | CXXDestructorDecl *getDestructor() const; |
1474 | |
1475 | /// Returns true if the class destructor, or any implicitly invoked |
1476 | /// destructors are marked noreturn. |
1477 | bool isAnyDestructorNoReturn() const; |
1478 | |
1479 | /// If the class is a local class [class.local], returns |
1480 | /// the enclosing function declaration. |
1481 | const FunctionDecl *isLocalClass() const { |
1482 | if (const auto *RD = dyn_cast<CXXRecordDecl>(getDeclContext())) |
1483 | return RD->isLocalClass(); |
1484 | |
1485 | return dyn_cast<FunctionDecl>(getDeclContext()); |
1486 | } |
1487 | |
1488 | FunctionDecl *isLocalClass() { |
1489 | return const_cast<FunctionDecl*>( |
1490 | const_cast<const CXXRecordDecl*>(this)->isLocalClass()); |
1491 | } |
1492 | |
1493 | /// Determine whether this dependent class is a current instantiation, |
1494 | /// when viewed from within the given context. |
1495 | bool isCurrentInstantiation(const DeclContext *CurContext) const; |
1496 | |
1497 | /// Determine whether this class is derived from the class \p Base. |
1498 | /// |
1499 | /// This routine only determines whether this class is derived from \p Base, |
1500 | /// but does not account for factors that may make a Derived -> Base class |
1501 | /// ill-formed, such as private/protected inheritance or multiple, ambiguous |
1502 | /// base class subobjects. |
1503 | /// |
1504 | /// \param Base the base class we are searching for. |
1505 | /// |
1506 | /// \returns true if this class is derived from Base, false otherwise. |
1507 | bool isDerivedFrom(const CXXRecordDecl *Base) const; |
1508 | |
1509 | /// Determine whether this class is derived from the type \p Base. |
1510 | /// |
1511 | /// This routine only determines whether this class is derived from \p Base, |
1512 | /// but does not account for factors that may make a Derived -> Base class |
1513 | /// ill-formed, such as private/protected inheritance or multiple, ambiguous |
1514 | /// base class subobjects. |
1515 | /// |
1516 | /// \param Base the base class we are searching for. |
1517 | /// |
1518 | /// \param Paths will contain the paths taken from the current class to the |
1519 | /// given \p Base class. |
1520 | /// |
1521 | /// \returns true if this class is derived from \p Base, false otherwise. |
1522 | /// |
1523 | /// \todo add a separate parameter to configure IsDerivedFrom, rather than |
1524 | /// tangling input and output in \p Paths |
1525 | bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const; |
1526 | |
1527 | /// Determine whether this class is virtually derived from |
1528 | /// the class \p Base. |
1529 | /// |
1530 | /// This routine only determines whether this class is virtually |
1531 | /// derived from \p Base, but does not account for factors that may |
1532 | /// make a Derived -> Base class ill-formed, such as |
1533 | /// private/protected inheritance or multiple, ambiguous base class |
1534 | /// subobjects. |
1535 | /// |
1536 | /// \param Base the base class we are searching for. |
1537 | /// |
1538 | /// \returns true if this class is virtually derived from Base, |
1539 | /// false otherwise. |
1540 | bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const; |
1541 | |
1542 | /// Determine whether this class is provably not derived from |
1543 | /// the type \p Base. |
1544 | bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const; |
1545 | |
1546 | /// Function type used by forallBases() as a callback. |
1547 | /// |
1548 | /// \param BaseDefinition the definition of the base class |
1549 | /// |
1550 | /// \returns true if this base matched the search criteria |
1551 | using ForallBasesCallback = |
1552 | llvm::function_ref<bool(const CXXRecordDecl *BaseDefinition)>; |
1553 | |
1554 | /// Determines if the given callback holds for all the direct |
1555 | /// or indirect base classes of this type. |
1556 | /// |
1557 | /// The class itself does not count as a base class. This routine |
1558 | /// returns false if the class has non-computable base classes. |
1559 | /// |
1560 | /// \param BaseMatches Callback invoked for each (direct or indirect) base |
1561 | /// class of this type until a call returns false. |
1562 | bool forallBases(ForallBasesCallback BaseMatches) const; |
1563 | |
1564 | /// Function type used by lookupInBases() to determine whether a |
1565 | /// specific base class subobject matches the lookup criteria. |
1566 | /// |
1567 | /// \param Specifier the base-class specifier that describes the inheritance |
1568 | /// from the base class we are trying to match. |
1569 | /// |
1570 | /// \param Path the current path, from the most-derived class down to the |
1571 | /// base named by the \p Specifier. |
1572 | /// |
1573 | /// \returns true if this base matched the search criteria, false otherwise. |
1574 | using BaseMatchesCallback = |
1575 | llvm::function_ref<bool(const CXXBaseSpecifier *Specifier, |
1576 | CXXBasePath &Path)>; |
1577 | |
1578 | /// Look for entities within the base classes of this C++ class, |
1579 | /// transitively searching all base class subobjects. |
1580 | /// |
1581 | /// This routine uses the callback function \p BaseMatches to find base |
1582 | /// classes meeting some search criteria, walking all base class subobjects |
1583 | /// and populating the given \p Paths structure with the paths through the |
1584 | /// inheritance hierarchy that resulted in a match. On a successful search, |
1585 | /// the \p Paths structure can be queried to retrieve the matching paths and |
1586 | /// to determine if there were any ambiguities. |
1587 | /// |
1588 | /// \param BaseMatches callback function used to determine whether a given |
1589 | /// base matches the user-defined search criteria. |
1590 | /// |
1591 | /// \param Paths used to record the paths from this class to its base class |
1592 | /// subobjects that match the search criteria. |
1593 | /// |
1594 | /// \param LookupInDependent can be set to true to extend the search to |
1595 | /// dependent base classes. |
1596 | /// |
1597 | /// \returns true if there exists any path from this class to a base class |
1598 | /// subobject that matches the search criteria. |
1599 | bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths, |
1600 | bool LookupInDependent = false) const; |
1601 | |
1602 | /// Base-class lookup callback that determines whether the given |
1603 | /// base class specifier refers to a specific class declaration. |
1604 | /// |
1605 | /// This callback can be used with \c lookupInBases() to determine whether |
1606 | /// a given derived class has is a base class subobject of a particular type. |
1607 | /// The base record pointer should refer to the canonical CXXRecordDecl of the |
1608 | /// base class that we are searching for. |
1609 | static bool FindBaseClass(const CXXBaseSpecifier *Specifier, |
1610 | CXXBasePath &Path, const CXXRecordDecl *BaseRecord); |
1611 | |
1612 | /// Base-class lookup callback that determines whether the |
1613 | /// given base class specifier refers to a specific class |
1614 | /// declaration and describes virtual derivation. |
1615 | /// |
1616 | /// This callback can be used with \c lookupInBases() to determine |
1617 | /// whether a given derived class has is a virtual base class |
1618 | /// subobject of a particular type. The base record pointer should |
1619 | /// refer to the canonical CXXRecordDecl of the base class that we |
1620 | /// are searching for. |
1621 | static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier, |
1622 | CXXBasePath &Path, |
1623 | const CXXRecordDecl *BaseRecord); |
1624 | |
1625 | /// Retrieve the final overriders for each virtual member |
1626 | /// function in the class hierarchy where this class is the |
1627 | /// most-derived class in the class hierarchy. |
1628 | void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const; |
1629 | |
1630 | /// Get the indirect primary bases for this class. |
1631 | void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const; |
1632 | |
1633 | /// Determine whether this class has a member with the given name, possibly |
1634 | /// in a non-dependent base class. |
1635 | /// |
1636 | /// No check for ambiguity is performed, so this should never be used when |
1637 | /// implementing language semantics, but it may be appropriate for warnings, |
1638 | /// static analysis, or similar. |
1639 | bool hasMemberName(DeclarationName N) const; |
1640 | |
1641 | /// Performs an imprecise lookup of a dependent name in this class. |
1642 | /// |
1643 | /// This function does not follow strict semantic rules and should be used |
1644 | /// only when lookup rules can be relaxed, e.g. indexing. |
1645 | std::vector<const NamedDecl *> |
1646 | lookupDependentName(DeclarationName Name, |
1647 | llvm::function_ref<bool(const NamedDecl *ND)> Filter); |
1648 | |
1649 | /// Renders and displays an inheritance diagram |
1650 | /// for this C++ class and all of its base classes (transitively) using |
1651 | /// GraphViz. |
1652 | void viewInheritance(ASTContext& Context) const; |
1653 | |
1654 | /// Calculates the access of a decl that is reached |
1655 | /// along a path. |
1656 | static AccessSpecifier MergeAccess(AccessSpecifier PathAccess, |
1657 | AccessSpecifier DeclAccess) { |
1658 | assert(DeclAccess != AS_none)((DeclAccess != AS_none) ? static_cast<void> (0) : __assert_fail ("DeclAccess != AS_none", "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 1658, __PRETTY_FUNCTION__)); |
1659 | if (DeclAccess == AS_private) return AS_none; |
1660 | return (PathAccess > DeclAccess ? PathAccess : DeclAccess); |
1661 | } |
1662 | |
1663 | /// Indicates that the declaration of a defaulted or deleted special |
1664 | /// member function is now complete. |
1665 | void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD); |
1666 | |
1667 | void setTrivialForCallFlags(CXXMethodDecl *MD); |
1668 | |
1669 | /// Indicates that the definition of this class is now complete. |
1670 | void completeDefinition() override; |
1671 | |
1672 | /// Indicates that the definition of this class is now complete, |
1673 | /// and provides a final overrider map to help determine |
1674 | /// |
1675 | /// \param FinalOverriders The final overrider map for this class, which can |
1676 | /// be provided as an optimization for abstract-class checking. If NULL, |
1677 | /// final overriders will be computed if they are needed to complete the |
1678 | /// definition. |
1679 | void completeDefinition(CXXFinalOverriderMap *FinalOverriders); |
1680 | |
1681 | /// Determine whether this class may end up being abstract, even though |
1682 | /// it is not yet known to be abstract. |
1683 | /// |
1684 | /// \returns true if this class is not known to be abstract but has any |
1685 | /// base classes that are abstract. In this case, \c completeDefinition() |
1686 | /// will need to compute final overriders to determine whether the class is |
1687 | /// actually abstract. |
1688 | bool mayBeAbstract() const; |
1689 | |
1690 | /// Determine whether it's impossible for a class to be derived from this |
1691 | /// class. This is best-effort, and may conservatively return false. |
1692 | bool isEffectivelyFinal() const; |
1693 | |
1694 | /// If this is the closure type of a lambda expression, retrieve the |
1695 | /// number to be used for name mangling in the Itanium C++ ABI. |
1696 | /// |
1697 | /// Zero indicates that this closure type has internal linkage, so the |
1698 | /// mangling number does not matter, while a non-zero value indicates which |
1699 | /// lambda expression this is in this particular context. |
1700 | unsigned getLambdaManglingNumber() const { |
1701 | assert(isLambda() && "Not a lambda closure type!")((isLambda() && "Not a lambda closure type!") ? static_cast <void> (0) : __assert_fail ("isLambda() && \"Not a lambda closure type!\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 1701, __PRETTY_FUNCTION__)); |
1702 | return getLambdaData().ManglingNumber; |
1703 | } |
1704 | |
1705 | /// The lambda is known to has internal linkage no matter whether it has name |
1706 | /// mangling number. |
1707 | bool hasKnownLambdaInternalLinkage() const { |
1708 | assert(isLambda() && "Not a lambda closure type!")((isLambda() && "Not a lambda closure type!") ? static_cast <void> (0) : __assert_fail ("isLambda() && \"Not a lambda closure type!\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 1708, __PRETTY_FUNCTION__)); |
1709 | return getLambdaData().HasKnownInternalLinkage; |
1710 | } |
1711 | |
1712 | /// Retrieve the declaration that provides additional context for a |
1713 | /// lambda, when the normal declaration context is not specific enough. |
1714 | /// |
1715 | /// Certain contexts (default arguments of in-class function parameters and |
1716 | /// the initializers of data members) have separate name mangling rules for |
1717 | /// lambdas within the Itanium C++ ABI. For these cases, this routine provides |
1718 | /// the declaration in which the lambda occurs, e.g., the function parameter |
1719 | /// or the non-static data member. Otherwise, it returns NULL to imply that |
1720 | /// the declaration context suffices. |
1721 | Decl *getLambdaContextDecl() const; |
1722 | |
1723 | /// Set the mangling number and context declaration for a lambda |
1724 | /// class. |
1725 | void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl, |
1726 | bool HasKnownInternalLinkage = false) { |
1727 | assert(isLambda() && "Not a lambda closure type!")((isLambda() && "Not a lambda closure type!") ? static_cast <void> (0) : __assert_fail ("isLambda() && \"Not a lambda closure type!\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 1727, __PRETTY_FUNCTION__)); |
1728 | getLambdaData().ManglingNumber = ManglingNumber; |
1729 | getLambdaData().ContextDecl = ContextDecl; |
1730 | getLambdaData().HasKnownInternalLinkage = HasKnownInternalLinkage; |
1731 | } |
1732 | |
1733 | /// Returns the inheritance model used for this record. |
1734 | MSInheritanceModel getMSInheritanceModel() const; |
1735 | |
1736 | /// Calculate what the inheritance model would be for this class. |
1737 | MSInheritanceModel calculateInheritanceModel() const; |
1738 | |
1739 | /// In the Microsoft C++ ABI, use zero for the field offset of a null data |
1740 | /// member pointer if we can guarantee that zero is not a valid field offset, |
1741 | /// or if the member pointer has multiple fields. Polymorphic classes have a |
1742 | /// vfptr at offset zero, so we can use zero for null. If there are multiple |
1743 | /// fields, we can use zero even if it is a valid field offset because |
1744 | /// null-ness testing will check the other fields. |
1745 | bool nullFieldOffsetIsZero() const; |
1746 | |
1747 | /// Controls when vtordisps will be emitted if this record is used as a |
1748 | /// virtual base. |
1749 | MSVtorDispMode getMSVtorDispMode() const; |
1750 | |
1751 | /// Determine whether this lambda expression was known to be dependent |
1752 | /// at the time it was created, even if its context does not appear to be |
1753 | /// dependent. |
1754 | /// |
1755 | /// This flag is a workaround for an issue with parsing, where default |
1756 | /// arguments are parsed before their enclosing function declarations have |
1757 | /// been created. This means that any lambda expressions within those |
1758 | /// default arguments will have as their DeclContext the context enclosing |
1759 | /// the function declaration, which may be non-dependent even when the |
1760 | /// function declaration itself is dependent. This flag indicates when we |
1761 | /// know that the lambda is dependent despite that. |
1762 | bool isDependentLambda() const { |
1763 | return isLambda() && getLambdaData().Dependent; |
1764 | } |
1765 | |
1766 | TypeSourceInfo *getLambdaTypeInfo() const { |
1767 | return getLambdaData().MethodTyInfo; |
1768 | } |
1769 | |
1770 | // Determine whether this type is an Interface Like type for |
1771 | // __interface inheritance purposes. |
1772 | bool isInterfaceLike() const; |
1773 | |
1774 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1775 | static bool classofKind(Kind K) { |
1776 | return K >= firstCXXRecord && K <= lastCXXRecord; |
1777 | } |
1778 | }; |
1779 | |
1780 | /// Store information needed for an explicit specifier. |
1781 | /// Used by CXXDeductionGuideDecl, CXXConstructorDecl and CXXConversionDecl. |
1782 | class ExplicitSpecifier { |
1783 | llvm::PointerIntPair<Expr *, 2, ExplicitSpecKind> ExplicitSpec{ |
1784 | nullptr, ExplicitSpecKind::ResolvedFalse}; |
1785 | |
1786 | public: |
1787 | ExplicitSpecifier() = default; |
1788 | ExplicitSpecifier(Expr *Expression, ExplicitSpecKind Kind) |
1789 | : ExplicitSpec(Expression, Kind) {} |
1790 | ExplicitSpecKind getKind() const { return ExplicitSpec.getInt(); } |
1791 | const Expr *getExpr() const { return ExplicitSpec.getPointer(); } |
1792 | Expr *getExpr() { return ExplicitSpec.getPointer(); } |
1793 | |
1794 | /// Determine if the declaration had an explicit specifier of any kind. |
1795 | bool isSpecified() const { |
1796 | return ExplicitSpec.getInt() != ExplicitSpecKind::ResolvedFalse || |
1797 | ExplicitSpec.getPointer(); |
1798 | } |
1799 | |
1800 | /// Check for equivalence of explicit specifiers. |
1801 | /// \return true if the explicit specifier are equivalent, false otherwise. |
1802 | bool isEquivalent(const ExplicitSpecifier Other) const; |
1803 | /// Determine whether this specifier is known to correspond to an explicit |
1804 | /// declaration. Returns false if the specifier is absent or has an |
1805 | /// expression that is value-dependent or evaluates to false. |
1806 | bool isExplicit() const { |
1807 | return ExplicitSpec.getInt() == ExplicitSpecKind::ResolvedTrue; |
1808 | } |
1809 | /// Determine if the explicit specifier is invalid. |
1810 | /// This state occurs after a substitution failures. |
1811 | bool isInvalid() const { |
1812 | return ExplicitSpec.getInt() == ExplicitSpecKind::Unresolved && |
1813 | !ExplicitSpec.getPointer(); |
1814 | } |
1815 | void setKind(ExplicitSpecKind Kind) { ExplicitSpec.setInt(Kind); } |
1816 | void setExpr(Expr *E) { ExplicitSpec.setPointer(E); } |
1817 | // Retrieve the explicit specifier in the given declaration, if any. |
1818 | static ExplicitSpecifier getFromDecl(FunctionDecl *Function); |
1819 | static const ExplicitSpecifier getFromDecl(const FunctionDecl *Function) { |
1820 | return getFromDecl(const_cast<FunctionDecl *>(Function)); |
1821 | } |
1822 | static ExplicitSpecifier Invalid() { |
1823 | return ExplicitSpecifier(nullptr, ExplicitSpecKind::Unresolved); |
1824 | } |
1825 | }; |
1826 | |
1827 | /// Represents a C++ deduction guide declaration. |
1828 | /// |
1829 | /// \code |
1830 | /// template<typename T> struct A { A(); A(T); }; |
1831 | /// A() -> A<int>; |
1832 | /// \endcode |
1833 | /// |
1834 | /// In this example, there will be an explicit deduction guide from the |
1835 | /// second line, and implicit deduction guide templates synthesized from |
1836 | /// the constructors of \c A. |
1837 | class CXXDeductionGuideDecl : public FunctionDecl { |
1838 | void anchor() override; |
1839 | |
1840 | private: |
1841 | CXXDeductionGuideDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
1842 | ExplicitSpecifier ES, |
1843 | const DeclarationNameInfo &NameInfo, QualType T, |
1844 | TypeSourceInfo *TInfo, SourceLocation EndLocation) |
1845 | : FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo, |
1846 | SC_None, false, ConstexprSpecKind::Unspecified), |
1847 | ExplicitSpec(ES) { |
1848 | if (EndLocation.isValid()) |
1849 | setRangeEnd(EndLocation); |
1850 | setIsCopyDeductionCandidate(false); |
1851 | } |
1852 | |
1853 | ExplicitSpecifier ExplicitSpec; |
1854 | void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; } |
1855 | |
1856 | public: |
1857 | friend class ASTDeclReader; |
1858 | friend class ASTDeclWriter; |
1859 | |
1860 | static CXXDeductionGuideDecl * |
1861 | Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
1862 | ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T, |
1863 | TypeSourceInfo *TInfo, SourceLocation EndLocation); |
1864 | |
1865 | static CXXDeductionGuideDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
1866 | |
1867 | ExplicitSpecifier getExplicitSpecifier() { return ExplicitSpec; } |
1868 | const ExplicitSpecifier getExplicitSpecifier() const { return ExplicitSpec; } |
1869 | |
1870 | /// Return true if the declartion is already resolved to be explicit. |
1871 | bool isExplicit() const { return ExplicitSpec.isExplicit(); } |
1872 | |
1873 | /// Get the template for which this guide performs deduction. |
1874 | TemplateDecl *getDeducedTemplate() const { |
1875 | return getDeclName().getCXXDeductionGuideTemplate(); |
1876 | } |
1877 | |
1878 | void setIsCopyDeductionCandidate(bool isCDC = true) { |
1879 | FunctionDeclBits.IsCopyDeductionCandidate = isCDC; |
1880 | } |
1881 | |
1882 | bool isCopyDeductionCandidate() const { |
1883 | return FunctionDeclBits.IsCopyDeductionCandidate; |
1884 | } |
1885 | |
1886 | // Implement isa/cast/dyncast/etc. |
1887 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1888 | static bool classofKind(Kind K) { return K == CXXDeductionGuide; } |
1889 | }; |
1890 | |
1891 | /// \brief Represents the body of a requires-expression. |
1892 | /// |
1893 | /// This decl exists merely to serve as the DeclContext for the local |
1894 | /// parameters of the requires expression as well as other declarations inside |
1895 | /// it. |
1896 | /// |
1897 | /// \code |
1898 | /// template<typename T> requires requires (T t) { {t++} -> regular; } |
1899 | /// \endcode |
1900 | /// |
1901 | /// In this example, a RequiresExpr object will be generated for the expression, |
1902 | /// and a RequiresExprBodyDecl will be created to hold the parameter t and the |
1903 | /// template argument list imposed by the compound requirement. |
1904 | class RequiresExprBodyDecl : public Decl, public DeclContext { |
1905 | RequiresExprBodyDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc) |
1906 | : Decl(RequiresExprBody, DC, StartLoc), DeclContext(RequiresExprBody) {} |
1907 | |
1908 | public: |
1909 | friend class ASTDeclReader; |
1910 | friend class ASTDeclWriter; |
1911 | |
1912 | static RequiresExprBodyDecl *Create(ASTContext &C, DeclContext *DC, |
1913 | SourceLocation StartLoc); |
1914 | |
1915 | static RequiresExprBodyDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
1916 | |
1917 | // Implement isa/cast/dyncast/etc. |
1918 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1919 | static bool classofKind(Kind K) { return K == RequiresExprBody; } |
1920 | }; |
1921 | |
1922 | /// Represents a static or instance method of a struct/union/class. |
1923 | /// |
1924 | /// In the terminology of the C++ Standard, these are the (static and |
1925 | /// non-static) member functions, whether virtual or not. |
1926 | class CXXMethodDecl : public FunctionDecl { |
1927 | void anchor() override; |
1928 | |
1929 | protected: |
1930 | CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD, |
1931 | SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, |
1932 | QualType T, TypeSourceInfo *TInfo, StorageClass SC, |
1933 | bool isInline, ConstexprSpecKind ConstexprKind, |
1934 | SourceLocation EndLocation, |
1935 | Expr *TrailingRequiresClause = nullptr) |
1936 | : FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo, SC, isInline, |
1937 | ConstexprKind, TrailingRequiresClause) { |
1938 | if (EndLocation.isValid()) |
1939 | setRangeEnd(EndLocation); |
1940 | } |
1941 | |
1942 | public: |
1943 | static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD, |
1944 | SourceLocation StartLoc, |
1945 | const DeclarationNameInfo &NameInfo, QualType T, |
1946 | TypeSourceInfo *TInfo, StorageClass SC, |
1947 | bool isInline, ConstexprSpecKind ConstexprKind, |
1948 | SourceLocation EndLocation, |
1949 | Expr *TrailingRequiresClause = nullptr); |
1950 | |
1951 | static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
1952 | |
1953 | bool isStatic() const; |
1954 | bool isInstance() const { return !isStatic(); } |
1955 | |
1956 | /// Returns true if the given operator is implicitly static in a record |
1957 | /// context. |
1958 | static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) { |
1959 | // [class.free]p1: |
1960 | // Any allocation function for a class T is a static member |
1961 | // (even if not explicitly declared static). |
1962 | // [class.free]p6 Any deallocation function for a class X is a static member |
1963 | // (even if not explicitly declared static). |
1964 | return OOK == OO_New || OOK == OO_Array_New || OOK == OO_Delete || |
1965 | OOK == OO_Array_Delete; |
1966 | } |
1967 | |
1968 | bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); } |
1969 | bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); } |
1970 | |
1971 | bool isVirtual() const { |
1972 | CXXMethodDecl *CD = const_cast<CXXMethodDecl*>(this)->getCanonicalDecl(); |
1973 | |
1974 | // Member function is virtual if it is marked explicitly so, or if it is |
1975 | // declared in __interface -- then it is automatically pure virtual. |
1976 | if (CD->isVirtualAsWritten() || CD->isPure()) |
1977 | return true; |
1978 | |
1979 | return CD->size_overridden_methods() != 0; |
1980 | } |
1981 | |
1982 | /// If it's possible to devirtualize a call to this method, return the called |
1983 | /// function. Otherwise, return null. |
1984 | |
1985 | /// \param Base The object on which this virtual function is called. |
1986 | /// \param IsAppleKext True if we are compiling for Apple kext. |
1987 | CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, bool IsAppleKext); |
1988 | |
1989 | const CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, |
1990 | bool IsAppleKext) const { |
1991 | return const_cast<CXXMethodDecl *>(this)->getDevirtualizedMethod( |
1992 | Base, IsAppleKext); |
1993 | } |
1994 | |
1995 | /// Determine whether this is a usual deallocation function (C++ |
1996 | /// [basic.stc.dynamic.deallocation]p2), which is an overloaded delete or |
1997 | /// delete[] operator with a particular signature. Populates \p PreventedBy |
1998 | /// with the declarations of the functions of the same kind if they were the |
1999 | /// reason for this function returning false. This is used by |
2000 | /// Sema::isUsualDeallocationFunction to reconsider the answer based on the |
2001 | /// context. |
2002 | bool isUsualDeallocationFunction( |
2003 | SmallVectorImpl<const FunctionDecl *> &PreventedBy) const; |
2004 | |
2005 | /// Determine whether this is a copy-assignment operator, regardless |
2006 | /// of whether it was declared implicitly or explicitly. |
2007 | bool isCopyAssignmentOperator() const; |
2008 | |
2009 | /// Determine whether this is a move assignment operator. |
2010 | bool isMoveAssignmentOperator() const; |
2011 | |
2012 | CXXMethodDecl *getCanonicalDecl() override { |
2013 | return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); |
2014 | } |
2015 | const CXXMethodDecl *getCanonicalDecl() const { |
2016 | return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl(); |
2017 | } |
2018 | |
2019 | CXXMethodDecl *getMostRecentDecl() { |
2020 | return cast<CXXMethodDecl>( |
2021 | static_cast<FunctionDecl *>(this)->getMostRecentDecl()); |
2022 | } |
2023 | const CXXMethodDecl *getMostRecentDecl() const { |
2024 | return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl(); |
2025 | } |
2026 | |
2027 | void addOverriddenMethod(const CXXMethodDecl *MD); |
2028 | |
2029 | using method_iterator = const CXXMethodDecl *const *; |
2030 | |
2031 | method_iterator begin_overridden_methods() const; |
2032 | method_iterator end_overridden_methods() const; |
2033 | unsigned size_overridden_methods() const; |
2034 | |
2035 | using overridden_method_range = llvm::iterator_range< |
2036 | llvm::TinyPtrVector<const CXXMethodDecl *>::const_iterator>; |
2037 | |
2038 | overridden_method_range overridden_methods() const; |
2039 | |
2040 | /// Return the parent of this method declaration, which |
2041 | /// is the class in which this method is defined. |
2042 | const CXXRecordDecl *getParent() const { |
2043 | return cast<CXXRecordDecl>(FunctionDecl::getParent()); |
2044 | } |
2045 | |
2046 | /// Return the parent of this method declaration, which |
2047 | /// is the class in which this method is defined. |
2048 | CXXRecordDecl *getParent() { |
2049 | return const_cast<CXXRecordDecl *>( |
2050 | cast<CXXRecordDecl>(FunctionDecl::getParent())); |
2051 | } |
2052 | |
2053 | /// Return the type of the \c this pointer. |
2054 | /// |
2055 | /// Should only be called for instance (i.e., non-static) methods. Note |
2056 | /// that for the call operator of a lambda closure type, this returns the |
2057 | /// desugared 'this' type (a pointer to the closure type), not the captured |
2058 | /// 'this' type. |
2059 | QualType getThisType() const; |
2060 | |
2061 | /// Return the type of the object pointed by \c this. |
2062 | /// |
2063 | /// See getThisType() for usage restriction. |
2064 | QualType getThisObjectType() const; |
2065 | |
2066 | static QualType getThisType(const FunctionProtoType *FPT, |
2067 | const CXXRecordDecl *Decl); |
2068 | |
2069 | static QualType getThisObjectType(const FunctionProtoType *FPT, |
2070 | const CXXRecordDecl *Decl); |
2071 | |
2072 | Qualifiers getMethodQualifiers() const { |
2073 | return getType()->castAs<FunctionProtoType>()->getMethodQuals(); |
2074 | } |
2075 | |
2076 | /// Retrieve the ref-qualifier associated with this method. |
2077 | /// |
2078 | /// In the following example, \c f() has an lvalue ref-qualifier, \c g() |
2079 | /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier. |
2080 | /// @code |
2081 | /// struct X { |
2082 | /// void f() &; |
2083 | /// void g() &&; |
2084 | /// void h(); |
2085 | /// }; |
2086 | /// @endcode |
2087 | RefQualifierKind getRefQualifier() const { |
2088 | return getType()->castAs<FunctionProtoType>()->getRefQualifier(); |
2089 | } |
2090 | |
2091 | bool hasInlineBody() const; |
2092 | |
2093 | /// Determine whether this is a lambda closure type's static member |
2094 | /// function that is used for the result of the lambda's conversion to |
2095 | /// function pointer (for a lambda with no captures). |
2096 | /// |
2097 | /// The function itself, if used, will have a placeholder body that will be |
2098 | /// supplied by IR generation to either forward to the function call operator |
2099 | /// or clone the function call operator. |
2100 | bool isLambdaStaticInvoker() const; |
2101 | |
2102 | /// Find the method in \p RD that corresponds to this one. |
2103 | /// |
2104 | /// Find if \p RD or one of the classes it inherits from override this method. |
2105 | /// If so, return it. \p RD is assumed to be a subclass of the class defining |
2106 | /// this method (or be the class itself), unless \p MayBeBase is set to true. |
2107 | CXXMethodDecl * |
2108 | getCorrespondingMethodInClass(const CXXRecordDecl *RD, |
2109 | bool MayBeBase = false); |
2110 | |
2111 | const CXXMethodDecl * |
2112 | getCorrespondingMethodInClass(const CXXRecordDecl *RD, |
2113 | bool MayBeBase = false) const { |
2114 | return const_cast<CXXMethodDecl *>(this) |
2115 | ->getCorrespondingMethodInClass(RD, MayBeBase); |
2116 | } |
2117 | |
2118 | /// Find if \p RD declares a function that overrides this function, and if so, |
2119 | /// return it. Does not search base classes. |
2120 | CXXMethodDecl *getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, |
2121 | bool MayBeBase = false); |
2122 | const CXXMethodDecl * |
2123 | getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, |
2124 | bool MayBeBase = false) const { |
2125 | return const_cast<CXXMethodDecl *>(this) |
2126 | ->getCorrespondingMethodDeclaredInClass(RD, MayBeBase); |
2127 | } |
2128 | |
2129 | // Implement isa/cast/dyncast/etc. |
2130 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2131 | static bool classofKind(Kind K) { |
2132 | return K >= firstCXXMethod && K <= lastCXXMethod; |
2133 | } |
2134 | }; |
2135 | |
2136 | /// Represents a C++ base or member initializer. |
2137 | /// |
2138 | /// This is part of a constructor initializer that |
2139 | /// initializes one non-static member variable or one base class. For |
2140 | /// example, in the following, both 'A(a)' and 'f(3.14159)' are member |
2141 | /// initializers: |
2142 | /// |
2143 | /// \code |
2144 | /// class A { }; |
2145 | /// class B : public A { |
2146 | /// float f; |
2147 | /// public: |
2148 | /// B(A& a) : A(a), f(3.14159) { } |
2149 | /// }; |
2150 | /// \endcode |
2151 | class CXXCtorInitializer final { |
2152 | /// Either the base class name/delegating constructor type (stored as |
2153 | /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field |
2154 | /// (IndirectFieldDecl*) being initialized. |
2155 | llvm::PointerUnion<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *> |
2156 | Initializee; |
2157 | |
2158 | /// The source location for the field name or, for a base initializer |
2159 | /// pack expansion, the location of the ellipsis. |
2160 | /// |
2161 | /// In the case of a delegating |
2162 | /// constructor, it will still include the type's source location as the |
2163 | /// Initializee points to the CXXConstructorDecl (to allow loop detection). |
2164 | SourceLocation MemberOrEllipsisLocation; |
2165 | |
2166 | /// The argument used to initialize the base or member, which may |
2167 | /// end up constructing an object (when multiple arguments are involved). |
2168 | Stmt *Init; |
2169 | |
2170 | /// Location of the left paren of the ctor-initializer. |
2171 | SourceLocation LParenLoc; |
2172 | |
2173 | /// Location of the right paren of the ctor-initializer. |
2174 | SourceLocation RParenLoc; |
2175 | |
2176 | /// If the initializee is a type, whether that type makes this |
2177 | /// a delegating initialization. |
2178 | unsigned IsDelegating : 1; |
2179 | |
2180 | /// If the initializer is a base initializer, this keeps track |
2181 | /// of whether the base is virtual or not. |
2182 | unsigned IsVirtual : 1; |
2183 | |
2184 | /// Whether or not the initializer is explicitly written |
2185 | /// in the sources. |
2186 | unsigned IsWritten : 1; |
2187 | |
2188 | /// If IsWritten is true, then this number keeps track of the textual order |
2189 | /// of this initializer in the original sources, counting from 0. |
2190 | unsigned SourceOrder : 13; |
2191 | |
2192 | public: |
2193 | /// Creates a new base-class initializer. |
2194 | explicit |
2195 | CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual, |
2196 | SourceLocation L, Expr *Init, SourceLocation R, |
2197 | SourceLocation EllipsisLoc); |
2198 | |
2199 | /// Creates a new member initializer. |
2200 | explicit |
2201 | CXXCtorInitializer(ASTContext &Context, FieldDecl *Member, |
2202 | SourceLocation MemberLoc, SourceLocation L, Expr *Init, |
2203 | SourceLocation R); |
2204 | |
2205 | /// Creates a new anonymous field initializer. |
2206 | explicit |
2207 | CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member, |
2208 | SourceLocation MemberLoc, SourceLocation L, Expr *Init, |
2209 | SourceLocation R); |
2210 | |
2211 | /// Creates a new delegating initializer. |
2212 | explicit |
2213 | CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, |
2214 | SourceLocation L, Expr *Init, SourceLocation R); |
2215 | |
2216 | /// \return Unique reproducible object identifier. |
2217 | int64_t getID(const ASTContext &Context) const; |
2218 | |
2219 | /// Determine whether this initializer is initializing a base class. |
2220 | bool isBaseInitializer() const { |
2221 | return Initializee.is<TypeSourceInfo*>() && !IsDelegating; |
2222 | } |
2223 | |
2224 | /// Determine whether this initializer is initializing a non-static |
2225 | /// data member. |
2226 | bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); } |
2227 | |
2228 | bool isAnyMemberInitializer() const { |
2229 | return isMemberInitializer() || isIndirectMemberInitializer(); |
2230 | } |
2231 | |
2232 | bool isIndirectMemberInitializer() const { |
2233 | return Initializee.is<IndirectFieldDecl*>(); |
2234 | } |
2235 | |
2236 | /// Determine whether this initializer is an implicit initializer |
2237 | /// generated for a field with an initializer defined on the member |
2238 | /// declaration. |
2239 | /// |
2240 | /// In-class member initializers (also known as "non-static data member |
2241 | /// initializations", NSDMIs) were introduced in C++11. |
2242 | bool isInClassMemberInitializer() const { |
2243 | return Init->getStmtClass() == Stmt::CXXDefaultInitExprClass; |
2244 | } |
2245 | |
2246 | /// Determine whether this initializer is creating a delegating |
2247 | /// constructor. |
2248 | bool isDelegatingInitializer() const { |
2249 | return Initializee.is<TypeSourceInfo*>() && IsDelegating; |
2250 | } |
2251 | |
2252 | /// Determine whether this initializer is a pack expansion. |
2253 | bool isPackExpansion() const { |
2254 | return isBaseInitializer() && MemberOrEllipsisLocation.isValid(); |
2255 | } |
2256 | |
2257 | // For a pack expansion, returns the location of the ellipsis. |
2258 | SourceLocation getEllipsisLoc() const { |
2259 | assert(isPackExpansion() && "Initializer is not a pack expansion")((isPackExpansion() && "Initializer is not a pack expansion" ) ? static_cast<void> (0) : __assert_fail ("isPackExpansion() && \"Initializer is not a pack expansion\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 2259, __PRETTY_FUNCTION__)); |
2260 | return MemberOrEllipsisLocation; |
2261 | } |
2262 | |
2263 | /// If this is a base class initializer, returns the type of the |
2264 | /// base class with location information. Otherwise, returns an NULL |
2265 | /// type location. |
2266 | TypeLoc getBaseClassLoc() const; |
2267 | |
2268 | /// If this is a base class initializer, returns the type of the base class. |
2269 | /// Otherwise, returns null. |
2270 | const Type *getBaseClass() const; |
2271 | |
2272 | /// Returns whether the base is virtual or not. |
2273 | bool isBaseVirtual() const { |
2274 | assert(isBaseInitializer() && "Must call this on base initializer!")((isBaseInitializer() && "Must call this on base initializer!" ) ? static_cast<void> (0) : __assert_fail ("isBaseInitializer() && \"Must call this on base initializer!\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 2274, __PRETTY_FUNCTION__)); |
2275 | |
2276 | return IsVirtual; |
2277 | } |
2278 | |
2279 | /// Returns the declarator information for a base class or delegating |
2280 | /// initializer. |
2281 | TypeSourceInfo *getTypeSourceInfo() const { |
2282 | return Initializee.dyn_cast<TypeSourceInfo *>(); |
2283 | } |
2284 | |
2285 | /// If this is a member initializer, returns the declaration of the |
2286 | /// non-static data member being initialized. Otherwise, returns null. |
2287 | FieldDecl *getMember() const { |
2288 | if (isMemberInitializer()) |
2289 | return Initializee.get<FieldDecl*>(); |
2290 | return nullptr; |
2291 | } |
2292 | |
2293 | FieldDecl *getAnyMember() const { |
2294 | if (isMemberInitializer()) |
2295 | return Initializee.get<FieldDecl*>(); |
2296 | if (isIndirectMemberInitializer()) |
2297 | return Initializee.get<IndirectFieldDecl*>()->getAnonField(); |
2298 | return nullptr; |
2299 | } |
2300 | |
2301 | IndirectFieldDecl *getIndirectMember() const { |
2302 | if (isIndirectMemberInitializer()) |
2303 | return Initializee.get<IndirectFieldDecl*>(); |
2304 | return nullptr; |
2305 | } |
2306 | |
2307 | SourceLocation getMemberLocation() const { |
2308 | return MemberOrEllipsisLocation; |
2309 | } |
2310 | |
2311 | /// Determine the source location of the initializer. |
2312 | SourceLocation getSourceLocation() const; |
2313 | |
2314 | /// Determine the source range covering the entire initializer. |
2315 | SourceRange getSourceRange() const LLVM_READONLY__attribute__((__pure__)); |
2316 | |
2317 | /// Determine whether this initializer is explicitly written |
2318 | /// in the source code. |
2319 | bool isWritten() const { return IsWritten; } |
2320 | |
2321 | /// Return the source position of the initializer, counting from 0. |
2322 | /// If the initializer was implicit, -1 is returned. |
2323 | int getSourceOrder() const { |
2324 | return IsWritten ? static_cast<int>(SourceOrder) : -1; |
2325 | } |
2326 | |
2327 | /// Set the source order of this initializer. |
2328 | /// |
2329 | /// This can only be called once for each initializer; it cannot be called |
2330 | /// on an initializer having a positive number of (implicit) array indices. |
2331 | /// |
2332 | /// This assumes that the initializer was written in the source code, and |
2333 | /// ensures that isWritten() returns true. |
2334 | void setSourceOrder(int Pos) { |
2335 | assert(!IsWritten &&((!IsWritten && "setSourceOrder() used on implicit initializer" ) ? static_cast<void> (0) : __assert_fail ("!IsWritten && \"setSourceOrder() used on implicit initializer\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 2336, __PRETTY_FUNCTION__)) |
2336 | "setSourceOrder() used on implicit initializer")((!IsWritten && "setSourceOrder() used on implicit initializer" ) ? static_cast<void> (0) : __assert_fail ("!IsWritten && \"setSourceOrder() used on implicit initializer\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 2336, __PRETTY_FUNCTION__)); |
2337 | assert(SourceOrder == 0 &&((SourceOrder == 0 && "calling twice setSourceOrder() on the same initializer" ) ? static_cast<void> (0) : __assert_fail ("SourceOrder == 0 && \"calling twice setSourceOrder() on the same initializer\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 2338, __PRETTY_FUNCTION__)) |
2338 | "calling twice setSourceOrder() on the same initializer")((SourceOrder == 0 && "calling twice setSourceOrder() on the same initializer" ) ? static_cast<void> (0) : __assert_fail ("SourceOrder == 0 && \"calling twice setSourceOrder() on the same initializer\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 2338, __PRETTY_FUNCTION__)); |
2339 | assert(Pos >= 0 &&((Pos >= 0 && "setSourceOrder() used to make an initializer implicit" ) ? static_cast<void> (0) : __assert_fail ("Pos >= 0 && \"setSourceOrder() used to make an initializer implicit\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 2340, __PRETTY_FUNCTION__)) |
2340 | "setSourceOrder() used to make an initializer implicit")((Pos >= 0 && "setSourceOrder() used to make an initializer implicit" ) ? static_cast<void> (0) : __assert_fail ("Pos >= 0 && \"setSourceOrder() used to make an initializer implicit\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 2340, __PRETTY_FUNCTION__)); |
2341 | IsWritten = true; |
2342 | SourceOrder = static_cast<unsigned>(Pos); |
2343 | } |
2344 | |
2345 | SourceLocation getLParenLoc() const { return LParenLoc; } |
2346 | SourceLocation getRParenLoc() const { return RParenLoc; } |
2347 | |
2348 | /// Get the initializer. |
2349 | Expr *getInit() const { return static_cast<Expr *>(Init); } |
2350 | }; |
2351 | |
2352 | /// Description of a constructor that was inherited from a base class. |
2353 | class InheritedConstructor { |
2354 | ConstructorUsingShadowDecl *Shadow = nullptr; |
2355 | CXXConstructorDecl *BaseCtor = nullptr; |
2356 | |
2357 | public: |
2358 | InheritedConstructor() = default; |
2359 | InheritedConstructor(ConstructorUsingShadowDecl *Shadow, |
2360 | CXXConstructorDecl *BaseCtor) |
2361 | : Shadow(Shadow), BaseCtor(BaseCtor) {} |
2362 | |
2363 | explicit operator bool() const { return Shadow; } |
2364 | |
2365 | ConstructorUsingShadowDecl *getShadowDecl() const { return Shadow; } |
2366 | CXXConstructorDecl *getConstructor() const { return BaseCtor; } |
2367 | }; |
2368 | |
2369 | /// Represents a C++ constructor within a class. |
2370 | /// |
2371 | /// For example: |
2372 | /// |
2373 | /// \code |
2374 | /// class X { |
2375 | /// public: |
2376 | /// explicit X(int); // represented by a CXXConstructorDecl. |
2377 | /// }; |
2378 | /// \endcode |
2379 | class CXXConstructorDecl final |
2380 | : public CXXMethodDecl, |
2381 | private llvm::TrailingObjects<CXXConstructorDecl, InheritedConstructor, |
2382 | ExplicitSpecifier> { |
2383 | // This class stores some data in DeclContext::CXXConstructorDeclBits |
2384 | // to save some space. Use the provided accessors to access it. |
2385 | |
2386 | /// \name Support for base and member initializers. |
2387 | /// \{ |
2388 | /// The arguments used to initialize the base or member. |
2389 | LazyCXXCtorInitializersPtr CtorInitializers; |
2390 | |
2391 | CXXConstructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2392 | const DeclarationNameInfo &NameInfo, QualType T, |
2393 | TypeSourceInfo *TInfo, ExplicitSpecifier ES, bool isInline, |
2394 | bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, |
2395 | InheritedConstructor Inherited, |
2396 | Expr *TrailingRequiresClause); |
2397 | |
2398 | void anchor() override; |
2399 | |
2400 | size_t numTrailingObjects(OverloadToken<InheritedConstructor>) const { |
2401 | return CXXConstructorDeclBits.IsInheritingConstructor; |
2402 | } |
2403 | size_t numTrailingObjects(OverloadToken<ExplicitSpecifier>) const { |
2404 | return CXXConstructorDeclBits.HasTrailingExplicitSpecifier; |
2405 | } |
2406 | |
2407 | ExplicitSpecifier getExplicitSpecifierInternal() const { |
2408 | if (CXXConstructorDeclBits.HasTrailingExplicitSpecifier) |
2409 | return *getTrailingObjects<ExplicitSpecifier>(); |
2410 | return ExplicitSpecifier( |
2411 | nullptr, CXXConstructorDeclBits.IsSimpleExplicit |
2412 | ? ExplicitSpecKind::ResolvedTrue |
2413 | : ExplicitSpecKind::ResolvedFalse); |
2414 | } |
2415 | |
2416 | enum TraillingAllocKind { |
2417 | TAKInheritsConstructor = 1, |
2418 | TAKHasTailExplicit = 1 << 1, |
2419 | }; |
2420 | |
2421 | uint64_t getTraillingAllocKind() const { |
2422 | return numTrailingObjects(OverloadToken<InheritedConstructor>()) | |
2423 | (numTrailingObjects(OverloadToken<ExplicitSpecifier>()) << 1); |
2424 | } |
2425 | |
2426 | public: |
2427 | friend class ASTDeclReader; |
2428 | friend class ASTDeclWriter; |
2429 | friend TrailingObjects; |
2430 | |
2431 | static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
2432 | uint64_t AllocKind); |
2433 | static CXXConstructorDecl * |
2434 | Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2435 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2436 | ExplicitSpecifier ES, bool isInline, bool isImplicitlyDeclared, |
2437 | ConstexprSpecKind ConstexprKind, |
2438 | InheritedConstructor Inherited = InheritedConstructor(), |
2439 | Expr *TrailingRequiresClause = nullptr); |
2440 | |
2441 | void setExplicitSpecifier(ExplicitSpecifier ES) { |
2442 | assert((!ES.getExpr() ||(((!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier ) && "cannot set this explicit specifier. no trail-allocated space for " "explicit") ? static_cast<void> (0) : __assert_fail ("(!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && \"cannot set this explicit specifier. no trail-allocated space for \" \"explicit\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 2445, __PRETTY_FUNCTION__)) |
2443 | CXXConstructorDeclBits.HasTrailingExplicitSpecifier) &&(((!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier ) && "cannot set this explicit specifier. no trail-allocated space for " "explicit") ? static_cast<void> (0) : __assert_fail ("(!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && \"cannot set this explicit specifier. no trail-allocated space for \" \"explicit\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 2445, __PRETTY_FUNCTION__)) |
2444 | "cannot set this explicit specifier. no trail-allocated space for "(((!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier ) && "cannot set this explicit specifier. no trail-allocated space for " "explicit") ? static_cast<void> (0) : __assert_fail ("(!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && \"cannot set this explicit specifier. no trail-allocated space for \" \"explicit\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 2445, __PRETTY_FUNCTION__)) |
2445 | "explicit")(((!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier ) && "cannot set this explicit specifier. no trail-allocated space for " "explicit") ? static_cast<void> (0) : __assert_fail ("(!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && \"cannot set this explicit specifier. no trail-allocated space for \" \"explicit\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 2445, __PRETTY_FUNCTION__)); |
2446 | if (ES.getExpr()) |
2447 | *getCanonicalDecl()->getTrailingObjects<ExplicitSpecifier>() = ES; |
2448 | else |
2449 | CXXConstructorDeclBits.IsSimpleExplicit = ES.isExplicit(); |
2450 | } |
2451 | |
2452 | ExplicitSpecifier getExplicitSpecifier() { |
2453 | return getCanonicalDecl()->getExplicitSpecifierInternal(); |
2454 | } |
2455 | const ExplicitSpecifier getExplicitSpecifier() const { |
2456 | return getCanonicalDecl()->getExplicitSpecifierInternal(); |
2457 | } |
2458 | |
2459 | /// Return true if the declartion is already resolved to be explicit. |
2460 | bool isExplicit() const { return getExplicitSpecifier().isExplicit(); } |
2461 | |
2462 | /// Iterates through the member/base initializer list. |
2463 | using init_iterator = CXXCtorInitializer **; |
2464 | |
2465 | /// Iterates through the member/base initializer list. |
2466 | using init_const_iterator = CXXCtorInitializer *const *; |
2467 | |
2468 | using init_range = llvm::iterator_range<init_iterator>; |
2469 | using init_const_range = llvm::iterator_range<init_const_iterator>; |
2470 | |
2471 | init_range inits() { return init_range(init_begin(), init_end()); } |
2472 | init_const_range inits() const { |
2473 | return init_const_range(init_begin(), init_end()); |
2474 | } |
2475 | |
2476 | /// Retrieve an iterator to the first initializer. |
2477 | init_iterator init_begin() { |
2478 | const auto *ConstThis = this; |
2479 | return const_cast<init_iterator>(ConstThis->init_begin()); |
2480 | } |
2481 | |
2482 | /// Retrieve an iterator to the first initializer. |
2483 | init_const_iterator init_begin() const; |
2484 | |
2485 | /// Retrieve an iterator past the last initializer. |
2486 | init_iterator init_end() { |
2487 | return init_begin() + getNumCtorInitializers(); |
2488 | } |
2489 | |
2490 | /// Retrieve an iterator past the last initializer. |
2491 | init_const_iterator init_end() const { |
2492 | return init_begin() + getNumCtorInitializers(); |
2493 | } |
2494 | |
2495 | using init_reverse_iterator = std::reverse_iterator<init_iterator>; |
2496 | using init_const_reverse_iterator = |
2497 | std::reverse_iterator<init_const_iterator>; |
2498 | |
2499 | init_reverse_iterator init_rbegin() { |
2500 | return init_reverse_iterator(init_end()); |
2501 | } |
2502 | init_const_reverse_iterator init_rbegin() const { |
2503 | return init_const_reverse_iterator(init_end()); |
2504 | } |
2505 | |
2506 | init_reverse_iterator init_rend() { |
2507 | return init_reverse_iterator(init_begin()); |
2508 | } |
2509 | init_const_reverse_iterator init_rend() const { |
2510 | return init_const_reverse_iterator(init_begin()); |
2511 | } |
2512 | |
2513 | /// Determine the number of arguments used to initialize the member |
2514 | /// or base. |
2515 | unsigned getNumCtorInitializers() const { |
2516 | return CXXConstructorDeclBits.NumCtorInitializers; |
2517 | } |
2518 | |
2519 | void setNumCtorInitializers(unsigned numCtorInitializers) { |
2520 | CXXConstructorDeclBits.NumCtorInitializers = numCtorInitializers; |
2521 | // This assert added because NumCtorInitializers is stored |
2522 | // in CXXConstructorDeclBits as a bitfield and its width has |
2523 | // been shrunk from 32 bits to fit into CXXConstructorDeclBitfields. |
2524 | assert(CXXConstructorDeclBits.NumCtorInitializers ==((CXXConstructorDeclBits.NumCtorInitializers == numCtorInitializers && "NumCtorInitializers overflow!") ? static_cast< void> (0) : __assert_fail ("CXXConstructorDeclBits.NumCtorInitializers == numCtorInitializers && \"NumCtorInitializers overflow!\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 2525, __PRETTY_FUNCTION__)) |
2525 | numCtorInitializers && "NumCtorInitializers overflow!")((CXXConstructorDeclBits.NumCtorInitializers == numCtorInitializers && "NumCtorInitializers overflow!") ? static_cast< void> (0) : __assert_fail ("CXXConstructorDeclBits.NumCtorInitializers == numCtorInitializers && \"NumCtorInitializers overflow!\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 2525, __PRETTY_FUNCTION__)); |
2526 | } |
2527 | |
2528 | void setCtorInitializers(CXXCtorInitializer **Initializers) { |
2529 | CtorInitializers = Initializers; |
2530 | } |
2531 | |
2532 | /// Determine whether this constructor is a delegating constructor. |
2533 | bool isDelegatingConstructor() const { |
2534 | return (getNumCtorInitializers() == 1) && |
2535 | init_begin()[0]->isDelegatingInitializer(); |
2536 | } |
2537 | |
2538 | /// When this constructor delegates to another, retrieve the target. |
2539 | CXXConstructorDecl *getTargetConstructor() const; |
2540 | |
2541 | /// Whether this constructor is a default |
2542 | /// constructor (C++ [class.ctor]p5), which can be used to |
2543 | /// default-initialize a class of this type. |
2544 | bool isDefaultConstructor() const; |
2545 | |
2546 | /// Whether this constructor is a copy constructor (C++ [class.copy]p2, |
2547 | /// which can be used to copy the class. |
2548 | /// |
2549 | /// \p TypeQuals will be set to the qualifiers on the |
2550 | /// argument type. For example, \p TypeQuals would be set to \c |
2551 | /// Qualifiers::Const for the following copy constructor: |
2552 | /// |
2553 | /// \code |
2554 | /// class X { |
2555 | /// public: |
2556 | /// X(const X&); |
2557 | /// }; |
2558 | /// \endcode |
2559 | bool isCopyConstructor(unsigned &TypeQuals) const; |
2560 | |
2561 | /// Whether this constructor is a copy |
2562 | /// constructor (C++ [class.copy]p2, which can be used to copy the |
2563 | /// class. |
2564 | bool isCopyConstructor() const { |
2565 | unsigned TypeQuals = 0; |
2566 | return isCopyConstructor(TypeQuals); |
2567 | } |
2568 | |
2569 | /// Determine whether this constructor is a move constructor |
2570 | /// (C++11 [class.copy]p3), which can be used to move values of the class. |
2571 | /// |
2572 | /// \param TypeQuals If this constructor is a move constructor, will be set |
2573 | /// to the type qualifiers on the referent of the first parameter's type. |
2574 | bool isMoveConstructor(unsigned &TypeQuals) const; |
2575 | |
2576 | /// Determine whether this constructor is a move constructor |
2577 | /// (C++11 [class.copy]p3), which can be used to move values of the class. |
2578 | bool isMoveConstructor() const { |
2579 | unsigned TypeQuals = 0; |
2580 | return isMoveConstructor(TypeQuals); |
2581 | } |
2582 | |
2583 | /// Determine whether this is a copy or move constructor. |
2584 | /// |
2585 | /// \param TypeQuals Will be set to the type qualifiers on the reference |
2586 | /// parameter, if in fact this is a copy or move constructor. |
2587 | bool isCopyOrMoveConstructor(unsigned &TypeQuals) const; |
2588 | |
2589 | /// Determine whether this a copy or move constructor. |
2590 | bool isCopyOrMoveConstructor() const { |
2591 | unsigned Quals; |
2592 | return isCopyOrMoveConstructor(Quals); |
2593 | } |
2594 | |
2595 | /// Whether this constructor is a |
2596 | /// converting constructor (C++ [class.conv.ctor]), which can be |
2597 | /// used for user-defined conversions. |
2598 | bool isConvertingConstructor(bool AllowExplicit) const; |
2599 | |
2600 | /// Determine whether this is a member template specialization that |
2601 | /// would copy the object to itself. Such constructors are never used to copy |
2602 | /// an object. |
2603 | bool isSpecializationCopyingObject() const; |
2604 | |
2605 | /// Determine whether this is an implicit constructor synthesized to |
2606 | /// model a call to a constructor inherited from a base class. |
2607 | bool isInheritingConstructor() const { |
2608 | return CXXConstructorDeclBits.IsInheritingConstructor; |
2609 | } |
2610 | |
2611 | /// State that this is an implicit constructor synthesized to |
2612 | /// model a call to a constructor inherited from a base class. |
2613 | void setInheritingConstructor(bool isIC = true) { |
2614 | CXXConstructorDeclBits.IsInheritingConstructor = isIC; |
2615 | } |
2616 | |
2617 | /// Get the constructor that this inheriting constructor is based on. |
2618 | InheritedConstructor getInheritedConstructor() const { |
2619 | return isInheritingConstructor() ? |
2620 | *getTrailingObjects<InheritedConstructor>() : InheritedConstructor(); |
2621 | } |
2622 | |
2623 | CXXConstructorDecl *getCanonicalDecl() override { |
2624 | return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl()); |
2625 | } |
2626 | const CXXConstructorDecl *getCanonicalDecl() const { |
2627 | return const_cast<CXXConstructorDecl*>(this)->getCanonicalDecl(); |
2628 | } |
2629 | |
2630 | // Implement isa/cast/dyncast/etc. |
2631 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2632 | static bool classofKind(Kind K) { return K == CXXConstructor; } |
2633 | }; |
2634 | |
2635 | /// Represents a C++ destructor within a class. |
2636 | /// |
2637 | /// For example: |
2638 | /// |
2639 | /// \code |
2640 | /// class X { |
2641 | /// public: |
2642 | /// ~X(); // represented by a CXXDestructorDecl. |
2643 | /// }; |
2644 | /// \endcode |
2645 | class CXXDestructorDecl : public CXXMethodDecl { |
2646 | friend class ASTDeclReader; |
2647 | friend class ASTDeclWriter; |
2648 | |
2649 | // FIXME: Don't allocate storage for these except in the first declaration |
2650 | // of a virtual destructor. |
2651 | FunctionDecl *OperatorDelete = nullptr; |
2652 | Expr *OperatorDeleteThisArg = nullptr; |
2653 | |
2654 | CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2655 | const DeclarationNameInfo &NameInfo, QualType T, |
2656 | TypeSourceInfo *TInfo, bool isInline, |
2657 | bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, |
2658 | Expr *TrailingRequiresClause = nullptr) |
2659 | : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo, |
2660 | SC_None, isInline, ConstexprKind, SourceLocation(), |
2661 | TrailingRequiresClause) { |
2662 | setImplicit(isImplicitlyDeclared); |
2663 | } |
2664 | |
2665 | void anchor() override; |
2666 | |
2667 | public: |
2668 | static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, |
2669 | SourceLocation StartLoc, |
2670 | const DeclarationNameInfo &NameInfo, |
2671 | QualType T, TypeSourceInfo *TInfo, |
2672 | bool isInline, bool isImplicitlyDeclared, |
2673 | ConstexprSpecKind ConstexprKind, |
2674 | Expr *TrailingRequiresClause = nullptr); |
2675 | static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID); |
2676 | |
2677 | void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg); |
2678 | |
2679 | const FunctionDecl *getOperatorDelete() const { |
2680 | return getCanonicalDecl()->OperatorDelete; |
2681 | } |
2682 | |
2683 | Expr *getOperatorDeleteThisArg() const { |
2684 | return getCanonicalDecl()->OperatorDeleteThisArg; |
2685 | } |
2686 | |
2687 | CXXDestructorDecl *getCanonicalDecl() override { |
2688 | return cast<CXXDestructorDecl>(FunctionDecl::getCanonicalDecl()); |
2689 | } |
2690 | const CXXDestructorDecl *getCanonicalDecl() const { |
2691 | return const_cast<CXXDestructorDecl*>(this)->getCanonicalDecl(); |
2692 | } |
2693 | |
2694 | // Implement isa/cast/dyncast/etc. |
2695 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2696 | static bool classofKind(Kind K) { return K == CXXDestructor; } |
2697 | }; |
2698 | |
2699 | /// Represents a C++ conversion function within a class. |
2700 | /// |
2701 | /// For example: |
2702 | /// |
2703 | /// \code |
2704 | /// class X { |
2705 | /// public: |
2706 | /// operator bool(); |
2707 | /// }; |
2708 | /// \endcode |
2709 | class CXXConversionDecl : public CXXMethodDecl { |
2710 | CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2711 | const DeclarationNameInfo &NameInfo, QualType T, |
2712 | TypeSourceInfo *TInfo, bool isInline, ExplicitSpecifier ES, |
2713 | ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, |
2714 | Expr *TrailingRequiresClause = nullptr) |
2715 | : CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo, |
2716 | SC_None, isInline, ConstexprKind, EndLocation, |
2717 | TrailingRequiresClause), |
2718 | ExplicitSpec(ES) {} |
2719 | void anchor() override; |
2720 | |
2721 | ExplicitSpecifier ExplicitSpec; |
2722 | |
2723 | public: |
2724 | friend class ASTDeclReader; |
2725 | friend class ASTDeclWriter; |
2726 | |
2727 | static CXXConversionDecl * |
2728 | Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2729 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2730 | bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind, |
2731 | SourceLocation EndLocation, Expr *TrailingRequiresClause = nullptr); |
2732 | static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2733 | |
2734 | ExplicitSpecifier getExplicitSpecifier() { |
2735 | return getCanonicalDecl()->ExplicitSpec; |
2736 | } |
2737 | |
2738 | const ExplicitSpecifier getExplicitSpecifier() const { |
2739 | return getCanonicalDecl()->ExplicitSpec; |
2740 | } |
2741 | |
2742 | /// Return true if the declartion is already resolved to be explicit. |
2743 | bool isExplicit() const { return getExplicitSpecifier().isExplicit(); } |
2744 | void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; } |
2745 | |
2746 | /// Returns the type that this conversion function is converting to. |
2747 | QualType getConversionType() const { |
2748 | return getType()->castAs<FunctionType>()->getReturnType(); |
2749 | } |
2750 | |
2751 | /// Determine whether this conversion function is a conversion from |
2752 | /// a lambda closure type to a block pointer. |
2753 | bool isLambdaToBlockPointerConversion() const; |
2754 | |
2755 | CXXConversionDecl *getCanonicalDecl() override { |
2756 | return cast<CXXConversionDecl>(FunctionDecl::getCanonicalDecl()); |
2757 | } |
2758 | const CXXConversionDecl *getCanonicalDecl() const { |
2759 | return const_cast<CXXConversionDecl*>(this)->getCanonicalDecl(); |
2760 | } |
2761 | |
2762 | // Implement isa/cast/dyncast/etc. |
2763 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2764 | static bool classofKind(Kind K) { return K == CXXConversion; } |
2765 | }; |
2766 | |
2767 | /// Represents a linkage specification. |
2768 | /// |
2769 | /// For example: |
2770 | /// \code |
2771 | /// extern "C" void foo(); |
2772 | /// \endcode |
2773 | class LinkageSpecDecl : public Decl, public DeclContext { |
2774 | virtual void anchor(); |
2775 | // This class stores some data in DeclContext::LinkageSpecDeclBits to save |
2776 | // some space. Use the provided accessors to access it. |
2777 | public: |
2778 | /// Represents the language in a linkage specification. |
2779 | /// |
2780 | /// The values are part of the serialization ABI for |
2781 | /// ASTs and cannot be changed without altering that ABI. |
2782 | enum LanguageIDs { lang_c = 1, lang_cxx = 2 }; |
2783 | |
2784 | private: |
2785 | /// The source location for the extern keyword. |
2786 | SourceLocation ExternLoc; |
2787 | |
2788 | /// The source location for the right brace (if valid). |
2789 | SourceLocation RBraceLoc; |
2790 | |
2791 | LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc, |
2792 | SourceLocation LangLoc, LanguageIDs lang, bool HasBraces); |
2793 | |
2794 | public: |
2795 | static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, |
2796 | SourceLocation ExternLoc, |
2797 | SourceLocation LangLoc, LanguageIDs Lang, |
2798 | bool HasBraces); |
2799 | static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2800 | |
2801 | /// Return the language specified by this linkage specification. |
2802 | LanguageIDs getLanguage() const { |
2803 | return static_cast<LanguageIDs>(LinkageSpecDeclBits.Language); |
2804 | } |
2805 | |
2806 | /// Set the language specified by this linkage specification. |
2807 | void setLanguage(LanguageIDs L) { LinkageSpecDeclBits.Language = L; } |
2808 | |
2809 | /// Determines whether this linkage specification had braces in |
2810 | /// its syntactic form. |
2811 | bool hasBraces() const { |
2812 | assert(!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces)((!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces) ? static_cast <void> (0) : __assert_fail ("!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 2812, __PRETTY_FUNCTION__)); |
2813 | return LinkageSpecDeclBits.HasBraces; |
2814 | } |
2815 | |
2816 | SourceLocation getExternLoc() const { return ExternLoc; } |
2817 | SourceLocation getRBraceLoc() const { return RBraceLoc; } |
2818 | void setExternLoc(SourceLocation L) { ExternLoc = L; } |
2819 | void setRBraceLoc(SourceLocation L) { |
2820 | RBraceLoc = L; |
2821 | LinkageSpecDeclBits.HasBraces = RBraceLoc.isValid(); |
2822 | } |
2823 | |
2824 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { |
2825 | if (hasBraces()) |
2826 | return getRBraceLoc(); |
2827 | // No braces: get the end location of the (only) declaration in context |
2828 | // (if present). |
2829 | return decls_empty() ? getLocation() : decls_begin()->getEndLoc(); |
2830 | } |
2831 | |
2832 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
2833 | return SourceRange(ExternLoc, getEndLoc()); |
2834 | } |
2835 | |
2836 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2837 | static bool classofKind(Kind K) { return K == LinkageSpec; } |
2838 | |
2839 | static DeclContext *castToDeclContext(const LinkageSpecDecl *D) { |
2840 | return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D)); |
2841 | } |
2842 | |
2843 | static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) { |
2844 | return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC)); |
2845 | } |
2846 | }; |
2847 | |
2848 | /// Represents C++ using-directive. |
2849 | /// |
2850 | /// For example: |
2851 | /// \code |
2852 | /// using namespace std; |
2853 | /// \endcode |
2854 | /// |
2855 | /// \note UsingDirectiveDecl should be Decl not NamedDecl, but we provide |
2856 | /// artificial names for all using-directives in order to store |
2857 | /// them in DeclContext effectively. |
2858 | class UsingDirectiveDecl : public NamedDecl { |
2859 | /// The location of the \c using keyword. |
2860 | SourceLocation UsingLoc; |
2861 | |
2862 | /// The location of the \c namespace keyword. |
2863 | SourceLocation NamespaceLoc; |
2864 | |
2865 | /// The nested-name-specifier that precedes the namespace. |
2866 | NestedNameSpecifierLoc QualifierLoc; |
2867 | |
2868 | /// The namespace nominated by this using-directive. |
2869 | NamedDecl *NominatedNamespace; |
2870 | |
2871 | /// Enclosing context containing both using-directive and nominated |
2872 | /// namespace. |
2873 | DeclContext *CommonAncestor; |
2874 | |
2875 | UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc, |
2876 | SourceLocation NamespcLoc, |
2877 | NestedNameSpecifierLoc QualifierLoc, |
2878 | SourceLocation IdentLoc, |
2879 | NamedDecl *Nominated, |
2880 | DeclContext *CommonAncestor) |
2881 | : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc), |
2882 | NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc), |
2883 | NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) {} |
2884 | |
2885 | /// Returns special DeclarationName used by using-directives. |
2886 | /// |
2887 | /// This is only used by DeclContext for storing UsingDirectiveDecls in |
2888 | /// its lookup structure. |
2889 | static DeclarationName getName() { |
2890 | return DeclarationName::getUsingDirectiveName(); |
2891 | } |
2892 | |
2893 | void anchor() override; |
2894 | |
2895 | public: |
2896 | friend class ASTDeclReader; |
2897 | |
2898 | // Friend for getUsingDirectiveName. |
2899 | friend class DeclContext; |
2900 | |
2901 | /// Retrieve the nested-name-specifier that qualifies the |
2902 | /// name of the namespace, with source-location information. |
2903 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
2904 | |
2905 | /// Retrieve the nested-name-specifier that qualifies the |
2906 | /// name of the namespace. |
2907 | NestedNameSpecifier *getQualifier() const { |
2908 | return QualifierLoc.getNestedNameSpecifier(); |
2909 | } |
2910 | |
2911 | NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; } |
2912 | const NamedDecl *getNominatedNamespaceAsWritten() const { |
2913 | return NominatedNamespace; |
2914 | } |
2915 | |
2916 | /// Returns the namespace nominated by this using-directive. |
2917 | NamespaceDecl *getNominatedNamespace(); |
2918 | |
2919 | const NamespaceDecl *getNominatedNamespace() const { |
2920 | return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace(); |
2921 | } |
2922 | |
2923 | /// Returns the common ancestor context of this using-directive and |
2924 | /// its nominated namespace. |
2925 | DeclContext *getCommonAncestor() { return CommonAncestor; } |
2926 | const DeclContext *getCommonAncestor() const { return CommonAncestor; } |
2927 | |
2928 | /// Return the location of the \c using keyword. |
2929 | SourceLocation getUsingLoc() const { return UsingLoc; } |
2930 | |
2931 | // FIXME: Could omit 'Key' in name. |
2932 | /// Returns the location of the \c namespace keyword. |
2933 | SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; } |
2934 | |
2935 | /// Returns the location of this using declaration's identifier. |
2936 | SourceLocation getIdentLocation() const { return getLocation(); } |
2937 | |
2938 | static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC, |
2939 | SourceLocation UsingLoc, |
2940 | SourceLocation NamespaceLoc, |
2941 | NestedNameSpecifierLoc QualifierLoc, |
2942 | SourceLocation IdentLoc, |
2943 | NamedDecl *Nominated, |
2944 | DeclContext *CommonAncestor); |
2945 | static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2946 | |
2947 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
2948 | return SourceRange(UsingLoc, getLocation()); |
2949 | } |
2950 | |
2951 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2952 | static bool classofKind(Kind K) { return K == UsingDirective; } |
2953 | }; |
2954 | |
2955 | /// Represents a C++ namespace alias. |
2956 | /// |
2957 | /// For example: |
2958 | /// |
2959 | /// \code |
2960 | /// namespace Foo = Bar; |
2961 | /// \endcode |
2962 | class NamespaceAliasDecl : public NamedDecl, |
2963 | public Redeclarable<NamespaceAliasDecl> { |
2964 | friend class ASTDeclReader; |
2965 | |
2966 | /// The location of the \c namespace keyword. |
2967 | SourceLocation NamespaceLoc; |
2968 | |
2969 | /// The location of the namespace's identifier. |
2970 | /// |
2971 | /// This is accessed by TargetNameLoc. |
2972 | SourceLocation IdentLoc; |
2973 | |
2974 | /// The nested-name-specifier that precedes the namespace. |
2975 | NestedNameSpecifierLoc QualifierLoc; |
2976 | |
2977 | /// The Decl that this alias points to, either a NamespaceDecl or |
2978 | /// a NamespaceAliasDecl. |
2979 | NamedDecl *Namespace; |
2980 | |
2981 | NamespaceAliasDecl(ASTContext &C, DeclContext *DC, |
2982 | SourceLocation NamespaceLoc, SourceLocation AliasLoc, |
2983 | IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc, |
2984 | SourceLocation IdentLoc, NamedDecl *Namespace) |
2985 | : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), redeclarable_base(C), |
2986 | NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc), |
2987 | QualifierLoc(QualifierLoc), Namespace(Namespace) {} |
2988 | |
2989 | void anchor() override; |
2990 | |
2991 | using redeclarable_base = Redeclarable<NamespaceAliasDecl>; |
2992 | |
2993 | NamespaceAliasDecl *getNextRedeclarationImpl() override; |
2994 | NamespaceAliasDecl *getPreviousDeclImpl() override; |
2995 | NamespaceAliasDecl *getMostRecentDeclImpl() override; |
2996 | |
2997 | public: |
2998 | static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, |
2999 | SourceLocation NamespaceLoc, |
3000 | SourceLocation AliasLoc, |
3001 | IdentifierInfo *Alias, |
3002 | NestedNameSpecifierLoc QualifierLoc, |
3003 | SourceLocation IdentLoc, |
3004 | NamedDecl *Namespace); |
3005 | |
3006 | static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3007 | |
3008 | using redecl_range = redeclarable_base::redecl_range; |
3009 | using redecl_iterator = redeclarable_base::redecl_iterator; |
3010 | |
3011 | using redeclarable_base::redecls_begin; |
3012 | using redeclarable_base::redecls_end; |
3013 | using redeclarable_base::redecls; |
3014 | using redeclarable_base::getPreviousDecl; |
3015 | using redeclarable_base::getMostRecentDecl; |
3016 | |
3017 | NamespaceAliasDecl *getCanonicalDecl() override { |
3018 | return getFirstDecl(); |
3019 | } |
3020 | const NamespaceAliasDecl *getCanonicalDecl() const { |
3021 | return getFirstDecl(); |
3022 | } |
3023 | |
3024 | /// Retrieve the nested-name-specifier that qualifies the |
3025 | /// name of the namespace, with source-location information. |
3026 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3027 | |
3028 | /// Retrieve the nested-name-specifier that qualifies the |
3029 | /// name of the namespace. |
3030 | NestedNameSpecifier *getQualifier() const { |
3031 | return QualifierLoc.getNestedNameSpecifier(); |
3032 | } |
3033 | |
3034 | /// Retrieve the namespace declaration aliased by this directive. |
3035 | NamespaceDecl *getNamespace() { |
3036 | if (auto *AD = dyn_cast<NamespaceAliasDecl>(Namespace)) |
3037 | return AD->getNamespace(); |
3038 | |
3039 | return cast<NamespaceDecl>(Namespace); |
3040 | } |
3041 | |
3042 | const NamespaceDecl *getNamespace() const { |
3043 | return const_cast<NamespaceAliasDecl *>(this)->getNamespace(); |
3044 | } |
3045 | |
3046 | /// Returns the location of the alias name, i.e. 'foo' in |
3047 | /// "namespace foo = ns::bar;". |
3048 | SourceLocation getAliasLoc() const { return getLocation(); } |
3049 | |
3050 | /// Returns the location of the \c namespace keyword. |
3051 | SourceLocation getNamespaceLoc() const { return NamespaceLoc; } |
3052 | |
3053 | /// Returns the location of the identifier in the named namespace. |
3054 | SourceLocation getTargetNameLoc() const { return IdentLoc; } |
3055 | |
3056 | /// Retrieve the namespace that this alias refers to, which |
3057 | /// may either be a NamespaceDecl or a NamespaceAliasDecl. |
3058 | NamedDecl *getAliasedNamespace() const { return Namespace; } |
3059 | |
3060 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
3061 | return SourceRange(NamespaceLoc, IdentLoc); |
3062 | } |
3063 | |
3064 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3065 | static bool classofKind(Kind K) { return K == NamespaceAlias; } |
3066 | }; |
3067 | |
3068 | /// Implicit declaration of a temporary that was materialized by |
3069 | /// a MaterializeTemporaryExpr and lifetime-extended by a declaration |
3070 | class LifetimeExtendedTemporaryDecl final |
3071 | : public Decl, |
3072 | public Mergeable<LifetimeExtendedTemporaryDecl> { |
3073 | friend class MaterializeTemporaryExpr; |
3074 | friend class ASTDeclReader; |
3075 | |
3076 | Stmt *ExprWithTemporary = nullptr; |
3077 | |
3078 | /// The declaration which lifetime-extended this reference, if any. |
3079 | /// Either a VarDecl, or (for a ctor-initializer) a FieldDecl. |
3080 | ValueDecl *ExtendingDecl = nullptr; |
3081 | unsigned ManglingNumber; |
3082 | |
3083 | mutable APValue *Value = nullptr; |
3084 | |
3085 | virtual void anchor(); |
3086 | |
3087 | LifetimeExtendedTemporaryDecl(Expr *Temp, ValueDecl *EDecl, unsigned Mangling) |
3088 | : Decl(Decl::LifetimeExtendedTemporary, EDecl->getDeclContext(), |
3089 | EDecl->getLocation()), |
3090 | ExprWithTemporary(Temp), ExtendingDecl(EDecl), |
3091 | ManglingNumber(Mangling) {} |
3092 | |
3093 | LifetimeExtendedTemporaryDecl(EmptyShell) |
3094 | : Decl(Decl::LifetimeExtendedTemporary, EmptyShell{}) {} |
3095 | |
3096 | public: |
3097 | static LifetimeExtendedTemporaryDecl *Create(Expr *Temp, ValueDecl *EDec, |
3098 | unsigned Mangling) { |
3099 | return new (EDec->getASTContext(), EDec->getDeclContext()) |
3100 | LifetimeExtendedTemporaryDecl(Temp, EDec, Mangling); |
3101 | } |
3102 | static LifetimeExtendedTemporaryDecl *CreateDeserialized(ASTContext &C, |
3103 | unsigned ID) { |
3104 | return new (C, ID) LifetimeExtendedTemporaryDecl(EmptyShell{}); |
3105 | } |
3106 | |
3107 | ValueDecl *getExtendingDecl() { return ExtendingDecl; } |
3108 | const ValueDecl *getExtendingDecl() const { return ExtendingDecl; } |
3109 | |
3110 | /// Retrieve the storage duration for the materialized temporary. |
3111 | StorageDuration getStorageDuration() const; |
3112 | |
3113 | /// Retrieve the expression to which the temporary materialization conversion |
3114 | /// was applied. This isn't necessarily the initializer of the temporary due |
3115 | /// to the C++98 delayed materialization rules, but |
3116 | /// skipRValueSubobjectAdjustments can be used to find said initializer within |
3117 | /// the subexpression. |
3118 | Expr *getTemporaryExpr() { return cast<Expr>(ExprWithTemporary); } |
3119 | const Expr *getTemporaryExpr() const { return cast<Expr>(ExprWithTemporary); } |
3120 | |
3121 | unsigned getManglingNumber() const { return ManglingNumber; } |
3122 | |
3123 | /// Get the storage for the constant value of a materialized temporary |
3124 | /// of static storage duration. |
3125 | APValue *getOrCreateValue(bool MayCreate) const; |
3126 | |
3127 | APValue *getValue() const { return Value; } |
3128 | |
3129 | // Iterators |
3130 | Stmt::child_range childrenExpr() { |
3131 | return Stmt::child_range(&ExprWithTemporary, &ExprWithTemporary + 1); |
3132 | } |
3133 | |
3134 | Stmt::const_child_range childrenExpr() const { |
3135 | return Stmt::const_child_range(&ExprWithTemporary, &ExprWithTemporary + 1); |
3136 | } |
3137 | |
3138 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3139 | static bool classofKind(Kind K) { |
3140 | return K == Decl::LifetimeExtendedTemporary; |
3141 | } |
3142 | }; |
3143 | |
3144 | /// Represents a shadow declaration introduced into a scope by a |
3145 | /// (resolved) using declaration. |
3146 | /// |
3147 | /// For example, |
3148 | /// \code |
3149 | /// namespace A { |
3150 | /// void foo(); |
3151 | /// } |
3152 | /// namespace B { |
3153 | /// using A::foo; // <- a UsingDecl |
3154 | /// // Also creates a UsingShadowDecl for A::foo() in B |
3155 | /// } |
3156 | /// \endcode |
3157 | class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> { |
3158 | friend class UsingDecl; |
3159 | |
3160 | /// The referenced declaration. |
3161 | NamedDecl *Underlying = nullptr; |
3162 | |
3163 | /// The using declaration which introduced this decl or the next using |
3164 | /// shadow declaration contained in the aforementioned using declaration. |
3165 | NamedDecl *UsingOrNextShadow = nullptr; |
3166 | |
3167 | void anchor() override; |
3168 | |
3169 | using redeclarable_base = Redeclarable<UsingShadowDecl>; |
3170 | |
3171 | UsingShadowDecl *getNextRedeclarationImpl() override { |
3172 | return getNextRedeclaration(); |
3173 | } |
3174 | |
3175 | UsingShadowDecl *getPreviousDeclImpl() override { |
3176 | return getPreviousDecl(); |
3177 | } |
3178 | |
3179 | UsingShadowDecl *getMostRecentDeclImpl() override { |
3180 | return getMostRecentDecl(); |
3181 | } |
3182 | |
3183 | protected: |
3184 | UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, SourceLocation Loc, |
3185 | UsingDecl *Using, NamedDecl *Target); |
3186 | UsingShadowDecl(Kind K, ASTContext &C, EmptyShell); |
3187 | |
3188 | public: |
3189 | friend class ASTDeclReader; |
3190 | friend class ASTDeclWriter; |
3191 | |
3192 | static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC, |
3193 | SourceLocation Loc, UsingDecl *Using, |
3194 | NamedDecl *Target) { |
3195 | return new (C, DC) UsingShadowDecl(UsingShadow, C, DC, Loc, Using, Target); |
3196 | } |
3197 | |
3198 | static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3199 | |
3200 | using redecl_range = redeclarable_base::redecl_range; |
3201 | using redecl_iterator = redeclarable_base::redecl_iterator; |
3202 | |
3203 | using redeclarable_base::redecls_begin; |
3204 | using redeclarable_base::redecls_end; |
3205 | using redeclarable_base::redecls; |
3206 | using redeclarable_base::getPreviousDecl; |
3207 | using redeclarable_base::getMostRecentDecl; |
3208 | using redeclarable_base::isFirstDecl; |
3209 | |
3210 | UsingShadowDecl *getCanonicalDecl() override { |
3211 | return getFirstDecl(); |
3212 | } |
3213 | const UsingShadowDecl *getCanonicalDecl() const { |
3214 | return getFirstDecl(); |
3215 | } |
3216 | |
3217 | /// Gets the underlying declaration which has been brought into the |
3218 | /// local scope. |
3219 | NamedDecl *getTargetDecl() const { return Underlying; } |
3220 | |
3221 | /// Sets the underlying declaration which has been brought into the |
3222 | /// local scope. |
3223 | void setTargetDecl(NamedDecl *ND) { |
3224 | assert(ND && "Target decl is null!")((ND && "Target decl is null!") ? static_cast<void > (0) : __assert_fail ("ND && \"Target decl is null!\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/DeclCXX.h" , 3224, __PRETTY_FUNCTION__)); |
3225 | Underlying = ND; |
3226 | // A UsingShadowDecl is never a friend or local extern declaration, even |
3227 | // if it is a shadow declaration for one. |
3228 | IdentifierNamespace = |
3229 | ND->getIdentifierNamespace() & |
3230 | ~(IDNS_OrdinaryFriend | IDNS_TagFriend | IDNS_LocalExtern); |
3231 | } |
3232 | |
3233 | /// Gets the using declaration to which this declaration is tied. |
3234 | UsingDecl *getUsingDecl() const; |
3235 | |
3236 | /// The next using shadow declaration contained in the shadow decl |
3237 | /// chain of the using declaration which introduced this decl. |
3238 | UsingShadowDecl *getNextUsingShadowDecl() const { |
3239 | return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow); |
3240 | } |
3241 | |
3242 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3243 | static bool classofKind(Kind K) { |
3244 | return K == Decl::UsingShadow || K == Decl::ConstructorUsingShadow; |
3245 | } |
3246 | }; |
3247 | |
3248 | /// Represents a shadow constructor declaration introduced into a |
3249 | /// class by a C++11 using-declaration that names a constructor. |
3250 | /// |
3251 | /// For example: |
3252 | /// \code |
3253 | /// struct Base { Base(int); }; |
3254 | /// struct Derived { |
3255 | /// using Base::Base; // creates a UsingDecl and a ConstructorUsingShadowDecl |
3256 | /// }; |
3257 | /// \endcode |
3258 | class ConstructorUsingShadowDecl final : public UsingShadowDecl { |
3259 | /// If this constructor using declaration inherted the constructor |
3260 | /// from an indirect base class, this is the ConstructorUsingShadowDecl |
3261 | /// in the named direct base class from which the declaration was inherited. |
3262 | ConstructorUsingShadowDecl *NominatedBaseClassShadowDecl = nullptr; |
3263 | |
3264 | /// If this constructor using declaration inherted the constructor |
3265 | /// from an indirect base class, this is the ConstructorUsingShadowDecl |
3266 | /// that will be used to construct the unique direct or virtual base class |
3267 | /// that receives the constructor arguments. |
3268 | ConstructorUsingShadowDecl *ConstructedBaseClassShadowDecl = nullptr; |
3269 | |
3270 | /// \c true if the constructor ultimately named by this using shadow |
3271 | /// declaration is within a virtual base class subobject of the class that |
3272 | /// contains this declaration. |
3273 | unsigned IsVirtual : 1; |
3274 | |
3275 | ConstructorUsingShadowDecl(ASTContext &C, DeclContext *DC, SourceLocation Loc, |
3276 | UsingDecl *Using, NamedDecl *Target, |
3277 | bool TargetInVirtualBase) |
3278 | : UsingShadowDecl(ConstructorUsingShadow, C, DC, Loc, Using, |
3279 | Target->getUnderlyingDecl()), |
3280 | NominatedBaseClassShadowDecl( |
3281 | dyn_cast<ConstructorUsingShadowDecl>(Target)), |
3282 | ConstructedBaseClassShadowDecl(NominatedBaseClassShadowDecl), |
3283 | IsVirtual(TargetInVirtualBase) { |
3284 | // If we found a constructor that chains to a constructor for a virtual |
3285 | // base, we should directly call that virtual base constructor instead. |
3286 | // FIXME: This logic belongs in Sema. |
3287 | if (NominatedBaseClassShadowDecl && |
3288 | NominatedBaseClassShadowDecl->constructsVirtualBase()) { |
3289 | ConstructedBaseClassShadowDecl = |
3290 | NominatedBaseClassShadowDecl->ConstructedBaseClassShadowDecl; |
3291 | IsVirtual = true; |
3292 | } |
3293 | } |
3294 | |
3295 | ConstructorUsingShadowDecl(ASTContext &C, EmptyShell Empty) |
3296 | : UsingShadowDecl(ConstructorUsingShadow, C, Empty), IsVirtual(false) {} |
3297 | |
3298 | void anchor() override; |
3299 | |
3300 | public: |
3301 | friend class ASTDeclReader; |
3302 | friend class ASTDeclWriter; |
3303 | |
3304 | static ConstructorUsingShadowDecl *Create(ASTContext &C, DeclContext *DC, |
3305 | SourceLocation Loc, |
3306 | UsingDecl *Using, NamedDecl *Target, |
3307 | bool IsVirtual); |
3308 | static ConstructorUsingShadowDecl *CreateDeserialized(ASTContext &C, |
3309 | unsigned ID); |
3310 | |
3311 | /// Returns the parent of this using shadow declaration, which |
3312 | /// is the class in which this is declared. |
3313 | //@{ |
3314 | const CXXRecordDecl *getParent() const { |
3315 | return cast<CXXRecordDecl>(getDeclContext()); |
3316 | } |
3317 | CXXRecordDecl *getParent() { |
3318 | return cast<CXXRecordDecl>(getDeclContext()); |
3319 | } |
3320 | //@} |
3321 | |
3322 | /// Get the inheriting constructor declaration for the direct base |
3323 | /// class from which this using shadow declaration was inherited, if there is |
3324 | /// one. This can be different for each redeclaration of the same shadow decl. |
3325 | ConstructorUsingShadowDecl *getNominatedBaseClassShadowDecl() const { |
3326 | return NominatedBaseClassShadowDecl; |
3327 | } |
3328 | |
3329 | /// Get the inheriting constructor declaration for the base class |
3330 | /// for which we don't have an explicit initializer, if there is one. |
3331 | ConstructorUsingShadowDecl *getConstructedBaseClassShadowDecl() const { |
3332 | return ConstructedBaseClassShadowDecl; |
3333 | } |
3334 | |
3335 | /// Get the base class that was named in the using declaration. This |
3336 | /// can be different for each redeclaration of this same shadow decl. |
3337 | CXXRecordDecl *getNominatedBaseClass() const; |
3338 | |
3339 | /// Get the base class whose constructor or constructor shadow |
3340 | /// declaration is passed the constructor arguments. |
3341 | CXXRecordDecl *getConstructedBaseClass() const { |
3342 | return cast<CXXRecordDecl>((ConstructedBaseClassShadowDecl |
3343 | ? ConstructedBaseClassShadowDecl |
3344 | : getTargetDecl()) |
3345 | ->getDeclContext()); |
3346 | } |
3347 | |
3348 | /// Returns \c true if the constructed base class is a virtual base |
3349 | /// class subobject of this declaration's class. |
3350 | bool constructsVirtualBase() const { |
3351 | return IsVirtual; |
3352 | } |
3353 | |
3354 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3355 | static bool classofKind(Kind K) { return K == ConstructorUsingShadow; } |
3356 | }; |
3357 | |
3358 | /// Represents a C++ using-declaration. |
3359 | /// |
3360 | /// For example: |
3361 | /// \code |
3362 | /// using someNameSpace::someIdentifier; |
3363 | /// \endcode |
3364 | class UsingDecl : public NamedDecl, public Mergeable<UsingDecl> { |
3365 | /// The source location of the 'using' keyword itself. |
3366 | SourceLocation UsingLocation; |
3367 | |
3368 | /// The nested-name-specifier that precedes the name. |
3369 | NestedNameSpecifierLoc QualifierLoc; |
3370 | |
3371 | /// Provides source/type location info for the declaration name |
3372 | /// embedded in the ValueDecl base class. |
3373 | DeclarationNameLoc DNLoc; |
3374 | |
3375 | /// The first shadow declaration of the shadow decl chain associated |
3376 | /// with this using declaration. |
3377 | /// |
3378 | /// The bool member of the pair store whether this decl has the \c typename |
3379 | /// keyword. |
3380 | llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow; |
3381 | |
3382 | UsingDecl(DeclContext *DC, SourceLocation UL, |
3383 | NestedNameSpecifierLoc QualifierLoc, |
3384 | const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword) |
3385 | : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()), |
3386 | UsingLocation(UL), QualifierLoc(QualifierLoc), |
3387 | DNLoc(NameInfo.getInfo()), FirstUsingShadow(nullptr, HasTypenameKeyword) { |
3388 | } |
3389 | |
3390 | void anchor() override; |
3391 | |
3392 | public: |
3393 | friend class ASTDeclReader; |
3394 | friend class ASTDeclWriter; |
3395 | |
3396 | /// Return the source location of the 'using' keyword. |
3397 | SourceLocation getUsingLoc() const { return UsingLocation; } |
3398 | |
3399 | /// Set the source location of the 'using' keyword. |
3400 | void setUsingLoc(SourceLocation L) { UsingLocation = L; } |
3401 | |
3402 | /// Retrieve the nested-name-specifier that qualifies the name, |
3403 | /// with source-location information. |
3404 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3405 | |
3406 | /// Retrieve the nested-name-specifier that qualifies the name. |
3407 | NestedNameSpecifier *getQualifier() const { |
3408 | return QualifierLoc.getNestedNameSpecifier(); |
3409 | } |
3410 | |
3411 | DeclarationNameInfo getNameInfo() const { |
3412 | return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); |
3413 | } |
3414 | |
3415 | /// Return true if it is a C++03 access declaration (no 'using'). |
3416 | bool isAccessDeclaration() const { return UsingLocation.isInvalid(); } |
3417 | |
3418 | /// Return true if the using declaration has 'typename'. |
3419 | bool hasTypename() const { return FirstUsingShadow.getInt(); } |
3420 | |
3421 | /// Sets whether the using declaration has 'typename'. |
3422 | void setTypename(bool TN) { FirstUsingShadow.setInt(TN); } |
3423 | |
3424 | /// Iterates through the using shadow declarations associated with |
3425 | /// this using declaration. |
3426 | class shadow_iterator { |
3427 | /// The current using shadow declaration. |
3428 | UsingShadowDecl *Current = nullptr; |
3429 | |
3430 | public: |
3431 | using value_type = UsingShadowDecl *; |
3432 | using reference = UsingShadowDecl *; |
3433 | using pointer = UsingShadowDecl *; |
3434 | using iterator_category = std::forward_iterator_tag; |
3435 | using difference_type = std::ptrdiff_t; |
3436 | |
3437 | shadow_iterator() = default; |
3438 | explicit shadow_iterator(UsingShadowDecl *C) : Current(C) {} |
3439 | |
3440 | reference operator*() const { return Current; } |
3441 | pointer operator->() const { return Current; } |
3442 | |
3443 | shadow_iterator& operator++() { |
3444 | Current = Current->getNextUsingShadowDecl(); |
3445 | return *this; |
3446 | } |
3447 | |
3448 | shadow_iterator operator++(int) { |
3449 | shadow_iterator tmp(*this); |
3450 | ++(*this); |
3451 | return tmp; |
3452 | } |
3453 | |
3454 | friend bool operator==(shadow_iterator x, shadow_iterator y) { |
3455 | return x.Current == y.Current; |
3456 | } |
3457 | friend bool operator!=(shadow_iterator x, shadow_iterator y) { |
3458 | return x.Current != y.Current; |
3459 | } |
3460 | }; |
3461 | |
3462 | using shadow_range = llvm::iterator_range<shadow_iterator>; |
3463 | |
3464 | shadow_range shadows() const { |
3465 | return shadow_range(shadow_begin(), shadow_end()); |
3466 | } |
3467 | |
3468 | shadow_iterator shadow_begin() const { |
3469 | return shadow_iterator(FirstUsingShadow.getPointer()); |
3470 | } |
3471 | |
3472 | shadow_iterator shadow_end() const { return shadow_iterator(); } |
3473 | |
3474 | /// Return the number of shadowed declarations associated with this |
3475 | /// using declaration. |
3476 | unsigned shadow_size() const { |
3477 | return std::distance(shadow_begin(), shadow_end()); |
3478 | } |
3479 | |
3480 | void addShadowDecl(UsingShadowDecl *S); |
3481 | void removeShadowDecl(UsingShadowDecl *S); |
3482 | |
3483 | static UsingDecl *Create(ASTContext &C, DeclContext *DC, |
3484 | SourceLocation UsingL, |
3485 | NestedNameSpecifierLoc QualifierLoc, |
3486 | const DeclarationNameInfo &NameInfo, |
3487 | bool HasTypenameKeyword); |
3488 | |
3489 | static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3490 | |
3491 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)); |
3492 | |
3493 | /// Retrieves the canonical declaration of this declaration. |
3494 | UsingDecl *getCanonicalDecl() override { return getFirstDecl(); } |
3495 | const UsingDecl *getCanonicalDecl() const { return getFirstDecl(); } |
3496 | |
3497 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3498 | static bool classofKind(Kind K) { return K == Using; } |
3499 | }; |
3500 | |
3501 | /// Represents a pack of using declarations that a single |
3502 | /// using-declarator pack-expanded into. |
3503 | /// |
3504 | /// \code |
3505 | /// template<typename ...T> struct X : T... { |
3506 | /// using T::operator()...; |
3507 | /// using T::operator T...; |
3508 | /// }; |
3509 | /// \endcode |
3510 | /// |
3511 | /// In the second case above, the UsingPackDecl will have the name |
3512 | /// 'operator T' (which contains an unexpanded pack), but the individual |
3513 | /// UsingDecls and UsingShadowDecls will have more reasonable names. |
3514 | class UsingPackDecl final |
3515 | : public NamedDecl, public Mergeable<UsingPackDecl>, |
3516 | private llvm::TrailingObjects<UsingPackDecl, NamedDecl *> { |
3517 | /// The UnresolvedUsingValueDecl or UnresolvedUsingTypenameDecl from |
3518 | /// which this waas instantiated. |
3519 | NamedDecl *InstantiatedFrom; |
3520 | |
3521 | /// The number of using-declarations created by this pack expansion. |
3522 | unsigned NumExpansions; |
3523 | |
3524 | UsingPackDecl(DeclContext *DC, NamedDecl *InstantiatedFrom, |
3525 | ArrayRef<NamedDecl *> UsingDecls) |
3526 | : NamedDecl(UsingPack, DC, |
3527 | InstantiatedFrom ? InstantiatedFrom->getLocation() |
3528 | : SourceLocation(), |
3529 | InstantiatedFrom ? InstantiatedFrom->getDeclName() |
3530 | : DeclarationName()), |
3531 | InstantiatedFrom(InstantiatedFrom), NumExpansions(UsingDecls.size()) { |
3532 | std::uninitialized_copy(UsingDecls.begin(), UsingDecls.end(), |
3533 | getTrailingObjects<NamedDecl *>()); |
3534 | } |
3535 | |
3536 | void anchor() override; |
3537 | |
3538 | public: |
3539 | friend class ASTDeclReader; |
3540 | friend class ASTDeclWriter; |
3541 | friend TrailingObjects; |
3542 | |
3543 | /// Get the using declaration from which this was instantiated. This will |
3544 | /// always be an UnresolvedUsingValueDecl or an UnresolvedUsingTypenameDecl |
3545 | /// that is a pack expansion. |
3546 | NamedDecl *getInstantiatedFromUsingDecl() const { return InstantiatedFrom; } |
3547 | |
3548 | /// Get the set of using declarations that this pack expanded into. Note that |
3549 | /// some of these may still be unresolved. |
3550 | ArrayRef<NamedDecl *> expansions() const { |
3551 | return llvm::makeArrayRef(getTrailingObjects<NamedDecl *>(), NumExpansions); |
3552 | } |
3553 | |
3554 | static UsingPackDecl *Create(ASTContext &C, DeclContext *DC, |
3555 | NamedDecl *InstantiatedFrom, |
3556 | ArrayRef<NamedDecl *> UsingDecls); |
3557 | |
3558 | static UsingPackDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
3559 | unsigned NumExpansions); |
3560 | |
3561 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
3562 | return InstantiatedFrom->getSourceRange(); |
3563 | } |
3564 | |
3565 | UsingPackDecl *getCanonicalDecl() override { return getFirstDecl(); } |
3566 | const UsingPackDecl *getCanonicalDecl() const { return getFirstDecl(); } |
3567 | |
3568 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3569 | static bool classofKind(Kind K) { return K == UsingPack; } |
3570 | }; |
3571 | |
3572 | /// Represents a dependent using declaration which was not marked with |
3573 | /// \c typename. |
3574 | /// |
3575 | /// Unlike non-dependent using declarations, these *only* bring through |
3576 | /// non-types; otherwise they would break two-phase lookup. |
3577 | /// |
3578 | /// \code |
3579 | /// template \<class T> class A : public Base<T> { |
3580 | /// using Base<T>::foo; |
3581 | /// }; |
3582 | /// \endcode |
3583 | class UnresolvedUsingValueDecl : public ValueDecl, |
3584 | public Mergeable<UnresolvedUsingValueDecl> { |
3585 | /// The source location of the 'using' keyword |
3586 | SourceLocation UsingLocation; |
3587 | |
3588 | /// If this is a pack expansion, the location of the '...'. |
3589 | SourceLocation EllipsisLoc; |
3590 | |
3591 | /// The nested-name-specifier that precedes the name. |
3592 | NestedNameSpecifierLoc QualifierLoc; |
3593 | |
3594 | /// Provides source/type location info for the declaration name |
3595 | /// embedded in the ValueDecl base class. |
3596 | DeclarationNameLoc DNLoc; |
3597 | |
3598 | UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty, |
3599 | SourceLocation UsingLoc, |
3600 | NestedNameSpecifierLoc QualifierLoc, |
3601 | const DeclarationNameInfo &NameInfo, |
3602 | SourceLocation EllipsisLoc) |
3603 | : ValueDecl(UnresolvedUsingValue, DC, |
3604 | NameInfo.getLoc(), NameInfo.getName(), Ty), |
3605 | UsingLocation(UsingLoc), EllipsisLoc(EllipsisLoc), |
3606 | QualifierLoc(QualifierLoc), DNLoc(NameInfo.getInfo()) {} |
3607 | |
3608 | void anchor() override; |
3609 | |
3610 | public: |
3611 | friend class ASTDeclReader; |
3612 | friend class ASTDeclWriter; |
3613 | |
3614 | /// Returns the source location of the 'using' keyword. |
3615 | SourceLocation getUsingLoc() const { return UsingLocation; } |
3616 | |
3617 | /// Set the source location of the 'using' keyword. |
3618 | void setUsingLoc(SourceLocation L) { UsingLocation = L; } |
3619 | |
3620 | /// Return true if it is a C++03 access declaration (no 'using'). |
3621 | bool isAccessDeclaration() const { return UsingLocation.isInvalid(); } |
3622 | |
3623 | /// Retrieve the nested-name-specifier that qualifies the name, |
3624 | /// with source-location information. |
3625 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3626 | |
3627 | /// Retrieve the nested-name-specifier that qualifies the name. |
3628 | NestedNameSpecifier *getQualifier() const { |
3629 | return QualifierLoc.getNestedNameSpecifier(); |
3630 | } |
3631 | |
3632 | DeclarationNameInfo getNameInfo() const { |
3633 | return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); |
3634 | } |
3635 | |
3636 | /// Determine whether this is a pack expansion. |
3637 | bool isPackExpansion() const { |
3638 | return EllipsisLoc.isValid(); |
3639 | } |
3640 | |
3641 | /// Get the location of the ellipsis if this is a pack expansion. |
3642 | SourceLocation getEllipsisLoc() const { |
3643 | return EllipsisLoc; |
3644 | } |
3645 | |
3646 | static UnresolvedUsingValueDecl * |
3647 | Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, |
3648 | NestedNameSpecifierLoc QualifierLoc, |
3649 | const DeclarationNameInfo &NameInfo, SourceLocation EllipsisLoc); |
3650 | |
3651 | static UnresolvedUsingValueDecl * |
3652 | CreateDeserialized(ASTContext &C, unsigned ID); |
3653 | |
3654 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)); |
3655 | |
3656 | /// Retrieves the canonical declaration of this declaration. |
3657 | UnresolvedUsingValueDecl *getCanonicalDecl() override { |
3658 | return getFirstDecl(); |
3659 | } |
3660 | const UnresolvedUsingValueDecl *getCanonicalDecl() const { |
3661 | return getFirstDecl(); |
3662 | } |
3663 | |
3664 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3665 | static bool classofKind(Kind K) { return K == UnresolvedUsingValue; } |
3666 | }; |
3667 | |
3668 | /// Represents a dependent using declaration which was marked with |
3669 | /// \c typename. |
3670 | /// |
3671 | /// \code |
3672 | /// template \<class T> class A : public Base<T> { |
3673 | /// using typename Base<T>::foo; |
3674 | /// }; |
3675 | /// \endcode |
3676 | /// |
3677 | /// The type associated with an unresolved using typename decl is |
3678 | /// currently always a typename type. |
3679 | class UnresolvedUsingTypenameDecl |
3680 | : public TypeDecl, |
3681 | public Mergeable<UnresolvedUsingTypenameDecl> { |
3682 | friend class ASTDeclReader; |
3683 | |
3684 | /// The source location of the 'typename' keyword |
3685 | SourceLocation TypenameLocation; |
3686 | |
3687 | /// If this is a pack expansion, the location of the '...'. |
3688 | SourceLocation EllipsisLoc; |
3689 | |
3690 | /// The nested-name-specifier that precedes the name. |
3691 | NestedNameSpecifierLoc QualifierLoc; |
3692 | |
3693 | UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc, |
3694 | SourceLocation TypenameLoc, |
3695 | NestedNameSpecifierLoc QualifierLoc, |
3696 | SourceLocation TargetNameLoc, |
3697 | IdentifierInfo *TargetName, |
3698 | SourceLocation EllipsisLoc) |
3699 | : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName, |
3700 | UsingLoc), |
3701 | TypenameLocation(TypenameLoc), EllipsisLoc(EllipsisLoc), |
3702 | QualifierLoc(QualifierLoc) {} |
3703 | |
3704 | void anchor() override; |
3705 | |
3706 | public: |
3707 | /// Returns the source location of the 'using' keyword. |
3708 | SourceLocation getUsingLoc() const { return getBeginLoc(); } |
3709 | |
3710 | /// Returns the source location of the 'typename' keyword. |
3711 | SourceLocation getTypenameLoc() const { return TypenameLocation; } |
3712 | |
3713 | /// Retrieve the nested-name-specifier that qualifies the name, |
3714 | /// with source-location information. |
3715 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3716 | |
3717 | /// Retrieve the nested-name-specifier that qualifies the name. |
3718 | NestedNameSpecifier *getQualifier() const { |
3719 | return QualifierLoc.getNestedNameSpecifier(); |
3720 | } |
3721 | |
3722 | DeclarationNameInfo getNameInfo() const { |
3723 | return DeclarationNameInfo(getDeclName(), getLocation()); |
3724 | } |
3725 | |
3726 | /// Determine whether this is a pack expansion. |
3727 | bool isPackExpansion() const { |
3728 | return EllipsisLoc.isValid(); |
3729 | } |
3730 | |
3731 | /// Get the location of the ellipsis if this is a pack expansion. |
3732 | SourceLocation getEllipsisLoc() const { |
3733 | return EllipsisLoc; |
3734 | } |
3735 | |
3736 | static UnresolvedUsingTypenameDecl * |
3737 | Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, |
3738 | SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc, |
3739 | SourceLocation TargetNameLoc, DeclarationName TargetName, |
3740 | SourceLocation EllipsisLoc); |
3741 | |
3742 | static UnresolvedUsingTypenameDecl * |
3743 | CreateDeserialized(ASTContext &C, unsigned ID); |
3744 | |
3745 | /// Retrieves the canonical declaration of this declaration. |
3746 | UnresolvedUsingTypenameDecl *getCanonicalDecl() override { |
3747 | return getFirstDecl(); |
3748 | } |
3749 | const UnresolvedUsingTypenameDecl *getCanonicalDecl() const { |
3750 | return getFirstDecl(); |
3751 | } |
3752 | |
3753 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3754 | static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; } |
3755 | }; |
3756 | |
3757 | /// Represents a C++11 static_assert declaration. |
3758 | class StaticAssertDecl : public Decl { |
3759 | llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed; |
3760 | StringLiteral *Message; |
3761 | SourceLocation RParenLoc; |
3762 | |
3763 | StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc, |
3764 | Expr *AssertExpr, StringLiteral *Message, |
3765 | SourceLocation RParenLoc, bool Failed) |
3766 | : Decl(StaticAssert, DC, StaticAssertLoc), |
3767 | AssertExprAndFailed(AssertExpr, Failed), Message(Message), |
3768 | RParenLoc(RParenLoc) {} |
3769 | |
3770 | virtual void anchor(); |
3771 | |
3772 | public: |
3773 | friend class ASTDeclReader; |
3774 | |
3775 | static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, |
3776 | SourceLocation StaticAssertLoc, |
3777 | Expr *AssertExpr, StringLiteral *Message, |
3778 | SourceLocation RParenLoc, bool Failed); |
3779 | static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3780 | |
3781 | Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); } |
3782 | const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); } |
3783 | |
3784 | StringLiteral *getMessage() { return Message; } |
3785 | const StringLiteral *getMessage() const { return Message; } |
3786 | |
3787 | bool isFailed() const { return AssertExprAndFailed.getInt(); } |
3788 | |
3789 | SourceLocation getRParenLoc() const { return RParenLoc; } |
3790 | |
3791 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
3792 | return SourceRange(getLocation(), getRParenLoc()); |
3793 | } |
3794 | |
3795 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3796 | static bool classofKind(Kind K) { return K == StaticAssert; } |
3797 | }; |
3798 | |
3799 | /// A binding in a decomposition declaration. For instance, given: |
3800 | /// |
3801 | /// int n[3]; |
3802 | /// auto &[a, b, c] = n; |
3803 | /// |
3804 | /// a, b, and c are BindingDecls, whose bindings are the expressions |
3805 | /// x[0], x[1], and x[2] respectively, where x is the implicit |
3806 | /// DecompositionDecl of type 'int (&)[3]'. |
3807 | class BindingDecl : public ValueDecl { |
3808 | /// The declaration that this binding binds to part of. |
3809 | LazyDeclPtr Decomp; |
3810 | /// The binding represented by this declaration. References to this |
3811 | /// declaration are effectively equivalent to this expression (except |
3812 | /// that it is only evaluated once at the point of declaration of the |
3813 | /// binding). |
3814 | Expr *Binding = nullptr; |
3815 | |
3816 | BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id) |
3817 | : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()) {} |
3818 | |
3819 | void anchor() override; |
3820 | |
3821 | public: |
3822 | friend class ASTDeclReader; |
3823 | |
3824 | static BindingDecl *Create(ASTContext &C, DeclContext *DC, |
3825 | SourceLocation IdLoc, IdentifierInfo *Id); |
3826 | static BindingDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3827 | |
3828 | /// Get the expression to which this declaration is bound. This may be null |
3829 | /// in two different cases: while parsing the initializer for the |
3830 | /// decomposition declaration, and when the initializer is type-dependent. |
3831 | Expr *getBinding() const { return Binding; } |
3832 | |
3833 | /// Get the decomposition declaration that this binding represents a |
3834 | /// decomposition of. |
3835 | ValueDecl *getDecomposedDecl() const; |
3836 | |
3837 | /// Get the variable (if any) that holds the value of evaluating the binding. |
3838 | /// Only present for user-defined bindings for tuple-like types. |
3839 | VarDecl *getHoldingVar() const; |
3840 | |
3841 | /// Set the binding for this BindingDecl, along with its declared type (which |
3842 | /// should be a possibly-cv-qualified form of the type of the binding, or a |
3843 | /// reference to such a type). |
3844 | void setBinding(QualType DeclaredType, Expr *Binding) { |
3845 | setType(DeclaredType); |
3846 | this->Binding = Binding; |
3847 | } |
3848 | |
3849 | /// Set the decomposed variable for this BindingDecl. |
3850 | void setDecomposedDecl(ValueDecl *Decomposed) { Decomp = Decomposed; } |
3851 | |
3852 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3853 | static bool classofKind(Kind K) { return K == Decl::Binding; } |
3854 | }; |
3855 | |
3856 | /// A decomposition declaration. For instance, given: |
3857 | /// |
3858 | /// int n[3]; |
3859 | /// auto &[a, b, c] = n; |
3860 | /// |
3861 | /// the second line declares a DecompositionDecl of type 'int (&)[3]', and |
3862 | /// three BindingDecls (named a, b, and c). An instance of this class is always |
3863 | /// unnamed, but behaves in almost all other respects like a VarDecl. |
3864 | class DecompositionDecl final |
3865 | : public VarDecl, |
3866 | private llvm::TrailingObjects<DecompositionDecl, BindingDecl *> { |
3867 | /// The number of BindingDecl*s following this object. |
3868 | unsigned NumBindings; |
3869 | |
3870 | DecompositionDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
3871 | SourceLocation LSquareLoc, QualType T, |
3872 | TypeSourceInfo *TInfo, StorageClass SC, |
3873 | ArrayRef<BindingDecl *> Bindings) |
3874 | : VarDecl(Decomposition, C, DC, StartLoc, LSquareLoc, nullptr, T, TInfo, |
3875 | SC), |
3876 | NumBindings(Bindings.size()) { |
3877 | std::uninitialized_copy(Bindings.begin(), Bindings.end(), |
3878 | getTrailingObjects<BindingDecl *>()); |
3879 | for (auto *B : Bindings) |
3880 | B->setDecomposedDecl(this); |
3881 | } |
3882 | |
3883 | void anchor() override; |
3884 | |
3885 | public: |
3886 | friend class ASTDeclReader; |
3887 | friend TrailingObjects; |
3888 | |
3889 | static DecompositionDecl *Create(ASTContext &C, DeclContext *DC, |
3890 | SourceLocation StartLoc, |
3891 | SourceLocation LSquareLoc, |
3892 | QualType T, TypeSourceInfo *TInfo, |
3893 | StorageClass S, |
3894 | ArrayRef<BindingDecl *> Bindings); |
3895 | static DecompositionDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
3896 | unsigned NumBindings); |
3897 | |
3898 | ArrayRef<BindingDecl *> bindings() const { |
3899 | return llvm::makeArrayRef(getTrailingObjects<BindingDecl *>(), NumBindings); |
3900 | } |
3901 | |
3902 | void printName(raw_ostream &os) const override; |
3903 | |
3904 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3905 | static bool classofKind(Kind K) { return K == Decomposition; } |
3906 | }; |
3907 | |
3908 | /// An instance of this class represents the declaration of a property |
3909 | /// member. This is a Microsoft extension to C++, first introduced in |
3910 | /// Visual Studio .NET 2003 as a parallel to similar features in C# |
3911 | /// and Managed C++. |
3912 | /// |
3913 | /// A property must always be a non-static class member. |
3914 | /// |
3915 | /// A property member superficially resembles a non-static data |
3916 | /// member, except preceded by a property attribute: |
3917 | /// __declspec(property(get=GetX, put=PutX)) int x; |
3918 | /// Either (but not both) of the 'get' and 'put' names may be omitted. |
3919 | /// |
3920 | /// A reference to a property is always an lvalue. If the lvalue |
3921 | /// undergoes lvalue-to-rvalue conversion, then a getter name is |
3922 | /// required, and that member is called with no arguments. |
3923 | /// If the lvalue is assigned into, then a setter name is required, |
3924 | /// and that member is called with one argument, the value assigned. |
3925 | /// Both operations are potentially overloaded. Compound assignments |
3926 | /// are permitted, as are the increment and decrement operators. |
3927 | /// |
3928 | /// The getter and putter methods are permitted to be overloaded, |
3929 | /// although their return and parameter types are subject to certain |
3930 | /// restrictions according to the type of the property. |
3931 | /// |
3932 | /// A property declared using an incomplete array type may |
3933 | /// additionally be subscripted, adding extra parameters to the getter |
3934 | /// and putter methods. |
3935 | class MSPropertyDecl : public DeclaratorDecl { |
3936 | IdentifierInfo *GetterId, *SetterId; |
3937 | |
3938 | MSPropertyDecl(DeclContext *DC, SourceLocation L, DeclarationName N, |
3939 | QualType T, TypeSourceInfo *TInfo, SourceLocation StartL, |
3940 | IdentifierInfo *Getter, IdentifierInfo *Setter) |
3941 | : DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL), |
3942 | GetterId(Getter), SetterId(Setter) {} |
3943 | |
3944 | void anchor() override; |
3945 | public: |
3946 | friend class ASTDeclReader; |
3947 | |
3948 | static MSPropertyDecl *Create(ASTContext &C, DeclContext *DC, |
3949 | SourceLocation L, DeclarationName N, QualType T, |
3950 | TypeSourceInfo *TInfo, SourceLocation StartL, |
3951 | IdentifierInfo *Getter, IdentifierInfo *Setter); |
3952 | static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3953 | |
3954 | static bool classof(const Decl *D) { return D->getKind() == MSProperty; } |
3955 | |
3956 | bool hasGetter() const { return GetterId != nullptr; } |
3957 | IdentifierInfo* getGetterId() const { return GetterId; } |
3958 | bool hasSetter() const { return SetterId != nullptr; } |
3959 | IdentifierInfo* getSetterId() const { return SetterId; } |
3960 | }; |
3961 | |
3962 | /// Parts of a decomposed MSGuidDecl. Factored out to avoid unnecessary |
3963 | /// dependencies on DeclCXX.h. |
3964 | struct MSGuidDeclParts { |
3965 | /// {01234567-... |
3966 | uint32_t Part1; |
3967 | /// ...-89ab-... |
3968 | uint16_t Part2; |
3969 | /// ...-cdef-... |
3970 | uint16_t Part3; |
3971 | /// ...-0123-456789abcdef} |
3972 | uint8_t Part4And5[8]; |
3973 | |
3974 | uint64_t getPart4And5AsUint64() const { |
3975 | uint64_t Val; |
3976 | memcpy(&Val, &Part4And5, sizeof(Part4And5)); |
3977 | return Val; |
3978 | } |
3979 | }; |
3980 | |
3981 | /// A global _GUID constant. These are implicitly created by UuidAttrs. |
3982 | /// |
3983 | /// struct _declspec(uuid("01234567-89ab-cdef-0123-456789abcdef")) X{}; |
3984 | /// |
3985 | /// X is a CXXRecordDecl that contains a UuidAttr that references the (unique) |
3986 | /// MSGuidDecl for the specified UUID. |
3987 | class MSGuidDecl : public ValueDecl, |
3988 | public Mergeable<MSGuidDecl>, |
3989 | public llvm::FoldingSetNode { |
3990 | public: |
3991 | using Parts = MSGuidDeclParts; |
3992 | |
3993 | private: |
3994 | /// The decomposed form of the UUID. |
3995 | Parts PartVal; |
3996 | |
3997 | /// The resolved value of the UUID as an APValue. Computed on demand and |
3998 | /// cached. |
3999 | mutable APValue APVal; |
4000 | |
4001 | void anchor() override; |
4002 | |
4003 | MSGuidDecl(DeclContext *DC, QualType T, Parts P); |
4004 | |
4005 | static MSGuidDecl *Create(const ASTContext &C, QualType T, Parts P); |
4006 | static MSGuidDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
4007 | |
4008 | // Only ASTContext::getMSGuidDecl and deserialization create these. |
4009 | friend class ASTContext; |
4010 | friend class ASTReader; |
4011 | friend class ASTDeclReader; |
4012 | |
4013 | public: |
4014 | /// Print this UUID in a human-readable format. |
4015 | void printName(llvm::raw_ostream &OS) const override; |
4016 | |
4017 | /// Get the decomposed parts of this declaration. |
4018 | Parts getParts() const { return PartVal; } |
4019 | |
4020 | /// Get the value of this MSGuidDecl as an APValue. This may fail and return |
4021 | /// an absent APValue if the type of the declaration is not of the expected |
4022 | /// shape. |
4023 | APValue &getAsAPValue() const; |
4024 | |
4025 | static void Profile(llvm::FoldingSetNodeID &ID, Parts P) { |
4026 | ID.AddInteger(P.Part1); |
4027 | ID.AddInteger(P.Part2); |
4028 | ID.AddInteger(P.Part3); |
4029 | ID.AddInteger(P.getPart4And5AsUint64()); |
4030 | } |
4031 | void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, PartVal); } |
4032 | |
4033 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
4034 | static bool classofKind(Kind K) { return K == Decl::MSGuid; } |
4035 | }; |
4036 | |
4037 | /// Insertion operator for diagnostics. This allows sending an AccessSpecifier |
4038 | /// into a diagnostic with <<. |
4039 | const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB, |
4040 | AccessSpecifier AS); |
4041 | |
4042 | } // namespace clang |
4043 | |
4044 | #endif // LLVM_CLANG_AST_DECLCXX_H |
1 | //===- llvm/ADT/PointerIntPair.h - Pair for pointer and int -----*- 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 PointerIntPair class. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #ifndef LLVM_ADT_POINTERINTPAIR_H |
14 | #define LLVM_ADT_POINTERINTPAIR_H |
15 | |
16 | #include "llvm/Support/Compiler.h" |
17 | #include "llvm/Support/PointerLikeTypeTraits.h" |
18 | #include "llvm/Support/type_traits.h" |
19 | #include <cassert> |
20 | #include <cstdint> |
21 | #include <limits> |
22 | |
23 | namespace llvm { |
24 | |
25 | template <typename T> struct DenseMapInfo; |
26 | template <typename PointerT, unsigned IntBits, typename PtrTraits> |
27 | struct PointerIntPairInfo; |
28 | |
29 | /// PointerIntPair - This class implements a pair of a pointer and small |
30 | /// integer. It is designed to represent this in the space required by one |
31 | /// pointer by bitmangling the integer into the low part of the pointer. This |
32 | /// can only be done for small integers: typically up to 3 bits, but it depends |
33 | /// on the number of bits available according to PointerLikeTypeTraits for the |
34 | /// type. |
35 | /// |
36 | /// Note that PointerIntPair always puts the IntVal part in the highest bits |
37 | /// possible. For example, PointerIntPair<void*, 1, bool> will put the bit for |
38 | /// the bool into bit #2, not bit #0, which allows the low two bits to be used |
39 | /// for something else. For example, this allows: |
40 | /// PointerIntPair<PointerIntPair<void*, 1, bool>, 1, bool> |
41 | /// ... and the two bools will land in different bits. |
42 | template <typename PointerTy, unsigned IntBits, typename IntType = unsigned, |
43 | typename PtrTraits = PointerLikeTypeTraits<PointerTy>, |
44 | typename Info = PointerIntPairInfo<PointerTy, IntBits, PtrTraits>> |
45 | class PointerIntPair { |
46 | // Used by MSVC visualizer and generally helpful for debugging/visualizing. |
47 | using InfoTy = Info; |
48 | intptr_t Value = 0; |
49 | |
50 | public: |
51 | constexpr PointerIntPair() = default; |
52 | |
53 | PointerIntPair(PointerTy PtrVal, IntType IntVal) { |
54 | setPointerAndInt(PtrVal, IntVal); |
55 | } |
56 | |
57 | explicit PointerIntPair(PointerTy PtrVal) { initWithPointer(PtrVal); } |
58 | |
59 | PointerTy getPointer() const { return Info::getPointer(Value); } |
60 | |
61 | IntType getInt() const { return (IntType)Info::getInt(Value); } |
62 | |
63 | void setPointer(PointerTy PtrVal) LLVM_LVALUE_FUNCTION& { |
64 | Value = Info::updatePointer(Value, PtrVal); |
65 | } |
66 | |
67 | void setInt(IntType IntVal) LLVM_LVALUE_FUNCTION& { |
68 | Value = Info::updateInt(Value, static_cast<intptr_t>(IntVal)); |
69 | } |
70 | |
71 | void initWithPointer(PointerTy PtrVal) LLVM_LVALUE_FUNCTION& { |
72 | Value = Info::updatePointer(0, PtrVal); |
73 | } |
74 | |
75 | void setPointerAndInt(PointerTy PtrVal, IntType IntVal) LLVM_LVALUE_FUNCTION& { |
76 | Value = Info::updateInt(Info::updatePointer(0, PtrVal), |
77 | static_cast<intptr_t>(IntVal)); |
78 | } |
79 | |
80 | PointerTy const *getAddrOfPointer() const { |
81 | return const_cast<PointerIntPair *>(this)->getAddrOfPointer(); |
82 | } |
83 | |
84 | PointerTy *getAddrOfPointer() { |
85 | assert(Value == reinterpret_cast<intptr_t>(getPointer()) &&((Value == reinterpret_cast<intptr_t>(getPointer()) && "Can only return the address if IntBits is cleared and " "PtrTraits doesn't change the pointer" ) ? static_cast<void> (0) : __assert_fail ("Value == reinterpret_cast<intptr_t>(getPointer()) && \"Can only return the address if IntBits is cleared and \" \"PtrTraits doesn't change the pointer\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/ADT/PointerIntPair.h" , 87, __PRETTY_FUNCTION__)) |
86 | "Can only return the address if IntBits is cleared and "((Value == reinterpret_cast<intptr_t>(getPointer()) && "Can only return the address if IntBits is cleared and " "PtrTraits doesn't change the pointer" ) ? static_cast<void> (0) : __assert_fail ("Value == reinterpret_cast<intptr_t>(getPointer()) && \"Can only return the address if IntBits is cleared and \" \"PtrTraits doesn't change the pointer\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/ADT/PointerIntPair.h" , 87, __PRETTY_FUNCTION__)) |
87 | "PtrTraits doesn't change the pointer")((Value == reinterpret_cast<intptr_t>(getPointer()) && "Can only return the address if IntBits is cleared and " "PtrTraits doesn't change the pointer" ) ? static_cast<void> (0) : __assert_fail ("Value == reinterpret_cast<intptr_t>(getPointer()) && \"Can only return the address if IntBits is cleared and \" \"PtrTraits doesn't change the pointer\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/ADT/PointerIntPair.h" , 87, __PRETTY_FUNCTION__)); |
88 | return reinterpret_cast<PointerTy *>(&Value); |
89 | } |
90 | |
91 | void *getOpaqueValue() const { return reinterpret_cast<void *>(Value); } |
92 | |
93 | void setFromOpaqueValue(void *Val) LLVM_LVALUE_FUNCTION& { |
94 | Value = reinterpret_cast<intptr_t>(Val); |
95 | } |
96 | |
97 | static PointerIntPair getFromOpaqueValue(void *V) { |
98 | PointerIntPair P; |
99 | P.setFromOpaqueValue(V); |
100 | return P; |
101 | } |
102 | |
103 | // Allow PointerIntPairs to be created from const void * if and only if the |
104 | // pointer type could be created from a const void *. |
105 | static PointerIntPair getFromOpaqueValue(const void *V) { |
106 | (void)PtrTraits::getFromVoidPointer(V); |
107 | return getFromOpaqueValue(const_cast<void *>(V)); |
108 | } |
109 | |
110 | bool operator==(const PointerIntPair &RHS) const { |
111 | return Value == RHS.Value; |
112 | } |
113 | |
114 | bool operator!=(const PointerIntPair &RHS) const { |
115 | return Value != RHS.Value; |
116 | } |
117 | |
118 | bool operator<(const PointerIntPair &RHS) const { return Value < RHS.Value; } |
119 | bool operator>(const PointerIntPair &RHS) const { return Value > RHS.Value; } |
120 | |
121 | bool operator<=(const PointerIntPair &RHS) const { |
122 | return Value <= RHS.Value; |
123 | } |
124 | |
125 | bool operator>=(const PointerIntPair &RHS) const { |
126 | return Value >= RHS.Value; |
127 | } |
128 | }; |
129 | |
130 | // Specialize is_trivially_copyable to avoid limitation of llvm::is_trivially_copyable |
131 | // when compiled with gcc 4.9. |
132 | template <typename PointerTy, unsigned IntBits, typename IntType, |
133 | typename PtrTraits, |
134 | typename Info> |
135 | struct is_trivially_copyable<PointerIntPair<PointerTy, IntBits, IntType, PtrTraits, Info>> : std::true_type { |
136 | #ifdef HAVE_STD_IS_TRIVIALLY_COPYABLE |
137 | static_assert(std::is_trivially_copyable<PointerIntPair<PointerTy, IntBits, IntType, PtrTraits, Info>>::value, |
138 | "inconsistent behavior between llvm:: and std:: implementation of is_trivially_copyable"); |
139 | #endif |
140 | }; |
141 | |
142 | |
143 | template <typename PointerT, unsigned IntBits, typename PtrTraits> |
144 | struct PointerIntPairInfo { |
145 | static_assert(PtrTraits::NumLowBitsAvailable < |
146 | std::numeric_limits<uintptr_t>::digits, |
147 | "cannot use a pointer type that has all bits free"); |
148 | static_assert(IntBits <= PtrTraits::NumLowBitsAvailable, |
149 | "PointerIntPair with integer size too large for pointer"); |
150 | enum MaskAndShiftConstants : uintptr_t { |
151 | /// PointerBitMask - The bits that come from the pointer. |
152 | PointerBitMask = |
153 | ~(uintptr_t)(((intptr_t)1 << PtrTraits::NumLowBitsAvailable) - 1), |
154 | |
155 | /// IntShift - The number of low bits that we reserve for other uses, and |
156 | /// keep zero. |
157 | IntShift = (uintptr_t)PtrTraits::NumLowBitsAvailable - IntBits, |
158 | |
159 | /// IntMask - This is the unshifted mask for valid bits of the int type. |
160 | IntMask = (uintptr_t)(((intptr_t)1 << IntBits) - 1), |
161 | |
162 | // ShiftedIntMask - This is the bits for the integer shifted in place. |
163 | ShiftedIntMask = (uintptr_t)(IntMask << IntShift) |
164 | }; |
165 | |
166 | static PointerT getPointer(intptr_t Value) { |
167 | return PtrTraits::getFromVoidPointer( |
168 | reinterpret_cast<void *>(Value & PointerBitMask)); |
169 | } |
170 | |
171 | static intptr_t getInt(intptr_t Value) { |
172 | return (Value >> IntShift) & IntMask; |
173 | } |
174 | |
175 | static intptr_t updatePointer(intptr_t OrigValue, PointerT Ptr) { |
176 | intptr_t PtrWord = |
177 | reinterpret_cast<intptr_t>(PtrTraits::getAsVoidPointer(Ptr)); |
178 | assert((PtrWord & ~PointerBitMask) == 0 &&(((PtrWord & ~PointerBitMask) == 0 && "Pointer is not sufficiently aligned" ) ? static_cast<void> (0) : __assert_fail ("(PtrWord & ~PointerBitMask) == 0 && \"Pointer is not sufficiently aligned\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/ADT/PointerIntPair.h" , 179, __PRETTY_FUNCTION__)) |
179 | "Pointer is not sufficiently aligned")(((PtrWord & ~PointerBitMask) == 0 && "Pointer is not sufficiently aligned" ) ? static_cast<void> (0) : __assert_fail ("(PtrWord & ~PointerBitMask) == 0 && \"Pointer is not sufficiently aligned\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/ADT/PointerIntPair.h" , 179, __PRETTY_FUNCTION__)); |
180 | // Preserve all low bits, just update the pointer. |
181 | return PtrWord | (OrigValue & ~PointerBitMask); |
182 | } |
183 | |
184 | static intptr_t updateInt(intptr_t OrigValue, intptr_t Int) { |
185 | intptr_t IntWord = static_cast<intptr_t>(Int); |
186 | assert((IntWord & ~IntMask) == 0 && "Integer too large for field")(((IntWord & ~IntMask) == 0 && "Integer too large for field" ) ? static_cast<void> (0) : __assert_fail ("(IntWord & ~IntMask) == 0 && \"Integer too large for field\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/llvm/include/llvm/ADT/PointerIntPair.h" , 186, __PRETTY_FUNCTION__)); |
187 | |
188 | // Preserve all bits other than the ones we are updating. |
189 | return (OrigValue & ~ShiftedIntMask) | IntWord << IntShift; |
190 | } |
191 | }; |
192 | |
193 | // Provide specialization of DenseMapInfo for PointerIntPair. |
194 | template <typename PointerTy, unsigned IntBits, typename IntType> |
195 | struct DenseMapInfo<PointerIntPair<PointerTy, IntBits, IntType>> { |
196 | using Ty = PointerIntPair<PointerTy, IntBits, IntType>; |
197 | |
198 | static Ty getEmptyKey() { |
199 | uintptr_t Val = static_cast<uintptr_t>(-1); |
200 | Val <<= PointerLikeTypeTraits<Ty>::NumLowBitsAvailable; |
201 | return Ty::getFromOpaqueValue(reinterpret_cast<void *>(Val)); |
202 | } |
203 | |
204 | static Ty getTombstoneKey() { |
205 | uintptr_t Val = static_cast<uintptr_t>(-2); |
206 | Val <<= PointerLikeTypeTraits<PointerTy>::NumLowBitsAvailable; |
207 | return Ty::getFromOpaqueValue(reinterpret_cast<void *>(Val)); |
208 | } |
209 | |
210 | static unsigned getHashValue(Ty V) { |
211 | uintptr_t IV = reinterpret_cast<uintptr_t>(V.getOpaqueValue()); |
212 | return unsigned(IV) ^ unsigned(IV >> 9); |
213 | } |
214 | |
215 | static bool isEqual(const Ty &LHS, const Ty &RHS) { return LHS == RHS; } |
216 | }; |
217 | |
218 | // Teach SmallPtrSet that PointerIntPair is "basically a pointer". |
219 | template <typename PointerTy, unsigned IntBits, typename IntType, |
220 | typename PtrTraits> |
221 | struct PointerLikeTypeTraits< |
222 | PointerIntPair<PointerTy, IntBits, IntType, PtrTraits>> { |
223 | static inline void * |
224 | getAsVoidPointer(const PointerIntPair<PointerTy, IntBits, IntType> &P) { |
225 | return P.getOpaqueValue(); |
226 | } |
227 | |
228 | static inline PointerIntPair<PointerTy, IntBits, IntType> |
229 | getFromVoidPointer(void *P) { |
230 | return PointerIntPair<PointerTy, IntBits, IntType>::getFromOpaqueValue(P); |
231 | } |
232 | |
233 | static inline PointerIntPair<PointerTy, IntBits, IntType> |
234 | getFromVoidPointer(const void *P) { |
235 | return PointerIntPair<PointerTy, IntBits, IntType>::getFromOpaqueValue(P); |
236 | } |
237 | |
238 | static constexpr int NumLowBitsAvailable = |
239 | PtrTraits::NumLowBitsAvailable - IntBits; |
240 | }; |
241 | |
242 | } // end namespace llvm |
243 | |
244 | #endif // LLVM_ADT_POINTERINTPAIR_H |
1 | //===- TemplateBase.h - Core classes for C++ templates ----------*- 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 provides definitions which are common for all kinds of |
10 | // template representation. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #ifndef LLVM_CLANG_AST_TEMPLATEBASE_H |
15 | #define LLVM_CLANG_AST_TEMPLATEBASE_H |
16 | |
17 | #include "clang/AST/DependenceFlags.h" |
18 | #include "clang/AST/NestedNameSpecifier.h" |
19 | #include "clang/AST/TemplateName.h" |
20 | #include "clang/AST/Type.h" |
21 | #include "clang/Basic/LLVM.h" |
22 | #include "clang/Basic/SourceLocation.h" |
23 | #include "llvm/ADT/APInt.h" |
24 | #include "llvm/ADT/APSInt.h" |
25 | #include "llvm/ADT/ArrayRef.h" |
26 | #include "llvm/ADT/None.h" |
27 | #include "llvm/ADT/Optional.h" |
28 | #include "llvm/ADT/SmallVector.h" |
29 | #include "llvm/Support/Compiler.h" |
30 | #include "llvm/Support/TrailingObjects.h" |
31 | #include <cassert> |
32 | #include <cstddef> |
33 | #include <cstdint> |
34 | |
35 | namespace llvm { |
36 | |
37 | class FoldingSetNodeID; |
38 | |
39 | // Provide PointerLikeTypeTraits for clang::Expr*, this default one requires a |
40 | // full definition of Expr, but this file only sees a forward del because of |
41 | // the dependency. |
42 | template <> struct PointerLikeTypeTraits<clang::Expr *> { |
43 | static inline void *getAsVoidPointer(clang::Expr *P) { return P; } |
44 | static inline clang::Expr *getFromVoidPointer(void *P) { |
45 | return static_cast<clang::Expr *>(P); |
46 | } |
47 | static constexpr int NumLowBitsAvailable = 2; |
48 | }; |
49 | |
50 | } // namespace llvm |
51 | |
52 | namespace clang { |
53 | |
54 | class ASTContext; |
55 | class DiagnosticBuilder; |
56 | class Expr; |
57 | struct PrintingPolicy; |
58 | class TypeSourceInfo; |
59 | class ValueDecl; |
60 | |
61 | /// Represents a template argument. |
62 | class TemplateArgument { |
63 | public: |
64 | /// The kind of template argument we're storing. |
65 | enum ArgKind { |
66 | /// Represents an empty template argument, e.g., one that has not |
67 | /// been deduced. |
68 | Null = 0, |
69 | |
70 | /// The template argument is a type. |
71 | Type, |
72 | |
73 | /// The template argument is a declaration that was provided for a pointer, |
74 | /// reference, or pointer to member non-type template parameter. |
75 | Declaration, |
76 | |
77 | /// The template argument is a null pointer or null pointer to member that |
78 | /// was provided for a non-type template parameter. |
79 | NullPtr, |
80 | |
81 | /// The template argument is an integral value stored in an llvm::APSInt |
82 | /// that was provided for an integral non-type template parameter. |
83 | Integral, |
84 | |
85 | /// The template argument is a template name that was provided for a |
86 | /// template template parameter. |
87 | Template, |
88 | |
89 | /// The template argument is a pack expansion of a template name that was |
90 | /// provided for a template template parameter. |
91 | TemplateExpansion, |
92 | |
93 | /// The template argument is an expression, and we've not resolved it to one |
94 | /// of the other forms yet, either because it's dependent or because we're |
95 | /// representing a non-canonical template argument (for instance, in a |
96 | /// TemplateSpecializationType). |
97 | Expression, |
98 | |
99 | /// The template argument is actually a parameter pack. Arguments are stored |
100 | /// in the Args struct. |
101 | Pack |
102 | }; |
103 | |
104 | private: |
105 | /// The kind of template argument we're storing. |
106 | |
107 | struct DA { |
108 | unsigned Kind; |
109 | void *QT; |
110 | ValueDecl *D; |
111 | }; |
112 | struct I { |
113 | unsigned Kind; |
114 | // We store a decomposed APSInt with the data allocated by ASTContext if |
115 | // BitWidth > 64. The memory may be shared between multiple |
116 | // TemplateArgument instances. |
117 | unsigned BitWidth : 31; |
118 | unsigned IsUnsigned : 1; |
119 | union { |
120 | /// Used to store the <= 64 bits integer value. |
121 | uint64_t VAL; |
122 | |
123 | /// Used to store the >64 bits integer value. |
124 | const uint64_t *pVal; |
125 | }; |
126 | void *Type; |
127 | }; |
128 | struct A { |
129 | unsigned Kind; |
130 | unsigned NumArgs; |
131 | const TemplateArgument *Args; |
132 | }; |
133 | struct TA { |
134 | unsigned Kind; |
135 | unsigned NumExpansions; |
136 | void *Name; |
137 | }; |
138 | struct TV { |
139 | unsigned Kind; |
140 | uintptr_t V; |
141 | }; |
142 | union { |
143 | struct DA DeclArg; |
144 | struct I Integer; |
145 | struct A Args; |
146 | struct TA TemplateArg; |
147 | struct TV TypeOrValue; |
148 | }; |
149 | |
150 | public: |
151 | /// Construct an empty, invalid template argument. |
152 | constexpr TemplateArgument() : TypeOrValue({Null, 0}) {} |
153 | |
154 | /// Construct a template type argument. |
155 | TemplateArgument(QualType T, bool isNullPtr = false) { |
156 | TypeOrValue.Kind = isNullPtr ? NullPtr : Type; |
157 | TypeOrValue.V = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr()); |
158 | } |
159 | |
160 | /// Construct a template argument that refers to a |
161 | /// declaration, which is either an external declaration or a |
162 | /// template declaration. |
163 | TemplateArgument(ValueDecl *D, QualType QT) { |
164 | assert(D && "Expected decl")((D && "Expected decl") ? static_cast<void> (0) : __assert_fail ("D && \"Expected decl\"", "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 164, __PRETTY_FUNCTION__)); |
165 | DeclArg.Kind = Declaration; |
166 | DeclArg.QT = QT.getAsOpaquePtr(); |
167 | DeclArg.D = D; |
168 | } |
169 | |
170 | /// Construct an integral constant template argument. The memory to |
171 | /// store the value is allocated with Ctx. |
172 | TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value, QualType Type); |
173 | |
174 | /// Construct an integral constant template argument with the same |
175 | /// value as Other but a different type. |
176 | TemplateArgument(const TemplateArgument &Other, QualType Type) { |
177 | Integer = Other.Integer; |
178 | Integer.Type = Type.getAsOpaquePtr(); |
179 | } |
180 | |
181 | /// Construct a template argument that is a template. |
182 | /// |
183 | /// This form of template argument is generally used for template template |
184 | /// parameters. However, the template name could be a dependent template |
185 | /// name that ends up being instantiated to a function template whose address |
186 | /// is taken. |
187 | /// |
188 | /// \param Name The template name. |
189 | TemplateArgument(TemplateName Name) { |
190 | TemplateArg.Kind = Template; |
191 | TemplateArg.Name = Name.getAsVoidPointer(); |
192 | TemplateArg.NumExpansions = 0; |
193 | } |
194 | |
195 | /// Construct a template argument that is a template pack expansion. |
196 | /// |
197 | /// This form of template argument is generally used for template template |
198 | /// parameters. However, the template name could be a dependent template |
199 | /// name that ends up being instantiated to a function template whose address |
200 | /// is taken. |
201 | /// |
202 | /// \param Name The template name. |
203 | /// |
204 | /// \param NumExpansions The number of expansions that will be generated by |
205 | /// instantiating |
206 | TemplateArgument(TemplateName Name, Optional<unsigned> NumExpansions) { |
207 | TemplateArg.Kind = TemplateExpansion; |
208 | TemplateArg.Name = Name.getAsVoidPointer(); |
209 | if (NumExpansions) |
210 | TemplateArg.NumExpansions = *NumExpansions + 1; |
211 | else |
212 | TemplateArg.NumExpansions = 0; |
213 | } |
214 | |
215 | /// Construct a template argument that is an expression. |
216 | /// |
217 | /// This form of template argument only occurs in template argument |
218 | /// lists used for dependent types and for expression; it will not |
219 | /// occur in a non-dependent, canonical template argument list. |
220 | TemplateArgument(Expr *E) { |
221 | TypeOrValue.Kind = Expression; |
222 | TypeOrValue.V = reinterpret_cast<uintptr_t>(E); |
223 | } |
224 | |
225 | /// Construct a template argument that is a template argument pack. |
226 | /// |
227 | /// We assume that storage for the template arguments provided |
228 | /// outlives the TemplateArgument itself. |
229 | explicit TemplateArgument(ArrayRef<TemplateArgument> Args) { |
230 | this->Args.Kind = Pack; |
231 | this->Args.Args = Args.data(); |
232 | this->Args.NumArgs = Args.size(); |
233 | } |
234 | |
235 | TemplateArgument(TemplateName, bool) = delete; |
236 | |
237 | static TemplateArgument getEmptyPack() { return TemplateArgument(None); } |
238 | |
239 | /// Create a new template argument pack by copying the given set of |
240 | /// template arguments. |
241 | static TemplateArgument CreatePackCopy(ASTContext &Context, |
242 | ArrayRef<TemplateArgument> Args); |
243 | |
244 | /// Return the kind of stored template argument. |
245 | ArgKind getKind() const { return (ArgKind)TypeOrValue.Kind; } |
246 | |
247 | /// Determine whether this template argument has no value. |
248 | bool isNull() const { return getKind() == Null; } |
249 | |
250 | TemplateArgumentDependence getDependence() const; |
251 | |
252 | /// Whether this template argument is dependent on a template |
253 | /// parameter such that its result can change from one instantiation to |
254 | /// another. |
255 | bool isDependent() const; |
256 | |
257 | /// Whether this template argument is dependent on a template |
258 | /// parameter. |
259 | bool isInstantiationDependent() const; |
260 | |
261 | /// Whether this template argument contains an unexpanded |
262 | /// parameter pack. |
263 | bool containsUnexpandedParameterPack() const; |
264 | |
265 | /// Determine whether this template argument is a pack expansion. |
266 | bool isPackExpansion() const; |
267 | |
268 | /// Retrieve the type for a type template argument. |
269 | QualType getAsType() const { |
270 | assert(getKind() == Type && "Unexpected kind")((getKind() == Type && "Unexpected kind") ? static_cast <void> (0) : __assert_fail ("getKind() == Type && \"Unexpected kind\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 270, __PRETTY_FUNCTION__)); |
271 | return QualType::getFromOpaquePtr(reinterpret_cast<void*>(TypeOrValue.V)); |
272 | } |
273 | |
274 | /// Retrieve the declaration for a declaration non-type |
275 | /// template argument. |
276 | ValueDecl *getAsDecl() const { |
277 | assert(getKind() == Declaration && "Unexpected kind")((getKind() == Declaration && "Unexpected kind") ? static_cast <void> (0) : __assert_fail ("getKind() == Declaration && \"Unexpected kind\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 277, __PRETTY_FUNCTION__)); |
278 | return DeclArg.D; |
279 | } |
280 | |
281 | QualType getParamTypeForDecl() const { |
282 | assert(getKind() == Declaration && "Unexpected kind")((getKind() == Declaration && "Unexpected kind") ? static_cast <void> (0) : __assert_fail ("getKind() == Declaration && \"Unexpected kind\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 282, __PRETTY_FUNCTION__)); |
283 | return QualType::getFromOpaquePtr(DeclArg.QT); |
284 | } |
285 | |
286 | /// Retrieve the type for null non-type template argument. |
287 | QualType getNullPtrType() const { |
288 | assert(getKind() == NullPtr && "Unexpected kind")((getKind() == NullPtr && "Unexpected kind") ? static_cast <void> (0) : __assert_fail ("getKind() == NullPtr && \"Unexpected kind\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 288, __PRETTY_FUNCTION__)); |
289 | return QualType::getFromOpaquePtr(reinterpret_cast<void*>(TypeOrValue.V)); |
290 | } |
291 | |
292 | /// Retrieve the template name for a template name argument. |
293 | TemplateName getAsTemplate() const { |
294 | assert(getKind() == Template && "Unexpected kind")((getKind() == Template && "Unexpected kind") ? static_cast <void> (0) : __assert_fail ("getKind() == Template && \"Unexpected kind\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 294, __PRETTY_FUNCTION__)); |
295 | return TemplateName::getFromVoidPointer(TemplateArg.Name); |
296 | } |
297 | |
298 | /// Retrieve the template argument as a template name; if the argument |
299 | /// is a pack expansion, return the pattern as a template name. |
300 | TemplateName getAsTemplateOrTemplatePattern() const { |
301 | assert((getKind() == Template || getKind() == TemplateExpansion) &&(((getKind() == Template || getKind() == TemplateExpansion) && "Unexpected kind") ? static_cast<void> (0) : __assert_fail ("(getKind() == Template || getKind() == TemplateExpansion) && \"Unexpected kind\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 302, __PRETTY_FUNCTION__)) |
302 | "Unexpected kind")(((getKind() == Template || getKind() == TemplateExpansion) && "Unexpected kind") ? static_cast<void> (0) : __assert_fail ("(getKind() == Template || getKind() == TemplateExpansion) && \"Unexpected kind\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 302, __PRETTY_FUNCTION__)); |
303 | |
304 | return TemplateName::getFromVoidPointer(TemplateArg.Name); |
305 | } |
306 | |
307 | /// Retrieve the number of expansions that a template template argument |
308 | /// expansion will produce, if known. |
309 | Optional<unsigned> getNumTemplateExpansions() const; |
310 | |
311 | /// Retrieve the template argument as an integral value. |
312 | // FIXME: Provide a way to read the integral data without copying the value. |
313 | llvm::APSInt getAsIntegral() const { |
314 | assert(getKind() == Integral && "Unexpected kind")((getKind() == Integral && "Unexpected kind") ? static_cast <void> (0) : __assert_fail ("getKind() == Integral && \"Unexpected kind\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 314, __PRETTY_FUNCTION__)); |
315 | |
316 | using namespace llvm; |
317 | |
318 | if (Integer.BitWidth <= 64) |
319 | return APSInt(APInt(Integer.BitWidth, Integer.VAL), Integer.IsUnsigned); |
320 | |
321 | unsigned NumWords = APInt::getNumWords(Integer.BitWidth); |
322 | return APSInt(APInt(Integer.BitWidth, makeArrayRef(Integer.pVal, NumWords)), |
323 | Integer.IsUnsigned); |
324 | } |
325 | |
326 | /// Retrieve the type of the integral value. |
327 | QualType getIntegralType() const { |
328 | assert(getKind() == Integral && "Unexpected kind")((getKind() == Integral && "Unexpected kind") ? static_cast <void> (0) : __assert_fail ("getKind() == Integral && \"Unexpected kind\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 328, __PRETTY_FUNCTION__)); |
329 | return QualType::getFromOpaquePtr(Integer.Type); |
330 | } |
331 | |
332 | void setIntegralType(QualType T) { |
333 | assert(getKind() == Integral && "Unexpected kind")((getKind() == Integral && "Unexpected kind") ? static_cast <void> (0) : __assert_fail ("getKind() == Integral && \"Unexpected kind\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 333, __PRETTY_FUNCTION__)); |
334 | Integer.Type = T.getAsOpaquePtr(); |
335 | } |
336 | |
337 | /// If this is a non-type template argument, get its type. Otherwise, |
338 | /// returns a null QualType. |
339 | QualType getNonTypeTemplateArgumentType() const; |
340 | |
341 | /// Retrieve the template argument as an expression. |
342 | Expr *getAsExpr() const { |
343 | assert(getKind() == Expression && "Unexpected kind")((getKind() == Expression && "Unexpected kind") ? static_cast <void> (0) : __assert_fail ("getKind() == Expression && \"Unexpected kind\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 343, __PRETTY_FUNCTION__)); |
344 | return reinterpret_cast<Expr *>(TypeOrValue.V); |
345 | } |
346 | |
347 | /// Iterator that traverses the elements of a template argument pack. |
348 | using pack_iterator = const TemplateArgument *; |
349 | |
350 | /// Iterator referencing the first argument of a template argument |
351 | /// pack. |
352 | pack_iterator pack_begin() const { |
353 | assert(getKind() == Pack)((getKind() == Pack) ? static_cast<void> (0) : __assert_fail ("getKind() == Pack", "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 353, __PRETTY_FUNCTION__)); |
354 | return Args.Args; |
355 | } |
356 | |
357 | /// Iterator referencing one past the last argument of a template |
358 | /// argument pack. |
359 | pack_iterator pack_end() const { |
360 | assert(getKind() == Pack)((getKind() == Pack) ? static_cast<void> (0) : __assert_fail ("getKind() == Pack", "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 360, __PRETTY_FUNCTION__)); |
361 | return Args.Args + Args.NumArgs; |
362 | } |
363 | |
364 | /// Iterator range referencing all of the elements of a template |
365 | /// argument pack. |
366 | ArrayRef<TemplateArgument> pack_elements() const { |
367 | return llvm::makeArrayRef(pack_begin(), pack_end()); |
368 | } |
369 | |
370 | /// The number of template arguments in the given template argument |
371 | /// pack. |
372 | unsigned pack_size() const { |
373 | assert(getKind() == Pack)((getKind() == Pack) ? static_cast<void> (0) : __assert_fail ("getKind() == Pack", "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 373, __PRETTY_FUNCTION__)); |
374 | return Args.NumArgs; |
375 | } |
376 | |
377 | /// Return the array of arguments in this template argument pack. |
378 | ArrayRef<TemplateArgument> getPackAsArray() const { |
379 | assert(getKind() == Pack)((getKind() == Pack) ? static_cast<void> (0) : __assert_fail ("getKind() == Pack", "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 379, __PRETTY_FUNCTION__)); |
380 | return llvm::makeArrayRef(Args.Args, Args.NumArgs); |
381 | } |
382 | |
383 | /// Determines whether two template arguments are superficially the |
384 | /// same. |
385 | bool structurallyEquals(const TemplateArgument &Other) const; |
386 | |
387 | /// When the template argument is a pack expansion, returns |
388 | /// the pattern of the pack expansion. |
389 | TemplateArgument getPackExpansionPattern() const; |
390 | |
391 | /// Print this template argument to the given output stream. |
392 | void print(const PrintingPolicy &Policy, raw_ostream &Out) const; |
393 | |
394 | /// Debugging aid that dumps the template argument. |
395 | void dump(raw_ostream &Out) const; |
396 | |
397 | /// Debugging aid that dumps the template argument to standard error. |
398 | void dump() const; |
399 | |
400 | /// Used to insert TemplateArguments into FoldingSets. |
401 | void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const; |
402 | }; |
403 | |
404 | /// Location information for a TemplateArgument. |
405 | struct TemplateArgumentLocInfo { |
406 | private: |
407 | struct TemplateTemplateArgLocInfo { |
408 | // FIXME: We'd like to just use the qualifier in the TemplateName, |
409 | // but template arguments get canonicalized too quickly. |
410 | NestedNameSpecifier *Qualifier; |
411 | void *QualifierLocData; |
412 | unsigned TemplateNameLoc; |
413 | unsigned EllipsisLoc; |
414 | }; |
415 | |
416 | llvm::PointerUnion<TemplateTemplateArgLocInfo *, Expr *, TypeSourceInfo *> |
417 | Pointer; |
418 | |
419 | TemplateTemplateArgLocInfo *getTemplate() const { |
420 | return Pointer.get<TemplateTemplateArgLocInfo *>(); |
421 | } |
422 | |
423 | public: |
424 | TemplateArgumentLocInfo() {} |
425 | TemplateArgumentLocInfo(TypeSourceInfo *Declarator) { Pointer = Declarator; } |
426 | |
427 | TemplateArgumentLocInfo(Expr *E) { Pointer = E; } |
428 | // Ctx is used for allocation -- this case is unusually large and also rare, |
429 | // so we store the payload out-of-line. |
430 | TemplateArgumentLocInfo(ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc, |
431 | SourceLocation TemplateNameLoc, |
432 | SourceLocation EllipsisLoc); |
433 | |
434 | TypeSourceInfo *getAsTypeSourceInfo() const { |
435 | return Pointer.get<TypeSourceInfo *>(); |
436 | } |
437 | |
438 | Expr *getAsExpr() const { return Pointer.get<Expr *>(); } |
439 | |
440 | NestedNameSpecifierLoc getTemplateQualifierLoc() const { |
441 | const auto *Template = getTemplate(); |
442 | return NestedNameSpecifierLoc(Template->Qualifier, |
443 | Template->QualifierLocData); |
444 | } |
445 | |
446 | SourceLocation getTemplateNameLoc() const { |
447 | return SourceLocation::getFromRawEncoding(getTemplate()->TemplateNameLoc); |
448 | } |
449 | |
450 | SourceLocation getTemplateEllipsisLoc() const { |
451 | return SourceLocation::getFromRawEncoding(getTemplate()->EllipsisLoc); |
452 | } |
453 | }; |
454 | |
455 | /// Location wrapper for a TemplateArgument. TemplateArgument is to |
456 | /// TemplateArgumentLoc as Type is to TypeLoc. |
457 | class TemplateArgumentLoc { |
458 | TemplateArgument Argument; |
459 | TemplateArgumentLocInfo LocInfo; |
460 | |
461 | public: |
462 | TemplateArgumentLoc() {} |
463 | |
464 | TemplateArgumentLoc(const TemplateArgument &Argument, |
465 | TemplateArgumentLocInfo Opaque) |
466 | : Argument(Argument), LocInfo(Opaque) {} |
467 | |
468 | TemplateArgumentLoc(const TemplateArgument &Argument, TypeSourceInfo *TInfo) |
469 | : Argument(Argument), LocInfo(TInfo) { |
470 | assert(Argument.getKind() == TemplateArgument::Type)((Argument.getKind() == TemplateArgument::Type) ? static_cast <void> (0) : __assert_fail ("Argument.getKind() == TemplateArgument::Type" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 470, __PRETTY_FUNCTION__)); |
471 | } |
472 | |
473 | TemplateArgumentLoc(const TemplateArgument &Argument, Expr *E) |
474 | : Argument(Argument), LocInfo(E) { |
475 | |
476 | // Permit any kind of template argument that can be represented with an |
477 | // expression. |
478 | assert(Argument.getKind() == TemplateArgument::NullPtr ||((Argument.getKind() == TemplateArgument::NullPtr || Argument .getKind() == TemplateArgument::Integral || Argument.getKind( ) == TemplateArgument::Declaration || Argument.getKind() == TemplateArgument ::Expression) ? static_cast<void> (0) : __assert_fail ( "Argument.getKind() == TemplateArgument::NullPtr || Argument.getKind() == TemplateArgument::Integral || Argument.getKind() == TemplateArgument::Declaration || Argument.getKind() == TemplateArgument::Expression" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 481, __PRETTY_FUNCTION__)) |
479 | Argument.getKind() == TemplateArgument::Integral ||((Argument.getKind() == TemplateArgument::NullPtr || Argument .getKind() == TemplateArgument::Integral || Argument.getKind( ) == TemplateArgument::Declaration || Argument.getKind() == TemplateArgument ::Expression) ? static_cast<void> (0) : __assert_fail ( "Argument.getKind() == TemplateArgument::NullPtr || Argument.getKind() == TemplateArgument::Integral || Argument.getKind() == TemplateArgument::Declaration || Argument.getKind() == TemplateArgument::Expression" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 481, __PRETTY_FUNCTION__)) |
480 | Argument.getKind() == TemplateArgument::Declaration ||((Argument.getKind() == TemplateArgument::NullPtr || Argument .getKind() == TemplateArgument::Integral || Argument.getKind( ) == TemplateArgument::Declaration || Argument.getKind() == TemplateArgument ::Expression) ? static_cast<void> (0) : __assert_fail ( "Argument.getKind() == TemplateArgument::NullPtr || Argument.getKind() == TemplateArgument::Integral || Argument.getKind() == TemplateArgument::Declaration || Argument.getKind() == TemplateArgument::Expression" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 481, __PRETTY_FUNCTION__)) |
481 | Argument.getKind() == TemplateArgument::Expression)((Argument.getKind() == TemplateArgument::NullPtr || Argument .getKind() == TemplateArgument::Integral || Argument.getKind( ) == TemplateArgument::Declaration || Argument.getKind() == TemplateArgument ::Expression) ? static_cast<void> (0) : __assert_fail ( "Argument.getKind() == TemplateArgument::NullPtr || Argument.getKind() == TemplateArgument::Integral || Argument.getKind() == TemplateArgument::Declaration || Argument.getKind() == TemplateArgument::Expression" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 481, __PRETTY_FUNCTION__)); |
482 | } |
483 | |
484 | TemplateArgumentLoc(ASTContext &Ctx, const TemplateArgument &Argument, |
485 | NestedNameSpecifierLoc QualifierLoc, |
486 | SourceLocation TemplateNameLoc, |
487 | SourceLocation EllipsisLoc = SourceLocation()) |
488 | : Argument(Argument), |
489 | LocInfo(Ctx, QualifierLoc, TemplateNameLoc, EllipsisLoc) { |
490 | assert(Argument.getKind() == TemplateArgument::Template ||((Argument.getKind() == TemplateArgument::Template || Argument .getKind() == TemplateArgument::TemplateExpansion) ? static_cast <void> (0) : __assert_fail ("Argument.getKind() == TemplateArgument::Template || Argument.getKind() == TemplateArgument::TemplateExpansion" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 491, __PRETTY_FUNCTION__)) |
491 | Argument.getKind() == TemplateArgument::TemplateExpansion)((Argument.getKind() == TemplateArgument::Template || Argument .getKind() == TemplateArgument::TemplateExpansion) ? static_cast <void> (0) : __assert_fail ("Argument.getKind() == TemplateArgument::Template || Argument.getKind() == TemplateArgument::TemplateExpansion" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 491, __PRETTY_FUNCTION__)); |
492 | } |
493 | |
494 | /// - Fetches the primary location of the argument. |
495 | SourceLocation getLocation() const { |
496 | if (Argument.getKind() == TemplateArgument::Template || |
497 | Argument.getKind() == TemplateArgument::TemplateExpansion) |
498 | return getTemplateNameLoc(); |
499 | |
500 | return getSourceRange().getBegin(); |
501 | } |
502 | |
503 | /// - Fetches the full source range of the argument. |
504 | SourceRange getSourceRange() const LLVM_READONLY__attribute__((__pure__)); |
505 | |
506 | const TemplateArgument &getArgument() const { |
507 | return Argument; |
508 | } |
509 | |
510 | TemplateArgumentLocInfo getLocInfo() const { |
511 | return LocInfo; |
512 | } |
513 | |
514 | TypeSourceInfo *getTypeSourceInfo() const { |
515 | assert(Argument.getKind() == TemplateArgument::Type)((Argument.getKind() == TemplateArgument::Type) ? static_cast <void> (0) : __assert_fail ("Argument.getKind() == TemplateArgument::Type" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 515, __PRETTY_FUNCTION__)); |
516 | return LocInfo.getAsTypeSourceInfo(); |
517 | } |
518 | |
519 | Expr *getSourceExpression() const { |
520 | assert(Argument.getKind() == TemplateArgument::Expression)((Argument.getKind() == TemplateArgument::Expression) ? static_cast <void> (0) : __assert_fail ("Argument.getKind() == TemplateArgument::Expression" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 520, __PRETTY_FUNCTION__)); |
521 | return LocInfo.getAsExpr(); |
522 | } |
523 | |
524 | Expr *getSourceDeclExpression() const { |
525 | assert(Argument.getKind() == TemplateArgument::Declaration)((Argument.getKind() == TemplateArgument::Declaration) ? static_cast <void> (0) : __assert_fail ("Argument.getKind() == TemplateArgument::Declaration" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 525, __PRETTY_FUNCTION__)); |
526 | return LocInfo.getAsExpr(); |
527 | } |
528 | |
529 | Expr *getSourceNullPtrExpression() const { |
530 | assert(Argument.getKind() == TemplateArgument::NullPtr)((Argument.getKind() == TemplateArgument::NullPtr) ? static_cast <void> (0) : __assert_fail ("Argument.getKind() == TemplateArgument::NullPtr" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 530, __PRETTY_FUNCTION__)); |
531 | return LocInfo.getAsExpr(); |
532 | } |
533 | |
534 | Expr *getSourceIntegralExpression() const { |
535 | assert(Argument.getKind() == TemplateArgument::Integral)((Argument.getKind() == TemplateArgument::Integral) ? static_cast <void> (0) : __assert_fail ("Argument.getKind() == TemplateArgument::Integral" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 535, __PRETTY_FUNCTION__)); |
536 | return LocInfo.getAsExpr(); |
537 | } |
538 | |
539 | NestedNameSpecifierLoc getTemplateQualifierLoc() const { |
540 | if (Argument.getKind() != TemplateArgument::Template && |
541 | Argument.getKind() != TemplateArgument::TemplateExpansion) |
542 | return NestedNameSpecifierLoc(); |
543 | return LocInfo.getTemplateQualifierLoc(); |
544 | } |
545 | |
546 | SourceLocation getTemplateNameLoc() const { |
547 | if (Argument.getKind() != TemplateArgument::Template && |
548 | Argument.getKind() != TemplateArgument::TemplateExpansion) |
549 | return SourceLocation(); |
550 | return LocInfo.getTemplateNameLoc(); |
551 | } |
552 | |
553 | SourceLocation getTemplateEllipsisLoc() const { |
554 | if (Argument.getKind() != TemplateArgument::TemplateExpansion) |
555 | return SourceLocation(); |
556 | return LocInfo.getTemplateEllipsisLoc(); |
557 | } |
558 | }; |
559 | |
560 | /// A convenient class for passing around template argument |
561 | /// information. Designed to be passed by reference. |
562 | class TemplateArgumentListInfo { |
563 | SmallVector<TemplateArgumentLoc, 8> Arguments; |
564 | SourceLocation LAngleLoc; |
565 | SourceLocation RAngleLoc; |
566 | |
567 | public: |
568 | TemplateArgumentListInfo() = default; |
569 | |
570 | TemplateArgumentListInfo(SourceLocation LAngleLoc, |
571 | SourceLocation RAngleLoc) |
572 | : LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc) {} |
573 | |
574 | // This can leak if used in an AST node, use ASTTemplateArgumentListInfo |
575 | // instead. |
576 | void *operator new(size_t bytes, ASTContext &C) = delete; |
577 | |
578 | SourceLocation getLAngleLoc() const { return LAngleLoc; } |
579 | SourceLocation getRAngleLoc() const { return RAngleLoc; } |
580 | |
581 | void setLAngleLoc(SourceLocation Loc) { LAngleLoc = Loc; } |
582 | void setRAngleLoc(SourceLocation Loc) { RAngleLoc = Loc; } |
583 | |
584 | unsigned size() const { return Arguments.size(); } |
585 | |
586 | const TemplateArgumentLoc *getArgumentArray() const { |
587 | return Arguments.data(); |
588 | } |
589 | |
590 | llvm::ArrayRef<TemplateArgumentLoc> arguments() const { |
591 | return Arguments; |
592 | } |
593 | |
594 | const TemplateArgumentLoc &operator[](unsigned I) const { |
595 | return Arguments[I]; |
596 | } |
597 | |
598 | TemplateArgumentLoc &operator[](unsigned I) { |
599 | return Arguments[I]; |
600 | } |
601 | |
602 | void addArgument(const TemplateArgumentLoc &Loc) { |
603 | Arguments.push_back(Loc); |
604 | } |
605 | }; |
606 | |
607 | /// Represents an explicit template argument list in C++, e.g., |
608 | /// the "<int>" in "sort<int>". |
609 | /// This is safe to be used inside an AST node, in contrast with |
610 | /// TemplateArgumentListInfo. |
611 | struct ASTTemplateArgumentListInfo final |
612 | : private llvm::TrailingObjects<ASTTemplateArgumentListInfo, |
613 | TemplateArgumentLoc> { |
614 | private: |
615 | friend class ASTNodeImporter; |
616 | friend TrailingObjects; |
617 | |
618 | ASTTemplateArgumentListInfo(const TemplateArgumentListInfo &List); |
619 | |
620 | public: |
621 | /// The source location of the left angle bracket ('<'). |
622 | SourceLocation LAngleLoc; |
623 | |
624 | /// The source location of the right angle bracket ('>'). |
625 | SourceLocation RAngleLoc; |
626 | |
627 | /// The number of template arguments in TemplateArgs. |
628 | unsigned NumTemplateArgs; |
629 | |
630 | SourceLocation getLAngleLoc() const { return LAngleLoc; } |
631 | SourceLocation getRAngleLoc() const { return RAngleLoc; } |
632 | |
633 | /// Retrieve the template arguments |
634 | const TemplateArgumentLoc *getTemplateArgs() const { |
635 | return getTrailingObjects<TemplateArgumentLoc>(); |
636 | } |
637 | unsigned getNumTemplateArgs() const { return NumTemplateArgs; } |
638 | |
639 | llvm::ArrayRef<TemplateArgumentLoc> arguments() const { |
640 | return llvm::makeArrayRef(getTemplateArgs(), getNumTemplateArgs()); |
641 | } |
642 | |
643 | const TemplateArgumentLoc &operator[](unsigned I) const { |
644 | return getTemplateArgs()[I]; |
645 | } |
646 | |
647 | static const ASTTemplateArgumentListInfo * |
648 | Create(const ASTContext &C, const TemplateArgumentListInfo &List); |
649 | }; |
650 | |
651 | /// Represents an explicit template argument list in C++, e.g., |
652 | /// the "<int>" in "sort<int>". |
653 | /// |
654 | /// It is intended to be used as a trailing object on AST nodes, and |
655 | /// as such, doesn't contain the array of TemplateArgumentLoc itself, |
656 | /// but expects the containing object to also provide storage for |
657 | /// that. |
658 | struct alignas(void *) ASTTemplateKWAndArgsInfo { |
659 | /// The source location of the left angle bracket ('<'). |
660 | SourceLocation LAngleLoc; |
661 | |
662 | /// The source location of the right angle bracket ('>'). |
663 | SourceLocation RAngleLoc; |
664 | |
665 | /// The source location of the template keyword; this is used |
666 | /// as part of the representation of qualified identifiers, such as |
667 | /// S<T>::template apply<T>. Will be empty if this expression does |
668 | /// not have a template keyword. |
669 | SourceLocation TemplateKWLoc; |
670 | |
671 | /// The number of template arguments in TemplateArgs. |
672 | unsigned NumTemplateArgs; |
673 | |
674 | void initializeFrom(SourceLocation TemplateKWLoc, |
675 | const TemplateArgumentListInfo &List, |
676 | TemplateArgumentLoc *OutArgArray); |
677 | // FIXME: The parameter Deps is the result populated by this method, the |
678 | // caller doesn't need it since it is populated by computeDependence. remove |
679 | // it. |
680 | void initializeFrom(SourceLocation TemplateKWLoc, |
681 | const TemplateArgumentListInfo &List, |
682 | TemplateArgumentLoc *OutArgArray, |
683 | TemplateArgumentDependence &Deps); |
684 | void initializeFrom(SourceLocation TemplateKWLoc); |
685 | |
686 | void copyInto(const TemplateArgumentLoc *ArgArray, |
687 | TemplateArgumentListInfo &List) const; |
688 | }; |
689 | |
690 | const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB, |
691 | const TemplateArgument &Arg); |
692 | |
693 | inline TemplateSpecializationType::iterator |
694 | TemplateSpecializationType::end() const { |
695 | return getArgs() + getNumArgs(); |
696 | } |
697 | |
698 | inline DependentTemplateSpecializationType::iterator |
699 | DependentTemplateSpecializationType::end() const { |
700 | return getArgs() + getNumArgs(); |
701 | } |
702 | |
703 | inline const TemplateArgument & |
704 | TemplateSpecializationType::getArg(unsigned Idx) const { |
705 | assert(Idx < getNumArgs() && "Template argument out of range")((Idx < getNumArgs() && "Template argument out of range" ) ? static_cast<void> (0) : __assert_fail ("Idx < getNumArgs() && \"Template argument out of range\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 705, __PRETTY_FUNCTION__)); |
706 | return getArgs()[Idx]; |
707 | } |
708 | |
709 | inline const TemplateArgument & |
710 | DependentTemplateSpecializationType::getArg(unsigned Idx) const { |
711 | assert(Idx < getNumArgs() && "Template argument out of range")((Idx < getNumArgs() && "Template argument out of range" ) ? static_cast<void> (0) : __assert_fail ("Idx < getNumArgs() && \"Template argument out of range\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 711, __PRETTY_FUNCTION__)); |
712 | return getArgs()[Idx]; |
713 | } |
714 | |
715 | inline const TemplateArgument &AutoType::getArg(unsigned Idx) const { |
716 | assert(Idx < getNumArgs() && "Template argument out of range")((Idx < getNumArgs() && "Template argument out of range" ) ? static_cast<void> (0) : __assert_fail ("Idx < getNumArgs() && \"Template argument out of range\"" , "/build/llvm-toolchain-snapshot-12~++20201130111130+b5fbc60e4de/clang/include/clang/AST/TemplateBase.h" , 716, __PRETTY_FUNCTION__)); |
717 | return getArgs()[Idx]; |
718 | } |
719 | |
720 | } // namespace clang |
721 | |
722 | #endif // LLVM_CLANG_AST_TEMPLATEBASE_H |