clang 19.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/APSInt.h"
57#include "llvm/ADT/ArrayRef.h"
58#include "llvm/ADT/DenseMap.h"
59#include "llvm/ADT/STLExtras.h"
60#include "llvm/ADT/ScopeExit.h"
61#include "llvm/ADT/SmallVector.h"
62#include "llvm/Support/Casting.h"
63#include "llvm/Support/ErrorHandling.h"
64#include "llvm/Support/MemoryBuffer.h"
65#include <algorithm>
66#include <cassert>
67#include <cstddef>
68#include <memory>
69#include <optional>
70#include <type_traits>
71#include <utility>
72
73namespace clang {
74
75 using llvm::make_error;
76 using llvm::Error;
77 using llvm::Expected;
85
86 std::string ASTImportError::toString() const {
87 // FIXME: Improve error texts.
88 switch (Error) {
89 case NameConflict:
90 return "NameConflict";
92 return "UnsupportedConstruct";
93 case Unknown:
94 return "Unknown error";
95 }
96 llvm_unreachable("Invalid error code.");
97 return "Invalid error code.";
98 }
99
100 void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
101
102 std::error_code ASTImportError::convertToErrorCode() const {
103 llvm_unreachable("Function not implemented.");
104 }
105
107
108 template <class T>
112 for (auto *R : D->getFirstDecl()->redecls()) {
113 if (R != D->getFirstDecl())
114 Redecls.push_back(R);
115 }
116 Redecls.push_back(D->getFirstDecl());
117 std::reverse(Redecls.begin(), Redecls.end());
118 return Redecls;
119 }
120
122 if (auto *FD = dyn_cast<FunctionDecl>(D))
123 return getCanonicalForwardRedeclChain<FunctionDecl>(FD);
124 if (auto *VD = dyn_cast<VarDecl>(D))
125 return getCanonicalForwardRedeclChain<VarDecl>(VD);
126 if (auto *TD = dyn_cast<TagDecl>(D))
127 return getCanonicalForwardRedeclChain<TagDecl>(TD);
128 llvm_unreachable("Bad declaration kind");
129 }
130
131 void updateFlags(const Decl *From, Decl *To) {
132 // Check if some flags or attrs are new in 'From' and copy into 'To'.
133 // FIXME: Other flags or attrs?
134 if (From->isUsed(false) && !To->isUsed(false))
135 To->setIsUsed();
136 }
137
138 /// How to handle import errors that occur when import of a child declaration
139 /// of a DeclContext fails.
141 /// This context is imported (in the 'from' domain).
142 /// It is nullptr if a non-DeclContext is imported.
143 const DeclContext *const FromDC;
144 /// Ignore import errors of the children.
145 /// If true, the context can be imported successfully if a child
146 /// of it failed to import. Otherwise the import errors of the child nodes
147 /// are accumulated (joined) into the import error object of the parent.
148 /// (Import of a parent can fail in other ways.)
149 bool const IgnoreChildErrors;
150
151 public:
153 : FromDC(FromDC), IgnoreChildErrors(!isa<TagDecl>(FromDC)) {}
155 : FromDC(dyn_cast<DeclContext>(FromD)),
156 IgnoreChildErrors(!isa<TagDecl>(FromD)) {}
157
158 /// Process the import result of a child (of the current declaration).
159 /// \param ResultErr The import error that can be used as result of
160 /// importing the parent. This may be changed by the function.
161 /// \param ChildErr Result of importing a child. Can be success or error.
162 void handleChildImportResult(Error &ResultErr, Error &&ChildErr) {
163 if (ChildErr && !IgnoreChildErrors)
164 ResultErr = joinErrors(std::move(ResultErr), std::move(ChildErr));
165 else
166 consumeError(std::move(ChildErr));
167 }
168
169 /// Determine if import failure of a child does not cause import failure of
170 /// its parent.
171 bool ignoreChildErrorOnParent(Decl *FromChildD) const {
172 if (!IgnoreChildErrors || !FromDC)
173 return false;
174 return FromDC->containsDecl(FromChildD);
175 }
176 };
177
178 class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>,
179 public DeclVisitor<ASTNodeImporter, ExpectedDecl>,
180 public StmtVisitor<ASTNodeImporter, ExpectedStmt> {
181 ASTImporter &Importer;
182
183 // Use this instead of Importer.importInto .
184 template <typename ImportT>
185 [[nodiscard]] Error importInto(ImportT &To, const ImportT &From) {
186 return Importer.importInto(To, From);
187 }
188
189 // Use this to import pointers of specific type.
190 template <typename ImportT>
191 [[nodiscard]] Error importInto(ImportT *&To, ImportT *From) {
192 auto ToOrErr = Importer.Import(From);
193 if (ToOrErr)
194 To = cast_or_null<ImportT>(*ToOrErr);
195 return ToOrErr.takeError();
196 }
197
198 // Call the import function of ASTImporter for a baseclass of type `T` and
199 // cast the return value to `T`.
200 template <typename T>
201 auto import(T *From)
202 -> std::conditional_t<std::is_base_of_v<Type, T>, Expected<const T *>,
204 auto ToOrErr = Importer.Import(From);
205 if (!ToOrErr)
206 return ToOrErr.takeError();
207 return cast_or_null<T>(*ToOrErr);
208 }
209
210 template <typename T>
211 auto import(const T *From) {
212 return import(const_cast<T *>(From));
213 }
214
215 // Call the import function of ASTImporter for type `T`.
216 template <typename T>
217 Expected<T> import(const T &From) {
218 return Importer.Import(From);
219 }
220
221 // Import an std::optional<T> by importing the contained T, if any.
222 template <typename T>
223 Expected<std::optional<T>> import(std::optional<T> From) {
224 if (!From)
225 return std::nullopt;
226 return import(*From);
227 }
228
229 ExplicitSpecifier importExplicitSpecifier(Error &Err,
230 ExplicitSpecifier ESpec);
231
232 // Wrapper for an overload set.
233 template <typename ToDeclT> struct CallOverloadedCreateFun {
234 template <typename... Args> decltype(auto) operator()(Args &&... args) {
235 return ToDeclT::Create(std::forward<Args>(args)...);
236 }
237 };
238
239 // Always use these functions to create a Decl during import. There are
240 // certain tasks which must be done after the Decl was created, e.g. we
241 // must immediately register that as an imported Decl. The parameter `ToD`
242 // will be set to the newly created Decl or if had been imported before
243 // then to the already imported Decl. Returns a bool value set to true if
244 // the `FromD` had been imported before.
245 template <typename ToDeclT, typename FromDeclT, typename... Args>
246 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
247 Args &&...args) {
248 // There may be several overloads of ToDeclT::Create. We must make sure
249 // to call the one which would be chosen by the arguments, thus we use a
250 // wrapper for the overload set.
251 CallOverloadedCreateFun<ToDeclT> OC;
252 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
253 std::forward<Args>(args)...);
254 }
255 // Use this overload if a special Type is needed to be created. E.g if we
256 // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl`
257 // then:
258 // TypedefNameDecl *ToTypedef;
259 // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...);
260 template <typename NewDeclT, typename ToDeclT, typename FromDeclT,
261 typename... Args>
262 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
263 Args &&...args) {
264 CallOverloadedCreateFun<NewDeclT> OC;
265 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
266 std::forward<Args>(args)...);
267 }
268 // Use this version if a special create function must be
269 // used, e.g. CXXRecordDecl::CreateLambda .
270 template <typename ToDeclT, typename CreateFunT, typename FromDeclT,
271 typename... Args>
272 [[nodiscard]] bool
273 GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun,
274 FromDeclT *FromD, Args &&...args) {
275 if (Importer.getImportDeclErrorIfAny(FromD)) {
276 ToD = nullptr;
277 return true; // Already imported but with error.
278 }
279 ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD));
280 if (ToD)
281 return true; // Already imported.
282 ToD = CreateFun(std::forward<Args>(args)...);
283 // Keep track of imported Decls.
284 Importer.RegisterImportedDecl(FromD, ToD);
285 Importer.SharedState->markAsNewDecl(ToD);
286 InitializeImportedDecl(FromD, ToD);
287 return false; // A new Decl is created.
288 }
289
290 void InitializeImportedDecl(Decl *FromD, Decl *ToD) {
291 ToD->IdentifierNamespace = FromD->IdentifierNamespace;
292 if (FromD->isUsed())
293 ToD->setIsUsed();
294 if (FromD->isImplicit())
295 ToD->setImplicit();
296 }
297
298 // Check if we have found an existing definition. Returns with that
299 // definition if yes, otherwise returns null.
300 Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) {
301 const FunctionDecl *Definition = nullptr;
303 FoundFunction->hasBody(Definition))
304 return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition));
305 return nullptr;
306 }
307
308 void addDeclToContexts(Decl *FromD, Decl *ToD) {
309 if (Importer.isMinimalImport()) {
310 // In minimal import case the decl must be added even if it is not
311 // contained in original context, for LLDB compatibility.
312 // FIXME: Check if a better solution is possible.
313 if (!FromD->getDescribedTemplate() &&
314 FromD->getFriendObjectKind() == Decl::FOK_None)
316 return;
317 }
318
319 DeclContext *FromDC = FromD->getDeclContext();
320 DeclContext *FromLexicalDC = FromD->getLexicalDeclContext();
321 DeclContext *ToDC = ToD->getDeclContext();
322 DeclContext *ToLexicalDC = ToD->getLexicalDeclContext();
323
324 bool Visible = false;
325 if (FromDC->containsDeclAndLoad(FromD)) {
326 ToDC->addDeclInternal(ToD);
327 Visible = true;
328 }
329 if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) {
330 ToLexicalDC->addDeclInternal(ToD);
331 Visible = true;
332 }
333
334 // If the Decl was added to any context, it was made already visible.
335 // Otherwise it is still possible that it should be visible.
336 if (!Visible) {
337 if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) {
338 auto *ToNamed = cast<NamedDecl>(ToD);
339 DeclContextLookupResult FromLookup =
340 FromDC->lookup(FromNamed->getDeclName());
341 if (llvm::is_contained(FromLookup, FromNamed))
342 ToDC->makeDeclVisibleInContext(ToNamed);
343 }
344 }
345 }
346
347 void updateLookupTableForTemplateParameters(TemplateParameterList &Params,
348 DeclContext *OldDC) {
349 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
350 if (!LT)
351 return;
352
353 for (NamedDecl *TP : Params)
354 LT->update(TP, OldDC);
355 }
356
357 void updateLookupTableForTemplateParameters(TemplateParameterList &Params) {
358 updateLookupTableForTemplateParameters(
359 Params, Importer.getToContext().getTranslationUnitDecl());
360 }
361
362 public:
363 explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {}
364
368
369 // Importing types
370 ExpectedType VisitType(const Type *T);
371#define TYPE(Class, Base) \
372 ExpectedType Visit##Class##Type(const Class##Type *T);
373#include "clang/AST/TypeNodes.inc"
374
375 // Importing declarations
376 Error ImportDeclParts(NamedDecl *D, DeclarationName &Name, NamedDecl *&ToD,
377 SourceLocation &Loc);
378 Error ImportDeclParts(
379 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
380 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc);
381 Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
384 Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
385 Error ImportDeclContext(
386 Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
387 Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To);
388
389 Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To);
391 Expected<APValue> ImportAPValue(const APValue &FromValue);
392
394
395 /// What we should import from the definition.
397 /// Import the default subset of the definition, which might be
398 /// nothing (if minimal import is set) or might be everything (if minimal
399 /// import is not set).
401 /// Import everything.
403 /// Import only the bare bones needed to establish a valid
404 /// DeclContext.
406 };
407
409 return IDK == IDK_Everything ||
410 (IDK == IDK_Default && !Importer.isMinimalImport());
411 }
412
413 Error ImportInitializer(VarDecl *From, VarDecl *To);
414 Error ImportDefinition(
415 RecordDecl *From, RecordDecl *To,
417 Error ImportDefinition(
418 EnumDecl *From, EnumDecl *To,
420 Error ImportDefinition(
423 Error ImportDefinition(
430
431 template <typename InContainerTy>
433 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo);
434
435 template<typename InContainerTy>
437 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
438 const InContainerTy &Container, TemplateArgumentListInfo &Result);
439
442 std::tuple<FunctionTemplateDecl *, TemplateArgsTy>;
445 FunctionDecl *FromFD);
447 DeclaratorDecl *ToD);
448
450
452
453 Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam,
454 ParmVarDecl *ToParam);
455
458
459 template <typename T>
460 bool hasSameVisibilityContextAndLinkage(T *Found, T *From);
461
462 bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
463 bool IgnoreTemplateParmDepth = false);
510
513
528
529 // Importing statements
549 // FIXME: MSAsmStmt
550 // FIXME: SEHExceptStmt
551 // FIXME: SEHFinallyStmt
552 // FIXME: SEHTryStmt
553 // FIXME: SEHLeaveStmt
554 // FIXME: CapturedStmt
558 // FIXME: MSDependentExistsStmt
566
567 // Importing expressions
644
645 // Helper for chaining together multiple imports. If an error is detected,
646 // subsequent imports will return default constructed nodes, so that failure
647 // can be detected with a single conditional branch after a sequence of
648 // imports.
649 template <typename T> T importChecked(Error &Err, const T &From) {
650 // Don't attempt to import nodes if we hit an error earlier.
651 if (Err)
652 return T{};
653 Expected<T> MaybeVal = import(From);
654 if (!MaybeVal) {
655 Err = MaybeVal.takeError();
656 return T{};
657 }
658 return *MaybeVal;
659 }
660
661 template<typename IIter, typename OIter>
662 Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
663 using ItemT = std::remove_reference_t<decltype(*Obegin)>;
664 for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
665 Expected<ItemT> ToOrErr = import(*Ibegin);
666 if (!ToOrErr)
667 return ToOrErr.takeError();
668 *Obegin = *ToOrErr;
669 }
670 return Error::success();
671 }
672
673 // Import every item from a container structure into an output container.
674 // If error occurs, stops at first error and returns the error.
675 // The output container should have space for all needed elements (it is not
676 // expanded, new items are put into from the beginning).
677 template<typename InContainerTy, typename OutContainerTy>
679 const InContainerTy &InContainer, OutContainerTy &OutContainer) {
680 return ImportArrayChecked(
681 InContainer.begin(), InContainer.end(), OutContainer.begin());
682 }
683
684 template<typename InContainerTy, typename OIter>
685 Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
686 return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
687 }
688
690 CXXMethodDecl *FromMethod);
691
693 FunctionDecl *FromFD);
694
695 // Returns true if the given function has a placeholder return type and
696 // that type is declared inside the body of the function.
697 // E.g. auto f() { struct X{}; return X(); }
699 };
700
701template <typename InContainerTy>
703 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
704 const InContainerTy &Container, TemplateArgumentListInfo &Result) {
705 auto ToLAngleLocOrErr = import(FromLAngleLoc);
706 if (!ToLAngleLocOrErr)
707 return ToLAngleLocOrErr.takeError();
708 auto ToRAngleLocOrErr = import(FromRAngleLoc);
709 if (!ToRAngleLocOrErr)
710 return ToRAngleLocOrErr.takeError();
711
712 TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr);
713 if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo))
714 return Err;
715 Result = ToTAInfo;
716 return Error::success();
717}
718
719template <>
720Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>(
723 From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result);
724}
725
726template <>
729 const ASTTemplateArgumentListInfo &From,
731 return ImportTemplateArgumentListInfo(
732 From.LAngleLoc, From.RAngleLoc, From.arguments(), Result);
733}
734
737 FunctionDecl *FromFD) {
738 assert(FromFD->getTemplatedKind() ==
740
742
743 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
744 if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate()))
745 return std::move(Err);
746
747 // Import template arguments.
748 if (Error Err = ImportTemplateArguments(FTSInfo->TemplateArguments->asArray(),
749 std::get<1>(Result)))
750 return std::move(Err);
751
752 return Result;
753}
754
755template <>
757ASTNodeImporter::import(TemplateParameterList *From) {
759 if (Error Err = ImportContainerChecked(*From, To))
760 return std::move(Err);
761
762 ExpectedExpr ToRequiresClause = import(From->getRequiresClause());
763 if (!ToRequiresClause)
764 return ToRequiresClause.takeError();
765
766 auto ToTemplateLocOrErr = import(From->getTemplateLoc());
767 if (!ToTemplateLocOrErr)
768 return ToTemplateLocOrErr.takeError();
769 auto ToLAngleLocOrErr = import(From->getLAngleLoc());
770 if (!ToLAngleLocOrErr)
771 return ToLAngleLocOrErr.takeError();
772 auto ToRAngleLocOrErr = import(From->getRAngleLoc());
773 if (!ToRAngleLocOrErr)
774 return ToRAngleLocOrErr.takeError();
775
777 Importer.getToContext(),
778 *ToTemplateLocOrErr,
779 *ToLAngleLocOrErr,
780 To,
781 *ToRAngleLocOrErr,
782 *ToRequiresClause);
783}
784
785template <>
787ASTNodeImporter::import(const TemplateArgument &From) {
788 switch (From.getKind()) {
790 return TemplateArgument();
791
793 ExpectedType ToTypeOrErr = import(From.getAsType());
794 if (!ToTypeOrErr)
795 return ToTypeOrErr.takeError();
796 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false,
797 From.getIsDefaulted());
798 }
799
801 ExpectedType ToTypeOrErr = import(From.getIntegralType());
802 if (!ToTypeOrErr)
803 return ToTypeOrErr.takeError();
804 return TemplateArgument(From, *ToTypeOrErr);
805 }
806
808 Expected<ValueDecl *> ToOrErr = import(From.getAsDecl());
809 if (!ToOrErr)
810 return ToOrErr.takeError();
811 ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
812 if (!ToTypeOrErr)
813 return ToTypeOrErr.takeError();
814 return TemplateArgument(dyn_cast<ValueDecl>((*ToOrErr)->getCanonicalDecl()),
815 *ToTypeOrErr, From.getIsDefaulted());
816 }
817
819 ExpectedType ToTypeOrErr = import(From.getNullPtrType());
820 if (!ToTypeOrErr)
821 return ToTypeOrErr.takeError();
822 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true,
823 From.getIsDefaulted());
824 }
825
827 ExpectedType ToTypeOrErr = import(From.getStructuralValueType());
828 if (!ToTypeOrErr)
829 return ToTypeOrErr.takeError();
830 Expected<APValue> ToValueOrErr = import(From.getAsStructuralValue());
831 if (!ToValueOrErr)
832 return ToValueOrErr.takeError();
833 return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
834 *ToValueOrErr);
835 }
836
838 Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
839 if (!ToTemplateOrErr)
840 return ToTemplateOrErr.takeError();
841
842 return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
843 }
844
846 Expected<TemplateName> ToTemplateOrErr =
847 import(From.getAsTemplateOrTemplatePattern());
848 if (!ToTemplateOrErr)
849 return ToTemplateOrErr.takeError();
850
851 return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(),
852 From.getIsDefaulted());
853 }
854
856 if (ExpectedExpr ToExpr = import(From.getAsExpr()))
857 return TemplateArgument(*ToExpr, From.getIsDefaulted());
858 else
859 return ToExpr.takeError();
860
863 ToPack.reserve(From.pack_size());
864 if (Error Err = ImportTemplateArguments(From.pack_elements(), ToPack))
865 return std::move(Err);
866
867 return TemplateArgument(
868 llvm::ArrayRef(ToPack).copy(Importer.getToContext()));
869 }
870 }
871
872 llvm_unreachable("Invalid template argument kind");
873}
874
875template <>
877ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) {
878 Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument());
879 if (!ArgOrErr)
880 return ArgOrErr.takeError();
881 TemplateArgument Arg = *ArgOrErr;
882
883 TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
884
887 ExpectedExpr E = import(FromInfo.getAsExpr());
888 if (!E)
889 return E.takeError();
890 ToInfo = TemplateArgumentLocInfo(*E);
891 } else if (Arg.getKind() == TemplateArgument::Type) {
892 if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo()))
893 ToInfo = TemplateArgumentLocInfo(*TSIOrErr);
894 else
895 return TSIOrErr.takeError();
896 } else {
897 auto ToTemplateQualifierLocOrErr =
898 import(FromInfo.getTemplateQualifierLoc());
899 if (!ToTemplateQualifierLocOrErr)
900 return ToTemplateQualifierLocOrErr.takeError();
901 auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc());
902 if (!ToTemplateNameLocOrErr)
903 return ToTemplateNameLocOrErr.takeError();
904 auto ToTemplateEllipsisLocOrErr =
905 import(FromInfo.getTemplateEllipsisLoc());
906 if (!ToTemplateEllipsisLocOrErr)
907 return ToTemplateEllipsisLocOrErr.takeError();
909 Importer.getToContext(), *ToTemplateQualifierLocOrErr,
910 *ToTemplateNameLocOrErr, *ToTemplateEllipsisLocOrErr);
911 }
912
913 return TemplateArgumentLoc(Arg, ToInfo);
914}
915
916template <>
917Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) {
918 if (DG.isNull())
919 return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
920 size_t NumDecls = DG.end() - DG.begin();
922 ToDecls.reserve(NumDecls);
923 for (Decl *FromD : DG) {
924 if (auto ToDOrErr = import(FromD))
925 ToDecls.push_back(*ToDOrErr);
926 else
927 return ToDOrErr.takeError();
928 }
929 return DeclGroupRef::Create(Importer.getToContext(),
930 ToDecls.begin(),
931 NumDecls);
932}
933
934template <>
936ASTNodeImporter::import(const Designator &D) {
937 if (D.isFieldDesignator()) {
938 IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
939
940 ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc());
941 if (!ToDotLocOrErr)
942 return ToDotLocOrErr.takeError();
943
944 ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc());
945 if (!ToFieldLocOrErr)
946 return ToFieldLocOrErr.takeError();
947
949 ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr);
950 }
951
952 ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc());
953 if (!ToLBracketLocOrErr)
954 return ToLBracketLocOrErr.takeError();
955
956 ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc());
957 if (!ToRBracketLocOrErr)
958 return ToRBracketLocOrErr.takeError();
959
960 if (D.isArrayDesignator())
962 *ToLBracketLocOrErr,
963 *ToRBracketLocOrErr);
964
965 ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc());
966 if (!ToEllipsisLocOrErr)
967 return ToEllipsisLocOrErr.takeError();
968
969 assert(D.isArrayRangeDesignator());
971 D.getArrayIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr,
972 *ToRBracketLocOrErr);
973}
974
975template <>
976Expected<ConceptReference *> ASTNodeImporter::import(ConceptReference *From) {
977 Error Err = Error::success();
978 auto ToNNS = importChecked(Err, From->getNestedNameSpecifierLoc());
979 auto ToTemplateKWLoc = importChecked(Err, From->getTemplateKWLoc());
980 auto ToConceptNameLoc =
982 auto ToConceptName = importChecked(Err, From->getConceptNameInfo().getName());
983 auto ToFoundDecl = importChecked(Err, From->getFoundDecl());
984 auto ToNamedConcept = importChecked(Err, From->getNamedConcept());
985 if (Err)
986 return std::move(Err);
988 const auto *ASTTemplateArgs = From->getTemplateArgsAsWritten();
989 if (ASTTemplateArgs)
990 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
991 return std::move(Err);
992 auto *ConceptRef = ConceptReference::Create(
993 Importer.getToContext(), ToNNS, ToTemplateKWLoc,
994 DeclarationNameInfo(ToConceptName, ToConceptNameLoc), ToFoundDecl,
995 ToNamedConcept,
996 ASTTemplateArgs ? ASTTemplateArgumentListInfo::Create(
997 Importer.getToContext(), ToTAInfo)
998 : nullptr);
999 return ConceptRef;
1000}
1001
1002template <>
1003Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) {
1004 ValueDecl *Var = nullptr;
1005 if (From.capturesVariable()) {
1006 if (auto VarOrErr = import(From.getCapturedVar()))
1007 Var = *VarOrErr;
1008 else
1009 return VarOrErr.takeError();
1010 }
1011
1012 auto LocationOrErr = import(From.getLocation());
1013 if (!LocationOrErr)
1014 return LocationOrErr.takeError();
1015
1016 SourceLocation EllipsisLoc;
1017 if (From.isPackExpansion())
1018 if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc()))
1019 return std::move(Err);
1020
1021 return LambdaCapture(
1022 *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var,
1023 EllipsisLoc);
1024}
1025
1026template <typename T>
1028 if (Found->getLinkageInternal() != From->getLinkageInternal())
1029 return false;
1030
1031 if (From->hasExternalFormalLinkage())
1032 return Found->hasExternalFormalLinkage();
1033 if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl())
1034 return false;
1035 if (From->isInAnonymousNamespace())
1036 return Found->isInAnonymousNamespace();
1037 else
1038 return !Found->isInAnonymousNamespace() &&
1039 !Found->hasExternalFormalLinkage();
1040}
1041
1042template <>
1044 TypedefNameDecl *From) {
1045 if (Found->getLinkageInternal() != From->getLinkageInternal())
1046 return false;
1047
1048 if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace())
1049 return Importer.GetFromTU(Found) == From->getTranslationUnitDecl();
1050 return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace();
1051}
1052
1053} // namespace clang
1054
1055//----------------------------------------------------------------------------
1056// Import Types
1057//----------------------------------------------------------------------------
1058
1059using namespace clang;
1060
1062 Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
1063 << T->getTypeClassName();
1064 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1065}
1066
1067ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
1068 ExpectedType UnderlyingTypeOrErr = import(T->getValueType());
1069 if (!UnderlyingTypeOrErr)
1070 return UnderlyingTypeOrErr.takeError();
1071
1072 return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr);
1073}
1074
1075ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
1076 switch (T->getKind()) {
1077#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1078 case BuiltinType::Id: \
1079 return Importer.getToContext().SingletonId;
1080#include "clang/Basic/OpenCLImageTypes.def"
1081#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1082 case BuiltinType::Id: \
1083 return Importer.getToContext().Id##Ty;
1084#include "clang/Basic/OpenCLExtensionTypes.def"
1085#define SVE_TYPE(Name, Id, SingletonId) \
1086 case BuiltinType::Id: \
1087 return Importer.getToContext().SingletonId;
1088#include "clang/Basic/AArch64SVEACLETypes.def"
1089#define PPC_VECTOR_TYPE(Name, Id, Size) \
1090 case BuiltinType::Id: \
1091 return Importer.getToContext().Id##Ty;
1092#include "clang/Basic/PPCTypes.def"
1093#define RVV_TYPE(Name, Id, SingletonId) \
1094 case BuiltinType::Id: \
1095 return Importer.getToContext().SingletonId;
1096#include "clang/Basic/RISCVVTypes.def"
1097#define WASM_TYPE(Name, Id, SingletonId) \
1098 case BuiltinType::Id: \
1099 return Importer.getToContext().SingletonId;
1100#include "clang/Basic/WebAssemblyReferenceTypes.def"
1101#define SHARED_SINGLETON_TYPE(Expansion)
1102#define BUILTIN_TYPE(Id, SingletonId) \
1103 case BuiltinType::Id: return Importer.getToContext().SingletonId;
1104#include "clang/AST/BuiltinTypes.def"
1105
1106 // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
1107 // context supports C++.
1108
1109 // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
1110 // context supports ObjC.
1111
1112 case BuiltinType::Char_U:
1113 // The context we're importing from has an unsigned 'char'. If we're
1114 // importing into a context with a signed 'char', translate to
1115 // 'unsigned char' instead.
1116 if (Importer.getToContext().getLangOpts().CharIsSigned)
1117 return Importer.getToContext().UnsignedCharTy;
1118
1119 return Importer.getToContext().CharTy;
1120
1121 case BuiltinType::Char_S:
1122 // The context we're importing from has an unsigned 'char'. If we're
1123 // importing into a context with a signed 'char', translate to
1124 // 'unsigned char' instead.
1125 if (!Importer.getToContext().getLangOpts().CharIsSigned)
1126 return Importer.getToContext().SignedCharTy;
1127
1128 return Importer.getToContext().CharTy;
1129
1130 case BuiltinType::WChar_S:
1131 case BuiltinType::WChar_U:
1132 // FIXME: If not in C++, shall we translate to the C equivalent of
1133 // wchar_t?
1134 return Importer.getToContext().WCharTy;
1135 }
1136
1137 llvm_unreachable("Invalid BuiltinType Kind!");
1138}
1139
1140ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) {
1141 ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType());
1142 if (!ToOriginalTypeOrErr)
1143 return ToOriginalTypeOrErr.takeError();
1144
1145 return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr);
1146}
1147
1148ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) {
1149 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1150 if (!ToElementTypeOrErr)
1151 return ToElementTypeOrErr.takeError();
1152
1153 return Importer.getToContext().getComplexType(*ToElementTypeOrErr);
1154}
1155
1156ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) {
1157 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1158 if (!ToPointeeTypeOrErr)
1159 return ToPointeeTypeOrErr.takeError();
1160
1161 return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr);
1162}
1163
1164ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) {
1165 // FIXME: Check for blocks support in "to" context.
1166 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1167 if (!ToPointeeTypeOrErr)
1168 return ToPointeeTypeOrErr.takeError();
1169
1170 return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr);
1171}
1172
1174ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) {
1175 // FIXME: Check for C++ support in "to" context.
1176 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1177 if (!ToPointeeTypeOrErr)
1178 return ToPointeeTypeOrErr.takeError();
1179
1180 return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr);
1181}
1182
1184ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) {
1185 // FIXME: Check for C++0x support in "to" context.
1186 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1187 if (!ToPointeeTypeOrErr)
1188 return ToPointeeTypeOrErr.takeError();
1189
1190 return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr);
1191}
1192
1194ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) {
1195 // FIXME: Check for C++ support in "to" context.
1196 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1197 if (!ToPointeeTypeOrErr)
1198 return ToPointeeTypeOrErr.takeError();
1199
1200 ExpectedTypePtr ClassTypeOrErr = import(T->getClass());
1201 if (!ClassTypeOrErr)
1202 return ClassTypeOrErr.takeError();
1203
1204 return Importer.getToContext().getMemberPointerType(*ToPointeeTypeOrErr,
1205 *ClassTypeOrErr);
1206}
1207
1209ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) {
1210 Error Err = Error::success();
1211 auto ToElementType = importChecked(Err, T->getElementType());
1212 auto ToSizeExpr = importChecked(Err, T->getSizeExpr());
1213 if (Err)
1214 return std::move(Err);
1215
1216 return Importer.getToContext().getConstantArrayType(
1217 ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(),
1219}
1220
1222ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
1223 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1224 if (!ToElementTypeOrErr)
1225 return ToElementTypeOrErr.takeError();
1226
1227 return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr,
1228 T->getSizeModifier(),
1230}
1231
1233ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
1234 Error Err = Error::success();
1235 QualType ToElementType = importChecked(Err, T->getElementType());
1236 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1237 SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange());
1238 if (Err)
1239 return std::move(Err);
1240 return Importer.getToContext().getVariableArrayType(
1241 ToElementType, ToSizeExpr, T->getSizeModifier(),
1242 T->getIndexTypeCVRQualifiers(), ToBracketsRange);
1243}
1244
1245ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
1246 const DependentSizedArrayType *T) {
1247 Error Err = Error::success();
1248 QualType ToElementType = importChecked(Err, T->getElementType());
1249 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1250 SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange());
1251 if (Err)
1252 return std::move(Err);
1253 // SizeExpr may be null if size is not specified directly.
1254 // For example, 'int a[]'.
1255
1256 return Importer.getToContext().getDependentSizedArrayType(
1257 ToElementType, ToSizeExpr, T->getSizeModifier(),
1258 T->getIndexTypeCVRQualifiers(), ToBracketsRange);
1259}
1260
1261ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(
1262 const DependentSizedExtVectorType *T) {
1263 Error Err = Error::success();
1264 QualType ToElementType = importChecked(Err, T->getElementType());
1265 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1266 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1267 if (Err)
1268 return std::move(Err);
1270 ToElementType, ToSizeExpr, ToAttrLoc);
1271}
1272
1273ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) {
1274 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1275 if (!ToElementTypeOrErr)
1276 return ToElementTypeOrErr.takeError();
1277
1278 return Importer.getToContext().getVectorType(*ToElementTypeOrErr,
1279 T->getNumElements(),
1280 T->getVectorKind());
1281}
1282
1283ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) {
1284 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1285 if (!ToElementTypeOrErr)
1286 return ToElementTypeOrErr.takeError();
1287
1288 return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr,
1289 T->getNumElements());
1290}
1291
1293ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1294 // FIXME: What happens if we're importing a function without a prototype
1295 // into C++? Should we make it variadic?
1296 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1297 if (!ToReturnTypeOrErr)
1298 return ToReturnTypeOrErr.takeError();
1299
1300 return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr,
1301 T->getExtInfo());
1302}
1303
1305ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
1306 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1307 if (!ToReturnTypeOrErr)
1308 return ToReturnTypeOrErr.takeError();
1309
1310 // Import argument types
1311 SmallVector<QualType, 4> ArgTypes;
1312 for (const auto &A : T->param_types()) {
1313 ExpectedType TyOrErr = import(A);
1314 if (!TyOrErr)
1315 return TyOrErr.takeError();
1316 ArgTypes.push_back(*TyOrErr);
1317 }
1318
1319 // Import exception types
1320 SmallVector<QualType, 4> ExceptionTypes;
1321 for (const auto &E : T->exceptions()) {
1322 ExpectedType TyOrErr = import(E);
1323 if (!TyOrErr)
1324 return TyOrErr.takeError();
1325 ExceptionTypes.push_back(*TyOrErr);
1326 }
1327
1329 Error Err = Error::success();
1331 ToEPI.ExtInfo = FromEPI.ExtInfo;
1332 ToEPI.Variadic = FromEPI.Variadic;
1333 ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
1334 ToEPI.TypeQuals = FromEPI.TypeQuals;
1335 ToEPI.RefQualifier = FromEPI.RefQualifier;
1336 ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
1343 ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
1344
1345 if (Err)
1346 return std::move(Err);
1347
1348 return Importer.getToContext().getFunctionType(
1349 *ToReturnTypeOrErr, ArgTypes, ToEPI);
1350}
1351
1352ExpectedType ASTNodeImporter::VisitUnresolvedUsingType(
1353 const UnresolvedUsingType *T) {
1354 Error Err = Error::success();
1355 auto ToD = importChecked(Err, T->getDecl());
1356 auto ToPrevD = importChecked(Err, T->getDecl()->getPreviousDecl());
1357 if (Err)
1358 return std::move(Err);
1359
1360 return Importer.getToContext().getTypeDeclType(
1361 ToD, cast_or_null<TypeDecl>(ToPrevD));
1362}
1363
1364ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) {
1365 ExpectedType ToInnerTypeOrErr = import(T->getInnerType());
1366 if (!ToInnerTypeOrErr)
1367 return ToInnerTypeOrErr.takeError();
1368
1369 return Importer.getToContext().getParenType(*ToInnerTypeOrErr);
1370}
1371
1373ASTNodeImporter::VisitPackIndexingType(clang::PackIndexingType const *T) {
1374
1375 ExpectedType Pattern = import(T->getPattern());
1376 if (!Pattern)
1377 return Pattern.takeError();
1378 ExpectedExpr Index = import(T->getIndexExpr());
1379 if (!Index)
1380 return Index.takeError();
1381 return Importer.getToContext().getPackIndexingType(*Pattern, *Index);
1382}
1383
1384ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) {
1385 Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl());
1386 if (!ToDeclOrErr)
1387 return ToDeclOrErr.takeError();
1388
1389 TypedefNameDecl *ToDecl = *ToDeclOrErr;
1390 if (ToDecl->getTypeForDecl())
1391 return QualType(ToDecl->getTypeForDecl(), 0);
1392
1393 ExpectedType ToUnderlyingTypeOrErr = import(T->desugar());
1394 if (!ToUnderlyingTypeOrErr)
1395 return ToUnderlyingTypeOrErr.takeError();
1396
1397 return Importer.getToContext().getTypedefType(ToDecl, *ToUnderlyingTypeOrErr);
1398}
1399
1400ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {
1401 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1402 if (!ToExprOrErr)
1403 return ToExprOrErr.takeError();
1404 return Importer.getToContext().getTypeOfExprType(*ToExprOrErr, T->getKind());
1405}
1406
1407ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
1408 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnmodifiedType());
1409 if (!ToUnderlyingTypeOrErr)
1410 return ToUnderlyingTypeOrErr.takeError();
1411 return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr,
1412 T->getKind());
1413}
1414
1415ExpectedType ASTNodeImporter::VisitUsingType(const UsingType *T) {
1416 Expected<UsingShadowDecl *> FoundOrErr = import(T->getFoundDecl());
1417 if (!FoundOrErr)
1418 return FoundOrErr.takeError();
1419 Expected<QualType> UnderlyingOrErr = import(T->getUnderlyingType());
1420 if (!UnderlyingOrErr)
1421 return UnderlyingOrErr.takeError();
1422
1423 return Importer.getToContext().getUsingType(*FoundOrErr, *UnderlyingOrErr);
1424}
1425
1426ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) {
1427 // FIXME: Make sure that the "to" context supports C++0x!
1428 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1429 if (!ToExprOrErr)
1430 return ToExprOrErr.takeError();
1431
1432 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1433 if (!ToUnderlyingTypeOrErr)
1434 return ToUnderlyingTypeOrErr.takeError();
1435
1436 return Importer.getToContext().getDecltypeType(
1437 *ToExprOrErr, *ToUnderlyingTypeOrErr);
1438}
1439
1441ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) {
1442 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1443 if (!ToBaseTypeOrErr)
1444 return ToBaseTypeOrErr.takeError();
1445
1446 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1447 if (!ToUnderlyingTypeOrErr)
1448 return ToUnderlyingTypeOrErr.takeError();
1449
1450 return Importer.getToContext().getUnaryTransformType(
1451 *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind());
1452}
1453
1454ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) {
1455 // FIXME: Make sure that the "to" context supports C++11!
1456 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1457 if (!ToDeducedTypeOrErr)
1458 return ToDeducedTypeOrErr.takeError();
1459
1460 ExpectedDecl ToTypeConstraintConcept = import(T->getTypeConstraintConcept());
1461 if (!ToTypeConstraintConcept)
1462 return ToTypeConstraintConcept.takeError();
1463
1464 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1466 ToTemplateArgs))
1467 return std::move(Err);
1468
1469 return Importer.getToContext().getAutoType(
1470 *ToDeducedTypeOrErr, T->getKeyword(), /*IsDependent*/false,
1471 /*IsPack=*/false, cast_or_null<ConceptDecl>(*ToTypeConstraintConcept),
1472 ToTemplateArgs);
1473}
1474
1475ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType(
1477 // FIXME: Make sure that the "to" context supports C++17!
1478 Expected<TemplateName> ToTemplateNameOrErr = import(T->getTemplateName());
1479 if (!ToTemplateNameOrErr)
1480 return ToTemplateNameOrErr.takeError();
1481 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1482 if (!ToDeducedTypeOrErr)
1483 return ToDeducedTypeOrErr.takeError();
1484
1486 *ToTemplateNameOrErr, *ToDeducedTypeOrErr, T->isDependentType());
1487}
1488
1489ExpectedType ASTNodeImporter::VisitInjectedClassNameType(
1490 const InjectedClassNameType *T) {
1491 Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl());
1492 if (!ToDeclOrErr)
1493 return ToDeclOrErr.takeError();
1494
1495 // The InjectedClassNameType is created in VisitRecordDecl when the
1496 // T->getDecl() is imported. Here we can return the existing type.
1497 const Type *Ty = (*ToDeclOrErr)->getTypeForDecl();
1498 assert(Ty && isa<InjectedClassNameType>(Ty));
1499 return QualType(Ty, 0);
1500}
1501
1502ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) {
1503 Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl());
1504 if (!ToDeclOrErr)
1505 return ToDeclOrErr.takeError();
1506
1507 return Importer.getToContext().getTagDeclType(*ToDeclOrErr);
1508}
1509
1510ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) {
1511 Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl());
1512 if (!ToDeclOrErr)
1513 return ToDeclOrErr.takeError();
1514
1515 return Importer.getToContext().getTagDeclType(*ToDeclOrErr);
1516}
1517
1518ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) {
1519 ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType());
1520 if (!ToModifiedTypeOrErr)
1521 return ToModifiedTypeOrErr.takeError();
1522 ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType());
1523 if (!ToEquivalentTypeOrErr)
1524 return ToEquivalentTypeOrErr.takeError();
1525
1526 return Importer.getToContext().getAttributedType(T->getAttrKind(),
1527 *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr);
1528}
1529
1530ExpectedType ASTNodeImporter::VisitTemplateTypeParmType(
1531 const TemplateTypeParmType *T) {
1532 Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl());
1533 if (!ToDeclOrErr)
1534 return ToDeclOrErr.takeError();
1535
1536 return Importer.getToContext().getTemplateTypeParmType(
1537 T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr);
1538}
1539
1540ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType(
1541 const SubstTemplateTypeParmType *T) {
1542 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1543 if (!ReplacedOrErr)
1544 return ReplacedOrErr.takeError();
1545
1546 ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType());
1547 if (!ToReplacementTypeOrErr)
1548 return ToReplacementTypeOrErr.takeError();
1549
1551 *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex(),
1552 T->getPackIndex());
1553}
1554
1555ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
1557 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1558 if (!ReplacedOrErr)
1559 return ReplacedOrErr.takeError();
1560
1561 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1562 if (!ToArgumentPack)
1563 return ToArgumentPack.takeError();
1564
1566 *ReplacedOrErr, T->getIndex(), T->getFinal(), *ToArgumentPack);
1567}
1568
1569ExpectedType ASTNodeImporter::VisitTemplateSpecializationType(
1570 const TemplateSpecializationType *T) {
1571 auto ToTemplateOrErr = import(T->getTemplateName());
1572 if (!ToTemplateOrErr)
1573 return ToTemplateOrErr.takeError();
1574
1575 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1576 if (Error Err =
1577 ImportTemplateArguments(T->template_arguments(), ToTemplateArgs))
1578 return std::move(Err);
1579
1580 QualType ToCanonType;
1581 if (!T->isCanonicalUnqualified()) {
1582 QualType FromCanonType
1583 = Importer.getFromContext().getCanonicalType(QualType(T, 0));
1584 if (ExpectedType TyOrErr = import(FromCanonType))
1585 ToCanonType = *TyOrErr;
1586 else
1587 return TyOrErr.takeError();
1588 }
1589 return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr,
1590 ToTemplateArgs,
1591 ToCanonType);
1592}
1593
1594ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) {
1595 // Note: the qualifier in an ElaboratedType is optional.
1596 auto ToQualifierOrErr = import(T->getQualifier());
1597 if (!ToQualifierOrErr)
1598 return ToQualifierOrErr.takeError();
1599
1600 ExpectedType ToNamedTypeOrErr = import(T->getNamedType());
1601 if (!ToNamedTypeOrErr)
1602 return ToNamedTypeOrErr.takeError();
1603
1604 Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl());
1605 if (!ToOwnedTagDeclOrErr)
1606 return ToOwnedTagDeclOrErr.takeError();
1607
1608 return Importer.getToContext().getElaboratedType(T->getKeyword(),
1609 *ToQualifierOrErr,
1610 *ToNamedTypeOrErr,
1611 *ToOwnedTagDeclOrErr);
1612}
1613
1615ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) {
1616 ExpectedType ToPatternOrErr = import(T->getPattern());
1617 if (!ToPatternOrErr)
1618 return ToPatternOrErr.takeError();
1619
1620 return Importer.getToContext().getPackExpansionType(*ToPatternOrErr,
1621 T->getNumExpansions(),
1622 /*ExpactPack=*/false);
1623}
1624
1625ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType(
1627 auto ToQualifierOrErr = import(T->getQualifier());
1628 if (!ToQualifierOrErr)
1629 return ToQualifierOrErr.takeError();
1630
1631 IdentifierInfo *ToName = Importer.Import(T->getIdentifier());
1632
1634 ToPack.reserve(T->template_arguments().size());
1635 if (Error Err = ImportTemplateArguments(T->template_arguments(), ToPack))
1636 return std::move(Err);
1637
1639 T->getKeyword(), *ToQualifierOrErr, ToName, ToPack);
1640}
1641
1643ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) {
1644 auto ToQualifierOrErr = import(T->getQualifier());
1645 if (!ToQualifierOrErr)
1646 return ToQualifierOrErr.takeError();
1647
1648 IdentifierInfo *Name = Importer.Import(T->getIdentifier());
1649
1650 QualType Canon;
1651 if (T != T->getCanonicalTypeInternal().getTypePtr()) {
1652 if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal()))
1653 Canon = (*TyOrErr).getCanonicalType();
1654 else
1655 return TyOrErr.takeError();
1656 }
1657
1658 return Importer.getToContext().getDependentNameType(T->getKeyword(),
1659 *ToQualifierOrErr,
1660 Name, Canon);
1661}
1662
1664ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1665 Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl());
1666 if (!ToDeclOrErr)
1667 return ToDeclOrErr.takeError();
1668
1669 return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr);
1670}
1671
1672ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) {
1673 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1674 if (!ToBaseTypeOrErr)
1675 return ToBaseTypeOrErr.takeError();
1676
1677 SmallVector<QualType, 4> TypeArgs;
1678 for (auto TypeArg : T->getTypeArgsAsWritten()) {
1679 if (ExpectedType TyOrErr = import(TypeArg))
1680 TypeArgs.push_back(*TyOrErr);
1681 else
1682 return TyOrErr.takeError();
1683 }
1684
1686 for (auto *P : T->quals()) {
1687 if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P))
1688 Protocols.push_back(*ProtocolOrErr);
1689 else
1690 return ProtocolOrErr.takeError();
1691
1692 }
1693
1694 return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs,
1695 Protocols,
1697}
1698
1700ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1701 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1702 if (!ToPointeeTypeOrErr)
1703 return ToPointeeTypeOrErr.takeError();
1704
1705 return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
1706}
1707
1709ASTNodeImporter::VisitMacroQualifiedType(const MacroQualifiedType *T) {
1710 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1711 if (!ToUnderlyingTypeOrErr)
1712 return ToUnderlyingTypeOrErr.takeError();
1713
1714 IdentifierInfo *ToIdentifier = Importer.Import(T->getMacroIdentifier());
1715 return Importer.getToContext().getMacroQualifiedType(*ToUnderlyingTypeOrErr,
1716 ToIdentifier);
1717}
1718
1719ExpectedType clang::ASTNodeImporter::VisitAdjustedType(const AdjustedType *T) {
1720 Error Err = Error::success();
1721 QualType ToOriginalType = importChecked(Err, T->getOriginalType());
1722 QualType ToAdjustedType = importChecked(Err, T->getAdjustedType());
1723 if (Err)
1724 return std::move(Err);
1725
1726 return Importer.getToContext().getAdjustedType(ToOriginalType,
1727 ToAdjustedType);
1728}
1729
1730ExpectedType clang::ASTNodeImporter::VisitBitIntType(const BitIntType *T) {
1731 return Importer.getToContext().getBitIntType(T->isUnsigned(),
1732 T->getNumBits());
1733}
1734
1735ExpectedType clang::ASTNodeImporter::VisitBTFTagAttributedType(
1736 const clang::BTFTagAttributedType *T) {
1737 Error Err = Error::success();
1738 const BTFTypeTagAttr *ToBTFAttr = importChecked(Err, T->getAttr());
1739 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
1740 if (Err)
1741 return std::move(Err);
1742
1743 return Importer.getToContext().getBTFTagAttributedType(ToBTFAttr,
1744 ToWrappedType);
1745}
1746
1747ExpectedType clang::ASTNodeImporter::VisitConstantMatrixType(
1748 const clang::ConstantMatrixType *T) {
1749 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1750 if (!ToElementTypeOrErr)
1751 return ToElementTypeOrErr.takeError();
1752
1753 return Importer.getToContext().getConstantMatrixType(
1754 *ToElementTypeOrErr, T->getNumRows(), T->getNumColumns());
1755}
1756
1757ExpectedType clang::ASTNodeImporter::VisitDependentAddressSpaceType(
1759 Error Err = Error::success();
1760 QualType ToPointeeType = importChecked(Err, T->getPointeeType());
1761 Expr *ToAddrSpaceExpr = importChecked(Err, T->getAddrSpaceExpr());
1762 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1763 if (Err)
1764 return std::move(Err);
1765
1766 return Importer.getToContext().getDependentAddressSpaceType(
1767 ToPointeeType, ToAddrSpaceExpr, ToAttrLoc);
1768}
1769
1770ExpectedType clang::ASTNodeImporter::VisitDependentBitIntType(
1771 const clang::DependentBitIntType *T) {
1772 ExpectedExpr ToNumBitsExprOrErr = import(T->getNumBitsExpr());
1773 if (!ToNumBitsExprOrErr)
1774 return ToNumBitsExprOrErr.takeError();
1775 return Importer.getToContext().getDependentBitIntType(T->isUnsigned(),
1776 *ToNumBitsExprOrErr);
1777}
1778
1779ExpectedType clang::ASTNodeImporter::VisitDependentSizedMatrixType(
1781 Error Err = Error::success();
1782 QualType ToElementType = importChecked(Err, T->getElementType());
1783 Expr *ToRowExpr = importChecked(Err, T->getRowExpr());
1784 Expr *ToColumnExpr = importChecked(Err, T->getColumnExpr());
1785 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1786 if (Err)
1787 return std::move(Err);
1788
1789 return Importer.getToContext().getDependentSizedMatrixType(
1790 ToElementType, ToRowExpr, ToColumnExpr, ToAttrLoc);
1791}
1792
1793ExpectedType clang::ASTNodeImporter::VisitDependentVectorType(
1794 const clang::DependentVectorType *T) {
1795 Error Err = Error::success();
1796 QualType ToElementType = importChecked(Err, T->getElementType());
1797 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1798 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1799 if (Err)
1800 return std::move(Err);
1801
1802 return Importer.getToContext().getDependentVectorType(
1803 ToElementType, ToSizeExpr, ToAttrLoc, T->getVectorKind());
1804}
1805
1806ExpectedType clang::ASTNodeImporter::VisitObjCTypeParamType(
1807 const clang::ObjCTypeParamType *T) {
1808 Expected<ObjCTypeParamDecl *> ToDeclOrErr = import(T->getDecl());
1809 if (!ToDeclOrErr)
1810 return ToDeclOrErr.takeError();
1811
1813 for (ObjCProtocolDecl *FromProtocol : T->getProtocols()) {
1814 Expected<ObjCProtocolDecl *> ToProtocolOrErr = import(FromProtocol);
1815 if (!ToProtocolOrErr)
1816 return ToProtocolOrErr.takeError();
1817 ToProtocols.push_back(*ToProtocolOrErr);
1818 }
1819
1820 return Importer.getToContext().getObjCTypeParamType(*ToDeclOrErr,
1821 ToProtocols);
1822}
1823
1824ExpectedType clang::ASTNodeImporter::VisitPipeType(const clang::PipeType *T) {
1825 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1826 if (!ToElementTypeOrErr)
1827 return ToElementTypeOrErr.takeError();
1828
1829 ASTContext &ToCtx = Importer.getToContext();
1830 if (T->isReadOnly())
1831 return ToCtx.getReadPipeType(*ToElementTypeOrErr);
1832 else
1833 return ToCtx.getWritePipeType(*ToElementTypeOrErr);
1834}
1835
1836//----------------------------------------------------------------------------
1837// Import Declarations
1838//----------------------------------------------------------------------------
1840 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
1841 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) {
1842 // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop.
1843 // example: int struct_in_proto(struct data_t{int a;int b;} *d);
1844 // FIXME: We could support these constructs by importing a different type of
1845 // this parameter and by importing the original type of the parameter only
1846 // after the FunctionDecl is created. See
1847 // VisitFunctionDecl::UsedDifferentProtoType.
1848 DeclContext *OrigDC = D->getDeclContext();
1849 FunctionDecl *FunDecl;
1850 if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) &&
1851 FunDecl->hasBody()) {
1852 auto getLeafPointeeType = [](const Type *T) {
1853 while (T->isPointerType() || T->isArrayType()) {
1855 }
1856 return T;
1857 };
1858 for (const ParmVarDecl *P : FunDecl->parameters()) {
1859 const Type *LeafT =
1860 getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
1861 auto *RT = dyn_cast<RecordType>(LeafT);
1862 if (RT && RT->getDecl() == D) {
1863 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
1864 << D->getDeclKindName();
1865 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1866 }
1867 }
1868 }
1869
1870 // Import the context of this declaration.
1871 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
1872 return Err;
1873
1874 // Import the name of this declaration.
1875 if (Error Err = importInto(Name, D->getDeclName()))
1876 return Err;
1877
1878 // Import the location of this declaration.
1879 if (Error Err = importInto(Loc, D->getLocation()))
1880 return Err;
1881
1882 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
1883 if (ToD)
1884 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
1885 return Err;
1886
1887 return Error::success();
1888}
1889
1891 NamedDecl *&ToD, SourceLocation &Loc) {
1892
1893 // Import the name of this declaration.
1894 if (Error Err = importInto(Name, D->getDeclName()))
1895 return Err;
1896
1897 // Import the location of this declaration.
1898 if (Error Err = importInto(Loc, D->getLocation()))
1899 return Err;
1900
1901 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
1902 if (ToD)
1903 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
1904 return Err;
1905
1906 return Error::success();
1907}
1908
1910 if (!FromD)
1911 return Error::success();
1912
1913 if (!ToD)
1914 if (Error Err = importInto(ToD, FromD))
1915 return Err;
1916
1917 if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
1918 if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) {
1919 if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() &&
1920 !ToRecord->getDefinition()) {
1921 if (Error Err = ImportDefinition(FromRecord, ToRecord))
1922 return Err;
1923 }
1924 }
1925 return Error::success();
1926 }
1927
1928 if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
1929 if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) {
1930 if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
1931 if (Error Err = ImportDefinition(FromEnum, ToEnum))
1932 return Err;
1933 }
1934 }
1935 return Error::success();
1936 }
1937
1938 return Error::success();
1939}
1940
1941Error
1943 const DeclarationNameInfo &From, DeclarationNameInfo& To) {
1944 // NOTE: To.Name and To.Loc are already imported.
1945 // We only have to import To.LocInfo.
1946 switch (To.getName().getNameKind()) {
1953 return Error::success();
1954
1956 if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange()))
1957 To.setCXXOperatorNameRange(*ToRangeOrErr);
1958 else
1959 return ToRangeOrErr.takeError();
1960 return Error::success();
1961 }
1963 if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc()))
1964 To.setCXXLiteralOperatorNameLoc(*LocOrErr);
1965 else
1966 return LocOrErr.takeError();
1967 return Error::success();
1968 }
1972 if (auto ToTInfoOrErr = import(From.getNamedTypeInfo()))
1973 To.setNamedTypeInfo(*ToTInfoOrErr);
1974 else
1975 return ToTInfoOrErr.takeError();
1976 return Error::success();
1977 }
1978 }
1979 llvm_unreachable("Unknown name kind.");
1980}
1981
1982Error
1984 if (Importer.isMinimalImport() && !ForceImport) {
1985 auto ToDCOrErr = Importer.ImportContext(FromDC);
1986 return ToDCOrErr.takeError();
1987 }
1988
1989 // We use strict error handling in case of records and enums, but not
1990 // with e.g. namespaces.
1991 //
1992 // FIXME Clients of the ASTImporter should be able to choose an
1993 // appropriate error handling strategy for their needs. For instance,
1994 // they may not want to mark an entire namespace as erroneous merely
1995 // because there is an ODR error with two typedefs. As another example,
1996 // the client may allow EnumConstantDecls with same names but with
1997 // different values in two distinct translation units.
1998 ChildErrorHandlingStrategy HandleChildErrors(FromDC);
1999
2000 auto MightNeedReordering = [](const Decl *D) {
2001 return isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<FriendDecl>(D);
2002 };
2003
2004 // Import everything that might need reordering first.
2005 Error ChildErrors = Error::success();
2006 for (auto *From : FromDC->decls()) {
2007 if (!MightNeedReordering(From))
2008 continue;
2009
2010 ExpectedDecl ImportedOrErr = import(From);
2011
2012 // If we are in the process of ImportDefinition(...) for a RecordDecl we
2013 // want to make sure that we are also completing each FieldDecl. There
2014 // are currently cases where this does not happen and this is correctness
2015 // fix since operations such as code generation will expect this to be so.
2016 if (!ImportedOrErr) {
2017 HandleChildErrors.handleChildImportResult(ChildErrors,
2018 ImportedOrErr.takeError());
2019 continue;
2020 }
2021 FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
2022 Decl *ImportedDecl = *ImportedOrErr;
2023 FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
2024 if (FieldFrom && FieldTo) {
2025 Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
2026 HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
2027 }
2028 }
2029
2030 // We reorder declarations in RecordDecls because they may have another order
2031 // in the "to" context than they have in the "from" context. This may happen
2032 // e.g when we import a class like this:
2033 // struct declToImport {
2034 // int a = c + b;
2035 // int b = 1;
2036 // int c = 2;
2037 // };
2038 // During the import of `a` we import first the dependencies in sequence,
2039 // thus the order would be `c`, `b`, `a`. We will get the normal order by
2040 // first removing the already imported members and then adding them in the
2041 // order as they appear in the "from" context.
2042 //
2043 // Keeping field order is vital because it determines structure layout.
2044 //
2045 // Here and below, we cannot call field_begin() method and its callers on
2046 // ToDC if it has an external storage. Calling field_begin() will
2047 // automatically load all the fields by calling
2048 // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would
2049 // call ASTImporter::Import(). This is because the ExternalASTSource
2050 // interface in LLDB is implemented by the means of the ASTImporter. However,
2051 // calling an import at this point would result in an uncontrolled import, we
2052 // must avoid that.
2053
2054 auto ToDCOrErr = Importer.ImportContext(FromDC);
2055 if (!ToDCOrErr) {
2056 consumeError(std::move(ChildErrors));
2057 return ToDCOrErr.takeError();
2058 }
2059
2060 if (const auto *FromRD = dyn_cast<RecordDecl>(FromDC)) {
2061 DeclContext *ToDC = *ToDCOrErr;
2062 // Remove all declarations, which may be in wrong order in the
2063 // lexical DeclContext and then add them in the proper order.
2064 for (auto *D : FromRD->decls()) {
2065 if (!MightNeedReordering(D))
2066 continue;
2067
2068 assert(D && "DC contains a null decl");
2069 if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
2070 // Remove only the decls which we successfully imported.
2071 assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
2072 // Remove the decl from its wrong place in the linked list.
2073 ToDC->removeDecl(ToD);
2074 // Add the decl to the end of the linked list.
2075 // This time it will be at the proper place because the enclosing for
2076 // loop iterates in the original (good) order of the decls.
2077 ToDC->addDeclInternal(ToD);
2078 }
2079 }
2080 }
2081
2082 // Import everything else.
2083 for (auto *From : FromDC->decls()) {
2084 if (MightNeedReordering(From))
2085 continue;
2086
2087 ExpectedDecl ImportedOrErr = import(From);
2088 if (!ImportedOrErr)
2089 HandleChildErrors.handleChildImportResult(ChildErrors,
2090 ImportedOrErr.takeError());
2091 }
2092
2093 return ChildErrors;
2094}
2095
2097 const FieldDecl *To) {
2098 RecordDecl *FromRecordDecl = nullptr;
2099 RecordDecl *ToRecordDecl = nullptr;
2100 // If we have a field that is an ArrayType we need to check if the array
2101 // element is a RecordDecl and if so we need to import the definition.
2102 QualType FromType = From->getType();
2103 QualType ToType = To->getType();
2104 if (FromType->isArrayType()) {
2105 // getBaseElementTypeUnsafe(...) handles multi-dimensonal arrays for us.
2106 FromRecordDecl = FromType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2107 ToRecordDecl = ToType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2108 }
2109
2110 if (!FromRecordDecl || !ToRecordDecl) {
2111 const RecordType *RecordFrom = FromType->getAs<RecordType>();
2112 const RecordType *RecordTo = ToType->getAs<RecordType>();
2113
2114 if (RecordFrom && RecordTo) {
2115 FromRecordDecl = RecordFrom->getDecl();
2116 ToRecordDecl = RecordTo->getDecl();
2117 }
2118 }
2119
2120 if (FromRecordDecl && ToRecordDecl) {
2121 if (FromRecordDecl->isCompleteDefinition() &&
2122 !ToRecordDecl->isCompleteDefinition())
2123 return ImportDefinition(FromRecordDecl, ToRecordDecl);
2124 }
2125
2126 return Error::success();
2127}
2128
2130 Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) {
2131 auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext());
2132 if (!ToDCOrErr)
2133 return ToDCOrErr.takeError();
2134 ToDC = *ToDCOrErr;
2135
2136 if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) {
2137 auto ToLexicalDCOrErr = Importer.ImportContext(
2138 FromD->getLexicalDeclContext());
2139 if (!ToLexicalDCOrErr)
2140 return ToLexicalDCOrErr.takeError();
2141 ToLexicalDC = *ToLexicalDCOrErr;
2142 } else
2143 ToLexicalDC = ToDC;
2144
2145 return Error::success();
2146}
2147
2149 const CXXRecordDecl *From, CXXRecordDecl *To) {
2150 assert(From->isCompleteDefinition() && To->getDefinition() == To &&
2151 "Import implicit methods to or from non-definition");
2152
2153 for (CXXMethodDecl *FromM : From->methods())
2154 if (FromM->isImplicit()) {
2155 Expected<CXXMethodDecl *> ToMOrErr = import(FromM);
2156 if (!ToMOrErr)
2157 return ToMOrErr.takeError();
2158 }
2159
2160 return Error::success();
2161}
2162
2164 ASTImporter &Importer) {
2165 if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
2166 if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef))
2167 To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr));
2168 else
2169 return ToTypedefOrErr.takeError();
2170 }
2171 return Error::success();
2172}
2173
2175 RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) {
2176 auto DefinitionCompleter = [To]() {
2177 // There are cases in LLDB when we first import a class without its
2178 // members. The class will have DefinitionData, but no members. Then,
2179 // importDefinition is called from LLDB, which tries to get the members, so
2180 // when we get here, the class already has the DefinitionData set, so we
2181 // must unset the CompleteDefinition here to be able to complete again the
2182 // definition.
2183 To->setCompleteDefinition(false);
2184 To->completeDefinition();
2185 };
2186
2187 if (To->getDefinition() || To->isBeingDefined()) {
2188 if (Kind == IDK_Everything ||
2189 // In case of lambdas, the class already has a definition ptr set, but
2190 // the contained decls are not imported yet. Also, isBeingDefined was
2191 // set in CXXRecordDecl::CreateLambda. We must import the contained
2192 // decls here and finish the definition.
2193 (To->isLambda() && shouldForceImportDeclContext(Kind))) {
2194 if (To->isLambda()) {
2195 auto *FromCXXRD = cast<CXXRecordDecl>(From);
2197 ToCaptures.reserve(FromCXXRD->capture_size());
2198 for (const auto &FromCapture : FromCXXRD->captures()) {
2199 if (auto ToCaptureOrErr = import(FromCapture))
2200 ToCaptures.push_back(*ToCaptureOrErr);
2201 else
2202 return ToCaptureOrErr.takeError();
2203 }
2204 cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(),
2205 ToCaptures);
2206 }
2207
2208 Error Result = ImportDeclContext(From, /*ForceImport=*/true);
2209 // Finish the definition of the lambda, set isBeingDefined to false.
2210 if (To->isLambda())
2211 DefinitionCompleter();
2212 return Result;
2213 }
2214
2215 return Error::success();
2216 }
2217
2218 To->startDefinition();
2219 // Set the definition to complete even if it is really not complete during
2220 // import. Some AST constructs (expressions) require the record layout
2221 // to be calculated (see 'clang::computeDependence') at the time they are
2222 // constructed. Import of such AST node is possible during import of the
2223 // same record, there is no way to have a completely defined record (all
2224 // fields imported) at that time without multiple AST import passes.
2225 if (!Importer.isMinimalImport())
2226 To->setCompleteDefinition(true);
2227 // Complete the definition even if error is returned.
2228 // The RecordDecl may be already part of the AST so it is better to
2229 // have it in complete state even if something is wrong with it.
2230 auto DefinitionCompleterScopeExit =
2231 llvm::make_scope_exit(DefinitionCompleter);
2232
2233 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2234 return Err;
2235
2236 // Add base classes.
2237 auto *ToCXX = dyn_cast<CXXRecordDecl>(To);
2238 auto *FromCXX = dyn_cast<CXXRecordDecl>(From);
2239 if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) {
2240
2241 struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
2242 struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2243
2244 #define FIELD(Name, Width, Merge) \
2245 ToData.Name = FromData.Name;
2246 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2247
2248 // Copy over the data stored in RecordDeclBits
2249 ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions());
2250
2252 for (const auto &Base1 : FromCXX->bases()) {
2253 ExpectedType TyOrErr = import(Base1.getType());
2254 if (!TyOrErr)
2255 return TyOrErr.takeError();
2256
2257 SourceLocation EllipsisLoc;
2258 if (Base1.isPackExpansion()) {
2259 if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc()))
2260 EllipsisLoc = *LocOrErr;
2261 else
2262 return LocOrErr.takeError();
2263 }
2264
2265 // Ensure that we have a definition for the base.
2266 if (Error Err =
2267 ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
2268 return Err;
2269
2270 auto RangeOrErr = import(Base1.getSourceRange());
2271 if (!RangeOrErr)
2272 return RangeOrErr.takeError();
2273
2274 auto TSIOrErr = import(Base1.getTypeSourceInfo());
2275 if (!TSIOrErr)
2276 return TSIOrErr.takeError();
2277
2278 Bases.push_back(
2279 new (Importer.getToContext()) CXXBaseSpecifier(
2280 *RangeOrErr,
2281 Base1.isVirtual(),
2282 Base1.isBaseOfClass(),
2283 Base1.getAccessSpecifierAsWritten(),
2284 *TSIOrErr,
2285 EllipsisLoc));
2286 }
2287 if (!Bases.empty())
2288 ToCXX->setBases(Bases.data(), Bases.size());
2289 }
2290
2291 if (shouldForceImportDeclContext(Kind)) {
2292 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2293 return Err;
2294 }
2295
2296 return Error::success();
2297}
2298
2300 if (To->getAnyInitializer())
2301 return Error::success();
2302
2303 Expr *FromInit = From->getInit();
2304 if (!FromInit)
2305 return Error::success();
2306
2307 ExpectedExpr ToInitOrErr = import(FromInit);
2308 if (!ToInitOrErr)
2309 return ToInitOrErr.takeError();
2310
2311 To->setInit(*ToInitOrErr);
2312 if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) {
2313 EvaluatedStmt *ToEval = To->ensureEvaluatedStmt();
2314 ToEval->HasConstantInitialization = FromEval->HasConstantInitialization;
2315 ToEval->HasConstantDestruction = FromEval->HasConstantDestruction;
2316 // FIXME: Also import the initializer value.
2317 }
2318
2319 // FIXME: Other bits to merge?
2320 return Error::success();
2321}
2322
2324 EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) {
2325 if (To->getDefinition() || To->isBeingDefined()) {
2326 if (Kind == IDK_Everything)
2327 return ImportDeclContext(From, /*ForceImport=*/true);
2328 return Error::success();
2329 }
2330
2331 To->startDefinition();
2332
2333 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2334 return Err;
2335
2336 ExpectedType ToTypeOrErr =
2337 import(Importer.getFromContext().getTypeDeclType(From));
2338 if (!ToTypeOrErr)
2339 return ToTypeOrErr.takeError();
2340
2341 ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType());
2342 if (!ToPromotionTypeOrErr)
2343 return ToPromotionTypeOrErr.takeError();
2344
2346 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2347 return Err;
2348
2349 // FIXME: we might need to merge the number of positive or negative bits
2350 // if the enumerator lists don't match.
2351 To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr,
2352 From->getNumPositiveBits(),
2353 From->getNumNegativeBits());
2354 return Error::success();
2355}
2356
2360 for (const auto &Arg : FromArgs) {
2361 if (auto ToOrErr = import(Arg))
2362 ToArgs.push_back(*ToOrErr);
2363 else
2364 return ToOrErr.takeError();
2365 }
2366
2367 return Error::success();
2368}
2369
2370// FIXME: Do not forget to remove this and use only 'import'.
2373 return import(From);
2374}
2375
2376template <typename InContainerTy>
2378 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) {
2379 for (const auto &FromLoc : Container) {
2380 if (auto ToLocOrErr = import(FromLoc))
2381 ToTAInfo.addArgument(*ToLocOrErr);
2382 else
2383 return ToLocOrErr.takeError();
2384 }
2385 return Error::success();
2386}
2387
2392}
2393
2394bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
2395 bool IgnoreTemplateParmDepth) {
2396 // Eliminate a potential failure point where we attempt to re-import
2397 // something we're trying to import while completing ToRecord.
2398 Decl *ToOrigin = Importer.GetOriginalDecl(To);
2399 if (ToOrigin) {
2400 To = ToOrigin;
2401 }
2402
2404 Importer.getFromContext(), Importer.getToContext(),
2406 /*StrictTypeSpelling=*/false, Complain, /*ErrorOnTagTypeMismatch=*/false,
2407 IgnoreTemplateParmDepth);
2408 return Ctx.IsEquivalent(From, To);
2409}
2410
2412 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2413 << D->getDeclKindName();
2414 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2415}
2416
2418 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2419 << D->getDeclKindName();
2420 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2421}
2422
2424 // Import the context of this declaration.
2425 DeclContext *DC, *LexicalDC;
2426 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2427 return std::move(Err);
2428
2429 // Import the location of this declaration.
2430 ExpectedSLoc LocOrErr = import(D->getLocation());
2431 if (!LocOrErr)
2432 return LocOrErr.takeError();
2433
2434 EmptyDecl *ToD;
2435 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr))
2436 return ToD;
2437
2438 ToD->setLexicalDeclContext(LexicalDC);
2439 LexicalDC->addDeclInternal(ToD);
2440 return ToD;
2441}
2442
2444 TranslationUnitDecl *ToD =
2446
2447 Importer.MapImported(D, ToD);
2448
2449 return ToD;
2450}
2451
2453 DeclContext *DC, *LexicalDC;
2454 DeclarationName Name;
2455 SourceLocation Loc;
2456 NamedDecl *ToND;
2457 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
2458 return std::move(Err);
2459 if (ToND)
2460 return ToND;
2461
2462 BindingDecl *ToD;
2463 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
2464 Name.getAsIdentifierInfo()))
2465 return ToD;
2466
2467 Error Err = Error::success();
2468 QualType ToType = importChecked(Err, D->getType());
2469 Expr *ToBinding = importChecked(Err, D->getBinding());
2470 ValueDecl *ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl());
2471 if (Err)
2472 return std::move(Err);
2473
2474 ToD->setBinding(ToType, ToBinding);
2475 ToD->setDecomposedDecl(ToDecomposedDecl);
2476 addDeclToContexts(D, ToD);
2477
2478 return ToD;
2479}
2480
2482 ExpectedSLoc LocOrErr = import(D->getLocation());
2483 if (!LocOrErr)
2484 return LocOrErr.takeError();
2485 auto ColonLocOrErr = import(D->getColonLoc());
2486 if (!ColonLocOrErr)
2487 return ColonLocOrErr.takeError();
2488
2489 // Import the context of this declaration.
2490 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2491 if (!DCOrErr)
2492 return DCOrErr.takeError();
2493 DeclContext *DC = *DCOrErr;
2494
2495 AccessSpecDecl *ToD;
2496 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(),
2497 DC, *LocOrErr, *ColonLocOrErr))
2498 return ToD;
2499
2500 // Lexical DeclContext and Semantic DeclContext
2501 // is always the same for the accessSpec.
2502 ToD->setLexicalDeclContext(DC);
2503 DC->addDeclInternal(ToD);
2504
2505 return ToD;
2506}
2507
2509 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2510 if (!DCOrErr)
2511 return DCOrErr.takeError();
2512 DeclContext *DC = *DCOrErr;
2513 DeclContext *LexicalDC = DC;
2514
2515 Error Err = Error::success();
2516 auto ToLocation = importChecked(Err, D->getLocation());
2517 auto ToRParenLoc = importChecked(Err, D->getRParenLoc());
2518 auto ToAssertExpr = importChecked(Err, D->getAssertExpr());
2519 auto ToMessage = importChecked(Err, D->getMessage());
2520 if (Err)
2521 return std::move(Err);
2522
2523 StaticAssertDecl *ToD;
2524 if (GetImportedOrCreateDecl(
2525 ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
2526 ToRParenLoc, D->isFailed()))
2527 return ToD;
2528
2529 ToD->setLexicalDeclContext(LexicalDC);
2530 LexicalDC->addDeclInternal(ToD);
2531 return ToD;
2532}
2533
2535 // Import the major distinguishing characteristics of this namespace.
2536 DeclContext *DC, *LexicalDC;
2537 DeclarationName Name;
2538 SourceLocation Loc;
2539 NamedDecl *ToD;
2540 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2541 return std::move(Err);
2542 if (ToD)
2543 return ToD;
2544
2545 NamespaceDecl *MergeWithNamespace = nullptr;
2546 if (!Name) {
2547 // This is an anonymous namespace. Adopt an existing anonymous
2548 // namespace if we can.
2549 // FIXME: Not testable.
2550 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2551 MergeWithNamespace = TU->getAnonymousNamespace();
2552 else
2553 MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace();
2554 } else {
2555 SmallVector<NamedDecl *, 4> ConflictingDecls;
2556 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2557 for (auto *FoundDecl : FoundDecls) {
2559 continue;
2560
2561 if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) {
2562 MergeWithNamespace = FoundNS;
2563 ConflictingDecls.clear();
2564 break;
2565 }
2566
2567 ConflictingDecls.push_back(FoundDecl);
2568 }
2569
2570 if (!ConflictingDecls.empty()) {
2571 ExpectedName NameOrErr = Importer.HandleNameConflict(
2572 Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(),
2573 ConflictingDecls.size());
2574 if (NameOrErr)
2575 Name = NameOrErr.get();
2576 else
2577 return NameOrErr.takeError();
2578 }
2579 }
2580
2581 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2582 if (!BeginLocOrErr)
2583 return BeginLocOrErr.takeError();
2584 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
2585 if (!RBraceLocOrErr)
2586 return RBraceLocOrErr.takeError();
2587
2588 // Create the "to" namespace, if needed.
2589 NamespaceDecl *ToNamespace = MergeWithNamespace;
2590 if (!ToNamespace) {
2591 if (GetImportedOrCreateDecl(ToNamespace, D, Importer.getToContext(), DC,
2592 D->isInline(), *BeginLocOrErr, Loc,
2593 Name.getAsIdentifierInfo(),
2594 /*PrevDecl=*/nullptr, D->isNested()))
2595 return ToNamespace;
2596 ToNamespace->setRBraceLoc(*RBraceLocOrErr);
2597 ToNamespace->setLexicalDeclContext(LexicalDC);
2598 LexicalDC->addDeclInternal(ToNamespace);
2599
2600 // If this is an anonymous namespace, register it as the anonymous
2601 // namespace within its context.
2602 if (!Name) {
2603 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2604 TU->setAnonymousNamespace(ToNamespace);
2605 else
2606 cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
2607 }
2608 }
2609 Importer.MapImported(D, ToNamespace);
2610
2611 if (Error Err = ImportDeclContext(D))
2612 return std::move(Err);
2613
2614 return ToNamespace;
2615}
2616
2618 // Import the major distinguishing characteristics of this namespace.
2619 DeclContext *DC, *LexicalDC;
2620 DeclarationName Name;
2621 SourceLocation Loc;
2622 NamedDecl *LookupD;
2623 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc))
2624 return std::move(Err);
2625 if (LookupD)
2626 return LookupD;
2627
2628 // NOTE: No conflict resolution is done for namespace aliases now.
2629
2630 Error Err = Error::success();
2631 auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc());
2632 auto ToAliasLoc = importChecked(Err, D->getAliasLoc());
2633 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
2634 auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc());
2635 auto ToNamespace = importChecked(Err, D->getNamespace());
2636 if (Err)
2637 return std::move(Err);
2638
2639 IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
2640
2641 NamespaceAliasDecl *ToD;
2642 if (GetImportedOrCreateDecl(
2643 ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
2644 ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
2645 return ToD;
2646
2647 ToD->setLexicalDeclContext(LexicalDC);
2648 LexicalDC->addDeclInternal(ToD);
2649
2650 return ToD;
2651}
2652
2655 // Import the major distinguishing characteristics of this typedef.
2656 DeclarationName Name;
2657 SourceLocation Loc;
2658 NamedDecl *ToD;
2659 // Do not import the DeclContext, we will import it once the TypedefNameDecl
2660 // is created.
2661 if (Error Err = ImportDeclParts(D, Name, ToD, Loc))
2662 return std::move(Err);
2663 if (ToD)
2664 return ToD;
2665
2666 DeclContext *DC = cast_or_null<DeclContext>(
2667 Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext())));
2668 DeclContext *LexicalDC =
2669 cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull(
2670 cast<Decl>(D->getLexicalDeclContext())));
2671
2672 // If this typedef is not in block scope, determine whether we've
2673 // seen a typedef with the same name (that we can merge with) or any
2674 // other entity by that name (which name lookup could conflict with).
2675 // Note: Repeated typedefs are not valid in C99:
2676 // 'typedef int T; typedef int T;' is invalid
2677 // We do not care about this now.
2678 if (DC && !DC->isFunctionOrMethod()) {
2679 SmallVector<NamedDecl *, 4> ConflictingDecls;
2680 unsigned IDNS = Decl::IDNS_Ordinary;
2681 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2682 for (auto *FoundDecl : FoundDecls) {
2683 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2684 continue;
2685 if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
2686 if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D))
2687 continue;
2688
2689 QualType FromUT = D->getUnderlyingType();
2690 QualType FoundUT = FoundTypedef->getUnderlyingType();
2691 if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) {
2692 // If the underlying declarations are unnamed records these can be
2693 // imported as different types. We should create a distinct typedef
2694 // node in this case.
2695 // If we found an existing underlying type with a record in a
2696 // different context (than the imported), this is already reason for
2697 // having distinct typedef nodes for these.
2698 // Again this can create situation like
2699 // 'typedef int T; typedef int T;' but this is hard to avoid without
2700 // a rename strategy at import.
2701 if (!FromUT.isNull() && !FoundUT.isNull()) {
2702 RecordDecl *FromR = FromUT->getAsRecordDecl();
2703 RecordDecl *FoundR = FoundUT->getAsRecordDecl();
2704 if (FromR && FoundR &&
2705 !hasSameVisibilityContextAndLinkage(FoundR, FromR))
2706 continue;
2707 }
2708 // If the "From" context has a complete underlying type but we
2709 // already have a complete underlying type then return with that.
2710 if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
2711 return Importer.MapImported(D, FoundTypedef);
2712 // FIXME Handle redecl chain. When you do that make consistent changes
2713 // in ASTImporterLookupTable too.
2714 } else {
2715 ConflictingDecls.push_back(FoundDecl);
2716 }
2717 }
2718 }
2719
2720 if (!ConflictingDecls.empty()) {
2721 ExpectedName NameOrErr = Importer.HandleNameConflict(
2722 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
2723 if (NameOrErr)
2724 Name = NameOrErr.get();
2725 else
2726 return NameOrErr.takeError();
2727 }
2728 }
2729
2730 Error Err = Error::success();
2732 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
2733 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
2734 if (Err)
2735 return std::move(Err);
2736
2737 // Create the new typedef node.
2738 // FIXME: ToUnderlyingType is not used.
2739 (void)ToUnderlyingType;
2740 TypedefNameDecl *ToTypedef;
2741 if (IsAlias) {
2742 if (GetImportedOrCreateDecl<TypeAliasDecl>(
2743 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
2744 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
2745 return ToTypedef;
2746 } else if (GetImportedOrCreateDecl<TypedefDecl>(
2747 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
2748 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
2749 return ToTypedef;
2750
2751 // Import the DeclContext and set it to the Typedef.
2752 if ((Err = ImportDeclContext(D, DC, LexicalDC)))
2753 return std::move(Err);
2754 ToTypedef->setDeclContext(DC);
2755 ToTypedef->setLexicalDeclContext(LexicalDC);
2756 // Add to the lookupTable because we could not do that in MapImported.
2757 Importer.AddToLookupTable(ToTypedef);
2758
2759 ToTypedef->setAccess(D->getAccess());
2760
2761 // Templated declarations should not appear in DeclContext.
2762 TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr;
2763 if (!FromAlias || !FromAlias->getDescribedAliasTemplate())
2764 LexicalDC->addDeclInternal(ToTypedef);
2765
2766 return ToTypedef;
2767}
2768
2770 return VisitTypedefNameDecl(D, /*IsAlias=*/false);
2771}
2772
2774 return VisitTypedefNameDecl(D, /*IsAlias=*/true);
2775}
2776
2779 // Import the major distinguishing characteristics of this typedef.
2780 DeclContext *DC, *LexicalDC;
2781 DeclarationName Name;
2782 SourceLocation Loc;
2783 NamedDecl *FoundD;
2784 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc))
2785 return std::move(Err);
2786 if (FoundD)
2787 return FoundD;
2788
2789 // If this typedef is not in block scope, determine whether we've
2790 // seen a typedef with the same name (that we can merge with) or any
2791 // other entity by that name (which name lookup could conflict with).
2792 if (!DC->isFunctionOrMethod()) {
2793 SmallVector<NamedDecl *, 4> ConflictingDecls;
2794 unsigned IDNS = Decl::IDNS_Ordinary;
2795 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2796 for (auto *FoundDecl : FoundDecls) {
2797 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2798 continue;
2799 if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) {
2800 if (IsStructuralMatch(D, FoundAlias))
2801 return Importer.MapImported(D, FoundAlias);
2802 ConflictingDecls.push_back(FoundDecl);
2803 }
2804 }
2805
2806 if (!ConflictingDecls.empty()) {
2807 ExpectedName NameOrErr = Importer.HandleNameConflict(
2808 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
2809 if (NameOrErr)
2810 Name = NameOrErr.get();
2811 else
2812 return NameOrErr.takeError();
2813 }
2814 }
2815
2816 Error Err = Error::success();
2817 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
2818 auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl());
2819 if (Err)
2820 return std::move(Err);
2821
2822 TypeAliasTemplateDecl *ToAlias;
2823 if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc,
2824 Name, ToTemplateParameters, ToTemplatedDecl))
2825 return ToAlias;
2826
2827 ToTemplatedDecl->setDescribedAliasTemplate(ToAlias);
2828
2829 ToAlias->setAccess(D->getAccess());
2830 ToAlias->setLexicalDeclContext(LexicalDC);
2831 LexicalDC->addDeclInternal(ToAlias);
2832 if (DC != Importer.getToContext().getTranslationUnitDecl())
2833 updateLookupTableForTemplateParameters(*ToTemplateParameters);
2834 return ToAlias;
2835}
2836
2838 // Import the major distinguishing characteristics of this label.
2839 DeclContext *DC, *LexicalDC;
2840 DeclarationName Name;
2841 SourceLocation Loc;
2842 NamedDecl *ToD;
2843 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2844 return std::move(Err);
2845 if (ToD)
2846 return ToD;
2847
2848 assert(LexicalDC->isFunctionOrMethod());
2849
2850 LabelDecl *ToLabel;
2851 if (D->isGnuLocal()) {
2852 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2853 if (!BeginLocOrErr)
2854 return BeginLocOrErr.takeError();
2855 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
2856 Name.getAsIdentifierInfo(), *BeginLocOrErr))
2857 return ToLabel;
2858
2859 } else {
2860 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
2861 Name.getAsIdentifierInfo()))
2862 return ToLabel;
2863
2864 }
2865
2866 Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
2867 if (!ToStmtOrErr)
2868 return ToStmtOrErr.takeError();
2869
2870 ToLabel->setStmt(*ToStmtOrErr);
2871 ToLabel->setLexicalDeclContext(LexicalDC);
2872 LexicalDC->addDeclInternal(ToLabel);
2873 return ToLabel;
2874}
2875
2877 // Import the major distinguishing characteristics of this enum.
2878 DeclContext *DC, *LexicalDC;
2879 DeclarationName Name;
2880 SourceLocation Loc;
2881 NamedDecl *ToD;
2882 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2883 return std::move(Err);
2884 if (ToD)
2885 return ToD;
2886
2887 // Figure out what enum name we're looking for.
2888 unsigned IDNS = Decl::IDNS_Tag;
2889 DeclarationName SearchName = Name;
2890 if (!SearchName && D->getTypedefNameForAnonDecl()) {
2891 if (Error Err = importInto(
2892 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
2893 return std::move(Err);
2894 IDNS = Decl::IDNS_Ordinary;
2895 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
2896 IDNS |= Decl::IDNS_Ordinary;
2897
2898 // We may already have an enum of the same name; try to find and match it.
2899 EnumDecl *PrevDecl = nullptr;
2900 if (!DC->isFunctionOrMethod() && SearchName) {
2901 SmallVector<NamedDecl *, 4> ConflictingDecls;
2902 auto FoundDecls =
2903 Importer.findDeclsInToCtx(DC, SearchName);
2904 for (auto *FoundDecl : FoundDecls) {
2905 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2906 continue;
2907
2908 if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
2909 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
2910 FoundDecl = Tag->getDecl();
2911 }
2912
2913 if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) {
2914 if (!hasSameVisibilityContextAndLinkage(FoundEnum, D))
2915 continue;
2916 if (IsStructuralMatch(D, FoundEnum)) {
2917 EnumDecl *FoundDef = FoundEnum->getDefinition();
2918 if (D->isThisDeclarationADefinition() && FoundDef)
2919 return Importer.MapImported(D, FoundDef);
2920 PrevDecl = FoundEnum->getMostRecentDecl();
2921 break;
2922 }
2923 ConflictingDecls.push_back(FoundDecl);
2924 }
2925 }
2926
2927 if (!ConflictingDecls.empty()) {
2928 ExpectedName NameOrErr = Importer.HandleNameConflict(
2929 SearchName, DC, IDNS, ConflictingDecls.data(),
2930 ConflictingDecls.size());
2931 if (NameOrErr)
2932 Name = NameOrErr.get();
2933 else
2934 return NameOrErr.takeError();
2935 }
2936 }
2937
2938 Error Err = Error::success();
2939 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
2940 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
2941 auto ToIntegerType = importChecked(Err, D->getIntegerType());
2942 auto ToBraceRange = importChecked(Err, D->getBraceRange());
2943 if (Err)
2944 return std::move(Err);
2945
2946 // Create the enum declaration.
2947 EnumDecl *D2;
2948 if (GetImportedOrCreateDecl(
2949 D2, D, Importer.getToContext(), DC, ToBeginLoc,
2950 Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(),
2951 D->isScopedUsingClassTag(), D->isFixed()))
2952 return D2;
2953
2954 D2->setQualifierInfo(ToQualifierLoc);
2955 D2->setIntegerType(ToIntegerType);
2956 D2->setBraceRange(ToBraceRange);
2957 D2->setAccess(D->getAccess());
2958 D2->setLexicalDeclContext(LexicalDC);
2959 addDeclToContexts(D, D2);
2960
2962 TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
2963 EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
2964 if (Expected<EnumDecl *> ToInstOrErr = import(FromInst))
2965 D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
2966 else
2967 return ToInstOrErr.takeError();
2968 if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
2970 else
2971 return POIOrErr.takeError();
2972 }
2973
2974 // Import the definition
2975 if (D->isCompleteDefinition())
2976 if (Error Err = ImportDefinition(D, D2))
2977 return std::move(Err);
2978
2979 return D2;
2980}
2981
2983 bool IsFriendTemplate = false;
2984 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
2985 IsFriendTemplate =
2986 DCXX->getDescribedClassTemplate() &&
2987 DCXX->getDescribedClassTemplate()->getFriendObjectKind() !=
2989 }
2990
2991 // Import the major distinguishing characteristics of this record.
2992 DeclContext *DC = nullptr, *LexicalDC = nullptr;
2993 DeclarationName Name;
2994 SourceLocation Loc;
2995 NamedDecl *ToD = nullptr;
2996 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2997 return std::move(Err);
2998 if (ToD)
2999 return ToD;
3000
3001 // Figure out what structure name we're looking for.
3002 unsigned IDNS = Decl::IDNS_Tag;
3003 DeclarationName SearchName = Name;
3004 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3005 if (Error Err = importInto(
3006 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3007 return std::move(Err);
3008 IDNS = Decl::IDNS_Ordinary;
3009 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3011
3012 bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
3013 : DC->isDependentContext();
3014 bool DependentFriend = IsFriendTemplate && IsDependentContext;
3015
3016 // We may already have a record of the same name; try to find and match it.
3017 RecordDecl *PrevDecl = nullptr;
3018 if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
3019 SmallVector<NamedDecl *, 4> ConflictingDecls;
3020 auto FoundDecls =
3021 Importer.findDeclsInToCtx(DC, SearchName);
3022 if (!FoundDecls.empty()) {
3023 // We're going to have to compare D against potentially conflicting Decls,
3024 // so complete it.
3027 }
3028
3029 for (auto *FoundDecl : FoundDecls) {
3030 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3031 continue;
3032
3033 Decl *Found = FoundDecl;
3034 if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
3035 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3036 Found = Tag->getDecl();
3037 }
3038
3039 if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) {
3040 // Do not emit false positive diagnostic in case of unnamed
3041 // struct/union and in case of anonymous structs. Would be false
3042 // because there may be several anonymous/unnamed structs in a class.
3043 // E.g. these are both valid:
3044 // struct A { // unnamed structs
3045 // struct { struct A *next; } entry0;
3046 // struct { struct A *next; } entry1;
3047 // };
3048 // struct X { struct { int a; }; struct { int b; }; }; // anon structs
3049 if (!SearchName)
3050 if (!IsStructuralMatch(D, FoundRecord, false))
3051 continue;
3052
3053 if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
3054 continue;
3055
3056 if (IsStructuralMatch(D, FoundRecord)) {
3057 RecordDecl *FoundDef = FoundRecord->getDefinition();
3058 if (D->isThisDeclarationADefinition() && FoundDef) {
3059 // FIXME: Structural equivalence check should check for same
3060 // user-defined methods.
3061 Importer.MapImported(D, FoundDef);
3062 if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3063 auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef);
3064 assert(FoundCXX && "Record type mismatch");
3065
3066 if (!Importer.isMinimalImport())
3067 // FoundDef may not have every implicit method that D has
3068 // because implicit methods are created only if they are used.
3069 if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
3070 return std::move(Err);
3071 }
3072 }
3073 PrevDecl = FoundRecord->getMostRecentDecl();
3074 break;
3075 }
3076 ConflictingDecls.push_back(FoundDecl);
3077 } // kind is RecordDecl
3078 } // for
3079
3080 if (!ConflictingDecls.empty() && SearchName) {
3081 ExpectedName NameOrErr = Importer.HandleNameConflict(
3082 SearchName, DC, IDNS, ConflictingDecls.data(),
3083 ConflictingDecls.size());
3084 if (NameOrErr)
3085 Name = NameOrErr.get();
3086 else
3087 return NameOrErr.takeError();
3088 }
3089 }
3090
3091 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3092 if (!BeginLocOrErr)
3093 return BeginLocOrErr.takeError();
3094
3095 // Create the record declaration.
3096 RecordDecl *D2 = nullptr;
3097 CXXRecordDecl *D2CXX = nullptr;
3098 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3099 if (DCXX->isLambda()) {
3100 auto TInfoOrErr = import(DCXX->getLambdaTypeInfo());
3101 if (!TInfoOrErr)
3102 return TInfoOrErr.takeError();
3103 if (GetImportedOrCreateSpecialDecl(
3104 D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(),
3105 DC, *TInfoOrErr, Loc, DCXX->getLambdaDependencyKind(),
3106 DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault()))
3107 return D2CXX;
3108 CXXRecordDecl::LambdaNumbering Numbering = DCXX->getLambdaNumbering();
3109 ExpectedDecl CDeclOrErr = import(Numbering.ContextDecl);
3110 if (!CDeclOrErr)
3111 return CDeclOrErr.takeError();
3112 Numbering.ContextDecl = *CDeclOrErr;
3113 D2CXX->setLambdaNumbering(Numbering);
3114 } else if (DCXX->isInjectedClassName()) {
3115 // We have to be careful to do a similar dance to the one in
3116 // Sema::ActOnStartCXXMemberDeclarations
3117 const bool DelayTypeCreation = true;
3118 if (GetImportedOrCreateDecl(
3119 D2CXX, D, Importer.getToContext(), D->getTagKind(), DC,
3120 *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(),
3121 cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation))
3122 return D2CXX;
3123 Importer.getToContext().getTypeDeclType(
3124 D2CXX, dyn_cast<CXXRecordDecl>(DC));
3125 } else {
3126 if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
3127 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3128 Name.getAsIdentifierInfo(),
3129 cast_or_null<CXXRecordDecl>(PrevDecl)))
3130 return D2CXX;
3131 }
3132
3133 D2 = D2CXX;
3134 D2->setAccess(D->getAccess());
3135 D2->setLexicalDeclContext(LexicalDC);
3136 addDeclToContexts(D, D2);
3137
3138 if (ClassTemplateDecl *FromDescribed =
3139 DCXX->getDescribedClassTemplate()) {
3140 ClassTemplateDecl *ToDescribed;
3141 if (Error Err = importInto(ToDescribed, FromDescribed))
3142 return std::move(Err);
3143 D2CXX->setDescribedClassTemplate(ToDescribed);
3144 if (!DCXX->isInjectedClassName() && !IsFriendTemplate) {
3145 // In a record describing a template the type should be an
3146 // InjectedClassNameType (see Sema::CheckClassTemplate). Update the
3147 // previously set type to the correct value here (ToDescribed is not
3148 // available at record create).
3149 CXXRecordDecl *Injected = nullptr;
3150 for (NamedDecl *Found : D2CXX->noload_lookup(Name)) {
3151 auto *Record = dyn_cast<CXXRecordDecl>(Found);
3152 if (Record && Record->isInjectedClassName()) {
3153 Injected = Record;
3154 break;
3155 }
3156 }
3157 // Create an injected type for the whole redecl chain.
3158 // The chain may contain an already existing injected type at the start,
3159 // if yes this should be reused. We must ensure that only one type
3160 // object exists for the injected type (including the injected record
3161 // declaration), ASTContext does not check it.
3162 SmallVector<Decl *, 2> Redecls =
3164 const Type *FrontTy =
3165 cast<CXXRecordDecl>(Redecls.front())->getTypeForDecl();
3166 QualType InjSpec;
3167 if (auto *InjTy = FrontTy->getAs<InjectedClassNameType>())
3168 InjSpec = InjTy->getInjectedSpecializationType();
3169 else
3170 InjSpec = ToDescribed->getInjectedClassNameSpecialization();
3171 for (auto *R : Redecls) {
3172 auto *RI = cast<CXXRecordDecl>(R);
3173 if (R != Redecls.front() ||
3174 !isa<InjectedClassNameType>(RI->getTypeForDecl()))
3175 RI->setTypeForDecl(nullptr);
3176 // This function tries to get the injected type from getTypeForDecl,
3177 // then from the previous declaration if possible. If not, it creates
3178 // a new type.
3179 Importer.getToContext().getInjectedClassNameType(RI, InjSpec);
3180 }
3181 // Set the new type for the injected decl too.
3182 if (Injected) {
3183 Injected->setTypeForDecl(nullptr);
3184 // This function will copy the injected type from D2CXX into Injected.
3185 // The injected decl does not have a previous decl to copy from.
3186 Importer.getToContext().getTypeDeclType(Injected, D2CXX);
3187 }
3188 }
3189 } else if (MemberSpecializationInfo *MemberInfo =
3190 DCXX->getMemberSpecializationInfo()) {
3192 MemberInfo->getTemplateSpecializationKind();
3194
3195 if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
3196 D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
3197 else
3198 return ToInstOrErr.takeError();
3199
3200 if (ExpectedSLoc POIOrErr =
3201 import(MemberInfo->getPointOfInstantiation()))
3203 *POIOrErr);
3204 else
3205 return POIOrErr.takeError();
3206 }
3207
3208 } else {
3209 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
3210 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3211 Name.getAsIdentifierInfo(), PrevDecl))
3212 return D2;
3213 D2->setLexicalDeclContext(LexicalDC);
3214 addDeclToContexts(D, D2);
3215 }
3216
3217 if (auto BraceRangeOrErr = import(D->getBraceRange()))
3218 D2->setBraceRange(*BraceRangeOrErr);
3219 else
3220 return BraceRangeOrErr.takeError();
3221 if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
3222 D2->setQualifierInfo(*QualifierLocOrErr);
3223 else
3224 return QualifierLocOrErr.takeError();
3225
3226 if (D->isAnonymousStructOrUnion())
3227 D2->setAnonymousStructOrUnion(true);
3228
3229 if (D->isCompleteDefinition())
3230 if (Error Err = ImportDefinition(D, D2, IDK_Default))
3231 return std::move(Err);
3232
3233 return D2;
3234}
3235
3237 // Import the major distinguishing characteristics of this enumerator.
3238 DeclContext *DC, *LexicalDC;
3239 DeclarationName Name;
3240 SourceLocation Loc;
3241 NamedDecl *ToD;
3242 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3243 return std::move(Err);
3244 if (ToD)
3245 return ToD;
3246
3247 // Determine whether there are any other declarations with the same name and
3248 // in the same context.
3249 if (!LexicalDC->isFunctionOrMethod()) {
3250 SmallVector<NamedDecl *, 4> ConflictingDecls;
3251 unsigned IDNS = Decl::IDNS_Ordinary;
3252 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3253 for (auto *FoundDecl : FoundDecls) {
3254 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3255 continue;
3256
3257 if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
3258 if (IsStructuralMatch(D, FoundEnumConstant))
3259 return Importer.MapImported(D, FoundEnumConstant);
3260 ConflictingDecls.push_back(FoundDecl);
3261 }
3262 }
3263
3264 if (!ConflictingDecls.empty()) {
3265 ExpectedName NameOrErr = Importer.HandleNameConflict(
3266 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3267 if (NameOrErr)
3268 Name = NameOrErr.get();
3269 else
3270 return NameOrErr.takeError();
3271 }
3272 }
3273
3274 ExpectedType TypeOrErr = import(D->getType());
3275 if (!TypeOrErr)
3276 return TypeOrErr.takeError();
3277
3278 ExpectedExpr InitOrErr = import(D->getInitExpr());
3279 if (!InitOrErr)
3280 return InitOrErr.takeError();
3281
3282 EnumConstantDecl *ToEnumerator;
3283 if (GetImportedOrCreateDecl(
3284 ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
3285 Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
3286 return ToEnumerator;
3287
3288 ToEnumerator->setAccess(D->getAccess());
3289 ToEnumerator->setLexicalDeclContext(LexicalDC);
3290 LexicalDC->addDeclInternal(ToEnumerator);
3291 return ToEnumerator;
3292}
3293
3295 DeclaratorDecl *ToD) {
3296 unsigned int Num = FromD->getNumTemplateParameterLists();
3297 if (Num == 0)
3298 return Error::success();
3300 for (unsigned int I = 0; I < Num; ++I)
3301 if (Expected<TemplateParameterList *> ToTPListOrErr =
3302 import(FromD->getTemplateParameterList(I)))
3303 ToTPLists[I] = *ToTPListOrErr;
3304 else
3305 return ToTPListOrErr.takeError();
3306 ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
3307 return Error::success();
3308}
3309
3311 FunctionDecl *FromFD, FunctionDecl *ToFD) {
3312 switch (FromFD->getTemplatedKind()) {
3315 return Error::success();
3316
3318 if (Expected<FunctionDecl *> InstFDOrErr =
3319 import(FromFD->getInstantiatedFromDecl()))
3320 ToFD->setInstantiatedFromDecl(*InstFDOrErr);
3321 return Error::success();
3324
3325 if (Expected<FunctionDecl *> InstFDOrErr =
3326 import(FromFD->getInstantiatedFromMemberFunction()))
3327 ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
3328 else
3329 return InstFDOrErr.takeError();
3330
3331 if (ExpectedSLoc POIOrErr = import(
3334 else
3335 return POIOrErr.takeError();
3336
3337 return Error::success();
3338 }
3339
3341 auto FunctionAndArgsOrErr =
3343 if (!FunctionAndArgsOrErr)
3344 return FunctionAndArgsOrErr.takeError();
3345
3347 Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
3348
3349 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
3350 TemplateArgumentListInfo ToTAInfo;
3351 const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
3352 if (FromTAArgsAsWritten)
3353 if (Error Err = ImportTemplateArgumentListInfo(
3354 *FromTAArgsAsWritten, ToTAInfo))
3355 return Err;
3356
3357 ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
3358 if (!POIOrErr)
3359 return POIOrErr.takeError();
3360
3361 if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
3362 return Err;
3363
3364 TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
3365 ToFD->setFunctionTemplateSpecialization(
3366 std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr,
3367 TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
3368 return Error::success();
3369 }
3370
3372 auto *FromInfo = FromFD->getDependentSpecializationInfo();
3373 UnresolvedSet<8> Candidates;
3374 for (FunctionTemplateDecl *FTD : FromInfo->getCandidates()) {
3375 if (Expected<FunctionTemplateDecl *> ToFTDOrErr = import(FTD))
3376 Candidates.addDecl(*ToFTDOrErr);
3377 else
3378 return ToFTDOrErr.takeError();
3379 }
3380
3381 // Import TemplateArgumentListInfo.
3382 TemplateArgumentListInfo ToTAInfo;
3383 const auto *FromTAArgsAsWritten = FromInfo->TemplateArgumentsAsWritten;
3384 if (FromTAArgsAsWritten)
3385 if (Error Err =
3386 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
3387 return Err;
3388
3390 Importer.getToContext(), Candidates,
3391 FromTAArgsAsWritten ? &ToTAInfo : nullptr);
3392 return Error::success();
3393 }
3394 }
3395 llvm_unreachable("All cases should be covered!");
3396}
3397
3400 auto FunctionAndArgsOrErr =
3402 if (!FunctionAndArgsOrErr)
3403 return FunctionAndArgsOrErr.takeError();
3404
3405 FunctionTemplateDecl *Template;
3406 TemplateArgsTy ToTemplArgs;
3407 std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
3408 void *InsertPos = nullptr;
3409 auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos);
3410 return FoundSpec;
3411}
3412
3414 FunctionDecl *ToFD) {
3415 if (Stmt *FromBody = FromFD->getBody()) {
3416 if (ExpectedStmt ToBodyOrErr = import(FromBody))
3417 ToFD->setBody(*ToBodyOrErr);
3418 else
3419 return ToBodyOrErr.takeError();
3420 }
3421 return Error::success();
3422}
3423
3424// Returns true if the given D has a DeclContext up to the TranslationUnitDecl
3425// which is equal to the given DC, or D is equal to DC.
3426static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) {
3427 const DeclContext *DCi = dyn_cast<DeclContext>(D);
3428 if (!DCi)
3429 DCi = D->getDeclContext();
3430 assert(DCi && "Declaration should have a context");
3431 while (DCi != D->getTranslationUnitDecl()) {
3432 if (DCi == DC)
3433 return true;
3434 DCi = DCi->getParent();
3435 }
3436 return false;
3437}
3438
3439// Check if there is a declaration that has 'DC' as parent context and is
3440// referenced from statement 'S' or one of its children. The search is done in
3441// BFS order through children of 'S'.
3442static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
3443 SmallVector<const Stmt *> ToProcess;
3444 ToProcess.push_back(S);
3445 while (!ToProcess.empty()) {
3446 const Stmt *CurrentS = ToProcess.pop_back_val();
3447 ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
3448 if (const auto *DeclRef = dyn_cast<DeclRefExpr>(CurrentS)) {
3449 if (const Decl *D = DeclRef->getDecl())
3450 if (isAncestorDeclContextOf(DC, D))
3451 return true;
3452 } else if (const auto *E =
3453 dyn_cast_or_null<SubstNonTypeTemplateParmExpr>(CurrentS)) {
3454 if (const Decl *D = E->getAssociatedDecl())
3455 if (isAncestorDeclContextOf(DC, D))
3456 return true;
3457 }
3458 }
3459 return false;
3460}
3461
3462namespace {
3463/// Check if a type has any reference to a declaration that is inside the body
3464/// of a function.
3465/// The \c CheckType(QualType) function should be used to determine
3466/// this property.
3467///
3468/// The type visitor visits one type object only (not recursive).
3469/// To find all referenced declarations we must discover all type objects until
3470/// the canonical type is reached (walk over typedef and similar objects). This
3471/// is done by loop over all "sugar" type objects. For every such type we must
3472/// check all declarations that are referenced from it. For this check the
3473/// visitor is used. In the visit functions all referenced declarations except
3474/// the one that follows in the sugar chain (if any) must be checked. For this
3475/// check the same visitor is re-used (it has no state-dependent data).
3476///
3477/// The visit functions have 3 possible return values:
3478/// - True, found a declaration inside \c ParentDC.
3479/// - False, found declarations only outside \c ParentDC and it is not possible
3480/// to find more declarations (the "sugar" chain does not continue).
3481/// - Empty optional value, found no declarations or only outside \c ParentDC,
3482/// but it is possible to find more declarations in the type "sugar" chain.
3483/// The loop over the "sugar" types can be implemented by using type visit
3484/// functions only (call \c CheckType with the desugared type). With the current
3485/// solution no visit function is needed if the type has only a desugared type
3486/// as data.
3487class IsTypeDeclaredInsideVisitor
3488 : public TypeVisitor<IsTypeDeclaredInsideVisitor, std::optional<bool>> {
3489public:
3490 IsTypeDeclaredInsideVisitor(const FunctionDecl *ParentDC)
3491 : ParentDC(ParentDC) {}
3492
3493 bool CheckType(QualType T) {
3494 // Check the chain of "sugar" types.
3495 // The "sugar" types are typedef or similar types that have the same
3496 // canonical type.
3497 if (std::optional<bool> Res = Visit(T.getTypePtr()))
3498 return *Res;
3499 QualType DsT =
3500 T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3501 while (DsT != T) {
3502 if (std::optional<bool> Res = Visit(DsT.getTypePtr()))
3503 return *Res;
3504 T = DsT;
3505 DsT = T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3506 }
3507 return false;
3508 }
3509
3510 std::optional<bool> VisitTagType(const TagType *T) {
3511 if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(T->getDecl()))
3512 for (const auto &Arg : Spec->getTemplateArgs().asArray())
3513 if (checkTemplateArgument(Arg))
3514 return true;
3515 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3516 }
3517
3518 std::optional<bool> VisitPointerType(const PointerType *T) {
3519 return CheckType(T->getPointeeType());
3520 }
3521
3522 std::optional<bool> VisitReferenceType(const ReferenceType *T) {
3523 return CheckType(T->getPointeeTypeAsWritten());
3524 }
3525
3526 std::optional<bool> VisitTypedefType(const TypedefType *T) {
3527 const TypedefNameDecl *TD = T->getDecl();
3528 assert(TD);
3529 return isAncestorDeclContextOf(ParentDC, TD);
3530 }
3531
3532 std::optional<bool> VisitUsingType(const UsingType *T) {
3533 if (T->getFoundDecl() &&
3534 isAncestorDeclContextOf(ParentDC, T->getFoundDecl()))
3535 return true;
3536
3537 return {};
3538 }
3539
3540 std::optional<bool>
3541 VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
3542 for (const auto &Arg : T->template_arguments())
3543 if (checkTemplateArgument(Arg))
3544 return true;
3545 // This type is a "sugar" to a record type, it can have a desugared type.
3546 return {};
3547 }
3548
3549 std::optional<bool>
3550 VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
3551 // The "associated declaration" can be the same as ParentDC.
3552 if (isAncestorDeclContextOf(ParentDC, T->getAssociatedDecl()))
3553 return true;
3554 return {};
3555 }
3556
3557 std::optional<bool> VisitConstantArrayType(const ConstantArrayType *T) {
3558 if (T->getSizeExpr() && isAncestorDeclContextOf(ParentDC, T->getSizeExpr()))
3559 return true;
3560
3561 return CheckType(T->getElementType());
3562 }
3563
3564 std::optional<bool> VisitVariableArrayType(const VariableArrayType *T) {
3565 llvm_unreachable(
3566 "Variable array should not occur in deduced return type of a function");
3567 }
3568
3569 std::optional<bool> VisitIncompleteArrayType(const IncompleteArrayType *T) {
3570 llvm_unreachable("Incomplete array should not occur in deduced return type "
3571 "of a function");
3572 }
3573
3574 std::optional<bool> VisitDependentArrayType(const IncompleteArrayType *T) {
3575 llvm_unreachable("Dependent array should not occur in deduced return type "
3576 "of a function");
3577 }
3578
3579private:
3580 const DeclContext *const ParentDC;
3581
3582 bool checkTemplateArgument(const TemplateArgument &Arg) {
3583 switch (Arg.getKind()) {
3585 return false;
3587 return CheckType(Arg.getIntegralType());
3589 return CheckType(Arg.getAsType());
3591 return isAncestorDeclContextOf(ParentDC, Arg.getAsExpr());
3593 // FIXME: The declaration in this case is not allowed to be in a function?
3594 return isAncestorDeclContextOf(ParentDC, Arg.getAsDecl());
3596 // FIXME: The type is not allowed to be in the function?
3597 return CheckType(Arg.getNullPtrType());
3599 return CheckType(Arg.getStructuralValueType());
3601 for (const auto &PackArg : Arg.getPackAsArray())
3602 if (checkTemplateArgument(PackArg))
3603 return true;
3604 return false;
3606 // Templates can not be defined locally in functions.
3607 // A template passed as argument can be not in ParentDC.
3608 return false;
3610 // Templates can not be defined locally in functions.
3611 // A template passed as argument can be not in ParentDC.
3612 return false;
3613 }
3614 llvm_unreachable("Unknown TemplateArgument::ArgKind enum");
3615 };
3616};
3617} // namespace
3618
3619/// This function checks if the function has 'auto' return type that contains
3620/// a reference (in any way) to a declaration inside the same function.
3622 QualType FromTy = D->getType();
3623 const auto *FromFPT = FromTy->getAs<FunctionProtoType>();
3624 assert(FromFPT && "Must be called on FunctionProtoType");
3625
3626 QualType RetT = FromFPT->getReturnType();
3627 if (isa<AutoType>(RetT.getTypePtr())) {
3628 FunctionDecl *Def = D->getDefinition();
3629 IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D);
3630 return Visitor.CheckType(RetT);
3631 }
3632
3633 return false;
3634}
3635
3637ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3638 Expr *ExplicitExpr = ESpec.getExpr();
3639 if (ExplicitExpr)
3640 ExplicitExpr = importChecked(Err, ESpec.getExpr());
3641 return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3642}
3643
3645
3647 auto RedeclIt = Redecls.begin();
3648 // Import the first part of the decl chain. I.e. import all previous
3649 // declarations starting from the canonical decl.
3650 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3651 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3652 if (!ToRedeclOrErr)
3653 return ToRedeclOrErr.takeError();
3654 }
3655 assert(*RedeclIt == D);
3656
3657 // Import the major distinguishing characteristics of this function.
3658 DeclContext *DC, *LexicalDC;
3659 DeclarationName Name;
3660 SourceLocation Loc;
3661 NamedDecl *ToD;
3662 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3663 return std::move(Err);
3664 if (ToD)
3665 return ToD;
3666
3667 FunctionDecl *FoundByLookup = nullptr;
3669
3670 // If this is a function template specialization, then try to find the same
3671 // existing specialization in the "to" context. The lookup below will not
3672 // find any specialization, but would find the primary template; thus, we
3673 // have to skip normal lookup in case of specializations.
3674 // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3675 if (D->getTemplatedKind() ==
3677 auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
3678 if (!FoundFunctionOrErr)
3679 return FoundFunctionOrErr.takeError();
3680 if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
3681 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3682 return Def;
3683 FoundByLookup = FoundFunction;
3684 }
3685 }
3686 // Try to find a function in our own ("to") context with the same name, same
3687 // type, and in the same context as the function we're importing.
3688 else if (!LexicalDC->isFunctionOrMethod()) {
3689 SmallVector<NamedDecl *, 4> ConflictingDecls;
3691 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3692 for (auto *FoundDecl : FoundDecls) {
3693 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3694 continue;
3695
3696 if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3697 if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
3698 continue;
3699
3700 if (IsStructuralMatch(D, FoundFunction)) {
3701 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3702 return Def;
3703 FoundByLookup = FoundFunction;
3704 break;
3705 }
3706 // FIXME: Check for overloading more carefully, e.g., by boosting
3707 // Sema::IsOverload out to the AST library.
3708
3709 // Function overloading is okay in C++.
3710 if (Importer.getToContext().getLangOpts().CPlusPlus)
3711 continue;
3712
3713 // Complain about inconsistent function types.
3714 Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
3715 << Name << D->getType() << FoundFunction->getType();
3716 Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
3717 << FoundFunction->getType();
3718 ConflictingDecls.push_back(FoundDecl);
3719 }
3720 }
3721
3722 if (!ConflictingDecls.empty()) {
3723 ExpectedName NameOrErr = Importer.HandleNameConflict(
3724 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3725 if (NameOrErr)
3726 Name = NameOrErr.get();
3727 else
3728 return NameOrErr.takeError();
3729 }
3730 }
3731
3732 // We do not allow more than one in-class declaration of a function. This is
3733 // because AST clients like VTableBuilder asserts on this. VTableBuilder
3734 // assumes there is only one in-class declaration. Building a redecl
3735 // chain would result in more than one in-class declaration for
3736 // overrides (even if they are part of the same redecl chain inside the
3737 // derived class.)
3738 if (FoundByLookup) {
3739 if (isa<CXXMethodDecl>(FoundByLookup)) {
3740 if (D->getLexicalDeclContext() == D->getDeclContext()) {
3741 if (!D->doesThisDeclarationHaveABody()) {
3742 if (FunctionTemplateDecl *DescribedD =
3744 // Handle a "templated" function together with its described
3745 // template. This avoids need for a similar check at import of the
3746 // described template.
3747 assert(FoundByLookup->getDescribedFunctionTemplate() &&
3748 "Templated function mapped to non-templated?");
3749 Importer.MapImported(DescribedD,
3750 FoundByLookup->getDescribedFunctionTemplate());
3751 }
3752 return Importer.MapImported(D, FoundByLookup);
3753 } else {
3754 // Let's continue and build up the redecl chain in this case.
3755 // FIXME Merge the functions into one decl.
3756 }
3757 }
3758 }
3759 }
3760
3761 DeclarationNameInfo NameInfo(Name, Loc);
3762 // Import additional name location/type info.
3763 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
3764 return std::move(Err);
3765
3766 QualType FromTy = D->getType();
3767 TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
3768 // Set to true if we do not import the type of the function as is. There are
3769 // cases when the original type would result in an infinite recursion during
3770 // the import. To avoid an infinite recursion when importing, we create the
3771 // FunctionDecl with a simplified function type and update it only after the
3772 // relevant AST nodes are already imported.
3773 // The type is related to TypeSourceInfo (it references the type), so we must
3774 // do the same with TypeSourceInfo.
3775 bool UsedDifferentProtoType = false;
3776 if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
3777 QualType FromReturnTy = FromFPT->getReturnType();
3778 // Functions with auto return type may define a struct inside their body
3779 // and the return type could refer to that struct.
3780 // E.g.: auto foo() { struct X{}; return X(); }
3781 // To avoid an infinite recursion when importing, create the FunctionDecl
3782 // with a simplified return type.
3784 FromReturnTy = Importer.getFromContext().VoidTy;
3785 UsedDifferentProtoType = true;
3786 }
3787 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
3788 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
3789 // FunctionDecl that we are importing the FunctionProtoType for.
3790 // To avoid an infinite recursion when importing, create the FunctionDecl
3791 // with a simplified function type.
3792 if (FromEPI.ExceptionSpec.SourceDecl ||
3793 FromEPI.ExceptionSpec.SourceTemplate ||
3794 FromEPI.ExceptionSpec.NoexceptExpr) {
3796 FromEPI = DefaultEPI;
3797 UsedDifferentProtoType = true;
3798 }
3799 FromTy = Importer.getFromContext().getFunctionType(
3800 FromReturnTy, FromFPT->getParamTypes(), FromEPI);
3801 FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
3802 FromTy, D->getBeginLoc());
3803 }
3804
3805 Error Err = Error::success();
3806 auto T = importChecked(Err, FromTy);
3807 auto TInfo = importChecked(Err, FromTSI);
3808 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
3809 auto ToEndLoc = importChecked(Err, D->getEndLoc());
3810 auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
3811 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3812 auto TrailingRequiresClause =
3814 if (Err)
3815 return std::move(Err);
3816
3817 // Import the function parameters.
3819 for (auto *P : D->parameters()) {
3820 if (Expected<ParmVarDecl *> ToPOrErr = import(P))
3821 Parameters.push_back(*ToPOrErr);
3822 else
3823 return ToPOrErr.takeError();
3824 }
3825
3826 // Create the imported function.
3827 FunctionDecl *ToFunction = nullptr;
3828 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
3829 ExplicitSpecifier ESpec =
3830 importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
3831 if (Err)
3832 return std::move(Err);
3833 auto ToInheritedConstructor = InheritedConstructor();
3834 if (FromConstructor->isInheritingConstructor()) {
3835 Expected<InheritedConstructor> ImportedInheritedCtor =
3836 import(FromConstructor->getInheritedConstructor());
3837 if (!ImportedInheritedCtor)
3838 return ImportedInheritedCtor.takeError();
3839 ToInheritedConstructor = *ImportedInheritedCtor;
3840 }
3841 if (GetImportedOrCreateDecl<CXXConstructorDecl>(
3842 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3843 ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
3845 ToInheritedConstructor, TrailingRequiresClause))
3846 return ToFunction;
3847 } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
3848
3849 Error Err = Error::success();
3850 auto ToOperatorDelete = importChecked(
3851 Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
3852 auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
3853 if (Err)
3854 return std::move(Err);
3855
3856 if (GetImportedOrCreateDecl<CXXDestructorDecl>(
3857 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3858 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
3860 TrailingRequiresClause))
3861 return ToFunction;
3862
3863 CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
3864
3865 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
3866 } else if (CXXConversionDecl *FromConversion =
3867 dyn_cast<CXXConversionDecl>(D)) {
3868 ExplicitSpecifier ESpec =
3869 importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
3870 if (Err)
3871 return std::move(Err);
3872 if (GetImportedOrCreateDecl<CXXConversionDecl>(
3873 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3874 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
3875 D->isInlineSpecified(), ESpec, D->getConstexprKind(),
3876 SourceLocation(), TrailingRequiresClause))
3877 return ToFunction;
3878 } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
3879 if (GetImportedOrCreateDecl<CXXMethodDecl>(
3880 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3881 ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
3882 Method->UsesFPIntrin(), Method->isInlineSpecified(),
3883 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
3884 return ToFunction;
3885 } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
3886 ExplicitSpecifier ESpec =
3887 importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
3888 CXXConstructorDecl *Ctor =
3889 importChecked(Err, Guide->getCorrespondingConstructor());
3890 if (Err)
3891 return std::move(Err);
3892 if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
3893 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
3894 NameInfo, T, TInfo, ToEndLoc, Ctor))
3895 return ToFunction;
3896 cast<CXXDeductionGuideDecl>(ToFunction)
3897 ->setDeductionCandidateKind(Guide->getDeductionCandidateKind());
3898 } else {
3899 if (GetImportedOrCreateDecl(
3900 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
3901 NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
3903 D->getConstexprKind(), TrailingRequiresClause))
3904 return ToFunction;
3905 }
3906
3907 // Connect the redecl chain.
3908 if (FoundByLookup) {
3909 auto *Recent = const_cast<FunctionDecl *>(
3910 FoundByLookup->getMostRecentDecl());
3911 ToFunction->setPreviousDecl(Recent);
3912 // FIXME Probably we should merge exception specifications. E.g. In the
3913 // "To" context the existing function may have exception specification with
3914 // noexcept-unevaluated, while the newly imported function may have an
3915 // evaluated noexcept. A call to adjustExceptionSpec() on the imported
3916 // decl and its redeclarations may be required.
3917 }
3918
3919 ToFunction->setQualifierInfo(ToQualifierLoc);
3920 ToFunction->setAccess(D->getAccess());
3921 ToFunction->setLexicalDeclContext(LexicalDC);
3922 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
3923 ToFunction->setTrivial(D->isTrivial());
3924 ToFunction->setIsPureVirtual(D->isPureVirtual());
3925 ToFunction->setDefaulted(D->isDefaulted());
3927 ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
3930 ToFunction->setRangeEnd(ToEndLoc);
3931 ToFunction->setDefaultLoc(ToDefaultLoc);
3932
3933 // Set the parameters.
3934 for (auto *Param : Parameters) {
3935 Param->setOwningFunction(ToFunction);
3936 ToFunction->addDeclInternal(Param);
3937 if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
3938 LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
3939 }
3940 ToFunction->setParams(Parameters);
3941
3942 // We need to complete creation of FunctionProtoTypeLoc manually with setting
3943 // params it refers to.
3944 if (TInfo) {
3945 if (auto ProtoLoc =
3946 TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
3947 for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
3948 ProtoLoc.setParam(I, Parameters[I]);
3949 }
3950 }
3951
3952 // Import the describing template function, if any.
3953 if (FromFT) {
3954 auto ToFTOrErr = import(FromFT);
3955 if (!ToFTOrErr)
3956 return ToFTOrErr.takeError();
3957 }
3958
3959 // Import Ctor initializers.
3960 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
3961 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
3962 SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
3963 // Import first, then allocate memory and copy if there was no error.
3964 if (Error Err = ImportContainerChecked(
3965 FromConstructor->inits(), CtorInitializers))
3966 return std::move(Err);
3967 auto **Memory =
3968 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
3969 std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
3970 auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
3971 ToCtor->setCtorInitializers(Memory);
3972 ToCtor->setNumCtorInitializers(NumInitializers);
3973 }
3974 }
3975
3976 // If it is a template, import all related things.
3977 if (Error Err = ImportTemplateInformation(D, ToFunction))
3978 return std::move(Err);
3979
3980 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
3981 if (Error Err = ImportOverriddenMethods(cast<CXXMethodDecl>(ToFunction),
3982 FromCXXMethod))
3983 return std::move(Err);
3984
3986 Error Err = ImportFunctionDeclBody(D, ToFunction);
3987
3988 if (Err)
3989 return std::move(Err);
3990 }
3991
3992 // Import and set the original type in case we used another type.
3993 if (UsedDifferentProtoType) {
3994 if (ExpectedType TyOrErr = import(D->getType()))
3995 ToFunction->setType(*TyOrErr);
3996 else
3997 return TyOrErr.takeError();
3998 if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
3999 ToFunction->setTypeSourceInfo(*TSIOrErr);
4000 else
4001 return TSIOrErr.takeError();
4002 }
4003
4004 // FIXME: Other bits to merge?
4005
4006 addDeclToContexts(D, ToFunction);
4007
4008 // Import the rest of the chain. I.e. import all subsequent declarations.
4009 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4010 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4011 if (!ToRedeclOrErr)
4012 return ToRedeclOrErr.takeError();
4013 }
4014
4015 return ToFunction;
4016}
4017
4019 return VisitFunctionDecl(D);
4020}
4021
4023 return VisitCXXMethodDecl(D);
4024}
4025
4027 return VisitCXXMethodDecl(D);
4028}
4029
4031 return VisitCXXMethodDecl(D);
4032}
4033
4036 return VisitFunctionDecl(D);
4037}
4038
4040 // Import the major distinguishing characteristics of a variable.
4041 DeclContext *DC, *LexicalDC;
4042 DeclarationName Name;
4043 SourceLocation Loc;
4044 NamedDecl *ToD;
4045 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4046 return std::move(Err);
4047 if (ToD)
4048 return ToD;
4049
4050 // Determine whether we've already imported this field.
4051 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4052 for (auto *FoundDecl : FoundDecls) {
4053 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4054 // For anonymous fields, match up by index.
4055 if (!Name &&
4057 ASTImporter::getFieldIndex(FoundField))
4058 continue;
4059
4060 if (Importer.IsStructurallyEquivalent(D->getType(),
4061 FoundField->getType())) {
4062 Importer.MapImported(D, FoundField);
4063 // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4064 // initializer of a FieldDecl might not had been instantiated in the
4065 // "To" context. However, the "From" context might instantiated that,
4066 // thus we have to merge that.
4067 // Note: `hasInClassInitializer()` is not the same as non-null
4068 // `getInClassInitializer()` value.
4069 if (Expr *FromInitializer = D->getInClassInitializer()) {
4070 if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4071 // Import of the FromInitializer may result in the setting of
4072 // InClassInitializer. If not, set it here.
4073 assert(FoundField->hasInClassInitializer() &&
4074 "Field should have an in-class initializer if it has an "
4075 "expression for it.");
4076 if (!FoundField->getInClassInitializer())
4077 FoundField->setInClassInitializer(*ToInitializerOrErr);
4078 } else {
4079 return ToInitializerOrErr.takeError();
4080 }
4081 }
4082 return FoundField;
4083 }
4084
4085 // FIXME: Why is this case not handled with calling HandleNameConflict?
4086 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4087 << Name << D->getType() << FoundField->getType();
4088 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4089 << FoundField->getType();
4090
4091 return make_error<ASTImportError>(ASTImportError::NameConflict);
4092 }
4093 }
4094
4095 Error Err = Error::success();
4096 auto ToType = importChecked(Err, D->getType());
4097 auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4098 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4099 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4100 if (Err)
4101 return std::move(Err);
4102 const Type *ToCapturedVLAType = nullptr;
4103 if (Error Err = Importer.importInto(
4104 ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4105 return std::move(Err);
4106
4107 FieldDecl *ToField;
4108 if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4109 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4110 ToType, ToTInfo, ToBitWidth, D->isMutable(),
4111 D->getInClassInitStyle()))
4112 return ToField;
4113
4114 // We need [[no_unqiue_address]] attributes to be added to FieldDecl, before
4115 // we add fields in CXXRecordDecl::addedMember, otherwise record will be
4116 // marked as having non-zero size.
4117 Err = Importer.ImportAttrs(ToField, D);
4118 if (Err)
4119 return std::move(Err);
4120 ToField->setAccess(D->getAccess());
4121 ToField->setLexicalDeclContext(LexicalDC);
4122 ToField->setImplicit(D->isImplicit());
4123 if (ToCapturedVLAType)
4124 ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4125 LexicalDC->addDeclInternal(ToField);
4126 // Import initializer only after the field was created, it may have recursive
4127 // reference to the field.
4128 auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4129 if (Err)
4130 return std::move(Err);
4131 if (ToInitializer) {
4132 auto *AlreadyImported = ToField->getInClassInitializer();
4133 if (AlreadyImported)
4134 assert(ToInitializer == AlreadyImported &&
4135 "Duplicate import of in-class initializer.");
4136 else
4137 ToField->setInClassInitializer(ToInitializer);
4138 }
4139
4140 return ToField;
4141}
4142
4144 // Import the major distinguishing characteristics of a variable.
4145 DeclContext *DC, *LexicalDC;
4146 DeclarationName Name;
4147 SourceLocation Loc;
4148 NamedDecl *ToD;
4149 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4150 return std::move(Err);
4151 if (ToD)
4152 return ToD;
4153
4154 // Determine whether we've already imported this field.
4155 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4156 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4157 if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4158 // For anonymous indirect fields, match up by index.
4159 if (!Name &&
4161 ASTImporter::getFieldIndex(FoundField))
4162 continue;
4163
4164 if (Importer.IsStructurallyEquivalent(D->getType(),
4165 FoundField->getType(),
4166 !Name.isEmpty())) {
4167 Importer.MapImported(D, FoundField);
4168 return FoundField;
4169 }
4170
4171 // If there are more anonymous fields to check, continue.
4172 if (!Name && I < N-1)
4173 continue;
4174
4175 // FIXME: Why is this case not handled with calling HandleNameConflict?
4176 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4177 << Name << D->getType() << FoundField->getType();
4178 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4179 << FoundField->getType();
4180
4181 return make_error<ASTImportError>(ASTImportError::NameConflict);
4182 }
4183 }
4184
4185 // Import the type.
4186 auto TypeOrErr = import(D->getType());
4187 if (!TypeOrErr)
4188 return TypeOrErr.takeError();
4189
4190 auto **NamedChain =
4191 new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4192
4193 unsigned i = 0;
4194 for (auto *PI : D->chain())
4195 if (Expected<NamedDecl *> ToD = import(PI))
4196 NamedChain[i++] = *ToD;
4197 else
4198 return ToD.takeError();
4199
4201 IndirectFieldDecl *ToIndirectField;
4202 if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4203 Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4204 // FIXME here we leak `NamedChain` which is allocated before
4205 return ToIndirectField;
4206
4207 ToIndirectField->setAccess(D->getAccess());
4208 ToIndirectField->setLexicalDeclContext(LexicalDC);
4209 LexicalDC->addDeclInternal(ToIndirectField);
4210 return ToIndirectField;
4211}
4212
4213/// Used as return type of getFriendCountAndPosition.
4215 /// Number of similar looking friends.
4216 unsigned int TotalCount;
4217 /// Index of the specific FriendDecl.
4218 unsigned int IndexOfDecl;
4219};
4220
4221static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4222 FriendDecl *FD2) {
4223 if ((!FD1->getFriendType()) != (!FD2->getFriendType()))
4224 return false;
4225
4226 if (const TypeSourceInfo *TSI = FD1->getFriendType())
4227 return Importer.IsStructurallyEquivalent(
4228 TSI->getType(), FD2->getFriendType()->getType(), /*Complain=*/false);
4229
4230 ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4232 FD1->getASTContext(), FD2->getASTContext(), NonEquivalentDecls,
4234 /* StrictTypeSpelling = */ false, /* Complain = */ false);
4235 return Ctx.IsEquivalent(FD1, FD2);
4236}
4237
4239 FriendDecl *FD) {
4240 unsigned int FriendCount = 0;
4241 std::optional<unsigned int> FriendPosition;
4242 const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4243
4244 for (FriendDecl *FoundFriend : RD->friends()) {
4245 if (FoundFriend == FD) {
4246 FriendPosition = FriendCount;
4247 ++FriendCount;
4248 } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4249 ++FriendCount;
4250 }
4251 }
4252
4253 assert(FriendPosition && "Friend decl not found in own parent.");
4254
4255 return {FriendCount, *FriendPosition};
4256}
4257
4259 // Import the major distinguishing characteristics of a declaration.
4260 DeclContext *DC, *LexicalDC;
4261 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4262 return std::move(Err);
4263
4264 // Determine whether we've already imported this decl.
4265 // FriendDecl is not a NamedDecl so we cannot use lookup.
4266 // We try to maintain order and count of redundant friend declarations.
4267 const auto *RD = cast<CXXRecordDecl>(DC);
4268 SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4269 for (FriendDecl *ImportedFriend : RD->friends())
4270 if (IsEquivalentFriend(Importer, D, ImportedFriend))
4271 ImportedEquivalentFriends.push_back(ImportedFriend);
4272
4273 FriendCountAndPosition CountAndPosition =
4274 getFriendCountAndPosition(Importer, D);
4275
4276 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4277 "Class with non-matching friends is imported, ODR check wrong?");
4278 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4279 return Importer.MapImported(
4280 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4281
4282 // Not found. Create it.
4283 // The declarations will be put into order later by ImportDeclContext.
4285 if (NamedDecl *FriendD = D->getFriendDecl()) {
4286 NamedDecl *ToFriendD;
4287 if (Error Err = importInto(ToFriendD, FriendD))
4288 return std::move(Err);
4289
4290 if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4291 !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator)))
4292 ToFriendD->setObjectOfFriendDecl(false);
4293
4294 ToFU = ToFriendD;
4295 } else { // The friend is a type, not a decl.
4296 if (auto TSIOrErr = import(D->getFriendType()))
4297 ToFU = *TSIOrErr;
4298 else
4299 return TSIOrErr.takeError();
4300 }
4301
4302 SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
4303 auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>();
4304 for (unsigned I = 0; I < D->NumTPLists; I++) {
4305 if (auto ListOrErr = import(FromTPLists[I]))
4306 ToTPLists[I] = *ListOrErr;
4307 else
4308 return ListOrErr.takeError();
4309 }
4310
4311 auto LocationOrErr = import(D->getLocation());
4312 if (!LocationOrErr)
4313 return LocationOrErr.takeError();
4314 auto FriendLocOrErr = import(D->getFriendLoc());
4315 if (!FriendLocOrErr)
4316 return FriendLocOrErr.takeError();
4317
4318 FriendDecl *FrD;
4319 if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4320 *LocationOrErr, ToFU,
4321 *FriendLocOrErr, ToTPLists))
4322 return FrD;
4323
4324 FrD->setAccess(D->getAccess());
4325 FrD->setLexicalDeclContext(LexicalDC);
4326 LexicalDC->addDeclInternal(FrD);
4327 return FrD;
4328}
4329
4331 // Import the major distinguishing characteristics of an ivar.
4332 DeclContext *DC, *LexicalDC;
4333 DeclarationName Name;
4334 SourceLocation Loc;
4335 NamedDecl *ToD;
4336 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4337 return std::move(Err);
4338 if (ToD)
4339 return ToD;
4340
4341 // Determine whether we've already imported this ivar
4342 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4343 for (auto *FoundDecl : FoundDecls) {
4344 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4345 if (Importer.IsStructurallyEquivalent(D->getType(),
4346 FoundIvar->getType())) {
4347 Importer.MapImported(D, FoundIvar);
4348 return FoundIvar;
4349 }
4350
4351 Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4352 << Name << D->getType() << FoundIvar->getType();
4353 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4354 << FoundIvar->getType();
4355
4356 return make_error<ASTImportError>(ASTImportError::NameConflict);
4357 }
4358 }
4359
4360 Error Err = Error::success();
4361 auto ToType = importChecked(Err, D->getType());
4362 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4363 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4364 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4365 if (Err)
4366 return std::move(Err);
4367
4368 ObjCIvarDecl *ToIvar;
4369 if (GetImportedOrCreateDecl(
4370 ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4371 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4372 ToType, ToTypeSourceInfo,
4373 D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4374 return ToIvar;
4375
4376 ToIvar->setLexicalDeclContext(LexicalDC);
4377 LexicalDC->addDeclInternal(ToIvar);
4378 return ToIvar;
4379}
4380
4382
4384 auto RedeclIt = Redecls.begin();
4385 // Import the first part of the decl chain. I.e. import all previous
4386 // declarations starting from the canonical decl.
4387 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4388 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4389 if (!RedeclOrErr)
4390 return RedeclOrErr.takeError();
4391 }
4392 assert(*RedeclIt == D);
4393
4394 // Import the major distinguishing characteristics of a variable.
4395 DeclContext *DC, *LexicalDC;
4396 DeclarationName Name;
4397 SourceLocation Loc;
4398 NamedDecl *ToD;
4399 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4400 return std::move(Err);
4401 if (ToD)
4402 return ToD;
4403
4404 // Try to find a variable in our own ("to") context with the same name and
4405 // in the same context as the variable we're importing.
4406 VarDecl *FoundByLookup = nullptr;
4407 if (D->isFileVarDecl()) {
4408 SmallVector<NamedDecl *, 4> ConflictingDecls;
4409 unsigned IDNS = Decl::IDNS_Ordinary;
4410 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4411 for (auto *FoundDecl : FoundDecls) {
4412 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4413 continue;
4414
4415 if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4416 if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4417 continue;
4418 if (Importer.IsStructurallyEquivalent(D->getType(),
4419 FoundVar->getType())) {
4420
4421 // The VarDecl in the "From" context has a definition, but in the
4422 // "To" context we already have a definition.
4423 VarDecl *FoundDef = FoundVar->getDefinition();
4424 if (D->isThisDeclarationADefinition() && FoundDef)
4425 // FIXME Check for ODR error if the two definitions have
4426 // different initializers?
4427 return Importer.MapImported(D, FoundDef);
4428
4429 // The VarDecl in the "From" context has an initializer, but in the
4430 // "To" context we already have an initializer.
4431 const VarDecl *FoundDInit = nullptr;
4432 if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4433 // FIXME Diagnose ODR error if the two initializers are different?
4434 return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4435
4436 FoundByLookup = FoundVar;
4437 break;
4438 }
4439
4440 const ArrayType *FoundArray
4441 = Importer.getToContext().getAsArrayType(FoundVar->getType());
4442 const ArrayType *TArray
4443 = Importer.getToContext().getAsArrayType(D->getType());
4444 if (FoundArray && TArray) {
4445 if (isa<IncompleteArrayType>(FoundArray) &&
4446 isa<ConstantArrayType>(TArray)) {
4447 // Import the type.
4448 if (auto TyOrErr = import(D->getType()))
4449 FoundVar->setType(*TyOrErr);
4450 else
4451 return TyOrErr.takeError();
4452
4453 FoundByLookup = FoundVar;
4454 break;
4455 } else if (isa<IncompleteArrayType>(TArray) &&
4456 isa<ConstantArrayType>(FoundArray)) {
4457 FoundByLookup = FoundVar;
4458 break;
4459 }
4460 }
4461
4462 Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4463 << Name << D->getType() << FoundVar->getType();
4464 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4465 << FoundVar->getType();
4466 ConflictingDecls.push_back(FoundDecl);
4467 }
4468 }
4469
4470 if (!ConflictingDecls.empty()) {
4471 ExpectedName NameOrErr = Importer.HandleNameConflict(
4472 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4473 if (NameOrErr)
4474 Name = NameOrErr.get();
4475 else
4476 return NameOrErr.takeError();
4477 }
4478 }
4479
4480 Error Err = Error::success();
4481 auto ToType = importChecked(Err, D->getType());
4482 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4483 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4484 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4485 if (Err)
4486 return std::move(Err);
4487
4488 VarDecl *ToVar;
4489 if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4490 SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4491 if (Error Err =
4492 ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4493 return std::move(Err);
4494 DecompositionDecl *ToDecomp;
4495 if (GetImportedOrCreateDecl(
4496 ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4497 Loc, ToType, ToTypeSourceInfo, D->getStorageClass(), Bindings))
4498 return ToDecomp;
4499 ToVar = ToDecomp;
4500 } else {
4501 // Create the imported variable.
4502 if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4503 ToInnerLocStart, Loc,
4504 Name.getAsIdentifierInfo(), ToType,
4505 ToTypeSourceInfo, D->getStorageClass()))
4506 return ToVar;
4507 }
4508
4509 ToVar->setTSCSpec(D->getTSCSpec());
4510 ToVar->setQualifierInfo(ToQualifierLoc);
4511 ToVar->setAccess(D->getAccess());
4512 ToVar->setLexicalDeclContext(LexicalDC);
4513
4514 if (FoundByLookup) {
4515 auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4516 ToVar->setPreviousDecl(Recent);
4517 }
4518
4519 // Import the described template, if any.
4520 if (D->getDescribedVarTemplate()) {
4521 auto ToVTOrErr = import(D->getDescribedVarTemplate());
4522 if (!ToVTOrErr)
4523 return ToVTOrErr.takeError();
4525 TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4527 if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4528 ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4529 else
4530 return ToInstOrErr.takeError();
4531 if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4533 else
4534 return POIOrErr.takeError();
4535 }
4536
4537 if (Error Err = ImportInitializer(D, ToVar))
4538 return std::move(Err);
4539
4540 if (D->isConstexpr())
4541 ToVar->setConstexpr(true);
4542
4543 addDeclToContexts(D, ToVar);
4544
4545 // Import the rest of the chain. I.e. import all subsequent declarations.
4546 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4547 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4548 if (!RedeclOrErr)
4549 return RedeclOrErr.takeError();
4550 }
4551
4552 return ToVar;
4553}
4554
4556 // Parameters are created in the translation unit's context, then moved
4557 // into the function declaration's context afterward.
4559
4560 Error Err = Error::success();
4561 auto ToDeclName = importChecked(Err, D->getDeclName());
4562 auto ToLocation = importChecked(Err, D->getLocation());
4563 auto ToType = importChecked(Err, D->getType());
4564 if (Err)
4565 return std::move(Err);
4566
4567 // Create the imported parameter.
4568 ImplicitParamDecl *ToParm = nullptr;
4569 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4570 ToLocation, ToDeclName.getAsIdentifierInfo(),
4571 ToType, D->getParameterKind()))
4572 return ToParm;
4573 return ToParm;
4574}
4575
4577 const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4580 FromParam->getExplicitObjectParamThisLoc());
4581 ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4582
4583 if (FromParam->hasUninstantiatedDefaultArg()) {
4584 if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4585 ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4586 else
4587 return ToDefArgOrErr.takeError();
4588 } else if (FromParam->hasUnparsedDefaultArg()) {
4589 ToParam->setUnparsedDefaultArg();
4590 } else if (FromParam->hasDefaultArg()) {
4591 if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4592 ToParam->setDefaultArg(*ToDefArgOrErr);
4593 else
4594 return ToDefArgOrErr.takeError();
4595 }
4596
4597 return Error::success();
4598}
4599
4602 Error Err = Error::success();
4603 CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4604 ConstructorUsingShadowDecl *ToShadow =
4605 importChecked(Err, From.getShadowDecl());
4606 if (Err)
4607 return std::move(Err);
4608 return InheritedConstructor(ToShadow, ToBaseCtor);
4609}
4610
4612 // Parameters are created in the translation unit's context, then moved
4613 // into the function declaration's context afterward.
4615
4616 Error Err = Error::success();
4617 auto ToDeclName = importChecked(Err, D->getDeclName());
4618 auto ToLocation = importChecked(Err, D->getLocation());
4619 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4620 auto ToType = importChecked(Err, D->getType());
4621 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4622 if (Err)
4623 return std::move(Err);
4624
4625 ParmVarDecl *ToParm;
4626 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4627 ToInnerLocStart, ToLocation,
4628 ToDeclName.getAsIdentifierInfo(), ToType,
4629 ToTypeSourceInfo, D->getStorageClass(),
4630 /*DefaultArg*/ nullptr))
4631 return ToParm;
4632
4633 // Set the default argument. It should be no problem if it was already done.
4634 // Do not import the default expression before GetImportedOrCreateDecl call
4635 // to avoid possible infinite import loop because circular dependency.
4636 if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4637 return std::move(Err);
4638
4639 if (D->isObjCMethodParameter()) {
4642 } else {
4645 }
4646
4647 return ToParm;
4648}
4649
4651 // Import the major distinguishing characteristics of a method.
4652 DeclContext *DC, *LexicalDC;
4653 DeclarationName Name;
4654 SourceLocation Loc;
4655 NamedDecl *ToD;
4656 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4657 return std::move(Err);
4658 if (ToD)
4659 return ToD;
4660
4661 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4662 for (auto *FoundDecl : FoundDecls) {
4663 if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
4664 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
4665 continue;
4666
4667 // Check return types.
4668 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
4669 FoundMethod->getReturnType())) {
4670 Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
4671 << D->isInstanceMethod() << Name << D->getReturnType()
4672 << FoundMethod->getReturnType();
4673 Importer.ToDiag(FoundMethod->getLocation(),
4674 diag::note_odr_objc_method_here)
4675 << D->isInstanceMethod() << Name;
4676
4677 return make_error<ASTImportError>(ASTImportError::NameConflict);
4678 }
4679
4680 // Check the number of parameters.
4681 if (D->param_size() != FoundMethod->param_size()) {
4682 Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
4683 << D->isInstanceMethod() << Name
4684 << D->param_size() << FoundMethod->param_size();
4685 Importer.ToDiag(FoundMethod->getLocation(),
4686 diag::note_odr_objc_method_here)
4687 << D->isInstanceMethod() << Name;
4688
4689 return make_error<ASTImportError>(ASTImportError::NameConflict);
4690 }
4691
4692 // Check parameter types.
4694 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
4695 P != PEnd; ++P, ++FoundP) {
4696 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
4697 (*FoundP)->getType())) {
4698 Importer.FromDiag((*P)->getLocation(),
4699 diag::warn_odr_objc_method_param_type_inconsistent)
4700 << D->isInstanceMethod() << Name
4701 << (*P)->getType() << (*FoundP)->getType();
4702 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
4703 << (*FoundP)->getType();
4704
4705 return make_error<ASTImportError>(ASTImportError::NameConflict);
4706 }
4707 }
4708
4709 // Check variadic/non-variadic.
4710 // Check the number of parameters.
4711 if (D->isVariadic() != FoundMethod->isVariadic()) {
4712 Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
4713 << D->isInstanceMethod() << Name;
4714 Importer.ToDiag(FoundMethod->getLocation(),
4715 diag::note_odr_objc_method_here)
4716 << D->isInstanceMethod() << Name;
4717
4718 return make_error<ASTImportError>(ASTImportError::NameConflict);
4719 }
4720
4721 // FIXME: Any other bits we need to merge?
4722 return Importer.MapImported(D, FoundMethod);
4723 }
4724 }
4725
4726 Error Err = Error::success();
4727 auto ToEndLoc = importChecked(Err, D->getEndLoc());
4728 auto ToReturnType = importChecked(Err, D->getReturnType());
4729 auto ToReturnTypeSourceInfo =
4731 if (Err)
4732 return std::move(Err);
4733
4734 ObjCMethodDecl *ToMethod;
4735 if (GetImportedOrCreateDecl(
4736 ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
4737 Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
4741 return ToMethod;
4742
4743 // FIXME: When we decide to merge method definitions, we'll need to
4744 // deal with implicit parameters.
4745
4746 // Import the parameters
4748 for (auto *FromP : D->parameters()) {
4749 if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
4750 ToParams.push_back(*ToPOrErr);
4751 else
4752 return ToPOrErr.takeError();
4753 }
4754
4755 // Set the parameters.
4756 for (auto *ToParam : ToParams) {
4757 ToParam->setOwningFunction(ToMethod);
4758 ToMethod->addDeclInternal(ToParam);
4759 }
4760
4762 D->getSelectorLocs(FromSelLocs);
4763 SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
4764 if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
4765 return std::move(Err);
4766
4767 ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
4768
4769 ToMethod->setLexicalDeclContext(LexicalDC);
4770 LexicalDC->addDeclInternal(ToMethod);
4771
4772 // Implicit params are declared when Sema encounters the definition but this
4773 // never happens when the method is imported. Manually declare the implicit
4774 // params now that the MethodDecl knows its class interface.
4775 if (D->getSelfDecl())
4776 ToMethod->createImplicitParams(Importer.getToContext(),
4777 ToMethod->getClassInterface());
4778
4779 return ToMethod;
4780}
4781
4783 // Import the major distinguishing characteristics of a category.
4784 DeclContext *DC, *LexicalDC;
4785 DeclarationName Name;
4786 SourceLocation Loc;
4787 NamedDecl *ToD;
4788 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4789 return std::move(Err);
4790 if (ToD)
4791 return ToD;
4792
4793 Error Err = Error::success();
4794 auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
4795 auto ToLocation = importChecked(Err, D->getLocation());
4796 auto ToColonLoc = importChecked(Err, D->getColonLoc());
4797 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4798 if (Err)
4799 return std::move(Err);
4800
4802 if (GetImportedOrCreateDecl(
4803 Result, D, Importer.getToContext(), DC, D->getVariance(),
4804 ToVarianceLoc, D->getIndex(),
4805 ToLocation, Name.getAsIdentifierInfo(),
4806 ToColonLoc, ToTypeSourceInfo))
4807 return Result;
4808
4809 // Only import 'ObjCTypeParamType' after the decl is created.
4810 auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
4811 if (Err)
4812 return std::move(Err);
4813 Result->setTypeForDecl(ToTypeForDecl);
4814 Result->setLexicalDeclContext(LexicalDC);
4815 return Result;
4816}
4817
4819 // Import the major distinguishing characteristics of a category.
4820 DeclContext *DC, *LexicalDC;
4821 DeclarationName Name;
4822 SourceLocation Loc;
4823 NamedDecl *ToD;
4824 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4825 return std::move(Err);
4826 if (ToD)
4827 return ToD;
4828
4829 ObjCInterfaceDecl *ToInterface;
4830 if (Error Err = importInto(ToInterface, D->getClassInterface()))
4831 return std::move(Err);
4832
4833 // Determine if we've already encountered this category.
4834 ObjCCategoryDecl *MergeWithCategory
4835 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
4836 ObjCCategoryDecl *ToCategory = MergeWithCategory;
4837 if (!ToCategory) {
4838
4839 Error Err = Error::success();
4840 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
4841 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
4842 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
4843 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
4844 if (Err)
4845 return std::move(Err);
4846
4847 if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
4848 ToAtStartLoc, Loc,
4849 ToCategoryNameLoc,
4850 Name.getAsIdentifierInfo(), ToInterface,
4851 /*TypeParamList=*/nullptr,
4852 ToIvarLBraceLoc,
4853 ToIvarRBraceLoc))
4854 return ToCategory;
4855
4856 ToCategory->setLexicalDeclContext(LexicalDC);
4857 LexicalDC->addDeclInternal(ToCategory);
4858 // Import the type parameter list after MapImported, to avoid
4859 // loops when bringing in their DeclContext.
4860 if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
4861 ToCategory->setTypeParamList(*PListOrErr);
4862 else
4863 return PListOrErr.takeError();
4864
4865 // Import protocols
4867 SmallVector<SourceLocation, 4> ProtocolLocs;
4869 = D->protocol_loc_begin();
4871 FromProtoEnd = D->protocol_end();
4872 FromProto != FromProtoEnd;
4873 ++FromProto, ++FromProtoLoc) {
4874 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
4875 Protocols.push_back(*ToProtoOrErr);
4876 else
4877 return ToProtoOrErr.takeError();
4878
4879 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
4880 ProtocolLocs.push_back(*ToProtoLocOrErr);
4881 else
4882 return ToProtoLocOrErr.takeError();
4883 }
4884
4885 // FIXME: If we're merging, make sure that the protocol list is the same.
4886 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
4887 ProtocolLocs.data(), Importer.getToContext());
4888
4889 } else {
4890 Importer.MapImported(D, ToCategory);
4891 }
4892
4893 // Import all of the members of this category.
4894 if (Error Err = ImportDeclContext(D))
4895 return std::move(Err);
4896
4897 // If we have an implementation, import it as well.
4898 if (D->getImplementation()) {
4899 if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
4900 import(D->getImplementation()))
4901 ToCategory->setImplementation(*ToImplOrErr);
4902 else
4903 return ToImplOrErr.takeError();
4904 }
4905
4906 return ToCategory;
4907}
4908
4911 if (To->getDefinition()) {
4913 if (Error Err = ImportDeclContext(From))
4914 return Err;
4915 return Error::success();
4916 }
4917
4918 // Start the protocol definition
4919 To->startDefinition();
4920
4921 // Import protocols
4923 SmallVector<SourceLocation, 4> ProtocolLocs;
4925 From->protocol_loc_begin();
4926 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
4927 FromProtoEnd = From->protocol_end();
4928 FromProto != FromProtoEnd;
4929 ++FromProto, ++FromProtoLoc) {
4930 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
4931 Protocols.push_back(*ToProtoOrErr);
4932 else
4933 return ToProtoOrErr.takeError();
4934
4935 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
4936 ProtocolLocs.push_back(*ToProtoLocOrErr);
4937 else
4938 return ToProtoLocOrErr.takeError();
4939
4940 }
4941
4942 // FIXME: If we're merging, make sure that the protocol list is the same.
4943 To->setProtocolList(Protocols.data(), Protocols.size(),
4944 ProtocolLocs.data(), Importer.getToContext());
4945
4946 if (shouldForceImportDeclContext(Kind)) {
4947 // Import all of the members of this protocol.
4948 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
4949 return Err;
4950 }
4951 return Error::success();
4952}
4953
4955 // If this protocol has a definition in the translation unit we're coming
4956 // from, but this particular declaration is not that definition, import the
4957 // definition and map to that.
4959 if (Definition && Definition != D) {
4960 if (ExpectedDecl ImportedDefOrErr = import(Definition))
4961 return Importer.MapImported(D, *ImportedDefOrErr);
4962 else
4963 return ImportedDefOrErr.takeError();
4964 }
4965
4966 // Import the major distinguishing characteristics of a protocol.
4967 DeclContext *DC, *LexicalDC;
4968 DeclarationName Name;
4969 SourceLocation Loc;
4970 NamedDecl *ToD;
4971 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4972 return std::move(Err);
4973 if (ToD)
4974 return ToD;
4975
4976 ObjCProtocolDecl *MergeWithProtocol = nullptr;
4977 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4978 for (auto *FoundDecl : FoundDecls) {
4980 continue;
4981
4982 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
4983 break;
4984 }
4985
4986 ObjCProtocolDecl *ToProto = MergeWithProtocol;
4987 if (!ToProto) {
4988 auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
4989 if (!ToAtBeginLocOrErr)
4990 return ToAtBeginLocOrErr.takeError();
4991
4992 if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
4993 Name.getAsIdentifierInfo(), Loc,
4994 *ToAtBeginLocOrErr,
4995 /*PrevDecl=*/nullptr))
4996 return ToProto;
4997 ToProto->setLexicalDeclContext(LexicalDC);
4998 LexicalDC->addDeclInternal(ToProto);
4999 }
5000
5001 Importer.MapImported(D, ToProto);
5002
5004 if (Error Err = ImportDefinition(D, ToProto))
5005 return std::move(Err);
5006
5007 return ToProto;
5008}
5009
5011 DeclContext *DC, *LexicalDC;
5012 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5013 return std::move(Err);
5014
5015 ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5016 if (!ExternLocOrErr)
5017 return ExternLocOrErr.takeError();
5018
5019 ExpectedSLoc LangLocOrErr = import(D->getLocation());
5020 if (!LangLocOrErr)
5021 return LangLocOrErr.takeError();
5022
5023 bool HasBraces = D->hasBraces();
5024
5025 LinkageSpecDecl *ToLinkageSpec;
5026 if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5027 *ExternLocOrErr, *LangLocOrErr,
5028 D->getLanguage(), HasBraces))
5029 return ToLinkageSpec;
5030
5031 if (HasBraces) {
5032 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5033 if (!RBraceLocOrErr)
5034 return RBraceLocOrErr.takeError();
5035 ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5036 }
5037
5038 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5039 LexicalDC->addDeclInternal(ToLinkageSpec);
5040
5041 return ToLinkageSpec;
5042}
5043
5045 BaseUsingDecl *ToSI) {
5046 for (UsingShadowDecl *FromShadow : D->shadows()) {
5047 if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5048 ToSI->addShadowDecl(*ToShadowOrErr);
5049 else
5050 // FIXME: We return error here but the definition is already created
5051 // and available with lookups. How to fix this?..
5052 return ToShadowOrErr.takeError();
5053 }
5054 return ToSI;
5055}
5056
5058 DeclContext *DC, *LexicalDC;
5059 DeclarationName Name;
5060 SourceLocation Loc;
5061 NamedDecl *ToD = nullptr;
5062 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5063 return std::move(Err);
5064 if (ToD)
5065 return ToD;
5066
5067 Error Err = Error::success();
5068 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5069 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5070 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5071 if (Err)
5072 return std::move(Err);
5073
5074 DeclarationNameInfo NameInfo(Name, ToLoc);
5075 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5076 return std::move(Err);
5077
5078 UsingDecl *ToUsing;
5079 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5080 ToUsingLoc, ToQualifierLoc, NameInfo,
5081 D->hasTypename()))
5082 return ToUsing;
5083
5084 ToUsing->setLexicalDeclContext(LexicalDC);
5085 LexicalDC->addDeclInternal(ToUsing);
5086
5087 if (NamedDecl *FromPattern =
5089 if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5091 ToUsing, *ToPatternOrErr);
5092 else
5093 return ToPatternOrErr.takeError();
5094 }
5095
5096 return ImportUsingShadowDecls(D, ToUsing);
5097}
5098
5100 DeclContext *DC, *LexicalDC;
5101 DeclarationName Name;
5102 SourceLocation Loc;
5103 NamedDecl *ToD = nullptr;
5104 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5105 return std::move(Err);
5106 if (ToD)
5107 return ToD;
5108
5109 Error Err = Error::success();
5110 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5111 auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5112 auto ToNameLoc = importChecked(Err, D->getLocation());
5113 auto *ToEnumType = importChecked(Err, D->getEnumType());
5114 if (Err)
5115 return std::move(Err);
5116
5117 UsingEnumDecl *ToUsingEnum;
5118 if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5119 ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5120 return ToUsingEnum;
5121
5122 ToUsingEnum->setLexicalDeclContext(LexicalDC);
5123 LexicalDC->addDeclInternal(ToUsingEnum);
5124
5125 if (UsingEnumDecl *FromPattern =
5127 if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5128 Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5129 *ToPatternOrErr);
5130 else
5131 return ToPatternOrErr.takeError();
5132 }
5133
5134 return ImportUsingShadowDecls(D, ToUsingEnum);
5135}
5136
5138 DeclContext *DC, *LexicalDC;
5139 DeclarationName Name;
5140 SourceLocation Loc;
5141 NamedDecl *ToD = nullptr;
5142 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5143 return std::move(Err);
5144 if (ToD)
5145 return ToD;
5146
5147 Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5148 if (!ToIntroducerOrErr)
5149 return ToIntroducerOrErr.takeError();
5150
5151 Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5152 if (!ToTargetOrErr)
5153 return ToTargetOrErr.takeError();
5154
5155 UsingShadowDecl *ToShadow;
5156 if (auto *FromConstructorUsingShadow =
5157 dyn_cast<ConstructorUsingShadowDecl>(D)) {
5158 Error Err = Error::success();
5160 Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5161 if (Err)
5162 return std::move(Err);
5163 // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5164 // is really the "NominatedBaseClassShadowDecl" value if it exists
5165 // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5166 // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5167 // get the correct values.
5168 if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5169 ToShadow, D, Importer.getToContext(), DC, Loc,
5170 cast<UsingDecl>(*ToIntroducerOrErr),
5171 Nominated ? Nominated : *ToTargetOrErr,
5172 FromConstructorUsingShadow->constructsVirtualBase()))
5173 return ToShadow;
5174 } else {
5175 if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5176 Name, *ToIntroducerOrErr, *ToTargetOrErr))
5177 return ToShadow;
5178 }
5179
5180 ToShadow->setLexicalDeclContext(LexicalDC);
5181 ToShadow->setAccess(D->getAccess());
5182
5183 if (UsingShadowDecl *FromPattern =
5185 if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5187 ToShadow, *ToPatternOrErr);
5188 else
5189 // FIXME: We return error here but the definition is already created
5190 // and available with lookups. How to fix this?..
5191 return ToPatternOrErr.takeError();
5192 }
5193
5194 LexicalDC->addDeclInternal(ToShadow);
5195
5196 return ToShadow;
5197}
5198
5200 DeclContext *DC, *LexicalDC;
5201 DeclarationName Name;
5202 SourceLocation Loc;
5203 NamedDecl *ToD = nullptr;
5204 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5205 return std::move(Err);
5206 if (ToD)
5207 return ToD;
5208
5209 auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5210 if (!ToComAncestorOrErr)
5211 return ToComAncestorOrErr.takeError();
5212
5213 Error Err = Error::success();
5214 auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5215 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5216 auto ToNamespaceKeyLocation =
5218 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5219 auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5220 if (Err)
5221 return std::move(Err);
5222
5223 UsingDirectiveDecl *ToUsingDir;
5224 if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5225 ToUsingLoc,
5226 ToNamespaceKeyLocation,
5227 ToQualifierLoc,
5228 ToIdentLocation,
5229 ToNominatedNamespace, *ToComAncestorOrErr))
5230 return ToUsingDir;
5231
5232 ToUsingDir->setLexicalDeclContext(LexicalDC);
5233 LexicalDC->addDeclInternal(ToUsingDir);
5234
5235 return ToUsingDir;
5236}
5237
5239 DeclContext *DC, *LexicalDC;
5240 DeclarationName Name;
5241 SourceLocation Loc;
5242 NamedDecl *ToD = nullptr;
5243 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5244 return std::move(Err);
5245 if (ToD)
5246 return ToD;
5247
5248 auto ToInstantiatedFromUsingOrErr =
5249 Importer.Import(D->getInstantiatedFromUsingDecl());
5250 if (!ToInstantiatedFromUsingOrErr)
5251 return ToInstantiatedFromUsingOrErr.takeError();
5252 SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5253 if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5254 return std::move(Err);
5255
5256 UsingPackDecl *ToUsingPack;
5257 if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5258 cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5259 Expansions))
5260 return ToUsingPack;
5261
5262 addDeclToContexts(D, ToUsingPack);
5263
5264 return ToUsingPack;
5265}
5266
5269 DeclContext *DC, *LexicalDC;
5270 DeclarationName Name;
5271 SourceLocation Loc;
5272 NamedDecl *ToD = nullptr;
5273 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5274 return std::move(Err);
5275 if (ToD)
5276 return ToD;
5277
5278 Error Err = Error::success();
5279 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5280 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5281 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5282 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5283 if (Err)
5284 return std::move(Err);
5285
5286 DeclarationNameInfo NameInfo(Name, ToLoc);
5287 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5288 return std::move(Err);
5289
5290 UnresolvedUsingValueDecl *ToUsingValue;
5291 if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5292 ToUsingLoc, ToQualifierLoc, NameInfo,
5293 ToEllipsisLoc))
5294 return ToUsingValue;
5295
5296 ToUsingValue->setAccess(D->getAccess());
5297 ToUsingValue->setLexicalDeclContext(LexicalDC);
5298 LexicalDC->addDeclInternal(ToUsingValue);
5299
5300 return ToUsingValue;
5301}
5302
5305 DeclContext *DC, *LexicalDC;
5306 DeclarationName Name;
5307 SourceLocation Loc;
5308 NamedDecl *ToD = nullptr;
5309 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5310 return std::move(Err);
5311 if (ToD)
5312 return ToD;
5313
5314 Error Err = Error::success();
5315 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5316 auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5317 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5318 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5319 if (Err)
5320 return std::move(Err);
5321
5323 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5324 ToUsingLoc, ToTypenameLoc,
5325 ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5326 return ToUsing;
5327
5328 ToUsing->setAccess(D->getAccess());
5329 ToUsing->setLexicalDeclContext(LexicalDC);
5330 LexicalDC->addDeclInternal(ToUsing);
5331
5332 return ToUsing;
5333}
5334
5336 Decl* ToD = nullptr;
5337 switch (D->getBuiltinTemplateKind()) {
5339 ToD = Importer.getToContext().getMakeIntegerSeqDecl();
5340 break;
5342 ToD = Importer.getToContext().getTypePackElementDecl();
5343 break;
5344 }
5345 assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5346 Importer.MapImported(D, ToD);
5347 return ToD;
5348}
5349
5352 if (To->getDefinition()) {
5353 // Check consistency of superclass.
5354 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5355 if (FromSuper) {
5356 if (auto FromSuperOrErr = import(FromSuper))
5357 FromSuper = *FromSuperOrErr;
5358 else
5359 return FromSuperOrErr.takeError();
5360 }
5361
5362 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5363 if ((bool)FromSuper != (bool)ToSuper ||
5364 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5365 Importer.ToDiag(To->getLocation(),
5366 diag::warn_odr_objc_superclass_inconsistent)
5367 << To->getDeclName();
5368 if (ToSuper)
5369 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5370 << To->getSuperClass()->getDeclName();
5371 else
5372 Importer.ToDiag(To->getLocation(),
5373 diag::note_odr_objc_missing_superclass);
5374 if (From->getSuperClass())
5375 Importer.FromDiag(From->getSuperClassLoc(),
5376 diag::note_odr_objc_superclass)
5377 << From->getSuperClass()->getDeclName();
5378 else
5379 Importer.FromDiag(From->getLocation(),
5380 diag::note_odr_objc_missing_superclass);
5381 }
5382
5384 if (Error Err = ImportDeclContext(From))
5385 return Err;
5386 return Error::success();
5387 }
5388
5389 // Start the definition.
5390 To->startDefinition();
5391
5392 // If this class has a superclass, import it.
5393 if (From->getSuperClass()) {
5394 if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5395 To->setSuperClass(*SuperTInfoOrErr);
5396 else
5397 return SuperTInfoOrErr.takeError();
5398 }
5399
5400 // Import protocols
5402 SmallVector<SourceLocation, 4> ProtocolLocs;
5404 From->protocol_loc_begin();
5405
5407 FromProtoEnd = From->protocol_end();
5408 FromProto != FromProtoEnd;
5409 ++FromProto, ++FromProtoLoc) {
5410 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5411 Protocols.push_back(*ToProtoOrErr);
5412 else
5413 return ToProtoOrErr.takeError();
5414
5415 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5416 ProtocolLocs.push_back(*ToProtoLocOrErr);
5417 else
5418 return ToProtoLocOrErr.takeError();
5419
5420 }
5421
5422 // FIXME: If we're merging, make sure that the protocol list is the same.
5423 To->setProtocolList(Protocols.data(), Protocols.size(),
5424 ProtocolLocs.data(), Importer.getToContext());
5425
5426 // Import categories. When the categories themselves are imported, they'll
5427 // hook themselves into this interface.
5428 for (auto *Cat : From->known_categories()) {
5429 auto ToCatOrErr = import(Cat);
5430 if (!ToCatOrErr)
5431 return ToCatOrErr.takeError();
5432 }
5433
5434 // If we have an @implementation, import it as well.
5435 if (From->getImplementation()) {
5436 if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5437 import(From->getImplementation()))
5438 To->setImplementation(*ToImplOrErr);
5439 else
5440 return ToImplOrErr.takeError();
5441 }
5442
5443 // Import all of the members of this class.
5444 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5445 return Err;
5446
5447 return Error::success();
5448}
5449
5452 if (!list)
5453 return nullptr;
5454
5456 for (auto *fromTypeParam : *list) {
5457 if (auto toTypeParamOrErr = import(fromTypeParam))
5458 toTypeParams.push_back(*toTypeParamOrErr);
5459 else
5460 return toTypeParamOrErr.takeError();
5461 }
5462
5463 auto LAngleLocOrErr = import(list->getLAngleLoc());
5464 if (!LAngleLocOrErr)
5465 return LAngleLocOrErr.takeError();
5466
5467 auto RAngleLocOrErr = import(list->getRAngleLoc());
5468 if (!RAngleLocOrErr)
5469 return RAngleLocOrErr.takeError();
5470
5471 return ObjCTypeParamList::create(Importer.getToContext(),
5472 *LAngleLocOrErr,
5473 toTypeParams,
5474 *RAngleLocOrErr);
5475}
5476
5478 // If this class has a definition in the translation unit we're coming from,
5479 // but this particular declaration is not that definition, import the
5480 // definition and map to that.
5482 if (Definition && Definition != D) {
5483 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5484 return Importer.MapImported(D, *ImportedDefOrErr);
5485 else
5486 return ImportedDefOrErr.takeError();
5487 }
5488
5489 // Import the major distinguishing characteristics of an @interface.
5490 DeclContext *DC, *LexicalDC;
5491 DeclarationName Name;
5492 SourceLocation Loc;
5493 NamedDecl *ToD;
5494 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5495 return std::move(Err);
5496 if (ToD)
5497 return ToD;
5498
5499 // Look for an existing interface with the same name.
5500 ObjCInterfaceDecl *MergeWithIface = nullptr;
5501 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5502 for (auto *FoundDecl : FoundDecls) {
5504 continue;
5505
5506 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5507 break;
5508 }
5509
5510 // Create an interface declaration, if one does not already exist.
5511 ObjCInterfaceDecl *ToIface = MergeWithIface;
5512 if (!ToIface) {
5513 ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5514 if (!AtBeginLocOrErr)
5515 return AtBeginLocOrErr.takeError();
5516
5517 if (GetImportedOrCreateDecl(
5518 ToIface, D, Importer.getToContext(), DC,
5519 *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5520 /*TypeParamList=*/nullptr,
5521 /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5522 return ToIface;
5523 ToIface->setLexicalDeclContext(LexicalDC);
5524 LexicalDC->addDeclInternal(ToIface);
5525 }
5526 Importer.MapImported(D, ToIface);
5527 // Import the type parameter list after MapImported, to avoid
5528 // loops when bringing in their DeclContext.
5529 if (auto ToPListOrErr =
5531 ToIface->setTypeParamList(*ToPListOrErr);
5532 else
5533 return ToPListOrErr.takeError();
5534
5536 if (Error Err = ImportDefinition(D, ToIface))
5537 return std::move(Err);
5538
5539 return ToIface;
5540}
5541
5545 if (Error Err = importInto(Category, D->getCategoryDecl()))
5546 return std::move(Err);
5547
5548 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5549 if (!ToImpl) {
5550 DeclContext *DC, *LexicalDC;
5551 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5552 return std::move(Err);
5553
5554 Error Err = Error::success();
5555 auto ToLocation = importChecked(Err, D->getLocation());
5556 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5557 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5558 if (Err)
5559 return std::move(Err);
5560
5561 if (GetImportedOrCreateDecl(
5562 ToImpl, D, Importer.getToContext(), DC,
5563 Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5564 ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5565 return ToImpl;
5566
5567 ToImpl->setLexicalDeclContext(LexicalDC);
5568 LexicalDC->addDeclInternal(ToImpl);
5569 Category->setImplementation(ToImpl);
5570 }
5571
5572 Importer.MapImported(D, ToImpl);
5573 if (Error Err = ImportDeclContext(D))
5574 return std::move(Err);
5575
5576 return ToImpl;
5577}
5578
5581 // Find the corresponding interface.
5582 ObjCInterfaceDecl *Iface;
5583 if (Error Err = importInto(Iface, D->getClassInterface()))
5584 return std::move(Err);
5585
5586 // Import the superclass, if any.
5587 ObjCInterfaceDecl *Super;
5588 if (Error Err = importInto(Super, D->getSuperClass()))
5589 return std::move(Err);
5590
5592 if (!Impl) {
5593 // We haven't imported an implementation yet. Create a new @implementation
5594 // now.
5595 DeclContext *DC, *LexicalDC;
5596 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5597 return std::move(Err);
5598
5599 Error Err = Error::success();
5600 auto ToLocation = importChecked(Err, D->getLocation());
5601 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5602 auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5603 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5604 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5605 if (Err)
5606 return std::move(Err);
5607
5608 if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5609 DC, Iface, Super,
5610 ToLocation,
5611 ToAtStartLoc,
5612 ToSuperClassLoc,
5613 ToIvarLBraceLoc,
5614 ToIvarRBraceLoc))
5615 return Impl;
5616
5617 Impl->setLexicalDeclContext(LexicalDC);
5618
5619 // Associate the implementation with the class it implements.
5620 Iface->setImplementation(Impl);
5621 Importer.MapImported(D, Iface->getImplementation());
5622 } else {
5623 Importer.MapImported(D, Iface->getImplementation());
5624
5625 // Verify that the existing @implementation has the same superclass.
5626 if ((Super && !Impl->getSuperClass()) ||
5627 (!Super && Impl->getSuperClass()) ||
5628 (Super && Impl->getSuperClass() &&
5630 Impl->getSuperClass()))) {
5631 Importer.ToDiag(Impl->getLocation(),
5632 diag::warn_odr_objc_superclass_inconsistent)
5633 << Iface->getDeclName();
5634 // FIXME: It would be nice to have the location of the superclass
5635 // below.
5636 if (Impl->getSuperClass())
5637 Importer.ToDiag(Impl->getLocation(),
5638 diag::note_odr_objc_superclass)
5639 << Impl->getSuperClass()->getDeclName();
5640 else
5641 Importer.ToDiag(Impl->getLocation(),
5642 diag::note_odr_objc_missing_superclass);
5643 if (D->getSuperClass())
5644 Importer.FromDiag(D->getLocation(),
5645 diag::note_odr_objc_superclass)
5646 << D->getSuperClass()->getDeclName();
5647 else
5648 Importer.FromDiag(D->getLocation(),
5649 diag::note_odr_objc_missing_superclass);
5650
5651 return make_error<ASTImportError>(ASTImportError::NameConflict);
5652 }
5653 }
5654
5655 // Import all of the members of this @implementation.
5656 if (Error Err = ImportDeclContext(D))
5657 return std::move(Err);
5658
5659 return Impl;
5660}
5661
5663 // Import the major distinguishing characteristics of an @property.
5664 DeclContext *DC, *LexicalDC;
5665 DeclarationName Name;
5666 SourceLocation Loc;
5667 NamedDecl *ToD;
5668 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5669 return std::move(Err);
5670 if (ToD)
5671 return ToD;
5672
5673 // Check whether we have already imported this property.
5674 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5675 for (auto *FoundDecl : FoundDecls) {
5676 if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
5677 // Instance and class properties can share the same name but are different
5678 // declarations.
5679 if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
5680 continue;
5681
5682 // Check property types.
5683 if (!Importer.IsStructurallyEquivalent(D->getType(),
5684 FoundProp->getType())) {
5685 Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
5686 << Name << D->getType() << FoundProp->getType();
5687 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
5688 << FoundProp->getType();
5689
5690 return make_error<ASTImportError>(ASTImportError::NameConflict);
5691 }
5692
5693 // FIXME: Check property attributes, getters, setters, etc.?
5694
5695 // Consider these properties to be equivalent.
5696 Importer.MapImported(D, FoundProp);
5697 return FoundProp;
5698 }
5699 }
5700
5701 Error Err = Error::success();
5702 auto ToType = importChecked(Err, D->getType());
5703 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5704 auto ToAtLoc = importChecked(Err, D->getAtLoc());
5705 auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
5706 if (Err)
5707 return std::move(Err);
5708
5709 // Create the new property.
5710 ObjCPropertyDecl *ToProperty;
5711 if (GetImportedOrCreateDecl(
5712 ToProperty, D, Importer.getToContext(), DC, Loc,
5713 Name.getAsIdentifierInfo(), ToAtLoc,
5714 ToLParenLoc, ToType,
5715 ToTypeSourceInfo, D->getPropertyImplementation()))
5716 return ToProperty;
5717
5718 auto ToGetterName = importChecked(Err, D->getGetterName());
5719 auto ToSetterName = importChecked(Err, D->getSetterName());
5720 auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
5721 auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
5722 auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
5723 auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
5724 auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
5725 if (Err)
5726 return std::move(Err);
5727
5728 ToProperty->setLexicalDeclContext(LexicalDC);
5729 LexicalDC->addDeclInternal(ToProperty);
5730
5734 ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
5735 ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
5736 ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
5737 ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
5738 ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
5739 return ToProperty;
5740}
5741
5745 if (Error Err = importInto(Property, D->getPropertyDecl()))
5746 return std::move(Err);
5747
5748 DeclContext *DC, *LexicalDC;
5749 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5750 return std::move(Err);
5751
5752 auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
5753
5754 // Import the ivar (for an @synthesize).
5755 ObjCIvarDecl *Ivar = nullptr;
5756 if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
5757 return std::move(Err);
5758
5759 ObjCPropertyImplDecl *ToImpl
5760 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
5761 Property->getQueryKind());
5762 if (!ToImpl) {
5763
5764 Error Err = Error::success();
5765 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
5766 auto ToLocation = importChecked(Err, D->getLocation());
5767 auto ToPropertyIvarDeclLoc =
5769 if (Err)
5770 return std::move(Err);
5771
5772 if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
5773 ToBeginLoc,
5774 ToLocation, Property,
5775 D->getPropertyImplementation(), Ivar,
5776 ToPropertyIvarDeclLoc))
5777 return ToImpl;
5778
5779 ToImpl->setLexicalDeclContext(LexicalDC);
5780 LexicalDC->addDeclInternal(ToImpl);
5781 } else {
5782 // Check that we have the same kind of property implementation (@synthesize
5783 // vs. @dynamic).
5785 Importer.ToDiag(ToImpl->getLocation(),
5786 diag::warn_odr_objc_property_impl_kind_inconsistent)
5787 << Property->getDeclName()
5788 << (ToImpl->getPropertyImplementation()
5790 Importer.FromDiag(D->getLocation(),
5791 diag::note_odr_objc_property_impl_kind)
5792 << D->getPropertyDecl()->getDeclName()
5794
5795 return make_error<ASTImportError>(ASTImportError::NameConflict);
5796 }
5797
5798 // For @synthesize, check that we have the same
5800 Ivar != ToImpl->getPropertyIvarDecl()) {
5801 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
5802 diag::warn_odr_objc_synthesize_ivar_inconsistent)
5803 << Property->getDeclName()
5804 << ToImpl->getPropertyIvarDecl()->getDeclName()
5805 << Ivar->getDeclName();
5806 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
5807 diag::note_odr_objc_synthesize_ivar_here)
5809
5810 return make_error<ASTImportError>(ASTImportError::NameConflict);
5811 }
5812
5813 // Merge the existing implementation with the new implementation.
5814 Importer.MapImported(D, ToImpl);
5815 }
5816
5817 return ToImpl;
5818}
5819
5822 // For template arguments, we adopt the translation unit as our declaration
5823 // context. This context will be fixed when the actual template declaration
5824 // is created.
5825
5826 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
5827 if (!BeginLocOrErr)
5828 return BeginLocOrErr.takeError();
5829
5830 ExpectedSLoc LocationOrErr = import(D->getLocation());
5831 if (!LocationOrErr)
5832 return LocationOrErr.takeError();
5833
5834 TemplateTypeParmDecl *ToD = nullptr;
5835 if (GetImportedOrCreateDecl(
5836 ToD, D, Importer.getToContext(),
5838 *BeginLocOrErr, *LocationOrErr,
5839 D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
5841 D->hasTypeConstraint()))
5842 return ToD;
5843
5844 // Import the type-constraint
5845 if (const TypeConstraint *TC = D->getTypeConstraint()) {
5846
5847 Error Err = Error::success();
5848 auto ToConceptRef = importChecked(Err, TC->getConceptReference());
5849 auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
5850 if (Err)
5851 return std::move(Err);
5852
5853 ToD->setTypeConstraint(ToConceptRef, ToIDC);
5854 }
5855
5856 if (D->hasDefaultArgument()) {
5857 Expected<TypeSourceInfo *> ToDefaultArgOrErr =
5858 import(D->getDefaultArgumentInfo());
5859 if (!ToDefaultArgOrErr)
5860 return ToDefaultArgOrErr.takeError();
5861 ToD->setDefaultArgument(*ToDefaultArgOrErr);
5862 }
5863
5864 return ToD;
5865}
5866
5869
5870 Error Err = Error::success();
5871 auto ToDeclName = importChecked(Err, D->getDeclName());
5872 auto ToLocation = importChecked(Err, D->getLocation());
5873 auto ToType = importChecked(Err, D->getType());
5874 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5875 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
5876 if (Err)
5877 return std::move(Err);
5878
5879 NonTypeTemplateParmDecl *ToD = nullptr;
5880 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
5882 ToInnerLocStart, ToLocation, D->getDepth(),
5883 D->getPosition(),
5884 ToDeclName.getAsIdentifierInfo(), ToType,
5885 D->isParameterPack(), ToTypeSourceInfo))
5886 return ToD;
5887
5888 if (D->hasDefaultArgument()) {
5889 ExpectedExpr ToDefaultArgOrErr = import(D->getDefaultArgument());
5890 if (!ToDefaultArgOrErr)
5891 return ToDefaultArgOrErr.takeError();
5892 ToD->setDefaultArgument(*ToDefaultArgOrErr);
5893 }
5894
5895 return ToD;
5896}
5897
5900 // Import the name of this declaration.
5901 auto NameOrErr = import(D->getDeclName());
5902 if (!NameOrErr)
5903 return NameOrErr.takeError();
5904
5905 // Import the location of this declaration.
5906 ExpectedSLoc LocationOrErr = import(D->getLocation());
5907 if (!LocationOrErr)
5908 return LocationOrErr.takeError();
5909
5910 // Import template parameters.
5911 auto TemplateParamsOrErr = import(D->getTemplateParameters());
5912 if (!TemplateParamsOrErr)
5913 return TemplateParamsOrErr.takeError();
5914
5915 TemplateTemplateParmDecl *ToD = nullptr;
5916 if (GetImportedOrCreateDecl(
5917 ToD, D, Importer.getToContext(),
5918 Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
5919 D->getDepth(), D->getPosition(), D->isParameterPack(),
5920 (*NameOrErr).getAsIdentifierInfo(), *TemplateParamsOrErr))
5921 return ToD;
5922
5923 if (D->hasDefaultArgument()) {
5924 Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
5925 import(D->getDefaultArgument());
5926 if (!ToDefaultArgOrErr)
5927 return ToDefaultArgOrErr.takeError();
5928 ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
5929 }
5930
5931 return ToD;
5932}
5933
5934// Returns the definition for a (forward) declaration of a TemplateDecl, if
5935// it has any definition in the redecl chain.
5936template <typename T> static auto getTemplateDefinition(T *D) -> T * {
5937 assert(D->getTemplatedDecl() && "Should be called on templates only");
5938 auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
5939 if (!ToTemplatedDef)
5940 return nullptr;
5941 auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
5942 return cast_or_null<T>(TemplateWithDef);
5943}
5944
5946
5947 // Import the major distinguishing characteristics of this class template.
5948 DeclContext *DC, *LexicalDC;
5949 DeclarationName Name;
5950 SourceLocation Loc;
5951 NamedDecl *ToD;
5952 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5953 return std::move(Err);
5954 if (ToD)
5955 return ToD;
5956
5957 // Should check if a declaration is friend in a dependent context.
5958 // Such templates are not linked together in a declaration chain.
5959 // The ASTImporter strategy is to map existing forward declarations to
5960 // imported ones only if strictly necessary, otherwise import these as new
5961 // forward declarations. In case of the "dependent friend" declarations, new
5962 // declarations are created, but not linked in a declaration chain.
5963 auto IsDependentFriend = [](ClassTemplateDecl *TD) {
5964 return TD->getFriendObjectKind() != Decl::FOK_None &&
5966 };
5967 bool DependentFriend = IsDependentFriend(D);
5968
5969 ClassTemplateDecl *FoundByLookup = nullptr;
5970
5971 // We may already have a template of the same name; try to find and match it.
5972 if (!DC->isFunctionOrMethod()) {
5973 SmallVector<NamedDecl *, 4> ConflictingDecls;
5974 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5975 for (auto *FoundDecl : FoundDecls) {
5978 continue;
5979
5980 Decl *Found = FoundDecl;
5981 auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found);
5982 if (FoundTemplate) {
5983 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
5984 continue;
5985
5986 // FIXME: sufficient conditon for 'IgnoreTemplateParmDepth'?
5987 bool IgnoreTemplateParmDepth =
5988 (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
5990 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
5991 IgnoreTemplateParmDepth)) {
5992 if (DependentFriend || IsDependentFriend(FoundTemplate))
5993 continue;
5994
5995 ClassTemplateDecl *TemplateWithDef =
5996 getTemplateDefinition(FoundTemplate);
5997 if (D->isThisDeclarationADefinition() && TemplateWithDef)
5998 return Importer.MapImported(D, TemplateWithDef);
5999 if (!FoundByLookup)
6000 FoundByLookup = FoundTemplate;
6001 // Search in all matches because there may be multiple decl chains,
6002 // see ASTTests test ImportExistingFriendClassTemplateDef.
6003 continue;
6004 }
6005 ConflictingDecls.push_back(FoundDecl);
6006 }
6007 }
6008
6009 if (!ConflictingDecls.empty()) {
6010 ExpectedName NameOrErr = Importer.HandleNameConflict(
6011 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6012 ConflictingDecls.size());
6013 if (NameOrErr)
6014 Name = NameOrErr.get();
6015 else
6016 return NameOrErr.takeError();
6017 }
6018 }
6019
6020 CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6021
6022 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6023 if (!TemplateParamsOrErr)
6024 return TemplateParamsOrErr.takeError();
6025
6026 // Create the declaration that is being templated.
6027 CXXRecordDecl *ToTemplated;
6028 if (Error Err = importInto(ToTemplated, FromTemplated))
6029 return std::move(Err);
6030
6031 // Create the class template declaration itself.
6033 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6034 *TemplateParamsOrErr, ToTemplated))
6035 return D2;
6036
6037 ToTemplated->setDescribedClassTemplate(D2);
6038
6039 D2->setAccess(D->getAccess());
6040 D2->setLexicalDeclContext(LexicalDC);
6041
6042 addDeclToContexts(D, D2);
6043 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6044
6045 if (FoundByLookup) {
6046 auto *Recent =
6047 const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6048
6049 // It is possible that during the import of the class template definition
6050 // we start the import of a fwd friend decl of the very same class template
6051 // and we add the fwd friend decl to the lookup table. But the ToTemplated
6052 // had been created earlier and by that time the lookup could not find
6053 // anything existing, so it has no previous decl. Later, (still during the
6054 // import of the fwd friend decl) we start to import the definition again
6055 // and this time the lookup finds the previous fwd friend class template.
6056 // In this case we must set up the previous decl for the templated decl.
6057 if (!ToTemplated->getPreviousDecl()) {
6058 assert(FoundByLookup->getTemplatedDecl() &&
6059 "Found decl must have its templated decl set");
6060 CXXRecordDecl *PrevTemplated =
6061 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6062 if (ToTemplated != PrevTemplated)
6063 ToTemplated->setPreviousDecl(PrevTemplated);
6064 }
6065
6066 D2->setPreviousDecl(Recent);
6067 }
6068
6069 return D2;
6070}
6071
6074 ClassTemplateDecl *ClassTemplate;
6075 if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6076 return std::move(Err);
6077
6078 // Import the context of this declaration.
6079 DeclContext *DC, *LexicalDC;
6080 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6081 return std::move(Err);
6082
6083 // Import template arguments.
6085 if (Error Err =
6086 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6087 return std::move(Err);
6088 // Try to find an existing specialization with these template arguments and
6089 // template parameter list.
6090 void *InsertPos = nullptr;
6091 ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6093 dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6094
6095 // Import template parameters.
6096 TemplateParameterList *ToTPList = nullptr;
6097
6098 if (PartialSpec) {
6099 auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6100 if (!ToTPListOrErr)
6101 return ToTPListOrErr.takeError();
6102 ToTPList = *ToTPListOrErr;
6103 PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs,
6104 *ToTPListOrErr,
6105 InsertPos);
6106 } else
6107 PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
6108
6109 if (PrevDecl) {
6110 if (IsStructuralMatch(D, PrevDecl)) {
6111 CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6112 if (D->isThisDeclarationADefinition() && PrevDefinition) {
6113 Importer.MapImported(D, PrevDefinition);
6114 // Import those default field initializers which have been
6115 // instantiated in the "From" context, but not in the "To" context.
6116 for (auto *FromField : D->fields()) {
6117 auto ToOrErr = import(FromField);
6118 if (!ToOrErr)
6119 return ToOrErr.takeError();
6120 }
6121
6122 // Import those methods which have been instantiated in the
6123 // "From" context, but not in the "To" context.
6124 for (CXXMethodDecl *FromM : D->methods()) {
6125 auto ToOrErr = import(FromM);
6126 if (!ToOrErr)
6127 return ToOrErr.takeError();
6128 }
6129
6130 // TODO Import instantiated default arguments.
6131 // TODO Import instantiated exception specifications.
6132 //
6133 // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6134 // what else could be fused during an AST merge.
6135 return PrevDefinition;
6136 }
6137 } else { // ODR violation.
6138 // FIXME HandleNameConflict
6139 return make_error<ASTImportError>(ASTImportError::NameConflict);
6140 }
6141 }
6142
6143 // Import the location of this declaration.
6144 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6145 if (!BeginLocOrErr)
6146 return BeginLocOrErr.takeError();
6147 ExpectedSLoc IdLocOrErr = import(D->getLocation());
6148 if (!IdLocOrErr)
6149 return IdLocOrErr.takeError();
6150
6151 // Create the specialization.
6152 ClassTemplateSpecializationDecl *D2 = nullptr;
6153 if (PartialSpec) {
6154 // Import TemplateArgumentListInfo.
6155 TemplateArgumentListInfo ToTAInfo;
6156 const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten();
6157 if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo))
6158 return std::move(Err);
6159
6160 QualType CanonInjType;
6161 if (Error Err = importInto(
6162 CanonInjType, PartialSpec->getInjectedSpecializationType()))
6163 return std::move(Err);
6164 CanonInjType = CanonInjType.getCanonicalType();
6165
6166 if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6167 D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6168 *IdLocOrErr, ToTPList, ClassTemplate,
6169 llvm::ArrayRef(TemplateArgs.data(), TemplateArgs.size()), ToTAInfo,
6170 CanonInjType,
6171 cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6172 return D2;
6173
6174 // Update InsertPos, because preceding import calls may have invalidated
6175 // it by adding new specializations.
6176 auto *PartSpec2 = cast<ClassTemplatePartialSpecializationDecl>(D2);
6177 if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6178 InsertPos))
6179 // Add this partial specialization to the class template.
6180 ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
6182 import(PartialSpec->getInstantiatedFromMember()))
6183 PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6184 else
6185 return ToInstOrErr.takeError();
6186
6187 updateLookupTableForTemplateParameters(*ToTPList);
6188 } else { // Not a partial specialization.
6189 if (GetImportedOrCreateDecl(
6190 D2, D, Importer.getToContext(), D->getTagKind(), DC,
6191 *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs,
6192 PrevDecl))
6193 return D2;
6194
6195 // Update InsertPos, because preceding import calls may have invalidated
6196 // it by adding new specializations.
6197 if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos))
6198 // Add this specialization to the class template.
6199 ClassTemplate->AddSpecialization(D2, InsertPos);
6200 }
6201
6203
6204 // Set the context of this specialization/instantiation.
6205 D2->setLexicalDeclContext(LexicalDC);
6206
6207 // Add to the DC only if it was an explicit specialization/instantiation.
6209 LexicalDC->addDeclInternal(D2);
6210 }
6211
6212 if (auto BraceRangeOrErr = import(D->getBraceRange()))
6213 D2->setBraceRange(*BraceRangeOrErr);
6214 else
6215 return BraceRangeOrErr.takeError();
6216
6217 // Import the qualifier, if any.
6218 if (auto LocOrErr = import(D->getQualifierLoc()))
6219 D2->setQualifierInfo(*LocOrErr);
6220 else
6221 return LocOrErr.takeError();
6222
6223 if (auto *TSI = D->getTypeAsWritten()) {
6224 if (auto TInfoOrErr = import(TSI))
6225 D2->setTypeAsWritten(*TInfoOrErr);
6226 else
6227 return TInfoOrErr.takeError();
6228
6229 if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6230 D2->setTemplateKeywordLoc(*LocOrErr);
6231 else
6232 return LocOrErr.takeError();
6233
6234 if (auto LocOrErr = import(D->getExternLoc()))
6235 D2->setExternLoc(*LocOrErr);
6236 else
6237 return LocOrErr.takeError();
6238 }
6239
6240 if (D->getPointOfInstantiation().isValid()) {
6241 if (auto POIOrErr = import(D->getPointOfInstantiation()))
6242 D2->setPointOfInstantiation(*POIOrErr);
6243 else
6244 return POIOrErr.takeError();
6245 }
6246
6248
6249 if (auto P = D->getInstantiatedFrom()) {
6250 if (auto *CTD = P.dyn_cast<ClassTemplateDecl *>()) {
6251 if (auto CTDorErr = import(CTD))
6252 D2->setInstantiationOf(*CTDorErr);
6253 } else {
6254 auto *CTPSD = cast<ClassTemplatePartialSpecializationDecl *>(P);
6255 auto CTPSDOrErr = import(CTPSD);
6256 if (!CTPSDOrErr)
6257 return CTPSDOrErr.takeError();
6259 SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6260 for (unsigned I = 0; I < DArgs.size(); ++I) {
6261 const TemplateArgument &DArg = DArgs[I];
6262 if (auto ArgOrErr = import(DArg))
6263 D2ArgsVec[I] = *ArgOrErr;
6264 else
6265 return ArgOrErr.takeError();
6266 }
6268 *CTPSDOrErr,
6269 TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6270 }
6271 }
6272
6273 if (D->isCompleteDefinition())
6274 if (Error Err = ImportDefinition(D, D2))
6275 return std::move(Err);
6276
6277 return D2;
6278}
6279
6281 // Import the major distinguishing characteristics of this variable template.
6282 DeclContext *DC, *LexicalDC;
6283 DeclarationName Name;
6284 SourceLocation Loc;
6285 NamedDecl *ToD;
6286 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6287 return std::move(Err);
6288 if (ToD)
6289 return ToD;
6290
6291 // We may already have a template of the same name; try to find and match it.
6292 assert(!DC->isFunctionOrMethod() &&
6293 "Variable templates cannot be declared at function scope");
6294
6295 SmallVector<NamedDecl *, 4> ConflictingDecls;
6296 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6297 VarTemplateDecl *FoundByLookup = nullptr;
6298 for (auto *FoundDecl : FoundDecls) {
6300 continue;
6301
6302 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6303 // Use the templated decl, some linkage flags are set only there.
6304 if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6305 D->getTemplatedDecl()))
6306 continue;
6307 if (IsStructuralMatch(D, FoundTemplate)) {
6308 // FIXME Check for ODR error if the two definitions have
6309 // different initializers?
6310 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6311 if (D->getDeclContext()->isRecord()) {
6312 assert(FoundTemplate->getDeclContext()->isRecord() &&
6313 "Member variable template imported as non-member, "
6314 "inconsistent imported AST?");
6315 if (FoundDef)
6316 return Importer.MapImported(D, FoundDef);
6318 return Importer.MapImported(D, FoundTemplate);
6319 } else {
6320 if (FoundDef && D->isThisDeclarationADefinition())
6321 return Importer.MapImported(D, FoundDef);
6322 }
6323 FoundByLookup = FoundTemplate;
6324 break;
6325 }
6326 ConflictingDecls.push_back(FoundDecl);
6327 }
6328 }
6329
6330 if (!ConflictingDecls.empty()) {
6331 ExpectedName NameOrErr = Importer.HandleNameConflict(
6332 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6333 ConflictingDecls.size());
6334 if (NameOrErr)
6335 Name = NameOrErr.get();
6336 else
6337 return NameOrErr.takeError();
6338 }
6339
6340 VarDecl *DTemplated = D->getTemplatedDecl();
6341
6342 // Import the type.
6343 // FIXME: Value not used?
6344 ExpectedType TypeOrErr = import(DTemplated->getType());
6345 if (!TypeOrErr)
6346 return TypeOrErr.takeError();
6347
6348 // Create the declaration that is being templated.
6349 VarDecl *ToTemplated;
6350 if (Error Err = importInto(ToTemplated, DTemplated))
6351 return std::move(Err);
6352
6353 // Create the variable template declaration itself.
6354 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6355 if (!TemplateParamsOrErr)
6356 return TemplateParamsOrErr.takeError();
6357
6358 VarTemplateDecl *ToVarTD;
6359 if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6360 Name, *TemplateParamsOrErr, ToTemplated))
6361 return ToVarTD;
6362
6363 ToTemplated->setDescribedVarTemplate(ToVarTD);
6364
6365 ToVarTD->setAccess(D->getAccess());
6366 ToVarTD->setLexicalDeclContext(LexicalDC);
6367 LexicalDC->addDeclInternal(ToVarTD);
6368 if (DC != Importer.getToContext().getTranslationUnitDecl())
6369 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6370
6371 if (FoundByLookup) {
6372 auto *Recent =
6373 const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6374 if (!ToTemplated->getPreviousDecl()) {
6375 auto *PrevTemplated =
6376 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6377 if (ToTemplated != PrevTemplated)
6378 ToTemplated->setPreviousDecl(PrevTemplated);
6379 }
6380 ToVarTD->setPreviousDecl(Recent);
6381 }
6382
6383 return ToVarTD;
6384}
6385
6388 // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6389 // in an analog way (but specialized for this case).
6390
6392 auto RedeclIt = Redecls.begin();
6393 // Import the first part of the decl chain. I.e. import all previous
6394 // declarations starting from the canonical decl.
6395 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6396 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6397 if (!RedeclOrErr)
6398 return RedeclOrErr.takeError();
6399 }
6400 assert(*RedeclIt == D);
6401
6402 VarTemplateDecl *VarTemplate = nullptr;
6403 if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate()))
6404 return std::move(Err);
6405
6406 // Import the context of this declaration.
6407 DeclContext *DC, *LexicalDC;
6408 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6409 return std::move(Err);
6410
6411 // Import the location of this declaration.
6412 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6413 if (!BeginLocOrErr)
6414 return BeginLocOrErr.takeError();
6415
6416 auto IdLocOrErr = import(D->getLocation());
6417 if (!IdLocOrErr)
6418 return IdLocOrErr.takeError();
6419
6420 // Import template arguments.
6422 if (Error Err =
6423 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6424 return std::move(Err);
6425
6426 // Try to find an existing specialization with these template arguments.
6427 void *InsertPos = nullptr;
6428 VarTemplateSpecializationDecl *FoundSpecialization =
6429 VarTemplate->findSpecialization(TemplateArgs, InsertPos);
6430 if (FoundSpecialization) {
6431 if (IsStructuralMatch(D, FoundSpecialization)) {
6432 VarDecl *FoundDef = FoundSpecialization->getDefinition();
6433 if (D->getDeclContext()->isRecord()) {
6434 // In a record, it is allowed only to have one optional declaration and
6435 // one definition of the (static or constexpr) variable template.
6436 assert(
6437 FoundSpecialization->getDeclContext()->isRecord() &&
6438 "Member variable template specialization imported as non-member, "
6439 "inconsistent imported AST?");
6440 if (FoundDef)
6441 return Importer.MapImported(D, FoundDef);
6443 return Importer.MapImported(D, FoundSpecialization);
6444 } else {
6445 // If definition is imported and there is already one, map to it.
6446 // Otherwise create a new variable and link it to the existing.
6447 if (FoundDef && D->isThisDeclarationADefinition())
6448 return Importer.MapImported(D, FoundDef);
6449 }
6450 } else {
6451 return make_error<ASTImportError>(ASTImportError::NameConflict);
6452 }
6453 }
6454
6455 VarTemplateSpecializationDecl *D2 = nullptr;
6456
6457 TemplateArgumentListInfo ToTAInfo;
6458 if (const ASTTemplateArgumentListInfo *Args = D->getTemplateArgsInfo()) {
6459 if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6460 return std::move(Err);
6461 }
6462
6463 using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6464 // Create a new specialization.
6465 if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6466 // Import TemplateArgumentListInfo
6467 TemplateArgumentListInfo ArgInfos;
6468 const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten();
6469 // NOTE: FromTAArgsAsWritten and template parameter list are non-null.
6470 if (Error Err =
6471 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ArgInfos))
6472 return std::move(Err);
6473
6474 auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6475 if (!ToTPListOrErr)
6476 return ToTPListOrErr.takeError();
6477
6478 PartVarSpecDecl *ToPartial;
6479 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6480 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6481 VarTemplate, QualType(), nullptr,
6482 D->getStorageClass(), TemplateArgs, ArgInfos))
6483 return ToPartial;
6484
6485 if (Expected<PartVarSpecDecl *> ToInstOrErr =
6486 import(FromPartial->getInstantiatedFromMember()))
6487 ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6488 else
6489 return ToInstOrErr.takeError();
6490
6491 if (FromPartial->isMemberSpecialization())
6492 ToPartial->setMemberSpecialization();
6493
6494 D2 = ToPartial;
6495
6496 // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6497 // to adopt template parameters.
6498 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6499 } else { // Full specialization
6500 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6501 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6502 QualType(), nullptr, D->getStorageClass(),
6503 TemplateArgs))
6504 return D2;
6505 }
6506
6507 QualType T;
6508 if (Error Err = importInto(T, D->getType()))
6509 return std::move(Err);
6510 D2->setType(T);
6511
6512 auto TInfoOrErr = import(D->getTypeSourceInfo());
6513 if (!TInfoOrErr)
6514 return TInfoOrErr.takeError();
6515 D2->setTypeSourceInfo(*TInfoOrErr);
6516
6517 if (D->getPointOfInstantiation().isValid()) {
6518 if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6519 D2->setPointOfInstantiation(*POIOrErr);
6520 else
6521 return POIOrErr.takeError();
6522 }
6523
6525 D2->setTemplateArgsInfo(ToTAInfo);
6526
6527 if (auto LocOrErr = import(D->getQualifierLoc()))
6528 D2->setQualifierInfo(*LocOrErr);
6529 else
6530 return LocOrErr.takeError();
6531
6532 if (D->isConstexpr())
6533 D2->setConstexpr(true);
6534
6535 D2->setAccess(D->getAccess());
6536
6537 if (Error Err = ImportInitializer(D, D2))
6538 return std::move(Err);
6539
6540 if (FoundSpecialization)
6541 D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6542
6543 VarTemplate->AddSpecialization(D2, InsertPos);
6544
6545 addDeclToContexts(D, D2);
6546
6547 // Import the rest of the chain. I.e. import all subsequent declarations.
6548 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6549 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6550 if (!RedeclOrErr)
6551 return RedeclOrErr.takeError();
6552 }
6553
6554 return D2;
6555}
6556
6559 DeclContext *DC, *LexicalDC;
6560 DeclarationName Name;
6561 SourceLocation Loc;
6562 NamedDecl *ToD;
6563
6564 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6565 return std::move(Err);
6566
6567 if (ToD)
6568 return ToD;
6569
6570 const FunctionTemplateDecl *FoundByLookup = nullptr;
6571
6572 // Try to find a function in our own ("to") context with the same name, same
6573 // type, and in the same context as the function we're importing.
6574 // FIXME Split this into a separate function.
6575 if (!LexicalDC->isFunctionOrMethod()) {
6577 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6578 for (auto *FoundDecl : FoundDecls) {
6579 if (!FoundDecl->isInIdentifierNamespace(IDNS))
6580 continue;
6581
6582 if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6583 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6584 continue;
6585 if (IsStructuralMatch(D, FoundTemplate)) {
6586 FunctionTemplateDecl *TemplateWithDef =
6587 getTemplateDefinition(FoundTemplate);
6588 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6589 return Importer.MapImported(D, TemplateWithDef);
6590
6591 FoundByLookup = FoundTemplate;
6592 break;
6593 // TODO: handle conflicting names
6594 }
6595 }
6596 }
6597 }
6598
6599 auto ParamsOrErr = import(D->getTemplateParameters());
6600 if (!ParamsOrErr)
6601 return ParamsOrErr.takeError();
6602 TemplateParameterList *Params = *ParamsOrErr;
6603
6604 FunctionDecl *TemplatedFD;
6605 if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6606 return std::move(Err);
6607
6608 // At creation of the template the template parameters are "adopted"
6609 // (DeclContext is changed). After this possible change the lookup table
6610 // must be updated.
6611 // At deduction guides the DeclContext of the template parameters may be
6612 // different from what we would expect, it may be the class template, or a
6613 // probably different CXXDeductionGuideDecl. This may come from the fact that
6614 // the template parameter objects may be shared between deduction guides or
6615 // the class template, and at creation of multiple FunctionTemplateDecl
6616 // objects (for deduction guides) the same parameters are re-used. The
6617 // "adoption" happens multiple times with different parent, even recursively
6618 // for TemplateTemplateParmDecl. The same happens at import when the
6619 // FunctionTemplateDecl objects are created, but in different order.
6620 // In this way the DeclContext of these template parameters is not necessarily
6621 // the same as in the "from" context.
6623 OldParamDC.reserve(Params->size());
6624 llvm::transform(*Params, std::back_inserter(OldParamDC),
6625 [](NamedDecl *ND) { return ND->getDeclContext(); });
6626
6627 FunctionTemplateDecl *ToFunc;
6628 if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6629 Params, TemplatedFD))
6630 return ToFunc;
6631
6632 TemplatedFD->setDescribedFunctionTemplate(ToFunc);
6633
6634 ToFunc->setAccess(D->getAccess());
6635 ToFunc->setLexicalDeclContext(LexicalDC);
6636 addDeclToContexts(D, ToFunc);
6637
6638 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
6639 if (LT && !OldParamDC.empty()) {
6640 for (unsigned int I = 0; I < OldParamDC.size(); ++I)
6641 LT->updateForced(Params->getParam(I), OldParamDC[I]);
6642 }
6643
6644 if (FoundByLookup) {
6645 auto *Recent =
6646 const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6647 if (!TemplatedFD->getPreviousDecl()) {
6648 assert(FoundByLookup->getTemplatedDecl() &&
6649 "Found decl must have its templated decl set");
6650 auto *PrevTemplated =
6651 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6652 if (TemplatedFD != PrevTemplated)
6653 TemplatedFD->setPreviousDecl(PrevTemplated);
6654 }
6655 ToFunc->setPreviousDecl(Recent);
6656 }
6657
6658 return ToFunc;
6659}
6660
6661//----------------------------------------------------------------------------
6662// Import Statements
6663//----------------------------------------------------------------------------
6664
6666 Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
6667 << S->getStmtClassName();
6668 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
6669}
6670
6671
6673 if (Importer.returnWithErrorInTest())
6674 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
6676 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
6677 IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
6678 // ToII is nullptr when no symbolic name is given for output operand
6679 // see ParseStmtAsm::ParseAsmOperandsOpt
6680 Names.push_back(ToII);
6681 }
6682
6683 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
6684 IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
6685 // ToII is nullptr when no symbolic name is given for input operand
6686 // see ParseStmtAsm::ParseAsmOperandsOpt
6687 Names.push_back(ToII);
6688 }
6689
6691 for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
6692 if (auto ClobberOrErr = import(S->getClobberStringLiteral(I)))
6693 Clobbers.push_back(*ClobberOrErr);
6694 else
6695 return ClobberOrErr.takeError();
6696
6697 }
6698
6700 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
6701 if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I)))
6702 Constraints.push_back(*OutputOrErr);
6703 else
6704 return OutputOrErr.takeError();
6705 }
6706
6707 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
6708 if (auto InputOrErr = import(S->getInputConstraintLiteral(I)))
6709 Constraints.push_back(*InputOrErr);
6710 else
6711 return InputOrErr.takeError();
6712 }
6713
6714 SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs() +
6715 S->getNumLabels());
6716 if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
6717 return std::move(Err);
6718
6719 if (Error Err =
6720 ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
6721 return std::move(Err);
6722
6723 if (Error Err = ImportArrayChecked(
6724 S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs()))
6725 return std::move(Err);
6726
6727 ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
6728 if (!AsmLocOrErr)
6729 return AsmLocOrErr.takeError();
6730 auto AsmStrOrErr = import(S->getAsmString());
6731 if (!AsmStrOrErr)
6732 return AsmStrOrErr.takeError();
6733 ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
6734 if (!RParenLocOrErr)
6735 return RParenLocOrErr.takeError();
6736
6737 return new (Importer.getToContext()) GCCAsmStmt(
6738 Importer.getToContext(),
6739 *AsmLocOrErr,
6740 S->isSimple(),
6741 S->isVolatile(),
6742 S->getNumOutputs(),
6743 S->getNumInputs(),
6744 Names.data(),
6745 Constraints.data(),
6746 Exprs.data(),
6747 *AsmStrOrErr,
6748 S->getNumClobbers(),
6749 Clobbers.data(),
6750 S->getNumLabels(),
6751 *RParenLocOrErr);
6752}
6753
6755
6756 Error Err = Error::success();
6757 auto ToDG = importChecked(Err, S->getDeclGroup());
6758 auto ToBeginLoc = importChecked(Err, S->getBeginLoc());
6759 auto ToEndLoc = importChecked(Err, S->getEndLoc());
6760 if (Err)
6761 return std::move(Err);
6762 return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
6763}
6764
6766 ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
6767 if (!ToSemiLocOrErr)
6768 return ToSemiLocOrErr.takeError();
6769 return new (Importer.getToContext()) NullStmt(
6770 *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
6771}
6772
6774 SmallVector<Stmt *, 8> ToStmts(S->size());
6775
6776 if (Error Err = ImportContainerChecked(S->body(), ToStmts))
6777 return std::move(Err);
6778
6779 ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
6780 if (!ToLBracLocOrErr)
6781 return ToLBracLocOrErr.takeError();
6782
6783 ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
6784 if (!ToRBracLocOrErr)
6785 return ToRBracLocOrErr.takeError();
6786
6787 FPOptionsOverride FPO =
6788 S->hasStoredFPFeatures() ? S->getStoredFPFeatures() : FPOptionsOverride();
6789 return CompoundStmt::Create(Importer.getToContext(), ToStmts, FPO,
6790 *ToLBracLocOrErr, *ToRBracLocOrErr);
6791}
6792
6794
6795 Error Err = Error::success();
6796 auto ToLHS = importChecked(Err, S->getLHS());
6797 auto ToRHS = importChecked(Err, S->getRHS());
6798 auto ToSubStmt = importChecked(Err, S->getSubStmt());
6799 auto ToCaseLoc = importChecked(Err, S->getCaseLoc());
6800 auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc());
6801 auto ToColonLoc = importChecked(Err, S->getColonLoc());
6802 if (Err)
6803 return std::move(Err);
6804
6805 auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
6806 ToCaseLoc, ToEllipsisLoc, ToColonLoc);
6807 ToStmt->setSubStmt(ToSubStmt);
6808
6809 return ToStmt;
6810}
6811
6813
6814 Error Err = Error::success();
6815 auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc());
6816 auto ToColonLoc = importChecked(Err, S->getColonLoc());
6817 auto ToSubStmt = importChecked(Err, S->getSubStmt());
6818 if (Err)
6819 return std::move(Err);
6820
6821 return new (Importer.getToContext()) DefaultStmt(
6822 ToDefaultLoc, ToColonLoc, ToSubStmt);
6823}
6824
6826
6827 Error Err = Error::success();
6828 auto ToIdentLoc = importChecked(Err, S->getIdentLoc());
6829 auto ToLabelDecl = importChecked(Err, S->getDecl());
6830 auto ToSubStmt = importChecked(Err, S->getSubStmt());
6831 if (Err)
6832 return std::move(Err);
6833
6834 return new (Importer.getToContext()) LabelStmt(
6835 ToIdentLoc, ToLabelDecl, ToSubStmt);
6836}
6837
6839 ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
6840 if (!ToAttrLocOrErr)
6841 return ToAttrLocOrErr.takeError();
6842 ArrayRef<const Attr*> FromAttrs(S->getAttrs());
6843 SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
6844 if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
6845 return std::move(Err);
6846 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
6847 if (!ToSubStmtOrErr)
6848 return ToSubStmtOrErr.takeError();
6849
6851 Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
6852}
6853
6855
6856 Error Err = Error::success();
6857 auto ToIfLoc = importChecked(Err, S->getIfLoc());
6858 auto ToInit = importChecked(Err, S->getInit());
6859 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
6860 auto ToCond = importChecked(Err, S->getCond());
6861 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
6862 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
6863 auto ToThen = importChecked(Err, S->getThen());
6864 auto ToElseLoc = importChecked(Err, S->getElseLoc());
6865 auto ToElse = importChecked(Err, S->getElse());
6866 if (Err)
6867 return std::move(Err);
6868
6869 return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(),
6870 ToInit, ToConditionVariable, ToCond, ToLParenLoc,
6871 ToRParenLoc, ToThen, ToElseLoc, ToElse);
6872}
6873
6875
6876 Error Err = Error::success();
6877 auto ToInit = importChecked(Err, S->getInit());
6878 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
6879 auto ToCond = importChecked(Err, S->getCond());
6880 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
6881 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
6882 auto ToBody = importChecked(Err, S->getBody());
6883 auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
6884 if (Err)
6885 return std::move(Err);
6886
6887 auto *ToStmt =
6888 SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
6889 ToCond, ToLParenLoc, ToRParenLoc);
6890 ToStmt->setBody(ToBody);
6891 ToStmt->setSwitchLoc(ToSwitchLoc);
6892
6893 // Now we have to re-chain the cases.
6894 SwitchCase *LastChainedSwitchCase = nullptr;
6895 for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
6896 SC = SC->getNextSwitchCase()) {
6897 Expected<SwitchCase *> ToSCOrErr = import(SC);
6898 if (!ToSCOrErr)
6899 return ToSCOrErr.takeError();
6900 if (LastChainedSwitchCase)
6901 LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
6902 else
6903 ToStmt->setSwitchCaseList(*ToSCOrErr);
6904 LastChainedSwitchCase = *ToSCOrErr;
6905 }
6906
6907 return ToStmt;
6908}
6909
6911
6912 Error Err = Error::success();
6913 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
6914 auto ToCond = importChecked(Err, S->getCond());
6915 auto ToBody = importChecked(Err, S->getBody());
6916 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
6917 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
6918 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
6919 if (Err)
6920 return std::move(Err);
6921
6922 return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
6923 ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc);
6924}
6925
6927
6928 Error Err = Error::success();
6929 auto ToBody = importChecked(Err, S->getBody());
6930 auto ToCond = importChecked(Err, S->getCond());
6931 auto ToDoLoc = importChecked(Err, S->getDoLoc());
6932 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
6933 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
6934 if (Err)
6935 return std::move(Err);
6936
6937 return new (Importer.getToContext()) DoStmt(
6938 ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
6939}
6940
6942
6943 Error Err = Error::success();
6944 auto ToInit = importChecked(Err, S->getInit());
6945 auto ToCond = importChecked(Err, S->getCond());
6946 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
6947 auto ToInc = importChecked(Err, S->getInc());
6948 auto ToBody = importChecked(Err, S->getBody());
6949 auto ToForLoc = importChecked(Err, S->getForLoc());
6950 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
6951 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
6952 if (Err)
6953 return std::move(Err);
6954
6955 return new (Importer.getToContext()) ForStmt(
6956 Importer.getToContext(),
6957 ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
6958 ToRParenLoc);
6959}
6960
6962
6963 Error Err = Error::success();
6964 auto ToLabel = importChecked(Err, S->getLabel());
6965 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
6966 auto ToLabelLoc = importChecked(Err, S->getLabelLoc());
6967 if (Err)
6968 return std::move(Err);
6969
6970 return new (Importer.getToContext()) GotoStmt(
6971 ToLabel, ToGotoLoc, ToLabelLoc);
6972}
6973
6975
6976 Error Err = Error::success();
6977 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
6978 auto ToStarLoc = importChecked(Err, S->getStarLoc());
6979 auto ToTarget = importChecked(Err, S->getTarget());
6980 if (Err)
6981 return std::move(Err);
6982
6983 return new (Importer.getToContext()) IndirectGotoStmt(
6984 ToGotoLoc, ToStarLoc, ToTarget);
6985}
6986
6988 ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc());
6989 if (!ToContinueLocOrErr)
6990 return ToContinueLocOrErr.takeError();
6991 return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr);
6992}
6993
6995 auto ToBreakLocOrErr = import(S->getBreakLoc());
6996 if (!ToBreakLocOrErr)
6997 return ToBreakLocOrErr.takeError();
6998 return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr);
6999}
7000
7002
7003 Error Err = Error::success();
7004 auto ToReturnLoc = importChecked(Err, S->getReturnLoc());
7005 auto ToRetValue = importChecked(Err, S->getRetValue());
7006 auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate());
7007 if (Err)
7008 return std::move(Err);
7009
7010 return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
7011 ToNRVOCandidate);
7012}
7013
7015
7016 Error Err = Error::success();
7017 auto ToCatchLoc = importChecked(Err, S->getCatchLoc());
7018 auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl());
7019 auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock());
7020 if (Err)
7021 return std::move(Err);
7022
7023 return new (Importer.getToContext()) CXXCatchStmt (
7024 ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
7025}
7026
7028 ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
7029 if (!ToTryLocOrErr)
7030 return ToTryLocOrErr.takeError();
7031
7032 ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
7033 if (!ToTryBlockOrErr)
7034 return ToTryBlockOrErr.takeError();
7035
7036 SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
7037 for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
7038 CXXCatchStmt *FromHandler = S->getHandler(HI);
7039 if (auto ToHandlerOrErr = import(FromHandler))
7040 ToHandlers[HI] = *ToHandlerOrErr;
7041 else
7042 return ToHandlerOrErr.takeError();
7043 }
7044
7045 return CXXTryStmt::Create(Importer.getToContext(), *ToTryLocOrErr,
7046 cast<CompoundStmt>(*ToTryBlockOrErr), ToHandlers);
7047}
7048
7050
7051 Error Err = Error::success();
7052 auto ToInit = importChecked(Err, S->getInit());
7053 auto ToRangeStmt = importChecked(Err, S->getRangeStmt());
7054 auto ToBeginStmt = importChecked(Err, S->getBeginStmt());
7055 auto ToEndStmt = importChecked(Err, S->getEndStmt());
7056 auto ToCond = importChecked(Err, S->getCond());
7057 auto ToInc = importChecked(Err, S->getInc());
7058 auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt());
7059 auto ToBody = importChecked(Err, S->getBody());
7060 auto ToForLoc = importChecked(Err, S->getForLoc());
7061 auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc());
7062 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7063 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7064 if (Err)
7065 return std::move(Err);
7066
7067 return new (Importer.getToContext()) CXXForRangeStmt(
7068 ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
7069 ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
7070}
7071
7074 Error Err = Error::success();
7075 auto ToElement = importChecked(Err, S->getElement());
7076 auto ToCollection = importChecked(Err, S->getCollection());
7077 auto ToBody = importChecked(Err, S->getBody());
7078 auto ToForLoc = importChecked(Err, S->getForLoc());
7079 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7080 if (Err)
7081 return std::move(Err);
7082
7083 return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
7084 ToCollection,
7085 ToBody,
7086 ToForLoc,
7087 ToRParenLoc);
7088}
7089
7091
7092 Error Err = Error::success();
7093 auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc());
7094 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7095 auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl());
7096 auto ToCatchBody = importChecked(Err, S->getCatchBody());
7097 if (Err)
7098 return std::move(Err);
7099
7100 return new (Importer.getToContext()) ObjCAtCatchStmt (
7101 ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
7102}
7103
7105 ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
7106 if (!ToAtFinallyLocOrErr)
7107 return ToAtFinallyLocOrErr.takeError();
7108 ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
7109 if (!ToAtFinallyStmtOrErr)
7110 return ToAtFinallyStmtOrErr.takeError();
7111 return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
7112 *ToAtFinallyStmtOrErr);
7113}
7114
7116
7117 Error Err = Error::success();
7118 auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc());
7119 auto ToTryBody = importChecked(Err, S->getTryBody());
7120 auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt());
7121 if (Err)
7122 return std::move(Err);
7123
7124 SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
7125 for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
7126 ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
7127 if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
7128 ToCatchStmts[CI] = *ToCatchStmtOrErr;
7129 else
7130 return ToCatchStmtOrErr.takeError();
7131 }
7132
7133 return ObjCAtTryStmt::Create(Importer.getToContext(),
7134 ToAtTryLoc, ToTryBody,
7135 ToCatchStmts.begin(), ToCatchStmts.size(),
7136 ToFinallyStmt);
7137}
7138
7141
7142 Error Err = Error::success();
7143 auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc());
7144 auto ToSynchExpr = importChecked(Err, S->getSynchExpr());
7145 auto ToSynchBody = importChecked(Err, S->getSynchBody());
7146 if (Err)
7147 return std::move(Err);
7148
7149 return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
7150 ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
7151}
7152
7154 ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
7155 if (!ToThrowLocOrErr)
7156 return ToThrowLocOrErr.takeError();
7157 ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
7158 if (!ToThrowExprOrErr)
7159 return ToThrowExprOrErr.takeError();
7160 return new (Importer.getToContext()) ObjCAtThrowStmt(
7161 *ToThrowLocOrErr, *ToThrowExprOrErr);
7162}
7163
7166 ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
7167 if (!ToAtLocOrErr)
7168 return ToAtLocOrErr.takeError();
7169 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7170 if (!ToSubStmtOrErr)
7171 return ToSubStmtOrErr.takeError();
7172 return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
7173 *ToSubStmtOrErr);
7174}
7175
7176//----------------------------------------------------------------------------
7177// Import Expressions
7178//----------------------------------------------------------------------------
7180 Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
7181 << E->getStmtClassName();
7182 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7183}
7184
7186 Error Err = Error::success();
7187 auto ToType = importChecked(Err, E->getType());
7188 auto BLoc = importChecked(Err, E->getBeginLoc());
7189 auto RParenLoc = importChecked(Err, E->getEndLoc());
7190 if (Err)
7191 return std::move(Err);
7192 auto ParentContextOrErr = Importer.ImportContext(E->getParentContext());
7193 if (!ParentContextOrErr)
7194 return ParentContextOrErr.takeError();
7195
7196 return new (Importer.getToContext())
7197 SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc,
7198 RParenLoc, *ParentContextOrErr);
7199}
7200
7202
7203 Error Err = Error::success();
7204 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7205 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7206 auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo());
7207 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7208 auto ToType = importChecked(Err, E->getType());
7209 if (Err)
7210 return std::move(Err);
7211
7212 return new (Importer.getToContext()) VAArgExpr(
7213 ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
7214 E->isMicrosoftABI());
7215}
7216
7218
7219 Error Err = Error::success();
7220 auto ToCond = importChecked(Err, E->getCond());
7221 auto ToLHS = importChecked(Err, E->getLHS());
7222 auto ToRHS = importChecked(Err, E->getRHS());
7223 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7224 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7225 auto ToType = importChecked(Err, E->getType());
7226 if (Err)
7227 return std::move(Err);
7228
7229 ExprValueKind VK = E->getValueKind();
7230 ExprObjectKind OK = E->getObjectKind();
7231
7232 // The value of CondIsTrue only matters if the value is not
7233 // condition-dependent.
7234 bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
7235
7236 return new (Importer.getToContext())
7237 ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
7238 ToRParenLoc, CondIsTrue);
7239}
7240
7242 Error Err = Error::success();
7243 auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
7244 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7245 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7246 auto ToType = importChecked(Err, E->getType());
7247 auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
7248 if (Err)
7249 return std::move(Err);
7250
7251 return new (Importer.getToContext())
7252 ConvertVectorExpr(ToSrcExpr, ToTSI, ToType, E->getValueKind(),
7253 E->getObjectKind(), ToBuiltinLoc, ToRParenLoc);
7254}
7255
7257 Error Err = Error::success();
7258 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7259 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7260 auto ToType = importChecked(Err, E->getType());
7261 const unsigned NumSubExprs = E->getNumSubExprs();
7262
7264 llvm::ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
7265 ToSubExprs.resize(NumSubExprs);
7266
7267 if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
7268 return std::move(Err);
7269
7270 return new (Importer.getToContext()) ShuffleVectorExpr(
7271 Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
7272}
7273
7275 ExpectedType TypeOrErr = import(E->getType());
7276 if (!TypeOrErr)
7277 return TypeOrErr.takeError();
7278
7279 ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
7280 if (!BeginLocOrErr)
7281 return BeginLocOrErr.takeError();
7282
7283 return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
7284}
7285
7288 Error Err = Error::success();
7289 auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
7290 Expr *ToControllingExpr = nullptr;
7291 TypeSourceInfo *ToControllingType = nullptr;
7292 if (E->isExprPredicate())
7293 ToControllingExpr = importChecked(Err, E->getControllingExpr());
7294 else
7295 ToControllingType = importChecked(Err, E->getControllingType());
7296 assert((ToControllingExpr || ToControllingType) &&
7297 "Either the controlling expr or type must be nonnull");
7298 auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
7299 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7300 if (Err)
7301 return std::move(Err);
7302
7304 SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
7305 if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
7306 return std::move(Err);
7307
7308 ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
7309 SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
7310 if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
7311 return std::move(Err);
7312
7313 const ASTContext &ToCtx = Importer.getToContext();
7314 if (E->isResultDependent()) {
7315 if (ToControllingExpr) {
7317 ToCtx, ToGenericLoc, ToControllingExpr, llvm::ArrayRef(ToAssocTypes),
7318 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7320 }
7322 ToCtx, ToGenericLoc, ToControllingType, llvm::ArrayRef(ToAssocTypes),
7323 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7325 }
7326
7327 if (ToControllingExpr) {
7329 ToCtx, ToGenericLoc, ToControllingExpr, llvm::ArrayRef(ToAssocTypes),
7330 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7332 }
7334 ToCtx, ToGenericLoc, ToControllingType, llvm::ArrayRef(ToAssocTypes),
7335 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7337}
7338
7340
7341 Error Err = Error::success();
7342 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7343 auto ToType = importChecked(Err, E->getType());
7344 auto ToFunctionName = importChecked(Err, E->getFunctionName());
7345 if (Err)
7346 return std::move(Err);
7347
7348 return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
7349 E->getIdentKind(), E->isTransparent(),
7350 ToFunctionName);
7351}
7352
7354
7355 Error Err = Error::success();
7356 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
7357 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
7358 auto ToDecl = importChecked(Err, E->getDecl());
7359 auto ToLocation = importChecked(Err, E->getLocation());
7360 auto ToType = importChecked(Err, E->getType());
7361 if (Err)
7362 return std::move(Err);
7363
7364 NamedDecl *ToFoundD = nullptr;
7365 if (E->getDecl() != E->getFoundDecl()) {
7366 auto FoundDOrErr = import(E->getFoundDecl());
7367 if (!FoundDOrErr)
7368 return FoundDOrErr.takeError();
7369 ToFoundD = *FoundDOrErr;
7370 }
7371
7372 TemplateArgumentListInfo ToTAInfo;
7373 TemplateArgumentListInfo *ToResInfo = nullptr;
7374 if (E->hasExplicitTemplateArgs()) {
7375 if (Error Err =
7377 E->template_arguments(), ToTAInfo))
7378 return std::move(Err);
7379 ToResInfo = &ToTAInfo;
7380 }
7381
7382 auto *ToE = DeclRefExpr::Create(
7383 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
7384 E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
7385 E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse());
7386 if (E->hadMultipleCandidates())
7387 ToE->setHadMultipleCandidates(true);
7388 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
7389 return ToE;
7390}
7391
7393 ExpectedType TypeOrErr = import(E->getType());
7394 if (!TypeOrErr)
7395 return TypeOrErr.takeError();
7396
7397 return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
7398}
7399
7401 ExpectedExpr ToInitOrErr = import(E->getInit());
7402 if (!ToInitOrErr)
7403 return ToInitOrErr.takeError();
7404
7405 ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
7406 if (!ToEqualOrColonLocOrErr)
7407 return ToEqualOrColonLocOrErr.takeError();
7408
7409 SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
7410 // List elements from the second, the first is Init itself
7411 for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
7412 if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
7413 ToIndexExprs[I - 1] = *ToArgOrErr;
7414 else
7415 return ToArgOrErr.takeError();
7416 }
7417
7418 SmallVector<Designator, 4> ToDesignators(E->size());
7419 if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
7420 return std::move(Err);
7421
7423 Importer.getToContext(), ToDesignators,
7424 ToIndexExprs, *ToEqualOrColonLocOrErr,
7425 E->usesGNUSyntax(), *ToInitOrErr);
7426}
7427
7430 ExpectedType ToTypeOrErr = import(E->getType());
7431 if (!ToTypeOrErr)
7432 return ToTypeOrErr.takeError();
7433
7434 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7435 if (!ToLocationOrErr)
7436 return ToLocationOrErr.takeError();
7437
7438 return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
7439 *ToTypeOrErr, *ToLocationOrErr);
7440}
7441
7443 ExpectedType ToTypeOrErr = import(E->getType());
7444 if (!ToTypeOrErr)
7445 return ToTypeOrErr.takeError();
7446
7447 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7448 if (!ToLocationOrErr)
7449 return ToLocationOrErr.takeError();
7450
7452 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7453}
7454
7455
7457 ExpectedType ToTypeOrErr = import(E->getType());
7458 if (!ToTypeOrErr)
7459 return ToTypeOrErr.takeError();
7460
7461 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7462 if (!ToLocationOrErr)
7463 return ToLocationOrErr.takeError();
7464
7466 Importer.getToContext(), E->getValue(), E->isExact(),
7467 *ToTypeOrErr, *ToLocationOrErr);
7468}
7469
7471 auto ToTypeOrErr = import(E->getType());
7472 if (!ToTypeOrErr)
7473 return ToTypeOrErr.takeError();
7474
7475 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7476 if (!ToSubExprOrErr)
7477 return ToSubExprOrErr.takeError();
7478
7479 return new (Importer.getToContext()) ImaginaryLiteral(
7480 *ToSubExprOrErr, *ToTypeOrErr);
7481}
7482
7484 auto ToTypeOrErr = import(E->getType());
7485 if (!ToTypeOrErr)
7486 return ToTypeOrErr.takeError();
7487
7488 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7489 if (!ToLocationOrErr)
7490 return ToLocationOrErr.takeError();
7491
7492 return new (Importer.getToContext()) FixedPointLiteral(
7493 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
7494 Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
7495}
7496
7498 ExpectedType ToTypeOrErr = import(E->getType());
7499 if (!ToTypeOrErr)
7500 return ToTypeOrErr.takeError();
7501
7502 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7503 if (!ToLocationOrErr)
7504 return ToLocationOrErr.takeError();
7505
7506 return new (Importer.getToContext()) CharacterLiteral(
7507 E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
7508}
7509
7511 ExpectedType ToTypeOrErr = import(E->getType());
7512 if (!ToTypeOrErr)
7513 return ToTypeOrErr.takeError();
7514
7516 if (Error Err = ImportArrayChecked(
7517 E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
7518 return std::move(Err);
7519
7520 return StringLiteral::Create(
7521 Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(),
7522 *ToTypeOrErr, ToLocations.data(), ToLocations.size());
7523}
7524
7526
7527 Error Err = Error::success();
7528 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7529 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7530 auto ToType = importChecked(Err, E->getType());
7531 auto ToInitializer = importChecked(Err, E->getInitializer());
7532 if (Err)
7533 return std::move(Err);
7534
7535 return new (Importer.getToContext()) CompoundLiteralExpr(
7536 ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
7537 ToInitializer, E->isFileScope());
7538}
7539
7541
7542 Error Err = Error::success();
7543 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7544 auto ToType = importChecked(Err, E->getType());
7545 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7546 if (Err)
7547 return std::move(Err);
7548
7550 if (Error Err = ImportArrayChecked(
7551 E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
7552 ToExprs.begin()))
7553 return std::move(Err);
7554
7555 return new (Importer.getToContext()) AtomicExpr(
7556
7557 ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
7558}
7559
7561 Error Err = Error::success();
7562 auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc());
7563 auto ToLabelLoc = importChecked(Err, E->getLabelLoc());
7564 auto ToLabel = importChecked(Err, E->getLabel());
7565 auto ToType = importChecked(Err, E->getType());
7566 if (Err)
7567 return std::move(Err);
7568
7569 return new (Importer.getToContext()) AddrLabelExpr(
7570 ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
7571}
7573 Error Err = Error::success();
7574 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7575 auto ToResult = importChecked(Err, E->getAPValueResult());
7576 if (Err)
7577 return std::move(Err);
7578
7579 return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult);
7580}
7582 Error Err = Error::success();
7583 auto ToLParen = importChecked(Err, E->getLParen());
7584 auto ToRParen = importChecked(Err, E->getRParen());
7585 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7586 if (Err)
7587 return std::move(Err);
7588
7589 return new (Importer.getToContext())
7590 ParenExpr(ToLParen, ToRParen, ToSubExpr);
7591}
7592
7594 SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
7595 if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
7596 return std::move(Err);
7597
7598 ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
7599 if (!ToLParenLocOrErr)
7600 return ToLParenLocOrErr.takeError();
7601
7602 ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
7603 if (!ToRParenLocOrErr)
7604 return ToRParenLocOrErr.takeError();
7605
7606 return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
7607 ToExprs, *ToRParenLocOrErr);
7608}
7609
7611 Error Err = Error::success();
7612 auto ToSubStmt = importChecked(Err, E->getSubStmt());
7613 auto ToType = importChecked(Err, E->getType());
7614 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7615 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7616 if (Err)
7617 return std::move(Err);
7618
7619 return new (Importer.getToContext())
7620 StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
7621 E->getTemplateDepth());
7622}
7623
7625 Error Err = Error::success();
7626 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7627 auto ToType = importChecked(Err, E->getType());
7628 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7629 if (Err)
7630 return std::move(Err);
7631
7632 auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
7633 E->hasStoredFPFeatures());
7634 UO->setType(ToType);
7635 UO->setSubExpr(ToSubExpr);
7636 UO->setOpcode(E->getOpcode());
7637 UO->setOperatorLoc(ToOperatorLoc);
7638 UO->setCanOverflow(E->canOverflow());
7639 if (E->hasStoredFPFeatures())
7640 UO->setStoredFPFeatures(E->getStoredFPFeatures());
7641
7642 return UO;
7643}
7644
7646
7648 Error Err = Error::success();
7649 auto ToType = importChecked(Err, E->getType());
7650 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7651 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7652 if (Err)
7653 return std::move(Err);
7654
7655 if (E->isArgumentType()) {
7656 Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
7657 import(E->getArgumentTypeInfo());
7658 if (!ToArgumentTypeInfoOrErr)
7659 return ToArgumentTypeInfoOrErr.takeError();
7660
7661 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
7662 E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
7663 ToRParenLoc);
7664 }
7665
7666 ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
7667 if (!ToArgumentExprOrErr)
7668 return ToArgumentExprOrErr.takeError();
7669
7670 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
7671 E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
7672}
7673
7675 Error Err = Error::success();
7676 auto ToLHS = importChecked(Err, E->getLHS());
7677 auto ToRHS = importChecked(Err, E->getRHS());
7678 auto ToType = importChecked(Err, E->getType());
7679 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7680 if (Err)
7681 return std::move(Err);
7682
7684 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
7685 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
7686 E->getFPFeatures());
7687}
7688
7690 Error Err = Error::success();
7691 auto ToCond = importChecked(Err, E->getCond());
7692 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
7693 auto ToLHS = importChecked(Err, E->getLHS());
7694 auto ToColonLoc = importChecked(Err, E->getColonLoc());
7695 auto ToRHS = importChecked(Err, E->getRHS());
7696 auto ToType = importChecked(Err, E->getType());
7697 if (Err)
7698 return std::move(Err);
7699
7700 return new (Importer.getToContext()) ConditionalOperator(
7701 ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
7702 E->getValueKind(), E->getObjectKind());
7703}
7704
7707 Error Err = Error::success();
7708 auto ToCommon = importChecked(Err, E->getCommon());
7709 auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue());
7710 auto ToCond = importChecked(Err, E->getCond());
7711 auto ToTrueExpr = importChecked(Err, E->getTrueExpr());
7712 auto ToFalseExpr = importChecked(Err, E->getFalseExpr());
7713 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
7714 auto ToColonLoc = importChecked(Err, E->getColonLoc());
7715 auto ToType = importChecked(Err, E->getType());
7716 if (Err)
7717 return std::move(Err);
7718
7719 return new (Importer.getToContext()) BinaryConditionalOperator(
7720 ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
7721 ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
7722 E->getObjectKind());
7723}
7724
7727 Error Err = Error::success();
7728 auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
7729 if (Err)
7730 return std::move(Err);
7731
7732 return new (Importer.getToContext())
7733 CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
7734}
7735
7737 Error Err = Error::success();
7738 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7739 auto ToQueriedTypeSourceInfo =
7741 auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression());
7742 auto ToEndLoc = importChecked(Err, E->getEndLoc());
7743 auto ToType = importChecked(Err, E->getType());
7744 if (Err)
7745 return std::move(Err);
7746
7747 return new (Importer.getToContext()) ArrayTypeTraitExpr(
7748 ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
7749 ToDimensionExpression, ToEndLoc, ToType);
7750}
7751
7753 Error Err = Error::success();
7754 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7755 auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression());
7756 auto ToEndLoc = importChecked(Err, E->getEndLoc());
7757 auto ToType = importChecked(Err, E->getType());
7758 if (Err)
7759 return std::move(Err);
7760
7761 return new (Importer.getToContext()) ExpressionTraitExpr(
7762 ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
7763 ToEndLoc, ToType);
7764}
7765
7767 Error Err = Error::success();
7768 auto ToLocation = importChecked(Err, E->getLocation());
7769 auto ToType = importChecked(Err, E->getType());
7770 auto ToSourceExpr = importChecked(Err, E->getSourceExpr());
7771 if (Err)
7772 return std::move(Err);
7773
7774 return new (Importer.getToContext()) OpaqueValueExpr(
7775 ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
7776}
7777
7779 Error Err = Error::success();
7780 auto ToLHS = importChecked(Err, E->getLHS());
7781 auto ToRHS = importChecked(Err, E->getRHS());
7782 auto ToType = importChecked(Err, E->getType());
7783 auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc());
7784 if (Err)
7785 return std::move(Err);
7786
7787 return new (Importer.getToContext()) ArraySubscriptExpr(
7788 ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
7789 ToRBracketLoc);
7790}
7791
7794 Error Err = Error::success();
7795 auto ToLHS = importChecked(Err, E->getLHS());
7796 auto ToRHS = importChecked(Err, E->getRHS());
7797 auto ToType = importChecked(Err, E->getType());
7798 auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType());
7799 auto ToComputationResultType =
7801 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7802 if (Err)
7803 return std::move(Err);
7804
7806 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
7807 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
7808 E->getFPFeatures(),
7809 ToComputationLHSType, ToComputationResultType);
7810}
7811
7814 CXXCastPath Path;
7815 for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
7816 if (auto SpecOrErr = import(*I))
7817 Path.push_back(*SpecOrErr);
7818 else
7819 return SpecOrErr.takeError();
7820 }
7821 return Path;
7822}
7823
7825 ExpectedType ToTypeOrErr = import(E->getType());
7826 if (!ToTypeOrErr)
7827 return ToTypeOrErr.takeError();
7828
7829 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7830 if (!ToSubExprOrErr)
7831 return ToSubExprOrErr.takeError();
7832
7833 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
7834 if (!ToBasePathOrErr)
7835 return ToBasePathOrErr.takeError();
7836
7838 Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
7839 &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures());
7840}
7841
7843 Error Err = Error::success();
7844 auto ToType = importChecked(Err, E->getType());
7845 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7846 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
7847 if (Err)
7848 return std::move(Err);
7849
7850 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
7851 if (!ToBasePathOrErr)
7852 return ToBasePathOrErr.takeError();
7853 CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
7854
7855 switch (E->getStmtClass()) {
7856 case Stmt::CStyleCastExprClass: {
7857 auto *CCE = cast<CStyleCastExpr>(E);
7858 ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
7859 if (!ToLParenLocOrErr)
7860 return ToLParenLocOrErr.takeError();
7861 ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
7862 if (!ToRParenLocOrErr)
7863 return ToRParenLocOrErr.takeError();
7865 Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
7866 ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten,
7867 *ToLParenLocOrErr, *ToRParenLocOrErr);
7868 }
7869
7870 case Stmt::CXXFunctionalCastExprClass: {
7871 auto *FCE = cast<CXXFunctionalCastExpr>(E);
7872 ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
7873 if (!ToLParenLocOrErr)
7874 return ToLParenLocOrErr.takeError();
7875 ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
7876 if (!ToRParenLocOrErr)
7877 return ToRParenLocOrErr.takeError();
7879 Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
7880 E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(),
7881 *ToLParenLocOrErr, *ToRParenLocOrErr);
7882 }
7883
7884 case Stmt::ObjCBridgedCastExprClass: {
7885 auto *OCE = cast<ObjCBridgedCastExpr>(E);
7886 ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
7887 if (!ToLParenLocOrErr)
7888 return ToLParenLocOrErr.takeError();
7889 ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
7890 if (!ToBridgeKeywordLocOrErr)
7891 return ToBridgeKeywordLocOrErr.takeError();
7892 return new (Importer.getToContext()) ObjCBridgedCastExpr(
7893 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
7894 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
7895 }
7896 case Stmt::BuiltinBitCastExprClass: {
7897 auto *BBC = cast<BuiltinBitCastExpr>(E);
7898 ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
7899 if (!ToKWLocOrErr)
7900 return ToKWLocOrErr.takeError();
7901 ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
7902 if (!ToRParenLocOrErr)
7903 return ToRParenLocOrErr.takeError();
7904 return new (Importer.getToContext()) BuiltinBitCastExpr(
7905 ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
7906 ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
7907 }
7908 default:
7909 llvm_unreachable("Cast expression of unsupported type!");
7910 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7911 }
7912}
7913
7916 for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
7917 const OffsetOfNode &FromNode = E->getComponent(I);
7918
7919 SourceLocation ToBeginLoc, ToEndLoc;
7920
7921 if (FromNode.getKind() != OffsetOfNode::Base) {
7922 Error Err = Error::success();
7923 ToBeginLoc = importChecked(Err, FromNode.getBeginLoc());
7924 ToEndLoc = importChecked(Err, FromNode.getEndLoc());
7925 if (Err)
7926 return std::move(Err);
7927 }
7928
7929 switch (FromNode.getKind()) {
7931 ToNodes.push_back(
7932 OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
7933 break;
7934 case OffsetOfNode::Base: {
7935 auto ToBSOrErr = import(FromNode.getBase());
7936 if (!ToBSOrErr)
7937 return ToBSOrErr.takeError();
7938 ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
7939 break;
7940 }
7941 case OffsetOfNode::Field: {
7942 auto ToFieldOrErr = import(FromNode.getField());
7943 if (!ToFieldOrErr)
7944 return ToFieldOrErr.takeError();
7945 ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
7946 break;
7947 }
7949 IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
7950 ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
7951 break;
7952 }
7953 }
7954 }
7955
7957 for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
7958 ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
7959 if (!ToIndexExprOrErr)
7960 return ToIndexExprOrErr.takeError();
7961 ToExprs[I] = *ToIndexExprOrErr;
7962 }
7963
7964 Error Err = Error::success();
7965 auto ToType = importChecked(Err, E->getType());
7966 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7967 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7968 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7969 if (Err)
7970 return std::move(Err);
7971
7972 return OffsetOfExpr::Create(
7973 Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
7974 ToExprs, ToRParenLoc);
7975}
7976
7978 Error Err = Error::success();
7979 auto ToType = importChecked(Err, E->getType());
7980 auto ToOperand = importChecked(Err, E->getOperand());
7981 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7982 auto ToEndLoc = importChecked(Err, E->getEndLoc());
7983 if (Err)
7984 return std::move(Err);
7985
7986 CanThrowResult ToCanThrow;
7987 if (E->isValueDependent())
7988 ToCanThrow = CT_Dependent;
7989 else
7990 ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
7991
7992 return new (Importer.getToContext()) CXXNoexceptExpr(
7993 ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
7994}
7995
7997 Error Err = Error::success();
7998 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7999 auto ToType = importChecked(Err, E->getType());
8000 auto ToThrowLoc = importChecked(Err, E->getThrowLoc());
8001 if (Err)
8002 return std::move(Err);
8003
8004 return new (Importer.getToContext()) CXXThrowExpr(
8005 ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
8006}
8007
8009 ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
8010 if (!ToUsedLocOrErr)
8011 return ToUsedLocOrErr.takeError();
8012
8013 auto ToParamOrErr = import(E->getParam());
8014 if (!ToParamOrErr)
8015 return ToParamOrErr.takeError();
8016
8017 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8018 if (!UsedContextOrErr)
8019 return UsedContextOrErr.takeError();
8020
8021 // Import the default arg if it was not imported yet.
8022 // This is needed because it can happen that during the import of the
8023 // default expression (from VisitParmVarDecl) the same ParmVarDecl is
8024 // encountered here. The default argument for a ParmVarDecl is set in the
8025 // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here,
8026 // see VisitParmVarDecl).
8027 ParmVarDecl *ToParam = *ToParamOrErr;
8028 if (!ToParam->getDefaultArg()) {
8029 std::optional<ParmVarDecl *> FromParam =
8030 Importer.getImportedFromDecl(ToParam);
8031 assert(FromParam && "ParmVarDecl was not imported?");
8032
8033 if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam))
8034 return std::move(Err);
8035 }
8036 Expr *RewrittenInit = nullptr;
8037 if (E->hasRewrittenInit()) {
8038 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8039 if (!ExprOrErr)
8040 return ExprOrErr.takeError();
8041 RewrittenInit = ExprOrErr.get();
8042 }
8043 return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr,
8044 *ToParamOrErr, RewrittenInit,
8045 *UsedContextOrErr);
8046}
8047
8050 Error Err = Error::success();
8051 auto ToType = importChecked(Err, E->getType());
8052 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8053 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8054 if (Err)
8055 return std::move(Err);
8056
8057 return new (Importer.getToContext()) CXXScalarValueInitExpr(
8058 ToType, ToTypeSourceInfo, ToRParenLoc);
8059}
8060
8063 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8064 if (!ToSubExprOrErr)
8065 return ToSubExprOrErr.takeError();
8066
8067 auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
8068 if (!ToDtorOrErr)
8069 return ToDtorOrErr.takeError();
8070
8071 ASTContext &ToCtx = Importer.getToContext();
8072 CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
8073 return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
8074}
8075
8077
8079 Error Err = Error::success();
8080 auto ToConstructor = importChecked(Err, E->getConstructor());
8081 auto ToType = importChecked(Err, E->getType());
8082 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8083 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8084 if (Err)
8085 return std::move(Err);
8086
8088 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8089 return std::move(Err);
8090
8092 Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
8093 ToParenOrBraceRange, E->hadMultipleCandidates(),
8096}
8097
8100 DeclContext *DC, *LexicalDC;
8101 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
8102 return std::move(Err);
8103
8104 Error Err = Error::success();
8105 auto Temporary = importChecked(Err, D->getTemporaryExpr());
8106 auto ExtendingDecl = importChecked(Err, D->getExtendingDecl());
8107 if (Err)
8108 return std::move(Err);
8109 // FIXME: Should ManglingNumber get numbers associated with 'to' context?
8110
8112 if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl,
8113 D->getManglingNumber()))
8114 return To;
8115
8116 To->setLexicalDeclContext(LexicalDC);
8117 LexicalDC->addDeclInternal(To);
8118 return To;
8119}
8120
8123 Error Err = Error::success();
8124 auto ToType = importChecked(Err, E->getType());
8125 Expr *ToTemporaryExpr = importChecked(
8126 Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr());
8127 auto ToMaterializedDecl =
8129 if (Err)
8130 return std::move(Err);
8131
8132 if (!ToTemporaryExpr)
8133 ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
8134
8135 auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
8136 ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
8137 ToMaterializedDecl);
8138
8139 return ToMTE;
8140}
8141
8143 Error Err = Error::success();
8144 auto ToType = importChecked(Err, E->getType());
8145 auto ToPattern = importChecked(Err, E->getPattern());
8146 auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8147 if (Err)
8148 return std::move(Err);
8149
8150 return new (Importer.getToContext()) PackExpansionExpr(
8151 ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions());
8152}
8153
8155 Error Err = Error::success();
8156 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8157 auto ToPack = importChecked(Err, E->getPack());
8158 auto ToPackLoc = importChecked(Err, E->getPackLoc());
8159 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8160 if (Err)
8161 return std::move(Err);
8162
8163 std::optional<unsigned> Length;
8164 if (!E->isValueDependent())
8165 Length = E->getPackLength();
8166
8167 SmallVector<TemplateArgument, 8> ToPartialArguments;
8168 if (E->isPartiallySubstituted()) {
8169 if (Error Err = ImportTemplateArguments(E->getPartialArguments(),
8170 ToPartialArguments))
8171 return std::move(Err);
8172 }
8173
8175 Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
8176 Length, ToPartialArguments);
8177}
8178
8179
8181 Error Err = Error::success();
8182 auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
8183 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8184 auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens());
8185 auto ToArraySize = importChecked(Err, E->getArraySize());
8186 auto ToInitializer = importChecked(Err, E->getInitializer());
8187 auto ToType = importChecked(Err, E->getType());
8188 auto ToAllocatedTypeSourceInfo =
8190 auto ToSourceRange = importChecked(Err, E->getSourceRange());
8191 auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange());
8192 if (Err)
8193 return std::move(Err);
8194
8195 SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
8196 if (Error Err =
8197 ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
8198 return std::move(Err);
8199
8200 return CXXNewExpr::Create(
8201 Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
8202 ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(),
8203 ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(),
8204 ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange,
8205 ToDirectInitRange);
8206}
8207
8209 Error Err = Error::success();
8210 auto ToType = importChecked(Err, E->getType());
8211 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8212 auto ToArgument = importChecked(Err, E->getArgument());
8213 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8214 if (Err)
8215 return std::move(Err);
8216
8217 return new (Importer.getToContext()) CXXDeleteExpr(
8218 ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
8219 E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
8220 ToBeginLoc);
8221}
8222
8224 Error Err = Error::success();
8225 auto ToType = importChecked(Err, E->getType());
8226 auto ToLocation = importChecked(Err, E->getLocation());
8227 auto ToConstructor = importChecked(Err, E->getConstructor());
8228 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8229 if (Err)
8230 return std::move(Err);
8231
8233 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8234 return std::move(Err);
8235
8237 Importer.getToContext(), ToType, ToLocation, ToConstructor,
8238 E->isElidable(), ToArgs, E->hadMultipleCandidates(),
8241 ToParenOrBraceRange);
8243 return ToE;
8244}
8245
8247 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8248 if (!ToSubExprOrErr)
8249 return ToSubExprOrErr.takeError();
8250
8252 if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
8253 return std::move(Err);
8254
8256 Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
8257 ToObjects);
8258}
8259
8261 Error Err = Error::success();
8262 auto ToCallee = importChecked(Err, E->getCallee());
8263 auto ToType = importChecked(Err, E->getType());
8264 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8265 if (Err)
8266 return std::move(Err);
8267
8269 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8270 return std::move(Err);
8271
8272 return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
8273 ToType, E->getValueKind(), ToRParenLoc,
8274 E->getFPFeatures());
8275}
8276
8278 ExpectedType ToTypeOrErr = import(E->getType());
8279 if (!ToTypeOrErr)
8280 return ToTypeOrErr.takeError();
8281
8282 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8283 if (!ToLocationOrErr)
8284 return ToLocationOrErr.takeError();
8285
8286 return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
8287 *ToTypeOrErr, E->isImplicit());
8288}
8289
8291 ExpectedType ToTypeOrErr = import(E->getType());
8292 if (!ToTypeOrErr)
8293 return ToTypeOrErr.takeError();
8294
8295 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8296 if (!ToLocationOrErr)
8297 return ToLocationOrErr.takeError();
8298
8299 return CXXBoolLiteralExpr::Create(Importer.getToContext(), E->getValue(),
8300 *ToTypeOrErr, *ToLocationOrErr);
8301}
8302
8304 Error Err = Error::success();
8305 auto ToBase = importChecked(Err, E->getBase());
8306 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8307 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8308 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8309 auto ToMemberDecl = importChecked(Err, E->getMemberDecl());
8310 auto ToType = importChecked(Err, E->getType());
8311 auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl());
8312 auto ToName = importChecked(Err, E->getMemberNameInfo().getName());
8313 auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc());
8314 if (Err)
8315 return std::move(Err);
8316
8317 DeclAccessPair ToFoundDecl =
8319
8320 DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
8321
8322 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8323 if (E->hasExplicitTemplateArgs()) {
8324 if (Error Err =
8326 E->template_arguments(), ToTAInfo))
8327 return std::move(Err);
8328 ResInfo = &ToTAInfo;
8329 }
8330
8331 return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(),
8332 ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8333 ToMemberDecl, ToFoundDecl, ToMemberNameInfo,
8334 ResInfo, ToType, E->getValueKind(),
8335 E->getObjectKind(), E->isNonOdrUse());
8336}
8337
8340 Error Err = Error::success();
8341 auto ToBase = importChecked(Err, E->getBase());
8342 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8343 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8344 auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo());
8345 auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc());
8346 auto ToTildeLoc = importChecked(Err, E->getTildeLoc());
8347 if (Err)
8348 return std::move(Err);
8349
8351 if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
8352 IdentifierInfo *ToII = Importer.Import(FromII);
8353 ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
8354 if (!ToDestroyedTypeLocOrErr)
8355 return ToDestroyedTypeLocOrErr.takeError();
8356 Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
8357 } else {
8358 if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
8359 Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
8360 else
8361 return ToTIOrErr.takeError();
8362 }
8363
8364 return new (Importer.getToContext()) CXXPseudoDestructorExpr(
8365 Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
8366 ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
8367}
8368
8371 Error Err = Error::success();
8372 auto ToType = importChecked(Err, E->getType());
8373 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8374 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8375 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8376 auto ToFirstQualifierFoundInScope =
8378 if (Err)
8379 return std::move(Err);
8380
8381 Expr *ToBase = nullptr;
8382 if (!E->isImplicitAccess()) {
8383 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8384 ToBase = *ToBaseOrErr;
8385 else
8386 return ToBaseOrErr.takeError();
8387 }
8388
8389 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8390
8391 if (E->hasExplicitTemplateArgs()) {
8392 if (Error Err =
8394 E->template_arguments(), ToTAInfo))
8395 return std::move(Err);
8396 ResInfo = &ToTAInfo;
8397 }
8398 auto ToMember = importChecked(Err, E->getMember());
8399 auto ToMemberLoc = importChecked(Err, E->getMemberLoc());
8400 if (Err)
8401 return std::move(Err);
8402 DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc);
8403
8404 // Import additional name location/type info.
8405 if (Error Err =
8406 ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo))
8407 return std::move(Err);
8408
8410 Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
8411 ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
8412 ToMemberNameInfo, ResInfo);
8413}
8414
8417 Error Err = Error::success();
8418 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8419 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8420 auto ToDeclName = importChecked(Err, E->getDeclName());
8421 auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc());
8422 auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc());
8423 auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc());
8424 if (Err)
8425 return std::move(Err);
8426
8427 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8428 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8429 return std::move(Err);
8430
8431 TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
8432 TemplateArgumentListInfo *ResInfo = nullptr;
8433 if (E->hasExplicitTemplateArgs()) {
8434 if (Error Err =
8436 return std::move(Err);
8437 ResInfo = &ToTAInfo;
8438 }
8439
8441 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
8442 ToNameInfo, ResInfo);
8443}
8444
8447 Error Err = Error::success();
8448 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8449 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8450 auto ToType = importChecked(Err, E->getType());
8451 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8452 if (Err)
8453 return std::move(Err);
8454
8456 if (Error Err =
8457 ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
8458 return std::move(Err);
8459
8461 Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc,
8462 llvm::ArrayRef(ToArgs), ToRParenLoc, E->isListInitialization());
8463}
8464
8467 Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
8468 if (!ToNamingClassOrErr)
8469 return ToNamingClassOrErr.takeError();
8470
8471 auto ToQualifierLocOrErr = import(E->getQualifierLoc());
8472 if (!ToQualifierLocOrErr)
8473 return ToQualifierLocOrErr.takeError();
8474
8475 Error Err = Error::success();
8476 auto ToName = importChecked(Err, E->getName());
8477 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8478 if (Err)
8479 return std::move(Err);
8480 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8481
8482 // Import additional name location/type info.
8483 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8484 return std::move(Err);
8485
8486 UnresolvedSet<8> ToDecls;
8487 for (auto *D : E->decls())
8488 if (auto ToDOrErr = import(D))
8489 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8490 else
8491 return ToDOrErr.takeError();
8492
8493 if (E->hasExplicitTemplateArgs()) {
8494 TemplateArgumentListInfo ToTAInfo;
8495 if (Error Err = ImportTemplateArgumentListInfo(
8497 ToTAInfo))
8498 return std::move(Err);
8499
8500 ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
8501 if (!ToTemplateKeywordLocOrErr)
8502 return ToTemplateKeywordLocOrErr.takeError();
8503
8504 const bool KnownDependent =
8505 (E->getDependence() & ExprDependence::TypeValue) ==
8506 ExprDependence::TypeValue;
8508 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8509 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
8510 ToDecls.begin(), ToDecls.end(), KnownDependent);
8511 }
8512
8514 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8515 ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(),
8516 ToDecls.end());
8517}
8518
8521 Error Err = Error::success();
8522 auto ToType = importChecked(Err, E->getType());
8523 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8524 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8525 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8526 auto ToName = importChecked(Err, E->getName());
8527 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8528 if (Err)
8529 return std::move(Err);
8530
8531 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8532 // Import additional name location/type info.
8533 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8534 return std::move(Err);
8535
8536 UnresolvedSet<8> ToDecls;
8537 for (Decl *D : E->decls())
8538 if (auto ToDOrErr = import(D))
8539 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8540 else
8541 return ToDOrErr.takeError();
8542
8543 TemplateArgumentListInfo ToTAInfo;
8544 TemplateArgumentListInfo *ResInfo = nullptr;
8545 if (E->hasExplicitTemplateArgs()) {
8546 TemplateArgumentListInfo FromTAInfo;
8547 E->copyTemplateArgumentsInto(FromTAInfo);
8548 if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo))
8549 return std::move(Err);
8550 ResInfo = &ToTAInfo;
8551 }
8552
8553 Expr *ToBase = nullptr;
8554 if (!E->isImplicitAccess()) {
8555 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8556 ToBase = *ToBaseOrErr;
8557 else
8558 return ToBaseOrErr.takeError();
8559 }
8560
8562 Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
8563 E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8564 ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
8565}
8566
8568 Error Err = Error::success();
8569 auto ToCallee = importChecked(Err, E->getCallee());
8570 auto ToType = importChecked(Err, E->getType());
8571 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8572 if (Err)
8573 return std::move(Err);
8574
8575 unsigned NumArgs = E->getNumArgs();
8576 llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
8577 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8578 return std::move(Err);
8579
8580 if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
8582 Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
8583 OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
8584 OCE->getADLCallKind());
8585 }
8586
8587 return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
8588 E->getValueKind(), ToRParenLoc, E->getFPFeatures(),
8589 /*MinNumArgs=*/0, E->getADLCallKind());
8590}
8591
8593 CXXRecordDecl *FromClass = E->getLambdaClass();
8594 auto ToClassOrErr = import(FromClass);
8595 if (!ToClassOrErr)
8596 return ToClassOrErr.takeError();
8597 CXXRecordDecl *ToClass = *ToClassOrErr;
8598
8599 auto ToCallOpOrErr = import(E->getCallOperator());
8600 if (!ToCallOpOrErr)
8601 return ToCallOpOrErr.takeError();
8602
8603 SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
8604 if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
8605 return std::move(Err);
8606
8607 Error Err = Error::success();
8608 auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange());
8609 auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc());
8610 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8611 if (Err)
8612 return std::move(Err);
8613
8614 return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange,
8615 E->getCaptureDefault(), ToCaptureDefaultLoc,
8617 E->hasExplicitResultType(), ToCaptureInits,
8618 ToEndLoc, E->containsUnexpandedParameterPack());
8619}
8620
8621
8623 Error Err = Error::success();
8624 auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
8625 auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc());
8626 auto ToType = importChecked(Err, E->getType());
8627 if (Err)
8628 return std::move(Err);
8629
8630 SmallVector<Expr *, 4> ToExprs(E->getNumInits());
8631 if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
8632 return std::move(Err);
8633
8634 ASTContext &ToCtx = Importer.getToContext();
8635 InitListExpr *To = new (ToCtx) InitListExpr(
8636 ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc);
8637 To->setType(ToType);
8638
8639 if (E->hasArrayFiller()) {
8640 if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
8641 To->setArrayFiller(*ToFillerOrErr);
8642 else
8643 return ToFillerOrErr.takeError();
8644 }
8645
8646 if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
8647 if (auto ToFDOrErr = import(FromFD))
8648 To->setInitializedFieldInUnion(*ToFDOrErr);
8649 else
8650 return ToFDOrErr.takeError();
8651 }
8652
8653 if (InitListExpr *SyntForm = E->getSyntacticForm()) {
8654 if (auto ToSyntFormOrErr = import(SyntForm))
8655 To->setSyntacticForm(*ToSyntFormOrErr);
8656 else
8657 return ToSyntFormOrErr.takeError();
8658 }
8659
8660 // Copy InitListExprBitfields, which are not handled in the ctor of
8661 // InitListExpr.
8663
8664 return To;
8665}
8666
8669 ExpectedType ToTypeOrErr = import(E->getType());
8670 if (!ToTypeOrErr)
8671 return ToTypeOrErr.takeError();
8672
8673 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8674 if (!ToSubExprOrErr)
8675 return ToSubExprOrErr.takeError();
8676
8677 return new (Importer.getToContext()) CXXStdInitializerListExpr(
8678 *ToTypeOrErr, *ToSubExprOrErr);
8679}
8680
8683 Error Err = Error::success();
8684 auto ToLocation = importChecked(Err, E->getLocation());
8685 auto ToType = importChecked(Err, E->getType());
8686 auto ToConstructor = importChecked(Err, E->getConstructor());
8687 if (Err)
8688 return std::move(Err);
8689
8690 return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
8691 ToLocation, ToType, ToConstructor, E->constructsVBase(),
8692 E->inheritedFromVBase());
8693}
8694
8696 Error Err = Error::success();
8697 auto ToType = importChecked(Err, E->getType());
8698 auto ToCommonExpr = importChecked(Err, E->getCommonExpr());
8699 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8700 if (Err)
8701 return std::move(Err);
8702
8703 return new (Importer.getToContext()) ArrayInitLoopExpr(
8704 ToType, ToCommonExpr, ToSubExpr);
8705}
8706
8708 ExpectedType ToTypeOrErr = import(E->getType());
8709 if (!ToTypeOrErr)
8710 return ToTypeOrErr.takeError();
8711 return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
8712}
8713
8715 ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
8716 if (!ToBeginLocOrErr)
8717 return ToBeginLocOrErr.takeError();
8718
8719 auto ToFieldOrErr = import(E->getField());
8720 if (!ToFieldOrErr)
8721 return ToFieldOrErr.takeError();
8722
8723 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8724 if (!UsedContextOrErr)
8725 return UsedContextOrErr.takeError();
8726
8727 FieldDecl *ToField = *ToFieldOrErr;
8728 assert(ToField->hasInClassInitializer() &&
8729 "Field should have in-class initializer if there is a default init "
8730 "expression that uses it.");
8731 if (!ToField->getInClassInitializer()) {
8732 // The in-class initializer may be not yet set in "To" AST even if the
8733 // field is already there. This must be set here to make construction of
8734 // CXXDefaultInitExpr work.
8735 auto ToInClassInitializerOrErr =
8736 import(E->getField()->getInClassInitializer());
8737 if (!ToInClassInitializerOrErr)
8738 return ToInClassInitializerOrErr.takeError();
8739 ToField->setInClassInitializer(*ToInClassInitializerOrErr);
8740 }
8741
8742 Expr *RewrittenInit = nullptr;
8743 if (E->hasRewrittenInit()) {
8744 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8745 if (!ExprOrErr)
8746 return ExprOrErr.takeError();
8747 RewrittenInit = ExprOrErr.get();
8748 }
8749
8750 return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr,
8751 ToField, *UsedContextOrErr, RewrittenInit);
8752}
8753
8755 Error Err = Error::success();
8756 auto ToType = importChecked(Err, E->getType());
8757 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8758 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
8759 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8760 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8761 auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets());
8762 if (Err)
8763 return std::move(Err);
8764
8765 ExprValueKind VK = E->getValueKind();
8766 CastKind CK = E->getCastKind();
8767 auto ToBasePathOrErr = ImportCastPath(E);
8768 if (!ToBasePathOrErr)
8769 return ToBasePathOrErr.takeError();
8770
8771 if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) {
8773 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
8774 ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc,
8775 ToAngleBrackets);
8776 } else if (isa<CXXDynamicCastExpr>(E)) {
8778 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
8779 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
8780 } else if (isa<CXXReinterpretCastExpr>(E)) {
8782 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
8783 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
8784 } else if (isa<CXXConstCastExpr>(E)) {
8786 Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
8787 ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
8788 } else {
8789 llvm_unreachable("Unknown cast type");
8790 return make_error<ASTImportError>();
8791 }
8792}
8793
8796 Error Err = Error::success();
8797 auto ToType = importChecked(Err, E->getType());
8798 auto ToExprLoc = importChecked(Err, E->getExprLoc());
8799 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
8800 auto ToReplacement = importChecked(Err, E->getReplacement());
8801 if (Err)
8802 return std::move(Err);
8803
8804 return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
8805 ToType, E->getValueKind(), ToExprLoc, ToReplacement, ToAssociatedDecl,
8806 E->getIndex(), E->getPackIndex(), E->isReferenceParameter());
8807}
8808
8810 Error Err = Error::success();
8811 auto ToType = importChecked(Err, E->getType());
8812 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8813 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8814 if (Err)
8815 return std::move(Err);
8816
8818 if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
8819 return std::move(Err);
8820
8821 // According to Sema::BuildTypeTrait(), if E is value-dependent,
8822 // Value is always false.
8823 bool ToValue = (E->isValueDependent() ? false : E->getValue());
8824
8825 return TypeTraitExpr::Create(
8826 Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs,
8827 ToEndLoc, ToValue);
8828}
8829
8831 ExpectedType ToTypeOrErr = import(E->getType());
8832 if (!ToTypeOrErr)
8833 return ToTypeOrErr.takeError();
8834
8835 auto ToSourceRangeOrErr = import(E->getSourceRange());
8836 if (!ToSourceRangeOrErr)
8837 return ToSourceRangeOrErr.takeError();
8838
8839 if (E->isTypeOperand()) {
8840 if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
8841 return new (Importer.getToContext()) CXXTypeidExpr(
8842 *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
8843 else
8844 return ToTSIOrErr.takeError();
8845 }
8846
8847 ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
8848 if (!ToExprOperandOrErr)
8849 return ToExprOperandOrErr.takeError();
8850
8851 return new (Importer.getToContext()) CXXTypeidExpr(
8852 *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
8853}
8854
8856 Error Err = Error::success();
8857
8858 QualType ToType = importChecked(Err, E->getType());
8859 UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
8860 SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
8861 Expr *ToLHS = importChecked(Err, E->getLHS());
8862 SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8863 Expr *ToRHS = importChecked(Err, E->getRHS());
8864 SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
8865
8866 if (Err)
8867 return std::move(Err);
8868
8869 return new (Importer.getToContext())
8870 CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
8871 ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
8872}
8873
8875 CXXMethodDecl *FromMethod) {
8876 Error ImportErrors = Error::success();
8877 for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
8878 if (auto ImportedOrErr = import(FromOverriddenMethod))
8879 ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>(
8880 (*ImportedOrErr)->getCanonicalDecl()));
8881 else
8882 ImportErrors =
8883 joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
8884 }
8885 return ImportErrors;
8886}
8887
8889 ASTContext &FromContext, FileManager &FromFileManager,
8890 bool MinimalImport,
8891 std::shared_ptr<ASTImporterSharedState> SharedState)
8892 : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
8893 ToFileManager(ToFileManager), FromFileManager(FromFileManager),
8894 Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) {
8895
8896 // Create a default state without the lookup table: LLDB case.
8897 if (!SharedState) {
8898 this->SharedState = std::make_shared<ASTImporterSharedState>();
8899 }
8900
8901 ImportedDecls[FromContext.getTranslationUnitDecl()] =
8902 ToContext.getTranslationUnitDecl();
8903}
8904
8905ASTImporter::~ASTImporter() = default;
8906
8907std::optional<unsigned> ASTImporter::getFieldIndex(Decl *F) {
8908 assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
8909 "Try to get field index for non-field.");
8910
8911 auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
8912 if (!Owner)
8913 return std::nullopt;
8914
8915 unsigned Index = 0;
8916 for (const auto *D : Owner->decls()) {
8917 if (D == F)
8918 return Index;
8919
8920 if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D))
8921 ++Index;
8922 }
8923
8924 llvm_unreachable("Field was not found in its parent context.");
8925
8926 return std::nullopt;
8927}
8928
8930ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
8931 // We search in the redecl context because of transparent contexts.
8932 // E.g. a simple C language enum is a transparent context:
8933 // enum E { A, B };
8934 // Now if we had a global variable in the TU
8935 // int A;
8936 // then the enum constant 'A' and the variable 'A' violates ODR.
8937 // We can diagnose this only if we search in the redecl context.
8938 DeclContext *ReDC = DC->getRedeclContext();
8939 if (SharedState->getLookupTable()) {
8941 SharedState->getLookupTable()->lookup(ReDC, Name);
8942 return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
8943 } else {
8944 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
8945 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
8946 // We must search by the slow case of localUncachedLookup because that is
8947 // working even if there is no LookupPtr for the DC. We could use
8948 // DC::buildLookup() to create the LookupPtr, but that would load external
8949 // decls again, we must avoid that case.
8950 // Also, even if we had the LookupPtr, we must find Decls which are not
8951 // in the LookupPtr, so we need the slow case.
8952 // These cases are handled in ASTImporterLookupTable, but we cannot use
8953 // that with LLDB since that traverses through the AST which initiates the
8954 // load of external decls again via DC::decls(). And again, we must avoid
8955 // loading external decls during the import.
8956 if (Result.empty())
8957 ReDC->localUncachedLookup(Name, Result);
8958 return Result;
8959 }
8960}
8961
8962void ASTImporter::AddToLookupTable(Decl *ToD) {
8963 SharedState->addDeclToLookup(ToD);
8964}
8965
8967 // Import the decl using ASTNodeImporter.
8968 ASTNodeImporter Importer(*this);
8969 return Importer.Visit(FromD);
8970}
8971
8973 MapImported(FromD, ToD);
8974}
8975
8978 if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) {
8979 if (Expected<Expr *> R = Import(CLE))
8980 return ExprWithCleanups::CleanupObject(cast<CompoundLiteralExpr>(*R));
8981 }
8982
8983 // FIXME: Handle BlockDecl when we implement importing BlockExpr in
8984 // ASTNodeImporter.
8985 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
8986}
8987
8989 if (!FromT)
8990 return FromT;
8991
8992 // Check whether we've already imported this type.
8993 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
8994 ImportedTypes.find(FromT);
8995 if (Pos != ImportedTypes.end())
8996 return Pos->second;
8997
8998 // Import the type.
8999 ASTNodeImporter Importer(*this);
9000 ExpectedType ToTOrErr = Importer.Visit(FromT);
9001 if (!ToTOrErr)
9002 return ToTOrErr.takeError();
9003
9004 // Record the imported type.
9005 ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9006
9007 return ToTOrErr->getTypePtr();
9008}
9009
9011 if (FromT.isNull())
9012 return QualType{};
9013
9014 ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9015 if (!ToTyOrErr)
9016 return ToTyOrErr.takeError();
9017
9018 return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9019}
9020
9022 if (!FromTSI)
9023 return FromTSI;
9024
9025 // FIXME: For now we just create a "trivial" type source info based
9026 // on the type and a single location. Implement a real version of this.
9027 ExpectedType TOrErr = Import(FromTSI->getType());
9028 if (!TOrErr)
9029 return TOrErr.takeError();
9030 ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9031 if (!BeginLocOrErr)
9032 return BeginLocOrErr.takeError();
9033
9034 return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9035}
9036
9037namespace {
9038// To use this object, it should be created before the new attribute is created,
9039// and destructed after it is created. The construction already performs the
9040// import of the data.
9041template <typename T> struct AttrArgImporter {
9042 AttrArgImporter(const AttrArgImporter<T> &) = delete;
9043 AttrArgImporter(AttrArgImporter<T> &&) = default;
9044 AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9045 AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9046
9047 AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9048 : To(I.importChecked(Err, From)) {}
9049
9050 const T &value() { return To; }
9051
9052private:
9053 T To;
9054};
9055
9056// To use this object, it should be created before the new attribute is created,
9057// and destructed after it is created. The construction already performs the
9058// import of the data. The array data is accessible in a pointer form, this form
9059// is used by the attribute classes. This object should be created once for the
9060// array data to be imported (the array size is not imported, just copied).
9061template <typename T> struct AttrArgArrayImporter {
9062 AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9063 AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9064 AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9065 AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9066
9067 AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9068 const llvm::iterator_range<T *> &From,
9069 unsigned ArraySize) {
9070 if (Err)
9071 return;
9072 To.reserve(ArraySize);
9073 Err = I.ImportContainerChecked(From, To);
9074 }
9075
9076 T *value() { return To.data(); }
9077
9078private:
9080};
9081
9082class AttrImporter {
9083 Error Err{Error::success()};
9084 Attr *ToAttr = nullptr;
9085 ASTImporter &Importer;
9086 ASTNodeImporter NImporter;
9087
9088public:
9089 AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9090
9091 // Useful for accessing the imported attribute.
9092 template <typename T> T *castAttrAs() { return cast<T>(ToAttr); }
9093 template <typename T> const T *castAttrAs() const { return cast<T>(ToAttr); }
9094
9095 // Create an "importer" for an attribute parameter.
9096 // Result of the 'value()' of that object is to be passed to the function
9097 // 'importAttr', in the order that is expected by the attribute class.
9098 template <class T> AttrArgImporter<T> importArg(const T &From) {
9099 return AttrArgImporter<T>(NImporter, Err, From);
9100 }
9101
9102 // Create an "importer" for an attribute parameter that has array type.
9103 // Result of the 'value()' of that object is to be passed to the function
9104 // 'importAttr', then the size of the array as next argument.
9105 template <typename T>
9106 AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9107 unsigned ArraySize) {
9108 return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9109 }
9110
9111 // Create an attribute object with the specified arguments.
9112 // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9113 // should be values that are passed to the 'Create' function of the attribute.
9114 // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9115 // used here.) As much data is copied or imported from the old attribute
9116 // as possible. The passed arguments should be already imported.
9117 // If an import error happens, the internal error is set to it, and any
9118 // further import attempt is ignored.
9119 template <typename T, typename... Arg>
9120 void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9121 static_assert(std::is_base_of<Attr, T>::value,
9122 "T should be subclass of Attr.");
9123 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9124
9125 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9126 const IdentifierInfo *ToScopeName =
9127 Importer.Import(FromAttr->getScopeName());
9128 SourceRange ToAttrRange =
9129 NImporter.importChecked(Err, FromAttr->getRange());
9130 SourceLocation ToScopeLoc =
9131 NImporter.importChecked(Err, FromAttr->getScopeLoc());
9132
9133 if (Err)
9134 return;
9135
9136 AttributeCommonInfo ToI(ToAttrName, ToScopeName, ToAttrRange, ToScopeLoc,
9137 FromAttr->getParsedKind(), FromAttr->getForm());
9138 // The "SemanticSpelling" is not needed to be passed to the constructor.
9139 // That value is recalculated from the SpellingListIndex if needed.
9140 ToAttr = T::Create(Importer.getToContext(),
9141 std::forward<Arg>(ImportedArg)..., ToI);
9142
9143 ToAttr->setImplicit(FromAttr->isImplicit());
9144 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9145 if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9146 ToInheritableAttr->setInherited(FromAttr->isInherited());
9147 }
9148
9149 // Create a clone of the 'FromAttr' and import its source range only.
9150 // This causes objects with invalid references to be created if the 'FromAttr'
9151 // contains other data that should be imported.
9152 void cloneAttr(const Attr *FromAttr) {
9153 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9154
9155 SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9156 if (Err)
9157 return;
9158
9159 ToAttr = FromAttr->clone(Importer.getToContext());
9160 ToAttr->setRange(ToRange);
9161 ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9162 }
9163
9164 // Get the result of the previous import attempt (can be used only once).
9165 llvm::Expected<Attr *> getResult() && {
9166 if (Err)
9167 return std::move(Err);
9168 assert(ToAttr && "Attribute should be created.");
9169 return ToAttr;
9170 }
9171};
9172} // namespace
9173
9175 AttrImporter AI(*this);
9176
9177 // FIXME: Is there some kind of AttrVisitor to use here?
9178 switch (FromAttr->getKind()) {
9179 case attr::Aligned: {
9180 auto *From = cast<AlignedAttr>(FromAttr);
9181 if (From->isAlignmentExpr())
9182 AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9183 else
9184 AI.importAttr(From, false,
9185 AI.importArg(From->getAlignmentType()).value());
9186 break;
9187 }
9188
9189 case attr::AlignValue: {
9190 auto *From = cast<AlignValueAttr>(FromAttr);
9191 AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9192 break;
9193 }
9194
9195 case attr::Format: {
9196 const auto *From = cast<FormatAttr>(FromAttr);
9197 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9198 From->getFirstArg());
9199 break;
9200 }
9201
9202 case attr::EnableIf: {
9203 const auto *From = cast<EnableIfAttr>(FromAttr);
9204 AI.importAttr(From, AI.importArg(From->getCond()).value(),
9205 From->getMessage());
9206 break;
9207 }
9208
9209 case attr::AssertCapability: {
9210 const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9211 AI.importAttr(From,
9212 AI.importArrayArg(From->args(), From->args_size()).value(),
9213 From->args_size());
9214 break;
9215 }
9216 case attr::AcquireCapability: {
9217 const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9218 AI.importAttr(From,
9219 AI.importArrayArg(From->args(), From->args_size()).value(),
9220 From->args_size());
9221 break;
9222 }
9223 case attr::TryAcquireCapability: {
9224 const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9225 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9226 AI.importArrayArg(From->args(), From->args_size()).value(),
9227 From->args_size());
9228 break;
9229 }
9230 case attr::ReleaseCapability: {
9231 const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9232 AI.importAttr(From,
9233 AI.importArrayArg(From->args(), From->args_size()).value(),
9234 From->args_size());
9235 break;
9236 }
9237 case attr::RequiresCapability: {
9238 const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9239 AI.importAttr(From,
9240 AI.importArrayArg(From->args(), From->args_size()).value(),
9241 From->args_size());
9242 break;
9243 }
9244 case attr::GuardedBy: {
9245 const auto *From = cast<GuardedByAttr>(FromAttr);
9246 AI.importAttr(From, AI.importArg(From->getArg()).value());
9247 break;
9248 }
9249 case attr::PtGuardedBy: {
9250 const auto *From = cast<PtGuardedByAttr>(FromAttr);
9251 AI.importAttr(From, AI.importArg(From->getArg()).value());
9252 break;
9253 }
9254 case attr::AcquiredAfter: {
9255 const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9256 AI.importAttr(From,
9257 AI.importArrayArg(From->args(), From->args_size()).value(),
9258 From->args_size());
9259 break;
9260 }
9261 case attr::AcquiredBefore: {
9262 const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9263 AI.importAttr(From,
9264 AI.importArrayArg(From->args(), From->args_size()).value(),
9265 From->args_size());
9266 break;
9267 }
9268 case attr::AssertExclusiveLock: {
9269 const auto *From = cast<AssertExclusiveLockAttr>(FromAttr);
9270 AI.importAttr(From,
9271 AI.importArrayArg(From->args(), From->args_size()).value(),
9272 From->args_size());
9273 break;
9274 }
9275 case attr::AssertSharedLock: {
9276 const auto *From = cast<AssertSharedLockAttr>(FromAttr);
9277 AI.importAttr(From,
9278 AI.importArrayArg(From->args(), From->args_size()).value(),
9279 From->args_size());
9280 break;
9281 }
9282 case attr::ExclusiveTrylockFunction: {
9283 const auto *From = cast<ExclusiveTrylockFunctionAttr>(FromAttr);
9284 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9285 AI.importArrayArg(From->args(), From->args_size()).value(),
9286 From->args_size());
9287 break;
9288 }
9289 case attr::SharedTrylockFunction: {
9290 const auto *From = cast<SharedTrylockFunctionAttr>(FromAttr);
9291 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9292 AI.importArrayArg(From->args(), From->args_size()).value(),
9293 From->args_size());
9294 break;
9295 }
9296 case attr::LockReturned: {
9297 const auto *From = cast<LockReturnedAttr>(FromAttr);
9298 AI.importAttr(From, AI.importArg(From->getArg()).value());
9299 break;
9300 }
9301 case attr::LocksExcluded: {
9302 const auto *From = cast<LocksExcludedAttr>(FromAttr);
9303 AI.importAttr(From,
9304 AI.importArrayArg(From->args(), From->args_size()).value(),
9305 From->args_size());
9306 break;
9307 }
9308 case attr::CountedBy: {
9309 AI.cloneAttr(FromAttr);
9310 const auto *CBA = cast<CountedByAttr>(FromAttr);
9311 Expected<SourceRange> SR = Import(CBA->getCountedByFieldLoc()).get();
9312 if (!SR)
9313 return SR.takeError();
9314 AI.castAttrAs<CountedByAttr>()->setCountedByFieldLoc(SR.get());
9315 break;
9316 }
9317
9318 default: {
9319 // The default branch works for attributes that have no arguments to import.
9320 // FIXME: Handle every attribute type that has arguments of type to import
9321 // (most often Expr* or Decl* or type) in the switch above.
9322 AI.cloneAttr(FromAttr);
9323 break;
9324 }
9325 }
9326
9327 return std::move(AI).getResult();
9328}
9329
9331 return ImportedDecls.lookup(FromD);
9332}
9333
9335 auto FromDPos = ImportedFromDecls.find(ToD);
9336 if (FromDPos == ImportedFromDecls.end())
9337 return nullptr;
9338 return FromDPos->second->getTranslationUnitDecl();
9339}
9340
9341Error ASTImporter::ImportAttrs(Decl *ToD, Decl *FromD) {
9342 if (!FromD->hasAttrs() || ToD->hasAttrs())
9343 return Error::success();
9344 for (const Attr *FromAttr : FromD->getAttrs()) {
9345 auto ToAttrOrErr = Import(FromAttr);
9346 if (ToAttrOrErr)
9347 ToD->addAttr(*ToAttrOrErr);
9348 else
9349 return ToAttrOrErr.takeError();
9350 }
9351 return Error::success();
9352}
9353
9355 if (!FromD)
9356 return nullptr;
9357
9358 // Push FromD to the stack, and remove that when we return.
9359 ImportPath.push(FromD);
9360 auto ImportPathBuilder =
9361 llvm::make_scope_exit([this]() { ImportPath.pop(); });
9362
9363 // Check whether there was a previous failed import.
9364 // If yes return the existing error.
9365 if (auto Error = getImportDeclErrorIfAny(FromD))
9366 return make_error<ASTImportError>(*Error);
9367
9368 // Check whether we've already imported this declaration.
9369 Decl *ToD = GetAlreadyImportedOrNull(FromD);
9370 if (ToD) {
9371 // Already imported (possibly from another TU) and with an error.
9372 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9373 setImportDeclError(FromD, *Error);
9374 return make_error<ASTImportError>(*Error);
9375 }
9376
9377 // If FromD has some updated flags after last import, apply it.
9378 updateFlags(FromD, ToD);
9379 // If we encounter a cycle during an import then we save the relevant part
9380 // of the import path associated to the Decl.
9381 if (ImportPath.hasCycleAtBack())
9382 SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9383 return ToD;
9384 }
9385
9386 // Import the declaration.
9387 ExpectedDecl ToDOrErr = ImportImpl(FromD);
9388 if (!ToDOrErr) {
9389 // Failed to import.
9390
9391 auto Pos = ImportedDecls.find(FromD);
9392 if (Pos != ImportedDecls.end()) {
9393 // Import failed after the object was created.
9394 // Remove all references to it.
9395 auto *ToD = Pos->second;
9396 ImportedDecls.erase(Pos);
9397
9398 // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9399 // (e.g. with namespaces) that several decls from the 'from' context are
9400 // mapped to the same decl in the 'to' context. If we removed entries
9401 // from the LookupTable here then we may end up removing them multiple
9402 // times.
9403
9404 // The Lookuptable contains decls only which are in the 'to' context.
9405 // Remove from the Lookuptable only if it is *imported* into the 'to'
9406 // context (and do not remove it if it was added during the initial
9407 // traverse of the 'to' context).
9408 auto PosF = ImportedFromDecls.find(ToD);
9409 if (PosF != ImportedFromDecls.end()) {
9410 // In the case of TypedefNameDecl we create the Decl first and only
9411 // then we import and set its DeclContext. So, the DC might not be set
9412 // when we reach here.
9413 if (ToD->getDeclContext())
9414 SharedState->removeDeclFromLookup(ToD);
9415 ImportedFromDecls.erase(PosF);
9416 }
9417
9418 // FIXME: AST may contain remaining references to the failed object.
9419 // However, the ImportDeclErrors in the shared state contains all the
9420 // failed objects together with their error.
9421 }
9422
9423 // Error encountered for the first time.
9424 // After takeError the error is not usable any more in ToDOrErr.
9425 // Get a copy of the error object (any more simple solution for this?).
9426 ASTImportError ErrOut;
9427 handleAllErrors(ToDOrErr.takeError(),
9428 [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9429 setImportDeclError(FromD, ErrOut);
9430 // Set the error for the mapped to Decl, which is in the "to" context.
9431 if (Pos != ImportedDecls.end())
9432 SharedState->setImportDeclError(Pos->second, ErrOut);
9433
9434 // Set the error for all nodes which have been created before we
9435 // recognized the error.
9436 for (const auto &Path : SavedImportPaths[FromD]) {
9437 // The import path contains import-dependency nodes first.
9438 // Save the node that was imported as dependency of the current node.
9439 Decl *PrevFromDi = FromD;
9440 for (Decl *FromDi : Path) {
9441 // Begin and end of the path equals 'FromD', skip it.
9442 if (FromDi == FromD)
9443 continue;
9444 // We should not set import error on a node and all following nodes in
9445 // the path if child import errors are ignored.
9446 if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9447 PrevFromDi))
9448 break;
9449 PrevFromDi = FromDi;
9450 setImportDeclError(FromDi, ErrOut);
9451 //FIXME Should we remove these Decls from ImportedDecls?
9452 // Set the error for the mapped to Decl, which is in the "to" context.
9453 auto Ii = ImportedDecls.find(FromDi);
9454 if (Ii != ImportedDecls.end())
9455 SharedState->setImportDeclError(Ii->second, ErrOut);
9456 // FIXME Should we remove these Decls from the LookupTable,
9457 // and from ImportedFromDecls?
9458 }
9459 }
9460 SavedImportPaths.erase(FromD);
9461
9462 // Do not return ToDOrErr, error was taken out of it.
9463 return make_error<ASTImportError>(ErrOut);
9464 }
9465
9466 ToD = *ToDOrErr;
9467
9468 // FIXME: Handle the "already imported with error" case. We can get here
9469 // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
9470 // previously failed create was requested).
9471 // Later GetImportedOrCreateDecl can be updated to return the error.
9472 if (!ToD) {
9473 auto Err = getImportDeclErrorIfAny(FromD);
9474 assert(Err);
9475 return make_error<ASTImportError>(*Err);
9476 }
9477
9478 // We could import from the current TU without error. But previously we
9479 // already had imported a Decl as `ToD` from another TU (with another
9480 // ASTImporter object) and with an error.
9481 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9482 setImportDeclError(FromD, *Error);
9483 return make_error<ASTImportError>(*Error);
9484 }
9485 // Make sure that ImportImpl registered the imported decl.
9486 assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
9487 if (auto Error = ImportAttrs(ToD, FromD))
9488 return std::move(Error);
9489
9490 // Notify subclasses.
9491 Imported(FromD, ToD);
9492
9493 updateFlags(FromD, ToD);
9494 SavedImportPaths.erase(FromD);
9495 return ToDOrErr;
9496}
9497
9500 return ASTNodeImporter(*this).ImportInheritedConstructor(From);
9501}
9502
9504 if (!FromDC)
9505 return FromDC;
9506
9507 ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
9508 if (!ToDCOrErr)
9509 return ToDCOrErr.takeError();
9510 auto *ToDC = cast<DeclContext>(*ToDCOrErr);
9511
9512 // When we're using a record/enum/Objective-C class/protocol as a context, we
9513 // need it to have a definition.
9514 if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
9515 auto *FromRecord = cast<RecordDecl>(FromDC);
9516 if (ToRecord->isCompleteDefinition())
9517 return ToDC;
9518
9519 // If FromRecord is not defined we need to force it to be.
9520 // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
9521 // it will start the definition but we never finish it.
9522 // If there are base classes they won't be imported and we will
9523 // be missing anything that we inherit from those bases.
9524 if (FromRecord->getASTContext().getExternalSource() &&
9525 !FromRecord->isCompleteDefinition())
9526 FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
9527
9528 if (FromRecord->isCompleteDefinition())
9529 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9530 FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
9531 return std::move(Err);
9532 } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
9533 auto *FromEnum = cast<EnumDecl>(FromDC);
9534 if (ToEnum->isCompleteDefinition()) {
9535 // Do nothing.
9536 } else if (FromEnum->isCompleteDefinition()) {
9537 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9538 FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
9539 return std::move(Err);
9540 } else {
9541 CompleteDecl(ToEnum);
9542 }
9543 } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
9544 auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
9545 if (ToClass->getDefinition()) {
9546 // Do nothing.
9547 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
9548 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9549 FromDef, ToClass, ASTNodeImporter::IDK_Basic))
9550 return std::move(Err);
9551 } else {
9552 CompleteDecl(ToClass);
9553 }
9554 } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
9555 auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
9556 if (ToProto->getDefinition()) {
9557 // Do nothing.
9558 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
9559 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9560 FromDef, ToProto, ASTNodeImporter::IDK_Basic))
9561 return std::move(Err);
9562 } else {
9563 CompleteDecl(ToProto);
9564 }
9565 }
9566
9567 return ToDC;
9568}
9569
9571 if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
9572 return cast_or_null<Expr>(*ToSOrErr);
9573 else
9574 return ToSOrErr.takeError();
9575}
9576
9578 if (!FromS)
9579 return nullptr;
9580
9581 // Check whether we've already imported this statement.
9582 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
9583 if (Pos != ImportedStmts.end())
9584 return Pos->second;
9585
9586 // Import the statement.
9587 ASTNodeImporter Importer(*this);
9588 ExpectedStmt ToSOrErr = Importer.Visit(FromS);
9589 if (!ToSOrErr)
9590 return ToSOrErr;
9591
9592 if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
9593 auto *FromE = cast<Expr>(FromS);
9594 // Copy ExprBitfields, which may not be handled in Expr subclasses
9595 // constructors.
9596 ToE->setValueKind(FromE->getValueKind());
9597 ToE->setObjectKind(FromE->getObjectKind());
9598 ToE->setDependence(FromE->getDependence());
9599 }
9600
9601 // Record the imported statement object.
9602 ImportedStmts[FromS] = *ToSOrErr;
9603 return ToSOrErr;
9604}
9605
9608 if (!FromNNS)
9609 return nullptr;
9610
9611 NestedNameSpecifier *Prefix = nullptr;
9612 if (Error Err = importInto(Prefix, FromNNS->getPrefix()))
9613 return std::move(Err);
9614
9615 switch (FromNNS->getKind()) {
9617 assert(FromNNS->getAsIdentifier() && "NNS should contain identifier.");
9618 return NestedNameSpecifier::Create(ToContext, Prefix,
9619 Import(FromNNS->getAsIdentifier()));
9620
9622 if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) {
9623 return NestedNameSpecifier::Create(ToContext, Prefix,
9624 cast<NamespaceDecl>(*NSOrErr));
9625 } else
9626 return NSOrErr.takeError();
9627
9629 if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias()))
9630 return NestedNameSpecifier::Create(ToContext, Prefix,
9631 cast<NamespaceAliasDecl>(*NSADOrErr));
9632 else
9633 return NSADOrErr.takeError();
9634
9636 return NestedNameSpecifier::GlobalSpecifier(ToContext);
9637
9639 if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl()))
9640 return NestedNameSpecifier::SuperSpecifier(ToContext,
9641 cast<CXXRecordDecl>(*RDOrErr));
9642 else
9643 return RDOrErr.takeError();
9644
9647 if (ExpectedTypePtr TyOrErr = Import(FromNNS->getAsType())) {
9648 bool TSTemplate =
9650 return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate,
9651 *TyOrErr);
9652 } else {
9653 return TyOrErr.takeError();
9654 }
9655 }
9656
9657 llvm_unreachable("Invalid nested name specifier kind");
9658}
9659
9662 // Copied from NestedNameSpecifier mostly.
9664 NestedNameSpecifierLoc NNS = FromNNS;
9665
9666 // Push each of the nested-name-specifiers's onto a stack for
9667 // serialization in reverse order.
9668 while (NNS) {
9669 NestedNames.push_back(NNS);
9670 NNS = NNS.getPrefix();
9671 }
9672
9674
9675 while (!NestedNames.empty()) {
9676 NNS = NestedNames.pop_back_val();
9677 NestedNameSpecifier *Spec = nullptr;
9678 if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
9679 return std::move(Err);
9680
9682
9683 SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
9684 if (Kind != NestedNameSpecifier::Super) {
9685 if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
9686 return std::move(Err);
9687
9688 if (Kind != NestedNameSpecifier::Global)
9689 if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
9690 return std::move(Err);
9691 }
9692
9693 switch (Kind) {
9695 Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc,
9696 ToLocalEndLoc);
9697 break;
9698
9700 Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc,
9701 ToLocalEndLoc);
9702 break;
9703
9705 Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(),
9706 ToLocalBeginLoc, ToLocalEndLoc);
9707 break;
9708
9711 SourceLocation ToTLoc;
9712 if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc()))
9713 return std::move(Err);
9715 QualType(Spec->getAsType(), 0), ToTLoc);
9717 // ToLocalBeginLoc is here the location of the 'template' keyword.
9718 Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(),
9719 ToLocalEndLoc);
9720 else
9721 // No location for 'template' keyword here.
9722 Builder.Extend(getToContext(), SourceLocation{}, TSI->getTypeLoc(),
9723 ToLocalEndLoc);
9724 break;
9725 }
9726
9728 Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
9729 break;
9730
9732 auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
9733 if (!ToSourceRangeOrErr)
9734 return ToSourceRangeOrErr.takeError();
9735
9736 Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(),
9737 ToSourceRangeOrErr->getBegin(),
9738 ToSourceRangeOrErr->getEnd());
9739 }
9740 }
9741 }
9742
9743 return Builder.getWithLocInContext(getToContext());
9744}
9745
9747 switch (From.getKind()) {
9749 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
9750 return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
9751 else
9752 return ToTemplateOrErr.takeError();
9753
9756 UnresolvedSet<2> ToTemplates;
9757 for (auto *I : *FromStorage) {
9758 if (auto ToOrErr = Import(I))
9759 ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
9760 else
9761 return ToOrErr.takeError();
9762 }
9763 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
9764 ToTemplates.end());
9765 }
9766
9769 auto DeclNameOrErr = Import(FromStorage->getDeclName());
9770 if (!DeclNameOrErr)
9771 return DeclNameOrErr.takeError();
9772 return ToContext.getAssumedTemplateName(*DeclNameOrErr);
9773 }
9774
9777 auto QualifierOrErr = Import(QTN->getQualifier());
9778 if (!QualifierOrErr)
9779 return QualifierOrErr.takeError();
9780 auto TNOrErr = Import(QTN->getUnderlyingTemplate());
9781 if (!TNOrErr)
9782 return TNOrErr.takeError();
9783 return ToContext.getQualifiedTemplateName(
9784 *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
9785 }
9786
9789 auto QualifierOrErr = Import(DTN->getQualifier());
9790 if (!QualifierOrErr)
9791 return QualifierOrErr.takeError();
9792
9793 if (DTN->isIdentifier()) {
9794 return ToContext.getDependentTemplateName(*QualifierOrErr,
9795 Import(DTN->getIdentifier()));
9796 }
9797
9798 return ToContext.getDependentTemplateName(*QualifierOrErr,
9799 DTN->getOperator());
9800 }
9801
9805 auto ReplacementOrErr = Import(Subst->getReplacement());
9806 if (!ReplacementOrErr)
9807 return ReplacementOrErr.takeError();
9808
9809 auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
9810 if (!AssociatedDeclOrErr)
9811 return AssociatedDeclOrErr.takeError();
9812
9813 return ToContext.getSubstTemplateTemplateParm(
9814 *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
9815 Subst->getPackIndex());
9816 }
9817
9821 ASTNodeImporter Importer(*this);
9822 auto ArgPackOrErr =
9823 Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
9824 if (!ArgPackOrErr)
9825 return ArgPackOrErr.takeError();
9826
9827 auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
9828 if (!AssociatedDeclOrErr)
9829 return AssociatedDeclOrErr.takeError();
9830
9831 return ToContext.getSubstTemplateTemplateParmPack(
9832 *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
9833 SubstPack->getFinal());
9834 }
9836 auto UsingOrError = Import(From.getAsUsingShadowDecl());
9837 if (!UsingOrError)
9838 return UsingOrError.takeError();
9839 return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
9840 }
9841 }
9842
9843 llvm_unreachable("Invalid template name kind");
9844}
9845
9847 if (FromLoc.isInvalid())
9848 return SourceLocation{};
9849
9850 SourceManager &FromSM = FromContext.getSourceManager();
9851 bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
9852
9853 std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc);
9854 Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
9855 if (!ToFileIDOrErr)
9856 return ToFileIDOrErr.takeError();
9857 SourceManager &ToSM = ToContext.getSourceManager();
9858 return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
9859}
9860
9862 SourceLocation ToBegin, ToEnd;
9863 if (Error Err = importInto(ToBegin, FromRange.getBegin()))
9864 return std::move(Err);
9865 if (Error Err = importInto(ToEnd, FromRange.getEnd()))
9866 return std::move(Err);
9867
9868 return SourceRange(ToBegin, ToEnd);
9869}
9870
9872 llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
9873 if (Pos != ImportedFileIDs.end())
9874 return Pos->second;
9875
9876 SourceManager &FromSM = FromContext.getSourceManager();
9877 SourceManager &ToSM = ToContext.getSourceManager();
9878 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
9879
9880 // Map the FromID to the "to" source manager.
9881 FileID ToID;
9882 if (FromSLoc.isExpansion()) {
9883 const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
9884 ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
9885 if (!ToSpLoc)
9886 return ToSpLoc.takeError();
9887 ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
9888 if (!ToExLocS)
9889 return ToExLocS.takeError();
9890 unsigned ExLength = FromSM.getFileIDSize(FromID);
9891 SourceLocation MLoc;
9892 if (FromEx.isMacroArgExpansion()) {
9893 MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
9894 } else {
9895 if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
9896 MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
9897 FromEx.isExpansionTokenRange());
9898 else
9899 return ToExLocE.takeError();
9900 }
9901 ToID = ToSM.getFileID(MLoc);
9902 } else {
9903 const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
9904
9905 if (!IsBuiltin && !Cache->BufferOverridden) {
9906 // Include location of this file.
9907 ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
9908 if (!ToIncludeLoc)
9909 return ToIncludeLoc.takeError();
9910
9911 // Every FileID that is not the main FileID needs to have a valid include
9912 // location so that the include chain points to the main FileID. When
9913 // importing the main FileID (which has no include location), we need to
9914 // create a fake include location in the main file to keep this property
9915 // intact.
9916 SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
9917 if (FromID == FromSM.getMainFileID())
9918 ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
9919
9920 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
9921 // FIXME: We probably want to use getVirtualFile(), so we don't hit the
9922 // disk again
9923 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
9924 // than mmap the files several times.
9925 auto Entry =
9926 ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
9927 // FIXME: The filename may be a virtual name that does probably not
9928 // point to a valid file and we get no Entry here. In this case try with
9929 // the memory buffer below.
9930 if (Entry)
9931 ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
9932 FromSLoc.getFile().getFileCharacteristic());
9933 }
9934 }
9935
9936 if (ToID.isInvalid() || IsBuiltin) {
9937 // FIXME: We want to re-use the existing MemoryBuffer!
9938 std::optional<llvm::MemoryBufferRef> FromBuf =
9939 Cache->getBufferOrNone(FromContext.getDiagnostics(),
9940 FromSM.getFileManager(), SourceLocation{});
9941 if (!FromBuf)
9942 return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
9943
9944 std::unique_ptr<llvm::MemoryBuffer> ToBuf =
9945 llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
9946 FromBuf->getBufferIdentifier());
9947 ToID = ToSM.createFileID(std::move(ToBuf),
9948 FromSLoc.getFile().getFileCharacteristic());
9949 }
9950 }
9951
9952 assert(ToID.isValid() && "Unexpected invalid fileID was created.");
9953
9954 ImportedFileIDs[FromID] = ToID;
9955 return ToID;
9956}
9957
9959 ExpectedExpr ToExprOrErr = Import(From->getInit());
9960 if (!ToExprOrErr)
9961 return ToExprOrErr.takeError();
9962
9963 auto LParenLocOrErr = Import(From->getLParenLoc());
9964 if (!LParenLocOrErr)
9965 return LParenLocOrErr.takeError();
9966
9967 auto RParenLocOrErr = Import(From->getRParenLoc());
9968 if (!RParenLocOrErr)
9969 return RParenLocOrErr.takeError();
9970
9971 if (From->isBaseInitializer()) {
9972 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
9973 if (!ToTInfoOrErr)
9974 return ToTInfoOrErr.takeError();
9975
9976 SourceLocation EllipsisLoc;
9977 if (From->isPackExpansion())
9978 if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
9979 return std::move(Err);
9980
9981 return new (ToContext) CXXCtorInitializer(
9982 ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
9983 *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
9984 } else if (From->isMemberInitializer()) {
9985 ExpectedDecl ToFieldOrErr = Import(From->getMember());
9986 if (!ToFieldOrErr)
9987 return ToFieldOrErr.takeError();
9988
9989 auto MemberLocOrErr = Import(From->getMemberLocation());
9990 if (!MemberLocOrErr)
9991 return MemberLocOrErr.takeError();
9992
9993 return new (ToContext) CXXCtorInitializer(
9994 ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
9995 *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
9996 } else if (From->isIndirectMemberInitializer()) {
9997 ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
9998 if (!ToIFieldOrErr)
9999 return ToIFieldOrErr.takeError();
10000
10001 auto MemberLocOrErr = Import(From->getMemberLocation());
10002 if (!MemberLocOrErr)
10003 return MemberLocOrErr.takeError();
10004
10005 return new (ToContext) CXXCtorInitializer(
10006 ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10007 *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10008 } else if (From->isDelegatingInitializer()) {
10009 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10010 if (!ToTInfoOrErr)
10011 return ToTInfoOrErr.takeError();
10012
10013 return new (ToContext)
10014 CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10015 *ToExprOrErr, *RParenLocOrErr);
10016 } else {
10017 // FIXME: assert?
10018 return make_error<ASTImportError>();
10019 }
10020}
10021
10024 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10025 if (Pos != ImportedCXXBaseSpecifiers.end())
10026 return Pos->second;
10027
10028 Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10029 if (!ToSourceRange)
10030 return ToSourceRange.takeError();
10032 if (!ToTSI)
10033 return ToTSI.takeError();
10034 ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10035 if (!ToEllipsisLoc)
10036 return ToEllipsisLoc.takeError();
10037 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10038 *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10039 BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10040 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10041 return Imported;
10042}
10043
10045 ASTNodeImporter Importer(*this);
10046 return Importer.ImportAPValue(FromValue);
10047}
10048
10050 ExpectedDecl ToOrErr = Import(From);
10051 if (!ToOrErr)
10052 return ToOrErr.takeError();
10053 Decl *To = *ToOrErr;
10054
10055 auto *FromDC = cast<DeclContext>(From);
10056 ASTNodeImporter Importer(*this);
10057
10058 if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10059 if (!ToRecord->getDefinition()) {
10060 return Importer.ImportDefinition(
10061 cast<RecordDecl>(FromDC), ToRecord,
10063 }
10064 }
10065
10066 if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10067 if (!ToEnum->getDefinition()) {
10068 return Importer.ImportDefinition(
10069 cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything);
10070 }
10071 }
10072
10073 if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10074 if (!ToIFace->getDefinition()) {
10075 return Importer.ImportDefinition(
10076 cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10078 }
10079 }
10080
10081 if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10082 if (!ToProto->getDefinition()) {
10083 return Importer.ImportDefinition(
10084 cast<ObjCProtocolDecl>(FromDC), ToProto,
10086 }
10087 }
10088
10089 return Importer.ImportDeclContext(FromDC, true);
10090}
10091
10093 if (!FromName)
10094 return DeclarationName{};
10095
10096 switch (FromName.getNameKind()) {
10098 return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10099
10103 if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10104 return DeclarationName(*ToSelOrErr);
10105 else
10106 return ToSelOrErr.takeError();
10107
10109 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10110 return ToContext.DeclarationNames.getCXXConstructorName(
10111 ToContext.getCanonicalType(*ToTyOrErr));
10112 else
10113 return ToTyOrErr.takeError();
10114 }
10115
10117 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10118 return ToContext.DeclarationNames.getCXXDestructorName(
10119 ToContext.getCanonicalType(*ToTyOrErr));
10120 else
10121 return ToTyOrErr.takeError();
10122 }
10123
10125 if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10127 cast<TemplateDecl>(*ToTemplateOrErr));
10128 else
10129 return ToTemplateOrErr.takeError();
10130 }
10131
10133 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10135 ToContext.getCanonicalType(*ToTyOrErr));
10136 else
10137 return ToTyOrErr.takeError();
10138 }
10139
10141 return ToContext.DeclarationNames.getCXXOperatorName(
10142 FromName.getCXXOverloadedOperator());
10143
10146 Import(FromName.getCXXLiteralIdentifier()));
10147
10149 // FIXME: STATICS!
10151 }
10152
10153 llvm_unreachable("Invalid DeclarationName Kind!");
10154}
10155
10157 if (!FromId)
10158 return nullptr;
10159
10160 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10161
10162 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10163 ToId->setBuiltinID(FromId->getBuiltinID());
10164
10165 return ToId;
10166}
10167
10169 if (FromSel.isNull())
10170 return Selector{};
10171
10173 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10174 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10175 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10176 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10177}
10178
10182 llvm::Error Err = llvm::Error::success();
10183 auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10184 for (unsigned Idx = 0; Idx < Size; Idx++) {
10185 APValue Tmp = importChecked(Err, From[Idx]);
10186 To[Idx] = Tmp;
10187 }
10188 };
10189 switch (FromValue.getKind()) {
10190 case APValue::None:
10192 case APValue::Int:
10193 case APValue::Float:
10197 Result = FromValue;
10198 break;
10199 case APValue::Vector: {
10200 Result.MakeVector();
10202 Result.setVectorUninit(FromValue.getVectorLength());
10203 ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10204 Elts.data(), FromValue.getVectorLength());
10205 break;
10206 }
10207 case APValue::Array:
10208 Result.MakeArray(FromValue.getArrayInitializedElts(),
10209 FromValue.getArraySize());
10210 ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10211 ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10212 FromValue.getArrayInitializedElts());
10213 break;
10214 case APValue::Struct:
10215 Result.MakeStruct(FromValue.getStructNumBases(),
10216 FromValue.getStructNumFields());
10217 ImportLoop(
10218 ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10219 ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10220 FromValue.getStructNumBases() + FromValue.getStructNumFields());
10221 break;
10222 case APValue::Union: {
10223 Result.MakeUnion();
10224 const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10225 APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10226 if (Err)
10227 return std::move(Err);
10228 Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10229 break;
10230 }
10232 Result.MakeAddrLabelDiff();
10233 const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10234 const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10235 if (Err)
10236 return std::move(Err);
10237 Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10238 cast<AddrLabelExpr>(ImpRHS));
10239 break;
10240 }
10242 const Decl *ImpMemPtrDecl =
10243 importChecked(Err, FromValue.getMemberPointerDecl());
10244 if (Err)
10245 return std::move(Err);
10247 Result.setMemberPointerUninit(
10248 cast<const ValueDecl>(ImpMemPtrDecl),
10250 FromValue.getMemberPointerPath().size());
10252 Result.getMemberPointerPath();
10253 for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10254 Idx++) {
10255 const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10256 if (Err)
10257 return std::move(Err);
10258 ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10259 }
10260 break;
10261 }
10262 case APValue::LValue:
10264 QualType FromElemTy;
10265 if (FromValue.getLValueBase()) {
10266 assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10267 "in C++20 dynamic allocation are transient so they shouldn't "
10268 "appear in the AST");
10269 if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10270 if (const auto *E =
10271 FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10272 FromElemTy = E->getType();
10273 const Expr *ImpExpr = importChecked(Err, E);
10274 if (Err)
10275 return std::move(Err);
10276 Base = APValue::LValueBase(ImpExpr,
10277 FromValue.getLValueBase().getCallIndex(),
10278 FromValue.getLValueBase().getVersion());
10279 } else {
10280 FromElemTy =
10281 FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10282 const Decl *ImpDecl = importChecked(
10283 Err, FromValue.getLValueBase().get<const ValueDecl *>());
10284 if (Err)
10285 return std::move(Err);
10286 Base = APValue::LValueBase(cast<ValueDecl>(ImpDecl),
10287 FromValue.getLValueBase().getCallIndex(),
10288 FromValue.getLValueBase().getVersion());
10289 }
10290 } else {
10291 FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10292 const Type *ImpTypeInfo = importChecked(
10293 Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10294 QualType ImpType =
10295 importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10296 if (Err)
10297 return std::move(Err);
10299 ImpType);
10300 }
10301 }
10302 CharUnits Offset = FromValue.getLValueOffset();
10303 unsigned PathLength = FromValue.getLValuePath().size();
10304 Result.MakeLValue();
10305 if (FromValue.hasLValuePath()) {
10306 MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10307 Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10308 FromValue.isNullPointer());
10310 FromValue.getLValuePath();
10311 for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10312 if (FromElemTy->isRecordType()) {
10313 const Decl *FromDecl =
10314 FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10315 const Decl *ImpDecl = importChecked(Err, FromDecl);
10316 if (Err)
10317 return std::move(Err);
10318 if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10319 FromElemTy = Importer.FromContext.getRecordType(RD);
10320 else
10321 FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10323 ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10324 } else {
10325 FromElemTy =
10326 Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10327 ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10328 FromPath[LoopIdx].getAsArrayIndex());
10329 }
10330 }
10331 } else
10332 Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10333 FromValue.isNullPointer());
10334 }
10335 if (Err)
10336 return std::move(Err);
10337 return Result;
10338}
10339
10341 DeclContext *DC,
10342 unsigned IDNS,
10343 NamedDecl **Decls,
10344 unsigned NumDecls) {
10345 if (ODRHandling == ODRHandlingType::Conservative)
10346 // Report error at any name conflict.
10347 return make_error<ASTImportError>(ASTImportError::NameConflict);
10348 else
10349 // Allow to create the new Decl with the same name.
10350 return Name;
10351}
10352
10354 if (LastDiagFromFrom)
10356 FromContext.getDiagnostics());
10357 LastDiagFromFrom = false;
10358 return ToContext.getDiagnostics().Report(Loc, DiagID);
10359}
10360
10362 if (!LastDiagFromFrom)
10364 ToContext.getDiagnostics());
10365 LastDiagFromFrom = true;
10366 return FromContext.getDiagnostics().Report(Loc, DiagID);
10367}
10368
10370 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10371 if (!ID->getDefinition())
10372 ID->startDefinition();
10373 }
10374 else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10375 if (!PD->getDefinition())
10376 PD->startDefinition();
10377 }
10378 else if (auto *TD = dyn_cast<TagDecl>(D)) {
10379 if (!TD->getDefinition() && !TD->isBeingDefined()) {
10380 TD->startDefinition();
10381 TD->setCompleteDefinition(true);
10382 }
10383 }
10384 else {
10385 assert(0 && "CompleteDecl called on a Decl that can't be completed");
10386 }
10387}
10388
10390 llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From);
10391 assert((Pos == ImportedDecls.end() || Pos->second == To) &&
10392 "Try to import an already imported Decl");
10393 if (Pos != ImportedDecls.end())
10394 return Pos->second;
10395 ImportedDecls[From] = To;
10396 // This mapping should be maintained only in this function. Therefore do not
10397 // check for additional consistency.
10398 ImportedFromDecls[To] = From;
10399 // In the case of TypedefNameDecl we create the Decl first and only then we
10400 // import and set its DeclContext. So, the DC is still not set when we reach
10401 // here from GetImportedOrCreateDecl.
10402 if (To->getDeclContext())
10403 AddToLookupTable(To);
10404 return To;
10405}
10406
10407std::optional<ASTImportError>
10409 auto Pos = ImportDeclErrors.find(FromD);
10410 if (Pos != ImportDeclErrors.end())
10411 return Pos->second;
10412 else
10413 return std::nullopt;
10414}
10415
10417 auto InsertRes = ImportDeclErrors.insert({From, Error});
10418 (void)InsertRes;
10419 // Either we set the error for the first time, or we already had set one and
10420 // now we want to set the same error.
10421 assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10422}
10423
10425 bool Complain) {
10426 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10427 ImportedTypes.find(From.getTypePtr());
10428 if (Pos != ImportedTypes.end()) {
10429 if (ExpectedType ToFromOrErr = Import(From)) {
10430 if (ToContext.hasSameType(*ToFromOrErr, To))
10431 return true;
10432 } else {
10433 llvm::consumeError(ToFromOrErr.takeError());
10434 }
10435 }
10436
10437 StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls,
10438 getStructuralEquivalenceKind(*this), false,
10439 Complain);
10440 return Ctx.IsEquivalent(From, To);
10441}
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.
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:2955
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:28
llvm::SmallVector< std::pair< const MemRegion *, SVal >, 4 > Bindings
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
llvm::APInt getValue() const
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:208
static LValuePathEntry ArrayIndex(uint64_t Index)
Definition: APValue.h:216
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
const LValueBase getLValueBase() const
Definition: APValue.cpp:970
ArrayRef< LValuePathEntry > getLValuePath() const
Definition: APValue.cpp:990
const FieldDecl * getUnionField() const
Definition: APValue.h:563
unsigned getStructNumFields() const
Definition: APValue.h:542
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:205
ValueKind getKind() const
Definition: APValue.h:395
bool isLValueOnePastTheEnd() const
Definition: APValue.cpp:975
bool isMemberPointerToDerivedMember() const
Definition: APValue.cpp:1060
unsigned getArrayInitializedElts() const
Definition: APValue.h:529
unsigned getStructNumBases() const
Definition: APValue.h:538
bool hasLValuePath() const
Definition: APValue.cpp:985
const ValueDecl * getMemberPointerDecl() const
Definition: APValue.cpp:1053
APValue & getUnionValue()
Definition: APValue.h:567
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition: APValue.h:583
CharUnits & getLValueOffset()
Definition: APValue.cpp:980
unsigned getVectorLength() const
Definition: APValue.h:505
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition: APValue.cpp:1067
unsigned getArraySize() const
Definition: APValue.h:533
@ 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:1006
const AddrLabelExpr * getAddrLabelDiffLHS() const
Definition: APValue.h:579
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
QualType getUsingType(const UsingShadowDecl *Found, QualType Underlying) const
SourceManager & getSourceManager()
Definition: ASTContext.h:700
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1068
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.
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType) 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:643
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 getPackExpansionType(QualType Pattern, std::optional< unsigned > NumExpansions, bool ExpectPackInType=true)
Form a pack expansion type with the given pattern.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2549
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2565
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 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:1575
IdentifierTable & Idents
Definition: ASTContext.h:639
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:770
SelectorTable & Selectors
Definition: ASTContext.h:640
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:1088
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:2141
QualType getElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType, TagDecl *OwnedTagDecl=nullptr) const
CanQualType SignedCharTy
Definition: ASTContext.h:1095
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
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:1086
CanQualType UnsignedCharTy
Definition: ASTContext.h:1096
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:1553
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:1182
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:1089
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.
QualType getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex) const
Retrieve a substitution-result type.
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
std::string toString() const
Definition: ASTImporter.cpp:86
@ 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:164
VecTy copyCycleAtBack() const
Returns the copy of the cycle.
Definition: ASTImporter.h:178
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:523
NonEquivalentDeclSet & getNonEquivalentDecls()
Return the set of declarations that we know are not equivalent.
Definition: ASTImporter.h:538
ASTContext & getToContext() const
Retrieve the context that AST nodes are being imported into.
Definition: ASTImporter.h:520
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.
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:563
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:548
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 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)
bool hasAutoReturnTypeDeclaredInside(FunctionDecl *D)
This function checks if the function has 'auto' return type that contains a reference (in any way) to...
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)
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)
Error ImportTemplateParameterLists(const DeclaratorDecl *FromD, DeclaratorDecl *ToD)
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)
SourceLocation getColonLoc() const
Definition: Expr.h:4163
SourceLocation getQuestionLoc() const
Definition: Expr.h:4162
Represents an access specifier followed by colon ':'.
Definition: DeclCXX.h:86
SourceLocation getColonLoc() const
The location of the colon following the access specifier.
Definition: DeclCXX.h:108
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition: Expr.h:4332
SourceLocation getAmpAmpLoc() const
Definition: Expr.h:4347
SourceLocation getLabelLoc() const
Definition: Expr.h:4349
LabelDecl * getLabel() const
Definition: Expr.h:4355
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Definition: Type.h:2927
QualType getAdjustedType() const
Definition: Type.h:2941
QualType getOriginalType() const
Definition: Type.h:2940
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition: Expr.h:5558
Represents a loop initializing the elements of an array.
Definition: Expr.h:5505
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition: Expr.h:5520
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition: Expr.h:5525
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2663
SourceLocation getRBracketLoc() const
Definition: Expr.h:2711
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Definition: Expr.h:2692
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition: ExprCXX.h:2836
uint64_t getValue() const
Definition: ExprCXX.h:2882
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:2874
ArrayTypeTrait getTrait() const
Definition: ExprCXX.h:2876
Expr * getDimensionExpression() const
Definition: ExprCXX.h:2884
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition: ExprCXX.h:2880
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.h:2873
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3147
ArraySizeModifier getSizeModifier() const
Definition: Type.h:3161
QualType getElementType() const
Definition: Type.h:3159
unsigned getIndexTypeCVRQualifiers() const
Definition: Type.h:3169
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:6431
Expr ** getSubExprs()
Definition: Expr.h:6508
SourceLocation getRParenLoc() const
Definition: Expr.h:6536
static unsigned getNumSubExprs(AtomicOp Op)
Determine the number of arguments the specified atomic builtin should have.
Definition: Expr.cpp:4939
AtomicOp getOp() const
Definition: Expr.h:6495
SourceLocation getBuiltinLoc() const
Definition: Expr.h:6535
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
Definition: Type.h:6732
Attr - This represents one attribute.
Definition: Attr.h:42
attr::Kind getKind() const
Definition: Attr.h:88
void setPackExpansion(bool PE)
Definition: Attr.h:104
Attr * clone(ASTContext &C) const
void setImplicit(bool I)
Definition: Attr.h:102
void setAttrName(const IdentifierInfo *AttrNameII)
const IdentifierInfo * getAttrName() const
Represents an attribute applied to a statement.
Definition: Stmt.h:2078
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: Stmt.cpp:425
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:5147
QualType getModifiedType() const
Definition: Type.h:5169
QualType getEquivalentType() const
Definition: Type.h:5170
Kind getAttrKind() const
Definition: Type.h:5165
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:5524
ArrayRef< TemplateArgument > getTypeConstraintArguments() const
Definition: Type.h:5534
ConceptDecl * getTypeConstraintConcept() const
Definition: Type.h:5539
AutoTypeKeyword getKeyword() const
Definition: Type.h:5555
const BTFTypeTagAttr * getAttr() const
Definition: Type.h:5260
QualType getWrappedType() const
Definition: Type.h:5259
Represents a C++ declaration that introduces decls from somewhere else.
Definition: DeclCXX.h:3410
void addShadowDecl(UsingShadowDecl *S)
Definition: DeclCXX.cpp:3139
shadow_range shadows() const
Definition: DeclCXX.h:3476
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition: Expr.h:4235
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condnition evaluates to false;...
Definition: Expr.h:4289
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition: Expr.h:4273
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
Definition: Expr.h:4277
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Definition: Expr.h:4282
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition: Expr.h:4270
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3834
Expr * getLHS() const
Definition: Expr.h:3883
SourceLocation getOperatorLoc() const
Definition: Expr.h:3875
Expr * getRHS() const
Definition: Expr.h:3885
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:4767
Opcode getOpcode() const
Definition: Expr.h:3878
FPOptionsOverride getFPFeatures() const
Definition: Expr.h:4040
A binding in a decomposition declaration.
Definition: DeclCXX.h:4100
ValueDecl * getDecomposedDecl() const
Get the decomposition declaration that this binding represents a decomposition of.
Definition: DeclCXX.h:4128
Expr * getBinding() const
Get the expression to which this declaration is bound.
Definition: DeclCXX.h:4124
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:4137
void setDecomposedDecl(ValueDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition: DeclCXX.h:4143
A fixed int type of a specified bitwidth.
Definition: Type.h:6785
bool isUnsigned() const
Definition: Type.h:6795
unsigned getNumBits() const
Definition: Type.h:6797
Pointer to a block type.
Definition: Type.h:2978
QualType getPointeeType() const
Definition: Type.h:2990
BreakStmt - This represents a break.
Definition: Stmt.h:2978
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition: ExprCXX.h:5251
Represents the builtin template declaration which is used to implement __make_integer_seq and other b...
BuiltinTemplateKind getBuiltinTemplateKind() const
This class is used for builtin types like 'int'.
Definition: Type.h:2740
Kind getKind() const
Definition: Type.h:2782
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:2091
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:1475
CXXTemporary * getTemporary()
Definition: ExprCXX.h:1493
static CXXBindTemporaryExpr * Create(const ASTContext &C, CXXTemporary *Temp, Expr *SubExpr)
Definition: ExprCXX.cpp:1048
const Expr * getSubExpr() const
Definition: ExprCXX.h:1497
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
bool getValue() const
Definition: ExprCXX.h:737
SourceLocation getLocation() const
Definition: ExprCXX.h:743
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:826
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1530
SourceRange getParenOrBraceRange() const
Definition: ExprCXX.h:1698
void setIsImmediateEscalating(bool Set)
Definition: ExprCXX.h:1692
bool isElidable() const
Whether this construction is elidable.
Definition: ExprCXX.h:1599
bool hadMultipleCandidates() const
Whether the referred constructor was resolved from an overloaded set having size greater than 1.
Definition: ExprCXX.h:1604
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:1110
arg_range arguments()
Definition: ExprCXX.h:1654
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition: ExprCXX.h:1623
bool isImmediateEscalating() const
Definition: ExprCXX.h:1688
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
Definition: ExprCXX.h:1632
SourceLocation getLocation() const
Definition: ExprCXX.h:1595
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition: ExprCXX.h:1593
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition: ExprCXX.h:1612
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition: ExprCXX.h:1670
CXXConstructionKind getConstructionKind() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition: ExprCXX.h:1641
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2528
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2855
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2293
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition: DeclCXX.h:2433
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition: DeclCXX.h:2393
Expr * getInit() const
Get the initializer.
Definition: DeclCXX.h:2495
SourceLocation getRParenLoc() const
Definition: DeclCXX.h:2492
SourceLocation getEllipsisLoc() const
Definition: DeclCXX.h:2403
SourceLocation getLParenLoc() const
Definition: DeclCXX.h:2491
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition: DeclCXX.h:2398
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition: DeclCXX.h:2427
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition: DeclCXX.h:2371
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition: DeclCXX.h:2365
bool isIndirectMemberInitializer() const
Definition: DeclCXX.h:2377
SourceLocation getMemberLocation() const
Definition: DeclCXX.h:2453
IndirectFieldDecl * getIndirectMember() const
Definition: DeclCXX.h:2447
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition: DeclCXX.h:2419
Represents a C++ deduction guide declaration.
Definition: DeclCXX.h:1947
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1254
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
Definition: ExprCXX.h:1328
const ParmVarDecl * getParam() const
Definition: ExprCXX.h:1296
const DeclContext * getUsedContext() const
Definition: ExprCXX.h:1324
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition: ExprCXX.cpp:969
bool hasRewrittenInit() const
Definition: ExprCXX.h:1299
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1361
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:1023
const DeclContext * getUsedContext() const
Definition: ExprCXX.h:1418
const Expr * getRewrittenExpr() const
Retrieve the initializing expression with evaluated immediate calls, if any.
Definition: ExprCXX.h:1406
bool hasRewrittenInit() const
Definition: ExprCXX.h:1390
FieldDecl * getField()
Get the field whose initializer will be used.
Definition: ExprCXX.h:1395
SourceLocation getBeginLoc() const
Definition: ExprCXX.h:1425
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition: ExprCXX.h:2481
FunctionDecl * getOperatorDelete() const
Definition: ExprCXX.h:2520
bool isArrayForm() const
Definition: ExprCXX.h:2507
SourceLocation getBeginLoc() const
Definition: ExprCXX.h:2531
bool isGlobalDelete() const
Definition: ExprCXX.h:2506
Expr * getArgument()
Definition: ExprCXX.h:2522
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition: ExprCXX.h:2516
bool isArrayFormAsWritten() const
Definition: ExprCXX.h:2508
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition: ExprCXX.h:3645
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition: ExprCXX.h:3748
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition: ExprCXX.h:3751
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:1484
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:3803
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition: ExprCXX.h:3795
const DeclarationNameInfo & getMemberNameInfo() const
Retrieve the name of the member that this expression refers to.
Definition: ExprCXX.h:3782
bool hasExplicitTemplateArgs() const
Determines whether this member expression actually had a C++ template argument list explicitly specif...
Definition: ExprCXX.h:3822
SourceLocation getMemberLoc() const
Definition: ExprCXX.h:3791
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:3811
DeclarationName getMember() const
Retrieve the name of the member that this expression refers to.
Definition: ExprCXX.h:3787
NamedDecl * getFirstQualifierFoundInScope() const
Retrieve the first part of the nested-name-specifier that was found in the scope of the member access...
Definition: ExprCXX.h:3775
Expr * getBase() const
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition: ExprCXX.h:3739
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the member name, with source location information.
Definition: ExprCXX.h:3762
bool isImplicitAccess() const
True if this is an implicit access, i.e.
Definition: ExprCXX.h:3731
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: ExprCXX.h:3850
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2792
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg)
Definition: DeclCXX.cpp:2868
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:738
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:4791
UnresolvedLookupExpr * getCallee() const
Definition: ExprCXX.h:4822
std::optional< unsigned > getNumExpansions() const
Definition: ExprCXX.h:4847
Expr * getRHS() const
Definition: ExprCXX.h:4826
SourceLocation getLParenLoc() const
Definition: ExprCXX.h:4842
SourceLocation getEllipsisLoc() const
Definition: ExprCXX.h:4844
Expr * getLHS() const
Definition: ExprCXX.h:4825
SourceLocation getRParenLoc() const
Definition: ExprCXX.h:4843
BinaryOperatorKind getOperator() const
Definition: ExprCXX.h:4845
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:852
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1721
bool constructsVBase() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition: ExprCXX.h:1762
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Definition: ExprCXX.h:1758
SourceLocation getLocation() const LLVM_READONLY
Definition: ExprCXX.h:1774
bool inheritedFromVBase() const
Determine whether the inherited constructor is inherited from a virtual base of the object we constru...
Definition: ExprCXX.h:1772
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:626
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2053
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition: DeclCXX.cpp:2507
overridden_method_range overridden_methods() const
Definition: DeclCXX.cpp:2532
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:2149
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition: ExprCXX.h:372
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition: ExprCXX.h:403
SourceRange getAngleBrackets() const LLVM_READONLY
Definition: ExprCXX.h:410
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition: ExprCXX.h:406
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition: ExprCXX.h:2224
SourceRange getDirectInitRange() const
Definition: ExprCXX.h:2464
llvm::iterator_range< arg_iterator > placement_arguments()
Definition: ExprCXX.h:2427
std::optional< Expr * > getArraySize()
This might return std::nullopt even if isArray() returns true, since there might not be an array size...
Definition: ExprCXX.h:2337
CXXNewInitializationStyle getInitializationStyle() const
The kind of initializer this new-expression has.
Definition: ExprCXX.h:2391
bool passAlignment() const
Indicates whether the required alignment should be implicitly passed to the allocation function.
Definition: ExprCXX.h:2415
FunctionDecl * getOperatorDelete() const
Definition: ExprCXX.h:2329
unsigned getNumPlacementArgs() const
Definition: ExprCXX.h:2362
TypeSourceInfo * getAllocatedTypeSourceInfo() const
Definition: ExprCXX.h:2306
SourceRange getSourceRange() const
Definition: ExprCXX.h:2465
SourceRange getTypeIdParens() const
Definition: ExprCXX.h:2380
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition: ExprCXX.h:2420
FunctionDecl * getOperatorNew() const
Definition: ExprCXX.h:2327
bool isGlobalNew() const
Definition: ExprCXX.h:2385
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:245
Expr * getInitializer()
The initializer of this new-expression.
Definition: ExprCXX.h:2397
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition: ExprCXX.h:4088
bool getValue() const
Definition: ExprCXX.h:4111
SourceLocation getEndLoc() const
Definition: ExprCXX.h:4108
Expr * getOperand() const
Definition: ExprCXX.h:4105
SourceLocation getBeginLoc() const
Definition: ExprCXX.h:4107
The null pointer literal (C++11 [lex.nullptr])
Definition: ExprCXX.h:765
SourceLocation getLocation() const
Definition: ExprCXX.h:779
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:562
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition: ExprCXX.h:2600
TypeSourceInfo * getDestroyedTypeInfo() const
Retrieve the source location information for the type being destroyed.
Definition: ExprCXX.h:2694
bool isArrow() const
Determine whether this pseudo-destructor expression was written using an '->' (otherwise,...
Definition: ExprCXX.h:2664
TypeSourceInfo * getScopeTypeInfo() const
Retrieve the scope type in a qualified pseudo-destructor expression.
Definition: ExprCXX.h:2678
IdentifierInfo * getDestroyedTypeIdentifier() const
In a dependent pseudo-destructor expression for which we do not have full type information on the des...
Definition: ExprCXX.h:2701
SourceLocation getTildeLoc() const
Retrieve the location of the '~'.
Definition: ExprCXX.h:2685
NestedNameSpecifierLoc getQualifierLoc() const
Retrieves the nested-name-specifier that qualifies the type name, with source-location information.
Definition: ExprCXX.h:2653
SourceLocation getDestroyedTypeLoc() const
Retrieve the starting location of the type being destroyed.
Definition: ExprCXX.h:2709
SourceLocation getColonColonLoc() const
Retrieve the location of the '::' in a qualified pseudo-destructor expression.
Definition: ExprCXX.h:2682
SourceLocation getOperatorLoc() const
Retrieve the location of the '.' or '->' operator.
Definition: ExprCXX.h:2667
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
CXXRecordDecl * getMostRecentDecl()
Definition: DeclCXX.h:540
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:1875
method_range methods() const
Definition: DeclCXX.h:660
CXXRecordDecl * getDefinition() const
Definition: DeclCXX.h:564
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, unsigned DependencyKind, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
Definition: DeclCXX.cpp:147
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
Definition: DeclCXX.cpp:1904
void setInstantiationOfMemberClass(CXXRecordDecl *RD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member class RD.
Definition: DeclCXX.cpp:1887
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition: DeclCXX.cpp:1900
void setLambdaNumbering(LambdaNumbering Numbering)
Set the mangling numbers and context declaration for a lambda class.
Definition: DeclCXX.cpp:1690
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
Definition: DeclCXX.cpp:1882
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition: DeclCXX.cpp:1915
CXXRecordDecl * getPreviousDecl()
Definition: DeclCXX.h:531
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:803
A rewritten comparison expression that was originally written using operator syntax.
Definition: ExprCXX.h:283
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
Definition: ExprCXX.h:301
bool isReversed() const
Determine whether this expression was rewritten in reverse form.
Definition: ExprCXX.h:319
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type.
Definition: ExprCXX.h:2165
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:2184
SourceLocation getRParenLoc() const
Definition: ExprCXX.h:2188
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:712
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:1869
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:1076
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:1898
Represents a C++ temporary.
Definition: ExprCXX.h:1443
const CXXDestructorDecl * getDestructor() const
Definition: ExprCXX.h:1454
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition: ExprCXX.cpp:1043
Represents the this expression in C++.
Definition: ExprCXX.h:1148
bool isImplicit() const
Definition: ExprCXX.h:1170
static CXXThisExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType Ty, bool IsImplicit)
Definition: ExprCXX.cpp:1519
SourceLocation getLocation() const
Definition: ExprCXX.h:1164
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:1192
const Expr * getSubExpr() const
Definition: ExprCXX.h:1212
SourceLocation getThrowLoc() const
Definition: ExprCXX.h:1215
bool isThrownVariableInScope() const
Determines whether the variable thrown by this expression (if any!) is within the innermost try block...
Definition: ExprCXX.h:1222
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
bool isTypeOperand() const
Definition: ExprCXX.h:881
TypeSourceInfo * getTypeOperandSourceInfo() const
Retrieve source information for the type operand.
Definition: ExprCXX.h:888
Expr * getExprOperand() const
Definition: ExprCXX.h:892
SourceRange getSourceRange() const LLVM_READONLY
Definition: ExprCXX.h:899
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition: ExprCXX.h:3519
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses ('(') that precedes the argument list.
Definition: ExprCXX.h:3563
bool isListInitialization() const
Determine whether this expression models list-initialization.
Definition: ExprCXX.h:3574
static CXXUnresolvedConstructExpr * Create(const ASTContext &Context, QualType T, TypeSourceInfo *TSI, SourceLocation LParenLoc, ArrayRef< Expr * > Args, SourceLocation RParenLoc, bool IsListInit)
Definition: ExprCXX.cpp:1422
TypeSourceInfo * getTypeSourceInfo() const
Retrieve the type source information for the type being constructed.
Definition: ExprCXX.h:3557
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (')') that follows the argument list.
Definition: ExprCXX.h:3568
unsigned getNumArgs() const
Retrieve the number of arguments.
Definition: ExprCXX.h:3577
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2819
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:1474
ADLCallKind getADLCallKind() const
Definition: Expr.h:2973
Expr * getCallee()
Definition: Expr.h:2969
FPOptionsOverride getFPFeatures() const
Definition: Expr.h:3101
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition: Expr.h:2997
arg_range arguments()
Definition: Expr.h:3058
SourceLocation getRParenLoc() const
Definition: Expr.h:3129
CaseStmt - Represent a case statement.
Definition: Stmt.h:1799
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Definition: Stmt.cpp:1220
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3489
path_iterator path_begin()
Definition: Expr.h:3559
CastKind getCastKind() const
Definition: Expr.h:3533
path_iterator path_end()
Definition: Expr.h:3560
FPOptionsOverride getFPFeatures() const
Definition: Expr.h:3592
Expr * getSubExpr()
Definition: Expr.h:3539
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
SourceLocation getLocation() const
Definition: Expr.h:1602
unsigned getValue() const
Definition: Expr.h:1610
CharacterLiteralKind getKind() const
Definition: Expr.h:1603
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:4552
SourceLocation getBuiltinLoc() const
Definition: Expr.h:4599
Expr * getLHS() const
Definition: Expr.h:4594
bool isConditionDependent() const
Definition: Expr.h:4582
bool isConditionTrue() const
isConditionTrue - Return whether the condition is true (i.e.
Definition: Expr.h:4575
Expr * getRHS() const
Definition: Expr.h:4596
SourceLocation getRParenLoc() const
Definition: Expr.h:4602
Expr * getCond() const
Definition: Expr.h:4592
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...
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary class pattern.
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.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Get the template arguments as written.
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...
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
SourceLocation getExternLoc() const
Gets the location of the extern keyword, if present.
void setTypeAsWritten(TypeSourceInfo *T)
Sets the type of this specialization as it was written by the user.
void setPointOfInstantiation(SourceLocation Loc)
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
TypeSourceInfo * getTypeAsWritten() const
Gets the type of this specialization as it was written by the user, if it was so written.
void setSpecializationKind(TemplateSpecializationKind TSK)
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
SourceLocation getTemplateKeywordLoc() const
Gets the location of the template keyword, if present.
const TemplateArgumentList & getTemplateInstantiationArgs() const
Retrieve the set of template arguments that should be used to instantiate members of the class templa...
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getInstantiatedFrom() const
If this class template specialization is an instantiation of a template (rather than an explicit spec...
void setExternLoc(SourceLocation Loc)
Sets the location of the extern 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,...
Complex values, per C99 6.2.5p11.
Definition: Type.h:2845
QualType getElementType() const
Definition: Type.h:2855
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4082
QualType getComputationLHSType() const
Definition: Expr.h:4116
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:4789
QualType getComputationResultType() const
Definition: Expr.h:4119
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3419
SourceLocation getLParenLoc() const
Definition: Expr.h:3449
bool isFileScope() const
Definition: Expr.h:3446
const Expr * getInitializer() const
Definition: Expr.h:3442
TypeSourceInfo * getTypeSourceInfo() const
Definition: Expr.h:3452
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1604
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Definition: Stmt.cpp:383
A reference to a concept and its template args, as it appears in the code.
Definition: ASTConcept.h:128
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
Definition: ASTConcept.h:167
NamedDecl * getFoundDecl() const
Definition: ASTConcept.h:199
const DeclarationNameInfo & getConceptNameInfo() const
Definition: ASTConcept.h:171
ConceptDecl * getNamedConcept() const
Definition: ASTConcept.h:203
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
Definition: ASTConcept.cpp:93
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition: ASTConcept.h:207
SourceLocation getTemplateKWLoc() const
Definition: ASTConcept.h:177
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:4173
Expr * getLHS() const
Definition: Expr.h:4207
Expr * getCond() const
getCond - Return the expression representing the condition for the ?: operator.
Definition: Expr.h:4196
Expr * getRHS() const
Definition: Expr.h:4208
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3186
const llvm::APInt & getSize() const
Definition: Type.h:3207
const Expr * getSizeExpr() const
Definition: Type.h:3208
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition: Expr.h:1072
APValue getAPValueResult() const
Definition: Expr.cpp:413
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:3710
unsigned getNumColumns() const
Returns the number of columns in the matrix.
Definition: Type.h:3731
unsigned getNumRows() const
Returns the number of rows in the matrix.
Definition: Type.h:3728
Represents a shadow constructor declaration introduced into a class by a C++11 using-declaration that...
Definition: DeclCXX.h:3591
ContinueStmt - This represents a continue.
Definition: Stmt.h:2948
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition: Expr.h:4493
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition: Expr.h:4527
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_convertvector token.
Definition: Expr.h:4524
TypeSourceInfo * getTypeSourceInfo() const
getTypeSourceInfo - Return the destination type.
Definition: Expr.h:4516
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition: Expr.h:4513
Represents a pointer type decayed from an array or function type.
Definition: Type.h:2961
A POD class for pairing a NamedDecl* with an access specifier.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
NamedDecl * getDecl() const
AccessSpecifier getAccess() const
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1379
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1446
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2076
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
Definition: DeclBase.cpp:1976
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1265
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1785
bool isRecord() const
Definition: DeclBase.h:2156
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1921
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
Definition: DeclBase.cpp:1707
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1573
void removeDecl(Decl *D)
Removes a declaration from this context.
Definition: DeclBase.cpp:1618
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:1850
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1568
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition: DeclBase.h:2647
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:2332
bool isFunctionOrMethod() const
Definition: DeclBase.h:2128
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:1882
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:1260
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
Definition: Expr.h:1365
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list.
Definition: Expr.h:1409
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Definition: Expr.h:1458
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: Expr.h:1381
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
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: Expr.h:1389
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
Definition: Expr.h:1347
ValueDecl * getDecl()
Definition: Expr.h:1328
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: Expr.h:1435
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition: Expr.h:1452
bool hadMultipleCandidates() const
Returns true if this expression refers to a function that was resolved from an overloaded set having ...
Definition: Expr.h:1441
SourceLocation getLocation() const
Definition: Expr.h:1336
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: Expr.h:1397
bool isImmediateEscalating() const
Definition: Expr.h:1462
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1495
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:85
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
Definition: DeclBase.h:1061
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:440
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition: DeclBase.h:1226
bool hasAttrs() const
Definition: DeclBase.h:523
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:501
void addAttr(Attr *A)
Definition: DeclBase.cpp:975
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:598
bool isInIdentifierNamespace(unsigned NS) const
Definition: DeclBase.h:893
@ FOK_None
Not a friend object.
Definition: DeclBase.h:1217
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:1180
void setAccess(AccessSpecifier AS)
Definition: DeclBase.h:507
SourceLocation getLocation() const
Definition: DeclBase.h:444
const char * getDeclKindName() const
Definition: DeclBase.cpp:123
IdentifierNamespace
IdentifierNamespace - The different namespaces in which declarations may appear.
Definition: DeclBase.h:114
@ IDNS_NonMemberOperator
This declaration is a C++ operator declared in a non-class context.
Definition: DeclBase.h:167
@ IDNS_TagFriend
This declaration is a friend class.
Definition: DeclBase.h:156
@ IDNS_Ordinary
Ordinary names.
Definition: DeclBase.h:143
@ IDNS_ObjCProtocol
Objective C @protocol.
Definition: DeclBase.h:146
@ IDNS_Namespace
Namespaces, declared with 'namespace foo {}'.
Definition: DeclBase.h:139
@ IDNS_OrdinaryFriend
This declaration is a friend function.
Definition: DeclBase.h:151
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
Definition: DeclBase.h:124
void setImplicit(bool I=true)
Definition: DeclBase.h:599
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition: DeclBase.h:613
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition: DeclBase.cpp:530
DeclContext * getDeclContext()
Definition: DeclBase.h:453
AccessSpecifier getAccess() const
Definition: DeclBase.h:512
bool isInAnonymousNamespace() const
Definition: DeclBase.cpp:393
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:436
TranslationUnitDecl * getTranslationUnitDecl()
Definition: DeclBase.cpp:486
AttrVec & getAttrs()
Definition: DeclBase.h:529
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition: DeclBase.cpp:336
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:918
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:340
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:978
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.
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:770
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition: Decl.h:813
TemplateParameterList * getTemplateParameterList(unsigned index) const
Definition: Decl.h:862
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:822
unsigned getNumTemplateParameterLists() const
Definition: Decl.h:858
void setTypeSourceInfo(TypeSourceInfo *TI)
Definition: Decl.h:805
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:1997
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition: Decl.h:836
Expr * getTrailingRequiresClause()
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Definition: Decl.h:846
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:799
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
Definition: Decl.cpp:2031
Represents the type decltype(expr) (C++11).
Definition: Type.h:4901
Expr * getUnderlyingExpr() const
Definition: Type.h:4911
QualType getUnderlyingType() const
Definition: Type.h:4912
A decomposition declaration.
Definition: DeclCXX.h:4159
Represents a C++17 deduced template specialization type.
Definition: Type.h:5572
TemplateName getTemplateName() const
Retrieve the name of the template that we are deducing.
Definition: Type.h:5592
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it has not been deduced.
Definition: Type.h:5511
Represents an extended address space qualifier where the input address space value is dependent.
Definition: Type.h:3402
Expr * getAddrSpaceExpr() const
Definition: Type.h:3413
QualType getPointeeType() const
Definition: Type.h:3414
SourceLocation getAttributeLoc() const
Definition: Type.h:3415
Expr * getNumBitsExpr() const
Definition: Type.cpp:377
bool isUnsigned() const
Definition: Type.cpp:373
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:5995
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:6013
const IdentifierInfo * getIdentifier() const
Retrieve the type named by the typename specifier as an identifier.
Definition: Type.h:6020
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3285
static DependentScopeDeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:482
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:3359
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition: ExprCXX.h:3333
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:3351
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: ExprCXX.h:3393
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition: ExprCXX.h:3369
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: ExprCXX.h:3343
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition: ExprCXX.h:3324
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition: ExprCXX.h:3321
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:3344
SourceRange getBracketsRange() const
Definition: Type.h:3370
Expr * getSizeExpr() const
Definition: Type.h:3364
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:3442
SourceLocation getAttributeLoc() const
Definition: Type.h:3458
QualType getElementType() const
Definition: Type.h:3457
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition: Type.h:3769
Expr * getColumnExpr() const
Definition: Type.h:3782
Expr * getRowExpr() const
Definition: Type.h:3781
SourceLocation getAttributeLoc() const
Definition: Type.h:3783
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:488
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
Definition: TemplateName.h:560
bool isIdentifier() const
Determine whether this template name refers to an identifier.
Definition: TemplateName.h:547
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:544
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:550
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: Type.h:6047
const IdentifierInfo * getIdentifier() const
Definition: Type.h:6064
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:6066
NestedNameSpecifier * getQualifier() const
Definition: Type.h:6063
Represents a vector type where either the type or size is dependent.
Definition: Type.h:3564
Expr * getSizeExpr() const
Definition: Type.h:3575
VectorKind getVectorKind() const
Definition: Type.h:3578
SourceLocation getAttributeLoc() const
Definition: Type.h:3577
QualType getElementType() const
Definition: Type.h:3576
Represents a single C99 designator.
Definition: Expr.h:5129
unsigned getArrayIndex() const
Definition: Expr.h:5267
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition: Expr.h:5256
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition: Expr.h:5210
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition: Expr.h:5246
SourceLocation getFieldLoc() const
Definition: Expr.h:5237
SourceLocation getRBracketLoc() const
Definition: Expr.h:5285
const IdentifierInfo * getFieldName() const
Definition: Expr.cpp:4526
SourceLocation getEllipsisLoc() const
Definition: Expr.h:5279
SourceLocation getDotLoc() const
Definition: Expr.h:5232
SourceLocation getLBracketLoc() const
Definition: Expr.h:5273
Represents a C99 designated initializer expression.
Definition: Expr.h:5086
Expr * getSubExpr(unsigned Idx) const
Definition: Expr.h:5368
llvm::MutableArrayRef< Designator > designators()
Definition: Expr.h:5319
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
Definition: Expr.h:5350
static DesignatedInitExpr * Create(const ASTContext &C, llvm::ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition: Expr.cpp:4568
Expr * getInit() const
Retrieve the initializer value.
Definition: Expr.h:5354
unsigned size() const
Returns the number of designators in this initializer.
Definition: Expr.h:5316
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
Definition: Expr.h:5341
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression,...
Definition: Expr.h:5366
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1271
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1547
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:896
DoStmt - This represents a 'do/while' stmt.
Definition: Stmt.h:2723
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:5914
TagDecl * getOwnedTagDecl() const
Return the (re)declaration of this type owned by this occurrence of this type, or nullptr if there is...
Definition: Type.h:5962
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:5949
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:5952
Represents an empty-declaration.
Definition: Decl.h:4890
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3265
llvm::APSInt getInitVal() const
Definition: Decl.h:3285
const Expr * getInitExpr() const
Definition: Decl.h:3283
Represents an enum.
Definition: Decl.h:3832
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition: Decl.h:4091
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:4037
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition: Decl.h:4029
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:4040
void setIntegerType(QualType T)
Set the underlying integer type.
Definition: Decl.h:4001
EnumDecl * getMostRecentDecl()
Definition: Decl.h:3928
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition: Decl.h:4046
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition: Decl.cpp:4845
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:3992
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition: Decl.cpp:4905
EnumDecl * getDefinition() const
Definition: Decl.h:3935
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition: Decl.h:4018
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition: Decl.h:3984
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:5118
EnumDecl * getDecl() const
Definition: Type.h:5125
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:3724
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition: Expr.h:3746
Store information needed for an explicit specifier.
Definition: DeclCXX.h:1892
ExplicitSpecKind getKind() const
Definition: DeclCXX.h:1900
const Expr * getExpr() const
Definition: DeclCXX.h:1901
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3436
bool cleanupsHaveSideEffects() const
Definition: ExprCXX.h:3471
ArrayRef< CleanupObject > getObjects() const
Definition: ExprCXX.h:3460
unsigned getNumObjects() const
Definition: ExprCXX.h:3464
llvm::PointerUnion< BlockDecl *, CompoundLiteralExpr * > CleanupObject
The type of objects that are kept in the cleanup.
Definition: ExprCXX.h:3442
static ExprWithCleanups * Create(const ASTContext &C, EmptyShell empty, unsigned numObjects)
Definition: ExprCXX.cpp:1397
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 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
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:2907
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.h:2941
Expr * getQueriedExpression() const
Definition: ExprCXX.h:2946
ExpressionTrait getTrait() const
Definition: ExprCXX.h:2944
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:2942
ExtVectorType - Extended vector type.
Definition: Type.h:3604
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:870
Represents a member of a struct/union/class.
Definition: Decl.h:3025
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition: Decl.h:3113
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition: Decl.cpp:4537
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition: Decl.h:3186
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition: Decl.h:3180
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition: Decl.cpp:4547
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition: Decl.h:3129
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition: Decl.h:3226
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition: Decl.cpp:4642
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:234
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition: Expr.h:1562
SourceLocation getLocation() const
Definition: Expr.h:1688
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition: Expr.cpp:1058
llvm::APFloat getValue() const
Definition: Expr.h:1647
bool isExact() const
Definition: Expr.h:1680
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition: Stmt.h:2779
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
SourceLocation getFriendLoc() const
Retrieves the location of the 'friend' keyword.
Definition: DeclFriend.h:142
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
Definition: DeclFriend.h:137
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition: DeclFriend.h:122
const Expr * getSubExpr() const
Definition: Expr.h:1052
Represents a function declaration or definition.
Definition: Decl.h:1959
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:3201
ConstexprSpecKind getConstexprKind() const
Definition: Decl.h:2413
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition: Decl.cpp:4012
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:4007
void setIsPureVirtual(bool P=true)
Definition: Decl.cpp:3220
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition: Decl.h:2586
bool UsesFPIntrin() const
Determine whether the function was declared in source context that requires constrained FP intrinsics...
Definition: Decl.h:2786
SourceLocation getDefaultLoc() const
Definition: Decl.h:2335
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2651
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
Definition: Decl.h:2326
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition: Decl.h:2314
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition: Decl.h:2385
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition: Decl.cpp:3986
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition: Decl.cpp:4137
void setDefaultLoc(SourceLocation NewLoc)
Definition: Decl.h:2339
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition: Decl.h:2270
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition: Decl.cpp:4204
@ TK_MemberSpecialization
Definition: Decl.h:1971
@ TK_DependentNonTemplate
Definition: Decl.h:1980
@ TK_FunctionTemplateSpecialization
Definition: Decl.h:1975
@ TK_DependentFunctionTemplateSpecialization
Definition: Decl.h:1978
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:2765
void setTrivial(bool IT)
Definition: Decl.h:2315
bool FriendConstraintRefersToEnclosingTemplate() const
Definition: Decl.h:2592
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition: Decl.cpp:3958
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition: Decl.cpp:4025
bool isDeletedAsWritten() const
Definition: Decl.h:2481
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:4193
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Definition: Decl.h:2297
void setVirtualAsWritten(bool V)
State that this function is marked as virtual explicitly.
Definition: Decl.h:2293
FunctionDecl * getDefinition()
Get the definition for this declaration.
Definition: Decl.h:2226
void setRangeEnd(SourceLocation E)
Definition: Decl.h:2164
bool isDefaulted() const
Whether this function is defaulted.
Definition: Decl.h:2322
FunctionDecl * getInstantiatedFromDecl() const
Definition: Decl.cpp:4031
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition: Decl.cpp:4233
void setDefaulted(bool D=true)
Definition: Decl.h:2323
void setBody(Stmt *B)
Definition: Decl.cpp:3213
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition: Decl.h:2288
void setExplicitlyDefaulted(bool ED=true)
State that this function is explicitly defaulted.
Definition: Decl.h:2331
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition: Decl.cpp:3979
DeclarationNameInfo getNameInfo() const
Definition: Decl.h:2157
void setDeletedAsWritten(bool D=true)
Definition: Decl.h:2485
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition: Decl.cpp:3121
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition: Decl.h:2776
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4154
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4199
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:4443
ArrayRef< QualType > exceptions() const
Definition: Type.h:4601
ArrayRef< QualType > param_types() const
Definition: Type.h:4587
Declaration of a template function.
Definition: DeclTemplate.h:958
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.
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary pattern.
FunctionTemplateDecl * getMostRecentDecl()
ExtInfo getExtInfo() const
Definition: Type.h:4128
QualType getReturnType() const
Definition: Type.h:4116
This represents a GCC inline-assembly statement extension.
Definition: Stmt.h:3257
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition: Expr.h:4627
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:4644
Represents a C11 generic selection.
Definition: Expr.h:5719
TypeSourceInfo * getControllingType()
Return the controlling type of this generic selection expression.
Definition: Expr.h:5994
ArrayRef< Expr * > getAssocExprs() const
Definition: Expr.h:6014
bool isExprPredicate() const
Whether this generic selection uses an expression as its controlling argument.
Definition: Expr.h:5975
SourceLocation getGenericLoc() const
Definition: Expr.h:6072
SourceLocation getRParenLoc() const
Definition: Expr.h:6076
unsigned getResultIndex() const
The zero-based index of the result expression's generic association in the generic selection's associ...
Definition: Expr.h:5964
SourceLocation getDefaultLoc() const
Definition: Expr.h:6075
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:4456
bool isResultDependent() const
Whether this generic selection is result-dependent.
Definition: Expr.h:5971
Expr * getControllingExpr()
Return the controlling expression of this generic selection expression.
Definition: Expr.h:5982
ArrayRef< TypeSourceInfo * > getAssocTypeSourceInfos() const
Definition: Expr.h:6019
GotoStmt - This represents a direct goto.
Definition: Stmt.h:2860
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:2136
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:958
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition: Expr.h:1712
const Expr * getSubExpr() const
Definition: Expr.h:1724
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3649
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition: Expr.cpp:2060
ImplicitParamKind getParameterKind() const
Returns the implicit parameter kind.
Definition: Decl.h:1739
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5594
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4764
Represents a C array with an unspecified size.
Definition: Type.h:3246
Represents a field injected from an anonymous union/struct into the parent scope.
Definition: Decl.h:3309
unsigned getChainingSize() const
Definition: Decl.h:3336
ArrayRef< NamedDecl * > chain() const
Definition: Decl.h:3330
IndirectGotoStmt - This represents an indirect goto.
Definition: Stmt.h:2899
Description of a constructor that was inherited from a base class.
Definition: DeclCXX.h:2499
CXXConstructorDecl * getConstructor() const
Definition: DeclCXX.h:2512
ConstructorUsingShadowDecl * getShadowDecl() const
Definition: DeclCXX.h:2511
Describes an C or C++ initializer list.
Definition: Expr.h:4841
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition: Expr.h:4945
void setSyntacticForm(InitListExpr *Init)
Definition: Expr.h:5011
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition: Expr.h:4960
unsigned getNumInits() const
Definition: Expr.h:4871
SourceLocation getLBraceLoc() const
Definition: Expr.h:4995
void setArrayFiller(Expr *filler)
Definition: Expr.cpp:2394
InitListExpr * getSyntacticForm() const
Definition: Expr.h:5007
bool hadArrayRangeDesignator() const
Definition: Expr.h:5018
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition: Expr.h:4935
SourceLocation getRBraceLoc() const
Definition: Expr.h:4997
void setInitializedFieldInUnion(FieldDecl *FD)
Definition: Expr.h:4966
ArrayRef< Expr * > inits()
Definition: Expr.h:4881
void sawArrayRangeDesignator(bool ARD=true)
Definition: Expr.h:5021
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:5764
CXXRecordDecl * getDecl() const
Definition: Type.cpp:4002
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:957
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition: Expr.h:1520
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3053
Represents the declaration of a label.
Definition: Decl.h:499
bool isGnuLocal() const
Definition: Decl.h:526
LabelStmt * getStmt() const
Definition: Decl.h:523
void setStmt(LabelStmt *T)
Definition: Decl.h:524
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:2029
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:1196
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:1938
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:1244
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:2156
bool hasExplicitParameters() const
Determine whether this lambda has an explicit parameter list vs.
Definition: ExprCXX.h:2141
SourceRange getIntroducerRange() const
Retrieve the source range covering the lambda introducer, which contains the explicit capture list su...
Definition: ExprCXX.h:2089
unsigned capture_size() const
Determine the number of captures in this lambda.
Definition: ExprCXX.h:2019
CXXMethodDecl * getCallOperator() const
Retrieve the function call operator associated with this lambda expression.
Definition: ExprCXX.cpp:1336
bool hasExplicitResultType() const
Whether this lambda had its result type explicitly specified.
Definition: ExprCXX.h:2144
SourceLocation getCaptureDefaultLoc() const
Retrieve the location of this lambda's capture-default, if any.
Definition: ExprCXX.h:1996
llvm::iterator_range< capture_init_iterator > capture_inits()
Retrieve the initialization expressions for this lambda's captures.
Definition: ExprCXX.h:2053
LambdaCaptureDefault getCaptureDefault() const
Determine the default capture kind for this lambda.
Definition: ExprCXX.h:1991
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition: ExprCXX.cpp:1332
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
Definition: DeclCXX.h:3222
unsigned getManglingNumber() const
Definition: DeclCXX.h:3271
Expr * getTemporaryExpr()
Retrieve the expression to which the temporary materialization conversion was applied.
Definition: DeclCXX.h:3268
Represents a linkage specification.
Definition: DeclCXX.h:2927
void setRBraceLoc(SourceLocation L)
Definition: DeclCXX.h:2969
LinkageSpecLanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition: DeclCXX.h:2950
SourceLocation getExternLoc() const
Definition: DeclCXX.h:2966
SourceLocation getRBraceLoc() const
Definition: DeclCXX.h:2967
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition: DeclCXX.h:2961
Represents the results of name lookup.
Definition: Lookup.h:46
iterator end() const
Definition: Lookup.h:356
iterator begin() const
Definition: Lookup.h:355
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation.
Definition: Type.h:4785
QualType getUnderlyingType() const
Definition: Type.h:4801
const IdentifierInfo * getMacroIdentifier() const
Definition: Type.h:4800
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4679
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
Definition: ExprCXX.h:4696
bool isBoundToLvalueReference() const
Determine whether this materialized temporary is bound to an lvalue reference; otherwise,...
Definition: ExprCXX.h:4748
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
Definition: ExprCXX.h:4719
QualType getElementType() const
Returns type of the elements being stored in the matrix.
Definition: Type.h:3688
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3182
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: Expr.h:3350
SourceLocation getOperatorLoc() const
Definition: Expr.h:3360
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition: Expr.h:3295
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name,...
Definition: Expr.h:3280
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition: Expr.h:3261
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition: Expr.h:3322
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why? This is only meaningful if the named memb...
Definition: Expr.h:3402
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:1712
Expr * getBase() const
Definition: Expr.h:3255
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: Expr.h:3311
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: Expr.h:3303
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition: Expr.h:3355
bool isArrow() const
Definition: Expr.h:3362
DeclAccessPair getFoundDecl() const
Retrieves the declaration found by lookup.
Definition: Expr.h:3265
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3089
QualType getPointeeType() const
Definition: Type.h:3105
const Type * getClass() const
Definition: Type.h:3119
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:616
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
Definition: DeclTemplate.h:656
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Definition: DeclTemplate.h:661
This represents a decl that may have a name.
Definition: Decl.h:249
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition: Decl.cpp:1169
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:315
Represents a C++ namespace alias.
Definition: DeclCXX.h:3113
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition: DeclCXX.h:3176
SourceLocation getAliasLoc() const
Returns the location of the alias name, i.e.
Definition: DeclCXX.h:3198
SourceLocation getNamespaceLoc() const
Returns the location of the namespace keyword.
Definition: DeclCXX.h:3201
SourceLocation getTargetNameLoc() const
Returns the location of the identifier in the named namespace.
Definition: DeclCXX.h:3204
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition: DeclCXX.h:3185
Represent a C++ namespace.
Definition: Decl.h:547
SourceLocation getRBraceLoc() const
Definition: Decl.h:686
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:685
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition: Decl.h:610
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace nested inside this namespace, if any.
Definition: Decl.h:665
bool isNested() const
Returns true if this is a nested namespace declaration.
Definition: Decl.h:627
void setRBraceLoc(SourceLocation L)
Definition: Decl.h:688
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.
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.
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
Expr * getDefaultArgument() const
Retrieve the default argument, if any.
void setDefaultArgument(Expr *DefArg)
Set the default argument for this template parameter, and whether that default argument was inherited...
unsigned getDepth() const
Get the nesting depth of the template parameter.
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition: Stmt.h:1567
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:1636
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2323
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this category.
Definition: DeclObjC.cpp:2178
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:2387
ObjCCategoryImplDecl * getImplementation() const
Definition: DeclObjC.cpp:2169
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.h:2368
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
Definition: DeclObjC.h:2373
protocol_iterator protocol_end() const
Definition: DeclObjC.h:2407
SourceLocation getIvarLBraceLoc() const
Definition: DeclObjC.h:2460
SourceLocation getIvarRBraceLoc() const
Definition: DeclObjC.h:2462
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:2417
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:2403
void setImplementation(ObjCCategoryImplDecl *ImplD)
Definition: DeclObjC.cpp:2174
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2396
SourceLocation getCategoryNameLoc() const
Definition: DeclObjC.h:2456
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition: DeclObjC.h:2542
SourceLocation getCategoryNameLoc() const
Definition: DeclObjC.h:2570
ObjCCategoryDecl * getCategoryDecl() const
Definition: DeclObjC.cpp:2213
SourceLocation getAtStartLoc() const
Definition: DeclObjC.h:1092
Represents Objective-C's collection statement.
Definition: StmtObjC.h:23
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:2483
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2595
SourceLocation getIvarRBraceLoc() const
Definition: DeclObjC.h:2741
SourceLocation getSuperClassLoc() const
Definition: DeclObjC.h:2734
const ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.h:2732
SourceLocation getIvarLBraceLoc() const
Definition: DeclObjC.h:2739
Represents an ObjC class declaration.
Definition: DeclObjC.h:1150
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:1481
bool isImplicitInterfaceDecl() const
isImplicitInterfaceDecl - check that this is an implicitly declared ObjCInterfaceDecl node.
Definition: DeclObjC.h:1888
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class.
Definition: DeclObjC.h:1300
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:1388
void setImplementation(ObjCImplementationDecl *ImplD)
Definition: DeclObjC.cpp:1648
known_categories_range known_categories() const
Definition: DeclObjC.h:1683
void setSuperClass(TypeSourceInfo *superClass)
Definition: DeclObjC.h:1584
protocol_iterator protocol_end() const
Definition: DeclObjC.h:1370
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
Definition: DeclObjC.cpp:371
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
Definition: DeclObjC.h:1519
ObjCCategoryDecl * FindCategoryDeclaration(IdentifierInfo *CategoryId) const
FindCategoryDeclaration - Finds category declaration in the list of categories for this class and ret...
Definition: DeclObjC.cpp:1755
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this class.
Definition: DeclObjC.cpp:342
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:1352
ObjCImplementationDecl * getImplementation() const
Definition: DeclObjC.cpp:1635
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:1359
void startDefinition()
Starts the definition of this Objective-C class, taking it from a forward declaration (@class) to a d...
Definition: DeclObjC.cpp:617
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition: DeclObjC.h:1910
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:351
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition: DeclObjC.h:1538
TypeSourceInfo * getSuperClassTInfo() const
Definition: DeclObjC.h:1569
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:6495
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
Definition: Type.cpp:849
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1947
AccessControl getAccessControl() const
Definition: DeclObjC.h:1996
bool getSynthesize() const
Definition: DeclObjC.h:2003
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
ImplicitParamDecl * getSelfDecl() const
Definition: DeclObjC.h:418
ArrayRef< ParmVarDecl * > parameters() const
Definition: DeclObjC.h:373
unsigned param_size() const
Definition: DeclObjC.h:347
bool isPropertyAccessor() const
Definition: DeclObjC.h:436
param_const_iterator param_end() const
Definition: DeclObjC.h:358
param_const_iterator param_begin() const
Definition: DeclObjC.h:354
bool isVariadic() const
Definition: DeclObjC.h:431
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclObjC.cpp:1047
TypeSourceInfo * getReturnTypeSourceInfo() const
Definition: DeclObjC.h:343
bool isSynthesizedAccessorStub() const
Definition: DeclObjC.h:444
bool hasRelatedResultType() const
Determine whether this method has a result type that is related to the message receiver's type.
Definition: DeclObjC.h:256
void setMethodParams(ASTContext &C, ArrayRef< ParmVarDecl * > Params, ArrayRef< SourceLocation > SelLocs=std::nullopt)
Sets the method's parameters and selector source locations.
Definition: DeclObjC.cpp:944
bool isInstanceMethod() const
Definition: DeclObjC.h:426
bool isDefined() const
Definition: DeclObjC.h:452
void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID)
createImplicitParams - Used to lazily create the self and cmd implicit parameters.
Definition: DeclObjC.cpp:1190
QualType getReturnType() const
Definition: DeclObjC.h:329
ParmVarDecl *const * param_iterator
Definition: DeclObjC.h:350
ObjCImplementationControl getImplementationControl() const
Definition: DeclObjC.h:500
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.cpp:1211
void getSelectorLocs(SmallVectorImpl< SourceLocation > &SelLocs) const
Definition: DeclObjC.cpp:938
Represents a pointer to an Objective C object.
Definition: Type.h:6551
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:6563
Represents a class type in Objective C.
Definition: Type.h:6297
bool isKindOfTypeAsWritten() const
Whether this is a "__kindof" type as written.
Definition: Type.h:6412
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments of this object type as they were written.
Definition: Type.h:6407
QualType getBaseType() const
Gets the base type of this object type.
Definition: Type.h:6359
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:729
void setSetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:892
SourceLocation getGetterNameLoc() const
Definition: DeclObjC.h:882
ObjCMethodDecl * getGetterMethodDecl() const
Definition: DeclObjC.h:897
bool isInstanceProperty() const
Definition: DeclObjC.h:850
ObjCMethodDecl * getSetterMethodDecl() const
Definition: DeclObjC.h:900
SourceLocation getSetterNameLoc() const
Definition: DeclObjC.h:890
SourceLocation getAtLoc() const
Definition: DeclObjC.h:792
void setPropertyAttributes(ObjCPropertyAttribute::Kind PRVal)
Definition: DeclObjC.h:815
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:920
Selector getSetterName() const
Definition: DeclObjC.h:889
TypeSourceInfo * getTypeSourceInfo() const
Definition: DeclObjC.h:798
QualType getType() const
Definition: DeclObjC.h:800
void setPropertyAttributesAsWritten(ObjCPropertyAttribute::Kind PRVal)
Definition: DeclObjC.h:827
Selector getGetterName() const
Definition: DeclObjC.h:881
void setPropertyIvarDecl(ObjCIvarDecl *Ivar)
Definition: DeclObjC.h:916
SourceLocation getLParenLoc() const
Definition: DeclObjC.h:795
void setSetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:901
ObjCPropertyAttribute::Kind getPropertyAttributesAsWritten() const
Definition: DeclObjC.h:823
ObjCPropertyAttribute::Kind getPropertyAttributes() const
Definition: DeclObjC.h:811
void setGetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:884
PropertyControl getPropertyImplementation() const
Definition: DeclObjC.h:908
void setGetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:898
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition: DeclObjC.h:2802
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:2875
SourceLocation getPropertyIvarDeclLoc() const
Definition: DeclObjC.h:2878
Kind getPropertyImplementation() const
Definition: DeclObjC.h:2871
ObjCPropertyDecl * getPropertyDecl() const
Definition: DeclObjC.h:2866
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclObjC.h:2863
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2079
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
Definition: DeclObjC.h:2255
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:2203
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Definition: DeclObjC.h:2244
void startDefinition()
Starts the definition of this Objective-C protocol.
Definition: DeclObjC.cpp:2029
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2152
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:2159
protocol_iterator protocol_end() const
Definition: DeclObjC.h:2166
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:2180
ArrayRef< ObjCProtocolDecl * > getProtocols() const
Retrieve all of the protocol qualifiers.
Definition: Type.h:6214
qual_range quals() const
Definition: Type.h:6195
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:578
unsigned getIndex() const
Retrieve the index into its type parameter list.
Definition: DeclObjC.h:635
SourceLocation getColonLoc() const
Retrieve the location of the ':' separating the type parameter name from the explicitly-specified bou...
Definition: DeclObjC.h:643
ObjCTypeParamVariance getVariance() const
Determine the variance of this type parameter.
Definition: DeclObjC.h:622
SourceLocation getVarianceLoc() const
Retrieve the location of the variance keyword.
Definition: DeclObjC.h:632
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition: DeclObjC.h:658
SourceLocation getRAngleLoc() const
Definition: DeclObjC.h:709
static ObjCTypeParamList * create(ASTContext &ctx, SourceLocation lAngleLoc, ArrayRef< ObjCTypeParamDecl * > typeParams, SourceLocation rAngleLoc)
Create a new Objective-C type parameter list.
Definition: DeclObjC.cpp:1520
SourceLocation getLAngleLoc() const
Definition: DeclObjC.h:708
Represents a type parameter type in Objective C.
Definition: Type.h:6223
ObjCTypeParamDecl * getDecl() const
Definition: Type.h:6265
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition: Expr.h:2464
Expr * getIndexExpr(unsigned Idx)
Definition: Expr.h:2525
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition: Expr.h:2497
const OffsetOfNode & getComponent(unsigned Idx) const
Definition: Expr.h:2511
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
Definition: Expr.cpp:1637
TypeSourceInfo * getTypeSourceInfo() const
Definition: Expr.h:2504
unsigned getNumExpressions() const
Definition: Expr.h:2540
SourceLocation getRParenLoc() const
Return the location of the right parentheses.
Definition: Expr.h:2501
unsigned getNumComponents() const
Definition: Expr.h:2521
Helper class for OffsetOfExpr.
Definition: Expr.h:2358
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition: Expr.h:2416
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition: Expr.h:2422
IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition: Expr.cpp:1672
@ Array
An index into an array.
Definition: Expr.h:2363
@ Identifier
A field in a dependent type, known only by its name.
Definition: Expr.h:2367
@ Field
A field.
Definition: Expr.h:2365
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition: Expr.h:2370
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:2444
Kind getKind() const
Determine what kind of offsetof node this is.
Definition: Expr.h:2412
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:2445
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition: Expr.h:2432
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1168
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition: Expr.h:1218
SourceLocation getLocation() const
Retrieve the location of this expression.
Definition: Expr.h:1190
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition: ExprCXX.h:3117
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:3099
const DeclarationNameInfo & getNameInfo() const
Gets the full name info.
Definition: ExprCXX.h:3072
SourceLocation getNameLoc() const
Gets the location of the name.
Definition: ExprCXX.h:3078
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: ExprCXX.h:3091
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition: ExprCXX.h:3087
llvm::iterator_range< decls_iterator > decls() const
Definition: ExprCXX.h:3064
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments into the given structure.
Definition: ExprCXX.h:3137
DeclarationName getName() const
Gets the name looked up.
Definition: ExprCXX.h:3075
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:3107
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: ExprCXX.h:3132
A structure for storing the information associated with an overloaded template name.
Definition: TemplateName.h:108
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:4142
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition: ExprCXX.h:4171
std::optional< unsigned > getNumExpansions() const
Determine the number of expansions that will be produced when this pack expansion is instantiated,...
Definition: ExprCXX.h:4182
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis that describes this pack expansion.
Definition: ExprCXX.h:4178
Represents a pack expansion of types.
Definition: Type.h:6112
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
Definition: Type.h:6133
std::optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:6137
QualType getPattern() const
Definition: Type.h:4961
Expr * getIndexExpr() const
Definition: Type.h:4960
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:2129
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition: Expr.h:2152
const Expr * getSubExpr() const
Definition: Expr.h:2144
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition: Expr.h:2156
ArrayRef< Expr * > exprs()
Definition: Expr.h:5662
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition: Expr.cpp:4709
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition: Expr.h:5647
SourceLocation getLParenLoc() const
Definition: Expr.h:5664
SourceLocation getRParenLoc() const
Definition: Expr.h:5665
Sugar for parentheses used when specifying types.
Definition: Type.h:2872
QualType getInnerType() const
Definition: Type.h:2881
Represents a parameter to a function.
Definition: Decl.h:1749
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion:
Definition: Decl.h:1830
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition: Decl.h:1809
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition: Decl.h:1817
void setDefaultArg(Expr *defarg)
Definition: Decl.cpp:2980
SourceLocation getExplicitObjectParamThisLoc() const
Definition: Decl.h:1845
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition: Decl.h:1890
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition: Decl.h:1878
void setUninstantiatedDefaultArg(Expr *arg)
Definition: Decl.cpp:3005
bool isObjCMethodParameter() const
Definition: Decl.h:1792
ObjCDeclQualifier getObjCDeclQualifier() const
Definition: Decl.h:1813
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1782
bool hasUninstantiatedDefaultArg() const
Definition: Decl.h:1882
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition: Decl.h:1777
bool hasInheritedDefaultArg() const
Definition: Decl.h:1894
void setKNRPromoted(bool promoted)
Definition: Decl.h:1833
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition: Decl.h:1841
Expr * getDefaultArg()
Definition: Decl.cpp:2968
Expr * getUninstantiatedDefaultArg()
Definition: Decl.cpp:3010
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition: Decl.cpp:3016
unsigned getFunctionScopeDepth() const
Definition: Decl.h:1799
void setHasInheritedDefaultArg(bool I=true)
Definition: Decl.h:1898
PipeType - OpenCL20.
Definition: Type.h:6751
QualType getElementType() const
Definition: Type.h:6762
bool isReadOnly() const
Definition: Type.h:6781
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2898
QualType getPointeeType() const
Definition: Type.h:2908
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1986
SourceLocation getBeginLoc() const
Definition: Expr.h:2050
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
Definition: Expr.cpp:638
bool isTransparent() const
Definition: Expr.h:2025
PredefinedIdentKind getIdentKind() const
Definition: Expr.h:2021
StringLiteral * getFunctionName()
Definition: Expr.h:2030
Stores the type being destroyed by a pseudo-destructor expression.
Definition: ExprCXX.h:2549
A (possibly-)qualified type.
Definition: Type.h:737
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:804
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6902
QualType getCanonicalType() const
Definition: Type.h:6954
QualType getSingleStepDesugaredType(const ASTContext &Context) const
Return the specified type with one level of "sugar" removed from the type.
Definition: Type.h:1101
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:6934
Represents a template name that was expressed as a qualified name.
Definition: TemplateName.h:431
TemplateName getUnderlyingTemplate() const
Return the underlying template name.
Definition: TemplateName.h:466
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:459
bool hasTemplateKeyword() const
Whether the template name was prefixed by the "template" keyword.
Definition: TemplateName.h:463
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3071
Represents a struct/union/class.
Definition: Decl.h:4133
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition: Decl.cpp:5006
void setAnonymousStructOrUnion(bool Anon)
Definition: Decl.h:4189
field_range fields() const
Definition: Decl.h:4339
RecordDecl * getMostRecentDecl()
Definition: Decl.h:4159
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition: Decl.cpp:5047
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:4324
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition: Decl.h:4185
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5092
RecordDecl * getDecl() const
Definition: Type.h:5102
Provides common interface for the Decls that can be redeclared.
Definition: Redeclarable.h:84
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Definition: Redeclarable.h:216
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Definition: Redeclarable.h:204
decl_type * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
Definition: Redeclarable.h:226
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
Definition: Decl.h:4959
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3009
QualType getPointeeTypeAsWritten() const
Definition: Type.h:3025
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition: Stmt.h:3017
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition: Stmt.cpp:1204
Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV)
Can create any sort of selector.
Smart pointer class that efficiently represents Objective-C method names.
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
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition: Expr.h:4425
Expr ** getSubExprs()
Retrieve the array of expressions.
Definition: Expr.h:4462
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Definition: Expr.h:4459
SourceLocation getRParenLoc() const
Definition: Expr.h:4446
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:4449
Represents an expression that computes the length of a parameter pack.
Definition: ExprCXX.h:4220
SourceLocation getPackLoc() const
Determine the location of the parameter pack.
Definition: ExprCXX.h:4283
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof... expression, such as is produced f...
Definition: ExprCXX.h:4306
ArrayRef< TemplateArgument > getPartialArguments() const
Get.
Definition: ExprCXX.h:4311
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, std::optional< unsigned > Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs=std::nullopt)
Definition: ExprCXX.cpp:1644
SourceLocation getOperatorLoc() const
Determine the location of the 'sizeof' keyword.
Definition: ExprCXX.h:4280
SourceLocation getRParenLoc() const
Determine the location of the right parenthesis.
Definition: ExprCXX.h:4286
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition: ExprCXX.h:4289
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Definition: ExprCXX.h:4295
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition: Expr.h:4721
SourceLocation getBeginLoc() const
Definition: Expr.h:4766
const DeclContext * getParentContext() const
If the SourceLocExpr has been resolved return the subexpression representing the resolved value.
Definition: Expr.h:4762
SourceLocation getEndLoc() const
Definition: Expr.h:4767
SourceLocIdentKind getIdentKind() const
Definition: Expr.h:4741
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
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:4051
bool isFailed() const
Definition: DeclCXX.h:4080
SourceLocation getRParenLoc() const
Definition: DeclCXX.h:4082
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:4377
CompoundStmt * getSubStmt()
Definition: Expr.h:4394
unsigned getTemplateDepth() const
Definition: Expr.h:4406
SourceLocation getRParenLoc() const
Definition: Expr.h:4403
SourceLocation getLParenLoc() const
Definition: Expr.h:4401
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:185
Stmt - This represents one statement.
Definition: Stmt.h:84
child_iterator child_begin()
Definition: Stmt.h:1455
StmtClass getStmtClass() const
Definition: Stmt.h:1356
child_iterator child_end()
Definition: Stmt.h:1456
const char * getStmtClassName() const
Definition: Stmt.cpp:79
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:338
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1773
bool isPascal() const
Definition: Expr.h:1903
tokloc_iterator tokloc_begin() const
Definition: Expr.h:1946
tokloc_iterator tokloc_end() const
Definition: Expr.h:1950
StringLiteralKind getKind() const
Definition: Expr.h:1893
StringRef getBytes() const
Allow access to clients that need the byte representation, such as ASTWriterStmt::VisitStringLiteral(...
Definition: Expr.h:1858
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:1171
unsigned getNumConcatenated() const
getNumConcatenated - Get the number of string literal tokens that were concatenated in translation ph...
Definition: Expr.h:1921
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4435
std::optional< unsigned > getPackIndex() const
Definition: ExprCXX.h:4483
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: ExprCXX.h:4477
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: ExprCXX.h:4481
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:141
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:156
A structure for storing the information associated with a substituted template template parameter.
Definition: TemplateName.h:373
std::optional< unsigned > getPackIndex() const
Definition: TemplateName.h:397
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: TemplateName.h:395
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: TemplateName.h:391
Represents the result of substituting a set of types for a template type parameter pack.
Definition: Type.h:5432
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: Type.cpp:4052
TemplateArgument getArgumentPack() const
Definition: Type.cpp:4069
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: Type.h:5458
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:5362
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: Type.h:5383
std::optional< unsigned > getPackIndex() const
Definition: Type.h:5392
QualType getReplacementType() const
Gets the type that was substituted for the template parameter.
Definition: Type.h:5374
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: Type.h:5390
void setNextSwitchCase(SwitchCase *SC)
Definition: Stmt.h:1774
SwitchStmt - This represents a 'switch' stmt.
Definition: Stmt.h:2386
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a switch statement.
Definition: Stmt.cpp:1081
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3549
SourceRange getBraceRange() const
Definition: Decl.h:3628
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3672
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition: Decl.h:3647
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3652
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition: Decl.h:3794
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3777
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:4704
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition: Decl.cpp:4695
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:4750
TagKind getTagKind() const
Definition: Decl.h:3744
void setBraceRange(SourceRange R)
Definition: Decl.h:3629
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition: Decl.h:3655
TagDecl * getDecl() const
Definition: Type.cpp:3902
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:244
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:280
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Definition: DeclTemplate.h:274
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
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:413
Represents a C++ template name within the type system.
Definition: TemplateName.h:202
TemplateDecl * getAsTemplateDecl() 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:247
@ OverloadedTemplate
A set of overloaded template declarations.
Definition: TemplateName.h:222
@ Template
A single template declaration.
Definition: TemplateName.h:219
@ DependentTemplate
A dependent template name that has not been resolved to a template (or set of templates).
Definition: TemplateName.h:234
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:238
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
Definition: TemplateName.h:243
@ QualifiedTemplate
A qualified template name, where the qualification is kept to describe the source code as written.
Definition: TemplateName.h:230
@ AssumedTemplate
An unqualified-id that has been assumed to name a function template that will be found by ADL.
Definition: TemplateName.h:226
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:144
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:180
SourceLocation getRAngleLoc() const
Definition: DeclTemplate.h:201
SourceLocation getLAngleLoc() const
Definition: DeclTemplate.h:200
SourceLocation getTemplateLoc() const
Definition: DeclTemplate.h:199
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:5632
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:5700
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
Definition: Type.h:5698
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
void setDefaultArgument(const ASTContext &C, const TemplateArgumentLoc &DefArg)
Set the default argument for this template parameter, and whether that default argument was inherited...
unsigned getDepth() const
Get the nesting depth of the template parameter.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
Declaration of a template type parameter.
bool wasDeclaredWithTypename() const
Whether this template type parameter was declared with the 'typename' keyword.
unsigned getIndex() const
Retrieve the index of the template parameter.
bool hasTypeConstraint() const
Determine whether this template parameter has a type-constraint.
TypeSourceInfo * getDefaultArgumentInfo() const
Retrieves the default argument's source information, if any.
const TypeConstraint * getTypeConstraint() const
Returns the type constraint associated with this template parameter (if any).
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
void setDefaultArgument(TypeSourceInfo *DefArg)
Set the default argument for this template parameter.
bool isParameterPack() const
Returns whether this is a parameter pack.
unsigned getDepth() const
Retrieve the depth of the template parameter.
void setTypeConstraint(ConceptReference *CR, Expr *ImmediatelyDeclaredConstraint)
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:5325
bool isParameterPack() const
Definition: Type.h:5323
unsigned getIndex() const
Definition: Type.h:5322
unsigned getDepth() const
Definition: Type.h:5321
The top declaration context.
Definition: Decl.h:84
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3521
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition: Decl.h:3538
Declaration of an alias template.
TypeAliasDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
Definition: ASTConcept.h:231
void setTypeForDecl(const Type *TD)
Definition: Decl.h:3382
const Type * getTypeForDecl() const
Definition: Decl.h:3381
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:3384
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:4817
TypeOfKind getKind() const
Returns the kind of 'typeof' type this is.
Definition: Type.h:4829
Expr * getUnderlyingExpr() const
Definition: Type.h:4826
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Definition: Type.h:4865
TypeOfKind getKind() const
Returns the kind of 'typeof' type this is.
Definition: Type.h:4892
QualType getUnmodifiedType() const
Definition: Type.h:4880
The type-property cache.
Definition: Type.cpp:4261
A container of type source information.
Definition: Type.h:6873
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:6884
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2751
ArrayRef< TypeSourceInfo * > getArgs() const
Retrieve the argument types.
Definition: ExprCXX.h:2807
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:1828
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:2812
unsigned getNumArgs() const
Determine the number of arguments to this type trait.
Definition: ExprCXX.h:2798
bool getValue() const
Definition: ExprCXX.h:2792
TypeTrait getTrait() const
Determine which type trait this expression uses.
Definition: ExprCXX.h:2788
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.h:2811
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
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:5872
The base class of the type hierarchy.
Definition: Type.h:1606
const Type * getPointeeOrArrayElementType() const
If this is a pointer type, return the pointee type.
Definition: Type.h:7614
bool isArrayType() const
Definition: Type.h:7220
bool isPointerType() const
Definition: Type.h:7154
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2420
QualType getCanonicalTypeInternal() const
Definition: Type.h:2703
const char * getTypeClassName() const
Definition: Type.cpp:3210
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition: Type.h:7607
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition: Type.cpp:2299
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition: Type.h:2100
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7657
bool isRecordType() const
Definition: Type.h:7244
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition: Type.cpp:1823
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3501
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3399
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:3449
QualType getUnderlyingType() const
Definition: Decl.h:3454
TypedefNameDecl * getDecl() const
Definition: Type.h:4760
QualType desugar() const
Definition: Type.cpp:3722
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition: Expr.h:2567
SourceLocation getRParenLoc() const
Definition: Expr.h:2643
SourceLocation getOperatorLoc() const
Definition: Expr.h:2640
bool isArgumentType() const
Definition: Expr.h:2609
TypeSourceInfo * getArgumentTypeInfo() const
Definition: Expr.h:2613
UnaryExprOrTypeTrait getKind() const
Definition: Expr.h:2599
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2182
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition: Expr.h:2231
Expr * getSubExpr() const
Definition: Expr.h:2227
Opcode getOpcode() const
Definition: Expr.h:2222
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
Definition: Expr.h:2323
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition: Expr.h:2326
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition: Expr.cpp:4803
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Definition: Expr.h:2240
A unary type transform, which is a type constructed from another.
Definition: Type.h:5009
QualType getUnderlyingType() const
Definition: Type.h:5035
QualType getBaseType() const
Definition: Type.h:5036
UTTKind getUTTKind() const
Definition: Type.h:5038
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:3163
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition: ExprCXX.h:3239
bool isOverloaded() const
True if this lookup is overloaded.
Definition: ExprCXX.h:3234
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition: ExprCXX.h:3231
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
Definition: ExprCXX.cpp:373
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition: ExprCXX.h:3905
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition: ExprCXX.h:3997
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition: ExprCXX.h:4000
bool hasUnresolvedUsing() const
Determine whether the lookup results contain an unresolved using declaration.
Definition: ExprCXX.h:3991
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition: ExprCXX.h:3978
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:1586
bool isImplicitAccess() const
True if this is an implicit access, i.e., one in which the member being accessed was not written in t...
Definition: ExprCXX.cpp:1579
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:91
A set of unresolved declarations.
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition: Type.h:4687
UnresolvedUsingTypenameDecl * getDecl() const
Definition: Type.h:4698
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3952
SourceLocation getTypenameLoc() const
Returns the source location of the 'typename' keyword.
Definition: DeclCXX.h:3982
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition: DeclCXX.h:3986
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition: DeclCXX.h:3979
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition: DeclCXX.h:4003
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3855
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition: DeclCXX.h:3886
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition: DeclCXX.h:3896
DeclarationNameInfo getNameInfo() const
Definition: DeclCXX.h:3903
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition: DeclCXX.h:3913
Represents a C++ using-declaration.
Definition: DeclCXX.h:3505
bool hasTypename() const
Return true if the using declaration has 'typename'.
Definition: DeclCXX.h:3554
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition: DeclCXX.h:3539
DeclarationNameInfo getNameInfo() const
Definition: DeclCXX.h:3546
SourceLocation getUsingLoc() const
Return the source location of the 'using' keyword.
Definition: DeclCXX.h:3532
Represents C++ using-directive.
Definition: DeclCXX.h:3008
SourceLocation getUsingLoc() const
Return the location of the using keyword.
Definition: DeclCXX.h:3079
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Definition: DeclCXX.cpp:2956
DeclContext * getCommonAncestor()
Returns the common ancestor context of this using-directive and its nominated namespace.
Definition: DeclCXX.h:3075
SourceLocation getNamespaceKeyLocation() const
Returns the location of the namespace keyword.
Definition: DeclCXX.h:3083
SourceLocation getIdentLocation() const
Returns the location of this using declaration's identifier.
Definition: DeclCXX.h:3086
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition: DeclCXX.h:3053
Represents a C++ using-enum-declaration.
Definition: DeclCXX.h:3706
SourceLocation getEnumLoc() const
The source location of the 'enum' keyword.
Definition: DeclCXX.h:3730
TypeSourceInfo * getEnumType() const
Definition: DeclCXX.h:3744
SourceLocation getUsingLoc() const
The source location of the 'using' keyword.
Definition: DeclCXX.h:3726
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition: DeclCXX.h:3787
NamedDecl * getInstantiatedFromUsingDecl() const
Get the using declaration from which this was instantiated.
Definition: DeclCXX.h:3817
ArrayRef< NamedDecl * > expansions() const
Get the set of using declarations that this pack expanded into.
Definition: DeclCXX.h:3821
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3313
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition: DeclCXX.h:3377
BaseUsingDecl * getIntroducer() const
Gets the (written or instantiated) using declaration that introduced this declaration.
Definition: DeclCXX.cpp:3110
UsingShadowDecl * getFoundDecl() const
Definition: Type.h:4727
QualType getUnderlyingType() const
Definition: Type.cpp:3736
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:4661
TypeSourceInfo * getWrittenTypeInfo() const
Definition: Expr.h:4685
SourceLocation getBuiltinLoc() const
Definition: Expr.h:4688
SourceLocation getRParenLoc() const
Definition: Expr.h:4691
bool isMicrosoftABI() const
Returns whether this is really a Win64 ABI va_arg expression.
Definition: Expr.h:4682
const Expr * getSubExpr() const
Definition: Expr.h:4677
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:706
void setType(QualType newType)
Definition: Decl.h:718
QualType getType() const
Definition: Decl.h:717
Represents a variable declaration or definition.
Definition: Decl.h:918
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition: Decl.cpp:2787
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1546
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition: Decl.cpp:2904
DefinitionKind isThisDeclarationADefinition(ASTContext &) const
Check whether this declaration is a definition.
Definition: Decl.cpp:2257
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition: Decl.cpp:2363
EvaluatedStmt * getEvaluatedStmt() const
Definition: Decl.cpp:2547
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition: Decl.cpp:2533
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
Definition: Decl.cpp:2749
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
Definition: Decl.h:1326
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition: Decl.h:1157
ThreadStorageClassSpecifier getTSCSpec() const
Definition: Decl.h:1161
const Expr * getInit() const
Definition: Decl.h:1352
void setConstexpr(bool IC)
Definition: Decl.h:1549
void setInit(Expr *I)
Definition: Decl.cpp:2454
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition: Decl.cpp:2792
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1152
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Definition: Decl.h:1342
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition: Decl.cpp:2867
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.
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary variable pattern.
VarTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
VarTemplateDecl * getMostRecentDecl()
Represents a variable template specialization, which refers to a variable template with a given set o...
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
void setSpecializationKind(TemplateSpecializationKind TSK)
void setTemplateArgsInfo(const TemplateArgumentListInfo &ArgsInfo)
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
void setPointOfInstantiation(SourceLocation Loc)
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
const ASTTemplateArgumentListInfo * getTemplateArgsInfo() const
VarTemplateSpecializationDecl * getMostRecentDecl()
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:3290
SourceRange getBracketsRange() const
Definition: Type.h:3315
Expr * getSizeExpr() const
Definition: Type.h:3309
Represents a GCC generic vector type.
Definition: Type.h:3512
unsigned getNumElements() const
Definition: Type.h:3527
VectorKind getVectorKind() const
Definition: Type.h:3532
QualType getElementType() const
Definition: Type.h:3526
WhileStmt - This represents a 'while' stmt.
Definition: Stmt.h:2582
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:1143
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition: Address.h:155
StructuralEquivalenceKind
Whether to perform a normal or minimal equivalence check.
CanThrowResult
Possible results from evaluation of a noexcept expression.
void updateFlags(const Decl *From, Decl *To)
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition: Specifiers.h:146
@ 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:307
@ BTK__make_integer_seq
This names the __make_integer_seq BuiltinTemplateDecl.
Definition: Builtins.h:304
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:129
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:1285
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:185
#define false
Definition: stdbool.h:22
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:1797
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:883
bool HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition: Decl.h:901
bool HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition: Decl.h:894
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition: Type.h:4262
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:4266
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:4252
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:4255
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition: Type.h:4258
Extra information about a function prototype.
Definition: Type.h:4278
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:4285
FunctionType::ExtInfo ExtInfo
Definition: Type.h:4279
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