clang 20.0.0git
ASTImporter.cpp
Go to the documentation of this file.
1//===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the ASTImporter class which imports AST nodes from one
10// context into another context.
11//
12//===----------------------------------------------------------------------===//
13
19#include "clang/AST/Attr.h"
20#include "clang/AST/Decl.h"
22#include "clang/AST/DeclBase.h"
23#include "clang/AST/DeclCXX.h"
25#include "clang/AST/DeclGroup.h"
26#include "clang/AST/DeclObjC.h"
30#include "clang/AST/Expr.h"
31#include "clang/AST/ExprCXX.h"
32#include "clang/AST/ExprObjC.h"
37#include "clang/AST/Stmt.h"
38#include "clang/AST/StmtCXX.h"
39#include "clang/AST/StmtObjC.h"
43#include "clang/AST/Type.h"
44#include "clang/AST/TypeLoc.h"
51#include "clang/Basic/LLVM.h"
56#include "llvm/ADT/ArrayRef.h"
57#include "llvm/ADT/DenseMap.h"
58#include "llvm/ADT/STLExtras.h"
59#include "llvm/ADT/ScopeExit.h"
60#include "llvm/ADT/SmallVector.h"
61#include "llvm/Support/ErrorHandling.h"
62#include "llvm/Support/MemoryBuffer.h"
63#include <algorithm>
64#include <cassert>
65#include <cstddef>
66#include <memory>
67#include <optional>
68#include <type_traits>
69#include <utility>
70
71namespace clang {
72
73 using llvm::make_error;
74 using llvm::Error;
75 using llvm::Expected;
83
84 std::string ASTImportError::toString() const {
85 // FIXME: Improve error texts.
86 switch (Error) {
87 case NameConflict:
88 return "NameConflict";
90 return "UnsupportedConstruct";
91 case Unknown:
92 return "Unknown error";
93 }
94 llvm_unreachable("Invalid error code.");
95 return "Invalid error code.";
96 }
97
98 void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
99
100 std::error_code ASTImportError::convertToErrorCode() const {
101 llvm_unreachable("Function not implemented.");
102 }
103
105
106 template <class T>
110 for (auto *R : D->getFirstDecl()->redecls()) {
111 if (R != D->getFirstDecl())
112 Redecls.push_back(R);
113 }
114 Redecls.push_back(D->getFirstDecl());
115 std::reverse(Redecls.begin(), Redecls.end());
116 return Redecls;
117 }
118
120 if (auto *FD = dyn_cast<FunctionDecl>(D))
121 return getCanonicalForwardRedeclChain<FunctionDecl>(FD);
122 if (auto *VD = dyn_cast<VarDecl>(D))
123 return getCanonicalForwardRedeclChain<VarDecl>(VD);
124 if (auto *TD = dyn_cast<TagDecl>(D))
125 return getCanonicalForwardRedeclChain<TagDecl>(TD);
126 llvm_unreachable("Bad declaration kind");
127 }
128
129 static void updateFlags(const Decl *From, Decl *To) {
130 // Check if some flags or attrs are new in 'From' and copy into 'To'.
131 // FIXME: Other flags or attrs?
132 if (From->isUsed(false) && !To->isUsed(false))
133 To->setIsUsed();
134 }
135
136 /// How to handle import errors that occur when import of a child declaration
137 /// of a DeclContext fails.
139 /// This context is imported (in the 'from' domain).
140 /// It is nullptr if a non-DeclContext is imported.
141 const DeclContext *const FromDC;
142 /// Ignore import errors of the children.
143 /// If true, the context can be imported successfully if a child
144 /// of it failed to import. Otherwise the import errors of the child nodes
145 /// are accumulated (joined) into the import error object of the parent.
146 /// (Import of a parent can fail in other ways.)
147 bool const IgnoreChildErrors;
148
149 public:
151 : FromDC(FromDC), IgnoreChildErrors(!isa<TagDecl>(FromDC)) {}
153 : FromDC(dyn_cast<DeclContext>(FromD)),
154 IgnoreChildErrors(!isa<TagDecl>(FromD)) {}
155
156 /// Process the import result of a child (of the current declaration).
157 /// \param ResultErr The import error that can be used as result of
158 /// importing the parent. This may be changed by the function.
159 /// \param ChildErr Result of importing a child. Can be success or error.
160 void handleChildImportResult(Error &ResultErr, Error &&ChildErr) {
161 if (ChildErr && !IgnoreChildErrors)
162 ResultErr = joinErrors(std::move(ResultErr), std::move(ChildErr));
163 else
164 consumeError(std::move(ChildErr));
165 }
166
167 /// Determine if import failure of a child does not cause import failure of
168 /// its parent.
169 bool ignoreChildErrorOnParent(Decl *FromChildD) const {
170 if (!IgnoreChildErrors || !FromDC)
171 return false;
172 return FromDC->containsDecl(FromChildD);
173 }
174 };
175
176 class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>,
177 public DeclVisitor<ASTNodeImporter, ExpectedDecl>,
178 public StmtVisitor<ASTNodeImporter, ExpectedStmt> {
179 ASTImporter &Importer;
180
181 // Use this instead of Importer.importInto .
182 template <typename ImportT>
183 [[nodiscard]] Error importInto(ImportT &To, const ImportT &From) {
184 return Importer.importInto(To, From);
185 }
186
187 // Use this to import pointers of specific type.
188 template <typename ImportT>
189 [[nodiscard]] Error importInto(ImportT *&To, ImportT *From) {
190 auto ToOrErr = Importer.Import(From);
191 if (ToOrErr)
192 To = cast_or_null<ImportT>(*ToOrErr);
193 return ToOrErr.takeError();
194 }
195
196 // Call the import function of ASTImporter for a baseclass of type `T` and
197 // cast the return value to `T`.
198 template <typename T>
199 auto import(T *From)
200 -> std::conditional_t<std::is_base_of_v<Type, T>, Expected<const T *>,
202 auto ToOrErr = Importer.Import(From);
203 if (!ToOrErr)
204 return ToOrErr.takeError();
205 return cast_or_null<T>(*ToOrErr);
206 }
207
208 template <typename T>
209 auto import(const T *From) {
210 return import(const_cast<T *>(From));
211 }
212
213 // Call the import function of ASTImporter for type `T`.
214 template <typename T>
215 Expected<T> import(const T &From) {
216 return Importer.Import(From);
217 }
218
219 // Import an std::optional<T> by importing the contained T, if any.
220 template <typename T>
221 Expected<std::optional<T>> import(std::optional<T> From) {
222 if (!From)
223 return std::nullopt;
224 return import(*From);
225 }
226
227 ExplicitSpecifier importExplicitSpecifier(Error &Err,
228 ExplicitSpecifier ESpec);
229
230 // Wrapper for an overload set.
231 template <typename ToDeclT> struct CallOverloadedCreateFun {
232 template <typename... Args> decltype(auto) operator()(Args &&... args) {
233 return ToDeclT::Create(std::forward<Args>(args)...);
234 }
235 };
236
237 // Always use these functions to create a Decl during import. There are
238 // certain tasks which must be done after the Decl was created, e.g. we
239 // must immediately register that as an imported Decl. The parameter `ToD`
240 // will be set to the newly created Decl or if had been imported before
241 // then to the already imported Decl. Returns a bool value set to true if
242 // the `FromD` had been imported before.
243 template <typename ToDeclT, typename FromDeclT, typename... Args>
244 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
245 Args &&...args) {
246 // There may be several overloads of ToDeclT::Create. We must make sure
247 // to call the one which would be chosen by the arguments, thus we use a
248 // wrapper for the overload set.
249 CallOverloadedCreateFun<ToDeclT> OC;
250 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
251 std::forward<Args>(args)...);
252 }
253 // Use this overload if a special Type is needed to be created. E.g if we
254 // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl`
255 // then:
256 // TypedefNameDecl *ToTypedef;
257 // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...);
258 template <typename NewDeclT, typename ToDeclT, typename FromDeclT,
259 typename... Args>
260 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
261 Args &&...args) {
262 CallOverloadedCreateFun<NewDeclT> OC;
263 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
264 std::forward<Args>(args)...);
265 }
266 // Use this version if a special create function must be
267 // used, e.g. CXXRecordDecl::CreateLambda .
268 template <typename ToDeclT, typename CreateFunT, typename FromDeclT,
269 typename... Args>
270 [[nodiscard]] bool
271 GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun,
272 FromDeclT *FromD, Args &&...args) {
273 if (Importer.getImportDeclErrorIfAny(FromD)) {
274 ToD = nullptr;
275 return true; // Already imported but with error.
276 }
277 ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD));
278 if (ToD)
279 return true; // Already imported.
280 ToD = CreateFun(std::forward<Args>(args)...);
281 // Keep track of imported Decls.
282 Importer.RegisterImportedDecl(FromD, ToD);
283 Importer.SharedState->markAsNewDecl(ToD);
284 InitializeImportedDecl(FromD, ToD);
285 return false; // A new Decl is created.
286 }
287
288 void InitializeImportedDecl(Decl *FromD, Decl *ToD) {
289 ToD->IdentifierNamespace = FromD->IdentifierNamespace;
290 if (FromD->isUsed())
291 ToD->setIsUsed();
292 if (FromD->isImplicit())
293 ToD->setImplicit();
294 }
295
296 // Check if we have found an existing definition. Returns with that
297 // definition if yes, otherwise returns null.
298 Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) {
299 const FunctionDecl *Definition = nullptr;
300 if (D->doesThisDeclarationHaveABody() &&
301 FoundFunction->hasBody(Definition))
302 return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition));
303 return nullptr;
304 }
305
306 void addDeclToContexts(Decl *FromD, Decl *ToD) {
307 if (Importer.isMinimalImport()) {
308 // In minimal import case the decl must be added even if it is not
309 // contained in original context, for LLDB compatibility.
310 // FIXME: Check if a better solution is possible.
311 if (!FromD->getDescribedTemplate() &&
312 FromD->getFriendObjectKind() == Decl::FOK_None)
314 return;
315 }
316
317 DeclContext *FromDC = FromD->getDeclContext();
318 DeclContext *FromLexicalDC = FromD->getLexicalDeclContext();
319 DeclContext *ToDC = ToD->getDeclContext();
320 DeclContext *ToLexicalDC = ToD->getLexicalDeclContext();
321
322 bool Visible = false;
323 if (FromDC->containsDeclAndLoad(FromD)) {
324 ToDC->addDeclInternal(ToD);
325 Visible = true;
326 }
327 if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) {
328 ToLexicalDC->addDeclInternal(ToD);
329 Visible = true;
330 }
331
332 // If the Decl was added to any context, it was made already visible.
333 // Otherwise it is still possible that it should be visible.
334 if (!Visible) {
335 if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) {
336 auto *ToNamed = cast<NamedDecl>(ToD);
337 DeclContextLookupResult FromLookup =
338 FromDC->lookup(FromNamed->getDeclName());
339 if (llvm::is_contained(FromLookup, FromNamed))
340 ToDC->makeDeclVisibleInContext(ToNamed);
341 }
342 }
343 }
344
345 void updateLookupTableForTemplateParameters(TemplateParameterList &Params,
346 DeclContext *OldDC) {
347 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
348 if (!LT)
349 return;
350
351 for (NamedDecl *TP : Params)
352 LT->update(TP, OldDC);
353 }
354
355 void updateLookupTableForTemplateParameters(TemplateParameterList &Params) {
356 updateLookupTableForTemplateParameters(
357 Params, Importer.getToContext().getTranslationUnitDecl());
358 }
359
360 template <typename TemplateParmDeclT>
361 Error importTemplateParameterDefaultArgument(const TemplateParmDeclT *D,
362 TemplateParmDeclT *ToD) {
363 if (D->hasDefaultArgument()) {
364 if (D->defaultArgumentWasInherited()) {
365 Expected<TemplateParmDeclT *> ToInheritedFromOrErr =
366 import(D->getDefaultArgStorage().getInheritedFrom());
367 if (!ToInheritedFromOrErr)
368 return ToInheritedFromOrErr.takeError();
369 TemplateParmDeclT *ToInheritedFrom = *ToInheritedFromOrErr;
370 if (!ToInheritedFrom->hasDefaultArgument()) {
371 // Resolve possible circular dependency between default value of the
372 // template argument and the template declaration.
373 Expected<TemplateArgumentLoc> ToInheritedDefaultArgOrErr =
374 import(D->getDefaultArgStorage()
375 .getInheritedFrom()
376 ->getDefaultArgument());
377 if (!ToInheritedDefaultArgOrErr)
378 return ToInheritedDefaultArgOrErr.takeError();
379 ToInheritedFrom->setDefaultArgument(Importer.getToContext(),
380 *ToInheritedDefaultArgOrErr);
381 }
382 ToD->setInheritedDefaultArgument(ToD->getASTContext(),
383 ToInheritedFrom);
384 } else {
385 Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
386 import(D->getDefaultArgument());
387 if (!ToDefaultArgOrErr)
388 return ToDefaultArgOrErr.takeError();
389 // Default argument could have been set in the
390 // '!ToInheritedFrom->hasDefaultArgument()' branch above.
391 if (!ToD->hasDefaultArgument())
392 ToD->setDefaultArgument(Importer.getToContext(),
393 *ToDefaultArgOrErr);
394 }
395 }
396 return Error::success();
397 }
398
399 public:
400 explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {}
401
405
406 // Importing types
408#define TYPE(Class, Base) \
409 ExpectedType Visit##Class##Type(const Class##Type *T);
410#include "clang/AST/TypeNodes.inc"
411
412 // Importing declarations
415 Error ImportDeclParts(
416 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
418 Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
421 Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
422 Error ImportDeclContext(
423 Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
424 Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To);
425
426 Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To);
428 Expected<APValue> ImportAPValue(const APValue &FromValue);
429
431
432 /// What we should import from the definition.
434 /// Import the default subset of the definition, which might be
435 /// nothing (if minimal import is set) or might be everything (if minimal
436 /// import is not set).
438 /// Import everything.
440 /// Import only the bare bones needed to establish a valid
441 /// DeclContext.
443 };
444
446 return IDK == IDK_Everything ||
447 (IDK == IDK_Default && !Importer.isMinimalImport());
448 }
449
450 Error ImportInitializer(VarDecl *From, VarDecl *To);
451 Error ImportDefinition(
452 RecordDecl *From, RecordDecl *To,
454 Error ImportDefinition(
455 EnumDecl *From, EnumDecl *To,
457 Error ImportDefinition(
460 Error ImportDefinition(
467
468 template <typename InContainerTy>
470 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo);
471
472 template<typename InContainerTy>
474 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
475 const InContainerTy &Container, TemplateArgumentListInfo &Result);
476
479 std::tuple<FunctionTemplateDecl *, TemplateArgsTy>;
482 FunctionDecl *FromFD);
483
484 template <typename DeclTy>
485 Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD);
486
488
490
491 Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam,
492 ParmVarDecl *ToParam);
493
496
497 template <typename T>
499
500 bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
501 bool IgnoreTemplateParmDepth = false);
548
551
566
567 // Importing statements
587 // FIXME: MSAsmStmt
588 // FIXME: SEHExceptStmt
589 // FIXME: SEHFinallyStmt
590 // FIXME: SEHTryStmt
591 // FIXME: SEHLeaveStmt
592 // FIXME: CapturedStmt
596 // FIXME: MSDependentExistsStmt
604
605 // Importing expressions
682
683 // Helper for chaining together multiple imports. If an error is detected,
684 // subsequent imports will return default constructed nodes, so that failure
685 // can be detected with a single conditional branch after a sequence of
686 // imports.
687 template <typename T> T importChecked(Error &Err, const T &From) {
688 // Don't attempt to import nodes if we hit an error earlier.
689 if (Err)
690 return T{};
691 Expected<T> MaybeVal = import(From);
692 if (!MaybeVal) {
693 Err = MaybeVal.takeError();
694 return T{};
695 }
696 return *MaybeVal;
697 }
698
699 template<typename IIter, typename OIter>
700 Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
701 using ItemT = std::remove_reference_t<decltype(*Obegin)>;
702 for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
703 Expected<ItemT> ToOrErr = import(*Ibegin);
704 if (!ToOrErr)
705 return ToOrErr.takeError();
706 *Obegin = *ToOrErr;
707 }
708 return Error::success();
709 }
710
711 // Import every item from a container structure into an output container.
712 // If error occurs, stops at first error and returns the error.
713 // The output container should have space for all needed elements (it is not
714 // expanded, new items are put into from the beginning).
715 template<typename InContainerTy, typename OutContainerTy>
717 const InContainerTy &InContainer, OutContainerTy &OutContainer) {
718 return ImportArrayChecked(
719 InContainer.begin(), InContainer.end(), OutContainer.begin());
720 }
721
722 template<typename InContainerTy, typename OIter>
723 Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
724 return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
725 }
726
728 CXXMethodDecl *FromMethod);
729
731 FunctionDecl *FromFD);
732
733 // Returns true if the given function has a placeholder return type and
734 // that type is declared inside the body of the function.
735 // E.g. auto f() { struct X{}; return X(); }
737 };
738
739template <typename InContainerTy>
741 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
742 const InContainerTy &Container, TemplateArgumentListInfo &Result) {
743 auto ToLAngleLocOrErr = import(FromLAngleLoc);
744 if (!ToLAngleLocOrErr)
745 return ToLAngleLocOrErr.takeError();
746 auto ToRAngleLocOrErr = import(FromRAngleLoc);
747 if (!ToRAngleLocOrErr)
748 return ToRAngleLocOrErr.takeError();
749
750 TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr);
751 if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo))
752 return Err;
753 Result = ToTAInfo;
754 return Error::success();
755}
756
757template <>
758Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>(
761 From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result);
762}
763
764template <>
767 const ASTTemplateArgumentListInfo &From,
769 return ImportTemplateArgumentListInfo(
770 From.LAngleLoc, From.RAngleLoc, From.arguments(), Result);
771}
772
775 FunctionDecl *FromFD) {
776 assert(FromFD->getTemplatedKind() ==
778
780
781 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
782 if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate()))
783 return std::move(Err);
784
785 // Import template arguments.
786 if (Error Err = ImportTemplateArguments(FTSInfo->TemplateArguments->asArray(),
787 std::get<1>(Result)))
788 return std::move(Err);
789
790 return Result;
791}
792
793template <>
795ASTNodeImporter::import(TemplateParameterList *From) {
797 if (Error Err = ImportContainerChecked(*From, To))
798 return std::move(Err);
799
800 ExpectedExpr ToRequiresClause = import(From->getRequiresClause());
801 if (!ToRequiresClause)
802 return ToRequiresClause.takeError();
803
804 auto ToTemplateLocOrErr = import(From->getTemplateLoc());
805 if (!ToTemplateLocOrErr)
806 return ToTemplateLocOrErr.takeError();
807 auto ToLAngleLocOrErr = import(From->getLAngleLoc());
808 if (!ToLAngleLocOrErr)
809 return ToLAngleLocOrErr.takeError();
810 auto ToRAngleLocOrErr = import(From->getRAngleLoc());
811 if (!ToRAngleLocOrErr)
812 return ToRAngleLocOrErr.takeError();
813
815 Importer.getToContext(),
816 *ToTemplateLocOrErr,
817 *ToLAngleLocOrErr,
818 To,
819 *ToRAngleLocOrErr,
820 *ToRequiresClause);
821}
822
823template <>
825ASTNodeImporter::import(const TemplateArgument &From) {
826 switch (From.getKind()) {
828 return TemplateArgument();
829
831 ExpectedType ToTypeOrErr = import(From.getAsType());
832 if (!ToTypeOrErr)
833 return ToTypeOrErr.takeError();
834 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false,
835 From.getIsDefaulted());
836 }
837
839 ExpectedType ToTypeOrErr = import(From.getIntegralType());
840 if (!ToTypeOrErr)
841 return ToTypeOrErr.takeError();
842 return TemplateArgument(From, *ToTypeOrErr);
843 }
844
846 Expected<ValueDecl *> ToOrErr = import(From.getAsDecl());
847 if (!ToOrErr)
848 return ToOrErr.takeError();
849 ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
850 if (!ToTypeOrErr)
851 return ToTypeOrErr.takeError();
852 return TemplateArgument(dyn_cast<ValueDecl>((*ToOrErr)->getCanonicalDecl()),
853 *ToTypeOrErr, From.getIsDefaulted());
854 }
855
857 ExpectedType ToTypeOrErr = import(From.getNullPtrType());
858 if (!ToTypeOrErr)
859 return ToTypeOrErr.takeError();
860 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true,
861 From.getIsDefaulted());
862 }
863
865 ExpectedType ToTypeOrErr = import(From.getStructuralValueType());
866 if (!ToTypeOrErr)
867 return ToTypeOrErr.takeError();
868 Expected<APValue> ToValueOrErr = import(From.getAsStructuralValue());
869 if (!ToValueOrErr)
870 return ToValueOrErr.takeError();
871 return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
872 *ToValueOrErr);
873 }
874
876 Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
877 if (!ToTemplateOrErr)
878 return ToTemplateOrErr.takeError();
879
880 return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
881 }
882
884 Expected<TemplateName> ToTemplateOrErr =
885 import(From.getAsTemplateOrTemplatePattern());
886 if (!ToTemplateOrErr)
887 return ToTemplateOrErr.takeError();
888
889 return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(),
890 From.getIsDefaulted());
891 }
892
894 if (ExpectedExpr ToExpr = import(From.getAsExpr()))
895 return TemplateArgument(*ToExpr, From.getIsDefaulted());
896 else
897 return ToExpr.takeError();
898
901 ToPack.reserve(From.pack_size());
902 if (Error Err = ImportTemplateArguments(From.pack_elements(), ToPack))
903 return std::move(Err);
904
905 return TemplateArgument(
906 llvm::ArrayRef(ToPack).copy(Importer.getToContext()));
907 }
908 }
909
910 llvm_unreachable("Invalid template argument kind");
911}
912
913template <>
915ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) {
916 Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument());
917 if (!ArgOrErr)
918 return ArgOrErr.takeError();
919 TemplateArgument Arg = *ArgOrErr;
920
921 TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
922
925 ExpectedExpr E = import(FromInfo.getAsExpr());
926 if (!E)
927 return E.takeError();
928 ToInfo = TemplateArgumentLocInfo(*E);
929 } else if (Arg.getKind() == TemplateArgument::Type) {
930 if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo()))
931 ToInfo = TemplateArgumentLocInfo(*TSIOrErr);
932 else
933 return TSIOrErr.takeError();
934 } else {
935 auto ToTemplateQualifierLocOrErr =
936 import(FromInfo.getTemplateQualifierLoc());
937 if (!ToTemplateQualifierLocOrErr)
938 return ToTemplateQualifierLocOrErr.takeError();
939 auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc());
940 if (!ToTemplateNameLocOrErr)
941 return ToTemplateNameLocOrErr.takeError();
942 auto ToTemplateEllipsisLocOrErr =
943 import(FromInfo.getTemplateEllipsisLoc());
944 if (!ToTemplateEllipsisLocOrErr)
945 return ToTemplateEllipsisLocOrErr.takeError();
947 Importer.getToContext(), *ToTemplateQualifierLocOrErr,
948 *ToTemplateNameLocOrErr, *ToTemplateEllipsisLocOrErr);
949 }
950
951 return TemplateArgumentLoc(Arg, ToInfo);
952}
953
954template <>
955Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) {
956 if (DG.isNull())
957 return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
958 size_t NumDecls = DG.end() - DG.begin();
960 ToDecls.reserve(NumDecls);
961 for (Decl *FromD : DG) {
962 if (auto ToDOrErr = import(FromD))
963 ToDecls.push_back(*ToDOrErr);
964 else
965 return ToDOrErr.takeError();
966 }
967 return DeclGroupRef::Create(Importer.getToContext(),
968 ToDecls.begin(),
969 NumDecls);
970}
971
972template <>
974ASTNodeImporter::import(const Designator &D) {
975 if (D.isFieldDesignator()) {
976 IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
977
978 ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc());
979 if (!ToDotLocOrErr)
980 return ToDotLocOrErr.takeError();
981
982 ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc());
983 if (!ToFieldLocOrErr)
984 return ToFieldLocOrErr.takeError();
985
987 ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr);
988 }
989
990 ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc());
991 if (!ToLBracketLocOrErr)
992 return ToLBracketLocOrErr.takeError();
993
994 ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc());
995 if (!ToRBracketLocOrErr)
996 return ToRBracketLocOrErr.takeError();
997
998 if (D.isArrayDesignator())
999 return Designator::CreateArrayDesignator(D.getArrayIndex(),
1000 *ToLBracketLocOrErr,
1001 *ToRBracketLocOrErr);
1002
1003 ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc());
1004 if (!ToEllipsisLocOrErr)
1005 return ToEllipsisLocOrErr.takeError();
1006
1007 assert(D.isArrayRangeDesignator());
1009 D.getArrayIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr,
1010 *ToRBracketLocOrErr);
1011}
1012
1013template <>
1014Expected<ConceptReference *> ASTNodeImporter::import(ConceptReference *From) {
1015 Error Err = Error::success();
1016 auto ToNNS = importChecked(Err, From->getNestedNameSpecifierLoc());
1017 auto ToTemplateKWLoc = importChecked(Err, From->getTemplateKWLoc());
1018 auto ToConceptNameLoc =
1019 importChecked(Err, From->getConceptNameInfo().getLoc());
1020 auto ToConceptName = importChecked(Err, From->getConceptNameInfo().getName());
1021 auto ToFoundDecl = importChecked(Err, From->getFoundDecl());
1022 auto ToNamedConcept = importChecked(Err, From->getNamedConcept());
1023 if (Err)
1024 return std::move(Err);
1025 TemplateArgumentListInfo ToTAInfo;
1026 const auto *ASTTemplateArgs = From->getTemplateArgsAsWritten();
1027 if (ASTTemplateArgs)
1028 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
1029 return std::move(Err);
1030 auto *ConceptRef = ConceptReference::Create(
1031 Importer.getToContext(), ToNNS, ToTemplateKWLoc,
1032 DeclarationNameInfo(ToConceptName, ToConceptNameLoc), ToFoundDecl,
1033 ToNamedConcept,
1034 ASTTemplateArgs ? ASTTemplateArgumentListInfo::Create(
1035 Importer.getToContext(), ToTAInfo)
1036 : nullptr);
1037 return ConceptRef;
1038}
1039
1040template <>
1041Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) {
1042 ValueDecl *Var = nullptr;
1043 if (From.capturesVariable()) {
1044 if (auto VarOrErr = import(From.getCapturedVar()))
1045 Var = *VarOrErr;
1046 else
1047 return VarOrErr.takeError();
1048 }
1049
1050 auto LocationOrErr = import(From.getLocation());
1051 if (!LocationOrErr)
1052 return LocationOrErr.takeError();
1053
1054 SourceLocation EllipsisLoc;
1055 if (From.isPackExpansion())
1056 if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc()))
1057 return std::move(Err);
1058
1059 return LambdaCapture(
1060 *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var,
1061 EllipsisLoc);
1062}
1063
1064template <typename T>
1066 if (Found->getLinkageInternal() != From->getLinkageInternal())
1067 return false;
1068
1069 if (From->hasExternalFormalLinkage())
1070 return Found->hasExternalFormalLinkage();
1071 if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl())
1072 return false;
1073 if (From->isInAnonymousNamespace())
1074 return Found->isInAnonymousNamespace();
1075 else
1076 return !Found->isInAnonymousNamespace() &&
1077 !Found->hasExternalFormalLinkage();
1078}
1079
1080template <>
1082 TypedefNameDecl *From) {
1083 if (Found->getLinkageInternal() != From->getLinkageInternal())
1084 return false;
1085
1086 if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace())
1087 return Importer.GetFromTU(Found) == From->getTranslationUnitDecl();
1088 return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace();
1089}
1090
1091} // namespace clang
1092
1093//----------------------------------------------------------------------------
1094// Import Types
1095//----------------------------------------------------------------------------
1096
1097using namespace clang;
1098
1100 Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
1101 << T->getTypeClassName();
1102 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1103}
1104
1105ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
1106 ExpectedType UnderlyingTypeOrErr = import(T->getValueType());
1107 if (!UnderlyingTypeOrErr)
1108 return UnderlyingTypeOrErr.takeError();
1109
1110 return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr);
1111}
1112
1113ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
1114 switch (T->getKind()) {
1115#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1116 case BuiltinType::Id: \
1117 return Importer.getToContext().SingletonId;
1118#include "clang/Basic/OpenCLImageTypes.def"
1119#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1120 case BuiltinType::Id: \
1121 return Importer.getToContext().Id##Ty;
1122#include "clang/Basic/OpenCLExtensionTypes.def"
1123#define SVE_TYPE(Name, Id, SingletonId) \
1124 case BuiltinType::Id: \
1125 return Importer.getToContext().SingletonId;
1126#include "clang/Basic/AArch64SVEACLETypes.def"
1127#define PPC_VECTOR_TYPE(Name, Id, Size) \
1128 case BuiltinType::Id: \
1129 return Importer.getToContext().Id##Ty;
1130#include "clang/Basic/PPCTypes.def"
1131#define RVV_TYPE(Name, Id, SingletonId) \
1132 case BuiltinType::Id: \
1133 return Importer.getToContext().SingletonId;
1134#include "clang/Basic/RISCVVTypes.def"
1135#define WASM_TYPE(Name, Id, SingletonId) \
1136 case BuiltinType::Id: \
1137 return Importer.getToContext().SingletonId;
1138#include "clang/Basic/WebAssemblyReferenceTypes.def"
1139#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
1140 case BuiltinType::Id: \
1141 return Importer.getToContext().SingletonId;
1142#include "clang/Basic/AMDGPUTypes.def"
1143#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
1144 case BuiltinType::Id: \
1145 return Importer.getToContext().SingletonId;
1146#include "clang/Basic/HLSLIntangibleTypes.def"
1147#define SHARED_SINGLETON_TYPE(Expansion)
1148#define BUILTIN_TYPE(Id, SingletonId) \
1149 case BuiltinType::Id: return Importer.getToContext().SingletonId;
1150#include "clang/AST/BuiltinTypes.def"
1151
1152 // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
1153 // context supports C++.
1154
1155 // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
1156 // context supports ObjC.
1157
1158 case BuiltinType::Char_U:
1159 // The context we're importing from has an unsigned 'char'. If we're
1160 // importing into a context with a signed 'char', translate to
1161 // 'unsigned char' instead.
1162 if (Importer.getToContext().getLangOpts().CharIsSigned)
1163 return Importer.getToContext().UnsignedCharTy;
1164
1165 return Importer.getToContext().CharTy;
1166
1167 case BuiltinType::Char_S:
1168 // The context we're importing from has an unsigned 'char'. If we're
1169 // importing into a context with a signed 'char', translate to
1170 // 'unsigned char' instead.
1171 if (!Importer.getToContext().getLangOpts().CharIsSigned)
1172 return Importer.getToContext().SignedCharTy;
1173
1174 return Importer.getToContext().CharTy;
1175
1176 case BuiltinType::WChar_S:
1177 case BuiltinType::WChar_U:
1178 // FIXME: If not in C++, shall we translate to the C equivalent of
1179 // wchar_t?
1180 return Importer.getToContext().WCharTy;
1181 }
1182
1183 llvm_unreachable("Invalid BuiltinType Kind!");
1184}
1185
1186ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) {
1187 ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType());
1188 if (!ToOriginalTypeOrErr)
1189 return ToOriginalTypeOrErr.takeError();
1190
1191 return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr);
1192}
1193
1194ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) {
1195 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1196 if (!ToElementTypeOrErr)
1197 return ToElementTypeOrErr.takeError();
1198
1199 return Importer.getToContext().getComplexType(*ToElementTypeOrErr);
1200}
1201
1202ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) {
1203 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1204 if (!ToPointeeTypeOrErr)
1205 return ToPointeeTypeOrErr.takeError();
1206
1207 return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr);
1208}
1209
1210ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) {
1211 // FIXME: Check for blocks support in "to" context.
1212 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1213 if (!ToPointeeTypeOrErr)
1214 return ToPointeeTypeOrErr.takeError();
1215
1216 return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr);
1217}
1218
1220ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) {
1221 // FIXME: Check for C++ support in "to" context.
1222 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1223 if (!ToPointeeTypeOrErr)
1224 return ToPointeeTypeOrErr.takeError();
1225
1226 return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr);
1227}
1228
1230ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) {
1231 // FIXME: Check for C++0x support in "to" context.
1232 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1233 if (!ToPointeeTypeOrErr)
1234 return ToPointeeTypeOrErr.takeError();
1235
1236 return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr);
1237}
1238
1240ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) {
1241 // FIXME: Check for C++ support in "to" context.
1242 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1243 if (!ToPointeeTypeOrErr)
1244 return ToPointeeTypeOrErr.takeError();
1245
1246 ExpectedTypePtr ClassTypeOrErr = import(T->getClass());
1247 if (!ClassTypeOrErr)
1248 return ClassTypeOrErr.takeError();
1249
1250 return Importer.getToContext().getMemberPointerType(*ToPointeeTypeOrErr,
1251 *ClassTypeOrErr);
1252}
1253
1255ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) {
1256 Error Err = Error::success();
1257 auto ToElementType = importChecked(Err, T->getElementType());
1258 auto ToSizeExpr = importChecked(Err, T->getSizeExpr());
1259 if (Err)
1260 return std::move(Err);
1261
1262 return Importer.getToContext().getConstantArrayType(
1263 ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(),
1264 T->getIndexTypeCVRQualifiers());
1265}
1266
1268ASTNodeImporter::VisitArrayParameterType(const ArrayParameterType *T) {
1269 ExpectedType ToArrayTypeOrErr = VisitConstantArrayType(T);
1270 if (!ToArrayTypeOrErr)
1271 return ToArrayTypeOrErr.takeError();
1272
1273 return Importer.getToContext().getArrayParameterType(*ToArrayTypeOrErr);
1274}
1275
1277ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
1278 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1279 if (!ToElementTypeOrErr)
1280 return ToElementTypeOrErr.takeError();
1281
1282 return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr,
1283 T->getSizeModifier(),
1284 T->getIndexTypeCVRQualifiers());
1285}
1286
1288ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
1289 Error Err = Error::success();
1290 QualType ToElementType = importChecked(Err, T->getElementType());
1291 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1292 SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange());
1293 if (Err)
1294 return std::move(Err);
1295 return Importer.getToContext().getVariableArrayType(
1296 ToElementType, ToSizeExpr, T->getSizeModifier(),
1297 T->getIndexTypeCVRQualifiers(), ToBracketsRange);
1298}
1299
1300ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
1301 const DependentSizedArrayType *T) {
1302 Error Err = Error::success();
1303 QualType ToElementType = importChecked(Err, T->getElementType());
1304 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1305 SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange());
1306 if (Err)
1307 return std::move(Err);
1308 // SizeExpr may be null if size is not specified directly.
1309 // For example, 'int a[]'.
1310
1311 return Importer.getToContext().getDependentSizedArrayType(
1312 ToElementType, ToSizeExpr, T->getSizeModifier(),
1313 T->getIndexTypeCVRQualifiers(), ToBracketsRange);
1314}
1315
1316ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(
1318 Error Err = Error::success();
1319 QualType ToElementType = importChecked(Err, T->getElementType());
1320 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1321 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1322 if (Err)
1323 return std::move(Err);
1325 ToElementType, ToSizeExpr, ToAttrLoc);
1326}
1327
1328ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) {
1329 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1330 if (!ToElementTypeOrErr)
1331 return ToElementTypeOrErr.takeError();
1332
1333 return Importer.getToContext().getVectorType(*ToElementTypeOrErr,
1334 T->getNumElements(),
1335 T->getVectorKind());
1336}
1337
1338ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) {
1339 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1340 if (!ToElementTypeOrErr)
1341 return ToElementTypeOrErr.takeError();
1342
1343 return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr,
1344 T->getNumElements());
1345}
1346
1348ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1349 // FIXME: What happens if we're importing a function without a prototype
1350 // into C++? Should we make it variadic?
1351 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1352 if (!ToReturnTypeOrErr)
1353 return ToReturnTypeOrErr.takeError();
1354
1355 return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr,
1356 T->getExtInfo());
1357}
1358
1360ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
1361 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1362 if (!ToReturnTypeOrErr)
1363 return ToReturnTypeOrErr.takeError();
1364
1365 // Import argument types
1366 SmallVector<QualType, 4> ArgTypes;
1367 for (const auto &A : T->param_types()) {
1368 ExpectedType TyOrErr = import(A);
1369 if (!TyOrErr)
1370 return TyOrErr.takeError();
1371 ArgTypes.push_back(*TyOrErr);
1372 }
1373
1374 // Import exception types
1375 SmallVector<QualType, 4> ExceptionTypes;
1376 for (const auto &E : T->exceptions()) {
1377 ExpectedType TyOrErr = import(E);
1378 if (!TyOrErr)
1379 return TyOrErr.takeError();
1380 ExceptionTypes.push_back(*TyOrErr);
1381 }
1382
1384 Error Err = Error::success();
1386 ToEPI.ExtInfo = FromEPI.ExtInfo;
1387 ToEPI.Variadic = FromEPI.Variadic;
1388 ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
1389 ToEPI.TypeQuals = FromEPI.TypeQuals;
1390 ToEPI.RefQualifier = FromEPI.RefQualifier;
1391 ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
1398 ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
1399
1400 if (Err)
1401 return std::move(Err);
1402
1403 return Importer.getToContext().getFunctionType(
1404 *ToReturnTypeOrErr, ArgTypes, ToEPI);
1405}
1406
1407ExpectedType ASTNodeImporter::VisitUnresolvedUsingType(
1408 const UnresolvedUsingType *T) {
1409 Error Err = Error::success();
1410 auto ToD = importChecked(Err, T->getDecl());
1411 auto ToPrevD = importChecked(Err, T->getDecl()->getPreviousDecl());
1412 if (Err)
1413 return std::move(Err);
1414
1415 return Importer.getToContext().getTypeDeclType(
1416 ToD, cast_or_null<TypeDecl>(ToPrevD));
1417}
1418
1419ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) {
1420 ExpectedType ToInnerTypeOrErr = import(T->getInnerType());
1421 if (!ToInnerTypeOrErr)
1422 return ToInnerTypeOrErr.takeError();
1423
1424 return Importer.getToContext().getParenType(*ToInnerTypeOrErr);
1425}
1426
1428ASTNodeImporter::VisitPackIndexingType(clang::PackIndexingType const *T) {
1429
1430 ExpectedType Pattern = import(T->getPattern());
1431 if (!Pattern)
1432 return Pattern.takeError();
1433 ExpectedExpr Index = import(T->getIndexExpr());
1434 if (!Index)
1435 return Index.takeError();
1436 return Importer.getToContext().getPackIndexingType(*Pattern, *Index);
1437}
1438
1439ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) {
1440 Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl());
1441 if (!ToDeclOrErr)
1442 return ToDeclOrErr.takeError();
1443
1444 TypedefNameDecl *ToDecl = *ToDeclOrErr;
1445 if (ToDecl->getTypeForDecl())
1446 return QualType(ToDecl->getTypeForDecl(), 0);
1447
1448 ExpectedType ToUnderlyingTypeOrErr = import(T->desugar());
1449 if (!ToUnderlyingTypeOrErr)
1450 return ToUnderlyingTypeOrErr.takeError();
1451
1452 return Importer.getToContext().getTypedefType(ToDecl, *ToUnderlyingTypeOrErr);
1453}
1454
1455ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {
1456 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1457 if (!ToExprOrErr)
1458 return ToExprOrErr.takeError();
1459 return Importer.getToContext().getTypeOfExprType(*ToExprOrErr, T->getKind());
1460}
1461
1462ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
1463 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnmodifiedType());
1464 if (!ToUnderlyingTypeOrErr)
1465 return ToUnderlyingTypeOrErr.takeError();
1466 return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr,
1467 T->getKind());
1468}
1469
1470ExpectedType ASTNodeImporter::VisitUsingType(const UsingType *T) {
1471 Expected<UsingShadowDecl *> FoundOrErr = import(T->getFoundDecl());
1472 if (!FoundOrErr)
1473 return FoundOrErr.takeError();
1474 Expected<QualType> UnderlyingOrErr = import(T->getUnderlyingType());
1475 if (!UnderlyingOrErr)
1476 return UnderlyingOrErr.takeError();
1477
1478 return Importer.getToContext().getUsingType(*FoundOrErr, *UnderlyingOrErr);
1479}
1480
1481ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) {
1482 // FIXME: Make sure that the "to" context supports C++0x!
1483 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1484 if (!ToExprOrErr)
1485 return ToExprOrErr.takeError();
1486
1487 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1488 if (!ToUnderlyingTypeOrErr)
1489 return ToUnderlyingTypeOrErr.takeError();
1490
1491 return Importer.getToContext().getDecltypeType(
1492 *ToExprOrErr, *ToUnderlyingTypeOrErr);
1493}
1494
1496ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) {
1497 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1498 if (!ToBaseTypeOrErr)
1499 return ToBaseTypeOrErr.takeError();
1500
1501 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1502 if (!ToUnderlyingTypeOrErr)
1503 return ToUnderlyingTypeOrErr.takeError();
1504
1505 return Importer.getToContext().getUnaryTransformType(
1506 *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind());
1507}
1508
1509ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) {
1510 // FIXME: Make sure that the "to" context supports C++11!
1511 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1512 if (!ToDeducedTypeOrErr)
1513 return ToDeducedTypeOrErr.takeError();
1514
1515 ExpectedDecl ToTypeConstraintConcept = import(T->getTypeConstraintConcept());
1516 if (!ToTypeConstraintConcept)
1517 return ToTypeConstraintConcept.takeError();
1518
1519 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1520 if (Error Err = ImportTemplateArguments(T->getTypeConstraintArguments(),
1521 ToTemplateArgs))
1522 return std::move(Err);
1523
1524 return Importer.getToContext().getAutoType(
1525 *ToDeducedTypeOrErr, T->getKeyword(), /*IsDependent*/false,
1526 /*IsPack=*/false, cast_or_null<ConceptDecl>(*ToTypeConstraintConcept),
1527 ToTemplateArgs);
1528}
1529
1530ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType(
1532 // FIXME: Make sure that the "to" context supports C++17!
1533 Expected<TemplateName> ToTemplateNameOrErr = import(T->getTemplateName());
1534 if (!ToTemplateNameOrErr)
1535 return ToTemplateNameOrErr.takeError();
1536 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1537 if (!ToDeducedTypeOrErr)
1538 return ToDeducedTypeOrErr.takeError();
1539
1541 *ToTemplateNameOrErr, *ToDeducedTypeOrErr, T->isDependentType());
1542}
1543
1544ExpectedType ASTNodeImporter::VisitInjectedClassNameType(
1545 const InjectedClassNameType *T) {
1546 Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl());
1547 if (!ToDeclOrErr)
1548 return ToDeclOrErr.takeError();
1549
1550 // The InjectedClassNameType is created in VisitRecordDecl when the
1551 // T->getDecl() is imported. Here we can return the existing type.
1552 const Type *Ty = (*ToDeclOrErr)->getTypeForDecl();
1553 assert(isa_and_nonnull<InjectedClassNameType>(Ty));
1554 return QualType(Ty, 0);
1555}
1556
1557ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) {
1558 Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl());
1559 if (!ToDeclOrErr)
1560 return ToDeclOrErr.takeError();
1561
1562 return Importer.getToContext().getTagDeclType(*ToDeclOrErr);
1563}
1564
1565ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) {
1566 Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl());
1567 if (!ToDeclOrErr)
1568 return ToDeclOrErr.takeError();
1569
1570 return Importer.getToContext().getTagDeclType(*ToDeclOrErr);
1571}
1572
1573ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) {
1574 ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType());
1575 if (!ToModifiedTypeOrErr)
1576 return ToModifiedTypeOrErr.takeError();
1577 ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType());
1578 if (!ToEquivalentTypeOrErr)
1579 return ToEquivalentTypeOrErr.takeError();
1580
1581 return Importer.getToContext().getAttributedType(
1582 T->getAttrKind(), *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr,
1583 T->getAttr());
1584}
1585
1587ASTNodeImporter::VisitCountAttributedType(const CountAttributedType *T) {
1588 ExpectedType ToWrappedTypeOrErr = import(T->desugar());
1589 if (!ToWrappedTypeOrErr)
1590 return ToWrappedTypeOrErr.takeError();
1591
1592 Error Err = Error::success();
1593 Expr *CountExpr = importChecked(Err, T->getCountExpr());
1594
1596 for (const TypeCoupledDeclRefInfo &TI : T->dependent_decls()) {
1597 Expected<ValueDecl *> ToDeclOrErr = import(TI.getDecl());
1598 if (!ToDeclOrErr)
1599 return ToDeclOrErr.takeError();
1600 CoupledDecls.emplace_back(*ToDeclOrErr, TI.isDeref());
1601 }
1602
1603 return Importer.getToContext().getCountAttributedType(
1604 *ToWrappedTypeOrErr, CountExpr, T->isCountInBytes(), T->isOrNull(),
1605 ArrayRef(CoupledDecls.data(), CoupledDecls.size()));
1606}
1607
1608ExpectedType ASTNodeImporter::VisitTemplateTypeParmType(
1609 const TemplateTypeParmType *T) {
1610 Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl());
1611 if (!ToDeclOrErr)
1612 return ToDeclOrErr.takeError();
1613
1614 return Importer.getToContext().getTemplateTypeParmType(
1615 T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr);
1616}
1617
1618ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType(
1620 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1621 if (!ReplacedOrErr)
1622 return ReplacedOrErr.takeError();
1623
1624 ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType());
1625 if (!ToReplacementTypeOrErr)
1626 return ToReplacementTypeOrErr.takeError();
1627
1629 *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex(), T->getPackIndex(),
1630 T->getSubstitutionFlag());
1631}
1632
1633ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
1635 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1636 if (!ReplacedOrErr)
1637 return ReplacedOrErr.takeError();
1638
1639 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1640 if (!ToArgumentPack)
1641 return ToArgumentPack.takeError();
1642
1644 *ReplacedOrErr, T->getIndex(), T->getFinal(), *ToArgumentPack);
1645}
1646
1647ExpectedType ASTNodeImporter::VisitTemplateSpecializationType(
1649 auto ToTemplateOrErr = import(T->getTemplateName());
1650 if (!ToTemplateOrErr)
1651 return ToTemplateOrErr.takeError();
1652
1653 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1654 if (Error Err =
1655 ImportTemplateArguments(T->template_arguments(), ToTemplateArgs))
1656 return std::move(Err);
1657
1658 QualType ToCanonType;
1659 if (!T->isCanonicalUnqualified()) {
1660 QualType FromCanonType
1661 = Importer.getFromContext().getCanonicalType(QualType(T, 0));
1662 if (ExpectedType TyOrErr = import(FromCanonType))
1663 ToCanonType = *TyOrErr;
1664 else
1665 return TyOrErr.takeError();
1666 }
1667 return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr,
1668 ToTemplateArgs,
1669 ToCanonType);
1670}
1671
1672ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) {
1673 // Note: the qualifier in an ElaboratedType is optional.
1674 auto ToQualifierOrErr = import(T->getQualifier());
1675 if (!ToQualifierOrErr)
1676 return ToQualifierOrErr.takeError();
1677
1678 ExpectedType ToNamedTypeOrErr = import(T->getNamedType());
1679 if (!ToNamedTypeOrErr)
1680 return ToNamedTypeOrErr.takeError();
1681
1682 Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl());
1683 if (!ToOwnedTagDeclOrErr)
1684 return ToOwnedTagDeclOrErr.takeError();
1685
1686 return Importer.getToContext().getElaboratedType(T->getKeyword(),
1687 *ToQualifierOrErr,
1688 *ToNamedTypeOrErr,
1689 *ToOwnedTagDeclOrErr);
1690}
1691
1693ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) {
1694 ExpectedType ToPatternOrErr = import(T->getPattern());
1695 if (!ToPatternOrErr)
1696 return ToPatternOrErr.takeError();
1697
1698 return Importer.getToContext().getPackExpansionType(*ToPatternOrErr,
1699 T->getNumExpansions(),
1700 /*ExpactPack=*/false);
1701}
1702
1703ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType(
1705 auto ToQualifierOrErr = import(T->getQualifier());
1706 if (!ToQualifierOrErr)
1707 return ToQualifierOrErr.takeError();
1708
1709 IdentifierInfo *ToName = Importer.Import(T->getIdentifier());
1710
1712 ToPack.reserve(T->template_arguments().size());
1713 if (Error Err = ImportTemplateArguments(T->template_arguments(), ToPack))
1714 return std::move(Err);
1715
1717 T->getKeyword(), *ToQualifierOrErr, ToName, ToPack);
1718}
1719
1721ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) {
1722 auto ToQualifierOrErr = import(T->getQualifier());
1723 if (!ToQualifierOrErr)
1724 return ToQualifierOrErr.takeError();
1725
1726 IdentifierInfo *Name = Importer.Import(T->getIdentifier());
1727
1728 QualType Canon;
1729 if (T != T->getCanonicalTypeInternal().getTypePtr()) {
1730 if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal()))
1731 Canon = (*TyOrErr).getCanonicalType();
1732 else
1733 return TyOrErr.takeError();
1734 }
1735
1736 return Importer.getToContext().getDependentNameType(T->getKeyword(),
1737 *ToQualifierOrErr,
1738 Name, Canon);
1739}
1740
1742ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1743 Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl());
1744 if (!ToDeclOrErr)
1745 return ToDeclOrErr.takeError();
1746
1747 return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr);
1748}
1749
1750ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) {
1751 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1752 if (!ToBaseTypeOrErr)
1753 return ToBaseTypeOrErr.takeError();
1754
1755 SmallVector<QualType, 4> TypeArgs;
1756 for (auto TypeArg : T->getTypeArgsAsWritten()) {
1757 if (ExpectedType TyOrErr = import(TypeArg))
1758 TypeArgs.push_back(*TyOrErr);
1759 else
1760 return TyOrErr.takeError();
1761 }
1762
1764 for (auto *P : T->quals()) {
1765 if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P))
1766 Protocols.push_back(*ProtocolOrErr);
1767 else
1768 return ProtocolOrErr.takeError();
1769
1770 }
1771
1772 return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs,
1773 Protocols,
1774 T->isKindOfTypeAsWritten());
1775}
1776
1778ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1779 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1780 if (!ToPointeeTypeOrErr)
1781 return ToPointeeTypeOrErr.takeError();
1782
1783 return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
1784}
1785
1787ASTNodeImporter::VisitMacroQualifiedType(const MacroQualifiedType *T) {
1788 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1789 if (!ToUnderlyingTypeOrErr)
1790 return ToUnderlyingTypeOrErr.takeError();
1791
1792 IdentifierInfo *ToIdentifier = Importer.Import(T->getMacroIdentifier());
1793 return Importer.getToContext().getMacroQualifiedType(*ToUnderlyingTypeOrErr,
1794 ToIdentifier);
1795}
1796
1797ExpectedType clang::ASTNodeImporter::VisitAdjustedType(const AdjustedType *T) {
1798 Error Err = Error::success();
1799 QualType ToOriginalType = importChecked(Err, T->getOriginalType());
1800 QualType ToAdjustedType = importChecked(Err, T->getAdjustedType());
1801 if (Err)
1802 return std::move(Err);
1803
1804 return Importer.getToContext().getAdjustedType(ToOriginalType,
1805 ToAdjustedType);
1806}
1807
1808ExpectedType clang::ASTNodeImporter::VisitBitIntType(const BitIntType *T) {
1809 return Importer.getToContext().getBitIntType(T->isUnsigned(),
1810 T->getNumBits());
1811}
1812
1813ExpectedType clang::ASTNodeImporter::VisitBTFTagAttributedType(
1815 Error Err = Error::success();
1816 const BTFTypeTagAttr *ToBTFAttr = importChecked(Err, T->getAttr());
1817 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
1818 if (Err)
1819 return std::move(Err);
1820
1821 return Importer.getToContext().getBTFTagAttributedType(ToBTFAttr,
1822 ToWrappedType);
1823}
1824
1825ExpectedType clang::ASTNodeImporter::VisitHLSLAttributedResourceType(
1827 Error Err = Error::success();
1828 const HLSLAttributedResourceType::Attributes &ToAttrs = T->getAttrs();
1829 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
1830 QualType ToContainedType = importChecked(Err, T->getContainedType());
1831 if (Err)
1832 return std::move(Err);
1833
1834 return Importer.getToContext().getHLSLAttributedResourceType(
1835 ToWrappedType, ToContainedType, ToAttrs);
1836}
1837
1838ExpectedType clang::ASTNodeImporter::VisitConstantMatrixType(
1840 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1841 if (!ToElementTypeOrErr)
1842 return ToElementTypeOrErr.takeError();
1843
1844 return Importer.getToContext().getConstantMatrixType(
1845 *ToElementTypeOrErr, T->getNumRows(), T->getNumColumns());
1846}
1847
1848ExpectedType clang::ASTNodeImporter::VisitDependentAddressSpaceType(
1850 Error Err = Error::success();
1851 QualType ToPointeeType = importChecked(Err, T->getPointeeType());
1852 Expr *ToAddrSpaceExpr = importChecked(Err, T->getAddrSpaceExpr());
1853 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1854 if (Err)
1855 return std::move(Err);
1856
1857 return Importer.getToContext().getDependentAddressSpaceType(
1858 ToPointeeType, ToAddrSpaceExpr, ToAttrLoc);
1859}
1860
1861ExpectedType clang::ASTNodeImporter::VisitDependentBitIntType(
1863 ExpectedExpr ToNumBitsExprOrErr = import(T->getNumBitsExpr());
1864 if (!ToNumBitsExprOrErr)
1865 return ToNumBitsExprOrErr.takeError();
1866 return Importer.getToContext().getDependentBitIntType(T->isUnsigned(),
1867 *ToNumBitsExprOrErr);
1868}
1869
1870ExpectedType clang::ASTNodeImporter::VisitDependentSizedMatrixType(
1872 Error Err = Error::success();
1873 QualType ToElementType = importChecked(Err, T->getElementType());
1874 Expr *ToRowExpr = importChecked(Err, T->getRowExpr());
1875 Expr *ToColumnExpr = importChecked(Err, T->getColumnExpr());
1876 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1877 if (Err)
1878 return std::move(Err);
1879
1880 return Importer.getToContext().getDependentSizedMatrixType(
1881 ToElementType, ToRowExpr, ToColumnExpr, ToAttrLoc);
1882}
1883
1884ExpectedType clang::ASTNodeImporter::VisitDependentVectorType(
1886 Error Err = Error::success();
1887 QualType ToElementType = importChecked(Err, T->getElementType());
1888 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1889 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1890 if (Err)
1891 return std::move(Err);
1892
1893 return Importer.getToContext().getDependentVectorType(
1894 ToElementType, ToSizeExpr, ToAttrLoc, T->getVectorKind());
1895}
1896
1897ExpectedType clang::ASTNodeImporter::VisitObjCTypeParamType(
1898 const clang::ObjCTypeParamType *T) {
1899 Expected<ObjCTypeParamDecl *> ToDeclOrErr = import(T->getDecl());
1900 if (!ToDeclOrErr)
1901 return ToDeclOrErr.takeError();
1902
1904 for (ObjCProtocolDecl *FromProtocol : T->getProtocols()) {
1905 Expected<ObjCProtocolDecl *> ToProtocolOrErr = import(FromProtocol);
1906 if (!ToProtocolOrErr)
1907 return ToProtocolOrErr.takeError();
1908 ToProtocols.push_back(*ToProtocolOrErr);
1909 }
1910
1911 return Importer.getToContext().getObjCTypeParamType(*ToDeclOrErr,
1912 ToProtocols);
1913}
1914
1915ExpectedType clang::ASTNodeImporter::VisitPipeType(const clang::PipeType *T) {
1916 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1917 if (!ToElementTypeOrErr)
1918 return ToElementTypeOrErr.takeError();
1919
1920 ASTContext &ToCtx = Importer.getToContext();
1921 if (T->isReadOnly())
1922 return ToCtx.getReadPipeType(*ToElementTypeOrErr);
1923 else
1924 return ToCtx.getWritePipeType(*ToElementTypeOrErr);
1925}
1926
1927//----------------------------------------------------------------------------
1928// Import Declarations
1929//----------------------------------------------------------------------------
1931 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
1933 // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop.
1934 // example: int struct_in_proto(struct data_t{int a;int b;} *d);
1935 // FIXME: We could support these constructs by importing a different type of
1936 // this parameter and by importing the original type of the parameter only
1937 // after the FunctionDecl is created. See
1938 // VisitFunctionDecl::UsedDifferentProtoType.
1939 DeclContext *OrigDC = D->getDeclContext();
1940 FunctionDecl *FunDecl;
1941 if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) &&
1942 FunDecl->hasBody()) {
1943 auto getLeafPointeeType = [](const Type *T) {
1944 while (T->isPointerType() || T->isArrayType()) {
1946 }
1947 return T;
1948 };
1949 for (const ParmVarDecl *P : FunDecl->parameters()) {
1950 const Type *LeafT =
1951 getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
1952 auto *RT = dyn_cast<RecordType>(LeafT);
1953 if (RT && RT->getDecl() == D) {
1954 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
1955 << D->getDeclKindName();
1956 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1957 }
1958 }
1959 }
1960
1961 // Import the context of this declaration.
1962 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
1963 return Err;
1964
1965 // Import the name of this declaration.
1966 if (Error Err = importInto(Name, D->getDeclName()))
1967 return Err;
1968
1969 // Import the location of this declaration.
1970 if (Error Err = importInto(Loc, D->getLocation()))
1971 return Err;
1972
1973 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
1974 if (ToD)
1975 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
1976 return Err;
1977
1978 return Error::success();
1979}
1980
1982 NamedDecl *&ToD, SourceLocation &Loc) {
1983
1984 // Import the name of this declaration.
1985 if (Error Err = importInto(Name, D->getDeclName()))
1986 return Err;
1987
1988 // Import the location of this declaration.
1989 if (Error Err = importInto(Loc, D->getLocation()))
1990 return Err;
1991
1992 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
1993 if (ToD)
1994 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
1995 return Err;
1996
1997 return Error::success();
1998}
1999
2001 if (!FromD)
2002 return Error::success();
2003
2004 if (!ToD)
2005 if (Error Err = importInto(ToD, FromD))
2006 return Err;
2007
2008 if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
2009 if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) {
2010 if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() &&
2011 !ToRecord->getDefinition()) {
2012 if (Error Err = ImportDefinition(FromRecord, ToRecord))
2013 return Err;
2014 }
2015 }
2016 return Error::success();
2017 }
2018
2019 if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
2020 if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) {
2021 if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
2022 if (Error Err = ImportDefinition(FromEnum, ToEnum))
2023 return Err;
2024 }
2025 }
2026 return Error::success();
2027 }
2028
2029 return Error::success();
2030}
2031
2032Error
2034 const DeclarationNameInfo &From, DeclarationNameInfo& To) {
2035 // NOTE: To.Name and To.Loc are already imported.
2036 // We only have to import To.LocInfo.
2037 switch (To.getName().getNameKind()) {
2044 return Error::success();
2045
2047 if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange()))
2048 To.setCXXOperatorNameRange(*ToRangeOrErr);
2049 else
2050 return ToRangeOrErr.takeError();
2051 return Error::success();
2052 }
2054 if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc()))
2055 To.setCXXLiteralOperatorNameLoc(*LocOrErr);
2056 else
2057 return LocOrErr.takeError();
2058 return Error::success();
2059 }
2063 if (auto ToTInfoOrErr = import(From.getNamedTypeInfo()))
2064 To.setNamedTypeInfo(*ToTInfoOrErr);
2065 else
2066 return ToTInfoOrErr.takeError();
2067 return Error::success();
2068 }
2069 }
2070 llvm_unreachable("Unknown name kind.");
2071}
2072
2073Error
2075 if (Importer.isMinimalImport() && !ForceImport) {
2076 auto ToDCOrErr = Importer.ImportContext(FromDC);
2077 return ToDCOrErr.takeError();
2078 }
2079
2080 // We use strict error handling in case of records and enums, but not
2081 // with e.g. namespaces.
2082 //
2083 // FIXME Clients of the ASTImporter should be able to choose an
2084 // appropriate error handling strategy for their needs. For instance,
2085 // they may not want to mark an entire namespace as erroneous merely
2086 // because there is an ODR error with two typedefs. As another example,
2087 // the client may allow EnumConstantDecls with same names but with
2088 // different values in two distinct translation units.
2089 ChildErrorHandlingStrategy HandleChildErrors(FromDC);
2090
2091 auto MightNeedReordering = [](const Decl *D) {
2092 return isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<FriendDecl>(D);
2093 };
2094
2095 // Import everything that might need reordering first.
2096 Error ChildErrors = Error::success();
2097 for (auto *From : FromDC->decls()) {
2098 if (!MightNeedReordering(From))
2099 continue;
2100
2101 ExpectedDecl ImportedOrErr = import(From);
2102
2103 // If we are in the process of ImportDefinition(...) for a RecordDecl we
2104 // want to make sure that we are also completing each FieldDecl. There
2105 // are currently cases where this does not happen and this is correctness
2106 // fix since operations such as code generation will expect this to be so.
2107 if (!ImportedOrErr) {
2108 HandleChildErrors.handleChildImportResult(ChildErrors,
2109 ImportedOrErr.takeError());
2110 continue;
2111 }
2112 FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
2113 Decl *ImportedDecl = *ImportedOrErr;
2114 FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
2115 if (FieldFrom && FieldTo) {
2116 Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
2117 HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
2118 }
2119 }
2120
2121 // We reorder declarations in RecordDecls because they may have another order
2122 // in the "to" context than they have in the "from" context. This may happen
2123 // e.g when we import a class like this:
2124 // struct declToImport {
2125 // int a = c + b;
2126 // int b = 1;
2127 // int c = 2;
2128 // };
2129 // During the import of `a` we import first the dependencies in sequence,
2130 // thus the order would be `c`, `b`, `a`. We will get the normal order by
2131 // first removing the already imported members and then adding them in the
2132 // order as they appear in the "from" context.
2133 //
2134 // Keeping field order is vital because it determines structure layout.
2135 //
2136 // Here and below, we cannot call field_begin() method and its callers on
2137 // ToDC if it has an external storage. Calling field_begin() will
2138 // automatically load all the fields by calling
2139 // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would
2140 // call ASTImporter::Import(). This is because the ExternalASTSource
2141 // interface in LLDB is implemented by the means of the ASTImporter. However,
2142 // calling an import at this point would result in an uncontrolled import, we
2143 // must avoid that.
2144
2145 auto ToDCOrErr = Importer.ImportContext(FromDC);
2146 if (!ToDCOrErr) {
2147 consumeError(std::move(ChildErrors));
2148 return ToDCOrErr.takeError();
2149 }
2150
2151 if (const auto *FromRD = dyn_cast<RecordDecl>(FromDC)) {
2152 DeclContext *ToDC = *ToDCOrErr;
2153 // Remove all declarations, which may be in wrong order in the
2154 // lexical DeclContext and then add them in the proper order.
2155 for (auto *D : FromRD->decls()) {
2156 if (!MightNeedReordering(D))
2157 continue;
2158
2159 assert(D && "DC contains a null decl");
2160 if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
2161 // Remove only the decls which we successfully imported.
2162 assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
2163 // Remove the decl from its wrong place in the linked list.
2164 ToDC->removeDecl(ToD);
2165 // Add the decl to the end of the linked list.
2166 // This time it will be at the proper place because the enclosing for
2167 // loop iterates in the original (good) order of the decls.
2168 ToDC->addDeclInternal(ToD);
2169 }
2170 }
2171 }
2172
2173 // Import everything else.
2174 for (auto *From : FromDC->decls()) {
2175 if (MightNeedReordering(From))
2176 continue;
2177
2178 ExpectedDecl ImportedOrErr = import(From);
2179 if (!ImportedOrErr)
2180 HandleChildErrors.handleChildImportResult(ChildErrors,
2181 ImportedOrErr.takeError());
2182 }
2183
2184 return ChildErrors;
2185}
2186
2188 const FieldDecl *To) {
2189 RecordDecl *FromRecordDecl = nullptr;
2190 RecordDecl *ToRecordDecl = nullptr;
2191 // If we have a field that is an ArrayType we need to check if the array
2192 // element is a RecordDecl and if so we need to import the definition.
2193 QualType FromType = From->getType();
2194 QualType ToType = To->getType();
2195 if (FromType->isArrayType()) {
2196 // getBaseElementTypeUnsafe(...) handles multi-dimensonal arrays for us.
2197 FromRecordDecl = FromType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2198 ToRecordDecl = ToType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2199 }
2200
2201 if (!FromRecordDecl || !ToRecordDecl) {
2202 const RecordType *RecordFrom = FromType->getAs<RecordType>();
2203 const RecordType *RecordTo = ToType->getAs<RecordType>();
2204
2205 if (RecordFrom && RecordTo) {
2206 FromRecordDecl = RecordFrom->getDecl();
2207 ToRecordDecl = RecordTo->getDecl();
2208 }
2209 }
2210
2211 if (FromRecordDecl && ToRecordDecl) {
2212 if (FromRecordDecl->isCompleteDefinition() &&
2213 !ToRecordDecl->isCompleteDefinition())
2214 return ImportDefinition(FromRecordDecl, ToRecordDecl);
2215 }
2216
2217 return Error::success();
2218}
2219
2221 Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) {
2222 auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext());
2223 if (!ToDCOrErr)
2224 return ToDCOrErr.takeError();
2225 ToDC = *ToDCOrErr;
2226
2227 if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) {
2228 auto ToLexicalDCOrErr = Importer.ImportContext(
2229 FromD->getLexicalDeclContext());
2230 if (!ToLexicalDCOrErr)
2231 return ToLexicalDCOrErr.takeError();
2232 ToLexicalDC = *ToLexicalDCOrErr;
2233 } else
2234 ToLexicalDC = ToDC;
2235
2236 return Error::success();
2237}
2238
2240 const CXXRecordDecl *From, CXXRecordDecl *To) {
2241 assert(From->isCompleteDefinition() && To->getDefinition() == To &&
2242 "Import implicit methods to or from non-definition");
2243
2244 for (CXXMethodDecl *FromM : From->methods())
2245 if (FromM->isImplicit()) {
2246 Expected<CXXMethodDecl *> ToMOrErr = import(FromM);
2247 if (!ToMOrErr)
2248 return ToMOrErr.takeError();
2249 }
2250
2251 return Error::success();
2252}
2253
2255 ASTImporter &Importer) {
2256 if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
2257 if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef))
2258 To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr));
2259 else
2260 return ToTypedefOrErr.takeError();
2261 }
2262 return Error::success();
2263}
2264
2266 RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) {
2267 auto DefinitionCompleter = [To]() {
2268 // There are cases in LLDB when we first import a class without its
2269 // members. The class will have DefinitionData, but no members. Then,
2270 // importDefinition is called from LLDB, which tries to get the members, so
2271 // when we get here, the class already has the DefinitionData set, so we
2272 // must unset the CompleteDefinition here to be able to complete again the
2273 // definition.
2274 To->setCompleteDefinition(false);
2275 To->completeDefinition();
2276 };
2277
2278 if (To->getDefinition() || To->isBeingDefined()) {
2279 if (Kind == IDK_Everything ||
2280 // In case of lambdas, the class already has a definition ptr set, but
2281 // the contained decls are not imported yet. Also, isBeingDefined was
2282 // set in CXXRecordDecl::CreateLambda. We must import the contained
2283 // decls here and finish the definition.
2284 (To->isLambda() && shouldForceImportDeclContext(Kind))) {
2285 if (To->isLambda()) {
2286 auto *FromCXXRD = cast<CXXRecordDecl>(From);
2288 ToCaptures.reserve(FromCXXRD->capture_size());
2289 for (const auto &FromCapture : FromCXXRD->captures()) {
2290 if (auto ToCaptureOrErr = import(FromCapture))
2291 ToCaptures.push_back(*ToCaptureOrErr);
2292 else
2293 return ToCaptureOrErr.takeError();
2294 }
2295 cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(),
2296 ToCaptures);
2297 }
2298
2299 Error Result = ImportDeclContext(From, /*ForceImport=*/true);
2300 // Finish the definition of the lambda, set isBeingDefined to false.
2301 if (To->isLambda())
2302 DefinitionCompleter();
2303 return Result;
2304 }
2305
2306 return Error::success();
2307 }
2308
2309 To->startDefinition();
2310 // Set the definition to complete even if it is really not complete during
2311 // import. Some AST constructs (expressions) require the record layout
2312 // to be calculated (see 'clang::computeDependence') at the time they are
2313 // constructed. Import of such AST node is possible during import of the
2314 // same record, there is no way to have a completely defined record (all
2315 // fields imported) at that time without multiple AST import passes.
2316 if (!Importer.isMinimalImport())
2317 To->setCompleteDefinition(true);
2318 // Complete the definition even if error is returned.
2319 // The RecordDecl may be already part of the AST so it is better to
2320 // have it in complete state even if something is wrong with it.
2321 auto DefinitionCompleterScopeExit =
2322 llvm::make_scope_exit(DefinitionCompleter);
2323
2324 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2325 return Err;
2326
2327 // Add base classes.
2328 auto *ToCXX = dyn_cast<CXXRecordDecl>(To);
2329 auto *FromCXX = dyn_cast<CXXRecordDecl>(From);
2330 if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) {
2331
2332 struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
2333 struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2334
2335 #define FIELD(Name, Width, Merge) \
2336 ToData.Name = FromData.Name;
2337 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2338
2339 // Copy over the data stored in RecordDeclBits
2340 ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions());
2341
2343 for (const auto &Base1 : FromCXX->bases()) {
2344 ExpectedType TyOrErr = import(Base1.getType());
2345 if (!TyOrErr)
2346 return TyOrErr.takeError();
2347
2348 SourceLocation EllipsisLoc;
2349 if (Base1.isPackExpansion()) {
2350 if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc()))
2351 EllipsisLoc = *LocOrErr;
2352 else
2353 return LocOrErr.takeError();
2354 }
2355
2356 // Ensure that we have a definition for the base.
2357 if (Error Err =
2358 ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
2359 return Err;
2360
2361 auto RangeOrErr = import(Base1.getSourceRange());
2362 if (!RangeOrErr)
2363 return RangeOrErr.takeError();
2364
2365 auto TSIOrErr = import(Base1.getTypeSourceInfo());
2366 if (!TSIOrErr)
2367 return TSIOrErr.takeError();
2368
2369 Bases.push_back(
2370 new (Importer.getToContext()) CXXBaseSpecifier(
2371 *RangeOrErr,
2372 Base1.isVirtual(),
2373 Base1.isBaseOfClass(),
2374 Base1.getAccessSpecifierAsWritten(),
2375 *TSIOrErr,
2376 EllipsisLoc));
2377 }
2378 if (!Bases.empty())
2379 ToCXX->setBases(Bases.data(), Bases.size());
2380 }
2381
2383 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2384 return Err;
2385 }
2386
2387 return Error::success();
2388}
2389
2391 if (To->getAnyInitializer())
2392 return Error::success();
2393
2394 Expr *FromInit = From->getInit();
2395 if (!FromInit)
2396 return Error::success();
2397
2398 ExpectedExpr ToInitOrErr = import(FromInit);
2399 if (!ToInitOrErr)
2400 return ToInitOrErr.takeError();
2401
2402 To->setInit(*ToInitOrErr);
2403 if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) {
2404 EvaluatedStmt *ToEval = To->ensureEvaluatedStmt();
2405 ToEval->HasConstantInitialization = FromEval->HasConstantInitialization;
2406 ToEval->HasConstantDestruction = FromEval->HasConstantDestruction;
2407 // FIXME: Also import the initializer value.
2408 }
2409
2410 // FIXME: Other bits to merge?
2411 return Error::success();
2412}
2413
2416 if (To->getDefinition() || To->isBeingDefined()) {
2417 if (Kind == IDK_Everything)
2418 return ImportDeclContext(From, /*ForceImport=*/true);
2419 return Error::success();
2420 }
2421
2422 To->startDefinition();
2423
2424 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2425 return Err;
2426
2427 ExpectedType ToTypeOrErr =
2428 import(Importer.getFromContext().getTypeDeclType(From));
2429 if (!ToTypeOrErr)
2430 return ToTypeOrErr.takeError();
2431
2432 ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType());
2433 if (!ToPromotionTypeOrErr)
2434 return ToPromotionTypeOrErr.takeError();
2435
2437 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2438 return Err;
2439
2440 // FIXME: we might need to merge the number of positive or negative bits
2441 // if the enumerator lists don't match.
2442 To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr,
2443 From->getNumPositiveBits(),
2444 From->getNumNegativeBits());
2445 return Error::success();
2446}
2447
2451 for (const auto &Arg : FromArgs) {
2452 if (auto ToOrErr = import(Arg))
2453 ToArgs.push_back(*ToOrErr);
2454 else
2455 return ToOrErr.takeError();
2456 }
2457
2458 return Error::success();
2459}
2460
2461// FIXME: Do not forget to remove this and use only 'import'.
2464 return import(From);
2465}
2466
2467template <typename InContainerTy>
2469 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) {
2470 for (const auto &FromLoc : Container) {
2471 if (auto ToLocOrErr = import(FromLoc))
2472 ToTAInfo.addArgument(*ToLocOrErr);
2473 else
2474 return ToLocOrErr.takeError();
2475 }
2476 return Error::success();
2477}
2478
2483}
2484
2485bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
2486 bool IgnoreTemplateParmDepth) {
2487 // Eliminate a potential failure point where we attempt to re-import
2488 // something we're trying to import while completing ToRecord.
2489 Decl *ToOrigin = Importer.GetOriginalDecl(To);
2490 if (ToOrigin) {
2491 To = ToOrigin;
2492 }
2493
2495 Importer.getFromContext(), Importer.getToContext(),
2497 /*StrictTypeSpelling=*/false, Complain, /*ErrorOnTagTypeMismatch=*/false,
2498 IgnoreTemplateParmDepth);
2499 return Ctx.IsEquivalent(From, To);
2500}
2501
2503 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2504 << D->getDeclKindName();
2505 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2506}
2507
2509 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2510 << D->getDeclKindName();
2511 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2512}
2513
2515 // Import the context of this declaration.
2516 DeclContext *DC, *LexicalDC;
2517 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2518 return std::move(Err);
2519
2520 // Import the location of this declaration.
2521 ExpectedSLoc LocOrErr = import(D->getLocation());
2522 if (!LocOrErr)
2523 return LocOrErr.takeError();
2524
2525 EmptyDecl *ToD;
2526 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr))
2527 return ToD;
2528
2529 ToD->setLexicalDeclContext(LexicalDC);
2530 LexicalDC->addDeclInternal(ToD);
2531 return ToD;
2532}
2533
2535 TranslationUnitDecl *ToD =
2537
2538 Importer.MapImported(D, ToD);
2539
2540 return ToD;
2541}
2542
2544 DeclContext *DC, *LexicalDC;
2545 DeclarationName Name;
2547 NamedDecl *ToND;
2548 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
2549 return std::move(Err);
2550 if (ToND)
2551 return ToND;
2552
2553 BindingDecl *ToD;
2554 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
2555 Name.getAsIdentifierInfo()))
2556 return ToD;
2557
2558 Error Err = Error::success();
2559 QualType ToType = importChecked(Err, D->getType());
2560 Expr *ToBinding = importChecked(Err, D->getBinding());
2561 ValueDecl *ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl());
2562 if (Err)
2563 return std::move(Err);
2564
2565 ToD->setBinding(ToType, ToBinding);
2566 ToD->setDecomposedDecl(ToDecomposedDecl);
2567 addDeclToContexts(D, ToD);
2568
2569 return ToD;
2570}
2571
2573 ExpectedSLoc LocOrErr = import(D->getLocation());
2574 if (!LocOrErr)
2575 return LocOrErr.takeError();
2576 auto ColonLocOrErr = import(D->getColonLoc());
2577 if (!ColonLocOrErr)
2578 return ColonLocOrErr.takeError();
2579
2580 // Import the context of this declaration.
2581 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2582 if (!DCOrErr)
2583 return DCOrErr.takeError();
2584 DeclContext *DC = *DCOrErr;
2585
2586 AccessSpecDecl *ToD;
2587 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(),
2588 DC, *LocOrErr, *ColonLocOrErr))
2589 return ToD;
2590
2591 // Lexical DeclContext and Semantic DeclContext
2592 // is always the same for the accessSpec.
2593 ToD->setLexicalDeclContext(DC);
2594 DC->addDeclInternal(ToD);
2595
2596 return ToD;
2597}
2598
2600 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2601 if (!DCOrErr)
2602 return DCOrErr.takeError();
2603 DeclContext *DC = *DCOrErr;
2604 DeclContext *LexicalDC = DC;
2605
2606 Error Err = Error::success();
2607 auto ToLocation = importChecked(Err, D->getLocation());
2608 auto ToRParenLoc = importChecked(Err, D->getRParenLoc());
2609 auto ToAssertExpr = importChecked(Err, D->getAssertExpr());
2610 auto ToMessage = importChecked(Err, D->getMessage());
2611 if (Err)
2612 return std::move(Err);
2613
2614 StaticAssertDecl *ToD;
2615 if (GetImportedOrCreateDecl(
2616 ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
2617 ToRParenLoc, D->isFailed()))
2618 return ToD;
2619
2620 ToD->setLexicalDeclContext(LexicalDC);
2621 LexicalDC->addDeclInternal(ToD);
2622 return ToD;
2623}
2624
2626 // Import the major distinguishing characteristics of this namespace.
2627 DeclContext *DC, *LexicalDC;
2628 DeclarationName Name;
2630 NamedDecl *ToD;
2631 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2632 return std::move(Err);
2633 if (ToD)
2634 return ToD;
2635
2636 NamespaceDecl *MergeWithNamespace = nullptr;
2637 if (!Name) {
2638 // This is an anonymous namespace. Adopt an existing anonymous
2639 // namespace if we can.
2640 // FIXME: Not testable.
2641 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2642 MergeWithNamespace = TU->getAnonymousNamespace();
2643 else
2644 MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace();
2645 } else {
2646 SmallVector<NamedDecl *, 4> ConflictingDecls;
2647 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2648 for (auto *FoundDecl : FoundDecls) {
2650 continue;
2651
2652 if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) {
2653 MergeWithNamespace = FoundNS;
2654 ConflictingDecls.clear();
2655 break;
2656 }
2657
2658 ConflictingDecls.push_back(FoundDecl);
2659 }
2660
2661 if (!ConflictingDecls.empty()) {
2662 ExpectedName NameOrErr = Importer.HandleNameConflict(
2663 Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(),
2664 ConflictingDecls.size());
2665 if (NameOrErr)
2666 Name = NameOrErr.get();
2667 else
2668 return NameOrErr.takeError();
2669 }
2670 }
2671
2672 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2673 if (!BeginLocOrErr)
2674 return BeginLocOrErr.takeError();
2675 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
2676 if (!RBraceLocOrErr)
2677 return RBraceLocOrErr.takeError();
2678
2679 // Create the "to" namespace, if needed.
2680 NamespaceDecl *ToNamespace = MergeWithNamespace;
2681 if (!ToNamespace) {
2682 if (GetImportedOrCreateDecl(ToNamespace, D, Importer.getToContext(), DC,
2683 D->isInline(), *BeginLocOrErr, Loc,
2684 Name.getAsIdentifierInfo(),
2685 /*PrevDecl=*/nullptr, D->isNested()))
2686 return ToNamespace;
2687 ToNamespace->setRBraceLoc(*RBraceLocOrErr);
2688 ToNamespace->setLexicalDeclContext(LexicalDC);
2689 LexicalDC->addDeclInternal(ToNamespace);
2690
2691 // If this is an anonymous namespace, register it as the anonymous
2692 // namespace within its context.
2693 if (!Name) {
2694 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2695 TU->setAnonymousNamespace(ToNamespace);
2696 else
2697 cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
2698 }
2699 }
2700 Importer.MapImported(D, ToNamespace);
2701
2702 if (Error Err = ImportDeclContext(D))
2703 return std::move(Err);
2704
2705 return ToNamespace;
2706}
2707
2709 // Import the major distinguishing characteristics of this namespace.
2710 DeclContext *DC, *LexicalDC;
2711 DeclarationName Name;
2713 NamedDecl *LookupD;
2714 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc))
2715 return std::move(Err);
2716 if (LookupD)
2717 return LookupD;
2718
2719 // NOTE: No conflict resolution is done for namespace aliases now.
2720
2721 Error Err = Error::success();
2722 auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc());
2723 auto ToAliasLoc = importChecked(Err, D->getAliasLoc());
2724 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
2725 auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc());
2726 auto ToNamespace = importChecked(Err, D->getNamespace());
2727 if (Err)
2728 return std::move(Err);
2729
2730 IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
2731
2732 NamespaceAliasDecl *ToD;
2733 if (GetImportedOrCreateDecl(
2734 ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
2735 ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
2736 return ToD;
2737
2738 ToD->setLexicalDeclContext(LexicalDC);
2739 LexicalDC->addDeclInternal(ToD);
2740
2741 return ToD;
2742}
2743
2746 // Import the major distinguishing characteristics of this typedef.
2747 DeclarationName Name;
2749 NamedDecl *ToD;
2750 // Do not import the DeclContext, we will import it once the TypedefNameDecl
2751 // is created.
2752 if (Error Err = ImportDeclParts(D, Name, ToD, Loc))
2753 return std::move(Err);
2754 if (ToD)
2755 return ToD;
2756
2757 DeclContext *DC = cast_or_null<DeclContext>(
2758 Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext())));
2759 DeclContext *LexicalDC =
2760 cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull(
2761 cast<Decl>(D->getLexicalDeclContext())));
2762
2763 // If this typedef is not in block scope, determine whether we've
2764 // seen a typedef with the same name (that we can merge with) or any
2765 // other entity by that name (which name lookup could conflict with).
2766 // Note: Repeated typedefs are not valid in C99:
2767 // 'typedef int T; typedef int T;' is invalid
2768 // We do not care about this now.
2769 if (DC && !DC->isFunctionOrMethod()) {
2770 SmallVector<NamedDecl *, 4> ConflictingDecls;
2771 unsigned IDNS = Decl::IDNS_Ordinary;
2772 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2773 for (auto *FoundDecl : FoundDecls) {
2774 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2775 continue;
2776 if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
2777 if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D))
2778 continue;
2779
2780 QualType FromUT = D->getUnderlyingType();
2781 QualType FoundUT = FoundTypedef->getUnderlyingType();
2782 if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) {
2783 // If the underlying declarations are unnamed records these can be
2784 // imported as different types. We should create a distinct typedef
2785 // node in this case.
2786 // If we found an existing underlying type with a record in a
2787 // different context (than the imported), this is already reason for
2788 // having distinct typedef nodes for these.
2789 // Again this can create situation like
2790 // 'typedef int T; typedef int T;' but this is hard to avoid without
2791 // a rename strategy at import.
2792 if (!FromUT.isNull() && !FoundUT.isNull()) {
2793 RecordDecl *FromR = FromUT->getAsRecordDecl();
2794 RecordDecl *FoundR = FoundUT->getAsRecordDecl();
2795 if (FromR && FoundR &&
2796 !hasSameVisibilityContextAndLinkage(FoundR, FromR))
2797 continue;
2798 }
2799 // If the "From" context has a complete underlying type but we
2800 // already have a complete underlying type then return with that.
2801 if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
2802 return Importer.MapImported(D, FoundTypedef);
2803 // FIXME Handle redecl chain. When you do that make consistent changes
2804 // in ASTImporterLookupTable too.
2805 } else {
2806 ConflictingDecls.push_back(FoundDecl);
2807 }
2808 }
2809 }
2810
2811 if (!ConflictingDecls.empty()) {
2812 ExpectedName NameOrErr = Importer.HandleNameConflict(
2813 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
2814 if (NameOrErr)
2815 Name = NameOrErr.get();
2816 else
2817 return NameOrErr.takeError();
2818 }
2819 }
2820
2821 Error Err = Error::success();
2822 auto ToUnderlyingType = importChecked(Err, D->getUnderlyingType());
2823 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
2824 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
2825 if (Err)
2826 return std::move(Err);
2827
2828 // Create the new typedef node.
2829 // FIXME: ToUnderlyingType is not used.
2830 (void)ToUnderlyingType;
2831 TypedefNameDecl *ToTypedef;
2832 if (IsAlias) {
2833 if (GetImportedOrCreateDecl<TypeAliasDecl>(
2834 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
2835 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
2836 return ToTypedef;
2837 } else if (GetImportedOrCreateDecl<TypedefDecl>(
2838 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
2839 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
2840 return ToTypedef;
2841
2842 // Import the DeclContext and set it to the Typedef.
2843 if ((Err = ImportDeclContext(D, DC, LexicalDC)))
2844 return std::move(Err);
2845 ToTypedef->setDeclContext(DC);
2846 ToTypedef->setLexicalDeclContext(LexicalDC);
2847 // Add to the lookupTable because we could not do that in MapImported.
2848 Importer.AddToLookupTable(ToTypedef);
2849
2850 ToTypedef->setAccess(D->getAccess());
2851
2852 // Templated declarations should not appear in DeclContext.
2853 TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr;
2854 if (!FromAlias || !FromAlias->getDescribedAliasTemplate())
2855 LexicalDC->addDeclInternal(ToTypedef);
2856
2857 return ToTypedef;
2858}
2859
2861 return VisitTypedefNameDecl(D, /*IsAlias=*/false);
2862}
2863
2865 return VisitTypedefNameDecl(D, /*IsAlias=*/true);
2866}
2867
2870 // Import the major distinguishing characteristics of this typedef.
2871 DeclContext *DC, *LexicalDC;
2872 DeclarationName Name;
2874 NamedDecl *FoundD;
2875 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc))
2876 return std::move(Err);
2877 if (FoundD)
2878 return FoundD;
2879
2880 // If this typedef is not in block scope, determine whether we've
2881 // seen a typedef with the same name (that we can merge with) or any
2882 // other entity by that name (which name lookup could conflict with).
2883 if (!DC->isFunctionOrMethod()) {
2884 SmallVector<NamedDecl *, 4> ConflictingDecls;
2885 unsigned IDNS = Decl::IDNS_Ordinary;
2886 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2887 for (auto *FoundDecl : FoundDecls) {
2888 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2889 continue;
2890 if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) {
2891 if (IsStructuralMatch(D, FoundAlias))
2892 return Importer.MapImported(D, FoundAlias);
2893 ConflictingDecls.push_back(FoundDecl);
2894 }
2895 }
2896
2897 if (!ConflictingDecls.empty()) {
2898 ExpectedName NameOrErr = Importer.HandleNameConflict(
2899 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
2900 if (NameOrErr)
2901 Name = NameOrErr.get();
2902 else
2903 return NameOrErr.takeError();
2904 }
2905 }
2906
2907 Error Err = Error::success();
2908 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
2909 auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl());
2910 if (Err)
2911 return std::move(Err);
2912
2913 TypeAliasTemplateDecl *ToAlias;
2914 if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc,
2915 Name, ToTemplateParameters, ToTemplatedDecl))
2916 return ToAlias;
2917
2918 ToTemplatedDecl->setDescribedAliasTemplate(ToAlias);
2919
2920 ToAlias->setAccess(D->getAccess());
2921 ToAlias->setLexicalDeclContext(LexicalDC);
2922 LexicalDC->addDeclInternal(ToAlias);
2923 if (DC != Importer.getToContext().getTranslationUnitDecl())
2924 updateLookupTableForTemplateParameters(*ToTemplateParameters);
2925 return ToAlias;
2926}
2927
2929 // Import the major distinguishing characteristics of this label.
2930 DeclContext *DC, *LexicalDC;
2931 DeclarationName Name;
2933 NamedDecl *ToD;
2934 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2935 return std::move(Err);
2936 if (ToD)
2937 return ToD;
2938
2939 assert(LexicalDC->isFunctionOrMethod());
2940
2941 LabelDecl *ToLabel;
2942 if (D->isGnuLocal()) {
2943 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2944 if (!BeginLocOrErr)
2945 return BeginLocOrErr.takeError();
2946 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
2947 Name.getAsIdentifierInfo(), *BeginLocOrErr))
2948 return ToLabel;
2949
2950 } else {
2951 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
2952 Name.getAsIdentifierInfo()))
2953 return ToLabel;
2954
2955 }
2956
2957 Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
2958 if (!ToStmtOrErr)
2959 return ToStmtOrErr.takeError();
2960
2961 ToLabel->setStmt(*ToStmtOrErr);
2962 ToLabel->setLexicalDeclContext(LexicalDC);
2963 LexicalDC->addDeclInternal(ToLabel);
2964 return ToLabel;
2965}
2966
2968 // Import the major distinguishing characteristics of this enum.
2969 DeclContext *DC, *LexicalDC;
2970 DeclarationName Name;
2972 NamedDecl *ToD;
2973 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2974 return std::move(Err);
2975 if (ToD)
2976 return ToD;
2977
2978 // Figure out what enum name we're looking for.
2979 unsigned IDNS = Decl::IDNS_Tag;
2980 DeclarationName SearchName = Name;
2981 if (!SearchName && D->getTypedefNameForAnonDecl()) {
2982 if (Error Err = importInto(
2983 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
2984 return std::move(Err);
2985 IDNS = Decl::IDNS_Ordinary;
2986 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
2987 IDNS |= Decl::IDNS_Ordinary;
2988
2989 // We may already have an enum of the same name; try to find and match it.
2990 EnumDecl *PrevDecl = nullptr;
2991 if (!DC->isFunctionOrMethod()) {
2992 SmallVector<NamedDecl *, 4> ConflictingDecls;
2993 auto FoundDecls =
2994 Importer.findDeclsInToCtx(DC, SearchName);
2995 for (auto *FoundDecl : FoundDecls) {
2996 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2997 continue;
2998
2999 if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3000 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3001 FoundDecl = Tag->getDecl();
3002 }
3003
3004 if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) {
3005 if (!hasSameVisibilityContextAndLinkage(FoundEnum, D))
3006 continue;
3007 if (IsStructuralMatch(D, FoundEnum, !SearchName.isEmpty())) {
3008 EnumDecl *FoundDef = FoundEnum->getDefinition();
3009 if (D->isThisDeclarationADefinition() && FoundDef)
3010 return Importer.MapImported(D, FoundDef);
3011 PrevDecl = FoundEnum->getMostRecentDecl();
3012 break;
3013 }
3014 ConflictingDecls.push_back(FoundDecl);
3015 }
3016 }
3017
3018 // In case of unnamed enums, we try to find an existing similar one, if none
3019 // was found, perform the import always.
3020 // Structural in-equivalence is not detected in this way here, but it may
3021 // be found when the parent decl is imported (if the enum is part of a
3022 // class). To make this totally exact a more difficult solution is needed.
3023 if (SearchName && !ConflictingDecls.empty()) {
3024 ExpectedName NameOrErr = Importer.HandleNameConflict(
3025 SearchName, DC, IDNS, ConflictingDecls.data(),
3026 ConflictingDecls.size());
3027 if (NameOrErr)
3028 Name = NameOrErr.get();
3029 else
3030 return NameOrErr.takeError();
3031 }
3032 }
3033
3034 Error Err = Error::success();
3035 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3036 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3037 auto ToIntegerType = importChecked(Err, D->getIntegerType());
3038 auto ToBraceRange = importChecked(Err, D->getBraceRange());
3039 if (Err)
3040 return std::move(Err);
3041
3042 // Create the enum declaration.
3043 EnumDecl *D2;
3044 if (GetImportedOrCreateDecl(
3045 D2, D, Importer.getToContext(), DC, ToBeginLoc,
3046 Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(),
3047 D->isScopedUsingClassTag(), D->isFixed()))
3048 return D2;
3049
3050 D2->setQualifierInfo(ToQualifierLoc);
3051 D2->setIntegerType(ToIntegerType);
3052 D2->setBraceRange(ToBraceRange);
3053 D2->setAccess(D->getAccess());
3054 D2->setLexicalDeclContext(LexicalDC);
3055 addDeclToContexts(D, D2);
3056
3057 if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
3058 TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
3059 EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
3060 if (Expected<EnumDecl *> ToInstOrErr = import(FromInst))
3061 D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
3062 else
3063 return ToInstOrErr.takeError();
3064 if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
3066 else
3067 return POIOrErr.takeError();
3068 }
3069
3070 // Import the definition
3071 if (D->isCompleteDefinition())
3072 if (Error Err = ImportDefinition(D, D2))
3073 return std::move(Err);
3074
3075 return D2;
3076}
3077
3079 bool IsFriendTemplate = false;
3080 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3081 IsFriendTemplate =
3082 DCXX->getDescribedClassTemplate() &&
3083 DCXX->getDescribedClassTemplate()->getFriendObjectKind() !=
3085 }
3086
3087 // Import the major distinguishing characteristics of this record.
3088 DeclContext *DC = nullptr, *LexicalDC = nullptr;
3089 DeclarationName Name;
3091 NamedDecl *ToD = nullptr;
3092 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3093 return std::move(Err);
3094 if (ToD)
3095 return ToD;
3096
3097 // Figure out what structure name we're looking for.
3098 unsigned IDNS = Decl::IDNS_Tag;
3099 DeclarationName SearchName = Name;
3100 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3101 if (Error Err = importInto(
3102 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3103 return std::move(Err);
3104 IDNS = Decl::IDNS_Ordinary;
3105 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3107
3108 bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
3109 : DC->isDependentContext();
3110 bool DependentFriend = IsFriendTemplate && IsDependentContext;
3111
3112 // We may already have a record of the same name; try to find and match it.
3113 RecordDecl *PrevDecl = nullptr;
3114 if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
3115 SmallVector<NamedDecl *, 4> ConflictingDecls;
3116 auto FoundDecls =
3117 Importer.findDeclsInToCtx(DC, SearchName);
3118 if (!FoundDecls.empty()) {
3119 // We're going to have to compare D against potentially conflicting Decls,
3120 // so complete it.
3121 if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition())
3123 }
3124
3125 for (auto *FoundDecl : FoundDecls) {
3126 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3127 continue;
3128
3129 Decl *Found = FoundDecl;
3130 if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
3131 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3132 Found = Tag->getDecl();
3133 }
3134
3135 if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) {
3136 // Do not emit false positive diagnostic in case of unnamed
3137 // struct/union and in case of anonymous structs. Would be false
3138 // because there may be several anonymous/unnamed structs in a class.
3139 // E.g. these are both valid:
3140 // struct A { // unnamed structs
3141 // struct { struct A *next; } entry0;
3142 // struct { struct A *next; } entry1;
3143 // };
3144 // struct X { struct { int a; }; struct { int b; }; }; // anon structs
3145 if (!SearchName)
3146 if (!IsStructuralMatch(D, FoundRecord, false))
3147 continue;
3148
3149 if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
3150 continue;
3151
3152 if (IsStructuralMatch(D, FoundRecord)) {
3153 RecordDecl *FoundDef = FoundRecord->getDefinition();
3154 if (D->isThisDeclarationADefinition() && FoundDef) {
3155 // FIXME: Structural equivalence check should check for same
3156 // user-defined methods.
3157 Importer.MapImported(D, FoundDef);
3158 if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3159 auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef);
3160 assert(FoundCXX && "Record type mismatch");
3161
3162 if (!Importer.isMinimalImport())
3163 // FoundDef may not have every implicit method that D has
3164 // because implicit methods are created only if they are used.
3165 if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
3166 return std::move(Err);
3167 }
3168 }
3169 PrevDecl = FoundRecord->getMostRecentDecl();
3170 break;
3171 }
3172 ConflictingDecls.push_back(FoundDecl);
3173 } // kind is RecordDecl
3174 } // for
3175
3176 if (!ConflictingDecls.empty() && SearchName) {
3177 ExpectedName NameOrErr = Importer.HandleNameConflict(
3178 SearchName, DC, IDNS, ConflictingDecls.data(),
3179 ConflictingDecls.size());
3180 if (NameOrErr)
3181 Name = NameOrErr.get();
3182 else
3183 return NameOrErr.takeError();
3184 }
3185 }
3186
3187 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3188 if (!BeginLocOrErr)
3189 return BeginLocOrErr.takeError();
3190
3191 // Create the record declaration.
3192 RecordDecl *D2 = nullptr;
3193 CXXRecordDecl *D2CXX = nullptr;
3194 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3195 if (DCXX->isLambda()) {
3196 auto TInfoOrErr = import(DCXX->getLambdaTypeInfo());
3197 if (!TInfoOrErr)
3198 return TInfoOrErr.takeError();
3199 if (GetImportedOrCreateSpecialDecl(
3200 D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(),
3201 DC, *TInfoOrErr, Loc, DCXX->getLambdaDependencyKind(),
3202 DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault()))
3203 return D2CXX;
3204 CXXRecordDecl::LambdaNumbering Numbering = DCXX->getLambdaNumbering();
3205 ExpectedDecl CDeclOrErr = import(Numbering.ContextDecl);
3206 if (!CDeclOrErr)
3207 return CDeclOrErr.takeError();
3208 Numbering.ContextDecl = *CDeclOrErr;
3209 D2CXX->setLambdaNumbering(Numbering);
3210 } else if (DCXX->isInjectedClassName()) {
3211 // We have to be careful to do a similar dance to the one in
3212 // Sema::ActOnStartCXXMemberDeclarations
3213 const bool DelayTypeCreation = true;
3214 if (GetImportedOrCreateDecl(
3215 D2CXX, D, Importer.getToContext(), D->getTagKind(), DC,
3216 *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(),
3217 cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation))
3218 return D2CXX;
3219 Importer.getToContext().getTypeDeclType(
3220 D2CXX, dyn_cast<CXXRecordDecl>(DC));
3221 } else {
3222 if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
3223 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3224 Name.getAsIdentifierInfo(),
3225 cast_or_null<CXXRecordDecl>(PrevDecl)))
3226 return D2CXX;
3227 }
3228
3229 D2 = D2CXX;
3230 D2->setAccess(D->getAccess());
3231 D2->setLexicalDeclContext(LexicalDC);
3232 addDeclToContexts(D, D2);
3233
3234 if (ClassTemplateDecl *FromDescribed =
3235 DCXX->getDescribedClassTemplate()) {
3236 ClassTemplateDecl *ToDescribed;
3237 if (Error Err = importInto(ToDescribed, FromDescribed))
3238 return std::move(Err);
3239 D2CXX->setDescribedClassTemplate(ToDescribed);
3240 if (!DCXX->isInjectedClassName() && !IsFriendTemplate) {
3241 // In a record describing a template the type should be an
3242 // InjectedClassNameType (see Sema::CheckClassTemplate). Update the
3243 // previously set type to the correct value here (ToDescribed is not
3244 // available at record create).
3245 CXXRecordDecl *Injected = nullptr;
3246 for (NamedDecl *Found : D2CXX->noload_lookup(Name)) {
3247 auto *Record = dyn_cast<CXXRecordDecl>(Found);
3248 if (Record && Record->isInjectedClassName()) {
3249 Injected = Record;
3250 break;
3251 }
3252 }
3253 // Create an injected type for the whole redecl chain.
3254 // The chain may contain an already existing injected type at the start,
3255 // if yes this should be reused. We must ensure that only one type
3256 // object exists for the injected type (including the injected record
3257 // declaration), ASTContext does not check it.
3258 SmallVector<Decl *, 2> Redecls =
3260 const Type *FrontTy =
3261 cast<CXXRecordDecl>(Redecls.front())->getTypeForDecl();
3262 QualType InjSpec;
3263 if (auto *InjTy = FrontTy->getAs<InjectedClassNameType>())
3264 InjSpec = InjTy->getInjectedSpecializationType();
3265 else
3266 InjSpec = ToDescribed->getInjectedClassNameSpecialization();
3267 for (auto *R : Redecls) {
3268 auto *RI = cast<CXXRecordDecl>(R);
3269 if (R != Redecls.front() ||
3270 !isa<InjectedClassNameType>(RI->getTypeForDecl()))
3271 RI->setTypeForDecl(nullptr);
3272 // This function tries to get the injected type from getTypeForDecl,
3273 // then from the previous declaration if possible. If not, it creates
3274 // a new type.
3275 Importer.getToContext().getInjectedClassNameType(RI, InjSpec);
3276 }
3277 // Set the new type for the injected decl too.
3278 if (Injected) {
3279 Injected->setTypeForDecl(nullptr);
3280 // This function will copy the injected type from D2CXX into Injected.
3281 // The injected decl does not have a previous decl to copy from.
3282 Importer.getToContext().getTypeDeclType(Injected, D2CXX);
3283 }
3284 }
3285 } else if (MemberSpecializationInfo *MemberInfo =
3286 DCXX->getMemberSpecializationInfo()) {
3288 MemberInfo->getTemplateSpecializationKind();
3290
3291 if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
3292 D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
3293 else
3294 return ToInstOrErr.takeError();
3295
3296 if (ExpectedSLoc POIOrErr =
3297 import(MemberInfo->getPointOfInstantiation()))
3299 *POIOrErr);
3300 else
3301 return POIOrErr.takeError();
3302 }
3303
3304 } else {
3305 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
3306 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3307 Name.getAsIdentifierInfo(), PrevDecl))
3308 return D2;
3309 D2->setLexicalDeclContext(LexicalDC);
3310 addDeclToContexts(D, D2);
3311 }
3312
3313 if (auto BraceRangeOrErr = import(D->getBraceRange()))
3314 D2->setBraceRange(*BraceRangeOrErr);
3315 else
3316 return BraceRangeOrErr.takeError();
3317 if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
3318 D2->setQualifierInfo(*QualifierLocOrErr);
3319 else
3320 return QualifierLocOrErr.takeError();
3321
3322 if (D->isAnonymousStructOrUnion())
3323 D2->setAnonymousStructOrUnion(true);
3324
3325 if (D->isCompleteDefinition())
3326 if (Error Err = ImportDefinition(D, D2, IDK_Default))
3327 return std::move(Err);
3328
3329 return D2;
3330}
3331
3333 // Import the major distinguishing characteristics of this enumerator.
3334 DeclContext *DC, *LexicalDC;
3335 DeclarationName Name;
3337 NamedDecl *ToD;
3338 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3339 return std::move(Err);
3340 if (ToD)
3341 return ToD;
3342
3343 // Determine whether there are any other declarations with the same name and
3344 // in the same context.
3345 if (!LexicalDC->isFunctionOrMethod()) {
3346 SmallVector<NamedDecl *, 4> ConflictingDecls;
3347 unsigned IDNS = Decl::IDNS_Ordinary;
3348 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3349 for (auto *FoundDecl : FoundDecls) {
3350 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3351 continue;
3352
3353 if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
3354 if (IsStructuralMatch(D, FoundEnumConstant))
3355 return Importer.MapImported(D, FoundEnumConstant);
3356 ConflictingDecls.push_back(FoundDecl);
3357 }
3358 }
3359
3360 if (!ConflictingDecls.empty()) {
3361 ExpectedName NameOrErr = Importer.HandleNameConflict(
3362 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3363 if (NameOrErr)
3364 Name = NameOrErr.get();
3365 else
3366 return NameOrErr.takeError();
3367 }
3368 }
3369
3370 ExpectedType TypeOrErr = import(D->getType());
3371 if (!TypeOrErr)
3372 return TypeOrErr.takeError();
3373
3374 ExpectedExpr InitOrErr = import(D->getInitExpr());
3375 if (!InitOrErr)
3376 return InitOrErr.takeError();
3377
3378 EnumConstantDecl *ToEnumerator;
3379 if (GetImportedOrCreateDecl(
3380 ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
3381 Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
3382 return ToEnumerator;
3383
3384 ToEnumerator->setAccess(D->getAccess());
3385 ToEnumerator->setLexicalDeclContext(LexicalDC);
3386 LexicalDC->addDeclInternal(ToEnumerator);
3387 return ToEnumerator;
3388}
3389
3390template <typename DeclTy>
3392 DeclTy *ToD) {
3393 unsigned int Num = FromD->getNumTemplateParameterLists();
3394 if (Num == 0)
3395 return Error::success();
3397 for (unsigned int I = 0; I < Num; ++I)
3398 if (Expected<TemplateParameterList *> ToTPListOrErr =
3399 import(FromD->getTemplateParameterList(I)))
3400 ToTPLists[I] = *ToTPListOrErr;
3401 else
3402 return ToTPListOrErr.takeError();
3403 ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
3404 return Error::success();
3405}
3406
3408 FunctionDecl *FromFD, FunctionDecl *ToFD) {
3409 switch (FromFD->getTemplatedKind()) {
3412 return Error::success();
3413
3415 if (Expected<FunctionDecl *> InstFDOrErr =
3416 import(FromFD->getInstantiatedFromDecl()))
3417 ToFD->setInstantiatedFromDecl(*InstFDOrErr);
3418 return Error::success();
3421
3422 if (Expected<FunctionDecl *> InstFDOrErr =
3423 import(FromFD->getInstantiatedFromMemberFunction()))
3424 ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
3425 else
3426 return InstFDOrErr.takeError();
3427
3428 if (ExpectedSLoc POIOrErr = import(
3431 else
3432 return POIOrErr.takeError();
3433
3434 return Error::success();
3435 }
3436
3438 auto FunctionAndArgsOrErr =
3440 if (!FunctionAndArgsOrErr)
3441 return FunctionAndArgsOrErr.takeError();
3442
3444 Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
3445
3446 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
3447 TemplateArgumentListInfo ToTAInfo;
3448 const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
3449 if (FromTAArgsAsWritten)
3450 if (Error Err = ImportTemplateArgumentListInfo(
3451 *FromTAArgsAsWritten, ToTAInfo))
3452 return Err;
3453
3454 ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
3455 if (!POIOrErr)
3456 return POIOrErr.takeError();
3457
3458 if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
3459 return Err;
3460
3461 TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
3462 ToFD->setFunctionTemplateSpecialization(
3463 std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr,
3464 TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
3465 return Error::success();
3466 }
3467
3469 auto *FromInfo = FromFD->getDependentSpecializationInfo();
3470 UnresolvedSet<8> Candidates;
3471 for (FunctionTemplateDecl *FTD : FromInfo->getCandidates()) {
3472 if (Expected<FunctionTemplateDecl *> ToFTDOrErr = import(FTD))
3473 Candidates.addDecl(*ToFTDOrErr);
3474 else
3475 return ToFTDOrErr.takeError();
3476 }
3477
3478 // Import TemplateArgumentListInfo.
3479 TemplateArgumentListInfo ToTAInfo;
3480 const auto *FromTAArgsAsWritten = FromInfo->TemplateArgumentsAsWritten;
3481 if (FromTAArgsAsWritten)
3482 if (Error Err =
3483 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
3484 return Err;
3485
3487 Importer.getToContext(), Candidates,
3488 FromTAArgsAsWritten ? &ToTAInfo : nullptr);
3489 return Error::success();
3490 }
3491 }
3492 llvm_unreachable("All cases should be covered!");
3493}
3494
3497 auto FunctionAndArgsOrErr =
3499 if (!FunctionAndArgsOrErr)
3500 return FunctionAndArgsOrErr.takeError();
3501
3502 FunctionTemplateDecl *Template;
3503 TemplateArgsTy ToTemplArgs;
3504 std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
3505 void *InsertPos = nullptr;
3506 auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos);
3507 return FoundSpec;
3508}
3509
3511 FunctionDecl *ToFD) {
3512 if (Stmt *FromBody = FromFD->getBody()) {
3513 if (ExpectedStmt ToBodyOrErr = import(FromBody))
3514 ToFD->setBody(*ToBodyOrErr);
3515 else
3516 return ToBodyOrErr.takeError();
3517 }
3518 return Error::success();
3519}
3520
3521// Returns true if the given D has a DeclContext up to the TranslationUnitDecl
3522// which is equal to the given DC, or D is equal to DC.
3523static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) {
3524 const DeclContext *DCi = dyn_cast<DeclContext>(D);
3525 if (!DCi)
3526 DCi = D->getDeclContext();
3527 assert(DCi && "Declaration should have a context");
3528 while (DCi != D->getTranslationUnitDecl()) {
3529 if (DCi == DC)
3530 return true;
3531 DCi = DCi->getParent();
3532 }
3533 return false;
3534}
3535
3536// Check if there is a declaration that has 'DC' as parent context and is
3537// referenced from statement 'S' or one of its children. The search is done in
3538// BFS order through children of 'S'.
3539static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
3540 SmallVector<const Stmt *> ToProcess;
3541 ToProcess.push_back(S);
3542 while (!ToProcess.empty()) {
3543 const Stmt *CurrentS = ToProcess.pop_back_val();
3544 ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
3545 if (const auto *DeclRef = dyn_cast<DeclRefExpr>(CurrentS)) {
3546 if (const Decl *D = DeclRef->getDecl())
3547 if (isAncestorDeclContextOf(DC, D))
3548 return true;
3549 } else if (const auto *E =
3550 dyn_cast_or_null<SubstNonTypeTemplateParmExpr>(CurrentS)) {
3551 if (const Decl *D = E->getAssociatedDecl())
3552 if (isAncestorDeclContextOf(DC, D))
3553 return true;
3554 }
3555 }
3556 return false;
3557}
3558
3559namespace {
3560/// Check if a type has any reference to a declaration that is inside the body
3561/// of a function.
3562/// The \c CheckType(QualType) function should be used to determine
3563/// this property.
3564///
3565/// The type visitor visits one type object only (not recursive).
3566/// To find all referenced declarations we must discover all type objects until
3567/// the canonical type is reached (walk over typedef and similar objects). This
3568/// is done by loop over all "sugar" type objects. For every such type we must
3569/// check all declarations that are referenced from it. For this check the
3570/// visitor is used. In the visit functions all referenced declarations except
3571/// the one that follows in the sugar chain (if any) must be checked. For this
3572/// check the same visitor is re-used (it has no state-dependent data).
3573///
3574/// The visit functions have 3 possible return values:
3575/// - True, found a declaration inside \c ParentDC.
3576/// - False, found declarations only outside \c ParentDC and it is not possible
3577/// to find more declarations (the "sugar" chain does not continue).
3578/// - Empty optional value, found no declarations or only outside \c ParentDC,
3579/// but it is possible to find more declarations in the type "sugar" chain.
3580/// The loop over the "sugar" types can be implemented by using type visit
3581/// functions only (call \c CheckType with the desugared type). With the current
3582/// solution no visit function is needed if the type has only a desugared type
3583/// as data.
3584class IsTypeDeclaredInsideVisitor
3585 : public TypeVisitor<IsTypeDeclaredInsideVisitor, std::optional<bool>> {
3586public:
3587 IsTypeDeclaredInsideVisitor(const FunctionDecl *ParentDC)
3588 : ParentDC(ParentDC) {}
3589
3590 bool CheckType(QualType T) {
3591 // Check the chain of "sugar" types.
3592 // The "sugar" types are typedef or similar types that have the same
3593 // canonical type.
3594 if (std::optional<bool> Res = Visit(T.getTypePtr()))
3595 return *Res;
3596 QualType DsT =
3597 T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3598 while (DsT != T) {
3599 if (std::optional<bool> Res = Visit(DsT.getTypePtr()))
3600 return *Res;
3601 T = DsT;
3602 DsT = T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3603 }
3604 return false;
3605 }
3606
3607 std::optional<bool> VisitTagType(const TagType *T) {
3608 if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(T->getDecl()))
3609 for (const auto &Arg : Spec->getTemplateArgs().asArray())
3610 if (checkTemplateArgument(Arg))
3611 return true;
3612 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3613 }
3614
3615 std::optional<bool> VisitPointerType(const PointerType *T) {
3616 return CheckType(T->getPointeeType());
3617 }
3618
3619 std::optional<bool> VisitReferenceType(const ReferenceType *T) {
3620 return CheckType(T->getPointeeTypeAsWritten());
3621 }
3622
3623 std::optional<bool> VisitTypedefType(const TypedefType *T) {
3624 const TypedefNameDecl *TD = T->getDecl();
3625 assert(TD);
3626 return isAncestorDeclContextOf(ParentDC, TD);
3627 }
3628
3629 std::optional<bool> VisitUsingType(const UsingType *T) {
3630 if (T->getFoundDecl() &&
3631 isAncestorDeclContextOf(ParentDC, T->getFoundDecl()))
3632 return true;
3633
3634 return {};
3635 }
3636
3637 std::optional<bool>
3638 VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
3639 for (const auto &Arg : T->template_arguments())
3640 if (checkTemplateArgument(Arg))
3641 return true;
3642 // This type is a "sugar" to a record type, it can have a desugared type.
3643 return {};
3644 }
3645
3646 std::optional<bool> VisitUnaryTransformType(const UnaryTransformType *T) {
3647 return CheckType(T->getBaseType());
3648 }
3649
3650 std::optional<bool>
3651 VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
3652 // The "associated declaration" can be the same as ParentDC.
3653 if (isAncestorDeclContextOf(ParentDC, T->getAssociatedDecl()))
3654 return true;
3655 return {};
3656 }
3657
3658 std::optional<bool> VisitConstantArrayType(const ConstantArrayType *T) {
3659 if (T->getSizeExpr() && isAncestorDeclContextOf(ParentDC, T->getSizeExpr()))
3660 return true;
3661
3662 return CheckType(T->getElementType());
3663 }
3664
3665 std::optional<bool> VisitVariableArrayType(const VariableArrayType *T) {
3666 llvm_unreachable(
3667 "Variable array should not occur in deduced return type of a function");
3668 }
3669
3670 std::optional<bool> VisitIncompleteArrayType(const IncompleteArrayType *T) {
3671 llvm_unreachable("Incomplete array should not occur in deduced return type "
3672 "of a function");
3673 }
3674
3675 std::optional<bool> VisitDependentArrayType(const IncompleteArrayType *T) {
3676 llvm_unreachable("Dependent array should not occur in deduced return type "
3677 "of a function");
3678 }
3679
3680private:
3681 const DeclContext *const ParentDC;
3682
3683 bool checkTemplateArgument(const TemplateArgument &Arg) {
3684 switch (Arg.getKind()) {
3686 return false;
3688 return CheckType(Arg.getIntegralType());
3690 return CheckType(Arg.getAsType());
3692 return isAncestorDeclContextOf(ParentDC, Arg.getAsExpr());
3694 // FIXME: The declaration in this case is not allowed to be in a function?
3695 return isAncestorDeclContextOf(ParentDC, Arg.getAsDecl());
3697 // FIXME: The type is not allowed to be in the function?
3698 return CheckType(Arg.getNullPtrType());
3700 return CheckType(Arg.getStructuralValueType());
3702 for (const auto &PackArg : Arg.getPackAsArray())
3703 if (checkTemplateArgument(PackArg))
3704 return true;
3705 return false;
3707 // Templates can not be defined locally in functions.
3708 // A template passed as argument can be not in ParentDC.
3709 return false;
3711 // Templates can not be defined locally in functions.
3712 // A template passed as argument can be not in ParentDC.
3713 return false;
3714 }
3715 llvm_unreachable("Unknown TemplateArgument::ArgKind enum");
3716 };
3717};
3718} // namespace
3719
3720/// This function checks if the given function has a return type that contains
3721/// a reference (in any way) to a declaration inside the same function.
3723 QualType FromTy = D->getType();
3724 const auto *FromFPT = FromTy->getAs<FunctionProtoType>();
3725 assert(FromFPT && "Must be called on FunctionProtoType");
3726
3727 auto IsCXX11Lambda = [&]() {
3728 if (Importer.FromContext.getLangOpts().CPlusPlus14) // C++14 or later
3729 return false;
3730
3731 if (const auto *MD = dyn_cast<CXXMethodDecl>(D))
3732 return cast<CXXRecordDecl>(MD->getDeclContext())->isLambda();
3733
3734 return false;
3735 };
3736
3737 QualType RetT = FromFPT->getReturnType();
3738 if (isa<AutoType>(RetT.getTypePtr()) || IsCXX11Lambda()) {
3739 FunctionDecl *Def = D->getDefinition();
3740 IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D);
3741 return Visitor.CheckType(RetT);
3742 }
3743
3744 return false;
3745}
3746
3748ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3749 Expr *ExplicitExpr = ESpec.getExpr();
3750 if (ExplicitExpr)
3751 ExplicitExpr = importChecked(Err, ESpec.getExpr());
3752 return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3753}
3754
3756
3758 auto RedeclIt = Redecls.begin();
3759 // Import the first part of the decl chain. I.e. import all previous
3760 // declarations starting from the canonical decl.
3761 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3762 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3763 if (!ToRedeclOrErr)
3764 return ToRedeclOrErr.takeError();
3765 }
3766 assert(*RedeclIt == D);
3767
3768 // Import the major distinguishing characteristics of this function.
3769 DeclContext *DC, *LexicalDC;
3770 DeclarationName Name;
3772 NamedDecl *ToD;
3773 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3774 return std::move(Err);
3775 if (ToD)
3776 return ToD;
3777
3778 FunctionDecl *FoundByLookup = nullptr;
3779 FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate();
3780
3781 // If this is a function template specialization, then try to find the same
3782 // existing specialization in the "to" context. The lookup below will not
3783 // find any specialization, but would find the primary template; thus, we
3784 // have to skip normal lookup in case of specializations.
3785 // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3786 if (D->getTemplatedKind() ==
3788 auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
3789 if (!FoundFunctionOrErr)
3790 return FoundFunctionOrErr.takeError();
3791 if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
3792 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3793 return Def;
3794 FoundByLookup = FoundFunction;
3795 }
3796 }
3797 // Try to find a function in our own ("to") context with the same name, same
3798 // type, and in the same context as the function we're importing.
3799 else if (!LexicalDC->isFunctionOrMethod()) {
3800 SmallVector<NamedDecl *, 4> ConflictingDecls;
3802 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3803 for (auto *FoundDecl : FoundDecls) {
3804 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3805 continue;
3806
3807 if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3808 if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
3809 continue;
3810
3811 if (IsStructuralMatch(D, FoundFunction)) {
3812 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3813 return Def;
3814 FoundByLookup = FoundFunction;
3815 break;
3816 }
3817 // FIXME: Check for overloading more carefully, e.g., by boosting
3818 // Sema::IsOverload out to the AST library.
3819
3820 // Function overloading is okay in C++.
3821 if (Importer.getToContext().getLangOpts().CPlusPlus)
3822 continue;
3823
3824 // Complain about inconsistent function types.
3825 Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
3826 << Name << D->getType() << FoundFunction->getType();
3827 Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
3828 << FoundFunction->getType();
3829 ConflictingDecls.push_back(FoundDecl);
3830 }
3831 }
3832
3833 if (!ConflictingDecls.empty()) {
3834 ExpectedName NameOrErr = Importer.HandleNameConflict(
3835 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3836 if (NameOrErr)
3837 Name = NameOrErr.get();
3838 else
3839 return NameOrErr.takeError();
3840 }
3841 }
3842
3843 // We do not allow more than one in-class declaration of a function. This is
3844 // because AST clients like VTableBuilder asserts on this. VTableBuilder
3845 // assumes there is only one in-class declaration. Building a redecl
3846 // chain would result in more than one in-class declaration for
3847 // overrides (even if they are part of the same redecl chain inside the
3848 // derived class.)
3849 if (FoundByLookup) {
3850 if (isa<CXXMethodDecl>(FoundByLookup)) {
3851 if (D->getLexicalDeclContext() == D->getDeclContext()) {
3852 if (!D->doesThisDeclarationHaveABody()) {
3853 if (FunctionTemplateDecl *DescribedD =
3854 D->getDescribedFunctionTemplate()) {
3855 // Handle a "templated" function together with its described
3856 // template. This avoids need for a similar check at import of the
3857 // described template.
3858 assert(FoundByLookup->getDescribedFunctionTemplate() &&
3859 "Templated function mapped to non-templated?");
3860 Importer.MapImported(DescribedD,
3861 FoundByLookup->getDescribedFunctionTemplate());
3862 }
3863 return Importer.MapImported(D, FoundByLookup);
3864 } else {
3865 // Let's continue and build up the redecl chain in this case.
3866 // FIXME Merge the functions into one decl.
3867 }
3868 }
3869 }
3870 }
3871
3872 DeclarationNameInfo NameInfo(Name, Loc);
3873 // Import additional name location/type info.
3874 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
3875 return std::move(Err);
3876
3877 QualType FromTy = D->getType();
3878 TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
3879 // Set to true if we do not import the type of the function as is. There are
3880 // cases when the original type would result in an infinite recursion during
3881 // the import. To avoid an infinite recursion when importing, we create the
3882 // FunctionDecl with a simplified function type and update it only after the
3883 // relevant AST nodes are already imported.
3884 // The type is related to TypeSourceInfo (it references the type), so we must
3885 // do the same with TypeSourceInfo.
3886 bool UsedDifferentProtoType = false;
3887 if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
3888 QualType FromReturnTy = FromFPT->getReturnType();
3889 // Functions with auto return type may define a struct inside their body
3890 // and the return type could refer to that struct.
3891 // E.g.: auto foo() { struct X{}; return X(); }
3892 // To avoid an infinite recursion when importing, create the FunctionDecl
3893 // with a simplified return type.
3895 FromReturnTy = Importer.getFromContext().VoidTy;
3896 UsedDifferentProtoType = true;
3897 }
3898 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
3899 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
3900 // FunctionDecl that we are importing the FunctionProtoType for.
3901 // To avoid an infinite recursion when importing, create the FunctionDecl
3902 // with a simplified function type.
3903 if (FromEPI.ExceptionSpec.SourceDecl ||
3904 FromEPI.ExceptionSpec.SourceTemplate ||
3905 FromEPI.ExceptionSpec.NoexceptExpr) {
3907 FromEPI = DefaultEPI;
3908 UsedDifferentProtoType = true;
3909 }
3910 FromTy = Importer.getFromContext().getFunctionType(
3911 FromReturnTy, FromFPT->getParamTypes(), FromEPI);
3912 FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
3913 FromTy, D->getBeginLoc());
3914 }
3915
3916 Error Err = Error::success();
3917 auto T = importChecked(Err, FromTy);
3918 auto TInfo = importChecked(Err, FromTSI);
3919 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
3920 auto ToEndLoc = importChecked(Err, D->getEndLoc());
3921 auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
3922 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3923 auto TrailingRequiresClause =
3924 importChecked(Err, D->getTrailingRequiresClause());
3925 if (Err)
3926 return std::move(Err);
3927
3928 // Import the function parameters.
3930 for (auto *P : D->parameters()) {
3931 if (Expected<ParmVarDecl *> ToPOrErr = import(P))
3932 Parameters.push_back(*ToPOrErr);
3933 else
3934 return ToPOrErr.takeError();
3935 }
3936
3937 // Create the imported function.
3938 FunctionDecl *ToFunction = nullptr;
3939 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
3940 ExplicitSpecifier ESpec =
3941 importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
3942 if (Err)
3943 return std::move(Err);
3944 auto ToInheritedConstructor = InheritedConstructor();
3945 if (FromConstructor->isInheritingConstructor()) {
3946 Expected<InheritedConstructor> ImportedInheritedCtor =
3947 import(FromConstructor->getInheritedConstructor());
3948 if (!ImportedInheritedCtor)
3949 return ImportedInheritedCtor.takeError();
3950 ToInheritedConstructor = *ImportedInheritedCtor;
3951 }
3952 if (GetImportedOrCreateDecl<CXXConstructorDecl>(
3953 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3954 ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
3955 D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(),
3956 ToInheritedConstructor, TrailingRequiresClause))
3957 return ToFunction;
3958 } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
3959
3960 Error Err = Error::success();
3961 auto ToOperatorDelete = importChecked(
3962 Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
3963 auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
3964 if (Err)
3965 return std::move(Err);
3966
3967 if (GetImportedOrCreateDecl<CXXDestructorDecl>(
3968 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3969 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
3970 D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(),
3971 TrailingRequiresClause))
3972 return ToFunction;
3973
3974 CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
3975
3976 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
3977 } else if (CXXConversionDecl *FromConversion =
3978 dyn_cast<CXXConversionDecl>(D)) {
3979 ExplicitSpecifier ESpec =
3980 importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
3981 if (Err)
3982 return std::move(Err);
3983 if (GetImportedOrCreateDecl<CXXConversionDecl>(
3984 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3985 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
3986 D->isInlineSpecified(), ESpec, D->getConstexprKind(),
3987 SourceLocation(), TrailingRequiresClause))
3988 return ToFunction;
3989 } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
3990 if (GetImportedOrCreateDecl<CXXMethodDecl>(
3991 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3992 ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
3993 Method->UsesFPIntrin(), Method->isInlineSpecified(),
3994 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
3995 return ToFunction;
3996 } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
3997 ExplicitSpecifier ESpec =
3998 importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
3999 CXXConstructorDecl *Ctor =
4000 importChecked(Err, Guide->getCorrespondingConstructor());
4001 if (Err)
4002 return std::move(Err);
4003 if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
4004 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
4005 NameInfo, T, TInfo, ToEndLoc, Ctor))
4006 return ToFunction;
4007 cast<CXXDeductionGuideDecl>(ToFunction)
4008 ->setDeductionCandidateKind(Guide->getDeductionCandidateKind());
4009 } else {
4010 if (GetImportedOrCreateDecl(
4011 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
4012 NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
4013 D->isInlineSpecified(), D->hasWrittenPrototype(),
4014 D->getConstexprKind(), TrailingRequiresClause))
4015 return ToFunction;
4016 }
4017
4018 // Connect the redecl chain.
4019 if (FoundByLookup) {
4020 auto *Recent = const_cast<FunctionDecl *>(
4021 FoundByLookup->getMostRecentDecl());
4022 ToFunction->setPreviousDecl(Recent);
4023 // FIXME Probably we should merge exception specifications. E.g. In the
4024 // "To" context the existing function may have exception specification with
4025 // noexcept-unevaluated, while the newly imported function may have an
4026 // evaluated noexcept. A call to adjustExceptionSpec() on the imported
4027 // decl and its redeclarations may be required.
4028 }
4029
4030 StringLiteral *Msg = D->getDeletedMessage();
4031 if (Msg) {
4032 auto Imported = import(Msg);
4033 if (!Imported)
4034 return Imported.takeError();
4035 Msg = *Imported;
4036 }
4037
4038 ToFunction->setQualifierInfo(ToQualifierLoc);
4039 ToFunction->setAccess(D->getAccess());
4040 ToFunction->setLexicalDeclContext(LexicalDC);
4041 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
4042 ToFunction->setTrivial(D->isTrivial());
4043 ToFunction->setIsPureVirtual(D->isPureVirtual());
4044 ToFunction->setDefaulted(D->isDefaulted());
4045 ToFunction->setExplicitlyDefaulted(D->isExplicitlyDefaulted());
4046 ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
4048 D->FriendConstraintRefersToEnclosingTemplate());
4049 ToFunction->setRangeEnd(ToEndLoc);
4050 ToFunction->setDefaultLoc(ToDefaultLoc);
4051
4052 if (Msg)
4053 ToFunction->setDefaultedOrDeletedInfo(
4055 Importer.getToContext(), {}, Msg));
4056
4057 // Set the parameters.
4058 for (auto *Param : Parameters) {
4059 Param->setOwningFunction(ToFunction);
4060 ToFunction->addDeclInternal(Param);
4061 if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
4062 LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
4063 }
4064 ToFunction->setParams(Parameters);
4065
4066 // We need to complete creation of FunctionProtoTypeLoc manually with setting
4067 // params it refers to.
4068 if (TInfo) {
4069 if (auto ProtoLoc =
4070 TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
4071 for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
4072 ProtoLoc.setParam(I, Parameters[I]);
4073 }
4074 }
4075
4076 // Import the describing template function, if any.
4077 if (FromFT) {
4078 auto ToFTOrErr = import(FromFT);
4079 if (!ToFTOrErr)
4080 return ToFTOrErr.takeError();
4081 }
4082
4083 // Import Ctor initializers.
4084 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4085 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
4086 SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
4087 // Import first, then allocate memory and copy if there was no error.
4088 if (Error Err = ImportContainerChecked(
4089 FromConstructor->inits(), CtorInitializers))
4090 return std::move(Err);
4091 auto **Memory =
4092 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4093 std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
4094 auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
4095 ToCtor->setCtorInitializers(Memory);
4096 ToCtor->setNumCtorInitializers(NumInitializers);
4097 }
4098 }
4099
4100 // If it is a template, import all related things.
4101 if (Error Err = ImportTemplateInformation(D, ToFunction))
4102 return std::move(Err);
4103
4104 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
4105 if (Error Err = ImportOverriddenMethods(cast<CXXMethodDecl>(ToFunction),
4106 FromCXXMethod))
4107 return std::move(Err);
4108
4109 if (D->doesThisDeclarationHaveABody()) {
4110 Error Err = ImportFunctionDeclBody(D, ToFunction);
4111
4112 if (Err)
4113 return std::move(Err);
4114 }
4115
4116 // Import and set the original type in case we used another type.
4117 if (UsedDifferentProtoType) {
4118 if (ExpectedType TyOrErr = import(D->getType()))
4119 ToFunction->setType(*TyOrErr);
4120 else
4121 return TyOrErr.takeError();
4122 if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
4123 ToFunction->setTypeSourceInfo(*TSIOrErr);
4124 else
4125 return TSIOrErr.takeError();
4126 }
4127
4128 // FIXME: Other bits to merge?
4129
4130 addDeclToContexts(D, ToFunction);
4131
4132 // Import the rest of the chain. I.e. import all subsequent declarations.
4133 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4134 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4135 if (!ToRedeclOrErr)
4136 return ToRedeclOrErr.takeError();
4137 }
4138
4139 return ToFunction;
4140}
4141
4143 return VisitFunctionDecl(D);
4144}
4145
4147 return VisitCXXMethodDecl(D);
4148}
4149
4151 return VisitCXXMethodDecl(D);
4152}
4153
4155 return VisitCXXMethodDecl(D);
4156}
4157
4160 return VisitFunctionDecl(D);
4161}
4162
4164 // Import the major distinguishing characteristics of a variable.
4165 DeclContext *DC, *LexicalDC;
4166 DeclarationName Name;
4168 NamedDecl *ToD;
4169 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4170 return std::move(Err);
4171 if (ToD)
4172 return ToD;
4173
4174 // Determine whether we've already imported this field.
4175 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4176 for (auto *FoundDecl : FoundDecls) {
4177 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4178 // For anonymous fields, match up by index.
4179 if (!Name &&
4181 ASTImporter::getFieldIndex(FoundField))
4182 continue;
4183
4184 if (Importer.IsStructurallyEquivalent(D->getType(),
4185 FoundField->getType())) {
4186 Importer.MapImported(D, FoundField);
4187 // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4188 // initializer of a FieldDecl might not had been instantiated in the
4189 // "To" context. However, the "From" context might instantiated that,
4190 // thus we have to merge that.
4191 // Note: `hasInClassInitializer()` is not the same as non-null
4192 // `getInClassInitializer()` value.
4193 if (Expr *FromInitializer = D->getInClassInitializer()) {
4194 if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4195 // Import of the FromInitializer may result in the setting of
4196 // InClassInitializer. If not, set it here.
4197 assert(FoundField->hasInClassInitializer() &&
4198 "Field should have an in-class initializer if it has an "
4199 "expression for it.");
4200 if (!FoundField->getInClassInitializer())
4201 FoundField->setInClassInitializer(*ToInitializerOrErr);
4202 } else {
4203 return ToInitializerOrErr.takeError();
4204 }
4205 }
4206 return FoundField;
4207 }
4208
4209 // FIXME: Why is this case not handled with calling HandleNameConflict?
4210 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4211 << Name << D->getType() << FoundField->getType();
4212 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4213 << FoundField->getType();
4214
4215 return make_error<ASTImportError>(ASTImportError::NameConflict);
4216 }
4217 }
4218
4219 Error Err = Error::success();
4220 auto ToType = importChecked(Err, D->getType());
4221 auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4222 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4223 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4224 if (Err)
4225 return std::move(Err);
4226 const Type *ToCapturedVLAType = nullptr;
4227 if (Error Err = Importer.importInto(
4228 ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4229 return std::move(Err);
4230
4231 FieldDecl *ToField;
4232 if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4233 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4234 ToType, ToTInfo, ToBitWidth, D->isMutable(),
4235 D->getInClassInitStyle()))
4236 return ToField;
4237
4238 ToField->setAccess(D->getAccess());
4239 ToField->setLexicalDeclContext(LexicalDC);
4240 ToField->setImplicit(D->isImplicit());
4241 if (ToCapturedVLAType)
4242 ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4243 LexicalDC->addDeclInternal(ToField);
4244 // Import initializer only after the field was created, it may have recursive
4245 // reference to the field.
4246 auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4247 if (Err)
4248 return std::move(Err);
4249 if (ToInitializer) {
4250 auto *AlreadyImported = ToField->getInClassInitializer();
4251 if (AlreadyImported)
4252 assert(ToInitializer == AlreadyImported &&
4253 "Duplicate import of in-class initializer.");
4254 else
4255 ToField->setInClassInitializer(ToInitializer);
4256 }
4257
4258 return ToField;
4259}
4260
4262 // Import the major distinguishing characteristics of a variable.
4263 DeclContext *DC, *LexicalDC;
4264 DeclarationName Name;
4266 NamedDecl *ToD;
4267 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4268 return std::move(Err);
4269 if (ToD)
4270 return ToD;
4271
4272 // Determine whether we've already imported this field.
4273 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4274 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4275 if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4276 // For anonymous indirect fields, match up by index.
4277 if (!Name &&
4279 ASTImporter::getFieldIndex(FoundField))
4280 continue;
4281
4282 if (Importer.IsStructurallyEquivalent(D->getType(),
4283 FoundField->getType(),
4284 !Name.isEmpty())) {
4285 Importer.MapImported(D, FoundField);
4286 return FoundField;
4287 }
4288
4289 // If there are more anonymous fields to check, continue.
4290 if (!Name && I < N-1)
4291 continue;
4292
4293 // FIXME: Why is this case not handled with calling HandleNameConflict?
4294 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4295 << Name << D->getType() << FoundField->getType();
4296 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4297 << FoundField->getType();
4298
4299 return make_error<ASTImportError>(ASTImportError::NameConflict);
4300 }
4301 }
4302
4303 // Import the type.
4304 auto TypeOrErr = import(D->getType());
4305 if (!TypeOrErr)
4306 return TypeOrErr.takeError();
4307
4308 auto **NamedChain =
4309 new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4310
4311 unsigned i = 0;
4312 for (auto *PI : D->chain())
4313 if (Expected<NamedDecl *> ToD = import(PI))
4314 NamedChain[i++] = *ToD;
4315 else
4316 return ToD.takeError();
4317
4318 llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()};
4319 IndirectFieldDecl *ToIndirectField;
4320 if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4321 Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4322 // FIXME here we leak `NamedChain` which is allocated before
4323 return ToIndirectField;
4324
4325 ToIndirectField->setAccess(D->getAccess());
4326 ToIndirectField->setLexicalDeclContext(LexicalDC);
4327 LexicalDC->addDeclInternal(ToIndirectField);
4328 return ToIndirectField;
4329}
4330
4331/// Used as return type of getFriendCountAndPosition.
4333 /// Number of similar looking friends.
4334 unsigned int TotalCount;
4335 /// Index of the specific FriendDecl.
4336 unsigned int IndexOfDecl;
4337};
4338
4339static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4340 FriendDecl *FD2) {
4341 if ((!FD1->getFriendType()) != (!FD2->getFriendType()))
4342 return false;
4343
4344 if (const TypeSourceInfo *TSI = FD1->getFriendType())
4345 return Importer.IsStructurallyEquivalent(
4346 TSI->getType(), FD2->getFriendType()->getType(), /*Complain=*/false);
4347
4348 ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4350 FD1->getASTContext(), FD2->getASTContext(), NonEquivalentDecls,
4352 /* StrictTypeSpelling = */ false, /* Complain = */ false);
4353 return Ctx.IsEquivalent(FD1, FD2);
4354}
4355
4357 FriendDecl *FD) {
4358 unsigned int FriendCount = 0;
4359 std::optional<unsigned int> FriendPosition;
4360 const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4361
4362 for (FriendDecl *FoundFriend : RD->friends()) {
4363 if (FoundFriend == FD) {
4364 FriendPosition = FriendCount;
4365 ++FriendCount;
4366 } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4367 ++FriendCount;
4368 }
4369 }
4370
4371 assert(FriendPosition && "Friend decl not found in own parent.");
4372
4373 return {FriendCount, *FriendPosition};
4374}
4375
4377 // Import the major distinguishing characteristics of a declaration.
4378 DeclContext *DC, *LexicalDC;
4379 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4380 return std::move(Err);
4381
4382 // Determine whether we've already imported this decl.
4383 // FriendDecl is not a NamedDecl so we cannot use lookup.
4384 // We try to maintain order and count of redundant friend declarations.
4385 const auto *RD = cast<CXXRecordDecl>(DC);
4386 SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4387 for (FriendDecl *ImportedFriend : RD->friends())
4388 if (IsEquivalentFriend(Importer, D, ImportedFriend))
4389 ImportedEquivalentFriends.push_back(ImportedFriend);
4390
4391 FriendCountAndPosition CountAndPosition =
4392 getFriendCountAndPosition(Importer, D);
4393
4394 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4395 "Class with non-matching friends is imported, ODR check wrong?");
4396 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4397 return Importer.MapImported(
4398 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4399
4400 // Not found. Create it.
4401 // The declarations will be put into order later by ImportDeclContext.
4403 if (NamedDecl *FriendD = D->getFriendDecl()) {
4404 NamedDecl *ToFriendD;
4405 if (Error Err = importInto(ToFriendD, FriendD))
4406 return std::move(Err);
4407
4408 if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4409 !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator)))
4410 ToFriendD->setObjectOfFriendDecl(false);
4411
4412 ToFU = ToFriendD;
4413 } else { // The friend is a type, not a decl.
4414 if (auto TSIOrErr = import(D->getFriendType()))
4415 ToFU = *TSIOrErr;
4416 else
4417 return TSIOrErr.takeError();
4418 }
4419
4420 SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
4421 auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>();
4422 for (unsigned I = 0; I < D->NumTPLists; I++) {
4423 if (auto ListOrErr = import(FromTPLists[I]))
4424 ToTPLists[I] = *ListOrErr;
4425 else
4426 return ListOrErr.takeError();
4427 }
4428
4429 auto LocationOrErr = import(D->getLocation());
4430 if (!LocationOrErr)
4431 return LocationOrErr.takeError();
4432 auto FriendLocOrErr = import(D->getFriendLoc());
4433 if (!FriendLocOrErr)
4434 return FriendLocOrErr.takeError();
4435 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4436 if (!EllipsisLocOrErr)
4437 return EllipsisLocOrErr.takeError();
4438
4439 FriendDecl *FrD;
4440 if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4441 *LocationOrErr, ToFU, *FriendLocOrErr,
4442 *EllipsisLocOrErr, ToTPLists))
4443 return FrD;
4444
4445 FrD->setAccess(D->getAccess());
4446 FrD->setLexicalDeclContext(LexicalDC);
4447 LexicalDC->addDeclInternal(FrD);
4448 return FrD;
4449}
4450
4452 // Import the major distinguishing characteristics of an ivar.
4453 DeclContext *DC, *LexicalDC;
4454 DeclarationName Name;
4456 NamedDecl *ToD;
4457 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4458 return std::move(Err);
4459 if (ToD)
4460 return ToD;
4461
4462 // Determine whether we've already imported this ivar
4463 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4464 for (auto *FoundDecl : FoundDecls) {
4465 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4466 if (Importer.IsStructurallyEquivalent(D->getType(),
4467 FoundIvar->getType())) {
4468 Importer.MapImported(D, FoundIvar);
4469 return FoundIvar;
4470 }
4471
4472 Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4473 << Name << D->getType() << FoundIvar->getType();
4474 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4475 << FoundIvar->getType();
4476
4477 return make_error<ASTImportError>(ASTImportError::NameConflict);
4478 }
4479 }
4480
4481 Error Err = Error::success();
4482 auto ToType = importChecked(Err, D->getType());
4483 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4484 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4485 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4486 if (Err)
4487 return std::move(Err);
4488
4489 ObjCIvarDecl *ToIvar;
4490 if (GetImportedOrCreateDecl(
4491 ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4492 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4493 ToType, ToTypeSourceInfo,
4494 D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4495 return ToIvar;
4496
4497 ToIvar->setLexicalDeclContext(LexicalDC);
4498 LexicalDC->addDeclInternal(ToIvar);
4499 return ToIvar;
4500}
4501
4503
4505 auto RedeclIt = Redecls.begin();
4506 // Import the first part of the decl chain. I.e. import all previous
4507 // declarations starting from the canonical decl.
4508 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4509 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4510 if (!RedeclOrErr)
4511 return RedeclOrErr.takeError();
4512 }
4513 assert(*RedeclIt == D);
4514
4515 // Import the major distinguishing characteristics of a variable.
4516 DeclContext *DC, *LexicalDC;
4517 DeclarationName Name;
4519 NamedDecl *ToD;
4520 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4521 return std::move(Err);
4522 if (ToD)
4523 return ToD;
4524
4525 // Try to find a variable in our own ("to") context with the same name and
4526 // in the same context as the variable we're importing.
4527 VarDecl *FoundByLookup = nullptr;
4528 if (D->isFileVarDecl()) {
4529 SmallVector<NamedDecl *, 4> ConflictingDecls;
4530 unsigned IDNS = Decl::IDNS_Ordinary;
4531 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4532 for (auto *FoundDecl : FoundDecls) {
4533 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4534 continue;
4535
4536 if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4537 if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4538 continue;
4539 if (Importer.IsStructurallyEquivalent(D->getType(),
4540 FoundVar->getType())) {
4541
4542 // The VarDecl in the "From" context has a definition, but in the
4543 // "To" context we already have a definition.
4544 VarDecl *FoundDef = FoundVar->getDefinition();
4545 if (D->isThisDeclarationADefinition() && FoundDef)
4546 // FIXME Check for ODR error if the two definitions have
4547 // different initializers?
4548 return Importer.MapImported(D, FoundDef);
4549
4550 // The VarDecl in the "From" context has an initializer, but in the
4551 // "To" context we already have an initializer.
4552 const VarDecl *FoundDInit = nullptr;
4553 if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4554 // FIXME Diagnose ODR error if the two initializers are different?
4555 return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4556
4557 FoundByLookup = FoundVar;
4558 break;
4559 }
4560
4561 const ArrayType *FoundArray
4562 = Importer.getToContext().getAsArrayType(FoundVar->getType());
4563 const ArrayType *TArray
4564 = Importer.getToContext().getAsArrayType(D->getType());
4565 if (FoundArray && TArray) {
4566 if (isa<IncompleteArrayType>(FoundArray) &&
4567 isa<ConstantArrayType>(TArray)) {
4568 // Import the type.
4569 if (auto TyOrErr = import(D->getType()))
4570 FoundVar->setType(*TyOrErr);
4571 else
4572 return TyOrErr.takeError();
4573
4574 FoundByLookup = FoundVar;
4575 break;
4576 } else if (isa<IncompleteArrayType>(TArray) &&
4577 isa<ConstantArrayType>(FoundArray)) {
4578 FoundByLookup = FoundVar;
4579 break;
4580 }
4581 }
4582
4583 Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4584 << Name << D->getType() << FoundVar->getType();
4585 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4586 << FoundVar->getType();
4587 ConflictingDecls.push_back(FoundDecl);
4588 }
4589 }
4590
4591 if (!ConflictingDecls.empty()) {
4592 ExpectedName NameOrErr = Importer.HandleNameConflict(
4593 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4594 if (NameOrErr)
4595 Name = NameOrErr.get();
4596 else
4597 return NameOrErr.takeError();
4598 }
4599 }
4600
4601 Error Err = Error::success();
4602 auto ToType = importChecked(Err, D->getType());
4603 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4604 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4605 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4606 if (Err)
4607 return std::move(Err);
4608
4609 VarDecl *ToVar;
4610 if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4611 SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4612 if (Error Err =
4613 ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4614 return std::move(Err);
4615 DecompositionDecl *ToDecomp;
4616 if (GetImportedOrCreateDecl(
4617 ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4618 Loc, ToType, ToTypeSourceInfo, D->getStorageClass(), Bindings))
4619 return ToDecomp;
4620 ToVar = ToDecomp;
4621 } else {
4622 // Create the imported variable.
4623 if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4624 ToInnerLocStart, Loc,
4625 Name.getAsIdentifierInfo(), ToType,
4626 ToTypeSourceInfo, D->getStorageClass()))
4627 return ToVar;
4628 }
4629
4630 ToVar->setTSCSpec(D->getTSCSpec());
4631 ToVar->setQualifierInfo(ToQualifierLoc);
4632 ToVar->setAccess(D->getAccess());
4633 ToVar->setLexicalDeclContext(LexicalDC);
4634 if (D->isInlineSpecified())
4635 ToVar->setInlineSpecified();
4636 if (D->isInline())
4637 ToVar->setImplicitlyInline();
4638
4639 if (FoundByLookup) {
4640 auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4641 ToVar->setPreviousDecl(Recent);
4642 }
4643
4644 // Import the described template, if any.
4645 if (D->getDescribedVarTemplate()) {
4646 auto ToVTOrErr = import(D->getDescribedVarTemplate());
4647 if (!ToVTOrErr)
4648 return ToVTOrErr.takeError();
4649 } else if (MemberSpecializationInfo *MSI = D->getMemberSpecializationInfo()) {
4650 TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4651 VarDecl *FromInst = D->getInstantiatedFromStaticDataMember();
4652 if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4653 ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4654 else
4655 return ToInstOrErr.takeError();
4656 if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4658 else
4659 return POIOrErr.takeError();
4660 }
4661
4662 if (Error Err = ImportInitializer(D, ToVar))
4663 return std::move(Err);
4664
4665 if (D->isConstexpr())
4666 ToVar->setConstexpr(true);
4667
4668 addDeclToContexts(D, ToVar);
4669
4670 // Import the rest of the chain. I.e. import all subsequent declarations.
4671 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4672 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4673 if (!RedeclOrErr)
4674 return RedeclOrErr.takeError();
4675 }
4676
4677 return ToVar;
4678}
4679
4681 // Parameters are created in the translation unit's context, then moved
4682 // into the function declaration's context afterward.
4684
4685 Error Err = Error::success();
4686 auto ToDeclName = importChecked(Err, D->getDeclName());
4687 auto ToLocation = importChecked(Err, D->getLocation());
4688 auto ToType = importChecked(Err, D->getType());
4689 if (Err)
4690 return std::move(Err);
4691
4692 // Create the imported parameter.
4693 ImplicitParamDecl *ToParm = nullptr;
4694 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4695 ToLocation, ToDeclName.getAsIdentifierInfo(),
4696 ToType, D->getParameterKind()))
4697 return ToParm;
4698 return ToParm;
4699}
4700
4702 const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4705 FromParam->getExplicitObjectParamThisLoc());
4706 ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4707
4708 if (FromParam->hasUninstantiatedDefaultArg()) {
4709 if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4710 ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4711 else
4712 return ToDefArgOrErr.takeError();
4713 } else if (FromParam->hasUnparsedDefaultArg()) {
4714 ToParam->setUnparsedDefaultArg();
4715 } else if (FromParam->hasDefaultArg()) {
4716 if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4717 ToParam->setDefaultArg(*ToDefArgOrErr);
4718 else
4719 return ToDefArgOrErr.takeError();
4720 }
4721
4722 return Error::success();
4723}
4724
4727 Error Err = Error::success();
4728 CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4729 ConstructorUsingShadowDecl *ToShadow =
4730 importChecked(Err, From.getShadowDecl());
4731 if (Err)
4732 return std::move(Err);
4733 return InheritedConstructor(ToShadow, ToBaseCtor);
4734}
4735
4737 // Parameters are created in the translation unit's context, then moved
4738 // into the function declaration's context afterward.
4740
4741 Error Err = Error::success();
4742 auto ToDeclName = importChecked(Err, D->getDeclName());
4743 auto ToLocation = importChecked(Err, D->getLocation());
4744 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4745 auto ToType = importChecked(Err, D->getType());
4746 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4747 if (Err)
4748 return std::move(Err);
4749
4750 ParmVarDecl *ToParm;
4751 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4752 ToInnerLocStart, ToLocation,
4753 ToDeclName.getAsIdentifierInfo(), ToType,
4754 ToTypeSourceInfo, D->getStorageClass(),
4755 /*DefaultArg*/ nullptr))
4756 return ToParm;
4757
4758 // Set the default argument. It should be no problem if it was already done.
4759 // Do not import the default expression before GetImportedOrCreateDecl call
4760 // to avoid possible infinite import loop because circular dependency.
4761 if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4762 return std::move(Err);
4763
4764 if (D->isObjCMethodParameter()) {
4765 ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex());
4766 ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier());
4767 } else {
4768 ToParm->setScopeInfo(D->getFunctionScopeDepth(),
4769 D->getFunctionScopeIndex());
4770 }
4771
4772 return ToParm;
4773}
4774
4776 // Import the major distinguishing characteristics of a method.
4777 DeclContext *DC, *LexicalDC;
4778 DeclarationName Name;
4780 NamedDecl *ToD;
4781 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4782 return std::move(Err);
4783 if (ToD)
4784 return ToD;
4785
4786 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4787 for (auto *FoundDecl : FoundDecls) {
4788 if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
4789 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
4790 continue;
4791
4792 // Check return types.
4793 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
4794 FoundMethod->getReturnType())) {
4795 Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
4796 << D->isInstanceMethod() << Name << D->getReturnType()
4797 << FoundMethod->getReturnType();
4798 Importer.ToDiag(FoundMethod->getLocation(),
4799 diag::note_odr_objc_method_here)
4800 << D->isInstanceMethod() << Name;
4801
4802 return make_error<ASTImportError>(ASTImportError::NameConflict);
4803 }
4804
4805 // Check the number of parameters.
4806 if (D->param_size() != FoundMethod->param_size()) {
4807 Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
4808 << D->isInstanceMethod() << Name
4809 << D->param_size() << FoundMethod->param_size();
4810 Importer.ToDiag(FoundMethod->getLocation(),
4811 diag::note_odr_objc_method_here)
4812 << D->isInstanceMethod() << Name;
4813
4814 return make_error<ASTImportError>(ASTImportError::NameConflict);
4815 }
4816
4817 // Check parameter types.
4818 for (ObjCMethodDecl::param_iterator P = D->param_begin(),
4819 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
4820 P != PEnd; ++P, ++FoundP) {
4821 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
4822 (*FoundP)->getType())) {
4823 Importer.FromDiag((*P)->getLocation(),
4824 diag::warn_odr_objc_method_param_type_inconsistent)
4825 << D->isInstanceMethod() << Name
4826 << (*P)->getType() << (*FoundP)->getType();
4827 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
4828 << (*FoundP)->getType();
4829
4830 return make_error<ASTImportError>(ASTImportError::NameConflict);
4831 }
4832 }
4833
4834 // Check variadic/non-variadic.
4835 // Check the number of parameters.
4836 if (D->isVariadic() != FoundMethod->isVariadic()) {
4837 Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
4838 << D->isInstanceMethod() << Name;
4839 Importer.ToDiag(FoundMethod->getLocation(),
4840 diag::note_odr_objc_method_here)
4841 << D->isInstanceMethod() << Name;
4842
4843 return make_error<ASTImportError>(ASTImportError::NameConflict);
4844 }
4845
4846 // FIXME: Any other bits we need to merge?
4847 return Importer.MapImported(D, FoundMethod);
4848 }
4849 }
4850
4851 Error Err = Error::success();
4852 auto ToEndLoc = importChecked(Err, D->getEndLoc());
4853 auto ToReturnType = importChecked(Err, D->getReturnType());
4854 auto ToReturnTypeSourceInfo =
4855 importChecked(Err, D->getReturnTypeSourceInfo());
4856 if (Err)
4857 return std::move(Err);
4858
4859 ObjCMethodDecl *ToMethod;
4860 if (GetImportedOrCreateDecl(
4861 ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
4862 Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
4863 D->isInstanceMethod(), D->isVariadic(), D->isPropertyAccessor(),
4864 D->isSynthesizedAccessorStub(), D->isImplicit(), D->isDefined(),
4865 D->getImplementationControl(), D->hasRelatedResultType()))
4866 return ToMethod;
4867
4868 // FIXME: When we decide to merge method definitions, we'll need to
4869 // deal with implicit parameters.
4870
4871 // Import the parameters
4873 for (auto *FromP : D->parameters()) {
4874 if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
4875 ToParams.push_back(*ToPOrErr);
4876 else
4877 return ToPOrErr.takeError();
4878 }
4879
4880 // Set the parameters.
4881 for (auto *ToParam : ToParams) {
4882 ToParam->setOwningFunction(ToMethod);
4883 ToMethod->addDeclInternal(ToParam);
4884 }
4885
4887 D->getSelectorLocs(FromSelLocs);
4888 SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
4889 if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
4890 return std::move(Err);
4891
4892 ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
4893
4894 ToMethod->setLexicalDeclContext(LexicalDC);
4895 LexicalDC->addDeclInternal(ToMethod);
4896
4897 // Implicit params are declared when Sema encounters the definition but this
4898 // never happens when the method is imported. Manually declare the implicit
4899 // params now that the MethodDecl knows its class interface.
4900 if (D->getSelfDecl())
4901 ToMethod->createImplicitParams(Importer.getToContext(),
4902 ToMethod->getClassInterface());
4903
4904 return ToMethod;
4905}
4906
4908 // Import the major distinguishing characteristics of a category.
4909 DeclContext *DC, *LexicalDC;
4910 DeclarationName Name;
4912 NamedDecl *ToD;
4913 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4914 return std::move(Err);
4915 if (ToD)
4916 return ToD;
4917
4918 Error Err = Error::success();
4919 auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
4920 auto ToLocation = importChecked(Err, D->getLocation());
4921 auto ToColonLoc = importChecked(Err, D->getColonLoc());
4922 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4923 if (Err)
4924 return std::move(Err);
4925
4927 if (GetImportedOrCreateDecl(
4928 Result, D, Importer.getToContext(), DC, D->getVariance(),
4929 ToVarianceLoc, D->getIndex(),
4930 ToLocation, Name.getAsIdentifierInfo(),
4931 ToColonLoc, ToTypeSourceInfo))
4932 return Result;
4933
4934 // Only import 'ObjCTypeParamType' after the decl is created.
4935 auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
4936 if (Err)
4937 return std::move(Err);
4938 Result->setTypeForDecl(ToTypeForDecl);
4939 Result->setLexicalDeclContext(LexicalDC);
4940 return Result;
4941}
4942
4944 // Import the major distinguishing characteristics of a category.
4945 DeclContext *DC, *LexicalDC;
4946 DeclarationName Name;
4948 NamedDecl *ToD;
4949 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4950 return std::move(Err);
4951 if (ToD)
4952 return ToD;
4953
4954 ObjCInterfaceDecl *ToInterface;
4955 if (Error Err = importInto(ToInterface, D->getClassInterface()))
4956 return std::move(Err);
4957
4958 // Determine if we've already encountered this category.
4959 ObjCCategoryDecl *MergeWithCategory
4960 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
4961 ObjCCategoryDecl *ToCategory = MergeWithCategory;
4962 if (!ToCategory) {
4963
4964 Error Err = Error::success();
4965 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
4966 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
4967 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
4968 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
4969 if (Err)
4970 return std::move(Err);
4971
4972 if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
4973 ToAtStartLoc, Loc,
4974 ToCategoryNameLoc,
4975 Name.getAsIdentifierInfo(), ToInterface,
4976 /*TypeParamList=*/nullptr,
4977 ToIvarLBraceLoc,
4978 ToIvarRBraceLoc))
4979 return ToCategory;
4980
4981 ToCategory->setLexicalDeclContext(LexicalDC);
4982 LexicalDC->addDeclInternal(ToCategory);
4983 // Import the type parameter list after MapImported, to avoid
4984 // loops when bringing in their DeclContext.
4985 if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
4986 ToCategory->setTypeParamList(*PListOrErr);
4987 else
4988 return PListOrErr.takeError();
4989
4990 // Import protocols
4992 SmallVector<SourceLocation, 4> ProtocolLocs;
4994 = D->protocol_loc_begin();
4995 for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(),
4996 FromProtoEnd = D->protocol_end();
4997 FromProto != FromProtoEnd;
4998 ++FromProto, ++FromProtoLoc) {
4999 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5000 Protocols.push_back(*ToProtoOrErr);
5001 else
5002 return ToProtoOrErr.takeError();
5003
5004 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5005 ProtocolLocs.push_back(*ToProtoLocOrErr);
5006 else
5007 return ToProtoLocOrErr.takeError();
5008 }
5009
5010 // FIXME: If we're merging, make sure that the protocol list is the same.
5011 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
5012 ProtocolLocs.data(), Importer.getToContext());
5013
5014 } else {
5015 Importer.MapImported(D, ToCategory);
5016 }
5017
5018 // Import all of the members of this category.
5019 if (Error Err = ImportDeclContext(D))
5020 return std::move(Err);
5021
5022 // If we have an implementation, import it as well.
5023 if (D->getImplementation()) {
5024 if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
5025 import(D->getImplementation()))
5026 ToCategory->setImplementation(*ToImplOrErr);
5027 else
5028 return ToImplOrErr.takeError();
5029 }
5030
5031 return ToCategory;
5032}
5033
5036 if (To->getDefinition()) {
5038 if (Error Err = ImportDeclContext(From))
5039 return Err;
5040 return Error::success();
5041 }
5042
5043 // Start the protocol definition
5044 To->startDefinition();
5045
5046 // Import protocols
5048 SmallVector<SourceLocation, 4> ProtocolLocs;
5050 From->protocol_loc_begin();
5051 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
5052 FromProtoEnd = From->protocol_end();
5053 FromProto != FromProtoEnd;
5054 ++FromProto, ++FromProtoLoc) {
5055 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5056 Protocols.push_back(*ToProtoOrErr);
5057 else
5058 return ToProtoOrErr.takeError();
5059
5060 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5061 ProtocolLocs.push_back(*ToProtoLocOrErr);
5062 else
5063 return ToProtoLocOrErr.takeError();
5064
5065 }
5066
5067 // FIXME: If we're merging, make sure that the protocol list is the same.
5068 To->setProtocolList(Protocols.data(), Protocols.size(),
5069 ProtocolLocs.data(), Importer.getToContext());
5070
5071 if (shouldForceImportDeclContext(Kind)) {
5072 // Import all of the members of this protocol.
5073 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5074 return Err;
5075 }
5076 return Error::success();
5077}
5078
5080 // If this protocol has a definition in the translation unit we're coming
5081 // from, but this particular declaration is not that definition, import the
5082 // definition and map to that.
5083 ObjCProtocolDecl *Definition = D->getDefinition();
5084 if (Definition && Definition != D) {
5085 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5086 return Importer.MapImported(D, *ImportedDefOrErr);
5087 else
5088 return ImportedDefOrErr.takeError();
5089 }
5090
5091 // Import the major distinguishing characteristics of a protocol.
5092 DeclContext *DC, *LexicalDC;
5093 DeclarationName Name;
5095 NamedDecl *ToD;
5096 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5097 return std::move(Err);
5098 if (ToD)
5099 return ToD;
5100
5101 ObjCProtocolDecl *MergeWithProtocol = nullptr;
5102 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5103 for (auto *FoundDecl : FoundDecls) {
5105 continue;
5106
5107 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
5108 break;
5109 }
5110
5111 ObjCProtocolDecl *ToProto = MergeWithProtocol;
5112 if (!ToProto) {
5113 auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
5114 if (!ToAtBeginLocOrErr)
5115 return ToAtBeginLocOrErr.takeError();
5116
5117 if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
5118 Name.getAsIdentifierInfo(), Loc,
5119 *ToAtBeginLocOrErr,
5120 /*PrevDecl=*/nullptr))
5121 return ToProto;
5122 ToProto->setLexicalDeclContext(LexicalDC);
5123 LexicalDC->addDeclInternal(ToProto);
5124 }
5125
5126 Importer.MapImported(D, ToProto);
5127
5128 if (D->isThisDeclarationADefinition())
5129 if (Error Err = ImportDefinition(D, ToProto))
5130 return std::move(Err);
5131
5132 return ToProto;
5133}
5134
5136 DeclContext *DC, *LexicalDC;
5137 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5138 return std::move(Err);
5139
5140 ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5141 if (!ExternLocOrErr)
5142 return ExternLocOrErr.takeError();
5143
5144 ExpectedSLoc LangLocOrErr = import(D->getLocation());
5145 if (!LangLocOrErr)
5146 return LangLocOrErr.takeError();
5147
5148 bool HasBraces = D->hasBraces();
5149
5150 LinkageSpecDecl *ToLinkageSpec;
5151 if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5152 *ExternLocOrErr, *LangLocOrErr,
5153 D->getLanguage(), HasBraces))
5154 return ToLinkageSpec;
5155
5156 if (HasBraces) {
5157 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5158 if (!RBraceLocOrErr)
5159 return RBraceLocOrErr.takeError();
5160 ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5161 }
5162
5163 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5164 LexicalDC->addDeclInternal(ToLinkageSpec);
5165
5166 return ToLinkageSpec;
5167}
5168
5170 BaseUsingDecl *ToSI) {
5171 for (UsingShadowDecl *FromShadow : D->shadows()) {
5172 if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5173 ToSI->addShadowDecl(*ToShadowOrErr);
5174 else
5175 // FIXME: We return error here but the definition is already created
5176 // and available with lookups. How to fix this?..
5177 return ToShadowOrErr.takeError();
5178 }
5179 return ToSI;
5180}
5181
5183 DeclContext *DC, *LexicalDC;
5184 DeclarationName Name;
5186 NamedDecl *ToD = nullptr;
5187 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5188 return std::move(Err);
5189 if (ToD)
5190 return ToD;
5191
5192 Error Err = Error::success();
5193 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5194 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5195 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5196 if (Err)
5197 return std::move(Err);
5198
5199 DeclarationNameInfo NameInfo(Name, ToLoc);
5200 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5201 return std::move(Err);
5202
5203 UsingDecl *ToUsing;
5204 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5205 ToUsingLoc, ToQualifierLoc, NameInfo,
5206 D->hasTypename()))
5207 return ToUsing;
5208
5209 ToUsing->setLexicalDeclContext(LexicalDC);
5210 LexicalDC->addDeclInternal(ToUsing);
5211
5212 if (NamedDecl *FromPattern =
5214 if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5216 ToUsing, *ToPatternOrErr);
5217 else
5218 return ToPatternOrErr.takeError();
5219 }
5220
5221 return ImportUsingShadowDecls(D, ToUsing);
5222}
5223
5225 DeclContext *DC, *LexicalDC;
5226 DeclarationName Name;
5228 NamedDecl *ToD = nullptr;
5229 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5230 return std::move(Err);
5231 if (ToD)
5232 return ToD;
5233
5234 Error Err = Error::success();
5235 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5236 auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5237 auto ToNameLoc = importChecked(Err, D->getLocation());
5238 auto *ToEnumType = importChecked(Err, D->getEnumType());
5239 if (Err)
5240 return std::move(Err);
5241
5242 UsingEnumDecl *ToUsingEnum;
5243 if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5244 ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5245 return ToUsingEnum;
5246
5247 ToUsingEnum->setLexicalDeclContext(LexicalDC);
5248 LexicalDC->addDeclInternal(ToUsingEnum);
5249
5250 if (UsingEnumDecl *FromPattern =
5252 if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5253 Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5254 *ToPatternOrErr);
5255 else
5256 return ToPatternOrErr.takeError();
5257 }
5258
5259 return ImportUsingShadowDecls(D, ToUsingEnum);
5260}
5261
5263 DeclContext *DC, *LexicalDC;
5264 DeclarationName Name;
5266 NamedDecl *ToD = nullptr;
5267 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5268 return std::move(Err);
5269 if (ToD)
5270 return ToD;
5271
5272 Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5273 if (!ToIntroducerOrErr)
5274 return ToIntroducerOrErr.takeError();
5275
5276 Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5277 if (!ToTargetOrErr)
5278 return ToTargetOrErr.takeError();
5279
5280 UsingShadowDecl *ToShadow;
5281 if (auto *FromConstructorUsingShadow =
5282 dyn_cast<ConstructorUsingShadowDecl>(D)) {
5283 Error Err = Error::success();
5285 Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5286 if (Err)
5287 return std::move(Err);
5288 // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5289 // is really the "NominatedBaseClassShadowDecl" value if it exists
5290 // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5291 // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5292 // get the correct values.
5293 if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5294 ToShadow, D, Importer.getToContext(), DC, Loc,
5295 cast<UsingDecl>(*ToIntroducerOrErr),
5296 Nominated ? Nominated : *ToTargetOrErr,
5297 FromConstructorUsingShadow->constructsVirtualBase()))
5298 return ToShadow;
5299 } else {
5300 if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5301 Name, *ToIntroducerOrErr, *ToTargetOrErr))
5302 return ToShadow;
5303 }
5304
5305 ToShadow->setLexicalDeclContext(LexicalDC);
5306 ToShadow->setAccess(D->getAccess());
5307
5308 if (UsingShadowDecl *FromPattern =
5310 if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5312 ToShadow, *ToPatternOrErr);
5313 else
5314 // FIXME: We return error here but the definition is already created
5315 // and available with lookups. How to fix this?..
5316 return ToPatternOrErr.takeError();
5317 }
5318
5319 LexicalDC->addDeclInternal(ToShadow);
5320
5321 return ToShadow;
5322}
5323
5325 DeclContext *DC, *LexicalDC;
5326 DeclarationName Name;
5328 NamedDecl *ToD = nullptr;
5329 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5330 return std::move(Err);
5331 if (ToD)
5332 return ToD;
5333
5334 auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5335 if (!ToComAncestorOrErr)
5336 return ToComAncestorOrErr.takeError();
5337
5338 Error Err = Error::success();
5339 auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5340 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5341 auto ToNamespaceKeyLocation =
5342 importChecked(Err, D->getNamespaceKeyLocation());
5343 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5344 auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5345 if (Err)
5346 return std::move(Err);
5347
5348 UsingDirectiveDecl *ToUsingDir;
5349 if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5350 ToUsingLoc,
5351 ToNamespaceKeyLocation,
5352 ToQualifierLoc,
5353 ToIdentLocation,
5354 ToNominatedNamespace, *ToComAncestorOrErr))
5355 return ToUsingDir;
5356
5357 ToUsingDir->setLexicalDeclContext(LexicalDC);
5358 LexicalDC->addDeclInternal(ToUsingDir);
5359
5360 return ToUsingDir;
5361}
5362
5364 DeclContext *DC, *LexicalDC;
5365 DeclarationName Name;
5367 NamedDecl *ToD = nullptr;
5368 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5369 return std::move(Err);
5370 if (ToD)
5371 return ToD;
5372
5373 auto ToInstantiatedFromUsingOrErr =
5374 Importer.Import(D->getInstantiatedFromUsingDecl());
5375 if (!ToInstantiatedFromUsingOrErr)
5376 return ToInstantiatedFromUsingOrErr.takeError();
5377 SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5378 if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5379 return std::move(Err);
5380
5381 UsingPackDecl *ToUsingPack;
5382 if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5383 cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5384 Expansions))
5385 return ToUsingPack;
5386
5387 addDeclToContexts(D, ToUsingPack);
5388
5389 return ToUsingPack;
5390}
5391
5394 DeclContext *DC, *LexicalDC;
5395 DeclarationName Name;
5397 NamedDecl *ToD = nullptr;
5398 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5399 return std::move(Err);
5400 if (ToD)
5401 return ToD;
5402
5403 Error Err = Error::success();
5404 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5405 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5406 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5407 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5408 if (Err)
5409 return std::move(Err);
5410
5411 DeclarationNameInfo NameInfo(Name, ToLoc);
5412 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5413 return std::move(Err);
5414
5415 UnresolvedUsingValueDecl *ToUsingValue;
5416 if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5417 ToUsingLoc, ToQualifierLoc, NameInfo,
5418 ToEllipsisLoc))
5419 return ToUsingValue;
5420
5421 ToUsingValue->setAccess(D->getAccess());
5422 ToUsingValue->setLexicalDeclContext(LexicalDC);
5423 LexicalDC->addDeclInternal(ToUsingValue);
5424
5425 return ToUsingValue;
5426}
5427
5430 DeclContext *DC, *LexicalDC;
5431 DeclarationName Name;
5433 NamedDecl *ToD = nullptr;
5434 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5435 return std::move(Err);
5436 if (ToD)
5437 return ToD;
5438
5439 Error Err = Error::success();
5440 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5441 auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5442 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5443 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5444 if (Err)
5445 return std::move(Err);
5446
5448 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5449 ToUsingLoc, ToTypenameLoc,
5450 ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5451 return ToUsing;
5452
5453 ToUsing->setAccess(D->getAccess());
5454 ToUsing->setLexicalDeclContext(LexicalDC);
5455 LexicalDC->addDeclInternal(ToUsing);
5456
5457 return ToUsing;
5458}
5459
5461 Decl* ToD = nullptr;
5462 switch (D->getBuiltinTemplateKind()) {
5464 ToD = Importer.getToContext().getMakeIntegerSeqDecl();
5465 break;
5467 ToD = Importer.getToContext().getTypePackElementDecl();
5468 break;
5470 ToD = Importer.getToContext().getBuiltinCommonTypeDecl();
5471 break;
5472 }
5473 assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5474 Importer.MapImported(D, ToD);
5475 return ToD;
5476}
5477
5480 if (To->getDefinition()) {
5481 // Check consistency of superclass.
5482 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5483 if (FromSuper) {
5484 if (auto FromSuperOrErr = import(FromSuper))
5485 FromSuper = *FromSuperOrErr;
5486 else
5487 return FromSuperOrErr.takeError();
5488 }
5489
5490 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5491 if ((bool)FromSuper != (bool)ToSuper ||
5492 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5493 Importer.ToDiag(To->getLocation(),
5494 diag::warn_odr_objc_superclass_inconsistent)
5495 << To->getDeclName();
5496 if (ToSuper)
5497 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5498 << To->getSuperClass()->getDeclName();
5499 else
5500 Importer.ToDiag(To->getLocation(),
5501 diag::note_odr_objc_missing_superclass);
5502 if (From->getSuperClass())
5503 Importer.FromDiag(From->getSuperClassLoc(),
5504 diag::note_odr_objc_superclass)
5505 << From->getSuperClass()->getDeclName();
5506 else
5507 Importer.FromDiag(From->getLocation(),
5508 diag::note_odr_objc_missing_superclass);
5509 }
5510
5512 if (Error Err = ImportDeclContext(From))
5513 return Err;
5514 return Error::success();
5515 }
5516
5517 // Start the definition.
5518 To->startDefinition();
5519
5520 // If this class has a superclass, import it.
5521 if (From->getSuperClass()) {
5522 if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5523 To->setSuperClass(*SuperTInfoOrErr);
5524 else
5525 return SuperTInfoOrErr.takeError();
5526 }
5527
5528 // Import protocols
5530 SmallVector<SourceLocation, 4> ProtocolLocs;
5532 From->protocol_loc_begin();
5533
5535 FromProtoEnd = From->protocol_end();
5536 FromProto != FromProtoEnd;
5537 ++FromProto, ++FromProtoLoc) {
5538 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5539 Protocols.push_back(*ToProtoOrErr);
5540 else
5541 return ToProtoOrErr.takeError();
5542
5543 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5544 ProtocolLocs.push_back(*ToProtoLocOrErr);
5545 else
5546 return ToProtoLocOrErr.takeError();
5547
5548 }
5549
5550 // FIXME: If we're merging, make sure that the protocol list is the same.
5551 To->setProtocolList(Protocols.data(), Protocols.size(),
5552 ProtocolLocs.data(), Importer.getToContext());
5553
5554 // Import categories. When the categories themselves are imported, they'll
5555 // hook themselves into this interface.
5556 for (auto *Cat : From->known_categories()) {
5557 auto ToCatOrErr = import(Cat);
5558 if (!ToCatOrErr)
5559 return ToCatOrErr.takeError();
5560 }
5561
5562 // If we have an @implementation, import it as well.
5563 if (From->getImplementation()) {
5564 if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5565 import(From->getImplementation()))
5566 To->setImplementation(*ToImplOrErr);
5567 else
5568 return ToImplOrErr.takeError();
5569 }
5570
5571 // Import all of the members of this class.
5572 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5573 return Err;
5574
5575 return Error::success();
5576}
5577
5580 if (!list)
5581 return nullptr;
5582
5584 for (auto *fromTypeParam : *list) {
5585 if (auto toTypeParamOrErr = import(fromTypeParam))
5586 toTypeParams.push_back(*toTypeParamOrErr);
5587 else
5588 return toTypeParamOrErr.takeError();
5589 }
5590
5591 auto LAngleLocOrErr = import(list->getLAngleLoc());
5592 if (!LAngleLocOrErr)
5593 return LAngleLocOrErr.takeError();
5594
5595 auto RAngleLocOrErr = import(list->getRAngleLoc());
5596 if (!RAngleLocOrErr)
5597 return RAngleLocOrErr.takeError();
5598
5599 return ObjCTypeParamList::create(Importer.getToContext(),
5600 *LAngleLocOrErr,
5601 toTypeParams,
5602 *RAngleLocOrErr);
5603}
5604
5606 // If this class has a definition in the translation unit we're coming from,
5607 // but this particular declaration is not that definition, import the
5608 // definition and map to that.
5609 ObjCInterfaceDecl *Definition = D->getDefinition();
5610 if (Definition && Definition != D) {
5611 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5612 return Importer.MapImported(D, *ImportedDefOrErr);
5613 else
5614 return ImportedDefOrErr.takeError();
5615 }
5616
5617 // Import the major distinguishing characteristics of an @interface.
5618 DeclContext *DC, *LexicalDC;
5619 DeclarationName Name;
5621 NamedDecl *ToD;
5622 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5623 return std::move(Err);
5624 if (ToD)
5625 return ToD;
5626
5627 // Look for an existing interface with the same name.
5628 ObjCInterfaceDecl *MergeWithIface = nullptr;
5629 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5630 for (auto *FoundDecl : FoundDecls) {
5632 continue;
5633
5634 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5635 break;
5636 }
5637
5638 // Create an interface declaration, if one does not already exist.
5639 ObjCInterfaceDecl *ToIface = MergeWithIface;
5640 if (!ToIface) {
5641 ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5642 if (!AtBeginLocOrErr)
5643 return AtBeginLocOrErr.takeError();
5644
5645 if (GetImportedOrCreateDecl(
5646 ToIface, D, Importer.getToContext(), DC,
5647 *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5648 /*TypeParamList=*/nullptr,
5649 /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5650 return ToIface;
5651 ToIface->setLexicalDeclContext(LexicalDC);
5652 LexicalDC->addDeclInternal(ToIface);
5653 }
5654 Importer.MapImported(D, ToIface);
5655 // Import the type parameter list after MapImported, to avoid
5656 // loops when bringing in their DeclContext.
5657 if (auto ToPListOrErr =
5658 ImportObjCTypeParamList(D->getTypeParamListAsWritten()))
5659 ToIface->setTypeParamList(*ToPListOrErr);
5660 else
5661 return ToPListOrErr.takeError();
5662
5663 if (D->isThisDeclarationADefinition())
5664 if (Error Err = ImportDefinition(D, ToIface))
5665 return std::move(Err);
5666
5667 return ToIface;
5668}
5669
5673 if (Error Err = importInto(Category, D->getCategoryDecl()))
5674 return std::move(Err);
5675
5676 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5677 if (!ToImpl) {
5678 DeclContext *DC, *LexicalDC;
5679 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5680 return std::move(Err);
5681
5682 Error Err = Error::success();
5683 auto ToLocation = importChecked(Err, D->getLocation());
5684 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5685 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5686 if (Err)
5687 return std::move(Err);
5688
5689 if (GetImportedOrCreateDecl(
5690 ToImpl, D, Importer.getToContext(), DC,
5691 Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5692 ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5693 return ToImpl;
5694
5695 ToImpl->setLexicalDeclContext(LexicalDC);
5696 LexicalDC->addDeclInternal(ToImpl);
5697 Category->setImplementation(ToImpl);
5698 }
5699
5700 Importer.MapImported(D, ToImpl);
5701 if (Error Err = ImportDeclContext(D))
5702 return std::move(Err);
5703
5704 return ToImpl;
5705}
5706
5709 // Find the corresponding interface.
5710 ObjCInterfaceDecl *Iface;
5711 if (Error Err = importInto(Iface, D->getClassInterface()))
5712 return std::move(Err);
5713
5714 // Import the superclass, if any.
5715 ObjCInterfaceDecl *Super;
5716 if (Error Err = importInto(Super, D->getSuperClass()))
5717 return std::move(Err);
5718
5720 if (!Impl) {
5721 // We haven't imported an implementation yet. Create a new @implementation
5722 // now.
5723 DeclContext *DC, *LexicalDC;
5724 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5725 return std::move(Err);
5726
5727 Error Err = Error::success();
5728 auto ToLocation = importChecked(Err, D->getLocation());
5729 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5730 auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5731 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5732 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5733 if (Err)
5734 return std::move(Err);
5735
5736 if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5737 DC, Iface, Super,
5738 ToLocation,
5739 ToAtStartLoc,
5740 ToSuperClassLoc,
5741 ToIvarLBraceLoc,
5742 ToIvarRBraceLoc))
5743 return Impl;
5744
5745 Impl->setLexicalDeclContext(LexicalDC);
5746
5747 // Associate the implementation with the class it implements.
5748 Iface->setImplementation(Impl);
5749 Importer.MapImported(D, Iface->getImplementation());
5750 } else {
5751 Importer.MapImported(D, Iface->getImplementation());
5752
5753 // Verify that the existing @implementation has the same superclass.
5754 if ((Super && !Impl->getSuperClass()) ||
5755 (!Super && Impl->getSuperClass()) ||
5756 (Super && Impl->getSuperClass() &&
5758 Impl->getSuperClass()))) {
5759 Importer.ToDiag(Impl->getLocation(),
5760 diag::warn_odr_objc_superclass_inconsistent)
5761 << Iface->getDeclName();
5762 // FIXME: It would be nice to have the location of the superclass
5763 // below.
5764 if (Impl->getSuperClass())
5765 Importer.ToDiag(Impl->getLocation(),
5766 diag::note_odr_objc_superclass)
5767 << Impl->getSuperClass()->getDeclName();
5768 else
5769 Importer.ToDiag(Impl->getLocation(),
5770 diag::note_odr_objc_missing_superclass);
5771 if (D->getSuperClass())
5772 Importer.FromDiag(D->getLocation(),
5773 diag::note_odr_objc_superclass)
5774 << D->getSuperClass()->getDeclName();
5775 else
5776 Importer.FromDiag(D->getLocation(),
5777 diag::note_odr_objc_missing_superclass);
5778
5779 return make_error<ASTImportError>(ASTImportError::NameConflict);
5780 }
5781 }
5782
5783 // Import all of the members of this @implementation.
5784 if (Error Err = ImportDeclContext(D))
5785 return std::move(Err);
5786
5787 return Impl;
5788}
5789
5791 // Import the major distinguishing characteristics of an @property.
5792 DeclContext *DC, *LexicalDC;
5793 DeclarationName Name;
5795 NamedDecl *ToD;
5796 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5797 return std::move(Err);
5798 if (ToD)
5799 return ToD;
5800
5801 // Check whether we have already imported this property.
5802 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5803 for (auto *FoundDecl : FoundDecls) {
5804 if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
5805 // Instance and class properties can share the same name but are different
5806 // declarations.
5807 if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
5808 continue;
5809
5810 // Check property types.
5811 if (!Importer.IsStructurallyEquivalent(D->getType(),
5812 FoundProp->getType())) {
5813 Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
5814 << Name << D->getType() << FoundProp->getType();
5815 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
5816 << FoundProp->getType();
5817
5818 return make_error<ASTImportError>(ASTImportError::NameConflict);
5819 }
5820
5821 // FIXME: Check property attributes, getters, setters, etc.?
5822
5823 // Consider these properties to be equivalent.
5824 Importer.MapImported(D, FoundProp);
5825 return FoundProp;
5826 }
5827 }
5828
5829 Error Err = Error::success();
5830 auto ToType = importChecked(Err, D->getType());
5831 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5832 auto ToAtLoc = importChecked(Err, D->getAtLoc());
5833 auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
5834 if (Err)
5835 return std::move(Err);
5836
5837 // Create the new property.
5838 ObjCPropertyDecl *ToProperty;
5839 if (GetImportedOrCreateDecl(
5840 ToProperty, D, Importer.getToContext(), DC, Loc,
5841 Name.getAsIdentifierInfo(), ToAtLoc,
5842 ToLParenLoc, ToType,
5843 ToTypeSourceInfo, D->getPropertyImplementation()))
5844 return ToProperty;
5845
5846 auto ToGetterName = importChecked(Err, D->getGetterName());
5847 auto ToSetterName = importChecked(Err, D->getSetterName());
5848 auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
5849 auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
5850 auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
5851 auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
5852 auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
5853 if (Err)
5854 return std::move(Err);
5855
5856 ToProperty->setLexicalDeclContext(LexicalDC);
5857 LexicalDC->addDeclInternal(ToProperty);
5858
5859 ToProperty->setPropertyAttributes(D->getPropertyAttributes());
5861 D->getPropertyAttributesAsWritten());
5862 ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
5863 ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
5864 ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
5865 ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
5866 ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
5867 return ToProperty;
5868}
5869
5873 if (Error Err = importInto(Property, D->getPropertyDecl()))
5874 return std::move(Err);
5875
5876 DeclContext *DC, *LexicalDC;
5877 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5878 return std::move(Err);
5879
5880 auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
5881
5882 // Import the ivar (for an @synthesize).
5883 ObjCIvarDecl *Ivar = nullptr;
5884 if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
5885 return std::move(Err);
5886
5887 ObjCPropertyImplDecl *ToImpl
5888 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
5889 Property->getQueryKind());
5890 if (!ToImpl) {
5891
5892 Error Err = Error::success();
5893 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
5894 auto ToLocation = importChecked(Err, D->getLocation());
5895 auto ToPropertyIvarDeclLoc =
5896 importChecked(Err, D->getPropertyIvarDeclLoc());
5897 if (Err)
5898 return std::move(Err);
5899
5900 if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
5901 ToBeginLoc,
5902 ToLocation, Property,
5903 D->getPropertyImplementation(), Ivar,
5904 ToPropertyIvarDeclLoc))
5905 return ToImpl;
5906
5907 ToImpl->setLexicalDeclContext(LexicalDC);
5908 LexicalDC->addDeclInternal(ToImpl);
5909 } else {
5910 // Check that we have the same kind of property implementation (@synthesize
5911 // vs. @dynamic).
5912 if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) {
5913 Importer.ToDiag(ToImpl->getLocation(),
5914 diag::warn_odr_objc_property_impl_kind_inconsistent)
5915 << Property->getDeclName()
5916 << (ToImpl->getPropertyImplementation()
5918 Importer.FromDiag(D->getLocation(),
5919 diag::note_odr_objc_property_impl_kind)
5920 << D->getPropertyDecl()->getDeclName()
5921 << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic);
5922
5923 return make_error<ASTImportError>(ASTImportError::NameConflict);
5924 }
5925
5926 // For @synthesize, check that we have the same
5927 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize &&
5928 Ivar != ToImpl->getPropertyIvarDecl()) {
5929 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
5930 diag::warn_odr_objc_synthesize_ivar_inconsistent)
5931 << Property->getDeclName()
5932 << ToImpl->getPropertyIvarDecl()->getDeclName()
5933 << Ivar->getDeclName();
5934 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
5935 diag::note_odr_objc_synthesize_ivar_here)
5936 << D->getPropertyIvarDecl()->getDeclName();
5937
5938 return make_error<ASTImportError>(ASTImportError::NameConflict);
5939 }
5940
5941 // Merge the existing implementation with the new implementation.
5942 Importer.MapImported(D, ToImpl);
5943 }
5944
5945 return ToImpl;
5946}
5947
5950 // For template arguments, we adopt the translation unit as our declaration
5951 // context. This context will be fixed when (during) the actual template
5952 // declaration is created.
5953
5954 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
5955 if (!BeginLocOrErr)
5956 return BeginLocOrErr.takeError();
5957
5958 ExpectedSLoc LocationOrErr = import(D->getLocation());
5959 if (!LocationOrErr)
5960 return LocationOrErr.takeError();
5961
5962 TemplateTypeParmDecl *ToD = nullptr;
5963 if (GetImportedOrCreateDecl(
5964 ToD, D, Importer.getToContext(),
5966 *BeginLocOrErr, *LocationOrErr,
5967 D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
5968 D->wasDeclaredWithTypename(), D->isParameterPack(),
5969 D->hasTypeConstraint()))
5970 return ToD;
5971
5972 // Import the type-constraint
5973 if (const TypeConstraint *TC = D->getTypeConstraint()) {
5974
5975 Error Err = Error::success();
5976 auto ToConceptRef = importChecked(Err, TC->getConceptReference());
5977 auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
5978 if (Err)
5979 return std::move(Err);
5980
5981 ToD->setTypeConstraint(ToConceptRef, ToIDC);
5982 }
5983
5984 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
5985 return Err;
5986
5987 return ToD;
5988}
5989
5992
5993 Error Err = Error::success();
5994 auto ToDeclName = importChecked(Err, D->getDeclName());
5995 auto ToLocation = importChecked(Err, D->getLocation());
5996 auto ToType = importChecked(Err, D->getType());
5997 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5998 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
5999 if (Err)
6000 return std::move(Err);
6001
6002 NonTypeTemplateParmDecl *ToD = nullptr;
6003 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
6005 ToInnerLocStart, ToLocation, D->getDepth(),
6006 D->getPosition(),
6007 ToDeclName.getAsIdentifierInfo(), ToType,
6008 D->isParameterPack(), ToTypeSourceInfo))
6009 return ToD;
6010
6011 Err = importTemplateParameterDefaultArgument(D, ToD);
6012 if (Err)
6013 return Err;
6014
6015 return ToD;
6016}
6017
6020 // Import the name of this declaration.
6021 auto NameOrErr = import(D->getDeclName());
6022 if (!NameOrErr)
6023 return NameOrErr.takeError();
6024
6025 // Import the location of this declaration.
6026 ExpectedSLoc LocationOrErr = import(D->getLocation());
6027 if (!LocationOrErr)
6028 return LocationOrErr.takeError();
6029
6030 // Import template parameters.
6031 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6032 if (!TemplateParamsOrErr)
6033 return TemplateParamsOrErr.takeError();
6034
6035 TemplateTemplateParmDecl *ToD = nullptr;
6036 if (GetImportedOrCreateDecl(
6037 ToD, D, Importer.getToContext(),
6038 Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
6039 D->getDepth(), D->getPosition(), D->isParameterPack(),
6040 (*NameOrErr).getAsIdentifierInfo(), D->wasDeclaredWithTypename(),
6041 *TemplateParamsOrErr))
6042 return ToD;
6043
6044 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6045 return Err;
6046
6047 return ToD;
6048}
6049
6050// Returns the definition for a (forward) declaration of a TemplateDecl, if
6051// it has any definition in the redecl chain.
6052template <typename T> static auto getTemplateDefinition(T *D) -> T * {
6053 assert(D->getTemplatedDecl() && "Should be called on templates only");
6054 auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
6055 if (!ToTemplatedDef)
6056 return nullptr;
6057 auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
6058 return cast_or_null<T>(TemplateWithDef);
6059}
6060
6062
6063 // Import the major distinguishing characteristics of this class template.
6064 DeclContext *DC, *LexicalDC;
6065 DeclarationName Name;
6067 NamedDecl *ToD;
6068 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6069 return std::move(Err);
6070 if (ToD)
6071 return ToD;
6072
6073 // Should check if a declaration is friend in a dependent context.
6074 // Such templates are not linked together in a declaration chain.
6075 // The ASTImporter strategy is to map existing forward declarations to
6076 // imported ones only if strictly necessary, otherwise import these as new
6077 // forward declarations. In case of the "dependent friend" declarations, new
6078 // declarations are created, but not linked in a declaration chain.
6079 auto IsDependentFriend = [](ClassTemplateDecl *TD) {
6080 return TD->getFriendObjectKind() != Decl::FOK_None &&
6082 };
6083 bool DependentFriend = IsDependentFriend(D);
6084
6085 ClassTemplateDecl *FoundByLookup = nullptr;
6086
6087 // We may already have a template of the same name; try to find and match it.
6088 if (!DC->isFunctionOrMethod()) {
6089 SmallVector<NamedDecl *, 4> ConflictingDecls;
6090 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6091 for (auto *FoundDecl : FoundDecls) {
6094 continue;
6095
6096 auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(FoundDecl);
6097 if (FoundTemplate) {
6098 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6099 continue;
6100
6101 // FIXME: sufficient conditon for 'IgnoreTemplateParmDepth'?
6102 bool IgnoreTemplateParmDepth =
6103 (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
6105 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
6106 IgnoreTemplateParmDepth)) {
6107 if (DependentFriend || IsDependentFriend(FoundTemplate))
6108 continue;
6109
6110 ClassTemplateDecl *TemplateWithDef =
6111 getTemplateDefinition(FoundTemplate);
6112 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6113 return Importer.MapImported(D, TemplateWithDef);
6114 if (!FoundByLookup)
6115 FoundByLookup = FoundTemplate;
6116 // Search in all matches because there may be multiple decl chains,
6117 // see ASTTests test ImportExistingFriendClassTemplateDef.
6118 continue;
6119 }
6120 // When importing a friend, it is possible that multiple declarations
6121 // with same name can co-exist in specific cases (if a template contains
6122 // a friend template and has a specialization). For this case the
6123 // declarations should match, except that the "template depth" is
6124 // different. No linking of previous declaration is needed in this case.
6125 // FIXME: This condition may need refinement.
6127 FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
6128 D->getFriendObjectKind() != FoundTemplate->getFriendObjectKind() &&
6129 IsStructuralMatch(D, FoundTemplate, /*Complain=*/false,
6130 /*IgnoreTemplateParmDepth=*/true))
6131 continue;
6132
6133 ConflictingDecls.push_back(FoundDecl);
6134 }
6135 }
6136
6137 if (!ConflictingDecls.empty()) {
6138 ExpectedName NameOrErr = Importer.HandleNameConflict(
6139 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6140 ConflictingDecls.size());
6141 if (NameOrErr)
6142 Name = NameOrErr.get();
6143 else
6144 return NameOrErr.takeError();
6145 }
6146 }
6147
6148 CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6149
6150 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6151 if (!TemplateParamsOrErr)
6152 return TemplateParamsOrErr.takeError();
6153
6154 // Create the declaration that is being templated.
6155 CXXRecordDecl *ToTemplated;
6156 if (Error Err = importInto(ToTemplated, FromTemplated))
6157 return std::move(Err);
6158
6159 // Create the class template declaration itself.
6161 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6162 *TemplateParamsOrErr, ToTemplated))
6163 return D2;
6164
6165 ToTemplated->setDescribedClassTemplate(D2);
6166
6167 D2->setAccess(D->getAccess());
6168 D2->setLexicalDeclContext(LexicalDC);
6169
6170 addDeclToContexts(D, D2);
6171 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6172
6173 if (FoundByLookup) {
6174 auto *Recent =
6175 const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6176
6177 // It is possible that during the import of the class template definition
6178 // we start the import of a fwd friend decl of the very same class template
6179 // and we add the fwd friend decl to the lookup table. But the ToTemplated
6180 // had been created earlier and by that time the lookup could not find
6181 // anything existing, so it has no previous decl. Later, (still during the
6182 // import of the fwd friend decl) we start to import the definition again
6183 // and this time the lookup finds the previous fwd friend class template.
6184 // In this case we must set up the previous decl for the templated decl.
6185 if (!ToTemplated->getPreviousDecl()) {
6186 assert(FoundByLookup->getTemplatedDecl() &&
6187 "Found decl must have its templated decl set");
6188 CXXRecordDecl *PrevTemplated =
6189 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6190 if (ToTemplated != PrevTemplated)
6191 ToTemplated->setPreviousDecl(PrevTemplated);
6192 }
6193
6194 D2->setPreviousDecl(Recent);
6195 }
6196
6197 return D2;
6198}
6199
6202 ClassTemplateDecl *ClassTemplate;
6203 if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6204 return std::move(Err);
6205
6206 // Import the context of this declaration.
6207 DeclContext *DC, *LexicalDC;
6208 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6209 return std::move(Err);
6210
6211 // Import template arguments.
6213 if (Error Err =
6214 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6215 return std::move(Err);
6216 // Try to find an existing specialization with these template arguments and
6217 // template parameter list.
6218 void *InsertPos = nullptr;
6219 ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6221 dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6222
6223 // Import template parameters.
6224 TemplateParameterList *ToTPList = nullptr;
6225
6226 if (PartialSpec) {
6227 auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6228 if (!ToTPListOrErr)
6229 return ToTPListOrErr.takeError();
6230 ToTPList = *ToTPListOrErr;
6231 PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs,
6232 *ToTPListOrErr,
6233 InsertPos);
6234 } else
6235 PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
6236
6237 if (PrevDecl) {
6238 if (IsStructuralMatch(D, PrevDecl)) {
6239 CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6240 if (D->isThisDeclarationADefinition() && PrevDefinition) {
6241 Importer.MapImported(D, PrevDefinition);
6242 // Import those default field initializers which have been
6243 // instantiated in the "From" context, but not in the "To" context.
6244 for (auto *FromField : D->fields()) {
6245 auto ToOrErr = import(FromField);
6246 if (!ToOrErr)
6247 return ToOrErr.takeError();
6248 }
6249
6250 // Import those methods which have been instantiated in the
6251 // "From" context, but not in the "To" context.
6252 for (CXXMethodDecl *FromM : D->methods()) {
6253 auto ToOrErr = import(FromM);
6254 if (!ToOrErr)
6255 return ToOrErr.takeError();
6256 }
6257
6258 // TODO Import instantiated default arguments.
6259 // TODO Import instantiated exception specifications.
6260 //
6261 // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6262 // what else could be fused during an AST merge.
6263 return PrevDefinition;
6264 }
6265 } else { // ODR violation.
6266 // FIXME HandleNameConflict
6267 return make_error<ASTImportError>(ASTImportError::NameConflict);
6268 }
6269 }
6270
6271 // Import the location of this declaration.
6272 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6273 if (!BeginLocOrErr)
6274 return BeginLocOrErr.takeError();
6275 ExpectedSLoc IdLocOrErr = import(D->getLocation());
6276 if (!IdLocOrErr)
6277 return IdLocOrErr.takeError();
6278
6279 // Import TemplateArgumentListInfo.
6280 TemplateArgumentListInfo ToTAInfo;
6281 if (const auto *ASTTemplateArgs = D->getTemplateArgsAsWritten()) {
6282 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
6283 return std::move(Err);
6284 }
6285
6286 // Create the specialization.
6287 ClassTemplateSpecializationDecl *D2 = nullptr;
6288 if (PartialSpec) {
6289 QualType CanonInjType;
6290 if (Error Err = importInto(
6291 CanonInjType, PartialSpec->getInjectedSpecializationType()))
6292 return std::move(Err);
6293 CanonInjType = CanonInjType.getCanonicalType();
6294
6295 if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6296 D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6297 *IdLocOrErr, ToTPList, ClassTemplate,
6298 llvm::ArrayRef(TemplateArgs.data(), TemplateArgs.size()),
6299 CanonInjType,
6300 cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6301 return D2;
6302
6303 // Update InsertPos, because preceding import calls may have invalidated
6304 // it by adding new specializations.
6305 auto *PartSpec2 = cast<ClassTemplatePartialSpecializationDecl>(D2);
6306 if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6307 InsertPos))
6308 // Add this partial specialization to the class template.
6309 ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
6311 import(PartialSpec->getInstantiatedFromMember()))
6312 PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6313 else
6314 return ToInstOrErr.takeError();
6315
6316 updateLookupTableForTemplateParameters(*ToTPList);
6317 } else { // Not a partial specialization.
6318 if (GetImportedOrCreateDecl(
6319 D2, D, Importer.getToContext(), D->getTagKind(), DC,
6320 *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs,
6321 PrevDecl))
6322 return D2;
6323
6324 // Update InsertPos, because preceding import calls may have invalidated
6325 // it by adding new specializations.
6326 if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos))
6327 // Add this specialization to the class template.
6328 ClassTemplate->AddSpecialization(D2, InsertPos);
6329 }
6330
6331 D2->setSpecializationKind(D->getSpecializationKind());
6332
6333 // Set the context of this specialization/instantiation.
6334 D2->setLexicalDeclContext(LexicalDC);
6335
6336 // Add to the DC only if it was an explicit specialization/instantiation.
6338 LexicalDC->addDeclInternal(D2);
6339 }
6340
6341 if (auto BraceRangeOrErr = import(D->getBraceRange()))
6342 D2->setBraceRange(*BraceRangeOrErr);
6343 else
6344 return BraceRangeOrErr.takeError();
6345
6346 if (Error Err = ImportTemplateParameterLists(D, D2))
6347 return std::move(Err);
6348
6349 // Import the qualifier, if any.
6350 if (auto LocOrErr = import(D->getQualifierLoc()))
6351 D2->setQualifierInfo(*LocOrErr);
6352 else
6353 return LocOrErr.takeError();
6354
6355 if (D->getTemplateArgsAsWritten())
6356 D2->setTemplateArgsAsWritten(ToTAInfo);
6357
6358 if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6359 D2->setTemplateKeywordLoc(*LocOrErr);
6360 else
6361 return LocOrErr.takeError();
6362
6363 if (auto LocOrErr = import(D->getExternKeywordLoc()))
6364 D2->setExternKeywordLoc(*LocOrErr);
6365 else
6366 return LocOrErr.takeError();
6367
6368 if (D->getPointOfInstantiation().isValid()) {
6369 if (auto POIOrErr = import(D->getPointOfInstantiation()))
6370 D2->setPointOfInstantiation(*POIOrErr);
6371 else
6372 return POIOrErr.takeError();
6373 }
6374
6375 D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind());
6376
6377 if (auto P = D->getInstantiatedFrom()) {
6378 if (auto *CTD = P.dyn_cast<ClassTemplateDecl *>()) {
6379 if (auto CTDorErr = import(CTD))
6380 D2->setInstantiationOf(*CTDorErr);
6381 } else {
6382 auto *CTPSD = cast<ClassTemplatePartialSpecializationDecl *>(P);
6383 auto CTPSDOrErr = import(CTPSD);
6384 if (!CTPSDOrErr)
6385 return CTPSDOrErr.takeError();
6386 const TemplateArgumentList &DArgs = D->getTemplateInstantiationArgs();
6387 SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6388 for (unsigned I = 0; I < DArgs.size(); ++I) {
6389 const TemplateArgument &DArg = DArgs[I];
6390 if (auto ArgOrErr = import(DArg))
6391 D2ArgsVec[I] = *ArgOrErr;
6392 else
6393 return ArgOrErr.takeError();
6394 }
6396 *CTPSDOrErr,
6397 TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6398 }
6399 }
6400
6401 if (D->isCompleteDefinition())
6402 if (Error Err = ImportDefinition(D, D2))
6403 return std::move(Err);
6404
6405 return D2;
6406}
6407
6409 // Import the major distinguishing characteristics of this variable template.
6410 DeclContext *DC, *LexicalDC;
6411 DeclarationName Name;
6413 NamedDecl *ToD;
6414 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6415 return std::move(Err);
6416 if (ToD)
6417 return ToD;
6418
6419 // We may already have a template of the same name; try to find and match it.
6420 assert(!DC->isFunctionOrMethod() &&
6421 "Variable templates cannot be declared at function scope");
6422
6423 SmallVector<NamedDecl *, 4> ConflictingDecls;
6424 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6425 VarTemplateDecl *FoundByLookup = nullptr;
6426 for (auto *FoundDecl : FoundDecls) {
6428 continue;
6429
6430 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6431 // Use the templated decl, some linkage flags are set only there.
6432 if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6433 D->getTemplatedDecl()))
6434 continue;
6435 if (IsStructuralMatch(D, FoundTemplate)) {
6436 // FIXME Check for ODR error if the two definitions have
6437 // different initializers?
6438 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6439 if (D->getDeclContext()->isRecord()) {
6440 assert(FoundTemplate->getDeclContext()->isRecord() &&
6441 "Member variable template imported as non-member, "
6442 "inconsistent imported AST?");
6443 if (FoundDef)
6444 return Importer.MapImported(D, FoundDef);
6445 if (!D->isThisDeclarationADefinition())
6446 return Importer.MapImported(D, FoundTemplate);
6447 } else {
6448 if (FoundDef && D->isThisDeclarationADefinition())
6449 return Importer.MapImported(D, FoundDef);
6450 }
6451 FoundByLookup = FoundTemplate;
6452 break;
6453 }
6454 ConflictingDecls.push_back(FoundDecl);
6455 }
6456 }
6457
6458 if (!ConflictingDecls.empty()) {
6459 ExpectedName NameOrErr = Importer.HandleNameConflict(
6460 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6461 ConflictingDecls.size());
6462 if (NameOrErr)
6463 Name = NameOrErr.get();
6464 else
6465 return NameOrErr.takeError();
6466 }
6467
6468 VarDecl *DTemplated = D->getTemplatedDecl();
6469
6470 // Import the type.
6471 // FIXME: Value not used?
6472 ExpectedType TypeOrErr = import(DTemplated->getType());
6473 if (!TypeOrErr)
6474 return TypeOrErr.takeError();
6475
6476 // Create the declaration that is being templated.
6477 VarDecl *ToTemplated;
6478 if (Error Err = importInto(ToTemplated, DTemplated))
6479 return std::move(Err);
6480
6481 // Create the variable template declaration itself.
6482 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6483 if (!TemplateParamsOrErr)
6484 return TemplateParamsOrErr.takeError();
6485
6486 VarTemplateDecl *ToVarTD;
6487 if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6488 Name, *TemplateParamsOrErr, ToTemplated))
6489 return ToVarTD;
6490
6491 ToTemplated->setDescribedVarTemplate(ToVarTD);
6492
6493 ToVarTD->setAccess(D->getAccess());
6494 ToVarTD->setLexicalDeclContext(LexicalDC);
6495 LexicalDC->addDeclInternal(ToVarTD);
6496 if (DC != Importer.getToContext().getTranslationUnitDecl())
6497 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6498
6499 if (FoundByLookup) {
6500 auto *Recent =
6501 const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6502 if (!ToTemplated->getPreviousDecl()) {
6503 auto *PrevTemplated =
6504 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6505 if (ToTemplated != PrevTemplated)
6506 ToTemplated->setPreviousDecl(PrevTemplated);
6507 }
6508 ToVarTD->setPreviousDecl(Recent);
6509 }
6510
6511 return ToVarTD;
6512}
6513
6516 // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6517 // in an analog way (but specialized for this case).
6518
6520 auto RedeclIt = Redecls.begin();
6521 // Import the first part of the decl chain. I.e. import all previous
6522 // declarations starting from the canonical decl.
6523 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6524 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6525 if (!RedeclOrErr)
6526 return RedeclOrErr.takeError();
6527 }
6528 assert(*RedeclIt == D);
6529
6530 VarTemplateDecl *VarTemplate = nullptr;
6531 if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate()))
6532 return std::move(Err);
6533
6534 // Import the context of this declaration.
6535 DeclContext *DC, *LexicalDC;
6536 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6537 return std::move(Err);
6538
6539 // Import the location of this declaration.
6540 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6541 if (!BeginLocOrErr)
6542 return BeginLocOrErr.takeError();
6543
6544 auto IdLocOrErr = import(D->getLocation());
6545 if (!IdLocOrErr)
6546 return IdLocOrErr.takeError();
6547
6548 // Import template arguments.
6550 if (Error Err =
6551 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6552 return std::move(Err);
6553
6554 // Try to find an existing specialization with these template arguments.
6555 void *InsertPos = nullptr;
6556 VarTemplateSpecializationDecl *FoundSpecialization =
6557 VarTemplate->findSpecialization(TemplateArgs, InsertPos);
6558 if (FoundSpecialization) {
6559 if (IsStructuralMatch(D, FoundSpecialization)) {
6560 VarDecl *FoundDef = FoundSpecialization->getDefinition();
6561 if (D->getDeclContext()->isRecord()) {
6562 // In a record, it is allowed only to have one optional declaration and
6563 // one definition of the (static or constexpr) variable template.
6564 assert(
6565 FoundSpecialization->getDeclContext()->isRecord() &&
6566 "Member variable template specialization imported as non-member, "
6567 "inconsistent imported AST?");
6568 if (FoundDef)
6569 return Importer.MapImported(D, FoundDef);
6570 if (!D->isThisDeclarationADefinition())
6571 return Importer.MapImported(D, FoundSpecialization);
6572 } else {
6573 // If definition is imported and there is already one, map to it.
6574 // Otherwise create a new variable and link it to the existing.
6575 if (FoundDef && D->isThisDeclarationADefinition())
6576 return Importer.MapImported(D, FoundDef);
6577 }
6578 } else {
6579 return make_error<ASTImportError>(ASTImportError::NameConflict);
6580 }
6581 }
6582
6583 VarTemplateSpecializationDecl *D2 = nullptr;
6584
6585 TemplateArgumentListInfo ToTAInfo;
6586 if (const auto *Args = D->getTemplateArgsAsWritten()) {
6587 if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6588 return std::move(Err);
6589 }
6590
6591 using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6592 // Create a new specialization.
6593 if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6594 auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6595 if (!ToTPListOrErr)
6596 return ToTPListOrErr.takeError();
6597
6598 PartVarSpecDecl *ToPartial;
6599 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6600 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6601 VarTemplate, QualType(), nullptr,
6602 D->getStorageClass(), TemplateArgs))
6603 return ToPartial;
6604
6605 if (Expected<PartVarSpecDecl *> ToInstOrErr =
6606 import(FromPartial->getInstantiatedFromMember()))
6607 ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6608 else
6609 return ToInstOrErr.takeError();
6610
6611 if (FromPartial->isMemberSpecialization())
6612 ToPartial->setMemberSpecialization();
6613
6614 D2 = ToPartial;
6615
6616 // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6617 // to adopt template parameters.
6618 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6619 } else { // Full specialization
6620 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6621 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6622 QualType(), nullptr, D->getStorageClass(),
6623 TemplateArgs))
6624 return D2;
6625 }
6626
6627 // Update InsertPos, because preceding import calls may have invalidated
6628 // it by adding new specializations.
6629 if (!VarTemplate->findSpecialization(TemplateArgs, InsertPos))
6630 VarTemplate->AddSpecialization(D2, InsertPos);
6631
6632 QualType T;
6633 if (Error Err = importInto(T, D->getType()))
6634 return std::move(Err);
6635 D2->setType(T);
6636
6637 auto TInfoOrErr = import(D->getTypeSourceInfo());
6638 if (!TInfoOrErr)
6639 return TInfoOrErr.takeError();
6640 D2->setTypeSourceInfo(*TInfoOrErr);
6641
6642 if (D->getPointOfInstantiation().isValid()) {
6643 if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6644 D2->setPointOfInstantiation(*POIOrErr);
6645 else
6646 return POIOrErr.takeError();
6647 }
6648
6649 D2->setSpecializationKind(D->getSpecializationKind());
6650
6651 if (D->getTemplateArgsAsWritten())
6652 D2->setTemplateArgsAsWritten(ToTAInfo);
6653
6654 if (auto LocOrErr = import(D->getQualifierLoc()))
6655 D2->setQualifierInfo(*LocOrErr);
6656 else
6657 return LocOrErr.takeError();
6658
6659 if (D->isConstexpr())
6660 D2->setConstexpr(true);
6661
6662 D2->setAccess(D->getAccess());
6663
6664 if (Error Err = ImportInitializer(D, D2))
6665 return std::move(Err);
6666
6667 if (FoundSpecialization)
6668 D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6669
6670 addDeclToContexts(D, D2);
6671
6672 // Import the rest of the chain. I.e. import all subsequent declarations.
6673 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6674 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6675 if (!RedeclOrErr)
6676 return RedeclOrErr.takeError();
6677 }
6678
6679 return D2;
6680}
6681
6684 DeclContext *DC, *LexicalDC;
6685 DeclarationName Name;
6687 NamedDecl *ToD;
6688
6689 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6690 return std::move(Err);
6691
6692 if (ToD)
6693 return ToD;
6694
6695 const FunctionTemplateDecl *FoundByLookup = nullptr;
6696
6697 // Try to find a function in our own ("to") context with the same name, same
6698 // type, and in the same context as the function we're importing.
6699 // FIXME Split this into a separate function.
6700 if (!LexicalDC->isFunctionOrMethod()) {
6702 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6703 for (auto *FoundDecl : FoundDecls) {
6704 if (!FoundDecl->isInIdentifierNamespace(IDNS))
6705 continue;
6706
6707 if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6708 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6709 continue;
6710 if (IsStructuralMatch(D, FoundTemplate)) {
6711 FunctionTemplateDecl *TemplateWithDef =
6712 getTemplateDefinition(FoundTemplate);
6713 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6714 return Importer.MapImported(D, TemplateWithDef);
6715
6716 FoundByLookup = FoundTemplate;
6717 break;
6718 // TODO: handle conflicting names
6719 }
6720 }
6721 }
6722 }
6723
6724 auto ParamsOrErr = import(D->getTemplateParameters());
6725 if (!ParamsOrErr)
6726 return ParamsOrErr.takeError();
6727 TemplateParameterList *Params = *ParamsOrErr;
6728
6729 FunctionDecl *TemplatedFD;
6730 if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6731 return std::move(Err);
6732
6733 // At creation of the template the template parameters are "adopted"
6734 // (DeclContext is changed). After this possible change the lookup table
6735 // must be updated.
6736 // At deduction guides the DeclContext of the template parameters may be
6737 // different from what we would expect, it may be the class template, or a
6738 // probably different CXXDeductionGuideDecl. This may come from the fact that
6739 // the template parameter objects may be shared between deduction guides or
6740 // the class template, and at creation of multiple FunctionTemplateDecl
6741 // objects (for deduction guides) the same parameters are re-used. The
6742 // "adoption" happens multiple times with different parent, even recursively
6743 // for TemplateTemplateParmDecl. The same happens at import when the
6744 // FunctionTemplateDecl objects are created, but in different order.
6745 // In this way the DeclContext of these template parameters is not necessarily
6746 // the same as in the "from" context.
6748 OldParamDC.reserve(Params->size());
6749 llvm::transform(*Params, std::back_inserter(OldParamDC),
6750 [](NamedDecl *ND) { return ND->getDeclContext(); });
6751
6752 FunctionTemplateDecl *ToFunc;
6753 if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6754 Params, TemplatedFD))
6755 return ToFunc;
6756
6757 TemplatedFD->setDescribedFunctionTemplate(ToFunc);
6758
6759 ToFunc->setAccess(D->getAccess());
6760 ToFunc->setLexicalDeclContext(LexicalDC);
6761 addDeclToContexts(D, ToFunc);
6762
6763 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
6764 if (LT && !OldParamDC.empty()) {
6765 for (unsigned int I = 0; I < OldParamDC.size(); ++I)
6766 LT->updateForced(Params->getParam(I), OldParamDC[I]);
6767 }
6768
6769 if (FoundByLookup) {
6770 auto *Recent =
6771 const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6772 if (!TemplatedFD->getPreviousDecl()) {
6773 assert(FoundByLookup->getTemplatedDecl() &&
6774 "Found decl must have its templated decl set");
6775 auto *PrevTemplated =
6776 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6777 if (TemplatedFD != PrevTemplated)
6778 TemplatedFD->setPreviousDecl(PrevTemplated);
6779 }
6780 ToFunc->setPreviousDecl(Recent);
6781 }
6782
6783 return ToFunc;
6784}
6785
6786//----------------------------------------------------------------------------
6787// Import Statements
6788//----------------------------------------------------------------------------
6789
6791 Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
6792 << S->getStmtClassName();
6793 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
6794}
6795
6796
6798 if (Importer.returnWithErrorInTest())
6799 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
6801 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
6802 IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
6803 // ToII is nullptr when no symbolic name is given for output operand
6804 // see ParseStmtAsm::ParseAsmOperandsOpt
6805 Names.push_back(ToII);
6806 }
6807
6808 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
6809 IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
6810 // ToII is nullptr when no symbolic name is given for input operand
6811 // see ParseStmtAsm::ParseAsmOperandsOpt
6812 Names.push_back(ToII);
6813 }
6814
6816 for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
6817 if (auto ClobberOrErr = import(S->getClobberStringLiteral(I)))
6818 Clobbers.push_back(*ClobberOrErr);
6819 else
6820 return ClobberOrErr.takeError();
6821
6822 }
6823
6825 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
6826 if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I)))
6827 Constraints.push_back(*OutputOrErr);
6828 else
6829 return OutputOrErr.takeError();
6830 }
6831
6832 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
6833 if (auto InputOrErr = import(S->getInputConstraintLiteral(I)))
6834 Constraints.push_back(*InputOrErr);
6835 else
6836 return InputOrErr.takeError();
6837 }
6838
6839 SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs() +
6840 S->getNumLabels());
6841 if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
6842 return std::move(Err);
6843
6844 if (Error Err =
6845 ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
6846 return std::move(Err);
6847
6848 if (Error Err = ImportArrayChecked(
6849 S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs()))
6850 return std::move(Err);
6851
6852 ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
6853 if (!AsmLocOrErr)
6854 return AsmLocOrErr.takeError();
6855 auto AsmStrOrErr = import(S->getAsmString());
6856 if (!AsmStrOrErr)
6857 return AsmStrOrErr.takeError();
6858 ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
6859 if (!RParenLocOrErr)
6860 return RParenLocOrErr.takeError();
6861
6862 return new (Importer.getToContext()) GCCAsmStmt(
6863 Importer.getToContext(),
6864 *AsmLocOrErr,
6865 S->isSimple(),
6866 S->isVolatile(),
6867 S->getNumOutputs(),
6868 S->getNumInputs(),
6869 Names.data(),
6870 Constraints.data(),
6871 Exprs.data(),
6872 *AsmStrOrErr,
6873 S->getNumClobbers(),
6874 Clobbers.data(),
6875 S->getNumLabels(),
6876 *RParenLocOrErr);
6877}
6878
6880
6881 Error Err = Error::success();
6882 auto ToDG = importChecked(Err, S->getDeclGroup());
6883 auto ToBeginLoc = importChecked(Err, S->getBeginLoc());
6884 auto ToEndLoc = importChecked(Err, S->getEndLoc());
6885 if (Err)
6886 return std::move(Err);
6887 return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
6888}
6889
6891 ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
6892 if (!ToSemiLocOrErr)
6893 return ToSemiLocOrErr.takeError();
6894 return new (Importer.getToContext()) NullStmt(
6895 *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
6896}
6897
6899 SmallVector<Stmt *, 8> ToStmts(S->size());
6900
6901 if (Error Err = ImportContainerChecked(S->body(), ToStmts))
6902 return std::move(Err);
6903
6904 ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
6905 if (!ToLBracLocOrErr)
6906 return ToLBracLocOrErr.takeError();
6907
6908 ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
6909 if (!ToRBracLocOrErr)
6910 return ToRBracLocOrErr.takeError();
6911
6912 FPOptionsOverride FPO =
6913 S->hasStoredFPFeatures() ? S->getStoredFPFeatures() : FPOptionsOverride();
6914 return CompoundStmt::Create(Importer.getToContext(), ToStmts, FPO,
6915 *ToLBracLocOrErr, *ToRBracLocOrErr);
6916}
6917
6919
6920 Error Err = Error::success();
6921 auto ToLHS = importChecked(Err, S->getLHS());
6922 auto ToRHS = importChecked(Err, S->getRHS());
6923 auto ToSubStmt = importChecked(Err, S->getSubStmt());
6924 auto ToCaseLoc = importChecked(Err, S->getCaseLoc());
6925 auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc());
6926 auto ToColonLoc = importChecked(Err, S->getColonLoc());
6927 if (Err)
6928 return std::move(Err);
6929
6930 auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
6931 ToCaseLoc, ToEllipsisLoc, ToColonLoc);
6932 ToStmt->setSubStmt(ToSubStmt);
6933
6934 return ToStmt;
6935}
6936
6938
6939 Error Err = Error::success();
6940 auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc());
6941 auto ToColonLoc = importChecked(Err, S->getColonLoc());
6942 auto ToSubStmt = importChecked(Err, S->getSubStmt());
6943 if (Err)
6944 return std::move(Err);
6945
6946 return new (Importer.getToContext()) DefaultStmt(
6947 ToDefaultLoc, ToColonLoc, ToSubStmt);
6948}
6949
6951
6952 Error Err = Error::success();
6953 auto ToIdentLoc = importChecked(Err, S->getIdentLoc());
6954 auto ToLabelDecl = importChecked(Err, S->getDecl());
6955 auto ToSubStmt = importChecked(Err, S->getSubStmt());
6956 if (Err)
6957 return std::move(Err);
6958
6959 return new (Importer.getToContext()) LabelStmt(
6960 ToIdentLoc, ToLabelDecl, ToSubStmt);
6961}
6962
6964 ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
6965 if (!ToAttrLocOrErr)
6966 return ToAttrLocOrErr.takeError();
6967 ArrayRef<const Attr*> FromAttrs(S->getAttrs());
6968 SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
6969 if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
6970 return std::move(Err);
6971 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
6972 if (!ToSubStmtOrErr)
6973 return ToSubStmtOrErr.takeError();
6974
6976 Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
6977}
6978
6980
6981 Error Err = Error::success();
6982 auto ToIfLoc = importChecked(Err, S->getIfLoc());
6983 auto ToInit = importChecked(Err, S->getInit());
6984 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
6985 auto ToCond = importChecked(Err, S->getCond());
6986 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
6987 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
6988 auto ToThen = importChecked(Err, S->getThen());
6989 auto ToElseLoc = importChecked(Err, S->getElseLoc());
6990 auto ToElse = importChecked(Err, S->getElse());
6991 if (Err)
6992 return std::move(Err);
6993
6994 return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(),
6995 ToInit, ToConditionVariable, ToCond, ToLParenLoc,
6996 ToRParenLoc, ToThen, ToElseLoc, ToElse);
6997}
6998
7000
7001 Error Err = Error::success();
7002 auto ToInit = importChecked(Err, S->getInit());
7003 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7004 auto ToCond = importChecked(Err, S->getCond());
7005 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7006 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7007 auto ToBody = importChecked(Err, S->getBody());
7008 auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
7009 if (Err)
7010 return std::move(Err);
7011
7012 auto *ToStmt =
7013 SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
7014 ToCond, ToLParenLoc, ToRParenLoc);
7015 ToStmt->setBody(ToBody);
7016 ToStmt->setSwitchLoc(ToSwitchLoc);
7017
7018 // Now we have to re-chain the cases.
7019 SwitchCase *LastChainedSwitchCase = nullptr;
7020 for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
7021 SC = SC->getNextSwitchCase()) {
7022 Expected<SwitchCase *> ToSCOrErr = import(SC);
7023 if (!ToSCOrErr)
7024 return ToSCOrErr.takeError();
7025 if (LastChainedSwitchCase)
7026 LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
7027 else
7028 ToStmt->setSwitchCaseList(*ToSCOrErr);
7029 LastChainedSwitchCase = *ToSCOrErr;
7030 }
7031
7032 return ToStmt;
7033}
7034
7036
7037 Error Err = Error::success();
7038 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7039 auto ToCond = importChecked(Err, S->getCond());
7040 auto ToBody = importChecked(Err, S->getBody());
7041 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7042 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7043 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7044 if (Err)
7045 return std::move(Err);
7046
7047 return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
7048 ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc);
7049}
7050
7052
7053 Error Err = Error::success();
7054 auto ToBody = importChecked(Err, S->getBody());
7055 auto ToCond = importChecked(Err, S->getCond());
7056 auto ToDoLoc = importChecked(Err, S->getDoLoc());
7057 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7058 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7059 if (Err)
7060 return std::move(Err);
7061
7062 return new (Importer.getToContext()) DoStmt(
7063 ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
7064}
7065
7067
7068 Error Err = Error::success();
7069 auto ToInit = importChecked(Err, S->getInit());
7070 auto ToCond = importChecked(Err, S->getCond());
7071 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7072 auto ToInc = importChecked(Err, S->getInc());
7073 auto ToBody = importChecked(Err, S->getBody());
7074 auto ToForLoc = importChecked(Err, S->getForLoc());
7075 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7076 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7077 if (Err)
7078 return std::move(Err);
7079
7080 return new (Importer.getToContext()) ForStmt(
7081 Importer.getToContext(),
7082 ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
7083 ToRParenLoc);
7084}
7085
7087
7088 Error Err = Error::success();
7089 auto ToLabel = importChecked(Err, S->getLabel());
7090 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7091 auto ToLabelLoc = importChecked(Err, S->getLabelLoc());
7092 if (Err)
7093 return std::move(Err);
7094
7095 return new (Importer.getToContext()) GotoStmt(
7096 ToLabel, ToGotoLoc, ToLabelLoc);
7097}
7098
7100
7101 Error Err = Error::success();
7102 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7103 auto ToStarLoc = importChecked(Err, S->getStarLoc());
7104 auto ToTarget = importChecked(Err, S->getTarget());
7105 if (Err)
7106 return std::move(Err);
7107
7108 return new (Importer.getToContext()) IndirectGotoStmt(
7109 ToGotoLoc, ToStarLoc, ToTarget);
7110}
7111
7113 ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc());
7114 if (!ToContinueLocOrErr)
7115 return ToContinueLocOrErr.takeError();
7116 return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr);
7117}
7118
7120 auto ToBreakLocOrErr = import(S->getBreakLoc());
7121 if (!ToBreakLocOrErr)
7122 return ToBreakLocOrErr.takeError();
7123 return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr);
7124}
7125
7127
7128 Error Err = Error::success();
7129 auto ToReturnLoc = importChecked(Err, S->getReturnLoc());
7130 auto ToRetValue = importChecked(Err, S->getRetValue());
7131 auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate());
7132 if (Err)
7133 return std::move(Err);
7134
7135 return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
7136 ToNRVOCandidate);
7137}
7138
7140
7141 Error Err = Error::success();
7142 auto ToCatchLoc = importChecked(Err, S->getCatchLoc());
7143 auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl());
7144 auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock());
7145 if (Err)
7146 return std::move(Err);
7147
7148 return new (Importer.getToContext()) CXXCatchStmt (
7149 ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
7150}
7151
7153 ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
7154 if (!ToTryLocOrErr)
7155 return ToTryLocOrErr.takeError();
7156
7157 ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
7158 if (!ToTryBlockOrErr)
7159 return ToTryBlockOrErr.takeError();
7160
7161 SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
7162 for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
7163 CXXCatchStmt *FromHandler = S->getHandler(HI);
7164 if (auto ToHandlerOrErr = import(FromHandler))
7165 ToHandlers[HI] = *ToHandlerOrErr;
7166 else
7167 return ToHandlerOrErr.takeError();
7168 }
7169
7170 return CXXTryStmt::Create(Importer.getToContext(), *ToTryLocOrErr,
7171 cast<CompoundStmt>(*ToTryBlockOrErr), ToHandlers);
7172}
7173
7175
7176 Error Err = Error::success();
7177 auto ToInit = importChecked(Err, S->getInit());
7178 auto ToRangeStmt = importChecked(Err, S->getRangeStmt());
7179 auto ToBeginStmt = importChecked(Err, S->getBeginStmt());
7180 auto ToEndStmt = importChecked(Err, S->getEndStmt());
7181 auto ToCond = importChecked(Err, S->getCond());
7182 auto ToInc = importChecked(Err, S->getInc());
7183 auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt());
7184 auto ToBody = importChecked(Err, S->getBody());
7185 auto ToForLoc = importChecked(Err, S->getForLoc());
7186 auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc());
7187 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7188 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7189 if (Err)
7190 return std::move(Err);
7191
7192 return new (Importer.getToContext()) CXXForRangeStmt(
7193 ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
7194 ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
7195}
7196
7199 Error Err = Error::success();
7200 auto ToElement = importChecked(Err, S->getElement());
7201 auto ToCollection = importChecked(Err, S->getCollection());
7202 auto ToBody = importChecked(Err, S->getBody());
7203 auto ToForLoc = importChecked(Err, S->getForLoc());
7204 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7205 if (Err)
7206 return std::move(Err);
7207
7208 return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
7209 ToCollection,
7210 ToBody,
7211 ToForLoc,
7212 ToRParenLoc);
7213}
7214
7216
7217 Error Err = Error::success();
7218 auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc());
7219 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7220 auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl());
7221 auto ToCatchBody = importChecked(Err, S->getCatchBody());
7222 if (Err)
7223 return std::move(Err);
7224
7225 return new (Importer.getToContext()) ObjCAtCatchStmt (
7226 ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
7227}
7228
7230 ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
7231 if (!ToAtFinallyLocOrErr)
7232 return ToAtFinallyLocOrErr.takeError();
7233 ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
7234 if (!ToAtFinallyStmtOrErr)
7235 return ToAtFinallyStmtOrErr.takeError();
7236 return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
7237 *ToAtFinallyStmtOrErr);
7238}
7239
7241
7242 Error Err = Error::success();
7243 auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc());
7244 auto ToTryBody = importChecked(Err, S->getTryBody());
7245 auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt());
7246 if (Err)
7247 return std::move(Err);
7248
7249 SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
7250 for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
7251 ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
7252 if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
7253 ToCatchStmts[CI] = *ToCatchStmtOrErr;
7254 else
7255 return ToCatchStmtOrErr.takeError();
7256 }
7257
7258 return ObjCAtTryStmt::Create(Importer.getToContext(),
7259 ToAtTryLoc, ToTryBody,
7260 ToCatchStmts.begin(), ToCatchStmts.size(),
7261 ToFinallyStmt);
7262}
7263
7266
7267 Error Err = Error::success();
7268 auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc());
7269 auto ToSynchExpr = importChecked(Err, S->getSynchExpr());
7270 auto ToSynchBody = importChecked(Err, S->getSynchBody());
7271 if (Err)
7272 return std::move(Err);
7273
7274 return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
7275 ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
7276}
7277
7279 ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
7280 if (!ToThrowLocOrErr)
7281 return ToThrowLocOrErr.takeError();
7282 ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
7283 if (!ToThrowExprOrErr)
7284 return ToThrowExprOrErr.takeError();
7285 return new (Importer.getToContext()) ObjCAtThrowStmt(
7286 *ToThrowLocOrErr, *ToThrowExprOrErr);
7287}
7288
7291 ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
7292 if (!ToAtLocOrErr)
7293 return ToAtLocOrErr.takeError();
7294 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7295 if (!ToSubStmtOrErr)
7296 return ToSubStmtOrErr.takeError();
7297 return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
7298 *ToSubStmtOrErr);
7299}
7300
7301//----------------------------------------------------------------------------
7302// Import Expressions
7303//----------------------------------------------------------------------------
7305 Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
7306 << E->getStmtClassName();
7307 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7308}
7309
7311 Error Err = Error::success();
7312 auto ToType = importChecked(Err, E->getType());
7313 auto BLoc = importChecked(Err, E->getBeginLoc());
7314 auto RParenLoc = importChecked(Err, E->getEndLoc());
7315 if (Err)
7316 return std::move(Err);
7317 auto ParentContextOrErr = Importer.ImportContext(E->getParentContext());
7318 if (!ParentContextOrErr)
7319 return ParentContextOrErr.takeError();
7320
7321 return new (Importer.getToContext())
7322 SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc,
7323 RParenLoc, *ParentContextOrErr);
7324}
7325
7327
7328 Error Err = Error::success();
7329 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7330 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7331 auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo());
7332 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7333 auto ToType = importChecked(Err, E->getType());
7334 if (Err)
7335 return std::move(Err);
7336
7337 return new (Importer.getToContext()) VAArgExpr(
7338 ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
7339 E->isMicrosoftABI());
7340}
7341
7343
7344 Error Err = Error::success();
7345 auto ToCond = importChecked(Err, E->getCond());
7346 auto ToLHS = importChecked(Err, E->getLHS());
7347 auto ToRHS = importChecked(Err, E->getRHS());
7348 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7349 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7350 auto ToType = importChecked(Err, E->getType());
7351 if (Err)
7352 return std::move(Err);
7353
7356
7357 // The value of CondIsTrue only matters if the value is not
7358 // condition-dependent.
7359 bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
7360
7361 return new (Importer.getToContext())
7362 ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
7363 ToRParenLoc, CondIsTrue);
7364}
7365
7367 Error Err = Error::success();
7368 auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
7369 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7370 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7371 auto ToType = importChecked(Err, E->getType());
7372 auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
7373 if (Err)
7374 return std::move(Err);
7375
7376 return new (Importer.getToContext())
7377 ConvertVectorExpr(ToSrcExpr, ToTSI, ToType, E->getValueKind(),
7378 E->getObjectKind(), ToBuiltinLoc, ToRParenLoc);
7379}
7380
7382 Error Err = Error::success();
7383 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7384 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7385 auto ToType = importChecked(Err, E->getType());
7386 const unsigned NumSubExprs = E->getNumSubExprs();
7387
7389 llvm::ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
7390 ToSubExprs.resize(NumSubExprs);
7391
7392 if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
7393 return std::move(Err);
7394
7395 return new (Importer.getToContext()) ShuffleVectorExpr(
7396 Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
7397}
7398
7400 ExpectedType TypeOrErr = import(E->getType());
7401 if (!TypeOrErr)
7402 return TypeOrErr.takeError();
7403
7404 ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
7405 if (!BeginLocOrErr)
7406 return BeginLocOrErr.takeError();
7407
7408 return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
7409}
7410
7413 Error Err = Error::success();
7414 auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
7415 Expr *ToControllingExpr = nullptr;
7416 TypeSourceInfo *ToControllingType = nullptr;
7417 if (E->isExprPredicate())
7418 ToControllingExpr = importChecked(Err, E->getControllingExpr());
7419 else
7420 ToControllingType = importChecked(Err, E->getControllingType());
7421 assert((ToControllingExpr || ToControllingType) &&
7422 "Either the controlling expr or type must be nonnull");
7423 auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
7424 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7425 if (Err)
7426 return std::move(Err);
7427
7428 ArrayRef<const TypeSourceInfo *> FromAssocTypes(E->getAssocTypeSourceInfos());
7429 SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
7430 if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
7431 return std::move(Err);
7432
7433 ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
7434 SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
7435 if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
7436 return std::move(Err);
7437
7438 const ASTContext &ToCtx = Importer.getToContext();
7439 if (E->isResultDependent()) {
7440 if (ToControllingExpr) {
7442 ToCtx, ToGenericLoc, ToControllingExpr, llvm::ArrayRef(ToAssocTypes),
7443 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7445 }
7447 ToCtx, ToGenericLoc, ToControllingType, llvm::ArrayRef(ToAssocTypes),
7448 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7450 }
7451
7452 if (ToControllingExpr) {
7454 ToCtx, ToGenericLoc, ToControllingExpr, llvm::ArrayRef(ToAssocTypes),
7455 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7456 E->containsUnexpandedParameterPack(), E->getResultIndex());
7457 }
7459 ToCtx, ToGenericLoc, ToControllingType, llvm::ArrayRef(ToAssocTypes),
7460 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7461 E->containsUnexpandedParameterPack(), E->getResultIndex());
7462}
7463
7465
7466 Error Err = Error::success();
7467 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7468 auto ToType = importChecked(Err, E->getType());
7469 auto ToFunctionName = importChecked(Err, E->getFunctionName());
7470 if (Err)
7471 return std::move(Err);
7472
7473 return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
7474 E->getIdentKind(), E->isTransparent(),
7475 ToFunctionName);
7476}
7477
7479
7480 Error Err = Error::success();
7481 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
7482 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
7483 auto ToDecl = importChecked(Err, E->getDecl());
7484 auto ToLocation = importChecked(Err, E->getLocation());
7485 auto ToType = importChecked(Err, E->getType());
7486 if (Err)
7487 return std::move(Err);
7488
7489 NamedDecl *ToFoundD = nullptr;
7490 if (E->getDecl() != E->getFoundDecl()) {
7491 auto FoundDOrErr = import(E->getFoundDecl());
7492 if (!FoundDOrErr)
7493 return FoundDOrErr.takeError();
7494 ToFoundD = *FoundDOrErr;
7495 }
7496
7497 TemplateArgumentListInfo ToTAInfo;
7498 TemplateArgumentListInfo *ToResInfo = nullptr;
7499 if (E->hasExplicitTemplateArgs()) {
7500 if (Error Err =
7501 ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(),
7502 E->template_arguments(), ToTAInfo))
7503 return std::move(Err);
7504 ToResInfo = &ToTAInfo;
7505 }
7506
7507 auto *ToE = DeclRefExpr::Create(
7508 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
7509 E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
7510 E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse());
7511 if (E->hadMultipleCandidates())
7512 ToE->setHadMultipleCandidates(true);
7513 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
7514 return ToE;
7515}
7516
7518 ExpectedType TypeOrErr = import(E->getType());
7519 if (!TypeOrErr)
7520 return TypeOrErr.takeError();
7521
7522 return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
7523}
7524
7526 ExpectedExpr ToInitOrErr = import(E->getInit());
7527 if (!ToInitOrErr)
7528 return ToInitOrErr.takeError();
7529
7530 ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
7531 if (!ToEqualOrColonLocOrErr)
7532 return ToEqualOrColonLocOrErr.takeError();
7533
7534 SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
7535 // List elements from the second, the first is Init itself
7536 for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
7537 if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
7538 ToIndexExprs[I - 1] = *ToArgOrErr;
7539 else
7540 return ToArgOrErr.takeError();
7541 }
7542
7543 SmallVector<Designator, 4> ToDesignators(E->size());
7544 if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
7545 return std::move(Err);
7546
7548 Importer.getToContext(), ToDesignators,
7549 ToIndexExprs, *ToEqualOrColonLocOrErr,
7550 E->usesGNUSyntax(), *ToInitOrErr);
7551}
7552
7555 ExpectedType ToTypeOrErr = import(E->getType());
7556 if (!ToTypeOrErr)
7557 return ToTypeOrErr.takeError();
7558
7559 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7560 if (!ToLocationOrErr)
7561 return ToLocationOrErr.takeError();
7562
7563 return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
7564 *ToTypeOrErr, *ToLocationOrErr);
7565}
7566
7568 ExpectedType ToTypeOrErr = import(E->getType());
7569 if (!ToTypeOrErr)
7570 return ToTypeOrErr.takeError();
7571
7572 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7573 if (!ToLocationOrErr)
7574 return ToLocationOrErr.takeError();
7575
7577 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7578}
7579
7580
7582 ExpectedType ToTypeOrErr = import(E->getType());
7583 if (!ToTypeOrErr)
7584 return ToTypeOrErr.takeError();
7585
7586 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7587 if (!ToLocationOrErr)
7588 return ToLocationOrErr.takeError();
7589
7591 Importer.getToContext(), E->getValue(), E->isExact(),
7592 *ToTypeOrErr, *ToLocationOrErr);
7593}
7594
7596 auto ToTypeOrErr = import(E->getType());
7597 if (!ToTypeOrErr)
7598 return ToTypeOrErr.takeError();
7599
7600 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7601 if (!ToSubExprOrErr)
7602 return ToSubExprOrErr.takeError();
7603
7604 return new (Importer.getToContext()) ImaginaryLiteral(
7605 *ToSubExprOrErr, *ToTypeOrErr);
7606}
7607
7609 auto ToTypeOrErr = import(E->getType());
7610 if (!ToTypeOrErr)
7611 return ToTypeOrErr.takeError();
7612
7613 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7614 if (!ToLocationOrErr)
7615 return ToLocationOrErr.takeError();
7616
7617 return new (Importer.getToContext()) FixedPointLiteral(
7618 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
7619 Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
7620}
7621
7623 ExpectedType ToTypeOrErr = import(E->getType());
7624 if (!ToTypeOrErr)
7625 return ToTypeOrErr.takeError();
7626
7627 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7628 if (!ToLocationOrErr)
7629 return ToLocationOrErr.takeError();
7630
7631 return new (Importer.getToContext()) CharacterLiteral(
7632 E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
7633}
7634
7636 ExpectedType ToTypeOrErr = import(E->getType());
7637 if (!ToTypeOrErr)
7638 return ToTypeOrErr.takeError();
7639
7640 SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated());
7641 if (Error Err = ImportArrayChecked(
7642 E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
7643 return std::move(Err);
7644
7645 return StringLiteral::Create(
7646 Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(),
7647 *ToTypeOrErr, ToLocations.data(), ToLocations.size());
7648}
7649
7651
7652 Error Err = Error::success();
7653 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7654 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7655 auto ToType = importChecked(Err, E->getType());
7656 auto ToInitializer = importChecked(Err, E->getInitializer());
7657 if (Err)
7658 return std::move(Err);
7659
7660 return new (Importer.getToContext()) CompoundLiteralExpr(
7661 ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
7662 ToInitializer, E->isFileScope());
7663}
7664
7666
7667 Error Err = Error::success();
7668 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7669 auto ToType = importChecked(Err, E->getType());
7670 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7671 if (Err)
7672 return std::move(Err);
7673
7674 SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs());
7675 if (Error Err = ImportArrayChecked(
7676 E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
7677 ToExprs.begin()))
7678 return std::move(Err);
7679
7680 return new (Importer.getToContext()) AtomicExpr(
7681
7682 ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
7683}
7684
7686 Error Err = Error::success();
7687 auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc());
7688 auto ToLabelLoc = importChecked(Err, E->getLabelLoc());
7689 auto ToLabel = importChecked(Err, E->getLabel());
7690 auto ToType = importChecked(Err, E->getType());
7691 if (Err)
7692 return std::move(Err);
7693
7694 return new (Importer.getToContext()) AddrLabelExpr(
7695 ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
7696}
7698 Error Err = Error::success();
7699 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7700 auto ToResult = importChecked(Err, E->getAPValueResult());
7701 if (Err)
7702 return std::move(Err);
7703
7704 return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult);
7705}
7707 Error Err = Error::success();
7708 auto ToLParen = importChecked(Err, E->getLParen());
7709 auto ToRParen = importChecked(Err, E->getRParen());
7710 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7711 if (Err)
7712 return std::move(Err);
7713
7714 return new (Importer.getToContext())
7715 ParenExpr(ToLParen, ToRParen, ToSubExpr);
7716}
7717
7719 SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
7720 if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
7721 return std::move(Err);
7722
7723 ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
7724 if (!ToLParenLocOrErr)
7725 return ToLParenLocOrErr.takeError();
7726
7727 ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
7728 if (!ToRParenLocOrErr)
7729 return ToRParenLocOrErr.takeError();
7730
7731 return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
7732 ToExprs, *ToRParenLocOrErr);
7733}
7734
7736 Error Err = Error::success();
7737 auto ToSubStmt = importChecked(Err, E->getSubStmt());
7738 auto ToType = importChecked(Err, E->getType());
7739 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7740 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7741 if (Err)
7742 return std::move(Err);
7743
7744 return new (Importer.getToContext())
7745 StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
7746 E->getTemplateDepth());
7747}
7748
7750 Error Err = Error::success();
7751 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7752 auto ToType = importChecked(Err, E->getType());
7753 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7754 if (Err)
7755 return std::move(Err);
7756
7757 auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
7758 E->hasStoredFPFeatures());
7759 UO->setType(ToType);
7760 UO->setSubExpr(ToSubExpr);
7761 UO->setOpcode(E->getOpcode());
7762 UO->setOperatorLoc(ToOperatorLoc);
7763 UO->setCanOverflow(E->canOverflow());
7764 if (E->hasStoredFPFeatures())
7765 UO->setStoredFPFeatures(E->getStoredFPFeatures());
7766
7767 return UO;
7768}
7769
7771
7773 Error Err = Error::success();
7774 auto ToType = importChecked(Err, E->getType());
7775 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7776 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7777 if (Err)
7778 return std::move(Err);
7779
7780 if (E->isArgumentType()) {
7781 Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
7782 import(E->getArgumentTypeInfo());
7783 if (!ToArgumentTypeInfoOrErr)
7784 return ToArgumentTypeInfoOrErr.takeError();
7785
7786 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
7787 E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
7788 ToRParenLoc);
7789 }
7790
7791 ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
7792 if (!ToArgumentExprOrErr)
7793 return ToArgumentExprOrErr.takeError();
7794
7795 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
7796 E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
7797}
7798
7800 Error Err = Error::success();
7801 auto ToLHS = importChecked(Err, E->getLHS());
7802 auto ToRHS = importChecked(Err, E->getRHS());
7803 auto ToType = importChecked(Err, E->getType());
7804 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7805 if (Err)
7806 return std::move(Err);
7807
7809 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
7810 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
7811 E->getFPFeatures());
7812}
7813
7815 Error Err = Error::success();
7816 auto ToCond = importChecked(Err, E->getCond());
7817 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
7818 auto ToLHS = importChecked(Err, E->getLHS());
7819 auto ToColonLoc = importChecked(Err, E->getColonLoc());
7820 auto ToRHS = importChecked(Err, E->getRHS());
7821 auto ToType = importChecked(Err, E->getType());
7822 if (Err)
7823 return std::move(Err);
7824
7825 return new (Importer.getToContext()) ConditionalOperator(
7826 ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
7827 E->getValueKind(), E->getObjectKind());
7828}
7829
7832 Error Err = Error::success();
7833 auto ToCommon = importChecked(Err, E->getCommon());
7834 auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue());
7835 auto ToCond = importChecked(Err, E->getCond());
7836 auto ToTrueExpr = importChecked(Err, E->getTrueExpr());
7837 auto ToFalseExpr = importChecked(Err, E->getFalseExpr());
7838 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
7839 auto ToColonLoc = importChecked(Err, E->getColonLoc());
7840 auto ToType = importChecked(Err, E->getType());
7841 if (Err)
7842 return std::move(Err);
7843
7844 return new (Importer.getToContext()) BinaryConditionalOperator(
7845 ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
7846 ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
7847 E->getObjectKind());
7848}
7849
7852 Error Err = Error::success();
7853 auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
7854 if (Err)
7855 return std::move(Err);
7856
7857 return new (Importer.getToContext())
7858 CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
7859}
7860
7862 Error Err = Error::success();
7863 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7864 auto ToQueriedTypeSourceInfo =
7865 importChecked(Err, E->getQueriedTypeSourceInfo());
7866 auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression());
7867 auto ToEndLoc = importChecked(Err, E->getEndLoc());
7868 auto ToType = importChecked(Err, E->getType());
7869 if (Err)
7870 return std::move(Err);
7871
7872 return new (Importer.getToContext()) ArrayTypeTraitExpr(
7873 ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
7874 ToDimensionExpression, ToEndLoc, ToType);
7875}
7876
7878 Error Err = Error::success();
7879 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7880 auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression());
7881 auto ToEndLoc = importChecked(Err, E->getEndLoc());
7882 auto ToType = importChecked(Err, E->getType());
7883 if (Err)
7884 return std::move(Err);
7885
7886 return new (Importer.getToContext()) ExpressionTraitExpr(
7887 ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
7888 ToEndLoc, ToType);
7889}
7890
7892 Error Err = Error::success();
7893 auto ToLocation = importChecked(Err, E->getLocation());
7894 auto ToType = importChecked(Err, E->getType());
7895 auto ToSourceExpr = importChecked(Err, E->getSourceExpr());
7896 if (Err)
7897 return std::move(Err);
7898
7899 return new (Importer.getToContext()) OpaqueValueExpr(
7900 ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
7901}
7902
7904 Error Err = Error::success();
7905 auto ToLHS = importChecked(Err, E->getLHS());
7906 auto ToRHS = importChecked(Err, E->getRHS());
7907 auto ToType = importChecked(Err, E->getType());
7908 auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc());
7909 if (Err)
7910 return std::move(Err);
7911
7912 return new (Importer.getToContext()) ArraySubscriptExpr(
7913 ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
7914 ToRBracketLoc);
7915}
7916
7919 Error Err = Error::success();
7920 auto ToLHS = importChecked(Err, E->getLHS());
7921 auto ToRHS = importChecked(Err, E->getRHS());
7922 auto ToType = importChecked(Err, E->getType());
7923 auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType());
7924 auto ToComputationResultType =
7925 importChecked(Err, E->getComputationResultType());
7926 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7927 if (Err)
7928 return std::move(Err);
7929
7931 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
7932 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
7933 E->getFPFeatures(),
7934 ToComputationLHSType, ToComputationResultType);
7935}
7936
7940 for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
7941 if (auto SpecOrErr = import(*I))
7942 Path.push_back(*SpecOrErr);
7943 else
7944 return SpecOrErr.takeError();
7945 }
7946 return Path;
7947}
7948
7950 ExpectedType ToTypeOrErr = import(E->getType());
7951 if (!ToTypeOrErr)
7952 return ToTypeOrErr.takeError();
7953
7954 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7955 if (!ToSubExprOrErr)
7956 return ToSubExprOrErr.takeError();
7957
7958 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
7959 if (!ToBasePathOrErr)
7960 return ToBasePathOrErr.takeError();
7961
7963 Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
7964 &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures());
7965}
7966
7968 Error Err = Error::success();
7969 auto ToType = importChecked(Err, E->getType());
7970 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7971 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
7972 if (Err)
7973 return std::move(Err);
7974
7975 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
7976 if (!ToBasePathOrErr)
7977 return ToBasePathOrErr.takeError();
7978 CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
7979
7980 switch (E->getStmtClass()) {
7981 case Stmt::CStyleCastExprClass: {
7982 auto *CCE = cast<CStyleCastExpr>(E);
7983 ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
7984 if (!ToLParenLocOrErr)
7985 return ToLParenLocOrErr.takeError();
7986 ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
7987 if (!ToRParenLocOrErr)
7988 return ToRParenLocOrErr.takeError();
7990 Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
7991 ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten,
7992 *ToLParenLocOrErr, *ToRParenLocOrErr);
7993 }
7994
7995 case Stmt::CXXFunctionalCastExprClass: {
7996 auto *FCE = cast<CXXFunctionalCastExpr>(E);
7997 ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
7998 if (!ToLParenLocOrErr)
7999 return ToLParenLocOrErr.takeError();
8000 ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
8001 if (!ToRParenLocOrErr)
8002 return ToRParenLocOrErr.takeError();
8004 Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
8005 E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(),
8006 *ToLParenLocOrErr, *ToRParenLocOrErr);
8007 }
8008
8009 case Stmt::ObjCBridgedCastExprClass: {
8010 auto *OCE = cast<ObjCBridgedCastExpr>(E);
8011 ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
8012 if (!ToLParenLocOrErr)
8013 return ToLParenLocOrErr.takeError();
8014 ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
8015 if (!ToBridgeKeywordLocOrErr)
8016 return ToBridgeKeywordLocOrErr.takeError();
8017 return new (Importer.getToContext()) ObjCBridgedCastExpr(
8018 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
8019 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
8020 }
8021 case Stmt::BuiltinBitCastExprClass: {
8022 auto *BBC = cast<BuiltinBitCastExpr>(E);
8023 ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
8024 if (!ToKWLocOrErr)
8025 return ToKWLocOrErr.takeError();
8026 ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
8027 if (!ToRParenLocOrErr)
8028 return ToRParenLocOrErr.takeError();
8029 return new (Importer.getToContext()) BuiltinBitCastExpr(
8030 ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
8031 ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
8032 }
8033 default:
8034 llvm_unreachable("Cast expression of unsupported type!");
8035 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
8036 }
8037}
8038
8041 for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
8042 const OffsetOfNode &FromNode = E->getComponent(I);
8043
8044 SourceLocation ToBeginLoc, ToEndLoc;
8045
8046 if (FromNode.getKind() != OffsetOfNode::Base) {
8047 Error Err = Error::success();
8048 ToBeginLoc = importChecked(Err, FromNode.getBeginLoc());
8049 ToEndLoc = importChecked(Err, FromNode.getEndLoc());
8050 if (Err)
8051 return std::move(Err);
8052 }
8053
8054 switch (FromNode.getKind()) {
8056 ToNodes.push_back(
8057 OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
8058 break;
8059 case OffsetOfNode::Base: {
8060 auto ToBSOrErr = import(FromNode.getBase());
8061 if (!ToBSOrErr)
8062 return ToBSOrErr.takeError();
8063 ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
8064 break;
8065 }
8066 case OffsetOfNode::Field: {
8067 auto ToFieldOrErr = import(FromNode.getField());
8068 if (!ToFieldOrErr)
8069 return ToFieldOrErr.takeError();
8070 ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
8071 break;
8072 }
8074 IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
8075 ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
8076 break;
8077 }
8078 }
8079 }
8080
8081 SmallVector<Expr *, 4> ToExprs(E->getNumExpressions());
8082 for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
8083 ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
8084 if (!ToIndexExprOrErr)
8085 return ToIndexExprOrErr.takeError();
8086 ToExprs[I] = *ToIndexExprOrErr;
8087 }
8088
8089 Error Err = Error::success();
8090 auto ToType = importChecked(Err, E->getType());
8091 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8092 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8093 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8094 if (Err)
8095 return std::move(Err);
8096
8097 return OffsetOfExpr::Create(
8098 Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
8099 ToExprs, ToRParenLoc);
8100}
8101
8103 Error Err = Error::success();
8104 auto ToType = importChecked(Err, E->getType());
8105 auto ToOperand = importChecked(Err, E->getOperand());
8106 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8107 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8108 if (Err)
8109 return std::move(Err);
8110
8111 CanThrowResult ToCanThrow;
8112 if (E->isValueDependent())
8113 ToCanThrow = CT_Dependent;
8114 else
8115 ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
8116
8117 return new (Importer.getToContext()) CXXNoexceptExpr(
8118 ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
8119}
8120
8122 Error Err = Error::success();
8123 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8124 auto ToType = importChecked(Err, E->getType());
8125 auto ToThrowLoc = importChecked(Err, E->getThrowLoc());
8126 if (Err)
8127 return std::move(Err);
8128
8129 return new (Importer.getToContext()) CXXThrowExpr(
8130 ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
8131}
8132
8134 ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
8135 if (!ToUsedLocOrErr)
8136 return ToUsedLocOrErr.takeError();
8137
8138 auto ToParamOrErr = import(E->getParam());
8139 if (!ToParamOrErr)
8140 return ToParamOrErr.takeError();
8141
8142 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8143 if (!UsedContextOrErr)
8144 return UsedContextOrErr.takeError();
8145
8146 // Import the default arg if it was not imported yet.
8147 // This is needed because it can happen that during the import of the
8148 // default expression (from VisitParmVarDecl) the same ParmVarDecl is
8149 // encountered here. The default argument for a ParmVarDecl is set in the
8150 // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here,
8151 // see VisitParmVarDecl).
8152 ParmVarDecl *ToParam = *ToParamOrErr;
8153 if (!ToParam->getDefaultArg()) {
8154 std::optional<ParmVarDecl *> FromParam =
8155 Importer.getImportedFromDecl(ToParam);
8156 assert(FromParam && "ParmVarDecl was not imported?");
8157
8158 if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam))
8159 return std::move(Err);
8160 }
8161 Expr *RewrittenInit = nullptr;
8162 if (E->hasRewrittenInit()) {
8163 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8164 if (!ExprOrErr)
8165 return ExprOrErr.takeError();
8166 RewrittenInit = ExprOrErr.get();
8167 }
8168 return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr,
8169 *ToParamOrErr, RewrittenInit,
8170 *UsedContextOrErr);
8171}
8172
8175 Error Err = Error::success();
8176 auto ToType = importChecked(Err, E->getType());
8177 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8178 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8179 if (Err)
8180 return std::move(Err);
8181
8182 return new (Importer.getToContext()) CXXScalarValueInitExpr(
8183 ToType, ToTypeSourceInfo, ToRParenLoc);
8184}
8185
8188 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8189 if (!ToSubExprOrErr)
8190 return ToSubExprOrErr.takeError();
8191
8192 auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
8193 if (!ToDtorOrErr)
8194 return ToDtorOrErr.takeError();
8195
8196 ASTContext &ToCtx = Importer.getToContext();
8197 CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
8198 return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
8199}
8200
8202
8204 Error Err = Error::success();
8205 auto ToConstructor = importChecked(Err, E->getConstructor());
8206 auto ToType = importChecked(Err, E->getType());
8207 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8208 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8209 if (Err)
8210 return std::move(Err);
8211
8212 SmallVector<Expr *, 8> ToArgs(E->getNumArgs());
8213 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8214 return std::move(Err);
8215
8217 Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
8218 ToParenOrBraceRange, E->hadMultipleCandidates(),
8219 E->isListInitialization(), E->isStdInitListInitialization(),
8220 E->requiresZeroInitialization());
8221}
8222
8225 DeclContext *DC, *LexicalDC;
8226 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
8227 return std::move(Err);
8228
8229 Error Err = Error::success();
8230 auto Temporary = importChecked(Err, D->getTemporaryExpr());
8231 auto ExtendingDecl = importChecked(Err, D->getExtendingDecl());
8232 if (Err)
8233 return std::move(Err);
8234 // FIXME: Should ManglingNumber get numbers associated with 'to' context?
8235
8237 if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl,
8238 D->getManglingNumber()))
8239 return To;
8240
8241 To->setLexicalDeclContext(LexicalDC);
8242 LexicalDC->addDeclInternal(To);
8243 return To;
8244}
8245
8248 Error Err = Error::success();
8249 auto ToType = importChecked(Err, E->getType());
8250 Expr *ToTemporaryExpr = importChecked(
8251 Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr());
8252 auto ToMaterializedDecl =
8253 importChecked(Err, E->getLifetimeExtendedTemporaryDecl());
8254 if (Err)
8255 return std::move(Err);
8256
8257 if (!ToTemporaryExpr)
8258 ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
8259
8260 auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
8261 ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
8262 ToMaterializedDecl);
8263
8264 return ToMTE;
8265}
8266
8268 Error Err = Error::success();
8269 auto ToType = importChecked(Err, E->getType());
8270 auto ToPattern = importChecked(Err, E->getPattern());
8271 auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8272 if (Err)
8273 return std::move(Err);
8274
8275 return new (Importer.getToContext()) PackExpansionExpr(
8276 ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions());
8277}
8278
8280 Error Err = Error::success();
8281 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8282 auto ToPack = importChecked(Err, E->getPack());
8283 auto ToPackLoc = importChecked(Err, E->getPackLoc());
8284 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8285 if (Err)
8286 return std::move(Err);
8287
8288 std::optional<unsigned> Length;
8289 if (!E->isValueDependent())
8290 Length = E->getPackLength();
8291
8292 SmallVector<TemplateArgument, 8> ToPartialArguments;
8293 if (E->isPartiallySubstituted()) {
8294 if (Error Err = ImportTemplateArguments(E->getPartialArguments(),
8295 ToPartialArguments))
8296 return std::move(Err);
8297 }
8298
8300 Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
8301 Length, ToPartialArguments);
8302}
8303
8304
8306 Error Err = Error::success();
8307 auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
8308 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8309 auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens());
8310 auto ToArraySize = importChecked(Err, E->getArraySize());
8311 auto ToInitializer = importChecked(Err, E->getInitializer());
8312 auto ToType = importChecked(Err, E->getType());
8313 auto ToAllocatedTypeSourceInfo =
8314 importChecked(Err, E->getAllocatedTypeSourceInfo());
8315 auto ToSourceRange = importChecked(Err, E->getSourceRange());
8316 auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange());
8317 if (Err)
8318 return std::move(Err);
8319
8320 SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
8321 if (Error Err =
8322 ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
8323 return std::move(Err);
8324
8325 return CXXNewExpr::Create(
8326 Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
8327 ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(),
8328 ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(),
8329 ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange,
8330 ToDirectInitRange);
8331}
8332
8334 Error Err = Error::success();
8335 auto ToType = importChecked(Err, E->getType());
8336 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8337 auto ToArgument = importChecked(Err, E->getArgument());
8338 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8339 if (Err)
8340 return std::move(Err);
8341
8342 return new (Importer.getToContext()) CXXDeleteExpr(
8343 ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
8344 E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
8345 ToBeginLoc);
8346}
8347
8349 Error Err = Error::success();
8350 auto ToType = importChecked(Err, E->getType());
8351 auto ToLocation = importChecked(Err, E->getLocation());
8352 auto ToConstructor = importChecked(Err, E->getConstructor());
8353 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8354 if (Err)
8355 return std::move(Err);
8356
8357 SmallVector<Expr *, 6> ToArgs(E->getNumArgs());
8358 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8359 return std::move(Err);
8360
8362 Importer.getToContext(), ToType, ToLocation, ToConstructor,
8363 E->isElidable(), ToArgs, E->hadMultipleCandidates(),
8364 E->isListInitialization(), E->isStdInitListInitialization(),
8365 E->requiresZeroInitialization(), E->getConstructionKind(),
8366 ToParenOrBraceRange);
8367 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
8368 return ToE;
8369}
8370
8372 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8373 if (!ToSubExprOrErr)
8374 return ToSubExprOrErr.takeError();
8375
8376 SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects());
8377 if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
8378 return std::move(Err);
8379
8381 Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
8382 ToObjects);
8383}
8384
8386 Error Err = Error::success();
8387 auto ToCallee = importChecked(Err, E->getCallee());
8388 auto ToType = importChecked(Err, E->getType());
8389 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8390 if (Err)
8391 return std::move(Err);
8392
8393 SmallVector<Expr *, 4> ToArgs(E->getNumArgs());
8394 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8395 return std::move(Err);
8396
8397 return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
8398 ToType, E->getValueKind(), ToRParenLoc,
8399 E->getFPFeatures());
8400}
8401
8403 ExpectedType ToTypeOrErr = import(E->getType());
8404 if (!ToTypeOrErr)
8405 return ToTypeOrErr.takeError();
8406
8407 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8408 if (!ToLocationOrErr)
8409 return ToLocationOrErr.takeError();
8410
8411 return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
8412 *ToTypeOrErr, E->isImplicit());
8413}
8414
8416 ExpectedType ToTypeOrErr = import(E->getType());
8417 if (!ToTypeOrErr)
8418 return ToTypeOrErr.takeError();
8419
8420 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8421 if (!ToLocationOrErr)
8422 return ToLocationOrErr.takeError();
8423
8424 return CXXBoolLiteralExpr::Create(Importer.getToContext(), E->getValue(),
8425 *ToTypeOrErr, *ToLocationOrErr);
8426}
8427
8429 Error Err = Error::success();
8430 auto ToBase = importChecked(Err, E->getBase());
8431 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8432 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8433 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8434 auto ToMemberDecl = importChecked(Err, E->getMemberDecl());
8435 auto ToType = importChecked(Err, E->getType());
8436 auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl());
8437 auto ToName = importChecked(Err, E->getMemberNameInfo().getName());
8438 auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc());
8439 if (Err)
8440 return std::move(Err);
8441
8442 DeclAccessPair ToFoundDecl =
8443 DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess());
8444
8445 DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
8446
8447 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8448 if (E->hasExplicitTemplateArgs()) {
8449 if (Error Err =
8450 ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(),
8451 E->template_arguments(), ToTAInfo))
8452 return std::move(Err);
8453 ResInfo = &ToTAInfo;
8454 }
8455
8456 return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(),
8457 ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8458 ToMemberDecl, ToFoundDecl, ToMemberNameInfo,
8459 ResInfo, ToType, E->getValueKind(),
8460 E->getObjectKind(), E->isNonOdrUse());
8461}
8462
8465 Error Err = Error::success();
8466 auto ToBase = importChecked(Err, E->getBase());
8467 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8468 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8469 auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo());
8470 auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc());
8471 auto ToTildeLoc = importChecked(Err, E->getTildeLoc());
8472 if (Err)
8473 return std::move(Err);
8474
8476 if (const IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
8477 const IdentifierInfo *ToII = Importer.Import(FromII);
8478 ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
8479 if (!ToDestroyedTypeLocOrErr)
8480 return ToDestroyedTypeLocOrErr.takeError();
8481 Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
8482 } else {
8483 if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
8484 Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
8485 else
8486 return ToTIOrErr.takeError();
8487 }
8488
8489 return new (Importer.getToContext()) CXXPseudoDestructorExpr(
8490 Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
8491 ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
8492}
8493
8496 Error Err = Error::success();
8497 auto ToType = importChecked(Err, E->getType());
8498 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8499 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8500 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8501 auto ToFirstQualifierFoundInScope =
8502 importChecked(Err, E->getFirstQualifierFoundInScope());
8503 if (Err)
8504 return std::move(Err);
8505
8506 Expr *ToBase = nullptr;
8507 if (!E->isImplicitAccess()) {
8508 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8509 ToBase = *ToBaseOrErr;
8510 else
8511 return ToBaseOrErr.takeError();
8512 }
8513
8514 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8515
8516 if (E->hasExplicitTemplateArgs()) {
8517 if (Error Err =
8518 ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(),
8519 E->template_arguments(), ToTAInfo))
8520 return std::move(Err);
8521 ResInfo = &ToTAInfo;
8522 }
8523 auto ToMember = importChecked(Err, E->getMember());
8524 auto ToMemberLoc = importChecked(Err, E->getMemberLoc());
8525 if (Err)
8526 return std::move(Err);
8527 DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc);
8528
8529 // Import additional name location/type info.
8530 if (Error Err =
8531 ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo))
8532 return std::move(Err);
8533
8535 Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
8536 ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
8537 ToMemberNameInfo, ResInfo);
8538}
8539
8542 Error Err = Error::success();
8543 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8544 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8545 auto ToDeclName = importChecked(Err, E->getDeclName());
8546 auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc());
8547 auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc());
8548 auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc());
8549 if (Err)
8550 return std::move(Err);
8551
8552 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8553 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8554 return std::move(Err);
8555
8556 TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
8557 TemplateArgumentListInfo *ResInfo = nullptr;
8558 if (E->hasExplicitTemplateArgs()) {
8559 if (Error Err =
8560 ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo))
8561 return std::move(Err);
8562 ResInfo = &ToTAInfo;
8563 }
8564
8566 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
8567 ToNameInfo, ResInfo);
8568}
8569
8572 Error Err = Error::success();
8573 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8574 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8575 auto ToType = importChecked(Err, E->getType());
8576 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8577 if (Err)
8578 return std::move(Err);
8579
8580 SmallVector<Expr *, 8> ToArgs(E->getNumArgs());
8581 if (Error Err =
8582 ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
8583 return std::move(Err);
8584
8586 Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc,
8587 llvm::ArrayRef(ToArgs), ToRParenLoc, E->isListInitialization());
8588}
8589
8592 Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
8593 if (!ToNamingClassOrErr)
8594 return ToNamingClassOrErr.takeError();
8595
8596 auto ToQualifierLocOrErr = import(E->getQualifierLoc());
8597 if (!ToQualifierLocOrErr)
8598 return ToQualifierLocOrErr.takeError();
8599
8600 Error Err = Error::success();
8601 auto ToName = importChecked(Err, E->getName());
8602 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8603 if (Err)
8604 return std::move(Err);
8605 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8606
8607 // Import additional name location/type info.
8608 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8609 return std::move(Err);
8610
8611 UnresolvedSet<8> ToDecls;
8612 for (auto *D : E->decls())
8613 if (auto ToDOrErr = import(D))
8614 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8615 else
8616 return ToDOrErr.takeError();
8617
8618 if (E->hasExplicitTemplateArgs()) {
8619 TemplateArgumentListInfo ToTAInfo;
8620 if (Error Err = ImportTemplateArgumentListInfo(
8621 E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(),
8622 ToTAInfo))
8623 return std::move(Err);
8624
8625 ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
8626 if (!ToTemplateKeywordLocOrErr)
8627 return ToTemplateKeywordLocOrErr.takeError();
8628
8629 const bool KnownDependent =
8630 (E->getDependence() & ExprDependence::TypeValue) ==
8631 ExprDependence::TypeValue;
8633 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8634 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
8635 ToDecls.begin(), ToDecls.end(), KnownDependent,
8636 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8637 }
8638
8640 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8641 ToNameInfo, E->requiresADL(), ToDecls.begin(), ToDecls.end(),
8642 /*KnownDependent=*/E->isTypeDependent(),
8643 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8644}
8645
8648 Error Err = Error::success();
8649 auto ToType = importChecked(Err, E->getType());
8650 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8651 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8652 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8653 auto ToName = importChecked(Err, E->getName());
8654 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8655 if (Err)
8656 return std::move(Err);
8657
8658 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8659 // Import additional name location/type info.
8660 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8661 return std::move(Err);
8662
8663 UnresolvedSet<8> ToDecls;
8664 for (Decl *D : E->decls())
8665 if (auto ToDOrErr = import(D))
8666 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8667 else
8668 return ToDOrErr.takeError();
8669
8670 TemplateArgumentListInfo ToTAInfo;
8671 TemplateArgumentListInfo *ResInfo = nullptr;
8672 if (E->hasExplicitTemplateArgs()) {
8673 TemplateArgumentListInfo FromTAInfo;
8674 E->copyTemplateArgumentsInto(FromTAInfo);
8675 if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo))
8676 return std::move(Err);
8677 ResInfo = &ToTAInfo;
8678 }
8679
8680 Expr *ToBase = nullptr;
8681 if (!E->isImplicitAccess()) {
8682 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8683 ToBase = *ToBaseOrErr;
8684 else
8685 return ToBaseOrErr.takeError();
8686 }
8687
8689 Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
8690 E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8691 ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
8692}
8693
8695 Error Err = Error::success();
8696 auto ToCallee = importChecked(Err, E->getCallee());
8697 auto ToType = importChecked(Err, E->getType());
8698 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8699 if (Err)
8700 return std::move(Err);
8701
8702 unsigned NumArgs = E->getNumArgs();
8703 llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
8704 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8705 return std::move(Err);
8706
8707 if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
8709 Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
8710 OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
8711 OCE->getADLCallKind());
8712 }
8713
8714 return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
8715 E->getValueKind(), ToRParenLoc, E->getFPFeatures(),
8716 /*MinNumArgs=*/0, E->getADLCallKind());
8717}
8718
8720 CXXRecordDecl *FromClass = E->getLambdaClass();
8721 auto ToClassOrErr = import(FromClass);
8722 if (!ToClassOrErr)
8723 return ToClassOrErr.takeError();
8724 CXXRecordDecl *ToClass = *ToClassOrErr;
8725
8726 auto ToCallOpOrErr = import(E->getCallOperator());
8727 if (!ToCallOpOrErr)
8728 return ToCallOpOrErr.takeError();
8729
8730 SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
8731 if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
8732 return std::move(Err);
8733
8734 Error Err = Error::success();
8735 auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange());
8736 auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc());
8737 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8738 if (Err)
8739 return std::move(Err);
8740
8741 return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange,
8742 E->getCaptureDefault(), ToCaptureDefaultLoc,
8743 E->hasExplicitParameters(),
8744 E->hasExplicitResultType(), ToCaptureInits,
8745 ToEndLoc, E->containsUnexpandedParameterPack());
8746}
8747
8748
8750 Error Err = Error::success();
8751 auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
8752 auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc());
8753 auto ToType = importChecked(Err, E->getType());
8754 if (Err)
8755 return std::move(Err);
8756
8757 SmallVector<Expr *, 4> ToExprs(E->getNumInits());
8758 if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
8759 return std::move(Err);
8760
8761 ASTContext &ToCtx = Importer.getToContext();
8762 InitListExpr *To = new (ToCtx) InitListExpr(
8763 ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc);
8764 To->setType(ToType);
8765
8766 if (E->hasArrayFiller()) {
8767 if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
8768 To->setArrayFiller(*ToFillerOrErr);
8769 else
8770 return ToFillerOrErr.takeError();
8771 }
8772
8773 if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
8774 if (auto ToFDOrErr = import(FromFD))
8775 To->setInitializedFieldInUnion(*ToFDOrErr);
8776 else
8777 return ToFDOrErr.takeError();
8778 }
8779
8780 if (InitListExpr *SyntForm = E->getSyntacticForm()) {
8781 if (auto ToSyntFormOrErr = import(SyntForm))
8782 To->setSyntacticForm(*ToSyntFormOrErr);
8783 else
8784 return ToSyntFormOrErr.takeError();
8785 }
8786
8787 // Copy InitListExprBitfields, which are not handled in the ctor of
8788 // InitListExpr.
8789 To->sawArrayRangeDesignator(E->hadArrayRangeDesignator());
8790
8791 return To;
8792}
8793
8796 ExpectedType ToTypeOrErr = import(E->getType());
8797 if (!ToTypeOrErr)
8798 return ToTypeOrErr.takeError();
8799
8800 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8801 if (!ToSubExprOrErr)
8802 return ToSubExprOrErr.takeError();
8803
8804 return new (Importer.getToContext()) CXXStdInitializerListExpr(
8805 *ToTypeOrErr, *ToSubExprOrErr);
8806}
8807
8810 Error Err = Error::success();
8811 auto ToLocation = importChecked(Err, E->getLocation());
8812 auto ToType = importChecked(Err, E->getType());
8813 auto ToConstructor = importChecked(Err, E->getConstructor());
8814 if (Err)
8815 return std::move(Err);
8816
8817 return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
8818 ToLocation, ToType, ToConstructor, E->constructsVBase(),
8819 E->inheritedFromVBase());
8820}
8821
8823 Error Err = Error::success();
8824 auto ToType = importChecked(Err, E->getType());
8825 auto ToCommonExpr = importChecked(Err, E->getCommonExpr());
8826 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8827 if (Err)
8828 return std::move(Err);
8829
8830 return new (Importer.getToContext()) ArrayInitLoopExpr(
8831 ToType, ToCommonExpr, ToSubExpr);
8832}
8833
8835 ExpectedType ToTypeOrErr = import(E->getType());
8836 if (!ToTypeOrErr)
8837 return ToTypeOrErr.takeError();
8838 return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
8839}
8840
8842 ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
8843 if (!ToBeginLocOrErr)
8844 return ToBeginLocOrErr.takeError();
8845
8846 auto ToFieldOrErr = import(E->getField());
8847 if (!ToFieldOrErr)
8848 return ToFieldOrErr.takeError();
8849
8850 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8851 if (!UsedContextOrErr)
8852 return UsedContextOrErr.takeError();
8853
8854 FieldDecl *ToField = *ToFieldOrErr;
8855 assert(ToField->hasInClassInitializer() &&
8856 "Field should have in-class initializer if there is a default init "
8857 "expression that uses it.");
8858 if (!ToField->getInClassInitializer()) {
8859 // The in-class initializer may be not yet set in "To" AST even if the
8860 // field is already there. This must be set here to make construction of
8861 // CXXDefaultInitExpr work.
8862 auto ToInClassInitializerOrErr =
8863 import(E->getField()->getInClassInitializer());
8864 if (!ToInClassInitializerOrErr)
8865 return ToInClassInitializerOrErr.takeError();
8866 ToField->setInClassInitializer(*ToInClassInitializerOrErr);
8867 }
8868
8869 Expr *RewrittenInit = nullptr;
8870 if (E->hasRewrittenInit()) {
8871 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8872 if (!ExprOrErr)
8873 return ExprOrErr.takeError();
8874 RewrittenInit = ExprOrErr.get();
8875 }
8876
8877 return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr,
8878 ToField, *UsedContextOrErr, RewrittenInit);
8879}
8880
8882 Error Err = Error::success();
8883 auto ToType = importChecked(Err, E->getType());
8884 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8885 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
8886 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8887 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8888 auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets());
8889 if (Err)
8890 return std::move(Err);
8891
8893 CastKind CK = E->getCastKind();
8894 auto ToBasePathOrErr = ImportCastPath(E);
8895 if (!ToBasePathOrErr)
8896 return ToBasePathOrErr.takeError();
8897
8898 if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) {
8900 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
8901 ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc,
8902 ToAngleBrackets);
8903 } else if (isa<CXXDynamicCastExpr>(E)) {
8905 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
8906 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
8907 } else if (isa<CXXReinterpretCastExpr>(E)) {
8909 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
8910 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
8911 } else if (isa<CXXConstCastExpr>(E)) {
8913 Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
8914 ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
8915 } else {
8916 llvm_unreachable("Unknown cast type");
8917 return make_error<ASTImportError>();
8918 }
8919}
8920
8923 Error Err = Error::success();
8924 auto ToType = importChecked(Err, E->getType());
8925 auto ToExprLoc = importChecked(Err, E->getExprLoc());
8926 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
8927 auto ToReplacement = importChecked(Err, E->getReplacement());
8928 if (Err)
8929 return std::move(Err);
8930
8931 return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
8932 ToType, E->getValueKind(), ToExprLoc, ToReplacement, ToAssociatedDecl,
8933 E->getIndex(), E->getPackIndex(), E->isReferenceParameter());
8934}
8935
8937 Error Err = Error::success();
8938 auto ToType = importChecked(Err, E->getType());
8939 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8940 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8941 if (Err)
8942 return std::move(Err);
8943
8944 SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs());
8945 if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
8946 return std::move(Err);
8947
8948 // According to Sema::BuildTypeTrait(), if E is value-dependent,
8949 // Value is always false.
8950 bool ToValue = (E->isValueDependent() ? false : E->getValue());
8951
8952 return TypeTraitExpr::Create(
8953 Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs,
8954 ToEndLoc, ToValue);
8955}
8956
8958 ExpectedType ToTypeOrErr = import(E->getType());
8959 if (!ToTypeOrErr)
8960 return ToTypeOrErr.takeError();
8961
8962 auto ToSourceRangeOrErr = import(E->getSourceRange());
8963 if (!ToSourceRangeOrErr)
8964 return ToSourceRangeOrErr.takeError();
8965
8966 if (E->isTypeOperand()) {
8967 if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
8968 return new (Importer.getToContext()) CXXTypeidExpr(
8969 *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
8970 else
8971 return ToTSIOrErr.takeError();
8972 }
8973
8974 ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
8975 if (!ToExprOperandOrErr)
8976 return ToExprOperandOrErr.takeError();
8977
8978 return new (Importer.getToContext()) CXXTypeidExpr(
8979 *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
8980}
8981
8983 Error Err = Error::success();
8984
8985 QualType ToType = importChecked(Err, E->getType());
8986 UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
8987 SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
8988 Expr *ToLHS = importChecked(Err, E->getLHS());
8989 SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8990 Expr *ToRHS = importChecked(Err, E->getRHS());
8991 SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
8992
8993 if (Err)
8994 return std::move(Err);
8995
8996 return new (Importer.getToContext())
8997 CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
8998 ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
8999}
9000
9002 CXXMethodDecl *FromMethod) {
9003 Error ImportErrors = Error::success();
9004 for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
9005 if (auto ImportedOrErr = import(FromOverriddenMethod))
9006 ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>(
9007 (*ImportedOrErr)->getCanonicalDecl()));
9008 else
9009 ImportErrors =
9010 joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
9011 }
9012 return ImportErrors;
9013}
9014
9016 ASTContext &FromContext, FileManager &FromFileManager,
9017 bool MinimalImport,
9018 std::shared_ptr<ASTImporterSharedState> SharedState)
9019 : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
9020 ToFileManager(ToFileManager), FromFileManager(FromFileManager),
9021 Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) {
9022
9023 // Create a default state without the lookup table: LLDB case.
9024 if (!SharedState) {
9025 this->SharedState = std::make_shared<ASTImporterSharedState>();
9026 }
9027
9028 ImportedDecls[FromContext.getTranslationUnitDecl()] =
9029 ToContext.getTranslationUnitDecl();
9030}
9031
9032ASTImporter::~ASTImporter() = default;
9033
9034std::optional<unsigned> ASTImporter::getFieldIndex(Decl *F) {
9035 assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
9036 "Try to get field index for non-field.");
9037
9038 auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
9039 if (!Owner)
9040 return std::nullopt;
9041
9042 unsigned Index = 0;
9043 for (const auto *D : Owner->decls()) {
9044 if (D == F)
9045 return Index;
9046
9047 if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D))
9048 ++Index;
9049 }
9050
9051 llvm_unreachable("Field was not found in its parent context.");
9052
9053 return std::nullopt;
9054}
9055
9057ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
9058 // We search in the redecl context because of transparent contexts.
9059 // E.g. a simple C language enum is a transparent context:
9060 // enum E { A, B };
9061 // Now if we had a global variable in the TU
9062 // int A;
9063 // then the enum constant 'A' and the variable 'A' violates ODR.
9064 // We can diagnose this only if we search in the redecl context.
9065 DeclContext *ReDC = DC->getRedeclContext();
9066 if (SharedState->getLookupTable()) {
9068 SharedState->getLookupTable()->lookup(ReDC, Name);
9069 return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
9070 } else {
9071 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
9072 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
9073 // We must search by the slow case of localUncachedLookup because that is
9074 // working even if there is no LookupPtr for the DC. We could use
9075 // DC::buildLookup() to create the LookupPtr, but that would load external
9076 // decls again, we must avoid that case.
9077 // Also, even if we had the LookupPtr, we must find Decls which are not
9078 // in the LookupPtr, so we need the slow case.
9079 // These cases are handled in ASTImporterLookupTable, but we cannot use
9080 // that with LLDB since that traverses through the AST which initiates the
9081 // load of external decls again via DC::decls(). And again, we must avoid
9082 // loading external decls during the import.
9083 if (Result.empty())
9084 ReDC->localUncachedLookup(Name, Result);
9085 return Result;
9086 }
9087}
9088
9089void ASTImporter::AddToLookupTable(Decl *ToD) {
9090 SharedState->addDeclToLookup(ToD);
9091}
9092
9094 // Import the decl using ASTNodeImporter.
9095 ASTNodeImporter Importer(*this);
9096 return Importer.Visit(FromD);
9097}
9098
9100 MapImported(FromD, ToD);
9101}
9102
9105 if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) {
9106 if (Expected<Expr *> R = Import(CLE))
9107 return ExprWithCleanups::CleanupObject(cast<CompoundLiteralExpr>(*R));
9108 }
9109
9110 // FIXME: Handle BlockDecl when we implement importing BlockExpr in
9111 // ASTNodeImporter.
9112 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
9113}
9114
9116 if (!FromT)
9117 return FromT;
9118
9119 // Check whether we've already imported this type.
9120 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
9121 ImportedTypes.find(FromT);
9122 if (Pos != ImportedTypes.end())
9123 return Pos->second;
9124
9125 // Import the type.
9126 ASTNodeImporter Importer(*this);
9127 ExpectedType ToTOrErr = Importer.Visit(FromT);
9128 if (!ToTOrErr)
9129 return ToTOrErr.takeError();
9130
9131 // Record the imported type.
9132 ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9133
9134 return ToTOrErr->getTypePtr();
9135}
9136
9138 if (FromT.isNull())
9139 return QualType{};
9140
9141 ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9142 if (!ToTyOrErr)
9143 return ToTyOrErr.takeError();
9144
9145 return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9146}
9147
9149 if (!FromTSI)
9150 return FromTSI;
9151
9152 // FIXME: For now we just create a "trivial" type source info based
9153 // on the type and a single location. Implement a real version of this.
9154 ExpectedType TOrErr = Import(FromTSI->getType());
9155 if (!TOrErr)
9156 return TOrErr.takeError();
9157 ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9158 if (!BeginLocOrErr)
9159 return BeginLocOrErr.takeError();
9160
9161 return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9162}
9163
9164namespace {
9165// To use this object, it should be created before the new attribute is created,
9166// and destructed after it is created. The construction already performs the
9167// import of the data.
9168template <typename T> struct AttrArgImporter {
9169 AttrArgImporter(const AttrArgImporter<T> &) = delete;
9170 AttrArgImporter(AttrArgImporter<T> &&) = default;
9171 AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9172 AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9173
9174 AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9175 : To(I.importChecked(Err, From)) {}
9176
9177 const T &value() { return To; }
9178
9179private:
9180 T To;
9181};
9182
9183// To use this object, it should be created before the new attribute is created,
9184// and destructed after it is created. The construction already performs the
9185// import of the data. The array data is accessible in a pointer form, this form
9186// is used by the attribute classes. This object should be created once for the
9187// array data to be imported (the array size is not imported, just copied).
9188template <typename T> struct AttrArgArrayImporter {
9189 AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9190 AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9191 AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9192 AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9193
9194 AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9195 const llvm::iterator_range<T *> &From,
9196 unsigned ArraySize) {
9197 if (Err)
9198 return;
9199 To.reserve(ArraySize);
9200 Err = I.ImportContainerChecked(From, To);
9201 }
9202
9203 T *value() { return To.data(); }
9204
9205private:
9207};
9208
9209class AttrImporter {
9210 Error Err{Error::success()};
9211 Attr *ToAttr = nullptr;
9212 ASTImporter &Importer;
9213 ASTNodeImporter NImporter;
9214
9215public:
9216 AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9217
9218 // Useful for accessing the imported attribute.
9219 template <typename T> T *castAttrAs() { return cast<T>(ToAttr); }
9220 template <typename T> const T *castAttrAs() const { return cast<T>(ToAttr); }
9221
9222 // Create an "importer" for an attribute parameter.
9223 // Result of the 'value()' of that object is to be passed to the function
9224 // 'importAttr', in the order that is expected by the attribute class.
9225 template <class T> AttrArgImporter<T> importArg(const T &From) {
9226 return AttrArgImporter<T>(NImporter, Err, From);
9227 }
9228
9229 // Create an "importer" for an attribute parameter that has array type.
9230 // Result of the 'value()' of that object is to be passed to the function
9231 // 'importAttr', then the size of the array as next argument.
9232 template <typename T>
9233 AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9234 unsigned ArraySize) {
9235 return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9236 }
9237
9238 // Create an attribute object with the specified arguments.
9239 // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9240 // should be values that are passed to the 'Create' function of the attribute.
9241 // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9242 // used here.) As much data is copied or imported from the old attribute
9243 // as possible. The passed arguments should be already imported.
9244 // If an import error happens, the internal error is set to it, and any
9245 // further import attempt is ignored.
9246 template <typename T, typename... Arg>
9247 void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9248 static_assert(std::is_base_of<Attr, T>::value,
9249 "T should be subclass of Attr.");
9250 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9251
9252 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9253 const IdentifierInfo *ToScopeName =
9254 Importer.Import(FromAttr->getScopeName());
9255 SourceRange ToAttrRange =
9256 NImporter.importChecked(Err, FromAttr->getRange());
9257 SourceLocation ToScopeLoc =
9258 NImporter.importChecked(Err, FromAttr->getScopeLoc());
9259
9260 if (Err)
9261 return;
9262
9263 AttributeCommonInfo ToI(ToAttrName, ToScopeName, ToAttrRange, ToScopeLoc,
9264 FromAttr->getParsedKind(), FromAttr->getForm());
9265 // The "SemanticSpelling" is not needed to be passed to the constructor.
9266 // That value is recalculated from the SpellingListIndex if needed.
9267 ToAttr = T::Create(Importer.getToContext(),
9268 std::forward<Arg>(ImportedArg)..., ToI);
9269
9270 ToAttr->setImplicit(FromAttr->isImplicit());
9271 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9272 if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9273 ToInheritableAttr->setInherited(FromAttr->isInherited());
9274 }
9275
9276 // Create a clone of the 'FromAttr' and import its source range only.
9277 // This causes objects with invalid references to be created if the 'FromAttr'
9278 // contains other data that should be imported.
9279 void cloneAttr(const Attr *FromAttr) {
9280 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9281
9282 SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9283 if (Err)
9284 return;
9285
9286 ToAttr = FromAttr->clone(Importer.getToContext());
9287 ToAttr->setRange(ToRange);
9288 ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9289 }
9290
9291 // Get the result of the previous import attempt (can be used only once).
9292 llvm::Expected<Attr *> getResult() && {
9293 if (Err)
9294 return std::move(Err);
9295 assert(ToAttr && "Attribute should be created.");
9296 return ToAttr;
9297 }
9298};
9299} // namespace
9300
9302 AttrImporter AI(*this);
9303
9304 // FIXME: Is there some kind of AttrVisitor to use here?
9305 switch (FromAttr->getKind()) {
9306 case attr::Aligned: {
9307 auto *From = cast<AlignedAttr>(FromAttr);
9308 if (From->isAlignmentExpr())
9309 AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9310 else
9311 AI.importAttr(From, false,
9312 AI.importArg(From->getAlignmentType()).value());
9313 break;
9314 }
9315
9316 case attr::AlignValue: {
9317 auto *From = cast<AlignValueAttr>(FromAttr);
9318 AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9319 break;
9320 }
9321
9322 case attr::Format: {
9323 const auto *From = cast<FormatAttr>(FromAttr);
9324 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9325 From->getFirstArg());
9326 break;
9327 }
9328
9329 case attr::EnableIf: {
9330 const auto *From = cast<EnableIfAttr>(FromAttr);
9331 AI.importAttr(From, AI.importArg(From->getCond()).value(),
9332 From->getMessage());
9333 break;
9334 }
9335
9336 case attr::AssertCapability: {
9337 const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9338 AI.importAttr(From,
9339 AI.importArrayArg(From->args(), From->args_size()).value(),
9340 From->args_size());
9341 break;
9342 }
9343 case attr::AcquireCapability: {
9344 const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9345 AI.importAttr(From,
9346 AI.importArrayArg(From->args(), From->args_size()).value(),
9347 From->args_size());
9348 break;
9349 }
9350 case attr::TryAcquireCapability: {
9351 const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9352 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9353 AI.importArrayArg(From->args(), From->args_size()).value(),
9354 From->args_size());
9355 break;
9356 }
9357 case attr::ReleaseCapability: {
9358 const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9359 AI.importAttr(From,
9360 AI.importArrayArg(From->args(), From->args_size()).value(),
9361 From->args_size());
9362 break;
9363 }
9364 case attr::RequiresCapability: {
9365 const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9366 AI.importAttr(From,
9367 AI.importArrayArg(From->args(), From->args_size()).value(),
9368 From->args_size());
9369 break;
9370 }
9371 case attr::GuardedBy: {
9372 const auto *From = cast<GuardedByAttr>(FromAttr);
9373 AI.importAttr(From, AI.importArg(From->getArg()).value());
9374 break;
9375 }
9376 case attr::PtGuardedBy: {
9377 const auto *From = cast<PtGuardedByAttr>(FromAttr);
9378 AI.importAttr(From, AI.importArg(From->getArg()).value());
9379 break;
9380 }
9381 case attr::AcquiredAfter: {
9382 const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9383 AI.importAttr(From,
9384 AI.importArrayArg(From->args(), From->args_size()).value(),
9385 From->args_size());
9386 break;
9387 }
9388 case attr::AcquiredBefore: {
9389 const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9390 AI.importAttr(From,
9391 AI.importArrayArg(From->args(), From->args_size()).value(),
9392 From->args_size());
9393 break;
9394 }
9395 case attr::AssertExclusiveLock: {
9396 const auto *From = cast<AssertExclusiveLockAttr>(FromAttr);
9397 AI.importAttr(From,
9398 AI.importArrayArg(From->args(), From->args_size()).value(),
9399 From->args_size());
9400 break;
9401 }
9402 case attr::AssertSharedLock: {
9403 const auto *From = cast<AssertSharedLockAttr>(FromAttr);
9404 AI.importAttr(From,
9405 AI.importArrayArg(From->args(), From->args_size()).value(),
9406 From->args_size());
9407 break;
9408 }
9409 case attr::ExclusiveTrylockFunction: {
9410 const auto *From = cast<ExclusiveTrylockFunctionAttr>(FromAttr);
9411 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9412 AI.importArrayArg(From->args(), From->args_size()).value(),
9413 From->args_size());
9414 break;
9415 }
9416 case attr::SharedTrylockFunction: {
9417 const auto *From = cast<SharedTrylockFunctionAttr>(FromAttr);
9418 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9419 AI.importArrayArg(From->args(), From->args_size()).value(),
9420 From->args_size());
9421 break;
9422 }
9423 case attr::LockReturned: {
9424 const auto *From = cast<LockReturnedAttr>(FromAttr);
9425 AI.importAttr(From, AI.importArg(From->getArg()).value());
9426 break;
9427 }
9428 case attr::LocksExcluded: {
9429 const auto *From = cast<LocksExcludedAttr>(FromAttr);
9430 AI.importAttr(From,
9431 AI.importArrayArg(From->args(), From->args_size()).value(),
9432 From->args_size());
9433 break;
9434 }
9435 default: {
9436 // The default branch works for attributes that have no arguments to import.
9437 // FIXME: Handle every attribute type that has arguments of type to import
9438 // (most often Expr* or Decl* or type) in the switch above.
9439 AI.cloneAttr(FromAttr);
9440 break;
9441 }
9442 }
9443
9444 return std::move(AI).getResult();
9445}
9446
9448 return ImportedDecls.lookup(FromD);
9449}
9450
9452 auto FromDPos = ImportedFromDecls.find(ToD);
9453 if (FromDPos == ImportedFromDecls.end())
9454 return nullptr;
9455 return FromDPos->second->getTranslationUnitDecl();
9456}
9457
9459 if (!FromD)
9460 return nullptr;
9461
9462 // Push FromD to the stack, and remove that when we return.
9463 ImportPath.push(FromD);
9464 auto ImportPathBuilder =
9465 llvm::make_scope_exit([this]() { ImportPath.pop(); });
9466
9467 // Check whether there was a previous failed import.
9468 // If yes return the existing error.
9469 if (auto Error = getImportDeclErrorIfAny(FromD))
9470 return make_error<ASTImportError>(*Error);
9471
9472 // Check whether we've already imported this declaration.
9473 Decl *ToD = GetAlreadyImportedOrNull(FromD);
9474 if (ToD) {
9475 // Already imported (possibly from another TU) and with an error.
9476 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9477 setImportDeclError(FromD, *Error);
9478 return make_error<ASTImportError>(*Error);
9479 }
9480
9481 // If FromD has some updated flags after last import, apply it.
9482 updateFlags(FromD, ToD);
9483 // If we encounter a cycle during an import then we save the relevant part
9484 // of the import path associated to the Decl.
9485 if (ImportPath.hasCycleAtBack())
9486 SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9487 return ToD;
9488 }
9489
9490 // Import the declaration.
9491 ExpectedDecl ToDOrErr = ImportImpl(FromD);
9492 if (!ToDOrErr) {
9493 // Failed to import.
9494
9495 auto Pos = ImportedDecls.find(FromD);
9496 if (Pos != ImportedDecls.end()) {
9497 // Import failed after the object was created.
9498 // Remove all references to it.
9499 auto *ToD = Pos->second;
9500 ImportedDecls.erase(Pos);
9501
9502 // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9503 // (e.g. with namespaces) that several decls from the 'from' context are
9504 // mapped to the same decl in the 'to' context. If we removed entries
9505 // from the LookupTable here then we may end up removing them multiple
9506 // times.
9507
9508 // The Lookuptable contains decls only which are in the 'to' context.
9509 // Remove from the Lookuptable only if it is *imported* into the 'to'
9510 // context (and do not remove it if it was added during the initial
9511 // traverse of the 'to' context).
9512 auto PosF = ImportedFromDecls.find(ToD);
9513 if (PosF != ImportedFromDecls.end()) {
9514 // In the case of TypedefNameDecl we create the Decl first and only
9515 // then we import and set its DeclContext. So, the DC might not be set
9516 // when we reach here.
9517 if (ToD->getDeclContext())
9518 SharedState->removeDeclFromLookup(ToD);
9519 ImportedFromDecls.erase(PosF);
9520 }
9521
9522 // FIXME: AST may contain remaining references to the failed object.
9523 // However, the ImportDeclErrors in the shared state contains all the
9524 // failed objects together with their error.
9525 }
9526
9527 // Error encountered for the first time.
9528 // After takeError the error is not usable any more in ToDOrErr.
9529 // Get a copy of the error object (any more simple solution for this?).
9530 ASTImportError ErrOut;
9531 handleAllErrors(ToDOrErr.takeError(),
9532 [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9533 setImportDeclError(FromD, ErrOut);
9534 // Set the error for the mapped to Decl, which is in the "to" context.
9535 if (Pos != ImportedDecls.end())
9536 SharedState->setImportDeclError(Pos->second, ErrOut);
9537
9538 // Set the error for all nodes which have been created before we
9539 // recognized the error.
9540 for (const auto &Path : SavedImportPaths[FromD]) {
9541 // The import path contains import-dependency nodes first.
9542 // Save the node that was imported as dependency of the current node.
9543 Decl *PrevFromDi = FromD;
9544 for (Decl *FromDi : Path) {
9545 // Begin and end of the path equals 'FromD', skip it.
9546 if (FromDi == FromD)
9547 continue;
9548 // We should not set import error on a node and all following nodes in
9549 // the path if child import errors are ignored.
9550 if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9551 PrevFromDi))
9552 break;
9553 PrevFromDi = FromDi;
9554 setImportDeclError(FromDi, ErrOut);
9555 //FIXME Should we remove these Decls from ImportedDecls?
9556 // Set the error for the mapped to Decl, which is in the "to" context.
9557 auto Ii = ImportedDecls.find(FromDi);
9558 if (Ii != ImportedDecls.end())
9559 SharedState->setImportDeclError(Ii->second, ErrOut);
9560 // FIXME Should we remove these Decls from the LookupTable,
9561 // and from ImportedFromDecls?
9562 }
9563 }
9564 SavedImportPaths.erase(FromD);
9565
9566 // Do not return ToDOrErr, error was taken out of it.
9567 return make_error<ASTImportError>(ErrOut);
9568 }
9569
9570 ToD = *ToDOrErr;
9571
9572 // FIXME: Handle the "already imported with error" case. We can get here
9573 // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
9574 // previously failed create was requested).
9575 // Later GetImportedOrCreateDecl can be updated to return the error.
9576 if (!ToD) {
9577 auto Err = getImportDeclErrorIfAny(FromD);
9578 assert(Err);
9579 return make_error<ASTImportError>(*Err);
9580 }
9581
9582 // We could import from the current TU without error. But previously we
9583 // already had imported a Decl as `ToD` from another TU (with another
9584 // ASTImporter object) and with an error.
9585 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9586 setImportDeclError(FromD, *Error);
9587 return make_error<ASTImportError>(*Error);
9588 }
9589 // Make sure that ImportImpl registered the imported decl.
9590 assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
9591
9592 if (FromD->hasAttrs())
9593 for (const Attr *FromAttr : FromD->getAttrs()) {
9594 auto ToAttrOrErr = Import(FromAttr);
9595 if (ToAttrOrErr)
9596 ToD->addAttr(*ToAttrOrErr);
9597 else
9598 return ToAttrOrErr.takeError();
9599 }
9600
9601 // Notify subclasses.
9602 Imported(FromD, ToD);
9603
9604 updateFlags(FromD, ToD);
9605 SavedImportPaths.erase(FromD);
9606 return ToDOrErr;
9607}
9608
9611 return ASTNodeImporter(*this).ImportInheritedConstructor(From);
9612}
9613
9615 if (!FromDC)
9616 return FromDC;
9617
9618 ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
9619 if (!ToDCOrErr)
9620 return ToDCOrErr.takeError();
9621 auto *ToDC = cast<DeclContext>(*ToDCOrErr);
9622
9623 // When we're using a record/enum/Objective-C class/protocol as a context, we
9624 // need it to have a definition.
9625 if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
9626 auto *FromRecord = cast<RecordDecl>(FromDC);
9627 if (ToRecord->isCompleteDefinition())
9628 return ToDC;
9629
9630 // If FromRecord is not defined we need to force it to be.
9631 // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
9632 // it will start the definition but we never finish it.
9633 // If there are base classes they won't be imported and we will
9634 // be missing anything that we inherit from those bases.
9635 if (FromRecord->getASTContext().getExternalSource() &&
9636 !FromRecord->isCompleteDefinition())
9637 FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
9638
9639 if (FromRecord->isCompleteDefinition())
9640 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9641 FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
9642 return std::move(Err);
9643 } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
9644 auto *FromEnum = cast<EnumDecl>(FromDC);
9645 if (ToEnum->isCompleteDefinition()) {
9646 // Do nothing.
9647 } else if (FromEnum->isCompleteDefinition()) {
9648 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9649 FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
9650 return std::move(Err);
9651 } else {
9652 CompleteDecl(ToEnum);
9653 }
9654 } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
9655 auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
9656 if (ToClass->getDefinition()) {
9657 // Do nothing.
9658 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
9659 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9660 FromDef, ToClass, ASTNodeImporter::IDK_Basic))
9661 return std::move(Err);
9662 } else {
9663 CompleteDecl(ToClass);
9664 }
9665 } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
9666 auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
9667 if (ToProto->getDefinition()) {
9668 // Do nothing.
9669 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
9670 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9671 FromDef, ToProto, ASTNodeImporter::IDK_Basic))
9672 return std::move(Err);
9673 } else {
9674 CompleteDecl(ToProto);
9675 }
9676 }
9677
9678 return ToDC;
9679}
9680
9682 if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
9683 return cast_or_null<Expr>(*ToSOrErr);
9684 else
9685 return ToSOrErr.takeError();
9686}
9687
9689 if (!FromS)
9690 return nullptr;
9691
9692 // Check whether we've already imported this statement.
9693 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
9694 if (Pos != ImportedStmts.end())
9695 return Pos->second;
9696
9697 // Import the statement.
9698 ASTNodeImporter Importer(*this);
9699 ExpectedStmt ToSOrErr = Importer.Visit(FromS);
9700 if (!ToSOrErr)
9701 return ToSOrErr;
9702
9703 if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
9704 auto *FromE = cast<Expr>(FromS);
9705 // Copy ExprBitfields, which may not be handled in Expr subclasses
9706 // constructors.
9707 ToE->setValueKind(FromE->getValueKind());
9708 ToE->setObjectKind(FromE->getObjectKind());
9709 ToE->setDependence(FromE->getDependence());
9710 }
9711
9712 // Record the imported statement object.
9713 ImportedStmts[FromS] = *ToSOrErr;
9714 return ToSOrErr;
9715}
9716
9719 if (!FromNNS)
9720 return nullptr;
9721
9722 NestedNameSpecifier *Prefix = nullptr;
9723 if (Error Err = importInto(Prefix, FromNNS->getPrefix()))
9724 return std::move(Err);
9725
9726 switch (FromNNS->getKind()) {
9728 assert(FromNNS->getAsIdentifier() && "NNS should contain identifier.");
9729 return NestedNameSpecifier::Create(ToContext, Prefix,
9730 Import(FromNNS->getAsIdentifier()));
9731
9733 if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) {
9734 return NestedNameSpecifier::Create(ToContext, Prefix,
9735 cast<NamespaceDecl>(*NSOrErr));
9736 } else
9737 return NSOrErr.takeError();
9738
9740 if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias()))
9741 return NestedNameSpecifier::Create(ToContext, Prefix,
9742 cast<NamespaceAliasDecl>(*NSADOrErr));
9743 else
9744 return NSADOrErr.takeError();
9745
9747 return NestedNameSpecifier::GlobalSpecifier(ToContext);
9748
9750 if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl()))
9751 return NestedNameSpecifier::SuperSpecifier(ToContext,
9752 cast<CXXRecordDecl>(*RDOrErr));
9753 else
9754 return RDOrErr.takeError();
9755
9758 if (ExpectedTypePtr TyOrErr = Import(FromNNS->getAsType())) {
9759 bool TSTemplate =
9761 return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate,
9762 *TyOrErr);
9763 } else {
9764 return TyOrErr.takeError();
9765 }
9766 }
9767
9768 llvm_unreachable("Invalid nested name specifier kind");
9769}
9770
9773 // Copied from NestedNameSpecifier mostly.
9775 NestedNameSpecifierLoc NNS = FromNNS;
9776
9777 // Push each of the nested-name-specifiers's onto a stack for
9778 // serialization in reverse order.
9779 while (NNS) {
9780 NestedNames.push_back(NNS);
9781 NNS = NNS.getPrefix();
9782 }
9783
9785
9786 while (!NestedNames.empty()) {
9787 NNS = NestedNames.pop_back_val();
9788 NestedNameSpecifier *Spec = nullptr;
9789 if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
9790 return std::move(Err);
9791
9793
9794 SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
9795 if (Kind != NestedNameSpecifier::Super) {
9796 if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
9797 return std::move(Err);
9798
9799 if (Kind != NestedNameSpecifier::Global)
9800 if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
9801 return std::move(Err);
9802 }
9803
9804 switch (Kind) {
9806 Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc,
9807 ToLocalEndLoc);
9808 break;
9809
9811 Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc,
9812 ToLocalEndLoc);
9813 break;
9814
9816 Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(),
9817 ToLocalBeginLoc, ToLocalEndLoc);
9818 break;
9819
9822 SourceLocation ToTLoc;
9823 if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc()))
9824 return std::move(Err);
9826 QualType(Spec->getAsType(), 0), ToTLoc);
9828 // ToLocalBeginLoc is here the location of the 'template' keyword.
9829 Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(),
9830 ToLocalEndLoc);
9831 else
9832 // No location for 'template' keyword here.
9833 Builder.Extend(getToContext(), SourceLocation{}, TSI->getTypeLoc(),
9834 ToLocalEndLoc);
9835 break;
9836 }
9837
9839 Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
9840 break;
9841
9843 auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
9844 if (!ToSourceRangeOrErr)
9845 return ToSourceRangeOrErr.takeError();
9846
9847 Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(),
9848 ToSourceRangeOrErr->getBegin(),
9849 ToSourceRangeOrErr->getEnd());
9850 }
9851 }
9852 }
9853
9854 return Builder.getWithLocInContext(getToContext());
9855}
9856
9858 switch (From.getKind()) {
9860 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
9861 return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
9862 else
9863 return ToTemplateOrErr.takeError();
9864
9867 UnresolvedSet<2> ToTemplates;
9868 for (auto *I : *FromStorage) {
9869 if (auto ToOrErr = Import(I))
9870 ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
9871 else
9872 return ToOrErr.takeError();
9873 }
9874 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
9875 ToTemplates.end());
9876 }
9877
9880 auto DeclNameOrErr = Import(FromStorage->getDeclName());
9881 if (!DeclNameOrErr)
9882 return DeclNameOrErr.takeError();
9883 return ToContext.getAssumedTemplateName(*DeclNameOrErr);
9884 }
9885
9888 auto QualifierOrErr = Import(QTN->getQualifier());
9889 if (!QualifierOrErr)
9890 return QualifierOrErr.takeError();
9891 auto TNOrErr = Import(QTN->getUnderlyingTemplate());
9892 if (!TNOrErr)
9893 return TNOrErr.takeError();
9894 return ToContext.getQualifiedTemplateName(
9895 *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
9896 }
9897
9900 auto QualifierOrErr = Import(DTN->getQualifier());
9901 if (!QualifierOrErr)
9902 return QualifierOrErr.takeError();
9903
9904 if (DTN->isIdentifier()) {
9905 return ToContext.getDependentTemplateName(*QualifierOrErr,
9906 Import(DTN->getIdentifier()));
9907 }
9908
9909 return ToContext.getDependentTemplateName(*QualifierOrErr,
9910 DTN->getOperator());
9911 }
9912
9916 auto ReplacementOrErr = Import(Subst->getReplacement());
9917 if (!ReplacementOrErr)
9918 return ReplacementOrErr.takeError();
9919
9920 auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
9921 if (!AssociatedDeclOrErr)
9922 return AssociatedDeclOrErr.takeError();
9923
9924 return ToContext.getSubstTemplateTemplateParm(
9925 *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
9926 Subst->getPackIndex());
9927 }
9928
9932 ASTNodeImporter Importer(*this);
9933 auto ArgPackOrErr =
9934 Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
9935 if (!ArgPackOrErr)
9936 return ArgPackOrErr.takeError();
9937
9938 auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
9939 if (!AssociatedDeclOrErr)
9940 return AssociatedDeclOrErr.takeError();
9941
9942 return ToContext.getSubstTemplateTemplateParmPack(
9943 *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
9944 SubstPack->getFinal());
9945 }
9947 auto UsingOrError = Import(From.getAsUsingShadowDecl());
9948 if (!UsingOrError)
9949 return UsingOrError.takeError();
9950 return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
9951 }
9953 llvm_unreachable("Unexpected DeducedTemplate");
9954 }
9955
9956 llvm_unreachable("Invalid template name kind");
9957}
9958
9960 if (FromLoc.isInvalid())
9961 return SourceLocation{};
9962
9963 SourceManager &FromSM = FromContext.getSourceManager();
9964 bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
9965
9966 std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc);
9967 Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
9968 if (!ToFileIDOrErr)
9969 return ToFileIDOrErr.takeError();
9970 SourceManager &ToSM = ToContext.getSourceManager();
9971 return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
9972}
9973
9975 SourceLocation ToBegin, ToEnd;
9976 if (Error Err = importInto(ToBegin, FromRange.getBegin()))
9977 return std::move(Err);
9978 if (Error Err = importInto(ToEnd, FromRange.getEnd()))
9979 return std::move(Err);
9980
9981 return SourceRange(ToBegin, ToEnd);
9982}
9983
9985 llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
9986 if (Pos != ImportedFileIDs.end())
9987 return Pos->second;
9988
9989 SourceManager &FromSM = FromContext.getSourceManager();
9990 SourceManager &ToSM = ToContext.getSourceManager();
9991 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
9992
9993 // Map the FromID to the "to" source manager.
9994 FileID ToID;
9995 if (FromSLoc.isExpansion()) {
9996 const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
9997 ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
9998 if (!ToSpLoc)
9999 return ToSpLoc.takeError();
10000 ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
10001 if (!ToExLocS)
10002 return ToExLocS.takeError();
10003 unsigned ExLength = FromSM.getFileIDSize(FromID);
10004 SourceLocation MLoc;
10005 if (FromEx.isMacroArgExpansion()) {
10006 MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
10007 } else {
10008 if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
10009 MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
10010 FromEx.isExpansionTokenRange());
10011 else
10012 return ToExLocE.takeError();
10013 }
10014 ToID = ToSM.getFileID(MLoc);
10015 } else {
10016 const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
10017
10018 if (!IsBuiltin && !Cache->BufferOverridden) {
10019 // Include location of this file.
10020 ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
10021 if (!ToIncludeLoc)
10022 return ToIncludeLoc.takeError();
10023
10024 // Every FileID that is not the main FileID needs to have a valid include
10025 // location so that the include chain points to the main FileID. When
10026 // importing the main FileID (which has no include location), we need to
10027 // create a fake include location in the main file to keep this property
10028 // intact.
10029 SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
10030 if (FromID == FromSM.getMainFileID())
10031 ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
10032
10033 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
10034 // FIXME: We probably want to use getVirtualFileRef(), so we don't hit
10035 // the disk again
10036 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
10037 // than mmap the files several times.
10038 auto Entry =
10039 ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
10040 // FIXME: The filename may be a virtual name that does probably not
10041 // point to a valid file and we get no Entry here. In this case try with
10042 // the memory buffer below.
10043 if (Entry)
10044 ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
10045 FromSLoc.getFile().getFileCharacteristic());
10046 }
10047 }
10048
10049 if (ToID.isInvalid() || IsBuiltin) {
10050 // FIXME: We want to re-use the existing MemoryBuffer!
10051 std::optional<llvm::MemoryBufferRef> FromBuf =
10052 Cache->getBufferOrNone(FromContext.getDiagnostics(),
10053 FromSM.getFileManager(), SourceLocation{});
10054 if (!FromBuf)
10055 return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
10056
10057 std::unique_ptr<llvm::MemoryBuffer> ToBuf =
10058 llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
10059 FromBuf->getBufferIdentifier());
10060 ToID = ToSM.createFileID(std::move(ToBuf),
10061 FromSLoc.getFile().getFileCharacteristic());
10062 }
10063 }
10064
10065 assert(ToID.isValid() && "Unexpected invalid fileID was created.");
10066
10067 ImportedFileIDs[FromID] = ToID;
10068 return ToID;
10069}
10070
10072 ExpectedExpr ToExprOrErr = Import(From->getInit());
10073 if (!ToExprOrErr)
10074 return ToExprOrErr.takeError();
10075
10076 auto LParenLocOrErr = Import(From->getLParenLoc());
10077 if (!LParenLocOrErr)
10078 return LParenLocOrErr.takeError();
10079
10080 auto RParenLocOrErr = Import(From->getRParenLoc());
10081 if (!RParenLocOrErr)
10082 return RParenLocOrErr.takeError();
10083
10084 if (From->isBaseInitializer()) {
10085 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10086 if (!ToTInfoOrErr)
10087 return ToTInfoOrErr.takeError();
10088
10089 SourceLocation EllipsisLoc;
10090 if (From->isPackExpansion())
10091 if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
10092 return std::move(Err);
10093
10094 return new (ToContext) CXXCtorInitializer(
10095 ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
10096 *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
10097 } else if (From->isMemberInitializer()) {
10098 ExpectedDecl ToFieldOrErr = Import(From->getMember());
10099 if (!ToFieldOrErr)
10100 return ToFieldOrErr.takeError();
10101
10102 auto MemberLocOrErr = Import(From->getMemberLocation());
10103 if (!MemberLocOrErr)
10104 return MemberLocOrErr.takeError();
10105
10106 return new (ToContext) CXXCtorInitializer(
10107 ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
10108 *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10109 } else if (From->isIndirectMemberInitializer()) {
10110 ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
10111 if (!ToIFieldOrErr)
10112 return ToIFieldOrErr.takeError();
10113
10114 auto MemberLocOrErr = Import(From->getMemberLocation());
10115 if (!MemberLocOrErr)
10116 return MemberLocOrErr.takeError();
10117
10118 return new (ToContext) CXXCtorInitializer(
10119 ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10120 *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10121 } else if (From->isDelegatingInitializer()) {
10122 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10123 if (!ToTInfoOrErr)
10124 return ToTInfoOrErr.takeError();
10125
10126 return new (ToContext)
10127 CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10128 *ToExprOrErr, *RParenLocOrErr);
10129 } else {
10130 // FIXME: assert?
10131 return make_error<ASTImportError>();
10132 }
10133}
10134
10137 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10138 if (Pos != ImportedCXXBaseSpecifiers.end())
10139 return Pos->second;
10140
10141 Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10142 if (!ToSourceRange)
10143 return ToSourceRange.takeError();
10145 if (!ToTSI)
10146 return ToTSI.takeError();
10147 ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10148 if (!ToEllipsisLoc)
10149 return ToEllipsisLoc.takeError();
10150 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10151 *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10152 BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10153 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10154 return Imported;
10155}
10156
10158 ASTNodeImporter Importer(*this);
10159 return Importer.ImportAPValue(FromValue);
10160}
10161
10163 ExpectedDecl ToOrErr = Import(From);
10164 if (!ToOrErr)
10165 return ToOrErr.takeError();
10166 Decl *To = *ToOrErr;
10167
10168 auto *FromDC = cast<DeclContext>(From);
10169 ASTNodeImporter Importer(*this);
10170
10171 if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10172 if (!ToRecord->getDefinition()) {
10173 return Importer.ImportDefinition(
10174 cast<RecordDecl>(FromDC), ToRecord,
10176 }
10177 }
10178
10179 if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10180 if (!ToEnum->getDefinition()) {
10181 return Importer.ImportDefinition(
10182 cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything);
10183 }
10184 }
10185
10186 if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10187 if (!ToIFace->getDefinition()) {
10188 return Importer.ImportDefinition(
10189 cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10191 }
10192 }
10193
10194 if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10195 if (!ToProto->getDefinition()) {
10196 return Importer.ImportDefinition(
10197 cast<ObjCProtocolDecl>(FromDC), ToProto,
10199 }
10200 }
10201
10202 return Importer.ImportDeclContext(FromDC, true);
10203}
10204
10206 if (!FromName)
10207 return DeclarationName{};
10208
10209 switch (FromName.getNameKind()) {
10211 return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10212
10216 if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10217 return DeclarationName(*ToSelOrErr);
10218 else
10219 return ToSelOrErr.takeError();
10220
10222 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10223 return ToContext.DeclarationNames.getCXXConstructorName(
10224 ToContext.getCanonicalType(*ToTyOrErr));
10225 else
10226 return ToTyOrErr.takeError();
10227 }
10228
10230 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10231 return ToContext.DeclarationNames.getCXXDestructorName(
10232 ToContext.getCanonicalType(*ToTyOrErr));
10233 else
10234 return ToTyOrErr.takeError();
10235 }
10236
10238 if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10240 cast<TemplateDecl>(*ToTemplateOrErr));
10241 else
10242 return ToTemplateOrErr.takeError();
10243 }
10244
10246 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10248 ToContext.getCanonicalType(*ToTyOrErr));
10249 else
10250 return ToTyOrErr.takeError();
10251 }
10252
10254 return ToContext.DeclarationNames.getCXXOperatorName(
10255 FromName.getCXXOverloadedOperator());
10256
10259 Import(FromName.getCXXLiteralIdentifier()));
10260
10262 // FIXME: STATICS!
10264 }
10265
10266 llvm_unreachable("Invalid DeclarationName Kind!");
10267}
10268
10270 if (!FromId)
10271 return nullptr;
10272
10273 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10274
10275 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10276 ToId->setBuiltinID(FromId->getBuiltinID());
10277
10278 return ToId;
10279}
10280
10282 if (FromSel.isNull())
10283 return Selector{};
10284
10286 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10287 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10288 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10289 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10290}
10291
10295 llvm::Error Err = llvm::Error::success();
10296 auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10297 for (unsigned Idx = 0; Idx < Size; Idx++) {
10298 APValue Tmp = importChecked(Err, From[Idx]);
10299 To[Idx] = Tmp;
10300 }
10301 };
10302 switch (FromValue.getKind()) {
10303 case APValue::None:
10305 case APValue::Int:
10306 case APValue::Float:
10310 Result = FromValue;
10311 break;
10312 case APValue::Vector: {
10313 Result.MakeVector();
10315 Result.setVectorUninit(FromValue.getVectorLength());
10316 ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10317 Elts.data(), FromValue.getVectorLength());
10318 break;
10319 }
10320 case APValue::Array:
10321 Result.MakeArray(FromValue.getArrayInitializedElts(),
10322 FromValue.getArraySize());
10323 ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10324 ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10325 FromValue.getArrayInitializedElts());
10326 break;
10327 case APValue::Struct:
10328 Result.MakeStruct(FromValue.getStructNumBases(),
10329 FromValue.getStructNumFields());
10330 ImportLoop(
10331 ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10332 ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10333 FromValue.getStructNumBases() + FromValue.getStructNumFields());
10334 break;
10335 case APValue::Union: {
10336 Result.MakeUnion();
10337 const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10338 APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10339 if (Err)
10340 return std::move(Err);
10341 Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10342 break;
10343 }
10345 Result.MakeAddrLabelDiff();
10346 const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10347 const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10348 if (Err)
10349 return std::move(Err);
10350 Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10351 cast<AddrLabelExpr>(ImpRHS));
10352 break;
10353 }
10355 const Decl *ImpMemPtrDecl =
10356 importChecked(Err, FromValue.getMemberPointerDecl());
10357 if (Err)
10358 return std::move(Err);
10360 Result.setMemberPointerUninit(
10361 cast<const ValueDecl>(ImpMemPtrDecl),
10363 FromValue.getMemberPointerPath().size());
10365 Result.getMemberPointerPath();
10366 for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10367 Idx++) {
10368 const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10369 if (Err)
10370 return std::move(Err);
10371 ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10372 }
10373 break;
10374 }
10375 case APValue::LValue:
10377 QualType FromElemTy;
10378 if (FromValue.getLValueBase()) {
10379 assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10380 "in C++20 dynamic allocation are transient so they shouldn't "
10381 "appear in the AST");
10382 if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10383 if (const auto *E =
10384 FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10385 FromElemTy = E->getType();
10386 const Expr *ImpExpr = importChecked(Err, E);
10387 if (Err)
10388 return std::move(Err);
10389 Base = APValue::LValueBase(ImpExpr,
10390 FromValue.getLValueBase().getCallIndex(),
10391 FromValue.getLValueBase().getVersion());
10392 } else {
10393 FromElemTy =
10394 FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10395 const Decl *ImpDecl = importChecked(
10396 Err, FromValue.getLValueBase().get<const ValueDecl *>());
10397 if (Err)
10398 return std::move(Err);
10399 Base = APValue::LValueBase(cast<ValueDecl>(ImpDecl),
10400 FromValue.getLValueBase().getCallIndex(),
10401 FromValue.getLValueBase().getVersion());
10402 }
10403 } else {
10404 FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10405 const Type *ImpTypeInfo = importChecked(
10406 Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10407 QualType ImpType =
10408 importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10409 if (Err)
10410 return std::move(Err);
10412 ImpType);
10413 }
10414 }
10415 CharUnits Offset = FromValue.getLValueOffset();
10416 unsigned PathLength = FromValue.getLValuePath().size();
10417 Result.MakeLValue();
10418 if (FromValue.hasLValuePath()) {
10419 MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10420 Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10421 FromValue.isNullPointer());
10423 FromValue.getLValuePath();
10424 for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10425 if (FromElemTy->isRecordType()) {
10426 const Decl *FromDecl =
10427 FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10428 const Decl *ImpDecl = importChecked(Err, FromDecl);
10429 if (Err)
10430 return std::move(Err);
10431 if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10432 FromElemTy = Importer.FromContext.getRecordType(RD);
10433 else
10434 FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10436 ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10437 } else {
10438 FromElemTy =
10439 Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10440 ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10441 FromPath[LoopIdx].getAsArrayIndex());
10442 }
10443 }
10444 } else
10445 Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10446 FromValue.isNullPointer());
10447 }
10448 if (Err)
10449 return std::move(Err);
10450 return Result;
10451}
10452
10454 DeclContext *DC,
10455 unsigned IDNS,
10456 NamedDecl **Decls,
10457 unsigned NumDecls) {
10458 if (ODRHandling == ODRHandlingType::Conservative)
10459 // Report error at any name conflict.
10460 return make_error<ASTImportError>(ASTImportError::NameConflict);
10461 else
10462 // Allow to create the new Decl with the same name.
10463 return Name;
10464}
10465
10467 if (LastDiagFromFrom)
10469 FromContext.getDiagnostics());
10470 LastDiagFromFrom = false;
10471 return ToContext.getDiagnostics().Report(Loc, DiagID);
10472}
10473
10475 if (!LastDiagFromFrom)
10477 ToContext.getDiagnostics());
10478 LastDiagFromFrom = true;
10479 return FromContext.getDiagnostics().Report(Loc, DiagID);
10480}
10481
10483 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10484 if (!ID->getDefinition())
10485 ID->startDefinition();
10486 }
10487 else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10488 if (!PD->getDefinition())
10489 PD->startDefinition();
10490 }
10491 else if (auto *TD = dyn_cast<TagDecl>(D)) {
10492 if (!TD->getDefinition() && !TD->isBeingDefined()) {
10493 TD->startDefinition();
10494 TD->setCompleteDefinition(true);
10495 }
10496 }
10497 else {
10498 assert(0 && "CompleteDecl called on a Decl that can't be completed");
10499 }
10500}
10501
10503 llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From);
10504 assert((Pos == ImportedDecls.end() || Pos->second == To) &&
10505 "Try to import an already imported Decl");
10506 if (Pos != ImportedDecls.end())
10507 return Pos->second;
10508 ImportedDecls[From] = To;
10509 // This mapping should be maintained only in this function. Therefore do not
10510 // check for additional consistency.
10511 ImportedFromDecls[To] = From;
10512 // In the case of TypedefNameDecl we create the Decl first and only then we
10513 // import and set its DeclContext. So, the DC is still not set when we reach
10514 // here from GetImportedOrCreateDecl.
10515 if (To->getDeclContext())
10516 AddToLookupTable(To);
10517 return To;
10518}
10519
10520std::optional<ASTImportError>
10522 auto Pos = ImportDeclErrors.find(FromD);
10523 if (Pos != ImportDeclErrors.end())
10524 return Pos->second;
10525 else
10526 return std::nullopt;
10527}
10528
10530 auto InsertRes = ImportDeclErrors.insert({From, Error});
10531 (void)InsertRes;
10532 // Either we set the error for the first time, or we already had set one and
10533 // now we want to set the same error.
10534 assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10535}
10536
10538 bool Complain) {
10539 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10540 ImportedTypes.find(From.getTypePtr());
10541 if (Pos != ImportedTypes.end()) {
10542 if (ExpectedType ToFromOrErr = Import(From)) {
10543 if (ToContext.hasSameType(*ToFromOrErr, To))
10544 return true;
10545 } else {
10546 llvm::consumeError(ToFromOrErr.takeError());
10547 }
10548 }
10549
10550 StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls,
10551 getStructuralEquivalenceKind(*this), false,
10552 Complain);
10553 return Ctx.IsEquivalent(From, To);
10554}
Defines the clang::ASTContext interface.
ASTImporterLookupTable & LT
static FriendCountAndPosition getFriendCountAndPosition(ASTImporter &Importer, FriendDecl *FD)
static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1, FriendDecl *FD2)
static auto getTemplateDefinition(T *D) -> T *
static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D)
static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, ASTImporter &Importer)
static StructuralEquivalenceKind getStructuralEquivalenceKind(const ASTImporter &Importer)
Defines enum values for all the target-independent builtin functions.
const Decl * D
IndirectLocalPath & Path
Expr * E
enum clang::sema::@1712::IndirectLocalPathEntry::EntryKind Kind
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines the ExceptionSpecificationType enumeration and various utility functions.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines the clang::FileManager interface and associated types.
int Category
Definition: Format.cpp:3035
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the LambdaCapture class.
Defines the clang::LangOptions interface.
llvm::MachO::Record Record
Definition: MachO.h:31
llvm::SmallVector< std::pair< const MemRegion *, SVal >, 4 > Bindings
SourceLocation Loc
Definition: SemaObjC.cpp:759
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Defines various enumerations that describe declaration and type specifiers.
Defines the Objective-C statement AST node classes.
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
const NamedDecl * FromDecl
unsigned getVersion() const
Definition: APValue.cpp:113
QualType getTypeInfoType() const
Definition: APValue.cpp:117
static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo)
Definition: APValue.cpp:55
unsigned getCallIndex() const
Definition: APValue.cpp:108
A non-discriminated union of a base, field, or array index.
Definition: APValue.h:206
static LValuePathEntry ArrayIndex(uint64_t Index)
Definition: APValue.h:214
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
const LValueBase getLValueBase() const
Definition: APValue.cpp:973
ArrayRef< LValuePathEntry > getLValuePath() const
Definition: APValue.cpp:993
const FieldDecl * getUnionField() const
Definition: APValue.h:605
unsigned getStructNumFields() const
Definition: APValue.h:584
llvm::PointerIntPair< const Decl *, 1, bool > BaseOrMemberType
A FieldDecl or CXXRecordDecl, along with a flag indicating whether we mean a virtual or non-virtual b...
Definition: APValue.h:203
ValueKind getKind() const
Definition: APValue.h:437
bool isLValueOnePastTheEnd() const
Definition: APValue.cpp:978
bool isMemberPointerToDerivedMember() const
Definition: APValue.cpp:1063
unsigned getArrayInitializedElts() const
Definition: APValue.h:571
unsigned getStructNumBases() const
Definition: APValue.h:580
bool hasLValuePath() const
Definition: APValue.cpp:988
const ValueDecl * getMemberPointerDecl() const
Definition: APValue.cpp:1056
APValue & getUnionValue()
Definition: APValue.h:609
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition: APValue.h:625
CharUnits & getLValueOffset()
Definition: APValue.cpp:983
unsigned getVectorLength() const
Definition: APValue.h:547
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition: APValue.cpp:1070
unsigned getArraySize() const
Definition: APValue.h:575
@ Indeterminate
This object has an indeterminate value (C++ [basic.indet]).
Definition: APValue.h:131
@ None
There is no such object (it's outside its lifetime).
Definition: APValue.h:129
bool isNullPointer() const
Definition: APValue.cpp:1009
const AddrLabelExpr * getAddrLabelDiffLHS() const
Definition: APValue.h:621
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
QualType getUsingType(const UsingShadowDecl *Found, QualType Underlying) const
SourceManager & getSourceManager()
Definition: ASTContext.h:741
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1141
QualType getAtomicType(QualType T) const
Return the uniqued reference to the atomic type for the specified type.
QualType getParenType(QualType NamedType) const
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type.
BuiltinTemplateDecl * getBuiltinCommonTypeDecl() const
BuiltinTemplateDecl * getMakeIntegerSeqDecl() const
void setInstantiatedFromUsingDecl(NamedDecl *Inst, NamedDecl *Pattern)
Remember that the using decl Inst is an instantiation of the using decl Pattern of a class template.
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent, bool IsPack=false, ConceptDecl *TypeConstraintConcept=nullptr, ArrayRef< TemplateArgument > TypeConstraintArgs={}) const
C++11 deduced auto type.
QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, ArrayRef< TemplateArgumentLoc > Args) const
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl.
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl.
QualType getMemberPointerType(QualType T, const Type *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
NamedDecl * getInstantiatedFromUsingDecl(NamedDecl *Inst)
If the given using decl Inst is an instantiation of another (possibly unresolved) using decl,...
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:684
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType, const Attr *attr=nullptr) const
QualType getTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon=QualType()) const
QualType getRecordType(const RecordDecl *Decl) const
QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const
getInjectedClassNameType - Return the unique reference to the injected class name type for the specif...
QualType getVariableArrayType(QualType EltTy, Expr *NumElts, ArraySizeModifier ASM, unsigned IndexTypeQuals, SourceRange Brackets) const
Return a non-unique reference to the type for a variable array of the specified element type.
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
QualType getArrayParameterType(QualType Ty) const
Return the uniqued reference to a specified array parameter type from the original array type.
QualType getCountAttributedType(QualType T, Expr *CountExpr, bool CountInBytes, bool OrNull, ArrayRef< TypeCoupledDeclRefInfo > DependentDecls) const
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2716
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2732
void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, UsingShadowDecl *Pattern)
TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, bool TemplateKeyword, TemplateName Template) const
Retrieve the template name that represents a qualified template name such as std::vector.
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
QualType getReadPipeType(QualType T) const
Return a read_only pipe type for the specified type.
QualType getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex, SubstTemplateTypeParmTypeFlag Flag=SubstTemplateTypeParmTypeFlag::None) const
Retrieve a substitution-result type.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1703
IdentifierTable & Idents
Definition: ASTContext.h:680
TemplateName getSubstTemplateTemplateParm(TemplateName replacement, Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex) const
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
const LangOptions & getLangOpts() const
Definition: ASTContext.h:834
SelectorTable & Selectors
Definition: ASTContext.h:681
QualType getMacroQualifiedType(QualType UnderlyingTy, const IdentifierInfo *MacroII) const
QualType getDecayedType(QualType T) const
Return the uniqued reference to the decayed version of the given type.
void setInstantiatedFromUsingEnumDecl(UsingEnumDecl *Inst, UsingEnumDecl *Pattern)
Remember that the using enum decl Inst is an instantiation of the using enum decl Pattern of a class ...
UsingEnumDecl * getInstantiatedFromUsingEnumDecl(UsingEnumDecl *Inst)
If the given using-enum decl Inst is an instantiation of another using-enum decl, return it.
QualType getDeducedTemplateSpecializationType(TemplateName Template, QualType DeducedType, bool IsDependent) const
C++17 deduced class template specialization type.
QualType getTemplateTypeParmType(unsigned Depth, unsigned Index, bool ParameterPack, TemplateTypeParmDecl *ParmDecl=nullptr) const
Retrieve the template type parameter type for a template parameter or parameter pack with the given d...
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
QualType getSubstTemplateTypeParmPackType(Decl *AssociatedDecl, unsigned Index, bool Final, const TemplateArgument &ArgPack)
Retrieve a.
CanQualType CharTy
Definition: ASTContext.h:1162
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:2289
QualType getElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType, TagDecl *OwnedTagDecl=nullptr) const
CanQualType SignedCharTy
Definition: ASTContext.h:1169
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
QualType getPackExpansionType(QualType Pattern, std::optional< unsigned > NumExpansions, bool ExpectPackInType=true) const
Form a pack expansion type with the given pattern.
QualType getObjCObjectType(QualType Base, ObjCProtocolDecl *const *Protocols, unsigned NumProtocols) const
Legacy interface: cannot provide type arguments or __kindof.
QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts, ArraySizeModifier ASM, unsigned IndexTypeQuals, SourceRange Brackets) const
Return a non-unique reference to the type for a dependently-sized array of the specified element type...
UsingShadowDecl * getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst)
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
QualType getWritePipeType(QualType T) const
Return a write_only pipe type for the specified type.
CanQualType VoidTy
Definition: ASTContext.h:1160
CanQualType UnsignedCharTy
Definition: ASTContext.h:1170
TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, const IdentifierInfo *Name) const
Retrieve the template name that represents a dependent template name such as MetaFun::template apply.
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
Definition: ASTContext.h:1681
QualType getDependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, QualType Canon=QualType()) const
QualType getPackIndexingType(QualType Pattern, Expr *IndexExpr, bool FullySubstituted=false, ArrayRef< QualType > Expansions={}, int Index=-1) const
QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType, UnaryTransformType::UTTKind UKind) const
Unary type transforms.
QualType getComplexType(QualType T) const
Return the uniqued reference to the type for a complex number with the specified element type.
DiagnosticsEngine & getDiagnostics() const
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size.
TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, UnresolvedSetIterator End) const
Retrieve the template name that corresponds to a non-empty lookup.
TemplateName getSubstTemplateTemplateParmPack(const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index, bool Final) const
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Definition: ASTContext.h:1274
BuiltinTemplateDecl * getTypePackElementDecl() const
QualType getTypeOfType(QualType QT, TypeOfKind Kind) const
getTypeOfType - Unlike many "get<Type>" functions, we don't unique TypeOfType nodes.
CanQualType WCharTy
Definition: ASTContext.h:1163
QualType getDecltypeType(Expr *e, QualType UnderlyingType) const
C++11 decltype.
QualType getTypedefType(const TypedefNameDecl *Decl, QualType Underlying=QualType()) const
Return the unique reference to the type for the specified typedef-name decl.
unsigned char getFixedPointScale(QualType Ty) const
QualType getIncompleteArrayType(QualType EltTy, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return a unique reference to the type for an incomplete array of the specified element type.
QualType getDependentSizedExtVectorType(QualType VectorType, Expr *SizeExpr, SourceLocation AttrLoc) const
TemplateName getAssumedTemplateName(DeclarationName Name) const
Retrieve a template name representing an unqualified-id that has been assumed to name a template for ...
QualType getTypeOfExprType(Expr *E, TypeOfKind Kind) const
C23 feature and GCC extension.
std::error_code convertToErrorCode() const override
void log(llvm::raw_ostream &OS) const override
Definition: ASTImporter.cpp:98
std::string toString() const
Definition: ASTImporter.cpp:84
@ Unknown
Not supported node or case.
@ UnsupportedConstruct
Naming ambiguity (likely ODR violation).
void update(NamedDecl *ND, DeclContext *OldDC)
void updateForced(NamedDecl *ND, DeclContext *OldDC)
bool hasCycleAtBack() const
Returns true if the last element can be found earlier in the path.
Definition: ASTImporter.h:165
VecTy copyCycleAtBack() const
Returns the copy of the cycle.
Definition: ASTImporter.h:179
Imports selected nodes from one AST context into another context, merging AST nodes where appropriate...
Definition: ASTImporter.h:62
ASTContext & getFromContext() const
Retrieve the context that AST nodes are being imported from.
Definition: ASTImporter.h:528
NonEquivalentDeclSet & getNonEquivalentDecls()
Return the set of declarations that we know are not equivalent.
Definition: ASTImporter.h:543
ASTContext & getToContext() const
Retrieve the context that AST nodes are being imported into.
Definition: ASTImporter.h:525
DiagnosticBuilder ToDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "to" context.
Decl * MapImported(Decl *From, Decl *To)
Store and assign the imported declaration to its counterpart.
llvm::DenseSet< std::tuple< Decl *, Decl *, int > > NonEquivalentDeclSet
Definition: ASTImporter.h:66
TranslationUnitDecl * GetFromTU(Decl *ToD)
Return the translation unit from where the declaration was imported.
llvm::Expected< DeclContext * > ImportContext(DeclContext *FromDC)
Import the given declaration context from the "from" AST context into the "to" AST context.
llvm::Error ImportDefinition(Decl *From)
Import the definition of the given declaration, including all of the declarations it contains.
virtual Expected< DeclarationName > HandleNameConflict(DeclarationName Name, DeclContext *DC, unsigned IDNS, NamedDecl **Decls, unsigned NumDecls)
Cope with a name conflict when importing a declaration into the given context.
virtual bool returnWithErrorInTest()
Used only in unittests to verify the behaviour of the error handling.
Definition: ASTImporter.h:270
std::optional< DeclT * > getImportedFromDecl(const DeclT *ToD) const
Return the declaration in the "from" context from which the declaration in the "to" context was impor...
Definition: ASTImporter.h:371
void RegisterImportedDecl(Decl *FromD, Decl *ToD)
std::optional< ASTImportError > getImportDeclErrorIfAny(Decl *FromD) const
Return if import of the given declaration has failed and if yes the kind of the problem.
friend class ASTNodeImporter
Definition: ASTImporter.h:63
static std::optional< unsigned > getFieldIndex(Decl *F)
Determine the index of a field in its parent record.
llvm::Error importInto(ImportT &To, const ImportT &From)
Import the given object, returns the result.
Definition: ASTImporter.h:308
virtual Decl * GetOriginalDecl(Decl *To)
Called by StructuralEquivalenceContext.
Definition: ASTImporter.h:568
virtual void Imported(Decl *From, Decl *To)
Subclasses can override this function to observe all of the From -> To declaration mappings as they a...
Definition: ASTImporter.h:553
DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "from" context.
virtual ~ASTImporter()
bool IsStructurallyEquivalent(QualType From, QualType To, bool Complain=true)
Determine whether the given types are structurally equivalent.
virtual Expected< Decl * > ImportImpl(Decl *From)
Can be overwritten by subclasses to implement their own import logic.
bool isMinimalImport() const
Whether the importer will perform a minimal import, creating to-be-completed forward declarations whe...
Definition: ASTImporter.h:298
ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, ASTContext &FromContext, FileManager &FromFileManager, bool MinimalImport, std::shared_ptr< ASTImporterSharedState > SharedState=nullptr)
llvm::Expected< ExprWithCleanups::CleanupObject > Import(ExprWithCleanups::CleanupObject From)
Import cleanup objects owned by ExprWithCleanup.
virtual void CompleteDecl(Decl *D)
Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl.
Decl * GetAlreadyImportedOrNull(const Decl *FromD) const
Return the copy of the given declaration in the "to" context if it has already been imported from the...
void setImportDeclError(Decl *From, ASTImportError Error)
Mark (newly) imported declaration with error.
ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D)
ExpectedStmt VisitGenericSelectionExpr(GenericSelectionExpr *E)
ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E)
ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D)
ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D)
ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E)
ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D)
ExpectedDecl VisitFunctionDecl(FunctionDecl *D)
ExpectedDecl VisitParmVarDecl(ParmVarDecl *D)
ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E)
ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E)
ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D)
ExpectedDecl VisitUsingDecl(UsingDecl *D)
ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D)
ExpectedStmt VisitStmt(Stmt *S)
ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D)
ExpectedDecl VisitFieldDecl(FieldDecl *D)
Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To)
Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD=nullptr)
ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E)
ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E)
ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S)
ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D)
ExpectedStmt VisitShuffleVectorExpr(ShuffleVectorExpr *E)
ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D)
ExpectedDecl VisitRecordDecl(RecordDecl *D)
ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E)
ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D)
Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin)
ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S)
T importChecked(Error &Err, const T &From)
ExpectedStmt VisitVAArgExpr(VAArgExpr *E)
ExpectedStmt VisitDefaultStmt(DefaultStmt *S)
ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D)
ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E)
ExpectedDecl VisitLabelDecl(LabelDecl *D)
ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E)
ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S)
ExpectedStmt VisitUnaryOperator(UnaryOperator *E)
Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD)
Error ImportDeclContext(DeclContext *FromDC, bool ForceImport=false)
ExpectedStmt VisitContinueStmt(ContinueStmt *S)
ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E)
ExpectedDecl VisitVarDecl(VarDecl *D)
ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E)
ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D)
Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To)
ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E)
ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E)
ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D)
ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D)
ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E)
ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE)
ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E)
ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D)
ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E)
ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D)
Expected< InheritedConstructor > ImportInheritedConstructor(const InheritedConstructor &From)
ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E)
Error ImportDeclParts(NamedDecl *D, DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc)
Error ImportDefinition(RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind=IDK_Default)
ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S)
ExpectedStmt VisitConstantExpr(ConstantExpr *E)
ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E)
ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E)
ExpectedDecl VisitDecl(Decl *D)
bool hasSameVisibilityContextAndLinkage(T *Found, T *From)
ExpectedStmt VisitParenExpr(ParenExpr *E)
ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S)
ExpectedStmt VisitSourceLocExpr(SourceLocExpr *E)
ExpectedStmt VisitInitListExpr(InitListExpr *E)
Expected< FunctionTemplateAndArgsTy > ImportFunctionTemplateWithTemplateArgsFromSpecialization(FunctionDecl *FromFD)
ExpectedStmt VisitReturnStmt(ReturnStmt *S)
ExpectedStmt VisitAtomicExpr(AtomicExpr *E)
ExpectedStmt VisitConditionalOperator(ConditionalOperator *E)
ExpectedStmt VisitChooseExpr(ChooseExpr *E)
ExpectedStmt VisitCompoundStmt(CompoundStmt *S)
Expected< TemplateArgument > ImportTemplateArgument(const TemplateArgument &From)
ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E)
ExpectedStmt VisitCaseStmt(CaseStmt *S)
ExpectedStmt VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *E)
ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E)
ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D)
ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E)
ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E)
ExpectedStmt VisitLambdaExpr(LambdaExpr *LE)
ExpectedStmt VisitBinaryOperator(BinaryOperator *E)
ExpectedStmt VisitCallExpr(CallExpr *E)
ExpectedStmt VisitDeclStmt(DeclStmt *S)
ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E)
ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E)
Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin)
ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D)
ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D)
Expected< CXXCastPath > ImportCastPath(CastExpr *E)
Expected< APValue > ImportAPValue(const APValue &FromValue)
ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D)
ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E)
ExpectedDecl VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D)
ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E)
ExpectedDecl VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D)
ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias)
ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D)
ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D)
ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D)
Expected< ObjCTypeParamList * > ImportObjCTypeParamList(ObjCTypeParamList *list)
ExpectedDecl VisitUsingPackDecl(UsingPackDecl *D)
ExpectedStmt VisitWhileStmt(WhileStmt *S)
ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D)
ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E)
ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S)
ExpectedDecl VisitFriendDecl(FriendDecl *D)
Error ImportContainerChecked(const InContainerTy &InContainer, OutContainerTy &OutContainer)
ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E)
ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E)
bool IsStructuralMatch(Decl *From, Decl *To, bool Complain=true, bool IgnoreTemplateParmDepth=false)
ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E)
ExpectedStmt VisitForStmt(ForStmt *S)
ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E)
ExpectedDecl VisitEnumDecl(EnumDecl *D)
ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D)
ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E)
ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E)
ExpectedStmt VisitSwitchStmt(SwitchStmt *S)
ExpectedType VisitType(const Type *T)
ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D)
ExpectedDecl ImportUsingShadowDecls(BaseUsingDecl *D, BaseUsingDecl *ToSI)
ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E)
ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E)
ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D)
ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E)
ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D)
ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E)
ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E)
ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D)
Error ImportTemplateArguments(ArrayRef< TemplateArgument > FromArgs, SmallVectorImpl< TemplateArgument > &ToArgs)
ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D)
ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E)
ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D)
ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D)
ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E)
ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E)
Error ImportTemplateArgumentListInfo(const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo)
ExpectedStmt VisitDoStmt(DoStmt *S)
ExpectedStmt VisitNullStmt(NullStmt *S)
ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E)
ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D)
Error ImportOverriddenMethods(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod)
ExpectedStmt VisitStringLiteral(StringLiteral *E)
Error ImportDeclarationNameLoc(const DeclarationNameInfo &From, DeclarationNameInfo &To)
ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E)
bool hasReturnTypeDeclaredInside(FunctionDecl *D)
This function checks if the given function has a return type that contains a reference (in any way) t...
ASTNodeImporter(ASTImporter &Importer)
std::tuple< FunctionTemplateDecl *, TemplateArgsTy > FunctionTemplateAndArgsTy
ExpectedDecl VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D)
ExpectedStmt VisitMemberExpr(MemberExpr *E)
ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E)
Error ImportInitializer(VarDecl *From, VarDecl *To)
ImportDefinitionKind
What we should import from the definition.
@ IDK_Everything
Import everything.
@ IDK_Default
Import the default subset of the definition, which might be nothing (if minimal import is set) or mig...
@ IDK_Basic
Import only the bare bones needed to establish a valid DeclContext.
ExpectedDecl VisitTypedefDecl(TypedefDecl *D)
ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D)
ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E)
ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D)
ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E)
ExpectedStmt VisitIfStmt(IfStmt *S)
ExpectedStmt VisitLabelStmt(LabelStmt *S)
ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E)
ExpectedStmt VisitConvertVectorExpr(ConvertVectorExpr *E)
ExpectedDecl VisitUsingEnumDecl(UsingEnumDecl *D)
ExpectedStmt VisitGotoStmt(GotoStmt *S)
ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E)
ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S)
ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S)
ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D)
ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S)
ExpectedDecl VisitImportDecl(ImportDecl *D)
Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD)
ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E)
ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E)
ExpectedDecl VisitEmptyDecl(EmptyDecl *D)
ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E)
ExpectedStmt VisitExpr(Expr *E)
Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam, ParmVarDecl *ToParam)
ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E)
ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S)
ExpectedStmt VisitAttributedStmt(AttributedStmt *S)
ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S)
ExpectedStmt VisitParenListExpr(ParenListExpr *E)
Expected< FunctionDecl * > FindFunctionTemplateSpecialization(FunctionDecl *FromFD)
ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D)
ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S)
Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD)
ExpectedStmt VisitStmtExpr(StmtExpr *E)
ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E)
bool shouldForceImportDeclContext(ImportDefinitionKind IDK)
ExpectedDecl VisitBindingDecl(BindingDecl *D)
ExpectedStmt VisitBreakStmt(BreakStmt *S)
Represents an access specifier followed by colon ':'.
Definition: DeclCXX.h:86
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition: Expr.h:4421
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Definition: Type.h:3357
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition: Expr.h:5805
Represents a loop initializing the elements of an array.
Definition: Expr.h:5752
Represents a constant array type that does not decay to a pointer when used as a function parameter.
Definition: Type.h:3747
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2718
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition: ExprCXX.h:2853
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3577
QualType getElementType() const
Definition: Type.h:3589
A structure for storing the information associated with a name that has been assumed to be a template...
DeclarationName getDeclName() const
Get the name of the template.
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition: Expr.h:6678
Attr - This represents one attribute.
Definition: Attr.h:43
attr::Kind getKind() const
Definition: Attr.h:89
void setPackExpansion(bool PE)
Definition: Attr.h:105
Attr * clone(ASTContext &C) const
void setImplicit(bool I)
Definition: Attr.h:103
void setAttrName(const IdentifierInfo *AttrNameII)
const IdentifierInfo * getAttrName() const
Represents an attribute applied to a statement.
Definition: Stmt.h:2117
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: Stmt.cpp:423
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:6127
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:6556
Represents a C++ declaration that introduces decls from somewhere else.
Definition: DeclCXX.h:3435
void addShadowDecl(UsingShadowDecl *S)
Definition: DeclCXX.cpp:3211
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition: Expr.h:4324
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3909
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Definition: Expr.cpp:4895
A binding in a decomposition declaration.
Definition: DeclCXX.h:4125
void setBinding(QualType DeclaredType, Expr *Binding)
Set the binding for this BindingDecl, along with its declared type (which should be a possibly-cv-qua...
Definition: DeclCXX.h:4162
void setDecomposedDecl(ValueDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition: DeclCXX.h:4168
A fixed int type of a specified bitwidth.
Definition: Type.h:7814
Pointer to a block type.
Definition: Type.h:3408
BreakStmt - This represents a break.
Definition: Stmt.h:3017
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition: ExprCXX.h:5298
Represents the builtin template declaration which is used to implement __make_integer_seq and other b...
This class is used for builtin types like 'int'.
Definition: Type.h:3034
static CStyleCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *BasePath, FPOptionsOverride FPO, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation R)
Definition: Expr.cpp:2113
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
AccessSpecifier getAccessSpecifierAsWritten() const
Retrieves the access specifier as written in the source code (which may mean that no access specifier...
Definition: DeclCXX.h:242
SourceLocation getEllipsisLoc() const
For a pack expansion, determine the location of the ellipsis.
Definition: DeclCXX.h:221
bool isVirtual() const
Determines whether the base class is a virtual base class (or not).
Definition: DeclCXX.h:203
TypeSourceInfo * getTypeSourceInfo() const
Retrieves the type and source location of the base class.
Definition: DeclCXX.h:254
bool isBaseOfClass() const
Determine whether this base class is a base of a class declared with the 'class' keyword (vs.
Definition: DeclCXX.h:207
SourceRange getSourceRange() const LLVM_READONLY
Retrieves the source range that contains the entire base specifier.
Definition: DeclCXX.h:193
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1491
static CXXBindTemporaryExpr * Create(const ASTContext &C, CXXTemporary *Temp, Expr *SubExpr)
Definition: ExprCXX.cpp:1097
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition: ExprCXX.h:720
static CXXBoolLiteralExpr * Create(const ASTContext &C, bool Val, QualType Ty, SourceLocation Loc)
Definition: ExprCXX.h:732
CXXCatchStmt - This represents a C++ catch block.
Definition: StmtCXX.h:28
static CXXConstCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, Expr *Op, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:875
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1546
void setIsImmediateEscalating(bool Set)
Definition: ExprCXX.h:1708
static CXXConstructExpr * Create(const ASTContext &Ctx, QualType Ty, SourceLocation Loc, CXXConstructorDecl *Ctor, bool Elidable, ArrayRef< Expr * > Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization, CXXConstructionKind ConstructKind, SourceRange ParenOrBraceRange)
Create a C++ construction expression.
Definition: ExprCXX.cpp:1159
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2553
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2880
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2318
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition: DeclCXX.h:2458
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition: DeclCXX.h:2418
Expr * getInit() const
Get the initializer.
Definition: DeclCXX.h:2520
SourceLocation getRParenLoc() const
Definition: DeclCXX.h:2517
SourceLocation getEllipsisLoc() const
Definition: DeclCXX.h:2428
SourceLocation getLParenLoc() const
Definition: DeclCXX.h:2516
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition: DeclCXX.h:2423
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition: DeclCXX.h:2452
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition: DeclCXX.h:2396
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition: DeclCXX.h:2390
bool isIndirectMemberInitializer() const
Definition: DeclCXX.h:2402
SourceLocation getMemberLocation() const
Definition: DeclCXX.h:2478
IndirectFieldDecl * getIndirectMember() const
Definition: DeclCXX.h:2472
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition: DeclCXX.h:2444
Represents a C++ deduction guide declaration.
Definition: DeclCXX.h:1967
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1268
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition: ExprCXX.cpp:1018
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1375
static CXXDefaultInitExpr * Create(const ASTContext &Ctx, SourceLocation Loc, FieldDecl *Field, DeclContext *UsedContext, Expr *RewrittenInitExpr)
Field is the non-static data member whose default initializer is used by this expression.
Definition: ExprCXX.cpp:1072
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition: ExprCXX.h:2498
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition: ExprCXX.h:3683
static CXXDependentScopeMemberExpr * Create(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:1533
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2817
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg)
Definition: DeclCXX.cpp:2962
static CXXDynamicCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:787
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:4846
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition: StmtCXX.h:135
static CXXFunctionalCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, TypeSourceInfo *Written, CastKind Kind, Expr *Op, const CXXCastPath *Path, FPOptionsOverride FPO, SourceLocation LPLoc, SourceLocation RPLoc)
Definition: ExprCXX.cpp:901
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1737
Represents a call to a member function that may be written either with member call syntax (e....
Definition: ExprCXX.h:176
static CXXMemberCallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RP, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0)
Definition: ExprCXX.cpp:675
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2078
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition: DeclCXX.cpp:2603
overridden_method_range overridden_methods() const
Definition: DeclCXX.cpp:2626
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:2174
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition: ExprCXX.h:372
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition: ExprCXX.h:2241
static CXXNewExpr * Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef< Expr * > PlacementArgs, SourceRange TypeIdParens, std::optional< Expr * > ArraySize, CXXNewInitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange)
Create a c++ new expression.
Definition: ExprCXX.cpp:291
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition: ExprCXX.h:4126
The null pointer literal (C++11 [lex.nullptr])
Definition: ExprCXX.h:765
static CXXOperatorCallExpr * Create(const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation OperatorLoc, FPOptionsOverride FPFeatures, ADLCallKind UsesADL=NotADL)
Definition: ExprCXX.cpp:611
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition: ExprCXX.h:2617
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
CXXRecordDecl * getMostRecentDecl()
Definition: DeclCXX.h:541
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
Definition: DeclCXX.cpp:1970
method_range methods() const
Definition: DeclCXX.h:662
CXXRecordDecl * getDefinition() const
Definition: DeclCXX.h:565
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, unsigned DependencyKind, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
Definition: DeclCXX.cpp:147
void setInstantiationOfMemberClass(CXXRecordDecl *RD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member class RD.
Definition: DeclCXX.cpp:1982
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition: DeclCXX.cpp:1995
void setLambdaNumbering(LambdaNumbering Numbering)
Set the mangling numbers and context declaration for a lambda class.
Definition: DeclCXX.cpp:1785
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
Definition: DeclCXX.cpp:1977
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition: DeclCXX.cpp:2010
CXXRecordDecl * getPreviousDecl()
Definition: DeclCXX.h:532
static CXXReinterpretCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:852
A rewritten comparison expression that was originally written using operator syntax.
Definition: ExprCXX.h:283
An expression "T()" which creates an rvalue of a non-class type T.
Definition: ExprCXX.h:2182
static CXXStaticCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, FPOptionsOverride FPO, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:761
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition: ExprCXX.h:797
Represents a C++ functional cast expression that builds a temporary object.
Definition: ExprCXX.h:1885
static CXXTemporaryObjectExpr * Create(const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty, TypeSourceInfo *TSI, ArrayRef< Expr * > Args, SourceRange ParenOrBraceRange, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization)
Definition: ExprCXX.cpp:1125
Represents a C++ temporary.
Definition: ExprCXX.h:1457
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition: ExprCXX.cpp:1092
Represents the this expression in C++.
Definition: ExprCXX.h:1152
static CXXThisExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType Ty, bool IsImplicit)
Definition: ExprCXX.cpp:1568
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:1206
CXXTryStmt - A C++ try block, including all handlers.
Definition: StmtCXX.h:69
static CXXTryStmt * Create(const ASTContext &C, SourceLocation tryLoc, CompoundStmt *tryBlock, ArrayRef< Stmt * > handlers)
Definition: StmtCXX.cpp:25
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition: ExprCXX.h:845
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition: ExprCXX.h:3557
static CXXUnresolvedConstructExpr * Create(const ASTContext &Context, QualType T, TypeSourceInfo *TSI, SourceLocation LParenLoc, ArrayRef< Expr * > Args, SourceLocation RParenLoc, bool IsListInit)
Definition: ExprCXX.cpp:1471
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2874
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
Definition: Expr.cpp:1492
CaseStmt - Represent a case statement.
Definition: Stmt.h:1838
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Definition: Stmt.cpp:1218
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3547
path_iterator path_begin()
Definition: Expr.h:3617
path_iterator path_end()
Definition: Expr.h:3618
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
How to handle import errors that occur when import of a child declaration of a DeclContext fails.
bool ignoreChildErrorOnParent(Decl *FromChildD) const
Determine if import failure of a child does not cause import failure of its parent.
ChildErrorHandlingStrategy(const Decl *FromD)
void handleChildImportResult(Error &ResultErr, Error &&ChildErr)
Process the import result of a child (of the current declaration).
ChildErrorHandlingStrategy(const DeclContext *FromDC)
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition: Expr.h:4641
Declaration of a class template.
void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, void *InsertPos)
Insert the specified partial specialization knowing that it is not already in.
ClassTemplateDecl * getMostRecentDecl()
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
ClassTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, TemplateParameterList *TPL, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
QualType getInjectedClassNameSpecialization()
Retrieve the template specialization type of the injected-class-name for this class template.
ClassTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
QualType getInjectedSpecializationType() const
Retrieves the injected specialization type for this partial specialization.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a class template specialization, which refers to a class template with a given set of temp...
void setPointOfInstantiation(SourceLocation Loc)
void setExternKeywordLoc(SourceLocation Loc)
Sets the location of the extern keyword.
void setSpecializationKind(TemplateSpecializationKind TSK)
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this class template specialization is actually an instantiation of the given class template...
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
Complex values, per C99 6.2.5p11.
Definition: Type.h:3145
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4171
static CompoundAssignOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures, QualType CompLHSType=QualType(), QualType CompResultType=QualType())
Definition: Expr.cpp:4917
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3477
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1638
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Definition: Stmt.cpp:381
A reference to a concept and its template args, as it appears in the code.
Definition: ASTConcept.h:124
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
Definition: ASTConcept.h:163
NamedDecl * getFoundDecl() const
Definition: ASTConcept.h:195
const DeclarationNameInfo & getConceptNameInfo() const
Definition: ASTConcept.h:167
ConceptDecl * getNamedConcept() const
Definition: ASTConcept.h:199
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
Definition: ASTConcept.cpp:87
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition: ASTConcept.h:203
SourceLocation getTemplateKWLoc() const
Definition: ASTConcept.h:173
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:4262
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3615
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition: Expr.h:1077
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition: Expr.cpp:350
Represents a concrete matrix type with constant number of rows and columns.
Definition: Type.h:4232
Represents a shadow constructor declaration introduced into a class by a C++11 using-declaration that...
Definition: DeclCXX.h:3616
ContinueStmt - This represents a continue.
Definition: Stmt.h:2987
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition: Expr.h:4582
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
Definition: Type.h:3306
Represents a pointer type decayed from an array or function type.
Definition: Type.h:3391
A POD class for pairing a NamedDecl* with an access specifier.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1368
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1435
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2089
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
Definition: DeclBase.cpp:2045
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1334
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1854
bool isRecord() const
Definition: DeclBase.h:2169
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1990
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
Definition: DeclBase.cpp:1776
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1642
void removeDecl(Decl *D)
Removes a declaration from this context.
Definition: DeclBase.cpp:1687
lookup_result noload_lookup(DeclarationName Name)
Find the declarations with the given name that are visible within this context; don't attempt to retr...
Definition: DeclBase.cpp:1919
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1637
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:2349
bool isFunctionOrMethod() const
Definition: DeclBase.h:2141
void localUncachedLookup(DeclarationName Name, SmallVectorImpl< NamedDecl * > &Results)
A simplistic name lookup mechanism that performs name lookup into this declaration context without co...
Definition: DeclBase.cpp:1951
static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls)
Definition: DeclGroup.h:68
iterator begin()
Definition: DeclGroup.h:99
iterator end()
Definition: DeclGroup.h:105
bool isNull() const
Definition: DeclGroup.h:79
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1265
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
Definition: Expr.cpp:488
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1529
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:67
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:438
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration.
Definition: DeclBase.cpp:258
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition: DeclBase.h:1215
bool hasAttrs() const
Definition: DeclBase.h:521
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:520
void addAttr(Attr *A)
Definition: DeclBase.cpp:1010
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:596
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition: DeclBase.cpp:239
bool isInIdentifierNamespace(unsigned NS) const
Definition: DeclBase.h:882
@ FOK_None
Not a friend object.
Definition: DeclBase.h:1206
void setObjectOfFriendDecl(bool PerformFriendInjection=false)
Changes the namespace of this declaration to reflect that it's the object of a friend declaration.
Definition: DeclBase.h:1169
void setAccess(AccessSpecifier AS)
Definition: DeclBase.h:505
SourceLocation getLocation() const
Definition: DeclBase.h:442
const char * getDeclKindName() const
Definition: DeclBase.cpp:142
IdentifierNamespace
IdentifierNamespace - The different namespaces in which declarations may appear.
Definition: DeclBase.h:115
@ IDNS_NonMemberOperator
This declaration is a C++ operator declared in a non-class context.
Definition: DeclBase.h:168
@ IDNS_TagFriend
This declaration is a friend class.
Definition: DeclBase.h:157
@ IDNS_Ordinary
Ordinary names.
Definition: DeclBase.h:144
@ IDNS_ObjCProtocol
Objective C @protocol.
Definition: DeclBase.h:147
@ IDNS_Namespace
Namespaces, declared with 'namespace foo {}'.
Definition: DeclBase.h:140
@ IDNS_OrdinaryFriend
This declaration is a friend function.
Definition: DeclBase.h:152
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
Definition: DeclBase.h:125
void setImplicit(bool I=true)
Definition: DeclBase.h:597
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: DeclBase.h:1038
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition: DeclBase.h:611
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition: DeclBase.cpp:549
DeclContext * getDeclContext()
Definition: DeclBase.h:451
AccessSpecifier getAccess() const
Definition: DeclBase.h:510
bool isInAnonymousNamespace() const
Definition: DeclBase.cpp:412
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:434
TranslationUnitDecl * getTranslationUnitDecl()
Definition: DeclBase.cpp:505
AttrVec & getAttrs()
Definition: DeclBase.h:527
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition: DeclBase.cpp:355
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:907
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:359
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:967
DeclarationName getCXXConversionFunctionName(CanQualType Ty)
Returns the name of a C++ conversion function for the given Type.
DeclarationName getCXXDestructorName(CanQualType Ty)
Returns the name of a C++ destructor for the given Type.
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
Get the name of the overloadable C++ operator corresponding to Op.
DeclarationName getCXXDeductionGuideName(TemplateDecl *TD)
Returns the name of a C++ deduction guide for the given template.
DeclarationName getCXXConstructorName(CanQualType Ty)
Returns the name of a C++ constructor for the given Type.
DeclarationName getCXXLiteralOperatorName(const IdentifierInfo *II)
Get the name of the literal operator function with II as the identifier.
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name.
const IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it.
static DeclarationName getUsingDirectiveName()
Returns the name for all C++ using-directives.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
NameKind getNameKind() const
Determine what kind of name this is.
bool isEmpty() const
Evaluates true when this declaration name is empty.
void setTypeSourceInfo(TypeSourceInfo *TI)
Definition: Decl.h:769
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:1989
Represents the type decltype(expr) (C++11).
Definition: Type.h:5874
A decomposition declaration.
Definition: DeclCXX.h:4184
Represents a C++17 deduced template specialization type.
Definition: Type.h:6604
Represents an extended address space qualifier where the input address space value is dependent.
Definition: Type.h:3920
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:7024
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3323
static DependentScopeDeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:531
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:3862
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:3960
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition: Type.h:4291
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:548
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
Definition: TemplateName.h:620
bool isIdentifier() const
Determine whether this template name refers to an identifier.
Definition: TemplateName.h:607
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:604
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:610
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: Type.h:7076
Represents a vector type where either the type or size is dependent.
Definition: Type.h:4086
Represents a single C99 designator.
Definition: Expr.h:5376
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition: Expr.h:5503
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition: Expr.h:5457
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition: Expr.h:5493
Represents a C99 designated initializer expression.
Definition: Expr.h:5333
static DesignatedInitExpr * Create(const ASTContext &C, llvm::ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition: Expr.cpp:4627
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1220
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1493
void notePriorDiagnosticFrom(const DiagnosticsEngine &Other)
Note that the prior diagnostic was emitted by some other DiagnosticsEngine, and we may be attaching a...
Definition: Diagnostic.h:919
DoStmt - This represents a 'do/while' stmt.
Definition: Stmt.h:2762
Symbolic representation of a dynamic allocation.
Definition: APValue.h:65
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:6943
Represents an empty-declaration.
Definition: Decl.h:4912
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3277
Represents an enum.
Definition: Decl.h:3847
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition: Decl.h:4106
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition: Decl.h:4044
void setIntegerType(QualType T)
Set the underlying integer type.
Definition: Decl.h:4016
EnumDecl * getMostRecentDecl()
Definition: Decl.h:3943
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition: Decl.cpp:4901
EnumDecl * getDefinition() const
Definition: Decl.h:3950
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition: Decl.h:4033
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition: Decl.h:3999
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:6098
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:3799
Store information needed for an explicit specifier.
Definition: DeclCXX.h:1912
ExplicitSpecKind getKind() const
Definition: DeclCXX.h:1920
const Expr * getExpr() const
Definition: DeclCXX.h:1921
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3474
llvm::PointerUnion< BlockDecl *, CompoundLiteralExpr * > CleanupObject
The type of objects that are kept in the cleanup.
Definition: ExprCXX.h:3480
static ExprWithCleanups * Create(const ASTContext &C, EmptyShell empty, unsigned numObjects)
Definition: ExprCXX.cpp:1446
This represents one expression.
Definition: Expr.h:110
void setType(QualType t)
Definition: Expr.h:143
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition: Expr.h:175
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:437
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:192
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
Definition: Expr.h:239
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:444
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition: Expr.h:221
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:277
QualType getType() const
Definition: Expr.h:142
ExprDependence getDependence() const
Definition: Expr.h:162
An expression trait intrinsic.
Definition: ExprCXX.h:2924
ExtVectorType - Extended vector type.
Definition: Type.h:4126
virtual void CompleteType(TagDecl *Tag)
Gives the external AST source an opportunity to complete an incomplete type.
Represents difference between two FPOptions values.
Definition: LangOptions.h:978
Represents a member of a struct/union/class.
Definition: Decl.h:3033
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition: Decl.cpp:4580
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition: Decl.h:3194
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition: Decl.cpp:4590
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition: Decl.cpp:4685
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool isValid() const
bool isInvalid() const
Implements support for file system lookup, file system caching, and directory search management.
Definition: FileManager.h:53
OptionalFileEntryRef getOptionalFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Get a FileEntryRef if it exists, without doing anything on error.
Definition: FileManager.h:245
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition: Expr.cpp:1074
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition: Stmt.h:2818
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
Definition: DeclFriend.h:54
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
Definition: DeclFriend.h:58
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition: DeclFriend.h:126
static DefaultedOrDeletedFunctionInfo * Create(ASTContext &Context, ArrayRef< DeclAccessPair > Lookups, StringLiteral *DeletedMessage=nullptr)
Definition: Decl.cpp:3103
Represents a function declaration or definition.
Definition: Decl.h:1935
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:3243
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition: Decl.cpp:4057
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:4052
void setIsPureVirtual(bool P=true)
Definition: Decl.cpp:3262
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition: Decl.cpp:3124
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition: Decl.h:2577
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2649
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition: Decl.cpp:4031
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition: Decl.cpp:4182
void setDefaultLoc(SourceLocation NewLoc)
Definition: Decl.h:2330
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition: Decl.cpp:4247
@ TK_MemberSpecialization
Definition: Decl.h:1947
@ TK_DependentNonTemplate
Definition: Decl.h:1956
@ TK_FunctionTemplateSpecialization
Definition: Decl.h:1951
@ TK_DependentFunctionTemplateSpecialization
Definition: Decl.h:1954
void setTrivial(bool IT)
Definition: Decl.h:2306
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition: Decl.cpp:4003
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition: Decl.cpp:4070
void setDependentTemplateSpecialization(ASTContext &Context, const UnresolvedSetImpl &Templates, const TemplateArgumentListInfo *TemplateArgs)
Specifies that this function declaration is actually a dependent function template specialization.
Definition: Decl.cpp:4236
void setVirtualAsWritten(bool V)
State that this function is marked as virtual explicitly.
Definition: Decl.h:2284
void setRangeEnd(SourceLocation E)
Definition: Decl.h:2153
FunctionDecl * getInstantiatedFromDecl() const
Definition: Decl.cpp:4076
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition: Decl.cpp:4276
void setDefaulted(bool D=true)
Definition: Decl.h:2314
void setBody(Stmt *B)
Definition: Decl.cpp:3255
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition: Decl.cpp:3133
void setExplicitlyDefaulted(bool ED=true)
State that this function is explicitly defaulted.
Definition: Decl.h:2322
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition: Decl.cpp:4024
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition: Decl.cpp:3163
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4681
Represents a prototype with parameter type info, e.g.
Definition: Type.h:5102
QualType desugar() const
Definition: Type.h:5646
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:5366
ArrayRef< QualType > exceptions() const
Definition: Type.h:5525
ArrayRef< QualType > param_types() const
Definition: Type.h:5511
Declaration of a template function.
Definition: DeclTemplate.h:959
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
FunctionTemplateDecl * getMostRecentDecl()
ExtInfo getExtInfo() const
Definition: Type.h:4655
QualType getReturnType() const
Definition: Type.h:4643
This represents a GCC inline-assembly statement extension.
Definition: Stmt.h:3296
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition: Expr.h:4716
Represents a C11 generic selection.
Definition: Expr.h:5966
static GenericSelectionExpr * Create(const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, ArrayRef< TypeSourceInfo * > AssocTypes, ArrayRef< Expr * > AssocExprs, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack, unsigned ResultIndex)
Create a non-result-dependent generic selection expression accepting an expression predicate.
Definition: Expr.cpp:4515
GotoStmt - This represents a direct goto.
Definition: Stmt.h:2899
One of these records is kept for each identifier that is lexed.
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
void setBuiltinID(unsigned ID)
StringRef getName() const
Return the actual identifier string.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
IfStmt - This represents an if/then/else.
Definition: Stmt.h:2175
static IfStmt * Create(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LPL, SourceLocation RPL, Stmt *Then, SourceLocation EL=SourceLocation(), Stmt *Else=nullptr)
Create an IfStmt.
Definition: Stmt.cpp:956
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition: Expr.h:1717
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3724
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition: Expr.cpp:2082
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5841
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4786
Represents a C array with an unspecified size.
Definition: Type.h:3764
Represents a field injected from an anonymous union/struct into the parent scope.
Definition: Decl.h:3321
IndirectGotoStmt - This represents an indirect goto.
Definition: Stmt.h:2938
Description of a constructor that was inherited from a base class.
Definition: DeclCXX.h:2524
CXXConstructorDecl * getConstructor() const
Definition: DeclCXX.h:2537
ConstructorUsingShadowDecl * getShadowDecl() const
Definition: DeclCXX.h:2536
Describes an C or C++ initializer list.
Definition: Expr.h:5088
void setSyntacticForm(InitListExpr *Init)
Definition: Expr.h:5258
void setArrayFiller(Expr *filler)
Definition: Expr.cpp:2436
void setInitializedFieldInUnion(FieldDecl *FD)
Definition: Expr.h:5213
void sawArrayRangeDesignator(bool ARD=true)
Definition: Expr.h:5268
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:6793
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition: Expr.cpp:973
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3483
Represents the declaration of a label.
Definition: Decl.h:503
void setStmt(LabelStmt *T)
Definition: Decl.h:528
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:2068
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:25
bool capturesVariable() const
Determine whether this capture handles a variable.
Definition: LambdaCapture.h:88
bool isPackExpansion() const
Determine whether this capture is a pack expansion, which captures a function parameter pack.
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis for a capture that is a pack expansion.
LambdaCaptureKind getCaptureKind() const
Determine the kind of capture.
Definition: ExprCXX.cpp:1245
ValueDecl * getCapturedVar() const
Retrieve the declaration of the local variable being captured.
bool isImplicit() const
Determine whether this was an implicit capture (not written between the square brackets introducing t...
SourceLocation getLocation() const
Retrieve the source location of the capture.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1954
static LambdaExpr * Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, bool ExplicitParams, bool ExplicitResultType, ArrayRef< Expr * > CaptureInits, SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack)
Construct a new lambda expression.
Definition: ExprCXX.cpp:1293
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
Definition: DeclCXX.h:3247
Represents a linkage specification.
Definition: DeclCXX.h:2952
void setRBraceLoc(SourceLocation L)
Definition: DeclCXX.h:2994
Represents the results of name lookup.
Definition: Lookup.h:46
iterator end() const
Definition: Lookup.h:359
iterator begin() const
Definition: Lookup.h:358
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation.
Definition: Type.h:5765
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4734
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3236
static MemberExpr * Create(const ASTContext &C, Expr *Base, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *MemberDecl, DeclAccessPair FoundDecl, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, QualType T, ExprValueKind VK, ExprObjectKind OK, NonOdrUseReason NOUR)
Definition: Expr.cpp:1762
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3519
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:620
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
Definition: DeclTemplate.h:660
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Definition: DeclTemplate.h:665
This represents a decl that may have a name.
Definition: Decl.h:253
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition: Decl.cpp:1176
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:319
Represents a C++ namespace alias.
Definition: DeclCXX.h:3138
Represent a C++ namespace.
Definition: Decl.h:551
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace that inhabits this namespace, if any.
Definition: Decl.h:634
void setRBraceLoc(SourceLocation L)
Definition: Decl.h:653
Class that aids in the construction of nested-name-specifiers along with source-location information ...
A C++ nested-name-specifier augmented with source location information.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
TypeLoc getTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
NestedNameSpecifierLoc getPrefix() const
Return the prefix of this nested-name-specifier.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, const IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
static NestedNameSpecifier * GlobalSpecifier(const ASTContext &Context)
Returns the nested name specifier representing the global scope.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
SpecifierKind
The kind of specifier that completes this nested name specifier.
@ NamespaceAlias
A namespace alias, stored as a NamespaceAliasDecl*.
@ TypeSpec
A type, stored as a Type*.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Identifier
An identifier, stored as an IdentifierInfo*.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace, stored as a NamespaceDecl*.
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
static NestedNameSpecifier * SuperSpecifier(const ASTContext &Context, CXXRecordDecl *RD)
Returns the nested name specifier representing the __super scope for the given CXXRecordDecl.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition: Stmt.h:1601
Represents Objective-C's @catch statement.
Definition: StmtObjC.h:77
Represents Objective-C's @finally statement.
Definition: StmtObjC.h:127
Represents Objective-C's @synchronized statement.
Definition: StmtObjC.h:303
Represents Objective-C's @throw statement.
Definition: StmtObjC.h:358
Represents Objective-C's @try ... @catch ... @finally statement.
Definition: StmtObjC.h:167
static ObjCAtTryStmt * Create(const ASTContext &Context, SourceLocation atTryLoc, Stmt *atTryStmt, Stmt **CatchStmts, unsigned NumCatchStmts, Stmt *atFinallyStmt)
Definition: StmtObjC.cpp:45
Represents Objective-C's @autoreleasepool Statement.
Definition: StmtObjC.h:394
An Objective-C "bridged" cast expression, which casts between Objective-C pointers and C pointers,...
Definition: ExprObjC.h:1632
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2328
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this category.
Definition: DeclObjC.cpp:2165
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition: DeclObjC.h:2390
void setImplementation(ObjCCategoryImplDecl *ImplD)
Definition: DeclObjC.cpp:2161
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2399
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition: DeclObjC.h:2544
Represents Objective-C's collection statement.
Definition: StmtObjC.h:23
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2596
const ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.h:2734
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition: DeclObjC.h:1484
ObjCCategoryDecl * FindCategoryDeclaration(const IdentifierInfo *CategoryId) const
FindCategoryDeclaration - Finds category declaration in the list of categories for this class and ret...
Definition: DeclObjC.cpp:1746
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:1391
void setImplementation(ObjCImplementationDecl *ImplD)
Definition: DeclObjC.cpp:1640
known_categories_range known_categories() const
Definition: DeclObjC.h:1686
void setSuperClass(TypeSourceInfo *superClass)
Definition: DeclObjC.h:1587
protocol_iterator protocol_end() const
Definition: DeclObjC.h:1373
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
Definition: DeclObjC.cpp:370
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this class.
Definition: DeclObjC.cpp:341
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:1355
ObjCImplementationDecl * getImplementation() const
Definition: DeclObjC.cpp:1627
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:1362
void startDefinition()
Starts the definition of this Objective-C class, taking it from a forward declaration (@class) to a d...
Definition: DeclObjC.cpp:614
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition: DeclObjC.h:1914
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:350
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition: DeclObjC.h:1541
TypeSourceInfo * getSuperClassTInfo() const
Definition: DeclObjC.h:1572
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:7524
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1951
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
void setMethodParams(ASTContext &C, ArrayRef< ParmVarDecl * > Params, ArrayRef< SourceLocation > SelLocs={})
Sets the method's parameters and selector source locations.
Definition: DeclObjC.cpp:942
void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID)
createImplicitParams - Used to lazily create the self and cmd implicit parameters.
Definition: DeclObjC.cpp:1188
ParmVarDecl *const * param_iterator
Definition: DeclObjC.h:350
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.cpp:1209
Represents a pointer to an Objective C object.
Definition: Type.h:7580
Represents a class type in Objective C.
Definition: Type.h:7326
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:730
void setSetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:895
void setPropertyAttributes(ObjCPropertyAttribute::Kind PRVal)
Definition: DeclObjC.h:818
void setPropertyAttributesAsWritten(ObjCPropertyAttribute::Kind PRVal)
Definition: DeclObjC.h:830
void setPropertyIvarDecl(ObjCIvarDecl *Ivar)
Definition: DeclObjC.h:919
void setSetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:904
void setGetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:887
void setGetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:901
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition: DeclObjC.h:2804
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:2878
SourceLocation getPropertyIvarDeclLoc() const
Definition: DeclObjC.h:2881
Kind getPropertyImplementation() const
Definition: DeclObjC.h:2874
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2083
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition: DeclObjC.h:2208
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Definition: DeclObjC.h:2249
void startDefinition()
Starts the definition of this Objective-C protocol.
Definition: DeclObjC.cpp:2021
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2157
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:2164
protocol_iterator protocol_end() const
Definition: DeclObjC.h:2171
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:2185
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:578
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition: DeclObjC.h:659
SourceLocation getRAngleLoc() const
Definition: DeclObjC.h:710
static ObjCTypeParamList * create(ASTContext &ctx, SourceLocation lAngleLoc, ArrayRef< ObjCTypeParamDecl * > typeParams, SourceLocation rAngleLoc)
Create a new Objective-C type parameter list.
Definition: DeclObjC.cpp:1518
SourceLocation getLAngleLoc() const
Definition: DeclObjC.h:709
Represents a type parameter type in Objective C.
Definition: Type.h:7252
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition: Expr.h:2519
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
Definition: Expr.cpp:1665
Helper class for OffsetOfExpr.
Definition: Expr.h:2413
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition: Expr.h:2471
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition: Expr.h:2477
IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition: Expr.cpp:1700
@ Array
An index into an array.
Definition: Expr.h:2418
@ Identifier
A field in a dependent type, known only by its name.
Definition: Expr.h:2422
@ Field
A field.
Definition: Expr.h:2420
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition: Expr.h:2425
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:2499
Kind getKind() const
Determine what kind of offsetof node this is.
Definition: Expr.h:2467
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:2500
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition: Expr.h:2487
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1173
A structure for storing the information associated with an overloaded template name.
Definition: TemplateName.h:116
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:4180
Represents a pack expansion of types.
Definition: Type.h:7141
ParenExpr - This represents a parenthesized expression, e.g.
Definition: Expr.h:2170
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition: Expr.cpp:4767
Sugar for parentheses used when specifying types.
Definition: Type.h:3172
Represents a parameter to a function.
Definition: Decl.h:1725
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion:
Definition: Decl.h:1806
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition: Decl.h:1793
void setDefaultArg(Expr *defarg)
Definition: Decl.cpp:2987
SourceLocation getExplicitObjectParamThisLoc() const
Definition: Decl.h:1821
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition: Decl.h:1866
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition: Decl.h:1854
void setUninstantiatedDefaultArg(Expr *arg)
Definition: Decl.cpp:3012
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1758
bool hasUninstantiatedDefaultArg() const
Definition: Decl.h:1858
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition: Decl.h:1753
bool hasInheritedDefaultArg() const
Definition: Decl.h:1870
void setKNRPromoted(bool promoted)
Definition: Decl.h:1809
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition: Decl.h:1817
Expr * getDefaultArg()
Definition: Decl.cpp:2975
Expr * getUninstantiatedDefaultArg()
Definition: Decl.cpp:3017
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition: Decl.cpp:3023
void setHasInheritedDefaultArg(bool I=true)
Definition: Decl.h:1874
PipeType - OpenCL20.
Definition: Type.h:7780
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:3198
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1991
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
Definition: Expr.cpp:638
Stores the type being destroyed by a pseudo-destructor expression.
Definition: ExprCXX.h:2566
A (possibly-)qualified type.
Definition: Type.h:929
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:996
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:7931
QualType getCanonicalType() const
Definition: Type.h:7983
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:7963
Represents a template name as written in source code.
Definition: TemplateName.h:491
TemplateName getUnderlyingTemplate() const
Return the underlying template name.
Definition: TemplateName.h:526
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:519
bool hasTemplateKeyword() const
Whether the template name was prefixed by the "template" keyword.
Definition: TemplateName.h:523
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3501
Represents a struct/union/class.
Definition: Decl.h:4148
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition: Decl.cpp:5063
void setAnonymousStructOrUnion(bool Anon)
Definition: Decl.h:4204
RecordDecl * getMostRecentDecl()
Definition: Decl.h:4174
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition: Decl.cpp:5104
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:4339
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:6072
RecordDecl * getDecl() const
Definition: Type.h:6082
Provides common interface for the Decls that can be redeclared.
Definition: Redeclarable.h:84
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Definition: Redeclarable.h:203
decl_type * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
Definition: Redeclarable.h:225
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
Definition: Decl.h:4981
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3439
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition: Stmt.h:3056
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition: Stmt.cpp:1202
Selector getSelector(unsigned NumArgs, const IdentifierInfo **IIV)
Can create any sort of selector.
Smart pointer class that efficiently represents Objective-C method names.
const IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
bool isNull() const
Determine whether this is the empty selector.
unsigned getNumArgs() const
static std::enable_if_t< std::is_base_of_v< Attr, AttrInfo >, SourceLocation > getAttrLoc(const AttrInfo &AL)
A helper function to provide Attribute Location for the Attr types AND the ParsedAttr.
Definition: Sema.h:4405
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition: Expr.h:4514
Represents an expression that computes the length of a parameter pack.
Definition: ExprCXX.h:4258
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, std::optional< unsigned > Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Definition: ExprCXX.cpp:1693
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition: Expr.h:4810
Encodes a location in the source.
This class handles loading and caching of source files into memory.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
bool isWrittenInBuiltinFile(SourceLocation Loc) const
Returns whether Loc is located in a <built-in> file.
FileID createFileID(FileEntryRef SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
SourceLocation getComposedLoc(FileID FID, unsigned Offset) const
Form a SourceLocation from a FileID and Offset pair.
FileManager & getFileManager() const
FileID getMainFileID() const
Returns the FileID of the main source file.
unsigned getFileIDSize(FileID FID) const
The size of the SLocEntry that FID represents.
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file.
SourceLocation createExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned Length, bool ExpansionIsTokenRange=true, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Creates an expansion SLocEntry for a macro use.
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
SourceLocation createMacroArgExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLoc, unsigned Length)
Creates an expansion SLocEntry for the substitution of an argument into a function-like macro's body.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
One instance of this struct is kept for every file loaded or used.
Each ExpansionInfo encodes the expansion location - where the token was ultimately expanded,...
SourceLocation getExpansionLocStart() const
SourceLocation getSpellingLoc() const
SourceLocation getExpansionLocEnd() const
const ContentCache & getContentCache() const
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
SourceLocation getIncludeLoc() const
This is a discriminated union of FileInfo and ExpansionInfo.
const FileInfo & getFile() const
const ExpansionInfo & getExpansion() const
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:4076
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:4466
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:185
Stmt - This represents one statement.
Definition: Stmt.h:84
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:348
child_iterator child_begin()
Definition: Stmt.h:1489
StmtClass getStmtClass() const
Definition: Stmt.h:1390
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:324
child_iterator child_end()
Definition: Stmt.h:1490
const char * getStmtClassName() const
Definition: Stmt.cpp:77
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:336
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1778
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, const SourceLocation *Loc, unsigned NumConcatenated)
This is the "fully general" constructor that allows representation of strings formed from multiple co...
Definition: Expr.cpp:1187
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4490
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:149
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
TemplateArgument getArgumentPack() const
Retrieve the template template argument pack with which this parameter was substituted.
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: TemplateName.h:164
A structure for storing the information associated with a substituted template template parameter.
Definition: TemplateName.h:408
std::optional< unsigned > getPackIndex() const
Definition: TemplateName.h:432
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: TemplateName.h:430
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: TemplateName.h:426
Represents the result of substituting a set of types for a template type parameter pack.
Definition: Type.h:6464
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:6383
void setNextSwitchCase(SwitchCase *SC)
Definition: Stmt.h:1813
SwitchStmt - This represents a 'switch' stmt.
Definition: Stmt.h:2425
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a switch statement.
Definition: Stmt.cpp:1079
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3564
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3687
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3667
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3792
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:4760
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition: Decl.cpp:4751
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:4806
void setBraceRange(SourceRange R)
Definition: Decl.h:3644
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition: Decl.h:3670
A convenient class for passing around template argument information.
Definition: TemplateBase.h:632
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:648
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:667
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:659
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:647
A template argument list.
Definition: DeclTemplate.h:250
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Definition: DeclTemplate.h:286
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:524
TemplateArgumentLocInfo getLocInfo() const
Definition: TemplateBase.h:576
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:574
Represents a template argument.
Definition: TemplateBase.h:61
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
Definition: TemplateBase.h:444
QualType getStructuralValueType() const
Get the type of a StructuralValue.
Definition: TemplateBase.h:399
QualType getParamTypeForDecl() const
Definition: TemplateBase.h:331
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:408
std::optional< unsigned > getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce,...
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:319
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
Definition: TemplateBase.h:337
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:343
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:438
QualType getIntegralType() const
Retrieve the type of the integral value.
Definition: TemplateBase.h:377
bool getIsDefaulted() const
If returns 'true', this TemplateArgument corresponds to a default template parameter.
Definition: TemplateBase.h:393
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:326
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:432
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
Definition: TemplateBase.h:74
@ Template
The template argument is a template name that was provided for a template template parameter.
Definition: TemplateBase.h:93
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
Definition: TemplateBase.h:89
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:107
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:97
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:78
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:67
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:82
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Definition: TemplateBase.h:103
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:295
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
Definition: TemplateBase.h:350
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
Definition: TemplateBase.h:396
Represents a C++ template name within the type system.
Definition: TemplateName.h:220
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
OverloadedTemplateStorage * getAsOverloadedTemplate() const
Retrieve the underlying, overloaded function template declarations that this template name refers to,...
AssumedTemplateStorage * getAsAssumedTemplateName() const
Retrieve information on a name that has been assumed to be a template-name in order to permit a call ...
NameKind getKind() const
@ UsingTemplate
A template name that refers to a template declaration found through a specific using shadow declarati...
Definition: TemplateName.h:265
@ OverloadedTemplate
A set of overloaded template declarations.
Definition: TemplateName.h:240
@ Template
A single template declaration.
Definition: TemplateName.h:237
@ DependentTemplate
A dependent template name that has not been resolved to a template (or set of templates).
Definition: TemplateName.h:252
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:256
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
Definition: TemplateName.h:261
@ DeducedTemplate
A template name that refers to another TemplateName with deduced default arguments.
Definition: TemplateName.h:269
@ QualifiedTemplate
A qualified template name, where the qualification is kept to describe the source code as written.
Definition: TemplateName.h:248
@ AssumedTemplate
An unqualified-id that has been assumed to name a function template that will be found by ADL.
Definition: TemplateName.h:244
UsingShadowDecl * getAsUsingShadowDecl() const
Retrieve the using shadow declaration through which the underlying template declaration is introduced...
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:147
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
Expr * getRequiresClause()
The constraint-expression of the associated requires-clause.
Definition: DeclTemplate.h:183
SourceLocation getRAngleLoc() const
Definition: DeclTemplate.h:207
SourceLocation getLAngleLoc() const
Definition: DeclTemplate.h:206
SourceLocation getTemplateLoc() const
Definition: DeclTemplate.h:205
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:6661
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Declaration of a template type parameter.
void setTypeConstraint(ConceptReference *CR, Expr *ImmediatelyDeclaredConstraint)
The top declaration context.
Definition: Decl.h:84
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3535
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition: Decl.h:3553
Declaration of an alias template.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
Definition: ASTConcept.h:227
[BoundsSafety] Represents information of declarations referenced by the arguments of the counted_by a...
Definition: Type.h:3226
void setTypeForDecl(const Type *TD)
Definition: Decl.h:3396
const Type * getTypeForDecl() const
Definition: Decl.h:3395
Symbolic representation of typeid(T) for some type T.
Definition: APValue.h:44
const Type * getType() const
Definition: APValue.h:51
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:192
Represents a typeof (or typeof) expression (a C23 feature and GCC extension) or a typeof_unqual expre...
Definition: Type.h:5797
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Definition: Type.h:5847
The type-property cache.
Definition: Type.cpp:4501
A container of type source information.
Definition: Type.h:7902
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:256
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:7913
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2768
static TypeTraitExpr * Create(const ASTContext &C, QualType T, SourceLocation Loc, TypeTrait Kind, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc, bool Value)
Create a new type trait expression.
Definition: ExprCXX.cpp:1876
An operation on a type.
Definition: TypeVisitor.h:64
ExpectedType Visit(const Type *T)
Performs the operation associated with this visitor object.
Definition: TypeVisitor.h:68
The base class of the type hierarchy.
Definition: Type.h:1828
const Type * getPointeeOrArrayElementType() const
If this is a pointer type, return the pointee type.
Definition: Type.h:8688
bool isArrayType() const
Definition: Type.h:8258
bool isPointerType() const
Definition: Type.h:8186
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:738
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2706
QualType getCanonicalTypeInternal() const
Definition: Type.h:2989
const char * getTypeClassName() const
Definition: Type.cpp:3318
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition: Type.h:8681
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition: Type.cpp:2396
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition: Type.h:2367
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8731
bool isRecordType() const
Definition: Type.h:8286
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition: Type.cpp:1920
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3514
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3413
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition: Expr.h:2622
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2232
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition: Expr.cpp:4931
A unary type transform, which is a type constructed from another.
Definition: Type.h:5989
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:3203
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, UnresolvedSetIterator Begin, UnresolvedSetIterator End, bool KnownDependent, bool KnownInstantiationDependent)
Definition: ExprCXX.cpp:419
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition: ExprCXX.h:3943
static UnresolvedMemberExpr * Create(const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
Definition: ExprCXX.cpp:1635
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:92
A set of unresolved declarations.
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition: Type.h:5667
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3977
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3880
Represents a C++ using-declaration.
Definition: DeclCXX.h:3530
Represents C++ using-directive.
Definition: DeclCXX.h:3033
Represents a C++ using-enum-declaration.
Definition: DeclCXX.h:3731
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition: DeclCXX.h:3812
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3338
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:4750
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:671
void setType(QualType newType)
Definition: Decl.h:683
QualType getType() const
Definition: Decl.h:682
Represents a variable declaration or definition.
Definition: Decl.h:882
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition: Decl.cpp:2911
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition: Decl.cpp:2355
EvaluatedStmt * getEvaluatedStmt() const
Definition: Decl.cpp:2543
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition: Decl.cpp:2529
void setInlineSpecified()
Definition: Decl.h:1502
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition: Decl.h:1124
const Expr * getInit() const
Definition: Decl.h:1319
void setConstexpr(bool IC)
Definition: Decl.h:1516
void setInit(Expr *I)
Definition: Decl.cpp:2449
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition: Decl.cpp:2791
void setImplicitlyInline()
Definition: Decl.h:1507
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Definition: Decl.h:1309
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition: Decl.cpp:2874
Declaration of a variable template.
VarDecl * getTemplatedDecl() const
Get the underlying variable declarations of the template.
void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
VarTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
VarTemplateDecl * getMostRecentDecl()
void setInstantiatedFromMember(VarTemplatePartialSpecializationDecl *PartialSpec)
Represents a variable template specialization, which refers to a variable template with a given set o...
void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
void setSpecializationKind(TemplateSpecializationKind TSK)
void setPointOfInstantiation(SourceLocation Loc)
VarTemplateSpecializationDecl * getMostRecentDecl()
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:3808
Represents a GCC generic vector type.
Definition: Type.h:4034
WhileStmt - This represents a 'while' stmt.
Definition: Stmt.h:2621
static WhileStmt * Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body, SourceLocation WL, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a while statement.
Definition: Stmt.cpp:1141
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition: Address.h:328
StructuralEquivalenceKind
Whether to perform a normal or minimal equivalence check.
CanThrowResult
Possible results from evaluation of a noexcept expression.
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition: Specifiers.h:149
@ Property
The type of a property.
@ Result
The result type of a method or function.
@ BTK__type_pack_element
This names the __type_pack_element BuiltinTemplateDecl.
Definition: Builtins.h:310
@ BTK__builtin_common_type
This names the __builtin_common_type BuiltinTemplateDecl.
Definition: Builtins.h:313
@ BTK__make_integer_seq
This names the __make_integer_seq BuiltinTemplateDecl.
Definition: Builtins.h:307
CastKind
CastKind - The kind of operation required for a conversion.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:132
const FunctionProtoType * T
llvm::SmallVector< Decl *, 2 > getCanonicalForwardRedeclChain(Decl *D)
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1274
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:188
static void updateFlags(const Decl *From, Decl *To)
#define false
Definition: stdbool.h:26
Used as return type of getFriendCountAndPosition.
unsigned int IndexOfDecl
Index of the specific FriendDecl.
unsigned int TotalCount
Number of similar looking friends.
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:676
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
Information about how a lambda is numbered within its context.
Definition: DeclCXX.h:1813
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
void setCXXLiteralOperatorNameLoc(SourceLocation Loc)
setCXXLiteralOperatorNameLoc - Sets the location of the literal operator name (not the operator keywo...
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
void setCXXOperatorNameRange(SourceRange R)
setCXXOperatorNameRange - Sets the range of the operator name (without the operator keyword).
SourceRange getCXXOperatorNameRange() const
getCXXOperatorNameRange - Gets the range of the operator name (without the operator keyword).
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
SourceLocation getCXXLiteralOperatorNameLoc() const
getCXXLiteralOperatorNameLoc - Returns the location of the literal operator name (not the operator ke...
Structure used to store a statement, the constant value to which it was evaluated (if any),...
Definition: Decl.h:847
bool HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition: Decl.h:865
bool HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition: Decl.h:858
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition: Type.h:5171
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:5175
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:5161
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:5164
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition: Type.h:5167
Extra information about a function prototype.
Definition: Type.h:5187
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:5194
FunctionType::ExtInfo ExtInfo
Definition: Type.h:5188
bool IsEquivalent(Decl *D1, Decl *D2)
Determine whether the two declarations are structurally equivalent.
Location information for a TemplateArgument.
Definition: TemplateBase.h:472
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:517
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:507
TypeSourceInfo * getAsTypeSourceInfo() const
Definition: TemplateBase.h:501
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:513