File: | tools/clang/lib/AST/ASTImporter.cpp |
Warning: | line 265, column 16 3rd function call argument is an uninitialized value |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===// | |||
2 | // | |||
3 | // The LLVM Compiler Infrastructure | |||
4 | // | |||
5 | // This file is distributed under the University of Illinois Open Source | |||
6 | // License. See LICENSE.TXT for details. | |||
7 | // | |||
8 | //===----------------------------------------------------------------------===// | |||
9 | // | |||
10 | // This file defines the ASTImporter class which imports AST nodes from one | |||
11 | // context into another context. | |||
12 | // | |||
13 | //===----------------------------------------------------------------------===// | |||
14 | ||||
15 | #include "clang/AST/ASTImporter.h" | |||
16 | #include "clang/AST/ASTContext.h" | |||
17 | #include "clang/AST/ASTDiagnostic.h" | |||
18 | #include "clang/AST/ASTStructuralEquivalence.h" | |||
19 | #include "clang/AST/Attr.h" | |||
20 | #include "clang/AST/Decl.h" | |||
21 | #include "clang/AST/DeclAccessPair.h" | |||
22 | #include "clang/AST/DeclBase.h" | |||
23 | #include "clang/AST/DeclCXX.h" | |||
24 | #include "clang/AST/DeclFriend.h" | |||
25 | #include "clang/AST/DeclGroup.h" | |||
26 | #include "clang/AST/DeclObjC.h" | |||
27 | #include "clang/AST/DeclTemplate.h" | |||
28 | #include "clang/AST/DeclVisitor.h" | |||
29 | #include "clang/AST/DeclarationName.h" | |||
30 | #include "clang/AST/Expr.h" | |||
31 | #include "clang/AST/ExprCXX.h" | |||
32 | #include "clang/AST/ExprObjC.h" | |||
33 | #include "clang/AST/ExternalASTSource.h" | |||
34 | #include "clang/AST/LambdaCapture.h" | |||
35 | #include "clang/AST/NestedNameSpecifier.h" | |||
36 | #include "clang/AST/OperationKinds.h" | |||
37 | #include "clang/AST/Stmt.h" | |||
38 | #include "clang/AST/StmtCXX.h" | |||
39 | #include "clang/AST/StmtObjC.h" | |||
40 | #include "clang/AST/StmtVisitor.h" | |||
41 | #include "clang/AST/TemplateBase.h" | |||
42 | #include "clang/AST/TemplateName.h" | |||
43 | #include "clang/AST/Type.h" | |||
44 | #include "clang/AST/TypeLoc.h" | |||
45 | #include "clang/AST/TypeVisitor.h" | |||
46 | #include "clang/AST/UnresolvedSet.h" | |||
47 | #include "clang/Basic/ExceptionSpecificationType.h" | |||
48 | #include "clang/Basic/FileManager.h" | |||
49 | #include "clang/Basic/IdentifierTable.h" | |||
50 | #include "clang/Basic/LLVM.h" | |||
51 | #include "clang/Basic/LangOptions.h" | |||
52 | #include "clang/Basic/SourceLocation.h" | |||
53 | #include "clang/Basic/SourceManager.h" | |||
54 | #include "clang/Basic/Specifiers.h" | |||
55 | #include "llvm/ADT/APSInt.h" | |||
56 | #include "llvm/ADT/ArrayRef.h" | |||
57 | #include "llvm/ADT/DenseMap.h" | |||
58 | #include "llvm/ADT/None.h" | |||
59 | #include "llvm/ADT/Optional.h" | |||
60 | #include "llvm/ADT/STLExtras.h" | |||
61 | #include "llvm/ADT/SmallVector.h" | |||
62 | #include "llvm/Support/Casting.h" | |||
63 | #include "llvm/Support/ErrorHandling.h" | |||
64 | #include "llvm/Support/MemoryBuffer.h" | |||
65 | #include <algorithm> | |||
66 | #include <cassert> | |||
67 | #include <cstddef> | |||
68 | #include <memory> | |||
69 | #include <type_traits> | |||
70 | #include <utility> | |||
71 | ||||
72 | namespace clang { | |||
73 | ||||
74 | using llvm::make_error; | |||
75 | using llvm::Error; | |||
76 | using llvm::Expected; | |||
77 | using ExpectedType = llvm::Expected<QualType>; | |||
78 | using ExpectedStmt = llvm::Expected<Stmt *>; | |||
79 | using ExpectedExpr = llvm::Expected<Expr *>; | |||
80 | using ExpectedDecl = llvm::Expected<Decl *>; | |||
81 | using ExpectedSLoc = llvm::Expected<SourceLocation>; | |||
82 | ||||
83 | std::string ImportError::toString() const { | |||
84 | // FIXME: Improve error texts. | |||
85 | switch (Error) { | |||
86 | case NameConflict: | |||
87 | return "NameConflict"; | |||
88 | case UnsupportedConstruct: | |||
89 | return "UnsupportedConstruct"; | |||
90 | case Unknown: | |||
91 | return "Unknown error"; | |||
92 | } | |||
93 | llvm_unreachable("Invalid error code.")::llvm::llvm_unreachable_internal("Invalid error code.", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 93); | |||
94 | return "Invalid error code."; | |||
95 | } | |||
96 | ||||
97 | void ImportError::log(raw_ostream &OS) const { | |||
98 | OS << toString(); | |||
99 | } | |||
100 | ||||
101 | std::error_code ImportError::convertToErrorCode() const { | |||
102 | llvm_unreachable("Function not implemented.")::llvm::llvm_unreachable_internal("Function not implemented." , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 102); | |||
103 | } | |||
104 | ||||
105 | char ImportError::ID; | |||
106 | ||||
107 | template <class T> | |||
108 | SmallVector<Decl *, 2> | |||
109 | getCanonicalForwardRedeclChain(Redeclarable<T>* D) { | |||
110 | SmallVector<Decl *, 2> Redecls; | |||
111 | for (auto *R : D->getFirstDecl()->redecls()) { | |||
112 | if (R != D->getFirstDecl()) | |||
113 | Redecls.push_back(R); | |||
114 | } | |||
115 | Redecls.push_back(D->getFirstDecl()); | |||
116 | std::reverse(Redecls.begin(), Redecls.end()); | |||
117 | return Redecls; | |||
118 | } | |||
119 | ||||
120 | SmallVector<Decl*, 2> getCanonicalForwardRedeclChain(Decl* D) { | |||
121 | if (auto *FD = dyn_cast<FunctionDecl>(D)) | |||
122 | return getCanonicalForwardRedeclChain<FunctionDecl>(FD); | |||
123 | if (auto *VD = dyn_cast<VarDecl>(D)) | |||
124 | return getCanonicalForwardRedeclChain<VarDecl>(VD); | |||
125 | llvm_unreachable("Bad declaration kind")::llvm::llvm_unreachable_internal("Bad declaration kind", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 125); | |||
126 | } | |||
127 | ||||
128 | void updateFlags(const Decl *From, Decl *To) { | |||
129 | // Check if some flags or attrs are new in 'From' and copy into 'To'. | |||
130 | // FIXME: Other flags or attrs? | |||
131 | if (From->isUsed(false) && !To->isUsed(false)) | |||
132 | To->setIsUsed(); | |||
133 | } | |||
134 | ||||
135 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { | |||
136 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&((F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl >(*F)) && "Try to get field index for non-field.") ? static_cast<void> (0) : __assert_fail ("F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && \"Try to get field index for non-field.\"" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 137, __PRETTY_FUNCTION__)) | |||
137 | "Try to get field index for non-field.")((F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl >(*F)) && "Try to get field index for non-field.") ? static_cast<void> (0) : __assert_fail ("F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && \"Try to get field index for non-field.\"" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 137, __PRETTY_FUNCTION__)); | |||
138 | ||||
139 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); | |||
140 | if (!Owner) | |||
141 | return None; | |||
142 | ||||
143 | unsigned Index = 0; | |||
144 | for (const auto *D : Owner->decls()) { | |||
145 | if (D == F) | |||
146 | return Index; | |||
147 | ||||
148 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) | |||
149 | ++Index; | |||
150 | } | |||
151 | ||||
152 | llvm_unreachable("Field was not found in its parent context.")::llvm::llvm_unreachable_internal("Field was not found in its parent context." , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 152); | |||
153 | ||||
154 | return None; | |||
155 | } | |||
156 | ||||
157 | // FIXME: Temporary until every import returns Expected. | |||
158 | template <> | |||
159 | LLVM_NODISCARD[[clang::warn_unused_result]] Error | |||
160 | ASTImporter::importInto(SourceLocation &To, const SourceLocation &From) { | |||
161 | To = Import(From); | |||
162 | if (From.isValid() && To.isInvalid()) | |||
163 | return llvm::make_error<ImportError>(); | |||
164 | return Error::success(); | |||
165 | } | |||
166 | // FIXME: Temporary until every import returns Expected. | |||
167 | template <> | |||
168 | LLVM_NODISCARD[[clang::warn_unused_result]] Error | |||
169 | ASTImporter::importInto(QualType &To, const QualType &From) { | |||
170 | To = Import(From); | |||
171 | if (!From.isNull() && To.isNull()) | |||
172 | return llvm::make_error<ImportError>(); | |||
173 | return Error::success(); | |||
174 | } | |||
175 | ||||
176 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>, | |||
177 | public DeclVisitor<ASTNodeImporter, ExpectedDecl>, | |||
178 | public StmtVisitor<ASTNodeImporter, ExpectedStmt> { | |||
179 | ASTImporter &Importer; | |||
180 | ||||
181 | // Use this instead of Importer.importInto . | |||
182 | template <typename ImportT> | |||
183 | LLVM_NODISCARD[[clang::warn_unused_result]] Error importInto(ImportT &To, const ImportT &From) { | |||
184 | return Importer.importInto(To, From); | |||
185 | } | |||
186 | ||||
187 | // Use this to import pointers of specific type. | |||
188 | template <typename ImportT> | |||
189 | LLVM_NODISCARD[[clang::warn_unused_result]] Error importInto(ImportT *&To, ImportT *From) { | |||
190 | auto ToI = Importer.Import(From); | |||
| ||||
191 | if (!ToI && From) | |||
192 | return make_error<ImportError>(); | |||
193 | To = cast_or_null<ImportT>(ToI); | |||
194 | return Error::success(); | |||
195 | // FIXME: This should be the final code. | |||
196 | //auto ToOrErr = Importer.Import(From); | |||
197 | //if (ToOrErr) { | |||
198 | // To = cast_or_null<ImportT>(*ToOrErr); | |||
199 | //} | |||
200 | //return ToOrErr.takeError(); | |||
201 | } | |||
202 | ||||
203 | // Call the import function of ASTImporter for a baseclass of type `T` and | |||
204 | // cast the return value to `T`. | |||
205 | template <typename T> | |||
206 | Expected<T *> import(T *From) { | |||
207 | auto *To = Importer.Import(From); | |||
208 | if (!To && From) | |||
209 | return make_error<ImportError>(); | |||
210 | return cast_or_null<T>(To); | |||
211 | // FIXME: This should be the final code. | |||
212 | //auto ToOrErr = Importer.Import(From); | |||
213 | //if (!ToOrErr) | |||
214 | // return ToOrErr.takeError(); | |||
215 | //return cast_or_null<T>(*ToOrErr); | |||
216 | } | |||
217 | ||||
218 | template <typename T> | |||
219 | Expected<T *> import(const T *From) { | |||
220 | return import(const_cast<T *>(From)); | |||
221 | } | |||
222 | ||||
223 | // Call the import function of ASTImporter for type `T`. | |||
224 | template <typename T> | |||
225 | Expected<T> import(const T &From) { | |||
226 | T To = Importer.Import(From); | |||
227 | T DefaultT; | |||
228 | if (To == DefaultT && !(From == DefaultT)) | |||
229 | return make_error<ImportError>(); | |||
230 | return To; | |||
231 | // FIXME: This should be the final code. | |||
232 | //return Importer.Import(From); | |||
233 | } | |||
234 | ||||
235 | template <class T> | |||
236 | Expected<std::tuple<T>> | |||
237 | importSeq(const T &From) { | |||
238 | Expected<T> ToOrErr = import(From); | |||
239 | if (!ToOrErr) | |||
240 | return ToOrErr.takeError(); | |||
241 | return std::make_tuple<T>(std::move(*ToOrErr)); | |||
242 | } | |||
243 | ||||
244 | // Import multiple objects with a single function call. | |||
245 | // This should work for every type for which a variant of `import` exists. | |||
246 | // The arguments are processed from left to right and import is stopped on | |||
247 | // first error. | |||
248 | template <class THead, class... TTail> | |||
249 | Expected<std::tuple<THead, TTail...>> | |||
250 | importSeq(const THead &FromHead, const TTail &...FromTail) { | |||
251 | Expected<std::tuple<THead>> ToHeadOrErr = importSeq(FromHead); | |||
252 | if (!ToHeadOrErr) | |||
253 | return ToHeadOrErr.takeError(); | |||
254 | Expected<std::tuple<TTail...>> ToTailOrErr = importSeq(FromTail...); | |||
255 | if (!ToTailOrErr) | |||
256 | return ToTailOrErr.takeError(); | |||
257 | return std::tuple_cat(*ToHeadOrErr, *ToTailOrErr); | |||
258 | } | |||
259 | ||||
260 | // Wrapper for an overload set. | |||
261 | template <typename ToDeclT> struct CallOverloadedCreateFun { | |||
262 | template <typename... Args> | |||
263 | auto operator()(Args &&... args) | |||
264 | -> decltype(ToDeclT::Create(std::forward<Args>(args)...)) { | |||
265 | return ToDeclT::Create(std::forward<Args>(args)...); | |||
| ||||
266 | } | |||
267 | }; | |||
268 | ||||
269 | // Always use these functions to create a Decl during import. There are | |||
270 | // certain tasks which must be done after the Decl was created, e.g. we | |||
271 | // must immediately register that as an imported Decl. The parameter `ToD` | |||
272 | // will be set to the newly created Decl or if had been imported before | |||
273 | // then to the already imported Decl. Returns a bool value set to true if | |||
274 | // the `FromD` had been imported before. | |||
275 | template <typename ToDeclT, typename FromDeclT, typename... Args> | |||
276 | LLVM_NODISCARD[[clang::warn_unused_result]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, | |||
277 | Args &&... args) { | |||
278 | // There may be several overloads of ToDeclT::Create. We must make sure | |||
279 | // to call the one which would be chosen by the arguments, thus we use a | |||
280 | // wrapper for the overload set. | |||
281 | CallOverloadedCreateFun<ToDeclT> OC; | |||
282 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, | |||
283 | std::forward<Args>(args)...); | |||
284 | } | |||
285 | // Use this overload if a special Type is needed to be created. E.g if we | |||
286 | // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl` | |||
287 | // then: | |||
288 | // TypedefNameDecl *ToTypedef; | |||
289 | // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...); | |||
290 | template <typename NewDeclT, typename ToDeclT, typename FromDeclT, | |||
291 | typename... Args> | |||
292 | LLVM_NODISCARD[[clang::warn_unused_result]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, | |||
293 | Args &&... args) { | |||
294 | CallOverloadedCreateFun<NewDeclT> OC; | |||
295 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, | |||
296 | std::forward<Args>(args)...); | |||
297 | } | |||
298 | // Use this version if a special create function must be | |||
299 | // used, e.g. CXXRecordDecl::CreateLambda . | |||
300 | template <typename ToDeclT, typename CreateFunT, typename FromDeclT, | |||
301 | typename... Args> | |||
302 | LLVM_NODISCARD[[clang::warn_unused_result]] bool | |||
303 | GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun, | |||
304 | FromDeclT *FromD, Args &&... args) { | |||
305 | // FIXME: This code is needed later. | |||
306 | //if (Importer.getImportDeclErrorIfAny(FromD)) { | |||
307 | // ToD = nullptr; | |||
308 | // return true; // Already imported but with error. | |||
309 | //} | |||
310 | ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD)); | |||
311 | if (ToD) | |||
312 | return true; // Already imported. | |||
313 | ToD = CreateFun(std::forward<Args>(args)...); | |||
314 | InitializeImportedDecl(FromD, ToD); | |||
315 | return false; // A new Decl is created. | |||
316 | } | |||
317 | ||||
318 | void InitializeImportedDecl(Decl *FromD, Decl *ToD) { | |||
319 | Importer.MapImported(FromD, ToD); | |||
320 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; | |||
321 | if (FromD->hasAttrs()) | |||
322 | for (const Attr *FromAttr : FromD->getAttrs()) | |||
323 | ToD->addAttr(Importer.Import(FromAttr)); | |||
324 | if (FromD->isUsed()) | |||
325 | ToD->setIsUsed(); | |||
326 | if (FromD->isImplicit()) | |||
327 | ToD->setImplicit(); | |||
328 | } | |||
329 | ||||
330 | public: | |||
331 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} | |||
332 | ||||
333 | using TypeVisitor<ASTNodeImporter, ExpectedType>::Visit; | |||
334 | using DeclVisitor<ASTNodeImporter, ExpectedDecl>::Visit; | |||
335 | using StmtVisitor<ASTNodeImporter, ExpectedStmt>::Visit; | |||
336 | ||||
337 | // Importing types | |||
338 | ExpectedType VisitType(const Type *T); | |||
339 | ExpectedType VisitAtomicType(const AtomicType *T); | |||
340 | ExpectedType VisitBuiltinType(const BuiltinType *T); | |||
341 | ExpectedType VisitDecayedType(const DecayedType *T); | |||
342 | ExpectedType VisitComplexType(const ComplexType *T); | |||
343 | ExpectedType VisitPointerType(const PointerType *T); | |||
344 | ExpectedType VisitBlockPointerType(const BlockPointerType *T); | |||
345 | ExpectedType VisitLValueReferenceType(const LValueReferenceType *T); | |||
346 | ExpectedType VisitRValueReferenceType(const RValueReferenceType *T); | |||
347 | ExpectedType VisitMemberPointerType(const MemberPointerType *T); | |||
348 | ExpectedType VisitConstantArrayType(const ConstantArrayType *T); | |||
349 | ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T); | |||
350 | ExpectedType VisitVariableArrayType(const VariableArrayType *T); | |||
351 | ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T); | |||
352 | // FIXME: DependentSizedExtVectorType | |||
353 | ExpectedType VisitVectorType(const VectorType *T); | |||
354 | ExpectedType VisitExtVectorType(const ExtVectorType *T); | |||
355 | ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T); | |||
356 | ExpectedType VisitFunctionProtoType(const FunctionProtoType *T); | |||
357 | ExpectedType VisitUnresolvedUsingType(const UnresolvedUsingType *T); | |||
358 | ExpectedType VisitParenType(const ParenType *T); | |||
359 | ExpectedType VisitTypedefType(const TypedefType *T); | |||
360 | ExpectedType VisitTypeOfExprType(const TypeOfExprType *T); | |||
361 | // FIXME: DependentTypeOfExprType | |||
362 | ExpectedType VisitTypeOfType(const TypeOfType *T); | |||
363 | ExpectedType VisitDecltypeType(const DecltypeType *T); | |||
364 | ExpectedType VisitUnaryTransformType(const UnaryTransformType *T); | |||
365 | ExpectedType VisitAutoType(const AutoType *T); | |||
366 | ExpectedType VisitInjectedClassNameType(const InjectedClassNameType *T); | |||
367 | // FIXME: DependentDecltypeType | |||
368 | ExpectedType VisitRecordType(const RecordType *T); | |||
369 | ExpectedType VisitEnumType(const EnumType *T); | |||
370 | ExpectedType VisitAttributedType(const AttributedType *T); | |||
371 | ExpectedType VisitTemplateTypeParmType(const TemplateTypeParmType *T); | |||
372 | ExpectedType VisitSubstTemplateTypeParmType( | |||
373 | const SubstTemplateTypeParmType *T); | |||
374 | ExpectedType VisitTemplateSpecializationType( | |||
375 | const TemplateSpecializationType *T); | |||
376 | ExpectedType VisitElaboratedType(const ElaboratedType *T); | |||
377 | ExpectedType VisitDependentNameType(const DependentNameType *T); | |||
378 | ExpectedType VisitPackExpansionType(const PackExpansionType *T); | |||
379 | ExpectedType VisitDependentTemplateSpecializationType( | |||
380 | const DependentTemplateSpecializationType *T); | |||
381 | ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T); | |||
382 | ExpectedType VisitObjCObjectType(const ObjCObjectType *T); | |||
383 | ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); | |||
384 | ||||
385 | // Importing declarations | |||
386 | Error ImportDeclParts( | |||
387 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, | |||
388 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc); | |||
389 | Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); | |||
390 | Error ImportDeclarationNameLoc( | |||
391 | const DeclarationNameInfo &From, DeclarationNameInfo &To); | |||
392 | Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); | |||
393 | Error ImportDeclContext( | |||
394 | Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC); | |||
395 | Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To); | |||
396 | ||||
397 | Expected<CXXCastPath> ImportCastPath(CastExpr *E); | |||
398 | ||||
399 | using Designator = DesignatedInitExpr::Designator; | |||
400 | ||||
401 | /// What we should import from the definition. | |||
402 | enum ImportDefinitionKind { | |||
403 | /// Import the default subset of the definition, which might be | |||
404 | /// nothing (if minimal import is set) or might be everything (if minimal | |||
405 | /// import is not set). | |||
406 | IDK_Default, | |||
407 | /// Import everything. | |||
408 | IDK_Everything, | |||
409 | /// Import only the bare bones needed to establish a valid | |||
410 | /// DeclContext. | |||
411 | IDK_Basic | |||
412 | }; | |||
413 | ||||
414 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { | |||
415 | return IDK == IDK_Everything || | |||
416 | (IDK == IDK_Default && !Importer.isMinimalImport()); | |||
417 | } | |||
418 | ||||
419 | Error ImportInitializer(VarDecl *From, VarDecl *To); | |||
420 | Error ImportDefinition( | |||
421 | RecordDecl *From, RecordDecl *To, | |||
422 | ImportDefinitionKind Kind = IDK_Default); | |||
423 | Error ImportDefinition( | |||
424 | EnumDecl *From, EnumDecl *To, | |||
425 | ImportDefinitionKind Kind = IDK_Default); | |||
426 | Error ImportDefinition( | |||
427 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, | |||
428 | ImportDefinitionKind Kind = IDK_Default); | |||
429 | Error ImportDefinition( | |||
430 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, | |||
431 | ImportDefinitionKind Kind = IDK_Default); | |||
432 | Expected<TemplateParameterList *> ImportTemplateParameterList( | |||
433 | TemplateParameterList *Params); | |||
434 | Error ImportTemplateArguments( | |||
435 | const TemplateArgument *FromArgs, unsigned NumFromArgs, | |||
436 | SmallVectorImpl<TemplateArgument> &ToArgs); | |||
437 | Expected<TemplateArgument> | |||
438 | ImportTemplateArgument(const TemplateArgument &From); | |||
439 | ||||
440 | template <typename InContainerTy> | |||
441 | Error ImportTemplateArgumentListInfo( | |||
442 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo); | |||
443 | ||||
444 | template<typename InContainerTy> | |||
445 | Error ImportTemplateArgumentListInfo( | |||
446 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, | |||
447 | const InContainerTy &Container, TemplateArgumentListInfo &Result); | |||
448 | ||||
449 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; | |||
450 | using FunctionTemplateAndArgsTy = | |||
451 | std::tuple<FunctionTemplateDecl *, TemplateArgsTy>; | |||
452 | Expected<FunctionTemplateAndArgsTy> | |||
453 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( | |||
454 | FunctionDecl *FromFD); | |||
455 | ||||
456 | Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); | |||
457 | ||||
458 | bool IsStructuralMatch(Decl *From, Decl *To, bool Complain); | |||
459 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, | |||
460 | bool Complain = true); | |||
461 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, | |||
462 | bool Complain = true); | |||
463 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); | |||
464 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); | |||
465 | bool IsStructuralMatch(FunctionTemplateDecl *From, | |||
466 | FunctionTemplateDecl *To); | |||
467 | bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To); | |||
468 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); | |||
469 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); | |||
470 | ExpectedDecl VisitDecl(Decl *D); | |||
471 | ExpectedDecl VisitImportDecl(ImportDecl *D); | |||
472 | ExpectedDecl VisitEmptyDecl(EmptyDecl *D); | |||
473 | ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D); | |||
474 | ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D); | |||
475 | ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D); | |||
476 | ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D); | |||
477 | ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D); | |||
478 | ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); | |||
479 | ExpectedDecl VisitTypedefDecl(TypedefDecl *D); | |||
480 | ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D); | |||
481 | ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); | |||
482 | ExpectedDecl VisitLabelDecl(LabelDecl *D); | |||
483 | ExpectedDecl VisitEnumDecl(EnumDecl *D); | |||
484 | ExpectedDecl VisitRecordDecl(RecordDecl *D); | |||
485 | ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D); | |||
486 | ExpectedDecl VisitFunctionDecl(FunctionDecl *D); | |||
487 | ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D); | |||
488 | ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); | |||
489 | ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); | |||
490 | ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); | |||
491 | ExpectedDecl VisitFieldDecl(FieldDecl *D); | |||
492 | ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); | |||
493 | ExpectedDecl VisitFriendDecl(FriendDecl *D); | |||
494 | ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D); | |||
495 | ExpectedDecl VisitVarDecl(VarDecl *D); | |||
496 | ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D); | |||
497 | ExpectedDecl VisitParmVarDecl(ParmVarDecl *D); | |||
498 | ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D); | |||
499 | ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); | |||
500 | ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D); | |||
501 | ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D); | |||
502 | ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D); | |||
503 | ExpectedDecl VisitUsingDecl(UsingDecl *D); | |||
504 | ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D); | |||
505 | ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D); | |||
506 | ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); | |||
507 | ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); | |||
508 | ||||
509 | Expected<ObjCTypeParamList *> | |||
510 | ImportObjCTypeParamList(ObjCTypeParamList *list); | |||
511 | ||||
512 | ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); | |||
513 | ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); | |||
514 | ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D); | |||
515 | ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D); | |||
516 | ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); | |||
517 | ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); | |||
518 | ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); | |||
519 | ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); | |||
520 | ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D); | |||
521 | ExpectedDecl VisitClassTemplateSpecializationDecl( | |||
522 | ClassTemplateSpecializationDecl *D); | |||
523 | ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D); | |||
524 | ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); | |||
525 | ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D); | |||
526 | ||||
527 | // Importing statements | |||
528 | ExpectedStmt VisitStmt(Stmt *S); | |||
529 | ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S); | |||
530 | ExpectedStmt VisitDeclStmt(DeclStmt *S); | |||
531 | ExpectedStmt VisitNullStmt(NullStmt *S); | |||
532 | ExpectedStmt VisitCompoundStmt(CompoundStmt *S); | |||
533 | ExpectedStmt VisitCaseStmt(CaseStmt *S); | |||
534 | ExpectedStmt VisitDefaultStmt(DefaultStmt *S); | |||
535 | ExpectedStmt VisitLabelStmt(LabelStmt *S); | |||
536 | ExpectedStmt VisitAttributedStmt(AttributedStmt *S); | |||
537 | ExpectedStmt VisitIfStmt(IfStmt *S); | |||
538 | ExpectedStmt VisitSwitchStmt(SwitchStmt *S); | |||
539 | ExpectedStmt VisitWhileStmt(WhileStmt *S); | |||
540 | ExpectedStmt VisitDoStmt(DoStmt *S); | |||
541 | ExpectedStmt VisitForStmt(ForStmt *S); | |||
542 | ExpectedStmt VisitGotoStmt(GotoStmt *S); | |||
543 | ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S); | |||
544 | ExpectedStmt VisitContinueStmt(ContinueStmt *S); | |||
545 | ExpectedStmt VisitBreakStmt(BreakStmt *S); | |||
546 | ExpectedStmt VisitReturnStmt(ReturnStmt *S); | |||
547 | // FIXME: MSAsmStmt | |||
548 | // FIXME: SEHExceptStmt | |||
549 | // FIXME: SEHFinallyStmt | |||
550 | // FIXME: SEHTryStmt | |||
551 | // FIXME: SEHLeaveStmt | |||
552 | // FIXME: CapturedStmt | |||
553 | ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S); | |||
554 | ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S); | |||
555 | ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S); | |||
556 | // FIXME: MSDependentExistsStmt | |||
557 | ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); | |||
558 | ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); | |||
559 | ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); | |||
560 | ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S); | |||
561 | ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); | |||
562 | ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); | |||
563 | ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); | |||
564 | ||||
565 | // Importing expressions | |||
566 | ExpectedStmt VisitExpr(Expr *E); | |||
567 | ExpectedStmt VisitVAArgExpr(VAArgExpr *E); | |||
568 | ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E); | |||
569 | ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E); | |||
570 | ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E); | |||
571 | ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); | |||
572 | ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E); | |||
573 | ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); | |||
574 | ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E); | |||
575 | ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E); | |||
576 | ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E); | |||
577 | ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E); | |||
578 | ExpectedStmt VisitStringLiteral(StringLiteral *E); | |||
579 | ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E); | |||
580 | ExpectedStmt VisitAtomicExpr(AtomicExpr *E); | |||
581 | ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E); | |||
582 | ExpectedStmt VisitParenExpr(ParenExpr *E); | |||
583 | ExpectedStmt VisitParenListExpr(ParenListExpr *E); | |||
584 | ExpectedStmt VisitStmtExpr(StmtExpr *E); | |||
585 | ExpectedStmt VisitUnaryOperator(UnaryOperator *E); | |||
586 | ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); | |||
587 | ExpectedStmt VisitBinaryOperator(BinaryOperator *E); | |||
588 | ExpectedStmt VisitConditionalOperator(ConditionalOperator *E); | |||
589 | ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E); | |||
590 | ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E); | |||
591 | ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); | |||
592 | ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E); | |||
593 | ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E); | |||
594 | ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E); | |||
595 | ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E); | |||
596 | ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E); | |||
597 | ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE); | |||
598 | ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E); | |||
599 | ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E); | |||
600 | ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); | |||
601 | ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); | |||
602 | ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); | |||
603 | ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); | |||
604 | ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); | |||
605 | ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E); | |||
606 | ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E); | |||
607 | ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E); | |||
608 | ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E); | |||
609 | ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E); | |||
610 | ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E); | |||
611 | ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); | |||
612 | ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); | |||
613 | ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); | |||
614 | ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); | |||
615 | ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); | |||
616 | ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E); | |||
617 | ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E); | |||
618 | ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); | |||
619 | ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); | |||
620 | ExpectedStmt VisitMemberExpr(MemberExpr *E); | |||
621 | ExpectedStmt VisitCallExpr(CallExpr *E); | |||
622 | ExpectedStmt VisitLambdaExpr(LambdaExpr *LE); | |||
623 | ExpectedStmt VisitInitListExpr(InitListExpr *E); | |||
624 | ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); | |||
625 | ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); | |||
626 | ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); | |||
627 | ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); | |||
628 | ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); | |||
629 | ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E); | |||
630 | ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); | |||
631 | ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); | |||
632 | ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); | |||
633 | ||||
634 | template<typename IIter, typename OIter> | |||
635 | Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { | |||
636 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; | |||
637 | for (; Ibegin != Iend; ++Ibegin, ++Obegin) { | |||
638 | Expected<ItemT> ToOrErr = import(*Ibegin); | |||
639 | if (!ToOrErr) | |||
640 | return ToOrErr.takeError(); | |||
641 | *Obegin = *ToOrErr; | |||
642 | } | |||
643 | return Error::success(); | |||
644 | } | |||
645 | ||||
646 | // Import every item from a container structure into an output container. | |||
647 | // If error occurs, stops at first error and returns the error. | |||
648 | // The output container should have space for all needed elements (it is not | |||
649 | // expanded, new items are put into from the beginning). | |||
650 | template<typename InContainerTy, typename OutContainerTy> | |||
651 | Error ImportContainerChecked( | |||
652 | const InContainerTy &InContainer, OutContainerTy &OutContainer) { | |||
653 | return ImportArrayChecked( | |||
654 | InContainer.begin(), InContainer.end(), OutContainer.begin()); | |||
655 | } | |||
656 | ||||
657 | template<typename InContainerTy, typename OIter> | |||
658 | Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { | |||
659 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); | |||
660 | } | |||
661 | ||||
662 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); | |||
663 | ||||
664 | Expected<FunctionDecl *> FindFunctionTemplateSpecialization( | |||
665 | FunctionDecl *FromFD); | |||
666 | }; | |||
667 | ||||
668 | // FIXME: Temporary until every import returns Expected. | |||
669 | template <> | |||
670 | Expected<TemplateName> ASTNodeImporter::import(const TemplateName &From) { | |||
671 | TemplateName To = Importer.Import(From); | |||
672 | if (To.isNull() && !From.isNull()) | |||
673 | return make_error<ImportError>(); | |||
674 | return To; | |||
675 | } | |||
676 | ||||
677 | template <typename InContainerTy> | |||
678 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( | |||
679 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, | |||
680 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { | |||
681 | auto ToLAngleLocOrErr = import(FromLAngleLoc); | |||
682 | if (!ToLAngleLocOrErr) | |||
683 | return ToLAngleLocOrErr.takeError(); | |||
684 | auto ToRAngleLocOrErr = import(FromRAngleLoc); | |||
685 | if (!ToRAngleLocOrErr) | |||
686 | return ToRAngleLocOrErr.takeError(); | |||
687 | ||||
688 | TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr); | |||
689 | if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo)) | |||
690 | return Err; | |||
691 | Result = ToTAInfo; | |||
692 | return Error::success(); | |||
693 | } | |||
694 | ||||
695 | template <> | |||
696 | Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( | |||
697 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { | |||
698 | return ImportTemplateArgumentListInfo( | |||
699 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); | |||
700 | } | |||
701 | ||||
702 | template <> | |||
703 | Error ASTNodeImporter::ImportTemplateArgumentListInfo< | |||
704 | ASTTemplateArgumentListInfo>( | |||
705 | const ASTTemplateArgumentListInfo &From, | |||
706 | TemplateArgumentListInfo &Result) { | |||
707 | return ImportTemplateArgumentListInfo( | |||
708 | From.LAngleLoc, From.RAngleLoc, From.arguments(), Result); | |||
709 | } | |||
710 | ||||
711 | Expected<ASTNodeImporter::FunctionTemplateAndArgsTy> | |||
712 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( | |||
713 | FunctionDecl *FromFD) { | |||
714 | assert(FromFD->getTemplatedKind() ==((FromFD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplateSpecialization ) ? static_cast<void> (0) : __assert_fail ("FromFD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplateSpecialization" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 715, __PRETTY_FUNCTION__)) | |||
715 | FunctionDecl::TK_FunctionTemplateSpecialization)((FromFD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplateSpecialization ) ? static_cast<void> (0) : __assert_fail ("FromFD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplateSpecialization" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 715, __PRETTY_FUNCTION__)); | |||
716 | ||||
717 | FunctionTemplateAndArgsTy Result; | |||
718 | ||||
719 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); | |||
720 | if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate())) | |||
721 | return std::move(Err); | |||
722 | ||||
723 | // Import template arguments. | |||
724 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); | |||
725 | if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), | |||
726 | std::get<1>(Result))) | |||
727 | return std::move(Err); | |||
728 | ||||
729 | return Result; | |||
730 | } | |||
731 | ||||
732 | template <> | |||
733 | Expected<TemplateParameterList *> | |||
734 | ASTNodeImporter::import(TemplateParameterList *From) { | |||
735 | SmallVector<NamedDecl *, 4> To(From->size()); | |||
736 | if (Error Err = ImportContainerChecked(*From, To)) | |||
737 | return std::move(Err); | |||
738 | ||||
739 | ExpectedExpr ToRequiresClause = import(From->getRequiresClause()); | |||
740 | if (!ToRequiresClause) | |||
741 | return ToRequiresClause.takeError(); | |||
742 | ||||
743 | auto ToTemplateLocOrErr = import(From->getTemplateLoc()); | |||
744 | if (!ToTemplateLocOrErr) | |||
745 | return ToTemplateLocOrErr.takeError(); | |||
746 | auto ToLAngleLocOrErr = import(From->getLAngleLoc()); | |||
747 | if (!ToLAngleLocOrErr) | |||
748 | return ToLAngleLocOrErr.takeError(); | |||
749 | auto ToRAngleLocOrErr = import(From->getRAngleLoc()); | |||
750 | if (!ToRAngleLocOrErr) | |||
751 | return ToRAngleLocOrErr.takeError(); | |||
752 | ||||
753 | return TemplateParameterList::Create( | |||
754 | Importer.getToContext(), | |||
755 | *ToTemplateLocOrErr, | |||
756 | *ToLAngleLocOrErr, | |||
757 | To, | |||
758 | *ToRAngleLocOrErr, | |||
759 | *ToRequiresClause); | |||
760 | } | |||
761 | ||||
762 | template <> | |||
763 | Expected<TemplateArgument> | |||
764 | ASTNodeImporter::import(const TemplateArgument &From) { | |||
765 | switch (From.getKind()) { | |||
766 | case TemplateArgument::Null: | |||
767 | return TemplateArgument(); | |||
768 | ||||
769 | case TemplateArgument::Type: { | |||
770 | ExpectedType ToTypeOrErr = import(From.getAsType()); | |||
771 | if (!ToTypeOrErr) | |||
772 | return ToTypeOrErr.takeError(); | |||
773 | return TemplateArgument(*ToTypeOrErr); | |||
774 | } | |||
775 | ||||
776 | case TemplateArgument::Integral: { | |||
777 | ExpectedType ToTypeOrErr = import(From.getIntegralType()); | |||
778 | if (!ToTypeOrErr) | |||
779 | return ToTypeOrErr.takeError(); | |||
780 | return TemplateArgument(From, *ToTypeOrErr); | |||
781 | } | |||
782 | ||||
783 | case TemplateArgument::Declaration: { | |||
784 | Expected<ValueDecl *> ToOrErr = import(From.getAsDecl()); | |||
785 | if (!ToOrErr) | |||
786 | return ToOrErr.takeError(); | |||
787 | ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); | |||
788 | if (!ToTypeOrErr) | |||
789 | return ToTypeOrErr.takeError(); | |||
790 | return TemplateArgument(*ToOrErr, *ToTypeOrErr); | |||
791 | } | |||
792 | ||||
793 | case TemplateArgument::NullPtr: { | |||
794 | ExpectedType ToTypeOrErr = import(From.getNullPtrType()); | |||
795 | if (!ToTypeOrErr) | |||
796 | return ToTypeOrErr.takeError(); | |||
797 | return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); | |||
798 | } | |||
799 | ||||
800 | case TemplateArgument::Template: { | |||
801 | Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate()); | |||
802 | if (!ToTemplateOrErr) | |||
803 | return ToTemplateOrErr.takeError(); | |||
804 | ||||
805 | return TemplateArgument(*ToTemplateOrErr); | |||
806 | } | |||
807 | ||||
808 | case TemplateArgument::TemplateExpansion: { | |||
809 | Expected<TemplateName> ToTemplateOrErr = | |||
810 | import(From.getAsTemplateOrTemplatePattern()); | |||
811 | if (!ToTemplateOrErr) | |||
812 | return ToTemplateOrErr.takeError(); | |||
813 | ||||
814 | return TemplateArgument( | |||
815 | *ToTemplateOrErr, From.getNumTemplateExpansions()); | |||
816 | } | |||
817 | ||||
818 | case TemplateArgument::Expression: | |||
819 | if (ExpectedExpr ToExpr = import(From.getAsExpr())) | |||
820 | return TemplateArgument(*ToExpr); | |||
821 | else | |||
822 | return ToExpr.takeError(); | |||
823 | ||||
824 | case TemplateArgument::Pack: { | |||
825 | SmallVector<TemplateArgument, 2> ToPack; | |||
826 | ToPack.reserve(From.pack_size()); | |||
827 | if (Error Err = ImportTemplateArguments( | |||
828 | From.pack_begin(), From.pack_size(), ToPack)) | |||
829 | return std::move(Err); | |||
830 | ||||
831 | return TemplateArgument( | |||
832 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); | |||
833 | } | |||
834 | } | |||
835 | ||||
836 | llvm_unreachable("Invalid template argument kind")::llvm::llvm_unreachable_internal("Invalid template argument kind" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 836); | |||
837 | } | |||
838 | ||||
839 | template <> | |||
840 | Expected<TemplateArgumentLoc> | |||
841 | ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) { | |||
842 | Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument()); | |||
843 | if (!ArgOrErr) | |||
844 | return ArgOrErr.takeError(); | |||
845 | TemplateArgument Arg = *ArgOrErr; | |||
846 | ||||
847 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); | |||
848 | ||||
849 | TemplateArgumentLocInfo ToInfo; | |||
850 | if (Arg.getKind() == TemplateArgument::Expression) { | |||
851 | ExpectedExpr E = import(FromInfo.getAsExpr()); | |||
852 | if (!E) | |||
853 | return E.takeError(); | |||
854 | ToInfo = TemplateArgumentLocInfo(*E); | |||
855 | } else if (Arg.getKind() == TemplateArgument::Type) { | |||
856 | if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo())) | |||
857 | ToInfo = TemplateArgumentLocInfo(*TSIOrErr); | |||
858 | else | |||
859 | return TSIOrErr.takeError(); | |||
860 | } else { | |||
861 | auto ToTemplateQualifierLocOrErr = | |||
862 | import(FromInfo.getTemplateQualifierLoc()); | |||
863 | if (!ToTemplateQualifierLocOrErr) | |||
864 | return ToTemplateQualifierLocOrErr.takeError(); | |||
865 | auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc()); | |||
866 | if (!ToTemplateNameLocOrErr) | |||
867 | return ToTemplateNameLocOrErr.takeError(); | |||
868 | auto ToTemplateEllipsisLocOrErr = | |||
869 | import(FromInfo.getTemplateEllipsisLoc()); | |||
870 | if (!ToTemplateEllipsisLocOrErr) | |||
871 | return ToTemplateEllipsisLocOrErr.takeError(); | |||
872 | ||||
873 | ToInfo = TemplateArgumentLocInfo( | |||
874 | *ToTemplateQualifierLocOrErr, | |||
875 | *ToTemplateNameLocOrErr, | |||
876 | *ToTemplateEllipsisLocOrErr); | |||
877 | } | |||
878 | ||||
879 | return TemplateArgumentLoc(Arg, ToInfo); | |||
880 | } | |||
881 | ||||
882 | template <> | |||
883 | Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) { | |||
884 | if (DG.isNull()) | |||
885 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); | |||
886 | size_t NumDecls = DG.end() - DG.begin(); | |||
887 | SmallVector<Decl *, 1> ToDecls; | |||
888 | ToDecls.reserve(NumDecls); | |||
889 | for (Decl *FromD : DG) { | |||
890 | if (auto ToDOrErr = import(FromD)) | |||
891 | ToDecls.push_back(*ToDOrErr); | |||
892 | else | |||
893 | return ToDOrErr.takeError(); | |||
894 | } | |||
895 | return DeclGroupRef::Create(Importer.getToContext(), | |||
896 | ToDecls.begin(), | |||
897 | NumDecls); | |||
898 | } | |||
899 | ||||
900 | template <> | |||
901 | Expected<ASTNodeImporter::Designator> | |||
902 | ASTNodeImporter::import(const Designator &D) { | |||
903 | if (D.isFieldDesignator()) { | |||
904 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); | |||
905 | ||||
906 | ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc()); | |||
907 | if (!ToDotLocOrErr) | |||
908 | return ToDotLocOrErr.takeError(); | |||
909 | ||||
910 | ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc()); | |||
911 | if (!ToFieldLocOrErr) | |||
912 | return ToFieldLocOrErr.takeError(); | |||
913 | ||||
914 | return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr); | |||
915 | } | |||
916 | ||||
917 | ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc()); | |||
918 | if (!ToLBracketLocOrErr) | |||
919 | return ToLBracketLocOrErr.takeError(); | |||
920 | ||||
921 | ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc()); | |||
922 | if (!ToRBracketLocOrErr) | |||
923 | return ToRBracketLocOrErr.takeError(); | |||
924 | ||||
925 | if (D.isArrayDesignator()) | |||
926 | return Designator(D.getFirstExprIndex(), | |||
927 | *ToLBracketLocOrErr, *ToRBracketLocOrErr); | |||
928 | ||||
929 | ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc()); | |||
930 | if (!ToEllipsisLocOrErr) | |||
931 | return ToEllipsisLocOrErr.takeError(); | |||
932 | ||||
933 | assert(D.isArrayRangeDesignator())((D.isArrayRangeDesignator()) ? static_cast<void> (0) : __assert_fail ("D.isArrayRangeDesignator()", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 933, __PRETTY_FUNCTION__)); | |||
934 | return Designator( | |||
935 | D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr, | |||
936 | *ToRBracketLocOrErr); | |||
937 | } | |||
938 | ||||
939 | template <> | |||
940 | Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) { | |||
941 | VarDecl *Var = nullptr; | |||
942 | if (From.capturesVariable()) { | |||
943 | if (auto VarOrErr = import(From.getCapturedVar())) | |||
944 | Var = *VarOrErr; | |||
945 | else | |||
946 | return VarOrErr.takeError(); | |||
947 | } | |||
948 | ||||
949 | auto LocationOrErr = import(From.getLocation()); | |||
950 | if (!LocationOrErr) | |||
951 | return LocationOrErr.takeError(); | |||
952 | ||||
953 | SourceLocation EllipsisLoc; | |||
954 | if (From.isPackExpansion()) | |||
955 | if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc())) | |||
956 | return std::move(Err); | |||
957 | ||||
958 | return LambdaCapture( | |||
959 | *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var, | |||
960 | EllipsisLoc); | |||
961 | } | |||
962 | ||||
963 | } // namespace clang | |||
964 | ||||
965 | //---------------------------------------------------------------------------- | |||
966 | // Import Types | |||
967 | //---------------------------------------------------------------------------- | |||
968 | ||||
969 | using namespace clang; | |||
970 | ||||
971 | ExpectedType ASTNodeImporter::VisitType(const Type *T) { | |||
972 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) | |||
973 | << T->getTypeClassName(); | |||
974 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
975 | } | |||
976 | ||||
977 | ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ | |||
978 | ExpectedType UnderlyingTypeOrErr = import(T->getValueType()); | |||
979 | if (!UnderlyingTypeOrErr) | |||
980 | return UnderlyingTypeOrErr.takeError(); | |||
981 | ||||
982 | return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr); | |||
983 | } | |||
984 | ||||
985 | ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { | |||
986 | switch (T->getKind()) { | |||
987 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ | |||
988 | case BuiltinType::Id: \ | |||
989 | return Importer.getToContext().SingletonId; | |||
990 | #include "clang/Basic/OpenCLImageTypes.def" | |||
991 | #define SHARED_SINGLETON_TYPE(Expansion) | |||
992 | #define BUILTIN_TYPE(Id, SingletonId) \ | |||
993 | case BuiltinType::Id: return Importer.getToContext().SingletonId; | |||
994 | #include "clang/AST/BuiltinTypes.def" | |||
995 | ||||
996 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" | |||
997 | // context supports C++. | |||
998 | ||||
999 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" | |||
1000 | // context supports ObjC. | |||
1001 | ||||
1002 | case BuiltinType::Char_U: | |||
1003 | // The context we're importing from has an unsigned 'char'. If we're | |||
1004 | // importing into a context with a signed 'char', translate to | |||
1005 | // 'unsigned char' instead. | |||
1006 | if (Importer.getToContext().getLangOpts().CharIsSigned) | |||
1007 | return Importer.getToContext().UnsignedCharTy; | |||
1008 | ||||
1009 | return Importer.getToContext().CharTy; | |||
1010 | ||||
1011 | case BuiltinType::Char_S: | |||
1012 | // The context we're importing from has an unsigned 'char'. If we're | |||
1013 | // importing into a context with a signed 'char', translate to | |||
1014 | // 'unsigned char' instead. | |||
1015 | if (!Importer.getToContext().getLangOpts().CharIsSigned) | |||
1016 | return Importer.getToContext().SignedCharTy; | |||
1017 | ||||
1018 | return Importer.getToContext().CharTy; | |||
1019 | ||||
1020 | case BuiltinType::WChar_S: | |||
1021 | case BuiltinType::WChar_U: | |||
1022 | // FIXME: If not in C++, shall we translate to the C equivalent of | |||
1023 | // wchar_t? | |||
1024 | return Importer.getToContext().WCharTy; | |||
1025 | } | |||
1026 | ||||
1027 | llvm_unreachable("Invalid BuiltinType Kind!")::llvm::llvm_unreachable_internal("Invalid BuiltinType Kind!" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 1027); | |||
1028 | } | |||
1029 | ||||
1030 | ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { | |||
1031 | ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType()); | |||
1032 | if (!ToOriginalTypeOrErr) | |||
1033 | return ToOriginalTypeOrErr.takeError(); | |||
1034 | ||||
1035 | return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr); | |||
1036 | } | |||
1037 | ||||
1038 | ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) { | |||
1039 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | |||
1040 | if (!ToElementTypeOrErr) | |||
1041 | return ToElementTypeOrErr.takeError(); | |||
1042 | ||||
1043 | return Importer.getToContext().getComplexType(*ToElementTypeOrErr); | |||
1044 | } | |||
1045 | ||||
1046 | ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) { | |||
1047 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | |||
1048 | if (!ToPointeeTypeOrErr) | |||
1049 | return ToPointeeTypeOrErr.takeError(); | |||
1050 | ||||
1051 | return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr); | |||
1052 | } | |||
1053 | ||||
1054 | ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { | |||
1055 | // FIXME: Check for blocks support in "to" context. | |||
1056 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | |||
1057 | if (!ToPointeeTypeOrErr) | |||
1058 | return ToPointeeTypeOrErr.takeError(); | |||
1059 | ||||
1060 | return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr); | |||
1061 | } | |||
1062 | ||||
1063 | ExpectedType | |||
1064 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { | |||
1065 | // FIXME: Check for C++ support in "to" context. | |||
1066 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); | |||
1067 | if (!ToPointeeTypeOrErr) | |||
1068 | return ToPointeeTypeOrErr.takeError(); | |||
1069 | ||||
1070 | return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr); | |||
1071 | } | |||
1072 | ||||
1073 | ExpectedType | |||
1074 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { | |||
1075 | // FIXME: Check for C++0x support in "to" context. | |||
1076 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); | |||
1077 | if (!ToPointeeTypeOrErr) | |||
1078 | return ToPointeeTypeOrErr.takeError(); | |||
1079 | ||||
1080 | return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr); | |||
1081 | } | |||
1082 | ||||
1083 | ExpectedType | |||
1084 | ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { | |||
1085 | // FIXME: Check for C++ support in "to" context. | |||
1086 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | |||
1087 | if (!ToPointeeTypeOrErr) | |||
1088 | return ToPointeeTypeOrErr.takeError(); | |||
1089 | ||||
1090 | ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0)); | |||
1091 | if (!ClassTypeOrErr) | |||
1092 | return ClassTypeOrErr.takeError(); | |||
1093 | ||||
1094 | return Importer.getToContext().getMemberPointerType( | |||
1095 | *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr()); | |||
1096 | } | |||
1097 | ||||
1098 | ExpectedType | |||
1099 | ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { | |||
1100 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | |||
1101 | if (!ToElementTypeOrErr) | |||
1102 | return ToElementTypeOrErr.takeError(); | |||
1103 | ||||
1104 | return Importer.getToContext().getConstantArrayType(*ToElementTypeOrErr, | |||
1105 | T->getSize(), | |||
1106 | T->getSizeModifier(), | |||
1107 | T->getIndexTypeCVRQualifiers()); | |||
1108 | } | |||
1109 | ||||
1110 | ExpectedType | |||
1111 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { | |||
1112 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | |||
1113 | if (!ToElementTypeOrErr) | |||
1114 | return ToElementTypeOrErr.takeError(); | |||
1115 | ||||
1116 | return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr, | |||
1117 | T->getSizeModifier(), | |||
1118 | T->getIndexTypeCVRQualifiers()); | |||
1119 | } | |||
1120 | ||||
1121 | ExpectedType | |||
1122 | ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { | |||
1123 | QualType ToElementType; | |||
1124 | Expr *ToSizeExpr; | |||
1125 | SourceRange ToBracketsRange; | |||
1126 | if (auto Imp = importSeq( | |||
1127 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) | |||
1128 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; | |||
1129 | else | |||
1130 | return Imp.takeError(); | |||
1131 | ||||
1132 | return Importer.getToContext().getVariableArrayType( | |||
1133 | ToElementType, ToSizeExpr, T->getSizeModifier(), | |||
1134 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); | |||
1135 | } | |||
1136 | ||||
1137 | ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( | |||
1138 | const DependentSizedArrayType *T) { | |||
1139 | QualType ToElementType; | |||
1140 | Expr *ToSizeExpr; | |||
1141 | SourceRange ToBracketsRange; | |||
1142 | if (auto Imp = importSeq( | |||
1143 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) | |||
1144 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; | |||
1145 | else | |||
1146 | return Imp.takeError(); | |||
1147 | // SizeExpr may be null if size is not specified directly. | |||
1148 | // For example, 'int a[]'. | |||
1149 | ||||
1150 | return Importer.getToContext().getDependentSizedArrayType( | |||
1151 | ToElementType, ToSizeExpr, T->getSizeModifier(), | |||
1152 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); | |||
1153 | } | |||
1154 | ||||
1155 | ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) { | |||
1156 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | |||
1157 | if (!ToElementTypeOrErr) | |||
1158 | return ToElementTypeOrErr.takeError(); | |||
1159 | ||||
1160 | return Importer.getToContext().getVectorType(*ToElementTypeOrErr, | |||
1161 | T->getNumElements(), | |||
1162 | T->getVectorKind()); | |||
1163 | } | |||
1164 | ||||
1165 | ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { | |||
1166 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | |||
1167 | if (!ToElementTypeOrErr) | |||
1168 | return ToElementTypeOrErr.takeError(); | |||
1169 | ||||
1170 | return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr, | |||
1171 | T->getNumElements()); | |||
1172 | } | |||
1173 | ||||
1174 | ExpectedType | |||
1175 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { | |||
1176 | // FIXME: What happens if we're importing a function without a prototype | |||
1177 | // into C++? Should we make it variadic? | |||
1178 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); | |||
1179 | if (!ToReturnTypeOrErr) | |||
1180 | return ToReturnTypeOrErr.takeError(); | |||
1181 | ||||
1182 | return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr, | |||
1183 | T->getExtInfo()); | |||
1184 | } | |||
1185 | ||||
1186 | ExpectedType | |||
1187 | ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { | |||
1188 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); | |||
1189 | if (!ToReturnTypeOrErr) | |||
1190 | return ToReturnTypeOrErr.takeError(); | |||
1191 | ||||
1192 | // Import argument types | |||
1193 | SmallVector<QualType, 4> ArgTypes; | |||
1194 | for (const auto &A : T->param_types()) { | |||
1195 | ExpectedType TyOrErr = import(A); | |||
1196 | if (!TyOrErr) | |||
1197 | return TyOrErr.takeError(); | |||
1198 | ArgTypes.push_back(*TyOrErr); | |||
1199 | } | |||
1200 | ||||
1201 | // Import exception types | |||
1202 | SmallVector<QualType, 4> ExceptionTypes; | |||
1203 | for (const auto &E : T->exceptions()) { | |||
1204 | ExpectedType TyOrErr = import(E); | |||
1205 | if (!TyOrErr) | |||
1206 | return TyOrErr.takeError(); | |||
1207 | ExceptionTypes.push_back(*TyOrErr); | |||
1208 | } | |||
1209 | ||||
1210 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); | |||
1211 | FunctionProtoType::ExtProtoInfo ToEPI; | |||
1212 | ||||
1213 | auto Imp = importSeq( | |||
1214 | FromEPI.ExceptionSpec.NoexceptExpr, | |||
1215 | FromEPI.ExceptionSpec.SourceDecl, | |||
1216 | FromEPI.ExceptionSpec.SourceTemplate); | |||
1217 | if (!Imp) | |||
1218 | return Imp.takeError(); | |||
1219 | ||||
1220 | ToEPI.ExtInfo = FromEPI.ExtInfo; | |||
1221 | ToEPI.Variadic = FromEPI.Variadic; | |||
1222 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; | |||
1223 | ToEPI.TypeQuals = FromEPI.TypeQuals; | |||
1224 | ToEPI.RefQualifier = FromEPI.RefQualifier; | |||
1225 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; | |||
1226 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; | |||
1227 | std::tie( | |||
1228 | ToEPI.ExceptionSpec.NoexceptExpr, | |||
1229 | ToEPI.ExceptionSpec.SourceDecl, | |||
1230 | ToEPI.ExceptionSpec.SourceTemplate) = *Imp; | |||
1231 | ||||
1232 | return Importer.getToContext().getFunctionType( | |||
1233 | *ToReturnTypeOrErr, ArgTypes, ToEPI); | |||
1234 | } | |||
1235 | ||||
1236 | ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( | |||
1237 | const UnresolvedUsingType *T) { | |||
1238 | UnresolvedUsingTypenameDecl *ToD; | |||
1239 | Decl *ToPrevD; | |||
1240 | if (auto Imp = importSeq(T->getDecl(), T->getDecl()->getPreviousDecl())) | |||
1241 | std::tie(ToD, ToPrevD) = *Imp; | |||
1242 | else | |||
1243 | return Imp.takeError(); | |||
1244 | ||||
1245 | return Importer.getToContext().getTypeDeclType( | |||
1246 | ToD, cast_or_null<TypeDecl>(ToPrevD)); | |||
1247 | } | |||
1248 | ||||
1249 | ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) { | |||
1250 | ExpectedType ToInnerTypeOrErr = import(T->getInnerType()); | |||
1251 | if (!ToInnerTypeOrErr) | |||
1252 | return ToInnerTypeOrErr.takeError(); | |||
1253 | ||||
1254 | return Importer.getToContext().getParenType(*ToInnerTypeOrErr); | |||
1255 | } | |||
1256 | ||||
1257 | ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { | |||
1258 | Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl()); | |||
1259 | if (!ToDeclOrErr) | |||
1260 | return ToDeclOrErr.takeError(); | |||
1261 | ||||
1262 | return Importer.getToContext().getTypeDeclType(*ToDeclOrErr); | |||
1263 | } | |||
1264 | ||||
1265 | ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { | |||
1266 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); | |||
1267 | if (!ToExprOrErr) | |||
1268 | return ToExprOrErr.takeError(); | |||
1269 | ||||
1270 | return Importer.getToContext().getTypeOfExprType(*ToExprOrErr); | |||
1271 | } | |||
1272 | ||||
1273 | ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { | |||
1274 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | |||
1275 | if (!ToUnderlyingTypeOrErr) | |||
1276 | return ToUnderlyingTypeOrErr.takeError(); | |||
1277 | ||||
1278 | return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr); | |||
1279 | } | |||
1280 | ||||
1281 | ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { | |||
1282 | // FIXME: Make sure that the "to" context supports C++0x! | |||
1283 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); | |||
1284 | if (!ToExprOrErr) | |||
1285 | return ToExprOrErr.takeError(); | |||
1286 | ||||
1287 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | |||
1288 | if (!ToUnderlyingTypeOrErr) | |||
1289 | return ToUnderlyingTypeOrErr.takeError(); | |||
1290 | ||||
1291 | return Importer.getToContext().getDecltypeType( | |||
1292 | *ToExprOrErr, *ToUnderlyingTypeOrErr); | |||
1293 | } | |||
1294 | ||||
1295 | ExpectedType | |||
1296 | ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { | |||
1297 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); | |||
1298 | if (!ToBaseTypeOrErr) | |||
1299 | return ToBaseTypeOrErr.takeError(); | |||
1300 | ||||
1301 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | |||
1302 | if (!ToUnderlyingTypeOrErr) | |||
1303 | return ToUnderlyingTypeOrErr.takeError(); | |||
1304 | ||||
1305 | return Importer.getToContext().getUnaryTransformType( | |||
1306 | *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind()); | |||
1307 | } | |||
1308 | ||||
1309 | ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) { | |||
1310 | // FIXME: Make sure that the "to" context supports C++11! | |||
1311 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); | |||
1312 | if (!ToDeducedTypeOrErr) | |||
1313 | return ToDeducedTypeOrErr.takeError(); | |||
1314 | ||||
1315 | return Importer.getToContext().getAutoType(*ToDeducedTypeOrErr, | |||
1316 | T->getKeyword(), | |||
1317 | /*IsDependent*/false); | |||
1318 | } | |||
1319 | ||||
1320 | ExpectedType ASTNodeImporter::VisitInjectedClassNameType( | |||
1321 | const InjectedClassNameType *T) { | |||
1322 | Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl()); | |||
1323 | if (!ToDeclOrErr) | |||
1324 | return ToDeclOrErr.takeError(); | |||
1325 | ||||
1326 | ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType()); | |||
1327 | if (!ToInjTypeOrErr) | |||
1328 | return ToInjTypeOrErr.takeError(); | |||
1329 | ||||
1330 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading | |||
1331 | // See comments in InjectedClassNameType definition for details | |||
1332 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); | |||
1333 | enum { | |||
1334 | TypeAlignmentInBits = 4, | |||
1335 | TypeAlignment = 1 << TypeAlignmentInBits | |||
1336 | }; | |||
1337 | ||||
1338 | return QualType(new (Importer.getToContext(), TypeAlignment) | |||
1339 | InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0); | |||
1340 | } | |||
1341 | ||||
1342 | ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) { | |||
1343 | Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl()); | |||
1344 | if (!ToDeclOrErr) | |||
1345 | return ToDeclOrErr.takeError(); | |||
1346 | ||||
1347 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); | |||
1348 | } | |||
1349 | ||||
1350 | ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) { | |||
1351 | Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl()); | |||
1352 | if (!ToDeclOrErr) | |||
1353 | return ToDeclOrErr.takeError(); | |||
1354 | ||||
1355 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); | |||
1356 | } | |||
1357 | ||||
1358 | ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { | |||
1359 | ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType()); | |||
1360 | if (!ToModifiedTypeOrErr) | |||
1361 | return ToModifiedTypeOrErr.takeError(); | |||
1362 | ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType()); | |||
1363 | if (!ToEquivalentTypeOrErr) | |||
1364 | return ToEquivalentTypeOrErr.takeError(); | |||
1365 | ||||
1366 | return Importer.getToContext().getAttributedType(T->getAttrKind(), | |||
1367 | *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr); | |||
1368 | } | |||
1369 | ||||
1370 | ExpectedType ASTNodeImporter::VisitTemplateTypeParmType( | |||
1371 | const TemplateTypeParmType *T) { | |||
1372 | Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl()); | |||
1373 | if (!ToDeclOrErr) | |||
1374 | return ToDeclOrErr.takeError(); | |||
1375 | ||||
1376 | return Importer.getToContext().getTemplateTypeParmType( | |||
1377 | T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr); | |||
1378 | } | |||
1379 | ||||
1380 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( | |||
1381 | const SubstTemplateTypeParmType *T) { | |||
1382 | ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); | |||
1383 | if (!ReplacedOrErr) | |||
1384 | return ReplacedOrErr.takeError(); | |||
1385 | const TemplateTypeParmType *Replaced = | |||
1386 | cast<TemplateTypeParmType>((*ReplacedOrErr).getTypePtr()); | |||
1387 | ||||
1388 | ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); | |||
1389 | if (!ToReplacementTypeOrErr) | |||
1390 | return ToReplacementTypeOrErr.takeError(); | |||
1391 | ||||
1392 | return Importer.getToContext().getSubstTemplateTypeParmType( | |||
1393 | Replaced, (*ToReplacementTypeOrErr).getCanonicalType()); | |||
1394 | } | |||
1395 | ||||
1396 | ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( | |||
1397 | const TemplateSpecializationType *T) { | |||
1398 | auto ToTemplateOrErr = import(T->getTemplateName()); | |||
1399 | if (!ToTemplateOrErr) | |||
1400 | return ToTemplateOrErr.takeError(); | |||
1401 | ||||
1402 | SmallVector<TemplateArgument, 2> ToTemplateArgs; | |||
1403 | if (Error Err = ImportTemplateArguments( | |||
1404 | T->getArgs(), T->getNumArgs(), ToTemplateArgs)) | |||
1405 | return std::move(Err); | |||
1406 | ||||
1407 | QualType ToCanonType; | |||
1408 | if (!QualType(T, 0).isCanonical()) { | |||
1409 | QualType FromCanonType | |||
1410 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); | |||
1411 | if (ExpectedType TyOrErr = import(FromCanonType)) | |||
1412 | ToCanonType = *TyOrErr; | |||
1413 | else | |||
1414 | return TyOrErr.takeError(); | |||
1415 | } | |||
1416 | return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr, | |||
1417 | ToTemplateArgs, | |||
1418 | ToCanonType); | |||
1419 | } | |||
1420 | ||||
1421 | ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { | |||
1422 | // Note: the qualifier in an ElaboratedType is optional. | |||
1423 | auto ToQualifierOrErr = import(T->getQualifier()); | |||
1424 | if (!ToQualifierOrErr) | |||
1425 | return ToQualifierOrErr.takeError(); | |||
1426 | ||||
1427 | ExpectedType ToNamedTypeOrErr = import(T->getNamedType()); | |||
1428 | if (!ToNamedTypeOrErr) | |||
1429 | return ToNamedTypeOrErr.takeError(); | |||
1430 | ||||
1431 | Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl()); | |||
1432 | if (!ToOwnedTagDeclOrErr) | |||
1433 | return ToOwnedTagDeclOrErr.takeError(); | |||
1434 | ||||
1435 | return Importer.getToContext().getElaboratedType(T->getKeyword(), | |||
1436 | *ToQualifierOrErr, | |||
1437 | *ToNamedTypeOrErr, | |||
1438 | *ToOwnedTagDeclOrErr); | |||
1439 | } | |||
1440 | ||||
1441 | ExpectedType | |||
1442 | ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { | |||
1443 | ExpectedType ToPatternOrErr = import(T->getPattern()); | |||
1444 | if (!ToPatternOrErr) | |||
1445 | return ToPatternOrErr.takeError(); | |||
1446 | ||||
1447 | return Importer.getToContext().getPackExpansionType(*ToPatternOrErr, | |||
1448 | T->getNumExpansions()); | |||
1449 | } | |||
1450 | ||||
1451 | ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType( | |||
1452 | const DependentTemplateSpecializationType *T) { | |||
1453 | auto ToQualifierOrErr = import(T->getQualifier()); | |||
1454 | if (!ToQualifierOrErr) | |||
1455 | return ToQualifierOrErr.takeError(); | |||
1456 | ||||
1457 | IdentifierInfo *ToName = Importer.Import(T->getIdentifier()); | |||
1458 | ||||
1459 | SmallVector<TemplateArgument, 2> ToPack; | |||
1460 | ToPack.reserve(T->getNumArgs()); | |||
1461 | if (Error Err = ImportTemplateArguments( | |||
1462 | T->getArgs(), T->getNumArgs(), ToPack)) | |||
1463 | return std::move(Err); | |||
1464 | ||||
1465 | return Importer.getToContext().getDependentTemplateSpecializationType( | |||
1466 | T->getKeyword(), *ToQualifierOrErr, ToName, ToPack); | |||
1467 | } | |||
1468 | ||||
1469 | ExpectedType | |||
1470 | ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { | |||
1471 | auto ToQualifierOrErr = import(T->getQualifier()); | |||
1472 | if (!ToQualifierOrErr) | |||
1473 | return ToQualifierOrErr.takeError(); | |||
1474 | ||||
1475 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); | |||
1476 | ||||
1477 | QualType Canon; | |||
1478 | if (T != T->getCanonicalTypeInternal().getTypePtr()) { | |||
1479 | if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal())) | |||
1480 | Canon = (*TyOrErr).getCanonicalType(); | |||
1481 | else | |||
1482 | return TyOrErr.takeError(); | |||
1483 | } | |||
1484 | ||||
1485 | return Importer.getToContext().getDependentNameType(T->getKeyword(), | |||
1486 | *ToQualifierOrErr, | |||
1487 | Name, Canon); | |||
1488 | } | |||
1489 | ||||
1490 | ExpectedType | |||
1491 | ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { | |||
1492 | Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl()); | |||
1493 | if (!ToDeclOrErr) | |||
1494 | return ToDeclOrErr.takeError(); | |||
1495 | ||||
1496 | return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr); | |||
1497 | } | |||
1498 | ||||
1499 | ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { | |||
1500 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); | |||
1501 | if (!ToBaseTypeOrErr) | |||
1502 | return ToBaseTypeOrErr.takeError(); | |||
1503 | ||||
1504 | SmallVector<QualType, 4> TypeArgs; | |||
1505 | for (auto TypeArg : T->getTypeArgsAsWritten()) { | |||
1506 | if (ExpectedType TyOrErr = import(TypeArg)) | |||
1507 | TypeArgs.push_back(*TyOrErr); | |||
1508 | else | |||
1509 | return TyOrErr.takeError(); | |||
1510 | } | |||
1511 | ||||
1512 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | |||
1513 | for (auto *P : T->quals()) { | |||
1514 | if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P)) | |||
1515 | Protocols.push_back(*ProtocolOrErr); | |||
1516 | else | |||
1517 | return ProtocolOrErr.takeError(); | |||
1518 | ||||
1519 | } | |||
1520 | ||||
1521 | return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs, | |||
1522 | Protocols, | |||
1523 | T->isKindOfTypeAsWritten()); | |||
1524 | } | |||
1525 | ||||
1526 | ExpectedType | |||
1527 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { | |||
1528 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | |||
1529 | if (!ToPointeeTypeOrErr) | |||
1530 | return ToPointeeTypeOrErr.takeError(); | |||
1531 | ||||
1532 | return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr); | |||
1533 | } | |||
1534 | ||||
1535 | //---------------------------------------------------------------------------- | |||
1536 | // Import Declarations | |||
1537 | //---------------------------------------------------------------------------- | |||
1538 | Error ASTNodeImporter::ImportDeclParts( | |||
1539 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, | |||
1540 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) { | |||
1541 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. | |||
1542 | // example: int struct_in_proto(struct data_t{int a;int b;} *d); | |||
1543 | DeclContext *OrigDC = D->getDeclContext(); | |||
1544 | FunctionDecl *FunDecl; | |||
1545 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && | |||
1546 | FunDecl->hasBody()) { | |||
1547 | auto getLeafPointeeType = [](const Type *T) { | |||
1548 | while (T->isPointerType() || T->isArrayType()) { | |||
1549 | T = T->getPointeeOrArrayElementType(); | |||
1550 | } | |||
1551 | return T; | |||
1552 | }; | |||
1553 | for (const ParmVarDecl *P : FunDecl->parameters()) { | |||
1554 | const Type *LeafT = | |||
1555 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); | |||
1556 | auto *RT = dyn_cast<RecordType>(LeafT); | |||
1557 | if (RT && RT->getDecl() == D) { | |||
1558 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | |||
1559 | << D->getDeclKindName(); | |||
1560 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
1561 | } | |||
1562 | } | |||
1563 | } | |||
1564 | ||||
1565 | // Import the context of this declaration. | |||
1566 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
1567 | return Err; | |||
1568 | ||||
1569 | // Import the name of this declaration. | |||
1570 | if (Error Err = importInto(Name, D->getDeclName())) | |||
1571 | return Err; | |||
1572 | ||||
1573 | // Import the location of this declaration. | |||
1574 | if (Error Err = importInto(Loc, D->getLocation())) | |||
1575 | return Err; | |||
1576 | ||||
1577 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); | |||
1578 | ||||
1579 | return Error::success(); | |||
1580 | } | |||
1581 | ||||
1582 | Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { | |||
1583 | if (!FromD) | |||
1584 | return Error::success(); | |||
1585 | ||||
1586 | if (!ToD) | |||
1587 | if (Error Err = importInto(ToD, FromD)) | |||
1588 | return Err; | |||
1589 | ||||
1590 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { | |||
1591 | if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) { | |||
1592 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && | |||
1593 | !ToRecord->getDefinition()) { | |||
1594 | if (Error Err = ImportDefinition(FromRecord, ToRecord)) | |||
1595 | return Err; | |||
1596 | } | |||
1597 | } | |||
1598 | return Error::success(); | |||
1599 | } | |||
1600 | ||||
1601 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { | |||
1602 | if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) { | |||
1603 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { | |||
1604 | if (Error Err = ImportDefinition(FromEnum, ToEnum)) | |||
1605 | return Err; | |||
1606 | } | |||
1607 | } | |||
1608 | return Error::success(); | |||
1609 | } | |||
1610 | ||||
1611 | return Error::success(); | |||
1612 | } | |||
1613 | ||||
1614 | Error | |||
1615 | ASTNodeImporter::ImportDeclarationNameLoc( | |||
1616 | const DeclarationNameInfo &From, DeclarationNameInfo& To) { | |||
1617 | // NOTE: To.Name and To.Loc are already imported. | |||
1618 | // We only have to import To.LocInfo. | |||
1619 | switch (To.getName().getNameKind()) { | |||
1620 | case DeclarationName::Identifier: | |||
1621 | case DeclarationName::ObjCZeroArgSelector: | |||
1622 | case DeclarationName::ObjCOneArgSelector: | |||
1623 | case DeclarationName::ObjCMultiArgSelector: | |||
1624 | case DeclarationName::CXXUsingDirective: | |||
1625 | case DeclarationName::CXXDeductionGuideName: | |||
1626 | return Error::success(); | |||
1627 | ||||
1628 | case DeclarationName::CXXOperatorName: { | |||
1629 | if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange())) | |||
1630 | To.setCXXOperatorNameRange(*ToRangeOrErr); | |||
1631 | else | |||
1632 | return ToRangeOrErr.takeError(); | |||
1633 | return Error::success(); | |||
1634 | } | |||
1635 | case DeclarationName::CXXLiteralOperatorName: { | |||
1636 | if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc())) | |||
1637 | To.setCXXLiteralOperatorNameLoc(*LocOrErr); | |||
1638 | else | |||
1639 | return LocOrErr.takeError(); | |||
1640 | return Error::success(); | |||
1641 | } | |||
1642 | case DeclarationName::CXXConstructorName: | |||
1643 | case DeclarationName::CXXDestructorName: | |||
1644 | case DeclarationName::CXXConversionFunctionName: { | |||
1645 | if (auto ToTInfoOrErr = import(From.getNamedTypeInfo())) | |||
1646 | To.setNamedTypeInfo(*ToTInfoOrErr); | |||
1647 | else | |||
1648 | return ToTInfoOrErr.takeError(); | |||
1649 | return Error::success(); | |||
1650 | } | |||
1651 | } | |||
1652 | llvm_unreachable("Unknown name kind.")::llvm::llvm_unreachable_internal("Unknown name kind.", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 1652); | |||
1653 | } | |||
1654 | ||||
1655 | Error | |||
1656 | ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { | |||
1657 | if (Importer.isMinimalImport() && !ForceImport) { | |||
1658 | auto ToDCOrErr = Importer.ImportContext(FromDC); | |||
1659 | return ToDCOrErr.takeError(); | |||
1660 | } | |||
1661 | llvm::SmallVector<Decl *, 8> ImportedDecls; | |||
1662 | for (auto *From : FromDC->decls()) { | |||
1663 | ExpectedDecl ImportedOrErr = import(From); | |||
1664 | if (!ImportedOrErr) | |||
1665 | // Ignore the error, continue with next Decl. | |||
1666 | // FIXME: Handle this case somehow better. | |||
1667 | consumeError(ImportedOrErr.takeError()); | |||
1668 | } | |||
1669 | ||||
1670 | return Error::success(); | |||
1671 | } | |||
1672 | ||||
1673 | Error ASTNodeImporter::ImportDeclContext( | |||
1674 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { | |||
1675 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); | |||
1676 | if (!ToDCOrErr) | |||
1677 | return ToDCOrErr.takeError(); | |||
1678 | ToDC = *ToDCOrErr; | |||
1679 | ||||
1680 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { | |||
1681 | auto ToLexicalDCOrErr = Importer.ImportContext( | |||
1682 | FromD->getLexicalDeclContext()); | |||
1683 | if (!ToLexicalDCOrErr) | |||
1684 | return ToLexicalDCOrErr.takeError(); | |||
1685 | ToLexicalDC = *ToLexicalDCOrErr; | |||
1686 | } else | |||
1687 | ToLexicalDC = ToDC; | |||
1688 | ||||
1689 | return Error::success(); | |||
1690 | } | |||
1691 | ||||
1692 | Error ASTNodeImporter::ImportImplicitMethods( | |||
1693 | const CXXRecordDecl *From, CXXRecordDecl *To) { | |||
1694 | assert(From->isCompleteDefinition() && To->getDefinition() == To &&((From->isCompleteDefinition() && To->getDefinition () == To && "Import implicit methods to or from non-definition" ) ? static_cast<void> (0) : __assert_fail ("From->isCompleteDefinition() && To->getDefinition() == To && \"Import implicit methods to or from non-definition\"" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 1695, __PRETTY_FUNCTION__)) | |||
1695 | "Import implicit methods to or from non-definition")((From->isCompleteDefinition() && To->getDefinition () == To && "Import implicit methods to or from non-definition" ) ? static_cast<void> (0) : __assert_fail ("From->isCompleteDefinition() && To->getDefinition() == To && \"Import implicit methods to or from non-definition\"" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 1695, __PRETTY_FUNCTION__)); | |||
1696 | ||||
1697 | for (CXXMethodDecl *FromM : From->methods()) | |||
1698 | if (FromM->isImplicit()) { | |||
1699 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); | |||
1700 | if (!ToMOrErr) | |||
1701 | return ToMOrErr.takeError(); | |||
1702 | } | |||
1703 | ||||
1704 | return Error::success(); | |||
1705 | } | |||
1706 | ||||
1707 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, | |||
1708 | ASTImporter &Importer) { | |||
1709 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { | |||
1710 | Decl *ToTypedef = Importer.Import(FromTypedef); | |||
1711 | if (!ToTypedef) | |||
1712 | return make_error<ImportError>(); | |||
1713 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(ToTypedef)); | |||
1714 | // FIXME: This should be the final code. | |||
1715 | //if (Expected<Decl *> ToTypedefOrErr = Importer.Import(FromTypedef)) | |||
1716 | // To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); | |||
1717 | //else | |||
1718 | // return ToTypedefOrErr.takeError(); | |||
1719 | } | |||
1720 | return Error::success(); | |||
1721 | } | |||
1722 | ||||
1723 | Error ASTNodeImporter::ImportDefinition( | |||
1724 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { | |||
1725 | if (To->getDefinition() || To->isBeingDefined()) { | |||
1726 | if (Kind == IDK_Everything) | |||
1727 | return ImportDeclContext(From, /*ForceImport=*/true); | |||
1728 | ||||
1729 | return Error::success(); | |||
1730 | } | |||
1731 | ||||
1732 | To->startDefinition(); | |||
1733 | ||||
1734 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) | |||
1735 | return Err; | |||
1736 | ||||
1737 | // Add base classes. | |||
1738 | if (auto *ToCXX = dyn_cast<CXXRecordDecl>(To)) { | |||
1739 | auto *FromCXX = cast<CXXRecordDecl>(From); | |||
1740 | ||||
1741 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); | |||
1742 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); | |||
1743 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; | |||
1744 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; | |||
1745 | ToData.Aggregate = FromData.Aggregate; | |||
1746 | ToData.PlainOldData = FromData.PlainOldData; | |||
1747 | ToData.Empty = FromData.Empty; | |||
1748 | ToData.Polymorphic = FromData.Polymorphic; | |||
1749 | ToData.Abstract = FromData.Abstract; | |||
1750 | ToData.IsStandardLayout = FromData.IsStandardLayout; | |||
1751 | ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout; | |||
1752 | ToData.HasBasesWithFields = FromData.HasBasesWithFields; | |||
1753 | ToData.HasBasesWithNonStaticDataMembers = | |||
1754 | FromData.HasBasesWithNonStaticDataMembers; | |||
1755 | ToData.HasPrivateFields = FromData.HasPrivateFields; | |||
1756 | ToData.HasProtectedFields = FromData.HasProtectedFields; | |||
1757 | ToData.HasPublicFields = FromData.HasPublicFields; | |||
1758 | ToData.HasMutableFields = FromData.HasMutableFields; | |||
1759 | ToData.HasVariantMembers = FromData.HasVariantMembers; | |||
1760 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; | |||
1761 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; | |||
1762 | ToData.HasUninitializedReferenceMember | |||
1763 | = FromData.HasUninitializedReferenceMember; | |||
1764 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; | |||
1765 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; | |||
1766 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; | |||
1767 | ToData.NeedOverloadResolutionForCopyConstructor | |||
1768 | = FromData.NeedOverloadResolutionForCopyConstructor; | |||
1769 | ToData.NeedOverloadResolutionForMoveConstructor | |||
1770 | = FromData.NeedOverloadResolutionForMoveConstructor; | |||
1771 | ToData.NeedOverloadResolutionForMoveAssignment | |||
1772 | = FromData.NeedOverloadResolutionForMoveAssignment; | |||
1773 | ToData.NeedOverloadResolutionForDestructor | |||
1774 | = FromData.NeedOverloadResolutionForDestructor; | |||
1775 | ToData.DefaultedCopyConstructorIsDeleted | |||
1776 | = FromData.DefaultedCopyConstructorIsDeleted; | |||
1777 | ToData.DefaultedMoveConstructorIsDeleted | |||
1778 | = FromData.DefaultedMoveConstructorIsDeleted; | |||
1779 | ToData.DefaultedMoveAssignmentIsDeleted | |||
1780 | = FromData.DefaultedMoveAssignmentIsDeleted; | |||
1781 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; | |||
1782 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; | |||
1783 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; | |||
1784 | ToData.HasConstexprNonCopyMoveConstructor | |||
1785 | = FromData.HasConstexprNonCopyMoveConstructor; | |||
1786 | ToData.HasDefaultedDefaultConstructor | |||
1787 | = FromData.HasDefaultedDefaultConstructor; | |||
1788 | ToData.DefaultedDefaultConstructorIsConstexpr | |||
1789 | = FromData.DefaultedDefaultConstructorIsConstexpr; | |||
1790 | ToData.HasConstexprDefaultConstructor | |||
1791 | = FromData.HasConstexprDefaultConstructor; | |||
1792 | ToData.HasNonLiteralTypeFieldsOrBases | |||
1793 | = FromData.HasNonLiteralTypeFieldsOrBases; | |||
1794 | // ComputedVisibleConversions not imported. | |||
1795 | ToData.UserProvidedDefaultConstructor | |||
1796 | = FromData.UserProvidedDefaultConstructor; | |||
1797 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; | |||
1798 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase | |||
1799 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; | |||
1800 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase | |||
1801 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; | |||
1802 | ToData.ImplicitCopyAssignmentHasConstParam | |||
1803 | = FromData.ImplicitCopyAssignmentHasConstParam; | |||
1804 | ToData.HasDeclaredCopyConstructorWithConstParam | |||
1805 | = FromData.HasDeclaredCopyConstructorWithConstParam; | |||
1806 | ToData.HasDeclaredCopyAssignmentWithConstParam | |||
1807 | = FromData.HasDeclaredCopyAssignmentWithConstParam; | |||
1808 | ||||
1809 | SmallVector<CXXBaseSpecifier *, 4> Bases; | |||
1810 | for (const auto &Base1 : FromCXX->bases()) { | |||
1811 | ExpectedType TyOrErr = import(Base1.getType()); | |||
1812 | if (!TyOrErr) | |||
1813 | return TyOrErr.takeError(); | |||
1814 | ||||
1815 | SourceLocation EllipsisLoc; | |||
1816 | if (Base1.isPackExpansion()) { | |||
1817 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) | |||
1818 | EllipsisLoc = *LocOrErr; | |||
1819 | else | |||
1820 | return LocOrErr.takeError(); | |||
1821 | } | |||
1822 | ||||
1823 | // Ensure that we have a definition for the base. | |||
1824 | if (Error Err = | |||
1825 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) | |||
1826 | return Err; | |||
1827 | ||||
1828 | auto RangeOrErr = import(Base1.getSourceRange()); | |||
1829 | if (!RangeOrErr) | |||
1830 | return RangeOrErr.takeError(); | |||
1831 | ||||
1832 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); | |||
1833 | if (!TSIOrErr) | |||
1834 | return TSIOrErr.takeError(); | |||
1835 | ||||
1836 | Bases.push_back( | |||
1837 | new (Importer.getToContext()) CXXBaseSpecifier( | |||
1838 | *RangeOrErr, | |||
1839 | Base1.isVirtual(), | |||
1840 | Base1.isBaseOfClass(), | |||
1841 | Base1.getAccessSpecifierAsWritten(), | |||
1842 | *TSIOrErr, | |||
1843 | EllipsisLoc)); | |||
1844 | } | |||
1845 | if (!Bases.empty()) | |||
1846 | ToCXX->setBases(Bases.data(), Bases.size()); | |||
1847 | } | |||
1848 | ||||
1849 | if (shouldForceImportDeclContext(Kind)) | |||
1850 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | |||
1851 | return Err; | |||
1852 | ||||
1853 | To->completeDefinition(); | |||
1854 | return Error::success(); | |||
1855 | } | |||
1856 | ||||
1857 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { | |||
1858 | if (To->getAnyInitializer()) | |||
1859 | return Error::success(); | |||
1860 | ||||
1861 | Expr *FromInit = From->getInit(); | |||
1862 | if (!FromInit) | |||
1863 | return Error::success(); | |||
1864 | ||||
1865 | ExpectedExpr ToInitOrErr = import(FromInit); | |||
1866 | if (!ToInitOrErr) | |||
1867 | return ToInitOrErr.takeError(); | |||
1868 | ||||
1869 | To->setInit(*ToInitOrErr); | |||
1870 | if (From->isInitKnownICE()) { | |||
1871 | EvaluatedStmt *Eval = To->ensureEvaluatedStmt(); | |||
1872 | Eval->CheckedICE = true; | |||
1873 | Eval->IsICE = From->isInitICE(); | |||
1874 | } | |||
1875 | ||||
1876 | // FIXME: Other bits to merge? | |||
1877 | return Error::success(); | |||
1878 | } | |||
1879 | ||||
1880 | Error ASTNodeImporter::ImportDefinition( | |||
1881 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { | |||
1882 | if (To->getDefinition() || To->isBeingDefined()) { | |||
1883 | if (Kind == IDK_Everything) | |||
1884 | return ImportDeclContext(From, /*ForceImport=*/true); | |||
1885 | return Error::success(); | |||
1886 | } | |||
1887 | ||||
1888 | To->startDefinition(); | |||
1889 | ||||
1890 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) | |||
1891 | return Err; | |||
1892 | ||||
1893 | ExpectedType ToTypeOrErr = | |||
1894 | import(Importer.getFromContext().getTypeDeclType(From)); | |||
1895 | if (!ToTypeOrErr) | |||
1896 | return ToTypeOrErr.takeError(); | |||
1897 | ||||
1898 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); | |||
1899 | if (!ToPromotionTypeOrErr) | |||
1900 | return ToPromotionTypeOrErr.takeError(); | |||
1901 | ||||
1902 | if (shouldForceImportDeclContext(Kind)) | |||
1903 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | |||
1904 | return Err; | |||
1905 | ||||
1906 | // FIXME: we might need to merge the number of positive or negative bits | |||
1907 | // if the enumerator lists don't match. | |||
1908 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, | |||
1909 | From->getNumPositiveBits(), | |||
1910 | From->getNumNegativeBits()); | |||
1911 | return Error::success(); | |||
1912 | } | |||
1913 | ||||
1914 | // FIXME: Remove this, use `import` instead. | |||
1915 | Expected<TemplateParameterList *> ASTNodeImporter::ImportTemplateParameterList( | |||
1916 | TemplateParameterList *Params) { | |||
1917 | SmallVector<NamedDecl *, 4> ToParams(Params->size()); | |||
1918 | if (Error Err = ImportContainerChecked(*Params, ToParams)) | |||
1919 | return std::move(Err); | |||
1920 | ||||
1921 | Expr *ToRequiresClause; | |||
1922 | if (Expr *const R = Params->getRequiresClause()) { | |||
1923 | if (Error Err = importInto(ToRequiresClause, R)) | |||
1924 | return std::move(Err); | |||
1925 | } else { | |||
1926 | ToRequiresClause = nullptr; | |||
1927 | } | |||
1928 | ||||
1929 | auto ToTemplateLocOrErr = import(Params->getTemplateLoc()); | |||
1930 | if (!ToTemplateLocOrErr) | |||
1931 | return ToTemplateLocOrErr.takeError(); | |||
1932 | auto ToLAngleLocOrErr = import(Params->getLAngleLoc()); | |||
1933 | if (!ToLAngleLocOrErr) | |||
1934 | return ToLAngleLocOrErr.takeError(); | |||
1935 | auto ToRAngleLocOrErr = import(Params->getRAngleLoc()); | |||
1936 | if (!ToRAngleLocOrErr) | |||
1937 | return ToRAngleLocOrErr.takeError(); | |||
1938 | ||||
1939 | return TemplateParameterList::Create( | |||
1940 | Importer.getToContext(), | |||
1941 | *ToTemplateLocOrErr, | |||
1942 | *ToLAngleLocOrErr, | |||
1943 | ToParams, | |||
1944 | *ToRAngleLocOrErr, | |||
1945 | ToRequiresClause); | |||
1946 | } | |||
1947 | ||||
1948 | Error ASTNodeImporter::ImportTemplateArguments( | |||
1949 | const TemplateArgument *FromArgs, unsigned NumFromArgs, | |||
1950 | SmallVectorImpl<TemplateArgument> &ToArgs) { | |||
1951 | for (unsigned I = 0; I != NumFromArgs; ++I) { | |||
1952 | if (auto ToOrErr = import(FromArgs[I])) | |||
1953 | ToArgs.push_back(*ToOrErr); | |||
1954 | else | |||
1955 | return ToOrErr.takeError(); | |||
1956 | } | |||
1957 | ||||
1958 | return Error::success(); | |||
1959 | } | |||
1960 | ||||
1961 | // FIXME: Do not forget to remove this and use only 'import'. | |||
1962 | Expected<TemplateArgument> | |||
1963 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { | |||
1964 | return import(From); | |||
1965 | } | |||
1966 | ||||
1967 | template <typename InContainerTy> | |||
1968 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( | |||
1969 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { | |||
1970 | for (const auto &FromLoc : Container) { | |||
1971 | if (auto ToLocOrErr = import(FromLoc)) | |||
1972 | ToTAInfo.addArgument(*ToLocOrErr); | |||
1973 | else | |||
1974 | return ToLocOrErr.takeError(); | |||
1975 | } | |||
1976 | return Error::success(); | |||
1977 | } | |||
1978 | ||||
1979 | static StructuralEquivalenceKind | |||
1980 | getStructuralEquivalenceKind(const ASTImporter &Importer) { | |||
1981 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal | |||
1982 | : StructuralEquivalenceKind::Default; | |||
1983 | } | |||
1984 | ||||
1985 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { | |||
1986 | StructuralEquivalenceContext Ctx( | |||
1987 | Importer.getFromContext(), Importer.getToContext(), | |||
1988 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | |||
1989 | false, Complain); | |||
1990 | return Ctx.IsEquivalent(From, To); | |||
1991 | } | |||
1992 | ||||
1993 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, | |||
1994 | RecordDecl *ToRecord, bool Complain) { | |||
1995 | // Eliminate a potential failure point where we attempt to re-import | |||
1996 | // something we're trying to import while completing ToRecord. | |||
1997 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); | |||
1998 | if (ToOrigin) { | |||
1999 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); | |||
2000 | if (ToOriginRecord) | |||
2001 | ToRecord = ToOriginRecord; | |||
2002 | } | |||
2003 | ||||
2004 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | |||
2005 | ToRecord->getASTContext(), | |||
2006 | Importer.getNonEquivalentDecls(), | |||
2007 | getStructuralEquivalenceKind(Importer), | |||
2008 | false, Complain); | |||
2009 | return Ctx.IsEquivalent(FromRecord, ToRecord); | |||
2010 | } | |||
2011 | ||||
2012 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, | |||
2013 | bool Complain) { | |||
2014 | StructuralEquivalenceContext Ctx( | |||
2015 | Importer.getFromContext(), Importer.getToContext(), | |||
2016 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | |||
2017 | false, Complain); | |||
2018 | return Ctx.IsEquivalent(FromVar, ToVar); | |||
2019 | } | |||
2020 | ||||
2021 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { | |||
2022 | StructuralEquivalenceContext Ctx( | |||
2023 | Importer.getFromContext(), Importer.getToContext(), | |||
2024 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); | |||
2025 | return Ctx.IsEquivalent(FromEnum, ToEnum); | |||
2026 | } | |||
2027 | ||||
2028 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, | |||
2029 | FunctionTemplateDecl *To) { | |||
2030 | StructuralEquivalenceContext Ctx( | |||
2031 | Importer.getFromContext(), Importer.getToContext(), | |||
2032 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | |||
2033 | false, false); | |||
2034 | return Ctx.IsEquivalent(From, To); | |||
2035 | } | |||
2036 | ||||
2037 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { | |||
2038 | StructuralEquivalenceContext Ctx( | |||
2039 | Importer.getFromContext(), Importer.getToContext(), | |||
2040 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | |||
2041 | false, false); | |||
2042 | return Ctx.IsEquivalent(From, To); | |||
2043 | } | |||
2044 | ||||
2045 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, | |||
2046 | EnumConstantDecl *ToEC) { | |||
2047 | const llvm::APSInt &FromVal = FromEC->getInitVal(); | |||
2048 | const llvm::APSInt &ToVal = ToEC->getInitVal(); | |||
2049 | ||||
2050 | return FromVal.isSigned() == ToVal.isSigned() && | |||
2051 | FromVal.getBitWidth() == ToVal.getBitWidth() && | |||
2052 | FromVal == ToVal; | |||
2053 | } | |||
2054 | ||||
2055 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, | |||
2056 | ClassTemplateDecl *To) { | |||
2057 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | |||
2058 | Importer.getToContext(), | |||
2059 | Importer.getNonEquivalentDecls(), | |||
2060 | getStructuralEquivalenceKind(Importer)); | |||
2061 | return Ctx.IsEquivalent(From, To); | |||
2062 | } | |||
2063 | ||||
2064 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, | |||
2065 | VarTemplateDecl *To) { | |||
2066 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | |||
2067 | Importer.getToContext(), | |||
2068 | Importer.getNonEquivalentDecls(), | |||
2069 | getStructuralEquivalenceKind(Importer)); | |||
2070 | return Ctx.IsEquivalent(From, To); | |||
2071 | } | |||
2072 | ||||
2073 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { | |||
2074 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | |||
2075 | << D->getDeclKindName(); | |||
2076 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
2077 | } | |||
2078 | ||||
2079 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { | |||
2080 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | |||
2081 | << D->getDeclKindName(); | |||
2082 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
2083 | } | |||
2084 | ||||
2085 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { | |||
2086 | // Import the context of this declaration. | |||
2087 | DeclContext *DC, *LexicalDC; | |||
2088 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
2089 | return std::move(Err); | |||
2090 | ||||
2091 | // Import the location of this declaration. | |||
2092 | ExpectedSLoc LocOrErr = import(D->getLocation()); | |||
2093 | if (!LocOrErr) | |||
2094 | return LocOrErr.takeError(); | |||
2095 | ||||
2096 | EmptyDecl *ToD; | |||
2097 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) | |||
2098 | return ToD; | |||
2099 | ||||
2100 | ToD->setLexicalDeclContext(LexicalDC); | |||
2101 | LexicalDC->addDeclInternal(ToD); | |||
2102 | return ToD; | |||
2103 | } | |||
2104 | ||||
2105 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { | |||
2106 | TranslationUnitDecl *ToD = | |||
2107 | Importer.getToContext().getTranslationUnitDecl(); | |||
2108 | ||||
2109 | Importer.MapImported(D, ToD); | |||
2110 | ||||
2111 | return ToD; | |||
2112 | } | |||
2113 | ||||
2114 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { | |||
2115 | ExpectedSLoc LocOrErr = import(D->getLocation()); | |||
2116 | if (!LocOrErr) | |||
2117 | return LocOrErr.takeError(); | |||
2118 | auto ColonLocOrErr = import(D->getColonLoc()); | |||
2119 | if (!ColonLocOrErr) | |||
2120 | return ColonLocOrErr.takeError(); | |||
2121 | ||||
2122 | // Import the context of this declaration. | |||
2123 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); | |||
2124 | if (!DCOrErr) | |||
2125 | return DCOrErr.takeError(); | |||
2126 | DeclContext *DC = *DCOrErr; | |||
2127 | ||||
2128 | AccessSpecDecl *ToD; | |||
2129 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), | |||
2130 | DC, *LocOrErr, *ColonLocOrErr)) | |||
2131 | return ToD; | |||
2132 | ||||
2133 | // Lexical DeclContext and Semantic DeclContext | |||
2134 | // is always the same for the accessSpec. | |||
2135 | ToD->setLexicalDeclContext(DC); | |||
2136 | DC->addDeclInternal(ToD); | |||
2137 | ||||
2138 | return ToD; | |||
2139 | } | |||
2140 | ||||
2141 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { | |||
2142 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); | |||
2143 | if (!DCOrErr) | |||
2144 | return DCOrErr.takeError(); | |||
2145 | DeclContext *DC = *DCOrErr; | |||
2146 | DeclContext *LexicalDC = DC; | |||
2147 | ||||
2148 | SourceLocation ToLocation, ToRParenLoc; | |||
2149 | Expr *ToAssertExpr; | |||
2150 | StringLiteral *ToMessage; | |||
2151 | if (auto Imp = importSeq( | |||
2152 | D->getLocation(), D->getAssertExpr(), D->getMessage(), D->getRParenLoc())) | |||
2153 | std::tie(ToLocation, ToAssertExpr, ToMessage, ToRParenLoc) = *Imp; | |||
2154 | else | |||
2155 | return Imp.takeError(); | |||
2156 | ||||
2157 | StaticAssertDecl *ToD; | |||
2158 | if (GetImportedOrCreateDecl( | |||
2159 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, | |||
2160 | ToRParenLoc, D->isFailed())) | |||
2161 | return ToD; | |||
2162 | ||||
2163 | ToD->setLexicalDeclContext(LexicalDC); | |||
2164 | LexicalDC->addDeclInternal(ToD); | |||
2165 | return ToD; | |||
2166 | } | |||
2167 | ||||
2168 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { | |||
2169 | // Import the major distinguishing characteristics of this namespace. | |||
2170 | DeclContext *DC, *LexicalDC; | |||
2171 | DeclarationName Name; | |||
2172 | SourceLocation Loc; | |||
2173 | NamedDecl *ToD; | |||
2174 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
2175 | return std::move(Err); | |||
2176 | if (ToD) | |||
2177 | return ToD; | |||
2178 | ||||
2179 | NamespaceDecl *MergeWithNamespace = nullptr; | |||
2180 | if (!Name) { | |||
2181 | // This is an anonymous namespace. Adopt an existing anonymous | |||
2182 | // namespace if we can. | |||
2183 | // FIXME: Not testable. | |||
2184 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) | |||
2185 | MergeWithNamespace = TU->getAnonymousNamespace(); | |||
2186 | else | |||
2187 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); | |||
2188 | } else { | |||
2189 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
2190 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
2191 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
2192 | for (auto *FoundDecl : FoundDecls) { | |||
2193 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) | |||
2194 | continue; | |||
2195 | ||||
2196 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { | |||
2197 | MergeWithNamespace = FoundNS; | |||
2198 | ConflictingDecls.clear(); | |||
2199 | break; | |||
2200 | } | |||
2201 | ||||
2202 | ConflictingDecls.push_back(FoundDecl); | |||
2203 | } | |||
2204 | ||||
2205 | if (!ConflictingDecls.empty()) { | |||
2206 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, | |||
2207 | ConflictingDecls.data(), | |||
2208 | ConflictingDecls.size()); | |||
2209 | if (!Name) | |||
2210 | return make_error<ImportError>(ImportError::NameConflict); | |||
2211 | } | |||
2212 | } | |||
2213 | ||||
2214 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | |||
2215 | if (!BeginLocOrErr) | |||
2216 | return BeginLocOrErr.takeError(); | |||
2217 | ||||
2218 | // Create the "to" namespace, if needed. | |||
2219 | NamespaceDecl *ToNamespace = MergeWithNamespace; | |||
2220 | if (!ToNamespace) { | |||
2221 | if (GetImportedOrCreateDecl( | |||
2222 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), | |||
2223 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), | |||
2224 | /*PrevDecl=*/nullptr)) | |||
2225 | return ToNamespace; | |||
2226 | ToNamespace->setLexicalDeclContext(LexicalDC); | |||
2227 | LexicalDC->addDeclInternal(ToNamespace); | |||
2228 | ||||
2229 | // If this is an anonymous namespace, register it as the anonymous | |||
2230 | // namespace within its context. | |||
2231 | if (!Name) { | |||
2232 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) | |||
2233 | TU->setAnonymousNamespace(ToNamespace); | |||
2234 | else | |||
2235 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); | |||
2236 | } | |||
2237 | } | |||
2238 | Importer.MapImported(D, ToNamespace); | |||
2239 | ||||
2240 | if (Error Err = ImportDeclContext(D)) | |||
2241 | return std::move(Err); | |||
2242 | ||||
2243 | return ToNamespace; | |||
2244 | } | |||
2245 | ||||
2246 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { | |||
2247 | // Import the major distinguishing characteristics of this namespace. | |||
2248 | DeclContext *DC, *LexicalDC; | |||
2249 | DeclarationName Name; | |||
2250 | SourceLocation Loc; | |||
2251 | NamedDecl *LookupD; | |||
2252 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) | |||
2253 | return std::move(Err); | |||
2254 | if (LookupD) | |||
2255 | return LookupD; | |||
2256 | ||||
2257 | // NOTE: No conflict resolution is done for namespace aliases now. | |||
2258 | ||||
2259 | SourceLocation ToNamespaceLoc, ToAliasLoc, ToTargetNameLoc; | |||
2260 | NestedNameSpecifierLoc ToQualifierLoc; | |||
2261 | NamespaceDecl *ToNamespace; | |||
2262 | if (auto Imp = importSeq( | |||
2263 | D->getNamespaceLoc(), D->getAliasLoc(), D->getQualifierLoc(), | |||
2264 | D->getTargetNameLoc(), D->getNamespace())) | |||
2265 | std::tie( | |||
2266 | ToNamespaceLoc, ToAliasLoc, ToQualifierLoc, ToTargetNameLoc, | |||
2267 | ToNamespace) = *Imp; | |||
2268 | else | |||
2269 | return Imp.takeError(); | |||
2270 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); | |||
2271 | ||||
2272 | NamespaceAliasDecl *ToD; | |||
2273 | if (GetImportedOrCreateDecl( | |||
2274 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, | |||
2275 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) | |||
2276 | return ToD; | |||
2277 | ||||
2278 | ToD->setLexicalDeclContext(LexicalDC); | |||
2279 | LexicalDC->addDeclInternal(ToD); | |||
2280 | ||||
2281 | return ToD; | |||
2282 | } | |||
2283 | ||||
2284 | ExpectedDecl | |||
2285 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { | |||
2286 | // Import the major distinguishing characteristics of this typedef. | |||
2287 | DeclContext *DC, *LexicalDC; | |||
2288 | DeclarationName Name; | |||
2289 | SourceLocation Loc; | |||
2290 | NamedDecl *ToD; | |||
2291 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
2292 | return std::move(Err); | |||
2293 | if (ToD) | |||
2294 | return ToD; | |||
2295 | ||||
2296 | // If this typedef is not in block scope, determine whether we've | |||
2297 | // seen a typedef with the same name (that we can merge with) or any | |||
2298 | // other entity by that name (which name lookup could conflict with). | |||
2299 | if (!DC->isFunctionOrMethod()) { | |||
2300 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
2301 | unsigned IDNS = Decl::IDNS_Ordinary; | |||
2302 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
2303 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
2304 | for (auto *FoundDecl : FoundDecls) { | |||
2305 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
2306 | continue; | |||
2307 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { | |||
2308 | if (Importer.IsStructurallyEquivalent( | |||
2309 | D->getUnderlyingType(), FoundTypedef->getUnderlyingType())) | |||
2310 | return Importer.MapImported(D, FoundTypedef); | |||
2311 | } | |||
2312 | ||||
2313 | ConflictingDecls.push_back(FoundDecl); | |||
2314 | } | |||
2315 | ||||
2316 | if (!ConflictingDecls.empty()) { | |||
2317 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | |||
2318 | ConflictingDecls.data(), | |||
2319 | ConflictingDecls.size()); | |||
2320 | if (!Name) | |||
2321 | return make_error<ImportError>(ImportError::NameConflict); | |||
2322 | } | |||
2323 | } | |||
2324 | ||||
2325 | QualType ToUnderlyingType; | |||
2326 | TypeSourceInfo *ToTypeSourceInfo; | |||
2327 | SourceLocation ToBeginLoc; | |||
2328 | if (auto Imp = importSeq( | |||
2329 | D->getUnderlyingType(), D->getTypeSourceInfo(), D->getBeginLoc())) | |||
2330 | std::tie(ToUnderlyingType, ToTypeSourceInfo, ToBeginLoc) = *Imp; | |||
2331 | else | |||
2332 | return Imp.takeError(); | |||
2333 | ||||
2334 | // Create the new typedef node. | |||
2335 | // FIXME: ToUnderlyingType is not used. | |||
2336 | TypedefNameDecl *ToTypedef; | |||
2337 | if (IsAlias) { | |||
2338 | if (GetImportedOrCreateDecl<TypeAliasDecl>( | |||
2339 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, | |||
2340 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) | |||
2341 | return ToTypedef; | |||
2342 | } else if (GetImportedOrCreateDecl<TypedefDecl>( | |||
2343 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, | |||
2344 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) | |||
2345 | return ToTypedef; | |||
2346 | ||||
2347 | ToTypedef->setAccess(D->getAccess()); | |||
2348 | ToTypedef->setLexicalDeclContext(LexicalDC); | |||
2349 | ||||
2350 | // Templated declarations should not appear in DeclContext. | |||
2351 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; | |||
2352 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) | |||
2353 | LexicalDC->addDeclInternal(ToTypedef); | |||
2354 | ||||
2355 | return ToTypedef; | |||
2356 | } | |||
2357 | ||||
2358 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { | |||
2359 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); | |||
2360 | } | |||
2361 | ||||
2362 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { | |||
2363 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); | |||
2364 | } | |||
2365 | ||||
2366 | ExpectedDecl | |||
2367 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { | |||
2368 | // Import the major distinguishing characteristics of this typedef. | |||
2369 | DeclContext *DC, *LexicalDC; | |||
2370 | DeclarationName Name; | |||
2371 | SourceLocation Loc; | |||
2372 | NamedDecl *FoundD; | |||
2373 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) | |||
2374 | return std::move(Err); | |||
2375 | if (FoundD) | |||
2376 | return FoundD; | |||
2377 | ||||
2378 | // If this typedef is not in block scope, determine whether we've | |||
2379 | // seen a typedef with the same name (that we can merge with) or any | |||
2380 | // other entity by that name (which name lookup could conflict with). | |||
2381 | if (!DC->isFunctionOrMethod()) { | |||
2382 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
2383 | unsigned IDNS = Decl::IDNS_Ordinary; | |||
2384 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
2385 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
2386 | for (auto *FoundDecl : FoundDecls) { | |||
2387 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
2388 | continue; | |||
2389 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) | |||
2390 | return Importer.MapImported(D, FoundAlias); | |||
2391 | ConflictingDecls.push_back(FoundDecl); | |||
2392 | } | |||
2393 | ||||
2394 | if (!ConflictingDecls.empty()) { | |||
2395 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | |||
2396 | ConflictingDecls.data(), | |||
2397 | ConflictingDecls.size()); | |||
2398 | if (!Name) | |||
2399 | return make_error<ImportError>(ImportError::NameConflict); | |||
2400 | } | |||
2401 | } | |||
2402 | ||||
2403 | TemplateParameterList *ToTemplateParameters; | |||
2404 | TypeAliasDecl *ToTemplatedDecl; | |||
2405 | if (auto Imp = importSeq(D->getTemplateParameters(), D->getTemplatedDecl())) | |||
2406 | std::tie(ToTemplateParameters, ToTemplatedDecl) = *Imp; | |||
2407 | else | |||
2408 | return Imp.takeError(); | |||
2409 | ||||
2410 | TypeAliasTemplateDecl *ToAlias; | |||
2411 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, | |||
2412 | Name, ToTemplateParameters, ToTemplatedDecl)) | |||
2413 | return ToAlias; | |||
2414 | ||||
2415 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); | |||
2416 | ||||
2417 | ToAlias->setAccess(D->getAccess()); | |||
2418 | ToAlias->setLexicalDeclContext(LexicalDC); | |||
2419 | LexicalDC->addDeclInternal(ToAlias); | |||
2420 | return ToAlias; | |||
2421 | } | |||
2422 | ||||
2423 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { | |||
2424 | // Import the major distinguishing characteristics of this label. | |||
2425 | DeclContext *DC, *LexicalDC; | |||
2426 | DeclarationName Name; | |||
2427 | SourceLocation Loc; | |||
2428 | NamedDecl *ToD; | |||
2429 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
2430 | return std::move(Err); | |||
2431 | if (ToD) | |||
2432 | return ToD; | |||
2433 | ||||
2434 | assert(LexicalDC->isFunctionOrMethod())((LexicalDC->isFunctionOrMethod()) ? static_cast<void> (0) : __assert_fail ("LexicalDC->isFunctionOrMethod()", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 2434, __PRETTY_FUNCTION__)); | |||
2435 | ||||
2436 | LabelDecl *ToLabel; | |||
2437 | if (D->isGnuLocal()) { | |||
2438 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | |||
2439 | if (!BeginLocOrErr) | |||
2440 | return BeginLocOrErr.takeError(); | |||
2441 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, | |||
2442 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) | |||
2443 | return ToLabel; | |||
2444 | ||||
2445 | } else { | |||
2446 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, | |||
2447 | Name.getAsIdentifierInfo())) | |||
2448 | return ToLabel; | |||
2449 | ||||
2450 | } | |||
2451 | ||||
2452 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); | |||
2453 | if (!ToStmtOrErr) | |||
2454 | return ToStmtOrErr.takeError(); | |||
2455 | ||||
2456 | ToLabel->setStmt(*ToStmtOrErr); | |||
2457 | ToLabel->setLexicalDeclContext(LexicalDC); | |||
2458 | LexicalDC->addDeclInternal(ToLabel); | |||
2459 | return ToLabel; | |||
2460 | } | |||
2461 | ||||
2462 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { | |||
2463 | // Import the major distinguishing characteristics of this enum. | |||
2464 | DeclContext *DC, *LexicalDC; | |||
2465 | DeclarationName Name; | |||
2466 | SourceLocation Loc; | |||
2467 | NamedDecl *ToD; | |||
2468 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
2469 | return std::move(Err); | |||
2470 | if (ToD) | |||
2471 | return ToD; | |||
2472 | ||||
2473 | // Figure out what enum name we're looking for. | |||
2474 | unsigned IDNS = Decl::IDNS_Tag; | |||
2475 | DeclarationName SearchName = Name; | |||
2476 | if (!SearchName && D->getTypedefNameForAnonDecl()) { | |||
2477 | if (Error Err = importInto( | |||
2478 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) | |||
2479 | return std::move(Err); | |||
2480 | IDNS = Decl::IDNS_Ordinary; | |||
2481 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) | |||
2482 | IDNS |= Decl::IDNS_Ordinary; | |||
2483 | ||||
2484 | // We may already have an enum of the same name; try to find and match it. | |||
2485 | if (!DC->isFunctionOrMethod() && SearchName) { | |||
2486 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
2487 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
2488 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); | |||
2489 | for (auto *FoundDecl : FoundDecls) { | |||
2490 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
2491 | continue; | |||
2492 | ||||
2493 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { | |||
2494 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) | |||
2495 | FoundDecl = Tag->getDecl(); | |||
2496 | } | |||
2497 | ||||
2498 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { | |||
2499 | if (IsStructuralMatch(D, FoundEnum)) | |||
2500 | return Importer.MapImported(D, FoundEnum); | |||
2501 | } | |||
2502 | ||||
2503 | ConflictingDecls.push_back(FoundDecl); | |||
2504 | } | |||
2505 | ||||
2506 | if (!ConflictingDecls.empty()) { | |||
2507 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | |||
2508 | ConflictingDecls.data(), | |||
2509 | ConflictingDecls.size()); | |||
2510 | if (!Name) | |||
2511 | return make_error<ImportError>(ImportError::NameConflict); | |||
2512 | } | |||
2513 | } | |||
2514 | ||||
2515 | SourceLocation ToBeginLoc; | |||
2516 | NestedNameSpecifierLoc ToQualifierLoc; | |||
2517 | QualType ToIntegerType; | |||
2518 | if (auto Imp = importSeq( | |||
2519 | D->getBeginLoc(), D->getQualifierLoc(), D->getIntegerType())) | |||
2520 | std::tie(ToBeginLoc, ToQualifierLoc, ToIntegerType) = *Imp; | |||
2521 | else | |||
2522 | return Imp.takeError(); | |||
2523 | ||||
2524 | // Create the enum declaration. | |||
2525 | EnumDecl *D2; | |||
2526 | if (GetImportedOrCreateDecl( | |||
2527 | D2, D, Importer.getToContext(), DC, ToBeginLoc, | |||
2528 | Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(), | |||
2529 | D->isScopedUsingClassTag(), D->isFixed())) | |||
2530 | return D2; | |||
2531 | ||||
2532 | D2->setQualifierInfo(ToQualifierLoc); | |||
2533 | D2->setIntegerType(ToIntegerType); | |||
2534 | D2->setAccess(D->getAccess()); | |||
2535 | D2->setLexicalDeclContext(LexicalDC); | |||
2536 | LexicalDC->addDeclInternal(D2); | |||
2537 | ||||
2538 | // Import the definition | |||
2539 | if (D->isCompleteDefinition()) | |||
2540 | if (Error Err = ImportDefinition(D, D2)) | |||
2541 | return std::move(Err); | |||
2542 | ||||
2543 | return D2; | |||
2544 | } | |||
2545 | ||||
2546 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { | |||
2547 | bool IsFriendTemplate = false; | |||
2548 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | |||
2549 | IsFriendTemplate = | |||
2550 | DCXX->getDescribedClassTemplate() && | |||
2551 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != | |||
2552 | Decl::FOK_None; | |||
2553 | } | |||
2554 | ||||
2555 | // If this record has a definition in the translation unit we're coming from, | |||
2556 | // but this particular declaration is not that definition, import the | |||
2557 | // definition and map to that. | |||
2558 | TagDecl *Definition = D->getDefinition(); | |||
2559 | if (Definition && Definition != D && | |||
2560 | // Friend template declaration must be imported on its own. | |||
2561 | !IsFriendTemplate && | |||
2562 | // In contrast to a normal CXXRecordDecl, the implicit | |||
2563 | // CXXRecordDecl of ClassTemplateSpecializationDecl is its redeclaration. | |||
2564 | // The definition of the implicit CXXRecordDecl in this case is the | |||
2565 | // ClassTemplateSpecializationDecl itself. Thus, we start with an extra | |||
2566 | // condition in order to be able to import the implict Decl. | |||
2567 | !D->isImplicit()) { | |||
2568 | ExpectedDecl ImportedDefOrErr = import(Definition); | |||
2569 | if (!ImportedDefOrErr) | |||
2570 | return ImportedDefOrErr.takeError(); | |||
2571 | ||||
2572 | return Importer.MapImported(D, *ImportedDefOrErr); | |||
2573 | } | |||
2574 | ||||
2575 | // Import the major distinguishing characteristics of this record. | |||
2576 | DeclContext *DC, *LexicalDC; | |||
2577 | DeclarationName Name; | |||
2578 | SourceLocation Loc; | |||
2579 | NamedDecl *ToD; | |||
2580 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
2581 | return std::move(Err); | |||
2582 | if (ToD) | |||
2583 | return ToD; | |||
2584 | ||||
2585 | // Figure out what structure name we're looking for. | |||
2586 | unsigned IDNS = Decl::IDNS_Tag; | |||
2587 | DeclarationName SearchName = Name; | |||
2588 | if (!SearchName && D->getTypedefNameForAnonDecl()) { | |||
2589 | if (Error Err = importInto( | |||
2590 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) | |||
2591 | return std::move(Err); | |||
2592 | IDNS = Decl::IDNS_Ordinary; | |||
2593 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) | |||
2594 | IDNS |= Decl::IDNS_Ordinary; | |||
2595 | ||||
2596 | // We may already have a record of the same name; try to find and match it. | |||
2597 | RecordDecl *AdoptDecl = nullptr; | |||
2598 | RecordDecl *PrevDecl = nullptr; | |||
2599 | if (!DC->isFunctionOrMethod()) { | |||
2600 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
2601 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
2602 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); | |||
2603 | ||||
2604 | if (!FoundDecls.empty()) { | |||
2605 | // We're going to have to compare D against potentially conflicting Decls, so complete it. | |||
2606 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) | |||
2607 | D->getASTContext().getExternalSource()->CompleteType(D); | |||
2608 | } | |||
2609 | ||||
2610 | for (auto *FoundDecl : FoundDecls) { | |||
2611 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
2612 | continue; | |||
2613 | ||||
2614 | Decl *Found = FoundDecl; | |||
2615 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { | |||
2616 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) | |||
2617 | Found = Tag->getDecl(); | |||
2618 | } | |||
2619 | ||||
2620 | if (D->getDescribedTemplate()) { | |||
2621 | if (auto *Template = dyn_cast<ClassTemplateDecl>(Found)) { | |||
2622 | Found = Template->getTemplatedDecl(); | |||
2623 | } else { | |||
2624 | ConflictingDecls.push_back(FoundDecl); | |||
2625 | continue; | |||
2626 | } | |||
2627 | } | |||
2628 | ||||
2629 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { | |||
2630 | if (!SearchName) { | |||
2631 | if (!IsStructuralMatch(D, FoundRecord, false)) | |||
2632 | continue; | |||
2633 | } else { | |||
2634 | if (!IsStructuralMatch(D, FoundRecord)) { | |||
2635 | ConflictingDecls.push_back(FoundDecl); | |||
2636 | continue; | |||
2637 | } | |||
2638 | } | |||
2639 | ||||
2640 | PrevDecl = FoundRecord; | |||
2641 | ||||
2642 | if (RecordDecl *FoundDef = FoundRecord->getDefinition()) { | |||
2643 | if ((SearchName && !D->isCompleteDefinition() && !IsFriendTemplate) | |||
2644 | || (D->isCompleteDefinition() && | |||
2645 | D->isAnonymousStructOrUnion() | |||
2646 | == FoundDef->isAnonymousStructOrUnion())) { | |||
2647 | // The record types structurally match, or the "from" translation | |||
2648 | // unit only had a forward declaration anyway; call it the same | |||
2649 | // function. | |||
2650 | // FIXME: Structural equivalence check should check for same | |||
2651 | // user-defined methods. | |||
2652 | Importer.MapImported(D, FoundDef); | |||
2653 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | |||
2654 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); | |||
2655 | assert(FoundCXX && "Record type mismatch")((FoundCXX && "Record type mismatch") ? static_cast< void> (0) : __assert_fail ("FoundCXX && \"Record type mismatch\"" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 2655, __PRETTY_FUNCTION__)); | |||
2656 | ||||
2657 | if (D->isCompleteDefinition() && !Importer.isMinimalImport()) | |||
2658 | // FoundDef may not have every implicit method that D has | |||
2659 | // because implicit methods are created only if they are used. | |||
2660 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) | |||
2661 | return std::move(Err); | |||
2662 | } | |||
2663 | return FoundDef; | |||
2664 | } | |||
2665 | if (IsFriendTemplate) | |||
2666 | continue; | |||
2667 | } else if (!D->isCompleteDefinition()) { | |||
2668 | // We have a forward declaration of this type, so adopt that forward | |||
2669 | // declaration rather than building a new one. | |||
2670 | ||||
2671 | // If one or both can be completed from external storage then try one | |||
2672 | // last time to complete and compare them before doing this. | |||
2673 | ||||
2674 | if (FoundRecord->hasExternalLexicalStorage() && | |||
2675 | !FoundRecord->isCompleteDefinition()) | |||
2676 | FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord); | |||
2677 | if (D->hasExternalLexicalStorage()) | |||
2678 | D->getASTContext().getExternalSource()->CompleteType(D); | |||
2679 | ||||
2680 | if (FoundRecord->isCompleteDefinition() && | |||
2681 | D->isCompleteDefinition() && | |||
2682 | !IsStructuralMatch(D, FoundRecord)) { | |||
2683 | ConflictingDecls.push_back(FoundDecl); | |||
2684 | continue; | |||
2685 | } | |||
2686 | ||||
2687 | AdoptDecl = FoundRecord; | |||
2688 | continue; | |||
2689 | } | |||
2690 | ||||
2691 | continue; | |||
2692 | } else if (isa<ValueDecl>(Found)) | |||
2693 | continue; | |||
2694 | ||||
2695 | ConflictingDecls.push_back(FoundDecl); | |||
2696 | } | |||
2697 | ||||
2698 | if (!ConflictingDecls.empty() && SearchName) { | |||
2699 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | |||
2700 | ConflictingDecls.data(), | |||
2701 | ConflictingDecls.size()); | |||
2702 | if (!Name) | |||
2703 | return make_error<ImportError>(ImportError::NameConflict); | |||
2704 | } | |||
2705 | } | |||
2706 | ||||
2707 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | |||
2708 | if (!BeginLocOrErr) | |||
2709 | return BeginLocOrErr.takeError(); | |||
2710 | ||||
2711 | // Create the record declaration. | |||
2712 | RecordDecl *D2 = AdoptDecl; | |||
2713 | if (!D2) { | |||
2714 | CXXRecordDecl *D2CXX = nullptr; | |||
2715 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | |||
2716 | if (DCXX->isLambda()) { | |||
2717 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); | |||
2718 | if (!TInfoOrErr) | |||
2719 | return TInfoOrErr.takeError(); | |||
2720 | if (GetImportedOrCreateSpecialDecl( | |||
2721 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), | |||
2722 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), | |||
2723 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) | |||
2724 | return D2CXX; | |||
2725 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); | |||
2726 | if (!CDeclOrErr) | |||
2727 | return CDeclOrErr.takeError(); | |||
2728 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr); | |||
2729 | } else if (DCXX->isInjectedClassName()) { | |||
2730 | // We have to be careful to do a similar dance to the one in | |||
2731 | // Sema::ActOnStartCXXMemberDeclarations | |||
2732 | CXXRecordDecl *const PrevDecl = nullptr; | |||
2733 | const bool DelayTypeCreation = true; | |||
2734 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), | |||
2735 | D->getTagKind(), DC, *BeginLocOrErr, Loc, | |||
2736 | Name.getAsIdentifierInfo(), PrevDecl, | |||
2737 | DelayTypeCreation)) | |||
2738 | return D2CXX; | |||
2739 | Importer.getToContext().getTypeDeclType( | |||
2740 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); | |||
2741 | } else { | |||
2742 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), | |||
2743 | D->getTagKind(), DC, *BeginLocOrErr, Loc, | |||
2744 | Name.getAsIdentifierInfo(), | |||
2745 | cast_or_null<CXXRecordDecl>(PrevDecl))) | |||
2746 | return D2CXX; | |||
2747 | } | |||
2748 | ||||
2749 | D2 = D2CXX; | |||
2750 | D2->setAccess(D->getAccess()); | |||
2751 | D2->setLexicalDeclContext(LexicalDC); | |||
2752 | if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit()) | |||
2753 | LexicalDC->addDeclInternal(D2); | |||
2754 | ||||
2755 | if (ClassTemplateDecl *FromDescribed = | |||
2756 | DCXX->getDescribedClassTemplate()) { | |||
2757 | ClassTemplateDecl *ToDescribed; | |||
2758 | if (Error Err = importInto(ToDescribed, FromDescribed)) | |||
2759 | return std::move(Err); | |||
2760 | D2CXX->setDescribedClassTemplate(ToDescribed); | |||
2761 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { | |||
2762 | // In a record describing a template the type should be an | |||
2763 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the | |||
2764 | // previously set type to the correct value here (ToDescribed is not | |||
2765 | // available at record create). | |||
2766 | // FIXME: The previous type is cleared but not removed from | |||
2767 | // ASTContext's internal storage. | |||
2768 | CXXRecordDecl *Injected = nullptr; | |||
2769 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { | |||
2770 | auto *Record = dyn_cast<CXXRecordDecl>(Found); | |||
2771 | if (Record && Record->isInjectedClassName()) { | |||
2772 | Injected = Record; | |||
2773 | break; | |||
2774 | } | |||
2775 | } | |||
2776 | D2CXX->setTypeForDecl(nullptr); | |||
2777 | Importer.getToContext().getInjectedClassNameType(D2CXX, | |||
2778 | ToDescribed->getInjectedClassNameSpecialization()); | |||
2779 | if (Injected) { | |||
2780 | Injected->setTypeForDecl(nullptr); | |||
2781 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); | |||
2782 | } | |||
2783 | } | |||
2784 | } else if (MemberSpecializationInfo *MemberInfo = | |||
2785 | DCXX->getMemberSpecializationInfo()) { | |||
2786 | TemplateSpecializationKind SK = | |||
2787 | MemberInfo->getTemplateSpecializationKind(); | |||
2788 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); | |||
2789 | ||||
2790 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) | |||
2791 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); | |||
2792 | else | |||
2793 | return ToInstOrErr.takeError(); | |||
2794 | ||||
2795 | if (ExpectedSLoc POIOrErr = | |||
2796 | import(MemberInfo->getPointOfInstantiation())) | |||
2797 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( | |||
2798 | *POIOrErr); | |||
2799 | else | |||
2800 | return POIOrErr.takeError(); | |||
2801 | } | |||
2802 | ||||
2803 | } else { | |||
2804 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), | |||
2805 | D->getTagKind(), DC, *BeginLocOrErr, Loc, | |||
2806 | Name.getAsIdentifierInfo(), PrevDecl)) | |||
2807 | return D2; | |||
2808 | D2->setLexicalDeclContext(LexicalDC); | |||
2809 | LexicalDC->addDeclInternal(D2); | |||
2810 | } | |||
2811 | ||||
2812 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) | |||
2813 | D2->setQualifierInfo(*QualifierLocOrErr); | |||
2814 | else | |||
2815 | return QualifierLocOrErr.takeError(); | |||
2816 | ||||
2817 | if (D->isAnonymousStructOrUnion()) | |||
2818 | D2->setAnonymousStructOrUnion(true); | |||
2819 | } | |||
2820 | ||||
2821 | Importer.MapImported(D, D2); | |||
2822 | ||||
2823 | if (D->isCompleteDefinition()) | |||
2824 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) | |||
2825 | return std::move(Err); | |||
2826 | ||||
2827 | return D2; | |||
2828 | } | |||
2829 | ||||
2830 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { | |||
2831 | // Import the major distinguishing characteristics of this enumerator. | |||
2832 | DeclContext *DC, *LexicalDC; | |||
2833 | DeclarationName Name; | |||
2834 | SourceLocation Loc; | |||
2835 | NamedDecl *ToD; | |||
2836 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
2837 | return std::move(Err); | |||
2838 | if (ToD) | |||
2839 | return ToD; | |||
2840 | ||||
2841 | // Determine whether there are any other declarations with the same name and | |||
2842 | // in the same context. | |||
2843 | if (!LexicalDC->isFunctionOrMethod()) { | |||
2844 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
2845 | unsigned IDNS = Decl::IDNS_Ordinary; | |||
2846 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
2847 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
2848 | for (auto *FoundDecl : FoundDecls) { | |||
2849 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
2850 | continue; | |||
2851 | ||||
2852 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { | |||
2853 | if (IsStructuralMatch(D, FoundEnumConstant)) | |||
2854 | return Importer.MapImported(D, FoundEnumConstant); | |||
2855 | } | |||
2856 | ||||
2857 | ConflictingDecls.push_back(FoundDecl); | |||
2858 | } | |||
2859 | ||||
2860 | if (!ConflictingDecls.empty()) { | |||
2861 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | |||
2862 | ConflictingDecls.data(), | |||
2863 | ConflictingDecls.size()); | |||
2864 | if (!Name) | |||
2865 | return make_error<ImportError>(ImportError::NameConflict); | |||
2866 | } | |||
2867 | } | |||
2868 | ||||
2869 | ExpectedType TypeOrErr = import(D->getType()); | |||
2870 | if (!TypeOrErr) | |||
2871 | return TypeOrErr.takeError(); | |||
2872 | ||||
2873 | ExpectedExpr InitOrErr = import(D->getInitExpr()); | |||
2874 | if (!InitOrErr) | |||
2875 | return InitOrErr.takeError(); | |||
2876 | ||||
2877 | EnumConstantDecl *ToEnumerator; | |||
2878 | if (GetImportedOrCreateDecl( | |||
2879 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, | |||
2880 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) | |||
2881 | return ToEnumerator; | |||
2882 | ||||
2883 | ToEnumerator->setAccess(D->getAccess()); | |||
2884 | ToEnumerator->setLexicalDeclContext(LexicalDC); | |||
2885 | LexicalDC->addDeclInternal(ToEnumerator); | |||
2886 | return ToEnumerator; | |||
2887 | } | |||
2888 | ||||
2889 | Error ASTNodeImporter::ImportTemplateInformation( | |||
2890 | FunctionDecl *FromFD, FunctionDecl *ToFD) { | |||
2891 | switch (FromFD->getTemplatedKind()) { | |||
2892 | case FunctionDecl::TK_NonTemplate: | |||
2893 | case FunctionDecl::TK_FunctionTemplate: | |||
2894 | return Error::success(); | |||
2895 | ||||
2896 | case FunctionDecl::TK_MemberSpecialization: { | |||
2897 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); | |||
2898 | ||||
2899 | if (Expected<FunctionDecl *> InstFDOrErr = | |||
2900 | import(FromFD->getInstantiatedFromMemberFunction())) | |||
2901 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); | |||
2902 | else | |||
2903 | return InstFDOrErr.takeError(); | |||
2904 | ||||
2905 | if (ExpectedSLoc POIOrErr = import( | |||
2906 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) | |||
2907 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); | |||
2908 | else | |||
2909 | return POIOrErr.takeError(); | |||
2910 | ||||
2911 | return Error::success(); | |||
2912 | } | |||
2913 | ||||
2914 | case FunctionDecl::TK_FunctionTemplateSpecialization: { | |||
2915 | auto FunctionAndArgsOrErr = | |||
2916 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); | |||
2917 | if (!FunctionAndArgsOrErr) | |||
2918 | return FunctionAndArgsOrErr.takeError(); | |||
2919 | ||||
2920 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( | |||
2921 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); | |||
2922 | ||||
2923 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); | |||
2924 | TemplateArgumentListInfo ToTAInfo; | |||
2925 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; | |||
2926 | if (FromTAArgsAsWritten) | |||
2927 | if (Error Err = ImportTemplateArgumentListInfo( | |||
2928 | *FromTAArgsAsWritten, ToTAInfo)) | |||
2929 | return Err; | |||
2930 | ||||
2931 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); | |||
2932 | if (!POIOrErr) | |||
2933 | return POIOrErr.takeError(); | |||
2934 | ||||
2935 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); | |||
2936 | ToFD->setFunctionTemplateSpecialization( | |||
2937 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, | |||
2938 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); | |||
2939 | return Error::success(); | |||
2940 | } | |||
2941 | ||||
2942 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { | |||
2943 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); | |||
2944 | UnresolvedSet<8> TemplDecls; | |||
2945 | unsigned NumTemplates = FromInfo->getNumTemplates(); | |||
2946 | for (unsigned I = 0; I < NumTemplates; I++) { | |||
2947 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = | |||
2948 | import(FromInfo->getTemplate(I))) | |||
2949 | TemplDecls.addDecl(*ToFTDOrErr); | |||
2950 | else | |||
2951 | return ToFTDOrErr.takeError(); | |||
2952 | } | |||
2953 | ||||
2954 | // Import TemplateArgumentListInfo. | |||
2955 | TemplateArgumentListInfo ToTAInfo; | |||
2956 | if (Error Err = ImportTemplateArgumentListInfo( | |||
2957 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), | |||
2958 | llvm::makeArrayRef( | |||
2959 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), | |||
2960 | ToTAInfo)) | |||
2961 | return Err; | |||
2962 | ||||
2963 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), | |||
2964 | TemplDecls, ToTAInfo); | |||
2965 | return Error::success(); | |||
2966 | } | |||
2967 | } | |||
2968 | llvm_unreachable("All cases should be covered!")::llvm::llvm_unreachable_internal("All cases should be covered!" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 2968); | |||
2969 | } | |||
2970 | ||||
2971 | Expected<FunctionDecl *> | |||
2972 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { | |||
2973 | auto FunctionAndArgsOrErr = | |||
2974 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); | |||
2975 | if (!FunctionAndArgsOrErr) | |||
2976 | return FunctionAndArgsOrErr.takeError(); | |||
2977 | ||||
2978 | FunctionTemplateDecl *Template; | |||
2979 | TemplateArgsTy ToTemplArgs; | |||
2980 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; | |||
2981 | void *InsertPos = nullptr; | |||
2982 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); | |||
2983 | return FoundSpec; | |||
2984 | } | |||
2985 | ||||
2986 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { | |||
2987 | ||||
2988 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); | |||
2989 | auto RedeclIt = Redecls.begin(); | |||
2990 | // Import the first part of the decl chain. I.e. import all previous | |||
2991 | // declarations starting from the canonical decl. | |||
2992 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { | |||
2993 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); | |||
2994 | if (!ToRedeclOrErr) | |||
2995 | return ToRedeclOrErr.takeError(); | |||
2996 | } | |||
2997 | assert(*RedeclIt == D)((*RedeclIt == D) ? static_cast<void> (0) : __assert_fail ("*RedeclIt == D", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 2997, __PRETTY_FUNCTION__)); | |||
2998 | ||||
2999 | // Import the major distinguishing characteristics of this function. | |||
3000 | DeclContext *DC, *LexicalDC; | |||
3001 | DeclarationName Name; | |||
3002 | SourceLocation Loc; | |||
3003 | NamedDecl *ToD; | |||
3004 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3005 | return std::move(Err); | |||
3006 | if (ToD) | |||
3007 | return ToD; | |||
3008 | ||||
3009 | const FunctionDecl *FoundByLookup = nullptr; | |||
3010 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); | |||
3011 | ||||
3012 | // If this is a function template specialization, then try to find the same | |||
3013 | // existing specialization in the "to" context. The localUncachedLookup | |||
3014 | // below will not find any specialization, but would find the primary | |||
3015 | // template; thus, we have to skip normal lookup in case of specializations. | |||
3016 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? | |||
3017 | if (D->getTemplatedKind() == | |||
3018 | FunctionDecl::TK_FunctionTemplateSpecialization) { | |||
3019 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); | |||
3020 | if (!FoundFunctionOrErr) | |||
3021 | return FoundFunctionOrErr.takeError(); | |||
3022 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { | |||
3023 | if (D->doesThisDeclarationHaveABody() && FoundFunction->hasBody()) | |||
3024 | return Importer.MapImported(D, FoundFunction); | |||
3025 | FoundByLookup = FoundFunction; | |||
3026 | } | |||
3027 | } | |||
3028 | // Try to find a function in our own ("to") context with the same name, same | |||
3029 | // type, and in the same context as the function we're importing. | |||
3030 | else if (!LexicalDC->isFunctionOrMethod()) { | |||
3031 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
3032 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; | |||
3033 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
3034 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
3035 | for (auto *FoundDecl : FoundDecls) { | |||
3036 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
3037 | continue; | |||
3038 | ||||
3039 | // If template was found, look at the templated function. | |||
3040 | if (FromFT) { | |||
3041 | if (auto *Template = dyn_cast<FunctionTemplateDecl>(FoundDecl)) | |||
3042 | FoundDecl = Template->getTemplatedDecl(); | |||
3043 | else | |||
3044 | continue; | |||
3045 | } | |||
3046 | ||||
3047 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { | |||
3048 | if (FoundFunction->hasExternalFormalLinkage() && | |||
3049 | D->hasExternalFormalLinkage()) { | |||
3050 | if (IsStructuralMatch(D, FoundFunction)) { | |||
3051 | const FunctionDecl *Definition = nullptr; | |||
3052 | if (D->doesThisDeclarationHaveABody() && | |||
3053 | FoundFunction->hasBody(Definition)) { | |||
3054 | return Importer.MapImported( | |||
3055 | D, const_cast<FunctionDecl *>(Definition)); | |||
3056 | } | |||
3057 | FoundByLookup = FoundFunction; | |||
3058 | break; | |||
3059 | } | |||
3060 | ||||
3061 | // FIXME: Check for overloading more carefully, e.g., by boosting | |||
3062 | // Sema::IsOverload out to the AST library. | |||
3063 | ||||
3064 | // Function overloading is okay in C++. | |||
3065 | if (Importer.getToContext().getLangOpts().CPlusPlus) | |||
3066 | continue; | |||
3067 | ||||
3068 | // Complain about inconsistent function types. | |||
3069 | Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent) | |||
3070 | << Name << D->getType() << FoundFunction->getType(); | |||
3071 | Importer.ToDiag(FoundFunction->getLocation(), | |||
3072 | diag::note_odr_value_here) | |||
3073 | << FoundFunction->getType(); | |||
3074 | } | |||
3075 | } | |||
3076 | ||||
3077 | ConflictingDecls.push_back(FoundDecl); | |||
3078 | } | |||
3079 | ||||
3080 | if (!ConflictingDecls.empty()) { | |||
3081 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | |||
3082 | ConflictingDecls.data(), | |||
3083 | ConflictingDecls.size()); | |||
3084 | if (!Name) | |||
3085 | return make_error<ImportError>(ImportError::NameConflict); | |||
3086 | } | |||
3087 | } | |||
3088 | ||||
3089 | DeclarationNameInfo NameInfo(Name, Loc); | |||
3090 | // Import additional name location/type info. | |||
3091 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | |||
3092 | return std::move(Err); | |||
3093 | ||||
3094 | QualType FromTy = D->getType(); | |||
3095 | bool usedDifferentExceptionSpec = false; | |||
3096 | ||||
3097 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { | |||
3098 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); | |||
3099 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the | |||
3100 | // FunctionDecl that we are importing the FunctionProtoType for. | |||
3101 | // To avoid an infinite recursion when importing, create the FunctionDecl | |||
3102 | // with a simplified function type and update it afterwards. | |||
3103 | if (FromEPI.ExceptionSpec.SourceDecl || | |||
3104 | FromEPI.ExceptionSpec.SourceTemplate || | |||
3105 | FromEPI.ExceptionSpec.NoexceptExpr) { | |||
3106 | FunctionProtoType::ExtProtoInfo DefaultEPI; | |||
3107 | FromTy = Importer.getFromContext().getFunctionType( | |||
3108 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); | |||
3109 | usedDifferentExceptionSpec = true; | |||
3110 | } | |||
3111 | } | |||
3112 | ||||
3113 | QualType T; | |||
3114 | TypeSourceInfo *TInfo; | |||
3115 | SourceLocation ToInnerLocStart, ToEndLoc; | |||
3116 | NestedNameSpecifierLoc ToQualifierLoc; | |||
3117 | if (auto Imp = importSeq( | |||
3118 | FromTy, D->getTypeSourceInfo(), D->getInnerLocStart(), | |||
3119 | D->getQualifierLoc(), D->getEndLoc())) | |||
3120 | std::tie(T, TInfo, ToInnerLocStart, ToQualifierLoc, ToEndLoc) = *Imp; | |||
3121 | else | |||
3122 | return Imp.takeError(); | |||
3123 | ||||
3124 | // Import the function parameters. | |||
3125 | SmallVector<ParmVarDecl *, 8> Parameters; | |||
3126 | for (auto P : D->parameters()) { | |||
3127 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) | |||
3128 | Parameters.push_back(*ToPOrErr); | |||
3129 | else | |||
3130 | return ToPOrErr.takeError(); | |||
3131 | } | |||
3132 | ||||
3133 | // Create the imported function. | |||
3134 | FunctionDecl *ToFunction = nullptr; | |||
3135 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { | |||
3136 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( | |||
3137 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | |||
3138 | ToInnerLocStart, NameInfo, T, TInfo, | |||
3139 | FromConstructor->isExplicit(), | |||
3140 | D->isInlineSpecified(), D->isImplicit(), D->isConstexpr())) | |||
3141 | return ToFunction; | |||
3142 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { | |||
3143 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); | |||
3144 | // Import first, then allocate memory and copy if there was no error. | |||
3145 | if (Error Err = ImportContainerChecked( | |||
3146 | FromConstructor->inits(), CtorInitializers)) | |||
3147 | return std::move(Err); | |||
3148 | auto **Memory = | |||
3149 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; | |||
3150 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); | |||
3151 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); | |||
3152 | ToCtor->setCtorInitializers(Memory); | |||
3153 | ToCtor->setNumCtorInitializers(NumInitializers); | |||
3154 | } | |||
3155 | } else if (isa<CXXDestructorDecl>(D)) { | |||
3156 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( | |||
3157 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | |||
3158 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), | |||
3159 | D->isImplicit())) | |||
3160 | return ToFunction; | |||
3161 | } else if (CXXConversionDecl *FromConversion = | |||
3162 | dyn_cast<CXXConversionDecl>(D)) { | |||
3163 | if (GetImportedOrCreateDecl<CXXConversionDecl>( | |||
3164 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | |||
3165 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), | |||
3166 | FromConversion->isExplicit(), D->isConstexpr(), SourceLocation())) | |||
3167 | return ToFunction; | |||
3168 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { | |||
3169 | if (GetImportedOrCreateDecl<CXXMethodDecl>( | |||
3170 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | |||
3171 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), | |||
3172 | Method->isInlineSpecified(), D->isConstexpr(), SourceLocation())) | |||
3173 | return ToFunction; | |||
3174 | } else { | |||
3175 | if (GetImportedOrCreateDecl(ToFunction, D, Importer.getToContext(), DC, | |||
3176 | ToInnerLocStart, NameInfo, T, TInfo, | |||
3177 | D->getStorageClass(), D->isInlineSpecified(), | |||
3178 | D->hasWrittenPrototype(), D->isConstexpr())) | |||
3179 | return ToFunction; | |||
3180 | } | |||
3181 | ||||
3182 | ToFunction->setQualifierInfo(ToQualifierLoc); | |||
3183 | ToFunction->setAccess(D->getAccess()); | |||
3184 | ToFunction->setLexicalDeclContext(LexicalDC); | |||
3185 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); | |||
3186 | ToFunction->setTrivial(D->isTrivial()); | |||
3187 | ToFunction->setPure(D->isPure()); | |||
3188 | ToFunction->setRangeEnd(ToEndLoc); | |||
3189 | ||||
3190 | // Set the parameters. | |||
3191 | for (auto *Param : Parameters) { | |||
3192 | Param->setOwningFunction(ToFunction); | |||
3193 | ToFunction->addDeclInternal(Param); | |||
3194 | } | |||
3195 | ToFunction->setParams(Parameters); | |||
3196 | ||||
3197 | if (FoundByLookup) { | |||
3198 | auto *Recent = const_cast<FunctionDecl *>( | |||
3199 | FoundByLookup->getMostRecentDecl()); | |||
3200 | ToFunction->setPreviousDecl(Recent); | |||
3201 | } | |||
3202 | ||||
3203 | // We need to complete creation of FunctionProtoTypeLoc manually with setting | |||
3204 | // params it refers to. | |||
3205 | if (TInfo) { | |||
3206 | if (auto ProtoLoc = | |||
3207 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { | |||
3208 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) | |||
3209 | ProtoLoc.setParam(I, Parameters[I]); | |||
3210 | } | |||
3211 | } | |||
3212 | ||||
3213 | if (usedDifferentExceptionSpec) { | |||
3214 | // Update FunctionProtoType::ExtProtoInfo. | |||
3215 | if (ExpectedType TyOrErr = import(D->getType())) | |||
3216 | ToFunction->setType(*TyOrErr); | |||
3217 | else | |||
3218 | return TyOrErr.takeError(); | |||
3219 | } | |||
3220 | ||||
3221 | // Import the describing template function, if any. | |||
3222 | if (FromFT) { | |||
3223 | auto ToFTOrErr = import(FromFT); | |||
3224 | if (!ToFTOrErr) | |||
3225 | return ToFTOrErr.takeError(); | |||
3226 | } | |||
3227 | ||||
3228 | if (D->doesThisDeclarationHaveABody()) { | |||
3229 | if (Stmt *FromBody = D->getBody()) { | |||
3230 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) | |||
3231 | ToFunction->setBody(*ToBodyOrErr); | |||
3232 | else | |||
3233 | return ToBodyOrErr.takeError(); | |||
3234 | } | |||
3235 | } | |||
3236 | ||||
3237 | // FIXME: Other bits to merge? | |||
3238 | ||||
3239 | // If it is a template, import all related things. | |||
3240 | if (Error Err = ImportTemplateInformation(D, ToFunction)) | |||
3241 | return std::move(Err); | |||
3242 | ||||
3243 | bool IsFriend = D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend); | |||
3244 | ||||
3245 | // TODO Can we generalize this approach to other AST nodes as well? | |||
3246 | if (D->getDeclContext()->containsDeclAndLoad(D)) | |||
3247 | DC->addDeclInternal(ToFunction); | |||
3248 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) | |||
3249 | LexicalDC->addDeclInternal(ToFunction); | |||
3250 | ||||
3251 | // Friend declaration's lexical context is the befriending class, but the | |||
3252 | // semantic context is the enclosing scope of the befriending class. | |||
3253 | // We want the friend functions to be found in the semantic context by lookup. | |||
3254 | // FIXME should we handle this generically in VisitFriendDecl? | |||
3255 | // In Other cases when LexicalDC != DC we don't want it to be added, | |||
3256 | // e.g out-of-class definitions like void B::f() {} . | |||
3257 | if (LexicalDC != DC && IsFriend) { | |||
3258 | DC->makeDeclVisibleInContext(ToFunction); | |||
3259 | } | |||
3260 | ||||
3261 | // Import the rest of the chain. I.e. import all subsequent declarations. | |||
3262 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { | |||
3263 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); | |||
3264 | if (!ToRedeclOrErr) | |||
3265 | return ToRedeclOrErr.takeError(); | |||
3266 | } | |||
3267 | ||||
3268 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) | |||
3269 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); | |||
3270 | ||||
3271 | return ToFunction; | |||
3272 | } | |||
3273 | ||||
3274 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { | |||
3275 | return VisitFunctionDecl(D); | |||
3276 | } | |||
3277 | ||||
3278 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { | |||
3279 | return VisitCXXMethodDecl(D); | |||
3280 | } | |||
3281 | ||||
3282 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { | |||
3283 | return VisitCXXMethodDecl(D); | |||
3284 | } | |||
3285 | ||||
3286 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { | |||
3287 | return VisitCXXMethodDecl(D); | |||
3288 | } | |||
3289 | ||||
3290 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { | |||
3291 | // Import the major distinguishing characteristics of a variable. | |||
3292 | DeclContext *DC, *LexicalDC; | |||
3293 | DeclarationName Name; | |||
3294 | SourceLocation Loc; | |||
3295 | NamedDecl *ToD; | |||
3296 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3297 | return std::move(Err); | |||
3298 | if (ToD) | |||
3299 | return ToD; | |||
3300 | ||||
3301 | // Determine whether we've already imported this field. | |||
3302 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
3303 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
3304 | for (auto *FoundDecl : FoundDecls) { | |||
3305 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { | |||
3306 | // For anonymous fields, match up by index. | |||
3307 | if (!Name && | |||
3308 | ASTImporter::getFieldIndex(D) != | |||
3309 | ASTImporter::getFieldIndex(FoundField)) | |||
3310 | continue; | |||
3311 | ||||
3312 | if (Importer.IsStructurallyEquivalent(D->getType(), | |||
3313 | FoundField->getType())) { | |||
3314 | Importer.MapImported(D, FoundField); | |||
3315 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the | |||
3316 | // initializer of a FieldDecl might not had been instantiated in the | |||
3317 | // "To" context. However, the "From" context might instantiated that, | |||
3318 | // thus we have to merge that. | |||
3319 | if (Expr *FromInitializer = D->getInClassInitializer()) { | |||
3320 | // We don't have yet the initializer set. | |||
3321 | if (FoundField->hasInClassInitializer() && | |||
3322 | !FoundField->getInClassInitializer()) { | |||
3323 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) | |||
3324 | FoundField->setInClassInitializer(*ToInitializerOrErr); | |||
3325 | else { | |||
3326 | // We can't return error here, | |||
3327 | // since we already mapped D as imported. | |||
3328 | // FIXME: warning message? | |||
3329 | consumeError(ToInitializerOrErr.takeError()); | |||
3330 | return FoundField; | |||
3331 | } | |||
3332 | } | |||
3333 | } | |||
3334 | return FoundField; | |||
3335 | } | |||
3336 | ||||
3337 | // FIXME: Why is this case not handled with calling HandleNameConflict? | |||
3338 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) | |||
3339 | << Name << D->getType() << FoundField->getType(); | |||
3340 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) | |||
3341 | << FoundField->getType(); | |||
3342 | ||||
3343 | return make_error<ImportError>(ImportError::NameConflict); | |||
3344 | } | |||
3345 | } | |||
3346 | ||||
3347 | QualType ToType; | |||
3348 | TypeSourceInfo *ToTInfo; | |||
3349 | Expr *ToBitWidth; | |||
3350 | SourceLocation ToInnerLocStart; | |||
3351 | Expr *ToInitializer; | |||
3352 | if (auto Imp = importSeq( | |||
3353 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), | |||
3354 | D->getInnerLocStart(), D->getInClassInitializer())) | |||
3355 | std::tie( | |||
3356 | ToType, ToTInfo, ToBitWidth, ToInnerLocStart, ToInitializer) = *Imp; | |||
3357 | else | |||
3358 | return Imp.takeError(); | |||
3359 | ||||
3360 | FieldDecl *ToField; | |||
3361 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, | |||
3362 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), | |||
3363 | ToType, ToTInfo, ToBitWidth, D->isMutable(), | |||
3364 | D->getInClassInitStyle())) | |||
3365 | return ToField; | |||
3366 | ||||
3367 | ToField->setAccess(D->getAccess()); | |||
3368 | ToField->setLexicalDeclContext(LexicalDC); | |||
3369 | if (ToInitializer) | |||
3370 | ToField->setInClassInitializer(ToInitializer); | |||
3371 | ToField->setImplicit(D->isImplicit()); | |||
3372 | LexicalDC->addDeclInternal(ToField); | |||
3373 | return ToField; | |||
3374 | } | |||
3375 | ||||
3376 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { | |||
3377 | // Import the major distinguishing characteristics of a variable. | |||
3378 | DeclContext *DC, *LexicalDC; | |||
3379 | DeclarationName Name; | |||
3380 | SourceLocation Loc; | |||
3381 | NamedDecl *ToD; | |||
3382 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3383 | return std::move(Err); | |||
3384 | if (ToD) | |||
3385 | return ToD; | |||
3386 | ||||
3387 | // Determine whether we've already imported this field. | |||
3388 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
3389 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
3390 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | |||
3391 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { | |||
3392 | // For anonymous indirect fields, match up by index. | |||
3393 | if (!Name && | |||
3394 | ASTImporter::getFieldIndex(D) != | |||
3395 | ASTImporter::getFieldIndex(FoundField)) | |||
3396 | continue; | |||
3397 | ||||
3398 | if (Importer.IsStructurallyEquivalent(D->getType(), | |||
3399 | FoundField->getType(), | |||
3400 | !Name.isEmpty())) { | |||
3401 | Importer.MapImported(D, FoundField); | |||
3402 | return FoundField; | |||
3403 | } | |||
3404 | ||||
3405 | // If there are more anonymous fields to check, continue. | |||
3406 | if (!Name && I < N-1) | |||
3407 | continue; | |||
3408 | ||||
3409 | // FIXME: Why is this case not handled with calling HandleNameConflict? | |||
3410 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) | |||
3411 | << Name << D->getType() << FoundField->getType(); | |||
3412 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) | |||
3413 | << FoundField->getType(); | |||
3414 | ||||
3415 | return make_error<ImportError>(ImportError::NameConflict); | |||
3416 | } | |||
3417 | } | |||
3418 | ||||
3419 | // Import the type. | |||
3420 | auto TypeOrErr = import(D->getType()); | |||
3421 | if (!TypeOrErr) | |||
3422 | return TypeOrErr.takeError(); | |||
3423 | ||||
3424 | auto **NamedChain = | |||
3425 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; | |||
3426 | ||||
3427 | unsigned i = 0; | |||
3428 | for (auto *PI : D->chain()) | |||
3429 | if (Expected<NamedDecl *> ToD = import(PI)) | |||
3430 | NamedChain[i++] = *ToD; | |||
3431 | else | |||
3432 | return ToD.takeError(); | |||
3433 | ||||
3434 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; | |||
3435 | IndirectFieldDecl *ToIndirectField; | |||
3436 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, | |||
3437 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) | |||
3438 | // FIXME here we leak `NamedChain` which is allocated before | |||
3439 | return ToIndirectField; | |||
3440 | ||||
3441 | for (const auto *Attr : D->attrs()) | |||
3442 | ToIndirectField->addAttr(Importer.Import(Attr)); | |||
3443 | ||||
3444 | ToIndirectField->setAccess(D->getAccess()); | |||
3445 | ToIndirectField->setLexicalDeclContext(LexicalDC); | |||
3446 | LexicalDC->addDeclInternal(ToIndirectField); | |||
3447 | return ToIndirectField; | |||
3448 | } | |||
3449 | ||||
3450 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { | |||
3451 | // Import the major distinguishing characteristics of a declaration. | |||
3452 | DeclContext *DC, *LexicalDC; | |||
3453 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
3454 | return std::move(Err); | |||
3455 | ||||
3456 | // Determine whether we've already imported this decl. | |||
3457 | // FriendDecl is not a NamedDecl so we cannot use localUncachedLookup. | |||
3458 | auto *RD = cast<CXXRecordDecl>(DC); | |||
3459 | FriendDecl *ImportedFriend = RD->getFirstFriend(); | |||
3460 | ||||
3461 | while (ImportedFriend) { | |||
3462 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { | |||
3463 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), | |||
3464 | /*Complain=*/false)) | |||
3465 | return Importer.MapImported(D, ImportedFriend); | |||
3466 | ||||
3467 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { | |||
3468 | if (Importer.IsStructurallyEquivalent( | |||
3469 | D->getFriendType()->getType(), | |||
3470 | ImportedFriend->getFriendType()->getType(), true)) | |||
3471 | return Importer.MapImported(D, ImportedFriend); | |||
3472 | } | |||
3473 | ImportedFriend = ImportedFriend->getNextFriend(); | |||
3474 | } | |||
3475 | ||||
3476 | // Not found. Create it. | |||
3477 | FriendDecl::FriendUnion ToFU; | |||
3478 | if (NamedDecl *FriendD = D->getFriendDecl()) { | |||
3479 | NamedDecl *ToFriendD; | |||
3480 | if (Error Err = importInto(ToFriendD, FriendD)) | |||
3481 | return std::move(Err); | |||
3482 | ||||
3483 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && | |||
3484 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) | |||
3485 | ToFriendD->setObjectOfFriendDecl(false); | |||
3486 | ||||
3487 | ToFU = ToFriendD; | |||
3488 | } else { // The friend is a type, not a decl. | |||
3489 | if (auto TSIOrErr = import(D->getFriendType())) | |||
3490 | ToFU = *TSIOrErr; | |||
3491 | else | |||
3492 | return TSIOrErr.takeError(); | |||
3493 | } | |||
3494 | ||||
3495 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); | |||
3496 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); | |||
3497 | for (unsigned I = 0; I < D->NumTPLists; I++) { | |||
3498 | if (auto ListOrErr = ImportTemplateParameterList(FromTPLists[I])) | |||
3499 | ToTPLists[I] = *ListOrErr; | |||
3500 | else | |||
3501 | return ListOrErr.takeError(); | |||
3502 | } | |||
3503 | ||||
3504 | auto LocationOrErr = import(D->getLocation()); | |||
3505 | if (!LocationOrErr) | |||
3506 | return LocationOrErr.takeError(); | |||
3507 | auto FriendLocOrErr = import(D->getFriendLoc()); | |||
3508 | if (!FriendLocOrErr) | |||
3509 | return FriendLocOrErr.takeError(); | |||
3510 | ||||
3511 | FriendDecl *FrD; | |||
3512 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, | |||
3513 | *LocationOrErr, ToFU, | |||
3514 | *FriendLocOrErr, ToTPLists)) | |||
3515 | return FrD; | |||
3516 | ||||
3517 | FrD->setAccess(D->getAccess()); | |||
3518 | FrD->setLexicalDeclContext(LexicalDC); | |||
3519 | LexicalDC->addDeclInternal(FrD); | |||
3520 | return FrD; | |||
3521 | } | |||
3522 | ||||
3523 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { | |||
3524 | // Import the major distinguishing characteristics of an ivar. | |||
3525 | DeclContext *DC, *LexicalDC; | |||
3526 | DeclarationName Name; | |||
3527 | SourceLocation Loc; | |||
3528 | NamedDecl *ToD; | |||
3529 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3530 | return std::move(Err); | |||
3531 | if (ToD) | |||
3532 | return ToD; | |||
3533 | ||||
3534 | // Determine whether we've already imported this ivar | |||
3535 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
3536 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
3537 | for (auto *FoundDecl : FoundDecls) { | |||
3538 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { | |||
3539 | if (Importer.IsStructurallyEquivalent(D->getType(), | |||
3540 | FoundIvar->getType())) { | |||
3541 | Importer.MapImported(D, FoundIvar); | |||
3542 | return FoundIvar; | |||
3543 | } | |||
3544 | ||||
3545 | Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent) | |||
3546 | << Name << D->getType() << FoundIvar->getType(); | |||
3547 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) | |||
3548 | << FoundIvar->getType(); | |||
3549 | ||||
3550 | return make_error<ImportError>(ImportError::NameConflict); | |||
3551 | } | |||
3552 | } | |||
3553 | ||||
3554 | QualType ToType; | |||
3555 | TypeSourceInfo *ToTypeSourceInfo; | |||
3556 | Expr *ToBitWidth; | |||
3557 | SourceLocation ToInnerLocStart; | |||
3558 | if (auto Imp = importSeq( | |||
3559 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), D->getInnerLocStart())) | |||
3560 | std::tie(ToType, ToTypeSourceInfo, ToBitWidth, ToInnerLocStart) = *Imp; | |||
3561 | else | |||
3562 | return Imp.takeError(); | |||
3563 | ||||
3564 | ObjCIvarDecl *ToIvar; | |||
3565 | if (GetImportedOrCreateDecl( | |||
3566 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), | |||
3567 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), | |||
3568 | ToType, ToTypeSourceInfo, | |||
3569 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) | |||
3570 | return ToIvar; | |||
3571 | ||||
3572 | ToIvar->setLexicalDeclContext(LexicalDC); | |||
3573 | LexicalDC->addDeclInternal(ToIvar); | |||
3574 | return ToIvar; | |||
3575 | } | |||
3576 | ||||
3577 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { | |||
3578 | ||||
3579 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); | |||
3580 | auto RedeclIt = Redecls.begin(); | |||
3581 | // Import the first part of the decl chain. I.e. import all previous | |||
3582 | // declarations starting from the canonical decl. | |||
3583 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { | |||
3584 | ExpectedDecl RedeclOrErr = import(*RedeclIt); | |||
3585 | if (!RedeclOrErr) | |||
3586 | return RedeclOrErr.takeError(); | |||
3587 | } | |||
3588 | assert(*RedeclIt == D)((*RedeclIt == D) ? static_cast<void> (0) : __assert_fail ("*RedeclIt == D", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 3588, __PRETTY_FUNCTION__)); | |||
3589 | ||||
3590 | // Import the major distinguishing characteristics of a variable. | |||
3591 | DeclContext *DC, *LexicalDC; | |||
3592 | DeclarationName Name; | |||
3593 | SourceLocation Loc; | |||
3594 | NamedDecl *ToD; | |||
3595 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3596 | return std::move(Err); | |||
3597 | if (ToD) | |||
3598 | return ToD; | |||
3599 | ||||
3600 | // Try to find a variable in our own ("to") context with the same name and | |||
3601 | // in the same context as the variable we're importing. | |||
3602 | VarDecl *FoundByLookup = nullptr; | |||
3603 | if (D->isFileVarDecl()) { | |||
3604 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
3605 | unsigned IDNS = Decl::IDNS_Ordinary; | |||
3606 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
3607 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
3608 | for (auto *FoundDecl : FoundDecls) { | |||
3609 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
3610 | continue; | |||
3611 | ||||
3612 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { | |||
3613 | // We have found a variable that we may need to merge with. Check it. | |||
3614 | if (FoundVar->hasExternalFormalLinkage() && | |||
3615 | D->hasExternalFormalLinkage()) { | |||
3616 | if (Importer.IsStructurallyEquivalent(D->getType(), | |||
3617 | FoundVar->getType())) { | |||
3618 | ||||
3619 | // The VarDecl in the "From" context has a definition, but in the | |||
3620 | // "To" context we already have a definition. | |||
3621 | VarDecl *FoundDef = FoundVar->getDefinition(); | |||
3622 | if (D->isThisDeclarationADefinition() && FoundDef) | |||
3623 | // FIXME Check for ODR error if the two definitions have | |||
3624 | // different initializers? | |||
3625 | return Importer.MapImported(D, FoundDef); | |||
3626 | ||||
3627 | // The VarDecl in the "From" context has an initializer, but in the | |||
3628 | // "To" context we already have an initializer. | |||
3629 | const VarDecl *FoundDInit = nullptr; | |||
3630 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) | |||
3631 | // FIXME Diagnose ODR error if the two initializers are different? | |||
3632 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); | |||
3633 | ||||
3634 | FoundByLookup = FoundVar; | |||
3635 | break; | |||
3636 | } | |||
3637 | ||||
3638 | const ArrayType *FoundArray | |||
3639 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); | |||
3640 | const ArrayType *TArray | |||
3641 | = Importer.getToContext().getAsArrayType(D->getType()); | |||
3642 | if (FoundArray && TArray) { | |||
3643 | if (isa<IncompleteArrayType>(FoundArray) && | |||
3644 | isa<ConstantArrayType>(TArray)) { | |||
3645 | // Import the type. | |||
3646 | if (auto TyOrErr = import(D->getType())) | |||
3647 | FoundVar->setType(*TyOrErr); | |||
3648 | else | |||
3649 | return TyOrErr.takeError(); | |||
3650 | ||||
3651 | FoundByLookup = FoundVar; | |||
3652 | break; | |||
3653 | } else if (isa<IncompleteArrayType>(TArray) && | |||
3654 | isa<ConstantArrayType>(FoundArray)) { | |||
3655 | FoundByLookup = FoundVar; | |||
3656 | break; | |||
3657 | } | |||
3658 | } | |||
3659 | ||||
3660 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) | |||
3661 | << Name << D->getType() << FoundVar->getType(); | |||
3662 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) | |||
3663 | << FoundVar->getType(); | |||
3664 | } | |||
3665 | } | |||
3666 | ||||
3667 | ConflictingDecls.push_back(FoundDecl); | |||
3668 | } | |||
3669 | ||||
3670 | if (!ConflictingDecls.empty()) { | |||
3671 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | |||
3672 | ConflictingDecls.data(), | |||
3673 | ConflictingDecls.size()); | |||
3674 | if (!Name) | |||
3675 | return make_error<ImportError>(ImportError::NameConflict); | |||
3676 | } | |||
3677 | } | |||
3678 | ||||
3679 | QualType ToType; | |||
3680 | TypeSourceInfo *ToTypeSourceInfo; | |||
3681 | SourceLocation ToInnerLocStart; | |||
3682 | NestedNameSpecifierLoc ToQualifierLoc; | |||
3683 | if (auto Imp = importSeq( | |||
3684 | D->getType(), D->getTypeSourceInfo(), D->getInnerLocStart(), | |||
3685 | D->getQualifierLoc())) | |||
3686 | std::tie(ToType, ToTypeSourceInfo, ToInnerLocStart, ToQualifierLoc) = *Imp; | |||
3687 | else | |||
3688 | return Imp.takeError(); | |||
3689 | ||||
3690 | // Create the imported variable. | |||
3691 | VarDecl *ToVar; | |||
3692 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, | |||
3693 | ToInnerLocStart, Loc, | |||
3694 | Name.getAsIdentifierInfo(), | |||
3695 | ToType, ToTypeSourceInfo, | |||
3696 | D->getStorageClass())) | |||
3697 | return ToVar; | |||
3698 | ||||
3699 | ToVar->setQualifierInfo(ToQualifierLoc); | |||
3700 | ToVar->setAccess(D->getAccess()); | |||
3701 | ToVar->setLexicalDeclContext(LexicalDC); | |||
3702 | ||||
3703 | if (FoundByLookup) { | |||
3704 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); | |||
3705 | ToVar->setPreviousDecl(Recent); | |||
3706 | } | |||
3707 | ||||
3708 | if (Error Err = ImportInitializer(D, ToVar)) | |||
3709 | return std::move(Err); | |||
3710 | ||||
3711 | if (D->isConstexpr()) | |||
3712 | ToVar->setConstexpr(true); | |||
3713 | ||||
3714 | if (D->getDeclContext()->containsDeclAndLoad(D)) | |||
3715 | DC->addDeclInternal(ToVar); | |||
3716 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) | |||
3717 | LexicalDC->addDeclInternal(ToVar); | |||
3718 | ||||
3719 | // Import the rest of the chain. I.e. import all subsequent declarations. | |||
3720 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { | |||
3721 | ExpectedDecl RedeclOrErr = import(*RedeclIt); | |||
3722 | if (!RedeclOrErr) | |||
3723 | return RedeclOrErr.takeError(); | |||
3724 | } | |||
3725 | ||||
3726 | return ToVar; | |||
3727 | } | |||
3728 | ||||
3729 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { | |||
3730 | // Parameters are created in the translation unit's context, then moved | |||
3731 | // into the function declaration's context afterward. | |||
3732 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); | |||
3733 | ||||
3734 | DeclarationName ToDeclName; | |||
3735 | SourceLocation ToLocation; | |||
3736 | QualType ToType; | |||
3737 | if (auto Imp = importSeq(D->getDeclName(), D->getLocation(), D->getType())) | |||
3738 | std::tie(ToDeclName, ToLocation, ToType) = *Imp; | |||
3739 | else | |||
3740 | return Imp.takeError(); | |||
3741 | ||||
3742 | // Create the imported parameter. | |||
3743 | ImplicitParamDecl *ToParm = nullptr; | |||
3744 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, | |||
3745 | ToLocation, ToDeclName.getAsIdentifierInfo(), | |||
3746 | ToType, D->getParameterKind())) | |||
3747 | return ToParm; | |||
3748 | return ToParm; | |||
3749 | } | |||
3750 | ||||
3751 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { | |||
3752 | // Parameters are created in the translation unit's context, then moved | |||
3753 | // into the function declaration's context afterward. | |||
3754 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); | |||
3755 | ||||
3756 | DeclarationName ToDeclName; | |||
3757 | SourceLocation ToLocation, ToInnerLocStart; | |||
3758 | QualType ToType; | |||
3759 | TypeSourceInfo *ToTypeSourceInfo; | |||
3760 | if (auto Imp = importSeq( | |||
3761 | D->getDeclName(), D->getLocation(), D->getType(), D->getInnerLocStart(), | |||
3762 | D->getTypeSourceInfo())) | |||
3763 | std::tie( | |||
3764 | ToDeclName, ToLocation, ToType, ToInnerLocStart, | |||
3765 | ToTypeSourceInfo) = *Imp; | |||
3766 | else | |||
3767 | return Imp.takeError(); | |||
3768 | ||||
3769 | ParmVarDecl *ToParm; | |||
3770 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, | |||
3771 | ToInnerLocStart, ToLocation, | |||
3772 | ToDeclName.getAsIdentifierInfo(), ToType, | |||
3773 | ToTypeSourceInfo, D->getStorageClass(), | |||
3774 | /*DefaultArg*/ nullptr)) | |||
3775 | return ToParm; | |||
3776 | ||||
3777 | // Set the default argument. | |||
3778 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); | |||
3779 | ToParm->setKNRPromoted(D->isKNRPromoted()); | |||
3780 | ||||
3781 | if (D->hasUninstantiatedDefaultArg()) { | |||
3782 | if (auto ToDefArgOrErr = import(D->getUninstantiatedDefaultArg())) | |||
3783 | ToParm->setUninstantiatedDefaultArg(*ToDefArgOrErr); | |||
3784 | else | |||
3785 | return ToDefArgOrErr.takeError(); | |||
3786 | } else if (D->hasUnparsedDefaultArg()) { | |||
3787 | ToParm->setUnparsedDefaultArg(); | |||
3788 | } else if (D->hasDefaultArg()) { | |||
3789 | if (auto ToDefArgOrErr = import(D->getDefaultArg())) | |||
3790 | ToParm->setDefaultArg(*ToDefArgOrErr); | |||
3791 | else | |||
3792 | return ToDefArgOrErr.takeError(); | |||
3793 | } | |||
3794 | ||||
3795 | if (D->isObjCMethodParameter()) { | |||
3796 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); | |||
3797 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); | |||
3798 | } else { | |||
3799 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), | |||
3800 | D->getFunctionScopeIndex()); | |||
3801 | } | |||
3802 | ||||
3803 | return ToParm; | |||
3804 | } | |||
3805 | ||||
3806 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { | |||
3807 | // Import the major distinguishing characteristics of a method. | |||
3808 | DeclContext *DC, *LexicalDC; | |||
3809 | DeclarationName Name; | |||
3810 | SourceLocation Loc; | |||
3811 | NamedDecl *ToD; | |||
3812 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3813 | return std::move(Err); | |||
3814 | if (ToD) | |||
3815 | return ToD; | |||
3816 | ||||
3817 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
3818 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
3819 | for (auto *FoundDecl : FoundDecls) { | |||
3820 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { | |||
3821 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) | |||
3822 | continue; | |||
3823 | ||||
3824 | // Check return types. | |||
3825 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), | |||
3826 | FoundMethod->getReturnType())) { | |||
3827 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) | |||
3828 | << D->isInstanceMethod() << Name << D->getReturnType() | |||
3829 | << FoundMethod->getReturnType(); | |||
3830 | Importer.ToDiag(FoundMethod->getLocation(), | |||
3831 | diag::note_odr_objc_method_here) | |||
3832 | << D->isInstanceMethod() << Name; | |||
3833 | ||||
3834 | return make_error<ImportError>(ImportError::NameConflict); | |||
3835 | } | |||
3836 | ||||
3837 | // Check the number of parameters. | |||
3838 | if (D->param_size() != FoundMethod->param_size()) { | |||
3839 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) | |||
3840 | << D->isInstanceMethod() << Name | |||
3841 | << D->param_size() << FoundMethod->param_size(); | |||
3842 | Importer.ToDiag(FoundMethod->getLocation(), | |||
3843 | diag::note_odr_objc_method_here) | |||
3844 | << D->isInstanceMethod() << Name; | |||
3845 | ||||
3846 | return make_error<ImportError>(ImportError::NameConflict); | |||
3847 | } | |||
3848 | ||||
3849 | // Check parameter types. | |||
3850 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), | |||
3851 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); | |||
3852 | P != PEnd; ++P, ++FoundP) { | |||
3853 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), | |||
3854 | (*FoundP)->getType())) { | |||
3855 | Importer.FromDiag((*P)->getLocation(), | |||
3856 | diag::err_odr_objc_method_param_type_inconsistent) | |||
3857 | << D->isInstanceMethod() << Name | |||
3858 | << (*P)->getType() << (*FoundP)->getType(); | |||
3859 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) | |||
3860 | << (*FoundP)->getType(); | |||
3861 | ||||
3862 | return make_error<ImportError>(ImportError::NameConflict); | |||
3863 | } | |||
3864 | } | |||
3865 | ||||
3866 | // Check variadic/non-variadic. | |||
3867 | // Check the number of parameters. | |||
3868 | if (D->isVariadic() != FoundMethod->isVariadic()) { | |||
3869 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) | |||
3870 | << D->isInstanceMethod() << Name; | |||
3871 | Importer.ToDiag(FoundMethod->getLocation(), | |||
3872 | diag::note_odr_objc_method_here) | |||
3873 | << D->isInstanceMethod() << Name; | |||
3874 | ||||
3875 | return make_error<ImportError>(ImportError::NameConflict); | |||
3876 | } | |||
3877 | ||||
3878 | // FIXME: Any other bits we need to merge? | |||
3879 | return Importer.MapImported(D, FoundMethod); | |||
3880 | } | |||
3881 | } | |||
3882 | ||||
3883 | SourceLocation ToEndLoc; | |||
3884 | QualType ToReturnType; | |||
3885 | TypeSourceInfo *ToReturnTypeSourceInfo; | |||
3886 | if (auto Imp = importSeq( | |||
3887 | D->getEndLoc(), D->getReturnType(), D->getReturnTypeSourceInfo())) | |||
3888 | std::tie(ToEndLoc, ToReturnType, ToReturnTypeSourceInfo) = *Imp; | |||
3889 | else | |||
3890 | return Imp.takeError(); | |||
3891 | ||||
3892 | ObjCMethodDecl *ToMethod; | |||
3893 | if (GetImportedOrCreateDecl( | |||
3894 | ToMethod, D, Importer.getToContext(), Loc, | |||
3895 | ToEndLoc, Name.getObjCSelector(), ToReturnType, | |||
3896 | ToReturnTypeSourceInfo, DC, D->isInstanceMethod(), D->isVariadic(), | |||
3897 | D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), | |||
3898 | D->getImplementationControl(), D->hasRelatedResultType())) | |||
3899 | return ToMethod; | |||
3900 | ||||
3901 | // FIXME: When we decide to merge method definitions, we'll need to | |||
3902 | // deal with implicit parameters. | |||
3903 | ||||
3904 | // Import the parameters | |||
3905 | SmallVector<ParmVarDecl *, 5> ToParams; | |||
3906 | for (auto *FromP : D->parameters()) { | |||
3907 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) | |||
3908 | ToParams.push_back(*ToPOrErr); | |||
3909 | else | |||
3910 | return ToPOrErr.takeError(); | |||
3911 | } | |||
3912 | ||||
3913 | // Set the parameters. | |||
3914 | for (auto *ToParam : ToParams) { | |||
3915 | ToParam->setOwningFunction(ToMethod); | |||
3916 | ToMethod->addDeclInternal(ToParam); | |||
3917 | } | |||
3918 | ||||
3919 | SmallVector<SourceLocation, 12> FromSelLocs; | |||
3920 | D->getSelectorLocs(FromSelLocs); | |||
3921 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); | |||
3922 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) | |||
3923 | return std::move(Err); | |||
3924 | ||||
3925 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); | |||
3926 | ||||
3927 | ToMethod->setLexicalDeclContext(LexicalDC); | |||
3928 | LexicalDC->addDeclInternal(ToMethod); | |||
3929 | return ToMethod; | |||
3930 | } | |||
3931 | ||||
3932 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { | |||
3933 | // Import the major distinguishing characteristics of a category. | |||
3934 | DeclContext *DC, *LexicalDC; | |||
3935 | DeclarationName Name; | |||
3936 | SourceLocation Loc; | |||
3937 | NamedDecl *ToD; | |||
3938 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3939 | return std::move(Err); | |||
3940 | if (ToD) | |||
3941 | return ToD; | |||
3942 | ||||
3943 | SourceLocation ToVarianceLoc, ToLocation, ToColonLoc; | |||
3944 | TypeSourceInfo *ToTypeSourceInfo; | |||
3945 | if (auto Imp = importSeq( | |||
3946 | D->getVarianceLoc(), D->getLocation(), D->getColonLoc(), | |||
3947 | D->getTypeSourceInfo())) | |||
3948 | std::tie(ToVarianceLoc, ToLocation, ToColonLoc, ToTypeSourceInfo) = *Imp; | |||
3949 | else | |||
3950 | return Imp.takeError(); | |||
3951 | ||||
3952 | ObjCTypeParamDecl *Result; | |||
3953 | if (GetImportedOrCreateDecl( | |||
3954 | Result, D, Importer.getToContext(), DC, D->getVariance(), | |||
3955 | ToVarianceLoc, D->getIndex(), | |||
3956 | ToLocation, Name.getAsIdentifierInfo(), | |||
3957 | ToColonLoc, ToTypeSourceInfo)) | |||
3958 | return Result; | |||
3959 | ||||
3960 | Result->setLexicalDeclContext(LexicalDC); | |||
3961 | return Result; | |||
3962 | } | |||
3963 | ||||
3964 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { | |||
3965 | // Import the major distinguishing characteristics of a category. | |||
3966 | DeclContext *DC, *LexicalDC; | |||
3967 | DeclarationName Name; | |||
3968 | SourceLocation Loc; | |||
3969 | NamedDecl *ToD; | |||
3970 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
3971 | return std::move(Err); | |||
3972 | if (ToD) | |||
3973 | return ToD; | |||
3974 | ||||
3975 | ObjCInterfaceDecl *ToInterface; | |||
3976 | if (Error Err = importInto(ToInterface, D->getClassInterface())) | |||
3977 | return std::move(Err); | |||
3978 | ||||
3979 | // Determine if we've already encountered this category. | |||
3980 | ObjCCategoryDecl *MergeWithCategory | |||
3981 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); | |||
3982 | ObjCCategoryDecl *ToCategory = MergeWithCategory; | |||
3983 | if (!ToCategory) { | |||
3984 | SourceLocation ToAtStartLoc, ToCategoryNameLoc; | |||
3985 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; | |||
3986 | if (auto Imp = importSeq( | |||
3987 | D->getAtStartLoc(), D->getCategoryNameLoc(), | |||
3988 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) | |||
3989 | std::tie( | |||
3990 | ToAtStartLoc, ToCategoryNameLoc, | |||
3991 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; | |||
3992 | else | |||
3993 | return Imp.takeError(); | |||
3994 | ||||
3995 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, | |||
3996 | ToAtStartLoc, Loc, | |||
3997 | ToCategoryNameLoc, | |||
3998 | Name.getAsIdentifierInfo(), ToInterface, | |||
3999 | /*TypeParamList=*/nullptr, | |||
4000 | ToIvarLBraceLoc, | |||
4001 | ToIvarRBraceLoc)) | |||
4002 | return ToCategory; | |||
4003 | ||||
4004 | ToCategory->setLexicalDeclContext(LexicalDC); | |||
4005 | LexicalDC->addDeclInternal(ToCategory); | |||
4006 | // Import the type parameter list after MapImported, to avoid | |||
4007 | // loops when bringing in their DeclContext. | |||
4008 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) | |||
4009 | ToCategory->setTypeParamList(*PListOrErr); | |||
4010 | else | |||
4011 | return PListOrErr.takeError(); | |||
4012 | ||||
4013 | // Import protocols | |||
4014 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | |||
4015 | SmallVector<SourceLocation, 4> ProtocolLocs; | |||
4016 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc | |||
4017 | = D->protocol_loc_begin(); | |||
4018 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), | |||
4019 | FromProtoEnd = D->protocol_end(); | |||
4020 | FromProto != FromProtoEnd; | |||
4021 | ++FromProto, ++FromProtoLoc) { | |||
4022 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | |||
4023 | Protocols.push_back(*ToProtoOrErr); | |||
4024 | else | |||
4025 | return ToProtoOrErr.takeError(); | |||
4026 | ||||
4027 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | |||
4028 | ProtocolLocs.push_back(*ToProtoLocOrErr); | |||
4029 | else | |||
4030 | return ToProtoLocOrErr.takeError(); | |||
4031 | } | |||
4032 | ||||
4033 | // FIXME: If we're merging, make sure that the protocol list is the same. | |||
4034 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), | |||
4035 | ProtocolLocs.data(), Importer.getToContext()); | |||
4036 | ||||
4037 | } else { | |||
4038 | Importer.MapImported(D, ToCategory); | |||
4039 | } | |||
4040 | ||||
4041 | // Import all of the members of this category. | |||
4042 | if (Error Err = ImportDeclContext(D)) | |||
4043 | return std::move(Err); | |||
4044 | ||||
4045 | // If we have an implementation, import it as well. | |||
4046 | if (D->getImplementation()) { | |||
4047 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = | |||
4048 | import(D->getImplementation())) | |||
4049 | ToCategory->setImplementation(*ToImplOrErr); | |||
4050 | else | |||
4051 | return ToImplOrErr.takeError(); | |||
4052 | } | |||
4053 | ||||
4054 | return ToCategory; | |||
4055 | } | |||
4056 | ||||
4057 | Error ASTNodeImporter::ImportDefinition( | |||
4058 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { | |||
4059 | if (To->getDefinition()) { | |||
4060 | if (shouldForceImportDeclContext(Kind)) | |||
4061 | if (Error Err = ImportDeclContext(From)) | |||
4062 | return Err; | |||
4063 | return Error::success(); | |||
4064 | } | |||
4065 | ||||
4066 | // Start the protocol definition | |||
4067 | To->startDefinition(); | |||
4068 | ||||
4069 | // Import protocols | |||
4070 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | |||
4071 | SmallVector<SourceLocation, 4> ProtocolLocs; | |||
4072 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = | |||
4073 | From->protocol_loc_begin(); | |||
4074 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), | |||
4075 | FromProtoEnd = From->protocol_end(); | |||
4076 | FromProto != FromProtoEnd; | |||
4077 | ++FromProto, ++FromProtoLoc) { | |||
4078 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | |||
4079 | Protocols.push_back(*ToProtoOrErr); | |||
4080 | else | |||
4081 | return ToProtoOrErr.takeError(); | |||
4082 | ||||
4083 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | |||
4084 | ProtocolLocs.push_back(*ToProtoLocOrErr); | |||
4085 | else | |||
4086 | return ToProtoLocOrErr.takeError(); | |||
4087 | ||||
4088 | } | |||
4089 | ||||
4090 | // FIXME: If we're merging, make sure that the protocol list is the same. | |||
4091 | To->setProtocolList(Protocols.data(), Protocols.size(), | |||
4092 | ProtocolLocs.data(), Importer.getToContext()); | |||
4093 | ||||
4094 | if (shouldForceImportDeclContext(Kind)) { | |||
4095 | // Import all of the members of this protocol. | |||
4096 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | |||
4097 | return Err; | |||
4098 | } | |||
4099 | return Error::success(); | |||
4100 | } | |||
4101 | ||||
4102 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { | |||
4103 | // If this protocol has a definition in the translation unit we're coming | |||
4104 | // from, but this particular declaration is not that definition, import the | |||
4105 | // definition and map to that. | |||
4106 | ObjCProtocolDecl *Definition = D->getDefinition(); | |||
4107 | if (Definition && Definition != D) { | |||
4108 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | |||
4109 | return Importer.MapImported(D, *ImportedDefOrErr); | |||
4110 | else | |||
4111 | return ImportedDefOrErr.takeError(); | |||
4112 | } | |||
4113 | ||||
4114 | // Import the major distinguishing characteristics of a protocol. | |||
4115 | DeclContext *DC, *LexicalDC; | |||
4116 | DeclarationName Name; | |||
4117 | SourceLocation Loc; | |||
4118 | NamedDecl *ToD; | |||
4119 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4120 | return std::move(Err); | |||
4121 | if (ToD) | |||
4122 | return ToD; | |||
4123 | ||||
4124 | ObjCProtocolDecl *MergeWithProtocol = nullptr; | |||
4125 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
4126 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
4127 | for (auto *FoundDecl : FoundDecls) { | |||
4128 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) | |||
4129 | continue; | |||
4130 | ||||
4131 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) | |||
4132 | break; | |||
4133 | } | |||
4134 | ||||
4135 | ObjCProtocolDecl *ToProto = MergeWithProtocol; | |||
4136 | if (!ToProto) { | |||
4137 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); | |||
4138 | if (!ToAtBeginLocOrErr) | |||
4139 | return ToAtBeginLocOrErr.takeError(); | |||
4140 | ||||
4141 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, | |||
4142 | Name.getAsIdentifierInfo(), Loc, | |||
4143 | *ToAtBeginLocOrErr, | |||
4144 | /*PrevDecl=*/nullptr)) | |||
4145 | return ToProto; | |||
4146 | ToProto->setLexicalDeclContext(LexicalDC); | |||
4147 | LexicalDC->addDeclInternal(ToProto); | |||
4148 | } | |||
4149 | ||||
4150 | Importer.MapImported(D, ToProto); | |||
4151 | ||||
4152 | if (D->isThisDeclarationADefinition()) | |||
4153 | if (Error Err = ImportDefinition(D, ToProto)) | |||
4154 | return std::move(Err); | |||
4155 | ||||
4156 | return ToProto; | |||
4157 | } | |||
4158 | ||||
4159 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { | |||
4160 | DeclContext *DC, *LexicalDC; | |||
4161 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
4162 | return std::move(Err); | |||
4163 | ||||
4164 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); | |||
4165 | if (!ExternLocOrErr) | |||
4166 | return ExternLocOrErr.takeError(); | |||
4167 | ||||
4168 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); | |||
4169 | if (!LangLocOrErr) | |||
4170 | return LangLocOrErr.takeError(); | |||
4171 | ||||
4172 | bool HasBraces = D->hasBraces(); | |||
4173 | ||||
4174 | LinkageSpecDecl *ToLinkageSpec; | |||
4175 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, | |||
4176 | *ExternLocOrErr, *LangLocOrErr, | |||
4177 | D->getLanguage(), HasBraces)) | |||
4178 | return ToLinkageSpec; | |||
4179 | ||||
4180 | if (HasBraces) { | |||
4181 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); | |||
4182 | if (!RBraceLocOrErr) | |||
4183 | return RBraceLocOrErr.takeError(); | |||
4184 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); | |||
4185 | } | |||
4186 | ||||
4187 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); | |||
4188 | LexicalDC->addDeclInternal(ToLinkageSpec); | |||
4189 | ||||
4190 | return ToLinkageSpec; | |||
4191 | } | |||
4192 | ||||
4193 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { | |||
4194 | DeclContext *DC, *LexicalDC; | |||
4195 | DeclarationName Name; | |||
4196 | SourceLocation Loc; | |||
4197 | NamedDecl *ToD = nullptr; | |||
4198 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4199 | return std::move(Err); | |||
4200 | if (ToD) | |||
4201 | return ToD; | |||
4202 | ||||
4203 | SourceLocation ToLoc, ToUsingLoc; | |||
4204 | NestedNameSpecifierLoc ToQualifierLoc; | |||
4205 | if (auto Imp = importSeq( | |||
4206 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc())) | |||
4207 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc) = *Imp; | |||
4208 | else | |||
4209 | return Imp.takeError(); | |||
4210 | ||||
4211 | DeclarationNameInfo NameInfo(Name, ToLoc); | |||
4212 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | |||
4213 | return std::move(Err); | |||
4214 | ||||
4215 | UsingDecl *ToUsing; | |||
4216 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, | |||
4217 | ToUsingLoc, ToQualifierLoc, NameInfo, | |||
4218 | D->hasTypename())) | |||
4219 | return ToUsing; | |||
4220 | ||||
4221 | ToUsing->setLexicalDeclContext(LexicalDC); | |||
4222 | LexicalDC->addDeclInternal(ToUsing); | |||
4223 | ||||
4224 | if (NamedDecl *FromPattern = | |||
4225 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { | |||
4226 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) | |||
4227 | Importer.getToContext().setInstantiatedFromUsingDecl( | |||
4228 | ToUsing, *ToPatternOrErr); | |||
4229 | else | |||
4230 | return ToPatternOrErr.takeError(); | |||
4231 | } | |||
4232 | ||||
4233 | for (UsingShadowDecl *FromShadow : D->shadows()) { | |||
4234 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) | |||
4235 | ToUsing->addShadowDecl(*ToShadowOrErr); | |||
4236 | else | |||
4237 | // FIXME: We return error here but the definition is already created | |||
4238 | // and available with lookups. How to fix this?.. | |||
4239 | return ToShadowOrErr.takeError(); | |||
4240 | } | |||
4241 | return ToUsing; | |||
4242 | } | |||
4243 | ||||
4244 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { | |||
4245 | DeclContext *DC, *LexicalDC; | |||
4246 | DeclarationName Name; | |||
4247 | SourceLocation Loc; | |||
4248 | NamedDecl *ToD = nullptr; | |||
4249 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4250 | return std::move(Err); | |||
4251 | if (ToD) | |||
4252 | return ToD; | |||
4253 | ||||
4254 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); | |||
4255 | if (!ToUsingOrErr) | |||
4256 | return ToUsingOrErr.takeError(); | |||
4257 | ||||
4258 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); | |||
4259 | if (!ToTargetOrErr) | |||
4260 | return ToTargetOrErr.takeError(); | |||
4261 | ||||
4262 | UsingShadowDecl *ToShadow; | |||
4263 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, | |||
4264 | *ToUsingOrErr, *ToTargetOrErr)) | |||
4265 | return ToShadow; | |||
4266 | ||||
4267 | ToShadow->setLexicalDeclContext(LexicalDC); | |||
4268 | ToShadow->setAccess(D->getAccess()); | |||
4269 | ||||
4270 | if (UsingShadowDecl *FromPattern = | |||
4271 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { | |||
4272 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) | |||
4273 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( | |||
4274 | ToShadow, *ToPatternOrErr); | |||
4275 | else | |||
4276 | // FIXME: We return error here but the definition is already created | |||
4277 | // and available with lookups. How to fix this?.. | |||
4278 | return ToPatternOrErr.takeError(); | |||
4279 | } | |||
4280 | ||||
4281 | LexicalDC->addDeclInternal(ToShadow); | |||
4282 | ||||
4283 | return ToShadow; | |||
4284 | } | |||
4285 | ||||
4286 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { | |||
4287 | DeclContext *DC, *LexicalDC; | |||
4288 | DeclarationName Name; | |||
4289 | SourceLocation Loc; | |||
4290 | NamedDecl *ToD = nullptr; | |||
4291 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4292 | return std::move(Err); | |||
4293 | if (ToD) | |||
4294 | return ToD; | |||
4295 | ||||
4296 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); | |||
4297 | if (!ToComAncestorOrErr) | |||
4298 | return ToComAncestorOrErr.takeError(); | |||
4299 | ||||
4300 | NamespaceDecl *ToNominatedNamespace; | |||
4301 | SourceLocation ToUsingLoc, ToNamespaceKeyLocation, ToIdentLocation; | |||
4302 | NestedNameSpecifierLoc ToQualifierLoc; | |||
4303 | if (auto Imp = importSeq( | |||
4304 | D->getNominatedNamespace(), D->getUsingLoc(), | |||
4305 | D->getNamespaceKeyLocation(), D->getQualifierLoc(), | |||
4306 | D->getIdentLocation())) | |||
4307 | std::tie( | |||
4308 | ToNominatedNamespace, ToUsingLoc, ToNamespaceKeyLocation, | |||
4309 | ToQualifierLoc, ToIdentLocation) = *Imp; | |||
4310 | else | |||
4311 | return Imp.takeError(); | |||
4312 | ||||
4313 | UsingDirectiveDecl *ToUsingDir; | |||
4314 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, | |||
4315 | ToUsingLoc, | |||
4316 | ToNamespaceKeyLocation, | |||
4317 | ToQualifierLoc, | |||
4318 | ToIdentLocation, | |||
4319 | ToNominatedNamespace, *ToComAncestorOrErr)) | |||
4320 | return ToUsingDir; | |||
4321 | ||||
4322 | ToUsingDir->setLexicalDeclContext(LexicalDC); | |||
4323 | LexicalDC->addDeclInternal(ToUsingDir); | |||
4324 | ||||
4325 | return ToUsingDir; | |||
4326 | } | |||
4327 | ||||
4328 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( | |||
4329 | UnresolvedUsingValueDecl *D) { | |||
4330 | DeclContext *DC, *LexicalDC; | |||
4331 | DeclarationName Name; | |||
4332 | SourceLocation Loc; | |||
4333 | NamedDecl *ToD = nullptr; | |||
4334 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4335 | return std::move(Err); | |||
4336 | if (ToD) | |||
4337 | return ToD; | |||
4338 | ||||
4339 | SourceLocation ToLoc, ToUsingLoc, ToEllipsisLoc; | |||
4340 | NestedNameSpecifierLoc ToQualifierLoc; | |||
4341 | if (auto Imp = importSeq( | |||
4342 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc(), | |||
4343 | D->getEllipsisLoc())) | |||
4344 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; | |||
4345 | else | |||
4346 | return Imp.takeError(); | |||
4347 | ||||
4348 | DeclarationNameInfo NameInfo(Name, ToLoc); | |||
4349 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | |||
4350 | return std::move(Err); | |||
4351 | ||||
4352 | UnresolvedUsingValueDecl *ToUsingValue; | |||
4353 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, | |||
4354 | ToUsingLoc, ToQualifierLoc, NameInfo, | |||
4355 | ToEllipsisLoc)) | |||
4356 | return ToUsingValue; | |||
4357 | ||||
4358 | ToUsingValue->setAccess(D->getAccess()); | |||
4359 | ToUsingValue->setLexicalDeclContext(LexicalDC); | |||
4360 | LexicalDC->addDeclInternal(ToUsingValue); | |||
4361 | ||||
4362 | return ToUsingValue; | |||
4363 | } | |||
4364 | ||||
4365 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( | |||
4366 | UnresolvedUsingTypenameDecl *D) { | |||
4367 | DeclContext *DC, *LexicalDC; | |||
4368 | DeclarationName Name; | |||
4369 | SourceLocation Loc; | |||
4370 | NamedDecl *ToD = nullptr; | |||
4371 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4372 | return std::move(Err); | |||
4373 | if (ToD) | |||
4374 | return ToD; | |||
4375 | ||||
4376 | SourceLocation ToUsingLoc, ToTypenameLoc, ToEllipsisLoc; | |||
4377 | NestedNameSpecifierLoc ToQualifierLoc; | |||
4378 | if (auto Imp = importSeq( | |||
4379 | D->getUsingLoc(), D->getTypenameLoc(), D->getQualifierLoc(), | |||
4380 | D->getEllipsisLoc())) | |||
4381 | std::tie(ToUsingLoc, ToTypenameLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; | |||
4382 | else | |||
4383 | return Imp.takeError(); | |||
4384 | ||||
4385 | UnresolvedUsingTypenameDecl *ToUsing; | |||
4386 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, | |||
4387 | ToUsingLoc, ToTypenameLoc, | |||
4388 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) | |||
4389 | return ToUsing; | |||
4390 | ||||
4391 | ToUsing->setAccess(D->getAccess()); | |||
4392 | ToUsing->setLexicalDeclContext(LexicalDC); | |||
4393 | LexicalDC->addDeclInternal(ToUsing); | |||
4394 | ||||
4395 | return ToUsing; | |||
4396 | } | |||
4397 | ||||
4398 | ||||
4399 | Error ASTNodeImporter::ImportDefinition( | |||
4400 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { | |||
4401 | if (To->getDefinition()) { | |||
4402 | // Check consistency of superclass. | |||
4403 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); | |||
4404 | if (FromSuper) { | |||
4405 | if (auto FromSuperOrErr = import(FromSuper)) | |||
4406 | FromSuper = *FromSuperOrErr; | |||
4407 | else | |||
4408 | return FromSuperOrErr.takeError(); | |||
4409 | } | |||
4410 | ||||
4411 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); | |||
4412 | if ((bool)FromSuper != (bool)ToSuper || | |||
4413 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { | |||
4414 | Importer.ToDiag(To->getLocation(), | |||
4415 | diag::err_odr_objc_superclass_inconsistent) | |||
4416 | << To->getDeclName(); | |||
4417 | if (ToSuper) | |||
4418 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) | |||
4419 | << To->getSuperClass()->getDeclName(); | |||
4420 | else | |||
4421 | Importer.ToDiag(To->getLocation(), | |||
4422 | diag::note_odr_objc_missing_superclass); | |||
4423 | if (From->getSuperClass()) | |||
4424 | Importer.FromDiag(From->getSuperClassLoc(), | |||
4425 | diag::note_odr_objc_superclass) | |||
4426 | << From->getSuperClass()->getDeclName(); | |||
4427 | else | |||
4428 | Importer.FromDiag(From->getLocation(), | |||
4429 | diag::note_odr_objc_missing_superclass); | |||
4430 | } | |||
4431 | ||||
4432 | if (shouldForceImportDeclContext(Kind)) | |||
4433 | if (Error Err = ImportDeclContext(From)) | |||
4434 | return Err; | |||
4435 | return Error::success(); | |||
4436 | } | |||
4437 | ||||
4438 | // Start the definition. | |||
4439 | To->startDefinition(); | |||
4440 | ||||
4441 | // If this class has a superclass, import it. | |||
4442 | if (From->getSuperClass()) { | |||
4443 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) | |||
4444 | To->setSuperClass(*SuperTInfoOrErr); | |||
4445 | else | |||
4446 | return SuperTInfoOrErr.takeError(); | |||
4447 | } | |||
4448 | ||||
4449 | // Import protocols | |||
4450 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | |||
4451 | SmallVector<SourceLocation, 4> ProtocolLocs; | |||
4452 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = | |||
4453 | From->protocol_loc_begin(); | |||
4454 | ||||
4455 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), | |||
4456 | FromProtoEnd = From->protocol_end(); | |||
4457 | FromProto != FromProtoEnd; | |||
4458 | ++FromProto, ++FromProtoLoc) { | |||
4459 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | |||
4460 | Protocols.push_back(*ToProtoOrErr); | |||
4461 | else | |||
4462 | return ToProtoOrErr.takeError(); | |||
4463 | ||||
4464 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | |||
4465 | ProtocolLocs.push_back(*ToProtoLocOrErr); | |||
4466 | else | |||
4467 | return ToProtoLocOrErr.takeError(); | |||
4468 | ||||
4469 | } | |||
4470 | ||||
4471 | // FIXME: If we're merging, make sure that the protocol list is the same. | |||
4472 | To->setProtocolList(Protocols.data(), Protocols.size(), | |||
4473 | ProtocolLocs.data(), Importer.getToContext()); | |||
4474 | ||||
4475 | // Import categories. When the categories themselves are imported, they'll | |||
4476 | // hook themselves into this interface. | |||
4477 | for (auto *Cat : From->known_categories()) { | |||
4478 | auto ToCatOrErr = import(Cat); | |||
4479 | if (!ToCatOrErr) | |||
4480 | return ToCatOrErr.takeError(); | |||
4481 | } | |||
4482 | ||||
4483 | // If we have an @implementation, import it as well. | |||
4484 | if (From->getImplementation()) { | |||
4485 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = | |||
4486 | import(From->getImplementation())) | |||
4487 | To->setImplementation(*ToImplOrErr); | |||
4488 | else | |||
4489 | return ToImplOrErr.takeError(); | |||
4490 | } | |||
4491 | ||||
4492 | if (shouldForceImportDeclContext(Kind)) { | |||
4493 | // Import all of the members of this class. | |||
4494 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | |||
4495 | return Err; | |||
4496 | } | |||
4497 | return Error::success(); | |||
4498 | } | |||
4499 | ||||
4500 | Expected<ObjCTypeParamList *> | |||
4501 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { | |||
4502 | if (!list) | |||
4503 | return nullptr; | |||
4504 | ||||
4505 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; | |||
4506 | for (auto *fromTypeParam : *list) { | |||
4507 | if (auto toTypeParamOrErr = import(fromTypeParam)) | |||
4508 | toTypeParams.push_back(*toTypeParamOrErr); | |||
4509 | else | |||
4510 | return toTypeParamOrErr.takeError(); | |||
4511 | } | |||
4512 | ||||
4513 | auto LAngleLocOrErr = import(list->getLAngleLoc()); | |||
4514 | if (!LAngleLocOrErr) | |||
4515 | return LAngleLocOrErr.takeError(); | |||
4516 | ||||
4517 | auto RAngleLocOrErr = import(list->getRAngleLoc()); | |||
4518 | if (!RAngleLocOrErr) | |||
4519 | return RAngleLocOrErr.takeError(); | |||
4520 | ||||
4521 | return ObjCTypeParamList::create(Importer.getToContext(), | |||
4522 | *LAngleLocOrErr, | |||
4523 | toTypeParams, | |||
4524 | *RAngleLocOrErr); | |||
4525 | } | |||
4526 | ||||
4527 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { | |||
4528 | // If this class has a definition in the translation unit we're coming from, | |||
4529 | // but this particular declaration is not that definition, import the | |||
4530 | // definition and map to that. | |||
4531 | ObjCInterfaceDecl *Definition = D->getDefinition(); | |||
4532 | if (Definition && Definition != D) { | |||
4533 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | |||
4534 | return Importer.MapImported(D, *ImportedDefOrErr); | |||
4535 | else | |||
4536 | return ImportedDefOrErr.takeError(); | |||
4537 | } | |||
4538 | ||||
4539 | // Import the major distinguishing characteristics of an @interface. | |||
4540 | DeclContext *DC, *LexicalDC; | |||
4541 | DeclarationName Name; | |||
4542 | SourceLocation Loc; | |||
4543 | NamedDecl *ToD; | |||
4544 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4545 | return std::move(Err); | |||
4546 | if (ToD) | |||
4547 | return ToD; | |||
4548 | ||||
4549 | // Look for an existing interface with the same name. | |||
4550 | ObjCInterfaceDecl *MergeWithIface = nullptr; | |||
4551 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
4552 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
4553 | for (auto *FoundDecl : FoundDecls) { | |||
4554 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) | |||
4555 | continue; | |||
4556 | ||||
4557 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) | |||
4558 | break; | |||
4559 | } | |||
4560 | ||||
4561 | // Create an interface declaration, if one does not already exist. | |||
4562 | ObjCInterfaceDecl *ToIface = MergeWithIface; | |||
4563 | if (!ToIface) { | |||
4564 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); | |||
4565 | if (!AtBeginLocOrErr) | |||
4566 | return AtBeginLocOrErr.takeError(); | |||
4567 | ||||
4568 | if (GetImportedOrCreateDecl( | |||
4569 | ToIface, D, Importer.getToContext(), DC, | |||
4570 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), | |||
4571 | /*TypeParamList=*/nullptr, | |||
4572 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) | |||
4573 | return ToIface; | |||
4574 | ToIface->setLexicalDeclContext(LexicalDC); | |||
4575 | LexicalDC->addDeclInternal(ToIface); | |||
4576 | } | |||
4577 | Importer.MapImported(D, ToIface); | |||
4578 | // Import the type parameter list after MapImported, to avoid | |||
4579 | // loops when bringing in their DeclContext. | |||
4580 | if (auto ToPListOrErr = | |||
4581 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) | |||
4582 | ToIface->setTypeParamList(*ToPListOrErr); | |||
4583 | else | |||
4584 | return ToPListOrErr.takeError(); | |||
4585 | ||||
4586 | if (D->isThisDeclarationADefinition()) | |||
4587 | if (Error Err = ImportDefinition(D, ToIface)) | |||
4588 | return std::move(Err); | |||
4589 | ||||
4590 | return ToIface; | |||
4591 | } | |||
4592 | ||||
4593 | ExpectedDecl | |||
4594 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { | |||
4595 | ObjCCategoryDecl *Category; | |||
4596 | if (Error Err = importInto(Category, D->getCategoryDecl())) | |||
4597 | return std::move(Err); | |||
4598 | ||||
4599 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); | |||
4600 | if (!ToImpl) { | |||
4601 | DeclContext *DC, *LexicalDC; | |||
4602 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
4603 | return std::move(Err); | |||
4604 | ||||
4605 | SourceLocation ToLocation, ToAtStartLoc, ToCategoryNameLoc; | |||
4606 | if (auto Imp = importSeq( | |||
4607 | D->getLocation(), D->getAtStartLoc(), D->getCategoryNameLoc())) | |||
4608 | std::tie(ToLocation, ToAtStartLoc, ToCategoryNameLoc) = *Imp; | |||
4609 | else | |||
4610 | return Imp.takeError(); | |||
4611 | ||||
4612 | if (GetImportedOrCreateDecl( | |||
4613 | ToImpl, D, Importer.getToContext(), DC, | |||
4614 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), | |||
4615 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) | |||
4616 | return ToImpl; | |||
4617 | ||||
4618 | ToImpl->setLexicalDeclContext(LexicalDC); | |||
4619 | LexicalDC->addDeclInternal(ToImpl); | |||
4620 | Category->setImplementation(ToImpl); | |||
4621 | } | |||
4622 | ||||
4623 | Importer.MapImported(D, ToImpl); | |||
4624 | if (Error Err = ImportDeclContext(D)) | |||
4625 | return std::move(Err); | |||
4626 | ||||
4627 | return ToImpl; | |||
4628 | } | |||
4629 | ||||
4630 | ExpectedDecl | |||
4631 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { | |||
4632 | // Find the corresponding interface. | |||
4633 | ObjCInterfaceDecl *Iface; | |||
4634 | if (Error Err = importInto(Iface, D->getClassInterface())) | |||
4635 | return std::move(Err); | |||
4636 | ||||
4637 | // Import the superclass, if any. | |||
4638 | ObjCInterfaceDecl *Super; | |||
4639 | if (Error Err = importInto(Super, D->getSuperClass())) | |||
4640 | return std::move(Err); | |||
4641 | ||||
4642 | ObjCImplementationDecl *Impl = Iface->getImplementation(); | |||
4643 | if (!Impl) { | |||
4644 | // We haven't imported an implementation yet. Create a new @implementation | |||
4645 | // now. | |||
4646 | DeclContext *DC, *LexicalDC; | |||
4647 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
4648 | return std::move(Err); | |||
4649 | ||||
4650 | SourceLocation ToLocation, ToAtStartLoc, ToSuperClassLoc; | |||
4651 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; | |||
4652 | if (auto Imp = importSeq( | |||
4653 | D->getLocation(), D->getAtStartLoc(), D->getSuperClassLoc(), | |||
4654 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) | |||
4655 | std::tie( | |||
4656 | ToLocation, ToAtStartLoc, ToSuperClassLoc, | |||
4657 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; | |||
4658 | else | |||
4659 | return Imp.takeError(); | |||
4660 | ||||
4661 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), | |||
4662 | DC, Iface, Super, | |||
4663 | ToLocation, | |||
4664 | ToAtStartLoc, | |||
4665 | ToSuperClassLoc, | |||
4666 | ToIvarLBraceLoc, | |||
4667 | ToIvarRBraceLoc)) | |||
4668 | return Impl; | |||
4669 | ||||
4670 | Impl->setLexicalDeclContext(LexicalDC); | |||
4671 | ||||
4672 | // Associate the implementation with the class it implements. | |||
4673 | Iface->setImplementation(Impl); | |||
4674 | Importer.MapImported(D, Iface->getImplementation()); | |||
4675 | } else { | |||
4676 | Importer.MapImported(D, Iface->getImplementation()); | |||
4677 | ||||
4678 | // Verify that the existing @implementation has the same superclass. | |||
4679 | if ((Super && !Impl->getSuperClass()) || | |||
4680 | (!Super && Impl->getSuperClass()) || | |||
4681 | (Super && Impl->getSuperClass() && | |||
4682 | !declaresSameEntity(Super->getCanonicalDecl(), | |||
4683 | Impl->getSuperClass()))) { | |||
4684 | Importer.ToDiag(Impl->getLocation(), | |||
4685 | diag::err_odr_objc_superclass_inconsistent) | |||
4686 | << Iface->getDeclName(); | |||
4687 | // FIXME: It would be nice to have the location of the superclass | |||
4688 | // below. | |||
4689 | if (Impl->getSuperClass()) | |||
4690 | Importer.ToDiag(Impl->getLocation(), | |||
4691 | diag::note_odr_objc_superclass) | |||
4692 | << Impl->getSuperClass()->getDeclName(); | |||
4693 | else | |||
4694 | Importer.ToDiag(Impl->getLocation(), | |||
4695 | diag::note_odr_objc_missing_superclass); | |||
4696 | if (D->getSuperClass()) | |||
4697 | Importer.FromDiag(D->getLocation(), | |||
4698 | diag::note_odr_objc_superclass) | |||
4699 | << D->getSuperClass()->getDeclName(); | |||
4700 | else | |||
4701 | Importer.FromDiag(D->getLocation(), | |||
4702 | diag::note_odr_objc_missing_superclass); | |||
4703 | ||||
4704 | return make_error<ImportError>(ImportError::NameConflict); | |||
4705 | } | |||
4706 | } | |||
4707 | ||||
4708 | // Import all of the members of this @implementation. | |||
4709 | if (Error Err = ImportDeclContext(D)) | |||
4710 | return std::move(Err); | |||
4711 | ||||
4712 | return Impl; | |||
4713 | } | |||
4714 | ||||
4715 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { | |||
4716 | // Import the major distinguishing characteristics of an @property. | |||
4717 | DeclContext *DC, *LexicalDC; | |||
4718 | DeclarationName Name; | |||
4719 | SourceLocation Loc; | |||
4720 | NamedDecl *ToD; | |||
4721 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4722 | return std::move(Err); | |||
4723 | if (ToD) | |||
4724 | return ToD; | |||
4725 | ||||
4726 | // Check whether we have already imported this property. | |||
4727 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
4728 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
4729 | for (auto *FoundDecl : FoundDecls) { | |||
4730 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { | |||
4731 | // Check property types. | |||
4732 | if (!Importer.IsStructurallyEquivalent(D->getType(), | |||
4733 | FoundProp->getType())) { | |||
4734 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) | |||
4735 | << Name << D->getType() << FoundProp->getType(); | |||
4736 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) | |||
4737 | << FoundProp->getType(); | |||
4738 | ||||
4739 | return make_error<ImportError>(ImportError::NameConflict); | |||
4740 | } | |||
4741 | ||||
4742 | // FIXME: Check property attributes, getters, setters, etc.? | |||
4743 | ||||
4744 | // Consider these properties to be equivalent. | |||
4745 | Importer.MapImported(D, FoundProp); | |||
4746 | return FoundProp; | |||
4747 | } | |||
4748 | } | |||
4749 | ||||
4750 | QualType ToType; | |||
4751 | TypeSourceInfo *ToTypeSourceInfo; | |||
4752 | SourceLocation ToAtLoc, ToLParenLoc; | |||
4753 | if (auto Imp = importSeq( | |||
4754 | D->getType(), D->getTypeSourceInfo(), D->getAtLoc(), D->getLParenLoc())) | |||
4755 | std::tie(ToType, ToTypeSourceInfo, ToAtLoc, ToLParenLoc) = *Imp; | |||
4756 | else | |||
4757 | return Imp.takeError(); | |||
4758 | ||||
4759 | // Create the new property. | |||
4760 | ObjCPropertyDecl *ToProperty; | |||
4761 | if (GetImportedOrCreateDecl( | |||
4762 | ToProperty, D, Importer.getToContext(), DC, Loc, | |||
4763 | Name.getAsIdentifierInfo(), ToAtLoc, | |||
4764 | ToLParenLoc, ToType, | |||
4765 | ToTypeSourceInfo, D->getPropertyImplementation())) | |||
4766 | return ToProperty; | |||
4767 | ||||
4768 | Selector ToGetterName, ToSetterName; | |||
4769 | SourceLocation ToGetterNameLoc, ToSetterNameLoc; | |||
4770 | ObjCMethodDecl *ToGetterMethodDecl, *ToSetterMethodDecl; | |||
4771 | ObjCIvarDecl *ToPropertyIvarDecl; | |||
4772 | if (auto Imp = importSeq( | |||
4773 | D->getGetterName(), D->getSetterName(), | |||
4774 | D->getGetterNameLoc(), D->getSetterNameLoc(), | |||
4775 | D->getGetterMethodDecl(), D->getSetterMethodDecl(), | |||
4776 | D->getPropertyIvarDecl())) | |||
4777 | std::tie( | |||
4778 | ToGetterName, ToSetterName, | |||
4779 | ToGetterNameLoc, ToSetterNameLoc, | |||
4780 | ToGetterMethodDecl, ToSetterMethodDecl, | |||
4781 | ToPropertyIvarDecl) = *Imp; | |||
4782 | else | |||
4783 | return Imp.takeError(); | |||
4784 | ||||
4785 | ToProperty->setLexicalDeclContext(LexicalDC); | |||
4786 | LexicalDC->addDeclInternal(ToProperty); | |||
4787 | ||||
4788 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); | |||
4789 | ToProperty->setPropertyAttributesAsWritten( | |||
4790 | D->getPropertyAttributesAsWritten()); | |||
4791 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); | |||
4792 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); | |||
4793 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); | |||
4794 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); | |||
4795 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); | |||
4796 | return ToProperty; | |||
4797 | } | |||
4798 | ||||
4799 | ExpectedDecl | |||
4800 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { | |||
4801 | ObjCPropertyDecl *Property; | |||
4802 | if (Error Err = importInto(Property, D->getPropertyDecl())) | |||
4803 | return std::move(Err); | |||
4804 | ||||
4805 | DeclContext *DC, *LexicalDC; | |||
4806 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
4807 | return std::move(Err); | |||
4808 | ||||
4809 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); | |||
4810 | ||||
4811 | // Import the ivar (for an @synthesize). | |||
4812 | ObjCIvarDecl *Ivar = nullptr; | |||
4813 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) | |||
4814 | return std::move(Err); | |||
4815 | ||||
4816 | ObjCPropertyImplDecl *ToImpl | |||
4817 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), | |||
4818 | Property->getQueryKind()); | |||
4819 | if (!ToImpl) { | |||
4820 | SourceLocation ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc; | |||
4821 | if (auto Imp = importSeq( | |||
4822 | D->getBeginLoc(), D->getLocation(), D->getPropertyIvarDeclLoc())) | |||
4823 | std::tie(ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc) = *Imp; | |||
4824 | else | |||
4825 | return Imp.takeError(); | |||
4826 | ||||
4827 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, | |||
4828 | ToBeginLoc, | |||
4829 | ToLocation, Property, | |||
4830 | D->getPropertyImplementation(), Ivar, | |||
4831 | ToPropertyIvarDeclLoc)) | |||
4832 | return ToImpl; | |||
4833 | ||||
4834 | ToImpl->setLexicalDeclContext(LexicalDC); | |||
4835 | LexicalDC->addDeclInternal(ToImpl); | |||
4836 | } else { | |||
4837 | // Check that we have the same kind of property implementation (@synthesize | |||
4838 | // vs. @dynamic). | |||
4839 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { | |||
4840 | Importer.ToDiag(ToImpl->getLocation(), | |||
4841 | diag::err_odr_objc_property_impl_kind_inconsistent) | |||
4842 | << Property->getDeclName() | |||
4843 | << (ToImpl->getPropertyImplementation() | |||
4844 | == ObjCPropertyImplDecl::Dynamic); | |||
4845 | Importer.FromDiag(D->getLocation(), | |||
4846 | diag::note_odr_objc_property_impl_kind) | |||
4847 | << D->getPropertyDecl()->getDeclName() | |||
4848 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); | |||
4849 | ||||
4850 | return make_error<ImportError>(ImportError::NameConflict); | |||
4851 | } | |||
4852 | ||||
4853 | // For @synthesize, check that we have the same | |||
4854 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && | |||
4855 | Ivar != ToImpl->getPropertyIvarDecl()) { | |||
4856 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), | |||
4857 | diag::err_odr_objc_synthesize_ivar_inconsistent) | |||
4858 | << Property->getDeclName() | |||
4859 | << ToImpl->getPropertyIvarDecl()->getDeclName() | |||
4860 | << Ivar->getDeclName(); | |||
4861 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), | |||
4862 | diag::note_odr_objc_synthesize_ivar_here) | |||
4863 | << D->getPropertyIvarDecl()->getDeclName(); | |||
4864 | ||||
4865 | return make_error<ImportError>(ImportError::NameConflict); | |||
4866 | } | |||
4867 | ||||
4868 | // Merge the existing implementation with the new implementation. | |||
4869 | Importer.MapImported(D, ToImpl); | |||
4870 | } | |||
4871 | ||||
4872 | return ToImpl; | |||
4873 | } | |||
4874 | ||||
4875 | ExpectedDecl | |||
4876 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { | |||
4877 | // For template arguments, we adopt the translation unit as our declaration | |||
4878 | // context. This context will be fixed when the actual template declaration | |||
4879 | // is created. | |||
4880 | ||||
4881 | // FIXME: Import default argument. | |||
4882 | ||||
4883 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | |||
4884 | if (!BeginLocOrErr) | |||
4885 | return BeginLocOrErr.takeError(); | |||
4886 | ||||
4887 | ExpectedSLoc LocationOrErr = import(D->getLocation()); | |||
4888 | if (!LocationOrErr) | |||
4889 | return LocationOrErr.takeError(); | |||
4890 | ||||
4891 | TemplateTypeParmDecl *ToD = nullptr; | |||
4892 | (void)GetImportedOrCreateDecl( | |||
4893 | ToD, D, Importer.getToContext(), | |||
4894 | Importer.getToContext().getTranslationUnitDecl(), | |||
4895 | *BeginLocOrErr, *LocationOrErr, | |||
4896 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), | |||
4897 | D->wasDeclaredWithTypename(), D->isParameterPack()); | |||
4898 | return ToD; | |||
4899 | } | |||
4900 | ||||
4901 | ExpectedDecl | |||
4902 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { | |||
4903 | DeclarationName ToDeclName; | |||
4904 | SourceLocation ToLocation, ToInnerLocStart; | |||
4905 | QualType ToType; | |||
4906 | TypeSourceInfo *ToTypeSourceInfo; | |||
4907 | if (auto Imp = importSeq( | |||
4908 | D->getDeclName(), D->getLocation(), D->getType(), D->getTypeSourceInfo(), | |||
4909 | D->getInnerLocStart())) | |||
4910 | std::tie( | |||
4911 | ToDeclName, ToLocation, ToType, ToTypeSourceInfo, | |||
4912 | ToInnerLocStart) = *Imp; | |||
4913 | else | |||
4914 | return Imp.takeError(); | |||
4915 | ||||
4916 | // FIXME: Import default argument. | |||
4917 | ||||
4918 | NonTypeTemplateParmDecl *ToD = nullptr; | |||
4919 | (void)GetImportedOrCreateDecl( | |||
4920 | ToD, D, Importer.getToContext(), | |||
4921 | Importer.getToContext().getTranslationUnitDecl(), | |||
4922 | ToInnerLocStart, ToLocation, D->getDepth(), | |||
4923 | D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType, | |||
4924 | D->isParameterPack(), ToTypeSourceInfo); | |||
4925 | return ToD; | |||
4926 | } | |||
4927 | ||||
4928 | ExpectedDecl | |||
4929 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { | |||
4930 | // Import the name of this declaration. | |||
4931 | auto NameOrErr = import(D->getDeclName()); | |||
4932 | if (!NameOrErr) | |||
4933 | return NameOrErr.takeError(); | |||
4934 | ||||
4935 | // Import the location of this declaration. | |||
4936 | ExpectedSLoc LocationOrErr = import(D->getLocation()); | |||
4937 | if (!LocationOrErr) | |||
4938 | return LocationOrErr.takeError(); | |||
4939 | ||||
4940 | // Import template parameters. | |||
4941 | auto TemplateParamsOrErr = ImportTemplateParameterList( | |||
4942 | D->getTemplateParameters()); | |||
4943 | if (!TemplateParamsOrErr) | |||
4944 | return TemplateParamsOrErr.takeError(); | |||
4945 | ||||
4946 | // FIXME: Import default argument. | |||
4947 | ||||
4948 | TemplateTemplateParmDecl *ToD = nullptr; | |||
4949 | (void)GetImportedOrCreateDecl( | |||
4950 | ToD, D, Importer.getToContext(), | |||
4951 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, | |||
4952 | D->getDepth(), D->getPosition(), D->isParameterPack(), | |||
4953 | (*NameOrErr).getAsIdentifierInfo(), | |||
4954 | *TemplateParamsOrErr); | |||
4955 | return ToD; | |||
4956 | } | |||
4957 | ||||
4958 | // Returns the definition for a (forward) declaration of a ClassTemplateDecl, if | |||
4959 | // it has any definition in the redecl chain. | |||
4960 | static ClassTemplateDecl *getDefinition(ClassTemplateDecl *D) { | |||
4961 | CXXRecordDecl *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); | |||
4962 | if (!ToTemplatedDef) | |||
4963 | return nullptr; | |||
4964 | ClassTemplateDecl *TemplateWithDef = | |||
4965 | ToTemplatedDef->getDescribedClassTemplate(); | |||
4966 | return TemplateWithDef; | |||
4967 | } | |||
4968 | ||||
4969 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { | |||
4970 | bool IsFriend = D->getFriendObjectKind() != Decl::FOK_None; | |||
4971 | ||||
4972 | // If this record has a definition in the translation unit we're coming from, | |||
4973 | // but this particular declaration is not that definition, import the | |||
4974 | // definition and map to that. | |||
4975 | auto *Definition = | |||
4976 | cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition()); | |||
4977 | if (Definition && Definition != D->getTemplatedDecl() && !IsFriend) { | |||
4978 | if (ExpectedDecl ImportedDefOrErr = import( | |||
4979 | Definition->getDescribedClassTemplate())) | |||
4980 | return Importer.MapImported(D, *ImportedDefOrErr); | |||
4981 | else | |||
4982 | return ImportedDefOrErr.takeError(); | |||
4983 | } | |||
4984 | ||||
4985 | // Import the major distinguishing characteristics of this class template. | |||
4986 | DeclContext *DC, *LexicalDC; | |||
4987 | DeclarationName Name; | |||
4988 | SourceLocation Loc; | |||
4989 | NamedDecl *ToD; | |||
4990 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
4991 | return std::move(Err); | |||
4992 | if (ToD) | |||
4993 | return ToD; | |||
4994 | ||||
4995 | // We may already have a template of the same name; try to find and match it. | |||
4996 | if (!DC->isFunctionOrMethod()) { | |||
4997 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
4998 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
4999 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
5000 | for (auto *FoundDecl : FoundDecls) { | |||
5001 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) | |||
5002 | continue; | |||
5003 | ||||
5004 | Decl *Found = FoundDecl; | |||
5005 | if (auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found)) { | |||
5006 | ||||
5007 | // The class to be imported is a definition. | |||
5008 | if (D->isThisDeclarationADefinition()) { | |||
5009 | // Lookup will find the fwd decl only if that is more recent than the | |||
5010 | // definition. So, try to get the definition if that is available in | |||
5011 | // the redecl chain. | |||
5012 | ClassTemplateDecl *TemplateWithDef = getDefinition(FoundTemplate); | |||
5013 | if (TemplateWithDef) | |||
5014 | FoundTemplate = TemplateWithDef; | |||
5015 | else | |||
5016 | continue; | |||
5017 | } | |||
5018 | ||||
5019 | if (IsStructuralMatch(D, FoundTemplate)) { | |||
5020 | if (!IsFriend) { | |||
5021 | Importer.MapImported(D->getTemplatedDecl(), | |||
5022 | FoundTemplate->getTemplatedDecl()); | |||
5023 | return Importer.MapImported(D, FoundTemplate); | |||
5024 | } | |||
5025 | ||||
5026 | continue; | |||
5027 | } | |||
5028 | } | |||
5029 | ||||
5030 | ConflictingDecls.push_back(FoundDecl); | |||
5031 | } | |||
5032 | ||||
5033 | if (!ConflictingDecls.empty()) { | |||
5034 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, | |||
5035 | ConflictingDecls.data(), | |||
5036 | ConflictingDecls.size()); | |||
5037 | } | |||
5038 | ||||
5039 | if (!Name) | |||
5040 | return make_error<ImportError>(ImportError::NameConflict); | |||
5041 | } | |||
5042 | ||||
5043 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); | |||
5044 | ||||
5045 | // Create the declaration that is being templated. | |||
5046 | CXXRecordDecl *ToTemplated; | |||
5047 | if (Error Err = importInto(ToTemplated, FromTemplated)) | |||
5048 | return std::move(Err); | |||
5049 | ||||
5050 | // Create the class template declaration itself. | |||
5051 | auto TemplateParamsOrErr = ImportTemplateParameterList( | |||
5052 | D->getTemplateParameters()); | |||
5053 | if (!TemplateParamsOrErr) | |||
5054 | return TemplateParamsOrErr.takeError(); | |||
5055 | ||||
5056 | ClassTemplateDecl *D2; | |||
5057 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, | |||
5058 | *TemplateParamsOrErr, ToTemplated)) | |||
5059 | return D2; | |||
5060 | ||||
5061 | ToTemplated->setDescribedClassTemplate(D2); | |||
5062 | ||||
5063 | if (ToTemplated->getPreviousDecl()) { | |||
5064 | assert(((ToTemplated->getPreviousDecl()->getDescribedClassTemplate () && "Missing described template") ? static_cast< void> (0) : __assert_fail ("ToTemplated->getPreviousDecl()->getDescribedClassTemplate() && \"Missing described template\"" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 5066, __PRETTY_FUNCTION__)) | |||
5065 | ToTemplated->getPreviousDecl()->getDescribedClassTemplate() &&((ToTemplated->getPreviousDecl()->getDescribedClassTemplate () && "Missing described template") ? static_cast< void> (0) : __assert_fail ("ToTemplated->getPreviousDecl()->getDescribedClassTemplate() && \"Missing described template\"" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 5066, __PRETTY_FUNCTION__)) | |||
5066 | "Missing described template")((ToTemplated->getPreviousDecl()->getDescribedClassTemplate () && "Missing described template") ? static_cast< void> (0) : __assert_fail ("ToTemplated->getPreviousDecl()->getDescribedClassTemplate() && \"Missing described template\"" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 5066, __PRETTY_FUNCTION__)); | |||
5067 | D2->setPreviousDecl( | |||
5068 | ToTemplated->getPreviousDecl()->getDescribedClassTemplate()); | |||
5069 | } | |||
5070 | D2->setAccess(D->getAccess()); | |||
5071 | D2->setLexicalDeclContext(LexicalDC); | |||
5072 | if (!IsFriend) | |||
5073 | LexicalDC->addDeclInternal(D2); | |||
5074 | ||||
5075 | if (FromTemplated->isCompleteDefinition() && | |||
5076 | !ToTemplated->isCompleteDefinition()) { | |||
5077 | // FIXME: Import definition! | |||
5078 | } | |||
5079 | ||||
5080 | return D2; | |||
5081 | } | |||
5082 | ||||
5083 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( | |||
5084 | ClassTemplateSpecializationDecl *D) { | |||
5085 | // If this record has a definition in the translation unit we're coming from, | |||
5086 | // but this particular declaration is not that definition, import the | |||
5087 | // definition and map to that. | |||
5088 | TagDecl *Definition = D->getDefinition(); | |||
5089 | if (Definition && Definition != D) { | |||
5090 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | |||
5091 | return Importer.MapImported(D, *ImportedDefOrErr); | |||
5092 | else | |||
5093 | return ImportedDefOrErr.takeError(); | |||
5094 | } | |||
5095 | ||||
5096 | ClassTemplateDecl *ClassTemplate; | |||
5097 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) | |||
5098 | return std::move(Err); | |||
5099 | ||||
5100 | // Import the context of this declaration. | |||
5101 | DeclContext *DC, *LexicalDC; | |||
5102 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
5103 | return std::move(Err); | |||
5104 | ||||
5105 | // Import template arguments. | |||
5106 | SmallVector<TemplateArgument, 2> TemplateArgs; | |||
5107 | if (Error Err = ImportTemplateArguments( | |||
5108 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) | |||
5109 | return std::move(Err); | |||
5110 | ||||
5111 | // Try to find an existing specialization with these template arguments. | |||
5112 | void *InsertPos = nullptr; | |||
5113 | ClassTemplateSpecializationDecl *D2 = nullptr; | |||
5114 | ClassTemplatePartialSpecializationDecl *PartialSpec = | |||
5115 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); | |||
5116 | if (PartialSpec) | |||
5117 | D2 = ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos); | |||
5118 | else | |||
5119 | D2 = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); | |||
5120 | ClassTemplateSpecializationDecl * const PrevDecl = D2; | |||
5121 | RecordDecl *FoundDef = D2 ? D2->getDefinition() : nullptr; | |||
5122 | if (FoundDef) { | |||
5123 | if (!D->isCompleteDefinition()) { | |||
5124 | // The "From" translation unit only had a forward declaration; call it | |||
5125 | // the same declaration. | |||
5126 | // TODO Handle the redecl chain properly! | |||
5127 | return Importer.MapImported(D, FoundDef); | |||
5128 | } | |||
5129 | ||||
5130 | if (IsStructuralMatch(D, FoundDef)) { | |||
5131 | ||||
5132 | Importer.MapImported(D, FoundDef); | |||
5133 | ||||
5134 | // Import those those default field initializers which have been | |||
5135 | // instantiated in the "From" context, but not in the "To" context. | |||
5136 | for (auto *FromField : D->fields()) { | |||
5137 | auto ToOrErr = import(FromField); | |||
5138 | if (!ToOrErr) | |||
5139 | // FIXME: return the error? | |||
5140 | consumeError(ToOrErr.takeError()); | |||
5141 | } | |||
5142 | ||||
5143 | // Import those methods which have been instantiated in the | |||
5144 | // "From" context, but not in the "To" context. | |||
5145 | for (CXXMethodDecl *FromM : D->methods()) { | |||
5146 | auto ToOrErr = import(FromM); | |||
5147 | if (!ToOrErr) | |||
5148 | // FIXME: return the error? | |||
5149 | consumeError(ToOrErr.takeError()); | |||
5150 | } | |||
5151 | ||||
5152 | // TODO Import instantiated default arguments. | |||
5153 | // TODO Import instantiated exception specifications. | |||
5154 | // | |||
5155 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint what | |||
5156 | // else could be fused during an AST merge. | |||
5157 | ||||
5158 | return FoundDef; | |||
5159 | } | |||
5160 | } else { // We either couldn't find any previous specialization in the "To" | |||
5161 | // context, or we found one but without definition. Let's create a | |||
5162 | // new specialization and register that at the class template. | |||
5163 | ||||
5164 | // Import the location of this declaration. | |||
5165 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | |||
5166 | if (!BeginLocOrErr) | |||
5167 | return BeginLocOrErr.takeError(); | |||
5168 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); | |||
5169 | if (!IdLocOrErr) | |||
5170 | return IdLocOrErr.takeError(); | |||
5171 | ||||
5172 | if (PartialSpec) { | |||
5173 | // Import TemplateArgumentListInfo. | |||
5174 | TemplateArgumentListInfo ToTAInfo; | |||
5175 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); | |||
5176 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) | |||
5177 | return std::move(Err); | |||
5178 | ||||
5179 | QualType CanonInjType; | |||
5180 | if (Error Err = importInto( | |||
5181 | CanonInjType, PartialSpec->getInjectedSpecializationType())) | |||
5182 | return std::move(Err); | |||
5183 | CanonInjType = CanonInjType.getCanonicalType(); | |||
5184 | ||||
5185 | auto ToTPListOrErr = ImportTemplateParameterList( | |||
5186 | PartialSpec->getTemplateParameters()); | |||
5187 | if (!ToTPListOrErr) | |||
5188 | return ToTPListOrErr.takeError(); | |||
5189 | ||||
5190 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( | |||
5191 | D2, D, Importer.getToContext(), D->getTagKind(), DC, | |||
5192 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, ClassTemplate, | |||
5193 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), | |||
5194 | ToTAInfo, CanonInjType, | |||
5195 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) | |||
5196 | return D2; | |||
5197 | ||||
5198 | // Update InsertPos, because preceding import calls may have invalidated | |||
5199 | // it by adding new specializations. | |||
5200 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos)) | |||
5201 | // Add this partial specialization to the class template. | |||
5202 | ClassTemplate->AddPartialSpecialization( | |||
5203 | cast<ClassTemplatePartialSpecializationDecl>(D2), InsertPos); | |||
5204 | ||||
5205 | } else { // Not a partial specialization. | |||
5206 | if (GetImportedOrCreateDecl( | |||
5207 | D2, D, Importer.getToContext(), D->getTagKind(), DC, | |||
5208 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, | |||
5209 | PrevDecl)) | |||
5210 | return D2; | |||
5211 | ||||
5212 | // Update InsertPos, because preceding import calls may have invalidated | |||
5213 | // it by adding new specializations. | |||
5214 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) | |||
5215 | // Add this specialization to the class template. | |||
5216 | ClassTemplate->AddSpecialization(D2, InsertPos); | |||
5217 | } | |||
5218 | ||||
5219 | D2->setSpecializationKind(D->getSpecializationKind()); | |||
5220 | ||||
5221 | // Import the qualifier, if any. | |||
5222 | if (auto LocOrErr = import(D->getQualifierLoc())) | |||
5223 | D2->setQualifierInfo(*LocOrErr); | |||
5224 | else | |||
5225 | return LocOrErr.takeError(); | |||
5226 | ||||
5227 | if (auto *TSI = D->getTypeAsWritten()) { | |||
5228 | if (auto TInfoOrErr = import(TSI)) | |||
5229 | D2->setTypeAsWritten(*TInfoOrErr); | |||
5230 | else | |||
5231 | return TInfoOrErr.takeError(); | |||
5232 | ||||
5233 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) | |||
5234 | D2->setTemplateKeywordLoc(*LocOrErr); | |||
5235 | else | |||
5236 | return LocOrErr.takeError(); | |||
5237 | ||||
5238 | if (auto LocOrErr = import(D->getExternLoc())) | |||
5239 | D2->setExternLoc(*LocOrErr); | |||
5240 | else | |||
5241 | return LocOrErr.takeError(); | |||
5242 | } | |||
5243 | ||||
5244 | if (D->getPointOfInstantiation().isValid()) { | |||
5245 | if (auto POIOrErr = import(D->getPointOfInstantiation())) | |||
5246 | D2->setPointOfInstantiation(*POIOrErr); | |||
5247 | else | |||
5248 | return POIOrErr.takeError(); | |||
5249 | } | |||
5250 | ||||
5251 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); | |||
5252 | ||||
5253 | // Set the context of this specialization/instantiation. | |||
5254 | D2->setLexicalDeclContext(LexicalDC); | |||
5255 | ||||
5256 | // Add to the DC only if it was an explicit specialization/instantiation. | |||
5257 | if (D2->isExplicitInstantiationOrSpecialization()) { | |||
5258 | LexicalDC->addDeclInternal(D2); | |||
5259 | } | |||
5260 | } | |||
5261 | if (D->isCompleteDefinition()) | |||
5262 | if (Error Err = ImportDefinition(D, D2)) | |||
5263 | return std::move(Err); | |||
5264 | ||||
5265 | return D2; | |||
5266 | } | |||
5267 | ||||
5268 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { | |||
5269 | // If this variable has a definition in the translation unit we're coming | |||
5270 | // from, | |||
5271 | // but this particular declaration is not that definition, import the | |||
5272 | // definition and map to that. | |||
5273 | auto *Definition = | |||
5274 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); | |||
5275 | if (Definition && Definition != D->getTemplatedDecl()) { | |||
5276 | if (ExpectedDecl ImportedDefOrErr = import( | |||
5277 | Definition->getDescribedVarTemplate())) | |||
5278 | return Importer.MapImported(D, *ImportedDefOrErr); | |||
5279 | else | |||
5280 | return ImportedDefOrErr.takeError(); | |||
5281 | } | |||
5282 | ||||
5283 | // Import the major distinguishing characteristics of this variable template. | |||
5284 | DeclContext *DC, *LexicalDC; | |||
5285 | DeclarationName Name; | |||
5286 | SourceLocation Loc; | |||
5287 | NamedDecl *ToD; | |||
5288 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
5289 | return std::move(Err); | |||
5290 | if (ToD) | |||
5291 | return ToD; | |||
5292 | ||||
5293 | // We may already have a template of the same name; try to find and match it. | |||
5294 | assert(!DC->isFunctionOrMethod() &&((!DC->isFunctionOrMethod() && "Variable templates cannot be declared at function scope" ) ? static_cast<void> (0) : __assert_fail ("!DC->isFunctionOrMethod() && \"Variable templates cannot be declared at function scope\"" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 5295, __PRETTY_FUNCTION__)) | |||
5295 | "Variable templates cannot be declared at function scope")((!DC->isFunctionOrMethod() && "Variable templates cannot be declared at function scope" ) ? static_cast<void> (0) : __assert_fail ("!DC->isFunctionOrMethod() && \"Variable templates cannot be declared at function scope\"" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 5295, __PRETTY_FUNCTION__)); | |||
5296 | SmallVector<NamedDecl *, 4> ConflictingDecls; | |||
5297 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
5298 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
5299 | for (auto *FoundDecl : FoundDecls) { | |||
5300 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) | |||
5301 | continue; | |||
5302 | ||||
5303 | Decl *Found = FoundDecl; | |||
5304 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { | |||
5305 | if (IsStructuralMatch(D, FoundTemplate)) { | |||
5306 | // The variable templates structurally match; call it the same template. | |||
5307 | Importer.MapImported(D->getTemplatedDecl(), | |||
5308 | FoundTemplate->getTemplatedDecl()); | |||
5309 | return Importer.MapImported(D, FoundTemplate); | |||
5310 | } | |||
5311 | } | |||
5312 | ||||
5313 | ConflictingDecls.push_back(FoundDecl); | |||
5314 | } | |||
5315 | ||||
5316 | if (!ConflictingDecls.empty()) { | |||
5317 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, | |||
5318 | ConflictingDecls.data(), | |||
5319 | ConflictingDecls.size()); | |||
5320 | } | |||
5321 | ||||
5322 | if (!Name) | |||
5323 | // FIXME: Is it possible to get other error than name conflict? | |||
5324 | // (Put this `if` into the previous `if`?) | |||
5325 | return make_error<ImportError>(ImportError::NameConflict); | |||
5326 | ||||
5327 | VarDecl *DTemplated = D->getTemplatedDecl(); | |||
5328 | ||||
5329 | // Import the type. | |||
5330 | // FIXME: Value not used? | |||
5331 | ExpectedType TypeOrErr = import(DTemplated->getType()); | |||
5332 | if (!TypeOrErr) | |||
5333 | return TypeOrErr.takeError(); | |||
5334 | ||||
5335 | // Create the declaration that is being templated. | |||
5336 | VarDecl *ToTemplated; | |||
5337 | if (Error Err = importInto(ToTemplated, DTemplated)) | |||
5338 | return std::move(Err); | |||
5339 | ||||
5340 | // Create the variable template declaration itself. | |||
5341 | auto TemplateParamsOrErr = ImportTemplateParameterList( | |||
5342 | D->getTemplateParameters()); | |||
5343 | if (!TemplateParamsOrErr) | |||
5344 | return TemplateParamsOrErr.takeError(); | |||
5345 | ||||
5346 | VarTemplateDecl *ToVarTD; | |||
5347 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, | |||
5348 | Name, *TemplateParamsOrErr, ToTemplated)) | |||
5349 | return ToVarTD; | |||
5350 | ||||
5351 | ToTemplated->setDescribedVarTemplate(ToVarTD); | |||
5352 | ||||
5353 | ToVarTD->setAccess(D->getAccess()); | |||
5354 | ToVarTD->setLexicalDeclContext(LexicalDC); | |||
5355 | LexicalDC->addDeclInternal(ToVarTD); | |||
5356 | ||||
5357 | if (DTemplated->isThisDeclarationADefinition() && | |||
5358 | !ToTemplated->isThisDeclarationADefinition()) { | |||
5359 | // FIXME: Import definition! | |||
5360 | } | |||
5361 | ||||
5362 | return ToVarTD; | |||
5363 | } | |||
5364 | ||||
5365 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( | |||
5366 | VarTemplateSpecializationDecl *D) { | |||
5367 | // If this record has a definition in the translation unit we're coming from, | |||
5368 | // but this particular declaration is not that definition, import the | |||
5369 | // definition and map to that. | |||
5370 | VarDecl *Definition = D->getDefinition(); | |||
5371 | if (Definition && Definition != D) { | |||
5372 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | |||
5373 | return Importer.MapImported(D, *ImportedDefOrErr); | |||
5374 | else | |||
5375 | return ImportedDefOrErr.takeError(); | |||
5376 | } | |||
5377 | ||||
5378 | VarTemplateDecl *VarTemplate; | |||
5379 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) | |||
5380 | return std::move(Err); | |||
5381 | ||||
5382 | // Import the context of this declaration. | |||
5383 | DeclContext *DC, *LexicalDC; | |||
5384 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | |||
5385 | return std::move(Err); | |||
5386 | ||||
5387 | // Import the location of this declaration. | |||
5388 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | |||
5389 | if (!BeginLocOrErr) | |||
5390 | return BeginLocOrErr.takeError(); | |||
5391 | ||||
5392 | auto IdLocOrErr = import(D->getLocation()); | |||
5393 | if (!IdLocOrErr) | |||
5394 | return IdLocOrErr.takeError(); | |||
5395 | ||||
5396 | // Import template arguments. | |||
5397 | SmallVector<TemplateArgument, 2> TemplateArgs; | |||
5398 | if (Error Err = ImportTemplateArguments( | |||
5399 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) | |||
5400 | return std::move(Err); | |||
5401 | ||||
5402 | // Try to find an existing specialization with these template arguments. | |||
5403 | void *InsertPos = nullptr; | |||
5404 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( | |||
5405 | TemplateArgs, InsertPos); | |||
5406 | if (D2) { | |||
5407 | // We already have a variable template specialization with these template | |||
5408 | // arguments. | |||
5409 | ||||
5410 | // FIXME: Check for specialization vs. instantiation errors. | |||
5411 | ||||
5412 | if (VarDecl *FoundDef = D2->getDefinition()) { | |||
5413 | if (!D->isThisDeclarationADefinition() || | |||
5414 | IsStructuralMatch(D, FoundDef)) { | |||
5415 | // The record types structurally match, or the "from" translation | |||
5416 | // unit only had a forward declaration anyway; call it the same | |||
5417 | // variable. | |||
5418 | return Importer.MapImported(D, FoundDef); | |||
5419 | } | |||
5420 | } | |||
5421 | } else { | |||
5422 | // Import the type. | |||
5423 | QualType T; | |||
5424 | if (Error Err = importInto(T, D->getType())) | |||
5425 | return std::move(Err); | |||
5426 | ||||
5427 | auto TInfoOrErr = import(D->getTypeSourceInfo()); | |||
5428 | if (!TInfoOrErr) | |||
5429 | return TInfoOrErr.takeError(); | |||
5430 | ||||
5431 | TemplateArgumentListInfo ToTAInfo; | |||
5432 | if (Error Err = ImportTemplateArgumentListInfo( | |||
5433 | D->getTemplateArgsInfo(), ToTAInfo)) | |||
5434 | return std::move(Err); | |||
5435 | ||||
5436 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; | |||
5437 | // Create a new specialization. | |||
5438 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { | |||
5439 | // Import TemplateArgumentListInfo | |||
5440 | TemplateArgumentListInfo ArgInfos; | |||
5441 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); | |||
5442 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. | |||
5443 | if (Error Err = ImportTemplateArgumentListInfo( | |||
5444 | *FromTAArgsAsWritten, ArgInfos)) | |||
5445 | return std::move(Err); | |||
5446 | ||||
5447 | auto ToTPListOrErr = ImportTemplateParameterList( | |||
5448 | FromPartial->getTemplateParameters()); | |||
5449 | if (!ToTPListOrErr) | |||
5450 | return ToTPListOrErr.takeError(); | |||
5451 | ||||
5452 | PartVarSpecDecl *ToPartial; | |||
5453 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, | |||
5454 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, | |||
5455 | VarTemplate, T, *TInfoOrErr, | |||
5456 | D->getStorageClass(), TemplateArgs, ArgInfos)) | |||
5457 | return ToPartial; | |||
5458 | ||||
5459 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( | |||
5460 | FromPartial->getInstantiatedFromMember())) | |||
5461 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); | |||
5462 | else | |||
5463 | return ToInstOrErr.takeError(); | |||
5464 | ||||
5465 | if (FromPartial->isMemberSpecialization()) | |||
5466 | ToPartial->setMemberSpecialization(); | |||
5467 | ||||
5468 | D2 = ToPartial; | |||
5469 | ||||
5470 | } else { // Full specialization | |||
5471 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, | |||
5472 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, | |||
5473 | T, *TInfoOrErr, | |||
5474 | D->getStorageClass(), TemplateArgs)) | |||
5475 | return D2; | |||
5476 | } | |||
5477 | ||||
5478 | if (D->getPointOfInstantiation().isValid()) { | |||
5479 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) | |||
5480 | D2->setPointOfInstantiation(*POIOrErr); | |||
5481 | else | |||
5482 | return POIOrErr.takeError(); | |||
5483 | } | |||
5484 | ||||
5485 | D2->setSpecializationKind(D->getSpecializationKind()); | |||
5486 | D2->setTemplateArgsInfo(ToTAInfo); | |||
5487 | ||||
5488 | // Add this specialization to the class template. | |||
5489 | VarTemplate->AddSpecialization(D2, InsertPos); | |||
5490 | ||||
5491 | // Import the qualifier, if any. | |||
5492 | if (auto LocOrErr = import(D->getQualifierLoc())) | |||
5493 | D2->setQualifierInfo(*LocOrErr); | |||
5494 | else | |||
5495 | return LocOrErr.takeError(); | |||
5496 | ||||
5497 | if (D->isConstexpr()) | |||
5498 | D2->setConstexpr(true); | |||
5499 | ||||
5500 | // Add the specialization to this context. | |||
5501 | D2->setLexicalDeclContext(LexicalDC); | |||
5502 | LexicalDC->addDeclInternal(D2); | |||
5503 | ||||
5504 | D2->setAccess(D->getAccess()); | |||
5505 | } | |||
5506 | ||||
5507 | if (Error Err = ImportInitializer(D, D2)) | |||
5508 | return std::move(Err); | |||
5509 | ||||
5510 | return D2; | |||
5511 | } | |||
5512 | ||||
5513 | ExpectedDecl | |||
5514 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { | |||
5515 | DeclContext *DC, *LexicalDC; | |||
5516 | DeclarationName Name; | |||
5517 | SourceLocation Loc; | |||
5518 | NamedDecl *ToD; | |||
5519 | ||||
5520 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | |||
5521 | return std::move(Err); | |||
5522 | ||||
5523 | if (ToD) | |||
5524 | return ToD; | |||
5525 | ||||
5526 | // Try to find a function in our own ("to") context with the same name, same | |||
5527 | // type, and in the same context as the function we're importing. | |||
5528 | if (!LexicalDC->isFunctionOrMethod()) { | |||
5529 | unsigned IDNS = Decl::IDNS_Ordinary; | |||
5530 | SmallVector<NamedDecl *, 2> FoundDecls; | |||
5531 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); | |||
5532 | for (auto *FoundDecl : FoundDecls) { | |||
5533 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | |||
5534 | continue; | |||
5535 | ||||
5536 | if (auto *FoundFunction = | |||
5537 | dyn_cast<FunctionTemplateDecl>(FoundDecl)) { | |||
5538 | if (FoundFunction->hasExternalFormalLinkage() && | |||
5539 | D->hasExternalFormalLinkage()) { | |||
5540 | if (IsStructuralMatch(D, FoundFunction)) { | |||
5541 | Importer.MapImported(D, FoundFunction); | |||
5542 | // FIXME: Actually try to merge the body and other attributes. | |||
5543 | return FoundFunction; | |||
5544 | } | |||
5545 | } | |||
5546 | } | |||
5547 | // TODO: handle conflicting names | |||
5548 | } | |||
5549 | } | |||
5550 | ||||
5551 | auto ParamsOrErr = ImportTemplateParameterList( | |||
5552 | D->getTemplateParameters()); | |||
5553 | if (!ParamsOrErr) | |||
5554 | return ParamsOrErr.takeError(); | |||
5555 | ||||
5556 | FunctionDecl *TemplatedFD; | |||
5557 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) | |||
5558 | return std::move(Err); | |||
5559 | ||||
5560 | FunctionTemplateDecl *ToFunc; | |||
5561 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, | |||
5562 | *ParamsOrErr, TemplatedFD)) | |||
5563 | return ToFunc; | |||
5564 | ||||
5565 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); | |||
5566 | ToFunc->setAccess(D->getAccess()); | |||
5567 | ToFunc->setLexicalDeclContext(LexicalDC); | |||
5568 | ||||
5569 | LexicalDC->addDeclInternal(ToFunc); | |||
5570 | return ToFunc; | |||
5571 | } | |||
5572 | ||||
5573 | //---------------------------------------------------------------------------- | |||
5574 | // Import Statements | |||
5575 | //---------------------------------------------------------------------------- | |||
5576 | ||||
5577 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { | |||
5578 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) | |||
5579 | << S->getStmtClassName(); | |||
5580 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
5581 | } | |||
5582 | ||||
5583 | ||||
5584 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { | |||
5585 | SmallVector<IdentifierInfo *, 4> Names; | |||
5586 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { | |||
5587 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); | |||
5588 | // ToII is nullptr when no symbolic name is given for output operand | |||
5589 | // see ParseStmtAsm::ParseAsmOperandsOpt | |||
5590 | Names.push_back(ToII); | |||
5591 | } | |||
5592 | ||||
5593 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { | |||
5594 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); | |||
5595 | // ToII is nullptr when no symbolic name is given for input operand | |||
5596 | // see ParseStmtAsm::ParseAsmOperandsOpt | |||
5597 | Names.push_back(ToII); | |||
5598 | } | |||
5599 | ||||
5600 | SmallVector<StringLiteral *, 4> Clobbers; | |||
5601 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { | |||
5602 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) | |||
5603 | Clobbers.push_back(*ClobberOrErr); | |||
5604 | else | |||
5605 | return ClobberOrErr.takeError(); | |||
5606 | ||||
5607 | } | |||
5608 | ||||
5609 | SmallVector<StringLiteral *, 4> Constraints; | |||
5610 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { | |||
5611 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) | |||
5612 | Constraints.push_back(*OutputOrErr); | |||
5613 | else | |||
5614 | return OutputOrErr.takeError(); | |||
5615 | } | |||
5616 | ||||
5617 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { | |||
5618 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) | |||
5619 | Constraints.push_back(*InputOrErr); | |||
5620 | else | |||
5621 | return InputOrErr.takeError(); | |||
5622 | } | |||
5623 | ||||
5624 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); | |||
5625 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) | |||
5626 | return std::move(Err); | |||
5627 | ||||
5628 | if (Error Err = ImportArrayChecked( | |||
5629 | S->inputs(), Exprs.begin() + S->getNumOutputs())) | |||
5630 | return std::move(Err); | |||
5631 | ||||
5632 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); | |||
5633 | if (!AsmLocOrErr) | |||
5634 | return AsmLocOrErr.takeError(); | |||
5635 | auto AsmStrOrErr = import(S->getAsmString()); | |||
5636 | if (!AsmStrOrErr) | |||
5637 | return AsmStrOrErr.takeError(); | |||
5638 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); | |||
5639 | if (!RParenLocOrErr) | |||
5640 | return RParenLocOrErr.takeError(); | |||
5641 | ||||
5642 | return new (Importer.getToContext()) GCCAsmStmt( | |||
5643 | Importer.getToContext(), | |||
5644 | *AsmLocOrErr, | |||
5645 | S->isSimple(), | |||
5646 | S->isVolatile(), | |||
5647 | S->getNumOutputs(), | |||
5648 | S->getNumInputs(), | |||
5649 | Names.data(), | |||
5650 | Constraints.data(), | |||
5651 | Exprs.data(), | |||
5652 | *AsmStrOrErr, | |||
5653 | S->getNumClobbers(), | |||
5654 | Clobbers.data(), | |||
5655 | *RParenLocOrErr); | |||
5656 | } | |||
5657 | ||||
5658 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { | |||
5659 | auto Imp = importSeq(S->getDeclGroup(), S->getBeginLoc(), S->getEndLoc()); | |||
5660 | if (!Imp) | |||
5661 | return Imp.takeError(); | |||
5662 | ||||
5663 | DeclGroupRef ToDG; | |||
5664 | SourceLocation ToBeginLoc, ToEndLoc; | |||
5665 | std::tie(ToDG, ToBeginLoc, ToEndLoc) = *Imp; | |||
5666 | ||||
5667 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); | |||
5668 | } | |||
5669 | ||||
5670 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { | |||
5671 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); | |||
5672 | if (!ToSemiLocOrErr) | |||
5673 | return ToSemiLocOrErr.takeError(); | |||
5674 | return new (Importer.getToContext()) NullStmt( | |||
5675 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); | |||
5676 | } | |||
5677 | ||||
5678 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { | |||
5679 | SmallVector<Stmt *, 8> ToStmts(S->size()); | |||
5680 | ||||
5681 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) | |||
5682 | return std::move(Err); | |||
5683 | ||||
5684 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); | |||
5685 | if (!ToLBracLocOrErr) | |||
5686 | return ToLBracLocOrErr.takeError(); | |||
5687 | ||||
5688 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); | |||
5689 | if (!ToRBracLocOrErr) | |||
5690 | return ToRBracLocOrErr.takeError(); | |||
5691 | ||||
5692 | return CompoundStmt::Create( | |||
5693 | Importer.getToContext(), ToStmts, | |||
5694 | *ToLBracLocOrErr, *ToRBracLocOrErr); | |||
5695 | } | |||
5696 | ||||
5697 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { | |||
5698 | auto Imp = importSeq( | |||
5699 | S->getLHS(), S->getRHS(), S->getSubStmt(), S->getCaseLoc(), | |||
5700 | S->getEllipsisLoc(), S->getColonLoc()); | |||
5701 | if (!Imp) | |||
5702 | return Imp.takeError(); | |||
5703 | ||||
5704 | Expr *ToLHS, *ToRHS; | |||
5705 | Stmt *ToSubStmt; | |||
5706 | SourceLocation ToCaseLoc, ToEllipsisLoc, ToColonLoc; | |||
5707 | std::tie(ToLHS, ToRHS, ToSubStmt, ToCaseLoc, ToEllipsisLoc, ToColonLoc) = | |||
5708 | *Imp; | |||
5709 | ||||
5710 | auto *ToStmt = new (Importer.getToContext()) CaseStmt( | |||
5711 | ToLHS, ToRHS, ToCaseLoc, ToEllipsisLoc, ToColonLoc); | |||
5712 | ToStmt->setSubStmt(ToSubStmt); | |||
5713 | ||||
5714 | return ToStmt; | |||
5715 | } | |||
5716 | ||||
5717 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { | |||
5718 | auto Imp = importSeq(S->getDefaultLoc(), S->getColonLoc(), S->getSubStmt()); | |||
5719 | if (!Imp) | |||
5720 | return Imp.takeError(); | |||
5721 | ||||
5722 | SourceLocation ToDefaultLoc, ToColonLoc; | |||
5723 | Stmt *ToSubStmt; | |||
5724 | std::tie(ToDefaultLoc, ToColonLoc, ToSubStmt) = *Imp; | |||
5725 | ||||
5726 | return new (Importer.getToContext()) DefaultStmt( | |||
5727 | ToDefaultLoc, ToColonLoc, ToSubStmt); | |||
5728 | } | |||
5729 | ||||
5730 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { | |||
5731 | auto Imp = importSeq(S->getIdentLoc(), S->getDecl(), S->getSubStmt()); | |||
5732 | if (!Imp) | |||
5733 | return Imp.takeError(); | |||
5734 | ||||
5735 | SourceLocation ToIdentLoc; | |||
5736 | LabelDecl *ToLabelDecl; | |||
5737 | Stmt *ToSubStmt; | |||
5738 | std::tie(ToIdentLoc, ToLabelDecl, ToSubStmt) = *Imp; | |||
5739 | ||||
5740 | return new (Importer.getToContext()) LabelStmt( | |||
5741 | ToIdentLoc, ToLabelDecl, ToSubStmt); | |||
5742 | } | |||
5743 | ||||
5744 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { | |||
5745 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); | |||
5746 | if (!ToAttrLocOrErr) | |||
5747 | return ToAttrLocOrErr.takeError(); | |||
5748 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); | |||
5749 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); | |||
5750 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) | |||
5751 | return std::move(Err); | |||
5752 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); | |||
5753 | if (!ToSubStmtOrErr) | |||
5754 | return ToSubStmtOrErr.takeError(); | |||
5755 | ||||
5756 | return AttributedStmt::Create( | |||
5757 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); | |||
5758 | } | |||
5759 | ||||
5760 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { | |||
5761 | auto Imp = importSeq( | |||
5762 | S->getIfLoc(), S->getInit(), S->getConditionVariable(), S->getCond(), | |||
5763 | S->getThen(), S->getElseLoc(), S->getElse()); | |||
5764 | if (!Imp) | |||
5765 | return Imp.takeError(); | |||
5766 | ||||
5767 | SourceLocation ToIfLoc, ToElseLoc; | |||
5768 | Stmt *ToInit, *ToThen, *ToElse; | |||
5769 | VarDecl *ToConditionVariable; | |||
5770 | Expr *ToCond; | |||
5771 | std::tie( | |||
5772 | ToIfLoc, ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, ToElse) = | |||
5773 | *Imp; | |||
5774 | ||||
5775 | return new (Importer.getToContext()) IfStmt( | |||
5776 | Importer.getToContext(), | |||
5777 | ToIfLoc, S->isConstexpr(), ToInit, ToConditionVariable, ToCond, | |||
5778 | ToThen, ToElseLoc, ToElse); | |||
5779 | } | |||
5780 | ||||
5781 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { | |||
5782 | auto Imp = importSeq( | |||
5783 | S->getInit(), S->getConditionVariable(), S->getCond(), | |||
5784 | S->getBody(), S->getSwitchLoc()); | |||
5785 | if (!Imp) | |||
5786 | return Imp.takeError(); | |||
5787 | ||||
5788 | Stmt *ToInit, *ToBody; | |||
5789 | VarDecl *ToConditionVariable; | |||
5790 | Expr *ToCond; | |||
5791 | SourceLocation ToSwitchLoc; | |||
5792 | std::tie(ToInit, ToConditionVariable, ToCond, ToBody, ToSwitchLoc) = *Imp; | |||
5793 | ||||
5794 | auto *ToStmt = new (Importer.getToContext()) SwitchStmt( | |||
5795 | Importer.getToContext(), ToInit, ToConditionVariable, ToCond); | |||
5796 | ToStmt->setBody(ToBody); | |||
5797 | ToStmt->setSwitchLoc(ToSwitchLoc); | |||
5798 | ||||
5799 | // Now we have to re-chain the cases. | |||
5800 | SwitchCase *LastChainedSwitchCase = nullptr; | |||
5801 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; | |||
5802 | SC = SC->getNextSwitchCase()) { | |||
5803 | Expected<SwitchCase *> ToSCOrErr = import(SC); | |||
5804 | if (!ToSCOrErr) | |||
5805 | return ToSCOrErr.takeError(); | |||
5806 | if (LastChainedSwitchCase) | |||
5807 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); | |||
5808 | else | |||
5809 | ToStmt->setSwitchCaseList(*ToSCOrErr); | |||
5810 | LastChainedSwitchCase = *ToSCOrErr; | |||
5811 | } | |||
5812 | ||||
5813 | return ToStmt; | |||
5814 | } | |||
5815 | ||||
5816 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { | |||
5817 | auto Imp = importSeq( | |||
5818 | S->getConditionVariable(), S->getCond(), S->getBody(), S->getWhileLoc()); | |||
5819 | if (!Imp) | |||
5820 | return Imp.takeError(); | |||
5821 | ||||
5822 | VarDecl *ToConditionVariable; | |||
5823 | Expr *ToCond; | |||
5824 | Stmt *ToBody; | |||
5825 | SourceLocation ToWhileLoc; | |||
5826 | std::tie(ToConditionVariable, ToCond, ToBody, ToWhileLoc) = *Imp; | |||
5827 | ||||
5828 | return new (Importer.getToContext()) WhileStmt( | |||
5829 | Importer.getToContext(), | |||
5830 | ToConditionVariable, ToCond, ToBody, ToWhileLoc); | |||
5831 | } | |||
5832 | ||||
5833 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { | |||
5834 | auto Imp = importSeq( | |||
5835 | S->getBody(), S->getCond(), S->getDoLoc(), S->getWhileLoc(), | |||
5836 | S->getRParenLoc()); | |||
5837 | if (!Imp) | |||
5838 | return Imp.takeError(); | |||
5839 | ||||
5840 | Stmt *ToBody; | |||
5841 | Expr *ToCond; | |||
5842 | SourceLocation ToDoLoc, ToWhileLoc, ToRParenLoc; | |||
5843 | std::tie(ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc) = *Imp; | |||
5844 | ||||
5845 | return new (Importer.getToContext()) DoStmt( | |||
5846 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); | |||
5847 | } | |||
5848 | ||||
5849 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { | |||
5850 | auto Imp = importSeq( | |||
5851 | S->getInit(), S->getCond(), S->getConditionVariable(), S->getInc(), | |||
5852 | S->getBody(), S->getForLoc(), S->getLParenLoc(), S->getRParenLoc()); | |||
5853 | if (!Imp) | |||
5854 | return Imp.takeError(); | |||
5855 | ||||
5856 | Stmt *ToInit; | |||
5857 | Expr *ToCond, *ToInc; | |||
5858 | VarDecl *ToConditionVariable; | |||
5859 | Stmt *ToBody; | |||
5860 | SourceLocation ToForLoc, ToLParenLoc, ToRParenLoc; | |||
5861 | std::tie( | |||
5862 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, | |||
5863 | ToLParenLoc, ToRParenLoc) = *Imp; | |||
5864 | ||||
5865 | return new (Importer.getToContext()) ForStmt( | |||
5866 | Importer.getToContext(), | |||
5867 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, | |||
5868 | ToRParenLoc); | |||
5869 | } | |||
5870 | ||||
5871 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { | |||
5872 | auto Imp = importSeq(S->getLabel(), S->getGotoLoc(), S->getLabelLoc()); | |||
5873 | if (!Imp) | |||
5874 | return Imp.takeError(); | |||
5875 | ||||
5876 | LabelDecl *ToLabel; | |||
5877 | SourceLocation ToGotoLoc, ToLabelLoc; | |||
5878 | std::tie(ToLabel, ToGotoLoc, ToLabelLoc) = *Imp; | |||
5879 | ||||
5880 | return new (Importer.getToContext()) GotoStmt( | |||
5881 | ToLabel, ToGotoLoc, ToLabelLoc); | |||
5882 | } | |||
5883 | ||||
5884 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { | |||
5885 | auto Imp = importSeq(S->getGotoLoc(), S->getStarLoc(), S->getTarget()); | |||
5886 | if (!Imp) | |||
5887 | return Imp.takeError(); | |||
5888 | ||||
5889 | SourceLocation ToGotoLoc, ToStarLoc; | |||
5890 | Expr *ToTarget; | |||
5891 | std::tie(ToGotoLoc, ToStarLoc, ToTarget) = *Imp; | |||
5892 | ||||
5893 | return new (Importer.getToContext()) IndirectGotoStmt( | |||
5894 | ToGotoLoc, ToStarLoc, ToTarget); | |||
5895 | } | |||
5896 | ||||
5897 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { | |||
5898 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); | |||
5899 | if (!ToContinueLocOrErr) | |||
5900 | return ToContinueLocOrErr.takeError(); | |||
5901 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); | |||
5902 | } | |||
5903 | ||||
5904 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { | |||
5905 | auto ToBreakLocOrErr = import(S->getBreakLoc()); | |||
5906 | if (!ToBreakLocOrErr) | |||
5907 | return ToBreakLocOrErr.takeError(); | |||
5908 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); | |||
5909 | } | |||
5910 | ||||
5911 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { | |||
5912 | auto Imp = importSeq( | |||
5913 | S->getReturnLoc(), S->getRetValue(), S->getNRVOCandidate()); | |||
5914 | if (!Imp) | |||
5915 | return Imp.takeError(); | |||
5916 | ||||
5917 | SourceLocation ToReturnLoc; | |||
5918 | Expr *ToRetValue; | |||
5919 | const VarDecl *ToNRVOCandidate; | |||
5920 | std::tie(ToReturnLoc, ToRetValue, ToNRVOCandidate) = *Imp; | |||
5921 | ||||
5922 | return new (Importer.getToContext()) ReturnStmt( | |||
5923 | ToReturnLoc, ToRetValue, ToNRVOCandidate); | |||
5924 | } | |||
5925 | ||||
5926 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { | |||
5927 | auto Imp = importSeq( | |||
5928 | S->getCatchLoc(), S->getExceptionDecl(), S->getHandlerBlock()); | |||
5929 | if (!Imp) | |||
5930 | return Imp.takeError(); | |||
5931 | ||||
5932 | SourceLocation ToCatchLoc; | |||
5933 | VarDecl *ToExceptionDecl; | |||
5934 | Stmt *ToHandlerBlock; | |||
5935 | std::tie(ToCatchLoc, ToExceptionDecl, ToHandlerBlock) = *Imp; | |||
5936 | ||||
5937 | return new (Importer.getToContext()) CXXCatchStmt ( | |||
5938 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); | |||
5939 | } | |||
5940 | ||||
5941 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { | |||
5942 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); | |||
5943 | if (!ToTryLocOrErr) | |||
5944 | return ToTryLocOrErr.takeError(); | |||
5945 | ||||
5946 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); | |||
5947 | if (!ToTryBlockOrErr) | |||
5948 | return ToTryBlockOrErr.takeError(); | |||
5949 | ||||
5950 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); | |||
5951 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { | |||
5952 | CXXCatchStmt *FromHandler = S->getHandler(HI); | |||
5953 | if (auto ToHandlerOrErr = import(FromHandler)) | |||
5954 | ToHandlers[HI] = *ToHandlerOrErr; | |||
5955 | else | |||
5956 | return ToHandlerOrErr.takeError(); | |||
5957 | } | |||
5958 | ||||
5959 | return CXXTryStmt::Create( | |||
5960 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); | |||
5961 | } | |||
5962 | ||||
5963 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { | |||
5964 | auto Imp1 = importSeq( | |||
5965 | S->getInit(), S->getRangeStmt(), S->getBeginStmt(), S->getEndStmt(), | |||
5966 | S->getCond(), S->getInc(), S->getLoopVarStmt(), S->getBody()); | |||
5967 | if (!Imp1) | |||
5968 | return Imp1.takeError(); | |||
5969 | auto Imp2 = importSeq( | |||
5970 | S->getForLoc(), S->getCoawaitLoc(), S->getColonLoc(), S->getRParenLoc()); | |||
5971 | if (!Imp2) | |||
5972 | return Imp2.takeError(); | |||
5973 | ||||
5974 | DeclStmt *ToRangeStmt, *ToBeginStmt, *ToEndStmt, *ToLoopVarStmt; | |||
5975 | Expr *ToCond, *ToInc; | |||
5976 | Stmt *ToInit, *ToBody; | |||
5977 | std::tie( | |||
5978 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, | |||
5979 | ToBody) = *Imp1; | |||
5980 | SourceLocation ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc; | |||
5981 | std::tie(ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc) = *Imp2; | |||
5982 | ||||
5983 | return new (Importer.getToContext()) CXXForRangeStmt( | |||
5984 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, | |||
5985 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); | |||
5986 | } | |||
5987 | ||||
5988 | ExpectedStmt | |||
5989 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { | |||
5990 | auto Imp = importSeq( | |||
5991 | S->getElement(), S->getCollection(), S->getBody(), | |||
5992 | S->getForLoc(), S->getRParenLoc()); | |||
5993 | if (!Imp) | |||
5994 | return Imp.takeError(); | |||
5995 | ||||
5996 | Stmt *ToElement, *ToBody; | |||
5997 | Expr *ToCollection; | |||
5998 | SourceLocation ToForLoc, ToRParenLoc; | |||
5999 | std::tie(ToElement, ToCollection, ToBody, ToForLoc, ToRParenLoc) = *Imp; | |||
6000 | ||||
6001 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, | |||
6002 | ToCollection, | |||
6003 | ToBody, | |||
6004 | ToForLoc, | |||
6005 | ToRParenLoc); | |||
6006 | } | |||
6007 | ||||
6008 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { | |||
6009 | auto Imp = importSeq( | |||
6010 | S->getAtCatchLoc(), S->getRParenLoc(), S->getCatchParamDecl(), | |||
6011 | S->getCatchBody()); | |||
6012 | if (!Imp) | |||
6013 | return Imp.takeError(); | |||
6014 | ||||
6015 | SourceLocation ToAtCatchLoc, ToRParenLoc; | |||
6016 | VarDecl *ToCatchParamDecl; | |||
6017 | Stmt *ToCatchBody; | |||
6018 | std::tie(ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody) = *Imp; | |||
6019 | ||||
6020 | return new (Importer.getToContext()) ObjCAtCatchStmt ( | |||
6021 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); | |||
6022 | } | |||
6023 | ||||
6024 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { | |||
6025 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); | |||
6026 | if (!ToAtFinallyLocOrErr) | |||
6027 | return ToAtFinallyLocOrErr.takeError(); | |||
6028 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); | |||
6029 | if (!ToAtFinallyStmtOrErr) | |||
6030 | return ToAtFinallyStmtOrErr.takeError(); | |||
6031 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, | |||
6032 | *ToAtFinallyStmtOrErr); | |||
6033 | } | |||
6034 | ||||
6035 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { | |||
6036 | auto Imp = importSeq( | |||
6037 | S->getAtTryLoc(), S->getTryBody(), S->getFinallyStmt()); | |||
6038 | if (!Imp) | |||
6039 | return Imp.takeError(); | |||
6040 | ||||
6041 | SourceLocation ToAtTryLoc; | |||
6042 | Stmt *ToTryBody, *ToFinallyStmt; | |||
6043 | std::tie(ToAtTryLoc, ToTryBody, ToFinallyStmt) = *Imp; | |||
6044 | ||||
6045 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); | |||
6046 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { | |||
6047 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); | |||
6048 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) | |||
6049 | ToCatchStmts[CI] = *ToCatchStmtOrErr; | |||
6050 | else | |||
6051 | return ToCatchStmtOrErr.takeError(); | |||
6052 | } | |||
6053 | ||||
6054 | return ObjCAtTryStmt::Create(Importer.getToContext(), | |||
6055 | ToAtTryLoc, ToTryBody, | |||
6056 | ToCatchStmts.begin(), ToCatchStmts.size(), | |||
6057 | ToFinallyStmt); | |||
6058 | } | |||
6059 | ||||
6060 | ExpectedStmt ASTNodeImporter::VisitObjCAtSynchronizedStmt | |||
6061 | (ObjCAtSynchronizedStmt *S) { | |||
6062 | auto Imp = importSeq( | |||
6063 | S->getAtSynchronizedLoc(), S->getSynchExpr(), S->getSynchBody()); | |||
6064 | if (!Imp) | |||
6065 | return Imp.takeError(); | |||
6066 | ||||
6067 | SourceLocation ToAtSynchronizedLoc; | |||
6068 | Expr *ToSynchExpr; | |||
6069 | Stmt *ToSynchBody; | |||
6070 | std::tie(ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody) = *Imp; | |||
6071 | ||||
6072 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( | |||
6073 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); | |||
6074 | } | |||
6075 | ||||
6076 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { | |||
6077 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); | |||
6078 | if (!ToThrowLocOrErr) | |||
6079 | return ToThrowLocOrErr.takeError(); | |||
6080 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); | |||
6081 | if (!ToThrowExprOrErr) | |||
6082 | return ToThrowExprOrErr.takeError(); | |||
6083 | return new (Importer.getToContext()) ObjCAtThrowStmt( | |||
6084 | *ToThrowLocOrErr, *ToThrowExprOrErr); | |||
6085 | } | |||
6086 | ||||
6087 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( | |||
6088 | ObjCAutoreleasePoolStmt *S) { | |||
6089 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); | |||
6090 | if (!ToAtLocOrErr) | |||
6091 | return ToAtLocOrErr.takeError(); | |||
6092 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); | |||
6093 | if (!ToSubStmtOrErr) | |||
6094 | return ToSubStmtOrErr.takeError(); | |||
6095 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, | |||
6096 | *ToSubStmtOrErr); | |||
6097 | } | |||
6098 | ||||
6099 | //---------------------------------------------------------------------------- | |||
6100 | // Import Expressions | |||
6101 | //---------------------------------------------------------------------------- | |||
6102 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { | |||
6103 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) | |||
6104 | << E->getStmtClassName(); | |||
6105 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
6106 | } | |||
6107 | ||||
6108 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { | |||
6109 | auto Imp = importSeq( | |||
6110 | E->getBuiltinLoc(), E->getSubExpr(), E->getWrittenTypeInfo(), | |||
6111 | E->getRParenLoc(), E->getType()); | |||
6112 | if (!Imp) | |||
6113 | return Imp.takeError(); | |||
6114 | ||||
6115 | SourceLocation ToBuiltinLoc, ToRParenLoc; | |||
6116 | Expr *ToSubExpr; | |||
6117 | TypeSourceInfo *ToWrittenTypeInfo; | |||
6118 | QualType ToType; | |||
6119 | std::tie(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType) = | |||
6120 | *Imp; | |||
6121 | ||||
6122 | return new (Importer.getToContext()) VAArgExpr( | |||
6123 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, | |||
6124 | E->isMicrosoftABI()); | |||
6125 | } | |||
6126 | ||||
6127 | ||||
6128 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { | |||
6129 | ExpectedType TypeOrErr = import(E->getType()); | |||
6130 | if (!TypeOrErr) | |||
6131 | return TypeOrErr.takeError(); | |||
6132 | ||||
6133 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); | |||
6134 | if (!BeginLocOrErr) | |||
6135 | return BeginLocOrErr.takeError(); | |||
6136 | ||||
6137 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); | |||
6138 | } | |||
6139 | ||||
6140 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { | |||
6141 | auto Imp = importSeq( | |||
6142 | E->getBeginLoc(), E->getType(), E->getFunctionName()); | |||
6143 | if (!Imp) | |||
6144 | return Imp.takeError(); | |||
6145 | ||||
6146 | SourceLocation ToBeginLoc; | |||
6147 | QualType ToType; | |||
6148 | StringLiteral *ToFunctionName; | |||
6149 | std::tie(ToBeginLoc, ToType, ToFunctionName) = *Imp; | |||
6150 | ||||
6151 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, | |||
6152 | E->getIdentKind(), ToFunctionName); | |||
6153 | } | |||
6154 | ||||
6155 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { | |||
6156 | auto Imp = importSeq( | |||
6157 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDecl(), | |||
6158 | E->getLocation(), E->getType()); | |||
6159 | if (!Imp) | |||
6160 | return Imp.takeError(); | |||
6161 | ||||
6162 | NestedNameSpecifierLoc ToQualifierLoc; | |||
6163 | SourceLocation ToTemplateKeywordLoc, ToLocation; | |||
6164 | ValueDecl *ToDecl; | |||
6165 | QualType ToType; | |||
6166 | std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, ToLocation, ToType) = | |||
6167 | *Imp; | |||
6168 | ||||
6169 | NamedDecl *ToFoundD = nullptr; | |||
6170 | if (E->getDecl() != E->getFoundDecl()) { | |||
6171 | auto FoundDOrErr = import(E->getFoundDecl()); | |||
6172 | if (!FoundDOrErr) | |||
6173 | return FoundDOrErr.takeError(); | |||
6174 | ToFoundD = *FoundDOrErr; | |||
6175 | } | |||
6176 | ||||
6177 | TemplateArgumentListInfo ToTAInfo; | |||
6178 | TemplateArgumentListInfo *ToResInfo = nullptr; | |||
6179 | if (E->hasExplicitTemplateArgs()) { | |||
6180 | if (Error Err = | |||
6181 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) | |||
6182 | return std::move(Err); | |||
6183 | ToResInfo = &ToTAInfo; | |||
6184 | } | |||
6185 | ||||
6186 | auto *ToE = DeclRefExpr::Create( | |||
6187 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, | |||
6188 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, | |||
6189 | E->getValueKind(), ToFoundD, ToResInfo); | |||
6190 | if (E->hadMultipleCandidates()) | |||
6191 | ToE->setHadMultipleCandidates(true); | |||
6192 | return ToE; | |||
6193 | } | |||
6194 | ||||
6195 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { | |||
6196 | ExpectedType TypeOrErr = import(E->getType()); | |||
6197 | if (!TypeOrErr) | |||
6198 | return TypeOrErr.takeError(); | |||
6199 | ||||
6200 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); | |||
6201 | } | |||
6202 | ||||
6203 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { | |||
6204 | ExpectedExpr ToInitOrErr = import(E->getInit()); | |||
6205 | if (!ToInitOrErr) | |||
6206 | return ToInitOrErr.takeError(); | |||
6207 | ||||
6208 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); | |||
6209 | if (!ToEqualOrColonLocOrErr) | |||
6210 | return ToEqualOrColonLocOrErr.takeError(); | |||
6211 | ||||
6212 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); | |||
6213 | // List elements from the second, the first is Init itself | |||
6214 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { | |||
6215 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) | |||
6216 | ToIndexExprs[I - 1] = *ToArgOrErr; | |||
6217 | else | |||
6218 | return ToArgOrErr.takeError(); | |||
6219 | } | |||
6220 | ||||
6221 | SmallVector<Designator, 4> ToDesignators(E->size()); | |||
6222 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) | |||
6223 | return std::move(Err); | |||
6224 | ||||
6225 | return DesignatedInitExpr::Create( | |||
6226 | Importer.getToContext(), ToDesignators, | |||
6227 | ToIndexExprs, *ToEqualOrColonLocOrErr, | |||
6228 | E->usesGNUSyntax(), *ToInitOrErr); | |||
6229 | } | |||
6230 | ||||
6231 | ExpectedStmt | |||
6232 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { | |||
6233 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
6234 | if (!ToTypeOrErr) | |||
6235 | return ToTypeOrErr.takeError(); | |||
6236 | ||||
6237 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | |||
6238 | if (!ToLocationOrErr) | |||
6239 | return ToLocationOrErr.takeError(); | |||
6240 | ||||
6241 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( | |||
6242 | *ToTypeOrErr, *ToLocationOrErr); | |||
6243 | } | |||
6244 | ||||
6245 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { | |||
6246 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
6247 | if (!ToTypeOrErr) | |||
6248 | return ToTypeOrErr.takeError(); | |||
6249 | ||||
6250 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | |||
6251 | if (!ToLocationOrErr) | |||
6252 | return ToLocationOrErr.takeError(); | |||
6253 | ||||
6254 | return IntegerLiteral::Create( | |||
6255 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); | |||
6256 | } | |||
6257 | ||||
6258 | ||||
6259 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { | |||
6260 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
6261 | if (!ToTypeOrErr) | |||
6262 | return ToTypeOrErr.takeError(); | |||
6263 | ||||
6264 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | |||
6265 | if (!ToLocationOrErr) | |||
6266 | return ToLocationOrErr.takeError(); | |||
6267 | ||||
6268 | return FloatingLiteral::Create( | |||
6269 | Importer.getToContext(), E->getValue(), E->isExact(), | |||
6270 | *ToTypeOrErr, *ToLocationOrErr); | |||
6271 | } | |||
6272 | ||||
6273 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { | |||
6274 | auto ToTypeOrErr = import(E->getType()); | |||
6275 | if (!ToTypeOrErr) | |||
6276 | return ToTypeOrErr.takeError(); | |||
6277 | ||||
6278 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | |||
6279 | if (!ToSubExprOrErr) | |||
6280 | return ToSubExprOrErr.takeError(); | |||
6281 | ||||
6282 | return new (Importer.getToContext()) ImaginaryLiteral( | |||
6283 | *ToSubExprOrErr, *ToTypeOrErr); | |||
6284 | } | |||
6285 | ||||
6286 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { | |||
6287 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
6288 | if (!ToTypeOrErr) | |||
6289 | return ToTypeOrErr.takeError(); | |||
6290 | ||||
6291 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | |||
6292 | if (!ToLocationOrErr) | |||
6293 | return ToLocationOrErr.takeError(); | |||
6294 | ||||
6295 | return new (Importer.getToContext()) CharacterLiteral( | |||
6296 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); | |||
6297 | } | |||
6298 | ||||
6299 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { | |||
6300 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
6301 | if (!ToTypeOrErr) | |||
6302 | return ToTypeOrErr.takeError(); | |||
6303 | ||||
6304 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); | |||
6305 | if (Error Err = ImportArrayChecked( | |||
6306 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) | |||
6307 | return std::move(Err); | |||
6308 | ||||
6309 | return StringLiteral::Create( | |||
6310 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), | |||
6311 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); | |||
6312 | } | |||
6313 | ||||
6314 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { | |||
6315 | auto Imp = importSeq( | |||
6316 | E->getLParenLoc(), E->getTypeSourceInfo(), E->getType(), | |||
6317 | E->getInitializer()); | |||
6318 | if (!Imp) | |||
6319 | return Imp.takeError(); | |||
6320 | ||||
6321 | SourceLocation ToLParenLoc; | |||
6322 | TypeSourceInfo *ToTypeSourceInfo; | |||
6323 | QualType ToType; | |||
6324 | Expr *ToInitializer; | |||
6325 | std::tie(ToLParenLoc, ToTypeSourceInfo, ToType, ToInitializer) = *Imp; | |||
6326 | ||||
6327 | return new (Importer.getToContext()) CompoundLiteralExpr( | |||
6328 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), | |||
6329 | ToInitializer, E->isFileScope()); | |||
6330 | } | |||
6331 | ||||
6332 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { | |||
6333 | auto Imp = importSeq( | |||
6334 | E->getBuiltinLoc(), E->getType(), E->getRParenLoc()); | |||
6335 | if (!Imp) | |||
6336 | return Imp.takeError(); | |||
6337 | ||||
6338 | SourceLocation ToBuiltinLoc, ToRParenLoc; | |||
6339 | QualType ToType; | |||
6340 | std::tie(ToBuiltinLoc, ToType, ToRParenLoc) = *Imp; | |||
6341 | ||||
6342 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); | |||
6343 | if (Error Err = ImportArrayChecked( | |||
6344 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), | |||
6345 | ToExprs.begin())) | |||
6346 | return std::move(Err); | |||
6347 | ||||
6348 | return new (Importer.getToContext()) AtomicExpr( | |||
6349 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); | |||
6350 | } | |||
6351 | ||||
6352 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { | |||
6353 | auto Imp = importSeq( | |||
6354 | E->getAmpAmpLoc(), E->getLabelLoc(), E->getLabel(), E->getType()); | |||
6355 | if (!Imp) | |||
6356 | return Imp.takeError(); | |||
6357 | ||||
6358 | SourceLocation ToAmpAmpLoc, ToLabelLoc; | |||
6359 | LabelDecl *ToLabel; | |||
6360 | QualType ToType; | |||
6361 | std::tie(ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType) = *Imp; | |||
6362 | ||||
6363 | return new (Importer.getToContext()) AddrLabelExpr( | |||
6364 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); | |||
6365 | } | |||
6366 | ||||
6367 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { | |||
6368 | auto Imp = importSeq(E->getLParen(), E->getRParen(), E->getSubExpr()); | |||
6369 | if (!Imp) | |||
6370 | return Imp.takeError(); | |||
6371 | ||||
6372 | SourceLocation ToLParen, ToRParen; | |||
6373 | Expr *ToSubExpr; | |||
6374 | std::tie(ToLParen, ToRParen, ToSubExpr) = *Imp; | |||
6375 | ||||
6376 | return new (Importer.getToContext()) | |||
6377 | ParenExpr(ToLParen, ToRParen, ToSubExpr); | |||
6378 | } | |||
6379 | ||||
6380 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { | |||
6381 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); | |||
6382 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) | |||
6383 | return std::move(Err); | |||
6384 | ||||
6385 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); | |||
6386 | if (!ToLParenLocOrErr) | |||
6387 | return ToLParenLocOrErr.takeError(); | |||
6388 | ||||
6389 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); | |||
6390 | if (!ToRParenLocOrErr) | |||
6391 | return ToRParenLocOrErr.takeError(); | |||
6392 | ||||
6393 | return new (Importer.getToContext()) ParenListExpr( | |||
6394 | Importer.getToContext(), *ToLParenLocOrErr, ToExprs, *ToRParenLocOrErr); | |||
6395 | } | |||
6396 | ||||
6397 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { | |||
6398 | auto Imp = importSeq( | |||
6399 | E->getSubStmt(), E->getType(), E->getLParenLoc(), E->getRParenLoc()); | |||
6400 | if (!Imp) | |||
6401 | return Imp.takeError(); | |||
6402 | ||||
6403 | CompoundStmt *ToSubStmt; | |||
6404 | QualType ToType; | |||
6405 | SourceLocation ToLParenLoc, ToRParenLoc; | |||
6406 | std::tie(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc) = *Imp; | |||
6407 | ||||
6408 | return new (Importer.getToContext()) StmtExpr( | |||
6409 | ToSubStmt, ToType, ToLParenLoc, ToRParenLoc); | |||
6410 | } | |||
6411 | ||||
6412 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { | |||
6413 | auto Imp = importSeq( | |||
6414 | E->getSubExpr(), E->getType(), E->getOperatorLoc()); | |||
6415 | if (!Imp) | |||
6416 | return Imp.takeError(); | |||
6417 | ||||
6418 | Expr *ToSubExpr; | |||
6419 | QualType ToType; | |||
6420 | SourceLocation ToOperatorLoc; | |||
6421 | std::tie(ToSubExpr, ToType, ToOperatorLoc) = *Imp; | |||
6422 | ||||
6423 | return new (Importer.getToContext()) UnaryOperator( | |||
6424 | ToSubExpr, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(), | |||
6425 | ToOperatorLoc, E->canOverflow()); | |||
6426 | } | |||
6427 | ||||
6428 | ExpectedStmt | |||
6429 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { | |||
6430 | auto Imp = importSeq(E->getType(), E->getOperatorLoc(), E->getRParenLoc()); | |||
6431 | if (!Imp) | |||
6432 | return Imp.takeError(); | |||
6433 | ||||
6434 | QualType ToType; | |||
6435 | SourceLocation ToOperatorLoc, ToRParenLoc; | |||
6436 | std::tie(ToType, ToOperatorLoc, ToRParenLoc) = *Imp; | |||
6437 | ||||
6438 | if (E->isArgumentType()) { | |||
6439 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = | |||
6440 | import(E->getArgumentTypeInfo()); | |||
6441 | if (!ToArgumentTypeInfoOrErr) | |||
6442 | return ToArgumentTypeInfoOrErr.takeError(); | |||
6443 | ||||
6444 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( | |||
6445 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, | |||
6446 | ToRParenLoc); | |||
6447 | } | |||
6448 | ||||
6449 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); | |||
6450 | if (!ToArgumentExprOrErr) | |||
6451 | return ToArgumentExprOrErr.takeError(); | |||
6452 | ||||
6453 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( | |||
6454 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); | |||
6455 | } | |||
6456 | ||||
6457 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { | |||
6458 | auto Imp = importSeq( | |||
6459 | E->getLHS(), E->getRHS(), E->getType(), E->getOperatorLoc()); | |||
6460 | if (!Imp) | |||
6461 | return Imp.takeError(); | |||
6462 | ||||
6463 | Expr *ToLHS, *ToRHS; | |||
6464 | QualType ToType; | |||
6465 | SourceLocation ToOperatorLoc; | |||
6466 | std::tie(ToLHS, ToRHS, ToType, ToOperatorLoc) = *Imp; | |||
6467 | ||||
6468 | return new (Importer.getToContext()) BinaryOperator( | |||
6469 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), | |||
6470 | E->getObjectKind(), ToOperatorLoc, E->getFPFeatures()); | |||
6471 | } | |||
6472 | ||||
6473 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { | |||
6474 | auto Imp = importSeq( | |||
6475 | E->getCond(), E->getQuestionLoc(), E->getLHS(), E->getColonLoc(), | |||
6476 | E->getRHS(), E->getType()); | |||
6477 | if (!Imp) | |||
6478 | return Imp.takeError(); | |||
6479 | ||||
6480 | Expr *ToCond, *ToLHS, *ToRHS; | |||
6481 | SourceLocation ToQuestionLoc, ToColonLoc; | |||
6482 | QualType ToType; | |||
6483 | std::tie(ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType) = *Imp; | |||
6484 | ||||
6485 | return new (Importer.getToContext()) ConditionalOperator( | |||
6486 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, | |||
6487 | E->getValueKind(), E->getObjectKind()); | |||
6488 | } | |||
6489 | ||||
6490 | ExpectedStmt ASTNodeImporter::VisitBinaryConditionalOperator( | |||
6491 | BinaryConditionalOperator *E) { | |||
6492 | auto Imp = importSeq( | |||
6493 | E->getCommon(), E->getOpaqueValue(), E->getCond(), E->getTrueExpr(), | |||
6494 | E->getFalseExpr(), E->getQuestionLoc(), E->getColonLoc(), E->getType()); | |||
6495 | if (!Imp) | |||
6496 | return Imp.takeError(); | |||
6497 | ||||
6498 | Expr *ToCommon, *ToCond, *ToTrueExpr, *ToFalseExpr; | |||
6499 | OpaqueValueExpr *ToOpaqueValue; | |||
6500 | SourceLocation ToQuestionLoc, ToColonLoc; | |||
6501 | QualType ToType; | |||
6502 | std::tie( | |||
6503 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, ToQuestionLoc, | |||
6504 | ToColonLoc, ToType) = *Imp; | |||
6505 | ||||
6506 | return new (Importer.getToContext()) BinaryConditionalOperator( | |||
6507 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, | |||
6508 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), | |||
6509 | E->getObjectKind()); | |||
6510 | } | |||
6511 | ||||
6512 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { | |||
6513 | auto Imp = importSeq( | |||
6514 | E->getBeginLoc(), E->getQueriedTypeSourceInfo(), | |||
6515 | E->getDimensionExpression(), E->getEndLoc(), E->getType()); | |||
6516 | if (!Imp) | |||
6517 | return Imp.takeError(); | |||
6518 | ||||
6519 | SourceLocation ToBeginLoc, ToEndLoc; | |||
6520 | TypeSourceInfo *ToQueriedTypeSourceInfo; | |||
6521 | Expr *ToDimensionExpression; | |||
6522 | QualType ToType; | |||
6523 | std::tie( | |||
6524 | ToBeginLoc, ToQueriedTypeSourceInfo, ToDimensionExpression, ToEndLoc, | |||
6525 | ToType) = *Imp; | |||
6526 | ||||
6527 | return new (Importer.getToContext()) ArrayTypeTraitExpr( | |||
6528 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), | |||
6529 | ToDimensionExpression, ToEndLoc, ToType); | |||
6530 | } | |||
6531 | ||||
6532 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { | |||
6533 | auto Imp = importSeq( | |||
6534 | E->getBeginLoc(), E->getQueriedExpression(), E->getEndLoc(), E->getType()); | |||
6535 | if (!Imp) | |||
6536 | return Imp.takeError(); | |||
6537 | ||||
6538 | SourceLocation ToBeginLoc, ToEndLoc; | |||
6539 | Expr *ToQueriedExpression; | |||
6540 | QualType ToType; | |||
6541 | std::tie(ToBeginLoc, ToQueriedExpression, ToEndLoc, ToType) = *Imp; | |||
6542 | ||||
6543 | return new (Importer.getToContext()) ExpressionTraitExpr( | |||
6544 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), | |||
6545 | ToEndLoc, ToType); | |||
6546 | } | |||
6547 | ||||
6548 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { | |||
6549 | auto Imp = importSeq( | |||
6550 | E->getLocation(), E->getType(), E->getSourceExpr()); | |||
6551 | if (!Imp) | |||
6552 | return Imp.takeError(); | |||
6553 | ||||
6554 | SourceLocation ToLocation; | |||
6555 | QualType ToType; | |||
6556 | Expr *ToSourceExpr; | |||
6557 | std::tie(ToLocation, ToType, ToSourceExpr) = *Imp; | |||
6558 | ||||
6559 | return new (Importer.getToContext()) OpaqueValueExpr( | |||
6560 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); | |||
6561 | } | |||
6562 | ||||
6563 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { | |||
6564 | auto Imp = importSeq( | |||
6565 | E->getLHS(), E->getRHS(), E->getType(), E->getRBracketLoc()); | |||
6566 | if (!Imp) | |||
6567 | return Imp.takeError(); | |||
6568 | ||||
6569 | Expr *ToLHS, *ToRHS; | |||
6570 | SourceLocation ToRBracketLoc; | |||
6571 | QualType ToType; | |||
6572 | std::tie(ToLHS, ToRHS, ToType, ToRBracketLoc) = *Imp; | |||
6573 | ||||
6574 | return new (Importer.getToContext()) ArraySubscriptExpr( | |||
6575 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), | |||
6576 | ToRBracketLoc); | |||
6577 | } | |||
6578 | ||||
6579 | ExpectedStmt | |||
6580 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { | |||
6581 | auto Imp = importSeq( | |||
6582 | E->getLHS(), E->getRHS(), E->getType(), E->getComputationLHSType(), | |||
6583 | E->getComputationResultType(), E->getOperatorLoc()); | |||
6584 | if (!Imp) | |||
6585 | return Imp.takeError(); | |||
6586 | ||||
6587 | Expr *ToLHS, *ToRHS; | |||
6588 | QualType ToType, ToComputationLHSType, ToComputationResultType; | |||
6589 | SourceLocation ToOperatorLoc; | |||
6590 | std::tie(ToLHS, ToRHS, ToType, ToComputationLHSType, ToComputationResultType, | |||
6591 | ToOperatorLoc) = *Imp; | |||
6592 | ||||
6593 | return new (Importer.getToContext()) CompoundAssignOperator( | |||
6594 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), | |||
6595 | E->getObjectKind(), ToComputationLHSType, ToComputationResultType, | |||
6596 | ToOperatorLoc, E->getFPFeatures()); | |||
6597 | } | |||
6598 | ||||
6599 | Expected<CXXCastPath> | |||
6600 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { | |||
6601 | CXXCastPath Path; | |||
6602 | for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) { | |||
6603 | if (auto SpecOrErr = import(*I)) | |||
6604 | Path.push_back(*SpecOrErr); | |||
6605 | else | |||
6606 | return SpecOrErr.takeError(); | |||
6607 | } | |||
6608 | return Path; | |||
6609 | } | |||
6610 | ||||
6611 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { | |||
6612 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
6613 | if (!ToTypeOrErr) | |||
6614 | return ToTypeOrErr.takeError(); | |||
6615 | ||||
6616 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | |||
6617 | if (!ToSubExprOrErr) | |||
6618 | return ToSubExprOrErr.takeError(); | |||
6619 | ||||
6620 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); | |||
6621 | if (!ToBasePathOrErr) | |||
6622 | return ToBasePathOrErr.takeError(); | |||
6623 | ||||
6624 | return ImplicitCastExpr::Create( | |||
6625 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, | |||
6626 | &(*ToBasePathOrErr), E->getValueKind()); | |||
6627 | } | |||
6628 | ||||
6629 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { | |||
6630 | auto Imp1 = importSeq( | |||
6631 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten()); | |||
6632 | if (!Imp1) | |||
6633 | return Imp1.takeError(); | |||
6634 | ||||
6635 | QualType ToType; | |||
6636 | Expr *ToSubExpr; | |||
6637 | TypeSourceInfo *ToTypeInfoAsWritten; | |||
6638 | std::tie(ToType, ToSubExpr, ToTypeInfoAsWritten) = *Imp1; | |||
6639 | ||||
6640 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); | |||
6641 | if (!ToBasePathOrErr) | |||
6642 | return ToBasePathOrErr.takeError(); | |||
6643 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); | |||
6644 | ||||
6645 | switch (E->getStmtClass()) { | |||
6646 | case Stmt::CStyleCastExprClass: { | |||
6647 | auto *CCE = cast<CStyleCastExpr>(E); | |||
6648 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); | |||
6649 | if (!ToLParenLocOrErr) | |||
6650 | return ToLParenLocOrErr.takeError(); | |||
6651 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); | |||
6652 | if (!ToRParenLocOrErr) | |||
6653 | return ToRParenLocOrErr.takeError(); | |||
6654 | return CStyleCastExpr::Create( | |||
6655 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), | |||
6656 | ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr, | |||
6657 | *ToRParenLocOrErr); | |||
6658 | } | |||
6659 | ||||
6660 | case Stmt::CXXFunctionalCastExprClass: { | |||
6661 | auto *FCE = cast<CXXFunctionalCastExpr>(E); | |||
6662 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); | |||
6663 | if (!ToLParenLocOrErr) | |||
6664 | return ToLParenLocOrErr.takeError(); | |||
6665 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); | |||
6666 | if (!ToRParenLocOrErr) | |||
6667 | return ToRParenLocOrErr.takeError(); | |||
6668 | return CXXFunctionalCastExpr::Create( | |||
6669 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, | |||
6670 | E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr, | |||
6671 | *ToRParenLocOrErr); | |||
6672 | } | |||
6673 | ||||
6674 | case Stmt::ObjCBridgedCastExprClass: { | |||
6675 | auto *OCE = cast<ObjCBridgedCastExpr>(E); | |||
6676 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); | |||
6677 | if (!ToLParenLocOrErr) | |||
6678 | return ToLParenLocOrErr.takeError(); | |||
6679 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); | |||
6680 | if (!ToBridgeKeywordLocOrErr) | |||
6681 | return ToBridgeKeywordLocOrErr.takeError(); | |||
6682 | return new (Importer.getToContext()) ObjCBridgedCastExpr( | |||
6683 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), | |||
6684 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); | |||
6685 | } | |||
6686 | default: | |||
6687 | llvm_unreachable("Cast expression of unsupported type!")::llvm::llvm_unreachable_internal("Cast expression of unsupported type!" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 6687); | |||
6688 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
6689 | } | |||
6690 | } | |||
6691 | ||||
6692 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { | |||
6693 | SmallVector<OffsetOfNode, 4> ToNodes; | |||
6694 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { | |||
6695 | const OffsetOfNode &FromNode = E->getComponent(I); | |||
6696 | ||||
6697 | SourceLocation ToBeginLoc, ToEndLoc; | |||
6698 | if (FromNode.getKind() != OffsetOfNode::Base) { | |||
6699 | auto Imp = importSeq(FromNode.getBeginLoc(), FromNode.getEndLoc()); | |||
6700 | if (!Imp) | |||
6701 | return Imp.takeError(); | |||
6702 | std::tie(ToBeginLoc, ToEndLoc) = *Imp; | |||
6703 | } | |||
6704 | ||||
6705 | switch (FromNode.getKind()) { | |||
6706 | case OffsetOfNode::Array: | |||
6707 | ToNodes.push_back( | |||
6708 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); | |||
6709 | break; | |||
6710 | case OffsetOfNode::Base: { | |||
6711 | auto ToBSOrErr = import(FromNode.getBase()); | |||
6712 | if (!ToBSOrErr) | |||
6713 | return ToBSOrErr.takeError(); | |||
6714 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); | |||
6715 | break; | |||
6716 | } | |||
6717 | case OffsetOfNode::Field: { | |||
6718 | auto ToFieldOrErr = import(FromNode.getField()); | |||
6719 | if (!ToFieldOrErr) | |||
6720 | return ToFieldOrErr.takeError(); | |||
6721 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); | |||
6722 | break; | |||
6723 | } | |||
6724 | case OffsetOfNode::Identifier: { | |||
6725 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); | |||
6726 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); | |||
6727 | break; | |||
6728 | } | |||
6729 | } | |||
6730 | } | |||
6731 | ||||
6732 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); | |||
6733 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { | |||
6734 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); | |||
6735 | if (!ToIndexExprOrErr) | |||
6736 | return ToIndexExprOrErr.takeError(); | |||
6737 | ToExprs[I] = *ToIndexExprOrErr; | |||
6738 | } | |||
6739 | ||||
6740 | auto Imp = importSeq( | |||
6741 | E->getType(), E->getTypeSourceInfo(), E->getOperatorLoc(), | |||
6742 | E->getRParenLoc()); | |||
6743 | if (!Imp) | |||
6744 | return Imp.takeError(); | |||
6745 | ||||
6746 | QualType ToType; | |||
6747 | TypeSourceInfo *ToTypeSourceInfo; | |||
6748 | SourceLocation ToOperatorLoc, ToRParenLoc; | |||
6749 | std::tie(ToType, ToTypeSourceInfo, ToOperatorLoc, ToRParenLoc) = *Imp; | |||
6750 | ||||
6751 | return OffsetOfExpr::Create( | |||
6752 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, | |||
6753 | ToExprs, ToRParenLoc); | |||
6754 | } | |||
6755 | ||||
6756 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { | |||
6757 | auto Imp = importSeq( | |||
6758 | E->getType(), E->getOperand(), E->getBeginLoc(), E->getEndLoc()); | |||
6759 | if (!Imp) | |||
6760 | return Imp.takeError(); | |||
6761 | ||||
6762 | QualType ToType; | |||
6763 | Expr *ToOperand; | |||
6764 | SourceLocation ToBeginLoc, ToEndLoc; | |||
6765 | std::tie(ToType, ToOperand, ToBeginLoc, ToEndLoc) = *Imp; | |||
6766 | ||||
6767 | CanThrowResult ToCanThrow; | |||
6768 | if (E->isValueDependent()) | |||
6769 | ToCanThrow = CT_Dependent; | |||
6770 | else | |||
6771 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; | |||
6772 | ||||
6773 | return new (Importer.getToContext()) CXXNoexceptExpr( | |||
6774 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); | |||
6775 | } | |||
6776 | ||||
6777 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { | |||
6778 | auto Imp = importSeq(E->getSubExpr(), E->getType(), E->getThrowLoc()); | |||
6779 | if (!Imp) | |||
6780 | return Imp.takeError(); | |||
6781 | ||||
6782 | Expr *ToSubExpr; | |||
6783 | QualType ToType; | |||
6784 | SourceLocation ToThrowLoc; | |||
6785 | std::tie(ToSubExpr, ToType, ToThrowLoc) = *Imp; | |||
6786 | ||||
6787 | return new (Importer.getToContext()) CXXThrowExpr( | |||
6788 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); | |||
6789 | } | |||
6790 | ||||
6791 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { | |||
6792 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); | |||
6793 | if (!ToUsedLocOrErr) | |||
6794 | return ToUsedLocOrErr.takeError(); | |||
6795 | ||||
6796 | auto ToParamOrErr = import(E->getParam()); | |||
6797 | if (!ToParamOrErr) | |||
6798 | return ToParamOrErr.takeError(); | |||
6799 | ||||
6800 | return CXXDefaultArgExpr::Create( | |||
6801 | Importer.getToContext(), *ToUsedLocOrErr, *ToParamOrErr); | |||
6802 | } | |||
6803 | ||||
6804 | ExpectedStmt | |||
6805 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { | |||
6806 | auto Imp = importSeq( | |||
6807 | E->getType(), E->getTypeSourceInfo(), E->getRParenLoc()); | |||
6808 | if (!Imp) | |||
6809 | return Imp.takeError(); | |||
6810 | ||||
6811 | QualType ToType; | |||
6812 | TypeSourceInfo *ToTypeSourceInfo; | |||
6813 | SourceLocation ToRParenLoc; | |||
6814 | std::tie(ToType, ToTypeSourceInfo, ToRParenLoc) = *Imp; | |||
6815 | ||||
6816 | return new (Importer.getToContext()) CXXScalarValueInitExpr( | |||
6817 | ToType, ToTypeSourceInfo, ToRParenLoc); | |||
6818 | } | |||
6819 | ||||
6820 | ExpectedStmt | |||
6821 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { | |||
6822 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | |||
6823 | if (!ToSubExprOrErr) | |||
6824 | return ToSubExprOrErr.takeError(); | |||
6825 | ||||
6826 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); | |||
6827 | if (!ToDtorOrErr) | |||
6828 | return ToDtorOrErr.takeError(); | |||
6829 | ||||
6830 | ASTContext &ToCtx = Importer.getToContext(); | |||
6831 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); | |||
6832 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); | |||
6833 | } | |||
6834 | ||||
6835 | ExpectedStmt | |||
6836 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { | |||
6837 | auto Imp = importSeq( | |||
6838 | E->getConstructor(), E->getType(), E->getTypeSourceInfo(), | |||
6839 | E->getParenOrBraceRange()); | |||
6840 | if (!Imp) | |||
6841 | return Imp.takeError(); | |||
6842 | ||||
6843 | CXXConstructorDecl *ToConstructor; | |||
6844 | QualType ToType; | |||
6845 | TypeSourceInfo *ToTypeSourceInfo; | |||
6846 | SourceRange ToParenOrBraceRange; | |||
6847 | std::tie(ToConstructor, ToType, ToTypeSourceInfo, ToParenOrBraceRange) = *Imp; | |||
6848 | ||||
6849 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); | |||
6850 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | |||
6851 | return std::move(Err); | |||
6852 | ||||
6853 | return new (Importer.getToContext()) CXXTemporaryObjectExpr( | |||
6854 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, | |||
6855 | ToParenOrBraceRange, E->hadMultipleCandidates(), | |||
6856 | E->isListInitialization(), E->isStdInitListInitialization(), | |||
6857 | E->requiresZeroInitialization()); | |||
6858 | } | |||
6859 | ||||
6860 | ExpectedStmt | |||
6861 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { | |||
6862 | auto Imp = importSeq( | |||
6863 | E->getType(), E->GetTemporaryExpr(), E->getExtendingDecl()); | |||
6864 | if (!Imp) | |||
6865 | return Imp.takeError(); | |||
6866 | ||||
6867 | QualType ToType; | |||
6868 | Expr *ToTemporaryExpr; | |||
6869 | const ValueDecl *ToExtendingDecl; | |||
6870 | std::tie(ToType, ToTemporaryExpr, ToExtendingDecl) = *Imp; | |||
6871 | ||||
6872 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( | |||
6873 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference()); | |||
6874 | ||||
6875 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? | |||
6876 | ToMTE->setExtendingDecl(ToExtendingDecl, E->getManglingNumber()); | |||
6877 | return ToMTE; | |||
6878 | } | |||
6879 | ||||
6880 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { | |||
6881 | auto Imp = importSeq( | |||
6882 | E->getType(), E->getPattern(), E->getEllipsisLoc()); | |||
6883 | if (!Imp) | |||
6884 | return Imp.takeError(); | |||
6885 | ||||
6886 | QualType ToType; | |||
6887 | Expr *ToPattern; | |||
6888 | SourceLocation ToEllipsisLoc; | |||
6889 | std::tie(ToType, ToPattern, ToEllipsisLoc) = *Imp; | |||
6890 | ||||
6891 | return new (Importer.getToContext()) PackExpansionExpr( | |||
6892 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); | |||
6893 | } | |||
6894 | ||||
6895 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { | |||
6896 | auto Imp = importSeq( | |||
6897 | E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc()); | |||
6898 | if (!Imp) | |||
6899 | return Imp.takeError(); | |||
6900 | ||||
6901 | SourceLocation ToOperatorLoc, ToPackLoc, ToRParenLoc; | |||
6902 | NamedDecl *ToPack; | |||
6903 | std::tie(ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc) = *Imp; | |||
6904 | ||||
6905 | Optional<unsigned> Length; | |||
6906 | if (!E->isValueDependent()) | |||
6907 | Length = E->getPackLength(); | |||
6908 | ||||
6909 | SmallVector<TemplateArgument, 8> ToPartialArguments; | |||
6910 | if (E->isPartiallySubstituted()) { | |||
6911 | if (Error Err = ImportTemplateArguments( | |||
6912 | E->getPartialArguments().data(), | |||
6913 | E->getPartialArguments().size(), | |||
6914 | ToPartialArguments)) | |||
6915 | return std::move(Err); | |||
6916 | } | |||
6917 | ||||
6918 | return SizeOfPackExpr::Create( | |||
6919 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, | |||
6920 | Length, ToPartialArguments); | |||
6921 | } | |||
6922 | ||||
6923 | ||||
6924 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { | |||
6925 | auto Imp = importSeq( | |||
6926 | E->getOperatorNew(), E->getOperatorDelete(), E->getTypeIdParens(), | |||
6927 | E->getArraySize(), E->getInitializer(), E->getType(), | |||
6928 | E->getAllocatedTypeSourceInfo(), E->getSourceRange(), | |||
6929 | E->getDirectInitRange()); | |||
6930 | if (!Imp) | |||
6931 | return Imp.takeError(); | |||
6932 | ||||
6933 | FunctionDecl *ToOperatorNew, *ToOperatorDelete; | |||
6934 | SourceRange ToTypeIdParens, ToSourceRange, ToDirectInitRange; | |||
6935 | Expr *ToArraySize, *ToInitializer; | |||
6936 | QualType ToType; | |||
6937 | TypeSourceInfo *ToAllocatedTypeSourceInfo; | |||
6938 | std::tie( | |||
6939 | ToOperatorNew, ToOperatorDelete, ToTypeIdParens, ToArraySize, ToInitializer, | |||
6940 | ToType, ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange) = *Imp; | |||
6941 | ||||
6942 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); | |||
6943 | if (Error Err = | |||
6944 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) | |||
6945 | return std::move(Err); | |||
6946 | ||||
6947 | return new (Importer.getToContext()) CXXNewExpr( | |||
6948 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, | |||
6949 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), | |||
6950 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), | |||
6951 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, | |||
6952 | ToDirectInitRange); | |||
6953 | } | |||
6954 | ||||
6955 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { | |||
6956 | auto Imp = importSeq( | |||
6957 | E->getType(), E->getOperatorDelete(), E->getArgument(), E->getBeginLoc()); | |||
6958 | if (!Imp) | |||
6959 | return Imp.takeError(); | |||
6960 | ||||
6961 | QualType ToType; | |||
6962 | FunctionDecl *ToOperatorDelete; | |||
6963 | Expr *ToArgument; | |||
6964 | SourceLocation ToBeginLoc; | |||
6965 | std::tie(ToType, ToOperatorDelete, ToArgument, ToBeginLoc) = *Imp; | |||
6966 | ||||
6967 | return new (Importer.getToContext()) CXXDeleteExpr( | |||
6968 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), | |||
6969 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, | |||
6970 | ToBeginLoc); | |||
6971 | } | |||
6972 | ||||
6973 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { | |||
6974 | auto Imp = importSeq( | |||
6975 | E->getType(), E->getLocation(), E->getConstructor(), | |||
6976 | E->getParenOrBraceRange()); | |||
6977 | if (!Imp) | |||
6978 | return Imp.takeError(); | |||
6979 | ||||
6980 | QualType ToType; | |||
6981 | SourceLocation ToLocation; | |||
6982 | CXXConstructorDecl *ToConstructor; | |||
6983 | SourceRange ToParenOrBraceRange; | |||
6984 | std::tie(ToType, ToLocation, ToConstructor, ToParenOrBraceRange) = *Imp; | |||
6985 | ||||
6986 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); | |||
6987 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | |||
6988 | return std::move(Err); | |||
6989 | ||||
6990 | return CXXConstructExpr::Create( | |||
6991 | Importer.getToContext(), ToType, ToLocation, ToConstructor, | |||
6992 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), | |||
6993 | E->isListInitialization(), E->isStdInitListInitialization(), | |||
6994 | E->requiresZeroInitialization(), E->getConstructionKind(), | |||
6995 | ToParenOrBraceRange); | |||
6996 | } | |||
6997 | ||||
6998 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { | |||
6999 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | |||
7000 | if (!ToSubExprOrErr) | |||
7001 | return ToSubExprOrErr.takeError(); | |||
7002 | ||||
7003 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); | |||
7004 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) | |||
7005 | return std::move(Err); | |||
7006 | ||||
7007 | return ExprWithCleanups::Create( | |||
7008 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), | |||
7009 | ToObjects); | |||
7010 | } | |||
7011 | ||||
7012 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { | |||
7013 | auto Imp = importSeq( | |||
7014 | E->getCallee(), E->getType(), E->getRParenLoc()); | |||
7015 | if (!Imp) | |||
7016 | return Imp.takeError(); | |||
7017 | ||||
7018 | Expr *ToCallee; | |||
7019 | QualType ToType; | |||
7020 | SourceLocation ToRParenLoc; | |||
7021 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; | |||
7022 | ||||
7023 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); | |||
7024 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | |||
7025 | return std::move(Err); | |||
7026 | ||||
7027 | return new (Importer.getToContext()) CXXMemberCallExpr( | |||
7028 | Importer.getToContext(), ToCallee, ToArgs, ToType, E->getValueKind(), | |||
7029 | ToRParenLoc); | |||
7030 | } | |||
7031 | ||||
7032 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { | |||
7033 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
7034 | if (!ToTypeOrErr) | |||
7035 | return ToTypeOrErr.takeError(); | |||
7036 | ||||
7037 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | |||
7038 | if (!ToLocationOrErr) | |||
7039 | return ToLocationOrErr.takeError(); | |||
7040 | ||||
7041 | return new (Importer.getToContext()) CXXThisExpr( | |||
7042 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); | |||
7043 | } | |||
7044 | ||||
7045 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { | |||
7046 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
7047 | if (!ToTypeOrErr) | |||
7048 | return ToTypeOrErr.takeError(); | |||
7049 | ||||
7050 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | |||
7051 | if (!ToLocationOrErr) | |||
7052 | return ToLocationOrErr.takeError(); | |||
7053 | ||||
7054 | return new (Importer.getToContext()) CXXBoolLiteralExpr( | |||
7055 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); | |||
7056 | } | |||
7057 | ||||
7058 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { | |||
7059 | auto Imp1 = importSeq( | |||
7060 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), | |||
7061 | E->getTemplateKeywordLoc(), E->getMemberDecl(), E->getType()); | |||
7062 | if (!Imp1) | |||
7063 | return Imp1.takeError(); | |||
7064 | ||||
7065 | Expr *ToBase; | |||
7066 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; | |||
7067 | NestedNameSpecifierLoc ToQualifierLoc; | |||
7068 | ValueDecl *ToMemberDecl; | |||
7069 | QualType ToType; | |||
7070 | std::tie( | |||
7071 | ToBase, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, | |||
7072 | ToType) = *Imp1; | |||
7073 | ||||
7074 | auto Imp2 = importSeq( | |||
7075 | E->getFoundDecl().getDecl(), E->getMemberNameInfo().getName(), | |||
7076 | E->getMemberNameInfo().getLoc(), E->getLAngleLoc(), E->getRAngleLoc()); | |||
7077 | if (!Imp2) | |||
7078 | return Imp2.takeError(); | |||
7079 | NamedDecl *ToDecl; | |||
7080 | DeclarationName ToName; | |||
7081 | SourceLocation ToLoc, ToLAngleLoc, ToRAngleLoc; | |||
7082 | std::tie(ToDecl, ToName, ToLoc, ToLAngleLoc, ToRAngleLoc) = *Imp2; | |||
7083 | ||||
7084 | DeclAccessPair ToFoundDecl = | |||
7085 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); | |||
7086 | ||||
7087 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); | |||
7088 | ||||
7089 | if (E->hasExplicitTemplateArgs()) { | |||
7090 | // FIXME: handle template arguments | |||
7091 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | |||
7092 | } | |||
7093 | ||||
7094 | return MemberExpr::Create( | |||
7095 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, | |||
7096 | ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, ToFoundDecl, | |||
7097 | ToMemberNameInfo, nullptr, ToType, E->getValueKind(), E->getObjectKind()); | |||
7098 | } | |||
7099 | ||||
7100 | ExpectedStmt | |||
7101 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { | |||
7102 | auto Imp = importSeq( | |||
7103 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), | |||
7104 | E->getScopeTypeInfo(), E->getColonColonLoc(), E->getTildeLoc()); | |||
7105 | if (!Imp) | |||
7106 | return Imp.takeError(); | |||
7107 | ||||
7108 | Expr *ToBase; | |||
7109 | SourceLocation ToOperatorLoc, ToColonColonLoc, ToTildeLoc; | |||
7110 | NestedNameSpecifierLoc ToQualifierLoc; | |||
7111 | TypeSourceInfo *ToScopeTypeInfo; | |||
7112 | std::tie( | |||
7113 | ToBase, ToOperatorLoc, ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, | |||
7114 | ToTildeLoc) = *Imp; | |||
7115 | ||||
7116 | PseudoDestructorTypeStorage Storage; | |||
7117 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { | |||
7118 | IdentifierInfo *ToII = Importer.Import(FromII); | |||
7119 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); | |||
7120 | if (!ToDestroyedTypeLocOrErr) | |||
7121 | return ToDestroyedTypeLocOrErr.takeError(); | |||
7122 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); | |||
7123 | } else { | |||
7124 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) | |||
7125 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); | |||
7126 | else | |||
7127 | return ToTIOrErr.takeError(); | |||
7128 | } | |||
7129 | ||||
7130 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( | |||
7131 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, | |||
7132 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); | |||
7133 | } | |||
7134 | ||||
7135 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( | |||
7136 | CXXDependentScopeMemberExpr *E) { | |||
7137 | auto Imp = importSeq( | |||
7138 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), | |||
7139 | E->getTemplateKeywordLoc(), E->getFirstQualifierFoundInScope()); | |||
7140 | if (!Imp) | |||
7141 | return Imp.takeError(); | |||
7142 | ||||
7143 | QualType ToType; | |||
7144 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; | |||
7145 | NestedNameSpecifierLoc ToQualifierLoc; | |||
7146 | NamedDecl *ToFirstQualifierFoundInScope; | |||
7147 | std::tie( | |||
7148 | ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, | |||
7149 | ToFirstQualifierFoundInScope) = *Imp; | |||
7150 | ||||
7151 | Expr *ToBase = nullptr; | |||
7152 | if (!E->isImplicitAccess()) { | |||
7153 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) | |||
7154 | ToBase = *ToBaseOrErr; | |||
7155 | else | |||
7156 | return ToBaseOrErr.takeError(); | |||
7157 | } | |||
7158 | ||||
7159 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; | |||
7160 | if (E->hasExplicitTemplateArgs()) { | |||
7161 | if (Error Err = ImportTemplateArgumentListInfo( | |||
7162 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), | |||
7163 | ToTAInfo)) | |||
7164 | return std::move(Err); | |||
7165 | ResInfo = &ToTAInfo; | |||
7166 | } | |||
7167 | ||||
7168 | auto ToMemberNameInfoOrErr = importSeq(E->getMember(), E->getMemberLoc()); | |||
7169 | if (!ToMemberNameInfoOrErr) | |||
7170 | return ToMemberNameInfoOrErr.takeError(); | |||
7171 | DeclarationNameInfo ToMemberNameInfo( | |||
7172 | std::get<0>(*ToMemberNameInfoOrErr), std::get<1>(*ToMemberNameInfoOrErr)); | |||
7173 | // Import additional name location/type info. | |||
7174 | if (Error Err = ImportDeclarationNameLoc( | |||
7175 | E->getMemberNameInfo(), ToMemberNameInfo)) | |||
7176 | return std::move(Err); | |||
7177 | ||||
7178 | return CXXDependentScopeMemberExpr::Create( | |||
7179 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, | |||
7180 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, | |||
7181 | ToMemberNameInfo, ResInfo); | |||
7182 | } | |||
7183 | ||||
7184 | ExpectedStmt | |||
7185 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { | |||
7186 | auto Imp = importSeq( | |||
7187 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDeclName(), | |||
7188 | E->getExprLoc(), E->getLAngleLoc(), E->getRAngleLoc()); | |||
7189 | if (!Imp) | |||
7190 | return Imp.takeError(); | |||
7191 | ||||
7192 | NestedNameSpecifierLoc ToQualifierLoc; | |||
7193 | SourceLocation ToTemplateKeywordLoc, ToExprLoc, ToLAngleLoc, ToRAngleLoc; | |||
7194 | DeclarationName ToDeclName; | |||
7195 | std::tie( | |||
7196 | ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToExprLoc, | |||
7197 | ToLAngleLoc, ToRAngleLoc) = *Imp; | |||
7198 | ||||
7199 | DeclarationNameInfo ToNameInfo(ToDeclName, ToExprLoc); | |||
7200 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | |||
7201 | return std::move(Err); | |||
7202 | ||||
7203 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); | |||
7204 | TemplateArgumentListInfo *ResInfo = nullptr; | |||
7205 | if (E->hasExplicitTemplateArgs()) { | |||
7206 | if (Error Err = | |||
7207 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) | |||
7208 | return std::move(Err); | |||
7209 | ResInfo = &ToTAInfo; | |||
7210 | } | |||
7211 | ||||
7212 | return DependentScopeDeclRefExpr::Create( | |||
7213 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, | |||
7214 | ToNameInfo, ResInfo); | |||
7215 | } | |||
7216 | ||||
7217 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( | |||
7218 | CXXUnresolvedConstructExpr *E) { | |||
7219 | auto Imp = importSeq( | |||
7220 | E->getLParenLoc(), E->getRParenLoc(), E->getTypeSourceInfo()); | |||
7221 | if (!Imp) | |||
7222 | return Imp.takeError(); | |||
7223 | ||||
7224 | SourceLocation ToLParenLoc, ToRParenLoc; | |||
7225 | TypeSourceInfo *ToTypeSourceInfo; | |||
7226 | std::tie(ToLParenLoc, ToRParenLoc, ToTypeSourceInfo) = *Imp; | |||
7227 | ||||
7228 | SmallVector<Expr *, 8> ToArgs(E->arg_size()); | |||
7229 | if (Error Err = | |||
7230 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) | |||
7231 | return std::move(Err); | |||
7232 | ||||
7233 | return CXXUnresolvedConstructExpr::Create( | |||
7234 | Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc, | |||
7235 | llvm::makeArrayRef(ToArgs), ToRParenLoc); | |||
7236 | } | |||
7237 | ||||
7238 | ExpectedStmt | |||
7239 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { | |||
7240 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); | |||
7241 | if (!ToNamingClassOrErr) | |||
7242 | return ToNamingClassOrErr.takeError(); | |||
7243 | ||||
7244 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); | |||
7245 | if (!ToQualifierLocOrErr) | |||
7246 | return ToQualifierLocOrErr.takeError(); | |||
7247 | ||||
7248 | auto ToNameInfoOrErr = importSeq(E->getName(), E->getNameLoc()); | |||
7249 | if (!ToNameInfoOrErr) | |||
7250 | return ToNameInfoOrErr.takeError(); | |||
7251 | DeclarationNameInfo ToNameInfo( | |||
7252 | std::get<0>(*ToNameInfoOrErr), std::get<1>(*ToNameInfoOrErr)); | |||
7253 | // Import additional name location/type info. | |||
7254 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | |||
7255 | return std::move(Err); | |||
7256 | ||||
7257 | UnresolvedSet<8> ToDecls; | |||
7258 | for (auto *D : E->decls()) | |||
7259 | if (auto ToDOrErr = import(D)) | |||
7260 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); | |||
7261 | else | |||
7262 | return ToDOrErr.takeError(); | |||
7263 | ||||
7264 | if (E->hasExplicitTemplateArgs() && E->getTemplateKeywordLoc().isValid()) { | |||
7265 | TemplateArgumentListInfo ToTAInfo; | |||
7266 | if (Error Err = ImportTemplateArgumentListInfo( | |||
7267 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), | |||
7268 | ToTAInfo)) | |||
7269 | return std::move(Err); | |||
7270 | ||||
7271 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); | |||
7272 | if (!ToTemplateKeywordLocOrErr) | |||
7273 | return ToTemplateKeywordLocOrErr.takeError(); | |||
7274 | ||||
7275 | return UnresolvedLookupExpr::Create( | |||
7276 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, | |||
7277 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, | |||
7278 | ToDecls.begin(), ToDecls.end()); | |||
7279 | } | |||
7280 | ||||
7281 | return UnresolvedLookupExpr::Create( | |||
7282 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, | |||
7283 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), | |||
7284 | ToDecls.end()); | |||
7285 | } | |||
7286 | ||||
7287 | ExpectedStmt | |||
7288 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { | |||
7289 | auto Imp1 = importSeq( | |||
7290 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), | |||
7291 | E->getTemplateKeywordLoc()); | |||
7292 | if (!Imp1) | |||
7293 | return Imp1.takeError(); | |||
7294 | ||||
7295 | QualType ToType; | |||
7296 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; | |||
7297 | NestedNameSpecifierLoc ToQualifierLoc; | |||
7298 | std::tie(ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc) = *Imp1; | |||
7299 | ||||
7300 | auto Imp2 = importSeq(E->getName(), E->getNameLoc()); | |||
7301 | if (!Imp2) | |||
7302 | return Imp2.takeError(); | |||
7303 | DeclarationNameInfo ToNameInfo(std::get<0>(*Imp2), std::get<1>(*Imp2)); | |||
7304 | // Import additional name location/type info. | |||
7305 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | |||
7306 | return std::move(Err); | |||
7307 | ||||
7308 | UnresolvedSet<8> ToDecls; | |||
7309 | for (Decl *D : E->decls()) | |||
7310 | if (auto ToDOrErr = import(D)) | |||
7311 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); | |||
7312 | else | |||
7313 | return ToDOrErr.takeError(); | |||
7314 | ||||
7315 | TemplateArgumentListInfo ToTAInfo; | |||
7316 | TemplateArgumentListInfo *ResInfo = nullptr; | |||
7317 | if (E->hasExplicitTemplateArgs()) { | |||
7318 | if (Error Err = | |||
7319 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) | |||
7320 | return std::move(Err); | |||
7321 | ResInfo = &ToTAInfo; | |||
7322 | } | |||
7323 | ||||
7324 | Expr *ToBase = nullptr; | |||
7325 | if (!E->isImplicitAccess()) { | |||
7326 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) | |||
7327 | ToBase = *ToBaseOrErr; | |||
7328 | else | |||
7329 | return ToBaseOrErr.takeError(); | |||
7330 | } | |||
7331 | ||||
7332 | return UnresolvedMemberExpr::Create( | |||
7333 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, | |||
7334 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, | |||
7335 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); | |||
7336 | } | |||
7337 | ||||
7338 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { | |||
7339 | auto Imp = importSeq(E->getCallee(), E->getType(), E->getRParenLoc()); | |||
7340 | if (!Imp) | |||
7341 | return Imp.takeError(); | |||
7342 | ||||
7343 | Expr *ToCallee; | |||
7344 | QualType ToType; | |||
7345 | SourceLocation ToRParenLoc; | |||
7346 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; | |||
7347 | ||||
7348 | unsigned NumArgs = E->getNumArgs(); | |||
7349 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); | |||
7350 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | |||
7351 | return std::move(Err); | |||
7352 | ||||
7353 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { | |||
7354 | return new (Importer.getToContext()) CXXOperatorCallExpr( | |||
7355 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, | |||
7356 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures()); | |||
7357 | } | |||
7358 | ||||
7359 | return new (Importer.getToContext()) CallExpr( | |||
7360 | Importer.getToContext(), ToCallee, ToArgs, ToType, E->getValueKind(), | |||
7361 | ToRParenLoc); | |||
7362 | } | |||
7363 | ||||
7364 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { | |||
7365 | CXXRecordDecl *FromClass = E->getLambdaClass(); | |||
7366 | auto ToClassOrErr = import(FromClass); | |||
7367 | if (!ToClassOrErr) | |||
7368 | return ToClassOrErr.takeError(); | |||
7369 | CXXRecordDecl *ToClass = *ToClassOrErr; | |||
7370 | ||||
7371 | // NOTE: lambda classes are created with BeingDefined flag set up. | |||
7372 | // It means that ImportDefinition doesn't work for them and we should fill it | |||
7373 | // manually. | |||
7374 | if (ToClass->isBeingDefined()) { | |||
7375 | for (auto FromField : FromClass->fields()) { | |||
7376 | auto ToFieldOrErr = import(FromField); | |||
7377 | if (!ToFieldOrErr) | |||
7378 | return ToFieldOrErr.takeError(); | |||
7379 | } | |||
7380 | } | |||
7381 | ||||
7382 | auto ToCallOpOrErr = import(E->getCallOperator()); | |||
7383 | if (!ToCallOpOrErr) | |||
7384 | return ToCallOpOrErr.takeError(); | |||
7385 | ||||
7386 | ToClass->completeDefinition(); | |||
7387 | ||||
7388 | SmallVector<LambdaCapture, 8> ToCaptures; | |||
7389 | ToCaptures.reserve(E->capture_size()); | |||
7390 | for (const auto &FromCapture : E->captures()) { | |||
7391 | if (auto ToCaptureOrErr = import(FromCapture)) | |||
7392 | ToCaptures.push_back(*ToCaptureOrErr); | |||
7393 | else | |||
7394 | return ToCaptureOrErr.takeError(); | |||
7395 | } | |||
7396 | ||||
7397 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); | |||
7398 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) | |||
7399 | return std::move(Err); | |||
7400 | ||||
7401 | auto Imp = importSeq( | |||
7402 | E->getIntroducerRange(), E->getCaptureDefaultLoc(), E->getEndLoc()); | |||
7403 | if (!Imp) | |||
7404 | return Imp.takeError(); | |||
7405 | ||||
7406 | SourceRange ToIntroducerRange; | |||
7407 | SourceLocation ToCaptureDefaultLoc, ToEndLoc; | |||
7408 | std::tie(ToIntroducerRange, ToCaptureDefaultLoc, ToEndLoc) = *Imp; | |||
7409 | ||||
7410 | return LambdaExpr::Create( | |||
7411 | Importer.getToContext(), ToClass, ToIntroducerRange, | |||
7412 | E->getCaptureDefault(), ToCaptureDefaultLoc, ToCaptures, | |||
7413 | E->hasExplicitParameters(), E->hasExplicitResultType(), ToCaptureInits, | |||
7414 | ToEndLoc, E->containsUnexpandedParameterPack()); | |||
7415 | } | |||
7416 | ||||
7417 | ||||
7418 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { | |||
7419 | auto Imp = importSeq(E->getLBraceLoc(), E->getRBraceLoc(), E->getType()); | |||
7420 | if (!Imp) | |||
7421 | return Imp.takeError(); | |||
7422 | ||||
7423 | SourceLocation ToLBraceLoc, ToRBraceLoc; | |||
7424 | QualType ToType; | |||
7425 | std::tie(ToLBraceLoc, ToRBraceLoc, ToType) = *Imp; | |||
7426 | ||||
7427 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); | |||
7428 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) | |||
7429 | return std::move(Err); | |||
7430 | ||||
7431 | ASTContext &ToCtx = Importer.getToContext(); | |||
7432 | InitListExpr *To = new (ToCtx) InitListExpr( | |||
7433 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); | |||
7434 | To->setType(ToType); | |||
7435 | ||||
7436 | if (E->hasArrayFiller()) { | |||
7437 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) | |||
7438 | To->setArrayFiller(*ToFillerOrErr); | |||
7439 | else | |||
7440 | return ToFillerOrErr.takeError(); | |||
7441 | } | |||
7442 | ||||
7443 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { | |||
7444 | if (auto ToFDOrErr = import(FromFD)) | |||
7445 | To->setInitializedFieldInUnion(*ToFDOrErr); | |||
7446 | else | |||
7447 | return ToFDOrErr.takeError(); | |||
7448 | } | |||
7449 | ||||
7450 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { | |||
7451 | if (auto ToSyntFormOrErr = import(SyntForm)) | |||
7452 | To->setSyntacticForm(*ToSyntFormOrErr); | |||
7453 | else | |||
7454 | return ToSyntFormOrErr.takeError(); | |||
7455 | } | |||
7456 | ||||
7457 | // Copy InitListExprBitfields, which are not handled in the ctor of | |||
7458 | // InitListExpr. | |||
7459 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); | |||
7460 | ||||
7461 | return To; | |||
7462 | } | |||
7463 | ||||
7464 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( | |||
7465 | CXXStdInitializerListExpr *E) { | |||
7466 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
7467 | if (!ToTypeOrErr) | |||
7468 | return ToTypeOrErr.takeError(); | |||
7469 | ||||
7470 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | |||
7471 | if (!ToSubExprOrErr) | |||
7472 | return ToSubExprOrErr.takeError(); | |||
7473 | ||||
7474 | return new (Importer.getToContext()) CXXStdInitializerListExpr( | |||
7475 | *ToTypeOrErr, *ToSubExprOrErr); | |||
7476 | } | |||
7477 | ||||
7478 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( | |||
7479 | CXXInheritedCtorInitExpr *E) { | |||
7480 | auto Imp = importSeq(E->getLocation(), E->getType(), E->getConstructor()); | |||
7481 | if (!Imp) | |||
7482 | return Imp.takeError(); | |||
7483 | ||||
7484 | SourceLocation ToLocation; | |||
7485 | QualType ToType; | |||
7486 | CXXConstructorDecl *ToConstructor; | |||
7487 | std::tie(ToLocation, ToType, ToConstructor) = *Imp; | |||
7488 | ||||
7489 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( | |||
7490 | ToLocation, ToType, ToConstructor, E->constructsVBase(), | |||
7491 | E->inheritedFromVBase()); | |||
7492 | } | |||
7493 | ||||
7494 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { | |||
7495 | auto Imp = importSeq(E->getType(), E->getCommonExpr(), E->getSubExpr()); | |||
7496 | if (!Imp) | |||
7497 | return Imp.takeError(); | |||
7498 | ||||
7499 | QualType ToType; | |||
7500 | Expr *ToCommonExpr, *ToSubExpr; | |||
7501 | std::tie(ToType, ToCommonExpr, ToSubExpr) = *Imp; | |||
7502 | ||||
7503 | return new (Importer.getToContext()) ArrayInitLoopExpr( | |||
7504 | ToType, ToCommonExpr, ToSubExpr); | |||
7505 | } | |||
7506 | ||||
7507 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { | |||
7508 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
7509 | if (!ToTypeOrErr) | |||
7510 | return ToTypeOrErr.takeError(); | |||
7511 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); | |||
7512 | } | |||
7513 | ||||
7514 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { | |||
7515 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); | |||
7516 | if (!ToBeginLocOrErr) | |||
7517 | return ToBeginLocOrErr.takeError(); | |||
7518 | ||||
7519 | auto ToFieldOrErr = import(E->getField()); | |||
7520 | if (!ToFieldOrErr) | |||
7521 | return ToFieldOrErr.takeError(); | |||
7522 | ||||
7523 | return CXXDefaultInitExpr::Create( | |||
7524 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr); | |||
7525 | } | |||
7526 | ||||
7527 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { | |||
7528 | auto Imp = importSeq( | |||
7529 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten(), | |||
7530 | E->getOperatorLoc(), E->getRParenLoc(), E->getAngleBrackets()); | |||
7531 | if (!Imp) | |||
7532 | return Imp.takeError(); | |||
7533 | ||||
7534 | QualType ToType; | |||
7535 | Expr *ToSubExpr; | |||
7536 | TypeSourceInfo *ToTypeInfoAsWritten; | |||
7537 | SourceLocation ToOperatorLoc, ToRParenLoc; | |||
7538 | SourceRange ToAngleBrackets; | |||
7539 | std::tie( | |||
7540 | ToType, ToSubExpr, ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, | |||
7541 | ToAngleBrackets) = *Imp; | |||
7542 | ||||
7543 | ExprValueKind VK = E->getValueKind(); | |||
7544 | CastKind CK = E->getCastKind(); | |||
7545 | auto ToBasePathOrErr = ImportCastPath(E); | |||
7546 | if (!ToBasePathOrErr) | |||
7547 | return ToBasePathOrErr.takeError(); | |||
7548 | ||||
7549 | if (isa<CXXStaticCastExpr>(E)) { | |||
7550 | return CXXStaticCastExpr::Create( | |||
7551 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | |||
7552 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | |||
7553 | } else if (isa<CXXDynamicCastExpr>(E)) { | |||
7554 | return CXXDynamicCastExpr::Create( | |||
7555 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | |||
7556 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | |||
7557 | } else if (isa<CXXReinterpretCastExpr>(E)) { | |||
7558 | return CXXReinterpretCastExpr::Create( | |||
7559 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | |||
7560 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | |||
7561 | } else if (isa<CXXConstCastExpr>(E)) { | |||
7562 | return CXXConstCastExpr::Create( | |||
7563 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, | |||
7564 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | |||
7565 | } else { | |||
7566 | llvm_unreachable("Unknown cast type")::llvm::llvm_unreachable_internal("Unknown cast type", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 7566); | |||
7567 | return make_error<ImportError>(); | |||
7568 | } | |||
7569 | } | |||
7570 | ||||
7571 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( | |||
7572 | SubstNonTypeTemplateParmExpr *E) { | |||
7573 | auto Imp = importSeq( | |||
7574 | E->getType(), E->getExprLoc(), E->getParameter(), E->getReplacement()); | |||
7575 | if (!Imp) | |||
7576 | return Imp.takeError(); | |||
7577 | ||||
7578 | QualType ToType; | |||
7579 | SourceLocation ToExprLoc; | |||
7580 | NonTypeTemplateParmDecl *ToParameter; | |||
7581 | Expr *ToReplacement; | |||
7582 | std::tie(ToType, ToExprLoc, ToParameter, ToReplacement) = *Imp; | |||
7583 | ||||
7584 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( | |||
7585 | ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); | |||
7586 | } | |||
7587 | ||||
7588 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { | |||
7589 | auto Imp = importSeq( | |||
7590 | E->getType(), E->getBeginLoc(), E->getEndLoc()); | |||
7591 | if (!Imp) | |||
7592 | return Imp.takeError(); | |||
7593 | ||||
7594 | QualType ToType; | |||
7595 | SourceLocation ToBeginLoc, ToEndLoc; | |||
7596 | std::tie(ToType, ToBeginLoc, ToEndLoc) = *Imp; | |||
7597 | ||||
7598 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); | |||
7599 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) | |||
7600 | return std::move(Err); | |||
7601 | ||||
7602 | // According to Sema::BuildTypeTrait(), if E is value-dependent, | |||
7603 | // Value is always false. | |||
7604 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); | |||
7605 | ||||
7606 | return TypeTraitExpr::Create( | |||
7607 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, | |||
7608 | ToEndLoc, ToValue); | |||
7609 | } | |||
7610 | ||||
7611 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { | |||
7612 | ExpectedType ToTypeOrErr = import(E->getType()); | |||
7613 | if (!ToTypeOrErr) | |||
7614 | return ToTypeOrErr.takeError(); | |||
7615 | ||||
7616 | auto ToSourceRangeOrErr = import(E->getSourceRange()); | |||
7617 | if (!ToSourceRangeOrErr) | |||
7618 | return ToSourceRangeOrErr.takeError(); | |||
7619 | ||||
7620 | if (E->isTypeOperand()) { | |||
7621 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) | |||
7622 | return new (Importer.getToContext()) CXXTypeidExpr( | |||
7623 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); | |||
7624 | else | |||
7625 | return ToTSIOrErr.takeError(); | |||
7626 | } | |||
7627 | ||||
7628 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); | |||
7629 | if (!ToExprOperandOrErr) | |||
7630 | return ToExprOperandOrErr.takeError(); | |||
7631 | ||||
7632 | return new (Importer.getToContext()) CXXTypeidExpr( | |||
7633 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); | |||
7634 | } | |||
7635 | ||||
7636 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, | |||
7637 | CXXMethodDecl *FromMethod) { | |||
7638 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { | |||
7639 | if (auto ImportedOrErr = import(FromOverriddenMethod)) | |||
7640 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( | |||
7641 | (*ImportedOrErr)->getCanonicalDecl())); | |||
7642 | else | |||
7643 | consumeError(ImportedOrErr.takeError()); | |||
7644 | } | |||
7645 | } | |||
7646 | ||||
7647 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, | |||
7648 | ASTContext &FromContext, FileManager &FromFileManager, | |||
7649 | bool MinimalImport) | |||
7650 | : ToContext(ToContext), FromContext(FromContext), | |||
7651 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), | |||
7652 | Minimal(MinimalImport) { | |||
7653 | ImportedDecls[FromContext.getTranslationUnitDecl()] | |||
7654 | = ToContext.getTranslationUnitDecl(); | |||
7655 | } | |||
7656 | ||||
7657 | ASTImporter::~ASTImporter() = default; | |||
7658 | ||||
7659 | QualType ASTImporter::Import(QualType FromT) { | |||
7660 | if (FromT.isNull()) | |||
7661 | return {}; | |||
7662 | ||||
7663 | const Type *FromTy = FromT.getTypePtr(); | |||
7664 | ||||
7665 | // Check whether we've already imported this type. | |||
7666 | llvm::DenseMap<const Type *, const Type *>::iterator Pos | |||
7667 | = ImportedTypes.find(FromTy); | |||
7668 | if (Pos != ImportedTypes.end()) | |||
7669 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); | |||
7670 | ||||
7671 | // Import the type | |||
7672 | ASTNodeImporter Importer(*this); | |||
7673 | ExpectedType ToTOrErr = Importer.Visit(FromTy); | |||
7674 | if (!ToTOrErr) { | |||
7675 | llvm::consumeError(ToTOrErr.takeError()); | |||
7676 | return {}; | |||
7677 | } | |||
7678 | ||||
7679 | // Record the imported type. | |||
7680 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); | |||
7681 | ||||
7682 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); | |||
7683 | } | |||
7684 | ||||
7685 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { | |||
7686 | if (!FromTSI) | |||
7687 | return FromTSI; | |||
7688 | ||||
7689 | // FIXME: For now we just create a "trivial" type source info based | |||
7690 | // on the type and a single location. Implement a real version of this. | |||
7691 | QualType T = Import(FromTSI->getType()); | |||
7692 | if (T.isNull()) | |||
7693 | return nullptr; | |||
7694 | ||||
7695 | return ToContext.getTrivialTypeSourceInfo( | |||
7696 | T, Import(FromTSI->getTypeLoc().getBeginLoc())); | |||
7697 | } | |||
7698 | ||||
7699 | Attr *ASTImporter::Import(const Attr *FromAttr) { | |||
7700 | Attr *ToAttr = FromAttr->clone(ToContext); | |||
7701 | ToAttr->setRange(Import(FromAttr->getRange())); | |||
7702 | return ToAttr; | |||
7703 | } | |||
7704 | ||||
7705 | Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) { | |||
7706 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); | |||
7707 | if (Pos != ImportedDecls.end()) { | |||
7708 | Decl *ToD = Pos->second; | |||
7709 | // FIXME: move this call to ImportDeclParts(). | |||
7710 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD)) | |||
7711 | llvm::consumeError(std::move(Err)); | |||
7712 | return ToD; | |||
7713 | } else { | |||
7714 | return nullptr; | |||
7715 | } | |||
7716 | } | |||
7717 | ||||
7718 | Decl *ASTImporter::Import(Decl *FromD) { | |||
7719 | if (!FromD) | |||
7720 | return nullptr; | |||
7721 | ||||
7722 | ASTNodeImporter Importer(*this); | |||
7723 | ||||
7724 | // Check whether we've already imported this declaration. | |||
7725 | Decl *ToD = GetAlreadyImportedOrNull(FromD); | |||
7726 | if (ToD) { | |||
7727 | // If FromD has some updated flags after last import, apply it | |||
7728 | updateFlags(FromD, ToD); | |||
7729 | return ToD; | |||
7730 | } | |||
7731 | ||||
7732 | // Import the type. | |||
7733 | ExpectedDecl ToDOrErr = Importer.Visit(FromD); | |||
7734 | if (!ToDOrErr) { | |||
7735 | llvm::consumeError(ToDOrErr.takeError()); | |||
7736 | return nullptr; | |||
7737 | } | |||
7738 | ToD = *ToDOrErr; | |||
7739 | ||||
7740 | // Notify subclasses. | |||
7741 | Imported(FromD, ToD); | |||
7742 | ||||
7743 | updateFlags(FromD, ToD); | |||
7744 | return ToD; | |||
7745 | } | |||
7746 | ||||
7747 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { | |||
7748 | if (!FromDC) | |||
7749 | return FromDC; | |||
7750 | ||||
7751 | auto *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); | |||
7752 | if (!ToDC) | |||
7753 | return nullptr; | |||
7754 | ||||
7755 | // When we're using a record/enum/Objective-C class/protocol as a context, we | |||
7756 | // need it to have a definition. | |||
7757 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { | |||
7758 | auto *FromRecord = cast<RecordDecl>(FromDC); | |||
7759 | if (ToRecord->isCompleteDefinition()) { | |||
7760 | // Do nothing. | |||
7761 | } else if (FromRecord->isCompleteDefinition()) { | |||
7762 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | |||
7763 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) | |||
7764 | return std::move(Err); | |||
7765 | } else { | |||
7766 | CompleteDecl(ToRecord); | |||
7767 | } | |||
7768 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { | |||
7769 | auto *FromEnum = cast<EnumDecl>(FromDC); | |||
7770 | if (ToEnum->isCompleteDefinition()) { | |||
7771 | // Do nothing. | |||
7772 | } else if (FromEnum->isCompleteDefinition()) { | |||
7773 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | |||
7774 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) | |||
7775 | return std::move(Err); | |||
7776 | } else { | |||
7777 | CompleteDecl(ToEnum); | |||
7778 | } | |||
7779 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { | |||
7780 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); | |||
7781 | if (ToClass->getDefinition()) { | |||
7782 | // Do nothing. | |||
7783 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { | |||
7784 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | |||
7785 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) | |||
7786 | return std::move(Err); | |||
7787 | } else { | |||
7788 | CompleteDecl(ToClass); | |||
7789 | } | |||
7790 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { | |||
7791 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); | |||
7792 | if (ToProto->getDefinition()) { | |||
7793 | // Do nothing. | |||
7794 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { | |||
7795 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | |||
7796 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) | |||
7797 | return std::move(Err); | |||
7798 | } else { | |||
7799 | CompleteDecl(ToProto); | |||
7800 | } | |||
7801 | } | |||
7802 | ||||
7803 | return ToDC; | |||
7804 | } | |||
7805 | ||||
7806 | Expr *ASTImporter::Import(Expr *FromE) { | |||
7807 | if (!FromE) | |||
7808 | return nullptr; | |||
7809 | ||||
7810 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); | |||
7811 | } | |||
7812 | ||||
7813 | Stmt *ASTImporter::Import(Stmt *FromS) { | |||
7814 | if (!FromS) | |||
7815 | return nullptr; | |||
7816 | ||||
7817 | // Check whether we've already imported this declaration. | |||
7818 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); | |||
7819 | if (Pos != ImportedStmts.end()) | |||
7820 | return Pos->second; | |||
7821 | ||||
7822 | // Import the statement. | |||
7823 | ASTNodeImporter Importer(*this); | |||
7824 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); | |||
7825 | if (!ToSOrErr) { | |||
7826 | llvm::consumeError(ToSOrErr.takeError()); | |||
7827 | return nullptr; | |||
7828 | } | |||
7829 | ||||
7830 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { | |||
7831 | auto *FromE = cast<Expr>(FromS); | |||
7832 | // Copy ExprBitfields, which may not be handled in Expr subclasses | |||
7833 | // constructors. | |||
7834 | ToE->setValueKind(FromE->getValueKind()); | |||
7835 | ToE->setObjectKind(FromE->getObjectKind()); | |||
7836 | ToE->setTypeDependent(FromE->isTypeDependent()); | |||
7837 | ToE->setValueDependent(FromE->isValueDependent()); | |||
7838 | ToE->setInstantiationDependent(FromE->isInstantiationDependent()); | |||
7839 | ToE->setContainsUnexpandedParameterPack( | |||
7840 | FromE->containsUnexpandedParameterPack()); | |||
7841 | } | |||
7842 | ||||
7843 | // Record the imported declaration. | |||
7844 | ImportedStmts[FromS] = *ToSOrErr; | |||
7845 | return *ToSOrErr; | |||
7846 | } | |||
7847 | ||||
7848 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { | |||
7849 | if (!FromNNS) | |||
7850 | return nullptr; | |||
7851 | ||||
7852 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); | |||
7853 | ||||
7854 | switch (FromNNS->getKind()) { | |||
7855 | case NestedNameSpecifier::Identifier: | |||
7856 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { | |||
7857 | return NestedNameSpecifier::Create(ToContext, prefix, II); | |||
7858 | } | |||
7859 | return nullptr; | |||
7860 | ||||
7861 | case NestedNameSpecifier::Namespace: | |||
7862 | if (auto *NS = | |||
7863 | cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { | |||
7864 | return NestedNameSpecifier::Create(ToContext, prefix, NS); | |||
7865 | } | |||
7866 | return nullptr; | |||
7867 | ||||
7868 | case NestedNameSpecifier::NamespaceAlias: | |||
7869 | if (auto *NSAD = | |||
7870 | cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { | |||
7871 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); | |||
7872 | } | |||
7873 | return nullptr; | |||
7874 | ||||
7875 | case NestedNameSpecifier::Global: | |||
7876 | return NestedNameSpecifier::GlobalSpecifier(ToContext); | |||
7877 | ||||
7878 | case NestedNameSpecifier::Super: | |||
7879 | if (auto *RD = | |||
7880 | cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) { | |||
7881 | return NestedNameSpecifier::SuperSpecifier(ToContext, RD); | |||
7882 | } | |||
7883 | return nullptr; | |||
7884 | ||||
7885 | case NestedNameSpecifier::TypeSpec: | |||
7886 | case NestedNameSpecifier::TypeSpecWithTemplate: { | |||
7887 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); | |||
7888 | if (!T.isNull()) { | |||
7889 | bool bTemplate = FromNNS->getKind() == | |||
7890 | NestedNameSpecifier::TypeSpecWithTemplate; | |||
7891 | return NestedNameSpecifier::Create(ToContext, prefix, | |||
7892 | bTemplate, T.getTypePtr()); | |||
7893 | } | |||
7894 | } | |||
7895 | return nullptr; | |||
7896 | } | |||
7897 | ||||
7898 | llvm_unreachable("Invalid nested name specifier kind")::llvm::llvm_unreachable_internal("Invalid nested name specifier kind" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 7898); | |||
7899 | } | |||
7900 | ||||
7901 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { | |||
7902 | // Copied from NestedNameSpecifier mostly. | |||
7903 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; | |||
7904 | NestedNameSpecifierLoc NNS = FromNNS; | |||
7905 | ||||
7906 | // Push each of the nested-name-specifiers's onto a stack for | |||
7907 | // serialization in reverse order. | |||
7908 | while (NNS) { | |||
7909 | NestedNames.push_back(NNS); | |||
7910 | NNS = NNS.getPrefix(); | |||
7911 | } | |||
7912 | ||||
7913 | NestedNameSpecifierLocBuilder Builder; | |||
7914 | ||||
7915 | while (!NestedNames.empty()) { | |||
7916 | NNS = NestedNames.pop_back_val(); | |||
7917 | NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier()); | |||
7918 | if (!Spec) | |||
7919 | return NestedNameSpecifierLoc(); | |||
7920 | ||||
7921 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); | |||
7922 | switch (Kind) { | |||
7923 | case NestedNameSpecifier::Identifier: | |||
7924 | Builder.Extend(getToContext(), | |||
7925 | Spec->getAsIdentifier(), | |||
7926 | Import(NNS.getLocalBeginLoc()), | |||
7927 | Import(NNS.getLocalEndLoc())); | |||
7928 | break; | |||
7929 | ||||
7930 | case NestedNameSpecifier::Namespace: | |||
7931 | Builder.Extend(getToContext(), | |||
7932 | Spec->getAsNamespace(), | |||
7933 | Import(NNS.getLocalBeginLoc()), | |||
7934 | Import(NNS.getLocalEndLoc())); | |||
7935 | break; | |||
7936 | ||||
7937 | case NestedNameSpecifier::NamespaceAlias: | |||
7938 | Builder.Extend(getToContext(), | |||
7939 | Spec->getAsNamespaceAlias(), | |||
7940 | Import(NNS.getLocalBeginLoc()), | |||
7941 | Import(NNS.getLocalEndLoc())); | |||
7942 | break; | |||
7943 | ||||
7944 | case NestedNameSpecifier::TypeSpec: | |||
7945 | case NestedNameSpecifier::TypeSpecWithTemplate: { | |||
7946 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( | |||
7947 | QualType(Spec->getAsType(), 0)); | |||
7948 | Builder.Extend(getToContext(), | |||
7949 | Import(NNS.getLocalBeginLoc()), | |||
7950 | TSI->getTypeLoc(), | |||
7951 | Import(NNS.getLocalEndLoc())); | |||
7952 | break; | |||
7953 | } | |||
7954 | ||||
7955 | case NestedNameSpecifier::Global: | |||
7956 | Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc())); | |||
7957 | break; | |||
7958 | ||||
7959 | case NestedNameSpecifier::Super: { | |||
7960 | SourceRange ToRange = Import(NNS.getSourceRange()); | |||
7961 | Builder.MakeSuper(getToContext(), | |||
7962 | Spec->getAsRecordDecl(), | |||
7963 | ToRange.getBegin(), | |||
7964 | ToRange.getEnd()); | |||
7965 | } | |||
7966 | } | |||
7967 | } | |||
7968 | ||||
7969 | return Builder.getWithLocInContext(getToContext()); | |||
7970 | } | |||
7971 | ||||
7972 | TemplateName ASTImporter::Import(TemplateName From) { | |||
7973 | switch (From.getKind()) { | |||
7974 | case TemplateName::Template: | |||
7975 | if (auto *ToTemplate = | |||
7976 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) | |||
7977 | return TemplateName(ToTemplate); | |||
7978 | ||||
7979 | return {}; | |||
7980 | ||||
7981 | case TemplateName::OverloadedTemplate: { | |||
7982 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); | |||
7983 | UnresolvedSet<2> ToTemplates; | |||
7984 | for (auto *I : *FromStorage) { | |||
7985 | if (auto *To = cast_or_null<NamedDecl>(Import(I))) | |||
7986 | ToTemplates.addDecl(To); | |||
7987 | else | |||
7988 | return {}; | |||
7989 | } | |||
7990 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), | |||
7991 | ToTemplates.end()); | |||
7992 | } | |||
7993 | ||||
7994 | case TemplateName::QualifiedTemplate: { | |||
7995 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); | |||
7996 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); | |||
7997 | if (!Qualifier) | |||
7998 | return {}; | |||
7999 | ||||
8000 | if (auto *ToTemplate = | |||
8001 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) | |||
8002 | return ToContext.getQualifiedTemplateName(Qualifier, | |||
8003 | QTN->hasTemplateKeyword(), | |||
8004 | ToTemplate); | |||
8005 | ||||
8006 | return {}; | |||
8007 | } | |||
8008 | ||||
8009 | case TemplateName::DependentTemplate: { | |||
8010 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); | |||
8011 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); | |||
8012 | if (!Qualifier) | |||
8013 | return {}; | |||
8014 | ||||
8015 | if (DTN->isIdentifier()) { | |||
8016 | return ToContext.getDependentTemplateName(Qualifier, | |||
8017 | Import(DTN->getIdentifier())); | |||
8018 | } | |||
8019 | ||||
8020 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); | |||
8021 | } | |||
8022 | ||||
8023 | case TemplateName::SubstTemplateTemplateParm: { | |||
8024 | SubstTemplateTemplateParmStorage *subst | |||
8025 | = From.getAsSubstTemplateTemplateParm(); | |||
8026 | auto *param = | |||
8027 | cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); | |||
8028 | if (!param) | |||
8029 | return {}; | |||
8030 | ||||
8031 | TemplateName replacement = Import(subst->getReplacement()); | |||
8032 | if (replacement.isNull()) | |||
8033 | return {}; | |||
8034 | ||||
8035 | return ToContext.getSubstTemplateTemplateParm(param, replacement); | |||
8036 | } | |||
8037 | ||||
8038 | case TemplateName::SubstTemplateTemplateParmPack: { | |||
8039 | SubstTemplateTemplateParmPackStorage *SubstPack | |||
8040 | = From.getAsSubstTemplateTemplateParmPack(); | |||
8041 | auto *Param = | |||
8042 | cast_or_null<TemplateTemplateParmDecl>( | |||
8043 | Import(SubstPack->getParameterPack())); | |||
8044 | if (!Param) | |||
8045 | return {}; | |||
8046 | ||||
8047 | ASTNodeImporter Importer(*this); | |||
8048 | Expected<TemplateArgument> ArgPack | |||
8049 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); | |||
8050 | if (!ArgPack) { | |||
8051 | llvm::consumeError(ArgPack.takeError()); | |||
8052 | return {}; | |||
8053 | } | |||
8054 | ||||
8055 | return ToContext.getSubstTemplateTemplateParmPack(Param, *ArgPack); | |||
8056 | } | |||
8057 | } | |||
8058 | ||||
8059 | llvm_unreachable("Invalid template name kind")::llvm::llvm_unreachable_internal("Invalid template name kind" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 8059); | |||
8060 | } | |||
8061 | ||||
8062 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { | |||
8063 | if (FromLoc.isInvalid()) | |||
8064 | return {}; | |||
8065 | ||||
8066 | SourceManager &FromSM = FromContext.getSourceManager(); | |||
8067 | ||||
8068 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); | |||
8069 | FileID ToFileID = Import(Decomposed.first); | |||
8070 | if (ToFileID.isInvalid()) | |||
8071 | return {}; | |||
8072 | SourceManager &ToSM = ToContext.getSourceManager(); | |||
8073 | return ToSM.getComposedLoc(ToFileID, Decomposed.second); | |||
8074 | } | |||
8075 | ||||
8076 | SourceRange ASTImporter::Import(SourceRange FromRange) { | |||
8077 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); | |||
8078 | } | |||
8079 | ||||
8080 | FileID ASTImporter::Import(FileID FromID) { | |||
8081 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); | |||
8082 | if (Pos != ImportedFileIDs.end()) | |||
8083 | return Pos->second; | |||
8084 | ||||
8085 | SourceManager &FromSM = FromContext.getSourceManager(); | |||
8086 | SourceManager &ToSM = ToContext.getSourceManager(); | |||
8087 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); | |||
8088 | ||||
8089 | // Map the FromID to the "to" source manager. | |||
8090 | FileID ToID; | |||
8091 | if (FromSLoc.isExpansion()) { | |||
8092 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); | |||
8093 | SourceLocation ToSpLoc = Import(FromEx.getSpellingLoc()); | |||
8094 | SourceLocation ToExLocS = Import(FromEx.getExpansionLocStart()); | |||
8095 | unsigned TokenLen = FromSM.getFileIDSize(FromID); | |||
8096 | SourceLocation MLoc; | |||
8097 | if (FromEx.isMacroArgExpansion()) { | |||
8098 | MLoc = ToSM.createMacroArgExpansionLoc(ToSpLoc, ToExLocS, TokenLen); | |||
8099 | } else { | |||
8100 | SourceLocation ToExLocE = Import(FromEx.getExpansionLocEnd()); | |||
8101 | MLoc = ToSM.createExpansionLoc(ToSpLoc, ToExLocS, ToExLocE, TokenLen, | |||
8102 | FromEx.isExpansionTokenRange()); | |||
8103 | } | |||
8104 | ToID = ToSM.getFileID(MLoc); | |||
8105 | } else { | |||
8106 | // Include location of this file. | |||
8107 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); | |||
8108 | ||||
8109 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); | |||
8110 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { | |||
8111 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the | |||
8112 | // disk again | |||
8113 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather | |||
8114 | // than mmap the files several times. | |||
8115 | const FileEntry *Entry = | |||
8116 | ToFileManager.getFile(Cache->OrigEntry->getName()); | |||
8117 | if (!Entry) | |||
8118 | return {}; | |||
8119 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, | |||
8120 | FromSLoc.getFile().getFileCharacteristic()); | |||
8121 | } else { | |||
8122 | // FIXME: We want to re-use the existing MemoryBuffer! | |||
8123 | const llvm::MemoryBuffer *FromBuf = | |||
8124 | Cache->getBuffer(FromContext.getDiagnostics(), FromSM); | |||
8125 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = | |||
8126 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), | |||
8127 | FromBuf->getBufferIdentifier()); | |||
8128 | ToID = ToSM.createFileID(std::move(ToBuf), | |||
8129 | FromSLoc.getFile().getFileCharacteristic()); | |||
8130 | } | |||
8131 | } | |||
8132 | ||||
8133 | ImportedFileIDs[FromID] = ToID; | |||
8134 | return ToID; | |||
8135 | } | |||
8136 | ||||
8137 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { | |||
8138 | Expr *ToExpr = Import(From->getInit()); | |||
8139 | if (!ToExpr && From->getInit()) | |||
8140 | return nullptr; | |||
8141 | ||||
8142 | if (From->isBaseInitializer()) { | |||
8143 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); | |||
8144 | if (!ToTInfo && From->getTypeSourceInfo()) | |||
8145 | return nullptr; | |||
8146 | ||||
8147 | return new (ToContext) CXXCtorInitializer( | |||
8148 | ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()), | |||
8149 | ToExpr, Import(From->getRParenLoc()), | |||
8150 | From->isPackExpansion() ? Import(From->getEllipsisLoc()) | |||
8151 | : SourceLocation()); | |||
8152 | } else if (From->isMemberInitializer()) { | |||
8153 | auto *ToField = cast_or_null<FieldDecl>(Import(From->getMember())); | |||
8154 | if (!ToField && From->getMember()) | |||
8155 | return nullptr; | |||
8156 | ||||
8157 | return new (ToContext) CXXCtorInitializer( | |||
8158 | ToContext, ToField, Import(From->getMemberLocation()), | |||
8159 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); | |||
8160 | } else if (From->isIndirectMemberInitializer()) { | |||
8161 | auto *ToIField = cast_or_null<IndirectFieldDecl>( | |||
8162 | Import(From->getIndirectMember())); | |||
8163 | if (!ToIField && From->getIndirectMember()) | |||
8164 | return nullptr; | |||
8165 | ||||
8166 | return new (ToContext) CXXCtorInitializer( | |||
8167 | ToContext, ToIField, Import(From->getMemberLocation()), | |||
8168 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); | |||
8169 | } else if (From->isDelegatingInitializer()) { | |||
8170 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); | |||
8171 | if (!ToTInfo && From->getTypeSourceInfo()) | |||
8172 | return nullptr; | |||
8173 | ||||
8174 | return new (ToContext) | |||
8175 | CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()), | |||
8176 | ToExpr, Import(From->getRParenLoc())); | |||
8177 | } else { | |||
8178 | return nullptr; | |||
8179 | } | |||
8180 | } | |||
8181 | ||||
8182 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { | |||
8183 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); | |||
8184 | if (Pos != ImportedCXXBaseSpecifiers.end()) | |||
8185 | return Pos->second; | |||
8186 | ||||
8187 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( | |||
8188 | Import(BaseSpec->getSourceRange()), | |||
8189 | BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), | |||
8190 | BaseSpec->getAccessSpecifierAsWritten(), | |||
8191 | Import(BaseSpec->getTypeSourceInfo()), | |||
8192 | Import(BaseSpec->getEllipsisLoc())); | |||
8193 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; | |||
8194 | return Imported; | |||
8195 | } | |||
8196 | ||||
8197 | Error ASTImporter::ImportDefinition_New(Decl *From) { | |||
8198 | Decl *To = Import(From); | |||
8199 | if (!To) | |||
8200 | return llvm::make_error<ImportError>(); | |||
8201 | ||||
8202 | if (auto *FromDC = cast<DeclContext>(From)) { | |||
8203 | ASTNodeImporter Importer(*this); | |||
8204 | ||||
8205 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { | |||
8206 | if (!ToRecord->getDefinition()) { | |||
8207 | return Importer.ImportDefinition( | |||
8208 | cast<RecordDecl>(FromDC), ToRecord, | |||
8209 | ASTNodeImporter::IDK_Everything); | |||
8210 | } | |||
8211 | } | |||
8212 | ||||
8213 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { | |||
8214 | if (!ToEnum->getDefinition()) { | |||
8215 | return Importer.ImportDefinition( | |||
8216 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); | |||
8217 | } | |||
8218 | } | |||
8219 | ||||
8220 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { | |||
8221 | if (!ToIFace->getDefinition()) { | |||
8222 | return Importer.ImportDefinition( | |||
8223 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, | |||
8224 | ASTNodeImporter::IDK_Everything); | |||
8225 | } | |||
8226 | } | |||
8227 | ||||
8228 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { | |||
8229 | if (!ToProto->getDefinition()) { | |||
8230 | return Importer.ImportDefinition( | |||
8231 | cast<ObjCProtocolDecl>(FromDC), ToProto, | |||
8232 | ASTNodeImporter::IDK_Everything); | |||
8233 | } | |||
8234 | } | |||
8235 | ||||
8236 | return Importer.ImportDeclContext(FromDC, true); | |||
8237 | } | |||
8238 | ||||
8239 | return Error::success(); | |||
8240 | } | |||
8241 | ||||
8242 | void ASTImporter::ImportDefinition(Decl *From) { | |||
8243 | Error Err = ImportDefinition_New(From); | |||
8244 | llvm::consumeError(std::move(Err)); | |||
8245 | } | |||
8246 | ||||
8247 | DeclarationName ASTImporter::Import(DeclarationName FromName) { | |||
8248 | if (!FromName) | |||
8249 | return {}; | |||
8250 | ||||
8251 | switch (FromName.getNameKind()) { | |||
8252 | case DeclarationName::Identifier: | |||
8253 | return Import(FromName.getAsIdentifierInfo()); | |||
8254 | ||||
8255 | case DeclarationName::ObjCZeroArgSelector: | |||
8256 | case DeclarationName::ObjCOneArgSelector: | |||
8257 | case DeclarationName::ObjCMultiArgSelector: | |||
8258 | return Import(FromName.getObjCSelector()); | |||
8259 | ||||
8260 | case DeclarationName::CXXConstructorName: { | |||
8261 | QualType T = Import(FromName.getCXXNameType()); | |||
8262 | if (T.isNull()) | |||
8263 | return {}; | |||
8264 | ||||
8265 | return ToContext.DeclarationNames.getCXXConstructorName( | |||
8266 | ToContext.getCanonicalType(T)); | |||
8267 | } | |||
8268 | ||||
8269 | case DeclarationName::CXXDestructorName: { | |||
8270 | QualType T = Import(FromName.getCXXNameType()); | |||
8271 | if (T.isNull()) | |||
8272 | return {}; | |||
8273 | ||||
8274 | return ToContext.DeclarationNames.getCXXDestructorName( | |||
8275 | ToContext.getCanonicalType(T)); | |||
8276 | } | |||
8277 | ||||
8278 | case DeclarationName::CXXDeductionGuideName: { | |||
8279 | auto *Template = cast_or_null<TemplateDecl>( | |||
8280 | Import(FromName.getCXXDeductionGuideTemplate())); | |||
8281 | if (!Template) | |||
8282 | return {}; | |||
8283 | return ToContext.DeclarationNames.getCXXDeductionGuideName(Template); | |||
8284 | } | |||
8285 | ||||
8286 | case DeclarationName::CXXConversionFunctionName: { | |||
8287 | QualType T = Import(FromName.getCXXNameType()); | |||
8288 | if (T.isNull()) | |||
8289 | return {}; | |||
8290 | ||||
8291 | return ToContext.DeclarationNames.getCXXConversionFunctionName( | |||
8292 | ToContext.getCanonicalType(T)); | |||
8293 | } | |||
8294 | ||||
8295 | case DeclarationName::CXXOperatorName: | |||
8296 | return ToContext.DeclarationNames.getCXXOperatorName( | |||
8297 | FromName.getCXXOverloadedOperator()); | |||
8298 | ||||
8299 | case DeclarationName::CXXLiteralOperatorName: | |||
8300 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( | |||
8301 | Import(FromName.getCXXLiteralIdentifier())); | |||
8302 | ||||
8303 | case DeclarationName::CXXUsingDirective: | |||
8304 | // FIXME: STATICS! | |||
8305 | return DeclarationName::getUsingDirectiveName(); | |||
8306 | } | |||
8307 | ||||
8308 | llvm_unreachable("Invalid DeclarationName Kind!")::llvm::llvm_unreachable_internal("Invalid DeclarationName Kind!" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 8308); | |||
8309 | } | |||
8310 | ||||
8311 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { | |||
8312 | if (!FromId) | |||
8313 | return nullptr; | |||
8314 | ||||
8315 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); | |||
8316 | ||||
8317 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) | |||
8318 | ToId->setBuiltinID(FromId->getBuiltinID()); | |||
8319 | ||||
8320 | return ToId; | |||
8321 | } | |||
8322 | ||||
8323 | Selector ASTImporter::Import(Selector FromSel) { | |||
8324 | if (FromSel.isNull()) | |||
8325 | return {}; | |||
8326 | ||||
8327 | SmallVector<IdentifierInfo *, 4> Idents; | |||
8328 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); | |||
8329 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) | |||
8330 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); | |||
8331 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); | |||
8332 | } | |||
8333 | ||||
8334 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, | |||
8335 | DeclContext *DC, | |||
8336 | unsigned IDNS, | |||
8337 | NamedDecl **Decls, | |||
8338 | unsigned NumDecls) { | |||
8339 | return Name; | |||
8340 | } | |||
8341 | ||||
8342 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { | |||
8343 | if (LastDiagFromFrom) | |||
8344 | ToContext.getDiagnostics().notePriorDiagnosticFrom( | |||
8345 | FromContext.getDiagnostics()); | |||
8346 | LastDiagFromFrom = false; | |||
8347 | return ToContext.getDiagnostics().Report(Loc, DiagID); | |||
8348 | } | |||
8349 | ||||
8350 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { | |||
8351 | if (!LastDiagFromFrom) | |||
8352 | FromContext.getDiagnostics().notePriorDiagnosticFrom( | |||
8353 | ToContext.getDiagnostics()); | |||
8354 | LastDiagFromFrom = true; | |||
8355 | return FromContext.getDiagnostics().Report(Loc, DiagID); | |||
8356 | } | |||
8357 | ||||
8358 | void ASTImporter::CompleteDecl (Decl *D) { | |||
8359 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { | |||
8360 | if (!ID->getDefinition()) | |||
8361 | ID->startDefinition(); | |||
8362 | } | |||
8363 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { | |||
8364 | if (!PD->getDefinition()) | |||
8365 | PD->startDefinition(); | |||
8366 | } | |||
8367 | else if (auto *TD = dyn_cast<TagDecl>(D)) { | |||
8368 | if (!TD->getDefinition() && !TD->isBeingDefined()) { | |||
8369 | TD->startDefinition(); | |||
8370 | TD->setCompleteDefinition(true); | |||
8371 | } | |||
8372 | } | |||
8373 | else { | |||
8374 | assert(0 && "CompleteDecl called on a Decl that can't be completed")((0 && "CompleteDecl called on a Decl that can't be completed" ) ? static_cast<void> (0) : __assert_fail ("0 && \"CompleteDecl called on a Decl that can't be completed\"" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 8374, __PRETTY_FUNCTION__)); | |||
8375 | } | |||
8376 | } | |||
8377 | ||||
8378 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { | |||
8379 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); | |||
8380 | assert((Pos == ImportedDecls.end() || Pos->second == To) &&(((Pos == ImportedDecls.end() || Pos->second == To) && "Try to import an already imported Decl") ? static_cast<void > (0) : __assert_fail ("(Pos == ImportedDecls.end() || Pos->second == To) && \"Try to import an already imported Decl\"" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 8381, __PRETTY_FUNCTION__)) | |||
8381 | "Try to import an already imported Decl")(((Pos == ImportedDecls.end() || Pos->second == To) && "Try to import an already imported Decl") ? static_cast<void > (0) : __assert_fail ("(Pos == ImportedDecls.end() || Pos->second == To) && \"Try to import an already imported Decl\"" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/ASTImporter.cpp" , 8381, __PRETTY_FUNCTION__)); | |||
8382 | if (Pos != ImportedDecls.end()) | |||
8383 | return Pos->second; | |||
8384 | ImportedDecls[From] = To; | |||
8385 | return To; | |||
8386 | } | |||
8387 | ||||
8388 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, | |||
8389 | bool Complain) { | |||
8390 | llvm::DenseMap<const Type *, const Type *>::iterator Pos | |||
8391 | = ImportedTypes.find(From.getTypePtr()); | |||
8392 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) | |||
8393 | return true; | |||
8394 | ||||
8395 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, | |||
8396 | getStructuralEquivalenceKind(*this), false, | |||
8397 | Complain); | |||
8398 | return Ctx.IsEquivalent(From, To); | |||
8399 | } |
1 | //===- DeclVisitor.h - Visitor for Decl subclasses --------------*- C++ -*-===// |
2 | // |
3 | // The LLVM Compiler Infrastructure |
4 | // |
5 | // This file is distributed under the University of Illinois Open Source |
6 | // License. See LICENSE.TXT for details. |
7 | // |
8 | //===----------------------------------------------------------------------===// |
9 | // |
10 | // This file defines the DeclVisitor interface. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #ifndef LLVM_CLANG_AST_DECLVISITOR_H |
15 | #define LLVM_CLANG_AST_DECLVISITOR_H |
16 | |
17 | #include "clang/AST/Decl.h" |
18 | #include "clang/AST/DeclBase.h" |
19 | #include "clang/AST/DeclCXX.h" |
20 | #include "clang/AST/DeclFriend.h" |
21 | #include "clang/AST/DeclObjC.h" |
22 | #include "clang/AST/DeclOpenMP.h" |
23 | #include "clang/AST/DeclTemplate.h" |
24 | #include "llvm/Support/ErrorHandling.h" |
25 | |
26 | namespace clang { |
27 | |
28 | namespace declvisitor { |
29 | |
30 | template <typename T> struct make_ptr { using type = T *; }; |
31 | template <typename T> struct make_const_ptr { using type = const T *; }; |
32 | |
33 | /// A simple visitor class that helps create declaration visitors. |
34 | template<template <typename> class Ptr, typename ImplClass, typename RetTy=void> |
35 | class Base { |
36 | public: |
37 | #define PTR(CLASS) typename Ptr<CLASS>::type |
38 | #define DISPATCH(NAME, CLASS) \ |
39 | return static_cast<ImplClass*>(this)->Visit##NAME(static_cast<PTR(CLASS)>(D)) |
40 | |
41 | RetTy Visit(PTR(Decl) D) { |
42 | switch (D->getKind()) { |
43 | #define DECL(DERIVED, BASE) \ |
44 | case Decl::DERIVED: DISPATCH(DERIVED##Decl, DERIVED##Decl); |
45 | #define ABSTRACT_DECL(DECL) |
46 | #include "clang/AST/DeclNodes.inc" |
47 | } |
48 | llvm_unreachable("Decl that isn't part of DeclNodes.inc!")::llvm::llvm_unreachable_internal("Decl that isn't part of DeclNodes.inc!" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/include/clang/AST/DeclVisitor.h" , 48); |
49 | } |
50 | |
51 | // If the implementation chooses not to implement a certain visit |
52 | // method, fall back to the parent. |
53 | #define DECL(DERIVED, BASE) \ |
54 | RetTy Visit##DERIVED##Decl(PTR(DERIVED##Decl) D) { DISPATCH(BASE, BASE); } |
55 | #include "clang/AST/DeclNodes.inc" |
56 | |
57 | RetTy VisitDecl(PTR(Decl) D) { return RetTy(); } |
58 | |
59 | #undef PTR |
60 | #undef DISPATCH |
61 | }; |
62 | |
63 | } // namespace declvisitor |
64 | |
65 | /// A simple visitor class that helps create declaration visitors. |
66 | /// |
67 | /// This class does not preserve constness of Decl pointers (see also |
68 | /// ConstDeclVisitor). |
69 | template<typename ImplClass, typename RetTy = void> |
70 | class DeclVisitor |
71 | : public declvisitor::Base<declvisitor::make_ptr, ImplClass, RetTy> {}; |
72 | |
73 | /// A simple visitor class that helps create declaration visitors. |
74 | /// |
75 | /// This class preserves constness of Decl pointers (see also DeclVisitor). |
76 | template<typename ImplClass, typename RetTy = void> |
77 | class ConstDeclVisitor |
78 | : public declvisitor::Base<declvisitor::make_const_ptr, ImplClass, RetTy> {}; |
79 | |
80 | } // namespace clang |
81 | |
82 | #endif // LLVM_CLANG_AST_DECLVISITOR_H |
1 | /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ |
2 | |* *| |
3 | |* List of AST nodes of a particular kind *| |
4 | |* *| |
5 | |* Automatically generated file, do not edit! *| |
6 | |* *| |
7 | \*===----------------------------------------------------------------------===*/ |
8 | |
9 | #ifndef ABSTRACT_DECL |
10 | # define ABSTRACT_DECL(Type) Type |
11 | #endif |
12 | #ifndef DECL_RANGE |
13 | # define DECL_RANGE(Base, First, Last) |
14 | #endif |
15 | |
16 | #ifndef LAST_DECL_RANGE |
17 | # define LAST_DECL_RANGE(Base, First, Last) DECL_RANGE(Base, First, Last) |
18 | #endif |
19 | |
20 | #ifndef ACCESSSPEC |
21 | # define ACCESSSPEC(Type, Base) DECL(Type, Base) |
22 | #endif |
23 | ACCESSSPEC(AccessSpec, Decl) |
24 | #undef ACCESSSPEC |
25 | |
26 | #ifndef BLOCK |
27 | # define BLOCK(Type, Base) DECL(Type, Base) |
28 | #endif |
29 | BLOCK(Block, Decl) |
30 | #undef BLOCK |
31 | |
32 | #ifndef CAPTURED |
33 | # define CAPTURED(Type, Base) DECL(Type, Base) |
34 | #endif |
35 | CAPTURED(Captured, Decl) |
36 | #undef CAPTURED |
37 | |
38 | #ifndef CLASSSCOPEFUNCTIONSPECIALIZATION |
39 | # define CLASSSCOPEFUNCTIONSPECIALIZATION(Type, Base) DECL(Type, Base) |
40 | #endif |
41 | CLASSSCOPEFUNCTIONSPECIALIZATION(ClassScopeFunctionSpecialization, Decl) |
42 | #undef CLASSSCOPEFUNCTIONSPECIALIZATION |
43 | |
44 | #ifndef EMPTY |
45 | # define EMPTY(Type, Base) DECL(Type, Base) |
46 | #endif |
47 | EMPTY(Empty, Decl) |
48 | #undef EMPTY |
49 | |
50 | #ifndef EXPORT |
51 | # define EXPORT(Type, Base) DECL(Type, Base) |
52 | #endif |
53 | EXPORT(Export, Decl) |
54 | #undef EXPORT |
55 | |
56 | #ifndef EXTERNCCONTEXT |
57 | # define EXTERNCCONTEXT(Type, Base) DECL(Type, Base) |
58 | #endif |
59 | EXTERNCCONTEXT(ExternCContext, Decl) |
60 | #undef EXTERNCCONTEXT |
61 | |
62 | #ifndef FILESCOPEASM |
63 | # define FILESCOPEASM(Type, Base) DECL(Type, Base) |
64 | #endif |
65 | FILESCOPEASM(FileScopeAsm, Decl) |
66 | #undef FILESCOPEASM |
67 | |
68 | #ifndef FRIEND |
69 | # define FRIEND(Type, Base) DECL(Type, Base) |
70 | #endif |
71 | FRIEND(Friend, Decl) |
72 | #undef FRIEND |
73 | |
74 | #ifndef FRIENDTEMPLATE |
75 | # define FRIENDTEMPLATE(Type, Base) DECL(Type, Base) |
76 | #endif |
77 | FRIENDTEMPLATE(FriendTemplate, Decl) |
78 | #undef FRIENDTEMPLATE |
79 | |
80 | #ifndef IMPORT |
81 | # define IMPORT(Type, Base) DECL(Type, Base) |
82 | #endif |
83 | IMPORT(Import, Decl) |
84 | #undef IMPORT |
85 | |
86 | #ifndef LINKAGESPEC |
87 | # define LINKAGESPEC(Type, Base) DECL(Type, Base) |
88 | #endif |
89 | LINKAGESPEC(LinkageSpec, Decl) |
90 | #undef LINKAGESPEC |
91 | |
92 | #ifndef NAMED |
93 | # define NAMED(Type, Base) DECL(Type, Base) |
94 | #endif |
95 | ABSTRACT_DECL(NAMED(Named, Decl)) |
96 | #ifndef LABEL |
97 | # define LABEL(Type, Base) NAMED(Type, Base) |
98 | #endif |
99 | LABEL(Label, NamedDecl) |
100 | #undef LABEL |
101 | |
102 | #ifndef NAMESPACE |
103 | # define NAMESPACE(Type, Base) NAMED(Type, Base) |
104 | #endif |
105 | NAMESPACE(Namespace, NamedDecl) |
106 | #undef NAMESPACE |
107 | |
108 | #ifndef NAMESPACEALIAS |
109 | # define NAMESPACEALIAS(Type, Base) NAMED(Type, Base) |
110 | #endif |
111 | NAMESPACEALIAS(NamespaceAlias, NamedDecl) |
112 | #undef NAMESPACEALIAS |
113 | |
114 | #ifndef OBJCCOMPATIBLEALIAS |
115 | # define OBJCCOMPATIBLEALIAS(Type, Base) NAMED(Type, Base) |
116 | #endif |
117 | OBJCCOMPATIBLEALIAS(ObjCCompatibleAlias, NamedDecl) |
118 | #undef OBJCCOMPATIBLEALIAS |
119 | |
120 | #ifndef OBJCCONTAINER |
121 | # define OBJCCONTAINER(Type, Base) NAMED(Type, Base) |
122 | #endif |
123 | ABSTRACT_DECL(OBJCCONTAINER(ObjCContainer, NamedDecl)) |
124 | #ifndef OBJCCATEGORY |
125 | # define OBJCCATEGORY(Type, Base) OBJCCONTAINER(Type, Base) |
126 | #endif |
127 | OBJCCATEGORY(ObjCCategory, ObjCContainerDecl) |
128 | #undef OBJCCATEGORY |
129 | |
130 | #ifndef OBJCIMPL |
131 | # define OBJCIMPL(Type, Base) OBJCCONTAINER(Type, Base) |
132 | #endif |
133 | ABSTRACT_DECL(OBJCIMPL(ObjCImpl, ObjCContainerDecl)) |
134 | #ifndef OBJCCATEGORYIMPL |
135 | # define OBJCCATEGORYIMPL(Type, Base) OBJCIMPL(Type, Base) |
136 | #endif |
137 | OBJCCATEGORYIMPL(ObjCCategoryImpl, ObjCImplDecl) |
138 | #undef OBJCCATEGORYIMPL |
139 | |
140 | #ifndef OBJCIMPLEMENTATION |
141 | # define OBJCIMPLEMENTATION(Type, Base) OBJCIMPL(Type, Base) |
142 | #endif |
143 | OBJCIMPLEMENTATION(ObjCImplementation, ObjCImplDecl) |
144 | #undef OBJCIMPLEMENTATION |
145 | |
146 | DECL_RANGE(ObjCImpl, ObjCCategoryImpl, ObjCImplementation) |
147 | |
148 | #undef OBJCIMPL |
149 | |
150 | #ifndef OBJCINTERFACE |
151 | # define OBJCINTERFACE(Type, Base) OBJCCONTAINER(Type, Base) |
152 | #endif |
153 | OBJCINTERFACE(ObjCInterface, ObjCContainerDecl) |
154 | #undef OBJCINTERFACE |
155 | |
156 | #ifndef OBJCPROTOCOL |
157 | # define OBJCPROTOCOL(Type, Base) OBJCCONTAINER(Type, Base) |
158 | #endif |
159 | OBJCPROTOCOL(ObjCProtocol, ObjCContainerDecl) |
160 | #undef OBJCPROTOCOL |
161 | |
162 | DECL_RANGE(ObjCContainer, ObjCCategory, ObjCProtocol) |
163 | |
164 | #undef OBJCCONTAINER |
165 | |
166 | #ifndef OBJCMETHOD |
167 | # define OBJCMETHOD(Type, Base) NAMED(Type, Base) |
168 | #endif |
169 | OBJCMETHOD(ObjCMethod, NamedDecl) |
170 | #undef OBJCMETHOD |
171 | |
172 | #ifndef OBJCPROPERTY |
173 | # define OBJCPROPERTY(Type, Base) NAMED(Type, Base) |
174 | #endif |
175 | OBJCPROPERTY(ObjCProperty, NamedDecl) |
176 | #undef OBJCPROPERTY |
177 | |
178 | #ifndef TEMPLATE |
179 | # define TEMPLATE(Type, Base) NAMED(Type, Base) |
180 | #endif |
181 | ABSTRACT_DECL(TEMPLATE(Template, NamedDecl)) |
182 | #ifndef BUILTINTEMPLATE |
183 | # define BUILTINTEMPLATE(Type, Base) TEMPLATE(Type, Base) |
184 | #endif |
185 | BUILTINTEMPLATE(BuiltinTemplate, TemplateDecl) |
186 | #undef BUILTINTEMPLATE |
187 | |
188 | #ifndef REDECLARABLETEMPLATE |
189 | # define REDECLARABLETEMPLATE(Type, Base) TEMPLATE(Type, Base) |
190 | #endif |
191 | ABSTRACT_DECL(REDECLARABLETEMPLATE(RedeclarableTemplate, TemplateDecl)) |
192 | #ifndef CLASSTEMPLATE |
193 | # define CLASSTEMPLATE(Type, Base) REDECLARABLETEMPLATE(Type, Base) |
194 | #endif |
195 | CLASSTEMPLATE(ClassTemplate, RedeclarableTemplateDecl) |
196 | #undef CLASSTEMPLATE |
197 | |
198 | #ifndef FUNCTIONTEMPLATE |
199 | # define FUNCTIONTEMPLATE(Type, Base) REDECLARABLETEMPLATE(Type, Base) |
200 | #endif |
201 | FUNCTIONTEMPLATE(FunctionTemplate, RedeclarableTemplateDecl) |
202 | #undef FUNCTIONTEMPLATE |
203 | |
204 | #ifndef TYPEALIASTEMPLATE |
205 | # define TYPEALIASTEMPLATE(Type, Base) REDECLARABLETEMPLATE(Type, Base) |
206 | #endif |
207 | TYPEALIASTEMPLATE(TypeAliasTemplate, RedeclarableTemplateDecl) |
208 | #undef TYPEALIASTEMPLATE |
209 | |
210 | #ifndef VARTEMPLATE |
211 | # define VARTEMPLATE(Type, Base) REDECLARABLETEMPLATE(Type, Base) |
212 | #endif |
213 | VARTEMPLATE(VarTemplate, RedeclarableTemplateDecl) |
214 | #undef VARTEMPLATE |
215 | |
216 | DECL_RANGE(RedeclarableTemplate, ClassTemplate, VarTemplate) |
217 | |
218 | #undef REDECLARABLETEMPLATE |
219 | |
220 | #ifndef TEMPLATETEMPLATEPARM |
221 | # define TEMPLATETEMPLATEPARM(Type, Base) TEMPLATE(Type, Base) |
222 | #endif |
223 | TEMPLATETEMPLATEPARM(TemplateTemplateParm, TemplateDecl) |
224 | #undef TEMPLATETEMPLATEPARM |
225 | |
226 | DECL_RANGE(Template, BuiltinTemplate, TemplateTemplateParm) |
227 | |
228 | #undef TEMPLATE |
229 | |
230 | #ifndef TYPE |
231 | # define TYPE(Type, Base) NAMED(Type, Base) |
232 | #endif |
233 | ABSTRACT_DECL(TYPE(Type, NamedDecl)) |
234 | #ifndef TAG |
235 | # define TAG(Type, Base) TYPE(Type, Base) |
236 | #endif |
237 | ABSTRACT_DECL(TAG(Tag, TypeDecl)) |
238 | #ifndef ENUM |
239 | # define ENUM(Type, Base) TAG(Type, Base) |
240 | #endif |
241 | ENUM(Enum, TagDecl) |
242 | #undef ENUM |
243 | |
244 | #ifndef RECORD |
245 | # define RECORD(Type, Base) TAG(Type, Base) |
246 | #endif |
247 | RECORD(Record, TagDecl) |
248 | #ifndef CXXRECORD |
249 | # define CXXRECORD(Type, Base) RECORD(Type, Base) |
250 | #endif |
251 | CXXRECORD(CXXRecord, RecordDecl) |
252 | #ifndef CLASSTEMPLATESPECIALIZATION |
253 | # define CLASSTEMPLATESPECIALIZATION(Type, Base) CXXRECORD(Type, Base) |
254 | #endif |
255 | CLASSTEMPLATESPECIALIZATION(ClassTemplateSpecialization, CXXRecordDecl) |
256 | #ifndef CLASSTEMPLATEPARTIALSPECIALIZATION |
257 | # define CLASSTEMPLATEPARTIALSPECIALIZATION(Type, Base) CLASSTEMPLATESPECIALIZATION(Type, Base) |
258 | #endif |
259 | CLASSTEMPLATEPARTIALSPECIALIZATION(ClassTemplatePartialSpecialization, ClassTemplateSpecializationDecl) |
260 | #undef CLASSTEMPLATEPARTIALSPECIALIZATION |
261 | |
262 | DECL_RANGE(ClassTemplateSpecialization, ClassTemplateSpecialization, ClassTemplatePartialSpecialization) |
263 | |
264 | #undef CLASSTEMPLATESPECIALIZATION |
265 | |
266 | DECL_RANGE(CXXRecord, CXXRecord, ClassTemplatePartialSpecialization) |
267 | |
268 | #undef CXXRECORD |
269 | |
270 | DECL_RANGE(Record, Record, ClassTemplatePartialSpecialization) |
271 | |
272 | #undef RECORD |
273 | |
274 | DECL_RANGE(Tag, Enum, ClassTemplatePartialSpecialization) |
275 | |
276 | #undef TAG |
277 | |
278 | #ifndef TEMPLATETYPEPARM |
279 | # define TEMPLATETYPEPARM(Type, Base) TYPE(Type, Base) |
280 | #endif |
281 | TEMPLATETYPEPARM(TemplateTypeParm, TypeDecl) |
282 | #undef TEMPLATETYPEPARM |
283 | |
284 | #ifndef TYPEDEFNAME |
285 | # define TYPEDEFNAME(Type, Base) TYPE(Type, Base) |
286 | #endif |
287 | ABSTRACT_DECL(TYPEDEFNAME(TypedefName, TypeDecl)) |
288 | #ifndef OBJCTYPEPARAM |
289 | # define OBJCTYPEPARAM(Type, Base) TYPEDEFNAME(Type, Base) |
290 | #endif |
291 | OBJCTYPEPARAM(ObjCTypeParam, TypedefNameDecl) |
292 | #undef OBJCTYPEPARAM |
293 | |
294 | #ifndef TYPEALIAS |
295 | # define TYPEALIAS(Type, Base) TYPEDEFNAME(Type, Base) |
296 | #endif |
297 | TYPEALIAS(TypeAlias, TypedefNameDecl) |
298 | #undef TYPEALIAS |
299 | |
300 | #ifndef TYPEDEF |
301 | # define TYPEDEF(Type, Base) TYPEDEFNAME(Type, Base) |
302 | #endif |
303 | TYPEDEF(Typedef, TypedefNameDecl) |
304 | #undef TYPEDEF |
305 | |
306 | DECL_RANGE(TypedefName, ObjCTypeParam, Typedef) |
307 | |
308 | #undef TYPEDEFNAME |
309 | |
310 | #ifndef UNRESOLVEDUSINGTYPENAME |
311 | # define UNRESOLVEDUSINGTYPENAME(Type, Base) TYPE(Type, Base) |
312 | #endif |
313 | UNRESOLVEDUSINGTYPENAME(UnresolvedUsingTypename, TypeDecl) |
314 | #undef UNRESOLVEDUSINGTYPENAME |
315 | |
316 | DECL_RANGE(Type, Enum, UnresolvedUsingTypename) |
317 | |
318 | #undef TYPE |
319 | |
320 | #ifndef USING |
321 | # define USING(Type, Base) NAMED(Type, Base) |
322 | #endif |
323 | USING(Using, NamedDecl) |
324 | #undef USING |
325 | |
326 | #ifndef USINGDIRECTIVE |
327 | # define USINGDIRECTIVE(Type, Base) NAMED(Type, Base) |
328 | #endif |
329 | USINGDIRECTIVE(UsingDirective, NamedDecl) |
330 | #undef USINGDIRECTIVE |
331 | |
332 | #ifndef USINGPACK |
333 | # define USINGPACK(Type, Base) NAMED(Type, Base) |
334 | #endif |
335 | USINGPACK(UsingPack, NamedDecl) |
336 | #undef USINGPACK |
337 | |
338 | #ifndef USINGSHADOW |
339 | # define USINGSHADOW(Type, Base) NAMED(Type, Base) |
340 | #endif |
341 | USINGSHADOW(UsingShadow, NamedDecl) |
342 | #ifndef CONSTRUCTORUSINGSHADOW |
343 | # define CONSTRUCTORUSINGSHADOW(Type, Base) USINGSHADOW(Type, Base) |
344 | #endif |
345 | CONSTRUCTORUSINGSHADOW(ConstructorUsingShadow, UsingShadowDecl) |
346 | #undef CONSTRUCTORUSINGSHADOW |
347 | |
348 | DECL_RANGE(UsingShadow, UsingShadow, ConstructorUsingShadow) |
349 | |
350 | #undef USINGSHADOW |
351 | |
352 | #ifndef VALUE |
353 | # define VALUE(Type, Base) NAMED(Type, Base) |
354 | #endif |
355 | ABSTRACT_DECL(VALUE(Value, NamedDecl)) |
356 | #ifndef BINDING |
357 | # define BINDING(Type, Base) VALUE(Type, Base) |
358 | #endif |
359 | BINDING(Binding, ValueDecl) |
360 | #undef BINDING |
361 | |
362 | #ifndef DECLARATOR |
363 | # define DECLARATOR(Type, Base) VALUE(Type, Base) |
364 | #endif |
365 | ABSTRACT_DECL(DECLARATOR(Declarator, ValueDecl)) |
366 | #ifndef FIELD |
367 | # define FIELD(Type, Base) DECLARATOR(Type, Base) |
368 | #endif |
369 | FIELD(Field, DeclaratorDecl) |
370 | #ifndef OBJCATDEFSFIELD |
371 | # define OBJCATDEFSFIELD(Type, Base) FIELD(Type, Base) |
372 | #endif |
373 | OBJCATDEFSFIELD(ObjCAtDefsField, FieldDecl) |
374 | #undef OBJCATDEFSFIELD |
375 | |
376 | #ifndef OBJCIVAR |
377 | # define OBJCIVAR(Type, Base) FIELD(Type, Base) |
378 | #endif |
379 | OBJCIVAR(ObjCIvar, FieldDecl) |
380 | #undef OBJCIVAR |
381 | |
382 | DECL_RANGE(Field, Field, ObjCIvar) |
383 | |
384 | #undef FIELD |
385 | |
386 | #ifndef FUNCTION |
387 | # define FUNCTION(Type, Base) DECLARATOR(Type, Base) |
388 | #endif |
389 | FUNCTION(Function, DeclaratorDecl) |
390 | #ifndef CXXDEDUCTIONGUIDE |
391 | # define CXXDEDUCTIONGUIDE(Type, Base) FUNCTION(Type, Base) |
392 | #endif |
393 | CXXDEDUCTIONGUIDE(CXXDeductionGuide, FunctionDecl) |
394 | #undef CXXDEDUCTIONGUIDE |
395 | |
396 | #ifndef CXXMETHOD |
397 | # define CXXMETHOD(Type, Base) FUNCTION(Type, Base) |
398 | #endif |
399 | CXXMETHOD(CXXMethod, FunctionDecl) |
400 | #ifndef CXXCONSTRUCTOR |
401 | # define CXXCONSTRUCTOR(Type, Base) CXXMETHOD(Type, Base) |
402 | #endif |
403 | CXXCONSTRUCTOR(CXXConstructor, CXXMethodDecl) |
404 | #undef CXXCONSTRUCTOR |
405 | |
406 | #ifndef CXXCONVERSION |
407 | # define CXXCONVERSION(Type, Base) CXXMETHOD(Type, Base) |
408 | #endif |
409 | CXXCONVERSION(CXXConversion, CXXMethodDecl) |
410 | #undef CXXCONVERSION |
411 | |
412 | #ifndef CXXDESTRUCTOR |
413 | # define CXXDESTRUCTOR(Type, Base) CXXMETHOD(Type, Base) |
414 | #endif |
415 | CXXDESTRUCTOR(CXXDestructor, CXXMethodDecl) |
416 | #undef CXXDESTRUCTOR |
417 | |
418 | DECL_RANGE(CXXMethod, CXXMethod, CXXDestructor) |
419 | |
420 | #undef CXXMETHOD |
421 | |
422 | DECL_RANGE(Function, Function, CXXDestructor) |
423 | |
424 | #undef FUNCTION |
425 | |
426 | #ifndef MSPROPERTY |
427 | # define MSPROPERTY(Type, Base) DECLARATOR(Type, Base) |
428 | #endif |
429 | MSPROPERTY(MSProperty, DeclaratorDecl) |
430 | #undef MSPROPERTY |
431 | |
432 | #ifndef NONTYPETEMPLATEPARM |
433 | # define NONTYPETEMPLATEPARM(Type, Base) DECLARATOR(Type, Base) |
434 | #endif |
435 | NONTYPETEMPLATEPARM(NonTypeTemplateParm, DeclaratorDecl) |
436 | #undef NONTYPETEMPLATEPARM |
437 | |
438 | #ifndef VAR |
439 | # define VAR(Type, Base) DECLARATOR(Type, Base) |
440 | #endif |
441 | VAR(Var, DeclaratorDecl) |
442 | #ifndef DECOMPOSITION |
443 | # define DECOMPOSITION(Type, Base) VAR(Type, Base) |
444 | #endif |
445 | DECOMPOSITION(Decomposition, VarDecl) |
446 | #undef DECOMPOSITION |
447 | |
448 | #ifndef IMPLICITPARAM |
449 | # define IMPLICITPARAM(Type, Base) VAR(Type, Base) |
450 | #endif |
451 | IMPLICITPARAM(ImplicitParam, VarDecl) |
452 | #undef IMPLICITPARAM |
453 | |
454 | #ifndef OMPCAPTUREDEXPR |
455 | # define OMPCAPTUREDEXPR(Type, Base) VAR(Type, Base) |
456 | #endif |
457 | OMPCAPTUREDEXPR(OMPCapturedExpr, VarDecl) |
458 | #undef OMPCAPTUREDEXPR |
459 | |
460 | #ifndef PARMVAR |
461 | # define PARMVAR(Type, Base) VAR(Type, Base) |
462 | #endif |
463 | PARMVAR(ParmVar, VarDecl) |
464 | #undef PARMVAR |
465 | |
466 | #ifndef VARTEMPLATESPECIALIZATION |
467 | # define VARTEMPLATESPECIALIZATION(Type, Base) VAR(Type, Base) |
468 | #endif |
469 | VARTEMPLATESPECIALIZATION(VarTemplateSpecialization, VarDecl) |
470 | #ifndef VARTEMPLATEPARTIALSPECIALIZATION |
471 | # define VARTEMPLATEPARTIALSPECIALIZATION(Type, Base) VARTEMPLATESPECIALIZATION(Type, Base) |
472 | #endif |
473 | VARTEMPLATEPARTIALSPECIALIZATION(VarTemplatePartialSpecialization, VarTemplateSpecializationDecl) |
474 | #undef VARTEMPLATEPARTIALSPECIALIZATION |
475 | |
476 | DECL_RANGE(VarTemplateSpecialization, VarTemplateSpecialization, VarTemplatePartialSpecialization) |
477 | |
478 | #undef VARTEMPLATESPECIALIZATION |
479 | |
480 | DECL_RANGE(Var, Var, VarTemplatePartialSpecialization) |
481 | |
482 | #undef VAR |
483 | |
484 | DECL_RANGE(Declarator, Field, VarTemplatePartialSpecialization) |
485 | |
486 | #undef DECLARATOR |
487 | |
488 | #ifndef ENUMCONSTANT |
489 | # define ENUMCONSTANT(Type, Base) VALUE(Type, Base) |
490 | #endif |
491 | ENUMCONSTANT(EnumConstant, ValueDecl) |
492 | #undef ENUMCONSTANT |
493 | |
494 | #ifndef INDIRECTFIELD |
495 | # define INDIRECTFIELD(Type, Base) VALUE(Type, Base) |
496 | #endif |
497 | INDIRECTFIELD(IndirectField, ValueDecl) |
498 | #undef INDIRECTFIELD |
499 | |
500 | #ifndef OMPDECLAREREDUCTION |
501 | # define OMPDECLAREREDUCTION(Type, Base) VALUE(Type, Base) |
502 | #endif |
503 | OMPDECLAREREDUCTION(OMPDeclareReduction, ValueDecl) |
504 | #undef OMPDECLAREREDUCTION |
505 | |
506 | #ifndef UNRESOLVEDUSINGVALUE |
507 | # define UNRESOLVEDUSINGVALUE(Type, Base) VALUE(Type, Base) |
508 | #endif |
509 | UNRESOLVEDUSINGVALUE(UnresolvedUsingValue, ValueDecl) |
510 | #undef UNRESOLVEDUSINGVALUE |
511 | |
512 | DECL_RANGE(Value, Binding, UnresolvedUsingValue) |
513 | |
514 | #undef VALUE |
515 | |
516 | DECL_RANGE(Named, Label, UnresolvedUsingValue) |
517 | |
518 | #undef NAMED |
519 | |
520 | #ifndef OMPREQUIRES |
521 | # define OMPREQUIRES(Type, Base) DECL(Type, Base) |
522 | #endif |
523 | OMPREQUIRES(OMPRequires, Decl) |
524 | #undef OMPREQUIRES |
525 | |
526 | #ifndef OMPTHREADPRIVATE |
527 | # define OMPTHREADPRIVATE(Type, Base) DECL(Type, Base) |
528 | #endif |
529 | OMPTHREADPRIVATE(OMPThreadPrivate, Decl) |
530 | #undef OMPTHREADPRIVATE |
531 | |
532 | #ifndef OBJCPROPERTYIMPL |
533 | # define OBJCPROPERTYIMPL(Type, Base) DECL(Type, Base) |
534 | #endif |
535 | OBJCPROPERTYIMPL(ObjCPropertyImpl, Decl) |
536 | #undef OBJCPROPERTYIMPL |
537 | |
538 | #ifndef PRAGMACOMMENT |
539 | # define PRAGMACOMMENT(Type, Base) DECL(Type, Base) |
540 | #endif |
541 | PRAGMACOMMENT(PragmaComment, Decl) |
542 | #undef PRAGMACOMMENT |
543 | |
544 | #ifndef PRAGMADETECTMISMATCH |
545 | # define PRAGMADETECTMISMATCH(Type, Base) DECL(Type, Base) |
546 | #endif |
547 | PRAGMADETECTMISMATCH(PragmaDetectMismatch, Decl) |
548 | #undef PRAGMADETECTMISMATCH |
549 | |
550 | #ifndef STATICASSERT |
551 | # define STATICASSERT(Type, Base) DECL(Type, Base) |
552 | #endif |
553 | STATICASSERT(StaticAssert, Decl) |
554 | #undef STATICASSERT |
555 | |
556 | #ifndef TRANSLATIONUNIT |
557 | # define TRANSLATIONUNIT(Type, Base) DECL(Type, Base) |
558 | #endif |
559 | TRANSLATIONUNIT(TranslationUnit, Decl) |
560 | #undef TRANSLATIONUNIT |
561 | |
562 | LAST_DECL_RANGE(Decl, AccessSpec, TranslationUnit) |
563 | |
564 | #undef DECL |
565 | #undef DECL_RANGE |
566 | #undef LAST_DECL_RANGE |
567 | #undef ABSTRACT_DECL |
568 | /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ |
569 | |* *| |
570 | |* List of AST Decl nodes *| |
571 | |* *| |
572 | |* Automatically generated file, do not edit! *| |
573 | |* *| |
574 | \*===----------------------------------------------------------------------===*/ |
575 | |
576 | #ifndef DECL_CONTEXT |
577 | # define DECL_CONTEXT(DECL) |
578 | #endif |
579 | #ifndef DECL_CONTEXT_BASE |
580 | # define DECL_CONTEXT_BASE(DECL) DECL_CONTEXT(DECL) |
581 | #endif |
582 | DECL_CONTEXT_BASE(Function) |
583 | DECL_CONTEXT_BASE(Tag) |
584 | DECL_CONTEXT_BASE(ObjCContainer) |
585 | DECL_CONTEXT(Block) |
586 | DECL_CONTEXT(Captured) |
587 | DECL_CONTEXT(Export) |
588 | DECL_CONTEXT(ExternCContext) |
589 | DECL_CONTEXT(LinkageSpec) |
590 | DECL_CONTEXT(Namespace) |
591 | DECL_CONTEXT(OMPDeclareReduction) |
592 | DECL_CONTEXT(ObjCMethod) |
593 | DECL_CONTEXT(TranslationUnit) |
594 | #undef DECL_CONTEXT |
595 | #undef DECL_CONTEXT_BASE |
1 | /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ |
2 | |* *| |
3 | |* List of AST nodes of a particular kind *| |
4 | |* *| |
5 | |* Automatically generated file, do not edit! *| |
6 | |* *| |
7 | \*===----------------------------------------------------------------------===*/ |
8 | |
9 | #ifndef ABSTRACT_DECL |
10 | # define ABSTRACT_DECL(Type) Type |
11 | #endif |
12 | #ifndef DECL_RANGE |
13 | # define DECL_RANGE(Base, First, Last) |
14 | #endif |
15 | |
16 | #ifndef LAST_DECL_RANGE |
17 | # define LAST_DECL_RANGE(Base, First, Last) DECL_RANGE(Base, First, Last) |
18 | #endif |
19 | |
20 | #ifndef ACCESSSPEC |
21 | # define ACCESSSPEC(Type, Base) DECL(Type, Base) |
22 | #endif |
23 | ACCESSSPEC(AccessSpec, Decl) |
24 | #undef ACCESSSPEC |
25 | |
26 | #ifndef BLOCK |
27 | # define BLOCK(Type, Base) DECL(Type, Base) |
28 | #endif |
29 | BLOCK(Block, Decl) |
30 | #undef BLOCK |
31 | |
32 | #ifndef CAPTURED |
33 | # define CAPTURED(Type, Base) DECL(Type, Base) |
34 | #endif |
35 | CAPTURED(Captured, Decl) |
36 | #undef CAPTURED |
37 | |
38 | #ifndef CLASSSCOPEFUNCTIONSPECIALIZATION |
39 | # define CLASSSCOPEFUNCTIONSPECIALIZATION(Type, Base) DECL(Type, Base) |
40 | #endif |
41 | CLASSSCOPEFUNCTIONSPECIALIZATION(ClassScopeFunctionSpecialization, Decl) |
42 | #undef CLASSSCOPEFUNCTIONSPECIALIZATION |
43 | |
44 | #ifndef EMPTY |
45 | # define EMPTY(Type, Base) DECL(Type, Base) |
46 | #endif |
47 | EMPTY(Empty, Decl) |
48 | #undef EMPTY |
49 | |
50 | #ifndef EXPORT |
51 | # define EXPORT(Type, Base) DECL(Type, Base) |
52 | #endif |
53 | EXPORT(Export, Decl) |
54 | #undef EXPORT |
55 | |
56 | #ifndef EXTERNCCONTEXT |
57 | # define EXTERNCCONTEXT(Type, Base) DECL(Type, Base) |
58 | #endif |
59 | EXTERNCCONTEXT(ExternCContext, Decl) |
60 | #undef EXTERNCCONTEXT |
61 | |
62 | #ifndef FILESCOPEASM |
63 | # define FILESCOPEASM(Type, Base) DECL(Type, Base) |
64 | #endif |
65 | FILESCOPEASM(FileScopeAsm, Decl) |
66 | #undef FILESCOPEASM |
67 | |
68 | #ifndef FRIEND |
69 | # define FRIEND(Type, Base) DECL(Type, Base) |
70 | #endif |
71 | FRIEND(Friend, Decl) |
72 | #undef FRIEND |
73 | |
74 | #ifndef FRIENDTEMPLATE |
75 | # define FRIENDTEMPLATE(Type, Base) DECL(Type, Base) |
76 | #endif |
77 | FRIENDTEMPLATE(FriendTemplate, Decl) |
78 | #undef FRIENDTEMPLATE |
79 | |
80 | #ifndef IMPORT |
81 | # define IMPORT(Type, Base) DECL(Type, Base) |
82 | #endif |
83 | IMPORT(Import, Decl) |
84 | #undef IMPORT |
85 | |
86 | #ifndef LINKAGESPEC |
87 | # define LINKAGESPEC(Type, Base) DECL(Type, Base) |
88 | #endif |
89 | LINKAGESPEC(LinkageSpec, Decl) |
90 | #undef LINKAGESPEC |
91 | |
92 | #ifndef NAMED |
93 | # define NAMED(Type, Base) DECL(Type, Base) |
94 | #endif |
95 | ABSTRACT_DECL(NAMED(Named, Decl)) |
96 | #ifndef LABEL |
97 | # define LABEL(Type, Base) NAMED(Type, Base) |
98 | #endif |
99 | LABEL(Label, NamedDecl) |
100 | #undef LABEL |
101 | |
102 | #ifndef NAMESPACE |
103 | # define NAMESPACE(Type, Base) NAMED(Type, Base) |
104 | #endif |
105 | NAMESPACE(Namespace, NamedDecl) |
106 | #undef NAMESPACE |
107 | |
108 | #ifndef NAMESPACEALIAS |
109 | # define NAMESPACEALIAS(Type, Base) NAMED(Type, Base) |
110 | #endif |
111 | NAMESPACEALIAS(NamespaceAlias, NamedDecl) |
112 | #undef NAMESPACEALIAS |
113 | |
114 | #ifndef OBJCCOMPATIBLEALIAS |
115 | # define OBJCCOMPATIBLEALIAS(Type, Base) NAMED(Type, Base) |
116 | #endif |
117 | OBJCCOMPATIBLEALIAS(ObjCCompatibleAlias, NamedDecl) |
118 | #undef OBJCCOMPATIBLEALIAS |
119 | |
120 | #ifndef OBJCCONTAINER |
121 | # define OBJCCONTAINER(Type, Base) NAMED(Type, Base) |
122 | #endif |
123 | ABSTRACT_DECL(OBJCCONTAINER(ObjCContainer, NamedDecl)) |
124 | #ifndef OBJCCATEGORY |
125 | # define OBJCCATEGORY(Type, Base) OBJCCONTAINER(Type, Base) |
126 | #endif |
127 | OBJCCATEGORY(ObjCCategory, ObjCContainerDecl) |
128 | #undef OBJCCATEGORY |
129 | |
130 | #ifndef OBJCIMPL |
131 | # define OBJCIMPL(Type, Base) OBJCCONTAINER(Type, Base) |
132 | #endif |
133 | ABSTRACT_DECL(OBJCIMPL(ObjCImpl, ObjCContainerDecl)) |
134 | #ifndef OBJCCATEGORYIMPL |
135 | # define OBJCCATEGORYIMPL(Type, Base) OBJCIMPL(Type, Base) |
136 | #endif |
137 | OBJCCATEGORYIMPL(ObjCCategoryImpl, ObjCImplDecl) |
138 | #undef OBJCCATEGORYIMPL |
139 | |
140 | #ifndef OBJCIMPLEMENTATION |
141 | # define OBJCIMPLEMENTATION(Type, Base) OBJCIMPL(Type, Base) |
142 | #endif |
143 | OBJCIMPLEMENTATION(ObjCImplementation, ObjCImplDecl) |
144 | #undef OBJCIMPLEMENTATION |
145 | |
146 | DECL_RANGE(ObjCImpl, ObjCCategoryImpl, ObjCImplementation) |
147 | |
148 | #undef OBJCIMPL |
149 | |
150 | #ifndef OBJCINTERFACE |
151 | # define OBJCINTERFACE(Type, Base) OBJCCONTAINER(Type, Base) |
152 | #endif |
153 | OBJCINTERFACE(ObjCInterface, ObjCContainerDecl) |
154 | #undef OBJCINTERFACE |
155 | |
156 | #ifndef OBJCPROTOCOL |
157 | # define OBJCPROTOCOL(Type, Base) OBJCCONTAINER(Type, Base) |
158 | #endif |
159 | OBJCPROTOCOL(ObjCProtocol, ObjCContainerDecl) |
160 | #undef OBJCPROTOCOL |
161 | |
162 | DECL_RANGE(ObjCContainer, ObjCCategory, ObjCProtocol) |
163 | |
164 | #undef OBJCCONTAINER |
165 | |
166 | #ifndef OBJCMETHOD |
167 | # define OBJCMETHOD(Type, Base) NAMED(Type, Base) |
168 | #endif |
169 | OBJCMETHOD(ObjCMethod, NamedDecl) |
170 | #undef OBJCMETHOD |
171 | |
172 | #ifndef OBJCPROPERTY |
173 | # define OBJCPROPERTY(Type, Base) NAMED(Type, Base) |
174 | #endif |
175 | OBJCPROPERTY(ObjCProperty, NamedDecl) |
176 | #undef OBJCPROPERTY |
177 | |
178 | #ifndef TEMPLATE |
179 | # define TEMPLATE(Type, Base) NAMED(Type, Base) |
180 | #endif |
181 | ABSTRACT_DECL(TEMPLATE(Template, NamedDecl)) |
182 | #ifndef BUILTINTEMPLATE |
183 | # define BUILTINTEMPLATE(Type, Base) TEMPLATE(Type, Base) |
184 | #endif |
185 | BUILTINTEMPLATE(BuiltinTemplate, TemplateDecl) |
186 | #undef BUILTINTEMPLATE |
187 | |
188 | #ifndef REDECLARABLETEMPLATE |
189 | # define REDECLARABLETEMPLATE(Type, Base) TEMPLATE(Type, Base) |
190 | #endif |
191 | ABSTRACT_DECL(REDECLARABLETEMPLATE(RedeclarableTemplate, TemplateDecl)) |
192 | #ifndef CLASSTEMPLATE |
193 | # define CLASSTEMPLATE(Type, Base) REDECLARABLETEMPLATE(Type, Base) |
194 | #endif |
195 | CLASSTEMPLATE(ClassTemplate, RedeclarableTemplateDecl) |
196 | #undef CLASSTEMPLATE |
197 | |
198 | #ifndef FUNCTIONTEMPLATE |
199 | # define FUNCTIONTEMPLATE(Type, Base) REDECLARABLETEMPLATE(Type, Base) |
200 | #endif |
201 | FUNCTIONTEMPLATE(FunctionTemplate, RedeclarableTemplateDecl) |
202 | #undef FUNCTIONTEMPLATE |
203 | |
204 | #ifndef TYPEALIASTEMPLATE |
205 | # define TYPEALIASTEMPLATE(Type, Base) REDECLARABLETEMPLATE(Type, Base) |
206 | #endif |
207 | TYPEALIASTEMPLATE(TypeAliasTemplate, RedeclarableTemplateDecl) |
208 | #undef TYPEALIASTEMPLATE |
209 | |
210 | #ifndef VARTEMPLATE |
211 | # define VARTEMPLATE(Type, Base) REDECLARABLETEMPLATE(Type, Base) |
212 | #endif |
213 | VARTEMPLATE(VarTemplate, RedeclarableTemplateDecl) |
214 | #undef VARTEMPLATE |
215 | |
216 | DECL_RANGE(RedeclarableTemplate, ClassTemplate, VarTemplate) |
217 | |
218 | #undef REDECLARABLETEMPLATE |
219 | |
220 | #ifndef TEMPLATETEMPLATEPARM |
221 | # define TEMPLATETEMPLATEPARM(Type, Base) TEMPLATE(Type, Base) |
222 | #endif |
223 | TEMPLATETEMPLATEPARM(TemplateTemplateParm, TemplateDecl) |
224 | #undef TEMPLATETEMPLATEPARM |
225 | |
226 | DECL_RANGE(Template, BuiltinTemplate, TemplateTemplateParm) |
227 | |
228 | #undef TEMPLATE |
229 | |
230 | #ifndef TYPE |
231 | # define TYPE(Type, Base) NAMED(Type, Base) |
232 | #endif |
233 | ABSTRACT_DECL(TYPE(Type, NamedDecl)) |
234 | #ifndef TAG |
235 | # define TAG(Type, Base) TYPE(Type, Base) |
236 | #endif |
237 | ABSTRACT_DECL(TAG(Tag, TypeDecl)) |
238 | #ifndef ENUM |
239 | # define ENUM(Type, Base) TAG(Type, Base) |
240 | #endif |
241 | ENUM(Enum, TagDecl) |
242 | #undef ENUM |
243 | |
244 | #ifndef RECORD |
245 | # define RECORD(Type, Base) TAG(Type, Base) |
246 | #endif |
247 | RECORD(Record, TagDecl) |
248 | #ifndef CXXRECORD |
249 | # define CXXRECORD(Type, Base) RECORD(Type, Base) |
250 | #endif |
251 | CXXRECORD(CXXRecord, RecordDecl) |
252 | #ifndef CLASSTEMPLATESPECIALIZATION |
253 | # define CLASSTEMPLATESPECIALIZATION(Type, Base) CXXRECORD(Type, Base) |
254 | #endif |
255 | CLASSTEMPLATESPECIALIZATION(ClassTemplateSpecialization, CXXRecordDecl) |
256 | #ifndef CLASSTEMPLATEPARTIALSPECIALIZATION |
257 | # define CLASSTEMPLATEPARTIALSPECIALIZATION(Type, Base) CLASSTEMPLATESPECIALIZATION(Type, Base) |
258 | #endif |
259 | CLASSTEMPLATEPARTIALSPECIALIZATION(ClassTemplatePartialSpecialization, ClassTemplateSpecializationDecl) |
260 | #undef CLASSTEMPLATEPARTIALSPECIALIZATION |
261 | |
262 | DECL_RANGE(ClassTemplateSpecialization, ClassTemplateSpecialization, ClassTemplatePartialSpecialization) |
263 | |
264 | #undef CLASSTEMPLATESPECIALIZATION |
265 | |
266 | DECL_RANGE(CXXRecord, CXXRecord, ClassTemplatePartialSpecialization) |
267 | |
268 | #undef CXXRECORD |
269 | |
270 | DECL_RANGE(Record, Record, ClassTemplatePartialSpecialization) |
271 | |
272 | #undef RECORD |
273 | |
274 | DECL_RANGE(Tag, Enum, ClassTemplatePartialSpecialization) |
275 | |
276 | #undef TAG |
277 | |
278 | #ifndef TEMPLATETYPEPARM |
279 | # define TEMPLATETYPEPARM(Type, Base) TYPE(Type, Base) |
280 | #endif |
281 | TEMPLATETYPEPARM(TemplateTypeParm, TypeDecl) |
282 | #undef TEMPLATETYPEPARM |
283 | |
284 | #ifndef TYPEDEFNAME |
285 | # define TYPEDEFNAME(Type, Base) TYPE(Type, Base) |
286 | #endif |
287 | ABSTRACT_DECL(TYPEDEFNAME(TypedefName, TypeDecl)) |
288 | #ifndef OBJCTYPEPARAM |
289 | # define OBJCTYPEPARAM(Type, Base) TYPEDEFNAME(Type, Base) |
290 | #endif |
291 | OBJCTYPEPARAM(ObjCTypeParam, TypedefNameDecl) |
292 | #undef OBJCTYPEPARAM |
293 | |
294 | #ifndef TYPEALIAS |
295 | # define TYPEALIAS(Type, Base) TYPEDEFNAME(Type, Base) |
296 | #endif |
297 | TYPEALIAS(TypeAlias, TypedefNameDecl) |
298 | #undef TYPEALIAS |
299 | |
300 | #ifndef TYPEDEF |
301 | # define TYPEDEF(Type, Base) TYPEDEFNAME(Type, Base) |
302 | #endif |
303 | TYPEDEF(Typedef, TypedefNameDecl) |
304 | #undef TYPEDEF |
305 | |
306 | DECL_RANGE(TypedefName, ObjCTypeParam, Typedef) |
307 | |
308 | #undef TYPEDEFNAME |
309 | |
310 | #ifndef UNRESOLVEDUSINGTYPENAME |
311 | # define UNRESOLVEDUSINGTYPENAME(Type, Base) TYPE(Type, Base) |
312 | #endif |
313 | UNRESOLVEDUSINGTYPENAME(UnresolvedUsingTypename, TypeDecl) |
314 | #undef UNRESOLVEDUSINGTYPENAME |
315 | |
316 | DECL_RANGE(Type, Enum, UnresolvedUsingTypename) |
317 | |
318 | #undef TYPE |
319 | |
320 | #ifndef USING |
321 | # define USING(Type, Base) NAMED(Type, Base) |
322 | #endif |
323 | USING(Using, NamedDecl) |
324 | #undef USING |
325 | |
326 | #ifndef USINGDIRECTIVE |
327 | # define USINGDIRECTIVE(Type, Base) NAMED(Type, Base) |
328 | #endif |
329 | USINGDIRECTIVE(UsingDirective, NamedDecl) |
330 | #undef USINGDIRECTIVE |
331 | |
332 | #ifndef USINGPACK |
333 | # define USINGPACK(Type, Base) NAMED(Type, Base) |
334 | #endif |
335 | USINGPACK(UsingPack, NamedDecl) |
336 | #undef USINGPACK |
337 | |
338 | #ifndef USINGSHADOW |
339 | # define USINGSHADOW(Type, Base) NAMED(Type, Base) |
340 | #endif |
341 | USINGSHADOW(UsingShadow, NamedDecl) |
342 | #ifndef CONSTRUCTORUSINGSHADOW |
343 | # define CONSTRUCTORUSINGSHADOW(Type, Base) USINGSHADOW(Type, Base) |
344 | #endif |
345 | CONSTRUCTORUSINGSHADOW(ConstructorUsingShadow, UsingShadowDecl) |
346 | #undef CONSTRUCTORUSINGSHADOW |
347 | |
348 | DECL_RANGE(UsingShadow, UsingShadow, ConstructorUsingShadow) |
349 | |
350 | #undef USINGSHADOW |
351 | |
352 | #ifndef VALUE |
353 | # define VALUE(Type, Base) NAMED(Type, Base) |
354 | #endif |
355 | ABSTRACT_DECL(VALUE(Value, NamedDecl)) |
356 | #ifndef BINDING |
357 | # define BINDING(Type, Base) VALUE(Type, Base) |
358 | #endif |
359 | BINDING(Binding, ValueDecl) |
360 | #undef BINDING |
361 | |
362 | #ifndef DECLARATOR |
363 | # define DECLARATOR(Type, Base) VALUE(Type, Base) |
364 | #endif |
365 | ABSTRACT_DECL(DECLARATOR(Declarator, ValueDecl)) |
366 | #ifndef FIELD |
367 | # define FIELD(Type, Base) DECLARATOR(Type, Base) |
368 | #endif |
369 | FIELD(Field, DeclaratorDecl) |
370 | #ifndef OBJCATDEFSFIELD |
371 | # define OBJCATDEFSFIELD(Type, Base) FIELD(Type, Base) |
372 | #endif |
373 | OBJCATDEFSFIELD(ObjCAtDefsField, FieldDecl) |
374 | #undef OBJCATDEFSFIELD |
375 | |
376 | #ifndef OBJCIVAR |
377 | # define OBJCIVAR(Type, Base) FIELD(Type, Base) |
378 | #endif |
379 | OBJCIVAR(ObjCIvar, FieldDecl) |
380 | #undef OBJCIVAR |
381 | |
382 | DECL_RANGE(Field, Field, ObjCIvar) |
383 | |
384 | #undef FIELD |
385 | |
386 | #ifndef FUNCTION |
387 | # define FUNCTION(Type, Base) DECLARATOR(Type, Base) |
388 | #endif |
389 | FUNCTION(Function, DeclaratorDecl) |
390 | #ifndef CXXDEDUCTIONGUIDE |
391 | # define CXXDEDUCTIONGUIDE(Type, Base) FUNCTION(Type, Base) |
392 | #endif |
393 | CXXDEDUCTIONGUIDE(CXXDeductionGuide, FunctionDecl) |
394 | #undef CXXDEDUCTIONGUIDE |
395 | |
396 | #ifndef CXXMETHOD |
397 | # define CXXMETHOD(Type, Base) FUNCTION(Type, Base) |
398 | #endif |
399 | CXXMETHOD(CXXMethod, FunctionDecl) |
400 | #ifndef CXXCONSTRUCTOR |
401 | # define CXXCONSTRUCTOR(Type, Base) CXXMETHOD(Type, Base) |
402 | #endif |
403 | CXXCONSTRUCTOR(CXXConstructor, CXXMethodDecl) |
404 | #undef CXXCONSTRUCTOR |
405 | |
406 | #ifndef CXXCONVERSION |
407 | # define CXXCONVERSION(Type, Base) CXXMETHOD(Type, Base) |
408 | #endif |
409 | CXXCONVERSION(CXXConversion, CXXMethodDecl) |
410 | #undef CXXCONVERSION |
411 | |
412 | #ifndef CXXDESTRUCTOR |
413 | # define CXXDESTRUCTOR(Type, Base) CXXMETHOD(Type, Base) |
414 | #endif |
415 | CXXDESTRUCTOR(CXXDestructor, CXXMethodDecl) |
416 | #undef CXXDESTRUCTOR |
417 | |
418 | DECL_RANGE(CXXMethod, CXXMethod, CXXDestructor) |
419 | |
420 | #undef CXXMETHOD |
421 | |
422 | DECL_RANGE(Function, Function, CXXDestructor) |
423 | |
424 | #undef FUNCTION |
425 | |
426 | #ifndef MSPROPERTY |
427 | # define MSPROPERTY(Type, Base) DECLARATOR(Type, Base) |
428 | #endif |
429 | MSPROPERTY(MSProperty, DeclaratorDecl) |
430 | #undef MSPROPERTY |
431 | |
432 | #ifndef NONTYPETEMPLATEPARM |
433 | # define NONTYPETEMPLATEPARM(Type, Base) DECLARATOR(Type, Base) |
434 | #endif |
435 | NONTYPETEMPLATEPARM(NonTypeTemplateParm, DeclaratorDecl) |
436 | #undef NONTYPETEMPLATEPARM |
437 | |
438 | #ifndef VAR |
439 | # define VAR(Type, Base) DECLARATOR(Type, Base) |
440 | #endif |
441 | VAR(Var, DeclaratorDecl) |
442 | #ifndef DECOMPOSITION |
443 | # define DECOMPOSITION(Type, Base) VAR(Type, Base) |
444 | #endif |
445 | DECOMPOSITION(Decomposition, VarDecl) |
446 | #undef DECOMPOSITION |
447 | |
448 | #ifndef IMPLICITPARAM |
449 | # define IMPLICITPARAM(Type, Base) VAR(Type, Base) |
450 | #endif |
451 | IMPLICITPARAM(ImplicitParam, VarDecl) |
452 | #undef IMPLICITPARAM |
453 | |
454 | #ifndef OMPCAPTUREDEXPR |
455 | # define OMPCAPTUREDEXPR(Type, Base) VAR(Type, Base) |
456 | #endif |
457 | OMPCAPTUREDEXPR(OMPCapturedExpr, VarDecl) |
458 | #undef OMPCAPTUREDEXPR |
459 | |
460 | #ifndef PARMVAR |
461 | # define PARMVAR(Type, Base) VAR(Type, Base) |
462 | #endif |
463 | PARMVAR(ParmVar, VarDecl) |
464 | #undef PARMVAR |
465 | |
466 | #ifndef VARTEMPLATESPECIALIZATION |
467 | # define VARTEMPLATESPECIALIZATION(Type, Base) VAR(Type, Base) |
468 | #endif |
469 | VARTEMPLATESPECIALIZATION(VarTemplateSpecialization, VarDecl) |
470 | #ifndef VARTEMPLATEPARTIALSPECIALIZATION |
471 | # define VARTEMPLATEPARTIALSPECIALIZATION(Type, Base) VARTEMPLATESPECIALIZATION(Type, Base) |
472 | #endif |
473 | VARTEMPLATEPARTIALSPECIALIZATION(VarTemplatePartialSpecialization, VarTemplateSpecializationDecl) |
474 | #undef VARTEMPLATEPARTIALSPECIALIZATION |
475 | |
476 | DECL_RANGE(VarTemplateSpecialization, VarTemplateSpecialization, VarTemplatePartialSpecialization) |
477 | |
478 | #undef VARTEMPLATESPECIALIZATION |
479 | |
480 | DECL_RANGE(Var, Var, VarTemplatePartialSpecialization) |
481 | |
482 | #undef VAR |
483 | |
484 | DECL_RANGE(Declarator, Field, VarTemplatePartialSpecialization) |
485 | |
486 | #undef DECLARATOR |
487 | |
488 | #ifndef ENUMCONSTANT |
489 | # define ENUMCONSTANT(Type, Base) VALUE(Type, Base) |
490 | #endif |
491 | ENUMCONSTANT(EnumConstant, ValueDecl) |
492 | #undef ENUMCONSTANT |
493 | |
494 | #ifndef INDIRECTFIELD |
495 | # define INDIRECTFIELD(Type, Base) VALUE(Type, Base) |
496 | #endif |
497 | INDIRECTFIELD(IndirectField, ValueDecl) |
498 | #undef INDIRECTFIELD |
499 | |
500 | #ifndef OMPDECLAREREDUCTION |
501 | # define OMPDECLAREREDUCTION(Type, Base) VALUE(Type, Base) |
502 | #endif |
503 | OMPDECLAREREDUCTION(OMPDeclareReduction, ValueDecl) |
504 | #undef OMPDECLAREREDUCTION |
505 | |
506 | #ifndef UNRESOLVEDUSINGVALUE |
507 | # define UNRESOLVEDUSINGVALUE(Type, Base) VALUE(Type, Base) |
508 | #endif |
509 | UNRESOLVEDUSINGVALUE(UnresolvedUsingValue, ValueDecl) |
510 | #undef UNRESOLVEDUSINGVALUE |
511 | |
512 | DECL_RANGE(Value, Binding, UnresolvedUsingValue) |
513 | |
514 | #undef VALUE |
515 | |
516 | DECL_RANGE(Named, Label, UnresolvedUsingValue) |
517 | |
518 | #undef NAMED |
519 | |
520 | #ifndef OMPREQUIRES |
521 | # define OMPREQUIRES(Type, Base) DECL(Type, Base) |
522 | #endif |
523 | OMPREQUIRES(OMPRequires, Decl) |
524 | #undef OMPREQUIRES |
525 | |
526 | #ifndef OMPTHREADPRIVATE |
527 | # define OMPTHREADPRIVATE(Type, Base) DECL(Type, Base) |
528 | #endif |
529 | OMPTHREADPRIVATE(OMPThreadPrivate, Decl) |
530 | #undef OMPTHREADPRIVATE |
531 | |
532 | #ifndef OBJCPROPERTYIMPL |
533 | # define OBJCPROPERTYIMPL(Type, Base) DECL(Type, Base) |
534 | #endif |
535 | OBJCPROPERTYIMPL(ObjCPropertyImpl, Decl) |
536 | #undef OBJCPROPERTYIMPL |
537 | |
538 | #ifndef PRAGMACOMMENT |
539 | # define PRAGMACOMMENT(Type, Base) DECL(Type, Base) |
540 | #endif |
541 | PRAGMACOMMENT(PragmaComment, Decl) |
542 | #undef PRAGMACOMMENT |
543 | |
544 | #ifndef PRAGMADETECTMISMATCH |
545 | # define PRAGMADETECTMISMATCH(Type, Base) DECL(Type, Base) |
546 | #endif |
547 | PRAGMADETECTMISMATCH(PragmaDetectMismatch, Decl) |
548 | #undef PRAGMADETECTMISMATCH |
549 | |
550 | #ifndef STATICASSERT |
551 | # define STATICASSERT(Type, Base) DECL(Type, Base) |
552 | #endif |
553 | STATICASSERT(StaticAssert, Decl) |
554 | #undef STATICASSERT |
555 | |
556 | #ifndef TRANSLATIONUNIT |
557 | # define TRANSLATIONUNIT(Type, Base) DECL(Type, Base) |
558 | #endif |
559 | TRANSLATIONUNIT(TranslationUnit, Decl) |
560 | #undef TRANSLATIONUNIT |
561 | |
562 | LAST_DECL_RANGE(Decl, AccessSpec, TranslationUnit) |
563 | |
564 | #undef DECL |
565 | #undef DECL_RANGE |
566 | #undef LAST_DECL_RANGE |
567 | #undef ABSTRACT_DECL |
568 | /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ |
569 | |* *| |
570 | |* List of AST Decl nodes *| |
571 | |* *| |
572 | |* Automatically generated file, do not edit! *| |
573 | |* *| |
574 | \*===----------------------------------------------------------------------===*/ |
575 | |
576 | #ifndef DECL_CONTEXT |
577 | # define DECL_CONTEXT(DECL) |
578 | #endif |
579 | #ifndef DECL_CONTEXT_BASE |
580 | # define DECL_CONTEXT_BASE(DECL) DECL_CONTEXT(DECL) |
581 | #endif |
582 | DECL_CONTEXT_BASE(Function) |
583 | DECL_CONTEXT_BASE(Tag) |
584 | DECL_CONTEXT_BASE(ObjCContainer) |
585 | DECL_CONTEXT(Block) |
586 | DECL_CONTEXT(Captured) |
587 | DECL_CONTEXT(Export) |
588 | DECL_CONTEXT(ExternCContext) |
589 | DECL_CONTEXT(LinkageSpec) |
590 | DECL_CONTEXT(Namespace) |
591 | DECL_CONTEXT(OMPDeclareReduction) |
592 | DECL_CONTEXT(ObjCMethod) |
593 | DECL_CONTEXT(TranslationUnit) |
594 | #undef DECL_CONTEXT |
595 | #undef DECL_CONTEXT_BASE |
1 | // Move, forward and identity for C++0x + swap -*- C++ -*- |
2 | |
3 | // Copyright (C) 2007-2016 Free Software Foundation, Inc. |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free |
6 | // software; you can redistribute it and/or modify it under the |
7 | // terms of the GNU General Public License as published by the |
8 | // Free Software Foundation; either version 3, or (at your option) |
9 | // any later version. |
10 | |
11 | // This library is distributed in the hope that it will be useful, |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | // GNU General Public License for more details. |
15 | |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version |
18 | // 3.1, as published by the Free Software Foundation. |
19 | |
20 | // You should have received a copy of the GNU General Public License and |
21 | // a copy of the GCC Runtime Library Exception along with this program; |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
23 | // <http://www.gnu.org/licenses/>. |
24 | |
25 | /** @file bits/move.h |
26 | * This is an internal header file, included by other library headers. |
27 | * Do not attempt to use it directly. @headername{utility} |
28 | */ |
29 | |
30 | #ifndef _MOVE_H1 |
31 | #define _MOVE_H1 1 |
32 | |
33 | #include <bits/c++config.h> |
34 | #include <bits/concept_check.h> |
35 | |
36 | namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default"))) |
37 | { |
38 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
39 | |
40 | // Used, in C++03 mode too, by allocators, etc. |
41 | /** |
42 | * @brief Same as C++11 std::addressof |
43 | * @ingroup utilities |
44 | */ |
45 | template<typename _Tp> |
46 | inline _Tp* |
47 | __addressof(_Tp& __r) _GLIBCXX_NOEXCEPTnoexcept |
48 | { |
49 | return reinterpret_cast<_Tp*> |
50 | (&const_cast<char&>(reinterpret_cast<const volatile char&>(__r))); |
51 | } |
52 | |
53 | _GLIBCXX_END_NAMESPACE_VERSION |
54 | } // namespace |
55 | |
56 | #if __cplusplus201103L >= 201103L |
57 | #include <type_traits> // Brings in std::declval too. |
58 | |
59 | namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default"))) |
60 | { |
61 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
62 | |
63 | /** |
64 | * @addtogroup utilities |
65 | * @{ |
66 | */ |
67 | |
68 | /** |
69 | * @brief Forward an lvalue. |
70 | * @return The parameter cast to the specified type. |
71 | * |
72 | * This function is used to implement "perfect forwarding". |
73 | */ |
74 | template<typename _Tp> |
75 | constexpr _Tp&& |
76 | forward(typename std::remove_reference<_Tp>::type& __t) noexcept |
77 | { return static_cast<_Tp&&>(__t); } |
78 | |
79 | /** |
80 | * @brief Forward an rvalue. |
81 | * @return The parameter cast to the specified type. |
82 | * |
83 | * This function is used to implement "perfect forwarding". |
84 | */ |
85 | template<typename _Tp> |
86 | constexpr _Tp&& |
87 | forward(typename std::remove_reference<_Tp>::type&& __t) noexcept |
88 | { |
89 | static_assert(!std::is_lvalue_reference<_Tp>::value, "template argument" |
90 | " substituting _Tp is an lvalue reference type"); |
91 | return static_cast<_Tp&&>(__t); |
92 | } |
93 | |
94 | /** |
95 | * @brief Convert a value to an rvalue. |
96 | * @param __t A thing of arbitrary type. |
97 | * @return The parameter cast to an rvalue-reference to allow moving it. |
98 | */ |
99 | template<typename _Tp> |
100 | constexpr typename std::remove_reference<_Tp>::type&& |
101 | move(_Tp&& __t) noexcept |
102 | { return static_cast<typename std::remove_reference<_Tp>::type&&>(__t); } |
103 | |
104 | |
105 | template<typename _Tp> |
106 | struct __move_if_noexcept_cond |
107 | : public __and_<__not_<is_nothrow_move_constructible<_Tp>>, |
108 | is_copy_constructible<_Tp>>::type { }; |
109 | |
110 | /** |
111 | * @brief Conditionally convert a value to an rvalue. |
112 | * @param __x A thing of arbitrary type. |
113 | * @return The parameter, possibly cast to an rvalue-reference. |
114 | * |
115 | * Same as std::move unless the type's move constructor could throw and the |
116 | * type is copyable, in which case an lvalue-reference is returned instead. |
117 | */ |
118 | template<typename _Tp> |
119 | constexpr typename |
120 | conditional<__move_if_noexcept_cond<_Tp>::value, const _Tp&, _Tp&&>::type |
121 | move_if_noexcept(_Tp& __x) noexcept |
122 | { return std::move(__x); } |
123 | |
124 | // declval, from type_traits. |
125 | |
126 | /** |
127 | * @brief Returns the actual address of the object or function |
128 | * referenced by r, even in the presence of an overloaded |
129 | * operator&. |
130 | * @param __r Reference to an object or function. |
131 | * @return The actual address. |
132 | */ |
133 | template<typename _Tp> |
134 | inline _Tp* |
135 | addressof(_Tp& __r) noexcept |
136 | { return std::__addressof(__r); } |
137 | |
138 | // C++11 version of std::exchange for internal use. |
139 | template <typename _Tp, typename _Up = _Tp> |
140 | inline _Tp |
141 | __exchange(_Tp& __obj, _Up&& __new_val) |
142 | { |
143 | _Tp __old_val = std::move(__obj); |
144 | __obj = std::forward<_Up>(__new_val); |
145 | return __old_val; |
146 | } |
147 | |
148 | /// @} group utilities |
149 | _GLIBCXX_END_NAMESPACE_VERSION |
150 | } // namespace |
151 | |
152 | #define _GLIBCXX_MOVE(__val)std::move(__val) std::move(__val) |
153 | #define _GLIBCXX_FORWARD(_Tp, __val)std::forward<_Tp>(__val) std::forward<_Tp>(__val) |
154 | #else |
155 | #define _GLIBCXX_MOVE(__val)std::move(__val) (__val) |
156 | #define _GLIBCXX_FORWARD(_Tp, __val)std::forward<_Tp>(__val) (__val) |
157 | #endif |
158 | |
159 | namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default"))) |
160 | { |
161 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
162 | |
163 | /** |
164 | * @addtogroup utilities |
165 | * @{ |
166 | */ |
167 | |
168 | /** |
169 | * @brief Swaps two values. |
170 | * @param __a A thing of arbitrary type. |
171 | * @param __b Another thing of arbitrary type. |
172 | * @return Nothing. |
173 | */ |
174 | template<typename _Tp> |
175 | inline |
176 | #if __cplusplus201103L >= 201103L |
177 | typename enable_if<__and_<is_move_constructible<_Tp>, |
178 | is_move_assignable<_Tp>>::value>::type |
179 | swap(_Tp& __a, _Tp& __b) |
180 | noexcept(__and_<is_nothrow_move_constructible<_Tp>, |
181 | is_nothrow_move_assignable<_Tp>>::value) |
182 | #else |
183 | void |
184 | swap(_Tp& __a, _Tp& __b) |
185 | #endif |
186 | { |
187 | // concept requirements |
188 | __glibcxx_function_requires(_SGIAssignableConcept<_Tp>) |
189 | |
190 | _Tp __tmp = _GLIBCXX_MOVE(__a)std::move(__a); |
191 | __a = _GLIBCXX_MOVE(__b)std::move(__b); |
192 | __b = _GLIBCXX_MOVE(__tmp)std::move(__tmp); |
193 | } |
194 | |
195 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
196 | // DR 809. std::swap should be overloaded for array types. |
197 | /// Swap the contents of two arrays. |
198 | template<typename _Tp, size_t _Nm> |
199 | inline |
200 | #if __cplusplus201103L >= 201103L |
201 | typename enable_if<__is_swappable<_Tp>::value>::type |
202 | swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm]) |
203 | noexcept(__is_nothrow_swappable<_Tp>::value) |
204 | #else |
205 | void |
206 | swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm]) |
207 | #endif |
208 | { |
209 | for (size_t __n = 0; __n < _Nm; ++__n) |
210 | swap(__a[__n], __b[__n]); |
211 | } |
212 | |
213 | /// @} group utilities |
214 | _GLIBCXX_END_NAMESPACE_VERSION |
215 | } // namespace |
216 | |
217 | #endif /* _MOVE_H */ |