Coverage Report

Created: 2017-10-03 07:32

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