-
Notifications
You must be signed in to change notification settings - Fork 13.3k
/
Copy pathASTImporter.cpp
10575 lines (9106 loc) · 388 KB
/
ASTImporter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines the ASTImporter class which imports AST nodes from one
// context into another context.
//
//===----------------------------------------------------------------------===//
#include "clang/AST/ASTImporter.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTDiagnostic.h"
#include "clang/AST/ASTImporterSharedState.h"
#include "clang/AST/ASTLambda.h"
#include "clang/AST/ASTStructuralEquivalence.h"
#include "clang/AST/Attr.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclAccessPair.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclFriend.h"
#include "clang/AST/DeclGroup.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/DeclVisitor.h"
#include "clang/AST/DeclarationName.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/ExternalASTSource.h"
#include "clang/AST/LambdaCapture.h"
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/OperationKinds.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/StmtCXX.h"
#include "clang/AST/StmtObjC.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/AST/TemplateBase.h"
#include "clang/AST/TemplateName.h"
#include "clang/AST/Type.h"
#include "clang/AST/TypeLoc.h"
#include "clang/AST/TypeVisitor.h"
#include "clang/AST/UnresolvedSet.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/ExceptionSpecificationType.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Specifiers.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MemoryBuffer.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <memory>
#include <optional>
#include <type_traits>
#include <utility>
namespace clang {
using llvm::make_error;
using llvm::Error;
using llvm::Expected;
using ExpectedTypePtr = llvm::Expected<const Type *>;
using ExpectedType = llvm::Expected<QualType>;
using ExpectedStmt = llvm::Expected<Stmt *>;
using ExpectedExpr = llvm::Expected<Expr *>;
using ExpectedDecl = llvm::Expected<Decl *>;
using ExpectedSLoc = llvm::Expected<SourceLocation>;
using ExpectedName = llvm::Expected<DeclarationName>;
std::string ASTImportError::toString() const {
// FIXME: Improve error texts.
switch (Error) {
case NameConflict:
return "NameConflict";
case UnsupportedConstruct:
return "UnsupportedConstruct";
case Unknown:
return "Unknown error";
}
llvm_unreachable("Invalid error code.");
return "Invalid error code.";
}
void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
std::error_code ASTImportError::convertToErrorCode() const {
llvm_unreachable("Function not implemented.");
}
char ASTImportError::ID;
template <class T>
static SmallVector<Decl *, 2>
getCanonicalForwardRedeclChain(Redeclarable<T> *D) {
SmallVector<Decl *, 2> Redecls;
for (auto *R : D->getFirstDecl()->redecls()) {
if (R != D->getFirstDecl())
Redecls.push_back(R);
}
Redecls.push_back(D->getFirstDecl());
std::reverse(Redecls.begin(), Redecls.end());
return Redecls;
}
SmallVector<Decl*, 2> getCanonicalForwardRedeclChain(Decl* D) {
if (auto *FD = dyn_cast<FunctionDecl>(D))
return getCanonicalForwardRedeclChain<FunctionDecl>(FD);
if (auto *VD = dyn_cast<VarDecl>(D))
return getCanonicalForwardRedeclChain<VarDecl>(VD);
if (auto *TD = dyn_cast<TagDecl>(D))
return getCanonicalForwardRedeclChain<TagDecl>(TD);
llvm_unreachable("Bad declaration kind");
}
static void updateFlags(const Decl *From, Decl *To) {
// Check if some flags or attrs are new in 'From' and copy into 'To'.
// FIXME: Other flags or attrs?
if (From->isUsed(false) && !To->isUsed(false))
To->setIsUsed();
}
/// How to handle import errors that occur when import of a child declaration
/// of a DeclContext fails.
class ChildErrorHandlingStrategy {
/// This context is imported (in the 'from' domain).
/// It is nullptr if a non-DeclContext is imported.
const DeclContext *const FromDC;
/// Ignore import errors of the children.
/// If true, the context can be imported successfully if a child
/// of it failed to import. Otherwise the import errors of the child nodes
/// are accumulated (joined) into the import error object of the parent.
/// (Import of a parent can fail in other ways.)
bool const IgnoreChildErrors;
public:
ChildErrorHandlingStrategy(const DeclContext *FromDC)
: FromDC(FromDC), IgnoreChildErrors(!isa<TagDecl>(FromDC)) {}
ChildErrorHandlingStrategy(const Decl *FromD)
: FromDC(dyn_cast<DeclContext>(FromD)),
IgnoreChildErrors(!isa<TagDecl>(FromD)) {}
/// Process the import result of a child (of the current declaration).
/// \param ResultErr The import error that can be used as result of
/// importing the parent. This may be changed by the function.
/// \param ChildErr Result of importing a child. Can be success or error.
void handleChildImportResult(Error &ResultErr, Error &&ChildErr) {
if (ChildErr && !IgnoreChildErrors)
ResultErr = joinErrors(std::move(ResultErr), std::move(ChildErr));
else
consumeError(std::move(ChildErr));
}
/// Determine if import failure of a child does not cause import failure of
/// its parent.
bool ignoreChildErrorOnParent(Decl *FromChildD) const {
if (!IgnoreChildErrors || !FromDC)
return false;
return FromDC->containsDecl(FromChildD);
}
};
class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>,
public DeclVisitor<ASTNodeImporter, ExpectedDecl>,
public StmtVisitor<ASTNodeImporter, ExpectedStmt> {
ASTImporter &Importer;
// Use this instead of Importer.importInto .
template <typename ImportT>
[[nodiscard]] Error importInto(ImportT &To, const ImportT &From) {
return Importer.importInto(To, From);
}
// Use this to import pointers of specific type.
template <typename ImportT>
[[nodiscard]] Error importInto(ImportT *&To, ImportT *From) {
auto ToOrErr = Importer.Import(From);
if (ToOrErr)
To = cast_or_null<ImportT>(*ToOrErr);
return ToOrErr.takeError();
}
// Call the import function of ASTImporter for a baseclass of type `T` and
// cast the return value to `T`.
template <typename T>
auto import(T *From)
-> std::conditional_t<std::is_base_of_v<Type, T>, Expected<const T *>,
Expected<T *>> {
auto ToOrErr = Importer.Import(From);
if (!ToOrErr)
return ToOrErr.takeError();
return cast_or_null<T>(*ToOrErr);
}
template <typename T>
auto import(const T *From) {
return import(const_cast<T *>(From));
}
// Call the import function of ASTImporter for type `T`.
template <typename T>
Expected<T> import(const T &From) {
return Importer.Import(From);
}
// Import an std::optional<T> by importing the contained T, if any.
template <typename T>
Expected<std::optional<T>> import(std::optional<T> From) {
if (!From)
return std::nullopt;
return import(*From);
}
ExplicitSpecifier importExplicitSpecifier(Error &Err,
ExplicitSpecifier ESpec);
// Wrapper for an overload set.
template <typename ToDeclT> struct CallOverloadedCreateFun {
template <typename... Args> decltype(auto) operator()(Args &&... args) {
return ToDeclT::Create(std::forward<Args>(args)...);
}
};
// Always use these functions to create a Decl during import. There are
// certain tasks which must be done after the Decl was created, e.g. we
// must immediately register that as an imported Decl. The parameter `ToD`
// will be set to the newly created Decl or if had been imported before
// then to the already imported Decl. Returns a bool value set to true if
// the `FromD` had been imported before.
template <typename ToDeclT, typename FromDeclT, typename... Args>
[[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
Args &&...args) {
// There may be several overloads of ToDeclT::Create. We must make sure
// to call the one which would be chosen by the arguments, thus we use a
// wrapper for the overload set.
CallOverloadedCreateFun<ToDeclT> OC;
return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
std::forward<Args>(args)...);
}
// Use this overload if a special Type is needed to be created. E.g if we
// want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl`
// then:
// TypedefNameDecl *ToTypedef;
// GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...);
template <typename NewDeclT, typename ToDeclT, typename FromDeclT,
typename... Args>
[[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
Args &&...args) {
CallOverloadedCreateFun<NewDeclT> OC;
return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
std::forward<Args>(args)...);
}
// Use this version if a special create function must be
// used, e.g. CXXRecordDecl::CreateLambda .
template <typename ToDeclT, typename CreateFunT, typename FromDeclT,
typename... Args>
[[nodiscard]] bool
GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun,
FromDeclT *FromD, Args &&...args) {
if (Importer.getImportDeclErrorIfAny(FromD)) {
ToD = nullptr;
return true; // Already imported but with error.
}
ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD));
if (ToD)
return true; // Already imported.
ToD = CreateFun(std::forward<Args>(args)...);
// Keep track of imported Decls.
Importer.RegisterImportedDecl(FromD, ToD);
Importer.SharedState->markAsNewDecl(ToD);
InitializeImportedDecl(FromD, ToD);
return false; // A new Decl is created.
}
void InitializeImportedDecl(Decl *FromD, Decl *ToD) {
ToD->IdentifierNamespace = FromD->IdentifierNamespace;
if (FromD->isUsed())
ToD->setIsUsed();
if (FromD->isImplicit())
ToD->setImplicit();
}
// Check if we have found an existing definition. Returns with that
// definition if yes, otherwise returns null.
Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) {
const FunctionDecl *Definition = nullptr;
if (D->doesThisDeclarationHaveABody() &&
FoundFunction->hasBody(Definition))
return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition));
return nullptr;
}
void addDeclToContexts(Decl *FromD, Decl *ToD) {
if (Importer.isMinimalImport()) {
// In minimal import case the decl must be added even if it is not
// contained in original context, for LLDB compatibility.
// FIXME: Check if a better solution is possible.
if (!FromD->getDescribedTemplate() &&
FromD->getFriendObjectKind() == Decl::FOK_None)
ToD->getLexicalDeclContext()->addDeclInternal(ToD);
return;
}
DeclContext *FromDC = FromD->getDeclContext();
DeclContext *FromLexicalDC = FromD->getLexicalDeclContext();
DeclContext *ToDC = ToD->getDeclContext();
DeclContext *ToLexicalDC = ToD->getLexicalDeclContext();
bool Visible = false;
if (FromDC->containsDeclAndLoad(FromD)) {
ToDC->addDeclInternal(ToD);
Visible = true;
}
if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) {
ToLexicalDC->addDeclInternal(ToD);
Visible = true;
}
// If the Decl was added to any context, it was made already visible.
// Otherwise it is still possible that it should be visible.
if (!Visible) {
if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) {
auto *ToNamed = cast<NamedDecl>(ToD);
DeclContextLookupResult FromLookup =
FromDC->lookup(FromNamed->getDeclName());
if (llvm::is_contained(FromLookup, FromNamed))
ToDC->makeDeclVisibleInContext(ToNamed);
}
}
}
void updateLookupTableForTemplateParameters(TemplateParameterList &Params,
DeclContext *OldDC) {
ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
if (!LT)
return;
for (NamedDecl *TP : Params)
LT->update(TP, OldDC);
}
void updateLookupTableForTemplateParameters(TemplateParameterList &Params) {
updateLookupTableForTemplateParameters(
Params, Importer.getToContext().getTranslationUnitDecl());
}
template <typename TemplateParmDeclT>
Error importTemplateParameterDefaultArgument(const TemplateParmDeclT *D,
TemplateParmDeclT *ToD) {
if (D->hasDefaultArgument()) {
if (D->defaultArgumentWasInherited()) {
Expected<TemplateParmDeclT *> ToInheritedFromOrErr =
import(D->getDefaultArgStorage().getInheritedFrom());
if (!ToInheritedFromOrErr)
return ToInheritedFromOrErr.takeError();
TemplateParmDeclT *ToInheritedFrom = *ToInheritedFromOrErr;
if (!ToInheritedFrom->hasDefaultArgument()) {
// Resolve possible circular dependency between default value of the
// template argument and the template declaration.
Expected<TemplateArgumentLoc> ToInheritedDefaultArgOrErr =
import(D->getDefaultArgStorage()
.getInheritedFrom()
->getDefaultArgument());
if (!ToInheritedDefaultArgOrErr)
return ToInheritedDefaultArgOrErr.takeError();
ToInheritedFrom->setDefaultArgument(Importer.getToContext(),
*ToInheritedDefaultArgOrErr);
}
ToD->setInheritedDefaultArgument(ToD->getASTContext(),
ToInheritedFrom);
} else {
Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
import(D->getDefaultArgument());
if (!ToDefaultArgOrErr)
return ToDefaultArgOrErr.takeError();
// Default argument could have been set in the
// '!ToInheritedFrom->hasDefaultArgument()' branch above.
if (!ToD->hasDefaultArgument())
ToD->setDefaultArgument(Importer.getToContext(),
*ToDefaultArgOrErr);
}
}
return Error::success();
}
public:
explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {}
using TypeVisitor<ASTNodeImporter, ExpectedType>::Visit;
using DeclVisitor<ASTNodeImporter, ExpectedDecl>::Visit;
using StmtVisitor<ASTNodeImporter, ExpectedStmt>::Visit;
// Importing types
ExpectedType VisitType(const Type *T);
#define TYPE(Class, Base) \
ExpectedType Visit##Class##Type(const Class##Type *T);
#include "clang/AST/TypeNodes.inc"
// Importing declarations
Error ImportDeclParts(NamedDecl *D, DeclarationName &Name, NamedDecl *&ToD,
SourceLocation &Loc);
Error ImportDeclParts(
NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc);
Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
Error ImportDeclarationNameLoc(
const DeclarationNameInfo &From, DeclarationNameInfo &To);
Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
Error ImportDeclContext(
Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To);
Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To);
Expected<CXXCastPath> ImportCastPath(CastExpr *E);
Expected<APValue> ImportAPValue(const APValue &FromValue);
using Designator = DesignatedInitExpr::Designator;
/// What we should import from the definition.
enum ImportDefinitionKind {
/// Import the default subset of the definition, which might be
/// nothing (if minimal import is set) or might be everything (if minimal
/// import is not set).
IDK_Default,
/// Import everything.
IDK_Everything,
/// Import only the bare bones needed to establish a valid
/// DeclContext.
IDK_Basic
};
bool shouldForceImportDeclContext(ImportDefinitionKind IDK) {
return IDK == IDK_Everything ||
(IDK == IDK_Default && !Importer.isMinimalImport());
}
Error ImportInitializer(VarDecl *From, VarDecl *To);
Error ImportDefinition(
RecordDecl *From, RecordDecl *To,
ImportDefinitionKind Kind = IDK_Default);
Error ImportDefinition(
EnumDecl *From, EnumDecl *To,
ImportDefinitionKind Kind = IDK_Default);
Error ImportDefinition(
ObjCInterfaceDecl *From, ObjCInterfaceDecl *To,
ImportDefinitionKind Kind = IDK_Default);
Error ImportDefinition(
ObjCProtocolDecl *From, ObjCProtocolDecl *To,
ImportDefinitionKind Kind = IDK_Default);
Error ImportTemplateArguments(ArrayRef<TemplateArgument> FromArgs,
SmallVectorImpl<TemplateArgument> &ToArgs);
Expected<TemplateArgument>
ImportTemplateArgument(const TemplateArgument &From);
template <typename InContainerTy>
Error ImportTemplateArgumentListInfo(
const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo);
template<typename InContainerTy>
Error ImportTemplateArgumentListInfo(
SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
const InContainerTy &Container, TemplateArgumentListInfo &Result);
using TemplateArgsTy = SmallVector<TemplateArgument, 8>;
using FunctionTemplateAndArgsTy =
std::tuple<FunctionTemplateDecl *, TemplateArgsTy>;
Expected<FunctionTemplateAndArgsTy>
ImportFunctionTemplateWithTemplateArgsFromSpecialization(
FunctionDecl *FromFD);
template <typename DeclTy>
Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD);
Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD);
Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD);
Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam,
ParmVarDecl *ToParam);
Expected<InheritedConstructor>
ImportInheritedConstructor(const InheritedConstructor &From);
template <typename T>
bool hasSameVisibilityContextAndLinkage(T *Found, T *From);
bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
bool IgnoreTemplateParmDepth = false);
ExpectedDecl VisitDecl(Decl *D);
ExpectedDecl VisitImportDecl(ImportDecl *D);
ExpectedDecl VisitEmptyDecl(EmptyDecl *D);
ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D);
ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D);
ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D);
ExpectedDecl VisitBindingDecl(BindingDecl *D);
ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D);
ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias);
ExpectedDecl VisitTypedefDecl(TypedefDecl *D);
ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D);
ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
ExpectedDecl VisitLabelDecl(LabelDecl *D);
ExpectedDecl VisitEnumDecl(EnumDecl *D);
ExpectedDecl VisitRecordDecl(RecordDecl *D);
ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D);
ExpectedDecl VisitFunctionDecl(FunctionDecl *D);
ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D);
ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D);
ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D);
ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D);
ExpectedDecl VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D);
ExpectedDecl VisitFieldDecl(FieldDecl *D);
ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D);
ExpectedDecl VisitFriendDecl(FriendDecl *D);
ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D);
ExpectedDecl VisitVarDecl(VarDecl *D);
ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D);
ExpectedDecl VisitParmVarDecl(ParmVarDecl *D);
ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D);
ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D);
ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D);
ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D);
ExpectedDecl VisitUsingDecl(UsingDecl *D);
ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D);
ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
ExpectedDecl VisitUsingPackDecl(UsingPackDecl *D);
ExpectedDecl ImportUsingShadowDecls(BaseUsingDecl *D, BaseUsingDecl *ToSI);
ExpectedDecl VisitUsingEnumDecl(UsingEnumDecl *D);
ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D);
ExpectedDecl
VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D);
Expected<ObjCTypeParamList *>
ImportObjCTypeParamList(ObjCTypeParamList *list);
ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D);
ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D);
ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D);
ExpectedDecl VisitClassTemplateSpecializationDecl(
ClassTemplateSpecializationDecl *D);
ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D);
ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D);
ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
// Importing statements
ExpectedStmt VisitStmt(Stmt *S);
ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S);
ExpectedStmt VisitDeclStmt(DeclStmt *S);
ExpectedStmt VisitNullStmt(NullStmt *S);
ExpectedStmt VisitCompoundStmt(CompoundStmt *S);
ExpectedStmt VisitCaseStmt(CaseStmt *S);
ExpectedStmt VisitDefaultStmt(DefaultStmt *S);
ExpectedStmt VisitLabelStmt(LabelStmt *S);
ExpectedStmt VisitAttributedStmt(AttributedStmt *S);
ExpectedStmt VisitIfStmt(IfStmt *S);
ExpectedStmt VisitSwitchStmt(SwitchStmt *S);
ExpectedStmt VisitWhileStmt(WhileStmt *S);
ExpectedStmt VisitDoStmt(DoStmt *S);
ExpectedStmt VisitForStmt(ForStmt *S);
ExpectedStmt VisitGotoStmt(GotoStmt *S);
ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S);
ExpectedStmt VisitContinueStmt(ContinueStmt *S);
ExpectedStmt VisitBreakStmt(BreakStmt *S);
ExpectedStmt VisitReturnStmt(ReturnStmt *S);
// FIXME: MSAsmStmt
// FIXME: SEHExceptStmt
// FIXME: SEHFinallyStmt
// FIXME: SEHTryStmt
// FIXME: SEHLeaveStmt
// FIXME: CapturedStmt
ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S);
ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S);
ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S);
// FIXME: MSDependentExistsStmt
ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S);
ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S);
ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S);
ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S);
ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S);
ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S);
ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S);
// Importing expressions
ExpectedStmt VisitExpr(Expr *E);
ExpectedStmt VisitSourceLocExpr(SourceLocExpr *E);
ExpectedStmt VisitVAArgExpr(VAArgExpr *E);
ExpectedStmt VisitChooseExpr(ChooseExpr *E);
ExpectedStmt VisitConvertVectorExpr(ConvertVectorExpr *E);
ExpectedStmt VisitShuffleVectorExpr(ShuffleVectorExpr *E);
ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E);
ExpectedStmt VisitGenericSelectionExpr(GenericSelectionExpr *E);
ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E);
ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E);
ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E);
ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E);
ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E);
ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E);
ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E);
ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E);
ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E);
ExpectedStmt VisitStringLiteral(StringLiteral *E);
ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
ExpectedStmt VisitAtomicExpr(AtomicExpr *E);
ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E);
ExpectedStmt VisitConstantExpr(ConstantExpr *E);
ExpectedStmt VisitParenExpr(ParenExpr *E);
ExpectedStmt VisitParenListExpr(ParenListExpr *E);
ExpectedStmt VisitStmtExpr(StmtExpr *E);
ExpectedStmt VisitUnaryOperator(UnaryOperator *E);
ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E);
ExpectedStmt VisitBinaryOperator(BinaryOperator *E);
ExpectedStmt VisitConditionalOperator(ConditionalOperator *E);
ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E);
ExpectedStmt VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *E);
ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E);
ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E);
ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E);
ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E);
ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E);
ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E);
ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E);
ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE);
ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E);
ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E);
ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E);
ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E);
ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E);
ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E);
ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E);
ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E);
ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E);
ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E);
ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E);
ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E);
ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E);
ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E);
ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E);
ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E);
ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E);
ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E);
ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E);
ExpectedStmt VisitMemberExpr(MemberExpr *E);
ExpectedStmt VisitCallExpr(CallExpr *E);
ExpectedStmt VisitLambdaExpr(LambdaExpr *LE);
ExpectedStmt VisitInitListExpr(InitListExpr *E);
ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E);
ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E);
ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E);
ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E);
ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E);
ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E);
ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E);
// Helper for chaining together multiple imports. If an error is detected,
// subsequent imports will return default constructed nodes, so that failure
// can be detected with a single conditional branch after a sequence of
// imports.
template <typename T> T importChecked(Error &Err, const T &From) {
// Don't attempt to import nodes if we hit an error earlier.
if (Err)
return T{};
Expected<T> MaybeVal = import(From);
if (!MaybeVal) {
Err = MaybeVal.takeError();
return T{};
}
return *MaybeVal;
}
template<typename IIter, typename OIter>
Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
using ItemT = std::remove_reference_t<decltype(*Obegin)>;
for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
Expected<ItemT> ToOrErr = import(*Ibegin);
if (!ToOrErr)
return ToOrErr.takeError();
*Obegin = *ToOrErr;
}
return Error::success();
}
// Import every item from a container structure into an output container.
// If error occurs, stops at first error and returns the error.
// The output container should have space for all needed elements (it is not
// expanded, new items are put into from the beginning).
template<typename InContainerTy, typename OutContainerTy>
Error ImportContainerChecked(
const InContainerTy &InContainer, OutContainerTy &OutContainer) {
return ImportArrayChecked(
InContainer.begin(), InContainer.end(), OutContainer.begin());
}
template<typename InContainerTy, typename OIter>
Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
}
Error ImportOverriddenMethods(CXXMethodDecl *ToMethod,
CXXMethodDecl *FromMethod);
Expected<FunctionDecl *> FindFunctionTemplateSpecialization(
FunctionDecl *FromFD);
// Returns true if the given function has a placeholder return type and
// that type is declared inside the body of the function.
// E.g. auto f() { struct X{}; return X(); }
bool hasReturnTypeDeclaredInside(FunctionDecl *D);
};
template <typename InContainerTy>
Error ASTNodeImporter::ImportTemplateArgumentListInfo(
SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
const InContainerTy &Container, TemplateArgumentListInfo &Result) {
auto ToLAngleLocOrErr = import(FromLAngleLoc);
if (!ToLAngleLocOrErr)
return ToLAngleLocOrErr.takeError();
auto ToRAngleLocOrErr = import(FromRAngleLoc);
if (!ToRAngleLocOrErr)
return ToRAngleLocOrErr.takeError();
TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr);
if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo))
return Err;
Result = ToTAInfo;
return Error::success();
}
template <>
Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>(
const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) {
return ImportTemplateArgumentListInfo(
From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result);
}
template <>
Error ASTNodeImporter::ImportTemplateArgumentListInfo<
ASTTemplateArgumentListInfo>(
const ASTTemplateArgumentListInfo &From,
TemplateArgumentListInfo &Result) {
return ImportTemplateArgumentListInfo(
From.LAngleLoc, From.RAngleLoc, From.arguments(), Result);
}
Expected<ASTNodeImporter::FunctionTemplateAndArgsTy>
ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization(
FunctionDecl *FromFD) {
assert(FromFD->getTemplatedKind() ==
FunctionDecl::TK_FunctionTemplateSpecialization);
FunctionTemplateAndArgsTy Result;
auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate()))
return std::move(Err);
// Import template arguments.
if (Error Err = ImportTemplateArguments(FTSInfo->TemplateArguments->asArray(),
std::get<1>(Result)))
return std::move(Err);
return Result;
}
template <>
Expected<TemplateParameterList *>
ASTNodeImporter::import(TemplateParameterList *From) {
SmallVector<NamedDecl *, 4> To(From->size());
if (Error Err = ImportContainerChecked(*From, To))
return std::move(Err);
ExpectedExpr ToRequiresClause = import(From->getRequiresClause());
if (!ToRequiresClause)
return ToRequiresClause.takeError();
auto ToTemplateLocOrErr = import(From->getTemplateLoc());
if (!ToTemplateLocOrErr)
return ToTemplateLocOrErr.takeError();
auto ToLAngleLocOrErr = import(From->getLAngleLoc());
if (!ToLAngleLocOrErr)
return ToLAngleLocOrErr.takeError();
auto ToRAngleLocOrErr = import(From->getRAngleLoc());
if (!ToRAngleLocOrErr)
return ToRAngleLocOrErr.takeError();
return TemplateParameterList::Create(
Importer.getToContext(),
*ToTemplateLocOrErr,
*ToLAngleLocOrErr,
To,
*ToRAngleLocOrErr,
*ToRequiresClause);
}
template <>
Expected<TemplateArgument>
ASTNodeImporter::import(const TemplateArgument &From) {
switch (From.getKind()) {
case TemplateArgument::Null:
return TemplateArgument();
case TemplateArgument::Type: {
ExpectedType ToTypeOrErr = import(From.getAsType());
if (!ToTypeOrErr)
return ToTypeOrErr.takeError();
return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false,
From.getIsDefaulted());
}
case TemplateArgument::Integral: {
ExpectedType ToTypeOrErr = import(From.getIntegralType());
if (!ToTypeOrErr)
return ToTypeOrErr.takeError();
return TemplateArgument(From, *ToTypeOrErr);
}
case TemplateArgument::Declaration: {
Expected<ValueDecl *> ToOrErr = import(From.getAsDecl());
if (!ToOrErr)
return ToOrErr.takeError();
ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
if (!ToTypeOrErr)
return ToTypeOrErr.takeError();
return TemplateArgument(dyn_cast<ValueDecl>((*ToOrErr)->getCanonicalDecl()),
*ToTypeOrErr, From.getIsDefaulted());
}
case TemplateArgument::NullPtr: {
ExpectedType ToTypeOrErr = import(From.getNullPtrType());
if (!ToTypeOrErr)
return ToTypeOrErr.takeError();
return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true,
From.getIsDefaulted());
}
case TemplateArgument::StructuralValue: {
ExpectedType ToTypeOrErr = import(From.getStructuralValueType());
if (!ToTypeOrErr)
return ToTypeOrErr.takeError();
Expected<APValue> ToValueOrErr = import(From.getAsStructuralValue());
if (!ToValueOrErr)
return ToValueOrErr.takeError();
return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
*ToValueOrErr);
}
case TemplateArgument::Template: {
Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
if (!ToTemplateOrErr)
return ToTemplateOrErr.takeError();
return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
}
case TemplateArgument::TemplateExpansion: {
Expected<TemplateName> ToTemplateOrErr =
import(From.getAsTemplateOrTemplatePattern());
if (!ToTemplateOrErr)
return ToTemplateOrErr.takeError();
return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(),
From.getIsDefaulted());
}
case TemplateArgument::Expression:
if (ExpectedExpr ToExpr = import(From.getAsExpr()))
return TemplateArgument(*ToExpr, From.isCanonicalExpr(),
From.getIsDefaulted());
else
return ToExpr.takeError();
case TemplateArgument::Pack: {
SmallVector<TemplateArgument, 2> ToPack;
ToPack.reserve(From.pack_size());
if (Error Err = ImportTemplateArguments(From.pack_elements(), ToPack))
return std::move(Err);
return TemplateArgument(
llvm::ArrayRef(ToPack).copy(Importer.getToContext()));
}
}
llvm_unreachable("Invalid template argument kind");
}
template <>
Expected<TemplateArgumentLoc>
ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) {
Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument());
if (!ArgOrErr)
return ArgOrErr.takeError();
TemplateArgument Arg = *ArgOrErr;
TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
TemplateArgumentLocInfo ToInfo;
if (Arg.getKind() == TemplateArgument::Expression) {
ExpectedExpr E = import(FromInfo.getAsExpr());
if (!E)
return E.takeError();
ToInfo = TemplateArgumentLocInfo(*E);
} else if (Arg.getKind() == TemplateArgument::Type) {
if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo()))
ToInfo = TemplateArgumentLocInfo(*TSIOrErr);
else
return TSIOrErr.takeError();
} else {
auto ToTemplateQualifierLocOrErr =
import(FromInfo.getTemplateQualifierLoc());
if (!ToTemplateQualifierLocOrErr)
return ToTemplateQualifierLocOrErr.takeError();
auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc());
if (!ToTemplateNameLocOrErr)
return ToTemplateNameLocOrErr.takeError();
auto ToTemplateEllipsisLocOrErr =
import(FromInfo.getTemplateEllipsisLoc());
if (!ToTemplateEllipsisLocOrErr)
return ToTemplateEllipsisLocOrErr.takeError();
ToInfo = TemplateArgumentLocInfo(
Importer.getToContext(), *ToTemplateQualifierLocOrErr,
*ToTemplateNameLocOrErr, *ToTemplateEllipsisLocOrErr);
}
return TemplateArgumentLoc(Arg, ToInfo);
}
template <>
Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) {
if (DG.isNull())
return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
size_t NumDecls = DG.end() - DG.begin();
SmallVector<Decl *, 1> ToDecls;
ToDecls.reserve(NumDecls);
for (Decl *FromD : DG) {
if (auto ToDOrErr = import(FromD))
ToDecls.push_back(*ToDOrErr);
else
return ToDOrErr.takeError();
}
return DeclGroupRef::Create(Importer.getToContext(),
ToDecls.begin(),
NumDecls);
}
template <>
Expected<ASTNodeImporter::Designator>
ASTNodeImporter::import(const Designator &D) {
if (D.isFieldDesignator()) {
IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc());
if (!ToDotLocOrErr)
return ToDotLocOrErr.takeError();
ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc());
if (!ToFieldLocOrErr)
return ToFieldLocOrErr.takeError();
return DesignatedInitExpr::Designator::CreateFieldDesignator(
ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr);
}
ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc());
if (!ToLBracketLocOrErr)
return ToLBracketLocOrErr.takeError();
ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc());
if (!ToRBracketLocOrErr)
return ToRBracketLocOrErr.takeError();
if (D.isArrayDesignator())