clang 23.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
18#include "clang/AST/ASTLambda.h"
20#include "clang/AST/Attr.h"
21#include "clang/AST/Decl.h"
23#include "clang/AST/DeclBase.h"
24#include "clang/AST/DeclCXX.h"
26#include "clang/AST/DeclGroup.h"
27#include "clang/AST/DeclObjC.h"
31#include "clang/AST/Expr.h"
32#include "clang/AST/ExprCXX.h"
33#include "clang/AST/ExprObjC.h"
38#include "clang/AST/Stmt.h"
39#include "clang/AST/StmtCXX.h"
40#include "clang/AST/StmtObjC.h"
44#include "clang/AST/Type.h"
45#include "clang/AST/TypeLoc.h"
52#include "clang/Basic/LLVM.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/ErrorHandling.h"
63#include "llvm/Support/MemoryBuffer.h"
64#include <algorithm>
65#include <cassert>
66#include <cstddef>
67#include <memory>
68#include <optional>
69#include <type_traits>
70#include <utility>
71
72namespace clang {
73
74 using llvm::make_error;
75 using llvm::Error;
76 using llvm::Expected;
84
85 std::string ASTImportError::toString() const {
86 // FIXME: Improve error texts.
87 switch (Error) {
88 case NameConflict:
89 return "NameConflict";
91 return "UnsupportedConstruct";
92 case Unknown:
93 return "Unknown error";
94 }
95 llvm_unreachable("Invalid error code.");
96 return "Invalid error code.";
97 }
98
99 void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
100
101 std::error_code ASTImportError::convertToErrorCode() const {
102 llvm_unreachable("Function not implemented.");
103 }
104
106
107 template <class T>
111 for (auto *R : D->getFirstDecl()->redecls()) {
112 if (R != D->getFirstDecl())
113 Redecls.push_back(R);
114 }
115 Redecls.push_back(D->getFirstDecl());
116 std::reverse(Redecls.begin(), Redecls.end());
117 return Redecls;
118 }
119
121 if (auto *FD = dyn_cast<FunctionDecl>(D))
123 if (auto *VD = dyn_cast<VarDecl>(D))
125 if (auto *TD = dyn_cast<TagDecl>(D))
127 llvm_unreachable("Bad declaration kind");
128 }
129
130 static void updateFlags(const Decl *From, Decl *To) {
131 // Check if some flags or attrs are new in 'From' and copy into 'To'.
132 // FIXME: Other flags or attrs?
133 if (From->isUsed(false) && !To->isUsed(false))
134 To->setIsUsed();
135 }
136
137 /// How to handle import errors that occur when import of a child declaration
138 /// of a DeclContext fails.
140 /// This context is imported (in the 'from' domain).
141 /// It is nullptr if a non-DeclContext is imported.
142 const DeclContext *const FromDC;
143 /// Ignore import errors of the children.
144 /// If true, the context can be imported successfully if a child
145 /// of it failed to import. Otherwise the import errors of the child nodes
146 /// are accumulated (joined) into the import error object of the parent.
147 /// (Import of a parent can fail in other ways.)
148 bool const IgnoreChildErrors;
149
150 public:
152 : FromDC(FromDC), IgnoreChildErrors(!isa<TagDecl>(FromDC)) {}
154 : FromDC(dyn_cast<DeclContext>(FromD)),
155 IgnoreChildErrors(!isa<TagDecl>(FromD)) {}
156
157 /// Process the import result of a child (of the current declaration).
158 /// \param ResultErr The import error that can be used as result of
159 /// importing the parent. This may be changed by the function.
160 /// \param ChildErr Result of importing a child. Can be success or error.
161 void handleChildImportResult(Error &ResultErr, Error &&ChildErr) {
162 if (ChildErr && !IgnoreChildErrors)
163 ResultErr = joinErrors(std::move(ResultErr), std::move(ChildErr));
164 else
165 consumeError(std::move(ChildErr));
166 }
167
168 /// Determine if import failure of a child does not cause import failure of
169 /// its parent.
170 bool ignoreChildErrorOnParent(Decl *FromChildD) const {
171 if (!IgnoreChildErrors || !FromDC)
172 return false;
173 return FromDC->containsDecl(FromChildD);
174 }
175 };
176
177 class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>,
178 public DeclVisitor<ASTNodeImporter, ExpectedDecl>,
179 public StmtVisitor<ASTNodeImporter, ExpectedStmt> {
180 ASTImporter &Importer;
181
182 // Use this instead of Importer.importInto .
183 template <typename ImportT>
184 [[nodiscard]] Error importInto(ImportT &To, const ImportT &From) {
185 return Importer.importInto(To, From);
186 }
187
188 // Use this to import pointers of specific type.
189 template <typename ImportT>
190 [[nodiscard]] Error importInto(ImportT *&To, ImportT *From) {
191 auto ToOrErr = Importer.Import(From);
192 if (ToOrErr)
193 To = cast_or_null<ImportT>(*ToOrErr);
194 return ToOrErr.takeError();
195 }
196
197 // Call the import function of ASTImporter for a baseclass of type `T` and
198 // cast the return value to `T`.
199 template <typename T>
200 auto import(T *From)
201 -> std::conditional_t<std::is_base_of_v<Type, T>, Expected<const T *>,
203 auto ToOrErr = Importer.Import(From);
204 if (!ToOrErr)
205 return ToOrErr.takeError();
206 return cast_or_null<T>(*ToOrErr);
207 }
208
209 template <typename T>
210 auto import(const T *From) {
211 return import(const_cast<T *>(From));
212 }
213
214 // Call the import function of ASTImporter for type `T`.
215 template <typename T>
216 Expected<T> import(const T &From) {
217 return Importer.Import(From);
218 }
219
220 // Import an std::optional<T> by importing the contained T, if any.
221 template <typename T>
222 Expected<std::optional<T>> import(std::optional<T> From) {
223 if (!From)
224 return std::nullopt;
225 return import(*From);
226 }
227
228 ExplicitSpecifier importExplicitSpecifier(Error &Err,
229 ExplicitSpecifier ESpec);
230
231 // Wrapper for an overload set.
232 template <typename ToDeclT> struct CallOverloadedCreateFun {
233 template <typename... Args> decltype(auto) operator()(Args &&... args) {
234 return ToDeclT::Create(std::forward<Args>(args)...);
235 }
236 };
237
238 // Always use these functions to create a Decl during import. There are
239 // certain tasks which must be done after the Decl was created, e.g. we
240 // must immediately register that as an imported Decl. The parameter `ToD`
241 // will be set to the newly created Decl or if had been imported before
242 // then to the already imported Decl. Returns a bool value set to true if
243 // the `FromD` had been imported before.
244 template <typename ToDeclT, typename FromDeclT, typename... Args>
245 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
246 Args &&...args) {
247 // There may be several overloads of ToDeclT::Create. We must make sure
248 // to call the one which would be chosen by the arguments, thus we use a
249 // wrapper for the overload set.
250 CallOverloadedCreateFun<ToDeclT> OC;
251 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
252 std::forward<Args>(args)...);
253 }
254 // Use this overload if a special Type is needed to be created. E.g if we
255 // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl`
256 // then:
257 // TypedefNameDecl *ToTypedef;
258 // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...);
259 template <typename NewDeclT, typename ToDeclT, typename FromDeclT,
260 typename... Args>
261 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
262 Args &&...args) {
263 CallOverloadedCreateFun<NewDeclT> OC;
264 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
265 std::forward<Args>(args)...);
266 }
267 // Use this version if a special create function must be
268 // used, e.g. CXXRecordDecl::CreateLambda .
269 template <typename ToDeclT, typename CreateFunT, typename FromDeclT,
270 typename... Args>
271 [[nodiscard]] bool
272 GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun,
273 FromDeclT *FromD, Args &&...args) {
274 if (Importer.getImportDeclErrorIfAny(FromD)) {
275 ToD = nullptr;
276 return true; // Already imported but with error.
277 }
278 ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD));
279 if (ToD)
280 return true; // Already imported.
281 ToD = CreateFun(std::forward<Args>(args)...);
282 // Keep track of imported Decls.
283 Importer.RegisterImportedDecl(FromD, ToD);
284 Importer.SharedState->markAsNewDecl(ToD);
285 InitializeImportedDecl(FromD, ToD);
286 return false; // A new Decl is created.
287 }
288
289 void InitializeImportedDecl(Decl *FromD, Decl *ToD) {
290 ToD->IdentifierNamespace = FromD->IdentifierNamespace;
291 if (FromD->isUsed())
292 ToD->setIsUsed();
293 if (FromD->isImplicit())
294 ToD->setImplicit();
295 }
296
297 // Check if we have found an existing definition. Returns with that
298 // definition if yes, otherwise returns null.
299 Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) {
300 const FunctionDecl *Definition = nullptr;
302 FoundFunction->hasBody(Definition))
303 return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition));
304 return nullptr;
305 }
306
307 void addDeclToContexts(Decl *FromD, Decl *ToD) {
308 if (Importer.isMinimalImport()) {
309 // In minimal import case the decl must be added even if it is not
310 // contained in original context, for LLDB compatibility.
311 // FIXME: Check if a better solution is possible.
312 if (!FromD->getDescribedTemplate() &&
313 FromD->getFriendObjectKind() == Decl::FOK_None)
315 return;
316 }
317
318 DeclContext *FromDC = FromD->getDeclContext();
319 DeclContext *FromLexicalDC = FromD->getLexicalDeclContext();
320 DeclContext *ToDC = ToD->getDeclContext();
321 DeclContext *ToLexicalDC = ToD->getLexicalDeclContext();
322
323 bool Visible = false;
324 if (FromDC->containsDeclAndLoad(FromD)) {
325 ToDC->addDeclInternal(ToD);
326 Visible = true;
327 }
328 if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) {
329 ToLexicalDC->addDeclInternal(ToD);
330 Visible = true;
331 }
332
333 // If the Decl was added to any context, it was made already visible.
334 // Otherwise it is still possible that it should be visible.
335 if (!Visible) {
336 if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) {
337 auto *ToNamed = cast<NamedDecl>(ToD);
338 DeclContextLookupResult FromLookup =
339 FromDC->lookup(FromNamed->getDeclName());
340 if (llvm::is_contained(FromLookup, FromNamed))
341 ToDC->makeDeclVisibleInContext(ToNamed);
342 }
343 }
344 }
345
346 void updateLookupTableForTemplateParameters(TemplateParameterList &Params,
347 DeclContext *OldDC) {
348 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
349 if (!LT)
350 return;
351
352 for (NamedDecl *TP : Params)
353 LT->update(TP, OldDC);
354 }
355
356 void updateLookupTableForTemplateParameters(TemplateParameterList &Params) {
357 updateLookupTableForTemplateParameters(
358 Params, Importer.getToContext().getTranslationUnitDecl());
359 }
360
361 template <typename TemplateParmDeclT>
362 Error importTemplateParameterDefaultArgument(const TemplateParmDeclT *D,
363 TemplateParmDeclT *ToD) {
364 if (D->hasDefaultArgument()) {
365 if (D->defaultArgumentWasInherited()) {
366 Expected<TemplateParmDeclT *> ToInheritedFromOrErr =
367 import(D->getDefaultArgStorage().getInheritedFrom());
368 if (!ToInheritedFromOrErr)
369 return ToInheritedFromOrErr.takeError();
370 TemplateParmDeclT *ToInheritedFrom = *ToInheritedFromOrErr;
371 if (!ToInheritedFrom->hasDefaultArgument()) {
372 // Resolve possible circular dependency between default value of the
373 // template argument and the template declaration.
374 Expected<TemplateArgumentLoc> ToInheritedDefaultArgOrErr =
375 import(D->getDefaultArgStorage()
376 .getInheritedFrom()
377 ->getDefaultArgument());
378 if (!ToInheritedDefaultArgOrErr)
379 return ToInheritedDefaultArgOrErr.takeError();
380 ToInheritedFrom->setDefaultArgument(Importer.getToContext(),
381 *ToInheritedDefaultArgOrErr);
382 }
383 ToD->setInheritedDefaultArgument(ToD->getASTContext(),
384 ToInheritedFrom);
385 } else {
386 Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
387 import(D->getDefaultArgument());
388 if (!ToDefaultArgOrErr)
389 return ToDefaultArgOrErr.takeError();
390 // Default argument could have been set in the
391 // '!ToInheritedFrom->hasDefaultArgument()' branch above.
392 if (!ToD->hasDefaultArgument())
393 ToD->setDefaultArgument(Importer.getToContext(),
394 *ToDefaultArgOrErr);
395 }
396 }
397 return Error::success();
398 }
399
400 public:
401 explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {}
402
406
407 // Importing types
408 ExpectedType VisitType(const Type *T);
409#define TYPE(Class, Base) \
410 ExpectedType Visit##Class##Type(const Class##Type *T);
411#include "clang/AST/TypeNodes.inc"
412
413 // Importing declarations
415 SourceLocation &Loc);
417 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
418 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc);
419 Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
422 Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
424 Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
426
427 Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To);
429 Expected<APValue> ImportAPValue(const APValue &FromValue);
430
432
433 /// What we should import from the definition.
435 /// Import the default subset of the definition, which might be
436 /// nothing (if minimal import is set) or might be everything (if minimal
437 /// import is not set).
439 /// Import everything.
441 /// Import only the bare bones needed to establish a valid
442 /// DeclContext.
444 };
445
447 return IDK == IDK_Everything ||
448 (IDK == IDK_Default && !Importer.isMinimalImport());
449 }
450
453 RecordDecl *From, RecordDecl *To,
456 EnumDecl *From, EnumDecl *To,
468
469 template <typename InContainerTy>
471 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo);
472
473 template<typename InContainerTy>
475 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
476 const InContainerTy &Container, TemplateArgumentListInfo &Result);
477
480 std::tuple<FunctionTemplateDecl *, TemplateArgsTy>;
483 FunctionDecl *FromFD);
484
485 template <typename DeclTy>
486 Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD);
487
489
491
493 ParmVarDecl *ToParam);
494
497
498 // Use for allocating string for newly imported object.
499 StringRef ImportASTStringRef(StringRef FromStr);
508
509 template <typename T>
511
512 bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
513 bool IgnoreTemplateParmDepth = false);
560
563
581
582 // Importing statements
602 // FIXME: MSAsmStmt
603 // FIXME: SEHExceptStmt
604 // FIXME: SEHFinallyStmt
605 // FIXME: SEHTryStmt
606 // FIXME: SEHLeaveStmt
607 // FIXME: CapturedStmt
611 // FIXME: MSDependentExistsStmt
619
620 // Importing expressions
703
704 // Helper for chaining together multiple imports. If an error is detected,
705 // subsequent imports will return default constructed nodes, so that failure
706 // can be detected with a single conditional branch after a sequence of
707 // imports.
708 template <typename T> T importChecked(Error &Err, const T &From) {
709 // Don't attempt to import nodes if we hit an error earlier.
710 if (Err)
711 return T{};
712 Expected<T> MaybeVal = import(From);
713 if (!MaybeVal) {
714 Err = MaybeVal.takeError();
715 return T{};
716 }
717 return *MaybeVal;
718 }
719
720 template<typename IIter, typename OIter>
721 Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
722 using ItemT = std::remove_reference_t<decltype(*Obegin)>;
723 for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
724 Expected<ItemT> ToOrErr = import(*Ibegin);
725 if (!ToOrErr)
726 return ToOrErr.takeError();
727 *Obegin = *ToOrErr;
728 }
729 return Error::success();
730 }
731
732 // Import every item from a container structure into an output container.
733 // If error occurs, stops at first error and returns the error.
734 // The output container should have space for all needed elements (it is not
735 // expanded, new items are put into from the beginning).
736 template<typename InContainerTy, typename OutContainerTy>
738 const InContainerTy &InContainer, OutContainerTy &OutContainer) {
739 return ImportArrayChecked(
740 InContainer.begin(), InContainer.end(), OutContainer.begin());
741 }
742
743 template<typename InContainerTy, typename OIter>
744 Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
745 return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
746 }
747
749 CXXMethodDecl *FromMethod);
750
752 FunctionDecl *FromFD);
753
754 // Returns true if the given function has a placeholder return type and
755 // that type is declared inside the body of the function.
756 // E.g. auto f() { struct X{}; return X(); }
758 };
759
760template <typename InContainerTy>
762 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
763 const InContainerTy &Container, TemplateArgumentListInfo &Result) {
764 auto ToLAngleLocOrErr = import(FromLAngleLoc);
765 if (!ToLAngleLocOrErr)
766 return ToLAngleLocOrErr.takeError();
767 auto ToRAngleLocOrErr = import(FromRAngleLoc);
768 if (!ToRAngleLocOrErr)
769 return ToRAngleLocOrErr.takeError();
770
771 TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr);
772 if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo))
773 return Err;
774 Result = std::move(ToTAInfo);
775 return Error::success();
776}
777
778template <>
784
785template <>
793
796 FunctionDecl *FromFD) {
797 assert(FromFD->getTemplatedKind() ==
799
801
802 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
803 if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate()))
804 return std::move(Err);
805
806 // Import template arguments.
807 if (Error Err = ImportTemplateArguments(FTSInfo->TemplateArguments->asArray(),
808 std::get<1>(Result)))
809 return std::move(Err);
810
811 return Result;
812}
813
814template <>
816ASTNodeImporter::import(TemplateParameterList *From) {
818 if (Error Err = ImportContainerChecked(*From, To))
819 return std::move(Err);
820
821 ExpectedExpr ToRequiresClause = import(From->getRequiresClause());
822 if (!ToRequiresClause)
823 return ToRequiresClause.takeError();
824
825 auto ToTemplateLocOrErr = import(From->getTemplateLoc());
826 if (!ToTemplateLocOrErr)
827 return ToTemplateLocOrErr.takeError();
828 auto ToLAngleLocOrErr = import(From->getLAngleLoc());
829 if (!ToLAngleLocOrErr)
830 return ToLAngleLocOrErr.takeError();
831 auto ToRAngleLocOrErr = import(From->getRAngleLoc());
832 if (!ToRAngleLocOrErr)
833 return ToRAngleLocOrErr.takeError();
834
836 Importer.getToContext(),
837 *ToTemplateLocOrErr,
838 *ToLAngleLocOrErr,
839 To,
840 *ToRAngleLocOrErr,
841 *ToRequiresClause);
842}
843
844template <>
846ASTNodeImporter::import(const TemplateArgument &From) {
847 switch (From.getKind()) {
849 return TemplateArgument();
850
852 ExpectedType ToTypeOrErr = import(From.getAsType());
853 if (!ToTypeOrErr)
854 return ToTypeOrErr.takeError();
855 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false,
856 From.getIsDefaulted());
857 }
858
860 ExpectedType ToTypeOrErr = import(From.getIntegralType());
861 if (!ToTypeOrErr)
862 return ToTypeOrErr.takeError();
863 return TemplateArgument(From, *ToTypeOrErr);
864 }
865
867 Expected<ValueDecl *> ToOrErr = import(From.getAsDecl());
868 if (!ToOrErr)
869 return ToOrErr.takeError();
870 ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
871 if (!ToTypeOrErr)
872 return ToTypeOrErr.takeError();
873 return TemplateArgument(dyn_cast<ValueDecl>((*ToOrErr)->getCanonicalDecl()),
874 *ToTypeOrErr, From.getIsDefaulted());
875 }
876
878 ExpectedType ToTypeOrErr = import(From.getNullPtrType());
879 if (!ToTypeOrErr)
880 return ToTypeOrErr.takeError();
881 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true,
882 From.getIsDefaulted());
883 }
884
886 ExpectedType ToTypeOrErr = import(From.getStructuralValueType());
887 if (!ToTypeOrErr)
888 return ToTypeOrErr.takeError();
889 Expected<APValue> ToValueOrErr = import(From.getAsStructuralValue());
890 if (!ToValueOrErr)
891 return ToValueOrErr.takeError();
892 return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
893 *ToValueOrErr);
894 }
895
897 Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
898 if (!ToTemplateOrErr)
899 return ToTemplateOrErr.takeError();
900
901 return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
902 }
903
905 Expected<TemplateName> ToTemplateOrErr =
906 import(From.getAsTemplateOrTemplatePattern());
907 if (!ToTemplateOrErr)
908 return ToTemplateOrErr.takeError();
909
910 return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(),
911 From.getIsDefaulted());
912 }
913
915 if (ExpectedExpr ToExpr = import(From.getAsExpr()))
916 return TemplateArgument(*ToExpr, From.isCanonicalExpr(),
917 From.getIsDefaulted());
918 else
919 return ToExpr.takeError();
920
923 ToPack.reserve(From.pack_size());
924 if (Error Err = ImportTemplateArguments(From.pack_elements(), ToPack))
925 return std::move(Err);
926
927 return TemplateArgument(ArrayRef(ToPack).copy(Importer.getToContext()));
928 }
929 }
930
931 llvm_unreachable("Invalid template argument kind");
932}
933
934template <>
936ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) {
937 Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument());
938 if (!ArgOrErr)
939 return ArgOrErr.takeError();
940 TemplateArgument Arg = *ArgOrErr;
941
942 TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
943
946 ExpectedExpr E = import(FromInfo.getAsExpr());
947 if (!E)
948 return E.takeError();
949 ToInfo = TemplateArgumentLocInfo(*E);
950 } else if (Arg.getKind() == TemplateArgument::Type) {
951 if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo()))
952 ToInfo = TemplateArgumentLocInfo(*TSIOrErr);
953 else
954 return TSIOrErr.takeError();
955 } else {
956 auto ToTemplateKWLocOrErr = import(FromInfo.getTemplateKwLoc());
957 if (!ToTemplateKWLocOrErr)
958 return ToTemplateKWLocOrErr.takeError();
959 auto ToTemplateQualifierLocOrErr = import(TALoc.getTemplateQualifierLoc());
960 if (!ToTemplateQualifierLocOrErr)
961 return ToTemplateQualifierLocOrErr.takeError();
962 auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc());
963 if (!ToTemplateNameLocOrErr)
964 return ToTemplateNameLocOrErr.takeError();
965 auto ToTemplateEllipsisLocOrErr =
966 import(FromInfo.getTemplateEllipsisLoc());
967 if (!ToTemplateEllipsisLocOrErr)
968 return ToTemplateEllipsisLocOrErr.takeError();
970 Importer.getToContext(), *ToTemplateKWLocOrErr,
971 *ToTemplateQualifierLocOrErr, *ToTemplateNameLocOrErr,
972 *ToTemplateEllipsisLocOrErr);
973 }
974
975 return TemplateArgumentLoc(Arg, ToInfo);
976}
977
978template <>
979Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) {
980 if (DG.isNull())
981 return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
982 size_t NumDecls = DG.end() - DG.begin();
984 ToDecls.reserve(NumDecls);
985 for (Decl *FromD : DG) {
986 if (auto ToDOrErr = import(FromD))
987 ToDecls.push_back(*ToDOrErr);
988 else
989 return ToDOrErr.takeError();
990 }
991 return DeclGroupRef::Create(Importer.getToContext(),
992 ToDecls.begin(),
993 NumDecls);
994}
995
996template <>
998ASTNodeImporter::import(const Designator &D) {
999 if (D.isFieldDesignator()) {
1000 IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
1001
1002 ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc());
1003 if (!ToDotLocOrErr)
1004 return ToDotLocOrErr.takeError();
1005
1006 ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc());
1007 if (!ToFieldLocOrErr)
1008 return ToFieldLocOrErr.takeError();
1009
1011 ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr);
1012 }
1013
1014 ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc());
1015 if (!ToLBracketLocOrErr)
1016 return ToLBracketLocOrErr.takeError();
1017
1018 ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc());
1019 if (!ToRBracketLocOrErr)
1020 return ToRBracketLocOrErr.takeError();
1021
1022 if (D.isArrayDesignator())
1024 *ToLBracketLocOrErr,
1025 *ToRBracketLocOrErr);
1026
1027 ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc());
1028 if (!ToEllipsisLocOrErr)
1029 return ToEllipsisLocOrErr.takeError();
1030
1031 assert(D.isArrayRangeDesignator());
1033 D.getArrayIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr,
1034 *ToRBracketLocOrErr);
1035}
1036
1037template <>
1038Expected<ConceptReference *> ASTNodeImporter::import(ConceptReference *From) {
1039 Error Err = Error::success();
1040 auto ToNNS = importChecked(Err, From->getNestedNameSpecifierLoc());
1041 auto ToTemplateKWLoc = importChecked(Err, From->getTemplateKWLoc());
1042 auto ToConceptNameLoc =
1043 importChecked(Err, From->getConceptNameInfo().getLoc());
1044 auto ToConceptName = importChecked(Err, From->getConceptNameInfo().getName());
1045 auto ToFoundDecl = importChecked(Err, From->getFoundDecl());
1046 auto ToNamedConcept = importChecked(Err, From->getNamedConcept());
1047 if (Err)
1048 return std::move(Err);
1049 TemplateArgumentListInfo ToTAInfo;
1050 const auto *ASTTemplateArgs = From->getTemplateArgsAsWritten();
1051 if (ASTTemplateArgs)
1052 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
1053 return std::move(Err);
1054 auto *ConceptRef = ConceptReference::Create(
1055 Importer.getToContext(), ToNNS, ToTemplateKWLoc,
1056 DeclarationNameInfo(ToConceptName, ToConceptNameLoc), ToFoundDecl,
1057 ToNamedConcept,
1058 ASTTemplateArgs ? ASTTemplateArgumentListInfo::Create(
1059 Importer.getToContext(), ToTAInfo)
1060 : nullptr);
1061 return ConceptRef;
1062}
1063
1064StringRef ASTNodeImporter::ImportASTStringRef(StringRef FromStr) {
1065 char *ToStore = new (Importer.getToContext()) char[FromStr.size()];
1066 std::copy(FromStr.begin(), FromStr.end(), ToStore);
1067 return StringRef(ToStore, FromStr.size());
1068}
1069
1071 const ASTConstraintSatisfaction &FromSat, ConstraintSatisfaction &ToSat) {
1072 ToSat.IsSatisfied = FromSat.IsSatisfied;
1073 ToSat.ContainsErrors = FromSat.ContainsErrors;
1074 if (!ToSat.IsSatisfied) {
1075 for (auto Record = FromSat.begin(); Record != FromSat.end(); ++Record) {
1076 if (const Expr *E = Record->dyn_cast<const Expr *>()) {
1077 ExpectedExpr ToSecondExpr = import(E);
1078 if (!ToSecondExpr)
1079 return ToSecondExpr.takeError();
1080 ToSat.Details.emplace_back(ToSecondExpr.get());
1081 } else {
1082 auto Pair =
1083 Record->dyn_cast<const ConstraintSubstitutionDiagnostic *>();
1084
1085 ExpectedSLoc ToPairFirst = import(Pair->first);
1086 if (!ToPairFirst)
1087 return ToPairFirst.takeError();
1088 StringRef ToPairSecond = ImportASTStringRef(Pair->second);
1089 ToSat.Details.emplace_back(new (Importer.getToContext())
1091 ToPairFirst.get(), ToPairSecond});
1092 }
1093 }
1094 }
1095 return Error::success();
1096}
1097
1098template <>
1100ASTNodeImporter::import(
1102 StringRef ToEntity = ImportASTStringRef(FromDiag->SubstitutedEntity);
1103 ExpectedSLoc ToLoc = import(FromDiag->DiagLoc);
1104 if (!ToLoc)
1105 return ToLoc.takeError();
1106 StringRef ToDiagMessage = ImportASTStringRef(FromDiag->DiagMessage);
1107 return new (Importer.getToContext())
1109 ToDiagMessage};
1110}
1111
1114 using namespace concepts;
1115
1116 if (From->isSubstitutionFailure()) {
1117 auto DiagOrErr = import(From->getSubstitutionDiagnostic());
1118 if (!DiagOrErr)
1119 return DiagOrErr.takeError();
1120 return new (Importer.getToContext()) TypeRequirement(*DiagOrErr);
1121 } else {
1122 Expected<TypeSourceInfo *> ToType = import(From->getType());
1123 if (!ToType)
1124 return ToType.takeError();
1125 return new (Importer.getToContext()) TypeRequirement(*ToType);
1126 }
1127}
1128
1131 using namespace concepts;
1132
1133 bool IsRKSimple = From->getKind() == Requirement::RK_Simple;
1134 ExprRequirement::SatisfactionStatus Status = From->getSatisfactionStatus();
1135
1136 std::optional<ExprRequirement::ReturnTypeRequirement> Req;
1137 ConceptSpecializationExpr *SubstitutedConstraintExpr = nullptr;
1138
1139 if (IsRKSimple) {
1140 Req.emplace();
1141 } else {
1142 const ExprRequirement::ReturnTypeRequirement &FromTypeRequirement =
1144
1145 if (FromTypeRequirement.isTypeConstraint()) {
1146 const bool IsDependent = FromTypeRequirement.isDependent();
1147 auto ParamsOrErr =
1148 import(FromTypeRequirement.getTypeConstraintTemplateParameterList());
1149 if (!ParamsOrErr)
1150 return ParamsOrErr.takeError();
1151 if (Status >= ExprRequirement::SS_ConstraintsNotSatisfied) {
1152 auto SubstConstraintExprOrErr =
1154 if (!SubstConstraintExprOrErr)
1155 return SubstConstraintExprOrErr.takeError();
1156 SubstitutedConstraintExpr = SubstConstraintExprOrErr.get();
1157 }
1158 Req.emplace(ParamsOrErr.get(), IsDependent);
1159 } else if (FromTypeRequirement.isSubstitutionFailure()) {
1160 auto DiagOrErr = import(FromTypeRequirement.getSubstitutionDiagnostic());
1161 if (!DiagOrErr)
1162 return DiagOrErr.takeError();
1163 Req.emplace(DiagOrErr.get());
1164 } else {
1165 Req.emplace();
1166 }
1167 }
1168
1169 ExpectedSLoc NoexceptLocOrErr = import(From->getNoexceptLoc());
1170 if (!NoexceptLocOrErr)
1171 return NoexceptLocOrErr.takeError();
1172
1173 if (Status == ExprRequirement::SS_ExprSubstitutionFailure) {
1174 auto DiagOrErr = import(From->getExprSubstitutionDiagnostic());
1175 if (!DiagOrErr)
1176 return DiagOrErr.takeError();
1177 return new (Importer.getToContext()) ExprRequirement(
1178 *DiagOrErr, IsRKSimple, *NoexceptLocOrErr, std::move(*Req));
1179 } else {
1180 Expected<Expr *> ExprOrErr = import(From->getExpr());
1181 if (!ExprOrErr)
1182 return ExprOrErr.takeError();
1183 return new (Importer.getToContext()) concepts::ExprRequirement(
1184 *ExprOrErr, IsRKSimple, *NoexceptLocOrErr, std::move(*Req), Status,
1185 SubstitutedConstraintExpr);
1186 }
1187}
1188
1191 using namespace concepts;
1192
1193 const ASTConstraintSatisfaction &FromSatisfaction =
1195 if (From->hasInvalidConstraint()) {
1196 StringRef ToEntity = ImportASTStringRef(From->getInvalidConstraintEntity());
1197 ASTConstraintSatisfaction *ToSatisfaction =
1198 ASTConstraintSatisfaction::Rebuild(Importer.getToContext(),
1199 FromSatisfaction);
1200 return new (Importer.getToContext())
1201 NestedRequirement(ToEntity, ToSatisfaction);
1202 } else {
1203 ExpectedExpr ToExpr = import(From->getConstraintExpr());
1204 if (!ToExpr)
1205 return ToExpr.takeError();
1206 if (ToExpr.get()->isInstantiationDependent()) {
1207 return new (Importer.getToContext()) NestedRequirement(ToExpr.get());
1208 } else {
1209 ConstraintSatisfaction Satisfaction;
1210 if (Error Err =
1211 ImportConstraintSatisfaction(FromSatisfaction, Satisfaction))
1212 return std::move(Err);
1213 return new (Importer.getToContext()) NestedRequirement(
1214 Importer.getToContext(), ToExpr.get(), Satisfaction);
1215 }
1216 }
1217}
1218
1219template <>
1221ASTNodeImporter::import(concepts::Requirement *FromRequire) {
1222 switch (FromRequire->getKind()) {
1231 }
1232 llvm_unreachable("Unhandled requirement kind");
1233}
1234
1235template <>
1236Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) {
1237 ValueDecl *Var = nullptr;
1238 if (From.capturesVariable()) {
1239 if (auto VarOrErr = import(From.getCapturedVar()))
1240 Var = *VarOrErr;
1241 else
1242 return VarOrErr.takeError();
1243 }
1244
1245 auto LocationOrErr = import(From.getLocation());
1246 if (!LocationOrErr)
1247 return LocationOrErr.takeError();
1248
1249 SourceLocation EllipsisLoc;
1250 if (From.isPackExpansion())
1251 if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc()))
1252 return std::move(Err);
1253
1254 return LambdaCapture(
1255 *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var,
1256 EllipsisLoc);
1257}
1258
1259template <typename T>
1261 if (Found->getLinkageInternal() != From->getLinkageInternal())
1262 return false;
1263
1264 if (From->hasExternalFormalLinkage())
1265 return Found->hasExternalFormalLinkage();
1266 if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl())
1267 return false;
1268 if (From->isInAnonymousNamespace())
1269 return Found->isInAnonymousNamespace();
1270 else
1271 return !Found->isInAnonymousNamespace() &&
1272 !Found->hasExternalFormalLinkage();
1273}
1274
1275template <>
1277 TypedefNameDecl *From) {
1278 if (Found->getLinkageInternal() != From->getLinkageInternal())
1279 return false;
1280
1281 if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace())
1282 return Importer.GetFromTU(Found) == From->getTranslationUnitDecl();
1283 return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace();
1284}
1285
1286} // namespace clang
1287
1288//----------------------------------------------------------------------------
1289// Import Types
1290//----------------------------------------------------------------------------
1291
1292using namespace clang;
1293
1295 const FunctionDecl *D) {
1296 const FunctionDecl *LambdaD = nullptr;
1297 if (!isCycle(D) && D) {
1298 FunctionDeclsWithImportInProgress.insert(D);
1299 LambdaD = D;
1300 }
1301 return llvm::scope_exit([this, LambdaD]() {
1302 if (LambdaD) {
1303 FunctionDeclsWithImportInProgress.erase(LambdaD);
1304 }
1305 });
1306}
1307
1309 const FunctionDecl *D) const {
1310 return FunctionDeclsWithImportInProgress.find(D) !=
1311 FunctionDeclsWithImportInProgress.end();
1312}
1313
1315 Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
1316 << T->getTypeClassName();
1317 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1318}
1319
1320ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
1321 ExpectedType UnderlyingTypeOrErr = import(T->getValueType());
1322 if (!UnderlyingTypeOrErr)
1323 return UnderlyingTypeOrErr.takeError();
1324
1325 return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr);
1326}
1327
1328ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
1329 switch (T->getKind()) {
1330#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1331 case BuiltinType::Id: \
1332 return Importer.getToContext().SingletonId;
1333#include "clang/Basic/OpenCLImageTypes.def"
1334#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1335 case BuiltinType::Id: \
1336 return Importer.getToContext().Id##Ty;
1337#include "clang/Basic/OpenCLExtensionTypes.def"
1338#define SVE_TYPE(Name, Id, SingletonId) \
1339 case BuiltinType::Id: \
1340 return Importer.getToContext().SingletonId;
1341#include "clang/Basic/AArch64ACLETypes.def"
1342#define PPC_VECTOR_TYPE(Name, Id, Size) \
1343 case BuiltinType::Id: \
1344 return Importer.getToContext().Id##Ty;
1345#include "clang/Basic/PPCTypes.def"
1346#define RVV_TYPE(Name, Id, SingletonId) \
1347 case BuiltinType::Id: \
1348 return Importer.getToContext().SingletonId;
1349#include "clang/Basic/RISCVVTypes.def"
1350#define WASM_TYPE(Name, Id, SingletonId) \
1351 case BuiltinType::Id: \
1352 return Importer.getToContext().SingletonId;
1353#include "clang/Basic/WebAssemblyReferenceTypes.def"
1354#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
1355 case BuiltinType::Id: \
1356 return Importer.getToContext().SingletonId;
1357#include "clang/Basic/AMDGPUTypes.def"
1358#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
1359 case BuiltinType::Id: \
1360 return Importer.getToContext().SingletonId;
1361#include "clang/Basic/HLSLIntangibleTypes.def"
1362#define SHARED_SINGLETON_TYPE(Expansion)
1363#define BUILTIN_TYPE(Id, SingletonId) \
1364 case BuiltinType::Id: return Importer.getToContext().SingletonId;
1365#include "clang/AST/BuiltinTypes.def"
1366
1367 // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
1368 // context supports C++.
1369
1370 // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
1371 // context supports ObjC.
1372
1373 case BuiltinType::Char_U:
1374 // The context we're importing from has an unsigned 'char'. If we're
1375 // importing into a context with a signed 'char', translate to
1376 // 'unsigned char' instead.
1377 if (Importer.getToContext().getLangOpts().CharIsSigned)
1378 return Importer.getToContext().UnsignedCharTy;
1379
1380 return Importer.getToContext().CharTy;
1381
1382 case BuiltinType::Char_S:
1383 // The context we're importing from has an unsigned 'char'. If we're
1384 // importing into a context with a signed 'char', translate to
1385 // 'unsigned char' instead.
1386 if (!Importer.getToContext().getLangOpts().CharIsSigned)
1387 return Importer.getToContext().SignedCharTy;
1388
1389 return Importer.getToContext().CharTy;
1390
1391 case BuiltinType::WChar_S:
1392 case BuiltinType::WChar_U:
1393 // FIXME: If not in C++, shall we translate to the C equivalent of
1394 // wchar_t?
1395 return Importer.getToContext().WCharTy;
1396 }
1397
1398 llvm_unreachable("Invalid BuiltinType Kind!");
1399}
1400
1401ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) {
1402 ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType());
1403 if (!ToOriginalTypeOrErr)
1404 return ToOriginalTypeOrErr.takeError();
1405
1406 return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr);
1407}
1408
1409ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) {
1410 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1411 if (!ToElementTypeOrErr)
1412 return ToElementTypeOrErr.takeError();
1413
1414 return Importer.getToContext().getComplexType(*ToElementTypeOrErr);
1415}
1416
1417ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) {
1418 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1419 if (!ToPointeeTypeOrErr)
1420 return ToPointeeTypeOrErr.takeError();
1421
1422 return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr);
1423}
1424
1425ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) {
1426 // FIXME: Check for blocks support in "to" context.
1427 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1428 if (!ToPointeeTypeOrErr)
1429 return ToPointeeTypeOrErr.takeError();
1430
1431 return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr);
1432}
1433
1435ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) {
1436 // FIXME: Check for C++ support in "to" context.
1437 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1438 if (!ToPointeeTypeOrErr)
1439 return ToPointeeTypeOrErr.takeError();
1440
1441 return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr);
1442}
1443
1445ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) {
1446 // FIXME: Check for C++0x support in "to" context.
1447 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1448 if (!ToPointeeTypeOrErr)
1449 return ToPointeeTypeOrErr.takeError();
1450
1451 return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr);
1452}
1453
1455ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) {
1456 // FIXME: Check for C++ support in "to" context.
1457 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1458 if (!ToPointeeTypeOrErr)
1459 return ToPointeeTypeOrErr.takeError();
1460
1461 auto QualifierOrErr = import(T->getQualifier());
1462 if (!QualifierOrErr)
1463 return QualifierOrErr.takeError();
1464
1465 auto ClsOrErr = import(T->getMostRecentCXXRecordDecl());
1466 if (!ClsOrErr)
1467 return ClsOrErr.takeError();
1468
1469 return Importer.getToContext().getMemberPointerType(
1470 *ToPointeeTypeOrErr, *QualifierOrErr, *ClsOrErr);
1471}
1472
1474ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) {
1475 Error Err = Error::success();
1476 auto ToElementType = importChecked(Err, T->getElementType());
1477 auto ToSizeExpr = importChecked(Err, T->getSizeExpr());
1478 if (Err)
1479 return std::move(Err);
1480
1481 return Importer.getToContext().getConstantArrayType(
1482 ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(),
1484}
1485
1487ASTNodeImporter::VisitArrayParameterType(const ArrayParameterType *T) {
1488 ExpectedType ToArrayTypeOrErr = VisitConstantArrayType(T);
1489 if (!ToArrayTypeOrErr)
1490 return ToArrayTypeOrErr.takeError();
1491
1492 return Importer.getToContext().getArrayParameterType(*ToArrayTypeOrErr);
1493}
1494
1496ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
1497 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1498 if (!ToElementTypeOrErr)
1499 return ToElementTypeOrErr.takeError();
1500
1501 return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr,
1502 T->getSizeModifier(),
1504}
1505
1507ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
1508 Error Err = Error::success();
1509 QualType ToElementType = importChecked(Err, T->getElementType());
1510 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1511 if (Err)
1512 return std::move(Err);
1513 return Importer.getToContext().getVariableArrayType(
1514 ToElementType, ToSizeExpr, T->getSizeModifier(),
1516}
1517
1518ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
1519 const DependentSizedArrayType *T) {
1520 Error Err = Error::success();
1521 QualType ToElementType = importChecked(Err, T->getElementType());
1522 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1523 if (Err)
1524 return std::move(Err);
1525 // SizeExpr may be null if size is not specified directly.
1526 // For example, 'int a[]'.
1527
1528 return Importer.getToContext().getDependentSizedArrayType(
1529 ToElementType, ToSizeExpr, T->getSizeModifier(),
1531}
1532
1533ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(
1534 const DependentSizedExtVectorType *T) {
1535 Error Err = Error::success();
1536 QualType ToElementType = importChecked(Err, T->getElementType());
1537 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1538 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1539 if (Err)
1540 return std::move(Err);
1541 return Importer.getToContext().getDependentSizedExtVectorType(
1542 ToElementType, ToSizeExpr, ToAttrLoc);
1543}
1544
1545ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) {
1546 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1547 if (!ToElementTypeOrErr)
1548 return ToElementTypeOrErr.takeError();
1549
1550 return Importer.getToContext().getVectorType(*ToElementTypeOrErr,
1551 T->getNumElements(),
1552 T->getVectorKind());
1553}
1554
1555ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) {
1556 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1557 if (!ToElementTypeOrErr)
1558 return ToElementTypeOrErr.takeError();
1559
1560 return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr,
1561 T->getNumElements());
1562}
1563
1565ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1566 // FIXME: What happens if we're importing a function without a prototype
1567 // into C++? Should we make it variadic?
1568 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1569 if (!ToReturnTypeOrErr)
1570 return ToReturnTypeOrErr.takeError();
1571
1572 return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr,
1573 T->getExtInfo());
1574}
1575
1577ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
1578 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1579 if (!ToReturnTypeOrErr)
1580 return ToReturnTypeOrErr.takeError();
1581
1582 // Import argument types
1583 SmallVector<QualType, 4> ArgTypes;
1584 for (const auto &A : T->param_types()) {
1585 ExpectedType TyOrErr = import(A);
1586 if (!TyOrErr)
1587 return TyOrErr.takeError();
1588 ArgTypes.push_back(*TyOrErr);
1589 }
1590
1591 // Import exception types
1592 SmallVector<QualType, 4> ExceptionTypes;
1593 for (const auto &E : T->exceptions()) {
1594 ExpectedType TyOrErr = import(E);
1595 if (!TyOrErr)
1596 return TyOrErr.takeError();
1597 ExceptionTypes.push_back(*TyOrErr);
1598 }
1599
1600 FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo();
1601 Error Err = Error::success();
1602 FunctionProtoType::ExtProtoInfo ToEPI;
1603 ToEPI.ExtInfo = FromEPI.ExtInfo;
1604 ToEPI.Variadic = FromEPI.Variadic;
1605 ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
1606 ToEPI.TypeQuals = FromEPI.TypeQuals;
1607 ToEPI.RefQualifier = FromEPI.RefQualifier;
1608 ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
1610 importChecked(Err, FromEPI.ExceptionSpec.NoexceptExpr);
1612 importChecked(Err, FromEPI.ExceptionSpec.SourceDecl);
1614 importChecked(Err, FromEPI.ExceptionSpec.SourceTemplate);
1615 ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
1616
1617 if (Err)
1618 return std::move(Err);
1619
1620 return Importer.getToContext().getFunctionType(
1621 *ToReturnTypeOrErr, ArgTypes, ToEPI);
1622}
1623
1624ExpectedType ASTNodeImporter::VisitUnresolvedUsingType(
1625 const UnresolvedUsingType *T) {
1626 Error Err = Error::success();
1627 auto ToQualifier = importChecked(Err, T->getQualifier());
1628 auto *ToD = importChecked(Err, T->getDecl());
1629 if (Err)
1630 return std::move(Err);
1631
1632 if (T->isCanonicalUnqualified())
1633 return Importer.getToContext().getCanonicalUnresolvedUsingType(ToD);
1634 return Importer.getToContext().getUnresolvedUsingType(T->getKeyword(),
1635 ToQualifier, ToD);
1636}
1637
1638ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) {
1639 ExpectedType ToInnerTypeOrErr = import(T->getInnerType());
1640 if (!ToInnerTypeOrErr)
1641 return ToInnerTypeOrErr.takeError();
1642
1643 return Importer.getToContext().getParenType(*ToInnerTypeOrErr);
1644}
1645
1647ASTNodeImporter::VisitPackIndexingType(clang::PackIndexingType const *T) {
1648
1649 ExpectedType Pattern = import(T->getPattern());
1650 if (!Pattern)
1651 return Pattern.takeError();
1652 ExpectedExpr Index = import(T->getIndexExpr());
1653 if (!Index)
1654 return Index.takeError();
1655 return Importer.getToContext().getPackIndexingType(*Pattern, *Index);
1656}
1657
1658ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) {
1659 Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl());
1660 if (!ToDeclOrErr)
1661 return ToDeclOrErr.takeError();
1662
1663 auto ToQualifierOrErr = import(T->getQualifier());
1664 if (!ToQualifierOrErr)
1665 return ToQualifierOrErr.takeError();
1666
1667 ExpectedType ToUnderlyingTypeOrErr =
1668 T->typeMatchesDecl() ? QualType() : import(T->desugar());
1669 if (!ToUnderlyingTypeOrErr)
1670 return ToUnderlyingTypeOrErr.takeError();
1671
1672 return Importer.getToContext().getTypedefType(
1673 T->getKeyword(), *ToQualifierOrErr, *ToDeclOrErr, *ToUnderlyingTypeOrErr);
1674}
1675
1676ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {
1677 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1678 if (!ToExprOrErr)
1679 return ToExprOrErr.takeError();
1680 return Importer.getToContext().getTypeOfExprType(*ToExprOrErr, T->getKind());
1681}
1682
1683ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
1684 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnmodifiedType());
1685 if (!ToUnderlyingTypeOrErr)
1686 return ToUnderlyingTypeOrErr.takeError();
1687 return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr,
1688 T->getKind());
1689}
1690
1691ExpectedType ASTNodeImporter::VisitUsingType(const UsingType *T) {
1692 Error Err = Error::success();
1693 auto ToQualifier = importChecked(Err, T->getQualifier());
1694 auto *ToD = importChecked(Err, T->getDecl());
1695 QualType ToT = importChecked(Err, T->desugar());
1696 if (Err)
1697 return std::move(Err);
1698 return Importer.getToContext().getUsingType(T->getKeyword(), ToQualifier, ToD,
1699 ToT);
1700}
1701
1702ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) {
1703 // FIXME: Make sure that the "to" context supports C++0x!
1704 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1705 if (!ToExprOrErr)
1706 return ToExprOrErr.takeError();
1707
1708 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1709 if (!ToUnderlyingTypeOrErr)
1710 return ToUnderlyingTypeOrErr.takeError();
1711
1712 return Importer.getToContext().getDecltypeType(
1713 *ToExprOrErr, *ToUnderlyingTypeOrErr);
1714}
1715
1717ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) {
1718 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1719 if (!ToBaseTypeOrErr)
1720 return ToBaseTypeOrErr.takeError();
1721
1722 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1723 if (!ToUnderlyingTypeOrErr)
1724 return ToUnderlyingTypeOrErr.takeError();
1725
1726 return Importer.getToContext().getUnaryTransformType(
1727 *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind());
1728}
1729
1730ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) {
1731 // FIXME: Make sure that the "to" context supports C++11!
1732 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1733 if (!ToDeducedTypeOrErr)
1734 return ToDeducedTypeOrErr.takeError();
1735
1736 ExpectedDecl ToTypeConstraintConcept = import(T->getTypeConstraintConcept());
1737 if (!ToTypeConstraintConcept)
1738 return ToTypeConstraintConcept.takeError();
1739
1740 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1741 if (Error Err = ImportTemplateArguments(T->getTypeConstraintArguments(),
1742 ToTemplateArgs))
1743 return std::move(Err);
1744
1745 return Importer.getToContext().getAutoType(
1746 *ToDeducedTypeOrErr, T->getKeyword(), /*IsDependent*/false,
1747 /*IsPack=*/false, cast_or_null<ConceptDecl>(*ToTypeConstraintConcept),
1748 ToTemplateArgs);
1749}
1750
1751ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType(
1752 const DeducedTemplateSpecializationType *T) {
1753 // FIXME: Make sure that the "to" context supports C++17!
1754 Expected<TemplateName> ToTemplateNameOrErr = import(T->getTemplateName());
1755 if (!ToTemplateNameOrErr)
1756 return ToTemplateNameOrErr.takeError();
1757 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1758 if (!ToDeducedTypeOrErr)
1759 return ToDeducedTypeOrErr.takeError();
1760
1761 return Importer.getToContext().getDeducedTemplateSpecializationType(
1762 T->getKeyword(), *ToTemplateNameOrErr, *ToDeducedTypeOrErr,
1763 T->isDependentType());
1764}
1765
1766ExpectedType ASTNodeImporter::VisitTagType(const TagType *T) {
1767 TagDecl *DeclForType = T->getDecl();
1768 Expected<TagDecl *> ToDeclOrErr = import(DeclForType);
1769 if (!ToDeclOrErr)
1770 return ToDeclOrErr.takeError();
1771
1772 // If there is a definition of the 'OriginalDecl', it should be imported to
1773 // have all information for the type in the "To" AST. (In some cases no
1774 // other reference may exist to the definition decl and it would not be
1775 // imported otherwise.)
1776 Expected<TagDecl *> ToDefDeclOrErr = import(DeclForType->getDefinition());
1777 if (!ToDefDeclOrErr)
1778 return ToDefDeclOrErr.takeError();
1779
1780 if (T->isCanonicalUnqualified())
1781 return Importer.getToContext().getCanonicalTagType(*ToDeclOrErr);
1782
1783 auto ToQualifierOrErr = import(T->getQualifier());
1784 if (!ToQualifierOrErr)
1785 return ToQualifierOrErr.takeError();
1786
1787 return Importer.getToContext().getTagType(T->getKeyword(), *ToQualifierOrErr,
1788 *ToDeclOrErr, T->isTagOwned());
1789}
1790
1791ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) {
1792 return VisitTagType(T);
1793}
1794
1795ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) {
1796 return VisitTagType(T);
1797}
1798
1800ASTNodeImporter::VisitInjectedClassNameType(const InjectedClassNameType *T) {
1801 return VisitTagType(T);
1802}
1803
1804ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) {
1805 ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType());
1806 if (!ToModifiedTypeOrErr)
1807 return ToModifiedTypeOrErr.takeError();
1808 ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType());
1809 if (!ToEquivalentTypeOrErr)
1810 return ToEquivalentTypeOrErr.takeError();
1811
1812 return Importer.getToContext().getAttributedType(
1813 T->getAttrKind(), *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr,
1814 T->getAttr());
1815}
1816
1818ASTNodeImporter::VisitCountAttributedType(const CountAttributedType *T) {
1819 ExpectedType ToWrappedTypeOrErr = import(T->desugar());
1820 if (!ToWrappedTypeOrErr)
1821 return ToWrappedTypeOrErr.takeError();
1822
1823 Error Err = Error::success();
1824 Expr *CountExpr = importChecked(Err, T->getCountExpr());
1825
1826 SmallVector<TypeCoupledDeclRefInfo, 1> CoupledDecls;
1827 for (const TypeCoupledDeclRefInfo &TI : T->dependent_decls()) {
1828 Expected<ValueDecl *> ToDeclOrErr = import(TI.getDecl());
1829 if (!ToDeclOrErr)
1830 return ToDeclOrErr.takeError();
1831 CoupledDecls.emplace_back(*ToDeclOrErr, TI.isDeref());
1832 }
1833
1834 return Importer.getToContext().getCountAttributedType(
1835 *ToWrappedTypeOrErr, CountExpr, T->isCountInBytes(), T->isOrNull(),
1836 ArrayRef(CoupledDecls));
1837}
1838
1839ExpectedType ASTNodeImporter::VisitTemplateTypeParmType(
1840 const TemplateTypeParmType *T) {
1841 Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl());
1842 if (!ToDeclOrErr)
1843 return ToDeclOrErr.takeError();
1844
1845 return Importer.getToContext().getTemplateTypeParmType(
1846 T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr);
1847}
1848
1849ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType(
1850 const SubstTemplateTypeParmType *T) {
1851 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1852 if (!ReplacedOrErr)
1853 return ReplacedOrErr.takeError();
1854
1855 ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType());
1856 if (!ToReplacementTypeOrErr)
1857 return ToReplacementTypeOrErr.takeError();
1858
1859 return Importer.getToContext().getSubstTemplateTypeParmType(
1860 *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex(), T->getPackIndex(),
1861 T->getFinal());
1862}
1863
1864ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
1865 const SubstTemplateTypeParmPackType *T) {
1866 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1867 if (!ReplacedOrErr)
1868 return ReplacedOrErr.takeError();
1869
1870 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1871 if (!ToArgumentPack)
1872 return ToArgumentPack.takeError();
1873
1874 return Importer.getToContext().getSubstTemplateTypeParmPackType(
1875 *ReplacedOrErr, T->getIndex(), T->getFinal(), *ToArgumentPack);
1876}
1877
1878ExpectedType ASTNodeImporter::VisitSubstBuiltinTemplatePackType(
1879 const SubstBuiltinTemplatePackType *T) {
1880 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1881 if (!ToArgumentPack)
1882 return ToArgumentPack.takeError();
1883 return Importer.getToContext().getSubstBuiltinTemplatePack(*ToArgumentPack);
1884}
1885
1886ExpectedType ASTNodeImporter::VisitTemplateSpecializationType(
1887 const TemplateSpecializationType *T) {
1888 auto ToTemplateOrErr = import(T->getTemplateName());
1889 if (!ToTemplateOrErr)
1890 return ToTemplateOrErr.takeError();
1891
1892 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1893 if (Error Err =
1894 ImportTemplateArguments(T->template_arguments(), ToTemplateArgs))
1895 return std::move(Err);
1896
1897 ExpectedType ToUnderlyingOrErr =
1898 T->isCanonicalUnqualified() ? QualType() : import(T->desugar());
1899 if (!ToUnderlyingOrErr)
1900 return ToUnderlyingOrErr.takeError();
1901 return Importer.getToContext().getTemplateSpecializationType(
1902 T->getKeyword(), *ToTemplateOrErr, ToTemplateArgs, {},
1903 *ToUnderlyingOrErr);
1904}
1905
1907ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) {
1908 ExpectedType ToPatternOrErr = import(T->getPattern());
1909 if (!ToPatternOrErr)
1910 return ToPatternOrErr.takeError();
1911
1912 return Importer.getToContext().getPackExpansionType(*ToPatternOrErr,
1913 T->getNumExpansions(),
1914 /*ExpactPack=*/false);
1915}
1916
1918ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) {
1919 auto ToQualifierOrErr = import(T->getQualifier());
1920 if (!ToQualifierOrErr)
1921 return ToQualifierOrErr.takeError();
1922
1923 IdentifierInfo *Name = Importer.Import(T->getIdentifier());
1924 return Importer.getToContext().getDependentNameType(T->getKeyword(),
1925 *ToQualifierOrErr, Name);
1926}
1927
1929ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1930 Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl());
1931 if (!ToDeclOrErr)
1932 return ToDeclOrErr.takeError();
1933
1934 return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr);
1935}
1936
1937ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) {
1938 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1939 if (!ToBaseTypeOrErr)
1940 return ToBaseTypeOrErr.takeError();
1941
1942 SmallVector<QualType, 4> TypeArgs;
1943 for (auto TypeArg : T->getTypeArgsAsWritten()) {
1944 if (ExpectedType TyOrErr = import(TypeArg))
1945 TypeArgs.push_back(*TyOrErr);
1946 else
1947 return TyOrErr.takeError();
1948 }
1949
1950 SmallVector<ObjCProtocolDecl *, 4> Protocols;
1951 for (auto *P : T->quals()) {
1952 if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P))
1953 Protocols.push_back(*ProtocolOrErr);
1954 else
1955 return ProtocolOrErr.takeError();
1956
1957 }
1958
1959 return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs,
1960 Protocols,
1961 T->isKindOfTypeAsWritten());
1962}
1963
1965ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1966 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1967 if (!ToPointeeTypeOrErr)
1968 return ToPointeeTypeOrErr.takeError();
1969
1970 return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
1971}
1972
1974ASTNodeImporter::VisitMacroQualifiedType(const MacroQualifiedType *T) {
1975 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1976 if (!ToUnderlyingTypeOrErr)
1977 return ToUnderlyingTypeOrErr.takeError();
1978
1979 IdentifierInfo *ToIdentifier = Importer.Import(T->getMacroIdentifier());
1980 return Importer.getToContext().getMacroQualifiedType(*ToUnderlyingTypeOrErr,
1981 ToIdentifier);
1982}
1983
1984ExpectedType clang::ASTNodeImporter::VisitAdjustedType(const AdjustedType *T) {
1985 Error Err = Error::success();
1986 QualType ToOriginalType = importChecked(Err, T->getOriginalType());
1987 QualType ToAdjustedType = importChecked(Err, T->getAdjustedType());
1988 if (Err)
1989 return std::move(Err);
1990
1991 return Importer.getToContext().getAdjustedType(ToOriginalType,
1992 ToAdjustedType);
1993}
1994
1995ExpectedType clang::ASTNodeImporter::VisitBitIntType(const BitIntType *T) {
1996 return Importer.getToContext().getBitIntType(T->isUnsigned(),
1997 T->getNumBits());
1998}
1999
2000ExpectedType clang::ASTNodeImporter::VisitBTFTagAttributedType(
2001 const clang::BTFTagAttributedType *T) {
2002 Error Err = Error::success();
2003 const BTFTypeTagAttr *ToBTFAttr = importChecked(Err, T->getAttr());
2004 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
2005 if (Err)
2006 return std::move(Err);
2007
2008 return Importer.getToContext().getBTFTagAttributedType(ToBTFAttr,
2009 ToWrappedType);
2010}
2011
2012ExpectedType clang::ASTNodeImporter::VisitOverflowBehaviorType(
2013 const clang::OverflowBehaviorType *T) {
2014 Error Err = Error::success();
2015 OverflowBehaviorType::OverflowBehaviorKind ToKind = T->getBehaviorKind();
2016 QualType ToUnderlyingType = importChecked(Err, T->getUnderlyingType());
2017 if (Err)
2018 return std::move(Err);
2019
2020 return Importer.getToContext().getOverflowBehaviorType(ToKind,
2022}
2023
2024ExpectedType clang::ASTNodeImporter::VisitHLSLAttributedResourceType(
2025 const clang::HLSLAttributedResourceType *T) {
2026 Error Err = Error::success();
2027 const HLSLAttributedResourceType::Attributes &ToAttrs = T->getAttrs();
2028 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
2029 QualType ToContainedType = importChecked(Err, T->getContainedType());
2030 if (Err)
2031 return std::move(Err);
2032
2033 return Importer.getToContext().getHLSLAttributedResourceType(
2034 ToWrappedType, ToContainedType, ToAttrs);
2035}
2036
2037ExpectedType clang::ASTNodeImporter::VisitHLSLInlineSpirvType(
2038 const clang::HLSLInlineSpirvType *T) {
2039 Error Err = Error::success();
2040
2041 uint32_t ToOpcode = T->getOpcode();
2042 uint32_t ToSize = T->getSize();
2043 uint32_t ToAlignment = T->getAlignment();
2044
2045 llvm::SmallVector<SpirvOperand> ToOperands;
2046
2047 for (auto &Operand : T->getOperands()) {
2048 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
2049
2050 switch (Operand.getKind()) {
2051 case SpirvOperandKind::ConstantId:
2052 ToOperands.push_back(SpirvOperand::createConstant(
2053 importChecked(Err, Operand.getResultType()), Operand.getValue()));
2054 break;
2055 case SpirvOperandKind::Literal:
2056 ToOperands.push_back(SpirvOperand::createLiteral(Operand.getValue()));
2057 break;
2058 case SpirvOperandKind::TypeId:
2059 ToOperands.push_back(SpirvOperand::createType(
2060 importChecked(Err, Operand.getResultType())));
2061 break;
2062 default:
2063 llvm_unreachable("Invalid SpirvOperand kind");
2064 }
2065
2066 if (Err)
2067 return std::move(Err);
2068 }
2069
2070 return Importer.getToContext().getHLSLInlineSpirvType(
2071 ToOpcode, ToSize, ToAlignment, ToOperands);
2072}
2073
2074ExpectedType clang::ASTNodeImporter::VisitConstantMatrixType(
2075 const clang::ConstantMatrixType *T) {
2076 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2077 if (!ToElementTypeOrErr)
2078 return ToElementTypeOrErr.takeError();
2079
2080 return Importer.getToContext().getConstantMatrixType(
2081 *ToElementTypeOrErr, T->getNumRows(), T->getNumColumns());
2082}
2083
2084ExpectedType clang::ASTNodeImporter::VisitDependentAddressSpaceType(
2085 const clang::DependentAddressSpaceType *T) {
2086 Error Err = Error::success();
2087 QualType ToPointeeType = importChecked(Err, T->getPointeeType());
2088 Expr *ToAddrSpaceExpr = importChecked(Err, T->getAddrSpaceExpr());
2089 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2090 if (Err)
2091 return std::move(Err);
2092
2093 return Importer.getToContext().getDependentAddressSpaceType(
2094 ToPointeeType, ToAddrSpaceExpr, ToAttrLoc);
2095}
2096
2097ExpectedType clang::ASTNodeImporter::VisitDependentBitIntType(
2098 const clang::DependentBitIntType *T) {
2099 ExpectedExpr ToNumBitsExprOrErr = import(T->getNumBitsExpr());
2100 if (!ToNumBitsExprOrErr)
2101 return ToNumBitsExprOrErr.takeError();
2102 return Importer.getToContext().getDependentBitIntType(T->isUnsigned(),
2103 *ToNumBitsExprOrErr);
2104}
2105
2106ExpectedType clang::ASTNodeImporter::VisitPredefinedSugarType(
2107 const clang::PredefinedSugarType *T) {
2108 return Importer.getToContext().getPredefinedSugarType(T->getKind());
2109}
2110
2111ExpectedType clang::ASTNodeImporter::VisitDependentSizedMatrixType(
2112 const clang::DependentSizedMatrixType *T) {
2113 Error Err = Error::success();
2114 QualType ToElementType = importChecked(Err, T->getElementType());
2115 Expr *ToRowExpr = importChecked(Err, T->getRowExpr());
2116 Expr *ToColumnExpr = importChecked(Err, T->getColumnExpr());
2117 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2118 if (Err)
2119 return std::move(Err);
2120
2121 return Importer.getToContext().getDependentSizedMatrixType(
2122 ToElementType, ToRowExpr, ToColumnExpr, ToAttrLoc);
2123}
2124
2125ExpectedType clang::ASTNodeImporter::VisitDependentVectorType(
2126 const clang::DependentVectorType *T) {
2127 Error Err = Error::success();
2128 QualType ToElementType = importChecked(Err, T->getElementType());
2129 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
2130 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2131 if (Err)
2132 return std::move(Err);
2133
2134 return Importer.getToContext().getDependentVectorType(
2135 ToElementType, ToSizeExpr, ToAttrLoc, T->getVectorKind());
2136}
2137
2138ExpectedType clang::ASTNodeImporter::VisitObjCTypeParamType(
2139 const clang::ObjCTypeParamType *T) {
2140 Expected<ObjCTypeParamDecl *> ToDeclOrErr = import(T->getDecl());
2141 if (!ToDeclOrErr)
2142 return ToDeclOrErr.takeError();
2143
2144 SmallVector<ObjCProtocolDecl *, 4> ToProtocols;
2145 for (ObjCProtocolDecl *FromProtocol : T->getProtocols()) {
2146 Expected<ObjCProtocolDecl *> ToProtocolOrErr = import(FromProtocol);
2147 if (!ToProtocolOrErr)
2148 return ToProtocolOrErr.takeError();
2149 ToProtocols.push_back(*ToProtocolOrErr);
2150 }
2151
2152 return Importer.getToContext().getObjCTypeParamType(*ToDeclOrErr,
2153 ToProtocols);
2154}
2155
2156ExpectedType clang::ASTNodeImporter::VisitPipeType(const clang::PipeType *T) {
2157 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2158 if (!ToElementTypeOrErr)
2159 return ToElementTypeOrErr.takeError();
2160
2161 ASTContext &ToCtx = Importer.getToContext();
2162 if (T->isReadOnly())
2163 return ToCtx.getReadPipeType(*ToElementTypeOrErr);
2164 else
2165 return ToCtx.getWritePipeType(*ToElementTypeOrErr);
2166}
2167
2168//----------------------------------------------------------------------------
2169// Import Declarations
2170//----------------------------------------------------------------------------
2172 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
2173 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) {
2174 // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop.
2175 // example: int struct_in_proto(struct data_t{int a;int b;} *d);
2176 // FIXME: We could support these constructs by importing a different type of
2177 // this parameter and by importing the original type of the parameter only
2178 // after the FunctionDecl is created. See
2179 // VisitFunctionDecl::UsedDifferentProtoType.
2180 DeclContext *OrigDC = D->getDeclContext();
2181 FunctionDecl *FunDecl;
2182 if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) &&
2183 FunDecl->hasBody()) {
2184 auto getLeafPointeeType = [](const Type *T) {
2185 while (T->isPointerType() || T->isArrayType()) {
2186 T = T->getPointeeOrArrayElementType();
2187 }
2188 return T;
2189 };
2190 for (const ParmVarDecl *P : FunDecl->parameters()) {
2191 const Type *LeafT =
2192 getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
2193 auto *RT = dyn_cast<RecordType>(LeafT);
2194 if (RT && RT->getDecl() == D) {
2195 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2196 << D->getDeclKindName();
2197 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2198 }
2199 }
2200 }
2201
2202 // Import the context of this declaration.
2203 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2204 return Err;
2205
2206 // Import the name of this declaration.
2207 if (Error Err = importInto(Name, D->getDeclName()))
2208 return Err;
2209
2210 // Import the location of this declaration.
2211 if (Error Err = importInto(Loc, D->getLocation()))
2212 return Err;
2213
2214 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2215 if (ToD)
2216 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
2217 return Err;
2218
2219 return Error::success();
2220}
2221
2223 NamedDecl *&ToD, SourceLocation &Loc) {
2224
2225 // Import the name of this declaration.
2226 if (Error Err = importInto(Name, D->getDeclName()))
2227 return Err;
2228
2229 // Import the location of this declaration.
2230 if (Error Err = importInto(Loc, D->getLocation()))
2231 return Err;
2232
2233 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2234 if (ToD)
2235 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
2236 return Err;
2237
2238 return Error::success();
2239}
2240
2242 if (!FromD)
2243 return Error::success();
2244
2245 if (!ToD)
2246 if (Error Err = importInto(ToD, FromD))
2247 return Err;
2248
2249 if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
2250 if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) {
2251 if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() &&
2252 !ToRecord->getDefinition()) {
2253 if (Error Err = ImportDefinition(FromRecord, ToRecord))
2254 return Err;
2255 }
2256 }
2257 return Error::success();
2258 }
2259
2260 if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
2261 if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) {
2262 if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
2263 if (Error Err = ImportDefinition(FromEnum, ToEnum))
2264 return Err;
2265 }
2266 }
2267 return Error::success();
2268 }
2269
2270 return Error::success();
2271}
2272
2273Error
2275 const DeclarationNameInfo &From, DeclarationNameInfo& To) {
2276 // NOTE: To.Name and To.Loc are already imported.
2277 // We only have to import To.LocInfo.
2278 switch (To.getName().getNameKind()) {
2285 return Error::success();
2286
2288 if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange()))
2289 To.setCXXOperatorNameRange(*ToRangeOrErr);
2290 else
2291 return ToRangeOrErr.takeError();
2292 return Error::success();
2293 }
2295 if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc()))
2296 To.setCXXLiteralOperatorNameLoc(*LocOrErr);
2297 else
2298 return LocOrErr.takeError();
2299 return Error::success();
2300 }
2304 if (auto ToTInfoOrErr = import(From.getNamedTypeInfo()))
2305 To.setNamedTypeInfo(*ToTInfoOrErr);
2306 else
2307 return ToTInfoOrErr.takeError();
2308 return Error::success();
2309 }
2310 }
2311 llvm_unreachable("Unknown name kind.");
2312}
2313
2314Error
2316 if (Importer.isMinimalImport() && !ForceImport) {
2317 auto ToDCOrErr = Importer.ImportContext(FromDC);
2318 return ToDCOrErr.takeError();
2319 }
2320
2321 // We use strict error handling in case of records and enums, but not
2322 // with e.g. namespaces.
2323 //
2324 // FIXME Clients of the ASTImporter should be able to choose an
2325 // appropriate error handling strategy for their needs. For instance,
2326 // they may not want to mark an entire namespace as erroneous merely
2327 // because there is an ODR error with two typedefs. As another example,
2328 // the client may allow EnumConstantDecls with same names but with
2329 // different values in two distinct translation units.
2330 ChildErrorHandlingStrategy HandleChildErrors(FromDC);
2331
2332 auto MightNeedReordering = [](const Decl *D) {
2334 };
2335
2336 // Import everything that might need reordering first.
2337 Error ChildErrors = Error::success();
2338 for (auto *From : FromDC->decls()) {
2339 if (!MightNeedReordering(From))
2340 continue;
2341
2342 ExpectedDecl ImportedOrErr = import(From);
2343
2344 // If we are in the process of ImportDefinition(...) for a RecordDecl we
2345 // want to make sure that we are also completing each FieldDecl. There
2346 // are currently cases where this does not happen and this is correctness
2347 // fix since operations such as code generation will expect this to be so.
2348 if (!ImportedOrErr) {
2349 HandleChildErrors.handleChildImportResult(ChildErrors,
2350 ImportedOrErr.takeError());
2351 continue;
2352 }
2353 FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
2354 Decl *ImportedDecl = *ImportedOrErr;
2355 FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
2356 if (FieldFrom && FieldTo) {
2357 Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
2358 HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
2359 }
2360 }
2361
2362 // We reorder declarations in RecordDecls because they may have another order
2363 // in the "to" context than they have in the "from" context. This may happen
2364 // e.g when we import a class like this:
2365 // struct declToImport {
2366 // int a = c + b;
2367 // int b = 1;
2368 // int c = 2;
2369 // };
2370 // During the import of `a` we import first the dependencies in sequence,
2371 // thus the order would be `c`, `b`, `a`. We will get the normal order by
2372 // first removing the already imported members and then adding them in the
2373 // order as they appear in the "from" context.
2374 //
2375 // Keeping field order is vital because it determines structure layout.
2376 //
2377 // Here and below, we cannot call field_begin() method and its callers on
2378 // ToDC if it has an external storage. Calling field_begin() will
2379 // automatically load all the fields by calling
2380 // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would
2381 // call ASTImporter::Import(). This is because the ExternalASTSource
2382 // interface in LLDB is implemented by the means of the ASTImporter. However,
2383 // calling an import at this point would result in an uncontrolled import, we
2384 // must avoid that.
2385
2386 auto ToDCOrErr = Importer.ImportContext(FromDC);
2387 if (!ToDCOrErr) {
2388 consumeError(std::move(ChildErrors));
2389 return ToDCOrErr.takeError();
2390 }
2391
2392 if (const auto *FromRD = dyn_cast<RecordDecl>(FromDC)) {
2393 DeclContext *ToDC = *ToDCOrErr;
2394 // Remove all declarations, which may be in wrong order in the
2395 // lexical DeclContext and then add them in the proper order.
2396 for (auto *D : FromRD->decls()) {
2397 if (!MightNeedReordering(D))
2398 continue;
2399
2400 assert(D && "DC contains a null decl");
2401 if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
2402 // Remove only the decls which we successfully imported.
2403 assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
2404 // Remove the decl from its wrong place in the linked list.
2405 ToDC->removeDecl(ToD);
2406 // Add the decl to the end of the linked list.
2407 // This time it will be at the proper place because the enclosing for
2408 // loop iterates in the original (good) order of the decls.
2409 ToDC->addDeclInternal(ToD);
2410 }
2411 }
2412 }
2413
2414 // Import everything else.
2415 for (auto *From : FromDC->decls()) {
2416 if (MightNeedReordering(From))
2417 continue;
2418
2419 ExpectedDecl ImportedOrErr = import(From);
2420 if (!ImportedOrErr)
2421 HandleChildErrors.handleChildImportResult(ChildErrors,
2422 ImportedOrErr.takeError());
2423 }
2424
2425 return ChildErrors;
2426}
2427
2429 const FieldDecl *To) {
2430 RecordDecl *FromRecordDecl = nullptr;
2431 RecordDecl *ToRecordDecl = nullptr;
2432 // If we have a field that is an ArrayType we need to check if the array
2433 // element is a RecordDecl and if so we need to import the definition.
2434 QualType FromType = From->getType();
2435 QualType ToType = To->getType();
2436 if (FromType->isArrayType()) {
2437 // getBaseElementTypeUnsafe(...) handles multi-dimensional arrays for us.
2438 FromRecordDecl = FromType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2439 ToRecordDecl = ToType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2440 }
2441
2442 if (!FromRecordDecl || !ToRecordDecl) {
2443 const RecordType *RecordFrom = FromType->getAs<RecordType>();
2444 const RecordType *RecordTo = ToType->getAs<RecordType>();
2445
2446 if (RecordFrom && RecordTo) {
2447 FromRecordDecl = RecordFrom->getDecl();
2448 ToRecordDecl = RecordTo->getDecl();
2449 }
2450 }
2451
2452 if (FromRecordDecl && ToRecordDecl) {
2453 if (FromRecordDecl->isCompleteDefinition() &&
2454 !ToRecordDecl->isCompleteDefinition())
2455 return ImportDefinition(FromRecordDecl, ToRecordDecl);
2456 }
2457
2458 return Error::success();
2459}
2460
2462 Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) {
2463 auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext());
2464 if (!ToDCOrErr)
2465 return ToDCOrErr.takeError();
2466 ToDC = *ToDCOrErr;
2467
2468 if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) {
2469 auto ToLexicalDCOrErr = Importer.ImportContext(
2470 FromD->getLexicalDeclContext());
2471 if (!ToLexicalDCOrErr)
2472 return ToLexicalDCOrErr.takeError();
2473 ToLexicalDC = *ToLexicalDCOrErr;
2474 } else
2475 ToLexicalDC = ToDC;
2476
2477 return Error::success();
2478}
2479
2481 const CXXRecordDecl *From, CXXRecordDecl *To) {
2482 assert(From->isCompleteDefinition() && To->getDefinition() == To &&
2483 "Import implicit methods to or from non-definition");
2484
2485 for (CXXMethodDecl *FromM : From->methods())
2486 if (FromM->isImplicit()) {
2487 Expected<CXXMethodDecl *> ToMOrErr = import(FromM);
2488 if (!ToMOrErr)
2489 return ToMOrErr.takeError();
2490 }
2491
2492 return Error::success();
2493}
2494
2496 ASTImporter &Importer) {
2497 if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
2498 if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef))
2500 else
2501 return ToTypedefOrErr.takeError();
2502 }
2503 return Error::success();
2504}
2505
2507 RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) {
2508 auto DefinitionCompleter = [To]() {
2509 // There are cases in LLDB when we first import a class without its
2510 // members. The class will have DefinitionData, but no members. Then,
2511 // importDefinition is called from LLDB, which tries to get the members, so
2512 // when we get here, the class already has the DefinitionData set, so we
2513 // must unset the CompleteDefinition here to be able to complete again the
2514 // definition.
2515 To->setCompleteDefinition(false);
2516 To->completeDefinition();
2517 };
2518
2519 if (To->getDefinition() || To->isBeingDefined()) {
2520 if (Kind == IDK_Everything ||
2521 // In case of lambdas, the class already has a definition ptr set, but
2522 // the contained decls are not imported yet. Also, isBeingDefined was
2523 // set in CXXRecordDecl::CreateLambda. We must import the contained
2524 // decls here and finish the definition.
2525 (To->isLambda() && shouldForceImportDeclContext(Kind))) {
2526 if (To->isLambda()) {
2527 auto *FromCXXRD = cast<CXXRecordDecl>(From);
2529 ToCaptures.reserve(FromCXXRD->capture_size());
2530 for (const auto &FromCapture : FromCXXRD->captures()) {
2531 if (auto ToCaptureOrErr = import(FromCapture))
2532 ToCaptures.push_back(*ToCaptureOrErr);
2533 else
2534 return ToCaptureOrErr.takeError();
2535 }
2536 cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(),
2537 ToCaptures);
2538 }
2539
2540 Error Result = ImportDeclContext(From, /*ForceImport=*/true);
2541 // Finish the definition of the lambda, set isBeingDefined to false.
2542 if (To->isLambda())
2543 DefinitionCompleter();
2544 return Result;
2545 }
2546
2547 return Error::success();
2548 }
2549
2550 To->startDefinition();
2551 // Set the definition to complete even if it is really not complete during
2552 // import. Some AST constructs (expressions) require the record layout
2553 // to be calculated (see 'clang::computeDependence') at the time they are
2554 // constructed. Import of such AST node is possible during import of the
2555 // same record, there is no way to have a completely defined record (all
2556 // fields imported) at that time without multiple AST import passes.
2557 if (!Importer.isMinimalImport())
2558 To->setCompleteDefinition(true);
2559 // Complete the definition even if error is returned.
2560 // The RecordDecl may be already part of the AST so it is better to
2561 // have it in complete state even if something is wrong with it.
2562 llvm::scope_exit DefinitionCompleterScopeExit(DefinitionCompleter);
2563
2564 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2565 return Err;
2566
2567 // Add base classes.
2568 auto *ToCXX = dyn_cast<CXXRecordDecl>(To);
2569 auto *FromCXX = dyn_cast<CXXRecordDecl>(From);
2570 if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) {
2571
2572 struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
2573 struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2574
2575 #define FIELD(Name, Width, Merge) \
2576 ToData.Name = FromData.Name;
2577 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2578
2579 // Copy over the data stored in RecordDeclBits
2580 ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions());
2581
2583 for (const auto &Base1 : FromCXX->bases()) {
2584 ExpectedType TyOrErr = import(Base1.getType());
2585 if (!TyOrErr)
2586 return TyOrErr.takeError();
2587
2588 SourceLocation EllipsisLoc;
2589 if (Base1.isPackExpansion()) {
2590 if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc()))
2591 EllipsisLoc = *LocOrErr;
2592 else
2593 return LocOrErr.takeError();
2594 }
2595
2596 // Ensure that we have a definition for the base.
2597 if (Error Err =
2598 ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
2599 return Err;
2600
2601 auto RangeOrErr = import(Base1.getSourceRange());
2602 if (!RangeOrErr)
2603 return RangeOrErr.takeError();
2604
2605 auto TSIOrErr = import(Base1.getTypeSourceInfo());
2606 if (!TSIOrErr)
2607 return TSIOrErr.takeError();
2608
2609 Bases.push_back(
2610 new (Importer.getToContext()) CXXBaseSpecifier(
2611 *RangeOrErr,
2612 Base1.isVirtual(),
2613 Base1.isBaseOfClass(),
2614 Base1.getAccessSpecifierAsWritten(),
2615 *TSIOrErr,
2616 EllipsisLoc));
2617 }
2618 if (!Bases.empty())
2619 ToCXX->setBases(Bases.data(), Bases.size());
2620 }
2621
2622 if (shouldForceImportDeclContext(Kind)) {
2623 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2624 return Err;
2625 }
2626
2627 return Error::success();
2628}
2629
2631 if (To->getAnyInitializer())
2632 return Error::success();
2633
2634 Expr *FromInit = From->getInit();
2635 if (!FromInit)
2636 return Error::success();
2637
2638 ExpectedExpr ToInitOrErr = import(FromInit);
2639 if (!ToInitOrErr)
2640 return ToInitOrErr.takeError();
2641
2642 To->setInit(*ToInitOrErr);
2643 if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) {
2644 EvaluatedStmt *ToEval = To->ensureEvaluatedStmt();
2645 ToEval->HasConstantInitialization = FromEval->HasConstantInitialization;
2646 ToEval->HasConstantDestruction = FromEval->HasConstantDestruction;
2647 // FIXME: Also import the initializer value.
2648 }
2649
2650 // FIXME: Other bits to merge?
2651 return Error::success();
2652}
2653
2655 EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) {
2656 if (To->getDefinition() || To->isBeingDefined()) {
2657 if (Kind == IDK_Everything)
2658 return ImportDeclContext(From, /*ForceImport=*/true);
2659 return Error::success();
2660 }
2661
2662 To->startDefinition();
2663
2664 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2665 return Err;
2666
2667 ExpectedType ToTypeOrErr =
2668 import(QualType(Importer.getFromContext().getCanonicalTagType(From)));
2669 if (!ToTypeOrErr)
2670 return ToTypeOrErr.takeError();
2671
2672 ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType());
2673 if (!ToPromotionTypeOrErr)
2674 return ToPromotionTypeOrErr.takeError();
2675
2677 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2678 return Err;
2679
2680 // FIXME: we might need to merge the number of positive or negative bits
2681 // if the enumerator lists don't match.
2682 To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr,
2683 From->getNumPositiveBits(),
2684 From->getNumNegativeBits());
2685 return Error::success();
2686}
2687
2691 for (const auto &Arg : FromArgs) {
2692 if (auto ToOrErr = import(Arg))
2693 ToArgs.push_back(*ToOrErr);
2694 else
2695 return ToOrErr.takeError();
2696 }
2697
2698 return Error::success();
2699}
2700
2701// FIXME: Do not forget to remove this and use only 'import'.
2704 return import(From);
2705}
2706
2707template <typename InContainerTy>
2709 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) {
2710 for (const auto &FromLoc : Container) {
2711 if (auto ToLocOrErr = import(FromLoc))
2712 ToTAInfo.addArgument(*ToLocOrErr);
2713 else
2714 return ToLocOrErr.takeError();
2715 }
2716 return Error::success();
2717}
2718
2724
2725bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
2726 bool IgnoreTemplateParmDepth) {
2727 // Eliminate a potential failure point where we attempt to re-import
2728 // something we're trying to import while completing ToRecord.
2729 Decl *ToOrigin = Importer.GetOriginalDecl(To);
2730 if (ToOrigin) {
2731 To = ToOrigin;
2732 }
2733
2735 Importer.getToContext().getLangOpts(), Importer.getFromContext(),
2736 Importer.getToContext(), Importer.getNonEquivalentDecls(),
2738 /*StrictTypeSpelling=*/false, Complain, /*ErrorOnTagTypeMismatch=*/false,
2739 IgnoreTemplateParmDepth);
2740 return Ctx.IsEquivalent(From, To);
2741}
2742
2744 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2745 << D->getDeclKindName();
2746 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2747}
2748
2750 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2751 << D->getDeclKindName();
2752 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2753}
2754
2756 // Import the context of this declaration.
2757 DeclContext *DC, *LexicalDC;
2758 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2759 return std::move(Err);
2760
2761 // Import the location of this declaration.
2762 ExpectedSLoc LocOrErr = import(D->getLocation());
2763 if (!LocOrErr)
2764 return LocOrErr.takeError();
2765
2766 EmptyDecl *ToD;
2767 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr))
2768 return ToD;
2769
2770 ToD->setLexicalDeclContext(LexicalDC);
2771 LexicalDC->addDeclInternal(ToD);
2772 return ToD;
2773}
2774
2776 TranslationUnitDecl *ToD =
2777 Importer.getToContext().getTranslationUnitDecl();
2778
2779 Importer.MapImported(D, ToD);
2780
2781 return ToD;
2782}
2783
2785 DeclContext *DC, *LexicalDC;
2786 DeclarationName Name;
2787 SourceLocation Loc;
2788 NamedDecl *ToND;
2789 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
2790 return std::move(Err);
2791 if (ToND)
2792 return ToND;
2793
2794 BindingDecl *ToD;
2795 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
2796 Name.getAsIdentifierInfo(), D->getType()))
2797 return ToD;
2798
2799 Error Err = Error::success();
2800 QualType ToType = importChecked(Err, D->getType());
2801 Expr *ToBinding = importChecked(Err, D->getBinding());
2802 ValueDecl *ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl());
2803 if (Err)
2804 return std::move(Err);
2805
2806 ToD->setBinding(ToType, ToBinding);
2807 ToD->setDecomposedDecl(ToDecomposedDecl);
2808 addDeclToContexts(D, ToD);
2809
2810 return ToD;
2811}
2812
2814 ExpectedSLoc LocOrErr = import(D->getLocation());
2815 if (!LocOrErr)
2816 return LocOrErr.takeError();
2817 auto ColonLocOrErr = import(D->getColonLoc());
2818 if (!ColonLocOrErr)
2819 return ColonLocOrErr.takeError();
2820
2821 // Import the context of this declaration.
2822 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2823 if (!DCOrErr)
2824 return DCOrErr.takeError();
2825 DeclContext *DC = *DCOrErr;
2826
2827 AccessSpecDecl *ToD;
2828 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(),
2829 DC, *LocOrErr, *ColonLocOrErr))
2830 return ToD;
2831
2832 // Lexical DeclContext and Semantic DeclContext
2833 // is always the same for the accessSpec.
2834 ToD->setLexicalDeclContext(DC);
2835 DC->addDeclInternal(ToD);
2836
2837 return ToD;
2838}
2839
2841 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2842 if (!DCOrErr)
2843 return DCOrErr.takeError();
2844 DeclContext *DC = *DCOrErr;
2845 DeclContext *LexicalDC = DC;
2846
2847 Error Err = Error::success();
2848 auto ToLocation = importChecked(Err, D->getLocation());
2849 auto ToRParenLoc = importChecked(Err, D->getRParenLoc());
2850 auto ToAssertExpr = importChecked(Err, D->getAssertExpr());
2851 auto ToMessage = importChecked(Err, D->getMessage());
2852 if (Err)
2853 return std::move(Err);
2854
2855 StaticAssertDecl *ToD;
2856 if (GetImportedOrCreateDecl(
2857 ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
2858 ToRParenLoc, D->isFailed()))
2859 return ToD;
2860
2861 ToD->setLexicalDeclContext(LexicalDC);
2862 LexicalDC->addDeclInternal(ToD);
2863 return ToD;
2864}
2865
2867 // Import the major distinguishing characteristics of this namespace.
2868 DeclContext *DC, *LexicalDC;
2869 DeclarationName Name;
2870 SourceLocation Loc;
2871 NamedDecl *ToD;
2872 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2873 return std::move(Err);
2874 if (ToD)
2875 return ToD;
2876
2877 NamespaceDecl *MergeWithNamespace = nullptr;
2878 if (!Name) {
2879 // This is an anonymous namespace. Adopt an existing anonymous
2880 // namespace if we can.
2881 DeclContext *EnclosingDC = DC->getEnclosingNamespaceContext();
2882 if (auto *TU = dyn_cast<TranslationUnitDecl>(EnclosingDC))
2883 MergeWithNamespace = TU->getAnonymousNamespace();
2884 else
2885 MergeWithNamespace =
2886 cast<NamespaceDecl>(EnclosingDC)->getAnonymousNamespace();
2887 } else {
2888 SmallVector<NamedDecl *, 4> ConflictingDecls;
2889 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2890 for (auto *FoundDecl : FoundDecls) {
2891 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace))
2892 continue;
2893
2894 if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) {
2895 MergeWithNamespace = FoundNS;
2896 ConflictingDecls.clear();
2897 break;
2898 }
2899
2900 ConflictingDecls.push_back(FoundDecl);
2901 }
2902
2903 if (!ConflictingDecls.empty()) {
2904 ExpectedName NameOrErr = Importer.HandleNameConflict(
2905 Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(),
2906 ConflictingDecls.size());
2907 if (NameOrErr)
2908 Name = NameOrErr.get();
2909 else
2910 return NameOrErr.takeError();
2911 }
2912 }
2913
2914 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2915 if (!BeginLocOrErr)
2916 return BeginLocOrErr.takeError();
2917 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
2918 if (!RBraceLocOrErr)
2919 return RBraceLocOrErr.takeError();
2920
2921 // Create the "to" namespace, if needed.
2922 NamespaceDecl *ToNamespace = MergeWithNamespace;
2923 if (!ToNamespace) {
2924 if (GetImportedOrCreateDecl(ToNamespace, D, Importer.getToContext(), DC,
2925 D->isInline(), *BeginLocOrErr, Loc,
2926 Name.getAsIdentifierInfo(),
2927 /*PrevDecl=*/nullptr, D->isNested()))
2928 return ToNamespace;
2929 ToNamespace->setRBraceLoc(*RBraceLocOrErr);
2930 ToNamespace->setLexicalDeclContext(LexicalDC);
2931 LexicalDC->addDeclInternal(ToNamespace);
2932
2933 // If this is an anonymous namespace, register it as the anonymous
2934 // namespace within its context.
2935 if (!Name) {
2936 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2937 TU->setAnonymousNamespace(ToNamespace);
2938 else
2939 cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
2940 }
2941 }
2942 Importer.MapImported(D, ToNamespace);
2943
2944 if (Error Err = ImportDeclContext(D))
2945 return std::move(Err);
2946
2947 return ToNamespace;
2948}
2949
2951 // Import the major distinguishing characteristics of this namespace.
2952 DeclContext *DC, *LexicalDC;
2953 DeclarationName Name;
2954 SourceLocation Loc;
2955 NamedDecl *LookupD;
2956 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc))
2957 return std::move(Err);
2958 if (LookupD)
2959 return LookupD;
2960
2961 // NOTE: No conflict resolution is done for namespace aliases now.
2962
2963 Error Err = Error::success();
2964 auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc());
2965 auto ToAliasLoc = importChecked(Err, D->getAliasLoc());
2966 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
2967 auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc());
2968 auto ToNamespace = importChecked(Err, D->getNamespace());
2969 if (Err)
2970 return std::move(Err);
2971
2972 IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
2973
2974 NamespaceAliasDecl *ToD;
2975 if (GetImportedOrCreateDecl(
2976 ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
2977 ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
2978 return ToD;
2979
2980 ToD->setLexicalDeclContext(LexicalDC);
2981 LexicalDC->addDeclInternal(ToD);
2982
2983 return ToD;
2984}
2985
2988 // Import the major distinguishing characteristics of this typedef.
2989 DeclarationName Name;
2990 SourceLocation Loc;
2991 NamedDecl *ToD;
2992 // Do not import the DeclContext, we will import it once the TypedefNameDecl
2993 // is created.
2994 if (Error Err = ImportDeclParts(D, Name, ToD, Loc))
2995 return std::move(Err);
2996 if (ToD)
2997 return ToD;
2998
2999 DeclContext *DC = cast_or_null<DeclContext>(
3000 Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext())));
3001 DeclContext *LexicalDC =
3002 cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull(
3004
3005 // If this typedef is not in block scope, determine whether we've
3006 // seen a typedef with the same name (that we can merge with) or any
3007 // other entity by that name (which name lookup could conflict with).
3008 // Note: Repeated typedefs are not valid in C99:
3009 // 'typedef int T; typedef int T;' is invalid
3010 // We do not care about this now.
3011 if (DC && !DC->isFunctionOrMethod()) {
3012 SmallVector<NamedDecl *, 4> ConflictingDecls;
3013 unsigned IDNS = Decl::IDNS_Ordinary;
3014 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3015 for (auto *FoundDecl : FoundDecls) {
3016 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3017 continue;
3018 if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3019 if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D))
3020 continue;
3021
3022 QualType FromUT = D->getUnderlyingType();
3023 QualType FoundUT = FoundTypedef->getUnderlyingType();
3024 if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) {
3025 // If the underlying declarations are unnamed records these can be
3026 // imported as different types. We should create a distinct typedef
3027 // node in this case.
3028 // If we found an existing underlying type with a record in a
3029 // different context (than the imported), this is already reason for
3030 // having distinct typedef nodes for these.
3031 // Again this can create situation like
3032 // 'typedef int T; typedef int T;' but this is hard to avoid without
3033 // a rename strategy at import.
3034 if (!FromUT.isNull() && !FoundUT.isNull()) {
3035 RecordDecl *FromR = FromUT->getAsRecordDecl();
3036 RecordDecl *FoundR = FoundUT->getAsRecordDecl();
3037 if (FromR && FoundR &&
3038 !hasSameVisibilityContextAndLinkage(FoundR, FromR))
3039 continue;
3040 }
3041 // If the "From" context has a complete underlying type but we
3042 // already have a complete underlying type then return with that.
3043 if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
3044 return Importer.MapImported(D, FoundTypedef);
3045 // FIXME Handle redecl chain. When you do that make consistent changes
3046 // in ASTImporterLookupTable too.
3047 } else {
3048 ConflictingDecls.push_back(FoundDecl);
3049 }
3050 }
3051 }
3052
3053 if (!ConflictingDecls.empty()) {
3054 ExpectedName NameOrErr = Importer.HandleNameConflict(
3055 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3056 if (NameOrErr)
3057 Name = NameOrErr.get();
3058 else
3059 return NameOrErr.takeError();
3060 }
3061 }
3062
3063 Error Err = Error::success();
3065 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
3066 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3067 if (Err)
3068 return std::move(Err);
3069
3070 // Create the new typedef node.
3071 // FIXME: ToUnderlyingType is not used.
3072 (void)ToUnderlyingType;
3073 TypedefNameDecl *ToTypedef;
3074 if (IsAlias) {
3075 if (GetImportedOrCreateDecl<TypeAliasDecl>(
3076 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3077 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3078 return ToTypedef;
3079 } else if (GetImportedOrCreateDecl<TypedefDecl>(
3080 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3081 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3082 return ToTypedef;
3083
3084 // Import the DeclContext and set it to the Typedef.
3085 if ((Err = ImportDeclContext(D, DC, LexicalDC)))
3086 return std::move(Err);
3087 ToTypedef->setDeclContext(DC);
3088 ToTypedef->setLexicalDeclContext(LexicalDC);
3089 // Add to the lookupTable because we could not do that in MapImported.
3090 Importer.AddToLookupTable(ToTypedef);
3091
3092 ToTypedef->setAccess(D->getAccess());
3093
3094 // Templated declarations should not appear in DeclContext.
3095 TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr;
3096 if (!FromAlias || !FromAlias->getDescribedAliasTemplate())
3097 LexicalDC->addDeclInternal(ToTypedef);
3098
3099 return ToTypedef;
3100}
3101
3105
3109
3112 // Import the major distinguishing characteristics of this typedef.
3113 DeclContext *DC, *LexicalDC;
3114 DeclarationName Name;
3115 SourceLocation Loc;
3116 NamedDecl *FoundD;
3117 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc))
3118 return std::move(Err);
3119 if (FoundD)
3120 return FoundD;
3121
3122 // If this typedef is not in block scope, determine whether we've
3123 // seen a typedef with the same name (that we can merge with) or any
3124 // other entity by that name (which name lookup could conflict with).
3125 if (!DC->isFunctionOrMethod()) {
3126 SmallVector<NamedDecl *, 4> ConflictingDecls;
3127 unsigned IDNS = Decl::IDNS_Ordinary;
3128 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3129 for (auto *FoundDecl : FoundDecls) {
3130 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3131 continue;
3132 if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) {
3133 if (IsStructuralMatch(D, FoundAlias))
3134 return Importer.MapImported(D, FoundAlias);
3135 ConflictingDecls.push_back(FoundDecl);
3136 }
3137 }
3138
3139 if (!ConflictingDecls.empty()) {
3140 ExpectedName NameOrErr = Importer.HandleNameConflict(
3141 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3142 if (NameOrErr)
3143 Name = NameOrErr.get();
3144 else
3145 return NameOrErr.takeError();
3146 }
3147 }
3148
3149 Error Err = Error::success();
3150 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
3151 auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl());
3152 if (Err)
3153 return std::move(Err);
3154
3155 TypeAliasTemplateDecl *ToAlias;
3156 if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc,
3157 Name, ToTemplateParameters, ToTemplatedDecl))
3158 return ToAlias;
3159
3160 ToTemplatedDecl->setDescribedAliasTemplate(ToAlias);
3161
3162 ToAlias->setAccess(D->getAccess());
3163 ToAlias->setLexicalDeclContext(LexicalDC);
3164 LexicalDC->addDeclInternal(ToAlias);
3165 if (DC != Importer.getToContext().getTranslationUnitDecl())
3166 updateLookupTableForTemplateParameters(*ToTemplateParameters);
3167 return ToAlias;
3168}
3169
3171 // Import the major distinguishing characteristics of this label.
3172 DeclContext *DC, *LexicalDC;
3173 DeclarationName Name;
3174 SourceLocation Loc;
3175 NamedDecl *ToD;
3176 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3177 return std::move(Err);
3178 if (ToD)
3179 return ToD;
3180
3181 assert(LexicalDC->isFunctionOrMethod());
3182
3183 LabelDecl *ToLabel;
3184 if (D->isGnuLocal()) {
3185 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3186 if (!BeginLocOrErr)
3187 return BeginLocOrErr.takeError();
3188 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3189 Name.getAsIdentifierInfo(), *BeginLocOrErr))
3190 return ToLabel;
3191
3192 } else {
3193 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3194 Name.getAsIdentifierInfo()))
3195 return ToLabel;
3196
3197 }
3198
3199 Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
3200 if (!ToStmtOrErr)
3201 return ToStmtOrErr.takeError();
3202
3203 ToLabel->setStmt(*ToStmtOrErr);
3204 ToLabel->setLexicalDeclContext(LexicalDC);
3205 LexicalDC->addDeclInternal(ToLabel);
3206 return ToLabel;
3207}
3208
3210 // Import the major distinguishing characteristics of this enum.
3211 DeclContext *DC, *LexicalDC;
3212 DeclarationName Name;
3213 SourceLocation Loc;
3214 NamedDecl *ToD;
3215 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3216 return std::move(Err);
3217 if (ToD)
3218 return ToD;
3219
3220 // Figure out what enum name we're looking for.
3221 unsigned IDNS = Decl::IDNS_Tag;
3222 DeclarationName SearchName = Name;
3223 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3224 if (Error Err = importInto(
3225 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3226 return std::move(Err);
3227 IDNS = Decl::IDNS_Ordinary;
3228 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3229 IDNS |= Decl::IDNS_Ordinary;
3230
3231 // We may already have an enum of the same name; try to find and match it.
3232 EnumDecl *PrevDecl = nullptr;
3233 if (!DC->isFunctionOrMethod()) {
3234 SmallVector<NamedDecl *, 4> ConflictingDecls;
3235 auto FoundDecls =
3236 Importer.findDeclsInToCtx(DC, SearchName);
3237 for (auto *FoundDecl : FoundDecls) {
3238 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3239 continue;
3240
3241 if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3242 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3243 FoundDecl = Tag->getDecl();
3244 }
3245
3246 if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) {
3247 if (!hasSameVisibilityContextAndLinkage(FoundEnum, D))
3248 continue;
3249 if (IsStructuralMatch(D, FoundEnum, !SearchName.isEmpty())) {
3250 EnumDecl *FoundDef = FoundEnum->getDefinition();
3251 if (D->isThisDeclarationADefinition() && FoundDef)
3252 return Importer.MapImported(D, FoundDef);
3253 PrevDecl = FoundEnum->getMostRecentDecl();
3254 break;
3255 }
3256 ConflictingDecls.push_back(FoundDecl);
3257 }
3258 }
3259
3260 // In case of unnamed enums, we try to find an existing similar one, if none
3261 // was found, perform the import always.
3262 // Structural in-equivalence is not detected in this way here, but it may
3263 // be found when the parent decl is imported (if the enum is part of a
3264 // class). To make this totally exact a more difficult solution is needed.
3265 if (SearchName && !ConflictingDecls.empty()) {
3266 ExpectedName NameOrErr = Importer.HandleNameConflict(
3267 SearchName, DC, IDNS, ConflictingDecls.data(),
3268 ConflictingDecls.size());
3269 if (NameOrErr)
3270 Name = NameOrErr.get();
3271 else
3272 return NameOrErr.takeError();
3273 }
3274 }
3275
3276 Error Err = Error::success();
3277 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3278 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3279 auto ToIntegerType = importChecked(Err, D->getIntegerType());
3280 auto ToBraceRange = importChecked(Err, D->getBraceRange());
3281 if (Err)
3282 return std::move(Err);
3283
3284 // Create the enum declaration.
3285 EnumDecl *D2;
3286 if (GetImportedOrCreateDecl(
3287 D2, D, Importer.getToContext(), DC, ToBeginLoc,
3288 Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(),
3289 D->isScopedUsingClassTag(), D->isFixed()))
3290 return D2;
3291
3292 D2->setQualifierInfo(ToQualifierLoc);
3293 D2->setIntegerType(ToIntegerType);
3294 D2->setBraceRange(ToBraceRange);
3295 D2->setAccess(D->getAccess());
3296 D2->setLexicalDeclContext(LexicalDC);
3297 addDeclToContexts(D, D2);
3298
3300 TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
3301 EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
3302 if (Expected<EnumDecl *> ToInstOrErr = import(FromInst))
3303 D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
3304 else
3305 return ToInstOrErr.takeError();
3306 if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
3308 else
3309 return POIOrErr.takeError();
3310 }
3311
3312 // Import the definition
3313 if (D->isCompleteDefinition())
3314 if (Error Err = ImportDefinition(D, D2))
3315 return std::move(Err);
3316
3317 return D2;
3318}
3319
3321 bool IsFriendTemplate = false;
3322 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3323 IsFriendTemplate =
3324 DCXX->getDescribedClassTemplate() &&
3325 DCXX->getDescribedClassTemplate()->getFriendObjectKind() !=
3327 }
3328
3329 // Import the major distinguishing characteristics of this record.
3330 DeclContext *DC = nullptr, *LexicalDC = nullptr;
3331 DeclarationName Name;
3332 SourceLocation Loc;
3333 NamedDecl *ToD = nullptr;
3334 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3335 return std::move(Err);
3336 if (ToD)
3337 return ToD;
3338
3339 // Figure out what structure name we're looking for.
3340 unsigned IDNS = Decl::IDNS_Tag;
3341 DeclarationName SearchName = Name;
3342 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3343 if (Error Err = importInto(
3344 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3345 return std::move(Err);
3346 IDNS = Decl::IDNS_Ordinary;
3347 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3349
3350 bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
3351 : DC->isDependentContext();
3352 bool DependentFriend = IsFriendTemplate && IsDependentContext;
3353
3354 // We may already have a record of the same name; try to find and match it.
3355 RecordDecl *PrevDecl = nullptr;
3356 if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
3357 SmallVector<NamedDecl *, 4> ConflictingDecls;
3358 auto FoundDecls =
3359 Importer.findDeclsInToCtx(DC, SearchName);
3360 if (!FoundDecls.empty()) {
3361 // We're going to have to compare D against potentially conflicting Decls,
3362 // so complete it.
3365 }
3366
3367 for (auto *FoundDecl : FoundDecls) {
3368 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3369 continue;
3370
3371 Decl *Found = FoundDecl;
3372 if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
3373 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3374 Found = Tag->getDecl();
3375 }
3376
3377 if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) {
3378 // Do not emit false positive diagnostic in case of unnamed
3379 // struct/union and in case of anonymous structs. Would be false
3380 // because there may be several anonymous/unnamed structs in a class.
3381 // E.g. these are both valid:
3382 // struct A { // unnamed structs
3383 // struct { struct A *next; } entry0;
3384 // struct { struct A *next; } entry1;
3385 // };
3386 // struct X { struct { int a; }; struct { int b; }; }; // anon structs
3387 if (!SearchName)
3388 if (!IsStructuralMatch(D, FoundRecord, false))
3389 continue;
3390
3391 if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
3392 continue;
3393
3394 if (IsStructuralMatch(D, FoundRecord)) {
3395 RecordDecl *FoundDef = FoundRecord->getDefinition();
3396 if (D->isThisDeclarationADefinition() && FoundDef) {
3397 // FIXME: Structural equivalence check should check for same
3398 // user-defined methods.
3399 Importer.MapImported(D, FoundDef);
3400 if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3401 auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef);
3402 assert(FoundCXX && "Record type mismatch");
3403
3404 if (!Importer.isMinimalImport())
3405 // FoundDef may not have every implicit method that D has
3406 // because implicit methods are created only if they are used.
3407 if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
3408 return std::move(Err);
3409 }
3410 // FIXME: We can return FoundDef here.
3411 }
3412 PrevDecl = FoundRecord->getMostRecentDecl();
3413 break;
3414 }
3415 ConflictingDecls.push_back(FoundDecl);
3416 } // kind is RecordDecl
3417 } // for
3418
3419 if (!ConflictingDecls.empty() && SearchName) {
3420 ExpectedName NameOrErr = Importer.HandleNameConflict(
3421 SearchName, DC, IDNS, ConflictingDecls.data(),
3422 ConflictingDecls.size());
3423 if (NameOrErr)
3424 Name = NameOrErr.get();
3425 else
3426 return NameOrErr.takeError();
3427 }
3428 }
3429
3430 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3431 if (!BeginLocOrErr)
3432 return BeginLocOrErr.takeError();
3433
3434 // Create the record declaration.
3435 RecordDecl *D2 = nullptr;
3436 CXXRecordDecl *D2CXX = nullptr;
3437 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3438 if (DCXX->isLambda()) {
3439 auto TInfoOrErr = import(DCXX->getLambdaTypeInfo());
3440 if (!TInfoOrErr)
3441 return TInfoOrErr.takeError();
3442 if (GetImportedOrCreateSpecialDecl(
3443 D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(),
3444 DC, *TInfoOrErr, Loc, DCXX->getLambdaDependencyKind(),
3445 DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault()))
3446 return D2CXX;
3447 Decl *ContextDecl = DCXX->getLambdaContextDecl();
3448 ExpectedDecl CDeclOrErr = import(ContextDecl);
3449 if (!CDeclOrErr)
3450 return CDeclOrErr.takeError();
3451 if (ContextDecl != nullptr) {
3452 D2CXX->setLambdaContextDecl(*CDeclOrErr);
3453 }
3454 D2CXX->setLambdaNumbering(DCXX->getLambdaNumbering());
3455 } else {
3456 if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
3457 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3458 Name.getAsIdentifierInfo(),
3459 cast_or_null<CXXRecordDecl>(PrevDecl)))
3460 return D2CXX;
3461 }
3462
3463 D2 = D2CXX;
3464 D2->setAccess(D->getAccess());
3465 D2->setLexicalDeclContext(LexicalDC);
3466 addDeclToContexts(D, D2);
3467
3468 if (ClassTemplateDecl *FromDescribed =
3469 DCXX->getDescribedClassTemplate()) {
3470 ClassTemplateDecl *ToDescribed;
3471 if (Error Err = importInto(ToDescribed, FromDescribed))
3472 return std::move(Err);
3473 D2CXX->setDescribedClassTemplate(ToDescribed);
3474 } else if (MemberSpecializationInfo *MemberInfo =
3475 DCXX->getMemberSpecializationInfo()) {
3477 MemberInfo->getTemplateSpecializationKind();
3479
3480 if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
3481 D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
3482 else
3483 return ToInstOrErr.takeError();
3484
3485 if (ExpectedSLoc POIOrErr =
3486 import(MemberInfo->getPointOfInstantiation()))
3488 *POIOrErr);
3489 else
3490 return POIOrErr.takeError();
3491 }
3492
3493 } else {
3494 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
3495 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3496 Name.getAsIdentifierInfo(), PrevDecl))
3497 return D2;
3498 D2->setLexicalDeclContext(LexicalDC);
3499 addDeclToContexts(D, D2);
3500 }
3501
3502 if (auto BraceRangeOrErr = import(D->getBraceRange()))
3503 D2->setBraceRange(*BraceRangeOrErr);
3504 else
3505 return BraceRangeOrErr.takeError();
3506 if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
3507 D2->setQualifierInfo(*QualifierLocOrErr);
3508 else
3509 return QualifierLocOrErr.takeError();
3510
3511 if (D->isAnonymousStructOrUnion())
3512 D2->setAnonymousStructOrUnion(true);
3513
3514 if (D->isCompleteDefinition())
3515 if (Error Err = ImportDefinition(D, D2, IDK_Default))
3516 return std::move(Err);
3517
3518 return D2;
3519}
3520
3522 // Import the major distinguishing characteristics of this enumerator.
3523 DeclContext *DC, *LexicalDC;
3524 DeclarationName Name;
3525 SourceLocation Loc;
3526 NamedDecl *ToD;
3527 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3528 return std::move(Err);
3529 if (ToD)
3530 return ToD;
3531
3532 // Determine whether there are any other declarations with the same name and
3533 // in the same context.
3534 if (!LexicalDC->isFunctionOrMethod()) {
3535 SmallVector<NamedDecl *, 4> ConflictingDecls;
3536 unsigned IDNS = Decl::IDNS_Ordinary;
3537 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3538 for (auto *FoundDecl : FoundDecls) {
3539 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3540 continue;
3541
3542 if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
3543 if (IsStructuralMatch(D, FoundEnumConstant))
3544 return Importer.MapImported(D, FoundEnumConstant);
3545 ConflictingDecls.push_back(FoundDecl);
3546 }
3547 }
3548
3549 if (!ConflictingDecls.empty()) {
3550 ExpectedName NameOrErr = Importer.HandleNameConflict(
3551 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3552 if (NameOrErr)
3553 Name = NameOrErr.get();
3554 else
3555 return NameOrErr.takeError();
3556 }
3557 }
3558
3559 ExpectedType TypeOrErr = import(D->getType());
3560 if (!TypeOrErr)
3561 return TypeOrErr.takeError();
3562
3563 ExpectedExpr InitOrErr = import(D->getInitExpr());
3564 if (!InitOrErr)
3565 return InitOrErr.takeError();
3566
3567 EnumConstantDecl *ToEnumerator;
3568 if (GetImportedOrCreateDecl(
3569 ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
3570 Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
3571 return ToEnumerator;
3572
3573 ToEnumerator->setAccess(D->getAccess());
3574 ToEnumerator->setLexicalDeclContext(LexicalDC);
3575 LexicalDC->addDeclInternal(ToEnumerator);
3576 return ToEnumerator;
3577}
3578
3579template <typename DeclTy>
3581 DeclTy *ToD) {
3582 unsigned int Num = FromD->getNumTemplateParameterLists();
3583 if (Num == 0)
3584 return Error::success();
3586 for (unsigned int I = 0; I < Num; ++I)
3587 if (Expected<TemplateParameterList *> ToTPListOrErr =
3588 import(FromD->getTemplateParameterList(I)))
3589 ToTPLists[I] = *ToTPListOrErr;
3590 else
3591 return ToTPListOrErr.takeError();
3592 ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
3593 return Error::success();
3594}
3595
3597 FunctionDecl *FromFD, FunctionDecl *ToFD) {
3598 switch (FromFD->getTemplatedKind()) {
3601 return Error::success();
3602
3604 if (Expected<FunctionDecl *> InstFDOrErr =
3605 import(FromFD->getInstantiatedFromDecl()))
3606 ToFD->setInstantiatedFromDecl(*InstFDOrErr);
3607 return Error::success();
3610
3611 if (Expected<FunctionDecl *> InstFDOrErr =
3612 import(FromFD->getInstantiatedFromMemberFunction()))
3613 ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
3614 else
3615 return InstFDOrErr.takeError();
3616
3617 if (ExpectedSLoc POIOrErr = import(
3620 else
3621 return POIOrErr.takeError();
3622
3623 return Error::success();
3624 }
3625
3627 auto FunctionAndArgsOrErr =
3629 if (!FunctionAndArgsOrErr)
3630 return FunctionAndArgsOrErr.takeError();
3631
3633 Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
3634
3635 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
3636 TemplateArgumentListInfo ToTAInfo;
3637 const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
3638 if (FromTAArgsAsWritten)
3640 *FromTAArgsAsWritten, ToTAInfo))
3641 return Err;
3642
3643 ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
3644 if (!POIOrErr)
3645 return POIOrErr.takeError();
3646
3647 if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
3648 return Err;
3649
3650 TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
3651 ToFD->setFunctionTemplateSpecialization(
3652 std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr,
3653 TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
3654 return Error::success();
3655 }
3656
3658 auto *FromInfo = FromFD->getDependentSpecializationInfo();
3659 UnresolvedSet<8> Candidates;
3660 for (FunctionTemplateDecl *FTD : FromInfo->getCandidates()) {
3661 if (Expected<FunctionTemplateDecl *> ToFTDOrErr = import(FTD))
3662 Candidates.addDecl(*ToFTDOrErr);
3663 else
3664 return ToFTDOrErr.takeError();
3665 }
3666
3667 // Import TemplateArgumentListInfo.
3668 TemplateArgumentListInfo ToTAInfo;
3669 const auto *FromTAArgsAsWritten = FromInfo->TemplateArgumentsAsWritten;
3670 if (FromTAArgsAsWritten)
3671 if (Error Err =
3672 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
3673 return Err;
3674
3676 Importer.getToContext(), Candidates,
3677 FromTAArgsAsWritten ? &ToTAInfo : nullptr);
3678 return Error::success();
3679 }
3680 }
3681 llvm_unreachable("All cases should be covered!");
3682}
3683
3686 auto FunctionAndArgsOrErr =
3688 if (!FunctionAndArgsOrErr)
3689 return FunctionAndArgsOrErr.takeError();
3690
3692 TemplateArgsTy ToTemplArgs;
3693 std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
3694 void *InsertPos = nullptr;
3695 auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos);
3696 return FoundSpec;
3697}
3698
3700 FunctionDecl *ToFD) {
3701 if (Stmt *FromBody = FromFD->getBody()) {
3702 if (ExpectedStmt ToBodyOrErr = import(FromBody))
3703 ToFD->setBody(*ToBodyOrErr);
3704 else
3705 return ToBodyOrErr.takeError();
3706 }
3707 return Error::success();
3708}
3709
3710// Returns true if the given D has a DeclContext up to the TranslationUnitDecl
3711// which is equal to the given DC, or D is equal to DC.
3712static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) {
3713 const DeclContext *DCi = dyn_cast<DeclContext>(D);
3714 if (!DCi)
3715 DCi = D->getDeclContext();
3716 assert(DCi && "Declaration should have a context");
3717 while (DCi != D->getTranslationUnitDecl()) {
3718 if (DCi == DC)
3719 return true;
3720 DCi = DCi->getParent();
3721 }
3722 return false;
3723}
3724
3725// Check if there is a declaration that has 'DC' as parent context and is
3726// referenced from statement 'S' or one of its children. The search is done in
3727// BFS order through children of 'S'.
3728static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
3729 SmallVector<const Stmt *> ToProcess;
3730 ToProcess.push_back(S);
3731 while (!ToProcess.empty()) {
3732 const Stmt *CurrentS = ToProcess.pop_back_val();
3733 ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
3734 if (const auto *DeclRef = dyn_cast<DeclRefExpr>(CurrentS)) {
3735 if (const Decl *D = DeclRef->getDecl())
3736 if (isAncestorDeclContextOf(DC, D))
3737 return true;
3738 } else if (const auto *E =
3739 dyn_cast_or_null<SubstNonTypeTemplateParmExpr>(CurrentS)) {
3740 if (const Decl *D = E->getAssociatedDecl())
3741 if (isAncestorDeclContextOf(DC, D))
3742 return true;
3743 }
3744 }
3745 return false;
3746}
3747
3748namespace {
3749/// Check if a type has any reference to a declaration that is inside the body
3750/// of a function.
3751/// The \c CheckType(QualType) function should be used to determine
3752/// this property.
3753///
3754/// The type visitor visits one type object only (not recursive).
3755/// To find all referenced declarations we must discover all type objects until
3756/// the canonical type is reached (walk over typedef and similar objects). This
3757/// is done by loop over all "sugar" type objects. For every such type we must
3758/// check all declarations that are referenced from it. For this check the
3759/// visitor is used. In the visit functions all referenced declarations except
3760/// the one that follows in the sugar chain (if any) must be checked. For this
3761/// check the same visitor is re-used (it has no state-dependent data).
3762///
3763/// The visit functions have 3 possible return values:
3764/// - True, found a declaration inside \c ParentDC.
3765/// - False, found declarations only outside \c ParentDC and it is not possible
3766/// to find more declarations (the "sugar" chain does not continue).
3767/// - Empty optional value, found no declarations or only outside \c ParentDC,
3768/// but it is possible to find more declarations in the type "sugar" chain.
3769/// The loop over the "sugar" types can be implemented by using type visit
3770/// functions only (call \c CheckType with the desugared type). With the current
3771/// solution no visit function is needed if the type has only a desugared type
3772/// as data.
3773class IsTypeDeclaredInsideVisitor
3774 : public TypeVisitor<IsTypeDeclaredInsideVisitor, std::optional<bool>> {
3775public:
3776 IsTypeDeclaredInsideVisitor(const FunctionDecl *ParentDC)
3777 : ParentDC(ParentDC) {}
3778
3779 bool CheckType(QualType T) {
3780 // Check the chain of "sugar" types.
3781 // The "sugar" types are typedef or similar types that have the same
3782 // canonical type.
3783 if (std::optional<bool> Res = Visit(T.getTypePtr()))
3784 return *Res;
3785 QualType DsT =
3786 T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3787 while (DsT != T) {
3788 if (std::optional<bool> Res = Visit(DsT.getTypePtr()))
3789 return *Res;
3790 T = DsT;
3791 DsT = T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3792 }
3793 return false;
3794 }
3795
3796 std::optional<bool> VisitTagType(const TagType *T) {
3797 if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(T->getDecl()))
3798 for (const auto &Arg : Spec->getTemplateArgs().asArray())
3799 if (checkTemplateArgument(Arg))
3800 return true;
3801 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3802 }
3803
3804 std::optional<bool> VisitPointerType(const PointerType *T) {
3805 return CheckType(T->getPointeeType());
3806 }
3807
3808 std::optional<bool> VisitReferenceType(const ReferenceType *T) {
3809 return CheckType(T->getPointeeTypeAsWritten());
3810 }
3811
3812 std::optional<bool> VisitTypedefType(const TypedefType *T) {
3813 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3814 }
3815
3816 std::optional<bool> VisitUsingType(const UsingType *T) {
3817 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3818 }
3819
3820 std::optional<bool>
3821 VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
3822 for (const auto &Arg : T->template_arguments())
3823 if (checkTemplateArgument(Arg))
3824 return true;
3825 // This type is a "sugar" to a record type, it can have a desugared type.
3826 return {};
3827 }
3828
3829 std::optional<bool> VisitUnaryTransformType(const UnaryTransformType *T) {
3830 return CheckType(T->getBaseType());
3831 }
3832
3833 std::optional<bool>
3834 VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
3835 // The "associated declaration" can be the same as ParentDC.
3836 if (isAncestorDeclContextOf(ParentDC, T->getAssociatedDecl()))
3837 return true;
3838 return {};
3839 }
3840
3841 std::optional<bool> VisitConstantArrayType(const ConstantArrayType *T) {
3842 if (T->getSizeExpr() && isAncestorDeclContextOf(ParentDC, T->getSizeExpr()))
3843 return true;
3844
3845 return CheckType(T->getElementType());
3846 }
3847
3848 std::optional<bool> VisitVariableArrayType(const VariableArrayType *T) {
3849 llvm_unreachable(
3850 "Variable array should not occur in deduced return type of a function");
3851 }
3852
3853 std::optional<bool> VisitIncompleteArrayType(const IncompleteArrayType *T) {
3854 llvm_unreachable("Incomplete array should not occur in deduced return type "
3855 "of a function");
3856 }
3857
3858 std::optional<bool> VisitDependentArrayType(const IncompleteArrayType *T) {
3859 llvm_unreachable("Dependent array should not occur in deduced return type "
3860 "of a function");
3861 }
3862
3863private:
3864 const DeclContext *const ParentDC;
3865
3866 bool checkTemplateArgument(const TemplateArgument &Arg) {
3867 switch (Arg.getKind()) {
3869 return false;
3871 return CheckType(Arg.getIntegralType());
3873 return CheckType(Arg.getAsType());
3875 return isAncestorDeclContextOf(ParentDC, Arg.getAsExpr());
3877 // FIXME: The declaration in this case is not allowed to be in a function?
3878 return isAncestorDeclContextOf(ParentDC, Arg.getAsDecl());
3880 // FIXME: The type is not allowed to be in the function?
3881 return CheckType(Arg.getNullPtrType());
3883 return CheckType(Arg.getStructuralValueType());
3885 for (const auto &PackArg : Arg.getPackAsArray())
3886 if (checkTemplateArgument(PackArg))
3887 return true;
3888 return false;
3890 // Templates can not be defined locally in functions.
3891 // A template passed as argument can be not in ParentDC.
3892 return false;
3894 // Templates can not be defined locally in functions.
3895 // A template passed as argument can be not in ParentDC.
3896 return false;
3897 }
3898 llvm_unreachable("Unknown TemplateArgument::ArgKind enum");
3899 };
3900};
3901} // namespace
3902
3903/// This function checks if the given function has a return type that contains
3904/// a reference (in any way) to a declaration inside the same function.
3906 QualType FromTy = D->getType();
3907 const auto *FromFPT = FromTy->getAs<FunctionProtoType>();
3908 assert(FromFPT && "Must be called on FunctionProtoType");
3909
3910 auto IsCXX11Lambda = [&]() {
3911 if (Importer.FromContext.getLangOpts().CPlusPlus14) // C++14 or later
3912 return false;
3913
3914 return isLambdaMethod(D);
3915 };
3916
3917 QualType RetT = FromFPT->getReturnType();
3918 if (isa<AutoType>(RetT.getTypePtr()) || IsCXX11Lambda()) {
3919 FunctionDecl *Def = D->getDefinition();
3920 IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D);
3921 return Visitor.CheckType(RetT);
3922 }
3923
3924 return false;
3925}
3926
3928ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3929 Expr *ExplicitExpr = ESpec.getExpr();
3930 if (ExplicitExpr)
3931 ExplicitExpr = importChecked(Err, ESpec.getExpr());
3932 return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3933}
3934
3936
3938 auto RedeclIt = Redecls.begin();
3939 // Import the first part of the decl chain. I.e. import all previous
3940 // declarations starting from the canonical decl.
3941 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3942 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3943 if (!ToRedeclOrErr)
3944 return ToRedeclOrErr.takeError();
3945 }
3946 assert(*RedeclIt == D);
3947
3948 // Import the major distinguishing characteristics of this function.
3949 DeclContext *DC, *LexicalDC;
3950 DeclarationName Name;
3951 SourceLocation Loc;
3952 NamedDecl *ToD;
3953 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3954 return std::move(Err);
3955 if (ToD)
3956 return ToD;
3957
3958 FunctionDecl *FoundByLookup = nullptr;
3960
3961 // If this is a function template specialization, then try to find the same
3962 // existing specialization in the "to" context. The lookup below will not
3963 // find any specialization, but would find the primary template; thus, we
3964 // have to skip normal lookup in case of specializations.
3965 // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3966 if (D->getTemplatedKind() ==
3968 auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
3969 if (!FoundFunctionOrErr)
3970 return FoundFunctionOrErr.takeError();
3971 if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
3972 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3973 return Def;
3974 FoundByLookup = FoundFunction;
3975 }
3976 }
3977 // Try to find a function in our own ("to") context with the same name, same
3978 // type, and in the same context as the function we're importing.
3979 else if (!LexicalDC->isFunctionOrMethod()) {
3980 SmallVector<NamedDecl *, 4> ConflictingDecls;
3982 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3983 for (auto *FoundDecl : FoundDecls) {
3984 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3985 continue;
3986
3987 if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3988 if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
3989 continue;
3990
3991 if (IsStructuralMatch(D, FoundFunction)) {
3992 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3993 return Def;
3994 FoundByLookup = FoundFunction;
3995 break;
3996 }
3997 // FIXME: Check for overloading more carefully, e.g., by boosting
3998 // Sema::IsOverload out to the AST library.
3999
4000 // Function overloading is okay in C++.
4001 if (Importer.getToContext().getLangOpts().CPlusPlus)
4002 continue;
4003
4004 // Complain about inconsistent function types.
4005 Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
4006 << Name << D->getType() << FoundFunction->getType();
4007 Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
4008 << FoundFunction->getType();
4009 ConflictingDecls.push_back(FoundDecl);
4010 }
4011 }
4012
4013 if (!ConflictingDecls.empty()) {
4014 ExpectedName NameOrErr = Importer.HandleNameConflict(
4015 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4016 if (NameOrErr)
4017 Name = NameOrErr.get();
4018 else
4019 return NameOrErr.takeError();
4020 }
4021 }
4022
4023 // We do not allow more than one in-class declaration of a function. This is
4024 // because AST clients like VTableBuilder asserts on this. VTableBuilder
4025 // assumes there is only one in-class declaration. Building a redecl
4026 // chain would result in more than one in-class declaration for
4027 // overrides (even if they are part of the same redecl chain inside the
4028 // derived class.)
4029 if (FoundByLookup) {
4030 if (isa<CXXMethodDecl>(FoundByLookup)) {
4031 if (D->getLexicalDeclContext() == D->getDeclContext()) {
4032 if (!D->doesThisDeclarationHaveABody()) {
4033 if (FunctionTemplateDecl *DescribedD =
4035 // Handle a "templated" function together with its described
4036 // template. This avoids need for a similar check at import of the
4037 // described template.
4038 assert(FoundByLookup->getDescribedFunctionTemplate() &&
4039 "Templated function mapped to non-templated?");
4040 Importer.MapImported(DescribedD,
4041 FoundByLookup->getDescribedFunctionTemplate());
4042 }
4043 return Importer.MapImported(D, FoundByLookup);
4044 } else {
4045 // Let's continue and build up the redecl chain in this case.
4046 // FIXME Merge the functions into one decl.
4047 }
4048 }
4049 }
4050 }
4051
4052 DeclarationNameInfo NameInfo(Name, Loc);
4053 // Import additional name location/type info.
4054 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
4055 return std::move(Err);
4056
4057 QualType FromTy = D->getType();
4058 TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
4059 // Set to true if we do not import the type of the function as is. There are
4060 // cases when the original type would result in an infinite recursion during
4061 // the import. To avoid an infinite recursion when importing, we create the
4062 // FunctionDecl with a simplified function type and update it only after the
4063 // relevant AST nodes are already imported.
4064 // The type is related to TypeSourceInfo (it references the type), so we must
4065 // do the same with TypeSourceInfo.
4066 bool UsedDifferentProtoType = false;
4067 if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
4068 QualType FromReturnTy = FromFPT->getReturnType();
4069 // Functions with auto return type may define a struct inside their body
4070 // and the return type could refer to that struct.
4071 // E.g.: auto foo() { struct X{}; return X(); }
4072 // To avoid an infinite recursion when importing, create the FunctionDecl
4073 // with a simplified return type.
4074 // Reuse this approach for auto return types declared as typenames from
4075 // template params, tracked in FindFunctionDeclImportCycle.
4077 Importer.FindFunctionDeclImportCycle.isCycle(D)) {
4078 FromReturnTy = Importer.getFromContext().VoidTy;
4079 UsedDifferentProtoType = true;
4080 }
4081 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
4082 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
4083 // FunctionDecl that we are importing the FunctionProtoType for.
4084 // To avoid an infinite recursion when importing, create the FunctionDecl
4085 // with a simplified function type.
4086 if (FromEPI.ExceptionSpec.SourceDecl ||
4087 FromEPI.ExceptionSpec.SourceTemplate ||
4088 FromEPI.ExceptionSpec.NoexceptExpr) {
4090 FromEPI = DefaultEPI;
4091 UsedDifferentProtoType = true;
4092 }
4093 FromTy = Importer.getFromContext().getFunctionType(
4094 FromReturnTy, FromFPT->getParamTypes(), FromEPI);
4095 FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
4096 FromTy, D->getBeginLoc());
4097 }
4098
4099 Error Err = Error::success();
4100 auto ScopedReturnTypeDeclCycleDetector =
4101 Importer.FindFunctionDeclImportCycle.makeScopedCycleDetection(D);
4102 auto T = importChecked(Err, FromTy);
4103 auto TInfo = importChecked(Err, FromTSI);
4104 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4105 auto ToEndLoc = importChecked(Err, D->getEndLoc());
4106 auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
4107 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4108 AssociatedConstraint TrailingRequiresClause = D->getTrailingRequiresClause();
4109 TrailingRequiresClause.ConstraintExpr =
4110 importChecked(Err, TrailingRequiresClause.ConstraintExpr);
4111 if (Err)
4112 return std::move(Err);
4113
4114 // Import the function parameters.
4116 for (auto *P : D->parameters()) {
4117 if (Expected<ParmVarDecl *> ToPOrErr = import(P))
4118 Parameters.push_back(*ToPOrErr);
4119 else
4120 return ToPOrErr.takeError();
4121 }
4122
4123 // Create the imported function.
4124 FunctionDecl *ToFunction = nullptr;
4125 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4126 ExplicitSpecifier ESpec =
4127 importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
4128 if (Err)
4129 return std::move(Err);
4130 auto ToInheritedConstructor = InheritedConstructor();
4131 if (FromConstructor->isInheritingConstructor()) {
4132 Expected<InheritedConstructor> ImportedInheritedCtor =
4133 import(FromConstructor->getInheritedConstructor());
4134 if (!ImportedInheritedCtor)
4135 return ImportedInheritedCtor.takeError();
4136 ToInheritedConstructor = *ImportedInheritedCtor;
4137 }
4138 if (GetImportedOrCreateDecl<CXXConstructorDecl>(
4139 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4140 ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
4142 ToInheritedConstructor, TrailingRequiresClause))
4143 return ToFunction;
4144 } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
4145
4146 Error Err = Error::success();
4147 auto ToOperatorDelete = importChecked(
4148 Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
4149 auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
4150 if (Err)
4151 return std::move(Err);
4152
4153 if (GetImportedOrCreateDecl<CXXDestructorDecl>(
4154 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4155 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4157 TrailingRequiresClause))
4158 return ToFunction;
4159
4160 CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
4161
4162 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
4163 } else if (CXXConversionDecl *FromConversion =
4164 dyn_cast<CXXConversionDecl>(D)) {
4165 ExplicitSpecifier ESpec =
4166 importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
4167 if (Err)
4168 return std::move(Err);
4169 if (GetImportedOrCreateDecl<CXXConversionDecl>(
4170 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4171 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4172 D->isInlineSpecified(), ESpec, D->getConstexprKind(),
4173 SourceLocation(), TrailingRequiresClause))
4174 return ToFunction;
4175 } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
4176 if (GetImportedOrCreateDecl<CXXMethodDecl>(
4177 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4178 ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
4179 Method->UsesFPIntrin(), Method->isInlineSpecified(),
4180 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
4181 return ToFunction;
4182 } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
4183 ExplicitSpecifier ESpec =
4184 importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
4185 CXXConstructorDecl *Ctor =
4186 importChecked(Err, Guide->getCorrespondingConstructor());
4187 const CXXDeductionGuideDecl *SourceDG =
4188 importChecked(Err, Guide->getSourceDeductionGuide());
4189 if (Err)
4190 return std::move(Err);
4191 if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
4192 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
4193 NameInfo, T, TInfo, ToEndLoc, Ctor,
4194 Guide->getDeductionCandidateKind(), TrailingRequiresClause,
4195 SourceDG, Guide->getSourceDeductionGuideKind()))
4196 return ToFunction;
4197 } else {
4198 if (GetImportedOrCreateDecl(
4199 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
4200 NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
4202 D->getConstexprKind(), TrailingRequiresClause))
4203 return ToFunction;
4204 }
4205
4206 // Connect the redecl chain.
4207 if (FoundByLookup) {
4208 auto *Recent = const_cast<FunctionDecl *>(
4209 FoundByLookup->getMostRecentDecl());
4210 ToFunction->setPreviousDecl(Recent);
4211 // FIXME Probably we should merge exception specifications. E.g. In the
4212 // "To" context the existing function may have exception specification with
4213 // noexcept-unevaluated, while the newly imported function may have an
4214 // evaluated noexcept. A call to adjustExceptionSpec() on the imported
4215 // decl and its redeclarations may be required.
4216 }
4217
4218 StringLiteral *Msg = D->getDeletedMessage();
4219 if (Msg) {
4220 auto Imported = import(Msg);
4221 if (!Imported)
4222 return Imported.takeError();
4223 Msg = *Imported;
4224 }
4225
4226 ToFunction->setQualifierInfo(ToQualifierLoc);
4227 ToFunction->setAccess(D->getAccess());
4228 ToFunction->setLexicalDeclContext(LexicalDC);
4229 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
4230 ToFunction->setTrivial(D->isTrivial());
4231 ToFunction->setIsPureVirtual(D->isPureVirtual());
4232 ToFunction->setDefaulted(D->isDefaulted());
4234 ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
4240 ToFunction->setRangeEnd(ToEndLoc);
4241 ToFunction->setDefaultLoc(ToDefaultLoc);
4242
4243 if (Msg)
4244 ToFunction->setDefaultedOrDeletedInfo(
4246 Importer.getToContext(), {}, Msg));
4247
4248 // Set the parameters.
4249 for (auto *Param : Parameters) {
4250 Param->setOwningFunction(ToFunction);
4251 ToFunction->addDeclInternal(Param);
4252 if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
4253 LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
4254 }
4255 ToFunction->setParams(Parameters);
4256
4257 // We need to complete creation of FunctionProtoTypeLoc manually with setting
4258 // params it refers to.
4259 if (TInfo) {
4260 if (auto ProtoLoc =
4261 TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
4262 for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
4263 ProtoLoc.setParam(I, Parameters[I]);
4264 }
4265 }
4266
4267 // Import the describing template function, if any.
4268 if (FromFT) {
4269 auto ToFTOrErr = import(FromFT);
4270 if (!ToFTOrErr)
4271 return ToFTOrErr.takeError();
4272 }
4273
4274 // Import Ctor initializers.
4275 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4276 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
4277 SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
4278 // Import first, then allocate memory and copy if there was no error.
4279 if (Error Err = ImportContainerChecked(
4280 FromConstructor->inits(), CtorInitializers))
4281 return std::move(Err);
4282 auto **Memory =
4283 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4284 llvm::copy(CtorInitializers, Memory);
4285 auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
4286 ToCtor->setCtorInitializers(Memory);
4287 ToCtor->setNumCtorInitializers(NumInitializers);
4288 }
4289 }
4290
4291 // If it is a template, import all related things.
4292 if (Error Err = ImportTemplateInformation(D, ToFunction))
4293 return std::move(Err);
4294
4295 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
4297 FromCXXMethod))
4298 return std::move(Err);
4299
4301 Error Err = ImportFunctionDeclBody(D, ToFunction);
4302
4303 if (Err)
4304 return std::move(Err);
4305 }
4306
4307 // Import and set the original type in case we used another type.
4308 if (UsedDifferentProtoType) {
4309 if (ExpectedType TyOrErr = import(D->getType()))
4310 ToFunction->setType(*TyOrErr);
4311 else
4312 return TyOrErr.takeError();
4313 if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
4314 ToFunction->setTypeSourceInfo(*TSIOrErr);
4315 else
4316 return TSIOrErr.takeError();
4317 }
4318
4319 // FIXME: Other bits to merge?
4320
4321 addDeclToContexts(D, ToFunction);
4322
4323 // Import the rest of the chain. I.e. import all subsequent declarations.
4324 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4325 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4326 if (!ToRedeclOrErr)
4327 return ToRedeclOrErr.takeError();
4328 }
4329
4330 return ToFunction;
4331}
4332
4336
4340
4344
4348
4353
4355 // Import the major distinguishing characteristics of a variable.
4356 DeclContext *DC, *LexicalDC;
4357 DeclarationName Name;
4358 SourceLocation Loc;
4359 NamedDecl *ToD;
4360 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4361 return std::move(Err);
4362 if (ToD)
4363 return ToD;
4364
4365 // Determine whether we've already imported this field.
4366 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4367 for (auto *FoundDecl : FoundDecls) {
4368 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4369 // For anonymous fields, match up by index.
4370 if (!Name &&
4372 ASTImporter::getFieldIndex(FoundField))
4373 continue;
4374
4375 if (Importer.IsStructurallyEquivalent(D->getType(),
4376 FoundField->getType())) {
4377 Importer.MapImported(D, FoundField);
4378 // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4379 // initializer of a FieldDecl might not had been instantiated in the
4380 // "To" context. However, the "From" context might instantiated that,
4381 // thus we have to merge that.
4382 // Note: `hasInClassInitializer()` is not the same as non-null
4383 // `getInClassInitializer()` value.
4384 if (Expr *FromInitializer = D->getInClassInitializer()) {
4385 if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4386 // Import of the FromInitializer may result in the setting of
4387 // InClassInitializer. If not, set it here.
4388 assert(FoundField->hasInClassInitializer() &&
4389 "Field should have an in-class initializer if it has an "
4390 "expression for it.");
4391 if (!FoundField->getInClassInitializer())
4392 FoundField->setInClassInitializer(*ToInitializerOrErr);
4393 } else {
4394 return ToInitializerOrErr.takeError();
4395 }
4396 }
4397 return FoundField;
4398 }
4399
4400 // FIXME: Why is this case not handled with calling HandleNameConflict?
4401 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4402 << Name << D->getType() << FoundField->getType();
4403 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4404 << FoundField->getType();
4405
4406 return make_error<ASTImportError>(ASTImportError::NameConflict);
4407 }
4408 }
4409
4410 Error Err = Error::success();
4411 auto ToType = importChecked(Err, D->getType());
4412 auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4413 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4414 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4415 if (Err)
4416 return std::move(Err);
4417 const Type *ToCapturedVLAType = nullptr;
4418 if (Error Err = Importer.importInto(
4419 ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4420 return std::move(Err);
4421
4422 FieldDecl *ToField;
4423 if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4424 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4425 ToType, ToTInfo, ToBitWidth, D->isMutable(),
4426 D->getInClassInitStyle()))
4427 return ToField;
4428
4429 ToField->setAccess(D->getAccess());
4430 ToField->setLexicalDeclContext(LexicalDC);
4431 ToField->setImplicit(D->isImplicit());
4432 if (ToCapturedVLAType)
4433 ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4434 LexicalDC->addDeclInternal(ToField);
4435 // Import initializer only after the field was created, it may have recursive
4436 // reference to the field.
4437 auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4438 if (Err)
4439 return std::move(Err);
4440 if (ToInitializer) {
4441 auto *AlreadyImported = ToField->getInClassInitializer();
4442 if (AlreadyImported)
4443 assert(ToInitializer == AlreadyImported &&
4444 "Duplicate import of in-class initializer.");
4445 else
4446 ToField->setInClassInitializer(ToInitializer);
4447 }
4448
4449 return ToField;
4450}
4451
4453 // Import the major distinguishing characteristics of a variable.
4454 DeclContext *DC, *LexicalDC;
4455 DeclarationName Name;
4456 SourceLocation Loc;
4457 NamedDecl *ToD;
4458 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4459 return std::move(Err);
4460 if (ToD)
4461 return ToD;
4462
4463 // Determine whether we've already imported this field.
4464 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4465 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4466 if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4467 // For anonymous indirect fields, match up by index.
4468 if (!Name &&
4470 ASTImporter::getFieldIndex(FoundField))
4471 continue;
4472
4473 if (Importer.IsStructurallyEquivalent(D->getType(),
4474 FoundField->getType(),
4475 !Name.isEmpty())) {
4476 Importer.MapImported(D, FoundField);
4477 return FoundField;
4478 }
4479
4480 // If there are more anonymous fields to check, continue.
4481 if (!Name && I < N-1)
4482 continue;
4483
4484 // FIXME: Why is this case not handled with calling HandleNameConflict?
4485 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4486 << Name << D->getType() << FoundField->getType();
4487 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4488 << FoundField->getType();
4489
4490 return make_error<ASTImportError>(ASTImportError::NameConflict);
4491 }
4492 }
4493
4494 // Import the type.
4495 auto TypeOrErr = import(D->getType());
4496 if (!TypeOrErr)
4497 return TypeOrErr.takeError();
4498
4499 auto **NamedChain =
4500 new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4501
4502 unsigned i = 0;
4503 for (auto *PI : D->chain())
4504 if (Expected<NamedDecl *> ToD = import(PI))
4505 NamedChain[i++] = *ToD;
4506 else
4507 return ToD.takeError();
4508
4509 MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()};
4510 IndirectFieldDecl *ToIndirectField;
4511 if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4512 Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4513 // FIXME here we leak `NamedChain` which is allocated before
4514 return ToIndirectField;
4515
4516 ToIndirectField->setAccess(D->getAccess());
4517 ToIndirectField->setLexicalDeclContext(LexicalDC);
4518 LexicalDC->addDeclInternal(ToIndirectField);
4519 return ToIndirectField;
4520}
4521
4522/// Used as return type of getFriendCountAndPosition.
4524 /// Number of similar looking friends.
4525 unsigned int TotalCount;
4526 /// Index of the specific FriendDecl.
4527 unsigned int IndexOfDecl;
4528};
4529
4530static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4531 FriendDecl *FD2) {
4532 if ((!FD1->getFriendType()) != (!FD2->getFriendType()))
4533 return false;
4534
4535 if (const TypeSourceInfo *TSI = FD1->getFriendType())
4536 return Importer.IsStructurallyEquivalent(
4537 TSI->getType(), FD2->getFriendType()->getType(), /*Complain=*/false);
4538
4539 ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4541 Importer.getToContext().getLangOpts(), FD1->getASTContext(),
4542 FD2->getASTContext(), NonEquivalentDecls,
4544 /* StrictTypeSpelling = */ false, /* Complain = */ false);
4545 return Ctx.IsEquivalent(FD1, FD2);
4546}
4547
4549 FriendDecl *FD) {
4550 unsigned int FriendCount = 0;
4551 UnsignedOrNone FriendPosition = std::nullopt;
4552 const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4553
4554 for (FriendDecl *FoundFriend : RD->friends()) {
4555 if (FoundFriend == FD) {
4556 FriendPosition = FriendCount;
4557 ++FriendCount;
4558 } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4559 ++FriendCount;
4560 }
4561 }
4562
4563 assert(FriendPosition && "Friend decl not found in own parent.");
4564
4565 return {FriendCount, *FriendPosition};
4566}
4567
4569 // Import the major distinguishing characteristics of a declaration.
4570 DeclContext *DC, *LexicalDC;
4571 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4572 return std::move(Err);
4573
4574 // Determine whether we've already imported this decl.
4575 // FriendDecl is not a NamedDecl so we cannot use lookup.
4576 // We try to maintain order and count of redundant friend declarations.
4577 const auto *RD = cast<CXXRecordDecl>(DC);
4578 SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4579 for (FriendDecl *ImportedFriend : RD->friends())
4580 if (IsEquivalentFriend(Importer, D, ImportedFriend))
4581 ImportedEquivalentFriends.push_back(ImportedFriend);
4582
4583 FriendCountAndPosition CountAndPosition =
4584 getFriendCountAndPosition(Importer, D);
4585
4586 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4587 "Class with non-matching friends is imported, ODR check wrong?");
4588 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4589 return Importer.MapImported(
4590 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4591
4592 // Not found. Create it.
4593 // The declarations will be put into order later by ImportDeclContext.
4595 if (NamedDecl *FriendD = D->getFriendDecl()) {
4596 NamedDecl *ToFriendD;
4597 if (Error Err = importInto(ToFriendD, FriendD))
4598 return std::move(Err);
4599
4600 if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4601 !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator)))
4602 ToFriendD->setObjectOfFriendDecl(false);
4603
4604 ToFU = ToFriendD;
4605 } else { // The friend is a type, not a decl.
4606 if (auto TSIOrErr = import(D->getFriendType()))
4607 ToFU = *TSIOrErr;
4608 else
4609 return TSIOrErr.takeError();
4610 }
4611
4612 SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
4613 auto **FromTPLists = D->getTrailingObjects();
4614 for (unsigned I = 0; I < D->NumTPLists; I++) {
4615 if (auto ListOrErr = import(FromTPLists[I]))
4616 ToTPLists[I] = *ListOrErr;
4617 else
4618 return ListOrErr.takeError();
4619 }
4620
4621 auto LocationOrErr = import(D->getLocation());
4622 if (!LocationOrErr)
4623 return LocationOrErr.takeError();
4624 auto FriendLocOrErr = import(D->getFriendLoc());
4625 if (!FriendLocOrErr)
4626 return FriendLocOrErr.takeError();
4627 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4628 if (!EllipsisLocOrErr)
4629 return EllipsisLocOrErr.takeError();
4630
4631 FriendDecl *FrD;
4632 if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4633 *LocationOrErr, ToFU, *FriendLocOrErr,
4634 *EllipsisLocOrErr, ToTPLists))
4635 return FrD;
4636
4637 FrD->setAccess(D->getAccess());
4638 FrD->setLexicalDeclContext(LexicalDC);
4639 LexicalDC->addDeclInternal(FrD);
4640 return FrD;
4641}
4642
4644 // Import the major distinguishing characteristics of an ivar.
4645 DeclContext *DC, *LexicalDC;
4646 DeclarationName Name;
4647 SourceLocation Loc;
4648 NamedDecl *ToD;
4649 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4650 return std::move(Err);
4651 if (ToD)
4652 return ToD;
4653
4654 // Determine whether we've already imported this ivar
4655 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4656 for (auto *FoundDecl : FoundDecls) {
4657 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4658 if (Importer.IsStructurallyEquivalent(D->getType(),
4659 FoundIvar->getType())) {
4660 Importer.MapImported(D, FoundIvar);
4661 return FoundIvar;
4662 }
4663
4664 Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4665 << Name << D->getType() << FoundIvar->getType();
4666 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4667 << FoundIvar->getType();
4668
4669 return make_error<ASTImportError>(ASTImportError::NameConflict);
4670 }
4671 }
4672
4673 Error Err = Error::success();
4674 auto ToType = importChecked(Err, D->getType());
4675 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4676 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4677 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4678 if (Err)
4679 return std::move(Err);
4680
4681 ObjCIvarDecl *ToIvar;
4682 if (GetImportedOrCreateDecl(
4683 ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4684 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4685 ToType, ToTypeSourceInfo,
4686 D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4687 return ToIvar;
4688
4689 ToIvar->setLexicalDeclContext(LexicalDC);
4690 LexicalDC->addDeclInternal(ToIvar);
4691 return ToIvar;
4692}
4693
4695
4697 auto RedeclIt = Redecls.begin();
4698 // Import the first part of the decl chain. I.e. import all previous
4699 // declarations starting from the canonical decl.
4700 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4701 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4702 if (!RedeclOrErr)
4703 return RedeclOrErr.takeError();
4704 }
4705 assert(*RedeclIt == D);
4706
4707 // Import the major distinguishing characteristics of a variable.
4708 DeclContext *DC, *LexicalDC;
4709 DeclarationName Name;
4710 SourceLocation Loc;
4711 NamedDecl *ToD;
4712 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4713 return std::move(Err);
4714 if (ToD)
4715 return ToD;
4716
4717 // Try to find a variable in our own ("to") context with the same name and
4718 // in the same context as the variable we're importing.
4719 VarDecl *FoundByLookup = nullptr;
4720 if (D->isFileVarDecl()) {
4721 SmallVector<NamedDecl *, 4> ConflictingDecls;
4722 unsigned IDNS = Decl::IDNS_Ordinary;
4723 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4724 for (auto *FoundDecl : FoundDecls) {
4725 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4726 continue;
4727
4728 if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4729 if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4730 continue;
4731 if (Importer.IsStructurallyEquivalent(D->getType(),
4732 FoundVar->getType())) {
4733
4734 // The VarDecl in the "From" context has a definition, but in the
4735 // "To" context we already have a definition.
4736 VarDecl *FoundDef = FoundVar->getDefinition();
4737 if (D->isThisDeclarationADefinition() && FoundDef)
4738 // FIXME Check for ODR error if the two definitions have
4739 // different initializers?
4740 return Importer.MapImported(D, FoundDef);
4741
4742 // The VarDecl in the "From" context has an initializer, but in the
4743 // "To" context we already have an initializer.
4744 const VarDecl *FoundDInit = nullptr;
4745 if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4746 // FIXME Diagnose ODR error if the two initializers are different?
4747 return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4748
4749 FoundByLookup = FoundVar;
4750 break;
4751 }
4752
4753 const ArrayType *FoundArray
4754 = Importer.getToContext().getAsArrayType(FoundVar->getType());
4755 const ArrayType *TArray
4756 = Importer.getToContext().getAsArrayType(D->getType());
4757 if (FoundArray && TArray) {
4758 if (isa<IncompleteArrayType>(FoundArray) &&
4759 isa<ConstantArrayType>(TArray)) {
4760 // Import the type.
4761 if (auto TyOrErr = import(D->getType()))
4762 FoundVar->setType(*TyOrErr);
4763 else
4764 return TyOrErr.takeError();
4765
4766 FoundByLookup = FoundVar;
4767 break;
4768 } else if (isa<IncompleteArrayType>(TArray) &&
4769 isa<ConstantArrayType>(FoundArray)) {
4770 FoundByLookup = FoundVar;
4771 break;
4772 }
4773 }
4774
4775 Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4776 << Name << D->getType() << FoundVar->getType();
4777 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4778 << FoundVar->getType();
4779 ConflictingDecls.push_back(FoundDecl);
4780 }
4781 }
4782
4783 if (!ConflictingDecls.empty()) {
4784 ExpectedName NameOrErr = Importer.HandleNameConflict(
4785 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4786 if (NameOrErr)
4787 Name = NameOrErr.get();
4788 else
4789 return NameOrErr.takeError();
4790 }
4791 }
4792
4793 Error Err = Error::success();
4794 auto ToType = importChecked(Err, D->getType());
4795 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4796 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4797 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4798 if (Err)
4799 return std::move(Err);
4800
4801 VarDecl *ToVar;
4802 if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4803 SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4804 if (Error Err =
4805 ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4806 return std::move(Err);
4807 DecompositionDecl *ToDecomp;
4808 if (GetImportedOrCreateDecl(
4809 ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4810 Loc, ToType, ToTypeSourceInfo, D->getStorageClass(), Bindings))
4811 return ToDecomp;
4812 ToVar = ToDecomp;
4813 } else {
4814 // Create the imported variable.
4815 if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4816 ToInnerLocStart, Loc,
4817 Name.getAsIdentifierInfo(), ToType,
4818 ToTypeSourceInfo, D->getStorageClass()))
4819 return ToVar;
4820 }
4821
4822 ToVar->setTSCSpec(D->getTSCSpec());
4823 ToVar->setQualifierInfo(ToQualifierLoc);
4824 ToVar->setAccess(D->getAccess());
4825 ToVar->setLexicalDeclContext(LexicalDC);
4826 if (D->isInlineSpecified())
4827 ToVar->setInlineSpecified();
4828 if (D->isInline())
4829 ToVar->setImplicitlyInline();
4830
4831 if (FoundByLookup) {
4832 auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4833 ToVar->setPreviousDecl(Recent);
4834 }
4835
4836 // Import the described template, if any.
4837 if (D->getDescribedVarTemplate()) {
4838 auto ToVTOrErr = import(D->getDescribedVarTemplate());
4839 if (!ToVTOrErr)
4840 return ToVTOrErr.takeError();
4842 TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4844 if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4845 ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4846 else
4847 return ToInstOrErr.takeError();
4848 if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4850 else
4851 return POIOrErr.takeError();
4852 }
4853
4854 if (Error Err = ImportInitializer(D, ToVar))
4855 return std::move(Err);
4856
4857 if (D->isConstexpr())
4858 ToVar->setConstexpr(true);
4859
4860 addDeclToContexts(D, ToVar);
4861
4862 // Import the rest of the chain. I.e. import all subsequent declarations.
4863 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4864 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4865 if (!RedeclOrErr)
4866 return RedeclOrErr.takeError();
4867 }
4868
4869 return ToVar;
4870}
4871
4873 // Parameters are created in the translation unit's context, then moved
4874 // into the function declaration's context afterward.
4875 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4876
4877 Error Err = Error::success();
4878 auto ToDeclName = importChecked(Err, D->getDeclName());
4879 auto ToLocation = importChecked(Err, D->getLocation());
4880 auto ToType = importChecked(Err, D->getType());
4881 if (Err)
4882 return std::move(Err);
4883
4884 // Create the imported parameter.
4885 ImplicitParamDecl *ToParm = nullptr;
4886 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4887 ToLocation, ToDeclName.getAsIdentifierInfo(),
4888 ToType, D->getParameterKind()))
4889 return ToParm;
4890 return ToParm;
4891}
4892
4894 const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4895
4896 if (auto LocOrErr = import(FromParam->getExplicitObjectParamThisLoc()))
4897 ToParam->setExplicitObjectParameterLoc(*LocOrErr);
4898 else
4899 return LocOrErr.takeError();
4900
4902 ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4903
4904 if (FromParam->hasUninstantiatedDefaultArg()) {
4905 if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4906 ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4907 else
4908 return ToDefArgOrErr.takeError();
4909 } else if (FromParam->hasUnparsedDefaultArg()) {
4910 ToParam->setUnparsedDefaultArg();
4911 } else if (FromParam->hasDefaultArg()) {
4912 if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4913 ToParam->setDefaultArg(*ToDefArgOrErr);
4914 else
4915 return ToDefArgOrErr.takeError();
4916 }
4917
4918 return Error::success();
4919}
4920
4923 Error Err = Error::success();
4924 CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4925 ConstructorUsingShadowDecl *ToShadow =
4926 importChecked(Err, From.getShadowDecl());
4927 if (Err)
4928 return std::move(Err);
4929 return InheritedConstructor(ToShadow, ToBaseCtor);
4930}
4931
4933 // Parameters are created in the translation unit's context, then moved
4934 // into the function declaration's context afterward.
4935 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4936
4937 Error Err = Error::success();
4938 auto ToDeclName = importChecked(Err, D->getDeclName());
4939 auto ToLocation = importChecked(Err, D->getLocation());
4940 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4941 auto ToType = importChecked(Err, D->getType());
4942 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4943 if (Err)
4944 return std::move(Err);
4945
4946 ParmVarDecl *ToParm;
4947 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4948 ToInnerLocStart, ToLocation,
4949 ToDeclName.getAsIdentifierInfo(), ToType,
4950 ToTypeSourceInfo, D->getStorageClass(),
4951 /*DefaultArg*/ nullptr))
4952 return ToParm;
4953
4954 // Set the default argument. It should be no problem if it was already done.
4955 // Do not import the default expression before GetImportedOrCreateDecl call
4956 // to avoid possible infinite import loop because circular dependency.
4957 if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4958 return std::move(Err);
4959
4960 if (D->isObjCMethodParameter()) {
4963 } else {
4966 }
4967
4968 return ToParm;
4969}
4970
4972 // Import the major distinguishing characteristics of a method.
4973 DeclContext *DC, *LexicalDC;
4974 DeclarationName Name;
4975 SourceLocation Loc;
4976 NamedDecl *ToD;
4977 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4978 return std::move(Err);
4979 if (ToD)
4980 return ToD;
4981
4982 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4983 for (auto *FoundDecl : FoundDecls) {
4984 if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
4985 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
4986 continue;
4987
4988 // Check return types.
4989 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
4990 FoundMethod->getReturnType())) {
4991 Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
4992 << D->isInstanceMethod() << Name << D->getReturnType()
4993 << FoundMethod->getReturnType();
4994 Importer.ToDiag(FoundMethod->getLocation(),
4995 diag::note_odr_objc_method_here)
4996 << D->isInstanceMethod() << Name;
4997
4998 return make_error<ASTImportError>(ASTImportError::NameConflict);
4999 }
5000
5001 // Check the number of parameters.
5002 if (D->param_size() != FoundMethod->param_size()) {
5003 Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
5004 << D->isInstanceMethod() << Name
5005 << D->param_size() << FoundMethod->param_size();
5006 Importer.ToDiag(FoundMethod->getLocation(),
5007 diag::note_odr_objc_method_here)
5008 << D->isInstanceMethod() << Name;
5009
5010 return make_error<ASTImportError>(ASTImportError::NameConflict);
5011 }
5012
5013 // Check parameter types.
5015 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
5016 P != PEnd; ++P, ++FoundP) {
5017 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
5018 (*FoundP)->getType())) {
5019 Importer.FromDiag((*P)->getLocation(),
5020 diag::warn_odr_objc_method_param_type_inconsistent)
5021 << D->isInstanceMethod() << Name
5022 << (*P)->getType() << (*FoundP)->getType();
5023 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
5024 << (*FoundP)->getType();
5025
5026 return make_error<ASTImportError>(ASTImportError::NameConflict);
5027 }
5028 }
5029
5030 // Check variadic/non-variadic.
5031 // Check the number of parameters.
5032 if (D->isVariadic() != FoundMethod->isVariadic()) {
5033 Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
5034 << D->isInstanceMethod() << Name;
5035 Importer.ToDiag(FoundMethod->getLocation(),
5036 diag::note_odr_objc_method_here)
5037 << D->isInstanceMethod() << Name;
5038
5039 return make_error<ASTImportError>(ASTImportError::NameConflict);
5040 }
5041
5042 // FIXME: Any other bits we need to merge?
5043 return Importer.MapImported(D, FoundMethod);
5044 }
5045 }
5046
5047 Error Err = Error::success();
5048 auto ToEndLoc = importChecked(Err, D->getEndLoc());
5049 auto ToReturnType = importChecked(Err, D->getReturnType());
5050 auto ToReturnTypeSourceInfo =
5052 if (Err)
5053 return std::move(Err);
5054
5055 ObjCMethodDecl *ToMethod;
5056 if (GetImportedOrCreateDecl(
5057 ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
5058 Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
5062 return ToMethod;
5063
5064 // FIXME: When we decide to merge method definitions, we'll need to
5065 // deal with implicit parameters.
5066
5067 // Import the parameters
5069 for (auto *FromP : D->parameters()) {
5070 if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
5071 ToParams.push_back(*ToPOrErr);
5072 else
5073 return ToPOrErr.takeError();
5074 }
5075
5076 // Set the parameters.
5077 for (auto *ToParam : ToParams) {
5078 ToParam->setOwningFunction(ToMethod);
5079 ToMethod->addDeclInternal(ToParam);
5080 }
5081
5083 D->getSelectorLocs(FromSelLocs);
5084 SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
5085 if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
5086 return std::move(Err);
5087
5088 ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
5089
5090 ToMethod->setLexicalDeclContext(LexicalDC);
5091 LexicalDC->addDeclInternal(ToMethod);
5092
5093 // Implicit params are declared when Sema encounters the definition but this
5094 // never happens when the method is imported. Manually declare the implicit
5095 // params now that the MethodDecl knows its class interface.
5096 if (D->getSelfDecl())
5097 ToMethod->createImplicitParams(Importer.getToContext(),
5098 ToMethod->getClassInterface());
5099
5100 return ToMethod;
5101}
5102
5104 // Import the major distinguishing characteristics of a category.
5105 DeclContext *DC, *LexicalDC;
5106 DeclarationName Name;
5107 SourceLocation Loc;
5108 NamedDecl *ToD;
5109 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5110 return std::move(Err);
5111 if (ToD)
5112 return ToD;
5113
5114 Error Err = Error::success();
5115 auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
5116 auto ToLocation = importChecked(Err, D->getLocation());
5117 auto ToColonLoc = importChecked(Err, D->getColonLoc());
5118 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5119 if (Err)
5120 return std::move(Err);
5121
5123 if (GetImportedOrCreateDecl(
5124 Result, D, Importer.getToContext(), DC, D->getVariance(),
5125 ToVarianceLoc, D->getIndex(),
5126 ToLocation, Name.getAsIdentifierInfo(),
5127 ToColonLoc, ToTypeSourceInfo))
5128 return Result;
5129
5130 // Only import 'ObjCTypeParamType' after the decl is created.
5131 auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
5132 if (Err)
5133 return std::move(Err);
5134 Result->setTypeForDecl(ToTypeForDecl);
5135 Result->setLexicalDeclContext(LexicalDC);
5136 return Result;
5137}
5138
5140 // Import the major distinguishing characteristics of a category.
5141 DeclContext *DC, *LexicalDC;
5142 DeclarationName Name;
5143 SourceLocation Loc;
5144 NamedDecl *ToD;
5145 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5146 return std::move(Err);
5147 if (ToD)
5148 return ToD;
5149
5150 ObjCInterfaceDecl *ToInterface;
5151 if (Error Err = importInto(ToInterface, D->getClassInterface()))
5152 return std::move(Err);
5153
5154 // Determine if we've already encountered this category.
5155 ObjCCategoryDecl *MergeWithCategory
5156 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
5157 ObjCCategoryDecl *ToCategory = MergeWithCategory;
5158 if (!ToCategory) {
5159
5160 Error Err = Error::success();
5161 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5162 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5163 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5164 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5165 if (Err)
5166 return std::move(Err);
5167
5168 if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
5169 ToAtStartLoc, Loc,
5170 ToCategoryNameLoc,
5171 Name.getAsIdentifierInfo(), ToInterface,
5172 /*TypeParamList=*/nullptr,
5173 ToIvarLBraceLoc,
5174 ToIvarRBraceLoc))
5175 return ToCategory;
5176
5177 ToCategory->setLexicalDeclContext(LexicalDC);
5178 LexicalDC->addDeclInternal(ToCategory);
5179 // Import the type parameter list after MapImported, to avoid
5180 // loops when bringing in their DeclContext.
5181 if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
5182 ToCategory->setTypeParamList(*PListOrErr);
5183 else
5184 return PListOrErr.takeError();
5185
5186 // Import protocols
5188 SmallVector<SourceLocation, 4> ProtocolLocs;
5190 = D->protocol_loc_begin();
5192 FromProtoEnd = D->protocol_end();
5193 FromProto != FromProtoEnd;
5194 ++FromProto, ++FromProtoLoc) {
5195 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5196 Protocols.push_back(*ToProtoOrErr);
5197 else
5198 return ToProtoOrErr.takeError();
5199
5200 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5201 ProtocolLocs.push_back(*ToProtoLocOrErr);
5202 else
5203 return ToProtoLocOrErr.takeError();
5204 }
5205
5206 // FIXME: If we're merging, make sure that the protocol list is the same.
5207 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
5208 ProtocolLocs.data(), Importer.getToContext());
5209
5210 } else {
5211 Importer.MapImported(D, ToCategory);
5212 }
5213
5214 // Import all of the members of this category.
5215 if (Error Err = ImportDeclContext(D))
5216 return std::move(Err);
5217
5218 // If we have an implementation, import it as well.
5219 if (D->getImplementation()) {
5220 if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
5221 import(D->getImplementation()))
5222 ToCategory->setImplementation(*ToImplOrErr);
5223 else
5224 return ToImplOrErr.takeError();
5225 }
5226
5227 return ToCategory;
5228}
5229
5232 if (To->getDefinition()) {
5234 if (Error Err = ImportDeclContext(From))
5235 return Err;
5236 return Error::success();
5237 }
5238
5239 // Start the protocol definition
5240 To->startDefinition();
5241
5242 // Import protocols
5244 SmallVector<SourceLocation, 4> ProtocolLocs;
5246 From->protocol_loc_begin();
5247 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
5248 FromProtoEnd = From->protocol_end();
5249 FromProto != FromProtoEnd;
5250 ++FromProto, ++FromProtoLoc) {
5251 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5252 Protocols.push_back(*ToProtoOrErr);
5253 else
5254 return ToProtoOrErr.takeError();
5255
5256 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5257 ProtocolLocs.push_back(*ToProtoLocOrErr);
5258 else
5259 return ToProtoLocOrErr.takeError();
5260
5261 }
5262
5263 // FIXME: If we're merging, make sure that the protocol list is the same.
5264 To->setProtocolList(Protocols.data(), Protocols.size(),
5265 ProtocolLocs.data(), Importer.getToContext());
5266
5267 if (shouldForceImportDeclContext(Kind)) {
5268 // Import all of the members of this protocol.
5269 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5270 return Err;
5271 }
5272 return Error::success();
5273}
5274
5276 // If this protocol has a definition in the translation unit we're coming
5277 // from, but this particular declaration is not that definition, import the
5278 // definition and map to that.
5280 if (Definition && Definition != D) {
5281 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5282 return Importer.MapImported(D, *ImportedDefOrErr);
5283 else
5284 return ImportedDefOrErr.takeError();
5285 }
5286
5287 // Import the major distinguishing characteristics of a protocol.
5288 DeclContext *DC, *LexicalDC;
5289 DeclarationName Name;
5290 SourceLocation Loc;
5291 NamedDecl *ToD;
5292 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5293 return std::move(Err);
5294 if (ToD)
5295 return ToD;
5296
5297 ObjCProtocolDecl *MergeWithProtocol = nullptr;
5298 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5299 for (auto *FoundDecl : FoundDecls) {
5300 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol))
5301 continue;
5302
5303 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
5304 break;
5305 }
5306
5307 ObjCProtocolDecl *ToProto = MergeWithProtocol;
5308 if (!ToProto) {
5309 auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
5310 if (!ToAtBeginLocOrErr)
5311 return ToAtBeginLocOrErr.takeError();
5312
5313 if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
5314 Name.getAsIdentifierInfo(), Loc,
5315 *ToAtBeginLocOrErr,
5316 /*PrevDecl=*/nullptr))
5317 return ToProto;
5318 ToProto->setLexicalDeclContext(LexicalDC);
5319 LexicalDC->addDeclInternal(ToProto);
5320 }
5321
5322 Importer.MapImported(D, ToProto);
5323
5325 if (Error Err = ImportDefinition(D, ToProto))
5326 return std::move(Err);
5327
5328 return ToProto;
5329}
5330
5332 DeclContext *DC, *LexicalDC;
5333 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5334 return std::move(Err);
5335
5336 ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5337 if (!ExternLocOrErr)
5338 return ExternLocOrErr.takeError();
5339
5340 ExpectedSLoc LangLocOrErr = import(D->getLocation());
5341 if (!LangLocOrErr)
5342 return LangLocOrErr.takeError();
5343
5344 bool HasBraces = D->hasBraces();
5345
5346 LinkageSpecDecl *ToLinkageSpec;
5347 if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5348 *ExternLocOrErr, *LangLocOrErr,
5349 D->getLanguage(), HasBraces))
5350 return ToLinkageSpec;
5351
5352 if (HasBraces) {
5353 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5354 if (!RBraceLocOrErr)
5355 return RBraceLocOrErr.takeError();
5356 ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5357 }
5358
5359 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5360 LexicalDC->addDeclInternal(ToLinkageSpec);
5361
5362 return ToLinkageSpec;
5363}
5364
5366 BaseUsingDecl *ToSI) {
5367 for (UsingShadowDecl *FromShadow : D->shadows()) {
5368 if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5369 ToSI->addShadowDecl(*ToShadowOrErr);
5370 else
5371 // FIXME: We return error here but the definition is already created
5372 // and available with lookups. How to fix this?..
5373 return ToShadowOrErr.takeError();
5374 }
5375 return ToSI;
5376}
5377
5379 DeclContext *DC, *LexicalDC;
5380 DeclarationName Name;
5381 SourceLocation Loc;
5382 NamedDecl *ToD = nullptr;
5383 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5384 return std::move(Err);
5385 if (ToD)
5386 return ToD;
5387
5388 Error Err = Error::success();
5389 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5390 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5391 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5392 if (Err)
5393 return std::move(Err);
5394
5395 DeclarationNameInfo NameInfo(Name, ToLoc);
5396 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5397 return std::move(Err);
5398
5399 UsingDecl *ToUsing;
5400 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5401 ToUsingLoc, ToQualifierLoc, NameInfo,
5402 D->hasTypename()))
5403 return ToUsing;
5404
5405 ToUsing->setLexicalDeclContext(LexicalDC);
5406 LexicalDC->addDeclInternal(ToUsing);
5407
5408 if (NamedDecl *FromPattern =
5409 Importer.getFromContext().getInstantiatedFromUsingDecl(D)) {
5410 if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5411 Importer.getToContext().setInstantiatedFromUsingDecl(
5412 ToUsing, *ToPatternOrErr);
5413 else
5414 return ToPatternOrErr.takeError();
5415 }
5416
5417 return ImportUsingShadowDecls(D, ToUsing);
5418}
5419
5421 DeclContext *DC, *LexicalDC;
5422 DeclarationName Name;
5423 SourceLocation Loc;
5424 NamedDecl *ToD = nullptr;
5425 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5426 return std::move(Err);
5427 if (ToD)
5428 return ToD;
5429
5430 Error Err = Error::success();
5431 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5432 auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5433 auto ToNameLoc = importChecked(Err, D->getLocation());
5434 auto *ToEnumType = importChecked(Err, D->getEnumType());
5435 if (Err)
5436 return std::move(Err);
5437
5438 UsingEnumDecl *ToUsingEnum;
5439 if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5440 ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5441 return ToUsingEnum;
5442
5443 ToUsingEnum->setLexicalDeclContext(LexicalDC);
5444 LexicalDC->addDeclInternal(ToUsingEnum);
5445
5446 if (UsingEnumDecl *FromPattern =
5447 Importer.getFromContext().getInstantiatedFromUsingEnumDecl(D)) {
5448 if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5449 Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5450 *ToPatternOrErr);
5451 else
5452 return ToPatternOrErr.takeError();
5453 }
5454
5455 return ImportUsingShadowDecls(D, ToUsingEnum);
5456}
5457
5459 DeclContext *DC, *LexicalDC;
5460 DeclarationName Name;
5461 SourceLocation Loc;
5462 NamedDecl *ToD = nullptr;
5463 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5464 return std::move(Err);
5465 if (ToD)
5466 return ToD;
5467
5468 Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5469 if (!ToIntroducerOrErr)
5470 return ToIntroducerOrErr.takeError();
5471
5472 Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5473 if (!ToTargetOrErr)
5474 return ToTargetOrErr.takeError();
5475
5476 UsingShadowDecl *ToShadow;
5477 if (auto *FromConstructorUsingShadow =
5478 dyn_cast<ConstructorUsingShadowDecl>(D)) {
5479 Error Err = Error::success();
5481 Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5482 if (Err)
5483 return std::move(Err);
5484 // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5485 // is really the "NominatedBaseClassShadowDecl" value if it exists
5486 // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5487 // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5488 // get the correct values.
5489 if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5490 ToShadow, D, Importer.getToContext(), DC, Loc,
5491 cast<UsingDecl>(*ToIntroducerOrErr),
5492 Nominated ? Nominated : *ToTargetOrErr,
5493 FromConstructorUsingShadow->constructsVirtualBase()))
5494 return ToShadow;
5495 } else {
5496 if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5497 Name, *ToIntroducerOrErr, *ToTargetOrErr))
5498 return ToShadow;
5499 }
5500
5501 ToShadow->setLexicalDeclContext(LexicalDC);
5502 ToShadow->setAccess(D->getAccess());
5503
5504 if (UsingShadowDecl *FromPattern =
5505 Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) {
5506 if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5507 Importer.getToContext().setInstantiatedFromUsingShadowDecl(
5508 ToShadow, *ToPatternOrErr);
5509 else
5510 // FIXME: We return error here but the definition is already created
5511 // and available with lookups. How to fix this?..
5512 return ToPatternOrErr.takeError();
5513 }
5514
5515 LexicalDC->addDeclInternal(ToShadow);
5516
5517 return ToShadow;
5518}
5519
5521 DeclContext *DC, *LexicalDC;
5522 DeclarationName Name;
5523 SourceLocation Loc;
5524 NamedDecl *ToD = nullptr;
5525 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5526 return std::move(Err);
5527 if (ToD)
5528 return ToD;
5529
5530 auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5531 if (!ToComAncestorOrErr)
5532 return ToComAncestorOrErr.takeError();
5533
5534 Error Err = Error::success();
5535 auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5536 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5537 auto ToNamespaceKeyLocation =
5539 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5540 auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5541 if (Err)
5542 return std::move(Err);
5543
5544 UsingDirectiveDecl *ToUsingDir;
5545 if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5546 ToUsingLoc,
5547 ToNamespaceKeyLocation,
5548 ToQualifierLoc,
5549 ToIdentLocation,
5550 ToNominatedNamespace, *ToComAncestorOrErr))
5551 return ToUsingDir;
5552
5553 ToUsingDir->setLexicalDeclContext(LexicalDC);
5554 LexicalDC->addDeclInternal(ToUsingDir);
5555
5556 return ToUsingDir;
5557}
5558
5560 DeclContext *DC, *LexicalDC;
5561 DeclarationName Name;
5562 SourceLocation Loc;
5563 NamedDecl *ToD = nullptr;
5564 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5565 return std::move(Err);
5566 if (ToD)
5567 return ToD;
5568
5569 auto ToInstantiatedFromUsingOrErr =
5570 Importer.Import(D->getInstantiatedFromUsingDecl());
5571 if (!ToInstantiatedFromUsingOrErr)
5572 return ToInstantiatedFromUsingOrErr.takeError();
5573 SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5574 if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5575 return std::move(Err);
5576
5577 UsingPackDecl *ToUsingPack;
5578 if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5579 cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5580 Expansions))
5581 return ToUsingPack;
5582
5583 addDeclToContexts(D, ToUsingPack);
5584
5585 return ToUsingPack;
5586}
5587
5590 DeclContext *DC, *LexicalDC;
5591 DeclarationName Name;
5592 SourceLocation Loc;
5593 NamedDecl *ToD = nullptr;
5594 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5595 return std::move(Err);
5596 if (ToD)
5597 return ToD;
5598
5599 Error Err = Error::success();
5600 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5601 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5602 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5603 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5604 if (Err)
5605 return std::move(Err);
5606
5607 DeclarationNameInfo NameInfo(Name, ToLoc);
5608 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5609 return std::move(Err);
5610
5611 UnresolvedUsingValueDecl *ToUsingValue;
5612 if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5613 ToUsingLoc, ToQualifierLoc, NameInfo,
5614 ToEllipsisLoc))
5615 return ToUsingValue;
5616
5617 ToUsingValue->setAccess(D->getAccess());
5618 ToUsingValue->setLexicalDeclContext(LexicalDC);
5619 LexicalDC->addDeclInternal(ToUsingValue);
5620
5621 return ToUsingValue;
5622}
5623
5626 DeclContext *DC, *LexicalDC;
5627 DeclarationName Name;
5628 SourceLocation Loc;
5629 NamedDecl *ToD = nullptr;
5630 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5631 return std::move(Err);
5632 if (ToD)
5633 return ToD;
5634
5635 Error Err = Error::success();
5636 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5637 auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5638 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5639 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5640 if (Err)
5641 return std::move(Err);
5642
5644 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5645 ToUsingLoc, ToTypenameLoc,
5646 ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5647 return ToUsing;
5648
5649 ToUsing->setAccess(D->getAccess());
5650 ToUsing->setLexicalDeclContext(LexicalDC);
5651 LexicalDC->addDeclInternal(ToUsing);
5652
5653 return ToUsing;
5654}
5655
5657 Decl* ToD = nullptr;
5658 switch (D->getBuiltinTemplateKind()) {
5659#define BuiltinTemplate(BTName) \
5660 case BuiltinTemplateKind::BTK##BTName: \
5661 ToD = Importer.getToContext().get##BTName##Decl(); \
5662 break;
5663#include "clang/Basic/BuiltinTemplates.inc"
5664 }
5665 assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5666 Importer.MapImported(D, ToD);
5667 return ToD;
5668}
5669
5672 if (To->getDefinition()) {
5673 // Check consistency of superclass.
5674 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5675 if (FromSuper) {
5676 if (auto FromSuperOrErr = import(FromSuper))
5677 FromSuper = *FromSuperOrErr;
5678 else
5679 return FromSuperOrErr.takeError();
5680 }
5681
5682 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5683 if ((bool)FromSuper != (bool)ToSuper ||
5684 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5685 Importer.ToDiag(To->getLocation(),
5686 diag::warn_odr_objc_superclass_inconsistent)
5687 << To->getDeclName();
5688 if (ToSuper)
5689 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5690 << To->getSuperClass()->getDeclName();
5691 else
5692 Importer.ToDiag(To->getLocation(),
5693 diag::note_odr_objc_missing_superclass);
5694 if (From->getSuperClass())
5695 Importer.FromDiag(From->getSuperClassLoc(),
5696 diag::note_odr_objc_superclass)
5697 << From->getSuperClass()->getDeclName();
5698 else
5699 Importer.FromDiag(From->getLocation(),
5700 diag::note_odr_objc_missing_superclass);
5701 }
5702
5704 if (Error Err = ImportDeclContext(From))
5705 return Err;
5706 return Error::success();
5707 }
5708
5709 // Start the definition.
5710 To->startDefinition();
5711
5712 // If this class has a superclass, import it.
5713 if (From->getSuperClass()) {
5714 if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5715 To->setSuperClass(*SuperTInfoOrErr);
5716 else
5717 return SuperTInfoOrErr.takeError();
5718 }
5719
5720 // Import protocols
5722 SmallVector<SourceLocation, 4> ProtocolLocs;
5724 From->protocol_loc_begin();
5725
5727 FromProtoEnd = From->protocol_end();
5728 FromProto != FromProtoEnd;
5729 ++FromProto, ++FromProtoLoc) {
5730 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5731 Protocols.push_back(*ToProtoOrErr);
5732 else
5733 return ToProtoOrErr.takeError();
5734
5735 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5736 ProtocolLocs.push_back(*ToProtoLocOrErr);
5737 else
5738 return ToProtoLocOrErr.takeError();
5739
5740 }
5741
5742 // FIXME: If we're merging, make sure that the protocol list is the same.
5743 To->setProtocolList(Protocols.data(), Protocols.size(),
5744 ProtocolLocs.data(), Importer.getToContext());
5745
5746 // Import categories. When the categories themselves are imported, they'll
5747 // hook themselves into this interface.
5748 for (auto *Cat : From->known_categories()) {
5749 auto ToCatOrErr = import(Cat);
5750 if (!ToCatOrErr)
5751 return ToCatOrErr.takeError();
5752 }
5753
5754 // If we have an @implementation, import it as well.
5755 if (From->getImplementation()) {
5756 if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5757 import(From->getImplementation()))
5758 To->setImplementation(*ToImplOrErr);
5759 else
5760 return ToImplOrErr.takeError();
5761 }
5762
5763 // Import all of the members of this class.
5764 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5765 return Err;
5766
5767 return Error::success();
5768}
5769
5772 if (!list)
5773 return nullptr;
5774
5776 for (auto *fromTypeParam : *list) {
5777 if (auto toTypeParamOrErr = import(fromTypeParam))
5778 toTypeParams.push_back(*toTypeParamOrErr);
5779 else
5780 return toTypeParamOrErr.takeError();
5781 }
5782
5783 auto LAngleLocOrErr = import(list->getLAngleLoc());
5784 if (!LAngleLocOrErr)
5785 return LAngleLocOrErr.takeError();
5786
5787 auto RAngleLocOrErr = import(list->getRAngleLoc());
5788 if (!RAngleLocOrErr)
5789 return RAngleLocOrErr.takeError();
5790
5791 return ObjCTypeParamList::create(Importer.getToContext(),
5792 *LAngleLocOrErr,
5793 toTypeParams,
5794 *RAngleLocOrErr);
5795}
5796
5798 // If this class has a definition in the translation unit we're coming from,
5799 // but this particular declaration is not that definition, import the
5800 // definition and map to that.
5802 if (Definition && Definition != D) {
5803 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5804 return Importer.MapImported(D, *ImportedDefOrErr);
5805 else
5806 return ImportedDefOrErr.takeError();
5807 }
5808
5809 // Import the major distinguishing characteristics of an @interface.
5810 DeclContext *DC, *LexicalDC;
5811 DeclarationName Name;
5812 SourceLocation Loc;
5813 NamedDecl *ToD;
5814 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5815 return std::move(Err);
5816 if (ToD)
5817 return ToD;
5818
5819 // Look for an existing interface with the same name.
5820 ObjCInterfaceDecl *MergeWithIface = nullptr;
5821 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5822 for (auto *FoundDecl : FoundDecls) {
5823 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
5824 continue;
5825
5826 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5827 break;
5828 }
5829
5830 // Create an interface declaration, if one does not already exist.
5831 ObjCInterfaceDecl *ToIface = MergeWithIface;
5832 if (!ToIface) {
5833 ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5834 if (!AtBeginLocOrErr)
5835 return AtBeginLocOrErr.takeError();
5836
5837 if (GetImportedOrCreateDecl(
5838 ToIface, D, Importer.getToContext(), DC,
5839 *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5840 /*TypeParamList=*/nullptr,
5841 /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5842 return ToIface;
5843 ToIface->setLexicalDeclContext(LexicalDC);
5844 LexicalDC->addDeclInternal(ToIface);
5845 }
5846 Importer.MapImported(D, ToIface);
5847 // Import the type parameter list after MapImported, to avoid
5848 // loops when bringing in their DeclContext.
5849 if (auto ToPListOrErr =
5851 ToIface->setTypeParamList(*ToPListOrErr);
5852 else
5853 return ToPListOrErr.takeError();
5854
5856 if (Error Err = ImportDefinition(D, ToIface))
5857 return std::move(Err);
5858
5859 return ToIface;
5860}
5861
5864 ObjCCategoryDecl *Category;
5865 if (Error Err = importInto(Category, D->getCategoryDecl()))
5866 return std::move(Err);
5867
5868 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5869 if (!ToImpl) {
5870 DeclContext *DC, *LexicalDC;
5871 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5872 return std::move(Err);
5873
5874 Error Err = Error::success();
5875 auto ToLocation = importChecked(Err, D->getLocation());
5876 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5877 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5878 if (Err)
5879 return std::move(Err);
5880
5881 if (GetImportedOrCreateDecl(
5882 ToImpl, D, Importer.getToContext(), DC,
5883 Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5884 ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5885 return ToImpl;
5886
5887 ToImpl->setLexicalDeclContext(LexicalDC);
5888 LexicalDC->addDeclInternal(ToImpl);
5889 Category->setImplementation(ToImpl);
5890 }
5891
5892 Importer.MapImported(D, ToImpl);
5893 if (Error Err = ImportDeclContext(D))
5894 return std::move(Err);
5895
5896 return ToImpl;
5897}
5898
5901 // Find the corresponding interface.
5902 ObjCInterfaceDecl *Iface;
5903 if (Error Err = importInto(Iface, D->getClassInterface()))
5904 return std::move(Err);
5905
5906 // Import the superclass, if any.
5907 ObjCInterfaceDecl *Super;
5908 if (Error Err = importInto(Super, D->getSuperClass()))
5909 return std::move(Err);
5910
5912 if (!Impl) {
5913 // We haven't imported an implementation yet. Create a new @implementation
5914 // now.
5915 DeclContext *DC, *LexicalDC;
5916 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5917 return std::move(Err);
5918
5919 Error Err = Error::success();
5920 auto ToLocation = importChecked(Err, D->getLocation());
5921 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5922 auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5923 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5924 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5925 if (Err)
5926 return std::move(Err);
5927
5928 if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5929 DC, Iface, Super,
5930 ToLocation,
5931 ToAtStartLoc,
5932 ToSuperClassLoc,
5933 ToIvarLBraceLoc,
5934 ToIvarRBraceLoc))
5935 return Impl;
5936
5937 Impl->setLexicalDeclContext(LexicalDC);
5938
5939 // Associate the implementation with the class it implements.
5940 Iface->setImplementation(Impl);
5941 Importer.MapImported(D, Iface->getImplementation());
5942 } else {
5943 Importer.MapImported(D, Iface->getImplementation());
5944
5945 // Verify that the existing @implementation has the same superclass.
5946 if ((Super && !Impl->getSuperClass()) ||
5947 (!Super && Impl->getSuperClass()) ||
5948 (Super && Impl->getSuperClass() &&
5950 Impl->getSuperClass()))) {
5951 Importer.ToDiag(Impl->getLocation(),
5952 diag::warn_odr_objc_superclass_inconsistent)
5953 << Iface->getDeclName();
5954 // FIXME: It would be nice to have the location of the superclass
5955 // below.
5956 if (Impl->getSuperClass())
5957 Importer.ToDiag(Impl->getLocation(),
5958 diag::note_odr_objc_superclass)
5959 << Impl->getSuperClass()->getDeclName();
5960 else
5961 Importer.ToDiag(Impl->getLocation(),
5962 diag::note_odr_objc_missing_superclass);
5963 if (D->getSuperClass())
5964 Importer.FromDiag(D->getLocation(),
5965 diag::note_odr_objc_superclass)
5966 << D->getSuperClass()->getDeclName();
5967 else
5968 Importer.FromDiag(D->getLocation(),
5969 diag::note_odr_objc_missing_superclass);
5970
5971 return make_error<ASTImportError>(ASTImportError::NameConflict);
5972 }
5973 }
5974
5975 // Import all of the members of this @implementation.
5976 if (Error Err = ImportDeclContext(D))
5977 return std::move(Err);
5978
5979 return Impl;
5980}
5981
5983 // Import the major distinguishing characteristics of an @property.
5984 DeclContext *DC, *LexicalDC;
5985 DeclarationName Name;
5986 SourceLocation Loc;
5987 NamedDecl *ToD;
5988 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5989 return std::move(Err);
5990 if (ToD)
5991 return ToD;
5992
5993 // Check whether we have already imported this property.
5994 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5995 for (auto *FoundDecl : FoundDecls) {
5996 if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
5997 // Instance and class properties can share the same name but are different
5998 // declarations.
5999 if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
6000 continue;
6001
6002 // Check property types.
6003 if (!Importer.IsStructurallyEquivalent(D->getType(),
6004 FoundProp->getType())) {
6005 Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
6006 << Name << D->getType() << FoundProp->getType();
6007 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
6008 << FoundProp->getType();
6009
6010 return make_error<ASTImportError>(ASTImportError::NameConflict);
6011 }
6012
6013 // FIXME: Check property attributes, getters, setters, etc.?
6014
6015 // Consider these properties to be equivalent.
6016 Importer.MapImported(D, FoundProp);
6017 return FoundProp;
6018 }
6019 }
6020
6021 Error Err = Error::success();
6022 auto ToType = importChecked(Err, D->getType());
6023 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6024 auto ToAtLoc = importChecked(Err, D->getAtLoc());
6025 auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
6026 if (Err)
6027 return std::move(Err);
6028
6029 // Create the new property.
6030 ObjCPropertyDecl *ToProperty;
6031 if (GetImportedOrCreateDecl(
6032 ToProperty, D, Importer.getToContext(), DC, Loc,
6033 Name.getAsIdentifierInfo(), ToAtLoc,
6034 ToLParenLoc, ToType,
6035 ToTypeSourceInfo, D->getPropertyImplementation()))
6036 return ToProperty;
6037
6038 auto ToGetterName = importChecked(Err, D->getGetterName());
6039 auto ToSetterName = importChecked(Err, D->getSetterName());
6040 auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
6041 auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
6042 auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
6043 auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
6044 auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
6045 if (Err)
6046 return std::move(Err);
6047
6048 ToProperty->setLexicalDeclContext(LexicalDC);
6049 LexicalDC->addDeclInternal(ToProperty);
6050
6054 ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
6055 ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
6056 ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
6057 ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
6058 ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
6059 return ToProperty;
6060}
6061
6065 if (Error Err = importInto(Property, D->getPropertyDecl()))
6066 return std::move(Err);
6067
6068 DeclContext *DC, *LexicalDC;
6069 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6070 return std::move(Err);
6071
6072 auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
6073
6074 // Import the ivar (for an @synthesize).
6075 ObjCIvarDecl *Ivar = nullptr;
6076 if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
6077 return std::move(Err);
6078
6079 ObjCPropertyImplDecl *ToImpl
6080 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
6081 Property->getQueryKind());
6082 if (!ToImpl) {
6083
6084 Error Err = Error::success();
6085 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
6086 auto ToLocation = importChecked(Err, D->getLocation());
6087 auto ToPropertyIvarDeclLoc =
6089 if (Err)
6090 return std::move(Err);
6091
6092 if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
6093 ToBeginLoc,
6094 ToLocation, Property,
6095 D->getPropertyImplementation(), Ivar,
6096 ToPropertyIvarDeclLoc))
6097 return ToImpl;
6098
6099 ToImpl->setLexicalDeclContext(LexicalDC);
6100 LexicalDC->addDeclInternal(ToImpl);
6101 } else {
6102 // Check that we have the same kind of property implementation (@synthesize
6103 // vs. @dynamic).
6105 Importer.ToDiag(ToImpl->getLocation(),
6106 diag::warn_odr_objc_property_impl_kind_inconsistent)
6107 << Property->getDeclName()
6108 << (ToImpl->getPropertyImplementation()
6110 Importer.FromDiag(D->getLocation(),
6111 diag::note_odr_objc_property_impl_kind)
6112 << D->getPropertyDecl()->getDeclName()
6114
6115 return make_error<ASTImportError>(ASTImportError::NameConflict);
6116 }
6117
6118 // For @synthesize, check that we have the same
6120 Ivar != ToImpl->getPropertyIvarDecl()) {
6121 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
6122 diag::warn_odr_objc_synthesize_ivar_inconsistent)
6123 << Property->getDeclName()
6124 << ToImpl->getPropertyIvarDecl()->getDeclName()
6125 << Ivar->getDeclName();
6126 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
6127 diag::note_odr_objc_synthesize_ivar_here)
6129
6130 return make_error<ASTImportError>(ASTImportError::NameConflict);
6131 }
6132
6133 // Merge the existing implementation with the new implementation.
6134 Importer.MapImported(D, ToImpl);
6135 }
6136
6137 return ToImpl;
6138}
6139
6142 // For template arguments, we adopt the translation unit as our declaration
6143 // context. This context will be fixed when (during) the actual template
6144 // declaration is created.
6145
6146 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6147 if (!BeginLocOrErr)
6148 return BeginLocOrErr.takeError();
6149
6150 ExpectedSLoc LocationOrErr = import(D->getLocation());
6151 if (!LocationOrErr)
6152 return LocationOrErr.takeError();
6153
6154 TemplateTypeParmDecl *ToD = nullptr;
6155 if (GetImportedOrCreateDecl(
6156 ToD, D, Importer.getToContext(),
6157 Importer.getToContext().getTranslationUnitDecl(),
6158 *BeginLocOrErr, *LocationOrErr,
6159 D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
6161 D->hasTypeConstraint()))
6162 return ToD;
6163
6164 // Import the type-constraint
6165 if (const TypeConstraint *TC = D->getTypeConstraint()) {
6166
6167 Error Err = Error::success();
6168 auto ToConceptRef = importChecked(Err, TC->getConceptReference());
6169 auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
6170 if (Err)
6171 return std::move(Err);
6172
6173 ToD->setTypeConstraint(ToConceptRef, ToIDC, TC->getArgPackSubstIndex());
6174 }
6175
6176 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6177 return Err;
6178
6179 return ToD;
6180}
6181
6184
6185 Error Err = Error::success();
6186 auto ToDeclName = importChecked(Err, D->getDeclName());
6187 auto ToLocation = importChecked(Err, D->getLocation());
6188 auto ToType = importChecked(Err, D->getType());
6189 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6190 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
6191 if (Err)
6192 return std::move(Err);
6193
6194 NonTypeTemplateParmDecl *ToD = nullptr;
6195 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
6196 Importer.getToContext().getTranslationUnitDecl(),
6197 ToInnerLocStart, ToLocation, D->getDepth(),
6198 D->getPosition(),
6199 ToDeclName.getAsIdentifierInfo(), ToType,
6200 D->isParameterPack(), ToTypeSourceInfo))
6201 return ToD;
6202
6203 Err = importTemplateParameterDefaultArgument(D, ToD);
6204 if (Err)
6205 return Err;
6206
6207 return ToD;
6208}
6209
6212 bool IsCanonical = false;
6213 if (auto *CanonD = Importer.getFromContext()
6214 .findCanonicalTemplateTemplateParmDeclInternal(D);
6215 CanonD == D)
6216 IsCanonical = true;
6217
6218 // Import the name of this declaration.
6219 auto NameOrErr = import(D->getDeclName());
6220 if (!NameOrErr)
6221 return NameOrErr.takeError();
6222
6223 // Import the location of this declaration.
6224 ExpectedSLoc LocationOrErr = import(D->getLocation());
6225 if (!LocationOrErr)
6226 return LocationOrErr.takeError();
6227
6228 // Import template parameters.
6229 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6230 if (!TemplateParamsOrErr)
6231 return TemplateParamsOrErr.takeError();
6232
6233 TemplateTemplateParmDecl *ToD = nullptr;
6234 if (GetImportedOrCreateDecl(
6235 ToD, D, Importer.getToContext(),
6236 Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
6237 D->getDepth(), D->getPosition(), D->isParameterPack(),
6238 (*NameOrErr).getAsIdentifierInfo(), D->templateParameterKind(),
6239 D->wasDeclaredWithTypename(), *TemplateParamsOrErr))
6240 return ToD;
6241
6242 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6243 return Err;
6244
6245 if (IsCanonical)
6246 return Importer.getToContext()
6247 .insertCanonicalTemplateTemplateParmDeclInternal(ToD);
6248
6249 return ToD;
6250}
6251
6252// Returns the definition for a (forward) declaration of a TemplateDecl, if
6253// it has any definition in the redecl chain.
6254template <typename T> static auto getTemplateDefinition(T *D) -> T * {
6255 assert(D->getTemplatedDecl() && "Should be called on templates only");
6256 auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
6257 if (!ToTemplatedDef)
6258 return nullptr;
6259 auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
6260 return cast_or_null<T>(TemplateWithDef);
6261}
6262
6264
6265 // Import the major distinguishing characteristics of this class template.
6266 DeclContext *DC, *LexicalDC;
6267 DeclarationName Name;
6268 SourceLocation Loc;
6269 NamedDecl *ToD;
6270 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6271 return std::move(Err);
6272 if (ToD)
6273 return ToD;
6274
6275 // Should check if a declaration is friend in a dependent context.
6276 // Such templates are not linked together in a declaration chain.
6277 // The ASTImporter strategy is to map existing forward declarations to
6278 // imported ones only if strictly necessary, otherwise import these as new
6279 // forward declarations. In case of the "dependent friend" declarations, new
6280 // declarations are created, but not linked in a declaration chain.
6281 auto IsDependentFriend = [](ClassTemplateDecl *TD) {
6282 return TD->getFriendObjectKind() != Decl::FOK_None &&
6283 TD->getLexicalDeclContext()->isDependentContext();
6284 };
6285 bool DependentFriend = IsDependentFriend(D);
6286
6287 ClassTemplateDecl *FoundByLookup = nullptr;
6288
6289 // We may already have a template of the same name; try to find and match it.
6290 if (!DC->isFunctionOrMethod()) {
6291 SmallVector<NamedDecl *, 4> ConflictingDecls;
6292 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6293 for (auto *FoundDecl : FoundDecls) {
6294 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary |
6296 continue;
6297
6298 auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(FoundDecl);
6299 if (FoundTemplate) {
6300 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6301 continue;
6302
6303 // FIXME: sufficient condition for 'IgnoreTemplateParmDepth'?
6304 bool IgnoreTemplateParmDepth =
6305 (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
6307 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
6308 IgnoreTemplateParmDepth)) {
6309 if (DependentFriend || IsDependentFriend(FoundTemplate))
6310 continue;
6311
6312 ClassTemplateDecl *TemplateWithDef =
6313 getTemplateDefinition(FoundTemplate);
6314 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6315 return Importer.MapImported(D, TemplateWithDef);
6316 if (!FoundByLookup)
6317 FoundByLookup = FoundTemplate;
6318 // Search in all matches because there may be multiple decl chains,
6319 // see ASTTests test ImportExistingFriendClassTemplateDef.
6320 continue;
6321 }
6322 // When importing a friend, it is possible that multiple declarations
6323 // with same name can co-exist in specific cases (if a template contains
6324 // a friend template and has a specialization). For this case the
6325 // declarations should match, except that the "template depth" is
6326 // different. No linking of previous declaration is needed in this case.
6327 // FIXME: This condition may need refinement.
6328 if (D->getFriendObjectKind() != Decl::FOK_None &&
6329 FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
6330 D->getFriendObjectKind() != FoundTemplate->getFriendObjectKind() &&
6331 IsStructuralMatch(D, FoundTemplate, /*Complain=*/false,
6332 /*IgnoreTemplateParmDepth=*/true))
6333 continue;
6334
6335 ConflictingDecls.push_back(FoundDecl);
6336 }
6337 }
6338
6339 if (!ConflictingDecls.empty()) {
6340 ExpectedName NameOrErr = Importer.HandleNameConflict(
6341 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6342 ConflictingDecls.size());
6343 if (NameOrErr)
6344 Name = NameOrErr.get();
6345 else
6346 return NameOrErr.takeError();
6347 }
6348 }
6349
6350 CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6351
6352 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6353 if (!TemplateParamsOrErr)
6354 return TemplateParamsOrErr.takeError();
6355
6356 // Create the declaration that is being templated.
6357 CXXRecordDecl *ToTemplated;
6358 if (Error Err = importInto(ToTemplated, FromTemplated))
6359 return std::move(Err);
6360
6361 // Create the class template declaration itself.
6363 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6364 *TemplateParamsOrErr, ToTemplated))
6365 return D2;
6366
6367 ToTemplated->setDescribedClassTemplate(D2);
6368
6369 D2->setAccess(D->getAccess());
6370 D2->setLexicalDeclContext(LexicalDC);
6371
6372 addDeclToContexts(D, D2);
6373 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6374
6375 if (FoundByLookup) {
6376 auto *Recent =
6377 const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6378
6379 // It is possible that during the import of the class template definition
6380 // we start the import of a fwd friend decl of the very same class template
6381 // and we add the fwd friend decl to the lookup table. But the ToTemplated
6382 // had been created earlier and by that time the lookup could not find
6383 // anything existing, so it has no previous decl. Later, (still during the
6384 // import of the fwd friend decl) we start to import the definition again
6385 // and this time the lookup finds the previous fwd friend class template.
6386 // In this case we must set up the previous decl for the templated decl.
6387 if (!ToTemplated->getPreviousDecl()) {
6388 assert(FoundByLookup->getTemplatedDecl() &&
6389 "Found decl must have its templated decl set");
6390 CXXRecordDecl *PrevTemplated =
6391 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6392 if (ToTemplated != PrevTemplated)
6393 ToTemplated->setPreviousDecl(PrevTemplated);
6394 }
6395
6396 D2->setPreviousDecl(Recent);
6397 }
6398
6399 return D2;
6400}
6401
6404 ClassTemplateDecl *ClassTemplate;
6405 if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6406 return std::move(Err);
6407
6408 // Import the context of this declaration.
6409 DeclContext *DC, *LexicalDC;
6410 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6411 return std::move(Err);
6412
6413 // Import template arguments.
6415 if (Error Err =
6416 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6417 return std::move(Err);
6418 // Try to find an existing specialization with these template arguments and
6419 // template parameter list.
6420 void *InsertPos = nullptr;
6421 ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6423 dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6424
6425 // Import template parameters.
6426 TemplateParameterList *ToTPList = nullptr;
6427
6428 if (PartialSpec) {
6429 auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6430 if (!ToTPListOrErr)
6431 return ToTPListOrErr.takeError();
6432 ToTPList = *ToTPListOrErr;
6433 PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs,
6434 *ToTPListOrErr,
6435 InsertPos);
6436 } else
6437 PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
6438
6439 if (PrevDecl) {
6440 if (IsStructuralMatch(D, PrevDecl)) {
6441 CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6442 if (D->isThisDeclarationADefinition() && PrevDefinition) {
6443 Importer.MapImported(D, PrevDefinition);
6444 // Import those default field initializers which have been
6445 // instantiated in the "From" context, but not in the "To" context.
6446 for (auto *FromField : D->fields()) {
6447 auto ToOrErr = import(FromField);
6448 if (!ToOrErr)
6449 return ToOrErr.takeError();
6450 }
6451
6452 // Import those methods which have been instantiated in the
6453 // "From" context, but not in the "To" context.
6454 for (CXXMethodDecl *FromM : D->methods()) {
6455 auto ToOrErr = import(FromM);
6456 if (!ToOrErr)
6457 return ToOrErr.takeError();
6458 }
6459
6460 // TODO Import instantiated default arguments.
6461 // TODO Import instantiated exception specifications.
6462 //
6463 // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6464 // what else could be fused during an AST merge.
6465 return PrevDefinition;
6466 }
6467 } else { // ODR violation.
6468 // FIXME HandleNameConflict
6469 return make_error<ASTImportError>(ASTImportError::NameConflict);
6470 }
6471 }
6472
6473 // Import the location of this declaration.
6474 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6475 if (!BeginLocOrErr)
6476 return BeginLocOrErr.takeError();
6477 ExpectedSLoc IdLocOrErr = import(D->getLocation());
6478 if (!IdLocOrErr)
6479 return IdLocOrErr.takeError();
6480
6481 // Import TemplateArgumentListInfo.
6482 TemplateArgumentListInfo ToTAInfo;
6483 if (const auto *ASTTemplateArgs = D->getTemplateArgsAsWritten()) {
6484 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
6485 return std::move(Err);
6486 }
6487
6488 // Create the specialization.
6489 ClassTemplateSpecializationDecl *D2 = nullptr;
6490 if (PartialSpec) {
6491 if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6492 D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6493 *IdLocOrErr, ToTPList, ClassTemplate, ArrayRef(TemplateArgs),
6494 /*CanonInjectedTST=*/CanQualType(),
6495 cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6496 return D2;
6497
6498 // Update InsertPos, because preceding import calls may have invalidated
6499 // it by adding new specializations.
6501 if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6502 InsertPos))
6503 // Add this partial specialization to the class template.
6504 ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
6506 import(PartialSpec->getInstantiatedFromMember()))
6507 PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6508 else
6509 return ToInstOrErr.takeError();
6510
6511 updateLookupTableForTemplateParameters(*ToTPList);
6512 } else { // Not a partial specialization.
6513 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), D->getTagKind(),
6514 DC, *BeginLocOrErr, *IdLocOrErr, ClassTemplate,
6515 TemplateArgs, D->hasStrictPackMatch(),
6516 PrevDecl))
6517 return D2;
6518
6519 // Update InsertPos, because preceding import calls may have invalidated
6520 // it by adding new specializations.
6521 if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos))
6522 // Add this specialization to the class template.
6523 ClassTemplate->AddSpecialization(D2, InsertPos);
6524 }
6525
6527
6528 // Set the context of this specialization/instantiation.
6529 D2->setLexicalDeclContext(LexicalDC);
6530
6531 // Add to the DC only if it was an explicit specialization/instantiation.
6533 LexicalDC->addDeclInternal(D2);
6534 }
6535
6536 if (auto BraceRangeOrErr = import(D->getBraceRange()))
6537 D2->setBraceRange(*BraceRangeOrErr);
6538 else
6539 return BraceRangeOrErr.takeError();
6540
6541 if (Error Err = ImportTemplateParameterLists(D, D2))
6542 return std::move(Err);
6543
6544 // Import the qualifier, if any.
6545 if (auto LocOrErr = import(D->getQualifierLoc()))
6546 D2->setQualifierInfo(*LocOrErr);
6547 else
6548 return LocOrErr.takeError();
6549
6550 if (D->getTemplateArgsAsWritten())
6551 D2->setTemplateArgsAsWritten(ToTAInfo);
6552
6553 if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6554 D2->setTemplateKeywordLoc(*LocOrErr);
6555 else
6556 return LocOrErr.takeError();
6557
6558 if (auto LocOrErr = import(D->getExternKeywordLoc()))
6559 D2->setExternKeywordLoc(*LocOrErr);
6560 else
6561 return LocOrErr.takeError();
6562
6563 if (D->getPointOfInstantiation().isValid()) {
6564 if (auto POIOrErr = import(D->getPointOfInstantiation()))
6565 D2->setPointOfInstantiation(*POIOrErr);
6566 else
6567 return POIOrErr.takeError();
6568 }
6569
6571
6572 if (auto P = D->getInstantiatedFrom()) {
6573 if (auto *CTD = dyn_cast<ClassTemplateDecl *>(P)) {
6574 if (auto CTDorErr = import(CTD))
6575 D2->setInstantiationOf(*CTDorErr);
6576 } else {
6578 auto CTPSDOrErr = import(CTPSD);
6579 if (!CTPSDOrErr)
6580 return CTPSDOrErr.takeError();
6582 SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6583 for (unsigned I = 0; I < DArgs.size(); ++I) {
6584 const TemplateArgument &DArg = DArgs[I];
6585 if (auto ArgOrErr = import(DArg))
6586 D2ArgsVec[I] = *ArgOrErr;
6587 else
6588 return ArgOrErr.takeError();
6589 }
6591 *CTPSDOrErr,
6592 TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6593 }
6594 }
6595
6596 if (D->isCompleteDefinition())
6597 if (Error Err = ImportDefinition(D, D2))
6598 return std::move(Err);
6599
6600 return D2;
6601}
6602
6604 // Import the major distinguishing characteristics of this variable template.
6605 DeclContext *DC, *LexicalDC;
6606 DeclarationName Name;
6607 SourceLocation Loc;
6608 NamedDecl *ToD;
6609 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6610 return std::move(Err);
6611 if (ToD)
6612 return ToD;
6613
6614 // We may already have a template of the same name; try to find and match it.
6615 assert(!DC->isFunctionOrMethod() &&
6616 "Variable templates cannot be declared at function scope");
6617
6618 SmallVector<NamedDecl *, 4> ConflictingDecls;
6619 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6620 VarTemplateDecl *FoundByLookup = nullptr;
6621 for (auto *FoundDecl : FoundDecls) {
6622 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
6623 continue;
6624
6625 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6626 // Use the templated decl, some linkage flags are set only there.
6627 if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6628 D->getTemplatedDecl()))
6629 continue;
6630 if (IsStructuralMatch(D, FoundTemplate)) {
6631 // FIXME Check for ODR error if the two definitions have
6632 // different initializers?
6633 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6634 if (D->getDeclContext()->isRecord()) {
6635 assert(FoundTemplate->getDeclContext()->isRecord() &&
6636 "Member variable template imported as non-member, "
6637 "inconsistent imported AST?");
6638 if (FoundDef)
6639 return Importer.MapImported(D, FoundDef);
6641 return Importer.MapImported(D, FoundTemplate);
6642 } else {
6643 if (FoundDef && D->isThisDeclarationADefinition())
6644 return Importer.MapImported(D, FoundDef);
6645 }
6646 FoundByLookup = FoundTemplate;
6647 break;
6648 }
6649 ConflictingDecls.push_back(FoundDecl);
6650 }
6651 }
6652
6653 if (!ConflictingDecls.empty()) {
6654 ExpectedName NameOrErr = Importer.HandleNameConflict(
6655 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6656 ConflictingDecls.size());
6657 if (NameOrErr)
6658 Name = NameOrErr.get();
6659 else
6660 return NameOrErr.takeError();
6661 }
6662
6663 VarDecl *DTemplated = D->getTemplatedDecl();
6664
6665 // Import the type.
6666 // FIXME: Value not used?
6667 ExpectedType TypeOrErr = import(DTemplated->getType());
6668 if (!TypeOrErr)
6669 return TypeOrErr.takeError();
6670
6671 // Create the declaration that is being templated.
6672 VarDecl *ToTemplated;
6673 if (Error Err = importInto(ToTemplated, DTemplated))
6674 return std::move(Err);
6675
6676 // Create the variable template declaration itself.
6677 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6678 if (!TemplateParamsOrErr)
6679 return TemplateParamsOrErr.takeError();
6680
6681 VarTemplateDecl *ToVarTD;
6682 if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6683 Name, *TemplateParamsOrErr, ToTemplated))
6684 return ToVarTD;
6685
6686 ToTemplated->setDescribedVarTemplate(ToVarTD);
6687
6688 ToVarTD->setAccess(D->getAccess());
6689 ToVarTD->setLexicalDeclContext(LexicalDC);
6690 LexicalDC->addDeclInternal(ToVarTD);
6691 if (DC != Importer.getToContext().getTranslationUnitDecl())
6692 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6693
6694 if (FoundByLookup) {
6695 auto *Recent =
6696 const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6697 if (!ToTemplated->getPreviousDecl()) {
6698 auto *PrevTemplated =
6699 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6700 if (ToTemplated != PrevTemplated)
6701 ToTemplated->setPreviousDecl(PrevTemplated);
6702 }
6703 ToVarTD->setPreviousDecl(Recent);
6704 }
6705
6706 return ToVarTD;
6707}
6708
6711 // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6712 // in an analog way (but specialized for this case).
6713
6715 auto RedeclIt = Redecls.begin();
6716 // Import the first part of the decl chain. I.e. import all previous
6717 // declarations starting from the canonical decl.
6718 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6719 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6720 if (!RedeclOrErr)
6721 return RedeclOrErr.takeError();
6722 }
6723 assert(*RedeclIt == D);
6724
6725 VarTemplateDecl *VarTemplate = nullptr;
6727 return std::move(Err);
6728
6729 // Import the context of this declaration.
6730 DeclContext *DC, *LexicalDC;
6731 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6732 return std::move(Err);
6733
6734 // Import the location of this declaration.
6735 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6736 if (!BeginLocOrErr)
6737 return BeginLocOrErr.takeError();
6738
6739 auto IdLocOrErr = import(D->getLocation());
6740 if (!IdLocOrErr)
6741 return IdLocOrErr.takeError();
6742
6743 // Import template arguments.
6745 if (Error Err =
6746 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6747 return std::move(Err);
6748
6749 // Try to find an existing specialization with these template arguments.
6750 void *InsertPos = nullptr;
6751 VarTemplateSpecializationDecl *FoundSpecialization =
6752 VarTemplate->findSpecialization(TemplateArgs, InsertPos);
6753 if (FoundSpecialization) {
6754 if (IsStructuralMatch(D, FoundSpecialization)) {
6755 VarDecl *FoundDef = FoundSpecialization->getDefinition();
6756 if (D->getDeclContext()->isRecord()) {
6757 // In a record, it is allowed only to have one optional declaration and
6758 // one definition of the (static or constexpr) variable template.
6759 assert(
6760 FoundSpecialization->getDeclContext()->isRecord() &&
6761 "Member variable template specialization imported as non-member, "
6762 "inconsistent imported AST?");
6763 if (FoundDef)
6764 return Importer.MapImported(D, FoundDef);
6766 return Importer.MapImported(D, FoundSpecialization);
6767 } else {
6768 // If definition is imported and there is already one, map to it.
6769 // Otherwise create a new variable and link it to the existing.
6770 if (FoundDef && D->isThisDeclarationADefinition())
6771 return Importer.MapImported(D, FoundDef);
6772 }
6773 } else {
6774 return make_error<ASTImportError>(ASTImportError::NameConflict);
6775 }
6776 }
6777
6778 VarTemplateSpecializationDecl *D2 = nullptr;
6779
6780 TemplateArgumentListInfo ToTAInfo;
6781 if (const auto *Args = D->getTemplateArgsAsWritten()) {
6782 if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6783 return std::move(Err);
6784 }
6785
6786 using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6787 // Create a new specialization.
6788 if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6789 auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6790 if (!ToTPListOrErr)
6791 return ToTPListOrErr.takeError();
6792
6793 PartVarSpecDecl *ToPartial;
6794 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6795 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6796 VarTemplate, QualType(), nullptr,
6797 D->getStorageClass(), TemplateArgs))
6798 return ToPartial;
6799
6800 if (Expected<PartVarSpecDecl *> ToInstOrErr =
6801 import(FromPartial->getInstantiatedFromMember()))
6802 ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6803 else
6804 return ToInstOrErr.takeError();
6805
6806 if (FromPartial->isMemberSpecialization())
6807 ToPartial->setMemberSpecialization();
6808
6809 D2 = ToPartial;
6810
6811 // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6812 // to adopt template parameters.
6813 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6814 } else { // Full specialization
6815 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6816 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6817 QualType(), nullptr, D->getStorageClass(),
6818 TemplateArgs))
6819 return D2;
6820 }
6821
6822 // Update InsertPos, because preceding import calls may have invalidated
6823 // it by adding new specializations.
6824 if (!VarTemplate->findSpecialization(TemplateArgs, InsertPos))
6825 VarTemplate->AddSpecialization(D2, InsertPos);
6826
6827 QualType T;
6828 if (Error Err = importInto(T, D->getType()))
6829 return std::move(Err);
6830 D2->setType(T);
6831
6832 auto TInfoOrErr = import(D->getTypeSourceInfo());
6833 if (!TInfoOrErr)
6834 return TInfoOrErr.takeError();
6835 D2->setTypeSourceInfo(*TInfoOrErr);
6836
6837 if (D->getPointOfInstantiation().isValid()) {
6838 if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6839 D2->setPointOfInstantiation(*POIOrErr);
6840 else
6841 return POIOrErr.takeError();
6842 }
6843
6845
6846 if (D->getTemplateArgsAsWritten())
6847 D2->setTemplateArgsAsWritten(ToTAInfo);
6848
6849 if (auto LocOrErr = import(D->getQualifierLoc()))
6850 D2->setQualifierInfo(*LocOrErr);
6851 else
6852 return LocOrErr.takeError();
6853
6854 if (D->isConstexpr())
6855 D2->setConstexpr(true);
6856
6857 D2->setAccess(D->getAccess());
6858
6859 if (Error Err = ImportInitializer(D, D2))
6860 return std::move(Err);
6861
6862 if (FoundSpecialization)
6863 D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6864
6865 addDeclToContexts(D, D2);
6866
6867 // Import the rest of the chain. I.e. import all subsequent declarations.
6868 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6869 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6870 if (!RedeclOrErr)
6871 return RedeclOrErr.takeError();
6872 }
6873
6874 return D2;
6875}
6876
6879 DeclContext *DC, *LexicalDC;
6880 DeclarationName Name;
6881 SourceLocation Loc;
6882 NamedDecl *ToD;
6883
6884 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6885 return std::move(Err);
6886
6887 if (ToD)
6888 return ToD;
6889
6890 const FunctionTemplateDecl *FoundByLookup = nullptr;
6891
6892 // Try to find a function in our own ("to") context with the same name, same
6893 // type, and in the same context as the function we're importing.
6894 // FIXME Split this into a separate function.
6895 if (!LexicalDC->isFunctionOrMethod()) {
6897 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6898 for (auto *FoundDecl : FoundDecls) {
6899 if (!FoundDecl->isInIdentifierNamespace(IDNS))
6900 continue;
6901
6902 if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6903 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6904 continue;
6905 if (IsStructuralMatch(D, FoundTemplate)) {
6906 FunctionTemplateDecl *TemplateWithDef =
6907 getTemplateDefinition(FoundTemplate);
6908 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6909 return Importer.MapImported(D, TemplateWithDef);
6910
6911 FoundByLookup = FoundTemplate;
6912 break;
6913 // TODO: handle conflicting names
6914 }
6915 }
6916 }
6917 }
6918
6919 auto ParamsOrErr = import(D->getTemplateParameters());
6920 if (!ParamsOrErr)
6921 return ParamsOrErr.takeError();
6922 TemplateParameterList *Params = *ParamsOrErr;
6923
6924 FunctionDecl *TemplatedFD;
6925 if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6926 return std::move(Err);
6927
6928 // At creation of the template the template parameters are "adopted"
6929 // (DeclContext is changed). After this possible change the lookup table
6930 // must be updated.
6931 // At deduction guides the DeclContext of the template parameters may be
6932 // different from what we would expect, it may be the class template, or a
6933 // probably different CXXDeductionGuideDecl. This may come from the fact that
6934 // the template parameter objects may be shared between deduction guides or
6935 // the class template, and at creation of multiple FunctionTemplateDecl
6936 // objects (for deduction guides) the same parameters are re-used. The
6937 // "adoption" happens multiple times with different parent, even recursively
6938 // for TemplateTemplateParmDecl. The same happens at import when the
6939 // FunctionTemplateDecl objects are created, but in different order.
6940 // In this way the DeclContext of these template parameters is not necessarily
6941 // the same as in the "from" context.
6943 OldParamDC.reserve(Params->size());
6944 llvm::transform(*Params, std::back_inserter(OldParamDC),
6945 [](NamedDecl *ND) { return ND->getDeclContext(); });
6946
6947 FunctionTemplateDecl *ToFunc;
6948 if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6949 Params, TemplatedFD))
6950 return ToFunc;
6951
6952 // Fail if TemplatedFD is already part of a template.
6953 // The template should have been found by structural equivalence check before,
6954 // or ToFunc should be already imported.
6955 // If not, there is AST incompatibility that can be caused by previous import
6956 // errors. (NameConflict is not exact here.)
6957 if (TemplatedFD->getDescribedTemplate())
6958 return make_error<ASTImportError>(ASTImportError::NameConflict);
6959
6960 TemplatedFD->setDescribedFunctionTemplate(ToFunc);
6961
6962 ToFunc->setAccess(D->getAccess());
6963 ToFunc->setLexicalDeclContext(LexicalDC);
6964 addDeclToContexts(D, ToFunc);
6965
6966 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
6967 if (LT && !OldParamDC.empty()) {
6968 for (unsigned int I = 0; I < OldParamDC.size(); ++I)
6969 LT->updateForced(Params->getParam(I), OldParamDC[I]);
6970 }
6971
6972 if (FoundByLookup) {
6973 auto *Recent =
6974 const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6975 if (!TemplatedFD->getPreviousDecl()) {
6976 assert(FoundByLookup->getTemplatedDecl() &&
6977 "Found decl must have its templated decl set");
6978 auto *PrevTemplated =
6979 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6980 if (TemplatedFD != PrevTemplated)
6981 TemplatedFD->setPreviousDecl(PrevTemplated);
6982 }
6983 ToFunc->setPreviousDecl(Recent);
6984 }
6985
6986 return ToFunc;
6987}
6988
6990 DeclContext *DC, *LexicalDC;
6991 Error Err = ImportDeclContext(D, DC, LexicalDC);
6992 auto LocationOrErr = importChecked(Err, D->getLocation());
6993 auto NameDeclOrErr = importChecked(Err, D->getDeclName());
6994 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
6995 auto ConstraintExpr = importChecked(Err, D->getConstraintExpr());
6996 if (Err)
6997 return std::move(Err);
6998
6999 ConceptDecl *To;
7000 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, LocationOrErr,
7001 NameDeclOrErr, ToTemplateParameters,
7002 ConstraintExpr))
7003 return To;
7004 To->setLexicalDeclContext(LexicalDC);
7005 LexicalDC->addDeclInternal(To);
7006 return To;
7007}
7008
7011 DeclContext *DC, *LexicalDC;
7012 Error Err = ImportDeclContext(D, DC, LexicalDC);
7013 auto RequiresLoc = importChecked(Err, D->getLocation());
7014 if (Err)
7015 return std::move(Err);
7016
7018 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, RequiresLoc))
7019 return To;
7020 To->setLexicalDeclContext(LexicalDC);
7021 LexicalDC->addDeclInternal(To);
7022 return To;
7023}
7024
7027 DeclContext *DC, *LexicalDC;
7028 Error Err = ImportDeclContext(D, DC, LexicalDC);
7029 auto ToSL = importChecked(Err, D->getLocation());
7030 if (Err)
7031 return std::move(Err);
7032
7034 if (Error Err = ImportTemplateArguments(D->getTemplateArguments(), ToArgs))
7035 return std::move(Err);
7036
7038 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, ToSL, ToArgs))
7039 return To;
7040 To->setLexicalDeclContext(LexicalDC);
7041 LexicalDC->addDeclInternal(To);
7042 return To;
7043}
7044
7045//----------------------------------------------------------------------------
7046// Import Statements
7047//----------------------------------------------------------------------------
7048
7050 Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
7051 << S->getStmtClassName();
7052 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7053}
7054
7055
7057 if (Importer.returnWithErrorInTest())
7058 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7060 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7061 IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
7062 // ToII is nullptr when no symbolic name is given for output operand
7063 // see ParseStmtAsm::ParseAsmOperandsOpt
7064 Names.push_back(ToII);
7065 }
7066
7067 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7068 IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
7069 // ToII is nullptr when no symbolic name is given for input operand
7070 // see ParseStmtAsm::ParseAsmOperandsOpt
7071 Names.push_back(ToII);
7072 }
7073
7074 SmallVector<Expr *, 4> Clobbers;
7075 for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
7076 if (auto ClobberOrErr = import(S->getClobberExpr(I)))
7077 Clobbers.push_back(*ClobberOrErr);
7078 else
7079 return ClobberOrErr.takeError();
7080
7081 }
7082
7083 SmallVector<Expr *, 4> Constraints;
7084 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7085 if (auto OutputOrErr = import(S->getOutputConstraintExpr(I)))
7086 Constraints.push_back(*OutputOrErr);
7087 else
7088 return OutputOrErr.takeError();
7089 }
7090
7091 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7092 if (auto InputOrErr = import(S->getInputConstraintExpr(I)))
7093 Constraints.push_back(*InputOrErr);
7094 else
7095 return InputOrErr.takeError();
7096 }
7097
7099 S->getNumLabels());
7100 if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
7101 return std::move(Err);
7102
7103 if (Error Err =
7104 ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
7105 return std::move(Err);
7106
7107 if (Error Err = ImportArrayChecked(
7108 S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs()))
7109 return std::move(Err);
7110
7111 ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
7112 if (!AsmLocOrErr)
7113 return AsmLocOrErr.takeError();
7114 auto AsmStrOrErr = import(S->getAsmStringExpr());
7115 if (!AsmStrOrErr)
7116 return AsmStrOrErr.takeError();
7117 ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
7118 if (!RParenLocOrErr)
7119 return RParenLocOrErr.takeError();
7120
7121 return new (Importer.getToContext()) GCCAsmStmt(
7122 Importer.getToContext(),
7123 *AsmLocOrErr,
7124 S->isSimple(),
7125 S->isVolatile(),
7126 S->getNumOutputs(),
7127 S->getNumInputs(),
7128 Names.data(),
7129 Constraints.data(),
7130 Exprs.data(),
7131 *AsmStrOrErr,
7132 S->getNumClobbers(),
7133 Clobbers.data(),
7134 S->getNumLabels(),
7135 *RParenLocOrErr);
7136}
7137
7139
7140 Error Err = Error::success();
7141 auto ToDG = importChecked(Err, S->getDeclGroup());
7142 auto ToBeginLoc = importChecked(Err, S->getBeginLoc());
7143 auto ToEndLoc = importChecked(Err, S->getEndLoc());
7144 if (Err)
7145 return std::move(Err);
7146 return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
7147}
7148
7150 ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
7151 if (!ToSemiLocOrErr)
7152 return ToSemiLocOrErr.takeError();
7153 return new (Importer.getToContext()) NullStmt(
7154 *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
7155}
7156
7158 SmallVector<Stmt *, 8> ToStmts(S->size());
7159
7160 if (Error Err = ImportContainerChecked(S->body(), ToStmts))
7161 return std::move(Err);
7162
7163 ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
7164 if (!ToLBracLocOrErr)
7165 return ToLBracLocOrErr.takeError();
7166
7167 ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
7168 if (!ToRBracLocOrErr)
7169 return ToRBracLocOrErr.takeError();
7170
7171 FPOptionsOverride FPO =
7173 return CompoundStmt::Create(Importer.getToContext(), ToStmts, FPO,
7174 *ToLBracLocOrErr, *ToRBracLocOrErr);
7175}
7176
7178
7179 Error Err = Error::success();
7180 auto ToLHS = importChecked(Err, S->getLHS());
7181 auto ToRHS = importChecked(Err, S->getRHS());
7182 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7183 auto ToCaseLoc = importChecked(Err, S->getCaseLoc());
7184 auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc());
7185 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7186 if (Err)
7187 return std::move(Err);
7188
7189 auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
7190 ToCaseLoc, ToEllipsisLoc, ToColonLoc);
7191 ToStmt->setSubStmt(ToSubStmt);
7192
7193 return ToStmt;
7194}
7195
7197
7198 Error Err = Error::success();
7199 auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc());
7200 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7201 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7202 if (Err)
7203 return std::move(Err);
7204
7205 return new (Importer.getToContext()) DefaultStmt(
7206 ToDefaultLoc, ToColonLoc, ToSubStmt);
7207}
7208
7210
7211 Error Err = Error::success();
7212 auto ToIdentLoc = importChecked(Err, S->getIdentLoc());
7213 auto ToLabelDecl = importChecked(Err, S->getDecl());
7214 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7215 if (Err)
7216 return std::move(Err);
7217
7218 return new (Importer.getToContext()) LabelStmt(
7219 ToIdentLoc, ToLabelDecl, ToSubStmt);
7220}
7221
7223 ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
7224 if (!ToAttrLocOrErr)
7225 return ToAttrLocOrErr.takeError();
7226 ArrayRef<const Attr*> FromAttrs(S->getAttrs());
7227 SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
7228 if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
7229 return std::move(Err);
7230 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7231 if (!ToSubStmtOrErr)
7232 return ToSubStmtOrErr.takeError();
7233
7235 Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
7236}
7237
7239
7240 Error Err = Error::success();
7241 auto ToIfLoc = importChecked(Err, S->getIfLoc());
7242 auto ToInit = importChecked(Err, S->getInit());
7243 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7244 auto ToCond = importChecked(Err, S->getCond());
7245 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7246 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7247 auto ToThen = importChecked(Err, S->getThen());
7248 auto ToElseLoc = importChecked(Err, S->getElseLoc());
7249 auto ToElse = importChecked(Err, S->getElse());
7250 if (Err)
7251 return std::move(Err);
7252
7253 return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(),
7254 ToInit, ToConditionVariable, ToCond, ToLParenLoc,
7255 ToRParenLoc, ToThen, ToElseLoc, ToElse);
7256}
7257
7259
7260 Error Err = Error::success();
7261 auto ToInit = importChecked(Err, S->getInit());
7262 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7263 auto ToCond = importChecked(Err, S->getCond());
7264 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7265 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7266 auto ToBody = importChecked(Err, S->getBody());
7267 auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
7268 if (Err)
7269 return std::move(Err);
7270
7271 auto *ToStmt =
7272 SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
7273 ToCond, ToLParenLoc, ToRParenLoc);
7274 ToStmt->setBody(ToBody);
7275 ToStmt->setSwitchLoc(ToSwitchLoc);
7276
7277 // Now we have to re-chain the cases.
7278 SwitchCase *LastChainedSwitchCase = nullptr;
7279 for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
7280 SC = SC->getNextSwitchCase()) {
7281 Expected<SwitchCase *> ToSCOrErr = import(SC);
7282 if (!ToSCOrErr)
7283 return ToSCOrErr.takeError();
7284 if (LastChainedSwitchCase)
7285 LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
7286 else
7287 ToStmt->setSwitchCaseList(*ToSCOrErr);
7288 LastChainedSwitchCase = *ToSCOrErr;
7289 }
7290
7291 return ToStmt;
7292}
7293
7295
7296 Error Err = Error::success();
7297 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7298 auto ToCond = importChecked(Err, S->getCond());
7299 auto ToBody = importChecked(Err, S->getBody());
7300 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7301 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7302 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7303 if (Err)
7304 return std::move(Err);
7305
7306 return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
7307 ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc);
7308}
7309
7311
7312 Error Err = Error::success();
7313 auto ToBody = importChecked(Err, S->getBody());
7314 auto ToCond = importChecked(Err, S->getCond());
7315 auto ToDoLoc = importChecked(Err, S->getDoLoc());
7316 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7317 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7318 if (Err)
7319 return std::move(Err);
7320
7321 return new (Importer.getToContext()) DoStmt(
7322 ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
7323}
7324
7326
7327 Error Err = Error::success();
7328 auto ToInit = importChecked(Err, S->getInit());
7329 auto ToCond = importChecked(Err, S->getCond());
7330 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7331 auto ToInc = importChecked(Err, S->getInc());
7332 auto ToBody = importChecked(Err, S->getBody());
7333 auto ToForLoc = importChecked(Err, S->getForLoc());
7334 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7335 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7336 if (Err)
7337 return std::move(Err);
7338
7339 return new (Importer.getToContext()) ForStmt(
7340 Importer.getToContext(),
7341 ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
7342 ToRParenLoc);
7343}
7344
7346
7347 Error Err = Error::success();
7348 auto ToLabel = importChecked(Err, S->getLabel());
7349 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7350 auto ToLabelLoc = importChecked(Err, S->getLabelLoc());
7351 if (Err)
7352 return std::move(Err);
7353
7354 return new (Importer.getToContext()) GotoStmt(
7355 ToLabel, ToGotoLoc, ToLabelLoc);
7356}
7357
7359
7360 Error Err = Error::success();
7361 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7362 auto ToStarLoc = importChecked(Err, S->getStarLoc());
7363 auto ToTarget = importChecked(Err, S->getTarget());
7364 if (Err)
7365 return std::move(Err);
7366
7367 return new (Importer.getToContext()) IndirectGotoStmt(
7368 ToGotoLoc, ToStarLoc, ToTarget);
7369}
7370
7371template <typename StmtClass>
7373 ASTImporter &Importer, StmtClass *S) {
7374 Error Err = Error::success();
7375 auto ToLoc = NodeImporter.importChecked(Err, S->getKwLoc());
7376 auto ToLabelLoc = S->hasLabelTarget()
7377 ? NodeImporter.importChecked(Err, S->getLabelLoc())
7378 : SourceLocation();
7379 auto ToDecl = S->hasLabelTarget()
7380 ? NodeImporter.importChecked(Err, S->getLabelDecl())
7381 : nullptr;
7382 if (Err)
7383 return std::move(Err);
7384 return new (Importer.getToContext()) StmtClass(ToLoc, ToLabelLoc, ToDecl);
7385}
7386
7390
7394
7396
7397 Error Err = Error::success();
7398 auto ToReturnLoc = importChecked(Err, S->getReturnLoc());
7399 auto ToRetValue = importChecked(Err, S->getRetValue());
7400 auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate());
7401 if (Err)
7402 return std::move(Err);
7403
7404 return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
7405 ToNRVOCandidate);
7406}
7407
7409
7410 Error Err = Error::success();
7411 auto ToCatchLoc = importChecked(Err, S->getCatchLoc());
7412 auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl());
7413 auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock());
7414 if (Err)
7415 return std::move(Err);
7416
7417 return new (Importer.getToContext()) CXXCatchStmt (
7418 ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
7419}
7420
7422 ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
7423 if (!ToTryLocOrErr)
7424 return ToTryLocOrErr.takeError();
7425
7426 ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
7427 if (!ToTryBlockOrErr)
7428 return ToTryBlockOrErr.takeError();
7429
7430 SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
7431 for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
7432 CXXCatchStmt *FromHandler = S->getHandler(HI);
7433 if (auto ToHandlerOrErr = import(FromHandler))
7434 ToHandlers[HI] = *ToHandlerOrErr;
7435 else
7436 return ToHandlerOrErr.takeError();
7437 }
7438
7439 return CXXTryStmt::Create(Importer.getToContext(), *ToTryLocOrErr,
7440 cast<CompoundStmt>(*ToTryBlockOrErr), ToHandlers);
7441}
7442
7444
7445 Error Err = Error::success();
7446 auto ToInit = importChecked(Err, S->getInit());
7447 auto ToRangeStmt = importChecked(Err, S->getRangeStmt());
7448 auto ToBeginStmt = importChecked(Err, S->getBeginStmt());
7449 auto ToEndStmt = importChecked(Err, S->getEndStmt());
7450 auto ToCond = importChecked(Err, S->getCond());
7451 auto ToInc = importChecked(Err, S->getInc());
7452 auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt());
7453 auto ToBody = importChecked(Err, S->getBody());
7454 auto ToForLoc = importChecked(Err, S->getForLoc());
7455 auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc());
7456 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7457 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7458 if (Err)
7459 return std::move(Err);
7460
7461 return new (Importer.getToContext()) CXXForRangeStmt(
7462 ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
7463 ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
7464}
7465
7468 Error Err = Error::success();
7469 auto ToElement = importChecked(Err, S->getElement());
7470 auto ToCollection = importChecked(Err, S->getCollection());
7471 auto ToBody = importChecked(Err, S->getBody());
7472 auto ToForLoc = importChecked(Err, S->getForLoc());
7473 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7474 if (Err)
7475 return std::move(Err);
7476
7477 return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
7478 ToCollection,
7479 ToBody,
7480 ToForLoc,
7481 ToRParenLoc);
7482}
7483
7485
7486 Error Err = Error::success();
7487 auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc());
7488 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7489 auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl());
7490 auto ToCatchBody = importChecked(Err, S->getCatchBody());
7491 if (Err)
7492 return std::move(Err);
7493
7494 return new (Importer.getToContext()) ObjCAtCatchStmt (
7495 ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
7496}
7497
7499 ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
7500 if (!ToAtFinallyLocOrErr)
7501 return ToAtFinallyLocOrErr.takeError();
7502 ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
7503 if (!ToAtFinallyStmtOrErr)
7504 return ToAtFinallyStmtOrErr.takeError();
7505 return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
7506 *ToAtFinallyStmtOrErr);
7507}
7508
7510
7511 Error Err = Error::success();
7512 auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc());
7513 auto ToTryBody = importChecked(Err, S->getTryBody());
7514 auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt());
7515 if (Err)
7516 return std::move(Err);
7517
7518 SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
7519 for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
7520 ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
7521 if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
7522 ToCatchStmts[CI] = *ToCatchStmtOrErr;
7523 else
7524 return ToCatchStmtOrErr.takeError();
7525 }
7526
7527 return ObjCAtTryStmt::Create(Importer.getToContext(),
7528 ToAtTryLoc, ToTryBody,
7529 ToCatchStmts.begin(), ToCatchStmts.size(),
7530 ToFinallyStmt);
7531}
7532
7535
7536 Error Err = Error::success();
7537 auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc());
7538 auto ToSynchExpr = importChecked(Err, S->getSynchExpr());
7539 auto ToSynchBody = importChecked(Err, S->getSynchBody());
7540 if (Err)
7541 return std::move(Err);
7542
7543 return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
7544 ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
7545}
7546
7548 ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
7549 if (!ToThrowLocOrErr)
7550 return ToThrowLocOrErr.takeError();
7551 ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
7552 if (!ToThrowExprOrErr)
7553 return ToThrowExprOrErr.takeError();
7554 return new (Importer.getToContext()) ObjCAtThrowStmt(
7555 *ToThrowLocOrErr, *ToThrowExprOrErr);
7556}
7557
7560 ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
7561 if (!ToAtLocOrErr)
7562 return ToAtLocOrErr.takeError();
7563 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7564 if (!ToSubStmtOrErr)
7565 return ToSubStmtOrErr.takeError();
7566 return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
7567 *ToSubStmtOrErr);
7568}
7569
7570//----------------------------------------------------------------------------
7571// Import Expressions
7572//----------------------------------------------------------------------------
7574 Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
7575 << E->getStmtClassName();
7576 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7577}
7578
7580 Error Err = Error::success();
7581 auto ToType = importChecked(Err, E->getType());
7582 auto BLoc = importChecked(Err, E->getBeginLoc());
7583 auto RParenLoc = importChecked(Err, E->getEndLoc());
7584 if (Err)
7585 return std::move(Err);
7586 auto ParentContextOrErr = Importer.ImportContext(E->getParentContext());
7587 if (!ParentContextOrErr)
7588 return ParentContextOrErr.takeError();
7589
7590 return new (Importer.getToContext())
7591 SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc,
7592 RParenLoc, *ParentContextOrErr);
7593}
7594
7596
7597 Error Err = Error::success();
7598 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7599 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7600 auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo());
7601 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7602 auto ToType = importChecked(Err, E->getType());
7603 if (Err)
7604 return std::move(Err);
7605
7606 return new (Importer.getToContext()) VAArgExpr(
7607 ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
7608 E->isMicrosoftABI());
7609}
7610
7612
7613 Error Err = Error::success();
7614 auto ToCond = importChecked(Err, E->getCond());
7615 auto ToLHS = importChecked(Err, E->getLHS());
7616 auto ToRHS = importChecked(Err, E->getRHS());
7617 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7618 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7619 auto ToType = importChecked(Err, E->getType());
7620 if (Err)
7621 return std::move(Err);
7622
7624 ExprObjectKind OK = E->getObjectKind();
7625
7626 // The value of CondIsTrue only matters if the value is not
7627 // condition-dependent.
7628 bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
7629
7630 return new (Importer.getToContext())
7631 ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
7632 ToRParenLoc, CondIsTrue);
7633}
7634
7636 Error Err = Error::success();
7637 auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
7638 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7639 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7640 auto ToType = importChecked(Err, E->getType());
7641 auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
7642 if (Err)
7643 return std::move(Err);
7644
7646 Importer.getToContext(), ToSrcExpr, ToTSI, ToType, E->getValueKind(),
7647 E->getObjectKind(), ToBuiltinLoc, ToRParenLoc,
7649}
7650
7652 Error Err = Error::success();
7653 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7654 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7655 auto ToType = importChecked(Err, E->getType());
7656 const unsigned NumSubExprs = E->getNumSubExprs();
7657
7659 ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
7660 ToSubExprs.resize(NumSubExprs);
7661
7662 if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
7663 return std::move(Err);
7664
7665 return new (Importer.getToContext()) ShuffleVectorExpr(
7666 Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
7667}
7668
7670 ExpectedType TypeOrErr = import(E->getType());
7671 if (!TypeOrErr)
7672 return TypeOrErr.takeError();
7673
7674 ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
7675 if (!BeginLocOrErr)
7676 return BeginLocOrErr.takeError();
7677
7678 return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
7679}
7680
7683 Error Err = Error::success();
7684 auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
7685 Expr *ToControllingExpr = nullptr;
7686 TypeSourceInfo *ToControllingType = nullptr;
7687 if (E->isExprPredicate())
7688 ToControllingExpr = importChecked(Err, E->getControllingExpr());
7689 else
7690 ToControllingType = importChecked(Err, E->getControllingType());
7691 assert((ToControllingExpr || ToControllingType) &&
7692 "Either the controlling expr or type must be nonnull");
7693 auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
7694 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7695 if (Err)
7696 return std::move(Err);
7697
7699 SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
7700 if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
7701 return std::move(Err);
7702
7703 ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
7704 SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
7705 if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
7706 return std::move(Err);
7707
7708 const ASTContext &ToCtx = Importer.getToContext();
7709 if (E->isResultDependent()) {
7710 if (ToControllingExpr) {
7712 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7713 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7715 }
7717 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7718 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7720 }
7721
7722 if (ToControllingExpr) {
7724 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7725 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7727 }
7729 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7730 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7732}
7733
7735
7736 Error Err = Error::success();
7737 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7738 auto ToType = importChecked(Err, E->getType());
7739 auto ToFunctionName = importChecked(Err, E->getFunctionName());
7740 if (Err)
7741 return std::move(Err);
7742
7743 return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
7744 E->getIdentKind(), E->isTransparent(),
7745 ToFunctionName);
7746}
7747
7749
7750 Error Err = Error::success();
7751 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
7752 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
7753 auto ToDecl = importChecked(Err, E->getDecl());
7754 auto ToLocation = importChecked(Err, E->getLocation());
7755 auto ToType = importChecked(Err, E->getType());
7756 if (Err)
7757 return std::move(Err);
7758
7759 NamedDecl *ToFoundD = nullptr;
7760 if (E->getDecl() != E->getFoundDecl()) {
7761 auto FoundDOrErr = import(E->getFoundDecl());
7762 if (!FoundDOrErr)
7763 return FoundDOrErr.takeError();
7764 ToFoundD = *FoundDOrErr;
7765 }
7766
7767 TemplateArgumentListInfo ToTAInfo;
7768 TemplateArgumentListInfo *ToResInfo = nullptr;
7769 if (E->hasExplicitTemplateArgs()) {
7770 if (Error Err =
7772 E->template_arguments(), ToTAInfo))
7773 return std::move(Err);
7774 ToResInfo = &ToTAInfo;
7775 }
7776
7777 auto *ToE = DeclRefExpr::Create(
7778 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
7779 E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
7780 E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse());
7781 if (E->hadMultipleCandidates())
7782 ToE->setHadMultipleCandidates(true);
7783 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
7784 return ToE;
7785}
7786
7788 ExpectedType TypeOrErr = import(E->getType());
7789 if (!TypeOrErr)
7790 return TypeOrErr.takeError();
7791
7792 return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
7793}
7794
7796 ExpectedExpr ToInitOrErr = import(E->getInit());
7797 if (!ToInitOrErr)
7798 return ToInitOrErr.takeError();
7799
7800 ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
7801 if (!ToEqualOrColonLocOrErr)
7802 return ToEqualOrColonLocOrErr.takeError();
7803
7804 SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
7805 // List elements from the second, the first is Init itself
7806 for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
7807 if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
7808 ToIndexExprs[I - 1] = *ToArgOrErr;
7809 else
7810 return ToArgOrErr.takeError();
7811 }
7812
7813 SmallVector<Designator, 4> ToDesignators(E->size());
7814 if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
7815 return std::move(Err);
7816
7818 Importer.getToContext(), ToDesignators,
7819 ToIndexExprs, *ToEqualOrColonLocOrErr,
7820 E->usesGNUSyntax(), *ToInitOrErr);
7821}
7822
7825 ExpectedType ToTypeOrErr = import(E->getType());
7826 if (!ToTypeOrErr)
7827 return ToTypeOrErr.takeError();
7828
7829 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7830 if (!ToLocationOrErr)
7831 return ToLocationOrErr.takeError();
7832
7833 return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
7834 *ToTypeOrErr, *ToLocationOrErr);
7835}
7836
7838 ExpectedType ToTypeOrErr = import(E->getType());
7839 if (!ToTypeOrErr)
7840 return ToTypeOrErr.takeError();
7841
7842 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7843 if (!ToLocationOrErr)
7844 return ToLocationOrErr.takeError();
7845
7847 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7848}
7849
7850
7852 ExpectedType ToTypeOrErr = import(E->getType());
7853 if (!ToTypeOrErr)
7854 return ToTypeOrErr.takeError();
7855
7856 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7857 if (!ToLocationOrErr)
7858 return ToLocationOrErr.takeError();
7859
7861 Importer.getToContext(), E->getValue(), E->isExact(),
7862 *ToTypeOrErr, *ToLocationOrErr);
7863}
7864
7866 auto ToTypeOrErr = import(E->getType());
7867 if (!ToTypeOrErr)
7868 return ToTypeOrErr.takeError();
7869
7870 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7871 if (!ToSubExprOrErr)
7872 return ToSubExprOrErr.takeError();
7873
7874 return new (Importer.getToContext()) ImaginaryLiteral(
7875 *ToSubExprOrErr, *ToTypeOrErr);
7876}
7877
7879 auto ToTypeOrErr = import(E->getType());
7880 if (!ToTypeOrErr)
7881 return ToTypeOrErr.takeError();
7882
7883 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7884 if (!ToLocationOrErr)
7885 return ToLocationOrErr.takeError();
7886
7887 return new (Importer.getToContext()) FixedPointLiteral(
7888 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
7889 Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
7890}
7891
7893 ExpectedType ToTypeOrErr = import(E->getType());
7894 if (!ToTypeOrErr)
7895 return ToTypeOrErr.takeError();
7896
7897 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7898 if (!ToLocationOrErr)
7899 return ToLocationOrErr.takeError();
7900
7901 return new (Importer.getToContext()) CharacterLiteral(
7902 E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
7903}
7904
7906 ExpectedType ToTypeOrErr = import(E->getType());
7907 if (!ToTypeOrErr)
7908 return ToTypeOrErr.takeError();
7909
7911 if (Error Err = ImportArrayChecked(
7912 E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
7913 return std::move(Err);
7914
7915 return StringLiteral::Create(Importer.getToContext(), E->getBytes(),
7916 E->getKind(), E->isPascal(), *ToTypeOrErr,
7917 ToLocations);
7918}
7919
7921
7922 Error Err = Error::success();
7923 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7924 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7925 auto ToType = importChecked(Err, E->getType());
7926 auto ToInitializer = importChecked(Err, E->getInitializer());
7927 if (Err)
7928 return std::move(Err);
7929
7930 return new (Importer.getToContext()) CompoundLiteralExpr(
7931 ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
7932 ToInitializer, E->isFileScope());
7933}
7934
7936
7937 Error Err = Error::success();
7938 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7939 auto ToType = importChecked(Err, E->getType());
7940 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7941 if (Err)
7942 return std::move(Err);
7943
7945 if (Error Err = ImportArrayChecked(
7946 E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
7947 ToExprs.begin()))
7948 return std::move(Err);
7949
7950 return new (Importer.getToContext()) AtomicExpr(
7951
7952 ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
7953}
7954
7956 Error Err = Error::success();
7957 auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc());
7958 auto ToLabelLoc = importChecked(Err, E->getLabelLoc());
7959 auto ToLabel = importChecked(Err, E->getLabel());
7960 auto ToType = importChecked(Err, E->getType());
7961 if (Err)
7962 return std::move(Err);
7963
7964 return new (Importer.getToContext()) AddrLabelExpr(
7965 ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
7966}
7968 Error Err = Error::success();
7969 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7970 auto ToResult = importChecked(Err, E->getAPValueResult());
7971 if (Err)
7972 return std::move(Err);
7973
7974 return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult);
7975}
7977 Error Err = Error::success();
7978 auto ToLParen = importChecked(Err, E->getLParen());
7979 auto ToRParen = importChecked(Err, E->getRParen());
7980 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7981 if (Err)
7982 return std::move(Err);
7983
7984 return new (Importer.getToContext())
7985 ParenExpr(ToLParen, ToRParen, ToSubExpr);
7986}
7987
7989 SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
7990 if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
7991 return std::move(Err);
7992
7993 ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
7994 if (!ToLParenLocOrErr)
7995 return ToLParenLocOrErr.takeError();
7996
7997 ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
7998 if (!ToRParenLocOrErr)
7999 return ToRParenLocOrErr.takeError();
8000
8001 return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
8002 ToExprs, *ToRParenLocOrErr);
8003}
8004
8006 Error Err = Error::success();
8007 auto ToSubStmt = importChecked(Err, E->getSubStmt());
8008 auto ToType = importChecked(Err, E->getType());
8009 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8010 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8011 if (Err)
8012 return std::move(Err);
8013
8014 return new (Importer.getToContext())
8015 StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
8016 E->getTemplateDepth());
8017}
8018
8020 Error Err = Error::success();
8021 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8022 auto ToType = importChecked(Err, E->getType());
8023 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8024 if (Err)
8025 return std::move(Err);
8026
8027 auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
8028 E->hasStoredFPFeatures());
8029 UO->setType(ToType);
8030 UO->setSubExpr(ToSubExpr);
8031 UO->setOpcode(E->getOpcode());
8032 UO->setOperatorLoc(ToOperatorLoc);
8033 UO->setCanOverflow(E->canOverflow());
8034 if (E->hasStoredFPFeatures())
8035 UO->setStoredFPFeatures(E->getStoredFPFeatures());
8036
8037 return UO;
8038}
8039
8041
8043 Error Err = Error::success();
8044 auto ToType = importChecked(Err, E->getType());
8045 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8046 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8047 if (Err)
8048 return std::move(Err);
8049
8050 if (E->isArgumentType()) {
8051 Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
8052 import(E->getArgumentTypeInfo());
8053 if (!ToArgumentTypeInfoOrErr)
8054 return ToArgumentTypeInfoOrErr.takeError();
8055
8056 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8057 E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
8058 ToRParenLoc);
8059 }
8060
8061 ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
8062 if (!ToArgumentExprOrErr)
8063 return ToArgumentExprOrErr.takeError();
8064
8065 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8066 E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
8067}
8068
8070 Error Err = Error::success();
8071 auto ToLHS = importChecked(Err, E->getLHS());
8072 auto ToRHS = importChecked(Err, E->getRHS());
8073 auto ToType = importChecked(Err, E->getType());
8074 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8075 if (Err)
8076 return std::move(Err);
8077
8079 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8080 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8081 E->getFPFeatures());
8082}
8083
8085 Error Err = Error::success();
8086 auto ToCond = importChecked(Err, E->getCond());
8087 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8088 auto ToLHS = importChecked(Err, E->getLHS());
8089 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8090 auto ToRHS = importChecked(Err, E->getRHS());
8091 auto ToType = importChecked(Err, E->getType());
8092 if (Err)
8093 return std::move(Err);
8094
8095 return new (Importer.getToContext()) ConditionalOperator(
8096 ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
8097 E->getValueKind(), E->getObjectKind());
8098}
8099
8102 Error Err = Error::success();
8103 auto ToCommon = importChecked(Err, E->getCommon());
8104 auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue());
8105 auto ToCond = importChecked(Err, E->getCond());
8106 auto ToTrueExpr = importChecked(Err, E->getTrueExpr());
8107 auto ToFalseExpr = importChecked(Err, E->getFalseExpr());
8108 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8109 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8110 auto ToType = importChecked(Err, E->getType());
8111 if (Err)
8112 return std::move(Err);
8113
8114 return new (Importer.getToContext()) BinaryConditionalOperator(
8115 ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
8116 ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
8117 E->getObjectKind());
8118}
8119
8122 Error Err = Error::success();
8123 auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
8124 if (Err)
8125 return std::move(Err);
8126
8127 return new (Importer.getToContext())
8128 CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
8129}
8130
8132 Error Err = Error::success();
8133 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8134 auto ToQueriedTypeSourceInfo =
8136 auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression());
8137 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8138 auto ToType = importChecked(Err, E->getType());
8139 if (Err)
8140 return std::move(Err);
8141
8142 return new (Importer.getToContext()) ArrayTypeTraitExpr(
8143 ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
8144 ToDimensionExpression, ToEndLoc, ToType);
8145}
8146
8148 Error Err = Error::success();
8149 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8150 auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression());
8151 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8152 auto ToType = importChecked(Err, E->getType());
8153 if (Err)
8154 return std::move(Err);
8155
8156 return new (Importer.getToContext()) ExpressionTraitExpr(
8157 ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
8158 ToEndLoc, ToType);
8159}
8160
8162 Error Err = Error::success();
8163 auto ToLocation = importChecked(Err, E->getLocation());
8164 auto ToType = importChecked(Err, E->getType());
8165 auto ToSourceExpr = importChecked(Err, E->getSourceExpr());
8166 if (Err)
8167 return std::move(Err);
8168
8169 return new (Importer.getToContext()) OpaqueValueExpr(
8170 ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
8171}
8172
8174 Error Err = Error::success();
8175 auto ToLHS = importChecked(Err, E->getLHS());
8176 auto ToRHS = importChecked(Err, E->getRHS());
8177 auto ToType = importChecked(Err, E->getType());
8178 auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc());
8179 if (Err)
8180 return std::move(Err);
8181
8182 return new (Importer.getToContext()) ArraySubscriptExpr(
8183 ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
8184 ToRBracketLoc);
8185}
8186
8189 Error Err = Error::success();
8190 auto ToLHS = importChecked(Err, E->getLHS());
8191 auto ToRHS = importChecked(Err, E->getRHS());
8192 auto ToType = importChecked(Err, E->getType());
8193 auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType());
8194 auto ToComputationResultType =
8196 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8197 if (Err)
8198 return std::move(Err);
8199
8201 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8202 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8203 E->getFPFeatures(),
8204 ToComputationLHSType, ToComputationResultType);
8205}
8206
8209 CXXCastPath Path;
8210 for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
8211 if (auto SpecOrErr = import(*I))
8212 Path.push_back(*SpecOrErr);
8213 else
8214 return SpecOrErr.takeError();
8215 }
8216 return Path;
8217}
8218
8220 ExpectedType ToTypeOrErr = import(E->getType());
8221 if (!ToTypeOrErr)
8222 return ToTypeOrErr.takeError();
8223
8224 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8225 if (!ToSubExprOrErr)
8226 return ToSubExprOrErr.takeError();
8227
8228 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8229 if (!ToBasePathOrErr)
8230 return ToBasePathOrErr.takeError();
8231
8233 Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
8234 &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures());
8235}
8236
8238 Error Err = Error::success();
8239 auto ToType = importChecked(Err, E->getType());
8240 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8241 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
8242 if (Err)
8243 return std::move(Err);
8244
8245 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8246 if (!ToBasePathOrErr)
8247 return ToBasePathOrErr.takeError();
8248 CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
8249
8250 switch (E->getStmtClass()) {
8251 case Stmt::CStyleCastExprClass: {
8252 auto *CCE = cast<CStyleCastExpr>(E);
8253 ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
8254 if (!ToLParenLocOrErr)
8255 return ToLParenLocOrErr.takeError();
8256 ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
8257 if (!ToRParenLocOrErr)
8258 return ToRParenLocOrErr.takeError();
8260 Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
8261 ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten,
8262 *ToLParenLocOrErr, *ToRParenLocOrErr);
8263 }
8264
8265 case Stmt::CXXFunctionalCastExprClass: {
8266 auto *FCE = cast<CXXFunctionalCastExpr>(E);
8267 ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
8268 if (!ToLParenLocOrErr)
8269 return ToLParenLocOrErr.takeError();
8270 ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
8271 if (!ToRParenLocOrErr)
8272 return ToRParenLocOrErr.takeError();
8274 Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
8275 E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(),
8276 *ToLParenLocOrErr, *ToRParenLocOrErr);
8277 }
8278
8279 case Stmt::ObjCBridgedCastExprClass: {
8280 auto *OCE = cast<ObjCBridgedCastExpr>(E);
8281 ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
8282 if (!ToLParenLocOrErr)
8283 return ToLParenLocOrErr.takeError();
8284 ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
8285 if (!ToBridgeKeywordLocOrErr)
8286 return ToBridgeKeywordLocOrErr.takeError();
8287 return new (Importer.getToContext()) ObjCBridgedCastExpr(
8288 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
8289 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
8290 }
8291 case Stmt::BuiltinBitCastExprClass: {
8292 auto *BBC = cast<BuiltinBitCastExpr>(E);
8293 ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
8294 if (!ToKWLocOrErr)
8295 return ToKWLocOrErr.takeError();
8296 ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
8297 if (!ToRParenLocOrErr)
8298 return ToRParenLocOrErr.takeError();
8299 return new (Importer.getToContext()) BuiltinBitCastExpr(
8300 ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
8301 ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
8302 }
8303 default:
8304 llvm_unreachable("Cast expression of unsupported type!");
8305 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
8306 }
8307}
8308
8311 for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
8312 const OffsetOfNode &FromNode = E->getComponent(I);
8313
8314 SourceLocation ToBeginLoc, ToEndLoc;
8315
8316 if (FromNode.getKind() != OffsetOfNode::Base) {
8317 Error Err = Error::success();
8318 ToBeginLoc = importChecked(Err, FromNode.getBeginLoc());
8319 ToEndLoc = importChecked(Err, FromNode.getEndLoc());
8320 if (Err)
8321 return std::move(Err);
8322 }
8323
8324 switch (FromNode.getKind()) {
8326 ToNodes.push_back(
8327 OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
8328 break;
8329 case OffsetOfNode::Base: {
8330 auto ToBSOrErr = import(FromNode.getBase());
8331 if (!ToBSOrErr)
8332 return ToBSOrErr.takeError();
8333 ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
8334 break;
8335 }
8336 case OffsetOfNode::Field: {
8337 auto ToFieldOrErr = import(FromNode.getField());
8338 if (!ToFieldOrErr)
8339 return ToFieldOrErr.takeError();
8340 ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
8341 break;
8342 }
8344 IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
8345 ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
8346 break;
8347 }
8348 }
8349 }
8350
8352 for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
8353 ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
8354 if (!ToIndexExprOrErr)
8355 return ToIndexExprOrErr.takeError();
8356 ToExprs[I] = *ToIndexExprOrErr;
8357 }
8358
8359 Error Err = Error::success();
8360 auto ToType = importChecked(Err, E->getType());
8361 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8362 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8363 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8364 if (Err)
8365 return std::move(Err);
8366
8367 return OffsetOfExpr::Create(
8368 Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
8369 ToExprs, ToRParenLoc);
8370}
8371
8373 Error Err = Error::success();
8374 auto ToType = importChecked(Err, E->getType());
8375 auto ToOperand = importChecked(Err, E->getOperand());
8376 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8377 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8378 if (Err)
8379 return std::move(Err);
8380
8381 CanThrowResult ToCanThrow;
8382 if (E->isValueDependent())
8383 ToCanThrow = CT_Dependent;
8384 else
8385 ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
8386
8387 return new (Importer.getToContext()) CXXNoexceptExpr(
8388 ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
8389}
8390
8392 Error Err = Error::success();
8393 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8394 auto ToType = importChecked(Err, E->getType());
8395 auto ToThrowLoc = importChecked(Err, E->getThrowLoc());
8396 if (Err)
8397 return std::move(Err);
8398
8399 return new (Importer.getToContext()) CXXThrowExpr(
8400 ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
8401}
8402
8404 ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
8405 if (!ToUsedLocOrErr)
8406 return ToUsedLocOrErr.takeError();
8407
8408 auto ToParamOrErr = import(E->getParam());
8409 if (!ToParamOrErr)
8410 return ToParamOrErr.takeError();
8411
8412 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8413 if (!UsedContextOrErr)
8414 return UsedContextOrErr.takeError();
8415
8416 // Import the default arg if it was not imported yet.
8417 // This is needed because it can happen that during the import of the
8418 // default expression (from VisitParmVarDecl) the same ParmVarDecl is
8419 // encountered here. The default argument for a ParmVarDecl is set in the
8420 // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here,
8421 // see VisitParmVarDecl).
8422 ParmVarDecl *ToParam = *ToParamOrErr;
8423 if (!ToParam->getDefaultArg()) {
8424 std::optional<ParmVarDecl *> FromParam =
8425 Importer.getImportedFromDecl(ToParam);
8426 assert(FromParam && "ParmVarDecl was not imported?");
8427
8428 if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam))
8429 return std::move(Err);
8430 }
8431 Expr *RewrittenInit = nullptr;
8432 if (E->hasRewrittenInit()) {
8433 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8434 if (!ExprOrErr)
8435 return ExprOrErr.takeError();
8436 RewrittenInit = ExprOrErr.get();
8437 }
8438 return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr,
8439 *ToParamOrErr, RewrittenInit,
8440 *UsedContextOrErr);
8441}
8442
8445 Error Err = Error::success();
8446 auto ToType = importChecked(Err, E->getType());
8447 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8448 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8449 if (Err)
8450 return std::move(Err);
8451
8452 return new (Importer.getToContext()) CXXScalarValueInitExpr(
8453 ToType, ToTypeSourceInfo, ToRParenLoc);
8454}
8455
8458 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8459 if (!ToSubExprOrErr)
8460 return ToSubExprOrErr.takeError();
8461
8462 auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
8463 if (!ToDtorOrErr)
8464 return ToDtorOrErr.takeError();
8465
8466 ASTContext &ToCtx = Importer.getToContext();
8467 CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
8468 return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
8469}
8470
8472
8474 Error Err = Error::success();
8475 auto ToConstructor = importChecked(Err, E->getConstructor());
8476 auto ToType = importChecked(Err, E->getType());
8477 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8478 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8479 if (Err)
8480 return std::move(Err);
8481
8483 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8484 return std::move(Err);
8485
8487 Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
8488 ToParenOrBraceRange, E->hadMultipleCandidates(),
8491}
8492
8495 DeclContext *DC, *LexicalDC;
8496 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
8497 return std::move(Err);
8498
8499 Error Err = Error::success();
8500 auto Temporary = importChecked(Err, D->getTemporaryExpr());
8501 auto ExtendingDecl = importChecked(Err, D->getExtendingDecl());
8502 if (Err)
8503 return std::move(Err);
8504 // FIXME: Should ManglingNumber get numbers associated with 'to' context?
8505
8507 if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl,
8508 D->getManglingNumber()))
8509 return To;
8510
8511 To->setLexicalDeclContext(LexicalDC);
8512 LexicalDC->addDeclInternal(To);
8513 return To;
8514}
8515
8518 Error Err = Error::success();
8519 auto ToType = importChecked(Err, E->getType());
8520 Expr *ToTemporaryExpr = importChecked(
8521 Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr());
8522 auto ToMaterializedDecl =
8524 if (Err)
8525 return std::move(Err);
8526
8527 if (!ToTemporaryExpr)
8528 ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
8529
8530 auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
8531 ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
8532 ToMaterializedDecl);
8533
8534 return ToMTE;
8535}
8536
8538 Error Err = Error::success();
8539 auto *ToPattern = importChecked(Err, E->getPattern());
8540 auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8541 if (Err)
8542 return std::move(Err);
8543
8544 return new (Importer.getToContext())
8545 PackExpansionExpr(ToPattern, ToEllipsisLoc, E->getNumExpansions());
8546}
8547
8549 Error Err = Error::success();
8550 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8551 auto ToPack = importChecked(Err, E->getPack());
8552 auto ToPackLoc = importChecked(Err, E->getPackLoc());
8553 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8554 if (Err)
8555 return std::move(Err);
8556
8557 UnsignedOrNone Length = std::nullopt;
8558 if (!E->isValueDependent())
8559 Length = E->getPackLength();
8560
8561 SmallVector<TemplateArgument, 8> ToPartialArguments;
8562 if (E->isPartiallySubstituted()) {
8564 ToPartialArguments))
8565 return std::move(Err);
8566 }
8567
8569 Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
8570 Length, ToPartialArguments);
8571}
8572
8573
8575 Error Err = Error::success();
8576 auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
8577 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8578 auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens());
8579 auto ToArraySize = importChecked(Err, E->getArraySize());
8580 auto ToInitializer = importChecked(Err, E->getInitializer());
8581 auto ToType = importChecked(Err, E->getType());
8582 auto ToAllocatedTypeSourceInfo =
8584 auto ToSourceRange = importChecked(Err, E->getSourceRange());
8585 auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange());
8586 if (Err)
8587 return std::move(Err);
8588
8589 SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
8590 if (Error Err =
8591 ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
8592 return std::move(Err);
8593
8594 return CXXNewExpr::Create(
8595 Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
8596 ToOperatorDelete, E->implicitAllocationParameters(),
8597 E->doesUsualArrayDeleteWantSize(), ToPlacementArgs, ToTypeIdParens,
8598 ToArraySize, E->getInitializationStyle(), ToInitializer, ToType,
8599 ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange);
8600}
8601
8603 Error Err = Error::success();
8604 auto ToType = importChecked(Err, E->getType());
8605 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8606 auto ToArgument = importChecked(Err, E->getArgument());
8607 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8608 if (Err)
8609 return std::move(Err);
8610
8611 return new (Importer.getToContext()) CXXDeleteExpr(
8612 ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
8613 E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
8614 ToBeginLoc);
8615}
8616
8618 Error Err = Error::success();
8619 auto ToType = importChecked(Err, E->getType());
8620 auto ToLocation = importChecked(Err, E->getLocation());
8621 auto ToConstructor = importChecked(Err, E->getConstructor());
8622 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8623 if (Err)
8624 return std::move(Err);
8625
8627 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8628 return std::move(Err);
8629
8631 Importer.getToContext(), ToType, ToLocation, ToConstructor,
8632 E->isElidable(), ToArgs, E->hadMultipleCandidates(),
8635 ToParenOrBraceRange);
8637 return ToE;
8638}
8639
8641 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8642 if (!ToSubExprOrErr)
8643 return ToSubExprOrErr.takeError();
8644
8646 if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
8647 return std::move(Err);
8648
8650 Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
8651 ToObjects);
8652}
8653
8655 Error Err = Error::success();
8656 auto ToCallee = importChecked(Err, E->getCallee());
8657 auto ToType = importChecked(Err, E->getType());
8658 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8659 if (Err)
8660 return std::move(Err);
8661
8663 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8664 return std::move(Err);
8665
8666 return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
8667 ToType, E->getValueKind(), ToRParenLoc,
8668 E->getFPFeatures());
8669}
8670
8672 ExpectedType ToTypeOrErr = import(E->getType());
8673 if (!ToTypeOrErr)
8674 return ToTypeOrErr.takeError();
8675
8676 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8677 if (!ToLocationOrErr)
8678 return ToLocationOrErr.takeError();
8679
8680 return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
8681 *ToTypeOrErr, E->isImplicit());
8682}
8683
8685 ExpectedType ToTypeOrErr = import(E->getType());
8686 if (!ToTypeOrErr)
8687 return ToTypeOrErr.takeError();
8688
8689 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8690 if (!ToLocationOrErr)
8691 return ToLocationOrErr.takeError();
8692
8693 return CXXBoolLiteralExpr::Create(Importer.getToContext(), E->getValue(),
8694 *ToTypeOrErr, *ToLocationOrErr);
8695}
8696
8698 Error Err = Error::success();
8699 auto ToBase = importChecked(Err, E->getBase());
8700 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8701 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8702 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8703 auto ToMemberDecl = importChecked(Err, E->getMemberDecl());
8704 auto ToType = importChecked(Err, E->getType());
8705 auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl());
8706 auto ToName = importChecked(Err, E->getMemberNameInfo().getName());
8707 auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc());
8708 if (Err)
8709 return std::move(Err);
8710
8711 DeclAccessPair ToFoundDecl =
8713
8714 DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
8715
8716 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8717 if (E->hasExplicitTemplateArgs()) {
8718 if (Error Err =
8720 E->template_arguments(), ToTAInfo))
8721 return std::move(Err);
8722 ResInfo = &ToTAInfo;
8723 }
8724
8725 return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(),
8726 ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8727 ToMemberDecl, ToFoundDecl, ToMemberNameInfo,
8728 ResInfo, ToType, E->getValueKind(),
8729 E->getObjectKind(), E->isNonOdrUse());
8730}
8731
8734 Error Err = Error::success();
8735 auto ToBase = importChecked(Err, E->getBase());
8736 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8737 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8738 auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo());
8739 auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc());
8740 auto ToTildeLoc = importChecked(Err, E->getTildeLoc());
8741 if (Err)
8742 return std::move(Err);
8743
8745 if (const IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
8746 const IdentifierInfo *ToII = Importer.Import(FromII);
8747 ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
8748 if (!ToDestroyedTypeLocOrErr)
8749 return ToDestroyedTypeLocOrErr.takeError();
8750 Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
8751 } else {
8752 if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
8753 Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
8754 else
8755 return ToTIOrErr.takeError();
8756 }
8757
8758 return new (Importer.getToContext()) CXXPseudoDestructorExpr(
8759 Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
8760 ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
8761}
8762
8765 Error Err = Error::success();
8766 auto ToType = importChecked(Err, E->getType());
8767 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8768 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8769 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8770 auto ToFirstQualifierFoundInScope =
8772 if (Err)
8773 return std::move(Err);
8774
8775 Expr *ToBase = nullptr;
8776 if (!E->isImplicitAccess()) {
8777 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8778 ToBase = *ToBaseOrErr;
8779 else
8780 return ToBaseOrErr.takeError();
8781 }
8782
8783 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8784
8785 if (E->hasExplicitTemplateArgs()) {
8786 if (Error Err =
8788 E->template_arguments(), ToTAInfo))
8789 return std::move(Err);
8790 ResInfo = &ToTAInfo;
8791 }
8792 auto ToMember = importChecked(Err, E->getMember());
8793 auto ToMemberLoc = importChecked(Err, E->getMemberLoc());
8794 if (Err)
8795 return std::move(Err);
8796 DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc);
8797
8798 // Import additional name location/type info.
8799 if (Error Err =
8800 ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo))
8801 return std::move(Err);
8802
8804 Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
8805 ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
8806 ToMemberNameInfo, ResInfo);
8807}
8808
8811 Error Err = Error::success();
8812 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8813 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8814 auto ToDeclName = importChecked(Err, E->getDeclName());
8815 auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc());
8816 auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc());
8817 auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc());
8818 if (Err)
8819 return std::move(Err);
8820
8821 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8822 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8823 return std::move(Err);
8824
8825 TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
8826 TemplateArgumentListInfo *ResInfo = nullptr;
8827 if (E->hasExplicitTemplateArgs()) {
8828 if (Error Err =
8830 return std::move(Err);
8831 ResInfo = &ToTAInfo;
8832 }
8833
8835 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
8836 ToNameInfo, ResInfo);
8837}
8838
8841 Error Err = Error::success();
8842 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8843 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8844 auto ToType = importChecked(Err, E->getType());
8845 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8846 if (Err)
8847 return std::move(Err);
8848
8850 if (Error Err =
8851 ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
8852 return std::move(Err);
8853
8855 Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc,
8856 ArrayRef(ToArgs), ToRParenLoc, E->isListInitialization());
8857}
8858
8861 Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
8862 if (!ToNamingClassOrErr)
8863 return ToNamingClassOrErr.takeError();
8864
8865 auto ToQualifierLocOrErr = import(E->getQualifierLoc());
8866 if (!ToQualifierLocOrErr)
8867 return ToQualifierLocOrErr.takeError();
8868
8869 Error Err = Error::success();
8870 auto ToName = importChecked(Err, E->getName());
8871 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8872 if (Err)
8873 return std::move(Err);
8874 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8875
8876 // Import additional name location/type info.
8877 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8878 return std::move(Err);
8879
8880 UnresolvedSet<8> ToDecls;
8881 for (auto *D : E->decls())
8882 if (auto ToDOrErr = import(D))
8883 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8884 else
8885 return ToDOrErr.takeError();
8886
8887 if (E->hasExplicitTemplateArgs()) {
8888 TemplateArgumentListInfo ToTAInfo;
8891 ToTAInfo))
8892 return std::move(Err);
8893
8894 ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
8895 if (!ToTemplateKeywordLocOrErr)
8896 return ToTemplateKeywordLocOrErr.takeError();
8897
8898 const bool KnownDependent =
8899 (E->getDependence() & ExprDependence::TypeValue) ==
8900 ExprDependence::TypeValue;
8902 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8903 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
8904 ToDecls.begin(), ToDecls.end(), KnownDependent,
8905 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8906 }
8907
8909 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8910 ToNameInfo, E->requiresADL(), ToDecls.begin(), ToDecls.end(),
8911 /*KnownDependent=*/E->isTypeDependent(),
8912 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8913}
8914
8917 Error Err = Error::success();
8918 auto ToType = importChecked(Err, E->getType());
8919 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8920 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8921 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8922 auto ToName = importChecked(Err, E->getName());
8923 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8924 if (Err)
8925 return std::move(Err);
8926
8927 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8928 // Import additional name location/type info.
8929 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8930 return std::move(Err);
8931
8932 UnresolvedSet<8> ToDecls;
8933 for (Decl *D : E->decls())
8934 if (auto ToDOrErr = import(D))
8935 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8936 else
8937 return ToDOrErr.takeError();
8938
8939 TemplateArgumentListInfo ToTAInfo;
8940 TemplateArgumentListInfo *ResInfo = nullptr;
8941 if (E->hasExplicitTemplateArgs()) {
8942 TemplateArgumentListInfo FromTAInfo;
8943 E->copyTemplateArgumentsInto(FromTAInfo);
8944 if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo))
8945 return std::move(Err);
8946 ResInfo = &ToTAInfo;
8947 }
8948
8949 Expr *ToBase = nullptr;
8950 if (!E->isImplicitAccess()) {
8951 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8952 ToBase = *ToBaseOrErr;
8953 else
8954 return ToBaseOrErr.takeError();
8955 }
8956
8958 Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
8959 E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8960 ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
8961}
8962
8964 Error Err = Error::success();
8965 auto ToCallee = importChecked(Err, E->getCallee());
8966 auto ToType = importChecked(Err, E->getType());
8967 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8968 if (Err)
8969 return std::move(Err);
8970
8971 unsigned NumArgs = E->getNumArgs();
8972 llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
8973 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8974 return std::move(Err);
8975
8976 if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
8978 Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
8979 OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
8980 OCE->getADLCallKind());
8981 }
8982
8983 return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
8984 E->getValueKind(), ToRParenLoc, E->getFPFeatures(),
8985 /*MinNumArgs=*/0, E->getADLCallKind());
8986}
8987
8989 CXXRecordDecl *FromClass = E->getLambdaClass();
8990 auto ToClassOrErr = import(FromClass);
8991 if (!ToClassOrErr)
8992 return ToClassOrErr.takeError();
8993 CXXRecordDecl *ToClass = *ToClassOrErr;
8994
8995 auto ToCallOpOrErr = import(E->getCallOperator());
8996 if (!ToCallOpOrErr)
8997 return ToCallOpOrErr.takeError();
8998
8999 SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
9000 if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
9001 return std::move(Err);
9002
9003 Error Err = Error::success();
9004 auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange());
9005 auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc());
9006 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9007 if (Err)
9008 return std::move(Err);
9009
9010 return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange,
9011 E->getCaptureDefault(), ToCaptureDefaultLoc,
9013 E->hasExplicitResultType(), ToCaptureInits,
9014 ToEndLoc, E->containsUnexpandedParameterPack());
9015}
9016
9017
9019 Error Err = Error::success();
9020 auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
9021 auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc());
9022 auto ToType = importChecked(Err, E->getType());
9023 if (Err)
9024 return std::move(Err);
9025
9026 SmallVector<Expr *, 4> ToExprs(E->getNumInits());
9027 if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
9028 return std::move(Err);
9029
9030 ASTContext &ToCtx = Importer.getToContext();
9031 InitListExpr *To = new (ToCtx) InitListExpr(
9032 ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc);
9033 To->setType(ToType);
9034
9035 if (E->hasArrayFiller()) {
9036 if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
9037 To->setArrayFiller(*ToFillerOrErr);
9038 else
9039 return ToFillerOrErr.takeError();
9040 }
9041
9042 if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
9043 if (auto ToFDOrErr = import(FromFD))
9044 To->setInitializedFieldInUnion(*ToFDOrErr);
9045 else
9046 return ToFDOrErr.takeError();
9047 }
9048
9049 if (InitListExpr *SyntForm = E->getSyntacticForm()) {
9050 if (auto ToSyntFormOrErr = import(SyntForm))
9051 To->setSyntacticForm(*ToSyntFormOrErr);
9052 else
9053 return ToSyntFormOrErr.takeError();
9054 }
9055
9056 // Copy InitListExprBitfields, which are not handled in the ctor of
9057 // InitListExpr.
9059
9060 return To;
9061}
9062
9065 ExpectedType ToTypeOrErr = import(E->getType());
9066 if (!ToTypeOrErr)
9067 return ToTypeOrErr.takeError();
9068
9069 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
9070 if (!ToSubExprOrErr)
9071 return ToSubExprOrErr.takeError();
9072
9073 return new (Importer.getToContext()) CXXStdInitializerListExpr(
9074 *ToTypeOrErr, *ToSubExprOrErr);
9075}
9076
9079 Error Err = Error::success();
9080 auto ToLocation = importChecked(Err, E->getLocation());
9081 auto ToType = importChecked(Err, E->getType());
9082 auto ToConstructor = importChecked(Err, E->getConstructor());
9083 if (Err)
9084 return std::move(Err);
9085
9086 return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
9087 ToLocation, ToType, ToConstructor, E->constructsVBase(),
9088 E->inheritedFromVBase());
9089}
9090
9092 Error Err = Error::success();
9093 auto ToType = importChecked(Err, E->getType());
9094 auto ToCommonExpr = importChecked(Err, E->getCommonExpr());
9095 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9096 if (Err)
9097 return std::move(Err);
9098
9099 return new (Importer.getToContext()) ArrayInitLoopExpr(
9100 ToType, ToCommonExpr, ToSubExpr);
9101}
9102
9104 ExpectedType ToTypeOrErr = import(E->getType());
9105 if (!ToTypeOrErr)
9106 return ToTypeOrErr.takeError();
9107 return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
9108}
9109
9111 ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
9112 if (!ToBeginLocOrErr)
9113 return ToBeginLocOrErr.takeError();
9114
9115 auto ToFieldOrErr = import(E->getField());
9116 if (!ToFieldOrErr)
9117 return ToFieldOrErr.takeError();
9118
9119 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
9120 if (!UsedContextOrErr)
9121 return UsedContextOrErr.takeError();
9122
9123 FieldDecl *ToField = *ToFieldOrErr;
9124 assert(ToField->hasInClassInitializer() &&
9125 "Field should have in-class initializer if there is a default init "
9126 "expression that uses it.");
9127 if (!ToField->getInClassInitializer()) {
9128 // The in-class initializer may be not yet set in "To" AST even if the
9129 // field is already there. This must be set here to make construction of
9130 // CXXDefaultInitExpr work.
9131 auto ToInClassInitializerOrErr =
9132 import(E->getField()->getInClassInitializer());
9133 if (!ToInClassInitializerOrErr)
9134 return ToInClassInitializerOrErr.takeError();
9135 ToField->setInClassInitializer(*ToInClassInitializerOrErr);
9136 }
9137
9138 Expr *RewrittenInit = nullptr;
9139 if (E->hasRewrittenInit()) {
9140 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
9141 if (!ExprOrErr)
9142 return ExprOrErr.takeError();
9143 RewrittenInit = ExprOrErr.get();
9144 }
9145
9146 return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr,
9147 ToField, *UsedContextOrErr, RewrittenInit);
9148}
9149
9151 Error Err = Error::success();
9152 auto ToType = importChecked(Err, E->getType());
9153 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9154 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
9155 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
9156 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
9157 auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets());
9158 if (Err)
9159 return std::move(Err);
9160
9162 CastKind CK = E->getCastKind();
9163 auto ToBasePathOrErr = ImportCastPath(E);
9164 if (!ToBasePathOrErr)
9165 return ToBasePathOrErr.takeError();
9166
9167 if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) {
9169 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9170 ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc,
9171 ToAngleBrackets);
9172 } else if (isa<CXXDynamicCastExpr>(E)) {
9174 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9175 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9176 } else if (isa<CXXReinterpretCastExpr>(E)) {
9178 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9179 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9180 } else if (isa<CXXConstCastExpr>(E)) {
9182 Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
9183 ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9184 } else {
9185 llvm_unreachable("Unknown cast type");
9186 return make_error<ASTImportError>();
9187 }
9188}
9189
9192 Error Err = Error::success();
9193 auto ToType = importChecked(Err, E->getType());
9194 auto ToNameLoc = importChecked(Err, E->getNameLoc());
9195 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9196 auto ToReplacement = importChecked(Err, E->getReplacement());
9197 if (Err)
9198 return std::move(Err);
9199
9200 return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
9201 ToType, E->getValueKind(), ToNameLoc, ToReplacement, ToAssociatedDecl,
9203 E->getFinal());
9204}
9205
9207 Error Err = Error::success();
9208 auto ToType = importChecked(Err, E->getType());
9209 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9210 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9211 if (Err)
9212 return std::move(Err);
9213
9215 if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
9216 return std::move(Err);
9217
9218 if (E->isStoredAsBoolean()) {
9219 // According to Sema::BuildTypeTrait(), if E is value-dependent,
9220 // Value is always false.
9221 bool ToValue = (E->isValueDependent() ? false : E->getBoolValue());
9222 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9223 E->getTrait(), ToArgs, ToEndLoc, ToValue);
9224 }
9225 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9226 E->getTrait(), ToArgs, ToEndLoc,
9227 E->getAPValue());
9228}
9229
9231 ExpectedType ToTypeOrErr = import(E->getType());
9232 if (!ToTypeOrErr)
9233 return ToTypeOrErr.takeError();
9234
9235 auto ToSourceRangeOrErr = import(E->getSourceRange());
9236 if (!ToSourceRangeOrErr)
9237 return ToSourceRangeOrErr.takeError();
9238
9239 if (E->isTypeOperand()) {
9240 if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
9241 return new (Importer.getToContext()) CXXTypeidExpr(
9242 *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
9243 else
9244 return ToTSIOrErr.takeError();
9245 }
9246
9247 ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
9248 if (!ToExprOperandOrErr)
9249 return ToExprOperandOrErr.takeError();
9250
9251 return new (Importer.getToContext()) CXXTypeidExpr(
9252 *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
9253}
9254
9256 Error Err = Error::success();
9257
9258 QualType ToType = importChecked(Err, E->getType());
9259 UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
9260 SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
9261 Expr *ToLHS = importChecked(Err, E->getLHS());
9262 SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
9263 Expr *ToRHS = importChecked(Err, E->getRHS());
9264 SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
9265
9266 if (Err)
9267 return std::move(Err);
9268
9269 return new (Importer.getToContext())
9270 CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
9271 ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
9272}
9273
9275 Error Err = Error::success();
9276 auto RequiresKWLoc = importChecked(Err, E->getRequiresKWLoc());
9277 auto RParenLoc = importChecked(Err, E->getRParenLoc());
9278 auto RBraceLoc = importChecked(Err, E->getRBraceLoc());
9279
9280 auto Body = importChecked(Err, E->getBody());
9281 auto LParenLoc = importChecked(Err, E->getLParenLoc());
9282 if (Err)
9283 return std::move(Err);
9284 SmallVector<ParmVarDecl *, 4> LocalParameters(E->getLocalParameters().size());
9285 if (Error Err =
9286 ImportArrayChecked(E->getLocalParameters(), LocalParameters.begin()))
9287 return std::move(Err);
9289 E->getRequirements().size());
9290 if (Error Err =
9291 ImportArrayChecked(E->getRequirements(), Requirements.begin()))
9292 return std::move(Err);
9293 return RequiresExpr::Create(Importer.getToContext(), RequiresKWLoc, Body,
9294 LParenLoc, LocalParameters, RParenLoc,
9295 Requirements, RBraceLoc);
9296}
9297
9300 Error Err = Error::success();
9301 auto CL = importChecked(Err, E->getConceptReference());
9302 auto CSD = importChecked(Err, E->getSpecializationDecl());
9303 if (Err)
9304 return std::move(Err);
9305 if (E->isValueDependent())
9307 Importer.getToContext(), CL,
9308 const_cast<ImplicitConceptSpecializationDecl *>(CSD), nullptr);
9309 ConstraintSatisfaction Satisfaction;
9310 if (Error Err =
9312 return std::move(Err);
9314 Importer.getToContext(), CL,
9315 const_cast<ImplicitConceptSpecializationDecl *>(CSD), &Satisfaction);
9316}
9317
9320 Error Err = Error::success();
9321 auto ToType = importChecked(Err, E->getType());
9322 auto ToPackLoc = importChecked(Err, E->getParameterPackLocation());
9323 auto ToArgPack = importChecked(Err, E->getArgumentPack());
9324 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9325 if (Err)
9326 return std::move(Err);
9327
9328 return new (Importer.getToContext()) SubstNonTypeTemplateParmPackExpr(
9329 ToType, E->getValueKind(), ToPackLoc, ToArgPack, ToAssociatedDecl,
9330 E->getIndex(), E->getFinal());
9331}
9332
9335 if (Error Err = ImportContainerChecked(E->semantics(), ToSemantics))
9336 return std::move(Err);
9337 auto ToSyntOrErr = import(E->getSyntacticForm());
9338 if (!ToSyntOrErr)
9339 return ToSyntOrErr.takeError();
9340 return PseudoObjectExpr::Create(Importer.getToContext(), *ToSyntOrErr,
9341 ToSemantics, E->getResultExprIndex());
9342}
9343
9346 Error Err = Error::success();
9347 auto ToType = importChecked(Err, E->getType());
9348 auto ToInitLoc = importChecked(Err, E->getInitLoc());
9349 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9350 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9351 if (Err)
9352 return std::move(Err);
9353
9354 SmallVector<Expr *, 4> ToArgs(E->getInitExprs().size());
9355 if (Error Err = ImportContainerChecked(E->getInitExprs(), ToArgs))
9356 return std::move(Err);
9357 return CXXParenListInitExpr::Create(Importer.getToContext(), ToArgs, ToType,
9358 E->getUserSpecifiedInitExprs().size(),
9359 ToInitLoc, ToBeginLoc, ToEndLoc);
9360}
9361
9363 CXXMethodDecl *FromMethod) {
9364 Error ImportErrors = Error::success();
9365 for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
9366 if (auto ImportedOrErr = import(FromOverriddenMethod))
9368 (*ImportedOrErr)->getCanonicalDecl()));
9369 else
9370 ImportErrors =
9371 joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
9372 }
9373 return ImportErrors;
9374}
9375
9377 ASTContext &FromContext, FileManager &FromFileManager,
9378 bool MinimalImport,
9379 std::shared_ptr<ASTImporterSharedState> SharedState)
9380 : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
9381 ToFileManager(ToFileManager), FromFileManager(FromFileManager),
9382 Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) {
9383
9384 // Create a default state without the lookup table: LLDB case.
9385 if (!SharedState) {
9386 this->SharedState = std::make_shared<ASTImporterSharedState>();
9387 }
9388
9389 ImportedDecls[FromContext.getTranslationUnitDecl()] =
9390 ToContext.getTranslationUnitDecl();
9391}
9392
9393ASTImporter::~ASTImporter() = default;
9394
9396 assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
9397 "Try to get field index for non-field.");
9398
9399 auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
9400 if (!Owner)
9401 return std::nullopt;
9402
9403 unsigned Index = 0;
9404 for (const auto *D : Owner->decls()) {
9405 if (D == F)
9406 return Index;
9407
9409 ++Index;
9410 }
9411
9412 llvm_unreachable("Field was not found in its parent context.");
9413
9414 return std::nullopt;
9415}
9416
9417ASTImporter::FoundDeclsTy
9418ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
9419 // We search in the redecl context because of transparent contexts.
9420 // E.g. a simple C language enum is a transparent context:
9421 // enum E { A, B };
9422 // Now if we had a global variable in the TU
9423 // int A;
9424 // then the enum constant 'A' and the variable 'A' violates ODR.
9425 // We can diagnose this only if we search in the redecl context.
9426 DeclContext *ReDC = DC->getRedeclContext();
9427 if (SharedState->getLookupTable()) {
9428 if (ReDC->isNamespace()) {
9429 // Namespaces can be reopened.
9430 // Lookup table does not handle this, we must search here in all linked
9431 // namespaces.
9432 FoundDeclsTy Result;
9433 SmallVector<Decl *, 2> NSChain =
9435 dyn_cast<NamespaceDecl>(ReDC));
9436 for (auto *D : NSChain) {
9438 SharedState->getLookupTable()->lookup(dyn_cast<NamespaceDecl>(D),
9439 Name);
9441 }
9442 return Result;
9443 } else {
9445 SharedState->getLookupTable()->lookup(ReDC, Name);
9446 return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
9447 }
9448 } else {
9449 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
9450 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
9451 // We must search by the slow case of localUncachedLookup because that is
9452 // working even if there is no LookupPtr for the DC. We could use
9453 // DC::buildLookup() to create the LookupPtr, but that would load external
9454 // decls again, we must avoid that case.
9455 // Also, even if we had the LookupPtr, we must find Decls which are not
9456 // in the LookupPtr, so we need the slow case.
9457 // These cases are handled in ASTImporterLookupTable, but we cannot use
9458 // that with LLDB since that traverses through the AST which initiates the
9459 // load of external decls again via DC::decls(). And again, we must avoid
9460 // loading external decls during the import.
9461 if (Result.empty())
9462 ReDC->localUncachedLookup(Name, Result);
9463 return Result;
9464 }
9465}
9466
9467void ASTImporter::AddToLookupTable(Decl *ToD) {
9468 SharedState->addDeclToLookup(ToD);
9469}
9470
9472 // Import the decl using ASTNodeImporter.
9473 ASTNodeImporter Importer(*this);
9474 return Importer.Visit(FromD);
9475}
9476
9478 MapImported(FromD, ToD);
9479}
9480
9483 if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) {
9484 if (Expected<Expr *> R = Import(CLE))
9486 }
9487
9488 // FIXME: Handle BlockDecl when we implement importing BlockExpr in
9489 // ASTNodeImporter.
9490 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
9491}
9492
9494 if (!FromT)
9495 return FromT;
9496
9497 // Check whether we've already imported this type.
9498 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
9499 ImportedTypes.find(FromT);
9500 if (Pos != ImportedTypes.end())
9501 return Pos->second;
9502
9503 // Import the type.
9504 ASTNodeImporter Importer(*this);
9505 ExpectedType ToTOrErr = Importer.Visit(FromT);
9506 if (!ToTOrErr)
9507 return ToTOrErr.takeError();
9508
9509 // Record the imported type.
9510 ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9511
9512 return ToTOrErr->getTypePtr();
9513}
9514
9516 if (FromT.isNull())
9517 return QualType{};
9518
9519 ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9520 if (!ToTyOrErr)
9521 return ToTyOrErr.takeError();
9522
9523 return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9524}
9525
9527 if (!FromTSI)
9528 return FromTSI;
9529
9530 // FIXME: For now we just create a "trivial" type source info based
9531 // on the type and a single location. Implement a real version of this.
9532 ExpectedType TOrErr = Import(FromTSI->getType());
9533 if (!TOrErr)
9534 return TOrErr.takeError();
9535 ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9536 if (!BeginLocOrErr)
9537 return BeginLocOrErr.takeError();
9538
9539 return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9540}
9541
9542namespace {
9543// To use this object, it should be created before the new attribute is created,
9544// and destructed after it is created. The construction already performs the
9545// import of the data.
9546template <typename T> struct AttrArgImporter {
9547 AttrArgImporter(const AttrArgImporter<T> &) = delete;
9548 AttrArgImporter(AttrArgImporter<T> &&) = default;
9549 AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9550 AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9551
9552 AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9553 : To(I.importChecked(Err, From)) {}
9554
9555 const T &value() { return To; }
9556
9557private:
9558 T To;
9559};
9560
9561// To use this object, it should be created before the new attribute is created,
9562// and destructed after it is created. The construction already performs the
9563// import of the data. The array data is accessible in a pointer form, this form
9564// is used by the attribute classes. This object should be created once for the
9565// array data to be imported (the array size is not imported, just copied).
9566template <typename T> struct AttrArgArrayImporter {
9567 AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9568 AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9569 AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9570 AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9571
9572 AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9573 const llvm::iterator_range<T *> &From,
9574 unsigned ArraySize) {
9575 if (Err)
9576 return;
9577 To.reserve(ArraySize);
9578 Err = I.ImportContainerChecked(From, To);
9579 }
9580
9581 T *value() { return To.data(); }
9582
9583private:
9584 llvm::SmallVector<T, 2> To;
9585};
9586
9587class AttrImporter {
9588 Error Err{Error::success()};
9589 Attr *ToAttr = nullptr;
9590 ASTImporter &Importer;
9591 ASTNodeImporter NImporter;
9592
9593public:
9594 AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9595
9596 // Useful for accessing the imported attribute.
9597 template <typename T> T *castAttrAs() { return cast<T>(ToAttr); }
9598 template <typename T> const T *castAttrAs() const { return cast<T>(ToAttr); }
9599
9600 // Create an "importer" for an attribute parameter.
9601 // Result of the 'value()' of that object is to be passed to the function
9602 // 'importAttr', in the order that is expected by the attribute class.
9603 template <class T> AttrArgImporter<T> importArg(const T &From) {
9604 return AttrArgImporter<T>(NImporter, Err, From);
9605 }
9606
9607 // Create an "importer" for an attribute parameter that has array type.
9608 // Result of the 'value()' of that object is to be passed to the function
9609 // 'importAttr', then the size of the array as next argument.
9610 template <typename T>
9611 AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9612 unsigned ArraySize) {
9613 return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9614 }
9615
9616 // Create an attribute object with the specified arguments.
9617 // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9618 // should be values that are passed to the 'Create' function of the attribute.
9619 // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9620 // used here.) As much data is copied or imported from the old attribute
9621 // as possible. The passed arguments should be already imported.
9622 // If an import error happens, the internal error is set to it, and any
9623 // further import attempt is ignored.
9624 template <typename T, typename... Arg>
9625 void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9626 static_assert(std::is_base_of<Attr, T>::value,
9627 "T should be subclass of Attr.");
9628 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9629
9630 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9631 const IdentifierInfo *ToScopeName =
9632 Importer.Import(FromAttr->getScopeName());
9633 SourceRange ToAttrRange =
9634 NImporter.importChecked(Err, FromAttr->getRange());
9635 SourceLocation ToScopeLoc =
9636 NImporter.importChecked(Err, FromAttr->getScopeLoc());
9637
9638 if (Err)
9639 return;
9640
9641 AttributeCommonInfo ToI(
9642 ToAttrName, AttributeScopeInfo(ToScopeName, ToScopeLoc), ToAttrRange,
9643 FromAttr->getParsedKind(), FromAttr->getForm());
9644 // The "SemanticSpelling" is not needed to be passed to the constructor.
9645 // That value is recalculated from the SpellingListIndex if needed.
9646 ToAttr = T::Create(Importer.getToContext(),
9647 std::forward<Arg>(ImportedArg)..., ToI);
9648
9649 ToAttr->setImplicit(FromAttr->isImplicit());
9650 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9651 if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9652 ToInheritableAttr->setInherited(FromAttr->isInherited());
9653 }
9654
9655 // Create a clone of the 'FromAttr' and import its source range only.
9656 // This causes objects with invalid references to be created if the 'FromAttr'
9657 // contains other data that should be imported.
9658 void cloneAttr(const Attr *FromAttr) {
9659 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9660
9661 SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9662 if (Err)
9663 return;
9664
9665 ToAttr = FromAttr->clone(Importer.getToContext());
9666 ToAttr->setRange(ToRange);
9667 ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9668 }
9669
9670 // Get the result of the previous import attempt (can be used only once).
9671 llvm::Expected<Attr *> getResult() && {
9672 if (Err)
9673 return std::move(Err);
9674 assert(ToAttr && "Attribute should be created.");
9675 return ToAttr;
9676 }
9677};
9678} // namespace
9679
9681 AttrImporter AI(*this);
9682
9683 // FIXME: Is there some kind of AttrVisitor to use here?
9684 switch (FromAttr->getKind()) {
9685 case attr::Aligned: {
9686 auto *From = cast<AlignedAttr>(FromAttr);
9687 if (From->isAlignmentExpr())
9688 AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9689 else
9690 AI.importAttr(From, false,
9691 AI.importArg(From->getAlignmentType()).value());
9692 break;
9693 }
9694
9695 case attr::AlignValue: {
9696 auto *From = cast<AlignValueAttr>(FromAttr);
9697 AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9698 break;
9699 }
9700
9701 case attr::Format: {
9702 const auto *From = cast<FormatAttr>(FromAttr);
9703 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9704 From->getFirstArg());
9705 break;
9706 }
9707
9708 case attr::EnableIf: {
9709 const auto *From = cast<EnableIfAttr>(FromAttr);
9710 AI.importAttr(From, AI.importArg(From->getCond()).value(),
9711 From->getMessage());
9712 break;
9713 }
9714
9715 case attr::AssertCapability: {
9716 const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9717 AI.importAttr(From,
9718 AI.importArrayArg(From->args(), From->args_size()).value(),
9719 From->args_size());
9720 break;
9721 }
9722 case attr::AcquireCapability: {
9723 const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9724 AI.importAttr(From,
9725 AI.importArrayArg(From->args(), From->args_size()).value(),
9726 From->args_size());
9727 break;
9728 }
9729 case attr::TryAcquireCapability: {
9730 const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9731 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9732 AI.importArrayArg(From->args(), From->args_size()).value(),
9733 From->args_size());
9734 break;
9735 }
9736 case attr::ReleaseCapability: {
9737 const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9738 AI.importAttr(From,
9739 AI.importArrayArg(From->args(), From->args_size()).value(),
9740 From->args_size());
9741 break;
9742 }
9743 case attr::RequiresCapability: {
9744 const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9745 AI.importAttr(From,
9746 AI.importArrayArg(From->args(), From->args_size()).value(),
9747 From->args_size());
9748 break;
9749 }
9750 case attr::GuardedBy: {
9751 const auto *From = cast<GuardedByAttr>(FromAttr);
9752 AI.importAttr(From, AI.importArg(From->getArg()).value());
9753 break;
9754 }
9755 case attr::PtGuardedBy: {
9756 const auto *From = cast<PtGuardedByAttr>(FromAttr);
9757 AI.importAttr(From, AI.importArg(From->getArg()).value());
9758 break;
9759 }
9760 case attr::AcquiredAfter: {
9761 const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9762 AI.importAttr(From,
9763 AI.importArrayArg(From->args(), From->args_size()).value(),
9764 From->args_size());
9765 break;
9766 }
9767 case attr::AcquiredBefore: {
9768 const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9769 AI.importAttr(From,
9770 AI.importArrayArg(From->args(), From->args_size()).value(),
9771 From->args_size());
9772 break;
9773 }
9774 case attr::LockReturned: {
9775 const auto *From = cast<LockReturnedAttr>(FromAttr);
9776 AI.importAttr(From, AI.importArg(From->getArg()).value());
9777 break;
9778 }
9779 case attr::LocksExcluded: {
9780 const auto *From = cast<LocksExcludedAttr>(FromAttr);
9781 AI.importAttr(From,
9782 AI.importArrayArg(From->args(), From->args_size()).value(),
9783 From->args_size());
9784 break;
9785 }
9786 default: {
9787 // The default branch works for attributes that have no arguments to import.
9788 // FIXME: Handle every attribute type that has arguments of type to import
9789 // (most often Expr* or Decl* or type) in the switch above.
9790 AI.cloneAttr(FromAttr);
9791 break;
9792 }
9793 }
9794
9795 return std::move(AI).getResult();
9796}
9797
9799 return ImportedDecls.lookup(FromD);
9800}
9801
9803 auto FromDPos = ImportedFromDecls.find(ToD);
9804 if (FromDPos == ImportedFromDecls.end())
9805 return nullptr;
9806 return FromDPos->second->getTranslationUnitDecl();
9807}
9808
9810 if (!FromD)
9811 return nullptr;
9812
9813 // Push FromD to the stack, and remove that when we return.
9814 ImportPath.push(FromD);
9815 llvm::scope_exit ImportPathBuilder([this]() { ImportPath.pop(); });
9816
9817 // Check whether there was a previous failed import.
9818 // If yes return the existing error.
9819 if (auto Error = getImportDeclErrorIfAny(FromD))
9820 return make_error<ASTImportError>(*Error);
9821
9822 // Check whether we've already imported this declaration.
9823 Decl *ToD = GetAlreadyImportedOrNull(FromD);
9824 if (ToD) {
9825 // Already imported (possibly from another TU) and with an error.
9826 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9827 setImportDeclError(FromD, *Error);
9828 return make_error<ASTImportError>(*Error);
9829 }
9830
9831 // If FromD has some updated flags after last import, apply it.
9832 updateFlags(FromD, ToD);
9833 // If we encounter a cycle during an import then we save the relevant part
9834 // of the import path associated to the Decl.
9835 if (ImportPath.hasCycleAtBack())
9836 SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9837 return ToD;
9838 }
9839
9840 // Import the declaration.
9841 ExpectedDecl ToDOrErr = ImportImpl(FromD);
9842 if (!ToDOrErr) {
9843 // Failed to import.
9844
9845 auto Pos = ImportedDecls.find(FromD);
9846 if (Pos != ImportedDecls.end()) {
9847 // Import failed after the object was created.
9848 // Remove all references to it.
9849 auto *ToD = Pos->second;
9850 ImportedDecls.erase(Pos);
9851
9852 // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9853 // (e.g. with namespaces) that several decls from the 'from' context are
9854 // mapped to the same decl in the 'to' context. If we removed entries
9855 // from the LookupTable here then we may end up removing them multiple
9856 // times.
9857
9858 // The Lookuptable contains decls only which are in the 'to' context.
9859 // Remove from the Lookuptable only if it is *imported* into the 'to'
9860 // context (and do not remove it if it was added during the initial
9861 // traverse of the 'to' context).
9862 auto PosF = ImportedFromDecls.find(ToD);
9863 if (PosF != ImportedFromDecls.end()) {
9864 // In the case of TypedefNameDecl we create the Decl first and only
9865 // then we import and set its DeclContext. So, the DC might not be set
9866 // when we reach here.
9867 if (ToD->getDeclContext())
9868 SharedState->removeDeclFromLookup(ToD);
9869 ImportedFromDecls.erase(PosF);
9870 }
9871
9872 // FIXME: AST may contain remaining references to the failed object.
9873 // However, the ImportDeclErrors in the shared state contains all the
9874 // failed objects together with their error.
9875 }
9876
9877 // Error encountered for the first time.
9878 // After takeError the error is not usable any more in ToDOrErr.
9879 // Get a copy of the error object (any more simple solution for this?).
9880 ASTImportError ErrOut;
9881 handleAllErrors(ToDOrErr.takeError(),
9882 [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9883 setImportDeclError(FromD, ErrOut);
9884 // Set the error for the mapped to Decl, which is in the "to" context.
9885 if (Pos != ImportedDecls.end())
9886 SharedState->setImportDeclError(Pos->second, ErrOut);
9887
9888 // Set the error for all nodes which have been created before we
9889 // recognized the error.
9890 for (const auto &Path : SavedImportPaths[FromD]) {
9891 // The import path contains import-dependency nodes first.
9892 // Save the node that was imported as dependency of the current node.
9893 Decl *PrevFromDi = FromD;
9894 for (Decl *FromDi : Path) {
9895 // Begin and end of the path equals 'FromD', skip it.
9896 if (FromDi == FromD)
9897 continue;
9898 // We should not set import error on a node and all following nodes in
9899 // the path if child import errors are ignored.
9900 if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9901 PrevFromDi))
9902 break;
9903 PrevFromDi = FromDi;
9904 setImportDeclError(FromDi, ErrOut);
9905 //FIXME Should we remove these Decls from ImportedDecls?
9906 // Set the error for the mapped to Decl, which is in the "to" context.
9907 auto Ii = ImportedDecls.find(FromDi);
9908 if (Ii != ImportedDecls.end())
9909 SharedState->setImportDeclError(Ii->second, ErrOut);
9910 // FIXME Should we remove these Decls from the LookupTable,
9911 // and from ImportedFromDecls?
9912 }
9913 }
9914 SavedImportPaths.erase(FromD);
9915
9916 // Do not return ToDOrErr, error was taken out of it.
9917 return make_error<ASTImportError>(ErrOut);
9918 }
9919
9920 ToD = *ToDOrErr;
9921
9922 // FIXME: Handle the "already imported with error" case. We can get here
9923 // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
9924 // previously failed create was requested).
9925 // Later GetImportedOrCreateDecl can be updated to return the error.
9926 if (!ToD) {
9927 auto Err = getImportDeclErrorIfAny(FromD);
9928 assert(Err);
9929 return make_error<ASTImportError>(*Err);
9930 }
9931
9932 // We could import from the current TU without error. But previously we
9933 // already had imported a Decl as `ToD` from another TU (with another
9934 // ASTImporter object) and with an error.
9935 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9936 setImportDeclError(FromD, *Error);
9937 return make_error<ASTImportError>(*Error);
9938 }
9939 // Make sure that ImportImpl registered the imported decl.
9940 assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
9941
9942 if (FromD->hasAttrs())
9943 for (const Attr *FromAttr : FromD->getAttrs()) {
9944 auto ToAttrOrErr = Import(FromAttr);
9945 if (ToAttrOrErr)
9946 ToD->addAttr(*ToAttrOrErr);
9947 else
9948 return ToAttrOrErr.takeError();
9949 }
9950
9951 // Notify subclasses.
9952 Imported(FromD, ToD);
9953
9954 updateFlags(FromD, ToD);
9955 SavedImportPaths.erase(FromD);
9956 return ToDOrErr;
9957}
9958
9961 return ASTNodeImporter(*this).ImportInheritedConstructor(From);
9962}
9963
9965 if (!FromDC)
9966 return FromDC;
9967
9968 ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
9969 if (!ToDCOrErr)
9970 return ToDCOrErr.takeError();
9971 auto *ToDC = cast<DeclContext>(*ToDCOrErr);
9972
9973 // When we're using a record/enum/Objective-C class/protocol as a context, we
9974 // need it to have a definition.
9975 if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
9976 auto *FromRecord = cast<RecordDecl>(FromDC);
9977 if (ToRecord->isCompleteDefinition())
9978 return ToDC;
9979
9980 // If FromRecord is not defined we need to force it to be.
9981 // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
9982 // it will start the definition but we never finish it.
9983 // If there are base classes they won't be imported and we will
9984 // be missing anything that we inherit from those bases.
9985 if (FromRecord->getASTContext().getExternalSource() &&
9986 !FromRecord->isCompleteDefinition())
9987 FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
9988
9989 if (FromRecord->isCompleteDefinition())
9990 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9991 FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
9992 return std::move(Err);
9993 } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
9994 auto *FromEnum = cast<EnumDecl>(FromDC);
9995 if (ToEnum->isCompleteDefinition()) {
9996 // Do nothing.
9997 } else if (FromEnum->isCompleteDefinition()) {
9998 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9999 FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
10000 return std::move(Err);
10001 } else {
10002 CompleteDecl(ToEnum);
10003 }
10004 } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
10005 auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
10006 if (ToClass->getDefinition()) {
10007 // Do nothing.
10008 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
10009 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10010 FromDef, ToClass, ASTNodeImporter::IDK_Basic))
10011 return std::move(Err);
10012 } else {
10013 CompleteDecl(ToClass);
10014 }
10015 } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
10016 auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
10017 if (ToProto->getDefinition()) {
10018 // Do nothing.
10019 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
10020 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10021 FromDef, ToProto, ASTNodeImporter::IDK_Basic))
10022 return std::move(Err);
10023 } else {
10024 CompleteDecl(ToProto);
10025 }
10026 }
10027
10028 return ToDC;
10029}
10030
10032 if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
10033 return cast_or_null<Expr>(*ToSOrErr);
10034 else
10035 return ToSOrErr.takeError();
10036}
10037
10039 if (!FromS)
10040 return nullptr;
10041
10042 // Check whether we've already imported this statement.
10043 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
10044 if (Pos != ImportedStmts.end())
10045 return Pos->second;
10046
10047 // Import the statement.
10048 ASTNodeImporter Importer(*this);
10049 ExpectedStmt ToSOrErr = Importer.Visit(FromS);
10050 if (!ToSOrErr)
10051 return ToSOrErr;
10052
10053 if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
10054 auto *FromE = cast<Expr>(FromS);
10055 // Copy ExprBitfields, which may not be handled in Expr subclasses
10056 // constructors.
10057 ToE->setValueKind(FromE->getValueKind());
10058 ToE->setObjectKind(FromE->getObjectKind());
10059 ToE->setDependence(FromE->getDependence());
10060 }
10061
10062 // Record the imported statement object.
10063 ImportedStmts[FromS] = *ToSOrErr;
10064 return ToSOrErr;
10065}
10066
10068 switch (FromNNS.getKind()) {
10071 return FromNNS;
10073 auto [Namespace, Prefix] = FromNNS.getAsNamespaceAndPrefix();
10074 auto NSOrErr = Import(Namespace);
10075 if (!NSOrErr)
10076 return NSOrErr.takeError();
10077 auto PrefixOrErr = Import(Prefix);
10078 if (!PrefixOrErr)
10079 return PrefixOrErr.takeError();
10080 return NestedNameSpecifier(ToContext, cast<NamespaceBaseDecl>(*NSOrErr),
10081 *PrefixOrErr);
10082 }
10084 if (ExpectedDecl RDOrErr = Import(FromNNS.getAsMicrosoftSuper()))
10085 return NestedNameSpecifier(cast<CXXRecordDecl>(*RDOrErr));
10086 else
10087 return RDOrErr.takeError();
10089 if (ExpectedTypePtr TyOrErr = Import(FromNNS.getAsType())) {
10090 return NestedNameSpecifier(*TyOrErr);
10091 } else {
10092 return TyOrErr.takeError();
10093 }
10094 }
10095 llvm_unreachable("Invalid nested name specifier kind");
10096}
10097
10100 // Copied from NestedNameSpecifier mostly.
10102 NestedNameSpecifierLoc NNS = FromNNS;
10103
10104 // Push each of the nested-name-specifiers's onto a stack for
10105 // serialization in reverse order.
10106 while (NNS) {
10107 NestedNames.push_back(NNS);
10108 NNS = NNS.getAsNamespaceAndPrefix().Prefix;
10109 }
10110
10112
10113 while (!NestedNames.empty()) {
10114 NNS = NestedNames.pop_back_val();
10115 NestedNameSpecifier Spec = std::nullopt;
10116 if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
10117 return std::move(Err);
10118
10119 NestedNameSpecifier::Kind Kind = Spec.getKind();
10120
10121 SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
10123 if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
10124 return std::move(Err);
10125
10127 if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
10128 return std::move(Err);
10129 }
10130
10131 switch (Kind) {
10133 Builder.Extend(getToContext(), Spec.getAsNamespaceAndPrefix().Namespace,
10134 ToLocalBeginLoc, ToLocalEndLoc);
10135 break;
10136
10138 SourceLocation ToTLoc;
10139 if (Error Err = importInto(ToTLoc, NNS.castAsTypeLoc().getBeginLoc()))
10140 return std::move(Err);
10142 QualType(Spec.getAsType(), 0), ToTLoc);
10143 Builder.Make(getToContext(), TSI->getTypeLoc(), ToLocalEndLoc);
10144 break;
10145 }
10146
10148 Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
10149 break;
10150
10152 auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
10153 if (!ToSourceRangeOrErr)
10154 return ToSourceRangeOrErr.takeError();
10155
10156 Builder.MakeMicrosoftSuper(getToContext(), Spec.getAsMicrosoftSuper(),
10157 ToSourceRangeOrErr->getBegin(),
10158 ToSourceRangeOrErr->getEnd());
10159 break;
10160 }
10162 llvm_unreachable("unexpected null nested name specifier");
10163 }
10164 }
10165
10166 return Builder.getWithLocInContext(getToContext());
10167}
10168
10170 switch (From.getKind()) {
10172 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
10173 return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
10174 else
10175 return ToTemplateOrErr.takeError();
10176
10179 UnresolvedSet<2> ToTemplates;
10180 for (auto *I : *FromStorage) {
10181 if (auto ToOrErr = Import(I))
10182 ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
10183 else
10184 return ToOrErr.takeError();
10185 }
10186 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
10187 ToTemplates.end());
10188 }
10189
10192 auto DeclNameOrErr = Import(FromStorage->getDeclName());
10193 if (!DeclNameOrErr)
10194 return DeclNameOrErr.takeError();
10195 return ToContext.getAssumedTemplateName(*DeclNameOrErr);
10196 }
10197
10200 auto QualifierOrErr = Import(QTN->getQualifier());
10201 if (!QualifierOrErr)
10202 return QualifierOrErr.takeError();
10203 auto TNOrErr = Import(QTN->getUnderlyingTemplate());
10204 if (!TNOrErr)
10205 return TNOrErr.takeError();
10206 return ToContext.getQualifiedTemplateName(
10207 *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
10208 }
10209
10212 auto QualifierOrErr = Import(DTN->getQualifier());
10213 if (!QualifierOrErr)
10214 return QualifierOrErr.takeError();
10215 return ToContext.getDependentTemplateName(
10216 {*QualifierOrErr, Import(DTN->getName()), DTN->hasTemplateKeyword()});
10217 }
10218
10222 auto ReplacementOrErr = Import(Subst->getReplacement());
10223 if (!ReplacementOrErr)
10224 return ReplacementOrErr.takeError();
10225
10226 auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
10227 if (!AssociatedDeclOrErr)
10228 return AssociatedDeclOrErr.takeError();
10229
10230 return ToContext.getSubstTemplateTemplateParm(
10231 *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
10232 Subst->getPackIndex(), Subst->getFinal());
10233 }
10234
10238 ASTNodeImporter Importer(*this);
10239 auto ArgPackOrErr =
10240 Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
10241 if (!ArgPackOrErr)
10242 return ArgPackOrErr.takeError();
10243
10244 auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
10245 if (!AssociatedDeclOrErr)
10246 return AssociatedDeclOrErr.takeError();
10247
10248 return ToContext.getSubstTemplateTemplateParmPack(
10249 *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
10250 SubstPack->getFinal());
10251 }
10253 auto UsingOrError = Import(From.getAsUsingShadowDecl());
10254 if (!UsingOrError)
10255 return UsingOrError.takeError();
10256 return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
10257 }
10259 llvm_unreachable("Unexpected DeducedTemplate");
10260 }
10261
10262 llvm_unreachable("Invalid template name kind");
10263}
10264
10266 if (FromLoc.isInvalid())
10267 return SourceLocation{};
10268
10269 SourceManager &FromSM = FromContext.getSourceManager();
10270 bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
10271
10272 FileIDAndOffset Decomposed = FromSM.getDecomposedLoc(FromLoc);
10273 Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
10274 if (!ToFileIDOrErr)
10275 return ToFileIDOrErr.takeError();
10276 SourceManager &ToSM = ToContext.getSourceManager();
10277 return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
10278}
10279
10281 SourceLocation ToBegin, ToEnd;
10282 if (Error Err = importInto(ToBegin, FromRange.getBegin()))
10283 return std::move(Err);
10284 if (Error Err = importInto(ToEnd, FromRange.getEnd()))
10285 return std::move(Err);
10286
10287 return SourceRange(ToBegin, ToEnd);
10288}
10289
10291 llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
10292 if (Pos != ImportedFileIDs.end())
10293 return Pos->second;
10294
10295 SourceManager &FromSM = FromContext.getSourceManager();
10296 SourceManager &ToSM = ToContext.getSourceManager();
10297 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
10298
10299 // Map the FromID to the "to" source manager.
10300 FileID ToID;
10301 if (FromSLoc.isExpansion()) {
10302 const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
10303 ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
10304 if (!ToSpLoc)
10305 return ToSpLoc.takeError();
10306 ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
10307 if (!ToExLocS)
10308 return ToExLocS.takeError();
10309 unsigned ExLength = FromSM.getFileIDSize(FromID);
10310 SourceLocation MLoc;
10311 if (FromEx.isMacroArgExpansion()) {
10312 MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
10313 } else {
10314 if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
10315 MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
10316 FromEx.isExpansionTokenRange());
10317 else
10318 return ToExLocE.takeError();
10319 }
10320 ToID = ToSM.getFileID(MLoc);
10321 } else {
10322 const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
10323
10324 if (!IsBuiltin && !Cache->BufferOverridden) {
10325 // Include location of this file.
10326 ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
10327 if (!ToIncludeLoc)
10328 return ToIncludeLoc.takeError();
10329
10330 // Every FileID that is not the main FileID needs to have a valid include
10331 // location so that the include chain points to the main FileID. When
10332 // importing the main FileID (which has no include location), we need to
10333 // create a fake include location in the main file to keep this property
10334 // intact.
10335 SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
10336 if (FromID == FromSM.getMainFileID())
10337 ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
10338
10339 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
10340 // FIXME: We probably want to use getVirtualFileRef(), so we don't hit
10341 // the disk again
10342 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
10343 // than mmap the files several times.
10344 auto Entry =
10345 ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
10346 // FIXME: The filename may be a virtual name that does probably not
10347 // point to a valid file and we get no Entry here. In this case try with
10348 // the memory buffer below.
10349 if (Entry)
10350 ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
10351 FromSLoc.getFile().getFileCharacteristic());
10352 }
10353 }
10354
10355 if (ToID.isInvalid() || IsBuiltin) {
10356 // FIXME: We want to re-use the existing MemoryBuffer!
10357 std::optional<llvm::MemoryBufferRef> FromBuf =
10358 Cache->getBufferOrNone(FromContext.getDiagnostics(),
10359 FromSM.getFileManager(), SourceLocation{});
10360 if (!FromBuf)
10361 return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
10362
10363 std::unique_ptr<llvm::MemoryBuffer> ToBuf =
10364 llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
10365 FromBuf->getBufferIdentifier());
10366 ToID = ToSM.createFileID(std::move(ToBuf),
10367 FromSLoc.getFile().getFileCharacteristic());
10368 }
10369 }
10370
10371 assert(ToID.isValid() && "Unexpected invalid fileID was created.");
10372
10373 ImportedFileIDs[FromID] = ToID;
10374 return ToID;
10375}
10376
10378 ExpectedExpr ToExprOrErr = Import(From->getInit());
10379 if (!ToExprOrErr)
10380 return ToExprOrErr.takeError();
10381
10382 auto LParenLocOrErr = Import(From->getLParenLoc());
10383 if (!LParenLocOrErr)
10384 return LParenLocOrErr.takeError();
10385
10386 auto RParenLocOrErr = Import(From->getRParenLoc());
10387 if (!RParenLocOrErr)
10388 return RParenLocOrErr.takeError();
10389
10390 if (From->isBaseInitializer()) {
10391 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10392 if (!ToTInfoOrErr)
10393 return ToTInfoOrErr.takeError();
10394
10395 SourceLocation EllipsisLoc;
10396 if (From->isPackExpansion())
10397 if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
10398 return std::move(Err);
10399
10400 return new (ToContext) CXXCtorInitializer(
10401 ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
10402 *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
10403 } else if (From->isMemberInitializer()) {
10404 ExpectedDecl ToFieldOrErr = Import(From->getMember());
10405 if (!ToFieldOrErr)
10406 return ToFieldOrErr.takeError();
10407
10408 auto MemberLocOrErr = Import(From->getMemberLocation());
10409 if (!MemberLocOrErr)
10410 return MemberLocOrErr.takeError();
10411
10412 return new (ToContext) CXXCtorInitializer(
10413 ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
10414 *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10415 } else if (From->isIndirectMemberInitializer()) {
10416 ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
10417 if (!ToIFieldOrErr)
10418 return ToIFieldOrErr.takeError();
10419
10420 auto MemberLocOrErr = Import(From->getMemberLocation());
10421 if (!MemberLocOrErr)
10422 return MemberLocOrErr.takeError();
10423
10424 return new (ToContext) CXXCtorInitializer(
10425 ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10426 *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10427 } else if (From->isDelegatingInitializer()) {
10428 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10429 if (!ToTInfoOrErr)
10430 return ToTInfoOrErr.takeError();
10431
10432 return new (ToContext)
10433 CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10434 *ToExprOrErr, *RParenLocOrErr);
10435 } else {
10436 // FIXME: assert?
10437 return make_error<ASTImportError>();
10438 }
10439}
10440
10443 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10444 if (Pos != ImportedCXXBaseSpecifiers.end())
10445 return Pos->second;
10446
10447 Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10448 if (!ToSourceRange)
10449 return ToSourceRange.takeError();
10451 if (!ToTSI)
10452 return ToTSI.takeError();
10453 ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10454 if (!ToEllipsisLoc)
10455 return ToEllipsisLoc.takeError();
10456 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10457 *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10458 BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10459 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10460 return Imported;
10461}
10462
10464 ASTNodeImporter Importer(*this);
10465 return Importer.ImportAPValue(FromValue);
10466}
10467
10469 ExpectedDecl ToOrErr = Import(From);
10470 if (!ToOrErr)
10471 return ToOrErr.takeError();
10472 Decl *To = *ToOrErr;
10473
10474 auto *FromDC = cast<DeclContext>(From);
10475 ASTNodeImporter Importer(*this);
10476
10477 if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10478 if (!ToRecord->getDefinition()) {
10479 return Importer.ImportDefinition(
10480 cast<RecordDecl>(FromDC), ToRecord,
10482 }
10483 }
10484
10485 if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10486 if (!ToEnum->getDefinition()) {
10487 return Importer.ImportDefinition(
10489 }
10490 }
10491
10492 if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10493 if (!ToIFace->getDefinition()) {
10494 return Importer.ImportDefinition(
10495 cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10497 }
10498 }
10499
10500 if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10501 if (!ToProto->getDefinition()) {
10502 return Importer.ImportDefinition(
10503 cast<ObjCProtocolDecl>(FromDC), ToProto,
10505 }
10506 }
10507
10508 return Importer.ImportDeclContext(FromDC, true);
10509}
10510
10512 if (!FromName)
10513 return DeclarationName{};
10514
10515 switch (FromName.getNameKind()) {
10517 return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10518
10522 if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10523 return DeclarationName(*ToSelOrErr);
10524 else
10525 return ToSelOrErr.takeError();
10526
10528 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10529 return ToContext.DeclarationNames.getCXXConstructorName(
10530 ToContext.getCanonicalType(*ToTyOrErr));
10531 else
10532 return ToTyOrErr.takeError();
10533 }
10534
10536 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10537 return ToContext.DeclarationNames.getCXXDestructorName(
10538 ToContext.getCanonicalType(*ToTyOrErr));
10539 else
10540 return ToTyOrErr.takeError();
10541 }
10542
10544 if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10545 return ToContext.DeclarationNames.getCXXDeductionGuideName(
10546 cast<TemplateDecl>(*ToTemplateOrErr));
10547 else
10548 return ToTemplateOrErr.takeError();
10549 }
10550
10552 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10553 return ToContext.DeclarationNames.getCXXConversionFunctionName(
10554 ToContext.getCanonicalType(*ToTyOrErr));
10555 else
10556 return ToTyOrErr.takeError();
10557 }
10558
10560 return ToContext.DeclarationNames.getCXXOperatorName(
10561 FromName.getCXXOverloadedOperator());
10562
10564 return ToContext.DeclarationNames.getCXXLiteralOperatorName(
10565 Import(FromName.getCXXLiteralIdentifier()));
10566
10568 // FIXME: STATICS!
10570 }
10571
10572 llvm_unreachable("Invalid DeclarationName Kind!");
10573}
10574
10576 if (!FromId)
10577 return nullptr;
10578
10579 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10580
10581 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10582 ToId->setBuiltinID(FromId->getBuiltinID());
10583
10584 return ToId;
10585}
10586
10589 if (const IdentifierInfo *FromII = FromIO.getIdentifier())
10590 return Import(FromII);
10591 return FromIO.getOperator();
10592}
10593
10595 if (FromSel.isNull())
10596 return Selector{};
10597
10599 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10600 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10601 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10602 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10603}
10604
10608 llvm::Error Err = llvm::Error::success();
10609 auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10610 for (unsigned Idx = 0; Idx < Size; Idx++) {
10611 APValue Tmp = importChecked(Err, From[Idx]);
10612 To[Idx] = Tmp;
10613 }
10614 };
10615 switch (FromValue.getKind()) {
10616 case APValue::None:
10618 case APValue::Int:
10619 case APValue::Float:
10623 Result = FromValue;
10624 break;
10625 case APValue::Vector: {
10626 Result.MakeVector();
10628 Result.setVectorUninit(FromValue.getVectorLength());
10629 ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10630 Elts.data(), FromValue.getVectorLength());
10631 break;
10632 }
10633 case APValue::Matrix:
10634 // Matrix values cannot currently arise in APValue import contexts.
10635 llvm_unreachable("Matrix APValue import not yet supported");
10636 case APValue::Array:
10637 Result.MakeArray(FromValue.getArrayInitializedElts(),
10638 FromValue.getArraySize());
10639 ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10640 ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10641 FromValue.getArrayInitializedElts());
10642 break;
10643 case APValue::Struct:
10644 Result.MakeStruct(FromValue.getStructNumBases(),
10645 FromValue.getStructNumFields());
10646 ImportLoop(
10647 ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10648 ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10649 FromValue.getStructNumBases() + FromValue.getStructNumFields());
10650 break;
10651 case APValue::Union: {
10652 Result.MakeUnion();
10653 const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10654 APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10655 if (Err)
10656 return std::move(Err);
10657 Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10658 break;
10659 }
10661 Result.MakeAddrLabelDiff();
10662 const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10663 const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10664 if (Err)
10665 return std::move(Err);
10666 Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10667 cast<AddrLabelExpr>(ImpRHS));
10668 break;
10669 }
10671 const Decl *ImpMemPtrDecl =
10672 importChecked(Err, FromValue.getMemberPointerDecl());
10673 if (Err)
10674 return std::move(Err);
10676 Result.setMemberPointerUninit(
10677 cast<const ValueDecl>(ImpMemPtrDecl),
10679 FromValue.getMemberPointerPath().size());
10680 ArrayRef<const CXXRecordDecl *> FromPath = Result.getMemberPointerPath();
10681 for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10682 Idx++) {
10683 const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10684 if (Err)
10685 return std::move(Err);
10686 ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10687 }
10688 break;
10689 }
10690 case APValue::LValue:
10692 QualType FromElemTy;
10693 if (FromValue.getLValueBase()) {
10694 assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10695 "in C++20 dynamic allocation are transient so they shouldn't "
10696 "appear in the AST");
10697 if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10698 if (const auto *E =
10699 FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10700 FromElemTy = E->getType();
10701 const Expr *ImpExpr = importChecked(Err, E);
10702 if (Err)
10703 return std::move(Err);
10704 Base = APValue::LValueBase(ImpExpr,
10705 FromValue.getLValueBase().getCallIndex(),
10706 FromValue.getLValueBase().getVersion());
10707 } else {
10708 FromElemTy =
10709 FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10710 const Decl *ImpDecl = importChecked(
10711 Err, FromValue.getLValueBase().get<const ValueDecl *>());
10712 if (Err)
10713 return std::move(Err);
10715 FromValue.getLValueBase().getCallIndex(),
10716 FromValue.getLValueBase().getVersion());
10717 }
10718 } else {
10719 FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10720 const Type *ImpTypeInfo = importChecked(
10721 Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10722 QualType ImpType =
10723 importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10724 if (Err)
10725 return std::move(Err);
10727 ImpType);
10728 }
10729 }
10730 CharUnits Offset = FromValue.getLValueOffset();
10731 unsigned PathLength = FromValue.getLValuePath().size();
10732 Result.MakeLValue();
10733 if (FromValue.hasLValuePath()) {
10734 MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10735 Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10736 FromValue.isNullPointer());
10738 for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10739 if (FromElemTy->isRecordType()) {
10740 const Decl *FromDecl =
10741 FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10742 const Decl *ImpDecl = importChecked(Err, FromDecl);
10743 if (Err)
10744 return std::move(Err);
10745 if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10746 FromElemTy = Importer.FromContext.getCanonicalTagType(RD);
10747 else
10748 FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10750 ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10751 } else {
10752 FromElemTy =
10753 Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10754 ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10755 FromPath[LoopIdx].getAsArrayIndex());
10756 }
10757 }
10758 } else
10759 Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10760 FromValue.isNullPointer());
10761 }
10762 if (Err)
10763 return std::move(Err);
10764 return Result;
10765}
10766
10768 DeclContext *DC,
10769 unsigned IDNS,
10770 NamedDecl **Decls,
10771 unsigned NumDecls) {
10772 if (ODRHandling == ODRHandlingType::Conservative)
10773 // Report error at any name conflict.
10774 return make_error<ASTImportError>(ASTImportError::NameConflict);
10775 else
10776 // Allow to create the new Decl with the same name.
10777 return Name;
10778}
10779
10781 if (LastDiagFromFrom)
10782 ToContext.getDiagnostics().notePriorDiagnosticFrom(
10783 FromContext.getDiagnostics());
10784 LastDiagFromFrom = false;
10785 return ToContext.getDiagnostics().Report(Loc, DiagID);
10786}
10787
10789 if (!LastDiagFromFrom)
10790 FromContext.getDiagnostics().notePriorDiagnosticFrom(
10791 ToContext.getDiagnostics());
10792 LastDiagFromFrom = true;
10793 return FromContext.getDiagnostics().Report(Loc, DiagID);
10794}
10795
10797 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10798 if (!ID->getDefinition())
10799 ID->startDefinition();
10800 }
10801 else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10802 if (!PD->getDefinition())
10803 PD->startDefinition();
10804 }
10805 else if (auto *TD = dyn_cast<TagDecl>(D)) {
10806 if (!TD->getDefinition() && !TD->isBeingDefined()) {
10807 TD->startDefinition();
10808 TD->setCompleteDefinition(true);
10809 }
10810 }
10811 else {
10812 assert(0 && "CompleteDecl called on a Decl that can't be completed");
10813 }
10814}
10815
10817 auto [Pos, Inserted] = ImportedDecls.try_emplace(From, To);
10818 assert((Inserted || Pos->second == To) &&
10819 "Try to import an already imported Decl");
10820 if (!Inserted)
10821 return Pos->second;
10822 // This mapping should be maintained only in this function. Therefore do not
10823 // check for additional consistency.
10824 ImportedFromDecls[To] = From;
10825 // In the case of TypedefNameDecl we create the Decl first and only then we
10826 // import and set its DeclContext. So, the DC is still not set when we reach
10827 // here from GetImportedOrCreateDecl.
10828 if (To->getDeclContext())
10829 AddToLookupTable(To);
10830 return To;
10831}
10832
10833std::optional<ASTImportError>
10835 auto Pos = ImportDeclErrors.find(FromD);
10836 if (Pos != ImportDeclErrors.end())
10837 return Pos->second;
10838 else
10839 return std::nullopt;
10840}
10841
10843 auto InsertRes = ImportDeclErrors.insert({From, Error});
10844 (void)InsertRes;
10845 // Either we set the error for the first time, or we already had set one and
10846 // now we want to set the same error.
10847 assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10848}
10849
10851 bool Complain) {
10852 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10853 ImportedTypes.find(From.getTypePtr());
10854 if (Pos != ImportedTypes.end()) {
10855 if (ExpectedType ToFromOrErr = Import(From)) {
10856 if (ToContext.hasSameType(*ToFromOrErr, To))
10857 return true;
10858 } else {
10859 llvm::consumeError(ToFromOrErr.takeError());
10860 }
10861 }
10862
10864 getToContext().getLangOpts(), FromContext, ToContext, NonEquivalentDecls,
10865 getStructuralEquivalenceKind(*this), false, Complain);
10866 return Ctx.IsEquivalent(From, To);
10867}
Defines the clang::ASTContext interface.
static FriendCountAndPosition getFriendCountAndPosition(ASTImporter &Importer, FriendDecl *FD)
static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1, FriendDecl *FD2)
static ExpectedStmt ImportLoopControlStmt(ASTNodeImporter &NodeImporter, ASTImporter &Importer, StmtClass *S)
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)
This file provides some common utility functions for processing Lambda related AST Constructs.
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.
TokenType getType() const
Returns the token's type, e.g.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the LambdaCapture class.
Defines the clang::LangOptions interface.
llvm::MachO::Record Record
Definition MachO.h:31
llvm::SmallVector< std::pair< const MemRegion *, SVal >, 4 > Bindings
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.
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:1015
ArrayRef< LValuePathEntry > getLValuePath() const
Definition APValue.cpp:1035
const FieldDecl * getUnionField() const
Definition APValue.h:679
unsigned getStructNumFields() const
Definition APValue.h:658
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:479
bool isLValueOnePastTheEnd() const
Definition APValue.cpp:1020
bool isMemberPointerToDerivedMember() const
Definition APValue.cpp:1105
unsigned getArrayInitializedElts() const
Definition APValue.h:645
unsigned getStructNumBases() const
Definition APValue.h:654
bool hasLValuePath() const
Definition APValue.cpp:1030
const ValueDecl * getMemberPointerDecl() const
Definition APValue.cpp:1098
APValue & getUnionValue()
Definition APValue.h:683
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition APValue.h:699
CharUnits & getLValueOffset()
Definition APValue.cpp:1025
unsigned getVectorLength() const
Definition APValue.h:590
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition APValue.cpp:1112
unsigned getArraySize() const
Definition APValue.h:649
@ 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:1051
const AddrLabelExpr * getAddrLabelDiffLHS() const
Definition APValue.h:695
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:226
QualType getReadPipeType(QualType T) const
Return a read_only pipe type for the specified type.
const LangOptions & getLangOpts() const
Definition ASTContext.h:951
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
QualType getWritePipeType(QualType T) const
Return a write_only pipe type for the specified type.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
std::error_code convertToErrorCode() const override
void log(llvm::raw_ostream &OS) const override
std::string toString() const
@ Unknown
Not supported node or case.
@ UnsupportedConstruct
Naming ambiguity (likely ODR violation).
Imports selected nodes from one AST context into another context, merging AST nodes where appropriate...
Definition ASTImporter.h:62
ASTContext & getToContext() const
Retrieve the context that AST nodes are being imported into.
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.
static UnsignedOrNone getFieldIndex(Decl *F)
Determine the index of a field in its parent record.
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.
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
llvm::Error ImportTemplateArguments(ArrayRef< TemplateArgument > FromArgs, SmallVectorImpl< TemplateArgument > &ToArgs)
llvm::Error importInto(ImportT &To, const ImportT &From)
Import the given object, returns the result.
virtual void Imported(Decl *From, Decl *To)
Subclasses can override this function to observe all of the From -> To declaration mappings as they a...
DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "from" context.
llvm::DenseSet< std::tuple< Decl *, Decl *, int > > NonEquivalentDeclSet
Definition ASTImporter.h:65
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...
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)
StringRef ImportASTStringRef(StringRef FromStr)
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)
ExpectedDecl VisitRequiresExprBodyDecl(RequiresExprBodyDecl *E)
ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S)
ExpectedStmt VisitUnaryOperator(UnaryOperator *E)
Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD)
Error ImportDeclContext(DeclContext *FromDC, bool ForceImport=false)
ExpectedStmt VisitRequiresExpr(RequiresExpr *E)
ExpectedDecl VisitImplicitConceptSpecializationDecl(ImplicitConceptSpecializationDecl *D)
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 VisitPseudoObjectExpr(PseudoObjectExpr *E)
ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E)
ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E)
ExpectedDecl VisitConceptDecl(ConceptDecl *D)
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)
SmallVector< TemplateArgument, 8 > TemplateArgsTy
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)
ExpectedStmt VisitSubstNonTypeTemplateParmPackExpr(SubstNonTypeTemplateParmPackExpr *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)
Expected< concepts::Requirement * > ImportNestedRequirement(concepts::NestedRequirement *From)
ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias)
ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D)
ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D)
ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D)
Expected< ObjCTypeParamList * > ImportObjCTypeParamList(ObjCTypeParamList *list)
ExpectedDecl VisitUsingPackDecl(UsingPackDecl *D)
ExpectedStmt VisitWhileStmt(WhileStmt *S)
ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D)
ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E)
ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S)
ExpectedDecl VisitFriendDecl(FriendDecl *D)
Error ImportContainerChecked(const InContainerTy &InContainer, OutContainerTy &OutContainer)
ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E)
ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E)
bool IsStructuralMatch(Decl *From, Decl *To, bool Complain=true, bool IgnoreTemplateParmDepth=false)
ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E)
ExpectedStmt VisitForStmt(ForStmt *S)
ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E)
ExpectedDecl VisitEnumDecl(EnumDecl *D)
ExpectedStmt VisitCXXParenListInitExpr(CXXParenListInitExpr *E)
ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D)
ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E)
ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E)
ExpectedStmt VisitSwitchStmt(SwitchStmt *S)
ExpectedType VisitType(const Type *T)
ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D)
ExpectedDecl ImportUsingShadowDecls(BaseUsingDecl *D, BaseUsingDecl *ToSI)
ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E)
ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E)
ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D)
ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E)
ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D)
ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E)
ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E)
ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D)
Error ImportTemplateArguments(ArrayRef< TemplateArgument > FromArgs, SmallVectorImpl< TemplateArgument > &ToArgs)
ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D)
ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E)
ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D)
ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D)
ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E)
ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E)
Error ImportTemplateArgumentListInfo(const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo)
ExpectedStmt VisitDoStmt(DoStmt *S)
ExpectedStmt VisitNullStmt(NullStmt *S)
ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E)
ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D)
Error ImportOverriddenMethods(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod)
ExpectedStmt VisitStringLiteral(StringLiteral *E)
Error ImportDeclarationNameLoc(const DeclarationNameInfo &From, DeclarationNameInfo &To)
ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E)
bool hasReturnTypeDeclaredInside(FunctionDecl *D)
This function checks if the given function has a return type that contains a reference (in any way) t...
ASTNodeImporter(ASTImporter &Importer)
ExpectedDecl VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D)
ExpectedStmt VisitMemberExpr(MemberExpr *E)
ExpectedStmt VisitConceptSpecializationExpr(ConceptSpecializationExpr *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)
Expected< concepts::Requirement * > ImportExprRequirement(concepts::ExprRequirement *From)
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 ImportConstraintSatisfaction(const ASTConstraintSatisfaction &FromSat, ConstraintSatisfaction &ToSat)
ExpectedDecl VisitImportDecl(ImportDecl *D)
Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD)
ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E)
Expected< concepts::Requirement * > ImportTypeRequirement(concepts::TypeRequirement *From)
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)
std::tuple< FunctionTemplateDecl *, TemplateArgsTy > FunctionTemplateAndArgsTy
ExpectedStmt VisitBreakStmt(BreakStmt *S)
DesignatedInitExpr::Designator Designator
SourceLocation getColonLoc() const
Definition Expr.h:4384
SourceLocation getQuestionLoc() const
Definition Expr.h:4383
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:4553
SourceLocation getAmpAmpLoc() const
Definition Expr.h:4568
SourceLocation getLabelLoc() const
Definition Expr.h:4570
LabelDecl * getLabel() const
Definition Expr.h:4576
QualType getAdjustedType() const
Definition TypeBase.h:3513
QualType getOriginalType() const
Definition TypeBase.h:3512
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition Expr.h:6024
Represents a loop initializing the elements of an array.
Definition Expr.h:5971
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition Expr.h:5986
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition Expr.h:5991
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2724
SourceLocation getRBracketLoc() const
Definition Expr.h:2772
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Definition Expr.h:2753
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition ExprCXX.h:2997
uint64_t getValue() const
Definition ExprCXX.h:3045
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3035
ArrayTypeTrait getTrait() const
Definition ExprCXX.h:3037
Expr * getDimensionExpression() const
Definition ExprCXX.h:3047
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition ExprCXX.h:3043
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3034
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3730
ArraySizeModifier getSizeModifier() const
Definition TypeBase.h:3744
QualType getElementType() const
Definition TypeBase.h:3742
unsigned getIndexTypeCVRQualifiers() const
Definition TypeBase.h:3752
bool isVolatile() const
Definition Stmt.h:3305
outputs_range outputs()
Definition Stmt.h:3412
SourceLocation getAsmLoc() const
Definition Stmt.h:3299
inputs_range inputs()
Definition Stmt.h:3383
unsigned getNumClobbers() const
Definition Stmt.h:3360
unsigned getNumOutputs() const
Definition Stmt.h:3328
unsigned getNumInputs() const
Definition Stmt.h:3350
bool isSimple() const
Definition Stmt.h:3302
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:6927
Expr ** getSubExprs()
Definition Expr.h:7002
SourceLocation getRParenLoc() const
Definition Expr.h:7056
static unsigned getNumSubExprs(AtomicOp Op)
Determine the number of arguments the specified atomic builtin should have.
Definition Expr.cpp:5250
AtomicOp getOp() const
Definition Expr.h:6990
SourceLocation getBuiltinLoc() const
Definition Expr.h:7055
Attr - This represents one attribute.
Definition Attr.h:46
attr::Kind getKind() const
Definition Attr.h:92
void setPackExpansion(bool PE)
Definition Attr.h:108
Attr * clone(ASTContext &C) const
void setImplicit(bool I)
Definition Attr.h:106
void setAttrName(const IdentifierInfo *AttrNameII)
const IdentifierInfo * getAttrName() const
Represents an attribute applied to a statement.
Definition Stmt.h:2195
Stmt * getSubStmt()
Definition Stmt.h:2231
SourceLocation getAttrLoc() const
Definition Stmt.h:2226
ArrayRef< const Attr * > getAttrs() const
Definition Stmt.h:2227
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition Stmt.cpp:441
Represents a C++ declaration that introduces decls from somewhere else.
Definition DeclCXX.h:3499
void addShadowDecl(UsingShadowDecl *S)
Definition DeclCXX.cpp:3474
shadow_range shadows() const
Definition DeclCXX.h:3565
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition Expr.h:4456
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condition evaluates to false; ...
Definition Expr.h:4510
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition Expr.h:4494
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
Definition Expr.h:4498
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Definition Expr.h:4503
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition Expr.h:4491
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4041
Expr * getLHS() const
Definition Expr.h:4091
SourceLocation getOperatorLoc() const
Definition Expr.h:4083
Expr * getRHS() const
Definition Expr.h:4093
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:5076
Opcode getOpcode() const
Definition Expr.h:4086
FPOptionsOverride getFPFeatures() const
Definition Expr.h:4261
A binding in a decomposition declaration.
Definition DeclCXX.h:4188
ValueDecl * getDecomposedDecl() const
Get the decomposition declaration that this binding represents a decomposition of.
Definition DeclCXX.h:4221
Expr * getBinding() const
Get the expression to which this declaration is bound.
Definition DeclCXX.h:4214
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:4226
void setDecomposedDecl(ValueDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition DeclCXX.h:4232
bool isUnsigned() const
Definition TypeBase.h:8250
unsigned getNumBits() const
Definition TypeBase.h:8252
QualType getPointeeType() const
Definition TypeBase.h:3562
decl_range dependent_decls() const
Definition TypeBase.h:3416
QualType desugar() const
Definition TypeBase.h:3406
BreakStmt - This represents a break.
Definition Stmt.h:3127
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition ExprCXX.h:5477
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 TypeBase.h:3172
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:2104
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:1494
CXXTemporary * getTemporary()
Definition ExprCXX.h:1512
static CXXBindTemporaryExpr * Create(const ASTContext &C, CXXTemporary *Temp, Expr *SubExpr)
Definition ExprCXX.cpp:1118
const Expr * getSubExpr() const
Definition ExprCXX.h:1516
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition ExprCXX.h:724
static CXXBoolLiteralExpr * Create(const ASTContext &C, bool Val, QualType Ty, SourceLocation Loc)
Definition ExprCXX.h:736
bool getValue() const
Definition ExprCXX.h:741
SourceLocation getLocation() const
Definition ExprCXX.h:747
CXXCatchStmt - This represents a C++ catch block.
Definition StmtCXX.h:28
SourceLocation getCatchLoc() const
Definition StmtCXX.h:48
Stmt * getHandlerBlock() const
Definition StmtCXX.h:51
VarDecl * getExceptionDecl() const
Definition StmtCXX.h:49
static CXXConstCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, Expr *Op, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition ExprCXX.cpp:892
Represents a call to a C++ constructor.
Definition ExprCXX.h:1549
SourceRange getParenOrBraceRange() const
Definition ExprCXX.h:1730
void setIsImmediateEscalating(bool Set)
Definition ExprCXX.h:1711
bool isElidable() const
Whether this construction is elidable.
Definition ExprCXX.h:1618
bool hadMultipleCandidates() const
Whether the referred constructor was resolved from an overloaded set having size greater than 1.
Definition ExprCXX.h:1623
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:1180
arg_range arguments()
Definition ExprCXX.h:1673
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition ExprCXX.h:1642
bool isImmediateEscalating() const
Definition ExprCXX.h:1707
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
Definition ExprCXX.h:1651
SourceLocation getLocation() const
Definition ExprCXX.h:1614
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition ExprCXX.h:1612
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition ExprCXX.h:1631
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition ExprCXX.h:1689
CXXConstructionKind getConstructionKind() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition ExprCXX.h:1660
Represents a C++ constructor within a class.
Definition DeclCXX.h:2611
Represents a C++ conversion function within a class.
Definition DeclCXX.h:2946
Represents a C++ base or member initializer.
Definition DeclCXX.h:2376
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition DeclCXX.h:2516
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition DeclCXX.h:2476
Expr * getInit() const
Get the initializer.
Definition DeclCXX.h:2578
SourceLocation getRParenLoc() const
Definition DeclCXX.h:2575
SourceLocation getEllipsisLoc() const
Definition DeclCXX.h:2486
SourceLocation getLParenLoc() const
Definition DeclCXX.h:2574
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition DeclCXX.h:2481
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition DeclCXX.h:2510
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition DeclCXX.h:2454
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition DeclCXX.h:2448
bool isIndirectMemberInitializer() const
Definition DeclCXX.h:2460
SourceLocation getMemberLocation() const
Definition DeclCXX.h:2536
IndirectFieldDecl * getIndirectMember() const
Definition DeclCXX.h:2530
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition DeclCXX.h:2502
Represents a C++ deduction guide declaration.
Definition DeclCXX.h:1986
SourceDeductionGuideKind getSourceDeductionGuideKind() const
Definition DeclCXX.h:2070
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1271
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
Definition ExprCXX.h:1345
const ParmVarDecl * getParam() const
Definition ExprCXX.h:1313
const DeclContext * getUsedContext() const
Definition ExprCXX.h:1341
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition ExprCXX.cpp:1039
bool hasRewrittenInit() const
Definition ExprCXX.h:1316
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1378
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:1093
const DeclContext * getUsedContext() const
Definition ExprCXX.h:1435
const Expr * getRewrittenExpr() const
Retrieve the initializing expression with evaluated immediate calls, if any.
Definition ExprCXX.h:1423
bool hasRewrittenInit() const
Definition ExprCXX.h:1407
FieldDecl * getField()
Get the field whose initializer will be used.
Definition ExprCXX.h:1412
SourceLocation getBeginLoc() const
Definition ExprCXX.h:1442
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2627
FunctionDecl * getOperatorDelete() const
Definition ExprCXX.h:2666
bool isArrayForm() const
Definition ExprCXX.h:2653
SourceLocation getBeginLoc() const
Definition ExprCXX.h:2677
bool isGlobalDelete() const
Definition ExprCXX.h:2652
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition ExprCXX.h:2662
bool isArrayFormAsWritten() const
Definition ExprCXX.h:2654
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition ExprCXX.h:3871
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition ExprCXX.h:3970
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition ExprCXX.h:3973
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:1550
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:4025
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition ExprCXX.h:4017
const DeclarationNameInfo & getMemberNameInfo() const
Retrieve the name of the member that this expression refers to.
Definition ExprCXX.h:4004
bool hasExplicitTemplateArgs() const
Determines whether this member expression actually had a C++ template argument list explicitly specif...
Definition ExprCXX.h:4044
SourceLocation getMemberLoc() const
Definition ExprCXX.h:4013
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:4033
DeclarationName getMember() const
Retrieve the name of the member that this expression refers to.
Definition ExprCXX.h:4009
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:3997
Expr * getBase() const
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition ExprCXX.h:3961
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the member name, with source location information.
Definition ExprCXX.h:3984
bool isImplicitAccess() const
True if this is an implicit access, i.e.
Definition ExprCXX.h:3953
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:4072
Represents a C++ destructor within a class.
Definition DeclCXX.h:2876
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg)
Definition DeclCXX.cpp:3130
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:806
Represents a folding of a pack over an operator.
Definition ExprCXX.h:5033
UnresolvedLookupExpr * getCallee() const
Definition ExprCXX.h:5055
Expr * getRHS() const
Definition ExprCXX.h:5059
SourceLocation getLParenLoc() const
Definition ExprCXX.h:5075
SourceLocation getEllipsisLoc() const
Definition ExprCXX.h:5077
UnsignedOrNone getNumExpansions() const
Definition ExprCXX.h:5080
Expr * getLHS() const
Definition ExprCXX.h:5058
SourceLocation getRParenLoc() const
Definition ExprCXX.h:5076
BinaryOperatorKind getOperator() const
Definition ExprCXX.h:5078
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition StmtCXX.h:135
DeclStmt * getBeginStmt()
Definition StmtCXX.h:163
DeclStmt * getLoopVarStmt()
Definition StmtCXX.h:169
DeclStmt * getEndStmt()
Definition StmtCXX.h:166
SourceLocation getForLoc() const
Definition StmtCXX.h:202
DeclStmt * getRangeStmt()
Definition StmtCXX.h:162
SourceLocation getRParenLoc() const
Definition StmtCXX.h:205
SourceLocation getColonLoc() const
Definition StmtCXX.h:204
SourceLocation getCoawaitLoc() const
Definition StmtCXX.h:203
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:918
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1752
bool constructsVBase() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition ExprCXX.h:1793
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Definition ExprCXX.h:1789
SourceLocation getLocation() const LLVM_READONLY
Definition ExprCXX.h:1805
bool inheritedFromVBase() const
Determine whether the inherited constructor is inherited from a virtual base of the object we constru...
Definition ExprCXX.h:1803
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:180
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:692
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2136
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition DeclCXX.cpp:2773
overridden_method_range overridden_methods() const
Definition DeclCXX.cpp:2796
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition DeclCXX.h:2232
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition ExprCXX.h:376
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition ExprCXX.h:407
SourceRange getAngleBrackets() const LLVM_READONLY
Definition ExprCXX.h:414
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition ExprCXX.h:410
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2356
static CXXNewExpr * Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, const ImplicitAllocationParameters &IAP, 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:293
SourceRange getDirectInitRange() const
Definition ExprCXX.h:2610
llvm::iterator_range< arg_iterator > placement_arguments()
Definition ExprCXX.h:2573
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:2470
CXXNewInitializationStyle getInitializationStyle() const
The kind of initializer this new-expression has.
Definition ExprCXX.h:2528
ImplicitAllocationParameters implicitAllocationParameters() const
Provides the full set of information about expected implicit parameters in this call.
Definition ExprCXX.h:2563
FunctionDecl * getOperatorDelete() const
Definition ExprCXX.h:2462
unsigned getNumPlacementArgs() const
Definition ExprCXX.h:2495
TypeSourceInfo * getAllocatedTypeSourceInfo() const
Definition ExprCXX.h:2439
SourceRange getSourceRange() const
Definition ExprCXX.h:2611
SourceRange getTypeIdParens() const
Definition ExprCXX.h:2517
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition ExprCXX.h:2557
FunctionDecl * getOperatorNew() const
Definition ExprCXX.h:2460
bool isGlobalNew() const
Definition ExprCXX.h:2522
Expr * getInitializer()
The initializer of this new-expression.
Definition ExprCXX.h:2534
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition ExprCXX.h:4310
bool getValue() const
Definition ExprCXX.h:4333
SourceLocation getEndLoc() const
Definition ExprCXX.h:4330
Expr * getOperand() const
Definition ExprCXX.h:4327
SourceLocation getBeginLoc() const
Definition ExprCXX.h:4329
The null pointer literal (C++11 [lex.nullptr])
Definition ExprCXX.h:769
SourceLocation getLocation() const
Definition ExprCXX.h:783
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:624
Represents a list-initialization with parenthesis.
Definition ExprCXX.h:5142
static CXXParenListInitExpr * Create(ASTContext &C, ArrayRef< Expr * > Args, QualType T, unsigned NumUserSpecifiedExprs, SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Definition ExprCXX.cpp:2005
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:5198
SourceLocation getInitLoc() const LLVM_READONLY
Definition ExprCXX.h:5200
MutableArrayRef< Expr * > getInitExprs()
Definition ExprCXX.h:5182
ArrayRef< Expr * > getUserSpecifiedInitExprs()
Definition ExprCXX.h:5188
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:5196
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition ExprCXX.h:2746
TypeSourceInfo * getDestroyedTypeInfo() const
Retrieve the source location information for the type being destroyed.
Definition ExprCXX.h:2840
bool isArrow() const
Determine whether this pseudo-destructor expression was written using an '->' (otherwise,...
Definition ExprCXX.h:2810
TypeSourceInfo * getScopeTypeInfo() const
Retrieve the scope type in a qualified pseudo-destructor expression.
Definition ExprCXX.h:2824
SourceLocation getTildeLoc() const
Retrieve the location of the '~'.
Definition ExprCXX.h:2831
NestedNameSpecifierLoc getQualifierLoc() const
Retrieves the nested-name-specifier that qualifies the type name, with source-location information.
Definition ExprCXX.h:2799
SourceLocation getDestroyedTypeLoc() const
Retrieve the starting location of the type being destroyed.
Definition ExprCXX.h:2855
SourceLocation getColonColonLoc() const
Retrieve the location of the '::' in a qualified pseudo-destructor expression.
Definition ExprCXX.h:2828
SourceLocation getOperatorLoc() const
Retrieve the location of the '.' or '->' operator.
Definition ExprCXX.h:2813
const IdentifierInfo * getDestroyedTypeIdentifier() const
In a dependent pseudo-destructor expression for which we do not have full type information on the des...
Definition ExprCXX.h:2847
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
CXXRecordDecl * getMostRecentDecl()
Definition DeclCXX.h:539
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:2030
method_range methods() const
Definition DeclCXX.h:650
CXXRecordDecl * getDefinition() const
Definition DeclCXX.h:548
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, unsigned DependencyKind, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
Definition DeclCXX.cpp:141
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
Definition DeclCXX.cpp:2060
void setInstantiationOfMemberClass(CXXRecordDecl *RD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member class RD.
Definition DeclCXX.cpp:2043
void setLambdaContextDecl(Decl *ContextDecl)
Set the context declaration for a lambda class.
Definition DeclCXX.cpp:1840
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition DeclCXX.cpp:2056
void setLambdaNumbering(LambdaNumbering Numbering)
Set the mangling numbers for a lambda class.
Definition DeclCXX.cpp:1845
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
Definition DeclCXX.cpp:2037
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition DeclCXX.cpp:2071
CXXRecordDecl * getPreviousDecl()
Definition DeclCXX.h:530
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:870
A rewritten comparison expression that was originally written using operator syntax.
Definition ExprCXX.h:287
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
Definition ExprCXX.h:305
bool isReversed() const
Determine whether this expression was rewritten in reverse form.
Definition ExprCXX.h:323
An expression "T()" which creates an rvalue of a non-class type T.
Definition ExprCXX.h:2197
TypeSourceInfo * getTypeSourceInfo() const
Definition ExprCXX.h:2216
SourceLocation getRParenLoc() const
Definition ExprCXX.h:2220
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:780
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition ExprCXX.h:801
Represents a C++ functional cast expression that builds a temporary object.
Definition ExprCXX.h:1900
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:1146
TypeSourceInfo * getTypeSourceInfo() const
Definition ExprCXX.h:1929
Represents a C++ temporary.
Definition ExprCXX.h:1460
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition ExprCXX.cpp:1113
Represents the this expression in C++.
Definition ExprCXX.h:1155
bool isImplicit() const
Definition ExprCXX.h:1178
static CXXThisExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType Ty, bool IsImplicit)
Definition ExprCXX.cpp:1585
SourceLocation getLocation() const
Definition ExprCXX.h:1172
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1209
const Expr * getSubExpr() const
Definition ExprCXX.h:1229
SourceLocation getThrowLoc() const
Definition ExprCXX.h:1232
bool isThrownVariableInScope() const
Determines whether the variable thrown by this expression (if any!) is within the innermost try block...
Definition ExprCXX.h:1239
CXXTryStmt - A C++ try block, including all handlers.
Definition StmtCXX.h:69
SourceLocation getTryLoc() const
Definition StmtCXX.h:95
CXXCatchStmt * getHandler(unsigned i)
Definition StmtCXX.h:108
unsigned getNumHandlers() const
Definition StmtCXX.h:107
static CXXTryStmt * Create(const ASTContext &C, SourceLocation tryLoc, CompoundStmt *tryBlock, ArrayRef< Stmt * > handlers)
Definition StmtCXX.cpp:25
CompoundStmt * getTryBlock()
Definition StmtCXX.h:100
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition ExprCXX.h:849
bool isTypeOperand() const
Definition ExprCXX.h:885
TypeSourceInfo * getTypeOperandSourceInfo() const
Retrieve source information for the type operand.
Definition ExprCXX.h:892
Expr * getExprOperand() const
Definition ExprCXX.h:896
SourceRange getSourceRange() const LLVM_READONLY
Definition ExprCXX.h:903
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition ExprCXX.h:3745
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses ('(') that precedes the argument list.
Definition ExprCXX.h:3789
bool isListInitialization() const
Determine whether this expression models list-initialization.
Definition ExprCXX.h:3800
static CXXUnresolvedConstructExpr * Create(const ASTContext &Context, QualType T, TypeSourceInfo *TSI, SourceLocation LParenLoc, ArrayRef< Expr * > Args, SourceLocation RParenLoc, bool IsListInit)
Definition ExprCXX.cpp:1488
TypeSourceInfo * getTypeSourceInfo() const
Retrieve the type source information for the type being constructed.
Definition ExprCXX.h:3783
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (')') that follows the argument list.
Definition ExprCXX.h:3794
unsigned getNumArgs() const
Retrieve the number of arguments.
Definition ExprCXX.h:3803
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2946
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:1517
ADLCallKind getADLCallKind() const
Definition Expr.h:3097
Expr * getCallee()
Definition Expr.h:3093
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3245
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition Expr.h:3137
arg_range arguments()
Definition Expr.h:3198
SourceLocation getRParenLoc() const
Definition Expr.h:3277
CaseStmt - Represent a case statement.
Definition Stmt.h:1912
Stmt * getSubStmt()
Definition Stmt.h:2025
Expr * getLHS()
Definition Stmt.h:1995
SourceLocation getEllipsisLoc() const
Get the location of the ... in a case statement of the form LHS ... RHS.
Definition Stmt.h:1981
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Definition Stmt.cpp:1306
SourceLocation getCaseLoc() const
Definition Stmt.h:1977
Expr * getRHS()
Definition Stmt.h:2007
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3679
path_iterator path_begin()
Definition Expr.h:3749
CastKind getCastKind() const
Definition Expr.h:3723
path_iterator path_end()
Definition Expr.h:3750
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3799
Expr * getSubExpr()
Definition Expr.h:3729
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
SourceLocation getLocation() const
Definition Expr.h:1624
unsigned getValue() const
Definition Expr.h:1632
CharacterLiteralKind getKind() const
Definition Expr.h:1625
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:4851
SourceLocation getBuiltinLoc() const
Definition Expr.h:4898
Expr * getLHS() const
Definition Expr.h:4893
bool isConditionDependent() const
Definition Expr.h:4881
bool isConditionTrue() const
isConditionTrue - Return whether the condition is true (i.e.
Definition Expr.h:4874
Expr * getRHS() const
Definition Expr.h:4895
SourceLocation getRParenLoc() const
Definition Expr.h:4901
Expr * getCond() const
Definition Expr.h:4891
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.
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...
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.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
void setPointOfInstantiation(SourceLocation Loc)
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
void setExternKeywordLoc(SourceLocation Loc)
Sets the location of the extern keyword.
void setSpecializationKind(TemplateSpecializationKind TSK)
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
SourceLocation getExternKeywordLoc() const
Gets the location of the extern keyword, if present.
SourceLocation getTemplateKeywordLoc() const
Gets the location of the template keyword, if present.
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
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 setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this class template specialization is actually an instantiation of the given class template...
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
QualType getElementType() const
Definition TypeBase.h:3293
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4303
QualType getComputationLHSType() const
Definition Expr.h:4337
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:5098
QualType getComputationResultType() const
Definition Expr.h:4340
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3608
SourceLocation getLParenLoc() const
Definition Expr.h:3643
bool isFileScope() const
Definition Expr.h:3640
const Expr * getInitializer() const
Definition Expr.h:3636
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:3646
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1732
unsigned size() const
Definition Stmt.h:1777
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition Stmt.h:1782
body_range body()
Definition Stmt.h:1795
SourceLocation getLBracLoc() const
Definition Stmt.h:1849
bool hasStoredFPFeatures() const
Definition Stmt.h:1779
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Definition Stmt.cpp:399
SourceLocation getRBracLoc() const
Definition Stmt.h:1850
Declaration of a C++20 concept.
Expr * getConstraintExpr() const
A reference to a concept and its template args, as it appears in the code.
Definition ASTConcept.h:130
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
Definition ASTConcept.h:170
NamedDecl * getFoundDecl() const
Definition ASTConcept.h:197
const DeclarationNameInfo & getConceptNameInfo() const
Definition ASTConcept.h:174
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition ASTConcept.h:203
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, TemplateDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
TemplateDecl * getNamedConcept() const
Definition ASTConcept.h:201
SourceLocation getTemplateKWLoc() const
Definition ASTConcept.h:180
Represents the specialization of a concept - evaluates to a prvalue of type bool.
static ConceptSpecializationExpr * Create(const ASTContext &C, ConceptReference *ConceptRef, ImplicitConceptSpecializationDecl *SpecDecl, const ConstraintSatisfaction *Satisfaction)
ConceptReference * getConceptReference() const
const ImplicitConceptSpecializationDecl * getSpecializationDecl() const
const ASTConstraintSatisfaction & getSatisfaction() const
Get elaborated satisfaction info about the template arguments' satisfaction of the named concept.
ConditionalOperator - The ?
Definition Expr.h:4394
Expr * getLHS() const
Definition Expr.h:4428
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Definition Expr.h:4417
Expr * getRHS() const
Definition Expr.h:4429
const Expr * getSizeExpr() const
Return a pointer to the size expression.
Definition TypeBase.h:3864
llvm::APInt getSize() const
Return the constant array size as an APInt.
Definition TypeBase.h:3824
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1085
APValue getAPValueResult() const
Definition Expr.cpp:413
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition Expr.cpp:350
unsigned getNumColumns() const
Returns the number of columns in the matrix.
Definition TypeBase.h:4414
unsigned getNumRows() const
Returns the number of rows in the matrix.
Definition TypeBase.h:4411
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition ASTConcept.h:47
llvm::SmallVector< UnsatisfiedConstraintRecord, 4 > Details
The substituted constraint expr, if the template arguments could be substituted into them,...
Definition ASTConcept.h:67
Represents a shadow constructor declaration introduced into a class by a C++11 using-declaration that...
Definition DeclCXX.h:3680
ContinueStmt - This represents a continue.
Definition Stmt.h:3111
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4722
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:4790
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition Expr.h:4826
static ConvertVectorExpr * Create(const ASTContext &C, Expr *SrcExpr, TypeSourceInfo *TI, QualType DstType, ExprValueKind VK, ExprObjectKind OK, SourceLocation BuiltinLoc, SourceLocation RParenLoc, FPOptionsOverride FPFeatures)
Definition Expr.cpp:5655
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_convertvector token.
Definition Expr.h:4823
TypeSourceInfo * getTypeSourceInfo() const
getTypeSourceInfo - Return the destination type.
Definition Expr.h:4815
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition Expr.h:4812
bool isCountInBytes() const
Definition TypeBase.h:3471
Expr * getCountExpr() const
Definition TypeBase.h:3470
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:1382
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1449
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2109
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
DeclContextLookupResult lookup_result
Definition DeclBase.h:2577
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
bool isNamespace() const
Definition DeclBase.h:2198
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
bool isRecord() const
Definition DeclBase.h:2189
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
void removeDecl(Decl *D)
Removes a declaration from this context.
lookup_result noload_lookup(DeclarationName Name)
Find the declarations with the given name that are visible within this context; don't attempt to retr...
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition DeclBase.h:2688
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition DeclBase.h:2373
bool isFunctionOrMethod() const
Definition DeclBase.h:2161
void localUncachedLookup(DeclarationName Name, SmallVectorImpl< NamedDecl * > &Results)
A simplistic name lookup mechanism that performs name lookup into this declaration context without co...
static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls)
Definition DeclGroup.h:64
iterator begin()
Definition DeclGroup.h:95
bool isNull() const
Definition DeclGroup.h:75
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1273
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
Definition Expr.h:1384
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list.
Definition Expr.h:1428
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Definition Expr.h:1477
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition Expr.h:1400
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:1408
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
Definition Expr.h:1366
ValueDecl * getDecl()
Definition Expr.h:1341
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:1454
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:1471
bool hadMultipleCandidates() const
Returns true if this expression refers to a function that was resolved from an overloaded set having ...
Definition Expr.h:1460
SourceLocation getLocation() const
Definition Expr.h:1349
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:1416
bool isImmediateEscalating() const
Definition Expr.h:1481
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1623
SourceLocation getEndLoc() const
Definition Stmt.h:1646
const DeclGroupRef getDeclGroup() const
Definition Stmt.h:1641
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:1649
A simple visitor class that helps create declaration visitors.
Definition DeclVisitor.h:68
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition DeclBase.h:435
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration.
Definition DeclBase.cpp:285
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:518
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:546
void addAttr(Attr *A)
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition DeclBase.h:593
@ 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:502
SourceLocation getLocation() const
Definition DeclBase.h:439
const char * getDeclKindName() const
Definition DeclBase.cpp:169
IdentifierNamespace
IdentifierNamespace - The different namespaces in which declarations may appear.
Definition DeclBase.h:115
@ IDNS_NonMemberOperator
This declaration is a C++ operator declared in a non-class context.
Definition DeclBase.h:168
@ IDNS_TagFriend
This declaration is a friend class.
Definition DeclBase.h:157
@ IDNS_Ordinary
Ordinary names.
Definition DeclBase.h:144
@ IDNS_ObjCProtocol
Objective C @protocol.
Definition DeclBase.h:147
@ IDNS_Namespace
Namespaces, declared with 'namespace foo {}'.
Definition DeclBase.h:140
@ IDNS_OrdinaryFriend
This declaration is a friend function.
Definition DeclBase.h:152
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
Definition DeclBase.h:125
void setImplicit(bool I=true)
Definition DeclBase.h:594
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition DeclBase.h:608
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition DeclBase.cpp:575
DeclContext * getDeclContext()
Definition DeclBase.h:448
AccessSpecifier getAccess() const
Definition DeclBase.h:507
bool isInAnonymousNamespace() const
Definition DeclBase.cpp:439
SourceLocation getBeginLoc() const LLVM_READONLY
Definition DeclBase.h:431
TranslationUnitDecl * getTranslationUnitDecl()
Definition DeclBase.cpp:531
AttrVec & getAttrs()
Definition DeclBase.h:524
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition DeclBase.cpp:382
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition DeclBase.h:918
void setLexicalDeclContext(DeclContext *DC)
Definition DeclBase.cpp:386
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition DeclBase.h:978
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name.
const IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it.
static DeclarationName getUsingDirectiveName()
Returns the name for all C++ using-directives.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
NameKind getNameKind() const
Determine what kind of name this is.
bool isEmpty() const
Evaluates true when this declaration name is empty.
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition Decl.h:822
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:831
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Definition Decl.h:855
void setTypeSourceInfo(TypeSourceInfo *TI)
Definition Decl.h:814
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:2012
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:845
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:809
A decomposition declaration.
Definition DeclCXX.h:4252
SourceLocation getDefaultLoc() const
Definition Stmt.h:2077
Stmt * getSubStmt()
Definition Stmt.h:2073
QualType getPointeeType() const
Definition TypeBase.h:4081
SourceLocation getAttributeLoc() const
Definition TypeBase.h:4082
Expr * getNumBitsExpr() const
Definition Type.cpp:438
bool isUnsigned() const
Definition Type.cpp:434
A qualified reference to a name whose declaration cannot yet be resolved.
Definition ExprCXX.h:3511
static DependentScopeDeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition ExprCXX.cpp:544
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3585
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition ExprCXX.h:3559
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3577
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:3619
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition ExprCXX.h:3595
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3569
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3550
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3547
SourceLocation getAttributeLoc() const
Definition TypeBase.h:4125
SourceLocation getAttributeLoc() const
Definition TypeBase.h:4495
IdentifierOrOverloadedOperator getName() const
NestedNameSpecifier getQualifier() const
Return the nested name specifier that qualifies this name.
bool hasTemplateKeyword() const
Was this template name was preceeded by the template keyword?
Expr * getSizeExpr() const
Definition TypeBase.h:4246
VectorKind getVectorKind() const
Definition TypeBase.h:4249
SourceLocation getAttributeLoc() const
Definition TypeBase.h:4248
QualType getElementType() const
Definition TypeBase.h:4247
Represents a single C99 designator.
Definition Expr.h:5597
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition Expr.h:5724
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition Expr.h:5678
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition Expr.h:5714
SourceLocation getFieldLoc() const
Definition Expr.h:5705
SourceLocation getRBracketLoc() const
Definition Expr.h:5753
const IdentifierInfo * getFieldName() const
Definition Expr.cpp:4768
SourceLocation getEllipsisLoc() const
Definition Expr.h:5747
SourceLocation getDotLoc() const
Definition Expr.h:5700
SourceLocation getLBracketLoc() const
Definition Expr.h:5741
Represents a C99 designated initializer expression.
Definition Expr.h:5554
Expr * getSubExpr(unsigned Idx) const
Definition Expr.h:5836
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
Definition Expr.h:5818
MutableArrayRef< Designator > designators()
Definition Expr.h:5787
Expr * getInit() const
Retrieve the initializer value.
Definition Expr.h:5822
unsigned size() const
Returns the number of designators in this initializer.
Definition Expr.h:5784
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
Definition Expr.h:5809
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression,...
Definition Expr.h:5834
static DesignatedInitExpr * Create(const ASTContext &C, ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition Expr.cpp:4809
A little helper class used to produce diagnostics.
DoStmt - This represents a 'do/while' stmt.
Definition Stmt.h:2824
Stmt * getBody()
Definition Stmt.h:2849
Expr * getCond()
Definition Stmt.h:2842
SourceLocation getWhileLoc() const
Definition Stmt.h:2855
SourceLocation getDoLoc() const
Definition Stmt.h:2853
SourceLocation getRParenLoc() const
Definition Stmt.h:2857
Symbolic representation of a dynamic allocation.
Definition APValue.h:65
Represents an empty-declaration.
Definition Decl.h:5181
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3423
llvm::APSInt getInitVal() const
Definition Decl.h:3443
const Expr * getInitExpr() const
Definition Decl.h:3441
Represents an enum.
Definition Decl.h:4013
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition Decl.h:4285
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4231
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition Decl.h:4223
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4234
void setIntegerType(QualType T)
Set the underlying integer type.
Definition Decl.h:4195
EnumDecl * getMostRecentDecl()
Definition Decl.h:4118
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition Decl.h:4240
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition Decl.cpp:5095
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition Decl.h:4186
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition Decl.cpp:5155
EnumDecl * getDefinition() const
Definition Decl.h:4125
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition Decl.h:4212
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition Decl.h:4178
ExplicitCastExpr - An explicit cast written in the source code.
Definition Expr.h:3931
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition Expr.h:3953
Store information needed for an explicit specifier.
Definition DeclCXX.h:1931
ExplicitSpecKind getKind() const
Definition DeclCXX.h:1939
const Expr * getExpr() const
Definition DeclCXX.h:1940
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition ExprCXX.h:3662
bool cleanupsHaveSideEffects() const
Definition ExprCXX.h:3697
ArrayRef< CleanupObject > getObjects() const
Definition ExprCXX.h:3686
unsigned getNumObjects() const
Definition ExprCXX.h:3690
llvm::PointerUnion< BlockDecl *, CompoundLiteralExpr * > CleanupObject
The type of objects that are kept in the cleanup.
Definition ExprCXX.h:3668
static ExprWithCleanups * Create(const ASTContext &C, EmptyShell empty, unsigned numObjects)
Definition ExprCXX.cpp:1464
This represents one expression.
Definition Expr.h:112
void setType(QualType t)
Definition Expr.h:145
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition Expr.h:177
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition Expr.h:447
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition Expr.h:194
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
Definition Expr.h:241
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition Expr.h:454
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition Expr.h:223
QualType getType() const
Definition Expr.h:144
ExprDependence getDependence() const
Definition Expr.h:164
An expression trait intrinsic.
Definition ExprCXX.h:3070
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3102
Expr * getQueriedExpression() const
Definition ExprCXX.h:3109
ExpressionTrait getTrait() const
Definition ExprCXX.h:3105
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3103
virtual void CompleteType(TagDecl *Tag)
Gives the external AST source an opportunity to complete an incomplete type.
Represents difference between two FPOptions values.
Represents a member of a struct/union/class.
Definition Decl.h:3160
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition Decl.h:3260
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition Decl.cpp:4726
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition Decl.h:3340
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition Decl.h:3334
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition Decl.cpp:4736
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition Decl.h:3276
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition Decl.h:3384
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition Decl.cpp:4836
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
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1584
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
Definition Expr.h:1578
SourceLocation getLocation() const
Definition Expr.h:1710
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition Expr.cpp:1076
llvm::APFloat getValue() const
Definition Expr.h:1669
bool isExact() const
Definition Expr.h:1702
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2880
Stmt * getInit()
Definition Stmt.h:2895
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
Definition Stmt.cpp:1120
SourceLocation getRParenLoc() const
Definition Stmt.h:2940
Stmt * getBody()
Definition Stmt.h:2924
Expr * getInc()
Definition Stmt.h:2923
SourceLocation getForLoc() const
Definition Stmt.h:2936
Expr * getCond()
Definition Stmt.h:2922
SourceLocation getLParenLoc() const
Definition Stmt.h:2938
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:144
SourceLocation getEllipsisLoc() const
Retrieves the location of the '...', if present.
Definition DeclFriend.h:149
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
Definition DeclFriend.h:139
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition DeclFriend.h:125
const Expr * getSubExpr() const
Definition Expr.h:1065
static DefaultedOrDeletedFunctionInfo * Create(ASTContext &Context, ArrayRef< DeclAccessPair > Lookups, StringLiteral *DeletedMessage=nullptr)
Definition Decl.cpp:3141
Represents a function declaration or definition.
Definition Decl.h:2000
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition Decl.cpp:3280
ConstexprSpecKind getConstexprKind() const
Definition Decl.h:2476
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition Decl.cpp:4199
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4194
void setIsPureVirtual(bool P=true)
Definition Decl.cpp:3299
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition Decl.cpp:3161
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition Decl.h:2701
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition Decl.cpp:3552
StringLiteral * getDeletedMessage() const
Get the message that indicates why this function was deleted.
Definition Decl.h:2758
bool UsesFPIntrin() const
Determine whether the function was declared in source context that requires constrained FP intrinsics...
Definition Decl.h:2909
SourceLocation getDefaultLoc() const
Definition Decl.h:2398
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2774
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
Definition Decl.h:2389
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition Decl.h:2377
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition Decl.h:2448
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4173
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition Decl.cpp:4324
void setDefaultLoc(SourceLocation NewLoc)
Definition Decl.h:2402
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition Decl.h:2326
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition Decl.cpp:4390
@ TK_FunctionTemplateSpecialization
Definition Decl.h:2016
@ TK_DependentFunctionTemplateSpecialization
Definition Decl.h:2019
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:2888
void setTrivial(bool IT)
Definition Decl.h:2378
bool FriendConstraintRefersToEnclosingTemplate() const
Definition Decl.h:2707
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition Decl.cpp:4145
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition Decl.cpp:4212
bool isDeletedAsWritten() const
Definition Decl.h:2544
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:4379
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Definition Decl.h:2353
FunctionDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
void setVirtualAsWritten(bool V)
State that this function is marked as virtual explicitly.
Definition Decl.h:2349
void setIsDestroyingOperatorDelete(bool IsDestroyingDelete)
Definition Decl.cpp:3556
FunctionDecl * getDefinition()
Get the definition for this declaration.
Definition Decl.h:2282
bool isTypeAwareOperatorNewOrDelete() const
Determine whether this is a type aware operator new or delete.
Definition Decl.cpp:3560
void setIsTypeAwareOperatorNewOrDelete(bool IsTypeAwareOperator=true)
Definition Decl.cpp:3564
void setRangeEnd(SourceLocation E)
Definition Decl.h:2218
bool isDefaulted() const
Whether this function is defaulted.
Definition Decl.h:2385
FunctionDecl * getInstantiatedFromDecl() const
Definition Decl.cpp:4218
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4418
void setDefaulted(bool D=true)
Definition Decl.h:2386
void setBody(Stmt *B)
Definition Decl.cpp:3292
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition Decl.h:2344
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition Decl.cpp:3170
void setExplicitlyDefaulted(bool ED=true)
State that this function is explicitly defaulted.
Definition Decl.h:2394
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4166
DeclarationNameInfo getNameInfo() const
Definition Decl.h:2211
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition Decl.cpp:3200
FunctionDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition Decl.h:2899
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5315
ExtProtoInfo getExtProtoInfo() const
Definition TypeBase.h:5604
ArrayRef< QualType > exceptions() const
Definition TypeBase.h:5769
ArrayRef< QualType > param_types() const
Definition TypeBase.h:5755
Declaration of a template function.
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 TypeBase.h:4867
QualType getReturnType() const
Definition TypeBase.h:4851
This represents a GCC inline-assembly statement extension.
Definition Stmt.h:3438
unsigned getNumLabels() const
Definition Stmt.h:3588
labels_range labels()
Definition Stmt.h:3611
SourceLocation getRParenLoc() const
Definition Stmt.h:3460
IdentifierInfo * getInputIdentifier(unsigned i) const
Definition Stmt.h:3553
const Expr * getOutputConstraintExpr(unsigned i) const
Definition Stmt.h:3540
const Expr * getInputConstraintExpr(unsigned i) const
Definition Stmt.h:3566
IdentifierInfo * getOutputIdentifier(unsigned i) const
Definition Stmt.h:3529
const Expr * getAsmStringExpr() const
Definition Stmt.h:3465
Expr * getClobberExpr(unsigned i)
Definition Stmt.h:3645
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition Expr.h:4926
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4943
Represents a C11 generic selection.
Definition Expr.h:6181
TypeSourceInfo * getControllingType()
Return the controlling type of this generic selection expression.
Definition Expr.h:6458
ArrayRef< Expr * > getAssocExprs() const
Definition Expr.h:6478
bool isExprPredicate() const
Whether this generic selection uses an expression as its controlling argument.
Definition Expr.h:6439
SourceLocation getGenericLoc() const
Definition Expr.h:6536
SourceLocation getRParenLoc() const
Definition Expr.h:6540
unsigned getResultIndex() const
The zero-based index of the result expression's generic association in the generic selection's associ...
Definition Expr.h:6428
SourceLocation getDefaultLoc() const
Definition Expr.h:6539
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:4698
bool isResultDependent() const
Whether this generic selection is result-dependent.
Definition Expr.h:6435
Expr * getControllingExpr()
Return the controlling expression of this generic selection expression.
Definition Expr.h:6446
ArrayRef< TypeSourceInfo * > getAssocTypeSourceInfos() const
Definition Expr.h:6483
GotoStmt - This represents a direct goto.
Definition Stmt.h:2961
SourceLocation getLabelLoc() const
Definition Stmt.h:2979
SourceLocation getGotoLoc() const
Definition Stmt.h:2977
LabelDecl * getLabel() const
Definition Stmt.h:2974
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.
IfStmt - This represents an if/then/else.
Definition Stmt.h:2251
Stmt * getThen()
Definition Stmt.h:2340
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:1044
SourceLocation getIfLoc() const
Definition Stmt.h:2417
IfStatementKind getStatementKind() const
Definition Stmt.h:2452
SourceLocation getElseLoc() const
Definition Stmt.h:2420
Stmt * getInit()
Definition Stmt.h:2401
SourceLocation getLParenLoc() const
Definition Stmt.h:2469
Expr * getCond()
Definition Stmt.h:2328
Stmt * getElse()
Definition Stmt.h:2349
SourceLocation getRParenLoc() const
Definition Stmt.h:2471
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
Definition Stmt.cpp:1068
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition Expr.h:1734
const Expr * getSubExpr() const
Definition Expr.h:1746
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3856
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition Expr.cpp:2073
ArrayRef< TemplateArgument > getTemplateArguments() const
ImplicitParamKind getParameterKind() const
Returns the implicit parameter kind.
Definition Decl.h:1780
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:6060
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition Decl.h:5055
Represents a field injected from an anonymous union/struct into the parent scope.
Definition Decl.h:3467
unsigned getChainingSize() const
Definition Decl.h:3492
ArrayRef< NamedDecl * > chain() const
Definition Decl.h:3488
IndirectGotoStmt - This represents an indirect goto.
Definition Stmt.h:3000
SourceLocation getGotoLoc() const
Definition Stmt.h:3016
SourceLocation getStarLoc() const
Definition Stmt.h:3018
Description of a constructor that was inherited from a base class.
Definition DeclCXX.h:2582
CXXConstructorDecl * getConstructor() const
Definition DeclCXX.h:2595
ConstructorUsingShadowDecl * getShadowDecl() const
Definition DeclCXX.h:2594
Describes an C or C++ initializer list.
Definition Expr.h:5302
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition Expr.h:5414
void setSyntacticForm(InitListExpr *Init)
Definition Expr.h:5479
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition Expr.h:5428
unsigned getNumInits() const
Definition Expr.h:5332
SourceLocation getLBraceLoc() const
Definition Expr.h:5463
void setArrayFiller(Expr *filler)
Definition Expr.cpp:2438
InitListExpr * getSyntacticForm() const
Definition Expr.h:5475
bool hadArrayRangeDesignator() const
Definition Expr.h:5486
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition Expr.h:5404
SourceLocation getRBraceLoc() const
Definition Expr.h:5465
void setInitializedFieldInUnion(FieldDecl *FD)
Definition Expr.h:5434
ArrayRef< Expr * > inits()
Definition Expr.h:5352
void sawArrayRangeDesignator(bool ARD=true)
Definition Expr.h:5489
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:975
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1539
ElaboratedTypeKeyword getKeyword() const
Definition TypeBase.h:5992
Represents the declaration of a label.
Definition Decl.h:524
bool isGnuLocal() const
Definition Decl.h:551
LabelStmt * getStmt() const
Definition Decl.h:548
void setStmt(LabelStmt *T)
Definition Decl.h:549
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2138
LabelDecl * getDecl() const
Definition Stmt.h:2156
Stmt * getSubStmt()
Definition Stmt.h:2160
SourceLocation getIdentLoc() const
Definition Stmt.h:2153
Describes the capture of a variable or of this, or of a C++1y init-capture.
bool capturesVariable() const
Determine whether this capture handles a variable.
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:1264
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:1969
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:1312
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:2187
bool hasExplicitParameters() const
Determine whether this lambda has an explicit parameter list vs.
Definition ExprCXX.h:2172
SourceRange getIntroducerRange() const
Retrieve the source range covering the lambda introducer, which contains the explicit capture list su...
Definition ExprCXX.h:2120
unsigned capture_size() const
Determine the number of captures in this lambda.
Definition ExprCXX.h:2050
CXXMethodDecl * getCallOperator() const
Retrieve the function call operator associated with this lambda expression.
Definition ExprCXX.cpp:1404
bool hasExplicitResultType() const
Whether this lambda had its result type explicitly specified.
Definition ExprCXX.h:2175
SourceLocation getCaptureDefaultLoc() const
Retrieve the location of this lambda's capture-default, if any.
Definition ExprCXX.h:2027
llvm::iterator_range< capture_init_iterator > capture_inits()
Retrieve the initialization expressions for this lambda's captures.
Definition ExprCXX.h:2084
LambdaCaptureDefault getCaptureDefault() const
Determine the default capture kind for this lambda.
Definition ExprCXX.h:2022
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition ExprCXX.cpp:1400
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
Definition DeclCXX.h:3311
Expr * getTemporaryExpr()
Retrieve the expression to which the temporary materialization conversion was applied.
Definition DeclCXX.h:3357
Represents a linkage specification.
Definition DeclCXX.h:3018
void setRBraceLoc(SourceLocation L)
Definition DeclCXX.h:3060
LinkageSpecLanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition DeclCXX.h:3041
SourceLocation getExternLoc() const
Definition DeclCXX.h:3057
SourceLocation getRBraceLoc() const
Definition DeclCXX.h:3058
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition DeclCXX.h:3052
Represents the results of name lookup.
Definition Lookup.h:147
iterator end() const
Definition Lookup.h:359
iterator begin() const
Definition Lookup.h:358
QualType getUnderlyingType() const
Definition TypeBase.h:6210
const IdentifierInfo * getMacroIdentifier() const
Definition TypeBase.h:6209
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4921
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
Definition ExprCXX.h:4938
bool isBoundToLvalueReference() const
Determine whether this materialized temporary is bound to an lvalue reference; otherwise,...
Definition ExprCXX.h:4990
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
Definition ExprCXX.h:4961
QualType getElementType() const
Returns type of the elements being stored in the matrix.
Definition TypeBase.h:4359
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3367
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:3539
SourceLocation getOperatorLoc() const
Definition Expr.h:3549
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition Expr.h:3484
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name,...
Definition Expr.h:3469
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition Expr.h:3450
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition Expr.h:3511
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:3591
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:1750
Expr * getBase() const
Definition Expr.h:3444
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:3500
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:3492
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition Expr.h:3544
bool isArrow() const
Definition Expr.h:3551
DeclAccessPair getFoundDecl() const
Retrieves the declaration found by lookup.
Definition Expr.h:3454
NestedNameSpecifier getQualifier() const
Definition TypeBase.h:3693
CXXRecordDecl * getMostRecentCXXRecordDecl() const
Note: this can trigger extra deserialization when external AST sources are used.
Definition Type.cpp:5530
QualType getPointeeType() const
Definition TypeBase.h:3679
Provides information a specialization of a member of a class template, which may be a member function...
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
This represents a decl that may have a name.
Definition Decl.h:274
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition Decl.cpp:1182
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:295
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:340
Represents a C++ namespace alias.
Definition DeclCXX.h:3204
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3265
SourceLocation getAliasLoc() const
Returns the location of the alias name, i.e.
Definition DeclCXX.h:3287
SourceLocation getNamespaceLoc() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3290
SourceLocation getTargetNameLoc() const
Returns the location of the identifier in the named namespace.
Definition DeclCXX.h:3293
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition DeclCXX.h:3274
Represent a C++ namespace.
Definition Decl.h:592
SourceLocation getRBraceLoc() const
Definition Decl.h:692
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:691
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition Decl.h:648
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace that inhabits this namespace, if any.
Definition Decl.h:675
bool isNested() const
Returns true if this is a nested namespace declaration.
Definition Decl.h:657
void setRBraceLoc(SourceLocation L)
Definition Decl.h:694
Class that aids in the construction of nested-name-specifiers along with source-location information ...
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
A C++ nested-name-specifier augmented with source location information.
NamespaceAndPrefixLoc getAsNamespaceAndPrefix() const
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end 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.
TypeLoc castAsTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsMicrosoftSuper() const
NamespaceAndPrefix getAsNamespaceAndPrefix() const
Kind
The kind of specifier that completes this nested name specifier.
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
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.
unsigned getDepth() const
Get the nesting depth of the template parameter.
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition Stmt.h:1695
bool hasLeadingEmptyMacro() const
Definition Stmt.h:1709
SourceLocation getSemiLoc() const
Definition Stmt.h:1706
Represents Objective-C's @catch statement.
Definition StmtObjC.h:77
const VarDecl * getCatchParamDecl() const
Definition StmtObjC.h:97
const Stmt * getCatchBody() const
Definition StmtObjC.h:93
SourceLocation getAtCatchLoc() const
Definition StmtObjC.h:105
SourceLocation getRParenLoc() const
Definition StmtObjC.h:107
Represents Objective-C's @finally statement.
Definition StmtObjC.h:127
const Stmt * getFinallyBody() const
Definition StmtObjC.h:139
SourceLocation getAtFinallyLoc() const
Definition StmtObjC.h:148
Represents Objective-C's @synchronized statement.
Definition StmtObjC.h:303
const Expr * getSynchExpr() const
Definition StmtObjC.h:331
const CompoundStmt * getSynchBody() const
Definition StmtObjC.h:323
SourceLocation getAtSynchronizedLoc() const
Definition StmtObjC.h:320
Represents Objective-C's @throw statement.
Definition StmtObjC.h:358
const Expr * getThrowExpr() const
Definition StmtObjC.h:370
SourceLocation getThrowLoc() const LLVM_READONLY
Definition StmtObjC.h:374
Represents Objective-C's @try ... @catch ... @finally statement.
Definition StmtObjC.h:167
const ObjCAtFinallyStmt * getFinallyStmt() const
Retrieve the @finally statement, if any.
Definition StmtObjC.h:241
static ObjCAtTryStmt * Create(const ASTContext &Context, SourceLocation atTryLoc, Stmt *atTryStmt, Stmt **CatchStmts, unsigned NumCatchStmts, Stmt *atFinallyStmt)
Definition StmtObjC.cpp:45
unsigned getNumCatchStmts() const
Retrieve the number of @catch statements in this try-catch-finally block.
Definition StmtObjC.h:220
const ObjCAtCatchStmt * getCatchStmt(unsigned I) const
Retrieve a @catch statement.
Definition StmtObjC.h:223
const Stmt * getTryBody() const
Retrieve the @try body.
Definition StmtObjC.h:214
SourceLocation getAtTryLoc() const
Retrieve the location of the @ in the @try.
Definition StmtObjC.h:210
Represents Objective-C's @autoreleasepool Statement.
Definition StmtObjC.h:394
SourceLocation getAtLoc() const
Definition StmtObjC.h:414
const Stmt * getSubStmt() const
Definition StmtObjC.h:405
An Objective-C "bridged" cast expression, which casts between Objective-C pointers and C pointers,...
Definition ExprObjC.h:1640
ObjCCategoryDecl - Represents a category declaration.
Definition DeclObjC.h:2329
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this category.
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:2391
ObjCCategoryImplDecl * getImplementation() const
ObjCInterfaceDecl * getClassInterface()
Definition DeclObjC.h:2372
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
Definition DeclObjC.h:2377
protocol_iterator protocol_end() const
Definition DeclObjC.h:2411
ObjCProtocolList::loc_iterator protocol_loc_iterator
Definition DeclObjC.h:2414
SourceLocation getIvarLBraceLoc() const
Definition DeclObjC.h:2464
SourceLocation getIvarRBraceLoc() const
Definition DeclObjC.h:2466
protocol_loc_iterator protocol_loc_begin() const
Definition DeclObjC.h:2421
protocol_iterator protocol_begin() const
Definition DeclObjC.h:2407
void setImplementation(ObjCCategoryImplDecl *ImplD)
ObjCProtocolList::iterator protocol_iterator
Definition DeclObjC.h:2400
SourceLocation getCategoryNameLoc() const
Definition DeclObjC.h:2460
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition DeclObjC.h:2545
SourceLocation getCategoryNameLoc() const
Definition DeclObjC.h:2572
ObjCCategoryDecl * getCategoryDecl() const
SourceLocation getAtStartLoc() const
Definition DeclObjC.h:1096
Represents Objective-C's collection statement.
Definition StmtObjC.h:23
SourceLocation getForLoc() const
Definition StmtObjC.h:52
SourceLocation getRParenLoc() const
Definition StmtObjC.h:54
const ObjCInterfaceDecl * getClassInterface() const
Definition DeclObjC.h:2486
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition DeclObjC.h:2597
SourceLocation getIvarRBraceLoc() const
Definition DeclObjC.h:2744
SourceLocation getSuperClassLoc() const
Definition DeclObjC.h:2737
const ObjCInterfaceDecl * getSuperClass() const
Definition DeclObjC.h:2735
SourceLocation getIvarLBraceLoc() const
Definition DeclObjC.h:2742
Represents an ObjC class declaration.
Definition DeclObjC.h:1154
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:1485
bool isImplicitInterfaceDecl() const
isImplicitInterfaceDecl - check that this is an implicitly declared ObjCInterfaceDecl node.
Definition DeclObjC.h:1893
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class.
Definition DeclObjC.h:1303
ObjCCategoryDecl * FindCategoryDeclaration(const IdentifierInfo *CategoryId) const
FindCategoryDeclaration - Finds category declaration in the list of categories for this class and ret...
protocol_loc_iterator protocol_loc_begin() const
Definition DeclObjC.h:1392
void setImplementation(ObjCImplementationDecl *ImplD)
known_categories_range known_categories() const
Definition DeclObjC.h:1687
void setSuperClass(TypeSourceInfo *superClass)
Definition DeclObjC.h:1588
protocol_iterator protocol_end() const
Definition DeclObjC.h:1374
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
Definition DeclObjC.cpp:369
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
Definition DeclObjC.h:1523
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this class.
Definition DeclObjC.cpp:340
ObjCProtocolList::iterator protocol_iterator
Definition DeclObjC.h:1356
ObjCImplementationDecl * getImplementation() const
protocol_iterator protocol_begin() const
Definition DeclObjC.h:1363
ObjCProtocolList::loc_iterator protocol_loc_iterator
Definition DeclObjC.h:1385
void startDefinition()
Starts the definition of this Objective-C class, taking it from a forward declaration (@class) to a d...
Definition DeclObjC.cpp:613
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition DeclObjC.h:1915
ObjCInterfaceDecl * getSuperClass() const
Definition DeclObjC.cpp:349
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition DeclObjC.h:1542
TypeSourceInfo * getSuperClassTInfo() const
Definition DeclObjC.h:1573
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
Definition Type.cpp:952
ObjCIvarDecl - Represents an ObjC instance variable.
Definition DeclObjC.h:1952
AccessControl getAccessControl() const
Definition DeclObjC.h:2000
bool getSynthesize() const
Definition DeclObjC.h:2007
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
TypeSourceInfo * getReturnTypeSourceInfo() const
Definition DeclObjC.h:343
void setMethodParams(ASTContext &C, ArrayRef< ParmVarDecl * > Params, ArrayRef< SourceLocation > SelLocs={})
Sets the method's parameters and selector source locations.
Definition DeclObjC.cpp:941
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
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.
QualType getReturnType() const
Definition DeclObjC.h:329
ParmVarDecl *const * param_iterator
Definition DeclObjC.h:350
ObjCImplementationControl getImplementationControl() const
Definition DeclObjC.h:500
ObjCInterfaceDecl * getClassInterface()
void getSelectorLocs(SmallVectorImpl< SourceLocation > &SelLocs) const
Definition DeclObjC.cpp:935
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Definition TypeBase.h:8018
Represents one property declaration in an Objective-C interface.
Definition DeclObjC.h:731
void setSetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition DeclObjC.h:896
SourceLocation getGetterNameLoc() const
Definition DeclObjC.h:886
ObjCMethodDecl * getGetterMethodDecl() const
Definition DeclObjC.h:901
bool isInstanceProperty() const
Definition DeclObjC.h:854
ObjCMethodDecl * getSetterMethodDecl() const
Definition DeclObjC.h:904
SourceLocation getSetterNameLoc() const
Definition DeclObjC.h:894
SourceLocation getAtLoc() const
Definition DeclObjC.h:796
void setPropertyAttributes(ObjCPropertyAttribute::Kind PRVal)
Definition DeclObjC.h:819
ObjCIvarDecl * getPropertyIvarDecl() const
Definition DeclObjC.h:924
Selector getSetterName() const
Definition DeclObjC.h:893
TypeSourceInfo * getTypeSourceInfo() const
Definition DeclObjC.h:802
QualType getType() const
Definition DeclObjC.h:804
void setPropertyAttributesAsWritten(ObjCPropertyAttribute::Kind PRVal)
Definition DeclObjC.h:831
Selector getGetterName() const
Definition DeclObjC.h:885
void setPropertyIvarDecl(ObjCIvarDecl *Ivar)
Definition DeclObjC.h:920
SourceLocation getLParenLoc() const
Definition DeclObjC.h:799
void setSetterMethodDecl(ObjCMethodDecl *gDecl)
Definition DeclObjC.h:905
ObjCPropertyAttribute::Kind getPropertyAttributesAsWritten() const
Definition DeclObjC.h:827
ObjCPropertyAttribute::Kind getPropertyAttributes() const
Definition DeclObjC.h:815
void setGetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition DeclObjC.h:888
PropertyControl getPropertyImplementation() const
Definition DeclObjC.h:912
void setGetterMethodDecl(ObjCMethodDecl *gDecl)
Definition DeclObjC.h:902
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition DeclObjC.h:2805
ObjCIvarDecl * getPropertyIvarDecl() const
Definition DeclObjC.h:2879
SourceLocation getPropertyIvarDeclLoc() const
Definition DeclObjC.h:2882
Kind getPropertyImplementation() const
Definition DeclObjC.h:2875
ObjCPropertyDecl * getPropertyDecl() const
Definition DeclObjC.h:2870
SourceLocation getBeginLoc() const LLVM_READONLY
Definition DeclObjC.h:2867
Represents an Objective-C protocol declaration.
Definition DeclObjC.h:2084
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
Definition DeclObjC.h:2261
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:2209
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Definition DeclObjC.h:2250
void startDefinition()
Starts the definition of this Objective-C protocol.
ObjCProtocolList::iterator protocol_iterator
Definition DeclObjC.h:2158
protocol_iterator protocol_begin() const
Definition DeclObjC.h:2165
ObjCProtocolList::loc_iterator protocol_loc_iterator
Definition DeclObjC.h:2179
protocol_iterator protocol_end() const
Definition DeclObjC.h:2172
protocol_loc_iterator protocol_loc_begin() const
Definition DeclObjC.h:2186
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:636
const Type * getTypeForDecl() const
Definition Decl.h:3538
SourceLocation getColonLoc() const
Retrieve the location of the ':' separating the type parameter name from the explicitly-specified bou...
Definition DeclObjC.h:644
ObjCTypeParamVariance getVariance() const
Determine the variance of this type parameter.
Definition DeclObjC.h:623
SourceLocation getVarianceLoc() const
Retrieve the location of the variance keyword.
Definition DeclObjC.h:633
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition DeclObjC.h:662
SourceLocation getRAngleLoc() const
Definition DeclObjC.h:711
static ObjCTypeParamList * create(ASTContext &ctx, SourceLocation lAngleLoc, ArrayRef< ObjCTypeParamDecl * > typeParams, SourceLocation rAngleLoc)
Create a new Objective-C type parameter list.
SourceLocation getLAngleLoc() const
Definition DeclObjC.h:710
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition Expr.h:2530
Expr * getIndexExpr(unsigned Idx)
Definition Expr.h:2589
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2563
const OffsetOfNode & getComponent(unsigned Idx) const
Definition Expr.h:2577
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
Definition Expr.cpp:1653
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:2570
unsigned getNumExpressions() const
Definition Expr.h:2601
SourceLocation getRParenLoc() const
Return the location of the right parentheses.
Definition Expr.h:2567
unsigned getNumComponents() const
Definition Expr.h:2585
Helper class for OffsetOfExpr.
Definition Expr.h:2424
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition Expr.h:2482
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition Expr.h:2488
IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition Expr.cpp:1688
@ Array
An index into an array.
Definition Expr.h:2429
@ Identifier
A field in a dependent type, known only by its name.
Definition Expr.h:2433
@ Field
A field.
Definition Expr.h:2431
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition Expr.h:2436
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2510
Kind getKind() const
Determine what kind of offsetof node this is.
Definition Expr.h:2478
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2511
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition Expr.h:2498
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1181
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1231
SourceLocation getLocation() const
Retrieve the location of this expression.
Definition Expr.h:1203
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition ExprCXX.h:3281
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3263
const DeclarationNameInfo & getNameInfo() const
Gets the full name info.
Definition ExprCXX.h:3236
SourceLocation getNameLoc() const
Gets the location of the name.
Definition ExprCXX.h:3242
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3255
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition ExprCXX.h:3251
llvm::iterator_range< decls_iterator > decls() const
Definition ExprCXX.h:3228
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments into the given structure.
Definition ExprCXX.h:3343
DeclarationName getName() const
Gets the name looked up.
Definition ExprCXX.h:3239
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3271
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:3338
A structure for storing the information associated with an overloaded template name.
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition ExprCXX.h:4364
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition ExprCXX.h:4393
UnsignedOrNone getNumExpansions() const
Determine the number of expansions that will be produced when this pack expansion is instantiated,...
Definition ExprCXX.h:4404
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis that describes this pack expansion.
Definition ExprCXX.h:4400
ParenExpr - This represents a parenthesized expression, e.g.
Definition Expr.h:2185
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition Expr.h:2210
const Expr * getSubExpr() const
Definition Expr.h:2202
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition Expr.h:2214
ArrayRef< Expr * > exprs()
Definition Expr.h:6126
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition Expr.cpp:4948
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition Expr.h:6113
SourceLocation getLParenLoc() const
Definition Expr.h:6128
SourceLocation getRParenLoc() const
Definition Expr.h:6129
QualType getInnerType() const
Definition TypeBase.h:3319
Represents a parameter to a function.
Definition Decl.h:1790
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion:
Definition Decl.h:1871
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition Decl.h:1850
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition Decl.h:1858
void setDefaultArg(Expr *defarg)
Definition Decl.cpp:3023
SourceLocation getExplicitObjectParamThisLoc() const
Definition Decl.h:1886
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition Decl.h:1931
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition Decl.h:1919
void setUninstantiatedDefaultArg(Expr *arg)
Definition Decl.cpp:3048
bool isObjCMethodParameter() const
Definition Decl.h:1833
ObjCDeclQualifier getObjCDeclQualifier() const
Definition Decl.h:1854
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1823
bool hasUninstantiatedDefaultArg() const
Definition Decl.h:1923
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition Decl.h:1818
bool hasInheritedDefaultArg() const
Definition Decl.h:1935
void setKNRPromoted(bool promoted)
Definition Decl.h:1874
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition Decl.h:1882
Expr * getDefaultArg()
Definition Decl.cpp:3011
Expr * getUninstantiatedDefaultArg()
Definition Decl.cpp:3053
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition Decl.cpp:3059
unsigned getFunctionScopeDepth() const
Definition Decl.h:1840
void setHasInheritedDefaultArg(bool I=true)
Definition Decl.h:1939
QualType getElementType() const
Definition TypeBase.h:8217
bool isReadOnly() const
Definition TypeBase.h:8236
QualType getPointeeType() const
Definition TypeBase.h:3346
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2008
SourceLocation getBeginLoc() const
Definition Expr.h:2073
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
Definition Expr.cpp:633
bool isTransparent() const
Definition Expr.h:2047
PredefinedIdentKind getIdentKind() const
Definition Expr.h:2043
StringLiteral * getFunctionName()
Definition Expr.h:2052
Stores the type being destroyed by a pseudo-destructor expression.
Definition ExprCXX.h:2695
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6803
unsigned getResultExprIndex() const
Return the index of the result-bearing expression into the semantics expressions, or PseudoObjectExpr...
Definition Expr.h:6845
static PseudoObjectExpr * Create(const ASTContext &Context, Expr *syntactic, ArrayRef< Expr * > semantic, unsigned resultIndex)
Definition Expr.cpp:5170
ArrayRef< Expr * > semantics()
Definition Expr.h:6875
unsigned getNumSemanticExprs() const
Definition Expr.h:6860
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Definition Expr.h:6840
A (possibly-)qualified type.
Definition TypeBase.h:937
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1004
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition TypeBase.h:8388
QualType getSingleStepDesugaredType(const ASTContext &Context) const
Return the specified type with one level of "sugar" removed from the type.
Definition TypeBase.h:1315
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition TypeBase.h:8420
Represents a template name as written in source code.
NestedNameSpecifier getQualifier() const
Return the nested name specifier that qualifies this name.
TemplateName getUnderlyingTemplate() const
Return the underlying template name.
bool hasTemplateKeyword() const
Whether the template name was prefixed by the "template" keyword.
Represents a struct/union/class.
Definition Decl.h:4327
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition Decl.cpp:5247
void setAnonymousStructOrUnion(bool Anon)
Definition Decl.h:4383
field_range fields() const
Definition Decl.h:4530
RecordDecl * getMostRecentDecl()
Definition Decl.h:4353
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition Decl.cpp:5292
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4511
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition Decl.h:4379
Provides common interface for the Decls that can be redeclared.
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
Definition Decl.h:5332
QualType getPointeeTypeAsWritten() const
Definition TypeBase.h:3597
Represents the body of a requires-expression.
Definition DeclCXX.h:2105
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
SourceLocation getLParenLoc() const
SourceLocation getRParenLoc() const
SourceLocation getRBraceLoc() const
SourceLocation getRequiresKWLoc() const
static RequiresExpr * Create(ASTContext &C, SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, SourceLocation LParenLoc, ArrayRef< ParmVarDecl * > LocalParameters, SourceLocation RParenLoc, ArrayRef< concepts::Requirement * > Requirements, SourceLocation RBraceLoc)
RequiresExprBodyDecl * getBody() const
ArrayRef< concepts::Requirement * > getRequirements() const
ArrayRef< ParmVarDecl * > getLocalParameters() const
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition Stmt.h:3152
SourceLocation getReturnLoc() const
Definition Stmt.h:3201
const VarDecl * getNRVOCandidate() const
Retrieve the variable that might be used for the named return value optimization.
Definition Stmt.h:3188
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition Stmt.cpp:1290
Expr * getRetValue()
Definition Stmt.h:3179
Smart pointer class that efficiently represents Objective-C method names.
const IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
bool isNull() const
Determine whether this is the empty selector.
unsigned getNumArgs() const
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition Expr.h:4646
Expr ** getSubExprs()
Retrieve the array of expressions.
Definition Expr.h:4682
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Definition Expr.h:4679
SourceLocation getRParenLoc() const
Definition Expr.h:4666
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4669
Represents an expression that computes the length of a parameter pack.
Definition ExprCXX.h:4442
SourceLocation getPackLoc() const
Determine the location of the parameter pack.
Definition ExprCXX.h:4504
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof... expression, such as is produced f...
Definition ExprCXX.h:4527
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, UnsignedOrNone Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Definition ExprCXX.cpp:1709
ArrayRef< TemplateArgument > getPartialArguments() const
Get.
Definition ExprCXX.h:4532
SourceLocation getOperatorLoc() const
Determine the location of the 'sizeof' keyword.
Definition ExprCXX.h:4501
SourceLocation getRParenLoc() const
Determine the location of the right parenthesis.
Definition ExprCXX.h:4507
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition ExprCXX.h:4510
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Definition ExprCXX.h:4516
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition Expr.h:5020
SourceLocation getBeginLoc() const
Definition Expr.h:5065
const DeclContext * getParentContext() const
If the SourceLocExpr has been resolved return the subexpression representing the resolved value.
Definition Expr.h:5061
SourceLocation getEndLoc() const
Definition Expr.h:5066
SourceLocIdentKind getIdentKind() const
Definition Expr.h:5040
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.
FileIDAndOffset getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
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.
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:4139
bool isFailed() const
Definition DeclCXX.h:4168
SourceLocation getRParenLoc() const
Definition DeclCXX.h:4170
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition Expr.h:4598
CompoundStmt * getSubStmt()
Definition Expr.h:4615
unsigned getTemplateDepth() const
Definition Expr.h:4627
SourceLocation getRParenLoc() const
Definition Expr.h:4624
SourceLocation getLParenLoc() const
Definition Expr.h:4622
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Stmt - This represents one statement.
Definition Stmt.h:86
child_iterator child_begin()
Definition Stmt.h:1583
StmtClass getStmtClass() const
Definition Stmt.h:1485
child_iterator child_end()
Definition Stmt.h:1584
const char * getStmtClassName() const
Definition Stmt.cpp:86
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.cpp:355
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1802
bool isPascal() const
Definition Expr.h:1925
tokloc_iterator tokloc_begin() const
Definition Expr.h:1968
tokloc_iterator tokloc_end() const
Definition Expr.h:1972
StringLiteralKind getKind() const
Definition Expr.h:1915
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, ArrayRef< SourceLocation > Locs)
This is the "fully general" constructor that allows representation of strings formed from one or more...
Definition Expr.cpp:1188
StringRef getBytes() const
Allow access to clients that need the byte representation, such as ASTWriterStmt::VisitStringLiteral(...
Definition Expr.h:1878
unsigned getNumConcatenated() const
getNumConcatenated - Get the number of string literal tokens that were concatenated in translation ph...
Definition Expr.h:1943
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition ExprCXX.h:4665
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition ExprCXX.h:4710
UnsignedOrNone getPackIndex() const
Definition ExprCXX.h:4716
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition ExprCXX.h:4714
SourceLocation getNameLoc() const
Definition ExprCXX.h:4700
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
Definition ExprCXX.h:4755
TemplateArgument getArgumentPack() const
Retrieve the template argument pack containing the substituted template arguments.
Definition ExprCXX.cpp:1799
SourceLocation getParameterPackLocation() const
Retrieve the location of the parameter pack name.
Definition ExprCXX.h:4803
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition ExprCXX.h:4789
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition ExprCXX.h:4793
A structure for storing an already-substituted template template parameter pack.
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.
A structure for storing the information associated with a substituted template template parameter.
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
void setNextSwitchCase(SwitchCase *SC)
Definition Stmt.h:1887
SourceLocation getColonLoc() const
Definition Stmt.h:1891
const SwitchCase * getNextSwitchCase() const
Definition Stmt.h:1885
SwitchStmt - This represents a 'switch' stmt.
Definition Stmt.h:2501
SourceLocation getSwitchLoc() const
Definition Stmt.h:2636
SourceLocation getLParenLoc() const
Definition Stmt.h:2638
SourceLocation getRParenLoc() const
Definition Stmt.h:2640
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a switch statement.
Definition Stmt.cpp:1167
Expr * getCond()
Definition Stmt.h:2564
Stmt * getBody()
Definition Stmt.h:2576
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
Definition Stmt.cpp:1186
Stmt * getInit()
Definition Stmt.h:2581
SwitchCase * getSwitchCaseList()
Definition Stmt.h:2632
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3717
SourceRange getBraceRange() const
Definition Decl.h:3794
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition Decl.h:3838
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition Decl.cpp:4930
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition Decl.h:3813
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3818
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:3971
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition Decl.h:3954
void startDefinition()
Starts the definition of this tag declaration.
Definition Decl.cpp:4907
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition Decl.cpp:4902
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:4944
TagKind getTagKind() const
Definition Decl.h:3917
void setBraceRange(SourceRange R)
Definition Decl.h:3795
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition Decl.h:3821
A convenient class for passing around template argument information.
SourceLocation getRAngleLoc() const
void addArgument(const TemplateArgumentLoc &Loc)
ArrayRef< TemplateArgumentLoc > arguments() const
SourceLocation getLAngleLoc() const
A template argument list.
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.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Location wrapper for a TemplateArgument.
TemplateArgumentLocInfo getLocInfo() const
const TemplateArgument & getArgument() const
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Represents a template argument.
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
QualType getStructuralValueType() const
Get the type of a StructuralValue.
QualType getParamTypeForDecl() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
UnsignedOrNone 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.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
QualType getIntegralType() const
Retrieve the type of the integral value.
bool getIsDefaulted() const
If returns 'true', this TemplateArgument corresponds to a default template parameter.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
bool isCanonicalExpr() const
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
OverloadedTemplateStorage * getAsOverloadedTemplate() const
Retrieve the underlying, overloaded function template declarations that this template name refers to,...
AssumedTemplateStorage * getAsAssumedTemplateName() const
Retrieve information on a name that has been assumed to be a template-name in order to permit a call ...
NameKind getKind() const
@ UsingTemplate
A template name that refers to a template declaration found through a specific using shadow declarati...
@ OverloadedTemplate
A set of overloaded template declarations.
@ Template
A single template declaration.
@ DependentTemplate
A dependent template name that has not been resolved to a template (or set of templates).
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
@ DeducedTemplate
A template name that refers to another TemplateName with deduced default arguments.
@ QualifiedTemplate
A qualified template name, where the qualification is kept to describe the source code as written.
@ AssumedTemplate
An unqualified-id that has been assumed to name a function template that will be found by ADL.
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.
NamedDecl * getParam(unsigned Idx)
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.
SourceLocation getRAngleLoc() const
SourceLocation getLAngleLoc() const
SourceLocation getTemplateLoc() const
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
bool wasDeclaredWithTypename() const
Whether this template template parameter was declared with the 'typename' keyword.
TemplateNameKind templateParameterKind() const
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.
unsigned getDepth() const
Get the nesting depth of the template parameter.
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.
void setTypeConstraint(ConceptReference *CR, Expr *ImmediatelyDeclaredConstraint, UnsignedOrNone ArgPackSubstIndex)
bool hasTypeConstraint() const
Determine whether this template parameter has a type-constraint.
const TypeConstraint * getTypeConstraint() const
Returns the type constraint associated with this template parameter (if any).
bool isParameterPack() const
Returns whether this is a parameter pack.
unsigned getDepth() const
Retrieve the depth of the template parameter.
The top declaration context.
Definition Decl.h:105
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition Decl.h:3688
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition Decl.h:3706
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:227
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:3547
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:193
TypeOfKind getKind() const
Returns the kind of 'typeof' type this is.
Definition TypeBase.h:6240
Expr * getUnderlyingExpr() const
Definition TypeBase.h:6237
A container of type source information.
Definition TypeBase.h:8359
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition TypeLoc.h:267
QualType getType() const
Return the type wrapped by this type source info.
Definition TypeBase.h:8370
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition ExprCXX.h:2897
bool getBoolValue() const
Definition ExprCXX.h:2948
ArrayRef< TypeSourceInfo * > getArgs() const
Retrieve the argument types.
Definition ExprCXX.h:2968
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:1914
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:2973
unsigned getNumArgs() const
Determine the number of arguments to this type trait.
Definition ExprCXX.h:2959
TypeTrait getTrait() const
Determine which type trait this expression uses.
Definition ExprCXX.h:2940
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:2972
const APValue & getAPValue() const
Definition ExprCXX.h:2953
bool isStoredAsBoolean() const
Definition ExprCXX.h:2944
An operation on a type.
Definition TypeVisitor.h:64
The base class of the type hierarchy.
Definition TypeBase.h:1839
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition Type.h:41
bool isArrayType() const
Definition TypeBase.h:8724
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition TypeBase.h:9171
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition Type.cpp:2479
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition TypeBase.h:2417
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9218
bool isRecordType() const
Definition TypeBase.h:8752
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition Decl.h:3667
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3562
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:3612
QualType getUnderlyingType() const
Definition Decl.h:3617
TypedefNameDecl * getDecl() const
Definition TypeBase.h:6160
NestedNameSpecifier getQualifier() const
Definition TypeBase.h:6155
bool typeMatchesDecl() const
Definition TypeBase.h:6168
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2628
SourceLocation getRParenLoc() const
Definition Expr.h:2704
SourceLocation getOperatorLoc() const
Definition Expr.h:2701
TypeSourceInfo * getArgumentTypeInfo() const
Definition Expr.h:2674
UnaryExprOrTypeTrait getKind() const
Definition Expr.h:2660
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2247
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2292
Expr * getSubExpr() const
Definition Expr.h:2288
Opcode getOpcode() const
Definition Expr.h:2283
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
Definition Expr.h:2384
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition Expr.h:2387
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition Expr.cpp:5112
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Definition Expr.h:2301
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition ExprCXX.h:3391
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition ExprCXX.h:3465
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition ExprCXX.h:3460
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, UnresolvedSetIterator Begin, UnresolvedSetIterator End, bool KnownDependent, bool KnownInstantiationDependent)
Definition ExprCXX.cpp:432
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition ExprCXX.h:4127
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition ExprCXX.h:4219
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition ExprCXX.h:4222
bool hasUnresolvedUsing() const
Determine whether the lookup results contain an unresolved using declaration.
Definition ExprCXX.h:4213
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition ExprCXX.h:4200
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:1652
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:1645
void addDecl(NamedDecl *D)
A set of unresolved declarations.
NestedNameSpecifier getQualifier() const
Definition TypeBase.h:6057
UnresolvedUsingTypenameDecl * getDecl() const
Definition TypeBase.h:6063
Represents a dependent using declaration which was marked with typename.
Definition DeclCXX.h:4040
SourceLocation getTypenameLoc() const
Returns the source location of the 'typename' keyword.
Definition DeclCXX.h:4070
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:4074
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:4067
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:4091
Represents a dependent using declaration which was not marked with typename.
Definition DeclCXX.h:3943
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:3974
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:3984
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:3991
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:4001
Represents a C++ using-declaration.
Definition DeclCXX.h:3594
bool hasTypename() const
Return true if the using declaration has 'typename'.
Definition DeclCXX.h:3643
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:3628
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:3635
SourceLocation getUsingLoc() const
Return the source location of the 'using' keyword.
Definition DeclCXX.h:3621
Represents C++ using-directive.
Definition DeclCXX.h:3099
SourceLocation getUsingLoc() const
Return the location of the using keyword.
Definition DeclCXX.h:3170
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Definition DeclCXX.cpp:3315
DeclContext * getCommonAncestor()
Returns the common ancestor context of this using-directive and its nominated namespace.
Definition DeclCXX.h:3166
SourceLocation getNamespaceKeyLocation() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3174
SourceLocation getIdentLocation() const
Returns the location of this using declaration's identifier.
Definition DeclCXX.h:3177
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3144
Represents a C++ using-enum-declaration.
Definition DeclCXX.h:3795
SourceLocation getEnumLoc() const
The source location of the 'enum' keyword.
Definition DeclCXX.h:3819
TypeSourceInfo * getEnumType() const
Definition DeclCXX.h:3831
SourceLocation getUsingLoc() const
The source location of the 'using' keyword.
Definition DeclCXX.h:3815
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition DeclCXX.h:3876
NamedDecl * getInstantiatedFromUsingDecl() const
Get the using declaration from which this was instantiated.
Definition DeclCXX.h:3905
ArrayRef< NamedDecl * > expansions() const
Get the set of using declarations that this pack expanded into.
Definition DeclCXX.h:3909
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3402
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition DeclCXX.h:3466
BaseUsingDecl * getIntroducer() const
Gets the (written or instantiated) using declaration that introduced this declaration.
Definition DeclCXX.cpp:3445
UsingShadowDecl * getDecl() const
Definition TypeBase.h:6103
QualType desugar() const
Definition TypeBase.h:6105
NestedNameSpecifier getQualifier() const
Definition TypeBase.h:6099
Represents a call to the builtin function __builtin_va_arg.
Definition Expr.h:4960
TypeSourceInfo * getWrittenTypeInfo() const
Definition Expr.h:4984
SourceLocation getBuiltinLoc() const
Definition Expr.h:4987
SourceLocation getRParenLoc() const
Definition Expr.h:4990
bool isMicrosoftABI() const
Returns whether this is really a Win64 ABI va_arg expression.
Definition Expr.h:4981
const Expr * getSubExpr() const
Definition Expr.h:4976
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
void setType(QualType newType)
Definition Decl.h:724
QualType getType() const
Definition Decl.h:723
Represents a variable declaration or definition.
Definition Decl.h:926
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition Decl.cpp:2822
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition Decl.h:1569
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition Decl.cpp:2947
VarDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
DefinitionKind isThisDeclarationADefinition(ASTContext &) const
Check whether this declaration is a definition.
Definition Decl.cpp:2272
bool isInlineSpecified() const
Definition Decl.h:1554
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition Decl.cpp:2378
EvaluatedStmt * getEvaluatedStmt() const
Definition Decl.cpp:2583
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition Decl.cpp:2569
void setInlineSpecified()
Definition Decl.h:1558
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
Definition Decl.cpp:2784
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
Definition Decl.h:1342
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition Decl.h:1173
bool isInline() const
Whether this variable is (C++1z) inline.
Definition Decl.h:1551
ThreadStorageClassSpecifier getTSCSpec() const
Definition Decl.h:1177
const Expr * getInit() const
Definition Decl.h:1368
void setConstexpr(bool IC)
Definition Decl.h:1572
void setInit(Expr *I)
Definition Decl.cpp:2489
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition Decl.cpp:2827
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1168
void setImplicitlyInline()
Definition Decl.h:1563
VarDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Definition Decl.h:1358
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition Decl.cpp:2910
Declaration of a variable template.
VarDecl * getTemplatedDecl() const
Get the underlying variable declarations of the template.
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary variable pattern.
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 setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
void setSpecializationKind(TemplateSpecializationKind TSK)
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.
VarTemplateSpecializationDecl * getMostRecentDecl()
Expr * getSizeExpr() const
Definition TypeBase.h:3988
unsigned getNumElements() const
Definition TypeBase.h:4198
VectorKind getVectorKind() const
Definition TypeBase.h:4203
QualType getElementType() const
Definition TypeBase.h:4197
WhileStmt - This represents a 'while' stmt.
Definition Stmt.h:2689
Expr * getCond()
Definition Stmt.h:2741
SourceLocation getWhileLoc() const
Definition Stmt.h:2794
SourceLocation getRParenLoc() const
Definition Stmt.h:2799
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
Definition Stmt.cpp:1247
SourceLocation getLParenLoc() const
Definition Stmt.h:2797
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:1229
Stmt * getBody()
Definition Stmt.h:2753
A requires-expression requirement which queries the validity and properties of an expression ('simple...
SubstitutionDiagnostic * getExprSubstitutionDiagnostic() const
ConceptSpecializationExpr * getReturnTypeRequirementSubstitutedConstraintExpr() const
const ReturnTypeRequirement & getReturnTypeRequirement() const
SatisfactionStatus getSatisfactionStatus() const
SourceLocation getNoexceptLoc() const
A requires-expression requirement which is satisfied when a general constraint expression is satisfie...
const ASTConstraintSatisfaction & getConstraintSatisfaction() const
A static requirement that can be used in a requires-expression to check properties of types and expre...
RequirementKind getKind() const
A requires-expression requirement which queries the existence of a type name or type template special...
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
TypeSourceInfo * getType() const
Definition SPIR.cpp:35
Definition SPIR.cpp:47
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
bool isa(CodeGen::Address addr)
Definition Address.h:330
llvm::Expected< SourceLocation > ExpectedSLoc
StructuralEquivalenceKind
Whether to perform a normal or minimal equivalence check.
llvm::Expected< const Type * > ExpectedTypePtr
CanThrowResult
Possible results from evaluation of a noexcept expression.
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
Definition Parser.h:61
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition Specifiers.h:149
std::pair< FileID, unsigned > FileIDAndOffset
llvm::Expected< DeclarationName > ExpectedName
llvm::Expected< Decl * > ExpectedDecl
@ Property
The type of a property.
Definition TypeBase.h:911
@ Result
The result type of a method or function.
Definition TypeBase.h:905
llvm::Expected< QualType > ExpectedType
@ Template
We are parsing a template declaration.
Definition Parser.h:81
@ VarTemplate
The name was classified as a variable template name.
Definition Sema.h:585
std::pair< SourceLocation, StringRef > ConstraintSubstitutionDiagnostic
Unsatisfied constraint expressions if the template arguments could be substituted into them,...
Definition ASTConcept.h:40
CastKind
CastKind - The kind of operation required for a conversion.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition Specifiers.h:132
llvm::SmallVector< Decl *, 2 > getCanonicalForwardRedeclChain(Decl *D)
SmallVector< CXXBaseSpecifier *, 4 > CXXCastPath
A simple array of base specifiers.
Definition ASTContext.h:150
llvm::Expected< Expr * > ExpectedExpr
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition DeclBase.h:1288
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition Specifiers.h:188
U cast(CodeGen::Address addr)
Definition Address.h:327
bool isLambdaMethod(const DeclContext *DC)
Definition ASTLambda.h:39
llvm::Expected< Stmt * > ExpectedStmt
static void updateFlags(const Decl *From, Decl *To)
unsigned int uint32_t
Used as return type of getFriendCountAndPosition.
unsigned int IndexOfDecl
Index of the specific FriendDecl.
unsigned int TotalCount
Number of similar looking friends.
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition ASTConcept.h:91
const UnsatisfiedConstraintRecord * end() const
Definition ASTConcept.h:100
static ASTConstraintSatisfaction * Rebuild(const ASTContext &C, const ASTConstraintSatisfaction &Satisfaction)
const UnsatisfiedConstraintRecord * begin() const
Definition ASTConcept.h:96
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
const Expr * ConstraintExpr
Definition Decl.h:88
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:887
bool HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition Decl.h:905
bool HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition Decl.h:898
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition TypeBase.h:5384
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5388
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5374
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5377
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5380
Extra information about a function prototype.
Definition TypeBase.h:5400
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
const NamespaceBaseDecl * Namespace
bool IsEquivalent(Decl *D1, Decl *D2)
Determine whether the two declarations are structurally equivalent.
Location information for a TemplateArgument.
SourceLocation getTemplateEllipsisLoc() const
SourceLocation getTemplateKwLoc() const
TypeSourceInfo * getAsTypeSourceInfo() const
SourceLocation getTemplateNameLoc() const