Bug Summary

File:tools/clang/lib/AST/ASTImporter.cpp
Warning:line 3390, column 12
Called C++ object pointer is null

Annotated Source Code

/build/llvm-toolchain-snapshot-6.0~svn318693/tools/clang/lib/AST/ASTImporter.cpp

1//===--- ASTImporter.cpp - Importing ASTs from other Contexts ---*- 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 ASTImporter class which imports AST nodes from one
11// context into another context.
12//
13//===----------------------------------------------------------------------===//
14#include "clang/AST/ASTImporter.h"
15#include "clang/AST/ASTContext.h"
16#include "clang/AST/ASTDiagnostic.h"
17#include "clang/AST/ASTStructuralEquivalence.h"
18#include "clang/AST/DeclCXX.h"
19#include "clang/AST/DeclObjC.h"
20#include "clang/AST/DeclVisitor.h"
21#include "clang/AST/StmtVisitor.h"
22#include "clang/AST/TypeVisitor.h"
23#include "clang/Basic/FileManager.h"
24#include "clang/Basic/SourceManager.h"
25#include "llvm/Support/MemoryBuffer.h"
26#include <deque>
27
28namespace clang {
29 class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, QualType>,
30 public DeclVisitor<ASTNodeImporter, Decl *>,
31 public StmtVisitor<ASTNodeImporter, Stmt *> {
32 ASTImporter &Importer;
33
34 public:
35 explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) { }
36
37 using TypeVisitor<ASTNodeImporter, QualType>::Visit;
38 using DeclVisitor<ASTNodeImporter, Decl *>::Visit;
39 using StmtVisitor<ASTNodeImporter, Stmt *>::Visit;
40
41 // Importing types
42 QualType VisitType(const Type *T);
43 QualType VisitAtomicType(const AtomicType *T);
44 QualType VisitBuiltinType(const BuiltinType *T);
45 QualType VisitDecayedType(const DecayedType *T);
46 QualType VisitComplexType(const ComplexType *T);
47 QualType VisitPointerType(const PointerType *T);
48 QualType VisitBlockPointerType(const BlockPointerType *T);
49 QualType VisitLValueReferenceType(const LValueReferenceType *T);
50 QualType VisitRValueReferenceType(const RValueReferenceType *T);
51 QualType VisitMemberPointerType(const MemberPointerType *T);
52 QualType VisitConstantArrayType(const ConstantArrayType *T);
53 QualType VisitIncompleteArrayType(const IncompleteArrayType *T);
54 QualType VisitVariableArrayType(const VariableArrayType *T);
55 // FIXME: DependentSizedArrayType
56 // FIXME: DependentSizedExtVectorType
57 QualType VisitVectorType(const VectorType *T);
58 QualType VisitExtVectorType(const ExtVectorType *T);
59 QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T);
60 QualType VisitFunctionProtoType(const FunctionProtoType *T);
61 // FIXME: UnresolvedUsingType
62 QualType VisitParenType(const ParenType *T);
63 QualType VisitTypedefType(const TypedefType *T);
64 QualType VisitTypeOfExprType(const TypeOfExprType *T);
65 // FIXME: DependentTypeOfExprType
66 QualType VisitTypeOfType(const TypeOfType *T);
67 QualType VisitDecltypeType(const DecltypeType *T);
68 QualType VisitUnaryTransformType(const UnaryTransformType *T);
69 QualType VisitAutoType(const AutoType *T);
70 QualType VisitInjectedClassNameType(const InjectedClassNameType *T);
71 // FIXME: DependentDecltypeType
72 QualType VisitRecordType(const RecordType *T);
73 QualType VisitEnumType(const EnumType *T);
74 QualType VisitAttributedType(const AttributedType *T);
75 QualType VisitTemplateTypeParmType(const TemplateTypeParmType *T);
76 QualType VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T);
77 QualType VisitTemplateSpecializationType(const TemplateSpecializationType *T);
78 QualType VisitElaboratedType(const ElaboratedType *T);
79 // FIXME: DependentNameType
80 QualType VisitPackExpansionType(const PackExpansionType *T);
81 // FIXME: DependentTemplateSpecializationType
82 QualType VisitObjCInterfaceType(const ObjCInterfaceType *T);
83 QualType VisitObjCObjectType(const ObjCObjectType *T);
84 QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T);
85
86 // Importing declarations
87 bool ImportDeclParts(NamedDecl *D, DeclContext *&DC,
88 DeclContext *&LexicalDC, DeclarationName &Name,
89 NamedDecl *&ToD, SourceLocation &Loc);
90 void ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
91 void ImportDeclarationNameLoc(const DeclarationNameInfo &From,
92 DeclarationNameInfo& To);
93 void ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
94
95 bool ImportCastPath(CastExpr *E, CXXCastPath &Path);
96
97 typedef DesignatedInitExpr::Designator Designator;
98 Designator ImportDesignator(const Designator &D);
99
100
101 /// \brief What we should import from the definition.
102 enum ImportDefinitionKind {
103 /// \brief Import the default subset of the definition, which might be
104 /// nothing (if minimal import is set) or might be everything (if minimal
105 /// import is not set).
106 IDK_Default,
107 /// \brief Import everything.
108 IDK_Everything,
109 /// \brief Import only the bare bones needed to establish a valid
110 /// DeclContext.
111 IDK_Basic
112 };
113
114 bool shouldForceImportDeclContext(ImportDefinitionKind IDK) {
115 return IDK == IDK_Everything ||
116 (IDK == IDK_Default && !Importer.isMinimalImport());
117 }
118
119 bool ImportDefinition(RecordDecl *From, RecordDecl *To,
120 ImportDefinitionKind Kind = IDK_Default);
121 bool ImportDefinition(VarDecl *From, VarDecl *To,
122 ImportDefinitionKind Kind = IDK_Default);
123 bool ImportDefinition(EnumDecl *From, EnumDecl *To,
124 ImportDefinitionKind Kind = IDK_Default);
125 bool ImportDefinition(ObjCInterfaceDecl *From, ObjCInterfaceDecl *To,
126 ImportDefinitionKind Kind = IDK_Default);
127 bool ImportDefinition(ObjCProtocolDecl *From, ObjCProtocolDecl *To,
128 ImportDefinitionKind Kind = IDK_Default);
129 TemplateParameterList *ImportTemplateParameterList(
130 TemplateParameterList *Params);
131 TemplateArgument ImportTemplateArgument(const TemplateArgument &From);
132 TemplateArgumentLoc ImportTemplateArgumentLoc(
133 const TemplateArgumentLoc &TALoc, bool &Error);
134 bool ImportTemplateArguments(const TemplateArgument *FromArgs,
135 unsigned NumFromArgs,
136 SmallVectorImpl<TemplateArgument> &ToArgs);
137 bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord,
138 bool Complain = true);
139 bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar,
140 bool Complain = true);
141 bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord);
142 bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC);
143 bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To);
144 bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To);
145 Decl *VisitDecl(Decl *D);
146 Decl *VisitAccessSpecDecl(AccessSpecDecl *D);
147 Decl *VisitStaticAssertDecl(StaticAssertDecl *D);
148 Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D);
149 Decl *VisitNamespaceDecl(NamespaceDecl *D);
150 Decl *VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias);
151 Decl *VisitTypedefDecl(TypedefDecl *D);
152 Decl *VisitTypeAliasDecl(TypeAliasDecl *D);
153 Decl *VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
154 Decl *VisitLabelDecl(LabelDecl *D);
155 Decl *VisitEnumDecl(EnumDecl *D);
156 Decl *VisitRecordDecl(RecordDecl *D);
157 Decl *VisitEnumConstantDecl(EnumConstantDecl *D);
158 Decl *VisitFunctionDecl(FunctionDecl *D);
159 Decl *VisitCXXMethodDecl(CXXMethodDecl *D);
160 Decl *VisitCXXConstructorDecl(CXXConstructorDecl *D);
161 Decl *VisitCXXDestructorDecl(CXXDestructorDecl *D);
162 Decl *VisitCXXConversionDecl(CXXConversionDecl *D);
163 Decl *VisitFieldDecl(FieldDecl *D);
164 Decl *VisitIndirectFieldDecl(IndirectFieldDecl *D);
165 Decl *VisitFriendDecl(FriendDecl *D);
166 Decl *VisitObjCIvarDecl(ObjCIvarDecl *D);
167 Decl *VisitVarDecl(VarDecl *D);
168 Decl *VisitImplicitParamDecl(ImplicitParamDecl *D);
169 Decl *VisitParmVarDecl(ParmVarDecl *D);
170 Decl *VisitObjCMethodDecl(ObjCMethodDecl *D);
171 Decl *VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
172 Decl *VisitObjCCategoryDecl(ObjCCategoryDecl *D);
173 Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D);
174 Decl *VisitLinkageSpecDecl(LinkageSpecDecl *D);
175
176 ObjCTypeParamList *ImportObjCTypeParamList(ObjCTypeParamList *list);
177 Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
178 Decl *VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
179 Decl *VisitObjCImplementationDecl(ObjCImplementationDecl *D);
180 Decl *VisitObjCPropertyDecl(ObjCPropertyDecl *D);
181 Decl *VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
182 Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
183 Decl *VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
184 Decl *VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
185 Decl *VisitClassTemplateDecl(ClassTemplateDecl *D);
186 Decl *VisitClassTemplateSpecializationDecl(
187 ClassTemplateSpecializationDecl *D);
188 Decl *VisitVarTemplateDecl(VarTemplateDecl *D);
189 Decl *VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D);
190
191 // Importing statements
192 DeclGroupRef ImportDeclGroup(DeclGroupRef DG);
193
194 Stmt *VisitStmt(Stmt *S);
195 Stmt *VisitGCCAsmStmt(GCCAsmStmt *S);
196 Stmt *VisitDeclStmt(DeclStmt *S);
197 Stmt *VisitNullStmt(NullStmt *S);
198 Stmt *VisitCompoundStmt(CompoundStmt *S);
199 Stmt *VisitCaseStmt(CaseStmt *S);
200 Stmt *VisitDefaultStmt(DefaultStmt *S);
201 Stmt *VisitLabelStmt(LabelStmt *S);
202 Stmt *VisitAttributedStmt(AttributedStmt *S);
203 Stmt *VisitIfStmt(IfStmt *S);
204 Stmt *VisitSwitchStmt(SwitchStmt *S);
205 Stmt *VisitWhileStmt(WhileStmt *S);
206 Stmt *VisitDoStmt(DoStmt *S);
207 Stmt *VisitForStmt(ForStmt *S);
208 Stmt *VisitGotoStmt(GotoStmt *S);
209 Stmt *VisitIndirectGotoStmt(IndirectGotoStmt *S);
210 Stmt *VisitContinueStmt(ContinueStmt *S);
211 Stmt *VisitBreakStmt(BreakStmt *S);
212 Stmt *VisitReturnStmt(ReturnStmt *S);
213 // FIXME: MSAsmStmt
214 // FIXME: SEHExceptStmt
215 // FIXME: SEHFinallyStmt
216 // FIXME: SEHTryStmt
217 // FIXME: SEHLeaveStmt
218 // FIXME: CapturedStmt
219 Stmt *VisitCXXCatchStmt(CXXCatchStmt *S);
220 Stmt *VisitCXXTryStmt(CXXTryStmt *S);
221 Stmt *VisitCXXForRangeStmt(CXXForRangeStmt *S);
222 // FIXME: MSDependentExistsStmt
223 Stmt *VisitObjCForCollectionStmt(ObjCForCollectionStmt *S);
224 Stmt *VisitObjCAtCatchStmt(ObjCAtCatchStmt *S);
225 Stmt *VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S);
226 Stmt *VisitObjCAtTryStmt(ObjCAtTryStmt *S);
227 Stmt *VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S);
228 Stmt *VisitObjCAtThrowStmt(ObjCAtThrowStmt *S);
229 Stmt *VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S);
230
231 // Importing expressions
232 Expr *VisitExpr(Expr *E);
233 Expr *VisitVAArgExpr(VAArgExpr *E);
234 Expr *VisitGNUNullExpr(GNUNullExpr *E);
235 Expr *VisitPredefinedExpr(PredefinedExpr *E);
236 Expr *VisitDeclRefExpr(DeclRefExpr *E);
237 Expr *VisitImplicitValueInitExpr(ImplicitValueInitExpr *ILE);
238 Expr *VisitDesignatedInitExpr(DesignatedInitExpr *E);
239 Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
240 Expr *VisitIntegerLiteral(IntegerLiteral *E);
241 Expr *VisitFloatingLiteral(FloatingLiteral *E);
242 Expr *VisitCharacterLiteral(CharacterLiteral *E);
243 Expr *VisitStringLiteral(StringLiteral *E);
244 Expr *VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
245 Expr *VisitAtomicExpr(AtomicExpr *E);
246 Expr *VisitAddrLabelExpr(AddrLabelExpr *E);
247 Expr *VisitParenExpr(ParenExpr *E);
248 Expr *VisitParenListExpr(ParenListExpr *E);
249 Expr *VisitStmtExpr(StmtExpr *E);
250 Expr *VisitUnaryOperator(UnaryOperator *E);
251 Expr *VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E);
252 Expr *VisitBinaryOperator(BinaryOperator *E);
253 Expr *VisitConditionalOperator(ConditionalOperator *E);
254 Expr *VisitBinaryConditionalOperator(BinaryConditionalOperator *E);
255 Expr *VisitOpaqueValueExpr(OpaqueValueExpr *E);
256 Expr *VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E);
257 Expr *VisitExpressionTraitExpr(ExpressionTraitExpr *E);
258 Expr *VisitArraySubscriptExpr(ArraySubscriptExpr *E);
259 Expr *VisitCompoundAssignOperator(CompoundAssignOperator *E);
260 Expr *VisitImplicitCastExpr(ImplicitCastExpr *E);
261 Expr *VisitExplicitCastExpr(ExplicitCastExpr *E);
262 Expr *VisitOffsetOfExpr(OffsetOfExpr *OE);
263 Expr *VisitCXXThrowExpr(CXXThrowExpr *E);
264 Expr *VisitCXXNoexceptExpr(CXXNoexceptExpr *E);
265 Expr *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
266 Expr *VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E);
267 Expr *VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
268 Expr *VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE);
269 Expr *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E);
270 Expr *VisitPackExpansionExpr(PackExpansionExpr *E);
271 Expr *VisitCXXNewExpr(CXXNewExpr *CE);
272 Expr *VisitCXXDeleteExpr(CXXDeleteExpr *E);
273 Expr *VisitCXXConstructExpr(CXXConstructExpr *E);
274 Expr *VisitCXXMemberCallExpr(CXXMemberCallExpr *E);
275 Expr *VisitExprWithCleanups(ExprWithCleanups *EWC);
276 Expr *VisitCXXThisExpr(CXXThisExpr *E);
277 Expr *VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
278 Expr *VisitMemberExpr(MemberExpr *E);
279 Expr *VisitCallExpr(CallExpr *E);
280 Expr *VisitInitListExpr(InitListExpr *E);
281 Expr *VisitArrayInitLoopExpr(ArrayInitLoopExpr *E);
282 Expr *VisitArrayInitIndexExpr(ArrayInitIndexExpr *E);
283 Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
284 Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
285 Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
286
287
288 template<typename IIter, typename OIter>
289 void ImportArray(IIter Ibegin, IIter Iend, OIter Obegin) {
290 typedef typename std::remove_reference<decltype(*Obegin)>::type ItemT;
291 ASTImporter &ImporterRef = Importer;
292 std::transform(Ibegin, Iend, Obegin,
293 [&ImporterRef](ItemT From) -> ItemT {
294 return ImporterRef.Import(From);
295 });
296 }
297
298 template<typename IIter, typename OIter>
299 bool ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
300 typedef typename std::remove_reference<decltype(**Obegin)>::type ItemT;
301 ASTImporter &ImporterRef = Importer;
302 bool Failed = false;
303 std::transform(Ibegin, Iend, Obegin,
304 [&ImporterRef, &Failed](ItemT *From) -> ItemT * {
305 ItemT *To = cast_or_null<ItemT>(
306 ImporterRef.Import(From));
307 if (!To && From)
308 Failed = true;
309 return To;
310 });
311 return Failed;
312 }
313
314 template<typename InContainerTy, typename OutContainerTy>
315 bool ImportContainerChecked(const InContainerTy &InContainer,
316 OutContainerTy &OutContainer) {
317 return ImportArrayChecked(InContainer.begin(), InContainer.end(),
318 OutContainer.begin());
319 }
320
321 template<typename InContainerTy, typename OIter>
322 bool ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
323 return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
324 }
325
326 // Importing overrides.
327 void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod);
328 };
329}
330
331//----------------------------------------------------------------------------
332// Import Types
333//----------------------------------------------------------------------------
334
335using namespace clang;
336
337QualType ASTNodeImporter::VisitType(const Type *T) {
338 Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
339 << T->getTypeClassName();
340 return QualType();
341}
342
343QualType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
344 QualType UnderlyingType = Importer.Import(T->getValueType());
345 if(UnderlyingType.isNull())
346 return QualType();
347
348 return Importer.getToContext().getAtomicType(UnderlyingType);
349}
350
351QualType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
352 switch (T->getKind()) {
353#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
354 case BuiltinType::Id: \
355 return Importer.getToContext().SingletonId;
356#include "clang/Basic/OpenCLImageTypes.def"
357#define SHARED_SINGLETON_TYPE(Expansion)
358#define BUILTIN_TYPE(Id, SingletonId) \
359 case BuiltinType::Id: return Importer.getToContext().SingletonId;
360#include "clang/AST/BuiltinTypes.def"
361
362 // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
363 // context supports C++.
364
365 // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
366 // context supports ObjC.
367
368 case BuiltinType::Char_U:
369 // The context we're importing from has an unsigned 'char'. If we're
370 // importing into a context with a signed 'char', translate to
371 // 'unsigned char' instead.
372 if (Importer.getToContext().getLangOpts().CharIsSigned)
373 return Importer.getToContext().UnsignedCharTy;
374
375 return Importer.getToContext().CharTy;
376
377 case BuiltinType::Char_S:
378 // The context we're importing from has an unsigned 'char'. If we're
379 // importing into a context with a signed 'char', translate to
380 // 'unsigned char' instead.
381 if (!Importer.getToContext().getLangOpts().CharIsSigned)
382 return Importer.getToContext().SignedCharTy;
383
384 return Importer.getToContext().CharTy;
385
386 case BuiltinType::WChar_S:
387 case BuiltinType::WChar_U:
388 // FIXME: If not in C++, shall we translate to the C equivalent of
389 // wchar_t?
390 return Importer.getToContext().WCharTy;
391 }
392
393 llvm_unreachable("Invalid BuiltinType Kind!")::llvm::llvm_unreachable_internal("Invalid BuiltinType Kind!"
, "/build/llvm-toolchain-snapshot-6.0~svn318693/tools/clang/lib/AST/ASTImporter.cpp"
, 393)
;
394}
395
396QualType ASTNodeImporter::VisitDecayedType(const DecayedType *T) {
397 QualType OrigT = Importer.Import(T->getOriginalType());
398 if (OrigT.isNull())
399 return QualType();
400
401 return Importer.getToContext().getDecayedType(OrigT);
402}
403
404QualType ASTNodeImporter::VisitComplexType(const ComplexType *T) {
405 QualType ToElementType = Importer.Import(T->getElementType());
406 if (ToElementType.isNull())
407 return QualType();
408
409 return Importer.getToContext().getComplexType(ToElementType);
410}
411
412QualType ASTNodeImporter::VisitPointerType(const PointerType *T) {
413 QualType ToPointeeType = Importer.Import(T->getPointeeType());
414 if (ToPointeeType.isNull())
415 return QualType();
416
417 return Importer.getToContext().getPointerType(ToPointeeType);
418}
419
420QualType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) {
421 // FIXME: Check for blocks support in "to" context.
422 QualType ToPointeeType = Importer.Import(T->getPointeeType());
423 if (ToPointeeType.isNull())
424 return QualType();
425
426 return Importer.getToContext().getBlockPointerType(ToPointeeType);
427}
428
429QualType
430ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) {
431 // FIXME: Check for C++ support in "to" context.
432 QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten());
433 if (ToPointeeType.isNull())
434 return QualType();
435
436 return Importer.getToContext().getLValueReferenceType(ToPointeeType);
437}
438
439QualType
440ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) {
441 // FIXME: Check for C++0x support in "to" context.
442 QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten());
443 if (ToPointeeType.isNull())
444 return QualType();
445
446 return Importer.getToContext().getRValueReferenceType(ToPointeeType);
447}
448
449QualType ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) {
450 // FIXME: Check for C++ support in "to" context.
451 QualType ToPointeeType = Importer.Import(T->getPointeeType());
452 if (ToPointeeType.isNull())
453 return QualType();
454
455 QualType ClassType = Importer.Import(QualType(T->getClass(), 0));
456 return Importer.getToContext().getMemberPointerType(ToPointeeType,
457 ClassType.getTypePtr());
458}
459
460QualType ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) {
461 QualType ToElementType = Importer.Import(T->getElementType());
462 if (ToElementType.isNull())
463 return QualType();
464
465 return Importer.getToContext().getConstantArrayType(ToElementType,
466 T->getSize(),
467 T->getSizeModifier(),
468 T->getIndexTypeCVRQualifiers());
469}
470
471QualType
472ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
473 QualType ToElementType = Importer.Import(T->getElementType());
474 if (ToElementType.isNull())
475 return QualType();
476
477 return Importer.getToContext().getIncompleteArrayType(ToElementType,
478 T->getSizeModifier(),
479 T->getIndexTypeCVRQualifiers());
480}
481
482QualType ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
483 QualType ToElementType = Importer.Import(T->getElementType());
484 if (ToElementType.isNull())
485 return QualType();
486
487 Expr *Size = Importer.Import(T->getSizeExpr());
488 if (!Size)
489 return QualType();
490
491 SourceRange Brackets = Importer.Import(T->getBracketsRange());
492 return Importer.getToContext().getVariableArrayType(ToElementType, Size,
493 T->getSizeModifier(),
494 T->getIndexTypeCVRQualifiers(),
495 Brackets);
496}
497
498QualType ASTNodeImporter::VisitVectorType(const VectorType *T) {
499 QualType ToElementType = Importer.Import(T->getElementType());
500 if (ToElementType.isNull())
501 return QualType();
502
503 return Importer.getToContext().getVectorType(ToElementType,
504 T->getNumElements(),
505 T->getVectorKind());
506}
507
508QualType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) {
509 QualType ToElementType = Importer.Import(T->getElementType());
510 if (ToElementType.isNull())
511 return QualType();
512
513 return Importer.getToContext().getExtVectorType(ToElementType,
514 T->getNumElements());
515}
516
517QualType
518ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
519 // FIXME: What happens if we're importing a function without a prototype
520 // into C++? Should we make it variadic?
521 QualType ToResultType = Importer.Import(T->getReturnType());
522 if (ToResultType.isNull())
523 return QualType();
524
525 return Importer.getToContext().getFunctionNoProtoType(ToResultType,
526 T->getExtInfo());
527}
528
529QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
530 QualType ToResultType = Importer.Import(T->getReturnType());
531 if (ToResultType.isNull())
532 return QualType();
533
534 // Import argument types
535 SmallVector<QualType, 4> ArgTypes;
536 for (const auto &A : T->param_types()) {
537 QualType ArgType = Importer.Import(A);
538 if (ArgType.isNull())
539 return QualType();
540 ArgTypes.push_back(ArgType);
541 }
542
543 // Import exception types
544 SmallVector<QualType, 4> ExceptionTypes;
545 for (const auto &E : T->exceptions()) {
546 QualType ExceptionType = Importer.Import(E);
547 if (ExceptionType.isNull())
548 return QualType();
549 ExceptionTypes.push_back(ExceptionType);
550 }
551
552 FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo();
553 FunctionProtoType::ExtProtoInfo ToEPI;
554
555 ToEPI.ExtInfo = FromEPI.ExtInfo;
556 ToEPI.Variadic = FromEPI.Variadic;
557 ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
558 ToEPI.TypeQuals = FromEPI.TypeQuals;
559 ToEPI.RefQualifier = FromEPI.RefQualifier;
560 ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
561 ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
562 ToEPI.ExceptionSpec.NoexceptExpr =
563 Importer.Import(FromEPI.ExceptionSpec.NoexceptExpr);
564 ToEPI.ExceptionSpec.SourceDecl = cast_or_null<FunctionDecl>(
565 Importer.Import(FromEPI.ExceptionSpec.SourceDecl));
566 ToEPI.ExceptionSpec.SourceTemplate = cast_or_null<FunctionDecl>(
567 Importer.Import(FromEPI.ExceptionSpec.SourceTemplate));
568
569 return Importer.getToContext().getFunctionType(ToResultType, ArgTypes, ToEPI);
570}
571
572QualType ASTNodeImporter::VisitParenType(const ParenType *T) {
573 QualType ToInnerType = Importer.Import(T->getInnerType());
574 if (ToInnerType.isNull())
575 return QualType();
576
577 return Importer.getToContext().getParenType(ToInnerType);
578}
579
580QualType ASTNodeImporter::VisitTypedefType(const TypedefType *T) {
581 TypedefNameDecl *ToDecl
582 = dyn_cast_or_null<TypedefNameDecl>(Importer.Import(T->getDecl()));
583 if (!ToDecl)
584 return QualType();
585
586 return Importer.getToContext().getTypeDeclType(ToDecl);
587}
588
589QualType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {
590 Expr *ToExpr = Importer.Import(T->getUnderlyingExpr());
591 if (!ToExpr)
592 return QualType();
593
594 return Importer.getToContext().getTypeOfExprType(ToExpr);
595}
596
597QualType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
598 QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType());
599 if (ToUnderlyingType.isNull())
600 return QualType();
601
602 return Importer.getToContext().getTypeOfType(ToUnderlyingType);
603}
604
605QualType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) {
606 // FIXME: Make sure that the "to" context supports C++0x!
607 Expr *ToExpr = Importer.Import(T->getUnderlyingExpr());
608 if (!ToExpr)
609 return QualType();
610
611 QualType UnderlyingType = Importer.Import(T->getUnderlyingType());
612 if (UnderlyingType.isNull())
613 return QualType();
614
615 return Importer.getToContext().getDecltypeType(ToExpr, UnderlyingType);
616}
617
618QualType ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) {
619 QualType ToBaseType = Importer.Import(T->getBaseType());
620 QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType());
621 if (ToBaseType.isNull() || ToUnderlyingType.isNull())
622 return QualType();
623
624 return Importer.getToContext().getUnaryTransformType(ToBaseType,
625 ToUnderlyingType,
626 T->getUTTKind());
627}
628
629QualType ASTNodeImporter::VisitAutoType(const AutoType *T) {
630 // FIXME: Make sure that the "to" context supports C++11!
631 QualType FromDeduced = T->getDeducedType();
632 QualType ToDeduced;
633 if (!FromDeduced.isNull()) {
634 ToDeduced = Importer.Import(FromDeduced);
635 if (ToDeduced.isNull())
636 return QualType();
637 }
638
639 return Importer.getToContext().getAutoType(ToDeduced, T->getKeyword(),
640 /*IsDependent*/false);
641}
642
643QualType ASTNodeImporter::VisitInjectedClassNameType(
644 const InjectedClassNameType *T) {
645 CXXRecordDecl *D = cast_or_null<CXXRecordDecl>(Importer.Import(T->getDecl()));
646 if (!D)
647 return QualType();
648
649 QualType InjType = Importer.Import(T->getInjectedSpecializationType());
650 if (InjType.isNull())
651 return QualType();
652
653 // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading
654 // See comments in InjectedClassNameType definition for details
655 // return Importer.getToContext().getInjectedClassNameType(D, InjType);
656 enum {
657 TypeAlignmentInBits = 4,
658 TypeAlignment = 1 << TypeAlignmentInBits
659 };
660
661 return QualType(new (Importer.getToContext(), TypeAlignment)
662 InjectedClassNameType(D, InjType), 0);
663}
664
665QualType ASTNodeImporter::VisitRecordType(const RecordType *T) {
666 RecordDecl *ToDecl
667 = dyn_cast_or_null<RecordDecl>(Importer.Import(T->getDecl()));
668 if (!ToDecl)
669 return QualType();
670
671 return Importer.getToContext().getTagDeclType(ToDecl);
672}
673
674QualType ASTNodeImporter::VisitEnumType(const EnumType *T) {
675 EnumDecl *ToDecl
676 = dyn_cast_or_null<EnumDecl>(Importer.Import(T->getDecl()));
677 if (!ToDecl)
678 return QualType();
679
680 return Importer.getToContext().getTagDeclType(ToDecl);
681}
682
683QualType ASTNodeImporter::VisitAttributedType(const AttributedType *T) {
684 QualType FromModifiedType = T->getModifiedType();
685 QualType FromEquivalentType = T->getEquivalentType();
686 QualType ToModifiedType;
687 QualType ToEquivalentType;
688
689 if (!FromModifiedType.isNull()) {
690 ToModifiedType = Importer.Import(FromModifiedType);
691 if (ToModifiedType.isNull())
692 return QualType();
693 }
694 if (!FromEquivalentType.isNull()) {
695 ToEquivalentType = Importer.Import(FromEquivalentType);
696 if (ToEquivalentType.isNull())
697 return QualType();
698 }
699
700 return Importer.getToContext().getAttributedType(T->getAttrKind(),
701 ToModifiedType, ToEquivalentType);
702}
703
704
705QualType ASTNodeImporter::VisitTemplateTypeParmType(
706 const TemplateTypeParmType *T) {
707 TemplateTypeParmDecl *ParmDecl =
708 cast_or_null<TemplateTypeParmDecl>(Importer.Import(T->getDecl()));
709 if (!ParmDecl && T->getDecl())
710 return QualType();
711
712 return Importer.getToContext().getTemplateTypeParmType(
713 T->getDepth(), T->getIndex(), T->isParameterPack(), ParmDecl);
714}
715
716QualType ASTNodeImporter::VisitSubstTemplateTypeParmType(
717 const SubstTemplateTypeParmType *T) {
718 const TemplateTypeParmType *Replaced =
719 cast_or_null<TemplateTypeParmType>(Importer.Import(
720 QualType(T->getReplacedParameter(), 0)).getTypePtr());
721 if (!Replaced)
722 return QualType();
723
724 QualType Replacement = Importer.Import(T->getReplacementType());
725 if (Replacement.isNull())
726 return QualType();
727 Replacement = Replacement.getCanonicalType();
728
729 return Importer.getToContext().getSubstTemplateTypeParmType(
730 Replaced, Replacement);
731}
732
733QualType ASTNodeImporter::VisitTemplateSpecializationType(
734 const TemplateSpecializationType *T) {
735 TemplateName ToTemplate = Importer.Import(T->getTemplateName());
736 if (ToTemplate.isNull())
737 return QualType();
738
739 SmallVector<TemplateArgument, 2> ToTemplateArgs;
740 if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToTemplateArgs))
741 return QualType();
742
743 QualType ToCanonType;
744 if (!QualType(T, 0).isCanonical()) {
745 QualType FromCanonType
746 = Importer.getFromContext().getCanonicalType(QualType(T, 0));
747 ToCanonType =Importer.Import(FromCanonType);
748 if (ToCanonType.isNull())
749 return QualType();
750 }
751 return Importer.getToContext().getTemplateSpecializationType(ToTemplate,
752 ToTemplateArgs,
753 ToCanonType);
754}
755
756QualType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) {
757 NestedNameSpecifier *ToQualifier = nullptr;
758 // Note: the qualifier in an ElaboratedType is optional.
759 if (T->getQualifier()) {
760 ToQualifier = Importer.Import(T->getQualifier());
761 if (!ToQualifier)
762 return QualType();
763 }
764
765 QualType ToNamedType = Importer.Import(T->getNamedType());
766 if (ToNamedType.isNull())
767 return QualType();
768
769 return Importer.getToContext().getElaboratedType(T->getKeyword(),
770 ToQualifier, ToNamedType);
771}
772
773QualType ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) {
774 QualType Pattern = Importer.Import(T->getPattern());
775 if (Pattern.isNull())
776 return QualType();
777
778 return Importer.getToContext().getPackExpansionType(Pattern,
779 T->getNumExpansions());
780}
781
782QualType ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
783 ObjCInterfaceDecl *Class
784 = dyn_cast_or_null<ObjCInterfaceDecl>(Importer.Import(T->getDecl()));
785 if (!Class)
786 return QualType();
787
788 return Importer.getToContext().getObjCInterfaceType(Class);
789}
790
791QualType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) {
792 QualType ToBaseType = Importer.Import(T->getBaseType());
793 if (ToBaseType.isNull())
794 return QualType();
795
796 SmallVector<QualType, 4> TypeArgs;
797 for (auto TypeArg : T->getTypeArgsAsWritten()) {
798 QualType ImportedTypeArg = Importer.Import(TypeArg);
799 if (ImportedTypeArg.isNull())
800 return QualType();
801
802 TypeArgs.push_back(ImportedTypeArg);
803 }
804
805 SmallVector<ObjCProtocolDecl *, 4> Protocols;
806 for (auto *P : T->quals()) {
807 ObjCProtocolDecl *Protocol
808 = dyn_cast_or_null<ObjCProtocolDecl>(Importer.Import(P));
809 if (!Protocol)
810 return QualType();
811 Protocols.push_back(Protocol);
812 }
813
814 return Importer.getToContext().getObjCObjectType(ToBaseType, TypeArgs,
815 Protocols,
816 T->isKindOfTypeAsWritten());
817}
818
819QualType
820ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
821 QualType ToPointeeType = Importer.Import(T->getPointeeType());
822 if (ToPointeeType.isNull())
823 return QualType();
824
825 return Importer.getToContext().getObjCObjectPointerType(ToPointeeType);
826}
827
828//----------------------------------------------------------------------------
829// Import Declarations
830//----------------------------------------------------------------------------
831bool ASTNodeImporter::ImportDeclParts(NamedDecl *D, DeclContext *&DC,
832 DeclContext *&LexicalDC,
833 DeclarationName &Name,
834 NamedDecl *&ToD,
835 SourceLocation &Loc) {
836 // Import the context of this declaration.
837 DC = Importer.ImportContext(D->getDeclContext());
838 if (!DC)
839 return true;
840
841 LexicalDC = DC;
842 if (D->getDeclContext() != D->getLexicalDeclContext()) {
843 LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
844 if (!LexicalDC)
845 return true;
846 }
847
848 // Import the name of this declaration.
849 Name = Importer.Import(D->getDeclName());
850 if (D->getDeclName() && !Name)
851 return true;
852
853 // Import the location of this declaration.
854 Loc = Importer.Import(D->getLocation());
855 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
856 return false;
857}
858
859void ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) {
860 if (!FromD)
861 return;
862
863 if (!ToD) {
864 ToD = Importer.Import(FromD);
865 if (!ToD)
866 return;
867 }
868
869 if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
870 if (RecordDecl *ToRecord = cast_or_null<RecordDecl>(ToD)) {
871 if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && !ToRecord->getDefinition()) {
872 ImportDefinition(FromRecord, ToRecord);
873 }
874 }
875 return;
876 }
877
878 if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
879 if (EnumDecl *ToEnum = cast_or_null<EnumDecl>(ToD)) {
880 if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
881 ImportDefinition(FromEnum, ToEnum);
882 }
883 }
884 return;
885 }
886}
887
888void
889ASTNodeImporter::ImportDeclarationNameLoc(const DeclarationNameInfo &From,
890 DeclarationNameInfo& To) {
891 // NOTE: To.Name and To.Loc are already imported.
892 // We only have to import To.LocInfo.
893 switch (To.getName().getNameKind()) {
894 case DeclarationName::Identifier:
895 case DeclarationName::ObjCZeroArgSelector:
896 case DeclarationName::ObjCOneArgSelector:
897 case DeclarationName::ObjCMultiArgSelector:
898 case DeclarationName::CXXUsingDirective:
899 case DeclarationName::CXXDeductionGuideName:
900 return;
901
902 case DeclarationName::CXXOperatorName: {
903 SourceRange Range = From.getCXXOperatorNameRange();
904 To.setCXXOperatorNameRange(Importer.Import(Range));
905 return;
906 }
907 case DeclarationName::CXXLiteralOperatorName: {
908 SourceLocation Loc = From.getCXXLiteralOperatorNameLoc();
909 To.setCXXLiteralOperatorNameLoc(Importer.Import(Loc));
910 return;
911 }
912 case DeclarationName::CXXConstructorName:
913 case DeclarationName::CXXDestructorName:
914 case DeclarationName::CXXConversionFunctionName: {
915 TypeSourceInfo *FromTInfo = From.getNamedTypeInfo();
916 To.setNamedTypeInfo(Importer.Import(FromTInfo));
917 return;
918 }
919 }
920 llvm_unreachable("Unknown name kind.")::llvm::llvm_unreachable_internal("Unknown name kind.", "/build/llvm-toolchain-snapshot-6.0~svn318693/tools/clang/lib/AST/ASTImporter.cpp"
, 920)
;
921}
922
923void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) {
924 if (Importer.isMinimalImport() && !ForceImport) {
9
Assuming the condition is false
925 Importer.ImportContext(FromDC);
926 return;
927 }
928
929 for (auto *From : FromDC->decls())
930 Importer.Import(From);
10
Calling 'ASTImporter::Import'
931}
932
933bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To,
934 ImportDefinitionKind Kind) {
935 if (To->getDefinition() || To->isBeingDefined()) {
936 if (Kind == IDK_Everything)
937 ImportDeclContext(From, /*ForceImport=*/true);
938
939 return false;
940 }
941
942 To->startDefinition();
943
944 // Add base classes.
945 if (CXXRecordDecl *ToCXX = dyn_cast<CXXRecordDecl>(To)) {
946 CXXRecordDecl *FromCXX = cast<CXXRecordDecl>(From);
947
948 struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
949 struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
950 ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor;
951 ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers;
952 ToData.Aggregate = FromData.Aggregate;
953 ToData.PlainOldData = FromData.PlainOldData;
954 ToData.Empty = FromData.Empty;
955 ToData.Polymorphic = FromData.Polymorphic;
956 ToData.Abstract = FromData.Abstract;
957 ToData.IsStandardLayout = FromData.IsStandardLayout;
958 ToData.HasNoNonEmptyBases = FromData.HasNoNonEmptyBases;
959 ToData.HasPrivateFields = FromData.HasPrivateFields;
960 ToData.HasProtectedFields = FromData.HasProtectedFields;
961 ToData.HasPublicFields = FromData.HasPublicFields;
962 ToData.HasMutableFields = FromData.HasMutableFields;
963 ToData.HasVariantMembers = FromData.HasVariantMembers;
964 ToData.HasOnlyCMembers = FromData.HasOnlyCMembers;
965 ToData.HasInClassInitializer = FromData.HasInClassInitializer;
966 ToData.HasUninitializedReferenceMember
967 = FromData.HasUninitializedReferenceMember;
968 ToData.HasUninitializedFields = FromData.HasUninitializedFields;
969 ToData.HasInheritedConstructor = FromData.HasInheritedConstructor;
970 ToData.HasInheritedAssignment = FromData.HasInheritedAssignment;
971 ToData.NeedOverloadResolutionForCopyConstructor
972 = FromData.NeedOverloadResolutionForCopyConstructor;
973 ToData.NeedOverloadResolutionForMoveConstructor
974 = FromData.NeedOverloadResolutionForMoveConstructor;
975 ToData.NeedOverloadResolutionForMoveAssignment
976 = FromData.NeedOverloadResolutionForMoveAssignment;
977 ToData.NeedOverloadResolutionForDestructor
978 = FromData.NeedOverloadResolutionForDestructor;
979 ToData.DefaultedCopyConstructorIsDeleted
980 = FromData.DefaultedCopyConstructorIsDeleted;
981 ToData.DefaultedMoveConstructorIsDeleted
982 = FromData.DefaultedMoveConstructorIsDeleted;
983 ToData.DefaultedMoveAssignmentIsDeleted
984 = FromData.DefaultedMoveAssignmentIsDeleted;
985 ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted;
986 ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers;
987 ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor;
988 ToData.HasConstexprNonCopyMoveConstructor
989 = FromData.HasConstexprNonCopyMoveConstructor;
990 ToData.HasDefaultedDefaultConstructor
991 = FromData.HasDefaultedDefaultConstructor;
992 ToData.CanPassInRegisters = FromData.CanPassInRegisters;
993 ToData.DefaultedDefaultConstructorIsConstexpr
994 = FromData.DefaultedDefaultConstructorIsConstexpr;
995 ToData.HasConstexprDefaultConstructor
996 = FromData.HasConstexprDefaultConstructor;
997 ToData.HasNonLiteralTypeFieldsOrBases
998 = FromData.HasNonLiteralTypeFieldsOrBases;
999 // ComputedVisibleConversions not imported.
1000 ToData.UserProvidedDefaultConstructor
1001 = FromData.UserProvidedDefaultConstructor;
1002 ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers;
1003 ToData.ImplicitCopyConstructorCanHaveConstParamForVBase
1004 = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase;
1005 ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase
1006 = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase;
1007 ToData.ImplicitCopyAssignmentHasConstParam
1008 = FromData.ImplicitCopyAssignmentHasConstParam;
1009 ToData.HasDeclaredCopyConstructorWithConstParam
1010 = FromData.HasDeclaredCopyConstructorWithConstParam;
1011 ToData.HasDeclaredCopyAssignmentWithConstParam
1012 = FromData.HasDeclaredCopyAssignmentWithConstParam;
1013 ToData.IsLambda = FromData.IsLambda;
1014
1015 SmallVector<CXXBaseSpecifier *, 4> Bases;
1016 for (const auto &Base1 : FromCXX->bases()) {
1017 QualType T = Importer.Import(Base1.getType());
1018 if (T.isNull())
1019 return true;
1020
1021 SourceLocation EllipsisLoc;
1022 if (Base1.isPackExpansion())
1023 EllipsisLoc = Importer.Import(Base1.getEllipsisLoc());
1024
1025 // Ensure that we have a definition for the base.
1026 ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl());
1027
1028 Bases.push_back(
1029 new (Importer.getToContext())
1030 CXXBaseSpecifier(Importer.Import(Base1.getSourceRange()),
1031 Base1.isVirtual(),
1032 Base1.isBaseOfClass(),
1033 Base1.getAccessSpecifierAsWritten(),
1034 Importer.Import(Base1.getTypeSourceInfo()),
1035 EllipsisLoc));
1036 }
1037 if (!Bases.empty())
1038 ToCXX->setBases(Bases.data(), Bases.size());
1039 }
1040
1041 if (shouldForceImportDeclContext(Kind))
1042 ImportDeclContext(From, /*ForceImport=*/true);
1043
1044 To->completeDefinition();
1045 return false;
1046}
1047
1048bool ASTNodeImporter::ImportDefinition(VarDecl *From, VarDecl *To,
1049 ImportDefinitionKind Kind) {
1050 if (To->getAnyInitializer())
1051 return false;
1052
1053 // FIXME: Can we really import any initializer? Alternatively, we could force
1054 // ourselves to import every declaration of a variable and then only use
1055 // getInit() here.
1056 To->setInit(Importer.Import(const_cast<Expr *>(From->getAnyInitializer())));
1057
1058 // FIXME: Other bits to merge?
1059
1060 return false;
1061}
1062
1063bool ASTNodeImporter::ImportDefinition(EnumDecl *From, EnumDecl *To,
1064 ImportDefinitionKind Kind) {
1065 if (To->getDefinition() || To->isBeingDefined()) {
1066 if (Kind == IDK_Everything)
1067 ImportDeclContext(From, /*ForceImport=*/true);
1068 return false;
1069 }
1070
1071 To->startDefinition();
1072
1073 QualType T = Importer.Import(Importer.getFromContext().getTypeDeclType(From));
1074 if (T.isNull())
1075 return true;
1076
1077 QualType ToPromotionType = Importer.Import(From->getPromotionType());
1078 if (ToPromotionType.isNull())
1079 return true;
1080
1081 if (shouldForceImportDeclContext(Kind))
1082 ImportDeclContext(From, /*ForceImport=*/true);
1083
1084 // FIXME: we might need to merge the number of positive or negative bits
1085 // if the enumerator lists don't match.
1086 To->completeDefinition(T, ToPromotionType,
1087 From->getNumPositiveBits(),
1088 From->getNumNegativeBits());
1089 return false;
1090}
1091
1092TemplateParameterList *ASTNodeImporter::ImportTemplateParameterList(
1093 TemplateParameterList *Params) {
1094 SmallVector<NamedDecl *, 4> ToParams(Params->size());
1095 if (ImportContainerChecked(*Params, ToParams))
1096 return nullptr;
1097
1098 Expr *ToRequiresClause;
1099 if (Expr *const R = Params->getRequiresClause()) {
1100 ToRequiresClause = Importer.Import(R);
1101 if (!ToRequiresClause)
1102 return nullptr;
1103 } else {
1104 ToRequiresClause = nullptr;
1105 }
1106
1107 return TemplateParameterList::Create(Importer.getToContext(),
1108 Importer.Import(Params->getTemplateLoc()),
1109 Importer.Import(Params->getLAngleLoc()),
1110 ToParams,
1111 Importer.Import(Params->getRAngleLoc()),
1112 ToRequiresClause);
1113}
1114
1115TemplateArgument
1116ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) {
1117 switch (From.getKind()) {
1118 case TemplateArgument::Null:
1119 return TemplateArgument();
1120
1121 case TemplateArgument::Type: {
1122 QualType ToType = Importer.Import(From.getAsType());
1123 if (ToType.isNull())
1124 return TemplateArgument();
1125 return TemplateArgument(ToType);
1126 }
1127
1128 case TemplateArgument::Integral: {
1129 QualType ToType = Importer.Import(From.getIntegralType());
1130 if (ToType.isNull())
1131 return TemplateArgument();
1132 return TemplateArgument(From, ToType);
1133 }
1134
1135 case TemplateArgument::Declaration: {
1136 ValueDecl *To = cast_or_null<ValueDecl>(Importer.Import(From.getAsDecl()));
1137 QualType ToType = Importer.Import(From.getParamTypeForDecl());
1138 if (!To || ToType.isNull())
1139 return TemplateArgument();
1140 return TemplateArgument(To, ToType);
1141 }
1142
1143 case TemplateArgument::NullPtr: {
1144 QualType ToType = Importer.Import(From.getNullPtrType());
1145 if (ToType.isNull())
1146 return TemplateArgument();
1147 return TemplateArgument(ToType, /*isNullPtr*/true);
1148 }
1149
1150 case TemplateArgument::Template: {
1151 TemplateName ToTemplate = Importer.Import(From.getAsTemplate());
1152 if (ToTemplate.isNull())
1153 return TemplateArgument();
1154
1155 return TemplateArgument(ToTemplate);
1156 }
1157
1158 case TemplateArgument::TemplateExpansion: {
1159 TemplateName ToTemplate
1160 = Importer.Import(From.getAsTemplateOrTemplatePattern());
1161 if (ToTemplate.isNull())
1162 return TemplateArgument();
1163
1164 return TemplateArgument(ToTemplate, From.getNumTemplateExpansions());
1165 }
1166
1167 case TemplateArgument::Expression:
1168 if (Expr *ToExpr = Importer.Import(From.getAsExpr()))
1169 return TemplateArgument(ToExpr);
1170 return TemplateArgument();
1171
1172 case TemplateArgument::Pack: {
1173 SmallVector<TemplateArgument, 2> ToPack;
1174 ToPack.reserve(From.pack_size());
1175 if (ImportTemplateArguments(From.pack_begin(), From.pack_size(), ToPack))
1176 return TemplateArgument();
1177
1178 return TemplateArgument(
1179 llvm::makeArrayRef(ToPack).copy(Importer.getToContext()));
1180 }
1181 }
1182
1183 llvm_unreachable("Invalid template argument kind")::llvm::llvm_unreachable_internal("Invalid template argument kind"
, "/build/llvm-toolchain-snapshot-6.0~svn318693/tools/clang/lib/AST/ASTImporter.cpp"
, 1183)
;
1184}
1185
1186TemplateArgumentLoc ASTNodeImporter::ImportTemplateArgumentLoc(
1187 const TemplateArgumentLoc &TALoc, bool &Error) {
1188 Error = false;
1189 TemplateArgument Arg = ImportTemplateArgument(TALoc.getArgument());
1190 TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
1191 TemplateArgumentLocInfo ToInfo;
1192 if (Arg.getKind() == TemplateArgument::Expression) {
1193 Expr *E = Importer.Import(FromInfo.getAsExpr());
1194 ToInfo = TemplateArgumentLocInfo(E);
1195 if (!E)
1196 Error = true;
1197 } else if (Arg.getKind() == TemplateArgument::Type) {
1198 if (TypeSourceInfo *TSI = Importer.Import(FromInfo.getAsTypeSourceInfo()))
1199 ToInfo = TemplateArgumentLocInfo(TSI);
1200 else
1201 Error = true;
1202 } else {
1203 ToInfo = TemplateArgumentLocInfo(
1204 Importer.Import(FromInfo.getTemplateQualifierLoc()),
1205 Importer.Import(FromInfo.getTemplateNameLoc()),
1206 Importer.Import(FromInfo.getTemplateEllipsisLoc()));
1207 }
1208 return TemplateArgumentLoc(Arg, ToInfo);
1209}
1210
1211bool ASTNodeImporter::ImportTemplateArguments(const TemplateArgument *FromArgs,
1212 unsigned NumFromArgs,
1213 SmallVectorImpl<TemplateArgument> &ToArgs) {
1214 for (unsigned I = 0; I != NumFromArgs; ++I) {
1215 TemplateArgument To = ImportTemplateArgument(FromArgs[I]);
1216 if (To.isNull() && !FromArgs[I].isNull())
1217 return true;
1218
1219 ToArgs.push_back(To);
1220 }
1221
1222 return false;
1223}
1224
1225bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord,
1226 RecordDecl *ToRecord, bool Complain) {
1227 // Eliminate a potential failure point where we attempt to re-import
1228 // something we're trying to import while completing ToRecord.
1229 Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord);
1230 if (ToOrigin) {
1231 RecordDecl *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin);
1232 if (ToOriginRecord)
1233 ToRecord = ToOriginRecord;
1234 }
1235
1236 StructuralEquivalenceContext Ctx(Importer.getFromContext(),
1237 ToRecord->getASTContext(),
1238 Importer.getNonEquivalentDecls(),
1239 false, Complain);
1240 return Ctx.IsStructurallyEquivalent(FromRecord, ToRecord);
1241}
1242
1243bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar,
1244 bool Complain) {
1245 StructuralEquivalenceContext Ctx(
1246 Importer.getFromContext(), Importer.getToContext(),
1247 Importer.getNonEquivalentDecls(), false, Complain);
1248 return Ctx.IsStructurallyEquivalent(FromVar, ToVar);
1249}
1250
1251bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) {
1252 StructuralEquivalenceContext Ctx(Importer.getFromContext(),
1253 Importer.getToContext(),
1254 Importer.getNonEquivalentDecls());
1255 return Ctx.IsStructurallyEquivalent(FromEnum, ToEnum);
1256}
1257
1258bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC,
1259 EnumConstantDecl *ToEC)
1260{
1261 const llvm::APSInt &FromVal = FromEC->getInitVal();
1262 const llvm::APSInt &ToVal = ToEC->getInitVal();
1263
1264 return FromVal.isSigned() == ToVal.isSigned() &&
1265 FromVal.getBitWidth() == ToVal.getBitWidth() &&
1266 FromVal == ToVal;
1267}
1268
1269bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From,
1270 ClassTemplateDecl *To) {
1271 StructuralEquivalenceContext Ctx(Importer.getFromContext(),
1272 Importer.getToContext(),
1273 Importer.getNonEquivalentDecls());
1274 return Ctx.IsStructurallyEquivalent(From, To);
1275}
1276
1277bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From,
1278 VarTemplateDecl *To) {
1279 StructuralEquivalenceContext Ctx(Importer.getFromContext(),
1280 Importer.getToContext(),
1281 Importer.getNonEquivalentDecls());
1282 return Ctx.IsStructurallyEquivalent(From, To);
1283}
1284
1285Decl *ASTNodeImporter::VisitDecl(Decl *D) {
1286 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
1287 << D->getDeclKindName();
1288 return nullptr;
1289}
1290
1291Decl *ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
1292 TranslationUnitDecl *ToD =
1293 Importer.getToContext().getTranslationUnitDecl();
1294
1295 Importer.Imported(D, ToD);
1296
1297 return ToD;
1298}
1299
1300Decl *ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) {
1301
1302 SourceLocation Loc = Importer.Import(D->getLocation());
1303 SourceLocation ColonLoc = Importer.Import(D->getColonLoc());
1304
1305 // Import the context of this declaration.
1306 DeclContext *DC = Importer.ImportContext(D->getDeclContext());
1307 if (!DC)
1308 return nullptr;
1309
1310 AccessSpecDecl *accessSpecDecl
1311 = AccessSpecDecl::Create(Importer.getToContext(), D->getAccess(),
1312 DC, Loc, ColonLoc);
1313
1314 if (!accessSpecDecl)
1315 return nullptr;
1316
1317 // Lexical DeclContext and Semantic DeclContext
1318 // is always the same for the accessSpec.
1319 accessSpecDecl->setLexicalDeclContext(DC);
1320 DC->addDeclInternal(accessSpecDecl);
1321
1322 return accessSpecDecl;
1323}
1324
1325Decl *ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) {
1326 DeclContext *DC = Importer.ImportContext(D->getDeclContext());
1327 if (!DC)
1328 return nullptr;
1329
1330 DeclContext *LexicalDC = DC;
1331
1332 // Import the location of this declaration.
1333 SourceLocation Loc = Importer.Import(D->getLocation());
1334
1335 Expr *AssertExpr = Importer.Import(D->getAssertExpr());
1336 if (!AssertExpr)
1337 return nullptr;
1338
1339 StringLiteral *FromMsg = D->getMessage();
1340 StringLiteral *ToMsg = cast_or_null<StringLiteral>(Importer.Import(FromMsg));
1341 if (!ToMsg && FromMsg)
1342 return nullptr;
1343
1344 StaticAssertDecl *ToD = StaticAssertDecl::Create(
1345 Importer.getToContext(), DC, Loc, AssertExpr, ToMsg,
1346 Importer.Import(D->getRParenLoc()), D->isFailed());
1347
1348 ToD->setLexicalDeclContext(LexicalDC);
1349 LexicalDC->addDeclInternal(ToD);
1350 Importer.Imported(D, ToD);
1351 return ToD;
1352}
1353
1354Decl *ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) {
1355 // Import the major distinguishing characteristics of this namespace.
1356 DeclContext *DC, *LexicalDC;
1357 DeclarationName Name;
1358 SourceLocation Loc;
1359 NamedDecl *ToD;
1360 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
1361 return nullptr;
1362 if (ToD)
1363 return ToD;
1364
1365 NamespaceDecl *MergeWithNamespace = nullptr;
1366 if (!Name) {
1367 // This is an anonymous namespace. Adopt an existing anonymous
1368 // namespace if we can.
1369 // FIXME: Not testable.
1370 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(DC))
1371 MergeWithNamespace = TU->getAnonymousNamespace();
1372 else
1373 MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace();
1374 } else {
1375 SmallVector<NamedDecl *, 4> ConflictingDecls;
1376 SmallVector<NamedDecl *, 2> FoundDecls;
1377 DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
1378 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
1379 if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Namespace))
1380 continue;
1381
1382 if (NamespaceDecl *FoundNS = dyn_cast<NamespaceDecl>(FoundDecls[I])) {
1383 MergeWithNamespace = FoundNS;
1384 ConflictingDecls.clear();
1385 break;
1386 }
1387
1388 ConflictingDecls.push_back(FoundDecls[I]);
1389 }
1390
1391 if (!ConflictingDecls.empty()) {
1392 Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace,
1393 ConflictingDecls.data(),
1394 ConflictingDecls.size());
1395 }
1396 }
1397
1398 // Create the "to" namespace, if needed.
1399 NamespaceDecl *ToNamespace = MergeWithNamespace;
1400 if (!ToNamespace) {
1401 ToNamespace = NamespaceDecl::Create(Importer.getToContext(), DC,
1402 D->isInline(),
1403 Importer.Import(D->getLocStart()),
1404 Loc, Name.getAsIdentifierInfo(),
1405 /*PrevDecl=*/nullptr);
1406 ToNamespace->setLexicalDeclContext(LexicalDC);
1407 LexicalDC->addDeclInternal(ToNamespace);
1408
1409 // If this is an anonymous namespace, register it as the anonymous
1410 // namespace within its context.
1411 if (!Name) {
1412 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(DC))
1413 TU->setAnonymousNamespace(ToNamespace);
1414 else
1415 cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
1416 }
1417 }
1418 Importer.Imported(D, ToNamespace);
1419
1420 ImportDeclContext(D);
1421
1422 return ToNamespace;
1423}
1424
1425Decl *ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) {
1426 // Import the major distinguishing characteristics of this typedef.
1427 DeclContext *DC, *LexicalDC;
1428 DeclarationName Name;
1429 SourceLocation Loc;
1430 NamedDecl *ToD;
1431 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
1432 return nullptr;
1433 if (ToD)
1434 return ToD;
1435
1436 // If this typedef is not in block scope, determine whether we've
1437 // seen a typedef with the same name (that we can merge with) or any
1438 // other entity by that name (which name lookup could conflict with).
1439 if (!DC->isFunctionOrMethod()) {
1440 SmallVector<NamedDecl *, 4> ConflictingDecls;
1441 unsigned IDNS = Decl::IDNS_Ordinary;
1442 SmallVector<NamedDecl *, 2> FoundDecls;
1443 DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
1444 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
1445 if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
1446 continue;
1447 if (TypedefNameDecl *FoundTypedef =
1448 dyn_cast<TypedefNameDecl>(FoundDecls[I])) {
1449 if (Importer.IsStructurallyEquivalent(D->getUnderlyingType(),
1450 FoundTypedef->getUnderlyingType()))
1451 return Importer.Imported(D, FoundTypedef);
1452 }
1453
1454 ConflictingDecls.push_back(FoundDecls[I]);
1455 }
1456
1457 if (!ConflictingDecls.empty()) {
1458 Name = Importer.HandleNameConflict(Name, DC, IDNS,
1459 ConflictingDecls.data(),
1460 ConflictingDecls.size());
1461 if (!Name)
1462 return nullptr;
1463 }
1464 }
1465
1466 // Import the underlying type of this typedef;
1467 QualType T = Importer.Import(D->getUnderlyingType());
1468 if (T.isNull())
1469 return nullptr;
1470
1471 // Create the new typedef node.
1472 TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
1473 SourceLocation StartL = Importer.Import(D->getLocStart());
1474 TypedefNameDecl *ToTypedef;
1475 if (IsAlias)
1476 ToTypedef = TypeAliasDecl::Create(Importer.getToContext(), DC,
1477 StartL, Loc,
1478 Name.getAsIdentifierInfo(),
1479 TInfo);
1480 else
1481 ToTypedef = TypedefDecl::Create(Importer.getToContext(), DC,
1482 StartL, Loc,
1483 Name.getAsIdentifierInfo(),
1484 TInfo);
1485
1486 ToTypedef->setAccess(D->getAccess());
1487 ToTypedef->setLexicalDeclContext(LexicalDC);
1488 Importer.Imported(D, ToTypedef);
1489 LexicalDC->addDeclInternal(ToTypedef);
1490
1491 return ToTypedef;
1492}
1493
1494Decl *ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) {
1495 return VisitTypedefNameDecl(D, /*IsAlias=*/false);
1496}
1497
1498Decl *ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) {
1499 return VisitTypedefNameDecl(D, /*IsAlias=*/true);
1500}
1501
1502Decl *ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1503 // Import the major distinguishing characteristics of this typedef.
1504 DeclContext *DC, *LexicalDC;
1505 DeclarationName Name;
1506 SourceLocation Loc;
1507 NamedDecl *ToD;
1508 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
1509 return nullptr;
1510 if (ToD)
1511 return ToD;
1512
1513 // If this typedef is not in block scope, determine whether we've
1514 // seen a typedef with the same name (that we can merge with) or any
1515 // other entity by that name (which name lookup could conflict with).
1516 if (!DC->isFunctionOrMethod()) {
1517 SmallVector<NamedDecl *, 4> ConflictingDecls;
1518 unsigned IDNS = Decl::IDNS_Ordinary;
1519 SmallVector<NamedDecl *, 2> FoundDecls;
1520 DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
1521 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
1522 if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
1523 continue;
1524 if (auto *FoundAlias =
1525 dyn_cast<TypeAliasTemplateDecl>(FoundDecls[I]))
1526 return Importer.Imported(D, FoundAlias);
1527 ConflictingDecls.push_back(FoundDecls[I]);
1528 }
1529
1530 if (!ConflictingDecls.empty()) {
1531 Name = Importer.HandleNameConflict(Name, DC, IDNS,
1532 ConflictingDecls.data(),
1533 ConflictingDecls.size());
1534 if (!Name)
1535 return nullptr;
1536 }
1537 }
1538
1539 TemplateParameterList *Params = ImportTemplateParameterList(
1540 D->getTemplateParameters());
1541 if (!Params)
1542 return nullptr;
1543
1544 NamedDecl *TemplDecl = cast_or_null<NamedDecl>(
1545 Importer.Import(D->getTemplatedDecl()));
1546 if (!TemplDecl)
1547 return nullptr;
1548
1549 TypeAliasTemplateDecl *ToAlias = TypeAliasTemplateDecl::Create(
1550 Importer.getToContext(), DC, Loc, Name, Params, TemplDecl);
1551
1552 ToAlias->setAccess(D->getAccess());
1553 ToAlias->setLexicalDeclContext(LexicalDC);
1554 Importer.Imported(D, ToAlias);
1555 LexicalDC->addDeclInternal(ToAlias);
1556 return ToD;
1557}
1558
1559Decl *ASTNodeImporter::VisitLabelDecl(LabelDecl *D) {
1560 // Import the major distinguishing characteristics of this label.
1561 DeclContext *DC, *LexicalDC;
1562 DeclarationName Name;
1563 SourceLocation Loc;
1564 NamedDecl *ToD;
1565 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
1566 return nullptr;
1567 if (ToD)
1568 return ToD;
1569
1570 assert(LexicalDC->isFunctionOrMethod())(static_cast <bool> (LexicalDC->isFunctionOrMethod()
) ? void (0) : __assert_fail ("LexicalDC->isFunctionOrMethod()"
, "/build/llvm-toolchain-snapshot-6.0~svn318693/tools/clang/lib/AST/ASTImporter.cpp"
, 1570, __extension__ __PRETTY_FUNCTION__))
;
1571
1572 LabelDecl *ToLabel = D->isGnuLocal()
1573 ? LabelDecl::Create(Importer.getToContext(),
1574 DC, Importer.Import(D->getLocation()),
1575 Name.getAsIdentifierInfo(),
1576 Importer.Import(D->getLocStart()))
1577 : LabelDecl::Create(Importer.getToContext(),
1578 DC, Importer.Import(D->getLocation()),
1579 Name.getAsIdentifierInfo());
1580 Importer.Imported(D, ToLabel);
1581
1582 LabelStmt *Label = cast_or_null<LabelStmt>(Importer.Import(D->getStmt()));
1583 if (!Label)
1584 return nullptr;
1585
1586 ToLabel->setStmt(Label);
1587 ToLabel->setLexicalDeclContext(LexicalDC);
1588 LexicalDC->addDeclInternal(ToLabel);
1589 return ToLabel;
1590}
1591
1592Decl *ASTNodeImporter::VisitEnumDecl(EnumDecl *D) {
1593 // Import the major distinguishing characteristics of this enum.
1594 DeclContext *DC, *LexicalDC;
1595 DeclarationName Name;
1596 SourceLocation Loc;
1597 NamedDecl *ToD;
1598 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
1599 return nullptr;
1600 if (ToD)
1601 return ToD;
1602
1603 // Figure out what enum name we're looking for.
1604 unsigned IDNS = Decl::IDNS_Tag;
1605 DeclarationName SearchName = Name;
1606 if (!SearchName && D->getTypedefNameForAnonDecl()) {
1607 SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName());
1608 IDNS = Decl::IDNS_Ordinary;
1609 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
1610 IDNS |= Decl::IDNS_Ordinary;
1611
1612 // We may already have an enum of the same name; try to find and match it.
1613 if (!DC->isFunctionOrMethod() && SearchName) {
1614 SmallVector<NamedDecl *, 4> ConflictingDecls;
1615 SmallVector<NamedDecl *, 2> FoundDecls;
1616 DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls);
1617 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
1618 if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
1619 continue;
1620
1621 Decl *Found = FoundDecls[I];
1622 if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
1623 if (const TagType *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
1624 Found = Tag->getDecl();
1625 }
1626
1627 if (EnumDecl *FoundEnum = dyn_cast<EnumDecl>(Found)) {
1628 if (IsStructuralMatch(D, FoundEnum))
1629 return Importer.Imported(D, FoundEnum);
1630 }
1631
1632 ConflictingDecls.push_back(FoundDecls[I]);
1633 }
1634
1635 if (!ConflictingDecls.empty()) {
1636 Name = Importer.HandleNameConflict(Name, DC, IDNS,
1637 ConflictingDecls.data(),
1638 ConflictingDecls.size());
1639 }
1640 }
1641
1642 // Create the enum declaration.
1643 EnumDecl *D2 = EnumDecl::Create(Importer.getToContext(), DC,
1644 Importer.Import(D->getLocStart()),
1645 Loc, Name.getAsIdentifierInfo(), nullptr,
1646 D->isScoped(), D->isScopedUsingClassTag(),
1647 D->isFixed());
1648 // Import the qualifier, if any.
1649 D2->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
1650 D2->setAccess(D->getAccess());
1651 D2->setLexicalDeclContext(LexicalDC);
1652 Importer.Imported(D, D2);
1653 LexicalDC->addDeclInternal(D2);
1654
1655 // Import the integer type.
1656 QualType ToIntegerType = Importer.Import(D->getIntegerType());
1657 if (ToIntegerType.isNull())
1658 return nullptr;
1659 D2->setIntegerType(ToIntegerType);
1660
1661 // Import the definition
1662 if (D->isCompleteDefinition() && ImportDefinition(D, D2))
1663 return nullptr;
1664
1665 return D2;
1666}
1667
1668Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) {
1669 // If this record has a definition in the translation unit we're coming from,
1670 // but this particular declaration is not that definition, import the
1671 // definition and map to that.
1672 TagDecl *Definition = D->getDefinition();
1673 if (Definition && Definition != D) {
1674 Decl *ImportedDef = Importer.Import(Definition);
1675 if (!ImportedDef)
1676 return nullptr;
1677
1678 return Importer.Imported(D, ImportedDef);
1679 }
1680
1681 // Import the major distinguishing characteristics of this record.
1682 DeclContext *DC, *LexicalDC;
1683 DeclarationName Name;
1684 SourceLocation Loc;
1685 NamedDecl *ToD;
1686 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
1687 return nullptr;
1688 if (ToD)
1689 return ToD;
1690
1691 // Figure out what structure name we're looking for.
1692 unsigned IDNS = Decl::IDNS_Tag;
1693 DeclarationName SearchName = Name;
1694 if (!SearchName && D->getTypedefNameForAnonDecl()) {
1695 SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName());
1696 IDNS = Decl::IDNS_Ordinary;
1697 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
1698 IDNS |= Decl::IDNS_Ordinary;
1699
1700 // We may already have a record of the same name; try to find and match it.
1701 RecordDecl *AdoptDecl = nullptr;
1702 RecordDecl *PrevDecl = nullptr;
1703 if (!DC->isFunctionOrMethod()) {
1704 SmallVector<NamedDecl *, 4> ConflictingDecls;
1705 SmallVector<NamedDecl *, 2> FoundDecls;
1706 DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls);
1707
1708 if (!FoundDecls.empty()) {
1709 // We're going to have to compare D against potentially conflicting Decls, so complete it.
1710 if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition())
1711 D->getASTContext().getExternalSource()->CompleteType(D);
1712 }
1713
1714 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
1715 if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
1716 continue;
1717
1718 Decl *Found = FoundDecls[I];
1719 if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
1720 if (const TagType *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
1721 Found = Tag->getDecl();
1722 }
1723
1724 if (RecordDecl *FoundRecord = dyn_cast<RecordDecl>(Found)) {
1725 if (D->isAnonymousStructOrUnion() &&
1726 FoundRecord->isAnonymousStructOrUnion()) {
1727 // If both anonymous structs/unions are in a record context, make sure
1728 // they occur in the same location in the context records.
1729 if (Optional<unsigned> Index1 =
1730 StructuralEquivalenceContext::findUntaggedStructOrUnionIndex(
1731 D)) {
1732 if (Optional<unsigned> Index2 = StructuralEquivalenceContext::
1733 findUntaggedStructOrUnionIndex(FoundRecord)) {
1734 if (*Index1 != *Index2)
1735 continue;
1736 }
1737 }
1738 }
1739
1740 PrevDecl = FoundRecord;
1741
1742 if (RecordDecl *FoundDef = FoundRecord->getDefinition()) {
1743 if ((SearchName && !D->isCompleteDefinition())
1744 || (D->isCompleteDefinition() &&
1745 D->isAnonymousStructOrUnion()
1746 == FoundDef->isAnonymousStructOrUnion() &&
1747 IsStructuralMatch(D, FoundDef))) {
1748 // The record types structurally match, or the "from" translation
1749 // unit only had a forward declaration anyway; call it the same
1750 // function.
1751 // FIXME: For C++, we should also merge methods here.
1752 return Importer.Imported(D, FoundDef);
1753 }
1754 } else if (!D->isCompleteDefinition()) {
1755 // We have a forward declaration of this type, so adopt that forward
1756 // declaration rather than building a new one.
1757
1758 // If one or both can be completed from external storage then try one
1759 // last time to complete and compare them before doing this.
1760
1761 if (FoundRecord->hasExternalLexicalStorage() &&
1762 !FoundRecord->isCompleteDefinition())
1763 FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord);
1764 if (D->hasExternalLexicalStorage())
1765 D->getASTContext().getExternalSource()->CompleteType(D);
1766
1767 if (FoundRecord->isCompleteDefinition() &&
1768 D->isCompleteDefinition() &&
1769 !IsStructuralMatch(D, FoundRecord))
1770 continue;
1771
1772 AdoptDecl = FoundRecord;
1773 continue;
1774 } else if (!SearchName) {
1775 continue;
1776 }
1777 }
1778
1779 ConflictingDecls.push_back(FoundDecls[I]);
1780 }
1781
1782 if (!ConflictingDecls.empty() && SearchName) {
1783 Name = Importer.HandleNameConflict(Name, DC, IDNS,
1784 ConflictingDecls.data(),
1785 ConflictingDecls.size());
1786 }
1787 }
1788
1789 // Create the record declaration.
1790 RecordDecl *D2 = AdoptDecl;
1791 SourceLocation StartLoc = Importer.Import(D->getLocStart());
1792 if (!D2) {
1793 CXXRecordDecl *D2CXX = nullptr;
1794 if (CXXRecordDecl *DCXX = llvm::dyn_cast<CXXRecordDecl>(D)) {
1795 if (DCXX->isLambda()) {
1796 TypeSourceInfo *TInfo = Importer.Import(DCXX->getLambdaTypeInfo());
1797 D2CXX = CXXRecordDecl::CreateLambda(Importer.getToContext(),
1798 DC, TInfo, Loc,
1799 DCXX->isDependentLambda(),
1800 DCXX->isGenericLambda(),
1801 DCXX->getLambdaCaptureDefault());
1802 Decl *CDecl = Importer.Import(DCXX->getLambdaContextDecl());
1803 if (DCXX->getLambdaContextDecl() && !CDecl)
1804 return nullptr;
1805 D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), CDecl);
1806 } else if (DCXX->isInjectedClassName()) {
1807 // We have to be careful to do a similar dance to the one in
1808 // Sema::ActOnStartCXXMemberDeclarations
1809 CXXRecordDecl *const PrevDecl = nullptr;
1810 const bool DelayTypeCreation = true;
1811 D2CXX = CXXRecordDecl::Create(
1812 Importer.getToContext(), D->getTagKind(), DC, StartLoc, Loc,
1813 Name.getAsIdentifierInfo(), PrevDecl, DelayTypeCreation);
1814 Importer.getToContext().getTypeDeclType(
1815 D2CXX, llvm::dyn_cast<CXXRecordDecl>(DC));
1816 } else {
1817 D2CXX = CXXRecordDecl::Create(Importer.getToContext(),
1818 D->getTagKind(),
1819 DC, StartLoc, Loc,
1820 Name.getAsIdentifierInfo());
1821 }
1822 D2 = D2CXX;
1823 D2->setAccess(D->getAccess());
1824 } else {
1825 D2 = RecordDecl::Create(Importer.getToContext(), D->getTagKind(),
1826 DC, StartLoc, Loc, Name.getAsIdentifierInfo());
1827 }
1828
1829 D2->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
1830 D2->setLexicalDeclContext(LexicalDC);
1831 LexicalDC->addDeclInternal(D2);
1832 if (D->isAnonymousStructOrUnion())
1833 D2->setAnonymousStructOrUnion(true);
1834 if (PrevDecl) {
1835 // FIXME: do this for all Redeclarables, not just RecordDecls.
1836 D2->setPreviousDecl(PrevDecl);
1837 }
1838 }
1839
1840 Importer.Imported(D, D2);
1841
1842 if (D->isCompleteDefinition() && ImportDefinition(D, D2, IDK_Default))
1843 return nullptr;
1844
1845 return D2;
1846}
1847
1848Decl *ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) {
1849 // Import the major distinguishing characteristics of this enumerator.
1850 DeclContext *DC, *LexicalDC;
1851 DeclarationName Name;
1852 SourceLocation Loc;
1853 NamedDecl *ToD;
1854 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
1855 return nullptr;
1856 if (ToD)
1857 return ToD;
1858
1859 QualType T = Importer.Import(D->getType());
1860 if (T.isNull())
1861 return nullptr;
1862
1863 // Determine whether there are any other declarations with the same name and
1864 // in the same context.
1865 if (!LexicalDC->isFunctionOrMethod()) {
1866 SmallVector<NamedDecl *, 4> ConflictingDecls;
1867 unsigned IDNS = Decl::IDNS_Ordinary;
1868 SmallVector<NamedDecl *, 2> FoundDecls;
1869 DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
1870 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
1871 if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
1872 continue;
1873
1874 if (EnumConstantDecl *FoundEnumConstant
1875 = dyn_cast<EnumConstantDecl>(FoundDecls[I])) {
1876 if (IsStructuralMatch(D, FoundEnumConstant))
1877 return Importer.Imported(D, FoundEnumConstant);
1878 }
1879
1880 ConflictingDecls.push_back(FoundDecls[I]);
1881 }
1882
1883 if (!ConflictingDecls.empty()) {
1884 Name = Importer.HandleNameConflict(Name, DC, IDNS,
1885 ConflictingDecls.data(),
1886 ConflictingDecls.size());
1887 if (!Name)
1888 return nullptr;
1889 }
1890 }
1891
1892 Expr *Init = Importer.Import(D->getInitExpr());
1893 if (D->getInitExpr() && !Init)
1894 return nullptr;
1895
1896 EnumConstantDecl *ToEnumerator
1897 = EnumConstantDecl::Create(Importer.getToContext(), cast<EnumDecl>(DC), Loc,
1898 Name.getAsIdentifierInfo(), T,
1899 Init, D->getInitVal());
1900 ToEnumerator->setAccess(D->getAccess());
1901 ToEnumerator->setLexicalDeclContext(LexicalDC);
1902 Importer.Imported(D, ToEnumerator);
1903 LexicalDC->addDeclInternal(ToEnumerator);
1904 return ToEnumerator;
1905}
1906
1907Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
1908 // Import the major distinguishing characteristics of this function.
1909 DeclContext *DC, *LexicalDC;
1910 DeclarationName Name;
1911 SourceLocation Loc;
1912 NamedDecl *ToD;
1913 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
1914 return nullptr;
1915 if (ToD)
1916 return ToD;
1917
1918 const FunctionDecl *FoundWithoutBody = nullptr;
1919
1920 // Try to find a function in our own ("to") context with the same name, same
1921 // type, and in the same context as the function we're importing.
1922 if (!LexicalDC->isFunctionOrMethod()) {
1923 SmallVector<NamedDecl *, 4> ConflictingDecls;
1924 unsigned IDNS = Decl::IDNS_Ordinary;
1925 SmallVector<NamedDecl *, 2> FoundDecls;
1926 DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
1927 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
1928 if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
1929 continue;
1930
1931 if (FunctionDecl *FoundFunction = dyn_cast<FunctionDecl>(FoundDecls[I])) {
1932 if (FoundFunction->hasExternalFormalLinkage() &&
1933 D->hasExternalFormalLinkage()) {
1934 if (Importer.IsStructurallyEquivalent(D->getType(),
1935 FoundFunction->getType())) {
1936 // FIXME: Actually try to merge the body and other attributes.
1937 const FunctionDecl *FromBodyDecl = nullptr;
1938 D->hasBody(FromBodyDecl);
1939 if (D == FromBodyDecl && !FoundFunction->hasBody()) {
1940 // This function is needed to merge completely.
1941 FoundWithoutBody = FoundFunction;
1942 break;
1943 }
1944 return Importer.Imported(D, FoundFunction);
1945 }
1946
1947 // FIXME: Check for overloading more carefully, e.g., by boosting
1948 // Sema::IsOverload out to the AST library.
1949
1950 // Function overloading is okay in C++.
1951 if (Importer.getToContext().getLangOpts().CPlusPlus)
1952 continue;
1953
1954 // Complain about inconsistent function types.
1955 Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent)
1956 << Name << D->getType() << FoundFunction->getType();
1957 Importer.ToDiag(FoundFunction->getLocation(),
1958 diag::note_odr_value_here)
1959 << FoundFunction->getType();
1960 }
1961 }
1962
1963 ConflictingDecls.push_back(FoundDecls[I]);
1964 }
1965
1966 if (!ConflictingDecls.empty()) {
1967 Name = Importer.HandleNameConflict(Name, DC, IDNS,
1968 ConflictingDecls.data(),
1969 ConflictingDecls.size());
1970 if (!Name)
1971 return nullptr;
1972 }
1973 }
1974
1975 DeclarationNameInfo NameInfo(Name, Loc);
1976 // Import additional name location/type info.
1977 ImportDeclarationNameLoc(D->getNameInfo(), NameInfo);
1978
1979 QualType FromTy = D->getType();
1980 bool usedDifferentExceptionSpec = false;
1981
1982 if (const FunctionProtoType *
1983 FromFPT = D->getType()->getAs<FunctionProtoType>()) {
1984 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
1985 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
1986 // FunctionDecl that we are importing the FunctionProtoType for.
1987 // To avoid an infinite recursion when importing, create the FunctionDecl
1988 // with a simplified function type and update it afterwards.
1989 if (FromEPI.ExceptionSpec.SourceDecl ||
1990 FromEPI.ExceptionSpec.SourceTemplate ||
1991 FromEPI.ExceptionSpec.NoexceptExpr) {
1992 FunctionProtoType::ExtProtoInfo DefaultEPI;
1993 FromTy = Importer.getFromContext().getFunctionType(
1994 FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI);
1995 usedDifferentExceptionSpec = true;
1996 }
1997 }
1998
1999 // Import the type.
2000 QualType T = Importer.Import(FromTy);
2001 if (T.isNull())
2002 return nullptr;
2003
2004 // Import the function parameters.
2005 SmallVector<ParmVarDecl *, 8> Parameters;
2006 for (auto P : D->parameters()) {
2007 ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(P));
2008 if (!ToP)
2009 return nullptr;
2010
2011 Parameters.push_back(ToP);
2012 }
2013
2014 // Create the imported function.
2015 TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
2016 FunctionDecl *ToFunction = nullptr;
2017 SourceLocation InnerLocStart = Importer.Import(D->getInnerLocStart());
2018 if (CXXConstructorDecl *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
2019 ToFunction = CXXConstructorDecl::Create(Importer.getToContext(),
2020 cast<CXXRecordDecl>(DC),
2021 InnerLocStart,
2022 NameInfo, T, TInfo,
2023 FromConstructor->isExplicit(),
2024 D->isInlineSpecified(),
2025 D->isImplicit(),
2026 D->isConstexpr());
2027 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
2028 SmallVector<CXXCtorInitializer *, 4> CtorInitializers;
2029 for (CXXCtorInitializer *I : FromConstructor->inits()) {
2030 CXXCtorInitializer *ToI =
2031 cast_or_null<CXXCtorInitializer>(Importer.Import(I));
2032 if (!ToI && I)
2033 return nullptr;
2034 CtorInitializers.push_back(ToI);
2035 }
2036 CXXCtorInitializer **Memory =
2037 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
2038 std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
2039 CXXConstructorDecl *ToCtor = llvm::cast<CXXConstructorDecl>(ToFunction);
2040 ToCtor->setCtorInitializers(Memory);
2041 ToCtor->setNumCtorInitializers(NumInitializers);
2042 }
2043 } else if (isa<CXXDestructorDecl>(D)) {
2044 ToFunction = CXXDestructorDecl::Create(Importer.getToContext(),
2045 cast<CXXRecordDecl>(DC),
2046 InnerLocStart,
2047 NameInfo, T, TInfo,
2048 D->isInlineSpecified(),
2049 D->isImplicit());
2050 } else if (CXXConversionDecl *FromConversion
2051 = dyn_cast<CXXConversionDecl>(D)) {
2052 ToFunction = CXXConversionDecl::Create(Importer.getToContext(),
2053 cast<CXXRecordDecl>(DC),
2054 InnerLocStart,
2055 NameInfo, T, TInfo,
2056 D->isInlineSpecified(),
2057 FromConversion->isExplicit(),
2058 D->isConstexpr(),
2059 Importer.Import(D->getLocEnd()));
2060 } else if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) {
2061 ToFunction = CXXMethodDecl::Create(Importer.getToContext(),
2062 cast<CXXRecordDecl>(DC),
2063 InnerLocStart,
2064 NameInfo, T, TInfo,
2065 Method->getStorageClass(),
2066 Method->isInlineSpecified(),
2067 D->isConstexpr(),
2068 Importer.Import(D->getLocEnd()));
2069 } else {
2070 ToFunction = FunctionDecl::Create(Importer.getToContext(), DC,
2071 InnerLocStart,
2072 NameInfo, T, TInfo, D->getStorageClass(),
2073 D->isInlineSpecified(),
2074 D->hasWrittenPrototype(),
2075 D->isConstexpr());
2076 }
2077
2078 // Import the qualifier, if any.
2079 ToFunction->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
2080 ToFunction->setAccess(D->getAccess());
2081 ToFunction->setLexicalDeclContext(LexicalDC);
2082 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
2083 ToFunction->setTrivial(D->isTrivial());
2084 ToFunction->setPure(D->isPure());
2085 Importer.Imported(D, ToFunction);
2086
2087 // Set the parameters.
2088 for (unsigned I = 0, N = Parameters.size(); I != N; ++I) {
2089 Parameters[I]->setOwningFunction(ToFunction);
2090 ToFunction->addDeclInternal(Parameters[I]);
2091 }
2092 ToFunction->setParams(Parameters);
2093
2094 if (FoundWithoutBody) {
2095 auto *Recent = const_cast<FunctionDecl *>(
2096 FoundWithoutBody->getMostRecentDecl());
2097 ToFunction->setPreviousDecl(Recent);
2098 }
2099
2100 if (usedDifferentExceptionSpec) {
2101 // Update FunctionProtoType::ExtProtoInfo.
2102 QualType T = Importer.Import(D->getType());
2103 if (T.isNull())
2104 return nullptr;
2105 ToFunction->setType(T);
2106 }
2107
2108 // Import the body, if any.
2109 if (Stmt *FromBody = D->getBody()) {
2110 if (Stmt *ToBody = Importer.Import(FromBody)) {
2111 ToFunction->setBody(ToBody);
2112 }
2113 }
2114
2115 // FIXME: Other bits to merge?
2116
2117 // Add this function to the lexical context.
2118 LexicalDC->addDeclInternal(ToFunction);
2119
2120 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
2121 ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod);
2122
2123 return ToFunction;
2124}
2125
2126Decl *ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) {
2127 return VisitFunctionDecl(D);
2128}
2129
2130Decl *ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
2131 return VisitCXXMethodDecl(D);
2132}
2133
2134Decl *ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
2135 return VisitCXXMethodDecl(D);
2136}
2137
2138Decl *ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) {
2139 return VisitCXXMethodDecl(D);
2140}
2141
2142static unsigned getFieldIndex(Decl *F) {
2143 RecordDecl *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
2144 if (!Owner)
2145 return 0;
2146
2147 unsigned Index = 1;
2148 for (const auto *D : Owner->noload_decls()) {
2149 if (D == F)
2150 return Index;
2151
2152 if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D))
2153 ++Index;
2154 }
2155
2156 return Index;
2157}
2158
2159Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) {
2160 // Import the major distinguishing characteristics of a variable.
2161 DeclContext *DC, *LexicalDC;
2162 DeclarationName Name;
2163 SourceLocation Loc;
2164 NamedDecl *ToD;
2165 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2166 return nullptr;
2167 if (ToD)
2168 return ToD;
2169
2170 // Determine whether we've already imported this field.
2171 SmallVector<NamedDecl *, 2> FoundDecls;
2172 DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
2173 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
2174 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecls[I])) {
2175 // For anonymous fields, match up by index.
2176 if (!Name && getFieldIndex(D) != getFieldIndex(FoundField))
2177 continue;
2178
2179 if (Importer.IsStructurallyEquivalent(D->getType(),
2180 FoundField->getType())) {
2181 Importer.Imported(D, FoundField);
2182 return FoundField;
2183 }
2184
2185 Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent)
2186 << Name << D->getType() << FoundField->getType();
2187 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
2188 << FoundField->getType();
2189 return nullptr;
2190 }
2191 }
2192
2193 // Import the type.
2194 QualType T = Importer.Import(D->getType());
2195 if (T.isNull())
2196 return nullptr;
2197
2198 TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
2199 Expr *BitWidth = Importer.Import(D->getBitWidth());
2200 if (!BitWidth && D->getBitWidth())
2201 return nullptr;
2202
2203 FieldDecl *ToField = FieldDecl::Create(Importer.getToContext(), DC,
2204 Importer.Import(D->getInnerLocStart()),
2205 Loc, Name.getAsIdentifierInfo(),
2206 T, TInfo, BitWidth, D->isMutable(),
2207 D->getInClassInitStyle());
2208 ToField->setAccess(D->getAccess());
2209 ToField->setLexicalDeclContext(LexicalDC);
2210 if (Expr *FromInitializer = D->getInClassInitializer()) {
2211 Expr *ToInitializer = Importer.Import(FromInitializer);
2212 if (ToInitializer)
2213 ToField->setInClassInitializer(ToInitializer);
2214 else
2215 return nullptr;
2216 }
2217 ToField->setImplicit(D->isImplicit());
2218 Importer.Imported(D, ToField);
2219 LexicalDC->addDeclInternal(ToField);
2220 return ToField;
2221}
2222
2223Decl *ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
2224 // Import the major distinguishing characteristics of a variable.
2225 DeclContext *DC, *LexicalDC;
2226 DeclarationName Name;
2227 SourceLocation Loc;
2228 NamedDecl *ToD;
2229 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2230 return nullptr;
2231 if (ToD)
2232 return ToD;
2233
2234 // Determine whether we've already imported this field.
2235 SmallVector<NamedDecl *, 2> FoundDecls;
2236 DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
2237 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
2238 if (IndirectFieldDecl *FoundField
2239 = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
2240 // For anonymous indirect fields, match up by index.
2241 if (!Name && getFieldIndex(D) != getFieldIndex(FoundField))
2242 continue;
2243
2244 if (Importer.IsStructurallyEquivalent(D->getType(),
2245 FoundField->getType(),
2246 !Name.isEmpty())) {
2247 Importer.Imported(D, FoundField);
2248 return FoundField;
2249 }
2250
2251 // If there are more anonymous fields to check, continue.
2252 if (!Name && I < N-1)
2253 continue;
2254
2255 Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent)
2256 << Name << D->getType() << FoundField->getType();
2257 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
2258 << FoundField->getType();
2259 return nullptr;
2260 }
2261 }
2262
2263 // Import the type.
2264 QualType T = Importer.Import(D->getType());
2265 if (T.isNull())
2266 return nullptr;
2267
2268 NamedDecl **NamedChain =
2269 new (Importer.getToContext())NamedDecl*[D->getChainingSize()];
2270
2271 unsigned i = 0;
2272 for (auto *PI : D->chain()) {
2273 Decl *D = Importer.Import(PI);
2274 if (!D)
2275 return nullptr;
2276 NamedChain[i++] = cast<NamedDecl>(D);
2277 }
2278
2279 IndirectFieldDecl *ToIndirectField = IndirectFieldDecl::Create(
2280 Importer.getToContext(), DC, Loc, Name.getAsIdentifierInfo(), T,
2281 {NamedChain, D->getChainingSize()});
2282
2283 for (const auto *Attr : D->attrs())
2284 ToIndirectField->addAttr(Attr->clone(Importer.getToContext()));
2285
2286 ToIndirectField->setAccess(D->getAccess());
2287 ToIndirectField->setLexicalDeclContext(LexicalDC);
2288 Importer.Imported(D, ToIndirectField);
2289 LexicalDC->addDeclInternal(ToIndirectField);
2290 return ToIndirectField;
2291}
2292
2293Decl *ASTNodeImporter::VisitFriendDecl(FriendDecl *D) {
2294 // Import the major distinguishing characteristics of a declaration.
2295 DeclContext *DC = Importer.ImportContext(D->getDeclContext());
2296 DeclContext *LexicalDC = D->getDeclContext() == D->getLexicalDeclContext()
2297 ? DC : Importer.ImportContext(D->getLexicalDeclContext());
2298 if (!DC || !LexicalDC)
2299 return nullptr;
2300
2301 // Determine whether we've already imported this decl.
2302 // FriendDecl is not a NamedDecl so we cannot use localUncachedLookup.
2303 auto *RD = cast<CXXRecordDecl>(DC);
2304 FriendDecl *ImportedFriend = RD->getFirstFriend();
2305 StructuralEquivalenceContext Context(
2306 Importer.getFromContext(), Importer.getToContext(),
2307 Importer.getNonEquivalentDecls(), false, false);
2308
2309 while (ImportedFriend) {
2310 if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) {
2311 if (Context.IsStructurallyEquivalent(D->getFriendDecl(),
2312 ImportedFriend->getFriendDecl()))
2313 return Importer.Imported(D, ImportedFriend);
2314
2315 } else if (D->getFriendType() && ImportedFriend->getFriendType()) {
2316 if (Importer.IsStructurallyEquivalent(
2317 D->getFriendType()->getType(),
2318 ImportedFriend->getFriendType()->getType(), true))
2319 return Importer.Imported(D, ImportedFriend);
2320 }
2321 ImportedFriend = ImportedFriend->getNextFriend();
2322 }
2323
2324 // Not found. Create it.
2325 FriendDecl::FriendUnion ToFU;
2326 if (NamedDecl *FriendD = D->getFriendDecl())
2327 ToFU = cast_or_null<NamedDecl>(Importer.Import(FriendD));
2328 else
2329 ToFU = Importer.Import(D->getFriendType());
2330 if (!ToFU)
2331 return nullptr;
2332
2333 SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
2334 TemplateParameterList **FromTPLists =
2335 D->getTrailingObjects<TemplateParameterList *>();
2336 for (unsigned I = 0; I < D->NumTPLists; I++) {
2337 TemplateParameterList *List = ImportTemplateParameterList(FromTPLists[I]);
2338 if (!List)
2339 return nullptr;
2340 ToTPLists[I] = List;
2341 }
2342
2343 FriendDecl *FrD = FriendDecl::Create(Importer.getToContext(), DC,
2344 Importer.Import(D->getLocation()),
2345 ToFU, Importer.Import(D->getFriendLoc()),
2346 ToTPLists);
2347
2348 Importer.Imported(D, FrD);
2349 RD->pushFriendDecl(FrD);
2350
2351 FrD->setAccess(D->getAccess());
2352 FrD->setLexicalDeclContext(LexicalDC);
2353 LexicalDC->addDeclInternal(FrD);
2354 return FrD;
2355}
2356
2357Decl *ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
2358 // Import the major distinguishing characteristics of an ivar.
2359 DeclContext *DC, *LexicalDC;
2360 DeclarationName Name;
2361 SourceLocation Loc;
2362 NamedDecl *ToD;
2363 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2364 return nullptr;
2365 if (ToD)
2366 return ToD;
2367
2368 // Determine whether we've already imported this ivar
2369 SmallVector<NamedDecl *, 2> FoundDecls;
2370 DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
2371 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
2372 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecls[I])) {
2373 if (Importer.IsStructurallyEquivalent(D->getType(),
2374 FoundIvar->getType())) {
2375 Importer.Imported(D, FoundIvar);
2376 return FoundIvar;
2377 }
2378
2379 Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent)
2380 << Name << D->getType() << FoundIvar->getType();
2381 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
2382 << FoundIvar->getType();
2383 return nullptr;
2384 }
2385 }
2386
2387 // Import the type.
2388 QualType T = Importer.Import(D->getType());
2389 if (T.isNull())
2390 return nullptr;
2391
2392 TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
2393 Expr *BitWidth = Importer.Import(D->getBitWidth());
2394 if (!BitWidth && D->getBitWidth())
2395 return nullptr;
2396
2397 ObjCIvarDecl *ToIvar = ObjCIvarDecl::Create(Importer.getToContext(),
2398 cast<ObjCContainerDecl>(DC),
2399 Importer.Import(D->getInnerLocStart()),
2400 Loc, Name.getAsIdentifierInfo(),
2401 T, TInfo, D->getAccessControl(),
2402 BitWidth, D->getSynthesize());
2403 ToIvar->setLexicalDeclContext(LexicalDC);
2404 Importer.Imported(D, ToIvar);
2405 LexicalDC->addDeclInternal(ToIvar);
2406 return ToIvar;
2407
2408}
2409
2410Decl *ASTNodeImporter::VisitVarDecl(VarDecl *D) {
2411 // Import the major distinguishing characteristics of a variable.
2412 DeclContext *DC, *LexicalDC;
2413 DeclarationName Name;
2414 SourceLocation Loc;
2415 NamedDecl *ToD;
2416 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2417 return nullptr;
2418 if (ToD)
2419 return ToD;
2420
2421 // Try to find a variable in our own ("to") context with the same name and
2422 // in the same context as the variable we're importing.
2423 if (D->isFileVarDecl()) {
2424 VarDecl *MergeWithVar = nullptr;
2425 SmallVector<NamedDecl *, 4> ConflictingDecls;
2426 unsigned IDNS = Decl::IDNS_Ordinary;
2427 SmallVector<NamedDecl *, 2> FoundDecls;
2428 DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
2429 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
2430 if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
2431 continue;
2432
2433 if (VarDecl *FoundVar = dyn_cast<VarDecl>(FoundDecls[I])) {
2434 // We have found a variable that we may need to merge with. Check it.
2435 if (FoundVar->hasExternalFormalLinkage() &&
2436 D->hasExternalFormalLinkage()) {
2437 if (Importer.IsStructurallyEquivalent(D->getType(),
2438 FoundVar->getType())) {
2439 MergeWithVar = FoundVar;
2440 break;
2441 }
2442
2443 const ArrayType *FoundArray
2444 = Importer.getToContext().getAsArrayType(FoundVar->getType());
2445 const ArrayType *TArray
2446 = Importer.getToContext().getAsArrayType(D->getType());
2447 if (FoundArray && TArray) {
2448 if (isa<IncompleteArrayType>(FoundArray) &&
2449 isa<ConstantArrayType>(TArray)) {
2450 // Import the type.
2451 QualType T = Importer.Import(D->getType());
2452 if (T.isNull())
2453 return nullptr;
2454
2455 FoundVar->setType(T);
2456 MergeWithVar = FoundVar;
2457 break;
2458 } else if (isa<IncompleteArrayType>(TArray) &&
2459 isa<ConstantArrayType>(FoundArray)) {
2460 MergeWithVar = FoundVar;
2461 break;
2462 }
2463 }
2464
2465 Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent)
2466 << Name << D->getType() << FoundVar->getType();
2467 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
2468 << FoundVar->getType();
2469 }
2470 }
2471
2472 ConflictingDecls.push_back(FoundDecls[I]);
2473 }
2474
2475 if (MergeWithVar) {
2476 // An equivalent variable with external linkage has been found. Link
2477 // the two declarations, then merge them.
2478 Importer.Imported(D, MergeWithVar);
2479
2480 if (VarDecl *DDef = D->getDefinition()) {
2481 if (VarDecl *ExistingDef = MergeWithVar->getDefinition()) {
2482 Importer.ToDiag(ExistingDef->getLocation(),
2483 diag::err_odr_variable_multiple_def)
2484 << Name;
2485 Importer.FromDiag(DDef->getLocation(), diag::note_odr_defined_here);
2486 } else {
2487 Expr *Init = Importer.Import(DDef->getInit());
2488 MergeWithVar->setInit(Init);
2489 if (DDef->isInitKnownICE()) {
2490 EvaluatedStmt *Eval = MergeWithVar->ensureEvaluatedStmt();
2491 Eval->CheckedICE = true;
2492 Eval->IsICE = DDef->isInitICE();
2493 }
2494 }
2495 }
2496
2497 return MergeWithVar;
2498 }
2499
2500 if (!ConflictingDecls.empty()) {
2501 Name = Importer.HandleNameConflict(Name, DC, IDNS,
2502 ConflictingDecls.data(),
2503 ConflictingDecls.size());
2504 if (!Name)
2505 return nullptr;
2506 }
2507 }
2508
2509 // Import the type.
2510 QualType T = Importer.Import(D->getType());
2511 if (T.isNull())
2512 return nullptr;
2513
2514 // Create the imported variable.
2515 TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
2516 VarDecl *ToVar = VarDecl::Create(Importer.getToContext(), DC,
2517 Importer.Import(D->getInnerLocStart()),
2518 Loc, Name.getAsIdentifierInfo(),
2519 T, TInfo,
2520 D->getStorageClass());
2521 ToVar->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
2522 ToVar->setAccess(D->getAccess());
2523 ToVar->setLexicalDeclContext(LexicalDC);
2524 Importer.Imported(D, ToVar);
2525 LexicalDC->addDeclInternal(ToVar);
2526
2527 if (!D->isFileVarDecl() &&
2528 D->isUsed())
2529 ToVar->setIsUsed();
2530
2531 // Merge the initializer.
2532 if (ImportDefinition(D, ToVar))
2533 return nullptr;
2534
2535 if (D->isConstexpr())
2536 ToVar->setConstexpr(true);
2537
2538 return ToVar;
2539}
2540
2541Decl *ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) {
2542 // Parameters are created in the translation unit's context, then moved
2543 // into the function declaration's context afterward.
2544 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
2545
2546 // Import the name of this declaration.
2547 DeclarationName Name = Importer.Import(D->getDeclName());
2548 if (D->getDeclName() && !Name)
2549 return nullptr;
2550
2551 // Import the location of this declaration.
2552 SourceLocation Loc = Importer.Import(D->getLocation());
2553
2554 // Import the parameter's type.
2555 QualType T = Importer.Import(D->getType());
2556 if (T.isNull())
2557 return nullptr;
2558
2559 // Create the imported parameter.
2560 auto *ToParm = ImplicitParamDecl::Create(Importer.getToContext(), DC, Loc,
2561 Name.getAsIdentifierInfo(), T,
2562 D->getParameterKind());
2563 return Importer.Imported(D, ToParm);
2564}
2565
2566Decl *ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) {
2567 // Parameters are created in the translation unit's context, then moved
2568 // into the function declaration's context afterward.
2569 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
2570
2571 // Import the name of this declaration.
2572 DeclarationName Name = Importer.Import(D->getDeclName());
2573 if (D->getDeclName() && !Name)
2574 return nullptr;
2575
2576 // Import the location of this declaration.
2577 SourceLocation Loc = Importer.Import(D->getLocation());
2578
2579 // Import the parameter's type.
2580 QualType T = Importer.Import(D->getType());
2581 if (T.isNull())
2582 return nullptr;
2583
2584 // Create the imported parameter.
2585 TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
2586 ParmVarDecl *ToParm = ParmVarDecl::Create(Importer.getToContext(), DC,
2587 Importer.Import(D->getInnerLocStart()),
2588 Loc, Name.getAsIdentifierInfo(),
2589 T, TInfo, D->getStorageClass(),
2590 /*DefaultArg*/ nullptr);
2591
2592 // Set the default argument.
2593 ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg());
2594 ToParm->setKNRPromoted(D->isKNRPromoted());
2595
2596 Expr *ToDefArg = nullptr;
2597 Expr *FromDefArg = nullptr;
2598 if (D->hasUninstantiatedDefaultArg()) {
2599 FromDefArg = D->getUninstantiatedDefaultArg();
2600 ToDefArg = Importer.Import(FromDefArg);
2601 ToParm->setUninstantiatedDefaultArg(ToDefArg);
2602 } else if (D->hasUnparsedDefaultArg()) {
2603 ToParm->setUnparsedDefaultArg();
2604 } else if (D->hasDefaultArg()) {
2605 FromDefArg = D->getDefaultArg();
2606 ToDefArg = Importer.Import(FromDefArg);
2607 ToParm->setDefaultArg(ToDefArg);
2608 }
2609 if (FromDefArg && !ToDefArg)
2610 return nullptr;
2611
2612 if (D->isUsed())
2613 ToParm->setIsUsed();
2614
2615 return Importer.Imported(D, ToParm);
2616}
2617
2618Decl *ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
2619 // Import the major distinguishing characteristics of a method.
2620 DeclContext *DC, *LexicalDC;
2621 DeclarationName Name;
2622 SourceLocation Loc;
2623 NamedDecl *ToD;
2624 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2625 return nullptr;
2626 if (ToD)
2627 return ToD;
2628
2629 SmallVector<NamedDecl *, 2> FoundDecls;
2630 DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
2631 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
2632 if (ObjCMethodDecl *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecls[I])) {
2633 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
2634 continue;
2635
2636 // Check return types.
2637 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
2638 FoundMethod->getReturnType())) {
2639 Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent)
2640 << D->isInstanceMethod() << Name << D->getReturnType()
2641 << FoundMethod->getReturnType();
2642 Importer.ToDiag(FoundMethod->getLocation(),
2643 diag::note_odr_objc_method_here)
2644 << D->isInstanceMethod() << Name;
2645 return nullptr;
2646 }
2647
2648 // Check the number of parameters.
2649 if (D->param_size() != FoundMethod->param_size()) {
2650 Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent)
2651 << D->isInstanceMethod() << Name
2652 << D->param_size() << FoundMethod->param_size();
2653 Importer.ToDiag(FoundMethod->getLocation(),
2654 diag::note_odr_objc_method_here)
2655 << D->isInstanceMethod() << Name;
2656 return nullptr;
2657 }
2658
2659 // Check parameter types.
2660 for (ObjCMethodDecl::param_iterator P = D->param_begin(),
2661 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
2662 P != PEnd; ++P, ++FoundP) {
2663 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
2664 (*FoundP)->getType())) {
2665 Importer.FromDiag((*P)->getLocation(),
2666 diag::err_odr_objc_method_param_type_inconsistent)
2667 << D->isInstanceMethod() << Name
2668 << (*P)->getType() << (*FoundP)->getType();
2669 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
2670 << (*FoundP)->getType();
2671 return nullptr;
2672 }
2673 }
2674
2675 // Check variadic/non-variadic.
2676 // Check the number of parameters.
2677 if (D->isVariadic() != FoundMethod->isVariadic()) {
2678 Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent)
2679 << D->isInstanceMethod() << Name;
2680 Importer.ToDiag(FoundMethod->getLocation(),
2681 diag::note_odr_objc_method_here)
2682 << D->isInstanceMethod() << Name;
2683 return nullptr;
2684 }
2685
2686 // FIXME: Any other bits we need to merge?
2687 return Importer.Imported(D, FoundMethod);
2688 }
2689 }
2690
2691 // Import the result type.
2692 QualType ResultTy = Importer.Import(D->getReturnType());
2693 if (ResultTy.isNull())
2694 return nullptr;
2695
2696 TypeSourceInfo *ReturnTInfo = Importer.Import(D->getReturnTypeSourceInfo());
2697
2698 ObjCMethodDecl *ToMethod = ObjCMethodDecl::Create(
2699 Importer.getToContext(), Loc, Importer.Import(D->getLocEnd()),
2700 Name.getObjCSelector(), ResultTy, ReturnTInfo, DC, D->isInstanceMethod(),
2701 D->isVariadic(), D->isPropertyAccessor(), D->isImplicit(), D->isDefined(),
2702 D->getImplementationControl(), D->hasRelatedResultType());
2703
2704 // FIXME: When we decide to merge method definitions, we'll need to
2705 // deal with implicit parameters.
2706
2707 // Import the parameters
2708 SmallVector<ParmVarDecl *, 5> ToParams;
2709 for (auto *FromP : D->parameters()) {
2710 ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(FromP));
2711 if (!ToP)
2712 return nullptr;
2713
2714 ToParams.push_back(ToP);
2715 }
2716
2717 // Set the parameters.
2718 for (unsigned I = 0, N = ToParams.size(); I != N; ++I) {
2719 ToParams[I]->setOwningFunction(ToMethod);
2720 ToMethod->addDeclInternal(ToParams[I]);
2721 }
2722 SmallVector<SourceLocation, 12> SelLocs;
2723 D->getSelectorLocs(SelLocs);
2724 ToMethod->setMethodParams(Importer.getToContext(), ToParams, SelLocs);
2725
2726 ToMethod->setLexicalDeclContext(LexicalDC);
2727 Importer.Imported(D, ToMethod);
2728 LexicalDC->addDeclInternal(ToMethod);
2729 return ToMethod;
2730}
2731
2732Decl *ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
2733 // Import the major distinguishing characteristics of a category.
2734 DeclContext *DC, *LexicalDC;
2735 DeclarationName Name;
2736 SourceLocation Loc;
2737 NamedDecl *ToD;
2738 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2739 return nullptr;
2740 if (ToD)
2741 return ToD;
2742
2743 TypeSourceInfo *BoundInfo = Importer.Import(D->getTypeSourceInfo());
2744 if (!BoundInfo)
2745 return nullptr;
2746
2747 ObjCTypeParamDecl *Result = ObjCTypeParamDecl::Create(
2748 Importer.getToContext(), DC,
2749 D->getVariance(),
2750 Importer.Import(D->getVarianceLoc()),
2751 D->getIndex(),
2752 Importer.Import(D->getLocation()),
2753 Name.getAsIdentifierInfo(),
2754 Importer.Import(D->getColonLoc()),
2755 BoundInfo);
2756 Importer.Imported(D, Result);
2757 Result->setLexicalDeclContext(LexicalDC);
2758 return Result;
2759}
2760
2761Decl *ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
2762 // Import the major distinguishing characteristics of a category.
2763 DeclContext *DC, *LexicalDC;
2764 DeclarationName Name;
2765 SourceLocation Loc;
2766 NamedDecl *ToD;
2767 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2768 return nullptr;
2769 if (ToD)
2770 return ToD;
2771
2772 ObjCInterfaceDecl *ToInterface
2773 = cast_or_null<ObjCInterfaceDecl>(Importer.Import(D->getClassInterface()));
2774 if (!ToInterface)
2775 return nullptr;
2776
2777 // Determine if we've already encountered this category.
2778 ObjCCategoryDecl *MergeWithCategory
2779 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
2780 ObjCCategoryDecl *ToCategory = MergeWithCategory;
2781 if (!ToCategory) {
2782 ToCategory = ObjCCategoryDecl::Create(Importer.getToContext(), DC,
2783 Importer.Import(D->getAtStartLoc()),
2784 Loc,
2785 Importer.Import(D->getCategoryNameLoc()),
2786 Name.getAsIdentifierInfo(),
2787 ToInterface,
2788 /*TypeParamList=*/nullptr,
2789 Importer.Import(D->getIvarLBraceLoc()),
2790 Importer.Import(D->getIvarRBraceLoc()));
2791 ToCategory->setLexicalDeclContext(LexicalDC);
2792 LexicalDC->addDeclInternal(ToCategory);
2793 Importer.Imported(D, ToCategory);
2794 // Import the type parameter list after calling Imported, to avoid
2795 // loops when bringing in their DeclContext.
2796 ToCategory->setTypeParamList(ImportObjCTypeParamList(
2797 D->getTypeParamList()));
2798
2799 // Import protocols
2800 SmallVector<ObjCProtocolDecl *, 4> Protocols;
2801 SmallVector<SourceLocation, 4> ProtocolLocs;
2802 ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc
2803 = D->protocol_loc_begin();
2804 for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(),
2805 FromProtoEnd = D->protocol_end();
2806 FromProto != FromProtoEnd;
2807 ++FromProto, ++FromProtoLoc) {
2808 ObjCProtocolDecl *ToProto
2809 = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto));
2810 if (!ToProto)
2811 return nullptr;
2812 Protocols.push_back(ToProto);
2813 ProtocolLocs.push_back(Importer.Import(*FromProtoLoc));
2814 }
2815
2816 // FIXME: If we're merging, make sure that the protocol list is the same.
2817 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
2818 ProtocolLocs.data(), Importer.getToContext());
2819
2820 } else {
2821 Importer.Imported(D, ToCategory);
2822 }
2823
2824 // Import all of the members of this category.
2825 ImportDeclContext(D);
2826
2827 // If we have an implementation, import it as well.
2828 if (D->getImplementation()) {
2829 ObjCCategoryImplDecl *Impl
2830 = cast_or_null<ObjCCategoryImplDecl>(
2831 Importer.Import(D->getImplementation()));
2832 if (!Impl)
2833 return nullptr;
2834
2835 ToCategory->setImplementation(Impl);
2836 }
2837
2838 return ToCategory;
2839}
2840
2841bool ASTNodeImporter::ImportDefinition(ObjCProtocolDecl *From,
2842 ObjCProtocolDecl *To,
2843 ImportDefinitionKind Kind) {
2844 if (To->getDefinition()) {
2845 if (shouldForceImportDeclContext(Kind))
2846 ImportDeclContext(From);
2847 return false;
2848 }
2849
2850 // Start the protocol definition
2851 To->startDefinition();
2852
2853 // Import protocols
2854 SmallVector<ObjCProtocolDecl *, 4> Protocols;
2855 SmallVector<SourceLocation, 4> ProtocolLocs;
2856 ObjCProtocolDecl::protocol_loc_iterator
2857 FromProtoLoc = From->protocol_loc_begin();
2858 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
2859 FromProtoEnd = From->protocol_end();
2860 FromProto != FromProtoEnd;
2861 ++FromProto, ++FromProtoLoc) {
2862 ObjCProtocolDecl *ToProto
2863 = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto));
2864 if (!ToProto)
2865 return true;
2866 Protocols.push_back(ToProto);
2867 ProtocolLocs.push_back(Importer.Import(*FromProtoLoc));
2868 }
2869
2870 // FIXME: If we're merging, make sure that the protocol list is the same.
2871 To->setProtocolList(Protocols.data(), Protocols.size(),
2872 ProtocolLocs.data(), Importer.getToContext());
2873
2874 if (shouldForceImportDeclContext(Kind)) {
2875 // Import all of the members of this protocol.
2876 ImportDeclContext(From, /*ForceImport=*/true);
2877 }
2878 return false;
2879}
2880
2881Decl *ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
2882 // If this protocol has a definition in the translation unit we're coming
2883 // from, but this particular declaration is not that definition, import the
2884 // definition and map to that.
2885 ObjCProtocolDecl *Definition = D->getDefinition();
2886 if (Definition && Definition != D) {
2887 Decl *ImportedDef = Importer.Import(Definition);
2888 if (!ImportedDef)
2889 return nullptr;
2890
2891 return Importer.Imported(D, ImportedDef);
2892 }
2893
2894 // Import the major distinguishing characteristics of a protocol.
2895 DeclContext *DC, *LexicalDC;
2896 DeclarationName Name;
2897 SourceLocation Loc;
2898 NamedDecl *ToD;
2899 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2900 return nullptr;
2901 if (ToD)
2902 return ToD;
2903
2904 ObjCProtocolDecl *MergeWithProtocol = nullptr;
2905 SmallVector<NamedDecl *, 2> FoundDecls;
2906 DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
2907 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
2908 if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol))
2909 continue;
2910
2911 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecls[I])))
2912 break;
2913 }
2914
2915 ObjCProtocolDecl *ToProto = MergeWithProtocol;
2916 if (!ToProto) {
2917 ToProto = ObjCProtocolDecl::Create(Importer.getToContext(), DC,
2918 Name.getAsIdentifierInfo(), Loc,
2919 Importer.Import(D->getAtStartLoc()),
2920 /*PrevDecl=*/nullptr);
2921 ToProto->setLexicalDeclContext(LexicalDC);
2922 LexicalDC->addDeclInternal(ToProto);
2923 }
2924
2925 Importer.Imported(D, ToProto);
2926
2927 if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToProto))
2928 return nullptr;
2929
2930 return ToProto;
2931}
2932
2933Decl *ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
2934 DeclContext *DC = Importer.ImportContext(D->getDeclContext());
2935 DeclContext *LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
2936
2937 SourceLocation ExternLoc = Importer.Import(D->getExternLoc());
2938 SourceLocation LangLoc = Importer.Import(D->getLocation());
2939
2940 bool HasBraces = D->hasBraces();
2941
2942 LinkageSpecDecl *ToLinkageSpec =
2943 LinkageSpecDecl::Create(Importer.getToContext(),
2944 DC,
2945 ExternLoc,
2946 LangLoc,
2947 D->getLanguage(),
2948 HasBraces);
2949
2950 if (HasBraces) {
2951 SourceLocation RBraceLoc = Importer.Import(D->getRBraceLoc());
2952 ToLinkageSpec->setRBraceLoc(RBraceLoc);
2953 }
2954
2955 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
2956 LexicalDC->addDeclInternal(ToLinkageSpec);
2957
2958 Importer.Imported(D, ToLinkageSpec);
2959
2960 return ToLinkageSpec;
2961}
2962
2963bool ASTNodeImporter::ImportDefinition(ObjCInterfaceDecl *From,
2964 ObjCInterfaceDecl *To,
2965 ImportDefinitionKind Kind) {
2966 if (To->getDefinition()) {
2967 // Check consistency of superclass.
2968 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
2969 if (FromSuper) {
2970 FromSuper = cast_or_null<ObjCInterfaceDecl>(Importer.Import(FromSuper));
2971 if (!FromSuper)
2972 return true;
2973 }
2974
2975 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
2976 if ((bool)FromSuper != (bool)ToSuper ||
2977 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
2978 Importer.ToDiag(To->getLocation(),
2979 diag::err_odr_objc_superclass_inconsistent)
2980 << To->getDeclName();
2981 if (ToSuper)
2982 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
2983 << To->getSuperClass()->getDeclName();
2984 else
2985 Importer.ToDiag(To->getLocation(),
2986 diag::note_odr_objc_missing_superclass);
2987 if (From->getSuperClass())
2988 Importer.FromDiag(From->getSuperClassLoc(),
2989 diag::note_odr_objc_superclass)
2990 << From->getSuperClass()->getDeclName();
2991 else
2992 Importer.FromDiag(From->getLocation(),
2993 diag::note_odr_objc_missing_superclass);
2994 }
2995
2996 if (shouldForceImportDeclContext(Kind))
2997 ImportDeclContext(From);
2998 return false;
2999 }
3000
3001 // Start the definition.
3002 To->startDefinition();
3003
3004 // If this class has a superclass, import it.
3005 if (From->getSuperClass()) {
3006 TypeSourceInfo *SuperTInfo = Importer.Import(From->getSuperClassTInfo());
3007 if (!SuperTInfo)
3008 return true;
3009
3010 To->setSuperClass(SuperTInfo);
3011 }
3012
3013 // Import protocols
3014 SmallVector<ObjCProtocolDecl *, 4> Protocols;
3015 SmallVector<SourceLocation, 4> ProtocolLocs;
3016 ObjCInterfaceDecl::protocol_loc_iterator
3017 FromProtoLoc = From->protocol_loc_begin();
3018
3019 for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(),
3020 FromProtoEnd = From->protocol_end();
3021 FromProto != FromProtoEnd;
3022 ++FromProto, ++FromProtoLoc) {
3023 ObjCProtocolDecl *ToProto
3024 = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto));
3025 if (!ToProto)
3026 return true;
3027 Protocols.push_back(ToProto);
3028 ProtocolLocs.push_back(Importer.Import(*FromProtoLoc));
3029 }
3030
3031 // FIXME: If we're merging, make sure that the protocol list is the same.
3032 To->setProtocolList(Protocols.data(), Protocols.size(),
3033 ProtocolLocs.data(), Importer.getToContext());
3034
3035 // Import categories. When the categories themselves are imported, they'll
3036 // hook themselves into this interface.
3037 for (auto *Cat : From->known_categories())
3038 Importer.Import(Cat);
3039
3040 // If we have an @implementation, import it as well.
3041 if (From->getImplementation()) {
3042 ObjCImplementationDecl *Impl = cast_or_null<ObjCImplementationDecl>(
3043 Importer.Import(From->getImplementation()));
3044 if (!Impl)
3045 return true;
3046
3047 To->setImplementation(Impl);
3048 }
3049
3050 if (shouldForceImportDeclContext(Kind)) {
3051 // Import all of the members of this class.
3052 ImportDeclContext(From, /*ForceImport=*/true);
3053 }
3054 return false;
3055}
3056
3057ObjCTypeParamList *
3058ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) {
3059 if (!list)
3060 return nullptr;
3061
3062 SmallVector<ObjCTypeParamDecl *, 4> toTypeParams;
3063 for (auto fromTypeParam : *list) {
3064 auto toTypeParam = cast_or_null<ObjCTypeParamDecl>(
3065 Importer.Import(fromTypeParam));
3066 if (!toTypeParam)
3067 return nullptr;
3068
3069 toTypeParams.push_back(toTypeParam);
3070 }
3071
3072 return ObjCTypeParamList::create(Importer.getToContext(),
3073 Importer.Import(list->getLAngleLoc()),
3074 toTypeParams,
3075 Importer.Import(list->getRAngleLoc()));
3076}
3077
3078Decl *ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
3079 // If this class has a definition in the translation unit we're coming from,
3080 // but this particular declaration is not that definition, import the
3081 // definition and map to that.
3082 ObjCInterfaceDecl *Definition = D->getDefinition();
3083 if (Definition && Definition != D) {
3084 Decl *ImportedDef = Importer.Import(Definition);
3085 if (!ImportedDef)
3086 return nullptr;
3087
3088 return Importer.Imported(D, ImportedDef);
3089 }
3090
3091 // Import the major distinguishing characteristics of an @interface.
3092 DeclContext *DC, *LexicalDC;
3093 DeclarationName Name;
3094 SourceLocation Loc;
3095 NamedDecl *ToD;
3096 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3097 return nullptr;
3098 if (ToD)
3099 return ToD;
3100
3101 // Look for an existing interface with the same name.
3102 ObjCInterfaceDecl *MergeWithIface = nullptr;
3103 SmallVector<NamedDecl *, 2> FoundDecls;
3104 DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
3105 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
3106 if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary))
3107 continue;
3108
3109 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecls[I])))
3110 break;
3111 }
3112
3113 // Create an interface declaration, if one does not already exist.
3114 ObjCInterfaceDecl *ToIface = MergeWithIface;
3115 if (!ToIface) {
3116 ToIface = ObjCInterfaceDecl::Create(Importer.getToContext(), DC,
3117 Importer.Import(D->getAtStartLoc()),
3118 Name.getAsIdentifierInfo(),
3119 /*TypeParamList=*/nullptr,
3120 /*PrevDecl=*/nullptr, Loc,
3121 D->isImplicitInterfaceDecl());
3122 ToIface->setLexicalDeclContext(LexicalDC);
3123 LexicalDC->addDeclInternal(ToIface);
3124 }
3125 Importer.Imported(D, ToIface);
3126 // Import the type parameter list after calling Imported, to avoid
3127 // loops when bringing in their DeclContext.
3128 ToIface->setTypeParamList(ImportObjCTypeParamList(
3129 D->getTypeParamListAsWritten()));
3130
3131 if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToIface))
3132 return nullptr;
3133
3134 return ToIface;
3135}
3136
3137Decl *ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
3138 ObjCCategoryDecl *Category = cast_or_null<ObjCCategoryDecl>(
3139 Importer.Import(D->getCategoryDecl()));
3140 if (!Category)
3141 return nullptr;
3142
3143 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
3144 if (!ToImpl) {
3145 DeclContext *DC = Importer.ImportContext(D->getDeclContext());
3146 if (!DC)
3147 return nullptr;
3148
3149 SourceLocation CategoryNameLoc = Importer.Import(D->getCategoryNameLoc());
3150 ToImpl = ObjCCategoryImplDecl::Create(Importer.getToContext(), DC,
3151 Importer.Import(D->getIdentifier()),
3152 Category->getClassInterface(),
3153 Importer.Import(D->getLocation()),
3154 Importer.Import(D->getAtStartLoc()),
3155 CategoryNameLoc);
3156
3157 DeclContext *LexicalDC = DC;
3158 if (D->getDeclContext() != D->getLexicalDeclContext()) {
3159 LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
3160 if (!LexicalDC)
3161 return nullptr;
3162
3163 ToImpl->setLexicalDeclContext(LexicalDC);
3164 }
3165
3166 LexicalDC->addDeclInternal(ToImpl);
3167 Category->setImplementation(ToImpl);
3168 }
3169
3170 Importer.Imported(D, ToImpl);
3171 ImportDeclContext(D);
3172 return ToImpl;
3173}
3174
3175Decl *ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
3176 // Find the corresponding interface.
3177 ObjCInterfaceDecl *Iface = cast_or_null<ObjCInterfaceDecl>(
3178 Importer.Import(D->getClassInterface()));
3179 if (!Iface)
3180 return nullptr;
3181
3182 // Import the superclass, if any.
3183 ObjCInterfaceDecl *Super = nullptr;
3184 if (D->getSuperClass()) {
3185 Super = cast_or_null<ObjCInterfaceDecl>(
3186 Importer.Import(D->getSuperClass()));
3187 if (!Super)
3188 return nullptr;
3189 }
3190
3191 ObjCImplementationDecl *Impl = Iface->getImplementation();
3192 if (!Impl) {
3193 // We haven't imported an implementation yet. Create a new @implementation
3194 // now.
3195 Impl = ObjCImplementationDecl::Create(Importer.getToContext(),
3196 Importer.ImportContext(D->getDeclContext()),
3197 Iface, Super,
3198 Importer.Import(D->getLocation()),
3199 Importer.Import(D->getAtStartLoc()),
3200 Importer.Import(D->getSuperClassLoc()),
3201 Importer.Import(D->getIvarLBraceLoc()),
3202 Importer.Import(D->getIvarRBraceLoc()));
3203
3204 if (D->getDeclContext() != D->getLexicalDeclContext()) {
3205 DeclContext *LexicalDC
3206 = Importer.ImportContext(D->getLexicalDeclContext());
3207 if (!LexicalDC)
3208 return nullptr;
3209 Impl->setLexicalDeclContext(LexicalDC);
3210 }
3211
3212 // Associate the implementation with the class it implements.
3213 Iface->setImplementation(Impl);
3214 Importer.Imported(D, Iface->getImplementation());
3215 } else {
3216 Importer.Imported(D, Iface->getImplementation());
3217
3218 // Verify that the existing @implementation has the same superclass.
3219 if ((Super && !Impl->getSuperClass()) ||
3220 (!Super && Impl->getSuperClass()) ||
3221 (Super && Impl->getSuperClass() &&
3222 !declaresSameEntity(Super->getCanonicalDecl(),
3223 Impl->getSuperClass()))) {
3224 Importer.ToDiag(Impl->getLocation(),
3225 diag::err_odr_objc_superclass_inconsistent)
3226 << Iface->getDeclName();
3227 // FIXME: It would be nice to have the location of the superclass
3228 // below.
3229 if (Impl->getSuperClass())
3230 Importer.ToDiag(Impl->getLocation(),
3231 diag::note_odr_objc_superclass)
3232 << Impl->getSuperClass()->getDeclName();
3233 else
3234 Importer.ToDiag(Impl->getLocation(),
3235 diag::note_odr_objc_missing_superclass);
3236 if (D->getSuperClass())
3237 Importer.FromDiag(D->getLocation(),
3238 diag::note_odr_objc_superclass)
3239 << D->getSuperClass()->getDeclName();
3240 else
3241 Importer.FromDiag(D->getLocation(),
3242 diag::note_odr_objc_missing_superclass);
3243 return nullptr;
3244 }
3245 }
3246
3247 // Import all of the members of this @implementation.
3248 ImportDeclContext(D);
3249
3250 return Impl;
3251}
3252
3253Decl *ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
3254 // Import the major distinguishing characteristics of an @property.
3255 DeclContext *DC, *LexicalDC;
3256 DeclarationName Name;
3257 SourceLocation Loc;
3258 NamedDecl *ToD;
3259 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3260 return nullptr;
3261 if (ToD)
3262 return ToD;
3263
3264 // Check whether we have already imported this property.
3265 SmallVector<NamedDecl *, 2> FoundDecls;
3266 DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
3267 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
3268 if (ObjCPropertyDecl *FoundProp
3269 = dyn_cast<ObjCPropertyDecl>(FoundDecls[I])) {
3270 // Check property types.
3271 if (!Importer.IsStructurallyEquivalent(D->getType(),
3272 FoundProp->getType())) {
3273 Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent)
3274 << Name << D->getType() << FoundProp->getType();
3275 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
3276 << FoundProp->getType();
3277 return nullptr;
3278 }
3279
3280 // FIXME: Check property attributes, getters, setters, etc.?
3281
3282 // Consider these properties to be equivalent.
3283 Importer.Imported(D, FoundProp);
3284 return FoundProp;
3285 }
3286 }
3287
3288 // Import the type.
3289 TypeSourceInfo *TSI = Importer.Import(D->getTypeSourceInfo());
3290 if (!TSI)
3291 return nullptr;
3292
3293 // Create the new property.
3294 ObjCPropertyDecl *ToProperty
3295 = ObjCPropertyDecl::Create(Importer.getToContext(), DC, Loc,
3296 Name.getAsIdentifierInfo(),
3297 Importer.Import(D->getAtLoc()),
3298 Importer.Import(D->getLParenLoc()),
3299 Importer.Import(D->getType()),
3300 TSI,
3301 D->getPropertyImplementation());
3302 Importer.Imported(D, ToProperty);
3303 ToProperty->setLexicalDeclContext(LexicalDC);
3304 LexicalDC->addDeclInternal(ToProperty);
3305
3306 ToProperty->setPropertyAttributes(D->getPropertyAttributes());
3307 ToProperty->setPropertyAttributesAsWritten(
3308 D->getPropertyAttributesAsWritten());
3309 ToProperty->setGetterName(Importer.Import(D->getGetterName()),
3310 Importer.Import(D->getGetterNameLoc()));
3311 ToProperty->setSetterName(Importer.Import(D->getSetterName()),
3312 Importer.Import(D->getSetterNameLoc()));
3313 ToProperty->setGetterMethodDecl(
3314 cast_or_null<ObjCMethodDecl>(Importer.Import(D->getGetterMethodDecl())));
3315 ToProperty->setSetterMethodDecl(
3316 cast_or_null<ObjCMethodDecl>(Importer.Import(D->getSetterMethodDecl())));
3317 ToProperty->setPropertyIvarDecl(
3318 cast_or_null<ObjCIvarDecl>(Importer.Import(D->getPropertyIvarDecl())));
3319 return ToProperty;
3320}
3321
3322Decl *ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
3323 ObjCPropertyDecl *Property = cast_or_null<ObjCPropertyDecl>(
3324 Importer.Import(D->getPropertyDecl()));
3325 if (!Property)
18
Assuming 'Property' is non-null
19
Taking false branch
3326 return nullptr;
3327
3328 DeclContext *DC = Importer.ImportContext(D->getDeclContext());
3329 if (!DC)
20
Assuming 'DC' is non-null
21
Taking false branch
3330 return nullptr;
3331
3332 // Import the lexical declaration context.
3333 DeclContext *LexicalDC = DC;
3334 if (D->getDeclContext() != D->getLexicalDeclContext()) {
22
Assuming the condition is false
23
Taking false branch
3335 LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
3336 if (!LexicalDC)
3337 return nullptr;
3338 }
3339
3340 ObjCImplDecl *InImpl = dyn_cast<ObjCImplDecl>(LexicalDC);
3341 if (!InImpl)
24
Assuming 'InImpl' is non-null
25
Taking false branch
3342 return nullptr;
3343
3344 // Import the ivar (for an @synthesize).
3345 ObjCIvarDecl *Ivar = nullptr;
26
'Ivar' initialized to a null pointer value
3346 if (D->getPropertyIvarDecl()) {
27
Assuming the condition is false
28
Taking false branch
3347 Ivar = cast_or_null<ObjCIvarDecl>(
3348 Importer.Import(D->getPropertyIvarDecl()));
3349 if (!Ivar)
3350 return nullptr;
3351 }
3352
3353 ObjCPropertyImplDecl *ToImpl
3354 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
3355 Property->getQueryKind());
3356 if (!ToImpl) {
29
Assuming 'ToImpl' is non-null
30
Taking false branch
3357 ToImpl = ObjCPropertyImplDecl::Create(Importer.getToContext(), DC,
3358 Importer.Import(D->getLocStart()),
3359 Importer.Import(D->getLocation()),
3360 Property,
3361 D->getPropertyImplementation(),
3362 Ivar,
3363 Importer.Import(D->getPropertyIvarDeclLoc()));
3364 ToImpl->setLexicalDeclContext(LexicalDC);
3365 Importer.Imported(D, ToImpl);
3366 LexicalDC->addDeclInternal(ToImpl);
3367 } else {
3368 // Check that we have the same kind of property implementation (@synthesize
3369 // vs. @dynamic).
3370 if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) {
31
Taking false branch
3371 Importer.ToDiag(ToImpl->getLocation(),
3372 diag::err_odr_objc_property_impl_kind_inconsistent)
3373 << Property->getDeclName()
3374 << (ToImpl->getPropertyImplementation()
3375 == ObjCPropertyImplDecl::Dynamic);
3376 Importer.FromDiag(D->getLocation(),
3377 diag::note_odr_objc_property_impl_kind)
3378 << D->getPropertyDecl()->getDeclName()
3379 << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic);
3380 return nullptr;
3381 }
3382
3383 // For @synthesize, check that we have the same
3384 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize &&
32
Assuming the condition is true
34
Taking true branch
3385 Ivar != ToImpl->getPropertyIvarDecl()) {
33
Assuming the condition is true
3386 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
3387 diag::err_odr_objc_synthesize_ivar_inconsistent)
3388 << Property->getDeclName()
3389 << ToImpl->getPropertyIvarDecl()->getDeclName()
3390 << Ivar->getDeclName();
35
Called C++ object pointer is null
3391 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
3392 diag::note_odr_objc_synthesize_ivar_here)
3393 << D->getPropertyIvarDecl()->getDeclName();
3394 return nullptr;
3395 }
3396
3397 // Merge the existing implementation with the new implementation.
3398 Importer.Imported(D, ToImpl);
3399 }
3400
3401 return ToImpl;
3402}
3403
3404Decl *ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
3405 // For template arguments, we adopt the translation unit as our declaration
3406 // context. This context will be fixed when the actual template declaration
3407 // is created.
3408
3409 // FIXME: Import default argument.
3410 return TemplateTypeParmDecl::Create(Importer.getToContext(),
3411 Importer.getToContext().getTranslationUnitDecl(),
3412 Importer.Import(D->getLocStart()),
3413 Importer.Import(D->getLocation()),
3414 D->getDepth(),
3415 D->getIndex(),
3416 Importer.Import(D->getIdentifier()),
3417 D->wasDeclaredWithTypename(),
3418 D->isParameterPack());
3419}
3420
3421Decl *
3422ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
3423 // Import the name of this declaration.
3424 DeclarationName Name = Importer.Import(D->getDeclName());
3425 if (D->getDeclName() && !Name)
3426 return nullptr;
3427
3428 // Import the location of this declaration.
3429 SourceLocation Loc = Importer.Import(D->getLocation());
3430
3431 // Import the type of this declaration.
3432 QualType T = Importer.Import(D->getType());
3433 if (T.isNull())
3434 return nullptr;
3435
3436 // Import type-source information.
3437 TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
3438 if (D->getTypeSourceInfo() && !TInfo)
3439 return nullptr;
3440
3441 // FIXME: Import default argument.
3442
3443 return NonTypeTemplateParmDecl::Create(Importer.getToContext(),
3444 Importer.getToContext().getTranslationUnitDecl(),
3445 Importer.Import(D->getInnerLocStart()),
3446 Loc, D->getDepth(), D->getPosition(),
3447 Name.getAsIdentifierInfo(),
3448 T, D->isParameterPack(), TInfo);
3449}
3450
3451Decl *
3452ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
3453 // Import the name of this declaration.
3454 DeclarationName Name = Importer.Import(D->getDeclName());
3455 if (D->getDeclName() && !Name)
3456 return nullptr;
3457
3458 // Import the location of this declaration.
3459 SourceLocation Loc = Importer.Import(D->getLocation());
3460
3461 // Import template parameters.
3462 TemplateParameterList *TemplateParams
3463 = ImportTemplateParameterList(D->getTemplateParameters());
3464 if (!TemplateParams)
3465 return nullptr;
3466
3467 // FIXME: Import default argument.
3468
3469 return TemplateTemplateParmDecl::Create(Importer.getToContext(),
3470 Importer.getToContext().getTranslationUnitDecl(),
3471 Loc, D->getDepth(), D->getPosition(),
3472 D->isParameterPack(),
3473 Name.getAsIdentifierInfo(),
3474 TemplateParams);
3475}
3476
3477Decl *ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
3478 // If this record has a definition in the translation unit we're coming from,
3479 // but this particular declaration is not that definition, import the
3480 // definition and map to that.
3481 CXXRecordDecl *Definition
3482 = cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition());
3483 if (Definition && Definition != D->getTemplatedDecl()) {
3484 Decl *ImportedDef
3485 = Importer.Import(Definition->getDescribedClassTemplate());
3486 if (!ImportedDef)
3487 return nullptr;
3488
3489 return Importer.Imported(D, ImportedDef);
3490 }
3491
3492 // Import the major distinguishing characteristics of this class template.
3493 DeclContext *DC, *LexicalDC;
3494 DeclarationName Name;
3495 SourceLocation Loc;
3496 NamedDecl *ToD;
3497 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3498 return nullptr;
3499 if (ToD)
3500 return ToD;
3501
3502 // We may already have a template of the same name; try to find and match it.
3503 if (!DC->isFunctionOrMethod()) {
3504 SmallVector<NamedDecl *, 4> ConflictingDecls;
3505 SmallVector<NamedDecl *, 2> FoundDecls;
3506 DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
3507 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
3508 if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary))
3509 continue;
3510
3511 Decl *Found = FoundDecls[I];
3512 if (ClassTemplateDecl *FoundTemplate
3513 = dyn_cast<ClassTemplateDecl>(Found)) {
3514 if (IsStructuralMatch(D, FoundTemplate)) {
3515 // The class templates structurally match; call it the same template.
3516 // FIXME: We may be filling in a forward declaration here. Handle
3517 // this case!
3518 Importer.Imported(D->getTemplatedDecl(),
3519 FoundTemplate->getTemplatedDecl());
3520 return Importer.Imported(D, FoundTemplate);
3521 }
3522 }
3523
3524 ConflictingDecls.push_back(FoundDecls[I]);
3525 }
3526
3527 if (!ConflictingDecls.empty()) {
3528 Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary,
3529 ConflictingDecls.data(),
3530 ConflictingDecls.size());
3531 }
3532
3533 if (!Name)
3534 return nullptr;
3535 }
3536
3537 CXXRecordDecl *DTemplated = D->getTemplatedDecl();
3538
3539 // Create the declaration that is being templated.
3540 // Create the declaration that is being templated.
3541 CXXRecordDecl *D2Templated = cast_or_null<CXXRecordDecl>(
3542 Importer.Import(DTemplated));
3543 if (!D2Templated)
3544 return nullptr;
3545
3546 // Resolve possible cyclic import.
3547 if (Decl *AlreadyImported = Importer.GetAlreadyImportedOrNull(D))
3548 return AlreadyImported;
3549
3550 // Create the class template declaration itself.
3551 TemplateParameterList *TemplateParams
3552 = ImportTemplateParameterList(D->getTemplateParameters());
3553 if (!TemplateParams)
3554 return nullptr;
3555
3556 ClassTemplateDecl *D2 = ClassTemplateDecl::Create(Importer.getToContext(), DC,
3557 Loc, Name, TemplateParams,
3558 D2Templated);
3559 D2Templated->setDescribedClassTemplate(D2);
3560
3561 D2->setAccess(D->getAccess());
3562 D2->setLexicalDeclContext(LexicalDC);
3563 LexicalDC->addDeclInternal(D2);
3564
3565 // Note the relationship between the class templates.
3566 Importer.Imported(D, D2);
3567 Importer.Imported(DTemplated, D2Templated);
3568
3569 if (DTemplated->isCompleteDefinition() &&
3570 !D2Templated->isCompleteDefinition()) {
3571 // FIXME: Import definition!
3572 }
3573
3574 return D2;
3575}
3576
3577Decl *ASTNodeImporter::VisitClassTemplateSpecializationDecl(
3578 ClassTemplateSpecializationDecl *D) {
3579 // If this record has a definition in the translation unit we're coming from,
3580 // but this particular declaration is not that definition, import the
3581 // definition and map to that.
3582 TagDecl *Definition = D->getDefinition();
3583 if (Definition && Definition != D) {
3584 Decl *ImportedDef = Importer.Import(Definition);
3585 if (!ImportedDef)
3586 return nullptr;
3587
3588 return Importer.Imported(D, ImportedDef);
3589 }
3590
3591 ClassTemplateDecl *ClassTemplate
3592 = cast_or_null<ClassTemplateDecl>(Importer.Import(
3593 D->getSpecializedTemplate()));
3594 if (!ClassTemplate)
3595 return nullptr;
3596
3597 // Import the context of this declaration.
3598 DeclContext *DC = ClassTemplate->getDeclContext();
3599 if (!DC)
3600 return nullptr;
3601
3602 DeclContext *LexicalDC = DC;
3603 if (D->getDeclContext() != D->getLexicalDeclContext()) {
3604 LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
3605 if (!LexicalDC)
3606 return nullptr;
3607 }
3608
3609 // Import the location of this declaration.
3610 SourceLocation StartLoc = Importer.Import(D->getLocStart());
3611 SourceLocation IdLoc = Importer.Import(D->getLocation());
3612
3613 // Import template arguments.
3614 SmallVector<TemplateArgument, 2> TemplateArgs;
3615 if (ImportTemplateArguments(D->getTemplateArgs().data(),
3616 D->getTemplateArgs().size(),
3617 TemplateArgs))
3618 return nullptr;
3619
3620 // Try to find an existing specialization with these template arguments.
3621 void *InsertPos = nullptr;
3622 ClassTemplateSpecializationDecl *D2
3623 = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
3624 if (D2) {
3625 // We already have a class template specialization with these template
3626 // arguments.
3627
3628 // FIXME: Check for specialization vs. instantiation errors.
3629
3630 if (RecordDecl *FoundDef = D2->getDefinition()) {
3631 if (!D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) {
3632 // The record types structurally match, or the "from" translation
3633 // unit only had a forward declaration anyway; call it the same
3634 // function.
3635 return Importer.Imported(D, FoundDef);
3636 }
3637 }
3638 } else {
3639 // Create a new specialization.
3640 if (ClassTemplatePartialSpecializationDecl *PartialSpec =
3641 dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
3642
3643 // Import TemplateArgumentListInfo
3644 TemplateArgumentListInfo ToTAInfo;
3645 auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten();
3646 for (unsigned I = 0, E = ASTTemplateArgs.NumTemplateArgs; I < E; ++I) {
3647 bool Error = false;
3648 auto ToLoc = ImportTemplateArgumentLoc(ASTTemplateArgs[I], Error);
3649 if (Error)
3650 return nullptr;
3651 ToTAInfo.addArgument(ToLoc);
3652 }
3653
3654 QualType CanonInjType = Importer.Import(
3655 PartialSpec->getInjectedSpecializationType());
3656 if (CanonInjType.isNull())
3657 return nullptr;
3658 CanonInjType = CanonInjType.getCanonicalType();
3659
3660 TemplateParameterList *ToTPList = ImportTemplateParameterList(
3661 PartialSpec->getTemplateParameters());
3662 if (!ToTPList && PartialSpec->getTemplateParameters())
3663 return nullptr;
3664
3665 D2 = ClassTemplatePartialSpecializationDecl::Create(
3666 Importer.getToContext(), D->getTagKind(), DC, StartLoc, IdLoc,
3667 ToTPList, ClassTemplate,
3668 llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()),
3669 ToTAInfo, CanonInjType, nullptr);
3670
3671 } else {
3672 D2 = ClassTemplateSpecializationDecl::Create(Importer.getToContext(),
3673 D->getTagKind(), DC,
3674 StartLoc, IdLoc,
3675 ClassTemplate,
3676 TemplateArgs,
3677 /*PrevDecl=*/nullptr);
3678 }
3679
3680 D2->setSpecializationKind(D->getSpecializationKind());
3681
3682 // Add this specialization to the class template.
3683 ClassTemplate->AddSpecialization(D2, InsertPos);
3684
3685 // Import the qualifier, if any.
3686 D2->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
3687
3688 Importer.Imported(D, D2);
3689
3690 if (auto *TSI = D->getTypeAsWritten()) {
3691 TypeSourceInfo *TInfo = Importer.Import(TSI);
3692 if (!TInfo)
3693 return nullptr;
3694 D2->setTypeAsWritten(TInfo);
3695 D2->setTemplateKeywordLoc(Importer.Import(D->getTemplateKeywordLoc()));
3696 D2->setExternLoc(Importer.Import(D->getExternLoc()));
3697 }
3698
3699 SourceLocation POI = Importer.Import(D->getPointOfInstantiation());
3700 if (POI.isValid())
3701 D2->setPointOfInstantiation(POI);
3702 else if (D->getPointOfInstantiation().isValid())
3703 return nullptr;
3704
3705 D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind());
3706
3707 // Add the specialization to this context.
3708 D2->setLexicalDeclContext(LexicalDC);
3709 LexicalDC->addDeclInternal(D2);
3710 }
3711 Importer.Imported(D, D2);
3712 if (D->isCompleteDefinition() && ImportDefinition(D, D2))
3713 return nullptr;
3714
3715 return D2;
3716}
3717
3718Decl *ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) {
3719 // If this variable has a definition in the translation unit we're coming
3720 // from,
3721 // but this particular declaration is not that definition, import the
3722 // definition and map to that.
3723 VarDecl *Definition =
3724 cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition());
3725 if (Definition && Definition != D->getTemplatedDecl()) {
3726 Decl *ImportedDef = Importer.Import(Definition->getDescribedVarTemplate());
3727 if (!ImportedDef)
3728 return nullptr;
3729
3730 return Importer.Imported(D, ImportedDef);
3731 }
3732
3733 // Import the major distinguishing characteristics of this variable template.
3734 DeclContext *DC, *LexicalDC;
3735 DeclarationName Name;
3736 SourceLocation Loc;
3737 NamedDecl *ToD;
3738 if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3739 return nullptr;
3740 if (ToD)
3741 return ToD;
3742
3743 // We may already have a template of the same name; try to find and match it.
3744 assert(!DC->isFunctionOrMethod() &&(static_cast <bool> (!DC->isFunctionOrMethod() &&
"Variable templates cannot be declared at function scope") ?
void (0) : __assert_fail ("!DC->isFunctionOrMethod() && \"Variable templates cannot be declared at function scope\""
, "/build/llvm-toolchain-snapshot-6.0~svn318693/tools/clang/lib/AST/ASTImporter.cpp"
, 3745, __extension__ __PRETTY_FUNCTION__))
3745 "Variable templates cannot be declared at function scope")(static_cast <bool> (!DC->isFunctionOrMethod() &&
"Variable templates cannot be declared at function scope") ?
void (0) : __assert_fail ("!DC->isFunctionOrMethod() && \"Variable templates cannot be declared at function scope\""
, "/build/llvm-toolchain-snapshot-6.0~svn318693/tools/clang/lib/AST/ASTImporter.cpp"
, 3745, __extension__ __PRETTY_FUNCTION__))
;
3746 SmallVector<NamedDecl *, 4> ConflictingDecls;
3747 SmallVector<NamedDecl *, 2> FoundDecls;
3748 DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
3749 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
3750 if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary))
3751 continue;
3752
3753 Decl *Found = FoundDecls[I];
3754 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) {
3755 if (IsStructuralMatch(D, FoundTemplate)) {
3756 // The variable templates structurally match; call it the same template.
3757 Importer.Imported(D->getTemplatedDecl(),
3758 FoundTemplate->getTemplatedDecl());
3759 return Importer.Imported(D, FoundTemplate);
3760 }
3761 }
3762
3763 ConflictingDecls.push_back(FoundDecls[I]);
3764 }
3765
3766 if (!ConflictingDecls.empty()) {
3767 Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary,
3768 ConflictingDecls.data(),
3769 ConflictingDecls.size());
3770 }
3771
3772 if (!Name)
3773 return nullptr;
3774
3775 VarDecl *DTemplated = D->getTemplatedDecl();
3776
3777 // Import the type.
3778 QualType T = Importer.Import(DTemplated->getType());
3779 if (T.isNull())
3780 return nullptr;
3781
3782 // Create the declaration that is being templated.
3783 SourceLocation StartLoc = Importer.Import(DTemplated->getLocStart());
3784 SourceLocation IdLoc = Importer.Import(DTemplated->getLocation());
3785 TypeSourceInfo *TInfo = Importer.Import(DTemplated->getTypeSourceInfo());
3786 VarDecl *D2Templated = VarDecl::Create(Importer.getToContext(), DC, StartLoc,
3787 IdLoc, Name.getAsIdentifierInfo(), T,
3788 TInfo, DTemplated->getStorageClass());
3789 D2Templated->setAccess(DTemplated->getAccess());
3790 D2Templated->setQualifierInfo(Importer.Import(DTemplated->getQualifierLoc()));
3791 D2Templated->setLexicalDeclContext(LexicalDC);
3792
3793 // Importer.Imported(DTemplated, D2Templated);
3794 // LexicalDC->addDeclInternal(D2Templated);
3795
3796 // Merge the initializer.
3797 if (ImportDefinition(DTemplated, D2Templated))
3798 return nullptr;
3799
3800 // Create the variable template declaration itself.
3801 TemplateParameterList *TemplateParams =
3802 ImportTemplateParameterList(D->getTemplateParameters());
3803 if (!TemplateParams)
3804 return nullptr;
3805
3806 VarTemplateDecl *D2 = VarTemplateDecl::Create(
3807 Importer.getToContext(), DC, Loc, Name, TemplateParams, D2Templated);
3808 D2Templated->setDescribedVarTemplate(D2);
3809
3810 D2->setAccess(D->getAccess());
3811 D2->setLexicalDeclContext(LexicalDC);
3812 LexicalDC->addDeclInternal(D2);
3813
3814 // Note the relationship between the variable templates.
3815 Importer.Imported(D, D2);
3816 Importer.Imported(DTemplated, D2Templated);
3817
3818 if (DTemplated->isThisDeclarationADefinition() &&
3819 !D2Templated->isThisDeclarationADefinition()) {
3820 // FIXME: Import definition!
3821 }
3822
3823 return D2;
3824}
3825
3826Decl *ASTNodeImporter::VisitVarTemplateSpecializationDecl(
3827 VarTemplateSpecializationDecl *D) {
3828 // If this record has a definition in the translation unit we're coming from,
3829 // but this particular declaration is not that definition, import the
3830 // definition and map to that.
3831 VarDecl *Definition = D->getDefinition();
3832 if (Definition && Definition != D) {
3833 Decl *ImportedDef = Importer.Import(Definition);
3834 if (!ImportedDef)
3835 return nullptr;
3836
3837 return Importer.Imported(D, ImportedDef);
3838 }
3839
3840 VarTemplateDecl *VarTemplate = cast_or_null<VarTemplateDecl>(
3841 Importer.Import(D->getSpecializedTemplate()));
3842 if (!VarTemplate)
3843 return nullptr;
3844
3845 // Import the context of this declaration.
3846 DeclContext *DC = VarTemplate->getDeclContext();
3847 if (!DC)
3848 return nullptr;
3849
3850 DeclContext *LexicalDC = DC;
3851 if (D->getDeclContext() != D->getLexicalDeclContext()) {
3852 LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
3853 if (!LexicalDC)
3854 return nullptr;
3855 }
3856
3857 // Import the location of this declaration.
3858 SourceLocation StartLoc = Importer.Import(D->getLocStart());
3859 SourceLocation IdLoc = Importer.Import(D->getLocation());
3860
3861 // Import template arguments.
3862 SmallVector<TemplateArgument, 2> TemplateArgs;
3863 if (ImportTemplateArguments(D->getTemplateArgs().data(),
3864 D->getTemplateArgs().size(), TemplateArgs))
3865 return nullptr;
3866
3867 // Try to find an existing specialization with these template arguments.
3868 void *InsertPos = nullptr;
3869 VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization(
3870 TemplateArgs, InsertPos);
3871 if (D2) {
3872 // We already have a variable template specialization with these template
3873 // arguments.
3874
3875 // FIXME: Check for specialization vs. instantiation errors.
3876
3877 if (VarDecl *FoundDef = D2->getDefinition()) {
3878 if (!D->isThisDeclarationADefinition() ||
3879 IsStructuralMatch(D, FoundDef)) {
3880 // The record types structurally match, or the "from" translation
3881 // unit only had a forward declaration anyway; call it the same
3882 // variable.
3883 return Importer.Imported(D, FoundDef);
3884 }
3885 }
3886 } else {
3887
3888 // Import the type.
3889 QualType T = Importer.Import(D->getType());
3890 if (T.isNull())
3891 return nullptr;
3892 TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
3893
3894 // Create a new specialization.
3895 D2 = VarTemplateSpecializationDecl::Create(
3896 Importer.getToContext(), DC, StartLoc, IdLoc, VarTemplate, T, TInfo,
3897 D->getStorageClass(), TemplateArgs);
3898 D2->setSpecializationKind(D->getSpecializationKind());
3899 D2->setTemplateArgsInfo(D->getTemplateArgsInfo());
3900
3901 // Add this specialization to the class template.
3902 VarTemplate->AddSpecialization(D2, InsertPos);
3903
3904 // Import the qualifier, if any.
3905 D2->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
3906
3907 // Add the specialization to this context.
3908 D2->setLexicalDeclContext(LexicalDC);
3909 LexicalDC->addDeclInternal(D2);
3910 }
3911 Importer.Imported(D, D2);
3912
3913 if (D->isThisDeclarationADefinition() && ImportDefinition(D, D2))
3914 return nullptr;
3915
3916 return D2;
3917}
3918
3919//----------------------------------------------------------------------------
3920// Import Statements
3921//----------------------------------------------------------------------------
3922
3923DeclGroupRef ASTNodeImporter::ImportDeclGroup(DeclGroupRef DG) {
3924 if (DG.isNull())
3925 return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
3926 size_t NumDecls = DG.end() - DG.begin();
3927 SmallVector<Decl *, 1> ToDecls(NumDecls);
3928 auto &_Importer = this->Importer;
3929 std::transform(DG.begin(), DG.end(), ToDecls.begin(),
3930 [&_Importer](Decl *D) -> Decl * {
3931 return _Importer.Import(D);
3932 });
3933 return DeclGroupRef::Create(Importer.getToContext(),
3934 ToDecls.begin(),
3935 NumDecls);
3936}
3937
3938 Stmt *ASTNodeImporter::VisitStmt(Stmt *S) {
3939 Importer.FromDiag(S->getLocStart(), diag::err_unsupported_ast_node)
3940 << S->getStmtClassName();
3941 return nullptr;
3942 }
3943
3944
3945Stmt *ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) {
3946 SmallVector<IdentifierInfo *, 4> Names;
3947 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
3948 IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
3949 // ToII is nullptr when no symbolic name is given for output operand
3950 // see ParseStmtAsm::ParseAsmOperandsOpt
3951 if (!ToII && S->getOutputIdentifier(I))
3952 return nullptr;
3953 Names.push_back(ToII);
3954 }
3955 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
3956 IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
3957 // ToII is nullptr when no symbolic name is given for input operand
3958 // see ParseStmtAsm::ParseAsmOperandsOpt
3959 if (!ToII && S->getInputIdentifier(I))
3960 return nullptr;
3961 Names.push_back(ToII);
3962 }
3963
3964 SmallVector<StringLiteral *, 4> Clobbers;
3965 for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
3966 StringLiteral *Clobber = cast_or_null<StringLiteral>(
3967 Importer.Import(S->getClobberStringLiteral(I)));
3968 if (!Clobber)
3969 return nullptr;
3970 Clobbers.push_back(Clobber);
3971 }
3972
3973 SmallVector<StringLiteral *, 4> Constraints;
3974 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
3975 StringLiteral *Output = cast_or_null<StringLiteral>(
3976 Importer.Import(S->getOutputConstraintLiteral(I)));
3977 if (!Output)
3978 return nullptr;
3979 Constraints.push_back(Output);
3980 }
3981
3982 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
3983 StringLiteral *Input = cast_or_null<StringLiteral>(
3984 Importer.Import(S->getInputConstraintLiteral(I)));
3985 if (!Input)
3986 return nullptr;
3987 Constraints.push_back(Input);
3988 }
3989
3990 SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs());
3991 if (ImportContainerChecked(S->outputs(), Exprs))
3992 return nullptr;
3993
3994 if (ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
3995 return nullptr;
3996
3997 StringLiteral *AsmStr = cast_or_null<StringLiteral>(
3998 Importer.Import(S->getAsmString()));
3999 if (!AsmStr)
4000 return nullptr;
4001
4002 return new (Importer.getToContext()) GCCAsmStmt(
4003 Importer.getToContext(),
4004 Importer.Import(S->getAsmLoc()),
4005 S->isSimple(),
4006 S->isVolatile(),
4007 S->getNumOutputs(),
4008 S->getNumInputs(),
4009 Names.data(),
4010 Constraints.data(),
4011 Exprs.data(),
4012 AsmStr,
4013 S->getNumClobbers(),
4014 Clobbers.data(),
4015 Importer.Import(S->getRParenLoc()));
4016}
4017
4018Stmt *ASTNodeImporter::VisitDeclStmt(DeclStmt *S) {
4019 DeclGroupRef ToDG = ImportDeclGroup(S->getDeclGroup());
4020 for (Decl *ToD : ToDG) {
4021 if (!ToD)
4022 return nullptr;
4023 }
4024 SourceLocation ToStartLoc = Importer.Import(S->getStartLoc());
4025 SourceLocation ToEndLoc = Importer.Import(S->getEndLoc());
4026 return new (Importer.getToContext()) DeclStmt(ToDG, ToStartLoc, ToEndLoc);
4027}
4028
4029Stmt *ASTNodeImporter::VisitNullStmt(NullStmt *S) {
4030 SourceLocation ToSemiLoc = Importer.Import(S->getSemiLoc());
4031 return new (Importer.getToContext()) NullStmt(ToSemiLoc,
4032 S->hasLeadingEmptyMacro());
4033}
4034
4035Stmt *ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) {
4036 llvm::SmallVector<Stmt *, 8> ToStmts(S->size());
4037
4038 if (ImportContainerChecked(S->body(), ToStmts))
4039 return nullptr;
4040
4041 SourceLocation ToLBraceLoc = Importer.Import(S->getLBracLoc());
4042 SourceLocation ToRBraceLoc = Importer.Import(S->getRBracLoc());
4043 return new (Importer.getToContext()) CompoundStmt(Importer.getToContext(),
4044 ToStmts,
4045 ToLBraceLoc, ToRBraceLoc);
4046}
4047
4048Stmt *ASTNodeImporter::VisitCaseStmt(CaseStmt *S) {
4049 Expr *ToLHS = Importer.Import(S->getLHS());
4050 if (!ToLHS)
4051 return nullptr;
4052 Expr *ToRHS = Importer.Import(S->getRHS());
4053 if (!ToRHS && S->getRHS())
4054 return nullptr;
4055 Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
4056 if (!ToSubStmt && S->getSubStmt())
4057 return nullptr;
4058 SourceLocation ToCaseLoc = Importer.Import(S->getCaseLoc());
4059 SourceLocation ToEllipsisLoc = Importer.Import(S->getEllipsisLoc());
4060 SourceLocation ToColonLoc = Importer.Import(S->getColonLoc());
4061 CaseStmt *ToStmt = new (Importer.getToContext())
4062 CaseStmt(ToLHS, ToRHS, ToCaseLoc, ToEllipsisLoc, ToColonLoc);
4063 ToStmt->setSubStmt(ToSubStmt);
4064 return ToStmt;
4065}
4066
4067Stmt *ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) {
4068 SourceLocation ToDefaultLoc = Importer.Import(S->getDefaultLoc());
4069 SourceLocation ToColonLoc = Importer.Import(S->getColonLoc());
4070 Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
4071 if (!ToSubStmt && S->getSubStmt())
4072 return nullptr;
4073 return new (Importer.getToContext()) DefaultStmt(ToDefaultLoc, ToColonLoc,
4074 ToSubStmt);
4075}
4076
4077Stmt *ASTNodeImporter::VisitLabelStmt(LabelStmt *S) {
4078 SourceLocation ToIdentLoc = Importer.Import(S->getIdentLoc());
4079 LabelDecl *ToLabelDecl =
4080 cast_or_null<LabelDecl>(Importer.Import(S->getDecl()));
4081 if (!ToLabelDecl && S->getDecl())
4082 return nullptr;
4083 Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
4084 if (!ToSubStmt && S->getSubStmt())
4085 return nullptr;
4086 return new (Importer.getToContext()) LabelStmt(ToIdentLoc, ToLabelDecl,
4087 ToSubStmt);
4088}
4089
4090Stmt *ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) {
4091 SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc());
4092 ArrayRef<const Attr*> FromAttrs(S->getAttrs());
4093 SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
4094 ASTContext &_ToContext = Importer.getToContext();
4095 std::transform(FromAttrs.begin(), FromAttrs.end(), ToAttrs.begin(),
4096 [&_ToContext](const Attr *A) -> const Attr * {
4097 return A->clone(_ToContext);
4098 });
4099 for (const Attr *ToA : ToAttrs) {
4100 if (!ToA)
4101 return nullptr;
4102 }
4103 Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
4104 if (!ToSubStmt && S->getSubStmt())
4105 return nullptr;
4106 return AttributedStmt::Create(Importer.getToContext(), ToAttrLoc,
4107 ToAttrs, ToSubStmt);
4108}
4109
4110Stmt *ASTNodeImporter::VisitIfStmt(IfStmt *S) {
4111 SourceLocation ToIfLoc = Importer.Import(S->getIfLoc());
4112 Stmt *ToInit = Importer.Import(S->getInit());
4113 if (!ToInit && S->getInit())
4114 return nullptr;
4115 VarDecl *ToConditionVariable = nullptr;
4116 if (VarDecl *FromConditionVariable = S->getConditionVariable()) {
4117 ToConditionVariable =
4118 dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable));
4119 if (!ToConditionVariable)
4120 return nullptr;
4121 }
4122 Expr *ToCondition = Importer.Import(S->getCond());
4123 if (!ToCondition && S->getCond())
4124 return nullptr;
4125 Stmt *ToThenStmt = Importer.Import(S->getThen());
4126 if (!ToThenStmt && S->getThen())
4127 return nullptr;
4128 SourceLocation ToElseLoc = Importer.Import(S->getElseLoc());
4129 Stmt *ToElseStmt = Importer.Import(S->getElse());
4130 if (!ToElseStmt && S->getElse())
4131 return nullptr;
4132 return new (Importer.getToContext()) IfStmt(Importer.getToContext(),
4133 ToIfLoc, S->isConstexpr(),
4134 ToInit,
4135 ToConditionVariable,
4136 ToCondition, ToThenStmt,
4137 ToElseLoc, ToElseStmt);
4138}
4139
4140Stmt *ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) {
4141 Stmt *ToInit = Importer.Import(S->getInit());
4142 if (!ToInit && S->getInit())
4143 return nullptr;
4144 VarDecl *ToConditionVariable = nullptr;
4145 if (VarDecl *FromConditionVariable = S->getConditionVariable()) {
4146 ToConditionVariable =
4147 dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable));
4148 if (!ToConditionVariable)
4149 return nullptr;
4150 }
4151 Expr *ToCondition = Importer.Import(S->getCond());
4152 if (!ToCondition && S->getCond())
4153 return nullptr;
4154 SwitchStmt *ToStmt = new (Importer.getToContext()) SwitchStmt(
4155 Importer.getToContext(), ToInit,
4156 ToConditionVariable, ToCondition);
4157 Stmt *ToBody = Importer.Import(S->getBody());
4158 if (!ToBody && S->getBody())
4159 return nullptr;
4160 ToStmt->setBody(ToBody);
4161 ToStmt->setSwitchLoc(Importer.Import(S->getSwitchLoc()));
4162 // Now we have to re-chain the cases.
4163 SwitchCase *LastChainedSwitchCase = nullptr;
4164 for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
4165 SC = SC->getNextSwitchCase()) {
4166 SwitchCase *ToSC = dyn_cast_or_null<SwitchCase>(Importer.Import(SC));
4167 if (!ToSC)
4168 return nullptr;
4169 if (LastChainedSwitchCase)
4170 LastChainedSwitchCase->setNextSwitchCase(ToSC);
4171 else
4172 ToStmt->setSwitchCaseList(ToSC);
4173 LastChainedSwitchCase = ToSC;
4174 }
4175 return ToStmt;
4176}
4177
4178Stmt *ASTNodeImporter::VisitWhileStmt(WhileStmt *S) {
4179 VarDecl *ToConditionVariable = nullptr;
4180 if (VarDecl *FromConditionVariable = S->getConditionVariable()) {
4181 ToConditionVariable =
4182 dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable));
4183 if (!ToConditionVariable)
4184 return nullptr;
4185 }
4186 Expr *ToCondition = Importer.Import(S->getCond());
4187 if (!ToCondition && S->getCond())
4188 return nullptr;
4189 Stmt *ToBody = Importer.Import(S->getBody());
4190 if (!ToBody && S->getBody())
4191 return nullptr;
4192 SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc());
4193 return new (Importer.getToContext()) WhileStmt(Importer.getToContext(),
4194 ToConditionVariable,
4195 ToCondition, ToBody,
4196 ToWhileLoc);
4197}
4198
4199Stmt *ASTNodeImporter::VisitDoStmt(DoStmt *S) {
4200 Stmt *ToBody = Importer.Import(S->getBody());
4201 if (!ToBody && S->getBody())
4202 return nullptr;
4203 Expr *ToCondition = Importer.Import(S->getCond());
4204 if (!ToCondition && S->getCond())
4205 return nullptr;
4206 SourceLocation ToDoLoc = Importer.Import(S->getDoLoc());
4207 SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc());
4208 SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
4209 return new (Importer.getToContext()) DoStmt(ToBody, ToCondition,
4210 ToDoLoc, ToWhileLoc,
4211 ToRParenLoc);
4212}
4213
4214Stmt *ASTNodeImporter::VisitForStmt(ForStmt *S) {
4215 Stmt *ToInit = Importer.Import(S->getInit());
4216 if (!ToInit && S->getInit())
4217 return nullptr;
4218 Expr *ToCondition = Importer.Import(S->getCond());
4219 if (!ToCondition && S->getCond())
4220 return nullptr;
4221 VarDecl *ToConditionVariable = nullptr;
4222 if (VarDecl *FromConditionVariable = S->getConditionVariable()) {
4223 ToConditionVariable =
4224 dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable));
4225 if (!ToConditionVariable)
4226 return nullptr;
4227 }
4228 Expr *ToInc = Importer.Import(S->getInc());
4229 if (!ToInc && S->getInc())
4230 return nullptr;
4231 Stmt *ToBody = Importer.Import(S->getBody());
4232 if (!ToBody && S->getBody())
4233 return nullptr;
4234 SourceLocation ToForLoc = Importer.Import(S->getForLoc());
4235 SourceLocation ToLParenLoc = Importer.Import(S->getLParenLoc());
4236 SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
4237 return new (Importer.getToContext()) ForStmt(Importer.getToContext(),
4238 ToInit, ToCondition,
4239 ToConditionVariable,
4240 ToInc, ToBody,
4241 ToForLoc, ToLParenLoc,
4242 ToRParenLoc);
4243}
4244
4245Stmt *ASTNodeImporter::VisitGotoStmt(GotoStmt *S) {
4246 LabelDecl *ToLabel = nullptr;
4247 if (LabelDecl *FromLabel = S->getLabel()) {
4248 ToLabel = dyn_cast_or_null<LabelDecl>(Importer.Import(FromLabel));
4249 if (!ToLabel)
4250 return nullptr;
4251 }
4252 SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc());
4253 SourceLocation ToLabelLoc = Importer.Import(S->getLabelLoc());
4254 return new (Importer.getToContext()) GotoStmt(ToLabel,
4255 ToGotoLoc, ToLabelLoc);
4256}
4257
4258Stmt *ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
4259 SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc());
4260 SourceLocation ToStarLoc = Importer.Import(S->getStarLoc());
4261 Expr *ToTarget = Importer.Import(S->getTarget());
4262 if (!ToTarget && S->getTarget())
4263 return nullptr;
4264 return new (Importer.getToContext()) IndirectGotoStmt(ToGotoLoc, ToStarLoc,
4265 ToTarget);
4266}
4267
4268Stmt *ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) {
4269 SourceLocation ToContinueLoc = Importer.Import(S->getContinueLoc());
4270 return new (Importer.getToContext()) ContinueStmt(ToContinueLoc);
4271}
4272
4273Stmt *ASTNodeImporter::VisitBreakStmt(BreakStmt *S) {
4274 SourceLocation ToBreakLoc = Importer.Import(S->getBreakLoc());
4275 return new (Importer.getToContext()) BreakStmt(ToBreakLoc);
4276}
4277
4278Stmt *ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) {
4279 SourceLocation ToRetLoc = Importer.Import(S->getReturnLoc());
4280 Expr *ToRetExpr = Importer.Import(S->getRetValue());
4281 if (!ToRetExpr && S->getRetValue())
4282 return nullptr;
4283 VarDecl *NRVOCandidate = const_cast<VarDecl*>(S->getNRVOCandidate());
4284 VarDecl *ToNRVOCandidate = cast_or_null<VarDecl>(Importer.Import(NRVOCandidate));
4285 if (!ToNRVOCandidate && NRVOCandidate)
4286 return nullptr;
4287 return new (Importer.getToContext()) ReturnStmt(ToRetLoc, ToRetExpr,
4288 ToNRVOCandidate);
4289}
4290
4291Stmt *ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) {
4292 SourceLocation ToCatchLoc = Importer.Import(S->getCatchLoc());
4293 VarDecl *ToExceptionDecl = nullptr;
4294 if (VarDecl *FromExceptionDecl = S->getExceptionDecl()) {
4295 ToExceptionDecl =
4296 dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl));
4297 if (!ToExceptionDecl)
4298 return nullptr;
4299 }
4300 Stmt *ToHandlerBlock = Importer.Import(S->getHandlerBlock());
4301 if (!ToHandlerBlock && S->getHandlerBlock())
4302 return nullptr;
4303 return new (Importer.getToContext()) CXXCatchStmt(ToCatchLoc,
4304 ToExceptionDecl,
4305 ToHandlerBlock);
4306}
4307
4308Stmt *ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) {
4309 SourceLocation ToTryLoc = Importer.Import(S->getTryLoc());
4310 Stmt *ToTryBlock = Importer.Import(S->getTryBlock());
4311 if (!ToTryBlock && S->getTryBlock())
4312 return nullptr;
4313 SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
4314 for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
4315 CXXCatchStmt *FromHandler = S->getHandler(HI);
4316 if (Stmt *ToHandler = Importer.Import(FromHandler))
4317 ToHandlers[HI] = ToHandler;
4318 else
4319 return nullptr;
4320 }
4321 return CXXTryStmt::Create(Importer.getToContext(), ToTryLoc, ToTryBlock,
4322 ToHandlers);
4323}
4324
4325Stmt *ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
4326 DeclStmt *ToRange =
4327 dyn_cast_or_null<DeclStmt>(Importer.Import(S->getRangeStmt()));
4328 if (!ToRange && S->getRangeStmt())
4329 return nullptr;
4330 DeclStmt *ToBegin =
4331 dyn_cast_or_null<DeclStmt>(Importer.Import(S->getBeginStmt()));
4332 if (!ToBegin && S->getBeginStmt())
4333 return nullptr;
4334 DeclStmt *ToEnd =
4335 dyn_cast_or_null<DeclStmt>(Importer.Import(S->getEndStmt()));
4336 if (!ToEnd && S->getEndStmt())
4337 return nullptr;
4338 Expr *ToCond = Importer.Import(S->getCond());
4339 if (!ToCond && S->getCond())
4340 return nullptr;
4341 Expr *ToInc = Importer.Import(S->getInc());
4342 if (!ToInc && S->getInc())
4343 return nullptr;
4344 DeclStmt *ToLoopVar =
4345 dyn_cast_or_null<DeclStmt>(Importer.Import(S->getLoopVarStmt()));
4346 if (!ToLoopVar && S->getLoopVarStmt())
4347 return nullptr;
4348 Stmt *ToBody = Importer.Import(S->getBody());
4349 if (!ToBody && S->getBody())
4350 return nullptr;
4351 SourceLocation ToForLoc = Importer.Import(S->getForLoc());
4352 SourceLocation ToCoawaitLoc = Importer.Import(S->getCoawaitLoc());
4353 SourceLocation ToColonLoc = Importer.Import(S->getColonLoc());
4354 SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
4355 return new (Importer.getToContext()) CXXForRangeStmt(ToRange, ToBegin, ToEnd,
4356 ToCond, ToInc,
4357 ToLoopVar, ToBody,
4358 ToForLoc, ToCoawaitLoc,
4359 ToColonLoc, ToRParenLoc);
4360}
4361
4362Stmt *ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
4363 Stmt *ToElem = Importer.Import(S->getElement());
4364 if (!ToElem && S->getElement())
4365 return nullptr;
4366 Expr *ToCollect = Importer.Import(S->getCollection());
4367 if (!ToCollect && S->getCollection())
4368 return nullptr;
4369 Stmt *ToBody = Importer.Import(S->getBody());
4370 if (!ToBody && S->getBody())
4371 return nullptr;
4372 SourceLocation ToForLoc = Importer.Import(S->getForLoc());
4373 SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
4374 return new (Importer.getToContext()) ObjCForCollectionStmt(ToElem,
4375 ToCollect,
4376 ToBody, ToForLoc,
4377 ToRParenLoc);
4378}
4379
4380Stmt *ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
4381 SourceLocation ToAtCatchLoc = Importer.Import(S->getAtCatchLoc());
4382 SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
4383 VarDecl *ToExceptionDecl = nullptr;
4384 if (VarDecl *FromExceptionDecl = S->getCatchParamDecl()) {
4385 ToExceptionDecl =
4386 dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl));
4387 if (!ToExceptionDecl)
4388 return nullptr;
4389 }
4390 Stmt *ToBody = Importer.Import(S->getCatchBody());
4391 if (!ToBody && S->getCatchBody())
4392 return nullptr;
4393 return new (Importer.getToContext()) ObjCAtCatchStmt(ToAtCatchLoc,
4394 ToRParenLoc,
4395 ToExceptionDecl,
4396 ToBody);
4397}
4398
4399Stmt *ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
4400 SourceLocation ToAtFinallyLoc = Importer.Import(S->getAtFinallyLoc());
4401 Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyBody());
4402 if (!ToAtFinallyStmt && S->getFinallyBody())
4403 return nullptr;
4404 return new (Importer.getToContext()) ObjCAtFinallyStmt(ToAtFinallyLoc,
4405 ToAtFinallyStmt);
4406}
4407
4408Stmt *ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
4409 SourceLocation ToAtTryLoc = Importer.Import(S->getAtTryLoc());
4410 Stmt *ToAtTryStmt = Importer.Import(S->getTryBody());
4411 if (!ToAtTryStmt && S->getTryBody())
4412 return nullptr;
4413 SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
4414 for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
4415 ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
4416 if (Stmt *ToCatchStmt = Importer.Import(FromCatchStmt))
4417 ToCatchStmts[CI] = ToCatchStmt;
4418 else
4419 return nullptr;
4420 }
4421 Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyStmt());
4422 if (!ToAtFinallyStmt && S->getFinallyStmt())
4423 return nullptr;
4424 return ObjCAtTryStmt::Create(Importer.getToContext(),
4425 ToAtTryLoc, ToAtTryStmt,
4426 ToCatchStmts.begin(), ToCatchStmts.size(),
4427 ToAtFinallyStmt);
4428}
4429
4430Stmt *ASTNodeImporter::VisitObjCAtSynchronizedStmt
4431 (ObjCAtSynchronizedStmt *S) {
4432 SourceLocation ToAtSynchronizedLoc =
4433 Importer.Import(S->getAtSynchronizedLoc());
4434 Expr *ToSynchExpr = Importer.Import(S->getSynchExpr());
4435 if (!ToSynchExpr && S->getSynchExpr())
4436 return nullptr;
4437 Stmt *ToSynchBody = Importer.Import(S->getSynchBody());
4438 if (!ToSynchBody && S->getSynchBody())
4439 return nullptr;
4440 return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
4441 ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
4442}
4443
4444Stmt *ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
4445 SourceLocation ToAtThrowLoc = Importer.Import(S->getThrowLoc());
4446 Expr *ToThrow = Importer.Import(S->getThrowExpr());
4447 if (!ToThrow && S->getThrowExpr())
4448 return nullptr;
4449 return new (Importer.getToContext()) ObjCAtThrowStmt(ToAtThrowLoc, ToThrow);
4450}
4451
4452Stmt *ASTNodeImporter::VisitObjCAutoreleasePoolStmt
4453 (ObjCAutoreleasePoolStmt *S) {
4454 SourceLocation ToAtLoc = Importer.Import(S->getAtLoc());
4455 Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
4456 if (!ToSubStmt && S->getSubStmt())
4457 return nullptr;
4458 return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(ToAtLoc,
4459 ToSubStmt);
4460}
4461
4462//----------------------------------------------------------------------------
4463// Import Expressions
4464//----------------------------------------------------------------------------
4465Expr *ASTNodeImporter::VisitExpr(Expr *E) {
4466 Importer.FromDiag(E->getLocStart(), diag::err_unsupported_ast_node)
4467 << E->getStmtClassName();
4468 return nullptr;
4469}
4470
4471Expr *ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) {
4472 QualType T = Importer.Import(E->getType());
4473 if (T.isNull())
4474 return nullptr;
4475
4476 Expr *SubExpr = Importer.Import(E->getSubExpr());
4477 if (!SubExpr && E->getSubExpr())
4478 return nullptr;
4479
4480 TypeSourceInfo *TInfo = Importer.Import(E->getWrittenTypeInfo());
4481 if (!TInfo)
4482 return nullptr;
4483
4484 return new (Importer.getToContext()) VAArgExpr(
4485 Importer.Import(E->getBuiltinLoc()), SubExpr, TInfo,
4486 Importer.Import(E->getRParenLoc()), T, E->isMicrosoftABI());
4487}
4488
4489
4490Expr *ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) {
4491 QualType T = Importer.Import(E->getType());
4492 if (T.isNull())
4493 return nullptr;
4494
4495 return new (Importer.getToContext()) GNUNullExpr(
4496 T, Importer.Import(E->getLocStart()));
4497}
4498
4499Expr *ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) {
4500 QualType T = Importer.Import(E->getType());
4501 if (T.isNull())
4502 return nullptr;
4503
4504 StringLiteral *SL = cast_or_null<StringLiteral>(
4505 Importer.Import(E->getFunctionName()));
4506 if (!SL && E->getFunctionName())
4507 return nullptr;
4508
4509 return new (Importer.getToContext()) PredefinedExpr(
4510 Importer.Import(E->getLocStart()), T, E->getIdentType(), SL);
4511}
4512
4513Expr *ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) {
4514 ValueDecl *ToD = cast_or_null<ValueDecl>(Importer.Import(E->getDecl()));
4515 if (!ToD)
4516 return nullptr;
4517
4518 NamedDecl *FoundD = nullptr;
4519 if (E->getDecl() != E->getFoundDecl()) {
4520 FoundD = cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl()));
4521 if (!FoundD)
4522 return nullptr;
4523 }
4524
4525 QualType T = Importer.Import(E->getType());
4526 if (T.isNull())
4527 return nullptr;
4528
4529
4530 TemplateArgumentListInfo ToTAInfo;
4531 TemplateArgumentListInfo *ResInfo = nullptr;
4532 if (E->hasExplicitTemplateArgs()) {
4533 for (const auto &FromLoc : E->template_arguments()) {
4534 bool Error = false;
4535 TemplateArgumentLoc ToTALoc = ImportTemplateArgumentLoc(FromLoc, Error);
4536 if (Error)
4537 return nullptr;
4538 ToTAInfo.addArgument(ToTALoc);
4539 }
4540 ResInfo = &ToTAInfo;
4541 }
4542
4543 DeclRefExpr *DRE = DeclRefExpr::Create(Importer.getToContext(),
4544 Importer.Import(E->getQualifierLoc()),
4545 Importer.Import(E->getTemplateKeywordLoc()),
4546 ToD,
4547 E->refersToEnclosingVariableOrCapture(),
4548 Importer.Import(E->getLocation()),
4549 T, E->getValueKind(),
4550 FoundD, ResInfo);
4551 if (E->hadMultipleCandidates())
4552 DRE->setHadMultipleCandidates(true);
4553 return DRE;
4554}
4555
4556Expr *ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
4557 QualType T = Importer.Import(E->getType());
4558 if (T.isNull())
4559 return nullptr;
4560
4561 return new (Importer.getToContext()) ImplicitValueInitExpr(T);
4562}
4563
4564ASTNodeImporter::Designator
4565ASTNodeImporter::ImportDesignator(const Designator &D) {
4566 if (D.isFieldDesignator()) {
4567 IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
4568 // Caller checks for import error
4569 return Designator(ToFieldName, Importer.Import(D.getDotLoc()),
4570 Importer.Import(D.getFieldLoc()));
4571 }
4572 if (D.isArrayDesignator())
4573 return Designator(D.getFirstExprIndex(),
4574 Importer.Import(D.getLBracketLoc()),
4575 Importer.Import(D.getRBracketLoc()));
4576
4577 assert(D.isArrayRangeDesignator())(static_cast <bool> (D.isArrayRangeDesignator()) ? void
(0) : __assert_fail ("D.isArrayRangeDesignator()", "/build/llvm-toolchain-snapshot-6.0~svn318693/tools/clang/lib/AST/ASTImporter.cpp"
, 4577, __extension__ __PRETTY_FUNCTION__))
;
4578 return Designator(D.getFirstExprIndex(),
4579 Importer.Import(D.getLBracketLoc()),
4580 Importer.Import(D.getEllipsisLoc()),
4581 Importer.Import(D.getRBracketLoc()));
4582}
4583
4584
4585Expr *ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *DIE) {
4586 Expr *Init = cast_or_null<Expr>(Importer.Import(DIE->getInit()));
4587 if (!Init)
4588 return nullptr;
4589
4590 SmallVector<Expr *, 4> IndexExprs(DIE->getNumSubExprs() - 1);
4591 // List elements from the second, the first is Init itself
4592 for (unsigned I = 1, E = DIE->getNumSubExprs(); I < E; I++) {
4593 if (Expr *Arg = cast_or_null<Expr>(Importer.Import(DIE->getSubExpr(I))))
4594 IndexExprs[I - 1] = Arg;
4595 else
4596 return nullptr;
4597 }
4598
4599 SmallVector<Designator, 4> Designators(DIE->size());
4600 llvm::transform(DIE->designators(), Designators.begin(),
4601 [this](const Designator &D) -> Designator {
4602 return ImportDesignator(D);
4603 });
4604
4605 for (const Designator &D : DIE->designators())
4606 if (D.isFieldDesignator() && !D.getFieldName())
4607 return nullptr;
4608
4609 return DesignatedInitExpr::Create(
4610 Importer.getToContext(), Designators,
4611 IndexExprs, Importer.Import(DIE->getEqualOrColonLoc()),
4612 DIE->usesGNUSyntax(), Init);
4613}
4614
4615Expr *ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
4616 QualType T = Importer.Import(E->getType());
4617 if (T.isNull())
4618 return nullptr;
4619
4620 return new (Importer.getToContext())
4621 CXXNullPtrLiteralExpr(T, Importer.Import(E->getLocation()));
4622}
4623
4624Expr *ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) {
4625 QualType T = Importer.Import(E->getType());
4626 if (T.isNull())
4627 return nullptr;
4628
4629 return IntegerLiteral::Create(Importer.getToContext(),
4630 E->getValue(), T,
4631 Importer.Import(E->getLocation()));
4632}
4633
4634Expr *ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) {
4635 QualType T = Importer.Import(E->getType());
4636 if (T.isNull())
4637 return nullptr;
4638
4639 return FloatingLiteral::Create(Importer.getToContext(),
4640 E->getValue(), E->isExact(), T,
4641 Importer.Import(E->getLocation()));
4642}
4643
4644Expr *ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) {
4645 QualType T = Importer.Import(E->getType());
4646 if (T.isNull())
4647 return nullptr;
4648
4649 return new (Importer.getToContext()) CharacterLiteral(E->getValue(),
4650 E->getKind(), T,
4651 Importer.Import(E->getLocation()));
4652}
4653
4654Expr *ASTNodeImporter::VisitStringLiteral(StringLiteral *E) {
4655 QualType T = Importer.Import(E->getType());
4656 if (T.isNull())
4657 return nullptr;
4658
4659 SmallVector<SourceLocation, 4> Locations(E->getNumConcatenated());
4660 ImportArray(E->tokloc_begin(), E->tokloc_end(), Locations.begin());
4661
4662 return StringLiteral::Create(Importer.getToContext(), E->getBytes(),
4663 E->getKind(), E->isPascal(), T,
4664 Locations.data(), Locations.size());
4665}
4666
4667Expr *ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
4668 QualType T = Importer.Import(E->getType());
4669 if (T.isNull())
4670 return nullptr;
4671
4672 TypeSourceInfo *TInfo = Importer.Import(E->getTypeSourceInfo());
4673 if (!TInfo)
4674 return nullptr;
4675
4676 Expr *Init = Importer.Import(E->getInitializer());
4677 if (!Init)
4678 return nullptr;
4679
4680 return new (Importer.getToContext()) CompoundLiteralExpr(
4681 Importer.Import(E->getLParenLoc()), TInfo, T, E->getValueKind(),
4682 Init, E->isFileScope());
4683}
4684
4685Expr *ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) {
4686 QualType T = Importer.Import(E->getType());
4687 if (T.isNull())
4688 return nullptr;
4689
4690 SmallVector<Expr *, 6> Exprs(E->getNumSubExprs());
4691 if (ImportArrayChecked(
4692 E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
4693 Exprs.begin()))
4694 return nullptr;
4695
4696 return new (Importer.getToContext()) AtomicExpr(
4697 Importer.Import(E->getBuiltinLoc()), Exprs, T, E->getOp(),
4698 Importer.Import(E->getRParenLoc()));
4699}
4700
4701Expr *ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) {
4702 QualType T = Importer.Import(E->getType());
4703 if (T.isNull())
4704 return nullptr;
4705
4706 LabelDecl *ToLabel = cast_or_null<LabelDecl>(Importer.Import(E->getLabel()));
4707 if (!ToLabel)
4708 return nullptr;
4709
4710 return new (Importer.getToContext()) AddrLabelExpr(
4711 Importer.Import(E->getAmpAmpLoc()), Importer.Import(E->getLabelLoc()),
4712 ToLabel, T);
4713}
4714
4715Expr *ASTNodeImporter::VisitParenExpr(ParenExpr *E) {
4716 Expr *SubExpr = Importer.Import(E->getSubExpr());
4717 if (!SubExpr)
4718 return nullptr;
4719
4720 return new (Importer.getToContext())
4721 ParenExpr(Importer.Import(E->getLParen()),
4722 Importer.Import(E->getRParen()),
4723 SubExpr);
4724}
4725
4726Expr *ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) {
4727 SmallVector<Expr *, 4> Exprs(E->getNumExprs());
4728 if (ImportContainerChecked(E->exprs(), Exprs))
4729 return nullptr;
4730
4731 return new (Importer.getToContext()) ParenListExpr(
4732 Importer.getToContext(), Importer.Import(E->getLParenLoc()),
4733 Exprs, Importer.Import(E->getLParenLoc()));
4734}
4735
4736Expr *ASTNodeImporter::VisitStmtExpr(StmtExpr *E) {
4737 QualType T = Importer.Import(E->getType());
4738 if (T.isNull())
4739 return nullptr;
4740
4741 CompoundStmt *ToSubStmt = cast_or_null<CompoundStmt>(
4742 Importer.Import(E->getSubStmt()));
4743 if (!ToSubStmt && E->getSubStmt())
4744 return nullptr;
4745
4746 return new (Importer.getToContext()) StmtExpr(ToSubStmt, T,
4747 Importer.Import(E->getLParenLoc()), Importer.Import(E->getRParenLoc()));
4748}
4749
4750Expr *ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) {
4751 QualType T = Importer.Import(E->getType());
4752 if (T.isNull())
4753 return nullptr;
4754
4755 Expr *SubExpr = Importer.Import(E->getSubExpr());
4756 if (!SubExpr)
4757 return nullptr;
4758
4759 return new (Importer.getToContext()) UnaryOperator(SubExpr, E->getOpcode(),
4760 T, E->getValueKind(),
4761 E->getObjectKind(),
4762 Importer.Import(E->getOperatorLoc()));
4763}
4764
4765Expr *ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(
4766 UnaryExprOrTypeTraitExpr *E) {
4767 QualType ResultType = Importer.Import(E->getType());
4768
4769 if (E->isArgumentType()) {
4770 TypeSourceInfo *TInfo = Importer.Import(E->getArgumentTypeInfo());
4771 if (!TInfo)
4772 return nullptr;
4773
4774 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(),
4775 TInfo, ResultType,
4776 Importer.Import(E->getOperatorLoc()),
4777 Importer.Import(E->getRParenLoc()));
4778 }
4779
4780 Expr *SubExpr = Importer.Import(E->getArgumentExpr());
4781 if (!SubExpr)
4782 return nullptr;
4783
4784 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(),
4785 SubExpr, ResultType,
4786 Importer.Import(E->getOperatorLoc()),
4787 Importer.Import(E->getRParenLoc()));
4788}
4789
4790Expr *ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) {
4791 QualType T = Importer.Import(E->getType());
4792 if (T.isNull())
4793 return nullptr;
4794
4795 Expr *LHS = Importer.Import(E->getLHS());
4796 if (!LHS)
4797 return nullptr;
4798
4799 Expr *RHS = Importer.Import(E->getRHS());
4800 if (!RHS)
4801 return nullptr;
4802
4803 return new (Importer.getToContext()) BinaryOperator(LHS, RHS, E->getOpcode(),
4804 T, E->getValueKind(),
4805 E->getObjectKind(),
4806 Importer.Import(E->getOperatorLoc()),
4807 E->getFPFeatures());
4808}
4809
4810Expr *ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) {
4811 QualType T = Importer.Import(E->getType());
4812 if (T.isNull())
4813 return nullptr;
4814
4815 Expr *ToLHS = Importer.Import(E->getLHS());
4816 if (!ToLHS)
4817 return nullptr;
4818
4819 Expr *ToRHS = Importer.Import(E->getRHS());
4820 if (!ToRHS)
4821 return nullptr;
4822
4823 Expr *ToCond = Importer.Import(E->getCond());
4824 if (!ToCond)
4825 return nullptr;
4826
4827 return new (Importer.getToContext()) ConditionalOperator(
4828 ToCond, Importer.Import(E->getQuestionLoc()),
4829 ToLHS, Importer.Import(E->getColonLoc()),
4830 ToRHS, T, E->getValueKind(), E->getObjectKind());
4831}
4832
4833Expr *ASTNodeImporter::VisitBinaryConditionalOperator(
4834 BinaryConditionalOperator *E) {
4835 QualType T = Importer.Import(E->getType());
4836 if (T.isNull())
4837 return nullptr;
4838
4839 Expr *Common = Importer.Import(E->getCommon());
4840 if (!Common)
4841 return nullptr;
4842
4843 Expr *Cond = Importer.Import(E->getCond());
4844 if (!Cond)
4845 return nullptr;
4846
4847 OpaqueValueExpr *OpaqueValue = cast_or_null<OpaqueValueExpr>(
4848 Importer.Import(E->getOpaqueValue()));
4849 if (!OpaqueValue)
4850 return nullptr;
4851
4852 Expr *TrueExpr = Importer.Import(E->getTrueExpr());
4853 if (!TrueExpr)
4854 return nullptr;
4855
4856 Expr *FalseExpr = Importer.Import(E->getFalseExpr());
4857 if (!FalseExpr)
4858 return nullptr;
4859
4860 return new (Importer.getToContext()) BinaryConditionalOperator(
4861 Common, OpaqueValue, Cond, TrueExpr, FalseExpr,
4862 Importer.Import(E->getQuestionLoc()), Importer.Import(E->getColonLoc()),
4863 T, E->getValueKind(), E->getObjectKind());
4864}
4865
4866Expr *ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
4867 QualType T = Importer.Import(E->getType());
4868 if (T.isNull())
4869 return nullptr;
4870
4871 TypeSourceInfo *ToQueried = Importer.Import(E->getQueriedTypeSourceInfo());
4872 if (!ToQueried)
4873 return nullptr;
4874
4875 Expr *Dim = Importer.Import(E->getDimensionExpression());
4876 if (!Dim && E->getDimensionExpression())
4877 return nullptr;
4878
4879 return new (Importer.getToContext()) ArrayTypeTraitExpr(
4880 Importer.Import(E->getLocStart()), E->getTrait(), ToQueried,
4881 E->getValue(), Dim, Importer.Import(E->getLocEnd()), T);
4882}
4883
4884Expr *ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
4885 QualType T = Importer.Import(E->getType());
4886 if (T.isNull())
4887 return nullptr;
4888
4889 Expr *ToQueried = Importer.Import(E->getQueriedExpression());
4890 if (!ToQueried)
4891 return nullptr;
4892
4893 return new (Importer.getToContext()) ExpressionTraitExpr(
4894 Importer.Import(E->getLocStart()), E->getTrait(), ToQueried,
4895 E->getValue(), Importer.Import(E->getLocEnd()), T);
4896}
4897
4898Expr *ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
4899 QualType T = Importer.Import(E->getType());
4900 if (T.isNull())
4901 return nullptr;
4902
4903 Expr *SourceExpr = Importer.Import(E->getSourceExpr());
4904 if (!SourceExpr && E->getSourceExpr())
4905 return nullptr;
4906
4907 return new (Importer.getToContext()) OpaqueValueExpr(
4908 Importer.Import(E->getLocation()), T, E->getValueKind(),
4909 E->getObjectKind(), SourceExpr);
4910}
4911
4912Expr *ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
4913 QualType T = Importer.Import(E->getType());
4914 if (T.isNull())
4915 return nullptr;
4916
4917 Expr *ToLHS = Importer.Import(E->getLHS());
4918 if (!ToLHS)
4919 return nullptr;
4920
4921 Expr *ToRHS = Importer.Import(E->getRHS());
4922 if (!ToRHS)
4923 return nullptr;
4924
4925 return new (Importer.getToContext()) ArraySubscriptExpr(
4926 ToLHS, ToRHS, T, E->getValueKind(), E->getObjectKind(),
4927 Importer.Import(E->getRBracketLoc()));
4928}
4929
4930Expr *ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
4931 QualType T = Importer.Import(E->getType());
4932 if (T.isNull())
4933 return nullptr;
4934
4935 QualType CompLHSType = Importer.Import(E->getComputationLHSType());
4936 if (CompLHSType.isNull())
4937 return nullptr;
4938
4939 QualType CompResultType = Importer.Import(E->getComputationResultType());
4940 if (CompResultType.isNull())
4941 return nullptr;
4942
4943 Expr *LHS = Importer.Import(E->getLHS());
4944 if (!LHS)
4945 return nullptr;
4946
4947 Expr *RHS = Importer.Import(E->getRHS());
4948 if (!RHS)
4949 return nullptr;
4950
4951 return new (Importer.getToContext())
4952 CompoundAssignOperator(LHS, RHS, E->getOpcode(),
4953 T, E->getValueKind(),
4954 E->getObjectKind(),
4955 CompLHSType, CompResultType,
4956 Importer.Import(E->getOperatorLoc()),
4957 E->getFPFeatures());
4958}
4959
4960bool ASTNodeImporter::ImportCastPath(CastExpr *CE, CXXCastPath &Path) {
4961 for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
4962 if (CXXBaseSpecifier *Spec = Importer.Import(*I))
4963 Path.push_back(Spec);
4964 else
4965 return true;
4966 }
4967 return false;
4968}
4969
4970Expr *ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
4971 QualType T = Importer.Import(E->getType());
4972 if (T.isNull())
4973 return nullptr;
4974
4975 Expr *SubExpr = Importer.Import(E->getSubExpr());
4976 if (!SubExpr)
4977 return nullptr;
4978
4979 CXXCastPath BasePath;
4980 if (ImportCastPath(E, BasePath))
4981 return nullptr;
4982
4983 return ImplicitCastExpr::Create(Importer.getToContext(), T, E->getCastKind(),
4984 SubExpr, &BasePath, E->getValueKind());
4985}
4986
4987Expr *ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
4988 QualType T = Importer.Import(E->getType());
4989 if (T.isNull())
4990 return nullptr;
4991
4992 Expr *SubExpr = Importer.Import(E->getSubExpr());
4993 if (!SubExpr)
4994 return nullptr;
4995
4996 TypeSourceInfo *TInfo = Importer.Import(E->getTypeInfoAsWritten());
4997 if (!TInfo && E->getTypeInfoAsWritten())
4998 return nullptr;
4999
5000 CXXCastPath BasePath;
5001 if (ImportCastPath(E, BasePath))
5002 return nullptr;
5003
5004 switch (E->getStmtClass()) {
5005 case Stmt::CStyleCastExprClass: {
5006 CStyleCastExpr *CCE = cast<CStyleCastExpr>(E);
5007 return CStyleCastExpr::Create(Importer.getToContext(), T,
5008 E->getValueKind(), E->getCastKind(),
5009 SubExpr, &BasePath, TInfo,
5010 Importer.Import(CCE->getLParenLoc()),
5011 Importer.Import(CCE->getRParenLoc()));
5012 }
5013
5014 case Stmt::CXXFunctionalCastExprClass: {
5015 CXXFunctionalCastExpr *FCE = cast<CXXFunctionalCastExpr>(E);
5016 return CXXFunctionalCastExpr::Create(Importer.getToContext(), T,
5017 E->getValueKind(), TInfo,
5018 E->getCastKind(), SubExpr, &BasePath,
5019 Importer.Import(FCE->getLParenLoc()),
5020 Importer.Import(FCE->getRParenLoc()));
5021 }
5022
5023 case Stmt::ObjCBridgedCastExprClass: {
5024 ObjCBridgedCastExpr *OCE = cast<ObjCBridgedCastExpr>(E);
5025 return new (Importer.getToContext()) ObjCBridgedCastExpr(
5026 Importer.Import(OCE->getLParenLoc()), OCE->getBridgeKind(),
5027 E->getCastKind(), Importer.Import(OCE->getBridgeKeywordLoc()),
5028 TInfo, SubExpr);
5029 }
5030 default:
5031 break; // just fall through
5032 }
5033
5034 CXXNamedCastExpr *Named = cast<CXXNamedCastExpr>(E);
5035 SourceLocation ExprLoc = Importer.Import(Named->getOperatorLoc()),
5036 RParenLoc = Importer.Import(Named->getRParenLoc());
5037 SourceRange Brackets = Importer.Import(Named->getAngleBrackets());
5038
5039 switch (E->getStmtClass()) {
5040 case Stmt::CXXStaticCastExprClass:
5041 return CXXStaticCastExpr::Create(Importer.getToContext(), T,
5042 E->getValueKind(), E->getCastKind(),
5043 SubExpr, &BasePath, TInfo,
5044 ExprLoc, RParenLoc, Brackets);
5045
5046 case Stmt::CXXDynamicCastExprClass:
5047 return CXXDynamicCastExpr::Create(Importer.getToContext(), T,
5048 E->getValueKind(), E->getCastKind(),
5049 SubExpr, &BasePath, TInfo,
5050 ExprLoc, RParenLoc, Brackets);
5051
5052 case Stmt::CXXReinterpretCastExprClass:
5053 return CXXReinterpretCastExpr::Create(Importer.getToContext(), T,
5054 E->getValueKind(), E->getCastKind(),
5055 SubExpr, &BasePath, TInfo,
5056 ExprLoc, RParenLoc, Brackets);
5057
5058 case Stmt::CXXConstCastExprClass:
5059 return CXXConstCastExpr::Create(Importer.getToContext(), T,
5060 E->getValueKind(), SubExpr, TInfo, ExprLoc,
5061 RParenLoc, Brackets);
5062 default:
5063 llvm_unreachable("Cast expression of unsupported type!")::llvm::llvm_unreachable_internal("Cast expression of unsupported type!"
, "/build/llvm-toolchain-snapshot-6.0~svn318693/tools/clang/lib/AST/ASTImporter.cpp"
, 5063)
;
5064 return nullptr;
5065 }
5066}
5067
5068Expr *ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *OE) {
5069 QualType T = Importer.Import(OE->getType());
5070 if (T.isNull())
5071 return nullptr;
5072
5073 SmallVector<OffsetOfNode, 4> Nodes;
5074 for (int I = 0, E = OE->getNumComponents(); I < E; ++I) {
5075 const OffsetOfNode &Node = OE->getComponent(I);
5076
5077 switch (Node.getKind()) {
5078 case OffsetOfNode::Array:
5079 Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()),
5080 Node.getArrayExprIndex(),
5081 Importer.Import(Node.getLocEnd())));
5082 break;
5083
5084 case OffsetOfNode::Base: {
5085 CXXBaseSpecifier *BS = Importer.Import(Node.getBase());
5086 if (!BS && Node.getBase())
5087 return nullptr;
5088 Nodes.push_back(OffsetOfNode(BS));
5089 break;
5090 }
5091 case OffsetOfNode::Field: {
5092 FieldDecl *FD = cast_or_null<FieldDecl>(Importer.Import(Node.getField()));
5093 if (!FD)
5094 return nullptr;
5095 Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), FD,
5096 Importer.Import(Node.getLocEnd())));
5097 break;
5098 }
5099 case OffsetOfNode::Identifier: {
5100 IdentifierInfo *ToII = Importer.Import(Node.getFieldName());
5101 if (!ToII)
5102 return nullptr;
5103 Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), ToII,
5104 Importer.Import(Node.getLocEnd())));
5105 break;
5106 }
5107 }
5108 }
5109
5110 SmallVector<Expr *, 4> Exprs(OE->getNumExpressions());
5111 for (int I = 0, E = OE->getNumExpressions(); I < E; ++I) {
5112 Expr *ToIndexExpr = Importer.Import(OE->getIndexExpr(I));
5113 if (!ToIndexExpr)
5114 return nullptr;
5115 Exprs[I] = ToIndexExpr;
5116 }
5117
5118 TypeSourceInfo *TInfo = Importer.Import(OE->getTypeSourceInfo());
5119 if (!TInfo && OE->getTypeSourceInfo())
5120 return nullptr;
5121
5122 return OffsetOfExpr::Create(Importer.getToContext(), T,
5123 Importer.Import(OE->getOperatorLoc()),
5124 TInfo, Nodes, Exprs,
5125 Importer.Import(OE->getRParenLoc()));
5126}
5127
5128Expr *ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
5129 QualType T = Importer.Import(E->getType());
5130 if (T.isNull())
5131 return nullptr;
5132
5133 Expr *Operand = Importer.Import(E->getOperand());
5134 if (!Operand)
5135 return nullptr;
5136
5137 CanThrowResult CanThrow;
5138 if (E->isValueDependent())
5139 CanThrow = CT_Dependent;
5140 else
5141 CanThrow = E->getValue() ? CT_Can : CT_Cannot;
5142
5143 return new (Importer.getToContext()) CXXNoexceptExpr(
5144 T, Operand, CanThrow,
5145 Importer.Import(E->getLocStart()), Importer.Import(E->getLocEnd()));
5146}
5147
5148Expr *ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) {
5149 QualType T = Importer.Import(E->getType());
5150 if (T.isNull())
5151 return nullptr;
5152
5153 Expr *SubExpr = Importer.Import(E->getSubExpr());
5154 if (!SubExpr && E->getSubExpr())
5155 return nullptr;
5156
5157 return new (Importer.getToContext()) CXXThrowExpr(
5158 SubExpr, T, Importer.Import(E->getThrowLoc()),
5159 E->isThrownVariableInScope());
5160}
5161
5162Expr *ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
5163 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
5164 Importer.Import(E->getParam()));
5165 if (!Param)
5166 return nullptr;
5167
5168 return CXXDefaultArgExpr::Create(
5169 Importer.getToContext(), Importer.Import(E->getUsedLocation()), Param);
5170}
5171
5172Expr *ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
5173 QualType T = Importer.Import(E->getType());
5174 if (T.isNull())
5175 return nullptr;
5176
5177 TypeSourceInfo *TypeInfo = Importer.Import(E->getTypeSourceInfo());
5178 if (!TypeInfo)
5179 return nullptr;
5180
5181 return new (Importer.getToContext()) CXXScalarValueInitExpr(
5182 T, TypeInfo, Importer.Import(E->getRParenLoc()));
5183}
5184
5185Expr *ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
5186 Expr *SubExpr = Importer.Import(E->getSubExpr());
5187 if (!SubExpr)
5188 return nullptr;
5189
5190 auto *Dtor = cast_or_null<CXXDestructorDecl>(
5191 Importer.Import(const_cast<CXXDestructorDecl *>(
5192 E->getTemporary()->getDestructor())));
5193 if (!Dtor)
5194 return nullptr;
5195
5196 ASTContext &ToCtx = Importer.getToContext();
5197 CXXTemporary *Temp = CXXTemporary::Create(ToCtx, Dtor);
5198 return CXXBindTemporaryExpr::Create(ToCtx, Temp, SubExpr);
5199}
5200
5201Expr *ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE) {
5202 QualType T = Importer.Import(CE->getType());
5203 if (T.isNull())
5204 return nullptr;
5205
5206 SmallVector<Expr *, 8> Args(CE->getNumArgs());
5207 if (ImportContainerChecked(CE->arguments(), Args))
5208 return nullptr;
5209
5210 auto *Ctor = cast_or_null<CXXConstructorDecl>(
5211 Importer.Import(CE->getConstructor()));
5212 if (!Ctor)
5213 return nullptr;
5214
5215 return CXXTemporaryObjectExpr::Create(
5216 Importer.getToContext(), T,
5217 Importer.Import(CE->getLocStart()),
5218 Ctor,
5219 CE->isElidable(),
5220 Args,
5221 CE->hadMultipleCandidates(),
5222 CE->isListInitialization(),
5223 CE->isStdInitListInitialization(),
5224 CE->requiresZeroInitialization(),
5225 CE->getConstructionKind(),
5226 Importer.Import(CE->getParenOrBraceRange()));
5227}
5228
5229Expr *
5230ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
5231 QualType T = Importer.Import(E->getType());
5232 if (T.isNull())
5233 return nullptr;
5234
5235 Expr *TempE = Importer.Import(E->GetTemporaryExpr());
5236 if (!TempE)
5237 return nullptr;
5238
5239 ValueDecl *ExtendedBy = cast_or_null<ValueDecl>(
5240 Importer.Import(const_cast<ValueDecl *>(E->getExtendingDecl())));
5241 if (!ExtendedBy && E->getExtendingDecl())
5242 return nullptr;
5243
5244 auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
5245 T, TempE, E->isBoundToLvalueReference());
5246
5247 // FIXME: Should ManglingNumber get numbers associated with 'to' context?
5248 ToMTE->setExtendingDecl(ExtendedBy, E->getManglingNumber());
5249 return ToMTE;
5250}
5251
5252Expr *ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) {
5253 QualType T = Importer.Import(E->getType());
5254 if (T.isNull())
5255 return nullptr;
5256
5257 Expr *Pattern = Importer.Import(E->getPattern());
5258 if (!Pattern)
5259 return nullptr;
5260
5261 return new (Importer.getToContext()) PackExpansionExpr(
5262 T, Pattern, Importer.Import(E->getEllipsisLoc()),
5263 E->getNumExpansions());
5264}
5265
5266Expr *ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *CE) {
5267 QualType T = Importer.Import(CE->getType());
5268 if (T.isNull())
5269 return nullptr;
5270
5271 SmallVector<Expr *, 4> PlacementArgs(CE->getNumPlacementArgs());
5272 if (ImportContainerChecked(CE->placement_arguments(), PlacementArgs))
5273 return nullptr;
5274
5275 FunctionDecl *OperatorNewDecl = cast_or_null<FunctionDecl>(
5276 Importer.Import(CE->getOperatorNew()));
5277 if (!OperatorNewDecl && CE->getOperatorNew())
5278 return nullptr;
5279
5280 FunctionDecl *OperatorDeleteDecl = cast_or_null<FunctionDecl>(
5281 Importer.Import(CE->getOperatorDelete()));
5282 if (!OperatorDeleteDecl && CE->getOperatorDelete())
5283 return nullptr;
5284
5285 Expr *ToInit = Importer.Import(CE->getInitializer());
5286 if (!ToInit && CE->getInitializer())
5287 return nullptr;
5288
5289 TypeSourceInfo *TInfo = Importer.Import(CE->getAllocatedTypeSourceInfo());
5290 if (!TInfo)
5291 return nullptr;
5292
5293 Expr *ToArrSize = Importer.Import(CE->getArraySize());
5294 if (!ToArrSize && CE->getArraySize())
5295 return nullptr;
5296
5297 return new (Importer.getToContext()) CXXNewExpr(
5298 Importer.getToContext(),
5299 CE->isGlobalNew(),
5300 OperatorNewDecl, OperatorDeleteDecl,
5301 CE->passAlignment(),
5302 CE->doesUsualArrayDeleteWantSize(),
5303 PlacementArgs,
5304 Importer.Import(CE->getTypeIdParens()),
5305 ToArrSize, CE->getInitializationStyle(), ToInit, T, TInfo,
5306 Importer.Import(CE->getSourceRange()),
5307 Importer.Import(CE->getDirectInitRange()));
5308}
5309
5310Expr *ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
5311 QualType T = Importer.Import(E->getType());
5312 if (T.isNull())
5313 return nullptr;
5314
5315 FunctionDecl *OperatorDeleteDecl = cast_or_null<FunctionDecl>(
5316 Importer.Import(E->getOperatorDelete()));
5317 if (!OperatorDeleteDecl && E->getOperatorDelete())
5318 return nullptr;
5319
5320 Expr *ToArg = Importer.Import(E->getArgument());
5321 if (!ToArg && E->getArgument())
5322 return nullptr;
5323
5324 return new (Importer.getToContext()) CXXDeleteExpr(
5325 T, E->isGlobalDelete(),
5326 E->isArrayForm(),
5327 E->isArrayFormAsWritten(),
5328 E->doesUsualArrayDeleteWantSize(),
5329 OperatorDeleteDecl,
5330 ToArg,
5331 Importer.Import(E->getLocStart()));
5332}
5333
5334Expr *ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) {
5335 QualType T = Importer.Import(E->getType());
5336 if (T.isNull())
5337 return nullptr;
5338
5339 CXXConstructorDecl *ToCCD =
5340 dyn_cast_or_null<CXXConstructorDecl>(Importer.Import(E->getConstructor()));
5341 if (!ToCCD)
5342 return nullptr;
5343
5344 SmallVector<Expr *, 6> ToArgs(E->getNumArgs());
5345 if (ImportContainerChecked(E->arguments(), ToArgs))
5346 return nullptr;
5347
5348 return CXXConstructExpr::Create(Importer.getToContext(), T,
5349 Importer.Import(E->getLocation()),
5350 ToCCD, E->isElidable(),
5351 ToArgs, E->hadMultipleCandidates(),
5352 E->isListInitialization(),
5353 E->isStdInitListInitialization(),
5354 E->requiresZeroInitialization(),
5355 E->getConstructionKind(),
5356 Importer.Import(E->getParenOrBraceRange()));
5357}
5358
5359Expr *ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *EWC) {
5360 Expr *SubExpr = Importer.Import(EWC->getSubExpr());
5361 if (!SubExpr && EWC->getSubExpr())
5362 return nullptr;
5363
5364 SmallVector<ExprWithCleanups::CleanupObject, 8> Objs(EWC->getNumObjects());
5365 for (unsigned I = 0, E = EWC->getNumObjects(); I < E; I++)
5366 if (ExprWithCleanups::CleanupObject Obj =
5367 cast_or_null<BlockDecl>(Importer.Import(EWC->getObject(I))))
5368 Objs[I] = Obj;
5369 else
5370 return nullptr;
5371
5372 return ExprWithCleanups::Create(Importer.getToContext(),
5373 SubExpr, EWC->cleanupsHaveSideEffects(),
5374 Objs);
5375}
5376
5377Expr *ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
5378 QualType T = Importer.Import(E->getType());
5379 if (T.isNull())
5380 return nullptr;
5381
5382 Expr *ToFn = Importer.Import(E->getCallee());
5383 if (!ToFn)
5384 return nullptr;
5385
5386 SmallVector<Expr *, 4> ToArgs(E->getNumArgs());
5387 if (ImportContainerChecked(E->arguments(), ToArgs))
5388 return nullptr;
5389
5390 return new (Importer.getToContext()) CXXMemberCallExpr(
5391 Importer.getToContext(), ToFn, ToArgs, T, E->getValueKind(),
5392 Importer.Import(E->getRParenLoc()));
5393}
5394
5395Expr *ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) {
5396 QualType T = Importer.Import(E->getType());
5397 if (T.isNull())
5398 return nullptr;
5399
5400 return new (Importer.getToContext())
5401 CXXThisExpr(Importer.Import(E->getLocation()), T, E->isImplicit());
5402}
5403
5404Expr *ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
5405 QualType T = Importer.Import(E->getType());
5406 if (T.isNull())
5407 return nullptr;
5408
5409 return new (Importer.getToContext())
5410 CXXBoolLiteralExpr(E->getValue(), T, Importer.Import(E->getLocation()));
5411}
5412
5413
5414Expr *ASTNodeImporter::VisitMemberExpr(MemberExpr *E) {
5415 QualType T = Importer.Import(E->getType());
5416 if (T.isNull())
5417 return nullptr;
5418
5419 Expr *ToBase = Importer.Import(E->getBase());
5420 if (!ToBase && E->getBase())
5421 return nullptr;
5422
5423 ValueDecl *ToMember = dyn_cast<ValueDecl>(Importer.Import(E->getMemberDecl()));
5424 if (!ToMember && E->getMemberDecl())
5425 return nullptr;
5426
5427 DeclAccessPair ToFoundDecl = DeclAccessPair::make(
5428 dyn_cast<NamedDecl>(Importer.Import(E->getFoundDecl().getDecl())),
5429 E->getFoundDecl().getAccess());
5430
5431 DeclarationNameInfo ToMemberNameInfo(
5432 Importer.Import(E->getMemberNameInfo().getName()),
5433 Importer.Import(E->getMemberNameInfo().getLoc()));
5434
5435 if (E->hasExplicitTemplateArgs()) {
5436 return nullptr; // FIXME: handle template arguments
5437 }
5438
5439 return MemberExpr::Create(Importer.getToContext(), ToBase,
5440 E->isArrow(),
5441 Importer.Import(E->getOperatorLoc()),
5442 Importer.Import(E->getQualifierLoc()),
5443 Importer.Import(E->getTemplateKeywordLoc()),
5444 ToMember, ToFoundDecl, ToMemberNameInfo,
5445 nullptr, T, E->getValueKind(),
5446 E->getObjectKind());
5447}
5448
5449Expr *ASTNodeImporter::VisitCallExpr(CallExpr *E) {
5450 QualType T = Importer.Import(E->getType());
5451 if (T.isNull())
5452 return nullptr;
5453
5454 Expr *ToCallee = Importer.Import(E->getCallee());
5455 if (!ToCallee && E->getCallee())
5456 return nullptr;
5457
5458 unsigned NumArgs = E->getNumArgs();
5459
5460 llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
5461
5462 for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) {
5463 Expr *FromArg = E->getArg(ai);
5464 Expr *ToArg = Importer.Import(FromArg);
5465 if (!ToArg)
5466 return nullptr;
5467 ToArgs[ai] = ToArg;
5468 }
5469
5470 Expr **ToArgs_Copied = new (Importer.getToContext())
5471 Expr*[NumArgs];
5472
5473 for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai)
5474 ToArgs_Copied[ai] = ToArgs[ai];
5475
5476 return new (Importer.getToContext())
5477 CallExpr(Importer.getToContext(), ToCallee,
5478 llvm::makeArrayRef(ToArgs_Copied, NumArgs), T, E->getValueKind(),
5479 Importer.Import(E->getRParenLoc()));
5480}
5481
5482Expr *ASTNodeImporter::VisitInitListExpr(InitListExpr *ILE) {
5483 QualType T = Importer.Import(ILE->getType());
5484 if (T.isNull())
5485 return nullptr;
5486
5487 llvm::SmallVector<Expr *, 4> Exprs(ILE->getNumInits());
5488 if (ImportContainerChecked(ILE->inits(), Exprs))
5489 return nullptr;
5490
5491 ASTContext &ToCtx = Importer.getToContext();
5492 InitListExpr *To = new (ToCtx) InitListExpr(
5493 ToCtx, Importer.Import(ILE->getLBraceLoc()),
5494 Exprs, Importer.Import(ILE->getLBraceLoc()));
5495 To->setType(T);
5496
5497 if (ILE->hasArrayFiller()) {
5498 Expr *Filler = Importer.Import(ILE->getArrayFiller());
5499 if (!Filler)
5500 return nullptr;
5501 To->setArrayFiller(Filler);
5502 }
5503
5504 if (FieldDecl *FromFD = ILE->getInitializedFieldInUnion()) {
5505 FieldDecl *ToFD = cast_or_null<FieldDecl>(Importer.Import(FromFD));
5506 if (!ToFD)
5507 return nullptr;
5508 To->setInitializedFieldInUnion(ToFD);
5509 }
5510
5511 if (InitListExpr *SyntForm = ILE->getSyntacticForm()) {
5512 InitListExpr *ToSyntForm = cast_or_null<InitListExpr>(
5513 Importer.Import(SyntForm));
5514 if (!ToSyntForm)
5515 return nullptr;
5516 To->setSyntacticForm(ToSyntForm);
5517 }
5518
5519 To->sawArrayRangeDesignator(ILE->hadArrayRangeDesignator());
5520 To->setValueDependent(ILE->isValueDependent());
5521 To->setInstantiationDependent(ILE->isInstantiationDependent());
5522
5523 return To;
5524}
5525
5526Expr *ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
5527 QualType ToType = Importer.Import(E->getType());
5528 if (ToType.isNull())
5529 return nullptr;
5530
5531 Expr *ToCommon = Importer.Import(E->getCommonExpr());
5532 if (!ToCommon && E->getCommonExpr())
5533 return nullptr;
5534
5535 Expr *ToSubExpr = Importer.Import(E->getSubExpr());
5536 if (!ToSubExpr && E->getSubExpr())
5537 return nullptr;
5538
5539 return new (Importer.getToContext())
5540 ArrayInitLoopExpr(ToType, ToCommon, ToSubExpr);
5541}
5542
5543Expr *ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
5544 QualType ToType = Importer.Import(E->getType());
5545 if (ToType.isNull())
5546 return nullptr;
5547 return new (Importer.getToContext()) ArrayInitIndexExpr(ToType);
5548}
5549
5550Expr *ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) {
5551 FieldDecl *ToField = llvm::dyn_cast_or_null<FieldDecl>(
5552 Importer.Import(DIE->getField()));
5553 if (!ToField && DIE->getField())
5554 return nullptr;
5555
5556 return CXXDefaultInitExpr::Create(
5557 Importer.getToContext(), Importer.Import(DIE->getLocStart()), ToField);
5558}
5559
5560Expr *ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
5561 QualType ToType = Importer.Import(E->getType());
5562 if (ToType.isNull() && !E->getType().isNull())
5563 return nullptr;
5564 ExprValueKind VK = E->getValueKind();
5565 CastKind CK = E->getCastKind();
5566 Expr *ToOp = Importer.Import(E->getSubExpr());
5567 if (!ToOp && E->getSubExpr())
5568 return nullptr;
5569 CXXCastPath BasePath;
5570 if (ImportCastPath(E, BasePath))
5571 return nullptr;
5572 TypeSourceInfo *ToWritten = Importer.Import(E->getTypeInfoAsWritten());
5573 SourceLocation ToOperatorLoc = Importer.Import(E->getOperatorLoc());
5574 SourceLocation ToRParenLoc = Importer.Import(E->getRParenLoc());
5575 SourceRange ToAngleBrackets = Importer.Import(E->getAngleBrackets());
5576
5577 if (isa<CXXStaticCastExpr>(E)) {
5578 return CXXStaticCastExpr::Create(
5579 Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath,
5580 ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
5581 } else if (isa<CXXDynamicCastExpr>(E)) {
5582 return CXXDynamicCastExpr::Create(
5583 Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath,
5584 ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
5585 } else if (isa<CXXReinterpretCastExpr>(E)) {
5586 return CXXReinterpretCastExpr::Create(
5587 Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath,
5588 ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
5589 } else {
5590 return nullptr;
5591 }
5592}
5593
5594
5595Expr *ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr(
5596 SubstNonTypeTemplateParmExpr *E) {
5597 QualType T = Importer.Import(E->getType());
5598 if (T.isNull())
5599 return nullptr;
5600
5601 NonTypeTemplateParmDecl *Param = cast_or_null<NonTypeTemplateParmDecl>(
5602 Importer.Import(E->getParameter()));
5603 if (!Param)
5604 return nullptr;
5605
5606 Expr *Replacement = Importer.Import(E->getReplacement());
5607 if (!Replacement)
5608 return nullptr;
5609
5610 return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
5611 T, E->getValueKind(), Importer.Import(E->getExprLoc()), Param,
5612 Replacement);
5613}
5614
5615void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
5616 CXXMethodDecl *FromMethod) {
5617 for (auto *FromOverriddenMethod : FromMethod->overridden_methods())
5618 ToMethod->addOverriddenMethod(
5619 cast<CXXMethodDecl>(Importer.Import(const_cast<CXXMethodDecl*>(
5620 FromOverriddenMethod))));
5621}
5622
5623ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager,
5624 ASTContext &FromContext, FileManager &FromFileManager,
5625 bool MinimalImport)
5626 : ToContext(ToContext), FromContext(FromContext),
5627 ToFileManager(ToFileManager), FromFileManager(FromFileManager),
5628 Minimal(MinimalImport), LastDiagFromFrom(false)
5629{
5630 ImportedDecls[FromContext.getTranslationUnitDecl()]
5631 = ToContext.getTranslationUnitDecl();
5632}
5633
5634ASTImporter::~ASTImporter() { }
5635
5636QualType ASTImporter::Import(QualType FromT) {
5637 if (FromT.isNull())
5638 return QualType();
5639
5640 const Type *fromTy = FromT.getTypePtr();
5641
5642 // Check whether we've already imported this type.
5643 llvm::DenseMap<const Type *, const Type *>::iterator Pos
5644 = ImportedTypes.find(fromTy);
5645 if (Pos != ImportedTypes.end())
5646 return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers());
5647
5648 // Import the type
5649 ASTNodeImporter Importer(*this);
5650 QualType ToT = Importer.Visit(fromTy);
5651 if (ToT.isNull())
5652 return ToT;
5653
5654 // Record the imported type.
5655 ImportedTypes[fromTy] = ToT.getTypePtr();
5656
5657 return ToContext.getQualifiedType(ToT, FromT.getLocalQualifiers());
5658}
5659
5660TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) {
5661 if (!FromTSI)
5662 return FromTSI;
5663
5664 // FIXME: For now we just create a "trivial" type source info based
5665 // on the type and a single location. Implement a real version of this.
5666 QualType T = Import(FromTSI->getType());
5667 if (T.isNull())
5668 return nullptr;
5669
5670 return ToContext.getTrivialTypeSourceInfo(T,
5671 Import(FromTSI->getTypeLoc().getLocStart()));
5672}
5673
5674Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) {
5675 llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD);
5676 if (Pos != ImportedDecls.end()) {
5677 Decl *ToD = Pos->second;
5678 ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD);
5679 return ToD;
5680 } else {
5681 return nullptr;
5682 }
5683}
5684
5685Decl *ASTImporter::Import(Decl *FromD) {
5686 if (!FromD)
11
Assuming 'FromD' is non-null
12
Taking false branch
5687 return nullptr;
5688
5689 ASTNodeImporter Importer(*this);
5690
5691 // Check whether we've already imported this declaration.
5692 llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD);
5693 if (Pos != ImportedDecls.end()) {
13
Assuming the condition is false
14
Taking false branch
5694 Decl *ToD = Pos->second;
5695 Importer.ImportDefinitionIfNeeded(FromD, ToD);
5696 return ToD;
5697 }
5698
5699 // Import the type
5700 Decl *ToD = Importer.Visit(FromD);
15
Calling 'Base::Visit'
5701 if (!ToD)
5702 return nullptr;
5703
5704 // Record the imported declaration.
5705 ImportedDecls[FromD] = ToD;
5706
5707 if (TagDecl *FromTag = dyn_cast<TagDecl>(FromD)) {
5708 // Keep track of anonymous tags that have an associated typedef.
5709 if (FromTag->getTypedefNameForAnonDecl())
5710 AnonTagsWithPendingTypedefs.push_back(FromTag);
5711 } else if (TypedefNameDecl *FromTypedef = dyn_cast<TypedefNameDecl>(FromD)) {
5712 // When we've finished transforming a typedef, see whether it was the
5713 // typedef for an anonymous tag.
5714 for (SmallVectorImpl<TagDecl *>::iterator
5715 FromTag = AnonTagsWithPendingTypedefs.begin(),
5716 FromTagEnd = AnonTagsWithPendingTypedefs.end();
5717 FromTag != FromTagEnd; ++FromTag) {
5718 if ((*FromTag)->getTypedefNameForAnonDecl() == FromTypedef) {
5719 if (TagDecl *ToTag = cast_or_null<TagDecl>(Import(*FromTag))) {
5720 // We found the typedef for an anonymous tag; link them.
5721 ToTag->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(ToD));
5722 AnonTagsWithPendingTypedefs.erase(FromTag);
5723 break;
5724 }
5725 }
5726 }
5727 }
5728
5729 return ToD;
5730}
5731
5732DeclContext *ASTImporter::ImportContext(DeclContext *FromDC) {
5733 if (!FromDC)
5734 return FromDC;
5735
5736 DeclContext *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC)));
5737 if (!ToDC)
5738 return nullptr;
5739
5740 // When we're using a record/enum/Objective-C class/protocol as a context, we
5741 // need it to have a definition.
5742 if (RecordDecl *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
5743 RecordDecl *FromRecord = cast<RecordDecl>(FromDC);
5744 if (ToRecord->isCompleteDefinition()) {
5745 // Do nothing.
5746 } else if (FromRecord->isCompleteDefinition()) {
5747 ASTNodeImporter(*this).ImportDefinition(FromRecord, ToRecord,
5748 ASTNodeImporter::IDK_Basic);
5749 } else {
5750 CompleteDecl(ToRecord);
5751 }
5752 } else if (EnumDecl *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
5753 EnumDecl *FromEnum = cast<EnumDecl>(FromDC);
5754 if (ToEnum->isCompleteDefinition()) {
5755 // Do nothing.
5756 } else if (FromEnum->isCompleteDefinition()) {
5757 ASTNodeImporter(*this).ImportDefinition(FromEnum, ToEnum,
5758 ASTNodeImporter::IDK_Basic);
5759 } else {
5760 CompleteDecl(ToEnum);
5761 }
5762 } else if (ObjCInterfaceDecl *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
5763 ObjCInterfaceDecl *FromClass = cast<ObjCInterfaceDecl>(FromDC);
5764 if (ToClass->getDefinition()) {
5765 // Do nothing.
5766 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
5767 ASTNodeImporter(*this).ImportDefinition(FromDef, ToClass,
5768 ASTNodeImporter::IDK_Basic);
5769 } else {
5770 CompleteDecl(ToClass);
5771 }
5772 } else if (ObjCProtocolDecl *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
5773 ObjCProtocolDecl *FromProto = cast<ObjCProtocolDecl>(FromDC);
5774 if (ToProto->getDefinition()) {
5775 // Do nothing.
5776 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
5777 ASTNodeImporter(*this).ImportDefinition(FromDef, ToProto,
5778 ASTNodeImporter::IDK_Basic);
5779 } else {
5780 CompleteDecl(ToProto);
5781 }
5782 }
5783
5784 return ToDC;
5785}
5786
5787Expr *ASTImporter::Import(Expr *FromE) {
5788 if (!FromE)
5789 return nullptr;
5790
5791 return cast_or_null<Expr>(Import(cast<Stmt>(FromE)));
5792}
5793
5794Stmt *ASTImporter::Import(Stmt *FromS) {
5795 if (!FromS)
5796 return nullptr;
5797
5798 // Check whether we've already imported this declaration.
5799 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
5800 if (Pos != ImportedStmts.end())
5801 return Pos->second;
5802
5803 // Import the type
5804 ASTNodeImporter Importer(*this);
5805 Stmt *ToS = Importer.Visit(FromS);
5806 if (!ToS)
5807 return nullptr;
5808
5809 // Record the imported declaration.
5810 ImportedStmts[FromS] = ToS;
5811 return ToS;
5812}
5813
5814NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) {
5815 if (!FromNNS)
5816 return nullptr;
5817
5818 NestedNameSpecifier *prefix = Import(FromNNS->getPrefix());
5819
5820 switch (FromNNS->getKind()) {
5821 case NestedNameSpecifier::Identifier:
5822 if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) {
5823 return NestedNameSpecifier::Create(ToContext, prefix, II);
5824 }
5825 return nullptr;
5826
5827 case NestedNameSpecifier::Namespace:
5828 if (NamespaceDecl *NS =
5829 cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) {
5830 return NestedNameSpecifier::Create(ToContext, prefix, NS);
5831 }
5832 return nullptr;
5833
5834 case NestedNameSpecifier::NamespaceAlias:
5835 if (NamespaceAliasDecl *NSAD =
5836 cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) {
5837 return NestedNameSpecifier::Create(ToContext, prefix, NSAD);
5838 }
5839 return nullptr;
5840
5841 case NestedNameSpecifier::Global:
5842 return NestedNameSpecifier::GlobalSpecifier(ToContext);
5843
5844 case NestedNameSpecifier::Super:
5845 if (CXXRecordDecl *RD =
5846 cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) {
5847 return NestedNameSpecifier::SuperSpecifier(ToContext, RD);
5848 }
5849 return nullptr;
5850
5851 case NestedNameSpecifier::TypeSpec:
5852 case NestedNameSpecifier::TypeSpecWithTemplate: {
5853 QualType T = Import(QualType(FromNNS->getAsType(), 0u));
5854 if (!T.isNull()) {
5855 bool bTemplate = FromNNS->getKind() ==
5856 NestedNameSpecifier::TypeSpecWithTemplate;
5857 return NestedNameSpecifier::Create(ToContext, prefix,
5858 bTemplate, T.getTypePtr());
5859 }
5860 }
5861 return nullptr;
5862 }
5863
5864 llvm_unreachable("Invalid nested name specifier kind")::llvm::llvm_unreachable_internal("Invalid nested name specifier kind"
, "/build/llvm-toolchain-snapshot-6.0~svn318693/tools/clang/lib/AST/ASTImporter.cpp"
, 5864)
;
5865}
5866
5867NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) {
5868 // Copied from NestedNameSpecifier mostly.
5869 SmallVector<NestedNameSpecifierLoc , 8> NestedNames;
5870 NestedNameSpecifierLoc NNS = FromNNS;
5871
5872 // Push each of the nested-name-specifiers's onto a stack for
5873 // serialization in reverse order.
5874 while (NNS) {
5875 NestedNames.push_back(NNS);
5876 NNS = NNS.getPrefix();
5877 }
5878
5879 NestedNameSpecifierLocBuilder Builder;
5880
5881 while (!NestedNames.empty()) {
5882 NNS = NestedNames.pop_back_val();
5883 NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier());
5884 if (!Spec)
5885 return NestedNameSpecifierLoc();
5886
5887 NestedNameSpecifier::SpecifierKind Kind = Spec->getKind();
5888 switch (Kind) {
5889 case NestedNameSpecifier::Identifier:
5890 Builder.Extend(getToContext(),
5891 Spec->getAsIdentifier(),
5892 Import(NNS.getLocalBeginLoc()),
5893 Import(NNS.getLocalEndLoc()));
5894 break;
5895
5896 case NestedNameSpecifier::Namespace:
5897 Builder.Extend(getToContext(),
5898 Spec->getAsNamespace(),
5899 Import(NNS.getLocalBeginLoc()),
5900 Import(NNS.getLocalEndLoc()));
5901 break;
5902
5903 case NestedNameSpecifier::NamespaceAlias:
5904 Builder.Extend(getToContext(),
5905 Spec->getAsNamespaceAlias(),
5906 Import(NNS.getLocalBeginLoc()),
5907 Import(NNS.getLocalEndLoc()));
5908 break;
5909
5910 case NestedNameSpecifier::TypeSpec:
5911 case NestedNameSpecifier::TypeSpecWithTemplate: {
5912 TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo(
5913 QualType(Spec->getAsType(), 0));
5914 Builder.Extend(getToContext(),
5915 Import(NNS.getLocalBeginLoc()),
5916 TSI->getTypeLoc(),
5917 Import(NNS.getLocalEndLoc()));
5918 break;
5919 }
5920
5921 case NestedNameSpecifier::Global:
5922 Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc()));
5923 break;
5924
5925 case NestedNameSpecifier::Super: {
5926 SourceRange ToRange = Import(NNS.getSourceRange());
5927 Builder.MakeSuper(getToContext(),
5928 Spec->getAsRecordDecl(),
5929 ToRange.getBegin(),
5930 ToRange.getEnd());
5931 }
5932 }
5933 }
5934
5935 return Builder.getWithLocInContext(getToContext());
5936}
5937
5938TemplateName ASTImporter::Import(TemplateName From) {
5939 switch (From.getKind()) {
5940 case TemplateName::Template:
5941 if (TemplateDecl *ToTemplate
5942 = cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl())))
5943 return TemplateName(ToTemplate);
5944
5945 return TemplateName();
5946
5947 case TemplateName::OverloadedTemplate: {
5948 OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate();
5949 UnresolvedSet<2> ToTemplates;
5950 for (OverloadedTemplateStorage::iterator I = FromStorage->begin(),
5951 E = FromStorage->end();
5952 I != E; ++I) {
5953 if (NamedDecl *To = cast_or_null<NamedDecl>(Import(*I)))
5954 ToTemplates.addDecl(To);
5955 else
5956 return TemplateName();
5957 }
5958 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
5959 ToTemplates.end());
5960 }
5961
5962 case TemplateName::QualifiedTemplate: {
5963 QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName();
5964 NestedNameSpecifier *Qualifier = Import(QTN->getQualifier());
5965 if (!Qualifier)
5966 return TemplateName();
5967
5968 if (TemplateDecl *ToTemplate
5969 = cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl())))
5970 return ToContext.getQualifiedTemplateName(Qualifier,
5971 QTN->hasTemplateKeyword(),
5972 ToTemplate);
5973
5974 return TemplateName();
5975 }
5976
5977 case TemplateName::DependentTemplate: {
5978 DependentTemplateName *DTN = From.getAsDependentTemplateName();
5979 NestedNameSpecifier *Qualifier = Import(DTN->getQualifier());
5980 if (!Qualifier)
5981 return TemplateName();
5982
5983 if (DTN->isIdentifier()) {
5984 return ToContext.getDependentTemplateName(Qualifier,
5985 Import(DTN->getIdentifier()));
5986 }
5987
5988 return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator());
5989 }
5990
5991 case TemplateName::SubstTemplateTemplateParm: {
5992 SubstTemplateTemplateParmStorage *subst
5993 = From.getAsSubstTemplateTemplateParm();
5994 TemplateTemplateParmDecl *param
5995 = cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter()));
5996 if (!param)
5997 return TemplateName();
5998
5999 TemplateName replacement = Import(subst->getReplacement());
6000 if (replacement.isNull()) return TemplateName();
6001
6002 return ToContext.getSubstTemplateTemplateParm(param, replacement);
6003 }
6004
6005 case TemplateName::SubstTemplateTemplateParmPack: {
6006 SubstTemplateTemplateParmPackStorage *SubstPack
6007 = From.getAsSubstTemplateTemplateParmPack();
6008 TemplateTemplateParmDecl *Param
6009 = cast_or_null<TemplateTemplateParmDecl>(
6010 Import(SubstPack->getParameterPack()));
6011 if (!Param)
6012 return TemplateName();
6013
6014 ASTNodeImporter Importer(*this);
6015 TemplateArgument ArgPack
6016 = Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
6017 if (ArgPack.isNull())
6018 return TemplateName();
6019
6020 return ToContext.getSubstTemplateTemplateParmPack(Param, ArgPack);
6021 }
6022 }
6023
6024 llvm_unreachable("Invalid template name kind")::llvm::llvm_unreachable_internal("Invalid template name kind"
, "/build/llvm-toolchain-snapshot-6.0~svn318693/tools/clang/lib/AST/ASTImporter.cpp"
, 6024)
;
6025}
6026
6027SourceLocation ASTImporter::Import(SourceLocation FromLoc) {
6028 if (FromLoc.isInvalid())
6029 return SourceLocation();
6030
6031 SourceManager &FromSM = FromContext.getSourceManager();
6032
6033 // For now, map everything down to its file location, so that we
6034 // don't have to import macro expansions.
6035 // FIXME: Import macro expansions!
6036 FromLoc = FromSM.getFileLoc(FromLoc);
6037 std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc);
6038 SourceManager &ToSM = ToContext.getSourceManager();
6039 FileID ToFileID = Import(Decomposed.first);
6040 if (ToFileID.isInvalid())
6041 return SourceLocation();
6042 SourceLocation ret = ToSM.getLocForStartOfFile(ToFileID)
6043 .getLocWithOffset(Decomposed.second);
6044 return ret;
6045}
6046
6047SourceRange ASTImporter::Import(SourceRange FromRange) {
6048 return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd()));
6049}
6050
6051FileID ASTImporter::Import(FileID FromID) {
6052 llvm::DenseMap<FileID, FileID>::iterator Pos
6053 = ImportedFileIDs.find(FromID);
6054 if (Pos != ImportedFileIDs.end())
6055 return Pos->second;
6056
6057 SourceManager &FromSM = FromContext.getSourceManager();
6058 SourceManager &ToSM = ToContext.getSourceManager();
6059 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
6060 assert(FromSLoc.isFile() && "Cannot handle macro expansions yet")(static_cast <bool> (FromSLoc.isFile() && "Cannot handle macro expansions yet"
) ? void (0) : __assert_fail ("FromSLoc.isFile() && \"Cannot handle macro expansions yet\""
, "/build/llvm-toolchain-snapshot-6.0~svn318693/tools/clang/lib/AST/ASTImporter.cpp"
, 6060, __extension__ __PRETTY_FUNCTION__))
;
6061
6062 // Include location of this file.
6063 SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
6064
6065 // Map the FileID for to the "to" source manager.
6066 FileID ToID;
6067 const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache();
6068 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
6069 // FIXME: We probably want to use getVirtualFile(), so we don't hit the
6070 // disk again
6071 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
6072 // than mmap the files several times.
6073 const FileEntry *Entry = ToFileManager.getFile(Cache->OrigEntry->getName());
6074 if (!Entry)
6075 return FileID();
6076 ToID = ToSM.createFileID(Entry, ToIncludeLoc,
6077 FromSLoc.getFile().getFileCharacteristic());
6078 } else {
6079 // FIXME: We want to re-use the existing MemoryBuffer!
6080 const llvm::MemoryBuffer *
6081 FromBuf = Cache->getBuffer(FromContext.getDiagnostics(), FromSM);
6082 std::unique_ptr<llvm::MemoryBuffer> ToBuf
6083 = llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
6084 FromBuf->getBufferIdentifier());
6085 ToID = ToSM.createFileID(std::move(ToBuf),
6086 FromSLoc.getFile().getFileCharacteristic());
6087 }
6088
6089
6090 ImportedFileIDs[FromID] = ToID;
6091 return ToID;
6092}
6093
6094CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) {
6095 Expr *ToExpr = Import(From->getInit());
6096 if (!ToExpr && From->getInit())
6097 return nullptr;
6098
6099 if (From->isBaseInitializer()) {
6100 TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo());
6101 if (!ToTInfo && From->getTypeSourceInfo())
6102 return nullptr;
6103
6104 return new (ToContext) CXXCtorInitializer(
6105 ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()),
6106 ToExpr, Import(From->getRParenLoc()),
6107 From->isPackExpansion() ? Import(From->getEllipsisLoc())
6108 : SourceLocation());
6109 } else if (From->isMemberInitializer()) {
6110 FieldDecl *ToField =
6111 llvm::cast_or_null<FieldDecl>(Import(From->getMember()));
6112 if (!ToField && From->getMember())
6113 return nullptr;
6114
6115 return new (ToContext) CXXCtorInitializer(
6116 ToContext, ToField, Import(From->getMemberLocation()),
6117 Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc()));
6118 } else if (From->isIndirectMemberInitializer()) {
6119 IndirectFieldDecl *ToIField = llvm::cast_or_null<IndirectFieldDecl>(
6120 Import(From->getIndirectMember()));
6121 if (!ToIField && From->getIndirectMember())
6122 return nullptr;
6123
6124 return new (ToContext) CXXCtorInitializer(
6125 ToContext, ToIField, Import(From->getMemberLocation()),
6126 Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc()));
6127 } else if (From->isDelegatingInitializer()) {
6128 TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo());
6129 if (!ToTInfo && From->getTypeSourceInfo())
6130 return nullptr;
6131
6132 return new (ToContext)
6133 CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()),
6134 ToExpr, Import(From->getRParenLoc()));
6135 } else {
6136 return nullptr;
6137 }
6138}
6139
6140
6141CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) {
6142 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
6143 if (Pos != ImportedCXXBaseSpecifiers.end())
6144 return Pos->second;
6145
6146 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
6147 Import(BaseSpec->getSourceRange()),
6148 BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
6149 BaseSpec->getAccessSpecifierAsWritten(),
6150 Import(BaseSpec->getTypeSourceInfo()),
6151 Import(BaseSpec->getEllipsisLoc()));
6152 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
6153 return Imported;
6154}
6155
6156void ASTImporter::ImportDefinition(Decl *From) {
6157 Decl *To = Import(From);
6158 if (!To)
1
Taking false branch
6159 return;
6160
6161 if (DeclContext *FromDC = cast<DeclContext>(From)) {
2
Assuming 'FromDC' is non-null
3
Taking true branch
6162 ASTNodeImporter Importer(*this);
6163
6164 if (RecordDecl *ToRecord = dyn_cast<RecordDecl>(To)) {
4
Taking false branch
6165 if (!ToRecord->getDefinition()) {
6166 Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord,
6167 ASTNodeImporter::IDK_Everything);
6168 return;
6169 }
6170 }
6171
6172 if (EnumDecl *ToEnum = dyn_cast<EnumDecl>(To)) {
5
Taking false branch
6173 if (!ToEnum->getDefinition()) {
6174 Importer.ImportDefinition(cast<EnumDecl>(FromDC), ToEnum,
6175 ASTNodeImporter::IDK_Everything);
6176 return;
6177 }
6178 }
6179
6180 if (ObjCInterfaceDecl *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
6
Taking false branch
6181 if (!ToIFace->getDefinition()) {
6182 Importer.ImportDefinition(cast<ObjCInterfaceDecl>(FromDC), ToIFace,
6183 ASTNodeImporter::IDK_Everything);
6184 return;
6185 }
6186 }
6187
6188 if (ObjCProtocolDecl *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
7
Taking false branch
6189 if (!ToProto->getDefinition()) {
6190 Importer.ImportDefinition(cast<ObjCProtocolDecl>(FromDC), ToProto,
6191 ASTNodeImporter::IDK_Everything);
6192 return;
6193 }
6194 }
6195
6196 Importer.ImportDeclContext(FromDC, true);
8
Calling 'ASTNodeImporter::ImportDeclContext'
6197 }
6198}
6199
6200DeclarationName ASTImporter::Import(DeclarationName FromName) {
6201 if (!FromName)
6202 return DeclarationName();
6203
6204 switch (FromName.getNameKind()) {
6205 case DeclarationName::Identifier:
6206 return Import(FromName.getAsIdentifierInfo());
6207
6208 case DeclarationName::ObjCZeroArgSelector:
6209 case DeclarationName::ObjCOneArgSelector:
6210 case DeclarationName::ObjCMultiArgSelector:
6211 return Import(FromName.getObjCSelector());
6212
6213 case DeclarationName::CXXConstructorName: {
6214 QualType T = Import(FromName.getCXXNameType());
6215 if (T.isNull())
6216 return DeclarationName();
6217
6218 return ToContext.DeclarationNames.getCXXConstructorName(
6219 ToContext.getCanonicalType(T));
6220 }
6221
6222 case DeclarationName::CXXDestructorName: {
6223 QualType T = Import(FromName.getCXXNameType());
6224 if (T.isNull())
6225 return DeclarationName();
6226
6227 return ToContext.DeclarationNames.getCXXDestructorName(
6228 ToContext.getCanonicalType(T));
6229 }
6230
6231 case DeclarationName::CXXDeductionGuideName: {
6232 TemplateDecl *Template = cast_or_null<TemplateDecl>(
6233 Import(FromName.getCXXDeductionGuideTemplate()));
6234 if (!Template)
6235 return DeclarationName();
6236 return ToContext.DeclarationNames.getCXXDeductionGuideName(Template);
6237 }
6238
6239 case DeclarationName::CXXConversionFunctionName: {
6240 QualType T = Import(FromName.getCXXNameType());
6241 if (T.isNull())
6242 return DeclarationName();
6243
6244 return ToContext.DeclarationNames.getCXXConversionFunctionName(
6245 ToContext.getCanonicalType(T));
6246 }
6247
6248 case DeclarationName::CXXOperatorName:
6249 return ToContext.DeclarationNames.getCXXOperatorName(
6250 FromName.getCXXOverloadedOperator());
6251
6252 case DeclarationName::CXXLiteralOperatorName:
6253 return ToContext.DeclarationNames.getCXXLiteralOperatorName(
6254 Import(FromName.getCXXLiteralIdentifier()));
6255
6256 case DeclarationName::CXXUsingDirective:
6257 // FIXME: STATICS!
6258 return DeclarationName::getUsingDirectiveName();
6259 }
6260
6261 llvm_unreachable("Invalid DeclarationName Kind!")::llvm::llvm_unreachable_internal("Invalid DeclarationName Kind!"
, "/build/llvm-toolchain-snapshot-6.0~svn318693/tools/clang/lib/AST/ASTImporter.cpp"
, 6261)
;
6262}
6263
6264IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) {
6265 if (!FromId)
6266 return nullptr;
6267
6268 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
6269
6270 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
6271 ToId->setBuiltinID(FromId->getBuiltinID());
6272
6273 return ToId;
6274}
6275
6276Selector ASTImporter::Import(Selector FromSel) {
6277 if (FromSel.isNull())
6278 return Selector();
6279
6280 SmallVector<IdentifierInfo *, 4> Idents;
6281 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
6282 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
6283 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
6284 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
6285}
6286
6287DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name,
6288 DeclContext *DC,
6289 unsigned IDNS,
6290 NamedDecl **Decls,
6291 unsigned NumDecls) {
6292 return Name;
6293}
6294
6295DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) {
6296 if (LastDiagFromFrom)
6297 ToContext.getDiagnostics().notePriorDiagnosticFrom(
6298 FromContext.getDiagnostics());
6299 LastDiagFromFrom = false;
6300 return ToContext.getDiagnostics().Report(Loc, DiagID);
6301}
6302
6303DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) {
6304 if (!LastDiagFromFrom)
6305 FromContext.getDiagnostics().notePriorDiagnosticFrom(
6306 ToContext.getDiagnostics());
6307 LastDiagFromFrom = true;
6308 return FromContext.getDiagnostics().Report(Loc, DiagID);
6309}
6310
6311void ASTImporter::CompleteDecl (Decl *D) {
6312 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
6313 if (!ID->getDefinition())
6314 ID->startDefinition();
6315 }
6316 else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) {
6317 if (!PD->getDefinition())
6318 PD->startDefinition();
6319 }
6320 else if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
6321 if (!TD->getDefinition() && !TD->isBeingDefined()) {
6322 TD->startDefinition();
6323 TD->setCompleteDefinition(true);
6324 }
6325 }
6326 else {
6327 assert (0 && "CompleteDecl called on a Decl that can't be completed")(static_cast <bool> (0 && "CompleteDecl called on a Decl that can't be completed"
) ? void (0) : __assert_fail ("0 && \"CompleteDecl called on a Decl that can't be completed\""
, "/build/llvm-toolchain-snapshot-6.0~svn318693/tools/clang/lib/AST/ASTImporter.cpp"
, 6327, __extension__ __PRETTY_FUNCTION__))
;
6328 }
6329}
6330
6331Decl *ASTImporter::Imported(Decl *From, Decl *To) {
6332 if (From->hasAttrs()) {
6333 for (Attr *FromAttr : From->getAttrs())
6334 To->addAttr(FromAttr->clone(To->getASTContext()));
6335 }
6336 if (From->isUsed()) {
6337 To->setIsUsed();
6338 }
6339 if (From->isImplicit()) {
6340 To->setImplicit();
6341 }
6342 ImportedDecls[From] = To;
6343 return To;
6344}
6345
6346bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To,
6347 bool Complain) {
6348 llvm::DenseMap<const Type *, const Type *>::iterator Pos
6349 = ImportedTypes.find(From.getTypePtr());
6350 if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To))
6351 return true;
6352
6353 StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls,
6354 false, Complain);
6355 return Ctx.IsStructurallyEquivalent(From, To);
6356}

