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 = 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 CXXRecordDecl::LambdaNumbering Numbering = DCXX->getLambdaNumbering();
3448 ExpectedDecl CDeclOrErr = import(Numbering.ContextDecl);
3449 if (!CDeclOrErr)
3450 return CDeclOrErr.takeError();
3451 Numbering.ContextDecl = *CDeclOrErr;
3452 D2CXX->setLambdaNumbering(Numbering);
3453 } else {
3454 if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
3455 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3456 Name.getAsIdentifierInfo(),
3457 cast_or_null<CXXRecordDecl>(PrevDecl)))
3458 return D2CXX;
3459 }
3460
3461 D2 = D2CXX;
3462 D2->setAccess(D->getAccess());
3463 D2->setLexicalDeclContext(LexicalDC);
3464 addDeclToContexts(D, D2);
3465
3466 if (ClassTemplateDecl *FromDescribed =
3467 DCXX->getDescribedClassTemplate()) {
3468 ClassTemplateDecl *ToDescribed;
3469 if (Error Err = importInto(ToDescribed, FromDescribed))
3470 return std::move(Err);
3471 D2CXX->setDescribedClassTemplate(ToDescribed);
3472 } else if (MemberSpecializationInfo *MemberInfo =
3473 DCXX->getMemberSpecializationInfo()) {
3475 MemberInfo->getTemplateSpecializationKind();
3477
3478 if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
3479 D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
3480 else
3481 return ToInstOrErr.takeError();
3482
3483 if (ExpectedSLoc POIOrErr =
3484 import(MemberInfo->getPointOfInstantiation()))
3486 *POIOrErr);
3487 else
3488 return POIOrErr.takeError();
3489 }
3490
3491 } else {
3492 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
3493 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3494 Name.getAsIdentifierInfo(), PrevDecl))
3495 return D2;
3496 D2->setLexicalDeclContext(LexicalDC);
3497 addDeclToContexts(D, D2);
3498 }
3499
3500 if (auto BraceRangeOrErr = import(D->getBraceRange()))
3501 D2->setBraceRange(*BraceRangeOrErr);
3502 else
3503 return BraceRangeOrErr.takeError();
3504 if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
3505 D2->setQualifierInfo(*QualifierLocOrErr);
3506 else
3507 return QualifierLocOrErr.takeError();
3508
3509 if (D->isAnonymousStructOrUnion())
3510 D2->setAnonymousStructOrUnion(true);
3511
3512 if (D->isCompleteDefinition())
3513 if (Error Err = ImportDefinition(D, D2, IDK_Default))
3514 return std::move(Err);
3515
3516 return D2;
3517}
3518
3520 // Import the major distinguishing characteristics of this enumerator.
3521 DeclContext *DC, *LexicalDC;
3522 DeclarationName Name;
3523 SourceLocation Loc;
3524 NamedDecl *ToD;
3525 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3526 return std::move(Err);
3527 if (ToD)
3528 return ToD;
3529
3530 // Determine whether there are any other declarations with the same name and
3531 // in the same context.
3532 if (!LexicalDC->isFunctionOrMethod()) {
3533 SmallVector<NamedDecl *, 4> ConflictingDecls;
3534 unsigned IDNS = Decl::IDNS_Ordinary;
3535 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3536 for (auto *FoundDecl : FoundDecls) {
3537 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3538 continue;
3539
3540 if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
3541 if (IsStructuralMatch(D, FoundEnumConstant))
3542 return Importer.MapImported(D, FoundEnumConstant);
3543 ConflictingDecls.push_back(FoundDecl);
3544 }
3545 }
3546
3547 if (!ConflictingDecls.empty()) {
3548 ExpectedName NameOrErr = Importer.HandleNameConflict(
3549 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3550 if (NameOrErr)
3551 Name = NameOrErr.get();
3552 else
3553 return NameOrErr.takeError();
3554 }
3555 }
3556
3557 ExpectedType TypeOrErr = import(D->getType());
3558 if (!TypeOrErr)
3559 return TypeOrErr.takeError();
3560
3561 ExpectedExpr InitOrErr = import(D->getInitExpr());
3562 if (!InitOrErr)
3563 return InitOrErr.takeError();
3564
3565 EnumConstantDecl *ToEnumerator;
3566 if (GetImportedOrCreateDecl(
3567 ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
3568 Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
3569 return ToEnumerator;
3570
3571 ToEnumerator->setAccess(D->getAccess());
3572 ToEnumerator->setLexicalDeclContext(LexicalDC);
3573 LexicalDC->addDeclInternal(ToEnumerator);
3574 return ToEnumerator;
3575}
3576
3577template <typename DeclTy>
3579 DeclTy *ToD) {
3580 unsigned int Num = FromD->getNumTemplateParameterLists();
3581 if (Num == 0)
3582 return Error::success();
3584 for (unsigned int I = 0; I < Num; ++I)
3585 if (Expected<TemplateParameterList *> ToTPListOrErr =
3586 import(FromD->getTemplateParameterList(I)))
3587 ToTPLists[I] = *ToTPListOrErr;
3588 else
3589 return ToTPListOrErr.takeError();
3590 ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
3591 return Error::success();
3592}
3593
3595 FunctionDecl *FromFD, FunctionDecl *ToFD) {
3596 switch (FromFD->getTemplatedKind()) {
3599 return Error::success();
3600
3602 if (Expected<FunctionDecl *> InstFDOrErr =
3603 import(FromFD->getInstantiatedFromDecl()))
3604 ToFD->setInstantiatedFromDecl(*InstFDOrErr);
3605 return Error::success();
3608
3609 if (Expected<FunctionDecl *> InstFDOrErr =
3610 import(FromFD->getInstantiatedFromMemberFunction()))
3611 ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
3612 else
3613 return InstFDOrErr.takeError();
3614
3615 if (ExpectedSLoc POIOrErr = import(
3618 else
3619 return POIOrErr.takeError();
3620
3621 return Error::success();
3622 }
3623
3625 auto FunctionAndArgsOrErr =
3627 if (!FunctionAndArgsOrErr)
3628 return FunctionAndArgsOrErr.takeError();
3629
3631 Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
3632
3633 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
3634 TemplateArgumentListInfo ToTAInfo;
3635 const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
3636 if (FromTAArgsAsWritten)
3638 *FromTAArgsAsWritten, ToTAInfo))
3639 return Err;
3640
3641 ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
3642 if (!POIOrErr)
3643 return POIOrErr.takeError();
3644
3645 if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
3646 return Err;
3647
3648 TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
3649 ToFD->setFunctionTemplateSpecialization(
3650 std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr,
3651 TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
3652 return Error::success();
3653 }
3654
3656 auto *FromInfo = FromFD->getDependentSpecializationInfo();
3657 UnresolvedSet<8> Candidates;
3658 for (FunctionTemplateDecl *FTD : FromInfo->getCandidates()) {
3659 if (Expected<FunctionTemplateDecl *> ToFTDOrErr = import(FTD))
3660 Candidates.addDecl(*ToFTDOrErr);
3661 else
3662 return ToFTDOrErr.takeError();
3663 }
3664
3665 // Import TemplateArgumentListInfo.
3666 TemplateArgumentListInfo ToTAInfo;
3667 const auto *FromTAArgsAsWritten = FromInfo->TemplateArgumentsAsWritten;
3668 if (FromTAArgsAsWritten)
3669 if (Error Err =
3670 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
3671 return Err;
3672
3674 Importer.getToContext(), Candidates,
3675 FromTAArgsAsWritten ? &ToTAInfo : nullptr);
3676 return Error::success();
3677 }
3678 }
3679 llvm_unreachable("All cases should be covered!");
3680}
3681
3684 auto FunctionAndArgsOrErr =
3686 if (!FunctionAndArgsOrErr)
3687 return FunctionAndArgsOrErr.takeError();
3688
3690 TemplateArgsTy ToTemplArgs;
3691 std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
3692 void *InsertPos = nullptr;
3693 auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos);
3694 return FoundSpec;
3695}
3696
3698 FunctionDecl *ToFD) {
3699 if (Stmt *FromBody = FromFD->getBody()) {
3700 if (ExpectedStmt ToBodyOrErr = import(FromBody))
3701 ToFD->setBody(*ToBodyOrErr);
3702 else
3703 return ToBodyOrErr.takeError();
3704 }
3705 return Error::success();
3706}
3707
3708// Returns true if the given D has a DeclContext up to the TranslationUnitDecl
3709// which is equal to the given DC, or D is equal to DC.
3710static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) {
3711 const DeclContext *DCi = dyn_cast<DeclContext>(D);
3712 if (!DCi)
3713 DCi = D->getDeclContext();
3714 assert(DCi && "Declaration should have a context");
3715 while (DCi != D->getTranslationUnitDecl()) {
3716 if (DCi == DC)
3717 return true;
3718 DCi = DCi->getParent();
3719 }
3720 return false;
3721}
3722
3723// Check if there is a declaration that has 'DC' as parent context and is
3724// referenced from statement 'S' or one of its children. The search is done in
3725// BFS order through children of 'S'.
3726static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
3727 SmallVector<const Stmt *> ToProcess;
3728 ToProcess.push_back(S);
3729 while (!ToProcess.empty()) {
3730 const Stmt *CurrentS = ToProcess.pop_back_val();
3731 ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
3732 if (const auto *DeclRef = dyn_cast<DeclRefExpr>(CurrentS)) {
3733 if (const Decl *D = DeclRef->getDecl())
3734 if (isAncestorDeclContextOf(DC, D))
3735 return true;
3736 } else if (const auto *E =
3737 dyn_cast_or_null<SubstNonTypeTemplateParmExpr>(CurrentS)) {
3738 if (const Decl *D = E->getAssociatedDecl())
3739 if (isAncestorDeclContextOf(DC, D))
3740 return true;
3741 }
3742 }
3743 return false;
3744}
3745
3746namespace {
3747/// Check if a type has any reference to a declaration that is inside the body
3748/// of a function.
3749/// The \c CheckType(QualType) function should be used to determine
3750/// this property.
3751///
3752/// The type visitor visits one type object only (not recursive).
3753/// To find all referenced declarations we must discover all type objects until
3754/// the canonical type is reached (walk over typedef and similar objects). This
3755/// is done by loop over all "sugar" type objects. For every such type we must
3756/// check all declarations that are referenced from it. For this check the
3757/// visitor is used. In the visit functions all referenced declarations except
3758/// the one that follows in the sugar chain (if any) must be checked. For this
3759/// check the same visitor is re-used (it has no state-dependent data).
3760///
3761/// The visit functions have 3 possible return values:
3762/// - True, found a declaration inside \c ParentDC.
3763/// - False, found declarations only outside \c ParentDC and it is not possible
3764/// to find more declarations (the "sugar" chain does not continue).
3765/// - Empty optional value, found no declarations or only outside \c ParentDC,
3766/// but it is possible to find more declarations in the type "sugar" chain.
3767/// The loop over the "sugar" types can be implemented by using type visit
3768/// functions only (call \c CheckType with the desugared type). With the current
3769/// solution no visit function is needed if the type has only a desugared type
3770/// as data.
3771class IsTypeDeclaredInsideVisitor
3772 : public TypeVisitor<IsTypeDeclaredInsideVisitor, std::optional<bool>> {
3773public:
3774 IsTypeDeclaredInsideVisitor(const FunctionDecl *ParentDC)
3775 : ParentDC(ParentDC) {}
3776
3777 bool CheckType(QualType T) {
3778 // Check the chain of "sugar" types.
3779 // The "sugar" types are typedef or similar types that have the same
3780 // canonical type.
3781 if (std::optional<bool> Res = Visit(T.getTypePtr()))
3782 return *Res;
3783 QualType DsT =
3784 T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3785 while (DsT != T) {
3786 if (std::optional<bool> Res = Visit(DsT.getTypePtr()))
3787 return *Res;
3788 T = DsT;
3789 DsT = T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3790 }
3791 return false;
3792 }
3793
3794 std::optional<bool> VisitTagType(const TagType *T) {
3795 if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(T->getDecl()))
3796 for (const auto &Arg : Spec->getTemplateArgs().asArray())
3797 if (checkTemplateArgument(Arg))
3798 return true;
3799 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3800 }
3801
3802 std::optional<bool> VisitPointerType(const PointerType *T) {
3803 return CheckType(T->getPointeeType());
3804 }
3805
3806 std::optional<bool> VisitReferenceType(const ReferenceType *T) {
3807 return CheckType(T->getPointeeTypeAsWritten());
3808 }
3809
3810 std::optional<bool> VisitTypedefType(const TypedefType *T) {
3811 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3812 }
3813
3814 std::optional<bool> VisitUsingType(const UsingType *T) {
3815 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3816 }
3817
3818 std::optional<bool>
3819 VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
3820 for (const auto &Arg : T->template_arguments())
3821 if (checkTemplateArgument(Arg))
3822 return true;
3823 // This type is a "sugar" to a record type, it can have a desugared type.
3824 return {};
3825 }
3826
3827 std::optional<bool> VisitUnaryTransformType(const UnaryTransformType *T) {
3828 return CheckType(T->getBaseType());
3829 }
3830
3831 std::optional<bool>
3832 VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
3833 // The "associated declaration" can be the same as ParentDC.
3834 if (isAncestorDeclContextOf(ParentDC, T->getAssociatedDecl()))
3835 return true;
3836 return {};
3837 }
3838
3839 std::optional<bool> VisitConstantArrayType(const ConstantArrayType *T) {
3840 if (T->getSizeExpr() && isAncestorDeclContextOf(ParentDC, T->getSizeExpr()))
3841 return true;
3842
3843 return CheckType(T->getElementType());
3844 }
3845
3846 std::optional<bool> VisitVariableArrayType(const VariableArrayType *T) {
3847 llvm_unreachable(
3848 "Variable array should not occur in deduced return type of a function");
3849 }
3850
3851 std::optional<bool> VisitIncompleteArrayType(const IncompleteArrayType *T) {
3852 llvm_unreachable("Incomplete array should not occur in deduced return type "
3853 "of a function");
3854 }
3855
3856 std::optional<bool> VisitDependentArrayType(const IncompleteArrayType *T) {
3857 llvm_unreachable("Dependent array should not occur in deduced return type "
3858 "of a function");
3859 }
3860
3861private:
3862 const DeclContext *const ParentDC;
3863
3864 bool checkTemplateArgument(const TemplateArgument &Arg) {
3865 switch (Arg.getKind()) {
3867 return false;
3869 return CheckType(Arg.getIntegralType());
3871 return CheckType(Arg.getAsType());
3873 return isAncestorDeclContextOf(ParentDC, Arg.getAsExpr());
3875 // FIXME: The declaration in this case is not allowed to be in a function?
3876 return isAncestorDeclContextOf(ParentDC, Arg.getAsDecl());
3878 // FIXME: The type is not allowed to be in the function?
3879 return CheckType(Arg.getNullPtrType());
3881 return CheckType(Arg.getStructuralValueType());
3883 for (const auto &PackArg : Arg.getPackAsArray())
3884 if (checkTemplateArgument(PackArg))
3885 return true;
3886 return false;
3888 // Templates can not be defined locally in functions.
3889 // A template passed as argument can be not in ParentDC.
3890 return false;
3892 // Templates can not be defined locally in functions.
3893 // A template passed as argument can be not in ParentDC.
3894 return false;
3895 }
3896 llvm_unreachable("Unknown TemplateArgument::ArgKind enum");
3897 };
3898};
3899} // namespace
3900
3901/// This function checks if the given function has a return type that contains
3902/// a reference (in any way) to a declaration inside the same function.
3904 QualType FromTy = D->getType();
3905 const auto *FromFPT = FromTy->getAs<FunctionProtoType>();
3906 assert(FromFPT && "Must be called on FunctionProtoType");
3907
3908 auto IsCXX11Lambda = [&]() {
3909 if (Importer.FromContext.getLangOpts().CPlusPlus14) // C++14 or later
3910 return false;
3911
3912 return isLambdaMethod(D);
3913 };
3914
3915 QualType RetT = FromFPT->getReturnType();
3916 if (isa<AutoType>(RetT.getTypePtr()) || IsCXX11Lambda()) {
3917 FunctionDecl *Def = D->getDefinition();
3918 IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D);
3919 return Visitor.CheckType(RetT);
3920 }
3921
3922 return false;
3923}
3924
3926ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3927 Expr *ExplicitExpr = ESpec.getExpr();
3928 if (ExplicitExpr)
3929 ExplicitExpr = importChecked(Err, ESpec.getExpr());
3930 return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3931}
3932
3934
3936 auto RedeclIt = Redecls.begin();
3937 // Import the first part of the decl chain. I.e. import all previous
3938 // declarations starting from the canonical decl.
3939 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3940 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3941 if (!ToRedeclOrErr)
3942 return ToRedeclOrErr.takeError();
3943 }
3944 assert(*RedeclIt == D);
3945
3946 // Import the major distinguishing characteristics of this function.
3947 DeclContext *DC, *LexicalDC;
3948 DeclarationName Name;
3949 SourceLocation Loc;
3950 NamedDecl *ToD;
3951 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3952 return std::move(Err);
3953 if (ToD)
3954 return ToD;
3955
3956 FunctionDecl *FoundByLookup = nullptr;
3958
3959 // If this is a function template specialization, then try to find the same
3960 // existing specialization in the "to" context. The lookup below will not
3961 // find any specialization, but would find the primary template; thus, we
3962 // have to skip normal lookup in case of specializations.
3963 // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3964 if (D->getTemplatedKind() ==
3966 auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
3967 if (!FoundFunctionOrErr)
3968 return FoundFunctionOrErr.takeError();
3969 if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
3970 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3971 return Def;
3972 FoundByLookup = FoundFunction;
3973 }
3974 }
3975 // Try to find a function in our own ("to") context with the same name, same
3976 // type, and in the same context as the function we're importing.
3977 else if (!LexicalDC->isFunctionOrMethod()) {
3978 SmallVector<NamedDecl *, 4> ConflictingDecls;
3980 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3981 for (auto *FoundDecl : FoundDecls) {
3982 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3983 continue;
3984
3985 if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3986 if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
3987 continue;
3988
3989 if (IsStructuralMatch(D, FoundFunction)) {
3990 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3991 return Def;
3992 FoundByLookup = FoundFunction;
3993 break;
3994 }
3995 // FIXME: Check for overloading more carefully, e.g., by boosting
3996 // Sema::IsOverload out to the AST library.
3997
3998 // Function overloading is okay in C++.
3999 if (Importer.getToContext().getLangOpts().CPlusPlus)
4000 continue;
4001
4002 // Complain about inconsistent function types.
4003 Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
4004 << Name << D->getType() << FoundFunction->getType();
4005 Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
4006 << FoundFunction->getType();
4007 ConflictingDecls.push_back(FoundDecl);
4008 }
4009 }
4010
4011 if (!ConflictingDecls.empty()) {
4012 ExpectedName NameOrErr = Importer.HandleNameConflict(
4013 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4014 if (NameOrErr)
4015 Name = NameOrErr.get();
4016 else
4017 return NameOrErr.takeError();
4018 }
4019 }
4020
4021 // We do not allow more than one in-class declaration of a function. This is
4022 // because AST clients like VTableBuilder asserts on this. VTableBuilder
4023 // assumes there is only one in-class declaration. Building a redecl
4024 // chain would result in more than one in-class declaration for
4025 // overrides (even if they are part of the same redecl chain inside the
4026 // derived class.)
4027 if (FoundByLookup) {
4028 if (isa<CXXMethodDecl>(FoundByLookup)) {
4029 if (D->getLexicalDeclContext() == D->getDeclContext()) {
4030 if (!D->doesThisDeclarationHaveABody()) {
4031 if (FunctionTemplateDecl *DescribedD =
4033 // Handle a "templated" function together with its described
4034 // template. This avoids need for a similar check at import of the
4035 // described template.
4036 assert(FoundByLookup->getDescribedFunctionTemplate() &&
4037 "Templated function mapped to non-templated?");
4038 Importer.MapImported(DescribedD,
4039 FoundByLookup->getDescribedFunctionTemplate());
4040 }
4041 return Importer.MapImported(D, FoundByLookup);
4042 } else {
4043 // Let's continue and build up the redecl chain in this case.
4044 // FIXME Merge the functions into one decl.
4045 }
4046 }
4047 }
4048 }
4049
4050 DeclarationNameInfo NameInfo(Name, Loc);
4051 // Import additional name location/type info.
4052 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
4053 return std::move(Err);
4054
4055 QualType FromTy = D->getType();
4056 TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
4057 // Set to true if we do not import the type of the function as is. There are
4058 // cases when the original type would result in an infinite recursion during
4059 // the import. To avoid an infinite recursion when importing, we create the
4060 // FunctionDecl with a simplified function type and update it only after the
4061 // relevant AST nodes are already imported.
4062 // The type is related to TypeSourceInfo (it references the type), so we must
4063 // do the same with TypeSourceInfo.
4064 bool UsedDifferentProtoType = false;
4065 if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
4066 QualType FromReturnTy = FromFPT->getReturnType();
4067 // Functions with auto return type may define a struct inside their body
4068 // and the return type could refer to that struct.
4069 // E.g.: auto foo() { struct X{}; return X(); }
4070 // To avoid an infinite recursion when importing, create the FunctionDecl
4071 // with a simplified return type.
4072 // Reuse this approach for auto return types declared as typenames from
4073 // template params, tracked in FindFunctionDeclImportCycle.
4075 Importer.FindFunctionDeclImportCycle.isCycle(D)) {
4076 FromReturnTy = Importer.getFromContext().VoidTy;
4077 UsedDifferentProtoType = true;
4078 }
4079 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
4080 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
4081 // FunctionDecl that we are importing the FunctionProtoType for.
4082 // To avoid an infinite recursion when importing, create the FunctionDecl
4083 // with a simplified function type.
4084 if (FromEPI.ExceptionSpec.SourceDecl ||
4085 FromEPI.ExceptionSpec.SourceTemplate ||
4086 FromEPI.ExceptionSpec.NoexceptExpr) {
4088 FromEPI = DefaultEPI;
4089 UsedDifferentProtoType = true;
4090 }
4091 FromTy = Importer.getFromContext().getFunctionType(
4092 FromReturnTy, FromFPT->getParamTypes(), FromEPI);
4093 FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
4094 FromTy, D->getBeginLoc());
4095 }
4096
4097 Error Err = Error::success();
4098 auto ScopedReturnTypeDeclCycleDetector =
4099 Importer.FindFunctionDeclImportCycle.makeScopedCycleDetection(D);
4100 auto T = importChecked(Err, FromTy);
4101 auto TInfo = importChecked(Err, FromTSI);
4102 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4103 auto ToEndLoc = importChecked(Err, D->getEndLoc());
4104 auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
4105 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4106 AssociatedConstraint TrailingRequiresClause = D->getTrailingRequiresClause();
4107 TrailingRequiresClause.ConstraintExpr =
4108 importChecked(Err, TrailingRequiresClause.ConstraintExpr);
4109 if (Err)
4110 return std::move(Err);
4111
4112 // Import the function parameters.
4114 for (auto *P : D->parameters()) {
4115 if (Expected<ParmVarDecl *> ToPOrErr = import(P))
4116 Parameters.push_back(*ToPOrErr);
4117 else
4118 return ToPOrErr.takeError();
4119 }
4120
4121 // Create the imported function.
4122 FunctionDecl *ToFunction = nullptr;
4123 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4124 ExplicitSpecifier ESpec =
4125 importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
4126 if (Err)
4127 return std::move(Err);
4128 auto ToInheritedConstructor = InheritedConstructor();
4129 if (FromConstructor->isInheritingConstructor()) {
4130 Expected<InheritedConstructor> ImportedInheritedCtor =
4131 import(FromConstructor->getInheritedConstructor());
4132 if (!ImportedInheritedCtor)
4133 return ImportedInheritedCtor.takeError();
4134 ToInheritedConstructor = *ImportedInheritedCtor;
4135 }
4136 if (GetImportedOrCreateDecl<CXXConstructorDecl>(
4137 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4138 ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
4140 ToInheritedConstructor, TrailingRequiresClause))
4141 return ToFunction;
4142 } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
4143
4144 Error Err = Error::success();
4145 auto ToOperatorDelete = importChecked(
4146 Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
4147 auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
4148 if (Err)
4149 return std::move(Err);
4150
4151 if (GetImportedOrCreateDecl<CXXDestructorDecl>(
4152 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4153 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4155 TrailingRequiresClause))
4156 return ToFunction;
4157
4158 CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
4159
4160 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
4161 } else if (CXXConversionDecl *FromConversion =
4162 dyn_cast<CXXConversionDecl>(D)) {
4163 ExplicitSpecifier ESpec =
4164 importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
4165 if (Err)
4166 return std::move(Err);
4167 if (GetImportedOrCreateDecl<CXXConversionDecl>(
4168 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4169 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4170 D->isInlineSpecified(), ESpec, D->getConstexprKind(),
4171 SourceLocation(), TrailingRequiresClause))
4172 return ToFunction;
4173 } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
4174 if (GetImportedOrCreateDecl<CXXMethodDecl>(
4175 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4176 ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
4177 Method->UsesFPIntrin(), Method->isInlineSpecified(),
4178 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
4179 return ToFunction;
4180 } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
4181 ExplicitSpecifier ESpec =
4182 importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
4183 CXXConstructorDecl *Ctor =
4184 importChecked(Err, Guide->getCorrespondingConstructor());
4185 const CXXDeductionGuideDecl *SourceDG =
4186 importChecked(Err, Guide->getSourceDeductionGuide());
4187 if (Err)
4188 return std::move(Err);
4189 if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
4190 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
4191 NameInfo, T, TInfo, ToEndLoc, Ctor,
4192 Guide->getDeductionCandidateKind(), TrailingRequiresClause,
4193 SourceDG, Guide->getSourceDeductionGuideKind()))
4194 return ToFunction;
4195 } else {
4196 if (GetImportedOrCreateDecl(
4197 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
4198 NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
4200 D->getConstexprKind(), TrailingRequiresClause))
4201 return ToFunction;
4202 }
4203
4204 // Connect the redecl chain.
4205 if (FoundByLookup) {
4206 auto *Recent = const_cast<FunctionDecl *>(
4207 FoundByLookup->getMostRecentDecl());
4208 ToFunction->setPreviousDecl(Recent);
4209 // FIXME Probably we should merge exception specifications. E.g. In the
4210 // "To" context the existing function may have exception specification with
4211 // noexcept-unevaluated, while the newly imported function may have an
4212 // evaluated noexcept. A call to adjustExceptionSpec() on the imported
4213 // decl and its redeclarations may be required.
4214 }
4215
4216 StringLiteral *Msg = D->getDeletedMessage();
4217 if (Msg) {
4218 auto Imported = import(Msg);
4219 if (!Imported)
4220 return Imported.takeError();
4221 Msg = *Imported;
4222 }
4223
4224 ToFunction->setQualifierInfo(ToQualifierLoc);
4225 ToFunction->setAccess(D->getAccess());
4226 ToFunction->setLexicalDeclContext(LexicalDC);
4227 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
4228 ToFunction->setTrivial(D->isTrivial());
4229 ToFunction->setIsPureVirtual(D->isPureVirtual());
4230 ToFunction->setDefaulted(D->isDefaulted());
4232 ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
4238 ToFunction->setRangeEnd(ToEndLoc);
4239 ToFunction->setDefaultLoc(ToDefaultLoc);
4240
4241 if (Msg)
4242 ToFunction->setDefaultedOrDeletedInfo(
4244 Importer.getToContext(), {}, Msg));
4245
4246 // Set the parameters.
4247 for (auto *Param : Parameters) {
4248 Param->setOwningFunction(ToFunction);
4249 ToFunction->addDeclInternal(Param);
4250 if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
4251 LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
4252 }
4253 ToFunction->setParams(Parameters);
4254
4255 // We need to complete creation of FunctionProtoTypeLoc manually with setting
4256 // params it refers to.
4257 if (TInfo) {
4258 if (auto ProtoLoc =
4259 TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
4260 for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
4261 ProtoLoc.setParam(I, Parameters[I]);
4262 }
4263 }
4264
4265 // Import the describing template function, if any.
4266 if (FromFT) {
4267 auto ToFTOrErr = import(FromFT);
4268 if (!ToFTOrErr)
4269 return ToFTOrErr.takeError();
4270 }
4271
4272 // Import Ctor initializers.
4273 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4274 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
4275 SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
4276 // Import first, then allocate memory and copy if there was no error.
4277 if (Error Err = ImportContainerChecked(
4278 FromConstructor->inits(), CtorInitializers))
4279 return std::move(Err);
4280 auto **Memory =
4281 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4282 llvm::copy(CtorInitializers, Memory);
4283 auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
4284 ToCtor->setCtorInitializers(Memory);
4285 ToCtor->setNumCtorInitializers(NumInitializers);
4286 }
4287 }
4288
4289 // If it is a template, import all related things.
4290 if (Error Err = ImportTemplateInformation(D, ToFunction))
4291 return std::move(Err);
4292
4293 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
4295 FromCXXMethod))
4296 return std::move(Err);
4297
4299 Error Err = ImportFunctionDeclBody(D, ToFunction);
4300
4301 if (Err)
4302 return std::move(Err);
4303 }
4304
4305 // Import and set the original type in case we used another type.
4306 if (UsedDifferentProtoType) {
4307 if (ExpectedType TyOrErr = import(D->getType()))
4308 ToFunction->setType(*TyOrErr);
4309 else
4310 return TyOrErr.takeError();
4311 if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
4312 ToFunction->setTypeSourceInfo(*TSIOrErr);
4313 else
4314 return TSIOrErr.takeError();
4315 }
4316
4317 // FIXME: Other bits to merge?
4318
4319 addDeclToContexts(D, ToFunction);
4320
4321 // Import the rest of the chain. I.e. import all subsequent declarations.
4322 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4323 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4324 if (!ToRedeclOrErr)
4325 return ToRedeclOrErr.takeError();
4326 }
4327
4328 return ToFunction;
4329}
4330
4334
4338
4342
4346
4351
4353 // Import the major distinguishing characteristics of a variable.
4354 DeclContext *DC, *LexicalDC;
4355 DeclarationName Name;
4356 SourceLocation Loc;
4357 NamedDecl *ToD;
4358 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4359 return std::move(Err);
4360 if (ToD)
4361 return ToD;
4362
4363 // Determine whether we've already imported this field.
4364 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4365 for (auto *FoundDecl : FoundDecls) {
4366 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4367 // For anonymous fields, match up by index.
4368 if (!Name &&
4370 ASTImporter::getFieldIndex(FoundField))
4371 continue;
4372
4373 if (Importer.IsStructurallyEquivalent(D->getType(),
4374 FoundField->getType())) {
4375 Importer.MapImported(D, FoundField);
4376 // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4377 // initializer of a FieldDecl might not had been instantiated in the
4378 // "To" context. However, the "From" context might instantiated that,
4379 // thus we have to merge that.
4380 // Note: `hasInClassInitializer()` is not the same as non-null
4381 // `getInClassInitializer()` value.
4382 if (Expr *FromInitializer = D->getInClassInitializer()) {
4383 if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4384 // Import of the FromInitializer may result in the setting of
4385 // InClassInitializer. If not, set it here.
4386 assert(FoundField->hasInClassInitializer() &&
4387 "Field should have an in-class initializer if it has an "
4388 "expression for it.");
4389 if (!FoundField->getInClassInitializer())
4390 FoundField->setInClassInitializer(*ToInitializerOrErr);
4391 } else {
4392 return ToInitializerOrErr.takeError();
4393 }
4394 }
4395 return FoundField;
4396 }
4397
4398 // FIXME: Why is this case not handled with calling HandleNameConflict?
4399 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4400 << Name << D->getType() << FoundField->getType();
4401 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4402 << FoundField->getType();
4403
4404 return make_error<ASTImportError>(ASTImportError::NameConflict);
4405 }
4406 }
4407
4408 Error Err = Error::success();
4409 auto ToType = importChecked(Err, D->getType());
4410 auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4411 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4412 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4413 if (Err)
4414 return std::move(Err);
4415 const Type *ToCapturedVLAType = nullptr;
4416 if (Error Err = Importer.importInto(
4417 ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4418 return std::move(Err);
4419
4420 FieldDecl *ToField;
4421 if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4422 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4423 ToType, ToTInfo, ToBitWidth, D->isMutable(),
4424 D->getInClassInitStyle()))
4425 return ToField;
4426
4427 ToField->setAccess(D->getAccess());
4428 ToField->setLexicalDeclContext(LexicalDC);
4429 ToField->setImplicit(D->isImplicit());
4430 if (ToCapturedVLAType)
4431 ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4432 LexicalDC->addDeclInternal(ToField);
4433 // Import initializer only after the field was created, it may have recursive
4434 // reference to the field.
4435 auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4436 if (Err)
4437 return std::move(Err);
4438 if (ToInitializer) {
4439 auto *AlreadyImported = ToField->getInClassInitializer();
4440 if (AlreadyImported)
4441 assert(ToInitializer == AlreadyImported &&
4442 "Duplicate import of in-class initializer.");
4443 else
4444 ToField->setInClassInitializer(ToInitializer);
4445 }
4446
4447 return ToField;
4448}
4449
4451 // Import the major distinguishing characteristics of a variable.
4452 DeclContext *DC, *LexicalDC;
4453 DeclarationName Name;
4454 SourceLocation Loc;
4455 NamedDecl *ToD;
4456 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4457 return std::move(Err);
4458 if (ToD)
4459 return ToD;
4460
4461 // Determine whether we've already imported this field.
4462 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4463 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4464 if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4465 // For anonymous indirect fields, match up by index.
4466 if (!Name &&
4468 ASTImporter::getFieldIndex(FoundField))
4469 continue;
4470
4471 if (Importer.IsStructurallyEquivalent(D->getType(),
4472 FoundField->getType(),
4473 !Name.isEmpty())) {
4474 Importer.MapImported(D, FoundField);
4475 return FoundField;
4476 }
4477
4478 // If there are more anonymous fields to check, continue.
4479 if (!Name && I < N-1)
4480 continue;
4481
4482 // FIXME: Why is this case not handled with calling HandleNameConflict?
4483 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4484 << Name << D->getType() << FoundField->getType();
4485 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4486 << FoundField->getType();
4487
4488 return make_error<ASTImportError>(ASTImportError::NameConflict);
4489 }
4490 }
4491
4492 // Import the type.
4493 auto TypeOrErr = import(D->getType());
4494 if (!TypeOrErr)
4495 return TypeOrErr.takeError();
4496
4497 auto **NamedChain =
4498 new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4499
4500 unsigned i = 0;
4501 for (auto *PI : D->chain())
4502 if (Expected<NamedDecl *> ToD = import(PI))
4503 NamedChain[i++] = *ToD;
4504 else
4505 return ToD.takeError();
4506
4507 MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()};
4508 IndirectFieldDecl *ToIndirectField;
4509 if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4510 Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4511 // FIXME here we leak `NamedChain` which is allocated before
4512 return ToIndirectField;
4513
4514 ToIndirectField->setAccess(D->getAccess());
4515 ToIndirectField->setLexicalDeclContext(LexicalDC);
4516 LexicalDC->addDeclInternal(ToIndirectField);
4517 return ToIndirectField;
4518}
4519
4520/// Used as return type of getFriendCountAndPosition.
4522 /// Number of similar looking friends.
4523 unsigned int TotalCount;
4524 /// Index of the specific FriendDecl.
4525 unsigned int IndexOfDecl;
4526};
4527
4528static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4529 FriendDecl *FD2) {
4530 if ((!FD1->getFriendType()) != (!FD2->getFriendType()))
4531 return false;
4532
4533 if (const TypeSourceInfo *TSI = FD1->getFriendType())
4534 return Importer.IsStructurallyEquivalent(
4535 TSI->getType(), FD2->getFriendType()->getType(), /*Complain=*/false);
4536
4537 ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4539 Importer.getToContext().getLangOpts(), FD1->getASTContext(),
4540 FD2->getASTContext(), NonEquivalentDecls,
4542 /* StrictTypeSpelling = */ false, /* Complain = */ false);
4543 return Ctx.IsEquivalent(FD1, FD2);
4544}
4545
4547 FriendDecl *FD) {
4548 unsigned int FriendCount = 0;
4549 UnsignedOrNone FriendPosition = std::nullopt;
4550 const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4551
4552 for (FriendDecl *FoundFriend : RD->friends()) {
4553 if (FoundFriend == FD) {
4554 FriendPosition = FriendCount;
4555 ++FriendCount;
4556 } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4557 ++FriendCount;
4558 }
4559 }
4560
4561 assert(FriendPosition && "Friend decl not found in own parent.");
4562
4563 return {FriendCount, *FriendPosition};
4564}
4565
4567 // Import the major distinguishing characteristics of a declaration.
4568 DeclContext *DC, *LexicalDC;
4569 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4570 return std::move(Err);
4571
4572 // Determine whether we've already imported this decl.
4573 // FriendDecl is not a NamedDecl so we cannot use lookup.
4574 // We try to maintain order and count of redundant friend declarations.
4575 const auto *RD = cast<CXXRecordDecl>(DC);
4576 SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4577 for (FriendDecl *ImportedFriend : RD->friends())
4578 if (IsEquivalentFriend(Importer, D, ImportedFriend))
4579 ImportedEquivalentFriends.push_back(ImportedFriend);
4580
4581 FriendCountAndPosition CountAndPosition =
4582 getFriendCountAndPosition(Importer, D);
4583
4584 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4585 "Class with non-matching friends is imported, ODR check wrong?");
4586 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4587 return Importer.MapImported(
4588 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4589
4590 // Not found. Create it.
4591 // The declarations will be put into order later by ImportDeclContext.
4593 if (NamedDecl *FriendD = D->getFriendDecl()) {
4594 NamedDecl *ToFriendD;
4595 if (Error Err = importInto(ToFriendD, FriendD))
4596 return std::move(Err);
4597
4598 if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4599 !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator)))
4600 ToFriendD->setObjectOfFriendDecl(false);
4601
4602 ToFU = ToFriendD;
4603 } else { // The friend is a type, not a decl.
4604 if (auto TSIOrErr = import(D->getFriendType()))
4605 ToFU = *TSIOrErr;
4606 else
4607 return TSIOrErr.takeError();
4608 }
4609
4610 SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
4611 auto **FromTPLists = D->getTrailingObjects();
4612 for (unsigned I = 0; I < D->NumTPLists; I++) {
4613 if (auto ListOrErr = import(FromTPLists[I]))
4614 ToTPLists[I] = *ListOrErr;
4615 else
4616 return ListOrErr.takeError();
4617 }
4618
4619 auto LocationOrErr = import(D->getLocation());
4620 if (!LocationOrErr)
4621 return LocationOrErr.takeError();
4622 auto FriendLocOrErr = import(D->getFriendLoc());
4623 if (!FriendLocOrErr)
4624 return FriendLocOrErr.takeError();
4625 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4626 if (!EllipsisLocOrErr)
4627 return EllipsisLocOrErr.takeError();
4628
4629 FriendDecl *FrD;
4630 if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4631 *LocationOrErr, ToFU, *FriendLocOrErr,
4632 *EllipsisLocOrErr, ToTPLists))
4633 return FrD;
4634
4635 FrD->setAccess(D->getAccess());
4636 FrD->setLexicalDeclContext(LexicalDC);
4637 LexicalDC->addDeclInternal(FrD);
4638 return FrD;
4639}
4640
4642 // Import the major distinguishing characteristics of an ivar.
4643 DeclContext *DC, *LexicalDC;
4644 DeclarationName Name;
4645 SourceLocation Loc;
4646 NamedDecl *ToD;
4647 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4648 return std::move(Err);
4649 if (ToD)
4650 return ToD;
4651
4652 // Determine whether we've already imported this ivar
4653 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4654 for (auto *FoundDecl : FoundDecls) {
4655 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4656 if (Importer.IsStructurallyEquivalent(D->getType(),
4657 FoundIvar->getType())) {
4658 Importer.MapImported(D, FoundIvar);
4659 return FoundIvar;
4660 }
4661
4662 Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4663 << Name << D->getType() << FoundIvar->getType();
4664 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4665 << FoundIvar->getType();
4666
4667 return make_error<ASTImportError>(ASTImportError::NameConflict);
4668 }
4669 }
4670
4671 Error Err = Error::success();
4672 auto ToType = importChecked(Err, D->getType());
4673 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4674 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4675 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4676 if (Err)
4677 return std::move(Err);
4678
4679 ObjCIvarDecl *ToIvar;
4680 if (GetImportedOrCreateDecl(
4681 ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4682 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4683 ToType, ToTypeSourceInfo,
4684 D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4685 return ToIvar;
4686
4687 ToIvar->setLexicalDeclContext(LexicalDC);
4688 LexicalDC->addDeclInternal(ToIvar);
4689 return ToIvar;
4690}
4691
4693
4695 auto RedeclIt = Redecls.begin();
4696 // Import the first part of the decl chain. I.e. import all previous
4697 // declarations starting from the canonical decl.
4698 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4699 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4700 if (!RedeclOrErr)
4701 return RedeclOrErr.takeError();
4702 }
4703 assert(*RedeclIt == D);
4704
4705 // Import the major distinguishing characteristics of a variable.
4706 DeclContext *DC, *LexicalDC;
4707 DeclarationName Name;
4708 SourceLocation Loc;
4709 NamedDecl *ToD;
4710 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4711 return std::move(Err);
4712 if (ToD)
4713 return ToD;
4714
4715 // Try to find a variable in our own ("to") context with the same name and
4716 // in the same context as the variable we're importing.
4717 VarDecl *FoundByLookup = nullptr;
4718 if (D->isFileVarDecl()) {
4719 SmallVector<NamedDecl *, 4> ConflictingDecls;
4720 unsigned IDNS = Decl::IDNS_Ordinary;
4721 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4722 for (auto *FoundDecl : FoundDecls) {
4723 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4724 continue;
4725
4726 if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4727 if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4728 continue;
4729 if (Importer.IsStructurallyEquivalent(D->getType(),
4730 FoundVar->getType())) {
4731
4732 // The VarDecl in the "From" context has a definition, but in the
4733 // "To" context we already have a definition.
4734 VarDecl *FoundDef = FoundVar->getDefinition();
4735 if (D->isThisDeclarationADefinition() && FoundDef)
4736 // FIXME Check for ODR error if the two definitions have
4737 // different initializers?
4738 return Importer.MapImported(D, FoundDef);
4739
4740 // The VarDecl in the "From" context has an initializer, but in the
4741 // "To" context we already have an initializer.
4742 const VarDecl *FoundDInit = nullptr;
4743 if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4744 // FIXME Diagnose ODR error if the two initializers are different?
4745 return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4746
4747 FoundByLookup = FoundVar;
4748 break;
4749 }
4750
4751 const ArrayType *FoundArray
4752 = Importer.getToContext().getAsArrayType(FoundVar->getType());
4753 const ArrayType *TArray
4754 = Importer.getToContext().getAsArrayType(D->getType());
4755 if (FoundArray && TArray) {
4756 if (isa<IncompleteArrayType>(FoundArray) &&
4757 isa<ConstantArrayType>(TArray)) {
4758 // Import the type.
4759 if (auto TyOrErr = import(D->getType()))
4760 FoundVar->setType(*TyOrErr);
4761 else
4762 return TyOrErr.takeError();
4763
4764 FoundByLookup = FoundVar;
4765 break;
4766 } else if (isa<IncompleteArrayType>(TArray) &&
4767 isa<ConstantArrayType>(FoundArray)) {
4768 FoundByLookup = FoundVar;
4769 break;
4770 }
4771 }
4772
4773 Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4774 << Name << D->getType() << FoundVar->getType();
4775 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4776 << FoundVar->getType();
4777 ConflictingDecls.push_back(FoundDecl);
4778 }
4779 }
4780
4781 if (!ConflictingDecls.empty()) {
4782 ExpectedName NameOrErr = Importer.HandleNameConflict(
4783 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4784 if (NameOrErr)
4785 Name = NameOrErr.get();
4786 else
4787 return NameOrErr.takeError();
4788 }
4789 }
4790
4791 Error Err = Error::success();
4792 auto ToType = importChecked(Err, D->getType());
4793 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4794 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4795 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4796 if (Err)
4797 return std::move(Err);
4798
4799 VarDecl *ToVar;
4800 if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4801 SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4802 if (Error Err =
4803 ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4804 return std::move(Err);
4805 DecompositionDecl *ToDecomp;
4806 if (GetImportedOrCreateDecl(
4807 ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4808 Loc, ToType, ToTypeSourceInfo, D->getStorageClass(), Bindings))
4809 return ToDecomp;
4810 ToVar = ToDecomp;
4811 } else {
4812 // Create the imported variable.
4813 if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4814 ToInnerLocStart, Loc,
4815 Name.getAsIdentifierInfo(), ToType,
4816 ToTypeSourceInfo, D->getStorageClass()))
4817 return ToVar;
4818 }
4819
4820 ToVar->setTSCSpec(D->getTSCSpec());
4821 ToVar->setQualifierInfo(ToQualifierLoc);
4822 ToVar->setAccess(D->getAccess());
4823 ToVar->setLexicalDeclContext(LexicalDC);
4824 if (D->isInlineSpecified())
4825 ToVar->setInlineSpecified();
4826 if (D->isInline())
4827 ToVar->setImplicitlyInline();
4828
4829 if (FoundByLookup) {
4830 auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4831 ToVar->setPreviousDecl(Recent);
4832 }
4833
4834 // Import the described template, if any.
4835 if (D->getDescribedVarTemplate()) {
4836 auto ToVTOrErr = import(D->getDescribedVarTemplate());
4837 if (!ToVTOrErr)
4838 return ToVTOrErr.takeError();
4840 TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4842 if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4843 ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4844 else
4845 return ToInstOrErr.takeError();
4846 if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4848 else
4849 return POIOrErr.takeError();
4850 }
4851
4852 if (Error Err = ImportInitializer(D, ToVar))
4853 return std::move(Err);
4854
4855 if (D->isConstexpr())
4856 ToVar->setConstexpr(true);
4857
4858 addDeclToContexts(D, ToVar);
4859
4860 // Import the rest of the chain. I.e. import all subsequent declarations.
4861 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4862 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4863 if (!RedeclOrErr)
4864 return RedeclOrErr.takeError();
4865 }
4866
4867 return ToVar;
4868}
4869
4871 // Parameters are created in the translation unit's context, then moved
4872 // into the function declaration's context afterward.
4873 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4874
4875 Error Err = Error::success();
4876 auto ToDeclName = importChecked(Err, D->getDeclName());
4877 auto ToLocation = importChecked(Err, D->getLocation());
4878 auto ToType = importChecked(Err, D->getType());
4879 if (Err)
4880 return std::move(Err);
4881
4882 // Create the imported parameter.
4883 ImplicitParamDecl *ToParm = nullptr;
4884 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4885 ToLocation, ToDeclName.getAsIdentifierInfo(),
4886 ToType, D->getParameterKind()))
4887 return ToParm;
4888 return ToParm;
4889}
4890
4892 const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4893
4894 if (auto LocOrErr = import(FromParam->getExplicitObjectParamThisLoc()))
4895 ToParam->setExplicitObjectParameterLoc(*LocOrErr);
4896 else
4897 return LocOrErr.takeError();
4898
4900 ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4901
4902 if (FromParam->hasUninstantiatedDefaultArg()) {
4903 if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4904 ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4905 else
4906 return ToDefArgOrErr.takeError();
4907 } else if (FromParam->hasUnparsedDefaultArg()) {
4908 ToParam->setUnparsedDefaultArg();
4909 } else if (FromParam->hasDefaultArg()) {
4910 if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4911 ToParam->setDefaultArg(*ToDefArgOrErr);
4912 else
4913 return ToDefArgOrErr.takeError();
4914 }
4915
4916 return Error::success();
4917}
4918
4921 Error Err = Error::success();
4922 CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4923 ConstructorUsingShadowDecl *ToShadow =
4924 importChecked(Err, From.getShadowDecl());
4925 if (Err)
4926 return std::move(Err);
4927 return InheritedConstructor(ToShadow, ToBaseCtor);
4928}
4929
4931 // Parameters are created in the translation unit's context, then moved
4932 // into the function declaration's context afterward.
4933 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4934
4935 Error Err = Error::success();
4936 auto ToDeclName = importChecked(Err, D->getDeclName());
4937 auto ToLocation = importChecked(Err, D->getLocation());
4938 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4939 auto ToType = importChecked(Err, D->getType());
4940 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4941 if (Err)
4942 return std::move(Err);
4943
4944 ParmVarDecl *ToParm;
4945 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4946 ToInnerLocStart, ToLocation,
4947 ToDeclName.getAsIdentifierInfo(), ToType,
4948 ToTypeSourceInfo, D->getStorageClass(),
4949 /*DefaultArg*/ nullptr))
4950 return ToParm;
4951
4952 // Set the default argument. It should be no problem if it was already done.
4953 // Do not import the default expression before GetImportedOrCreateDecl call
4954 // to avoid possible infinite import loop because circular dependency.
4955 if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4956 return std::move(Err);
4957
4958 if (D->isObjCMethodParameter()) {
4961 } else {
4964 }
4965
4966 return ToParm;
4967}
4968
4970 // Import the major distinguishing characteristics of a method.
4971 DeclContext *DC, *LexicalDC;
4972 DeclarationName Name;
4973 SourceLocation Loc;
4974 NamedDecl *ToD;
4975 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4976 return std::move(Err);
4977 if (ToD)
4978 return ToD;
4979
4980 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4981 for (auto *FoundDecl : FoundDecls) {
4982 if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
4983 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
4984 continue;
4985
4986 // Check return types.
4987 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
4988 FoundMethod->getReturnType())) {
4989 Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
4990 << D->isInstanceMethod() << Name << D->getReturnType()
4991 << FoundMethod->getReturnType();
4992 Importer.ToDiag(FoundMethod->getLocation(),
4993 diag::note_odr_objc_method_here)
4994 << D->isInstanceMethod() << Name;
4995
4996 return make_error<ASTImportError>(ASTImportError::NameConflict);
4997 }
4998
4999 // Check the number of parameters.
5000 if (D->param_size() != FoundMethod->param_size()) {
5001 Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
5002 << D->isInstanceMethod() << Name
5003 << D->param_size() << FoundMethod->param_size();
5004 Importer.ToDiag(FoundMethod->getLocation(),
5005 diag::note_odr_objc_method_here)
5006 << D->isInstanceMethod() << Name;
5007
5008 return make_error<ASTImportError>(ASTImportError::NameConflict);
5009 }
5010
5011 // Check parameter types.
5013 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
5014 P != PEnd; ++P, ++FoundP) {
5015 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
5016 (*FoundP)->getType())) {
5017 Importer.FromDiag((*P)->getLocation(),
5018 diag::warn_odr_objc_method_param_type_inconsistent)
5019 << D->isInstanceMethod() << Name
5020 << (*P)->getType() << (*FoundP)->getType();
5021 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
5022 << (*FoundP)->getType();
5023
5024 return make_error<ASTImportError>(ASTImportError::NameConflict);
5025 }
5026 }
5027
5028 // Check variadic/non-variadic.
5029 // Check the number of parameters.
5030 if (D->isVariadic() != FoundMethod->isVariadic()) {
5031 Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
5032 << D->isInstanceMethod() << Name;
5033 Importer.ToDiag(FoundMethod->getLocation(),
5034 diag::note_odr_objc_method_here)
5035 << D->isInstanceMethod() << Name;
5036
5037 return make_error<ASTImportError>(ASTImportError::NameConflict);
5038 }
5039
5040 // FIXME: Any other bits we need to merge?
5041 return Importer.MapImported(D, FoundMethod);
5042 }
5043 }
5044
5045 Error Err = Error::success();
5046 auto ToEndLoc = importChecked(Err, D->getEndLoc());
5047 auto ToReturnType = importChecked(Err, D->getReturnType());
5048 auto ToReturnTypeSourceInfo =
5050 if (Err)
5051 return std::move(Err);
5052
5053 ObjCMethodDecl *ToMethod;
5054 if (GetImportedOrCreateDecl(
5055 ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
5056 Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
5060 return ToMethod;
5061
5062 // FIXME: When we decide to merge method definitions, we'll need to
5063 // deal with implicit parameters.
5064
5065 // Import the parameters
5067 for (auto *FromP : D->parameters()) {
5068 if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
5069 ToParams.push_back(*ToPOrErr);
5070 else
5071 return ToPOrErr.takeError();
5072 }
5073
5074 // Set the parameters.
5075 for (auto *ToParam : ToParams) {
5076 ToParam->setOwningFunction(ToMethod);
5077 ToMethod->addDeclInternal(ToParam);
5078 }
5079
5081 D->getSelectorLocs(FromSelLocs);
5082 SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
5083 if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
5084 return std::move(Err);
5085
5086 ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
5087
5088 ToMethod->setLexicalDeclContext(LexicalDC);
5089 LexicalDC->addDeclInternal(ToMethod);
5090
5091 // Implicit params are declared when Sema encounters the definition but this
5092 // never happens when the method is imported. Manually declare the implicit
5093 // params now that the MethodDecl knows its class interface.
5094 if (D->getSelfDecl())
5095 ToMethod->createImplicitParams(Importer.getToContext(),
5096 ToMethod->getClassInterface());
5097
5098 return ToMethod;
5099}
5100
5102 // Import the major distinguishing characteristics of a category.
5103 DeclContext *DC, *LexicalDC;
5104 DeclarationName Name;
5105 SourceLocation Loc;
5106 NamedDecl *ToD;
5107 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5108 return std::move(Err);
5109 if (ToD)
5110 return ToD;
5111
5112 Error Err = Error::success();
5113 auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
5114 auto ToLocation = importChecked(Err, D->getLocation());
5115 auto ToColonLoc = importChecked(Err, D->getColonLoc());
5116 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5117 if (Err)
5118 return std::move(Err);
5119
5121 if (GetImportedOrCreateDecl(
5122 Result, D, Importer.getToContext(), DC, D->getVariance(),
5123 ToVarianceLoc, D->getIndex(),
5124 ToLocation, Name.getAsIdentifierInfo(),
5125 ToColonLoc, ToTypeSourceInfo))
5126 return Result;
5127
5128 // Only import 'ObjCTypeParamType' after the decl is created.
5129 auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
5130 if (Err)
5131 return std::move(Err);
5132 Result->setTypeForDecl(ToTypeForDecl);
5133 Result->setLexicalDeclContext(LexicalDC);
5134 return Result;
5135}
5136
5138 // Import the major distinguishing characteristics of a category.
5139 DeclContext *DC, *LexicalDC;
5140 DeclarationName Name;
5141 SourceLocation Loc;
5142 NamedDecl *ToD;
5143 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5144 return std::move(Err);
5145 if (ToD)
5146 return ToD;
5147
5148 ObjCInterfaceDecl *ToInterface;
5149 if (Error Err = importInto(ToInterface, D->getClassInterface()))
5150 return std::move(Err);
5151
5152 // Determine if we've already encountered this category.
5153 ObjCCategoryDecl *MergeWithCategory
5154 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
5155 ObjCCategoryDecl *ToCategory = MergeWithCategory;
5156 if (!ToCategory) {
5157
5158 Error Err = Error::success();
5159 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5160 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5161 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5162 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5163 if (Err)
5164 return std::move(Err);
5165
5166 if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
5167 ToAtStartLoc, Loc,
5168 ToCategoryNameLoc,
5169 Name.getAsIdentifierInfo(), ToInterface,
5170 /*TypeParamList=*/nullptr,
5171 ToIvarLBraceLoc,
5172 ToIvarRBraceLoc))
5173 return ToCategory;
5174
5175 ToCategory->setLexicalDeclContext(LexicalDC);
5176 LexicalDC->addDeclInternal(ToCategory);
5177 // Import the type parameter list after MapImported, to avoid
5178 // loops when bringing in their DeclContext.
5179 if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
5180 ToCategory->setTypeParamList(*PListOrErr);
5181 else
5182 return PListOrErr.takeError();
5183
5184 // Import protocols
5186 SmallVector<SourceLocation, 4> ProtocolLocs;
5188 = D->protocol_loc_begin();
5190 FromProtoEnd = D->protocol_end();
5191 FromProto != FromProtoEnd;
5192 ++FromProto, ++FromProtoLoc) {
5193 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5194 Protocols.push_back(*ToProtoOrErr);
5195 else
5196 return ToProtoOrErr.takeError();
5197
5198 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5199 ProtocolLocs.push_back(*ToProtoLocOrErr);
5200 else
5201 return ToProtoLocOrErr.takeError();
5202 }
5203
5204 // FIXME: If we're merging, make sure that the protocol list is the same.
5205 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
5206 ProtocolLocs.data(), Importer.getToContext());
5207
5208 } else {
5209 Importer.MapImported(D, ToCategory);
5210 }
5211
5212 // Import all of the members of this category.
5213 if (Error Err = ImportDeclContext(D))
5214 return std::move(Err);
5215
5216 // If we have an implementation, import it as well.
5217 if (D->getImplementation()) {
5218 if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
5219 import(D->getImplementation()))
5220 ToCategory->setImplementation(*ToImplOrErr);
5221 else
5222 return ToImplOrErr.takeError();
5223 }
5224
5225 return ToCategory;
5226}
5227
5230 if (To->getDefinition()) {
5232 if (Error Err = ImportDeclContext(From))
5233 return Err;
5234 return Error::success();
5235 }
5236
5237 // Start the protocol definition
5238 To->startDefinition();
5239
5240 // Import protocols
5242 SmallVector<SourceLocation, 4> ProtocolLocs;
5244 From->protocol_loc_begin();
5245 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
5246 FromProtoEnd = From->protocol_end();
5247 FromProto != FromProtoEnd;
5248 ++FromProto, ++FromProtoLoc) {
5249 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5250 Protocols.push_back(*ToProtoOrErr);
5251 else
5252 return ToProtoOrErr.takeError();
5253
5254 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5255 ProtocolLocs.push_back(*ToProtoLocOrErr);
5256 else
5257 return ToProtoLocOrErr.takeError();
5258
5259 }
5260
5261 // FIXME: If we're merging, make sure that the protocol list is the same.
5262 To->setProtocolList(Protocols.data(), Protocols.size(),
5263 ProtocolLocs.data(), Importer.getToContext());
5264
5265 if (shouldForceImportDeclContext(Kind)) {
5266 // Import all of the members of this protocol.
5267 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5268 return Err;
5269 }
5270 return Error::success();
5271}
5272
5274 // If this protocol has a definition in the translation unit we're coming
5275 // from, but this particular declaration is not that definition, import the
5276 // definition and map to that.
5278 if (Definition && Definition != D) {
5279 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5280 return Importer.MapImported(D, *ImportedDefOrErr);
5281 else
5282 return ImportedDefOrErr.takeError();
5283 }
5284
5285 // Import the major distinguishing characteristics of a protocol.
5286 DeclContext *DC, *LexicalDC;
5287 DeclarationName Name;
5288 SourceLocation Loc;
5289 NamedDecl *ToD;
5290 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5291 return std::move(Err);
5292 if (ToD)
5293 return ToD;
5294
5295 ObjCProtocolDecl *MergeWithProtocol = nullptr;
5296 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5297 for (auto *FoundDecl : FoundDecls) {
5298 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol))
5299 continue;
5300
5301 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
5302 break;
5303 }
5304
5305 ObjCProtocolDecl *ToProto = MergeWithProtocol;
5306 if (!ToProto) {
5307 auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
5308 if (!ToAtBeginLocOrErr)
5309 return ToAtBeginLocOrErr.takeError();
5310
5311 if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
5312 Name.getAsIdentifierInfo(), Loc,
5313 *ToAtBeginLocOrErr,
5314 /*PrevDecl=*/nullptr))
5315 return ToProto;
5316 ToProto->setLexicalDeclContext(LexicalDC);
5317 LexicalDC->addDeclInternal(ToProto);
5318 }
5319
5320 Importer.MapImported(D, ToProto);
5321
5323 if (Error Err = ImportDefinition(D, ToProto))
5324 return std::move(Err);
5325
5326 return ToProto;
5327}
5328
5330 DeclContext *DC, *LexicalDC;
5331 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5332 return std::move(Err);
5333
5334 ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5335 if (!ExternLocOrErr)
5336 return ExternLocOrErr.takeError();
5337
5338 ExpectedSLoc LangLocOrErr = import(D->getLocation());
5339 if (!LangLocOrErr)
5340 return LangLocOrErr.takeError();
5341
5342 bool HasBraces = D->hasBraces();
5343
5344 LinkageSpecDecl *ToLinkageSpec;
5345 if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5346 *ExternLocOrErr, *LangLocOrErr,
5347 D->getLanguage(), HasBraces))
5348 return ToLinkageSpec;
5349
5350 if (HasBraces) {
5351 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5352 if (!RBraceLocOrErr)
5353 return RBraceLocOrErr.takeError();
5354 ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5355 }
5356
5357 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5358 LexicalDC->addDeclInternal(ToLinkageSpec);
5359
5360 return ToLinkageSpec;
5361}
5362
5364 BaseUsingDecl *ToSI) {
5365 for (UsingShadowDecl *FromShadow : D->shadows()) {
5366 if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5367 ToSI->addShadowDecl(*ToShadowOrErr);
5368 else
5369 // FIXME: We return error here but the definition is already created
5370 // and available with lookups. How to fix this?..
5371 return ToShadowOrErr.takeError();
5372 }
5373 return ToSI;
5374}
5375
5377 DeclContext *DC, *LexicalDC;
5378 DeclarationName Name;
5379 SourceLocation Loc;
5380 NamedDecl *ToD = nullptr;
5381 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5382 return std::move(Err);
5383 if (ToD)
5384 return ToD;
5385
5386 Error Err = Error::success();
5387 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5388 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5389 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5390 if (Err)
5391 return std::move(Err);
5392
5393 DeclarationNameInfo NameInfo(Name, ToLoc);
5394 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5395 return std::move(Err);
5396
5397 UsingDecl *ToUsing;
5398 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5399 ToUsingLoc, ToQualifierLoc, NameInfo,
5400 D->hasTypename()))
5401 return ToUsing;
5402
5403 ToUsing->setLexicalDeclContext(LexicalDC);
5404 LexicalDC->addDeclInternal(ToUsing);
5405
5406 if (NamedDecl *FromPattern =
5407 Importer.getFromContext().getInstantiatedFromUsingDecl(D)) {
5408 if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5409 Importer.getToContext().setInstantiatedFromUsingDecl(
5410 ToUsing, *ToPatternOrErr);
5411 else
5412 return ToPatternOrErr.takeError();
5413 }
5414
5415 return ImportUsingShadowDecls(D, ToUsing);
5416}
5417
5419 DeclContext *DC, *LexicalDC;
5420 DeclarationName Name;
5421 SourceLocation Loc;
5422 NamedDecl *ToD = nullptr;
5423 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5424 return std::move(Err);
5425 if (ToD)
5426 return ToD;
5427
5428 Error Err = Error::success();
5429 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5430 auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5431 auto ToNameLoc = importChecked(Err, D->getLocation());
5432 auto *ToEnumType = importChecked(Err, D->getEnumType());
5433 if (Err)
5434 return std::move(Err);
5435
5436 UsingEnumDecl *ToUsingEnum;
5437 if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5438 ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5439 return ToUsingEnum;
5440
5441 ToUsingEnum->setLexicalDeclContext(LexicalDC);
5442 LexicalDC->addDeclInternal(ToUsingEnum);
5443
5444 if (UsingEnumDecl *FromPattern =
5445 Importer.getFromContext().getInstantiatedFromUsingEnumDecl(D)) {
5446 if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5447 Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5448 *ToPatternOrErr);
5449 else
5450 return ToPatternOrErr.takeError();
5451 }
5452
5453 return ImportUsingShadowDecls(D, ToUsingEnum);
5454}
5455
5457 DeclContext *DC, *LexicalDC;
5458 DeclarationName Name;
5459 SourceLocation Loc;
5460 NamedDecl *ToD = nullptr;
5461 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5462 return std::move(Err);
5463 if (ToD)
5464 return ToD;
5465
5466 Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5467 if (!ToIntroducerOrErr)
5468 return ToIntroducerOrErr.takeError();
5469
5470 Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5471 if (!ToTargetOrErr)
5472 return ToTargetOrErr.takeError();
5473
5474 UsingShadowDecl *ToShadow;
5475 if (auto *FromConstructorUsingShadow =
5476 dyn_cast<ConstructorUsingShadowDecl>(D)) {
5477 Error Err = Error::success();
5479 Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5480 if (Err)
5481 return std::move(Err);
5482 // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5483 // is really the "NominatedBaseClassShadowDecl" value if it exists
5484 // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5485 // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5486 // get the correct values.
5487 if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5488 ToShadow, D, Importer.getToContext(), DC, Loc,
5489 cast<UsingDecl>(*ToIntroducerOrErr),
5490 Nominated ? Nominated : *ToTargetOrErr,
5491 FromConstructorUsingShadow->constructsVirtualBase()))
5492 return ToShadow;
5493 } else {
5494 if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5495 Name, *ToIntroducerOrErr, *ToTargetOrErr))
5496 return ToShadow;
5497 }
5498
5499 ToShadow->setLexicalDeclContext(LexicalDC);
5500 ToShadow->setAccess(D->getAccess());
5501
5502 if (UsingShadowDecl *FromPattern =
5503 Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) {
5504 if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5505 Importer.getToContext().setInstantiatedFromUsingShadowDecl(
5506 ToShadow, *ToPatternOrErr);
5507 else
5508 // FIXME: We return error here but the definition is already created
5509 // and available with lookups. How to fix this?..
5510 return ToPatternOrErr.takeError();
5511 }
5512
5513 LexicalDC->addDeclInternal(ToShadow);
5514
5515 return ToShadow;
5516}
5517
5519 DeclContext *DC, *LexicalDC;
5520 DeclarationName Name;
5521 SourceLocation Loc;
5522 NamedDecl *ToD = nullptr;
5523 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5524 return std::move(Err);
5525 if (ToD)
5526 return ToD;
5527
5528 auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5529 if (!ToComAncestorOrErr)
5530 return ToComAncestorOrErr.takeError();
5531
5532 Error Err = Error::success();
5533 auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5534 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5535 auto ToNamespaceKeyLocation =
5537 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5538 auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5539 if (Err)
5540 return std::move(Err);
5541
5542 UsingDirectiveDecl *ToUsingDir;
5543 if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5544 ToUsingLoc,
5545 ToNamespaceKeyLocation,
5546 ToQualifierLoc,
5547 ToIdentLocation,
5548 ToNominatedNamespace, *ToComAncestorOrErr))
5549 return ToUsingDir;
5550
5551 ToUsingDir->setLexicalDeclContext(LexicalDC);
5552 LexicalDC->addDeclInternal(ToUsingDir);
5553
5554 return ToUsingDir;
5555}
5556
5558 DeclContext *DC, *LexicalDC;
5559 DeclarationName Name;
5560 SourceLocation Loc;
5561 NamedDecl *ToD = nullptr;
5562 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5563 return std::move(Err);
5564 if (ToD)
5565 return ToD;
5566
5567 auto ToInstantiatedFromUsingOrErr =
5568 Importer.Import(D->getInstantiatedFromUsingDecl());
5569 if (!ToInstantiatedFromUsingOrErr)
5570 return ToInstantiatedFromUsingOrErr.takeError();
5571 SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5572 if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5573 return std::move(Err);
5574
5575 UsingPackDecl *ToUsingPack;
5576 if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5577 cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5578 Expansions))
5579 return ToUsingPack;
5580
5581 addDeclToContexts(D, ToUsingPack);
5582
5583 return ToUsingPack;
5584}
5585
5588 DeclContext *DC, *LexicalDC;
5589 DeclarationName Name;
5590 SourceLocation Loc;
5591 NamedDecl *ToD = nullptr;
5592 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5593 return std::move(Err);
5594 if (ToD)
5595 return ToD;
5596
5597 Error Err = Error::success();
5598 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5599 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5600 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5601 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5602 if (Err)
5603 return std::move(Err);
5604
5605 DeclarationNameInfo NameInfo(Name, ToLoc);
5606 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5607 return std::move(Err);
5608
5609 UnresolvedUsingValueDecl *ToUsingValue;
5610 if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5611 ToUsingLoc, ToQualifierLoc, NameInfo,
5612 ToEllipsisLoc))
5613 return ToUsingValue;
5614
5615 ToUsingValue->setAccess(D->getAccess());
5616 ToUsingValue->setLexicalDeclContext(LexicalDC);
5617 LexicalDC->addDeclInternal(ToUsingValue);
5618
5619 return ToUsingValue;
5620}
5621
5624 DeclContext *DC, *LexicalDC;
5625 DeclarationName Name;
5626 SourceLocation Loc;
5627 NamedDecl *ToD = nullptr;
5628 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5629 return std::move(Err);
5630 if (ToD)
5631 return ToD;
5632
5633 Error Err = Error::success();
5634 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5635 auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5636 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5637 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5638 if (Err)
5639 return std::move(Err);
5640
5642 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5643 ToUsingLoc, ToTypenameLoc,
5644 ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5645 return ToUsing;
5646
5647 ToUsing->setAccess(D->getAccess());
5648 ToUsing->setLexicalDeclContext(LexicalDC);
5649 LexicalDC->addDeclInternal(ToUsing);
5650
5651 return ToUsing;
5652}
5653
5655 Decl* ToD = nullptr;
5656 switch (D->getBuiltinTemplateKind()) {
5657#define BuiltinTemplate(BTName) \
5658 case BuiltinTemplateKind::BTK##BTName: \
5659 ToD = Importer.getToContext().get##BTName##Decl(); \
5660 break;
5661#include "clang/Basic/BuiltinTemplates.inc"
5662 }
5663 assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5664 Importer.MapImported(D, ToD);
5665 return ToD;
5666}
5667
5670 if (To->getDefinition()) {
5671 // Check consistency of superclass.
5672 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5673 if (FromSuper) {
5674 if (auto FromSuperOrErr = import(FromSuper))
5675 FromSuper = *FromSuperOrErr;
5676 else
5677 return FromSuperOrErr.takeError();
5678 }
5679
5680 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5681 if ((bool)FromSuper != (bool)ToSuper ||
5682 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5683 Importer.ToDiag(To->getLocation(),
5684 diag::warn_odr_objc_superclass_inconsistent)
5685 << To->getDeclName();
5686 if (ToSuper)
5687 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5688 << To->getSuperClass()->getDeclName();
5689 else
5690 Importer.ToDiag(To->getLocation(),
5691 diag::note_odr_objc_missing_superclass);
5692 if (From->getSuperClass())
5693 Importer.FromDiag(From->getSuperClassLoc(),
5694 diag::note_odr_objc_superclass)
5695 << From->getSuperClass()->getDeclName();
5696 else
5697 Importer.FromDiag(From->getLocation(),
5698 diag::note_odr_objc_missing_superclass);
5699 }
5700
5702 if (Error Err = ImportDeclContext(From))
5703 return Err;
5704 return Error::success();
5705 }
5706
5707 // Start the definition.
5708 To->startDefinition();
5709
5710 // If this class has a superclass, import it.
5711 if (From->getSuperClass()) {
5712 if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5713 To->setSuperClass(*SuperTInfoOrErr);
5714 else
5715 return SuperTInfoOrErr.takeError();
5716 }
5717
5718 // Import protocols
5720 SmallVector<SourceLocation, 4> ProtocolLocs;
5722 From->protocol_loc_begin();
5723
5725 FromProtoEnd = From->protocol_end();
5726 FromProto != FromProtoEnd;
5727 ++FromProto, ++FromProtoLoc) {
5728 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5729 Protocols.push_back(*ToProtoOrErr);
5730 else
5731 return ToProtoOrErr.takeError();
5732
5733 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5734 ProtocolLocs.push_back(*ToProtoLocOrErr);
5735 else
5736 return ToProtoLocOrErr.takeError();
5737
5738 }
5739
5740 // FIXME: If we're merging, make sure that the protocol list is the same.
5741 To->setProtocolList(Protocols.data(), Protocols.size(),
5742 ProtocolLocs.data(), Importer.getToContext());
5743
5744 // Import categories. When the categories themselves are imported, they'll
5745 // hook themselves into this interface.
5746 for (auto *Cat : From->known_categories()) {
5747 auto ToCatOrErr = import(Cat);
5748 if (!ToCatOrErr)
5749 return ToCatOrErr.takeError();
5750 }
5751
5752 // If we have an @implementation, import it as well.
5753 if (From->getImplementation()) {
5754 if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5755 import(From->getImplementation()))
5756 To->setImplementation(*ToImplOrErr);
5757 else
5758 return ToImplOrErr.takeError();
5759 }
5760
5761 // Import all of the members of this class.
5762 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5763 return Err;
5764
5765 return Error::success();
5766}
5767
5770 if (!list)
5771 return nullptr;
5772
5774 for (auto *fromTypeParam : *list) {
5775 if (auto toTypeParamOrErr = import(fromTypeParam))
5776 toTypeParams.push_back(*toTypeParamOrErr);
5777 else
5778 return toTypeParamOrErr.takeError();
5779 }
5780
5781 auto LAngleLocOrErr = import(list->getLAngleLoc());
5782 if (!LAngleLocOrErr)
5783 return LAngleLocOrErr.takeError();
5784
5785 auto RAngleLocOrErr = import(list->getRAngleLoc());
5786 if (!RAngleLocOrErr)
5787 return RAngleLocOrErr.takeError();
5788
5789 return ObjCTypeParamList::create(Importer.getToContext(),
5790 *LAngleLocOrErr,
5791 toTypeParams,
5792 *RAngleLocOrErr);
5793}
5794
5796 // If this class has a definition in the translation unit we're coming from,
5797 // but this particular declaration is not that definition, import the
5798 // definition and map to that.
5800 if (Definition && Definition != D) {
5801 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5802 return Importer.MapImported(D, *ImportedDefOrErr);
5803 else
5804 return ImportedDefOrErr.takeError();
5805 }
5806
5807 // Import the major distinguishing characteristics of an @interface.
5808 DeclContext *DC, *LexicalDC;
5809 DeclarationName Name;
5810 SourceLocation Loc;
5811 NamedDecl *ToD;
5812 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5813 return std::move(Err);
5814 if (ToD)
5815 return ToD;
5816
5817 // Look for an existing interface with the same name.
5818 ObjCInterfaceDecl *MergeWithIface = nullptr;
5819 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5820 for (auto *FoundDecl : FoundDecls) {
5821 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
5822 continue;
5823
5824 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5825 break;
5826 }
5827
5828 // Create an interface declaration, if one does not already exist.
5829 ObjCInterfaceDecl *ToIface = MergeWithIface;
5830 if (!ToIface) {
5831 ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5832 if (!AtBeginLocOrErr)
5833 return AtBeginLocOrErr.takeError();
5834
5835 if (GetImportedOrCreateDecl(
5836 ToIface, D, Importer.getToContext(), DC,
5837 *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5838 /*TypeParamList=*/nullptr,
5839 /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5840 return ToIface;
5841 ToIface->setLexicalDeclContext(LexicalDC);
5842 LexicalDC->addDeclInternal(ToIface);
5843 }
5844 Importer.MapImported(D, ToIface);
5845 // Import the type parameter list after MapImported, to avoid
5846 // loops when bringing in their DeclContext.
5847 if (auto ToPListOrErr =
5849 ToIface->setTypeParamList(*ToPListOrErr);
5850 else
5851 return ToPListOrErr.takeError();
5852
5854 if (Error Err = ImportDefinition(D, ToIface))
5855 return std::move(Err);
5856
5857 return ToIface;
5858}
5859
5862 ObjCCategoryDecl *Category;
5863 if (Error Err = importInto(Category, D->getCategoryDecl()))
5864 return std::move(Err);
5865
5866 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5867 if (!ToImpl) {
5868 DeclContext *DC, *LexicalDC;
5869 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5870 return std::move(Err);
5871
5872 Error Err = Error::success();
5873 auto ToLocation = importChecked(Err, D->getLocation());
5874 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5875 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5876 if (Err)
5877 return std::move(Err);
5878
5879 if (GetImportedOrCreateDecl(
5880 ToImpl, D, Importer.getToContext(), DC,
5881 Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5882 ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5883 return ToImpl;
5884
5885 ToImpl->setLexicalDeclContext(LexicalDC);
5886 LexicalDC->addDeclInternal(ToImpl);
5887 Category->setImplementation(ToImpl);
5888 }
5889
5890 Importer.MapImported(D, ToImpl);
5891 if (Error Err = ImportDeclContext(D))
5892 return std::move(Err);
5893
5894 return ToImpl;
5895}
5896
5899 // Find the corresponding interface.
5900 ObjCInterfaceDecl *Iface;
5901 if (Error Err = importInto(Iface, D->getClassInterface()))
5902 return std::move(Err);
5903
5904 // Import the superclass, if any.
5905 ObjCInterfaceDecl *Super;
5906 if (Error Err = importInto(Super, D->getSuperClass()))
5907 return std::move(Err);
5908
5910 if (!Impl) {
5911 // We haven't imported an implementation yet. Create a new @implementation
5912 // now.
5913 DeclContext *DC, *LexicalDC;
5914 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5915 return std::move(Err);
5916
5917 Error Err = Error::success();
5918 auto ToLocation = importChecked(Err, D->getLocation());
5919 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5920 auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5921 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5922 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5923 if (Err)
5924 return std::move(Err);
5925
5926 if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5927 DC, Iface, Super,
5928 ToLocation,
5929 ToAtStartLoc,
5930 ToSuperClassLoc,
5931 ToIvarLBraceLoc,
5932 ToIvarRBraceLoc))
5933 return Impl;
5934
5935 Impl->setLexicalDeclContext(LexicalDC);
5936
5937 // Associate the implementation with the class it implements.
5938 Iface->setImplementation(Impl);
5939 Importer.MapImported(D, Iface->getImplementation());
5940 } else {
5941 Importer.MapImported(D, Iface->getImplementation());
5942
5943 // Verify that the existing @implementation has the same superclass.
5944 if ((Super && !Impl->getSuperClass()) ||
5945 (!Super && Impl->getSuperClass()) ||
5946 (Super && Impl->getSuperClass() &&
5948 Impl->getSuperClass()))) {
5949 Importer.ToDiag(Impl->getLocation(),
5950 diag::warn_odr_objc_superclass_inconsistent)
5951 << Iface->getDeclName();
5952 // FIXME: It would be nice to have the location of the superclass
5953 // below.
5954 if (Impl->getSuperClass())
5955 Importer.ToDiag(Impl->getLocation(),
5956 diag::note_odr_objc_superclass)
5957 << Impl->getSuperClass()->getDeclName();
5958 else
5959 Importer.ToDiag(Impl->getLocation(),
5960 diag::note_odr_objc_missing_superclass);
5961 if (D->getSuperClass())
5962 Importer.FromDiag(D->getLocation(),
5963 diag::note_odr_objc_superclass)
5964 << D->getSuperClass()->getDeclName();
5965 else
5966 Importer.FromDiag(D->getLocation(),
5967 diag::note_odr_objc_missing_superclass);
5968
5969 return make_error<ASTImportError>(ASTImportError::NameConflict);
5970 }
5971 }
5972
5973 // Import all of the members of this @implementation.
5974 if (Error Err = ImportDeclContext(D))
5975 return std::move(Err);
5976
5977 return Impl;
5978}
5979
5981 // Import the major distinguishing characteristics of an @property.
5982 DeclContext *DC, *LexicalDC;
5983 DeclarationName Name;
5984 SourceLocation Loc;
5985 NamedDecl *ToD;
5986 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5987 return std::move(Err);
5988 if (ToD)
5989 return ToD;
5990
5991 // Check whether we have already imported this property.
5992 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5993 for (auto *FoundDecl : FoundDecls) {
5994 if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
5995 // Instance and class properties can share the same name but are different
5996 // declarations.
5997 if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
5998 continue;
5999
6000 // Check property types.
6001 if (!Importer.IsStructurallyEquivalent(D->getType(),
6002 FoundProp->getType())) {
6003 Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
6004 << Name << D->getType() << FoundProp->getType();
6005 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
6006 << FoundProp->getType();
6007
6008 return make_error<ASTImportError>(ASTImportError::NameConflict);
6009 }
6010
6011 // FIXME: Check property attributes, getters, setters, etc.?
6012
6013 // Consider these properties to be equivalent.
6014 Importer.MapImported(D, FoundProp);
6015 return FoundProp;
6016 }
6017 }
6018
6019 Error Err = Error::success();
6020 auto ToType = importChecked(Err, D->getType());
6021 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6022 auto ToAtLoc = importChecked(Err, D->getAtLoc());
6023 auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
6024 if (Err)
6025 return std::move(Err);
6026
6027 // Create the new property.
6028 ObjCPropertyDecl *ToProperty;
6029 if (GetImportedOrCreateDecl(
6030 ToProperty, D, Importer.getToContext(), DC, Loc,
6031 Name.getAsIdentifierInfo(), ToAtLoc,
6032 ToLParenLoc, ToType,
6033 ToTypeSourceInfo, D->getPropertyImplementation()))
6034 return ToProperty;
6035
6036 auto ToGetterName = importChecked(Err, D->getGetterName());
6037 auto ToSetterName = importChecked(Err, D->getSetterName());
6038 auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
6039 auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
6040 auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
6041 auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
6042 auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
6043 if (Err)
6044 return std::move(Err);
6045
6046 ToProperty->setLexicalDeclContext(LexicalDC);
6047 LexicalDC->addDeclInternal(ToProperty);
6048
6052 ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
6053 ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
6054 ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
6055 ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
6056 ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
6057 return ToProperty;
6058}
6059
6063 if (Error Err = importInto(Property, D->getPropertyDecl()))
6064 return std::move(Err);
6065
6066 DeclContext *DC, *LexicalDC;
6067 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6068 return std::move(Err);
6069
6070 auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
6071
6072 // Import the ivar (for an @synthesize).
6073 ObjCIvarDecl *Ivar = nullptr;
6074 if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
6075 return std::move(Err);
6076
6077 ObjCPropertyImplDecl *ToImpl
6078 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
6079 Property->getQueryKind());
6080 if (!ToImpl) {
6081
6082 Error Err = Error::success();
6083 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
6084 auto ToLocation = importChecked(Err, D->getLocation());
6085 auto ToPropertyIvarDeclLoc =
6087 if (Err)
6088 return std::move(Err);
6089
6090 if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
6091 ToBeginLoc,
6092 ToLocation, Property,
6093 D->getPropertyImplementation(), Ivar,
6094 ToPropertyIvarDeclLoc))
6095 return ToImpl;
6096
6097 ToImpl->setLexicalDeclContext(LexicalDC);
6098 LexicalDC->addDeclInternal(ToImpl);
6099 } else {
6100 // Check that we have the same kind of property implementation (@synthesize
6101 // vs. @dynamic).
6103 Importer.ToDiag(ToImpl->getLocation(),
6104 diag::warn_odr_objc_property_impl_kind_inconsistent)
6105 << Property->getDeclName()
6106 << (ToImpl->getPropertyImplementation()
6108 Importer.FromDiag(D->getLocation(),
6109 diag::note_odr_objc_property_impl_kind)
6110 << D->getPropertyDecl()->getDeclName()
6112
6113 return make_error<ASTImportError>(ASTImportError::NameConflict);
6114 }
6115
6116 // For @synthesize, check that we have the same
6118 Ivar != ToImpl->getPropertyIvarDecl()) {
6119 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
6120 diag::warn_odr_objc_synthesize_ivar_inconsistent)
6121 << Property->getDeclName()
6122 << ToImpl->getPropertyIvarDecl()->getDeclName()
6123 << Ivar->getDeclName();
6124 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
6125 diag::note_odr_objc_synthesize_ivar_here)
6127
6128 return make_error<ASTImportError>(ASTImportError::NameConflict);
6129 }
6130
6131 // Merge the existing implementation with the new implementation.
6132 Importer.MapImported(D, ToImpl);
6133 }
6134
6135 return ToImpl;
6136}
6137
6140 // For template arguments, we adopt the translation unit as our declaration
6141 // context. This context will be fixed when (during) the actual template
6142 // declaration is created.
6143
6144 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6145 if (!BeginLocOrErr)
6146 return BeginLocOrErr.takeError();
6147
6148 ExpectedSLoc LocationOrErr = import(D->getLocation());
6149 if (!LocationOrErr)
6150 return LocationOrErr.takeError();
6151
6152 TemplateTypeParmDecl *ToD = nullptr;
6153 if (GetImportedOrCreateDecl(
6154 ToD, D, Importer.getToContext(),
6155 Importer.getToContext().getTranslationUnitDecl(),
6156 *BeginLocOrErr, *LocationOrErr,
6157 D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
6159 D->hasTypeConstraint()))
6160 return ToD;
6161
6162 // Import the type-constraint
6163 if (const TypeConstraint *TC = D->getTypeConstraint()) {
6164
6165 Error Err = Error::success();
6166 auto ToConceptRef = importChecked(Err, TC->getConceptReference());
6167 auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
6168 if (Err)
6169 return std::move(Err);
6170
6171 ToD->setTypeConstraint(ToConceptRef, ToIDC, TC->getArgPackSubstIndex());
6172 }
6173
6174 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6175 return Err;
6176
6177 return ToD;
6178}
6179
6182
6183 Error Err = Error::success();
6184 auto ToDeclName = importChecked(Err, D->getDeclName());
6185 auto ToLocation = importChecked(Err, D->getLocation());
6186 auto ToType = importChecked(Err, D->getType());
6187 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6188 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
6189 if (Err)
6190 return std::move(Err);
6191
6192 NonTypeTemplateParmDecl *ToD = nullptr;
6193 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
6194 Importer.getToContext().getTranslationUnitDecl(),
6195 ToInnerLocStart, ToLocation, D->getDepth(),
6196 D->getPosition(),
6197 ToDeclName.getAsIdentifierInfo(), ToType,
6198 D->isParameterPack(), ToTypeSourceInfo))
6199 return ToD;
6200
6201 Err = importTemplateParameterDefaultArgument(D, ToD);
6202 if (Err)
6203 return Err;
6204
6205 return ToD;
6206}
6207
6210 bool IsCanonical = false;
6211 if (auto *CanonD = Importer.getFromContext()
6212 .findCanonicalTemplateTemplateParmDeclInternal(D);
6213 CanonD == D)
6214 IsCanonical = true;
6215
6216 // Import the name of this declaration.
6217 auto NameOrErr = import(D->getDeclName());
6218 if (!NameOrErr)
6219 return NameOrErr.takeError();
6220
6221 // Import the location of this declaration.
6222 ExpectedSLoc LocationOrErr = import(D->getLocation());
6223 if (!LocationOrErr)
6224 return LocationOrErr.takeError();
6225
6226 // Import template parameters.
6227 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6228 if (!TemplateParamsOrErr)
6229 return TemplateParamsOrErr.takeError();
6230
6231 TemplateTemplateParmDecl *ToD = nullptr;
6232 if (GetImportedOrCreateDecl(
6233 ToD, D, Importer.getToContext(),
6234 Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
6235 D->getDepth(), D->getPosition(), D->isParameterPack(),
6236 (*NameOrErr).getAsIdentifierInfo(), D->templateParameterKind(),
6237 D->wasDeclaredWithTypename(), *TemplateParamsOrErr))
6238 return ToD;
6239
6240 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6241 return Err;
6242
6243 if (IsCanonical)
6244 return Importer.getToContext()
6245 .insertCanonicalTemplateTemplateParmDeclInternal(ToD);
6246
6247 return ToD;
6248}
6249
6250// Returns the definition for a (forward) declaration of a TemplateDecl, if
6251// it has any definition in the redecl chain.
6252template <typename T> static auto getTemplateDefinition(T *D) -> T * {
6253 assert(D->getTemplatedDecl() && "Should be called on templates only");
6254 auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
6255 if (!ToTemplatedDef)
6256 return nullptr;
6257 auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
6258 return cast_or_null<T>(TemplateWithDef);
6259}
6260
6262
6263 // Import the major distinguishing characteristics of this class template.
6264 DeclContext *DC, *LexicalDC;
6265 DeclarationName Name;
6266 SourceLocation Loc;
6267 NamedDecl *ToD;
6268 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6269 return std::move(Err);
6270 if (ToD)
6271 return ToD;
6272
6273 // Should check if a declaration is friend in a dependent context.
6274 // Such templates are not linked together in a declaration chain.
6275 // The ASTImporter strategy is to map existing forward declarations to
6276 // imported ones only if strictly necessary, otherwise import these as new
6277 // forward declarations. In case of the "dependent friend" declarations, new
6278 // declarations are created, but not linked in a declaration chain.
6279 auto IsDependentFriend = [](ClassTemplateDecl *TD) {
6280 return TD->getFriendObjectKind() != Decl::FOK_None &&
6281 TD->getLexicalDeclContext()->isDependentContext();
6282 };
6283 bool DependentFriend = IsDependentFriend(D);
6284
6285 ClassTemplateDecl *FoundByLookup = nullptr;
6286
6287 // We may already have a template of the same name; try to find and match it.
6288 if (!DC->isFunctionOrMethod()) {
6289 SmallVector<NamedDecl *, 4> ConflictingDecls;
6290 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6291 for (auto *FoundDecl : FoundDecls) {
6292 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary |
6294 continue;
6295
6296 auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(FoundDecl);
6297 if (FoundTemplate) {
6298 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6299 continue;
6300
6301 // FIXME: sufficient condition for 'IgnoreTemplateParmDepth'?
6302 bool IgnoreTemplateParmDepth =
6303 (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
6305 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
6306 IgnoreTemplateParmDepth)) {
6307 if (DependentFriend || IsDependentFriend(FoundTemplate))
6308 continue;
6309
6310 ClassTemplateDecl *TemplateWithDef =
6311 getTemplateDefinition(FoundTemplate);
6312 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6313 return Importer.MapImported(D, TemplateWithDef);
6314 if (!FoundByLookup)
6315 FoundByLookup = FoundTemplate;
6316 // Search in all matches because there may be multiple decl chains,
6317 // see ASTTests test ImportExistingFriendClassTemplateDef.
6318 continue;
6319 }
6320 // When importing a friend, it is possible that multiple declarations
6321 // with same name can co-exist in specific cases (if a template contains
6322 // a friend template and has a specialization). For this case the
6323 // declarations should match, except that the "template depth" is
6324 // different. No linking of previous declaration is needed in this case.
6325 // FIXME: This condition may need refinement.
6326 if (D->getFriendObjectKind() != Decl::FOK_None &&
6327 FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
6328 D->getFriendObjectKind() != FoundTemplate->getFriendObjectKind() &&
6329 IsStructuralMatch(D, FoundTemplate, /*Complain=*/false,
6330 /*IgnoreTemplateParmDepth=*/true))
6331 continue;
6332
6333 ConflictingDecls.push_back(FoundDecl);
6334 }
6335 }
6336
6337 if (!ConflictingDecls.empty()) {
6338 ExpectedName NameOrErr = Importer.HandleNameConflict(
6339 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6340 ConflictingDecls.size());
6341 if (NameOrErr)
6342 Name = NameOrErr.get();
6343 else
6344 return NameOrErr.takeError();
6345 }
6346 }
6347
6348 CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6349
6350 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6351 if (!TemplateParamsOrErr)
6352 return TemplateParamsOrErr.takeError();
6353
6354 // Create the declaration that is being templated.
6355 CXXRecordDecl *ToTemplated;
6356 if (Error Err = importInto(ToTemplated, FromTemplated))
6357 return std::move(Err);
6358
6359 // Create the class template declaration itself.
6361 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6362 *TemplateParamsOrErr, ToTemplated))
6363 return D2;
6364
6365 ToTemplated->setDescribedClassTemplate(D2);
6366
6367 D2->setAccess(D->getAccess());
6368 D2->setLexicalDeclContext(LexicalDC);
6369
6370 addDeclToContexts(D, D2);
6371 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6372
6373 if (FoundByLookup) {
6374 auto *Recent =
6375 const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6376
6377 // It is possible that during the import of the class template definition
6378 // we start the import of a fwd friend decl of the very same class template
6379 // and we add the fwd friend decl to the lookup table. But the ToTemplated
6380 // had been created earlier and by that time the lookup could not find
6381 // anything existing, so it has no previous decl. Later, (still during the
6382 // import of the fwd friend decl) we start to import the definition again
6383 // and this time the lookup finds the previous fwd friend class template.
6384 // In this case we must set up the previous decl for the templated decl.
6385 if (!ToTemplated->getPreviousDecl()) {
6386 assert(FoundByLookup->getTemplatedDecl() &&
6387 "Found decl must have its templated decl set");
6388 CXXRecordDecl *PrevTemplated =
6389 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6390 if (ToTemplated != PrevTemplated)
6391 ToTemplated->setPreviousDecl(PrevTemplated);
6392 }
6393
6394 D2->setPreviousDecl(Recent);
6395 }
6396
6397 return D2;
6398}
6399
6402 ClassTemplateDecl *ClassTemplate;
6403 if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6404 return std::move(Err);
6405
6406 // Import the context of this declaration.
6407 DeclContext *DC, *LexicalDC;
6408 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6409 return std::move(Err);
6410
6411 // Import template arguments.
6413 if (Error Err =
6414 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6415 return std::move(Err);
6416 // Try to find an existing specialization with these template arguments and
6417 // template parameter list.
6418 void *InsertPos = nullptr;
6419 ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6421 dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6422
6423 // Import template parameters.
6424 TemplateParameterList *ToTPList = nullptr;
6425
6426 if (PartialSpec) {
6427 auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6428 if (!ToTPListOrErr)
6429 return ToTPListOrErr.takeError();
6430 ToTPList = *ToTPListOrErr;
6431 PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs,
6432 *ToTPListOrErr,
6433 InsertPos);
6434 } else
6435 PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
6436
6437 if (PrevDecl) {
6438 if (IsStructuralMatch(D, PrevDecl)) {
6439 CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6440 if (D->isThisDeclarationADefinition() && PrevDefinition) {
6441 Importer.MapImported(D, PrevDefinition);
6442 // Import those default field initializers which have been
6443 // instantiated in the "From" context, but not in the "To" context.
6444 for (auto *FromField : D->fields()) {
6445 auto ToOrErr = import(FromField);
6446 if (!ToOrErr)
6447 return ToOrErr.takeError();
6448 }
6449
6450 // Import those methods which have been instantiated in the
6451 // "From" context, but not in the "To" context.
6452 for (CXXMethodDecl *FromM : D->methods()) {
6453 auto ToOrErr = import(FromM);
6454 if (!ToOrErr)
6455 return ToOrErr.takeError();
6456 }
6457
6458 // TODO Import instantiated default arguments.
6459 // TODO Import instantiated exception specifications.
6460 //
6461 // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6462 // what else could be fused during an AST merge.
6463 return PrevDefinition;
6464 }
6465 } else { // ODR violation.
6466 // FIXME HandleNameConflict
6467 return make_error<ASTImportError>(ASTImportError::NameConflict);
6468 }
6469 }
6470
6471 // Import the location of this declaration.
6472 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6473 if (!BeginLocOrErr)
6474 return BeginLocOrErr.takeError();
6475 ExpectedSLoc IdLocOrErr = import(D->getLocation());
6476 if (!IdLocOrErr)
6477 return IdLocOrErr.takeError();
6478
6479 // Import TemplateArgumentListInfo.
6480 TemplateArgumentListInfo ToTAInfo;
6481 if (const auto *ASTTemplateArgs = D->getTemplateArgsAsWritten()) {
6482 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
6483 return std::move(Err);
6484 }
6485
6486 // Create the specialization.
6487 ClassTemplateSpecializationDecl *D2 = nullptr;
6488 if (PartialSpec) {
6489 if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6490 D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6491 *IdLocOrErr, ToTPList, ClassTemplate, ArrayRef(TemplateArgs),
6492 /*CanonInjectedTST=*/CanQualType(),
6493 cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6494 return D2;
6495
6496 // Update InsertPos, because preceding import calls may have invalidated
6497 // it by adding new specializations.
6499 if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6500 InsertPos))
6501 // Add this partial specialization to the class template.
6502 ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
6504 import(PartialSpec->getInstantiatedFromMember()))
6505 PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6506 else
6507 return ToInstOrErr.takeError();
6508
6509 updateLookupTableForTemplateParameters(*ToTPList);
6510 } else { // Not a partial specialization.
6511 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), D->getTagKind(),
6512 DC, *BeginLocOrErr, *IdLocOrErr, ClassTemplate,
6513 TemplateArgs, D->hasStrictPackMatch(),
6514 PrevDecl))
6515 return D2;
6516
6517 // Update InsertPos, because preceding import calls may have invalidated
6518 // it by adding new specializations.
6519 if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos))
6520 // Add this specialization to the class template.
6521 ClassTemplate->AddSpecialization(D2, InsertPos);
6522 }
6523
6525
6526 // Set the context of this specialization/instantiation.
6527 D2->setLexicalDeclContext(LexicalDC);
6528
6529 // Add to the DC only if it was an explicit specialization/instantiation.
6531 LexicalDC->addDeclInternal(D2);
6532 }
6533
6534 if (auto BraceRangeOrErr = import(D->getBraceRange()))
6535 D2->setBraceRange(*BraceRangeOrErr);
6536 else
6537 return BraceRangeOrErr.takeError();
6538
6539 if (Error Err = ImportTemplateParameterLists(D, D2))
6540 return std::move(Err);
6541
6542 // Import the qualifier, if any.
6543 if (auto LocOrErr = import(D->getQualifierLoc()))
6544 D2->setQualifierInfo(*LocOrErr);
6545 else
6546 return LocOrErr.takeError();
6547
6548 if (D->getTemplateArgsAsWritten())
6549 D2->setTemplateArgsAsWritten(ToTAInfo);
6550
6551 if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6552 D2->setTemplateKeywordLoc(*LocOrErr);
6553 else
6554 return LocOrErr.takeError();
6555
6556 if (auto LocOrErr = import(D->getExternKeywordLoc()))
6557 D2->setExternKeywordLoc(*LocOrErr);
6558 else
6559 return LocOrErr.takeError();
6560
6561 if (D->getPointOfInstantiation().isValid()) {
6562 if (auto POIOrErr = import(D->getPointOfInstantiation()))
6563 D2->setPointOfInstantiation(*POIOrErr);
6564 else
6565 return POIOrErr.takeError();
6566 }
6567
6569
6570 if (auto P = D->getInstantiatedFrom()) {
6571 if (auto *CTD = dyn_cast<ClassTemplateDecl *>(P)) {
6572 if (auto CTDorErr = import(CTD))
6573 D2->setInstantiationOf(*CTDorErr);
6574 } else {
6576 auto CTPSDOrErr = import(CTPSD);
6577 if (!CTPSDOrErr)
6578 return CTPSDOrErr.takeError();
6580 SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6581 for (unsigned I = 0; I < DArgs.size(); ++I) {
6582 const TemplateArgument &DArg = DArgs[I];
6583 if (auto ArgOrErr = import(DArg))
6584 D2ArgsVec[I] = *ArgOrErr;
6585 else
6586 return ArgOrErr.takeError();
6587 }
6589 *CTPSDOrErr,
6590 TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6591 }
6592 }
6593
6594 if (D->isCompleteDefinition())
6595 if (Error Err = ImportDefinition(D, D2))
6596 return std::move(Err);
6597
6598 return D2;
6599}
6600
6602 // Import the major distinguishing characteristics of this variable template.
6603 DeclContext *DC, *LexicalDC;
6604 DeclarationName Name;
6605 SourceLocation Loc;
6606 NamedDecl *ToD;
6607 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6608 return std::move(Err);
6609 if (ToD)
6610 return ToD;
6611
6612 // We may already have a template of the same name; try to find and match it.
6613 assert(!DC->isFunctionOrMethod() &&
6614 "Variable templates cannot be declared at function scope");
6615
6616 SmallVector<NamedDecl *, 4> ConflictingDecls;
6617 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6618 VarTemplateDecl *FoundByLookup = nullptr;
6619 for (auto *FoundDecl : FoundDecls) {
6620 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
6621 continue;
6622
6623 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6624 // Use the templated decl, some linkage flags are set only there.
6625 if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6626 D->getTemplatedDecl()))
6627 continue;
6628 if (IsStructuralMatch(D, FoundTemplate)) {
6629 // FIXME Check for ODR error if the two definitions have
6630 // different initializers?
6631 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6632 if (D->getDeclContext()->isRecord()) {
6633 assert(FoundTemplate->getDeclContext()->isRecord() &&
6634 "Member variable template imported as non-member, "
6635 "inconsistent imported AST?");
6636 if (FoundDef)
6637 return Importer.MapImported(D, FoundDef);
6639 return Importer.MapImported(D, FoundTemplate);
6640 } else {
6641 if (FoundDef && D->isThisDeclarationADefinition())
6642 return Importer.MapImported(D, FoundDef);
6643 }
6644 FoundByLookup = FoundTemplate;
6645 break;
6646 }
6647 ConflictingDecls.push_back(FoundDecl);
6648 }
6649 }
6650
6651 if (!ConflictingDecls.empty()) {
6652 ExpectedName NameOrErr = Importer.HandleNameConflict(
6653 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6654 ConflictingDecls.size());
6655 if (NameOrErr)
6656 Name = NameOrErr.get();
6657 else
6658 return NameOrErr.takeError();
6659 }
6660
6661 VarDecl *DTemplated = D->getTemplatedDecl();
6662
6663 // Import the type.
6664 // FIXME: Value not used?
6665 ExpectedType TypeOrErr = import(DTemplated->getType());
6666 if (!TypeOrErr)
6667 return TypeOrErr.takeError();
6668
6669 // Create the declaration that is being templated.
6670 VarDecl *ToTemplated;
6671 if (Error Err = importInto(ToTemplated, DTemplated))
6672 return std::move(Err);
6673
6674 // Create the variable template declaration itself.
6675 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6676 if (!TemplateParamsOrErr)
6677 return TemplateParamsOrErr.takeError();
6678
6679 VarTemplateDecl *ToVarTD;
6680 if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6681 Name, *TemplateParamsOrErr, ToTemplated))
6682 return ToVarTD;
6683
6684 ToTemplated->setDescribedVarTemplate(ToVarTD);
6685
6686 ToVarTD->setAccess(D->getAccess());
6687 ToVarTD->setLexicalDeclContext(LexicalDC);
6688 LexicalDC->addDeclInternal(ToVarTD);
6689 if (DC != Importer.getToContext().getTranslationUnitDecl())
6690 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6691
6692 if (FoundByLookup) {
6693 auto *Recent =
6694 const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6695 if (!ToTemplated->getPreviousDecl()) {
6696 auto *PrevTemplated =
6697 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6698 if (ToTemplated != PrevTemplated)
6699 ToTemplated->setPreviousDecl(PrevTemplated);
6700 }
6701 ToVarTD->setPreviousDecl(Recent);
6702 }
6703
6704 return ToVarTD;
6705}
6706
6709 // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6710 // in an analog way (but specialized for this case).
6711
6713 auto RedeclIt = Redecls.begin();
6714 // Import the first part of the decl chain. I.e. import all previous
6715 // declarations starting from the canonical decl.
6716 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6717 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6718 if (!RedeclOrErr)
6719 return RedeclOrErr.takeError();
6720 }
6721 assert(*RedeclIt == D);
6722
6723 VarTemplateDecl *VarTemplate = nullptr;
6725 return std::move(Err);
6726
6727 // Import the context of this declaration.
6728 DeclContext *DC, *LexicalDC;
6729 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6730 return std::move(Err);
6731
6732 // Import the location of this declaration.
6733 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6734 if (!BeginLocOrErr)
6735 return BeginLocOrErr.takeError();
6736
6737 auto IdLocOrErr = import(D->getLocation());
6738 if (!IdLocOrErr)
6739 return IdLocOrErr.takeError();
6740
6741 // Import template arguments.
6743 if (Error Err =
6744 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6745 return std::move(Err);
6746
6747 // Try to find an existing specialization with these template arguments.
6748 void *InsertPos = nullptr;
6749 VarTemplateSpecializationDecl *FoundSpecialization =
6750 VarTemplate->findSpecialization(TemplateArgs, InsertPos);
6751 if (FoundSpecialization) {
6752 if (IsStructuralMatch(D, FoundSpecialization)) {
6753 VarDecl *FoundDef = FoundSpecialization->getDefinition();
6754 if (D->getDeclContext()->isRecord()) {
6755 // In a record, it is allowed only to have one optional declaration and
6756 // one definition of the (static or constexpr) variable template.
6757 assert(
6758 FoundSpecialization->getDeclContext()->isRecord() &&
6759 "Member variable template specialization imported as non-member, "
6760 "inconsistent imported AST?");
6761 if (FoundDef)
6762 return Importer.MapImported(D, FoundDef);
6764 return Importer.MapImported(D, FoundSpecialization);
6765 } else {
6766 // If definition is imported and there is already one, map to it.
6767 // Otherwise create a new variable and link it to the existing.
6768 if (FoundDef && D->isThisDeclarationADefinition())
6769 return Importer.MapImported(D, FoundDef);
6770 }
6771 } else {
6772 return make_error<ASTImportError>(ASTImportError::NameConflict);
6773 }
6774 }
6775
6776 VarTemplateSpecializationDecl *D2 = nullptr;
6777
6778 TemplateArgumentListInfo ToTAInfo;
6779 if (const auto *Args = D->getTemplateArgsAsWritten()) {
6780 if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6781 return std::move(Err);
6782 }
6783
6784 using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6785 // Create a new specialization.
6786 if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6787 auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6788 if (!ToTPListOrErr)
6789 return ToTPListOrErr.takeError();
6790
6791 PartVarSpecDecl *ToPartial;
6792 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6793 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6794 VarTemplate, QualType(), nullptr,
6795 D->getStorageClass(), TemplateArgs))
6796 return ToPartial;
6797
6798 if (Expected<PartVarSpecDecl *> ToInstOrErr =
6799 import(FromPartial->getInstantiatedFromMember()))
6800 ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6801 else
6802 return ToInstOrErr.takeError();
6803
6804 if (FromPartial->isMemberSpecialization())
6805 ToPartial->setMemberSpecialization();
6806
6807 D2 = ToPartial;
6808
6809 // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6810 // to adopt template parameters.
6811 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6812 } else { // Full specialization
6813 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6814 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6815 QualType(), nullptr, D->getStorageClass(),
6816 TemplateArgs))
6817 return D2;
6818 }
6819
6820 // Update InsertPos, because preceding import calls may have invalidated
6821 // it by adding new specializations.
6822 if (!VarTemplate->findSpecialization(TemplateArgs, InsertPos))
6823 VarTemplate->AddSpecialization(D2, InsertPos);
6824
6825 QualType T;
6826 if (Error Err = importInto(T, D->getType()))
6827 return std::move(Err);
6828 D2->setType(T);
6829
6830 auto TInfoOrErr = import(D->getTypeSourceInfo());
6831 if (!TInfoOrErr)
6832 return TInfoOrErr.takeError();
6833 D2->setTypeSourceInfo(*TInfoOrErr);
6834
6835 if (D->getPointOfInstantiation().isValid()) {
6836 if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6837 D2->setPointOfInstantiation(*POIOrErr);
6838 else
6839 return POIOrErr.takeError();
6840 }
6841
6843
6844 if (D->getTemplateArgsAsWritten())
6845 D2->setTemplateArgsAsWritten(ToTAInfo);
6846
6847 if (auto LocOrErr = import(D->getQualifierLoc()))
6848 D2->setQualifierInfo(*LocOrErr);
6849 else
6850 return LocOrErr.takeError();
6851
6852 if (D->isConstexpr())
6853 D2->setConstexpr(true);
6854
6855 D2->setAccess(D->getAccess());
6856
6857 if (Error Err = ImportInitializer(D, D2))
6858 return std::move(Err);
6859
6860 if (FoundSpecialization)
6861 D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6862
6863 addDeclToContexts(D, D2);
6864
6865 // Import the rest of the chain. I.e. import all subsequent declarations.
6866 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6867 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6868 if (!RedeclOrErr)
6869 return RedeclOrErr.takeError();
6870 }
6871
6872 return D2;
6873}
6874
6877 DeclContext *DC, *LexicalDC;
6878 DeclarationName Name;
6879 SourceLocation Loc;
6880 NamedDecl *ToD;
6881
6882 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6883 return std::move(Err);
6884
6885 if (ToD)
6886 return ToD;
6887
6888 const FunctionTemplateDecl *FoundByLookup = nullptr;
6889
6890 // Try to find a function in our own ("to") context with the same name, same
6891 // type, and in the same context as the function we're importing.
6892 // FIXME Split this into a separate function.
6893 if (!LexicalDC->isFunctionOrMethod()) {
6895 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6896 for (auto *FoundDecl : FoundDecls) {
6897 if (!FoundDecl->isInIdentifierNamespace(IDNS))
6898 continue;
6899
6900 if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6901 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6902 continue;
6903 if (IsStructuralMatch(D, FoundTemplate)) {
6904 FunctionTemplateDecl *TemplateWithDef =
6905 getTemplateDefinition(FoundTemplate);
6906 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6907 return Importer.MapImported(D, TemplateWithDef);
6908
6909 FoundByLookup = FoundTemplate;
6910 break;
6911 // TODO: handle conflicting names
6912 }
6913 }
6914 }
6915 }
6916
6917 auto ParamsOrErr = import(D->getTemplateParameters());
6918 if (!ParamsOrErr)
6919 return ParamsOrErr.takeError();
6920 TemplateParameterList *Params = *ParamsOrErr;
6921
6922 FunctionDecl *TemplatedFD;
6923 if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6924 return std::move(Err);
6925
6926 // At creation of the template the template parameters are "adopted"
6927 // (DeclContext is changed). After this possible change the lookup table
6928 // must be updated.
6929 // At deduction guides the DeclContext of the template parameters may be
6930 // different from what we would expect, it may be the class template, or a
6931 // probably different CXXDeductionGuideDecl. This may come from the fact that
6932 // the template parameter objects may be shared between deduction guides or
6933 // the class template, and at creation of multiple FunctionTemplateDecl
6934 // objects (for deduction guides) the same parameters are re-used. The
6935 // "adoption" happens multiple times with different parent, even recursively
6936 // for TemplateTemplateParmDecl. The same happens at import when the
6937 // FunctionTemplateDecl objects are created, but in different order.
6938 // In this way the DeclContext of these template parameters is not necessarily
6939 // the same as in the "from" context.
6941 OldParamDC.reserve(Params->size());
6942 llvm::transform(*Params, std::back_inserter(OldParamDC),
6943 [](NamedDecl *ND) { return ND->getDeclContext(); });
6944
6945 FunctionTemplateDecl *ToFunc;
6946 if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6947 Params, TemplatedFD))
6948 return ToFunc;
6949
6950 // Fail if TemplatedFD is already part of a template.
6951 // The template should have been found by structural equivalence check before,
6952 // or ToFunc should be already imported.
6953 // If not, there is AST incompatibility that can be caused by previous import
6954 // errors. (NameConflict is not exact here.)
6955 if (TemplatedFD->getDescribedTemplate())
6956 return make_error<ASTImportError>(ASTImportError::NameConflict);
6957
6958 TemplatedFD->setDescribedFunctionTemplate(ToFunc);
6959
6960 ToFunc->setAccess(D->getAccess());
6961 ToFunc->setLexicalDeclContext(LexicalDC);
6962 addDeclToContexts(D, ToFunc);
6963
6964 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
6965 if (LT && !OldParamDC.empty()) {
6966 for (unsigned int I = 0; I < OldParamDC.size(); ++I)
6967 LT->updateForced(Params->getParam(I), OldParamDC[I]);
6968 }
6969
6970 if (FoundByLookup) {
6971 auto *Recent =
6972 const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6973 if (!TemplatedFD->getPreviousDecl()) {
6974 assert(FoundByLookup->getTemplatedDecl() &&
6975 "Found decl must have its templated decl set");
6976 auto *PrevTemplated =
6977 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6978 if (TemplatedFD != PrevTemplated)
6979 TemplatedFD->setPreviousDecl(PrevTemplated);
6980 }
6981 ToFunc->setPreviousDecl(Recent);
6982 }
6983
6984 return ToFunc;
6985}
6986
6988 DeclContext *DC, *LexicalDC;
6989 Error Err = ImportDeclContext(D, DC, LexicalDC);
6990 auto LocationOrErr = importChecked(Err, D->getLocation());
6991 auto NameDeclOrErr = importChecked(Err, D->getDeclName());
6992 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
6993 auto ConstraintExpr = importChecked(Err, D->getConstraintExpr());
6994 if (Err)
6995 return std::move(Err);
6996
6997 ConceptDecl *To;
6998 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, LocationOrErr,
6999 NameDeclOrErr, ToTemplateParameters,
7000 ConstraintExpr))
7001 return To;
7002 To->setLexicalDeclContext(LexicalDC);
7003 LexicalDC->addDeclInternal(To);
7004 return To;
7005}
7006
7009 DeclContext *DC, *LexicalDC;
7010 Error Err = ImportDeclContext(D, DC, LexicalDC);
7011 auto RequiresLoc = importChecked(Err, D->getLocation());
7012 if (Err)
7013 return std::move(Err);
7014
7016 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, RequiresLoc))
7017 return To;
7018 To->setLexicalDeclContext(LexicalDC);
7019 LexicalDC->addDeclInternal(To);
7020 return To;
7021}
7022
7025 DeclContext *DC, *LexicalDC;
7026 Error Err = ImportDeclContext(D, DC, LexicalDC);
7027 auto ToSL = importChecked(Err, D->getLocation());
7028 if (Err)
7029 return std::move(Err);
7030
7032 if (Error Err = ImportTemplateArguments(D->getTemplateArguments(), ToArgs))
7033 return std::move(Err);
7034
7036 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, ToSL, ToArgs))
7037 return To;
7038 To->setLexicalDeclContext(LexicalDC);
7039 LexicalDC->addDeclInternal(To);
7040 return To;
7041}
7042
7043//----------------------------------------------------------------------------
7044// Import Statements
7045//----------------------------------------------------------------------------
7046
7048 Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
7049 << S->getStmtClassName();
7050 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7051}
7052
7053
7055 if (Importer.returnWithErrorInTest())
7056 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7058 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7059 IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
7060 // ToII is nullptr when no symbolic name is given for output operand
7061 // see ParseStmtAsm::ParseAsmOperandsOpt
7062 Names.push_back(ToII);
7063 }
7064
7065 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7066 IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
7067 // ToII is nullptr when no symbolic name is given for input operand
7068 // see ParseStmtAsm::ParseAsmOperandsOpt
7069 Names.push_back(ToII);
7070 }
7071
7072 SmallVector<Expr *, 4> Clobbers;
7073 for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
7074 if (auto ClobberOrErr = import(S->getClobberExpr(I)))
7075 Clobbers.push_back(*ClobberOrErr);
7076 else
7077 return ClobberOrErr.takeError();
7078
7079 }
7080
7081 SmallVector<Expr *, 4> Constraints;
7082 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7083 if (auto OutputOrErr = import(S->getOutputConstraintExpr(I)))
7084 Constraints.push_back(*OutputOrErr);
7085 else
7086 return OutputOrErr.takeError();
7087 }
7088
7089 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7090 if (auto InputOrErr = import(S->getInputConstraintExpr(I)))
7091 Constraints.push_back(*InputOrErr);
7092 else
7093 return InputOrErr.takeError();
7094 }
7095
7097 S->getNumLabels());
7098 if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
7099 return std::move(Err);
7100
7101 if (Error Err =
7102 ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
7103 return std::move(Err);
7104
7105 if (Error Err = ImportArrayChecked(
7106 S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs()))
7107 return std::move(Err);
7108
7109 ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
7110 if (!AsmLocOrErr)
7111 return AsmLocOrErr.takeError();
7112 auto AsmStrOrErr = import(S->getAsmStringExpr());
7113 if (!AsmStrOrErr)
7114 return AsmStrOrErr.takeError();
7115 ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
7116 if (!RParenLocOrErr)
7117 return RParenLocOrErr.takeError();
7118
7119 return new (Importer.getToContext()) GCCAsmStmt(
7120 Importer.getToContext(),
7121 *AsmLocOrErr,
7122 S->isSimple(),
7123 S->isVolatile(),
7124 S->getNumOutputs(),
7125 S->getNumInputs(),
7126 Names.data(),
7127 Constraints.data(),
7128 Exprs.data(),
7129 *AsmStrOrErr,
7130 S->getNumClobbers(),
7131 Clobbers.data(),
7132 S->getNumLabels(),
7133 *RParenLocOrErr);
7134}
7135
7137
7138 Error Err = Error::success();
7139 auto ToDG = importChecked(Err, S->getDeclGroup());
7140 auto ToBeginLoc = importChecked(Err, S->getBeginLoc());
7141 auto ToEndLoc = importChecked(Err, S->getEndLoc());
7142 if (Err)
7143 return std::move(Err);
7144 return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
7145}
7146
7148 ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
7149 if (!ToSemiLocOrErr)
7150 return ToSemiLocOrErr.takeError();
7151 return new (Importer.getToContext()) NullStmt(
7152 *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
7153}
7154
7156 SmallVector<Stmt *, 8> ToStmts(S->size());
7157
7158 if (Error Err = ImportContainerChecked(S->body(), ToStmts))
7159 return std::move(Err);
7160
7161 ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
7162 if (!ToLBracLocOrErr)
7163 return ToLBracLocOrErr.takeError();
7164
7165 ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
7166 if (!ToRBracLocOrErr)
7167 return ToRBracLocOrErr.takeError();
7168
7169 FPOptionsOverride FPO =
7171 return CompoundStmt::Create(Importer.getToContext(), ToStmts, FPO,
7172 *ToLBracLocOrErr, *ToRBracLocOrErr);
7173}
7174
7176
7177 Error Err = Error::success();
7178 auto ToLHS = importChecked(Err, S->getLHS());
7179 auto ToRHS = importChecked(Err, S->getRHS());
7180 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7181 auto ToCaseLoc = importChecked(Err, S->getCaseLoc());
7182 auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc());
7183 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7184 if (Err)
7185 return std::move(Err);
7186
7187 auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
7188 ToCaseLoc, ToEllipsisLoc, ToColonLoc);
7189 ToStmt->setSubStmt(ToSubStmt);
7190
7191 return ToStmt;
7192}
7193
7195
7196 Error Err = Error::success();
7197 auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc());
7198 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7199 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7200 if (Err)
7201 return std::move(Err);
7202
7203 return new (Importer.getToContext()) DefaultStmt(
7204 ToDefaultLoc, ToColonLoc, ToSubStmt);
7205}
7206
7208
7209 Error Err = Error::success();
7210 auto ToIdentLoc = importChecked(Err, S->getIdentLoc());
7211 auto ToLabelDecl = importChecked(Err, S->getDecl());
7212 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7213 if (Err)
7214 return std::move(Err);
7215
7216 return new (Importer.getToContext()) LabelStmt(
7217 ToIdentLoc, ToLabelDecl, ToSubStmt);
7218}
7219
7221 ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
7222 if (!ToAttrLocOrErr)
7223 return ToAttrLocOrErr.takeError();
7224 ArrayRef<const Attr*> FromAttrs(S->getAttrs());
7225 SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
7226 if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
7227 return std::move(Err);
7228 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7229 if (!ToSubStmtOrErr)
7230 return ToSubStmtOrErr.takeError();
7231
7233 Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
7234}
7235
7237
7238 Error Err = Error::success();
7239 auto ToIfLoc = importChecked(Err, S->getIfLoc());
7240 auto ToInit = importChecked(Err, S->getInit());
7241 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7242 auto ToCond = importChecked(Err, S->getCond());
7243 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7244 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7245 auto ToThen = importChecked(Err, S->getThen());
7246 auto ToElseLoc = importChecked(Err, S->getElseLoc());
7247 auto ToElse = importChecked(Err, S->getElse());
7248 if (Err)
7249 return std::move(Err);
7250
7251 return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(),
7252 ToInit, ToConditionVariable, ToCond, ToLParenLoc,
7253 ToRParenLoc, ToThen, ToElseLoc, ToElse);
7254}
7255
7257
7258 Error Err = Error::success();
7259 auto ToInit = importChecked(Err, S->getInit());
7260 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7261 auto ToCond = importChecked(Err, S->getCond());
7262 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7263 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7264 auto ToBody = importChecked(Err, S->getBody());
7265 auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
7266 if (Err)
7267 return std::move(Err);
7268
7269 auto *ToStmt =
7270 SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
7271 ToCond, ToLParenLoc, ToRParenLoc);
7272 ToStmt->setBody(ToBody);
7273 ToStmt->setSwitchLoc(ToSwitchLoc);
7274
7275 // Now we have to re-chain the cases.
7276 SwitchCase *LastChainedSwitchCase = nullptr;
7277 for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
7278 SC = SC->getNextSwitchCase()) {
7279 Expected<SwitchCase *> ToSCOrErr = import(SC);
7280 if (!ToSCOrErr)
7281 return ToSCOrErr.takeError();
7282 if (LastChainedSwitchCase)
7283 LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
7284 else
7285 ToStmt->setSwitchCaseList(*ToSCOrErr);
7286 LastChainedSwitchCase = *ToSCOrErr;
7287 }
7288
7289 return ToStmt;
7290}
7291
7293
7294 Error Err = Error::success();
7295 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7296 auto ToCond = importChecked(Err, S->getCond());
7297 auto ToBody = importChecked(Err, S->getBody());
7298 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7299 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7300 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7301 if (Err)
7302 return std::move(Err);
7303
7304 return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
7305 ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc);
7306}
7307
7309
7310 Error Err = Error::success();
7311 auto ToBody = importChecked(Err, S->getBody());
7312 auto ToCond = importChecked(Err, S->getCond());
7313 auto ToDoLoc = importChecked(Err, S->getDoLoc());
7314 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7315 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7316 if (Err)
7317 return std::move(Err);
7318
7319 return new (Importer.getToContext()) DoStmt(
7320 ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
7321}
7322
7324
7325 Error Err = Error::success();
7326 auto ToInit = importChecked(Err, S->getInit());
7327 auto ToCond = importChecked(Err, S->getCond());
7328 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7329 auto ToInc = importChecked(Err, S->getInc());
7330 auto ToBody = importChecked(Err, S->getBody());
7331 auto ToForLoc = importChecked(Err, S->getForLoc());
7332 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7333 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7334 if (Err)
7335 return std::move(Err);
7336
7337 return new (Importer.getToContext()) ForStmt(
7338 Importer.getToContext(),
7339 ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
7340 ToRParenLoc);
7341}
7342
7344
7345 Error Err = Error::success();
7346 auto ToLabel = importChecked(Err, S->getLabel());
7347 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7348 auto ToLabelLoc = importChecked(Err, S->getLabelLoc());
7349 if (Err)
7350 return std::move(Err);
7351
7352 return new (Importer.getToContext()) GotoStmt(
7353 ToLabel, ToGotoLoc, ToLabelLoc);
7354}
7355
7357
7358 Error Err = Error::success();
7359 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7360 auto ToStarLoc = importChecked(Err, S->getStarLoc());
7361 auto ToTarget = importChecked(Err, S->getTarget());
7362 if (Err)
7363 return std::move(Err);
7364
7365 return new (Importer.getToContext()) IndirectGotoStmt(
7366 ToGotoLoc, ToStarLoc, ToTarget);
7367}
7368
7369template <typename StmtClass>
7371 ASTImporter &Importer, StmtClass *S) {
7372 Error Err = Error::success();
7373 auto ToLoc = NodeImporter.importChecked(Err, S->getKwLoc());
7374 auto ToLabelLoc = S->hasLabelTarget()
7375 ? NodeImporter.importChecked(Err, S->getLabelLoc())
7376 : SourceLocation();
7377 auto ToDecl = S->hasLabelTarget()
7378 ? NodeImporter.importChecked(Err, S->getLabelDecl())
7379 : nullptr;
7380 if (Err)
7381 return std::move(Err);
7382 return new (Importer.getToContext()) StmtClass(ToLoc, ToLabelLoc, ToDecl);
7383}
7384
7388
7392
7394
7395 Error Err = Error::success();
7396 auto ToReturnLoc = importChecked(Err, S->getReturnLoc());
7397 auto ToRetValue = importChecked(Err, S->getRetValue());
7398 auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate());
7399 if (Err)
7400 return std::move(Err);
7401
7402 return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
7403 ToNRVOCandidate);
7404}
7405
7407
7408 Error Err = Error::success();
7409 auto ToCatchLoc = importChecked(Err, S->getCatchLoc());
7410 auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl());
7411 auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock());
7412 if (Err)
7413 return std::move(Err);
7414
7415 return new (Importer.getToContext()) CXXCatchStmt (
7416 ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
7417}
7418
7420 ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
7421 if (!ToTryLocOrErr)
7422 return ToTryLocOrErr.takeError();
7423
7424 ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
7425 if (!ToTryBlockOrErr)
7426 return ToTryBlockOrErr.takeError();
7427
7428 SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
7429 for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
7430 CXXCatchStmt *FromHandler = S->getHandler(HI);
7431 if (auto ToHandlerOrErr = import(FromHandler))
7432 ToHandlers[HI] = *ToHandlerOrErr;
7433 else
7434 return ToHandlerOrErr.takeError();
7435 }
7436
7437 return CXXTryStmt::Create(Importer.getToContext(), *ToTryLocOrErr,
7438 cast<CompoundStmt>(*ToTryBlockOrErr), ToHandlers);
7439}
7440
7442
7443 Error Err = Error::success();
7444 auto ToInit = importChecked(Err, S->getInit());
7445 auto ToRangeStmt = importChecked(Err, S->getRangeStmt());
7446 auto ToBeginStmt = importChecked(Err, S->getBeginStmt());
7447 auto ToEndStmt = importChecked(Err, S->getEndStmt());
7448 auto ToCond = importChecked(Err, S->getCond());
7449 auto ToInc = importChecked(Err, S->getInc());
7450 auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt());
7451 auto ToBody = importChecked(Err, S->getBody());
7452 auto ToForLoc = importChecked(Err, S->getForLoc());
7453 auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc());
7454 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7455 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7456 if (Err)
7457 return std::move(Err);
7458
7459 return new (Importer.getToContext()) CXXForRangeStmt(
7460 ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
7461 ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
7462}
7463
7466 Error Err = Error::success();
7467 auto ToElement = importChecked(Err, S->getElement());
7468 auto ToCollection = importChecked(Err, S->getCollection());
7469 auto ToBody = importChecked(Err, S->getBody());
7470 auto ToForLoc = importChecked(Err, S->getForLoc());
7471 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7472 if (Err)
7473 return std::move(Err);
7474
7475 return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
7476 ToCollection,
7477 ToBody,
7478 ToForLoc,
7479 ToRParenLoc);
7480}
7481
7483
7484 Error Err = Error::success();
7485 auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc());
7486 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7487 auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl());
7488 auto ToCatchBody = importChecked(Err, S->getCatchBody());
7489 if (Err)
7490 return std::move(Err);
7491
7492 return new (Importer.getToContext()) ObjCAtCatchStmt (
7493 ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
7494}
7495
7497 ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
7498 if (!ToAtFinallyLocOrErr)
7499 return ToAtFinallyLocOrErr.takeError();
7500 ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
7501 if (!ToAtFinallyStmtOrErr)
7502 return ToAtFinallyStmtOrErr.takeError();
7503 return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
7504 *ToAtFinallyStmtOrErr);
7505}
7506
7508
7509 Error Err = Error::success();
7510 auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc());
7511 auto ToTryBody = importChecked(Err, S->getTryBody());
7512 auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt());
7513 if (Err)
7514 return std::move(Err);
7515
7516 SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
7517 for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
7518 ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
7519 if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
7520 ToCatchStmts[CI] = *ToCatchStmtOrErr;
7521 else
7522 return ToCatchStmtOrErr.takeError();
7523 }
7524
7525 return ObjCAtTryStmt::Create(Importer.getToContext(),
7526 ToAtTryLoc, ToTryBody,
7527 ToCatchStmts.begin(), ToCatchStmts.size(),
7528 ToFinallyStmt);
7529}
7530
7533
7534 Error Err = Error::success();
7535 auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc());
7536 auto ToSynchExpr = importChecked(Err, S->getSynchExpr());
7537 auto ToSynchBody = importChecked(Err, S->getSynchBody());
7538 if (Err)
7539 return std::move(Err);
7540
7541 return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
7542 ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
7543}
7544
7546 ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
7547 if (!ToThrowLocOrErr)
7548 return ToThrowLocOrErr.takeError();
7549 ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
7550 if (!ToThrowExprOrErr)
7551 return ToThrowExprOrErr.takeError();
7552 return new (Importer.getToContext()) ObjCAtThrowStmt(
7553 *ToThrowLocOrErr, *ToThrowExprOrErr);
7554}
7555
7558 ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
7559 if (!ToAtLocOrErr)
7560 return ToAtLocOrErr.takeError();
7561 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7562 if (!ToSubStmtOrErr)
7563 return ToSubStmtOrErr.takeError();
7564 return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
7565 *ToSubStmtOrErr);
7566}
7567
7568//----------------------------------------------------------------------------
7569// Import Expressions
7570//----------------------------------------------------------------------------
7572 Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
7573 << E->getStmtClassName();
7574 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7575}
7576
7578 Error Err = Error::success();
7579 auto ToType = importChecked(Err, E->getType());
7580 auto BLoc = importChecked(Err, E->getBeginLoc());
7581 auto RParenLoc = importChecked(Err, E->getEndLoc());
7582 if (Err)
7583 return std::move(Err);
7584 auto ParentContextOrErr = Importer.ImportContext(E->getParentContext());
7585 if (!ParentContextOrErr)
7586 return ParentContextOrErr.takeError();
7587
7588 return new (Importer.getToContext())
7589 SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc,
7590 RParenLoc, *ParentContextOrErr);
7591}
7592
7594
7595 Error Err = Error::success();
7596 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7597 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7598 auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo());
7599 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7600 auto ToType = importChecked(Err, E->getType());
7601 if (Err)
7602 return std::move(Err);
7603
7604 return new (Importer.getToContext()) VAArgExpr(
7605 ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
7606 E->isMicrosoftABI());
7607}
7608
7610
7611 Error Err = Error::success();
7612 auto ToCond = importChecked(Err, E->getCond());
7613 auto ToLHS = importChecked(Err, E->getLHS());
7614 auto ToRHS = importChecked(Err, E->getRHS());
7615 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7616 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7617 auto ToType = importChecked(Err, E->getType());
7618 if (Err)
7619 return std::move(Err);
7620
7622 ExprObjectKind OK = E->getObjectKind();
7623
7624 // The value of CondIsTrue only matters if the value is not
7625 // condition-dependent.
7626 bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
7627
7628 return new (Importer.getToContext())
7629 ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
7630 ToRParenLoc, CondIsTrue);
7631}
7632
7634 Error Err = Error::success();
7635 auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
7636 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7637 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7638 auto ToType = importChecked(Err, E->getType());
7639 auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
7640 if (Err)
7641 return std::move(Err);
7642
7644 Importer.getToContext(), ToSrcExpr, ToTSI, ToType, E->getValueKind(),
7645 E->getObjectKind(), ToBuiltinLoc, ToRParenLoc,
7647}
7648
7650 Error Err = Error::success();
7651 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7652 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7653 auto ToType = importChecked(Err, E->getType());
7654 const unsigned NumSubExprs = E->getNumSubExprs();
7655
7657 ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
7658 ToSubExprs.resize(NumSubExprs);
7659
7660 if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
7661 return std::move(Err);
7662
7663 return new (Importer.getToContext()) ShuffleVectorExpr(
7664 Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
7665}
7666
7668 ExpectedType TypeOrErr = import(E->getType());
7669 if (!TypeOrErr)
7670 return TypeOrErr.takeError();
7671
7672 ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
7673 if (!BeginLocOrErr)
7674 return BeginLocOrErr.takeError();
7675
7676 return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
7677}
7678
7681 Error Err = Error::success();
7682 auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
7683 Expr *ToControllingExpr = nullptr;
7684 TypeSourceInfo *ToControllingType = nullptr;
7685 if (E->isExprPredicate())
7686 ToControllingExpr = importChecked(Err, E->getControllingExpr());
7687 else
7688 ToControllingType = importChecked(Err, E->getControllingType());
7689 assert((ToControllingExpr || ToControllingType) &&
7690 "Either the controlling expr or type must be nonnull");
7691 auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
7692 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7693 if (Err)
7694 return std::move(Err);
7695
7697 SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
7698 if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
7699 return std::move(Err);
7700
7701 ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
7702 SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
7703 if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
7704 return std::move(Err);
7705
7706 const ASTContext &ToCtx = Importer.getToContext();
7707 if (E->isResultDependent()) {
7708 if (ToControllingExpr) {
7710 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7711 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7713 }
7715 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7716 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7718 }
7719
7720 if (ToControllingExpr) {
7722 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7723 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7725 }
7727 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7728 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7730}
7731
7733
7734 Error Err = Error::success();
7735 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7736 auto ToType = importChecked(Err, E->getType());
7737 auto ToFunctionName = importChecked(Err, E->getFunctionName());
7738 if (Err)
7739 return std::move(Err);
7740
7741 return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
7742 E->getIdentKind(), E->isTransparent(),
7743 ToFunctionName);
7744}
7745
7747
7748 Error Err = Error::success();
7749 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
7750 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
7751 auto ToDecl = importChecked(Err, E->getDecl());
7752 auto ToLocation = importChecked(Err, E->getLocation());
7753 auto ToType = importChecked(Err, E->getType());
7754 if (Err)
7755 return std::move(Err);
7756
7757 NamedDecl *ToFoundD = nullptr;
7758 if (E->getDecl() != E->getFoundDecl()) {
7759 auto FoundDOrErr = import(E->getFoundDecl());
7760 if (!FoundDOrErr)
7761 return FoundDOrErr.takeError();
7762 ToFoundD = *FoundDOrErr;
7763 }
7764
7765 TemplateArgumentListInfo ToTAInfo;
7766 TemplateArgumentListInfo *ToResInfo = nullptr;
7767 if (E->hasExplicitTemplateArgs()) {
7768 if (Error Err =
7770 E->template_arguments(), ToTAInfo))
7771 return std::move(Err);
7772 ToResInfo = &ToTAInfo;
7773 }
7774
7775 auto *ToE = DeclRefExpr::Create(
7776 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
7777 E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
7778 E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse());
7779 if (E->hadMultipleCandidates())
7780 ToE->setHadMultipleCandidates(true);
7781 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
7782 return ToE;
7783}
7784
7786 ExpectedType TypeOrErr = import(E->getType());
7787 if (!TypeOrErr)
7788 return TypeOrErr.takeError();
7789
7790 return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
7791}
7792
7794 ExpectedExpr ToInitOrErr = import(E->getInit());
7795 if (!ToInitOrErr)
7796 return ToInitOrErr.takeError();
7797
7798 ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
7799 if (!ToEqualOrColonLocOrErr)
7800 return ToEqualOrColonLocOrErr.takeError();
7801
7802 SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
7803 // List elements from the second, the first is Init itself
7804 for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
7805 if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
7806 ToIndexExprs[I - 1] = *ToArgOrErr;
7807 else
7808 return ToArgOrErr.takeError();
7809 }
7810
7811 SmallVector<Designator, 4> ToDesignators(E->size());
7812 if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
7813 return std::move(Err);
7814
7816 Importer.getToContext(), ToDesignators,
7817 ToIndexExprs, *ToEqualOrColonLocOrErr,
7818 E->usesGNUSyntax(), *ToInitOrErr);
7819}
7820
7823 ExpectedType ToTypeOrErr = import(E->getType());
7824 if (!ToTypeOrErr)
7825 return ToTypeOrErr.takeError();
7826
7827 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7828 if (!ToLocationOrErr)
7829 return ToLocationOrErr.takeError();
7830
7831 return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
7832 *ToTypeOrErr, *ToLocationOrErr);
7833}
7834
7836 ExpectedType ToTypeOrErr = import(E->getType());
7837 if (!ToTypeOrErr)
7838 return ToTypeOrErr.takeError();
7839
7840 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7841 if (!ToLocationOrErr)
7842 return ToLocationOrErr.takeError();
7843
7845 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7846}
7847
7848
7850 ExpectedType ToTypeOrErr = import(E->getType());
7851 if (!ToTypeOrErr)
7852 return ToTypeOrErr.takeError();
7853
7854 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7855 if (!ToLocationOrErr)
7856 return ToLocationOrErr.takeError();
7857
7859 Importer.getToContext(), E->getValue(), E->isExact(),
7860 *ToTypeOrErr, *ToLocationOrErr);
7861}
7862
7864 auto ToTypeOrErr = import(E->getType());
7865 if (!ToTypeOrErr)
7866 return ToTypeOrErr.takeError();
7867
7868 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7869 if (!ToSubExprOrErr)
7870 return ToSubExprOrErr.takeError();
7871
7872 return new (Importer.getToContext()) ImaginaryLiteral(
7873 *ToSubExprOrErr, *ToTypeOrErr);
7874}
7875
7877 auto ToTypeOrErr = import(E->getType());
7878 if (!ToTypeOrErr)
7879 return ToTypeOrErr.takeError();
7880
7881 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7882 if (!ToLocationOrErr)
7883 return ToLocationOrErr.takeError();
7884
7885 return new (Importer.getToContext()) FixedPointLiteral(
7886 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
7887 Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
7888}
7889
7891 ExpectedType ToTypeOrErr = import(E->getType());
7892 if (!ToTypeOrErr)
7893 return ToTypeOrErr.takeError();
7894
7895 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7896 if (!ToLocationOrErr)
7897 return ToLocationOrErr.takeError();
7898
7899 return new (Importer.getToContext()) CharacterLiteral(
7900 E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
7901}
7902
7904 ExpectedType ToTypeOrErr = import(E->getType());
7905 if (!ToTypeOrErr)
7906 return ToTypeOrErr.takeError();
7907
7909 if (Error Err = ImportArrayChecked(
7910 E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
7911 return std::move(Err);
7912
7913 return StringLiteral::Create(Importer.getToContext(), E->getBytes(),
7914 E->getKind(), E->isPascal(), *ToTypeOrErr,
7915 ToLocations);
7916}
7917
7919
7920 Error Err = Error::success();
7921 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7922 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7923 auto ToType = importChecked(Err, E->getType());
7924 auto ToInitializer = importChecked(Err, E->getInitializer());
7925 if (Err)
7926 return std::move(Err);
7927
7928 return new (Importer.getToContext()) CompoundLiteralExpr(
7929 ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
7930 ToInitializer, E->isFileScope());
7931}
7932
7934
7935 Error Err = Error::success();
7936 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7937 auto ToType = importChecked(Err, E->getType());
7938 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7939 if (Err)
7940 return std::move(Err);
7941
7943 if (Error Err = ImportArrayChecked(
7944 E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
7945 ToExprs.begin()))
7946 return std::move(Err);
7947
7948 return new (Importer.getToContext()) AtomicExpr(
7949
7950 ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
7951}
7952
7954 Error Err = Error::success();
7955 auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc());
7956 auto ToLabelLoc = importChecked(Err, E->getLabelLoc());
7957 auto ToLabel = importChecked(Err, E->getLabel());
7958 auto ToType = importChecked(Err, E->getType());
7959 if (Err)
7960 return std::move(Err);
7961
7962 return new (Importer.getToContext()) AddrLabelExpr(
7963 ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
7964}
7966 Error Err = Error::success();
7967 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7968 auto ToResult = importChecked(Err, E->getAPValueResult());
7969 if (Err)
7970 return std::move(Err);
7971
7972 return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult);
7973}
7975 Error Err = Error::success();
7976 auto ToLParen = importChecked(Err, E->getLParen());
7977 auto ToRParen = importChecked(Err, E->getRParen());
7978 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7979 if (Err)
7980 return std::move(Err);
7981
7982 return new (Importer.getToContext())
7983 ParenExpr(ToLParen, ToRParen, ToSubExpr);
7984}
7985
7987 SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
7988 if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
7989 return std::move(Err);
7990
7991 ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
7992 if (!ToLParenLocOrErr)
7993 return ToLParenLocOrErr.takeError();
7994
7995 ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
7996 if (!ToRParenLocOrErr)
7997 return ToRParenLocOrErr.takeError();
7998
7999 return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
8000 ToExprs, *ToRParenLocOrErr);
8001}
8002
8004 Error Err = Error::success();
8005 auto ToSubStmt = importChecked(Err, E->getSubStmt());
8006 auto ToType = importChecked(Err, E->getType());
8007 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8008 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8009 if (Err)
8010 return std::move(Err);
8011
8012 return new (Importer.getToContext())
8013 StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
8014 E->getTemplateDepth());
8015}
8016
8018 Error Err = Error::success();
8019 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8020 auto ToType = importChecked(Err, E->getType());
8021 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8022 if (Err)
8023 return std::move(Err);
8024
8025 auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
8026 E->hasStoredFPFeatures());
8027 UO->setType(ToType);
8028 UO->setSubExpr(ToSubExpr);
8029 UO->setOpcode(E->getOpcode());
8030 UO->setOperatorLoc(ToOperatorLoc);
8031 UO->setCanOverflow(E->canOverflow());
8032 if (E->hasStoredFPFeatures())
8033 UO->setStoredFPFeatures(E->getStoredFPFeatures());
8034
8035 return UO;
8036}
8037
8039
8041 Error Err = Error::success();
8042 auto ToType = importChecked(Err, E->getType());
8043 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8044 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8045 if (Err)
8046 return std::move(Err);
8047
8048 if (E->isArgumentType()) {
8049 Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
8050 import(E->getArgumentTypeInfo());
8051 if (!ToArgumentTypeInfoOrErr)
8052 return ToArgumentTypeInfoOrErr.takeError();
8053
8054 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8055 E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
8056 ToRParenLoc);
8057 }
8058
8059 ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
8060 if (!ToArgumentExprOrErr)
8061 return ToArgumentExprOrErr.takeError();
8062
8063 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8064 E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
8065}
8066
8068 Error Err = Error::success();
8069 auto ToLHS = importChecked(Err, E->getLHS());
8070 auto ToRHS = importChecked(Err, E->getRHS());
8071 auto ToType = importChecked(Err, E->getType());
8072 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8073 if (Err)
8074 return std::move(Err);
8075
8077 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8078 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8079 E->getFPFeatures());
8080}
8081
8083 Error Err = Error::success();
8084 auto ToCond = importChecked(Err, E->getCond());
8085 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8086 auto ToLHS = importChecked(Err, E->getLHS());
8087 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8088 auto ToRHS = importChecked(Err, E->getRHS());
8089 auto ToType = importChecked(Err, E->getType());
8090 if (Err)
8091 return std::move(Err);
8092
8093 return new (Importer.getToContext()) ConditionalOperator(
8094 ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
8095 E->getValueKind(), E->getObjectKind());
8096}
8097
8100 Error Err = Error::success();
8101 auto ToCommon = importChecked(Err, E->getCommon());
8102 auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue());
8103 auto ToCond = importChecked(Err, E->getCond());
8104 auto ToTrueExpr = importChecked(Err, E->getTrueExpr());
8105 auto ToFalseExpr = importChecked(Err, E->getFalseExpr());
8106 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8107 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8108 auto ToType = importChecked(Err, E->getType());
8109 if (Err)
8110 return std::move(Err);
8111
8112 return new (Importer.getToContext()) BinaryConditionalOperator(
8113 ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
8114 ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
8115 E->getObjectKind());
8116}
8117
8120 Error Err = Error::success();
8121 auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
8122 if (Err)
8123 return std::move(Err);
8124
8125 return new (Importer.getToContext())
8126 CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
8127}
8128
8130 Error Err = Error::success();
8131 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8132 auto ToQueriedTypeSourceInfo =
8134 auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression());
8135 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8136 auto ToType = importChecked(Err, E->getType());
8137 if (Err)
8138 return std::move(Err);
8139
8140 return new (Importer.getToContext()) ArrayTypeTraitExpr(
8141 ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
8142 ToDimensionExpression, ToEndLoc, ToType);
8143}
8144
8146 Error Err = Error::success();
8147 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8148 auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression());
8149 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8150 auto ToType = importChecked(Err, E->getType());
8151 if (Err)
8152 return std::move(Err);
8153
8154 return new (Importer.getToContext()) ExpressionTraitExpr(
8155 ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
8156 ToEndLoc, ToType);
8157}
8158
8160 Error Err = Error::success();
8161 auto ToLocation = importChecked(Err, E->getLocation());
8162 auto ToType = importChecked(Err, E->getType());
8163 auto ToSourceExpr = importChecked(Err, E->getSourceExpr());
8164 if (Err)
8165 return std::move(Err);
8166
8167 return new (Importer.getToContext()) OpaqueValueExpr(
8168 ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
8169}
8170
8172 Error Err = Error::success();
8173 auto ToLHS = importChecked(Err, E->getLHS());
8174 auto ToRHS = importChecked(Err, E->getRHS());
8175 auto ToType = importChecked(Err, E->getType());
8176 auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc());
8177 if (Err)
8178 return std::move(Err);
8179
8180 return new (Importer.getToContext()) ArraySubscriptExpr(
8181 ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
8182 ToRBracketLoc);
8183}
8184
8187 Error Err = Error::success();
8188 auto ToLHS = importChecked(Err, E->getLHS());
8189 auto ToRHS = importChecked(Err, E->getRHS());
8190 auto ToType = importChecked(Err, E->getType());
8191 auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType());
8192 auto ToComputationResultType =
8194 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8195 if (Err)
8196 return std::move(Err);
8197
8199 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8200 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8201 E->getFPFeatures(),
8202 ToComputationLHSType, ToComputationResultType);
8203}
8204
8207 CXXCastPath Path;
8208 for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
8209 if (auto SpecOrErr = import(*I))
8210 Path.push_back(*SpecOrErr);
8211 else
8212 return SpecOrErr.takeError();
8213 }
8214 return Path;
8215}
8216
8218 ExpectedType ToTypeOrErr = import(E->getType());
8219 if (!ToTypeOrErr)
8220 return ToTypeOrErr.takeError();
8221
8222 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8223 if (!ToSubExprOrErr)
8224 return ToSubExprOrErr.takeError();
8225
8226 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8227 if (!ToBasePathOrErr)
8228 return ToBasePathOrErr.takeError();
8229
8231 Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
8232 &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures());
8233}
8234
8236 Error Err = Error::success();
8237 auto ToType = importChecked(Err, E->getType());
8238 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8239 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
8240 if (Err)
8241 return std::move(Err);
8242
8243 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8244 if (!ToBasePathOrErr)
8245 return ToBasePathOrErr.takeError();
8246 CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
8247
8248 switch (E->getStmtClass()) {
8249 case Stmt::CStyleCastExprClass: {
8250 auto *CCE = cast<CStyleCastExpr>(E);
8251 ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
8252 if (!ToLParenLocOrErr)
8253 return ToLParenLocOrErr.takeError();
8254 ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
8255 if (!ToRParenLocOrErr)
8256 return ToRParenLocOrErr.takeError();
8258 Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
8259 ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten,
8260 *ToLParenLocOrErr, *ToRParenLocOrErr);
8261 }
8262
8263 case Stmt::CXXFunctionalCastExprClass: {
8264 auto *FCE = cast<CXXFunctionalCastExpr>(E);
8265 ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
8266 if (!ToLParenLocOrErr)
8267 return ToLParenLocOrErr.takeError();
8268 ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
8269 if (!ToRParenLocOrErr)
8270 return ToRParenLocOrErr.takeError();
8272 Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
8273 E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(),
8274 *ToLParenLocOrErr, *ToRParenLocOrErr);
8275 }
8276
8277 case Stmt::ObjCBridgedCastExprClass: {
8278 auto *OCE = cast<ObjCBridgedCastExpr>(E);
8279 ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
8280 if (!ToLParenLocOrErr)
8281 return ToLParenLocOrErr.takeError();
8282 ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
8283 if (!ToBridgeKeywordLocOrErr)
8284 return ToBridgeKeywordLocOrErr.takeError();
8285 return new (Importer.getToContext()) ObjCBridgedCastExpr(
8286 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
8287 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
8288 }
8289 case Stmt::BuiltinBitCastExprClass: {
8290 auto *BBC = cast<BuiltinBitCastExpr>(E);
8291 ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
8292 if (!ToKWLocOrErr)
8293 return ToKWLocOrErr.takeError();
8294 ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
8295 if (!ToRParenLocOrErr)
8296 return ToRParenLocOrErr.takeError();
8297 return new (Importer.getToContext()) BuiltinBitCastExpr(
8298 ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
8299 ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
8300 }
8301 default:
8302 llvm_unreachable("Cast expression of unsupported type!");
8303 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
8304 }
8305}
8306
8309 for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
8310 const OffsetOfNode &FromNode = E->getComponent(I);
8311
8312 SourceLocation ToBeginLoc, ToEndLoc;
8313
8314 if (FromNode.getKind() != OffsetOfNode::Base) {
8315 Error Err = Error::success();
8316 ToBeginLoc = importChecked(Err, FromNode.getBeginLoc());
8317 ToEndLoc = importChecked(Err, FromNode.getEndLoc());
8318 if (Err)
8319 return std::move(Err);
8320 }
8321
8322 switch (FromNode.getKind()) {
8324 ToNodes.push_back(
8325 OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
8326 break;
8327 case OffsetOfNode::Base: {
8328 auto ToBSOrErr = import(FromNode.getBase());
8329 if (!ToBSOrErr)
8330 return ToBSOrErr.takeError();
8331 ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
8332 break;
8333 }
8334 case OffsetOfNode::Field: {
8335 auto ToFieldOrErr = import(FromNode.getField());
8336 if (!ToFieldOrErr)
8337 return ToFieldOrErr.takeError();
8338 ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
8339 break;
8340 }
8342 IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
8343 ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
8344 break;
8345 }
8346 }
8347 }
8348
8350 for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
8351 ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
8352 if (!ToIndexExprOrErr)
8353 return ToIndexExprOrErr.takeError();
8354 ToExprs[I] = *ToIndexExprOrErr;
8355 }
8356
8357 Error Err = Error::success();
8358 auto ToType = importChecked(Err, E->getType());
8359 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8360 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8361 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8362 if (Err)
8363 return std::move(Err);
8364
8365 return OffsetOfExpr::Create(
8366 Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
8367 ToExprs, ToRParenLoc);
8368}
8369
8371 Error Err = Error::success();
8372 auto ToType = importChecked(Err, E->getType());
8373 auto ToOperand = importChecked(Err, E->getOperand());
8374 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8375 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8376 if (Err)
8377 return std::move(Err);
8378
8379 CanThrowResult ToCanThrow;
8380 if (E->isValueDependent())
8381 ToCanThrow = CT_Dependent;
8382 else
8383 ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
8384
8385 return new (Importer.getToContext()) CXXNoexceptExpr(
8386 ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
8387}
8388
8390 Error Err = Error::success();
8391 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8392 auto ToType = importChecked(Err, E->getType());
8393 auto ToThrowLoc = importChecked(Err, E->getThrowLoc());
8394 if (Err)
8395 return std::move(Err);
8396
8397 return new (Importer.getToContext()) CXXThrowExpr(
8398 ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
8399}
8400
8402 ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
8403 if (!ToUsedLocOrErr)
8404 return ToUsedLocOrErr.takeError();
8405
8406 auto ToParamOrErr = import(E->getParam());
8407 if (!ToParamOrErr)
8408 return ToParamOrErr.takeError();
8409
8410 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8411 if (!UsedContextOrErr)
8412 return UsedContextOrErr.takeError();
8413
8414 // Import the default arg if it was not imported yet.
8415 // This is needed because it can happen that during the import of the
8416 // default expression (from VisitParmVarDecl) the same ParmVarDecl is
8417 // encountered here. The default argument for a ParmVarDecl is set in the
8418 // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here,
8419 // see VisitParmVarDecl).
8420 ParmVarDecl *ToParam = *ToParamOrErr;
8421 if (!ToParam->getDefaultArg()) {
8422 std::optional<ParmVarDecl *> FromParam =
8423 Importer.getImportedFromDecl(ToParam);
8424 assert(FromParam && "ParmVarDecl was not imported?");
8425
8426 if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam))
8427 return std::move(Err);
8428 }
8429 Expr *RewrittenInit = nullptr;
8430 if (E->hasRewrittenInit()) {
8431 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8432 if (!ExprOrErr)
8433 return ExprOrErr.takeError();
8434 RewrittenInit = ExprOrErr.get();
8435 }
8436 return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr,
8437 *ToParamOrErr, RewrittenInit,
8438 *UsedContextOrErr);
8439}
8440
8443 Error Err = Error::success();
8444 auto ToType = importChecked(Err, E->getType());
8445 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8446 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8447 if (Err)
8448 return std::move(Err);
8449
8450 return new (Importer.getToContext()) CXXScalarValueInitExpr(
8451 ToType, ToTypeSourceInfo, ToRParenLoc);
8452}
8453
8456 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8457 if (!ToSubExprOrErr)
8458 return ToSubExprOrErr.takeError();
8459
8460 auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
8461 if (!ToDtorOrErr)
8462 return ToDtorOrErr.takeError();
8463
8464 ASTContext &ToCtx = Importer.getToContext();
8465 CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
8466 return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
8467}
8468
8470
8472 Error Err = Error::success();
8473 auto ToConstructor = importChecked(Err, E->getConstructor());
8474 auto ToType = importChecked(Err, E->getType());
8475 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8476 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8477 if (Err)
8478 return std::move(Err);
8479
8481 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8482 return std::move(Err);
8483
8485 Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
8486 ToParenOrBraceRange, E->hadMultipleCandidates(),
8489}
8490
8493 DeclContext *DC, *LexicalDC;
8494 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
8495 return std::move(Err);
8496
8497 Error Err = Error::success();
8498 auto Temporary = importChecked(Err, D->getTemporaryExpr());
8499 auto ExtendingDecl = importChecked(Err, D->getExtendingDecl());
8500 if (Err)
8501 return std::move(Err);
8502 // FIXME: Should ManglingNumber get numbers associated with 'to' context?
8503
8505 if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl,
8506 D->getManglingNumber()))
8507 return To;
8508
8509 To->setLexicalDeclContext(LexicalDC);
8510 LexicalDC->addDeclInternal(To);
8511 return To;
8512}
8513
8516 Error Err = Error::success();
8517 auto ToType = importChecked(Err, E->getType());
8518 Expr *ToTemporaryExpr = importChecked(
8519 Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr());
8520 auto ToMaterializedDecl =
8522 if (Err)
8523 return std::move(Err);
8524
8525 if (!ToTemporaryExpr)
8526 ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
8527
8528 auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
8529 ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
8530 ToMaterializedDecl);
8531
8532 return ToMTE;
8533}
8534
8536 Error Err = Error::success();
8537 auto *ToPattern = importChecked(Err, E->getPattern());
8538 auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8539 if (Err)
8540 return std::move(Err);
8541
8542 return new (Importer.getToContext())
8543 PackExpansionExpr(ToPattern, ToEllipsisLoc, E->getNumExpansions());
8544}
8545
8547 Error Err = Error::success();
8548 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8549 auto ToPack = importChecked(Err, E->getPack());
8550 auto ToPackLoc = importChecked(Err, E->getPackLoc());
8551 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8552 if (Err)
8553 return std::move(Err);
8554
8555 UnsignedOrNone Length = std::nullopt;
8556 if (!E->isValueDependent())
8557 Length = E->getPackLength();
8558
8559 SmallVector<TemplateArgument, 8> ToPartialArguments;
8560 if (E->isPartiallySubstituted()) {
8562 ToPartialArguments))
8563 return std::move(Err);
8564 }
8565
8567 Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
8568 Length, ToPartialArguments);
8569}
8570
8571
8573 Error Err = Error::success();
8574 auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
8575 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8576 auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens());
8577 auto ToArraySize = importChecked(Err, E->getArraySize());
8578 auto ToInitializer = importChecked(Err, E->getInitializer());
8579 auto ToType = importChecked(Err, E->getType());
8580 auto ToAllocatedTypeSourceInfo =
8582 auto ToSourceRange = importChecked(Err, E->getSourceRange());
8583 auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange());
8584 if (Err)
8585 return std::move(Err);
8586
8587 SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
8588 if (Error Err =
8589 ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
8590 return std::move(Err);
8591
8592 return CXXNewExpr::Create(
8593 Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
8594 ToOperatorDelete, E->implicitAllocationParameters(),
8595 E->doesUsualArrayDeleteWantSize(), ToPlacementArgs, ToTypeIdParens,
8596 ToArraySize, E->getInitializationStyle(), ToInitializer, ToType,
8597 ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange);
8598}
8599
8601 Error Err = Error::success();
8602 auto ToType = importChecked(Err, E->getType());
8603 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8604 auto ToArgument = importChecked(Err, E->getArgument());
8605 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8606 if (Err)
8607 return std::move(Err);
8608
8609 return new (Importer.getToContext()) CXXDeleteExpr(
8610 ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
8611 E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
8612 ToBeginLoc);
8613}
8614
8616 Error Err = Error::success();
8617 auto ToType = importChecked(Err, E->getType());
8618 auto ToLocation = importChecked(Err, E->getLocation());
8619 auto ToConstructor = importChecked(Err, E->getConstructor());
8620 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8621 if (Err)
8622 return std::move(Err);
8623
8625 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8626 return std::move(Err);
8627
8629 Importer.getToContext(), ToType, ToLocation, ToConstructor,
8630 E->isElidable(), ToArgs, E->hadMultipleCandidates(),
8633 ToParenOrBraceRange);
8635 return ToE;
8636}
8637
8639 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8640 if (!ToSubExprOrErr)
8641 return ToSubExprOrErr.takeError();
8642
8644 if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
8645 return std::move(Err);
8646
8648 Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
8649 ToObjects);
8650}
8651
8653 Error Err = Error::success();
8654 auto ToCallee = importChecked(Err, E->getCallee());
8655 auto ToType = importChecked(Err, E->getType());
8656 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8657 if (Err)
8658 return std::move(Err);
8659
8661 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8662 return std::move(Err);
8663
8664 return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
8665 ToType, E->getValueKind(), ToRParenLoc,
8666 E->getFPFeatures());
8667}
8668
8670 ExpectedType ToTypeOrErr = import(E->getType());
8671 if (!ToTypeOrErr)
8672 return ToTypeOrErr.takeError();
8673
8674 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8675 if (!ToLocationOrErr)
8676 return ToLocationOrErr.takeError();
8677
8678 return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
8679 *ToTypeOrErr, E->isImplicit());
8680}
8681
8683 ExpectedType ToTypeOrErr = import(E->getType());
8684 if (!ToTypeOrErr)
8685 return ToTypeOrErr.takeError();
8686
8687 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8688 if (!ToLocationOrErr)
8689 return ToLocationOrErr.takeError();
8690
8691 return CXXBoolLiteralExpr::Create(Importer.getToContext(), E->getValue(),
8692 *ToTypeOrErr, *ToLocationOrErr);
8693}
8694
8696 Error Err = Error::success();
8697 auto ToBase = importChecked(Err, E->getBase());
8698 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8699 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8700 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8701 auto ToMemberDecl = importChecked(Err, E->getMemberDecl());
8702 auto ToType = importChecked(Err, E->getType());
8703 auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl());
8704 auto ToName = importChecked(Err, E->getMemberNameInfo().getName());
8705 auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc());
8706 if (Err)
8707 return std::move(Err);
8708
8709 DeclAccessPair ToFoundDecl =
8711
8712 DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
8713
8714 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8715 if (E->hasExplicitTemplateArgs()) {
8716 if (Error Err =
8718 E->template_arguments(), ToTAInfo))
8719 return std::move(Err);
8720 ResInfo = &ToTAInfo;
8721 }
8722
8723 return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(),
8724 ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8725 ToMemberDecl, ToFoundDecl, ToMemberNameInfo,
8726 ResInfo, ToType, E->getValueKind(),
8727 E->getObjectKind(), E->isNonOdrUse());
8728}
8729
8732 Error Err = Error::success();
8733 auto ToBase = importChecked(Err, E->getBase());
8734 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8735 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8736 auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo());
8737 auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc());
8738 auto ToTildeLoc = importChecked(Err, E->getTildeLoc());
8739 if (Err)
8740 return std::move(Err);
8741
8743 if (const IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
8744 const IdentifierInfo *ToII = Importer.Import(FromII);
8745 ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
8746 if (!ToDestroyedTypeLocOrErr)
8747 return ToDestroyedTypeLocOrErr.takeError();
8748 Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
8749 } else {
8750 if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
8751 Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
8752 else
8753 return ToTIOrErr.takeError();
8754 }
8755
8756 return new (Importer.getToContext()) CXXPseudoDestructorExpr(
8757 Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
8758 ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
8759}
8760
8763 Error Err = Error::success();
8764 auto ToType = importChecked(Err, E->getType());
8765 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8766 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8767 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8768 auto ToFirstQualifierFoundInScope =
8770 if (Err)
8771 return std::move(Err);
8772
8773 Expr *ToBase = nullptr;
8774 if (!E->isImplicitAccess()) {
8775 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8776 ToBase = *ToBaseOrErr;
8777 else
8778 return ToBaseOrErr.takeError();
8779 }
8780
8781 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8782
8783 if (E->hasExplicitTemplateArgs()) {
8784 if (Error Err =
8786 E->template_arguments(), ToTAInfo))
8787 return std::move(Err);
8788 ResInfo = &ToTAInfo;
8789 }
8790 auto ToMember = importChecked(Err, E->getMember());
8791 auto ToMemberLoc = importChecked(Err, E->getMemberLoc());
8792 if (Err)
8793 return std::move(Err);
8794 DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc);
8795
8796 // Import additional name location/type info.
8797 if (Error Err =
8798 ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo))
8799 return std::move(Err);
8800
8802 Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
8803 ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
8804 ToMemberNameInfo, ResInfo);
8805}
8806
8809 Error Err = Error::success();
8810 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8811 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8812 auto ToDeclName = importChecked(Err, E->getDeclName());
8813 auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc());
8814 auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc());
8815 auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc());
8816 if (Err)
8817 return std::move(Err);
8818
8819 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8820 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8821 return std::move(Err);
8822
8823 TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
8824 TemplateArgumentListInfo *ResInfo = nullptr;
8825 if (E->hasExplicitTemplateArgs()) {
8826 if (Error Err =
8828 return std::move(Err);
8829 ResInfo = &ToTAInfo;
8830 }
8831
8833 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
8834 ToNameInfo, ResInfo);
8835}
8836
8839 Error Err = Error::success();
8840 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8841 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8842 auto ToType = importChecked(Err, E->getType());
8843 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8844 if (Err)
8845 return std::move(Err);
8846
8848 if (Error Err =
8849 ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
8850 return std::move(Err);
8851
8853 Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc,
8854 ArrayRef(ToArgs), ToRParenLoc, E->isListInitialization());
8855}
8856
8859 Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
8860 if (!ToNamingClassOrErr)
8861 return ToNamingClassOrErr.takeError();
8862
8863 auto ToQualifierLocOrErr = import(E->getQualifierLoc());
8864 if (!ToQualifierLocOrErr)
8865 return ToQualifierLocOrErr.takeError();
8866
8867 Error Err = Error::success();
8868 auto ToName = importChecked(Err, E->getName());
8869 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8870 if (Err)
8871 return std::move(Err);
8872 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8873
8874 // Import additional name location/type info.
8875 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8876 return std::move(Err);
8877
8878 UnresolvedSet<8> ToDecls;
8879 for (auto *D : E->decls())
8880 if (auto ToDOrErr = import(D))
8881 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8882 else
8883 return ToDOrErr.takeError();
8884
8885 if (E->hasExplicitTemplateArgs()) {
8886 TemplateArgumentListInfo ToTAInfo;
8889 ToTAInfo))
8890 return std::move(Err);
8891
8892 ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
8893 if (!ToTemplateKeywordLocOrErr)
8894 return ToTemplateKeywordLocOrErr.takeError();
8895
8896 const bool KnownDependent =
8897 (E->getDependence() & ExprDependence::TypeValue) ==
8898 ExprDependence::TypeValue;
8900 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8901 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
8902 ToDecls.begin(), ToDecls.end(), KnownDependent,
8903 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8904 }
8905
8907 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8908 ToNameInfo, E->requiresADL(), ToDecls.begin(), ToDecls.end(),
8909 /*KnownDependent=*/E->isTypeDependent(),
8910 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8911}
8912
8915 Error Err = Error::success();
8916 auto ToType = importChecked(Err, E->getType());
8917 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8918 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8919 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8920 auto ToName = importChecked(Err, E->getName());
8921 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8922 if (Err)
8923 return std::move(Err);
8924
8925 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8926 // Import additional name location/type info.
8927 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8928 return std::move(Err);
8929
8930 UnresolvedSet<8> ToDecls;
8931 for (Decl *D : E->decls())
8932 if (auto ToDOrErr = import(D))
8933 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8934 else
8935 return ToDOrErr.takeError();
8936
8937 TemplateArgumentListInfo ToTAInfo;
8938 TemplateArgumentListInfo *ResInfo = nullptr;
8939 if (E->hasExplicitTemplateArgs()) {
8940 TemplateArgumentListInfo FromTAInfo;
8941 E->copyTemplateArgumentsInto(FromTAInfo);
8942 if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo))
8943 return std::move(Err);
8944 ResInfo = &ToTAInfo;
8945 }
8946
8947 Expr *ToBase = nullptr;
8948 if (!E->isImplicitAccess()) {
8949 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8950 ToBase = *ToBaseOrErr;
8951 else
8952 return ToBaseOrErr.takeError();
8953 }
8954
8956 Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
8957 E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8958 ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
8959}
8960
8962 Error Err = Error::success();
8963 auto ToCallee = importChecked(Err, E->getCallee());
8964 auto ToType = importChecked(Err, E->getType());
8965 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8966 if (Err)
8967 return std::move(Err);
8968
8969 unsigned NumArgs = E->getNumArgs();
8970 llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
8971 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8972 return std::move(Err);
8973
8974 if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
8976 Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
8977 OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
8978 OCE->getADLCallKind());
8979 }
8980
8981 return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
8982 E->getValueKind(), ToRParenLoc, E->getFPFeatures(),
8983 /*MinNumArgs=*/0, E->getADLCallKind());
8984}
8985
8987 CXXRecordDecl *FromClass = E->getLambdaClass();
8988 auto ToClassOrErr = import(FromClass);
8989 if (!ToClassOrErr)
8990 return ToClassOrErr.takeError();
8991 CXXRecordDecl *ToClass = *ToClassOrErr;
8992
8993 auto ToCallOpOrErr = import(E->getCallOperator());
8994 if (!ToCallOpOrErr)
8995 return ToCallOpOrErr.takeError();
8996
8997 SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
8998 if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
8999 return std::move(Err);
9000
9001 Error Err = Error::success();
9002 auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange());
9003 auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc());
9004 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9005 if (Err)
9006 return std::move(Err);
9007
9008 return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange,
9009 E->getCaptureDefault(), ToCaptureDefaultLoc,
9011 E->hasExplicitResultType(), ToCaptureInits,
9012 ToEndLoc, E->containsUnexpandedParameterPack());
9013}
9014
9015
9017 Error Err = Error::success();
9018 auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
9019 auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc());
9020 auto ToType = importChecked(Err, E->getType());
9021 if (Err)
9022 return std::move(Err);
9023
9024 SmallVector<Expr *, 4> ToExprs(E->getNumInits());
9025 if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
9026 return std::move(Err);
9027
9028 ASTContext &ToCtx = Importer.getToContext();
9029 InitListExpr *To = new (ToCtx) InitListExpr(
9030 ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc);
9031 To->setType(ToType);
9032
9033 if (E->hasArrayFiller()) {
9034 if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
9035 To->setArrayFiller(*ToFillerOrErr);
9036 else
9037 return ToFillerOrErr.takeError();
9038 }
9039
9040 if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
9041 if (auto ToFDOrErr = import(FromFD))
9042 To->setInitializedFieldInUnion(*ToFDOrErr);
9043 else
9044 return ToFDOrErr.takeError();
9045 }
9046
9047 if (InitListExpr *SyntForm = E->getSyntacticForm()) {
9048 if (auto ToSyntFormOrErr = import(SyntForm))
9049 To->setSyntacticForm(*ToSyntFormOrErr);
9050 else
9051 return ToSyntFormOrErr.takeError();
9052 }
9053
9054 // Copy InitListExprBitfields, which are not handled in the ctor of
9055 // InitListExpr.
9057
9058 return To;
9059}
9060
9063 ExpectedType ToTypeOrErr = import(E->getType());
9064 if (!ToTypeOrErr)
9065 return ToTypeOrErr.takeError();
9066
9067 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
9068 if (!ToSubExprOrErr)
9069 return ToSubExprOrErr.takeError();
9070
9071 return new (Importer.getToContext()) CXXStdInitializerListExpr(
9072 *ToTypeOrErr, *ToSubExprOrErr);
9073}
9074
9077 Error Err = Error::success();
9078 auto ToLocation = importChecked(Err, E->getLocation());
9079 auto ToType = importChecked(Err, E->getType());
9080 auto ToConstructor = importChecked(Err, E->getConstructor());
9081 if (Err)
9082 return std::move(Err);
9083
9084 return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
9085 ToLocation, ToType, ToConstructor, E->constructsVBase(),
9086 E->inheritedFromVBase());
9087}
9088
9090 Error Err = Error::success();
9091 auto ToType = importChecked(Err, E->getType());
9092 auto ToCommonExpr = importChecked(Err, E->getCommonExpr());
9093 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9094 if (Err)
9095 return std::move(Err);
9096
9097 return new (Importer.getToContext()) ArrayInitLoopExpr(
9098 ToType, ToCommonExpr, ToSubExpr);
9099}
9100
9102 ExpectedType ToTypeOrErr = import(E->getType());
9103 if (!ToTypeOrErr)
9104 return ToTypeOrErr.takeError();
9105 return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
9106}
9107
9109 ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
9110 if (!ToBeginLocOrErr)
9111 return ToBeginLocOrErr.takeError();
9112
9113 auto ToFieldOrErr = import(E->getField());
9114 if (!ToFieldOrErr)
9115 return ToFieldOrErr.takeError();
9116
9117 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
9118 if (!UsedContextOrErr)
9119 return UsedContextOrErr.takeError();
9120
9121 FieldDecl *ToField = *ToFieldOrErr;
9122 assert(ToField->hasInClassInitializer() &&
9123 "Field should have in-class initializer if there is a default init "
9124 "expression that uses it.");
9125 if (!ToField->getInClassInitializer()) {
9126 // The in-class initializer may be not yet set in "To" AST even if the
9127 // field is already there. This must be set here to make construction of
9128 // CXXDefaultInitExpr work.
9129 auto ToInClassInitializerOrErr =
9130 import(E->getField()->getInClassInitializer());
9131 if (!ToInClassInitializerOrErr)
9132 return ToInClassInitializerOrErr.takeError();
9133 ToField->setInClassInitializer(*ToInClassInitializerOrErr);
9134 }
9135
9136 Expr *RewrittenInit = nullptr;
9137 if (E->hasRewrittenInit()) {
9138 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
9139 if (!ExprOrErr)
9140 return ExprOrErr.takeError();
9141 RewrittenInit = ExprOrErr.get();
9142 }
9143
9144 return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr,
9145 ToField, *UsedContextOrErr, RewrittenInit);
9146}
9147
9149 Error Err = Error::success();
9150 auto ToType = importChecked(Err, E->getType());
9151 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9152 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
9153 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
9154 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
9155 auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets());
9156 if (Err)
9157 return std::move(Err);
9158
9160 CastKind CK = E->getCastKind();
9161 auto ToBasePathOrErr = ImportCastPath(E);
9162 if (!ToBasePathOrErr)
9163 return ToBasePathOrErr.takeError();
9164
9165 if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) {
9167 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9168 ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc,
9169 ToAngleBrackets);
9170 } else if (isa<CXXDynamicCastExpr>(E)) {
9172 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9173 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9174 } else if (isa<CXXReinterpretCastExpr>(E)) {
9176 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9177 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9178 } else if (isa<CXXConstCastExpr>(E)) {
9180 Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
9181 ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9182 } else {
9183 llvm_unreachable("Unknown cast type");
9184 return make_error<ASTImportError>();
9185 }
9186}
9187
9190 Error Err = Error::success();
9191 auto ToType = importChecked(Err, E->getType());
9192 auto ToNameLoc = importChecked(Err, E->getNameLoc());
9193 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9194 auto ToReplacement = importChecked(Err, E->getReplacement());
9195 if (Err)
9196 return std::move(Err);
9197
9198 return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
9199 ToType, E->getValueKind(), ToNameLoc, ToReplacement, ToAssociatedDecl,
9201 E->getFinal());
9202}
9203
9205 Error Err = Error::success();
9206 auto ToType = importChecked(Err, E->getType());
9207 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9208 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9209 if (Err)
9210 return std::move(Err);
9211
9213 if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
9214 return std::move(Err);
9215
9216 if (E->isStoredAsBoolean()) {
9217 // According to Sema::BuildTypeTrait(), if E is value-dependent,
9218 // Value is always false.
9219 bool ToValue = (E->isValueDependent() ? false : E->getBoolValue());
9220 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9221 E->getTrait(), ToArgs, ToEndLoc, ToValue);
9222 }
9223 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9224 E->getTrait(), ToArgs, ToEndLoc,
9225 E->getAPValue());
9226}
9227
9229 ExpectedType ToTypeOrErr = import(E->getType());
9230 if (!ToTypeOrErr)
9231 return ToTypeOrErr.takeError();
9232
9233 auto ToSourceRangeOrErr = import(E->getSourceRange());
9234 if (!ToSourceRangeOrErr)
9235 return ToSourceRangeOrErr.takeError();
9236
9237 if (E->isTypeOperand()) {
9238 if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
9239 return new (Importer.getToContext()) CXXTypeidExpr(
9240 *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
9241 else
9242 return ToTSIOrErr.takeError();
9243 }
9244
9245 ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
9246 if (!ToExprOperandOrErr)
9247 return ToExprOperandOrErr.takeError();
9248
9249 return new (Importer.getToContext()) CXXTypeidExpr(
9250 *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
9251}
9252
9254 Error Err = Error::success();
9255
9256 QualType ToType = importChecked(Err, E->getType());
9257 UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
9258 SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
9259 Expr *ToLHS = importChecked(Err, E->getLHS());
9260 SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
9261 Expr *ToRHS = importChecked(Err, E->getRHS());
9262 SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
9263
9264 if (Err)
9265 return std::move(Err);
9266
9267 return new (Importer.getToContext())
9268 CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
9269 ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
9270}
9271
9273 Error Err = Error::success();
9274 auto RequiresKWLoc = importChecked(Err, E->getRequiresKWLoc());
9275 auto RParenLoc = importChecked(Err, E->getRParenLoc());
9276 auto RBraceLoc = importChecked(Err, E->getRBraceLoc());
9277
9278 auto Body = importChecked(Err, E->getBody());
9279 auto LParenLoc = importChecked(Err, E->getLParenLoc());
9280 if (Err)
9281 return std::move(Err);
9282 SmallVector<ParmVarDecl *, 4> LocalParameters(E->getLocalParameters().size());
9283 if (Error Err =
9284 ImportArrayChecked(E->getLocalParameters(), LocalParameters.begin()))
9285 return std::move(Err);
9287 E->getRequirements().size());
9288 if (Error Err =
9289 ImportArrayChecked(E->getRequirements(), Requirements.begin()))
9290 return std::move(Err);
9291 return RequiresExpr::Create(Importer.getToContext(), RequiresKWLoc, Body,
9292 LParenLoc, LocalParameters, RParenLoc,
9293 Requirements, RBraceLoc);
9294}
9295
9298 Error Err = Error::success();
9299 auto CL = importChecked(Err, E->getConceptReference());
9300 auto CSD = importChecked(Err, E->getSpecializationDecl());
9301 if (Err)
9302 return std::move(Err);
9303 if (E->isValueDependent())
9305 Importer.getToContext(), CL,
9306 const_cast<ImplicitConceptSpecializationDecl *>(CSD), nullptr);
9307 ConstraintSatisfaction Satisfaction;
9308 if (Error Err =
9310 return std::move(Err);
9312 Importer.getToContext(), CL,
9313 const_cast<ImplicitConceptSpecializationDecl *>(CSD), &Satisfaction);
9314}
9315
9318 Error Err = Error::success();
9319 auto ToType = importChecked(Err, E->getType());
9320 auto ToPackLoc = importChecked(Err, E->getParameterPackLocation());
9321 auto ToArgPack = importChecked(Err, E->getArgumentPack());
9322 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9323 if (Err)
9324 return std::move(Err);
9325
9326 return new (Importer.getToContext()) SubstNonTypeTemplateParmPackExpr(
9327 ToType, E->getValueKind(), ToPackLoc, ToArgPack, ToAssociatedDecl,
9328 E->getIndex(), E->getFinal());
9329}
9330
9333 if (Error Err = ImportContainerChecked(E->semantics(), ToSemantics))
9334 return std::move(Err);
9335 auto ToSyntOrErr = import(E->getSyntacticForm());
9336 if (!ToSyntOrErr)
9337 return ToSyntOrErr.takeError();
9338 return PseudoObjectExpr::Create(Importer.getToContext(), *ToSyntOrErr,
9339 ToSemantics, E->getResultExprIndex());
9340}
9341
9344 Error Err = Error::success();
9345 auto ToType = importChecked(Err, E->getType());
9346 auto ToInitLoc = importChecked(Err, E->getInitLoc());
9347 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9348 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9349 if (Err)
9350 return std::move(Err);
9351
9352 SmallVector<Expr *, 4> ToArgs(E->getInitExprs().size());
9353 if (Error Err = ImportContainerChecked(E->getInitExprs(), ToArgs))
9354 return std::move(Err);
9355 return CXXParenListInitExpr::Create(Importer.getToContext(), ToArgs, ToType,
9356 E->getUserSpecifiedInitExprs().size(),
9357 ToInitLoc, ToBeginLoc, ToEndLoc);
9358}
9359
9361 CXXMethodDecl *FromMethod) {
9362 Error ImportErrors = Error::success();
9363 for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
9364 if (auto ImportedOrErr = import(FromOverriddenMethod))
9366 (*ImportedOrErr)->getCanonicalDecl()));
9367 else
9368 ImportErrors =
9369 joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
9370 }
9371 return ImportErrors;
9372}
9373
9375 ASTContext &FromContext, FileManager &FromFileManager,
9376 bool MinimalImport,
9377 std::shared_ptr<ASTImporterSharedState> SharedState)
9378 : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
9379 ToFileManager(ToFileManager), FromFileManager(FromFileManager),
9380 Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) {
9381
9382 // Create a default state without the lookup table: LLDB case.
9383 if (!SharedState) {
9384 this->SharedState = std::make_shared<ASTImporterSharedState>();
9385 }
9386
9387 ImportedDecls[FromContext.getTranslationUnitDecl()] =
9388 ToContext.getTranslationUnitDecl();
9389}
9390
9391ASTImporter::~ASTImporter() = default;
9392
9394 assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
9395 "Try to get field index for non-field.");
9396
9397 auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
9398 if (!Owner)
9399 return std::nullopt;
9400
9401 unsigned Index = 0;
9402 for (const auto *D : Owner->decls()) {
9403 if (D == F)
9404 return Index;
9405
9407 ++Index;
9408 }
9409
9410 llvm_unreachable("Field was not found in its parent context.");
9411
9412 return std::nullopt;
9413}
9414
9415ASTImporter::FoundDeclsTy
9416ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
9417 // We search in the redecl context because of transparent contexts.
9418 // E.g. a simple C language enum is a transparent context:
9419 // enum E { A, B };
9420 // Now if we had a global variable in the TU
9421 // int A;
9422 // then the enum constant 'A' and the variable 'A' violates ODR.
9423 // We can diagnose this only if we search in the redecl context.
9424 DeclContext *ReDC = DC->getRedeclContext();
9425 if (SharedState->getLookupTable()) {
9426 if (ReDC->isNamespace()) {
9427 // Namespaces can be reopened.
9428 // Lookup table does not handle this, we must search here in all linked
9429 // namespaces.
9430 FoundDeclsTy Result;
9431 SmallVector<Decl *, 2> NSChain =
9433 dyn_cast<NamespaceDecl>(ReDC));
9434 for (auto *D : NSChain) {
9436 SharedState->getLookupTable()->lookup(dyn_cast<NamespaceDecl>(D),
9437 Name);
9439 }
9440 return Result;
9441 } else {
9443 SharedState->getLookupTable()->lookup(ReDC, Name);
9444 return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
9445 }
9446 } else {
9447 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
9448 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
9449 // We must search by the slow case of localUncachedLookup because that is
9450 // working even if there is no LookupPtr for the DC. We could use
9451 // DC::buildLookup() to create the LookupPtr, but that would load external
9452 // decls again, we must avoid that case.
9453 // Also, even if we had the LookupPtr, we must find Decls which are not
9454 // in the LookupPtr, so we need the slow case.
9455 // These cases are handled in ASTImporterLookupTable, but we cannot use
9456 // that with LLDB since that traverses through the AST which initiates the
9457 // load of external decls again via DC::decls(). And again, we must avoid
9458 // loading external decls during the import.
9459 if (Result.empty())
9460 ReDC->localUncachedLookup(Name, Result);
9461 return Result;
9462 }
9463}
9464
9465void ASTImporter::AddToLookupTable(Decl *ToD) {
9466 SharedState->addDeclToLookup(ToD);
9467}
9468
9470 // Import the decl using ASTNodeImporter.
9471 ASTNodeImporter Importer(*this);
9472 return Importer.Visit(FromD);
9473}
9474
9476 MapImported(FromD, ToD);
9477}
9478
9481 if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) {
9482 if (Expected<Expr *> R = Import(CLE))
9484 }
9485
9486 // FIXME: Handle BlockDecl when we implement importing BlockExpr in
9487 // ASTNodeImporter.
9488 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
9489}
9490
9492 if (!FromT)
9493 return FromT;
9494
9495 // Check whether we've already imported this type.
9496 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
9497 ImportedTypes.find(FromT);
9498 if (Pos != ImportedTypes.end())
9499 return Pos->second;
9500
9501 // Import the type.
9502 ASTNodeImporter Importer(*this);
9503 ExpectedType ToTOrErr = Importer.Visit(FromT);
9504 if (!ToTOrErr)
9505 return ToTOrErr.takeError();
9506
9507 // Record the imported type.
9508 ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9509
9510 return ToTOrErr->getTypePtr();
9511}
9512
9514 if (FromT.isNull())
9515 return QualType{};
9516
9517 ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9518 if (!ToTyOrErr)
9519 return ToTyOrErr.takeError();
9520
9521 return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9522}
9523
9525 if (!FromTSI)
9526 return FromTSI;
9527
9528 // FIXME: For now we just create a "trivial" type source info based
9529 // on the type and a single location. Implement a real version of this.
9530 ExpectedType TOrErr = Import(FromTSI->getType());
9531 if (!TOrErr)
9532 return TOrErr.takeError();
9533 ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9534 if (!BeginLocOrErr)
9535 return BeginLocOrErr.takeError();
9536
9537 return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9538}
9539
9540namespace {
9541// To use this object, it should be created before the new attribute is created,
9542// and destructed after it is created. The construction already performs the
9543// import of the data.
9544template <typename T> struct AttrArgImporter {
9545 AttrArgImporter(const AttrArgImporter<T> &) = delete;
9546 AttrArgImporter(AttrArgImporter<T> &&) = default;
9547 AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9548 AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9549
9550 AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9551 : To(I.importChecked(Err, From)) {}
9552
9553 const T &value() { return To; }
9554
9555private:
9556 T To;
9557};
9558
9559// To use this object, it should be created before the new attribute is created,
9560// and destructed after it is created. The construction already performs the
9561// import of the data. The array data is accessible in a pointer form, this form
9562// is used by the attribute classes. This object should be created once for the
9563// array data to be imported (the array size is not imported, just copied).
9564template <typename T> struct AttrArgArrayImporter {
9565 AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9566 AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9567 AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9568 AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9569
9570 AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9571 const llvm::iterator_range<T *> &From,
9572 unsigned ArraySize) {
9573 if (Err)
9574 return;
9575 To.reserve(ArraySize);
9576 Err = I.ImportContainerChecked(From, To);
9577 }
9578
9579 T *value() { return To.data(); }
9580
9581private:
9582 llvm::SmallVector<T, 2> To;
9583};
9584
9585class AttrImporter {
9586 Error Err{Error::success()};
9587 Attr *ToAttr = nullptr;
9588 ASTImporter &Importer;
9589 ASTNodeImporter NImporter;
9590
9591public:
9592 AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9593
9594 // Useful for accessing the imported attribute.
9595 template <typename T> T *castAttrAs() { return cast<T>(ToAttr); }
9596 template <typename T> const T *castAttrAs() const { return cast<T>(ToAttr); }
9597
9598 // Create an "importer" for an attribute parameter.
9599 // Result of the 'value()' of that object is to be passed to the function
9600 // 'importAttr', in the order that is expected by the attribute class.
9601 template <class T> AttrArgImporter<T> importArg(const T &From) {
9602 return AttrArgImporter<T>(NImporter, Err, From);
9603 }
9604
9605 // Create an "importer" for an attribute parameter that has array type.
9606 // Result of the 'value()' of that object is to be passed to the function
9607 // 'importAttr', then the size of the array as next argument.
9608 template <typename T>
9609 AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9610 unsigned ArraySize) {
9611 return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9612 }
9613
9614 // Create an attribute object with the specified arguments.
9615 // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9616 // should be values that are passed to the 'Create' function of the attribute.
9617 // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9618 // used here.) As much data is copied or imported from the old attribute
9619 // as possible. The passed arguments should be already imported.
9620 // If an import error happens, the internal error is set to it, and any
9621 // further import attempt is ignored.
9622 template <typename T, typename... Arg>
9623 void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9624 static_assert(std::is_base_of<Attr, T>::value,
9625 "T should be subclass of Attr.");
9626 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9627
9628 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9629 const IdentifierInfo *ToScopeName =
9630 Importer.Import(FromAttr->getScopeName());
9631 SourceRange ToAttrRange =
9632 NImporter.importChecked(Err, FromAttr->getRange());
9633 SourceLocation ToScopeLoc =
9634 NImporter.importChecked(Err, FromAttr->getScopeLoc());
9635
9636 if (Err)
9637 return;
9638
9639 AttributeCommonInfo ToI(
9640 ToAttrName, AttributeScopeInfo(ToScopeName, ToScopeLoc), ToAttrRange,
9641 FromAttr->getParsedKind(), FromAttr->getForm());
9642 // The "SemanticSpelling" is not needed to be passed to the constructor.
9643 // That value is recalculated from the SpellingListIndex if needed.
9644 ToAttr = T::Create(Importer.getToContext(),
9645 std::forward<Arg>(ImportedArg)..., ToI);
9646
9647 ToAttr->setImplicit(FromAttr->isImplicit());
9648 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9649 if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9650 ToInheritableAttr->setInherited(FromAttr->isInherited());
9651 }
9652
9653 // Create a clone of the 'FromAttr' and import its source range only.
9654 // This causes objects with invalid references to be created if the 'FromAttr'
9655 // contains other data that should be imported.
9656 void cloneAttr(const Attr *FromAttr) {
9657 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9658
9659 SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9660 if (Err)
9661 return;
9662
9663 ToAttr = FromAttr->clone(Importer.getToContext());
9664 ToAttr->setRange(ToRange);
9665 ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9666 }
9667
9668 // Get the result of the previous import attempt (can be used only once).
9669 llvm::Expected<Attr *> getResult() && {
9670 if (Err)
9671 return std::move(Err);
9672 assert(ToAttr && "Attribute should be created.");
9673 return ToAttr;
9674 }
9675};
9676} // namespace
9677
9679 AttrImporter AI(*this);
9680
9681 // FIXME: Is there some kind of AttrVisitor to use here?
9682 switch (FromAttr->getKind()) {
9683 case attr::Aligned: {
9684 auto *From = cast<AlignedAttr>(FromAttr);
9685 if (From->isAlignmentExpr())
9686 AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9687 else
9688 AI.importAttr(From, false,
9689 AI.importArg(From->getAlignmentType()).value());
9690 break;
9691 }
9692
9693 case attr::AlignValue: {
9694 auto *From = cast<AlignValueAttr>(FromAttr);
9695 AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9696 break;
9697 }
9698
9699 case attr::Format: {
9700 const auto *From = cast<FormatAttr>(FromAttr);
9701 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9702 From->getFirstArg());
9703 break;
9704 }
9705
9706 case attr::EnableIf: {
9707 const auto *From = cast<EnableIfAttr>(FromAttr);
9708 AI.importAttr(From, AI.importArg(From->getCond()).value(),
9709 From->getMessage());
9710 break;
9711 }
9712
9713 case attr::AssertCapability: {
9714 const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9715 AI.importAttr(From,
9716 AI.importArrayArg(From->args(), From->args_size()).value(),
9717 From->args_size());
9718 break;
9719 }
9720 case attr::AcquireCapability: {
9721 const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9722 AI.importAttr(From,
9723 AI.importArrayArg(From->args(), From->args_size()).value(),
9724 From->args_size());
9725 break;
9726 }
9727 case attr::TryAcquireCapability: {
9728 const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9729 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9730 AI.importArrayArg(From->args(), From->args_size()).value(),
9731 From->args_size());
9732 break;
9733 }
9734 case attr::ReleaseCapability: {
9735 const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9736 AI.importAttr(From,
9737 AI.importArrayArg(From->args(), From->args_size()).value(),
9738 From->args_size());
9739 break;
9740 }
9741 case attr::RequiresCapability: {
9742 const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9743 AI.importAttr(From,
9744 AI.importArrayArg(From->args(), From->args_size()).value(),
9745 From->args_size());
9746 break;
9747 }
9748 case attr::GuardedBy: {
9749 const auto *From = cast<GuardedByAttr>(FromAttr);
9750 AI.importAttr(From, AI.importArg(From->getArg()).value());
9751 break;
9752 }
9753 case attr::PtGuardedBy: {
9754 const auto *From = cast<PtGuardedByAttr>(FromAttr);
9755 AI.importAttr(From, AI.importArg(From->getArg()).value());
9756 break;
9757 }
9758 case attr::AcquiredAfter: {
9759 const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9760 AI.importAttr(From,
9761 AI.importArrayArg(From->args(), From->args_size()).value(),
9762 From->args_size());
9763 break;
9764 }
9765 case attr::AcquiredBefore: {
9766 const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9767 AI.importAttr(From,
9768 AI.importArrayArg(From->args(), From->args_size()).value(),
9769 From->args_size());
9770 break;
9771 }
9772 case attr::LockReturned: {
9773 const auto *From = cast<LockReturnedAttr>(FromAttr);
9774 AI.importAttr(From, AI.importArg(From->getArg()).value());
9775 break;
9776 }
9777 case attr::LocksExcluded: {
9778 const auto *From = cast<LocksExcludedAttr>(FromAttr);
9779 AI.importAttr(From,
9780 AI.importArrayArg(From->args(), From->args_size()).value(),
9781 From->args_size());
9782 break;
9783 }
9784 default: {
9785 // The default branch works for attributes that have no arguments to import.
9786 // FIXME: Handle every attribute type that has arguments of type to import
9787 // (most often Expr* or Decl* or type) in the switch above.
9788 AI.cloneAttr(FromAttr);
9789 break;
9790 }
9791 }
9792
9793 return std::move(AI).getResult();
9794}
9795
9797 return ImportedDecls.lookup(FromD);
9798}
9799
9801 auto FromDPos = ImportedFromDecls.find(ToD);
9802 if (FromDPos == ImportedFromDecls.end())
9803 return nullptr;
9804 return FromDPos->second->getTranslationUnitDecl();
9805}
9806
9808 if (!FromD)
9809 return nullptr;
9810
9811 // Push FromD to the stack, and remove that when we return.
9812 ImportPath.push(FromD);
9813 llvm::scope_exit ImportPathBuilder([this]() { ImportPath.pop(); });
9814
9815 // Check whether there was a previous failed import.
9816 // If yes return the existing error.
9817 if (auto Error = getImportDeclErrorIfAny(FromD))
9818 return make_error<ASTImportError>(*Error);
9819
9820 // Check whether we've already imported this declaration.
9821 Decl *ToD = GetAlreadyImportedOrNull(FromD);
9822 if (ToD) {
9823 // Already imported (possibly from another TU) and with an error.
9824 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9825 setImportDeclError(FromD, *Error);
9826 return make_error<ASTImportError>(*Error);
9827 }
9828
9829 // If FromD has some updated flags after last import, apply it.
9830 updateFlags(FromD, ToD);
9831 // If we encounter a cycle during an import then we save the relevant part
9832 // of the import path associated to the Decl.
9833 if (ImportPath.hasCycleAtBack())
9834 SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9835 return ToD;
9836 }
9837
9838 // Import the declaration.
9839 ExpectedDecl ToDOrErr = ImportImpl(FromD);
9840 if (!ToDOrErr) {
9841 // Failed to import.
9842
9843 auto Pos = ImportedDecls.find(FromD);
9844 if (Pos != ImportedDecls.end()) {
9845 // Import failed after the object was created.
9846 // Remove all references to it.
9847 auto *ToD = Pos->second;
9848 ImportedDecls.erase(Pos);
9849
9850 // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9851 // (e.g. with namespaces) that several decls from the 'from' context are
9852 // mapped to the same decl in the 'to' context. If we removed entries
9853 // from the LookupTable here then we may end up removing them multiple
9854 // times.
9855
9856 // The Lookuptable contains decls only which are in the 'to' context.
9857 // Remove from the Lookuptable only if it is *imported* into the 'to'
9858 // context (and do not remove it if it was added during the initial
9859 // traverse of the 'to' context).
9860 auto PosF = ImportedFromDecls.find(ToD);
9861 if (PosF != ImportedFromDecls.end()) {
9862 // In the case of TypedefNameDecl we create the Decl first and only
9863 // then we import and set its DeclContext. So, the DC might not be set
9864 // when we reach here.
9865 if (ToD->getDeclContext())
9866 SharedState->removeDeclFromLookup(ToD);
9867 ImportedFromDecls.erase(PosF);
9868 }
9869
9870 // FIXME: AST may contain remaining references to the failed object.
9871 // However, the ImportDeclErrors in the shared state contains all the
9872 // failed objects together with their error.
9873 }
9874
9875 // Error encountered for the first time.
9876 // After takeError the error is not usable any more in ToDOrErr.
9877 // Get a copy of the error object (any more simple solution for this?).
9878 ASTImportError ErrOut;
9879 handleAllErrors(ToDOrErr.takeError(),
9880 [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9881 setImportDeclError(FromD, ErrOut);
9882 // Set the error for the mapped to Decl, which is in the "to" context.
9883 if (Pos != ImportedDecls.end())
9884 SharedState->setImportDeclError(Pos->second, ErrOut);
9885
9886 // Set the error for all nodes which have been created before we
9887 // recognized the error.
9888 for (const auto &Path : SavedImportPaths[FromD]) {
9889 // The import path contains import-dependency nodes first.
9890 // Save the node that was imported as dependency of the current node.
9891 Decl *PrevFromDi = FromD;
9892 for (Decl *FromDi : Path) {
9893 // Begin and end of the path equals 'FromD', skip it.
9894 if (FromDi == FromD)
9895 continue;
9896 // We should not set import error on a node and all following nodes in
9897 // the path if child import errors are ignored.
9898 if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9899 PrevFromDi))
9900 break;
9901 PrevFromDi = FromDi;
9902 setImportDeclError(FromDi, ErrOut);
9903 //FIXME Should we remove these Decls from ImportedDecls?
9904 // Set the error for the mapped to Decl, which is in the "to" context.
9905 auto Ii = ImportedDecls.find(FromDi);
9906 if (Ii != ImportedDecls.end())
9907 SharedState->setImportDeclError(Ii->second, ErrOut);
9908 // FIXME Should we remove these Decls from the LookupTable,
9909 // and from ImportedFromDecls?
9910 }
9911 }
9912 SavedImportPaths.erase(FromD);
9913
9914 // Do not return ToDOrErr, error was taken out of it.
9915 return make_error<ASTImportError>(ErrOut);
9916 }
9917
9918 ToD = *ToDOrErr;
9919
9920 // FIXME: Handle the "already imported with error" case. We can get here
9921 // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
9922 // previously failed create was requested).
9923 // Later GetImportedOrCreateDecl can be updated to return the error.
9924 if (!ToD) {
9925 auto Err = getImportDeclErrorIfAny(FromD);
9926 assert(Err);
9927 return make_error<ASTImportError>(*Err);
9928 }
9929
9930 // We could import from the current TU without error. But previously we
9931 // already had imported a Decl as `ToD` from another TU (with another
9932 // ASTImporter object) and with an error.
9933 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9934 setImportDeclError(FromD, *Error);
9935 return make_error<ASTImportError>(*Error);
9936 }
9937 // Make sure that ImportImpl registered the imported decl.
9938 assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
9939
9940 if (FromD->hasAttrs())
9941 for (const Attr *FromAttr : FromD->getAttrs()) {
9942 auto ToAttrOrErr = Import(FromAttr);
9943 if (ToAttrOrErr)
9944 ToD->addAttr(*ToAttrOrErr);
9945 else
9946 return ToAttrOrErr.takeError();
9947 }
9948
9949 // Notify subclasses.
9950 Imported(FromD, ToD);
9951
9952 updateFlags(FromD, ToD);
9953 SavedImportPaths.erase(FromD);
9954 return ToDOrErr;
9955}
9956
9959 return ASTNodeImporter(*this).ImportInheritedConstructor(From);
9960}
9961
9963 if (!FromDC)
9964 return FromDC;
9965
9966 ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
9967 if (!ToDCOrErr)
9968 return ToDCOrErr.takeError();
9969 auto *ToDC = cast<DeclContext>(*ToDCOrErr);
9970
9971 // When we're using a record/enum/Objective-C class/protocol as a context, we
9972 // need it to have a definition.
9973 if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
9974 auto *FromRecord = cast<RecordDecl>(FromDC);
9975 if (ToRecord->isCompleteDefinition())
9976 return ToDC;
9977
9978 // If FromRecord is not defined we need to force it to be.
9979 // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
9980 // it will start the definition but we never finish it.
9981 // If there are base classes they won't be imported and we will
9982 // be missing anything that we inherit from those bases.
9983 if (FromRecord->getASTContext().getExternalSource() &&
9984 !FromRecord->isCompleteDefinition())
9985 FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
9986
9987 if (FromRecord->isCompleteDefinition())
9988 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9989 FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
9990 return std::move(Err);
9991 } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
9992 auto *FromEnum = cast<EnumDecl>(FromDC);
9993 if (ToEnum->isCompleteDefinition()) {
9994 // Do nothing.
9995 } else if (FromEnum->isCompleteDefinition()) {
9996 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9997 FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
9998 return std::move(Err);
9999 } else {
10000 CompleteDecl(ToEnum);
10001 }
10002 } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
10003 auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
10004 if (ToClass->getDefinition()) {
10005 // Do nothing.
10006 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
10007 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10008 FromDef, ToClass, ASTNodeImporter::IDK_Basic))
10009 return std::move(Err);
10010 } else {
10011 CompleteDecl(ToClass);
10012 }
10013 } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
10014 auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
10015 if (ToProto->getDefinition()) {
10016 // Do nothing.
10017 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
10018 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10019 FromDef, ToProto, ASTNodeImporter::IDK_Basic))
10020 return std::move(Err);
10021 } else {
10022 CompleteDecl(ToProto);
10023 }
10024 }
10025
10026 return ToDC;
10027}
10028
10030 if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
10031 return cast_or_null<Expr>(*ToSOrErr);
10032 else
10033 return ToSOrErr.takeError();
10034}
10035
10037 if (!FromS)
10038 return nullptr;
10039
10040 // Check whether we've already imported this statement.
10041 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
10042 if (Pos != ImportedStmts.end())
10043 return Pos->second;
10044
10045 // Import the statement.
10046 ASTNodeImporter Importer(*this);
10047 ExpectedStmt ToSOrErr = Importer.Visit(FromS);
10048 if (!ToSOrErr)
10049 return ToSOrErr;
10050
10051 if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
10052 auto *FromE = cast<Expr>(FromS);
10053 // Copy ExprBitfields, which may not be handled in Expr subclasses
10054 // constructors.
10055 ToE->setValueKind(FromE->getValueKind());
10056 ToE->setObjectKind(FromE->getObjectKind());
10057 ToE->setDependence(FromE->getDependence());
10058 }
10059
10060 // Record the imported statement object.
10061 ImportedStmts[FromS] = *ToSOrErr;
10062 return ToSOrErr;
10063}
10064
10066 switch (FromNNS.getKind()) {
10069 return FromNNS;
10071 auto [Namespace, Prefix] = FromNNS.getAsNamespaceAndPrefix();
10072 auto NSOrErr = Import(Namespace);
10073 if (!NSOrErr)
10074 return NSOrErr.takeError();
10075 auto PrefixOrErr = Import(Prefix);
10076 if (!PrefixOrErr)
10077 return PrefixOrErr.takeError();
10078 return NestedNameSpecifier(ToContext, cast<NamespaceBaseDecl>(*NSOrErr),
10079 *PrefixOrErr);
10080 }
10082 if (ExpectedDecl RDOrErr = Import(FromNNS.getAsMicrosoftSuper()))
10083 return NestedNameSpecifier(cast<CXXRecordDecl>(*RDOrErr));
10084 else
10085 return RDOrErr.takeError();
10087 if (ExpectedTypePtr TyOrErr = Import(FromNNS.getAsType())) {
10088 return NestedNameSpecifier(*TyOrErr);
10089 } else {
10090 return TyOrErr.takeError();
10091 }
10092 }
10093 llvm_unreachable("Invalid nested name specifier kind");
10094}
10095
10098 // Copied from NestedNameSpecifier mostly.
10100 NestedNameSpecifierLoc NNS = FromNNS;
10101
10102 // Push each of the nested-name-specifiers's onto a stack for
10103 // serialization in reverse order.
10104 while (NNS) {
10105 NestedNames.push_back(NNS);
10106 NNS = NNS.getAsNamespaceAndPrefix().Prefix;
10107 }
10108
10110
10111 while (!NestedNames.empty()) {
10112 NNS = NestedNames.pop_back_val();
10113 NestedNameSpecifier Spec = std::nullopt;
10114 if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
10115 return std::move(Err);
10116
10117 NestedNameSpecifier::Kind Kind = Spec.getKind();
10118
10119 SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
10121 if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
10122 return std::move(Err);
10123
10125 if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
10126 return std::move(Err);
10127 }
10128
10129 switch (Kind) {
10131 Builder.Extend(getToContext(), Spec.getAsNamespaceAndPrefix().Namespace,
10132 ToLocalBeginLoc, ToLocalEndLoc);
10133 break;
10134
10136 SourceLocation ToTLoc;
10137 if (Error Err = importInto(ToTLoc, NNS.castAsTypeLoc().getBeginLoc()))
10138 return std::move(Err);
10140 QualType(Spec.getAsType(), 0), ToTLoc);
10141 Builder.Make(getToContext(), TSI->getTypeLoc(), ToLocalEndLoc);
10142 break;
10143 }
10144
10146 Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
10147 break;
10148
10150 auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
10151 if (!ToSourceRangeOrErr)
10152 return ToSourceRangeOrErr.takeError();
10153
10154 Builder.MakeMicrosoftSuper(getToContext(), Spec.getAsMicrosoftSuper(),
10155 ToSourceRangeOrErr->getBegin(),
10156 ToSourceRangeOrErr->getEnd());
10157 break;
10158 }
10160 llvm_unreachable("unexpected null nested name specifier");
10161 }
10162 }
10163
10164 return Builder.getWithLocInContext(getToContext());
10165}
10166
10168 switch (From.getKind()) {
10170 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
10171 return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
10172 else
10173 return ToTemplateOrErr.takeError();
10174
10177 UnresolvedSet<2> ToTemplates;
10178 for (auto *I : *FromStorage) {
10179 if (auto ToOrErr = Import(I))
10180 ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
10181 else
10182 return ToOrErr.takeError();
10183 }
10184 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
10185 ToTemplates.end());
10186 }
10187
10190 auto DeclNameOrErr = Import(FromStorage->getDeclName());
10191 if (!DeclNameOrErr)
10192 return DeclNameOrErr.takeError();
10193 return ToContext.getAssumedTemplateName(*DeclNameOrErr);
10194 }
10195
10198 auto QualifierOrErr = Import(QTN->getQualifier());
10199 if (!QualifierOrErr)
10200 return QualifierOrErr.takeError();
10201 auto TNOrErr = Import(QTN->getUnderlyingTemplate());
10202 if (!TNOrErr)
10203 return TNOrErr.takeError();
10204 return ToContext.getQualifiedTemplateName(
10205 *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
10206 }
10207
10210 auto QualifierOrErr = Import(DTN->getQualifier());
10211 if (!QualifierOrErr)
10212 return QualifierOrErr.takeError();
10213 return ToContext.getDependentTemplateName(
10214 {*QualifierOrErr, Import(DTN->getName()), DTN->hasTemplateKeyword()});
10215 }
10216
10220 auto ReplacementOrErr = Import(Subst->getReplacement());
10221 if (!ReplacementOrErr)
10222 return ReplacementOrErr.takeError();
10223
10224 auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
10225 if (!AssociatedDeclOrErr)
10226 return AssociatedDeclOrErr.takeError();
10227
10228 return ToContext.getSubstTemplateTemplateParm(
10229 *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
10230 Subst->getPackIndex(), Subst->getFinal());
10231 }
10232
10236 ASTNodeImporter Importer(*this);
10237 auto ArgPackOrErr =
10238 Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
10239 if (!ArgPackOrErr)
10240 return ArgPackOrErr.takeError();
10241
10242 auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
10243 if (!AssociatedDeclOrErr)
10244 return AssociatedDeclOrErr.takeError();
10245
10246 return ToContext.getSubstTemplateTemplateParmPack(
10247 *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
10248 SubstPack->getFinal());
10249 }
10251 auto UsingOrError = Import(From.getAsUsingShadowDecl());
10252 if (!UsingOrError)
10253 return UsingOrError.takeError();
10254 return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
10255 }
10257 llvm_unreachable("Unexpected DeducedTemplate");
10258 }
10259
10260 llvm_unreachable("Invalid template name kind");
10261}
10262
10264 if (FromLoc.isInvalid())
10265 return SourceLocation{};
10266
10267 SourceManager &FromSM = FromContext.getSourceManager();
10268 bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
10269
10270 FileIDAndOffset Decomposed = FromSM.getDecomposedLoc(FromLoc);
10271 Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
10272 if (!ToFileIDOrErr)
10273 return ToFileIDOrErr.takeError();
10274 SourceManager &ToSM = ToContext.getSourceManager();
10275 return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
10276}
10277
10279 SourceLocation ToBegin, ToEnd;
10280 if (Error Err = importInto(ToBegin, FromRange.getBegin()))
10281 return std::move(Err);
10282 if (Error Err = importInto(ToEnd, FromRange.getEnd()))
10283 return std::move(Err);
10284
10285 return SourceRange(ToBegin, ToEnd);
10286}
10287
10289 llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
10290 if (Pos != ImportedFileIDs.end())
10291 return Pos->second;
10292
10293 SourceManager &FromSM = FromContext.getSourceManager();
10294 SourceManager &ToSM = ToContext.getSourceManager();
10295 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
10296
10297 // Map the FromID to the "to" source manager.
10298 FileID ToID;
10299 if (FromSLoc.isExpansion()) {
10300 const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
10301 ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
10302 if (!ToSpLoc)
10303 return ToSpLoc.takeError();
10304 ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
10305 if (!ToExLocS)
10306 return ToExLocS.takeError();
10307 unsigned ExLength = FromSM.getFileIDSize(FromID);
10308 SourceLocation MLoc;
10309 if (FromEx.isMacroArgExpansion()) {
10310 MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
10311 } else {
10312 if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
10313 MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
10314 FromEx.isExpansionTokenRange());
10315 else
10316 return ToExLocE.takeError();
10317 }
10318 ToID = ToSM.getFileID(MLoc);
10319 } else {
10320 const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
10321
10322 if (!IsBuiltin && !Cache->BufferOverridden) {
10323 // Include location of this file.
10324 ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
10325 if (!ToIncludeLoc)
10326 return ToIncludeLoc.takeError();
10327
10328 // Every FileID that is not the main FileID needs to have a valid include
10329 // location so that the include chain points to the main FileID. When
10330 // importing the main FileID (which has no include location), we need to
10331 // create a fake include location in the main file to keep this property
10332 // intact.
10333 SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
10334 if (FromID == FromSM.getMainFileID())
10335 ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
10336
10337 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
10338 // FIXME: We probably want to use getVirtualFileRef(), so we don't hit
10339 // the disk again
10340 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
10341 // than mmap the files several times.
10342 auto Entry =
10343 ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
10344 // FIXME: The filename may be a virtual name that does probably not
10345 // point to a valid file and we get no Entry here. In this case try with
10346 // the memory buffer below.
10347 if (Entry)
10348 ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
10349 FromSLoc.getFile().getFileCharacteristic());
10350 }
10351 }
10352
10353 if (ToID.isInvalid() || IsBuiltin) {
10354 // FIXME: We want to re-use the existing MemoryBuffer!
10355 std::optional<llvm::MemoryBufferRef> FromBuf =
10356 Cache->getBufferOrNone(FromContext.getDiagnostics(),
10357 FromSM.getFileManager(), SourceLocation{});
10358 if (!FromBuf)
10359 return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
10360
10361 std::unique_ptr<llvm::MemoryBuffer> ToBuf =
10362 llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
10363 FromBuf->getBufferIdentifier());
10364 ToID = ToSM.createFileID(std::move(ToBuf),
10365 FromSLoc.getFile().getFileCharacteristic());
10366 }
10367 }
10368
10369 assert(ToID.isValid() && "Unexpected invalid fileID was created.");
10370
10371 ImportedFileIDs[FromID] = ToID;
10372 return ToID;
10373}
10374
10376 ExpectedExpr ToExprOrErr = Import(From->getInit());
10377 if (!ToExprOrErr)
10378 return ToExprOrErr.takeError();
10379
10380 auto LParenLocOrErr = Import(From->getLParenLoc());
10381 if (!LParenLocOrErr)
10382 return LParenLocOrErr.takeError();
10383
10384 auto RParenLocOrErr = Import(From->getRParenLoc());
10385 if (!RParenLocOrErr)
10386 return RParenLocOrErr.takeError();
10387
10388 if (From->isBaseInitializer()) {
10389 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10390 if (!ToTInfoOrErr)
10391 return ToTInfoOrErr.takeError();
10392
10393 SourceLocation EllipsisLoc;
10394 if (From->isPackExpansion())
10395 if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
10396 return std::move(Err);
10397
10398 return new (ToContext) CXXCtorInitializer(
10399 ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
10400 *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
10401 } else if (From->isMemberInitializer()) {
10402 ExpectedDecl ToFieldOrErr = Import(From->getMember());
10403 if (!ToFieldOrErr)
10404 return ToFieldOrErr.takeError();
10405
10406 auto MemberLocOrErr = Import(From->getMemberLocation());
10407 if (!MemberLocOrErr)
10408 return MemberLocOrErr.takeError();
10409
10410 return new (ToContext) CXXCtorInitializer(
10411 ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
10412 *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10413 } else if (From->isIndirectMemberInitializer()) {
10414 ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
10415 if (!ToIFieldOrErr)
10416 return ToIFieldOrErr.takeError();
10417
10418 auto MemberLocOrErr = Import(From->getMemberLocation());
10419 if (!MemberLocOrErr)
10420 return MemberLocOrErr.takeError();
10421
10422 return new (ToContext) CXXCtorInitializer(
10423 ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10424 *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10425 } else if (From->isDelegatingInitializer()) {
10426 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10427 if (!ToTInfoOrErr)
10428 return ToTInfoOrErr.takeError();
10429
10430 return new (ToContext)
10431 CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10432 *ToExprOrErr, *RParenLocOrErr);
10433 } else {
10434 // FIXME: assert?
10435 return make_error<ASTImportError>();
10436 }
10437}
10438
10441 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10442 if (Pos != ImportedCXXBaseSpecifiers.end())
10443 return Pos->second;
10444
10445 Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10446 if (!ToSourceRange)
10447 return ToSourceRange.takeError();
10449 if (!ToTSI)
10450 return ToTSI.takeError();
10451 ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10452 if (!ToEllipsisLoc)
10453 return ToEllipsisLoc.takeError();
10454 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10455 *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10456 BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10457 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10458 return Imported;
10459}
10460
10462 ASTNodeImporter Importer(*this);
10463 return Importer.ImportAPValue(FromValue);
10464}
10465
10467 ExpectedDecl ToOrErr = Import(From);
10468 if (!ToOrErr)
10469 return ToOrErr.takeError();
10470 Decl *To = *ToOrErr;
10471
10472 auto *FromDC = cast<DeclContext>(From);
10473 ASTNodeImporter Importer(*this);
10474
10475 if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10476 if (!ToRecord->getDefinition()) {
10477 return Importer.ImportDefinition(
10478 cast<RecordDecl>(FromDC), ToRecord,
10480 }
10481 }
10482
10483 if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10484 if (!ToEnum->getDefinition()) {
10485 return Importer.ImportDefinition(
10487 }
10488 }
10489
10490 if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10491 if (!ToIFace->getDefinition()) {
10492 return Importer.ImportDefinition(
10493 cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10495 }
10496 }
10497
10498 if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10499 if (!ToProto->getDefinition()) {
10500 return Importer.ImportDefinition(
10501 cast<ObjCProtocolDecl>(FromDC), ToProto,
10503 }
10504 }
10505
10506 return Importer.ImportDeclContext(FromDC, true);
10507}
10508
10510 if (!FromName)
10511 return DeclarationName{};
10512
10513 switch (FromName.getNameKind()) {
10515 return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10516
10520 if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10521 return DeclarationName(*ToSelOrErr);
10522 else
10523 return ToSelOrErr.takeError();
10524
10526 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10527 return ToContext.DeclarationNames.getCXXConstructorName(
10528 ToContext.getCanonicalType(*ToTyOrErr));
10529 else
10530 return ToTyOrErr.takeError();
10531 }
10532
10534 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10535 return ToContext.DeclarationNames.getCXXDestructorName(
10536 ToContext.getCanonicalType(*ToTyOrErr));
10537 else
10538 return ToTyOrErr.takeError();
10539 }
10540
10542 if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10543 return ToContext.DeclarationNames.getCXXDeductionGuideName(
10544 cast<TemplateDecl>(*ToTemplateOrErr));
10545 else
10546 return ToTemplateOrErr.takeError();
10547 }
10548
10550 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10551 return ToContext.DeclarationNames.getCXXConversionFunctionName(
10552 ToContext.getCanonicalType(*ToTyOrErr));
10553 else
10554 return ToTyOrErr.takeError();
10555 }
10556
10558 return ToContext.DeclarationNames.getCXXOperatorName(
10559 FromName.getCXXOverloadedOperator());
10560
10562 return ToContext.DeclarationNames.getCXXLiteralOperatorName(
10563 Import(FromName.getCXXLiteralIdentifier()));
10564
10566 // FIXME: STATICS!
10568 }
10569
10570 llvm_unreachable("Invalid DeclarationName Kind!");
10571}
10572
10574 if (!FromId)
10575 return nullptr;
10576
10577 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10578
10579 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10580 ToId->setBuiltinID(FromId->getBuiltinID());
10581
10582 return ToId;
10583}
10584
10587 if (const IdentifierInfo *FromII = FromIO.getIdentifier())
10588 return Import(FromII);
10589 return FromIO.getOperator();
10590}
10591
10593 if (FromSel.isNull())
10594 return Selector{};
10595
10597 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10598 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10599 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10600 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10601}
10602
10606 llvm::Error Err = llvm::Error::success();
10607 auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10608 for (unsigned Idx = 0; Idx < Size; Idx++) {
10609 APValue Tmp = importChecked(Err, From[Idx]);
10610 To[Idx] = Tmp;
10611 }
10612 };
10613 switch (FromValue.getKind()) {
10614 case APValue::None:
10616 case APValue::Int:
10617 case APValue::Float:
10621 Result = FromValue;
10622 break;
10623 case APValue::Vector: {
10624 Result.MakeVector();
10626 Result.setVectorUninit(FromValue.getVectorLength());
10627 ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10628 Elts.data(), FromValue.getVectorLength());
10629 break;
10630 }
10631 case APValue::Array:
10632 Result.MakeArray(FromValue.getArrayInitializedElts(),
10633 FromValue.getArraySize());
10634 ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10635 ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10636 FromValue.getArrayInitializedElts());
10637 break;
10638 case APValue::Struct:
10639 Result.MakeStruct(FromValue.getStructNumBases(),
10640 FromValue.getStructNumFields());
10641 ImportLoop(
10642 ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10643 ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10644 FromValue.getStructNumBases() + FromValue.getStructNumFields());
10645 break;
10646 case APValue::Union: {
10647 Result.MakeUnion();
10648 const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10649 APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10650 if (Err)
10651 return std::move(Err);
10652 Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10653 break;
10654 }
10656 Result.MakeAddrLabelDiff();
10657 const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10658 const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10659 if (Err)
10660 return std::move(Err);
10661 Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10662 cast<AddrLabelExpr>(ImpRHS));
10663 break;
10664 }
10666 const Decl *ImpMemPtrDecl =
10667 importChecked(Err, FromValue.getMemberPointerDecl());
10668 if (Err)
10669 return std::move(Err);
10671 Result.setMemberPointerUninit(
10672 cast<const ValueDecl>(ImpMemPtrDecl),
10674 FromValue.getMemberPointerPath().size());
10675 ArrayRef<const CXXRecordDecl *> FromPath = Result.getMemberPointerPath();
10676 for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10677 Idx++) {
10678 const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10679 if (Err)
10680 return std::move(Err);
10681 ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10682 }
10683 break;
10684 }
10685 case APValue::LValue:
10687 QualType FromElemTy;
10688 if (FromValue.getLValueBase()) {
10689 assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10690 "in C++20 dynamic allocation are transient so they shouldn't "
10691 "appear in the AST");
10692 if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10693 if (const auto *E =
10694 FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10695 FromElemTy = E->getType();
10696 const Expr *ImpExpr = importChecked(Err, E);
10697 if (Err)
10698 return std::move(Err);
10699 Base = APValue::LValueBase(ImpExpr,
10700 FromValue.getLValueBase().getCallIndex(),
10701 FromValue.getLValueBase().getVersion());
10702 } else {
10703 FromElemTy =
10704 FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10705 const Decl *ImpDecl = importChecked(
10706 Err, FromValue.getLValueBase().get<const ValueDecl *>());
10707 if (Err)
10708 return std::move(Err);
10710 FromValue.getLValueBase().getCallIndex(),
10711 FromValue.getLValueBase().getVersion());
10712 }
10713 } else {
10714 FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10715 const Type *ImpTypeInfo = importChecked(
10716 Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10717 QualType ImpType =
10718 importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10719 if (Err)
10720 return std::move(Err);
10722 ImpType);
10723 }
10724 }
10725 CharUnits Offset = FromValue.getLValueOffset();
10726 unsigned PathLength = FromValue.getLValuePath().size();
10727 Result.MakeLValue();
10728 if (FromValue.hasLValuePath()) {
10729 MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10730 Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10731 FromValue.isNullPointer());
10733 for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10734 if (FromElemTy->isRecordType()) {
10735 const Decl *FromDecl =
10736 FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10737 const Decl *ImpDecl = importChecked(Err, FromDecl);
10738 if (Err)
10739 return std::move(Err);
10740 if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10741 FromElemTy = Importer.FromContext.getCanonicalTagType(RD);
10742 else
10743 FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10745 ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10746 } else {
10747 FromElemTy =
10748 Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10749 ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10750 FromPath[LoopIdx].getAsArrayIndex());
10751 }
10752 }
10753 } else
10754 Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10755 FromValue.isNullPointer());
10756 }
10757 if (Err)
10758 return std::move(Err);
10759 return Result;
10760}
10761
10763 DeclContext *DC,
10764 unsigned IDNS,
10765 NamedDecl **Decls,
10766 unsigned NumDecls) {
10767 if (ODRHandling == ODRHandlingType::Conservative)
10768 // Report error at any name conflict.
10769 return make_error<ASTImportError>(ASTImportError::NameConflict);
10770 else
10771 // Allow to create the new Decl with the same name.
10772 return Name;
10773}
10774
10776 if (LastDiagFromFrom)
10777 ToContext.getDiagnostics().notePriorDiagnosticFrom(
10778 FromContext.getDiagnostics());
10779 LastDiagFromFrom = false;
10780 return ToContext.getDiagnostics().Report(Loc, DiagID);
10781}
10782
10784 if (!LastDiagFromFrom)
10785 FromContext.getDiagnostics().notePriorDiagnosticFrom(
10786 ToContext.getDiagnostics());
10787 LastDiagFromFrom = true;
10788 return FromContext.getDiagnostics().Report(Loc, DiagID);
10789}
10790
10792 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10793 if (!ID->getDefinition())
10794 ID->startDefinition();
10795 }
10796 else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10797 if (!PD->getDefinition())
10798 PD->startDefinition();
10799 }
10800 else if (auto *TD = dyn_cast<TagDecl>(D)) {
10801 if (!TD->getDefinition() && !TD->isBeingDefined()) {
10802 TD->startDefinition();
10803 TD->setCompleteDefinition(true);
10804 }
10805 }
10806 else {
10807 assert(0 && "CompleteDecl called on a Decl that can't be completed");
10808 }
10809}
10810
10812 auto [Pos, Inserted] = ImportedDecls.try_emplace(From, To);
10813 assert((Inserted || Pos->second == To) &&
10814 "Try to import an already imported Decl");
10815 if (!Inserted)
10816 return Pos->second;
10817 // This mapping should be maintained only in this function. Therefore do not
10818 // check for additional consistency.
10819 ImportedFromDecls[To] = From;
10820 // In the case of TypedefNameDecl we create the Decl first and only then we
10821 // import and set its DeclContext. So, the DC is still not set when we reach
10822 // here from GetImportedOrCreateDecl.
10823 if (To->getDeclContext())
10824 AddToLookupTable(To);
10825 return To;
10826}
10827
10828std::optional<ASTImportError>
10830 auto Pos = ImportDeclErrors.find(FromD);
10831 if (Pos != ImportDeclErrors.end())
10832 return Pos->second;
10833 else
10834 return std::nullopt;
10835}
10836
10838 auto InsertRes = ImportDeclErrors.insert({From, Error});
10839 (void)InsertRes;
10840 // Either we set the error for the first time, or we already had set one and
10841 // now we want to set the same error.
10842 assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10843}
10844
10846 bool Complain) {
10847 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10848 ImportedTypes.find(From.getTypePtr());
10849 if (Pos != ImportedTypes.end()) {
10850 if (ExpectedType ToFromOrErr = Import(From)) {
10851 if (ToContext.hasSameType(*ToFromOrErr, To))
10852 return true;
10853 } else {
10854 llvm::consumeError(ToFromOrErr.takeError());
10855 }
10856 }
10857
10859 getToContext().getLangOpts(), FromContext, ToContext, NonEquivalentDecls,
10860 getStructuralEquivalenceKind(*this), false, Complain);
10861 return Ctx.IsEquivalent(From, To);
10862}
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:207
static LValuePathEntry ArrayIndex(uint64_t Index)
Definition APValue.h:215
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition APValue.h:122
const LValueBase getLValueBase() const
Definition APValue.cpp:983
ArrayRef< LValuePathEntry > getLValuePath() const
Definition APValue.cpp:1003
const FieldDecl * getUnionField() const
Definition APValue.h:629
unsigned getStructNumFields() const
Definition APValue.h:608
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:204
ValueKind getKind() const
Definition APValue.h:461
bool isLValueOnePastTheEnd() const
Definition APValue.cpp:988
bool isMemberPointerToDerivedMember() const
Definition APValue.cpp:1073
unsigned getArrayInitializedElts() const
Definition APValue.h:595
unsigned getStructNumBases() const
Definition APValue.h:604
bool hasLValuePath() const
Definition APValue.cpp:998
const ValueDecl * getMemberPointerDecl() const
Definition APValue.cpp:1066
APValue & getUnionValue()
Definition APValue.h:633
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition APValue.h:649
CharUnits & getLValueOffset()
Definition APValue.cpp:993
unsigned getVectorLength() const
Definition APValue.h:571
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition APValue.cpp:1080
unsigned getArraySize() const
Definition APValue.h:599
@ 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:1019
const AddrLabelExpr * getAddrLabelDiffLHS() const
Definition APValue.h:645
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:3498
void addShadowDecl(UsingShadowDecl *S)
Definition DeclCXX.cpp:3470
shadow_range shadows() const
Definition DeclCXX.h:3564
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:4187
ValueDecl * getDecomposedDecl() const
Get the decomposition declaration that this binding represents a decomposition of.
Definition DeclCXX.h:4220
Expr * getBinding() const
Get the expression to which this declaration is bound.
Definition DeclCXX.h:4213
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:4225
void setDecomposedDecl(ValueDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition DeclCXX.h:4231
bool isUnsigned() const
Definition TypeBase.h:8211
unsigned getNumBits() const
Definition TypeBase.h:8213
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:2610
Represents a C++ conversion function within a class.
Definition DeclCXX.h:2945
Represents a C++ base or member initializer.
Definition DeclCXX.h:2375
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition DeclCXX.h:2515
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition DeclCXX.h:2475
Expr * getInit() const
Get the initializer.
Definition DeclCXX.h:2577
SourceLocation getRParenLoc() const
Definition DeclCXX.h:2574
SourceLocation getEllipsisLoc() const
Definition DeclCXX.h:2485
SourceLocation getLParenLoc() const
Definition DeclCXX.h:2573
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition DeclCXX.h:2480
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition DeclCXX.h:2509
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition DeclCXX.h:2453
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition DeclCXX.h:2447
bool isIndirectMemberInitializer() const
Definition DeclCXX.h:2459
SourceLocation getMemberLocation() const
Definition DeclCXX.h:2535
IndirectFieldDecl * getIndirectMember() const
Definition DeclCXX.h:2529
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition DeclCXX.h:2501
Represents a C++ deduction guide declaration.
Definition DeclCXX.h:1985
SourceDeductionGuideKind getSourceDeductionGuideKind() const
Definition DeclCXX.h:2069
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:2875
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg)
Definition DeclCXX.cpp:3126
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:2135
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition DeclCXX.cpp:2769
overridden_method_range overridden_methods() const
Definition DeclCXX.cpp:2792
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition DeclCXX.h:2231
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:2026
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:2056
void setInstantiationOfMemberClass(CXXRecordDecl *RD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member class RD.
Definition DeclCXX.cpp:2039
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition DeclCXX.cpp:2052
void setLambdaNumbering(LambdaNumbering Numbering)
Set the mangling numbers and context declaration for a lambda class.
Definition DeclCXX.cpp:1840
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
Definition DeclCXX.cpp:2033
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition DeclCXX.cpp:2067
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:3679
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:4251
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:4456
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:1930
ExplicitSpecKind getKind() const
Definition DeclCXX.h:1938
const Expr * getExpr() const
Definition DeclCXX.h:1939
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:5276
ExtProtoInfo getExtProtoInfo() const
Definition TypeBase.h:5565
ArrayRef< QualType > exceptions() const
Definition TypeBase.h:5730
ArrayRef< QualType > param_types() const
Definition TypeBase.h:5716
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:4828
QualType getReturnType() const
Definition TypeBase.h:4812
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:2581
CXXConstructorDecl * getConstructor() const
Definition DeclCXX.h:2594
ConstructorUsingShadowDecl * getShadowDecl() const
Definition DeclCXX.h:2593
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:5953
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:3310
Expr * getTemporaryExpr()
Retrieve the expression to which the temporary materialization conversion was applied.
Definition DeclCXX.h:3356
Represents a linkage specification.
Definition DeclCXX.h:3017
void setRBraceLoc(SourceLocation L)
Definition DeclCXX.h:3059
LinkageSpecLanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition DeclCXX.h:3040
SourceLocation getExternLoc() const
Definition DeclCXX.h:3056
SourceLocation getRBraceLoc() const
Definition DeclCXX.h:3057
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition DeclCXX.h:3051
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:6171
const IdentifierInfo * getMacroIdentifier() const
Definition TypeBase.h:6170
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:5526
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:3203
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3264
SourceLocation getAliasLoc() const
Returns the location of the alias name, i.e.
Definition DeclCXX.h:3286
SourceLocation getNamespaceLoc() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3289
SourceLocation getTargetNameLoc() const
Returns the location of the identifier in the named namespace.
Definition DeclCXX.h:3292
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition DeclCXX.h:3273
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:7979
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:8178
bool isReadOnly() const
Definition TypeBase.h:8197
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:8349
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:8381
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:2104
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:4138
bool isFailed() const
Definition DeclCXX.h:4167
SourceLocation getRParenLoc() const
Definition DeclCXX.h:4169
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:6201
Expr * getUnderlyingExpr() const
Definition TypeBase.h:6198
A container of type source information.
Definition TypeBase.h:8320
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:8331
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:8685
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition TypeBase.h:9132
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:9179
bool isRecordType() const
Definition TypeBase.h:8713
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:6121
NestedNameSpecifier getQualifier() const
Definition TypeBase.h:6116
bool typeMatchesDecl() const
Definition TypeBase.h:6129
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:6018
UnresolvedUsingTypenameDecl * getDecl() const
Definition TypeBase.h:6024
Represents a dependent using declaration which was marked with typename.
Definition DeclCXX.h:4039
SourceLocation getTypenameLoc() const
Returns the source location of the 'typename' keyword.
Definition DeclCXX.h:4069
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:4073
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:4066
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:4090
Represents a dependent using declaration which was not marked with typename.
Definition DeclCXX.h:3942
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:3973
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:3983
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:3990
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:4000
Represents a C++ using-declaration.
Definition DeclCXX.h:3593
bool hasTypename() const
Return true if the using declaration has 'typename'.
Definition DeclCXX.h:3642
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:3627
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:3634
SourceLocation getUsingLoc() const
Return the source location of the 'using' keyword.
Definition DeclCXX.h:3620
Represents C++ using-directive.
Definition DeclCXX.h:3098
SourceLocation getUsingLoc() const
Return the location of the using keyword.
Definition DeclCXX.h:3169
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Definition DeclCXX.cpp:3311
DeclContext * getCommonAncestor()
Returns the common ancestor context of this using-directive and its nominated namespace.
Definition DeclCXX.h:3165
SourceLocation getNamespaceKeyLocation() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3173
SourceLocation getIdentLocation() const
Returns the location of this using declaration's identifier.
Definition DeclCXX.h:3176
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3143
Represents a C++ using-enum-declaration.
Definition DeclCXX.h:3794
SourceLocation getEnumLoc() const
The source location of the 'enum' keyword.
Definition DeclCXX.h:3818
TypeSourceInfo * getEnumType() const
Definition DeclCXX.h:3830
SourceLocation getUsingLoc() const
The source location of the 'using' keyword.
Definition DeclCXX.h:3814
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition DeclCXX.h:3875
NamedDecl * getInstantiatedFromUsingDecl() const
Get the using declaration from which this was instantiated.
Definition DeclCXX.h:3904
ArrayRef< NamedDecl * > expansions() const
Get the set of using declarations that this pack expanded into.
Definition DeclCXX.h:3908
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3401
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition DeclCXX.h:3465
BaseUsingDecl * getIntroducer() const
Gets the (written or instantiated) using declaration that introduced this declaration.
Definition DeclCXX.cpp:3441
UsingShadowDecl * getDecl() const
Definition TypeBase.h:6064
QualType desugar() const
Definition TypeBase.h:6066
NestedNameSpecifier getQualifier() const
Definition TypeBase.h:6060
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
Information about how a lambda is numbered within its context.
Definition DeclCXX.h:1802
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:5345
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5349
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5335
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5338
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5341
Extra information about a function prototype.
Definition TypeBase.h:5361
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