/build/llvm-toolchain-snapshot-6.0~svn318693/tools/clang/include/clang/AST/DeclVisitor.h

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
26namespace clang {
27
28namespace declvisitor {
29
30template <typename T> struct make_ptr { using type = T *; };
31template <typename T> struct make_const_ptr { using type = const T *; };
32
33/// \brief A simple visitor class that helps create declaration visitors.
34template<template <typename> class Ptr, typename ImplClass, typename RetTy=void>
35class Base {
36public:
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()) {
16
Control jumps to 'case ObjCPropertyImpl:' at line 529
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-6.0~svn318693/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/// \brief A simple visitor class that helps create declaration visitors.
66///
67/// This class does not preserve constness of Decl pointers (see also
68/// ConstDeclVisitor).
69template<typename ImplClass, typename RetTy = void>
70class DeclVisitor
71 : public declvisitor::Base<declvisitor::make_ptr, ImplClass, RetTy> {};
72
73/// \brief A simple visitor class that helps create declaration visitors.
74///
75/// This class preserves constness of Decl pointers (see also DeclVisitor).
76template<typename ImplClass, typename RetTy = void>
77class ConstDeclVisitor
78 : public declvisitor::Base<declvisitor::make_const_ptr, ImplClass, RetTy> {};
79
80} // namespace clang
81
82#endif // LLVM_CLANG_AST_DECLVISITOR_H

/build/llvm-toolchain-snapshot-6.0~svn318693/build-llvm/tools/clang/include/clang/AST/DeclNodes.inc

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
23ACCESSSPEC(AccessSpec, Decl)
24#undef ACCESSSPEC
25
26#ifndef BLOCK
27# define BLOCK(Type, Base) DECL(Type, Base)
28#endif
29BLOCK(Block, Decl)
30#undef BLOCK
31
32#ifndef CAPTURED
33# define CAPTURED(Type, Base) DECL(Type, Base)
34#endif
35CAPTURED(Captured, Decl)
36#undef CAPTURED
37
38#ifndef CLASSSCOPEFUNCTIONSPECIALIZATION
39# define CLASSSCOPEFUNCTIONSPECIALIZATION(Type, Base) DECL(Type, Base)
40#endif
41CLASSSCOPEFUNCTIONSPECIALIZATION(ClassScopeFunctionSpecialization, Decl)
42#undef CLASSSCOPEFUNCTIONSPECIALIZATION
43
44#ifndef EMPTY
45# define EMPTY(Type, Base) DECL(Type, Base)
46#endif
47EMPTY(Empty, Decl)
48#undef EMPTY
49
50#ifndef EXPORT
51# define EXPORT(Type, Base) DECL(Type, Base)
52#endif
53EXPORT(Export, Decl)
54#undef EXPORT
55
56#ifndef EXTERNCCONTEXT
57# define EXTERNCCONTEXT(Type, Base) DECL(Type, Base)
58#endif
59EXTERNCCONTEXT(ExternCContext, Decl)
60#undef EXTERNCCONTEXT
61
62#ifndef FILESCOPEASM
63# define FILESCOPEASM(Type, Base) DECL(Type, Base)
64#endif
65FILESCOPEASM(FileScopeAsm, Decl)
66#undef FILESCOPEASM
67
68#ifndef FRIEND
69# define FRIEND(Type, Base) DECL(Type, Base)
70#endif
71FRIEND(Friend, Decl)
72#undef FRIEND
73
74#ifndef FRIENDTEMPLATE
75# define FRIENDTEMPLATE(Type, Base) DECL(Type, Base)
76#endif
77FRIENDTEMPLATE(FriendTemplate, Decl)
78#undef FRIENDTEMPLATE
79
80#ifndef IMPORT
81# define IMPORT(Type, Base) DECL(Type, Base)
82#endif
83IMPORT(Import, Decl)
84#undef IMPORT
85
86#ifndef LINKAGESPEC
87# define LINKAGESPEC(Type, Base) DECL(Type, Base)
88#endif
89LINKAGESPEC(LinkageSpec, Decl)
90#undef LINKAGESPEC
91
92#ifndef NAMED
93# define NAMED(Type, Base) DECL(Type, Base)
94#endif
95ABSTRACT_DECL(NAMED(Named, Decl))
96#ifndef LABEL
97# define LABEL(Type, Base) NAMED(Type, Base)
98#endif
99LABEL(Label, NamedDecl)
100#undef LABEL
101
102#ifndef NAMESPACE
103# define NAMESPACE(Type, Base) NAMED(Type, Base)
104#endif
105NAMESPACE(Namespace, NamedDecl)
106#undef NAMESPACE
107
108#ifndef NAMESPACEALIAS
109# define NAMESPACEALIAS(Type, Base) NAMED(Type, Base)
110#endif
111NAMESPACEALIAS(NamespaceAlias, NamedDecl)
112#undef NAMESPACEALIAS
113
114#ifndef OBJCCOMPATIBLEALIAS
115# define OBJCCOMPATIBLEALIAS(Type, Base) NAMED(Type, Base)
116#endif
117OBJCCOMPATIBLEALIAS(ObjCCompatibleAlias, NamedDecl)
118#undef OBJCCOMPATIBLEALIAS
119
120#ifndef OBJCCONTAINER
121# define OBJCCONTAINER(Type, Base) NAMED(Type, Base)
122#endif
123ABSTRACT_DECL(OBJCCONTAINER(ObjCContainer, NamedDecl))
124#ifndef OBJCCATEGORY
125# define OBJCCATEGORY(Type, Base) OBJCCONTAINER(Type, Base)
126#endif
127OBJCCATEGORY(ObjCCategory, ObjCContainerDecl)
128#undef OBJCCATEGORY
129
130#ifndef OBJCIMPL
131# define OBJCIMPL(Type, Base) OBJCCONTAINER(Type, Base)
132#endif
133ABSTRACT_DECL(OBJCIMPL(ObjCImpl, ObjCContainerDecl))
134#ifndef OBJCCATEGORYIMPL
135# define OBJCCATEGORYIMPL(Type, Base) OBJCIMPL(Type, Base)
136#endif
137OBJCCATEGORYIMPL(ObjCCategoryImpl, ObjCImplDecl)
138#undef OBJCCATEGORYIMPL
139
140#ifndef OBJCIMPLEMENTATION
141# define OBJCIMPLEMENTATION(Type, Base) OBJCIMPL(Type, Base)
142#endif
143OBJCIMPLEMENTATION(ObjCImplementation, ObjCImplDecl)
144#undef OBJCIMPLEMENTATION
145
146DECL_RANGE(ObjCImpl, ObjCCategoryImpl, ObjCImplementation)
147
148#undef OBJCIMPL
149
150#ifndef OBJCINTERFACE
151# define OBJCINTERFACE(Type, Base) OBJCCONTAINER(Type, Base)
152#endif
153OBJCINTERFACE(ObjCInterface, ObjCContainerDecl)
154#undef OBJCINTERFACE
155
156#ifndef OBJCPROTOCOL
157# define OBJCPROTOCOL(Type, Base) OBJCCONTAINER(Type, Base)
158#endif
159OBJCPROTOCOL(ObjCProtocol, ObjCContainerDecl)
160#undef OBJCPROTOCOL
161
162DECL_RANGE(ObjCContainer, ObjCCategory, ObjCProtocol)
163
164#undef OBJCCONTAINER
165
166#ifndef OBJCMETHOD
167# define OBJCMETHOD(Type, Base) NAMED(Type, Base)
168#endif
169OBJCMETHOD(ObjCMethod, NamedDecl)
170#undef OBJCMETHOD
171
172#ifndef OBJCPROPERTY
173# define OBJCPROPERTY(Type, Base) NAMED(Type, Base)
174#endif
175OBJCPROPERTY(ObjCProperty, NamedDecl)
176#undef OBJCPROPERTY
177
178#ifndef TEMPLATE
179# define TEMPLATE(Type, Base) NAMED(Type, Base)
180#endif
181ABSTRACT_DECL(TEMPLATE(Template, NamedDecl))
182#ifndef BUILTINTEMPLATE
183# define BUILTINTEMPLATE(Type, Base) TEMPLATE(Type, Base)
184#endif
185BUILTINTEMPLATE(BuiltinTemplate, TemplateDecl)
186#undef BUILTINTEMPLATE
187
188#ifndef REDECLARABLETEMPLATE
189# define REDECLARABLETEMPLATE(Type, Base) TEMPLATE(Type, Base)
190#endif
191ABSTRACT_DECL(REDECLARABLETEMPLATE(RedeclarableTemplate, TemplateDecl))
192#ifndef CLASSTEMPLATE
193# define CLASSTEMPLATE(Type, Base) REDECLARABLETEMPLATE(Type, Base)
194#endif
195CLASSTEMPLATE(ClassTemplate, RedeclarableTemplateDecl)
196#undef CLASSTEMPLATE
197
198#ifndef FUNCTIONTEMPLATE
199# define FUNCTIONTEMPLATE(Type, Base) REDECLARABLETEMPLATE(Type, Base)
200#endif
201FUNCTIONTEMPLATE(FunctionTemplate, RedeclarableTemplateDecl)
202#undef FUNCTIONTEMPLATE
203
204#ifndef TYPEALIASTEMPLATE
205# define TYPEALIASTEMPLATE(Type, Base) REDECLARABLETEMPLATE(Type, Base)
206#endif
207TYPEALIASTEMPLATE(TypeAliasTemplate, RedeclarableTemplateDecl)
208#undef TYPEALIASTEMPLATE
209
210#ifndef VARTEMPLATE
211# define VARTEMPLATE(Type, Base) REDECLARABLETEMPLATE(Type, Base)
212#endif
213VARTEMPLATE(VarTemplate, RedeclarableTemplateDecl)
214#undef VARTEMPLATE
215
216DECL_RANGE(RedeclarableTemplate, ClassTemplate, VarTemplate)
217
218#undef REDECLARABLETEMPLATE
219
220#ifndef TEMPLATETEMPLATEPARM
221# define TEMPLATETEMPLATEPARM(Type, Base) TEMPLATE(Type, Base)
222#endif
223TEMPLATETEMPLATEPARM(TemplateTemplateParm, TemplateDecl)
224#undef TEMPLATETEMPLATEPARM
225
226DECL_RANGE(Template, BuiltinTemplate, TemplateTemplateParm)
227
228#undef TEMPLATE
229
230#ifndef TYPE
231# define TYPE(Type, Base) NAMED(Type, Base)
232#endif
233ABSTRACT_DECL(TYPE(Type, NamedDecl))
234#ifndef TAG
235# define TAG(Type, Base) TYPE(Type, Base)
236#endif
237ABSTRACT_DECL(TAG(Tag, TypeDecl))
238#ifndef ENUM
239# define ENUM(Type, Base) TAG(Type, Base)
240#endif
241ENUM(Enum, TagDecl)
242#undef ENUM
243
244#ifndef RECORD
245# define RECORD(Type, Base) TAG(Type, Base)
246#endif
247RECORD(Record, TagDecl)
248#ifndef CXXRECORD
249# define CXXRECORD(Type, Base) RECORD(Type, Base)
250#endif
251CXXRECORD(CXXRecord, RecordDecl)
252#ifndef CLASSTEMPLATESPECIALIZATION
253# define CLASSTEMPLATESPECIALIZATION(Type, Base) CXXRECORD(Type, Base)
254#endif
255CLASSTEMPLATESPECIALIZATION(ClassTemplateSpecialization, CXXRecordDecl)
256#ifndef CLASSTEMPLATEPARTIALSPECIALIZATION
257# define CLASSTEMPLATEPARTIALSPECIALIZATION(Type, Base) CLASSTEMPLATESPECIALIZATION(Type, Base)
258#endif
259CLASSTEMPLATEPARTIALSPECIALIZATION(ClassTemplatePartialSpecialization, ClassTemplateSpecializationDecl)
260#undef CLASSTEMPLATEPARTIALSPECIALIZATION
261
262DECL_RANGE(ClassTemplateSpecialization, ClassTemplateSpecialization, ClassTemplatePartialSpecialization)
263
264#undef CLASSTEMPLATESPECIALIZATION
265
266DECL_RANGE(CXXRecord, CXXRecord, ClassTemplatePartialSpecialization)
267
268#undef CXXRECORD
269
270DECL_RANGE(Record, Record, ClassTemplatePartialSpecialization)
271
272#undef RECORD
273
274DECL_RANGE(Tag, Enum, ClassTemplatePartialSpecialization)
275
276#undef TAG
277
278#ifndef TEMPLATETYPEPARM
279# define TEMPLATETYPEPARM(Type, Base) TYPE(Type, Base)
280#endif
281TEMPLATETYPEPARM(TemplateTypeParm, TypeDecl)
282#undef TEMPLATETYPEPARM
283
284#ifndef TYPEDEFNAME
285# define TYPEDEFNAME(Type, Base) TYPE(Type, Base)
286#endif
287ABSTRACT_DECL(TYPEDEFNAME(TypedefName, TypeDecl))
288#ifndef OBJCTYPEPARAM
289# define OBJCTYPEPARAM(Type, Base) TYPEDEFNAME(Type, Base)
290#endif
291OBJCTYPEPARAM(ObjCTypeParam, TypedefNameDecl)
292#undef OBJCTYPEPARAM
293
294#ifndef TYPEALIAS
295# define TYPEALIAS(Type, Base) TYPEDEFNAME(Type, Base)
296#endif
297TYPEALIAS(TypeAlias, TypedefNameDecl)
298#undef TYPEALIAS
299
300#ifndef TYPEDEF
301# define TYPEDEF(Type, Base) TYPEDEFNAME(Type, Base)
302#endif
303TYPEDEF(Typedef, TypedefNameDecl)
304#undef TYPEDEF
305
306DECL_RANGE(TypedefName, ObjCTypeParam, Typedef)
307
308#undef TYPEDEFNAME
309
310#ifndef UNRESOLVEDUSINGTYPENAME
311# define UNRESOLVEDUSINGTYPENAME(Type, Base) TYPE(Type, Base)
312#endif
313UNRESOLVEDUSINGTYPENAME(UnresolvedUsingTypename, TypeDecl)
314#undef UNRESOLVEDUSINGTYPENAME
315
316DECL_RANGE(Type, Enum, UnresolvedUsingTypename)
317
318#undef TYPE
319
320#ifndef USING
321# define USING(Type, Base) NAMED(Type, Base)
322#endif
323USING(Using, NamedDecl)
324#undef USING
325
326#ifndef USINGDIRECTIVE
327# define USINGDIRECTIVE(Type, Base) NAMED(Type, Base)
328#endif
329USINGDIRECTIVE(UsingDirective, NamedDecl)
330#undef USINGDIRECTIVE
331
332#ifndef USINGPACK
333# define USINGPACK(Type, Base) NAMED(Type, Base)
334#endif
335USINGPACK(UsingPack, NamedDecl)
336#undef USINGPACK
337
338#ifndef USINGSHADOW
339# define USINGSHADOW(Type, Base) NAMED(Type, Base)
340#endif
341USINGSHADOW(UsingShadow, NamedDecl)
342#ifndef CONSTRUCTORUSINGSHADOW
343# define CONSTRUCTORUSINGSHADOW(Type, Base) USINGSHADOW(Type, Base)
344#endif
345CONSTRUCTORUSINGSHADOW(ConstructorUsingShadow, UsingShadowDecl)
346#undef CONSTRUCTORUSINGSHADOW
347
348DECL_RANGE(UsingShadow, UsingShadow, ConstructorUsingShadow)
349
350#undef USINGSHADOW
351
352#ifndef VALUE
353# define VALUE(Type, Base) NAMED(Type, Base)
354#endif
355ABSTRACT_DECL(VALUE(Value, NamedDecl))
356#ifndef BINDING
357# define BINDING(Type, Base) VALUE(Type, Base)
358#endif
359BINDING(Binding, ValueDecl)
360#undef BINDING
361
362#ifndef DECLARATOR
363# define DECLARATOR(Type, Base) VALUE(Type, Base)
364#endif
365ABSTRACT_DECL(DECLARATOR(Declarator, ValueDecl))
366#ifndef FIELD
367# define FIELD(Type, Base) DECLARATOR(Type, Base)
368#endif
369FIELD(Field, DeclaratorDecl)
370#ifndef OBJCATDEFSFIELD
371# define OBJCATDEFSFIELD(Type, Base) FIELD(Type, Base)
372#endif
373OBJCATDEFSFIELD(ObjCAtDefsField, FieldDecl)
374#undef OBJCATDEFSFIELD
375
376#ifndef OBJCIVAR
377# define OBJCIVAR(Type, Base) FIELD(Type, Base)
378#endif
379OBJCIVAR(ObjCIvar, FieldDecl)
380#undef OBJCIVAR
381
382DECL_RANGE(Field, Field, ObjCIvar)
383
384#undef FIELD
385
386#ifndef FUNCTION
387# define FUNCTION(Type, Base) DECLARATOR(Type, Base)
388#endif
389FUNCTION(Function, DeclaratorDecl)
390#ifndef CXXDEDUCTIONGUIDE
391# define CXXDEDUCTIONGUIDE(Type, Base) FUNCTION(Type, Base)
392#endif
393CXXDEDUCTIONGUIDE(CXXDeductionGuide, FunctionDecl)
394#undef CXXDEDUCTIONGUIDE
395
396#ifndef CXXMETHOD
397# define CXXMETHOD(Type, Base) FUNCTION(Type, Base)
398#endif
399CXXMETHOD(CXXMethod, FunctionDecl)
400#ifndef CXXCONSTRUCTOR
401# define CXXCONSTRUCTOR(Type, Base) CXXMETHOD(Type, Base)
402#endif
403CXXCONSTRUCTOR(CXXConstructor, CXXMethodDecl)
404#undef CXXCONSTRUCTOR
405
406#ifndef CXXCONVERSION
407# define CXXCONVERSION(Type, Base) CXXMETHOD(Type, Base)
408#endif
409CXXCONVERSION(CXXConversion, CXXMethodDecl)
410#undef CXXCONVERSION
411
412#ifndef CXXDESTRUCTOR
413# define CXXDESTRUCTOR(Type, Base) CXXMETHOD(Type, Base)
414#endif
415CXXDESTRUCTOR(CXXDestructor, CXXMethodDecl)
416#undef CXXDESTRUCTOR
417
418DECL_RANGE(CXXMethod, CXXMethod, CXXDestructor)
419
420#undef CXXMETHOD
421
422DECL_RANGE(Function, Function, CXXDestructor)
423
424#undef FUNCTION
425
426#ifndef MSPROPERTY
427# define MSPROPERTY(Type, Base) DECLARATOR(Type, Base)
428#endif
429MSPROPERTY(MSProperty, DeclaratorDecl)
430#undef MSPROPERTY
431
432#ifndef NONTYPETEMPLATEPARM
433# define NONTYPETEMPLATEPARM(Type, Base) DECLARATOR(Type, Base)
434#endif
435NONTYPETEMPLATEPARM(NonTypeTemplateParm, DeclaratorDecl)
436#undef NONTYPETEMPLATEPARM
437
438#ifndef VAR
439# define VAR(Type, Base) DECLARATOR(Type, Base)
440#endif
441VAR(Var, DeclaratorDecl)
442#ifndef DECOMPOSITION
443# define DECOMPOSITION(Type, Base) VAR(Type, Base)
444#endif
445DECOMPOSITION(Decomposition, VarDecl)
446#undef DECOMPOSITION
447
448#ifndef IMPLICITPARAM
449# define IMPLICITPARAM(Type, Base) VAR(Type, Base)
450#endif
451IMPLICITPARAM(ImplicitParam, VarDecl)
452#undef IMPLICITPARAM
453
454#ifndef OMPCAPTUREDEXPR
455# define OMPCAPTUREDEXPR(Type, Base) VAR(Type, Base)
456#endif
457OMPCAPTUREDEXPR(OMPCapturedExpr, VarDecl)
458#undef OMPCAPTUREDEXPR
459
460#ifndef PARMVAR
461# define PARMVAR(Type, Base) VAR(Type, Base)
462#endif
463PARMVAR(ParmVar, VarDecl)
464#undef PARMVAR
465
466#ifndef VARTEMPLATESPECIALIZATION
467# define VARTEMPLATESPECIALIZATION(Type, Base) VAR(Type, Base)
468#endif
469VARTEMPLATESPECIALIZATION(VarTemplateSpecialization, VarDecl)
470#ifndef VARTEMPLATEPARTIALSPECIALIZATION
471# define VARTEMPLATEPARTIALSPECIALIZATION(Type, Base) VARTEMPLATESPECIALIZATION(Type, Base)
472#endif
473VARTEMPLATEPARTIALSPECIALIZATION(VarTemplatePartialSpecialization, VarTemplateSpecializationDecl)
474#undef VARTEMPLATEPARTIALSPECIALIZATION
475
476DECL_RANGE(VarTemplateSpecialization, VarTemplateSpecialization, VarTemplatePartialSpecialization)
477
478#undef VARTEMPLATESPECIALIZATION
479
480DECL_RANGE(Var, Var, VarTemplatePartialSpecialization)
481
482#undef VAR
483
484DECL_RANGE(Declarator, Field, VarTemplatePartialSpecialization)
485
486#undef DECLARATOR
487
488#ifndef ENUMCONSTANT
489# define ENUMCONSTANT(Type, Base) VALUE(Type, Base)
490#endif
491ENUMCONSTANT(EnumConstant, ValueDecl)
492#undef ENUMCONSTANT
493
494#ifndef INDIRECTFIELD
495# define INDIRECTFIELD(Type, Base) VALUE(Type, Base)
496#endif
497INDIRECTFIELD(IndirectField, ValueDecl)
498#undef INDIRECTFIELD
499
500#ifndef OMPDECLAREREDUCTION
501# define OMPDECLAREREDUCTION(Type, Base) VALUE(Type, Base)
502#endif
503OMPDECLAREREDUCTION(OMPDeclareReduction, ValueDecl)
504#undef OMPDECLAREREDUCTION
505
506#ifndef UNRESOLVEDUSINGVALUE
507# define UNRESOLVEDUSINGVALUE(Type, Base) VALUE(Type, Base)
508#endif
509UNRESOLVEDUSINGVALUE(UnresolvedUsingValue, ValueDecl)
510#undef UNRESOLVEDUSINGVALUE
511
512DECL_RANGE(Value, Binding, UnresolvedUsingValue)
513
514#undef VALUE
515
516DECL_RANGE(Named, Label, UnresolvedUsingValue)
517
518#undef NAMED
519
520#ifndef OMPTHREADPRIVATE
521# define OMPTHREADPRIVATE(Type, Base) DECL(Type, Base)
522#endif
523OMPTHREADPRIVATE(OMPThreadPrivate, Decl)
524#undef OMPTHREADPRIVATE
525
526#ifndef OBJCPROPERTYIMPL
527# define OBJCPROPERTYIMPL(Type, Base) DECL(Type, Base)
528#endif
529OBJCPROPERTYIMPL(ObjCPropertyImpl, Decl)
17
Within the expansion of the macro 'OBJCPROPERTYIMPL':
a
Calling 'ASTNodeImporter::VisitObjCPropertyImplDecl'
530#undef OBJCPROPERTYIMPL
531
532#ifndef PRAGMACOMMENT
533# define PRAGMACOMMENT(Type, Base) DECL(Type, Base)
534#endif
535PRAGMACOMMENT(PragmaComment, Decl)
536#undef PRAGMACOMMENT
537
538#ifndef PRAGMADETECTMISMATCH
539# define PRAGMADETECTMISMATCH(Type, Base) DECL(Type, Base)
540#endif
541PRAGMADETECTMISMATCH(PragmaDetectMismatch, Decl)
542#undef PRAGMADETECTMISMATCH
543
544#ifndef STATICASSERT
545# define STATICASSERT(Type, Base) DECL(Type, Base)
546#endif
547STATICASSERT(StaticAssert, Decl)
548#undef STATICASSERT
549
550#ifndef TRANSLATIONUNIT
551# define TRANSLATIONUNIT(Type, Base) DECL(Type, Base)
552#endif
553TRANSLATIONUNIT(TranslationUnit, Decl)
554#undef TRANSLATIONUNIT
555
556LAST_DECL_RANGE(Decl, AccessSpec, TranslationUnit)
557
558#undef DECL
559#undef DECL_RANGE
560#undef LAST_DECL_RANGE
561#undef ABSTRACT_DECL
562/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
563|* *|
564|* List of AST Decl nodes *|
565|* *|
566|* Automatically generated file, do not edit! *|
567|* *|
568\*===----------------------------------------------------------------------===*/
569
570#ifndef DECL_CONTEXT
571# define DECL_CONTEXT(DECL)
572#endif
573#ifndef DECL_CONTEXT_BASE
574# define DECL_CONTEXT_BASE(DECL) DECL_CONTEXT(DECL)
575#endif
576DECL_CONTEXT_BASE(Function)
577DECL_CONTEXT_BASE(Tag)
578DECL_CONTEXT_BASE(ObjCContainer)
579DECL_CONTEXT(Block)
580DECL_CONTEXT(Captured)
581DECL_CONTEXT(Export)
582DECL_CONTEXT(ExternCContext)
583DECL_CONTEXT(LinkageSpec)
584DECL_CONTEXT(Namespace)
585DECL_CONTEXT(OMPDeclareReduction)
586DECL_CONTEXT(ObjCMethod)
587DECL_CONTEXT(TranslationUnit)
588#undef DECL_CONTEXT
589#undef DECL_CONTEXT_BASE